WIP: refactor(hooks): the player features on hook sites, and Skip title screen on the game's own waits #2253
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2253
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:feat/hook-sites"
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/<build id>/sites.toml), 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. This is
the hook-site half of #1958 (the Modding API), split out so it lands, and is measured, on its own; #1958 stacks on it.
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).
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
and the frame's real time at the step divides. What is left of
oot_patches.py: the output size's eight edits, thegameplay HUD wrapper (#1855) and main's own later text patches.
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 told by45 s). It waits on the Insert menu alone (
HOS_OPT_INSERT_MENU, 99), not option 1.scripts/parity_gates.py, docs/dev/reference/parity-gates.md): gates 3 to 5 for refactors ofthe game's code, run against
main.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). See #1958 (the Modding API, rebased onto
this).
Testing
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 ab --a main=<main's runtime> --b hooks=<this branch's>,--saveeachof the three saves, A, B, A):
parity: FAILon all three, but not by this branch.parity_gates.py runas committedstops at once (
AttributeError: module 'pipeline_tour' has no attribute 'ctl_module': #1802 moved the tour's drivingto
scripts/tours/drive.pyand its client tolongshot_bridge.py); the runs here used a local copy withtour()andctl()pointed there, now fixed in the branch (8ebb143d, with a game-free test). With it, every run reached all 7 checkpoints, and in every save the map,age, life, maximum life, rupees and every compared flag were the same on both sides. What failed:
mainwere 4.1 m apart after the walk in Link's house and 9.9 m after the fieldwalk, past the gate's ceilings (0.6 m), so the gate cannot judge; B (3.9 m and 8.0 m from A1) lies within that
spread and 0.2 m from A2 at the walk. 47 flag values compared, 12 left out as noise, none differing.
mainagainst itself 0.7 m and 114 degrees apart atfield, 3.9 m atfield-walk; B differed atfieldin flag0x9b2ba99b(#cea5ea8e, A#6f88b078) and atforestin Link's facing (-70 against 90degrees). Both are a checkpoint taken while the teleport's arrival still settles: A1's own change list saw
#cea5ea8eatfieldbefore reading#6f88b078, A2 had the pre-teleport facing atfieldtoo, and B'sendhas 90 degrees and
#6f88b078as A's.field3.1 degrees from A1 (tolerance 3.0; 1.8 degrees from A2);the facing there is the walk's, kept through the teleport, where the walk's own tolerance is 10 degrees.
in each log, no file changed), as parity-gates.md expects. Gate 5: PASS on both sides of all three.
mainagainstmain, and--b-env HOS_FPS_STEP=1) was not run; the A-against-A spreadsabove say the scenario's walks need calibrating first (the doc's "first runs").
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).parity_gates.pyonce its scenario is calibrated (mainagainstmainwithin the ceilings), expectingparity: PASS; the gates' own check,mainagainstmainpassing and--b-env HOS_FPS_STEP=1failing (by hand).(Text speed and size, Skip opening, saves and Transition autosave, Camera speed, mouse look, the menus' mouse, button
prompts switched live, zstd loads, cloth, movies, native HDR, Damage taken and heart protection, flight, free camera,
Movement speed, horse jump, texture compaction, physics, music and sound, the driven body, whole frames (pickup,
water, time of day, scarecrow song, web floor), camera centering, moving floors, Voice Language kept, heap retries,
song notes, the ocarina's wait, one-frame loops, steering, the barriers, dynamic and fixed resolution, the preload,
animation speed uncapped, the gameplay HUD, an ExeFS patch over a site refused with its name), expecting each as on
main(by hand; Camera speed done, above).@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: within the neutral band on this PC: +0.6 % fps (median 127.9 against 127.1), every run of this branch
above every run of
main, a gap smaller than the 2 % band. The RX 580 is still to come.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
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.
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.
calling through a pointer; sites in loops (
player.lifeHit, the barriers,anim.loop*) are what gate 2 must read.sites.toml's signatures are a few masked instruction words of the game per site,with function names and offsets, as
nx2/oot_wide.pyonmainalready holds; no other game data.the sites, or no wait told by 45 s, falls back to the old timed presses. It meets #659 and #1577.
HOS_OPT_INSERT_MENUtakes option 99: free onmaintoday (to check against open pull requests at merge).Checklist
Ready for review
main; the title is a Conventional Commit.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. (Updated;test_drive_targetnow checks only that its patch'shos_oot_drive_targetis gone, since main's takeoff velocity patch names the same function: a reviewer to agree.)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
The site forms M2's conversions need beyond entry and after: - entry with can_return: if (on && fn(c)) return;, as nx2/entry_hooks.py's hooks; - return: the function lifted as f_1<address> under a wrapper f_<address> that calls it and then the hook, so every way out (ret, tail call, indirect jump) runs it and the body keeps its locals; - before: before the instruction at offset, of any kind, after its label; - replace: if (on) fn(c); else { the instruction }, a plain instruction only; - branch: before a conditional branch, a non-zero answer takes it. before, replace and branch are emitted by lines of nx2/fastfp.py's copy of the kit's emit_function tagged "# (hooks)" (tests/test_fastfp_override.py takes both tags out before comparing with the kit), from Lifter.site_before, site_replace and site_branch, sent to the emit's processes with the others. Every callback is int fn(Ctx *): only can_return and branch read the answer (hos_text_letter_step returns 0). Inline data rules (rule = mul_f32, scale_f32, note_u64): the compiler's own C inlined at the site, reading a host value named in host/game/sites.def (HOS_VALUE, the feature's own variable): one load and a predicted branch when off, no call. The host fills a value with one atomic store and a table by publishing a new one with one pointer exchange, the old kept until a quiescent point (host/game/sites.c hos_value_set, hos_table_publish, hos_tables_quiesce): no lock on the game's side. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e3nBDxBnhodLguFyEtThe hook site callbacks became int (an entry that can return, a branch) after the text.letterStep site was written, and the two checks still cut "void hos_text_letter_step(", which no source has: both would stop on the missing marker. sites.h and docs/hooks.md said the sites' several subscribers come with the script runtime, which is in without them: they come with the API's hook namespaces. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e3nBDxBnhodLguFyEtThe cloth solve job's text patch (nx2/oot_patches.py patch_cloth_solve: if (!hos_oot_cloth_solve(the frame step at 0x84d61fc8)) { x0 = 0; return; } first in f_81b47080) is the site cloth.solve, the job's entry with can_return, its callback host/oot_sites.c's hos_site_cloth_solve: it reads the step as the patch did and answers 1, x0 = 0, for a frame the gate holds. Identity: the same call with the same word read, before the job saves anything (its first line, the prologue's store, comes after the entry hook as it came after the patch); a held frame returns with x0 = 0 and the stack pointer as given. tests/test_oot_cloth_60.py builds the job with the emitted hook and with the patch's line side by side and checks they solve and hold the same frames in every case (240, 144, 120, 60 and 30 fps, a cap of 60, a step of 0 and NaN, a load), for HOS_FPS_CLOTH_60 unset, 1 and 0. The patch, its constants and its report line are deleted; the job may now get locals. Gates: gate 1 (nx2/test_leaf.py with the table) and gate 3 (Zora's Domain near King Zora at a cap of 240 with HOS_FPS_CLOTH_60=1: the cloth solved some 60 times a second, HOS_FPS_LOG's counts as on main) need a lift and a game run. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e3nBDxBnhodLguFyEtThe camera centering's text patch (nx2/oot_patches.py patch_camera_centering: if (hos_disable_camera_centering()) { x25 = x26; goto L_80645ad8; } on the fall-through of f_80644c80's b.ne at L_8064720c, the follow camera's movement yaw) is the site camera.followYaw, a jump site before +0x2590 to +0xe58, its callback host/oot_sites.c's hos_site_camera_follow_yaw: with the row on, x25 = x26 and the answer 1. Identity: the same call at the same point (+0x2590 is the b.ne's fall-through and no label: nothing else reaches it, so a before site there runs only where the patch's line ran), the same register written, the same label jumped to. The function keeps every flag store now (the jump's edge, which the flow analysis does not see); the patch's goto was not seen either, so this keeps more, never less. The signature takes the b.ne, the call the movement path starts with and its x25 = x26. tests/test_camera_centering.py checks the site and runs a block with the emitted hook and one with the patch's line, row off and on: the same way out, the same registers. The patch, CAM_HEAD and its report entry are deleted: f_80644c80 is no longer named by nx2/oot_patches.py. Gates: gate 1 (nx2/test_leaf.py with the table) and gate 3 (walking with the row on and off on a fixed save: the yaw follows Link's movement only with it off, as on main) need a lift and a game run. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e3nBDxBnhodLguFyEtPossibly related, for context:
Split out of #1958 (the Modding API), which now stacks on this branch (its base is feat/hook-sites). Opened before its game runs at the person I work for's request: gates 1-3, build time and the title skip on the three saves are running on this PC now, and Testing and Measurements get their results when they finish.
The game runs at
6b01227aare in Testing and Measurements (RTX 3090, driver 620.70.06, CachyOS 7.3.3). Gate 2: +0.6 % fps on hyrule-field, inside the 2 % band. The title skip reached play from all three saves and held where it should (no save, Insert menu open, row turned off). Camera speed matches main to 0.1°. Gate 3 found no difference this branch causes, but main against itself is past the ceilings, so the scenario needs calibrating first. New head8ebb143d: parity_gates.py drives the game through tours/drive.py and longshot_bridge.py again (#1802 moved them), with a game-free test. Still WIP: the per-feature checks by hand and gate 3 passing.Description: who runs the Windows gate 1 (by hand), and the Measurements column's commit.
run_all --strictat the branch (Linux, 920 passed, 18 skipped): the 22 failures left are the same 22 that fail onmaina2dc5385in the same run, so none comes from this branch:nx2/test_import_windows.pytests/test_close_waits_for_save.pytests/test_compile_zero_byte.pytests/test_damaged_rom_files.pytests/test_dev_packs.pytests/test_draw_stream_visibility.pytests/test_fsr_uniform_ownership.pytests/test_fs_save_commit.pytests/test_guest_copies.pytests/test_hold_toggle.pytests/test_lower_atomg_cas.pytests/test_menu_i18n.pytests/test_menu_keys.pytests/test_menu_slider_ends.pytests/test_mise_build.pytests/test_pads_after_menu.pytests/test_recording_admission.pytests/test_sim_turf_pools.pytests/test_sim_turf_settings.pytests/test_switch_table.pytests/test_tls_objects.pytests/test_vibration_menu.pyThe run before
a2cfde82also failedtests/test_teleport_check.py(main's teleport check readoot_gamedata_bool, which this branch removes). It passes at the head (light queue).Ticked mise run test (the 22 failures that also fail on main are named in issuecomment-73352), and Measurements says the switch names in the diff are main's, set by the gate script for its runs.
Measurements: every switch name in the diff accounted for (main's own, set by the gate script for its runs; none added).
Closed for #2272: the same change squashed into one commit (
3c58d599), with the remaining features moved onto sites. This PR's last head was8ebb143d(branch feat/hook-sites, kept).Superseded by #2272.
Pull request closed