Skip to content

RetroPlayer: Add a cheat engine - #157

Open
sunlollyking wants to merge 2 commits into
garbear:masterfrom
sunlollyking:retroplayer-cheats
Open

sunlollyking wants to merge 2 commits into
garbear:masterfrom
sunlollyking:retroplayer-cheats

Conversation

@sunlollyking

@sunlollyking sunlollyking commented Sep 2, 2026

Copy link
Copy Markdown

Description

Cheats are read from libretro .cht files and offered as switches in a dialog one level below the game OSD.

The Cheats row only appears when a cheat file was found for the game being played, so a system with no cheats never offers a list with nothing in it. That is driven by a new boolean condition, RetroPlayer.HasCheats, which skins can use themselves. The row is added to both game OSD variants in Estuary, the cartridge one and the disc one, along with a new icon.

A cheats folder is set under Settings > Games. The libretro cheat database is published a folder per system, so the setting can point straight at the database itself, and a folder of loose files the user has gathered works just as well. The file is matched by the game's name, which is how that database is published.

Two things about how the codes are sent are worth calling out, because both look like the harder option until you hit them:

  • The set is sent whole after a reset rather than one code at a time. A cheat is identified by the slot it was given, so switching one off would leave every cheat after it answering to the wrong index.
  • Only the cheats that are switched on are sent. Cores are not obliged to honour the enabled flag they are handed and several ignore it outright. fceumm adds every code it is given, so sending a disabled cheat applies it. With a full database loaded that shows up as a corrupted picture rather than as an error.

Two limits, both from measurement rather than taste. A cheat file is read to 16 MB, and at most 1024 cheats are taken from one. The median file in the libretro database holds 6 cheats and the largest holds 30911; past a thousand nobody is reading down the list, and the ones beyond cost frames and memory to carry. At thirty thousand the dialog still opens, but the frame rate halves and the process grows by a few hundred megabytes. A file over the limit gives its first cheats rather than none at all, and says so in the log.

A cheat name longer than 55 characters is truncated in its row, because past that the text runs under the switch. The full text is handed to the settings description control, so a skin that lays out a description area shows it. Estuary's DialogSettings.xml has no such control, so it is not visible in the default skin today.

Motivation and context

The Game API has carried CheatReset() and SetCheat() for a long time and nothing in Kodi has ever called them. Game clients already implement them, so the emulator side of this works today and only the frontend was missing.

How has this been tested?

Linux build, against game.libretro.fceumm and Super Mario Bros. with the libretro cheat database, which gives that game 711 usable cheats out of 725 declared.

  • Switching cheats on and off during play, confirming in the log exactly which codes reach the core, and that a cheat switched off is dropped from the set rather than sent as disabled.
  • Loading a game with no cheat file, and with the cheats folder unset, to confirm the row stays hidden.
  • Measured the cheat database rather than guessing at the limits: cheat counts per file, and description lengths, where the median is 12 characters and the 99th percentile is 56.
  • Stress tested the dialog at 1024, 8000 and 30911 toggles to pick the cap.
  • Cheat files that declare cheats with no code, which RetroArch writes for its own engine to poke. Those are counted and left out rather than offered as cheats that do nothing.
  • The 48 existing game and GUI info unit tests pass.

What is the effect on users?

A Cheats item appears in the game OSD while playing a game that has a cheat file, listing the cheats that file declares as switches that can be turned on and off during play. Nothing changes for a game with no cheat file.

Screenshots (if appropriate):

image image

Types of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@sunlollyking

Copy link
Copy Markdown
Author

@garbear again opening against your master and i'll keep maintaining until you think it's ready to include in master. All tested, working :)

@garbear

garbear commented Sep 4, 2026

Copy link
Copy Markdown
Owner

How about providing cht files in a game resource add-on?

It doesn't need to be a binary add-on. The reason why game.shader.presets has any C++ code at all is because we ripped it from retroarch, which is GPLv3, hence the DLL boundary. If we had AI back in 2017 we would have just hand rolled all the code into master.

