Skip to content

gameinput: support state-relative scripted presses - #2749

Closed
j-weiner wants to merge 1 commit into
ProjectLeonida:mainfrom
j-weiner:fix/boot-input-state-relative
Closed

j-weiner wants to merge 1 commit into
ProjectLeonida:mainfrom
j-weiner:fix/boot-input-state-relative

Conversation

@j-weiner

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: BOOT-INPUT-STATE-RELATIVE — #2570 (comment)

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.

@Kal0s-design

Copy link
Copy Markdown
Contributor

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 aslan2142 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

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.

@aslan2142 aslan2142 closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

windows-boot: input scripts are absolute-time, so a press lands in a different game state across runs (BOOT-INPUT-STATE-RELATIVE)

4 participants