fix(mods): code modules made for the console load as the console loads them #3300

Merged
HumanBean merged 9 commits from llun/Longshot:fix/mod-modules-console-order into main 2026-12-06 02:24:39 +00:00
Member

Summary

Mods made for the console or an emulator that bring their own code module (exefs/subsdk1 to subsdk9, beside an
.ips for main) did not work. kuribox's Super Hero Boost (OOT-SuperHeroBoostMod,
MIT) is one: stamina, sprint, an extended HUD, a button remap and more, all in a subsdk9. On v3.1.1, which loaded
no code module, players who installed it had a boot crash (#81's crash-bot signature e2587375ba1d: the patch's
first hook sends the first file open into sdk, nn::crypto's AES, guest 0x1). On main the build leaves it out
instead, so it does nothing. Three things stood in the way, each a place where Longshot was stricter than the
console's loader (a fourth rule comes with the first):

  1. Where the module loads. The console's loader takes the modules in the order rtld, main, subsdk0..9, sdk, so a
    mod's subsdk9 loads right after the game's subsdk0, before sdk. A mod links its module at that address, and
    its patch in main branches to it by a fixed distance. main placed the module after sdk, so those branches
    landed in sdk. Now a mod's subsdk<n> takes the place its file name has in the loader's order, and sdk moves up
    by the modules' room (image::build::layout, take_modules). With no mod module the game's layout is the same as
    before; a module with relocations works at either place. A mod's subsdk0 loads after the game's, not in its place
    (the console would replace the game's).
  2. A module's room. The loader gives a module its segments' end plus the header's bss size in whole pages, and
    zeroes MOD0's bss inside that. Super Hero Boost's MOD0 bss ends 0x20 past the header's count (its fields count from
    the module, not from MOD0), inside the last page: fine on the console, refused on main ("the bss ... is not inside
    the module's ... bytes"). Now the room is counted in pages (Nso::read_tables); a bss past the page is still
    refused.
  3. A patch beside one of Longshot's hook sites. The mod points the bl at f_833e98f0+0x1c4 at its quick select.
    That bl is where items.shortcutConfirm (the mod API's custom items) is hooked: a jump site before the call,
    whose signature takes the call with any target (94000000/fc000000). The site is still found and still runs, but
    main refused the mod's whole patch file for it. Now a site's signature and guard words are needed as their masks
    read them, and the word a site is hooked at may change in one case only: a call its signature takes with any
    target, where the site lets it run (before) or skips that call alone (a jump to the next instruction).
    Whichever function the call reaches, the site runs or skips it whole. Anything else there stays refused: a branch
    (a jump site's own jump would pass its new place, as at cloth.sphere), a call a jump skips more than, a site that
    replaces the instruction, narrows its branch or runs after its call, and a jump's target
    (build-driver's clashes::needs, stopped).
  4. Two mods with a module of one name (subsdk9 twice) cannot both have it at that name's place, where their
    patches branch. The mod lower in the list wins, as for patch bytes and RomFS files; the other's module is left out
    with why, and its mod's code patches with it, since they would branch into the winner's code
    (game_files::modules::one_of_a_name). Eden differs: its layered exefs takes the first mod's file in name order
    and still applies the other mod's patches over it.

These are general rules: nothing names Super Hero Boost. Any console mod with a fixed-address code module, a bss in its
last page, or a call it retargets under a site placed before it, is helped the same way. #2497's save-profiles mod
ships a subsdk9 and an .ips too and may be the same case (not tested: its files aren't on this PC).

How to see it on main: put the mod's exefs/subsdk9 and E0F3CCFAF50065AE4EA01EB5AEB13B1A45DA3348.ips in a
profile's mods/zz-Super-Hero-Boost/exefs/, switch it on and accept its code, build. The build log says
exefs: refused ... .ips (it changes f_833e98f0+0x1c4, ... items.shortcutConfirm ...) and
exefs: left out ... subsdk9 (... the bss 0x20020..0x8f2750 is not inside the module's 0x8f2730 bytes), and the game
has no stamina. Fix only those two and the module lands after sdk, where the patch's branches don't reach it.

Read first: builder/crates/image/src/build.rs (load_slot, take_modules, layout), then
builder/crates/build-driver/src/clashes.rs (needs), then builder/crates/game-files/src/nso.rs (read_tables).
Docs: docs/modding/unsafe.md and docs/dev/reference/mods.md say where a code module loads.

See #2497
See #81

Testing

Tested: Windows 11 (build 26300), RTX 5080, driver 621.47, headless through the PC's job queue. The mod's
module and patch built from kuribox's sources at 0.12.1 (6f2602b), the release's standalone variant (the same
features and link address), with this PC's llvm-mingw clang; its build verified all 29 of its hook sites against this
game's main. A test profile with the mod as an emulator user has it (mods/zz-Super-Hero-Boost/exefs/), switched on
and its code accepted in the builder's window, built with this branch's builder:

  • The build log: exefs: module local/zz-Super-Hero-Boost/exefs/subsdk9, exefs: code ... .ips (192 bytes),
    image: 5 modules.
  • From the repository save castle-gate, A held with the left stick forward for 7 s, then let go: the mod's stamina
    ring shows beside Link and drains while he sprints (picture below). Read from the game's memory through the
    bridge (HOS_CONTROL_MEM=ro): the mod's settings block SHBCFG01 at its console address (main + 0x4F9D000), its
    input hooks' counters rising every frame, its sprint flag 0 standing, 1 sprinting, 0 after; its stamina 75.0 full,
    62.8, 37.6, 12.3 while sprinting, 75.0 again after.
  • 60 fps from start to end (59.7 and 60.7 at the two status reads), no FATAL, exception or crash line in the log.
  • The same run on main's game (the shared base, which is what main builds with this mod: its code left out): no
    ring, and Link covers less ground in the same frames.
  • kokiri-start as well: in play, 60 fps, no crash.
  • Again after the review's fixes (d22aa8d61's builder): the build takes the patch and the module; the sprint flag
    0, 1, 0 and the stamina 75.0, 25.4, 75.0; the menu opens and its cursor moves; 59.6 fps; no FATAL or exception.
  • The mod's in-game menu (- and R3 together, sent through the bridge): it opens and is drawn over the game, its
    cursor moves (picture below). The menu paints itself by wrapping three NVN entry points in the game's table and
    copying its picture onto the frame's HDR buffer; on Longshot its counters show the picture made (704x360,
    R11G11B10F) and copied every frame. It opens only while the mod's own item-button HUD is on (button_mapping and
    hud_custom_items in its settings block), which its factory settings leave off and its app turns on: with them off
    it sees the buttons (0x820) but never takes the game as in play, the mod's rule, not Longshot's. This run had both
    set in the test copy, as the app writes them.

The checks, on Windows (llvm-mingw, gnullvm Rust): each fix's test fails on main for the bug's reason and passes here
(a_mods_code_module_loads_where_the_console_loads_it, a_bss_inside_the_modules_last_page_is_read,
a_call_retargeted_where_the_site_runs_or_skips_it_whole_is_no_clash, an invented site's words; and
two_mods_with_a_module_of_one_name_keep_the_later, new with the review); cargo test -p image -p game-files -p build-driver,
clippy -D warnings and rustfmt on the changed crates. mise run test -- --jobs 12 on this branch over 0b284cc76: 899 passed, 2 failed, 55 skipped. test_lifter stops at ffi-gen's the_repositorys_files_are_current (host/game_host.h's rx_menu_open has no doc comment: it fails on main too, left out in #3294); its rustfmt and clippy steps pass, and as cargo stops at ffi-gen, cargo test -p image -p game-files -p build-driver ran on its own after the rebase: all pass. test_sync_watch_event timed out under the suite's load and passes alone (3.4 s).

Still to test:

  • Linux: build a profile with the mod (its exefs/subsdk9 and .ips) and sprint, expecting the stamina ring and no
    crash, as on Windows (by hand: the mod's files are not in the repository).
  • #2497's save-profiles mod: its Options row (by hand, with its files from its page).

Measurements

Verdict: no cost for a game without a mod's code module (its layout is unchanged); with Super Hero Boost the
game holds 60 fps and its build takes as long as on main, where the mod is left out.

Setup: Windows 11 (26300), RTX 5080, driver 621.47; the test profile's builds over this PC's warm store; the game
headless from castle-gate, the status's fps read twice in play. Observed, not interleaved timed runs: a build's time
here is the store's, and the fps is the game's 60 cap.

Before: main @ 8c0beeec5 (the mod left out) After: this PR @ deb7b7612 (the mod built in)
The test profile's build 2 min 16 s (compile 2 min 3 s) 2 min 15 s (compile 2 min 5 s)
The game's fps in play, Hyrule Field 60 (the shared base) 59.7, 60.7
The image without a mod module rtld, main, subsdk0, sdk the same (the image test)

The numbers still hold on main 0b284cc76: it adds only #3294 over 8c0beeec5, which changes checks, tests and the fog rows' label in the menu, nothing the build, the image or the lift does. Each later build of a profile with such a mod reuses its sdk units from the store (the item-HUD rebuild: 47 s).

Risks

  • A mod with a code module now loads it at the console's address and moves sdk: its first build after this change
    compiles sdk again (minutes, once; switching such a mod already needed a build). A module with relocations is
    placed at another address than before; it is relocated as before.
  • Module start routines run in address order, as rtld runs them: a mod's module starts before sdk's, as on the
    console (it started after on main). Super Hero Boost's module has none.
  • The clash rule is looser only where a patch changes bits a site's signature ignores, at a before or jump site's
    instruction or a signature or guard word; the site is still found, and the lift still stops on one it can't place.
  • Revert is enough. Players without such mods see nothing change.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened. (The checks that read the image crate,
    test_re, test_doc_commands, test_dev_ab, test_dev_update, test_options_path, test_framelog_sink, pass
    unchanged: none reads the functions this changes.)
  • Screenshots of the same spot on main and here, for a change that shows on screen.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

Credit: Super Hero Boost is kuribox's work (MIT); nothing of it is in this PR.

🤖 Generated with Claude Code

## Summary Mods made for the console or an emulator that bring their own code module (`exefs/subsdk1` to `subsdk9`, beside an `.ips` for `main`) did not work. kuribox's **Super Hero Boost** ([OOT-SuperHeroBoostMod](https://github.com/kuribox/OOT-SuperHeroBoostMod), MIT) is one: stamina, sprint, an extended HUD, a button remap and more, all in a `subsdk9`. On v3.1.1, which loaded no code module, players who installed it had a boot crash (#81's crash-bot signature `e2587375ba1d`: the patch's first hook sends the first file open into `sdk`, `nn::crypto`'s AES, guest `0x1`). On `main` the build leaves it out instead, so it does nothing. Three things stood in the way, each a place where Longshot was stricter than the console's loader (a fourth rule comes with the first): 1. **Where the module loads.** The console's loader takes the modules in the order rtld, main, subsdk0..9, sdk, so a mod's `subsdk9` loads right after the game's `subsdk0`, before `sdk`. A mod links its module at that address, and its patch in `main` branches to it by a fixed distance. `main` placed the module after `sdk`, so those branches landed in `sdk`. Now a mod's `subsdk<n>` takes the place its file name has in the loader's order, and `sdk` moves up by the modules' room (`image::build::layout`, `take_modules`). With no mod module the game's layout is the same as before; a module with relocations works at either place. A mod's `subsdk0` loads after the game's, not in its place (the console would replace the game's). 2. **A module's room.** The loader gives a module its segments' end plus the header's bss size in whole pages, and zeroes MOD0's bss inside that. Super Hero Boost's MOD0 bss ends 0x20 past the header's count (its fields count from the module, not from MOD0), inside the last page: fine on the console, refused on `main` ("the bss ... is not inside the module's ... bytes"). Now the room is counted in pages (`Nso::read_tables`); a bss past the page is still refused. 3. **A patch beside one of Longshot's hook sites.** The mod points the `bl` at `f_833e98f0+0x1c4` at its quick select. That `bl` is where `items.shortcutConfirm` (the mod API's custom items) is hooked: a `jump` site *before* the call, whose signature takes the call with any target (`94000000/fc000000`). The site is still found and still runs, but `main` refused the mod's whole patch file for it. Now a site's signature and guard words are needed as their masks read them, and the word a site is hooked at may change in one case only: a call its signature takes with any target, where the site lets it run (`before`) or skips that call alone (a `jump` to the next instruction). Whichever function the call reaches, the site runs or skips it whole. Anything else there stays refused: a branch (a jump site's own jump would pass its new place, as at `cloth.sphere`), a call a jump skips more than, a site that replaces the instruction, narrows its branch or runs after its call, and a jump's target (`build-driver`'s `clashes::needs`, `stopped`). 4. **Two mods with a module of one name** (`subsdk9` twice) cannot both have it at that name's place, where their patches branch. The mod lower in the list wins, as for patch bytes and RomFS files; the other's module is left out with why, and its mod's code patches with it, since they would branch into the winner's code (`game_files::modules::one_of_a_name`). Eden differs: its layered exefs takes the first mod's file in name order and still applies the other mod's patches over it. These are general rules: nothing names Super Hero Boost. Any console mod with a fixed-address code module, a bss in its last page, or a call it retargets under a site placed before it, is helped the same way. #2497's save-profiles mod ships a `subsdk9` and an `.ips` too and may be the same case (not tested: its files aren't on this PC). **How to see it on `main`:** put the mod's `exefs/subsdk9` and `E0F3CCFAF50065AE4EA01EB5AEB13B1A45DA3348.ips` in a profile's `mods/zz-Super-Hero-Boost/exefs/`, switch it on and accept its code, build. The build log says `exefs: refused ... .ips (it changes f_833e98f0+0x1c4, ... items.shortcutConfirm ...)` and `exefs: left out ... subsdk9 (... the bss 0x20020..0x8f2750 is not inside the module's 0x8f2730 bytes)`, and the game has no stamina. Fix only those two and the module lands after `sdk`, where the patch's branches don't reach it. **Read first:** `builder/crates/image/src/build.rs` (`load_slot`, `take_modules`, `layout`), then `builder/crates/build-driver/src/clashes.rs` (`needs`), then `builder/crates/game-files/src/nso.rs` (`read_tables`). Docs: `docs/modding/unsafe.md` and `docs/dev/reference/mods.md` say where a code module loads. See #2497 See #81 ## Testing **Tested:** Windows 11 (build 26300), RTX 5080, driver 621.47, headless through the PC's job queue. The mod's module and patch built from kuribox's sources at 0.12.1 (`6f2602b`), the release's standalone variant (the same features and link address), with this PC's llvm-mingw clang; its build verified all 29 of its hook sites against this game's `main`. A test profile with the mod as an emulator user has it (`mods/zz-Super-Hero-Boost/exefs/`), switched on and its code accepted in the builder's window, built with this branch's builder: - The build log: `exefs: module local/zz-Super-Hero-Boost/exefs/subsdk9`, `exefs: code ... .ips (192 bytes)`, `image: 5 modules`. - From the repository save `castle-gate`, A held with the left stick forward for 7 s, then let go: the mod's stamina ring shows beside Link and drains while he sprints (picture below). Read from the game's memory through the bridge (`HOS_CONTROL_MEM=ro`): the mod's settings block `SHBCFG01` at its console address (main + 0x4F9D000), its input hooks' counters rising every frame, its sprint flag 0 standing, 1 sprinting, 0 after; its stamina 75.0 full, 62.8, 37.6, 12.3 while sprinting, 75.0 again after. - 60 fps from start to end (59.7 and 60.7 at the two status reads), no FATAL, exception or crash line in the log. - The same run on `main`'s game (the shared base, which is what `main` builds with this mod: its code left out): no ring, and Link covers less ground in the same frames. - `kokiri-start` as well: in play, 60 fps, no crash. - Again after the review's fixes (`d22aa8d61`'s builder): the build takes the patch and the module; the sprint flag 0, 1, 0 and the stamina 75.0, 25.4, 75.0; the menu opens and its cursor moves; 59.6 fps; no FATAL or exception. - The mod's in-game menu (`-` and `R3` together, sent through the bridge): it opens and is drawn over the game, its cursor moves (picture below). The menu paints itself by wrapping three NVN entry points in the game's table and copying its picture onto the frame's HDR buffer; on Longshot its counters show the picture made (704x360, R11G11B10F) and copied every frame. It opens only while the mod's own item-button HUD is on (`button_mapping` and `hud_custom_items` in its settings block), which its factory settings leave off and its app turns on: with them off it sees the buttons (`0x820`) but never takes the game as in play, the mod's rule, not Longshot's. This run had both set in the test copy, as the app writes them. The checks, on Windows (llvm-mingw, gnullvm Rust): each fix's test fails on `main` for the bug's reason and passes here (`a_mods_code_module_loads_where_the_console_loads_it`, `a_bss_inside_the_modules_last_page_is_read`, `a_call_retargeted_where_the_site_runs_or_skips_it_whole_is_no_clash`, an invented site's words; and `two_mods_with_a_module_of_one_name_keep_the_later`, new with the review); `cargo test -p image -p game-files -p build-driver`, clippy `-D warnings` and rustfmt on the changed crates. `mise run test -- --jobs 12` on this branch over `0b284cc76`: 899 passed, 2 failed, 55 skipped. `test_lifter` stops at `ffi-gen`'s `the_repositorys_files_are_current` (`host/game_host.h`'s `rx_menu_open` has no doc comment: it fails on `main` too, left out in #3294); its rustfmt and clippy steps pass, and as cargo stops at `ffi-gen`, `cargo test -p image -p game-files -p build-driver` ran on its own after the rebase: all pass. `test_sync_watch_event` timed out under the suite's load and passes alone (3.4 s). **Still to test:** - Linux: build a profile with the mod (its `exefs/subsdk9` and `.ips`) and sprint, expecting the stamina ring and no crash, as on Windows (by hand: the mod's files are not in the repository). - #2497's save-profiles mod: its Options row (by hand, with its files from its page). ## Measurements **Verdict:** no cost for a game without a mod's code module (its layout is unchanged); with Super Hero Boost the game holds 60 fps and its build takes as long as on `main`, where the mod is left out. Setup: Windows 11 (26300), RTX 5080, driver 621.47; the test profile's builds over this PC's warm store; the game headless from `castle-gate`, the status's fps read twice in play. Observed, not interleaved timed runs: a build's time here is the store's, and the fps is the game's 60 cap. | | Before: main @ `8c0beeec5` (the mod left out) | After: this PR @ `deb7b7612` (the mod built in) | |---|---|---| | The test profile's build | 2 min 16 s (compile 2 min 3 s) | 2 min 15 s (compile 2 min 5 s) | | The game's fps in play, Hyrule Field | 60 (the shared base) | 59.7, 60.7 | | The image without a mod module | rtld, main, subsdk0, sdk | the same (the image test) | The numbers still hold on main `0b284cc76`: it adds only #3294 over `8c0beeec5`, which changes checks, tests and the fog rows' label in the menu, nothing the build, the image or the lift does. Each later build of a profile with such a mod reuses its `sdk` units from the store (the item-HUD rebuild: 47 s). ## Risks - A mod with a code module now loads it at the console's address and moves `sdk`: its first build after this change compiles `sdk` again (minutes, once; switching such a mod already needed a build). A module with relocations is placed at another address than before; it is relocated as before. - Module start routines run in address order, as rtld runs them: a mod's module starts before `sdk`'s, as on the console (it started after on `main`). Super Hero Boost's module has none. - The clash rule is looser only where a patch changes bits a site's signature ignores, at a `before` or `jump` site's instruction or a signature or guard word; the site is still found, and the lift still stops on one it can't place. - Revert is enough. Players without such mods see nothing change. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. (The checks that read the image crate, `test_re`, `test_doc_commands`, `test_dev_ab`, `test_dev_update`, `test_options_path`, `test_framelog_sink`, pass unchanged: none reads the functions this changes.) - [x] Screenshots of the same spot on `main` and here, for a change that shows on screen. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. Credit: Super Hero Boost is kuribox's work (MIT); nothing of it is in this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A test of the image's layout with a mod's exefs/subsdk9: the console and the emulators put it after the game's
subsdk0 and before sdk, where its patch in main branches. On main it is laid out after sdk. The image's step that
puts the game's and the mods' modules together moves into image::build::layout (no change in what it does).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A mod's exefs/subsdk<n> now takes the place its file name has in the system loader's order (rtld, main,
subsdk0..9, sdk): after the game's modules up to that name and before sdk, which moves up by the modules' room. A
mod made for the console or an emulator links its module there and its patch in main branches to it by a fixed
distance: placed after sdk, those branches landed in sdk (zz-Super-Hero-Boost's first file open went into
nn::crypto's AES and the game stopped at boot). A module with relocations works at either place. With no mod module
the game's layout is the same; a mod's subsdk0 loads after the game's, not in its place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The system's loader gives a module its segments' end plus the header's bss size in whole pages and zeroes MOD0's
bss there. Super Hero Boost's subsdk9 names a MOD0 bss 0x20 past the header's count, inside the page: it loads on the
console and in the emulators, and main refuses it ("the bss ... is not inside the module's ... bytes").

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The loader gives a module its segments' end plus the header's bss size in whole pages; a MOD0 bss that ends inside
that last page is zeroed there on the console and in the emulators. main counted the bytes exactly and refused such a
module, Super Hero Boost's subsdk9 among them (its MOD0 bss fields count from the module, not from MOD0: 0x20 past).
A bss past the page is still refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
items.shortcutConfirm is a jump site before a `bl` its signature takes with any target; Super Hero Boost points that
`bl` at its quick select. The site is still found and still runs before the call, but main refuses the mod's whole
patch file for it. The words a site needs move into clashes::needs and clashes::stopped (no change in what they
decide), and the test says what they should decide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(mods): a patch that changes only bits a hook site's signature ignores, before the site, is no clash
Some checks failed
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / What the change needs (pull_request) Waiting to run
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Waiting to run
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Has been cancelled
deb7b7612d
A site's signature and guards are needed as their words read them: a change to a bit a word ignores (a call's target
where the site takes any call) leaves the site found. A site placed before an instruction (before, jump) does not
read that instruction, so its word needs only what the signature reads; any other form at an instruction (replace,
branch, allow, after) still needs it as it is, and a jump's target too. Super Hero Boost's quick select points
items.shortcutConfirm's call at its own code; its patch file was refused whole for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Tested in game: Windows 11 (26300), RTX 5080, driver 621.47, headless through the job queue. kuribox's Super Hero Boost (built from its 0.12.1 sources, the release's standalone variant) in a test profile as an emulator user has it (exefs/subsdk9 + the .ips), code accepted: the build takes the module and the patch (image: 5 modules); from castle-gate, A held with the stick forward: the stamina ring shows and drains, the mod's sprint flag and stamina read from memory follow it (75.0 -> 12.3 -> 75.0), 60 fps, no crash; its in-game menu (- and R3) opens and draws over the game with its item HUD on. Same spot on main: no ring, Link slower. kokiri-start: in play, 60 fps.

Tested in game: Windows 11 (26300), RTX 5080, driver 621.47, headless through the job queue. kuribox's Super Hero Boost (built from its 0.12.1 sources, the release's standalone variant) in a test profile as an emulator user has it (exefs/subsdk9 + the .ips), code accepted: the build takes the module and the patch (image: 5 modules); from castle-gate, A held with the stick forward: the stamina ring shows and drains, the mod's sprint flag and stamina read from memory follow it (75.0 -> 12.3 -> 75.0), 60 fps, no crash; its in-game menu (- and R3) opens and draws over the game with its item HUD on. Same spot on main: no ring, Link slower. kokiri-start: in play, 60 fps.
Author
Member

Pictures from the runs in Testing (Windows 11, RTX 5080, castle-gate, the same frame after A held with the stick forward).

main (the shared base: the game main builds with this mod, its code left out): no stamina ring.
main

This PR, with kuribox's Super Hero Boost: the mod's stamina ring beside Link, draining; Link further out (its sprint is 125%).
this PR

This PR, the mod's in-game menu (- and R3, then Down), with its item HUD on in the test copy:
menu

Pictures from the runs in Testing (Windows 11, RTX 5080, castle-gate, the same frame after A held with the stick forward). **main** (the shared base: the game main builds with this mod, its code left out): no stamina ring. ![main](https://git.magicbean.dev/attachments/c78d6c42-9c91-4277-bdb4-a7dc60269ef0) **This PR**, with kuribox's Super Hero Boost: the mod's stamina ring beside Link, draining; Link further out (its sprint is 125%). ![this PR](https://git.magicbean.dev/attachments/a9e1f8bb-97b2-43d6-a360-c7d0504b9e12) **This PR**, the mod's in-game menu (- and R3, then Down), with its item HUD on in the test copy: ![menu](https://git.magicbean.dev/attachments/74f8fe9e-d417-46b5-b688-1bf77f0c9ff1)
Member

Possibly related, for context:

  • issue #2953 Install: one ExeFS patch on a function's entry stops the build at frame.stepDivide — Related ExeFS hook-site clash behavior in the builder
Possibly related, for context: - issue #2953 Install: one ExeFS patch on a function's entry stops the build at frame.stepDivide — Related ExeFS hook-site clash behavior in the builder
Author
Member

Measurements: the base main moved to 0b284cc76 (#3294: checks, tests and a menu label only); the numbers still hold, said in the description.

Measurements: the base main moved to 0b284cc76 (#3294: checks, tests and a menu label only); the numbers still hold, said in the description.
llun changed title from WIP: fix(mods): code modules made for the console load as the console loads them to fix(mods): code modules made for the console load as the console loads them 2026-12-06 02:01:36 +00:00
Author
Member
@review
BeanBot left a comment

Recommendation: Request changes. The hook clash check can accept a patch that changes the behavior a native hook replaces, and the new test commits instructions copied from the game. The intended mod works in the reported Windows run, but these problems need edits before merge.

The change places mod code modules before the SDK, accepts BSS within the last allocated page, and permits some patches at hook sites. It enables the tested mod, but the broader clash rule can produce incorrect game behavior.

Blocking (3): must change before merging.

  1. L1 builder/crates/build-driver/src/clashes.rs:43: A jump site's masked instruction is not always independent of the native hook's behavior. (more on the line) Do: Keep jump-site instructions exact unless the site explicitly establishes that changing the instruction is safe, or otherwise validate the changed target against the hook's semantics. Add a test for a retargeted jump whose callback takes the skip path.
  2. L2 builder/crates/build-driver/src/clashes.rs:183: The new test copies a sequence of the game's instructions into another committed file. (more on the line) Do: Use invented instruction words, a synthetic address, and a synthetic site to exercise the same masked-call behavior.
  3. L3 builder/crates/image/src/build.rs:184: Two enabled mods with the same subsdk name are both placed, although their fixed-address patches can target only the first module's console slot. (more on the line) Do: Resolve duplicate ExeFS module names according to the mod overlay precedence, mark the displaced module and its incompatible patch clearly, and test two enabled mods using the same slot.

@fix can do L1, L2 and L3.

Questions (1) (not confirmed from the code; they don't hold the recommendation)

  • builder/crates/build-driver/src/clashes.rs:198: Is there a current patch-refusal failure this test misses?

Checks: Still running: 11 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes for the tested mod: the reported Windows run built its module and patch, showed the stamina ring, and observed stamina drain and recover. Linux and the save-profiles mod remain untested.

Other systems: Module ordering also changes symbol resolution and initialization order for builds with code mods. Hook clash detection affects existing native game hooks as well as the tested mod; the reported run does not cover every such hook.

Switches: None added, changed, or removed.

Reviewed: deb7b7612d against 0b284cc767: Read the repository rules, PR template, commit messages, diff, changed Rust code and documentation, and relevant site definitions and resolver code. Skimmed unrelated tests and generated material; the linked screenshots were not available in the closed network.; nothing run (a code review).

Checked and fine:

  • The reported Windows run demonstrates the intended mod's stamina and menu behavior.
  • The BSS bound is rounded to the same page size used for module placement, and a past-page BSS has a synthetic test.
  • The commits record AI assistance; no switches or API versions are changed.

Testing: No commands from the project were run. The author reports game-free crate tests and an in-game Windows run; Linux remains to be tested, and CI is still running.

Overlaps and merge order: None found in the supplied review context.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as llun took it out of WIP. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The hook clash check can accept a patch that changes the behavior a native hook replaces, and the new test commits instructions copied from the game. The intended mod works in the reported Windows run, but these problems need edits before merge. The change places mod code modules before the SDK, accepts BSS within the last allocated page, and permits some patches at hook sites. It enables the tested mod, but the broader clash rule can produce incorrect game behavior. **Blocking (3)**: must change before merging. 1. **L1** `builder/crates/build-driver/src/clashes.rs:43`: A jump site's masked instruction is not always independent of the native hook's behavior. (more on the line) **Do:** Keep jump-site instructions exact unless the site explicitly establishes that changing the instruction is safe, or otherwise validate the changed target against the hook's semantics. Add a test for a retargeted jump whose callback takes the skip path. 2. **L2** `builder/crates/build-driver/src/clashes.rs:183`: The new test copies a sequence of the game's instructions into another committed file. (more on the line) **Do:** Use invented instruction words, a synthetic address, and a synthetic site to exercise the same masked-call behavior. 3. **L3** `builder/crates/image/src/build.rs:184`: Two enabled mods with the same subsdk name are both placed, although their fixed-address patches can target only the first module's console slot. (more on the line) **Do:** Resolve duplicate ExeFS module names according to the mod overlay precedence, mark the displaced module and its incompatible patch clearly, and test two enabled mods using the same slot. `@fix` can do L1, L2 and L3. **Questions (1)** (not confirmed from the code; they don't hold the recommendation) - `builder/crates/build-driver/src/clashes.rs:198`: Is there a current patch-refusal failure this test misses? **Checks:** Still running: 11 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the tested mod: the reported Windows run built its module and patch, showed the stamina ring, and observed stamina drain and recover. Linux and the save-profiles mod remain untested. **Other systems:** Module ordering also changes symbol resolution and initialization order for builds with code mods. Hook clash detection affects existing native game hooks as well as the tested mod; the reported run does not cover every such hook. **Switches:** None added, changed, or removed. **Reviewed:** deb7b7612d7d against 0b284cc7673f: Read the repository rules, PR template, commit messages, diff, changed Rust code and documentation, and relevant site definitions and resolver code. Skimmed unrelated tests and generated material; the linked screenshots were not available in the closed network.; nothing run (a code review). **Checked and fine:** - The reported Windows run demonstrates the intended mod's stamina and menu behavior. - The BSS bound is rounded to the same page size used for module placement, and a past-page BSS has a synthetic test. - The commits record AI assistance; no switches or API versions are changed. **Testing:** No commands from the project were run. The author reports game-free crate tests and an in-game Windows run; Linux remains to be tested, and CI is still running. **Overlaps and merge order:** None found in the supplied review context. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as llun took it out of WIP. Nothing was run; a maintainer decides.</sub>
@ -13,0 +40,4 @@
masked(entry + (g.offset / 4) as i64, &g.signature);
}
if let Some(off) = c.offset {
let k = entry + if c.form.at_offset() { (off / 4) as i64 } else { 0 };
Member

L1 (blocking): A jump site's masked instruction is not always independent of the native hook's behavior. Retargeting its branch can change the path that the hook substitutes.

When: At cloth.sphere, the hook runs before a masked unconditional branch into the original record loop. A patch can retarget that branch and pass this check; when the native callback returns nonzero, the jump site instead skips to its fixed original destination, bypassing the mod's new target.

Do: Keep jump-site instructions exact unless the site explicitly establishes that changing the instruction is safe, or otherwise validate the changed target against the hook's semantics. Add a test for a retargeted jump whose callback takes the skip path.

**L1** (blocking): A jump site's masked instruction is not always independent of the native hook's behavior. Retargeting its branch can change the path that the hook substitutes. *When:* At cloth.sphere, the hook runs before a masked unconditional branch into the original record loop. A patch can retarget that branch and pass this check; when the native callback returns nonzero, the jump site instead skips to its fixed original destination, bypassing the mod's new target. **Do:** Keep jump-site instructions exact unless the site explicitly establishes that changing the instruction is safe, or otherwise validate the changed target against the hook's semantics. Add a test for a retargeted jump whose callback takes the skip path.
@ -130,0 +180,4 @@
wrapper: None,
// (items.shortcutConfirm's: four moves, any call, a load)
signature: Some(
sites::Signature::parse("52800023 52800024 2a1903e2 aa1503e1 94000000/fc000000 f9403668").unwrap(),
Member

L2 (blocking): The new test copies a sequence of the game's instructions into another committed file. The repository rule prohibits committing game code or material made from the game.

When: The test identifies these words as the real shortcutConfirm signature and repeats the instruction sequence from the game's site table.

Do: Use invented instruction words, a synthetic address, and a synthetic site to exercise the same masked-call behavior.

**L2** (blocking): The new test copies a sequence of the game's instructions into another committed file. The repository rule prohibits committing game code or material made from the game. *When:* The test identifies these words as the real shortcutConfirm signature and repeats the instruction sequence from the game's site table. **Do:** Use invented instruction words, a synthetic address, and a synthetic site to exercise the same masked-call behavior.
@ -146,0 +181,4 @@
let mut modules = Vec::with_capacity(game.len() + mods.len());
let mut mods = mods.into_iter().peekable();
for g in game {
while let Some(m) = mods.next_if(|m| load_slot(&m.name) < load_slot(&g.name)) {
Member

L3 (blocking): Two enabled mods with the same subsdk name are both placed, although their fixed-address patches can target only the first module's console slot.

When: If two console mods each supply subsdk9 linked for the same slot and each patches main to call its own module, layout puts the second module after the first. The second mod's fixed branch still reaches the first module at that offset, potentially executing unrelated code or crashing.

Do: Resolve duplicate ExeFS module names according to the mod overlay precedence, mark the displaced module and its incompatible patch clearly, and test two enabled mods using the same slot.

**L3** (blocking): Two enabled mods with the same subsdk name are both placed, although their fixed-address patches can target only the first module's console slot. *When:* If two console mods each supply subsdk9 linked for the same slot and each patches main to call its own module, layout puts the second module after the first. The second mod's fixed branch still reaches the first module at that offset, potentially executing unrelated code or crashing. **Do:** Resolve duplicate ExeFS module names according to the mod overlay precedence, mark the displaced module and its incompatible patch clearly, and test two enabled mods using the same slot.
Review (BeanBot, L1 and L2): a jump site placed before a branch would pass the branch's new place with its own jump
(cloth.sphere's), so the word a site is hooked at may change only where its signature takes any call there and the
site lets that call run (before) or skips it alone (a jump to the next instruction). Any other change there is
refused as before. The test is of an invented site, with invented words at a made-up address, and adds the branch,
a jump past more than the call, and the branch and allow forms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review (BeanBot, L3): the system's loader takes one file of each name, so two mods that bring a subsdk9 cannot both
have their module at that name's place, where their patches branch. The later in the list wins, as a later patch
file wins its bytes; the earlier's module is left out, said, and its mod's code patches with it (they would branch
into the other mod's code); its data patches stay (game_files::modules::one_of_a_name, called by the read stage).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs(mods): one_of_a_name says where Eden's order differs, and why the list's one rule is kept
Some checks are pending
PR description / Title and description (pull_request_target) Waiting to run
d22aa8d610
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Thanks, all three made (19be0a53d, 59382510d, d22aa8d61), and the in-game run done again on them (Testing).

  • L1 (clashes.rs): agreed, a jump site's branch pointed elsewhere would be passed by the site's own jump. The word a site is hooked at may now change in one case only: a call its signature takes with any target, where the site lets it run (before) or skips that call alone (a jump whose to is the next instruction). Whichever function the call reaches, the site runs or skips it whole. A branch there, a call a jump skips more than, and every other form stay refused. The test has the branch case (cloth.sphere's shape) and a jump past more than the call. The skip path itself is the site's own jump, which this rule now only allows over a call it skips whole; there is no game-free way to run the callback here, so the rule is tested where it decides.
  • L2 (the test): it is now an invented site: made-up words (11111111 22222222 33333333 94000000/fc000000 44444444), a made-up address, nothing from the game. (The earlier words were game/sites/sites.toml's own committed signature, but a test needs none of them.)
  • L3 (two mods with one module name): now one module of a name loads, the mod's lower in the list, as for patch bytes and RomFS files (game_files::modules::one_of_a_name, called by the read stage before the lists are written). The other's module is left out with why (exefs_modules.txt, the Mods tab), and its mod's code patch files are refused with it (Unsupported, the note naming the module), since they branch to that place; its data patches stay. Test: two_mods_with_a_module_of_one_name_keep_the_later. For the record, Eden takes the first mod's file in name order and still applies the other's patches over it; the list's one rule was chosen on purpose (the PR's Summary, item 4).
  • The question (clashes.rs:198): the test covers the decision needs and stopped make; refuse's other check, a patch that makes the signature match a second place, is unchanged by this PR.

cargo test -p game-files -p build-driver -p image, clippy -D warnings and rustfmt pass on the head.

Thanks, all three made (`19be0a53d`, `59382510d`, `d22aa8d61`), and the in-game run done again on them (Testing). - **L1** (clashes.rs): agreed, a jump site's branch pointed elsewhere would be passed by the site's own jump. The word a site is hooked at may now change in one case only: a call its signature takes with any target, where the site lets it run (`before`) or skips that call alone (a `jump` whose `to` is the next instruction). Whichever function the call reaches, the site runs or skips it whole. A branch there, a call a jump skips more than, and every other form stay refused. The test has the branch case (`cloth.sphere`'s shape) and a jump past more than the call. The skip path itself is the site's own jump, which this rule now only allows over a call it skips whole; there is no game-free way to run the callback here, so the rule is tested where it decides. - **L2** (the test): it is now an invented site: made-up words (`11111111 22222222 33333333 94000000/fc000000 44444444`), a made-up address, nothing from the game. (The earlier words were `game/sites/sites.toml`'s own committed signature, but a test needs none of them.) - **L3** (two mods with one module name): now one module of a name loads, the mod's lower in the list, as for patch bytes and RomFS files (`game_files::modules::one_of_a_name`, called by the read stage before the lists are written). The other's module is left out with why (`exefs_modules.txt`, the Mods tab), and its mod's code patch files are refused with it (`Unsupported`, the note naming the module), since they branch to that place; its data patches stay. Test: `two_mods_with_a_module_of_one_name_keep_the_later`. For the record, Eden takes the *first* mod's file in name order and still applies the other's patches over it; the list's one rule was chosen on purpose (the PR's Summary, item 4). - **The question** (clashes.rs:198): the test covers the decision `needs` and `stopped` make; `refuse`'s other check, a patch that makes the signature match a second place, is unchanged by this PR. `cargo test -p game-files -p build-driver -p image`, clippy `-D warnings` and rustfmt pass on the head.
Author
Member
@review
BeanBot left a comment

Recommendation: Approve. The three requested fixes are in place: unsafe retargeting remains refused, the test uses invented words, and duplicate module names no longer produce two placed modules. The reported Windows run shows the target mod working after the fixes. Recommend approval; not approved on the forge.

Console mods can load code modules in loader order, use BSS space within the final page, and retarget a compatible hook-site call. Duplicate module names now have a defined winner, at the cost of leaving the other mod’s module and code patches out.

Since the last review (on deb7b7612d)
Resolved: L1 (A jump site's masked instruction is not always independent of the native hook's behavior.…); L2 (The new test copies a sequence of the game's instructions into another committed file. The…); L3 (Two enabled mods with the same subsdk name are both placed, although their fixed-address p…)

Checks: Still running: PR description / Title and description (pull_request_target).

Also noticed (2; not asked for, not blocking)
  • The Linux mod build and play run and the save-profiles mod run remain listed as still to test.
  • The title and description CI check is still running.
More: does it help, other systems, switches, what was read

Does it help: Yes. The reported Windows run shows Super Hero Boost’s stamina changing from 75.0 to 25.4 and back to 75.0, with its menu working. This is a functional fix; the reported single build and capped-FPS observations do not establish a performance gain.

Other systems: The builder and resulting module layout affect Windows and Linux. The reported game run covers Windows on NVIDIA; a Linux mod build and play run and the save-profiles mod remain untested.

Switches: None added, changed or removed.

Reviewed: d22aa8d610 against 0b284cc767: Read the changes since the ledger, the affected selection and clash paths, AGENTS.md, CONTRIBUTING.md and the pull request template. Skimmed the remaining pull request diff and recorded test results; the other changed code files were not read in full.; nothing run (a code review).

Checked and fine:

  • The duplicate-name selection ignores modules already left out and retains data patches.
  • The reported post-fix Windows run exercises the target mod’s sprint and menu.

Testing: Read-only review; no tests or project scripts were run. The author reports passing changed-crate tests, clippy and rustfmt, plus an in-game Windows run after the fixes.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The three requested fixes are in place: unsafe retargeting remains refused, the test uses invented words, and duplicate module names no longer produce two placed modules. The reported Windows run shows the target mod working after the fixes. Recommend approval; not approved on the forge. Console mods can load code modules in loader order, use BSS space within the final page, and retarget a compatible hook-site call. Duplicate module names now have a defined winner, at the cost of leaving the other mod’s module and code patches out. **Since the last review** (on deb7b7612d7d) Resolved: L1 (A jump site's masked instruction is not always independent of the native hook's behavior.…); L2 (The new test copies a sequence of the game's instructions into another committed file. The…); L3 (Two enabled mods with the same subsdk name are both placed, although their fixed-address p…) **Checks:** Still running: `PR description / Title and description (pull_request_target)`. <details> <summary>Also noticed (2; not asked for, not blocking)</summary> - The Linux mod build and play run and the save-profiles mod run remain listed as still to test. - The title and description CI check is still running. </details> <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes. The reported Windows run shows Super Hero Boost’s stamina changing from 75.0 to 25.4 and back to 75.0, with its menu working. This is a functional fix; the reported single build and capped-FPS observations do not establish a performance gain. **Other systems:** The builder and resulting module layout affect Windows and Linux. The reported game run covers Windows on NVIDIA; a Linux mod build and play run and the save-profiles mod remain untested. **Switches:** None added, changed or removed. **Reviewed:** d22aa8d610ee against 0b284cc7673f: Read the changes since the ledger, the affected selection and clash paths, AGENTS.md, CONTRIBUTING.md and the pull request template. Skimmed the remaining pull request diff and recorded test results; the other changed code files were not read in full.; nothing run (a code review). **Checked and fine:** - The duplicate-name selection ignores modules already left out and retains data patches. - The reported post-fix Windows run exercises the target mod’s sprint and menu. **Testing:** Read-only review; no tests or project scripts were run. The author reports passing changed-crate tests, clippy and rustfmt, plus an in-game Windows run after the fixes. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch fix/mod-modules-console-order 2026-12-06 02:24:39 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!3300
No description provided.