Skip to content

windows-boot: state-relative input presses (BOOT-INPUT-STATE-RELATIVE) - #1917

Open
BubsMcgee wants to merge 1 commit into
ProjectLeonida:mainfrom
BubsMcgee:boot-input-state
Open

BubsMcgee wants to merge 1 commit into
ProjectLeonida:mainfrom
BubsMcgee:boot-input-state

Conversation

@BubsMcgee

@BubsMcgee BubsMcgee commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: BOOT-INPUT-STATE-RELATIVE (#1608 (comment)). No dependencies; this is the harness side and reads keys through the keyboard pad (GetAsyncKeyState), so #1790's focus mode is orthogonal.

Fixes: #1900

What and why

-InputScript was absolute-time only (a@45,a@60,...). The title reaches the same states at different times from run to run, so the same script lands presses in different game states; in A/B runs an A at 75/90 s can advance in one build and back out to the menu (session d -> 0) in another, changing presents, PSO counts and the path being compared.

This adds button@game=<hex>+<delay> / button@session=<hex>+<delay>: the harness watches the existing LEONIDA_PEEK values (0x7446510 game, low dword of 0x98f828c session) and injects the key once that state has been seen for the delay. Absolute entries still go to the runtime unchanged.

Files

  • tools/boot_input_script.py: parse and due matcher (stdlib only).
  • scripts/windows-boot/boot.ps1: split the script, watch the log, inject through the keyboard pad (SendInput, LEONIDA_KEYBOARD_PAD=always; no focus needed), and read the log in the digest with a share that tolerates the redirect handle.
  • scripts/windows-boot/README.md and --help: the new form and an example.
  • tests/test_boot_input_script.py: synthetic parse/due cases.

Tested

  • python -I tests/test_boot_input_script.py: 12/12.
  • python -I scripts/check_no_game_data.py on the changed files: OK.
  • -DryRun with a@session=3+5,a@session=d+5: absolute='' state=2.
  • 200 s boot on RTX 3080 Ti / Windows 11 / NVIDIA 616.64 with a@session=3+5,a@session=d+5: the harness injected a at session=3 (55.8 s) and session=d (70.9 s); the keyboard pad logged press a@54.9/69.0/69.9; -DigestOnly reads states session=3 @55 s, session=d @70 s, and the known world-start device loss (lib_cs_03426...).

AI-assisted.

Absolute `button@seconds` entries still go to the runtime. `button@game=3+5` and
`button@session=d+5` are matched by the harness against LEONIDA_PEEK and injected as keys once the
state has been seen for the delay, so an A/B boot presses in the same game state when startup timing
shifts. The parser/state matcher is tools/boot_input_script.py (unit-tested); boot.ps1 watches the log,
injects through the keyboard pad (SendInput; LEONIDA_KEYBOARD_PAD=always, no focus needed), and now
reads the log with a share that tolerates the redirect handle.

Tested: 12/12 unit tests; dry run; 200 s boot on RTX 3080 Ti / Windows 11 / NVIDIA 616.64 with
-InputScript "a@session=3+5,a@session=d+5": the harness injected a at session=3 (55.8 s) and
session=d (70.9 s), the keyboard pad logged press a@54.9/69.0/69.9, and the run reached session d and
the known world-start device loss (lib_cs_03426...).

Claimed in the coordination issue as: BOOT-INPUT-STATE-RELATIVE.
AI-assisted.

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Independent Windows check at 34da84a13: the 12 Python tests pass. Synthetic state transitions and two PowerShell 5.1 dry runs reproduce the timing and plan-file issues below. No game process was launched and no system input was sent.

AI-assisted.

if ($null -eq $game -and $null -eq $session) { continue }
$now = ((Get-Date) - $watchStart).TotalSeconds
if ($null -ne $game -and $null -eq $seen.game) { $seen.game = $now }
if ($null -ne $session -and $null -eq $seen.session) { $seen.session = $now }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Start the delay when the observed value changes

The timer is set on the first report for the field and is never reset if its value changes. With a synthetic first report of session 0 at t=0 and the first d at t=10, the watcher code supplies seen-session=0 and button@session=d+5 is due immediately. It should first be eligible at t=15. Track the current value and its entry time for both fields, and add a transition case to the tests.

# for the delay. The parser/state matcher is tools/boot_input_script.py (unit-tested separately).
$absoluteScript = $InputScript
$statePlan = @()
$InputPlanFile = Join-Path ([System.IO.Path]::GetTempPath()) ("leonida-input-plan-" + $Name + ".json")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Keep the input plan local to the run

This path is keyed only by -Name and is written before the -DryRun exit and before the run lock. Two dry runs using different output directories and the same name created and then replaced the same temporary plan. The second run can also replace a live run's plan, since the watcher opens it on each poll. Keep the plan in memory or use a unique per-run file written after validation and dry-run handling.

input[0].type = 1; // INPUT_KEYBOARD
input[0].ki.wVk = vk;
input[0].ki.dwFlags = down ? 0u : 2u; // KEYEVENTF_KEYUP
SendInput(1, input, Marshal.SizeOf(typeof(INPUT)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Keep unattended input out of the system keyboard stream

SendInput enters the system keyboard stream. LEONIDA_KEYBOARD_PAD=always lets the game observe it in the background, and the foreground app can still receive the synthesized Enter, Backspace or Escape. This makes unattended runs affect other apps. Route scripted presses through the runtime's virtual pad. Win32 SendInput docs.

@MoonEyes

Copy link
Copy Markdown
Collaborator

Hi @BubsMcgee, thanks for this pull request. It currently conflicts with main (conflicting file(s): scripts/windows-boot/boot.ps1), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

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)

3 participants