feat(modapi): flags.evaluate, enumValue and enumValues: the game's BoolExp flags and enum values by name #3204
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3204
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/modapi-flag-exp-main"
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?
feat(modapi): flags.evaluate, enumValue and enumValues: the game's BoolExp flags and enum values by name
Summary
Part of #2783 (Ocarina Forge, from glinesbdev): the reads a mod needs to follow the game's own checks.
flags.evaluate(name): one of the game's BoolExp flags worked out now (SageOfForest_IsCompleted_Exp). ABoolExp is never stored: it is a rule over other flags that the game's checks ask (the flows through
GameDataActor'sEventQueryIsGameDataBoolExp, 692 steps in the game's flows).flags.getcannot read them. Nullwhen it cannot be answered (the flags not made yet, or a BoolArray it reads).
flags.enumValue(name)andflags.enumValues(name): an Enum flag's value by its name, and all its values'names in the game's order. A challenge's step is the Enum
Step_<ChallengeName>(Step_SageOfForest:NotReady,Ready,Step01, ...,Complete);getonly gives the value's hash.How it works:
GameData/GameDataList.Product.<n>.byml.zs(the loader's rule,the last by name), read once on a thread of its own as the game starts and kept (
api::services::flag_exps); untilit is read, the answers are null (
enumValuesempty). Decoding it takes about 11 ms, more than a listener's 5 msbudget, so it is never read on a mod's call. No game data in the repository.
game_core::flag_exp, pure) runs a rule's postfix steps over a stack of answers, reading flagsas
flags.getdoes. The opcodes were read off the table's shape and the entries the game's flows name (the doccomment has the table): 0 Bool, 10 nested BoolExp, 1 / 11 / 12 Enum ==, before, after a value (strictly), 15 / 18 / 19
Int ==, <, != a number, 3 and, 4 or, 5 not. An opcode the table never uses, and BoolArray reads (7 entries), answer
null rather than a guess.
game.setGameDataList({ enums, boolExps })puts a small list in the fake RomFS;setFlag(name, "Step01", { kind: "enum" })sets an Enum flag by its value's name.docs/modding/scripting.md("The game's checks"), the generated reference.Read first:
game/crates/game-core/src/flag_exp.rs.Testing
Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU.
game-coreflag_exp::tests(new, 3): enums compared in the game's order (==, strictly after, a before-and-not-afterrange), Bool / Int / nested rules, and every case that answers null (no such rule, a flag not read, a BoolArray, a
loop, a malformed rule, an unknown opcode).
apiflag_exps::tests::the_players_list_is_read_and_kept(new): a GameDataList written withcontent::bymlintothe fake RomFS is found (the last by name), read and kept.
modtooltesting_game::tests::boolexp_flags_and_enum_values_by_name(new): a mod'sevaluateandenumValueinthe fake game follow
setFlag.dev.py game-tests, a test mod on thekokiri-startsave; passed): the list read on its own thread, nolistener over its budget; in play
Step_SageOfForestreadsReadywith its 16 values in the game's order, andSageOfForest_IsCompleted_Exp,DoorOfTime_IsAfter_Step03_ExpandMiniGame_DampeRace_IsClearLeastOnceevaluatefalse, as the save's flags say.evaluatewith eachEventQueryIsGameDataBoolExpanswer the flows give: the query's answer is its branch, 0 yes): the Kokiri shopkeeper (3 checks), the
target-shooting minigame (4: two Bool rules,
MiniGame_HitTarget_IsAfter_Ready_Expat exactly Ready, and_IsAfter_Retry_Exp), and the earlier sages' checks: every answer the game's, yes and no. The minigame first showedevaluatetrue where the game said no: opcode 12 is strictly after, not at or after (fixed incd42f0f8f). In theplaytest's flags page,
Step_SageOfForestandStep_SageOfShadowreadCompletewith their 16 and 11 values, andthe rules over them answer as the steps say.
Still to test:
mise run test(CI).Measurements
Nothing to measure: the list is read once (about 1.4 MB decoded) on its own thread at start, off the frame; an evaluation is a few
flag reads.
Risks
An opcode read wrong would give a wrong answer for the rules that use it; the in-game check compares every BoolExp
the flows ask against the game's own answer. Unknown opcodes answer null.
Checklist
Ready for review
main; 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
Assisted-by:/Co-Authored-By:trailers.Ready to merge
🤖 Generated with Claude Code
Tested in game: Windows 11, RTX 4060 Laptop GPU: dev.py game-tests with a test mod on the kokiri-start save (passed). The GameDataList read on its own thread, no listener over budget; Step_SageOfForest reads Ready with its 16 values in order; SageOfForest_IsCompleted_Exp, DoorOfTime_IsAfter_Step03_Exp and MiniGame_DampeRace_IsClearLeastOnce evaluate false, as the save says. Not yet compared against a BoolExp a flow asks in play (the load asks none).
@review
Recommendation: Request changes. The fake game can return another test’s cached flag rules when two lists have the same path and size. The interpreter’s comparison with the game’s own BoolExp answers also remains to be run.
Adds named BoolExp evaluation and enum reads for mods, backed by a list loaded from the player’s game. It also adds fake-game support, but its cache can make tests exercise stale rules.
Blocking (1): must change before merging.
game/crates/api/src/services/flag_exps.rs:99: The fake-game cache identifies a list only by path and byte length, although fake RomFS contents belong to each test thread and can be replaced with different bytes of the same length. (more on the line) Do: Keep the fake cache with the fake RomFS instance and invalidate it on replacement or reset, or key it by the list’s actual contents.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
game/crates/game-core/src/flag_exp.rs:8: The opcode meanings have not yet been compared with the answers the game gives during a flow. (more on the line) Do: Run the comparison mod during gameplay that asks BoolExp queries, covering the supported opcode families and both true and false results, and report the game’s answers against evaluate.@fixcan do L1.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven for BoolExp evaluation: the reported Windows run read enum names and returned plausible answers for three expressions, but no result was compared with a game flow’s answer. This is not a performance change.
Other systems: The loader runs at startup even without a mod using these functions, on Windows and Linux. The reported run covers Windows on NVIDIA; Linux and the comparison with live game queries remain untested. The fake RomFS is per-thread, while the new cache is process-wide.
Switches: None.
Reviewed:
e30c81d275against18edd5097e: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, the full diff, the new flag expression files, game-core watch code, host RomFS wrapper and zstd implementation, and fake-game content setup. Skimmed the remaining changed files and generated documentation; not every changed code file was read in full. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review).Checked and fine:
Testing: No commands that build, run tests, or execute project code were run. CI is still running; the author reports game-free tests and a Windows game run.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -0,0 +96,4 @@}let Some(path) = list_path() else { return Lookup::Missing };let Some(size) = host_sys::romfs::stat(&path) else { return Lookup::Missing };if let Some((p, s, t)) = KEPT.lock().unwrap_or_else(PoisonError::into_inner).as_ref()L1 (blocking): The fake-game cache identifies a list only by path and byte length, although fake RomFS contents belong to each test thread and can be replaced with different bytes of the same length.
When: Two tests, or two calls to setGameDataList, install different same-sized lists at GameDataList.Product.0.byml.zs. The second lookup reuses the first table, so enum names and expression results come from the wrong test or earlier list.
Do: Keep the fake cache with the fake RomFS instance and invalidate it on replacement or reset, or key it by the list’s actual contents.
@ -0,0 +5,4 @@//! callback, so it is tested without the game.//!//! **A rule** is postfix over a stack of yes/no: each entry an opcode and its operands (a flag's hash, then a value).//! Read off the table's shape and its named entries (2026-12, build e0f3ccfa):L2 (should fix): The opcode meanings have not yet been compared with the answers the game gives during a flow.
When: A mod relies on an expression using an inferred comparison or logical opcode; an incorrect interpretation would return a definite but wrong answer. The reported load encountered no BoolExp queries to compare.
Do: Run the comparison mod during gameplay that asks BoolExp queries, covering the supported opcode families and both true and false results, and report the game’s answers against evaluate.
Pushed
cd42f0f8f: a BoolExp's "after" (opcode 12) is strictly after. In a playtest, MiniGame_HitTarget_IsAfter_Ready_Exp was no in game at exactly Ready while evaluate said true; now it agrees, as every other live check did (yes and no). Docs that said "at or after" fixed. Testing updated with the played results.@rebase
I rebased this pull request onto
main(37f90245b0): the new head is4481223f81.Conflicts resolved
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.
cd42f0f8f64481223f81Recommendation: Request changes. The fake-game cache can return another test's rules or stale rules after a same-size replacement. The reported playtest addresses the earlier request to compare expression answers with the game.
Adds named BoolExp evaluation and enum reads for mods, with a background list load and fake-game support. It gives mods access to game checks at the cost of a retained decoded table and added interpreter code.
Blocking (1): must change before merging.
game/crates/api/src/services/flag_exps.rs:99: The fake-game cache identifies a list only by path and byte length, although fake RomFS contents belong to each test thread and can be replaced with different bytes of the same length. When: Two tests, or two calls to setGameDataList, install different same-sized lists at GameDataList.Product.0.byml.zs. The second lookup reuses the first table, so enum names and expression results come from the wrong test or earlier list. Do: Keep the fake cache with the fake RomFS instance and invalidate it on replacement or reset, or key it by the list’s actual contents.@fixcan do L1.Since the last review (on
e30c81d275)Resolved: L2 (The opcode meanings have not yet been compared with the answers the game gives during a fl…)
Still open: L1 (The fake-game cache identifies a list only by path and byte length, although fake RomFS co…)
Checks: they run again on this head; a failure shows on the pull request.
Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes for the demonstrated cases: the author reports matching the game's answers during play, including the strict-after boundary. This is not a performance change; the reported list decode takes about 11 ms and retains about 1.4 MB.
Other systems: The list loader and interpreter affect game mod calls and the fake game on Windows and Linux. Windows gameplay was reported; Linux tests and CI are still pending.
Switches: None.
Reviewed:
4481223f81against37f90245b0: Read the repository rules and pull request template, the ledger, comments and reported testing, and the flag expression loader and interpreter in full. The remaining changed files and dependent callers were not read in full; the large diff output was truncated.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run code were executed. The author reports Windows game and unit tests; Linux suite and CI have not yet run on this head.
Overlaps and merge order: Not checked; network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.
@fix
4481223f816500684d9fRecommendation: Approve. The fake-game cache now distinguishes list contents within each test thread, including equal-length replacements. The fix preserves the feature and its real-game loading path. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
6500684d9f. I rebased it ontomain(01f53fed8b).Changed
Nothing was built or run: the checks run again on the new head.
Mods can evaluate game flag rules and read enum names. The cache fix prevents fake games from receiving another list's decoded table, at the cost of reading and comparing the fake list on each lookup.
Checks: they run again on this head; a failure shows on the pull request.
More: does it help, other systems, switches, what was read
Does it help: Yes: the author reports in-game flag results matching the game's checks on Windows. The equal-length cache cases have new tests, though those tests have not been run on this head.
Other systems: The fix changes only the fake-game cache; the real game retains its background loader and shared table. Linux results are not reported.
Switches: None added or changed.
Reviewed:
6500684d9fagainst01f53fed8b: Read flag_exps.rs in full, the fix diff, the relevant fake RomFS storage and read paths, AGENTS.md and CONTRIBUTING.md. Inspected the game API and flag expression diffs; the remaining changed files and generated reference were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run tests were executed. CI has not run on this head; the author reports Windows game testing of the feature.
Overlaps and merge order: Not checked.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
WIP: feat(modapi): flags.evaluate, enumValue and enumValues: the game's BoolExp flags and enum values by nameto feat(modapi): flags.evaluate, enumValue and enumValues: the game's BoolExp flags and enum values by name