Unity-Technologies / InputSystem

An efficient and versatile input system for Unity.
Other
1.43k stars 310 forks source link

FIX: Update DualSense HID support so OutputReports function properly (ISXB-787) #1900

Closed timkeo closed 6 months ago

timkeo commented 6 months ago

Description

The OutputReport size for the DualSense Edge controller is larger than the basic DS controller: 64 bytes vs. 32 bytes. This causes IOCTL commands for setting bumble and light bar values to be rejected by the Windows back-end, i.e. the command buffer size didn't match the feature report.

To fix this problem we need to dispatch output commands with the same buffer size reported by the HID descriptor.

Changes made

I modified all the DualShockHID output commands to take an outputReportSize parameter, which is used instead of the constant kSize when creating the output buffer. This value should, of course come from the controller's HID descriptor. Note that the const kSize is still used (and unchanged) for the field serialization, but the parameter is used for initializing the command buffer.

I added an (internal) property to DualShockGamepad returning said HID descriptor parsed from InputDevice's Description, if the DS controller is connected via HID.

Notes

I verified the fix using the (wired) DualSense Edge and PS4 DualShock controllers. I tested these controllers over Bluetooth, but that still doesn't work; the WriteFile API fails with INVALID_ARGUMENT error, which I guess is expected.

I did not test with a standard DualSense controller (I don't currently have one), and I also didn't test with the PS5 package.

I noticed the SwitchPro HID controller has a similar implementation: output commands use a hard-coded size instead of the value from HID descriptor. It could potentially have a similar issue if Nintendo released a new rev. of the hardware, but it's not worth the risk right now and so I left it alone.

Checklist

Before review:

During merge:

Pauliusd01 commented 6 months ago

I do not have the special controller, adding @stefanunity instead

stefanunity commented 6 months ago

-Tested normal DS, DS Edge and DS4 all wired and they all rumble -don't rumble via BT as mentioned by Tim -there were errors with the PS5 package in the repro project about accessing (internal) properties, but adding latest from their repro made the errors go away