Skip to content

Atmosphère cheat codes: a host engine, a Mac Cheats menu and panel, and cheat_anchor.py to carry cheats across game updates - #406

Closed
Amost- wants to merge 11 commits into
seedds:mainfrom
Amost-:topic/cheats
Closed

Amost- wants to merge 11 commits into
seedds:mainfrom
Amost-:topic/cheats

Conversation

@Amost-

@Amost- Amost- commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Atmosphère cheat codes run on the Mac host: hle_cheats.c loads a game'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; code pages are written through a writable alias of main mapped only while a file is loaded. Without a cheats file nothing changes, on the Mac or the iPhone.

  • Engine (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.tsv with typed values and run-once cheats. DM_CHEATS_ON, DM_CHEATS_ANY_BUILD, DM_CHEATS_DEBUG for scripted runs; all in docs/env_switches.tsv.
  • Mac front end (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>.txt of any build, so a cheat survives a game update. Unit tests on synthetic NSOs.
  • The files as a contract for front ends: a Cheats section of 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.
  • One host hook outside the engine: hle_nvn.c calls dm_cheats_present once per presented frame; nvn_mtl.m carries 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

  • This branch on main (75065df): dmhost for The Legend of Zelda: Echoes of Wisdom and FINAL FANTASY CRYSTAL CHRONICLES; make -C dm/host/tests GAME=01008CF01BAAC000 run (t_cheats covers the opcodes and the layer); dm/gfx/tests t_nvn builds; every test in dm/tools/tests (382, 16 skipped) and dm/ios/tests.
  • Gameplay, on the local branch these commits come from: FINAL FANTASY CRYSTAL CHRONICLES Remastered Edition 1.0.3 with the engine's compiled file (a cave patch written once, stats and Mog every frame), the panel's toggles live in the game; 13 Sentinels: Aegis Rim 1.10's community list compiled to 1.00 by cheat_anchor.py with identical writes.

Not checked

  • scripts/regress.py check over local games: the harness is not set up on this Mac (no /Volumes/NX).
  • The iPhone: the engine compiles into the iOS host but was not run there; the menu and panel are Mac-only.

🤖 Generated with Claude Code

@v0lumehi

Copy link
Copy Markdown
Contributor

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.

@Amost-

Amost- commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Hello, working on it

@Amost-

Amost- commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on today's main. The cheat engine and its menu change no launch setting, so nothing here touches the store; said in #388 (comment).

@v0lumehi

Copy link
Copy Markdown
Contributor

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 docs/frontends.md, the way "Saved choices" and "Data folder" are written?

  • the folder (DM_CHEATS, default <DM_ROOT>/cheats, flat or the atmosphere/contents tree), and how it relates to a dataFolder once Mac app: a dataFolder key keeps a game's save, caches and log in one folder a front end chooses #460 lands;
  • <build ID>.txt, <build ID>.enabled (its format: which cheats are on, keyed by what) and <build>.meta.tsv (the typed values), plus the master switch and DM_CHEATS_ON;
  • what a front end may write while the game runs. Does the panel pick up a changed .enabled, or does the front end only write before the start?
  • the iPhone: does hle_cheats.c run there, and where does it look (Documents/cheats, or the per-game Documents/games/<id>/ folder)?

Then a front end can manage cheats without reading the host's code, and a change to the format comes with a docs change.

@Amost-

Amost- commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Done: the branch now has a Cheats section in docs/frontends.md, written as a contract in the style of Saved choices. Your four points, in short (the section has the details):

  • The folder: DM_CHEATS, else <DM_ROOT>/cheats, which for a Mac app is ~/Library/Application Support/nxnative/<title ID>/cheats; flat <build ID>.txt files or a card's atmosphere/contents/<title ID>/cheats/ tree under it. Everything under DM_ROOT moves with a dataFolder once Mac app: a dataFolder key keeps a game's save, caches and log in one folder a front end chooses #460 lands, this folder with it.
  • The files: <build ID>.enabled is one cheat name per line (Name #2 for a duplicate), rewritten atomically on every toggle; <build ID>.meta.tsv (columns by header name, from cheat_anchor.py) and <build ID>.values (name<TAB>value) are optional. The master switch is the flag file .cheats-off-<title ID>; .cheats-running-<title ID> is the host's safe-mode flag, which a front end leaves alone. DM_CHEATS_ON=<name>,… turns cheats on for one start without touching .enabled.
  • While the game runs: the host reads the cheat file and .enabled when it loads them, at the start and on Reload cheats (⌘R), and never watches the folder, so a front end writes before the start or asks for a reload. The panel's refresh reads the engine's state, not the files.
  • The iPhone: the engine is compiled into the iOS host (without safe mode) with the same folder rule, but the iOS app sets neither DM_CHEATS nor DM_ROOT, so cheats are off there unless Documents/env.txt names a folder. The section says a Documents/cheats default is the natural next step; I left that out of this PR so the folder for a device is one decision, not a side effect. Say if you would rather have it in here.

@v0lumehi

Copy link
Copy Markdown
Contributor

@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 docs/frontends.md. It goes into our patch queue as Upstream-Status: forwarded seedds/nxnative#406, with you as the author, and the next bump drops it as soon as this merges. Nothing changes here because of it. Fixes we find while carrying it come back to this branch as suggestions.

@seedds, would a split make the review easier? For example the engine first (hle_cheats.c, the hooks, t_cheats.c, cheats.md), then cheat_anchor.py, then the Mac panel in front_mac.m. Most of the change is new files, the only large edit to an existing file is the panel.

v0lumehi pushed a commit to LNPANDY/NX2Apple that referenced this pull request Oct 29, 2026
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).
v0lumehi pushed a commit to LNPANDY/NX2Apple that referenced this pull request Oct 29, 2026
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.
v0lumehi added a commit to LNPANDY/NX2Apple that referenced this pull request Oct 29, 2026
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.
LNPANDY added a commit to LNPANDY/NX2Apple that referenced this pull request Oct 29, 2026
Amost- and others added 11 commits October 30, 2026 01:46
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]>
seedds added a commit that referenced this pull request Oct 30, 2026
…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]>
@seedds

seedds commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Thank you! This landed on main as ef9f9bb, with you as co-author. The cheat engine, the Mac Cheats panel, cheat_anchor.py and the docs are yours as written, with three changes:

  • Cheats never write over the rewriter's work. patch_nso.py now writes <name>.changed.tsv, the text words it changed (SVC and TLS sites, cuts, lock acquires, jump tables) and the words whose copies run instead (windows, spin waits). Mac apps carry it. A code write that covers one of those words turns the cheat off with the reason. An "off" restore there would put back the Switch's original SVC or TLS read, which doesn't run natively, or undo an ldaxr, and a write into a copied instruction never runs. Without the list (modules from an older rewriter), 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. The mprotect fallback is gone, because on the Mac it raced with the game's cores and on the iPhone the code pages are the app's signed pages. The iPhone runs data cheats only, and the docs say so.

t_cheats covers the refusals (143 checks, also under ASan and UBSan). The new files' clang-tidy findings are fixed or marked with a reason, so the ratchet stays at its baseline. Regression on Mario Wonder, Tears of the Kingdom and Breath of the Wild found no cheat-related change. The full results are in the commit message.

@seedds seedds closed this Oct 30, 2026
@Amost-

Amost- commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

thank you

Arcaneology pushed a commit to Arcaneology/NX2Apple that referenced this pull request Oct 31, 2026
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.
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…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]>
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