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 --- runtime/shims/gameinput.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'runtime/shims/gameinput.cpp') 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; -- cgit v1.2.3 From acd9f98c1f751fda83df958c869bc91e2770fccc Mon Sep 17 00:00:00 2001 From: Jan Trencansky Date: Thu, 26 Nov 2026 00:34:26 -0500 Subject: gameinput: LEONIDA_INPUT_FILE presses buttons named in a file while the title runs A local tool for headless runs, whose private display passes no keyboard input to Wine: every line appended to the file names one button of the script's table and becomes a press at once, held like a scripted press (300 ms and six readings, at most 5 s), so a run can be driven step by step from the shell while its screenshots are read. The file is read again at most every 250 ms. Off by default. Co-Authored-By: Claude Opus 5.5 --- runtime/shims/gameinput.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'runtime/shims/gameinput.cpp') diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index fa5889d6a..454923457 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp @@ -1899,7 +1899,21 @@ void update_keyboard_pad() { s.presses.size(), s.rejected); return s; }(); - if (!scripted.empty()) { + // LEONIDA_INPUT_FILE= (local, for headless runs whose display takes no keyboard input): every line appended + // to the file names one button of gameinput_script.h's table ("a", "down", ...) and becomes a press at once, held + // like a scripted one (300 ms and six readings, at most 5 s). The file is read again at most every 250 ms. + struct FilePress { + uint32_t bit; + double at; + uint64_t began; + bool started; + }; + static std::vector file_presses; + static const std::string input_file = [] { + const char* v = std::getenv("LEONIDA_INPUT_FILE"); + return std::string(v ? v : ""); + }(); + if (!scripted.empty() || !input_file.empty()) { static const ULONGLONG origin = GetTickCount64(); const double now = (GetTickCount64() - origin) / 1000.0; script::Held held{}; @@ -1908,6 +1922,42 @@ void update_keyboard_pad() { static std::vector began(scripted.presses.size(), 0); static std::vector started(scripted.presses.size(), 0); const uint64_t calls = g_reading_calls.load(std::memory_order_relaxed); + if (!input_file.empty()) { + static ULONGLONG last_read = 0; + static std::size_t lines_done = 0; + const ULONGLONG tick = GetTickCount64(); + if (tick - last_read >= 250) { + last_read = tick; + if (FILE* f = std::fopen(input_file.c_str(), "r")) { + char line[64]; + std::size_t n = 0; + while (std::fgets(line, sizeof(line), f)) { + if (++n <= lines_done) continue; + lines_done = n; + std::string name(line); + while (!name.empty() && (name.back() == '\n' || name.back() == '\r' || name.back() == ' ')) + name.pop_back(); + bool known = false; + for (const script::Button& b : script::kButtons) + if (name == b.name) { + file_presses.push_back({b.bit, now, 0, false}); + known = true; + } + std::fprintf(stderr, "[rt] gameinput: input file line %zu \"%s\" at %.1f s%s\n", n, + name.c_str(), now, known ? "" : " (unknown button, ignored)"); + } + std::fclose(f); + } + } + for (auto& p : file_presses) { + if (now < p.at || now >= p.at + kMaxHold) continue; + if (!p.started) { + p.started = true; + p.began = calls; + } + if (now < p.at + 0.3 || calls - p.began < kReads) held.buttons |= p.bit; + } + } for (std::size_t i = 0; i < scripted.presses.size(); ++i) { const auto& press = scripted.presses[i]; bool active = false; @@ -1924,7 +1974,7 @@ void update_keyboard_pad() { } if (held.stick) right_y = held.stick > 0 ? -kStickFull : kStickFull; // SDL's +Y is down for (const script::Button& b : script::kButtons) { - if (!(scripted.named & b.bit)) continue; + if (!(scripted.named & b.bit) && input_file.empty()) continue; const auto button = static_cast(b.sdl); SDL_SetJoystickVirtualButton(g_keyboard.js, button, (held.buttons & b.bit) || down[button]); } -- cgit v1.2.3 From ee470192461a2911aa204cfecf9fdccb265a8b5f Mon Sep 17 00:00:00 2001 From: ZroFreaks <42916282+ZroIsHere@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:49:58 +0100 Subject: Improve first-run input diagnostics --- runtime/shims/gameinput.cpp | 15 ++++++++++----- runtime/shims/gameinput_no_sdl.cpp | 2 +- scripts/windows-boot/boot.ps1 | 7 ++++++- 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'runtime/shims/gameinput.cpp') diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index 5abb2a2fe..c989daff4 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp @@ -2495,13 +2495,13 @@ public: struct Stats { std::mutex mu; uint64_t calls[3][3] = {}; // method x (null, aggregate, a device) - uint64_t found[3] = {}, pressed[3] = {}; + uint64_t found[3] = {}, pressed[3] = {}, a_pressed[3] = {}; std::map> by_device; // name -> (readings, with buttons) uint64_t since = 0; }; static Stats st; std::string name; - bool buttons = false; + bool buttons = false, a_button = false; if (SUCCEEDED(hr) && got) { IGameInputDevice* d = nullptr; got->GetDevice(&d); @@ -2510,7 +2510,10 @@ public: d->Release(); } GameInputGamepadState g{}; - if (got->GetGamepadState(&g)) buttons = g.buttons != 0; + if (got->GetGamepadState(&g)) { + buttons = g.buttons != 0; + a_button = (g.buttons & GameInputGamepadA) != 0; + } } const int arg = !asked ? 0 : as_device(asked)->info.deviceFamily == GameInputFamilyAggregate ? 1 : 2; std::lock_guard lock(st.mu); @@ -2518,6 +2521,7 @@ public: if (SUCCEEDED(hr) && got) { ++st.found[method]; st.pressed[method] += buttons; + st.a_pressed[method] += a_button; auto& e = st.by_device[name]; ++e.first; e.second += buttons; @@ -2529,10 +2533,10 @@ public: std::string line; for (int m = 0; m < 3; ++m) { char t[200]; - std::snprintf(t, sizeof(t), " %s %llu/%llu/%llu found %llu pressed %llu;", methods[m], + std::snprintf(t, sizeof(t), " %s %llu/%llu/%llu found %llu pressed %llu A %llu;", methods[m], (unsigned long long)st.calls[m][0], (unsigned long long)st.calls[m][1], (unsigned long long)st.calls[m][2], (unsigned long long)st.found[m], - (unsigned long long)st.pressed[m]); + (unsigned long long)st.pressed[m], (unsigned long long)st.a_pressed[m]); line += t; } for (const auto& [n, c] : st.by_device) { @@ -2545,6 +2549,7 @@ public: std::memset(st.calls, 0, sizeof(st.calls)); std::memset(st.found, 0, sizeof(st.found)); std::memset(st.pressed, 0, sizeof(st.pressed)); + std::memset(st.a_pressed, 0, sizeof(st.a_pressed)); st.by_device.clear(); st.since = now; } diff --git a/runtime/shims/gameinput_no_sdl.cpp b/runtime/shims/gameinput_no_sdl.cpp index 04a29fc6c..43f7b6b20 100644 --- a/runtime/shims/gameinput_no_sdl.cpp +++ b/runtime/shims/gameinput_no_sdl.cpp @@ -435,7 +435,7 @@ void update(uint64_t now) { void trace_reading(State& s, const char* api, uint32_t kind, const Reading* reading) { const uint64_t query = ++s.reading_queries; const uint32_t buttons = reading ? reading->state().buttons : 0; - if (s.trace_reads && (query == 1 || buttons || query % 1000 == 0)) + if (s.trace_reads && (query <= 128 || buttons || query % 1000 == 0)) std::fprintf(stderr, "[rt] gameinput: %s #%llu kind=0x%08x seq=%llu buttons=0x%08x\n", api, static_cast(query), kind, static_cast(reading ? reading->seq() : 0), buttons); diff --git a/scripts/windows-boot/boot.ps1 b/scripts/windows-boot/boot.ps1 index 4a80dedfd..db11e4e76 100644 --- a/scripts/windows-boot/boot.ps1 +++ b/scripts/windows-boot/boot.ps1 @@ -76,6 +76,9 @@ .PARAMETER ExtraArgs More gta6rt arguments, appended after the standard ones. +.PARAMETER FirstRunUi + Launch with the offline first-run UI profile instead of the generic runtime profile. + .PARAMETER Python Python 3.12+ used for tools/boot_trace.py. Default: python, else py -3. @@ -119,6 +122,7 @@ param( [switch]$NoCapture, [switch]$NoInput, [string[]]$ExtraArgs = @(), + [switch]$FirstRunUi, [string]$Python = "", [int]$SummaryLines = 40, [int]$LockWaitSeconds = 3600, @@ -278,7 +282,8 @@ foreach ($pair in $EnvPairs) { } if ($bootEnv["LEONIDA_CAPTURE"]) { $Capture = $bootEnv["LEONIDA_CAPTURE"] } -$gameArgs = @("--run", $Exe, "--game-dir", $GameDir, "--overlay", $Overlay, "--trace", $TraceFile, "--trace-d3d12") + $ExtraArgs +$launchMode = if ($FirstRunUi) { "--first-run-ui" } else { "--run" } +$gameArgs = @($launchMode, $Exe, "--game-dir", $GameDir, "--overlay", $Overlay, "--trace", $TraceFile, "--trace-d3d12") + $ExtraArgs $argLine = ($gameArgs | ForEach-Object { ConvertTo-ProcessArgument ([string]$_) }) -join " " if (-not $DigestOnly) { -- cgit v1.2.3