Fix SDL DualSense triggers/touchpad and restore native PS5 haptics/effects #543

Open
github-bot wants to merge 2 commits from github-bot/gh-543 into main AGit
Owner

@⁠wh1te-rgb on GitHub · 2026-12-06 02:19 UTC · original
wh1te-rgb:pr/dualsense-native → main · +1695 −187 · 11 files · 2 commits · open

Fixes two bugs preventing DualSense features from working when SDL3.dll is present, and ports Darner's native PS5 DualSense stack (originally derived from lobomfz/VIctory-xmem#273) for trigger effects, rumble curve, R2 vehicle notch, lightbar sync, and actuator haptics.

Fixes (SDL + PlayStation HID)

  • Start HID thread in SDL mode (sdl.rs, playstation.rs): playstation::pads() was only called by the XInput fallback (Host::pad), so when SDL3.dll handled input, no Sony HID output handle was ever opened and adaptive triggers never fired. Now calls playstation::ensure_running() on 0x054C connect and when install_hook initializes.
  • Route Sony rumble through HID (sdl.rs, playstation.rs): Sending rumble via SDL_RumbleGamepad on Sony pads overwrote DualSense HID adaptive-trigger reports. sdl.rs now detects VID == 0x054C (is_sony) and forwards rumble through playstation::rumble_all() so motors and adaptive triggers share one HID output report. Non-Sony (Xbox) pads are untouched and still use SDL_RumbleGamepad.
  • Map DualSense touchpad click to VIEW (sdl.rs): Adds (20, VIEW) (SDL_GAMEPAD_BUTTON_TOUCHPAD) to BUTTONS alongside (4, VIEW) (back), matching native HID (playstation.rs) so pressing the DualSense touchpad opens the map without affecting Xbox back/View.

Native PS5 DualSense Stack (ported from Darner)

  • Native trigger byte decoder & title lightbar (ps5_trigger.rs, playstation.rs): Replaces the float-based effect() decoder with Darner's native PS5 byte-encoded trigger decoding (Feedback, Weapon, Vibration, MultiFeedback, MultiVibration, Slope, Off on target 2/3), syncs target 4 lightbar colors (TITLE_LIGHTBAR), holds hooked effects until explicit release (0x05), and sends an initial [0xFF; 11] release on connect.
  • PS5 R2 vehicle throttle notch (vehicle_notch.rs): Ports Darner's PS5 R2 notch hook (0x140d1b510 / 0x140d1ab6a) using larp_loader::call_stub.
  • PS5 single-strength rumble curve (ps5_rumble.rs): Ports Darner's PS5 motor split curve (0x140c16170 / 0x1441c5e30) in place of the Xbox motor curve.
  • WASAPI DualSense actuator haptics (haptics.rs, larp-hle/Cargo.toml, apps/larp/src/run.rs): Ports Darner's PadHaptics mixer hook (0x144e59960) playing its stereo submix on channels 3–4 of wired DualSense USB audio via WASAPI (LARP_DS_HAPTICS, LARP_HAPTICS_GAIN_DB).
  • Auto-enable on PS pad detection & Docs (playstation.rs, docs/environment-variables.md): LARP_DS_TRIGGERS and LARP_DS_HAPTICS default to enabled when a PlayStation controller is detected (0 disables).

Verification

  • cargo check -p larp-hle -p larp
  • cargo test -p larp-hle gameinput (43 passed, 2 hardware tests ignored)
  • Tested in-game on Windows with DualSense (touchpad map button, adaptive triggers, driving notch/rumble, and actuator haptics).
