Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full support in Unity #33

Open
devingDev opened this issue May 22, 2024 · 9 comments
Open

Full support in Unity #33

devingDev opened this issue May 22, 2024 · 9 comments

Comments

@devingDev
Copy link

devingDev commented May 22, 2024

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
Copy link
Author

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
Copy link
Author

devingDev commented May 22, 2024

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
Copy link
Author

devingDev commented May 22, 2024

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
Copy link

DJm00n commented May 24, 2024

@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
Copy link
Author

devingDev commented May 24, 2024

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
Copy link

DJm00n commented May 24, 2024

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

@devingDev
Copy link
Author

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
Copy link

DJm00n commented May 25, 2024

@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 Jays2Kings/DS4Windows#123 (comment)

@devingDev
Copy link
Author

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

@devingDev devingDev reopened this May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants