Repository navigation
Conversation
|
Heads-up: in #388 there is a proposal for one settings model that every UI reads and writes (#388 (comment)). Where the Cheats menu changes a launch setting, it would use that model, so its choices show up in the other views too. The cheat engine itself stays independent of it. Input welcome there. |
|
Hello, working on it |
|
Rebased on today's |
|
Nice work, @Amost-. A note from the front-end side (#388), since outside front ends will want to manage cheats too. NX2Apple plans "Manage → Cheats…" for a game. On the iPhone and iPad there is no panel, so a front end that installs the game would be the only place to pick cheats. On the Mac it would be another view of the same files as your panel: import, then on or off per cheat before the start. For that to stay compatible, could this PR document the files as the contract, in a "Cheats" section of
Then a front end can manage cheats without reading the host's code, and a change to the format comes with a docs change. |
|
Done: the branch now has a Cheats section in
|
|
@Amost-, a heads-up from NX2Apple: we'd like to carry this PR downstream until it lands here, so the launcher's cheat manager (LNPANDY/NX2Apple#97) can be built on the file contract you wrote in @seedds, would a split make the review easier? For example the engine first ( |
The host reads Atmosphère-format cheat files for the running game's build (dm/host/hle_cheats.c), keeps the player's toggles beside them, and scripts/cheat_anchor.py carries a cheat file across game updates. Includes the Cheats section of docs/frontends.md, the file contract for front ends. Ported onto the pinned tree from seedds/nxnative#406 (all but the Mac panel).
The Cheats menu of the Mac game window and the floating Cheats panel (sections, search, master switch, values, import of cheat files) in dm/host/front_mac.m. Ported onto the pinned tree from seedds/nxnative#406.
The engine, hooks, tools, tests and docs as 0027-cheats-engine, the Mac panel as 0028-cheats-mac-panel, both authored by Amost-. The launcher's cheat manager (#97) builds on the file contract in docs/frontends.md.
Cheats sheet in the launcher, carrying seedds/nxnative#406
hle_cheats.c loads <build ID>.txt from DM_CHEATS (default <DM_ROOT>/cheats, flat or the atmosphere/contents tree), runs the dmnt cheat VM (opcodes 0-8, bounds- checked, a malformed line disables its cheat) once per presented frame and from a ~60 Hz thread, and writes code pages through a writable alias of main mapped only when a file is loaded. The Mac window's Cheats menu toggles cheats (remembered per build in <build ID>.enabled), reloads and opens the folder, and lists files for other builds. DM_CHEATS_ON, DM_CHEATS_ANY_BUILD and DM_CHEATS_DEBUG for scripted runs. Without a cheats file nothing changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 46c4b3710a28e26a1a8058c4634b35d85e659b94)
The Cheats menu's first item, Show Cheats Window (⌘⇧C), opens a floating utility panel beside the game: one checkbox per cheat from the dm_cheat* API, toggles applied live and saved to <build ID>.enabled, Select All / Deselect All for the plain cheats, Reload cheats and Open cheats folder, and a ~1 s refresh while it is visible so a cheat turned off at run time shows its reason. The panel never takes the key window from the game, shows over a fullscreen game, closes only to hide and remembers its frame. The Cheats menu keeps its rows and is filled at launch, so ⌘R and ⌘⇧C work before it has been opened once. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit d4f4d5ea75c90447b43e733d199fe41ccb2f4332)
An Atmosphère cheat names fixed offsets into the main NSO, valid for one build: every game update breaks it. cheat_anchor.py imports a cheat file into a version-independent source (<game>.cheats.toml) whose addresses are anchored to the game's code, and compiles it into the plain <build ID>.txt of any build, which every engine runs: - data: the nearest address the code references (adrp + add/ldr/str pairs in identified functions, optionally through relocated .data slots), plus a field offset; two references must agree, none may disagree - code: the run of words a cheat writes, found by nso_match's function fingerprint, then by the body digest, then by a relocation-masked window unique in the text; original words always checked, relocated ones never overwritten with the old build's bits - caves: the zero padding before the read-only data Patches compile to "still the original?" guarded stores (--plain for build-time baking); B/BL to elsewhere are re-encoded per build; on/off pairs keep both names and their order. Only an unchanged output of the same source is rewritten. Words the rewriter changed are reported. Validated: FFCC's 1.0.1 cheats land on 1.0.3 at exactly the hand-verified +0x43680; its 1.0.3 file compiles back to identical writes and to the cartridge build; a 13 Sentinels 1.10 list compiles back to identical writes and to 1.00 (-0x330). Unit tests on synthetic NSOs. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 0e32d7b7383c6f98c7d22e18764f4a6ff9fc4cb3)
hle_cheats.c gains Atmosphère's store register (A), register conditional (C0) and static registers (C3), and a layer of its own over the format, all optional (a plain community file behaves as on a Switch): - labels and EdiZon sections instead of "(empty)" cheats; a header glued to a code word and code on a header's own line are read as dmnt does - "X - on" / "X - off" entries are one switch (the restore runs one pass) - <build>.meta.tsv from scripts/cheat_anchor.py: sections, notes, typed values the panel may set (<build>.values), "set" cheats that run once, never-decrease (a host action: Atmosphère's VM keeps no state between passes, so its .txt entry is empty), the compiler's left-outs - duplicate names saved as "Name seedds#2"; a new build compiled from the same source takes the previous build's toggles - a dry run (dm_cheat_preview), a master switch and, on the Mac, safe mode after an unclean exit (dm_cheats_exit on every clean path), and a load report with Atmosphère's size limits - a heap cheat before the game opens its heap waits instead of dying scripts/cheat_anchor.py compiles never-decrease into that empty entry and a meta row with the type and address. dm/host/tests/t_cheats.c covers the opcodes and the layer; verified on FFCC 1.0.3 with the compiled file (cave patch written once, stats and Mog every frame). Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit c7ed066bc121cd3e98d0838417d36aa356417b46)
…mport The panel and the Cheats menu show what hle_cheats.c now knows: - the build and its version in the header, a safe-mode line with Restore, Cheats On (the master switch) and a search by name / section - section headers and labels; an on / off pair as one row; an Apply button for "set" cheats; a value field for "ask" cheats (Return applies, Escape abandons); a details line with a cheat's dry run and note, or the load report - the cheats the compiler left out, the other builds' files with their versions, anchored sources with a Copy Command for compiling them - Find Cheats… (Ryujinx, the yuzu family, SD cards) and dropped files copied into the cheats folder, asking before renaming or replacing - DM_CHEATS_WINDOW=1 opens the panel at launch A click never takes the keyboard from the game; the panel keeps it only while a field is being edited. Engine strings that are not UTF-8 (Shift-JIS, Latin-1, a name cut mid-character) are decoded instead of crashing, and the engine cuts long names on a character boundary. Verified in the FFCC app with temporary cheats and save. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit f4c06ec1591fdb5c7d29913045822c284871fed7)
…free words allowed over moved ones, segment-aware data anchors, in-function branch flips, strict parsing Gated and register-sourced stores, narrow writes and new adrp users no longer carry a build's address bits into another; NOPs and immediates over a moved word are accepted by a conservative classifier; data anchors stay inside their NSO segment; a flipped conditional branch inside an anchored function is carried; glued words split and junk beside code words marks the cheat malformed instead of shortening it; undecodable cheats, title-ID file names, master flags, weak marks and partial hooks handled. 16 new tests; FFCC and 13 Sentinels outputs unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> (cherry picked from commit c17dadada8816e66807a4aad0de8ea256c0108ed)
… reference notes from the Atmosphère source docs/reference/cheats.md documents how dmnt runs cheats (from Atmosphère 1.12.1) and where the host differs. The engine now ignores a failed read or write like the reference (the cheat keeps running, a note in the panel, one RED line) instead of turning the cheat off for the session; reads reach any mapped guest page and writes any writable one, with main through its alias and never another module's code or patch area; registers are shared across the cheats of a pass, loop tops stay per cheat; memory regions 2-4 resolved; glued hex words split; .enabled written atomically off the presenting thread; previews never mark a cheat. t_cheats grows from 58 to 111 checks. Co-Authored-By: Claude Fable 5.1 <[email protected]> (cherry picked from commit b9abdd89bd65d87491ec98632ed1590f7c5daa99)
Find Cheats… reads the Ryujinx, yuzu-family and SD card folders on a background queue: a sleeping external disk can take seconds to answer and the game window would beachball meanwhile. The button reads "Looking…" and is disabled until the scan ends, a second click starts no second scan, and the menu of the files found is shown on the main queue only while the panel is still on screen. The build ID is read from the engine on the main thread. (cherry picked from commit 505bde6c9c51d2c7f4ab38a66c41fa585b5df604, only its Find Cheats hunks) Co-Authored-By: Claude Fable 5.1 <[email protected]>
Register arithmetic with every math type (the float ones at T = 4 / 8, shifts modulo 64 as the hardware), save / restore of registers with the saved values zeroed once per pass like the registers, and the extended key-press conditional (64-bit mask; r = 0 met on the pass where the keys became held, against one previous-keys value shared by every C4 and set at the end of each pass that ran a VM cheat). Opcode 8 reads the same per-pass key snapshot. FF0, FF1 and FFF stay unsupported. 24 new checks in t_cheats (135 in all); the docs' opcode list and the reference table updated. Co-Authored-By: Claude Fable 5.1 <[email protected]> (cherry picked from commit ecaa202904a5b953070a77bcf2b457a96fe413e8)
hle_nvn.c calls dm_cheats_present once per presented frame, and the CPU-only graphics tests (dm/gfx/tests t_nvn) link hle_nvn.c without the host, so they stopped linking. A weak no-op in nvn_mtl.m, beside the other weak host stubs, lets them link again; hle_cheats.c provides the strong definition in the host. (cherry picked from commit 9782490ec0127ccec6d7f5042cd95a05cbc7f35e, only its weak cheats stub) Co-Authored-By: Claude Fable 5.1 <[email protected]>
A front end that installs cheats or picks which ones run before the start writes the same files the host and the Mac panel use. The new Cheats section of docs/frontends.md describes them, as Saved choices describes the preferences: the folder (DM_CHEATS, else <DM_ROOT>/cheats, flat or the SD card's tree), <build ID>.enabled (one name per line), .meta.tsv and .values, the master switch and safe-mode flag files, what may be written while the game runs (nothing the host reads back without a reload), the one-start switches, the iPhone (the engine is there, the app names no folder yet) and cheat_anchor.py's compiled files. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…s carried across game updates (PR #406) hle_cheats.c loads the running build's <build ID>.txt from DM_CHEATS (default <DM_ROOT>/cheats, flat or the atmosphere/contents tree) and runs the dmnt cheat VM, opcodes 0-C4 as Atmosphère 1.12.1 runs them (docs/reference/cheats.md says where the host differs), once per presented frame and from a ~60 Hz thread while the game is not presenting. On top of the plain format: labels and EdiZon sections, on / off pairs as one switch, per-build toggles (<build ID>.enabled), typed values, run-once cheats, a dry run, a master switch and, on the Mac, safe mode after an unclean exit. The Mac window gets a Cheats menu and a floating Cheats panel (⌘⇧C) that never takes the keyboard from the game. scripts/cheat_anchor.py imports a cheat file into a version-independent source anchored to the game's code and data and compiles it for any build. docs/frontends.md has the files as the contract for front ends. Changes to the pull request: - Cheats never write over the rewriter's work. patch_nso.py writes <name>.changed.tsv: the text words it changed (sites, cuts, lock acquires, jump tables) and those whose copies run instead (windows, spin waits); Mac apps carry it. A code write that covers one turns the cheat off with the reason: the Switch's original word there (an "X - off" restore, most often) would run an SVC or a TLS read natively or undo an ldaxr, and a write into a copied instruction never runs. Without the list (an older rewriter's modules) no code write is allowed. Writes past the game's own image (the key page, the frame step page, the patch areas) are refused too. - No thread without cheats: the ~60 Hz apply thread starts with the first file that has a cheat in it, not for every game. - No code writes without the writable alias of main. On the iPhone the code pages are the app's signed pages, and toggling the game's own pages writable on the Mac races with its cores, so the mprotect fallback is gone: the iPhone runs data cheats only. t_cheats covers the refusals (143 checks, also under ASan and UBSan). The clang-tidy findings the new files brought are fixed (a realloc that lost its buffer, a shift by 64 on an untyped value, three nils handed to AppKit, the test's unchecked lookups) or marked: file loads under the cheats lock, which the per-frame pass only trylocks. Regression (normal reach, 3 games), check against fe6d3df: - Super Mario Bros. Wonder: PASS (16268/16268 shaders, fps 59.4 → 59.6, no new RED). - Tears of the Kingdom: the first run never presented. Its window resigned key before the first frame and the game suspended on the out-of-focus notification, as on a Switch. A second run booted (first frame 7.9 s, fps 34.5 → 46.5, p99 51.6 → 17.9 ms, 28669/28669 shaders); only its 90 s screenshot was missing, after a late focus loss. - Breath of the Wild: frame p99 17.5 → 33.4 ms in 3 of 3 runs (fps 60.0 → 58.5, 19592/19592 shaders, no new RED). This baseline's 17.5 ms is the outlier: BotW's other checks today measured 32.8 to 33.5 ms on both sides (e513bfe, 195986f). Without a cheats file the host's only new per-frame work is a timestamp and a flag check. Co-authored-by: Amost <[email protected]>
|
Thank you! This landed on main as ef9f9bb, with you as co-author. The cheat engine, the Mac Cheats panel,
|
|
thank you |
seedds/nxnative ef9f9bb lands the cheat engine and the Mac Cheats panel (seedds/nxnative#406), and f35fe86 lands the NSP script's --work-dir (seedds/nxnative#475). Their patches are dropped: 0007-nsp-work-dir, 0028-cheats-engine and 0029-cheats-mac-panel. Refreshed: 0001-runtime-profile (hle_fpslock.c's Unreal rows, the tests Makefile), 0003-ios-game-data-folder (front_ios.m and main.m beside the TV output), 0008-bc-cpu-decode (upstream now refuses a GPU without BC at start, and tex_bc_cpu on lets such a GPU through), 0009-mac-keymap (beside the cheats code in front_mac.m, the tests Makefile and docs/development.md). Launcher: the iPhone runs data cheats only, so the Cheats sheet's iOS note says that code cheats run in the Mac app only. The README names the Xcode 27.1 download and the side-by-side setup, which upstream's toolchain test checks. GAMES.md has the three new ports.
…s carried across game updates (PR seedds#406) hle_cheats.c loads the running build's <build ID>.txt from DM_CHEATS (default <DM_ROOT>/cheats, flat or the atmosphere/contents tree) and runs the dmnt cheat VM, opcodes 0-C4 as Atmosphère 1.12.1 runs them (docs/reference/cheats.md says where the host differs), once per presented frame and from a ~60 Hz thread while the game is not presenting. On top of the plain format: labels and EdiZon sections, on / off pairs as one switch, per-build toggles (<build ID>.enabled), typed values, run-once cheats, a dry run, a master switch and, on the Mac, safe mode after an unclean exit. The Mac window gets a Cheats menu and a floating Cheats panel (⌘⇧C) that never takes the keyboard from the game. scripts/cheat_anchor.py imports a cheat file into a version-independent source anchored to the game's code and data and compiles it for any build. docs/frontends.md has the files as the contract for front ends. Changes to the pull request: - Cheats never write over the rewriter's work. patch_nso.py writes <name>.changed.tsv: the text words it changed (sites, cuts, lock acquires, jump tables) and those whose copies run instead (windows, spin waits); Mac apps carry it. A code write that covers one turns the cheat off with the reason: the Switch's original word there (an "X - off" restore, most often) would run an SVC or a TLS read natively or undo an ldaxr, and a write into a copied instruction never runs. Without the list (an older rewriter's modules) no code write is allowed. Writes past the game's own image (the key page, the frame step page, the patch areas) are refused too. - No thread without cheats: the ~60 Hz apply thread starts with the first file that has a cheat in it, not for every game. - No code writes without the writable alias of main. On the iPhone the code pages are the app's signed pages, and toggling the game's own pages writable on the Mac races with its cores, so the mprotect fallback is gone: the iPhone runs data cheats only. t_cheats covers the refusals (143 checks, also under ASan and UBSan). The clang-tidy findings the new files brought are fixed (a realloc that lost its buffer, a shift by 64 on an untyped value, three nils handed to AppKit, the test's unchecked lookups) or marked: file loads under the cheats lock, which the per-frame pass only trylocks. Regression (normal reach, 3 games), check against 9b54720: - Super Mario Bros. Wonder: PASS (16268/16268 shaders, fps 59.4 → 59.6, no new RED). - Tears of the Kingdom: the first run never presented. Its window resigned key before the first frame and the game suspended on the out-of-focus notification, as on a Switch. A second run booted (first frame 7.9 s, fps 34.5 → 46.5, p99 51.6 → 17.9 ms, 28669/28669 shaders); only its 90 s screenshot was missing, after a late focus loss. - Breath of the Wild: frame p99 17.5 → 33.4 ms in 3 of 3 runs (fps 60.0 → 58.5, 19592/19592 shaders, no new RED). This baseline's 17.5 ms is the outlier: BotW's other checks today measured 32.8 to 33.5 ms on both sides (c15f94f, b55c40d). Without a cheats file the host's only new per-frame work is a timestamp and a flag check. Co-authored-by: Amost <[email protected]>
Atmosphère cheat codes run on the Mac host:
hle_cheats.cloads a game's<build ID>.txt(fromDM_CHEATS, default<DM_ROOT>/cheats, flat or theatmosphere/contentstree) and runs the dmnt cheat VM, opcodes 0–C4 as Atmosphère 1.12.1 runs them (docs/reference/cheats.mdsays where the host differs), once per presented frame and from a ~60 Hz thread; code pages are written through a writable alias ofmainmapped only while a file is loaded. Without a cheats file nothing changes, on the Mac or the iPhone.dm/host/hle_cheats.c, 10 commits): the VM with bounds-checked accesses (a failed read or write is ignored like the reference, with a note and one[RED]line), key-press conditionals from every input source (dm_cheats_keys), per-build enabled states (<build ID>.enabled), a master switch, a dry run, safe mode after an unclean exit, and an optional layer over the plain format: labels and EdiZon sections, on / off pairs as one switch,<build>.meta.tsvwith typed values and run-once cheats.DM_CHEATS_ON,DM_CHEATS_ANY_BUILD,DM_CHEATS_DEBUGfor scripted runs; all indocs/env_switches.tsv.front_mac.m): a Cheats menu and a floating Cheats panel (⌘⇧C) with live checkboxes, sections, search, values, the other builds' files, Find Cheats… (Ryujinx, the yuzu family, SD cards, read off the main thread) and drag-and-drop import. The panel never takes the key window from the game.scripts/cheat_anchor.py: imports a cheat file into a version-independent source (<game>.cheats.toml) anchored to the game's code and data, and compiles it into the plain<build ID>.txtof any build, so a cheat survives a game update. Unit tests on synthetic NSOs.docs/frontends.md(the folder,<build ID>.enabled,.meta.tsv,.values, the flag files, what may be written while the game runs, the iPhone), asked for in the review.hle_nvn.ccallsdm_cheats_presentonce per presented frame;nvn_mtl.mcarries a weak no-op so the CPU-only graphics tests still link without the host.regress.py impact origin/main..HEAD: 3 games with manifests use what the change touches (Hades, BotW, TotK, through the HID reads and the present path), 76 unknown; the engine itself is off without a file.Depends on nothing. The FFCC-specific notes and anchored cheats that were written alongside this follow once #285 lands (the links to that profile's README are plain text here).
Checked
main(75065df):dmhostfor The Legend of Zelda: Echoes of Wisdom and FINAL FANTASY CRYSTAL CHRONICLES;make -C dm/host/tests GAME=01008CF01BAAC000 run(t_cheatscovers the opcodes and the layer);dm/gfx/testst_nvnbuilds; every test indm/tools/tests(382, 16 skipped) anddm/ios/tests.cheat_anchor.pywith identical writes.Not checked
scripts/regress.py checkover local games: the harness is not set up on this Mac (no/Volumes/NX).🤖 Generated with Claude Code