mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-30 15:08:31 +00:00
Added the CRC of the joystick name to the GUID
This will make it possible to have mappings for different controllers that have the same VID/PID. This happens frequently with some generic controller boards that have been reused in many products. Fixes https://github.com/libsdl-org/SDL/issues/6004
This commit is contained in:
@@ -700,13 +700,17 @@ BSD_JoystickQuit(void)
|
||||
}
|
||||
|
||||
static SDL_JoystickGUID
|
||||
BSD_JoystickGetDeviceGUID( int device_index )
|
||||
BSD_JoystickGetDeviceGUID(int device_index)
|
||||
{
|
||||
/* the GUID is just the name for now */
|
||||
const char *name = BSD_JoystickGetDeviceName(device_index);
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = BSD_JoystickGetDeviceName( device_index );
|
||||
SDL_zero( guid );
|
||||
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
|
||||
Uint16 *guid16 = (Uint16 *)guid.data;
|
||||
|
||||
SDL_zero(guid);
|
||||
*guid16++ = SDL_SwapLE16(SDL_HARDWARE_BUS_UNKNOWN);
|
||||
*guid16++ = SDL_SwapLE16(SDL_crc16(0, name, SDL_strlen(name)));
|
||||
SDL_strlcpy((char*)guid16, name, sizeof(guid.data) - 4);
|
||||
return guid;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user