WIP: feat(modapi): watch the game's event flows run: eventStarted, eventEnded and flowStep #3203

Draft
ChloeNow wants to merge 2 commits from ChloeNow/Longshot:feat/modapi-event-flows-main into main
Member

feat(modapi): watch the game's event flows run: eventStarted, eventEnded and flowStep

Summary

Part of #2783 (Ocarina Forge, from glinesbdev): a mod can now watch the game's event flows as they run, read-only.
longshot/game gets three events:

  • eventStarted / eventEnded: the event the game's event manager plays (a cutscene, a conversation, a door, a
    map's arrival), by its flowchart and entry point ({ flow: "DefaultBootEvent", entry: "DefaultBootEvent" }). Another
    event taking its place is an end, then a start, in one frame.
  • flowStep: every action and query step of every flow the game runs, in order, at the next frame: its flowchart,
    the step's name, "action" or "query", the actor and its sub name, the action's or query's name, its parameters by
    name as the flowchart has them (numbers, booleans, texts, arrays), and a query's answer. At most 256 between frames.

What it is for: learning how the game's own flows work before patching one (which answer of a query means yes, what a
fade's Length does, which flowchart a cutscene is), and following a cutscene. Nothing can be changed through it.

How it works (game_core::flows; docs/dev/reference/game-events.md#event-flows has the layouts):

  • Two sites in evfl's step loop, FlowchartContext::ProcessContext (f_81248840, e0f3ccfa): flows.query just
    after a query returned (its answer in w0) and flows.action before an action's lookup. Each copies the step (names
    and parameters, bounded) from the work item and the ResEvent into a queue the API takes once a frame. The sites are
    owned only while a mod listens to flowStep.
  • The event playing is EventMgr's: its flowchart context is inline in the event at an offset that depends on the
    event's kind (+0x13c8 for the title's, +0x1398 for a save's load, +0x2828 for the boot's). It is found once an event
    by the context's +0x48, which points back to it (searched from +0x1000 to +0x3000), and checked by the names it gives.
    Its flowchart and entry point names come from the context's indices.
  • An event whose context has no names yet (a conversation's, as it starts) holds its eventStarted until its first
    step names it from the step's flowchart, a second at most; its entry is then empty. One told with no name gets the
    name a later step gives at its eventEnded.
  • The fake game: game.startEvent(flow, entry?), game.endEvent(), game.flowStep({ ... }).
  • Docs: docs/modding/game-events.md#event-flows (and the fake game's rows), the dev reference's section, the
    generated reference.

Read first: game/crates/game-core/src/flows.rs, then the firing in game/crates/api/src/services/game.rs.

Testing

Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU.

  • game-core flows::tests (new, 4): a step read from a made-up flowchart in fake memory (flowchart, event, actor,
    action and query names, Bool / Int / Float-array parameters), an event's context found by its self-pointer at
    either offset (a decoy passed over), the queue kept only while watched and bounded at 256
    (the rest counted), the fake game's event as the one playing.

  • modtool testing_game::tests::event_flows_their_events_and_steps (new): a mod's listeners in the fake game see
    eventStarted, steps with their parameters as JSON and a query's answer, another event's start as end + start, and
    eventEnded; an event with no name told once its first step names it, one with no step for a second told unnamed
    and named at its end.

  • In game (dev.py game-tests, a test mod on the kokiri-start save; passed): eventStarted
    TitleEvent:Title_Loop on the title screen and its eventEnded as the save is loaded, then
    DefaultBootEvent:DefaultBootEvent for the save's load (26 frames) and its end. flowStep saw the title's steps and
    the load's on the flow worker thread, in the order the flowchart has them (its Common subflow included), with
    parameters by name and the queries' answers (EventQueryCheckPlayerState State 0 β†’ 0, 2 β†’ 1, 32 β†’ 0).

  • Played, with #3204 and the screen fade (a playtest mod: a tick per step, a chime per check, the scene's name and
    steps on a card and in a list after it): the Kokiri shopkeeper's conversation, the character at the forest's
    entrance, warps, the ocarina, and the target-shooting minigame (MiniGame_HitTarget, 81 to 93 steps), each named
    (Npc_Kokiri_001_Shop_Adult, MiniGame_HitTarget:Ready_Npc_Hylia_019_Shop_Child_Talk), every step listed with its
    actor, parameters and answer. The playtest first found conversations and the minigame's results with no name (fixed
    in f513a6243).

Still to test:

  • Linux: mise run test (CI).

Measurements

