[Ryujinx.HLE] Address dotnet-format issues (#5380)

* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0060 warnings

* Silence dotnet format IDE0052 warnings

* Address or silence dotnet format IDE1006 warnings

* Address dotnet format CA1816 warnings

* Address or silence dotnet format CA2208 warnings

* Address or silence dotnet format CA1806 and a few CA1854 warnings

* Address dotnet format CA2211 warnings

* Address dotnet format CA1822 warnings

* Address or silence dotnet format CA1069 warnings

* Make dotnet format succeed in style mode

* Address or silence dotnet format CA2211 warnings

* Address review comments

* Address dotnet format CA2208 warnings properly

* Make ProcessResult readonly

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Add previously silenced warnings back

I have no clue how these disappeared

* Revert formatting changes for while and for-loops

* Format if-blocks correctly

* Run dotnet format style after rebase

* Run dotnet format whitespace after rebase

* Run dotnet format style after rebase

* Run dotnet format analyzers after rebase

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Disable 'prefer switch expression' rule

* Add comments to disabled warnings

* Fix a few disabled warnings

* Fix naming rule violation, Convert shader properties to auto-property and convert values to const

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Start working on disabled warnings

* Fix and silence a few dotnet-format warnings again

* Run dotnet format after rebase

* Use using declaration instead of block syntax

* Address IDE0251 warnings

* Address a few disabled IDE0060 warnings

* Silence IDE0060 in .editorconfig

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First dotnet format pass

* Fix naming rule violations

* Fix typo

* Add trailing commas, use targeted new and use array initializer

* Fix build issues

* Fix remaining build issues

* Remove SuppressMessage for CA1069 where possible

* Address dotnet format issues

* Address formatting issues

Co-authored-by: Ac_K <acoustik666@gmail.com>

* Add GetHashCode implementation for RenderingSurfaceInfo

* Explicitly silence CA1822 for every affected method in Syscall

* Address formatting issues in Demangler.cs

* Address review feedback

Co-authored-by: Ac_K <acoustik666@gmail.com>

* Revert marking service methods as static

* Next dotnet format pass

* Address review feedback

---------

Co-authored-by: Ac_K <acoustik666@gmail.com>
This commit is contained in:
TSRBerry
2023-07-16 19:31:14 +02:00
committed by GitHub
parent fec8291c17
commit 326749498b
1015 changed files with 8173 additions and 7615 deletions

View File

@@ -13,17 +13,14 @@ namespace Ryujinx.HLE.HOS.Services.Mii
{
get
{
if (_instance == null)
{
_instance = new DatabaseImpl();
}
_instance ??= new DatabaseImpl();
return _instance;
}
}
private UtilityImpl _utilityImpl;
private MiiDatabaseManager _miiDatabase;
private readonly MiiDatabaseManager _miiDatabase;
private bool _isBroken;
public DatabaseImpl()

View File

@@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii
{
class DatabaseSessionMetadata
{
public uint InterfaceVersion;
public uint InterfaceVersion;
public ulong UpdateCounter;
public SpecialMiiKeyCode MiiKeyCode { get; private set; }
@@ -12,8 +12,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii
public DatabaseSessionMetadata(ulong updateCounter, SpecialMiiKeyCode miiKeyCode)
{
InterfaceVersion = 0;
UpdateCounter = updateCounter;
MiiKeyCode = miiKeyCode;
UpdateCounter = updateCounter;
MiiKeyCode = miiKeyCode;
}
public bool IsInterfaceVersionSupported(uint interfaceVersion)

View File

@@ -39,10 +39,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii
return UInt128Utils.FromHex("5279754d69694e780000000000000000"); // RyuMiiNx
}
#pragma warning disable IDE0055 // Disable formatting
public static ReadOnlySpan<byte> Ver3FacelineColorTable => new byte[] { 0, 1, 2, 3, 4, 5 };
public static ReadOnlySpan<byte> Ver3HairColorTable => new byte[] { 8, 1, 2, 3, 4, 5, 6, 7 };
public static ReadOnlySpan<byte> Ver3EyeColorTable => new byte[] { 8, 9, 10, 11, 12, 13 };
public static ReadOnlySpan<byte> Ver3MouthColorTable => new byte[] { 19, 20, 21, 22, 23 };
public static ReadOnlySpan<byte> Ver3GlassColorTable => new byte[] { 8, 14, 15, 16, 17, 18, 0 };
#pragma warning restore IDE0055
}
}

View File

@@ -18,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii
bool useHardcodedData = context.RequestData.ReadBoolean();
_imageCount = 0;
_isDirty = false;
_isDirty = false;
context.ResponseData.Write(_isDirty);
@@ -38,4 +38,4 @@ namespace Ryujinx.HLE.HOS.Services.Mii
return ResultCode.Success;
}
}
}
}

View File

@@ -8,13 +8,13 @@ namespace Ryujinx.HLE.HOS.Services.Mii
[Service("mii:u", false)]
class IStaticService : IpcService
{
private DatabaseImpl _databaseImpl;
private readonly DatabaseImpl _databaseImpl;
private bool _isSystem;
private readonly bool _isSystem;
public IStaticService(ServiceCtx context, bool isSystem)
{
_isSystem = isSystem;
_isSystem = isSystem;
_databaseImpl = DatabaseImpl.Instance;
}
@@ -29,4 +29,4 @@ namespace Ryujinx.HLE.HOS.Services.Mii
return ResultCode.Success;
}
}
}
}

View File

