isXander / Controlify

Another controller mod - for fabric!
https://www.isxander.dev/mods/controlify
GNU Lesser General Public License v3.0
138 stars 29 forks source link

[Bug] Controllers not detected properly on macOS #168

Closed andre4ik3 closed 5 months ago

andre4ik3 commented 11 months ago

Current Behaviour

The current library for detecting controllers (hid4java) is shipped only with an x86_64 version. This doesn't work on new Apple silicon Macs - see logs for what appears on game startup. This leads to controllers showing up as a "joystick" and having no bindings by default (However, vibration does work, also connecting controller with wire leads to no detection at all - not sure if it's a separate bug). I managed to input all my own bindings to make it playable, however all button indicators will have a "missing texture" instead of the proper controller button (sometimes with a number like "2" or "6" over them).

Expected Behaviour

You should ship an arm64 version of the hid4java library, so newer computers can load it properly and controllers can be properly detected on Mac. This means users won't have to manually configure all controller inputs, controllers will work out of the box. Also I think this will make controller button images load properly (the joystick ones are just missing textures I guess).

Screenshots

Joystick warning Missing textures

Reproduction Steps

  1. (Do this on an Apple silicon Mac)
  2. Load up Fabric 1.20.2 with YACL, Fabric API, and Controlify installed.
  3. Look at logs as the game loads. Observe the error as stated below.
  4. Plug in / connect controller via bluetooth.
  5. Observe how Controlify thinks it's a joystick in the image.
  6. Do the calibration, try using the controller to exit out of it.
  7. Observe how nothing happens because no button is bound yet. (However pushing buttons and moving joysticks does hide the mouse and switch to controller mode)
  8. Go to settings, bind all the stuff. Now the controller is usable, but...
  9. Observe how the button glyphs are all missing textures.

Logs

Full log: https://mclo.gs/vxJkWpc

In particular:

[15:10:19] [Render thread/ERROR]: Failed to start controller HID service! If you are on Linux using flatpak or snap, this is likely because your launcher has not added libusb to their package.
...
Caused by: java.lang.UnsatisfiedLinkError: dlopen(/Users/craftsman/Library/Caches/JNA/temp/jna2809707430857862433.tmp, 0x0009): tried: '/Users/craftsman/Library/Caches/JNA/temp/jna2809707430857862433.tmp' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/craftsman/Library/Caches/JNA/temp/jna2809707430857862433.tmp' (no such file), '/Users/craftsman/Library/Caches/JNA/temp/jna2809707430857862433.tmp' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

And then missing textures:
[15:10:57] [Render thread/WARN]: Failed to load texture: controlify:textures/gui/joystick/xbox_one/button_button-0.png
java.io.FileNotFoundException: controlify:textures/gui/joystick/xbox_one/button_button-0.png

Mod Version

1.7.0 Beta 2 on 1.20.2

Controller

Xbox Elite Series 2

Bluetooth

Operating System

macOS

ARM

Additional Information

Reproducible on the following:

Just to make sure...

isXander commented 11 months ago

This is not the fault of HID4Java, as SDL is used as a backup on macOS arm64. In fact controller detection is not responsible for determining if a connected controller is a joystick or if it's a gamepad. That comes down to underlying system drivers of your computer. Missing textures for joysticks are known, I just haven't got round to implementation.

andre4ik3 commented 11 months ago