Nothing to measure while no mod listens: the sites are not owned then. With a listener, each step is a few bounded
reads and a push under a lock (flowStep is for watching, not for every player's mods).

Risks

Two new engine sites in the flow runner: if their signatures stop matching on another build, flowStep is absent
there (has() false) and nothing else changes. The readers are bounded and never fault (an unreadable step is
dropped).

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

  • 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.
  • Approved in review, every comment answered.
  • CI passes on the head.

πŸ€– Generated with Claude Code

feat(modapi): watch the game's event flows run: eventStarted, eventEnded and flowStep ## Summary Part of #2783 (Ocarina Forge, from glinesbdev): a mod can now watch the game's event flows as they run, read-only. `longshot/game` gets three events: - **`eventStarted` / `eventEnded`**: the event the game's event manager plays (a cutscene, a conversation, a door, a map's arrival), by its flowchart and entry point (`{ flow: "DefaultBootEvent", entry: "DefaultBootEvent" }`). Another event taking its place is an end, then a start, in one frame. - **`flowStep`**: every action and query step of every flow the game runs, in order, at the next frame: its flowchart, the step's name, `"action"` or `"query"`, the actor and its sub name, the action's or query's name, its parameters by name as the flowchart has them (numbers, booleans, texts, arrays), and a query's answer. At most 256 between frames. What it is for: learning how the game's own flows work before patching one (which answer of a query means yes, what a fade's `Length` does, which flowchart a cutscene is), and following a cutscene. Nothing can be changed through it. How it works (`game_core::flows`; `docs/dev/reference/game-events.md#event-flows` has the layouts): - **Two sites in evfl's step loop**, `FlowchartContext::ProcessContext` (`f_81248840`, e0f3ccfa): `flows.query` just after a query returned (its answer in `w0`) and `flows.action` before an action's lookup. Each copies the step (names and parameters, bounded) from the work item and the `ResEvent` into a queue the API takes once a frame. The sites are owned only while a mod listens to `flowStep`. - **The event playing** is EventMgr's: its flowchart context is inline in the event at an offset that depends on the event's kind (+0x13c8 for the title's, +0x1398 for a save's load, +0x2828 for the boot's). It is found once an event by the context's +0x48, which points back to it (searched from +0x1000 to +0x3000), and checked by the names it gives. Its flowchart and entry point names come from the context's indices. - **An event whose context has no names yet** (a conversation's, as it starts) holds its `eventStarted` until its first step names it from the step's flowchart, a second at most; its `entry` is then empty. One told with no name gets the name a later step gives at its `eventEnded`. - **The fake game**: `game.startEvent(flow, entry?)`, `game.endEvent()`, `game.flowStep({ ... })`. - **Docs**: `docs/modding/game-events.md#event-flows` (and the fake game's rows), the dev reference's section, the generated reference. Read first: `game/crates/game-core/src/flows.rs`, then the firing in `game/crates/api/src/services/game.rs`. ## Testing **Tested:** Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU. - `game-core` `flows::tests` (new, 4): a step read from a made-up flowchart in fake memory (flowchart, event, actor, action and query names, Bool / Int / Float-array parameters), an event's context found by its self-pointer at either offset (a decoy passed over), the queue kept only while watched and bounded at 256 (the rest counted), the fake game's event as the one playing. - `modtool` `testing_game::tests::event_flows_their_events_and_steps` (new): a mod's listeners in the fake game see `eventStarted`, steps with their parameters as JSON and a query's answer, another event's start as end + start, and `eventEnded`; an event with no name told once its first step names it, one with no step for a second told unnamed and named at its end. - In game (`dev.py game-tests`, a test mod on the `kokiri-start` save; passed): `eventStarted` `TitleEvent:Title_Loop` on the title screen and its `eventEnded` as the save is loaded, then `DefaultBootEvent:DefaultBootEvent` for the save's load (26 frames) and its end. `flowStep` saw the title's steps and the load's on the flow worker thread, in the order the flowchart has them (its `Common` subflow included), with parameters by name and the queries' answers (`EventQueryCheckPlayerState` `State` 0 β†’ 0, 2 β†’ 1, 32 β†’ 0). - Played, with #3204 and the screen fade (a playtest mod: a tick per step, a chime per check, the scene's name and steps on a card and in a list after it): the Kokiri shopkeeper's conversation, the character at the forest's entrance, warps, the ocarina, and the target-shooting minigame (`MiniGame_HitTarget`, 81 to 93 steps), each named (`Npc_Kokiri_001_Shop_Adult`, `MiniGame_HitTarget:Ready_Npc_Hylia_019_Shop_Child_Talk`), every step listed with its actor, parameters and answer. The playtest first found conversations and the minigame's results with no name (fixed in f513a6243). **Still to test:** - Linux: `mise run test` (CI). ## Measurements Nothing to measure while no mod listens: the sites are not owned then. With a listener, each step is a few bounded reads and a push under a lock (`flowStep` is for watching, not for every player's mods). ## Risks Two new engine sites in the flow runner: if their signatures stop matching on another build, `flowStep` is absent there (`has()` false) and nothing else changes. The readers are bounded and never fault (an unreadable step is dropped). ## 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. - [ ] `mise run test` passes (any failure that also fails on `main` is named). <!-- the new tests run; the whole suite not yet --> - [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] 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. - [ ] Approved in review, every comment answered. - [ ] CI passes on the head. πŸ€– Generated with [Claude Code](https://claude.com/claude-code)
feat(modapi): watch the game's event flows run: eventStarted, eventEnded and flowStep
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
aebeded65f
Part of #2783. Two sites in evfl's step loop (flows.query, flows.action) copy
each step (flowchart, actor, action or query, parameters by name, a query's
answer) into a queue the API fires as flowStep at the next frame; the sites are
owned only while a mod listens. eventStarted and eventEnded follow EventMgr's
event, named by its flowchart context, which is found by its self-pointer.
Fake game: startEvent, endEvent, flowStep.

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