@@ -11,17 +11,17 @@ namespace Ryujinx.HLE.HOS.Services.Mii
{
class MiiDatabaseManager
{
private static bool IsTestModeEnabled = false;
private static uint MountCounter = 0;
private readonly bool _isTestModeEnabled = false;
private uint _mountCounter = 0;
private const ulong DatabaseTestSaveDataId = 0x8000000000000031;
private const ulong DatabaseSaveDataId = 0x8000000000000030;
private const ulong DatabaseTestSaveDataId = 0x8000000000000031;
private const ulong DatabaseSaveDataId = 0x8000000000000030;
private static U8String DatabasePath = new U8String("mii:/MiiDatabase.dat");
private static U8String MountName = new U8String("mii");
private readonly U8String _databasePath = new("mii:/MiiDatabase.dat");
private readonly U8String _mountName = new("mii");
private NintendoFigurineDatabase _database;
private bool _isDirty;
private bool _isDirty;
private HorizonClient _horizonClient;
@@ -29,8 +29,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii
public MiiDatabaseManager()
{
_database = new NintendoFigurineDatabase();
_isDirty = false;
_database = new NintendoFigurineDatabase();
_isDirty = false;
UpdateCounter = 0;
}
@@ -106,50 +106,63 @@ namespace Ryujinx.HLE.HOS.Services.Mii
private Result MountSave()
{
if (MountCounter != 0)
if (_mountCounter != 0)
{
MountCounter++;
_mountCounter++;
return Result.Success;
}
ulong saveDataId = IsTestModeEnabled ? DatabaseTestSaveDataId : DatabaseSaveDataId;
ulong saveDataId = _isTestModeEnabled ? DatabaseTestSaveDataId : DatabaseSaveDataId;
Result result = _horizonClient.Fs.MountSystemSaveData(MountName, SaveDataSpaceId.System, saveDataId);
Result result = _horizonClient.Fs.MountSystemSaveData(_mountName, SaveDataSpaceId.System, saveDataId);
if (result.IsFailure())
{
if (!ResultFs.TargetNotFound.Includes(result))
{
return result;
}
if (IsTestModeEnabled)
if (_isTestModeEnabled)
#pragma warning disable CS0162
{
result = _horizonClient.Fs.CreateSystemSaveData(saveDataId, 0x10000, 0x10000,
SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData);
if (result.IsFailure()) return result;
if (result.IsFailure())
{
return result;
}
}
#pragma warning restore CS0162
else
{
result = _horizonClient.Fs.CreateSystemSaveData(saveDataId, SystemProgramId.Ns.Value, 0x10000,
0x10000, SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData);
if (result.IsFailure()) return result;
if (result.IsFailure())
{
return result;
}
}
result = _horizonClient.Fs.MountSystemSaveData(MountName, SaveDataSpaceId.System, saveDataId);
if (result.IsFailure()) return result;
result = _horizonClient.Fs.MountSystemSaveData(_mountName, SaveDataSpaceId.System, saveDataId);
if (result.IsFailure())
{
return result;
}
}
if (result == Result.Success)
{
MountCounter++;
_mountCounter++;
}
return result;
}
public ResultCode DeleteFile()
{
ResultCode result = (ResultCode)_horizonClient.Fs.DeleteFile(DatabasePath).Value;
ResultCode result = (ResultCode)_horizonClient.Fs.DeleteFile(_databasePath).Value;
_horizonClient.Fs.Commit(MountName);
_horizonClient.Fs.Commit(_mountName);
return result;
}
@@ -158,7 +171,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii
{
isBroken = false;
if (MountCounter == 0)
if (_mountCounter == 0)
{
return ResultCode.InvalidArgument;
}
@@ -167,7 +180,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii
ResetDatabase();
Result result = _horizonClient.Fs.OpenFile(out FileHandle handle, DatabasePath, OpenMode.Read);
Result result = _horizonClient.Fs.OpenFile(out FileHandle handle, _databasePath, OpenMode.Read);
if (result.IsSuccess())
{
@@ -213,11 +226,11 @@ namespace Ryujinx.HLE.HOS.Services.Mii
private Result ForceSaveDatabase()
{
Result result = _horizonClient.Fs.CreateFile(DatabasePath, Unsafe.SizeOf<NintendoFigurineDatabase>());
Result result = _horizonClient.Fs.CreateFile(_databasePath, Unsafe.SizeOf<NintendoFigurineDatabase>());
if (result.IsSuccess() || ResultFs.PathAlreadyExists.Includes(result))
{
result = _horizonClient.Fs.OpenFile(out FileHandle handle, DatabasePath, OpenMode.Write);
result = _horizonClient.Fs.OpenFile(out FileHandle handle, _databasePath, OpenMode.Write);
if (result.IsSuccess())
{
@@ -230,15 +243,15 @@ namespace Ryujinx.HLE.HOS.Services.Mii
{
_horizonClient.Fs.CloseFile(handle);
result = _horizonClient.Fs.DeleteFile(DatabasePath);
result = _horizonClient.Fs.DeleteFile(_databasePath);
if (result.IsSuccess())
{
result = _horizonClient.Fs.CreateFile(DatabasePath, Unsafe.SizeOf<NintendoFigurineDatabase>());
result = _horizonClient.Fs.CreateFile(_databasePath, Unsafe.SizeOf<NintendoFigurineDatabase>());
if (result.IsSuccess())
{
result = _horizonClient.Fs.OpenFile(out handle, DatabasePath, OpenMode.Write);
result = _horizonClient.Fs.OpenFile(out handle, _databasePath, OpenMode.Write);
}
}
@@ -259,7 +272,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii
{
_isDirty = false;
result = _horizonClient.Fs.Commit(MountName);
result = _horizonClient.Fs.Commit(_mountName);
}
return result;

View File

@@ -2,29 +2,29 @@
{
public enum ResultCode
{
ModuleId = 126,
ModuleId = 126,
ErrorCodeShift = 9,
Success = 0,
InvalidArgument = (1 << ErrorCodeShift) | ModuleId,
BufferTooSmall = (2 << ErrorCodeShift) | ModuleId,
NotUpdated = (3 << ErrorCodeShift) | ModuleId,
NotFound = (4 << ErrorCodeShift) | ModuleId,
DatabaseFull = (5 << ErrorCodeShift) | ModuleId,
InvalidDatabaseSignatureValue = (67 << ErrorCodeShift) | ModuleId,
InvalidDatabaseEntryCount = (69 << ErrorCodeShift) | ModuleId,
InvalidCharInfo = (100 << ErrorCodeShift) | ModuleId,
InvalidCrc = (101 << ErrorCodeShift) | ModuleId,
InvalidDeviceCrc = (102 << ErrorCodeShift) | ModuleId,
InvalidDatabaseMagic = (103 << ErrorCodeShift) | ModuleId,
InvalidDatabaseVersion = (104 << ErrorCodeShift) | ModuleId,
InvalidDatabaseSize = (105 << ErrorCodeShift) | ModuleId,
InvalidCreateId = (106 << ErrorCodeShift) | ModuleId,
InvalidCoreData = (108 << ErrorCodeShift) | ModuleId,
InvalidStoreData = (109 << ErrorCodeShift) | ModuleId,
InvalidOperationOnSpecialMii = (202 << ErrorCodeShift) | ModuleId,
PermissionDenied = (203 << ErrorCodeShift) | ModuleId,
TestModeNotEnabled = (204 << ErrorCodeShift) | ModuleId
InvalidArgument = (1 << ErrorCodeShift) | ModuleId,
BufferTooSmall = (2 << ErrorCodeShift) | ModuleId,
NotUpdated = (3 << ErrorCodeShift) | ModuleId,
NotFound = (4 << ErrorCodeShift) | ModuleId,
DatabaseFull = (5 << ErrorCodeShift) | ModuleId,
InvalidDatabaseSignatureValue = (67 << ErrorCodeShift) | ModuleId,
InvalidDatabaseEntryCount = (69 << ErrorCodeShift) | ModuleId,
InvalidCharInfo = (100 << ErrorCodeShift) | ModuleId,
InvalidCrc = (101 << ErrorCodeShift) | ModuleId,
InvalidDeviceCrc = (102 << ErrorCodeShift) | ModuleId,
InvalidDatabaseMagic = (103 << ErrorCodeShift) | ModuleId,
InvalidDatabaseVersion = (104 << ErrorCodeShift) | ModuleId,
InvalidDatabaseSize = (105 << ErrorCodeShift) | ModuleId,
InvalidCreateId = (106 << ErrorCodeShift) | ModuleId,
InvalidCoreData = (108 << ErrorCodeShift) | ModuleId,
InvalidStoreData = (109 << ErrorCodeShift) | ModuleId,
InvalidOperationOnSpecialMii = (202 << ErrorCodeShift) | ModuleId,
PermissionDenied = (203 << ErrorCodeShift) | ModuleId,
TestModeNotEnabled = (204 << ErrorCodeShift) | ModuleId,
}
}

View File

@@ -6,9 +6,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
{
class DatabaseServiceImpl : IDatabaseService
{
private DatabaseImpl _database;
private DatabaseSessionMetadata _metadata;
private bool _isSystem;
private readonly DatabaseImpl _database;
private readonly DatabaseSessionMetadata _metadata;
private readonly bool _isSystem;
public DatabaseServiceImpl(DatabaseImpl database, bool isSystem, SpecialMiiKeyCode miiKeyCode)
{

View File

@@ -51,7 +51,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
ResultCode result = Get(flag, out int count, elementsSpan);
elementsSpan = elementsSpan.Slice(0, count);
elementsSpan = elementsSpan[..count];
context.ResponseData.Write(count);
@@ -72,7 +72,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
ResultCode result = Get1(flag, out int count, elementsSpan);
elementsSpan = elementsSpan.Slice(0, count);
elementsSpan = elementsSpan[..count];
context.ResponseData.Write(count);
@@ -85,8 +85,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
// UpdateLatest(nn::mii::CharInfo old_char_info, SourceFlag flag) -> nn::mii::CharInfo
public ResultCode UpdateLatest(ServiceCtx context)
{
CharInfo oldCharInfo = context.RequestData.ReadStruct<CharInfo>();
SourceFlag flag = (SourceFlag)context.RequestData.ReadInt32();
CharInfo oldCharInfo = context.RequestData.ReadStruct<CharInfo>();
SourceFlag flag = (SourceFlag)context.RequestData.ReadInt32();
ResultCode result = UpdateLatest(oldCharInfo, flag, out CharInfo newCharInfo);
@@ -99,9 +99,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
// BuildRandom(Age age, Gender gender, Race race) -> nn::mii::CharInfo
public ResultCode BuildRandom(ServiceCtx context)
{
Age age = (Age)context.RequestData.ReadInt32();
Age age = (Age)context.RequestData.ReadInt32();
Gender gender = (Gender)context.RequestData.ReadInt32();
Race race = (Race)context.RequestData.ReadInt32();
Race race = (Race)context.RequestData.ReadInt32();
ResultCode result = BuildRandom(age, gender, race, out CharInfo charInfo);
@@ -135,7 +135,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
ResultCode result = Get2(flag, out int count, elementsSpan);
elementsSpan = elementsSpan.Slice(0, count);
elementsSpan = elementsSpan[..count];
context.ResponseData.Write(count);
@@ -156,7 +156,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
ResultCode result = Get3(flag, out int count, elementsSpan);
elementsSpan = elementsSpan.Slice(0, count);
elementsSpan = elementsSpan[..count];
context.ResponseData.Write(count);
@@ -169,8 +169,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
// UpdateLatest1(nn::mii::StoreData old_store_data, SourceFlag flag) -> nn::mii::StoreData
public ResultCode UpdateLatest1(ServiceCtx context)
{
StoreData oldStoreData = context.RequestData.ReadStruct<StoreData>();
SourceFlag flag = (SourceFlag)context.RequestData.ReadInt32();
StoreData oldStoreData = context.RequestData.ReadStruct<StoreData>();
SourceFlag flag = (SourceFlag)context.RequestData.ReadInt32();
ResultCode result = UpdateLatest1(oldStoreData, flag, out StoreData newStoreData);
@@ -183,8 +183,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
// FindIndex(nn::mii::CreateId create_id, bool is_special) -> s32
public ResultCode FindIndex(ServiceCtx context)
{
CreateId createId = context.RequestData.ReadStruct<CreateId>();
bool isSpecial = context.RequestData.ReadBoolean();
CreateId createId = context.RequestData.ReadStruct<CreateId>();
bool isSpecial = context.RequestData.ReadBoolean();
ResultCode result = FindIndex(createId, isSpecial, out int index);
@@ -198,7 +198,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
public ResultCode Move(ServiceCtx context)
{
CreateId createId = context.RequestData.ReadStruct<CreateId>();
int newIndex = context.RequestData.ReadInt32();
int newIndex = context.RequestData.ReadInt32();
return Move(createId, newIndex);
}
@@ -358,12 +358,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
return new Span<byte>(rawData);
}
private Span<T> CreateSpanFromBuffer<T>(ServiceCtx context, IpcBuffDesc ipcBuff, bool isOutput) where T: unmanaged
private Span<T> CreateSpanFromBuffer<T>(ServiceCtx context, IpcBuffDesc ipcBuff, bool isOutput) where T : unmanaged
{
return MemoryMarshal.Cast<byte, T>(CreateByteSpanFromBuffer(context, ipcBuff, isOutput));
}
private void WriteSpanToBuffer<T>(ServiceCtx context, IpcBuffDesc ipcBuff, Span<T> span) where T: unmanaged
private void WriteSpanToBuffer<T>(ServiceCtx context, IpcBuffDesc ipcBuff, Span<T> span) where T : unmanaged
{
Span<byte> rawData = MemoryMarshal.Cast<T, byte>(span);

View File

@@ -5,6 +5,6 @@
Young,
Normal,
Old,
All
All,
}
}

View File

@@ -9,7 +9,7 @@
LionsMane,
Full,
Min = 0,
Max = 5
Min = None,
Max = Full,
}
}

View File

@@ -59,11 +59,11 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public byte MoleY;
public byte Reserved;
byte IStoredData<CharInfo>.Type => Type;
readonly byte IStoredData<CharInfo>.Type => Type;
CreateId IStoredData<CharInfo>.CreateId => CreateId;
readonly CreateId IStoredData<CharInfo>.CreateId => CreateId;
public ResultCode InvalidData => ResultCode.InvalidCharInfo;
public readonly ResultCode InvalidData => ResultCode.InvalidCharInfo;
public bool IsValid()
{
@@ -72,118 +72,271 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public uint Verify()
{
if (!CreateId.IsValid) return 50;
if (!Nickname.IsValid()) return 51;
if ((byte)FontRegion > 3) return 23;
if (FavoriteColor > 11) return 22;
if (Gender > Gender.Max) return 24;
if ((sbyte)Height < 0) return 32;
if ((sbyte)Build < 0) return 3;
if (Type > 1) return 53;
if (RegionMove > 3) return 49;
if (FacelineType > FacelineType.Max) return 21;
if (FacelineColor > FacelineColor.Max) return 18;
if (FacelineWrinkle > FacelineWrinkle.Max) return 20;
if (FacelineMake > FacelineMake.Max) return 19;
if (HairType > HairType.Max) return 31;
if (HairColor > CommonColor.Max) return 29;
if (HairFlip > HairFlip.Max) return 30;
if (EyeType > EyeType.Max) return 8;
if (EyeColor > CommonColor.Max) return 5;
if (EyeScale > 7) return 7;
if (EyeAspect > 6) return 4;
if (EyeRotate > 7) return 6;
if (EyeX > 12) return 9;
if (EyeY > 18) return 10;
if (EyebrowType > EyebrowType.Max) return 15;
if (EyebrowColor > CommonColor.Max) return 12;
if (EyebrowScale > 8) return 14;
if (EyebrowAspect > 6) return 11;
if (EyebrowRotate > 11) return 13;
if (EyebrowX > 12) return 16;
if (EyebrowY - 3 > 15) return 17;
if (NoseType > NoseType.Max) return 47;
if (NoseScale > 8) return 46;
if (NoseY> 18) return 48;
if (MouthType > MouthType.Max) return 40;
if (MouthColor > CommonColor.Max) return 38;
if (MouthScale > 8) return 39;
if (MouthAspect > 6) return 37;
if (MouthY > 18) return 41;
if (BeardColor > CommonColor.Max) return 1;
if (BeardType > BeardType.Max) return 2;
if (MustacheType > MustacheType.Max) return 43;
if (MustacheScale > 8) return 42;
if (MustacheY > 16) return 44;
if (GlassType > GlassType.Max) return 27;
if (GlassColor > CommonColor.Max) return 25;
if (GlassScale > 7) return 26;
if (GlassY > 20) return 28;
if (MoleType > MoleType.Max) return 34;
if (MoleScale > 8) return 33;
if (MoleX > 16) return 35;
if (MoleY >= 31) return 36;
if (!CreateId.IsValid)
{
return 50;
}
if (!Nickname.IsValid())
{
return 51;
}
if ((byte)FontRegion > 3)
{
return 23;
}
if (FavoriteColor > 11)
{
return 22;
}
if (Gender > Gender.Max)
{
return 24;
}
if ((sbyte)Height < 0)
{
return 32;
}
if ((sbyte)Build < 0)
{
return 3;
}
if (Type > 1)
{
return 53;
}
if (RegionMove > 3)
{
return 49;
}
if (FacelineType > FacelineType.Max)
{
return 21;
}
if (FacelineColor > FacelineColor.Max)
{
return 18;
}
if (FacelineWrinkle > FacelineWrinkle.Max)
{
return 20;
}
if (FacelineMake > FacelineMake.Max)
{
return 19;
}
if (HairType > HairType.Max)
{
return 31;
}
if (HairColor > CommonColor.Max)
{
return 29;
}
if (HairFlip > HairFlip.Max)
{
return 30;
}
if (EyeType > EyeType.Max)
{
return 8;
}
if (EyeColor > CommonColor.Max)
{
return 5;
}
if (EyeScale > 7)
{
return 7;
}
if (EyeAspect > 6)
{
return 4;
}
if (EyeRotate > 7)
{
return 6;
}
if (EyeX > 12)
{
return 9;
}
if (EyeY > 18)
{
return 10;
}
if (EyebrowType > EyebrowType.Max)
{
return 15;
}
if (EyebrowColor > CommonColor.Max)
{
return 12;
}
if (EyebrowScale > 8)
{
return 14;
}
if (EyebrowAspect > 6)
{
return 11;
}
if (EyebrowRotate > 11)
{
return 13;
}
if (EyebrowX > 12)
{
return 16;
}
if (EyebrowY - 3 > 15)
{
return 17;
}
if (NoseType > NoseType.Max)
{
return 47;
}
if (NoseScale > 8)
{
return 46;
}
if (NoseY > 18)
{
return 48;
}
if (MouthType > MouthType.Max)
{
return 40;
}
if (MouthColor > CommonColor.Max)
{
return 38;
}
if (MouthScale > 8)
{
return 39;
}
if (MouthAspect > 6)
{
return 37;
}
if (MouthY > 18)
{
return 41;
}
if (BeardColor > CommonColor.Max)
{
return 1;
}
if (BeardType > BeardType.Max)
{
return 2;
}
if (MustacheType > MustacheType.Max)
{
return 43;
}
if (MustacheScale > 8)
{
return 42;
}
if (MustacheY > 16)
{
return 44;
}
if (GlassType > GlassType.Max)
{
return 27;
}
if (GlassColor > CommonColor.Max)
{
return 25;
}
if (GlassScale > 7)
{
return 26;
}
if (GlassY > 20)
{
return 28;
}
if (MoleType > MoleType.Max)
{
return 34;
}
if (MoleScale > 8)
{
return 33;
}
if (MoleX > 16)
{
return 35;
}
if (MoleY >= 31)
{
return 36;
}
return 0;
}
public void SetFromStoreData(StoreData storeData)
{
Nickname = storeData.CoreData.Nickname;
CreateId = storeData.CreateId;
FontRegion = storeData.CoreData.FontRegion;
FavoriteColor = storeData.CoreData.FavoriteColor;
Gender = storeData.CoreData.Gender;
Height = storeData.CoreData.Height;
Build = storeData.CoreData.Build;
Type = storeData.CoreData.Type;
RegionMove = storeData.CoreData.RegionMove;
FacelineType = storeData.CoreData.FacelineType;
FacelineColor = storeData.CoreData.FacelineColor;
Nickname = storeData.CoreData.Nickname;
CreateId = storeData.CreateId;
FontRegion = storeData.CoreData.FontRegion;
FavoriteColor = storeData.CoreData.FavoriteColor;
Gender = storeData.CoreData.Gender;
Height = storeData.CoreData.Height;
Build = storeData.CoreData.Build;
Type = storeData.CoreData.Type;
RegionMove = storeData.CoreData.RegionMove;
FacelineType = storeData.CoreData.FacelineType;
FacelineColor = storeData.CoreData.FacelineColor;
FacelineWrinkle = storeData.CoreData.FacelineWrinkle;
FacelineMake = storeData.CoreData.FacelineMake;
HairType = storeData.CoreData.HairType;
HairColor = storeData.CoreData.HairColor;
HairFlip = storeData.CoreData.HairFlip;
EyeType = storeData.CoreData.EyeType;
EyeColor = storeData.CoreData.EyeColor;
EyeScale = storeData.CoreData.EyeScale;
EyeAspect = storeData.CoreData.EyeAspect;
EyeRotate = storeData.CoreData.EyeRotate;
EyeX = storeData.CoreData.EyeX;
EyeY = storeData.CoreData.EyeY;
EyebrowType = storeData.CoreData.EyebrowType;
EyebrowColor = storeData.CoreData.EyebrowColor;
EyebrowScale = storeData.CoreData.EyebrowScale;
EyebrowAspect = storeData.CoreData.EyebrowAspect;
EyebrowRotate = storeData.CoreData.EyebrowRotate;
EyebrowX = storeData.CoreData.EyebrowX;
EyebrowY = storeData.CoreData.EyebrowY;
NoseType = storeData.CoreData.NoseType;
NoseScale = storeData.CoreData.NoseScale;
NoseY = storeData.CoreData.NoseY;
MouthType = storeData.CoreData.MouthType;
MouthColor = storeData.CoreData.MouthColor;
MouthScale = storeData.CoreData.MouthScale;
MouthAspect = storeData.CoreData.MouthAspect;
MouthY = storeData.CoreData.MouthY;
BeardColor = storeData.CoreData.BeardColor;
BeardType = storeData.CoreData.BeardType;
MustacheType = storeData.CoreData.MustacheType;
MustacheScale = storeData.CoreData.MustacheScale;
MustacheY = storeData.CoreData.MustacheY;
GlassType = storeData.CoreData.GlassType;
GlassColor = storeData.CoreData.GlassColor;
GlassScale = storeData.CoreData.GlassScale;
GlassY = storeData.CoreData.GlassY;
MoleType = storeData.CoreData.MoleType;
MoleScale = storeData.CoreData.MoleScale;
MoleX = storeData.CoreData.MoleX;
MoleY = storeData.CoreData.MoleY;
Reserved = 0;
FacelineMake = storeData.CoreData.FacelineMake;
HairType = storeData.CoreData.HairType;
HairColor = storeData.CoreData.HairColor;
HairFlip = storeData.CoreData.HairFlip;
EyeType = storeData.CoreData.EyeType;
EyeColor = storeData.CoreData.EyeColor;
EyeScale = storeData.CoreData.EyeScale;
EyeAspect = storeData.CoreData.EyeAspect;
EyeRotate = storeData.CoreData.EyeRotate;
EyeX = storeData.CoreData.EyeX;
EyeY = storeData.CoreData.EyeY;
EyebrowType = storeData.CoreData.EyebrowType;
EyebrowColor = storeData.CoreData.EyebrowColor;
EyebrowScale = storeData.CoreData.EyebrowScale;
EyebrowAspect = storeData.CoreData.EyebrowAspect;
EyebrowRotate = storeData.CoreData.EyebrowRotate;
EyebrowX = storeData.CoreData.EyebrowX;
EyebrowY = storeData.CoreData.EyebrowY;
NoseType = storeData.CoreData.NoseType;
NoseScale = storeData.CoreData.NoseScale;
NoseY = storeData.CoreData.NoseY;
MouthType = storeData.CoreData.MouthType;
MouthColor = storeData.CoreData.MouthColor;
MouthScale = storeData.CoreData.MouthScale;
MouthAspect = storeData.CoreData.MouthAspect;
MouthY = storeData.CoreData.MouthY;
BeardColor = storeData.CoreData.BeardColor;
BeardType = storeData.CoreData.BeardType;
MustacheType = storeData.CoreData.MustacheType;
MustacheScale = storeData.CoreData.MustacheScale;
MustacheY = storeData.CoreData.MustacheY;
GlassType = storeData.CoreData.GlassType;
GlassColor = storeData.CoreData.GlassColor;
GlassScale = storeData.CoreData.GlassScale;
GlassY = storeData.CoreData.GlassY;
MoleType = storeData.CoreData.MoleType;
MoleScale = storeData.CoreData.MoleScale;
MoleX = storeData.CoreData.MoleX;
MoleY = storeData.CoreData.MoleY;
Reserved = 0;
}
public void SetSource(Source source)
public readonly void SetSource(Source source)
{
// Only implemented for Element variants.
}
@@ -198,12 +351,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
return !x.Equals(y);
}
public override bool Equals(object obj)
public readonly override bool Equals(object obj)
{
return obj is CharInfo charInfo && Equals(charInfo);
}
public bool Equals(CharInfo cmpObj)
public readonly bool Equals(CharInfo cmpObj)
{
if (!cmpObj.IsValid())
{
@@ -267,9 +420,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
return result;
}
public override int GetHashCode()
public readonly override int GetHashCode()
{
HashCode hashCode = new HashCode();
HashCode hashCode = new();
hashCode.Add(Nickname);
hashCode.Add(CreateId);

View File

@@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
struct CharInfoElement : IElement
{
public CharInfo CharInfo;
public Source Source;
public Source Source;
public void SetFromStoreData(StoreData storeData)
{

View File

@@ -4,6 +4,6 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
enum CommonColor : byte
{
Min = 0,
Max = 99
Max = 99,
}
}

View File

@@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public void SetDefault()
{
Storage.Fill(0);
Storage.Clear();
Nickname = Nickname.Default;
}
@@ -374,18 +374,18 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public Span<byte> GetNicknameStorage()
{
return Storage.Slice(0x1c);
return Storage[0x1c..];
}
public Nickname Nickname
{
get => Nickname.FromBytes(GetNicknameStorage());
set => value.Raw.Slice(0, 20).CopyTo(GetNicknameStorage());
set => value.Raw[..20].CopyTo(GetNicknameStorage());
}
public static CoreData BuildRandom(UtilityImpl utilImpl, Age age, Gender gender, Race race)
{
CoreData coreData = new CoreData();
CoreData coreData = new();
coreData.SetDefault();
@@ -439,29 +439,29 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
int indexFor4 = 3 * (int)age + 9 * (int)gender + (int)race;
var facelineTypeInfo = RandomMiiFacelineArray[indexFor4];
var facelineColorInfo = RandomMiiFacelineColorArray[3 * (int)gender + (int)race];
var facelineTypeInfo = RandomMiiFacelineArray[indexFor4];
var facelineColorInfo = RandomMiiFacelineColorArray[3 * (int)gender + (int)race];
var facelineWrinkleInfo = RandomMiiFacelineWrinkleArray[indexFor4];
var facelineMakeInfo = RandomMiiFacelineMakeArray[indexFor4];
var hairTypeInfo = RandomMiiHairTypeArray[indexFor4];
var hairColorInfo = RandomMiiHairColorArray[3 * (int)race + (int)age];
var eyeTypeInfo = RandomMiiEyeTypeArray[indexFor4];
var eyeColorInfo = RandomMiiEyeColorArray[(int)race];
var eyebrowTypeInfo = RandomMiiEyebrowTypeArray[indexFor4];
var noseTypeInfo = RandomMiiNoseTypeArray[indexFor4];
var mouthTypeInfo = RandomMiiMouthTypeArray[indexFor4];
var glassTypeInfo = RandomMiiGlassTypeArray[(int)age];
var facelineMakeInfo = RandomMiiFacelineMakeArray[indexFor4];
var hairTypeInfo = RandomMiiHairTypeArray[indexFor4];
var hairColorInfo = RandomMiiHairColorArray[3 * (int)race + (int)age];
var eyeTypeInfo = RandomMiiEyeTypeArray[indexFor4];
var eyeColorInfo = RandomMiiEyeColorArray[(int)race];
var eyebrowTypeInfo = RandomMiiEyebrowTypeArray[indexFor4];
var noseTypeInfo = RandomMiiNoseTypeArray[indexFor4];
var mouthTypeInfo = RandomMiiMouthTypeArray[indexFor4];
var glassTypeInfo = RandomMiiGlassTypeArray[(int)age];
// Faceline
coreData.FacelineType = (FacelineType)facelineTypeInfo.Values[utilImpl.GetRandom(facelineTypeInfo.ValuesCount)];
coreData.FacelineColor = (FacelineColor)Helper.Ver3FacelineColorTable[facelineColorInfo.Values[utilImpl.GetRandom(facelineColorInfo.ValuesCount)]];
coreData.FacelineType = (FacelineType)facelineTypeInfo.Values[utilImpl.GetRandom(facelineTypeInfo.ValuesCount)];
coreData.FacelineColor = (FacelineColor)Helper.Ver3FacelineColorTable[facelineColorInfo.Values[utilImpl.GetRandom(facelineColorInfo.ValuesCount)]];
coreData.FacelineWrinkle = (FacelineWrinkle)facelineWrinkleInfo.Values[utilImpl.GetRandom(facelineWrinkleInfo.ValuesCount)];
coreData.FacelineMake = (FacelineMake)facelineMakeInfo.Values[utilImpl.GetRandom(facelineMakeInfo.ValuesCount)];
coreData.FacelineMake = (FacelineMake)facelineMakeInfo.Values[utilImpl.GetRandom(facelineMakeInfo.ValuesCount)];
// Hair
coreData.HairType = (HairType)hairTypeInfo.Values[utilImpl.GetRandom(hairTypeInfo.ValuesCount)];
coreData.HairType = (HairType)hairTypeInfo.Values[utilImpl.GetRandom(hairTypeInfo.ValuesCount)];
coreData.HairColor = (CommonColor)Helper.Ver3HairColorTable[hairColorInfo.Values[utilImpl.GetRandom(hairColorInfo.ValuesCount)]];
coreData.HairFlip = (HairFlip)utilImpl.GetRandom((int)HairFlip.Max + 1);
coreData.HairFlip = (HairFlip)utilImpl.GetRandom((int)HairFlip.Max + 1);
// Eye
coreData.EyeType = (EyeType)eyeTypeInfo.Values[utilImpl.GetRandom(eyeTypeInfo.ValuesCount)];
@@ -470,56 +470,56 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
int eyeRotateKey2 = gender != Gender.Male ? 3 : 4;
byte eyeRotateOffset = (byte)(32 - EyeRotateTable[eyeRotateKey1] + eyeRotateKey2);
byte eyeRotate = (byte)(32 - EyeRotateTable[(int)coreData.EyeType]);
byte eyeRotate = (byte)(32 - EyeRotateTable[(int)coreData.EyeType]);
coreData.EyeColor = (CommonColor)Helper.Ver3EyeColorTable[eyeColorInfo.Values[utilImpl.GetRandom(eyeColorInfo.ValuesCount)]];
coreData.EyeScale = 4;
coreData.EyeColor = (CommonColor)Helper.Ver3EyeColorTable[eyeColorInfo.Values[utilImpl.GetRandom(eyeColorInfo.ValuesCount)]];
coreData.EyeScale = 4;
coreData.EyeAspect = 3;
coreData.EyeRotate = (byte)(eyeRotateOffset - eyeRotate);
coreData.EyeX = 2;
coreData.EyeY = (byte)(axisY + 12);
coreData.EyeX = 2;
coreData.EyeY = (byte)(axisY + 12);
// Eyebrow
coreData.EyebrowType = (EyebrowType)eyebrowTypeInfo.Values[utilImpl.GetRandom(eyebrowTypeInfo.ValuesCount)];
int eyebrowRotateKey = race == Race.Asian ? 6 : 0;
int eyebrowY = race == Race.Asian ? 9 : 10;
int eyebrowY = race == Race.Asian ? 9 : 10;
byte eyebrowRotateOffset = (byte)(32 - EyebrowRotateTable[eyebrowRotateKey] + 6);
byte eyebrowRotate = (byte)(32 - EyebrowRotateTable[(int)coreData.EyebrowType]);
byte eyebrowRotate = (byte)(32 - EyebrowRotateTable[(int)coreData.EyebrowType]);
coreData.EyebrowColor = coreData.HairColor;
coreData.EyebrowScale = 4;
coreData.EyebrowColor = coreData.HairColor;
coreData.EyebrowScale = 4;
coreData.EyebrowAspect = 3;
coreData.EyebrowRotate = (byte)(eyebrowRotateOffset - eyebrowRotate);
coreData.EyebrowX = 2;
coreData.EyebrowY = (byte)(axisY + eyebrowY);
coreData.EyebrowX = 2;
coreData.EyebrowY = (byte)(axisY + eyebrowY);
// Nose
int noseScale = gender == Gender.Female ? 3 : 4;
coreData.NoseType = (NoseType)noseTypeInfo.Values[utilImpl.GetRandom(noseTypeInfo.ValuesCount)];
coreData.NoseType = (NoseType)noseTypeInfo.Values[utilImpl.GetRandom(noseTypeInfo.ValuesCount)];
coreData.NoseScale = (byte)noseScale;
coreData.NoseY = (byte)(axisY + 9);
coreData.NoseY = (byte)(axisY + 9);
// Mouth
int mouthColor = gender == Gender.Female ? utilImpl.GetRandom(0, 4) : 0;
coreData.MouthType = (MouthType)mouthTypeInfo.Values[utilImpl.GetRandom(mouthTypeInfo.ValuesCount)];
coreData.MouthColor = (CommonColor)Helper.Ver3MouthColorTable[mouthColor];
coreData.MouthScale = 4;
coreData.MouthType = (MouthType)mouthTypeInfo.Values[utilImpl.GetRandom(mouthTypeInfo.ValuesCount)];
coreData.MouthColor = (CommonColor)Helper.Ver3MouthColorTable[mouthColor];
coreData.MouthScale = 4;
coreData.MouthAspect = 3;
coreData.MouthY = (byte)(axisY + 13);
coreData.MouthY = (byte)(axisY + 13);
// Beard & Mustache
coreData.BeardColor = coreData.HairColor;
coreData.BeardColor = coreData.HairColor;
coreData.MustacheScale = 4;
if (gender == Gender.Male && age != Age.Young && utilImpl.GetRandom(10) < 2)
{
BeardAndMustacheFlag mustacheAndBeardFlag = (BeardAndMustacheFlag)utilImpl.GetRandom(3);
BeardType beardType = BeardType.None;
BeardType beardType = BeardType.None;
MustacheType mustacheType = MustacheType.None;
if ((mustacheAndBeardFlag & BeardAndMustacheFlag.Beard) == BeardAndMustacheFlag.Beard)
@@ -533,14 +533,14 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
}
coreData.MustacheType = mustacheType;
coreData.BeardType = beardType;
coreData.MustacheY = 10;
coreData.BeardType = beardType;
coreData.MustacheY = 10;
}
else
{
coreData.MustacheType = MustacheType.None;
coreData.BeardType = BeardType.None;
coreData.MustacheY = (byte)(axisY + 10);
coreData.BeardType = BeardType.None;
coreData.MustacheY = (byte)(axisY + 10);
}
// Glass
@@ -557,84 +557,84 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
}
}
coreData.GlassType = glassType;
coreData.GlassType = glassType;
coreData.GlassColor = (CommonColor)Helper.Ver3GlassColorTable[0];
coreData.GlassScale = 4;
coreData.GlassY = (byte)(axisY + 10);
coreData.GlassY = (byte)(axisY + 10);
// Mole
coreData.MoleType = 0;
coreData.MoleType = 0;
coreData.MoleScale = 4;
coreData.MoleX = 2;
coreData.MoleY = 20;
coreData.MoleX = 2;
coreData.MoleY = 20;
// Body sizing
coreData.Height = 64;
coreData.Build = 64;
coreData.Build = 64;
// Misc
coreData.Nickname = Nickname.Default;
coreData.Gender = gender;
coreData.Nickname = Nickname.Default;
coreData.Gender = gender;
coreData.FavoriteColor = (byte)utilImpl.GetRandom(0, 11);
coreData.RegionMove = 0;
coreData.FontRegion = 0;
coreData.Type = 0;
coreData.RegionMove = 0;
coreData.FontRegion = 0;
coreData.Type = 0;
return coreData;
}
public void SetFromCharInfo(CharInfo charInfo)
{
Nickname = charInfo.Nickname;
FontRegion = charInfo.FontRegion;
FavoriteColor = charInfo.FavoriteColor;
Gender = charInfo.Gender;
Height = charInfo.Height;
Build = charInfo.Build;
Type = charInfo.Type;
RegionMove = charInfo.RegionMove;
FacelineType = charInfo.FacelineType;
FacelineColor = charInfo.FacelineColor;
Nickname = charInfo.Nickname;
FontRegion = charInfo.FontRegion;
FavoriteColor = charInfo.FavoriteColor;
Gender = charInfo.Gender;
Height = charInfo.Height;
Build = charInfo.Build;
Type = charInfo.Type;
RegionMove = charInfo.RegionMove;
FacelineType = charInfo.FacelineType;
FacelineColor = charInfo.FacelineColor;
FacelineWrinkle = charInfo.FacelineWrinkle;
FacelineMake = charInfo.FacelineMake;
HairType = charInfo.HairType;
HairColor = charInfo.HairColor;
HairFlip = charInfo.HairFlip;
EyeType = charInfo.EyeType;
EyeColor = charInfo.EyeColor;
EyeScale = charInfo.EyeScale;
EyeAspect = charInfo.EyeAspect;
EyeRotate = charInfo.EyeRotate;
EyeX = charInfo.EyeX;
EyeY = charInfo.EyeY;
EyebrowType = charInfo.EyebrowType;
EyebrowColor = charInfo.EyebrowColor;
EyebrowScale = charInfo.EyebrowScale;
EyebrowAspect = charInfo.EyebrowAspect;
EyebrowRotate = charInfo.EyebrowRotate;
EyebrowX = charInfo.EyebrowX;
EyebrowY = charInfo.EyebrowY;
NoseType = charInfo.NoseType;
NoseScale = charInfo.NoseScale;
NoseY = charInfo.NoseY;
MouthType = charInfo.MouthType;
MouthColor = charInfo.MouthColor;
MouthScale = charInfo.MouthScale;
MouthAspect = charInfo.MouthAspect;
MouthY = charInfo.MouthY;
BeardColor = charInfo.BeardColor;
BeardType = charInfo.BeardType;
MustacheType = charInfo.MustacheType;
MustacheScale = charInfo.MustacheScale;
MustacheY = charInfo.MustacheY;
GlassType = charInfo.GlassType;
GlassColor = charInfo.GlassColor;
GlassScale = charInfo.GlassScale;
GlassY = charInfo.GlassY;
MoleType = charInfo.MoleType;
MoleScale = charInfo.MoleScale;
MoleX = charInfo.MoleX;
MoleY = charInfo.MoleY;
FacelineMake = charInfo.FacelineMake;
HairType = charInfo.HairType;
HairColor = charInfo.HairColor;
HairFlip = charInfo.HairFlip;
EyeType = charInfo.EyeType;
EyeColor = charInfo.EyeColor;
EyeScale = charInfo.EyeScale;
EyeAspect = charInfo.EyeAspect;
EyeRotate = charInfo.EyeRotate;
EyeX = charInfo.EyeX;
EyeY = charInfo.EyeY;
EyebrowType = charInfo.EyebrowType;
EyebrowColor = charInfo.EyebrowColor;
EyebrowScale = charInfo.EyebrowScale;
EyebrowAspect = charInfo.EyebrowAspect;
EyebrowRotate = charInfo.EyebrowRotate;
EyebrowX = charInfo.EyebrowX;
EyebrowY = charInfo.EyebrowY;
NoseType = charInfo.NoseType;
NoseScale = charInfo.NoseScale;
NoseY = charInfo.NoseY;
MouthType = charInfo.MouthType;
MouthColor = charInfo.MouthColor;
MouthScale = charInfo.MouthScale;
MouthAspect = charInfo.MouthAspect;
MouthY = charInfo.MouthY;
BeardColor = charInfo.BeardColor;
BeardType = charInfo.BeardType;
MustacheType = charInfo.MustacheType;
MustacheScale = charInfo.MustacheScale;
MustacheY = charInfo.MustacheY;
GlassType = charInfo.GlassType;
GlassColor = charInfo.GlassColor;
GlassScale = charInfo.GlassScale;
GlassY = charInfo.GlassY;
MoleType = charInfo.MoleType;
MoleScale = charInfo.MoleScale;
MoleX = charInfo.MoleX;
MoleY = charInfo.MoleY;
}
public static bool operator ==(CoreData x, CoreData y)
@@ -717,7 +717,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public override int GetHashCode()
{
HashCode hashCode = new HashCode();
HashCode hashCode = new();
hashCode.Add(Nickname);
hashCode.Add(FontRegion);
@@ -773,7 +773,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
return hashCode.ToHashCode();
}
private static ReadOnlySpan<ElementInfo> ElementInfos => MemoryMarshal.Cast<byte, ElementInfo>(ElementInfoArray);
private readonly ReadOnlySpan<ElementInfo> ElementInfos => MemoryMarshal.Cast<byte, ElementInfo>(ElementInfoArray);
private enum ElementInfoIndex
{
@@ -825,11 +825,11 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
NoseScale,
MouthScale,
MustacheScale,
MoleScale
MoleScale,
}
#region "Element Info Array"
private static ReadOnlySpan<byte> ElementInfoArray => new byte[]
private readonly ReadOnlySpan<byte> ElementInfoArray => new byte[]
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x83, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -904,7 +904,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x1b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
};
#endregion
}

View File

@@ -4,12 +4,12 @@ using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Mii.Types
{
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x10)]
struct CreateId : IEquatable<CreateId>
readonly struct CreateId : IEquatable<CreateId>
{
public readonly UInt128 Raw;
public bool IsNull => Raw == UInt128.Zero;
public bool IsValid => !IsNull && ((Raw >> 64) & 0xC0) == 0x80;
public readonly bool IsNull => Raw == UInt128.Zero;
public readonly bool IsValid => !IsNull && ((Raw >> 64) & 0xC0) == 0x80;
public CreateId(UInt128 raw)
{
@@ -26,18 +26,18 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
return !x.Equals(y);
}
public override bool Equals(object obj)
public readonly override bool Equals(object obj)
{
return obj is CreateId createId && Equals(createId);
}
public bool Equals(CreateId cmpObj)
public readonly bool Equals(CreateId cmpObj)
{
// Nintendo additionally check that the CreatorId is valid before doing the actual comparison.
return IsValid && Raw == cmpObj.Raw;
}
public override int GetHashCode()
public readonly override int GetHashCode()
{
return Raw.GetHashCode();
}

View File

@@ -65,7 +65,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public Nickname Nickname
{
get => Nickname.FromBytes(NicknameStorage);
set => value.Raw.Slice(0, 20).CopyTo(NicknameStorage);
set => value.Raw[..20].CopyTo(NicknameStorage);
}
public static ReadOnlySpan<DefaultMii> Table => MemoryMarshal.Cast<byte, DefaultMii>(TableRawArray);
@@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
// The first 2 Mii in the default table are used as base for Male/Female in editor but not exposed via IPC.
public static int TableLength => _fromIndex.Length;
private static readonly int[] _fromIndex = new int[] { 2, 3, 4, 5, 6, 7 };
private static readonly int[] _fromIndex = { 2, 3, 4, 5, 6, 7 };
public static DefaultMii GetDefaultMii(uint index)
{
@@ -190,7 +190,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x6f, 0x00,
0x20, 0x00, 0x6e, 0x00, 0x61, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x20, 0x00, 0x6e, 0x00, 0x61, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
#endregion
}

View File

@@ -63,7 +63,7 @@
RoundTired,
WhiteLarge,
Min = 0,
Max = 59
Min = Normal,
Max = WhiteLarge,
}
}

View File

@@ -27,7 +27,7 @@
Dotted,
None,
Min = 0,
Max = 23
Min = FlatAngledLarge,
Max = None,
}
}

View File

@@ -13,7 +13,7 @@
Almond,
Espresso,
Min = 0,
Max = 9
Min = Beige,
Max = Espresso,
}
}

View File

@@ -15,7 +15,7 @@
LionsManeBeard,
StubbleBeard,
Min = 0,
Max = 11
Min = None,
Max = StubbleBeard,
}
}

View File

@@ -15,7 +15,7 @@
FlatRounded,
AngularSmall,
Min = 0,
Max = 11
Min = Sharp,
Max = AngularSmall,
}
}

