From 02b5c7ea89bb6aae1c214b78fb1047872382dc43 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sat, 1 Jul 2023 12:42:10 +0200 Subject: [PATCH] [Ryujinx.Horizon] Address dotnet-format issues (#5381) * 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 dotnet format CA1822 warnings * 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 * Revert formatting changes for while and for-loops * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Remove a few unused parameters * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Address IDE0251 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 * Add trailing commas and fix formatting issues * Convert if-else chain to switch block * Address review feedback --- src/Ryujinx.Horizon/Bcat/BcatIpcServer.cs | 7 +- src/Ryujinx.Horizon/Bcat/BcatMain.cs | 9 +- src/Ryujinx.Horizon/Bcat/BcatServerManager.cs | 10 +- .../Bcat/Ipc/ServiceCreator/BcatService.cs | 7 +- .../DeliveryCacheDirectoryService.cs | 2 +- .../DeliveryCacheFileService.cs | 2 +- .../DeliveryCacheProgressService.cs | 2 +- .../Types/DeliveryCacheProgressImpl.cs | 4 +- .../Bcat/Types/BcatPortIndex.cs | 2 +- .../Bcat/Types/BcatServicePermissionLevel.cs | 10 +- src/Ryujinx.Horizon/HeapAllocator.cs | 16 +-- src/Ryujinx.Horizon/HorizonOptions.cs | 8 +- src/Ryujinx.Horizon/HorizonStatic.cs | 26 ++--- .../LogManager/Ipc/LmLogger.cs | 110 +++++++----------- .../LogManager/Ipc/LogService.cs | 2 +- src/Ryujinx.Horizon/LogManager/LmIpcServer.cs | 10 +- src/Ryujinx.Horizon/LogManager/LmMain.cs | 2 +- .../LogManager/Types/LogPacket.cs | 24 ++-- src/Ryujinx.Horizon/Prepo/Ipc/PrepoService.cs | 17 +-- src/Ryujinx.Horizon/Prepo/PrepoIpcServer.cs | 12 +- src/Ryujinx.Horizon/Prepo/PrepoMain.cs | 2 +- src/Ryujinx.Horizon/Prepo/PrepoResult.cs | 4 +- .../Prepo/PrepoServerManager.cs | 4 +- .../Prepo/Types/PrepoPortIndex.cs | 4 +- .../Types/PrepoServicePermissionLevel.cs | 10 +- src/Ryujinx.Horizon/Sdk/Account/Uid.cs | 8 +- .../Sdk/Bcat/IServiceCreator.cs | 3 +- src/Ryujinx.Horizon/Sdk/Diag/LogSeverity.cs | 4 +- src/Ryujinx.Horizon/Sdk/Lm/ILmLogger.cs | 2 +- src/Ryujinx.Horizon/Sdk/Lm/ILogService.cs | 2 +- src/Ryujinx.Horizon/Sdk/Lm/LogDataChunkKey.cs | 4 +- src/Ryujinx.Horizon/Sdk/Lm/LogDestination.cs | 2 +- src/Ryujinx.Horizon/Sdk/Lm/LogPacketFlags.cs | 2 +- src/Ryujinx.Horizon/Sdk/Ncm/ApplicationId.cs | 2 +- .../Sdk/OsTypes/EventClearMode.cs | 2 +- .../Sdk/OsTypes/Impl/MultiWaitImpl.cs | 17 +-- .../Sdk/OsTypes/InitializationState.cs | 4 +- .../Sdk/OsTypes/MultiWaitHolderOfEvent.cs | 2 +- .../Sdk/OsTypes/MultiWaitHolderOfHandle.cs | 2 +- src/Ryujinx.Horizon/Sdk/OsTypes/OsEvent.cs | 2 +- src/Ryujinx.Horizon/Sdk/OsTypes/OsResult.cs | 2 +- .../Sdk/OsTypes/SystemEventType.cs | 4 +- src/Ryujinx.Horizon/Sdk/OsTypes/TriBool.cs | 2 +- .../Sdk/Prepo/IPrepoService.cs | 7 +- src/Ryujinx.Horizon/Sdk/ServiceUtil.cs | 10 +- .../Sdk/Sf/Cmif/CmifDomainInHeader.cs | 10 +- .../Sdk/Sf/Cmif/CmifDomainOutHeader.cs | 2 +- .../Sdk/Sf/Cmif/CmifDomainRequestType.cs | 4 +- .../Sdk/Sf/Cmif/CmifMessage.cs | 64 +++++----- .../Sdk/Sf/Cmif/CmifOutHeader.cs | 8 +- .../Sdk/Sf/Cmif/CmifRequest.cs | 8 +- .../Sdk/Sf/Cmif/CmifRequestFormat.cs | 28 ++--- .../Sdk/Sf/Cmif/CmifResponse.cs | 4 +- .../Sdk/Sf/Cmif/CommandType.cs | 14 +-- .../Cmif/DomainServiceObjectDispatchTable.cs | 2 +- .../Sf/Cmif/DomainServiceObjectProcessor.cs | 1 - .../Sdk/Sf/Cmif/HandlesToClose.cs | 39 +++++-- .../Sdk/Sf/Cmif/PointerAndSize.cs | 4 +- .../Sdk/Sf/Cmif/ScopedInlineContextChange.cs | 2 +- .../Sdk/Sf/Cmif/ServerDomainManager.cs | 2 +- .../Sf/Cmif/ServerMessageRuntimeMetadata.cs | 34 +++--- .../Sdk/Sf/Cmif/ServiceDispatchContext.cs | 18 +-- .../Sdk/Sf/Cmif/ServiceDispatchMeta.cs | 2 +- .../Sdk/Sf/Cmif/ServiceDispatchTable.cs | 4 +- .../Sdk/Sf/Cmif/ServiceDispatchTableBase.cs | 8 +- src/Ryujinx.Horizon/Sdk/Sf/CommandArg.cs | 40 +++---- .../Sdk/Sf/CommandArgAttributes.cs | 8 +- src/Ryujinx.Horizon/Sdk/Sf/CommandHandler.cs | 20 ++-- .../Sdk/Sf/CommandSerialization.cs | 2 +- src/Ryujinx.Horizon/Sdk/Sf/Hipc/Api.cs | 14 +-- src/Ryujinx.Horizon/Sdk/Sf/Hipc/Header.cs | 18 +-- .../Sdk/Sf/Hipc/HipcBufferDescriptor.cs | 10 +- .../Sdk/Sf/Hipc/HipcBufferFlags.cs | 14 +-- .../Sdk/Sf/Hipc/HipcBufferMode.cs | 6 +- .../Sdk/Sf/Hipc/HipcManager.cs | 2 +- .../Sdk/Sf/Hipc/HipcMessage.cs | 92 +++++++-------- .../Sdk/Sf/Hipc/HipcMessageData.cs | 8 +- .../Sdk/Sf/Hipc/HipcMetadata.cs | 18 +-- .../Sdk/Sf/Hipc/HipcReceiveListEntry.cs | 10 +- src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs | 2 + .../Sdk/Sf/Hipc/HipcStaticDescriptor.cs | 10 +- .../Sdk/Sf/Hipc/ManagerOptions.cs | 16 +-- .../Sdk/Sf/Hipc/ReceiveResult.cs | 2 +- src/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs | 20 ++-- .../Sdk/Sf/Hipc/ServerManager.cs | 22 ++-- .../Sdk/Sf/Hipc/ServerManagerBase.cs | 22 ++-- .../Sdk/Sf/Hipc/ServerSession.cs | 16 +-- .../Sdk/Sf/Hipc/ServerSessionManager.cs | 99 +++++++--------- .../Sdk/Sf/Hipc/SpecialHeader.cs | 6 +- .../Sdk/Sf/HipcCommandProcessor.cs | 34 +++--- .../Sdk/Sf/RawDataOffsetCalculator.cs | 14 +-- src/Ryujinx.Horizon/Sdk/Sf/SfResult.cs | 4 +- src/Ryujinx.Horizon/Sdk/Sm/IManagerService.cs | 2 +- src/Ryujinx.Horizon/Sdk/Sm/IUserService.cs | 2 +- src/Ryujinx.Horizon/Sdk/Sm/ServiceName.cs | 6 +- src/Ryujinx.Horizon/Sdk/Sm/SmApi.cs | 2 +- src/Ryujinx.Horizon/ServiceEntry.cs | 12 +- src/Ryujinx.Horizon/ServiceTable.cs | 2 +- src/Ryujinx.Horizon/Sm/Impl/ServiceInfo.cs | 10 +- src/Ryujinx.Horizon/Sm/Impl/ServiceManager.cs | 12 +- src/Ryujinx.Horizon/Sm/Ipc/UserService.cs | 6 +- src/Ryujinx.Horizon/Sm/SmMain.cs | 10 +- src/Ryujinx.Horizon/Sm/SmResult.cs | 4 +- src/Ryujinx.Horizon/Sm/SmServerManager.cs | 6 +- src/Ryujinx.Horizon/Sm/Types/SmPortIndex.cs | 4 +- 105 files changed, 617 insertions(+), 637 deletions(-) diff --git a/src/Ryujinx.Horizon/Bcat/BcatIpcServer.cs b/src/Ryujinx.Horizon/Bcat/BcatIpcServer.cs index 4a5378af..f39929dd 100644 --- a/src/Ryujinx.Horizon/Bcat/BcatIpcServer.cs +++ b/src/Ryujinx.Horizon/Bcat/BcatIpcServer.cs @@ -1,5 +1,4 @@ -using Ryujinx.Horizon.Bcat.Ipc; -using Ryujinx.Horizon.Bcat.Types; +using Ryujinx.Horizon.Bcat.Types; using Ryujinx.Horizon.Sdk.Sf.Hipc; using Ryujinx.Horizon.Sdk.Sm; @@ -8,7 +7,7 @@ namespace Ryujinx.Horizon.Bcat internal class BcatIpcServer { private const int BcatMaxSessionsCount = 8; - private const int BcatTotalMaxSessionsCount = BcatMaxSessionsCount * 4; + private const int BcatTotalMaxSessionsCount = BcatMaxSessionsCount * 4; private const int PointerBufferSize = 0x400; private const int MaxDomains = 64; @@ -29,10 +28,12 @@ namespace Ryujinx.Horizon.Bcat _serverManager = new BcatServerManager(allocator, _sm, MaxPortsCount, _bcatManagerOptions, BcatTotalMaxSessionsCount); +#pragma warning disable IDE0055 // Disable formatting _serverManager.RegisterServer((int)BcatPortIndex.Admin, ServiceName.Encode("bcat:a"), BcatMaxSessionsCount); _serverManager.RegisterServer((int)BcatPortIndex.Manager, ServiceName.Encode("bcat:m"), BcatMaxSessionsCount); _serverManager.RegisterServer((int)BcatPortIndex.User, ServiceName.Encode("bcat:u"), BcatMaxSessionsCount); _serverManager.RegisterServer((int)BcatPortIndex.System, ServiceName.Encode("bcat:s"), BcatMaxSessionsCount); +#pragma warning restore IDE0055 } public void ServiceRequests() diff --git a/src/Ryujinx.Horizon/Bcat/BcatMain.cs b/src/Ryujinx.Horizon/Bcat/BcatMain.cs index d4166fb1..f347e216 100644 --- a/src/Ryujinx.Horizon/Bcat/BcatMain.cs +++ b/src/Ryujinx.Horizon/Bcat/BcatMain.cs @@ -1,11 +1,4 @@ -using Ryujinx.Horizon.LogManager; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Ryujinx.Horizon.Bcat +namespace Ryujinx.Horizon.Bcat { internal class BcatMain : IService { diff --git a/src/Ryujinx.Horizon/Bcat/BcatServerManager.cs b/src/Ryujinx.Horizon/Bcat/BcatServerManager.cs index f02eafd9..0431bd9a 100644 --- a/src/Ryujinx.Horizon/Bcat/BcatServerManager.cs +++ b/src/Ryujinx.Horizon/Bcat/BcatServerManager.cs @@ -17,12 +17,12 @@ namespace Ryujinx.Horizon.Bcat { return (BcatPortIndex)portIndex switch { - BcatPortIndex.Admin => AcceptImpl(server, new ServiceCreator("bcat:a", BcatServicePermissionLevel.Admin)), + BcatPortIndex.Admin => AcceptImpl(server, new ServiceCreator("bcat:a", BcatServicePermissionLevel.Admin)), BcatPortIndex.Manager => AcceptImpl(server, new ServiceCreator("bcat:m", BcatServicePermissionLevel.Manager)), - BcatPortIndex.User => AcceptImpl(server, new ServiceCreator("bcat:u", BcatServicePermissionLevel.User)), - BcatPortIndex.System => AcceptImpl(server, new ServiceCreator("bcat:s", BcatServicePermissionLevel.System)), - _ => throw new ArgumentOutOfRangeException(nameof(portIndex)), + BcatPortIndex.User => AcceptImpl(server, new ServiceCreator("bcat:u", BcatServicePermissionLevel.User)), + BcatPortIndex.System => AcceptImpl(server, new ServiceCreator("bcat:s", BcatServicePermissionLevel.System)), + _ => throw new ArgumentOutOfRangeException(nameof(portIndex)), }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/BcatService.cs b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/BcatService.cs index e82f597e..9ea2dc11 100644 --- a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/BcatService.cs +++ b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/BcatService.cs @@ -7,12 +7,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc { partial class BcatService : IBcatService { - private readonly BcatServicePermissionLevel _permissionLevel; - - public BcatService(BcatServicePermissionLevel permissionLevel) - { - _permissionLevel = permissionLevel; - } + public BcatService(BcatServicePermissionLevel permissionLevel) { } [CmifCommand(10100)] public Result RequestSyncDeliveryCache(out IDeliveryCacheProgressService deliveryCacheProgressService) diff --git a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheDirectoryService.cs b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheDirectoryService.cs index dd13eefb..c8b38c28 100644 --- a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheDirectoryService.cs +++ b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheDirectoryService.cs @@ -26,7 +26,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc } [CmifCommand(1)] - public Result Read(out int entriesRead, [Buffer(Sdk.Sf.Hipc.HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span entriesBuffer) + public Result Read(out int entriesRead, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span entriesBuffer) { return _libHacService.Get.Read(out entriesRead, entriesBuffer).ToHorizonResult(); } diff --git a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheFileService.cs b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheFileService.cs index d23f5f41..a26c3258 100644 --- a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheFileService.cs +++ b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheFileService.cs @@ -28,7 +28,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc [CmifCommand(1)] public Result Read(long offset, out long bytesRead, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span data) { - return _libHacService.Get.Read(out bytesRead, offset, data).ToHorizonResult(); + return _libHacService.Get.Read(out bytesRead, offset, data).ToHorizonResult(); } [CmifCommand(2)] diff --git a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheProgressService.cs b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheProgressService.cs index 91aa2686..578c18f4 100644 --- a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheProgressService.cs +++ b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/DeliveryCacheProgressService.cs @@ -39,7 +39,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc deliveryCacheProgressImpl = new DeliveryCacheProgressImpl { State = DeliveryCacheProgressImpl.Status.Done, - Result = 0 + Result = 0, }; Logger.Stub?.PrintStub(LogClass.ServiceBcat); diff --git a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/Types/DeliveryCacheProgressImpl.cs b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/Types/DeliveryCacheProgressImpl.cs index 10e0b54f..9e5274a6 100644 --- a/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/Types/DeliveryCacheProgressImpl.cs +++ b/src/Ryujinx.Horizon/Bcat/Ipc/ServiceCreator/Types/DeliveryCacheProgressImpl.cs @@ -8,11 +8,11 @@ namespace Ryujinx.Horizon.Bcat.Ipc.Types public enum Status { // TODO: determine other values - Done = 9 + Done = 9, } public Status State; - public uint Result; + public uint Result; // TODO: reverse the rest of the structure } } diff --git a/src/Ryujinx.Horizon/Bcat/Types/BcatPortIndex.cs b/src/Ryujinx.Horizon/Bcat/Types/BcatPortIndex.cs index e448dfdc..95851789 100644 --- a/src/Ryujinx.Horizon/Bcat/Types/BcatPortIndex.cs +++ b/src/Ryujinx.Horizon/Bcat/Types/BcatPortIndex.cs @@ -5,6 +5,6 @@ Admin, Manager, User, - System + System, } } diff --git a/src/Ryujinx.Horizon/Bcat/Types/BcatServicePermissionLevel.cs b/src/Ryujinx.Horizon/Bcat/Types/BcatServicePermissionLevel.cs index 54d7461a..6bf4b4cc 100644 --- a/src/Ryujinx.Horizon/Bcat/Types/BcatServicePermissionLevel.cs +++ b/src/Ryujinx.Horizon/Bcat/Types/BcatServicePermissionLevel.cs @@ -2,9 +2,9 @@ { enum BcatServicePermissionLevel { - Admin = -1, - User = 1, - System = 2, - Manager = 6 + Admin = -1, + User = 1, + System = 2, + Manager = 6, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/HeapAllocator.cs b/src/Ryujinx.Horizon/HeapAllocator.cs index 40ff14d0..fc125387 100644 --- a/src/Ryujinx.Horizon/HeapAllocator.cs +++ b/src/Ryujinx.Horizon/HeapAllocator.cs @@ -9,15 +9,15 @@ namespace Ryujinx.Horizon { private const ulong InvalidAddress = ulong.MaxValue; - private struct Range : IComparable + private readonly struct Range : IComparable { public ulong Offset { get; } - public ulong Size { get; } + public ulong Size { get; } public Range(ulong offset, ulong size) { Offset = offset; - Size = size; + Size = size; } public int CompareTo(Range other) @@ -31,7 +31,7 @@ namespace Ryujinx.Horizon public HeapAllocator() { - _freeRanges = new List(); + _freeRanges = new List(); _currentHeapSize = 0; } @@ -70,8 +70,8 @@ namespace Ryujinx.Horizon var range = _freeRanges[i]; ulong alignedOffset = BitUtils.AlignUp(range.Offset, alignment); - ulong sizeDelta = alignedOffset - range.Offset; - ulong usableSize = range.Size - sizeDelta; + ulong sizeDelta = alignedOffset - range.Offset; + ulong usableSize = range.Size - sizeDelta; if (sizeDelta < range.Size && usableSize >= size) { @@ -82,7 +82,7 @@ namespace Ryujinx.Horizon InsertFreeRange(range.Offset, sizeDelta); } - ulong endOffset = range.Offset + range.Size; + ulong endOffset = range.Offset + range.Size; ulong remainingSize = endOffset - (alignedOffset + size); if (remainingSize != 0) { @@ -140,4 +140,4 @@ namespace Ryujinx.Horizon _freeRanges.Insert(index, range); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/HorizonOptions.cs b/src/Ryujinx.Horizon/HorizonOptions.cs index 1ec56bfa..75cc29b7 100644 --- a/src/Ryujinx.Horizon/HorizonOptions.cs +++ b/src/Ryujinx.Horizon/HorizonOptions.cs @@ -2,18 +2,18 @@ using LibHac; namespace Ryujinx.Horizon { - public struct HorizonOptions + public readonly struct HorizonOptions { - public bool IgnoreMissingServices { get; } + public bool IgnoreMissingServices { get; } public bool ThrowOnInvalidCommandIds { get; } public HorizonClient BcatClient { get; } public HorizonOptions(bool ignoreMissingServices, HorizonClient bcatClient) { - IgnoreMissingServices = ignoreMissingServices; + IgnoreMissingServices = ignoreMissingServices; ThrowOnInvalidCommandIds = true; - BcatClient = bcatClient; + BcatClient = bcatClient; } } } diff --git a/src/Ryujinx.Horizon/HorizonStatic.cs b/src/Ryujinx.Horizon/HorizonStatic.cs index e372df69..1e483cd4 100644 --- a/src/Ryujinx.Horizon/HorizonStatic.cs +++ b/src/Ryujinx.Horizon/HorizonStatic.cs @@ -21,24 +21,24 @@ namespace Ryujinx.Horizon [ThreadStatic] private static int _threadHandle; - public static HorizonOptions Options => _options; - public static ISyscallApi Syscall => _syscall; - public static IVirtualMemoryManager AddressSpace => _addressSpace; - public static IThreadContext ThreadContext => _threadContext; - public static int CurrentThreadHandle => _threadHandle; + public static HorizonOptions Options => _options; + public static ISyscallApi Syscall => _syscall; + public static IVirtualMemoryManager AddressSpace => _addressSpace; + public static IThreadContext ThreadContext => _threadContext; + public static int CurrentThreadHandle => _threadHandle; public static void Register( - HorizonOptions options, - ISyscallApi syscallApi, + HorizonOptions options, + ISyscallApi syscallApi, IVirtualMemoryManager addressSpace, - IThreadContext threadContext, - int threadHandle) + IThreadContext threadContext, + int threadHandle) { - _options = options; - _syscall = syscallApi; - _addressSpace = addressSpace; + _options = options; + _syscall = syscallApi; + _addressSpace = addressSpace; _threadContext = threadContext; - _threadHandle = threadHandle; + _threadHandle = threadHandle; } } } diff --git a/src/Ryujinx.Horizon/LogManager/Ipc/LmLogger.cs b/src/Ryujinx.Horizon/LogManager/Ipc/LmLogger.cs index 88dddef5..b6460a4b 100644 --- a/src/Ryujinx.Horizon/LogManager/Ipc/LmLogger.cs +++ b/src/Ryujinx.Horizon/LogManager/Ipc/LmLogger.cs @@ -95,74 +95,52 @@ namespace Ryujinx.Horizon.LogManager.Ipc LogDataChunkKey key = (LogDataChunkKey)type; - if (key == LogDataChunkKey.Start) + switch (key) { - reader.Skip(size); - - continue; - } - else if (key == LogDataChunkKey.Stop) - { - break; - } - else if (key == LogDataChunkKey.Line) - { - if (!reader.TryRead(out _logPacket.Line)) - { + case LogDataChunkKey.Start: + reader.Skip(size); + continue; + case LogDataChunkKey.Stop: + break; + case LogDataChunkKey.Line when !reader.TryRead(out _logPacket.Line): + case LogDataChunkKey.DropCount when !reader.TryRead(out _logPacket.DropCount): + case LogDataChunkKey.Time when !reader.TryRead(out _logPacket.Time): return true; - } - } - else if (key == LogDataChunkKey.DropCount) - { - if (!reader.TryRead(out _logPacket.DropCount)) - { - return true; - } - } - else if (key == LogDataChunkKey.Time) - { - if (!reader.TryRead(out _logPacket.Time)) - { - return true; - } - } - else if (key == LogDataChunkKey.Message) - { - string text = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); - - if (isHeadPacket && isTailPacket) - { - _logPacket.Message = text; - } - else - { - _logPacket.Message += text; - - if (_logPacket.Message.Length >= MessageLengthLimit) + case LogDataChunkKey.Message: { - isTailPacket = true; + string text = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); + + if (isHeadPacket && isTailPacket) + { + _logPacket.Message = text; + } + else + { + _logPacket.Message += text; + + if (_logPacket.Message.Length >= MessageLengthLimit) + { + isTailPacket = true; + } + } + + break; } - } - } - else if (key == LogDataChunkKey.Filename) - { - _logPacket.Filename = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); - } - else if (key == LogDataChunkKey.Function) - { - _logPacket.Function = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); - } - else if (key == LogDataChunkKey.Module) - { - _logPacket.Module = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); - } - else if (key == LogDataChunkKey.Thread) - { - _logPacket.Thread = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); - } - else if (key == LogDataChunkKey.ProgramName) - { - _logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); + case LogDataChunkKey.Filename: + _logPacket.Filename = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); + break; + case LogDataChunkKey.Function: + _logPacket.Function = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); + break; + case LogDataChunkKey.Module: + _logPacket.Module = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); + break; + case LogDataChunkKey.Thread: + _logPacket.Thread = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); + break; + case LogDataChunkKey.ProgramName: + _logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); + break; } } @@ -177,7 +155,7 @@ namespace Ryujinx.Horizon.LogManager.Ipc do { - if (!reader.TryRead(out encoded)) + if (!reader.TryRead(out encoded)) { return false; } @@ -190,4 +168,4 @@ namespace Ryujinx.Horizon.LogManager.Ipc return true; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/LogManager/Ipc/LogService.cs b/src/Ryujinx.Horizon/LogManager/Ipc/LogService.cs index 6899739e..9ac9c27e 100644 --- a/src/Ryujinx.Horizon/LogManager/Ipc/LogService.cs +++ b/src/Ryujinx.Horizon/LogManager/Ipc/LogService.cs @@ -17,4 +17,4 @@ namespace Ryujinx.Horizon.LogManager.Ipc return Result.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/LogManager/LmIpcServer.cs b/src/Ryujinx.Horizon/LogManager/LmIpcServer.cs index 71b844a2..d1a405b8 100644 --- a/src/Ryujinx.Horizon/LogManager/LmIpcServer.cs +++ b/src/Ryujinx.Horizon/LogManager/LmIpcServer.cs @@ -9,13 +9,13 @@ namespace Ryujinx.Horizon.LogManager private const int LogMaxSessionsCount = 42; private const int PointerBufferSize = 0x400; - private const int MaxDomains = 31; - private const int MaxDomainObjects = 61; - private const int MaxPortsCount = 1; + private const int MaxDomains = 31; + private const int MaxDomainObjects = 61; + private const int MaxPortsCount = 1; private static readonly ManagerOptions _logManagerOptions = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false); - private SmApi _sm; + private SmApi _sm; private ServerManager _serverManager; public void Initialize() @@ -40,4 +40,4 @@ namespace Ryujinx.Horizon.LogManager _serverManager.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/LogManager/LmMain.cs b/src/Ryujinx.Horizon/LogManager/LmMain.cs index bbe96d4c..c229de59 100644 --- a/src/Ryujinx.Horizon/LogManager/LmMain.cs +++ b/src/Ryujinx.Horizon/LogManager/LmMain.cs @@ -14,4 +14,4 @@ ipcServer.Shutdown(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/LogManager/Types/LogPacket.cs b/src/Ryujinx.Horizon/LogManager/Types/LogPacket.cs index dbff5e3e..57a389be 100644 --- a/src/Ryujinx.Horizon/LogManager/Types/LogPacket.cs +++ b/src/Ryujinx.Horizon/LogManager/Types/LogPacket.cs @@ -5,15 +5,15 @@ namespace Ryujinx.Horizon.LogManager.Types { struct LogPacket { - public string Message; - public int Line; - public string Filename; - public string Function; - public string Module; - public string Thread; - public long DropCount; - public long Time; - public string ProgramName; + public string Message; + public int Line; + public string Filename; + public string Function; + public string Module; + public string Thread; + public long DropCount; + public long Time; + public string ProgramName; public LogSeverity Severity; public override string ToString() @@ -35,12 +35,12 @@ namespace Ryujinx.Horizon.LogManager.Types { builder.AppendLine($" ProgramName: {ProgramName}"); } - + if (!string.IsNullOrEmpty(Module)) { builder.AppendLine($" Module: {Module}"); } - + if (!string.IsNullOrEmpty(Thread)) { builder.AppendLine($" Thread: {Thread}"); @@ -69,4 +69,4 @@ namespace Ryujinx.Horizon.LogManager.Types return builder.ToString(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Prepo/Ipc/PrepoService.cs b/src/Ryujinx.Horizon/Prepo/Ipc/PrepoService.cs index e157fa56..f424b17e 100644 --- a/src/Ryujinx.Horizon/Prepo/Ipc/PrepoService.cs +++ b/src/Ryujinx.Horizon/Prepo/Ipc/PrepoService.cs @@ -10,6 +10,7 @@ using Ryujinx.Horizon.Sdk.Sf; using Ryujinx.Horizon.Sdk.Sf.Hipc; using System; using System.Text; +using ApplicationId = Ryujinx.Horizon.Sdk.Ncm.ApplicationId; namespace Ryujinx.Horizon.Prepo.Ipc { @@ -18,14 +19,14 @@ namespace Ryujinx.Horizon.Prepo.Ipc enum PlayReportKind { Normal, - System + System, } private readonly PrepoServicePermissionLevel _permissionLevel; private ulong _systemSessionId; - private bool _immediateTransmissionEnabled = false; - private bool _userAgreementCheckEnabled = true; + private bool _immediateTransmissionEnabled; + private bool _userAgreementCheckEnabled = true; public PrepoService(PrepoServicePermissionLevel permissionLevel) { @@ -107,7 +108,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc } [CmifCommand(20100)] - public Result SaveSystemReport([Buffer(HipcBufferFlags.In | HipcBufferFlags.Pointer)] ReadOnlySpan gameRoomBuffer, Sdk.Ncm.ApplicationId applicationId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan reportBuffer) + public Result SaveSystemReport([Buffer(HipcBufferFlags.In | HipcBufferFlags.Pointer)] ReadOnlySpan gameRoomBuffer, ApplicationId applicationId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan reportBuffer) { if ((_permissionLevel & PrepoServicePermissionLevel.System) != 0) { @@ -118,7 +119,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc } [CmifCommand(20101)] - public Result SaveSystemReportWithUser(Uid userId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.Pointer)] ReadOnlySpan gameRoomBuffer, Sdk.Ncm.ApplicationId applicationId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan reportBuffer) + public Result SaveSystemReportWithUser(Uid userId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.Pointer)] ReadOnlySpan gameRoomBuffer, ApplicationId applicationId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan reportBuffer) { if ((_permissionLevel & PrepoServicePermissionLevel.System) != 0) { @@ -164,7 +165,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc return PrepoResult.PermissionDenied; } - private static Result ProcessPlayReport(PlayReportKind playReportKind, ReadOnlySpan gameRoomBuffer, ReadOnlySpan reportBuffer, ulong pid, Uid userId, bool withUserId = false, Sdk.Ncm.ApplicationId applicationId = default) + private static Result ProcessPlayReport(PlayReportKind playReportKind, ReadOnlySpan gameRoomBuffer, ReadOnlySpan reportBuffer, ulong pid, Uid userId, bool withUserId = false, ApplicationId applicationId = default) { if (withUserId) { @@ -191,7 +192,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc return PrepoResult.InvalidBufferSize; } - StringBuilder builder = new(); + StringBuilder builder = new(); MessagePackObject deserializedReport = MessagePackSerializer.UnpackMessagePackObject(reportBuffer.ToArray()); builder.AppendLine(); @@ -222,4 +223,4 @@ namespace Ryujinx.Horizon.Prepo.Ipc return Result.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Prepo/PrepoIpcServer.cs b/src/Ryujinx.Horizon/Prepo/PrepoIpcServer.cs index b80399ea..9c185520 100644 --- a/src/Ryujinx.Horizon/Prepo/PrepoIpcServer.cs +++ b/src/Ryujinx.Horizon/Prepo/PrepoIpcServer.cs @@ -6,13 +6,13 @@ namespace Ryujinx.Horizon.Prepo { class PrepoIpcServer { - private const int PrepoMaxSessionsCount = 12; + private const int PrepoMaxSessionsCount = 12; private const int PrepoTotalMaxSessionsCount = PrepoMaxSessionsCount * 6; private const int PointerBufferSize = 0x80; - private const int MaxDomains = 64; - private const int MaxDomainObjects = 16; - private const int MaxPortsCount = 6; + private const int MaxDomains = 64; + private const int MaxDomainObjects = 16; + private const int MaxPortsCount = 6; private static readonly ManagerOptions _prepoManagerOptions = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false); @@ -28,12 +28,14 @@ namespace Ryujinx.Horizon.Prepo _serverManager = new PrepoServerManager(allocator, _sm, MaxPortsCount, _prepoManagerOptions, PrepoTotalMaxSessionsCount); +#pragma warning disable IDE0055 // Disable formatting _serverManager.RegisterServer((int)PrepoPortIndex.Admin, ServiceName.Encode("prepo:a"), PrepoMaxSessionsCount); // 1.0.0-5.1.0 _serverManager.RegisterServer((int)PrepoPortIndex.Admin2, ServiceName.Encode("prepo:a2"), PrepoMaxSessionsCount); // 6.0.0+ _serverManager.RegisterServer((int)PrepoPortIndex.Manager, ServiceName.Encode("prepo:m"), PrepoMaxSessionsCount); _serverManager.RegisterServer((int)PrepoPortIndex.User, ServiceName.Encode("prepo:u"), PrepoMaxSessionsCount); _serverManager.RegisterServer((int)PrepoPortIndex.System, ServiceName.Encode("prepo:s"), PrepoMaxSessionsCount); _serverManager.RegisterServer((int)PrepoPortIndex.Debug, ServiceName.Encode("prepo:d"), PrepoMaxSessionsCount); // 1.0.0 +#pragma warning restore IDE0055 } public void ServiceRequests() @@ -46,4 +48,4 @@ namespace Ryujinx.Horizon.Prepo _serverManager.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Prepo/PrepoMain.cs b/src/Ryujinx.Horizon/Prepo/PrepoMain.cs index 5ff0f53d..c311d619 100644 --- a/src/Ryujinx.Horizon/Prepo/PrepoMain.cs +++ b/src/Ryujinx.Horizon/Prepo/PrepoMain.cs @@ -14,4 +14,4 @@ ipcServer.Shutdown(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Prepo/PrepoResult.cs b/src/Ryujinx.Horizon/Prepo/PrepoResult.cs index 12255e3d..4c6bc7a4 100644 --- a/src/Ryujinx.Horizon/Prepo/PrepoResult.cs +++ b/src/Ryujinx.Horizon/Prepo/PrepoResult.cs @@ -6,10 +6,12 @@ namespace Ryujinx.Horizon.Prepo { private const int ModuleId = 129; +#pragma warning disable IDE0055 // Disable formatting public static Result InvalidArgument => new(ModuleId, 1); public static Result InvalidState => new(ModuleId, 5); public static Result InvalidBufferSize => new(ModuleId, 9); public static Result PermissionDenied => new(ModuleId, 90); public static Result InvalidPid => new(ModuleId, 101); +#pragma warning restore IDE0055 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Prepo/PrepoServerManager.cs b/src/Ryujinx.Horizon/Prepo/PrepoServerManager.cs index 55e4ff7d..a7936095 100644 --- a/src/Ryujinx.Horizon/Prepo/PrepoServerManager.cs +++ b/src/Ryujinx.Horizon/Prepo/PrepoServerManager.cs @@ -17,6 +17,7 @@ namespace Ryujinx.Horizon.Prepo { return (PrepoPortIndex)portIndex switch { +#pragma warning disable IDE0055 // Disable formatting PrepoPortIndex.Admin => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)), PrepoPortIndex.Admin2 => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)), PrepoPortIndex.Manager => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Manager)), @@ -24,7 +25,8 @@ namespace Ryujinx.Horizon.Prepo PrepoPortIndex.System => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.System)), PrepoPortIndex.Debug => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Debug)), _ => throw new ArgumentOutOfRangeException(nameof(portIndex)), +#pragma warning restore IDE0055 }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Prepo/Types/PrepoPortIndex.cs b/src/Ryujinx.Horizon/Prepo/Types/PrepoPortIndex.cs index f4d6b877..31c5b02d 100644 --- a/src/Ryujinx.Horizon/Prepo/Types/PrepoPortIndex.cs +++ b/src/Ryujinx.Horizon/Prepo/Types/PrepoPortIndex.cs @@ -7,6 +7,6 @@ Manager, User, System, - Debug + Debug, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Prepo/Types/PrepoServicePermissionLevel.cs b/src/Ryujinx.Horizon/Prepo/Types/PrepoServicePermissionLevel.cs index 8214f4b9..759c5018 100644 --- a/src/Ryujinx.Horizon/Prepo/Types/PrepoServicePermissionLevel.cs +++ b/src/Ryujinx.Horizon/Prepo/Types/PrepoServicePermissionLevel.cs @@ -2,10 +2,10 @@ { enum PrepoServicePermissionLevel { - Admin = -1, - User = 1, - System = 2, + Admin = -1, + User = 1, + System = 2, Manager = 6, - Debug = unchecked((int)0x80000006) + Debug = unchecked((int)0x80000006), } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Account/Uid.cs b/src/Ryujinx.Horizon/Sdk/Account/Uid.cs index 5aad0463..0175d393 100644 --- a/src/Ryujinx.Horizon/Sdk/Account/Uid.cs +++ b/src/Ryujinx.Horizon/Sdk/Account/Uid.cs @@ -17,14 +17,14 @@ namespace Ryujinx.Horizon.Sdk.Account public Uid(long low, long high) { - Low = low; + Low = low; High = high; } public Uid(byte[] bytes) { High = BitConverter.ToInt64(bytes, 0); - Low = BitConverter.ToInt64(bytes, 8); + Low = BitConverter.ToInt64(bytes, 8); } public Uid(string hex) @@ -34,7 +34,7 @@ namespace Ryujinx.Horizon.Sdk.Account throw new ArgumentException("Invalid Hex value!", nameof(hex)); } - Low = Convert.ToInt64(hex[16..], 16); + Low = Convert.ToInt64(hex[16..], 16); High = Convert.ToInt64(hex[..16], 16); } @@ -59,4 +59,4 @@ namespace Ryujinx.Horizon.Sdk.Account return new UInt128((ulong)High, (ulong)Low); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Bcat/IServiceCreator.cs b/src/Ryujinx.Horizon/Sdk/Bcat/IServiceCreator.cs index edc52590..04f25259 100644 --- a/src/Ryujinx.Horizon/Sdk/Bcat/IServiceCreator.cs +++ b/src/Ryujinx.Horizon/Sdk/Bcat/IServiceCreator.cs @@ -1,4 +1,5 @@ using Ryujinx.Horizon.Common; +using Ryujinx.Horizon.Sdk.Ncm; using Ryujinx.Horizon.Sdk.Sf; namespace Ryujinx.Horizon.Sdk.Bcat @@ -7,6 +8,6 @@ namespace Ryujinx.Horizon.Sdk.Bcat { Result CreateBcatService(out IBcatService service, ulong pid); Result CreateDeliveryCacheStorageService(out IDeliveryCacheStorageService service, ulong pid); - Result CreateDeliveryCacheStorageServiceWithApplicationId(out IDeliveryCacheStorageService service, Ncm.ApplicationId applicationId); + Result CreateDeliveryCacheStorageServiceWithApplicationId(out IDeliveryCacheStorageService service, ApplicationId applicationId); } } diff --git a/src/Ryujinx.Horizon/Sdk/Diag/LogSeverity.cs b/src/Ryujinx.Horizon/Sdk/Diag/LogSeverity.cs index 72acf789..ecac00bb 100644 --- a/src/Ryujinx.Horizon/Sdk/Diag/LogSeverity.cs +++ b/src/Ryujinx.Horizon/Sdk/Diag/LogSeverity.cs @@ -6,6 +6,6 @@ namespace Ryujinx.Horizon.Sdk.Diag Info = 1, Warn = 2, Error = 3, - Fatal = 4 + Fatal = 4, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Lm/ILmLogger.cs b/src/Ryujinx.Horizon/Sdk/Lm/ILmLogger.cs index bb5770cb..42165aab 100644 --- a/src/Ryujinx.Horizon/Sdk/Lm/ILmLogger.cs +++ b/src/Ryujinx.Horizon/Sdk/Lm/ILmLogger.cs @@ -9,4 +9,4 @@ namespace Ryujinx.Horizon.Sdk.Lm Result Log(Span message); Result SetDestination(LogDestination destination); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Lm/ILogService.cs b/src/Ryujinx.Horizon/Sdk/Lm/ILogService.cs index ad6c8455..b66b9126 100644 --- a/src/Ryujinx.Horizon/Sdk/Lm/ILogService.cs +++ b/src/Ryujinx.Horizon/Sdk/Lm/ILogService.cs @@ -8,4 +8,4 @@ namespace Ryujinx.Horizon.Sdk.Lm { Result OpenLogger(out LmLogger logger, ulong pid); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Lm/LogDataChunkKey.cs b/src/Ryujinx.Horizon/Sdk/Lm/LogDataChunkKey.cs index 90756ece..6905db0c 100644 --- a/src/Ryujinx.Horizon/Sdk/Lm/LogDataChunkKey.cs +++ b/src/Ryujinx.Horizon/Sdk/Lm/LogDataChunkKey.cs @@ -14,6 +14,6 @@ namespace Ryujinx.Horizon.Sdk.Lm Time = 9, ProgramName = 10, - Count + Count, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Lm/LogDestination.cs b/src/Ryujinx.Horizon/Sdk/Lm/LogDestination.cs index 8b08548d..d9078629 100644 --- a/src/Ryujinx.Horizon/Sdk/Lm/LogDestination.cs +++ b/src/Ryujinx.Horizon/Sdk/Lm/LogDestination.cs @@ -9,6 +9,6 @@ namespace Ryujinx.Horizon.Sdk.Lm Uart = 1 << 1, UartIfSleep = 1 << 2, - All = 0xffff + All = 0xffff, } } diff --git a/src/Ryujinx.Horizon/Sdk/Lm/LogPacketFlags.cs b/src/Ryujinx.Horizon/Sdk/Lm/LogPacketFlags.cs index 75d9f40b..e7d5d664 100644 --- a/src/Ryujinx.Horizon/Sdk/Lm/LogPacketFlags.cs +++ b/src/Ryujinx.Horizon/Sdk/Lm/LogPacketFlags.cs @@ -7,6 +7,6 @@ namespace Ryujinx.Horizon.Sdk.Lm { IsHead = 1 << 0, IsTail = 1 << 1, - IsLittleEndian = 1 << 2 + IsLittleEndian = 1 << 2, } } diff --git a/src/Ryujinx.Horizon/Sdk/Ncm/ApplicationId.cs b/src/Ryujinx.Horizon/Sdk/Ncm/ApplicationId.cs index 37b4cbfb..652589e1 100644 --- a/src/Ryujinx.Horizon/Sdk/Ncm/ApplicationId.cs +++ b/src/Ryujinx.Horizon/Sdk/Ncm/ApplicationId.cs @@ -49,4 +49,4 @@ return $"0x{Id:x}"; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/EventClearMode.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/EventClearMode.cs index b500e6b3..b82518d7 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/EventClearMode.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/EventClearMode.cs @@ -3,6 +3,6 @@ enum EventClearMode { ManualClear, - AutoClear + AutoClear, } } diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/Impl/MultiWaitImpl.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/Impl/MultiWaitImpl.cs index 04bc8d1d..ad57152c 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/Impl/MultiWaitImpl.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/Impl/MultiWaitImpl.cs @@ -7,9 +7,9 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl { class MultiWaitImpl { - private const int WaitTimedOut = -1; + private const int WaitTimedOut = -1; private const int WaitCancelled = -2; - private const int WaitInvalid = -3; + private const int WaitInvalid = -3; private readonly List _multiWaits; @@ -63,10 +63,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl } } - if (result == null) - { - result = WaitAnyHandleImpl(infinite, timeout); - } + result ??= WaitAnyHandleImpl(infinite, timeout); UnlinkHoldersFromObjectsList(); _waitingThreadHandle = 0; @@ -98,7 +95,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl } else { - index = WaitSynchronization(objectHandles.Slice(0, count), minTimeout); + index = WaitSynchronization(objectHandles[..count], minTimeout); DebugUtil.Assert(index != WaitInvalid); } @@ -200,10 +197,8 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl { return WaitCancelled; } - else - { - result.AbortOnFailure(); - } + + result.AbortOnFailure(); return index; } diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/InitializationState.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/InitializationState.cs index 45ffd258..3d5bb810 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/InitializationState.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/InitializationState.cs @@ -3,6 +3,6 @@ namespace Ryujinx.Horizon.Sdk.OsTypes enum InitializationState : byte { NotInitialized, - Initialized + Initialized, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/MultiWaitHolderOfEvent.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/MultiWaitHolderOfEvent.cs index 37ac22f0..f5597847 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/MultiWaitHolderOfEvent.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/MultiWaitHolderOfEvent.cs @@ -4,7 +4,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes { class MultiWaitHolderOfEvent : MultiWaitHolder { - private Event _event; + private readonly Event _event; private LinkedListNode _node; public override TriBool Signaled diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/MultiWaitHolderOfHandle.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/MultiWaitHolderOfHandle.cs index 6fc5c75b..e5839a48 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/MultiWaitHolderOfHandle.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/MultiWaitHolderOfHandle.cs @@ -2,7 +2,7 @@ { class MultiWaitHolderOfHandle : MultiWaitHolder { - private int _handle; + private readonly int _handle; public override int Handle => _handle; diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/OsEvent.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/OsEvent.cs index cc7e8483..eac5e7c4 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/OsEvent.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/OsEvent.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes InitiallySignaled = signaled, ClearMode = clearMode, State = InitializationState.Initialized, - Lock = new object() + Lock = new object(), }; } diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/OsResult.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/OsResult.cs index 86dcd1fa..302922f1 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/OsResult.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/OsResult.cs @@ -6,6 +6,6 @@ namespace Ryujinx.Horizon.Sdk.OsTypes { private const int ModuleId = 3; - public static Result OutOfResource => new Result(ModuleId, 9); + public static Result OutOfResource => new(ModuleId, 9); } } diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/SystemEventType.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/SystemEventType.cs index 338493d2..dee0fa43 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/SystemEventType.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/SystemEventType.cs @@ -6,12 +6,12 @@ { NotInitialized, InitializedAsEvent, - InitializedAsInterProcess + InitializedAsInterProcess, } public InterProcessEventType InterProcessEvent; public InitializationState State; - public bool NotInitialized => State == InitializationState.NotInitialized; + public readonly bool NotInitialized => State == InitializationState.NotInitialized; } } diff --git a/src/Ryujinx.Horizon/Sdk/OsTypes/TriBool.cs b/src/Ryujinx.Horizon/Sdk/OsTypes/TriBool.cs index 7debd9e2..868d1025 100644 --- a/src/Ryujinx.Horizon/Sdk/OsTypes/TriBool.cs +++ b/src/Ryujinx.Horizon/Sdk/OsTypes/TriBool.cs @@ -4,6 +4,6 @@ { False, True, - Undefined + Undefined, } } diff --git a/src/Ryujinx.Horizon/Sdk/Prepo/IPrepoService.cs b/src/Ryujinx.Horizon/Sdk/Prepo/IPrepoService.cs index 042cb400..3f262820 100644 --- a/src/Ryujinx.Horizon/Sdk/Prepo/IPrepoService.cs +++ b/src/Ryujinx.Horizon/Sdk/Prepo/IPrepoService.cs @@ -2,6 +2,7 @@ using Ryujinx.Horizon.Sdk.Account; using Ryujinx.Horizon.Sdk.Sf; using System; +using ApplicationId = Ryujinx.Horizon.Sdk.Ncm.ApplicationId; namespace Ryujinx.Horizon.Sdk.Prepo { @@ -12,9 +13,9 @@ namespace Ryujinx.Horizon.Sdk.Prepo Result RequestImmediateTransmission(); Result GetTransmissionStatus(out int status); Result GetSystemSessionId(out ulong systemSessionId); - Result SaveSystemReport(ReadOnlySpan gameRoomBuffer, Ncm.ApplicationId applicationId, ReadOnlySpan reportBuffer); - Result SaveSystemReportWithUser(Uid userId, ReadOnlySpan gameRoomBuffer, Ncm.ApplicationId applicationId, ReadOnlySpan reportBuffer); + Result SaveSystemReport(ReadOnlySpan gameRoomBuffer, ApplicationId applicationId, ReadOnlySpan reportBuffer); + Result SaveSystemReportWithUser(Uid userId, ReadOnlySpan gameRoomBuffer, ApplicationId applicationId, ReadOnlySpan reportBuffer); Result IsUserAgreementCheckEnabled(out bool enabled); Result SetUserAgreementCheckEnabled(bool enabled); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/ServiceUtil.cs b/src/Ryujinx.Horizon/Sdk/ServiceUtil.cs index fe6fcce1..ccd6c93a 100644 --- a/src/Ryujinx.Horizon/Sdk/ServiceUtil.cs +++ b/src/Ryujinx.Horizon/Sdk/ServiceUtil.cs @@ -10,15 +10,15 @@ namespace Ryujinx.Horizon.Sdk public static Result SendRequest(out CmifResponse response, int sessionHandle, uint requestId, bool sendPid, scoped ReadOnlySpan data) { ulong tlsAddress = HorizonStatic.ThreadContext.TlsAddress; - int tlsSize = Api.TlsMessageBufferSize; + int tlsSize = Api.TlsMessageBufferSize; using (var tlsRegion = HorizonStatic.AddressSpace.GetWritableRegion(tlsAddress, tlsSize)) { - CmifRequest request = CmifMessage.CreateRequest(tlsRegion.Memory.Span, new CmifRequestFormat() + CmifRequest request = CmifMessage.CreateRequest(tlsRegion.Memory.Span, new CmifRequestFormat { - DataSize = data.Length, + DataSize = data.Length, RequestId = requestId, - SendPid = sendPid + SendPid = sendPid, }); data.CopyTo(request.Data); @@ -36,4 +36,4 @@ namespace Ryujinx.Horizon.Sdk return CmifMessage.ParseResponse(out response, HorizonStatic.AddressSpace.GetWritableRegion(tlsAddress, tlsSize).Memory.Span, false, 0); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainInHeader.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainInHeader.cs index beaff613..88211501 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainInHeader.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainInHeader.cs @@ -3,10 +3,10 @@ struct CmifDomainInHeader { public CmifDomainRequestType Type; - public byte ObjectsCount; - public ushort DataSize; - public int ObjectId; - public uint Padding; - public uint Token; + public byte ObjectsCount; + public ushort DataSize; + public int ObjectId; + public uint Padding; + public uint Token; } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainOutHeader.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainOutHeader.cs index 2086d24c..89766a42 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainOutHeader.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainOutHeader.cs @@ -2,7 +2,7 @@ { struct CmifDomainOutHeader { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public uint ObjectsCount; public uint Padding; public uint Padding2; diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainRequestType.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainRequestType.cs index 1a02e082..4e52ff93 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainRequestType.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifDomainRequestType.cs @@ -2,8 +2,8 @@ { enum CmifDomainRequestType : byte { - Invalid = 0, + Invalid = 0, SendMessage = 1, - Close = 2 + Close = 2, } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifMessage.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifMessage.cs index 0d23d33b..f0b6f0c3 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifMessage.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifMessage.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { static class CmifMessage { - public const uint CmifInHeaderMagic = 0x49434653; // SFCI + public const uint CmifInHeaderMagic = 0x49434653; // SFCI public const uint CmifOutHeaderMagic = 0x4f434653; // SFCO public static CmifRequest CreateRequest(Span output, CmifRequestFormat format) @@ -21,10 +21,10 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif } totalSize += Unsafe.SizeOf() + format.DataSize; - totalSize = (totalSize + 1) & ~1; + totalSize = (totalSize + 1) & ~1; int outPointerSizeTableOffset = totalSize; - int outPointerSizeTableSize = format.OutAutoBuffersCount + format.OutPointersCount; + int outPointerSizeTableSize = format.OutAutoBuffersCount + format.OutPointersCount; totalSize += sizeof(ushort) * outPointerSizeTableSize; @@ -32,19 +32,19 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif CmifRequest request = new() { - Hipc = HipcMessage.WriteMessage(output, new HipcMetadata() + Hipc = HipcMessage.WriteMessage(output, new HipcMetadata { - Type = format.Context != 0 ? (int)CommandType.RequestWithContext : (int)CommandType.Request, - SendStaticsCount = format.InAutoBuffersCount + format.InPointersCount, - SendBuffersCount = format.InAutoBuffersCount + format.InBuffersCount, - ReceiveBuffersCount = format.OutAutoBuffersCount + format.OutBuffersCount, + Type = format.Context != 0 ? (int)CommandType.RequestWithContext : (int)CommandType.Request, + SendStaticsCount = format.InAutoBuffersCount + format.InPointersCount, + SendBuffersCount = format.InAutoBuffersCount + format.InBuffersCount, + ReceiveBuffersCount = format.OutAutoBuffersCount + format.OutBuffersCount, ExchangeBuffersCount = format.InOutBuffersCount, - DataWordsCount = rawDataSizeInWords, - ReceiveStaticsCount = outPointerSizeTableSize + format.OutFixedPointersCount, - SendPid = format.SendPid, - CopyHandlesCount = format.HandlesCount, - MoveHandlesCount = 0 - }) + DataWordsCount = rawDataSizeInWords, + ReceiveStaticsCount = outPointerSizeTableSize + format.OutFixedPointersCount, + SendPid = format.SendPid, + CopyHandlesCount = format.HandlesCount, + MoveHandlesCount = 0, + }), }; Span data = request.Hipc.DataWords; @@ -55,14 +55,14 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif int payloadSize = Unsafe.SizeOf() + format.DataSize; - domainHeader = new CmifDomainInHeader() + domainHeader = new CmifDomainInHeader { - Type = CmifDomainRequestType.SendMessage, + Type = CmifDomainRequestType.SendMessage, ObjectsCount = (byte)format.ObjectsCount, - DataSize = (ushort)payloadSize, - ObjectId = format.ObjectId, - Padding = 0, - Token = format.Context + DataSize = (ushort)payloadSize, + ObjectId = format.ObjectId, + Padding = 0, + Token = format.Context, }; data = data[(Unsafe.SizeOf() / sizeof(uint))..]; @@ -72,12 +72,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif ref CmifInHeader header = ref MemoryMarshal.Cast(data)[0]; - header = new CmifInHeader() + header = new CmifInHeader { - Magic = CmifInHeaderMagic, - Version = format.Context != 0 ? 1u : 0u, + Magic = CmifInHeaderMagic, + Version = format.Context != 0 ? 1u : 0u, CommandId = format.RequestId, - Token = format.ObjectId != 0 ? 0u : format.Context + Token = format.ObjectId != 0 ? 0u : format.Context, }; request.Data = MemoryMarshal.Cast(data)[Unsafe.SizeOf()..]; @@ -86,7 +86,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif Span outPointerTable = MemoryMarshal.Cast(request.Hipc.DataWords)[(outPointerSizeTableOffset - paddingSizeBefore)..]; - request.OutPointerSizes = MemoryMarshal.Cast(outPointerTable); + request.OutPointerSizes = MemoryMarshal.Cast(outPointerTable); request.ServerPointerSize = format.ServerPointerSize; return request; @@ -96,12 +96,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { HipcMessage responseMessage = new(input); - Span data = MemoryMarshal.Cast(responseMessage.Data.DataWords); + Span data = MemoryMarshal.Cast(responseMessage.Data.DataWords); Span objects = Span.Empty; if (isDomain) { - data = data[Unsafe.SizeOf()..]; + data = data[Unsafe.SizeOf()..]; objects = MemoryMarshal.Cast(data[(Unsafe.SizeOf() + size)..]); } @@ -121,15 +121,15 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif return header.Result; } - response = new CmifResponse() + response = new CmifResponse { - Data = data[Unsafe.SizeOf()..], - Objects = objects, + Data = data[Unsafe.SizeOf()..], + Objects = objects, CopyHandles = responseMessage.Data.CopyHandles, - MoveHandles = responseMessage.Data.MoveHandles + MoveHandles = responseMessage.Data.MoveHandles, }; return Result.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifOutHeader.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifOutHeader.cs index 00b9d2bd..ae32e78d 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifOutHeader.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifOutHeader.cs @@ -4,11 +4,11 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { struct CmifOutHeader { -#pragma warning disable CS0649 - public uint Magic; - public uint Version; +#pragma warning disable CS0649 // Field is never assigned to + public uint Magic; + public uint Version; public Result Result; - public uint Token; + public uint Token; #pragma warning restore CS0649 } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifRequest.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifRequest.cs index e44a84ec..80772ad3 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifRequest.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifRequest.cs @@ -6,9 +6,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif ref struct CmifRequest { public HipcMessageData Hipc; - public Span Data; - public Span OutPointerSizes; - public Span Objects; - public int ServerPointerSize; + public Span Data; + public Span OutPointerSizes; + public Span Objects; + public int ServerPointerSize; } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifRequestFormat.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifRequestFormat.cs index 592f11f4..c32646e3 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifRequestFormat.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifRequestFormat.cs @@ -2,22 +2,22 @@ { struct CmifRequestFormat { -#pragma warning disable CS0649 - public int ObjectId; +#pragma warning disable CS0649 // Field is never assigned to + public int ObjectId; public uint RequestId; public uint Context; - public int DataSize; - public int ServerPointerSize; - public int InAutoBuffersCount; - public int OutAutoBuffersCount; - public int InBuffersCount; - public int OutBuffersCount; - public int InOutBuffersCount; - public int InPointersCount; - public int OutPointersCount; - public int OutFixedPointersCount; - public int ObjectsCount; - public int HandlesCount; + public int DataSize; + public int ServerPointerSize; + public int InAutoBuffersCount; + public int OutAutoBuffersCount; + public int InBuffersCount; + public int OutBuffersCount; + public int InOutBuffersCount; + public int InPointersCount; + public int OutPointersCount; + public int OutFixedPointersCount; + public int ObjectsCount; + public int HandlesCount; public bool SendPid; #pragma warning restore CS0649 } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifResponse.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifResponse.cs index 2ff31eb6..d1d8dc9c 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifResponse.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CmifResponse.cs @@ -6,7 +6,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { public ReadOnlySpan Data; public ReadOnlySpan Objects; - public ReadOnlySpan CopyHandles; - public ReadOnlySpan MoveHandles; + public ReadOnlySpan CopyHandles; + public ReadOnlySpan MoveHandles; } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CommandType.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CommandType.cs index 82c0648b..4f6c50fc 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CommandType.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/CommandType.cs @@ -2,13 +2,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { enum CommandType { - Invalid = 0, - LegacyRequest = 1, - Close = 2, - LegacyControl = 3, - Request = 4, - Control = 5, + Invalid = 0, + LegacyRequest = 1, + Close = 2, + LegacyControl = 3, + Request = 4, + Control = 5, RequestWithContext = 6, - ControlWithContext = 7 + ControlWithContext = 7, } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/DomainServiceObjectDispatchTable.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/DomainServiceObjectDispatchTable.cs index b0b4498d..ccfacd90 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/DomainServiceObjectDispatchTable.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/DomainServiceObjectDispatchTable.cs @@ -12,7 +12,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif return ProcessMessageImpl(ref context, ((DomainServiceObject)context.ServiceObject).GetServerDomain(), inRawData); } - private Result ProcessMessageImpl(ref ServiceDispatchContext context, ServerDomainBase domain, ReadOnlySpan inRawData) + private static Result ProcessMessageImpl(ref ServiceDispatchContext context, ServerDomainBase domain, ReadOnlySpan inRawData) { if (inRawData.Length < Unsafe.SizeOf()) { diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/DomainServiceObjectProcessor.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/DomainServiceObjectProcessor.cs index 796b8a78..20ac5f10 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/DomainServiceObjectProcessor.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/DomainServiceObjectProcessor.cs @@ -19,7 +19,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif private int InObjectsCount => _inObjectIds.Length; private int OutObjectsCount => _implMetadata.OutObjectsCount; - private int ImplOutHeadersSize => _implMetadata.OutHeadersSize; private int ImplOutDataTotalSize => _implMetadata.OutDataSize + _implMetadata.OutHeadersSize; public DomainServiceObjectProcessor(ServerDomainBase domain, int[] inObjectIds) diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/HandlesToClose.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/HandlesToClose.cs index 0f3b259a..3c37e8b2 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/HandlesToClose.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/HandlesToClose.cs @@ -17,7 +17,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif public int this[int index] { - get + readonly get { return index switch { @@ -29,22 +29,39 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif 5 => _handle5, 6 => _handle6, 7 => _handle7, - _ => throw new IndexOutOfRangeException() + _ => throw new IndexOutOfRangeException(), }; } set { switch (index) { - case 0: _handle0 = value; break; - case 1: _handle1 = value; break; - case 2: _handle2 = value; break; - case 3: _handle3 = value; break; - case 4: _handle4 = value; break; - case 5: _handle5 = value; break; - case 6: _handle6 = value; break; - case 7: _handle7 = value; break; - default: throw new IndexOutOfRangeException(); + case 0: + _handle0 = value; + break; + case 1: + _handle1 = value; + break; + case 2: + _handle2 = value; + break; + case 3: + _handle3 = value; + break; + case 4: + _handle4 = value; + break; + case 5: + _handle5 = value; + break; + case 6: + _handle6 = value; + break; + case 7: + _handle7 = value; + break; + default: + throw new IndexOutOfRangeException(); } } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/PointerAndSize.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/PointerAndSize.cs index ad0e1824..23780c7c 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/PointerAndSize.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/PointerAndSize.cs @@ -1,6 +1,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { - struct PointerAndSize + readonly struct PointerAndSize { public static PointerAndSize Empty => new(0UL, 0UL); @@ -11,7 +11,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif public PointerAndSize(ulong address, ulong size) { Address = address; - Size = size; + Size = size; } } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ScopedInlineContextChange.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ScopedInlineContextChange.cs index eabe544f..0126d1f6 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ScopedInlineContextChange.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ScopedInlineContextChange.cs @@ -2,7 +2,7 @@ using System; namespace Ryujinx.Horizon.Sdk.Sf.Cmif { - struct ScopedInlineContextChange : IDisposable + readonly struct ScopedInlineContextChange : IDisposable { private readonly int _previousContext; diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs index f789b6c0..f0222991 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs @@ -211,7 +211,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif private readonly EntryManager _entryManager; private readonly object _entryOwnerLock; private readonly HashSet _domains; - private int _maxDomains; + private readonly int _maxDomains; public ServerDomainManager(int entryCount, int maxDomains) { diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerMessageRuntimeMetadata.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerMessageRuntimeMetadata.cs index 6a92e8d5..20667602 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerMessageRuntimeMetadata.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerMessageRuntimeMetadata.cs @@ -1,30 +1,30 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { - struct ServerMessageRuntimeMetadata + readonly struct ServerMessageRuntimeMetadata { - public ushort InDataSize { get; } - public ushort OutDataSize { get; } - public byte InHeadersSize { get; } - public byte OutHeadersSize { get; } - public byte InObjectsCount { get; } - public byte OutObjectsCount { get; } + public ushort InDataSize { get; } + public ushort OutDataSize { get; } + public byte InHeadersSize { get; } + public byte OutHeadersSize { get; } + public byte InObjectsCount { get; } + public byte OutObjectsCount { get; } public int UnfixedOutPointerSizeOffset => InDataSize + InHeadersSize + 0x10; public ServerMessageRuntimeMetadata( ushort inDataSize, ushort outDataSize, - byte inHeadersSize, - byte outHeadersSize, - byte inObjectsCount, - byte outObjectsCount) + byte inHeadersSize, + byte outHeadersSize, + byte inObjectsCount, + byte outObjectsCount) { - InDataSize = inDataSize; - OutDataSize = outDataSize; - InHeadersSize = inHeadersSize; - OutHeadersSize = outHeadersSize; - InObjectsCount = inObjectsCount; + InDataSize = inDataSize; + OutDataSize = outDataSize; + InHeadersSize = inHeadersSize; + OutHeadersSize = outHeadersSize; + InObjectsCount = inObjectsCount; OutObjectsCount = outObjectsCount; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchContext.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchContext.cs index 31be810d..3339a1a6 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchContext.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchContext.cs @@ -5,14 +5,14 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { ref struct ServiceDispatchContext { - public IServiceObject ServiceObject; - public ServerSessionManager Manager; - public ServerSession Session; + public IServiceObject ServiceObject; + public ServerSessionManager Manager; + public ServerSession Session; public ServerMessageProcessor Processor; - public HandlesToClose HandlesToClose; - public PointerAndSize PointerBuffer; - public ReadOnlySpan InMessageBuffer; - public Span OutMessageBuffer; - public HipcMessage Request; + public HandlesToClose HandlesToClose; + public PointerAndSize PointerBuffer; + public ReadOnlySpan InMessageBuffer; + public Span OutMessageBuffer; + public HipcMessage Request; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchMeta.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchMeta.cs index 7fbd8eb8..286e9414 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchMeta.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchMeta.cs @@ -1,6 +1,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { - struct ServiceDispatchMeta + readonly struct ServiceDispatchMeta { public ServiceDispatchTableBase DispatchTable { get; } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchTable.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchTable.cs index 21b342df..145c1783 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchTable.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchTable.cs @@ -12,7 +12,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif public ServiceDispatchTable(string objectName, IReadOnlyDictionary entries) { _objectName = objectName; - _entries = entries; + _entries = entries; } public override Result ProcessMessage(ref ServiceDispatchContext context, ReadOnlySpan inRawData) @@ -30,4 +30,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif return new ServiceDispatchTable(instance.GetType().Name, instance.GetCommandHandlers()); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchTableBase.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchTableBase.cs index 81600067..a127bfcd 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchTableBase.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServiceDispatchTableBase.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif public abstract Result ProcessMessage(ref ServiceDispatchContext context, ReadOnlySpan inRawData); - protected Result ProcessMessageImpl(ref ServiceDispatchContext context, ReadOnlySpan inRawData, IReadOnlyDictionary entries, string objectName) + protected static Result ProcessMessageImpl(ref ServiceDispatchContext context, ReadOnlySpan inRawData, IReadOnlyDictionary entries, string objectName) { if (inRawData.Length < Unsafe.SizeOf()) { @@ -44,7 +44,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif // If ignore missing services is enabled, just pretend that everything is fine. PrepareForStubReply(ref context, out Span outRawData); CommandHandler.GetCmifOutHeaderPointer(ref outHeader, ref outRawData); - outHeader[0] = new CmifOutHeader() { Magic = CmifMessage.CmifOutHeaderMagic, Result = Result.Success }; + outHeader[0] = new CmifOutHeader { Magic = CmifMessage.CmifOutHeaderMagic, Result = Result.Success }; Logger.Warning?.Print(LogClass.Service, $"Missing service {objectName} (command ID: {commandId}) ignored"); @@ -80,7 +80,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif return commandResult; } - outHeader[0] = new CmifOutHeader() { Magic = CmifMessage.CmifOutHeaderMagic, Result = commandResult }; + outHeader[0] = new CmifOutHeader { Magic = CmifMessage.CmifOutHeaderMagic, Result = commandResult }; return Result.Success; } @@ -91,4 +91,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif outRawData = MemoryMarshal.Cast(response.DataWords); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/CommandArg.cs b/src/Ryujinx.Horizon/Sdk/Sf/CommandArg.cs index 47aedde9..f6b54403 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/CommandArg.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/CommandArg.cs @@ -15,42 +15,42 @@ namespace Ryujinx.Horizon.Sdk.Sf OutCopyHandle, OutMoveHandle, OutObject, - ProcessId + ProcessId, } - struct CommandArg + readonly struct CommandArg { - public CommandArgType Type { get; } - public HipcBufferFlags BufferFlags { get; } - public ushort BufferFixedSize { get; } - public int ArgSize { get; } - public int ArgAlignment { get; } + public CommandArgType Type { get; } + public HipcBufferFlags BufferFlags { get; } + public ushort BufferFixedSize { get; } + public int ArgSize { get; } + public int ArgAlignment { get; } public CommandArg(CommandArgType type) { - Type = type; - BufferFlags = default; + Type = type; + BufferFlags = default; BufferFixedSize = 0; - ArgSize = 0; - ArgAlignment = 0; + ArgSize = 0; + ArgAlignment = 0; } public CommandArg(CommandArgType type, int argSize, int argAlignment) { - Type = type; - BufferFlags = default; + Type = type; + BufferFlags = default; BufferFixedSize = 0; - ArgSize = argSize; - ArgAlignment = argAlignment; + ArgSize = argSize; + ArgAlignment = argAlignment; } public CommandArg(HipcBufferFlags flags, ushort fixedSize = 0) { - Type = CommandArgType.Buffer; - BufferFlags = flags; + Type = CommandArgType.Buffer; + BufferFlags = flags; BufferFixedSize = fixedSize; - ArgSize = 0; - ArgAlignment = 0; + ArgSize = 0; + ArgAlignment = 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/CommandArgAttributes.cs b/src/Ryujinx.Horizon/Sdk/Sf/CommandArgAttributes.cs index 294c7d58..5b7c302f 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/CommandArgAttributes.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/CommandArgAttributes.cs @@ -6,8 +6,8 @@ namespace Ryujinx.Horizon.Sdk.Sf [AttributeUsage(AttributeTargets.Parameter)] class BufferAttribute : Attribute { - public HipcBufferFlags Flags { get; } - public ushort FixedSize { get; } + public HipcBufferFlags Flags { get; } + public ushort FixedSize { get; } public BufferAttribute(HipcBufferFlags flags) { @@ -16,7 +16,7 @@ namespace Ryujinx.Horizon.Sdk.Sf public BufferAttribute(HipcBufferFlags flags, ushort fixedSize) { - Flags = flags | HipcBufferFlags.FixedSize; + Flags = flags | HipcBufferFlags.FixedSize; FixedSize = fixedSize; } } @@ -35,4 +35,4 @@ namespace Ryujinx.Horizon.Sdk.Sf class MoveHandleAttribute : Attribute { } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/CommandHandler.cs b/src/Ryujinx.Horizon/Sdk/Sf/CommandHandler.cs index 081ce3be..fb88eaaa 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/CommandHandler.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/CommandHandler.cs @@ -9,20 +9,20 @@ namespace Ryujinx.Horizon.Sdk.Sf class CommandHandler { public delegate Result MethodInvoke( - ref ServiceDispatchContext context, - HipcCommandProcessor processor, + ref ServiceDispatchContext context, + HipcCommandProcessor processor, ServerMessageRuntimeMetadata runtimeMetadata, - ReadOnlySpan inRawData, - ref Span outHeader); + ReadOnlySpan inRawData, + ref Span outHeader); - private readonly MethodInvoke _invoke; + private readonly MethodInvoke _invoke; private readonly HipcCommandProcessor _processor; public string MethodName => _invoke.Method.Name; public CommandHandler(MethodInvoke invoke, params CommandArg[] args) { - _invoke = invoke; + _invoke = invoke; _processor = new HipcCommandProcessor(args); } @@ -37,16 +37,16 @@ namespace Ryujinx.Horizon.Sdk.Sf context.Processor.SetImplementationProcessor(_processor); } - var runtimeMetadata = context.Processor.GetRuntimeMetadata(); - Result result = context.Processor.PrepareForProcess(ref context, runtimeMetadata); + var runtimeMetadata = context.Processor.GetRuntimeMetadata(); + Result result = context.Processor.PrepareForProcess(ref context, runtimeMetadata); return result.IsFailure ? result : _invoke(ref context, _processor, runtimeMetadata, inRawData, ref outHeader); } public static void GetCmifOutHeaderPointer(ref Span outHeader, ref Span outRawData) { - outHeader = MemoryMarshal.Cast(outRawData)[..1]; + outHeader = MemoryMarshal.Cast(outRawData)[..1]; outRawData = outRawData[Unsafe.SizeOf()..]; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/CommandSerialization.cs b/src/Ryujinx.Horizon/Sdk/Sf/CommandSerialization.cs index 4205d3c1..a14892a8 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/CommandSerialization.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/CommandSerialization.cs @@ -66,4 +66,4 @@ namespace Ryujinx.Horizon.Sdk.Sf response.MoveHandles[index] = value; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Api.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Api.cs index 33c42825..530f81bd 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Api.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Api.cs @@ -41,10 +41,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return HorizonStatic.Syscall.ReplyAndReceive(out _, handles, 0, -1L); } - else - { - throw new NotImplementedException(); - } + + throw new NotImplementedException(); } public static Result Reply(int sessionHandle, ReadOnlySpan messageBuffer) @@ -64,10 +62,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return HorizonStatic.Syscall.ReplyAndReceive(out _, ReadOnlySpan.Empty, sessionHandle, 0); } - else - { - throw new NotImplementedException(); - } + + throw new NotImplementedException(); } public static Result CreateSession(out int serverHandle, out int clientHandle) @@ -82,4 +78,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return result; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Header.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Header.cs index cdb50b57..04abf693 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Header.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Header.cs @@ -10,55 +10,55 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public CommandType Type { - get => (CommandType)_word0.Extract(0, 16); + readonly get => (CommandType)_word0.Extract(0, 16); set => _word0 = _word0.Insert(0, 16, (uint)value); } public int SendStaticsCount { - get => (int)_word0.Extract(16, 4); + readonly get => (int)_word0.Extract(16, 4); set => _word0 = _word0.Insert(16, 4, (uint)value); } public int SendBuffersCount { - get => (int)_word0.Extract(20, 4); + readonly get => (int)_word0.Extract(20, 4); set => _word0 = _word0.Insert(20, 4, (uint)value); } public int ReceiveBuffersCount { - get => (int)_word0.Extract(24, 4); + readonly get => (int)_word0.Extract(24, 4); set => _word0 = _word0.Insert(24, 4, (uint)value); } public int ExchangeBuffersCount { - get => (int)_word0.Extract(28, 4); + readonly get => (int)_word0.Extract(28, 4); set => _word0 = _word0.Insert(28, 4, (uint)value); } public int DataWordsCount { - get => (int)_word1.Extract(0, 10); + readonly get => (int)_word1.Extract(0, 10); set => _word1 = _word1.Insert(0, 10, (uint)value); } public int ReceiveStaticMode { - get => (int)_word1.Extract(10, 4); + readonly get => (int)_word1.Extract(10, 4); set => _word1 = _word1.Insert(10, 4, (uint)value); } public int ReceiveListOffset { - get => (int)_word1.Extract(20, 11); + readonly get => (int)_word1.Extract(20, 11); set => _word1 = _word1.Insert(20, 11, (uint)value); } public bool HasSpecialHeader { - get => _word1.Extract(31); + readonly get => _word1.Extract(31); set => _word1 = _word1.Insert(31, value); } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferDescriptor.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferDescriptor.cs index 7778d5bc..bef772e6 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferDescriptor.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferDescriptor.cs @@ -1,11 +1,11 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { - struct HipcBufferDescriptor + readonly struct HipcBufferDescriptor { -#pragma warning disable CS0649 - private uint _sizeLow; - private uint _addressLow; - private uint _word2; +#pragma warning disable CS0649 // Field is never assigned to + private readonly uint _sizeLow; + private readonly uint _addressLow; + private readonly uint _word2; #pragma warning restore CS0649 public ulong Address => _addressLow | (((ulong)_word2 << 4) & 0xf00000000UL) | (((ulong)_word2 << 34) & 0x7000000000UL); diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs index 269ab4fe..b1523d61 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs @@ -5,13 +5,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc [Flags] enum HipcBufferFlags : byte { - In = 1 << 0, - Out = 1 << 1, - MapAlias = 1 << 2, - Pointer = 1 << 3, - FixedSize = 1 << 4, - AutoSelect = 1 << 5, + In = 1 << 0, + Out = 1 << 1, + MapAlias = 1 << 2, + Pointer = 1 << 3, + FixedSize = 1 << 4, + AutoSelect = 1 << 5, MapTransferAllowsNonSecure = 1 << 6, - MapTransferAllowsNonDevice = 1 << 7 + MapTransferAllowsNonDevice = 1 << 7, } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs index b1e67253..bc2d5336 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs @@ -2,9 +2,9 @@ { enum HipcBufferMode { - Normal = 0, + Normal = 0, NonSecure = 1, - Invalid = 2, - NonDevice = 3 + Invalid = 2, + NonDevice = 3, } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs index 7541e294..f72d8e81 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs @@ -112,4 +112,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return Result.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs index 6500d6cf..82cf6e75 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs @@ -10,9 +10,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { public const int AutoReceiveStatic = byte.MaxValue; - public HipcMetadata Meta; + public HipcMetadata Meta; public HipcMessageData Data; - public ulong Pid; + public ulong Pid; public HipcMessage(Span data) { @@ -22,8 +22,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc data = data[Unsafe.SizeOf
()..]; - int receiveStaticsCount = 0; - ulong pid = 0; + int receiveStaticsCount = 0; + ulong pid = 0; if (header.ReceiveStaticMode != 0) { @@ -42,75 +42,75 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc if (header.HasSpecialHeader) { specialHeader = MemoryMarshal.Cast(data)[0]; - data = data[Unsafe.SizeOf()..]; + data = data[Unsafe.SizeOf()..]; if (specialHeader.SendPid) { - pid = MemoryMarshal.Cast(data)[0]; + pid = MemoryMarshal.Cast(data)[0]; data = data[sizeof(ulong)..]; } } - Meta = new HipcMetadata() + Meta = new HipcMetadata { - Type = (int)header.Type, - SendStaticsCount = header.SendStaticsCount, - SendBuffersCount = header.SendBuffersCount, - ReceiveBuffersCount = header.ReceiveBuffersCount, + Type = (int)header.Type, + SendStaticsCount = header.SendStaticsCount, + SendBuffersCount = header.SendBuffersCount, + ReceiveBuffersCount = header.ReceiveBuffersCount, ExchangeBuffersCount = header.ExchangeBuffersCount, - DataWordsCount = header.DataWordsCount, - ReceiveStaticsCount = receiveStaticsCount, - SendPid = specialHeader.SendPid, - CopyHandlesCount = specialHeader.CopyHandlesCount, - MoveHandlesCount = specialHeader.MoveHandlesCount + DataWordsCount = header.DataWordsCount, + ReceiveStaticsCount = receiveStaticsCount, + SendPid = specialHeader.SendPid, + CopyHandlesCount = specialHeader.CopyHandlesCount, + MoveHandlesCount = specialHeader.MoveHandlesCount, }; Data = CreateMessageData(Meta, data, initialLength); - Pid = pid; + Pid = pid; } public static HipcMessageData WriteResponse( Span destination, - int sendStaticCount, - int dataWordsCount, - int copyHandlesCount, - int moveHandlesCount) + int sendStaticCount, + int dataWordsCount, + int copyHandlesCount, + int moveHandlesCount) { - return WriteMessage(destination, new HipcMetadata() + return WriteMessage(destination, new HipcMetadata { SendStaticsCount = sendStaticCount, - DataWordsCount = dataWordsCount, + DataWordsCount = dataWordsCount, CopyHandlesCount = copyHandlesCount, - MoveHandlesCount = moveHandlesCount + MoveHandlesCount = moveHandlesCount, }); } public static HipcMessageData WriteMessage(Span destination, HipcMetadata meta) { - int initialLength = destination.Length; + int initialLength = destination.Length; bool hasSpecialHeader = meta.SendPid || meta.CopyHandlesCount != 0 || meta.MoveHandlesCount != 0; - MemoryMarshal.Cast(destination)[0] = new Header() + MemoryMarshal.Cast(destination)[0] = new Header { - Type = (CommandType)meta.Type, - SendStaticsCount = meta.SendStaticsCount, - SendBuffersCount = meta.SendBuffersCount, - ReceiveBuffersCount = meta.ReceiveBuffersCount, + Type = (CommandType)meta.Type, + SendStaticsCount = meta.SendStaticsCount, + SendBuffersCount = meta.SendBuffersCount, + ReceiveBuffersCount = meta.ReceiveBuffersCount, ExchangeBuffersCount = meta.ExchangeBuffersCount, - DataWordsCount = meta.DataWordsCount, - ReceiveStaticMode = meta.ReceiveStaticsCount != 0 ? (meta.ReceiveStaticsCount != AutoReceiveStatic ? meta.ReceiveStaticsCount + 2 : 2) : 0, - HasSpecialHeader = hasSpecialHeader + DataWordsCount = meta.DataWordsCount, + ReceiveStaticMode = meta.ReceiveStaticsCount != 0 ? (meta.ReceiveStaticsCount != AutoReceiveStatic ? meta.ReceiveStaticsCount + 2 : 2) : 0, + HasSpecialHeader = hasSpecialHeader, }; destination = destination[Unsafe.SizeOf
()..]; if (hasSpecialHeader) { - MemoryMarshal.Cast(destination)[0] = new SpecialHeader() + MemoryMarshal.Cast(destination)[0] = new SpecialHeader { - SendPid = meta.SendPid, + SendPid = meta.SendPid, CopyHandlesCount = meta.CopyHandlesCount, - MoveHandlesCount = meta.MoveHandlesCount + MoveHandlesCount = meta.MoveHandlesCount, }; destination = destination[Unsafe.SizeOf()..]; @@ -184,9 +184,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc if (meta.DataWordsCount != 0) { - int dataOffset = initialLength - data.Length; + int dataOffset = initialLength - data.Length; int dataOffsetAligned = BitUtils.AlignUp(dataOffset, 0x10); - int padding = (dataOffsetAligned - dataOffset) / sizeof(uint); + int padding = (dataOffsetAligned - dataOffset) / sizeof(uint); dataWords = MemoryMarshal.Cast(data)[padding..meta.DataWordsCount]; @@ -202,16 +202,16 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc receiveList = MemoryMarshal.Cast(data)[..receiveListSize]; } - return new HipcMessageData() + return new HipcMessageData { - SendStatics = sendStatics, - SendBuffers = sendBuffers, - ReceiveBuffers = receiveBuffers, + SendStatics = sendStatics, + SendBuffers = sendBuffers, + ReceiveBuffers = receiveBuffers, ExchangeBuffers = exchangeBuffers, - DataWords = dataWords, - ReceiveList = receiveList, - CopyHandles = copyHandles, - MoveHandles = moveHandles + DataWords = dataWords, + ReceiveList = receiveList, + CopyHandles = copyHandles, + MoveHandles = moveHandles, }; } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs index 154b8f07..c83c422c 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs @@ -8,9 +8,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public Span SendBuffers; public Span ReceiveBuffers; public Span ExchangeBuffers; - public Span DataWords; + public Span DataWords; public Span ReceiveList; - public Span CopyHandles; - public Span MoveHandles; + public Span CopyHandles; + public Span MoveHandles; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs index 10abc400..fe13137a 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs @@ -2,15 +2,15 @@ { struct HipcMetadata { - public int Type; - public int SendStaticsCount; - public int SendBuffersCount; - public int ReceiveBuffersCount; - public int ExchangeBuffersCount; - public int DataWordsCount; - public int ReceiveStaticsCount; + public int Type; + public int SendStaticsCount; + public int SendBuffersCount; + public int ReceiveBuffersCount; + public int ExchangeBuffersCount; + public int DataWordsCount; + public int ReceiveStaticsCount; public bool SendPid; - public int CopyHandlesCount; - public int MoveHandlesCount; + public int CopyHandlesCount; + public int MoveHandlesCount; } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs index 56cf16fb..955428b8 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs @@ -1,14 +1,16 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { - struct HipcReceiveListEntry + readonly struct HipcReceiveListEntry { - private uint _addressLow; - private uint _word1; +#pragma warning disable IDE0052 // Remove unread private member + private readonly uint _addressLow; + private readonly uint _word1; +#pragma warning restore IDE0052 public HipcReceiveListEntry(ulong address, ulong size) { _addressLow = (uint)address; - _word1 = (ushort)(address >> 32) | (uint)(size << 16); + _word1 = (ushort)(address >> 32) | (uint)(size << 16); } } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs index 3b483be8..faf5dc41 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs @@ -6,6 +6,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { public const int ModuleId = 11; +#pragma warning disable IDE0055 // Disable formatting public static Result OutOfSessionMemory => new(ModuleId, 102); public static Result OutOfSessions => new(ModuleId, 131); public static Result PointerBufferTooSmall => new(ModuleId, 141); @@ -15,5 +16,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public static Result InvalidCmifRequest => new(ModuleId, 420); public static Result TargetNotDomain => new(ModuleId, 491); public static Result DomainObjectNotFound => new(ModuleId, 492); + #pragma warning restore IDE0055 } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs index 103820a6..43e7afb9 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs @@ -1,12 +1,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { - struct HipcStaticDescriptor + readonly struct HipcStaticDescriptor { private readonly ulong _data; - public ulong Address => ((((_data >> 2) & 0x70) | ((_data >> 12) & 0xf)) << 32) | (_data >> 32); - public ushort Size => (ushort)(_data >> 16); - public int ReceiveIndex => (int)(_data & 0xf); + public ulong Address => ((((_data >> 2) & 0x70) | ((_data >> 12) & 0xf)) << 32) | (_data >> 32); + public ushort Size => (ushort)(_data >> 16); + public int ReceiveIndex => (int)(_data & 0xf); public HipcStaticDescriptor(ulong address, ushort size, int receiveIndex) { @@ -19,4 +19,4 @@ _data = data; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs index b99d63c5..e747490e 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs @@ -1,20 +1,20 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { - struct ManagerOptions + readonly struct ManagerOptions { public static ManagerOptions Default => new(0, 0, 0, false); - public int PointerBufferSize { get; } - public int MaxDomains { get; } - public int MaxDomainObjects { get; } + public int PointerBufferSize { get; } + public int MaxDomains { get; } + public int MaxDomainObjects { get; } public bool CanDeferInvokeRequest { get; } public ManagerOptions(int pointerBufferSize, int maxDomains, int maxDomainObjects, bool canDeferInvokeRequest) { - PointerBufferSize = pointerBufferSize; - MaxDomains = maxDomains; - MaxDomainObjects = maxDomainObjects; + PointerBufferSize = pointerBufferSize; + MaxDomains = maxDomains; + MaxDomainObjects = maxDomainObjects; CanDeferInvokeRequest = canDeferInvokeRequest; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ReceiveResult.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ReceiveResult.cs index 7c380a01..efe99f3f 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ReceiveResult.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ReceiveResult.cs @@ -4,6 +4,6 @@ { Success, Closed, - NeedsRetry + NeedsRetry, } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs index bbbab898..923f2d52 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs @@ -6,22 +6,22 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { class Server : MultiWaitHolderOfHandle { - public int PortIndex { get; } - public int PortHandle { get; } - public ServiceName Name { get; } - public bool Managed { get; } + public int PortIndex { get; } + public int PortHandle { get; } + public ServiceName Name { get; } + public bool Managed { get; } public ServiceObjectHolder StaticObject { get; } public Server( - int portIndex, - int portHandle, - ServiceName name, - bool managed, + int portIndex, + int portHandle, + ServiceName name, + bool managed, ServiceObjectHolder staticHoder) : base(portHandle) { PortHandle = portHandle; - Name = name; - Managed = managed; + Name = name; + Managed = managed; if (staticHoder != null) { diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs index 2ca9ceea..9ac2a337 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs @@ -14,8 +14,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc private readonly bool _canDeferInvokeRequest; private readonly int _maxSessions; - private ulong _pointerBuffersBaseAddress; - private ulong _savedMessagesBaseAddress; + private readonly ulong _pointerBuffersBaseAddress; + private readonly ulong _savedMessagesBaseAddress; private readonly object _resourceLock; private readonly ulong[] _sessionAllocationBitmap; @@ -35,7 +35,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc if (options.CanDeferInvokeRequest) { - _savedMessagesBaseAddress = allocator.Allocate((ulong)maxSessions * (ulong)Api.TlsMessageBufferSize); + _savedMessagesBaseAddress = allocator.Allocate((ulong)maxSessions * Api.TlsMessageBufferSize); } } @@ -45,7 +45,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc _servers = new HashSet(); } - private PointerAndSize GetObjectBySessionIndex(ServerSession session, ulong baseAddress, ulong size) + private static PointerAndSize GetObjectBySessionIndex(ServerSession session, ulong baseAddress, ulong size) { return new PointerAndSize(baseAddress + (ulong)session.SessionIndex * size, size); } @@ -61,7 +61,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return null; } - for (int i = 0; i <_sessionAllocationBitmap.Length; i++) + for (int i = 0; i < _sessionAllocationBitmap.Length; i++) { ref ulong mask = ref _sessionAllocationBitmap[i]; @@ -145,10 +145,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return GetObjectBySessionIndex(session, _pointerBuffersBaseAddress, (ulong)_pointerBufferSize); } - else - { - return PointerAndSize.Empty; - } + + return PointerAndSize.Empty; } protected override PointerAndSize GetSessionSavedMessageBuffer(ServerSession session) @@ -157,10 +155,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return GetObjectBySessionIndex(session, _savedMessagesBaseAddress, Api.TlsMessageBufferSize); } - else - { - return PointerAndSize.Empty; - } + + return PointerAndSize.Empty; } protected virtual void Dispose(bool disposing) diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs index c36cdda2..76407840 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs @@ -10,7 +10,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { private readonly SmApi _sm; - private bool _canDeferInvokeRequest; + private readonly bool _canDeferInvokeRequest; private readonly MultiWait _multiWait; private readonly MultiWait _waitList; @@ -26,8 +26,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc private enum UserDataTag { - Server = 1, - Session = 2 + Server = 1, + Session = 2, } public ServerManagerBase(SmApi sm, ManagerOptions options) : base(options.MaxDomainObjects, options.MaxDomains) @@ -36,13 +36,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc _canDeferInvokeRequest = options.CanDeferInvokeRequest; _multiWait = new MultiWait(); - _waitList = new MultiWait(); + _waitList = new MultiWait(); _multiWaitSelectionLock = new object(); - _waitListLock = new object(); + _waitListLock = new object(); _requestStopEvent = new Event(EventClearMode.ManualClear); - _notifyEvent = new Event(EventClearMode.ManualClear); + _notifyEvent = new Event(EventClearMode.ManualClear); _requestStopEventHolder = new MultiWaitHolderOfEvent(_requestStopEvent); _multiWait.LinkMultiWaitHolder(_requestStopEventHolder); @@ -113,7 +113,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public void ServiceRequests() { - while (WaitAndProcessRequestsImpl()); + while (WaitAndProcessRequestsImpl()) + { + } } public void WaitAndProcessRequests() @@ -183,7 +185,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc protected override void RegisterSessionToWaitList(ServerSession session) { session.HasReceived = false; - session.UserData = UserDataTag.Session; + session.UserData = UserDataTag.Session; RegisterToWaitList(session); } @@ -209,9 +211,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return (UserDataTag)holder.UserData switch { - UserDataTag.Server => ProcessForServer(holder), + UserDataTag.Server => ProcessForServer(holder), UserDataTag.Session => ProcessForSession(holder), - _ => throw new NotImplementedException(((UserDataTag)holder.UserData).ToString()) + _ => throw new NotImplementedException(((UserDataTag)holder.UserData).ToString()), }; } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs index a1730082..eb98fefd 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs @@ -6,18 +6,18 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc class ServerSession : MultiWaitHolderOfHandle { public ServiceObjectHolder ServiceObjectHolder { get; set; } - public PointerAndSize PointerBuffer { get; set; } - public PointerAndSize SavedMessage { get; set; } - public int SessionIndex { get; } - public int SessionHandle { get; } - public bool IsClosed { get; set; } - public bool HasReceived { get; set; } + public PointerAndSize PointerBuffer { get; set; } + public PointerAndSize SavedMessage { get; set; } + public int SessionIndex { get; } + public int SessionHandle { get; } + public bool IsClosed { get; set; } + public bool HasReceived { get; set; } public ServerSession(int index, int handle, ServiceObjectHolder obj) : base(handle) { ServiceObjectHolder = obj; - SessionIndex = index; - SessionHandle = handle; + SessionIndex = index; + SessionHandle = handle; } } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs index 6d395081..bd5a4844 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs @@ -75,7 +75,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc } session.PointerBuffer = GetSessionPointerBuffer(session); - session.SavedMessage = GetSessionSavedMessageBuffer(session); + session.SavedMessage = GetSessionSavedMessageBuffer(session); RegisterSessionToWaitList(session); @@ -110,10 +110,10 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc } protected virtual Server AllocateServer( - int portIndex, - int portHandle, - ServiceName name, - bool managed, + int portIndex, + int portHandle, + ServiceName name, + bool managed, ServiceObjectHolder staticHoder) { throw new NotSupportedException(); @@ -161,29 +161,25 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return Result.Success; } - else + + Result result = ProcessRequestImpl(session, message, message); + + if (result.IsSuccess) { - Result result = ProcessRequestImpl(session, message, message); + RegisterSessionToWaitList(session); - if (result.IsSuccess) - { - RegisterSessionToWaitList(session); - - return Result.Success; - } - else if (SfResult.RequestContextChanged(result)) - { - return result; - } - else - { - Logger.Warning?.Print(LogClass.KernelIpc, $"Request processing returned error {result}"); - - CloseSessionImpl(session); - - return Result.Success; - } + return Result.Success; } + else if (SfResult.RequestContextChanged(result)) + { + return result; + } + + Logger.Warning?.Print(LogClass.KernelIpc, $"Request processing returned error {result}"); + + CloseSessionImpl(session); + + return Result.Success; } private Result ProcessRequestImpl(ServerSession session, Span inMessage, Span outMessage) @@ -192,18 +188,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc using var _ = new ScopedInlineContextChange(GetInlineContext(commandType, inMessage)); - switch (commandType) + return commandType switch { - case CommandType.Request: - case CommandType.RequestWithContext: - return DispatchRequest(session.ServiceObjectHolder, session, inMessage, outMessage); - case CommandType.Control: - case CommandType.ControlWithContext: - return DispatchManagerRequest(session, inMessage, outMessage); - default: - return HipcResult.UnknownCommandType; + CommandType.Request or CommandType.RequestWithContext => DispatchRequest(session.ServiceObjectHolder, session, inMessage, outMessage), + CommandType.Control or CommandType.ControlWithContext => DispatchManagerRequest(session, inMessage, outMessage), + _ => HipcResult.UnknownCommandType, + }; } - } private static int GetInlineContext(CommandType commandType, ReadOnlySpan inMessage) { @@ -221,12 +212,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return 0; } - protected Result ReceiveRequest(ServerSession session, Span message) + protected static Result ReceiveRequest(ServerSession session, Span message) { return ReceiveRequestImpl(session, message); } - private Result ReceiveRequestImpl(ServerSession session, Span message) + private static Result ReceiveRequestImpl(ServerSession session, Span message) { PointerAndSize pointerBuffer = session.PointerBuffer; @@ -234,19 +225,19 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { if (pointerBuffer.Address != 0) { - HipcMessageData messageData = HipcMessage.WriteMessage(message, new HipcMetadata() + HipcMessageData messageData = HipcMessage.WriteMessage(message, new HipcMetadata { - Type = (int)CommandType.Invalid, - ReceiveStaticsCount = HipcMessage.AutoReceiveStatic + Type = (int)CommandType.Invalid, + ReceiveStaticsCount = HipcMessage.AutoReceiveStatic, }); messageData.ReceiveList[0] = new HipcReceiveListEntry(pointerBuffer.Address, pointerBuffer.Size); } else { - MemoryMarshal.Cast(message)[0] = new Header() + MemoryMarshal.Cast(message)[0] = new Header { - Type = CommandType.Invalid + Type = CommandType.Invalid, }; } @@ -276,9 +267,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc protected virtual Result DispatchRequest( ServiceObjectHolder objectHolder, - ServerSession session, - Span inMessage, - Span outMessage) + ServerSession session, + Span inMessage, + Span outMessage) { HipcMessage request; @@ -291,16 +282,16 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return HipcResult.InvalidRequestSize; } - var dispatchCtx = new ServiceDispatchContext() + var dispatchCtx = new ServiceDispatchContext { - ServiceObject = objectHolder.ServiceObject, - Manager = this, - Session = session, - HandlesToClose = new HandlesToClose(), - PointerBuffer = session.PointerBuffer, - InMessageBuffer = inMessage, + ServiceObject = objectHolder.ServiceObject, + Manager = this, + Session = session, + HandlesToClose = new HandlesToClose(), + PointerBuffer = session.PointerBuffer, + InMessageBuffer = inMessage, OutMessageBuffer = outMessage, - Request = request + Request = request, }; ReadOnlySpan inRawData = MemoryMarshal.Cast(dispatchCtx.Request.Data.DataWords); @@ -337,4 +328,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return this; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/SpecialHeader.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/SpecialHeader.cs index 8b747626..b6304b7b 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/SpecialHeader.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/SpecialHeader.cs @@ -8,19 +8,19 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public bool SendPid { - get => _word.Extract(0); + readonly get => _word.Extract(0); set => _word = _word.Insert(0, value); } public int CopyHandlesCount { - get => (int)_word.Extract(1, 4); + readonly get => (int)_word.Extract(1, 4); set => _word = _word.Insert(1, 4, (uint)value); } public int MoveHandlesCount { - get => (int)_word.Extract(5, 4); + readonly get => (int)_word.Extract(5, 4); set => _word = _word.Insert(5, 4, (uint)value); } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/HipcCommandProcessor.cs b/src/Ryujinx.Horizon/Sdk/Sf/HipcCommandProcessor.cs index a0578d48..08b1d89b 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/HipcCommandProcessor.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/HipcCommandProcessor.cs @@ -134,9 +134,9 @@ namespace Ryujinx.Horizon.Sdk.Sf ulong pointerBufferTail = context.PointerBuffer.Address; ulong pointerBufferHead = pointerBufferTail + context.PointerBuffer.Size; - int sendMapAliasIndex = 0; - int recvMapAliasIndex = 0; - int sendPointerIndex = 0; + int sendMapAliasIndex = 0; + int recvMapAliasIndex = 0; + int sendPointerIndex = 0; int unfixedRecvPointerIndex = 0; for (int i = 0; i < _args.Length; i++) @@ -186,8 +186,8 @@ namespace Ryujinx.Horizon.Sdk.Sf if (flags.HasFlag(HipcBufferFlags.In)) { var descriptor = context.Request.Data.SendStatics[sendPointerIndex++]; - ulong address = descriptor.Address; - ulong size = descriptor.Size; + ulong address = descriptor.Address; + ulong size = descriptor.Size; _bufferRanges[i] = new PointerAndSize(address, size); @@ -206,14 +206,14 @@ namespace Ryujinx.Horizon.Sdk.Sf } else { - var data = MemoryMarshal.Cast(context.Request.Data.DataWords); + var data = MemoryMarshal.Cast(context.Request.Data.DataWords); var recvPointerSizes = MemoryMarshal.Cast(data[runtimeMetadata.UnfixedOutPointerSizeOffset..]); size = recvPointerSizes[unfixedRecvPointerIndex++]; } pointerBufferHead = BitUtils.AlignDown(pointerBufferHead - size, 0x10UL); - _bufferRanges[i] = new PointerAndSize(pointerBufferHead, size); + _bufferRanges[i] = new PointerAndSize(pointerBufferHead, size); } } } @@ -305,13 +305,13 @@ namespace Ryujinx.Horizon.Sdk.Sf { ref var meta = ref context.Request.Meta; bool requestValid = true; - requestValid &= meta.SendPid == _hasInProcessIdHolder; - requestValid &= meta.SendStaticsCount == _inPointerBuffersCount; - requestValid &= meta.SendBuffersCount == _inMapAliasBuffersCount; - requestValid &= meta.ReceiveBuffersCount == _outMapAliasBuffersCount; + requestValid &= meta.SendPid == _hasInProcessIdHolder; + requestValid &= meta.SendStaticsCount == _inPointerBuffersCount; + requestValid &= meta.SendBuffersCount == _inMapAliasBuffersCount; + requestValid &= meta.ReceiveBuffersCount == _outMapAliasBuffersCount; requestValid &= meta.ExchangeBuffersCount == 0; - requestValid &= meta.CopyHandlesCount == _inCopyHandlesCount; - requestValid &= meta.MoveHandlesCount == _inMoveHandlesCount; + requestValid &= meta.CopyHandlesCount == _inCopyHandlesCount; + requestValid &= meta.MoveHandlesCount == _inMoveHandlesCount; int rawSizeInBytes = meta.DataWordsCount * sizeof(uint); int commandRawSize = BitUtils.AlignUp(runtimeMetadata.UnfixedOutPointerSizeOffset + (OutUnfixedSizePointerBuffersCount * sizeof(ushort)), sizeof(uint)); @@ -345,7 +345,7 @@ namespace Ryujinx.Horizon.Sdk.Sf continue; } - int index = inObjectIndex++; + int index = inObjectIndex++; var inObject = inObjects[index]; objects[index] = inObject?.ServiceObject; @@ -386,7 +386,9 @@ namespace Ryujinx.Horizon.Sdk.Sf outRawData = MemoryMarshal.Cast(response.DataWords); } +#pragma warning disable CA1822 // Mark member as static public void SetOutObjects(ref ServiceDispatchContext context, HipcMessageData response, Span objects) +#pragma warning restore CA1822 { if (objects.Length == 0) { @@ -411,7 +413,7 @@ namespace Ryujinx.Horizon.Sdk.Sf } } - private void SetOutObjectImpl(int index, HipcMessageData response, ServerSessionManager manager, ServiceObjectHolder obj) + private static void SetOutObjectImpl(int index, HipcMessageData response, ServerSessionManager manager, ServiceObjectHolder obj) { if (obj == null) { @@ -425,4 +427,4 @@ namespace Ryujinx.Horizon.Sdk.Sf response.MoveHandles[index] = clientHandle; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/RawDataOffsetCalculator.cs b/src/Ryujinx.Horizon/Sdk/Sf/RawDataOffsetCalculator.cs index 10e4f909..0172c115 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/RawDataOffsetCalculator.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/RawDataOffsetCalculator.cs @@ -12,15 +12,15 @@ namespace Ryujinx.Horizon.Sdk.Sf { int argsCount = args.Length; - int[] sizes = new int[argsCount]; + int[] sizes = new int[argsCount]; int[] aligns = new int[argsCount]; - int[] map = new int[argsCount]; + int[] map = new int[argsCount]; for (int i = 0; i < argsCount; i++) { - sizes[i] = args[i].ArgSize; + sizes[i] = args[i].ArgSize; aligns[i] = args[i].ArgAlignment; - map[i] = i; + map[i] = i; } for (int i = 1; i < argsCount; i++) @@ -35,9 +35,9 @@ namespace Ryujinx.Horizon.Sdk.Sf foreach (int i in map) { - offset = BitUtils.AlignUp(offset, aligns[i]); + offset = BitUtils.AlignUp(offset, aligns[i]); offsets[i] = offset; - offset += sizes[i]; + offset += sizes[i]; } offsets[argsCount] = offset; @@ -46,4 +46,4 @@ namespace Ryujinx.Horizon.Sdk.Sf return offsets; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/SfResult.cs b/src/Ryujinx.Horizon/Sdk/Sf/SfResult.cs index 72502d17..029e17af 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/SfResult.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/SfResult.cs @@ -6,6 +6,7 @@ namespace Ryujinx.Horizon.Sdk.Sf { public const int ModuleId = 10; +#pragma warning disable IDE0055 // Disable formatting public static Result NotSupported => new(ModuleId, 1); public static Result InvalidHeaderSize => new(ModuleId, 202); public static Result InvalidInHeader => new(ModuleId, 211); @@ -23,5 +24,6 @@ namespace Ryujinx.Horizon.Sdk.Sf public static bool RequestContextChanged(Result result) => result.InRange(800, 899); public static bool Invalidated(Result result) => result.InRange(801, 809); public static bool RequestDeferred(Result result) => result.InRange(811, 819); +#pragma warning restore IDE0055 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sm/IManagerService.cs b/src/Ryujinx.Horizon/Sdk/Sm/IManagerService.cs index 64428583..2343c7d6 100644 --- a/src/Ryujinx.Horizon/Sdk/Sm/IManagerService.cs +++ b/src/Ryujinx.Horizon/Sdk/Sm/IManagerService.cs @@ -5,4 +5,4 @@ namespace Ryujinx.Horizon.Sdk.Sm interface IManagerService : IServiceObject { } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sm/IUserService.cs b/src/Ryujinx.Horizon/Sdk/Sm/IUserService.cs index ad9bc9d7..8605cdd1 100644 --- a/src/Ryujinx.Horizon/Sdk/Sm/IUserService.cs +++ b/src/Ryujinx.Horizon/Sdk/Sm/IUserService.cs @@ -10,4 +10,4 @@ namespace Ryujinx.Horizon.Sdk.Sm Result RegisterService(out int handle, ServiceName name, int maxSessions, bool isLight); Result UnregisterService(ServiceName name); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sm/ServiceName.cs b/src/Ryujinx.Horizon/Sdk/Sm/ServiceName.cs index 9b7fae3f..f90d39c2 100644 --- a/src/Ryujinx.Horizon/Sdk/Sm/ServiceName.cs +++ b/src/Ryujinx.Horizon/Sdk/Sm/ServiceName.cs @@ -4,13 +4,13 @@ using System.Runtime.InteropServices; namespace Ryujinx.Horizon.Sdk.Sm { [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct ServiceName + readonly struct ServiceName { - public static ServiceName Invalid { get; } = new ServiceName(0); + public static ServiceName Invalid { get; } = new(0); public bool IsValid => Packed != 0; - public int Length => sizeof(ulong); + public const int Length = sizeof(ulong); public ulong Packed { get; } diff --git a/src/Ryujinx.Horizon/Sdk/Sm/SmApi.cs b/src/Ryujinx.Horizon/Sdk/Sm/SmApi.cs index 533e68d9..3e5635bf 100644 --- a/src/Ryujinx.Horizon/Sdk/Sm/SmApi.cs +++ b/src/Ryujinx.Horizon/Sdk/Sm/SmApi.cs @@ -110,4 +110,4 @@ namespace Ryujinx.Horizon.Sdk.Sm return ServiceUtil.SendRequest(out _, _portHandle, 4, sendPid: true, data); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/ServiceEntry.cs b/src/Ryujinx.Horizon/ServiceEntry.cs index 06152d9f..edf76fcd 100644 --- a/src/Ryujinx.Horizon/ServiceEntry.cs +++ b/src/Ryujinx.Horizon/ServiceEntry.cs @@ -4,17 +4,17 @@ using System; namespace Ryujinx.Horizon { - public struct ServiceEntry + public readonly struct ServiceEntry { private readonly Action _entrypoint; - private readonly ServiceTable _serviceTable; - private readonly HorizonOptions _options; + private readonly ServiceTable _serviceTable; + private readonly HorizonOptions _options; internal ServiceEntry(Action entrypoint, ServiceTable serviceTable, HorizonOptions options) { - _entrypoint = entrypoint; + _entrypoint = entrypoint; _serviceTable = serviceTable; - _options = options; + _options = options; } public void Start(ISyscallApi syscallApi, IVirtualMemoryManager addressSpace, IThreadContext threadContext) @@ -24,4 +24,4 @@ namespace Ryujinx.Horizon _entrypoint(_serviceTable); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/ServiceTable.cs b/src/Ryujinx.Horizon/ServiceTable.cs index d97457d9..d47f91bf 100644 --- a/src/Ryujinx.Horizon/ServiceTable.cs +++ b/src/Ryujinx.Horizon/ServiceTable.cs @@ -57,4 +57,4 @@ namespace Ryujinx.Horizon Dispose(true); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sm/Impl/ServiceInfo.cs b/src/Ryujinx.Horizon/Sm/Impl/ServiceInfo.cs index 50c18a2c..fed420aa 100644 --- a/src/Ryujinx.Horizon/Sm/Impl/ServiceInfo.cs +++ b/src/Ryujinx.Horizon/Sm/Impl/ServiceInfo.cs @@ -5,16 +5,16 @@ namespace Ryujinx.Horizon.Sm.Impl struct ServiceInfo { public ServiceName Name; - public ulong OwnerProcessId; - public int PortHandle; + public ulong OwnerProcessId; + public int PortHandle; public void Free() { HorizonStatic.Syscall.CloseHandle(PortHandle); - Name = ServiceName.Invalid; + Name = ServiceName.Invalid; OwnerProcessId = 0L; - PortHandle = 0; + PortHandle = 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sm/Impl/ServiceManager.cs b/src/Ryujinx.Horizon/Sm/Impl/ServiceManager.cs index d1f94267..929474aa 100644 --- a/src/Ryujinx.Horizon/Sm/Impl/ServiceManager.cs +++ b/src/Ryujinx.Horizon/Sm/Impl/ServiceManager.cs @@ -40,7 +40,7 @@ namespace Ryujinx.Horizon.Sm.Impl return result == KernelResult.SessionCountExceeded ? SmResult.OutOfSessions : result; } - private Result GetServiceImpl(out int handle, ref ServiceInfo serviceInfo) + private static Result GetServiceImpl(out int handle, ref ServiceInfo serviceInfo) { return HorizonStatic.Syscall.ConnectToPort(out handle, serviceInfo.PortHandle); } @@ -96,8 +96,8 @@ namespace Ryujinx.Horizon.Sm.Impl return result; } - freeService.PortHandle = clientPort; - freeService.Name = name; + freeService.PortHandle = clientPort; + freeService.Name = name; freeService.OwnerProcessId = processId; return Result.Success; @@ -140,7 +140,7 @@ namespace Ryujinx.Horizon.Sm.Impl int nameLength = 1; - for (; nameLength < name.Length; nameLength++) + for (; nameLength < ServiceName.Length; nameLength++) { if (name[nameLength] == 0) { @@ -148,7 +148,7 @@ namespace Ryujinx.Horizon.Sm.Impl } } - while (nameLength < name.Length) + while (nameLength < ServiceName.Length) { if (name[nameLength++] != 0) { @@ -182,4 +182,4 @@ namespace Ryujinx.Horizon.Sm.Impl return -1; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sm/Ipc/UserService.cs b/src/Ryujinx.Horizon/Sm/Ipc/UserService.cs index d093913a..868a15e6 100644 --- a/src/Ryujinx.Horizon/Sm/Ipc/UserService.cs +++ b/src/Ryujinx.Horizon/Sm/Ipc/UserService.cs @@ -10,7 +10,7 @@ namespace Ryujinx.Horizon.Sm.Ipc private readonly ServiceManager _serviceManager; private ulong _clientProcessId; - private bool _initialized; + private bool _initialized; public UserService(ServiceManager serviceManager) { @@ -21,7 +21,7 @@ namespace Ryujinx.Horizon.Sm.Ipc public Result Initialize([ClientProcessId] ulong clientProcessId) { _clientProcessId = clientProcessId; - _initialized = true; + _initialized = true; return Result.Success; } @@ -63,4 +63,4 @@ namespace Ryujinx.Horizon.Sm.Ipc return _serviceManager.UnregisterService(_clientProcessId, name); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sm/SmMain.cs b/src/Ryujinx.Horizon/Sm/SmMain.cs index f0b4d330..7303847a 100644 --- a/src/Ryujinx.Horizon/Sm/SmMain.cs +++ b/src/Ryujinx.Horizon/Sm/SmMain.cs @@ -1,6 +1,4 @@ -using Ryujinx.Horizon.Prepo; -using Ryujinx.Horizon.Prepo.Types; -using Ryujinx.Horizon.Sdk.Sf.Hipc; +using Ryujinx.Horizon.Sdk.Sf.Hipc; using Ryujinx.Horizon.Sdk.Sm; using Ryujinx.Horizon.Sm.Impl; using Ryujinx.Horizon.Sm.Types; @@ -9,8 +7,8 @@ namespace Ryujinx.Horizon.Sm { public class SmMain { - private const int SmMaxSessionsCount = 64; - private const int SmmMaxSessionsCount = 1; + private const int SmMaxSessionsCount = 64; + private const int SmmMaxSessionsCount = 1; private const int SmTotalMaxSessionsCount = SmMaxSessionsCount + SmmMaxSessionsCount; private const int MaxPortsCount = 2; @@ -31,4 +29,4 @@ namespace Ryujinx.Horizon.Sm _serverManager.ServiceRequests(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sm/SmResult.cs b/src/Ryujinx.Horizon/Sm/SmResult.cs index 2d503a4f..75f47ca9 100644 --- a/src/Ryujinx.Horizon/Sm/SmResult.cs +++ b/src/Ryujinx.Horizon/Sm/SmResult.cs @@ -6,6 +6,7 @@ namespace Ryujinx.Horizon.Sm { private const int ModuleId = 21; +#pragma warning disable IDE0055 // Disable formatting public static Result OutOfProcess => new(ModuleId, 1); public static Result InvalidClient => new(ModuleId, 2); public static Result OutOfSessions => new(ModuleId, 3); @@ -15,5 +16,6 @@ namespace Ryujinx.Horizon.Sm public static Result NotRegistered => new(ModuleId, 7); public static Result NotAllowed => new(ModuleId, 8); public static Result TooLargeAccessControl => new(ModuleId, 9); +#pragma warning restore IDE0055 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sm/SmServerManager.cs b/src/Ryujinx.Horizon/Sm/SmServerManager.cs index dc8dc5b6..c0412345 100644 --- a/src/Ryujinx.Horizon/Sm/SmServerManager.cs +++ b/src/Ryujinx.Horizon/Sm/SmServerManager.cs @@ -21,10 +21,10 @@ namespace Ryujinx.Horizon.Sm { return (SmPortIndex)portIndex switch { - SmPortIndex.User => AcceptImpl(server, new UserService(_serviceManager)), + SmPortIndex.User => AcceptImpl(server, new UserService(_serviceManager)), SmPortIndex.Manager => AcceptImpl(server, new ManagerService()), - _ => throw new ArgumentOutOfRangeException(nameof(portIndex)), + _ => throw new ArgumentOutOfRangeException(nameof(portIndex)), }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sm/Types/SmPortIndex.cs b/src/Ryujinx.Horizon/Sm/Types/SmPortIndex.cs index 5325558b..a2977856 100644 --- a/src/Ryujinx.Horizon/Sm/Types/SmPortIndex.cs +++ b/src/Ryujinx.Horizon/Sm/Types/SmPortIndex.cs @@ -3,6 +3,6 @@ enum SmPortIndex { User, - Manager + Manager, } -} \ No newline at end of file +}