**@⁠wh1te-rgb** on GitHub · 2026-12-06 02:19 UTC · [original](https://github.com/gamingwithhomie/larp/pull/543) `wh1te-rgb:pr/dualsense-native` → `main` · +1695 −187 · 11 files · 2 commits · open Fixes two bugs preventing DualSense features from working when `SDL3.dll` is present, and ports Darner's native PS5 DualSense stack (originally derived from `lobomfz/VIctory-xmem#273`) for trigger effects, rumble curve, R2 vehicle notch, lightbar sync, and actuator haptics. ### Fixes (SDL + PlayStation HID) - **Start HID thread in SDL mode (`sdl.rs`, `playstation.rs`)**: `playstation::pads()` was only called by the XInput fallback (`Host::pad`), so when `SDL3.dll` handled input, no Sony HID output handle was ever opened and adaptive triggers never fired. Now calls `playstation::ensure_running()` on `0x054C` connect and when `install_hook` initializes. - **Route Sony rumble through HID (`sdl.rs`, `playstation.rs`)**: Sending rumble via `SDL_RumbleGamepad` on Sony pads overwrote DualSense HID adaptive-trigger reports. `sdl.rs` now detects `VID == 0x054C` (`is_sony`) and forwards rumble through `playstation::rumble_all()` so motors and adaptive triggers share one HID output report. Non-Sony (Xbox) pads are untouched and still use `SDL_RumbleGamepad`. - **Map DualSense touchpad click to `VIEW` (`sdl.rs`)**: Adds `(20, VIEW)` (`SDL_GAMEPAD_BUTTON_TOUCHPAD`) to `BUTTONS` alongside `(4, VIEW)` (`back`), matching native HID (`playstation.rs`) so pressing the DualSense touchpad opens the map without affecting Xbox `back`/`View`. ### Native PS5 DualSense Stack (ported from Darner) - **Native trigger byte decoder & title lightbar (`ps5_trigger.rs`, `playstation.rs`)**: Replaces the float-based `effect()` decoder with Darner's native PS5 byte-encoded trigger decoding (`Feedback`, `Weapon`, `Vibration`, `MultiFeedback`, `MultiVibration`, `Slope`, `Off` on `target 2/3`), syncs `target 4` lightbar colors (`TITLE_LIGHTBAR`), holds hooked effects until explicit release (`0x05`), and sends an initial `[0xFF; 11]` release on connect. - **PS5 R2 vehicle throttle notch (`vehicle_notch.rs`)**: Ports Darner's PS5 R2 notch hook (`0x140d1b510` / `0x140d1ab6a`) using `larp_loader::call_stub`. - **PS5 single-strength rumble curve (`ps5_rumble.rs`)**: Ports Darner's PS5 motor split curve (`0x140c16170` / `0x1441c5e30`) in place of the Xbox motor curve. - **WASAPI DualSense actuator haptics (`haptics.rs`, `larp-hle/Cargo.toml`, `apps/larp/src/run.rs`)**: Ports Darner's `PadHaptics` mixer hook (`0x144e59960`) playing its stereo submix on channels 3–4 of wired DualSense USB audio via WASAPI (`LARP_DS_HAPTICS`, `LARP_HAPTICS_GAIN_DB`). - **Auto-enable on PS pad detection & Docs (`playstation.rs`, `docs/environment-variables.md`)**: `LARP_DS_TRIGGERS` and `LARP_DS_HAPTICS` default to enabled when a PlayStation controller is detected (`0` disables). ### Verification - `cargo check -p larp-hle -p larp` - `cargo test -p larp-hle gameinput` (43 passed, 2 hardware tests ignored) - Tested in-game on Windows with DualSense (touchpad map button, adaptive triggers, driving notch/rumble, and actuator haptics).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 02:19:45 +00:00
Author
Owner

@⁠wh1te-rgb on GitHub · 2026-12-06 02:37 UTC · original

Pushed e673818 to proactively address the real-time safety and hook-boundary points raised on #495 / #496, plus clarify how this relates to those PRs:

  • Non-blocking audio mixer path (haptics.rs): push_nonblocking now uses RING_STATE.try_lock() on the title's mixer thread and counts any contended block (DROPPED_CONTENDED) instead of blocking the audio thread.
  • USB audio haptics vs legacy rumble isolation & write retry (playstation.rs): Added haptics::active() + rumble_report_for_mode so wired USB DualSense audio haptics clear only legacy compatible rumble (0x00) while keeping triggers independent (0x04 | 0x08) and falling back to 0x03 over Bluetooth or when WASAPI haptics is inactive; added possible_triggers + WRITE_MS retry on transient HID write failures.
  • Negative hook boundary tests: Added unit tests across playstation.rs, vehicle_notch.rs, ps5_rumble.rs, and haptics.rs verifying undersized images or mismatched target bytes refuse hook installation cleanly (cargo test -p larp-hle gameinput: 50 passed, 2 hardware tests ignored).

Note: unlike #495/#496, this PR also includes the sdl.rs fixes required when SDL3.dll is loaded (starting Sony HID output via ensure_running(), routing Sony rumble via rumble_all(), and mapping SDL_GAMEPAD_BUTTON_TOUCHPAD -> VIEW without affecting Xbox back).

**@⁠wh1te-rgb** on GitHub · 2026-12-06 02:37 UTC · [original](https://github.com/gamingwithhomie/larp/pull/543#issuecomment-7450080637) Pushed `e673818` to proactively address the real-time safety and hook-boundary points raised on #495 / #496, plus clarify how this relates to those PRs: - **Non-blocking audio mixer path (`haptics.rs`)**: `push_nonblocking` now uses `RING_STATE.try_lock()` on the title's mixer thread and counts any contended block (`DROPPED_CONTENDED`) instead of blocking the audio thread. - **USB audio haptics vs legacy rumble isolation & write retry (`playstation.rs`)**: Added `haptics::active()` + `rumble_report_for_mode` so wired USB DualSense audio haptics clear only legacy compatible rumble (`0x00`) while keeping triggers independent (`0x04 | 0x08`) and falling back to `0x03` over Bluetooth or when WASAPI haptics is inactive; added `possible_triggers` + `WRITE_MS` retry on transient HID write failures. - **Negative hook boundary tests**: Added unit tests across `playstation.rs`, `vehicle_notch.rs`, `ps5_rumble.rs`, and `haptics.rs` verifying undersized images or mismatched target bytes refuse hook installation cleanly (`cargo test -p larp-hle gameinput`: 50 passed, 2 hardware tests ignored). Note: unlike #495/#496, this PR also includes the `sdl.rs` fixes required when `SDL3.dll` is loaded (starting Sony HID output via `ensure_running()`, routing Sony rumble via `rumble_all()`, and mapping `SDL_GAMEPAD_BUTTON_TOUCHPAD` -> `VIEW` without affecting Xbox `back`).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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