View File

@@ -15,7 +15,7 @@
CrowsFeet,
FoldsCrowsFrown,
Min = 0,
Max = 11
Min = None,
Max = FoldsCrowsFrown,
}
}

View File

@@ -5,6 +5,6 @@
Standard,
China,
Korea,
Taiwan
Taiwan,
}
}

View File

@@ -6,7 +6,7 @@
Female,
All,
Min = 0,
Max = 1
Min = Male,
Max = Female,
}
}

View File

@@ -23,7 +23,7 @@
OpaqueRectangle,
OpaqueAviator,
Min = 0,
Max = 19
Min = None,
Max = OpaqueAviator,
}
}

View File

@@ -5,7 +5,7 @@
Left,
Right,
Min = 0,
Max = 1
Min = Left,
Max = Right,
}
}

View File

@@ -135,7 +135,7 @@
TwoLongSidedPonyTails,
LongFrontTwoBackPonyTails,
Min = 0,
Max = 131
Min = NormalLong,
Max = LongFrontTwoBackPonyTails,
}
}

View File

@@ -5,7 +5,7 @@
None,
OneDot,
Min = 0,
Max = 1
Min = None,
Max = OneDot,
}
}

View File

@@ -39,7 +39,7 @@
SmileDownLine,
Kiss,
Min = 0,
Max = 35
Min = Neutral,
Max = Kiss,
}
}

