diff --git a/src/Ryujinx.Common/Memory/StructArrayHelpers.cs b/src/Ryujinx.Common/Memory/StructArrayHelpers.cs index 65956ed3..807bd69c 100644 --- a/src/Ryujinx.Common/Memory/StructArrayHelpers.cs +++ b/src/Ryujinx.Common/Memory/StructArrayHelpers.cs @@ -756,6 +756,18 @@ namespace Ryujinx.Common.Memory public Span AsSpan() => MemoryMarshal.CreateSpan(ref _e0, Length); } + public struct Array96 : IArray where T : unmanaged + { + T _e0; + Array64 _other; + Array31 _other2; + public readonly int Length => 96; + public ref T this[int index] => ref AsSpan()[index]; + + [Pure] + public Span AsSpan() => MemoryMarshal.CreateSpan(ref _e0, Length); + } + public struct Array127 : IArray where T : unmanaged { T _e0; diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseImpl.cs b/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseImpl.cs index d9bcecee..5041dc88 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseImpl.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseImpl.cs @@ -290,7 +290,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii { coreData = new CoreData(); - if (charInfo.IsValid()) + if (!charInfo.IsValid()) { return ResultCode.InvalidCharInfo; } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CoreData.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CoreData.cs index 00e49ecb..4f6e289e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CoreData.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CoreData.cs @@ -1,4 +1,5 @@ -using System; +using Ryujinx.Common.Memory; +using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using static Ryujinx.HLE.HOS.Services.Mii.Types.RandomMiiConstants; @@ -10,9 +11,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types { public const int Size = 0x30; - private byte _storage; + private Array48 _storage; - public Span Storage => MemoryMarshal.CreateSpan(ref _storage, Size); + public Span Storage => _storage.AsSpan(); [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 0x18)] public struct ElementInfo diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Nickname.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Nickname.cs index dc21d8e5..6665ca6d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Nickname.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Nickname.cs @@ -1,4 +1,5 @@ -using System; +using Ryujinx.Common.Memory; +using System; using System.Runtime.InteropServices; using System.Text; @@ -10,12 +11,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public const int CharCount = 10; private const int SizeConst = (CharCount + 1) * 2; - private byte _storage; + private Array22 _storage; public static Nickname Default => FromString("no name"); public static Nickname Question => FromString("???"); - public Span Raw => MemoryMarshal.CreateSpan(ref _storage, SizeConst); + public Span Raw => _storage.AsSpan(); private ReadOnlySpan Characters => MemoryMarshal.Cast(Raw); diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreData.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreData.cs index 994f6b7c..178b4831 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreData.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreData.cs @@ -62,7 +62,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types private ushort CalculateDataCrc() { - return Helper.CalculateCrc16(AsSpanWithoutDeviceCrc(), 0, true); + return Helper.CalculateCrc16(AsSpanWithoutCrcs(), 0, true); } private ushort CalculateDeviceCrc() @@ -71,7 +71,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types ushort deviceIdCrc16 = Helper.CalculateCrc16(SpanHelpers.AsByteSpan(ref deviceId), 0, false); - return Helper.CalculateCrc16(AsSpan(), deviceIdCrc16, true); + return Helper.CalculateCrc16(AsSpanWithoutDeviceCrc(), deviceIdCrc16, true); } private ReadOnlySpan AsSpan() @@ -84,6 +84,11 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types return AsSpan()[..(Size - 2)]; } + private ReadOnlySpan AsSpanWithoutCrcs() + { + return AsSpan()[..(Size - 4)]; + } + public static StoreData BuildDefault(UtilityImpl utilImpl, uint index) { StoreData result = new() diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Ver3StoreData.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Ver3StoreData.cs index 70bb348b..1c7db8e6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Ver3StoreData.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Ver3StoreData.cs @@ -1,4 +1,6 @@ -using System; +using Ryujinx.Common.Memory; +using Ryujinx.Common.Utilities; +using System; using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Services.Mii.Types @@ -8,9 +10,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types { public const int Size = 0x60; - private byte _storage; + private Array96 _storage; - public Span Storage => MemoryMarshal.CreateSpan(ref _storage, Size); + public Span Storage => _storage.AsSpan(); // TODO: define all getters/setters }