From 305f06eb71a7832e6b0081a67015b66ced8a23cd Mon Sep 17 00:00:00 2001 From: Mary Date: Sat, 24 Apr 2021 12:16:01 +0200 Subject: HLE: Fix integer sign inconcistency accross the codebase (#2222) * Make all title id instances unsigned * Replace address and size with ulong instead of signed types Long overdue change. Also change some logics here and there to optimize with the new memory manager. * Address Ac_K's comments * Remove uneeded cast all around * Fixes some others misalignment --- Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs | 22 ++++++++++------------ .../HOS/Services/Hid/Types/Npad/NpadIdType.cs | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'Ryujinx.HLE/HOS/Services/Hid') diff --git a/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs b/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs index e45e695f..11f33252 100644 --- a/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs +++ b/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs @@ -4,6 +4,7 @@ using Ryujinx.HLE.HOS.Kernel.Common; using Ryujinx.HLE.HOS.Kernel.Threading; using Ryujinx.HLE.HOS.Services.Hid.HidServer; using System; +using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Services.Hid { @@ -590,25 +591,22 @@ namespace Ryujinx.HLE.HOS.Services.Hid public ResultCode SetSupportedNpadIdType(ServiceCtx context) { long appletResourceUserId = context.RequestData.ReadInt64(); - long arraySize = context.Request.PtrBuff[0].Size / 4; + ulong arrayPosition = context.Request.PtrBuff[0].Position; + ulong arraySize = context.Request.PtrBuff[0].Size; - NpadIdType[] supportedPlayerIds = new NpadIdType[arraySize]; + ReadOnlySpan supportedPlayerIds = MemoryMarshal.Cast(context.Memory.GetSpan(arrayPosition, (int)arraySize)); context.Device.Hid.Npads.ClearSupportedPlayers(); - for (int i = 0; i < arraySize; ++i) + for (int i = 0; i < supportedPlayerIds.Length; ++i) { - NpadIdType id = context.Memory.Read((ulong)(context.Request.PtrBuff[0].Position + i * 4)); - - if (id >= 0) + if (supportedPlayerIds[i] >= 0) { - context.Device.Hid.Npads.SetSupportedPlayer(HidUtils.GetIndexFromNpadIdType(id)); + context.Device.Hid.Npads.SetSupportedPlayer(HidUtils.GetIndexFromNpadIdType(supportedPlayerIds[i])); } - - supportedPlayerIds[i] = id; } - Logger.Stub?.PrintStub(LogClass.ServiceHid, $"{arraySize} " + string.Join(",", supportedPlayerIds)); + Logger.Stub?.PrintStub(LogClass.ServiceHid, $"{supportedPlayerIds.Length} " + string.Join(",", supportedPlayerIds.ToArray())); return ResultCode.Success; } @@ -1007,11 +1005,11 @@ namespace Ryujinx.HLE.HOS.Services.Hid byte[] vibrationDeviceHandleBuffer = new byte[context.Request.PtrBuff[0].Size]; - context.Memory.Read((ulong)context.Request.PtrBuff[0].Position, vibrationDeviceHandleBuffer); + context.Memory.Read(context.Request.PtrBuff[0].Position, vibrationDeviceHandleBuffer); byte[] vibrationValueBuffer = new byte[context.Request.PtrBuff[1].Size]; - context.Memory.Read((ulong)context.Request.PtrBuff[1].Position, vibrationValueBuffer); + context.Memory.Read(context.Request.PtrBuff[1].Position, vibrationValueBuffer); // TODO: Read all handles and values from buffer. diff --git a/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadIdType.cs b/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadIdType.cs index 5f6a68cb..c061e15a 100644 --- a/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadIdType.cs +++ b/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadIdType.cs @@ -1,6 +1,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid { - public enum NpadIdType + public enum NpadIdType : uint { Player1 = 0, Player2 = 1, -- cgit v1.2.3