mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-22 03:08:22 +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:
@@ -755,26 +755,6 @@ RAWINPUT_AddDevice(HANDLE hDevice)
|
||||
CHECK(device->preparsed_data = (PHIDP_PREPARSED_DATA)SDL_calloc(size, sizeof(BYTE)));
|
||||
CHECK(GetRawInputDeviceInfoA(hDevice, RIDI_PREPARSEDDATA, device->preparsed_data, &size) != (UINT)-1);
|
||||
|
||||
{
|
||||
const Uint16 vendor = device->vendor_id;
|
||||
const Uint16 product = device->product_id;
|
||||
const Uint16 version = device->version;
|
||||
Uint16 *guid16 = (Uint16 *)device->guid.data;
|
||||
|
||||
*guid16++ = SDL_SwapLE16(SDL_HARDWARE_BUS_USB);
|
||||
*guid16++ = 0;
|
||||
*guid16++ = SDL_SwapLE16(vendor);
|
||||
*guid16++ = 0;
|
||||
*guid16++ = SDL_SwapLE16(product);
|
||||
*guid16++ = 0;
|
||||
*guid16++ = SDL_SwapLE16(version);
|
||||
*guid16++ = 0;
|
||||
|
||||
/* Note that this is a RAWINPUT device for special handling elsewhere */
|
||||
device->guid.data[14] = 'r';
|
||||
device->guid.data[15] = 0;
|
||||
}
|
||||
|
||||
hFile = CreateFileA(dev_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
CHECK(hFile != INVALID_HANDLE_VALUE);
|
||||
|
||||
@@ -799,6 +779,26 @@ RAWINPUT_AddDevice(HANDLE hDevice)
|
||||
SDL_free(product_string);
|
||||
}
|
||||
}
|
||||
{
|
||||
const Uint16 vendor = device->vendor_id;
|
||||
const Uint16 product = device->product_id;
|
||||
const Uint16 version = device->version;
|
||||
Uint16 *guid16 = (Uint16 *)device->guid.data;
|
||||
|
||||
*guid16++ = SDL_SwapLE16(SDL_HARDWARE_BUS_USB);
|
||||
*guid16++ = SDL_SwapLE16(SDL_crc16(0, device->name, SDL_strlen(device->name)));
|
||||
*guid16++ = SDL_SwapLE16(vendor);
|
||||
*guid16++ = 0;
|
||||
*guid16++ = SDL_SwapLE16(product);
|
||||
*guid16++ = 0;
|
||||
*guid16++ = SDL_SwapLE16(version);
|
||||
*guid16++ = 0;
|
||||
|
||||
/* Note that this is a RAWINPUT device for special handling elsewhere */
|
||||
device->guid.data[14] = 'r';
|
||||
device->guid.data[15] = 0;
|
||||
}
|
||||
|
||||
device->path = SDL_strdup(dev_name);
|
||||
|
||||
CloseHandle(hFile);
|
||||
|
Reference in New Issue
Block a user