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 --- .../HOS/Services/Settings/ISettingsServer.cs | 8 ++-- .../HOS/Services/Settings/ISystemSettingsServer.cs | 43 +++++++++++----------- 2 files changed, 26 insertions(+), 25 deletions(-) (limited to 'Ryujinx.HLE/HOS/Services/Settings') diff --git a/Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs b/Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs index 2932ee22..6f106789 100644 --- a/Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs +++ b/Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs @@ -190,17 +190,17 @@ namespace Ryujinx.HLE.HOS.Services.Settings break; } - context.Memory.Write((ulong)context.Request.ReceiveBuff[0].Position, keyCodeMap); + context.Memory.Write(context.Request.ReceiveBuff[0].Position, keyCodeMap); if (version == 1 && context.Device.System.State.DesiredKeyboardLayout == (long)KeyboardLayout.Default) { - context.Memory.Write((ulong)context.Request.ReceiveBuff[0].Position, (byte)0x01); + context.Memory.Write(context.Request.ReceiveBuff[0].Position, (byte)0x01); } return ResultCode.Success; } - public ResultCode GetAvailableLanguagesCodesImpl(ServiceCtx context, long position, long size, int maxSize) + public ResultCode GetAvailableLanguagesCodesImpl(ServiceCtx context, ulong position, ulong size, int maxSize) { int count = (int)(size / 8); @@ -211,7 +211,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings for (int index = 0; index < count; index++) { - context.Memory.Write((ulong)position, SystemStateMgr.GetLanguageCode(index)); + context.Memory.Write(position, SystemStateMgr.GetLanguageCode(index)); position += 8; } diff --git a/Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs b/Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs index 6bd6866d..54076b4b 100644 --- a/Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs +++ b/Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs @@ -29,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings // GetFirmwareVersion2() -> buffer public ResultCode GetFirmwareVersion2(ServiceCtx context) { - long replyPos = context.Request.RecvListBuff[0].Position; + ulong replyPos = context.Request.RecvListBuff[0].Position; context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x100L); @@ -37,7 +37,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings if (firmwareData != null) { - context.Memory.Write((ulong)replyPos, firmwareData); + context.Memory.Write(replyPos, firmwareData); return ResultCode.Success; } @@ -80,7 +80,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings writer.Write(Encoding.ASCII.GetBytes(build)); - context.Memory.Write((ulong)replyPos, ms.ToArray()); + context.Memory.Write(replyPos, ms.ToArray()); } return ResultCode.Success; @@ -110,19 +110,19 @@ namespace Ryujinx.HLE.HOS.Services.Settings // GetSettingsItemValueSize(buffer, buffer) -> u64 public ResultCode GetSettingsItemValueSize(ServiceCtx context) { - long classPos = context.Request.PtrBuff[0].Position; - long classSize = context.Request.PtrBuff[0].Size; + ulong classPos = context.Request.PtrBuff[0].Position; + ulong classSize = context.Request.PtrBuff[0].Size; - long namePos = context.Request.PtrBuff[1].Position; - long nameSize = context.Request.PtrBuff[1].Size; + ulong namePos = context.Request.PtrBuff[1].Position; + ulong nameSize = context.Request.PtrBuff[1].Size; byte[] classBuffer = new byte[classSize]; - context.Memory.Read((ulong)classPos, classBuffer); + context.Memory.Read(classPos, classBuffer); byte[] nameBuffer = new byte[nameSize]; - context.Memory.Read((ulong)namePos, nameBuffer); + context.Memory.Read(namePos, nameBuffer); string askedSetting = Encoding.ASCII.GetString(classBuffer).Trim('\0') + "!" + Encoding.ASCII.GetString(nameBuffer).Trim('\0'); @@ -159,22 +159,22 @@ namespace Ryujinx.HLE.HOS.Services.Settings // GetSettingsItemValue(buffer, buffer) -> (u64, buffer) public ResultCode GetSettingsItemValue(ServiceCtx context) { - long classPos = context.Request.PtrBuff[0].Position; - long classSize = context.Request.PtrBuff[0].Size; + ulong classPos = context.Request.PtrBuff[0].Position; + ulong classSize = context.Request.PtrBuff[0].Size; - long namePos = context.Request.PtrBuff[1].Position; - long nameSize = context.Request.PtrBuff[1].Size; + ulong namePos = context.Request.PtrBuff[1].Position; + ulong nameSize = context.Request.PtrBuff[1].Size; - long replyPos = context.Request.ReceiveBuff[0].Position; - long replySize = context.Request.ReceiveBuff[0].Size; + ulong replyPos = context.Request.ReceiveBuff[0].Position; + ulong replySize = context.Request.ReceiveBuff[0].Size; byte[] classBuffer = new byte[classSize]; - context.Memory.Read((ulong)classPos, classBuffer); + context.Memory.Read(classPos, classBuffer); byte[] nameBuffer = new byte[nameSize]; - context.Memory.Read((ulong)namePos, nameBuffer); + context.Memory.Read(namePos, nameBuffer); string askedSetting = Encoding.ASCII.GetString(classBuffer).Trim('\0') + "!" + Encoding.ASCII.GetString(nameBuffer).Trim('\0'); @@ -186,7 +186,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings if (nxSetting is string stringValue) { - if (stringValue.Length + 1 > replySize) + if ((ulong)(stringValue.Length + 1) > replySize) { Logger.Error?.Print(LogClass.ServiceSet, $"{askedSetting} String value size is too big!"); } @@ -209,7 +209,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings throw new NotImplementedException(nxSetting.GetType().Name); } - context.Memory.Write((ulong)replyPos, settingBuffer); + context.Memory.Write(replyPos, settingBuffer); Logger.Debug?.Print(LogClass.ServiceSet, $"{askedSetting} set value: {nxSetting} as {nxSetting.GetType()}"); } @@ -235,8 +235,9 @@ namespace Ryujinx.HLE.HOS.Services.Settings public byte[] GetFirmwareData(Switch device) { - long titleId = 0x0100000000000809; - string contentPath = device.System.ContentManager.GetInstalledContentPath(titleId, StorageId.NandSystem, NcaContentType.Data); + const ulong SystemVersionTitleId = 0x0100000000000809; + + string contentPath = device.System.ContentManager.GetInstalledContentPath(SystemVersionTitleId, StorageId.NandSystem, NcaContentType.Data); if (string.IsNullOrWhiteSpace(contentPath)) { -- cgit v1.2.3