devkitPro / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
11 stars 12 forks source link

Fix GameController interface on Switch #56

Closed rsn8887 closed 5 months ago

rsn8887 commented 5 months ago

This fixes Switch controllers not being recognized as SDL_GameControllers because of missing mappings.

The GUID struct was changed at some point in recent SDL2.

The GUID is not simply the first 16 characters of the joystick name anymore as it used to be. The first four bytes now contain a number related to the hardware bus and a crc16 of the name, see here: https://github.com/devkitPro/SDL/blob/ed13eea0aaca1caed8d2052a4db8ebb0b4a0f302/src/joystick/SDL_joystick.c#L2111 To be correct, the GUID must be constructed from the joystick name via the function SDL_CreateJoystickGUIDForName(). Compare this also to upstreamed platforms like Vita and PS2 where that function is now also used. I then checked the resulting GUID string via SDL_JoystickGetGUIDString(), and used it to fix the mapping line.

This is a port of the same fix from branch switch-sdl2-2.28, adapted to use SDL_GAMECONTROLLER_USE_BUTTON_LABELS

WinterMute commented 5 months ago

the sdl2 branch isn't current. Releases are being made from https://github.com/devkitPro/SDL/tree/switch-sdl-2.28

Sorry for the confusion, we should have probably deleted this one already, it's based on 2.0.14