@garbear

garbear commented Sep 4, 2026

Copy link
Copy Markdown
Owner

This is an awesome feature! Upstreaming might take a little bit, as we probably won't branch for v23 for a little while, and the team is discussing ways to fast-track big AI features like this into v23.

@eigendude

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c44b66409e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread xbmc/games/cheats/CheatPack.cpp Outdated
Comment thread xbmc/games/cheats/CheatPack.cpp Outdated
Comment thread xbmc/games/cheats/CheatRuntime.cpp Outdated
Comment thread xbmc/games/cheats/CheatRuntime.cpp Outdated
Comment thread xbmc/games/dialogs/osd/DialogGameCheats.cpp Outdated
Comment thread xbmc/guilib/GUIWindowManager.cpp
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T22:21:41.728536Z 424892e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sunlollyking
sunlollyking force-pushed the retroplayer-cheats branch 2 times, most recently from c7932a9 to 4066342 Compare September 8, 2026 08:12
@sunlollyking

Copy link
Copy Markdown
Author

Good idea, and no binary needed as you say. I have folded it into this PR: the engine now searches every installed game resource add-on as well as the folder setting, about forty lines, because Kodi already has kodi.resource.games, CGameResource and resource://. No change to the parsing or the dialog, which I think says the shape was right.

I would keep the folder setting either way though. Anyone with their own cht files, a full libretro checkout, or a system no add-on covers still wants to point at it, same as RetroArch does.

On the add-on itself, the data is the awkward part rather than the plumbing. The cht folder is 28,308 files and 250 MB, with DS alone at 108 MB over 4,204 files, so one add-on for everything is out. 27 of the 45 systems are a megabyte or less though and only 8 are over 5 MB, so per system is mostly tiny and it is a handful of consoles causing it. Licence is fine, CC-BY-SA-4.0, which the add-on rules take.

Also rebased onto master while I was in there, and picked up an include ordering fix clang-format wanted.

Comment thread addons/resource.language.en_gb/resources/strings.po Outdated
@sunlollyking
sunlollyking force-pushed the retroplayer-cheats branch 3 times, most recently from c92cdac to 852e101 Compare September 8, 2026 12:30
@eigendude

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 852e101442

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread xbmc/games/addons/GameClient.cpp Outdated
Comment thread xbmc/games/cheats/CheatRuntime.cpp Outdated
Comment thread xbmc/games/cheats/CheatPack.cpp Outdated
Comment thread xbmc/games/cheats/CheatRuntime.cpp Outdated
Comment thread addons/skin.estuary/xml/GameOSD.xml Outdated
@sunlollyking
sunlollyking force-pushed the retroplayer-cheats branch 2 times, most recently from 89146e8 to 4940b8c Compare September 9, 2026 13:16
@eigendude

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4940b8c0f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread xbmc/games/cheats/CheatRuntime.cpp Outdated
@sunlollyking

Copy link
Copy Markdown
Author

@garbear is there a chance we could open this for 22 - or do you think too big for the RC remit?

Comment thread cmake/treedata/common/games.txt Outdated
@garbear

garbear commented Sep 10, 2026

Copy link
Copy Markdown
Owner

V22 is possible due to the line counts: 1K lines added, 2 removed. Red in a PR is a big warning flag that existing code is touched, and this PR has barely any red.

If we're going to upstream this, we'll need to do it ASAP. I'll see what I can do about review today.

Comment thread xbmc/games/addons/GameClient.cpp
Comment thread xbmc/games/dialogs/osd/DialogGameCheats.cpp Outdated
Comment thread xbmc/games/dialogs/osd/DialogGameCheats.h Outdated
Comment thread xbmc/games/GameServices.h Outdated
Comment thread addons/skin.estuary/xml/GameOSD.xml Outdated
Comment thread xbmc/games/addons/GameClient.cpp Outdated
@garbear

