Input: read PlayStation and generic HID pads that XInput does not list #68

Open
marquezinii wants to merge 1 commit from upstream-pr/68 into main
marquezinii commented 2026-11-24 21:08:41 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by marquezinii on 2026-11-24T21:08:41Z.


Only XInput pads reach the title today, so a DualSense or DualShock 4 (or any pad without an XInput driver) does nothing unless something like Steam Input turns it into an XInput pad. This reads those pads over HID and puts them in the slots XInput leaves empty.

What is read

  • DualShock 4 and DualSense / DualSense Edge, USB and Bluetooth, from their own report layouts (the ones Linux's hid-playstation uses). On Bluetooth the feature report that switches the pad to full reports is read first; the short report is understood as well. Cross/Circle/Square/Triangle go to A/B/X/Y, Options to Menu, Create and the touchpad click to View. Rumble goes through their output reports (Bluetooth ones with the CRC); the light bar is left alone.
  • Any other HID gamepad or joystick, by its usages: X/Y the left stick, Z/Rz the right one when both are there (Rx/Ry are then analogue triggers), else Rx/Ry, the hat as the D-pad, buttons in the usual DirectInput order (1 west, 2 south, 3 east, 4 north, 5-8 shoulders and triggers, 9 select, 10 start, 11-12 stick clicks). VICTORY_PAD_BUTTONS takes other button numbers for pads that differ.

How it fits

  • New gameinput/hid.rs; Host in gameinput.rs asks XInput first, then the HID pads. An XInput pad keeps its slot; a HID pad sitting in a slot XInput takes moves to a free one. rumble reaches the HID pad in that slot too.
  • A background thread looks for pads every 2 s; each pad has a reader thread, and a pad that stops answering is dropped and found again when it comes back.
  • XInput's own HID devices (IG_ in the path) are skipped, so Xbox pads are not read twice.
  • No new crates: two windows-sys features (HID, SetupAPI) and Win32_System_IO. Cargo.lock is unchanged.

Tested

  • Unit tests for both Sony report forms on USB and Bluetooth, the rumble reports (motor bytes, CRC), the generic mapping, the button-map variable and value normalisation.
  • With a DualSense on USB (Windows 11), through the ignored connected_hid_pads test, read both ways: as a DualSense, and forced through the generic path (a local change, not in this PR). Both times every one of the 14 buttons came through on its own bit, both triggers went 0 to 1 and both sticks -1 to 1 on each axis. The rumble ran for the second the test asks for.
  • Unplugging the DualSense and plugging it back in during a run: it dropped out, came back on the next scan as a new pad, and its buttons came through again.
  • cargo clippy --workspace --all-targets -- -D warnings (default and --all-features), cargo test -p victory-hle (105 passed) and cargo xtask policy pass.

Not tested: Bluetooth (no adapter here), a DualShock 4, a real generic pad other than the DualSense, and in the title itself (I don't have the files on this machine). If someone can try one of those, cargo test -p victory-hle connected_hid_pads -- --ignored --nocapture prints every change of state.

Upstream has similar open work (Marvisak/VIctory#150 and #1517 for the DualSense over HID, #312 for an SDL3 backend). This one stays without new dependencies and also covers the DualShock 4 and generic pads.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6591453295 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/68). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T21:08:41Z. --- Only XInput pads reach the title today, so a DualSense or DualShock 4 (or any pad without an XInput driver) does nothing unless something like Steam Input turns it into an XInput pad. This reads those pads over HID and puts them in the slots XInput leaves empty. **What is read** - **DualShock 4 and DualSense / DualSense Edge**, USB and Bluetooth, from their own report layouts (the ones Linux's `hid-playstation` uses). On Bluetooth the feature report that switches the pad to full reports is read first; the short report is understood as well. Cross/Circle/Square/Triangle go to A/B/X/Y, Options to Menu, Create and the touchpad click to View. Rumble goes through their output reports (Bluetooth ones with the CRC); the light bar is left alone. - **Any other HID gamepad or joystick**, by its usages: X/Y the left stick, Z/Rz the right one when both are there (Rx/Ry are then analogue triggers), else Rx/Ry, the hat as the D-pad, buttons in the usual DirectInput order (1 west, 2 south, 3 east, 4 north, 5-8 shoulders and triggers, 9 select, 10 start, 11-12 stick clicks). `VICTORY_PAD_BUTTONS` takes other button numbers for pads that differ. **How it fits** - New `gameinput/hid.rs`; `Host` in `gameinput.rs` asks XInput first, then the HID pads. An XInput pad keeps its slot; a HID pad sitting in a slot XInput takes moves to a free one. `rumble` reaches the HID pad in that slot too. - A background thread looks for pads every 2 s; each pad has a reader thread, and a pad that stops answering is dropped and found again when it comes back. - XInput's own HID devices (`IG_` in the path) are skipped, so Xbox pads are not read twice. - No new crates: two `windows-sys` features (HID, SetupAPI) and `Win32_System_IO`. `Cargo.lock` is unchanged. **Tested** - Unit tests for both Sony report forms on USB and Bluetooth, the rumble reports (motor bytes, CRC), the generic mapping, the button-map variable and value normalisation. - With a DualSense on USB (Windows 11), through the ignored `connected_hid_pads` test, read **both ways**: as a DualSense, and forced through the generic path (a local change, not in this PR). Both times every one of the 14 buttons came through on its own bit, both triggers went 0 to 1 and both sticks -1 to 1 on each axis. The rumble ran for the second the test asks for. - Unplugging the DualSense and plugging it back in during a run: it dropped out, came back on the next scan as a new pad, and its buttons came through again. - `cargo clippy --workspace --all-targets -- -D warnings` (default and `--all-features`), `cargo test -p victory-hle` (105 passed) and `cargo xtask policy` pass. **Not tested**: Bluetooth (no adapter here), a DualShock 4, a real generic pad other than the DualSense, and in the title itself (I don't have the files on this machine). If someone can try one of those, `cargo test -p victory-hle connected_hid_pads -- --ignored --nocapture` prints every change of state. Upstream has similar open work (Marvisak/VIctory#150 and #1517 for the DualSense over HID, #312 for an SDL3 backend). This one stays without new dependencies and also covers the DualShock 4 and generic pads.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/68:upstream-pr/68'
git switch 'upstream-pr/68'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/68'
git switch 'upstream-pr/68'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/68'
git switch 'upstream-pr/68'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/68'
git switch 'main'
git merge --squash 'upstream-pr/68'
git switch 'main'
git merge --ff-only 'upstream-pr/68'
git switch 'main'
git merge 'upstream-pr/68'
git push origin 'main'
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
fxceless/victory-fork!68
No description provided.