View File

@@ -9,7 +9,7 @@
Normal,
Toothbrush,
Min = 0,
Max = 5
Min = None,
Max = Toothbrush,
}
}

View File

@@ -48,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public bool IsValid()
{
// Create a new unicode encoding instance with error checking enabled
UnicodeEncoding unicodeEncoding = new UnicodeEncoding(false, false, true);
UnicodeEncoding unicodeEncoding = new(false, false, true);
try
{
@@ -77,10 +77,10 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
{
if (data.Length > SizeConst)
{
data = data.Slice(0, SizeConst);
data = data[..SizeConst];
}
Nickname result = new Nickname();
Nickname result = new();
data.CopyTo(result.Raw);

View File

@@ -25,19 +25,19 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
// Set to true to allow fixing database with invalid storedata device crc instead of deleting them.
private const bool AcceptInvalidDeviceCrc = true;
public int Length => _figurineCount;
public readonly int Length => _figurineCount;
[StructLayout(LayoutKind.Sequential, Size = FigurineArraySize)]
private struct FigurineStorageStruct { }
private Span<StoreData> Figurines => SpanHelpers.AsSpan<FigurineStorageStruct, StoreData>(ref _figurineStorage);
public StoreData Get(int index)
{
return Figurines[index];
}
public bool IsFull()
public readonly bool IsFull()
{
return Length >= MaxMii;
}
@@ -74,14 +74,14 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
if (newIndex < oldIndex)
{
targetLength = oldIndex - newIndex;
sourceIndex = newIndex;
targetLength = oldIndex - newIndex;
sourceIndex = newIndex;
destinationIndex = newIndex + 1;
}
else
{
targetLength = newIndex - oldIndex;
sourceIndex = oldIndex + 1;
targetLength = newIndex - oldIndex;
sourceIndex = oldIndex + 1;
destinationIndex = oldIndex;
}
@@ -113,8 +113,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
// If this isn't the only element in the list, move the data in it.
if (index < newCount)
{
int targetLength = newCount - index;
int sourceIndex = index + 1;
int targetLength = newCount - index;
int sourceIndex = index + 1;
int destinationIndex = index;
Figurines.Slice(sourceIndex, targetLength).CopyTo(Figurines.Slice(destinationIndex, targetLength));
@@ -204,12 +204,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public void Format()
{
_magic = DatabaseMagic;
_version = CurrentVersion;
_magic = DatabaseMagic;
_version = CurrentVersion;
_figurineCount = 0;
// Fill with empty data
Figurines.Fill(new StoreData());
Figurines.Clear();
UpdateCrc();
}
@@ -248,7 +248,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
private ReadOnlySpan<byte> AsSpanWithoutCrc()
{
return AsReadOnlySpan().Slice(0, Unsafe.SizeOf<NintendoFigurineDatabase>() - 2);
return AsReadOnlySpan()[..(Unsafe.SizeOf<NintendoFigurineDatabase>() - 2)];
}
}
}

View File

@@ -21,7 +21,7 @@
Droopy,
ArrowLarge,
Min = 0,
Max = 17
Min = Normal,
Max = ArrowLarge,
}
}

