HLE/gameinput: the system button registration gets its own six arguments #838

Manually merged
github merged 1 commit from github-bot/gh-838 into main 2026-11-29 08:22:32 +00:00 AGit
Owner

@⁠CwWwWwW on GitHub · 2026-11-28 07:34 UTC · original
CwWwWwW:fix/gameinput-system-button-arity → main · +54 −4 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC

Ported to trustno1-coder/VIctory-NVIDIA from the same change submitted to fxceless/victory-fork as PR #1462 (head 9911e5efde, author CwWwWwW). The fork's own line was dropped when it rebased onto 959dcaf (5dbf5ce), so this is submitted here directly. The description below is the original one; its 'Verification' numbers refer to the fork tree. Rebased onto main 63b902f.

The problem

The IInput vtable (crates/victory-hle/src/modules/gameinput.rs:897) pointed both 0x50 (RegisterSystemButtonCallback) and 0x58 (RegisterKeyboardLayoutCallback) at the same extern "system" handler with five arguments. The platform's signatures differ: slot 0x50 takes (this, device, button filter, context, callback, token*) 鈥?six arguments, the filter between the device and the context 鈥?while 0x58 takes the five the handler has.

On x64 a six-argument call passes the fifth and sixth on the stack, so the shared five-argument handler's out was the title's callback pointer, not its token*:

  • token(out) (:707-713) wrote the registration token over the first 8 bytes of the title's callback code 鈥?an access violation on a read-only code page, or a write to whatever page the callback lives in;
  • the title's real token was never written, so a title that checks the HRESULT and then uses the token would unregister or use a stale value.

Trigger: any title that calls RegisterSystemButtonCallback for the guide/share buttons. The current title only registers device callbacks (slot 0x48), so this is latent today and a crash for the first title or update that uses it.

Evidence for the platform argument lists: the host's own C:\Windows\System32\GameInput.dll was disassembled read-only offline for these two slots (slot 0x50 reads rcx this, rdx device, r8d filter, r9 context, [rsp+0x90] callback, [rsp+0x98] token*; slot 0x58 reads r8 context, r9 callback, token on the stack). No game launch was involved.

The change

Two handlers with their own argument lists: register_button for slot 0x50 (six arguments) and register_layout for slot 0x58 (five, unchanged behaviour). Neither callback runs in the HLE either way; only the token is written, now into the right place.

Evidence

New test gameinput::tests::a_system_button_registration_writes_its_token_and_not_the_callback calls slot 0x50 with the platform's six-argument signature and passes a writable buffer where the callback code would be:

  • old code: the token out stays 0 (left: 0, right: 0 on assert_ne!(token, 0)) and the buffer is written instead;
  • new code: the token is written and the buffer is untouched.

Verification on this branch (base 9a9091d):

  • cargo test -p victory-hle --lib --locked -- --test-threads=1 鈥?104 passed, 0 failed
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings 鈥?clean
  • cargo clippy -p victory-hle --all-targets --locked --all-features -- -D warnings 鈥?clean
  • git diff --check clean; the crate is not fmt-clean on this toolchain already (pre-existing diffs in this file at 834/1169/1594/1603), and the change adds no new fmt diff.

Scope and overlap

