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

Merged
kibagami-nc merged 1 commit from upstream-pr/1185 into main 2026-11-29 08:16:57 +00:00
kibagami-nc commented 2026-11-28 15:09:03 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T15:09:03Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5541526959 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1185). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T15:09:03Z. --- ## 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.
jptorres96 commented 2026-11-28 17:19:16 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by jptorres96 on 2026-11-28T17:19:16Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7242925091 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1185#issuecomment-7242925091). Originally posted by [jptorres96](https://github.com/jptorres96) on 2026-11-28T17:19:16Z. --- 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.
kibagami-nc commented 2026-11-28 17:45:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T17:45:29Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7243263422 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1185#issuecomment-7243263422). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T17:45:29Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
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.

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