View File

@@ -5,6 +5,6 @@
Black,
White,
Asian,
All
All,
}
}

View File

@@ -6,25 +6,23 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
{
static class RandomMiiConstants
{
public static int[] EyeRotateTable = new int[]
{
public static int[] EyeRotateTable = {
0x03, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x04,
0x04, 0x04, 0x03, 0x03, 0x04, 0x03, 0x04, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x03, 0x04, 0x04,
0x04, 0x03, 0x03, 0x03, 0x04, 0x04, 0x03, 0x03, 0x03, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x03, 0x04, 0x04
0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x03, 0x04, 0x04,
};
public static int[] EyebrowRotateTable = new int[]
{
public static int[] EyebrowRotateTable = {
0x06, 0x06, 0x05, 0x07, 0x06, 0x07, 0x06, 0x07, 0x04, 0x07, 0x06, 0x08, 0x05, 0x05, 0x06, 0x06,
0x07, 0x07, 0x06, 0x06, 0x05, 0x06, 0x07, 0x05
0x07, 0x07, 0x06, 0x06, 0x05, 0x06, 0x07, 0x05,
};
[Flags]
public enum BeardAndMustacheFlag
{
Beard = 1,
Mustache
Mustache,
}
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = ValuesArraySize)]
@@ -32,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
{
private const int ValuesArraySize = 0xbc;
private int _firstValueByte;
private readonly int _firstValueByte;
public ReadOnlySpan<int> Values => SpanHelpers.AsSpan<RandomMiiValues, int>(ref this);
}
@@ -44,34 +42,34 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public int Age;
public int Race;
public int ValuesCount;
private RandomMiiValues _values;
public ReadOnlySpan<int> Values => _values.Values.Slice(0, ValuesCount);
private readonly RandomMiiValues _values;
public readonly ReadOnlySpan<int> Values => _values.Values[..ValuesCount];
}
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = 0xC8)]
public struct RandomMiiData3
{
private int _argument1;
private int _argument2;
private readonly int _argument1;
private readonly int _argument2;
public int ValuesCount;
private RandomMiiValues _values;
public ReadOnlySpan<int> Values => _values.Values.Slice(0, ValuesCount);
private readonly RandomMiiValues _values;
public readonly ReadOnlySpan<int> Values => _values.Values[..ValuesCount];
}
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = 0xC4)]
public struct RandomMiiData2
{
private int _argument;
private readonly int _argument;
public int ValuesCount;
private RandomMiiValues _values;
private readonly RandomMiiValues _values;
public ReadOnlySpan<int> Values => _values.Values.Slice(0, ValuesCount);
public readonly ReadOnlySpan<int> Values => _values.Values[..ValuesCount];
}
public static ReadOnlySpan<RandomMiiData4> RandomMiiFacelineArray => MemoryMarshal.Cast<byte, RandomMiiData4>(RandomMiiFacelineRawArray);
@@ -332,7 +330,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
, };
private static ReadOnlySpan<byte> RandomMiiFacelineColorRawArray => new byte[]
{
@@ -411,7 +409,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
, };
private static ReadOnlySpan<byte> RandomMiiFacelineWrinkleRawArray => new byte[]
{
@@ -645,7 +643,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
, };
private static ReadOnlySpan<byte> RandomMiiFacelineMakeRawArray => new byte[]
{
@@ -879,7 +877,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
, };
private static ReadOnlySpan<byte> RandomMiiHairTypeRawArray => new byte[]
{
@@ -1113,7 +1111,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
, };
private static ReadOnlySpan<byte> RandomMiiHairColorRawArray => new byte[]
{
@@ -1230,7 +1228,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
, };
private static ReadOnlySpan<byte> RandomMiiEyeTypeRawArray => new byte[]
{
@@ -1464,7 +1462,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
,};
private static ReadOnlySpan<byte> RandomMiiEyeColorRawArray => new byte[]
{

View File

@@ -3,6 +3,6 @@
enum Source
{
Database,
Default
Default,
}
}