Tested in game: Windows 11, RTX 4060 Laptop GPU: dev.py game-tests with a test mod on the kokiri-start save (passed). eventStarted/eventEnded named TitleEvent:Title_Loop on the title screen and DefaultBootEvent:DefaultBootEvent for the save's load; flowStep saw both events' steps in the flowchart's order with their parameters and the queries' answers.

Tested in game: Windows 11, RTX 4060 Laptop GPU: dev.py game-tests with a test mod on the kokiri-start save (passed). eventStarted/eventEnded named TitleEvent:Title_Loop on the title screen and DefaultBootEvent:DefaultBootEvent for the save's load; flowStep saw both events' steps in the flowchart's order with their parameters and the queries' answers.
Member

Possibly related, for context:

  • PR #3204 WIP: feat(modapi): flags.evaluate, enumValue and enumValues: the game's BoolExp flags and enum values by name β€” Parallel #2783 work adds read APIs for flow checks
Possibly related, for context: - PR #3204 WIP: feat(modapi): flags.evaluate, enumValue and enumValues: the game's BoolExp flags and enum values by name β€” Parallel #2783 work adds read APIs for flow checks
Owner
@review
BeanBot requested changes 2026-12-04 21:21:50 +00:00
Dismissed
BeanBot left a comment

Recommendation: Request changes. The flow-step availability check can report incomplete support, and watch lifetime and fake-game cases can give mods missing or incorrect events. The Windows game run shows the intended paths working, but does not cover these cases or the live paths on Linux.

Adds read-only event-flow notifications for mods and corresponding fake-game helpers. It makes flow inspection possible, at the cost of new worker-thread hooks and live-memory reads whose safety and event identity handling need work.

Blocking (1): must change before merging.

  1. L1 game/crates/api/src/services/features.rs:141: The common site check accepts any one listed site, but flowStep requires both to provide actions and queries. (more on the line) Do: Require both placed sites for flowStep and test each partial-placement case.

Should fix (3): not blocking, but worth doing before merging.

  • L2 game/crates/game-core/src/flows.rs:148: Disabling the watch clears the queue without synchronizing with callbacks that already passed the watch check. (more on the line) Do: Check the watch state while holding the queue lock, or associate queued steps with a watch generation and discard steps from older generations.
  • L3 game/crates/game-core/src/flows.rs:229: In the fake game, an explicitly ended event falls through to the fake world's EventMgr instead of reliably returning no event. (more on the line) Do: Make the fake implementation return the fake event state directly, including None, without falling back to the live-memory reader. Test endEvent while the fake world is in movie mode.
  • L4 game/crates/game-core/src/flows.rs:214: Pointer arithmetic happens before the checked memory reader, so a torn or invalid pointer can overflow rather than being rejected. (more on the line) Do: Pass offsets to the checked memory helpers or use checked_add for every pointer calculation before dereferencing it, and test wrapping pointers.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L5 game/crates/game-core/src/flows.rs:247: The new live-memory and worker-hook paths have only an in-game Windows run; their behavior on Linux remains untested. (more on the line) Do: Run the event and step listener in game on Linux, including a transition between events and an event end, and report the result.

@fix can do L1, L2, L3 and L4.

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

  • game/crates/api/src/services/game.rs:315: Can EventMgr replace an event with a new instance at the same address between two frame samples?
  • game/crates/game-core/src/flows.rs:250: Can EventMgr reuse an event address for a later event whose context is at a different offset?

Checks: Still running: 11 checks.

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

Does it help: Unproven for the full feature: the author reports a successful Windows game run for title and save-load events and their steps. Other event lifetimes and Linux have not been demonstrated.

Other systems: The hooks run on a flow worker and the event scan runs during frame processing. Windows guest heap pages may be decommitted; Linux and other event kinds have not been tested in game. GPU-specific rendering is not changed.

Switches: None.

