Skip to content

Commit 21a7bbb

Browse files
committed
Restore compatibility with older GameCube mappings
Restore the original button values for GameCube controllers, but swap labeled mappings to positional while loading mappings Fixes #12847
1 parent 3730128 commit 21a7bbb

File tree

6 files changed

+55
-32
lines changed

6 files changed

+55
-32
lines changed

src/joystick/SDL_gamepad.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,24 @@ static void SDL_FixupHIDAPIMapping(SDL_Gamepad *gamepad)
14661466
}
14671467
}
14681468

1469+
static void SDL_FixupGameCubeMapping(SDL_Gamepad *gamepad, const char *pchString)
1470+
{
1471+
if (SDL_strstr(gamepad->mapping->mapping, SDL_GAMEPAD_FACE_FIELD) != NULL) {
1472+
return;
1473+
}
1474+
1475+
for (int i = 0; i < gamepad->num_bindings; ++i) {
1476+
SDL_GamepadBinding *binding = &gamepad->bindings[i];
1477+
if (binding->output_type == SDL_GAMEPAD_BINDTYPE_BUTTON) {
1478+
if (binding->output.button == SDL_GAMEPAD_BUTTON_EAST) {
1479+
binding->output.button = SDL_GAMEPAD_BUTTON_WEST;
1480+
} else if (binding->output.button == SDL_GAMEPAD_BUTTON_WEST) {
1481+
binding->output.button = SDL_GAMEPAD_BUTTON_EAST;
1482+
}
1483+
}
1484+
}
1485+
}
1486+
14691487
/*
14701488
* Make a new button mapping struct
14711489
*/
@@ -1491,6 +1509,10 @@ static void SDL_PrivateLoadButtonMapping(SDL_Gamepad *gamepad, GamepadMapping_t
14911509
SDL_FixupHIDAPIMapping(gamepad);
14921510
}
14931511

1512+
if (SDL_IsJoystickGameCube(SDL_GetGamepadVendor(gamepad), SDL_GetGamepadProduct(gamepad))) {
1513+
SDL_FixupGameCubeMapping(gamepad, pGamepadMapping->mapping);
1514+
}
1515+
14941516
// Set the zero point for triggers
14951517
for (i = 0; i < gamepad->num_bindings; ++i) {
14961518
SDL_GamepadBinding *binding = &gamepad->bindings[i];

0 commit comments

Comments
 (0)