hle: event-driven 8 kHz raw mouse ring, cursor capture, KBM+pad XUID binding, and trigger/DualSense haptics #276

Closed
Vladimir-Human wants to merge 638 commits from upstream-pr/276 into main
Vladimir-Human commented 2026-11-27 13:22:18 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by Vladimir-Human on 2026-11-27T13:22:18Z.


Summary

Adds four independently opt-in host input and haptics subsystems inside crates/victory-hle (zero changes to victory-gpu, victory-shader, or Cargo.lock). All four switches default to 0 so baseline behavior stays unchanged unless explicitly enabled:

Switch Default Scope
VICTORY_RAW_MOUSE=0|1 0 Event-driven 8 kHz WM_INPUT + batched GetRawInputBuffer ingestion and lock-free microsecond-timestamped MouseRing (RI_MOUSE_*_DOWN/UP edge preservation, MOUSE_HISTORY = 1024). When 0, preserves exact baseline VICTORY_GAMEPAD_MOUSE=1 single-packet GetRawInputData + GetAsyncKeyState path (zero Raw Input registration when both are 0).
VICTORY_CURSOR_CAPTURE=0|1 0 Independent CursorCapture state machine (ClipCursor + exact-step-balanced ShowCursor with owner-thread visibility sync) releasing on WM_KILLFOCUS, WM_ACTIVATE(WA_INACTIVE), WM_ACTIVATEAPP(0), WM_ENTERSIZEMOVE, WM_SIZE(SIZE_MINIMIZED) / SC_MINIMIZE (restoring cleanly via WM_SIZE(SIZE_RESTORED/SIZE_MAXIMIZED) without requiring SC_RESTORE), end_title, WM_NCDESTROY, and modal xgameui dialogs (OverlayGuard).
VICTORY_KBM_PAD=0|1 0 Binds logical PAD[0..4], stand-in pad, KEYBOARD, and MOUSE device IDs simultaneously to the active local XUID in xuser::find_for_device (returns baseline USER_NOT_FOUND when 0).
VICTORY_HAPTICS=0|1 0 Advertises all 4 rumble motors (0xF), preserves trigger levels (params[2..4]), routes non-HID pads to a dedicated MTA Windows.Gaming.Input worker (Gamepad::SetVibration with XInputSetState fallback), and writes DualSense USB (0x02, 48 B) / Bluetooth (0x31, 78 B + rolling 4-bit seq_tag + 0x10 tag + IEEE CRC-32 seed 0xA2) overlapped HID output reports (0x05 Off / 0x06 Vibration). When 0, advertises 0x3, zeroes triggers, skips WGI init, and uses XInputSetState only.

Also populates KeyState::code_point and dead_key via ToUnicodeEx (TOUNICODE_NO_STATE_CHANGE = 0x04, extended scan-code mask scan_code & 0xFF, surrogate pairs, VICTORY_IME_ENGLISH=1 US-English HKL awareness).

