Ohjurot / DualSense-Windows

Windows API for the PS5 DualSense controller
Other
342 stars 38 forks source link

Full support in Unity #33

Open devingDev opened 4 months ago

devingDev commented 4 months ago

Hello and thanks for your work!

Sorry if this is the wrong place to ask but: I want to try to have DualSense support in Unity Editor as well as in Build (Windows PC only for now since it would be too much work otherwise)

I tried this library: https://github.com/nullkal/UniSense/

Sadly it does not work fully and the repo seems to be unmaintained. The Problems (btw I'm on Unity 2022.3.28f1) :

In Unity Editor: The adaptive triggers seem to work, vibration however does not. In PC Build: Adaptive triggers do not work, left and right vibrations seem to work (not sure if there is more to haptic feedback than those two) Touchpad color works in both cases.

Do you have any ideas how I could fix that, maybe using this library? I read a bit through the PDF and saw you have to use lib files and I'm not sure if that works in Unity Also I saw this https://docs.unity3d.com/Manual/NativePlugins.html but I'm really overwhelmed and not sure if I can use it this way... Could you maybe help?

devingDev commented 4 months ago

Actually got something working now using HIDAPI library and grabbed the needed infos from here and elsewhere to get the correct offsets and ids to output the stuff. (annoying to find this info) Well I didn't do input... but after some tinkering and using this hdapi I think I could actually just pop your dll in and use it as well 😅

devingDev commented 4 months ago

I'm still wondering if haptic feedback has more to it than just these two motors (left and right)? any insight on this? I read something about audio channels and such but not sure what that is meant for nor how to go about using that.. 🤔 what do i have to do in order to do it?

As an example: ghost of tsushima when you ride on your horse it makes vibrations according to the steps.

devingDev commented 4 months ago

After further testing, it is rather "simple" as sending audio data with certain channels to the audio device of the controller (the one with DualSense in sound panel). Used CSCore and made it output as 4 or 6 or 8 channels using the matrix and it vibrates now but also sometimes you can hear the sound through the controller.

Anyway I can not seem to combine this with the HIDAPI writes because the audio one stops working if i do send a controller output report (reading seems fine). Also it won't work until I reconnect the controller usb (+ also restart unity, a seperate vs project works fine after reconnect without restart) ALTHOUGH(!): without reconnecting I can open Ghost Of Tsushima and the haptics work in there..? Thanks sony for not making it public 🤦

Any ideas why this would be and how to stop it from happening so I can use the write to do stuff like adaptive triggers still but also keep using the audio haptic feedback at the same time?

Edit: To be precise, if at any time I call the hid write to the dualsense controller then no audio haptics will work until i reconnect the controller. This is even if I don't play any audio haptics at all, only send output report, and then later only play audio haptics which then don't work. (writing with hidapi still works though.. adaptive triggers and such) Also haptics don't work at all then if I play audio and at the same time try writing the 48 bytes stuff with adaptive triggers (and even rumble motors). Only works if i disable the audio playback part, even without reconnecting. Reading still works fine.

DJm00n commented 4 months ago

@devingDev it looks like that haptics type (audio haptics or "compatible" rumble with 0x00-0xff values) is controlled by the DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT flag (‎DualSenseHIDOutputReport::Flags1.MainMotors2 in UniSense) in the first byte of output report. UniSense always sets it so audio haptics is disabled.

Additional info: https://github.com/torvalds/linux/blob/master/drivers/hid/hid-playstation.c#L1265-L1274 https://github.com/libsdl-org/SDL/blob/main/src/joystick/hidapi/SDL_hidapi_ps5.c#L681-L702 https://controllers.fandom.com/wiki/Sony_DualSense#Output_Reports (named as EnableRumbleEmulation and UseRumbleNotHaptics here)

without reconnecting I can open Ghost Of Tsushima and the haptics work in there..? Thanks sony for not making it public 🤦

this game is using proprietary library for interaction with DualSense. it is available only for Sony partners.

devingDev commented 4 months ago

Thanks @DJm00n ! I already used the game (Ghost of Tsushima) with Wireshark + USBPcap and now I got adaptive triggers + haptic feedback working over an usb connection! Wireless the audio haptic feedback isn't working because its not shown as a speaker device in Windows when connected via Bluetooth. Not sure how the PS5 does it actually anyway. Although this page does suggest it may be sent via the same Bluetooth device(?)

https://controllers.fandom.com/wiki/Sony_DualSense#Bluetooth

DJm00n commented 4 months ago

Bluetooth haptics on DualSense is only working on actual PS5. AFAIK on PC it is not reversed yet.

devingDev commented 4 months ago

Yeah apparently not even in their own Remote play... I'm wondering if it's rather simple of just sending specific stuff to the same bluetooth hid device. Sadly no ps5 here (and also no way to mitm it anyway) to reverse it

DJm00n commented 4 months ago

@devingDev I’d say it is more because of marketing reasons - advanced audio features of DualSense/DualShock4 are for actual console users. Just speculation.

PS: some work was done on this here https://github.com/Pecacheu/dualshock and https://github.com/Jays2Kings/DS4Windows/issues/123#issuecomment-233172550

devingDev commented 4 months ago

Interesting.. no dualsense mentions but i assume it uses almost the same stuff. 🤔