forked from Mirror/Ryujinx
mii: Fix multiple inconsistencies (#2392)
I found multiple inconsistencies while diffing with latest sdb, this PR fixes those findings.
This commit is contained in:
parent
0644db02ad
commit
e334303559
5 changed files with 44 additions and 40 deletions
|
@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
||||||
{
|
{
|
||||||
static class Helper
|
static class Helper
|
||||||
{
|
{
|
||||||
public static ushort CalculateCrc16BE(ReadOnlySpan<byte> data, int crc = 0)
|
public static ushort CalculateCrc16(ReadOnlySpan<byte> data, int crc, bool reverseEndianess)
|
||||||
{
|
{
|
||||||
const ushort poly = 0x1021;
|
const ushort poly = 0x1021;
|
||||||
|
|
||||||
|
@ -25,7 +25,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BinaryPrimitives.ReverseEndianness((ushort)crc);
|
if (reverseEndianess)
|
||||||
|
{
|
||||||
|
return (ushort)(BinaryPrimitives.ReverseEndianness(crc) >> 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (ushort)crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UInt128 GetDeviceId()
|
public static UInt128 GetDeviceId()
|
||||||
|
|
|
@ -416,8 +416,11 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
||||||
return ResultCode.InvalidStoreData;
|
return ResultCode.InvalidStoreData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!metadata.MiiKeyCode.IsEnabledSpecialMii() && !storeData.IsSpecial())
|
if (!metadata.MiiKeyCode.IsEnabledSpecialMii() && storeData.IsSpecial())
|
||||||
{
|
{
|
||||||
|
return ResultCode.InvalidOperationOnSpecialMii;
|
||||||
|
}
|
||||||
|
|
||||||
if (_database.GetIndexByCreatorId(out int index, storeData.CreateId))
|
if (_database.GetIndexByCreatorId(out int index, storeData.CreateId))
|
||||||
{
|
{
|
||||||
StoreData oldStoreData = _database.Get(index);
|
StoreData oldStoreData = _database.Get(index);
|
||||||
|
@ -444,9 +447,6 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
||||||
return ResultCode.Success;
|
return ResultCode.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultCode.InvalidOperationOnSpecialMii;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResultCode Delete(DatabaseSessionMetadata metadata, CreateId createId)
|
public ResultCode Delete(DatabaseSessionMetadata metadata, CreateId createId)
|
||||||
{
|
{
|
||||||
if (!_database.GetIndexByCreatorId(out int index, createId))
|
if (!_database.GetIndexByCreatorId(out int index, createId))
|
||||||
|
|
|
@ -588,7 +588,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
|
||||||
Nickname = charInfo.Nickname;
|
Nickname = charInfo.Nickname;
|
||||||
FontRegion = charInfo.FontRegion;
|
FontRegion = charInfo.FontRegion;
|
||||||
FavoriteColor = charInfo.FavoriteColor;
|
FavoriteColor = charInfo.FavoriteColor;
|
||||||
Gender = (Gender)charInfo.Gender;
|
Gender = charInfo.Gender;
|
||||||
Height = charInfo.Height;
|
Height = charInfo.Height;
|
||||||
Build = charInfo.Build;
|
Build = charInfo.Build;
|
||||||
Type = charInfo.Type;
|
Type = charInfo.Type;
|
||||||
|
|
|
@ -233,7 +233,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
|
||||||
|
|
||||||
private ushort CalculateCrc()
|
private ushort CalculateCrc()
|
||||||
{
|
{
|
||||||
return Helper.CalculateCrc16BE(AsSpanWithoutCrc());
|
return Helper.CalculateCrc16(AsSpanWithoutCrc(), 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Span<byte> AsSpan()
|
public Span<byte> AsSpan()
|
||||||
|
|
|
@ -49,26 +49,30 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
|
||||||
|
|
||||||
public bool IsValidDataCrc()
|
public bool IsValidDataCrc()
|
||||||
{
|
{
|
||||||
return DataCrc == CalculateDataCrc();
|
return Helper.CalculateCrc16(AsSpanWithoutDeviceCrc(), 0, false) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsValidDeviceCrc()
|
public bool IsValidDeviceCrc()
|
||||||
{
|
{
|
||||||
return DeviceCrc == CalculateDeviceCrc();
|
UInt128 deviceId = Helper.GetDeviceId();
|
||||||
|
|
||||||
|
ushort deviceIdCrc16 = Helper.CalculateCrc16(SpanHelpers.AsByteSpan(ref deviceId), 0, false);
|
||||||
|
|
||||||
|
return Helper.CalculateCrc16(AsSpan(), deviceIdCrc16, false) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ushort CalculateDataCrc()
|
private ushort CalculateDataCrc()
|
||||||
{
|
{
|
||||||
return Helper.CalculateCrc16BE(AsSpanWithoutCrc());
|
return Helper.CalculateCrc16(AsSpanWithoutDeviceCrc(), 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ushort CalculateDeviceCrc()
|
private ushort CalculateDeviceCrc()
|
||||||
{
|
{
|
||||||
UInt128 deviceId = Helper.GetDeviceId();
|
UInt128 deviceId = Helper.GetDeviceId();
|
||||||
|
|
||||||
ushort deviceIdCrc16 = Helper.CalculateCrc16BE(SpanHelpers.AsByteSpan(ref deviceId));
|
ushort deviceIdCrc16 = Helper.CalculateCrc16(SpanHelpers.AsByteSpan(ref deviceId), 0, false);
|
||||||
|
|
||||||
return Helper.CalculateCrc16BE(AsSpanWithoutDeviceCrc(), deviceIdCrc16);
|
return Helper.CalculateCrc16(AsSpan(), deviceIdCrc16, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReadOnlySpan<byte> AsSpan()
|
private ReadOnlySpan<byte> AsSpan()
|
||||||
|
@ -76,11 +80,6 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
|
||||||
return MemoryMarshal.AsBytes(SpanHelpers.CreateReadOnlySpan(in this, 1));
|
return MemoryMarshal.AsBytes(SpanHelpers.CreateReadOnlySpan(in this, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReadOnlySpan<byte> AsSpanWithoutCrc()
|
|
||||||
{
|
|
||||||
return AsSpan().Slice(0, Size - 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ReadOnlySpan<byte> AsSpanWithoutDeviceCrc()
|
private ReadOnlySpan<byte> AsSpanWithoutDeviceCrc()
|
||||||
{
|
{
|
||||||
return AsSpan().Slice(0, Size - 2);
|
return AsSpan().Slice(0, Size - 2);
|
||||||
|
|
Reference in a new issue