Fixed whitespace and added code to support older game controller GUIDs

This commit is contained in:
Sam Lantinga 2016-11-11 04:35:06 -08:00
parent b6542ab237
commit 160e719449

View File

@ -540,7 +540,26 @@ char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping)
return NULL;
}
SDL_memcpy(pchGUID, pMapping, pFirstComma - pMapping);
pchGUID[ pFirstComma - pMapping ] = 0;
pchGUID[pFirstComma - pMapping] = '\0';
/* Convert old style GUIDs to the new style in 2.0.5 */
#if __WIN32__
if (SDL_strlen(pchGUID) == 32 &&
SDL_memcmp(&pchGUID[20], "504944564944", 12) == 0) {
SDL_memcpy(&pchGUID[20], "000000000000", 12);
SDL_memcpy(&pchGUID[16], &pchGUID[4], 4);
SDL_memcpy(&pchGUID[8], &pchGUID[0], 4);
SDL_memcpy(&pchGUID[0], "03000000", 8);
}
#elif __MACOSX__
if (SDL_strlen(pchGUID) == 32 &&
SDL_memcmp(&pchGUID[4], "000000000000", 12) == 0 &&
SDL_memcmp(&pchGUID[20], "000000000000", 12) == 0) {
SDL_memcpy(&pchGUID[20], "000000000000", 12);
SDL_memcpy(&pchGUID[8], &pchGUID[0], 4);
SDL_memcpy(&pchGUID[0], "03000000", 8);
}
#endif
return pchGUID;
}
return NULL;