diff --git a/source/ControllerSwitch/SwitchControllerHandler.cpp b/source/ControllerSwitch/SwitchControllerHandler.cpp index 9247e3a..f628d01 100644 --- a/source/ControllerSwitch/SwitchControllerHandler.cpp +++ b/source/ControllerSwitch/SwitchControllerHandler.cpp @@ -27,7 +27,8 @@ void SwitchControllerHandler::Exit() void SwitchControllerHandler::ConvertAxisToSwitchAxis(float x, float y, float deadzone, s32 *x_out, s32 *y_out) { float floatRange = 2.0f; - float newRange = (JOYSTICK_MAX - JOYSTICK_MIN); + //JOYSTICK_MAX is 1 above the s16 max value, causing crashes on various games including Xenoblade Chronicles 2 + float newRange = ((JOYSTICK_MAX-1) - JOYSTICK_MIN); *x_out = (((x + 1.0f) * newRange) / floatRange) + JOYSTICK_MIN; *y_out = (((y + 1.0f) * newRange) / floatRange) + JOYSTICK_MIN; diff --git a/source/ControllerSwitch/SwitchHDLHandler.cpp b/source/ControllerSwitch/SwitchHDLHandler.cpp index 8a8351b..b4a6513 100644 --- a/source/ControllerSwitch/SwitchHDLHandler.cpp +++ b/source/ControllerSwitch/SwitchHDLHandler.cpp @@ -1,7 +1,6 @@ #include "SwitchHDLHandler.h" #include "ControllerHelpers.h" #include -#include SwitchHDLHandler::SwitchHDLHandler(std::unique_ptr &&controller) : SwitchVirtualGamepadHandler(std::move(controller)) @@ -159,12 +158,6 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data) m_controllerHandler.ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_hdlState.joysticks[JOYSTICK_RIGHT].dx, &m_hdlState.joysticks[JOYSTICK_RIGHT].dy); - //Actual joystick values never use the full range of the s32 type and exceeding them has caused crashes with multiple games, so we clamp them to s16 - m_hdlState.joysticks[JOYSTICK_LEFT].dx = std::clamp(m_hdlState.joysticks[JOYSTICK_LEFT].dx, -32768, 32768 -1); - m_hdlState.joysticks[JOYSTICK_LEFT].dy = std::clamp(m_hdlState.joysticks[JOYSTICK_LEFT].dy, -32768, 32768 -1); - m_hdlState.joysticks[JOYSTICK_RIGHT].dx = std::clamp(m_hdlState.joysticks[JOYSTICK_RIGHT].dx, -32768, 32768 -1); - m_hdlState.joysticks[JOYSTICK_RIGHT].dy = std::clamp(m_hdlState.joysticks[JOYSTICK_RIGHT].dy, -32768, 32768 -1); - m_hdlState.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0); m_hdlState.buttons |= (data.buttons[17] ? KEY_HOME : 0); m_hdlState.buttons |= (data.buttons[18] ? KEY_TOUCH : 0);