Verification

  • cargo run -p xtask --locked -- policy: asset policy: 313 files ok
  • cargo test -p xtask --locked: 11/11 passed
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings (default & --all-features): 0 warnings
  • cargo test -p victory-hle --lib --locked -- --test-threads=1 (default env AND all 4 switches =1, default & --all-features): 218 passed, 0 failed, 3 ignored + no_dll_planting 1/1
    • Deterministic unit coverage for default-off parity & independent switching (all_four_input_switches_default_off_and_toggle_independently, raw_mouse_and_cursor_capture_switches_are_strictly_independent), 8 kHz delta batching & sub-millisecond click preservation, ring overflow monotonicity, GetRawInputBuffer alignment/mixed-type/truncation parsing, CursorCapture focus/minimize/restore/overlay/pause/ShowCursor balance, ToUnicodeEx/VICTORY_IME_ENGLISH code points & dead keys, xuser::find_for_device default-off & opted-in KBM+pad binding, WGI mapping & fallback, and byte-exact DualSense USB 0x02 / BT 0x31 + 0xA2 CRC-32 vectors.
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5527358392 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/276). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T13:22:18Z. --- ## Summary Adds four independently opt-in host input and haptics subsystems inside `crates/victory-hle` (zero changes to `victory-gpu`, `victory-shader`, or `Cargo.lock`). All four switches default to `0` so baseline behavior stays unchanged unless explicitly enabled: | Switch | Default | Scope | | --- | --- | --- | | `VICTORY_RAW_MOUSE=0\|1` | `0` | Event-driven 8 kHz `WM_INPUT` + batched `GetRawInputBuffer` ingestion and lock-free microsecond-timestamped `MouseRing` (`RI_MOUSE_*_DOWN/UP` edge preservation, `MOUSE_HISTORY = 1024`). When `0`, preserves exact baseline `VICTORY_GAMEPAD_MOUSE=1` single-packet `GetRawInputData` + `GetAsyncKeyState` path (zero Raw Input registration when both are `0`). | | `VICTORY_CURSOR_CAPTURE=0\|1` | `0` | Independent `CursorCapture` state machine (`ClipCursor` + exact-step-balanced `ShowCursor` with owner-thread visibility sync) releasing on `WM_KILLFOCUS`, `WM_ACTIVATE(WA_INACTIVE)`, `WM_ACTIVATEAPP(0)`, `WM_ENTERSIZEMOVE`, `WM_SIZE(SIZE_MINIMIZED)` / `SC_MINIMIZE` (restoring cleanly via `WM_SIZE(SIZE_RESTORED/SIZE_MAXIMIZED)` without requiring `SC_RESTORE`), `end_title`, `WM_NCDESTROY`, and modal `xgameui` dialogs (`OverlayGuard`). | | `VICTORY_KBM_PAD=0\|1` | `0` | Binds logical `PAD[0..4]`, stand-in pad, `KEYBOARD`, and `MOUSE` device IDs simultaneously to the active local `XUID` in `xuser::find_for_device` (returns baseline `USER_NOT_FOUND` when `0`). | | `VICTORY_HAPTICS=0\|1` | `0` | Advertises all 4 rumble motors (`0xF`), preserves trigger levels (`params[2..4]`), routes non-HID pads to a dedicated MTA `Windows.Gaming.Input` worker (`Gamepad::SetVibration` with `XInputSetState` fallback), and writes DualSense USB (`0x02`, 48 B) / Bluetooth (`0x31`, 78 B + rolling 4-bit `seq_tag` + `0x10` tag + IEEE CRC-32 seed `0xA2`) overlapped HID output reports (`0x05` Off / `0x06` Vibration). When `0`, advertises `0x3`, zeroes triggers, skips WGI init, and uses `XInputSetState` only. | Also populates `KeyState::code_point` and `dead_key` via `ToUnicodeEx` (`TOUNICODE_NO_STATE_CHANGE = 0x04`, extended scan-code mask `scan_code & 0xFF`, surrogate pairs, `VICTORY_IME_ENGLISH=1` US-English `HKL` awareness). ## Verification - `cargo run -p xtask --locked -- policy`: `asset policy: 313 files ok` - `cargo test -p xtask --locked`: **11/11 passed** - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` (default & `--all-features`): **0 warnings** - `cargo test -p victory-hle --lib --locked -- --test-threads=1` (default env AND all 4 switches `=1`, default & `--all-features`): **218 passed, 0 failed, 3 ignored** + `no_dll_planting` **1/1** - Deterministic unit coverage for default-off parity & independent switching (`all_four_input_switches_default_off_and_toggle_independently`, `raw_mouse_and_cursor_capture_switches_are_strictly_independent`), 8 kHz delta batching & sub-millisecond click preservation, ring overflow monotonicity, `GetRawInputBuffer` alignment/mixed-type/truncation parsing, `CursorCapture` focus/minimize/restore/overlay/pause/ShowCursor balance, `ToUnicodeEx`/`VICTORY_IME_ENGLISH` code points & dead keys, `xuser::find_for_device` default-off & opted-in KBM+pad binding, WGI mapping & fallback, and byte-exact DualSense USB `0x02` / BT `0x31` + `0xA2` CRC-32 vectors.
TaynanGT commented 2026-11-27 13:37:33 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T13:37:33Z.


