Key bindings: three small safeguards from #1365 (focus loss, failed save, default file) #2245

Manually merged
github merged 3 commits from github-bot/gh-2245 into main 2026-11-30 14:17:30 +00:00 AGit
Owner

@⁠hussainmussa on GitHub · 2026-11-29 11:00 UTC · original
hussainmussa:fix/1365-binding-safeguards → main · +153 −14 · 3 files · 3 commits · merged 2026-11-30 14:12 UTC

Part of #1365: the three small input safeguards listed there. The ideas are @⁠ItsYungFlexer's, from that issue; the third is done the way their fork does it (create_new). Three commits, each independent, so any one can be taken alone. The HUD prompts in #1365 are not touched.

What it changes

  1. A wait for a key ends when the game window is not in front (menu.rs). F1's KEY BINDINGS waits for the key with GetAsyncKeyState, which sees keys in every program. After Enter on a line, a click on another window or a key typed there was saved to bindings.ini, and the wait stayed on while the player was away. Now the wait ends before any key is read, the line keeps its key, and the note says NOT CHANGED: THE GAME WINDOW WAS NOT IN FRONT. Not covered: Alt+Tab itself still binds Alt, because Alt goes down while the game is still in front.
  2. The list shows a key only once bindings.ini took it (menu.rs). Binds::set changed the shown text, then wrote the file. After a failed write the line showed the new key while the game used the old one, and the next line that did save wrote the failed key too. Now the text is written first and kept only if the write worked.
  3. The default bindings.ini is never written over one that is there (play.rs, scripts/play-foxhound.ps1). Both launchers did "is it there? if not, write", and the write empties whatever is at that path. Both now create the file in one step that fails if it exists. This is a small window, not an everyday bug; the test pins the rule.

How it was tested

  • GPU and profile: RTX 4070 12 GB, Core Ultra 7 265KF, Windows 11. Unit tests only; not run in the game yet.
  • cargo test -p victory-gpu --lib host::menu -- --test-threads=1: 16 passed, with the new a_wait_for_a_key_ends_when_the_window_is_not_in_front and a_binding_is_shown_only_once_its_file_took_it (the second fails with the old order: "a key that was not saved is shown").
  • cargo test -p victory: 79 + 1 + 2 passed, with the new the_default_bindings_are_never_written_over_a_file_that_is_there.
  • The script's copy line was run by hand in a scratch folder: a new file equals the default, an existing file is kept.
  • Run in parallel, one older menu test (a_change_is_saved_at_once_however_the_game_was_started) fails on main as well, without this change.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1739 rewrites this area; #652 and #482 add their own remapping pages; none does these three.

Written with help from Claude; everything above was built and run on my machine.

**@⁠hussainmussa** on GitHub · 2026-11-29 11:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2245) `hussainmussa:fix/1365-binding-safeguards` → `main` · +153 −14 · 3 files · 3 commits · merged 2026-11-30 14:12 UTC Part of #1365: the three small input safeguards listed there. The ideas are @⁠ItsYungFlexer's, from that issue; the third is done the way their fork does it (`create_new`). Three commits, each independent, so any one can be taken alone. The HUD prompts in #1365 are not touched. ## What it changes 1. **A wait for a key ends when the game window is not in front** (`menu.rs`). F1's KEY BINDINGS waits for the key with `GetAsyncKeyState`, which sees keys in every program. After Enter on a line, a click on another window or a key typed there was saved to `bindings.ini`, and the wait stayed on while the player was away. Now the wait ends before any key is read, the line keeps its key, and the note says NOT CHANGED: THE GAME WINDOW WAS NOT IN FRONT. Not covered: Alt+Tab itself still binds Alt, because Alt goes down while the game is still in front. 2. **The list shows a key only once `bindings.ini` took it** (`menu.rs`). `Binds::set` changed the shown text, then wrote the file. After a failed write the line showed the new key while the game used the old one, and the next line that did save wrote the failed key too. Now the text is written first and kept only if the write worked. 3. **The default `bindings.ini` is never written over one that is there** (`play.rs`, `scripts/play-foxhound.ps1`). Both launchers did "is it there? if not, write", and the write empties whatever is at that path. Both now create the file in one step that fails if it exists. This is a small window, not an everyday bug; the test pins the rule. ## How it was tested - GPU and profile: RTX 4070 12 GB, Core Ultra 7 265KF, Windows 11. Unit tests only; not run in the game yet. - `cargo test -p victory-gpu --lib host::menu -- --test-threads=1`: 16 passed, with the new `a_wait_for_a_key_ends_when_the_window_is_not_in_front` and `a_binding_is_shown_only_once_its_file_took_it` (the second fails with the old order: "a key that was not saved is shown"). - `cargo test -p victory`: 79 + 1 + 2 passed, with the new `the_default_bindings_are_never_written_over_a_file_that_is_there`. - The script's copy line was run by hand in a scratch folder: a new file equals the default, an existing file is kept. - Run in parallel, one older menu test (`a_change_is_saved_at_once_however_the_game_was_started`) fails on main as well, without this change. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1739 rewrites this area; #652 and #482 add their own remapping pages; none does these three. Written with help from Claude; everything above was built and run on my machine.
KEY BINDINGS (F1) waits for the key or mouse button to bind by asking
GetAsyncKeyState, which answers for the whole desktop. The menu's own keys
are only counted while a window of ours is in front, but the wait was not:
after Enter on a line, then Alt+Tab or a click on another window, the next
key typed or button clicked there was written to bindings.ini, and the
wait stayed armed however long the player was away.

