feat(mods): two mods' ExeFS patches that write one place differently are named, and the lower one wins every byte #3165
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3165
Loading…
Reference in a new issue
No description provided.
Delete branch "snaildev99/Longshot:mods/exefs-overlaps"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
When two mods' ExeFS patches (
.ips,.ips32,.pchtxt) write the same place in the game's code differently, thebuild picked a winner byte by byte and said nothing. So a player had no way to know that one of their mods was partly
overwritten, which is the first thing to know when a mod "does nothing" or the game crashes. There was also a fault:
where the lower mod writes the game's own byte back over the higher mod's change, that byte was dropped (the build
keeps only the bytes that differ from the game), so the place held a mix of both mods' code. Emulators write every
byte of each patch in list order, so there the lower mod's patch is used whole.
With this change the build names every place two patch files write differently, in the build log and in both files'
notes, and the Mods tab shows that note first (a file's note names three overlaps and counts the others, so the patch
list the game reads stays short however many places mods dispute). The lower file in the list wins every byte it
writes, including a byte
it restores to the game's value. A mod that writes a disputed byte is built in (it needs a build to turn on or off,
so the named winner stays true across restarts); other mods keep restart switching.
This is the Rust port of #961, which was written for the old Python builder.
Read first:
builder/crates/game-files/src/patches.rs(overlaps, called bycollect),builder/crates/game-files/src/switches.rs, thengame/crates/api/src/loader/exefs.rsandloader/mod.rs(thenote on the Mods tab).
Testing
Tested: Windows 11 Pro, RTX 3090, NVIDIA 610.88, in the game, built by
longshot-builder play --profilewiththis PR and the other mod compatibility ports merged (the same test profile for all of them), adult Link in Kakariko.
Rupee Counter (an
.ipshook and a code module) with an Atmosphere patch set below it that writes back the 4 bytes ofRupee Counter's hook. The build log says:
exefs: local/rupee-counter-off/exefs/E0F3CCFAF50065AE4EA01EB5AEB13B1A45DA3348.ips wins by list order where 4 bytes differ (main+33C3B80-33C3B83). Also written by local/rupee-counter/exefs/E0F3CCFAF50065AE4EA01EB5AEB13B1A45DA3348.ips.In the game the rupee counter is gone, as on an emulator. HUD of Time, in the same build, still shows. The Mods tab
pages of both mods start with the overlap, on
mainneither says anything (screenshots in the comments).Game-free: the
overlaps_*tests ingame-filesandthe_mods_tab_shows_a_later_files_overlap_firstinapi(below). After the review two more:
overlaps_a_restoring_file_above_the_hook_leaves_the_hook(the reverse order: thefile that writes the game's word back above the hook, which then wins all 4 bytes) and
overlaps_keep_each_files_note_short_however_many_places_differ(eight mods and 128 bytes, each written by another setof them: each note names three overlaps and counts the rest, the log names all 128; on the earlier head one note named
67).
Rebased onto
main@3a0f7d8f7, here @d30a27407:cargo test -p game-files73 passed (69 in the library, 4 in itsother targets);
cargo test -p build-driver --test driver9 passed;cargo test -p api -- loader::153 passed (the Mods tab test among them);clippy -p game-files --no-deps --all-targets -- -D warningsclean (without--no-depsit stops onmain's ownerrors:
host-sys's "large array defined as const" and an unused import inbuild-core'ssandbox_windows.rs);rustfmt clean;
tests/test_doc_anchors.pyandtests/test_mise_build.pypass;tests/test_parity_gates.py56 of 57,its
test_the_session_is_stoppedfailing on this PC's drives (the checkout on G:, the temp folder on C:, so "path is onmount 'G:', start on mount 'C:'"), not on
loader/mod.rs, whose lines it reads and finds.build-driver's librarytests: 224 passed, 2 failed, both outside this PR (
the_repository_s_lock_and_the_table_agree, which #3192 names asfailing on
main, andprepare_only_says_in_one_line_when_the_caches_stand, which sees this PC'sLONGSHOT_NO_PREPARE).mise run test, run locally while CI's run waits for approval (Windows 11,tests/run_all.py --strict, 12 checks atonce), here @
d30a27407and onmain@3a0f7d8f7: 847 passed, 12 failed, 52 skipped here; 845 passed, 14 failed, 52skipped on
main. All 12 also fail onmain: test_dlssg, test_fsr4_tune, test_lifter, test_no_game_title,test_no_map_reload, test_present_acquire_ahead, test_present_geometry_trace, test_present_held_image,
test_present_image_free, test_sync_watch_event, test_turf_budget, test_ui_renderer.
Rupee Counter off then moved above Rupee Counter in the same profile: Play built the game again (
fast check: not built yet, a new game folder for the new order), the log saidexefs: local/rupee-counter/exefs/E0F3CCFAF50065AE4EA01EB5AEB13B1A45DA3348.ips wins by list order where 4 bytes differ (main+33C3B80-33C3B83). Also written by local/rupee-counter-off/exefs/E0F3CCFAF50065AE4EA01EB5AEB13B1A45DA3348.ips.,and in the game the rupee counter is back (screenshot in the comments).
After the rebase onto
main@3a0f7d8f7and the review's fixes, here @d30a27407, built with the other ports merged(929bf025a), the same profile again: the same build line (Rupee Counter off wins at main+33C3B80-33C3B83), the rupee
counter gone and HUD of Time's clock shown, and both mods' pages starting with the overlap. With Rupee Counter off
moved above Rupee Counter: a new game folder, the line flipped (Rupee Counter wins), and the counter back (549/1000;
screenshots in the comments).
Still to test:
main(measurement, the review's L2)Measurements
Verdict: It works: the overlap is named and the lower mod's patch is used whole. Nothing changes per frame; the
pass runs in the build, over the patch files' bytes (137 bytes in the test profile).
Setup: the game-free tests; then the test profile above built in the game on Windows 11, RTX 3090.
f577a1aeaf4071ee12(the build log the same @d30a27407, Testing)cargo test -p game-files overlaps_d30a27407cargo test -p api the_mods_tab_shows_a_later_files_overlap_firstcargo test -p game-filesd30a27407, onmain@3a0f7d8f7.ipsexefs: empty(its 4 bytes are the game's, so it was dropped, and Rupee Counter's hook stays), no word of the overlapwins by list order where 4 bytes differ (main+33C3B80-33C3B83)The before side's line is from
main's own build of a copy of the same test profile(
longshot-builder build --profile, main @f577a1aea):Risks
needs a build. Mods that share no bytes switch as before.
No save, setting or cache changes. A revert is enough.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (run locally, Testing names them; CI's run waits for approval)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened. (tests/test_parity_gates.pyreadsloader/mod.rs's log lines, which this keeps: it passes unchanged)mainand here, for a change that shows on screen. (in the comments)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Windows 11 Pro, RTX 3090, NVIDIA 610.88, adult Link in Kakariko, built by longshot-builder play --profile with the mod compatibility ports merged: Rupee Counter (an .ips hook and a code module) with an Atmosphere patch set below it that writes back the hook's 4 bytes. The build log named the overlap (main+33C3B80-33C3B83) and the lower patch won every byte; in the game the rupee counter was gone, as on an emulator, and HUD of Time still showed.
Screenshots: the Mods tab pages of both mods, the same test profile on both sides (Windows 11, RTX 3090). Rupee Counter off is below Rupee Counter and writes the 4 bytes of its hook back.
Before, main @


f577a1aea: no word of the overlap on either page.After, this PR (the build with the other mod compatibility ports merged, 72d64e92f): both pages start with the overlap, the lower file named as the winner.


Description updated: the Mods tab screenshots of both mods, here and on main, are taken (comment above), and Measurements has main's own build line for the same profile (
exefs: emptyfor the lower patch, no word of the overlap).mise run test, run locally while CI's run waits for approval (Windows 11, run_all --strict, 12 checks at once), here @
f4071ee12and on main @f577a1aea: 822 passed, 23 failed, 51 skipped here; 820 passed, 25 failed, 51 skipped on main. 20 of the 23 also fail on main (named in Testing). The other three (test_direct_buffer_writes, test_frame_wait_bounds, test_mesh_args_cleanup) timed out under that load and pass here run alone (--exact). Box ticked.WIP: feat(mods): two mods' ExeFS patches that write one place differently are named, and the lower one wins every byteto feat(mods): two mods' ExeFS patches that write one place differently are named, and the lower one wins every byteRecommendation: Request changes. The overlap notes can grow beyond the loader’s 16 MiB limit, causing it to lose the build’s patch list and hold back manifest mods. The restoration fix is demonstrated for one mod order, but the reversed order and build cost remain untested.
The change reports conflicting ExeFS patches and preserves bytes that a lower patch restores to the game’s original values. It also makes conflicting mods require a rebuild to switch; the new diagnostic data can become large enough to disrupt mod loading.
Blocking (1): must change before merging.
@​fixor@​rebasetry first). (for the author)Should fix (1): not blocking, but worth doing before merging.
builder/crates/game-files/src/patches.rs:665: Overlap notes are appended without a bound to every participating file, but the loader reads the entire resulting patch list with a 16 MiB limit. (more on the line) Do: Bound or compact the serialized diagnostics so the complete patch list remains readable, and add a test covering a list with many distinct overlap groups.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixdoes its part first: Bound or compact the overlap data retained during comparison and reporting.)@fixcan do L1 and L2.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes for the tested restoration case: the author reports that four hook bytes were restored and the rupee counter disappeared in game, whereas main dropped the lower patch as empty. The reversed mod order has not yet been tested in game.
Other systems: The builder, restart switches, hook-site refusal, the Mods tab and manifest-mod code acceptance consume the changed results. The reported game run was on Windows with NVIDIA hardware; Linux and the reversed order remain untested. No per-frame rendering path changes.
Switches: No environment variables or player options added, changed or removed. Conflicting mods lose restart switching and require a build, as documented.
Reviewed:
f4071ee12dagainstf577a1aeab: Read the repository rules and standards, PR template, commit and diff; patches.rs, switches.rs, clashes.rs and the ExeFS loader paths in detail. Skimmed the remaining portions of the large loader, tab and build-driver files, documentation changes and reported runs. The requested docs/review-checklist.md and ../Tooling/AGENTS.md were absent; screenshots and external repositories were unavailable.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run. The author reports game-free tests passing for the changed behavior and one Windows in-game run; CI remains pending.
Overlaps and merge order: No overlapping pull requests could be checked with the network closed; the description identifies this as the Rust port of #961.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as snaildev99 took it out of WIP. Nothing was run; a maintainer decides.
@ -516,0 +662,4 @@let mut peers = others[..others.len().min(3)].join(", ");if others.len() > 3 {peers.push_str(&format!(" and {} others", others.len() - 3));}L1 (should fix): Overlap notes are appended without a bound to every participating file, but the loader reads the entire resulting patch list with a 16 MiB limit.
When: A large patch set with many different combinations of writers can generate enough repeated overlap summaries to exceed 16 MiB in exefs_patches.txt. The loader then treats the list as empty: patch status is reported as waiting, and manifest mods with ExeFS files fail the built-code check and are held back.
Do: Bound or compact the serialized diagnostics so the complete patch list remains readable, and add a test covering a list with many distinct overlap groups.
Still to test, run: Rupee Counter off moved above Rupee Counter in the same profile (Windows 11, RTX 3090, NVIDIA 610.88, adult Link in Kakariko). Play built the game again for the new order, the build log names local/rupee-counter's .ips as the winner of main+33C3B80-33C3B83, and the rupee counter is back (bottom left, beside HUD of Time's clock):
Description updated: the Still to test item ran (reorder, a build, the counter back; screenshot above), moved into Tested, and its Ready-to-merge box ticked.
f4071ee12dd30a274075Rebased onto main @
3a0f7d8f7for the base conflict; here @d30a27407. Tested (the game again on this head),mise run test(against main @3a0f7d8f7: every failure also fails on main) and Measurements are updated. Answers to the review below.L1 (overlap notes without a bound): fixed in
d30a27407. A file's note now names at most three overlaps and then counts the others ("Overlap: 64 more overlaps with other files, named in the build log."); the build log still names every one. Each named overlap is short (at most four file names and three ranges), so the patch list grows with the number of files, as it did before this PR, not with the number of overlaps, and stays far under the loader's 16 MiB read. New testoverlaps_keep_each_files_note_short_however_many_places_differ: eight mods and 128 bytes, each written by a different set of them (a file in 8 to 67 overlaps). It failed on the earlier head (67 overlaps in one note), passes now, and fails the same way again with the bound taken out. builder.md and mods.md say a note names three.L2 (the reverse order and the build cost): the game-free reverse order now has its own test,
overlaps_a_restoring_file_above_the_hook_leaves_the_hook(ind30a27407): the file that writes the game's word back sits above the hook, so the hook wins all 4 bytes, the upper file stays empty and puts nothing back, both mods lose their restart switch, and both notes name the hook's file as the winner. In the game the reverse order (Rupee Counter off moved above Rupee Counter) ran again on this head, built with the other ports merged: the line flips to Rupee Counter winning and the counter comes back (Testing, screenshot below). The build time and peak memory againstmainwith a large mod list are still to measure (Still to test). The comparison keeps one entry per validated byte a patch writes (each file at most 1 MiB,MAX_WRITTEN) for one sort per build; the notes, the part the game reads, are bounded now (L1).L3 (conflicts with
main): rebased ontomain@3a0f7d8f7. Two conflicts: the module comment ofpatches.rs(#3137 reads code mods, manifest mods and the emulators' layout alike: kept, with this PR's sentence on overlaps), andLoader::textsinloader/mod.rs(#3151's notes for a mod whose files are still served, a deferred one and a live one: kept, in the note that now starts with the overlap). On the rebased headcargo test -p game-files(73),-p build-driver --test driver(9) and-p api -- loader::(153) pass.In the game on this head (929bf025a, with the other ports merged): Rupee Counter off below Rupee Counter, the counter gone and HUD of Time's clock shown; both mods' pages lead with the overlap.
The reverse order on this head: Rupee Counter off moved above Rupee Counter, a new game folder, Rupee Counter wins, and the counter is back.
Merge note for #3165 and #3169: each passes alone on
main, but whichever merges second needs a one-line test fix. #3165 givesgame_files::patches::collecta refuse callback, and #3169's import test ingame/crates/modtool/src/import.rscalls it without one:collect(&nso, &mods, |_| Ok(()), &mut |l| said.push(l)). With all the mod compatibility ports merged together, that is the only change it needed there.@review
Recommendation: Approve. The code is ready: only testing is left. The recorded tests show that the lower patch wins in both orders and that overlap notes are shown. Build time and peak memory for large patch sets remain unmeasured. Recommend approval; not approved on the forge.
The build reports conflicting ExeFS writes and preserves a lower patch’s restoration of the original game byte. Overlapping mods require a rebuild to switch; comparison adds build-time work and memory use.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixdoes its part first: Bound or compact the overlap data retained during comparison and reporting.)@fixcan do L2.Since the last review (on
f4071ee12d)Resolved: L1 (Overlap notes are appended without a bound to every participating file, but the loader rea…); L3 (It conflicts with its base branch: bring it up to date (
@​fixor@​rebasetry first).)Still open: L2 (The build time and peak memory cost of comparing large patch sets remain unmeasured.)
Checks: Still running: 11 checks.
Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes: the author reports that the counter disappeared when the restoring patch was lower and returned after reversing the order. The game-free tests also cover both orders and bounded notes. The build-time and peak-memory cost remains unmeasured.
Other systems: The comparison runs in the builder on Windows and Linux, independent of GPU. The reported in-game runs were on Windows; large patch-set cost has not been measured.
Switches: No new player or developer switch. Mods writing disputed bytes become build-time switches rather than restart switches; other eligible mods retain restart switching.
Reviewed:
d30a274075against3a0f7d8f7f: Read AGENTS.md and CONTRIBUTING.md, the overlap implementation, the changed loader text, the commit summary and relevant diffs. The remaining changed files and recorded runs were skimmed; not every changed code file was read in full.; nothing run (a code review).Checked and fine:
Testing: No commands or tests from the project were run. The author reports passing targeted tests and in-game checks in both patch orders; CI is still running.
Overlaps and merge order: PR #3169: whichever merges second needs its import test updated for the collect callback.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.