1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-12-26 12:16:13 +00:00

Fix joystick values going out of bounds

Joystick value of 32768 (0x8000) causes games like Xenoblade 2 to crash under failed assertions.
Even though it should be within range of acceptable joystick values.
This commit is contained in:
cathery 2020-01-24 01:38:10 +03:00
parent 69ed3e45de
commit c7c5c42ae8
2 changed files with 11 additions and 1 deletions

View File

@ -46,7 +46,10 @@
"random": "cpp",
"ratio": "cpp",
"string": "cpp",
"thread": "cpp"
"thread": "cpp",
"bit": "cpp",
"cinttypes": "cpp",
"variant": "cpp"
},
"C_Cpp.dimInactiveRegions": true
}

View File

@ -1,6 +1,7 @@
#include "SwitchHDLHandler.h"
#include "ControllerHelpers.h"
#include <cmath>
#include <algorithm>
SwitchHDLHandler::SwitchHDLHandler(std::unique_ptr<IController> &&controller)
: SwitchVirtualGamepadHandler(std::move(controller))
@ -149,6 +150,12 @@ 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);