WIP: feat(mods): flow patches, new events in an event flow #2578
No reviewers
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2578
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/mods-rs-flow-patches"
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'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 toops,rows,placements,textsandflags, in a mod'spatches/folder or throughcontent.patch. It names the flow's own events, so the mod ships none of the game's file: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'scases, a fork's branches, an entry point) goes to the check; clear goes on as before, set goes to
then. Two checksbefore 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 patchesapply 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
EventQueryIsGameDataBoolanswers 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), thenread_flow_opincontent/src/patch/parse.rsand the flow branch ofapplyincontent/src/merge.rs. The fake game's twin isflowOpin
mod-tools/lib/fake-patches.js; the schema'sContentPatchFlowOptypes it forcontent.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 withsongPlayed, 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'skokiri-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 thepatched flow (
Dm_SY_Ocarina.bfevfl.zs <- modcache\files\... (made of the mods' copies)), and the mod's test passesin play. The served file read back with the evfl library: all 96 ops as written (the actions' actors, actions, params
and next; each check
EventQueryIsGameDataBoolon the mod's flag,M1f6faaa6.Sungor.ButtonsToo, case 0 tothen), the 330 original events unchanged but their links, the 102 links into the 46 checked events moved to eachchain'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: twomods' 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 Rustreader 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 twoapiloader tests andfive mod-tools tests fail on
mod-apiitself 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 andsymlinks).
Still to test:
mise run rustandmise run test(by hand, or CI)songPlayed(Magic Singing) on the Rust APIMeasurements
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 gamesomewhere wrong is the mod's to fix (turning the mod off restores the game's flow).
Checklist
Ready for review
mod-api; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.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 "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]>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.
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.
Pull request closed