Reviewed: aebeded65f against 18edd5097e: Read AGENTS.md, CONTRIBUTING.md, the pull request template, relevant standards, the commit, flows.rs, the feature dispatch and memory readers. Reviewed the changed API, fake-game, schema, site and documentation diffs; the larger surrounding files and generated reference were skimmed, not read in full. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review).

Checked and fine:

  • The commit records AI assistance with a Co-Authored-By trailer.
  • No switch, renderer API change, shader or third-party change appears in the diff.
  • The reported Windows run exercised both action and query steps and event transitions.

Testing: No code or tests were run, as requested. The author reports Windows game and unit-test runs; CI is still running.

Overlaps and merge order: Unknown; network access was unavailable.


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

**Recommendation: Request changes.** The flow-step availability check can report incomplete support, and watch lifetime and fake-game cases can give mods missing or incorrect events. The Windows game run shows the intended paths working, but does not cover these cases or the live paths on Linux. Adds read-only event-flow notifications for mods and corresponding fake-game helpers. It makes flow inspection possible, at the cost of new worker-thread hooks and live-memory reads whose safety and event identity handling need work. **Blocking (1)**: must change before merging. 1. **L1** `game/crates/api/src/services/features.rs:141`: The common site check accepts any one listed site, but flowStep requires both to provide actions and queries. (more on the line) **Do:** Require both placed sites for flowStep and test each partial-placement case. **Should fix (3)**: not blocking, but worth doing before merging. - **L2** `game/crates/game-core/src/flows.rs:148`: Disabling the watch clears the queue without synchronizing with callbacks that already passed the watch check. (more on the line) **Do:** Check the watch state while holding the queue lock, or associate queued steps with a watch generation and discard steps from older generations. - **L3** `game/crates/game-core/src/flows.rs:229`: In the fake game, an explicitly ended event falls through to the fake world's EventMgr instead of reliably returning no event. (more on the line) **Do:** Make the fake implementation return the fake event state directly, including None, without falling back to the live-memory reader. Test endEvent while the fake world is in movie mode. - **L4** `game/crates/game-core/src/flows.rs:214`: Pointer arithmetic happens before the checked memory reader, so a torn or invalid pointer can overflow rather than being rejected. (more on the line) **Do:** Pass offsets to the checked memory helpers or use checked_add for every pointer calculation before dereferencing it, and test wrapping pointers. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L5** `game/crates/game-core/src/flows.rs:247`: The new live-memory and worker-hook paths have only an in-game Windows run; their behavior on Linux remains untested. (more on the line) **Do:** Run the event and step listener in game on Linux, including a transition between events and an event end, and report the result. `@fix` can do L1, L2, L3 and L4. **Questions (2)** (not confirmed from the code; they don't hold the recommendation) - `game/crates/api/src/services/game.rs:315`: Can EventMgr replace an event with a new instance at the same address between two frame samples? - `game/crates/game-core/src/flows.rs:250`: Can EventMgr reuse an event address for a later event whose context is at a different offset? **Checks:** Still running: 11 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven for the full feature: the author reports a successful Windows game run for title and save-load events and their steps. Other event lifetimes and Linux have not been demonstrated. **Other systems:** The hooks run on a flow worker and the event scan runs during frame processing. Windows guest heap pages may be decommitted; Linux and other event kinds have not been tested in game. GPU-specific rendering is not changed. **Switches:** None. **Reviewed:** aebeded65fcb against 18edd5097e36: Read AGENTS.md, CONTRIBUTING.md, the pull request template, relevant standards, the commit, flows.rs, the feature dispatch and memory readers. Reviewed the changed API, fake-game, schema, site and documentation diffs; the larger surrounding files and generated reference were skimmed, not read in full. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review). **Checked and fine:** - The commit records AI assistance with a Co-Authored-By trailer. - No switch, renderer API change, shader or third-party change appears in the diff. - The reported Windows run exercised both action and query steps and event transitions. **Testing:** No code or tests were run, as requested. The author reports Windows game and unit-test runs; CI is still running. **Overlaps and merge order:** Unknown; network access was unavailable. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -138,6 +138,7 @@ fn sites_of(name: &str) -> &'static [&'static str] {
"camera.override.lens" => &["camera.lens", "jitter.viewRows", "jitter.viewRowX", "jitter.viewRowY"],
"camera.override.collide" => &["physics.stepped", "physics.steppedOther"],
"game.songPlayed" => &["ocarina.melody"],
"game.flowStep" => &["flows.query", "flows.action"],
Member

L1 (blocking): The common site check accepts any one listed site, but flowStep requires both to provide actions and queries.

When: On a build where only flows.action is placed, has("game.flowStep") returns true and a mod requiring it loads, but receives no query steps; the converse loses actions.

Do: Require both placed sites for flowStep and test each partial-placement case.

**L1** (blocking): The common site check accepts any one listed site, but flowStep requires both to provide actions and queries. *When:* On a build where only flows.action is placed, has("game.flowStep") returns true and a mod requiring it loads, but receives no query steps; the converse loses actions. **Do:** Require both placed sites for flowStep and test each partial-placement case.
@ -0,0 +145,4 @@
if WATCH_ON.swap(on, Ordering::AcqRel) == on {
return;
}
if !on {
Member

L2 (should fix): Disabling the watch clears the queue without synchronizing with callbacks that already passed the watch check.

When: A worker passes the check, the last listener is removed and watch(false) clears the queue, then the worker pushes its old step. A later listener enables the watch and receives that step as though it occurred during its subscription.

Do: Check the watch state while holding the queue lock, or associate queued steps with a watch generation and discard steps from older generations.

**L2** (should fix): Disabling the watch clears the queue without synchronizing with callbacks that already passed the watch check. *When:* A worker passes the check, the last listener is removed and watch(false) clears the queue, then the worker pushes its old step. A later listener enables the watch and receives that step as though it occurred during its subscription. **Do:** Check the watch state while holding the queue lock, or associate queued steps with a watch generation and discard steps from older generations.
@ -0,0 +211,4 @@
0
}
/// A step read from its work item and event; `None` when its flowchart or actor cannot be read.
Member

L4 (should fix): Pointer arithmetic happens before the checked memory reader, so a torn or invalid pointer can overflow rather than being rejected.

When: If the actor-table pointer read from a live record is near u64::MAX and the actor index is nonzero, the addition overflows; checked builds panic in the hook and wrapping builds can read an unrelated low address. The same pattern appears in the context and flowchart binding calculations.

Do: Pass offsets to the checked memory helpers or use checked_add for every pointer calculation before dereferencing it, and test wrapping pointers.

**L4** (should fix): Pointer arithmetic happens before the checked memory reader, so a torn or invalid pointer can overflow rather than being rejected. *When:* If the actor-table pointer read from a live record is near u64::MAX and the actor index is nonzero, the addition overflows; checked builds panic in the hook and wrapping builds can read an unrelated low address. The same pattern appears in the context and flowchart binding calculations. **Do:** Pass offsets to the checked memory helpers or use checked_add for every pointer calculation before dereferencing it, and test wrapping pointers.
@ -0,0 +226,4 @@
kind,
actor: text_at(actor, ACTOR_NAME),
actor_sub: text_at(actor, ACTOR_SUB_NAME),
name: text_at(verbs, verb * 8),
Member

L3 (should fix): In the fake game, an explicitly ended event falls through to the fake world's EventMgr instead of reliably returning no event.

When: If the fake world is in movie mode, its EventMgr event field is 1. Calling endEvent clears FAKE_PLAYING, after which playing() returns that sentinel as another event, so listeners see an unexpected start instead of just the end.

Do: Make the fake implementation return the fake event state directly, including None, without falling back to the live-memory reader. Test endEvent while the fake world is in movie mode.

**L3** (should fix): In the fake game, an explicitly ended event falls through to the fake world's EventMgr instead of reliably returning no event. *When:* If the fake world is in movie mode, its EventMgr event field is 1. Calling endEvent clears FAKE_PLAYING, after which playing() returns that sentinel as another event, so listeners see an unexpected start instead of just the end. **Do:** Make the fake implementation return the fake event state directly, including None, without falling back to the live-memory reader. Test endEvent while the fake world is in movie mode.
@ -0,0 +244,4 @@
let mgr = mem::read_ptr(holder, 0)?;
let id = crate::layout::state::EVENTMGR_EVENT.read(mgr).filter(|&e| e != 0)?;
let names = event_context(id).and_then(names_at);
let (flow, entry) = names.unwrap_or_default();
Member

L5 (should fix): The new live-memory and worker-hook paths have only an in-game Windows run; their behavior on Linux remains untested.

When: A mod listening to these events on Linux exercises the worker hooks and event-context discovery, neither of which the reported game run covers there.

Do: Run the event and step listener in game on Linux, including a transition between events and an event end, and report the result.

**L5** (should fix): The new live-memory and worker-hook paths have only an in-game Windows run; their behavior on Linux remains untested. *When:* A mod listening to these events on Linux exercises the worker hooks and event-context discovery, neither of which the reported game run covers there. **Do:** Run the event and step listener in game on Linux, including a transition between events and an event end, and report the result.
Author
Member

Found in a playtest (a mod built on this PR, #3204 and the screen fade, played on Windows): some events reach mods with no name. eventStarted / eventEnded give flow: "", entry: "" while their steps still come through.

  • The adult character at the Kokiri Forest entrance: : 31 steps every time.
  • The Kokiri shopkeeper: named once (Npc_Kokiri_001_Shop_Adult, 44 steps), unnamed on another talk (54 steps).
  • Warps (Dm_SY_BancChangeGo / Arrive) were named.

Why (a temporary log in the game): the event's flowchart context sits further in than the range searched (+0x2828 in the boot event, +0x2370 in a conversation; the range was +0x1000..+0x2000), and in a conversation its names are still empty when the event starts.

Fix coming to this branch: search to +0x3000, and when the context has no names yet, hold eventStarted (10 frames at most) until the event's first step names it from its flowchart. The fake-game test covers both cases. I'll check it in game again before marking this ready.

Found in a playtest (a mod built on this PR, #3204 and the screen fade, played on Windows): **some events reach mods with no name.** `eventStarted` / `eventEnded` give `flow: ""`, `entry: ""` while their steps still come through. - The adult character at the Kokiri Forest entrance: `: 31 steps` every time. - The Kokiri shopkeeper: named once (`Npc_Kokiri_001_Shop_Adult`, 44 steps), unnamed on another talk (54 steps). - Warps (`Dm_SY_BancChangeGo` / `Arrive`) were named. Why (a temporary log in the game): the event's flowchart context sits further in than the range searched (+0x2828 in the boot event, +0x2370 in a conversation; the range was +0x1000..+0x2000), and in a conversation its names are still empty when the event starts. Fix coming to this branch: search to +0x3000, and when the context has no names yet, hold `eventStarted` (10 frames at most) until the event's first step names it from its flowchart. The fake-game test covers both cases. I'll check it in game again before marking this ready.
fix(modapi): name every event, from its first step when its context has none
Some checks failed
PR description / Title and description (pull_request_target) Successful in 6s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
f513a62438
A playtest found events reaching mods with no name: a conversation's
flowchart context has no names yet when it starts, the boot event's sits
at +0x2828 (past the +0x2000 searched), and a minigame's results scene
takes more than 10 frames to its first step. The search now goes to
+0x3000; an event with no name holds its eventStarted (a second at most)
until its first step names it from its flowchart, and an event told with
no name gets the name a later step gives at its eventEnded.

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

Pushed f513a6243: every event is named now. The playtest's unnamed events (a conversation's context with no names yet as it starts, the boot event's context past the range searched, a minigame's results scene slow to its first step) are named from their first step's flowchart, and the search goes to +0x3000. Played again: the conversations and the minigame named. Testing updated.

Pushed f513a6243: every event is named now. The playtest's unnamed events (a conversation's context with no names yet as it starts, the boot event's context past the range searched, a minigame's results scene slow to its first step) are named from their first step's flowchart, and the search goes to +0x3000. Played again: the conversations and the minigame named. Testing updated.
Owner
@rebase
Member

I rebased this pull request onto main (37f90245b0): the new head is d04fb3ee14.

Conflicts resolved

  • docs/modding/permissions.md: Kept the base schema stamp and the flow-event permissions.
  • docs/modding/reference.md: Kept the pause-menu and flow-event entries, with flow-event orders 34–36.
  • docs/modding/scripting.md: Kept both feature sets and updated the flow-event orders.
  • docs/modding/game-events.md: Updated the documented flow-event orders to 34–36.
  • game/modapi/schema/game.toml: Moved the flow-event orders to 34–36, preserving the base branch’s order 31.
  • Also changed, beyond the conflict: docs/modding/game-events.md, game/modapi/schema/game.toml

Nothing was built or run: read the resolution before merging.


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

I rebased this pull request onto `main` (37f90245b0d1): the new head is d04fb3ee145d. **Conflicts resolved** - docs/modding/permissions.md: Kept the base schema stamp and the flow-event permissions. - docs/modding/reference.md: Kept the pause-menu and flow-event entries, with flow-event orders 34–36. - docs/modding/scripting.md: Kept both feature sets and updated the flow-event orders. - docs/modding/game-events.md: Updated the documented flow-event orders to 34–36. - game/modapi/schema/game.toml: Moved the flow-event orders to 34–36, preserving the base branch’s order 31. - Also changed, beyond the conflict: `docs/modding/game-events.md`, `game/modapi/schema/game.toml` Nothing was built or run: read the resolution before merging. --- <sub>Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot force-pushed feat/modapi-event-flows-main from f513a62438
Some checks failed
PR description / Title and description (pull_request_target) Successful in 6s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
to d04fb3ee14
Some checks are pending
PR description / Title and description (pull_request_target) Successful in 6s
CI / What the change needs (pull_request) Successful in 6s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Waiting to run
CI / Website build and checks (pull_request) Waiting to run
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Waiting to run
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Waiting to run
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Waiting to run
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Waiting to run
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Waiting to run
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Waiting to run
CI / Third-party parts and guide screenshots (pull_request) Successful in 11s
2026-12-05 17:42:53 +00:00
Compare
BeanBot left a comment

Recommendation: Request changes. A build with only one flow hook reports flowStep as available even though it cannot deliver both actions and queries. The watch synchronization, fake-game end state and checked pointer arithmetic issues also remain unresolved.

Adds read-only event lifecycle and flow-step events for mods, with fake-game support and documentation. Windows playtesting shows the feature working; it adds live-memory reads and worker-thread hooks while watched.

Blocking (1): must change before merging.

  1. L1 game/crates/api/src/services/features.rs:141: The common site check accepts any one listed site, but flowStep requires both to provide actions and queries. When: On a build where only flows.action is placed, has("game.flowStep") returns true and a mod requiring it loads, but receives no query steps; the converse loses actions. Do: Require both placed sites for flowStep and test each partial-placement case.

Should fix (3): not blocking, but worth doing before merging.

  • L2 game/crates/game-core/src/flows.rs:148: Disabling the watch clears the queue without synchronizing with callbacks that already passed the watch check. When: A worker passes the check, the last listener is removed and watch(false) clears the queue, then the worker pushes its old step. A later listener enables the watch and receives that step as though it occurred during its subscription. Do: Check the watch state while holding the queue lock, or associate queued steps with a watch generation and discard steps from older generations.
  • L3 game/crates/game-core/src/flows.rs:229: In the fake game, an explicitly ended event falls through to the fake world's EventMgr instead of reliably returning no event. When: If the fake world is in movie mode, its EventMgr event field is 1. Calling endEvent clears FAKE_PLAYING, after which playing() returns that sentinel as another event, so listeners see an unexpected start instead of just the end. Do: Make the fake implementation return the fake event state directly, including None, without falling back to the live-memory reader. Test endEvent while the fake world is in movie mode.
  • L4 game/crates/game-core/src/flows.rs:214: Pointer arithmetic happens before the checked memory reader, so a torn or invalid pointer can overflow rather than being rejected. When: If the actor-table pointer read from a live record is near u64::MAX and the actor index is nonzero, the addition overflows; checked builds panic in the hook and wrapping builds can read an unrelated low address. The same pattern appears in the context and flowchart binding calculations. Do: Pass offsets to the checked memory helpers or use checked_add for every pointer calculation before dereferencing it, and test wrapping pointers.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L5 game/crates/game-core/src/flows.rs:247: The new live-memory and worker-hook paths have only an in-game Windows run; their behavior on Linux remains untested. When: A mod listening to these events on Linux exercises the worker hooks and event-context discovery, neither of which the reported game run covers there. Do: Run the event and step listener in game on Linux, including a transition between events and an event end, and report the result.

@fix can do L1, L2, L3 and L4.

Since the last review (on aebeded65f)
Still open: L1 (The common site check accepts any one listed site, but flowStep requires both to provide a…); L2 (Disabling the watch clears the queue without synchronizing with callbacks that already pas…); L3 (In the fake game, an explicitly ended event falls through to the fake world's EventMgr ins…); L4 (Pointer arithmetic happens before the checked memory reader, so a torn or invalid pointer…); L5 (The new live-memory and worker-hook paths have only an in-game Windows run; their behavior…)

Checks: Still running: 11 checks.

Also noticed (2; not asked for, not blocking)
  • The event context module comment still describes a fixed +0x3d8 offset, while the implementation scans a range.
  • Event-only listeners also enable flow-step hooks, so the description's statement that those sites are owned only while a mod listens to flowStep is out of date.
More: does it help, other systems, switches, what was read

Does it help: Yes: the author reports Windows in-game runs showing named events, ordered steps, parameters and query answers, including conversations and a minigame. This is a feature rather than a performance change; its runtime cost has not been measured.

Other systems: The hooks and live-memory layouts can affect Linux as well as Windows; only Windows in-game results are reported. Event listeners now also activate the step hooks to obtain names.

Switches: None.

Reviewed: d04fb3ee14 against 37f90245b0: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, flows.rs and the feature availability logic; inspected the game service diff and event dispatch around the changed lines. The remaining changed files and generated documentation were not read in full.; nothing run (a code review).

Checked and fine:

  • The rebase updates the documented and schema event orders to 34–36.
  • The author reports successful Windows playtests of the previously unnamed conversations and minigame.

Testing: No commands that build or run project code were executed. The reported Windows playtest passed; Linux in-game coverage remains outstanding and CI is still running.

Overlaps and merge order: none found


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

**Recommendation: Request changes.** A build with only one flow hook reports flowStep as available even though it cannot deliver both actions and queries. The watch synchronization, fake-game end state and checked pointer arithmetic issues also remain unresolved. Adds read-only event lifecycle and flow-step events for mods, with fake-game support and documentation. Windows playtesting shows the feature working; it adds live-memory reads and worker-thread hooks while watched. **Blocking (1)**: must change before merging. 1. **L1** `game/crates/api/src/services/features.rs:141`: The common site check accepts any one listed site, but flowStep requires both to provide actions and queries. *When:* On a build where only flows.action is placed, has("game.flowStep") returns true and a mod requiring it loads, but receives no query steps; the converse loses actions. **Do:** Require both placed sites for flowStep and test each partial-placement case. **Should fix (3)**: not blocking, but worth doing before merging. - **L2** `game/crates/game-core/src/flows.rs:148`: Disabling the watch clears the queue without synchronizing with callbacks that already passed the watch check. *When:* A worker passes the check, the last listener is removed and watch(false) clears the queue, then the worker pushes its old step. A later listener enables the watch and receives that step as though it occurred during its subscription. **Do:** Check the watch state while holding the queue lock, or associate queued steps with a watch generation and discard steps from older generations. - **L3** `game/crates/game-core/src/flows.rs:229`: In the fake game, an explicitly ended event falls through to the fake world's EventMgr instead of reliably returning no event. *When:* If the fake world is in movie mode, its EventMgr event field is 1. Calling endEvent clears FAKE_PLAYING, after which playing() returns that sentinel as another event, so listeners see an unexpected start instead of just the end. **Do:** Make the fake implementation return the fake event state directly, including None, without falling back to the live-memory reader. Test endEvent while the fake world is in movie mode. - **L4** `game/crates/game-core/src/flows.rs:214`: Pointer arithmetic happens before the checked memory reader, so a torn or invalid pointer can overflow rather than being rejected. *When:* If the actor-table pointer read from a live record is near u64::MAX and the actor index is nonzero, the addition overflows; checked builds panic in the hook and wrapping builds can read an unrelated low address. The same pattern appears in the context and flowchart binding calculations. **Do:** Pass offsets to the checked memory helpers or use checked_add for every pointer calculation before dereferencing it, and test wrapping pointers. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L5** `game/crates/game-core/src/flows.rs:247`: The new live-memory and worker-hook paths have only an in-game Windows run; their behavior on Linux remains untested. *When:* A mod listening to these events on Linux exercises the worker hooks and event-context discovery, neither of which the reported game run covers there. **Do:** Run the event and step listener in game on Linux, including a transition between events and an event end, and report the result. `@fix` can do L1, L2, L3 and L4. **Since the last review** (on aebeded65fcb) Still open: L1 (The common site check accepts any one listed site, but flowStep requires both to provide a…); L2 (Disabling the watch clears the queue without synchronizing with callbacks that already pas…); L3 (In the fake game, an explicitly ended event falls through to the fake world's EventMgr ins…); L4 (Pointer arithmetic happens before the checked memory reader, so a torn or invalid pointer…); L5 (The new live-memory and worker-hook paths have only an in-game Windows run; their behavior…) **Checks:** Still running: 11 checks. <details> <summary>Also noticed (2; not asked for, not blocking)</summary> - The event context module comment still describes a fixed +0x3d8 offset, while the implementation scans a range. - Event-only listeners also enable flow-step hooks, so the description's statement that those sites are owned only while a mod listens to flowStep is out of date. </details> <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes: the author reports Windows in-game runs showing named events, ordered steps, parameters and query answers, including conversations and a minigame. This is a feature rather than a performance change; its runtime cost has not been measured. **Other systems:** The hooks and live-memory layouts can affect Linux as well as Windows; only Windows in-game results are reported. Event listeners now also activate the step hooks to obtain names. **Switches:** None. **Reviewed:** d04fb3ee145d against 37f90245b0d1: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, flows.rs and the feature availability logic; inspected the game service diff and event dispatch around the changed lines. The remaining changed files and generated documentation were not read in full.; nothing run (a code review). **Checked and fine:** - The rebase updates the documented and schema event orders to 34–36. - The author reports successful Windows playtests of the previously unnamed conversations and minigame. **Testing:** No commands that build or run project code were executed. The reported Windows playtest passed; Linux in-game coverage remains outstanding and CI is still running. **Overlaps and merge order:** none found </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.</sub>
Some checks are pending
PR description / Title and description (pull_request_target) Successful in 6s
CI / What the change needs (pull_request) Successful in 6s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Waiting to run
CI / Website build and checks (pull_request) Waiting to run
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Waiting to run
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Waiting to run
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Waiting to run
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Waiting to run
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Waiting to run
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Waiting to run
CI / Third-party parts and guide screenshots (pull_request) Successful in 11s
This pull request has changes conflicting with the target branch.
  • docs/modding/permissions.md
  • docs/modding/reference.md
  • docs/modding/scripting.md
  • game/crates/modtool/src/testing_game/fake.js
  • game/crates/modtool/src/testing_game/tests.rs
  • game/modapi/testing/longshot-testing.d.ts
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'feat/modapi-event-flows-main:ChloeNow-feat/modapi-event-flows-main'
git switch 'ChloeNow-feat/modapi-event-flows-main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 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!3203
No description provided.