WIP: refactor(hooks): the player features on hook sites, and Skip title screen on the game's own waits #2272
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2272
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:feat/hook-sites-squashed"
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
Longshot's own changes to the game's code were exact-text patches over the lifted C (
nx2/oot_patches.py): eachsearched the translated functions for a line it expected and wrote its C beside it, so a lifter change that moved a
line silently dropped a feature ("found 0 times"), and every patch kept its function out of the shared context. This
moves them to hook sites: places in the game's functions, listed as data in one table per game build
(
host/game/sites.toml, the definitions, andhost/game/sites/<build id>/locations.toml, each build's places), found by a masked signature of the game's instructions and hooked by thelift while it writes the C (
nx2/hooks.py). A site that does not resolve exactly once stops the build, naming it.What a player gets: the same features as before, now placed by address instead of found by text, and Skip title screen
pressing A only as the game waits on the title, its file list and its Yes, instead of blind presses from 20 s. The
features that were edits after an instruction by address (field of view, shadows, jitter, widescreen) and the host's
calls into the game by fixed address move the same way, so the game is changed in one way only.
What changed:
nx2/hooks.py,host/game/sites.{c,h,def},host/oot_sites.c): the table's reader and itssignature resolver; the forms
entry(andcan_return),return,after,before,replace,branch,allow,jumpand a call replaced; inline data rules (C over a host value, no callback); a site's flag byte and callbackslot; a rule table retired and freed only when its readers have left. A site that changes the game's outcome on a
worker thread must be an engine feature's or an inline rule (the reader checks it).
hooks.md says which were taken and why): a site's definition (
host/game/sites.toml: name, form, arguments,answer) apart from each build's locations (
host/game/sites/<build id>/locations.toml); anchors by a call's targetor a vtable slot, an ordinal, a slice from and to another site, a shift, a site inside another's function
(
jump.takeoffVelocityandshadow.fitBasisuse them, without the guards they needed); a site that does notresolve exactly once names its candidates and nearest misses; several handlers on one site in a set order around
its callback (
hos_site_add,hos_site_next);nx2/hooks.py checkandreview. The lifted C of all 132 sites isbyte for byte the same as before these (96 of 96 generated files).
host/game/game.c,flags.c,phases.c): onegame_calland one reader of the game'sflags, and frame phases run on the main thread at the window acquire (the reclaim of retired tables runs there).
opening, the save requests' trace and Transition autosave, Camera speed, native mouse look, the menus' mouse, the
button prompts, the host's zstd decodes, the cloth's solve and time, a movie's frame count, the native HDR scene
format, the Debug tab's Damage taken, heart protection, Link's update, flight, free camera and Movement speed, a
horse's jump step, texture compaction, the physics solver's steps, the sound job and the music manager, Link's driven
body, the counters cut to whole frames, the fixed resolution's scale, Disable camera centering, a moving floor's
carry, the Voice Language option, the OptimizeChangeBank heap retries, song notes, the ocarina's note wait, a loop of
one frame on one pose, the saved steering rate, the job barriers, dynamic resolution, the preload manager's choice
the frame's real time at the step divides, Sprint and a jump's takeoff (speed and velocity), the field of view, the
shadow size, steady sun shadows, the camera jitter, and widescreen and ultrawide (23 sites,
host/oot_wide_sites.c).nx2/oot_fov.py,oot_shadow.py,oot_shadow_fit.py,oot_jitter.pyandoot_wide.pyare gone. What is left ofoot_patches.py: the output size's eight edits and the gameplay HUD wrapper (#1855); why each stays is in hooks.md.the heap retries) go through
game_call(game_call_morefor a call with x8, its own LR, or s0/s1 handed back).site, instead of stopping the lift (
nx2/exefs_patches.pyrefuse_site_clashes).host/oot_autoload.c, sitesmenu.buttonWait*): A 300 ms after the game waits onTitle_00,SystemLoadList_00andSystemSaveLoad_00; the timed presses stay as the fallback (no wait on thosethree told by 45 s; a wait told later puts the hook path back), and presses stop once the check's A has been taken and
the game is loading. It holds while the Insert menu is open (option 1, as on
main).scripts/parity_gates.py, docs/dev/reference/parity-gates.md): gates 3 to 5 for refactors ofthe game's code, run against
main, at the 60 cap and with each checkpoint taken once the game has settled.host/game/sites/, which every builder and the AppImage carry, so a pull request built by thereleased launcher over a nightly's tools has them too.
Read first: docs/dev/reference/hooks.md,
nx2/hooks.py,host/game/sites.h,host/oot_sites.c, then any one port(
refactor(text): Text speed and Text size through the hook site text.letterStep) and its test.Prior work: supersedes the unopened branch
feat/title-skip-hooked(the title skip as a text patch). See #659 and#1577 (the title skip and the boot save meet this one's Skip title screen). Replaces #2253 (the same change before the last
moves, squashed); #1958 is rebased onto this.
Testing
Self-review (
348f2215): the ports read and write whatmain's patches did, under the same conditions, on the samepaths. Fixed with a game-free test each:
sites.defin the lift key; anaftersite on an instruction areplacesite took;
apply's host-def; republishing a live rule table; gate 4's noise counting the save picture; Voice Languagereading entry 0 past the count, as
maindoes;of = Nfor ordinal anchors (jump.takeoffVelocityusesordinal = 1, of = 2); Skip title's fallback; the handler chain's callee, guest-context cursor, grace period, andrefusal of a run-time handler on the 39 sites that change a worker thread's outcome. All 66 site, hook, flag, title
skip and gate checks pass; the lift of 348f2215's tree is byte for byte the lift of
3c58d599(96 of 96 generatedfiles). Skip title's changed fallback is to run again in the game (branch only).
By hand, this PC (the user, at 03ce25a2's game code, the market-entrance save): Text speed and size, Disable camera
centering, Movement speed 2x, cloth at 144, and widescreen at 21:9 look as they should. The menus' mouse does not take
the mouse on Linux, as on
main: it is a Windows feature (host/posix/display_sdl.canswers no game menu, on both);Windows on Beanstalk. Flight: to confirm against
main.At
3c58d599/03ce25a2, whose game code is the same (320f745ckeeps the lifted game code byte for byte; it adds thesite finding and the host's handler chains). Linux CachyOS 7.3.3, RTX 3090, NVIDIA 620.70.06, this PC. A pack over
base
8aa74983(5 min 43 s: lift and split 90 s, compile 216 s cold, no failure; every site of the 132 placed, onewarning as before:
preload.choice before f_832b9880+0x548).maina2dc5385's runtime against this one, every gamerun a
--mode sharedjob of the queue (gate 2timing), a throwaway user folder (headless, no audio; a window for theInsert menu's keys and the wide picture),
RX_VK_LOAD=createon both sides (programs at first use; gate 2 keeps thedefault). The same inputs and readings on both sides, over the control bridge (inputs, teleports, option rows, the live
input file, timed Insert-menu keys), each item read from numbers and log lines with a written pass rule:
Title_00,SystemLoadList_00,SystemSaveLoad_00waited and A on each, thenloaded, Link in the save's map; no save: the title stays; the Insert menu open: no press; the row turned off while waiting: no press; the menu closed later: the A only after it (title waited at frame 148, A at 11016), then loadedsave trace:lines (reasons 4, 10, 2, 6, 2, 1, 4, 6, 6, 2) on both, every time; the row off: the same 13 lines withtransition autosave suppressedon both. No file written on either side (as in the gates' runs here)main's own spreadmain) against 317 deg/s, swimming 6.05 and 6.63 against 5.97 m/sHOS_GPU_ALLOC_TEST_FAIL=8,8: the same retry lines and kinds, made in a parent, the game aliveshadow:line the same (the steady fit's list differs by one passing size as Link moved); shots of the same spot and light, apart by Link's and Navi's placementit changes f_80643f10+0x30 ... it would stop the game's hook site camera.yawSpeed; a patch elsewhere applies; exit 03c58d599(scenario 2, Amaina2dc5385, A, B, A): PASS on all three, 7 of 7checkpoints each; kokiri-start 40 flag values compared (14 left out as noise), castle-gate 34 (14), market-entrance
59 (14). Gate 4 inconclusive on all three (no save written in the scenario, 9, 9 and 11 requests on each side);
gate 5 PASS on both sides of all three.
3c58d599: Measurements.The runs below were at
6b01227a, before Sprint, the takeoff, the field of view, shadows, jitter, widescreen and the host's calls moved; they hold for what was on sites then.Tested: Linux CachyOS (kernel 7.3.3), RTX 3090, NVIDIA 620.70.06, this PC.
mainisa2dc5385built as a pack overthe same shared base (
8aa74983) as this branch's6b01227a, so both sides differ only by this branch; every game runthrough the PC's queue (
shared,timingfor gate 2):tests/run_all.py --strictthrough the queue (light): 920 passed, 23 failed, 18 skipped;maina2dc5385the sameway: 22 failed, the same 22 (they fail on
maintoo). The 23rd,tests/test_teleport_check.py, failed on a cut ofhost/hos_main.cthegame_callrefactor moved; fixed in the branch and passing since (run alone through thequeue).
tests/test_crash_record.pytimed out once in the first run and passed in the second.dev.py pack,dev.py rt, through the queue): built on base8aa74983in 7 min 36 s (compile 5 min 6 s), no failure; the lift placed everysite of the table (
hooks: <site> at ...for each) and the runtime was made. Rebuilt for gate 2: the lift againplaced all 98 sites, one with a warning:
preload.choice before f_832b9880+0x548 (WARNING: after a call, but a label: other paths reach it too, not only the call's return).scripts/parity_gates.py, scenario 2: the 60 cap, each checkpoint once the game hassettled; A =
maina2dc5385, B = this branch at8ebb143d, whose game code is 6b01227a's; A, B, A on each save):gate 3 PASS on all three, every run at all 7 checkpoints, the map, age, life, maximum life, rupees and every
compared flag the same (kokiri-start 48 flag values compared, 14 left out as noise; castle-gate 50, 18; market-entrance
61, 14). The two runs of
mainwere 0.000 m, 0.0 degrees apart at every checkpoint (scenario 1, at a 1000 cap,had them 4 to 10 m and 114 degrees apart: game time followed the measured frame rate, and a teleport's checkpoint was
taken before its arrival). Gate 4: castle-gate PASS (account.sav, slot_00 identical; option.sav, slot_01's
progress.sav and caption.sav the same outside their noise, date and picture); kokiri-start and market-entrance
inconclusive, no save written in the scenario (9 and 11 requests). Gate 5: PASS on both sides of all three.
The gates' own check:
mainagainstmainPASS;--b-env HOS_FPS_MAX=1000 --b-env HOS_FPS_STEP=1FAIL on thewalks as it must (
walk: pos 0.968 m apart (tolerance 0.300),field-walk: pos 3.378 m apart, 9 flag values).dev.py ab --scene hyrule-field --options <resolution=3>, A B A B A B, Amain's runtime(Measurements).
tests/test_hooks_emit.py(the empty table emits byte for byte) passes, 3 tests, through thequeue (light).
nx2/test_leaf.pydoes not run on Linux: its harness is Windows-only (windows.h,__try,VirtualAlloc), onmaintoo, and it lifts with the kit's lifter directly, not through the site table.skip_title_screen=1), each in a userfolder of its own with the save copied in, through the bridge (screenshots on this PC):
Title_00waited at frame 103, A at 120;SystemLoadList_00at 234, A at 308;SystemSaveLoad_00at 324, A at 397;
skip title: loaded, the player is running at frame 1383, 14.4 s after the first controller read,in Link's house.
skip title: no saved game yet: the title screen stays, no press; still on the title 40 s later.RX_VK_MENU_SCRIPT=0.5:INS):Title_00waited at frame 89, then no press for60 s, the title still there.
skip title: the row was turned off while waiting, no press, the title stays.close at a set time came before the title).
camera.*Speed*), a spot check over the bridge from kokiri-start: the right stick held 40frames turned the camera 90.3 / 92.6 degrees at 100 % and 174.9 / 174.9 at 200 %, the same on
mainand this branchto 0.1 degree.
tests/test_launcher_pr_build.pyfrom #1958, without its system mods' and SDK's checks: passes (the site tables arefound under
host/game/sites/, every site of build e0f3ccfa's table loads, the AppImage and the Windows builder stillcarry every top folder).
Still to test:
nx2/test_leaf.py(its harness is Windows-only), expecting the lifted fixture functionsas on
main.mainagainst this branch atresolution=3, expecting the 2 % neutral band; this PC andthe lab: the other two areas of the 3-area bench and the hot sites read apart (
barrier.*,anim.loop*,physics.floorCarry*,heap.*,sound.job*) (by hand).mainthen this branch with the same steps, each expecting the same asmain:main.main.main.main.main.@Beanstalk the hook sites: a cold build (every player re-lifts once), the game to play, Skip title screen on with a save, Text speed, Camera speed and the Debug tab's Damage taken as on main.Measurements
Verdict: (
3c58d599) no difference shown on this PC:dev.py abgives +3.0 % fps (median 124.4 against 120.8),within the runs' spread. One run of
main, A2, was disturbed (96.6 fps, p99 38.75 ms: the PC was shared, swap inuse); without it
main's median is 123.0 and this branch's 124.4, +1.1 %, inside the 2 % band, and the two clean pairsare 120.8 / 125.0 and 125.2 / 124.4. A fourth pair to replace A2 was queued but stopped before it ran (the PC ran short
of memory). The RX 580 is still to come.
Setup (
3c58d599): as below;dev.py ab --scene hyrule-field --options <resolution=3> --runs 3 --allow sim_turf_density --allow sim_turf_fade_start --allow sim_turf_far_power --allow sim_turf_minimum_blades(a run ofmainhad read those Simulated turf rows before its area loaded), side Amaina2dc5385's runtime, each run atimingjob alone, the runtime's default program loading.a2dc53853c58d599Spread: observed fps ranges: A 96.6 to 125.2; B 119.0 to 125.0 (A2 is the disturbed run).
The build at
3c58d599: a pack over base8aa74983, this PC, not quiet: lift and split 90 s (coverage 12 s, emit andwrite 38 s, the patches 1.3 s), compile 216 s (every object again: the system headers had changed), 5 min 43 s in all;
the executable 612,171,000 bytes against
main's 612,108,656 (+62 KB).At
6b01227a(before the last ports moved), for the record: within the neutral band, +0.6 % fps (median 127.9 against127.1), every run of the branch above every run of
main.Switches: none added, so no default changes. The names the diff carries are already
main's switches, which the gate script (scripts/parity_gates.py) and its docs set for their own runs: no Discord, no mods, the bridge's input alone, no pacing, a fixed step and Output resolution (HOS_DISCORD,HOS_MODS,HOS_INPUT_EXCLUSIVE,HOS_INPUT_SCRIPT_BACKGROUND,HOS_NO_PACING,HOS_NO_SDL,HOS_REALTIME_STEP,HOS_OUTPUT_RES,HOS_RT_POOL_MB,HOS_TEXT_SPEED,HOS_OOT_TRACE_SAVES,RX_VK_FRAMEGEN).LONGSHOT_JOBandLONGSHOT_JOB_MODEare the job queue's, read to refuse a run outside a--mode sharedjob.HOS_OOT_BOOT_SAVE(#1577, not merged) is set only with--boot-save.Setup: Linux CachyOS 7.3.3-1, NVIDIA RTX 3090, driver 620.70.06; Hyrule Field, child (open, far view) (window
3840x2049); quality preset Custom, Render resolution 67 % (1707x960,
resolution=3pinned), output 2560x1440, framegeneration Off, V-Sync Off; uncapped (
HOS_FPS_MAX=1000); the frame trace, 60 s each after a warm-up until no framewaited for a pipeline, 3 interleaved pairs, the median;
dev.py ab, side Amaina2dc5385's runtime (its pack overthe same base; the tool's label says
main @ 068fb8eb, a mislabel of the side, the runs' manifests name main's runtime).a2dc53856b01227aSpread: observed fps ranges: A 126.8 to 127.3; B 127.5 to 128.2.
The build (the re-lift every player makes once), dev packs on one shared base and work folder, this PC (Ryzen,
znver4), not a quiet one (other sessions' runs, swap in use):maina2dc5385main'sThe lift is the same order on both sides (the text patches' phase falls from 7 s to 2 s; the site resolver is inside
"image and discovery", whose 35 to 90 s spread here is the PC's load, as the read phase's 16 s against 42 s shows). A
clean compile of each side on a quiet PC is still to come; the executable is 612,157,288 bytes against
main's612,108,656 (+48 KB).
Risks
The camera clearance keeps fewer locals:
f_8073a4a0no longer keeps its integer and flag registers as locals(on
main#2009's vector-only exemption kept them; itsaftersites now put it inno_local, as do the vector-onlyrule sites in
f_80706be0). #2009 measured the clearance's first read at about once a frame; gate 2 at3c58d599read+1.1 % over the clean pairs, inside the 2 % band.
Every player lifts once more:
host/game/sites.defis now part of the lift's key.A port that does something other than its text patch did: each site's callback or rule replaces a patch's C;
a wrong register or a missed path changes a feature, or (the heap retries, the barriers) brings back a crash or a
hang. The ports' game-free checks compile each site as the lift emits it beside the patch it replaced where they can;
gates 1 to 3 and the per-feature runs above are the rest. Revert the branch to go back.
Every player re-lifts once: the lift's key hashes the site tables. A site that stops resolving (another game
build, a player's code mods together) stops the build with the site's name, where a text patch was silently left
out; one ExeFS patch over a site alone is refused instead.
Cost at play: 132 hooks of one byte load and a predicted branch each when dormant, the 95 engine ones on and
calling through a pointer; sites in loops (
player.lifeHit, the barriers,anim.loop*,jitter.view*,wide.bubble) and the functions that now keep their context are what gate 2 must read.Game code in the repository:
sites.toml's signatures are a few masked instruction words of the game per site,with function names and offsets, as
nx2/oot_wide.pyonmainholds; no other game data.Skip title screen changes for every player who has it on: it presses on the game's own waits now; a build without
the sites, or no wait told by 45 s, falls back to the old timed presses. It meets #659 and #1577.
A player notices nothing else: no new option, no settings or save change.
Checklist
Ready for review
main; the title is a Conventional Commit.3c58d599: the per-feature checks againstmain(every reading the same, or insidemain's own spread), gate 3 PASS on all three saves, gate 2 no difference shown. Not yet: the by-eye list in Still to test.)mise run testpasses (any failure that also fails onmainis named). (run_all --strict, which ismise run test: the 22 failures left also fail onmaina2dc5385, named in #2253 (comment).)main, or Measurements says why there is nothing to measure. (This PC; the RX 580 and a clean build's time to come, in Still to test.)third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened. (test_drive_targetchecks the takeoff sites directly: their signatures, arguments and callback registers, exactly-once resolution, and a stop when the body's load moves or a third copy appears; six mutations caught.)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
Opened before its game runs, as asked: this is #2253 squashed into one commit, plus the last moves onto sites (Sprint, the takeoff, field of view, shadows, jitter, widescreen and the host's calls through game_call; 132 sites). The per-feature checks (main against this, the same inputs), gate 2 and gate 3 are running on this head now; results go into Testing when they finish.
3c58d59958320f745ce6New head
320f745c(still one commit; the previous head was3c58d599): sites defined once apart from each build's locations, found by call targets, vtable slots, ordinals and slices as well as words (from Morphe's fingerprints and Mixin), clear reports of candidates and near misses, and several handlers on one site in a set order (MixinExtras-style chaining). The lifted C of all 132 sites is byte for byte the same as 3c58d599's, so the feature checks running on3c58d599hold.320f745ce603ce25a21cNew head
03ce25a2(still one commit; previous320f745c): the hook sites' side-by-side checks build their places from made-up lifted text of the lift's form (test_oot_barrier, test_ocarina_wait and 7 more), and hooks.md's examples use made-up words. Tests and docs only: the lift's 96 generated files are byte for byte the same, so the feature checks running hold.Testing and Measurements at
3c58d599(game code the same as03ce25a2), RTX 3090, driver 620.70.06, CachyOS 7.3.3, maina2dc5385against this, the same inputs on both: no regression found. Title skip, opening skip, mouse look, camera, heap retries, dynamic resolution and the ExeFS refusal pass; movement at 60, 144 and uncapped agrees once frames stalled on first-use loads are left out; gate 3 PASS on all three saves (7/7 checkpoints); the one extra autosave trace line did not repeat (four repeat walks identical). Gate 2: +1.1 % over the two clean pairs, inside the 2 % band (one main run was disturbed by other load on the PC). Still to test: the by-eye list in Still to test, Windows on Beanstalk, the RX 580.Description: who runs the HDR and Epona checks (by hand), and the Verdict line's form.
By hand on this PC: Text speed and size, camera centering, Movement speed 2x, cloth at 144 and widescreen at 21:9 look right. The menus' mouse is Windows-only on main too (Linux keeps the mouse captured in both), so it moves to the Windows run. Flight still to confirm against main.
03ce25a21c348f2215faNew head
348f2215(one commit; previous03ce25a2): the self-review's fixes. The ports hold; fixed with a test each: sites.def in the lift key, an after site on a replaced instruction, a live table republished, gate 4's noise, Voice Language past the count (as main), of = N on ordinal anchors, Skip title's fallback, and the handler chains (callee, fiber cursor, grace period, outcome sites refused). test_drive_target checks the takeoff sites directly. 66 checks pass; the lifted game code is byte for byte the same (96/96). Skip title runs again in the game next.The branch-only Skip title run on
348f2215found a regression from the review's fallback change: on kokiri-start the stop-after-loading rule fired on the same frame as the save check's A, before that press reached the game, and the game stayed on the menu (at3c58d599it loaded and ran at frame 1364). Being fixed with a game-free test of the press delay; the run is repeated before this goes further.348f2215fad1ce425a2aNew head
d1ce425a(one commit; previous348f2215): the Skip title fix. The game's loading flag was already up when it waited on the save check, so the new stop fired before the check's A was taken. Presses now stop only for a load that begins after the check's A was pressed and released; a game-free test of the press delay and the early flag failed on348f2215and passes. test_skip_title and the other checks that read host/oot_autoload.c pass. The branch-only Skip title game run (three saves, no save, menu open, row off, menu resume) is running on this head now.Superseded by #2286, the builder rewritten in Rust, which carries this pull request whole: the hook sites, the 132 sites and Skip title screen on the game's own waits. This pull request's latest version (
d1ce425a) is being folded into #2286, withnx2/hooks.pyandnx2/oot_patches.pyported to its Rustsitesandeditscrates; it lands with #2286's next push. #2286 merges alone, so this one closes without merging.Pull request closed