@Vladimir-Human The mouse ring, cursor ownership, user binding and haptics should be testable separately. #256 already has a resize and trigger check, with camera movement still under investigation. I’ll compare the incoming WM_INPUT path against that case before combining the window changes.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7219730517 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7219730517). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T13:37:33Z. --- @Vladimir-Human The mouse ring, cursor ownership, user binding and haptics should be testable separately. #256 already has a resize and trigger check, with camera movement still under investigation. I’ll compare the incoming WM_INPUT path against that case before combining the window changes.
Vladimir-Human commented 2026-11-27 14:14:22 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by Vladimir-Human on 2026-11-27T14:14:22Z.


@TaynanGT Updated #276 (9e8b7f9) so all four subsystems are gated behind independent opt-in switches that default to 0, keeping baseline behavior (including VICTORY_GAMEPAD_MOUSE=1 single-packet GetRawInputData + GetAsyncKeyState and #256's WM_INPUT/resize comparison) untouched unless explicitly enabled:

  • VICTORY_RAW_MOUSE=1 — event-driven 8 kHz WM_INPUT + batched GetRawInputBuffer ring (gameinput/mouse.rs, gameinput.rs; auto-disables batch draining if any non-mouse Raw Input device/packet appears).
  • VICTORY_CURSOR_CAPTURE=1 — independent ClipCursor + balanced ShowCursor focus/minimize/overlay/pause ownership (gameinput/mouse.rs, lifecycle.rs, xgameui.rs), testable with or without VICTORY_RAW_MOUSE=1.
  • VICTORY_KBM_PAD=1 — simultaneous PAD[0..4] + stand-in pad + KEYBOARD + MOUSE local XUID binding in xuser::find_for_device (xuser.rs, returns baseline USER_NOT_FOUND when 0).
  • VICTORY_HAPTICS=1 — 4-motor trigger haptics (0xF) via dedicated MTA Windows.Gaming.Input worker (XInputSetState fallback) and DualSense USB 0x02 / Bluetooth 0x31 (0xA2 CRC-32) overlapped HID output reports (gameinput.rs, gameinput/dualsense.rs; stays on baseline 0x3 + XInputSetState-only with zero WGI/HID output when 0).

