gameinput: support state-relative scripted presses #2749

Closed
j-weiner wants to merge 1 commit from upstream-pr/2749 into main
j-weiner commented 2026-11-30 15:25:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by j-weiner on 2026-11-30T15:25:07Z.


Claimed in the coordination issue as: BOOT-INPUT-STATE-RELATIVE — https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7282361011

Fixes: #1900

What and why

Add opt-in state-relative scripted GameInput presses (button@game=<hex>+seconds and button@session=<hex>+seconds) while preserving the existing button@seconds format. The runtime samples the locally configured game/session state RVAs once per second; a relative press is scheduled from the observation of its matching state. No RVAs or game-derived state data are stored in the repository.

Tested

  • Configured with cmake -S runtime -B runtime/build -DLEONIDA_SDL3=OFF.
  • Built gta6rt and gameinput_no_sdl_test with Visual Studio 2022 BuildTools / MSVC 19.44 and Windows SDK 10.0.26100.0. Build succeeded; existing warnings remain in unrelated files.
  • ctest --test-dir runtime/build -C RelWithDebInfo -R '^gameinput_no_sdl(_script)?$' --output-on-failure — 2/2 passed. Synthetic tests cover both state anchors and a press missed by sparse title reads.
  • tests/test_text_write_line_endings.py (Python 3.13) — 3 passed.
  • scripts/check_no_game_data.py on changed files and git diff --check — passed.
  • No game launch or GPU tests; this is a CPU-only synthetic runtime test.

GPUs tested: n/a (no GPU tests run; Windows 11 Pro 10.0.26200)

