feat(mod-api): actors.guarded tells a blocked hit and the reaction it gave #3293
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3293
Loading…
Reference in a new issue
No description provided.
Delete branch "glinesbdev/Longshot:feat/mod-api-actor-guarded"
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
A mod can react to a hit that landed (
actors.damaged), but not to one an actor blocked: Link's shield or Nayru's Love, or an enemy guarding. So it cannot reward a guard, count what a shield stopped, or react to an enemy blocking Link's sword.This adds the event
actors.guarded(actors.read, filtered byActorFilter, told at the next frame likedamaged). It carries the actor that blocked (actor,key,type,file),guardType, the reaction the block gave it by the game's own list of hit reactions (a new enumGuardType:guard,mediumHit,smallHit, ...), andnayrusLove, set when Link's Nayru's Love took the hit. A blocked hit is not anactors.damagedhit. It costs nothing while no mod listens.How it works: a new core site,
actors.guard, at the function the game hands a hit's guard data to the defender's life component with (build e0f3ccfa:f_80addb90(record, hit), before it loads the hit's guard type). Its engine callback only reads, and notes a block in a ring while a mod watches; the main thread takes the ring at the acquire phase, as it takes the damage notes. The game's function also takes a hit that landed (with guard type 0): only a hit whose guard field (hit+0x64) is set is told.How each field was found (the code index, a write-watch and runs) is in
docs/dev/reference/actors.md, "A blocked hit".Read first:
game/crates/game-core/src/guard.rs(the reading and the ring) andgame/crates/game-core/src/layout/guard.rs(the fields and the list of reactions, with what each is). Then the site ingame/sites/sites.toml(actors.guard) and its callback inengine.rs(on_guard),api/src/services/actors.rs(fire_guard) andfeatures.rs.Testing
Tested: Windows 10, Radeon RX 7800 XT (AMD 26.11.2), a build of this branch with a mod logging every
actors.damagedandactors.guarded. No landed hit was told as a block: 9 of Link's sword hits on Wolfos, a cut of grass, 3 scripted hits (actors.damage) and 2 hits on Link each readdamagedonly. Each block was told once:typeguardTypenayrusLoveEnemy_WolfosguardPlayerguardPlayermediumHitPlayerguard, ormediumHitfor a heavy blowEarlier runs of the same site in a write-watch build also had a Skulltula turning Link's sword away (
smallHit), an Iron Knuckle's landed hit read as not a block, and the Hylian Shield reading the same as the Deku Shield. What told a block from a landed hit was found with a dump of the hit at the site: hit+0x64was non-zero for every block and 0 for each of 13 landed hits.Checks, on
main@de091ae29:cargo test -p game-core --lib: 445 passed (new:a_block_is_read_from_the_hit_before_the_game_turns_a_9_into_0, which also checks a landed hit is not a block).cargo test -p api --lib: 650 passed, 1 failed:services::settings_push::tests::a_rows_dependencies_come_from_its_data, which fails onmaintoo (run with this change stashed). The features test now checksactors.guardedneeds theactors.guardsite and is absent without it.testing_game::tests::a_blocked_hit_names_its_reaction_and_whether_nayrus_love_took_itpasses; removing the site's note fails it. modtool's lib tests do not compile onmain:import.rscallsgame_files::patches::collectwithout therefuseargument added in #2533's change; the test was run with that call fixed locally, not in this PR.cargo test -p game-sites -p sites: passed (the site's signature and owner).cargo clippy -p game-core -p api -p modtool --lib --tests --no-deps -- -D warnings: nothing in the changed files;main's own errors inapi(flag_exps.rs,settings_host.rs) stop it before modtool. rustfmt is clean on the changed files (cargo fmt --all --checkfails onmainin files this does not touch).schema-gen --check: clean.Still to test:
actors.guarded, block an Octorok's rock with the shield and let a Wolfos block the sword, expectingguardfor each and no block for a hit that lands (@Beanstalk or by hand).Measurements
Nothing to measure: the site's callback returns at once while no mod listens; with one, it is a few bounded reads and a ring write per block.
Risks
has("actors.guarded")is false and the event never fires.guardTypenames come from the game's list of reactions, by its order; onlyguard,mediumHitandsmallHitwere seen in a block. A value past the list reads null.damagednorguardedmay be told there.Open questions:
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). Not run: mise isn't installed on this PC. The cargo checks under Testing ran instead, with the failures that also fail onmainnamed.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
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
A mod could react to a hit that landed (`actors.damaged`) but not to one an actor blocked: Link's shield or Nayru's Love, or an enemy guarding. A new core site, `actors.guard`, reads the hit at the function the game hands a blocked hit to the defender's life component with. It only reads, and notes a block while a mod watches; the main thread takes the notes at the acquire phase and fires `actors.guarded` with the actor that blocked, `guardType` (the reaction the block gave it, by the game's own list of hit reactions: `guard`, `mediumHit`, `smallHit`, ...) and `nayrusLove`. The game's function also takes a hit that landed; only a hit whose guard field is set is told. The fake game gets `game.guard({ target, guardType, nayrusLove })`; `has("actors.guarded")` needs the new site. Co-Authored-By: Claude Opus 5.5 <[email protected]>WIP: feat(mod-api): actors.guarded tells a blocked hit and the reaction it gaveto feat(mod-api): actors.guarded tells a blocked hit and the reaction it gave@review
Recommendation: Request changes. The change commits material copied from the game's code and data, and the new worker-thread queue can corrupt or permanently stall event delivery after its ring wraps. The published event order also differs from the order in which the service fires it.
Adds a next-frame event for blocked hits, including the defender, reaction and Nayru's Love flag. The reported Windows run shows the intended cases working, but the queue and repository-rule problems need correction before merge.
Blocking (1): must change before merging.
game/sites/sites.toml:848: The new signature commits instruction words from the game; the new guard type table also reproduces the game's ordered list of names. (more on the line) Do: Remove the copied game material and use a repository-permitted way to identify the site and describe reactions, including updating the schema and generated documentation as needed.Should fix (2): not blocking, but worth doing before merging.
game/crates/game-core/src/guard.rs:101: Ticket reservation does not give a writer exclusive ownership of a ring slot after the ring wraps. (more on the line) Do: Use a bounded multi-producer queue that prevents an older reservation from writing a slot reused by a newer ticket, and add a test that forces a delayed writer across a wrap.game/modapi/schema/actors.toml:614: The declared event order does not match dispatch: order 32 places guarded after the pause-menu and other later acquire events, but actors_step fires it before those services run. (more on the line) Do: Dispatch guarded at its declared position, or assign and document an order matching its actual dispatch; add an ordering test.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
game/sites/sites.toml:836: The new worker-thread site has not been exercised on Linux. (more on the line) Do: Run the listed Linux shield, enemy-guard and landed-hit cases and report the results.game/crates/game-core/src/engine.rs:330: The claim of no cost without a listener omits the installed hook and callback reached for landed hits as well as blocks. (more on the line) Do: Compare frame times and 1% lows against the base in a representative combat scene with no listener, using repeated interleaved runs. (@fixdoes its part first: Move or gate the inactive check at the lowest practical hook layer to reduce callback overhead.)@fixcan do L1, L2, L3 and L5.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes for the tested Windows cases: the PR reports 28 blocks delivered once and 16 landed hits delivered only as damage. Linux behavior and the cost of the new hook without a listener remain unmeasured.
Other systems: The site runs on game worker threads for landed hits as well as blocks, even without a listener; events are delivered on the main thread. The reported game run covers Windows on one AMD GPU, not Linux. No saves, renderer, audio or input changes are apparent.
Switches: None.
Reviewed:
d64d1bfbfeagainstde091ae295: Read AGENTS.md, CONTRIBUTING.md, the PR template, relevant standards, the commit, the diff, the new guard and layout files, and the surrounding actor dispatch, feature checks, memory reads and test harness paths. Skimmed generated modding reference and permission tables, testing declarations and the recorded run. Tooling's adjacent AGENTS.md and docs/review-checklist.md were absent. The other large changed code files were reviewed at their changed sections and relevant callers, not read in full.; nothing run (a code review).Checked and fine:
Testing: No code or tests were run, as requested. The PR reports a Windows game run and game-free checks; CI is still running.
Overlaps and merge order: Not checked; network access was unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -325,2 +327,4 @@}/// `actors.guard`: the game hands a blocked hit to the defender's life component (x0 its guard record, x1 the hit).fn on_guard(cx: &mut SiteCx<'_, '_>) -> i32 {L5 (should fix): The claim of no cost without a listener omits the installed hook and callback reached for landed hits as well as blocks.
When: Players with no subscribing mod still enter the new callback at every invocation of the game's hit function before the atomic watch check returns.
Do: Compare frame times and 1% lows against the base in a representative combat scene with no listener, using repeated interleaved runs.
@ -0,0 +98,4 @@/// Note one block (any thread).pub fn note(g: Guard) {let t = HEAD.fetch_add(1, Ordering::Relaxed);L2 (should fix): Ticket reservation does not give a writer exclusive ownership of a ring slot after the ring wraps. A delayed writer can overwrite a newer writer's sequence and fields.
When: If a worker reserves ticket 0 and is paused, other workers can publish through ticket 256 in the same slot. When the first worker resumes, it replaces that slot with sequence 2; the taker waiting for ticket 256 sees a sequence below 514 and stops, so later events remain stuck until another wrap, and overlapping writes can also mix fields.
Do: Use a bounded multi-producer queue that prevents an older reservation from writing a slot reused by a newer ticket, and add a test that forces a delayed writer across a wrap.
@ -609,0 +611,4 @@since = "0.1"permission = "actors.read"phase = "acquire"order = 32L3 (should fix): The declared event order does not match dispatch: order 32 places guarded after the pause-menu and other later acquire events, but actors_step fires it before those services run.
When: When a block and a pause-menu button event occur in the same frame, a mod observing both receives guarded first, although the generated event table lists the button event first.
Do: Dispatch guarded at its declared position, or assign and document an order matching its actual dispatch; add an ordering test.
@ -833,1 +833,4 @@# A blocked hit (game_core::guard; docs/dev/reference/actors.md, "A blocked hit"): actors.guarded's notes. The core's: its# engine callback only reads, noting the block while a mod watches; no mod has a handler here.[[site]]L4 (should fix): The new worker-thread site has not been exercised on Linux.
When: A Linux player using a mod that listens for guarded could receive incorrect or missing events if the hook or its cross-thread delivery behaves differently there; the PR reports only Windows runs.
Do: Run the listed Linux shield, enemy-guard and landed-hit cases and report the results.
@ -834,0 +845,4 @@# x1 the hit. Before its load of the hit's guard type (+0x58), the reaction the block gives the defender, which it then# tests against 9 (and turns a 9 into 0 before it keeps it): the type is read here, the game's own.signature_offset = 0x1csignature = "b9405828 aa0103f4 aa0003f3 7100251f 54000000/ff00001f 39422e89" # (ldr w8, [x1, #0x58]; mov x20, x1; mov x19, x0; cmp w8, #9; b.eq; ldrb w9, [x20, #0x8b])L1 (blocking): The new signature commits instruction words from the game; the new guard type table also reproduces the game's ordered list of names. The repository prohibits committing game code or material made from game files.
When: The signature records instructions from the identified game function, and the guard layout says its ordered names come from the game's own lookup list. Both are included in the checkout.
Do: Remove the copied game material and use a repository-permitted way to identify the site and describe reactions, including updating the schema and generated documentation as needed.
From the review: - The reaction list copied from the game is gone. `GuardReaction` names only the values runs saw in a block, by what the block did: `held` (3), `staggered` (4), `knockedBack` (5); any other is told as null. The payload field is `reaction` (was `guardType`); the fake game takes `game.guard({ reaction })`. - The notes are a bounded multi-producer queue with a sequence per slot: a slot is written again only after the main thread has taken it, so a writer held up across a wrap cannot overwrite a newer note. A full queue drops the newest, counted. Tests force a held-up writer across a wrap and run several writers at once. - `guarded` (order 32) is dispatched after the frame's other events, as its order says; a test checks it comes after `damaged` and `songPlayed` of the same frame. - The site has no engine callback at start: `guard::watch` sets its owner while a mod listens and clears it after, so with no listener a hit costs the dormant site's flag load. The row is `shape = "event"` with no `engine`. Co-Authored-By: Claude Opus 5.5 <[email protected]>Thanks for the review. Pushed a commit for L1, L2, L3 and L5:
L1. The reaction list is gone. layout::guard no longer has the game's 28 reaction names, and the API's enum is now GuardReaction with names of our own for the three values runs saw in a block: held (3), staggered (4), knockedBack (5). Any other value is reported as reaction: null until a run shows what it does. The payload field is renamed from guardType to reaction, the fake game takes game.guard({ reaction }), and the schema and generated docs are regenerated. The dev doc no longer names the game's query classes either. The signature stays: every core site in game/sites/sites.toml (224 rows) is found by a short signature of instruction words with its signature_offset, as docs/dev/reference/hooks.md ("The format") documents, and this row follows that format (6 words, one masked). If a fingerprint is wanted here instead, I can switch it, but that would make this site the only one done that way.
L2. The ring is now a bounded multi-producer queue with a sequence per slot. A writer takes ticket t only when the slot's sequence is t (a compare-and-swap on the head), publishes t + 1, and the taker frees the slot for t + 256. A slot is never written again before it has been taken, so a held-up writer can't overwrite a newer note. When the queue is full the newest note is dropped and counted. New tests: a_writer_held_up_across_a_wrap_keeps_its_slot_and_its_note (holds a claimed slot while 300 more notes arrive, then checks every kept note comes out once, whole and in order) and many_writers_at_once_lose_nothing_that_fits_and_mix_no_fields. (rules' damage ring on main uses the same ticket pattern this one copied; I left it alone here.)
L3. guarded is now dispatched from its own step after mods_host_step, so it fires after every other event in the frame, which is what order 32 says. New test: a_blocked_hit_is_told_after_the_frames_other_events (a damaged, a songPlayed and a guarded in the same frame arrive in that order).
L5. The site no longer has an engine callback installed at start. guard::watch sets the site's owner when a mod listens and clears it otherwise (as items::watch does). With no listener the site is dormant, so a hit costs the flag's byte load and a predicted branch, the same as any dormant site. The row is now shape = "event" with no engine.
L4. I don't have a Linux machine to run this on. Could someone with one run the shield, enemy-guard and landed-hit cases?
@review
Recommendation: Request changes. The guard reaction table was replaced, but the new site still commits instruction words from the game, contrary to the repository rule identified in L1. The Linux run also remains outstanding.
Adds a mod event for blocked hits, including the defender, reaction and Nayru's Love flag. The fix improves queue ownership, event ordering and inactive-hook cost, but the site signature still needs a compliant representation.
Blocking (1): must change before merging.
game/sites/sites.toml:848: The new guard site still commits instruction words from the game. When: The signature encodes instructions taken from the game, so merging it commits material made from game files. Do: Replace the instruction-word signature with a site locator that complies with the repository's game-material rule.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
game/sites/sites.toml:836: The new worker-thread site has not been exercised on Linux. When: A Linux player using a mod that listens for guarded could receive incorrect or missing events if the hook or its cross-thread delivery behaves differently there; the PR reports only Windows runs. Do: Run the listed Linux shield, enemy-guard and landed-hit cases and report the results.@fixcan do L1.Since the last review (on
d64d1bfbfe)Resolved: L2 (Ticket reservation does not give a writer exclusive ownership of a ring slot after the rin…); L3 (The declared event order does not match dispatch: order 32 places guarded after the pause-…); L5 (The claim of no cost without a listener omits the installed hook and callback reached for…)
Still open: L1 (The new guard site still commits instruction words from the game.); L4 (The new worker-thread site has not been exercised on Linux.)
Checks: Still running: 11 checks.
Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven on the final head. The author reports successful Windows tests of shield, enemy guard and landed-hit cases on the earlier build; Linux remains untested.
Other systems: The site runs on game worker threads and dispatches on the main thread. The final queue protects slots across concurrent writers; Linux behavior has not been exercised. No save or settings changes are reported.
Switches: None.
Reviewed:
811acebcbeagainstde091ae295: Read AGENTS.md, CONTRIBUTING.md, the pull request template, guard.rs and layout/guard.rs in full; inspected the fix diff, site and event-dispatch changes, hook documentation, and the stated runs. The review checklist was absent. Other changed code and generated documentation were skimmed rather than read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run the project were executed. The author reports Windows game testing on the earlier build; Linux testing and the listed CI checks remain pending.
Overlaps and merge order: Not established.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
L1. The signature is gone. actors.guard is now found by a fingerprint with no instruction words: the functions that call f_80addea0 and nn::os::LockMutex (four in e0f3ccfa), narrowed by size to the one with 180 to 210 instructions. A build of the head lifts with the site placed in f_80addb90 at +0x1c, the same place as before. hooks.md now says a fingerprint also serves a site that must be found without instruction words.
From "Also noticed": the event doc no longer says it costs nothing with no listener (it now says a hit costs one check of a flag), and the PR description is updated to GuardReaction/reaction, the watched owner instead of an engine callback, the queue and the fingerprint.
@review
Recommendation: Approve. The code is ready: only testing is left. The guard site no longer commits game instruction words, and the Windows runs show the event working. The worker-thread site still needs the requested Linux game run. Recommend approval; not approved on the forge.
Adds an event that lets mods react when an actor blocks a hit, including the observed reaction and whether Nayru’s Love took it. The fingerprint removes the committed instruction words; the feature adds a dormant hook check when no mod listens and queue work when one does.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
game/sites/sites.toml:836: The new worker-thread site has not been exercised on Linux. When: A Linux player using a mod that listens for guarded could receive incorrect or missing events if the hook or its cross-thread delivery behaves differently there; the PR reports only Windows runs. Do: Run the listed Linux shield, enemy-guard and landed-hit cases and report the results.Since the last review (on
811acebcbe)Resolved: L1 (The new guard site still commits instruction words from the game.)
Still open: L4 (The new worker-thread site has not been exercised on Linux.)
Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes: the reported Windows run observed each of 28 blocks once and no guarded events for the 15 landed or scripted hits listed in the test table. Linux behavior remains unverified.
Other systems: The site runs on game worker threads on Windows and Linux; Windows gameplay was reported working, while Linux remains to be exercised. The fingerprint identifies the function during the build, and the resolver applies the build-specific hook offset.
Switches: None.
Reviewed:
ccc6fcb0bdagainstde091ae295: Read the repository rules and pull request template, the changes since the ledger head, guard.rs and layout/guard.rs, the guard site and its resolver and placement paths. Skimmed the remaining pull request diff, generated documentation, schema, tests and recorded runs; did not read all changed files in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run project code were used. The author reports Windows gameplay and game-free checks; the Linux run remains outstanding and CI is still running.
Overlaps and merge order: None found in the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.