Verified default-off parity and independent switching under both default env and all-4-switches-on (218/218 victory-hle lib tests, 0 clippy warnings default & --all-features, xtask 11/11).

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7220527958 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7220527958). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T14:14:22Z. --- @TaynanGT Updated `#276` (`9e8b7f9`) so all four subsystems are gated behind independent opt-in switches that default to `0`, keeping baseline behavior (including `VICTORY_GAMEPAD_MOUSE=1` single-packet `GetRawInputData` + `GetAsyncKeyState` and `#256`'s `WM_INPUT`/resize comparison) untouched unless explicitly enabled: - `VICTORY_RAW_MOUSE=1` — event-driven 8 kHz `WM_INPUT` + batched `GetRawInputBuffer` ring (`gameinput/mouse.rs`, `gameinput.rs`; auto-disables batch draining if any non-mouse Raw Input device/packet appears). - `VICTORY_CURSOR_CAPTURE=1` — independent `ClipCursor` + balanced `ShowCursor` focus/minimize/overlay/pause ownership (`gameinput/mouse.rs`, `lifecycle.rs`, `xgameui.rs`), testable with or without `VICTORY_RAW_MOUSE=1`. - `VICTORY_KBM_PAD=1` — simultaneous `PAD[0..4]` + stand-in pad + `KEYBOARD` + `MOUSE` local `XUID` binding in `xuser::find_for_device` (`xuser.rs`, returns baseline `USER_NOT_FOUND` when `0`). - `VICTORY_HAPTICS=1` — 4-motor trigger haptics (`0xF`) via dedicated MTA `Windows.Gaming.Input` worker (`XInputSetState` fallback) and DualSense USB `0x02` / Bluetooth `0x31` (`0xA2` CRC-32) overlapped HID output reports (`gameinput.rs`, `gameinput/dualsense.rs`; stays on baseline `0x3` + `XInputSetState`-only with zero WGI/HID output when `0`). Verified default-off parity and independent switching under both default env and all-4-switches-on (`218/218` `victory-hle` lib tests, `0` clippy warnings default & `--all-features`, `xtask` `11/11`).
TaynanGT commented 2026-11-27 14:25:22 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T14:25:22Z.


@Vladimir-Human The four independent switches give us a way to isolate each change. #220 still needs to show whether the title reads the nonzero stick state from #256, so keep that camera test on the smaller branch. #292 touches the same HID reader. Please keep USB DS4 input covered when updating the haptics branch.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7220762584 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7220762584). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T14:25:22Z. --- @Vladimir-Human The four independent switches give us a way to isolate each change. #220 still needs to show whether the title reads the nonzero stick state from #256, so keep that camera test on the smaller branch. #292 touches the same HID reader. Please keep USB DS4 input covered when updating the haptics branch.
Vladimir-Human commented 2026-11-27 15:01:04 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by Vladimir-Human on 2026-11-27T15:01:04Z.


Rebased #276 cleanly onto main (b67e8d8, commit 462476f) after #292, preserving all USB DualShock 4 input support/tests and gating DualSense 0x02/0x31 output report formatting so USB DualShock 4 pads never receive DualSense packets (format_output_report).
All four independent opt-in switches (VICTORY_RAW_MOUSE, VICTORY_CURSOR_CAPTURE, VICTORY_KBM_PAD, VICTORY_HAPTICS) remain 0 by default; re-verified victory-hle 228/228 (both all-0 and all-1), 0 clippy warnings, and xtask 11/11.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7221518322 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7221518322). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T15:01:04Z. --- Rebased `#276` cleanly onto `main` (`b67e8d8`, commit `462476f`) after `#292`, preserving all USB DualShock 4 input support/tests and gating DualSense `0x02`/`0x31` output report formatting so USB DualShock 4 pads never receive DualSense packets (`format_output_report`). All four independent opt-in switches (`VICTORY_RAW_MOUSE`, `VICTORY_CURSOR_CAPTURE`, `VICTORY_KBM_PAD`, `VICTORY_HAPTICS`) remain `0` by default; re-verified `victory-hle` `228/228` (both all-`0` and all-`1`), `0` clippy warnings, and `xtask` `11/11`.
TaynanGT commented 2026-11-27 15:08:52 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T15:08:52Z.


@Vladimir-Human The device-specific output guard covers the DS4 issue from #292. The useful hardware pair now is a USB DS4 and a DualSense on the same build, with haptics enabled. That checks DS4 input alongside the DualSense output path. The camera read trace can stay with #220.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7221685039 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7221685039). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T15:08:52Z. --- @Vladimir-Human The device-specific output guard covers the DS4 issue from #292. The useful hardware pair now is a USB DS4 and a DualSense on the same build, with haptics enabled. That checks DS4 input alongside the DualSense output path. The camera read trace can stay with #220.
TaynanGT commented 2026-11-30 17:13:40 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:13:40Z.


main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285922889 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7285922889). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:13:40Z. --- `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

Pull request closed

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
TaynanGT/Vice-Tay!276
No description provided.