Skip to content

usbd: Implement libusb passthrough#2271

Merged
georgemoralis merged 8 commits intoshadps4-emu:mainfrom
deReeperJosh:usbd-libusb
Mar 31, 2025
Merged

usbd: Implement libusb passthrough#2271
georgemoralis merged 8 commits intoshadps4-emu:mainfrom
deReeperJosh:usbd-libusb

Conversation

@deReeperJosh
Copy link
Contributor

@deReeperJosh deReeperJosh commented Jan 29, 2025

Re-opening pull request that I had previously opened on accident to implement libusb passthrough for the USBD library.

It appears that the free bsd build that orbis os is based off of used libusb for it's usb transactions (seen here), so we can use libusb as a submodule, and pass on all functions and parameters directly to libusb.

I can't take full credit for this code, many thanks go to Osyotr in the discord server who posted this code stub, I just needed to add the submodule.

The only major differences from the linked code stub are that I return the return value from libusb if the return code is > 0 (for methods where a return value > 0 is expected), and in the sceUsbdClaimInterface method, I check to see if a kernel driver is active before claiming the interface (required on linux and macos before performing device transactions)

I have tested this as working for Skylanders Trap Team, Skylanders Superchargers and Skylanders Imaginators on MacOS - would like some help testing more usb passthrough games (Lego Dimensions or Disney Infinity) as well as any users on Windows/Linux. Just an FYI that users on Windows will need to install winUSB as a driver for their chosen passthrough device, which can be done using Zadig

@ElBread3
Copy link
Contributor

ElBread3 commented Jan 29, 2025

Lego Dimensions has this block of code, taken from Ghidra:

iVar13 = sceUsbdKernelDriverActive(*puVar3,0);
if ((iVar13 != 1) ||
   ((iVar13 = sceUsbdDetachKernelDriver(*puVar3,*pcVar1), iVar13 != 0 ||
    (iVar13 = sceUsbdClaimInterface(*puVar3), iVar13 != 0)))) {
  sceUsbdResetDevice(*puVar3);
  puts("USB DEVICE RESET ON INIT 1");
  goto LAB_01517144;
}

which, since on Windows sceUsbdDetachKernelDriver will error LIBUSB_ERROR_NOT_SUPPORTED, will need handled on unsupported platforms to pass this.

@ElBread3
Copy link
Contributor

Now since sceUsbdKernelDriverActive returns 0 it still doesn't pass this condition, so like the condition says it will need to return 1. For future proofing for games that may check sceUsbdKernelDriverActive after detaching it and think it's still attached though, I'd recommend storing the state of attachment in a variable and returning that.

@deReeperJosh
Copy link
Contributor Author

deReeperJosh commented Jan 29, 2025

libusb_kernel_driver_active returns 0 if no kernel driver is active though - not sure why I would pass 1 back? The initial (iVar13 != 1) will return true, which then means it will go straight to the sceUsbdResetDevice line. Unless it is unwanted behaviour to be heading to the sceUsbdResetDevice line, because the game is assuming it will return 1?

@ElBread3
Copy link
Contributor

Unless it is unwanted behaviour to be heading to the sceUsbdResetDevice line, because the game is assuming it will return 1?

Exactly.

@deReeperJosh
Copy link
Contributor Author

This is an example of libusb in action, getting past the no portal screen in Skylanders: Trap Team; https://youtu.be/G8ydGRB1pJw

@georgemoralis
Copy link
Collaborator

looking nice , i will try it on windows as well :)

@georgemoralis
Copy link
Collaborator

Ok it seems that it doesn't work on windows ;/

εικόνα

@deReeperJosh
Copy link
Contributor Author

Welp, at least it doesn't crash. Will see if I can test on Windows to see why it doesn't work there, my assumption would be some byte order issue

@georgemoralis
Copy link
Collaborator

it stucks here in main as well

@deReeperJosh
Copy link
Contributor Author

I assume you had a USB portal plugged in? On windows, winUSB drivers will need to be installed as well, the default HID drivers don't work with libusb

@georgemoralis
Copy link
Collaborator

oh need to have a USB portal to pass it :? (thought it was just skipping it)

@deReeperJosh
Copy link
Contributor Author

Yes sorry should have made that clear - the games will require a USB peripheral like you would use on your PS4 normally to be attached, specifically for Trap Team in order to get past the please plug in a portal screen it requires a portal plugged in

@deReeperJosh
Copy link
Contributor Author

