From f1529b1bc2bafbdadcf4d4643aa5716414097239 Mon Sep 17 00:00:00 2001
From: emmauss <emmausssss@gmail.com>
Date: Fri, 7 Dec 2018 22:59:38 +0200
Subject: [PATCH] Fix homebrew input (#528)

* fix homebrew input
---
 Ryujinx.HLE/Input/Hid.cs               | 2 +-
 Ryujinx.HLE/Input/HidNpadController.cs | 6 ++++++
 Ryujinx.HLE/Input/HidProController.cs  | 6 ++++++
 Ryujinx/Ui/GLScreen.cs                 | 2 ++
 4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/Ryujinx.HLE/Input/Hid.cs b/Ryujinx.HLE/Input/Hid.cs
index c35fb07cd..0154fc63c 100644
--- a/Ryujinx.HLE/Input/Hid.cs
+++ b/Ryujinx.HLE/Input/Hid.cs
@@ -39,7 +39,7 @@ namespace Ryujinx.HLE.Input
             PrimaryController.Connect(controllerId);
         }
 
-        private HidControllerButtons UpdateStickButtons(
+        public HidControllerButtons UpdateStickButtons(
             HidJoystickPosition leftStick,
             HidJoystickPosition rightStick)
         {
diff --git a/Ryujinx.HLE/Input/HidNpadController.cs b/Ryujinx.HLE/Input/HidNpadController.cs
index 90cffbdd7..45dee3cad 100644
--- a/Ryujinx.HLE/Input/HidNpadController.cs
+++ b/Ryujinx.HLE/Input/HidNpadController.cs
@@ -81,6 +81,12 @@
             Device.Memory.WriteInt64(controllerOffset + 0x28,
               (Connected ? (uint)HidControllerConnState.ControllerStateConnected : 0) |
               (_currentLayout == HidControllerLayouts.HandheldJoined ? (uint)HidControllerConnState.ControllerStateWired : 0));
+
+            controllerOffset = WriteInput(buttons, leftStick, rightStick, HidControllerLayouts.Main);
+
+            Device.Memory.WriteInt64(controllerOffset + 0x28,
+              (Connected ? (uint)HidControllerConnState.ControllerStateWired : 0) |
+              (uint)HidControllerConnState.ControllerStateWired);
         }
     }
 }
diff --git a/Ryujinx.HLE/Input/HidProController.cs b/Ryujinx.HLE/Input/HidProController.cs
index f08fb0857..e30e91722 100644
--- a/Ryujinx.HLE/Input/HidProController.cs
+++ b/Ryujinx.HLE/Input/HidProController.cs
@@ -39,6 +39,12 @@
             Device.Memory.WriteInt64(controllerOffset + 0x28,
               (Connected ? (uint)HidControllerConnState.ControllerStateConnected : 0) |
               (_wired ? (uint)HidControllerConnState.ControllerStateWired : 0));
+
+            controllerOffset = WriteInput(buttons, leftStick, rightStick, HidControllerLayouts.Main);
+
+            Device.Memory.WriteInt64(controllerOffset + 0x28,
+              (Connected ? (uint)HidControllerConnState.ControllerStateWired : 0) |
+              (uint)HidControllerConnState.ControllerStateWired);
         }
     }
 }
diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs
index 023359998..e3a6d299b 100644
--- a/Ryujinx/Ui/GLScreen.cs
+++ b/Ryujinx/Ui/GLScreen.cs
@@ -174,6 +174,8 @@ namespace Ryujinx
                 Dy = rightJoystickDy
             };
 
+            currentButton |= _device.Hid.UpdateStickButtons(leftJoystick, rightJoystick);
+
             bool hasTouch = false;
 
             //Get screen touch position from left mouse click