Sorry, I just assumed it was hid4java since that was what was mentioned in the error. macOS correctly sees the controller and can vibrate it correctly and even lets me remap buttons (didn't know macOS could do this!). And in the log it says:

[15:10:21] [Render thread/INFO]: Using SDL to identify controller type.
[15:10:21] [Render thread/WARN]: No joystick mapping found for controller type: 'unmapped' - using unmapped
[15:10:21] [Render thread/INFO]: Controller found: 'Xbox Controller'#0-joy (0000045e, 00000b22: Xbox Controller)

Which confirms the mod uses SDL and not hid4java. Is it possible that the Elite Series 2 is not recognized as an Xbox controller in the mod database?

Controller detected

Controller remap menu

More remap

(Sorry for the delayed post, was meant to reply an hour ago, but got distracted and forgot about it for a while after I restarted my computer)

(Also another weird thing - it says paddle remaps are only available when no profile is active, yet when I put the active profile to none, nothing changes. Unrelated macOS bug? But nevertheless it correctly recognizes it as an Elite V2 since it calls it out by name)

andre4ik3 commented 11 months ago

Additional context:

kurisubrooks commented 10 months ago

Having the same issue with the Nintendo Switch Pro Controller using near-identical specs to the above comment

I've tried both with Bluetooth and connected via USB. I also tried using the Steam Gamepad Input workaround (launching Prism Launcher/Minecraft through Steam Big Picture), but even the Steam Gamepad (Emulated) Controller isn't recognised, though Steam correctly identifies the controller and all inputs work correctly. GamePadTester also reports the controller is recognisable and all inputs are correct.

image image

image

Relevant logs:

[09:32:11] [Render thread/INFO]: Pre-initializing Controlify...
[09:32:11] [Render thread/ERROR]: Failed to start controller HID service! If you are on Linux using flatpak or snap, this is likely because your launcher has not added libusb to their package.
org.hid4java.HidException: Hidapi did not initialise: dlopen(/Users/kurisu/Library/Caches/JNA/temp/jna7849689221124036488.tmp, 0x0009): tried: '/jna7849689221124036488.tmp' (no such file), '/Users/kurisu/Library/Caches/JNA/temp/jna7849689221124036488.tmp' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/kurisu/Library/Caches/JNA/temp/jna7849689221124036488.tmp' (no such file), '/Users/kurisu/Library/Caches/JNA/temp/jna7849689221124036488.tmp' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
    at org.hid4java.HidDeviceManager.<init>(HidDeviceManager.java:87) ~[org_hid4java_hid4java-0.7.0-52dfcbae6ead1805.jar:?]
    at org.hid4java.HidServices.<init>(HidServices.java:82) ~[org_hid4java_hid4java-0.7.0-52dfcbae6ead1805.jar:?]
    at org.hid4java.HidManager.getHidServices(HidManager.java:75) ~[org_hid4java_hid4java-0.7.0-52dfcbae6ead1805.jar:?]
    at dev.isxander.controlify.hid.ControllerHIDService.start(ControllerHIDService.java:43) ~[Controlify-1.7.0-beta.3+1.20.2.jar:?]
    at dev.isxander.controlify.Controlify.preInitialiseControlify(Controlify.java:103) ~[Controlify-1.7.0-beta.3+1.20.2.jar:?]
    at dev.isxander.controlify.ControlifyEntrypoint.onInitializeClient(ControlifyEntrypoint.java:8) ~[Controlify-1.7.0-beta.3+1.20.2.jar:?]
    at net.fabricmc.loader.impl.FabricLoaderImpl.invokeEntrypoints(FabricLoaderImpl.java:383) ~[fabric-loader-0.14.23.jar:?]
    at net.fabricmc.loader.impl.game.minecraft.Hooks.startClient(Hooks.java:53) ~[fabric-loader-0.14.23.jar:?]
    at net.minecraft.class_310.<init>(class_310.java:466) ~[client-intermediary.jar:?]
    at net.minecraft.client.main.Main.main(Main.java:214) ~[minecraft-1.20.2-client.jar:?]
    at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:468) ~[fabric-loader-0.14.23.jar:?]
    at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) ~[fabric-loader-0.14.23.jar:?]
    at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) ~[fabric-loader-0.14.23.jar:?]
    at org.prismlauncher.launcher.impl.StandardLauncher.launch(StandardLauncher.java:88) ~[NewLaunch.jar:?]
    at org.prismlauncher.EntryPoint.listen(EntryPoint.java:126) ~[NewLaunch.jar:?]
    at org.prismlauncher.EntryPoint.main(EntryPoint.java:71) ~[NewLaunch.jar:?]
Caused by: java.lang.UnsatisfiedLinkError: dlopen(/Users/kurisu/Library/Caches/JNA/temp/jna7849689221124036488.tmp, 0x0009): tried: '/jna7849689221124036488.tmp' (no such file), '/Users/kurisu/Library/Caches/JNA/temp/jna7849689221124036488.tmp' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/kurisu/Library/Caches/JNA/temp/jna7849689221124036488.tmp' (no such file), '/Users/kurisu/Library/Caches/JNA/temp/jna7849689221124036488.tmp' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
    at com.sun.jna.Native.open(Native Method) ~[jna-5.13.0.jar:?]
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:298) ~[jna-5.13.0.jar:?]
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:483) ~[jna-5.13.0.jar:?]
    at com.sun.jna.Library$Handler.<init>(Library.java:197) ~[jna-5.13.0.jar:?]
    at com.sun.jna.Native.load(Native.java:622) ~[jna-5.13.0.jar:?]
    at com.sun.jna.Native.load(Native.java:596) ~[jna-5.13.0.jar:?]
    at org.hid4java.jna.HidrawHidApiLibrary.<clinit>(HidrawHidApiLibrary.java:36) ~[org_hid4java_hid4java-0.7.0-52dfcbae6ead1805.jar:?]
    at org.hid4java.jna.HidApi.init(HidApi.java:105) ~[org_hid4java_hid4java-0.7.0-52dfcbae6ead1805.jar:?]
    at org.hid4java.HidDeviceManager.<init>(HidDeviceManager.java:84) ~[org_hid4java_hid4java-0.7.0-52dfcbae6ead1805.jar:?]
    ... 15 more

[09:32:17] [Render thread/INFO]: Initializing Controlify...
[09:32:17] [Render thread/INFO]: Loading Controlify config...
[09:32:17] [Render thread/INFO]: Initialised SDL4j 2.28.2-11
[09:32:17] [Render thread/INFO]: Finishing Controlify init...
[09:32:17] [Render thread/INFO]: No controllers found.

[09:34:13] [Render thread/INFO]: Generating YACL screen

Full log: https://mclo.gs/xd46uSs

Please let me know if you need any more information or if I can assist further in any way 🙋🏻‍♀️

isXander commented 9 months ago

I now have a mac of my own, and also an Xbox Elite Controller Series 2! Will be able to test this tomorrow!

milankkk commented 7 months ago

@isXander Any luck with it?

isXander commented 5 months ago

On the latest version, Xbox Elite Controller 2 and DualSense work flawlessly, on Bluetooth and Wired!