AI-assisted: yes (OpenCode, GPT-6 Luna)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption.
  • Not a translator rule.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5568223534 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2749). Originally posted by [j-weiner](https://github.com/j-weiner) on 2026-11-30T15:25:07Z. --- Claimed in the coordination issue as: BOOT-INPUT-STATE-RELATIVE — https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7282361011 Fixes: #1900 ### What and why Add opt-in state-relative scripted GameInput presses (`button@game=<hex>+seconds` and `button@session=<hex>+seconds`) while preserving the existing `button@seconds` format. The runtime samples the locally configured game/session state RVAs once per second; a relative press is scheduled from the observation of its matching state. No RVAs or game-derived state data are stored in the repository. ### Tested - Configured with `cmake -S runtime -B runtime/build -DLEONIDA_SDL3=OFF`. - Built `gta6rt` and `gameinput_no_sdl_test` with Visual Studio 2022 BuildTools / MSVC 19.44 and Windows SDK 10.0.26100.0. Build succeeded; existing warnings remain in unrelated files. - `ctest --test-dir runtime/build -C RelWithDebInfo -R '^gameinput_no_sdl(_script)?$' --output-on-failure` — 2/2 passed. Synthetic tests cover both state anchors and a press missed by sparse title reads. - `tests/test_text_write_line_endings.py` (Python 3.13) — 3 passed. - `scripts/check_no_game_data.py` on changed files and `git diff --check` — passed. - No game launch or GPU tests; this is a CPU-only synthetic runtime test. GPUs tested: n/a (no GPU tests run; Windows 11 Pro 10.0.26200) AI-assisted: yes (OpenCode, GPT-6 Luna) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption. - [x] Not a translator rule.
Kal0s-design commented 2026-11-30 17:15:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-11-30T17:15:46Z.


Independent Windows check under AddressSanitizer of 48e8c5216 on current main 1d4949d58 (no conflict, tree 6a9e3a1c7). MSVC 19.50 x64. gameinput_no_sdl_test was built from its CMake target's sources (test/gameinput_no_sdl_test.cpp, shims/gameinput_no_sdl.cpp, shims/registry.cpp, /W4 /permissive- /utf-8) with /Od /MDd /fsanitize=address, so checked iterators are on too.

  • Both ctest entries run directly: gameinput_no_sdl_test and gameinput_no_sdl_test --input-script each end with 0 failure(s), exit 0, no ASan report, 0 warnings at /W4.
  • No red run is possible: the test calls rt::gameinput::update_title_state, which this PR adds, so against main's shim it doesn't compile (C2039/C3861).

No title run, so the state RVAs and real game/session transitions aren't covered.

GPUs tested: n/a (CPU unit test). AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7285981779 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2749#issuecomment-7285981779). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-11-30T17:15:46Z. --- **Independent Windows check under AddressSanitizer** of `48e8c5216` on current `main` `1d4949d58` (no conflict, tree `6a9e3a1c7`). MSVC 19.50 x64. `gameinput_no_sdl_test` was built from its CMake target's sources (`test/gameinput_no_sdl_test.cpp`, `shims/gameinput_no_sdl.cpp`, `shims/registry.cpp`, `/W4 /permissive- /utf-8`) with `/Od /MDd /fsanitize=address`, so checked iterators are on too. - Both ctest entries run directly: `gameinput_no_sdl_test` and `gameinput_no_sdl_test --input-script` each end with `0 failure(s)`, exit 0, no ASan report, 0 warnings at `/W4`. - No red run is possible: the test calls `rt::gameinput::update_title_state`, which this PR adds, so against `main`'s shim it doesn't compile (C2039/C3861). No title run, so the state RVAs and real game/session transitions aren't covered. GPUs tested: n/a (CPU unit test). AI-assisted: yes.
aslan2142 commented 2026-12-01 11:52:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:52:57Z.

Review: CHANGES_REQUESTED


Keeping #2749 over closed competing variant #1917 (BOOT-INPUT-STATE-RELATIVE, #1900): implementing state-relative presses natively in GameInput using locally supplied LEONIDA_GAME_STATE_RVA / LEONIDA_SESSION_STATE_RVA is clean-room compliant and avoids #1917's hardcoded game RVAs and PowerShell SendInput races.

However, requesting changes before merge for two bugs spotted in the diff:

  1. runtime/shims/gameinput.cpp (update_keyboard_pad): After moving the now >= *due + std::max(press.hold, kMaxHold) check inside if (!started[i]), once started[i] becomes 1, the line const bool active = now < scheduled[i] + press.hold || calls - began[i] < kReads; no longer enforces the std::max(press.hold, kMaxHold) upper cap. If the title stops polling pads (calls - began[i] < kReads), a started press stays held indefinitely past 5 s, contradicting docs/gameinput.md. Please restore now < scheduled[i] + std::max(press.hold, kMaxHold) && (...).
  2. runtime/src/main.cpp (start_title_peek): Setting if (have_title_state) period = 1; unconditionally overrides LEONIDA_PEEK_SECONDS for [rt] peek stderr logging as well, printing peek lines every 1 s (5–10× faster than configured). Please keep sampling title state every 1 s while only printing [rt] peek when tick % peek_period == 0 (respecting LEONIDA_PEEK_SECONDS).

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130711656 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2749#pullrequestreview-6130711656). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:52:57Z. **Review:** CHANGES_REQUESTED --- Keeping **#2749** over closed competing variant **#1917** (`BOOT-INPUT-STATE-RELATIVE`, `#1900`): implementing state-relative presses natively in `GameInput` using locally supplied `LEONIDA_GAME_STATE_RVA` / `LEONIDA_SESSION_STATE_RVA` is clean-room compliant and avoids `#1917`'s hardcoded game RVAs and PowerShell `SendInput` races. However, **requesting changes before merge** for two bugs spotted in the diff: 1. **`runtime/shims/gameinput.cpp` (`update_keyboard_pad`)**: After moving the `now >= *due + std::max(press.hold, kMaxHold)` check inside `if (!started[i])`, once `started[i]` becomes `1`, the line `const bool active = now < scheduled[i] + press.hold || calls - began[i] < kReads;` no longer enforces the `std::max(press.hold, kMaxHold)` upper cap. If the title stops polling pads (`calls - began[i] < kReads`), a started press stays held indefinitely past 5 s, contradicting `docs/gameinput.md`. Please restore `now < scheduled[i] + std::max(press.hold, kMaxHold) && (...)`. 2. **`runtime/src/main.cpp` (`start_title_peek`)**: Setting `if (have_title_state) period = 1;` unconditionally overrides `LEONIDA_PEEK_SECONDS` for `[rt] peek` stderr logging as well, printing peek lines every 1 s (5–10× faster than configured). Please keep sampling title state every 1 s while only printing `[rt] peek` when `tick % peek_period == 0` (respecting `LEONIDA_PEEK_SECONDS`). *(AI-assisted review.)*
KelboLive commented 2026-12-01 16:02:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T16:02:22Z.

Review: COMMENTED


Two blockers, both matching aslan2142's review — and I built the SDL path the PR's own test command never compiles (-DLEONIDA_SDL3=OFF), which is where the first one lives.

  1. The 5 s cap is lost once a press starts (runtime/shims/gameinput.cpp:2044 vs :2049). The cap only gates the !started[i] branch; afterwards active = now < scheduled + hold || calls - began < kReads, with no wall-clock bound. Reproduced with a temporary probe case: y@0:0.3 with two reads is still held at 6 s, and with no further reads it stays down indefinitely. docs/gameinput.md:537 promises "never past 5 s". The LEONIDA_INPUT_FILE loop still enforces the cap at :2032 — the scripted loop should keep the same outer check after started[i].
  2. The peek period is overridden (runtime/src/main.cpp:143). period = 1 also drives the print (:188) and the Sleep (:203), so when both RVAs are set LEONIDA_PEEK_SECONDS is ignored; boot.ps1 sets PEEK_SECONDS=5 together with the RVAs by default, so peek output is 5× as frequent and the t= labels advance in 1 s. runtime/README.md:405 still says "every LEONIDA_PEEK_SECONDS". Sample at 1 s, print every configured period.

Everything else checks out: the RVA sampling and since/start_at/update() chain is exactly as described (the tests pin 62.0/62.6 s and 67.0/67.6 s), the anchor-identity guard is covered (forcing if (false && …) gives 5 failures), gameinput_no_sdl_test and the SDL gameinput_test both pass here (0 and 400 checks), gta6rt builds, the docs tests are 37 + 39 green, and merge-tree is clean with none of the four changed files touched on main since the merge base.

Minor: the SDL build adds a C4456 tick shadow at gameinput.cpp:2007, and no SDL test covers relative anchors (the shared parser is covered by the no-SDL test). Also the two state RVAs (LEONIDA_GAME_STATE_RVA, LEONIDA_SESSION_STATE_RVA) are missing from runtime/README.md's table, and the parser accepts 64-bit hex while main.cpp:199 truncates to u32, so a longer value silently never matches.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6135005287 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2749#pullrequestreview-6135005287). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T16:02:22Z. **Review:** COMMENTED --- Two blockers, both matching aslan2142's review — and I built the SDL path the PR's own test command never compiles (`-DLEONIDA_SDL3=OFF`), which is where the first one lives. 1. **The 5 s cap is lost once a press starts** (`runtime/shims/gameinput.cpp:2044` vs `:2049`). The cap only gates the `!started[i]` branch; afterwards `active = now < scheduled + hold || calls - began < kReads`, with no wall-clock bound. Reproduced with a temporary probe case: `y@0:0.3` with two reads is **still held at 6 s**, and with no further reads it stays down indefinitely. `docs/gameinput.md:537` promises "never past 5 s". The `LEONIDA_INPUT_FILE` loop still enforces the cap at `:2032` — the scripted loop should keep the same outer check after `started[i]`. 2. **The peek period is overridden** (`runtime/src/main.cpp:143`). `period = 1` also drives the print (`:188`) and the `Sleep` (`:203`), so when both RVAs are set `LEONIDA_PEEK_SECONDS` is ignored; `boot.ps1` sets `PEEK_SECONDS=5` together with the RVAs by default, so peek output is 5× as frequent and the `t=` labels advance in 1 s. `runtime/README.md:405` still says "every `LEONIDA_PEEK_SECONDS`". Sample at 1 s, print every configured period. Everything else checks out: the RVA sampling and `since`/`start_at`/`update()` chain is exactly as described (the tests pin 62.0/62.6 s and 67.0/67.6 s), the anchor-identity guard is covered (forcing `if (false && …)` gives 5 failures), `gameinput_no_sdl_test` and the SDL `gameinput_test` both pass here (0 and 400 checks), `gta6rt` builds, the docs tests are 37 + 39 green, and `merge-tree` is clean with none of the four changed files touched on main since the merge base. Minor: the SDL build adds a C4456 `tick` shadow at `gameinput.cpp:2007`, and no SDL test covers relative anchors (the shared parser is covered by the no-SDL test). Also the two state RVAs (`LEONIDA_GAME_STATE_RVA`, `LEONIDA_SESSION_STATE_RVA`) are missing from `runtime/README.md`'s table, and the parser accepts 64-bit hex while `main.cpp:199` truncates to u32, so a longer value silently never matches.
aslan2142 commented 2026-12-01 17:26:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:26:32Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7319304338 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2749#issuecomment-7319304338). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:26:32Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2749
No description provided.