From f0e79141a41b63e737560fbd4a051e3ab34dad7d Mon Sep 17 00:00:00 2001 From: klikso <204526810+klikso@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:32:55 +0000 Subject: gameinput: a scripted press can be held longer (button@seconds:hold) At world-start frame rates the retail title reads its pad every few seconds, so a 0.3 s scripted press falls between two reads and never arrives. An entry may now give its own hold time; without one the press stays 0.3 s. Holds of 0 or less, over 600 s or that are not a number reject the entry. Co-Authored-By: Claude Opus 5.5 --- runtime/test/gameinput_test.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'runtime/test/gameinput_test.cpp') diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index be9dc5398..42a59e764 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -1718,10 +1718,12 @@ int main(int argc, char** argv) { check(create(&input) == S_OK && input, "GameInputCreate returns an instance"); if (argc == 2 && std::strcmp(argv[1], "--input-script") == 0) { if (!input) return 1; - // Only the X after byte 63 is due now. Its later entry must not cancel it. + // Only the X after byte 63 and the Y held 0.6 s are due now. X's later entry must not cancel it; the + // malformed holds at the end hold nothing. set_env("LEONIDA_INPUT_SCRIPT", "start@3600,start@3600,start@3600,start@3600,start@3600,start@3600, X@0 \t,x@3600," - "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,"); + "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,y@0:0.6," + "a@0:0,a@0:-1,a@0:,a@0:x,a@0:inf,a@0:601,a@0:1tail"); set_env("LEONIDA_KEYBOARD_PAD", "1"); rt::gameinput::set_keyboard_source(fake_key_down, fake_focus); rt::gameinput::set_cursor_source(fake_cursor); @@ -1730,27 +1732,24 @@ int main(int argc, char** argv) { rt::gameinput::reload_config(); rt::gameinput::poll(); const auto buttons = pad_state(input, nullptr).buttons; - const auto expected = GameInputGamepadX | GameInputGamepadB; - check((buttons & expected) == expected, "long script: the spaced X after byte 63 and the physical B are held"); + const auto expected = GameInputGamepadX | GameInputGamepadB | GameInputGamepadY; + check((buttons & expected) == expected, + "long script: the spaced X after byte 63, the held Y and the physical B are held"); check((buttons & ~expected) == 0, "malformed script entries hold no extra buttons"); g_focus = false; set_env("LEONIDA_INPUT_SCRIPT", "y@0"); rt::gameinput::reload_config(); rt::gameinput::poll(); - check(pad_state(input, nullptr).buttons == GameInputGamepadX, - "scripted X survives focus loss; reload does not replace it with Y"); + check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadY), + "scripted X and Y survive focus loss; reload does not replace the script with y@0"); Sleep(350); g_focus = true; rt::gameinput::poll(); - // A scripted press lasts its 300 ms and then until the title has read the pads six times since it began - // (update_keyboard_pad: kReads, at most kMaxHold seconds), so a title that polls slowly still sees it. Each - // pad_state() is one GetCurrentReading, and this is the third since the X began. - check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadB), - "long script: past its 300 ms the press is still held while the title has read the pads fewer than six times"); - for (int i = 0; i < 6; ++i) pad_state(input, nullptr); + check(pad_state(input, nullptr).buttons == (GameInputGamepadB | GameInputGamepadY), + "long script: X's 0.3 s press ends, y@0:0.6 is still held, the physical key stays held"); + Sleep(400); rt::gameinput::poll(); - check(pad_state(input, nullptr).buttons == GameInputGamepadB, - "long script: the timed press ends once the title has read it, while the physical key stays held"); + check(pad_state(input, nullptr).buttons == GameInputGamepadB, "long script: Y is released after its 0.6 s hold"); input->Release(); std::printf("%d checks, %d failures\n", g_checks, g_failures); return g_failures ? 1 : 0; -- cgit v1.2.3 From 1ce60558c72770e881a4ef458e125f587b66022e Mon Sep 17 00:00:00 2001 From: klikso <204526810+klikso@users.noreply.github.com> Date: Thu, 26 Nov 2026 01:00:51 +0000 Subject: gameinput: the SDL keyboard pad honours a scripted hold too #2098 gave the SDL path its own loop (held 300 ms, then until the title has read the pads six times, at most 5 s), which ignored button@seconds:hold. A press now lasts its own hold, then the read latch, and never past 5 s or its hold if longer. The long-script test checks both: X kept past 300 ms until six reads, Y kept for its 0.6 s after them. It fails on the old loop. Found by AndreiKocherzhinskiiA on #1608. Co-Authored-By: Claude Opus 5.5 --- docs/gameinput.md | 2 +- runtime/README.md | 2 +- runtime/shims/gameinput.cpp | 8 +++++--- runtime/test/gameinput_test.cpp | 12 ++++++++++-- 4 files changed, 17 insertions(+), 7 deletions(-) (limited to 'runtime/test/gameinput_test.cpp') diff --git a/docs/gameinput.md b/docs/gameinput.md index 9b263a7aa..6f39b459e 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md @@ -336,7 +336,7 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | -| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. | +| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). With SDL3 a press then stays down until the title has read the pads six times since it began, but never past 5 s from its start (or its hold, if longer). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to diff --git a/runtime/README.md b/runtime/README.md index 23a7811ab..033997c1a 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -353,7 +353,7 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w | `LEONIDA_POOL_DIAG_AT` | unset | *Diagnostic.* `+0x` of the title's transient-pool assert, as the trace prints it (measured locally): the trace dumps the pool's resource list when that int3 is hit (`shims/startup_trace.h`). | | `LEONIDA_PEEK` | unset | *Diagnostic.* `[:n],,...` (hex): a thread prints the 8-byte values at these RVAs of the title's image (`:n` = n consecutive values) every `LEONIDA_PEEK_SECONDS` (`src/main.cpp`). The RVAs are measured locally and not kept in the repository. `scripts/windows-boot/boot.ps1` no longer sets the game-state and session-state RVAs by default: it sets `LEONIDA_PEEK` only from `LEONIDA_GAME_STATE_RVA` and `LEONIDA_SESSION_STATE_RVA`, and without them its RESULT states read `?` ([scripts/windows-boot/README.md](../scripts/windows-boot/README.md)). | | `LEONIDA_PEEK_SECONDS` | `10` | *Diagnostic.* The period of the `LEONIDA_PEEK` thread (`src/main.cpp`), which prints 8-byte values of the title's image. | -| `LEONIDA_INPUT_SCRIPT` | unset | Timed pad presses, `button@seconds` separated by commas (`a@70,a@85,start@120`), each held 300 ms; the clock starts with the shim. Works with and without SDL3: with SDL3 it drives the keyboard pad (`LEONIDA_KEYBOARD_PAD=always`), without SDL3 one scripted pad that is the only device. Controllers and the keyboard pad still need SDL3. Format and buttons in [docs/gameinput.md](../docs/gameinput.md#environment-variables). | +| `LEONIDA_INPUT_SCRIPT` | unset | Timed pad presses, `button@seconds` separated by commas (`a@70,a@85,start@120`), each held 300 ms or its own `button@seconds:hold`; the clock starts with the shim. Works with and without SDL3: with SDL3 it drives the keyboard pad (`LEONIDA_KEYBOARD_PAD=always`), without SDL3 one scripted pad that is the only device. Controllers and the keyboard pad still need SDL3. Format and buttons in [docs/gameinput.md](../docs/gameinput.md#environment-variables). | | `LEONIDA_INPUT_LOG` | on | The GameInput shim logs every press in `LEONIDA_INPUT_SCRIPT`'s form (`name@seconds`), so a session played by hand can be replayed. `0` turns the lines off. | | `LEONIDA_LOG_ALLOCINFO` | unset | *Diagnostic.* `1` logs every device slot 25 call (`GetResourceAllocationInfo`) with its thread, description and sizes (`shims/d3d12_xs_device.cpp`). | | `LEONIDA_LOG_EXE_PIPELINES` | unset | *Diagnostic.* When set, one line per distinct graphics pipeline that uses a program translated from the executable's inline containers. | diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index fa5889d6a..3a66fd2fa 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp @@ -1887,7 +1887,9 @@ void update_keyboard_pad() { clip_cursor(active && g_raw_ready && g_cursor_pos.load() == system_cursor_pos && foreground_is_ours()); for (const auto& b : kKeyBindings) SDL_SetJoystickVirtualButton(g_keyboard.js, b.sdl_button, down[b.sdl_button]); // LEONIDA_INPUT_SCRIPT="a@70,a@85,start@120" (with LEONIDA_KEYBOARD_PAD=always): timed presses on the keyboard - // pad, in seconds since the pad's first update, each held 300 ms. For unattended boots: the title's first prompt + // pad, in seconds since the pad's first update, each held 300 ms or its own button@seconds:hold, and then until the + // title has read the pads kReads times since it began (never past kMaxHold seconds, or the hold if it is longer, so + // a title that stops reading does not keep the button). For unattended boots: the title's first prompt // waits for a button with no timeout (docs/re/notes/firstframe.md, step 5). The parser, the timeline and the // button names are gameinput_script.h's, shared with the scripted pad of a build without SDL3. namespace script = rt::gameinput::script; @@ -1911,12 +1913,12 @@ void update_keyboard_pad() { for (std::size_t i = 0; i < scripted.presses.size(); ++i) { const auto& press = scripted.presses[i]; bool active = false; - if (now >= press.at && now < press.at + kMaxHold) { + if (now >= press.at && now < press.at + std::max(press.hold, kMaxHold)) { if (!started[i]) { started[i] = 1; began[i] = calls; } - active = now < press.at + 0.3 || calls - began[i] < kReads; + active = now < press.at + press.hold || calls - began[i] < kReads; } if (!active) continue; if (press.stick) held.stick = press.stick; diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index 42a59e764..09d959f34 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -1745,11 +1745,19 @@ int main(int argc, char** argv) { Sleep(350); g_focus = true; rt::gameinput::poll(); + // A scripted press lasts its hold (300 ms, or button@seconds:hold) and then until the title has read the pads + // six times since it began (update_keyboard_pad: kReads), so a title that polls slowly still sees it. Each + // pad_state() is one GetCurrentReading, and this is the third since X and Y began. + check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadB | GameInputGamepadY), + "long script: past its 300 ms X is still held while the title has read the pads fewer than six times"); + for (int i = 0; i < 6; ++i) pad_state(input, nullptr); + rt::gameinput::poll(); check(pad_state(input, nullptr).buttons == (GameInputGamepadB | GameInputGamepadY), - "long script: X's 0.3 s press ends, y@0:0.6 is still held, the physical key stays held"); + "long script: X ends once the title has read it, y@0:0.6 is still held for its time, the key stays held"); Sleep(400); rt::gameinput::poll(); - check(pad_state(input, nullptr).buttons == GameInputGamepadB, "long script: Y is released after its 0.6 s hold"); + check(pad_state(input, nullptr).buttons == GameInputGamepadB, + "long script: Y is released after its 0.6 s hold, the title having read it six times"); input->Release(); std::printf("%d checks, %d failures\n", g_checks, g_failures); return g_failures ? 1 : 0; -- cgit v1.2.3