Tested Windows and got in game on Skylanders Imaginators, had game crashes with the portal plugged in on Trap Team and Superchargers, Swap Force crashes with or without portal plugged in

image

@valjbp
Copy link

valjbp commented Jan 31, 2025

Tested on Windows with LEGO Dimensions, toypad was not detected and the game reached the point where it asks for it.
image

@deReeperJosh
Copy link
Contributor Author

What driver did you have installed for your ToyPad?

@valjbp
Copy link

valjbp commented Jan 31, 2025

WinUSB, tried libusb too but doesn't seem to detect.
image

@squidbus
Copy link
Collaborator

squidbus commented Feb 1, 2025

Not having much luck with LEGO Dimensions either, on Mac. I'm also getting occasional crashes while the game boots in darwin_reenumerate_device, called from sceUsbdResetDevice, here:

(*dpriv->device)->GetConfigurationDescriptorPtr (dpriv->device, i, &cached_configuration);

With dpriv->device being null.

@deReeperJosh
Copy link
Contributor Author

Thanks for testing, might need to get myself the Dimensions starter set for PS4 to do some testing locally

@georgemoralis
Copy link
Collaborator

this needs some testing :D

@deReeperJosh
Copy link
Contributor Author

I tried to test Lego Dimensions on my Mac, but the game crashes immediately after opening so will need some more time to test on a Windows machine

@georgemoralis
Copy link
Collaborator

any update on this?

@valjbp
Copy link

valjbp commented Mar 28, 2025

I'd test it for LEGO Dimensions on windows but I'm not specifically great on building the emulator correctly. If someone can provide me with a build of the emulator that includes this modification I can go ahead and test as I have the game

@georgemoralis
Copy link
Collaborator

i did rebase it , you will find a link here in a while

@Graubek
Copy link

Graubek commented Mar 29, 2025

Doesn't detect on my Windows 11 system
Zrzut ekranu 2025-03-29 131728

@valjbp
Copy link

valjbp commented Mar 30, 2025

Where am I supposed to download this branch? I can't find the link you mentioned

@georgemoralis
Copy link
Collaborator

@georgemoralis
Copy link
Collaborator

testers you can also test games that were spamming usb lib stuff (driverclub for example)

@georgemoralis
Copy link
Collaborator

tested a bit on windows , doesn't seem to create issues in games that calls usb , so let's get it in main so it can be tested :D

@georgemoralis georgemoralis merged commit 7533206 into shadps4-emu:main Mar 31, 2025
12 checks passed
@valjbp
Copy link

valjbp commented Mar 31, 2025

Didn't work for me on Windows either, here's the log.
shad_log.txt

kalaposfos13 pushed a commit to kalaposfos13/shadPS4 that referenced this pull request Apr 1, 2025
* usbd: Implement libusb passthrough

* clang-format

* only do kernel activities on non-windows

* use variable to represent "fake" windows kernel driver

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
@gamerbross
Copy link

It's not working for me on Windows, trying Skylanders: Trap Team with its portal.
(The log doesn't show anything related to usb)

AzaharPlus pushed a commit to AzaharPlus/shadPS4Plus that referenced this pull request Apr 22, 2025
* usbd: Implement libusb passthrough

* clang-format

* only do kernel activities on non-windows

* use variable to represent "fake" windows kernel driver

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
# Conflicts:
#	CMakeLists.txt
alextrack2013 added a commit to alextrack2013/shadPS4 that referenced this pull request Apr 24, 2025
alextrack2013 pushed a commit to alextrack2013/shadPS4 that referenced this pull request May 5, 2025
* usbd: Implement libusb passthrough

* clang-format

* only do kernel activities on non-windows

* use variable to represent "fake" windows kernel driver

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
Change-Id: I63be75d7d7289c367c995e2878539b400ee93502
alextrack2013 pushed a commit to alextrack2013/shadPS4 that referenced this pull request May 9, 2025
* usbd: Implement libusb passthrough

* clang-format

* only do kernel activities on non-windows

* use variable to represent "fake" windows kernel driver

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
Change-Id: I63be75d7d7289c367c995e2878539b400ee93502
rainmakerv3 pushed a commit to rainmakerv3/shadPS4 that referenced this pull request Jun 7, 2025
* usbd: Implement libusb passthrough

* clang-format

* only do kernel activities on non-windows

* use variable to represent "fake" windows kernel driver

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
@deReeperJosh deReeperJosh deleted the usbd-libusb branch October 24, 2025 13:10
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

Successfully merging this pull request may close these issues.

7 participants