From d324b8357cd998c094aeaacb1a7e061a9e109cbe Mon Sep 17 00:00:00 2001 From: Starlet Date: Sun, 10 Jun 2018 20:57:53 -0400 Subject: [PATCH] Add config to XInput --- Ryujinx/Config.cs | 20 ++++++++++++++++++++ Ryujinx/Ryujinx.conf | 16 ++++++++++++++++ Ryujinx/Ui/GLScreen.cs | 28 ++++++++++++++-------------- Ryujinx/XInputController.cs | 24 ++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 Ryujinx/XInputController.cs diff --git a/Ryujinx/Config.cs b/Ryujinx/Config.cs index 86b74c966..37c2b0ddb 100644 --- a/Ryujinx/Config.cs +++ b/Ryujinx/Config.cs @@ -12,6 +12,8 @@ namespace Ryujinx { public static JoyCon FakeJoyCon { get; private set; } + public static XInputController XInput { get; private set; } + public static void Read(Logger Log) { string IniFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); @@ -56,6 +58,24 @@ namespace Ryujinx } } + XInput = new XInputController + { + ButtonA = Convert.ToInt16(Parser.Value("Controls_XInput_Button_A")), + ButtonB = Convert.ToInt16(Parser.Value("Controls_XInput_Button_B")), + ButtonX = Convert.ToInt16(Parser.Value("Controls_XInput_Button_X")), + ButtonY = Convert.ToInt16(Parser.Value("Controls_XInput_Button_Y")), + ButtonPlus = Convert.ToInt16(Parser.Value("Controls_XInput_Button_A")), + ButtonMinus = Convert.ToInt16(Parser.Value("Controls_XInput_Button_A")), + DPadUp = Convert.ToInt16(Parser.Value("Controls_XInput_DPad_Up")), + DPadDown = Convert.ToInt16(Parser.Value("Controls_XInput_DPad_Down")), + DPadLeft = Convert.ToInt16(Parser.Value("Controls_XInput_DPad_Left")), + DPadRight = Convert.ToInt16(Parser.Value("Controls_XInput_DPad_Right")), + ButtonL = Convert.ToInt16(Parser.Value("Controls_XInput_Button_L")), + ButtonZL = Convert.ToInt16(Parser.Value("Controls_XInput_Button_ZL")), + ButtonR = Convert.ToInt16(Parser.Value("Controls_XInput_Button_R")), + ButtonZR = Convert.ToInt16(Parser.Value("Controls_XInput_Button_ZR")) + }; + FakeJoyCon = new JoyCon { Left = new JoyConLeft diff --git a/Ryujinx/Ryujinx.conf b/Ryujinx/Ryujinx.conf index 611f32071..91b53dd6b 100644 --- a/Ryujinx/Ryujinx.conf +++ b/Ryujinx/Ryujinx.conf @@ -19,6 +19,22 @@ Logging_Enable_Error = true #Filtered log classes, seperated by ", ", eg. `Logging_Filtered_Classes = Loader, ServiceFS` Logging_Filtered_Classes = +#XInput, https://gist.github.com/Cyuubi/923bb473e412f477b39d7ee4ddae51ed +Controls_XInput_Button_A = 4096 +Controls_XInput_Button_B = 8192 +Controls_XInput_Button_X = 16384 +Controls_XInput_Button_Y = 32768 +Controls_XInput_Button_Plus = 32 +Controls_XInput_Button_Minus = 16 +Controls_XInput_DPad_Up = 1 +Controls_XInput_DPad_Down = 2 +Controls_XInput_DPad_Left = 4 +Controls_XInput_DPad_Right = 8 +Controls_XInput_Button_L = 64 +Controls_XInput_Button_ZL = 256 +Controls_XInput_Button_R = 128 +Controls_XInput_Button_ZR = 512 + #https://github.com/opentk/opentk/blob/develop/src/OpenTK/Input/Key.cs Controls_Left_FakeJoycon_Stick_Up = 105 Controls_Left_FakeJoycon_Stick_Down = 101 diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs index 1db35103e..cebca0e01 100644 --- a/Ryujinx/Ui/GLScreen.cs +++ b/Ryujinx/Ui/GLScreen.cs @@ -94,26 +94,26 @@ namespace Ryujinx State CurrentState = InputController.GetState(); //Buttons - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.A)) CurrentButton |= HidControllerButtons.KEY_A; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.B)) CurrentButton |= HidControllerButtons.KEY_B; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.X)) CurrentButton |= HidControllerButtons.KEY_X; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Y)) CurrentButton |= HidControllerButtons.KEY_Y; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonA)) CurrentButton |= HidControllerButtons.KEY_A; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonB)) CurrentButton |= HidControllerButtons.KEY_B; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonX)) CurrentButton |= HidControllerButtons.KEY_X; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonY)) CurrentButton |= HidControllerButtons.KEY_Y; //Plus/Minus - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Back)) CurrentButton |= HidControllerButtons.KEY_MINUS; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Start)) CurrentButton |= HidControllerButtons.KEY_PLUS; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonPlus)) CurrentButton |= HidControllerButtons.KEY_PLUS; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonMinus)) CurrentButton |= HidControllerButtons.KEY_MINUS; //DPad - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadUp)) CurrentButton |= HidControllerButtons.KEY_DUP; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown)) CurrentButton |= HidControllerButtons.KEY_DDOWN; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadLeft)) CurrentButton |= HidControllerButtons.KEY_DLEFT; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadRight)) CurrentButton |= HidControllerButtons.KEY_DRIGHT; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.DPadUp)) CurrentButton |= HidControllerButtons.KEY_DUP; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.DPadDown)) CurrentButton |= HidControllerButtons.KEY_DDOWN; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.DPadLeft)) CurrentButton |= HidControllerButtons.KEY_DLEFT; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.DPadRight)) CurrentButton |= HidControllerButtons.KEY_DRIGHT; //L/ZL/R/ZR - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftThumb)) CurrentButton |= HidControllerButtons.KEY_L; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder)) CurrentButton |= HidControllerButtons.KEY_ZL; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.RightThumb)) CurrentButton |= HidControllerButtons.KEY_R; - if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.RightShoulder)) CurrentButton |= HidControllerButtons.KEY_ZR; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonL)) CurrentButton |= HidControllerButtons.KEY_L; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonZL)) CurrentButton |= HidControllerButtons.KEY_ZL; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonR)) CurrentButton |= HidControllerButtons.KEY_R; + if (CurrentState.Gamepad.Buttons.HasFlag((GamepadButtonFlags)Config.XInput.ButtonZR)) CurrentButton |= HidControllerButtons.KEY_ZR; } //LeftJoystick diff --git a/Ryujinx/XInputController.cs b/Ryujinx/XInputController.cs new file mode 100644 index 000000000..5c8758a97 --- /dev/null +++ b/Ryujinx/XInputController.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Ryujinx +{ + public struct XInputController + { + public int ButtonA; + public int ButtonB; + public int ButtonX; + public int ButtonY; + public int ButtonPlus; + public int ButtonMinus; + public int DPadUp; + public int DPadDown; + public int DPadLeft; + public int DPadRight; + public int ButtonL; + public int ButtonZL; + public int ButtonR; + public int ButtonZR; + } +}