input: DualSense and DualShock 4 support (HID input, adaptive triggers, light bar, haptics) #44

Open
sperm wants to merge 1 commit from upstream-pr/44 into main
sperm commented 2026-12-04 11:58:12 +00:00 (Migrated from github.com)

Imported from ReTerryDavis/ReVIctory. Originally posted by sperm on 2026-12-04T11:58:12Z.


Right now only XInput pads reach the title. A DualSense or DualShock 4 does nothing
unless Steam Input or DS4Windows makes it look like an Xbox pad, and even then the PS5
build's trigger, light bar and haptics effects are lost.

This ports the PlayStation controller support from
VIctory xmem (Linux/Wine) to this fork,
which runs natively on Windows. It also fixes what Windows does differently over
Bluetooth.

What is changed

Input, always on. Pads XInput does not list are read over the HID API and fill
the XInput slots that are empty. These are the DualSense, DualSense Edge, DualShock 4
and any other HID gamepad. They work over USB and Bluetooth, and the Sony pads get
rumble.

  • An XInput pad keeps its slot; a HID pad in that slot moves to a free one.
  • XInput's own HID devices (IG_ in the path) are skipped.
  • VICTORY_PAD_BUTTONS sets a button order for generic pads.
  • VICTORY_RUMBLE_GAIN and VICTORY_DUALSENSE_RUMBLE=0 tune the motors.
  • Files: gameinput/hid.rs (from xmem, with the Bluetooth rumble fix below) and a
    small change to gameinput.rs.

PS5 effects, opt-in: VICTORY_DUALSENSE=1 / -DualSense. These are what the
title's PS5 build does with the pad:

  • Adaptive triggers. The title passes its pad a list of effects. The Xbox build
    acts on rumble only; the PS5 build's trigger and light bar effects are decoded from
    that list and sent to the pad (pad_effects.rs, dualsense.rs).
  • R2 throttle notch in vehicles. This is the PS5 vehicle block, run after the
    title's trigger producer (vehicle_notch.rs).
  • Light bar colours.
  • Haptics. The title's PadHaptics submix is played on the controller's
    actuators (channels 3/4 of its USB audio endpoint) through WASAPI (haptics.rs).
    Haptics need USB: over Bluetooth, Windows has no audio endpoint for the pad.
  • Rumble curve. Single-strength rumble is split between the motors as on the PS5
    (ps5_rumble.rs).

VICTORY_DUALSHOCK=1 / -DualShock shows the light bar colours on a DualShock 4.

What Windows needed that Linux did not

xmem writes output reports to Linux's /dev/hidrawN through Wine's Z: drive. Here
dualsense.rs finds the pad with SetupAPI/HidD_*, opens it shared, and writes with
WriteFile. Three differences came up:

  • Report length. Windows takes writes of exactly the output report length the
    device declares. A Bluetooth DualSense declares 547 bytes (its longest report),
    but the pad reads a 78-byte report with its CRC at byte 74.
    • Bluetooth reports are now built at 78 bytes, CRC at 74, then padded with zeros to
      the declared length.
    • USB reports are padded or cut to the declared length.
  • Bluetooth rumble. xmem's sony_rumble put the CRC at the end of the declared
    length: byte 543 of 547 on Windows. The pad dropped every rumble report. It now
    goes at byte 74, for the DualSense and DualShock 4 alike.
  • Light bar release. A DualSense's firmware keeps the light bar until it is sent
    "lightbar setup: light out" (valid_flag2 bit 1, lightbar_setup 0x02). Linux's
    hid-playstation sends that when the pad connects; Windows sends nothing, so our
    colours were ignored. The output thread now sends it once per connection, then the
    current colour (the default blue until the title names one).

The trigger encodings and their tests are xmem's and are unchanged.

Other changes.

  • tls::near becomes pub(crate) (the notch hook uses it).
  • HID/SetupAPI features are added to windows-sys in victory-loader and
    victory-hle.
  • WASAPI features are added to windows in victory-loader.
  • Hook install is wired in apps/victory/src/run.rs next to the other apply_asked
    calls.
  • -DualSense/-DualShock switches are added to scripts/play.ps1.
  • A "PlayStation controllers" section is added to the README.

