mirror of https://github.com/encounter/SDL.git
Make sure we match the same way when adding a mapping and looking up a mapping
Fixes https://github.com/libsdl-org/SDL/issues/6898 (cherry picked from commit 3db9112ef4cbb936b11f941f8a98c1704e37e140)
This commit is contained in:
parent
2462262e0c
commit
278c78e34c
|
@ -752,10 +752,13 @@ static ControllerMapping_t *SDL_PrivateMatchControllerMappingForGUID(SDL_Joystic
|
||||||
|
|
||||||
if (SDL_memcmp(&guid, &mapping_guid, sizeof(guid)) == 0) {
|
if (SDL_memcmp(&guid, &mapping_guid, sizeof(guid)) == 0) {
|
||||||
Uint16 mapping_crc = 0;
|
Uint16 mapping_crc = 0;
|
||||||
|
|
||||||
|
if (match_crc) {
|
||||||
const char *crc_string = SDL_strstr(mapping->mapping, SDL_CONTROLLER_CRC_FIELD);
|
const char *crc_string = SDL_strstr(mapping->mapping, SDL_CONTROLLER_CRC_FIELD);
|
||||||
if (crc_string) {
|
if (crc_string) {
|
||||||
mapping_crc = (Uint16)SDL_strtol(crc_string + SDL_CONTROLLER_CRC_FIELD_SIZE, NULL, 16);
|
mapping_crc = (Uint16)SDL_strtol(crc_string + SDL_CONTROLLER_CRC_FIELD_SIZE, NULL, 16);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (crc == mapping_crc) {
|
if (crc == mapping_crc) {
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
@ -767,7 +770,7 @@ static ControllerMapping_t *SDL_PrivateMatchControllerMappingForGUID(SDL_Joystic
|
||||||
/*
|
/*
|
||||||
* Helper function to scan the mappings database for a controller with the specified GUID
|
* Helper function to scan the mappings database for a controller with the specified GUID
|
||||||
*/
|
*/
|
||||||
static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID guid)
|
static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool create_mapping)
|
||||||
{
|
{
|
||||||
ControllerMapping_t *mapping;
|
ControllerMapping_t *mapping;
|
||||||
Uint16 vendor, product, crc;
|
Uint16 vendor, product, crc;
|
||||||
|
@ -802,6 +805,10 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!create_mapping) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#if SDL_JOYSTICK_XINPUT
|
#if SDL_JOYSTICK_XINPUT
|
||||||
if (SDL_IsJoystickXInput(guid)) {
|
if (SDL_IsJoystickXInput(guid)) {
|
||||||
/* This is an XInput device */
|
/* This is an XInput device */
|
||||||
|
@ -1269,7 +1276,7 @@ SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pControllerMapping = SDL_PrivateMatchControllerMappingForGUID(jGUID, SDL_TRUE, SDL_TRUE);
|
pControllerMapping = SDL_PrivateGetControllerMappingForGUID(jGUID, SDL_FALSE);
|
||||||
if (pControllerMapping) {
|
if (pControllerMapping) {
|
||||||
/* Only overwrite the mapping if the priority is the same or higher. */
|
/* Only overwrite the mapping if the priority is the same or higher. */
|
||||||
if (pControllerMapping->priority <= priority) {
|
if (pControllerMapping->priority <= priority) {
|
||||||
|
@ -1329,7 +1336,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
|
||||||
{
|
{
|
||||||
ControllerMapping_t *mapping;
|
ControllerMapping_t *mapping;
|
||||||
|
|
||||||
mapping = SDL_PrivateGetControllerMappingForGUID(guid);
|
mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_TRUE);
|
||||||
#ifdef __LINUX__
|
#ifdef __LINUX__
|
||||||
if (!mapping && name) {
|
if (!mapping && name) {
|
||||||
if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
|
if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
|
||||||
|
@ -1744,7 +1751,7 @@ SDL_GameControllerMappingForIndex(int mapping_index)
|
||||||
char *
|
char *
|
||||||
SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
|
SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
|
||||||
{
|
{
|
||||||
ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(guid);
|
ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_TRUE);
|
||||||
if (mapping) {
|
if (mapping) {
|
||||||
return CreateMappingString(mapping, guid);
|
return CreateMappingString(mapping, guid);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue