Mouse and keyboard: bindings read again after KEY BINDINGS, also after a file that did not read #1185

Manually merged
github merged 1 commit from github-bot/gh-1185 into main 2026-11-29 08:21:25 +00:00 AGit
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 15:09 UTC · original
kibagami-nc:fix/mnk-bindings-read-again → main · +32 −6 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC

What happens

bindings.ini asks to be edited by hand ("Edit while the game is closed…"). With a typo in it, for example RT = LeftClick instead of Mouse1, parse refuses the file. The start then says Mouse and keyboard disabled: Invalid binding on line …, and mouse and keyboard are off.

The natural fix is F1, KEY BINDINGS: pick the line and press the key. That writes a good file, bumps MNK_BINDINGS_CHANGED, and the menu says "SAVED TO BINDINGS.INI AND USED AT ONCE." But config() read the file again only when the earlier read had worked:

match &c.1 {
    None => *c = (changed, Some(load().map(Arc::new))),
    Some(Some(_)) if c.0 != changed => { … read again … }
    _ => {}            // Some(None): the first read failed, so never again
}

So mouse and keyboard stayed off until a restart.

The change (crates/victory-hle/src/modules/mnk.rs)

  • The rule moves into refresh(state, changed, load), which config() calls with its static, the write count and load. That lets the rule be tested without the file or the globals.
  • The second arm is Some(_). The file is read again whenever the write count moved, whatever the last read gave. enabled() and sample() call config() each time, so the bindings are in use at once, as the menu says.
  • Unchanged: the first read, no read without a write, and a write that no longer reads keeps the last bindings.

The menu's side needs nothing. It writes the key names that key() reads back (letters and digits, the named keys, 0x.. for the rest).

Tests

  • New bindings_are_read_again_after_a_write_even_after_a_file_that_did_not_read:

    • a typo gives no bindings;
    • no read without a write;
    • after a write with a good line, the bindings are in use (RT on Mouse1);
    • a later bad write keeps them.
    • With the old Some(Some(_)) arm it fails, at the read after the write.
  • cargo test -p victory-hle --locked: 191 passed, 3 ignored, plus the other test binaries.

  • Clippy (-p victory-hle --all-targets -D warnings, default and --all-features): clean. That is with main's three findings allowed (let_and_return, manual_is_multiple_of, some_filter), which #665 fixes.

  • Checked independently by jptorres96 on Windows 11 26300 (rustc 1.98.1): cargo test -p victory-hle --lib 191 passed, including the new test. Clippy: nothing in mnk.rs.

Not run with the game.

No game files, dumps or extracted data are included.

