-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Fix gamepad L2/R2 in games #5623
Conversation
it works perfectly (on uhid), thank you. public final class UhidManager {
ByteBuffer buf = ByteBuffer.allocate(280 + reportDesc.length).order(ByteOrder.nativeOrder());
buf.putInt(UHID_CREATE2);
- String actualName = name.isEmpty() ? "scrcpy" : "scrcpy: " + name;
+ int vid = 0;
+ int pid = 0;
+ String actualName;
+ if ("Xbox One Controller".equals(name)) {
+ actualName = "Microsoft X-Box 360 Pad";
+ vid = 0x045e;
+ pid = 0x028e;
+ } else {
+ actualName = name.isEmpty() ? "scrcpy" : "scrcpy: " + name;
+ }
byte[] utf8Name = actualName.getBytes(StandardCharsets.UTF_8);
int len = StringUtils.getUtf8TruncationIndex(utf8Name, 127);
assert len <= 127;
@@ -183,8 +192,8 @@ public final class UhidManager {
buf.putShort((short) reportDesc.length);
buf.putShort(BUS_VIRTUAL);
- buf.putInt(0); // vendor id
- buf.putInt(0); // product id
+ buf.putInt(vid); // vendor id
+ buf.putInt(pid); // product id
buf.putInt(0); // version
buf.putInt(0); // country;
buf.put(reportDesc); aoa is gonna be broken as long as we cant change the vid:pid on it (or you could revert back to the old descriptor for aoa). im doing the "if ("Xbox One Controller".equals(name)){" check so i dont affect other devices like a mouse or a keyboard, i dont know if it would work for people with other controllers (or other os). but here's the modified server file with that check removed if anyone wants to try it (probably breaks the uhid keyboard): |
What if you keep 0:0, does it also work? |
well, yes, but the rstick doesnt work and the triggers act as the rstick instead. |
Is that also true with "Game Controller Tester" ( Can it be related to your changes in .kl files? (#5362 (comment)) |
yup, its the same, which gamepad(s) did you try?
nope, i reverted all of those changes, you dont need keylayout modifications to use xbox360 vid:pids with this update. |
With a PS4 controller, but that should not make any difference, since scrcpy uses the events received from SDL to generate UHID events. The difference is probably the drivers on the device. On my devices, it works correctly with both 0:0 or 045e:028e (but not with the ids of the PS4 controller, because it is expected to behave differently I guess). |
how do games react to input? do they see your gamepad as an xbox or a ps one? |
With 054c:0ce6, in Gamepad Tester, it is detected as a "PS5 Controller". With 0:0 or 045e:028e, it works correctly. |
I will add an option |
Or just force |
I updated the PR. Please test the latest version. Here are binaries for Linux and Windows:
|
@LHLaurini @yume-chan I'm also interested in your feedback if you have some time, since you worked on gamepads in the past 😉 Thank you. |
it works perfectly, but i think we should change the controller name as well, since some games seem to pay attention to that: diff --git a/app/src/uhid/gamepad_uhid.c b/app/src/uhid/gamepad_uhid.c
index 2a063af5..b9016b39 100644
--- a/app/src/uhid/gamepad_uhid.c
+++ b/app/src/uhid/gamepad_uhid.c
@@ -36,7 +36,7 @@ sc_gamepad_uhid_send_open(struct sc_gamepad_uhid *gamepad,
msg.uhid_create.id = hid_open->hid_id;
msg.uhid_create.vendor_id = SC_GAMEPAD_UHID_VENDOR_ID;
msg.uhid_create.product_id = SC_GAMEPAD_UHID_PRODUCT_ID;
- msg.uhid_create.name = hid_open->name;
+ msg.uhid_create.name = "Microsoft X-Box 360 Pad";
msg.uhid_create.report_desc = hid_open->report_desc;
msg.uhid_create.report_desc_size = hid_open->report_desc_size;
diff --git a/server/src/main/java/com/genymobile/scrcpy/control/UhidManager.java b/server/src/main/java/com/genymobile/scrcpy/control/UhidManager.java
index 1d7678ec..c4867a3f 100644
--- a/server/src/main/java/com/genymobile/scrcpy/control/UhidManager.java
+++ b/server/src/main/java/com/genymobile/scrcpy/control/UhidManager.java
@@ -174,7 +174,7 @@ public final class UhidManager {
ByteBuffer buf = ByteBuffer.allocate(280 + reportDesc.length).order(ByteOrder.nativeOrder());
buf.putInt(UHID_CREATE2);
- String actualName = name.isEmpty() ? "scrcpy" : "scrcpy: " + name;
+ String actualName = name.isEmpty() ? "scrcpy" : name;
byte[] utf8Name = actualName.getBytes(StandardCharsets.UTF_8);
int len = StringUtils.getUtf8TruncationIndex(utf8Name, 127);
assert len <= 127; |
Did you observe a difference in behavior with just a different name? If possible, I'd like to keep exposing the real controller name, but if it causes issues, ok. |
I believe having that option would only be useful for games and controllers that support stuff like gyro, adaptive triggers and haptic feedback. While I did find some references online saying some games support these features, I didn't find which games support them. In any case, I don't think scrcpy currently supports these features anyway, so it doesn't matter for now. |
yes, in human fall flat (#5362), the game didnt recognize the controller cause of its name, changing the name fixed the issue. |
Some games do not work without a known gamepad name. Fixes #5362 <#5362> Refs #5623 comment <#5623 (comment)> PR #5623 <#5623> Signed-off-by: Romain Vimont <[email protected]>
@Withoutruless Thank you 👍 I added a commit under your authorship: 7418fd0. (and I added a log when a gamepad is added or removed: 548d2c7) Please confirm that everything works. |
(scrcpy 3.1 including this PR is ready. I will publish it soon 🚀) |
Use two separate callbacks for gamepad device added and gamepad device removed. It looks cleaner. PR #5623 <Genymobile/scrcpy#5623>
Use Z and Rz for L2/R2, which are more widely supported than Brake/Accelerator. The right stick must then be bound to Rx and Ry. Fixes #5362 <Genymobile/scrcpy#5362> PR #5623 <Genymobile/scrcpy#5623>
By default, initialize axis to 0, which is represented by 0x8000 as a 16-bit unsigned value. PR #5623 <Genymobile/scrcpy#5623>
Let the client choose the USB ids, that it transmits in UHID_CREATE requests. PR #5623 <Genymobile/scrcpy#5623>
Use the vendorId and productId of an Xbox 360 controller for better support (the HID gamepad protocol used in scrcpy is similar to that of the Xbox 360 controller). Fixes #5362 <Genymobile/scrcpy#5362> PR #5623 <Genymobile/scrcpy#5623>
@rom1v Hello! It seems there's still a problem with some gamepads. The triggers on Logitech F310 don't work in either mode, and the Y and X buttons are for some reason swapped. Tested on 3.1 release version and gamepad_fixes version from this conversation. On hardwaretester.com website opened on my phone I can see that pulling LT does nothing, pulling RT changes Axis 3 (RS Y-axis) value from -1 to 1. B6 and B7 (correct inputs for LT/RT) don't activate at all. Other inputs work fine. On PC (win-64) this gamepad is identified as Xbox 360 Controller and on my phone as ffff, if it helps. Could you please look into it? |
Fix #5362 (to be tested)