One file, crates/victory-hle/src/modules/gameinput.rs (+54/-4). Checked the open tracker: no open PR changes this pairing (open #534/#485 keep the same five-argument handler at both slots; #680 is xstore). CI's check may be red from main's own victory-shader clippy errors (#1440) and asset policy (#1322), which this diff does not touch.

Verification on this tree (base 63b902f, 2026-11-27)

  • cargo check --workspace --all-targets --locked: pass (Rust 1.98.1, the version pinned in rust-toolchain.toml)
  • cargo check --workspace --all-targets --all-features --locked: pass
  • cargo clippy --workspace --all-targets --locked -- -D warnings (and --all-features): this change adds no clippy finding. The only failures are on unmodified lines of main (clippy::manual_is_multiple_of at crates/victory-gpu/src/shadow.rs:1708 and crates/victory-gpu/src/descriptor.rs:1234, clippy::let_and_return at crates/victory-shader/src/emit/mod.rs:2768); CI run 46104876336 on 63b902f failed on those before this change.
  • cargo test was not run in the author's environment (Windows VM without an MSVC toolchain; test binaries could not be linked there). CI on Windows and a run on the card should confirm.
**@⁠CwWwWwW** on GitHub · 2026-11-28 07:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/838) `CwWwWwW:fix/gameinput-system-button-arity` → `main` · +54 −4 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC Ported to trustno1-coder/VIctory-NVIDIA from the same change submitted to fxceless/victory-fork as PR #1462 (head 9911e5efde48dc3cd05b8f8fe115e11d83db2e94, author CwWwWwW). The fork's own line was dropped when it rebased onto 959dcaf (5dbf5ce), so this is submitted here directly. The description below is the original one; its 'Verification' numbers refer to the fork tree. Rebased onto main 63b902f. ## The problem The `IInput` vtable (`crates/victory-hle/src/modules/gameinput.rs:897`) pointed both `0x50` (RegisterSystemButtonCallback) and `0x58` (RegisterKeyboardLayoutCallback) at the same `extern "system"` handler with five arguments. The platform's signatures differ: slot `0x50` takes `(this, device, button filter, context, callback, token*)` 鈥?six arguments, the filter between the device and the context 鈥?while `0x58` takes the five the handler has. On x64 a six-argument call passes the fifth and sixth on the stack, so the shared five-argument handler's `out` was the title's **callback pointer**, not its `token*`: - `token(out)` (`:707-713`) wrote the registration token over the first 8 bytes of the title's callback code 鈥?an access violation on a read-only code page, or a write to whatever page the callback lives in; - the title's real token was never written, so a title that checks the HRESULT and then uses the token would unregister or use a stale value. Trigger: any title that calls `RegisterSystemButtonCallback` for the guide/share buttons. The current title only registers device callbacks (slot 0x48), so this is latent today and a crash for the first title or update that uses it. Evidence for the platform argument lists: the host's own `C:\Windows\System32\GameInput.dll` was disassembled read-only offline for these two slots (slot 0x50 reads `rcx` this, `rdx` device, `r8d` filter, `r9` context, `[rsp+0x90]` callback, `[rsp+0x98]` token*; slot 0x58 reads `r8` context, `r9` callback, token on the stack). No game launch was involved. ## The change Two handlers with their own argument lists: `register_button` for slot `0x50` (six arguments) and `register_layout` for slot `0x58` (five, unchanged behaviour). Neither callback runs in the HLE either way; only the token is written, now into the right place. ## Evidence New test `gameinput::tests::a_system_button_registration_writes_its_token_and_not_the_callback` calls slot `0x50` with the platform's six-argument signature and passes a writable buffer where the callback code would be: - old code: the token out stays 0 (`left: 0, right: 0` on `assert_ne!(token, 0)`) and the buffer is written instead; - new code: the token is written and the buffer is untouched. Verification on this branch (base `9a9091d`): - `cargo test -p victory-hle --lib --locked -- --test-threads=1` 鈥?104 passed, 0 failed - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` 鈥?clean - `cargo clippy -p victory-hle --all-targets --locked --all-features -- -D warnings` 鈥?clean - `git diff --check` clean; the crate is not fmt-clean on this toolchain already (pre-existing diffs in this file at 834/1169/1594/1603), and the change adds no new fmt diff. ## Scope and overlap One file, `crates/victory-hle/src/modules/gameinput.rs` (+54/-4). Checked the open tracker: no open PR changes this pairing (open #534/#485 keep the same five-argument handler at both slots; #680 is xstore). CI's `check` may be red from main's own victory-shader clippy errors (#1440) and asset policy (#1322), which this diff does not touch. ## Verification on this tree (base 63b902f, 2026-11-27) - cargo check --workspace --all-targets --locked: pass (Rust 1.98.1, the version pinned in rust-toolchain.toml) - cargo check --workspace --all-targets --all-features --locked: pass - cargo clippy --workspace --all-targets --locked -- -D warnings (and --all-features): this change adds no clippy finding. The only failures are on unmodified lines of main (clippy::manual_is_multiple_of at crates/victory-gpu/src/shadow.rs:1708 and crates/victory-gpu/src/descriptor.rs:1234, clippy::let_and_return at crates/victory-shader/src/emit/mod.rs:2768); CI run 46104876336 on 63b902f failed on those before this change. - cargo test was not run in the author's environment (Windows VM without an MSVC toolchain; test binaries could not be linked there). CI on Windows and a run on the card should confirm.
IInput vtable slots 0x50 (RegisterSystemButtonCallback) and 0x58 (RegisterKeyboardLayoutCallback) shared one five-argument handler, but 0x50 takes six arguments (the filter sits between device and context). On x64 the shared handler out pointer was the title callback pointer, so token(out) wrote the registration token over the callback code and the real token was never written. Split the handler into register_button (six arguments) and register_layout (five, unchanged).

Ported from fxceless/victory-fork PR #1462 (head 0c8a519d188932edc9ce2c0456708a5d1d353197).
Original author: CwWwWwW <[email protected]>.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:28:40 +00:00
github manually merged commit 2b6eb83831 into main 2026-11-29 08:22:32 +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!838
No description provided.