garbear commented Sep 10, 2026

Copy link
Copy Markdown
Owner

I'll redo the dialog, then cheats will just be adding a button

@sunlollyking

Copy link
Copy Markdown
Author

Ok. I'm making changes aswell in the next 10 so hopefully we don't crash

@sunlollyking

Copy link
Copy Markdown
Author

Cool that's me all done. Everything should be working now. Did some manual tests ! Dialog definitely needs that polish

@garbear

garbear commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Here's your first commit:

http://github.com/garbear/xbmc/commit/new-game-osd

Then do:

--- a/addons/skin.estuary/xml/GameOSD.xml
+++ b/addons/skin.estuary/xml/GameOSD.xml
@@ -14,7 +14,8 @@
                                !Window.IsActive(InGameSaves) +
                                !Window.IsActive(GameAgents) +
                                !Window.IsActive(GameDiscManager) +
-                               !Window.IsActive(GameAchievements)
+                               !Window.IsActive(GameAchievements) +
+                               !Window.IsActive(GameCheats)
                        </visible>
                        <include>Visible_Fade</include>
                        <control type="group" id="10">
@@ -143,6 +144,13 @@
                                                        <description>Always show Achievements; its dialog explains sign-in requirements and missing achievement sets.</description>
                                                        <onclick>ActivateWindow(GameAchievements)</onclick>
                                                </include>
+                                               <include content="GameOSDMenuButton">
+                                                       <param name="id" value="1118" />
+                                                       <param name="label" value="$LOCALIZE[35320]" />
+                                                       <param name="icon" value="osd/fullscreen/buttons/cheats.png" />
+                                                       <visible>RetroPlayer.HasCheats</visible>
+                                                       <onclick>ActivateWindow(GameCheats)</onclick>
+                                               </include>
                                                <include content="GameOSDMenuButton">
                                                        <param name="id" value="1115" />
                                                        <param name="label" value="$LOCALIZE[13007]" />

(untested but testing now)

@garbear

garbear commented Sep 10, 2026

Copy link
Copy Markdown
Owner

The design is roughly this:

fixed maximum-height grouplist
        ↓
<align>center</align>

  ┌────────────┐  ← header as an 80px group
  │ Game menu  │
  ├────────────┤
  │ Play       │
  │ Saves      │
  │ Disc       │ ← conditional
  │ Players    │
  │ Cheevos    │
  │ Cheats     │ ← conditional
  │ Reset      │
  │ Stop       │
  │ Settings   │
  └────────────┘

@garbear

garbear commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Sorry, Astra High let us down. Bumping to Astra Ultra, it'll nail the new OSD.

@sunlollyking

Copy link
Copy Markdown
Author

Fab let me know when you're done and I'll take the lead back over with commit ordering and rebasing. Don't want to crash into you

@garbear

garbear commented Sep 10, 2026

Copy link
Copy Markdown
Owner

K, got it workin good: 8e7307a

No change to the patch I posted.

I also made the icon smaller. It matches the others better now IMO.

cheats

Before:

Screenshot 2026-09-10 at 12 46 33 PM

After:

Screenshot 2026-09-10 at 1 07 58 PM

@sunlollyking

Copy link
Copy Markdown
Author

Cool order is all good now. Apologies for the 11 commits I think we just need your master to catch up

@eigendude

Copy link
Copy Markdown
Collaborator

OK, I pushed the latest master

Replace the duplicated Disc and non-Disc layouts with reusable buttons
in a centered grouplist. Visible controls determine the menu height
together with its header.

Draw one continuous background to avoid row seams at fractional GUI
scales. Size the optional background from the header and menu controls,
as the context menu does for its dynamic background.

Preserve existing actions, help mode, and navigation. Remove the obsolete
list and scrollbar machinery.
@garbear

garbear commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Did you replace the icon? I think the current one is a bit too big:

Screenshot 2026-09-10 at 3 15 54 PM

I pasted a slightly smaller one above.