The wait now ends as soon as we are not in front, before any key is asked
for. The line keeps its keys, nothing is written, and the note says so
(NOT CHANGED: THE GAME WINDOW WAS NOT IN FRONT). The rule is in
Binds::heard_from, which takes "in front" and the keys held as arguments,
so it is tested without a window.

Part of #1365 (the idea is ItsYungFlexer's, from the issue's list of small
input safeguards; the code is written against main).

Tested: cargo test -p victory-gpu --lib host::menu, new test
a_wait_for_a_key_ends_when_the_window_is_not_in_front; the new note is in
key_bindings_are_shown_and_written's check that every line fits the box
and has its letters. Not tried in the game.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Binds::set changed the text the KEY BINDINGS list shows first and wrote
the file second. After a write that failed (a read-only file, a folder
that is gone, a full disk) the note said COULD NOT SAVE BINDINGS.INI, but
the line showed the new key although the game still used the old one, and
the next line that did save wrote the failed key along with its own. The
sensitivity line went the same way.

The new text is now made aside, written, and kept only if the write
succeeded. A failed write leaves the list, the file and the game's
bindings as they were, under the same note.

Binds::open's reading of the file is Binds::read, so a test can name the
file.

Part of #1365 (the idea is ItsYungFlexer's, from the issue's list of small
input safeguards; the code is written against main).

Tested: cargo test -p victory-gpu --lib host::menu, new test
a_binding_is_shown_only_once_its_file_took_it (a file in a temporary
folder that is removed, then put back); it fails with the old order.
Not tried in the game.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The first start with MOUSE AND KEYBOARD on writes the default bindings.ini
beside the settings. `victory play` did it in two steps: "not a file?",
then std::fs::write, which empties and rewrites whatever is at that path.
A bindings.ini the first step did not see (a file the system would not
answer for at that moment, or one made in between by a second start or by
the player) lost the keys the player had set. The script launcher had the
same two steps with Test-Path and Copy-Item.

Both now make the file in one step that fails when it exists: create_new
in play.rs (default_bindings), [System.IO.File]::Copy without overwrite
in play-foxhound.ps1. "Already there" is taken as done and the file is
used as it is.

Part of #1365 (the idea is ItsYungFlexer's, from the issue's list of small
input safeguards; create_new is also what their fork uses, the code here
is written against main).

Tested: cargo test -p victory, new test
the_default_bindings_are_never_written_over_a_file_that_is_there (new
file gets the defaults; a custom and an empty file are kept; a missing
folder is an error and makes nothing). The script's copy line was run by
hand in a scratch folder: new file equal to the default, existing file
kept, missing folder quiet. Not tried in the game.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 11:01:13 +00:00
Author
Owner

@⁠ItsYungFlexer on GitHub · 2026-11-29 12:06 UTC · original

Thanks @⁠hussainmussa for crediting my fork and keeping the HUD work separate. This covers the three safeguards I wanted upstream, so please proceed with your PR—I won’t submit duplicates.

My current build is victory-reviewed-defaults.exe, with its source now on [VIctory-NVIDIA-Reloaded/main](https://github.com/ItsYungFlexer/VIctory-NVIDIA-Reloaded). The previous main is preserved on a backup branch.

Codex reviewed your diff at d59447b2cca584e45ef1e69376493327c107fb13 and independently ran four isolated Rust checks plus the PowerShell no-overwrite copy check; all passed. That validation did not include the full upstream workspace suite or in-game testing.

**@⁠ItsYungFlexer** on GitHub · 2026-11-29 12:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2245#issuecomment-7255573845) Thanks @⁠hussainmussa for crediting my fork and keeping the HUD work separate. This covers the three safeguards I wanted upstream, so please proceed with your PR—I won’t submit duplicates. My current build is **victory-reviewed-defaults.exe**, with its source now on [[VIctory-NVIDIA-Reloaded/main](https://github.com/ItsYungFlexer/VIctory-NVIDIA-Reloaded)](https://github.com/ItsYungFlexer/VIctory-NVIDIA-Reloaded). The previous main is preserved on a backup branch. Codex reviewed your diff at `d59447b2cca584e45ef1e69376493327c107fb13` and independently ran four isolated Rust checks plus the PowerShell no-overwrite copy check; all passed. That validation did not include the full upstream workspace suite or in-game testing.
github manually merged commit e535816d1b into main 2026-11-30 14:17:30 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2245
No description provided.