**@⁠kibagami-nc** on GitHub · 2026-11-28 15:09 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1185) `kibagami-nc:fix/mnk-bindings-read-again` → `main` · +32 −6 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC ## What happens `bindings.ini` asks to be edited by hand ("Edit while the game is closed…"). With a typo in it, for example `RT = LeftClick` instead of `Mouse1`, `parse` refuses the file. The start then says `Mouse and keyboard disabled: Invalid binding on line …`, and mouse and keyboard are off. The natural fix is F1, KEY BINDINGS: pick the line and press the key. That writes a good file, bumps `MNK_BINDINGS_CHANGED`, and the menu says "SAVED TO BINDINGS.INI AND USED AT ONCE." But `config()` read the file again only when the earlier read had worked: ```rust match &c.1 { None => *c = (changed, Some(load().map(Arc::new))), Some(Some(_)) if c.0 != changed => { … read again … } _ => {} // Some(None): the first read failed, so never again } ``` So mouse and keyboard stayed off until a restart. ## The change (`crates/victory-hle/src/modules/mnk.rs`) - The rule moves into `refresh(state, changed, load)`, which `config()` calls with its static, the write count and `load`. That lets the rule be tested without the file or the globals. - The second arm is `Some(_)`. The file is read again whenever the write count moved, whatever the last read gave. `enabled()` and `sample()` call `config()` each time, so the bindings are in use at once, as the menu says. - Unchanged: the first read, no read without a write, and a write that no longer reads keeps the last bindings. The menu's side needs nothing. It writes the key names that `key()` reads back (letters and digits, the named keys, `0x..` for the rest). ## Tests - **New** `bindings_are_read_again_after_a_write_even_after_a_file_that_did_not_read`: - a typo gives no bindings; - no read without a write; - after a write with a good line, the bindings are in use (`RT` on `Mouse1`); - a later bad write keeps them. - With the old `Some(Some(_))` arm it fails, at the read after the write. - **`cargo test -p victory-hle --locked`**: 191 passed, 3 ignored, plus the other test binaries. - **Clippy** (`-p victory-hle --all-targets -D warnings`, default and `--all-features`): clean. That is with main's three findings allowed (`let_and_return`, `manual_is_multiple_of`, `some_filter`), which #665 fixes. - **Checked independently** by jptorres96 on Windows 11 26300 (rustc 1.98.1): `cargo test -p victory-hle --lib` 191 passed, including the new test. Clippy: nothing in `mnk.rs`. Not run with the game. No game files, dumps or extracted data are included.
config() reloaded bindings.ini when F1's KEY BINDINGS wrote it only if the
first read had worked. With a typo in the file (as `RT = LeftClick`), mouse
and keyboard were off at the start ("Mouse and keyboard disabled: Invalid
binding on line ..."). Setting the line in KEY BINDINGS then wrote a good
file, and said "SAVED TO BINDINGS.INI AND USED AT ONCE", but it was never
read again until a restart.

The rule is now refresh(): read the first time, then again whenever the
write count moved, whatever the last read gave. A write that no longer reads
still keeps the last bindings.

Test: bindings_are_read_again_after_a_write_even_after_a_file_that_did_not_read
(it fails with the old rule).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 15:11:35 +00:00
Author
Owner

@⁠jptorres96 on GitHub · 2026-11-28 17:19 UTC · original

Checked at pr1185 (on 9ce3cf9), Windows build 26300, rustc 1.98.1:

  • cargo test -p victory-hle --lib: 191 passed, including bindings_are_read_again_after_a_write_even_after_a_file_that_did_not_read.
  • cargo clippy -p victory-hle --all-targets --no-deps -- -D warnings: nothing in mnk.rs. The one finding is main's own some_filter at gameinput.rs:1383.

I found the same thing reading 4715a42..f4608f0, and Some(_) in refresh is the whole fix for it.

A separate question on the same feature, not for this PR. With VICTORY_MNK=1, Host::xinput returns None for every slot (if super::mnk::enabled() { return None; }, gameinput.rs ~1303). A controller that is plugged in is then ignored for as long as mouse and keyboard are on, and switching back means F1 and a restart. If that is meant, to keep a resting stick from fighting the mouse, fine. If not, a pad that reports input could take precedence over the keyboard stand-in, with mouse and keyboard used when it is idle, and players with both could switch without a restart.

**@⁠jptorres96** on GitHub · 2026-11-28 17:19 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1185#issuecomment-7242925091) Checked at `pr1185` (on `9ce3cf9`), Windows build 26300, rustc 1.98.1: - `cargo test -p victory-hle --lib`: 191 passed, including `bindings_are_read_again_after_a_write_even_after_a_file_that_did_not_read`. - `cargo clippy -p victory-hle --all-targets --no-deps -- -D warnings`: nothing in `mnk.rs`. The one finding is `main`'s own `some_filter` at `gameinput.rs:1383`. I found the same thing reading `4715a42`..`f4608f0`, and `Some(_)` in `refresh` is the whole fix for it. A separate question on the same feature, not for this PR. With `VICTORY_MNK=1`, `Host::xinput` returns `None` for every slot (`if super::mnk::enabled() { return None; }`, `gameinput.rs` ~1303). A controller that is plugged in is then ignored for as long as mouse and keyboard are on, and switching back means F1 and a restart. If that is meant, to keep a resting stick from fighting the mouse, fine. If not, a pad that reports input could take precedence over the keyboard stand-in, with mouse and keyboard used when it is idle, and players with both could switch without a restart.
Author
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 17:45 UTC · original

Thanks for checking it on 26300, and for reading the range independently.

On Host::xinput returning None while mouse and keyboard are on: that's the feature's own design, not something this PR touches, so it's the maintainer's call. Your suggestion makes sense to me, though: let a pad that reports input win, and fall back to mouse and keyboard while it's idle. Players with both could then switch without F1 and a restart. Worth an issue of its own if it isn't meant.

**@⁠kibagami-nc** on GitHub · 2026-11-28 17:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1185#issuecomment-7243263422) Thanks for checking it on 26300, and for reading the range independently. On `Host::xinput` returning `None` while mouse and keyboard are on: that's the feature's own design, not something this PR touches, so it's the maintainer's call. Your suggestion makes sense to me, though: let a pad that reports input win, and fall back to mouse and keyboard while it's idle. Players with both could then switch without F1 and a restart. Worth an issue of its own if it isn't meant.
github manually merged commit 64683d8684 into main 2026-11-29 08:21:25 +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!1185
No description provided.