Safety. Every hook checks the title's code before patching. On a build it doesn't
recognise, it logs a warning (not hooked … another build?) and stays off. Without
VICTORY_DUALSENSE/VICTORY_DUALSHOCK, nothing is patched; only the HID input
reader is new.

Using the launcher. The launcher passes only its own settings to the game and
drops VICTORY_* variables set in the shell. Put VICTORY_DUALSENSE=1 in the
launcher's extra settings.

Tested

  • cargo test -p victory-loader: the new modules' 13 tests pass. They include report
    sizing at the lengths Windows declares (USB 48/64, Bluetooth 547), the light bar
    release report, and a padded DualShock 4 Bluetooth report.
  • cargo test -p victory-hle -- gameinput: 21 pass, including rumble at 547 bytes for
    both pads. The 1 hardware test is ignored.
  • cargo clippy -p victory-loader -p victory-hle -p victory --all-targets: no
    warnings.
  • cargo xtask policy: ok.
  • cargo build --locked --release -p victory: ok.
  • The four hook sites match a retail executable (read from the file): the
    pad-effect handler, the rumble emitter, the haptics mixer step and the notch call.
  • In game, release build, RX 9070 XT, DualSense over Bluetooth:
    • The pad connects and drives the title over HID.
    • Adaptive triggers work.
  • Still to test:
    • DualSense Bluetooth: rumble, light bar (after the CRC and light bar fixes)
    • DualSense USB: triggers, light bar, haptics, rumble
    • Without VICTORY_DUALSENSE: pad works, no effects
    • Xbox pad still works as before
    • DualShock 4: not tested (no hardware)

Credits