View File

@@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
enum SourceFlag
{
Database = 1 << Source.Database,
Default = 1 << Source.Default,
All = Database | Default
Default = 1 << Source.Default,
All = Database | Default,
}
}

View File

@@ -9,7 +9,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public uint RawValue;
public bool IsEnabledSpecialMii()
public readonly bool IsEnabledSpecialMii()
{
return RawValue == SpecialMiiMagic;
}

View File

@@ -9,16 +9,16 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
{
public const int Size = 0x44;
public CoreData CoreData;
public CoreData CoreData;
private CreateId _createId;
public ushort DataCrc;
public ushort DeviceCrc;
public ushort DataCrc;
public ushort DeviceCrc;
public byte Type => CoreData.Type;
public CreateId CreateId => _createId;
public readonly CreateId CreateId => _createId;
public ResultCode InvalidData => ResultCode.InvalidStoreData;
public readonly ResultCode InvalidData => ResultCode.InvalidStoreData;
private void UpdateDataCrc()
{
@@ -81,22 +81,23 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
private ReadOnlySpan<byte> AsSpanWithoutDeviceCrc()
{
return AsSpan().Slice(0, Size - 2);
return AsSpan()[..(Size - 2)];
}
public static StoreData BuildDefault(UtilityImpl utilImpl, uint index)
{
StoreData result = new StoreData
StoreData result = new()
{
_createId = utilImpl.MakeCreateId()
_createId = utilImpl.MakeCreateId(),
};
CoreData coreData = new CoreData();
CoreData coreData = new();
DefaultMii template = DefaultMii.GetDefaultMii(index);
coreData.SetDefault();
#pragma warning disable IDE0055 // Disable formatting
coreData.Nickname = template.Nickname;
coreData.FontRegion = (FontRegion)template.FontRegion;
coreData.FavoriteColor = (byte)template.FavoriteColor;
@@ -147,6 +148,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
coreData.MoleScale = (byte)template.MoleScale;
coreData.MoleX = (byte)template.MoleX;
coreData.MoleY = (byte)template.MoleY;
#pragma warning restore IDE0055
result.CoreData = coreData;
@@ -162,10 +164,10 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
public static StoreData BuildFromCoreData(UtilityImpl utilImpl, CoreData coreData)
{
StoreData result = new StoreData
StoreData result = new()
{
CoreData = coreData,
_createId = utilImpl.MakeCreateId()
CoreData = coreData,
_createId = utilImpl.MakeCreateId(),
};
result.UpdateCrc();
@@ -178,7 +180,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
this = storeData;
}
public void SetSource(Source source)
public readonly void SetSource(Source source)
{
// Only implemented for Element variants.
}
@@ -193,12 +195,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
return !x.Equals(y);
}
public override bool Equals(object obj)
public readonly override bool Equals(object obj)
{
return obj is StoreData storeData && Equals(storeData);
}
public bool Equals(StoreData cmpObj)
public readonly bool Equals(StoreData cmpObj)
{
if (!cmpObj.IsValid())
{
@@ -215,9 +217,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
return result;
}
public override int GetHashCode()
public readonly override int GetHashCode()
{
HashCode hashCode = new HashCode();
HashCode hashCode = new();
hashCode.Add(CreateId);
hashCode.Add(CoreData);

View File

@@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
struct StoreDataElement : IElement
{
public StoreData StoreData;
public Source Source;
public Source Source;
public void SetFromStoreData(StoreData storeData)
{