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

Open
github-bot wants to merge 1 commit from github-bot/gh-276 into main AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 13:22 UTC · original
Vladimir-Human:feat/raw-input-haptics-hid → main · +3083 −221 · 7 files · 1 commits · open

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.
**@⁠Vladimir-Human** on GitHub · 2026-11-27 13:22 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/276) `Vladimir-Human:feat/raw-input-haptics-hid` → `main` · +3083 −221 · 7 files · 1 commits · open ## 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.
- Replace 8 ms GetAsyncKeyState mouse polling with event-driven batched
  GetRawInputBuffer ingestion on WM_INPUT and a lock-free microsecond-
  timestamped ring preserving all RI_MOUSE_*_DOWN/UP edges and 8 kHz
  relative deltas without quantization or dropped fast taps.
- Add safe ClipCursor and balanced ShowCursor capture management with
  automatic release on focus loss (WM_KILLFOCUS/WM_ACTIVATE/WM_ACTIVATEAPP),
  move/size loops, minimize, shutdown, and modal xgameui dialogs.
- Populate KeyState::code_point and dead_key via ToUnicodeEx without
  mutating dead-key state (respecting VICTORY_IME_ENGLISH when set).
- Bind logical MOUSE, KEYBOARD, fallback pad, and PAD[0..4] device IDs
  simultaneously to the active local XUID in xuser::find_for_device.
- Route all four rumble channels (including trigger motors) via
  Windows.Gaming.Input with XInput fallback, and emit DualSense USB
  (0x02, 48 B) and Bluetooth (0x31, 78 B + CRC-32 seed 0xA2) HID output
  reports over the write-opened overlapped HID handle.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:23:52 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 13:37 UTC · original

@⁠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.

**@⁠TaynanGT** on GitHub · 2026-11-27 13:37 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7219730517) @⁠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.
github-bot force-pushed github-bot/gh-276 from 745f2a0bc6 to 9e8b7f9ba2 2026-11-27 14:19:45 +00:00 Compare
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 14:14 UTC · original

@⁠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).

**@⁠Vladimir-Human** on GitHub · 2026-11-27 14:14 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7220527958) @⁠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`).
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 14:25 UTC · original

@⁠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.

**@⁠TaynanGT** on GitHub · 2026-11-27 14:25 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7220762584) @⁠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.
github-bot force-pushed github-bot/gh-276 from 9e8b7f9ba2 to 462476f6d1 2026-11-27 15:05:31 +00:00 Compare
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 15:01 UTC · original

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.

**@⁠Vladimir-Human** on GitHub · 2026-11-27 15:01 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7221518322) 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`.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 15:08 UTC · original

@⁠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** on GitHub · 2026-11-27 15:08 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/276#issuecomment-7221685039) @⁠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.
This pull request has changes conflicting with the target branch.
  • crates/victory-hle/src/modules/gameinput.rs
  • crates/victory-hle/src/modules/gameinput/dualsense.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/276/head:github-bot/gh-276'
git switch 'github-bot/gh-276'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-276'
git switch 'github-bot/gh-276'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-276'
git switch 'github-bot/gh-276'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-276'
git switch 'main'
git merge --squash 'github-bot/gh-276'
git switch 'main'
git merge --ff-only 'github-bot/gh-276'
git switch 'main'
git merge 'github-bot/gh-276'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.