Ported from VIctory xmem, at 0fd7614:

  • The loader modules are by Sam Sepiol and goldfishdev.
  • The HID pad reader is by delacor and goldfishdev. It was itself ported from
    delacor/VIctory a9553ae72 (author marquezini).
  • Trigger effect encodings follow Nielk1's TriggerEffectGenerator.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ReTerryDavis/ReVIctory:issue:5645998645 --> Imported from [ReTerryDavis/ReVIctory](https://github.com/ReTerryDavis/ReVIctory/pull/44). Originally posted by [sperm](https://github.com/sperm) on 2026-12-04T11:58:12Z. --- Right now only XInput pads reach the title. A DualSense or DualShock 4 does nothing unless Steam Input or DS4Windows makes it look like an Xbox pad, and even then the PS5 build's trigger, light bar and haptics effects are lost. This ports the PlayStation controller support from [VIctory xmem](https://github.com/lobomfz/VIctory-xmem) (Linux/Wine) to this fork, which runs natively on Windows. It also fixes what Windows does differently over Bluetooth. ### What is changed **Input, always on.** Pads XInput does not list are read over the HID API and fill the XInput slots that are empty. These are the DualSense, DualSense Edge, DualShock 4 and any other HID gamepad. They work over USB and Bluetooth, and the Sony pads get rumble. - An XInput pad keeps its slot; a HID pad in that slot moves to a free one. - XInput's own HID devices (`IG_` in the path) are skipped. - `VICTORY_PAD_BUTTONS` sets a button order for generic pads. - `VICTORY_RUMBLE_GAIN` and `VICTORY_DUALSENSE_RUMBLE=0` tune the motors. - Files: `gameinput/hid.rs` (from xmem, with the Bluetooth rumble fix below) and a small change to `gameinput.rs`. **PS5 effects, opt-in: `VICTORY_DUALSENSE=1` / `-DualSense`.** These are what the title's PS5 build does with the pad: - **Adaptive triggers.** The title passes its pad a list of effects. The Xbox build acts on rumble only; the PS5 build's trigger and light bar effects are decoded from that list and sent to the pad (`pad_effects.rs`, `dualsense.rs`). - **R2 throttle notch in vehicles.** This is the PS5 vehicle block, run after the title's trigger producer (`vehicle_notch.rs`). - **Light bar colours.** - **Haptics.** The title's `PadHaptics` submix is played on the controller's actuators (channels 3/4 of its USB audio endpoint) through WASAPI (`haptics.rs`). Haptics need USB: over Bluetooth, Windows has no audio endpoint for the pad. - **Rumble curve.** Single-strength rumble is split between the motors as on the PS5 (`ps5_rumble.rs`). `VICTORY_DUALSHOCK=1` / `-DualShock` shows the light bar colours on a DualShock 4. ### What Windows needed that Linux did not xmem writes output reports to Linux's `/dev/hidrawN` through Wine's `Z:` drive. Here `dualsense.rs` finds the pad with SetupAPI/`HidD_*`, opens it shared, and writes with `WriteFile`. Three differences came up: - **Report length.** Windows takes writes of exactly the output report length the device declares. A Bluetooth DualSense declares **547 bytes** (its longest report), but the pad reads a 78-byte report with its CRC at byte 74. - Bluetooth reports are now built at 78 bytes, CRC at 74, then padded with zeros to the declared length. - USB reports are padded or cut to the declared length. - **Bluetooth rumble.** xmem's `sony_rumble` put the CRC at the end of the declared length: byte 543 of 547 on Windows. The pad dropped every rumble report. It now goes at byte 74, for the DualSense and DualShock 4 alike. - **Light bar release.** A DualSense's firmware keeps the light bar until it is sent "lightbar setup: light out" (valid_flag2 bit 1, lightbar_setup 0x02). Linux's `hid-playstation` sends that when the pad connects; Windows sends nothing, so our colours were ignored. The output thread now sends it once per connection, then the current colour (the default blue until the title names one). The trigger encodings and their tests are xmem's and are unchanged. **Other changes.** - `tls::near` becomes `pub(crate)` (the notch hook uses it). - HID/SetupAPI features are added to `windows-sys` in `victory-loader` and `victory-hle`. - WASAPI features are added to `windows` in `victory-loader`. - Hook install is wired in `apps/victory/src/run.rs` next to the other `apply_asked` calls. - `-DualSense`/`-DualShock` switches are added to `scripts/play.ps1`. - A "PlayStation controllers" section is added to the README. **Safety.** Every hook checks the title's code before patching. On a build it doesn't recognise, it logs a warning (`not hooked … another build?`) and stays off. Without `VICTORY_DUALSENSE`/`VICTORY_DUALSHOCK`, nothing is patched; only the HID input reader is new. **Using the launcher.** The launcher passes only its own settings to the game and drops `VICTORY_*` variables set in the shell. Put `VICTORY_DUALSENSE=1` in the launcher's extra settings. ### Tested - `cargo test -p victory-loader`: the new modules' 13 tests pass. They include report sizing at the lengths Windows declares (USB 48/64, Bluetooth 547), the light bar release report, and a padded DualShock 4 Bluetooth report. - `cargo test -p victory-hle -- gameinput`: 21 pass, including rumble at 547 bytes for both pads. The 1 hardware test is ignored. - `cargo clippy -p victory-loader -p victory-hle -p victory --all-targets`: no warnings. - `cargo xtask policy`: ok. - `cargo build --locked --release -p victory`: ok. - The four hook sites match a retail executable (read from the file): the pad-effect handler, the rumble emitter, the haptics mixer step and the notch call. - In game, release build, RX 9070 XT, DualSense over Bluetooth: - The pad connects and drives the title over HID. - Adaptive triggers work. - Still to test: - [x] DualSense Bluetooth: rumble, light bar (after the CRC and light bar fixes) - [x] DualSense USB: triggers, light bar, haptics, rumble - [x] Without `VICTORY_DUALSENSE`: pad works, no effects - [ ] Xbox pad still works as before - [ ] DualShock 4: not tested (no hardware) ### Credits Ported from VIctory xmem, at 0fd7614: - The loader modules are by Sam Sepiol and goldfishdev. - The HID pad reader is by delacor and goldfishdev. It was itself ported from delacor/VIctory a9553ae72 (author marquezini). - Trigger effect encodings follow Nielk1's TriggerEffectGenerator. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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/44:upstream-pr/44'
git switch 'upstream-pr/44'

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/44'
git switch 'upstream-pr/44'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/44'
git switch 'upstream-pr/44'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/44'
git switch 'main'
git merge --squash 'upstream-pr/44'
git switch 'main'
git merge --ff-only 'upstream-pr/44'
git switch 'main'
git merge 'upstream-pr/44'
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
ReTerryDavis/ReVIctory!44
No description provided.