@eigendude

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 424892e775

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread xbmc/games/dialogs/osd/DialogGameCheats.cpp Outdated
@garbear

garbear commented Sep 10, 2026

Copy link
Copy Markdown
Owner

I've taken care of upstreaming the refactored game OSD: xbmc#29278

If you open this PR against master before that merges, include that commit (it changed). When xbmc#29278 is merged, we'll rebase it out.

@garbear

garbear commented Sep 11, 2026

Copy link
Copy Markdown
Owner
Screenshot 2026-09-10 at 5 55 53 PM

Are those "Weapon modifier [slot]" entries supposed to be toggle buttons?

@garbear

garbear commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Sorting, structure, and organization, leaves something to be desired.

Screenshot 2026-09-10 at 8 50 29 PM

Cheats are read from libretro .cht files named after the game and offered
as toggles in a dialog one level below the game OSD. The row only appears
for a client that implements the cheat entry points.

Only the cheats that are switched on are sent, and they are sent whole
after a reset, because a cheat is identified by the slot it was given and
several cores ignore the enabled flag they are handed.

Files are looked for in the folder the player points the setting at, and in
every game resource add-on they have installed. Cheat files are data, so an
add-on carrying them needs no binary of its own and installs and updates
through the repository like anything else. The setting is asked first and
stays either way, for a database of somebody's own or a system no add-on
covers.

A cheat add-on ships one zip per system rather than tens of thousands of loose
files, so an archive is searched like a folder. Kodi reads it through the same
calls either way.

The dialog offers to fetch that add-on when it is missing or switched off, the
way the video filter offers shader presets, since the player has no other way
of learning the database exists. That is also why the OSD row now shows while
the offer stands rather than only once cheats have been found, and why the
folder setting has moved to expert: it is the escape hatch now, not the way in.

The cheats belong to the game client, as a subsystem beside its achievements,
input and streams. The pack and the switches are that client's, and go when it
does. Nothing global holds a pointer back to a client, so nothing here assumes
only one can ever be loaded.

The client's own lock is taken before the cheat state's on every path, which is
the order a game being closed already holds them in, and the client cannot be
torn down between the codes of a batch because closing it takes that same lock.

Descriptions are written with the HTML entities that came with them from the
web, so they are resolved through Kodi's own table rather than shown as
written: a quoted button arrives as &quot;A&quot;, and 428 of the database's
28,308 files carry one.

The dialog keeps its own copy of the settings layout so the column beside the
list can say what is switched on, which the shared one has no control for. The
player would otherwise have to scroll back through several hundred rows to see
what they had turned on.
@sunlollyking

Copy link
Copy Markdown
Author
  • Addressed Codex P2 (dialog reactivation)
  • Decoded HTML entities confirmed ours, and real: 428 of the database's 28,308 files carry them. Used Kodi's own CHTMLUtil::ConvertHTMLToW rather than writing a table. Proven in the UI: cheat game.libretro addons create files in Application directory #93 now reads Jump 'til Release "A" Walking Start, not "A".
  • Shrank the cheats icon
  • Enabled-cheats panel in the previously blank right column

"Weapon modifier — should those be toggles?" — All chats are booleans we are at mercy of jow an author describes a cheat

"Other groupings we could take?" — I thought about going alphabetical but then we do lose what the author of the cheats wanted. Unfortunately there's very little data to sort by

@garbear

garbear commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Good work! I saw the upstream PR. Only comments are to update the description:

  • Link here near the beginning of the description
  • Add some beautiful screenshots, and don't put them under a wall of text, so that people see them when opening the PR

@garbear

garbear commented Sep 11, 2026

Copy link
Copy Markdown
Owner

For screenshots, get a good one of the OSD with Cheats highlighted, then show the dialog, and put a pretty game (and maybe not IP-contentious) in the background.

EDIT: I noticed you did this perfectly in your description here, nice! Though the ones on master could use no debugging text and a prettier game in the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants