WIP: feat(mods): flow patches, new events in an event flow #2578

Closed
ChloeNow wants to merge 1032 commits from ChloeNow/Longshot:feat/mods-rs-flow-patches into mod-api
Contributor

Summary

A mod can't change one of the game's event flows (the cutscenes and scripted moments: a song played, a door's question,
a chest) without shipping a whole replaced copy of the game's file. That copy is game data, so it can't be shared, and
two mods changing one flow overwrite each other.

This adds a new kind of typed patch, "flow", next to ops, rows, placements, texts and flags, in a mod's
patches/ folder or through content.patch. It names the flow's own events, so the mod ships none of the game's file:

{ "target": "Event/EventFlow/Dm_SY_Ocarina.bfevfl.zs",
  "flow": [
    { "op": "action", "id": "Tune", "actor": "GameSystemActor", "action": "EventTriggerPlayAutoFixedTune",
      "params": { "IsLearningWarpMelodyDemo": false }, "next": "Event137" },
    { "op": "branch", "id": "TuneIfSung", "before": "Event171", "flag": ":Sung", "then": "Tune" } ] }
  • action: a new action event, an actor and action the flow already has, with params, then its next event.
  • branch: a check of a bool flag before an event. Whatever went to that event (events before it, a switch's
    cases, a fork's branches, an entry point) goes to the check; clear goes on as before, set goes to then. Two checks
    before one event chain. A fork's join is never moved. The flag is the game's by its name, or a content flag by its id
    (":Sung" the mod's own, "owner/name:Sung" another's), as the runtime takes content.

Each mod's new events are named after it (local/my-mod.Tune: its id, a . and the op's), so mods never collide, and their patches
apply in the Mods list's order, each on the one before's output. An op naming something the flow doesn't have is left
out with its reason in the log; the rest apply, as with the other typed patches. Flow patches never conflict.

Longshot writes the patched flow with its own writer: every byte of the game's file before its relocation table is
kept, the events move to a longer array after it, the new events' params (with a DIC built as Nintendo's tree, so the
game finds each param by name), cases and texts follow, then a new relocation table. The game's
EventQueryIsGameDataBool answers 0 for a set flag and 1 for a clear one, so a check's case 0 is "then".

Read first: game/crates/content/src/evfl.rs (the reader, the ops and the writer), then read_flow_op in
content/src/patch/parse.rs and the flow branch of apply in content/src/merge.rs. The fake game's twin is flowOp
in mod-tools/lib/fake-patches.js; the schema's ContentPatchFlowOp types it for content.patch. Docs:
assets/modding/docs/files.md, "Event flows".

This is #2268's change, made again on the Rust mod API; #2268 (the C mod API) can close. Part of #1958's Modding API;
targets mod-api. Magic Singing uses it with songPlayed, which waits for the hooks rework.

