Fixed whitespace and added code to support older game controller GUIDs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index c722804..1f1827c 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -396,11 +396,11 @@ void SDL_PrivateGameControllerParseButton(const char *szGameButton, const char *
return;
}
if (axis != SDL_CONTROLLER_AXIS_INVALID) {
- pMapping->axes[ axis ] = iSDLButton;
- pMapping->raxes[ iSDLButton ] = axis;
+ pMapping->axes[axis] = iSDLButton;
+ pMapping->raxes[iSDLButton] = axis;
} else if (button != SDL_CONTROLLER_BUTTON_INVALID) {
- pMapping->axesasbutton[ button ] = iSDLButton;
- pMapping->raxesasbutton[ iSDLButton ] = button;
+ pMapping->axesasbutton[button] = iSDLButton;
+ pMapping->raxesasbutton[iSDLButton] = button;
} else {
SDL_assert(!"How did we get here?");
}
@@ -411,11 +411,11 @@ void SDL_PrivateGameControllerParseButton(const char *szGameButton, const char *
return;
}
if (button != SDL_CONTROLLER_BUTTON_INVALID) {
- pMapping->buttons[ button ] = iSDLButton;
- pMapping->rbuttons[ iSDLButton ] = button;
+ pMapping->buttons[button] = iSDLButton;
+ pMapping->rbuttons[iSDLButton] = button;
} else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
- pMapping->buttonasaxis[ axis ] = iSDLButton;
- pMapping->rbuttonasaxis[ iSDLButton ] = axis;
+ pMapping->buttonasaxis[axis] = iSDLButton;
+ pMapping->rbuttonasaxis[iSDLButton] = axis;
} else {
SDL_assert(!"How did we get here?");
}
@@ -428,10 +428,10 @@ void SDL_PrivateGameControllerParseButton(const char *szGameButton, const char *
if (button != SDL_CONTROLLER_BUTTON_INVALID) {
int ridx;
- pMapping->hatasbutton[ button ].hat = hat;
- pMapping->hatasbutton[ button ].mask = mask;
+ pMapping->hatasbutton[button].hat = hat;
+ pMapping->hatasbutton[button].mask = mask;
ridx = (hat << 4) | mask;
- pMapping->rhatasbutton[ ridx ] = button;
+ pMapping->rhatasbutton[ridx] = button;
} else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
SDL_assert(!"Support hat as axis");
} else {
@@ -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;
@@ -569,7 +588,7 @@ char *SDL_PrivateGetControllerNameFromMappingString(const char *pMapping)
return NULL;
}
SDL_memcpy(pchName, pFirstComma + 1, pSecondComma - pFirstComma);
- pchName[ pSecondComma - pFirstComma - 1 ] = 0;
+ pchName[pSecondComma - pFirstComma - 1] = 0;
return pchName;
}