GameInput: the Sony pad reader takes reports as long as Windows gives them #421

Closed
github-bot wants to merge 0 commits from github-bot/gh-421 into main AGit
Owner

@⁠retroiffy on GitHub · 2026-12-02 06:03 UTC · original
retroiffy:sony-pad-report-lengths → main · +109 −7 · 1 files · 72 commits · closed without merging

The raw-HID reader for Sony pads reads each input report into a fixed 128-byte buffer. Over Bluetooth on Windows, a DualShock 4's top-level collection reports InputReportByteLength 547, and ReadFile refuses a buffer shorter than that. The reader thread then ends at its first read, the 1 s enumeration finds the pad again, and this repeats for the whole session without a reading. That once-a-second rediscovery is probably what #419 shows ("a Sony pad on raw HID ... kind=Ds4" once per second, Bluetooth HID service path).

What changes, all in gameinput/hid.rs:

  • report_lengths: HidD_GetPreparsedData + HidP_GetCaps give the collection's input, feature and output report lengths (0 when they cannot be read).
  • The reader's buffer is input_len.max(128), so short USB reports behave as before.
  • The Bluetooth feature read (0x05 / 0x20) uses at least the collection's feature length.
  • Output reports (the Bluetooth init report and rumble) are padded with zeros up to OutputReportByteLength. The pad's own bytes, including the CRC, stay where they are.
  • bluetooth(path, input_len): bluetooth_path(path) from #254, or input reports longer than the 64 bytes these pads send over USB.

Overlap: #390 pads rumble output reports through a write handle of its own. If that lands first, the output-padding part here can be dropped and only the reader buffer and feature length kept. I am happy to rebase.

Tested on Windows 11 with a DualShock 4 (pid 09cc) paired over Bluetooth:

  • cargo test --locked -p victory-hle --lib gameinput::hid: 15 passed, including two new tests: a Bluetooth service path is taken as Bluetooth and a USB path is not, and output reports are padded to the length Windows asks for.
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean.
  • The new ignored live test connected_sony_pads -- --ignored --nocapture read the paired pad continuously for 10 s. Before the change, the same pad was rediscovered once a second with no reading (203 times in a 3-minute session log).
  • Not yet checked over a full game session, and rumble was not checked.

🤖 Generated with Claude Code

**@⁠retroiffy** on GitHub · 2026-12-02 06:03 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/421) `retroiffy:sony-pad-report-lengths` → `main` · +109 −7 · 1 files · 72 commits · closed without merging The raw-HID reader for Sony pads reads each input report into a fixed 128-byte buffer. Over Bluetooth on Windows, a DualShock 4's top-level collection reports `InputReportByteLength` 547, and `ReadFile` refuses a buffer shorter than that. The reader thread then ends at its first read, the 1 s enumeration finds the pad again, and this repeats for the whole session without a reading. That once-a-second rediscovery is probably what #419 shows ("a Sony pad on raw HID ... kind=Ds4" once per second, Bluetooth HID service path). What changes, all in `gameinput/hid.rs`: - `report_lengths`: `HidD_GetPreparsedData` + `HidP_GetCaps` give the collection's input, feature and output report lengths (0 when they cannot be read). - The reader's buffer is `input_len.max(128)`, so short USB reports behave as before. - The Bluetooth feature read (0x05 / 0x20) uses at least the collection's feature length. - Output reports (the Bluetooth init report and rumble) are padded with zeros up to `OutputReportByteLength`. The pad's own bytes, including the CRC, stay where they are. - `bluetooth(path, input_len)`: `bluetooth_path(path)` from #254, or input reports longer than the 64 bytes these pads send over USB. Overlap: #390 pads rumble output reports through a write handle of its own. If that lands first, the output-padding part here can be dropped and only the reader buffer and feature length kept. I am happy to rebase. Tested on Windows 11 with a DualShock 4 (pid 09cc) paired over Bluetooth: - `cargo test --locked -p victory-hle --lib gameinput::hid`: 15 passed, including two new tests: a Bluetooth service path is taken as Bluetooth and a USB path is not, and output reports are padded to the length Windows asks for. - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: clean. - The new ignored live test `connected_sony_pads -- --ignored --nocapture` read the paired pad continuously for 10 s. Before the change, the same pad was rediscovered once a second with no reading (203 times in a 3-minute session log). - Not yet checked over a full game session, and rumble was not checked. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Over Bluetooth a DualShock 4's input reports are 547 bytes as Windows gives them; the reader's 128-byte buffer made its first read fail, so it left and the pad was found anew every second without a reading (issue #419). The reader, the feature read and the output reports now use the lengths from HidP_GetCaps; a pad whose input reports are longer than 64 bytes is also taken as Bluetooth.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 06:03:22 +00:00
github-bot closed this pull request 2026-12-02 07:54:14 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.