From 89c2c6c76bc8d260002e638e215565b607f56869 Mon Sep 17 00:00:00 2001 From: Aaron Murgatroyd Date: Sun, 17 Dec 2023 01:27:57 +1000 Subject: [PATCH] Fix issues with Invert X / Y and Rotate when mapping different physical stick to JoyCon logical stick --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 52 +++++++++++++++++++-------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 187ca48dd..18e353567 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -313,6 +313,33 @@ namespace Ryujinx.Input.SDL2 return value * ConvertRate; } + private JoyconConfigControllerStick GetLogicalJoyStickConfig(StickInputId inputId) + { + switch(inputId) + { + case StickInputId.Left: + if (_configuration.RightJoyconStick.Joystick == Common.Configuration.Hid.Controller.StickInputId.Left) + { + return _configuration.RightJoyconStick; + } + else + { + return _configuration.LeftJoyconStick; + } + case StickInputId.Right: + if (_configuration.LeftJoyconStick.Joystick == Common.Configuration.Hid.Controller.StickInputId.Right) + { + return _configuration.LeftJoyconStick; + } + else + { + return _configuration.RightJoyconStick; + } + } + + return null; + } + public (float, float) GetStick(StickInputId inputId) { if (inputId == StickInputId.Unbound) @@ -343,24 +370,19 @@ namespace Ryujinx.Input.SDL2 if (HasConfiguration) { - if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.InvertStickX) || - (inputId == StickInputId.Right && _configuration.RightJoyconStick.InvertStickX)) - { - resultX = -resultX; - } + var joyconStickConfig = GetLogicalJoyStickConfig(inputId); - if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.InvertStickY) || - (inputId == StickInputId.Right && _configuration.RightJoyconStick.InvertStickY)) + if (joyconStickConfig != null) { - resultY = -resultY; - } + if (joyconStickConfig.InvertStickX) resultX = -resultX; + if (joyconStickConfig.InvertStickY) resultY = -resultY; - if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.Rotate90CW) || - (inputId == StickInputId.Right && _configuration.RightJoyconStick.Rotate90CW)) - { - float temp = resultX; - resultX = resultY; - resultY = -temp; + if (joyconStickConfig.Rotate90CW) + { + float temp = resultX; + resultX = resultY; + resultY = -temp; + } } }