From 322c14ee3118d11347fb15f02f525abc1647179e Mon Sep 17 00:00:00 2001 From: Ac_K Date: Wed, 29 Dec 2021 14:49:10 +0100 Subject: [PATCH] hid: A little cleanup (#2950) While I'm looking to the code, I've found some syntax issue, and a little inconsistencie between `ActivateNpad` and `ActivateNpadWithRevision`. Nothing more. --- Ryujinx.HLE/HOS/Services/Hid/Hid.cs | 14 ++-- .../Services/Hid/HidDevices/NpadDevices.cs | 9 +-- Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs | 77 +++++++------------ .../Services/Hid/Types/Npad/NpadStyleIndex.cs | 12 +-- 4 files changed, 43 insertions(+), 69 deletions(-) diff --git a/Ryujinx.HLE/HOS/Services/Hid/Hid.cs b/Ryujinx.HLE/HOS/Services/Hid/Hid.cs index 85c811fa2..b8833e9e1 100644 --- a/Ryujinx.HLE/HOS/Services/Hid/Hid.cs +++ b/Ryujinx.HLE/HOS/Services/Hid/Hid.cs @@ -1,17 +1,17 @@ using Ryujinx.Common; -using Ryujinx.HLE.Exceptions; using Ryujinx.Common.Configuration.Hid; -using System.Collections.Generic; -using System.Runtime.CompilerServices; using Ryujinx.Common.Memory; +using Ryujinx.HLE.Exceptions; +using Ryujinx.HLE.HOS.Kernel.Memory; using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory; using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common; -using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse; -using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard; using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugPad; -using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen; +using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard; +using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse; using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad; -using Ryujinx.HLE.HOS.Kernel.Memory; +using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen; +using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace Ryujinx.HLE.HOS.Services.Hid { diff --git a/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs b/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs index ff93204c9..5f56c770d 100644 --- a/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs +++ b/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs @@ -1,14 +1,13 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Runtime.CompilerServices; using Ryujinx.Common; -using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Logging; using Ryujinx.HLE.HOS.Kernel.Threading; using Ryujinx.HLE.HOS.Services.Hid.Types; using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common; using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace Ryujinx.HLE.HOS.Services.Hid { diff --git a/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs b/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs index 140545ad9..ce7dddd34 100644 --- a/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs +++ b/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs @@ -5,9 +5,7 @@ using Ryujinx.HLE.HOS.Kernel.Common; using Ryujinx.HLE.HOS.Kernel.Threading; using Ryujinx.HLE.HOS.Services.Hid.HidServer; using Ryujinx.HLE.HOS.Services.Hid.Types; -using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad; using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Runtime.InteropServices; @@ -642,9 +640,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SetSupportedNpadIdType(nn::applet::AppletResourceUserId, array) public ResultCode SetSupportedNpadIdType(ServiceCtx context) { - long appletResourceUserId = context.RequestData.ReadInt64(); - ulong arrayPosition = context.Request.PtrBuff[0].Position; - ulong arraySize = context.Request.PtrBuff[0].Size; + long appletResourceUserId = context.RequestData.ReadInt64(); + ulong arrayPosition = context.Request.PtrBuff[0].Position; + ulong arraySize = context.Request.PtrBuff[0].Size; ReadOnlySpan supportedPlayerIds = MemoryMarshal.Cast(context.Memory.GetSpan(arrayPosition, (int)arraySize)); @@ -667,38 +665,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid // ActivateNpad(nn::applet::AppletResourceUserId) public ResultCode ActivateNpad(ServiceCtx context) { - long appletResourceUserId = context.RequestData.ReadInt64(); - - context.Device.Hid.Npads.Active = true; - - // Initialize entries to avoid issues with some games. - - List emptyGamepadInputs = new List(); - List emptySixAxisInputs = new List(); - - for (int player = 0; player < NpadDevices.MaxControllers; player++) - { - GamepadInput gamepadInput = new GamepadInput(); - SixAxisInput sixaxisInput = new SixAxisInput(); - - gamepadInput.PlayerId = (PlayerIndex)player; - sixaxisInput.PlayerId = (PlayerIndex)player; - - sixaxisInput.Orientation = new float[9]; - - emptyGamepadInputs.Add(gamepadInput); - emptySixAxisInputs.Add(sixaxisInput); - } - - for (int entry = 0; entry < Hid.SharedMemEntryCount; entry++) - { - context.Device.Hid.Npads.Update(emptyGamepadInputs); - context.Device.Hid.Npads.UpdateSixAxis(emptySixAxisInputs); - } - - Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId }); - - return ResultCode.Success; + return ActiveNpadImpl(context); } [CommandHipc(104)] @@ -773,12 +740,20 @@ namespace Ryujinx.HLE.HOS.Services.Hid } [CommandHipc(109)] // 5.0.0+ - // ActivateNpadWithRevision(nn::applet::AppletResourceUserId, int revision) + // ActivateNpadWithRevision(nn::applet::AppletResourceUserId, ulong revision) public ResultCode ActivateNpadWithRevision(ServiceCtx context) { - int revision = context.RequestData.ReadInt32(); + ulong revision = context.RequestData.ReadUInt64(); + + return ActiveNpadImpl(context, revision); + } + + private ResultCode ActiveNpadImpl(ServiceCtx context, ulong revision = 0) + { long appletResourceUserId = context.RequestData.ReadInt64(); + context.Device.Hid.Npads.Active = true; + // Initialize entries to avoid issues with some games. List emptyGamepadInputs = new List(); @@ -974,7 +949,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid // IsUnintendedHomeButtonInputProtectionEnabled(uint Unknown0, nn::applet::AppletResourceUserId) -> bool IsEnabled public ResultCode IsUnintendedHomeButtonInputProtectionEnabled(ServiceCtx context) { - uint unknown0 = context.RequestData.ReadUInt32(); + uint unknown0 = context.RequestData.ReadUInt32(); long appletResourceUserId = context.RequestData.ReadInt64(); context.ResponseData.Write(_unintendedHomeButtonInputProtectionEnabled); @@ -989,7 +964,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid public ResultCode EnableUnintendedHomeButtonInputProtection(ServiceCtx context) { _unintendedHomeButtonInputProtectionEnabled = context.RequestData.ReadBoolean(); - uint unknown0 = context.RequestData.ReadUInt32(); + uint unknown0 = context.RequestData.ReadUInt32(); long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, unknown0, _unintendedHomeButtonInputProtectionEnabled }); @@ -1027,8 +1002,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid public ResultCode GetVibrationDeviceInfo(ServiceCtx context) { HidVibrationDeviceHandle deviceHandle = context.RequestData.ReadStruct(); - NpadStyleIndex deviceType = (NpadStyleIndex)deviceHandle.DeviceType; - NpadIdType npadIdType = (NpadIdType)deviceHandle.PlayerId; + NpadStyleIndex deviceType = (NpadStyleIndex)deviceHandle.DeviceType; + NpadIdType npadIdType = (NpadIdType)deviceHandle.PlayerId; if (deviceType < NpadStyleIndex.System || deviceType >= NpadStyleIndex.FullKey) { @@ -1092,9 +1067,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid HidVibrationDeviceHandle deviceHandle = new HidVibrationDeviceHandle { DeviceType = context.RequestData.ReadByte(), - PlayerId = context.RequestData.ReadByte(), - Position = context.RequestData.ReadByte(), - Reserved = context.RequestData.ReadByte() + PlayerId = context.RequestData.ReadByte(), + Position = context.RequestData.ReadByte(), + Reserved = context.RequestData.ReadByte() }; HidVibrationValue vibrationValue = new HidVibrationValue @@ -1123,9 +1098,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid HidVibrationDeviceHandle deviceHandle = new HidVibrationDeviceHandle { DeviceType = context.RequestData.ReadByte(), - PlayerId = context.RequestData.ReadByte(), - Position = context.RequestData.ReadByte(), - Reserved = context.RequestData.ReadByte() + PlayerId = context.RequestData.ReadByte(), + Position = context.RequestData.ReadByte(), + Reserved = context.RequestData.ReadByte() }; long appletResourceUserId = context.RequestData.ReadInt64(); @@ -1185,8 +1160,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid context.Memory.Read(context.Request.PtrBuff[1].Position, vibrationValueBuffer); - Span deviceHandles = MemoryMarshal.Cast(vibrationDeviceHandleBuffer); - Span vibrationValues = MemoryMarshal.Cast(vibrationValueBuffer); + Span deviceHandles = MemoryMarshal.Cast(vibrationDeviceHandleBuffer); + Span vibrationValues = MemoryMarshal.Cast(vibrationValueBuffer); if (!deviceHandles.IsEmpty && vibrationValues.Length == deviceHandles.Length) { diff --git a/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadStyleIndex.cs b/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadStyleIndex.cs index b85681d27..ddf5d97f5 100644 --- a/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadStyleIndex.cs +++ b/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadStyleIndex.cs @@ -2,12 +2,12 @@ { public enum NpadStyleIndex : byte { - FullKey = 3, - Handheld = 4, - JoyDual = 5, - JoyLeft = 6, - JoyRight = 7, + FullKey = 3, + Handheld = 4, + JoyDual = 5, + JoyLeft = 6, + JoyRight = 7, SystemExt = 32, - System = 33 + System = 33 } }