Input: read DualSense pads over HID when XInput has none #150
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!150
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-150"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Kam471 on GitHub · 2026-11-24 00:58 UTC · original
Kam471:input/dualsense-hid→main· +550 −13 · 5 files · 2 commits · openA DualSense is not an XInput device, so the title never saw one even though GameInput reports pads. This reads the pad's HID input reports on a background thread and exposes them in the same shape as the XInput source, on slot 0 when no XInput pad answers there.
USB input reports (
0x01, 64 bytes) and Bluetooth reports (0x31, 78 bytes) place the buttons and triggers at different offsets, so the fields are read through Windows' HID parser (HidP_GetUsages/HidP_GetUsageValue) by declared usage instead of fixed offsets. That also covers the DualSense Edge's report. Mapping: square/cross/circle/triangle to X/A/B/Y, L1/R1, create/options, L3/R3, PS to Menu, hat to D-pad, sticks, analog triggers.Not included: touchpad, gyro and lightbar (the title's pad surface has no axes for them), and rumble back to the pad.
Keyboard
Onow also plays Circle (B) next to Enter's Cross; the README input table is updated.Tests run:
cargo test -p victory-hle --lib dualsense(6 passed, 1 ignored hardware probe)cargo test -p victory-hle(92 passed, 1 ignored)cargo build --release -p victoryVerified live on Windows with a DualSense connected: the title registered a gamepad callback (kind 0x40000), pad 0 connected, and real button presses and analog triggers arrived.
@CIS-C0 on GitHub · 2026-11-24 02:01 UTC · original
Tested this with a wired DualShock 4 (054C:05C4) after adding its product ids. Its HID descriptor declares the same usages this reads (X/Y/Z/Rz sticks, Rx/Ry triggers, hat, buttons 1–14 in the same order), so nothing else needed to change:
Results on
34a0823+ that change (i5-11400F, RTX 2060, Windows 11 build 28000, toolchain 1.98.1 msvc):cargo test -p victory-hle: 92 passed, 1 ignored; the ignored probelists_and_opens_hid_devicespasses and opens the DS4 (report length 64).VICTORY_PAD_LOG=1:DualSense connected over HID product=0x05c4 report=64, pad 0 connects and the keyboard stand-in disconnects. Pressing every button in the menu gave all 14 bits (union0x3fff), triggers reach 1.00, sticks −1 … 0.97, idle sticks within 0.2 of centre.Not tested: the 09CC model, the USB adaptor, a DS4 over Bluetooth.
If you add it, the log line and module name say "DualSense" for a DS4 too; something like "PlayStation pad" would read better.
@Kam471 on GitHub · 2026-11-24 02:09 UTC · original
Thanks for testing the DualShock 4 and for the exact diff. I've added it: 0x05c4 (DS4), 0x09cc (DS4 v2) and 0x0ba0 (USB wireless adaptor) now go through the same usage-based HID read, with a unit test for the product ids. The log line and module docs now say "PlayStation pad" instead of DualSense, so a DS4 report isn't mislabelled. The 09cc/0ba0 variants are untested on hardware here; your 05c4 result covers the report layout they share.
@crissuper20 on GitHub · 2026-11-24 21:30 UTC · original
Crash: the HID device paths passed to
CreateFileWaren't NUL-terminated.In
device_paths()(crates/victory-hle/src/modules/dualsense.rs), the path is copied without its terminator:Then
open_pad()callsCreateFileW(path.as_ptr(), …), which reads until it finds a 0 u16. That runs past the end of theVec's allocation. It works when the next bytes happen to be zero, and crashes when the allocation ends at a page boundary.Seen in a run: Forge
fd79f92(#1624, which includes this PR atfe014c1), Windows 11 LTSC 24H2, i5-4690, no PlayStation pad connected, only a Logitech USB device and the usual HID devices. About 15 s after the world load starts, theplaystation-padthread dies with:The faulting address is page-aligned, which fits a read just past the end of a heap allocation. Every machine enumerates HID devices here, with or without a pad, so this can hit anyone running a build that includes this PR.
Fix: keep the terminator, e.g.
Verified: with only that change applied to the same Forge build, the
playstation-padcrash is gone in a rerun on the same machine.(A smaller nit nearby:
bufferis aVec<u8>cast to*mut SP_DEVICE_INTERFACE_DETAIL_DATA_W, which needs 4-byte alignment. AVec<u32>ofrequired.div_ceil(4)elements would make that cast sound.)AI-assisted (Claude Code)
@Marvisak on GitHub · 2026-11-25 00:18 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-hle/src/modules/mod.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
@WHOISJARDAS on GitHub · 2026-11-25 12:35 UTC · original
A bug in
device_paths(atfe014c1): each path is copied without its NUL (std::slice::from_raw_parts(path, len).to_vec()), andopen_padpasses it toCreateFileW, which reads up to a NUL, past the end of the copy. With no DualSense connected the scan runs every 2 s, and once a copy ends a heap page the read faults. It happened once 231 s into a run in a fork that carries this PR (RX 9070 XT, no DualSense):Fix: keep the NUL,
let mut path = ...to_vec(); path.push(0); paths.push(path);(and drop it where a path is printed). A test that every returned path ends in exactly one NUL fails without that and passes with it: Belobug/VIctory-Belobug-AMD#40.AI-assisted (Claude Code).
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.Merge
Merge the changes and update on Forgejo.