Testing

Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24. In the game (a quick build of this head, dev.py game-tests, the repository's kokiri-start): a test mod with Magic Singing's 96-op patch on the ocarina's flow
(Dm_SY_Ocarina) and its two content flags. The patch applies at the start with no op refused, the game loads the
patched flow (Dm_SY_Ocarina.bfevfl.zs <- modcache\files\... (made of the mods' copies)), and the mod's test passes
in play. The served file read back with the evfl library: all 96 ops as written (the actions' actors, actions, params
and next; each check EventQueryIsGameDataBool on the mod's flag, M1f6faaa6.Sung or .ButtonsToo, case 0 to
then), the 330 original events unchanged but their links, the 102 links into the 46 checked events moved to each
chain's first check, no fork's join moved, the 20 entry points as they were. A song played with a check's flag set
needs songPlayed (below).

Checks: cargo test -p content (evfl's own tests on a made-up flow, read back by a reader of the test's own: two
mods' actions and checks in order, their params found by name through the DIC as the game looks them up, the bytes
kept, every pointer in the relocation table; a flag by a mod's id, the patching mod's own and another's; bad patch
files and a file that is not an event flow refused; the output past the largest flow refused; the DIC finding every
name of many. merge's test of two mods' flow patches served in order. The content vectors, which now hold the Rust
reader to the flow rules, and the fake game's reader checked against the same cases); cargo check --workspace --all-targets; cargo run -p schema-gen -- --check; mod-tools' tests; rustfmt. The same two api loader tests and
five mod-tools tests fail on mod-api itself and here (a_content_mods_changed_module_runs_again_and_its_outputs_are_served,
the_note_goes_when_the_list_is_the_game_folders_or_not_there; mod-tools' 59, 69, 73, 86 and 100: Windows paths and
symlinks).

Still to test:

  • Linux, and clippy with warnings as errors: mise run rust and mise run test (by hand, or CI)
  • The patched flow played with a check's flag set, which needs songPlayed (Magic Singing) on the Rust API

Measurements

Nothing to measure in play: the patch is applied once at the start, with the merged files; a patched flow is a few
kilobytes larger than the game's.

Risks

Only mods that ship a "flow" patch reach the new code; with none, nothing changes. A flow patch that routes the game
somewhere wrong is the mod's to fix (turning the mod off restores the game's flow).

Checklist

Ready for review

  • One topic, on current mod-api; 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

  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • 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.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary A mod can't change one of the game's event flows (the cutscenes and scripted moments: a song played, a door's question, a chest) without shipping a whole replaced copy of the game's file. That copy is game data, so it can't be shared, and two mods changing one flow overwrite each other. This adds a new kind of typed patch, `"flow"`, next to `ops`, `rows`, `placements`, `texts` and `flags`, in a mod's `patches/` folder or through `content.patch`. It names the flow's own events, so the mod ships none of the game's file: ```json { "target": "Event/EventFlow/Dm_SY_Ocarina.bfevfl.zs", "flow": [ { "op": "action", "id": "Tune", "actor": "GameSystemActor", "action": "EventTriggerPlayAutoFixedTune", "params": { "IsLearningWarpMelodyDemo": false }, "next": "Event137" }, { "op": "branch", "id": "TuneIfSung", "before": "Event171", "flag": ":Sung", "then": "Tune" } ] } ``` - **`action`**: a new action event, an actor and action the flow already has, with params, then its next event. - **`branch`**: a check of a bool flag before an event. Whatever went to that event (events before it, a switch's cases, a fork's branches, an entry point) goes to the check; clear goes on as before, set goes to `then`. Two checks before one event chain. A fork's join is never moved. The flag is the game's by its name, or a content flag by its id (`":Sung"` the mod's own, `"owner/name:Sung"` another's), as the runtime takes content. Each mod's new events are named after it (`local/my-mod.Tune`: its id, a `.` and the op's), so mods never collide, and their patches apply in the Mods list's order, each on the one before's output. An op naming something the flow doesn't have is left out with its reason in the log; the rest apply, as with the other typed patches. Flow patches never conflict. Longshot writes the patched flow with its own writer: every byte of the game's file before its relocation table is kept, the events move to a longer array after it, the new events' params (with a DIC built as Nintendo's tree, so the game finds each param by name), cases and texts follow, then a new relocation table. The game's `EventQueryIsGameDataBool` answers **0 for a set flag and 1 for a clear one**, so a check's case 0 is "then". Read first: `game/crates/content/src/evfl.rs` (the reader, the ops and the writer), then `read_flow_op` in `content/src/patch/parse.rs` and the flow branch of `apply` in `content/src/merge.rs`. The fake game's twin is `flowOp` in `mod-tools/lib/fake-patches.js`; the schema's `ContentPatchFlowOp` types it for `content.patch`. Docs: `assets/modding/docs/files.md`, "Event flows". This is #2268's change, made again on the Rust mod API; #2268 (the C mod API) can close. Part of #1958's Modding API; targets `mod-api`. Magic Singing uses it with `songPlayed`, which waits for the hooks rework. ## Testing **Tested:** Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24. In the game (a quick build of this head, `dev.py game-tests`, the repository's `kokiri-start`): a test mod with Magic Singing's 96-op patch on the ocarina's flow (`Dm_SY_Ocarina`) and its two content flags. The patch applies at the start with no op refused, the game loads the patched flow (`Dm_SY_Ocarina.bfevfl.zs <- modcache\files\... (made of the mods' copies)`), and the mod's test passes in play. The served file read back with the evfl library: all 96 ops as written (the actions' actors, actions, params and next; each check `EventQueryIsGameDataBool` on the mod's flag, `M1f6faaa6.Sung` or `.ButtonsToo`, case 0 to `then`), the 330 original events unchanged but their links, the 102 links into the 46 checked events moved to each chain's first check, no fork's join moved, the 20 entry points as they were. A song played with a check's flag set needs `songPlayed` (below). Checks: `cargo test -p content` (`evfl`'s own tests on a made-up flow, read back by a reader of the test's own: two mods' actions and checks in order, their params found by name through the DIC as the game looks them up, the bytes kept, every pointer in the relocation table; a flag by a mod's id, the patching mod's own and another's; bad patch files and a file that is not an event flow refused; the output past the largest flow refused; the DIC finding every name of many. `merge`'s test of two mods' flow patches served in order. The content vectors, which now hold the Rust reader to the flow rules, and the fake game's reader checked against the same cases); `cargo check --workspace --all-targets`; `cargo run -p schema-gen -- --check`; mod-tools' tests; rustfmt. The same two `api` loader tests and five mod-tools tests fail on `mod-api` itself and here (`a_content_mods_changed_module_runs_again_and_its_outputs_are_served`, `the_note_goes_when_the_list_is_the_game_folders_or_not_there`; mod-tools' 59, 69, 73, 86 and 100: Windows paths and symlinks). **Still to test:** - Linux, and clippy with warnings as errors: `mise run rust` and `mise run test` (by hand, or CI) - The patched flow played with a check's flag set, which needs `songPlayed` (Magic Singing) on the Rust API ## Measurements Nothing to measure in play: the patch is applied once at the start, with the merged files; a patched flow is a few kilobytes larger than the game's. ## Risks Only mods that ship a `"flow"` patch reach the new code; with none, nothing changes. A flow patch that routes the game somewhere wrong is the mod's to fix (turning the mod off restores the game's flow). ## Checklist ### Ready for review - [x] One topic, on current `mod-api`; 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). <!-- Windows run as Testing says; clippy and Linux: CI --> - [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] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. <!-- Windows built and played; Linux: CI --> - [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. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(mods): flow patches, new events in an event flow (Rust)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 8s
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
19148a53e2
A "flow" patch adds events to an event flow (Event/EventFlow/<name>.bfevfl.zs) by the flow's own event names:
"action" (an actor's action the flow has, its params, then next) and "branch" (a bool flag checked before an
event: set, on to "then"; clear, on to "before"). The flag is the game's by its name or a content flag by its id
(":Sung", "owner/name:Sung"); each op's id is the mod's own, its event named after the mod.

content::evfl reads the BFEVFL (0x300/0x400), keeps every byte of the game's file and writes the new events,
their params, names and the relocation table after it. merge applies a flow's patches in the mods' order, each on
the previous one's output; an op that does not apply is left out and logged. Flow patches never conflict.

The patch reader, the fake game's (fake-patches.js) and the schema's ContentPatch take the new kind; the
content vectors hold both readers to the flow rules. Ported from the C mod API's PR #2268.

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

Tested in game: Windows 11, RTX 4060 Laptop, a quick build of this head: a test mod with Magic Singing's 96-op patch on Dm_SY_Ocarina applies it with no op refused, the game loads the patched flow, and the mod's test passes in play (dev.py game-tests, kokiri-start). The served flow read back with the evfl library: every op as written, the original events unchanged but their links.

Tested in game: Windows 11, RTX 4060 Laptop, a quick build of this head: a test mod with Magic Singing's 96-op patch on Dm_SY_Ocarina applies it with no op refused, the game loads the patched flow, and the mod's test passes in play (dev.py game-tests, kokiri-start). The served flow read back with the evfl library: every op as written, the original events unchanged but their links.
Author
Contributor

Moved to #2656: the same flow patches on the current mod-api (rewritten since), on a new branch so the PR is only this change.

Moved to #2656: the same flow patches on the current mod-api (rewritten since), on a new branch so the PR is only this change.
ChloeNow closed this pull request 2026-11-27 09:48:45 +00:00
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 8s
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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!2578
No description provided.