Merge fe5a66851c
into 53ebbcfbd9
This commit is contained in:
commit
f0e80f3e61
5 changed files with 124 additions and 1 deletions
|
@ -12,6 +12,8 @@ namespace Ryujinx
|
||||||
{
|
{
|
||||||
public static JoyCon FakeJoyCon { get; private set; }
|
public static JoyCon FakeJoyCon { get; private set; }
|
||||||
|
|
||||||
|
public static XInputController XInput { get; private set; }
|
||||||
|
|
||||||
public static void Read(Logger Log)
|
public static void Read(Logger Log)
|
||||||
{
|
{
|
||||||
string IniFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
string IniFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
|
@ -56,6 +58,24 @@ namespace Ryujinx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XInput = new XInputController
|
||||||
|
{
|
||||||
|
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
|
FakeJoyCon = new JoyCon
|
||||||
{
|
{
|
||||||
Left = new JoyConLeft
|
Left = new JoyConLeft
|
||||||
|
|
|
@ -19,6 +19,22 @@ Logging_Enable_Error = true
|
||||||
#Filtered log classes, seperated by ", ", eg. `Logging_Filtered_Classes = Loader, ServiceFS`
|
#Filtered log classes, seperated by ", ", eg. `Logging_Filtered_Classes = Loader, ServiceFS`
|
||||||
Logging_Filtered_Classes =
|
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
|
#https://github.com/opentk/opentk/blob/develop/src/OpenTK/Input/Key.cs
|
||||||
Controls_Left_FakeJoycon_Stick_Up = 105
|
Controls_Left_FakeJoycon_Stick_Up = 105
|
||||||
Controls_Left_FakeJoycon_Stick_Down = 101
|
Controls_Left_FakeJoycon_Stick_Down = 101
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="OpenTK.NETCore" Version="1.1.2749.6433" />
|
<PackageReference Include="OpenTK.NETCore" Version="1.1.2749.6433" />
|
||||||
|
<PackageReference Include="SharpDX.XInput" Version="4.1.0" />
|
||||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.4.0" />
|
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.4.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
|
using SharpDX.XInput;
|
||||||
using Ryujinx.Graphics.Gal;
|
using Ryujinx.Graphics.Gal;
|
||||||
using Ryujinx.HLE;
|
using Ryujinx.HLE;
|
||||||
using Ryujinx.HLE.Input;
|
using Ryujinx.HLE.Input;
|
||||||
|
@ -20,6 +21,19 @@ namespace Ryujinx
|
||||||
|
|
||||||
private IGalRenderer Renderer;
|
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)
|
public GLScreen(Switch Ns, IGalRenderer Renderer)
|
||||||
: base(1280, 720,
|
: base(1280, 720,
|
||||||
new GraphicsMode(), "Ryujinx", 0,
|
new GraphicsMode(), "Ryujinx", 0,
|
||||||
|
@ -29,6 +43,26 @@ namespace Ryujinx
|
||||||
this.Ns = Ns;
|
this.Ns = Ns;
|
||||||
this.Renderer = Renderer;
|
this.Renderer = Renderer;
|
||||||
|
|
||||||
|
//Get 1st controller detected
|
||||||
|
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(
|
Location = new Point(
|
||||||
(DisplayDevice.Default.Width / 2) - (Width / 2),
|
(DisplayDevice.Default.Width / 2) - (Width / 2),
|
||||||
(DisplayDevice.Default.Height / 2) - (Height / 2));
|
(DisplayDevice.Default.Height / 2) - (Height / 2));
|
||||||
|
@ -54,7 +88,35 @@ namespace Ryujinx
|
||||||
int RightJoystickDX = 0;
|
int RightJoystickDX = 0;
|
||||||
int RightJoystickDY = 0;
|
int RightJoystickDY = 0;
|
||||||
|
|
||||||
//RightJoystick
|
//XInput
|
||||||
|
if (XInputEnabled)
|
||||||
|
{
|
||||||
|
State CurrentState = InputController.GetState();
|
||||||
|
|
||||||
|
//Buttons
|
||||||
|
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)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)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)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
|
||||||
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickUp]) LeftJoystickDY = short.MaxValue;
|
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.StickDown]) LeftJoystickDY = -short.MaxValue;
|
||||||
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickLeft]) LeftJoystickDX = -short.MaxValue;
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickLeft]) LeftJoystickDX = -short.MaxValue;
|
||||||
|
|
24
Ryujinx/XInputController.cs
Normal file
24
Ryujinx/XInputController.cs
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue