From 3560a489fbed059b9446b44b538f290b3f823d17 Mon Sep 17 00:00:00 2001 From: The Dax Date: Fri, 5 Jul 2013 19:09:16 -0400 Subject: [PATCH] Add an option to allow DirectInput to swap the right analog stick axes, in case the emulator detects them incorrectly. --- Core/Config.cpp | 1 + Core/Config.h | 1 + Windows/DinputDevice.cpp | 68 ++++++++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 897f137696..f97128d78f 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -141,6 +141,7 @@ void Config::Load(const char *iniFileName) control->Get("AccelerometerToAnalogHoriz", &bAccelerometerToAnalogHoriz, false); control->Get("ForceInputDevice", &iForceInputDevice, -1); control->Get("RightStickBind", &iRightStickBind, 0); + control->Get("SwapDInputRightAxes", &iSwapRightAxes, 0); control->Get("TouchButtonOpacity", &iTouchButtonOpacity, 65); control->Get("ButtonScale", &fButtonScale, 1.15); diff --git a/Core/Config.h b/Core/Config.h index 9ce7696153..584d4d1cd9 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -110,6 +110,7 @@ public: // 3 = L/R // 4 = L/R + triangle/cross int iRightStickBind; + int iSwapRightAxes; // Control std::map iMappingMap; // Can be used differently depending on systems diff --git a/Windows/DinputDevice.cpp b/Windows/DinputDevice.cpp index ab3776b5b8..1af4ec1234 100644 --- a/Windows/DinputDevice.cpp +++ b/Windows/DinputDevice.cpp @@ -216,30 +216,66 @@ int DinputDevice::UpdateState(InputState &input_state) case 0: break; case 1: - if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RIGHT; - else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LEFT; - if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_UP; - else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_DOWN; + if(!g_Config.iSwapRightAxes) { + if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RIGHT; + else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LEFT; + if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_UP; + else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_DOWN; + } + else { + if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RIGHT; + else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LEFT; + if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_UP; + else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_DOWN; + } break; case 2: - if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_B; - else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_X; - if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_Y; - else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_A; + if(!g_Config.iSwapRightAxes) { + if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_B; + else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_X; + if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_Y; + else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_A; + } + else { + if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_B; + else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_X; + if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_Y; + else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_A; + } break; case 3: - if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RBUMPER; - else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LBUMPER; + if(!g_Config.iSwapRightAxes) { + if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RBUMPER; + else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LBUMPER; + } + else { + if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RBUMPER; + else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LBUMPER; + } break; case 4: - if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RBUMPER; - else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LBUMPER; - if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_Y; - else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_A; + if(!g_Config.iSwapRightAxes) { + if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RBUMPER; + else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LBUMPER; + if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_Y; + else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_A; + } + else { + if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RBUMPER; + else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LBUMPER; + if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_Y; + else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_A; + } break; case 5: - if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RIGHT; - else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LEFT; + if(!g_Config.iSwapRightAxes) { + if (js.lRz > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RIGHT; + else if (js.lRz < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LEFT; + } + else { + if (js.lZ > rthreshold) input_state.pad_buttons |= PAD_BUTTON_RIGHT; + else if (js.lZ < -rthreshold) input_state.pad_buttons |= PAD_BUTTON_LEFT; + } break; }