From a5e90ec2d1fe6482bc9810900bd521b7945c3fa4 Mon Sep 17 00:00:00 2001 From: Starlet Date: Sun, 10 Jun 2018 18:26:59 -0400 Subject: [PATCH 1/5] Basic XInput support. --- Ryujinx/Ryujinx.csproj | 1 + Ryujinx/Ui/GLScreen.cs | 67 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/Ryujinx/Ryujinx.csproj b/Ryujinx/Ryujinx.csproj index dc6203d528..70ecde1449 100644 --- a/Ryujinx/Ryujinx.csproj +++ b/Ryujinx/Ryujinx.csproj @@ -7,6 +7,7 @@ + diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs index 6b6ae6a01a..0efb2bb989 100644 --- a/Ryujinx/Ui/GLScreen.cs +++ b/Ryujinx/Ui/GLScreen.cs @@ -1,6 +1,7 @@ using OpenTK; using OpenTK.Graphics; using OpenTK.Input; +using SharpDX.XInput; using Ryujinx.Core; using Ryujinx.Core.Input; using Ryujinx.Graphics.Gal; @@ -20,6 +21,19 @@ namespace Ryujinx private IGalRenderer Renderer; + // Initialize XInput + private Controller[] InputControllers = new[] + { + new Controller(UserIndex.One), + new Controller(UserIndex.Two), + new Controller(UserIndex.Three), + new Controller(UserIndex.Four) + }; + + private Controller InputController = null; + + private bool XInputEnabled = false; + public GLScreen(Switch Ns, IGalRenderer Renderer) : base(1280, 720, new GraphicsMode(), "Ryujinx", 0, @@ -29,6 +43,26 @@ namespace Ryujinx this.Ns = Ns; this.Renderer = Renderer; + // Get 1st controller detected/available + foreach (Controller SelectController in InputControllers) + { + if (SelectController.IsConnected) + { + InputController = SelectController; + break; + } + } + + if (InputController != null) + { + XInputEnabled = true; + Console.WriteLine("XInput controller detected!"); + } + else + { + Console.WriteLine("XInput controller not detected!"); + } + Location = new Point( (DisplayDevice.Default.Width / 2) - (Width / 2), (DisplayDevice.Default.Height / 2) - (Height / 2)); @@ -54,6 +88,39 @@ namespace Ryujinx int RightJoystickDX = 0; int RightJoystickDY = 0; + //XInput + if (XInputEnabled) + { + State CurrentState = InputController.GetState(); + switch (CurrentState.Gamepad.Buttons) + { + case GamepadButtonFlags.A: + CurrentButton |= HidControllerButtons.KEY_A; + break; + case GamepadButtonFlags.B: + CurrentButton |= HidControllerButtons.KEY_B; + break; + case GamepadButtonFlags.X: + CurrentButton |= HidControllerButtons.KEY_X; + break; + case GamepadButtonFlags.Y: + CurrentButton |= HidControllerButtons.KEY_Y; + break; + case GamepadButtonFlags.DPadUp: + CurrentButton |= HidControllerButtons.KEY_DUP; + break; + case GamepadButtonFlags.DPadDown: + CurrentButton |= HidControllerButtons.KEY_DDOWN; + break; + case GamepadButtonFlags.DPadLeft: + CurrentButton |= HidControllerButtons.KEY_DLEFT; + break; + case GamepadButtonFlags.DPadRight: + CurrentButton |= HidControllerButtons.KEY_DRIGHT; + break; + } + } + //RightJoystick if (Keyboard[(Key)Config.FakeJoyCon.Left.StickUp]) LeftJoystickDY = short.MaxValue; if (Keyboard[(Key)Config.FakeJoyCon.Left.StickDown]) LeftJoystickDY = -short.MaxValue; From b513c00627b7dfc031df2b53c1b5ed8ab17637b6 Mon Sep 17 00:00:00 2001 From: Starlet Date: Sun, 10 Jun 2018 19:52:09 -0400 Subject: [PATCH 2/5] Add more buttons, fix multiple inputs and fix a small typo --- Ryujinx/Ui/GLScreen.cs | 55 +++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs index 0efb2bb989..1db35103ed 100644 --- a/Ryujinx/Ui/GLScreen.cs +++ b/Ryujinx/Ui/GLScreen.cs @@ -21,7 +21,7 @@ namespace Ryujinx private IGalRenderer Renderer; - // Initialize XInput + //Initialize XInput private Controller[] InputControllers = new[] { new Controller(UserIndex.One), @@ -43,7 +43,7 @@ namespace Ryujinx this.Ns = Ns; this.Renderer = Renderer; - // Get 1st controller detected/available + //Get 1st controller detected foreach (Controller SelectController in InputControllers) { if (SelectController.IsConnected) @@ -92,36 +92,31 @@ namespace Ryujinx if (XInputEnabled) { State CurrentState = InputController.GetState(); - switch (CurrentState.Gamepad.Buttons) - { - case GamepadButtonFlags.A: - CurrentButton |= HidControllerButtons.KEY_A; - break; - case GamepadButtonFlags.B: - CurrentButton |= HidControllerButtons.KEY_B; - break; - case GamepadButtonFlags.X: - CurrentButton |= HidControllerButtons.KEY_X; - break; - case GamepadButtonFlags.Y: - CurrentButton |= HidControllerButtons.KEY_Y; - break; - case GamepadButtonFlags.DPadUp: - CurrentButton |= HidControllerButtons.KEY_DUP; - break; - case GamepadButtonFlags.DPadDown: - CurrentButton |= HidControllerButtons.KEY_DDOWN; - break; - case GamepadButtonFlags.DPadLeft: - CurrentButton |= HidControllerButtons.KEY_DLEFT; - break; - case GamepadButtonFlags.DPadRight: - CurrentButton |= HidControllerButtons.KEY_DRIGHT; - break; - } + + //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; + + //Plus/Minus + if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Back)) CurrentButton |= HidControllerButtons.KEY_MINUS; + if (CurrentState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Start)) CurrentButton |= HidControllerButtons.KEY_PLUS; + + //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; + + //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; } - //RightJoystick + //LeftJoystick if (Keyboard[(Key)Config.FakeJoyCon.Left.StickUp]) LeftJoystickDY = short.MaxValue; if (Keyboard[(Key)Config.FakeJoyCon.Left.StickDown]) LeftJoystickDY = -short.MaxValue; if (Keyboard[(Key)Config.FakeJoyCon.Left.StickLeft]) LeftJoystickDX = -short.MaxValue; From d324b8357cd998c094aeaacb1a7e061a9e109cbe Mon Sep 17 00:00:00 2001 From: Starlet Date: Sun, 10 Jun 2018 20:57:53 -0400 Subject: [PATCH 3/5] 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 86b74c9667..37c2b0ddb6 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 611f320717..91b53dd6bd 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 1db35103ed..cebca0e019 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 0000000000..5c8758a97c --- /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; + } +} From 051de97b2132142308fdbdc0bcf3cfb8a7d4728f Mon Sep 17 00:00:00 2001 From: Starlet Date: Sun, 10 Jun 2018 21:20:13 -0400 Subject: [PATCH 4/5] I suck at copy pasting --- Ryujinx/Config.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Ryujinx/Config.cs b/Ryujinx/Config.cs index 316ade42dd..730e448f30 100644 --- a/Ryujinx/Config.cs +++ b/Ryujinx/Config.cs @@ -64,8 +64,8 @@ namespace Ryujinx 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")), + ButtonPlus = Convert.ToInt16(Parser.Value("Controls_XInput_Button_Plus")), + ButtonMinus = Convert.ToInt16(Parser.Value("Controls_XInput_Button_Minus")), 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")), From fe5a66851cd0c57c35d79f09a4c5993bf72dbbef Mon Sep 17 00:00:00 2001 From: Starlet Date: Mon, 11 Jun 2018 09:48:34 -0400 Subject: [PATCH 5/5] Oops... --- Ryujinx/Config.cs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Ryujinx/Config.cs b/Ryujinx/Config.cs index 730e448f30..56eb7e8898 100644 --- a/Ryujinx/Config.cs +++ b/Ryujinx/Config.cs @@ -60,20 +60,20 @@ 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_Plus")), - ButtonMinus = Convert.ToInt16(Parser.Value("Controls_XInput_Button_Minus")), - 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")) + ButtonA = Convert.ToInt32(Parser.Value("Controls_XInput_Button_A")), + ButtonB = Convert.ToInt32(Parser.Value("Controls_XInput_Button_B")), + ButtonX = Convert.ToInt32(Parser.Value("Controls_XInput_Button_X")), + ButtonY = Convert.ToInt32(Parser.Value("Controls_XInput_Button_Y")), + ButtonPlus = Convert.ToInt32(Parser.Value("Controls_XInput_Button_Plus")), + ButtonMinus = Convert.ToInt32(Parser.Value("Controls_XInput_Button_Minus")), + DPadUp = Convert.ToInt32(Parser.Value("Controls_XInput_DPad_Up")), + DPadDown = Convert.ToInt32(Parser.Value("Controls_XInput_DPad_Down")), + DPadLeft = Convert.ToInt32(Parser.Value("Controls_XInput_DPad_Left")), + DPadRight = Convert.ToInt32(Parser.Value("Controls_XInput_DPad_Right")), + ButtonL = Convert.ToInt32(Parser.Value("Controls_XInput_Button_L")), + ButtonZL = Convert.ToInt32(Parser.Value("Controls_XInput_Button_ZL")), + ButtonR = Convert.ToInt32(Parser.Value("Controls_XInput_Button_R")), + ButtonZR = Convert.ToInt32(Parser.Value("Controls_XInput_Button_ZR")) }; FakeJoyCon = new JoyCon