From 326749498bed4360e5a4b11fc67d5ec7cb9a3076 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 16 Jul 2023 19:31:14 +0200 Subject: [PATCH] [Ryujinx.HLE] Address dotnet-format issues (#5380) * dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA2208 warnings * Address or silence dotnet format CA1806 and a few CA1854 warnings * Address dotnet format CA2211 warnings * Address dotnet format CA1822 warnings * Address or silence dotnet format CA1069 warnings * Make dotnet format succeed in style mode * Address or silence dotnet format CA2211 warnings * Address review comments * Address dotnet format CA2208 warnings properly * Make ProcessResult readonly * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Add previously silenced warnings back I have no clue how these disappeared * Revert formatting changes for while and for-loops * Format if-blocks correctly * Run dotnet format style after rebase * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Fix a few disabled warnings * Fix naming rule violation, Convert shader properties to auto-property and convert values to const * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Fix and silence a few dotnet-format warnings again * Run dotnet format after rebase * Use using declaration instead of block syntax * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Fix naming rule violations * Fix typo * Add trailing commas, use targeted new and use array initializer * Fix build issues * Fix remaining build issues * Remove SuppressMessage for CA1069 where possible * Address dotnet format issues * Address formatting issues Co-authored-by: Ac_K * Add GetHashCode implementation for RenderingSurfaceInfo * Explicitly silence CA1822 for every affected method in Syscall * Address formatting issues in Demangler.cs * Address review feedback Co-authored-by: Ac_K * Revert marking service methods as static * Next dotnet format pass * Address review feedback --------- Co-authored-by: Ac_K --- src/Ryujinx.Ava/Common/ApplicationHelper.cs | 2 +- src/Ryujinx.Ava/UI/Models/SaveModel.cs | 3 +- .../UserFirmwareAvatarSelectorViewModel.cs | 2 +- src/Ryujinx.HLE/AssemblyInfo.cs | 2 +- .../GuestBrokeExecutionException.cs | 2 +- .../Exceptions/InternalServiceException.cs | 4 +- .../InvalidFirmwarePackageException.cs | 2 +- .../Exceptions/InvalidNpdmException.cs | 2 +- .../InvalidStructLayoutException.cs | 6 +- .../InvalidSystemResourceException.cs | 2 +- .../ServiceNotImplementedException.cs | 16 +- .../Exceptions/TamperCompilationException.cs | 2 +- .../Exceptions/TamperExecutionException.cs | 2 +- .../UndefinedInstructionException.cs | 2 +- src/Ryujinx.HLE/FileSystem/ContentManager.cs | 407 ++++++++---------- src/Ryujinx.HLE/FileSystem/ContentPath.cs | 57 ++- .../FileSystem/EncryptedFileSystemCreator.cs | 2 +- src/Ryujinx.HLE/FileSystem/LocationEntry.cs | 10 +- src/Ryujinx.HLE/FileSystem/SystemVersion.cs | 44 +- .../FileSystem/VirtualFileSystem.cs | 125 ++++-- src/Ryujinx.HLE/HLEConfiguration.cs | 98 ++--- src/Ryujinx.HLE/HOS/Applets/AppletManager.cs | 4 +- .../HOS/Applets/Browser/BootDisplayKind.cs | 2 +- .../HOS/Applets/Browser/BrowserApplet.cs | 55 ++- .../HOS/Applets/Browser/BrowserArgument.cs | 16 +- .../HOS/Applets/Browser/BrowserOutput.cs | 12 +- .../HOS/Applets/Browser/BrowserOutputType.cs | 16 +- .../HOS/Applets/Browser/DocumentKind.cs | 2 +- .../HOS/Applets/Browser/LeftStickMode.cs | 2 +- .../HOS/Applets/Browser/ShimKind.cs | 2 +- .../HOS/Applets/Browser/WebArgHeader.cs | 4 +- .../HOS/Applets/Browser/WebArgTLV.cs | 2 +- .../HOS/Applets/Browser/WebArgTLVType.cs | 110 ++--- .../Applets/Browser/WebCommonReturnValue.cs | 4 +- .../HOS/Applets/Browser/WebExitReason.cs | 2 +- .../HOS/Applets/CommonArguments.cs | 10 +- .../Applets/Controller/ControllerApplet.cs | 42 +- .../Controller/ControllerAppletUiArgs.cs | 2 +- .../Controller/ControllerSupportArgHeader.cs | 4 +- .../Controller/ControllerSupportArgPrivate.cs | 4 +- .../Controller/ControllerSupportArgV7.cs | 4 +- .../Controller/ControllerSupportArgVPre7.cs | 4 +- .../Controller/ControllerSupportMode.cs | 4 +- .../Controller/ControllerSupportResultInfo.cs | 4 +- .../HOS/Applets/Error/ApplicationErrorArg.cs | 6 +- .../HOS/Applets/Error/ErrorApplet.cs | 63 +-- .../HOS/Applets/Error/ErrorCommonArg.cs | 2 +- .../HOS/Applets/Error/ErrorCommonHeader.cs | 16 +- .../HOS/Applets/Error/ErrorType.cs | 4 +- .../PlayerSelect/PlayerSelectApplet.cs | 19 +- .../PlayerSelect/PlayerSelectResult.cs | 2 +- .../CJKCharacterValidation.cs | 2 +- .../SoftwareKeyboard/InitialCursorPosition.cs | 2 +- .../SoftwareKeyboard/InlineKeyboardRequest.cs | 2 +- .../InlineKeyboardResponse.cs | 2 +- .../SoftwareKeyboard/InlineKeyboardState.cs | 2 +- .../SoftwareKeyboard/InlineResponses.cs | 219 +++++----- .../Applets/SoftwareKeyboard/InputFormMode.cs | 2 +- .../SoftwareKeyboard/InvalidButtonFlags.cs | 6 +- .../SoftwareKeyboard/InvalidCharFlags.cs | 2 +- .../SoftwareKeyboard/KeyboardCalcFlags.cs | 26 +- .../KeyboardMiniaturizationMode.cs | 6 +- .../Applets/SoftwareKeyboard/KeyboardMode.cs | 12 +- .../SoftwareKeyboard/KeyboardResult.cs | 2 +- .../Applets/SoftwareKeyboard/PasswordMode.cs | 2 +- .../SoftwareKeyboardAppear.cs | 63 +-- .../SoftwareKeyboardAppearEx.cs | 4 +- .../SoftwareKeyboardApplet.cs | 389 +++++++++-------- .../SoftwareKeyboard/SoftwareKeyboardCalc.cs | 79 ++-- .../SoftwareKeyboardConfig.cs | 6 +- .../SoftwareKeyboardRenderer.cs | 32 +- .../SoftwareKeyboardRendererBase.cs | 210 +++++---- .../SoftwareKeyboard/SoftwareKeyboardState.cs | 4 +- .../SoftwareKeyboardUiArgs.cs | 2 +- .../SoftwareKeyboardUiState.cs | 18 +- .../Applets/SoftwareKeyboard/TimedAction.cs | 4 +- .../HOS/ArmProcessContextFactory.cs | 2 +- .../Ast/ArraySubscriptingExpression.cs | 10 +- .../Diagnostics/Demangler/Ast/ArrayType.cs | 16 +- .../HOS/Diagnostics/Demangler/Ast/BaseNode.cs | 8 +- .../Demangler/Ast/BinaryExpression.cs | 12 +- .../Demangler/Ast/BracedExpression.cs | 10 +- .../Demangler/Ast/BracedRangeExpression.cs | 10 +- .../Demangler/Ast/CallExpression.cs | 4 +- .../Demangler/Ast/CastExpression.cs | 10 +- .../Demangler/Ast/ConditionalExpression.cs | 12 +- .../Demangler/Ast/ConversionExpression.cs | 8 +- .../Demangler/Ast/ConversionOperatorType.cs | 2 +- .../Demangler/Ast/CtorDtorNameType.cs | 4 +- .../Demangler/Ast/CtorVtableSpecialName.cs | 8 +- .../Demangler/Ast/DeleteExpression.cs | 8 +- .../HOS/Diagnostics/Demangler/Ast/DtorName.cs | 2 +- .../Demangler/Ast/DynamicExceptionSpec.cs | 2 +- .../Demangler/Ast/ElaboratedType.cs | 4 +- .../Demangler/Ast/EnclosedExpression.cs | 12 +- .../Demangler/Ast/EncodedFunction.cs | 55 +-- .../Demangler/Ast/FoldExpression.cs | 16 +- .../Demangler/Ast/ForwardTemplateReference.cs | 4 +- .../Demangler/Ast/FunctionParameter.cs | 4 +- .../Diagnostics/Demangler/Ast/FunctionType.cs | 20 +- .../Demangler/Ast/InitListExpression.cs | 13 +- .../Demangler/Ast/IntegerCastExpression.cs | 4 +- .../Demangler/Ast/IntegerLiteral.cs | 8 +- .../Demangler/Ast/LiteralOperator.cs | 2 +- .../Diagnostics/Demangler/Ast/LocalName.cs | 8 +- .../Demangler/Ast/MemberExpression.cs | 12 +- .../HOS/Diagnostics/Demangler/Ast/NameType.cs | 4 +- .../Ast/NameTypeWithTemplateArguments.cs | 10 +- .../Diagnostics/Demangler/Ast/NestedName.cs | 4 +- .../Demangler/Ast/NewExpression.cs | 20 +- .../Diagnostics/Demangler/Ast/NodeArray.cs | 2 +- .../Demangler/Ast/PackedTemplateParameter.cs | 2 +- .../Ast/PackedTemplateParameterExpansion.cs | 10 +- .../Diagnostics/Demangler/Ast/ParentNode.cs | 2 +- .../Diagnostics/Demangler/Ast/PointerType.cs | 4 +- .../Demangler/Ast/PostfixExpression.cs | 4 +- .../Demangler/Ast/PostfixQualifiedType.cs | 4 +- .../Demangler/Ast/PrefixExpression.cs | 4 +- .../Demangler/Ast/QualifiedName.cs | 8 +- .../Diagnostics/Demangler/Ast/Qualifier.cs | 21 +- .../Demangler/Ast/ReferenceType.cs | 8 +- .../Diagnostics/Demangler/Ast/SpecialName.cs | 4 +- .../Demangler/Ast/SpecialSubstitution.cs | 29 +- .../Demangler/Ast/TemplateArguments.cs | 6 +- .../Demangler/Ast/ThrowExpression.cs | 4 +- .../HOS/Diagnostics/Demangler/Demangler.cs | 131 +++--- src/Ryujinx.HLE/HOS/HomebrewRomFsStream.cs | 6 +- src/Ryujinx.HLE/HOS/Horizon.cs | 70 ++- src/Ryujinx.HLE/HOS/IdDictionary.cs | 10 +- src/Ryujinx.HLE/HOS/Ipc/IpcBuffDesc.cs | 12 +- src/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs | 2 +- src/Ryujinx.HLE/HOS/Ipc/IpcMagic.cs | 2 +- src/Ryujinx.HLE/HOS/Ipc/IpcMessage.cs | 156 ++++--- src/Ryujinx.HLE/HOS/Ipc/IpcMessageType.cs | 12 +- src/Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs | 18 +- .../HOS/Ipc/IpcRecvListBuffDesc.cs | 6 +- .../HOS/Ipc/ServiceProcessRequest.cs | 2 +- .../Kernel/Common/IKFutureSchedulerObject.cs | 2 +- .../HOS/Kernel/Common/KAutoObject.cs | 2 +- .../HOS/Kernel/Common/KResourceLimit.cs | 8 +- .../Kernel/Common/KSynchronizationObject.cs | 2 +- .../HOS/Kernel/Common/KSystemControl.cs | 8 +- .../HOS/Kernel/Common/KTimeManager.cs | 8 +- .../HOS/Kernel/Common/KernelInit.cs | 26 +- .../HOS/Kernel/Common/KernelTransfer.cs | 4 +- .../HOS/Kernel/Common/LimitableResource.cs | 12 +- .../HOS/Kernel/Common/MemoryArrange.cs | 4 +- .../Common/{MemroySize.cs => MemorySize.cs} | 4 +- .../HOS/Kernel/Common/MersenneTwister.cs | 16 +- .../HOS/Kernel/Ipc/ChannelState.cs | 4 +- .../HOS/Kernel/Ipc/KBufferDescriptor.cs | 14 +- .../HOS/Kernel/Ipc/KBufferDescriptorTable.cs | 40 +- src/Ryujinx.HLE/HOS/Kernel/Ipc/KClientPort.cs | 10 +- .../HOS/Kernel/Ipc/KClientSession.cs | 12 +- .../HOS/Kernel/Ipc/KLightClientSession.cs | 4 +- .../HOS/Kernel/Ipc/KLightServerSession.cs | 4 +- .../HOS/Kernel/Ipc/KLightSession.cs | 2 +- src/Ryujinx.HLE/HOS/Kernel/Ipc/KPort.cs | 8 +- src/Ryujinx.HLE/HOS/Kernel/Ipc/KServerPort.cs | 6 +- .../HOS/Kernel/Ipc/KServerSession.cs | 147 +++---- src/Ryujinx.HLE/HOS/Kernel/Ipc/KSession.cs | 4 +- .../HOS/Kernel/Ipc/KSessionRequest.cs | 12 +- src/Ryujinx.HLE/HOS/Kernel/KernelConstants.cs | 2 +- src/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs | 16 +- .../HOS/Kernel/Memory/AddressSpaceType.cs | 8 +- .../HOS/Kernel/Memory/DramMemoryMap.cs | 4 +- .../HOS/Kernel/Memory/KCodeMemory.cs | 2 +- .../HOS/Kernel/Memory/KMemoryBlock.cs | 2 +- .../Kernel/Memory/KMemoryBlockSlabManager.cs | 4 +- .../HOS/Kernel/Memory/KMemoryInfo.cs | 38 +- .../HOS/Kernel/Memory/KMemoryRegionManager.cs | 2 +- .../HOS/Kernel/Memory/KPageBitmap.cs | 4 +- .../HOS/Kernel/Memory/KPageHeap.cs | 26 +- .../HOS/Kernel/Memory/KPageList.cs | 10 +- .../HOS/Kernel/Memory/KPageNode.cs | 4 +- .../HOS/Kernel/Memory/KPageTable.cs | 10 +- .../HOS/Kernel/Memory/KPageTableBase.cs | 90 ++-- .../HOS/Kernel/Memory/KScopedPageList.cs | 2 +- .../HOS/Kernel/Memory/KSharedMemory.cs | 2 +- .../HOS/Kernel/Memory/KSlabHeap.cs | 4 +- .../HOS/Kernel/Memory/KTransferMemory.cs | 2 +- .../HOS/Kernel/Memory/MemoryAttribute.cs | 12 +- .../HOS/Kernel/Memory/MemoryPermission.cs | 16 +- .../HOS/Kernel/Memory/MemoryRegion.cs | 8 +- .../HOS/Kernel/Memory/MemoryState.cs | 78 ++-- .../Kernel/Process/CapabilityExtensions.cs | 2 +- .../HOS/Kernel/Process/CapabilityType.cs | 22 +- .../HOS/Kernel/Process/HleProcessDebugger.cs | 46 +- .../HOS/Kernel/Process/KContextIdManager.cs | 10 +- .../HOS/Kernel/Process/KHandleEntry.cs | 6 +- .../HOS/Kernel/Process/KHandleTable.cs | 27 +- .../HOS/Kernel/Process/KProcess.cs | 41 +- .../Kernel/Process/KProcessCapabilities.cs | 260 +++++------ .../HOS/Kernel/Process/KTlsPageInfo.cs | 2 +- .../HOS/Kernel/Process/KTlsPageManager.cs | 8 +- .../Kernel/Process/ProcessCreationFlags.cs | 4 +- .../HOS/Kernel/Process/ProcessCreationInfo.cs | 2 +- .../Kernel/Process/ProcessExecutionContext.cs | 5 +- .../HOS/Kernel/Process/ProcessState.cs | 16 +- .../HOS/Kernel/Process/ProcessTamperInfo.cs | 12 +- .../SupervisorCall/CodeMemoryOperation.cs | 4 +- .../HOS/Kernel/SupervisorCall/InfoType.cs | 2 +- .../HOS/Kernel/SupervisorCall/MemoryInfo.cs | 8 +- .../HOS/Kernel/SupervisorCall/Syscall.cs | 223 ++++++++-- .../Kernel/SupervisorCall/SyscallHandler.cs | 2 +- .../Kernel/SupervisorCall/ThreadContext.cs | 6 +- .../HOS/Kernel/Threading/ArbitrationType.cs | 6 +- .../HOS/Kernel/Threading/KAddressArbiter.cs | 42 +- .../Kernel/Threading/KConditionVariable.cs | 2 +- .../HOS/Kernel/Threading/KCriticalSection.cs | 2 +- .../HOS/Kernel/Threading/KEvent.cs | 4 +- .../HOS/Kernel/Threading/KPriorityQueue.cs | 4 +- .../HOS/Kernel/Threading/KReadableEvent.cs | 7 +- .../HOS/Kernel/Threading/KScheduler.cs | 24 +- .../HOS/Kernel/Threading/KSynchronization.cs | 10 +- .../HOS/Kernel/Threading/KThread.cs | 8 +- .../HOS/Kernel/Threading/KWritableEvent.cs | 2 +- .../HOS/Kernel/Threading/SignalType.cs | 4 +- .../HOS/Kernel/Threading/ThreadSchedState.cs | 22 +- .../HOS/Kernel/Threading/ThreadType.cs | 4 +- src/Ryujinx.HLE/HOS/LibHacHorizonManager.cs | 27 +- src/Ryujinx.HLE/HOS/ModLoader.cs | 38 +- src/Ryujinx.HLE/HOS/ResultCode.cs | 6 +- src/Ryujinx.HLE/HOS/ServiceCtx.cs | 46 +- .../Services/Account/Acc/AccountManager.cs | 8 +- .../Account/Acc/AccountSaveDataManager.cs | 32 +- .../AccountService/IManagerForApplication.cs | 4 +- .../IManagerForSystemService.cs | 4 +- .../Account/Acc/AccountService/IProfile.cs | 4 +- .../Acc/AccountService/IProfileEditor.cs | 4 +- .../Acc/AccountService/ManagerServer.cs | 28 +- .../Acc/AccountService/ProfileServer.cs | 16 +- .../Account/Acc/ApplicationServiceServer.cs | 10 +- .../Acc/AsyncContext/AsyncExecution.cs | 14 +- .../Acc/IAccountServiceForAdministrator.cs | 4 +- .../Acc/IAccountServiceForApplication.cs | 4 +- .../Acc/IAccountServiceForSystemService.cs | 4 +- .../HOS/Services/Account/Acc/IAsyncContext.cs | 8 +- .../IAsyncNetworkServiceLicenseKindContext.cs | 2 +- .../Account/Acc/IBaasAccessTokenAccessor.cs | 2 +- .../Acc/ProfilesJsonSerializerContext.cs | 2 +- .../Account/Acc/Types/AccountServiceFlag.cs | 10 +- .../Account/Acc/Types/AccountState.cs | 4 +- .../Acc/Types/NetworkServiceLicenseKind.cs | 2 +- .../Account/Acc/Types/ProfilesJson.cs | 2 +- .../HOS/Services/Account/Acc/Types/UserId.cs | 10 +- .../Services/Account/Acc/Types/UserProfile.cs | 10 +- .../Account/Acc/Types/UserProfileJson.cs | 2 +- .../HOS/Services/Account/Dauth/IService.cs | 2 +- .../HOS/Services/Account/ResultCode.cs | 26 +- .../ILibraryAppletProxy.cs | 2 +- .../ISystemAppletProxy.cs | 2 +- .../ILibraryAppletAccessor.cs | 24 +- .../LibraryAppletProxy/AppletStandalone.cs | 6 +- .../ILibraryAppletSelfAccessor.cs | 18 +- .../IProcessWindingController.cs | 6 +- .../IAppletCommonFunctions.cs | 2 +- .../SystemAppletProxy/IApplicationCreator.cs | 2 +- .../SystemAppletProxy/IAudioController.cs | 12 +- .../SystemAppletProxy/ICommonStateGetter.cs | 22 +- .../SystemAppletProxy/IDebugFunctions.cs | 2 +- .../SystemAppletProxy/IDisplayController.cs | 10 +- .../IGlobalStateController.cs | 2 +- .../SystemAppletProxy/IHomeMenuFunctions.cs | 6 +- .../ILibraryAppletCreator.cs | 16 +- .../SystemAppletProxy/ISelfController.cs | 24 +- .../SystemAppletProxy/IWindowController.cs | 2 +- .../Types/AlbumReportOption.cs | 4 +- .../SystemAppletProxy/Types/AppletMessage.cs | 60 +-- .../SystemAppletProxy/Types/FocusState.cs | 6 +- .../SystemAppletProxy/Types/OperationMode.cs | 4 +- .../Types/WirelessPriorityMode.cs | 4 +- .../HOS/Services/Am/AppletAE/AppletFifo.cs | 2 +- .../HOS/Services/Am/AppletAE/AppletSession.cs | 6 +- .../IAllSystemAppletProxiesService.cs | 2 +- .../HOS/Services/Am/AppletAE/IStorage.cs | 8 +- .../Services/Am/AppletAE/IStorageAccessor.cs | 4 +- .../Am/AppletAE/Storage/StorageHelper.cs | 16 +- .../Services/Am/AppletAE/Types/AppletId.cs | 40 +- .../Am/AppletAE/Types/AppletIdentityInfo.cs | 6 +- .../Types/AppletProcessLaunchReason.cs | 6 +- .../Am/AppletAE/Types/LibraryAppletInfo.cs | 4 +- .../Am/AppletAE/Types/LibraryAppletMode.cs | 4 +- .../ApplicationProxy/IApplicationFunctions.cs | 72 ++-- .../Types/LaunchParameterKind.cs | 2 +- .../Types/ProgramSpecifyKind.cs | 2 +- .../IApplicationProxy.cs | 2 +- .../Am/AppletOE/IApplicationProxyService.cs | 2 +- .../Services/Am/Idle/IPolicyManagerSystem.cs | 2 +- .../Services/Am/Omm/IOperationModeManager.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Am/ResultCode.cs | 36 +- .../Services/Am/Spsm/IPowerStateInterface.cs | 2 +- .../HOS/Services/Am/Tcap/IManager.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Apm/IManager.cs | 2 +- .../HOS/Services/Apm/IManagerPrivileged.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Apm/ISession.cs | 4 +- .../HOS/Services/Apm/ISystemManager.cs | 2 +- .../HOS/Services/Apm/ManagerServer.cs | 2 +- .../HOS/Services/Apm/PerformanceState.cs | 10 +- .../HOS/Services/Apm/ResultCode.cs | 6 +- .../HOS/Services/Apm/SessionServer.cs | 4 +- .../HOS/Services/Apm/SystemManagerServer.cs | 2 +- .../HOS/Services/Apm/Types/CpuBoostMode.cs | 8 +- .../Apm/Types/PerformanceConfiguration.cs | 22 +- .../HOS/Services/Apm/Types/PerformanceMode.cs | 4 +- .../Services/Arp/ApplicationLaunchProperty.cs | 26 +- src/Ryujinx.HLE/HOS/Services/Arp/IReader.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Arp/IWriter.cs | 2 +- .../HOS/Services/Arp/LibHacIReader.cs | 7 +- .../HOS/Services/Audio/AudioIn/AudioIn.cs | 12 +- .../Services/Audio/AudioIn/AudioInServer.cs | 22 +- .../HOS/Services/Audio/AudioInManager.cs | 2 +- .../Services/Audio/AudioInManagerServer.cs | 10 +- .../HOS/Services/Audio/AudioOut/AudioOut.cs | 10 +- .../Services/Audio/AudioOut/AudioOutServer.cs | 22 +- .../HOS/Services/Audio/AudioOutManager.cs | 2 +- .../Services/Audio/AudioOutManagerServer.cs | 6 +- .../Audio/AudioRenderer/AudioDevice.cs | 16 +- .../Audio/AudioRenderer/AudioDeviceServer.cs | 2 +- .../Audio/AudioRenderer/AudioRenderer.cs | 6 +- .../AudioRenderer/AudioRendererServer.cs | 42 +- .../Audio/AudioRenderer/IAudioDevice.cs | 2 +- .../Services/Audio/AudioRendererManager.cs | 4 +- .../Audio/AudioRendererManagerServer.cs | 2 +- .../HardwareOpusDecoderManager/Decoder.cs | 2 +- .../DecoderCommon.cs | 2 +- .../HardwareOpusDecoderManager/IDecoder.cs | 2 +- .../IHardwareOpusDecoder.cs | 8 +- .../MultiSampleDecoder.cs | 2 +- .../HOS/Services/Audio/IAudioController.cs | 2 +- .../HOS/Services/Audio/IAudioInManager.cs | 2 +- .../Audio/IAudioInManagerForApplet.cs | 2 +- .../Audio/IAudioInManagerForDebugger.cs | 2 +- .../Audio/IAudioOutManagerForApplet.cs | 2 +- .../Audio/IAudioOutManagerForDebugger.cs | 2 +- .../Audio/IAudioRendererManagerForApplet.cs | 2 +- .../Audio/IAudioRendererManagerForDebugger.cs | 2 +- .../HOS/Services/Audio/IAudioSnoopManager.cs | 2 +- .../Audio/IFinalOutputRecorderManager.cs | 2 +- .../IFinalOutputRecorderManagerForApplet.cs | 2 +- .../IFinalOutputRecorderManagerForDebugger.cs | 2 +- .../Audio/IHardwareOpusDecoderManager.cs | 10 +- .../HOS/Services/Audio/ResultCode.cs | 20 +- .../Services/Audio/Types/OpusPacketHeader.cs | 2 +- .../HOS/Services/Bgtc/IStateControlService.cs | 2 +- .../HOS/Services/Bgtc/ITaskService.cs | 2 +- .../BluetoothDriver/BluetoothEventManager.cs | 14 +- .../Services/Bluetooth/IBluetoothDriver.cs | 6 +- .../HOS/Services/Bluetooth/IBluetoothUser.cs | 2 +- .../BluetoothManager/BtmUser/IBtmUserCore.cs | 10 +- .../HOS/Services/BluetoothManager/IBtm.cs | 2 +- .../Services/BluetoothManager/IBtmDebug.cs | 2 +- .../Services/BluetoothManager/IBtmSystem.cs | 2 +- .../HOS/Services/BluetoothManager/IBtmUser.cs | 2 +- .../Services/BluetoothManager/ResultCode.cs | 6 +- .../HOS/Services/Caps/CaptureManager.cs | 40 +- .../Services/Caps/IAlbumAccessorService.cs | 2 +- .../Services/Caps/IAlbumApplicationService.cs | 12 +- .../HOS/Services/Caps/IAlbumControlService.cs | 2 +- .../Caps/IScreenShotApplicationService.cs | 37 +- .../Caps/IScreenShotControlService.cs | 2 +- .../HOS/Services/Caps/IScreenshotService.cs | 2 +- .../HOS/Services/Caps/ResultCode.cs | 18 +- .../Services/Caps/Types/AlbumFileDateTime.cs | 14 +- .../Caps/Types/AlbumImageOrientation.cs | 4 +- .../HOS/Services/Caps/Types/AlbumStorage.cs | 4 +- .../Caps/Types/ApplicationAlbumEntry.cs | 14 +- .../HOS/Services/Caps/Types/ContentType.cs | 4 +- .../Caps/Types/ScreenShotAttribute.cs | 10 +- .../HOS/Services/Cec/ICecManager.cs | 2 +- .../HOS/Services/CommandCmifAttribute.cs | 2 +- src/Ryujinx.HLE/HOS/Services/DummyService.cs | 2 +- .../HOS/Services/Ectx/IReaderForSystem.cs | 2 +- .../Services/Ectx/IWriterForApplication.cs | 2 +- .../HOS/Services/Ectx/IWriterForSystem.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Erpt/IContext.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Erpt/ISession.cs | 2 +- .../HOS/Services/Es/IETicketService.cs | 2 +- .../HOS/Services/Eupld/IControl.cs | 2 +- .../HOS/Services/Eupld/IRequest.cs | 2 +- .../HOS/Services/Fatal/IPrivateService.cs | 2 +- .../HOS/Services/Fatal/IService.cs | 16 +- .../HOS/Services/Fatal/Types/CpuContext32.cs | 2 +- .../HOS/Services/Fatal/Types/CpuContext64.cs | 4 +- .../HOS/Services/Fatal/Types/FatalPolicy.cs | 4 +- .../HOS/Services/Friend/IServiceCreator.cs | 4 +- .../HOS/Services/Friend/ResultCode.cs | 8 +- .../FriendService/Types/Friend.cs | 8 +- .../FriendService/Types/FriendFilter.cs | 2 +- .../FriendService/Types/PresenceStatus.cs | 4 +- .../Types/PresenceStatusFilter.cs | 4 +- .../FriendService/Types/UserPresence.cs | 8 +- .../IDaemonSuspendSessionService.cs | 8 +- .../Friend/ServiceCreator/IFriendService.cs | 54 +-- .../ServiceCreator/INotificationService.cs | 24 +- .../NotificationEventHandler.cs | 27 +- .../Types/NotificationEventType.cs | 6 +- .../Types/NotificationInfo.cs | 2 +- .../Types/FriendServicePermissionLevel.cs | 16 +- .../Types/PlayHistoryRegistrationKey.cs | 8 +- .../FileSystemProxy/FileSystemProxyHelper.cs | 10 +- .../Services/Fs/FileSystemProxy/IDirectory.cs | 10 +- .../HOS/Services/Fs/FileSystemProxy/IFile.cs | 16 +- .../Fs/FileSystemProxy/IFileSystem.cs | 6 +- .../Services/Fs/FileSystemProxy/IStorage.cs | 13 +- .../HOS/Services/Fs/IFileSystemProxy.cs | 238 +++++++--- .../Services/Fs/IFileSystemProxyForLoader.cs | 2 +- .../HOS/Services/Fs/IProgramRegistry.cs | 2 +- .../HOS/Services/Fs/ISaveDataInfoReader.cs | 10 +- src/Ryujinx.HLE/HOS/Services/Fs/ResultCode.cs | 12 +- .../HOS/Services/Fs/Types/FileSystemType.cs | 14 +- .../HOS/Services/Grc/IGrcService.cs | 2 +- .../HOS/Services/Grc/IRemoteVideoTransfer.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Hid/Hid.cs | 20 +- .../HOS/Services/Hid/HidDevices/BaseDevice.cs | 2 +- .../Services/Hid/HidDevices/DebugPadDevice.cs | 4 +- .../Services/Hid/HidDevices/KeyboardDevice.cs | 4 +- .../Services/Hid/HidDevices/MouseDevice.cs | 6 +- .../Services/Hid/HidDevices/NpadDevices.cs | 75 ++-- .../Services/Hid/HidDevices/TouchDevice.cs | 8 +- .../Hid/HidDevices/Types/ControllerConfig.cs | 4 +- .../Hid/HidDevices/Types/GamepadInput.cs | 6 +- .../Hid/HidDevices/Types/JoystickPosition.cs | 2 +- .../Hid/HidDevices/Types/KeyboardInput.cs | 2 +- .../Hid/HidDevices/Types/SixAxisInput.cs | 10 +- .../Hid/HidDevices/Types/TouchPoint.cs | 2 +- .../HOS/Services/Hid/HidServer/HidUtils.cs | 10 +- .../HidServer/IActiveVibrationDeviceList.cs | 4 +- .../Services/Hid/HidServer/IAppletResource.cs | 6 +- .../Types/Npad/NpadHandheldActivationMode.cs | 4 +- .../HidServer/Types/Npad/NpadJoyDeviceType.cs | 4 +- .../Types/SixAxis/AccelerometerParameters.cs | 2 +- .../Types/SixAxis/GyroscopeZeroDriftMode.cs | 4 +- .../Types/SixAxis/SensorFusionParameters.cs | 2 +- .../Types/Vibration/VibrationDeviceHandle.cs | 2 +- .../Vibration/VibrationDevicePosition.cs | 4 +- .../Types/Vibration/VibrationDeviceType.cs | 4 +- .../Types/Vibration/VibrationDeviceValue.cs | 4 +- .../Types/Vibration/VibrationValue.cs | 16 +- .../HOS/Services/Hid/IHidDebugServer.cs | 2 +- .../HOS/Services/Hid/IHidServer.cs | 243 ++++++----- .../HOS/Services/Hid/IHidSystemServer.cs | 4 +- .../HOS/Services/Hid/IHidbusServer.cs | 10 +- .../HOS/Services/Hid/ISystemServer.cs | 2 +- .../HOS/Services/Hid/Irs/IIrSensorServer.cs | 46 +- .../Services/Hid/Irs/IIrSensorSystemServer.cs | 2 +- .../HOS/Services/Hid/Irs/ResultCode.cs | 8 +- .../Irs/Types/ImageTransferProcessorState.cs | 6 +- .../Services/Hid/Irs/Types/IrCameraHandle.cs | 6 +- .../Types/PackedClusteringProcessorConfig.cs | 24 +- .../PackedImageTransferProcessorConfig.cs | 20 +- .../Irs/Types/PackedMomentProcessorConfig.cs | 20 +- .../Types/PackedTeraPluginProcessorConfig.cs | 2 +- .../HOS/Services/Hid/ResultCode.cs | 10 +- .../Services/Hid/Types/AppletFooterUiType.cs | 4 +- .../HOS/Services/Hid/Types/HidVector.cs | 2 +- .../HOS/Services/Hid/Types/Npad/BusHandle.cs | 2 +- .../HOS/Services/Hid/Types/Npad/BusType.cs | 4 +- .../Services/Hid/Types/Npad/ControllerKeys.cs | 64 +-- .../Services/Hid/Types/Npad/ControllerType.cs | 18 +- .../HOS/Services/Hid/Types/Npad/NpadColor.cs | 64 +-- .../HOS/Services/Hid/Types/Npad/NpadIdType.cs | 20 +- .../Services/Hid/Types/Npad/NpadStyleIndex.cs | 12 +- .../Services/Hid/Types/Npad/PlayerIndex.cs | 22 +- .../HOS/Services/Hid/Types/NpadJoyHoldType.cs | 2 +- .../SharedMemory/Common/AtomicStorage.cs | 2 +- .../SharedMemory/Common/ISampledDataStruct.cs | 8 +- .../Hid/Types/SharedMemory/Common/RingLifo.cs | 16 +- .../DebugPad/DebugPadAttribute.cs | 4 +- .../SharedMemory/DebugPad/DebugPadButton.cs | 4 +- .../SharedMemory/Keyboard/KeyboardKey.cs | 2 +- .../SharedMemory/Keyboard/KeyboardKeyShift.cs | 4 +- .../SharedMemory/Keyboard/KeyboardModifier.cs | 2 +- .../SharedMemory/Mouse/MouseAttribute.cs | 4 +- .../Types/SharedMemory/Mouse/MouseButton.cs | 4 +- .../Hid/Types/SharedMemory/Npad/DeviceType.cs | 2 +- .../Types/SharedMemory/Npad/NpadAttribute.cs | 4 +- .../SharedMemory/Npad/NpadBatteryLevel.cs | 2 +- .../Hid/Types/SharedMemory/Npad/NpadButton.cs | 4 +- .../SharedMemory/Npad/NpadColorAttribute.cs | 2 +- .../SharedMemory/Npad/NpadCommonState.cs | 2 +- .../Npad/NpadFullKeyColorState.cs | 2 +- .../SharedMemory/Npad/NpadGcTriggerState.cs | 4 +- .../SharedMemory/Npad/NpadInternalState.cs | 12 +- .../Npad/NpadJoyAssignmentMode.cs | 4 +- .../SharedMemory/Npad/NpadJoyColorState.cs | 2 +- .../Types/SharedMemory/Npad/NpadLuciaType.cs | 4 +- .../Hid/Types/SharedMemory/Npad/NpadState.cs | 2 +- .../Types/SharedMemory/Npad/NpadStyleTag.cs | 2 +- .../Npad/NpadSystemButtonProperties.cs | 4 +- .../SharedMemory/Npad/NpadSystemProperties.cs | 2 +- .../Npad/SixAxisSensorAttribute.cs | 4 +- .../SharedMemory/Npad/SixAxisSensorState.cs | 4 +- .../Hid/Types/SharedMemory/SharedMemory.cs | 2 +- .../TouchScreen/TouchAttribute.cs | 2 +- .../TouchScreen/TouchScreenState.cs | 2 +- .../SharedMemory/TouchScreen/TouchState.cs | 8 +- .../HOS/Services/Ins/IReceiverManager.cs | 2 +- .../HOS/Services/Ins/ISenderManager.cs | 2 +- src/Ryujinx.HLE/HOS/Services/IpcService.cs | 10 +- .../HOS/Services/Lbl/ILblController.cs | 2 +- .../HOS/Services/Lbl/LblControllerServer.cs | 2 +- .../Services/Ldn/IMonitorServiceCreator.cs | 2 +- .../HOS/Services/Ldn/ISystemServiceCreator.cs | 2 +- .../HOS/Services/Ldn/IUserServiceCreator.cs | 2 +- .../HOS/Services/Ldn/Lp2p/IServiceCreator.cs | 2 +- .../HOS/Services/Ldn/NetworkInterface.cs | 8 +- .../HOS/Services/Ldn/ResultCode.cs | 12 +- .../HOS/Services/Ldn/Types/NetworkState.cs | 4 +- .../IUserLocalCommunicationService.cs | 8 +- .../Services/Loader/IDebugMonitorInterface.cs | 2 +- .../Loader/IProcessManagerInterface.cs | 2 +- .../HOS/Services/Loader/IShellInterface.cs | 2 +- .../HOS/Services/Loader/ResultCode.cs | 69 +-- src/Ryujinx.HLE/HOS/Services/Mig/IService.cs | 2 +- .../HOS/Services/Mii/DatabaseImpl.cs | 7 +- .../Services/Mii/DatabaseSessionMetadata.cs | 6 +- src/Ryujinx.HLE/HOS/Services/Mii/Helper.cs | 2 + .../HOS/Services/Mii/IImageDatabaseService.cs | 4 +- .../HOS/Services/Mii/IStaticService.cs | 8 +- .../HOS/Services/Mii/MiiDatabaseManager.cs | 71 +-- .../HOS/Services/Mii/ResultCode.cs | 40 +- .../Mii/StaticService/DatabaseServiceImpl.cs | 6 +- .../Mii/StaticService/IDatabaseService.cs | 30 +- src/Ryujinx.HLE/HOS/Services/Mii/Types/Age.cs | 2 +- .../HOS/Services/Mii/Types/BeardType.cs | 4 +- .../HOS/Services/Mii/Types/CharInfo.cs | 373 +++++++++++----- .../HOS/Services/Mii/Types/CharInfoElement.cs | 2 +- .../HOS/Services/Mii/Types/CommonColor.cs | 2 +- .../HOS/Services/Mii/Types/CoreData.cs | 216 +++++----- .../HOS/Services/Mii/Types/CreateId.cs | 12 +- .../HOS/Services/Mii/Types/DefaultMii.cs | 6 +- .../HOS/Services/Mii/Types/EyeType.cs | 4 +- .../HOS/Services/Mii/Types/EyebrowType.cs | 4 +- .../HOS/Services/Mii/Types/FacelineColor.cs | 4 +- .../HOS/Services/Mii/Types/FacelineMake.cs | 4 +- .../HOS/Services/Mii/Types/FacelineType.cs | 4 +- .../HOS/Services/Mii/Types/FacelineWrinkle.cs | 4 +- .../HOS/Services/Mii/Types/FontRegion.cs | 2 +- .../HOS/Services/Mii/Types/Gender.cs | 4 +- .../HOS/Services/Mii/Types/GlassType.cs | 4 +- .../HOS/Services/Mii/Types/HairFlip.cs | 4 +- .../HOS/Services/Mii/Types/HairType.cs | 4 +- .../HOS/Services/Mii/Types/MoleType.cs | 4 +- .../HOS/Services/Mii/Types/MouthType.cs | 4 +- .../HOS/Services/Mii/Types/MustacheType.cs | 4 +- .../HOS/Services/Mii/Types/Nickname.cs | 6 +- .../Mii/Types/NintendoFigurineDatabase.cs | 26 +- .../HOS/Services/Mii/Types/NoseType.cs | 4 +- .../HOS/Services/Mii/Types/Race.cs | 2 +- .../Services/Mii/Types/RandomMiiConstants.cs | 50 ++- .../HOS/Services/Mii/Types/Source.cs | 2 +- .../HOS/Services/Mii/Types/SourceFlag.cs | 4 +- .../Services/Mii/Types/SpecialMiiKeyCode.cs | 2 +- .../HOS/Services/Mii/Types/StoreData.cs | 36 +- .../Services/Mii/Types/StoreDataElement.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Mm/IRequest.cs | 30 +- .../Mm/Types/MultiMediaOperationType.cs | 6 +- .../Services/Mm/Types/MultiMediaSession.cs | 10 +- .../Services/Mnpp/IServiceForApplication.cs | 4 +- .../HOS/Services/Mnpp/ResultCode.cs | 8 +- .../HOS/Services/Ncm/IContentManager.cs | 2 +- .../Ncm/Lr/ILocationResolverManager.cs | 2 +- .../ILocationResolver.cs | 17 +- .../HOS/Services/Ncm/Lr/ResultCode.cs | 20 +- .../HOS/Services/News/IServiceCreator.cs | 2 +- .../HOS/Services/Nfc/IAmManager.cs | 2 +- .../HOS/Services/Nfc/ISystemManager.cs | 2 +- .../HOS/Services/Nfc/IUserManager.cs | 2 +- .../HOS/Services/Nfc/Mifare/IUserManager.cs | 2 +- .../HOS/Services/Nfc/NfcManager/INfc.cs | 6 +- .../NfcManager/Types/NfcPermissionLevel.cs | 4 +- .../Services/Nfc/NfcManager/Types/State.cs | 4 +- .../Nfc/Nfp/AmiiboJsonSerializerContext.cs | 2 +- .../HOS/Services/Nfc/Nfp/IDebugManager.cs | 2 +- .../HOS/Services/Nfc/Nfp/ISystemManager.cs | 2 +- .../HOS/Services/Nfc/Nfp/IUserManager.cs | 2 +- .../HOS/Services/Nfc/Nfp/NfpManager/INfp.cs | 81 ++-- .../Nfp/NfpManager/Types/AmiiboConstants.cs | 4 +- .../Nfc/Nfp/NfpManager/Types/CommonInfo.cs | 14 +- .../Nfc/Nfp/NfpManager/Types/DeviceType.cs | 2 +- .../Nfc/Nfp/NfpManager/Types/ModelInfo.cs | 12 +- .../Nfc/Nfp/NfpManager/Types/MountTarget.cs | 4 +- .../Nfc/Nfp/NfpManager/Types/NfpDevice.cs | 6 +- .../Nfp/NfpManager/Types/NfpDeviceState.cs | 14 +- .../NfpManager/Types/NfpPermissionLevel.cs | 4 +- .../Nfc/Nfp/NfpManager/Types/RegisterInfo.cs | 12 +- .../Nfc/Nfp/NfpManager/Types/State.cs | 4 +- .../Nfc/Nfp/NfpManager/Types/TagInfo.cs | 8 +- .../Nfp/NfpManager/Types/VirtualAmiiboFile.cs | 14 +- .../HOS/Services/Nfc/Nfp/ResultCode.cs | 18 +- .../HOS/Services/Nfc/Nfp/VirtualAmiibo.cs | 57 ++- src/Ryujinx.HLE/HOS/Services/Ngct/IService.cs | 2 +- .../Ngct/IServiceWithManagementApi.cs | 2 +- .../HOS/Services/Ngct/NgctServer.cs | 12 +- .../HOS/Services/Nifm/IStaticService.cs | 2 +- .../HOS/Services/Nifm/ResultCode.cs | 10 +- .../GeneralService/GeneralServiceManager.cs | 4 +- .../Types/GeneralServiceDetail.cs | 4 +- .../Nifm/StaticService/IGeneralService.cs | 30 +- .../Services/Nifm/StaticService/IRequest.cs | 14 +- .../Nifm/StaticService/Types/DnsSetting.cs | 8 +- .../Types/InternetConnectionState.cs | 2 +- .../Types/InternetConnectionStatus.cs | 4 +- .../Types/InternetConnectionType.cs | 4 +- .../StaticService/Types/IpAddressSetting.cs | 10 +- .../Nifm/StaticService/Types/IpSettingData.cs | 8 +- .../StaticService/Types/NetworkProfileData.cs | 12 +- .../Nifm/StaticService/Types/ProxySetting.cs | 18 +- .../Types/WirelessSettingData.cs | 8 +- .../Services/Nim/INetworkInstallManager.cs | 2 +- .../Services/Nim/IShopServiceAccessServer.cs | 2 +- .../Nim/IShopServiceAccessServerInterface.cs | 2 +- .../Nim/IShopServiceAccessSystemInterface.cs | 2 +- .../HOS/Services/Nim/IShopServiceAccessor.cs | 2 +- .../HOS/Services/Nim/IShopServiceAsync.cs | 2 +- .../HOS/Services/Nim/IShopServiceManager.cs | 2 +- .../HOS/Services/Nim/Ntc/IStaticService.cs | 2 +- .../IEnsureNetworkClockAvailabilityService.cs | 6 +- .../HOS/Services/Nim/ResultCode.cs | 6 +- .../INotificationServicesForApplication.cs | 2 +- .../INotificationServicesForSystem.cs | 2 +- .../HOS/Services/Npns/INpnsSystem.cs | 2 +- .../HOS/Services/Npns/INpnsUser.cs | 2 +- .../Services/Ns/Aoc/IAddOnContentManager.cs | 28 +- .../Ns/Aoc/IContentsServiceManager.cs | 2 +- .../Services/Ns/Aoc/IPurchaseEventManager.cs | 8 +- .../HOS/Services/Ns/Aoc/ResultCode.cs | 6 +- .../Ns/IApplicationManagerInterface.cs | 7 +- .../HOS/Services/Ns/IDevelopInterface.cs | 2 +- ...ReadOnlyApplicationControlDataInterface.cs | 2 + .../Services/Ns/IServiceGetterInterface.cs | 2 +- .../HOS/Services/Ns/ISystemUpdateInterface.cs | 2 +- .../Ns/IVulnerabilityManagerInterface.cs | 2 +- .../HOS/Services/Nv/Host1xContext.cs | 4 +- .../HOS/Services/Nv/INvDrvDebugFSServices.cs | 2 +- .../HOS/Services/Nv/INvDrvServices.cs | 120 +++--- .../HOS/Services/Nv/INvGemControl.cs | 2 +- .../HOS/Services/Nv/INvGemCoreDump.cs | 2 +- .../Services/Nv/NvDrvServices/NvDeviceFile.cs | 4 +- .../NvHostAsGpu/NvHostAsGpuDeviceFile.cs | 7 +- .../NvHostAsGpu/Types/AddressSpaceContext.cs | 18 +- .../NvHostAsGpu/Types/AddressSpaceFlags.cs | 2 +- .../NvHostAsGpu/Types/AllocSpaceArguments.cs | 8 +- .../NvHostAsGpu/Types/FreeSpaceArguments.cs | 4 +- .../Types/InitializeExArguments.cs | 8 +- .../NvHostAsGpu/Types/MapBufferExArguments.cs | 12 +- .../NvHostAsGpu/Types/RemapArguments.cs | 8 +- .../NvHostAsGpu/Types/UnmapBufferArguments.cs | 2 +- .../NvHostChannel/ChannelInitialization.cs | 2 +- .../NvHostChannel/NvHostChannelDeviceFile.cs | 52 +-- .../NvHostChannel/NvHostGpuDeviceFile.cs | 37 +- .../Types/AllocGpfifoExArguments.cs | 12 +- .../Types/AllocObjCtxArguments.cs | 4 +- .../Types/MapCommandBufferArguments.cs | 8 +- .../NvHostChannel/Types/NvChannel.cs | 4 +- .../NvHostChannel/Types/NvChannelPriority.cs | 6 +- .../Types/SetErrorNotifierArguments.cs | 4 +- .../Types/SubmitGpfifoArguments.cs | 6 +- .../NvHostChannel/Types/SubmitGpfifoFlags.cs | 8 +- .../NvHostChannel/Types/ZcullBindArguments.cs | 4 +- .../NvHostCtrl/NvHostCtrlDeviceFile.cs | 6 +- .../NvHostCtrl/Types/EventWaitArguments.cs | 4 +- .../Types/GetConfigurationArguments.cs | 12 +- .../NvHostCtrl/Types/NvHostEvent.cs | 20 +- .../NvHostCtrl/Types/NvHostEventState.cs | 12 +- .../NvHostCtrl/Types/NvHostSyncPt.cs | 24 +- .../NvHostCtrl/Types/SyncptWaitArguments.cs | 2 +- .../NvHostCtrl/Types/SyncptWaitExArguments.cs | 2 +- .../NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs | 16 +- .../Types/GetCharacteristicsArguments.cs | 64 +-- .../Types/GetTpcMasksArguments.cs | 8 +- .../Types/ZbcSetTableArguments.cs | 1 - .../NvHostDbgGpu/NvHostDbgGpuDeviceFile.cs | 2 +- .../Nv/NvDrvServices/NvInternalResult.cs | 50 +-- .../Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs | 35 +- .../NvDrvServices/NvMap/Types/NvMapAlloc.cs | 12 +- .../NvDrvServices/NvMap/Types/NvMapCreate.cs | 2 +- .../Nv/NvDrvServices/NvMap/Types/NvMapFree.cs | 10 +- .../NvDrvServices/NvMap/Types/NvMapFromId.cs | 2 +- .../NvDrvServices/NvMap/Types/NvMapGetId.cs | 2 +- .../NvDrvServices/NvMap/Types/NvMapHandle.cs | 16 +- .../NvMap/Types/NvMapHandleParam.cs | 12 +- .../NvMap/Types/NvMapIdDictionary.cs | 2 +- .../NvDrvServices/NvMap/Types/NvMapParam.cs | 6 +- src/Ryujinx.HLE/HOS/Services/Nv/NvIoctl.cs | 38 +- .../HOS/Services/Nv/NvMemoryAllocator.cs | 6 +- .../HOS/Services/Nv/Types/NvFence.cs | 4 +- .../Types/NvIoctlNotImplementedException.cs | 10 +- .../NvQueryEventNotImplementedException.cs | 10 +- .../HOS/Services/Nv/Types/NvResult.cs | 46 +- .../HOS/Services/Nv/Types/NvStatus.cs | 2 +- .../Olsc/IOlscServiceForApplication.cs | 8 +- .../Olsc/IOlscServiceForSystemService.cs | 2 +- .../HOS/Services/Olsc/ResultCode.cs | 6 +- .../HOS/Services/Ovln/IReceiverService.cs | 2 +- .../HOS/Services/Ovln/ISenderService.cs | 2 +- .../HOS/Services/Pcie/ILogManager.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Pcie/IManager.cs | 2 +- .../Pctl/IParentalControlServiceFactory.cs | 6 +- .../IParentalControlService.cs | 41 +- .../HOS/Services/Pctl/ResultCode.cs | 10 +- .../Pcv/Bpc/IBoardPowerControlManager.cs | 2 +- .../Clkrst/ClkrstManager/IClkrstSession.cs | 23 +- .../Pcv/Clkrst/IArbitrationManager.cs | 2 +- .../HOS/Services/Pcv/Clkrst/IClkrstManager.cs | 4 +- .../HOS/Services/Pcv/IPcvService.cs | 2 +- .../HOS/Services/Pcv/ResultCode.cs | 6 +- .../Services/Pcv/Rgltr/IRegulatorManager.cs | 2 +- .../HOS/Services/Pcv/Rtc/IRtcManager.cs | 2 +- .../HOS/Services/Pcv/Types/DeviceCode.cs | 176 ++++---- .../HOS/Services/Pm/IBootModeInterface.cs | 2 +- .../HOS/Services/Pm/IDebugMonitorInterface.cs | 2 +- .../HOS/Services/Pm/IInformationInterface.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs | 14 +- .../HOS/Services/Psc/IPmControl.cs | 2 +- .../HOS/Services/Psc/IPmService.cs | 2 +- .../HOS/Services/Psc/IPmUnknown.cs | 2 +- .../HOS/Services/Ptm/Fan/IManager.cs | 2 +- .../HOS/Services/Ptm/Fgm/IDebugger.cs | 2 +- .../HOS/Services/Ptm/Fgm/ISession.cs | 2 +- .../HOS/Services/Ptm/Pcm/IManager.cs | 2 +- .../HOS/Services/Ptm/Psm/IPsmServer.cs | 2 +- .../HOS/Services/Ptm/Psm/IPsmSession.cs | 8 +- .../HOS/Services/Ptm/Psm/Types/ChargerType.cs | 4 +- .../HOS/Services/Ptm/Tc/IManager.cs | 2 +- .../HOS/Services/Ptm/Ts/IMeasurementServer.cs | 2 +- .../HOS/Services/Ptm/Ts/Types/Location.cs | 2 +- .../HOS/Services/Ro/IRoInterface.cs | 52 ++- src/Ryujinx.HLE/HOS/Services/Ro/ResultCode.cs | 30 +- .../HOS/Services/Ro/Types/NroInfo.cs | 38 +- .../HOS/Services/Ro/Types/NrrInfo.cs | 12 +- .../HOS/Services/Sdb/Avm/IAvmService.cs | 2 +- .../HOS/Services/Sdb/Pdm/INotifyService.cs | 2 +- .../HOS/Services/Sdb/Pdm/IQueryService.cs | 2 +- .../QueryPlayStatisticsManager.cs | 14 +- .../Types/ApplicationPlayStatistics.cs | 6 +- .../Types/PlayLogQueryCapability.cs | 4 +- .../HOS/Services/Sdb/Pdm/ResultCode.cs | 8 +- .../HOS/Services/Sdb/Pl/ISharedFontManager.cs | 18 +- .../HOS/Services/Sdb/Pl/SharedFontManager.cs | 51 ++- .../Services/Sdb/Pl/Types/SharedFontType.cs | 14 +- src/Ryujinx.HLE/HOS/Services/ServerBase.cs | 38 +- .../HOS/Services/ServiceAttributes.cs | 4 +- .../Settings/IFactorySettingsServer.cs | 2 +- .../Settings/IFirmwareDebugSettingsServer.cs | 2 +- .../HOS/Services/Settings/ISettingsServer.cs | 2 +- .../Settings/ISystemSettingsServer.cs | 123 +++--- .../HOS/Services/Settings/KeyCodeMaps.cs | 30 +- .../HOS/Services/Settings/NxSettings.cs | 6 +- .../HOS/Services/Settings/ResultCode.cs | 232 +++++----- .../Services/Settings/Types/PlatformRegion.cs | 4 +- .../HOS/Services/Sm/IManagerInterface.cs | 2 +- .../HOS/Services/Sm/IUserInterface.cs | 11 +- src/Ryujinx.HLE/HOS/Services/Sm/ResultCode.cs | 10 +- src/Ryujinx.HLE/HOS/Services/Sm/SmRegistry.cs | 2 +- .../HOS/Services/Sockets/Bsd/BsdContext.cs | 6 +- .../HOS/Services/Sockets/Bsd/IClient.cs | 224 +++++----- .../Services/Sockets/Bsd/IFileDescriptor.cs | 2 +- .../Sockets/Bsd/Impl/EventFileDescriptor.cs | 2 +- .../Impl/EventFileDescriptorPollManager.cs | 9 +- .../Sockets/Bsd/Impl/ManagedSocket.cs | 6 +- .../Bsd/Impl/ManagedSocketPollManager.cs | 13 +- .../HOS/Services/Sockets/Bsd/Impl/WSAError.cs | 146 +++---- .../Sockets/Bsd/Impl/WinSockHelper.cs | 16 +- .../Services/Sockets/Bsd/ServerInterface.cs | 2 +- .../Sockets/Bsd/Types/BsdAddressFamily.cs | 4 +- .../Services/Sockets/Bsd/Types/BsdIoctl.cs | 4 +- .../Services/Sockets/Bsd/Types/BsdSockAddr.cs | 6 +- .../Bsd/Types/BsdSocketCreationFlags.cs | 2 +- .../Sockets/Bsd/Types/BsdSocketFlags.cs | 4 +- .../Sockets/Bsd/Types/BsdSocketOption.cs | 7 +- .../Bsd/Types/BsdSocketShutdownFlags.cs | 2 +- .../Sockets/Bsd/Types/EventFdFlags.cs | 2 +- .../Sockets/Bsd/Types/IPollManager.cs | 2 +- .../Services/Sockets/Bsd/Types/LinuxError.cs | 264 ++++++------ .../Services/Sockets/Bsd/Types/PollEvent.cs | 2 +- .../Sockets/Bsd/Types/PollEventData.cs | 4 +- .../Sockets/Bsd/Types/PollEventTypeMask.cs | 2 +- .../Services/Sockets/Ethc/IEthInterface.cs | 2 +- .../Sockets/Ethc/IEthInterfaceGroup.cs | 2 +- .../HOS/Services/Sockets/Nsd/IManager.cs | 14 +- .../Sockets/Nsd/Manager/FqdnResolver.cs | 14 +- .../HOS/Services/Sockets/Nsd/ResultCode.cs | 20 +- .../Types/ApplicationServerEnvironmentType.cs | 4 +- .../Services/Sockets/Nsd/Types/NsdSettings.cs | 6 +- .../Services/Sockets/Sfdnsres/IResolver.cs | 220 +++++----- .../Sockets/Sfdnsres/Proxy/DnsBlacklist.cs | 8 +- .../Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs | 8 +- .../Sockets/Sfdnsres/Types/AddrInfo4.cs | 14 +- .../Types/AddrInfoSerializedHeader.cs | 38 +- .../Sockets/Sfdnsres/Types/GaiError.cs | 4 +- .../Sockets/Sfdnsres/Types/NetDBError.cs | 4 +- .../Sfdnsres/Types/SfdnsresContants.cs | 4 +- .../HOS/Services/Spl/IGeneralInterface.cs | 14 +- .../HOS/Services/Spl/IRandomInterface.cs | 6 +- .../HOS/Services/Spl/ResultCode.cs | 6 +- .../HOS/Services/Spl/Types/ConfigItem.cs | 34 +- .../HOS/Services/Spl/Types/DramId.cs | 4 +- .../HOS/Services/Spl/Types/HardwareState.cs | 4 +- .../HOS/Services/Spl/Types/HardwareType.cs | 2 +- .../HOS/Services/Spl/Types/SmcResult.cs | 23 +- .../HOS/Services/Srepo/ISrepoService.cs | 2 +- .../Services/Ssl/BuiltInCertificateManager.cs | 19 +- .../HOS/Services/Ssl/ISslService.cs | 12 +- .../HOS/Services/Ssl/ResultCode.cs | 20 +- .../Services/Ssl/SslService/ISslConnection.cs | 47 +- .../Ssl/SslService/ISslConnectionBase.cs | 2 +- .../Services/Ssl/SslService/ISslContext.cs | 12 +- .../SslService/SslManagedSocketConnection.cs | 32 +- .../HOS/Services/Ssl/Types/CaCertificateId.cs | 2 +- .../Services/Ssl/Types/CertificateFormat.cs | 4 +- .../HOS/Services/Ssl/Types/IoMode.cs | 6 +- .../HOS/Services/Ssl/Types/OptionType.cs | 4 +- .../Services/Ssl/Types/SessionCacheMode.cs | 4 +- .../HOS/Services/Ssl/Types/SslVersion.cs | 6 +- .../Services/Ssl/Types/TrustedCertStatus.cs | 2 +- .../HOS/Services/Ssl/Types/VerifyOption.cs | 14 +- .../SurfaceFlinger/BufferItemConsumer.cs | 2 +- .../Services/SurfaceFlinger/BufferQueue.cs | 2 +- .../SurfaceFlinger/BufferQueueConsumer.cs | 24 +- .../SurfaceFlinger/BufferQueueCore.cs | 94 ++-- .../SurfaceFlinger/BufferQueueProducer.cs | 108 ++--- .../HOS/Services/SurfaceFlinger/BufferSlot.cs | 28 +- .../SurfaceFlinger/BufferSlotArray.cs | 6 +- .../Services/SurfaceFlinger/ConsumerBase.cs | 14 +- .../SurfaceFlinger/HOSBinderDriverServer.cs | 4 +- .../HOS/Services/SurfaceFlinger/IBinder.cs | 4 +- .../SurfaceFlinger/IGraphicBufferProducer.cs | 58 +-- .../SurfaceFlinger/IHOSBinderDriver.cs | 37 +- .../HOS/Services/SurfaceFlinger/LayerState.cs | 4 +- .../SurfaceFlinger/NativeWindowApi.cs | 10 +- .../SurfaceFlinger/NativeWindowAttribute.cs | 12 +- .../SurfaceFlinger/NativeWindowScalingMode.cs | 8 +- .../SurfaceFlinger/NativeWindowTransform.cs | 16 +- .../HOS/Services/SurfaceFlinger/Parcel.cs | 42 +- .../HOS/Services/SurfaceFlinger/Status.cs | 23 +- .../Services/SurfaceFlinger/SurfaceFlinger.cs | 100 +++-- .../SurfaceFlinger/Types/AndroidFence.cs | 14 +- .../Types/AndroidStrongPointer.cs | 6 +- .../SurfaceFlinger/Types/BufferInfo.cs | 4 +- .../SurfaceFlinger/Types/BufferItem.cs | 73 ++-- .../SurfaceFlinger/Types/BufferState.cs | 8 +- .../Types/Color/ColorBytePerPixel.cs | 24 +- .../Types/Color/ColorComponent.cs | 4 +- .../Types/Color/ColorDataType.cs | 6 +- .../SurfaceFlinger/Types/Color/ColorFormat.cs | 9 +- .../SurfaceFlinger/Types/Color/ColorShift.cs | 8 +- .../SurfaceFlinger/Types/Color/ColorSpace.cs | 40 +- .../Types/Color/ColorSwizzle.cs | 6 +- .../SurfaceFlinger/Types/GraphicBuffer.cs | 26 +- .../Types/GraphicBufferHeader.cs | 12 +- .../SurfaceFlinger/Types/NvGraphicBuffer.cs | 2 +- .../Types/NvGraphicBufferSurface.cs | 2 +- .../Types/NvGraphicBufferSurfaceArray.cs | 25 +- .../HOS/Services/SurfaceFlinger/Types/Rect.cs | 30 +- .../Clock/LocalSystemClockContextWriter.cs | 4 +- .../Clock/NetworkSystemClockContextWriter.cs | 4 +- .../Clock/StandardLocalSystemClockCore.cs | 2 +- .../Clock/StandardNetworkSystemClockCore.cs | 2 +- .../Time/Clock/StandardSteadyClockCore.cs | 14 +- .../Time/Clock/StandardUserSystemClockCore.cs | 18 +- .../Services/Time/Clock/SteadyClockCore.cs | 12 +- .../Clock/SystemClockContextUpdateCallback.cs | 14 +- .../Services/Time/Clock/SystemClockCore.cs | 23 +- .../Time/Clock/TickBasedSteadyClockCore.cs | 8 +- .../Time/Clock/Types/ClockSnapshot.cs | 20 +- .../Time/Clock/Types/SteadyClockTimePoint.cs | 10 +- .../Time/Clock/Types/SystemClockContext.cs | 4 +- .../Services/Time/Clock/Types/TimeSpanType.cs | 10 +- .../HOS/Services/Time/IAlarmService.cs | 2 +- .../Time/IPowerStateRequestHandler.cs | 2 +- .../Services/Time/IStaticServiceForGlue.cs | 8 +- .../HOS/Services/Time/IStaticServiceForPsc.cs | 43 +- .../HOS/Services/Time/ITimeServiceManager.cs | 35 +- .../HOS/Services/Time/ResultCode.cs | 33 +- .../Time/StaticService/ISteadyClock.cs | 12 +- .../Time/StaticService/ISystemClock.cs | 18 +- .../StaticService/ITimeZoneServiceForGlue.cs | 27 +- .../StaticService/ITimeZoneServiceForPsc.cs | 39 +- .../HOS/Services/Time/TimeManager.cs | 43 +- .../HOS/Services/Time/TimeSharedMemory.cs | 28 +- .../HOS/Services/Time/TimeZone/TimeZone.cs | 251 +++++------ .../Time/TimeZone/TimeZoneContentManager.cs | 64 ++- .../Services/Time/TimeZone/TimeZoneManager.cs | 42 +- .../TimeZone/Types/CalendarAdditionalInfo.cs | 2 +- .../Time/TimeZone/Types/CalendarInfo.cs | 4 +- .../Time/TimeZone/Types/CalendarTime.cs | 2 +- .../Time/TimeZone/Types/TimeTypeInfo.cs | 2 +- .../Time/TimeZone/Types/TimeZoneRule.cs | 2 +- .../Time/TimeZone/Types/TzifHeader.cs | 2 +- .../Services/Time/Types/SteadyClockContext.cs | 2 +- .../Services/Time/Types/TimePermissions.cs | 20 +- .../HOS/Services/Usb/IClientRootSession.cs | 2 +- .../HOS/Services/Usb/IDsService.cs | 2 +- .../HOS/Services/Usb/IPdCradleManager.cs | 2 +- .../HOS/Services/Usb/IPdManager.cs | 2 +- .../HOS/Services/Usb/IPmService.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Usb/IUnknown1.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Usb/IUnknown2.cs | 2 +- .../Services/Vi/IApplicationRootService.cs | 2 +- .../HOS/Services/Vi/IManagerRootService.cs | 2 +- .../HOS/Services/Vi/ISystemRootService.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Vi/ResultCode.cs | 14 +- .../AndroidSurfaceComposerClient.cs | 4 +- .../IManagerDisplayService.cs | 12 +- .../ISystemDisplayService.cs | 6 +- .../Types/DestinationScalingMode.cs | 4 +- .../Types/DisplayInfo.cs | 12 +- .../Types/SourceScalingMode.cs | 4 +- .../RootService/IApplicationDisplayService.cs | 75 ++-- .../HOS/Services/Vi/Types/ViServiceType.cs | 4 +- .../HOS/Services/Wlan/IInfraManager.cs | 2 +- .../HOS/Services/Wlan/ILocalGetActionFrame.cs | 2 +- .../HOS/Services/Wlan/ILocalGetFrame.cs | 2 +- .../HOS/Services/Wlan/ILocalManager.cs | 2 +- .../HOS/Services/Wlan/ISocketGetFrame.cs | 2 +- .../HOS/Services/Wlan/ISocketManager.cs | 2 +- .../HOS/Services/Wlan/IUnknown1.cs | 2 +- .../HOS/SystemState/AppletStateMgr.cs | 4 +- src/Ryujinx.HLE/HOS/SystemState/ColorSet.cs | 2 +- .../HOS/SystemState/KeyboardLayout.cs | 2 +- src/Ryujinx.HLE/HOS/SystemState/RegionCode.cs | 2 +- .../HOS/SystemState/SystemLanguage.cs | 4 +- .../HOS/SystemState/SystemStateMgr.cs | 19 +- .../HOS/SystemState/TitleLanguage.cs | 2 +- .../HOS/Tamper/AtmosphereCompiler.cs | 37 +- .../HOS/Tamper/AtmosphereProgram.cs | 4 +- .../HOS/Tamper/CodeEmitters/Arithmetic.cs | 50 ++- .../CodeEmitters/EndConditionalBlock.cs | 6 +- .../Tamper/CodeEmitters/LegacyArithmetic.cs | 24 +- .../CodeEmitters/LoadRegisterWithConstant.cs | 2 +- .../Tamper/CodeEmitters/MemoryConditional.cs | 2 +- .../HOS/Tamper/CodeEmitters/ResumeProcess.cs | 1 - .../HOS/Tamper/CodeEmitters/StartEndLoop.cs | 2 +- .../CodeEmitters/StoreConstantToAddress.cs | 2 +- .../CodeEmitters/StoreConstantToMemory.cs | 2 +- src/Ryujinx.HLE/HOS/Tamper/CodeType.cs | 2 +- src/Ryujinx.HLE/HOS/Tamper/Comparison.cs | 2 +- .../HOS/Tamper/CompilationContext.cs | 18 +- .../HOS/Tamper/Conditions/CondEQ.cs | 4 +- .../HOS/Tamper/Conditions/CondGE.cs | 4 +- .../HOS/Tamper/Conditions/CondGT.cs | 4 +- .../HOS/Tamper/Conditions/CondLE.cs | 4 +- .../HOS/Tamper/Conditions/CondLT.cs | 4 +- .../HOS/Tamper/Conditions/CondNE.cs | 4 +- .../HOS/Tamper/Conditions/InputMask.cs | 4 +- .../HOS/Tamper/InstructionHelper.cs | 37 +- src/Ryujinx.HLE/HOS/Tamper/MemoryHelper.cs | 41 +- .../HOS/Tamper/Operations/Block.cs | 2 +- .../HOS/Tamper/Operations/ForBlock.cs | 6 +- .../HOS/Tamper/Operations/IfBlock.cs | 6 +- .../HOS/Tamper/Operations/OpAdd.cs | 6 +- .../HOS/Tamper/Operations/OpAnd.cs | 6 +- .../HOS/Tamper/Operations/OpLog.cs | 4 +- .../HOS/Tamper/Operations/OpLsh.cs | 6 +- .../HOS/Tamper/Operations/OpMov.cs | 4 +- .../HOS/Tamper/Operations/OpMul.cs | 6 +- .../HOS/Tamper/Operations/OpNot.cs | 4 +- src/Ryujinx.HLE/HOS/Tamper/Operations/OpOr.cs | 6 +- .../HOS/Tamper/Operations/OpProcCtrl.cs | 4 +- .../HOS/Tamper/Operations/OpRsh.cs | 6 +- .../HOS/Tamper/Operations/OpSub.cs | 6 +- .../HOS/Tamper/Operations/OpXor.cs | 6 +- src/Ryujinx.HLE/HOS/Tamper/Pointer.cs | 4 +- src/Ryujinx.HLE/HOS/Tamper/Register.cs | 2 +- .../HOS/Tamper/TamperedKProcess.cs | 4 +- src/Ryujinx.HLE/HOS/Tamper/Value.cs | 8 +- src/Ryujinx.HLE/HOS/TamperMachine.cs | 16 +- src/Ryujinx.HLE/HOS/UserChannelPersistence.cs | 2 +- src/Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs | 4 +- src/Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs | 133 +++--- src/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs | 36 +- src/Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs | 14 +- src/Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs | 14 +- .../Loaders/Elf/ElfSymbolBinding.cs | 6 +- src/Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs | 14 +- .../Loaders/Elf/ElfSymbolVisibility.cs | 10 +- .../Loaders/Executables/IExecutable.cs | 10 +- .../Loaders/Executables/KipExecutable.cs | 52 +-- .../Loaders/Executables/NroExecutable.cs | 18 +- .../Loaders/Executables/NsoExecutable.cs | 30 +- src/Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs | 27 +- .../Loaders/Mods/IPSwitchPatcher.cs | 50 ++- src/Ryujinx.HLE/Loaders/Mods/MemPatch.cs | 6 +- src/Ryujinx.HLE/Loaders/Npdm/ACI0.cs | 20 +- src/Ryujinx.HLE/Loaders/Npdm/ACID.cs | 24 +- .../Loaders/Npdm/FsAccessControl.cs | 22 +- .../Loaders/Npdm/FsAccessHeader.cs | 11 +- .../Loaders/Npdm/KernelAccessControl.cs | 2 +- src/Ryujinx.HLE/Loaders/Npdm/Npdm.cs | 28 +- .../Loaders/Npdm/ServiceAccessControl.cs | 6 +- .../Extensions/FileSystemExtensions.cs | 4 +- .../Extensions/LocalFileSystemExtensions.cs | 8 +- .../Extensions/MetaLoaderExtensions.cs | 2 +- .../Processes/Extensions/NcaExtensions.cs | 4 +- .../PartitionFileSystemExtensions.cs | 14 +- .../Loaders/Processes/ProcessConst.cs | 8 +- .../Loaders/Processes/ProcessLoader.cs | 23 +- .../Loaders/Processes/ProcessLoaderHelper.cs | 46 +- .../Loaders/Processes/ProcessResult.cs | 43 +- src/Ryujinx.HLE/MemoryConfiguration.cs | 16 +- src/Ryujinx.HLE/PerformanceStatistics.cs | 62 +-- src/Ryujinx.HLE/Switch.cs | 29 +- .../Ui/DynamicTextChangedHandler.cs | 2 +- .../Ui/IDynamicTextInputHandler.cs | 2 +- src/Ryujinx.HLE/Ui/IHostUiHandler.cs | 2 +- src/Ryujinx.HLE/Ui/Input/NpadReader.cs | 12 +- src/Ryujinx.HLE/Ui/KeyPressedHandler.cs | 2 +- src/Ryujinx.HLE/Ui/KeyReleasedHandler.cs | 2 +- src/Ryujinx.HLE/Ui/RenderingSurfaceInfo.cs | 18 +- src/Ryujinx.HLE/Utilities/StringUtils.cs | 49 +-- src/Ryujinx/Ui/MainWindow.cs | 2 +- .../Ui/Widgets/GameTableContextMenu.cs | 2 +- src/Ryujinx/Ui/Windows/AvatarWindow.cs | 2 +- 1015 files changed, 8173 insertions(+), 7615 deletions(-) rename src/Ryujinx.HLE/HOS/Kernel/Common/{MemroySize.cs => MemorySize.cs} (82%) diff --git a/src/Ryujinx.Ava/Common/ApplicationHelper.cs b/src/Ryujinx.Ava/Common/ApplicationHelper.cs index b8f2366cd..d28d5aac1 100644 --- a/src/Ryujinx.Ava/Common/ApplicationHelper.cs +++ b/src/Ryujinx.Ava/Common/ApplicationHelper.cs @@ -114,7 +114,7 @@ namespace Ryujinx.Ava.Common public static void OpenSaveDir(ulong saveDataId) { - string saveRootPath = Path.Combine(_virtualFileSystem.GetNandPath(), $"user/save/{saveDataId:x16}"); + string saveRootPath = Path.Combine(VirtualFileSystem.GetNandPath(), $"user/save/{saveDataId:x16}"); if (!Directory.Exists(saveRootPath)) { diff --git a/src/Ryujinx.Ava/UI/Models/SaveModel.cs b/src/Ryujinx.Ava/UI/Models/SaveModel.cs index 2f220162f..f15befbb3 100644 --- a/src/Ryujinx.Ava/UI/Models/SaveModel.cs +++ b/src/Ryujinx.Ava/UI/Models/SaveModel.cs @@ -2,6 +2,7 @@ using LibHac.Fs; using LibHac.Ncm; using Ryujinx.Ava.UI.ViewModels; using Ryujinx.Ava.UI.Windows; +using Ryujinx.HLE.FileSystem; using Ryujinx.Ui.App.Common; using System; using System.IO; @@ -81,7 +82,7 @@ namespace Ryujinx.Ava.UI.Models Task.Run(() => { - var saveRoot = Path.Combine(MainWindow.MainWindowViewModel.VirtualFileSystem.GetNandPath(), $"user/save/{info.SaveDataId:x16}"); + var saveRoot = Path.Combine(VirtualFileSystem.GetNandPath(), $"user/save/{info.SaveDataId:x16}"); long totalSize = GetDirectorySize(saveRoot); diff --git a/src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs index cb8da9ede..89b591229 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs @@ -105,7 +105,7 @@ namespace Ryujinx.Ava.UI.ViewModels } string contentPath = contentManager.GetInstalledContentPath(0x010000000000080A, StorageId.BuiltInSystem, NcaContentType.Data); - string avatarPath = virtualFileSystem.SwitchPathToSystemPath(contentPath); + string avatarPath = VirtualFileSystem.SwitchPathToSystemPath(contentPath); if (!string.IsNullOrWhiteSpace(avatarPath)) { diff --git a/src/Ryujinx.HLE/AssemblyInfo.cs b/src/Ryujinx.HLE/AssemblyInfo.cs index 9d7bad6be..82519d542 100644 --- a/src/Ryujinx.HLE/AssemblyInfo.cs +++ b/src/Ryujinx.HLE/AssemblyInfo.cs @@ -1,3 +1,3 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("Ryujinx.Tests")] \ No newline at end of file +[assembly: InternalsVisibleTo("Ryujinx.Tests")] diff --git a/src/Ryujinx.HLE/Exceptions/GuestBrokeExecutionException.cs b/src/Ryujinx.HLE/Exceptions/GuestBrokeExecutionException.cs index fe41b02a6..4e06ab772 100644 --- a/src/Ryujinx.HLE/Exceptions/GuestBrokeExecutionException.cs +++ b/src/Ryujinx.HLE/Exceptions/GuestBrokeExecutionException.cs @@ -8,4 +8,4 @@ namespace Ryujinx.HLE.Exceptions public GuestBrokeExecutionException() : base(ExMsg) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Exceptions/InternalServiceException.cs b/src/Ryujinx.HLE/Exceptions/InternalServiceException.cs index 85de63a6a..e0ee5eb91 100644 --- a/src/Ryujinx.HLE/Exceptions/InternalServiceException.cs +++ b/src/Ryujinx.HLE/Exceptions/InternalServiceException.cs @@ -2,8 +2,8 @@ namespace Ryujinx.HLE.Exceptions { - class InternalServiceException: Exception + class InternalServiceException : Exception { public InternalServiceException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Exceptions/InvalidFirmwarePackageException.cs b/src/Ryujinx.HLE/Exceptions/InvalidFirmwarePackageException.cs index d08de581b..bddd827a0 100644 --- a/src/Ryujinx.HLE/Exceptions/InvalidFirmwarePackageException.cs +++ b/src/Ryujinx.HLE/Exceptions/InvalidFirmwarePackageException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public InvalidFirmwarePackageException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Exceptions/InvalidNpdmException.cs b/src/Ryujinx.HLE/Exceptions/InvalidNpdmException.cs index 98675e42c..c4036ea0d 100644 --- a/src/Ryujinx.HLE/Exceptions/InvalidNpdmException.cs +++ b/src/Ryujinx.HLE/Exceptions/InvalidNpdmException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public InvalidNpdmException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Exceptions/InvalidStructLayoutException.cs b/src/Ryujinx.HLE/Exceptions/InvalidStructLayoutException.cs index 2f03d13ab..6852dcefe 100644 --- a/src/Ryujinx.HLE/Exceptions/InvalidStructLayoutException.cs +++ b/src/Ryujinx.HLE/Exceptions/InvalidStructLayoutException.cs @@ -3,13 +3,13 @@ using System.Runtime.CompilerServices; namespace Ryujinx.HLE.Exceptions { - public class InvalidStructLayoutException : Exception + public class InvalidStructLayoutException : Exception { static readonly Type _structType = typeof(T); public InvalidStructLayoutException(string message) : base(message) { } - + public InvalidStructLayoutException(int expectedSize) : base($"Type {_structType.Name} has the wrong size. Expected: {expectedSize} bytes, got: {Unsafe.SizeOf()} bytes") { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Exceptions/InvalidSystemResourceException.cs b/src/Ryujinx.HLE/Exceptions/InvalidSystemResourceException.cs index 3c63e0641..d9afff111 100644 --- a/src/Ryujinx.HLE/Exceptions/InvalidSystemResourceException.cs +++ b/src/Ryujinx.HLE/Exceptions/InvalidSystemResourceException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public InvalidSystemResourceException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Exceptions/ServiceNotImplementedException.cs b/src/Ryujinx.HLE/Exceptions/ServiceNotImplementedException.cs index 40b19cc8e..e43c838a2 100644 --- a/src/Ryujinx.HLE/Exceptions/ServiceNotImplementedException.cs +++ b/src/Ryujinx.HLE/Exceptions/ServiceNotImplementedException.cs @@ -47,7 +47,7 @@ namespace Ryujinx.HLE.Exceptions private string BuildMessage() { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new(); // Print the IPC command details (service name, command ID, and handler) (Type callingType, MethodBase callingMethod) = WalkStackTrace(new StackTrace(this)); @@ -58,9 +58,9 @@ namespace Ryujinx.HLE.Exceptions var ipcCommands = Request.Type > IpcMessageType.TipcCloseSession ? Service.TipcCommands : Service.CmifCommands; // Find the handler for the method called - var ipcHandler = ipcCommands.FirstOrDefault(x => x.Value == callingMethod); + var ipcHandler = ipcCommands.FirstOrDefault(x => x.Value == callingMethod); var ipcCommandId = ipcHandler.Key; - var ipcMethod = ipcHandler.Value; + var ipcMethod = ipcHandler.Value; if (ipcMethod != null) { @@ -73,9 +73,9 @@ namespace Ryujinx.HLE.Exceptions sb.AppendLine(Context.Thread.GetGuestStackTrace()); // Print buffer information - if (Request.PtrBuff.Count > 0 || - Request.SendBuff.Count > 0 || - Request.ReceiveBuff.Count > 0 || + if (Request.PtrBuff.Count > 0 || + Request.SendBuff.Count > 0 || + Request.ReceiveBuff.Count > 0 || Request.ExchangeBuff.Count > 0 || Request.RecvListBuff.Count > 0) { @@ -149,7 +149,7 @@ namespace Ryujinx.HLE.Exceptions // Find the IIpcService method that threw this exception while ((frame = trace.GetFrame(i++)) != null) { - var method = frame.GetMethod(); + var method = frame.GetMethod(); var declType = method.DeclaringType; if (typeof(IpcService).IsAssignableFrom(declType)) @@ -161,4 +161,4 @@ namespace Ryujinx.HLE.Exceptions return (null, null); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Exceptions/TamperCompilationException.cs b/src/Ryujinx.HLE/Exceptions/TamperCompilationException.cs index 02d871638..370df5d3b 100644 --- a/src/Ryujinx.HLE/Exceptions/TamperCompilationException.cs +++ b/src/Ryujinx.HLE/Exceptions/TamperCompilationException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public TamperCompilationException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Exceptions/TamperExecutionException.cs b/src/Ryujinx.HLE/Exceptions/TamperExecutionException.cs index d62effe3a..1f132607d 100644 --- a/src/Ryujinx.HLE/Exceptions/TamperExecutionException.cs +++ b/src/Ryujinx.HLE/Exceptions/TamperExecutionException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public TamperExecutionException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Exceptions/UndefinedInstructionException.cs b/src/Ryujinx.HLE/Exceptions/UndefinedInstructionException.cs index dfbd6c272..3886e5e76 100644 --- a/src/Ryujinx.HLE/Exceptions/UndefinedInstructionException.cs +++ b/src/Ryujinx.HLE/Exceptions/UndefinedInstructionException.cs @@ -10,4 +10,4 @@ namespace Ryujinx.HLE.Exceptions public UndefinedInstructionException(ulong address, int opCode) : base(string.Format(ExMsg, address, opCode)) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/FileSystem/ContentManager.cs b/src/Ryujinx.HLE/FileSystem/ContentManager.cs index e00310a07..13f987638 100644 --- a/src/Ryujinx.HLE/FileSystem/ContentManager.cs +++ b/src/Ryujinx.HLE/FileSystem/ContentManager.cs @@ -26,17 +26,17 @@ namespace Ryujinx.HLE.FileSystem public class ContentManager { private const ulong SystemVersionTitleId = 0x0100000000000809; - private const ulong SystemUpdateTitleId = 0x0100000000000816; + private const ulong SystemUpdateTitleId = 0x0100000000000816; private Dictionary> _locationEntries; - private Dictionary _sharedFontTitleDictionary; - private Dictionary _systemTitlesNameDictionary; - private Dictionary _sharedFontFilenameDictionary; + private readonly Dictionary _sharedFontTitleDictionary; + private readonly Dictionary _systemTitlesNameDictionary; + private readonly Dictionary _sharedFontFilenameDictionary; private SortedDictionary<(ulong titleId, NcaContentType type), string> _contentDictionary; - private struct AocItem + private readonly struct AocItem { public readonly string ContainerPath; public readonly string NcaPath; @@ -48,16 +48,16 @@ namespace Ryujinx.HLE.FileSystem } } - private SortedList _aocData { get; } + private SortedList AocData { get; } - private VirtualFileSystem _virtualFileSystem; + private readonly VirtualFileSystem _virtualFileSystem; private readonly object _lock = new(); public ContentManager(VirtualFileSystem virtualFileSystem) { _contentDictionary = new SortedDictionary<(ulong, NcaContentType), string>(); - _locationEntries = new Dictionary>(); + _locationEntries = new Dictionary>(); _sharedFontTitleDictionary = new Dictionary { @@ -66,7 +66,7 @@ namespace Ryujinx.HLE.FileSystem { "FontExtendedChineseSimplified", 0x0100000000000814 }, { "FontKorean", 0x0100000000000812 }, { "FontChineseTraditional", 0x0100000000000813 }, - { "FontNintendoExtended", 0x0100000000000810 } + { "FontNintendoExtended", 0x0100000000000810 }, }; _systemTitlesNameDictionary = new Dictionary() @@ -86,12 +86,12 @@ namespace Ryujinx.HLE.FileSystem { "FontExtendedChineseSimplified", "nintendo_udsg-r_ext_zh-cn_003.bfttf" }, { "FontKorean", "nintendo_udsg-r_ko_003.bfttf" }, { "FontChineseTraditional", "nintendo_udjxh-db_zh-tw_003.bfttf" }, - { "FontNintendoExtended", "nintendo_ext_003.bfttf" } + { "FontNintendoExtended", "nintendo_ext_003.bfttf" }, }; _virtualFileSystem = virtualFileSystem; - _aocData = new SortedList(); + AocData = new SortedList(); } public void LoadEntries(Switch device = null) @@ -99,18 +99,18 @@ namespace Ryujinx.HLE.FileSystem lock (_lock) { _contentDictionary = new SortedDictionary<(ulong, NcaContentType), string>(); - _locationEntries = new Dictionary>(); + _locationEntries = new Dictionary>(); foreach (StorageId storageId in Enum.GetValues()) { - string contentDirectory = null; - string contentPathString = null; + string contentDirectory = null; + string contentPathString = null; string registeredDirectory = null; try { - contentPathString = ContentPath.GetContentPath(storageId); - contentDirectory = ContentPath.GetRealPath(_virtualFileSystem, contentPathString); + contentPathString = ContentPath.GetContentPath(storageId); + contentDirectory = ContentPath.GetRealPath(contentPathString); registeredDirectory = Path.Combine(contentDirectory, "registered"); } catch (NotSupportedException) @@ -120,7 +120,7 @@ namespace Ryujinx.HLE.FileSystem Directory.CreateDirectory(registeredDirectory); - LinkedList locationList = new LinkedList(); + LinkedList locationList = new(); void AddEntry(LocationEntry entry) { @@ -133,24 +133,19 @@ namespace Ryujinx.HLE.FileSystem { string ncaName = new DirectoryInfo(directoryPath).Name.Replace(".nca", string.Empty); - using (FileStream ncaFile = File.OpenRead(Directory.GetFiles(directoryPath)[0])) - { - Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage()); + using FileStream ncaFile = File.OpenRead(Directory.GetFiles(directoryPath)[0]); + Nca nca = new(_virtualFileSystem.KeySet, ncaFile.AsStorage()); - string switchPath = contentPathString + ":/" + ncaFile.Name.Replace(contentDirectory, string.Empty).TrimStart(Path.DirectorySeparatorChar); + string switchPath = contentPathString + ":/" + ncaFile.Name.Replace(contentDirectory, string.Empty).TrimStart(Path.DirectorySeparatorChar); - // Change path format to switch's - switchPath = switchPath.Replace('\\', '/'); + // Change path format to switch's + switchPath = switchPath.Replace('\\', '/'); - LocationEntry entry = new LocationEntry(switchPath, - 0, - nca.Header.TitleId, - nca.Header.ContentType); + LocationEntry entry = new(switchPath, 0, nca.Header.TitleId, nca.Header.ContentType); - AddEntry(entry); + AddEntry(entry); - _contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName); - } + _contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName); } } @@ -160,24 +155,19 @@ namespace Ryujinx.HLE.FileSystem { string ncaName = Path.GetFileNameWithoutExtension(filePath); - using (FileStream ncaFile = new FileStream(filePath, FileMode.Open, FileAccess.Read)) - { - Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage()); + using FileStream ncaFile = new(filePath, FileMode.Open, FileAccess.Read); + Nca nca = new(_virtualFileSystem.KeySet, ncaFile.AsStorage()); - string switchPath = contentPathString + ":/" + filePath.Replace(contentDirectory, string.Empty).TrimStart(Path.DirectorySeparatorChar); + string switchPath = contentPathString + ":/" + filePath.Replace(contentDirectory, string.Empty).TrimStart(Path.DirectorySeparatorChar); - // Change path format to switch's - switchPath = switchPath.Replace('\\', '/'); + // Change path format to switch's + switchPath = switchPath.Replace('\\', '/'); - LocationEntry entry = new LocationEntry(switchPath, - 0, - nca.Header.TitleId, - nca.Header.ContentType); + LocationEntry entry = new(switchPath, 0, nca.Header.TitleId, nca.Header.ContentType); - AddEntry(entry); + AddEntry(entry); - _contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName); - } + _contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName); } } @@ -186,10 +176,7 @@ namespace Ryujinx.HLE.FileSystem _locationEntries.Remove(storageId); } - if (!_locationEntries.ContainsKey(storageId)) - { - _locationEntries.Add(storageId, locationList); - } + _locationEntries.TryAdd(storageId, locationList); } if (device != null) @@ -239,7 +226,7 @@ namespace Ryujinx.HLE.FileSystem public void AddAocItem(ulong titleId, string containerPath, string ncaPath, bool mergedToContainer = false) { // TODO: Check Aoc version. - if (!_aocData.TryAdd(titleId, new AocItem(containerPath, ncaPath))) + if (!AocData.TryAdd(titleId, new AocItem(containerPath, ncaPath))) { Logger.Warning?.Print(LogClass.Application, $"Duplicate AddOnContent detected. TitleId {titleId:X16}"); } @@ -249,7 +236,7 @@ namespace Ryujinx.HLE.FileSystem if (!mergedToContainer) { - using FileStream fileStream = File.OpenRead(containerPath); + using FileStream fileStream = File.OpenRead(containerPath); using PartitionFileSystem partitionFileSystem = new(fileStream.AsStorage()); _virtualFileSystem.ImportTickets(partitionFileSystem); @@ -257,17 +244,17 @@ namespace Ryujinx.HLE.FileSystem } } - public void ClearAocData() => _aocData.Clear(); + public void ClearAocData() => AocData.Clear(); - public int GetAocCount() => _aocData.Count; + public int GetAocCount() => AocData.Count; - public IList GetAocTitleIds() => _aocData.Select(e => e.Key).ToList(); + public IList GetAocTitleIds() => AocData.Select(e => e.Key).ToList(); public bool GetAocDataStorage(ulong aocTitleId, out IStorage aocStorage, IntegrityCheckLevel integrityCheckLevel) { aocStorage = null; - if (_aocData.TryGetValue(aocTitleId, out AocItem aoc)) + if (AocData.TryGetValue(aocTitleId, out AocItem aoc)) { var file = new FileStream(aoc.ContainerPath, FileMode.Open, FileAccess.Read); using var ncaFile = new UniqueRef(); @@ -307,7 +294,7 @@ namespace Ryujinx.HLE.FileSystem { lock (_lock) { - LinkedList locationList = _locationEntries[storageId]; + LinkedList locationList = _locationEntries[storageId]; LinkedListNode locationEntry = locationList.First; while (locationEntry != null) @@ -331,7 +318,7 @@ namespace Ryujinx.HLE.FileSystem if (_contentDictionary.ContainsValue(ncaId)) { var content = _contentDictionary.FirstOrDefault(x => x.Value == ncaId); - ulong titleId = content.Key.Item1; + ulong titleId = content.Key.titleId; NcaContentType contentType = content.Key.type; StorageId storage = GetInstalledStorage(titleId, contentType, storageId); @@ -403,19 +390,17 @@ namespace Ryujinx.HLE.FileSystem return false; } - string installedPath = _virtualFileSystem.SwitchPathToSystemPath(locationEntry.ContentPath); + string installedPath = VirtualFileSystem.SwitchPathToSystemPath(locationEntry.ContentPath); if (!string.IsNullOrWhiteSpace(installedPath)) { if (File.Exists(installedPath)) { - using (FileStream file = new FileStream(installedPath, FileMode.Open, FileAccess.Read)) - { - Nca nca = new Nca(_virtualFileSystem.KeySet, file.AsStorage()); - bool contentCheck = nca.Header.ContentType == contentType; + using FileStream file = new(installedPath, FileMode.Open, FileAccess.Read); + Nca nca = new(_virtualFileSystem.KeySet, file.AsStorage()); + bool contentCheck = nca.Header.ContentType == contentType; - return contentCheck; - } + return contentCheck; } } @@ -426,9 +411,9 @@ namespace Ryujinx.HLE.FileSystem { LinkedList locationList = null; - if (_locationEntries.ContainsKey(storageId)) + if (_locationEntries.TryGetValue(storageId, out LinkedList locationEntry)) { - locationList = _locationEntries[storageId]; + locationList = locationEntry; } if (locationList != null) @@ -446,9 +431,9 @@ namespace Ryujinx.HLE.FileSystem { LinkedList locationList = null; - if (_locationEntries.ContainsKey(storageId)) + if (_locationEntries.TryGetValue(storageId, out LinkedList locationEntry)) { - locationList = _locationEntries[storageId]; + locationList = locationEntry; } if (locationList != null) @@ -487,10 +472,10 @@ namespace Ryujinx.HLE.FileSystem public void InstallFirmware(string firmwareSource) { - string contentPathString = ContentPath.GetContentPath(StorageId.BuiltInSystem); - string contentDirectory = ContentPath.GetRealPath(_virtualFileSystem, contentPathString); + string contentPathString = ContentPath.GetContentPath(StorageId.BuiltInSystem); + string contentDirectory = ContentPath.GetRealPath(contentPathString); string registeredDirectory = Path.Combine(contentDirectory, "registered"); - string temporaryDirectory = Path.Combine(contentDirectory, "temp"); + string temporaryDirectory = Path.Combine(contentDirectory, "temp"); if (Directory.Exists(temporaryDirectory)) { @@ -510,28 +495,27 @@ namespace Ryujinx.HLE.FileSystem throw new FileNotFoundException("Firmware file does not exist."); } - FileInfo info = new FileInfo(firmwareSource); + FileInfo info = new(firmwareSource); - using (FileStream file = File.OpenRead(firmwareSource)) + using FileStream file = File.OpenRead(firmwareSource); + + switch (info.Extension) { - switch (info.Extension) - { - case ".zip": - using (ZipArchive archive = ZipFile.OpenRead(firmwareSource)) - { - InstallFromZip(archive, temporaryDirectory); - } - break; - case ".xci": - Xci xci = new Xci(_virtualFileSystem.KeySet, file.AsStorage()); - InstallFromCart(xci, temporaryDirectory); - break; - default: - throw new InvalidFirmwarePackageException("Input file is not a valid firmware package"); - } - - FinishInstallation(temporaryDirectory, registeredDirectory); + case ".zip": + using (ZipArchive archive = ZipFile.OpenRead(firmwareSource)) + { + InstallFromZip(archive, temporaryDirectory); + } + break; + case ".xci": + Xci xci = new(_virtualFileSystem.KeySet, file.AsStorage()); + InstallFromCart(xci, temporaryDirectory); + break; + default: + throw new InvalidFirmwarePackageException("Input file is not a valid firmware package"); } + + FinishInstallation(temporaryDirectory, registeredDirectory); } private void FinishInstallation(string temporaryDirectory, string registeredDirectory) @@ -555,7 +539,7 @@ namespace Ryujinx.HLE.FileSystem { foreach (var entry in filesystem.EnumerateEntries("/", "*.nca")) { - Nca nca = new Nca(_virtualFileSystem.KeySet, OpenPossibleFragmentedFile(filesystem, entry.FullPath, OpenMode.Read).AsStorage()); + Nca nca = new(_virtualFileSystem.KeySet, OpenPossibleFragmentedFile(filesystem, entry.FullPath, OpenMode.Read).AsStorage()); SaveNca(nca, entry.Name.Remove(entry.Name.IndexOf('.')), temporaryDirectory); } @@ -575,52 +559,47 @@ namespace Ryujinx.HLE.FileSystem } } - private void InstallFromZip(ZipArchive archive, string temporaryDirectory) + private static void InstallFromZip(ZipArchive archive, string temporaryDirectory) { - using (archive) + foreach (var entry in archive.Entries) { - foreach (var entry in archive.Entries) + if (entry.FullName.EndsWith(".nca") || entry.FullName.EndsWith(".nca/00")) { - if (entry.FullName.EndsWith(".nca") || entry.FullName.EndsWith(".nca/00")) + // Clean up the name and get the NcaId + + string[] pathComponents = entry.FullName.Replace(".cnmt", "").Split('/'); + + string ncaId = pathComponents[^1]; + + // If this is a fragmented nca, we need to get the previous element.GetZip + if (ncaId.Equals("00")) { - // Clean up the name and get the NcaId + ncaId = pathComponents[^2]; + } - string[] pathComponents = entry.FullName.Replace(".cnmt", "").Split('/'); + if (ncaId.Contains(".nca")) + { + string newPath = Path.Combine(temporaryDirectory, ncaId); - string ncaId = pathComponents[pathComponents.Length - 1]; + Directory.CreateDirectory(newPath); - // If this is a fragmented nca, we need to get the previous element.GetZip - if (ncaId.Equals("00")) - { - ncaId = pathComponents[pathComponents.Length - 2]; - } - - if (ncaId.Contains(".nca")) - { - string newPath = Path.Combine(temporaryDirectory, ncaId); - - Directory.CreateDirectory(newPath); - - entry.ExtractToFile(Path.Combine(newPath, "00")); - } + entry.ExtractToFile(Path.Combine(newPath, "00")); } } } } - public void SaveNca(Nca nca, string ncaId, string temporaryDirectory) + public static void SaveNca(Nca nca, string ncaId, string temporaryDirectory) { string newPath = Path.Combine(temporaryDirectory, ncaId + ".nca"); Directory.CreateDirectory(newPath); - using (FileStream file = File.Create(Path.Combine(newPath, "00"))) - { - nca.BaseStorage.AsStream().CopyTo(file); - } + using FileStream file = File.Create(Path.Combine(newPath, "00")); + nca.BaseStorage.AsStream().CopyTo(file); } - private IFile OpenPossibleFragmentedFile(IFileSystem filesystem, string path, OpenMode mode) + private static IFile OpenPossibleFragmentedFile(IFileSystem filesystem, string path, OpenMode mode) { using var file = new UniqueRef(); @@ -636,14 +615,12 @@ namespace Ryujinx.HLE.FileSystem return file.Release(); } - private Stream GetZipStream(ZipArchiveEntry entry) + private static Stream GetZipStream(ZipArchiveEntry entry) { MemoryStream dest = MemoryStreamManager.Shared.GetStream(); - using (Stream src = entry.Open()) - { - src.CopyTo(dest); - } + using Stream src = entry.Open(); + src.CopyTo(dest); return dest; } @@ -659,7 +636,7 @@ namespace Ryujinx.HLE.FileSystem throw new MissingKeyException("HeaderKey is empty. Cannot decrypt NCA headers."); } - Dictionary> updateNcas = new Dictionary>(); + Dictionary> updateNcas = new(); if (Directory.Exists(firmwarePackage)) { @@ -671,33 +648,32 @@ namespace Ryujinx.HLE.FileSystem throw new FileNotFoundException("Firmware file does not exist."); } - FileInfo info = new FileInfo(firmwarePackage); + FileInfo info = new(firmwarePackage); - using (FileStream file = File.OpenRead(firmwarePackage)) + using FileStream file = File.OpenRead(firmwarePackage); + + switch (info.Extension) { - switch (info.Extension) - { - case ".zip": - using (ZipArchive archive = ZipFile.OpenRead(firmwarePackage)) - { - return VerifyAndGetVersionZip(archive); - } - case ".xci": - Xci xci = new Xci(_virtualFileSystem.KeySet, file.AsStorage()); + case ".zip": + using (ZipArchive archive = ZipFile.OpenRead(firmwarePackage)) + { + return VerifyAndGetVersionZip(archive); + } + case ".xci": + Xci xci = new(_virtualFileSystem.KeySet, file.AsStorage()); - if (xci.HasPartition(XciPartitionType.Update)) - { - XciPartition partition = xci.OpenPartition(XciPartitionType.Update); + if (xci.HasPartition(XciPartitionType.Update)) + { + XciPartition partition = xci.OpenPartition(XciPartitionType.Update); - return VerifyAndGetVersion(partition); - } - else - { - throw new InvalidFirmwarePackageException("Update not found in xci file."); - } - default: - break; - } + return VerifyAndGetVersion(partition); + } + else + { + throw new InvalidFirmwarePackageException("Update not found in xci file."); + } + default: + break; } SystemVersion VerifyAndGetVersionDirectory(string firmwareDirectory) @@ -713,21 +689,19 @@ namespace Ryujinx.HLE.FileSystem { if (entry.FullName.EndsWith(".nca") || entry.FullName.EndsWith(".nca/00")) { - using (Stream ncaStream = GetZipStream(entry)) + using Stream ncaStream = GetZipStream(entry); + IStorage storage = ncaStream.AsStorage(); + + Nca nca = new(_virtualFileSystem.KeySet, storage); + + if (updateNcas.TryGetValue(nca.Header.TitleId, out var updateNcasItem)) { - IStorage storage = ncaStream.AsStorage(); - - Nca nca = new Nca(_virtualFileSystem.KeySet, storage); - - if (updateNcas.TryGetValue(nca.Header.TitleId, out var updateNcasItem)) - { - updateNcasItem.Add((nca.Header.ContentType, entry.FullName)); - } - else - { - updateNcas.Add(nca.Header.TitleId, new List<(NcaContentType, string)>()); - updateNcas[nca.Header.TitleId].Add((nca.Header.ContentType, entry.FullName)); - } + updateNcasItem.Add((nca.Header.ContentType, entry.FullName)); + } + else + { + updateNcas.Add(nca.Header.TitleId, new List<(NcaContentType, string)>()); + updateNcas[nca.Header.TitleId].Add((nca.Header.ContentType, entry.FullName)); } } } @@ -742,7 +716,7 @@ namespace Ryujinx.HLE.FileSystem using (Stream ncaStream = GetZipStream(fileEntry)) { - Nca metaNca = new Nca(_virtualFileSystem.KeySet, ncaStream.AsStorage()); + Nca metaNca = new(_virtualFileSystem.KeySet, ncaStream.AsStorage()); IFileSystem fs = metaNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); @@ -772,18 +746,16 @@ namespace Ryujinx.HLE.FileSystem { string versionEntry = updateNcasItem.Find(x => x.type != NcaContentType.Meta).path; - using (Stream ncaStream = GetZipStream(archive.GetEntry(versionEntry))) + using Stream ncaStream = GetZipStream(archive.GetEntry(versionEntry)); + Nca nca = new(_virtualFileSystem.KeySet, ncaStream.AsStorage()); + + var romfs = nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); + + using var systemVersionFile = new UniqueRef(); + + if (romfs.OpenFile(ref systemVersionFile.Ref, "/file".ToU8Span(), OpenMode.Read).IsSuccess()) { - Nca nca = new Nca(_virtualFileSystem.KeySet, ncaStream.AsStorage()); - - var romfs = nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); - - using var systemVersionFile = new UniqueRef(); - - if (romfs.OpenFile(ref systemVersionFile.Ref, "/file".ToU8Span(), OpenMode.Read).IsSuccess()) - { - systemVersion = new SystemVersion(systemVersionFile.Get.AsStream()); - } + systemVersion = new SystemVersion(systemVersionFile.Get.AsStream()); } } @@ -804,43 +776,39 @@ namespace Ryujinx.HLE.FileSystem continue; } - ZipArchiveEntry metaZipEntry = archive.GetEntry(metaPath); + ZipArchiveEntry metaZipEntry = archive.GetEntry(metaPath); ZipArchiveEntry contentZipEntry = archive.GetEntry(contentPath); - using (Stream metaNcaStream = GetZipStream(metaZipEntry)) + using Stream metaNcaStream = GetZipStream(metaZipEntry); + using Stream contentNcaStream = GetZipStream(contentZipEntry); + Nca metaNca = new(_virtualFileSystem.KeySet, metaNcaStream.AsStorage()); + + IFileSystem fs = metaNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); + + string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath; + + using var metaFile = new UniqueRef(); + + if (fs.OpenFile(ref metaFile.Ref, cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess()) { - using (Stream contentNcaStream = GetZipStream(contentZipEntry)) + var meta = new Cnmt(metaFile.Get.AsStream()); + + IStorage contentStorage = contentNcaStream.AsStorage(); + if (contentStorage.GetSize(out long size).IsSuccess()) { - Nca metaNca = new Nca(_virtualFileSystem.KeySet, metaNcaStream.AsStorage()); + byte[] contentData = new byte[size]; - IFileSystem fs = metaNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); + Span content = new(contentData); - string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath; + contentStorage.Read(0, content); - using var metaFile = new UniqueRef(); + Span hash = new(new byte[32]); - if (fs.OpenFile(ref metaFile.Ref, cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess()) + LibHac.Crypto.Sha256.GenerateSha256Hash(content, hash); + + if (LibHac.Common.Utilities.ArraysEqual(hash.ToArray(), meta.ContentEntries[0].Hash)) { - var meta = new Cnmt(metaFile.Get.AsStream()); - - IStorage contentStorage = contentNcaStream.AsStorage(); - if (contentStorage.GetSize(out long size).IsSuccess()) - { - byte[] contentData = new byte[size]; - - Span content = new Span(contentData); - - contentStorage.Read(0, content); - - Span hash = new Span(new byte[32]); - - LibHac.Crypto.Sha256.GenerateSha256Hash(content, hash); - - if (LibHac.Common.Utilities.ArraysEqual(hash.ToArray(), meta.ContentEntries[0].Hash)) - { - updateNcas.Remove(metaEntry.TitleId); - } - } + updateNcas.Remove(metaEntry.TitleId); } } } @@ -853,9 +821,9 @@ namespace Ryujinx.HLE.FileSystem foreach (var entry in updateNcas) { - foreach (var nca in entry.Value) + foreach (var (type, path) in entry.Value) { - extraNcas += nca.path + Environment.NewLine; + extraNcas += path + Environment.NewLine; } } @@ -880,7 +848,7 @@ namespace Ryujinx.HLE.FileSystem { IStorage ncaStorage = OpenPossibleFragmentedFile(filesystem, entry.FullPath, OpenMode.Read).AsStorage(); - Nca nca = new Nca(_virtualFileSystem.KeySet, ncaStorage); + Nca nca = new(_virtualFileSystem.KeySet, ncaStorage); if (nca.Header.TitleId == SystemUpdateTitleId && nca.Header.ContentType == NcaContentType.Meta) { @@ -936,8 +904,8 @@ namespace Ryujinx.HLE.FileSystem { if (updateNcas.TryGetValue(metaEntry.TitleId, out var ncaEntry)) { - var metaNcaEntry = ncaEntry.Find(x => x.type == NcaContentType.Meta); - string contentPath = ncaEntry.Find(x => x.type != NcaContentType.Meta).path; + string metaNcaPath = ncaEntry.Find(x => x.type == NcaContentType.Meta).path; + string contentPath = ncaEntry.Find(x => x.type != NcaContentType.Meta).path; // Nintendo in 9.0.0, removed PPC and only kept the meta nca of it. // This is a perfect valid case, so we should just ignore the missing content nca and continue. @@ -948,10 +916,10 @@ namespace Ryujinx.HLE.FileSystem continue; } - IStorage metaStorage = OpenPossibleFragmentedFile(filesystem, metaNcaEntry.path, OpenMode.Read).AsStorage(); + IStorage metaStorage = OpenPossibleFragmentedFile(filesystem, metaNcaPath, OpenMode.Read).AsStorage(); IStorage contentStorage = OpenPossibleFragmentedFile(filesystem, contentPath, OpenMode.Read).AsStorage(); - Nca metaNca = new Nca(_virtualFileSystem.KeySet, metaStorage); + Nca metaNca = new(_virtualFileSystem.KeySet, metaStorage); IFileSystem fs = metaNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); @@ -967,11 +935,11 @@ namespace Ryujinx.HLE.FileSystem { byte[] contentData = new byte[size]; - Span content = new Span(contentData); + Span content = new(contentData); contentStorage.Read(0, content); - Span hash = new Span(new byte[32]); + Span hash = new(new byte[32]); LibHac.Crypto.Sha256.GenerateSha256Hash(content, hash); @@ -1017,24 +985,21 @@ namespace Ryujinx.HLE.FileSystem { if (entry.ContentType == NcaContentType.Data) { - var path = _virtualFileSystem.SwitchPathToSystemPath(entry.ContentPath); + var path = VirtualFileSystem.SwitchPathToSystemPath(entry.ContentPath); - using (FileStream fileStream = File.OpenRead(path)) + using FileStream fileStream = File.OpenRead(path); + Nca nca = new(_virtualFileSystem.KeySet, fileStream.AsStorage()); + + if (nca.Header.TitleId == SystemVersionTitleId && nca.Header.ContentType == NcaContentType.Data) { - Nca nca = new Nca(_virtualFileSystem.KeySet, fileStream.AsStorage()); + var romfs = nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); - if (nca.Header.TitleId == SystemVersionTitleId && nca.Header.ContentType == NcaContentType.Data) + using var systemVersionFile = new UniqueRef(); + + if (romfs.OpenFile(ref systemVersionFile.Ref, "/file".ToU8Span(), OpenMode.Read).IsSuccess()) { - var romfs = nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); - - using var systemVersionFile = new UniqueRef(); - - if (romfs.OpenFile(ref systemVersionFile.Ref, "/file".ToU8Span(), OpenMode.Read).IsSuccess()) - { - return new SystemVersion(systemVersionFile.Get.AsStream()); - } + return new SystemVersion(systemVersionFile.Get.AsStream()); } - } } } diff --git a/src/Ryujinx.HLE/FileSystem/ContentPath.cs b/src/Ryujinx.HLE/FileSystem/ContentPath.cs index c8663081a..6d2f3f6ab 100644 --- a/src/Ryujinx.HLE/FileSystem/ContentPath.cs +++ b/src/Ryujinx.HLE/FileSystem/ContentPath.cs @@ -2,7 +2,6 @@ using LibHac.Ncm; using Ryujinx.Common.Configuration; using System; - using static Ryujinx.HLE.FileSystem.VirtualFileSystem; using Path = System.IO.Path; @@ -10,33 +9,33 @@ namespace Ryujinx.HLE.FileSystem { internal static class ContentPath { - public const string SystemContent = "@SystemContent"; - public const string UserContent = "@UserContent"; - public const string SdCardContent = "@SdCardContent"; - public const string SdCard = "@Sdcard"; - public const string CalibFile = "@CalibFile"; - public const string Safe = "@Safe"; - public const string User = "@User"; - public const string System = "@System"; - public const string Host = "@Host"; - public const string GamecardApp = "@GcApp"; + public const string SystemContent = "@SystemContent"; + public const string UserContent = "@UserContent"; + public const string SdCardContent = "@SdCardContent"; + public const string SdCard = "@Sdcard"; + public const string CalibFile = "@CalibFile"; + public const string Safe = "@Safe"; + public const string User = "@User"; + public const string System = "@System"; + public const string Host = "@Host"; + public const string GamecardApp = "@GcApp"; public const string GamecardContents = "@GcS00000001"; - public const string GamecardUpdate = "@upp"; + public const string GamecardUpdate = "@upp"; public const string RegisteredUpdate = "@RegUpdate"; public const string Nintendo = "Nintendo"; public const string Contents = "Contents"; - public static string GetRealPath(VirtualFileSystem fileSystem, string switchContentPath) + public static string GetRealPath(string switchContentPath) { return switchContentPath switch { SystemContent => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath, Contents), - UserContent => Path.Combine(AppDataManager.BaseDirPath, UserNandPath, Contents), - SdCardContent => Path.Combine(fileSystem.GetSdCardPath(), Nintendo, Contents), - System => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath), - User => Path.Combine(AppDataManager.BaseDirPath, UserNandPath), - _ => throw new NotSupportedException($"Content Path \"`{switchContentPath}`\" is not supported.") + UserContent => Path.Combine(AppDataManager.BaseDirPath, UserNandPath, Contents), + SdCardContent => Path.Combine(GetSdCardPath(), Nintendo, Contents), + System => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath), + User => Path.Combine(AppDataManager.BaseDirPath, UserNandPath), + _ => throw new NotSupportedException($"Content Path \"`{switchContentPath}`\" is not supported."), }; } @@ -45,9 +44,9 @@ namespace Ryujinx.HLE.FileSystem return contentStorageId switch { ContentStorageId.System => SystemContent, - ContentStorageId.User => UserContent, + ContentStorageId.User => UserContent, ContentStorageId.SdCard => SdCardContent, - _ => throw new NotSupportedException($"Content Storage Id \"`{contentStorageId}`\" is not supported.") + _ => throw new NotSupportedException($"Content Storage Id \"`{contentStorageId}`\" is not supported."), }; } @@ -56,9 +55,9 @@ namespace Ryujinx.HLE.FileSystem return storageId switch { StorageId.BuiltInSystem => SystemContent, - StorageId.BuiltInUser => UserContent, - StorageId.SdCard => SdCardContent, - _ => throw new NotSupportedException($"Storage Id \"`{storageId}`\" is not supported.") + StorageId.BuiltInUser => UserContent, + StorageId.SdCard => SdCardContent, + _ => throw new NotSupportedException($"Storage Id \"`{storageId}`\" is not supported."), }; } @@ -67,16 +66,16 @@ namespace Ryujinx.HLE.FileSystem return contentPathString.Split(':')[0] switch { SystemContent or - System => StorageId.BuiltInSystem, + System => StorageId.BuiltInSystem, UserContent or - User => StorageId.BuiltInUser, - SdCardContent => StorageId.SdCard, - Host => StorageId.Host, + User => StorageId.BuiltInUser, + SdCardContent => StorageId.SdCard, + Host => StorageId.Host, GamecardApp or GamecardContents or GamecardUpdate => StorageId.GameCard, - _ => StorageId.None + _ => StorageId.None, }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs b/src/Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs index f32dc2d77..d50b80ffb 100644 --- a/src/Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs +++ b/src/Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs @@ -23,4 +23,4 @@ namespace Ryujinx.HLE.FileSystem return Result.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/FileSystem/LocationEntry.cs b/src/Ryujinx.HLE/FileSystem/LocationEntry.cs index a60c28967..dd4068aab 100644 --- a/src/Ryujinx.HLE/FileSystem/LocationEntry.cs +++ b/src/Ryujinx.HLE/FileSystem/LocationEntry.cs @@ -4,16 +4,16 @@ namespace Ryujinx.HLE.FileSystem { public struct LocationEntry { - public string ContentPath { get; private set; } - public int Flag { get; private set; } - public ulong TitleId { get; private set; } + public string ContentPath { get; private set; } + public int Flag { get; private set; } + public ulong TitleId { get; private set; } public NcaContentType ContentType { get; private set; } public LocationEntry(string contentPath, int flag, ulong titleId, NcaContentType contentType) { ContentPath = contentPath; - Flag = flag; - TitleId = titleId; + Flag = flag; + TitleId = titleId; ContentType = contentType; } diff --git a/src/Ryujinx.HLE/FileSystem/SystemVersion.cs b/src/Ryujinx.HLE/FileSystem/SystemVersion.cs index a7926d5d3..bd64d7f2e 100644 --- a/src/Ryujinx.HLE/FileSystem/SystemVersion.cs +++ b/src/Ryujinx.HLE/FileSystem/SystemVersion.cs @@ -5,36 +5,34 @@ namespace Ryujinx.HLE.FileSystem { public class SystemVersion { - public byte Major { get; } - public byte Minor { get; } - public byte Micro { get; } - public byte RevisionMajor { get; } - public byte RevisionMinor { get; } + public byte Major { get; } + public byte Minor { get; } + public byte Micro { get; } + public byte RevisionMajor { get; } + public byte RevisionMinor { get; } public string PlatformString { get; } - public string Hex { get; } - public string VersionString { get; } - public string VersionTitle { get; } + public string Hex { get; } + public string VersionString { get; } + public string VersionTitle { get; } public SystemVersion(Stream systemVersionFile) { - using (BinaryReader reader = new BinaryReader(systemVersionFile)) - { - Major = reader.ReadByte(); - Minor = reader.ReadByte(); - Micro = reader.ReadByte(); + using BinaryReader reader = new(systemVersionFile); + Major = reader.ReadByte(); + Minor = reader.ReadByte(); + Micro = reader.ReadByte(); - reader.ReadByte(); // Padding + reader.ReadByte(); // Padding - RevisionMajor = reader.ReadByte(); - RevisionMinor = reader.ReadByte(); + RevisionMajor = reader.ReadByte(); + RevisionMinor = reader.ReadByte(); - reader.ReadBytes(2); // Padding + reader.ReadBytes(2); // Padding - PlatformString = StringUtils.ReadInlinedAsciiString(reader, 0x20); - Hex = StringUtils.ReadInlinedAsciiString(reader, 0x40); - VersionString = StringUtils.ReadInlinedAsciiString(reader, 0x18); - VersionTitle = StringUtils.ReadInlinedAsciiString(reader, 0x80); - } + PlatformString = StringUtils.ReadInlinedAsciiString(reader, 0x20); + Hex = StringUtils.ReadInlinedAsciiString(reader, 0x40); + VersionString = StringUtils.ReadInlinedAsciiString(reader, 0x18); + VersionTitle = StringUtils.ReadInlinedAsciiString(reader, 0x80); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs b/src/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs index 83604b420..807020c60 100644 --- a/src/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs +++ b/src/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs @@ -26,14 +26,14 @@ namespace Ryujinx.HLE.FileSystem { public class VirtualFileSystem : IDisposable { - public static string SafeNandPath = Path.Combine(AppDataManager.DefaultNandDir, "safe"); - public static string SystemNandPath = Path.Combine(AppDataManager.DefaultNandDir, "system"); - public static string UserNandPath = Path.Combine(AppDataManager.DefaultNandDir, "user"); + public static readonly string SafeNandPath = Path.Combine(AppDataManager.DefaultNandDir, "safe"); + public static readonly string SystemNandPath = Path.Combine(AppDataManager.DefaultNandDir, "system"); + public static readonly string UserNandPath = Path.Combine(AppDataManager.DefaultNandDir, "user"); - public KeySet KeySet { get; private set; } - public EmulatedGameCard GameCard { get; private set; } - public EmulatedSdCard SdCard { get; private set; } - public ModLoader ModLoader { get; private set; } + public KeySet KeySet { get; private set; } + public EmulatedGameCard GameCard { get; private set; } + public EmulatedSdCard SdCard { get; private set; } + public ModLoader ModLoader { get; private set; } private readonly ConcurrentDictionary _romFsByPid; @@ -85,15 +85,15 @@ namespace Ryujinx.HLE.FileSystem return _romFsByPid[pid]; } - public string GetFullPath(string basePath, string fileName) + public static string GetFullPath(string basePath, string fileName) { if (fileName.StartsWith("//")) { - fileName = fileName.Substring(2); + fileName = fileName[2..]; } else if (fileName.StartsWith('/')) { - fileName = fileName.Substring(1); + fileName = fileName[1..]; } else { @@ -110,10 +110,10 @@ namespace Ryujinx.HLE.FileSystem return fullPath; } - internal string GetSdCardPath() => MakeFullPath(AppDataManager.DefaultSdcardDir); - public string GetNandPath() => MakeFullPath(AppDataManager.DefaultNandDir); + internal static string GetSdCardPath() => MakeFullPath(AppDataManager.DefaultSdcardDir); + public static string GetNandPath() => MakeFullPath(AppDataManager.DefaultNandDir); - public string SwitchPathToSystemPath(string switchPath) + public static string SwitchPathToSystemPath(string switchPath) { string[] parts = switchPath.Split(":"); @@ -125,7 +125,7 @@ namespace Ryujinx.HLE.FileSystem return GetFullPath(MakeFullPath(parts[0]), parts[1]); } - public string SystemPathToSwitchPath(string systemPath) + public static string SystemPathToSwitchPath(string systemPath) { string baseSystemPath = AppDataManager.BaseDirPath + Path.DirectorySeparatorChar; @@ -148,7 +148,7 @@ namespace Ryujinx.HLE.FileSystem return null; } - private string MakeFullPath(string path, bool isDirectory = true) + private static string MakeFullPath(string path, bool isDirectory = true) { // Handles Common Switch Content Paths switch (path) @@ -185,7 +185,7 @@ namespace Ryujinx.HLE.FileSystem public void InitializeFsServer(LibHac.Horizon horizon, out HorizonClient fsServerClient) { - LocalFileSystem serverBaseFs = new LocalFileSystem(AppDataManager.BaseDirPath); + LocalFileSystem serverBaseFs = new(AppDataManager.BaseDirPath); fsServerClient = horizon.CreatePrivilegedHorizonClient(); var fsServer = new FileSystemServer(fsServerClient); @@ -207,7 +207,7 @@ namespace Ryujinx.HLE.FileSystem DeviceOperator = fsServerObjects.DeviceOperator, ExternalKeySet = KeySet.ExternalKeySet, FsCreators = fsServerObjects.FsCreators, - RandomGenerator = randomGenerator + RandomGenerator = randomGenerator, }; FileSystemServerInitializer.InitializeWithConfig(fsServerClient, fsServer, fsServerConfig); @@ -282,16 +282,28 @@ namespace Ryujinx.HLE.FileSystem public static Result FixExtraData(HorizonClient hos) { Result rc = GetSystemSaveList(hos, out List systemSaveIds); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } rc = FixUnindexedSystemSaves(hos, systemSaveIds); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } rc = FixExtraDataInSpaceId(hos, SaveDataSpaceId.System); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } rc = FixExtraDataInSpaceId(hos, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } return Result.Success; } @@ -303,15 +315,23 @@ namespace Ryujinx.HLE.FileSystem using var iterator = new UniqueRef(); Result rc = hos.Fs.OpenSaveDataIterator(ref iterator.Ref, spaceId); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } while (true) { rc = iterator.Get.ReadSaveDataInfo(out long count, info); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } if (count == 0) + { return Result.Success; + } for (int i = 0; i < count; i++) { @@ -351,7 +371,9 @@ namespace Ryujinx.HLE.FileSystem private static Result CreateSaveDataDirectory(HorizonClient hos, in SaveDataInfo info) { if (info.SpaceId != SaveDataSpaceId.User && info.SpaceId != SaveDataSpaceId.System) + { return Result.Success; + } const string MountName = "SaveDir"; var mountNameU8 = MountName.ToU8Span(); @@ -360,11 +382,15 @@ namespace Ryujinx.HLE.FileSystem { SaveDataSpaceId.System => BisPartitionId.System, SaveDataSpaceId.User => BisPartitionId.User, - _ => throw new ArgumentOutOfRangeException() + _ => throw new ArgumentOutOfRangeException(nameof(info), info.SpaceId, null), }; Result rc = hos.Fs.MountBis(mountNameU8, partitionId); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } + try { var path = $"{MountName}:/save/{info.SaveDataId:x16}".ToU8Span(); @@ -391,28 +417,38 @@ namespace Ryujinx.HLE.FileSystem var mountName = "system".ToU8Span(); DirectoryHandle handle = default; - List localList = new List(); + List localList = new(); try { Result rc = hos.Fs.MountBis(mountName, BisPartitionId.System); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } rc = hos.Fs.OpenDirectory(out handle, "system:/save".ToU8Span(), OpenDirectoryMode.All); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } - DirectoryEntry entry = new DirectoryEntry(); + DirectoryEntry entry = new(); while (true) { rc = hos.Fs.ReadDirectory(out long readCount, SpanHelpers.AsSpan(ref entry), handle); - if (rc.IsFailure()) return rc; + if (rc.IsFailure()) + { + return rc; + } if (readCount == 0) + { break; + } - if (Utf8Parser.TryParse(entry.Name, out ulong saveDataId, out int bytesRead, 'x') && - bytesRead == 16 && (long)saveDataId < 0) + if (Utf8Parser.TryParse(entry.Name, out ulong saveDataId, out int bytesRead, 'x') && bytesRead == 16 && (long)saveDataId < 0) { localList.Add(saveDataId); } @@ -440,7 +476,7 @@ namespace Ryujinx.HLE.FileSystem // Only save data IDs added to SystemExtraDataFixInfo will be fixed. private static Result FixUnindexedSystemSaves(HorizonClient hos, List existingSaveIds) { - foreach (var fixInfo in SystemExtraDataFixInfo) + foreach (var fixInfo in _systemExtraDataFixInfo) { if (!existingSaveIds.Contains(fixInfo.StaticSaveDataId)) { @@ -472,7 +508,9 @@ namespace Ryujinx.HLE.FileSystem if (!rc.IsSuccess()) { if (!ResultFs.TargetNotFound.Includes(rc)) + { return rc; + } // We'll reach this point only if the save data directory exists but it's not in the save data indexer. // Creating the save will add it to the indexer while leaving its existing contents intact. @@ -492,7 +530,7 @@ namespace Ryujinx.HLE.FileSystem OwnerId = info.OwnerId, Flags = info.Flags, DataSize = info.DataSize, - JournalSize = info.JournalSize + JournalSize = info.JournalSize, }; // Make a mask for writing the entire extra data @@ -507,9 +545,11 @@ namespace Ryujinx.HLE.FileSystem { wasFixNeeded = true; - Result rc = hos.Fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, info.SpaceId, - info.SaveDataId); - if (rc.IsFailure()) return rc; + Result rc = hos.Fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, info.SpaceId, info.SaveDataId); + if (rc.IsFailure()) + { + return rc; + } // The extra data should have program ID or static save data ID set if it's valid. // We only try to fix the extra data if the info from the save data indexer has a program ID or static save data ID. @@ -543,7 +583,7 @@ namespace Ryujinx.HLE.FileSystem else { // Try to match the system save with one of the known saves - foreach (ExtraDataFixInfo fixInfo in SystemExtraDataFixInfo) + foreach (ExtraDataFixInfo fixInfo in _systemExtraDataFixInfo) { if (extraData.Attribute.StaticSaveDataId == fixInfo.StaticSaveDataId) { @@ -573,7 +613,7 @@ namespace Ryujinx.HLE.FileSystem public long JournalSize; } - private static readonly ExtraDataFixInfo[] SystemExtraDataFixInfo = + private static readonly ExtraDataFixInfo[] _systemExtraDataFixInfo = { new ExtraDataFixInfo() { @@ -581,7 +621,7 @@ namespace Ryujinx.HLE.FileSystem OwnerId = 0x010000000000001F, Flags = SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData, DataSize = 0x10000, - JournalSize = 0x10000 + JournalSize = 0x10000, }, new ExtraDataFixInfo() { @@ -589,12 +629,13 @@ namespace Ryujinx.HLE.FileSystem OwnerId = 0x0100000000001009, Flags = SaveDataFlags.None, DataSize = 0xC000, - JournalSize = 0xC000 - } + JournalSize = 0xC000, + }, }; public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } diff --git a/src/Ryujinx.HLE/HLEConfiguration.cs b/src/Ryujinx.HLE/HLEConfiguration.cs index df8dea6d6..22477a8c0 100644 --- a/src/Ryujinx.HLE/HLEConfiguration.cs +++ b/src/Ryujinx.HLE/HLEConfiguration.cs @@ -163,57 +163,57 @@ namespace Ryujinx.HLE /// public Action RefreshInputConfig { internal get; set; } - public HLEConfiguration(VirtualFileSystem virtualFileSystem, - LibHacHorizonManager libHacHorizonManager, - ContentManager contentManager, - AccountManager accountManager, + public HLEConfiguration(VirtualFileSystem virtualFileSystem, + LibHacHorizonManager libHacHorizonManager, + ContentManager contentManager, + AccountManager accountManager, UserChannelPersistence userChannelPersistence, - IRenderer gpuRenderer, - IHardwareDeviceDriver audioDeviceDriver, - MemoryConfiguration memoryConfiguration, - IHostUiHandler hostUiHandler, - SystemLanguage systemLanguage, - RegionCode region, - bool enableVsync, - bool enableDockedMode, - bool enablePtc, - bool enableInternetAccess, - IntegrityCheckLevel fsIntegrityCheckLevel, - int fsGlobalAccessLogMode, - long systemTimeOffset, - string timeZone, - MemoryManagerMode memoryManagerMode, - bool ignoreMissingServices, - AspectRatio aspectRatio, - float audioVolume, - bool useHypervisor, - string multiplayerLanInterfaceId) + IRenderer gpuRenderer, + IHardwareDeviceDriver audioDeviceDriver, + MemoryConfiguration memoryConfiguration, + IHostUiHandler hostUiHandler, + SystemLanguage systemLanguage, + RegionCode region, + bool enableVsync, + bool enableDockedMode, + bool enablePtc, + bool enableInternetAccess, + IntegrityCheckLevel fsIntegrityCheckLevel, + int fsGlobalAccessLogMode, + long systemTimeOffset, + string timeZone, + MemoryManagerMode memoryManagerMode, + bool ignoreMissingServices, + AspectRatio aspectRatio, + float audioVolume, + bool useHypervisor, + string multiplayerLanInterfaceId) { - VirtualFileSystem = virtualFileSystem; - LibHacHorizonManager = libHacHorizonManager; - AccountManager = accountManager; - ContentManager = contentManager; - UserChannelPersistence = userChannelPersistence; - GpuRenderer = gpuRenderer; - AudioDeviceDriver = audioDeviceDriver; - MemoryConfiguration = memoryConfiguration; - HostUiHandler = hostUiHandler; - SystemLanguage = systemLanguage; - Region = region; - EnableVsync = enableVsync; - EnableDockedMode = enableDockedMode; - EnablePtc = enablePtc; - EnableInternetAccess = enableInternetAccess; - FsIntegrityCheckLevel = fsIntegrityCheckLevel; - FsGlobalAccessLogMode = fsGlobalAccessLogMode; - SystemTimeOffset = systemTimeOffset; - TimeZone = timeZone; - MemoryManagerMode = memoryManagerMode; - IgnoreMissingServices = ignoreMissingServices; - AspectRatio = aspectRatio; - AudioVolume = audioVolume; - UseHypervisor = useHypervisor; + VirtualFileSystem = virtualFileSystem; + LibHacHorizonManager = libHacHorizonManager; + AccountManager = accountManager; + ContentManager = contentManager; + UserChannelPersistence = userChannelPersistence; + GpuRenderer = gpuRenderer; + AudioDeviceDriver = audioDeviceDriver; + MemoryConfiguration = memoryConfiguration; + HostUiHandler = hostUiHandler; + SystemLanguage = systemLanguage; + Region = region; + EnableVsync = enableVsync; + EnableDockedMode = enableDockedMode; + EnablePtc = enablePtc; + EnableInternetAccess = enableInternetAccess; + FsIntegrityCheckLevel = fsIntegrityCheckLevel; + FsGlobalAccessLogMode = fsGlobalAccessLogMode; + SystemTimeOffset = systemTimeOffset; + TimeZone = timeZone; + MemoryManagerMode = memoryManagerMode; + IgnoreMissingServices = ignoreMissingServices; + AspectRatio = aspectRatio; + AudioVolume = audioVolume; + UseHypervisor = useHypervisor; MultiplayerLanInterfaceId = multiplayerLanInterfaceId; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/AppletManager.cs b/src/Ryujinx.HLE/HOS/Applets/AppletManager.cs index a686a8328..93d49cd24 100644 --- a/src/Ryujinx.HLE/HOS/Applets/AppletManager.cs +++ b/src/Ryujinx.HLE/HOS/Applets/AppletManager.cs @@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Applets { static class AppletManager { - private static Dictionary _appletMapping; + private static readonly Dictionary _appletMapping; static AppletManager() { @@ -20,7 +20,7 @@ namespace Ryujinx.HLE.HOS.Applets { AppletId.SoftwareKeyboard, typeof(SoftwareKeyboardApplet) }, { AppletId.LibAppletWeb, typeof(BrowserApplet) }, { AppletId.LibAppletShop, typeof(BrowserApplet) }, - { AppletId.LibAppletOff, typeof(BrowserApplet) } + { AppletId.LibAppletOff, typeof(BrowserApplet) }, }; } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/BootDisplayKind.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/BootDisplayKind.cs index fe6e60400..11c1cb912 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/BootDisplayKind.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/BootDisplayKind.cs @@ -6,6 +6,6 @@ Offline, Black, Share, - Lobby + Lobby, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserApplet.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserApplet.cs index 952afcd5f..f50e6448f 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserApplet.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserApplet.cs @@ -13,13 +13,12 @@ namespace Ryujinx.HLE.HOS.Applets.Browser public event EventHandler AppletStateChanged; private AppletSession _normalSession; - private AppletSession _interactiveSession; private CommonArguments _commonArguments; private List _arguments; private ShimKind _shimKind; - public BrowserApplet(Horizon system) {} + public BrowserApplet(Horizon system) { } public ResultCode GetResult() { @@ -29,7 +28,6 @@ namespace Ryujinx.HLE.HOS.Applets.Browser public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession) { _normalSession = normalSession; - _interactiveSession = interactiveSession; _commonArguments = IApplet.ReadStruct(_normalSession.Pop()); @@ -48,17 +46,18 @@ namespace Ryujinx.HLE.HOS.Applets.Browser if ((_commonArguments.AppletVersion >= 0x80000 && _shimKind == ShimKind.Web) || (_commonArguments.AppletVersion >= 0x30000 && _shimKind == ShimKind.Share)) { - List result = new List(); - - result.Add(new BrowserOutput(BrowserOutputType.ExitReason, (uint)WebExitReason.ExitButton)); + List result = new() + { + new BrowserOutput(BrowserOutputType.ExitReason, (uint)WebExitReason.ExitButton), + }; _normalSession.Push(BuildResponseNew(result)); } else { - WebCommonReturnValue result = new WebCommonReturnValue() + WebCommonReturnValue result = new() { - ExitReason = WebExitReason.ExitButton, + ExitReason = WebExitReason.ExitButton, }; _normalSession.Push(BuildResponseOld(result)); @@ -69,36 +68,32 @@ namespace Ryujinx.HLE.HOS.Applets.Browser return ResultCode.Success; } - private byte[] BuildResponseOld(WebCommonReturnValue result) + private static byte[] BuildResponseOld(WebCommonReturnValue result) { - using (MemoryStream stream = MemoryStreamManager.Shared.GetStream()) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - writer.WriteStruct(result); + using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); + using BinaryWriter writer = new(stream); + writer.WriteStruct(result); - return stream.ToArray(); - } + return stream.ToArray(); } private byte[] BuildResponseNew(List outputArguments) { - using (MemoryStream stream = MemoryStreamManager.Shared.GetStream()) - using (BinaryWriter writer = new BinaryWriter(stream)) + using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); + using BinaryWriter writer = new(stream); + writer.WriteStruct(new WebArgHeader { - writer.WriteStruct(new WebArgHeader - { - Count = (ushort)outputArguments.Count, - ShimKind = _shimKind - }); + Count = (ushort)outputArguments.Count, + ShimKind = _shimKind, + }); - foreach (BrowserOutput output in outputArguments) - { - output.Write(writer); - } - - writer.Write(new byte[0x2000 - writer.BaseStream.Position]); - - return stream.ToArray(); + foreach (BrowserOutput output in outputArguments) + { + output.Write(writer); } + + writer.Write(new byte[0x2000 - writer.BaseStream.Position]); + + return stream.ToArray(); } } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserArgument.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserArgument.cs index 17fd40898..708781bf3 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserArgument.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserArgument.cs @@ -8,16 +8,16 @@ namespace Ryujinx.HLE.HOS.Applets.Browser { class BrowserArgument { - public WebArgTLVType Type { get; } - public byte[] Value { get; } + public WebArgTLVType Type { get; } + public byte[] Value { get; } public BrowserArgument(WebArgTLVType type, byte[] value) { - Type = type; + Type = type; Value = value; } - private static readonly Dictionary _typeRegistry = new Dictionary + private static readonly Dictionary _typeRegistry = new() { { WebArgTLVType.InitialURL, typeof(string) }, { WebArgTLVType.CallbackUrl, typeof(string) }, @@ -64,11 +64,11 @@ namespace Ryujinx.HLE.HOS.Applets.Browser public static (ShimKind, List) ParseArguments(ReadOnlySpan data) { - List browserArguments = new List(); + List browserArguments = new(); - WebArgHeader header = IApplet.ReadStruct(data.Slice(0, 8)); + WebArgHeader header = IApplet.ReadStruct(data[..8]); - ReadOnlySpan rawTLVs = data.Slice(8); + ReadOnlySpan rawTLVs = data[8..]; for (int i = 0; i < header.Count; i++) { @@ -77,7 +77,7 @@ namespace Ryujinx.HLE.HOS.Applets.Browser browserArguments.Add(new BrowserArgument((WebArgTLVType)tlv.Type, tlvData.ToArray())); - rawTLVs = rawTLVs.Slice(Unsafe.SizeOf() + tlv.Size); + rawTLVs = rawTLVs[(Unsafe.SizeOf() + tlv.Size)..]; } return (header.ShimKind, browserArguments); diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserOutput.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserOutput.cs index 0b3682627..443886fde 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserOutput.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserOutput.cs @@ -11,25 +11,25 @@ namespace Ryujinx.HLE.HOS.Applets.Browser public BrowserOutput(BrowserOutputType type, byte[] value) { - Type = type; + Type = type; Value = value; } public BrowserOutput(BrowserOutputType type, uint value) { - Type = type; - Value = BitConverter.GetBytes(value); + Type = type; + Value = BitConverter.GetBytes(value); } public BrowserOutput(BrowserOutputType type, ulong value) { - Type = type; + Type = type; Value = BitConverter.GetBytes(value); } public BrowserOutput(BrowserOutputType type, bool value) { - Type = type; + Type = type; Value = BitConverter.GetBytes(value); } @@ -38,7 +38,7 @@ namespace Ryujinx.HLE.HOS.Applets.Browser writer.WriteStruct(new WebArgTLV { Type = (ushort)Type, - Size = (ushort)Value.Length + Size = (ushort)Value.Length, }); writer.Write(Value); diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserOutputType.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserOutputType.cs index 209ae8ae1..7f85bc81c 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserOutputType.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/BrowserOutputType.cs @@ -2,13 +2,13 @@ { enum BrowserOutputType : ushort { - ExitReason = 0x1, - LastUrl = 0x2, - LastUrlSize = 0x3, - SharePostResult = 0x4, - PostServiceName = 0x5, - PostServiceNameSize = 0x6, - PostId = 0x7, - MediaPlayerAutoClosedByCompletion = 0x8 + ExitReason = 0x1, + LastUrl = 0x2, + LastUrlSize = 0x3, + SharePostResult = 0x4, + PostServiceName = 0x5, + PostServiceNameSize = 0x6, + PostId = 0x7, + MediaPlayerAutoClosedByCompletion = 0x8, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/DocumentKind.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/DocumentKind.cs index 385bcdd00..9d355cd75 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/DocumentKind.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/DocumentKind.cs @@ -4,6 +4,6 @@ { OfflineHtmlPage = 1, ApplicationLegalInformation, - SystemDataPage + SystemDataPage, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/LeftStickMode.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/LeftStickMode.cs index 917549d2c..50ad7b8bb 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/LeftStickMode.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/LeftStickMode.cs @@ -3,6 +3,6 @@ enum LeftStickMode { Pointer = 0, - Cursor + Cursor, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/ShimKind.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/ShimKind.cs index ca2ef32fe..f097d1f4a 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/ShimKind.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/ShimKind.cs @@ -8,6 +8,6 @@ Share, Web, Wifi, - Lobby + Lobby, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgHeader.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgHeader.cs index c5e19f6ca..c3cc711e4 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgHeader.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgHeader.cs @@ -2,8 +2,8 @@ { public struct WebArgHeader { - public ushort Count; - public ushort Padding; + public ushort Count; + public ushort Padding; public ShimKind ShimKind; } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgTLV.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgTLV.cs index f6c1e5ae0..1b5510a5d 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgTLV.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgTLV.cs @@ -4,6 +4,6 @@ { public ushort Type; public ushort Size; - public uint Padding; + public uint Padding; } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgTLVType.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgTLVType.cs index bd3032072..575138330 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgTLVType.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/WebArgTLVType.cs @@ -2,61 +2,61 @@ { enum WebArgTLVType : ushort { - InitialURL = 0x1, - CallbackUrl = 0x3, - CallbackableUrl = 0x4, - ApplicationId = 0x5, - DocumentPath = 0x6, - DocumentKind = 0x7, - SystemDataId = 0x8, - ShareStartPage = 0x9, - Whitelist = 0xA, - NewsFlag = 0xB, - UserID = 0xE, - AlbumEntry0 = 0xF, - ScreenShotEnabled = 0x10, - EcClientCertEnabled = 0x11, - PlayReportEnabled = 0x13, - UnknownFlag0x14 = 0x14, - UnknownFlag0x15 = 0x15, - BootDisplayKind = 0x17, - BackgroundKind = 0x18, - FooterEnabled = 0x19, - PointerEnabled = 0x1A, - LeftStickMode = 0x1B, - KeyRepeatFrame1 = 0x1C, - KeyRepeatFrame2 = 0x1D, - BootAsMediaPlayerInverted = 0x1E, - DisplayUrlKind = 0x1F, - BootAsMediaPlayer = 0x21, - ShopJumpEnabled = 0x22, - MediaAutoPlayEnabled = 0x23, - LobbyParameter = 0x24, - ApplicationAlbumEntry = 0x26, - JsExtensionEnabled = 0x27, - AdditionalCommentText = 0x28, - TouchEnabledOnContents = 0x29, - UserAgentAdditionalString = 0x2A, - AdditionalMediaData0 = 0x2B, - MediaPlayerAutoCloseEnabled = 0x2C, - PageCacheEnabled = 0x2D, - WebAudioEnabled = 0x2E, - FooterFixedKind = 0x32, - PageFadeEnabled = 0x33, + InitialURL = 0x1, + CallbackUrl = 0x3, + CallbackableUrl = 0x4, + ApplicationId = 0x5, + DocumentPath = 0x6, + DocumentKind = 0x7, + SystemDataId = 0x8, + ShareStartPage = 0x9, + Whitelist = 0xA, + NewsFlag = 0xB, + UserID = 0xE, + AlbumEntry0 = 0xF, + ScreenShotEnabled = 0x10, + EcClientCertEnabled = 0x11, + PlayReportEnabled = 0x13, + UnknownFlag0x14 = 0x14, + UnknownFlag0x15 = 0x15, + BootDisplayKind = 0x17, + BackgroundKind = 0x18, + FooterEnabled = 0x19, + PointerEnabled = 0x1A, + LeftStickMode = 0x1B, + KeyRepeatFrame1 = 0x1C, + KeyRepeatFrame2 = 0x1D, + BootAsMediaPlayerInverted = 0x1E, + DisplayUrlKind = 0x1F, + BootAsMediaPlayer = 0x21, + ShopJumpEnabled = 0x22, + MediaAutoPlayEnabled = 0x23, + LobbyParameter = 0x24, + ApplicationAlbumEntry = 0x26, + JsExtensionEnabled = 0x27, + AdditionalCommentText = 0x28, + TouchEnabledOnContents = 0x29, + UserAgentAdditionalString = 0x2A, + AdditionalMediaData0 = 0x2B, + MediaPlayerAutoCloseEnabled = 0x2C, + PageCacheEnabled = 0x2D, + WebAudioEnabled = 0x2E, + FooterFixedKind = 0x32, + PageFadeEnabled = 0x33, MediaCreatorApplicationRatingAge = 0x34, - BootLoadingIconEnabled = 0x35, - PageScrollIndicatorEnabled = 0x36, - MediaPlayerSpeedControlEnabled = 0x37, - AlbumEntry1 = 0x38, - AlbumEntry2 = 0x39, - AlbumEntry3 = 0x3A, - AdditionalMediaData1 = 0x3B, - AdditionalMediaData2 = 0x3C, - AdditionalMediaData3 = 0x3D, - BootFooterButton = 0x3E, - OverrideWebAudioVolume = 0x3F, - OverrideMediaAudioVolume = 0x40, - BootMode = 0x41, - MediaPlayerUiEnabled = 0x43 + BootLoadingIconEnabled = 0x35, + PageScrollIndicatorEnabled = 0x36, + MediaPlayerSpeedControlEnabled = 0x37, + AlbumEntry1 = 0x38, + AlbumEntry2 = 0x39, + AlbumEntry3 = 0x3A, + AdditionalMediaData1 = 0x3B, + AdditionalMediaData2 = 0x3C, + AdditionalMediaData3 = 0x3D, + BootFooterButton = 0x3E, + OverrideWebAudioVolume = 0x3F, + OverrideMediaAudioVolume = 0x40, + BootMode = 0x41, + MediaPlayerUiEnabled = 0x43, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/WebCommonReturnValue.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/WebCommonReturnValue.cs index 9f7eae700..a1bdf0c76 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/WebCommonReturnValue.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/WebCommonReturnValue.cs @@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Applets.Browser public struct WebCommonReturnValue { public WebExitReason ExitReason; - public uint Padding; + public uint Padding; public ByteArray4096 LastUrl; - public ulong LastUrlSize; + public ulong LastUrlSize; } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/WebExitReason.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/WebExitReason.cs index 4e44d34ab..1959fc0b4 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Browser/WebExitReason.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Browser/WebExitReason.cs @@ -6,6 +6,6 @@ BackButton, Requested, LastUrl, - ErrorDialog = 7 + ErrorDialog = 7, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/CommonArguments.cs b/src/Ryujinx.HLE/HOS/Applets/CommonArguments.cs index 5da34db1f..857798987 100644 --- a/src/Ryujinx.HLE/HOS/Applets/CommonArguments.cs +++ b/src/Ryujinx.HLE/HOS/Applets/CommonArguments.cs @@ -5,12 +5,12 @@ namespace Ryujinx.HLE.HOS.Applets [StructLayout(LayoutKind.Sequential, Pack = 8)] struct CommonArguments { - public uint Version; - public uint StructureSize; - public uint AppletVersion; - public uint ThemeColor; + public uint Version; + public uint StructureSize; + public uint AppletVersion; + public uint ThemeColor; [MarshalAs(UnmanagedType.I1)] - public bool PlayStartupSound; + public bool PlayStartupSound; public ulong SystemTicks; } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerApplet.cs b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerApplet.cs index 5d5a26c23..867202178 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerApplet.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerApplet.cs @@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Applets { internal class ControllerApplet : IApplet { - private Horizon _system; + private readonly Horizon _system; private AppletSession _normalSession; @@ -65,7 +65,7 @@ namespace Ryujinx.HLE.HOS.Applets } else { - Logger.Stub?.PrintStub(LogClass.ServiceHid, $"ControllerSupportArg Version Unknown"); + Logger.Stub?.PrintStub(LogClass.ServiceHid, "ControllerSupportArg Version Unknown"); argHeader = IApplet.ReadStruct(controllerSupportArg); // Read just the header } @@ -82,17 +82,17 @@ namespace Ryujinx.HLE.HOS.Applets playerMin = playerMax = 1; } - int configuredCount = 0; - PlayerIndex primaryIndex = PlayerIndex.Unknown; + int configuredCount; + PlayerIndex primaryIndex; while (!_system.Device.Hid.Npads.Validate(playerMin, playerMax, (ControllerType)privateArg.NpadStyleSet, out configuredCount, out primaryIndex)) { - ControllerAppletUiArgs uiArgs = new ControllerAppletUiArgs + ControllerAppletUiArgs uiArgs = new() { PlayerCountMin = playerMin, PlayerCountMax = playerMax, SupportedStyles = (ControllerType)privateArg.NpadStyleSet, SupportedPlayers = _system.Device.Hid.Npads.GetSupportedPlayers(), - IsDocked = _system.State.DockedMode + IsDocked = _system.State.DockedMode, }; if (!_system.Device.UiHandler.DisplayMessageDialog(uiArgs)) @@ -101,10 +101,10 @@ namespace Ryujinx.HLE.HOS.Applets } } - ControllerSupportResultInfo result = new ControllerSupportResultInfo + ControllerSupportResultInfo result = new() { PlayerCount = (sbyte)configuredCount, - SelectedId = (uint)GetNpadIdTypeFromIndex(primaryIndex) + SelectedId = (uint)GetNpadIdTypeFromIndex(primaryIndex), }; Logger.Stub?.PrintStub(LogClass.ServiceHid, $"ControllerApplet ReturnResult {result.PlayerCount} {result.SelectedId}"); @@ -122,26 +122,24 @@ namespace Ryujinx.HLE.HOS.Applets return ResultCode.Success; } - private byte[] BuildResponse(ControllerSupportResultInfo result) + private static byte[] BuildResponse(ControllerSupportResultInfo result) { - using (MemoryStream stream = MemoryStreamManager.Shared.GetStream()) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - writer.Write(MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(ref result, Unsafe.SizeOf()))); + using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + writer.Write(MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(ref result, Unsafe.SizeOf()))); + + return stream.ToArray(); } - private byte[] BuildResponse() + private static byte[] BuildResponse() { - using (MemoryStream stream = MemoryStreamManager.Shared.GetStream()) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - writer.Write((ulong)ResultCode.Success); + using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + writer.Write((ulong)ResultCode.Success); + + return stream.ToArray(); } } } diff --git a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerAppletUiArgs.cs b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerAppletUiArgs.cs index cc15a406a..bf440515b 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerAppletUiArgs.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerAppletUiArgs.cs @@ -11,4 +11,4 @@ namespace Ryujinx.HLE.HOS.Applets public IEnumerable SupportedPlayers; public bool IsDocked; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgHeader.cs b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgHeader.cs index 141994a8a..b066da8e8 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgHeader.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgHeader.cs @@ -2,7 +2,7 @@ using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Applets { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ControllerSupportArgHeader { @@ -15,4 +15,4 @@ namespace Ryujinx.HLE.HOS.Applets public byte EnableIdentificationColor; } #pragma warning restore CS0649 -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgPrivate.cs b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgPrivate.cs index d4c8177eb..d5a18d468 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgPrivate.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgPrivate.cs @@ -1,6 +1,6 @@ namespace Ryujinx.HLE.HOS.Applets { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to struct ControllerSupportArgPrivate { public uint PrivateSize; @@ -13,4 +13,4 @@ namespace Ryujinx.HLE.HOS.Applets public uint NpadJoyHoldType; } #pragma warning restore CS0649 -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgV7.cs b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgV7.cs index 98c413beb..0969493fa 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgV7.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgV7.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Applets { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to // (8.0.0+ version) [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ControllerSupportArgV7 @@ -23,4 +23,4 @@ namespace Ryujinx.HLE.HOS.Applets } } #pragma warning restore CS0649 -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgVPre7.cs b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgVPre7.cs index 87417e16f..886782553 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgVPre7.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportArgVPre7.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Applets { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to // (1.0.0+ version) [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ControllerSupportArgVPre7 @@ -23,4 +23,4 @@ namespace Ryujinx.HLE.HOS.Applets } } #pragma warning restore CS0649 -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportMode.cs b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportMode.cs index 9496c1dd6..5e181e197 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportMode.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportMode.cs @@ -4,6 +4,6 @@ namespace Ryujinx.HLE.HOS.Applets { ShowControllerSupport = 0, ShowControllerStrapGuide = 1, - ShowControllerFirmwareUpdate = 2 + ShowControllerFirmwareUpdate = 2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportResultInfo.cs b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportResultInfo.cs index 689a54dec..96cfd5903 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportResultInfo.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Controller/ControllerSupportResultInfo.cs @@ -3,7 +3,7 @@ using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Applets { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ControllerSupportResultInfo { @@ -13,4 +13,4 @@ namespace Ryujinx.HLE.HOS.Applets public uint Result; } #pragma warning restore CS0649 -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Error/ApplicationErrorArg.cs b/src/Ryujinx.HLE/HOS/Applets/Error/ApplicationErrorArg.cs index f40d54112..4263c84b8 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Error/ApplicationErrorArg.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Error/ApplicationErrorArg.cs @@ -6,9 +6,9 @@ namespace Ryujinx.HLE.HOS.Applets.Error [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ApplicationErrorArg { - public uint ErrorNumber; - public ulong LanguageCode; + public uint ErrorNumber; + public ulong LanguageCode; public ByteArray2048 MessageText; public ByteArray2048 DetailsText; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs index c5c6e8e95..fa415b396 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs @@ -22,11 +22,11 @@ namespace Ryujinx.HLE.HOS.Applets.Error { private const long ErrorMessageBinaryTitleId = 0x0100000000000801; - private Horizon _horizon; - private AppletSession _normalSession; - private CommonArguments _commonArguments; + private readonly Horizon _horizon; + private AppletSession _normalSession; + private CommonArguments _commonArguments; private ErrorCommonHeader _errorCommonHeader; - private byte[] _errorStorage; + private byte[] _errorStorage; public event EventHandler AppletStateChanged; @@ -40,14 +40,14 @@ namespace Ryujinx.HLE.HOS.Applets.Error public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession) { - _normalSession = normalSession; + _normalSession = normalSession; _commonArguments = IApplet.ReadStruct(_normalSession.Pop()); Logger.Info?.PrintMsg(LogClass.ServiceAm, $"ErrorApplet version: 0x{_commonArguments.AppletVersion:x8}"); - _errorStorage = _normalSession.Pop(); + _errorStorage = _normalSession.Pop(); _errorCommonHeader = IApplet.ReadStruct(_errorStorage); - _errorStorage = _errorStorage.Skip(Marshal.SizeOf()).ToArray(); + _errorStorage = _errorStorage.Skip(Marshal.SizeOf()).ToArray(); switch (_errorCommonHeader.Type) { @@ -63,7 +63,8 @@ namespace Ryujinx.HLE.HOS.Applets.Error break; } - default: throw new NotImplementedException($"ErrorApplet type {_errorCommonHeader.Type} is not implemented."); + default: + throw new NotImplementedException($"ErrorApplet type {_errorCommonHeader.Type} is not implemented."); } AppletStateChanged?.Invoke(this, null); @@ -71,15 +72,16 @@ namespace Ryujinx.HLE.HOS.Applets.Error return ResultCode.Success; } - private (uint module, uint description) HexToResultCode(uint resultCode) + private static (uint module, uint description) HexToResultCode(uint resultCode) { return ((resultCode & 0x1FF) + 2000, (resultCode >> 9) & 0x3FFF); } - private string SystemLanguageToLanguageKey(SystemLanguage systemLanguage) + private static string SystemLanguageToLanguageKey(SystemLanguage systemLanguage) { return systemLanguage switch { +#pragma warning disable IDE0055 // Disable formatting SystemLanguage.Japanese => "ja", SystemLanguage.AmericanEnglish => "en-US", SystemLanguage.French => "fr", @@ -98,7 +100,8 @@ namespace Ryujinx.HLE.HOS.Applets.Error SystemLanguage.SimplifiedChinese => "zh-Hans", SystemLanguage.TraditionalChinese => "zh-Hant", SystemLanguage.BrazilianPortuguese => "pt-BR", - _ => "en-US" + _ => "en-US", +#pragma warning restore IDE0055 }; } @@ -111,26 +114,24 @@ namespace Ryujinx.HLE.HOS.Applets.Error { string binaryTitleContentPath = _horizon.ContentManager.GetInstalledContentPath(ErrorMessageBinaryTitleId, StorageId.BuiltInSystem, NcaContentType.Data); - using (LibHac.Fs.IStorage ncaFileStream = new LocalStorage(_horizon.Device.FileSystem.SwitchPathToSystemPath(binaryTitleContentPath), FileAccess.Read, FileMode.Open)) + using LibHac.Fs.IStorage ncaFileStream = new LocalStorage(FileSystem.VirtualFileSystem.SwitchPathToSystemPath(binaryTitleContentPath), FileAccess.Read, FileMode.Open); + Nca nca = new(_horizon.Device.FileSystem.KeySet, ncaFileStream); + IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _horizon.FsIntegrityCheckLevel); + string languageCode = SystemLanguageToLanguageKey(_horizon.State.DesiredSystemLanguage); + string filePath = $"/{module}/{description:0000}/{languageCode}_{key}"; + + if (romfs.FileExists(filePath)) { - Nca nca = new Nca(_horizon.Device.FileSystem.KeySet, ncaFileStream); - IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _horizon.FsIntegrityCheckLevel); - string languageCode = SystemLanguageToLanguageKey(_horizon.State.DesiredSystemLanguage); - string filePath = $"/{module}/{description:0000}/{languageCode}_{key}"; + using var binaryFile = new UniqueRef(); - if (romfs.FileExists(filePath)) - { - using var binaryFile = new UniqueRef(); + romfs.OpenFile(ref binaryFile.Ref, filePath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); + StreamReader reader = new(binaryFile.Get.AsStream(), Encoding.Unicode); - romfs.OpenFile(ref binaryFile.Ref, filePath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); - StreamReader reader = new StreamReader(binaryFile.Get.AsStream(), Encoding.Unicode); - - return CleanText(reader.ReadToEnd()); - } - else - { - return ""; - } + return CleanText(reader.ReadToEnd()); + } + else + { + return ""; } } @@ -145,7 +146,7 @@ namespace Ryujinx.HLE.HOS.Applets.Error { ErrorCommonArg errorCommonArg = IApplet.ReadStruct(_errorStorage); - uint module = errorCommonArg.Module; + uint module = errorCommonArg.Module; uint description = errorCommonArg.Description; if (_errorCommonHeader.MessageFlag == 0) @@ -188,7 +189,7 @@ namespace Ryujinx.HLE.HOS.Applets.Error string messageText = Encoding.ASCII.GetString(messageTextBuffer.TakeWhile(b => !b.Equals(0)).ToArray()); string detailsText = Encoding.ASCII.GetString(detailsTextBuffer.TakeWhile(b => !b.Equals(0)).ToArray()); - List buttons = new List(); + List buttons = new(); // TODO: Handle the LanguageCode to return the translated "OK" and "Details". @@ -213,4 +214,4 @@ namespace Ryujinx.HLE.HOS.Applets.Error return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorCommonArg.cs b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorCommonArg.cs index 530a2ad8b..a042739cb 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorCommonArg.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorCommonArg.cs @@ -9,4 +9,4 @@ namespace Ryujinx.HLE.HOS.Applets.Error public uint Description; public uint ResultCode; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorCommonHeader.cs b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorCommonHeader.cs index b93cdd4f1..ca8e9220f 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorCommonHeader.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorCommonHeader.cs @@ -6,12 +6,12 @@ namespace Ryujinx.HLE.HOS.Applets.Error struct ErrorCommonHeader { public ErrorType Type; - public byte JumpFlag; - public byte ReservedFlag1; - public byte ReservedFlag2; - public byte ReservedFlag3; - public byte ContextFlag; - public byte MessageFlag; - public byte ContextFlag2; + public byte JumpFlag; + public byte ReservedFlag1; + public byte ReservedFlag2; + public byte ReservedFlag3; + public byte ContextFlag; + public byte MessageFlag; + public byte ContextFlag2; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorType.cs b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorType.cs index f06af1d3c..c5f7e4eb0 100644 --- a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorType.cs +++ b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorType.cs @@ -8,6 +8,6 @@ ErrorEulaArg, ErrorPctlArg, ErrorRecordArg, - SystemUpdateEulaArg = 8 + SystemUpdateEulaArg = 8, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectApplet.cs b/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectApplet.cs index a8119a470..8db23d30b 100644 --- a/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectApplet.cs +++ b/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectApplet.cs @@ -8,10 +8,12 @@ namespace Ryujinx.HLE.HOS.Applets { internal class PlayerSelectApplet : IApplet { - private Horizon _system; + private readonly Horizon _system; private AppletSession _normalSession; +#pragma warning disable IDE0052 // Remove unread private member private AppletSession _interactiveSession; +#pragma warning restore IDE0052 public event EventHandler AppletStateChanged; @@ -22,7 +24,7 @@ namespace Ryujinx.HLE.HOS.Applets public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession) { - _normalSession = normalSession; + _normalSession = normalSession; _interactiveSession = interactiveSession; // TODO(jduncanator): Parse PlayerSelectConfig from input data @@ -44,15 +46,14 @@ namespace Ryujinx.HLE.HOS.Applets { UserProfile currentUser = _system.AccountManager.LastOpenedUser; - using (MemoryStream stream = MemoryStreamManager.Shared.GetStream()) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - writer.Write((ulong)PlayerSelectResult.Success); + using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); + using BinaryWriter writer = new(stream); - currentUser.UserId.Write(writer); + writer.Write((ulong)PlayerSelectResult.Success); - return stream.ToArray(); - } + currentUser.UserId.Write(writer); + + return stream.ToArray(); } } } diff --git a/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectResult.cs b/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectResult.cs index 682e094ed..d07aadf4b 100644 --- a/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectResult.cs +++ b/src/Ryujinx.HLE/HOS/Applets/PlayerSelect/PlayerSelectResult.cs @@ -3,6 +3,6 @@ enum PlayerSelectResult : ulong { Success = 0, - Failure = 2 + Failure = 2, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/CJKCharacterValidation.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/CJKCharacterValidation.cs index 36e6ff512..722fe60af 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/CJKCharacterValidation.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/CJKCharacterValidation.cs @@ -14,4 +14,4 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard [GeneratedRegex("\\p{IsHangulJamo}|\\p{IsCJKRadicalsSupplement}|\\p{IsCJKSymbolsandPunctuation}|\\p{IsEnclosedCJKLettersandMonths}|\\p{IsCJKCompatibility}|\\p{IsCJKUnifiedIdeographsExtensionA}|\\p{IsCJKUnifiedIdeographs}|\\p{IsHangulSyllables}|\\p{IsCJKCompatibilityForms}")] private static partial Regex CJKRegex(); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InitialCursorPosition.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InitialCursorPosition.cs index 727b6d27b..be94ee482 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InitialCursorPosition.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InitialCursorPosition.cs @@ -13,6 +13,6 @@ /// /// Position the cursor at the end of the text /// - End + End, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardRequest.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardRequest.cs index b17debfc7..cc2938e04 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardRequest.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardRequest.cs @@ -43,6 +43,6 @@ /// /// [8.0.0+] Request the keyboard applet to use the MovedCursorV2 response when notifying changes in cursor position. /// - UseMovedCursorV2 = 0xE + UseMovedCursorV2 = 0xE, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardResponse.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardResponse.cs index b21db507c..2179752e1 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardResponse.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardResponse.cs @@ -88,6 +88,6 @@ /// /// Same as MovedCursorUtf8, but with additional fields. /// - MovedCursorUtf8V2 = 0x10 + MovedCursorUtf8V2 = 0x10, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardState.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardState.cs index 47e1a7746..da802fbc1 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardState.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineKeyboardState.cs @@ -28,6 +28,6 @@ /// /// software keyboard is transitioning to a hidden state because the user pressed either OK or Cancel. /// - Disappearing = 0x4 + Disappearing = 0x4, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineResponses.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineResponses.cs index c3e45d469..e8e57a48d 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineResponses.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineResponses.cs @@ -60,55 +60,51 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard { uint resSize = 2 * sizeof(uint) + 0x1; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.FinishedInitialize, writer); - writer.Write((byte)1); // Data (ignored by the program) + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.FinishedInitialize, writer); + writer.Write((byte)1); // Data (ignored by the program) + + return stream.ToArray(); } public static byte[] Default(InlineKeyboardState state) { uint resSize = 2 * sizeof(uint); - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.Default, writer); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.Default, writer); + + return stream.ToArray(); } public static byte[] ChangedString(string text, uint cursor, InlineKeyboardState state) { uint resSize = 6 * sizeof(uint) + MaxStrLenUTF16; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.ChangedString, writer); - WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, true); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.ChangedString, writer); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, true); + + return stream.ToArray(); } public static byte[] MovedCursor(string text, uint cursor, InlineKeyboardState state) { uint resSize = 4 * sizeof(uint) + MaxStrLenUTF16; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.MovedCursor, writer); - WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, false); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.MovedCursor, writer); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, false); + + return stream.ToArray(); } public static byte[] MovedTab(string text, uint cursor, InlineKeyboardState state) @@ -117,182 +113,169 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard uint resSize = 4 * sizeof(uint) + MaxStrLenUTF16; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.MovedTab, writer); - WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, false); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.MovedTab, writer); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, false); + + return stream.ToArray(); } public static byte[] DecidedEnter(string text, InlineKeyboardState state) { uint resSize = 3 * sizeof(uint) + MaxStrLenUTF16; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.DecidedEnter, writer); - WriteString(text, writer, MaxStrLenUTF16, Encoding.Unicode); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.DecidedEnter, writer); + WriteString(text, writer, MaxStrLenUTF16, Encoding.Unicode); + + return stream.ToArray(); } public static byte[] DecidedCancel(InlineKeyboardState state) { uint resSize = 2 * sizeof(uint); - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.DecidedCancel, writer); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.DecidedCancel, writer); + + return stream.ToArray(); } public static byte[] ChangedStringUtf8(string text, uint cursor, InlineKeyboardState state) { uint resSize = 6 * sizeof(uint) + MaxStrLenUTF8; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.ChangedStringUtf8, writer); - WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, true); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.ChangedStringUtf8, writer); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, true); + + return stream.ToArray(); } public static byte[] MovedCursorUtf8(string text, uint cursor, InlineKeyboardState state) { uint resSize = 4 * sizeof(uint) + MaxStrLenUTF8; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.MovedCursorUtf8, writer); - WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, false); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.MovedCursorUtf8, writer); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, false); + + return stream.ToArray(); } public static byte[] DecidedEnterUtf8(string text, InlineKeyboardState state) { uint resSize = 3 * sizeof(uint) + MaxStrLenUTF8; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.DecidedEnterUtf8, writer); - WriteString(text, writer, MaxStrLenUTF8, Encoding.UTF8); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.DecidedEnterUtf8, writer); + WriteString(text, writer, MaxStrLenUTF8, Encoding.UTF8); + + return stream.ToArray(); } public static byte[] UnsetCustomizeDic(InlineKeyboardState state) { uint resSize = 2 * sizeof(uint); - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.UnsetCustomizeDic, writer); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.UnsetCustomizeDic, writer); + + return stream.ToArray(); } public static byte[] ReleasedUserWordInfo(InlineKeyboardState state) { uint resSize = 2 * sizeof(uint); - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.ReleasedUserWordInfo, writer); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.ReleasedUserWordInfo, writer); + + return stream.ToArray(); } public static byte[] UnsetCustomizedDictionaries(InlineKeyboardState state) { uint resSize = 2 * sizeof(uint); - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.UnsetCustomizedDictionaries, writer); + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.UnsetCustomizedDictionaries, writer); + + return stream.ToArray(); } public static byte[] ChangedStringV2(string text, uint cursor, InlineKeyboardState state) { uint resSize = 6 * sizeof(uint) + MaxStrLenUTF16 + 0x1; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.ChangedStringV2, writer); - WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, true); - writer.Write((byte)0); // Flag == 0 + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.ChangedStringV2, writer); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, true); + writer.Write((byte)0); // Flag == 0 + + return stream.ToArray(); } public static byte[] MovedCursorV2(string text, uint cursor, InlineKeyboardState state) { uint resSize = 4 * sizeof(uint) + MaxStrLenUTF16 + 0x1; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.MovedCursorV2, writer); - WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, false); - writer.Write((byte)0); // Flag == 0 + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.MovedCursorV2, writer); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, false); + writer.Write((byte)0); // Flag == 0 + + return stream.ToArray(); } public static byte[] ChangedStringUtf8V2(string text, uint cursor, InlineKeyboardState state) { uint resSize = 6 * sizeof(uint) + MaxStrLenUTF8 + 0x1; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.ChangedStringUtf8V2, writer); - WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, true); - writer.Write((byte)0); // Flag == 0 + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.ChangedStringUtf8V2, writer); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, true); + writer.Write((byte)0); // Flag == 0 + + return stream.ToArray(); } public static byte[] MovedCursorUtf8V2(string text, uint cursor, InlineKeyboardState state) { uint resSize = 4 * sizeof(uint) + MaxStrLenUTF8 + 0x1; - using (MemoryStream stream = new MemoryStream(new byte[resSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - BeginResponse(state, InlineKeyboardResponse.MovedCursorUtf8V2, writer); - WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, false); - writer.Write((byte)0); // Flag == 0 + using MemoryStream stream = new(new byte[resSize]); + using BinaryWriter writer = new(stream); - return stream.ToArray(); - } + BeginResponse(state, InlineKeyboardResponse.MovedCursorUtf8V2, writer); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, false); + writer.Write((byte)0); // Flag == 0 + + return stream.ToArray(); } } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InputFormMode.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InputFormMode.cs index c3ce2c125..9b7ef9c61 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InputFormMode.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InputFormMode.cs @@ -13,6 +13,6 @@ /// /// Displays the text entry area as a multi-line field. /// - MultiLine + MultiLine, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InvalidButtonFlags.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InvalidButtonFlags.cs index 1166e81dd..4928c1943 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InvalidButtonFlags.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InvalidButtonFlags.cs @@ -8,10 +8,10 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard [Flags] enum InvalidButtonFlags : uint { - None = 0, + None = 0, AnalogStickL = 1 << 1, AnalogStickR = 1 << 2, - ZL = 1 << 3, - ZR = 1 << 4, + ZL = 1 << 3, + ZR = 1 << 4, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InvalidCharFlags.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InvalidCharFlags.cs index f3fd8ac85..f2dcc5823 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InvalidCharFlags.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InvalidCharFlags.cs @@ -51,6 +51,6 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard /// /// Prohibits characters outside of those allowed in Mii Nicknames. /// - Username = 1 << 8 + Username = 1 << 8, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardCalcFlags.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardCalcFlags.cs index 0b0f138b6..e1402b1b2 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardCalcFlags.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardCalcFlags.cs @@ -8,19 +8,19 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard [Flags] enum KeyboardCalcFlags : ulong { - Initialize = 0x1, - SetVolume = 0x2, - Appear = 0x4, - SetInputText = 0x8, - SetCursorPos = 0x10, - SetUtf8Mode = 0x20, + Initialize = 0x1, + SetVolume = 0x2, + Appear = 0x4, + SetInputText = 0x8, + SetCursorPos = 0x10, + SetUtf8Mode = 0x20, SetKeyboardBackground = 0x100, - SetKeyboardOptions1 = 0x200, - SetKeyboardOptions2 = 0x800, - EnableSeGroup = 0x2000, - DisableSeGroup = 0x4000, - SetBackspaceEnabled = 0x8000, - AppearTrigger = 0x10000, - MustShow = Appear | SetInputText | AppearTrigger + SetKeyboardOptions1 = 0x200, + SetKeyboardOptions2 = 0x800, + EnableSeGroup = 0x2000, + DisableSeGroup = 0x4000, + SetBackspaceEnabled = 0x8000, + AppearTrigger = 0x10000, + MustShow = Appear | SetInputText | AppearTrigger, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMiniaturizationMode.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMiniaturizationMode.cs index 5184118cd..b5ebabebb 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMiniaturizationMode.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMiniaturizationMode.cs @@ -5,8 +5,8 @@ /// enum KeyboardMiniaturizationMode : byte { - None = 0, - Auto = 1, - Forced = 2 + None = 0, + Auto = 1, + Forced = 2, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMode.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMode.cs index e28622111..917e1f9e1 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMode.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMode.cs @@ -24,16 +24,16 @@ /// Synonymous with default. /// FullLatin = 3, - + /// /// All UTF-16 characters except CJK characters allowed. /// Alphabet = 4, - - SimplifiedChinese = 5, + + SimplifiedChinese = 5, TraditionalChinese = 6, - Korean = 7, - LanguageSet2 = 8, - LanguageSet2Latin = 9, + Korean = 7, + LanguageSet2 = 8, + LanguageSet2Latin = 9, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardResult.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardResult.cs index 4f570d3f3..dc39feb87 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardResult.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardResult.cs @@ -9,4 +9,4 @@ Accept = 1, Cancel = 2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/PasswordMode.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/PasswordMode.cs index fc9e1ff8e..b5ea7faa2 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/PasswordMode.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/PasswordMode.cs @@ -13,6 +13,6 @@ /// /// Hide input characters. /// - Enabled + Enabled, } } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardAppear.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardAppear.cs index e1ee0507d..fb6aad649 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardAppear.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardAppear.cs @@ -77,41 +77,42 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard [MarshalAs(UnmanagedType.I1)] public bool UseSaveData; - public uint Reserved3; + public uint Reserved3; public ushort Reserved4; - public byte Reserved5; - public ulong Reserved6; - public ulong Reserved7; + public byte Reserved5; + public ulong Reserved6; + public ulong Reserved7; public SoftwareKeyboardAppearEx ToExtended() { - SoftwareKeyboardAppearEx appear = new SoftwareKeyboardAppearEx(); - - appear.KeyboardMode = KeyboardMode; - appear.OkText = OkText; - appear.LeftOptionalSymbolKey = LeftOptionalSymbolKey; - appear.RightOptionalSymbolKey = RightOptionalSymbolKey; - appear.PredictionEnabled = PredictionEnabled; - appear.CancelButtonDisabled = CancelButtonDisabled; - appear.InvalidChars = InvalidChars; - appear.TextMaxLength = TextMaxLength; - appear.TextMinLength = TextMinLength; - appear.UseNewLine = UseNewLine; - appear.MiniaturizationMode = MiniaturizationMode; - appear.Reserved1 = Reserved1; - appear.Reserved2 = Reserved2; - appear.InvalidButtons = InvalidButtons; - appear.UseSaveData = UseSaveData; - appear.Reserved3 = Reserved3; - appear.Reserved4 = Reserved4; - appear.Reserved5 = Reserved5; - appear.Uid0 = Reserved6; - appear.Uid1 = Reserved7; - appear.SamplingNumber = 0; - appear.Reserved6 = 0; - appear.Reserved7 = 0; - appear.Reserved8 = 0; - appear.Reserved9 = 0; + SoftwareKeyboardAppearEx appear = new() + { + KeyboardMode = KeyboardMode, + OkText = OkText, + LeftOptionalSymbolKey = LeftOptionalSymbolKey, + RightOptionalSymbolKey = RightOptionalSymbolKey, + PredictionEnabled = PredictionEnabled, + CancelButtonDisabled = CancelButtonDisabled, + InvalidChars = InvalidChars, + TextMaxLength = TextMaxLength, + TextMinLength = TextMinLength, + UseNewLine = UseNewLine, + MiniaturizationMode = MiniaturizationMode, + Reserved1 = Reserved1, + Reserved2 = Reserved2, + InvalidButtons = InvalidButtons, + UseSaveData = UseSaveData, + Reserved3 = Reserved3, + Reserved4 = Reserved4, + Reserved5 = Reserved5, + Uid0 = Reserved6, + Uid1 = Reserved7, + SamplingNumber = 0, + Reserved6 = 0, + Reserved7 = 0, + Reserved8 = 0, + Reserved9 = 0, + }; return appear; } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardAppearEx.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardAppearEx.cs index d1756b07a..29cd0a73c 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardAppearEx.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardAppearEx.cs @@ -77,9 +77,9 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard [MarshalAs(UnmanagedType.I1)] public bool UseSaveData; - public uint Reserved3; + public uint Reserved3; public ushort Reserved4; - public byte Reserved5; + public byte Reserved5; /// /// The id of the user associated with the appear request. diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs index 4337ec44b..e0f6e3f0c 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs @@ -21,16 +21,16 @@ namespace Ryujinx.HLE.HOS.Applets { private const string DefaultInputText = "Ryujinx"; - private const int StandardBufferSize = 0x7D8; + private const int StandardBufferSize = 0x7D8; private const int InteractiveBufferSize = 0x7D4; - private const int MaxUserWords = 0x1388; - private const int MaxUiTextSize = 100; + private const int MaxUserWords = 0x1388; + private const int MaxUiTextSize = 100; private const Key CycleInputModesKey = Key.F6; private readonly Switch _device; - private SoftwareKeyboardState _foregroundState = SoftwareKeyboardState.Uninitialized; + private SoftwareKeyboardState _foregroundState = SoftwareKeyboardState.Uninitialized; private volatile InlineKeyboardState _backgroundState = InlineKeyboardState.Uninitialized; private bool _isBackground = false; @@ -42,23 +42,25 @@ namespace Ryujinx.HLE.HOS.Applets private SoftwareKeyboardConfig _keyboardForegroundConfig; // Configuration for background (inline) mode. - private SoftwareKeyboardInitialize _keyboardBackgroundInitialize; +#pragma warning disable IDE0052 // Remove unread private member + private SoftwareKeyboardInitialize _keyboardBackgroundInitialize; private SoftwareKeyboardCustomizeDic _keyboardBackgroundDic; - private SoftwareKeyboardDictSet _keyboardBackgroundDictSet; - private SoftwareKeyboardUserWord[] _keyboardBackgroundUserWords; + private SoftwareKeyboardDictSet _keyboardBackgroundDictSet; +#pragma warning restore IDE0052 + private SoftwareKeyboardUserWord[] _keyboardBackgroundUserWords; private byte[] _transferMemory; - private string _textValue = ""; - private int _cursorBegin = 0; - private Encoding _encoding = Encoding.Unicode; - private KeyboardResult _lastResult = KeyboardResult.NotSet; + private string _textValue = ""; + private int _cursorBegin = 0; + private Encoding _encoding = Encoding.Unicode; + private KeyboardResult _lastResult = KeyboardResult.NotSet; private IDynamicTextInputHandler _dynamicTextInputHandler = null; - private SoftwareKeyboardRenderer _keyboardRenderer = null; - private NpadReader _npads = null; - private bool _canAcceptController = false; - private KeyboardInputMode _inputMode = KeyboardInputMode.ControllerAndKeyboard; + private SoftwareKeyboardRenderer _keyboardRenderer = null; + private NpadReader _npads = null; + private bool _canAcceptController = false; + private KeyboardInputMode _inputMode = KeyboardInputMode.ControllerAndKeyboard; private readonly object _lock = new(); @@ -73,12 +75,12 @@ namespace Ryujinx.HLE.HOS.Applets { lock (_lock) { - _normalSession = normalSession; + _normalSession = normalSession; _interactiveSession = interactiveSession; _interactiveSession.DataAvailable += OnInteractiveData; - var launchParams = _normalSession.Pop(); + var launchParams = _normalSession.Pop(); var keyboardConfig = _normalSession.Pop(); _isBackground = keyboardConfig.Length == Unsafe.SizeOf(); @@ -88,7 +90,7 @@ namespace Ryujinx.HLE.HOS.Applets // Initialize the keyboard applet in background mode. _keyboardBackgroundInitialize = MemoryMarshal.Read(keyboardConfig); - _backgroundState = InlineKeyboardState.Uninitialized; + _backgroundState = InlineKeyboardState.Uninitialized; if (_device.UiHandler == null) { @@ -99,11 +101,11 @@ namespace Ryujinx.HLE.HOS.Applets // Create a text handler that converts keyboard strokes to strings. _dynamicTextInputHandler = _device.UiHandler.CreateDynamicTextInputHandler(); _dynamicTextInputHandler.TextChangedEvent += HandleTextChangedEvent; - _dynamicTextInputHandler.KeyPressedEvent += HandleKeyPressedEvent; + _dynamicTextInputHandler.KeyPressedEvent += HandleKeyPressedEvent; _npads = new NpadReader(_device); _npads.NpadButtonDownEvent += HandleNpadButtonDownEvent; - _npads.NpadButtonUpEvent += HandleNpadButtonUpEvent; + _npads.NpadButtonUpEvent += HandleNpadButtonUpEvent; _keyboardRenderer = new SoftwareKeyboardRenderer(_device.UiHandler.HostUiTheme); } @@ -217,7 +219,7 @@ namespace Ryujinx.HLE.HOS.Applets _keyboardForegroundConfig.SubmitText : "OK"), StringLengthMin = _keyboardForegroundConfig.StringLengthMin, StringLengthMax = _keyboardForegroundConfig.StringLengthMax, - InitialText = initialText + InitialText = initialText, }; _lastResult = _device.UiHandler.DisplayInputDialog(args, out _textValue) ? KeyboardResult.Accept : KeyboardResult.Cancel; @@ -237,7 +239,7 @@ namespace Ryujinx.HLE.HOS.Applets // we truncate it. if (_textValue.Length > _keyboardForegroundConfig.StringLengthMax) { - _textValue = _textValue.Substring(0, _keyboardForegroundConfig.StringLengthMax); + _textValue = _textValue[.._keyboardForegroundConfig.StringLengthMax]; } // Does the application want to validate the text itself? @@ -319,178 +321,177 @@ namespace Ryujinx.HLE.HOS.Applets // request from the game, this is because the inline keyboard is expected to // keep running in the background sending data by itself. - using (MemoryStream stream = new MemoryStream(data)) - using (BinaryReader reader = new BinaryReader(stream)) + using MemoryStream stream = new(data); + using BinaryReader reader = new(stream); + + var request = (InlineKeyboardRequest)reader.ReadUInt32(); + + long remaining; + + Logger.Debug?.Print(LogClass.ServiceAm, $"Keyboard received command {request} in state {_backgroundState}"); + + switch (request) { - var request = (InlineKeyboardRequest)reader.ReadUInt32(); - - long remaining; - - Logger.Debug?.Print(LogClass.ServiceAm, $"Keyboard received command {request} in state {_backgroundState}"); - - switch (request) - { - case InlineKeyboardRequest.UseChangedStringV2: - Logger.Stub?.Print(LogClass.ServiceAm, "Inline keyboard request UseChangedStringV2"); - break; - case InlineKeyboardRequest.UseMovedCursorV2: - Logger.Stub?.Print(LogClass.ServiceAm, "Inline keyboard request UseMovedCursorV2"); - break; - case InlineKeyboardRequest.SetUserWordInfo: - // Read the user word info data. + case InlineKeyboardRequest.UseChangedStringV2: + Logger.Stub?.Print(LogClass.ServiceAm, "Inline keyboard request UseChangedStringV2"); + break; + case InlineKeyboardRequest.UseMovedCursorV2: + Logger.Stub?.Print(LogClass.ServiceAm, "Inline keyboard request UseMovedCursorV2"); + break; + case InlineKeyboardRequest.SetUserWordInfo: + // Read the user word info data. + remaining = stream.Length - stream.Position; + if (remaining < sizeof(int)) + { + Logger.Warning?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard User Word Info of {remaining} bytes"); + } + else + { + int wordsCount = reader.ReadInt32(); + int wordSize = Unsafe.SizeOf(); remaining = stream.Length - stream.Position; - if (remaining < sizeof(int)) + + if (wordsCount > MaxUserWords) { - Logger.Warning?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard User Word Info of {remaining} bytes"); + Logger.Warning?.Print(LogClass.ServiceAm, $"Received {wordsCount} User Words but the maximum is {MaxUserWords}"); + } + else if (wordsCount * wordSize != remaining) + { + Logger.Warning?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard User Word Info data of {remaining} bytes for {wordsCount} words"); } else { - int wordsCount = reader.ReadInt32(); - int wordSize = Unsafe.SizeOf(); - remaining = stream.Length - stream.Position; + _keyboardBackgroundUserWords = new SoftwareKeyboardUserWord[wordsCount]; - if (wordsCount > MaxUserWords) + for (int word = 0; word < wordsCount; word++) { - Logger.Warning?.Print(LogClass.ServiceAm, $"Received {wordsCount} User Words but the maximum is {MaxUserWords}"); - } - else if (wordsCount * wordSize != remaining) - { - Logger.Warning?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard User Word Info data of {remaining} bytes for {wordsCount} words"); - } - else - { - _keyboardBackgroundUserWords = new SoftwareKeyboardUserWord[wordsCount]; - - for (int word = 0; word < wordsCount; word++) - { - _keyboardBackgroundUserWords[word] = reader.ReadStruct(); - } + _keyboardBackgroundUserWords[word] = reader.ReadStruct(); } } - _interactiveSession.Push(InlineResponses.ReleasedUserWordInfo(_backgroundState)); - break; - case InlineKeyboardRequest.SetCustomizeDic: - // Read the custom dic data. - remaining = stream.Length - stream.Position; - if (remaining != Unsafe.SizeOf()) - { - Logger.Warning?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard Customize Dic of {remaining} bytes"); - } - else - { - _keyboardBackgroundDic = reader.ReadStruct(); - } - break; - case InlineKeyboardRequest.SetCustomizedDictionaries: - // Read the custom dictionaries data. - remaining = stream.Length - stream.Position; - if (remaining != Unsafe.SizeOf()) - { - Logger.Warning?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard DictSet of {remaining} bytes"); - } - else - { - _keyboardBackgroundDictSet = reader.ReadStruct(); - } - break; - case InlineKeyboardRequest.Calc: - // The Calc request is used to communicate configuration changes and commands to the keyboard. - // Fields in the Calc struct and operations are masked by the Flags field. + } + _interactiveSession.Push(InlineResponses.ReleasedUserWordInfo(_backgroundState)); + break; + case InlineKeyboardRequest.SetCustomizeDic: + // Read the custom dic data. + remaining = stream.Length - stream.Position; + if (remaining != Unsafe.SizeOf()) + { + Logger.Warning?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard Customize Dic of {remaining} bytes"); + } + else + { + _keyboardBackgroundDic = reader.ReadStruct(); + } + break; + case InlineKeyboardRequest.SetCustomizedDictionaries: + // Read the custom dictionaries data. + remaining = stream.Length - stream.Position; + if (remaining != Unsafe.SizeOf()) + { + Logger.Warning?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard DictSet of {remaining} bytes"); + } + else + { + _keyboardBackgroundDictSet = reader.ReadStruct(); + } + break; + case InlineKeyboardRequest.Calc: + // The Calc request is used to communicate configuration changes and commands to the keyboard. + // Fields in the Calc struct and operations are masked by the Flags field. - // Read the Calc data. - SoftwareKeyboardCalcEx newCalc; - remaining = stream.Length - stream.Position; - if (remaining == Marshal.SizeOf()) - { - var keyboardCalcData = reader.ReadBytes((int)remaining); - var keyboardCalc = ReadStruct(keyboardCalcData); + // Read the Calc data. + SoftwareKeyboardCalcEx newCalc; + remaining = stream.Length - stream.Position; + if (remaining == Marshal.SizeOf()) + { + var keyboardCalcData = reader.ReadBytes((int)remaining); + var keyboardCalc = ReadStruct(keyboardCalcData); - newCalc = keyboardCalc.ToExtended(); - } - else if (remaining == Marshal.SizeOf() || remaining == SoftwareKeyboardCalcEx.AlternativeSize) - { - var keyboardCalcData = reader.ReadBytes((int)remaining); + newCalc = keyboardCalc.ToExtended(); + } + else if (remaining == Marshal.SizeOf() || remaining == SoftwareKeyboardCalcEx.AlternativeSize) + { + var keyboardCalcData = reader.ReadBytes((int)remaining); - newCalc = ReadStruct(keyboardCalcData); - } - else - { - Logger.Error?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard Calc of {remaining} bytes"); + newCalc = ReadStruct(keyboardCalcData); + } + else + { + Logger.Error?.Print(LogClass.ServiceAm, $"Received invalid Software Keyboard Calc of {remaining} bytes"); - newCalc = new SoftwareKeyboardCalcEx(); - } + newCalc = new SoftwareKeyboardCalcEx(); + } - // Process each individual operation specified in the flags. + // Process each individual operation specified in the flags. - bool updateText = false; + bool updateText = false; - if ((newCalc.Flags & KeyboardCalcFlags.Initialize) != 0) - { - _interactiveSession.Push(InlineResponses.FinishedInitialize(_backgroundState)); + if ((newCalc.Flags & KeyboardCalcFlags.Initialize) != 0) + { + _interactiveSession.Push(InlineResponses.FinishedInitialize(_backgroundState)); - _backgroundState = InlineKeyboardState.Initialized; - } + _backgroundState = InlineKeyboardState.Initialized; + } - if ((newCalc.Flags & KeyboardCalcFlags.SetCursorPos) != 0) - { - _cursorBegin = newCalc.CursorPos; - updateText = true; + if ((newCalc.Flags & KeyboardCalcFlags.SetCursorPos) != 0) + { + _cursorBegin = newCalc.CursorPos; + updateText = true; - Logger.Debug?.Print(LogClass.ServiceAm, $"Cursor position set to {_cursorBegin}"); - } + Logger.Debug?.Print(LogClass.ServiceAm, $"Cursor position set to {_cursorBegin}"); + } - if ((newCalc.Flags & KeyboardCalcFlags.SetInputText) != 0) - { - _textValue = newCalc.InputText; - updateText = true; + if ((newCalc.Flags & KeyboardCalcFlags.SetInputText) != 0) + { + _textValue = newCalc.InputText; + updateText = true; - Logger.Debug?.Print(LogClass.ServiceAm, $"Input text set to {_textValue}"); - } + Logger.Debug?.Print(LogClass.ServiceAm, $"Input text set to {_textValue}"); + } - if ((newCalc.Flags & KeyboardCalcFlags.SetUtf8Mode) != 0) - { - _encoding = newCalc.UseUtf8 ? Encoding.UTF8 : Encoding.Default; + if ((newCalc.Flags & KeyboardCalcFlags.SetUtf8Mode) != 0) + { + _encoding = newCalc.UseUtf8 ? Encoding.UTF8 : Encoding.Default; - Logger.Debug?.Print(LogClass.ServiceAm, $"Encoding set to {_encoding}"); - } + Logger.Debug?.Print(LogClass.ServiceAm, $"Encoding set to {_encoding}"); + } - if (updateText) - { - _dynamicTextInputHandler.SetText(_textValue, _cursorBegin); - _keyboardRenderer.UpdateTextState(_textValue, _cursorBegin, _cursorBegin, null, null); - } + if (updateText) + { + _dynamicTextInputHandler.SetText(_textValue, _cursorBegin); + _keyboardRenderer.UpdateTextState(_textValue, _cursorBegin, _cursorBegin, null, null); + } - if ((newCalc.Flags & KeyboardCalcFlags.MustShow) != 0) - { - ActivateFrontend(); + if ((newCalc.Flags & KeyboardCalcFlags.MustShow) != 0) + { + ActivateFrontend(); - _backgroundState = InlineKeyboardState.Shown; + _backgroundState = InlineKeyboardState.Shown; - PushChangedString(_textValue, (uint)_cursorBegin, _backgroundState); - } + PushChangedString(_textValue, (uint)_cursorBegin, _backgroundState); + } - // Send the response to the Calc - _interactiveSession.Push(InlineResponses.Default(_backgroundState)); - break; - case InlineKeyboardRequest.Finalize: - // Destroy the frontend. - DestroyFrontend(); - // The calling application wants to close the keyboard applet and will wait for a state change. - _backgroundState = InlineKeyboardState.Uninitialized; - AppletStateChanged?.Invoke(this, null); - break; - default: - // We shouldn't be able to get here through standard swkbd execution. - Logger.Warning?.Print(LogClass.ServiceAm, $"Invalid Software Keyboard request {request} during state {_backgroundState}"); - _interactiveSession.Push(InlineResponses.Default(_backgroundState)); - break; - } + // Send the response to the Calc + _interactiveSession.Push(InlineResponses.Default(_backgroundState)); + break; + case InlineKeyboardRequest.Finalize: + // Destroy the frontend. + DestroyFrontend(); + // The calling application wants to close the keyboard applet and will wait for a state change. + _backgroundState = InlineKeyboardState.Uninitialized; + AppletStateChanged?.Invoke(this, null); + break; + default: + // We shouldn't be able to get here through standard swkbd execution. + Logger.Warning?.Print(LogClass.ServiceAm, $"Invalid Software Keyboard request {request} during state {_backgroundState}"); + _interactiveSession.Push(InlineResponses.Default(_backgroundState)); + break; } } private void ActivateFrontend() { - Logger.Debug?.Print(LogClass.ServiceAm, $"Activating software keyboard frontend"); + Logger.Debug?.Print(LogClass.ServiceAm, "Activating software keyboard frontend"); _inputMode = KeyboardInputMode.ControllerAndKeyboard; @@ -509,9 +510,9 @@ namespace Ryujinx.HLE.HOS.Applets private void DeactivateFrontend() { - Logger.Debug?.Print(LogClass.ServiceAm, $"Deactivating software keyboard frontend"); + Logger.Debug?.Print(LogClass.ServiceAm, "Deactivating software keyboard frontend"); - _inputMode = KeyboardInputMode.ControllerAndKeyboard; + _inputMode = KeyboardInputMode.ControllerAndKeyboard; _canAcceptController = false; _dynamicTextInputHandler.TextProcessingEnabled = false; @@ -520,7 +521,7 @@ namespace Ryujinx.HLE.HOS.Applets private void DestroyFrontend() { - Logger.Debug?.Print(LogClass.ServiceAm, $"Destroying software keyboard frontend"); + Logger.Debug?.Print(LogClass.ServiceAm, "Destroying software keyboard frontend"); _keyboardRenderer?.Dispose(); _keyboardRenderer = null; @@ -528,7 +529,7 @@ namespace Ryujinx.HLE.HOS.Applets if (_dynamicTextInputHandler != null) { _dynamicTextInputHandler.TextChangedEvent -= HandleTextChangedEvent; - _dynamicTextInputHandler.KeyPressedEvent -= HandleKeyPressedEvent; + _dynamicTextInputHandler.KeyPressedEvent -= HandleKeyPressedEvent; _dynamicTextInputHandler.Dispose(); _dynamicTextInputHandler = null; } @@ -536,7 +537,7 @@ namespace Ryujinx.HLE.HOS.Applets if (_npads != null) { _npads.NpadButtonDownEvent -= HandleNpadButtonDownEvent; - _npads.NpadButtonUpEvent -= HandleNpadButtonUpEvent; + _npads.NpadButtonUpEvent -= HandleNpadButtonUpEvent; _npads = null; } } @@ -551,7 +552,7 @@ namespace Ryujinx.HLE.HOS.Applets { AdvanceInputMode(); - bool typingEnabled = InputModeTypingEnabled(); + bool typingEnabled = InputModeTypingEnabled(); bool controllerEnabled = InputModeControllerEnabled(); _dynamicTextInputHandler.TextProcessingEnabled = typingEnabled; @@ -575,14 +576,14 @@ namespace Ryujinx.HLE.HOS.Applets if (text.Length > MaxUiTextSize) { // Limit the text size and change it back. - text = text.Substring(0, MaxUiTextSize); + text = text[..MaxUiTextSize]; cursorBegin = Math.Min(cursorBegin, MaxUiTextSize); - cursorEnd = Math.Min(cursorEnd, MaxUiTextSize); + cursorEnd = Math.Min(cursorEnd, MaxUiTextSize); _dynamicTextInputHandler.SetText(text, cursorBegin, cursorEnd); } - _textValue = text; + _textValue = text; _cursorBegin = cursorBegin; _keyboardRenderer.UpdateTextState(text, cursorBegin, cursorEnd, overwriteMode, null); @@ -646,7 +647,7 @@ namespace Ryujinx.HLE.HOS.Applets private void PushUpdatedState(string text, int cursorBegin, KeyboardResult result) { _lastResult = result; - _textValue = text; + _textValue = text; bool cancel = result == KeyboardResult.Cancel; bool accept = result == KeyboardResult.Accept; @@ -734,33 +735,31 @@ namespace Ryujinx.HLE.HOS.Applets { int bufferSize = interactive ? InteractiveBufferSize : StandardBufferSize; - using (MemoryStream stream = new MemoryStream(new byte[bufferSize])) - using (BinaryWriter writer = new BinaryWriter(stream)) + using MemoryStream stream = new(new byte[bufferSize]); + using BinaryWriter writer = new(stream); + byte[] output = _encoding.GetBytes(_textValue); + + if (!interactive) { - byte[] output = _encoding.GetBytes(_textValue); + // Result Code. + writer.Write(_lastResult == KeyboardResult.Accept ? 0U : 1U); + } + else + { + // In interactive mode, we write the length of the text as a long, rather than + // a result code. This field is inclusive of the 64-bit size. + writer.Write((long)output.Length + 8); + } - if (!interactive) - { - // Result Code. - writer.Write(_lastResult == KeyboardResult.Accept ? 0U : 1U); - } - else - { - // In interactive mode, we write the length of the text as a long, rather than - // a result code. This field is inclusive of the 64-bit size. - writer.Write((long)output.Length + 8); - } + writer.Write(output); - writer.Write(output); - - if (!interactive) - { - _normalSession.Push(stream.ToArray()); - } - else - { - _interactiveSession.Push(stream.ToArray()); - } + if (!interactive) + { + _normalSession.Push(stream.ToArray()); + } + else + { + _interactiveSession.Push(stream.ToArray()); } } @@ -787,7 +786,7 @@ namespace Ryujinx.HLE.HOS.Applets return string.Empty; } - StringBuilder sb = new StringBuilder(capacity: input.Length); + StringBuilder sb = new(capacity: input.Length); foreach (char c in input) { if (!char.IsControl(c)) diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardCalc.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardCalc.cs index 90df6fa35..2941e15d1 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardCalc.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardCalc.cs @@ -174,45 +174,46 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard public SoftwareKeyboardCalcEx ToExtended() { - SoftwareKeyboardCalcEx calc = new SoftwareKeyboardCalcEx(); - - calc.Unknown = Unknown; - calc.Size = Size; - calc.Unknown1 = Unknown1; - calc.Unknown2 = Unknown2; - calc.Flags = Flags; - calc.Initialize = Initialize; - calc.Volume = Volume; - calc.CursorPos = CursorPos; - calc.Appear = Appear.ToExtended(); - calc.InputText = InputText; - calc.UseUtf8 = UseUtf8; - calc.Unknown3 = Unknown3; - calc.BackspaceEnabled = BackspaceEnabled; - calc.Unknown4 = Unknown4; - calc.Unknown5 = Unknown5; - calc.KeytopAsFloating = KeytopAsFloating; - calc.FooterScalable = FooterScalable; - calc.AlphaEnabledInInputMode = AlphaEnabledInInputMode; - calc.InputModeFadeType = InputModeFadeType; - calc.TouchDisabled = TouchDisabled; - calc.HardwareKeyboardDisabled = HardwareKeyboardDisabled; - calc.Unknown6 = Unknown6; - calc.Unknown7 = Unknown7; - calc.KeytopScale0 = KeytopScale0; - calc.KeytopScale1 = KeytopScale1; - calc.KeytopTranslate0 = KeytopTranslate0; - calc.KeytopTranslate1 = KeytopTranslate1; - calc.KeytopBgAlpha = KeytopBgAlpha; - calc.FooterBgAlpha = FooterBgAlpha; - calc.BalloonScale = BalloonScale; - calc.Unknown8 = Unknown8; - calc.Unknown9 = Unknown9; - calc.Unknown10 = Unknown10; - calc.Unknown11 = Unknown11; - calc.SeGroup = SeGroup; - calc.TriggerFlag = TriggerFlag; - calc.Trigger = Trigger; + SoftwareKeyboardCalcEx calc = new() + { + Unknown = Unknown, + Size = Size, + Unknown1 = Unknown1, + Unknown2 = Unknown2, + Flags = Flags, + Initialize = Initialize, + Volume = Volume, + CursorPos = CursorPos, + Appear = Appear.ToExtended(), + InputText = InputText, + UseUtf8 = UseUtf8, + Unknown3 = Unknown3, + BackspaceEnabled = BackspaceEnabled, + Unknown4 = Unknown4, + Unknown5 = Unknown5, + KeytopAsFloating = KeytopAsFloating, + FooterScalable = FooterScalable, + AlphaEnabledInInputMode = AlphaEnabledInInputMode, + InputModeFadeType = InputModeFadeType, + TouchDisabled = TouchDisabled, + HardwareKeyboardDisabled = HardwareKeyboardDisabled, + Unknown6 = Unknown6, + Unknown7 = Unknown7, + KeytopScale0 = KeytopScale0, + KeytopScale1 = KeytopScale1, + KeytopTranslate0 = KeytopTranslate0, + KeytopTranslate1 = KeytopTranslate1, + KeytopBgAlpha = KeytopBgAlpha, + FooterBgAlpha = FooterBgAlpha, + BalloonScale = BalloonScale, + Unknown8 = Unknown8, + Unknown9 = Unknown9, + Unknown10 = Unknown10, + Unknown11 = Unknown11, + SeGroup = SeGroup, + TriggerFlag = TriggerFlag, + Trigger = Trigger, + }; return calc; } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardConfig.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardConfig.cs index fd462382b..58c389e1a 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardConfig.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardConfig.cs @@ -8,10 +8,10 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] struct SoftwareKeyboardConfig { - private const int SubmitTextLength = 8; - private const int HeaderTextLength = 64; + private const int SubmitTextLength = 8; + private const int HeaderTextLength = 64; private const int SubtitleTextLength = 128; - private const int GuideTextLength = 256; + private const int GuideTextLength = 256; /// /// Type of keyboard. diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs index fb4cec82a..2331e36ab 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs @@ -10,16 +10,16 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard /// internal class SoftwareKeyboardRenderer : IDisposable { - private const int TextBoxBlinkSleepMilliseconds = 100; + private const int TextBoxBlinkSleepMilliseconds = 100; private const int RendererWaitTimeoutMilliseconds = 100; - private readonly object _stateLock = new(); + private readonly object _stateLock = new(); - private SoftwareKeyboardUiState _state = new SoftwareKeyboardUiState(); - private SoftwareKeyboardRendererBase _renderer; + private readonly SoftwareKeyboardUiState _state = new(); + private readonly SoftwareKeyboardRendererBase _renderer; - private TimedAction _textBoxBlinkTimedAction = new TimedAction(); - private TimedAction _renderAction = new TimedAction(); + private readonly TimedAction _textBoxBlinkTimedAction = new(); + private readonly TimedAction _renderAction = new(); public SoftwareKeyboardRenderer(IHostUiTheme uiTheme) { @@ -47,10 +47,10 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard private static void StartRenderer(TimedAction timedAction, SoftwareKeyboardRendererBase renderer, SoftwareKeyboardUiState state, object stateLock) { - SoftwareKeyboardUiState internalState = new SoftwareKeyboardUiState(); + SoftwareKeyboardUiState internalState = new(); bool canCreateSurface = false; - bool needsUpdate = true; + bool needsUpdate = true; timedAction.Reset(() => { @@ -61,6 +61,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard return; } +#pragma warning disable IDE0055 // Disable formatting needsUpdate = UpdateStateField(ref state.InputText, ref internalState.InputText); needsUpdate |= UpdateStateField(ref state.CursorBegin, ref internalState.CursorBegin); needsUpdate |= UpdateStateField(ref state.CursorEnd, ref internalState.CursorEnd); @@ -70,6 +71,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard needsUpdate |= UpdateStateField(ref state.TypingEnabled, ref internalState.TypingEnabled); needsUpdate |= UpdateStateField(ref state.ControllerEnabled, ref internalState.ControllerEnabled); needsUpdate |= UpdateStateField(ref state.TextBoxBlinkCounter, ref internalState.TextBoxBlinkCounter); +#pragma warning restore IDE0055 canCreateSurface = state.SurfaceInfo != null && internalState.SurfaceInfo == null; @@ -104,16 +106,14 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard return false; } -#pragma warning disable CS8632 - public void UpdateTextState(string? inputText, int? cursorBegin, int? cursorEnd, bool? overwriteMode, bool? typingEnabled) -#pragma warning restore CS8632 + public void UpdateTextState(string inputText, int? cursorBegin, int? cursorEnd, bool? overwriteMode, bool? typingEnabled) { lock (_stateLock) { // Update the parameters that were provided. - _state.InputText = inputText != null ? inputText : _state.InputText; - _state.CursorBegin = cursorBegin.GetValueOrDefault(_state.CursorBegin); - _state.CursorEnd = cursorEnd.GetValueOrDefault(_state.CursorEnd); + _state.InputText = inputText ?? _state.InputText; + _state.CursorBegin = cursorBegin.GetValueOrDefault(_state.CursorBegin); + _state.CursorEnd = cursorEnd.GetValueOrDefault(_state.CursorEnd); _state.OverwriteMode = overwriteMode.GetValueOrDefault(_state.OverwriteMode); _state.TypingEnabled = typingEnabled.GetValueOrDefault(_state.TypingEnabled); @@ -130,8 +130,8 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard lock (_stateLock) { // Update the parameters that were provided. - _state.AcceptPressed = acceptPressed.GetValueOrDefault(_state.AcceptPressed); - _state.CancelPressed = cancelPressed.GetValueOrDefault(_state.CancelPressed); + _state.AcceptPressed = acceptPressed.GetValueOrDefault(_state.AcceptPressed); + _state.CancelPressed = cancelPressed.GetValueOrDefault(_state.CancelPressed); _state.ControllerEnabled = controllerEnabled.GetValueOrDefault(_state.ControllerEnabled); // Tell the render thread there is something new to render. diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs index 595223ed3..770bf6e5a 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRendererBase.cs @@ -21,47 +21,47 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard { public const int TextBoxBlinkThreshold = 8; - const string MessageText = "Please use the keyboard to input text"; - const string AcceptText = "Accept"; - const string CancelText = "Cancel"; + const string MessageText = "Please use the keyboard to input text"; + const string AcceptText = "Accept"; + const string CancelText = "Cancel"; const string ControllerToggleText = "Toggle input"; private readonly object _bufferLock = new(); private RenderingSurfaceInfo _surfaceInfo = null; - private Image _surface = null; - private byte[] _bufferData = null; + private Image _surface = null; + private byte[] _bufferData = null; - private Image _ryujinxLogo = null; - private Image _padAcceptIcon = null; - private Image _padCancelIcon = null; - private Image _keyModeIcon = null; + private readonly Image _ryujinxLogo = null; + private readonly Image _padAcceptIcon = null; + private readonly Image _padCancelIcon = null; + private readonly Image _keyModeIcon = null; - private float _textBoxOutlineWidth; - private float _padPressedPenWidth; + private readonly float _textBoxOutlineWidth; + private readonly float _padPressedPenWidth; - private Color _textNormalColor; - private Color _textSelectedColor; - private Color _textOverCursorColor; + private readonly Color _textNormalColor; + private readonly Color _textSelectedColor; + private readonly Color _textOverCursorColor; - private IBrush _panelBrush; - private IBrush _disabledBrush; - private IBrush _cursorBrush; - private IBrush _selectionBoxBrush; + private readonly IBrush _panelBrush; + private readonly IBrush _disabledBrush; + private readonly IBrush _cursorBrush; + private readonly IBrush _selectionBoxBrush; - private Pen _textBoxOutlinePen; - private Pen _cursorPen; - private Pen _selectionBoxPen; - private Pen _padPressedPen; + private readonly Pen _textBoxOutlinePen; + private readonly Pen _cursorPen; + private readonly Pen _selectionBoxPen; + private readonly Pen _padPressedPen; - private int _inputTextFontSize; + private readonly int _inputTextFontSize; private Font _messageFont; private Font _inputTextFont; private Font _labelsTextFont; private RectangleF _panelRectangle; - private Point _logoPosition; - private float _messagePositionY; + private Point _logoPosition; + private float _messagePositionY; public SoftwareKeyboardRendererBase(IHostUiTheme uiTheme) { @@ -72,35 +72,35 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard string padAcceptIconPath = "Ryujinx.HLE.HOS.Applets.SoftwareKeyboard.Resources.Icon_BtnA.png"; string padCancelIconPath = "Ryujinx.HLE.HOS.Applets.SoftwareKeyboard.Resources.Icon_BtnB.png"; - string keyModeIconPath = "Ryujinx.HLE.HOS.Applets.SoftwareKeyboard.Resources.Icon_KeyF6.png"; + string keyModeIconPath = "Ryujinx.HLE.HOS.Applets.SoftwareKeyboard.Resources.Icon_KeyF6.png"; - _padAcceptIcon = LoadResource(Assembly.GetExecutingAssembly(), padAcceptIconPath , 0, 0); - _padCancelIcon = LoadResource(Assembly.GetExecutingAssembly(), padCancelIconPath , 0, 0); - _keyModeIcon = LoadResource(Assembly.GetExecutingAssembly(), keyModeIconPath , 0, 0); + _padAcceptIcon = LoadResource(Assembly.GetExecutingAssembly(), padAcceptIconPath, 0, 0); + _padCancelIcon = LoadResource(Assembly.GetExecutingAssembly(), padCancelIconPath, 0, 0); + _keyModeIcon = LoadResource(Assembly.GetExecutingAssembly(), keyModeIconPath, 0, 0); - Color panelColor = ToColor(uiTheme.DefaultBackgroundColor, 255); - Color panelTransparentColor = ToColor(uiTheme.DefaultBackgroundColor, 150); - Color borderColor = ToColor(uiTheme.DefaultBorderColor); + Color panelColor = ToColor(uiTheme.DefaultBackgroundColor, 255); + Color panelTransparentColor = ToColor(uiTheme.DefaultBackgroundColor, 150); + Color borderColor = ToColor(uiTheme.DefaultBorderColor); Color selectionBackgroundColor = ToColor(uiTheme.SelectionBackgroundColor); - _textNormalColor = ToColor(uiTheme.DefaultForegroundColor); - _textSelectedColor = ToColor(uiTheme.SelectionForegroundColor); + _textNormalColor = ToColor(uiTheme.DefaultForegroundColor); + _textSelectedColor = ToColor(uiTheme.SelectionForegroundColor); _textOverCursorColor = ToColor(uiTheme.DefaultForegroundColor, null, true); float cursorWidth = 2; _textBoxOutlineWidth = 2; - _padPressedPenWidth = 2; + _padPressedPenWidth = 2; - _panelBrush = new SolidBrush(panelColor); - _disabledBrush = new SolidBrush(panelTransparentColor); - _cursorBrush = new SolidBrush(_textNormalColor); + _panelBrush = new SolidBrush(panelColor); + _disabledBrush = new SolidBrush(panelTransparentColor); + _cursorBrush = new SolidBrush(_textNormalColor); _selectionBoxBrush = new SolidBrush(selectionBackgroundColor); _textBoxOutlinePen = new Pen(borderColor, _textBoxOutlineWidth); - _cursorPen = new Pen(_textNormalColor, cursorWidth); - _selectionBoxPen = new Pen(selectionBackgroundColor, cursorWidth); - _padPressedPen = new Pen(borderColor, _padPressedPenWidth); + _cursorPen = new Pen(_textNormalColor, cursorWidth); + _selectionBoxPen = new Pen(selectionBackgroundColor, cursorWidth); + _padPressedPen = new Pen(borderColor, _padPressedPenWidth); _inputTextFontSize = 20; @@ -111,22 +111,21 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard { // Try a list of fonts in case any of them is not available in the system. - string[] availableFonts = new string[] - { + string[] availableFonts = { uiThemeFontFamily, "Liberation Sans", "FreeSans", "DejaVu Sans", - "Lucida Grande" + "Lucida Grande", }; foreach (string fontFamily in availableFonts) { try { - _messageFont = SystemFonts.CreateFont(fontFamily, 26, FontStyle.Regular); - _inputTextFont = SystemFonts.CreateFont(fontFamily, _inputTextFontSize, FontStyle.Regular); - _labelsTextFont = SystemFonts.CreateFont(fontFamily, 24, FontStyle.Regular); + _messageFont = SystemFonts.CreateFont(fontFamily, 26, FontStyle.Regular); + _inputTextFont = SystemFonts.CreateFont(fontFamily, _inputTextFontSize, FontStyle.Regular); + _labelsTextFont = SystemFonts.CreateFont(fontFamily, 24, FontStyle.Regular); return; } @@ -138,7 +137,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard throw new Exception($"None of these fonts were found in the system: {String.Join(", ", availableFonts)}!"); } - private Color ToColor(ThemeColor color, byte? overrideAlpha = null, bool flipRgb = false) + private static Color ToColor(ThemeColor color, byte? overrideAlpha = null, bool flipRgb = false) { var a = (byte)(color.A * 255); var r = (byte)(color.R * 255); @@ -155,14 +154,14 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard return Color.FromRgba(r, g, b, overrideAlpha.GetValueOrDefault(a)); } - private Image LoadResource(Assembly assembly, string resourcePath, int newWidth, int newHeight) + private static Image LoadResource(Assembly assembly, string resourcePath, int newWidth, int newHeight) { Stream resourceStream = assembly.GetManifestResourceStream(resourcePath); return LoadResource(resourceStream, newWidth, newHeight); } - private Image LoadResource(Stream resourceStream, int newWidth, int newHeight) + private static Image LoadResource(Stream resourceStream, int newWidth, int newHeight) { Debug.Assert(resourceStream != null); @@ -176,7 +175,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard return image; } - private void SetGraphicsOptions(IImageProcessingContext context) + private static void SetGraphicsOptions(IImageProcessingContext context) { context.GetGraphicsOptions().Antialias = true; context.GetShapeGraphicsOptions().GraphicsOptions.Antialias = true; @@ -198,9 +197,9 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard context.DrawImage(_ryujinxLogo, _logoPosition, 1); float halfWidth = _panelRectangle.Width / 2; - float buttonsY = _panelRectangle.Y + 185; + float buttonsY = _panelRectangle.Y + 185; - PointF disableButtonPosition = new PointF(halfWidth + 180, buttonsY); + PointF disableButtonPosition = new(halfWidth + 180, buttonsY); DrawControllerToggle(context, disableButtonPosition); }); @@ -215,11 +214,11 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard _surface.Mutate(context => { - var messageRectangle = MeasureString(MessageText, _messageFont); - float messagePositionX = (_panelRectangle.Width - messageRectangle.Width) / 2 - messageRectangle.X; - float messagePositionY = _messagePositionY - messageRectangle.Y; - var messagePosition = new PointF(messagePositionX, messagePositionY); - var messageBoundRectangle = new RectangleF(messagePositionX, messagePositionY, messageRectangle.Width, messageRectangle.Height); + var messageRectangle = MeasureString(MessageText, _messageFont); + float messagePositionX = (_panelRectangle.Width - messageRectangle.Width) / 2 - messageRectangle.X; + float messagePositionY = _messagePositionY - messageRectangle.Y; + var messagePosition = new PointF(messagePositionX, messagePositionY); + var messageBoundRectangle = new RectangleF(messagePositionX, messagePositionY, messageRectangle.Width, messageRectangle.Height); SetGraphicsOptions(context); @@ -238,11 +237,11 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard DrawTextBox(context, state); float halfWidth = _panelRectangle.Width / 2; - float buttonsY = _panelRectangle.Y + 185; + float buttonsY = _panelRectangle.Y + 185; - PointF acceptButtonPosition = new PointF(halfWidth - 180, buttonsY); - PointF cancelButtonPosition = new PointF(halfWidth , buttonsY); - PointF disableButtonPosition = new PointF(halfWidth + 180, buttonsY); + PointF acceptButtonPosition = new(halfWidth - 180, buttonsY); + PointF cancelButtonPosition = new(halfWidth, buttonsY); + PointF disableButtonPosition = new(halfWidth + 180, buttonsY); DrawPadButton(context, acceptButtonPosition, _padAcceptIcon, AcceptText, state.AcceptPressed, state.ControllerEnabled); DrawPadButton(context, cancelButtonPosition, _padCancelIcon, CancelText, state.CancelPressed, state.ControllerEnabled); @@ -262,7 +261,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard // Use the whole area of the image to draw, even the alignment, otherwise it may shear the final // image if the pitch is different. - uint totalWidth = _surfaceInfo.Pitch / 4; + uint totalWidth = _surfaceInfo.Pitch / 4; uint totalHeight = _surfaceInfo.Size / _surfaceInfo.Pitch; Debug.Assert(_surfaceInfo.Width <= totalWidth); @@ -277,10 +276,10 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard private void ComputeConstants() { - int totalWidth = (int)_surfaceInfo.Width; + int totalWidth = (int)_surfaceInfo.Width; int totalHeight = (int)_surfaceInfo.Height; - int panelHeight = 240; + int panelHeight = 240; int panelPositionY = totalHeight - panelHeight; _panelRectangle = new RectangleF(0, panelPositionY, totalWidth, panelHeight); @@ -294,7 +293,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard } private static RectangleF MeasureString(string text, Font font) { - RendererOptions options = new RendererOptions(font); + RendererOptions options = new(font); if (text == "") { @@ -310,7 +309,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard private static RectangleF MeasureString(ReadOnlySpan text, Font font) { - RendererOptions options = new RendererOptions(font); + RendererOptions options = new(font); if (text == "") { @@ -327,14 +326,14 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard { var inputTextRectangle = MeasureString(state.InputText, _inputTextFont); - float boxWidth = (int)(Math.Max(300, inputTextRectangle.Width + inputTextRectangle.X + 8)); + float boxWidth = (int)(Math.Max(300, inputTextRectangle.Width + inputTextRectangle.X + 8)); float boxHeight = 32; - float boxY = _panelRectangle.Y + 110; - float boxX = (int)((_panelRectangle.Width - boxWidth) / 2); + float boxY = _panelRectangle.Y + 110; + float boxX = (int)((_panelRectangle.Width - boxWidth) / 2); - RectangleF boxRectangle = new RectangleF(boxX, boxY, boxWidth, boxHeight); + RectangleF boxRectangle = new(boxX, boxY, boxWidth, boxHeight); - RectangleF boundRectangle = new RectangleF(_panelRectangle.X, boxY - _textBoxOutlineWidth, + RectangleF boundRectangle = new(_panelRectangle.X, boxY - _textBoxOutlineWidth, _panelRectangle.Width, boxHeight + 2 * _textBoxOutlineWidth); context.Fill(_panelBrush, boundRectangle); @@ -350,11 +349,11 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard // Draw the cursor on top of the text and redraw the text with a different color if necessary. - Color cursorTextColor; + Color cursorTextColor; IBrush cursorBrush; - Pen cursorPen; + Pen cursorPen; - float cursorPositionYTop = inputTextY + 1; + float cursorPositionYTop = inputTextY + 1; float cursorPositionYBottom = cursorPositionYTop + _inputTextFontSize + 1; float cursorPositionXLeft; float cursorPositionXRight; @@ -366,34 +365,34 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard Debug.Assert(state.InputText.Length > 0); cursorTextColor = _textSelectedColor; - cursorBrush = _selectionBoxBrush; - cursorPen = _selectionBoxPen; + cursorBrush = _selectionBoxBrush; + cursorPen = _selectionBoxPen; ReadOnlySpan textUntilBegin = state.InputText.AsSpan(0, state.CursorBegin); - ReadOnlySpan textUntilEnd = state.InputText.AsSpan(0, state.CursorEnd); + ReadOnlySpan textUntilEnd = state.InputText.AsSpan(0, state.CursorEnd); var selectionBeginRectangle = MeasureString(textUntilBegin, _inputTextFont); - var selectionEndRectangle = MeasureString(textUntilEnd , _inputTextFont); + var selectionEndRectangle = MeasureString(textUntilEnd, _inputTextFont); - cursorVisible = true; - cursorPositionXLeft = inputTextX + selectionBeginRectangle.Width + selectionBeginRectangle.X; - cursorPositionXRight = inputTextX + selectionEndRectangle.Width + selectionEndRectangle.X; + cursorVisible = true; + cursorPositionXLeft = inputTextX + selectionBeginRectangle.Width + selectionBeginRectangle.X; + cursorPositionXRight = inputTextX + selectionEndRectangle.Width + selectionEndRectangle.X; } else { cursorTextColor = _textOverCursorColor; - cursorBrush = _cursorBrush; - cursorPen = _cursorPen; + cursorBrush = _cursorBrush; + cursorPen = _cursorPen; if (state.TextBoxBlinkCounter < TextBoxBlinkThreshold) { // Show the blinking cursor. - int cursorBegin = Math.Min(state.InputText.Length, state.CursorBegin); - ReadOnlySpan textUntilCursor = state.InputText.AsSpan(0, cursorBegin); - var cursorTextRectangle = MeasureString(textUntilCursor, _inputTextFont); + int cursorBegin = Math.Min(state.InputText.Length, state.CursorBegin); + ReadOnlySpan textUntilCursor = state.InputText.AsSpan(0, cursorBegin); + var cursorTextRectangle = MeasureString(textUntilCursor, _inputTextFont); - cursorVisible = true; + cursorVisible = true; cursorPositionXLeft = inputTextX + cursorTextRectangle.Width + cursorTextRectangle.X; if (state.OverwriteMode) @@ -402,8 +401,8 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard if (state.CursorBegin < state.InputText.Length) { - textUntilCursor = state.InputText.AsSpan(0, cursorBegin + 1); - cursorTextRectangle = MeasureString(textUntilCursor, _inputTextFont); + textUntilCursor = state.InputText.AsSpan(0, cursorBegin + 1); + cursorTextRectangle = MeasureString(textUntilCursor, _inputTextFont); cursorPositionXRight = inputTextX + cursorTextRectangle.Width + cursorTextRectangle.X; } else @@ -419,20 +418,19 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard } else { - cursorPositionXLeft = inputTextX; + cursorPositionXLeft = inputTextX; cursorPositionXRight = inputTextX; } } if (state.TypingEnabled && cursorVisible) { - float cursorWidth = cursorPositionXRight - cursorPositionXLeft; + float cursorWidth = cursorPositionXRight - cursorPositionXLeft; float cursorHeight = cursorPositionYBottom - cursorPositionYTop; if (cursorWidth == 0) { - PointF[] points = new PointF[] - { + PointF[] points = { new PointF(cursorPositionXLeft, cursorPositionYTop), new PointF(cursorPositionXLeft, cursorPositionYBottom), }; @@ -443,10 +441,10 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard { var cursorRectangle = new RectangleF(cursorPositionXLeft, cursorPositionYTop, cursorWidth, cursorHeight); - context.Draw(cursorPen , cursorRectangle); + context.Draw(cursorPen, cursorRectangle); context.Fill(cursorBrush, cursorRectangle); - Image textOverCursor = new Image((int)cursorRectangle.Width, (int)cursorRectangle.Height); + Image textOverCursor = new((int)cursorRectangle.Width, (int)cursorRectangle.Height); textOverCursor.Mutate(context => { var textRelativePosition = new PointF(inputTextPosition.X - cursorRectangle.X, inputTextPosition.Y - cursorRectangle.Y); @@ -470,9 +468,9 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard { // Use relative positions so we can center the the entire drawing later. - float iconX = 0; - float iconY = 0; - float iconWidth = icon.Width; + float iconX = 0; + float iconY = 0; + float iconWidth = icon.Width; float iconHeight = icon.Height; var labelRectangle = MeasureString(label, _labelsTextFont); @@ -480,18 +478,18 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard float labelPositionX = iconWidth + 8 - labelRectangle.X; float labelPositionY = 3; - float fullWidth = labelPositionX + labelRectangle.Width + labelRectangle.X; + float fullWidth = labelPositionX + labelRectangle.Width + labelRectangle.X; float fullHeight = iconHeight; // Convert all relative positions into absolute. - float originX = (int)(point.X - fullWidth / 2); + float originX = (int)(point.X - fullWidth / 2); float originY = (int)(point.Y - fullHeight / 2); iconX += originX; iconY += originY; - var iconPosition = new Point((int)iconX, (int)iconY); + var iconPosition = new Point((int)iconX, (int)iconY); var labelPosition = new PointF(labelPositionX + originX, labelPositionY + originY); var selectedRectangle = new RectangleF(originX - 2 * _padPressedPenWidth, originY - 2 * _padPressedPenWidth, @@ -526,7 +524,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard // Use relative positions so we can center the the entire drawing later. - float keyWidth = _keyModeIcon.Width; + float keyWidth = _keyModeIcon.Width; float keyHeight = _keyModeIcon.Height; float labelPositionX = keyWidth + 8 - labelRectangle.X; @@ -535,18 +533,18 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard float keyX = 0; float keyY = (int)((labelPositionY + labelRectangle.Height - keyHeight) / 2); - float fullWidth = labelPositionX + labelRectangle.Width; + float fullWidth = labelPositionX + labelRectangle.Width; float fullHeight = Math.Max(labelPositionY + labelRectangle.Height, keyHeight); // Convert all relative positions into absolute. - float originX = (int)(point.X - fullWidth / 2); + float originX = (int)(point.X - fullWidth / 2); float originY = (int)(point.Y - fullHeight / 2); keyX += originX; keyY += originY; - var labelPosition = new PointF(labelPositionX + originX, labelPositionY + originY); + var labelPosition = new PointF(labelPositionX + originX, labelPositionY + originY); var overlayPosition = new Point((int)keyX, (int)keyY); context.DrawImage(_keyModeIcon, overlayPosition, 1); diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardState.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardState.cs index 0f66fc9ba..92a943f27 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardState.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardState.cs @@ -23,6 +23,6 @@ /// /// swkbd has completed. /// - Complete + Complete, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardUiArgs.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardUiArgs.cs index d67a44094..52fa7ed85 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardUiArgs.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardUiArgs.cs @@ -13,4 +13,4 @@ namespace Ryujinx.HLE.HOS.Applets public int StringLengthMin; public int StringLengthMax; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardUiState.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardUiState.cs index e6131e62d..aed53d40d 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardUiState.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardUiState.cs @@ -7,15 +7,15 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard /// internal class SoftwareKeyboardUiState { - public string InputText = ""; - public int CursorBegin = 0; - public int CursorEnd = 0; - public bool AcceptPressed = false; - public bool CancelPressed = false; - public bool OverwriteMode = false; - public bool TypingEnabled = true; - public bool ControllerEnabled = true; - public int TextBoxBlinkCounter = 0; + public string InputText = ""; + public int CursorBegin = 0; + public int CursorEnd = 0; + public bool AcceptPressed = false; + public bool CancelPressed = false; + public bool OverwriteMode = false; + public bool TypingEnabled = true; + public bool ControllerEnabled = true; + public int TextBoxBlinkCounter = 0; public RenderingSurfaceInfo SurfaceInfo = null; } diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TimedAction.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TimedAction.cs index ed876ffd2..f44dc5da0 100644 --- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TimedAction.cs +++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TimedAction.cs @@ -19,8 +19,8 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard public SleepSubstepData(int sleepMilliseconds) { - SleepMilliseconds = Math.Min(sleepMilliseconds, MaxThreadSleep); - SleepCount = sleepMilliseconds / SleepMilliseconds; + SleepMilliseconds = Math.Min(sleepMilliseconds, MaxThreadSleep); + SleepCount = sleepMilliseconds / SleepMilliseconds; SleepRemainderMilliseconds = sleepMilliseconds - SleepCount * SleepMilliseconds; } } diff --git a/src/Ryujinx.HLE/HOS/ArmProcessContextFactory.cs b/src/Ryujinx.HLE/HOS/ArmProcessContextFactory.cs index 140b10a26..7ff055a69 100644 --- a/src/Ryujinx.HLE/HOS/ArmProcessContextFactory.cs +++ b/src/Ryujinx.HLE/HOS/ArmProcessContextFactory.cs @@ -96,7 +96,7 @@ namespace Ryujinx.HLE.HOS break; default: - throw new ArgumentOutOfRangeException(); + throw new InvalidOperationException($"{nameof(mode)} contains an invalid value: {mode}"); } } diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ArraySubscriptingExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ArraySubscriptingExpression.cs index 5145ff7b0..8248b420e 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ArraySubscriptingExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ArraySubscriptingExpression.cs @@ -4,12 +4,12 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class ArraySubscriptingExpression : BaseNode { - private BaseNode _leftNode; - private BaseNode _subscript; + private readonly BaseNode _leftNode; + private readonly BaseNode _subscript; public ArraySubscriptingExpression(BaseNode leftNode, BaseNode subscript) : base(NodeType.ArraySubscriptingExpression) { - _leftNode = leftNode; + _leftNode = leftNode; _subscript = subscript; } @@ -19,7 +19,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _leftNode.Print(writer); writer.Write(")["); _subscript.Print(writer); - writer.Write("]"); + writer.Write("]"); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ArrayType.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ArrayType.cs index 4b1041ab7..59fd915a7 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ArrayType.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ArrayType.cs @@ -4,19 +4,19 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class ArrayType : BaseNode { - private BaseNode _base; - private BaseNode _dimensionExpression; - private string _dimensionString; + private readonly BaseNode _base; + private readonly BaseNode _dimensionExpression; + private readonly string _dimensionString; public ArrayType(BaseNode Base, BaseNode dimensionExpression = null) : base(NodeType.ArrayType) { - _base = Base; + _base = Base; _dimensionExpression = dimensionExpression; } public ArrayType(BaseNode Base, string dimensionString) : base(NodeType.ArrayType) { - _base = Base; + _base = Base; _dimensionString = dimensionString; } @@ -46,9 +46,9 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { writer.Write(_dimensionString); } - else if (_dimensionExpression != null) + else { - _dimensionExpression.Print(writer); + _dimensionExpression?.Print(writer); } writer.Write("]"); @@ -56,4 +56,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _base.PrintRight(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BaseNode.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BaseNode.cs index ca4b98f88..fc60fb6e9 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BaseNode.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BaseNode.cs @@ -55,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast ConversionOperatorType, LocalName, CtorVtableSpecialName, - ArrayType + ArrayType, } public abstract class BaseNode @@ -99,15 +99,15 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast return null; } - public virtual void PrintRight(TextWriter writer) {} + public virtual void PrintRight(TextWriter writer) { } public override string ToString() { - StringWriter writer = new StringWriter(); + StringWriter writer = new(); Print(writer); return writer.ToString(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BinaryExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BinaryExpression.cs index 0c492df39..81ea80dbc 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BinaryExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BinaryExpression.cs @@ -4,14 +4,14 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class BinaryExpression : BaseNode { - private BaseNode _leftPart; - private string _name; - private BaseNode _rightPart; + private readonly BaseNode _leftPart; + private readonly string _name; + private readonly BaseNode _rightPart; public BinaryExpression(BaseNode leftPart, string name, BaseNode rightPart) : base(NodeType.BinaryExpression) { - _leftPart = leftPart; - _name = name; + _leftPart = leftPart; + _name = name; _rightPart = rightPart; } @@ -38,4 +38,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BracedExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BracedExpression.cs index 6b9782f5c..53fbb2040 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BracedExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BracedExpression.cs @@ -4,14 +4,14 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class BracedExpression : BaseNode { - private BaseNode _element; - private BaseNode _expression; - private bool _isArrayExpression; + private readonly BaseNode _element; + private readonly BaseNode _expression; + private readonly bool _isArrayExpression; public BracedExpression(BaseNode element, BaseNode expression, bool isArrayExpression) : base(NodeType.BracedExpression) { - _element = element; - _expression = expression; + _element = element; + _expression = expression; _isArrayExpression = isArrayExpression; } diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BracedRangeExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BracedRangeExpression.cs index 802422d9a..38d8ccd4d 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BracedRangeExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/BracedRangeExpression.cs @@ -4,14 +4,14 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class BracedRangeExpression : BaseNode { - private BaseNode _firstNode; - private BaseNode _lastNode; - private BaseNode _expression; + private readonly BaseNode _firstNode; + private readonly BaseNode _lastNode; + private readonly BaseNode _expression; public BracedRangeExpression(BaseNode firstNode, BaseNode lastNode, BaseNode expression) : base(NodeType.BracedRangeExpression) { - _firstNode = firstNode; - _lastNode = lastNode; + _firstNode = firstNode; + _lastNode = lastNode; _expression = expression; } diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CallExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CallExpression.cs index 8e3fc3e69..0ee2e9d77 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CallExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CallExpression.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class CallExpression : NodeArray { - private BaseNode _callee; + private readonly BaseNode _callee; public CallExpression(BaseNode callee, List nodes) : base(nodes, NodeType.CallExpression) { @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(")"); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CastExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CastExpression.cs index 1149a788c..b35d06dd4 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CastExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CastExpression.cs @@ -4,14 +4,14 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class CastExpression : BaseNode { - private string _kind; - private BaseNode _to; - private BaseNode _from; + private readonly string _kind; + private readonly BaseNode _to; + private readonly BaseNode _from; public CastExpression(string kind, BaseNode to, BaseNode from) : base(NodeType.CastExpression) { _kind = kind; - _to = to; + _to = to; _from = from; } @@ -25,4 +25,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(")"); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConditionalExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConditionalExpression.cs index c0dd67179..b441a377d 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConditionalExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConditionalExpression.cs @@ -4,15 +4,15 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class ConditionalExpression : BaseNode { - private BaseNode _thenNode; - private BaseNode _elseNode; - private BaseNode _conditionNode; + private readonly BaseNode _thenNode; + private readonly BaseNode _elseNode; + private readonly BaseNode _conditionNode; public ConditionalExpression(BaseNode conditionNode, BaseNode thenNode, BaseNode elseNode) : base(NodeType.ConditionalExpression) { - _thenNode = thenNode; + _thenNode = thenNode; _conditionNode = conditionNode; - _elseNode = elseNode; + _elseNode = elseNode; } public override void PrintLeft(TextWriter writer) @@ -26,4 +26,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(")"); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConversionExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConversionExpression.cs index dd1f7a008..d30912f46 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConversionExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConversionExpression.cs @@ -4,12 +4,12 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class ConversionExpression : BaseNode { - private BaseNode _typeNode; - private BaseNode _expressions; + private readonly BaseNode _typeNode; + private readonly BaseNode _expressions; public ConversionExpression(BaseNode typeNode, BaseNode expressions) : base(NodeType.ConversionExpression) { - _typeNode = typeNode; + _typeNode = typeNode; _expressions = expressions; } @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _expressions.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConversionOperatorType.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConversionOperatorType.cs index 8a5cde860..814b4a2fe 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConversionOperatorType.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ConversionOperatorType.cs @@ -12,4 +12,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast Child.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CtorDtorNameType.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CtorDtorNameType.cs index 5f4581235..068662a66 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CtorDtorNameType.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CtorDtorNameType.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class CtorDtorNameType : ParentNode { - private bool _isDestructor; + private readonly bool _isDestructor; public CtorDtorNameType(BaseNode name, bool isDestructor) : base(NodeType.CtorDtorNameType, name) { @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(Child.GetName()); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CtorVtableSpecialName.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CtorVtableSpecialName.cs index 3bb5b1631..924969565 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CtorVtableSpecialName.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/CtorVtableSpecialName.cs @@ -4,12 +4,12 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class CtorVtableSpecialName : BaseNode { - private BaseNode _firstType; - private BaseNode _secondType; + private readonly BaseNode _firstType; + private readonly BaseNode _secondType; public CtorVtableSpecialName(BaseNode firstType, BaseNode secondType) : base(NodeType.CtorVtableSpecialName) { - _firstType = firstType; + _firstType = firstType; _secondType = secondType; } @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _secondType.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DeleteExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DeleteExpression.cs index 14715d25e..20d0bd8a2 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DeleteExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DeleteExpression.cs @@ -4,12 +4,12 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class DeleteExpression : ParentNode { - private bool _isGlobal; - private bool _isArrayExpression; + private readonly bool _isGlobal; + private readonly bool _isArrayExpression; public DeleteExpression(BaseNode child, bool isGlobal, bool isArrayExpression) : base(NodeType.DeleteExpression, child) { - _isGlobal = isGlobal; + _isGlobal = isGlobal; _isArrayExpression = isArrayExpression; } @@ -30,4 +30,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast Child.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DtorName.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DtorName.cs index 5cc4e6cfb..b584dba93 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DtorName.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DtorName.cs @@ -12,4 +12,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast Child.PrintLeft(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DynamicExceptionSpec.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DynamicExceptionSpec.cs index faa91443a..98619b20b 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DynamicExceptionSpec.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/DynamicExceptionSpec.cs @@ -13,4 +13,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(")"); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ElaboratedType.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ElaboratedType.cs index 086cd3dc7..2877557d1 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ElaboratedType.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ElaboratedType.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class ElaboratedType : ParentNode { - private string _elaborated; + private readonly string _elaborated; public ElaboratedType(string elaborated, BaseNode type) : base(NodeType.ElaboratedType, type) { @@ -18,4 +18,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast Child.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/EnclosedExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/EnclosedExpression.cs index b45481ddc..178db5129 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/EnclosedExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/EnclosedExpression.cs @@ -4,15 +4,15 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class EnclosedExpression : BaseNode { - private string _prefix; - private BaseNode _expression; - private string _postfix; + private readonly string _prefix; + private readonly BaseNode _expression; + private readonly string _postfix; public EnclosedExpression(string prefix, BaseNode expression, string postfix) : base(NodeType.EnclosedExpression) { - _prefix = prefix; + _prefix = prefix; _expression = expression; - _postfix = postfix; + _postfix = postfix; } public override void PrintLeft(TextWriter writer) @@ -22,4 +22,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(_postfix); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/EncodedFunction.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/EncodedFunction.cs index c7b6dab1a..de5598044 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/EncodedFunction.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/EncodedFunction.cs @@ -4,21 +4,21 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class EncodedFunction : BaseNode { - private BaseNode _name; - private BaseNode _params; - private BaseNode _cv; - private BaseNode _ref; - private BaseNode _attrs; - private BaseNode _ret; + private readonly BaseNode _name; + private readonly BaseNode _params; + private readonly BaseNode _cv; + private readonly BaseNode _ref; + private readonly BaseNode _attrs; + private readonly BaseNode _ret; public EncodedFunction(BaseNode name, BaseNode Params, BaseNode cv, BaseNode Ref, BaseNode attrs, BaseNode ret) : base(NodeType.NameType) { - _name = name; + _name = name; _params = Params; - _cv = cv; - _ref = Ref; - _attrs = attrs; - _ret = ret; + _cv = cv; + _ref = Ref; + _attrs = attrs; + _ret = ret; } public override void PrintLeft(TextWriter writer) @@ -45,33 +45,12 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast public override void PrintRight(TextWriter writer) { writer.Write("("); - - if (_params != null) - { - _params.Print(writer); - } - + _params?.Print(writer); writer.Write(")"); - - if (_ret != null) - { - _ret.PrintRight(writer); - } - - if (_cv != null) - { - _cv.Print(writer); - } - - if (_ref != null) - { - _ref.Print(writer); - } - - if (_attrs != null) - { - _attrs.Print(writer); - } + _ret?.PrintRight(writer); + _cv?.Print(writer); + _ref?.Print(writer); + _attrs?.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FoldExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FoldExpression.cs index 04f7053e3..ed73fa09a 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FoldExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FoldExpression.cs @@ -4,17 +4,17 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class FoldExpression : BaseNode { - private bool _isLeftFold; - private string _operatorName; - private BaseNode _expression; - private BaseNode _initializer; + private readonly bool _isLeftFold; + private readonly string _operatorName; + private readonly BaseNode _expression; + private readonly BaseNode _initializer; public FoldExpression(bool isLeftFold, string operatorName, BaseNode expression, BaseNode initializer) : base(NodeType.FunctionParameter) { - _isLeftFold = isLeftFold; + _isLeftFold = isLeftFold; _operatorName = operatorName; - _expression = expression; - _initializer = initializer; + _expression = expression; + _initializer = initializer; } public override void PrintLeft(TextWriter writer) @@ -45,4 +45,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(")"); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ForwardTemplateReference.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ForwardTemplateReference.cs index 1bbf6ef9a..30c838ca0 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ForwardTemplateReference.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ForwardTemplateReference.cs @@ -6,7 +6,9 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { // TODO: Compute inside the Demangler public BaseNode Reference; - private int _index; +#pragma warning disable IDE0052 // Remove unread private member + private readonly int _index; +#pragma warning restore IDE0052 public ForwardTemplateReference(int index) : base(NodeType.ForwardTemplateReference) { diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FunctionParameter.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FunctionParameter.cs index 5654a048f..9c2d0955f 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FunctionParameter.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FunctionParameter.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class FunctionParameter : BaseNode { - private string _number; + private readonly string _number; public FunctionParameter(string number) : base(NodeType.FunctionParameter) { @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FunctionType.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FunctionType.cs index 4ad0c9f5f..431c21119 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FunctionType.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/FunctionType.cs @@ -4,19 +4,19 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class FunctionType : BaseNode { - private BaseNode _returnType; - private BaseNode _params; - private BaseNode _cvQualifier; - private SimpleReferenceType _referenceQualifier; - private BaseNode _exceptionSpec; + private readonly BaseNode _returnType; + private readonly BaseNode _params; + private readonly BaseNode _cvQualifier; + private readonly SimpleReferenceType _referenceQualifier; + private readonly BaseNode _exceptionSpec; public FunctionType(BaseNode returnType, BaseNode Params, BaseNode cvQualifier, SimpleReferenceType referenceQualifier, BaseNode exceptionSpec) : base(NodeType.FunctionType) { - _returnType = returnType; - _params = Params; - _cvQualifier = cvQualifier; + _returnType = returnType; + _params = Params; + _cvQualifier = cvQualifier; _referenceQualifier = referenceQualifier; - _exceptionSpec = exceptionSpec; + _exceptionSpec = exceptionSpec; } public override void PrintLeft(TextWriter writer) @@ -58,4 +58,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast return true; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/InitListExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/InitListExpression.cs index 7155dd601..908319c31 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/InitListExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/InitListExpression.cs @@ -5,25 +5,22 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class InitListExpression : BaseNode { - private BaseNode _typeNode; - private List _nodes; + private readonly BaseNode _typeNode; + private readonly List _nodes; public InitListExpression(BaseNode typeNode, List nodes) : base(NodeType.InitListExpression) { _typeNode = typeNode; - _nodes = nodes; + _nodes = nodes; } public override void PrintLeft(TextWriter writer) { - if (_typeNode != null) - { - _typeNode.Print(writer); - } + _typeNode?.Print(writer); writer.Write("{"); writer.Write(string.Join(", ", _nodes.ToArray())); writer.Write("}"); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerCastExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerCastExpression.cs index ef07414de..eed36b218 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerCastExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerCastExpression.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class IntegerCastExpression : ParentNode { - private string _number; + private readonly string _number; public IntegerCastExpression(BaseNode type, string number) : base(NodeType.IntegerCastExpression, type) { @@ -19,4 +19,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(_number); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerLiteral.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerLiteral.cs index 33752d00c..762ef7aea 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerLiteral.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerLiteral.cs @@ -5,13 +5,13 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class IntegerLiteral : BaseNode { - private string _literalName; - private string _literalValue; + private readonly string _literalName; + private readonly string _literalValue; public IntegerLiteral(string literalName, string literalValue) : base(NodeType.IntegerLiteral) { _literalValue = literalValue; - _literalName = literalName; + _literalName = literalName; } public override void PrintLeft(TextWriter writer) @@ -39,4 +39,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/LiteralOperator.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/LiteralOperator.cs index f7e86c9e2..f2c934afa 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/LiteralOperator.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/LiteralOperator.cs @@ -13,4 +13,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write("\""); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/LocalName.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/LocalName.cs index 15d46b387..661043b44 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/LocalName.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/LocalName.cs @@ -4,13 +4,13 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class LocalName : BaseNode { - private BaseNode _encoding; - private BaseNode _entity; + private readonly BaseNode _encoding; + private readonly BaseNode _entity; public LocalName(BaseNode encoding, BaseNode entity) : base(NodeType.LocalName) { _encoding = encoding; - _entity = entity; + _entity = entity; } public override void PrintLeft(TextWriter writer) @@ -20,4 +20,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _entity.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/MemberExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/MemberExpression.cs index 9b91f6f5d..6617ec208 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/MemberExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/MemberExpression.cs @@ -4,14 +4,14 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class MemberExpression : BaseNode { - private BaseNode _leftNode; - private string _kind; - private BaseNode _rightNode; + private readonly BaseNode _leftNode; + private readonly string _kind; + private readonly BaseNode _rightNode; public MemberExpression(BaseNode leftNode, string kind, BaseNode rightNode) : base(NodeType.MemberExpression) { - _leftNode = leftNode; - _kind = kind; + _leftNode = leftNode; + _kind = kind; _rightNode = rightNode; } @@ -22,4 +22,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _rightNode.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NameType.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NameType.cs index f9f4cb20e..5ea21a2b7 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NameType.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NameType.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class NameType : BaseNode { - private string _nameValue; + private readonly string _nameValue; public NameType(string nameValue, NodeType type) : base(type) { @@ -26,4 +26,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(_nameValue); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NameTypeWithTemplateArguments.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NameTypeWithTemplateArguments.cs index ee725f36b..9512926a9 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NameTypeWithTemplateArguments.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NameTypeWithTemplateArguments.cs @@ -4,12 +4,12 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class NameTypeWithTemplateArguments : BaseNode { - private BaseNode _prev; - private BaseNode _templateArgument; + private readonly BaseNode _prev; + private readonly BaseNode _templateArgument; public NameTypeWithTemplateArguments(BaseNode prev, BaseNode templateArgument) : base(NodeType.NameTypeWithTemplateArguments) { - _prev = prev; + _prev = prev; _templateArgument = templateArgument; } @@ -17,11 +17,11 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { return _prev.GetName(); } - + public override void PrintLeft(TextWriter writer) { _prev.Print(writer); _templateArgument.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NestedName.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NestedName.cs index 640c200cb..cadea66c6 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NestedName.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NestedName.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class NestedName : ParentNode { - private BaseNode _name; + private readonly BaseNode _name; public NestedName(BaseNode name, BaseNode type) : base(NodeType.NestedName, type) { @@ -23,4 +23,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _name.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NewExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NewExpression.cs index ba4690af4..4c321afd3 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NewExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NewExpression.cs @@ -4,20 +4,20 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class NewExpression : BaseNode { - private NodeArray _expressions; - private BaseNode _typeNode; - private NodeArray _initializers; + private readonly NodeArray _expressions; + private readonly BaseNode _typeNode; + private readonly NodeArray _initializers; - private bool _isGlobal; - private bool _isArrayExpression; + private readonly bool _isGlobal; + private readonly bool _isArrayExpression; public NewExpression(NodeArray expressions, BaseNode typeNode, NodeArray initializers, bool isGlobal, bool isArrayExpression) : base(NodeType.NewExpression) { - _expressions = expressions; - _typeNode = typeNode; - _initializers = initializers; + _expressions = expressions; + _typeNode = typeNode; + _initializers = initializers; - _isGlobal = isGlobal; + _isGlobal = isGlobal; _isArrayExpression = isArrayExpression; } @@ -52,4 +52,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NodeArray.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NodeArray.cs index 1482dfc37..395ad1a05 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NodeArray.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/NodeArray.cs @@ -27,4 +27,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(string.Join(", ", Nodes.ToArray())); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PackedTemplateParameter.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PackedTemplateParameter.cs index 4c8200958..23104fff0 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PackedTemplateParameter.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PackedTemplateParameter.cs @@ -36,4 +36,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast return false; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PackedTemplateParameterExpansion.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PackedTemplateParameterExpansion.cs index c3645044a..45e4084a4 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PackedTemplateParameterExpansion.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PackedTemplateParameterExpansion.cs @@ -4,15 +4,15 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class PackedTemplateParameterExpansion : ParentNode { - public PackedTemplateParameterExpansion(BaseNode child) : base(NodeType.PackedTemplateParameterExpansion, child) {} + public PackedTemplateParameterExpansion(BaseNode child) : base(NodeType.PackedTemplateParameterExpansion, child) { } public override void PrintLeft(TextWriter writer) { - if (Child is PackedTemplateParameter) + if (Child is PackedTemplateParameter parameter) { - if (((PackedTemplateParameter)Child).Nodes.Count != 0) + if (parameter.Nodes.Count != 0) { - Child.Print(writer); + parameter.Print(writer); } } else @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ParentNode.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ParentNode.cs index 786abced8..848727db2 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ParentNode.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ParentNode.cs @@ -14,4 +14,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast return Child.GetName(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PointerType.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PointerType.cs index b1a3ec422..f331e8331 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PointerType.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PointerType.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class PointerType : BaseNode { - private BaseNode _child; + private readonly BaseNode _child; public PointerType(BaseNode child) : base(NodeType.PointerType) { @@ -42,4 +42,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _child.PrintRight(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PostfixExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PostfixExpression.cs index ccaea3ba7..dfbe11ae3 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PostfixExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PostfixExpression.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class PostfixExpression : ParentNode { - private string _operator; + private readonly string _operator; public PostfixExpression(BaseNode type, string Operator) : base(NodeType.PostfixExpression, type) { @@ -19,4 +19,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(_operator); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PostfixQualifiedType.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PostfixQualifiedType.cs index 5024a8f99..ec1dd142f 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PostfixQualifiedType.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PostfixQualifiedType.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class PostfixQualifiedType : ParentNode { - private string _postfixQualifier; + private readonly string _postfixQualifier; public PostfixQualifiedType(string postfixQualifier, BaseNode type) : base(NodeType.PostfixQualifiedType, type) { @@ -17,4 +17,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(_postfixQualifier); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PrefixExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PrefixExpression.cs index 9c3d4552a..309c575d9 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PrefixExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/PrefixExpression.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class PrefixExpression : ParentNode { - private string _prefix; + private readonly string _prefix; public PrefixExpression(string prefix, BaseNode child) : base(NodeType.PrefixExpression, child) { @@ -19,4 +19,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(")"); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/QualifiedName.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/QualifiedName.cs index 2e18f564e..ae43f0418 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/QualifiedName.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/QualifiedName.cs @@ -4,13 +4,13 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class QualifiedName : BaseNode { - private BaseNode _qualifier; - private BaseNode _name; + private readonly BaseNode _qualifier; + private readonly BaseNode _name; public QualifiedName(BaseNode qualifier, BaseNode name) : base(NodeType.QualifiedName) { _qualifier = qualifier; - _name = name; + _name = name; } public override void PrintLeft(TextWriter writer) @@ -20,4 +20,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _name.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/Qualifier.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/Qualifier.cs index cb6dd6bf6..e926c3443 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/Qualifier.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/Qualifier.cs @@ -7,14 +7,14 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast None, Const, Volatile, - Restricted = 4 + Restricted = 4, } public enum Reference { None, RValue, - LValue + LValue, } public class CvType : ParentNode @@ -46,10 +46,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast public override void PrintLeft(TextWriter writer) { - if (Child != null) - { - Child.PrintLeft(writer); - } + Child?.PrintLeft(writer); PrintQualifier(writer); } @@ -61,10 +58,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast public override void PrintRight(TextWriter writer) { - if (Child != null) - { - Child.PrintRight(writer); - } + Child?.PrintRight(writer); } } @@ -111,10 +105,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast public override void PrintRight(TextWriter writer) { - if (Child != null) - { - Child.PrintRight(writer); - } + Child?.PrintRight(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ReferenceType.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ReferenceType.cs index a3214171f..22a601c91 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ReferenceType.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ReferenceType.cs @@ -4,13 +4,13 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class ReferenceType : BaseNode { - private string _reference; - private BaseNode _child; + private readonly string _reference; + private readonly BaseNode _child; public ReferenceType(string reference, BaseNode child) : base(NodeType.ReferenceType) { _reference = reference; - _child = child; + _child = child; } public override bool HasRightPart() @@ -44,4 +44,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _child.PrintRight(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/SpecialName.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/SpecialName.cs index 1447458b3..8a968d63d 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/SpecialName.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/SpecialName.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class SpecialName : ParentNode { - private string _specialValue; + private readonly string _specialValue; public SpecialName(string specialValue, BaseNode type) : base(NodeType.SpecialName, type) { @@ -17,4 +17,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast Child.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/SpecialSubstitution.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/SpecialSubstitution.cs index 8d45e180b..793d94989 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/SpecialSubstitution.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/SpecialSubstitution.cs @@ -14,7 +14,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast IOStream } - private SpecialType _specialSubstitutionKey; + private readonly SpecialType _specialSubstitutionKey; public SpecialSubstitution(SpecialType specialSubstitutionKey) : base(NodeType.SpecialSubstitution) { @@ -54,23 +54,16 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast private string GetExtendedName() { - switch (_specialSubstitutionKey) + return _specialSubstitutionKey switch { - case SpecialType.Allocator: - return "std::allocator"; - case SpecialType.BasicString: - return "std::basic_string"; - case SpecialType.String: - return "std::basic_string, std::allocator >"; - case SpecialType.IStream: - return "std::basic_istream >"; - case SpecialType.OStream: - return "std::basic_ostream >"; - case SpecialType.IOStream: - return "std::basic_iostream >"; - } - - return null; + SpecialType.Allocator => "std::allocator", + SpecialType.BasicString => "std::basic_string", + SpecialType.String => "std::basic_string, std::allocator >", + SpecialType.IStream => "std::basic_istream >", + SpecialType.OStream => "std::basic_ostream >", + SpecialType.IOStream => "std::basic_iostream >", + _ => null, + }; } public override void PrintLeft(TextWriter writer) @@ -86,4 +79,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/TemplateArguments.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/TemplateArguments.cs index cc14d9645..d9f25ac66 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/TemplateArguments.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/TemplateArguments.cs @@ -9,13 +9,13 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast public override void PrintLeft(TextWriter writer) { - string Params = string.Join(", ", Nodes.ToArray()); + string paramsString = string.Join(", ", Nodes.ToArray()); writer.Write("<"); - writer.Write(Params); + writer.Write(paramsString); - if (Params.EndsWith('>')) + if (paramsString.EndsWith('>')) { writer.Write(" "); } diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ThrowExpression.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ThrowExpression.cs index 2972a31c2..4edff138b 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ThrowExpression.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/ThrowExpression.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { public class ThrowExpression : BaseNode { - private BaseNode _expression; + private readonly BaseNode _expression; public ThrowExpression(BaseNode expression) : base(NodeType.ThrowExpression) { @@ -17,4 +17,4 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast _expression.Print(writer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Demangler.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Demangler.cs index 1bfd7ac07..ba2d67fca 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Demangler.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Demangler.cs @@ -8,25 +8,25 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler { class Demangler { - private static readonly string Base36 = "0123456789abcdefghijklmnopqrstuvwxyz"; - private List _substitutionList = new List(); - private List _templateParamList = new List(); + private static readonly string _base36 = "0123456789abcdefghijklmnopqrstuvwxyz"; + private readonly List _substitutionList = new(); + private List _templateParamList = new(); - private List _forwardTemplateReferenceList = new List(); + private readonly List _forwardTemplateReferenceList = new(); public string Mangled { get; private set; } private int _position; - private int _length; + private readonly int _length; private bool _canForwardTemplateReference; private bool _canParseTemplateArgs; public Demangler(string mangled) { - Mangled = mangled; - _position = 0; - _length = mangled.Length; + Mangled = mangled; + _position = 0; + _length = mangled.Length; _canParseTemplateArgs = true; } @@ -87,7 +87,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler for (int i = 0; i < reversedEncoded.Length; i++) { - int value = Base36.IndexOf(reversedEncoded[i]); + int value = _base36.IndexOf(reversedEncoded[i]); if (value == -1) { return -1; @@ -101,8 +101,8 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler private int ParseSeqId() { - ReadOnlySpan part = Mangled.AsSpan(_position); - int seqIdLen = 0; + ReadOnlySpan part = Mangled.AsSpan(_position); + int seqIdLen = 0; for (; seqIdLen < part.Length; seqIdLen++) { @@ -274,7 +274,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler } else if (ConsumeIf("Dw")) { - List types = new List(); + List types = new(); while (!ConsumeIf("E")) { @@ -308,7 +308,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler } Reference referenceQualifier = Reference.None; - List Params = new List(); + List paramsList = new(); while (true) { @@ -339,10 +339,10 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return null; } - Params.Add(type); + paramsList.Add(type); } - return new FunctionType(returnType, new NodeArray(Params), new CvType(cvQualifiers, null), new SimpleReferenceType(referenceQualifier, null), exceptionSpec); + return new FunctionType(returnType, new NodeArray(paramsList), new CvType(cvQualifiers, null), new SimpleReferenceType(referenceQualifier, null), exceptionSpec); } // ::= A _ @@ -416,12 +416,9 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler private BaseNode ParseType(NameParserContext context = null) { // Temporary context - if (context == null) - { - context = new NameParserContext(); - } + context ??= new NameParserContext(); - BaseNode result = null; + BaseNode result; switch (Peek()) { case 'r': @@ -545,8 +542,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler case 'h': _position += 2; // FIXME: GNU c++flit returns this but that is not what is supposed to be returned. - return new NameType("half"); - // return new NameType("decimal16"); + return new NameType("half"); // return new NameType("decimal16"); case 'i': _position += 2; return new NameType("char32_t"); @@ -559,8 +555,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler case 'n': _position += 2; // FIXME: GNU c++flit returns this but that is not what is supposed to be returned. - return new NameType("decltype(nullptr)"); - // return new NameType("std::nullptr_t"); + return new NameType("decltype(nullptr)"); // return new NameType("std::nullptr_t"); case 't': case 'T': _position += 2; @@ -882,7 +877,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return new SimpleReferenceType(result, null); } - private BaseNode CreateNameNode(BaseNode prev, BaseNode name, NameParserContext context) + private static BaseNode CreateNameNode(BaseNode prev, BaseNode name, NameParserContext context) { BaseNode result = name; if (prev != null) @@ -900,8 +895,8 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler private int ParsePositiveNumber() { - ReadOnlySpan part = Mangled.AsSpan(_position); - int numberLength = 0; + ReadOnlySpan part = Mangled.AsSpan(_position); + int numberLength = 0; for (; numberLength < part.Length; numberLength++) { @@ -933,8 +928,8 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return null; } - ReadOnlySpan part = Mangled.AsSpan(_position); - int numberLength = 0; + ReadOnlySpan part = Mangled.AsSpan(_position); + int numberLength = 0; for (; numberLength < part.Length; numberLength++) { @@ -1057,15 +1052,15 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler case 'v': _position += 2; - bool canParseTemplateArgsBackup = _canParseTemplateArgs; + bool canParseTemplateArgsBackup = _canParseTemplateArgs; bool canForwardTemplateReferenceBackup = _canForwardTemplateReference; - _canParseTemplateArgs = false; + _canParseTemplateArgs = false; _canForwardTemplateReference = canForwardTemplateReferenceBackup || context != null; BaseNode type = ParseType(); - _canParseTemplateArgs = canParseTemplateArgsBackup; + _canParseTemplateArgs = canParseTemplateArgsBackup; _canForwardTemplateReference = canForwardTemplateReferenceBackup; if (type == null) @@ -1324,17 +1319,17 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler // ::= C3 # complete object allocating constructor // ::= D0 # deleting destructor // ::= D1 # complete object destructor - // ::= D2 # base object destructor + // ::= D2 # base object destructor private BaseNode ParseCtorDtorName(NameParserContext context, BaseNode prev) { - if (prev.Type == NodeType.SpecialSubstitution && prev is SpecialSubstitution) + if (prev.Type == NodeType.SpecialSubstitution && prev is SpecialSubstitution substitution) { - ((SpecialSubstitution)prev).SetExtended(); + substitution.SetExtended(); } if (ConsumeIf("C")) { - bool isInherited = ConsumeIf("I"); + bool isInherited = ConsumeIf("I"); char ctorDtorType = Peek(); if (ctorDtorType != '1' && ctorDtorType != '2' && ctorDtorType != '3') @@ -1434,9 +1429,9 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return null; } - char foldKind = Peek(); + char foldKind = Peek(); bool hasInitializer = foldKind == 'L' || foldKind == 'R'; - bool isLeftFold = foldKind == 'l' || foldKind == 'L'; + bool isLeftFold = foldKind == 'l' || foldKind == 'L'; if (!isLeftFold && !(foldKind == 'r' || foldKind == 'R')) { @@ -1445,7 +1440,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler _position++; - string operatorName = null; + string operatorName; switch (PeekString(0, 2)) { @@ -1567,9 +1562,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler if (isLeftFold && initializer != null) { - BaseNode temp = expression; - expression = initializer; - initializer = temp; + (initializer, expression) = (expression, initializer); } return new FoldExpression(isLeftFold, operatorName, new PackedTemplateParameterExpansion(expression), initializer); @@ -1586,16 +1579,16 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler } bool canParseTemplateArgsBackup = _canParseTemplateArgs; - _canParseTemplateArgs = false; - BaseNode type = ParseType(); - _canParseTemplateArgs = canParseTemplateArgsBackup; + _canParseTemplateArgs = false; + BaseNode type = ParseType(); + _canParseTemplateArgs = canParseTemplateArgsBackup; if (type == null) { return null; } - List expressions = new List(); + List expressions = new(); if (ConsumeIf("_")) { while (!ConsumeIf("E")) @@ -1730,15 +1723,15 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler private BaseNode ParseNewExpression() { bool isGlobal = ConsumeIf("gs"); - bool isArray = Peek(1) == 'a'; + bool isArray = Peek(1) == 'a'; if (!ConsumeIf("nw") || !ConsumeIf("na")) { return null; } - List expressions = new List(); - List initializers = new List(); + List expressions = new(); + List initializers = new(); while (!ConsumeIf("_")) { @@ -1824,7 +1817,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler private BaseNode ParseExpression() { bool isGlobal = ConsumeIf("gs"); - BaseNode expression = null; + BaseNode expression; if (Count() < 2) { return null; @@ -1906,7 +1899,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return null; } - List names = new List(); + List names = new(); while (!ConsumeIf("E")) { expression = ParseExpression(); @@ -1929,8 +1922,8 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler } return null; case 'd': - BaseNode leftNode = null; - BaseNode rightNode = null; + BaseNode leftNode; + BaseNode rightNode; switch (Peek(1)) { case 'a': @@ -2055,7 +2048,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler case 'l': _position += 2; - List bracedExpressions = new List(); + List bracedExpressions = new(); while (!ConsumeIf("E")) { expression = ParseBracedExpression(); @@ -2310,7 +2303,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return new EnclosedExpression("sizeof (", expression, ")"); case 'Z': _position += 2; - BaseNode sizeofParamNode = null; + BaseNode sizeofParamNode; switch (Peek()) { case 'T': @@ -2334,7 +2327,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return null; case 'P': _position += 2; - List arguments = new List(); + List arguments = new(); while (!ConsumeIf("E")) { BaseNode argument = ParseTemplateArgument(); @@ -2375,7 +2368,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return null; } - List bracedExpressions = new List(); + List bracedExpressions = new(); while (!ConsumeIf("E")) { expression = ParseBracedExpression(); @@ -2582,7 +2575,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler if (_canForwardTemplateReference) { - ForwardTemplateReference forwardTemplateReference = new ForwardTemplateReference(index); + ForwardTemplateReference forwardTemplateReference = new(index); _forwardTemplateReferenceList.Add(forwardTemplateReference); return forwardTemplateReference; } @@ -2607,12 +2600,12 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler _templateParamList.Clear(); } - List args = new List(); + List args = new(); while (!ConsumeIf("E")) { if (hasContext) { - List templateParamListTemp = new List(_templateParamList); + List templateParamListTemp = new(_templateParamList); BaseNode templateArgument = ParseTemplateArgument(); _templateParamList = templateParamListTemp; if (templateArgument == null) @@ -2666,7 +2659,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler // J * E case 'J': _position++; - List templateArguments = new List(); + List templateArguments = new(); while (!ConsumeIf("E")) { BaseNode templateArgument = ParseTemplateArgument(); @@ -2976,7 +2969,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler } BaseNode result = null; - CvType cv = new CvType(ParseCvQualifiers(), null); + CvType cv = new(ParseCvQualifiers(), null); if (context != null) { context.Cv = cv; @@ -3269,7 +3262,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler // ::= private BaseNode ParseEncoding() { - NameParserContext context = new NameParserContext(); + NameParserContext context = new(); if (Peek() == 'T' || (Peek() == 'G' && Peek(1) == 'V')) { return ParseSpecialName(context); @@ -3305,7 +3298,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return new EncodedFunction(name, null, context.Cv, context.Ref, null, returnType); } - List Params = new List(); + List paramsList = new(); // backup because that can be destroyed by parseType CvType cv = context.Cv; @@ -3319,10 +3312,10 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return null; } - Params.Add(param); + paramsList.Add(param); } - return new EncodedFunction(name, new NodeArray(Params), cv, Ref, null, returnType); + return new EncodedFunction(name, new NodeArray(paramsList), cv, Ref, null, returnType); } // ::= _Z @@ -3351,12 +3344,12 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler public static string Parse(string originalMangled) { - Demangler instance = new Demangler(originalMangled); - BaseNode resNode = instance.Parse(); + Demangler instance = new(originalMangled); + BaseNode resNode = instance.Parse(); if (resNode != null) { - StringWriter writer = new StringWriter(); + StringWriter writer = new(); resNode.Print(writer); return writer.ToString(); } diff --git a/src/Ryujinx.HLE/HOS/HomebrewRomFsStream.cs b/src/Ryujinx.HLE/HOS/HomebrewRomFsStream.cs index 59bc881f0..2cba640b8 100644 --- a/src/Ryujinx.HLE/HOS/HomebrewRomFsStream.cs +++ b/src/Ryujinx.HLE/HOS/HomebrewRomFsStream.cs @@ -5,12 +5,12 @@ namespace Ryujinx.HLE.HOS { class HomebrewRomFsStream : Stream { - private Stream _baseStream; - private long _positionOffset; + private readonly Stream _baseStream; + private readonly long _positionOffset; public HomebrewRomFsStream(Stream baseStream, long positionOffset) { - _baseStream = baseStream; + _baseStream = baseStream; _positionOffset = positionOffset; _baseStream.Position = _positionOffset; diff --git a/src/Ryujinx.HLE/HOS/Horizon.cs b/src/Ryujinx.HLE/HOS/Horizon.cs index 2f163fa22..f65d357e7 100644 --- a/src/Ryujinx.HLE/HOS/Horizon.cs +++ b/src/Ryujinx.HLE/HOS/Horizon.cs @@ -10,7 +10,6 @@ using Ryujinx.Audio.Integration; using Ryujinx.Audio.Output; using Ryujinx.Audio.Renderer.Device; using Ryujinx.Audio.Renderer.Server; -using Ryujinx.Common.Utilities; using Ryujinx.Cpu; using Ryujinx.HLE.FileSystem; using Ryujinx.HLE.HOS.Kernel; @@ -42,7 +41,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; -using TimeSpanType = Ryujinx.HLE.HOS.Services.Time.Clock.TimeSpanType; namespace Ryujinx.HLE.HOS { @@ -50,10 +48,10 @@ namespace Ryujinx.HLE.HOS public class Horizon : IDisposable { - internal const int HidSize = 0x40000; - internal const int FontSize = 0x1100000; - internal const int IirsSize = 0x8000; - internal const int TimeSize = 0x1000; + internal const int HidSize = 0x40000; + internal const int FontSize = 0x1100000; + internal const int IirsSize = 0x8000; + internal const int TimeSize = 0x1000; internal const int AppletCaptureBufferSize = 0x384000; internal KernelContext KernelContext { get; } @@ -91,16 +89,16 @@ namespace Ryujinx.HLE.HOS internal ServerBase ViServerM { get; private set; } internal ServerBase ViServerS { get; private set; } - internal KSharedMemory HidSharedMem { get; private set; } + internal KSharedMemory HidSharedMem { get; private set; } internal KSharedMemory FontSharedMem { get; private set; } internal KSharedMemory IirsSharedMem { get; private set; } internal KTransferMemory AppletCaptureBufferTransfer { get; private set; } internal SharedFontManager SharedFontManager { get; private set; } - internal AccountManager AccountManager { get; private set; } - internal ContentManager ContentManager { get; private set; } - internal CaptureManager CaptureManager { get; private set; } + internal AccountManager AccountManager { get; private set; } + internal ContentManager ContentManager { get; private set; } + internal CaptureManager CaptureManager { get; private set; } internal KEvent VsyncEvent { get; private set; } @@ -149,17 +147,17 @@ namespace Ryujinx.HLE.HOS // region used that is used is Application, so we can use the other ones for anything. KMemoryRegionManager region = KernelContext.MemoryManager.MemoryRegions[(int)MemoryRegion.NvServices]; - ulong hidPa = region.Address; - ulong fontPa = region.Address + HidSize; - ulong iirsPa = region.Address + HidSize + FontSize; - ulong timePa = region.Address + HidSize + FontSize + IirsSize; + ulong hidPa = region.Address; + ulong fontPa = region.Address + HidSize; + ulong iirsPa = region.Address + HidSize + FontSize; + ulong timePa = region.Address + HidSize + FontSize + IirsSize; ulong appletCaptureBufferPa = region.Address + HidSize + FontSize + IirsSize + TimeSize; - KPageList hidPageList = new KPageList(); - KPageList fontPageList = new KPageList(); - KPageList iirsPageList = new KPageList(); - KPageList timePageList = new KPageList(); - KPageList appletCaptureBufferPageList = new KPageList(); + KPageList hidPageList = new(); + KPageList fontPageList = new(); + KPageList iirsPageList = new(); + KPageList timePageList = new(); + KPageList appletCaptureBufferPageList = new(); hidPageList.AddRange(hidPa, HidSize / KPageTableBase.PageSize); fontPageList.AddRange(fontPa, FontSize / KPageTableBase.PageSize); @@ -175,11 +173,11 @@ namespace Ryujinx.HLE.HOS HidStorage = hidStorage; - HidSharedMem = new KSharedMemory(KernelContext, hidStorage, 0, 0, KMemoryPermission.Read); + HidSharedMem = new KSharedMemory(KernelContext, hidStorage, 0, 0, KMemoryPermission.Read); FontSharedMem = new KSharedMemory(KernelContext, fontStorage, 0, 0, KMemoryPermission.Read); IirsSharedMem = new KSharedMemory(KernelContext, iirsStorage, 0, 0, KMemoryPermission.Read); - KSharedMemory timeSharedMemory = new KSharedMemory(KernelContext, timeStorage, 0, 0, KMemoryPermission.Read); + KSharedMemory timeSharedMemory = new(KernelContext, timeStorage, 0, 0, KMemoryPermission.Read); TimeServiceManager.Instance.Initialize(device, this, timeSharedMemory, timeStorage, TimeSize); @@ -194,16 +192,16 @@ namespace Ryujinx.HLE.HOS DisplayResolutionChangeEvent = new KEvent(KernelContext); SharedFontManager = new SharedFontManager(device, fontStorage); - AccountManager = device.Configuration.AccountManager; - ContentManager = device.Configuration.ContentManager; - CaptureManager = new CaptureManager(device); + AccountManager = device.Configuration.AccountManager; + ContentManager = device.Configuration.ContentManager; + CaptureManager = new CaptureManager(device); LibHacHorizonManager = device.Configuration.LibHacHorizonManager; // We hardcode a clock source id to avoid it changing between each start. // TODO: use set:sys (and get external clock source id from settings) // TODO: use "time!standard_steady_clock_rtc_update_interval_minutes" and implement a worker thread to be accurate. - UInt128 clockSourceId = new UInt128(0x36a0328702ce8bc1, 0x1608eaba02333284); + UInt128 clockSourceId = new(0x36a0328702ce8bc1, 0x1608eaba02333284); IRtcManager.GetExternalRtcValue(out ulong rtcValue); // We assume the rtc is system time. @@ -212,7 +210,7 @@ namespace Ryujinx.HLE.HOS // Configure and setup internal offset TimeSpanType internalOffset = TimeSpanType.FromSeconds(device.Configuration.SystemTimeOffset); - TimeSpanType systemTimeOffset = new TimeSpanType(systemTime.NanoSeconds + internalOffset.NanoSeconds); + TimeSpanType systemTimeOffset = new(systemTime.NanoSeconds + internalOffset.NanoSeconds); if (systemTime.IsDaylightSavingTime() && !systemTimeOffset.IsDaylightSavingTime()) { @@ -232,7 +230,7 @@ namespace Ryujinx.HLE.HOS if (NxSettings.Settings.TryGetValue("time!standard_network_clock_sufficient_accuracy_minutes", out object standardNetworkClockSufficientAccuracyMinutes)) { - TimeSpanType standardNetworkClockSufficientAccuracy = new TimeSpanType((int)standardNetworkClockSufficientAccuracyMinutes * 60000000000); + TimeSpanType standardNetworkClockSufficientAccuracy = new((int)standardNetworkClockSufficientAccuracyMinutes * 60000000000); // The network system clock needs a valid system clock, as such we setup this system clock using the local system clock. TimeServiceManager.Instance.SetupStandardNetworkSystemClock(localSytemClockContext, standardNetworkClockSufficientAccuracy); @@ -267,7 +265,7 @@ namespace Ryujinx.HLE.HOS for (int i = 0; i < audioOutputRegisterBufferEvents.Length; i++) { - KEvent registerBufferEvent = new KEvent(KernelContext); + KEvent registerBufferEvent = new(KernelContext); audioOutputRegisterBufferEvents[i] = new AudioKernelEvent(registerBufferEvent); } @@ -279,7 +277,7 @@ namespace Ryujinx.HLE.HOS for (int i = 0; i < audioInputRegisterBufferEvents.Length; i++) { - KEvent registerBufferEvent = new KEvent(KernelContext); + KEvent registerBufferEvent = new(KernelContext); audioInputRegisterBufferEvents[i] = new AudioKernelEvent(registerBufferEvent); } @@ -290,7 +288,7 @@ namespace Ryujinx.HLE.HOS for (int i = 0; i < systemEvents.Length; i++) { - KEvent systemEvent = new KEvent(KernelContext); + KEvent systemEvent = new(KernelContext); systemEvents[i] = new AudioKernelEvent(systemEvent); } @@ -338,16 +336,15 @@ namespace Ryujinx.HLE.HOS ProcessCreationFlags.Is64Bit | ProcessCreationFlags.PoolPartitionSystem; - ProcessCreationInfo creationInfo = new ProcessCreationInfo("Service", 1, 0, 0x8000000, 1, Flags, 0, 0); + ProcessCreationInfo creationInfo = new("Service", 1, 0, 0x8000000, 1, Flags, 0, 0); - uint[] defaultCapabilities = new uint[] - { + uint[] defaultCapabilities = { 0x030363F7, 0x1FFFFFCF, 0x207FFFEF, 0x47E0060F, 0x0048BFFF, - 0x01007FFF + 0x01007FFF, }; // TODO: @@ -445,6 +442,7 @@ namespace Ryujinx.HLE.HOS public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } @@ -464,8 +462,8 @@ namespace Ryujinx.HLE.HOS AudioRendererManager.StopSendingCommands(); } - KProcess terminationProcess = new KProcess(KernelContext); - KThread terminationThread = new KThread(KernelContext); + KProcess terminationProcess = new(KernelContext); + KThread terminationThread = new(KernelContext); terminationThread.Initialize(0, 0, 0, 3, 0, terminationProcess, ThreadType.Kernel, () => { diff --git a/src/Ryujinx.HLE/HOS/IdDictionary.cs b/src/Ryujinx.HLE/HOS/IdDictionary.cs index 5ae720ea3..56ffcd0c3 100644 --- a/src/Ryujinx.HLE/HOS/IdDictionary.cs +++ b/src/Ryujinx.HLE/HOS/IdDictionary.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS { class IdDictionary { - private ConcurrentDictionary _objs; + private readonly ConcurrentDictionary _objs; public ICollection Values => _objs.Values; @@ -45,12 +45,12 @@ namespace Ryujinx.HLE.HOS public T GetData(int id) { - if (_objs.TryGetValue(id, out object data) && data is T) + if (_objs.TryGetValue(id, out object dataObject) && dataObject is T data) { - return (T)data; + return data; } - return default(T); + return default; } public object Delete(int id) @@ -72,4 +72,4 @@ namespace Ryujinx.HLE.HOS return values; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Ipc/IpcBuffDesc.cs b/src/Ryujinx.HLE/HOS/Ipc/IpcBuffDesc.cs index b61d56973..aa9174354 100644 --- a/src/Ryujinx.HLE/HOS/Ipc/IpcBuffDesc.cs +++ b/src/Ryujinx.HLE/HOS/Ipc/IpcBuffDesc.cs @@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Ipc struct IpcBuffDesc { public ulong Position { get; private set; } - public ulong Size { get; private set; } - public byte Flags { get; private set; } + public ulong Size { get; private set; } + public byte Flags { get; private set; } public IpcBuffDesc(BinaryReader reader) { @@ -14,14 +14,14 @@ namespace Ryujinx.HLE.HOS.Ipc ulong word1 = reader.ReadUInt32(); ulong word2 = reader.ReadUInt32(); - Position = word1; - Position |= (word2 << 4) & 0x0f00000000; + Position = word1; + Position |= (word2 << 4) & 0x0f00000000; Position |= (word2 << 34) & 0x7000000000; - Size = word0; + Size = word0; Size |= (word2 << 8) & 0xf00000000; Flags = (byte)(word2 & 3); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs b/src/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs index c7ef7e9cf..887fe28e6 100644 --- a/src/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs +++ b/src/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs @@ -90,4 +90,4 @@ namespace Ryujinx.HLE.HOS.Ipc return ms; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Ipc/IpcMagic.cs b/src/Ryujinx.HLE/HOS/Ipc/IpcMagic.cs index 72770b90e..05d609071 100644 --- a/src/Ryujinx.HLE/HOS/Ipc/IpcMagic.cs +++ b/src/Ryujinx.HLE/HOS/Ipc/IpcMagic.cs @@ -5,4 +5,4 @@ namespace Ryujinx.HLE.HOS.Ipc public const long Sfci = 'S' << 0 | 'F' << 8 | 'C' << 16 | 'I' << 24; public const long Sfco = 'S' << 0 | 'F' << 8 | 'C' << 16 | 'O' << 24; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Ipc/IpcMessage.cs b/src/Ryujinx.HLE/HOS/Ipc/IpcMessage.cs index 21630c42e..feba09fe3 100644 --- a/src/Ryujinx.HLE/HOS/Ipc/IpcMessage.cs +++ b/src/Ryujinx.HLE/HOS/Ipc/IpcMessage.cs @@ -2,7 +2,6 @@ using Microsoft.IO; using Ryujinx.Common; using Ryujinx.Common.Memory; using System; -using System.Buffers; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -15,10 +14,10 @@ namespace Ryujinx.HLE.HOS.Ipc public IpcHandleDesc HandleDesc { get; set; } - public List PtrBuff { get; private set; } - public List SendBuff { get; private set; } - public List ReceiveBuff { get; private set; } - public List ExchangeBuff { get; private set; } + public List PtrBuff { get; private set; } + public List SendBuff { get; private set; } + public List ReceiveBuff { get; private set; } + public List ExchangeBuff { get; private set; } public List RecvListBuff { get; private set; } public List ObjectIds { get; private set; } @@ -27,9 +26,9 @@ namespace Ryujinx.HLE.HOS.Ipc public IpcMessage() { - PtrBuff = new List(0); - SendBuff = new List(0); - ReceiveBuff = new List(0); + PtrBuff = new List(0); + SendBuff = new List(0); + ReceiveBuff = new List(0); ExchangeBuff = new List(0); RecvListBuff = new List(0); @@ -38,93 +37,92 @@ namespace Ryujinx.HLE.HOS.Ipc public IpcMessage(ReadOnlySpan data, long cmdPtr) { - using (RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream(data)) + using RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream(data); + + BinaryReader reader = new(ms); + + int word0 = reader.ReadInt32(); + int word1 = reader.ReadInt32(); + + Type = (IpcMessageType)(word0 & 0xffff); + + int ptrBuffCount = (word0 >> 16) & 0xf; + int sendBuffCount = (word0 >> 20) & 0xf; + int recvBuffCount = (word0 >> 24) & 0xf; + int xchgBuffCount = (word0 >> 28) & 0xf; + + int rawDataSize = (word1 >> 0) & 0x3ff; + int recvListFlags = (word1 >> 10) & 0xf; + bool hndDescEnable = ((word1 >> 31) & 0x1) != 0; + + if (hndDescEnable) { - BinaryReader reader = new BinaryReader(ms); + HandleDesc = new IpcHandleDesc(reader); + } - int word0 = reader.ReadInt32(); - int word1 = reader.ReadInt32(); + PtrBuff = new List(ptrBuffCount); - Type = (IpcMessageType)(word0 & 0xffff); + for (int index = 0; index < ptrBuffCount; index++) + { + PtrBuff.Add(new IpcPtrBuffDesc(reader)); + } - int ptrBuffCount = (word0 >> 16) & 0xf; - int sendBuffCount = (word0 >> 20) & 0xf; - int recvBuffCount = (word0 >> 24) & 0xf; - int xchgBuffCount = (word0 >> 28) & 0xf; + static List ReadBuff(BinaryReader reader, int count) + { + List buff = new(count); - int rawDataSize = (word1 >> 0) & 0x3ff; - int recvListFlags = (word1 >> 10) & 0xf; - bool hndDescEnable = ((word1 >> 31) & 0x1) != 0; - - if (hndDescEnable) + for (int index = 0; index < count; index++) { - HandleDesc = new IpcHandleDesc(reader); + buff.Add(new IpcBuffDesc(reader)); } - PtrBuff = new List(ptrBuffCount); + return buff; + } - for (int index = 0; index < ptrBuffCount; index++) - { - PtrBuff.Add(new IpcPtrBuffDesc(reader)); - } + SendBuff = ReadBuff(reader, sendBuffCount); + ReceiveBuff = ReadBuff(reader, recvBuffCount); + ExchangeBuff = ReadBuff(reader, xchgBuffCount); - static List ReadBuff(BinaryReader reader, int count) - { - List buff = new List(count); - - for (int index = 0; index < count; index++) - { - buff.Add(new IpcBuffDesc(reader)); - } - - return buff; - } + rawDataSize *= 4; - SendBuff = ReadBuff(reader, sendBuffCount); - ReceiveBuff = ReadBuff(reader, recvBuffCount); - ExchangeBuff = ReadBuff(reader, xchgBuffCount); - - rawDataSize *= 4; - - long recvListPos = reader.BaseStream.Position + rawDataSize; + long recvListPos = reader.BaseStream.Position + rawDataSize; // Only CMIF has the padding requirements. if (Type < IpcMessageType.TipcCloseSession) { long pad0 = GetPadSize16(reader.BaseStream.Position + cmdPtr); - if (rawDataSize != 0) - { - rawDataSize -= (int)pad0; - } - - reader.BaseStream.Seek(pad0, SeekOrigin.Current); - } - - int recvListCount = recvListFlags - 2; - - if (recvListCount == 0) + if (rawDataSize != 0) { - recvListCount = 1; - } - else if (recvListCount < 0) - { - recvListCount = 0; + rawDataSize -= (int)pad0; } - RawData = reader.ReadBytes(rawDataSize); - - reader.BaseStream.Seek(recvListPos, SeekOrigin.Begin); - - RecvListBuff = new List(recvListCount); - - for (int index = 0; index < recvListCount; index++) - { - RecvListBuff.Add(new IpcRecvListBuffDesc(reader.ReadUInt64())); - } - - ObjectIds = new List(0); + reader.BaseStream.Seek(pad0, SeekOrigin.Current); } + + int recvListCount = recvListFlags - 2; + + if (recvListCount == 0) + { + recvListCount = 1; + } + else if (recvListCount < 0) + { + recvListCount = 0; + } + + RawData = reader.ReadBytes(rawDataSize); + + reader.BaseStream.Seek(recvListPos, SeekOrigin.Begin); + + RecvListBuff = new List(recvListCount); + + for (int index = 0; index < recvListCount; index++) + { + RecvListBuff.Add(new IpcRecvListBuffDesc(reader.ReadUInt64())); + } + + ObjectIds = new List(0); } public RecyclableMemoryStream GetStream(long cmdPtr, ulong recvListAddr) @@ -134,10 +132,10 @@ namespace Ryujinx.HLE.HOS.Ipc int word0; int word1; - word0 = (int)Type; - word0 |= (PtrBuff.Count & 0xf) << 16; - word0 |= (SendBuff.Count & 0xf) << 20; - word0 |= (ReceiveBuff.Count & 0xf) << 24; + word0 = (int)Type; + word0 |= (PtrBuff.Count & 0xf) << 16; + word0 |= (SendBuff.Count & 0xf) << 20; + word0 |= (ReceiveBuff.Count & 0xf) << 24; word0 |= (ExchangeBuff.Count & 0xf) << 28; using RecyclableMemoryStream handleDataStream = HandleDesc?.GetStream(); @@ -238,7 +236,7 @@ namespace Ryujinx.HLE.HOS.Ipc return ms; } - private long GetPadSize16(long position) + private static long GetPadSize16(long position) { if ((position & 0xf) != 0) { diff --git a/src/Ryujinx.HLE/HOS/Ipc/IpcMessageType.cs b/src/Ryujinx.HLE/HOS/Ipc/IpcMessageType.cs index 1c8622485..1391569cb 100644 --- a/src/Ryujinx.HLE/HOS/Ipc/IpcMessageType.cs +++ b/src/Ryujinx.HLE/HOS/Ipc/IpcMessageType.cs @@ -2,12 +2,12 @@ namespace Ryujinx.HLE.HOS.Ipc { enum IpcMessageType { - CmifResponse = 0, - CmifCloseSession = 2, - CmifRequest = 4, - CmifControl = 5, + CmifResponse = 0, + CmifCloseSession = 2, + CmifRequest = 4, + CmifControl = 5, CmifRequestWithContext = 6, CmifControlWithContext = 7, - TipcCloseSession = 0xF + TipcCloseSession = 0xF, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs b/src/Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs index 05798fe18..7ea2af0a8 100644 --- a/src/Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs +++ b/src/Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs @@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Ipc struct IpcPtrBuffDesc { public ulong Position { get; private set; } - public uint Index { get; private set; } - public ulong Size { get; private set; } + public uint Index { get; private set; } + public ulong Size { get; private set; } public IpcPtrBuffDesc(ulong position, uint index, ulong size) { @@ -20,26 +20,26 @@ namespace Ryujinx.HLE.HOS.Ipc ulong word0 = reader.ReadUInt32(); ulong word1 = reader.ReadUInt32(); - Position = word1; + Position = word1; Position |= (word0 << 20) & 0x0f00000000; Position |= (word0 << 30) & 0x7000000000; - Index = ((uint)word0 >> 0) & 0x03f; + Index = ((uint)word0 >> 0) & 0x03f; Index |= ((uint)word0 >> 3) & 0x1c0; Size = (ushort)(word0 >> 16); } - public IpcPtrBuffDesc WithSize(ulong size) + public readonly IpcPtrBuffDesc WithSize(ulong size) { return new IpcPtrBuffDesc(Position, Index, size); } - public uint GetWord0() + public readonly uint GetWord0() { uint word0; - word0 = (uint)((Position & 0x0f00000000) >> 20); + word0 = (uint)((Position & 0x0f00000000) >> 20); word0 |= (uint)((Position & 0x7000000000) >> 30); word0 |= (Index & 0x03f) << 0; @@ -50,9 +50,9 @@ namespace Ryujinx.HLE.HOS.Ipc return word0; } - public uint GetWord1() + public readonly uint GetWord1() { return (uint)Position; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Ipc/IpcRecvListBuffDesc.cs b/src/Ryujinx.HLE/HOS/Ipc/IpcRecvListBuffDesc.cs index bcc9d8f89..f74f81c74 100644 --- a/src/Ryujinx.HLE/HOS/Ipc/IpcRecvListBuffDesc.cs +++ b/src/Ryujinx.HLE/HOS/Ipc/IpcRecvListBuffDesc.cs @@ -1,11 +1,9 @@ -using System.IO; - namespace Ryujinx.HLE.HOS.Ipc { struct IpcRecvListBuffDesc { public ulong Position { get; private set; } - public ulong Size { get; private set; } + public ulong Size { get; private set; } public IpcRecvListBuffDesc(ulong position, ulong size) { @@ -20,4 +18,4 @@ namespace Ryujinx.HLE.HOS.Ipc Size = (ushort)(packedValue >> 48); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Ipc/ServiceProcessRequest.cs b/src/Ryujinx.HLE/HOS/Ipc/ServiceProcessRequest.cs index b3aaa2191..556b3df45 100644 --- a/src/Ryujinx.HLE/HOS/Ipc/ServiceProcessRequest.cs +++ b/src/Ryujinx.HLE/HOS/Ipc/ServiceProcessRequest.cs @@ -1,4 +1,4 @@ namespace Ryujinx.HLE.HOS.Ipc { delegate long ServiceProcessRequest(ServiceCtx context); -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/IKFutureSchedulerObject.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/IKFutureSchedulerObject.cs index 473683ff7..1550c9bf2 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/IKFutureSchedulerObject.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/IKFutureSchedulerObject.cs @@ -4,4 +4,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Common { void TimeUp(); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/KAutoObject.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/KAutoObject.cs index 424bf788b..e5dd3d171 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/KAutoObject.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/KAutoObject.cs @@ -70,4 +70,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Common { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/KResourceLimit.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/KResourceLimit.cs index b1a602f18..3f16f8c24 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/KResourceLimit.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/KResourceLimit.cs @@ -22,10 +22,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Common public KResourceLimit(KernelContext context) : base(context) { - _current = new long[(int)LimitableResource.Count]; - _limit = new long[(int)LimitableResource.Count]; + _current = new long[(int)LimitableResource.Count]; + _limit = new long[(int)LimitableResource.Count]; _current2 = new long[(int)LimitableResource.Count]; - _peak = new long[(int)LimitableResource.Count]; + _peak = new long[(int)LimitableResource.Count]; _lock = new object(); @@ -185,4 +185,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Common return (int)resource; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/KSynchronizationObject.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/KSynchronizationObject.cs index ddc0069d0..7e725e747 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/KSynchronizationObject.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/KSynchronizationObject.cs @@ -32,4 +32,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Common return false; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/KSystemControl.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/KSystemControl.cs index 8a727c30c..10f0b6f78 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/KSystemControl.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/KSystemControl.cs @@ -30,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common MemoryArrange.MemoryArrange4GiBAppletDev => 2048 * MiB, MemoryArrange.MemoryArrange6GiB or MemoryArrange.MemoryArrange8GiB => 4916 * MiB, - _ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\".") + _ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\"."), }; } @@ -44,7 +44,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common MemoryArrange.MemoryArrange6GiB => 562 * MiB, MemoryArrange.MemoryArrange6GiBAppletDev or MemoryArrange.MemoryArrange8GiB => 2193 * MiB, - _ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\".") + _ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\"."), }; } @@ -71,8 +71,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Common MemorySize.MemorySize4GiB => 4 * GiB, MemorySize.MemorySize6GiB => 6 * GiB, MemorySize.MemorySize8GiB => 8 * GiB, - _ => throw new ArgumentException($"Invalid memory size \"{size}\".") + _ => throw new ArgumentException($"Invalid memory size \"{size}\"."), }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/KTimeManager.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/KTimeManager.cs index c0cd9ce99..499bc2c61 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/KTimeManager.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/KTimeManager.cs @@ -36,9 +36,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Common _waitingObjects = new List(); _keepRunning = true; - Thread work = new Thread(WaitAndCheckScheduledObjects) + Thread work = new(WaitAndCheckScheduledObjects) { - Name = "HLE.TimeManager" + Name = "HLE.TimeManager", }; work.Start(); @@ -83,7 +83,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common private void WaitAndCheckScheduledObjects() { - SpinWait spinWait = new SpinWait(); + SpinWait spinWait = new(); WaitingObject next; using (_waitEvent = new AutoResetEvent(false)) @@ -215,4 +215,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Common _waitEvent?.Set(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/KernelInit.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/KernelInit.cs index efa2a480d..8021d8da0 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/KernelInit.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/KernelInit.cs @@ -9,20 +9,20 @@ namespace Ryujinx.HLE.HOS.Kernel.Common private readonly struct MemoryRegion { public ulong Address { get; } - public ulong Size { get; } + public ulong Size { get; } public ulong EndAddress => Address + Size; public MemoryRegion(ulong address, ulong size) { Address = address; - Size = size; + Size = size; } } public static void InitializeResourceLimit(KResourceLimit resourceLimit, MemorySize size) { - void EnsureSuccess(Result result) + static void EnsureSuccess(Result result) { if (result != Result.Success) { @@ -32,11 +32,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Common ulong ramSize = KSystemControl.GetDramSize(size); - EnsureSuccess(resourceLimit.SetLimitValue(LimitableResource.Memory, (long)ramSize)); - EnsureSuccess(resourceLimit.SetLimitValue(LimitableResource.Thread, 800)); - EnsureSuccess(resourceLimit.SetLimitValue(LimitableResource.Event, 700)); + EnsureSuccess(resourceLimit.SetLimitValue(LimitableResource.Memory, (long)ramSize)); + EnsureSuccess(resourceLimit.SetLimitValue(LimitableResource.Thread, 800)); + EnsureSuccess(resourceLimit.SetLimitValue(LimitableResource.Event, 700)); EnsureSuccess(resourceLimit.SetLimitValue(LimitableResource.TransferMemory, 200)); - EnsureSuccess(resourceLimit.SetLimitValue(LimitableResource.Session, 900)); + EnsureSuccess(resourceLimit.SetLimitValue(LimitableResource.Session, 900)); if (!resourceLimit.Reserve(LimitableResource.Memory, 0) || !resourceLimit.Reserve(LimitableResource.Memory, 0x60000)) @@ -47,9 +47,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Common public static KMemoryRegionManager[] GetMemoryRegions(MemorySize size, MemoryArrange arrange) { - ulong poolEnd = KSystemControl.GetDramEndAddress(size); + ulong poolEnd = KSystemControl.GetDramEndAddress(size); ulong applicationPoolSize = KSystemControl.GetApplicationPoolSize(arrange); - ulong appletPoolSize = KSystemControl.GetAppletPoolSize(arrange); + ulong appletPoolSize = KSystemControl.GetAppletPoolSize(arrange); MemoryRegion servicePool; MemoryRegion nvServicesPool; @@ -63,7 +63,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common ulong nvServicesPoolEnd = applicationPool.Address - appletPoolSize; nvServicesPool = new MemoryRegion(nvServicesPoolEnd - nvServicesPoolSize, nvServicesPoolSize); - appletPool = new MemoryRegion(nvServicesPoolEnd, appletPoolSize); + appletPool = new MemoryRegion(nvServicesPoolEnd, appletPoolSize); // Note: There is an extra region used by the kernel, however // since we are doing HLE we are not going to use that memory, so give all @@ -72,12 +72,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Common servicePool = new MemoryRegion(DramMemoryMap.SlabHeapEnd, servicePoolSize); - return new KMemoryRegionManager[] + return new[] { GetMemoryRegion(applicationPool), GetMemoryRegion(appletPool), GetMemoryRegion(servicePool), - GetMemoryRegion(nvServicesPool) + GetMemoryRegion(nvServicesPool), }; } @@ -86,4 +86,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Common return new KMemoryRegionManager(region.Address, region.Size, region.EndAddress); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs index cbc276c50..082d25ff0 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs @@ -56,7 +56,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common return false; } - public static bool KernelToUser(ulong address, T value) where T: unmanaged + public static bool KernelToUser(ulong address, T value) where T : unmanaged { KProcess currentProcess = KernelStatic.GetCurrentProcess(); @@ -70,4 +70,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Common return false; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/LimitableResource.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/LimitableResource.cs index 2e6a3e455..8655e61c1 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/LimitableResource.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/LimitableResource.cs @@ -2,12 +2,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Common { enum LimitableResource : byte { - Memory = 0, - Thread = 1, - Event = 2, + Memory = 0, + Thread = 1, + Event = 2, TransferMemory = 3, - Session = 4, + Session = 4, - Count = 5 + Count = 5, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/MemoryArrange.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/MemoryArrange.cs index d2bcfd62e..2c88d8b35 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/MemoryArrange.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/MemoryArrange.cs @@ -7,6 +7,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Common MemoryArrange4GiBSystemDev, MemoryArrange6GiB, MemoryArrange6GiBAppletDev, - MemoryArrange8GiB + MemoryArrange8GiB, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/MemroySize.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/MemorySize.cs similarity index 82% rename from src/Ryujinx.HLE/HOS/Kernel/Common/MemroySize.cs rename to src/Ryujinx.HLE/HOS/Kernel/Common/MemorySize.cs index 159385b63..7cc34a722 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/MemroySize.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/MemorySize.cs @@ -4,6 +4,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Common { MemorySize4GiB = 0, MemorySize6GiB = 1, - MemorySize8GiB = 2 + MemorySize8GiB = 2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/MersenneTwister.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/MersenneTwister.cs index 4c99f4251..9f078b10a 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Common/MersenneTwister.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Common/MersenneTwister.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common class MersenneTwister { private int _index; - private uint[] _mt; + private readonly uint[] _mt; public MersenneTwister(uint seed) { @@ -46,12 +46,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Common // If Range is already power of 2, subtract one to use log2(Range) directly. int rangeLog2 = nextRangeLog2 - (BitOperations.IsPow2(range) ? 1 : 0); - int parts = rangeLog2 > 32 ? 2 : 1; + int parts = rangeLog2 > 32 ? 2 : 1; int bitsPerPart = rangeLog2 / parts; int fullParts = parts - (rangeLog2 - parts * bitsPerPart); - uint mask = 0xffffffffu >> (32 - bitsPerPart); + uint mask = 0xffffffffu >> (32 - bitsPerPart); uint maskPlus1 = 0xffffffffu >> (31 - bitsPerPart); long randomNumber; @@ -66,9 +66,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Common } private long GenRandomNumber( - int parts, - int fullParts, - int bitsPerPart, + int parts, + int fullParts, + int bitsPerPart, uint mask, uint maskPlus1) { @@ -79,13 +79,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Common for (; part < fullParts; part++) { randomNumber <<= bitsPerPart; - randomNumber |= GenRandomNumber() & mask; + randomNumber |= GenRandomNumber() & mask; } for (; part < parts; part++) { randomNumber <<= bitsPerPart + 1; - randomNumber |= GenRandomNumber() & maskPlus1; + randomNumber |= GenRandomNumber() & maskPlus1; } return randomNumber; diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/ChannelState.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/ChannelState.cs index 4827384eb..3a943f94b 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/ChannelState.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/ChannelState.cs @@ -5,6 +5,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc NotInitialized, Open, ClientDisconnected, - ServerDisconnected + ServerDisconnected, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptor.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptor.cs index e28244d4a..5fa9cbe7a 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptor.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptor.cs @@ -4,17 +4,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { class KBufferDescriptor { - public ulong ClientAddress { get; } - public ulong ServerAddress { get; } - public ulong Size { get; } - public MemoryState State { get; } + public ulong ClientAddress { get; } + public ulong ServerAddress { get; } + public ulong Size { get; } + public MemoryState State { get; } public KBufferDescriptor(ulong src, ulong dst, ulong size, MemoryState state) { ClientAddress = src; ServerAddress = dst; - Size = size; - State = state; + Size = size; + State = state; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs index 593d2c9d5..373899b7b 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs @@ -9,14 +9,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { private const int MaxInternalBuffersCount = 8; - private List _sendBufferDescriptors; - private List _receiveBufferDescriptors; - private List _exchangeBufferDescriptors; + private readonly List _sendBufferDescriptors; + private readonly List _receiveBufferDescriptors; + private readonly List _exchangeBufferDescriptors; public KBufferDescriptorTable() { - _sendBufferDescriptors = new List(MaxInternalBuffersCount); - _receiveBufferDescriptors = new List(MaxInternalBuffersCount); + _sendBufferDescriptors = new List(MaxInternalBuffersCount); + _receiveBufferDescriptors = new List(MaxInternalBuffersCount); _exchangeBufferDescriptors = new List(MaxInternalBuffersCount); } @@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return Add(_exchangeBufferDescriptors, src, dst, size, state); } - private Result Add(List list, ulong src, ulong dst, ulong size, MemoryState state) + private static Result Add(List list, ulong src, ulong dst, ulong size, MemoryState state) { if (list.Count < MaxInternalBuffersCount) { @@ -59,7 +59,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return CopyToClient(memoryManager, _exchangeBufferDescriptors); } - private Result CopyToClient(KPageTableBase memoryManager, List list) + private static Result CopyToClient(KPageTableBase memoryManager, List list) { foreach (KBufferDescriptor desc in list) { @@ -67,11 +67,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc switch (desc.State) { - case MemoryState.IpcBuffer0: stateMask = MemoryState.IpcSendAllowedType0; break; - case MemoryState.IpcBuffer1: stateMask = MemoryState.IpcSendAllowedType1; break; - case MemoryState.IpcBuffer3: stateMask = MemoryState.IpcSendAllowedType3; break; - - default: return KernelResult.InvalidCombination; + case MemoryState.IpcBuffer0: + stateMask = MemoryState.IpcSendAllowedType0; + break; + case MemoryState.IpcBuffer1: + stateMask = MemoryState.IpcSendAllowedType1; + break; + case MemoryState.IpcBuffer3: + stateMask = MemoryState.IpcSendAllowedType3; + break; + default: + return KernelResult.InvalidCombination; } MemoryAttribute attributeMask = MemoryAttribute.Borrowed | MemoryAttribute.Uncached; @@ -82,7 +88,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc } ulong clientAddrTruncated = BitUtils.AlignDown(desc.ClientAddress, KPageTableBase.PageSize); - ulong clientAddrRounded = BitUtils.AlignUp(desc.ClientAddress, KPageTableBase.PageSize); + ulong clientAddrRounded = BitUtils.AlignUp(desc.ClientAddress, KPageTableBase.PageSize); // Check if address is not aligned, in this case we need to perform 2 copies. if (clientAddrTruncated != clientAddrRounded) @@ -114,7 +120,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc ulong serverEndAddr = desc.ServerAddress + desc.Size; ulong clientEndAddrTruncated = BitUtils.AlignDown(clientEndAddr, (ulong)KPageTableBase.PageSize); - ulong clientEndAddrRounded = BitUtils.AlignUp(clientEndAddr, KPageTableBase.PageSize); + ulong clientEndAddrRounded = BitUtils.AlignUp(clientEndAddr, KPageTableBase.PageSize); ulong serverEndAddrTruncated = BitUtils.AlignDown(serverEndAddr, (ulong)KPageTableBase.PageSize); if (clientEndAddrTruncated < clientEndAddrRounded && @@ -159,7 +165,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return UnmapServer(memoryManager, _exchangeBufferDescriptors); } - private Result UnmapServer(KPageTableBase memoryManager, List list) + private static Result UnmapServer(KPageTableBase memoryManager, List list) { foreach (KBufferDescriptor descriptor in list) { @@ -196,7 +202,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return RestoreClient(memoryManager, _exchangeBufferDescriptors); } - private Result RestoreClient(KPageTableBase memoryManager, List list) + private static Result RestoreClient(KPageTableBase memoryManager, List list) { foreach (KBufferDescriptor descriptor in list) { @@ -214,4 +220,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return Result.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KClientPort.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KClientPort.cs index eb7c5a418..6355fb6ee 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KClientPort.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KClientPort.cs @@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc public KClientPort(KernelContext context, KPort parent, int maxSessions) : base(context) { _maxSessions = maxSessions; - _parent = parent; + _parent = parent; } public Result Connect(out KClientSession clientSession) @@ -39,7 +39,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return KernelResult.SessionCountExceeded; } - KSession session = new KSession(KernelContext, this); + KSession session = new(KernelContext, this); Result result = _parent.EnqueueIncomingSession(session.ServerSession); @@ -75,7 +75,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return KernelResult.SessionCountExceeded; } - KLightSession session = new KLightSession(KernelContext); + KLightSession session = new(KernelContext); Result result = _parent.EnqueueIncomingLightSession(session.ServerSession); @@ -133,7 +133,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { KAutoObject foundObj = FindNamedObject(context, name); - if (!(foundObj is KClientPort)) + if (foundObj is not KClientPort) { return KernelResult.NotFound; } @@ -141,4 +141,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return KAutoObject.RemoveName(context, name); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KClientSession.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KClientSession.cs index a24bcc311..385f09020 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KClientSession.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KClientSession.cs @@ -9,7 +9,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { public KProcess CreatorProcess { get; } - private KSession _parent; + private readonly KSession _parent; public ChannelState State { get; set; } @@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc public KClientSession(KernelContext context, KSession parent, KClientPort parentPort) : base(context) { - _parent = parent; + _parent = parent; ParentPort = parentPort; parentPort?.IncrementReferenceCount(); @@ -32,11 +32,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { KThread currentThread = KernelStatic.GetCurrentThread(); - KSessionRequest request = new KSessionRequest(currentThread, customCmdBuffAddr, customCmdBuffSize); + KSessionRequest request = new(currentThread, customCmdBuffAddr, customCmdBuffSize); KernelContext.CriticalSection.Enter(); - currentThread.SignaledObj = null; + currentThread.SignaledObj = null; currentThread.ObjSyncResult = Result.Success; Result result = _parent.ServerSession.EnqueueRequest(request); @@ -55,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { KThread currentThread = KernelStatic.GetCurrentThread(); - KSessionRequest request = new KSessionRequest(currentThread, customCmdBuffAddr, customCmdBuffSize, asyncEvent); + KSessionRequest request = new(currentThread, customCmdBuffAddr, customCmdBuffSize, asyncEvent); KernelContext.CriticalSection.Enter(); @@ -81,4 +81,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc _parent.DecrementReferenceCount(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightClientSession.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightClientSession.cs index 27a9732be..1ff37282f 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightClientSession.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightClientSession.cs @@ -4,11 +4,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { class KLightClientSession : KAutoObject { +#pragma warning disable IDE0052 // Remove unread private member private readonly KLightSession _parent; +#pragma warning restore IDE0052 public KLightClientSession(KernelContext context, KLightSession parent) : base(context) { _parent = parent; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightServerSession.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightServerSession.cs index 0edbba6cb..c355409ec 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightServerSession.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightServerSession.cs @@ -4,11 +4,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { class KLightServerSession : KAutoObject { +#pragma warning disable IDE0052 // Remove unread private member private readonly KLightSession _parent; +#pragma warning restore IDE0052 public KLightServerSession(KernelContext context, KLightSession parent) : base(context) { _parent = parent; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightSession.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightSession.cs index 3abb1ab0d..16158a707 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightSession.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KLightSession.cs @@ -13,4 +13,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc ClientSession = new KLightClientSession(context, this); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KPort.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KPort.cs index 93f0f34cd..84ebcbc3e 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KPort.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KPort.cs @@ -8,9 +8,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc public KServerPort ServerPort { get; } public KClientPort ClientPort { get; } - private string _name; +#pragma warning disable IDE0052 // Remove unread private member + private readonly string _name; +#pragma warning restore IDE0052 - private ChannelState _state; + private readonly ChannelState _state; public bool IsLight { get; private set; } @@ -69,4 +71,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return result; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KServerPort.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KServerPort.cs index 21a3919cf..08efa8d94 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KServerPort.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KServerPort.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { class KServerPort : KSynchronizationObject { - private readonly LinkedList _incomingConnections; + private readonly LinkedList _incomingConnections; private readonly LinkedList _lightIncomingConnections; private readonly KPort _parent; @@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { _parent = parent; - _incomingConnections = new LinkedList(); + _incomingConnections = new LinkedList(); _lightIncomingConnections = new LinkedList(); } @@ -84,4 +84,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs index 86469c03a..7e41a3f3a 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs @@ -10,19 +10,18 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { class KServerSession : KSynchronizationObject { - private static readonly MemoryState[] IpcMemoryStates = new MemoryState[] - { + private static readonly MemoryState[] _ipcMemoryStates = { MemoryState.IpcBuffer3, MemoryState.IpcBuffer0, MemoryState.IpcBuffer1, - (MemoryState)0xfffce5d4 //This is invalid, shouldn't be accessed. + (MemoryState)0xfffce5d4, //This is invalid, shouldn't be accessed. }; private readonly struct Message { - public ulong Address { get; } - public ulong Size { get; } - public bool IsCustom { get; } + public ulong Address { get; } + public ulong Size { get; } + public bool IsCustom { get; } public Message(KThread thread, ulong customCmdBuffAddress, ulong customCmdBuffSize) { @@ -31,19 +30,20 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc if (IsCustom) { Address = customCmdBuffAddress; - Size = customCmdBuffSize; + Size = customCmdBuffSize; } else { Address = thread.TlsAddress; - Size = 0x100; + Size = 0x100; } } public Message(KSessionRequest request) : this( request.ClientThread, request.CustomCmdBuffAddr, - request.CustomCmdBuffSize) { } + request.CustomCmdBuffSize) + { } } private readonly struct MessageHeader @@ -52,18 +52,18 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc public uint Word1 { get; } public uint Word2 { get; } - public uint PointerBuffersCount { get; } - public uint SendBuffersCount { get; } - public uint ReceiveBuffersCount { get; } + public uint PointerBuffersCount { get; } + public uint SendBuffersCount { get; } + public uint ReceiveBuffersCount { get; } public uint ExchangeBuffersCount { get; } public uint RawDataSizeInWords { get; } public uint ReceiveListType { get; } - public uint MessageSizeInWords { get; } + public uint MessageSizeInWords { get; } public uint ReceiveListOffsetInWords { get; } - public uint ReceiveListOffset { get; } + public uint ReceiveListOffset { get; } public bool HasHandles { get; } @@ -101,14 +101,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc MoveHandlesCount = 0; } - PointerBuffersCount = (word0 >> 16) & 0xf; - SendBuffersCount = (word0 >> 20) & 0xf; - ReceiveBuffersCount = (word0 >> 24) & 0xf; - ExchangeBuffersCount = word0 >> 28; + PointerBuffersCount = (word0 >> 16) & 0xf; + SendBuffersCount = (word0 >> 20) & 0xf; + ReceiveBuffersCount = (word0 >> 24) & 0xf; + ExchangeBuffersCount = word0 >> 28; - uint pointerDescSizeInWords = PointerBuffersCount * 2; - uint sendDescSizeInWords = SendBuffersCount * 3; - uint receiveDescSizeInWords = ReceiveBuffersCount * 3; + uint pointerDescSizeInWords = PointerBuffersCount * 2; + uint sendDescSizeInWords = SendBuffersCount * 3; + uint receiveDescSizeInWords = ReceiveBuffersCount * 3; uint exchangeDescSizeInWords = ExchangeBuffersCount * 3; RawDataSizeInWords = word1 & 0x3ff; @@ -119,12 +119,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc uint paddingSizeInWords = HasHandles ? 3u : 2u; - MessageSizeInWords = pointerDescSizeInWords + - sendDescSizeInWords + - receiveDescSizeInWords + + MessageSizeInWords = pointerDescSizeInWords + + sendDescSizeInWords + + receiveDescSizeInWords + exchangeDescSizeInWords + - RawDataSizeInWords + - paddingSizeInWords + + RawDataSizeInWords + + paddingSizeInWords + handleDescSizeInWords; if (ReceiveListOffsetInWords == 0) @@ -140,25 +140,25 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { public uint ReceiveIndex { get; } - public uint BufferSize { get; } + public uint BufferSize { get; } public ulong BufferAddress { get; set; } public PointerBufferDesc(ulong dword) { ReceiveIndex = (uint)dword & 0xf; - BufferSize = (uint)dword >> 16; + BufferSize = (uint)dword >> 16; - BufferAddress = (dword >> 2) & 0x70; + BufferAddress = (dword >> 2) & 0x70; BufferAddress |= (dword >> 12) & 0xf; BufferAddress = (BufferAddress << 32) | (dword >> 32); } - public ulong Pack() + public readonly ulong Pack() { ulong dword = (ReceiveIndex & 0xf) | ((BufferSize & 0xffff) << 16); - dword |= BufferAddress << 32; + dword |= BufferAddress << 32; dword |= (BufferAddress >> 20) & 0xf000; dword |= (BufferAddress >> 30) & 0xffc0; @@ -166,9 +166,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc } } - private KSession _parent; + private readonly KSession _parent; - private LinkedList _requests; + private readonly LinkedList _requests; private KSessionRequest _activeRequest; @@ -208,7 +208,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc public Result Receive(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0) { - KThread serverThread = KernelStatic.GetCurrentThread(); + KThread serverThread = KernelStatic.GetCurrentThread(); KProcess serverProcess = serverThread.Owner; KernelContext.CriticalSection.Enter(); @@ -234,7 +234,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return KernelResult.PortRemoteClosed; } - KThread clientThread = request.ClientThread; + KThread clientThread = request.ClientThread; KProcess clientProcess = clientThread.Owner; KernelContext.CriticalSection.Leave(); @@ -243,8 +243,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc request.ServerProcess = serverProcess; - Message clientMsg = new Message(request); - Message serverMsg = new Message(serverThread, customCmdBuffAddr, customCmdBuffSize); + Message clientMsg = new(request); + Message serverMsg = new(serverThread, customCmdBuffAddr, customCmdBuffSize); MessageHeader clientHeader = GetClientMessageHeader(clientProcess, clientMsg); MessageHeader serverHeader = GetServerMessageHeader(serverMsg); @@ -399,7 +399,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { ulong pointerDesc = clientProcess.CpuMemory.Read(clientMsg.Address + offset * 4); - PointerBufferDesc descriptor = new PointerBufferDesc(pointerDesc); + PointerBufferDesc descriptor = new(pointerDesc); if (descriptor.BufferSize != 0) { @@ -409,7 +409,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc serverHeader.ReceiveListType, clientHeader.MessageSizeInWords, receiveList, - ref recvListDstOffset, + ref recvListDstOffset, out ulong recvListBufferAddress); if (clientResult != Result.Success) @@ -450,7 +450,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc // Copy send, receive and exchange buffers. uint totalBuffersCount = - clientHeader.SendBuffersCount + + clientHeader.SendBuffersCount + clientHeader.ReceiveBuffersCount + clientHeader.ExchangeBuffersCount; @@ -462,11 +462,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc uint descWord1 = clientProcess.CpuMemory.Read(clientDescAddress + 4); uint descWord2 = clientProcess.CpuMemory.Read(clientDescAddress + 8); - bool isSendDesc = index < clientHeader.SendBuffersCount; + bool isSendDesc = index < clientHeader.SendBuffersCount; bool isExchangeDesc = index >= clientHeader.SendBuffersCount + clientHeader.ReceiveBuffersCount; bool notReceiveDesc = isSendDesc || isExchangeDesc; - bool isReceiveDesc = !notReceiveDesc; + bool isReceiveDesc = !notReceiveDesc; KMemoryPermission permission = index >= clientHeader.SendBuffersCount ? KMemoryPermission.ReadAndWrite @@ -482,12 +482,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { ulong bufferAddress; - bufferAddress = descWord2 >> 28; + bufferAddress = descWord2 >> 28; bufferAddress |= ((descWord2 >> 2) & 7) << 4; bufferAddress = (bufferAddress << 32) | descWord1; - MemoryState state = IpcMemoryStates[(descWord2 + 1) & 3]; + MemoryState state = _ipcMemoryStates[(descWord2 + 1) & 3]; clientResult = serverProcess.MemoryManager.MapBufferFromClientProcess( bufferSize, @@ -533,7 +533,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc descWord2 |= sizeHigh4 << 24; descWord2 |= (uint)(dstAddress >> 34) & 0x3ffffffc; - descWord2 |= (uint)(dstAddress >> 4) & 0xf0000000; + descWord2 |= (uint)(dstAddress >> 4) & 0xf0000000; ulong serverDescAddress = serverMsg.Address + offset * 4; @@ -586,7 +586,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc public Result Reply(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0) { - KThread serverThread = KernelStatic.GetCurrentThread(); + KThread serverThread = KernelStatic.GetCurrentThread(); KProcess serverProcess = serverThread.Owner; KernelContext.CriticalSection.Enter(); @@ -609,11 +609,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc KernelContext.CriticalSection.Leave(); - KThread clientThread = request.ClientThread; + KThread clientThread = request.ClientThread; KProcess clientProcess = clientThread.Owner; - Message clientMsg = new Message(request); - Message serverMsg = new Message(serverThread, customCmdBuffAddr, customCmdBuffSize); + Message clientMsg = new(request); + Message serverMsg = new(serverThread, customCmdBuffAddr, customCmdBuffSize); MessageHeader clientHeader = GetClientMessageHeader(clientProcess, clientMsg); MessageHeader serverHeader = GetServerMessageHeader(serverMsg); @@ -664,8 +664,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return KernelResult.CmdBufferTooSmall; } - if (serverHeader.SendBuffersCount != 0 || - serverHeader.ReceiveBuffersCount != 0 || + if (serverHeader.SendBuffersCount != 0 || + serverHeader.ReceiveBuffersCount != 0 || serverHeader.ExchangeBuffersCount != 0) { CleanUpForError(); @@ -761,7 +761,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc { ulong pointerDesc = serverProcess.CpuMemory.Read(serverMsg.Address + offset * 4); - PointerBufferDesc descriptor = new PointerBufferDesc(pointerDesc); + PointerBufferDesc descriptor = new(pointerDesc); ulong recvListBufferAddress = 0; @@ -817,7 +817,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc // Set send, receive and exchange buffer descriptors to zero. uint totalBuffersCount = - serverHeader.SendBuffersCount + + serverHeader.SendBuffersCount + serverHeader.ReceiveBuffersCount + serverHeader.ExchangeBuffersCount; @@ -868,7 +868,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return serverResult; } - private MessageHeader GetClientMessageHeader(KProcess clientProcess, Message clientMsg) + private static MessageHeader GetClientMessageHeader(KProcess clientProcess, Message clientMsg) { uint word0 = clientProcess.CpuMemory.Read(clientMsg.Address + 0); uint word1 = clientProcess.CpuMemory.Read(clientMsg.Address + 4); @@ -877,7 +877,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return new MessageHeader(word0, word1, word2); } - private MessageHeader GetServerMessageHeader(Message serverMsg) + private static MessageHeader GetServerMessageHeader(Message serverMsg) { KProcess currentProcess = KernelStatic.GetCurrentProcess(); @@ -888,7 +888,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return new MessageHeader(word0, word1, word2); } - private Result GetCopyObjectHandle(KThread srcThread, KProcess dstProcess, int srcHandle, out int dstHandle) + private static Result GetCopyObjectHandle(KThread srcThread, KProcess dstProcess, int srcHandle, out int dstHandle) { dstHandle = 0; @@ -919,7 +919,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc } } - private Result GetMoveObjectHandle(KProcess srcProcess, KProcess dstProcess, int srcHandle, out int dstHandle) + private static Result GetMoveObjectHandle(KProcess srcProcess, KProcess dstProcess, int srcHandle, out int dstHandle) { dstHandle = 0; @@ -939,7 +939,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc } } - private ulong[] GetReceiveList(KProcess ownerProcess, Message message, uint recvListType, uint recvListOffset) + private static ulong[] GetReceiveList(KProcess ownerProcess, Message message, uint recvListType, uint recvListOffset) { int recvListSize = 0; @@ -964,16 +964,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return receiveList; } - private Result GetReceiveListAddress( + private static Result GetReceiveListAddress( PointerBufferDesc descriptor, - Message message, - uint recvListType, - uint messageSizeInWords, - ulong[] receiveList, - ref uint dstOffset, - out ulong address) + Message message, + uint recvListType, + uint messageSizeInWords, + ulong[] receiveList, + ref uint dstOffset, + out ulong address) { - ulong recvListBufferAddress = address = 0; + ulong recvListBufferAddress; + address = 0; if (recvListType == 0) { @@ -987,7 +988,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc if (recvListType == 1) { recvListBaseAddr = message.Address + messageSizeInWords * 4; - recvListEndAddr = message.Address + message.Size; + recvListEndAddr = message.Address + message.Size; } else /* if (recvListType == 2) */ { @@ -1012,7 +1013,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc dstOffset = (uint)endAddress - (uint)recvListBaseAddr; if (recvListBufferAddress + descriptor.BufferSize <= recvListBufferAddress || - recvListBufferAddress + descriptor.BufferSize > recvListEndAddr) + recvListBufferAddress + descriptor.BufferSize > recvListEndAddr) { return KernelResult.OutOfResource; } @@ -1041,7 +1042,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc return Result.Success; } - private void CloseAllHandles(Message message, MessageHeader header, KProcess process) + private static void CloseAllHandles(Message message, MessageHeader header, KProcess process) { if (header.HasHandles) { @@ -1202,7 +1203,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc } } - private void SendResultToAsyncRequestClient(KSessionRequest request, Result result) + private static void SendResultToAsyncRequestClient(KSessionRequest request, Result result) { KProcess clientProcess = request.ClientThread.Owner; @@ -1232,15 +1233,15 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc KernelContext.CriticalSection.Leave(); } - private void WakeAndSetResult(KThread thread, Result result, KSynchronizationObject signaledObj = null) + private static void WakeAndSetResult(KThread thread, Result result, KSynchronizationObject signaledObj = null) { if ((thread.SchedFlags & ThreadSchedState.LowMask) == ThreadSchedState.Paused) { - thread.SignaledObj = signaledObj; + thread.SignaledObj = signaledObj; thread.ObjSyncResult = result; thread.Reschedule(ThreadSchedState.Running); } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KSession.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KSession.cs index 13cf4b51b..6659d4141 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KSession.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KSession.cs @@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc public KServerSession ServerSession { get; } public KClientSession ClientSession { get; } - private bool _hasBeenInitialized; + private readonly bool _hasBeenInitialized; public KSession(KernelContext context, KClientPort parentPort = null) : base(context) { @@ -51,4 +51,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KSessionRequest.cs b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KSessionRequest.cs index 31ddfc9c4..bc3eef71e 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Ipc/KSessionRequest.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Ipc/KSessionRequest.cs @@ -17,17 +17,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc public ulong CustomCmdBuffSize { get; } public KSessionRequest( - KThread clientThread, - ulong customCmdBuffAddr, - ulong customCmdBuffSize, + KThread clientThread, + ulong customCmdBuffAddr, + ulong customCmdBuffSize, KWritableEvent asyncEvent = null) { - ClientThread = clientThread; + ClientThread = clientThread; CustomCmdBuffAddr = customCmdBuffAddr; CustomCmdBuffSize = customCmdBuffSize; - AsyncEvent = asyncEvent; + AsyncEvent = asyncEvent; BufferDescriptorTable = new KBufferDescriptorTable(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/KernelConstants.cs b/src/Ryujinx.HLE/HOS/Kernel/KernelConstants.cs index 28db750c7..3dbaec187 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/KernelConstants.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/KernelConstants.cs @@ -17,4 +17,4 @@ namespace Ryujinx.HLE.HOS.Kernel public const ulong CounterFrequency = 19200000; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs b/src/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs index c66f4b578..2234a8c42 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs @@ -10,10 +10,10 @@ namespace Ryujinx.HLE.HOS.Kernel static class KernelStatic { [ThreadStatic] - private static KernelContext Context; + private static KernelContext _context; [ThreadStatic] - private static KThread CurrentThread; + private static KThread _currentThread; public static Result StartInitialProcess( KernelContext context, @@ -22,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Kernel int mainThreadPriority, ThreadStart customThreadStart) { - KProcess process = new KProcess(context); + KProcess process = new(context); Result result = process.Initialize( creationInfo, @@ -46,13 +46,13 @@ namespace Ryujinx.HLE.HOS.Kernel internal static void SetKernelContext(KernelContext context, KThread thread) { - Context = context; - CurrentThread = thread; + _context = context; + _currentThread = thread; } internal static KThread GetCurrentThread() { - return CurrentThread; + return _currentThread; } internal static KProcess GetCurrentProcess() @@ -62,7 +62,7 @@ namespace Ryujinx.HLE.HOS.Kernel internal static KProcess GetProcessByPid(ulong pid) { - if (Context.Processes.TryGetValue(pid, out KProcess process)) + if (_context.Processes.TryGetValue(pid, out KProcess process)) { return process; } @@ -70,4 +70,4 @@ namespace Ryujinx.HLE.HOS.Kernel return null; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/AddressSpaceType.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/AddressSpaceType.cs index 8395c5777..8dfa4303f 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/AddressSpaceType.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/AddressSpaceType.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { enum AddressSpaceType { - Addr32Bits = 0, - Addr36Bits = 1, + Addr32Bits = 0, + Addr36Bits = 1, Addr32BitsNoMap = 2, - Addr39Bits = 3 + Addr39Bits = 3, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/DramMemoryMap.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/DramMemoryMap.cs index 4941d5b78..e7af29636 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/DramMemoryMap.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/DramMemoryMap.cs @@ -8,11 +8,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public const ulong SlabHeapBase = KernelReserveBase + 0x85000; public const ulong SlapHeapSize = 0xa21000; - public const ulong SlabHeapEnd = SlabHeapBase + SlapHeapSize; + public const ulong SlabHeapEnd = SlabHeapBase + SlapHeapSize; public static bool IsHeapPhysicalAddress(ulong address) { return address >= SlabHeapEnd; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs index 11474e493..c725501b0 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs @@ -166,4 +166,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory Owner.DecrementReferenceCount(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryBlock.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryBlock.cs index e082105b8..d2c4aadf3 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryBlock.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryBlock.cs @@ -153,4 +153,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryBlockSlabManager.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryBlockSlabManager.cs index 8732b507a..b4f566991 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryBlockSlabManager.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryBlockSlabManager.cs @@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { class KMemoryBlockSlabManager { - private ulong _capacityElements; + private readonly ulong _capacityElements; public int Count { get; set; } @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory return (ulong)(Count + count) <= _capacityElements; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryInfo.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryInfo.cs index af070ac23..4db484d04 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryInfo.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryInfo.cs @@ -3,34 +3,34 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory class KMemoryInfo { public ulong Address { get; } - public ulong Size { get; } + public ulong Size { get; } - public MemoryState State { get; } - public KMemoryPermission Permission { get; } - public MemoryAttribute Attribute { get; } + public MemoryState State { get; } + public KMemoryPermission Permission { get; } + public MemoryAttribute Attribute { get; } public KMemoryPermission SourcePermission { get; } - public int IpcRefCount { get; } + public int IpcRefCount { get; } public int DeviceRefCount { get; } public KMemoryInfo( - ulong address, - ulong size, - MemoryState state, + ulong address, + ulong size, + MemoryState state, KMemoryPermission permission, - MemoryAttribute attribute, + MemoryAttribute attribute, KMemoryPermission sourcePermission, - int ipcRefCount, - int deviceRefCount) + int ipcRefCount, + int deviceRefCount) { - Address = address; - Size = size; - State = state; - Permission = permission; - Attribute = attribute; + Address = address; + Size = size; + State = state; + Permission = permission; + Attribute = attribute; SourcePermission = sourcePermission; - IpcRefCount = ipcRefCount; - DeviceRefCount = deviceRefCount; + IpcRefCount = ipcRefCount; + DeviceRefCount = deviceRefCount; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryRegionManager.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryRegionManager.cs index 4596b15d5..2eff616c4 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryRegionManager.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KMemoryRegionManager.cs @@ -239,4 +239,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory return (EndAddr - address) / KPageTableBase.PageSize; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs index fa090b02c..e0f9df484 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs @@ -224,7 +224,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { while (depth >= 0) { - int ind = (int)(offset / UInt64BitSize); + int ind = (int)(offset / UInt64BitSize); int which = (int)(offset % UInt64BitSize); ulong mask = 1UL << which; @@ -247,7 +247,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { while (depth >= 0) { - int ind = (int)(offset / UInt64BitSize); + int ind = (int)(offset / UInt64BitSize); int which = (int)(offset % UInt64BitSize); ulong mask = 1UL << which; diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs index c3586ed78..635dcced8 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { private class Block { - private KPageBitmap _bitmap = new KPageBitmap(); + private readonly KPageBitmap _bitmap = new(); private ulong _heapAddress; private ulong _endOffset; @@ -29,8 +29,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory ? 1UL << nextBlockShift : 1UL << blockShift; - address = BitUtils.AlignDown(address, align); - endAddress = BitUtils.AlignUp (endAddress, align); + address = BitUtils.AlignDown(address, align); + endAddress = BitUtils.AlignUp(endAddress, align); _heapAddress = address; _endOffset = (endAddress - address) / (1UL << blockShift); @@ -84,11 +84,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory } } - private static readonly int[] _memoryBlockPageShifts = new int[] { 12, 16, 21, 22, 25, 29, 30 }; + private static readonly int[] _memoryBlockPageShifts = { 12, 16, 21, 22, 25, 29, 30 }; +#pragma warning disable IDE0052 // Remove unread private member private readonly ulong _heapAddress; private readonly ulong _heapSize; private ulong _usedSize; +#pragma warning restore IDE0052 private readonly int _blocksCount; private readonly Block[] _blocks; @@ -175,19 +177,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory int bigIndex = _blocksCount - 1; - ulong start = address; - ulong end = address + pagesCount * KPageTableBase.PageSize; + ulong start = address; + ulong end = address + pagesCount * KPageTableBase.PageSize; ulong beforeStart = start; - ulong beforeEnd = start; - ulong afterStart = end; - ulong afterEnd = end; + ulong beforeEnd = start; + ulong afterStart = end; + ulong afterEnd = end; while (bigIndex >= 0) { ulong blockSize = _blocks[bigIndex].Size; - ulong bigStart = BitUtils.AlignUp (start, blockSize); - ulong bigEnd = BitUtils.AlignDown(end, blockSize); + ulong bigStart = BitUtils.AlignUp(start, blockSize); + ulong bigEnd = BitUtils.AlignDown(end, blockSize); if (bigStart < bigEnd) { @@ -196,7 +198,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory FreeBlock(block, bigIndex); } - beforeEnd = bigStart; + beforeEnd = bigStart; afterStart = bigEnd; break; diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageList.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageList.cs index 3149faa97..60514824a 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageList.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageList.cs @@ -23,7 +23,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory if (lastNode.Address + lastNode.PagesCount * KPageTableBase.PageSize == address) { - address = lastNode.Address; + address = lastNode.Address; pagesCount += lastNode.PagesCount; Nodes.RemoveLast(); @@ -50,18 +50,18 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public bool IsEqual(KPageList other) { - LinkedListNode thisNode = Nodes.First; + LinkedListNode thisNode = Nodes.First; LinkedListNode otherNode = other.Nodes.First; while (thisNode != null && otherNode != null) { - if (thisNode.Value.Address != otherNode.Value.Address || + if (thisNode.Value.Address != otherNode.Value.Address || thisNode.Value.PagesCount != otherNode.Value.PagesCount) { return false; } - thisNode = thisNode.Next; + thisNode = thisNode.Next; otherNode = otherNode.Next; } @@ -94,4 +94,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageNode.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageNode.cs index ada41687e..395c8c835 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageNode.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageNode.cs @@ -7,8 +7,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public KPageNode(ulong address, ulong pagesCount) { - Address = address; + Address = address; PagesCount = pagesCount; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageTable.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageTable.cs index 119034c16..dcfc8f4ff 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageTable.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageTable.cs @@ -43,7 +43,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory /// protected override Result MapMemory(ulong src, ulong dst, ulong pagesCount, KMemoryPermission oldSrcPermission, KMemoryPermission newDstPermission) { - KPageList pageList = new KPageList(); + KPageList pageList = new(); GetPhysicalRegions(src, pagesCount * PageSize, pageList); Result result = Reprotect(src, pagesCount, KMemoryPermission.None); @@ -69,8 +69,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { ulong size = pagesCount * PageSize; - KPageList srcPageList = new KPageList(); - KPageList dstPageList = new KPageList(); + KPageList srcPageList = new(); + KPageList dstPageList = new(); GetPhysicalRegions(src, size, srcPageList); GetPhysicalRegions(dst, size, dstPageList); @@ -180,7 +180,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory /// protected override Result Unmap(ulong address, ulong pagesCount) { - KPageList pagesToClose = new KPageList(); + KPageList pagesToClose = new(); var regions = _cpuMemory.GetPhysicalRegions(address, pagesCount * PageSize); @@ -226,4 +226,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory _cpuMemory.Write(va, data); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs index 6746a0a7a..2b00f802a 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs @@ -12,14 +12,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { abstract class KPageTableBase { - private static readonly int[] MappingUnitSizes = new int[] - { + private static readonly int[] _mappingUnitSizes = { 0x1000, 0x10000, 0x200000, 0x400000, 0x2000000, - 0x40000000 + 0x40000000, }; private const ulong RegionAlignment = 0x200000; @@ -58,7 +57,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public ulong AslrRegionStart { get; private set; } public ulong AslrRegionEnd { get; private set; } +#pragma warning disable IDE0052 // Remove unread private member private ulong _heapCapacity; +#pragma warning restore IDE0052 public ulong PhysicalMemoryUsage { get; private set; } @@ -67,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory private MemoryRegion _memRegion; private bool _allocateFromBack; - private bool _isKernel; + private readonly bool _isKernel; private bool _aslrEnabled; @@ -77,10 +78,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory private MersenneTwister _randomNumberGenerator; - private MemoryFillValue _heapFillValue; - private MemoryFillValue _ipcFillValue; + private readonly MemoryFillValue _heapFillValue; + private readonly MemoryFillValue _ipcFillValue; - private ulong _reservedAddressSpaceSize; + private readonly ulong _reservedAddressSpaceSize; public KPageTableBase(KernelContext context, ulong reservedAddressSpaceSize) { @@ -96,7 +97,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory _reservedAddressSpaceSize = reservedAddressSpaceSize; } - private static readonly int[] AddrSpaceSizes = new int[] { 32, 36, 32, 39 }; + private static readonly int[] _addrSpaceSizes = { 32, 36, 32, 39 }; public Result InitializeForProcess( AddressSpaceType addrSpaceType, @@ -109,13 +110,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { if ((uint)addrSpaceType > (uint)AddressSpaceType.Addr39Bits) { - throw new ArgumentException(nameof(addrSpaceType)); + throw new ArgumentException($"AddressSpaceType bigger than {(uint)AddressSpaceType.Addr39Bits}: {(uint)addrSpaceType}", nameof(addrSpaceType)); } _contextId = Context.ContextIdManager.GetId(); ulong addrSpaceBase = 0; - ulong addrSpaceSize = 1UL << AddrSpaceSizes[(int)addrSpaceType]; + ulong addrSpaceSize = 1UL << _addrSpaceSizes[(int)addrSpaceType]; Result result = CreateUserAddressSpace( addrSpaceType, @@ -157,10 +158,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { ulong endAddr = address + size; - Region aliasRegion = new Region(); - Region heapRegion = new Region(); - Region stackRegion = new Region(); - Region tlsIoRegion = new Region(); + Region aliasRegion = new(); + Region heapRegion = new(); + Region stackRegion = new(); + Region tlsIoRegion = new(); ulong codeRegionSize; ulong stackAndTlsIoStart; @@ -238,8 +239,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory stackAndTlsIoEnd = 0; } break; - - default: throw new ArgumentException(nameof(addrSpaceType)); + default: + throw new ArgumentException($"AddressSpaceType bigger than {(uint)AddressSpaceType.Addr39Bits}: {(uint)addrSpaceType}", nameof(addrSpaceType)); } CodeRegionEnd = CodeRegionStart + codeRegionSize; @@ -374,10 +375,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory private long GetRandomValue(long min, long max) { - if (_randomNumberGenerator == null) - { - _randomNumberGenerator = new MersenneTwister(0); - } + _randomNumberGenerator ??= new MersenneTwister(0); return _randomNumberGenerator.GenRandomNumber(min, max); } @@ -442,7 +440,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory lock (_blockManager) { - KPageList currentPageList = new KPageList(); + KPageList currentPageList = new(); GetPhysicalRegions(address, size, currentPageList); @@ -486,13 +484,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory } } - public Result MapNormalMemory(long address, long size, KMemoryPermission permission) + public static Result MapNormalMemory(long address, long size, KMemoryPermission permission) { // TODO. return Result.Success; } - public Result MapIoMemory(long address, long size, KMemoryPermission permission) + public static Result MapIoMemory(long address, long size, KMemoryPermission permission) { // TODO. return Result.Success; @@ -1174,8 +1172,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory return KernelResult.InvalidMemState; } - KPageList srcPageList = new KPageList(); - KPageList dstPageList = new KPageList(); + KPageList srcPageList = new(); + KPageList dstPageList = new(); srcPageTable.GetPhysicalRegions(src, size, srcPageList); GetPhysicalRegions(dst, size, dstPageList); @@ -1681,11 +1679,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory switch (state) { - case MemoryState.IpcBuffer0: stateMask = MemoryState.IpcSendAllowedType0; break; - case MemoryState.IpcBuffer1: stateMask = MemoryState.IpcSendAllowedType1; break; - case MemoryState.IpcBuffer3: stateMask = MemoryState.IpcSendAllowedType3; break; - - default: return KernelResult.InvalidCombination; + case MemoryState.IpcBuffer0: + stateMask = MemoryState.IpcSendAllowedType0; + break; + case MemoryState.IpcBuffer1: + stateMask = MemoryState.IpcSendAllowedType1; + break; + case MemoryState.IpcBuffer3: + stateMask = MemoryState.IpcSendAllowedType3; + break; + default: + return KernelResult.InvalidCombination; } KMemoryPermission permissionMask = permission == KMemoryPermission.ReadAndWrite @@ -1822,9 +1826,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory ulong va = 0; - for (int unit = MappingUnitSizes.Length - 1; unit >= 0 && va == 0; unit--) + for (int unit = _mappingUnitSizes.Length - 1; unit >= 0 && va == 0; unit--) { - int alignment = MappingUnitSizes[unit]; + int alignment = _mappingUnitSizes[unit]; va = AllocateVa(AliasRegionStart, regionPagesCount, neededPagesCount, alignment); } @@ -1937,7 +1941,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory if (srcPageTable.Supports4KBPages) { - KPageList pageList = new KPageList(); + KPageList pageList = new(); srcPageTable.GetPhysicalRegions(addressRounded, alignedSize, pageList); result = MapPages(currentVa, pageList, permission, MemoryMapFlags.None); @@ -2075,11 +2079,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory switch (state) { - case MemoryState.IpcBuffer0: stateMask = MemoryState.IpcSendAllowedType0; break; - case MemoryState.IpcBuffer1: stateMask = MemoryState.IpcSendAllowedType1; break; - case MemoryState.IpcBuffer3: stateMask = MemoryState.IpcSendAllowedType3; break; - - default: return KernelResult.InvalidCombination; + case MemoryState.IpcBuffer0: + stateMask = MemoryState.IpcSendAllowedType0; + break; + case MemoryState.IpcBuffer1: + stateMask = MemoryState.IpcSendAllowedType1; + break; + case MemoryState.IpcBuffer3: + stateMask = MemoryState.IpcSendAllowedType3; + break; + default: + return KernelResult.InvalidCombination; } MemoryAttribute attributeMask = @@ -2392,7 +2402,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory if (pageList != null) { - KPageList currentPageList = new KPageList(); + KPageList currentPageList = new(); GetPhysicalRegions(address, pagesCount * PageSize, currentPageList); @@ -3050,4 +3060,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory /// Throw for unhandled invalid or unmapped memory accesses protected abstract void Write(ulong va, ReadOnlySpan data); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KScopedPageList.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KScopedPageList.cs index a0c19f9c1..498e6f8c8 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KScopedPageList.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KScopedPageList.cs @@ -19,7 +19,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory _pageList = null; } - public void Dispose() + public readonly void Dispose() { _pageList?.DecrementPagesReferenceCount(_manager); } diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs index 5ec3cd724..e302ee443 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs @@ -72,4 +72,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory return memoryManager.UnmapPages(address, _pageList, MemoryState.SharedMemory); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KSlabHeap.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KSlabHeap.cs index 9051e84cc..cd8c2e470 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KSlabHeap.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KSlabHeap.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { class KSlabHeap { - private LinkedList _items; + private readonly LinkedList _items; public KSlabHeap(ulong pa, ulong itemSize, ulong size) { @@ -47,4 +47,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs index b24495980..9f64532e7 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs @@ -127,4 +127,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryAttribute.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryAttribute.cs index 42407ffe2..36b1ec8c3 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryAttribute.cs @@ -3,20 +3,20 @@ using System; namespace Ryujinx.HLE.HOS.Kernel.Memory { [Flags] - enum MemoryAttribute : byte + enum MemoryAttribute : byte { None = 0, Mask = 0xff, - Borrowed = 1 << 0, - IpcMapped = 1 << 1, + Borrowed = 1 << 0, + IpcMapped = 1 << 1, DeviceMapped = 1 << 2, - Uncached = 1 << 3, + Uncached = 1 << 3, IpcAndDeviceMapped = IpcMapped | DeviceMapped, BorrowedAndIpcMapped = Borrowed | IpcMapped, - DeviceMappedAndUncached = DeviceMapped | Uncached + DeviceMappedAndUncached = DeviceMapped | Uncached, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryPermission.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryPermission.cs index 563b817d8..068cdbb88 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryPermission.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryPermission.cs @@ -5,16 +5,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory [Flags] enum KMemoryPermission : uint { - None = 0, + None = 0, UserMask = Read | Write | Execute, - Mask = uint.MaxValue, + Mask = uint.MaxValue, - Read = 1 << 0, - Write = 1 << 1, - Execute = 1 << 2, + Read = 1 << 0, + Write = 1 << 1, + Execute = 1 << 2, DontCare = 1 << 28, - ReadAndWrite = Read | Write, - ReadAndExecute = Read | Execute + ReadAndWrite = Read | Write, + ReadAndExecute = Read | Execute, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryRegion.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryRegion.cs index ad719bded..18784bf91 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryRegion.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryRegion.cs @@ -3,8 +3,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory enum MemoryRegion { Application = 0, - Applet = 1, - Service = 2, - NvServices = 3 + Applet = 1, + Service = 2, + NvServices = 3, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryState.cs b/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryState.cs index d3b61780c..273b58e5e 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryState.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Memory/MemoryState.cs @@ -5,46 +5,46 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory [Flags] enum MemoryState : uint { - Unmapped = 0x00000000, - Io = 0x00002001, - Normal = 0x00042002, - CodeStatic = 0x00DC7E03, - CodeMutable = 0x03FEBD04, - Heap = 0x037EBD05, - SharedMemory = 0x00402006, - ModCodeStatic = 0x00DD7E08, - ModCodeMutable = 0x03FFBD09, - IpcBuffer0 = 0x005C3C0A, - Stack = 0x005C3C0B, - ThreadLocal = 0x0040200C, + Unmapped = 0x00000000, + Io = 0x00002001, + Normal = 0x00042002, + CodeStatic = 0x00DC7E03, + CodeMutable = 0x03FEBD04, + Heap = 0x037EBD05, + SharedMemory = 0x00402006, + ModCodeStatic = 0x00DD7E08, + ModCodeMutable = 0x03FFBD09, + IpcBuffer0 = 0x005C3C0A, + Stack = 0x005C3C0B, + ThreadLocal = 0x0040200C, TransferMemoryIsolated = 0x015C3C0D, - TransferMemory = 0x005C380E, - ProcessMemory = 0x0040380F, - Reserved = 0x00000010, - IpcBuffer1 = 0x005C3811, - IpcBuffer3 = 0x004C2812, - KernelStack = 0x00002013, - CodeReadOnly = 0x00402214, - CodeWritable = 0x00402015, - UserMask = 0xff, - Mask = 0xffffffff, + TransferMemory = 0x005C380E, + ProcessMemory = 0x0040380F, + Reserved = 0x00000010, + IpcBuffer1 = 0x005C3811, + IpcBuffer3 = 0x004C2812, + KernelStack = 0x00002013, + CodeReadOnly = 0x00402214, + CodeWritable = 0x00402015, + UserMask = 0xff, + Mask = 0xffffffff, - PermissionChangeAllowed = 1 << 8, + PermissionChangeAllowed = 1 << 8, ForceReadWritableByDebugSyscalls = 1 << 9, - IpcSendAllowedType0 = 1 << 10, - IpcSendAllowedType3 = 1 << 11, - IpcSendAllowedType1 = 1 << 12, - ProcessPermissionChangeAllowed = 1 << 14, - MapAllowed = 1 << 15, - UnmapProcessCodeMemoryAllowed = 1 << 16, - TransferMemoryAllowed = 1 << 17, - QueryPhysicalAddressAllowed = 1 << 18, - MapDeviceAllowed = 1 << 19, - MapDeviceAlignedAllowed = 1 << 20, - IpcBufferAllowed = 1 << 21, - IsPoolAllocated = 1 << 22, - MapProcessAllowed = 1 << 23, - AttributeChangeAllowed = 1 << 24, - CodeMemoryAllowed = 1 << 25 + IpcSendAllowedType0 = 1 << 10, + IpcSendAllowedType3 = 1 << 11, + IpcSendAllowedType1 = 1 << 12, + ProcessPermissionChangeAllowed = 1 << 14, + MapAllowed = 1 << 15, + UnmapProcessCodeMemoryAllowed = 1 << 16, + TransferMemoryAllowed = 1 << 17, + QueryPhysicalAddressAllowed = 1 << 18, + MapDeviceAllowed = 1 << 19, + MapDeviceAlignedAllowed = 1 << 20, + IpcBufferAllowed = 1 << 21, + IsPoolAllocated = 1 << 22, + MapProcessAllowed = 1 << 23, + AttributeChangeAllowed = 1 << 24, + CodeMemoryAllowed = 1 << 25, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityExtensions.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityExtensions.cs index 66d56fe31..dd133ee15 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityExtensions.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityExtensions.cs @@ -19,4 +19,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return (uint)BitOperations.TrailingZeroCount(type.GetFlag()); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityType.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityType.cs index 51d92316d..9812eea0c 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityType.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityType.cs @@ -2,18 +2,18 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { enum CapabilityType : uint { - CorePriority = (1u << 3) - 1, - SyscallMask = (1u << 4) - 1, - MapRange = (1u << 6) - 1, - MapIoPage = (1u << 7) - 1, - MapRegion = (1u << 10) - 1, + CorePriority = (1u << 3) - 1, + SyscallMask = (1u << 4) - 1, + MapRange = (1u << 6) - 1, + MapIoPage = (1u << 7) - 1, + MapRegion = (1u << 10) - 1, InterruptPair = (1u << 11) - 1, - ProgramType = (1u << 13) - 1, + ProgramType = (1u << 13) - 1, KernelVersion = (1u << 14) - 1, - HandleTable = (1u << 15) - 1, - DebugFlags = (1u << 16) - 1, + HandleTable = (1u << 15) - 1, + DebugFlags = (1u << 16) - 1, - Invalid = 0u, - Padding = ~0u + Invalid = 0u, + Padding = ~0u, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs index 8fee5c0d1..cbfef588c 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs @@ -14,7 +14,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { private const int Mod0 = 'M' << 0 | 'O' << 8 | 'D' << 16 | '0' << 24; - private KProcess _owner; + private readonly KProcess _owner; private class Image { @@ -27,12 +27,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public Image(ulong baseAddress, ulong size, ElfSymbol[] symbols) { BaseAddress = baseAddress; - Size = size; - Symbols = symbols; + Size = size; + Symbols = symbols; } } - private List _images; + private readonly List _images; private int _loaded; @@ -49,7 +49,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process var context = thread.Context; - StringBuilder trace = new StringBuilder(); + StringBuilder trace = new(); trace.AppendLine($"Process: {_owner.Name}, PID: {_owner.Pid}"); @@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process var context = thread.Context; - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new(); string GetReg(int x) { @@ -145,11 +145,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return sb.ToString(); } - private bool TryGetSubName(Image image, ulong address, out ElfSymbol symbol) + private static bool TryGetSubName(Image image, ulong address, out ElfSymbol symbol) { address -= image.BaseAddress; - int left = 0; + int left = 0; int right = image.Symbols.Length - 1; while (left <= right) @@ -190,9 +190,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public ulong Offset; public ulong SubOffset; - public string ImageDisplay => $"{ImageName}:0x{Offset:x4}"; - public string SubDisplay => SubOffset == 0 ? SubName : $"{SubName}:0x{SubOffset:x4}"; - public string SpDisplay => SubOffset == 0 ? "SP" : $"SP:-0x{SubOffset:x4}"; + public readonly string ImageDisplay => $"{ImageName}:0x{Offset:x4}"; + public readonly string SubDisplay => SubOffset == 0 ? SubName : $"{SubName}:0x{SubOffset:x4}"; + public readonly string SpDisplay => SubOffset == 0 ? "SP" : $"SP:-0x{SubOffset:x4}"; } private bool AnalyzePointer(out PointerInfo info, ulong address, KThread thread) @@ -324,7 +324,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process private void ScanMemoryForTextSegments() { ulong oldAddress = 0; - ulong address = 0; + ulong address = 0; while (address >= oldAddress) { @@ -355,7 +355,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return; } - Dictionary dynamic = new Dictionary(); + Dictionary dynamic = new(); int mod0Magic = memory.Read(mod0Offset + 0x0); @@ -364,12 +364,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return; } - ulong dynamicOffset = memory.Read(mod0Offset + 0x4) + mod0Offset; - ulong bssStartOffset = memory.Read(mod0Offset + 0x8) + mod0Offset; - ulong bssEndOffset = memory.Read(mod0Offset + 0xc) + mod0Offset; + ulong dynamicOffset = memory.Read(mod0Offset + 0x4) + mod0Offset; + ulong bssStartOffset = memory.Read(mod0Offset + 0x8) + mod0Offset; + ulong bssEndOffset = memory.Read(mod0Offset + 0xc) + mod0Offset; ulong ehHdrStartOffset = memory.Read(mod0Offset + 0x10) + mod0Offset; - ulong ehHdrEndOffset = memory.Read(mod0Offset + 0x14) + mod0Offset; - ulong modObjOffset = memory.Read(mod0Offset + 0x18) + mod0Offset; + ulong ehHdrEndOffset = memory.Read(mod0Offset + 0x14) + mod0Offset; + ulong modObjOffset = memory.Read(mod0Offset + 0x18) + mod0Offset; bool isAArch32 = memory.Read(dynamicOffset) > 0xFFFFFFFF || memory.Read(dynamicOffset + 0x10) > 0xFFFFFFFF; @@ -381,14 +381,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process if (isAArch32) { tagVal = memory.Read(dynamicOffset + 0); - value = memory.Read(dynamicOffset + 4); + value = memory.Read(dynamicOffset + 4); dynamicOffset += 0x8; } else { tagVal = memory.Read(dynamicOffset + 0); - value = memory.Read(dynamicOffset + 8); + value = memory.Read(dynamicOffset + 8); dynamicOffset += 0x10; } @@ -413,7 +413,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process ulong strTblAddr = textOffset + strTab; ulong symTblAddr = textOffset + symTab; - List symbols = new List(); + List symbols = new(); while (symTblAddr < strTblAddr) { @@ -430,7 +430,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } } - private ElfSymbol GetSymbol64(IVirtualMemoryManager memory, ulong address, ulong strTblAddr) + private static ElfSymbol GetSymbol64(IVirtualMemoryManager memory, ulong address, ulong strTblAddr) { ElfSymbol64 sym = memory.Read(address); @@ -446,7 +446,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size); } - private ElfSymbol GetSymbol32(IVirtualMemoryManager memory, ulong address, ulong strTblAddr) + private static ElfSymbol GetSymbol32(IVirtualMemoryManager memory, ulong address, ulong strTblAddr) { ElfSymbol32 sym = memory.Read(address); diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KContextIdManager.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KContextIdManager.cs index 104fe578a..32a751325 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KContextIdManager.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KContextIdManager.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { private const int IdMasksCount = 8; - private int[] _idMasks; + private readonly int[] _idMasks; private int _nextFreeBitHint; @@ -67,17 +67,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Process private bool TestBit(int bit) { - return (_idMasks[_nextFreeBitHint / 32] & (1 << (_nextFreeBitHint & 31))) != 0; + return (_idMasks[bit / 32] & (1 << (bit & 31))) != 0; } private void SetBit(int bit) { - _idMasks[_nextFreeBitHint / 32] |= (1 << (_nextFreeBitHint & 31)); + _idMasks[bit / 32] |= (1 << (bit & 31)); } private void ClearBit(int bit) { - _idMasks[_nextFreeBitHint / 32] &= ~(1 << (_nextFreeBitHint & 31)); + _idMasks[bit / 32] &= ~(1 << (bit & 31)); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleEntry.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleEntry.cs index b5ca9b5e2..c80423b7a 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleEntry.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleEntry.cs @@ -8,12 +8,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public int Index { get; private set; } - public ushort HandleId { get; set; } - public KAutoObject Obj { get; set; } + public ushort HandleId { get; set; } + public KAutoObject Obj { get; set; } public KHandleEntry(int index) { Index = index; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleTable.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleTable.cs index 6dd7e5b78..21ea6bb28 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleTable.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleTable.cs @@ -7,11 +7,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { class KHandleTable { - public const int SelfThreadHandle = (0x1ffff << 15) | 0; + public const int SelfThreadHandle = (0x1ffff << 15) | 0; public const int SelfProcessHandle = (0x1ffff << 15) | 1; - private readonly KernelContext _context; - private KHandleEntry[] _table; private KHandleEntry _tableHead; @@ -23,11 +21,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process private ushort _idCounter; - public KHandleTable(KernelContext context) - { - _context = context; - } - public Result Initialize(uint size) { if (size > 1024) @@ -81,7 +74,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process _nextFreeEntry = entry.Next; - entry.Obj = obj; + entry.Obj = obj; entry.HandleId = _idCounter; _activeSlotsCount++; @@ -143,7 +136,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { KHandleEntry entry = _table[index]; - entry.Obj = null; + entry.Obj = null; entry.Next = _nextFreeEntry; _nextFreeEntry = entry; @@ -154,14 +147,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public void SetReservedHandleObj(int handle, KAutoObject obj) { - int index = (handle >> 0) & 0x7fff; + int index = (handle >> 0) & 0x7fff; int handleId = (handle >> 15); lock (_table) { KHandleEntry entry = _table[index]; - entry.Obj = obj; + entry.Obj = obj; entry.HandleId = (ushort)handleId; obj.IncrementReferenceCount(); @@ -177,7 +170,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return false; } - int index = (handle >> 0) & 0x7fff; + int index = (handle >> 0) & 0x7fff; int handleId = (handle >> 15); KAutoObject obj = null; @@ -192,7 +185,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process if ((obj = entry.Obj) != null && entry.HandleId == handleId) { - entry.Obj = null; + entry.Obj = null; entry.Next = _nextFreeEntry; _nextFreeEntry = entry; @@ -214,7 +207,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public T GetObject(int handle) where T : KAutoObject { - int index = (handle >> 0) & 0x7fff; + int index = (handle >> 0) & 0x7fff; int handleId = (handle >> 15); lock (_table) @@ -273,7 +266,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } entry.Obj.DecrementReferenceCount(); - entry.Obj = null; + entry.Obj = null; entry.Next = _nextFreeEntry; _nextFreeEntry = entry; @@ -282,4 +275,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs index c284243ae..6008548be 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs @@ -27,8 +27,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public KPageTableBase MemoryManager { get; private set; } - private SortedDictionary _fullTlsPages; - private SortedDictionary _freeTlsPages; + private readonly SortedDictionary _fullTlsPages; + private readonly SortedDictionary _freeTlsPages; public int DefaultCpuCore { get; set; } @@ -66,19 +66,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public bool IsApplication { get; private set; } public ulong Pid { get; private set; } - private long _creationTimestamp; private ulong _entrypoint; private ThreadStart _customThreadStart; private ulong _imageSize; private ulong _mainThreadStackSize; private ulong _memoryUsageCapacity; - private int _version; public KHandleTable HandleTable { get; private set; } public ulong UserExceptionContextAddress { get; private set; } - private LinkedList _threads; + private readonly LinkedList _threads; public bool IsPaused { get; private set; } @@ -107,7 +105,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process PinnedThreads = new KThread[KScheduler.CpuCoresCount]; // TODO: Remove once we no longer need to initialize it externally. - HandleTable = new KHandleTable(context); + HandleTable = new KHandleTable(); _threads = new LinkedList(); @@ -347,10 +345,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process State = ProcessState.Created; - _creationTimestamp = PerformanceCounter.ElapsedMilliseconds; - Flags = creationInfo.Flags; - _version = creationInfo.Version; TitleId = creationInfo.TitleId; _entrypoint = creationInfo.CodeAddress; _imageSize = (ulong)creationInfo.CodePagesCount * KPageTableBase.PageSize; @@ -370,8 +365,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process MemoryManager.AliasRegionEnd - MemoryManager.AliasRegionStart; break; - - default: throw new InvalidOperationException($"Invalid MMU flags value 0x{Flags:x2}."); + default: + throw new InvalidOperationException($"Invalid MMU flags value 0x{Flags:x2}."); } GenerateRandomEntropy(); @@ -476,9 +471,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process Result result = Result.Success; - KTlsPageInfo pageInfo; - if (_fullTlsPages.TryGetValue(tlsPageAddr, out pageInfo)) + if (_fullTlsPages.TryGetValue(tlsPageAddr, out KTlsPageInfo pageInfo)) { // TLS page was full, free slot and move to free pages tree. _fullTlsPages.Remove(tlsPageAddr); @@ -525,10 +519,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return result; } +#pragma warning disable CA1822 // Mark member as static private void GenerateRandomEntropy() { // TODO. } +#pragma warning restore CA1822 public Result Start(int mainThreadPriority, ulong stackSize) { @@ -549,7 +545,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process if (_mainThreadStackSize != 0) { - throw new InvalidOperationException("Trying to start a process with a invalid state!"); + throw new InvalidOperationException("Trying to start a process with an invalid state!"); } ulong stackSizeRounded = BitUtils.AlignUp(stackSize, KPageTableBase.PageSize); @@ -648,7 +644,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return result; } - HandleTable = new KHandleTable(KernelContext); + HandleTable = new KHandleTable(); result = HandleTable.Initialize(Capabilities.HandleTableSize); @@ -1018,22 +1014,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } } - private void SignalExitToDebugTerminated() + private static void SignalExitToDebugTerminated() { // TODO: Debug events. } - private void SignalExitToDebugExited() + private static void SignalExitToDebugExited() { // TODO: Debug events. } private void SignalExit() { - if (ResourceLimit != null) - { - ResourceLimit.Release(LimitableResource.Memory, GetMemoryUsage()); - } + ResourceLimit?.Release(LimitableResource.Memory, GetMemoryUsage()); KernelContext.CriticalSection.Enter(); @@ -1075,7 +1068,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process ProcessCreationFlags.AddressSpace64BitDeprecated => 36, ProcessCreationFlags.AddressSpace32BitWithoutAlias => 32, ProcessCreationFlags.AddressSpace64Bit => 39, - _ => 39 + _ => 39, }; bool for64Bit = flags.HasFlag(ProcessCreationFlags.Is64Bit); @@ -1184,10 +1177,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } } - public bool IsExceptionUserThread(KThread thread) + public static bool IsExceptionUserThread(KThread thread) { // TODO return false; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcessCapabilities.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcessCapabilities.cs index c99e31123..314aadf36 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcessCapabilities.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcessCapabilities.cs @@ -11,13 +11,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public byte[] SvcAccessMask { get; } public byte[] IrqAccessMask { get; } - public ulong AllowedCpuCoresMask { get; private set; } + public ulong AllowedCpuCoresMask { get; private set; } public ulong AllowedThreadPriosMask { get; private set; } - public uint DebuggingFlags { get; private set; } - public uint HandleTableSize { get; private set; } + public uint DebuggingFlags { get; private set; } + public uint HandleTableSize { get; private set; } public uint KernelReleaseVersion { get; private set; } - public uint ApplicationType { get; private set; } + public uint ApplicationType { get; private set; } public KProcessCapabilities() { @@ -28,10 +28,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public Result InitializeForKernel(ReadOnlySpan capabilities, KPageTableBase memoryManager) { - AllowedCpuCoresMask = 0xf; + AllowedCpuCoresMask = 0xf; AllowedThreadPriosMask = ulong.MaxValue; - DebuggingFlags &= ~3u; - KernelReleaseVersion = KProcess.KernelVersionPacked; + DebuggingFlags &= ~3u; + KernelReleaseVersion = KProcess.KernelVersionPacked; return Parse(capabilities, memoryManager); } @@ -86,7 +86,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } long address = ((long)prevCap << 5) & 0xffffff000; - long size = ((long)cap << 5) & 0xfffff000; + long size = ((long)cap << 5) & 0xfffff000; if (((ulong)(address + size - 1) >> 36) != 0) { @@ -101,11 +101,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Process if ((cap >> 31) != 0) { - result = memoryManager.MapNormalMemory(address, size, perm); + result = KPageTableBase.MapNormalMemory(address, size, perm); } else { - result = memoryManager.MapIoMemory(address, size, perm); + result = KPageTableBase.MapIoMemory(address, size, perm); } if (result != Result.Success) @@ -144,168 +144,168 @@ namespace Ryujinx.HLE.HOS.Kernel.Process switch (code) { case CapabilityType.CorePriority: - { - if (AllowedCpuCoresMask != 0 || AllowedThreadPriosMask != 0) { - return KernelResult.InvalidCapability; + if (AllowedCpuCoresMask != 0 || AllowedThreadPriosMask != 0) + { + return KernelResult.InvalidCapability; + } + + uint lowestCpuCore = (cap >> 16) & 0xff; + uint highestCpuCore = (cap >> 24) & 0xff; + + if (lowestCpuCore > highestCpuCore) + { + return KernelResult.InvalidCombination; + } + + uint highestThreadPrio = (cap >> 4) & 0x3f; + uint lowestThreadPrio = (cap >> 10) & 0x3f; + + if (lowestThreadPrio > highestThreadPrio) + { + return KernelResult.InvalidCombination; + } + + if (highestCpuCore >= KScheduler.CpuCoresCount) + { + return KernelResult.InvalidCpuCore; + } + + AllowedCpuCoresMask = GetMaskFromMinMax(lowestCpuCore, highestCpuCore); + AllowedThreadPriosMask = GetMaskFromMinMax(lowestThreadPrio, highestThreadPrio); + + break; } - uint lowestCpuCore = (cap >> 16) & 0xff; - uint highestCpuCore = (cap >> 24) & 0xff; - - if (lowestCpuCore > highestCpuCore) - { - return KernelResult.InvalidCombination; - } - - uint highestThreadPrio = (cap >> 4) & 0x3f; - uint lowestThreadPrio = (cap >> 10) & 0x3f; - - if (lowestThreadPrio > highestThreadPrio) - { - return KernelResult.InvalidCombination; - } - - if (highestCpuCore >= KScheduler.CpuCoresCount) - { - return KernelResult.InvalidCpuCore; - } - - AllowedCpuCoresMask = GetMaskFromMinMax(lowestCpuCore, highestCpuCore); - AllowedThreadPriosMask = GetMaskFromMinMax(lowestThreadPrio, highestThreadPrio); - - break; - } - case CapabilityType.SyscallMask: - { - int slot = ((int)cap >> 29) & 7; - - int svcSlotMask = 1 << slot; - - if ((mask1 & svcSlotMask) != 0) { - return KernelResult.InvalidCombination; - } + int slot = ((int)cap >> 29) & 7; - mask1 |= svcSlotMask; + int svcSlotMask = 1 << slot; - uint svcMask = (cap >> 5) & 0xffffff; - - int baseSvc = slot * 24; - - for (int index = 0; index < 24; index++) - { - if (((svcMask >> index) & 1) == 0) + if ((mask1 & svcSlotMask) != 0) { - continue; + return KernelResult.InvalidCombination; } - int svcId = baseSvc + index; + mask1 |= svcSlotMask; - if (svcId >= KernelConstants.SupervisorCallCount) + uint svcMask = (cap >> 5) & 0xffffff; + + int baseSvc = slot * 24; + + for (int index = 0; index < 24; index++) { - return KernelResult.MaximumExceeded; + if (((svcMask >> index) & 1) == 0) + { + continue; + } + + int svcId = baseSvc + index; + + if (svcId >= KernelConstants.SupervisorCallCount) + { + return KernelResult.MaximumExceeded; + } + + SvcAccessMask[svcId / 8] |= (byte)(1 << (svcId & 7)); } - SvcAccessMask[svcId / 8] |= (byte)(1 << (svcId & 7)); + break; } - break; - } - case CapabilityType.MapIoPage: - { - long address = ((long)cap << 4) & 0xffffff000; + { + long address = ((long)cap << 4) & 0xffffff000; - memoryManager.MapIoMemory(address, KPageTableBase.PageSize, KMemoryPermission.ReadAndWrite); + KPageTableBase.MapIoMemory(address, KPageTableBase.PageSize, KMemoryPermission.ReadAndWrite); - break; - } + break; + } case CapabilityType.MapRegion: - { - // TODO: Implement capabilities for MapRegion + { + // TODO: Implement capabilities for MapRegion - break; - } + break; + } case CapabilityType.InterruptPair: - { - // TODO: GIC distributor check. - int irq0 = ((int)cap >> 12) & 0x3ff; - int irq1 = ((int)cap >> 22) & 0x3ff; - - if (irq0 != 0x3ff) { - IrqAccessMask[irq0 / 8] |= (byte)(1 << (irq0 & 7)); - } + // TODO: GIC distributor check. + int irq0 = ((int)cap >> 12) & 0x3ff; + int irq1 = ((int)cap >> 22) & 0x3ff; - if (irq1 != 0x3ff) - { - IrqAccessMask[irq1 / 8] |= (byte)(1 << (irq1 & 7)); - } + if (irq0 != 0x3ff) + { + IrqAccessMask[irq0 / 8] |= (byte)(1 << (irq0 & 7)); + } - break; - } + if (irq1 != 0x3ff) + { + IrqAccessMask[irq1 / 8] |= (byte)(1 << (irq1 & 7)); + } + + break; + } case CapabilityType.ProgramType: - { - uint applicationType = (cap >> 14); - - if (applicationType > 7) { - return KernelResult.ReservedValue; + uint applicationType = (cap >> 14); + + if (applicationType > 7) + { + return KernelResult.ReservedValue; + } + + ApplicationType = applicationType; + + break; } - ApplicationType = applicationType; - - break; - } - case CapabilityType.KernelVersion: - { - // Note: This check is bugged on kernel too, we are just replicating the bug here. - if ((KernelReleaseVersion >> 17) != 0 || cap < 0x80000) { - return KernelResult.ReservedValue; + // Note: This check is bugged on kernel too, we are just replicating the bug here. + if ((KernelReleaseVersion >> 17) != 0 || cap < 0x80000) + { + return KernelResult.ReservedValue; + } + + KernelReleaseVersion = cap; + + break; } - KernelReleaseVersion = cap; - - break; - } - case CapabilityType.HandleTable: - { - uint handleTableSize = cap >> 26; - - if (handleTableSize > 0x3ff) { - return KernelResult.ReservedValue; + uint handleTableSize = cap >> 26; + + if (handleTableSize > 0x3ff) + { + return KernelResult.ReservedValue; + } + + HandleTableSize = handleTableSize; + + break; } - HandleTableSize = handleTableSize; - - break; - } - case CapabilityType.DebugFlags: - { - uint debuggingFlags = cap >> 19; - - if (debuggingFlags > 3) { - return KernelResult.ReservedValue; + uint debuggingFlags = cap >> 19; + + if (debuggingFlags > 3) + { + return KernelResult.ReservedValue; + } + + DebuggingFlags &= ~3u; + DebuggingFlags |= debuggingFlags; + + break; } - - DebuggingFlags &= ~3u; - DebuggingFlags |= debuggingFlags; - - break; - } - - default: return KernelResult.InvalidCapability; + default: + return KernelResult.InvalidCapability; } return Result.Success; @@ -325,4 +325,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return mask << (int)min; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageInfo.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageInfo.cs index f55e3c10e..7fcd87b6c 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageInfo.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageInfo.cs @@ -74,4 +74,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process _isSlotFree[(address - PageVirtualAddress) / TlsEntrySize] = true; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageManager.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageManager.cs index 0fde495ca..279fa13e8 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageManager.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageManager.cs @@ -7,14 +7,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { private const int TlsEntrySize = 0x200; - private long _pagePosition; + private readonly long _pagePosition; private int _usedSlots; - private bool[] _slots; + private readonly bool[] _slots; public bool IsEmpty => _usedSlots == 0; - public bool IsFull => _usedSlots == _slots.Length; + public bool IsFull => _usedSlots == _slots.Length; public KTlsPageManager(long pagePosition) { @@ -58,4 +58,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process _usedSlots--; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationFlags.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationFlags.cs index a79978ac4..c68190d69 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationFlags.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationFlags.cs @@ -1,8 +1,10 @@ using System; +using System.Diagnostics.CodeAnalysis; namespace Ryujinx.HLE.HOS.Kernel.Process { [Flags] + [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")] enum ProcessCreationFlags { Is64Bit = 1 << 0, @@ -36,6 +38,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process IsApplication | DeprecatedUseSecureMemory | PoolPartitionMask | - OptimizeMemoryAllocation + OptimizeMemoryAllocation, } } diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationInfo.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationInfo.cs index c05bb574e..b5e5c29bb 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationInfo.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationInfo.cs @@ -34,4 +34,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process SystemResourcePagesCount = systemResourcePagesCount; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs index 77fcdf33b..b8118fbb4 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs @@ -7,9 +7,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { public ulong Pc => 0UL; - public ulong CntfrqEl0 { get; set; } - public ulong CntpctEl0 => 0UL; - public long TpidrEl0 { get; set; } public long TpidrroEl0 { get; set; } @@ -43,4 +40,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessState.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessState.cs index 5ef3077e3..e6c7e33e7 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessState.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessState.cs @@ -2,13 +2,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { enum ProcessState : byte { - Created = 0, + Created = 0, CreatedAttached = 1, - Started = 2, - Crashed = 3, - Attached = 4, - Exiting = 5, - Exited = 6, - DebugSuspended = 7 + Started = 2, + Crashed = 3, + Attached = 4, + Exiting = 5, + Exited = 6, + DebugSuspended = 7, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessTamperInfo.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessTamperInfo.cs index 4cf67172d..8eafd96c2 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessTamperInfo.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessTamperInfo.cs @@ -13,12 +13,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public ProcessTamperInfo(KProcess process, IEnumerable buildIds, IEnumerable codeAddresses, ulong heapAddress, ulong aliasAddress, ulong aslrAddress) { - Process = process; - BuildIds = buildIds; + Process = process; + BuildIds = buildIds; CodeAddresses = codeAddresses; - HeapAddress = heapAddress; - AliasAddress = aliasAddress; - AslrAddress = aslrAddress; + HeapAddress = heapAddress; + AliasAddress = aliasAddress; + AslrAddress = aslrAddress; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/CodeMemoryOperation.cs b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/CodeMemoryOperation.cs index 511ee99af..09e159a83 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/CodeMemoryOperation.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/CodeMemoryOperation.cs @@ -5,6 +5,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall Map, MapToOwner, Unmap, - UnmapFromOwner + UnmapFromOwner, }; -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/InfoType.cs b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/InfoType.cs index 3cf7ba748..2ca0d03a4 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/InfoType.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/InfoType.cs @@ -29,6 +29,6 @@ IsApplication, FreeThreadCount, ThreadTickCount, - MesosphereCurrentProcess = 65001 + MesosphereCurrentProcess = 65001, } } diff --git a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/MemoryInfo.cs b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/MemoryInfo.cs index a71cce1fe..c900781e9 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/MemoryInfo.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/MemoryInfo.cs @@ -11,9 +11,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall public KMemoryPermission Permission; public int IpcRefCount; public int DeviceRefCount; -#pragma warning disable CS0414 - private int _padding; -#pragma warning restore CS0414 +#pragma warning disable CS0414, IDE0052 // Remove unread private member + private readonly int _padding; +#pragma warning restore CS0414, IDE0052 public MemoryInfo( ulong address, @@ -34,4 +34,4 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall _padding = 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs index 3163c3487..82632f44c 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs @@ -91,7 +91,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall KHandleTable handleTable = KernelStatic.GetCurrentProcess().HandleTable; - KProcess process = new KProcess(_context); + KProcess process = new(_context); using var _ = new OnScopeExit(process.DecrementReferenceCount); @@ -117,7 +117,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall ProcessCreationFlags.PoolPartitionApplet => MemoryRegion.Applet, ProcessCreationFlags.PoolPartitionSystem => MemoryRegion.Service, ProcessCreationFlags.PoolPartitionSystemNonSecure => MemoryRegion.NvServices, - _ => MemoryRegion.NvServices + _ => MemoryRegion.NvServices, }; Result result = process.Initialize( @@ -138,6 +138,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return handleTable.GenerateHandle(process, out handle); } +#pragma warning disable CA1822 // Mark member as static public Result StartProcess(int handle, int priority, int cpuCore, ulong mainThreadStackSize) { KProcess process = KernelStatic.GetCurrentProcess().HandleTable.GetObject(handle); @@ -170,14 +171,17 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return Result.Success; } +#pragma warning restore CA1822 [Svc(0x5f)] +#pragma warning disable CA1822 // Mark member as static public Result FlushProcessDataCache(int processHandle, ulong address, ulong size) { // FIXME: This needs to be implemented as ARMv7 doesn't have any way to do cache maintenance operations on EL0. // As we don't support (and don't actually need) to flush the cache, this is stubbed. return Result.Success; } +#pragma warning restore CA1822 // IPC @@ -251,6 +255,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(0x22)] +#pragma warning disable CA1822 // Mark member as static public Result SendSyncRequestWithUserBuffer( [PointerSized] ulong messagePtr, [PointerSized] ulong messageSize, @@ -300,6 +305,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return result; } +#pragma warning restore CA1822 [Svc(0x23)] public Result SendAsyncRequestWithUserBuffer( @@ -351,7 +357,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } else { - KEvent doneEvent = new KEvent(_context); + KEvent doneEvent = new(_context); result = currentProcess.HandleTable.GenerateHandle(doneEvent.ReadableEvent, out doneEventHandle); @@ -408,7 +414,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall if (isLight) { - KLightSession session = new KLightSession(_context); + KLightSession session = new(_context); result = currentProcess.HandleTable.GenerateHandle(session.ServerSession, out serverSessionHandle); @@ -429,7 +435,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } else { - KSession session = new KSession(_context); + KSession session = new(_context); result = currentProcess.HandleTable.GenerateHandle(session.ServerSession, out serverSessionHandle); @@ -745,7 +751,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.MaximumExceeded; } - KPort port = new KPort(_context, maxSessions, isLight, name); + KPort port = new(_context, maxSessions, isLight, name); KProcess currentProcess = KernelStatic.GetCurrentProcess(); @@ -798,7 +804,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KAutoObject.RemoveName(_context, name); } - KPort port = new KPort(_context, maxSessions, false, null); + KPort port = new(_context, maxSessions, false, null); KProcess currentProcess = KernelStatic.GetCurrentProcess(); @@ -889,6 +895,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(2)] +#pragma warning disable CA1822 // Mark member as static public Result SetMemoryPermission([PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission) { if (!PageAligned(address)) @@ -920,8 +927,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return currentProcess.MemoryManager.SetMemoryPermission(address, size, permission); } +#pragma warning restore CA1822 [Svc(3)] +#pragma warning disable CA1822 // Mark member as static public Result SetMemoryAttribute( [PointerSized] ulong address, [PointerSized] ulong size, @@ -961,8 +970,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return result; } +#pragma warning restore CA1822 [Svc(4)] +#pragma warning disable CA1822 // Mark member as static public Result MapMemory([PointerSized] ulong dst, [PointerSized] ulong src, [PointerSized] ulong size) { if (!PageAligned(src | dst)) @@ -998,8 +1009,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return process.MemoryManager.Map(dst, src, size); } +#pragma warning restore CA1822 [Svc(5)] +#pragma warning disable CA1822 // Mark member as static public Result UnmapMemory([PointerSized] ulong dst, [PointerSized] ulong src, [PointerSized] ulong size) { if (!PageAligned(src | dst)) @@ -1035,6 +1048,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return process.MemoryManager.Unmap(dst, src, size); } +#pragma warning restore CA1822 [Svc(6)] public Result QueryMemory([PointerSized] ulong infoPtr, [PointerSized] out ulong pageInfo, [PointerSized] ulong address) @@ -1051,6 +1065,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return result; } +#pragma warning disable CA1822 // Mark member as static public Result QueryMemory(out MemoryInfo info, out ulong pageInfo, ulong address) { KProcess process = KernelStatic.GetCurrentProcess(); @@ -1070,8 +1085,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return Result.Success; } +#pragma warning restore CA1822 [Svc(0x13)] +#pragma warning disable CA1822 // Mark member as static public Result MapSharedMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission) { if (!PageAligned(address)) @@ -1117,8 +1134,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall currentProcess, permission); } +#pragma warning restore CA1822 [Svc(0x14)] +#pragma warning disable CA1822 // Mark member as static public Result UnmapSharedMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size) { if (!PageAligned(address)) @@ -1158,6 +1177,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall size, currentProcess); } +#pragma warning restore CA1822 [Svc(0x15)] public Result CreateTransferMemory(out int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission) @@ -1205,7 +1225,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.InvalidMemState; } - KTransferMemory transferMemory = new KTransferMemory(_context); + KTransferMemory transferMemory = new(_context); Result result = transferMemory.Initialize(address, size, permission); @@ -1224,6 +1244,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(0x51)] +#pragma warning disable CA1822 // Mark member as static public Result MapTransferMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission) { if (!PageAligned(address)) @@ -1269,8 +1290,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall currentProcess, permission); } +#pragma warning restore CA1822 [Svc(0x52)] +#pragma warning disable CA1822 // Mark member as static public Result UnmapTransferMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size) { if (!PageAligned(address)) @@ -1310,8 +1333,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall size, currentProcess); } +#pragma warning restore CA1822 [Svc(0x2c)] +#pragma warning disable CA1822 // Mark member as static public Result MapPhysicalMemory([PointerSized] ulong address, [PointerSized] ulong size) { if (!PageAligned(address)) @@ -1346,8 +1371,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return process.MemoryManager.MapPhysicalMemory(address, size); } +#pragma warning restore CA1822 [Svc(0x2d)] +#pragma warning disable CA1822 // Mark member as static public Result UnmapPhysicalMemory([PointerSized] ulong address, [PointerSized] ulong size) { if (!PageAligned(address)) @@ -1382,6 +1409,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return process.MemoryManager.UnmapPhysicalMemory(address, size); } +#pragma warning restore CA1822 [Svc(0x4b)] public Result CreateCodeMemory(out int handle, [PointerSized] ulong address, [PointerSized] ulong size) @@ -1403,7 +1431,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.InvalidMemState; } - KCodeMemory codeMemory = new KCodeMemory(_context); + KCodeMemory codeMemory = new(_context); using var _ = new OnScopeExit(codeMemory.DecrementReferenceCount); @@ -1425,6 +1453,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(0x4c)] +#pragma warning disable CA1822 // Mark member as static public Result ControlCodeMemory( int handle, CodeMemoryOperation op, @@ -1498,11 +1527,14 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return codeMemory.UnmapFromOwner(address, size); - default: return KernelResult.InvalidEnumValue; + default: + return KernelResult.InvalidEnumValue; } } +#pragma warning restore CA1822 [Svc(0x73)] +#pragma warning disable CA1822 // Mark member as static public Result SetProcessMemoryPermission( int handle, [PointerSized] ulong src, @@ -1543,8 +1575,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return targetProcess.MemoryManager.SetProcessMemoryPermission(src, size, permission); } +#pragma warning restore CA1822 [Svc(0x74)] +#pragma warning disable CA1822 // Mark member as static public Result MapProcessMemory( [PointerSized] ulong dst, int handle, @@ -1580,7 +1614,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.InvalidMemRange; } - KPageList pageList = new KPageList(); + KPageList pageList = new(); Result result = srcProcess.MemoryManager.GetPagesIfStateEquals( src, @@ -1600,8 +1634,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return dstProcess.MemoryManager.MapPages(dst, pageList, MemoryState.ProcessMemory, KMemoryPermission.ReadAndWrite); } +#pragma warning restore CA1822 [Svc(0x75)] +#pragma warning disable CA1822 // Mark member as static public Result UnmapProcessMemory( [PointerSized] ulong dst, int handle, @@ -1646,8 +1682,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return Result.Success; } +#pragma warning restore CA1822 [Svc(0x77)] +#pragma warning disable CA1822 // Mark member as static public Result MapProcessCodeMemory(int handle, ulong dst, ulong src, ulong size) { if (!PageAligned(dst) || !PageAligned(src)) @@ -1684,8 +1722,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return targetProcess.MemoryManager.MapProcessCodeMemory(dst, src, size); } +#pragma warning restore CA1822 [Svc(0x78)] +#pragma warning disable CA1822 // Mark member as static public Result UnmapProcessCodeMemory(int handle, ulong dst, ulong src, ulong size) { if (!PageAligned(dst) || !PageAligned(src)) @@ -1722,6 +1762,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return targetProcess.MemoryManager.UnmapProcessCodeMemory(dst, src, size); } +#pragma warning restore CA1822 private static bool PageAligned(ulong address) { @@ -1731,6 +1772,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall // System [Svc(0x7b)] +#pragma warning disable CA1822 // Mark member as static public Result TerminateProcess(int handle) { KProcess process = KernelStatic.GetCurrentProcess(); @@ -1759,12 +1801,15 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return result; } +#pragma warning restore CA1822 [Svc(7)] +#pragma warning disable CA1822 // Mark member as static public void ExitProcess() { KernelStatic.GetCurrentProcess().TerminateCurrentProcess(); } +#pragma warning restore CA1822 [Svc(0x11)] public Result SignalEvent(int handle) @@ -1857,6 +1902,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(0x26)] +#pragma warning disable CA1822 // Mark member as static public void Break(ulong reason) { KThread currentThread = KernelStatic.GetCurrentThread(); @@ -1882,8 +1928,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall Logger.Debug?.Print(LogClass.KernelSvc, "Debugger triggered."); } } +#pragma warning restore CA1822 [Svc(0x27)] +#pragma warning disable CA1822 // Mark member as static public void OutputDebugString([PointerSized] ulong strPtr, [PointerSized] ulong size) { KProcess process = KernelStatic.GetCurrentProcess(); @@ -1892,6 +1940,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall Logger.Warning?.Print(LogClass.KernelSvc, str); } +#pragma warning restore CA1822 [Svc(0x29)] public Result GetInfo(out ulong value, InfoType id, int handle, long subId) @@ -1937,33 +1986,56 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall switch (id) { - case InfoType.CoreMask: value = process.Capabilities.AllowedCpuCoresMask; break; - case InfoType.PriorityMask: value = process.Capabilities.AllowedThreadPriosMask; break; + case InfoType.CoreMask: + value = process.Capabilities.AllowedCpuCoresMask; + break; + case InfoType.PriorityMask: + value = process.Capabilities.AllowedThreadPriosMask; + break; - case InfoType.AliasRegionAddress: value = process.MemoryManager.AliasRegionStart; break; + case InfoType.AliasRegionAddress: + value = process.MemoryManager.AliasRegionStart; + break; case InfoType.AliasRegionSize: value = (process.MemoryManager.AliasRegionEnd - - process.MemoryManager.AliasRegionStart); break; + process.MemoryManager.AliasRegionStart); + break; - case InfoType.HeapRegionAddress: value = process.MemoryManager.HeapRegionStart; break; + case InfoType.HeapRegionAddress: + value = process.MemoryManager.HeapRegionStart; + break; case InfoType.HeapRegionSize: value = (process.MemoryManager.HeapRegionEnd - - process.MemoryManager.HeapRegionStart); break; + process.MemoryManager.HeapRegionStart); + break; - case InfoType.TotalMemorySize: value = process.GetMemoryCapacity(); break; + case InfoType.TotalMemorySize: + value = process.GetMemoryCapacity(); + break; - case InfoType.UsedMemorySize: value = process.GetMemoryUsage(); break; + case InfoType.UsedMemorySize: + value = process.GetMemoryUsage(); + break; - case InfoType.AslrRegionAddress: value = process.MemoryManager.GetAddrSpaceBaseAddr(); break; + case InfoType.AslrRegionAddress: + value = process.MemoryManager.GetAddrSpaceBaseAddr(); + break; - case InfoType.AslrRegionSize: value = process.MemoryManager.GetAddrSpaceSize(); break; + case InfoType.AslrRegionSize: + value = process.MemoryManager.GetAddrSpaceSize(); + break; - case InfoType.StackRegionAddress: value = process.MemoryManager.StackRegionStart; break; + case InfoType.StackRegionAddress: + value = process.MemoryManager.StackRegionStart; + break; case InfoType.StackRegionSize: value = (process.MemoryManager.StackRegionEnd - - process.MemoryManager.StackRegionStart); break; + process.MemoryManager.StackRegionStart); + break; - case InfoType.SystemResourceSizeTotal: value = process.PersonalMmHeapPagesCount * KPageTableBase.PageSize; break; + case InfoType.SystemResourceSizeTotal: + value = process.PersonalMmHeapPagesCount * KPageTableBase.PageSize; + break; case InfoType.SystemResourceSizeUsed: if (process.PersonalMmHeapPagesCount != 0) @@ -1973,15 +2045,25 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall break; - case InfoType.ProgramId: value = process.TitleId; break; + case InfoType.ProgramId: + value = process.TitleId; + break; - case InfoType.UserExceptionContextAddress: value = process.UserExceptionContextAddress; break; + case InfoType.UserExceptionContextAddress: + value = process.UserExceptionContextAddress; + break; - case InfoType.TotalNonSystemMemorySize: value = process.GetMemoryCapacityWithoutPersonalMmHeap(); break; + case InfoType.TotalNonSystemMemorySize: + value = process.GetMemoryCapacityWithoutPersonalMmHeap(); + break; - case InfoType.UsedNonSystemMemorySize: value = process.GetMemoryUsageWithoutPersonalMmHeap(); break; + case InfoType.UsedNonSystemMemorySize: + value = process.GetMemoryUsageWithoutPersonalMmHeap(); + break; - case InfoType.IsApplication: value = process.IsApplication ? 1UL : 0UL; break; + case InfoType.IsApplication: + value = process.IsApplication ? 1UL : 0UL; + break; case InfoType.FreeThreadCount: if (process.ResourceLimit != null) @@ -2160,7 +2242,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall break; } - default: return KernelResult.InvalidEnumValue; + default: + return KernelResult.InvalidEnumValue; } return Result.Success; @@ -2169,7 +2252,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall [Svc(0x45)] public Result CreateEvent(out int wEventHandle, out int rEventHandle) { - KEvent Event = new KEvent(_context); + KEvent Event = new(_context); KProcess process = KernelStatic.GetCurrentProcess(); @@ -2269,7 +2352,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall switch (id) { // Memory region capacity. - case 0: value = (long)region.Size; break; + case 0: + value = (long)region.Size; + break; // Memory region free space. case 1: @@ -2291,8 +2376,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall switch (subId) { - case 0: value = _context.PrivilegedProcessLowestId; break; - case 1: value = _context.PrivilegedProcessHighestId; break; + case 0: + value = _context.PrivilegedProcessLowestId; + break; + case 1: + value = _context.PrivilegedProcessHighestId; + break; } } @@ -2300,6 +2389,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(0x30)] +#pragma warning disable CA1822 // Mark member as static public Result GetResourceLimitLimitValue(out long limitValue, int handle, LimitableResource resource) { limitValue = 0; @@ -2320,8 +2410,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return Result.Success; } +#pragma warning restore CA1822 [Svc(0x31)] +#pragma warning disable CA1822 // Mark member as static public Result GetResourceLimitCurrentValue(out long limitValue, int handle, LimitableResource resource) { limitValue = 0; @@ -2342,8 +2434,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return Result.Success; } +#pragma warning restore CA1822 [Svc(0x37)] +#pragma warning disable CA1822 // Mark member as static public Result GetResourceLimitPeakValue(out long peak, int handle, LimitableResource resource) { peak = 0; @@ -2364,11 +2458,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return Result.Success; } +#pragma warning restore CA1822 [Svc(0x7d)] public Result CreateResourceLimit(out int handle) { - KResourceLimit limit = new KResourceLimit(_context); + KResourceLimit limit = new(_context); KProcess process = KernelStatic.GetCurrentProcess(); @@ -2376,6 +2471,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(0x7e)] +#pragma warning disable CA1822 // Mark member as static public Result SetResourceLimitLimitValue(int handle, LimitableResource resource, long limitValue) { if (resource >= LimitableResource.Count) @@ -2392,6 +2488,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return resourceLimit.SetLimitValue(resource, limitValue); } +#pragma warning restore CA1822 // Thread @@ -2443,7 +2540,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.ResLimitExceeded; } - KThread thread = new KThread(_context); + KThread thread = new(_context); Result result = currentProcess.InitializeThread( thread, @@ -2471,6 +2568,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(9)] +#pragma warning disable CA1822 // Mark member as static public Result StartThread(int handle) { KProcess process = KernelStatic.GetCurrentProcess(); @@ -2497,14 +2595,17 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.InvalidHandle; } } +#pragma warning restore CA1822 [Svc(0xa)] +#pragma warning disable CA1822 // Mark member as static public void ExitThread() { KThread currentThread = KernelStatic.GetCurrentThread(); currentThread.Exit(); } +#pragma warning restore CA1822 [Svc(0xb)] public void SleepThread(long timeout) @@ -2513,9 +2614,15 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall { switch (timeout) { - case 0: KScheduler.Yield(_context); break; - case -1: KScheduler.YieldWithLoadBalancing(_context); break; - case -2: KScheduler.YieldToAnyThread(_context); break; + case 0: + KScheduler.Yield(_context); + break; + case -1: + KScheduler.YieldWithLoadBalancing(_context); + break; + case -2: + KScheduler.YieldToAnyThread(_context); + break; } } else @@ -2525,6 +2632,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(0xc)] +#pragma warning disable CA1822 // Mark member as static public Result GetThreadPriority(out int priority, int handle) { KProcess process = KernelStatic.GetCurrentProcess(); @@ -2544,8 +2652,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.InvalidHandle; } } +#pragma warning restore CA1822 [Svc(0xd)] +#pragma warning disable CA1822 // Mark member as static public Result SetThreadPriority(int handle, int priority) { // TODO: NPDM check. @@ -2563,8 +2673,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return Result.Success; } +#pragma warning restore CA1822 [Svc(0xe)] +#pragma warning disable CA1822 // Mark member as static public Result GetThreadCoreMask(out int preferredCore, out ulong affinityMask, int handle) { KProcess process = KernelStatic.GetCurrentProcess(); @@ -2586,8 +2698,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.InvalidHandle; } } +#pragma warning restore CA1822 [Svc(0xf)] +#pragma warning disable CA1822 // Mark member as static public Result SetThreadCoreMask(int handle, int preferredCore, ulong affinityMask) { KProcess currentProcess = KernelStatic.GetCurrentProcess(); @@ -2635,14 +2749,18 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return thread.SetCoreAndAffinityMask(preferredCore, affinityMask); } +#pragma warning restore CA1822 [Svc(0x10)] +#pragma warning disable CA1822 // Mark member as static public int GetCurrentProcessorNumber() { return KernelStatic.GetCurrentThread().CurrentCore; } +#pragma warning restore CA1822 [Svc(0x25)] +#pragma warning disable CA1822 // Mark member as static public Result GetThreadId(out ulong threadUid, int handle) { KProcess process = KernelStatic.GetCurrentProcess(); @@ -2662,8 +2780,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.InvalidHandle; } } +#pragma warning restore CA1822 [Svc(0x32)] +#pragma warning disable CA1822 // Mark member as static public Result SetThreadActivity(int handle, bool pause) { KProcess process = KernelStatic.GetCurrentProcess(); @@ -2687,8 +2807,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return thread.SetActivity(pause); } +#pragma warning restore CA1822 [Svc(0x33)] +#pragma warning disable CA1822 // Mark member as static public Result GetThreadContext3([PointerSized] ulong address, int handle) { KProcess currentProcess = KernelStatic.GetCurrentProcess(); @@ -2722,6 +2844,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return result; } +#pragma warning restore CA1822 // Thread synchronization @@ -2758,7 +2881,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return KernelResult.UserCopyFailed; } - Span handles = new Span(currentThread.WaitSyncHandles).Slice(0, handlesCount); + Span handles = new Span(currentThread.WaitSyncHandles)[..handlesCount]; if (!KernelTransfer.UserToKernelArray(handlesPtr, handles)) { @@ -2782,7 +2905,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall KThread currentThread = KernelStatic.GetCurrentThread(); - var syncObjs = new Span(currentThread.WaitSyncObjects).Slice(0, handles.Length); + var syncObjs = new Span(currentThread.WaitSyncObjects)[..handles.Length]; if (handles.Length != 0) { @@ -2854,6 +2977,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } [Svc(0x1a)] +#pragma warning disable CA1822 // Mark member as static public Result ArbitrateLock(int ownerHandle, [PointerSized] ulong mutexAddress, int requesterHandle) { if (IsPointingInsideKernel(mutexAddress)) @@ -2870,8 +2994,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return currentProcess.AddressArbiter.ArbitrateLock(ownerHandle, mutexAddress, requesterHandle); } +#pragma warning restore CA1822 [Svc(0x1b)] +#pragma warning disable CA1822 // Mark member as static public Result ArbitrateUnlock([PointerSized] ulong mutexAddress) { if (IsPointingInsideKernel(mutexAddress)) @@ -2888,8 +3014,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return currentProcess.AddressArbiter.ArbitrateUnlock(mutexAddress); } +#pragma warning restore CA1822 [Svc(0x1c)] +#pragma warning disable CA1822 // Mark member as static public Result WaitProcessWideKeyAtomic( [PointerSized] ulong mutexAddress, [PointerSized] ulong condVarAddress, @@ -2919,8 +3047,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall handle, timeout); } +#pragma warning restore CA1822 [Svc(0x1d)] +#pragma warning disable CA1822 // Mark member as static public Result SignalProcessWideKey([PointerSized] ulong address, int count) { KProcess currentProcess = KernelStatic.GetCurrentProcess(); @@ -2929,8 +3059,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return Result.Success; } +#pragma warning restore CA1822 [Svc(0x34)] +#pragma warning disable CA1822 // Mark member as static public Result WaitForAddress([PointerSized] ulong address, ArbitrationType type, int value, long timeout) { if (IsPointingInsideKernel(address)) @@ -2961,8 +3093,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall _ => KernelResult.InvalidEnumValue, }; } +#pragma warning restore CA1822 [Svc(0x35)] +#pragma warning disable CA1822 // Mark member as static public Result SignalToAddress([PointerSized] ulong address, SignalType type, int value, int count) { if (IsPointingInsideKernel(address)) @@ -2985,17 +3119,20 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall => currentProcess.AddressArbiter.SignalAndIncrementIfEqual(address, value, count), SignalType.SignalAndModifyIfEqual => currentProcess.AddressArbiter.SignalAndModifyIfEqual(address, value, count), - _ => KernelResult.InvalidEnumValue + _ => KernelResult.InvalidEnumValue, }; } +#pragma warning restore CA1822 [Svc(0x36)] +#pragma warning disable CA1822 // Mark member as static public Result SynchronizePreemptionState() { KernelStatic.GetCurrentThread().SynchronizePreemptionState(); return Result.Success; } +#pragma warning restore CA1822 private static bool IsPointingInsideKernel(ulong address) { @@ -3007,4 +3144,4 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall return (address & 3) != 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallHandler.cs b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallHandler.cs index 710bac946..72f906422 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallHandler.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallHandler.cs @@ -41,4 +41,4 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall currentThread.HandlePostSyscall(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/ThreadContext.cs b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/ThreadContext.cs index b524406af..fd1b41e32 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/ThreadContext.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/ThreadContext.cs @@ -11,9 +11,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall public ulong Sp; public ulong Pc; public uint Pstate; -#pragma warning disable CS0169 - private uint _padding; -#pragma warning restore CS0169 +#pragma warning disable CS0169, IDE0051 // Remove unused private member + private readonly uint _padding; +#pragma warning restore CS0169, IDE0051 public Array32 FpuRegisters; public uint Fpcr; public uint Fpsr; diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/ArbitrationType.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/ArbitrationType.cs index 89c1bf1fa..ddcf02029 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/ArbitrationType.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/ArbitrationType.cs @@ -2,8 +2,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading { enum ArbitrationType { - WaitIfLessThan = 0, + WaitIfLessThan = 0, DecrementAndWaitIfLessThan = 1, - WaitIfEqual = 2 + WaitIfEqual = 2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KAddressArbiter.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KAddressArbiter.cs index 57fbabd51..f6b9a112c 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KAddressArbiter.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KAddressArbiter.cs @@ -38,7 +38,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return KernelResult.ThreadTerminating; } - currentThread.SignaledObj = null; + currentThread.SignaledObj = null; currentThread.ObjSyncResult = Result.Success; KProcess currentProcess = KernelStatic.GetCurrentProcess(); @@ -66,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return KernelResult.InvalidHandle; } - currentThread.MutexAddress = mutexAddress; + currentThread.MutexAddress = mutexAddress; currentThread.ThreadHandleForUserMutex = requesterHandle; mutexOwner.AddMutexWaiter(currentThread); @@ -76,10 +76,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading _context.CriticalSection.Leave(); _context.CriticalSection.Enter(); - if (currentThread.MutexOwner != null) - { - currentThread.MutexOwner.RemoveMutexWaiter(currentThread); - } + currentThread.MutexOwner?.RemoveMutexWaiter(currentThread); _context.CriticalSection.Leave(); @@ -103,7 +100,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading if (result != Result.Success && newOwnerThread != null) { - newOwnerThread.SignaledObj = null; + newOwnerThread.SignaledObj = null; newOwnerThread.ObjSyncResult = result; } @@ -118,7 +115,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading KThread currentThread = KernelStatic.GetCurrentThread(); - currentThread.SignaledObj = null; + currentThread.SignaledObj = null; currentThread.ObjSyncResult = KernelResult.TimedOut; if (currentThread.TerminationRequested) @@ -139,9 +136,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return KernelResult.InvalidMemState; } - currentThread.MutexAddress = mutexAddress; + currentThread.MutexAddress = mutexAddress; currentThread.ThreadHandleForUserMutex = threadHandle; - currentThread.CondVarAddress = condVarAddress; + currentThread.CondVarAddress = condVarAddress; _condVarThreads.Add(currentThread); @@ -164,10 +161,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading _context.CriticalSection.Enter(); - if (currentThread.MutexOwner != null) - { - currentThread.MutexOwner.RemoveMutexWaiter(currentThread); - } + currentThread.MutexOwner?.RemoveMutexWaiter(currentThread); _condVarThreads.Remove(currentThread); @@ -176,7 +170,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return currentThread.ObjSyncResult; } - private (int, KThread) MutexUnlock(KThread currentThread, ulong mutexAddress) + private static (int, KThread) MutexUnlock(KThread currentThread, ulong mutexAddress) { KThread newOwnerThread = currentThread.RelinquishMutex(mutexAddress, out int count); @@ -191,7 +185,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading mutexValue |= HasListenersMask; } - newOwnerThread.SignaledObj = null; + newOwnerThread.SignaledObj = null; newOwnerThread.ObjSyncResult = Result.Success; newOwnerThread.ReleaseAndResume(); @@ -223,7 +217,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading if (!currentProcess.CpuMemory.IsMapped(address)) { // Invalid address. - requester.SignaledObj = null; + requester.SignaledObj = null; requester.ObjSyncResult = KernelResult.InvalidMemState; return; @@ -253,7 +247,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading if (mutexValue == 0) { // We now own the mutex. - requester.SignaledObj = null; + requester.SignaledObj = null; requester.ObjSyncResult = Result.Success; requester.ReleaseAndResume(); @@ -273,7 +267,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading else { // Invalid mutex owner. - requester.SignaledObj = null; + requester.SignaledObj = null; requester.ObjSyncResult = KernelResult.InvalidHandle; requester.ReleaseAndResume(); @@ -293,7 +287,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return KernelResult.ThreadTerminating; } - currentThread.SignaledObj = null; + currentThread.SignaledObj = null; currentThread.ObjSyncResult = KernelResult.TimedOut; if (!KernelTransfer.UserToKernel(out int currentValue, address)) @@ -312,7 +306,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return KernelResult.TimedOut; } - currentThread.MutexAddress = address; + currentThread.MutexAddress = address; currentThread.WaitingInArbitration = true; _arbiterThreads.Add(currentThread); @@ -363,7 +357,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return KernelResult.ThreadTerminating; } - currentThread.SignaledObj = null; + currentThread.SignaledObj = null; currentThread.ObjSyncResult = KernelResult.TimedOut; KProcess currentProcess = KernelStatic.GetCurrentProcess(); @@ -389,7 +383,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return KernelResult.TimedOut; } - currentThread.MutexAddress = address; + currentThread.MutexAddress = address; currentThread.WaitingInArbitration = true; _arbiterThreads.Add(currentThread); @@ -551,7 +545,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading { static void RemoveArbiterThread(KThread thread) { - thread.SignaledObj = null; + thread.SignaledObj = null; thread.ObjSyncResult = Result.Success; thread.ReleaseAndResume(); diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KConditionVariable.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KConditionVariable.cs index 891e632f9..c6aa984c2 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KConditionVariable.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KConditionVariable.cs @@ -67,4 +67,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading context.CriticalSection.Leave(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KCriticalSection.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KCriticalSection.cs index 1d61f2f06..3d6744882 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KCriticalSection.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KCriticalSection.cs @@ -61,4 +61,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KEvent.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KEvent.cs index da3e217bf..65169d035 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KEvent.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KEvent.cs @@ -7,8 +7,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading public KEvent(KernelContext context) { - ReadableEvent = new KReadableEvent(context, this); + ReadableEvent = new KReadableEvent(context); WritableEvent = new KWritableEvent(context, this); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KPriorityQueue.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KPriorityQueue.cs index 14fba7045..1608db095 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KPriorityQueue.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KPriorityQueue.cs @@ -68,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading _prioMask &= ~(1L << _prio); } - public KThread Current => _node?.Value; + public readonly KThread Current => _node?.Value; public bool MoveNext() { @@ -283,4 +283,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return _scheduledThreadsPerPrioPerCore[prio][core]; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KReadableEvent.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KReadableEvent.cs index d9e7befa6..6ed61f5a3 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KReadableEvent.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KReadableEvent.cs @@ -5,13 +5,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading { class KReadableEvent : KSynchronizationObject { - private readonly KEvent _parent; - private bool _signaled; - public KReadableEvent(KernelContext context, KEvent parent) : base(context) + public KReadableEvent(KernelContext context) : base(context) { - _parent = parent; } public override void Signal() @@ -62,4 +59,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return _signaled; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KScheduler.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KScheduler.cs index b9de7d9c7..905c61d66 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KScheduler.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KScheduler.cs @@ -9,11 +9,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading partial class KScheduler : IDisposable { public const int PrioritiesCount = 64; - public const int CpuCoresCount = 4; + public const int CpuCoresCount = 4; private const int RoundRobinTimeQuantumMs = 10; - private static readonly int[] PreemptionPriorities = new int[] { 59, 59, 59, 63 }; + private static readonly int[] _preemptionPriorities = { 59, 59, 59, 63 }; private static readonly int[] _srcCoresHighestPrioThreads = new int[CpuCoresCount]; @@ -59,7 +59,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading private KThread CreateIdleThread(KernelContext context, int cpuCore) { - KThread idleThread = new KThread(context); + KThread idleThread = new(context); idleThread.Initialize(0UL, 0UL, 0UL, PrioritiesCount, cpuCore, null, ThreadType.Dummy, IdleThreadLoop); @@ -95,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading { KThread candidate = thread.Owner.PinnedThreads[core]; - if (candidate.KernelWaitersCount == 0 && !thread.Owner.IsExceptionUserThread(candidate)) + if (candidate.KernelWaitersCount == 0 && !KProcess.IsExceptionUserThread(candidate)) { if (candidate.SchedFlags == ThreadSchedState.Running) { @@ -378,10 +378,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading currentThread.AddCpuTime(ticksDelta); - if (currentProcess != null) - { - currentProcess.AddCpuTime(ticksDelta); - } + currentProcess?.AddCpuTime(ticksDelta); LastContextSwitchTime = currentTicks; @@ -411,7 +408,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading for (int core = 0; core < CpuCoresCount; core++) { - RotateScheduledQueue(context, core, PreemptionPriorities[core]); + RotateScheduledQueue(context, core, _preemptionPriorities[core]); } context.CriticalSection.Leave(); @@ -431,7 +428,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading nextThread = context.PriorityQueue.Reschedule(prio, core, selectedThread); } - static KThread FirstSuitableCandidateOrDefault(KernelContext context, int core, KThread selectedThread, KThread nextThread, Predicate< KThread> predicate) + static KThread FirstSuitableCandidateOrDefault(KernelContext context, int core, KThread selectedThread, KThread nextThread, Predicate predicate) { foreach (KThread suggested in context.PriorityQueue.SuggestedThreads(core)) { @@ -651,11 +648,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading // Ensure that the idle thread is not blocked and can exit. lock (_idleInterruptEventLock) { - if (_idleInterruptEvent != null) - { - _idleInterruptEvent.Set(); - } + _idleInterruptEvent?.Set(); } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KSynchronization.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KSynchronization.cs index 9c196810c..b1af06b0d 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KSynchronization.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KSynchronization.cs @@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading { class KSynchronization { - private KernelContext _context; + private readonly KernelContext _context; public KSynchronization(KernelContext context) { @@ -68,8 +68,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading syncNodes[index] = syncObjs[index].AddWaitingThread(currentThread); } - currentThread.WaitingSync = true; - currentThread.SignaledObj = null; + currentThread.WaitingSync = true; + currentThread.SignaledObj = null; currentThread.ObjSyncResult = result; currentThread.Reschedule(ThreadSchedState.Paused); @@ -126,7 +126,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading if ((thread.SchedFlags & ThreadSchedState.LowMask) == ThreadSchedState.Paused) { - thread.SignaledObj = syncObj; + thread.SignaledObj = syncObj; thread.ObjSyncResult = Result.Success; thread.Reschedule(ThreadSchedState.Running); @@ -139,4 +139,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading _context.CriticalSection.Leave(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs index 78bd577e1..12383fb8a 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs @@ -68,10 +68,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading public LinkedListNode ProcessListNode { get; set; } - private LinkedList _mutexWaiters; + private readonly LinkedList _mutexWaiters; private LinkedListNode _mutexWaiterNode; - private LinkedList _pinnedWaiters; + private readonly LinkedList _pinnedWaiters; public KThread MutexOwner { get; private set; } @@ -659,7 +659,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading const int MaxRegistersAArch32 = 15; const int MaxFpuRegistersAArch32 = 16; - ThreadContext context = new ThreadContext(); + ThreadContext context = new(); if (Owner.Flags.HasFlag(ProcessCreationFlags.Is64Bit)) { @@ -1433,4 +1433,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading Owner.CpuMemory.Write(_tlsAddress + TlsUserInterruptFlagOffset, 0); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KWritableEvent.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KWritableEvent.cs index b46122be7..fd65361ac 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KWritableEvent.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KWritableEvent.cs @@ -22,4 +22,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading return _parent.ReadableEvent.Clear(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/SignalType.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/SignalType.cs index e72b719b4..9f257d983 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/SignalType.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/SignalType.cs @@ -2,8 +2,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading { enum SignalType { - Signal = 0, + Signal = 0, SignalAndIncrementIfEqual = 1, - SignalAndModifyIfEqual = 2 + SignalAndModifyIfEqual = 2, } } diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/ThreadSchedState.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/ThreadSchedState.cs index 1d09e021e..eca412d03 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/ThreadSchedState.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/ThreadSchedState.cs @@ -5,19 +5,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading [Flags] enum ThreadSchedState : ushort { - LowMask = 0xf, - HighMask = 0xfff0, + LowMask = 0xf, + HighMask = 0xfff0, ForcePauseMask = 0x1f0, - ProcessPauseFlag = 1 << 4, - ThreadPauseFlag = 1 << 5, + ProcessPauseFlag = 1 << 4, + ThreadPauseFlag = 1 << 5, ProcessDebugPauseFlag = 1 << 6, - BacktracePauseFlag = 1 << 7, - KernelInitPauseFlag = 1 << 8, + BacktracePauseFlag = 1 << 7, + KernelInitPauseFlag = 1 << 8, - None = 0, - Paused = 1, - Running = 2, - TerminationPending = 3 + None = 0, + Paused = 1, + Running = 2, + TerminationPending = 3, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/ThreadType.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/ThreadType.cs index 0b44b57ff..83093570b 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/ThreadType.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/ThreadType.cs @@ -5,6 +5,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading Dummy, Kernel, Kernel2, - User + User, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/LibHacHorizonManager.cs b/src/Ryujinx.HLE/HOS/LibHacHorizonManager.cs index 8fde5dd6a..01d4b2450 100644 --- a/src/Ryujinx.HLE/HOS/LibHacHorizonManager.cs +++ b/src/Ryujinx.HLE/HOS/LibHacHorizonManager.cs @@ -1,15 +1,12 @@ using LibHac; using LibHac.Bcat; using LibHac.Common; -using LibHac.Fs.Fsa; -using LibHac.Fs.Shim; using LibHac.FsSrv.Impl; using LibHac.Loader; using LibHac.Ncm; using Ryujinx.HLE.FileSystem; using Ryujinx.HLE.HOS.Services.Arp; using System; -using StorageId = LibHac.Ncm.StorageId; namespace Ryujinx.HLE.HOS { @@ -17,15 +14,15 @@ namespace Ryujinx.HLE.HOS { private LibHac.Horizon Server { get; set; } - public HorizonClient RyujinxClient { get; private set; } + public HorizonClient RyujinxClient { get; private set; } public HorizonClient ApplicationClient { get; private set; } - public HorizonClient AccountClient { get; private set; } - public HorizonClient AmClient { get; private set; } - public HorizonClient BcatClient { get; private set; } - public HorizonClient FsClient { get; private set; } - public HorizonClient NsClient { get; private set; } - public HorizonClient PmClient { get; private set; } - public HorizonClient SdbClient { get; private set; } + public HorizonClient AccountClient { get; private set; } + public HorizonClient AmClient { get; private set; } + public HorizonClient BcatClient { get; private set; } + public HorizonClient FsClient { get; private set; } + public HorizonClient NsClient { get; private set; } + public HorizonClient PmClient { get; private set; } + public HorizonClient SdbClient { get; private set; } private SharedRef _arpIReader; internal LibHacIReader ArpIReader => _arpIReader.Get; @@ -64,11 +61,13 @@ namespace Ryujinx.HLE.HOS public void InitializeSystemClients() { +#pragma warning disable IDE0055 // Disable formatting PmClient = Server.CreatePrivilegedHorizonClient(); AccountClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Account, StorageId.BuiltInSystem), AccountFsPermissions); AmClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Am, StorageId.BuiltInSystem), AmFsPermissions); NsClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Ns, StorageId.BuiltInSystem), NsFsPermissions); SdbClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Sdb, StorageId.BuiltInSystem), SdbFacData, SdbFacDescriptor); +#pragma warning restore IDE0055 } public void InitializeApplicationClient(ProgramId programId, in Npdm npdm) @@ -106,7 +105,7 @@ namespace Ryujinx.HLE.HOS 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x09, 0x10, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01 + 0x00, 0x00, 0x00, 0x01, }; private static ReadOnlySpan SdbFacDescriptor => new byte[] @@ -114,7 +113,7 @@ namespace Ryujinx.HLE.HOS 0x01, 0x00, 0x02, 0x00, 0x08, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x09, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 + 0x01, 0x09, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/ModLoader.cs b/src/Ryujinx.HLE/HOS/ModLoader.cs index 243510967..6706006c3 100644 --- a/src/Ryujinx.HLE/HOS/ModLoader.cs +++ b/src/Ryujinx.HLE/HOS/ModLoader.cs @@ -110,16 +110,16 @@ namespace Ryujinx.HLE.HOS private readonly Dictionary _appMods; // key is TitleId private PatchCache _patches; - private static readonly EnumerationOptions DirEnumOptions; + private static readonly EnumerationOptions _dirEnumOptions; static ModLoader() { - DirEnumOptions = new EnumerationOptions + _dirEnumOptions = new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive, MatchType = MatchType.Simple, RecurseSubdirectories = false, - ReturnSpecialDirectories = false + ReturnSpecialDirectories = false, }; } @@ -137,7 +137,7 @@ namespace Ryujinx.HLE.HOS private static bool StrEquals(string s1, string s2) => string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase); - public static string GetModsBasePath() => EnsureBaseDirStructure(AppDataManager.GetModsPath()); + public static string GetModsBasePath() => EnsureBaseDirStructure(AppDataManager.GetModsPath()); public static string GetSdModsBasePath() => EnsureBaseDirStructure(AppDataManager.GetSdModsPath()); private static string EnsureBaseDirStructure(string modsBasePath) @@ -154,7 +154,7 @@ namespace Ryujinx.HLE.HOS } private static DirectoryInfo FindTitleDir(DirectoryInfo contentsDir, string titleId) - => contentsDir.EnumerateDirectories(titleId, DirEnumOptions).FirstOrDefault(); + => contentsDir.EnumerateDirectories(titleId, _dirEnumOptions).FirstOrDefault(); private static void AddModsFromDirectory(ModCache mods, DirectoryInfo dir, string titleId) { @@ -218,15 +218,18 @@ namespace Ryujinx.HLE.HOS if (StrEquals(AmsNsoPatchDir, patchDir.Name)) { - patches = cache.NsoPatches; type = "NSO"; + patches = cache.NsoPatches; + type = "NSO"; } else if (StrEquals(AmsNroPatchDir, patchDir.Name)) { - patches = cache.NroPatches; type = "NRO"; + patches = cache.NroPatches; + type = "NRO"; } else if (StrEquals(AmsKipPatchDir, patchDir.Name)) { - patches = cache.KipPatches; type = "KIP"; + patches = cache.KipPatches; + type = "KIP"; } else { @@ -352,7 +355,7 @@ namespace Ryujinx.HLE.HOS } // Start a new cheat section. - cheatName = line.Substring(1, line.Length - 2); + cheatName = line[1..^1]; instructions = new List(); } else if (line.Length > 0) @@ -528,7 +531,7 @@ namespace Ryujinx.HLE.HOS Logger.Warning?.Print(LogClass.ModLoader, "Multiple ExeFS partition replacements detected"); } - Logger.Info?.Print(LogClass.ModLoader, $"Using replacement ExeFS partition"); + Logger.Info?.Print(LogClass.ModLoader, "Using replacement ExeFS partition"); exefs = new PartitionFileSystem(mods.ExefsContainers[0].Path.OpenRead().AsStorage()); @@ -549,7 +552,7 @@ namespace Ryujinx.HLE.HOS ModLoadResult modLoadResult = new() { Stubs = new BitVector32(), - Replaces = new BitVector32() + Replaces = new BitVector32(), }; if (!_appMods.TryGetValue(titleId, out ModCache mods) || mods.ExefsDirs.Count == 0) @@ -559,7 +562,7 @@ namespace Ryujinx.HLE.HOS if (nsos.Length != ProcessConst.ExeFsPrefixes.Length) { - throw new ArgumentOutOfRangeException("NSO Count is incorrect"); + throw new ArgumentOutOfRangeException(nameof(nsos), nsos.Length, "NSO Count is incorrect"); } var exeMods = mods.ExefsDirs; @@ -622,7 +625,10 @@ namespace Ryujinx.HLE.HOS { var nroPatches = _patches.NroPatches; - if (nroPatches.Count == 0) return; + if (nroPatches.Count == 0) + { + return; + } // NRO patches aren't offset relative to header unlike NSO // according to Atmosphere's ro patcher module @@ -682,7 +688,7 @@ namespace Ryujinx.HLE.HOS EnableCheats(titleId, tamperMachine); } - internal void EnableCheats(ulong titleId, TamperMachine tamperMachine) + internal static void EnableCheats(ulong titleId, TamperMachine tamperMachine) { var contentDirectory = FindTitleDir(new DirectoryInfo(Path.Combine(GetModsBasePath(), AmsContentsDir)), $"{titleId:x16}"); string enabledCheatsPath = Path.Combine(contentDirectory.FullName, CheatDir, "enabled.txt"); @@ -708,7 +714,7 @@ namespace Ryujinx.HLE.HOS { NsoExecutable nso => Convert.ToHexString(nso.BuildId.ItemsRo.ToArray()).TrimEnd('0'), NroExecutable nro => Convert.ToHexString(nro.Header.BuildId).TrimEnd('0'), - _ => string.Empty + _ => string.Empty, }).ToList(); int GetIndex(string buildId) => buildIds.FindIndex(id => id == buildId); // O(n) but list is small @@ -767,4 +773,4 @@ namespace Ryujinx.HLE.HOS return count > 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/ResultCode.cs b/src/Ryujinx.HLE/HOS/ResultCode.cs index 4004357b5..3fec365cd 100644 --- a/src/Ryujinx.HLE/HOS/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/ResultCode.cs @@ -2,11 +2,11 @@ { public enum ResultCode { - OsModuleId = 3, + OsModuleId = 3, ErrorCodeShift = 9, Success = 0, - NotAllocated = (1023 << ErrorCodeShift) | OsModuleId + NotAllocated = (1023 << ErrorCodeShift) | OsModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/ServiceCtx.cs b/src/Ryujinx.HLE/HOS/ServiceCtx.cs index 659b212ac..ba27e12ea 100644 --- a/src/Ryujinx.HLE/HOS/ServiceCtx.cs +++ b/src/Ryujinx.HLE/HOS/ServiceCtx.cs @@ -8,33 +8,33 @@ namespace Ryujinx.HLE.HOS { class ServiceCtx { - public Switch Device { get; } - public KProcess Process { get; } - public IVirtualMemoryManager Memory { get; } - public KThread Thread { get; } - public IpcMessage Request { get; } - public IpcMessage Response { get; } - public BinaryReader RequestData { get; } - public BinaryWriter ResponseData { get; } + public Switch Device { get; } + public KProcess Process { get; } + public IVirtualMemoryManager Memory { get; } + public KThread Thread { get; } + public IpcMessage Request { get; } + public IpcMessage Response { get; } + public BinaryReader RequestData { get; } + public BinaryWriter ResponseData { get; } public ServiceCtx( - Switch device, - KProcess process, + Switch device, + KProcess process, IVirtualMemoryManager memory, - KThread thread, - IpcMessage request, - IpcMessage response, - BinaryReader requestData, - BinaryWriter responseData) + KThread thread, + IpcMessage request, + IpcMessage response, + BinaryReader requestData, + BinaryWriter responseData) { - Device = device; - Process = process; - Memory = memory; - Thread = thread; - Request = request; - Response = response; - RequestData = requestData; + Device = device; + Process = process; + Memory = memory; + Thread = thread; + Request = request; + Response = response; + RequestData = requestData; ResponseData = responseData; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountManager.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountManager.cs index f5364329d..a6dde3c53 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountManager.cs @@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc { public class AccountManager { - public static readonly UserId DefaultUserId = new UserId("00000000000000010000000000000000"); + public static readonly UserId DefaultUserId = new("00000000000000010000000000000000"); private readonly AccountSaveDataManager _accountSaveDataManager; @@ -51,7 +51,9 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc { commandLineUserProfileOverride = _profiles.Values.FirstOrDefault(x => x.Name == initialProfileName)?.UserId ?? default; if (commandLineUserProfileOverride.IsNull) + { Logger.Warning?.Print(LogClass.Application, $"The command line specified profile named '{initialProfileName}' was not found"); + } } OpenUser(commandLineUserProfileOverride.IsNull ? _accountSaveDataManager.LastOpened : commandLineUserProfileOverride); } @@ -64,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc userId = new UserId(Guid.NewGuid().ToString().Replace("-", "")); } - UserProfile profile = new UserProfile(userId, name, image); + UserProfile profile = new(userId, name, image); _profiles.AddOrUpdate(userId.ToString(), profile, (key, old) => profile); @@ -238,4 +240,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc return _profiles.First().Value; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountSaveDataManager.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountSaveDataManager.cs index 535779d2e..c2ae0119c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountSaveDataManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountSaveDataManager.cs @@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc { private readonly string _profilesJsonPath = Path.Join(AppDataManager.BaseDirPath, "system", "Profiles.json"); - private static readonly ProfilesJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); + private static readonly ProfilesJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions()); public UserId LastOpened { get; set; } @@ -23,22 +23,22 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc if (File.Exists(_profilesJsonPath)) { - try + try { - ProfilesJson profilesJson = JsonHelper.DeserializeFromFile(_profilesJsonPath, SerializerContext.ProfilesJson); + ProfilesJson profilesJson = JsonHelper.DeserializeFromFile(_profilesJsonPath, _serializerContext.ProfilesJson); foreach (var profile in profilesJson.Profiles) { - UserProfile addedProfile = new UserProfile(new UserId(profile.UserId), profile.Name, profile.Image, profile.LastModifiedTimestamp); + UserProfile addedProfile = new(new UserId(profile.UserId), profile.Name, profile.Image, profile.LastModifiedTimestamp); profiles.AddOrUpdate(profile.UserId, addedProfile, (key, old) => addedProfile); } LastOpened = new UserId(profilesJson.LastOpened); } - catch (Exception e) + catch (Exception ex) { - Logger.Error?.Print(LogClass.Application, $"Failed to parse {_profilesJsonPath}: {e.Message} Loading default profile!"); + Logger.Error?.Print(LogClass.Application, $"Failed to parse {_profilesJsonPath}: {ex.Message} Loading default profile!"); LastOpened = AccountManager.DefaultUserId; } @@ -51,26 +51,26 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc public void Save(ConcurrentDictionary profiles) { - ProfilesJson profilesJson = new ProfilesJson() + ProfilesJson profilesJson = new() { - Profiles = new List(), - LastOpened = LastOpened.ToString() + Profiles = new List(), + LastOpened = LastOpened.ToString(), }; foreach (var profile in profiles) { profilesJson.Profiles.Add(new UserProfileJson() { - UserId = profile.Value.UserId.ToString(), - Name = profile.Value.Name, - AccountState = profile.Value.AccountState, - OnlinePlayState = profile.Value.OnlinePlayState, + UserId = profile.Value.UserId.ToString(), + Name = profile.Value.Name, + AccountState = profile.Value.AccountState, + OnlinePlayState = profile.Value.OnlinePlayState, LastModifiedTimestamp = profile.Value.LastModifiedTimestamp, - Image = profile.Value.Image, + Image = profile.Value.Image, }); } - JsonHelper.SerializeToFile(_profilesJsonPath, profilesJson, SerializerContext.ProfilesJson); + JsonHelper.SerializeToFile(_profilesJsonPath, profilesJson, _serializerContext.ProfilesJson); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs index 9c058cb59..3cb46d204 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs @@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService { class IManagerForApplication : IpcService { - private ManagerServer _managerServer; + private readonly ManagerServer _managerServer; public IManagerForApplication(UserId userId) { @@ -72,4 +72,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService return resultCode; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs index ecd516876..8510837b2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs @@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService { class IManagerForSystemService : IpcService { - private ManagerServer _managerServer; + private readonly ManagerServer _managerServer; public IManagerForSystemService(UserId userId) { @@ -44,4 +44,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService return _managerServer.LoadIdTokenCache(context); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs index 14911dfb1..a0021917f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs @@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService { class IProfile : IpcService { - private ProfileServer _profileServer; + private readonly ProfileServer _profileServer; public IProfile(UserProfile profile) { @@ -37,4 +37,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService return _profileServer.LoadImage(context); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs index 64b6070f2..5d5d0dd69 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs @@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService { class IProfileEditor : IpcService { - private ProfileServer _profileServer; + private readonly ProfileServer _profileServer; public IProfileEditor(UserProfile profile) { @@ -51,4 +51,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService return _profileServer.StoreWithImage(context); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs index 972403118..c43186de1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs @@ -16,7 +16,9 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService // TODO: Determine where and how NetworkServiceAccountId is set. private const long NetworkServiceAccountId = 0xcafe; - private UserId _userId; +#pragma warning disable IDE0052 // Remove unread private member + private readonly UserId _userId; +#pragma warning restore IDE0052 public ManagerServer(UserId userId) { @@ -29,15 +31,15 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService RSAParameters parameters = provider.ExportParameters(true); - RsaSecurityKey secKey = new RsaSecurityKey(parameters); + RsaSecurityKey secKey = new(parameters); - SigningCredentials credentials = new SigningCredentials(secKey, "RS256"); + SigningCredentials credentials = new(secKey, "RS256"); credentials.Key.KeyId = parameters.ToString(); var header = new JwtHeader(credentials) { - { "jku", "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com/1.0.0/certificates" } + { "jku", "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com/1.0.0/certificates" }, }; byte[] rawUserId = new byte[0x10]; @@ -60,10 +62,10 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService { "typ", "id_token" }, { "iat", DateTimeOffset.UtcNow.ToUnixTimeSeconds() }, { "jti", Guid.NewGuid().ToString() }, - { "exp", (DateTimeOffset.UtcNow + TimeSpan.FromHours(3)).ToUnixTimeSeconds() } + { "exp", (DateTimeOffset.UtcNow + TimeSpan.FromHours(3)).ToUnixTimeSeconds() }, }; - JwtSecurityToken securityToken = new JwtSecurityToken(header, payload); + JwtSecurityToken securityToken = new(header, payload); return new JwtSecurityTokenHandler().WriteToken(securityToken); } @@ -94,8 +96,8 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService public ResultCode EnsureIdTokenCacheAsync(ServiceCtx context, out IAsyncContext asyncContext) { - KEvent asyncEvent = new KEvent(context.Device.System.KernelContext); - AsyncExecution asyncExecution = new AsyncExecution(asyncEvent); + KEvent asyncEvent = new(context.Device.System.KernelContext); + AsyncExecution asyncExecution = new(asyncEvent); asyncExecution.Initialize(1000, EnsureIdTokenCacheAsyncImpl); @@ -123,7 +125,9 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService public ResultCode LoadIdTokenCache(ServiceCtx context) { ulong bufferPosition = context.Request.ReceiveBuff[0].Position; - ulong bufferSize = context.Request.ReceiveBuff[0].Size; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong bufferSize = context.Request.ReceiveBuff[0].Size; +#pragma warning restore IDE0059 // NOTE: This opens the file at "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x") // in the "account:/" savedata and writes some data in the buffer. @@ -169,8 +173,8 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService public ResultCode LoadNetworkServiceLicenseKindAsync(ServiceCtx context, out IAsyncNetworkServiceLicenseKindContext asyncContext) { - KEvent asyncEvent = new KEvent(context.Device.System.KernelContext); - AsyncExecution asyncExecution = new AsyncExecution(asyncEvent); + KEvent asyncEvent = new(context.Device.System.KernelContext); + AsyncExecution asyncExecution = new(asyncEvent); Logger.Stub?.PrintStub(LogClass.ServiceAcc); @@ -184,4 +188,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs index 8e29f94bc..08400baf2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService { class ProfileServer { - private UserProfile _profile; + private readonly UserProfile _profile; public ProfileServer(UserProfile profile) { @@ -23,8 +23,8 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService MemoryHelper.FillWithZeros(context.Memory, bufferPosition, 0x80); // TODO: Determine the struct. - context.Memory.Write(bufferPosition, 0); // Unknown - context.Memory.Write(bufferPosition + 4, 1); // Icon ID. 0 = Mii, the rest are character icon IDs. + context.Memory.Write(bufferPosition, 0); // Unknown + context.Memory.Write(bufferPosition + 4, 1); // Icon ID. 0 = Mii, the rest are character icon IDs. context.Memory.Write(bufferPosition + 8, (byte)1); // Profile icon background color ID // 0x07 bytes - Unknown // 0x10 bytes - Some ID related to the Mii? All zeros when a character icon is used. @@ -58,7 +58,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService public ResultCode LoadImage(ServiceCtx context) { ulong bufferPosition = context.Request.ReceiveBuff[0].Position; - ulong bufferLen = context.Request.ReceiveBuff[0].Size; + ulong bufferLen = context.Request.ReceiveBuff[0].Size; if ((ulong)_profile.Image.Length > bufferLen) { @@ -75,7 +75,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService public ResultCode Store(ServiceCtx context) { ulong userDataPosition = context.Request.PtrBuff[0].Position; - ulong userDataSize = context.Request.PtrBuff[0].Size; + ulong userDataSize = context.Request.PtrBuff[0].Size; byte[] userData = new byte[userDataSize]; @@ -91,14 +91,14 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService public ResultCode StoreWithImage(ServiceCtx context) { ulong userDataPosition = context.Request.PtrBuff[0].Position; - ulong userDataSize = context.Request.PtrBuff[0].Size; + ulong userDataSize = context.Request.PtrBuff[0].Size; byte[] userData = new byte[userDataSize]; context.Memory.Read(userDataPosition, userData); ulong profileImagePosition = context.Request.SendBuff[0].Position; - ulong profileImageSize = context.Request.SendBuff[0].Size; + ulong profileImageSize = context.Request.SendBuff[0].Size; byte[] profileImageData = new byte[profileImageSize]; @@ -111,4 +111,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/ApplicationServiceServer.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/ApplicationServiceServer.cs index d9f9864a0..b30a81e94 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/ApplicationServiceServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/ApplicationServiceServer.cs @@ -58,7 +58,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc } ulong outputPosition = context.Request.RecvListBuff[0].Position; - ulong outputSize = context.Request.RecvListBuff[0].Size; + ulong outputSize = context.Request.RecvListBuff[0].Size; MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize); @@ -71,7 +71,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc break; } - context.Memory.Write(outputPosition + offset, userProfile.UserId.High); + context.Memory.Write(outputPosition + offset, userProfile.UserId.High); context.Memory.Write(outputPosition + offset + 8, userProfile.UserId.Low); offset += 0x10; @@ -148,7 +148,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc public ResultCode CheckNetworkServiceAvailabilityAsync(ServiceCtx context, out IAsyncContext asyncContext) { - KEvent asyncEvent = new(context.Device.System.KernelContext); + KEvent asyncEvent = new(context.Device.System.KernelContext); AsyncExecution asyncExecution = new(asyncEvent); asyncExecution.Initialize(1000, CheckNetworkServiceAvailabilityAsyncImpl); @@ -183,7 +183,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc } ulong inputPosition = context.Request.SendBuff[0].Position; - ulong inputSize = context.Request.SendBuff[0].Size; + ulong inputSize = context.Request.SendBuff[0].Size; if (inputSize != 0x24000) { @@ -251,4 +251,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AsyncContext/AsyncExecution.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AsyncContext/AsyncExecution.cs index 2ea92b117..c5f3d91ec 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AsyncContext/AsyncExecution.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AsyncContext/AsyncExecution.cs @@ -1,4 +1,4 @@ -using Ryujinx.Common.Logging; +using Ryujinx.Common.Logging; using Ryujinx.HLE.HOS.Kernel.Threading; using System; using System.Threading; @@ -9,18 +9,18 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext class AsyncExecution { private readonly CancellationTokenSource _tokenSource; - private readonly CancellationToken _token; + private readonly CancellationToken _token; - public KEvent SystemEvent { get; } - public bool IsInitialized { get; private set; } - public bool IsRunning { get; private set; } + public KEvent SystemEvent { get; } + public bool IsInitialized { get; private set; } + public bool IsRunning { get; private set; } public AsyncExecution(KEvent asyncEvent) { SystemEvent = asyncEvent; _tokenSource = new CancellationTokenSource(); - _token = _tokenSource.Token; + _token = _tokenSource.Token; } public void Initialize(int timeout, Func taskAsync) @@ -53,4 +53,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext _tokenSource.Cancel(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForAdministrator.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForAdministrator.cs index 6a457f042..121b79373 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForAdministrator.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForAdministrator.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc [Service("acc:su", AccountServiceFlag.Administrator)] // Max Sessions: 8 class IAccountServiceForAdministrator : IpcService { - private ApplicationServiceServer _applicationServiceServer; + private readonly ApplicationServiceServer _applicationServiceServer; public IAccountServiceForAdministrator(ServiceCtx context, AccountServiceFlag serviceFlag) { @@ -126,4 +126,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForApplication.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForApplication.cs index 8ec83e5c1..98af10694 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForApplication.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForApplication.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc [Service("acc:u0", AccountServiceFlag.Application)] // Max Sessions: 4 class IAccountServiceForApplication : IpcService { - private ApplicationServiceServer _applicationServiceServer; + private readonly ApplicationServiceServer _applicationServiceServer; public IAccountServiceForApplication(ServiceCtx context, AccountServiceFlag serviceFlag) { @@ -197,4 +197,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForSystemService.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForSystemService.cs index 3b5f3b03e..a586d21cc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForSystemService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAccountServiceForSystemService.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc [Service("acc:u1", AccountServiceFlag.SystemService)] // Max Sessions: 16 class IAccountServiceForSystemService : IpcService { - private ApplicationServiceServer _applicationServiceServer; + private readonly ApplicationServiceServer _applicationServiceServer; public IAccountServiceForSystemService(ServiceCtx context, AccountServiceFlag serviceFlag) { @@ -104,4 +104,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc return _applicationServiceServer.ListQualifiedUsers(context); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAsyncContext.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAsyncContext.cs index c9af0727f..2fa354b19 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAsyncContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAsyncContext.cs @@ -1,4 +1,4 @@ -using Ryujinx.HLE.HOS.Ipc; +using Ryujinx.HLE.HOS.Ipc; using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext; using Ryujinx.Horizon.Common; using System; @@ -18,12 +18,12 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc // GetSystemEvent() -> handle public ResultCode GetSystemEvent(ServiceCtx context) { - if (context.Process.HandleTable.GenerateHandle(AsyncExecution.SystemEvent.ReadableEvent, out int _systemEventHandle) != Result.Success) + if (context.Process.HandleTable.GenerateHandle(AsyncExecution.SystemEvent.ReadableEvent, out int systemEventHandle) != Result.Success) { throw new InvalidOperationException("Out of handles!"); } - context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_systemEventHandle); + context.Response.HandleDesc = IpcHandleDesc.MakeCopy(systemEventHandle); return ResultCode.Success; } @@ -76,4 +76,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAsyncNetworkServiceLicenseKindContext.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAsyncNetworkServiceLicenseKindContext.cs index 1fa5cf2a1..a7b0c0638 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAsyncNetworkServiceLicenseKindContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IAsyncNetworkServiceLicenseKindContext.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc { class IAsyncNetworkServiceLicenseKindContext : IAsyncContext { - private NetworkServiceLicenseKind? _serviceLicenseKind; + private readonly NetworkServiceLicenseKind? _serviceLicenseKind; public IAsyncNetworkServiceLicenseKindContext(AsyncExecution asyncExecution, NetworkServiceLicenseKind? serviceLicenseKind) : base(asyncExecution) { diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IBaasAccessTokenAccessor.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IBaasAccessTokenAccessor.cs index 223be2f5e..f86e30746 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/IBaasAccessTokenAccessor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/IBaasAccessTokenAccessor.cs @@ -5,4 +5,4 @@ { public IBaasAccessTokenAccessor(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/ProfilesJsonSerializerContext.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/ProfilesJsonSerializerContext.cs index 6b54898e5..d6446e735 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/ProfilesJsonSerializerContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/ProfilesJsonSerializerContext.cs @@ -8,4 +8,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc internal partial class ProfilesJsonSerializerContext : JsonSerializerContext { } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/AccountServiceFlag.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/AccountServiceFlag.cs index a991f9776..5dbf9a673 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/AccountServiceFlag.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/AccountServiceFlag.cs @@ -2,9 +2,9 @@ { enum AccountServiceFlag { - Administrator = 100, - SystemService = 101, - Application = 102, - BaasAccessTokenAccessor = 200 + Administrator = 100, + SystemService = 101, + Application = 102, + BaasAccessTokenAccessor = 200, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/AccountState.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/AccountState.cs index 1699abfbd..0e35b4812 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/AccountState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/AccountState.cs @@ -7,6 +7,6 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc public enum AccountState { Closed, - Open + Open, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/NetworkServiceLicenseKind.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/NetworkServiceLicenseKind.cs index a33e26707..a766edeff 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/NetworkServiceLicenseKind.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/NetworkServiceLicenseKind.cs @@ -3,6 +3,6 @@ enum NetworkServiceLicenseKind : uint { NoSubscription, - Subscribed + Subscribed, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/ProfilesJson.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/ProfilesJson.cs index 09f9d1421..4e22f434e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/ProfilesJson.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/ProfilesJson.cs @@ -7,4 +7,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.Types public List Profiles { get; set; } public string LastOpened { get; set; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs index e5577a94b..ed7bf4e56 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs @@ -15,18 +15,18 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc public bool IsNull => (Low | High) == 0; - public static UserId Null => new UserId(0, 0); + public static UserId Null => new(0, 0); public UserId(long low, long high) { - Low = low; + Low = low; High = high; } public UserId(byte[] bytes) { High = BitConverter.ToInt64(bytes, 0); - Low = BitConverter.ToInt64(bytes, 8); + Low = BitConverter.ToInt64(bytes, 8); } public UserId(string hex) @@ -36,7 +36,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc throw new ArgumentException("Invalid Hex value!", nameof(hex)); } - Low = long.Parse(hex.AsSpan(16), NumberStyles.HexNumber); + Low = long.Parse(hex.AsSpan(16), NumberStyles.HexNumber); High = long.Parse(hex.AsSpan(0, 16), NumberStyles.HexNumber); } @@ -61,4 +61,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc return new UInt128((ulong)High, (ulong)Low); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserProfile.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserProfile.cs index 210b369c3..4482de2dd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserProfile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserProfile.cs @@ -47,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc } } - public AccountState _onlinePlayState; + private AccountState _onlinePlayState; public AccountState OnlinePlayState { @@ -63,10 +63,10 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc public UserProfile(UserId userId, string name, byte[] image, long lastModifiedTimestamp = 0) { UserId = userId; - Name = name; - Image = image; + Name = name; + Image = image; - AccountState = AccountState.Closed; + AccountState = AccountState.Closed; OnlinePlayState = AccountState.Closed; if (lastModifiedTimestamp != 0) @@ -84,4 +84,4 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc LastModifiedTimestamp = (long)(DateTime.Now - DateTime.UnixEpoch).TotalSeconds; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserProfileJson.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserProfileJson.cs index 06ff4833f..e51aa8d1b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserProfileJson.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserProfileJson.cs @@ -9,4 +9,4 @@ public long LastModifiedTimestamp { get; set; } public byte[] Image { get; set; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Dauth/IService.cs b/src/Ryujinx.HLE/HOS/Services/Account/Dauth/IService.cs index 723013492..698c01a4a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Dauth/IService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Dauth/IService.cs @@ -5,4 +5,4 @@ { public IService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Account/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Account/ResultCode.cs index 34114ec9f..6bd3cce85 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/ResultCode.cs @@ -2,23 +2,23 @@ namespace Ryujinx.HLE.HOS.Services.Account { enum ResultCode { - ModuleId = 124, + ModuleId = 124, ErrorCodeShift = 9, Success = 0, - NullArgument = (20 << ErrorCodeShift) | ModuleId, - InvalidArgument = (22 << ErrorCodeShift) | ModuleId, - NullInputBuffer = (30 << ErrorCodeShift) | ModuleId, - InvalidBufferSize = (31 << ErrorCodeShift) | ModuleId, - InvalidBuffer = (32 << ErrorCodeShift) | ModuleId, - AsyncExecutionNotInitialized = (40 << ErrorCodeShift) | ModuleId, - Unknown41 = (41 << ErrorCodeShift) | ModuleId, - InternetRequestDenied = (59 << ErrorCodeShift) | ModuleId, - UserNotFound = (100 << ErrorCodeShift) | ModuleId, - NullObject = (302 << ErrorCodeShift) | ModuleId, - Unknown341 = (341 << ErrorCodeShift) | ModuleId, + NullArgument = (20 << ErrorCodeShift) | ModuleId, + InvalidArgument = (22 << ErrorCodeShift) | ModuleId, + NullInputBuffer = (30 << ErrorCodeShift) | ModuleId, + InvalidBufferSize = (31 << ErrorCodeShift) | ModuleId, + InvalidBuffer = (32 << ErrorCodeShift) | ModuleId, + AsyncExecutionNotInitialized = (40 << ErrorCodeShift) | ModuleId, + Unknown41 = (41 << ErrorCodeShift) | ModuleId, + InternetRequestDenied = (59 << ErrorCodeShift) | ModuleId, + UserNotFound = (100 << ErrorCodeShift) | ModuleId, + NullObject = (302 << ErrorCodeShift) | ModuleId, + Unknown341 = (341 << ErrorCodeShift) | ModuleId, MissingNetworkServiceLicenseKind = (400 << ErrorCodeShift) | ModuleId, - InvalidIdTokenCacheBufferSize = (451 << ErrorCodeShift) | ModuleId + InvalidIdTokenCacheBufferSize = (451 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ILibraryAppletProxy.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ILibraryAppletProxy.cs index bf86aaaa9..6821c7111 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ILibraryAppletProxy.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ILibraryAppletProxy.cs @@ -102,4 +102,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ISystemAppletProxy.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ISystemAppletProxy.cs index 93dff041c..dd015fd80 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ISystemAppletProxy.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ISystemAppletProxy.cs @@ -110,4 +110,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletCreator/ILibraryAppletAccessor.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletCreator/ILibraryAppletAccessor.cs index 0057eba34..d35cfdbe2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletCreator/ILibraryAppletAccessor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletCreator/ILibraryAppletAccessor.cs @@ -10,16 +10,16 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib { class ILibraryAppletAccessor : DisposableIpcService { - private KernelContext _kernelContext; + private readonly KernelContext _kernelContext; - private IApplet _applet; + private readonly IApplet _applet; - private AppletSession _normalSession; - private AppletSession _interactiveSession; + private readonly AppletSession _normalSession; + private readonly AppletSession _interactiveSession; - private KEvent _stateChangedEvent; - private KEvent _normalOutDataEvent; - private KEvent _interactiveOutDataEvent; + private readonly KEvent _stateChangedEvent; + private readonly KEvent _normalOutDataEvent; + private readonly KEvent _interactiveOutDataEvent; private int _stateChangedEventHandle; private int _normalOutDataEventHandle; @@ -31,17 +31,17 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib { _kernelContext = system.KernelContext; - _stateChangedEvent = new KEvent(system.KernelContext); - _normalOutDataEvent = new KEvent(system.KernelContext); + _stateChangedEvent = new KEvent(system.KernelContext); + _normalOutDataEvent = new KEvent(system.KernelContext); _interactiveOutDataEvent = new KEvent(system.KernelContext); _applet = AppletManager.Create(appletId, system); - _normalSession = new AppletSession(); + _normalSession = new AppletSession(); _interactiveSession = new AppletSession(); - _applet.AppletStateChanged += OnAppletStateChanged; - _normalSession.DataAvailable += OnNormalOutData; + _applet.AppletStateChanged += OnAppletStateChanged; + _normalSession.DataAvailable += OnNormalOutData; _interactiveSession.DataAvailable += OnInteractiveOutData; Logger.Info?.Print(LogClass.ServiceAm, $"Applet '{appletId}' created."); diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/AppletStandalone.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/AppletStandalone.cs index 69967c568..b523f02f1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/AppletStandalone.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/AppletStandalone.cs @@ -4,13 +4,13 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib { class AppletStandalone { - public AppletId AppletId; + public AppletId AppletId; public LibraryAppletMode LibraryAppletMode; - public Queue InputData; + public Queue InputData; public AppletStandalone() { InputData = new Queue(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/ILibraryAppletSelfAccessor.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/ILibraryAppletSelfAccessor.cs index 176bd6322..85bdd985c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/ILibraryAppletSelfAccessor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/ILibraryAppletSelfAccessor.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib { class ILibraryAppletSelfAccessor : IpcService { - private AppletStandalone _appletStandalone = new AppletStandalone(); + private readonly AppletStandalone _appletStandalone = new(); public ILibraryAppletSelfAccessor(ServiceCtx context) { @@ -14,8 +14,8 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib // Create MiiEdit data. _appletStandalone = new AppletStandalone() { - AppletId = AppletId.MiiEdit, - LibraryAppletMode = LibraryAppletMode.AllForeground + AppletId = AppletId.MiiEdit, + LibraryAppletMode = LibraryAppletMode.AllForeground, }; byte[] miiEditInputData = new byte[0x100]; @@ -49,10 +49,10 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib // GetLibraryAppletInfo() -> nn::am::service::LibraryAppletInfo public ResultCode GetLibraryAppletInfo(ServiceCtx context) { - LibraryAppletInfo libraryAppletInfo = new LibraryAppletInfo() + LibraryAppletInfo libraryAppletInfo = new() { - AppletId = _appletStandalone.AppletId, - LibraryAppletMode = _appletStandalone.LibraryAppletMode + AppletId = _appletStandalone.AppletId, + LibraryAppletMode = _appletStandalone.LibraryAppletMode, }; context.ResponseData.WriteStruct(libraryAppletInfo); @@ -64,10 +64,10 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib // GetCallerAppletIdentityInfo() -> nn::am::service::AppletIdentityInfo public ResultCode GetCallerAppletIdentityInfo(ServiceCtx context) { - AppletIdentifyInfo appletIdentifyInfo = new AppletIdentifyInfo() + AppletIdentifyInfo appletIdentifyInfo = new() { AppletId = AppletId.QLaunch, - TitleId = 0x0100000000001000 + TitleId = 0x0100000000001000, }; context.ResponseData.WriteStruct(appletIdentifyInfo); @@ -75,4 +75,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/IProcessWindingController.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/IProcessWindingController.cs index 6acd18cd6..e1857fb3e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/IProcessWindingController.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/LibraryAppletProxy/IProcessWindingController.cs @@ -11,9 +11,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib public ResultCode GetLaunchReason(ServiceCtx context) { // NOTE: Flag is set by using an internal field. - AppletProcessLaunchReason appletProcessLaunchReason = new AppletProcessLaunchReason() + AppletProcessLaunchReason appletProcessLaunchReason = new() { - Flag = 0 + Flag = 0, }; context.ResponseData.WriteStruct(appletProcessLaunchReason); @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IAppletCommonFunctions.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IAppletCommonFunctions.cs index c42202b82..fbcc33204 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IAppletCommonFunctions.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IAppletCommonFunctions.cs @@ -4,4 +4,4 @@ { public IAppletCommonFunctions() { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IApplicationCreator.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IApplicationCreator.cs index 79e5b0507..502324ea1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IApplicationCreator.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IApplicationCreator.cs @@ -4,4 +4,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys { public IApplicationCreator() { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IAudioController.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IAudioController.cs index 48dd42e41..05a4b0a63 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IAudioController.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IAudioController.cs @@ -10,8 +10,10 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys // SetExpectedMasterVolume(f32, f32) public ResultCode SetExpectedMasterVolume(ServiceCtx context) { - float appletVolume = context.RequestData.ReadSingle(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + float appletVolume = context.RequestData.ReadSingle(); float libraryAppletVolume = context.RequestData.ReadSingle(); +#pragma warning restore IDE0059 Logger.Stub?.PrintStub(LogClass.ServiceAm); @@ -44,8 +46,10 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys // ChangeMainAppletMasterVolume(f32, u64) public ResultCode ChangeMainAppletMasterVolume(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment float unknown0 = context.RequestData.ReadSingle(); - long unknown1 = context.RequestData.ReadInt64(); + long unknown1 = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 Logger.Stub?.PrintStub(LogClass.ServiceAm); @@ -56,11 +60,13 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys // SetTransparentVolumeRate(f32) public ResultCode SetTransparentVolumeRate(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment float unknown0 = context.RequestData.ReadSingle(); +#pragma warning restore IDE0059 Logger.Stub?.PrintStub(LogClass.ServiceAm); return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs index 5e7d0baea..0d2ec8bc4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ICommonStateGetter.cs @@ -13,28 +13,28 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys { private readonly ServiceCtx _context; - private Apm.ManagerServer _apmManagerServer; - private Apm.SystemManagerServer _apmSystemManagerServer; - private Lbl.LblControllerServer _lblControllerServer; + private readonly Apm.ManagerServer _apmManagerServer; + private readonly Apm.SystemManagerServer _apmSystemManagerServer; + private readonly Lbl.LblControllerServer _lblControllerServer; private bool _vrModeEnabled; -#pragma warning disable CS0414 +#pragma warning disable CS0414, IDE0052 // Remove unread private member private bool _lcdBacklighOffEnabled; private bool _requestExitToLibraryAppletAtExecuteNextProgramEnabled; -#pragma warning restore CS0414 - private int _messageEventHandle; - private int _displayResolutionChangedEventHandle; +#pragma warning restore CS0414, IDE0052 + private int _messageEventHandle; + private int _displayResolutionChangedEventHandle; - private KEvent _acquiredSleepLockEvent; + private readonly KEvent _acquiredSleepLockEvent; private int _acquiredSleepLockEventHandle; public ICommonStateGetter(ServiceCtx context) { _context = context; - _apmManagerServer = new Apm.ManagerServer(context); + _apmManagerServer = new Apm.ManagerServer(context); _apmSystemManagerServer = new Apm.SystemManagerServer(context); - _lblControllerServer = new Lbl.LblControllerServer(context); + _lblControllerServer = new Lbl.LblControllerServer(context); _acquiredSleepLockEvent = new KEvent(context.Device.System.KernelContext); } @@ -331,4 +331,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IDebugFunctions.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IDebugFunctions.cs index 51a112fd0..61cef13b9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IDebugFunctions.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IDebugFunctions.cs @@ -4,4 +4,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys { public IDebugFunctions() { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IDisplayController.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IDisplayController.cs index 92c97d861..6bd35a779 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IDisplayController.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IDisplayController.cs @@ -8,9 +8,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys { class IDisplayController : IpcService { - private KTransferMemory _transferMem; - private bool _lastApplicationCaptureBufferAcquired; - private bool _callerAppletCaptureBufferAcquired; + private readonly KTransferMemory _transferMem; + private bool _lastApplicationCaptureBufferAcquired; + private bool _callerAppletCaptureBufferAcquired; public IDisplayController(ServiceCtx context) { @@ -22,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys public ResultCode TakeScreenShotOfOwnLayer(ServiceCtx context) { bool unknown1 = context.RequestData.ReadBoolean(); - int unknown2 = context.RequestData.ReadInt32(); + int unknown2 = context.RequestData.ReadInt32(); Logger.Stub?.PrintStub(LogClass.ServiceAm, new { unknown1, unknown2 }); @@ -103,4 +103,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IGlobalStateController.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IGlobalStateController.cs index 24eeefb98..9e46d1cd7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IGlobalStateController.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IGlobalStateController.cs @@ -4,4 +4,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys { public IGlobalStateController() { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IHomeMenuFunctions.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IHomeMenuFunctions.cs index c7c073ff1..78f47e0e9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IHomeMenuFunctions.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IHomeMenuFunctions.cs @@ -8,8 +8,8 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys { class IHomeMenuFunctions : IpcService { - private KEvent _channelEvent; - private int _channelEventHandle; + private readonly KEvent _channelEvent; + private int _channelEventHandle; public IHomeMenuFunctions(Horizon system) { @@ -45,4 +45,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ILibraryAppletCreator.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ILibraryAppletCreator.cs index fb870c242..23ba99b04 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ILibraryAppletCreator.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ILibraryAppletCreator.cs @@ -11,8 +11,10 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys // CreateLibraryApplet(u32, u32) -> object public ResultCode CreateLibraryApplet(ServiceCtx context) { - AppletId appletId = (AppletId)context.RequestData.ReadInt32(); - int libraryAppletMode = context.RequestData.ReadInt32(); + AppletId appletId = (AppletId)context.RequestData.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + int libraryAppletMode = context.RequestData.ReadInt32(); +#pragma warning restore IDE0059 MakeObject(context, new ILibraryAppletAccessor(appletId, context.Device.System)); @@ -42,8 +44,8 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys public ResultCode CreateTransferMemoryStorage(ServiceCtx context) { bool isReadOnly = (context.RequestData.ReadInt64() & 1) == 0; - long size = context.RequestData.ReadInt64(); - int handle = context.Request.HandleDesc.ToCopy[0]; + long size = context.RequestData.ReadInt64(); + int handle = context.Request.HandleDesc.ToCopy[0]; KTransferMemory transferMem = context.Process.HandleTable.GetObject(handle); @@ -67,8 +69,8 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys // CreateHandleStorage(u64, handle) -> object public ResultCode CreateHandleStorage(ServiceCtx context) { - long size = context.RequestData.ReadInt64(); - int handle = context.Request.HandleDesc.ToCopy[0]; + long size = context.RequestData.ReadInt64(); + int handle = context.Request.HandleDesc.ToCopy[0]; KTransferMemory transferMem = context.Process.HandleTable.GetObject(handle); @@ -88,4 +90,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs index 8f93117e1..85898f138 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs @@ -11,30 +11,34 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys { private readonly ulong _pid; - private KEvent _libraryAppletLaunchableEvent; - private int _libraryAppletLaunchableEventHandle; + private readonly KEvent _libraryAppletLaunchableEvent; + private int _libraryAppletLaunchableEventHandle; private KEvent _accumulatedSuspendedTickChangedEvent; - private int _accumulatedSuspendedTickChangedEventHandle; + private int _accumulatedSuspendedTickChangedEventHandle; private readonly object _fatalSectionLock = new(); private int _fatalSectionCount; // TODO: Set this when the game goes in suspension (go back to home menu ect), we currently don't support that so we can keep it set to 0. - private ulong _accumulatedSuspendedTickValue = 0; + private readonly ulong _accumulatedSuspendedTickValue = 0; // TODO: Determine where those fields are used. - private bool _screenShotPermission = false; - private bool _operationModeChangedNotification = false; +#pragma warning disable IDE0052 // Remove unread private member + private bool _screenShotPermission = false; + private bool _operationModeChangedNotification = false; private bool _performanceModeChangedNotification = false; - private bool _restartMessageEnabled = false; - private bool _outOfFocusSuspendingEnabled = false; - private bool _handlesRequestToDisplay = false; - private bool _autoSleepDisabled = false; + private bool _restartMessageEnabled = false; + private bool _outOfFocusSuspendingEnabled = false; + private bool _handlesRequestToDisplay = false; +#pragma warning restore IDE0052 + private bool _autoSleepDisabled = false; +#pragma warning disable IDE0052 // Remove unread private member private bool _albumImageTakenNotificationEnabled = false; private bool _recordVolumeMuted = false; private uint _screenShotImageOrientation = 0; +#pragma warning restore IDE0052 private uint _idleTimeDetectionExtension = 0; public ISelfController(ServiceCtx context, ulong pid) diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IWindowController.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IWindowController.cs index 730df5d05..46dc4916d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IWindowController.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IWindowController.cs @@ -33,4 +33,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AlbumReportOption.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AlbumReportOption.cs index 84fc5c836..e4b434956 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AlbumReportOption.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AlbumReportOption.cs @@ -5,6 +5,6 @@ OverlayNotDisplayed, OverlayDisplayed, Unknown2, - Unknown3 + Unknown3, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AppletMessage.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AppletMessage.cs index 2920c3298..3f4600fa5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AppletMessage.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/AppletMessage.cs @@ -2,35 +2,35 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys { enum AppletMessage { - None = 0, - ChangeIntoForeground = 1, - ChangeIntoBackground = 2, - Exit = 4, - ApplicationExited = 6, - FocusStateChanged = 15, - Resume = 16, - DetectShortPressingHomeButton = 20, - DetectLongPressingHomeButton = 21, - DetectShortPressingPowerButton = 22, - DetectMiddlePressingPowerButton = 23, - DetectLongPressingPowerButton = 24, - RequestToPrepareSleep = 25, - FinishedSleepSequence = 26, - SleepRequiredByHighTemperature = 27, - SleepRequiredByLowBattery = 28, - AutoPowerDown = 29, - OperationModeChanged = 30, - PerformanceModeChanged = 31, - DetectReceivingCecSystemStandby = 32, - SdCardRemoved = 33, - LaunchApplicationRequested = 50, - RequestToDisplay = 51, - ShowApplicationLogo = 55, - HideApplicationLogo = 56, - ForceHideApplicationLogo = 57, - FloatingApplicationDetected = 60, + None = 0, + ChangeIntoForeground = 1, + ChangeIntoBackground = 2, + Exit = 4, + ApplicationExited = 6, + FocusStateChanged = 15, + Resume = 16, + DetectShortPressingHomeButton = 20, + DetectLongPressingHomeButton = 21, + DetectShortPressingPowerButton = 22, + DetectMiddlePressingPowerButton = 23, + DetectLongPressingPowerButton = 24, + RequestToPrepareSleep = 25, + FinishedSleepSequence = 26, + SleepRequiredByHighTemperature = 27, + SleepRequiredByLowBattery = 28, + AutoPowerDown = 29, + OperationModeChanged = 30, + PerformanceModeChanged = 31, + DetectReceivingCecSystemStandby = 32, + SdCardRemoved = 33, + LaunchApplicationRequested = 50, + RequestToDisplay = 51, + ShowApplicationLogo = 55, + HideApplicationLogo = 56, + ForceHideApplicationLogo = 57, + FloatingApplicationDetected = 60, DetectShortPressingCaptureButton = 90, - AlbumScreenShotTaken = 92, - AlbumRecordingSaved = 93 + AlbumScreenShotTaken = 92, + AlbumRecordingSaved = 93, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/FocusState.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/FocusState.cs index dfd7d7f2c..afb7d6b42 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/FocusState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/FocusState.cs @@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys { enum FocusState { - InFocus = 1, - OutOfFocus = 2 + InFocus = 1, + OutOfFocus = 2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/OperationMode.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/OperationMode.cs index a82ed476e..861259783 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/OperationMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/OperationMode.cs @@ -3,6 +3,6 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys enum OperationMode { Handheld = 0, - Docked = 1 + Docked = 1, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/WirelessPriorityMode.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/WirelessPriorityMode.cs index e8ba9b615..3ea923f55 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/WirelessPriorityMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/Types/WirelessPriorityMode.cs @@ -4,6 +4,6 @@ { Default, OptimizedForWlan, - Unknown2 + Unknown2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AppletFifo.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AppletFifo.cs index fb16c86e7..e7482b789 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AppletFifo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AppletFifo.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE { internal class AppletFifo : IAppletFifo { - private ConcurrentQueue _dataQueue; + private readonly ConcurrentQueue _dataQueue; public event EventHandler DataAvailable; diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AppletSession.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AppletSession.cs index 6c9197b3e..63eb2ca54 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AppletSession.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/AppletSession.cs @@ -4,8 +4,8 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE { internal class AppletSession { - private IAppletFifo _inputData; - private IAppletFifo _outputData; + private readonly IAppletFifo _inputData; + private readonly IAppletFifo _outputData; public event EventHandler DataAvailable; @@ -23,7 +23,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE IAppletFifo inputData, IAppletFifo outputData) { - _inputData = inputData; + _inputData = inputData; _outputData = outputData; _inputData.DataAvailable += OnDataAvailable; diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IAllSystemAppletProxiesService.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IAllSystemAppletProxiesService.cs index 728a10180..0a032562a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IAllSystemAppletProxiesService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IAllSystemAppletProxiesService.cs @@ -26,4 +26,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IStorage.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IStorage.cs index 190f1a514..311084aa1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IStorage.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IStorage.cs @@ -2,13 +2,13 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE { class IStorage : IpcService { - public bool IsReadOnly { get; private set; } - public byte[] Data { get; private set; } + public bool IsReadOnly { get; private set; } + public byte[] Data { get; private set; } public IStorage(byte[] data, bool isReadOnly = false) { IsReadOnly = isReadOnly; - Data = data; + Data = data; } [CommandCmif(0)] @@ -20,4 +20,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IStorageAccessor.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IStorageAccessor.cs index 4c7e264d0..54c7b69e5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IStorageAccessor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/IStorageAccessor.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE { class IStorageAccessor : IpcService { - private IStorage _storage; + private readonly IStorage _storage; public IStorageAccessor(IStorage storage) { @@ -83,4 +83,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Storage/StorageHelper.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Storage/StorageHelper.cs index 49e342f27..ef5951d70 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Storage/StorageHelper.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Storage/StorageHelper.cs @@ -11,18 +11,16 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.Storage public static byte[] MakeLaunchParams(UserProfile userProfile) { // Size needs to be at least 0x88 bytes otherwise application errors. - using (MemoryStream ms = MemoryStreamManager.Shared.GetStream()) - { - BinaryWriter writer = new BinaryWriter(ms); + using MemoryStream ms = MemoryStreamManager.Shared.GetStream(); + BinaryWriter writer = new(ms); - ms.SetLength(0x88); + ms.SetLength(0x88); - writer.Write(LaunchParamsMagic); - writer.Write(1); // IsAccountSelected? Only lower 8 bits actually used. - userProfile.UserId.Write(writer); + writer.Write(LaunchParamsMagic); + writer.Write(1); // IsAccountSelected? Only lower 8 bits actually used. + userProfile.UserId.Write(writer); - return ms.ToArray(); - } + return ms.ToArray(); } } } diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletId.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletId.cs index 917f68658..503de4d2e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletId.cs @@ -2,26 +2,26 @@ { enum AppletId { - Application = 0x01, - OverlayDisplay = 0x02, - QLaunch = 0x03, - Starter = 0x04, - Auth = 0x0A, - Cabinet = 0x0B, - Controller = 0x0C, - DataErase = 0x0D, - Error = 0x0E, - NetConnect = 0x0F, - PlayerSelect = 0x10, - SoftwareKeyboard = 0x11, - MiiEdit = 0x12, - LibAppletWeb = 0x13, - LibAppletShop = 0x14, - PhotoViewer = 0x15, - Settings = 0x16, - LibAppletOff = 0x17, + Application = 0x01, + OverlayDisplay = 0x02, + QLaunch = 0x03, + Starter = 0x04, + Auth = 0x0A, + Cabinet = 0x0B, + Controller = 0x0C, + DataErase = 0x0D, + Error = 0x0E, + NetConnect = 0x0F, + PlayerSelect = 0x10, + SoftwareKeyboard = 0x11, + MiiEdit = 0x12, + LibAppletWeb = 0x13, + LibAppletShop = 0x14, + PhotoViewer = 0x15, + Settings = 0x16, + LibAppletOff = 0x17, LibAppletWhitelisted = 0x18, - LibAppletAuth = 0x19, - MyPage = 0x1A + LibAppletAuth = 0x19, + MyPage = 0x1A, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletIdentityInfo.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletIdentityInfo.cs index 17a485ab0..84fd1b4ca 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletIdentityInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletIdentityInfo.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE struct AppletIdentifyInfo { public AppletId AppletId; - public uint Padding; - public ulong TitleId; + public uint Padding; + public ulong TitleId; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletProcessLaunchReason.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletProcessLaunchReason.cs index 6c5283370..b6c32da5d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletProcessLaunchReason.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/AppletProcessLaunchReason.cs @@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE [StructLayout(LayoutKind.Sequential, Size = 0x4)] struct AppletProcessLaunchReason { - public byte Flag; + public byte Flag; public ushort Unknown1; - public byte Unknown2; + public byte Unknown2; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/LibraryAppletInfo.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/LibraryAppletInfo.cs index fc1c11e48..1205a7dcf 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/LibraryAppletInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/LibraryAppletInfo.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE [StructLayout(LayoutKind.Sequential, Size = 0x8)] struct LibraryAppletInfo { - public AppletId AppletId; + public AppletId AppletId; public LibraryAppletMode LibraryAppletMode; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/LibraryAppletMode.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/LibraryAppletMode.cs index 6b9a2284d..044a3168c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/LibraryAppletMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletAE/Types/LibraryAppletMode.cs @@ -9,6 +9,6 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE PartialForeground, NoUi, PartialForegroundWithIndirectDisplay, - AllForegroundInitiallyHidden + AllForegroundInitiallyHidden, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs index 5ae8f459f..271d00605 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs @@ -1,5 +1,4 @@ using LibHac.Account; -using LibHac.Common; using LibHac.Fs; using LibHac.Ncm; using LibHac.Ns; @@ -18,20 +17,20 @@ using Ryujinx.Horizon.Common; using System; using System.Numerics; using System.Threading; -using AccountUid = Ryujinx.HLE.HOS.Services.Account.Acc.UserId; +using AccountUid = Ryujinx.HLE.HOS.Services.Account.Acc.UserId; using ApplicationId = LibHac.Ncm.ApplicationId; namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy { class IApplicationFunctions : IpcService { - private long _defaultSaveDataSize = 200000000; + private long _defaultSaveDataSize = 200000000; private long _defaultJournalSaveDataSize = 200000000; - private KEvent _gpuErrorDetectedSystemEvent; - private KEvent _friendInvitationStorageChannelEvent; - private KEvent _notificationStorageChannelEvent; - private KEvent _healthWarningDisappearedSystemEvent; + private readonly KEvent _gpuErrorDetectedSystemEvent; + private readonly KEvent _friendInvitationStorageChannelEvent; + private readonly KEvent _notificationStorageChannelEvent; + private readonly KEvent _healthWarningDisappearedSystemEvent; private int _gpuErrorDetectedSystemEventHandle; private int _friendInvitationStorageChannelEventHandle; @@ -42,14 +41,14 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati private int _jitLoaded; - private LibHac.HorizonClient _horizon; + private readonly LibHac.HorizonClient _horizon; public IApplicationFunctions(Horizon system) { // TODO: Find where they are signaled. - _gpuErrorDetectedSystemEvent = new KEvent(system.KernelContext); + _gpuErrorDetectedSystemEvent = new KEvent(system.KernelContext); _friendInvitationStorageChannelEvent = new KEvent(system.KernelContext); - _notificationStorageChannelEvent = new KEvent(system.KernelContext); + _notificationStorageChannelEvent = new KEvent(system.KernelContext); _healthWarningDisappearedSystemEvent = new KEvent(system.KernelContext); _horizon = system.LibHacHorizonManager.AmClient; @@ -115,7 +114,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati Uid userId = context.RequestData.ReadStruct().ToLibHacUid(); // Mask out the low nibble of the program ID to get the application ID - ApplicationId applicationId = new ApplicationId(context.Device.Processes.ActiveApplication.ProgramId & ~0xFul); + ApplicationId applicationId = new(context.Device.Processes.ActiveApplication.ProgramId & ~0xFul); ApplicationControlProperty nacp = context.Device.Processes.ActiveApplication.ApplicationControlProperties; @@ -137,8 +136,8 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati // TODO: When above calls are implemented, switch to using ns:am long desiredLanguageCode = context.Device.System.State.DesiredLanguageCode; - int supportedLanguages = (int)context.Device.Processes.ActiveApplication.ApplicationControlProperties.SupportedLanguageFlag; - int firstSupported = BitOperations.TrailingZeroCount(supportedLanguages); + int supportedLanguages = (int)context.Device.Processes.ActiveApplication.ApplicationControlProperties.SupportedLanguageFlag; + int firstSupported = BitOperations.TrailingZeroCount(supportedLanguages); if (firstSupported > (int)TitleLanguage.BrazilianPortuguese) { @@ -168,7 +167,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati // SetTerminateResult(u32) public ResultCode SetTerminateResult(ServiceCtx context) { - LibHac.Result result = new LibHac.Result(context.RequestData.ReadUInt32()); + LibHac.Result result = new(context.RequestData.ReadUInt32()); Logger.Info?.Print(LogClass.ServiceAm, $"Result = 0x{result.Value:x8} ({result.ToStringWithName()})."); @@ -190,14 +189,14 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati public ResultCode ExtendSaveData(ServiceCtx context) { SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadUInt64(); - Uid userId = context.RequestData.ReadStruct(); - long saveDataSize = context.RequestData.ReadInt64(); - long journalSize = context.RequestData.ReadInt64(); + Uid userId = context.RequestData.ReadStruct(); + long saveDataSize = context.RequestData.ReadInt64(); + long journalSize = context.RequestData.ReadInt64(); // NOTE: Service calls nn::fs::ExtendApplicationSaveData. // Since LibHac currently doesn't support this method, we can stub it for now. - _defaultSaveDataSize = saveDataSize; + _defaultSaveDataSize = saveDataSize; _defaultJournalSaveDataSize = journalSize; context.ResponseData.Write((uint)ResultCode.Success); @@ -212,7 +211,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati public ResultCode GetSaveDataSize(ServiceCtx context) { SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadUInt64(); - Uid userId = context.RequestData.ReadStruct(); + Uid userId = context.RequestData.ReadStruct(); // NOTE: Service calls nn::fs::FindSaveDataWithFilter with SaveDataType = 1 hardcoded. // Then it calls nn::fs::GetSaveDataAvailableSize and nn::fs::GetSaveDataJournalSize to get the sizes. @@ -235,14 +234,17 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati long journalSize = context.RequestData.ReadInt64(); // Mask out the low nibble of the program ID to get the application ID - ApplicationId applicationId = new ApplicationId(context.Device.Processes.ActiveApplication.ProgramId & ~0xFul); + ApplicationId applicationId = new(context.Device.Processes.ActiveApplication.ProgramId & ~0xFul); ApplicationControlProperty nacp = context.Device.Processes.ActiveApplication.ApplicationControlProperties; LibHac.Result result = _horizon.Fs.CreateApplicationCacheStorage(out long requiredSize, out CacheStorageTargetMedia storageTarget, applicationId, in nacp, index, saveSize, journalSize); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write((ulong)storageTarget); context.ResponseData.Write(requiredSize); @@ -391,10 +393,10 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati // InitializeApplicationCopyrightFrameBuffer(s32 width, s32 height, handle transfer_memory, u64 transfer_memory_size) public ResultCode InitializeApplicationCopyrightFrameBuffer(ServiceCtx context) { - int width = context.RequestData.ReadInt32(); - int height = context.RequestData.ReadInt32(); - ulong transferMemorySize = context.RequestData.ReadUInt64(); - int transferMemoryHandle = context.Request.HandleDesc.ToCopy[0]; + int width = context.RequestData.ReadInt32(); + int height = context.RequestData.ReadInt32(); + ulong transferMemorySize = context.RequestData.ReadUInt64(); + int transferMemoryHandle = context.Request.HandleDesc.ToCopy[0]; ulong transferMemoryAddress = context.Process.HandleTable.GetObject(transferMemoryHandle).Address; ResultCode resultCode = ResultCode.InvalidParameters; @@ -437,13 +439,13 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati // SetApplicationCopyrightImage(buffer frame_buffer, s32 x, s32 y, s32 width, s32 height, s32 window_origin_mode) public ResultCode SetApplicationCopyrightImage(ServiceCtx context) { - ulong frameBufferPos = context.Request.SendBuff[0].Position; - ulong frameBufferSize = context.Request.SendBuff[0].Size; - int x = context.RequestData.ReadInt32(); - int y = context.RequestData.ReadInt32(); - int width = context.RequestData.ReadInt32(); - int height = context.RequestData.ReadInt32(); - uint windowOriginMode = context.RequestData.ReadUInt32(); + ulong frameBufferPos = context.Request.SendBuff[0].Position; + ulong frameBufferSize = context.Request.SendBuff[0].Size; + int x = context.RequestData.ReadInt32(); + int y = context.RequestData.ReadInt32(); + int width = context.RequestData.ReadInt32(); + int height = context.RequestData.ReadInt32(); + uint windowOriginMode = context.RequestData.ReadUInt32(); ResultCode resultCode = ResultCode.InvalidParameters; @@ -653,11 +655,11 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati if (Interlocked.Exchange(ref _jitLoaded, 1) == 0) { string jitPath = context.Device.System.ContentManager.GetInstalledContentPath(0x010000000000003B, StorageId.BuiltInSystem, NcaContentType.Program); - string filePath = context.Device.FileSystem.SwitchPathToSystemPath(jitPath); + string filePath = FileSystem.VirtualFileSystem.SwitchPathToSystemPath(jitPath); if (string.IsNullOrWhiteSpace(filePath)) { - throw new InvalidSystemResourceException($"JIT (010000000000003B) system title not found! The JIT will not work, provide the system archive to fix this error. (See https://github.com/Ryujinx/Ryujinx#requirements for more information)"); + throw new InvalidSystemResourceException("JIT (010000000000003B) system title not found! The JIT will not work, provide the system archive to fix this error. (See https://github.com/Ryujinx/Ryujinx#requirements for more information)"); } context.Device.LoadNca(filePath); @@ -672,4 +674,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/Types/LaunchParameterKind.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/Types/LaunchParameterKind.cs index 40432074d..7d82dcf5f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/Types/LaunchParameterKind.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/Types/LaunchParameterKind.cs @@ -4,6 +4,6 @@ { UserChannel = 1, PreselectedUser, - Unknown + Unknown, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/Types/ProgramSpecifyKind.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/Types/ProgramSpecifyKind.cs index efc284a5c..29ecf4217 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/Types/ProgramSpecifyKind.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/Types/ProgramSpecifyKind.cs @@ -4,6 +4,6 @@ { ExecuteProgram, SubApplicationProgram, - RestartProgram + RestartProgram, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/IApplicationProxy.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/IApplicationProxy.cs index 50e3be274..b24e1bf4f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/IApplicationProxy.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/IApplicationProxy.cs @@ -84,4 +84,4 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/IApplicationProxyService.cs b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/IApplicationProxyService.cs index 3a4c71e4b..9814976f7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/IApplicationProxyService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/AppletOE/IApplicationProxyService.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.Am return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/Idle/IPolicyManagerSystem.cs b/src/Ryujinx.HLE/HOS/Services/Am/Idle/IPolicyManagerSystem.cs index 8c72319c3..824d4c22f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/Idle/IPolicyManagerSystem.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/Idle/IPolicyManagerSystem.cs @@ -5,4 +5,4 @@ { public IPolicyManagerSystem(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/Omm/IOperationModeManager.cs b/src/Ryujinx.HLE/HOS/Services/Am/Omm/IOperationModeManager.cs index 2856e6d7b..44c4dafce 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/Omm/IOperationModeManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/Omm/IOperationModeManager.cs @@ -5,4 +5,4 @@ { public IOperationModeManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Am/ResultCode.cs index 5cafff678..9142f65e0 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/ResultCode.cs @@ -2,29 +2,29 @@ namespace Ryujinx.HLE.HOS.Services.Am { enum ResultCode { - ModuleId = 128, + ModuleId = 128, ErrorCodeShift = 9, Success = 0, - NotAvailable = (2 << ErrorCodeShift) | ModuleId, - NoMessages = (3 << ErrorCodeShift) | ModuleId, - AppletLaunchFailed = (35 << ErrorCodeShift) | ModuleId, - TitleIdNotFound = (37 << ErrorCodeShift) | ModuleId, - ObjectInvalid = (500 << ErrorCodeShift) | ModuleId, - IStorageInUse = (502 << ErrorCodeShift) | ModuleId, - OutOfBounds = (503 << ErrorCodeShift) | ModuleId, - BufferNotAcquired = (504 << ErrorCodeShift) | ModuleId, - BufferAlreadyAcquired = (505 << ErrorCodeShift) | ModuleId, - InvalidParameters = (506 << ErrorCodeShift) | ModuleId, - OpenedAsWrongType = (511 << ErrorCodeShift) | ModuleId, + NotAvailable = (2 << ErrorCodeShift) | ModuleId, + NoMessages = (3 << ErrorCodeShift) | ModuleId, + AppletLaunchFailed = (35 << ErrorCodeShift) | ModuleId, + TitleIdNotFound = (37 << ErrorCodeShift) | ModuleId, + ObjectInvalid = (500 << ErrorCodeShift) | ModuleId, + IStorageInUse = (502 << ErrorCodeShift) | ModuleId, + OutOfBounds = (503 << ErrorCodeShift) | ModuleId, + BufferNotAcquired = (504 << ErrorCodeShift) | ModuleId, + BufferAlreadyAcquired = (505 << ErrorCodeShift) | ModuleId, + InvalidParameters = (506 << ErrorCodeShift) | ModuleId, + OpenedAsWrongType = (511 << ErrorCodeShift) | ModuleId, UnbalancedFatalSection = (512 << ErrorCodeShift) | ModuleId, - NullObject = (518 << ErrorCodeShift) | ModuleId, + NullObject = (518 << ErrorCodeShift) | ModuleId, MemoryAllocationFailed = (600 << ErrorCodeShift) | ModuleId, - StackPoolExhausted = (712 << ErrorCodeShift) | ModuleId, - DebugModeNotEnabled = (974 << ErrorCodeShift) | ModuleId, - DevFunctionNotEnabled = (980 << ErrorCodeShift) | ModuleId, - NotImplemented = (998 << ErrorCodeShift) | ModuleId, - Stubbed = (999 << ErrorCodeShift) | ModuleId + StackPoolExhausted = (712 << ErrorCodeShift) | ModuleId, + DebugModeNotEnabled = (974 << ErrorCodeShift) | ModuleId, + DevFunctionNotEnabled = (980 << ErrorCodeShift) | ModuleId, + NotImplemented = (998 << ErrorCodeShift) | ModuleId, + Stubbed = (999 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Am/Spsm/IPowerStateInterface.cs b/src/Ryujinx.HLE/HOS/Services/Am/Spsm/IPowerStateInterface.cs index a393f76be..40a1300c1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/Spsm/IPowerStateInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/Spsm/IPowerStateInterface.cs @@ -5,4 +5,4 @@ { public IPowerStateInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Am/Tcap/IManager.cs b/src/Ryujinx.HLE/HOS/Services/Am/Tcap/IManager.cs index b31ccf8a3..edb9618c6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Am/Tcap/IManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Am/Tcap/IManager.cs @@ -5,4 +5,4 @@ { public IManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/IManager.cs b/src/Ryujinx.HLE/HOS/Services/Apm/IManager.cs index 72e39a77f..83215befa 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/IManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/IManager.cs @@ -40,4 +40,4 @@ namespace Ryujinx.HLE.HOS.Services.Apm return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/IManagerPrivileged.cs b/src/Ryujinx.HLE/HOS/Services/Apm/IManagerPrivileged.cs index 9620c30a1..bb0049d1b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/IManagerPrivileged.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/IManagerPrivileged.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.Apm return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/ISession.cs b/src/Ryujinx.HLE/HOS/Services/Apm/ISession.cs index f828cd175..6ee696056 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/ISession.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/ISession.cs @@ -12,7 +12,7 @@ namespace Ryujinx.HLE.HOS.Services.Apm // SetPerformanceConfiguration(nn::apm::PerformanceMode, nn::apm::PerformanceConfiguration) public ResultCode SetPerformanceConfiguration(ServiceCtx context) { - PerformanceMode performanceMode = (PerformanceMode)context.RequestData.ReadInt32(); + PerformanceMode performanceMode = (PerformanceMode)context.RequestData.ReadInt32(); PerformanceConfiguration performanceConfiguration = (PerformanceConfiguration)context.RequestData.ReadInt32(); return SetPerformanceConfiguration(performanceMode, performanceConfiguration); @@ -42,4 +42,4 @@ namespace Ryujinx.HLE.HOS.Services.Apm return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/ISystemManager.cs b/src/Ryujinx.HLE/HOS/Services/Apm/ISystemManager.cs index 9d2c7b0b4..375423cf2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/ISystemManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/ISystemManager.cs @@ -39,4 +39,4 @@ namespace Ryujinx.HLE.HOS.Services.Apm return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/ManagerServer.cs b/src/Ryujinx.HLE/HOS/Services/Apm/ManagerServer.cs index af0519344..9a3a0462f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/ManagerServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/ManagerServer.cs @@ -28,4 +28,4 @@ return _context.Device.System.PerformanceState.CpuOverclockEnabled; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/PerformanceState.cs b/src/Ryujinx.HLE/HOS/Services/Apm/PerformanceState.cs index d03bf6c72..0fb6c28a6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/PerformanceState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/PerformanceState.cs @@ -7,19 +7,19 @@ public bool CpuOverclockEnabled = false; public PerformanceMode PerformanceMode = PerformanceMode.Default; - public CpuBoostMode CpuBoostMode = CpuBoostMode.Disabled; + public CpuBoostMode CpuBoostMode = CpuBoostMode.Disabled; public PerformanceConfiguration DefaultPerformanceConfiguration = PerformanceConfiguration.PerformanceConfiguration7; - public PerformanceConfiguration BoostPerformanceConfiguration = PerformanceConfiguration.PerformanceConfiguration8; + public PerformanceConfiguration BoostPerformanceConfiguration = PerformanceConfiguration.PerformanceConfiguration8; public PerformanceConfiguration GetCurrentPerformanceConfiguration(PerformanceMode performanceMode) { return performanceMode switch { PerformanceMode.Default => DefaultPerformanceConfiguration, - PerformanceMode.Boost => BoostPerformanceConfiguration, - _ => PerformanceConfiguration.PerformanceConfiguration7 + PerformanceMode.Boost => BoostPerformanceConfiguration, + _ => PerformanceConfiguration.PerformanceConfiguration7, }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Apm/ResultCode.cs index c4499b014..3cbfbffb4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/ResultCode.cs @@ -2,11 +2,11 @@ namespace Ryujinx.HLE.HOS.Services.Apm { enum ResultCode { - ModuleId = 148, + ModuleId = 148, ErrorCodeShift = 9, Success = 0, - InvalidParameters = (1 << ErrorCodeShift) | ModuleId + InvalidParameters = (1 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/SessionServer.cs b/src/Ryujinx.HLE/HOS/Services/Apm/SessionServer.cs index 3ef713cf3..260992be7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/SessionServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/SessionServer.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Apm { private readonly ServiceCtx _context; - public SessionServer(ServiceCtx context) : base(context) + public SessionServer(ServiceCtx context) : base(context) { _context = context; } @@ -55,4 +55,4 @@ namespace Ryujinx.HLE.HOS.Services.Apm // NOTE: This call seems to overclock the system, since we emulate it, it's fine to do nothing instead. } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/SystemManagerServer.cs b/src/Ryujinx.HLE/HOS/Services/Apm/SystemManagerServer.cs index a62642360..3fe5b3834 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/SystemManagerServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/SystemManagerServer.cs @@ -25,4 +25,4 @@ return _context.Device.System.PerformanceState.GetCurrentPerformanceConfiguration(_context.Device.System.PerformanceState.PerformanceMode); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/Types/CpuBoostMode.cs b/src/Ryujinx.HLE/HOS/Services/Apm/Types/CpuBoostMode.cs index 587142c83..c84d32baf 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/Types/CpuBoostMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/Types/CpuBoostMode.cs @@ -2,8 +2,8 @@ { enum CpuBoostMode { - Disabled = 0, - BoostCPU = 1, // Uses PerformanceConfiguration13 and PerformanceConfiguration14, or PerformanceConfiguration15 and PerformanceConfiguration16 - ConservePower = 2 // Uses PerformanceConfiguration15 and PerformanceConfiguration16. + Disabled = 0, + BoostCPU = 1, // Uses PerformanceConfiguration13 and PerformanceConfiguration14, or PerformanceConfiguration15 and PerformanceConfiguration16 + ConservePower = 2, // Uses PerformanceConfiguration15 and PerformanceConfiguration16. } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/Types/PerformanceConfiguration.cs b/src/Ryujinx.HLE/HOS/Services/Apm/Types/PerformanceConfiguration.cs index e8c5752e4..6dd193f9b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/Types/PerformanceConfiguration.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/Types/PerformanceConfiguration.cs @@ -2,21 +2,21 @@ { enum PerformanceConfiguration : uint // Clocks are all in MHz. { // CPU | GPU | RAM | NOTE - PerformanceConfiguration1 = 0x00010000, // 1020 | 384 | 1600 | Only available while docked. - PerformanceConfiguration2 = 0x00010001, // 1020 | 768 | 1600 | Only available while docked. - PerformanceConfiguration3 = 0x00010002, // 1224 | 691.2 | 1600 | Only available for SDEV units. - PerformanceConfiguration4 = 0x00020000, // 1020 | 230.4 | 1600 | Only available for SDEV units. - PerformanceConfiguration5 = 0x00020001, // 1020 | 307.2 | 1600 | - PerformanceConfiguration6 = 0x00020002, // 1224 | 230.4 | 1600 | - PerformanceConfiguration7 = 0x00020003, // 1020 | 307 | 1331.2 | - PerformanceConfiguration8 = 0x00020004, // 1020 | 384 | 1331.2 | - PerformanceConfiguration9 = 0x00020005, // 1020 | 307.2 | 1065.6 | + PerformanceConfiguration1 = 0x00010000, // 1020 | 384 | 1600 | Only available while docked. + PerformanceConfiguration2 = 0x00010001, // 1020 | 768 | 1600 | Only available while docked. + PerformanceConfiguration3 = 0x00010002, // 1224 | 691.2 | 1600 | Only available for SDEV units. + PerformanceConfiguration4 = 0x00020000, // 1020 | 230.4 | 1600 | Only available for SDEV units. + PerformanceConfiguration5 = 0x00020001, // 1020 | 307.2 | 1600 | + PerformanceConfiguration6 = 0x00020002, // 1224 | 230.4 | 1600 | + PerformanceConfiguration7 = 0x00020003, // 1020 | 307 | 1331.2 | + PerformanceConfiguration8 = 0x00020004, // 1020 | 384 | 1331.2 | + PerformanceConfiguration9 = 0x00020005, // 1020 | 307.2 | 1065.6 | PerformanceConfiguration10 = 0x00020006, // 1020 | 384 | 1065.6 | PerformanceConfiguration11 = 0x92220007, // 1020 | 460.8 | 1600 | PerformanceConfiguration12 = 0x92220008, // 1020 | 460.8 | 1331.2 | PerformanceConfiguration13 = 0x92220009, // 1785 | 768 | 1600 | 7.0.0+ PerformanceConfiguration14 = 0x9222000A, // 1785 | 768 | 1331.2 | 7.0.0+ PerformanceConfiguration15 = 0x9222000B, // 1020 | 768 | 1600 | 7.0.0+ - PerformanceConfiguration16 = 0x9222000C // 1020 | 768 | 1331.2 | 7.0.0+ + PerformanceConfiguration16 = 0x9222000C, // 1020 | 768 | 1331.2 | 7.0.0+ } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Apm/Types/PerformanceMode.cs b/src/Ryujinx.HLE/HOS/Services/Apm/Types/PerformanceMode.cs index 6d6f9643e..0a7719657 100644 --- a/src/Ryujinx.HLE/HOS/Services/Apm/Types/PerformanceMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Apm/Types/PerformanceMode.cs @@ -3,6 +3,6 @@ enum PerformanceMode : uint { Default = 0, - Boost = 1 + Boost = 1, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Arp/ApplicationLaunchProperty.cs b/src/Ryujinx.HLE/HOS/Services/Arp/ApplicationLaunchProperty.cs index 3e4eca0ac..9c2b9d19a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Arp/ApplicationLaunchProperty.cs +++ b/src/Ryujinx.HLE/HOS/Services/Arp/ApplicationLaunchProperty.cs @@ -5,10 +5,10 @@ namespace Ryujinx.HLE.HOS.Services.Arp class ApplicationLaunchProperty { public ulong TitleId; - public int Version; - public byte BaseGameStorageId; - public byte UpdateGameStorageId; -#pragma warning disable CS0649 + public int Version; + public byte BaseGameStorageId; + public byte UpdateGameStorageId; +#pragma warning disable CS0649 // Field is never assigned to public short Padding; #pragma warning restore CS0649 @@ -18,10 +18,10 @@ namespace Ryujinx.HLE.HOS.Services.Arp { return new ApplicationLaunchProperty { - TitleId = 0x00, - Version = 0x00, - BaseGameStorageId = (byte)StorageId.BuiltInSystem, - UpdateGameStorageId = (byte)StorageId.None + TitleId = 0x00, + Version = 0x00, + BaseGameStorageId = (byte)StorageId.BuiltInSystem, + UpdateGameStorageId = (byte)StorageId.None, }; } } @@ -33,11 +33,11 @@ namespace Ryujinx.HLE.HOS.Services.Arp return new ApplicationLaunchProperty { - TitleId = context.Device.Processes.ActiveApplication.ProgramId, - Version = 0x00, - BaseGameStorageId = (byte)StorageId.BuiltInSystem, - UpdateGameStorageId = (byte)StorageId.None + TitleId = context.Device.Processes.ActiveApplication.ProgramId, + Version = 0x00, + BaseGameStorageId = (byte)StorageId.BuiltInSystem, + UpdateGameStorageId = (byte)StorageId.None, }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Arp/IReader.cs b/src/Ryujinx.HLE/HOS/Services/Arp/IReader.cs index 35a2de0c1..90cba861a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Arp/IReader.cs +++ b/src/Ryujinx.HLE/HOS/Services/Arp/IReader.cs @@ -5,4 +5,4 @@ { public IReader(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Arp/IWriter.cs b/src/Ryujinx.HLE/HOS/Services/Arp/IWriter.cs index 8d13f0fb8..7c3992c73 100644 --- a/src/Ryujinx.HLE/HOS/Services/Arp/IWriter.cs +++ b/src/Ryujinx.HLE/HOS/Services/Arp/IWriter.cs @@ -5,4 +5,4 @@ { public IWriter(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Arp/LibHacIReader.cs b/src/Ryujinx.HLE/HOS/Services/Arp/LibHacIReader.cs index d7686871a..fdddb79e5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Arp/LibHacIReader.cs +++ b/src/Ryujinx.HLE/HOS/Services/Arp/LibHacIReader.cs @@ -3,7 +3,6 @@ using LibHac.Common; using LibHac.Ncm; using LibHac.Ns; using System; - using ApplicationId = LibHac.ApplicationId; namespace Ryujinx.HLE.HOS.Services.Arp @@ -17,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Services.Arp launchProperty = new LibHac.Arp.ApplicationLaunchProperty { StorageId = StorageId.BuiltInUser, - ApplicationId = ApplicationId + ApplicationId = ApplicationId, }; return Result.Success; @@ -30,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Arp launchProperty = new LibHac.Arp.ApplicationLaunchProperty { StorageId = StorageId.BuiltInUser, - ApplicationId = applicationId + ApplicationId = applicationId, }; return Result.Success; @@ -73,4 +72,4 @@ namespace Ryujinx.HLE.HOS.Services.Arp return Result.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioIn/AudioIn.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioIn/AudioIn.cs index ee85ded98..ee8e46436 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioIn/AudioIn.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioIn/AudioIn.cs @@ -10,9 +10,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn { class AudioIn : IAudioIn { - private AudioInputSystem _system; - private uint _processHandle; - private KernelContext _kernelContext; + private readonly AudioInputSystem _system; + private readonly uint _processHandle; + private readonly KernelContext _kernelContext; public AudioIn(AudioInputSystem system, KernelContext kernelContext, uint processHandle) { @@ -80,9 +80,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn { IWritableEvent outEvent = _system.RegisterBufferEvent(); - if (outEvent is AudioKernelEvent) + if (outEvent is AudioKernelEvent kernelEvent) { - return ((AudioKernelEvent)outEvent).Event; + return kernelEvent.Event; } else { @@ -105,4 +105,4 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn return (ResultCode)_system.Stop(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioIn/AudioInServer.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioIn/AudioInServer.cs index a80b94025..81b76e7a8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioIn/AudioInServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioIn/AudioInServer.cs @@ -11,7 +11,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn { class AudioInServer : DisposableIpcService { - private IAudioIn _impl; + private readonly IAudioIn _impl; public AudioInServer(IAudioIn impl) { @@ -77,14 +77,12 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn ulong position = context.Request.ReceiveBuff[0].Position; ulong size = context.Request.ReceiveBuff[0].Size; - using (WritableRegion outputRegion = context.Memory.GetWritableRegion((ulong)position, (int)size)) - { - ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast(outputRegion.Memory.Span), out uint releasedCount); + using WritableRegion outputRegion = context.Memory.GetWritableRegion((ulong)position, (int)size); + ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast(outputRegion.Memory.Span), out uint releasedCount); - context.ResponseData.Write(releasedCount); + context.ResponseData.Write(releasedCount); - return result; - } + return result; } [CommandCmif(6)] @@ -131,14 +129,12 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn { (ulong position, ulong size) = context.Request.GetBufferType0x22(); - using (WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size)) - { - ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast(outputRegion.Memory.Span), out uint releasedCount); + using WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size); + ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast(outputRegion.Memory.Span), out uint releasedCount); - context.ResponseData.Write(releasedCount); + context.ResponseData.Write(releasedCount); - return result; - } + return result; } [CommandCmif(10)] // 3.0.0+ diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManager.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManager.cs index 36b0ed282..ba7462d36 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManager.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio { class AudioInManager : IAudioInManager { - private AudioInManagerImpl _impl; + private readonly AudioInManagerImpl _impl; public AudioInManager(AudioInManagerImpl impl) { diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManagerServer.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManagerServer.cs index 755caee52..ac1863abe 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManagerServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManagerServer.cs @@ -12,7 +12,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio { private const int AudioInNameSize = 0x100; - private IAudioInManager _impl; + private readonly IAudioInManager _impl; public AudioInManagerServer(ServiceCtx context) : this(context, new AudioInManager(context.Device.System.AudioInputManager)) { } @@ -69,7 +69,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio ulong deviceNameInputSize = context.Request.SendBuff[0].Size; ulong deviceNameOutputPosition = context.Request.ReceiveBuff[0].Position; +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong deviceNameOutputSize = context.Request.ReceiveBuff[0].Size; +#pragma warning restore IDE0059 uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0]; @@ -136,7 +138,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio ulong appletResourceUserId = context.RequestData.ReadUInt64(); (ulong deviceNameInputPosition, ulong deviceNameInputSize) = context.Request.GetBufferType0x21(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong deviceNameOutputPosition, ulong deviceNameOutputSize) = context.Request.GetBufferType0x22(); +#pragma warning restore IDE0059 uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0]; @@ -200,7 +204,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio public ResultCode OpenAudioInProtocolSpecified(ServiceCtx context) { // NOTE: We always assume that only the default device will be plugged (we never report any USB Audio Class type devices). +#pragma warning disable IDE0059 // Remove unnecessary value assignment bool protocolSpecifiedRelated = context.RequestData.ReadUInt64() == 1; +#pragma warning restore IDE0059 AudioInputConfiguration inputConfiguration = context.RequestData.ReadStruct(); ulong appletResourceUserId = context.RequestData.ReadUInt64(); @@ -209,7 +215,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio ulong deviceNameInputSize = context.Request.SendBuff[0].Size; ulong deviceNameOutputPosition = context.Request.ReceiveBuff[0].Position; +#pragma warning disable IDE0051, IDE0059 // Remove unused private member ulong deviceNameOutputSize = context.Request.ReceiveBuff[0].Size; +#pragma warning restore IDE0051, IDE0059 uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0]; diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOut/AudioOut.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOut/AudioOut.cs index f25884523..8624ab9bc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOut/AudioOut.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOut/AudioOut.cs @@ -10,9 +10,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut { class AudioOut : IAudioOut { - private AudioOutputSystem _system; - private uint _processHandle; - private KernelContext _kernelContext; + private readonly AudioOutputSystem _system; + private readonly uint _processHandle; + private readonly KernelContext _kernelContext; public AudioOut(AudioOutputSystem system, KernelContext kernelContext, uint processHandle) { @@ -80,9 +80,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut { IWritableEvent outEvent = _system.RegisterBufferEvent(); - if (outEvent is AudioKernelEvent) + if (outEvent is AudioKernelEvent kernelEvent) { - return ((AudioKernelEvent)outEvent).Event; + return kernelEvent.Event; } else { diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOut/AudioOutServer.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOut/AudioOutServer.cs index 329e17941..3b6834f7c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOut/AudioOutServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOut/AudioOutServer.cs @@ -11,7 +11,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut { class AudioOutServer : DisposableIpcService { - private IAudioOut _impl; + private readonly IAudioOut _impl; public AudioOutServer(IAudioOut impl) { @@ -77,14 +77,12 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut ulong position = context.Request.ReceiveBuff[0].Position; ulong size = context.Request.ReceiveBuff[0].Size; - using (WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size)) - { - ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast(outputRegion.Memory.Span), out uint releasedCount); + using WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size); + ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast(outputRegion.Memory.Span), out uint releasedCount); - context.ResponseData.Write(releasedCount); + context.ResponseData.Write(releasedCount); - return result; - } + return result; } [CommandCmif(6)] @@ -117,14 +115,12 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut { (ulong position, ulong size) = context.Request.GetBufferType0x22(); - using (WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size)) - { - ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast(outputRegion.Memory.Span), out uint releasedCount); + using WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size); + ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast(outputRegion.Memory.Span), out uint releasedCount); - context.ResponseData.Write(releasedCount); + context.ResponseData.Write(releasedCount); - return result; - } + return result; } [CommandCmif(9)] // 4.0.0+ diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManager.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManager.cs index e95de0575..fbbb3e1df 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManager.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio { class AudioOutManager : IAudioOutManager { - private AudioOutManagerImpl _impl; + private readonly AudioOutManagerImpl _impl; public AudioOutManager(AudioOutManagerImpl impl) { diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManagerServer.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManagerServer.cs index 7c5d8c4ec..ca4d61630 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManagerServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManagerServer.cs @@ -12,7 +12,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio { private const int AudioOutNameSize = 0x100; - private IAudioOutManager _impl; + private readonly IAudioOutManager _impl; public AudioOutManagerServer(ServiceCtx context) : this(context, new AudioOutManager(context.Device.System.AudioOutputManager)) { } @@ -69,7 +69,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio ulong deviceNameInputSize = context.Request.SendBuff[0].Size; ulong deviceNameOutputPosition = context.Request.ReceiveBuff[0].Position; +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong deviceNameOutputSize = context.Request.ReceiveBuff[0].Size; +#pragma warning restore IDE0059 uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0]; @@ -136,7 +138,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio ulong appletResourceUserId = context.RequestData.ReadUInt64(); (ulong deviceNameInputPosition, ulong deviceNameInputSize) = context.Request.GetBufferType0x21(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong deviceNameOutputPosition, ulong deviceNameOutputSize) = context.Request.GetBufferType0x22(); +#pragma warning restore IDE0059 uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0]; diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioDevice.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioDevice.cs index 724a1e9ec..9a08f1ba9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioDevice.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioDevice.cs @@ -7,13 +7,15 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer { class AudioDevice : IAudioDevice { - private VirtualDeviceSession[] _sessions; - private ulong _appletResourceId; - private int _revision; - private bool _isUsbDeviceSupported; + private readonly VirtualDeviceSession[] _sessions; +#pragma warning disable IDE0052 // Remove unread private member + private readonly ulong _appletResourceId; + private readonly int _revision; +#pragma warning restore IDE0052 + private readonly bool _isUsbDeviceSupported; - private VirtualDeviceSessionRegistry _registry; - private KEvent _systemEvent; + private readonly VirtualDeviceSessionRegistry _registry; + private readonly KEvent _systemEvent; public AudioDevice(VirtualDeviceSessionRegistry registry, KernelContext context, ulong appletResourceId, int revision) { @@ -21,7 +23,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer _appletResourceId = appletResourceId; _revision = revision; - BehaviourContext behaviourContext = new BehaviourContext(); + BehaviourContext behaviourContext = new(); behaviourContext.SetUserRevision(revision); _isUsbDeviceSupported = behaviourContext.IsAudioUsbDeviceOutputSupported(); diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioDeviceServer.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioDeviceServer.cs index e7a751216..9694406d6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioDeviceServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioDeviceServer.cs @@ -12,7 +12,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer { private const int AudioDeviceNameSize = 0x100; - private IAudioDevice _impl; + private readonly IAudioDevice _impl; public AudioDeviceServer(IAudioDevice impl) { diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioRenderer.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioRenderer.cs index 5b682bf84..8b8e55fb2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioRenderer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioRenderer.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer { class AudioRenderer : IAudioRenderer { - private AudioRenderSystem _impl; + private readonly AudioRenderSystem _impl; public AudioRenderer(AudioRenderSystem impl) { @@ -55,9 +55,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer if (resultCode == ResultCode.Success) { - if (outEvent is AudioKernelEvent) + if (outEvent is AudioKernelEvent kernelEvent) { - systemEvent = ((AudioKernelEvent)outEvent).Event; + systemEvent = kernelEvent.Event; } else { diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioRendererServer.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioRendererServer.cs index 5d8e086d0..af8d20ba7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioRendererServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/AudioRendererServer.cs @@ -10,7 +10,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer { class AudioRendererServer : DisposableIpcService { - private IAudioRenderer _impl; + private readonly IAudioRenderer _impl; public AudioRendererServer(IAudioRenderer impl) { @@ -69,29 +69,27 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer ReadOnlyMemory input = context.Memory.GetSpan(inputPosition, (int)inputSize).ToArray(); - using (IMemoryOwner outputOwner = ByteMemoryPool.RentCleared(outputSize)) - using (IMemoryOwner performanceOutputOwner = ByteMemoryPool.RentCleared(performanceOutputSize)) + using IMemoryOwner outputOwner = ByteMemoryPool.RentCleared(outputSize); + using IMemoryOwner performanceOutputOwner = ByteMemoryPool.RentCleared(performanceOutputSize); + Memory output = outputOwner.Memory; + Memory performanceOutput = performanceOutputOwner.Memory; + + using MemoryHandle outputHandle = output.Pin(); + using MemoryHandle performanceOutputHandle = performanceOutput.Pin(); + + ResultCode result = _impl.RequestUpdate(output, performanceOutput, input); + + if (result == ResultCode.Success) { - Memory output = outputOwner.Memory; - Memory performanceOutput = performanceOutputOwner.Memory; - - using MemoryHandle outputHandle = output.Pin(); - using MemoryHandle performanceOutputHandle = performanceOutput.Pin(); - - ResultCode result = _impl.RequestUpdate(output, performanceOutput, input); - - if (result == ResultCode.Success) - { - context.Memory.Write(outputPosition, output.Span); - context.Memory.Write(performanceOutputPosition, performanceOutput.Span); - } - else - { - Logger.Error?.Print(LogClass.ServiceAudio, $"Error while processing renderer update: 0x{(int)result:X}"); - } - - return result; + context.Memory.Write(outputPosition, output.Span); + context.Memory.Write(performanceOutputPosition, performanceOutput.Span); } + else + { + Logger.Error?.Print(LogClass.ServiceAudio, $"Error while processing renderer update: 0x{(int)result:X}"); + } + + return result; } [CommandCmif(5)] diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/IAudioDevice.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/IAudioDevice.cs index 1918a977f..4a1b5ffb1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/IAudioDevice.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRenderer/IAudioDevice.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer { string[] ListAudioDeviceName(); ResultCode SetAudioDeviceOutputVolume(string name, float volume); - ResultCode GetAudioDeviceOutputVolume(string name, out float volume); + ResultCode GetAudioDeviceOutputVolume(string name, out float volume); string GetActiveAudioDeviceName(); KEvent QueryAudioDeviceSystemEvent(); uint GetActiveChannelCount(); diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRendererManager.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRendererManager.cs index 40e71a43b..b40c32a12 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRendererManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRendererManager.cs @@ -10,8 +10,8 @@ namespace Ryujinx.HLE.HOS.Services.Audio { class AudioRendererManager : IAudioRendererManager { - private AudioRendererManagerImpl _impl; - private VirtualDeviceSessionRegistry _registry; + private readonly AudioRendererManagerImpl _impl; + private readonly VirtualDeviceSessionRegistry _registry; public AudioRendererManager(AudioRendererManagerImpl impl, VirtualDeviceSessionRegistry registry) { diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRendererManagerServer.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRendererManagerServer.cs index 80b54e8c7..58a1daf10 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioRendererManagerServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioRendererManagerServer.cs @@ -12,7 +12,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio { private const int InitialRevision = ('R' << 0) | ('E' << 8) | ('V' << 16) | ('1' << 24); - private IAudioRendererManager _impl; + private readonly IAudioRendererManager _impl; public AudioRendererManagerServer(ServiceCtx context) : this(context, new AudioRendererManager(context.Device.System.AudioRendererManager, context.Device.System.AudioDeviceSessionRegistry)) { } diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/Decoder.cs b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/Decoder.cs index b77fc4b05..c5dd2f00d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/Decoder.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/Decoder.cs @@ -24,4 +24,4 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager _decoder.ResetState(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/DecoderCommon.cs b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/DecoderCommon.cs index 944541cce..9ff511a50 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/DecoderCommon.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/DecoderCommon.cs @@ -89,4 +89,4 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/IDecoder.cs b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/IDecoder.cs index 9047c2668..cc83be5e3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/IDecoder.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/IDecoder.cs @@ -8,4 +8,4 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager int Decode(byte[] inData, int inDataOffset, int len, short[] outPcm, int outPcmOffset, int frameSize); void ResetState(); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/IHardwareOpusDecoder.cs b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/IHardwareOpusDecoder.cs index e94b31ca1..3d5d2839f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/IHardwareOpusDecoder.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/IHardwareOpusDecoder.cs @@ -87,10 +87,10 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager private ResultCode DecodeInterleavedInternal(ServiceCtx context, OpusDecoderFlags flags, bool reset, bool withPerf) { - ulong inPosition = context.Request.SendBuff[0].Position; - ulong inSize = context.Request.SendBuff[0].Size; + ulong inPosition = context.Request.SendBuff[0].Position; + ulong inSize = context.Request.SendBuff[0].Size; ulong outputPosition = context.Request.ReceiveBuff[0].Position; - ulong outputSize = context.Request.ReceiveBuff[0].Size; + ulong outputSize = context.Request.ReceiveBuff[0].Size; ReadOnlySpan input = context.Memory.GetSpan(inPosition, (int)inSize); @@ -113,4 +113,4 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager return result; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/MultiSampleDecoder.cs b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/MultiSampleDecoder.cs index 23721d3bf..910bb23ee 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/MultiSampleDecoder.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/HardwareOpusDecoderManager/MultiSampleDecoder.cs @@ -25,4 +25,4 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager _decoder.ResetState(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioController.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioController.cs index 1bd2e31de..223675808 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioController.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioController.cs @@ -5,4 +5,4 @@ { public IAudioController(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManager.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManager.cs index 9bbe5b0e4..709320c82 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManager.cs @@ -9,4 +9,4 @@ namespace Ryujinx.HLE.HOS.Services.Audio public ResultCode OpenAudioIn(ServiceCtx context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioIn obj, string inputDeviceName, ref AudioInputConfiguration parameter, ulong appletResourceUserId, uint processHandle); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManagerForApplet.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManagerForApplet.cs index 37d9a8fe8..1735768c0 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManagerForApplet.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManagerForApplet.cs @@ -5,4 +5,4 @@ { public IAudioInManagerForApplet(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManagerForDebugger.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManagerForDebugger.cs index 1a497efb6..ebdcfd8c2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManagerForDebugger.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioInManagerForDebugger.cs @@ -5,4 +5,4 @@ { public IAudioInManagerForDebugger(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioOutManagerForApplet.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioOutManagerForApplet.cs index 4b41b0cfc..1c3502d6c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioOutManagerForApplet.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioOutManagerForApplet.cs @@ -5,4 +5,4 @@ { public IAudioOutManagerForApplet(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioOutManagerForDebugger.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioOutManagerForDebugger.cs index 41cde9726..1da017cbe 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioOutManagerForDebugger.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioOutManagerForDebugger.cs @@ -5,4 +5,4 @@ { public IAudioOutManagerForDebugger(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioRendererManagerForApplet.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioRendererManagerForApplet.cs index ca5768cca..28aa6d8c9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioRendererManagerForApplet.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioRendererManagerForApplet.cs @@ -5,4 +5,4 @@ { public IAudioRendererManagerForApplet(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioRendererManagerForDebugger.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioRendererManagerForDebugger.cs index a970ae45c..50754f8a8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioRendererManagerForDebugger.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioRendererManagerForDebugger.cs @@ -5,4 +5,4 @@ { public IAudioRendererManagerForDebugger(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioSnoopManager.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioSnoopManager.cs index 59e3ad09b..73bc629fe 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IAudioSnoopManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IAudioSnoopManager.cs @@ -5,4 +5,4 @@ { public IAudioSnoopManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManager.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManager.cs index 014350081..56647d04f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManager.cs @@ -5,4 +5,4 @@ { public IFinalOutputRecorderManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManagerForApplet.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManagerForApplet.cs index d8fd270d5..6dfd5f968 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManagerForApplet.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManagerForApplet.cs @@ -5,4 +5,4 @@ { public IFinalOutputRecorderManagerForApplet(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManagerForDebugger.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManagerForDebugger.cs index a8ec51ee5..653ab598c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManagerForDebugger.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IFinalOutputRecorderManagerForDebugger.cs @@ -5,4 +5,4 @@ { public IFinalOutputRecorderManagerForDebugger(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/IHardwareOpusDecoderManager.cs b/src/Ryujinx.HLE/HOS/Services/Audio/IHardwareOpusDecoderManager.cs index 8df8a38c9..b69a23921 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/IHardwareOpusDecoderManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/IHardwareOpusDecoderManager.cs @@ -14,7 +14,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio // Initialize(bytes<8, 4>, u32, handle) -> object public ResultCode Initialize(ServiceCtx context) { - int sampleRate = context.RequestData.ReadInt32(); + int sampleRate = context.RequestData.ReadInt32(); int channelsCount = context.RequestData.ReadInt32(); MakeObject(context, new IHardwareOpusDecoder(sampleRate, channelsCount, OpusDecoderFlags.None)); @@ -29,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio // GetWorkBufferSize(bytes<8, 4>) -> u32 public ResultCode GetWorkBufferSize(ServiceCtx context) { - int sampleRate = context.RequestData.ReadInt32(); + int sampleRate = context.RequestData.ReadInt32(); int channelsCount = context.RequestData.ReadInt32(); int opusDecoderSize = GetOpusDecoderSize(channelsCount); @@ -196,10 +196,10 @@ namespace Ryujinx.HLE.HOS.Services.Audio private static int GetCeltDecoderSize(int channelsCount) { const int DecodeBufferSize = 0x2030; - const int Overlap = 120; - const int EBandsCount = 21; + const int Overlap = 120; + const int EBandsCount = 21; return (DecodeBufferSize + Overlap * 4) * channelsCount + EBandsCount * 16 + 0x50; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Audio/ResultCode.cs index fd2091c2a..c1d49109c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/ResultCode.cs @@ -2,20 +2,20 @@ namespace Ryujinx.HLE.HOS.Services.Audio { enum ResultCode { - ModuleId = 153, + ModuleId = 153, ErrorCodeShift = 9, Success = 0, - DeviceNotFound = (1 << ErrorCodeShift) | ModuleId, - UnsupportedRevision = (2 << ErrorCodeShift) | ModuleId, + DeviceNotFound = (1 << ErrorCodeShift) | ModuleId, + UnsupportedRevision = (2 << ErrorCodeShift) | ModuleId, UnsupportedSampleRate = (3 << ErrorCodeShift) | ModuleId, - BufferSizeTooSmall = (4 << ErrorCodeShift) | ModuleId, - OpusInvalidInput = (6 << ErrorCodeShift) | ModuleId, - TooManyBuffersInUse = (8 << ErrorCodeShift) | ModuleId, - InvalidChannelCount = (10 << ErrorCodeShift) | ModuleId, - InvalidOperation = (513 << ErrorCodeShift) | ModuleId, - InvalidHandle = (1536 << ErrorCodeShift) | ModuleId, - OutputAlreadyStarted = (1540 << ErrorCodeShift) | ModuleId + BufferSizeTooSmall = (4 << ErrorCodeShift) | ModuleId, + OpusInvalidInput = (6 << ErrorCodeShift) | ModuleId, + TooManyBuffersInUse = (8 << ErrorCodeShift) | ModuleId, + InvalidChannelCount = (10 << ErrorCodeShift) | ModuleId, + InvalidOperation = (513 << ErrorCodeShift) | ModuleId, + InvalidHandle = (1536 << ErrorCodeShift) | ModuleId, + OutputAlreadyStarted = (1540 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/Types/OpusPacketHeader.cs b/src/Ryujinx.HLE/HOS/Services/Audio/Types/OpusPacketHeader.cs index 5ae0eb1e4..2c5478276 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/Types/OpusPacketHeader.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/Types/OpusPacketHeader.cs @@ -14,7 +14,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.Types { OpusPacketHeader header = MemoryMarshal.Cast(data)[0]; - header.length = BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(header.length) : header.length; + header.length = BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(header.length) : header.length; header.finalRange = BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(header.finalRange) : header.finalRange; return header; diff --git a/src/Ryujinx.HLE/HOS/Services/Bgtc/IStateControlService.cs b/src/Ryujinx.HLE/HOS/Services/Bgtc/IStateControlService.cs index 4926d4d82..97d0cf946 100644 --- a/src/Ryujinx.HLE/HOS/Services/Bgtc/IStateControlService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Bgtc/IStateControlService.cs @@ -5,4 +5,4 @@ { public IStateControlService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Bgtc/ITaskService.cs b/src/Ryujinx.HLE/HOS/Services/Bgtc/ITaskService.cs index a032c3809..1b4b45f61 100644 --- a/src/Ryujinx.HLE/HOS/Services/Bgtc/ITaskService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Bgtc/ITaskService.cs @@ -5,4 +5,4 @@ { public ITaskService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Bluetooth/BluetoothDriver/BluetoothEventManager.cs b/src/Ryujinx.HLE/HOS/Services/Bluetooth/BluetoothDriver/BluetoothEventManager.cs index 81f4a7d29..5b8624001 100644 --- a/src/Ryujinx.HLE/HOS/Services/Bluetooth/BluetoothDriver/BluetoothEventManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Bluetooth/BluetoothDriver/BluetoothEventManager.cs @@ -5,21 +5,21 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth.BluetoothDriver static class BluetoothEventManager { public static KEvent InitializeBleDebugEvent; - public static int InitializeBleDebugEventHandle; + public static int InitializeBleDebugEventHandle; public static KEvent UnknownBleDebugEvent; - public static int UnknownBleDebugEventHandle; + public static int UnknownBleDebugEventHandle; public static KEvent RegisterBleDebugEvent; - public static int RegisterBleDebugEventHandle; + public static int RegisterBleDebugEventHandle; public static KEvent InitializeBleEvent; - public static int InitializeBleEventHandle; + public static int InitializeBleEventHandle; public static KEvent UnknownBleEvent; - public static int UnknownBleEventHandle; + public static int UnknownBleEventHandle; public static KEvent RegisterBleEvent; - public static int RegisterBleEventHandle; + public static int RegisterBleEventHandle; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothDriver.cs b/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothDriver.cs index feff5a73f..ace2c86a4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothDriver.cs +++ b/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothDriver.cs @@ -10,9 +10,9 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth [Service("btdrv")] class IBluetoothDriver : IpcService { -#pragma warning disable CS0414 +#pragma warning disable CS0414, IDE0052 // Remove unread private member private string _unknownLowEnergy; -#pragma warning restore CS0414 +#pragma warning restore CS0414, IDE0052 public IBluetoothDriver(ServiceCtx context) { } @@ -100,4 +100,4 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothUser.cs b/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothUser.cs index 1a5e25a48..04782d08e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothUser.cs +++ b/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothUser.cs @@ -27,4 +27,4 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/BtmUser/IBtmUserCore.cs b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/BtmUser/IBtmUserCore.cs index 3c9938ad7..da45dc776 100644 --- a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/BtmUser/IBtmUserCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/BtmUser/IBtmUserCore.cs @@ -8,16 +8,16 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser class IBtmUserCore : IpcService { public KEvent _bleScanEvent; - public int _bleScanEventHandle; + public int _bleScanEventHandle; public KEvent _bleConnectionEvent; - public int _bleConnectionEventHandle; + public int _bleConnectionEventHandle; public KEvent _bleServiceDiscoveryEvent; - public int _bleServiceDiscoveryEventHandle; + public int _bleServiceDiscoveryEventHandle; public KEvent _bleMtuConfigEvent; - public int _bleMtuConfigEventHandle; + public int _bleMtuConfigEventHandle; public IBtmUserCore() { } @@ -125,4 +125,4 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtm.cs b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtm.cs index 48a273a09..13d14151a 100644 --- a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtm.cs +++ b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtm.cs @@ -5,4 +5,4 @@ { public IBtm(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmDebug.cs b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmDebug.cs index 259698af5..43a6ccc6c 100644 --- a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmDebug.cs +++ b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmDebug.cs @@ -5,4 +5,4 @@ { public IBtmDebug(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmSystem.cs b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmSystem.cs index c4210b782..67d851b49 100644 --- a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmSystem.cs +++ b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmSystem.cs @@ -5,4 +5,4 @@ { public IBtmSystem(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmUser.cs b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmUser.cs index b00f0a2f3..225a71e33 100644 --- a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmUser.cs +++ b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/IBtmUser.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/ResultCode.cs index 0ad2c4855..01e62d2af 100644 --- a/src/Ryujinx.HLE/HOS/Services/BluetoothManager/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/BluetoothManager/ResultCode.cs @@ -2,9 +2,9 @@ { enum ResultCode { - ModuleId = 143, + ModuleId = 143, ErrorCodeShift = 9, - Success = 0 + Success = 0, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs b/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs index 6320fe284..349dd34f9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs @@ -11,19 +11,21 @@ namespace Ryujinx.HLE.HOS.Services.Caps { class CaptureManager { - private string _sdCardPath; + private readonly string _sdCardPath; private uint _shimLibraryVersion; public CaptureManager(Switch device) { - _sdCardPath = device.FileSystem.GetSdCardPath(); + _sdCardPath = FileSystem.VirtualFileSystem.GetSdCardPath(); } public ResultCode SetShimLibraryVersion(ServiceCtx context) { - ulong shimLibraryVersion = context.RequestData.ReadUInt64(); + ulong shimLibraryVersion = context.RequestData.ReadUInt64(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong appletResourceUserId = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 // TODO: Service checks if the pid is present in an internal list and returns ResultCode.BlacklistedPid if it is. // The list contents needs to be determined. @@ -82,28 +84,28 @@ namespace Ryujinx.HLE.HOS.Services.Caps applicationAlbumEntry = new ApplicationAlbumEntry() { - Size = (ulong)Unsafe.SizeOf(), - TitleId = titleId, + Size = (ulong)Unsafe.SizeOf(), + TitleId = titleId, AlbumFileDateTime = new AlbumFileDateTime() { - Year = (ushort)currentDateTime.Year, - Month = (byte)currentDateTime.Month, - Day = (byte)currentDateTime.Day, - Hour = (byte)currentDateTime.Hour, - Minute = (byte)currentDateTime.Minute, - Second = (byte)currentDateTime.Second, - UniqueId = 0 + Year = (ushort)currentDateTime.Year, + Month = (byte)currentDateTime.Month, + Day = (byte)currentDateTime.Day, + Hour = (byte)currentDateTime.Hour, + Minute = (byte)currentDateTime.Minute, + Second = (byte)currentDateTime.Second, + UniqueId = 0, }, - AlbumStorage = AlbumStorage.Sd, - ContentType = ContentType.Screenshot, - Padding = new Array5(), - Unknown0x1f = 1 + AlbumStorage = AlbumStorage.Sd, + ContentType = ContentType.Screenshot, + Padding = new Array5(), + Unknown0x1f = 1, }; // NOTE: The hex hash is a HMAC-SHA256 (first 32 bytes) using a hardcoded secret key over the titleId, we can simulate it by hashing the titleId instead. - string hash = Convert.ToHexString(SHA256.HashData(BitConverter.GetBytes(titleId))).Remove(0x20); + string hash = Convert.ToHexString(SHA256.HashData(BitConverter.GetBytes(titleId))).Remove(0x20); string folderPath = Path.Combine(_sdCardPath, "Nintendo", "Album", currentDateTime.Year.ToString("00"), currentDateTime.Month.ToString("00"), currentDateTime.Day.ToString("00")); - string filePath = GenerateFilePath(folderPath, applicationAlbumEntry, currentDateTime, hash); + string filePath = GenerateFilePath(folderPath, applicationAlbumEntry, currentDateTime, hash); // TODO: Handle that using the FS service implementation and return the right error code instead of throwing exceptions. Directory.CreateDirectory(folderPath); @@ -131,4 +133,4 @@ namespace Ryujinx.HLE.HOS.Services.Caps return Path.Combine(folderPath, fileName); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumAccessorService.cs b/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumAccessorService.cs index 4071b9cc0..de62b08d7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumAccessorService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumAccessorService.cs @@ -5,4 +5,4 @@ namespace Ryujinx.HLE.HOS.Services.Caps { public IAlbumAccessorService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumApplicationService.cs b/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumApplicationService.cs index af99232eb..5fbba310f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumApplicationService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumApplicationService.cs @@ -18,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Services.Caps [CommandCmif(102)] // GetAlbumFileList0AafeAruidDeprecated(pid, u16 content_type, u64 start_time, u64 end_time, nn::applet::AppletResourceUserId) -> (u64 count, buffer) - public ResultCode GetAlbumFileList0AafeAruidDeprecated(ServiceCtx context) + public ResultCode GetAlbumFileList0AafeAruidDeprecated(ServiceCtx context) { // NOTE: ApplicationAlbumFileEntry size is 0x30. return GetAlbumFileList(context); @@ -35,18 +35,18 @@ namespace Ryujinx.HLE.HOS.Services.Caps private ResultCode GetAlbumFileList(ServiceCtx context) { ResultCode resultCode = ResultCode.Success; - ulong count = 0; + ulong count = 0; ContentType contentType = (ContentType)context.RequestData.ReadUInt16(); - ulong startTime = context.RequestData.ReadUInt64(); - ulong endTime = context.RequestData.ReadUInt64(); + ulong startTime = context.RequestData.ReadUInt64(); + ulong endTime = context.RequestData.ReadUInt64(); context.RequestData.ReadUInt16(); // Alignment. ulong appletResourceUserId = context.RequestData.ReadUInt64(); ulong applicationAlbumFileEntryPosition = context.Request.ReceiveBuff[0].Position; - ulong applicationAlbumFileEntrySize = context.Request.ReceiveBuff[0].Size; + ulong applicationAlbumFileEntrySize = context.Request.ReceiveBuff[0].Size; MemoryHelper.FillWithZeros(context.Memory, applicationAlbumFileEntryPosition, (int)applicationAlbumFileEntrySize); @@ -66,4 +66,4 @@ namespace Ryujinx.HLE.HOS.Services.Caps return resultCode; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumControlService.cs b/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumControlService.cs index b16a41224..4376c4d14 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumControlService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/IAlbumControlService.cs @@ -12,4 +12,4 @@ namespace Ryujinx.HLE.HOS.Services.Caps return context.Device.System.CaptureManager.SetShimLibraryVersion(context); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/IScreenShotApplicationService.cs b/src/Ryujinx.HLE/HOS/Services/Caps/IScreenShotApplicationService.cs index a3501286c..fb62b710d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/IScreenShotApplicationService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/IScreenShotApplicationService.cs @@ -20,14 +20,18 @@ namespace Ryujinx.HLE.HOS.Services.Caps public ResultCode SaveScreenShotEx0(ServiceCtx context) { // TODO: Use the ScreenShotAttribute. +#pragma warning disable IDE0059 // Remove unnecessary value assignment ScreenShotAttribute screenShotAttribute = context.RequestData.ReadStruct(); - uint unknown = context.RequestData.ReadUInt32(); + uint unknown = context.RequestData.ReadUInt32(); +#pragma warning restore IDE0059 ulong appletResourceUserId = context.RequestData.ReadUInt64(); - ulong pidPlaceholder = context.RequestData.ReadUInt64(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong pidPlaceholder = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 ulong screenshotDataPosition = context.Request.SendBuff[0].Position; - ulong screenshotDataSize = context.Request.SendBuff[0].Size; + ulong screenshotDataSize = context.Request.SendBuff[0].Size; byte[] screenshotData = context.Memory.GetSpan(screenshotDataPosition, (int)screenshotDataSize, true).ToArray(); @@ -43,20 +47,22 @@ namespace Ryujinx.HLE.HOS.Services.Caps public ResultCode SaveScreenShotEx1(ServiceCtx context) { // TODO: Use the ScreenShotAttribute. - ScreenShotAttribute screenShotAttribute = context.RequestData.ReadStruct(); + _ = context.RequestData.ReadStruct(); - uint unknown = context.RequestData.ReadUInt32(); + _ = context.RequestData.ReadUInt32(); ulong appletResourceUserId = context.RequestData.ReadUInt64(); - ulong pidPlaceholder = context.RequestData.ReadUInt64(); + + _ = context.RequestData.ReadUInt64(); ulong applicationDataPosition = context.Request.SendBuff[0].Position; - ulong applicationDataSize = context.Request.SendBuff[0].Size; + ulong applicationDataSize = context.Request.SendBuff[0].Size; ulong screenshotDataPosition = context.Request.SendBuff[1].Position; - ulong screenshotDataSize = context.Request.SendBuff[1].Size; + ulong screenshotDataSize = context.Request.SendBuff[1].Size; + // TODO: Parse the application data: At 0x00 it's UserData (Size of 0x400), at 0x404 it's a uint UserDataSize (Always empty for now). - byte[] applicationData = context.Memory.GetSpan(applicationDataPosition, (int)applicationDataSize).ToArray(); + _ = context.Memory.GetSpan(applicationDataPosition, (int)applicationDataSize).ToArray(); byte[] screenshotData = context.Memory.GetSpan(screenshotDataPosition, (int)screenshotDataSize, true).ToArray(); @@ -72,19 +78,20 @@ namespace Ryujinx.HLE.HOS.Services.Caps public ResultCode SaveScreenShotEx2(ServiceCtx context) { // TODO: Use the ScreenShotAttribute. - ScreenShotAttribute screenShotAttribute = context.RequestData.ReadStruct(); + _ = context.RequestData.ReadStruct(); - uint unknown = context.RequestData.ReadUInt32(); + _ = context.RequestData.ReadUInt32(); ulong appletResourceUserId = context.RequestData.ReadUInt64(); ulong userIdListPosition = context.Request.SendBuff[0].Position; - ulong userIdListSize = context.Request.SendBuff[0].Size; + ulong userIdListSize = context.Request.SendBuff[0].Size; ulong screenshotDataPosition = context.Request.SendBuff[1].Position; - ulong screenshotDataSize = context.Request.SendBuff[1].Size; + ulong screenshotDataSize = context.Request.SendBuff[1].Size; + // TODO: Parse the UserIdList. - byte[] userIdList = context.Memory.GetSpan(userIdListPosition, (int)userIdListSize).ToArray(); + _ = context.Memory.GetSpan(userIdListPosition, (int)userIdListSize).ToArray(); byte[] screenshotData = context.Memory.GetSpan(screenshotDataPosition, (int)screenshotDataSize, true).ToArray(); @@ -95,4 +102,4 @@ namespace Ryujinx.HLE.HOS.Services.Caps return resultCode; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/IScreenShotControlService.cs b/src/Ryujinx.HLE/HOS/Services/Caps/IScreenShotControlService.cs index 337fa9eec..c3e2036bb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/IScreenShotControlService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/IScreenShotControlService.cs @@ -5,4 +5,4 @@ { public IScreenShotControlService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/IScreenshotService.cs b/src/Ryujinx.HLE/HOS/Services/Caps/IScreenshotService.cs index 03703e05d..ab921e085 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/IScreenshotService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/IScreenshotService.cs @@ -5,4 +5,4 @@ namespace Ryujinx.HLE.HOS.Services.Caps { public IScreenshotService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Caps/ResultCode.cs index 2615eeda6..51a6fd8ac 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/ResultCode.cs @@ -2,17 +2,17 @@ { enum ResultCode { - ModuleId = 206, + ModuleId = 206, ErrorCodeShift = 9, Success = 0, - InvalidArgument = (2 << ErrorCodeShift) | ModuleId, - ShimLibraryVersionAlreadySet = (7 << ErrorCodeShift) | ModuleId, - OutOfRange = (8 << ErrorCodeShift) | ModuleId, - InvalidContentType = (14 << ErrorCodeShift) | ModuleId, - NullOutputBuffer = (141 << ErrorCodeShift) | ModuleId, - NullInputBuffer = (142 << ErrorCodeShift) | ModuleId, - BlacklistedPid = (822 << ErrorCodeShift) | ModuleId + InvalidArgument = (2 << ErrorCodeShift) | ModuleId, + ShimLibraryVersionAlreadySet = (7 << ErrorCodeShift) | ModuleId, + OutOfRange = (8 << ErrorCodeShift) | ModuleId, + InvalidContentType = (14 << ErrorCodeShift) | ModuleId, + NullOutputBuffer = (141 << ErrorCodeShift) | ModuleId, + NullInputBuffer = (142 << ErrorCodeShift) | ModuleId, + BlacklistedPid = (822 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumFileDateTime.cs b/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumFileDateTime.cs index b9bc799c0..09c9b1760 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumFileDateTime.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumFileDateTime.cs @@ -6,11 +6,11 @@ namespace Ryujinx.HLE.HOS.Services.Caps.Types struct AlbumFileDateTime { public ushort Year; - public byte Month; - public byte Day; - public byte Hour; - public byte Minute; - public byte Second; - public byte UniqueId; + public byte Month; + public byte Day; + public byte Hour; + public byte Minute; + public byte Second; + public byte UniqueId; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumImageOrientation.cs b/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumImageOrientation.cs index 479675d67..2a1fbcac6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumImageOrientation.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumImageOrientation.cs @@ -5,6 +5,6 @@ Degrees0, Degrees90, Degrees180, - Degrees270 + Degrees270, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumStorage.cs b/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumStorage.cs index cfe6c1e04..2fe99d455 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumStorage.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/Types/AlbumStorage.cs @@ -3,6 +3,6 @@ enum AlbumStorage : byte { Nand, - Sd + Sd, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/Types/ApplicationAlbumEntry.cs b/src/Ryujinx.HLE/HOS/Services/Caps/Types/ApplicationAlbumEntry.cs index 699bb4180..701fa63d9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/Types/ApplicationAlbumEntry.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/Types/ApplicationAlbumEntry.cs @@ -6,12 +6,12 @@ namespace Ryujinx.HLE.HOS.Services.Caps.Types [StructLayout(LayoutKind.Sequential, Size = 0x20)] struct ApplicationAlbumEntry { - public ulong Size; - public ulong TitleId; + public ulong Size; + public ulong TitleId; public AlbumFileDateTime AlbumFileDateTime; - public AlbumStorage AlbumStorage; - public ContentType ContentType; - public Array5 Padding; - public byte Unknown0x1f; // Always 1 + public AlbumStorage AlbumStorage; + public ContentType ContentType; + public Array5 Padding; + public byte Unknown0x1f; // Always 1 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/Types/ContentType.cs b/src/Ryujinx.HLE/HOS/Services/Caps/Types/ContentType.cs index 5f8bb5376..56023d2ea 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/Types/ContentType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/Types/ContentType.cs @@ -5,6 +5,6 @@ Screenshot, Movie, ExtraMovie, - Unknown + Unknown, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/Types/ScreenShotAttribute.cs b/src/Ryujinx.HLE/HOS/Services/Caps/Types/ScreenShotAttribute.cs index 5528379ad..e7d8d0afd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/Types/ScreenShotAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/Types/ScreenShotAttribute.cs @@ -6,10 +6,10 @@ namespace Ryujinx.HLE.HOS.Services.Caps.Types [StructLayout(LayoutKind.Sequential, Size = 0x40)] struct ScreenShotAttribute { - public uint Unknown0x00; // Always 0 + public uint Unknown0x00; // Always 0 public AlbumImageOrientation AlbumImageOrientation; - public uint Unknown0x08; // Always 0 - public uint Unknown0x0C; // Always 1 - public Array30 Unknown0x10; // Always 0 + public uint Unknown0x08; // Always 0 + public uint Unknown0x0C; // Always 1 + public Array30 Unknown0x10; // Always 0 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Cec/ICecManager.cs b/src/Ryujinx.HLE/HOS/Services/Cec/ICecManager.cs index 71c267868..044f5b1eb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Cec/ICecManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Cec/ICecManager.cs @@ -5,4 +5,4 @@ namespace Ryujinx.HLE.HOS.Services.Cec { public ICecManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/CommandCmifAttribute.cs b/src/Ryujinx.HLE/HOS/Services/CommandCmifAttribute.cs index 3b3279ab6..5b4f30da9 100644 --- a/src/Ryujinx.HLE/HOS/Services/CommandCmifAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Services/CommandCmifAttribute.cs @@ -9,4 +9,4 @@ namespace Ryujinx.HLE.HOS.Services public CommandCmifAttribute(int id) => Id = id; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/DummyService.cs b/src/Ryujinx.HLE/HOS/Services/DummyService.cs index d69441a3a..838a9018e 100644 --- a/src/Ryujinx.HLE/HOS/Services/DummyService.cs +++ b/src/Ryujinx.HLE/HOS/Services/DummyService.cs @@ -9,4 +9,4 @@ ServiceName = serviceName; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ectx/IReaderForSystem.cs b/src/Ryujinx.HLE/HOS/Services/Ectx/IReaderForSystem.cs index 52fe87024..09f02fc4b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ectx/IReaderForSystem.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ectx/IReaderForSystem.cs @@ -5,4 +5,4 @@ { public IReaderForSystem(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ectx/IWriterForApplication.cs b/src/Ryujinx.HLE/HOS/Services/Ectx/IWriterForApplication.cs index 9401a6d71..a61fca553 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ectx/IWriterForApplication.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ectx/IWriterForApplication.cs @@ -5,4 +5,4 @@ { public IWriterForApplication(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ectx/IWriterForSystem.cs b/src/Ryujinx.HLE/HOS/Services/Ectx/IWriterForSystem.cs index 621ec777d..30c22d1fc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ectx/IWriterForSystem.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ectx/IWriterForSystem.cs @@ -5,4 +5,4 @@ { public IWriterForSystem(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Erpt/IContext.cs b/src/Ryujinx.HLE/HOS/Services/Erpt/IContext.cs index 9a689172b..eadd3ea8b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Erpt/IContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Erpt/IContext.cs @@ -5,4 +5,4 @@ { public IContext(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Erpt/ISession.cs b/src/Ryujinx.HLE/HOS/Services/Erpt/ISession.cs index 6397afae8..b43cb30a2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Erpt/ISession.cs +++ b/src/Ryujinx.HLE/HOS/Services/Erpt/ISession.cs @@ -5,4 +5,4 @@ { public ISession(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Es/IETicketService.cs b/src/Ryujinx.HLE/HOS/Services/Es/IETicketService.cs index 34be7bdd8..ced213f02 100644 --- a/src/Ryujinx.HLE/HOS/Services/Es/IETicketService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Es/IETicketService.cs @@ -5,4 +5,4 @@ { public IETicketService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Eupld/IControl.cs b/src/Ryujinx.HLE/HOS/Services/Eupld/IControl.cs index dd8705e66..4b069c60a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Eupld/IControl.cs +++ b/src/Ryujinx.HLE/HOS/Services/Eupld/IControl.cs @@ -5,4 +5,4 @@ { public IControl(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Eupld/IRequest.cs b/src/Ryujinx.HLE/HOS/Services/Eupld/IRequest.cs index 850978789..e14e4df4d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Eupld/IRequest.cs +++ b/src/Ryujinx.HLE/HOS/Services/Eupld/IRequest.cs @@ -5,4 +5,4 @@ { public IRequest(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fatal/IPrivateService.cs b/src/Ryujinx.HLE/HOS/Services/Fatal/IPrivateService.cs index eb2c95534..4cb3a2c18 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fatal/IPrivateService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fatal/IPrivateService.cs @@ -5,4 +5,4 @@ { public IPrivateService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fatal/IService.cs b/src/Ryujinx.HLE/HOS/Services/Fatal/IService.cs index aaa5c873a..a62d633e2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fatal/IService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fatal/IService.cs @@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Services.Fatal public ResultCode ThrowFatal(ServiceCtx context) { ResultCode resultCode = (ResultCode)context.RequestData.ReadUInt64(); - ulong pid = context.Request.HandleDesc.PId; + ulong pid = context.Request.HandleDesc.PId; return ThrowFatalWithCpuContextImpl(context, resultCode, pid, FatalPolicy.ErrorReportAndErrorScreen, null); } @@ -25,9 +25,9 @@ namespace Ryujinx.HLE.HOS.Services.Fatal // ThrowFatalWithPolicy(u64 result_code, u32 fatal_policy, u64 pid) public ResultCode ThrowFatalWithPolicy(ServiceCtx context) { - ResultCode resultCode = (ResultCode)context.RequestData.ReadUInt64(); + ResultCode resultCode = (ResultCode)context.RequestData.ReadUInt64(); FatalPolicy fatalPolicy = (FatalPolicy)context.RequestData.ReadUInt32(); - ulong pid = context.Request.HandleDesc.PId; + ulong pid = context.Request.HandleDesc.PId; return ThrowFatalWithCpuContextImpl(context, resultCode, pid, fatalPolicy, null); } @@ -36,12 +36,12 @@ namespace Ryujinx.HLE.HOS.Services.Fatal // ThrowFatalWithCpuContext(u64 result_code, u32 fatal_policy, u64 pid, buffer cpu_context) public ResultCode ThrowFatalWithCpuContext(ServiceCtx context) { - ResultCode resultCode = (ResultCode)context.RequestData.ReadUInt64(); + ResultCode resultCode = (ResultCode)context.RequestData.ReadUInt64(); FatalPolicy fatalPolicy = (FatalPolicy)context.RequestData.ReadUInt32(); - ulong pid = context.Request.HandleDesc.PId; + ulong pid = context.Request.HandleDesc.PId; ulong cpuContextPosition = context.Request.SendBuff[0].Position; - ulong cpuContextSize = context.Request.SendBuff[0].Size; + ulong cpuContextSize = context.Request.SendBuff[0].Size; ReadOnlySpan cpuContextData = context.Memory.GetSpan(cpuContextPosition, (int)cpuContextSize); @@ -50,7 +50,7 @@ namespace Ryujinx.HLE.HOS.Services.Fatal private ResultCode ThrowFatalWithCpuContextImpl(ServiceCtx context, ResultCode resultCode, ulong pid, FatalPolicy fatalPolicy, ReadOnlySpan cpuContext) { - StringBuilder errorReport = new StringBuilder(); + StringBuilder errorReport = new(); errorReport.AppendLine(); errorReport.AppendLine("ErrorReport log:"); @@ -144,4 +144,4 @@ namespace Ryujinx.HLE.HOS.Services.Fatal return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fatal/Types/CpuContext32.cs b/src/Ryujinx.HLE/HOS/Services/Fatal/Types/CpuContext32.cs index 5c0b116bc..5eb1406a1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fatal/Types/CpuContext32.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fatal/Types/CpuContext32.cs @@ -22,4 +22,4 @@ namespace Ryujinx.HLE.HOS.Services.Fatal.Types public uint StartAddress; public uint RegisterSetFlags; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fatal/Types/CpuContext64.cs b/src/Ryujinx.HLE/HOS/Services/Fatal/Types/CpuContext64.cs index 24829a78a..58fd3c4ac 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fatal/Types/CpuContext64.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fatal/Types/CpuContext64.cs @@ -19,6 +19,6 @@ namespace Ryujinx.HLE.HOS.Services.Fatal.Types public Array32 StackTrace; public ulong StartAddress; public ulong RegisterSetFlags; - public uint StackTraceSize; + public uint StackTraceSize; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fatal/Types/FatalPolicy.cs b/src/Ryujinx.HLE/HOS/Services/Fatal/Types/FatalPolicy.cs index fe55cf12b..f536d17d3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fatal/Types/FatalPolicy.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fatal/Types/FatalPolicy.cs @@ -4,6 +4,6 @@ { ErrorReportAndErrorScreen, ErrorReport, - ErrorScreen + ErrorScreen, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/IServiceCreator.cs b/src/Ryujinx.HLE/HOS/Services/Friend/IServiceCreator.cs index d5258a824..3f15f3fc6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/IServiceCreator.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/IServiceCreator.cs @@ -11,7 +11,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend [Service("friend:v", FriendServicePermissionLevel.Viewer)] class IServiceCreator : IpcService { - private FriendServicePermissionLevel _permissionLevel; + private readonly FriendServicePermissionLevel _permissionLevel; public IServiceCreator(ServiceCtx context, FriendServicePermissionLevel permissionLevel) { @@ -52,4 +52,4 @@ namespace Ryujinx.HLE.HOS.Services.Friend return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ResultCode.cs index 3e66e8733..82462b4ed 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ResultCode.cs @@ -2,13 +2,13 @@ { enum ResultCode { - ModuleId = 121, + ModuleId = 121, ErrorCodeShift = 9, Success = 0, - InvalidArgument = (2 << ErrorCodeShift) | ModuleId, - InternetRequestDenied = (6 << ErrorCodeShift) | ModuleId, - NotificationQueueEmpty = (15 << ErrorCodeShift) | ModuleId + InvalidArgument = (2 << ErrorCodeShift) | ModuleId, + InternetRequestDenied = (6 << ErrorCodeShift) | ModuleId, + NotificationQueueEmpty = (15 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/Friend.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/Friend.cs index 87f54bf3e..e727cafbb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/Friend.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/Friend.cs @@ -6,8 +6,8 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService [StructLayout(LayoutKind.Sequential, Pack = 0x8, Size = 0x200, CharSet = CharSet.Ansi)] struct Friend { - public UserId UserId; - public long NetworkUserId; + public UserId UserId; + public long NetworkUserId; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x21)] public string Nickname; @@ -21,9 +21,9 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService public bool IsNew; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x6)] - char[] Unknown; + readonly char[] Unknown; [MarshalAs(UnmanagedType.I1)] public bool IsValid; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/FriendFilter.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/FriendFilter.cs index 261bf7bf0..6f10a7579 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/FriendFilter.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/FriendFilter.cs @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService public long PresenceGroupId; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/PresenceStatus.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/PresenceStatus.cs index df2e65257..0271e61a4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/PresenceStatus.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/PresenceStatus.cs @@ -4,6 +4,6 @@ { Offline, Online, - OnlinePlay + OnlinePlay, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/PresenceStatusFilter.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/PresenceStatusFilter.cs index 24da7fd33..5949b8f64 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/PresenceStatusFilter.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/PresenceStatusFilter.cs @@ -5,6 +5,6 @@ None, Online, OnlinePlay, - OnlineOrOnlinePlay + OnlineOrOnlinePlay, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/UserPresence.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/UserPresence.cs index d36b3f310..9769e1609 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/UserPresence.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/FriendService/Types/UserPresence.cs @@ -8,8 +8,8 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService [StructLayout(LayoutKind.Sequential, Pack = 0x8)] struct UserPresence { - public UserId UserId; - public long LastTimeOnlineTimestamp; + public UserId UserId; + public long LastTimeOnlineTimestamp; public PresenceStatus Status; [MarshalAs(UnmanagedType.I1)] @@ -26,9 +26,9 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService public const int Size = 0xC0; } - public override string ToString() + public readonly override string ToString() { return $"UserPresence {{ UserId: {UserId}, LastTimeOnlineTimestamp: {LastTimeOnlineTimestamp}, Status: {Status} }}"; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IDaemonSuspendSessionService.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IDaemonSuspendSessionService.cs index 42b34312c..3b1601abb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IDaemonSuspendSessionService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IDaemonSuspendSessionService.cs @@ -2,11 +2,13 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator { class IDaemonSuspendSessionService : IpcService { - private FriendServicePermissionLevel PermissionLevel; +#pragma warning disable IDE0052 // Remove unread private member + private readonly FriendServicePermissionLevel _permissionLevel; +#pragma warning restore IDE0052 public IDaemonSuspendSessionService(FriendServicePermissionLevel permissionLevel) { - PermissionLevel = permissionLevel; + _permissionLevel = permissionLevel; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs index 2858aa468..f084fad11 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs @@ -15,8 +15,10 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator { class IFriendService : IpcService { - private FriendServicePermissionLevel _permissionLevel; - private KEvent _completionEvent; +#pragma warning disable IDE0052 // Remove unread private member + private readonly FriendServicePermissionLevel _permissionLevel; +#pragma warning restore IDE0052 + private KEvent _completionEvent; public IFriendService(FriendServicePermissionLevel permissionLevel) { @@ -27,10 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator // GetCompletionEvent() -> handle public ResultCode GetCompletionEvent(ServiceCtx context) { - if (_completionEvent == null) - { - _completionEvent = new KEvent(context.Device.System.KernelContext); - } + _completionEvent ??= new KEvent(context.Device.System.KernelContext); if (context.Process.HandleTable.GenerateHandle(_completionEvent.ReadableEvent, out int completionEventHandle) != Result.Success) { @@ -62,7 +61,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator // Padding context.RequestData.ReadInt32(); - UserId userId = context.RequestData.ReadStruct(); + UserId userId = context.RequestData.ReadStruct(); FriendFilter filter = context.RequestData.ReadStruct(); // Pid placeholder @@ -101,7 +100,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator // Padding context.RequestData.ReadInt32(); - UserId userId = context.RequestData.ReadStruct(); + UserId userId = context.RequestData.ReadStruct(); FriendFilter filter = context.RequestData.ReadStruct(); // Pid placeholder @@ -115,7 +114,8 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator // There are no friends online, so we return 0 because the nn::account::NetworkServiceAccountId array is empty. context.ResponseData.Write(0); - Logger.Stub?.PrintStub(LogClass.ServiceFriend, new { + Logger.Stub?.PrintStub(LogClass.ServiceFriend, new + { UserId = userId.ToString(), offset, filter.PresenceStatus, @@ -233,7 +233,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator context.RequestData.ReadInt64(); ulong position = context.Request.PtrBuff[0].Position; - ulong size = context.Request.PtrBuff[0].Size; + ulong size = context.Request.PtrBuff[0].Size; ReadOnlySpan userPresenceInputArray = MemoryMarshal.Cast(context.Memory.GetSpan(position, (int)size)); @@ -251,8 +251,8 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator // nn::friends::GetPlayHistoryRegistrationKey(b8 unknown, nn::account::Uid) -> buffer public ResultCode GetPlayHistoryRegistrationKey(ServiceCtx context) { - bool unknownBool = context.RequestData.ReadBoolean(); - UserId userId = context.RequestData.ReadStruct(); + bool unknownBool = context.RequestData.ReadBoolean(); + UserId userId = context.RequestData.ReadStruct(); context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x40UL); @@ -274,18 +274,18 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator // Then it checks if an Uuid is already stored for the UserId, if not it generates a random Uuid. // And store it in the savedata 8000000000000080 in the friends:/uid.bin file. - Array16 randomGuid = new Array16(); + Array16 randomGuid = new(); Guid.NewGuid().ToByteArray().AsSpan().CopyTo(randomGuid.AsSpan()); - PlayHistoryRegistrationKey playHistoryRegistrationKey = new PlayHistoryRegistrationKey + PlayHistoryRegistrationKey playHistoryRegistrationKey = new() { - Type = 0x101, - KeyIndex = (byte)(randomBytes[0] & 7), - UserIdBool = 0, // TODO: Find it. + Type = 0x101, + KeyIndex = (byte)(randomBytes[0] & 7), + UserIdBool = 0, // TODO: Find it. UnknownBool = (byte)(unknownBool ? 1 : 0), // TODO: Find it. - Reserved = new Array11(), - Uuid = randomGuid + Reserved = new Array11(), + Uuid = randomGuid, }; ReadOnlySpan playHistoryRegistrationKeyBuffer = SpanHelpers.AsByteSpan(ref playHistoryRegistrationKey); @@ -303,7 +303,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator */ - context.Memory.Write(bufferPosition, playHistoryRegistrationKeyBuffer); + context.Memory.Write(bufferPosition, playHistoryRegistrationKeyBuffer); context.Memory.Write(bufferPosition + 0x20, new byte[0x20]); // HmacHash return ResultCode.Success; @@ -317,16 +317,20 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator // Pid placeholder context.RequestData.ReadInt64(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pid = context.Request.HandleDesc.PId; ulong playHistoryRegistrationKeyPosition = context.Request.PtrBuff[0].Position; - ulong PlayHistoryRegistrationKeySize = context.Request.PtrBuff[0].Size; + ulong playHistoryRegistrationKeySize = context.Request.PtrBuff[0].Size; ulong inAppScreenName1Position = context.Request.PtrBuff[1].Position; - ulong inAppScreenName1Size = context.Request.PtrBuff[1].Size; +#pragma warning restore IDE0059 + ulong inAppScreenName1Size = context.Request.PtrBuff[1].Size; +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong inAppScreenName2Position = context.Request.PtrBuff[2].Position; - ulong inAppScreenName2Size = context.Request.PtrBuff[2].Size; +#pragma warning restore IDE0059 + ulong inAppScreenName2Size = context.Request.PtrBuff[2].Size; if (userId.IsNull || inAppScreenName1Size > 0x48 || inAppScreenName2Size > 0x48) { @@ -334,7 +338,9 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator } // TODO: Call nn::arp::GetApplicationControlProperty here when implemented. +#pragma warning disable IDE0059 // Remove unnecessary value assignment ApplicationControlProperty controlProperty = context.Device.Processes.ActiveApplication.ApplicationControlProperties; +#pragma warning restore IDE0059 /* @@ -349,4 +355,4 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/INotificationService.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/INotificationService.cs index 505580221..8fc7a4609 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/INotificationService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/INotificationService.cs @@ -11,24 +11,24 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator { class INotificationService : DisposableIpcService { - private readonly UserId _userId; + private readonly UserId _userId; private readonly FriendServicePermissionLevel _permissionLevel; private readonly object _lock = new(); - private KEvent _notificationEvent; - private int _notificationEventHandle = 0; + private readonly KEvent _notificationEvent; + private int _notificationEventHandle = 0; - private LinkedList _notifications; + private readonly LinkedList _notifications; private bool _hasNewFriendRequest; private bool _hasFriendListUpdate; public INotificationService(ServiceCtx context, UserId userId, FriendServicePermissionLevel permissionLevel) { - _userId = userId; - _permissionLevel = permissionLevel; - _notifications = new LinkedList(); + _userId = userId; + _permissionLevel = permissionLevel; + _notifications = new LinkedList(); _notificationEvent = new KEvent(context.Device.System.KernelContext); _hasNewFriendRequest = false; @@ -106,7 +106,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator { if (!_hasFriendListUpdate) { - NotificationInfo friendListNotification = new NotificationInfo(); + NotificationInfo friendListNotification = new(); if (_notifications.Count != 0) { @@ -119,7 +119,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator if (_hasNewFriendRequest) { - NotificationInfo newFriendRequestNotification = new NotificationInfo(); + NotificationInfo newFriendRequestNotification = new(); if (_notifications.Count != 0) { @@ -153,9 +153,9 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator SignalFriendListUpdate(targetId); } - NotificationInfo newFriendRequestNotification = new NotificationInfo + NotificationInfo newFriendRequestNotification = new() { - Type = NotificationEventType.NewFriendRequest + Type = NotificationEventType.NewFriendRequest, }; _notifications.AddLast(newFriendRequestNotification); @@ -175,4 +175,4 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/NotificationEventHandler.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/NotificationEventHandler.cs index 383ad006e..f0970d166 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/NotificationEventHandler.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/NotificationEventHandler.cs @@ -4,23 +4,20 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService { public sealed class NotificationEventHandler { - private static NotificationEventHandler instance; - private static object instanceLock = new object(); + private static NotificationEventHandler _instance; + private static readonly object _instanceLock = new(); - private INotificationService[] _registry; + private readonly INotificationService[] _registry; public static NotificationEventHandler Instance { get { - lock (instanceLock) + lock (_instanceLock) { - if (instance == null) - { - instance = new NotificationEventHandler(); - } + _instance ??= new NotificationEventHandler(); - return instance; + return _instance; } } } @@ -61,10 +58,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService { for (int i = 0; i < _registry.Length; i++) { - if (_registry[i] != null) - { - _registry[i].SignalFriendListUpdate(targetId); - } + _registry[i]?.SignalFriendListUpdate(targetId); } } @@ -73,11 +67,8 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService { for (int i = 0; i < _registry.Length; i++) { - if (_registry[i] != null) - { - _registry[i].SignalNewFriendRequest(targetId); - } + _registry[i]?.SignalNewFriendRequest(targetId); } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/Types/NotificationEventType.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/Types/NotificationEventType.cs index 5136ae8a6..d7f3f55d2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/Types/NotificationEventType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/Types/NotificationEventType.cs @@ -2,8 +2,8 @@ { enum NotificationEventType : uint { - Invalid = 0x0, + Invalid = 0x0, FriendListUpdate = 0x1, - NewFriendRequest = 0x65 + NewFriendRequest = 0x65, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/Types/NotificationInfo.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/Types/NotificationInfo.cs index e710bf064..1073c47d3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/Types/NotificationInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/NotificationService/Types/NotificationInfo.cs @@ -10,4 +10,4 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService private Array4 _padding; public long NetworkUserIdPlaceholder; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/Types/FriendServicePermissionLevel.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/Types/FriendServicePermissionLevel.cs index 12a3d42fe..bf7d1bd32 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/Types/FriendServicePermissionLevel.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/Types/FriendServicePermissionLevel.cs @@ -5,15 +5,15 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator [Flags] enum FriendServicePermissionLevel { - UserMask = 1, - ViewerMask = 2, + UserMask = 1, + ViewerMask = 2, ManagerMask = 4, - SystemMask = 8, + SystemMask = 8, Administrator = -1, - User = UserMask, - Viewer = UserMask | ViewerMask, - Manager = UserMask | ViewerMask | ManagerMask, - System = UserMask | SystemMask + User = UserMask, + Viewer = UserMask | ViewerMask, + Manager = UserMask | ViewerMask | ManagerMask, + System = UserMask | SystemMask, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/Types/PlayHistoryRegistrationKey.cs b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/Types/PlayHistoryRegistrationKey.cs index 32d962c11..aaeef0593 100644 --- a/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/Types/PlayHistoryRegistrationKey.cs +++ b/src/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/Types/PlayHistoryRegistrationKey.cs @@ -6,10 +6,10 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator [StructLayout(LayoutKind.Sequential, Size = 0x20)] struct PlayHistoryRegistrationKey { - public ushort Type; - public byte KeyIndex; - public byte UserIdBool; - public byte UnknownBool; + public ushort Type; + public byte KeyIndex; + public byte UserIdBool; + public byte UnknownBool; public Array11 Reserved; public Array16 Uuid; } diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/FileSystemProxyHelper.cs b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/FileSystemProxyHelper.cs index ba924db83..599025e3b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/FileSystemProxyHelper.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/FileSystemProxyHelper.cs @@ -25,7 +25,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy try { - LocalStorage storage = new LocalStorage(pfsPath, FileAccess.Read, FileMode.Open); + LocalStorage storage = new(pfsPath, FileAccess.Read, FileMode.Open); using SharedRef nsp = new(new PartitionFileSystem(storage)); ImportTitleKeysFromNsp(nsp.Get, context.Device.System.KeySet); @@ -48,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy try { - Nca nca = new Nca(context.Device.System.KeySet, ncaStorage); + Nca nca = new(context.Device.System.KeySet, ncaStorage); if (!nca.SectionExists(NcaSectionType.Data)) { @@ -83,14 +83,14 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy if (archivePath.Extension == ".nsp" && File.Exists(archivePath.FullName)) { - FileStream pfsFile = new FileStream( + FileStream pfsFile = new( archivePath.FullName.TrimEnd(Path.DirectorySeparatorChar), FileMode.Open, FileAccess.Read); try { - PartitionFileSystem nsp = new PartitionFileSystem(pfsFile.AsStorage()); + PartitionFileSystem nsp = new(pfsFile.AsStorage()); ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet); @@ -125,7 +125,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy if (result.IsSuccess()) { - Ticket ticket = new Ticket(ticketFile.Get.AsStream()); + Ticket ticket = new(ticketFile.Get.AsStream()); var titleKey = ticket.GetTitleKey(keySet); if (titleKey != null) diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs index b97594498..70d3a6bd8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs @@ -20,14 +20,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy ulong bufferAddress = context.Request.ReceiveBuff[0].Position; ulong bufferLen = context.Request.ReceiveBuff[0].Size; - using (var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true)) - { - Result result = _baseDirectory.Get.Read(out long entriesRead, new OutBuffer(region.Memory.Span)); + using var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true); + Result result = _baseDirectory.Get.Read(out long entriesRead, new OutBuffer(region.Memory.Span)); - context.ResponseData.Write(entriesRead); + context.ResponseData.Write(entriesRead); - return (ResultCode)result.Value; - } + return (ResultCode)result.Value; } [CommandCmif(1)] diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs index 4bc58ae5f..dcc34a754 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs @@ -26,16 +26,14 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); - long size = context.RequestData.ReadInt64(); + long size = context.RequestData.ReadInt64(); - using (var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true)) - { - Result result = _baseFile.Get.Read(out long bytesRead, offset, new OutBuffer(region.Memory.Span), size, readOption); + using var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true); + Result result = _baseFile.Get.Read(out long bytesRead, offset, new OutBuffer(region.Memory.Span), size, readOption); - context.ResponseData.Write(bytesRead); + context.ResponseData.Write(bytesRead); - return (ResultCode)result.Value; - } + return (ResultCode)result.Value; } [CommandCmif(1)] @@ -48,7 +46,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); - long size = context.RequestData.ReadInt64(); + long size = context.RequestData.ReadInt64(); byte[] data = new byte[context.Request.SendBuff[0].Size]; @@ -92,4 +90,4 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFileSystem.cs b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFileSystem.cs index 9effa79dc..4c5c56240 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFileSystem.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFileSystem.cs @@ -115,7 +115,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy if (result.IsSuccess()) { - IFile fileInterface = new IFile(ref file.Ref); + IFile fileInterface = new(ref file.Ref); MakeObject(context, fileInterface); } @@ -136,7 +136,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy if (result.IsSuccess()) { - IDirectory dirInterface = new IDirectory(ref dir.Ref); + IDirectory dirInterface = new(ref dir.Ref); MakeObject(context, dirInterface); } @@ -210,4 +210,4 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IStorage.cs b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IStorage.cs index 54c7b800b..4299a6c74 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IStorage.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IStorage.cs @@ -1,7 +1,6 @@ using LibHac; using LibHac.Common; using LibHac.Sf; -using Ryujinx.HLE.HOS.Ipc; namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy { @@ -19,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy public ResultCode Read(ServiceCtx context) { ulong offset = context.RequestData.ReadUInt64(); - ulong size = context.RequestData.ReadUInt64(); + ulong size = context.RequestData.ReadUInt64(); if (context.Request.ReceiveBuff.Count > 0) { @@ -32,12 +31,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy size = bufferLen; } - using (var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true)) - { - Result result = _baseStorage.Get.Read((long)offset, new OutBuffer(region.Memory.Span), (long)size); + using var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true); + Result result = _baseStorage.Get.Read((long)offset, new OutBuffer(region.Memory.Span), (long)size); - return (ResultCode)result.Value; - } + return (ResultCode)result.Value; } return ResultCode.Success; @@ -62,4 +59,4 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs b/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs index e961e9b18..644e1a17a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs @@ -18,7 +18,6 @@ using static Ryujinx.HLE.Utilities.StringUtils; using GameCardHandle = System.UInt32; using IFileSystem = LibHac.FsSrv.Sf.IFileSystem; using IStorage = LibHac.FsSrv.Sf.IStorage; -using RightsId = LibHac.Fs.RightsId; namespace Ryujinx.HLE.HOS.Services.Fs { @@ -48,14 +47,16 @@ namespace Ryujinx.HLE.HOS.Services.Fs // -> object contentFs public ResultCode OpenFileSystemWithId(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment FileSystemType fileSystemType = (FileSystemType)context.RequestData.ReadInt32(); ulong titleId = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 string switchPath = ReadUtf8String(context); - string fullPath = context.Device.FileSystem.SwitchPathToSystemPath(switchPath); + string fullPath = FileSystem.VirtualFileSystem.SwitchPathToSystemPath(switchPath); if (!File.Exists(fullPath)) { - if (fullPath.Contains(".")) + if (fullPath.Contains('.')) { ResultCode result = FileSystemProxyHelper.OpenFileSystemFromInternalFile(context, fullPath, out FileSystemProxy.IFileSystem fileSystem); @@ -70,7 +71,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs return ResultCode.PathDoesNotExist; } - FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read); + FileStream fileStream = new(fullPath, FileMode.Open, FileAccess.Read); string extension = System.IO.Path.GetExtension(fullPath); if (extension == ".nca") @@ -109,7 +110,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenBisFileSystem(ref fileSystem.Ref, in path, bisPartitionId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -124,7 +128,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var storage = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenBisStorage(ref storage.Ref, bisPartitionId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IStorage(ref storage.Ref)); @@ -145,7 +152,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenSdCardFileSystem(ref fileSystem.Ref); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -221,7 +231,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs public ResultCode IsExFatSupported(ServiceCtx context) { Result result = _baseFileSystemProxy.Get.IsExFatSupported(out bool isSupported); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(isSupported); @@ -247,7 +260,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var storage = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenGameCardStorage(ref storage.Ref, handle, partitionId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IStorage(ref storage.Ref)); @@ -263,7 +279,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenGameCardFileSystem(ref fileSystem.Ref, handle, partitionId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -298,7 +317,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs ushort index = context.RequestData.ReadUInt16(); Result result = _baseFileSystemProxy.Get.GetCacheStorageSize(out long dataSize, out long journalSize, index); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(dataSize); context.ResponseData.Write(journalSize); @@ -338,7 +360,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref, spaceId, in attribute); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -354,7 +379,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenSaveDataFileSystemBySystemSaveDataId(ref fileSystem.Ref, spaceId, in attribute); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -370,7 +398,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenReadOnlySaveDataFileSystem(ref fileSystem.Ref, spaceId, in attribute); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -388,7 +419,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs context.Memory.Read(context.Request.ReceiveBuff[0].Position, extraDataBuffer); Result result = _baseFileSystemProxy.Get.ReadSaveDataFileSystemExtraDataBySaveDataSpaceId(new OutBuffer(extraDataBuffer), spaceId, saveDataId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.Memory.Write(context.Request.ReceiveBuff[0].Position, extraDataBuffer); @@ -405,7 +439,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs context.Memory.Read(context.Request.ReceiveBuff[0].Position, extraDataBuffer); Result result = _baseFileSystemProxy.Get.ReadSaveDataFileSystemExtraData(new OutBuffer(extraDataBuffer), saveDataId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.Memory.Write(context.Request.ReceiveBuff[0].Position, extraDataBuffer); @@ -432,7 +469,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var infoReader = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenSaveDataInfoReader(ref infoReader.Ref); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new ISaveDataInfoReader(ref infoReader.Ref)); @@ -447,7 +487,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var infoReader = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenSaveDataInfoReaderBySaveDataSpaceId(ref infoReader.Ref, spaceId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new ISaveDataInfoReader(ref infoReader.Ref)); @@ -461,7 +504,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var infoReader = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenSaveDataInfoReaderOnlyCacheStorage(ref infoReader.Ref); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new ISaveDataInfoReader(ref infoReader.Ref)); @@ -477,7 +523,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenSaveDataInternalStorageFileSystem(ref fileSystem.Ref, spaceId, saveDataId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -518,14 +567,15 @@ namespace Ryujinx.HLE.HOS.Services.Fs ulong bufferAddress = context.Request.ReceiveBuff[0].Position; ulong bufferLen = context.Request.ReceiveBuff[0].Size; - using (var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true)) + using var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true); + Result result = _baseFileSystemProxy.Get.FindSaveDataWithFilter(out long count, new OutBuffer(region.Memory.Span), spaceId, in filter); + if (result.IsFailure()) { - Result result = _baseFileSystemProxy.Get.FindSaveDataWithFilter(out long count, new OutBuffer(region.Memory.Span), spaceId, in filter); - if (result.IsFailure()) return (ResultCode)result.Value; - - context.ResponseData.Write(count); + return (ResultCode)result.Value; } + context.ResponseData.Write(count); + return ResultCode.Success; } @@ -537,7 +587,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var infoReader = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenSaveDataInfoReaderWithFilter(ref infoReader.Ref, spaceId, in filter); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new ISaveDataInfoReader(ref infoReader.Ref)); @@ -554,7 +607,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs context.Memory.Read(context.Request.ReceiveBuff[0].Position, outputBuffer); Result result = _baseFileSystemProxy.Get.ReadSaveDataFileSystemExtraDataBySaveDataAttribute(new OutBuffer(outputBuffer), spaceId, in attribute); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.Memory.Write(context.Request.ReceiveBuff[0].Position, outputBuffer); @@ -589,7 +645,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs context.Memory.Read(context.Request.ReceiveBuff[0].Position, outputBuffer); Result result = _baseFileSystemProxy.Get.ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(new OutBuffer(outputBuffer), spaceId, in attribute, new InBuffer(maskBuffer)); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.Memory.Write(context.Request.ReceiveBuff[0].Position, outputBuffer); @@ -605,7 +664,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var file = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenSaveDataMetaFile(ref file.Ref, spaceId, in attribute, metaType); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new IFile(ref file.Ref)); @@ -623,7 +685,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs context.Memory.Read(context.Request.ReceiveBuff[0].Position, outputBuffer); Result result = _baseFileSystemProxy.Get.ListAccessibleSaveDataOwnerId(out int readCount, new OutBuffer(outputBuffer), programId, startIndex, bufferCount); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(readCount); @@ -637,7 +702,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenImageDirectoryFileSystem(ref fileSystem.Ref, directoryId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -651,7 +719,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenBaseFileSystem(ref fileSystem.Ref, fileSystemId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -665,7 +736,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenContentStorageFileSystem(ref fileSystem.Ref, contentStorageId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -679,7 +753,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenCloudBackupWorkStorageFileSystem(ref fileSystem.Ref, storageId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -693,7 +770,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenCustomStorageFileSystem(ref fileSystem.Ref, customStorageId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -718,7 +798,9 @@ namespace Ryujinx.HLE.HOS.Services.Fs public ResultCode OpenDataStorageByDataId(ServiceCtx context) { StorageId storageId = (StorageId)context.RequestData.ReadByte(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment byte[] padding = context.RequestData.ReadBytes(7); +#pragma warning restore IDE0059 ulong titleId = context.RequestData.ReadUInt64(); // We do a mitm here to find if the request is for an AOC. @@ -750,7 +832,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs if (installedStorage != StorageId.None) { string contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, contentType); - string installPath = context.Device.FileSystem.SwitchPathToSystemPath(contentPath); + string installPath = FileSystem.VirtualFileSystem.SwitchPathToSystemPath(contentPath); if (!string.IsNullOrWhiteSpace(installPath)) { @@ -761,7 +843,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs try { LibHac.Fs.IStorage ncaStorage = new LocalStorage(ncaPath, FileAccess.Read, FileMode.Open); - Nca nca = new Nca(context.Device.System.KeySet, ncaStorage); + Nca nca = new(context.Device.System.KeySet, ncaStorage); LibHac.Fs.IStorage romfsStorage = nca.OpenStorage(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel); using var sharedStorage = new SharedRef(romfsStorage); using var sfStorage = new SharedRef(new StorageInterfaceAdapter(ref sharedStorage.Ref)); @@ -829,7 +911,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var deviceOperator = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new IDeviceOperator(ref deviceOperator.Ref)); @@ -843,7 +928,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs long journalSize = context.RequestData.ReadInt64(); Result result = _baseFileSystemProxy.Get.QuerySaveDataTotalSize(out long totalSize, dataSize, journalSize); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(totalSize); @@ -907,7 +995,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs ProgramId programId = context.RequestData.ReadStruct(); Result result = _baseFileSystemProxy.Get.GetRightsId(out RightsId rightsId, programId, storageId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.WriteStruct(rightsId); @@ -935,7 +1026,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs ref readonly var path = ref FileSystemProxyHelper.GetFspPath(context); Result result = _baseFileSystemProxy.Get.GetRightsIdByPath(out RightsId rightsId, in path); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.WriteStruct(rightsId); @@ -948,7 +1042,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs ref readonly var path = ref FileSystemProxyHelper.GetFspPath(context); Result result = _baseFileSystemProxy.Get.GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, in path); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(keyGeneration); context.ResponseData.BaseStream.Seek(7, SeekOrigin.Current); @@ -973,7 +1070,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs SaveDataSpaceId spaceId = context.RequestData.ReadStruct(); Result result = _baseFileSystemProxy.Get.GetFreeSpaceSizeForSaveData(out long freeSpaceSize, spaceId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(freeSpaceSize); @@ -1008,7 +1108,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs ulong saveDataId = context.RequestData.ReadUInt64(); Result result = _baseFileSystemProxy.Get.QuerySaveDataInternalStorageTotalSize(out long size, spaceId, saveDataId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(size); @@ -1022,7 +1125,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs ulong saveDataId = context.RequestData.ReadUInt64(); Result result = _baseFileSystemProxy.Get.GetSaveDataCommitId(out long commitId, spaceId, saveDataId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(commitId); @@ -1059,7 +1165,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs public ResultCode IsSdCardAccessible(ServiceCtx context) { Result result = _baseFileSystemProxy.Get.IsSdCardAccessible(out bool isAccessible); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(isAccessible); @@ -1072,7 +1181,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs ulong processId = context.RequestData.ReadUInt64(); Result result = _baseFileSystemProxy.Get.IsAccessFailureDetected(out bool isDetected, processId); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(isDetected); @@ -1099,7 +1211,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs public ResultCode GetAndClearErrorInfo(ServiceCtx context) { Result result = _baseFileSystemProxy.Get.GetAndClearErrorInfo(out FileSystemProxyErrorInfo errorInfo); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.WriteStruct(errorInfo); @@ -1195,7 +1310,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var fileSystem = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenRegisteredUpdatePartition(ref fileSystem.Ref); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref)); @@ -1206,7 +1324,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs public ResultCode GetAndClearMemoryReportInfo(ServiceCtx context) { Result result = _baseFileSystemProxy.Get.GetAndClearMemoryReportInfo(out MemoryReportInfo reportInfo); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.WriteStruct(reportInfo); @@ -1217,7 +1338,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs public ResultCode GetProgramIndexForAccessLog(ServiceCtx context) { Result result = _baseFileSystemProxy.Get.GetProgramIndexForAccessLog(out int programIndex, out int programCount); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(programIndex); context.ResponseData.Write(programCount); @@ -1231,7 +1355,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs FsStackUsageThreadType threadType = context.RequestData.ReadStruct(); Result result = _baseFileSystemProxy.Get.GetFsStackUsage(out uint usage, threadType); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } context.ResponseData.Write(usage); @@ -1290,7 +1417,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs using var commitManager = new SharedRef(); Result result = _baseFileSystemProxy.Get.OpenMultiCommitManager(ref commitManager.Ref); - if (result.IsFailure()) return (ResultCode)result.Value; + if (result.IsFailure()) + { + return (ResultCode)result.Value; + } MakeObject(context, new IMultiCommitManager(ref commitManager.Ref)); @@ -1305,4 +1435,4 @@ namespace Ryujinx.HLE.HOS.Services.Fs } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxyForLoader.cs b/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxyForLoader.cs index a40821b93..c3e228758 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxyForLoader.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxyForLoader.cs @@ -5,4 +5,4 @@ { public IFileSystemProxyForLoader(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/IProgramRegistry.cs b/src/Ryujinx.HLE/HOS/Services/Fs/IProgramRegistry.cs index e11eadf53..4554a053a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/IProgramRegistry.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/IProgramRegistry.cs @@ -5,4 +5,4 @@ { public IProgramRegistry(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/ISaveDataInfoReader.cs b/src/Ryujinx.HLE/HOS/Services/Fs/ISaveDataInfoReader.cs index 0611375b1..022d7b819 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/ISaveDataInfoReader.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/ISaveDataInfoReader.cs @@ -20,14 +20,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs ulong bufferAddress = context.Request.ReceiveBuff[0].Position; ulong bufferLen = context.Request.ReceiveBuff[0].Size; - using (var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true)) - { - Result result = _baseReader.Get.Read(out long readCount, new OutBuffer(region.Memory.Span)); + using var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true); + Result result = _baseReader.Get.Read(out long readCount, new OutBuffer(region.Memory.Span)); - context.ResponseData.Write(readCount); + context.ResponseData.Write(readCount); - return (ResultCode)result.Value; - } + return (ResultCode)result.Value; } protected override void Dispose(bool isDisposing) diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Fs/ResultCode.cs index 8f87142b1..e04bd7be2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/ResultCode.cs @@ -2,15 +2,15 @@ namespace Ryujinx.HLE.HOS.Services.Fs { enum ResultCode { - ModuleId = 2, + ModuleId = 2, ErrorCodeShift = 9, Success = 0, - PathDoesNotExist = (1 << ErrorCodeShift) | ModuleId, - PathAlreadyExists = (2 << ErrorCodeShift) | ModuleId, - PathAlreadyInUse = (7 << ErrorCodeShift) | ModuleId, + PathDoesNotExist = (1 << ErrorCodeShift) | ModuleId, + PathAlreadyExists = (2 << ErrorCodeShift) | ModuleId, + PathAlreadyInUse = (7 << ErrorCodeShift) | ModuleId, PartitionNotFound = (1001 << ErrorCodeShift) | ModuleId, - InvalidInput = (6001 << ErrorCodeShift) | ModuleId + InvalidInput = (6001 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/Types/FileSystemType.cs b/src/Ryujinx.HLE/HOS/Services/Fs/Types/FileSystemType.cs index f12c1661d..369df9b68 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/Types/FileSystemType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/Types/FileSystemType.cs @@ -2,11 +2,11 @@ { enum FileSystemType { - Logo = 2, - ContentControl = 3, - ContentManual = 4, - ContentMeta = 5, - ContentData = 6, - ApplicationPackage = 7 + Logo = 2, + ContentControl = 3, + ContentManual = 4, + ContentMeta = 5, + ContentData = 6, + ApplicationPackage = 7, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Grc/IGrcService.cs b/src/Ryujinx.HLE/HOS/Services/Grc/IGrcService.cs index 90646b406..131ba541c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Grc/IGrcService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Grc/IGrcService.cs @@ -5,4 +5,4 @@ { public IGrcService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Grc/IRemoteVideoTransfer.cs b/src/Ryujinx.HLE/HOS/Services/Grc/IRemoteVideoTransfer.cs index edb1d64e1..1d200ac3c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Grc/IRemoteVideoTransfer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Grc/IRemoteVideoTransfer.cs @@ -5,4 +5,4 @@ { public IRemoteVideoTransfer(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Hid.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Hid.cs index e4755f787..dbcbe1870 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Hid.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Hid.cs @@ -26,10 +26,10 @@ namespace Ryujinx.HLE.HOS.Services.Hid internal const int SharedMemEntryCount = 17; public DebugPadDevice DebugPad; - public TouchDevice Touchscreen; - public MouseDevice Mouse; + public TouchDevice Touchscreen; + public MouseDevice Mouse; public KeyboardDevice Keyboard; - public NpadDevices Npads; + public NpadDevices Npads; private static void CheckTypeSizeOrThrow(int expectedSize) { @@ -51,7 +51,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid internal Hid(in Switch device, SharedMemoryStorage storage) { - _device = device; + _device = device; _storage = storage; SharedMemory = SharedMemory.Create(); @@ -61,11 +61,11 @@ namespace Ryujinx.HLE.HOS.Services.Hid private void InitDevices() { - DebugPad = new DebugPadDevice(_device, true); + DebugPad = new DebugPadDevice(_device, true); Touchscreen = new TouchDevice(_device, true); - Mouse = new MouseDevice(_device, false); - Keyboard = new KeyboardDevice(_device, false); - Npads = new NpadDevices(_device, true); + Mouse = new MouseDevice(_device, false); + Keyboard = new KeyboardDevice(_device, false); + Npads = new NpadDevices(_device, true); } public void RefreshInputConfig(List inputConfig) @@ -86,6 +86,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid const int StickButtonThreshold = short.MaxValue / 2; ControllerKeys result = 0; +#pragma warning disable IDE0055 // Disable formatting result |= (leftStick.Dx < -StickButtonThreshold) ? ControllerKeys.LStickLeft : result; result |= (leftStick.Dx > StickButtonThreshold) ? ControllerKeys.LStickRight : result; result |= (leftStick.Dy < -StickButtonThreshold) ? ControllerKeys.LStickDown : result; @@ -95,11 +96,12 @@ namespace Ryujinx.HLE.HOS.Services.Hid result |= (rightStick.Dx > StickButtonThreshold) ? ControllerKeys.RStickRight : result; result |= (rightStick.Dy < -StickButtonThreshold) ? ControllerKeys.RStickDown : result; result |= (rightStick.Dy > StickButtonThreshold) ? ControllerKeys.RStickUp : result; +#pragma warning restore IDE0055 return result; } - internal static ulong GetTimestampTicks() + internal ulong GetTimestampTicks() { return (ulong)PerformanceCounter.ElapsedMilliseconds * 19200; } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/BaseDevice.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/BaseDevice.cs index 0e3cd18a0..a6c21fdaf 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/BaseDevice.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/BaseDevice.cs @@ -11,4 +11,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid Active = active; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/DebugPadDevice.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/DebugPadDevice.cs index e3b95390b..6b1d7af5d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/DebugPadDevice.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/DebugPadDevice.cs @@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid ref DebugPadState previousEntry = ref lifo.GetCurrentEntryRef(); - DebugPadState newState = new DebugPadState(); + DebugPadState newState = new(); if (Active) { @@ -25,4 +25,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid lifo.Write(ref newState); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/KeyboardDevice.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/KeyboardDevice.cs index 8908b74dc..0e3630f26 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/KeyboardDevice.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/KeyboardDevice.cs @@ -21,7 +21,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid ref KeyboardState previousEntry = ref lifo.GetCurrentEntryRef(); - KeyboardState newState = new KeyboardState + KeyboardState newState = new() { SamplingNumber = previousEntry.SamplingNumber + 1, }; @@ -32,4 +32,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid lifo.Write(ref newState); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/MouseDevice.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/MouseDevice.cs index 66d1b0c49..b2dd3feaf 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/MouseDevice.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/MouseDevice.cs @@ -12,8 +12,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid ref RingLifo lifo = ref _device.Hid.SharedMemory.Mouse; ref MouseState previousEntry = ref lifo.GetCurrentEntryRef(); - - MouseState newState = new MouseState() + + MouseState newState = new() { SamplingNumber = previousEntry.SamplingNumber + 1, }; @@ -33,4 +33,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid lifo.Write(ref newState); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs index edcc47d83..240933ada 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs @@ -19,22 +19,22 @@ namespace Ryujinx.HLE.HOS.Services.Hid public const int MaxControllers = 9; // Players 1-8 and Handheld private ControllerType[] _configuredTypes; - private KEvent[] _styleSetUpdateEvents; - private bool[] _supportedPlayers; - private static VibrationValue _neutralVibrationValue = new VibrationValue + private readonly KEvent[] _styleSetUpdateEvents; + private readonly bool[] _supportedPlayers; + private VibrationValue _neutralVibrationValue = new() { AmplitudeLow = 0f, FrequencyLow = 160f, AmplitudeHigh = 0f, - FrequencyHigh = 320f + FrequencyHigh = 320f, }; internal NpadJoyHoldType JoyHold { get; set; } internal bool SixAxisActive = false; // TODO: link to hidserver when implemented internal ControllerType SupportedStyleSets { get; set; } - public Dictionary> RumbleQueues = new Dictionary>(); - public Dictionary LastVibrationValues = new Dictionary(); + public Dictionary> RumbleQueues = new(); + public Dictionary LastVibrationValues = new(); public NpadDevices(Switch device, bool active = true) : base(device, active) { @@ -129,7 +129,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid if (player > PlayerIndex.Handheld) { - throw new ArgumentOutOfRangeException("Player must be Player1-8 or Handheld"); + throw new InvalidOperationException("Player must be Player1-8 or Handheld"); } if (controllerType == ControllerType.Handheld) @@ -249,6 +249,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid switch (type) { +#pragma warning disable IDE0055 // Disable formatting case ControllerType.ProController: controller.StyleSet = NpadStyleTag.FullKey; controller.DeviceType = DeviceType.FullKey; @@ -296,6 +297,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid controller.DeviceType = DeviceType.Palma; controller.AppletFooterUiType = AppletFooterUiType.None; break; +#pragma warning restore IDE0055 } _styleSetUpdateEvents[(int)player].ReadableEvent.Signal(); @@ -329,7 +331,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid { if (!Unsafe.AreSame(ref currentlyUsed, ref possiblyUnused)) { - NpadCommonState newState = new NpadCommonState(); + NpadCommonState newState = new(); WriteNewInputEntry(ref possiblyUnused, ref newState); } @@ -348,7 +350,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid { if (!Unsafe.AreSame(ref currentlyUsed, ref possiblyUnused)) { - SixAxisSensorState newState = new SixAxisSensorState(); + SixAxisSensorState newState = new(); WriteNewSixInputEntry(ref possiblyUnused, ref newState); } @@ -379,23 +381,22 @@ namespace Ryujinx.HLE.HOS.Services.Hid ref RingLifo lifo = ref GetCommonStateLifo(ref currentNpad); - NpadCommonState newState = new NpadCommonState + NpadCommonState newState = new() { - Buttons = (NpadButton)state.Buttons, + Buttons = (NpadButton)state.Buttons, AnalogStickL = new AnalogStickState { - X = state.LStick.Dx, - Y = state.LStick.Dy, + X = state.LStick.Dx, + Y = state.LStick.Dy, }, AnalogStickR = new AnalogStickState { - X = state.RStick.Dx, - Y = state.RStick.Dy, - } + X = state.RStick.Dx, + Y = state.RStick.Dy, + }, + Attributes = NpadAttribute.IsConnected, }; - newState.Attributes = NpadAttribute.IsConnected; - switch (currentNpad.StyleSet) { case NpadStyleTag.Handheld: @@ -434,7 +435,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid { ref NpadInternalState currentNpad = ref _device.Hid.SharedMemory.Npads[(int)index].InternalState; - NpadCommonState newState = new NpadCommonState(); + NpadCommonState newState = new(); WriteNewInputEntry(ref currentNpad.FullKey, ref newState); WriteNewInputEntry(ref currentNpad.Handheld, ref newState); @@ -514,33 +515,33 @@ namespace Ryujinx.HLE.HOS.Services.Hid return false; } - HidVector accel = new HidVector() + HidVector accel = new() { X = state.Accelerometer.X, Y = state.Accelerometer.Y, - Z = state.Accelerometer.Z + Z = state.Accelerometer.Z, }; - HidVector gyro = new HidVector() + HidVector gyro = new() { X = state.Gyroscope.X, Y = state.Gyroscope.Y, - Z = state.Gyroscope.Z + Z = state.Gyroscope.Z, }; - HidVector rotation = new HidVector() + HidVector rotation = new() { X = state.Rotation.X, Y = state.Rotation.Y, - Z = state.Rotation.Z + Z = state.Rotation.Z, }; - SixAxisSensorState newState = new SixAxisSensorState + SixAxisSensorState newState = new() { - Acceleration = accel, + Acceleration = accel, AngularVelocity = gyro, - Angle = rotation, - Attributes = SixAxisSensorAttribute.IsConnected + Angle = rotation, + Attributes = SixAxisSensorAttribute.IsConnected, }; state.Orientation.AsSpan().CopyTo(newState.Direction.AsSpan()); @@ -562,9 +563,10 @@ namespace Ryujinx.HLE.HOS.Services.Hid if (!needUpdateRight && !isRightPair) { - SixAxisSensorState emptyState = new SixAxisSensorState(); - - emptyState.Attributes = SixAxisSensorAttribute.IsConnected; + SixAxisSensorState emptyState = new() + { + Attributes = SixAxisSensorAttribute.IsConnected, + }; WriteNewSixInputEntry(ref currentNpad.JoyDualRightSixAxisSensor, ref emptyState); } @@ -576,9 +578,10 @@ namespace Ryujinx.HLE.HOS.Services.Hid { ref NpadInternalState currentNpad = ref _device.Hid.SharedMemory.Npads[(int)index].InternalState; - SixAxisSensorState newState = new SixAxisSensorState(); - - newState.Attributes = SixAxisSensorAttribute.IsConnected; + SixAxisSensorState newState = new() + { + Attributes = SixAxisSensorAttribute.IsConnected, + }; WriteNewSixInputEntry(ref currentNpad.FullKeySixAxisSensor, ref newState); WriteNewSixInputEntry(ref currentNpad.HandheldSixAxisSensor, ref newState); @@ -632,4 +635,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid return rumbleQueue; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/TouchDevice.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/TouchDevice.cs index bb58ee517..35ac1a16f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/TouchDevice.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/TouchDevice.cs @@ -14,9 +14,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid ref TouchScreenState previousEntry = ref lifo.GetCurrentEntryRef(); - TouchScreenState newState = new TouchScreenState + TouchScreenState newState = new() { - SamplingNumber = previousEntry.SamplingNumber + 1 + SamplingNumber = previousEntry.SamplingNumber + 1, }; if (Active) @@ -37,7 +37,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid FingerId = (uint)i, DiameterX = pi.DiameterX, DiameterY = pi.DiameterY, - RotationAngle = pi.Angle + RotationAngle = pi.Angle, }; } } @@ -45,4 +45,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid lifo.Write(ref newState); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/ControllerConfig.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/ControllerConfig.cs index 477e1a840..cba5c7b1d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/ControllerConfig.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/ControllerConfig.cs @@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid { public struct ControllerConfig { - public PlayerIndex Player; + public PlayerIndex Player; public ControllerType Type; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/GamepadInput.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/GamepadInput.cs index 633671df8..452901a08 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/GamepadInput.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/GamepadInput.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid { public struct GamepadInput { - public PlayerIndex PlayerId; - public ControllerKeys Buttons; + public PlayerIndex PlayerId; + public ControllerKeys Buttons; public JoystickPosition LStick; public JoystickPosition RStick; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/JoystickPosition.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/JoystickPosition.cs index 6df477d6c..47be8d413 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/JoystickPosition.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/JoystickPosition.cs @@ -5,4 +5,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid public int Dx; public int Dy; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/KeyboardInput.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/KeyboardInput.cs index be6857fb3..26fe980f5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/KeyboardInput.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/KeyboardInput.cs @@ -5,4 +5,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid public int Modifier; public ulong[] Keys; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/SixAxisInput.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/SixAxisInput.cs index 4dda82c72..5c5c5d8c1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/SixAxisInput.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/SixAxisInput.cs @@ -5,9 +5,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid public struct SixAxisInput { public PlayerIndex PlayerId; - public Vector3 Accelerometer; - public Vector3 Gyroscope; - public Vector3 Rotation; - public float[] Orientation; + public Vector3 Accelerometer; + public Vector3 Gyroscope; + public Vector3 Rotation; + public float[] Orientation; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/TouchPoint.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/TouchPoint.cs index 457d2b0d0..ab0c85262 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/TouchPoint.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/Types/TouchPoint.cs @@ -11,4 +11,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid public uint DiameterY; public uint Angle; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/HidUtils.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/HidUtils.cs index b98f60658..d76704b3e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/HidUtils.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/HidUtils.cs @@ -7,6 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.HidServer public static PlayerIndex GetIndexFromNpadIdType(NpadIdType npadIdType) => npadIdType switch { +#pragma warning disable IDE0055 // Disable formatting NpadIdType.Player1 => PlayerIndex.Player1, NpadIdType.Player2 => PlayerIndex.Player2, NpadIdType.Player3 => PlayerIndex.Player3, @@ -17,12 +18,14 @@ namespace Ryujinx.HLE.HOS.Services.Hid.HidServer NpadIdType.Player8 => PlayerIndex.Player8, NpadIdType.Handheld => PlayerIndex.Handheld, NpadIdType.Unknown => PlayerIndex.Unknown, - _ => throw new ArgumentOutOfRangeException(nameof(npadIdType)) + _ => throw new ArgumentOutOfRangeException(nameof(npadIdType)), +#pragma warning restore IDE0055 }; public static NpadIdType GetNpadIdTypeFromIndex(PlayerIndex index) => index switch { +#pragma warning disable IDE0055 // Disable formatting PlayerIndex.Player1 => NpadIdType.Player1, PlayerIndex.Player2 => NpadIdType.Player2, PlayerIndex.Player3 => NpadIdType.Player3, @@ -33,7 +36,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid.HidServer PlayerIndex.Player8 => NpadIdType.Player8, PlayerIndex.Handheld => NpadIdType.Handheld, PlayerIndex.Unknown => NpadIdType.Unknown, - _ => throw new ArgumentOutOfRangeException(nameof(index)) + _ => throw new ArgumentOutOfRangeException(nameof(index)), +#pragma warning restore IDE0055 }; public static bool IsValidNpadIdType(NpadIdType npadIdType) @@ -43,4 +47,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid.HidServer npadIdType == NpadIdType.Unknown; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/IActiveVibrationDeviceList.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/IActiveVibrationDeviceList.cs index 56f63e52e..93f19c915 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/IActiveVibrationDeviceList.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/IActiveVibrationDeviceList.cs @@ -8,9 +8,11 @@ namespace Ryujinx.HLE.HOS.Services.Hid.HidServer // ActivateVibrationDevice(nn::hid::VibrationDeviceHandle) public ResultCode ActivateVibrationDevice(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment int vibrationDeviceHandle = context.RequestData.ReadInt32(); +#pragma warning restore IDE0059 return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/IAppletResource.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/IAppletResource.cs index f0aaf5e36..56eb345af 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/IAppletResource.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/IAppletResource.cs @@ -7,8 +7,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid.HidServer { class IAppletResource : IpcService { - private KSharedMemory _hidSharedMem; - private int _hidSharedMemHandle; + private readonly KSharedMemory _hidSharedMem; + private int _hidSharedMemHandle; public IAppletResource(KSharedMemory hidSharedMem) { @@ -32,4 +32,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid.HidServer return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Npad/NpadHandheldActivationMode.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Npad/NpadHandheldActivationMode.cs index 0cf4a0472..02e3d803f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Npad/NpadHandheldActivationMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Npad/NpadHandheldActivationMode.cs @@ -4,6 +4,6 @@ { Dual, Single, - None + None, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Npad/NpadJoyDeviceType.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Npad/NpadJoyDeviceType.cs index 05587bfd2..f52e18f28 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Npad/NpadJoyDeviceType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Npad/NpadJoyDeviceType.cs @@ -3,6 +3,6 @@ public enum NpadJoyDeviceType { Left, - Right + Right, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/AccelerometerParameters.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/AccelerometerParameters.cs index 4fd0a1b5b..8e4d80e24 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/AccelerometerParameters.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/AccelerometerParameters.cs @@ -5,4 +5,4 @@ public float X; public float Y; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/GyroscopeZeroDriftMode.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/GyroscopeZeroDriftMode.cs index db7467fa7..659afa0df 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/GyroscopeZeroDriftMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/GyroscopeZeroDriftMode.cs @@ -4,6 +4,6 @@ { Loose, Standard, - Tight + Tight, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/SensorFusionParameters.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/SensorFusionParameters.cs index 2683ffee4..37cef783a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/SensorFusionParameters.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/SixAxis/SensorFusionParameters.cs @@ -5,4 +5,4 @@ public float RevisePower; public float ReviseRange; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceHandle.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceHandle.cs index fe50e6718..d59afe513 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceHandle.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceHandle.cs @@ -7,4 +7,4 @@ public byte Position; public byte Reserved; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDevicePosition.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDevicePosition.cs index 117451f16..19d52f9fd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDevicePosition.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDevicePosition.cs @@ -4,6 +4,6 @@ { None, Left, - Right + Right, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceType.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceType.cs index 4e5557c94..4849c3426 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceType.cs @@ -4,6 +4,6 @@ { None, LinearResonantActuator, - GcErm + GcErm, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceValue.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceValue.cs index 91a23eb7e..8ac06cb79 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceValue.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationDeviceValue.cs @@ -2,7 +2,7 @@ { public struct VibrationDeviceValue { - public VibrationDeviceType DeviceType; + public VibrationDeviceType DeviceType; public VibrationDevicePosition Position; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationValue.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationValue.cs index 38ac9ccac..c6143a013 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationValue.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidServer/Types/Vibration/VibrationValue.cs @@ -9,16 +9,26 @@ namespace Ryujinx.HLE.HOS.Services.Hid public float AmplitudeHigh; public float FrequencyHigh; - public override bool Equals(object obj) + public readonly override bool Equals(object obj) { return obj is VibrationValue value && AmplitudeLow == value.AmplitudeLow && AmplitudeHigh == value.AmplitudeHigh; } - public override int GetHashCode() + public readonly override int GetHashCode() { return HashCode.Combine(AmplitudeLow, AmplitudeHigh); } + + public static bool operator ==(VibrationValue left, VibrationValue right) + { + return left.Equals(right); + } + + public static bool operator !=(VibrationValue left, VibrationValue right) + { + return !(left == right); + } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/IHidDebugServer.cs b/src/Ryujinx.HLE/HOS/Services/Hid/IHidDebugServer.cs index adaaa0123..0d1867db5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/IHidDebugServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/IHidDebugServer.cs @@ -5,4 +5,4 @@ { public IHidDebugServer(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs b/src/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs index d508aba42..1d1b145cc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs @@ -15,8 +15,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid [Service("hid")] class IHidServer : IpcService { - private KEvent _xpadIdEvent; - private KEvent _palmaOperationCompleteEvent; + private readonly KEvent _xpadIdEvent; + private readonly KEvent _palmaOperationCompleteEvent; private int _xpadIdEventHandle; @@ -24,33 +24,33 @@ namespace Ryujinx.HLE.HOS.Services.Hid private bool _unintendedHomeButtonInputProtectionEnabled; private bool _vibrationPermitted; private bool _usbFullKeyControllerEnabled; - private bool _isFirmwareUpdateAvailableForSixAxisSensor; + private readonly bool _isFirmwareUpdateAvailableForSixAxisSensor; private bool _isSixAxisSensorUnalteredPassthroughEnabled; private NpadHandheldActivationMode _npadHandheldActivationMode; - private GyroscopeZeroDriftMode _gyroscopeZeroDriftMode; + private GyroscopeZeroDriftMode _gyroscopeZeroDriftMode; - private long _npadCommunicationMode; - private uint _accelerometerPlayMode; -#pragma warning disable CS0649 - private long _vibrationGcErmCommand; + private long _npadCommunicationMode; + private uint _accelerometerPlayMode; +#pragma warning disable CS0649 // Field is never assigned to + private readonly long _vibrationGcErmCommand; #pragma warning restore CS0649 private float _sevenSixAxisSensorFusionStrength; - private SensorFusionParameters _sensorFusionParams; + private SensorFusionParameters _sensorFusionParams; private AccelerometerParameters _accelerometerParams; public IHidServer(ServiceCtx context) : base(context.Device.System.HidServer) { - _xpadIdEvent = new KEvent(context.Device.System.KernelContext); + _xpadIdEvent = new KEvent(context.Device.System.KernelContext); _palmaOperationCompleteEvent = new KEvent(context.Device.System.KernelContext); _npadHandheldActivationMode = NpadHandheldActivationMode.Dual; - _gyroscopeZeroDriftMode = GyroscopeZeroDriftMode.Standard; + _gyroscopeZeroDriftMode = GyroscopeZeroDriftMode.Standard; _isFirmwareUpdateAvailableForSixAxisSensor = false; - _sensorFusionParams = new SensorFusionParameters(); + _sensorFusionParams = new SensorFusionParameters(); _accelerometerParams = new AccelerometerParameters(); // TODO: signal event at right place @@ -63,7 +63,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid // CreateAppletResource(nn::applet::AppletResourceUserId) -> object public ResultCode CreateAppletResource(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 MakeObject(context, new IAppletResource(context.Device.System.HidSharedMem)); @@ -138,8 +140,10 @@ namespace Ryujinx.HLE.HOS.Services.Hid // Initialize entries to avoid issues with some games. - KeyboardInput emptyInput = new KeyboardInput(); - emptyInput.Keys = new ulong[4]; + KeyboardInput emptyInput = new() + { + Keys = new ulong[4], + }; for (int entry = 0; entry < Hid.SharedMemEntryCount; entry++) { @@ -199,7 +203,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid // ActivateXpad(nn::hid::BasicXpadId, nn::applet::AppletResourceUserId) public ResultCode ActivateXpad(ServiceCtx context) { - int basicXpadId = context.RequestData.ReadInt32(); + int basicXpadId = context.RequestData.ReadInt32(); long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, basicXpadId }); @@ -395,7 +399,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid _sensorFusionParams = new SensorFusionParameters { RevisePower = context.RequestData.ReadInt32(), - ReviseRange = context.RequestData.ReadInt32() + ReviseRange = context.RequestData.ReadInt32(), }; long appletResourceUserId = context.RequestData.ReadInt64(); @@ -447,7 +451,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid _accelerometerParams = new AccelerometerParameters { X = context.RequestData.ReadInt32(), - Y = context.RequestData.ReadInt32() + Y = context.RequestData.ReadInt32(), }; long appletResourceUserId = context.RequestData.ReadInt64(); @@ -671,7 +675,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid public ResultCode ActivateGesture(ServiceCtx context) { long appletResourceUserId = context.RequestData.ReadInt64(); - int unknown0 = context.RequestData.ReadInt32(); + int unknown0 = context.RequestData.ReadInt32(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, unknown0 }); @@ -698,8 +702,10 @@ namespace Ryujinx.HLE.HOS.Services.Hid // GetSupportedNpadStyleSet(pid, nn::applet::AppletResourceUserId) -> uint nn::hid::NpadStyleTag public ResultCode GetSupportedNpadStyleSet(ServiceCtx context) { - ulong pid = context.Request.HandleDesc.PId; - long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong pid = context.Request.HandleDesc.PId; +#pragma warning restore IDE0059 + long appletResourceUserId = context.RequestData.ReadInt64(); context.ResponseData.Write((int)context.Device.Hid.Npads.SupportedStyleSets); @@ -712,9 +718,11 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SetSupportedNpadIdType(nn::applet::AppletResourceUserId, array) public ResultCode SetSupportedNpadIdType(ServiceCtx context) { - long appletResourceUserId = context.RequestData.ReadInt64(); - ulong arrayPosition = context.Request.PtrBuff[0].Position; - ulong arraySize = context.Request.PtrBuff[0].Size; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 + ulong arrayPosition = context.Request.PtrBuff[0].Position; + ulong arraySize = context.Request.PtrBuff[0].Size; ReadOnlySpan supportedPlayerIds = MemoryMarshal.Cast(context.Memory.GetSpan(arrayPosition, (int)arraySize)); @@ -756,9 +764,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid // AcquireNpadStyleSetUpdateEventHandle(nn::applet::AppletResourceUserId, uint, ulong) -> nn::sf::NativeHandle public ResultCode AcquireNpadStyleSetUpdateEventHandle(ServiceCtx context) { - PlayerIndex npadId = HidUtils.GetIndexFromNpadIdType((NpadIdType)context.RequestData.ReadInt32()); - long appletResourceUserId = context.RequestData.ReadInt64(); - long npadStyleSet = context.RequestData.ReadInt64(); + PlayerIndex npadId = HidUtils.GetIndexFromNpadIdType((NpadIdType)context.RequestData.ReadInt32()); + long appletResourceUserId = context.RequestData.ReadInt64(); + long npadStyleSet = context.RequestData.ReadInt64(); KEvent evnt = context.Device.Hid.Npads.GetStyleSetUpdateEvent(npadId); if (context.Process.HandleTable.GenerateHandle(evnt.ReadableEvent, out int handle) != Result.Success) @@ -780,8 +788,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // DisconnectNpad(nn::applet::AppletResourceUserId, uint NpadIdType) public ResultCode DisconnectNpad(ServiceCtx context) { - NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadInt32(); - long appletResourceUserId = context.RequestData.ReadInt64(); + NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadInt32(); + long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, npadIdType }); @@ -796,17 +804,17 @@ namespace Ryujinx.HLE.HOS.Services.Hid ulong ledPattern = npadId switch { - NpadIdType.Player1 => 0b0001, - NpadIdType.Player2 => 0b0011, - NpadIdType.Player3 => 0b0111, - NpadIdType.Player4 => 0b1111, - NpadIdType.Player5 => 0b1001, - NpadIdType.Player6 => 0b0101, - NpadIdType.Player7 => 0b1101, - NpadIdType.Player8 => 0b0110, - NpadIdType.Unknown => 0b0000, + NpadIdType.Player1 => 0b0001, + NpadIdType.Player2 => 0b0011, + NpadIdType.Player3 => 0b0111, + NpadIdType.Player4 => 0b1111, + NpadIdType.Player5 => 0b1001, + NpadIdType.Player6 => 0b0101, + NpadIdType.Player7 => 0b1101, + NpadIdType.Player8 => 0b0110, + NpadIdType.Unknown => 0b0000, NpadIdType.Handheld => 0b0000, - _ => throw new ArgumentOutOfRangeException(nameof(npadId)) + _ => throw new InvalidOperationException($"{nameof(npadId)} contains an invalid value: {npadId}"), }; context.ResponseData.Write(ledPattern); @@ -831,13 +839,13 @@ namespace Ryujinx.HLE.HOS.Services.Hid // Initialize entries to avoid issues with some games. - List emptyGamepadInputs = new List(); - List emptySixAxisInputs = new List(); + List emptyGamepadInputs = new(); + List emptySixAxisInputs = new(); for (int player = 0; player < NpadDevices.MaxControllers; player++) { - GamepadInput gamepadInput = new GamepadInput(); - SixAxisInput sixaxisInput = new SixAxisInput(); + GamepadInput gamepadInput = new(); + SixAxisInput sixaxisInput = new(); gamepadInput.PlayerId = (PlayerIndex)player; sixaxisInput.PlayerId = (PlayerIndex)player; @@ -863,13 +871,15 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SetNpadJoyHoldType(nn::applet::AppletResourceUserId, ulong NpadJoyHoldType) public ResultCode SetNpadJoyHoldType(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 NpadJoyHoldType npadJoyHoldType = (NpadJoyHoldType)context.RequestData.ReadUInt64(); if (npadJoyHoldType > NpadJoyHoldType.Horizontal) { - throw new ArgumentOutOfRangeException(nameof(npadJoyHoldType)); + throw new InvalidOperationException($"{nameof(npadJoyHoldType)} contains an invalid value: {npadJoyHoldType}"); } foreach (PlayerIndex playerIndex in context.Device.Hid.Npads.GetSupportedPlayers()) @@ -889,7 +899,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid // GetNpadJoyHoldType(nn::applet::AppletResourceUserId) -> ulong NpadJoyHoldType public ResultCode GetNpadJoyHoldType(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 foreach (PlayerIndex playerIndex in context.Device.Hid.Npads.GetSupportedPlayers()) { @@ -910,7 +922,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid { NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32(); context.RequestData.BaseStream.Position += 4; // Padding +#pragma warning disable IDE0059 // Remove unnecessary value assignment long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 if (HidUtils.IsValidNpadIdType(npadIdType)) { @@ -943,7 +957,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid { NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32(); context.RequestData.BaseStream.Position += 4; // Padding +#pragma warning disable IDE0059 // Remove unnecessary value assignment long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 if (HidUtils.IsValidNpadIdType(npadIdType)) { @@ -957,9 +973,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid // MergeSingleJoyAsDualJoy(uint npadIdType0, uint npadIdType1, nn::applet::AppletResourceUserId) public ResultCode MergeSingleJoyAsDualJoy(ServiceCtx context) { - NpadIdType npadIdType0 = (NpadIdType)context.RequestData.ReadUInt32(); - NpadIdType npadIdType1 = (NpadIdType)context.RequestData.ReadUInt32(); - long appletResourceUserId = context.RequestData.ReadInt64(); + NpadIdType npadIdType0 = (NpadIdType)context.RequestData.ReadUInt32(); + NpadIdType npadIdType1 = (NpadIdType)context.RequestData.ReadUInt32(); + long appletResourceUserId = context.RequestData.ReadInt64(); if (HidUtils.IsValidNpadIdType(npadIdType0) && HidUtils.IsValidNpadIdType(npadIdType1)) { @@ -995,7 +1011,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SetNpadHandheldActivationMode(nn::applet::AppletResourceUserId, long HidNpadHandheldActivationMode) public ResultCode SetNpadHandheldActivationMode(ServiceCtx context) { - long appletResourceUserId = context.RequestData.ReadInt64(); + long appletResourceUserId = context.RequestData.ReadInt64(); _npadHandheldActivationMode = (NpadHandheldActivationMode)context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, _npadHandheldActivationMode }); @@ -1020,8 +1036,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SwapNpadAssignment(uint OldNpadAssignment, uint NewNpadAssignment, nn::applet::AppletResourceUserId) public ResultCode SwapNpadAssignment(ServiceCtx context) { - int oldNpadAssignment = context.RequestData.ReadInt32(); - int newNpadAssignment = context.RequestData.ReadInt32(); + int oldNpadAssignment = context.RequestData.ReadInt32(); + int newNpadAssignment = context.RequestData.ReadInt32(); long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, oldNpadAssignment, newNpadAssignment }); @@ -1033,7 +1049,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid // IsUnintendedHomeButtonInputProtectionEnabled(uint Unknown0, nn::applet::AppletResourceUserId) -> bool IsEnabled public ResultCode IsUnintendedHomeButtonInputProtectionEnabled(ServiceCtx context) { - uint unknown0 = context.RequestData.ReadUInt32(); + uint unknown0 = context.RequestData.ReadUInt32(); long appletResourceUserId = context.RequestData.ReadInt64(); context.ResponseData.Write(_unintendedHomeButtonInputProtectionEnabled); @@ -1048,8 +1064,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid public ResultCode EnableUnintendedHomeButtonInputProtection(ServiceCtx context) { _unintendedHomeButtonInputProtectionEnabled = context.RequestData.ReadBoolean(); - uint unknown0 = context.RequestData.ReadUInt32(); - long appletResourceUserId = context.RequestData.ReadInt64(); + uint unknown0 = context.RequestData.ReadUInt32(); + long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, unknown0, _unintendedHomeButtonInputProtectionEnabled }); @@ -1060,7 +1076,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SetNpadJoyAssignmentModeSingleWithDestination(uint npadIdType, uint npadJoyDeviceType, nn::applet::AppletResourceUserId) -> bool npadIdTypeIsSet, uint npadIdTypeSet public ResultCode SetNpadJoyAssignmentModeSingleWithDestination(ServiceCtx context) { - NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadInt32(); + NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadInt32(); NpadJoyDeviceType npadJoyDeviceType = (NpadJoyDeviceType)context.RequestData.ReadInt32(); context.RequestData.BaseStream.Position += 4; // Padding long appletResourceUserId = context.RequestData.ReadInt64(); @@ -1081,7 +1097,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid private void SetNpadJoyAssignmentModeSingleWithDestinationImpl(ServiceCtx context, NpadIdType npadIdType, long appletResourceUserId, NpadJoyDeviceType npadJoyDeviceType, out NpadIdType npadIdTypeSet, out bool npadIdTypeIsSet) { - npadIdTypeSet = default; + npadIdTypeSet = default; npadIdTypeIsSet = false; context.Device.Hid.SharedMemory.Npads[(int)HidUtils.GetIndexFromNpadIdType(npadIdType)].InternalState.JoyAssignmentMode = NpadJoyAssignmentMode.Single; @@ -1096,8 +1112,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid public ResultCode GetVibrationDeviceInfo(ServiceCtx context) { VibrationDeviceHandle deviceHandle = context.RequestData.ReadStruct(); - NpadStyleIndex deviceType = (NpadStyleIndex)deviceHandle.DeviceType; - NpadIdType npadIdType = (NpadIdType)deviceHandle.PlayerId; + NpadStyleIndex deviceType = (NpadStyleIndex)deviceHandle.DeviceType; + NpadIdType npadIdType = (NpadIdType)deviceHandle.PlayerId; if (deviceType < NpadStyleIndex.System || deviceType >= NpadStyleIndex.FullKey) { @@ -1136,14 +1152,14 @@ namespace Ryujinx.HLE.HOS.Services.Hid } else { - throw new ArgumentOutOfRangeException(nameof(deviceHandle.Position)); + throw new InvalidOperationException($"{nameof(deviceHandle.Position)} contains an invalid value: {deviceHandle.Position}"); } } - VibrationDeviceValue deviceInfo = new VibrationDeviceValue + VibrationDeviceValue deviceInfo = new() { DeviceType = vibrationDeviceType, - Position = vibrationDevicePosition + Position = vibrationDevicePosition, }; context.ResponseData.WriteStruct(deviceInfo); @@ -1158,27 +1174,30 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SendVibrationValue(nn::hid::VibrationDeviceHandle, nn::hid::VibrationValue, nn::applet::AppletResourceUserId) public ResultCode SendVibrationValue(ServiceCtx context) { - VibrationDeviceHandle deviceHandle = new VibrationDeviceHandle + VibrationDeviceHandle deviceHandle = new() { DeviceType = context.RequestData.ReadByte(), - PlayerId = context.RequestData.ReadByte(), - Position = context.RequestData.ReadByte(), - Reserved = context.RequestData.ReadByte() + PlayerId = context.RequestData.ReadByte(), + Position = context.RequestData.ReadByte(), + Reserved = context.RequestData.ReadByte(), }; - VibrationValue vibrationValue = new VibrationValue + VibrationValue vibrationValue = new() { - AmplitudeLow = context.RequestData.ReadSingle(), - FrequencyLow = context.RequestData.ReadSingle(), + AmplitudeLow = context.RequestData.ReadSingle(), + FrequencyLow = context.RequestData.ReadSingle(), AmplitudeHigh = context.RequestData.ReadSingle(), - FrequencyHigh = context.RequestData.ReadSingle() + FrequencyHigh = context.RequestData.ReadSingle(), }; +#pragma warning disable IDE0059 // Remove unnecessary value assignment long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 - Dictionary dualVibrationValues = new Dictionary(); - - dualVibrationValues[deviceHandle.Position] = vibrationValue; + Dictionary dualVibrationValues = new() + { + [deviceHandle.Position] = vibrationValue, + }; context.Device.Hid.Npads.UpdateRumbleQueue((PlayerIndex)deviceHandle.PlayerId, dualVibrationValues); @@ -1189,15 +1208,17 @@ namespace Ryujinx.HLE.HOS.Services.Hid // GetActualVibrationValue(nn::hid::VibrationDeviceHandle, nn::applet::AppletResourceUserId) -> nn::hid::VibrationValue public ResultCode GetActualVibrationValue(ServiceCtx context) { - VibrationDeviceHandle deviceHandle = new VibrationDeviceHandle + VibrationDeviceHandle deviceHandle = new() { DeviceType = context.RequestData.ReadByte(), - PlayerId = context.RequestData.ReadByte(), - Position = context.RequestData.ReadByte(), - Reserved = context.RequestData.ReadByte() + PlayerId = context.RequestData.ReadByte(), + Position = context.RequestData.ReadByte(), + Reserved = context.RequestData.ReadByte(), }; +#pragma warning disable IDE0059 // Remove unnecessary value assignment long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 VibrationValue vibrationValue = context.Device.Hid.Npads.GetLastVibrationValue((PlayerIndex)deviceHandle.PlayerId, deviceHandle.Position); @@ -1242,7 +1263,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SendVibrationValues(nn::applet::AppletResourceUserId, buffer, type: 9>, buffer, type: 9>) public ResultCode SendVibrationValues(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 byte[] vibrationDeviceHandleBuffer = new byte[context.Request.PtrBuff[0].Size]; @@ -1252,12 +1275,12 @@ namespace Ryujinx.HLE.HOS.Services.Hid context.Memory.Read(context.Request.PtrBuff[1].Position, vibrationValueBuffer); - Span deviceHandles = MemoryMarshal.Cast(vibrationDeviceHandleBuffer); - Span vibrationValues = MemoryMarshal.Cast(vibrationValueBuffer); + Span deviceHandles = MemoryMarshal.Cast(vibrationDeviceHandleBuffer); + Span vibrationValues = MemoryMarshal.Cast(vibrationValueBuffer); if (!deviceHandles.IsEmpty && vibrationValues.Length == deviceHandles.Length) { - Dictionary dualVibrationValues = new Dictionary(); + Dictionary dualVibrationValues = new(); PlayerIndex currentIndex = (PlayerIndex)deviceHandles[0].PlayerId; for (int deviceCounter = 0; deviceCounter < deviceHandles.Length; deviceCounter++) @@ -1285,9 +1308,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SendVibrationGcErmCommand(nn::hid::VibrationDeviceHandle, nn::hid::VibrationGcErmCommand, nn::applet::AppletResourceUserId) public ResultCode SendVibrationGcErmCommand(ServiceCtx context) { - int vibrationDeviceHandle = context.RequestData.ReadInt32(); + int vibrationDeviceHandle = context.RequestData.ReadInt32(); long vibrationGcErmCommand = context.RequestData.ReadInt64(); - long appletResourceUserId = context.RequestData.ReadInt64(); + long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, vibrationDeviceHandle, vibrationGcErmCommand }); @@ -1298,8 +1321,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // GetActualVibrationGcErmCommand(nn::hid::VibrationDeviceHandle, nn::applet::AppletResourceUserId) -> nn::hid::VibrationGcErmCommand public ResultCode GetActualVibrationGcErmCommand(ServiceCtx context) { - int vibrationDeviceHandle = context.RequestData.ReadInt32(); - long appletResourceUserId = context.RequestData.ReadInt64(); + int vibrationDeviceHandle = context.RequestData.ReadInt32(); + long appletResourceUserId = context.RequestData.ReadInt64(); context.ResponseData.Write(_vibrationGcErmCommand); @@ -1332,8 +1355,10 @@ namespace Ryujinx.HLE.HOS.Services.Hid // IsVibrationDeviceMounted(nn::hid::VibrationDeviceHandle, nn::applet::AppletResourceUserId) public ResultCode IsVibrationDeviceMounted(ServiceCtx context) { - int vibrationDeviceHandle = context.RequestData.ReadInt32(); - long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + int vibrationDeviceHandle = context.RequestData.ReadInt32(); + long appletResourceUserId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 // NOTE: Service use vibrationDeviceHandle to get the PlayerIndex. // And return false if (npadIdType >= (NpadIdType)8 && npadIdType != NpadIdType.Handheld && npadIdType != NpadIdType.Unknown) @@ -1358,8 +1383,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // StartConsoleSixAxisSensor(nn::hid::ConsoleSixAxisSensorHandle, nn::applet::AppletResourceUserId) public ResultCode StartConsoleSixAxisSensor(ServiceCtx context) { - int consoleSixAxisSensorHandle = context.RequestData.ReadInt32(); - long appletResourceUserId = context.RequestData.ReadInt64(); + int consoleSixAxisSensorHandle = context.RequestData.ReadInt32(); + long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, consoleSixAxisSensorHandle }); @@ -1370,8 +1395,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // StopConsoleSixAxisSensor(nn::hid::ConsoleSixAxisSensorHandle, nn::applet::AppletResourceUserId) public ResultCode StopConsoleSixAxisSensor(ServiceCtx context) { - int consoleSixAxisSensorHandle = context.RequestData.ReadInt32(); - long appletResourceUserId = context.RequestData.ReadInt64(); + int consoleSixAxisSensorHandle = context.RequestData.ReadInt32(); + long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, consoleSixAxisSensorHandle }); @@ -1416,8 +1441,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid public ResultCode InitializeSevenSixAxisSensor(ServiceCtx context) { long appletResourceUserId = context.RequestData.ReadInt64(); - long counter0 = context.RequestData.ReadInt64(); - long counter1 = context.RequestData.ReadInt64(); + long counter0 = context.RequestData.ReadInt64(); + long counter1 = context.RequestData.ReadInt64(); // TODO: Determine if array is a buffer or not... @@ -1441,8 +1466,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SetSevenSixAxisSensorFusionStrength(float Strength, nn::applet::AppletResourceUserId) public ResultCode SetSevenSixAxisSensorFusionStrength(ServiceCtx context) { - _sevenSixAxisSensorFusionStrength = context.RequestData.ReadSingle(); - long appletResourceUserId = context.RequestData.ReadInt64(); + _sevenSixAxisSensorFusionStrength = context.RequestData.ReadSingle(); + long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, _sevenSixAxisSensorFusionStrength }); @@ -1566,14 +1591,14 @@ namespace Ryujinx.HLE.HOS.Services.Hid // GetPalmaConnectionHandle(uint Unknown0, nn::applet::AppletResourceUserId) -> nn::hid::PalmaConnectionHandle public ResultCode GetPalmaConnectionHandle(ServiceCtx context) { - int unknown0 = context.RequestData.ReadInt32(); + int unknown0 = context.RequestData.ReadInt32(); long appletResourceUserId = context.RequestData.ReadInt64(); int palmaConnectionHandle = 0; context.ResponseData.Write(palmaConnectionHandle); - Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId , unknown0, palmaConnectionHandle }); + Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, unknown0, palmaConnectionHandle }); return ResultCode.Success; } @@ -1628,8 +1653,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // PlayPalmaActivity(nn::hid::PalmaConnectionHandle, ulong Unknown0) public ResultCode PlayPalmaActivity(ServiceCtx context) { - int palmaConnectionHandle = context.RequestData.ReadInt32(); - long unknown0 = context.RequestData.ReadInt64(); + int palmaConnectionHandle = context.RequestData.ReadInt32(); + long unknown0 = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { palmaConnectionHandle, unknown0 }); @@ -1642,8 +1667,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SetPalmaFrModeType(nn::hid::PalmaConnectionHandle, ulong FrModeType) public ResultCode SetPalmaFrModeType(ServiceCtx context) { - int palmaConnectionHandle = context.RequestData.ReadInt32(); - long frModeType = context.RequestData.ReadInt64(); + int palmaConnectionHandle = context.RequestData.ReadInt32(); + long frModeType = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { palmaConnectionHandle, frModeType }); @@ -1667,8 +1692,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // EnablePalmaStep(nn::hid::PalmaConnectionHandle, bool Enable) public ResultCode EnablePalmaStep(ServiceCtx context) { - int palmaConnectionHandle = context.RequestData.ReadInt32(); - bool enabledPalmaStep = context.RequestData.ReadBoolean(); + int palmaConnectionHandle = context.RequestData.ReadInt32(); + bool enabledPalmaStep = context.RequestData.ReadBoolean(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { palmaConnectionHandle, enabledPalmaStep }); @@ -1694,9 +1719,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid // ReadPalmaApplicationSection(nn::hid::PalmaConnectionHandle, ulong Unknown0, ulong Unknown1) public ResultCode ReadPalmaApplicationSection(ServiceCtx context) { - int palmaConnectionHandle = context.RequestData.ReadInt32(); - long unknown0 = context.RequestData.ReadInt64(); - long unknown1 = context.RequestData.ReadInt64(); + int palmaConnectionHandle = context.RequestData.ReadInt32(); + long unknown0 = context.RequestData.ReadInt64(); + long unknown1 = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { palmaConnectionHandle, unknown0, unknown1 }); @@ -1707,9 +1732,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid // WritePalmaApplicationSection(nn::hid::PalmaConnectionHandle, ulong Unknown0, ulong Unknown1, nn::hid::PalmaApplicationSectionAccessBuffer) public ResultCode WritePalmaApplicationSection(ServiceCtx context) { - int palmaConnectionHandle = context.RequestData.ReadInt32(); - long unknown0 = context.RequestData.ReadInt64(); - long unknown1 = context.RequestData.ReadInt64(); + int palmaConnectionHandle = context.RequestData.ReadInt32(); + long unknown0 = context.RequestData.ReadInt64(); + long unknown1 = context.RequestData.ReadInt64(); // nn::hid::PalmaApplicationSectionAccessBuffer cast is unknown Logger.Stub?.PrintStub(LogClass.ServiceHid, new { palmaConnectionHandle, unknown0, unknown1 }); @@ -1746,7 +1771,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid public ResultCode SetIsPalmaAllConnectable(ServiceCtx context) { long appletResourceUserId = context.RequestData.ReadInt64(); - long unknownBool = context.RequestData.ReadInt64(); + long unknownBool = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, unknownBool }); @@ -1766,8 +1791,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid // SetNpadCommunicationMode(long CommunicationMode, nn::applet::AppletResourceUserId) public ResultCode SetNpadCommunicationMode(ServiceCtx context) { - _npadCommunicationMode = context.RequestData.ReadInt64(); - long appletResourceUserId = context.RequestData.ReadInt64(); + _npadCommunicationMode = context.RequestData.ReadInt64(); + long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, _npadCommunicationMode }); @@ -1790,7 +1815,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid public ResultCode SetTouchScreenConfiguration(ServiceCtx context) { long touchScreenConfigurationForNx = context.RequestData.ReadInt64(); - long appletResourceUserId = context.RequestData.ReadInt64(); + long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, touchScreenConfigurationForNx }); diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/IHidSystemServer.cs b/src/Ryujinx.HLE/HOS/Services/Hid/IHidSystemServer.cs index 4a5d0e9b5..685f6841d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/IHidSystemServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/IHidSystemServer.cs @@ -65,7 +65,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid private ResultCode GetAppletFooterUiTypeImpl(ServiceCtx context, out AppletFooterUiType appletFooterUiType) { - NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32(); + NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32(); PlayerIndex playerIndex = HidUtils.GetIndexFromNpadIdType(npadIdType); appletFooterUiType = context.Device.Hid.SharedMemory.Npads[(int)playerIndex].InternalState.AppletFooterUiType; @@ -73,4 +73,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/IHidbusServer.cs b/src/Ryujinx.HLE/HOS/Services/Hid/IHidbusServer.cs index eec5292f5..7c624dfc3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/IHidbusServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/IHidbusServer.cs @@ -10,12 +10,14 @@ namespace Ryujinx.HLE.HOS.Services.Hid [CommandCmif(1)] // GetBusHandle(nn::hid::NpadIdType, nn::hidbus::BusType, nn::applet::AppletResourceUserId) -> (bool HasHandle, nn::hidbus::BusHandle) +#pragma warning disable CA1822 // Mark member as static public ResultCode GetBusHandle(ServiceCtx context) +#pragma warning restore CA1822 { - NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadInt32(); + NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadInt32(); context.RequestData.BaseStream.Position += 4; // Padding - BusType busType = (BusType)context.RequestData.ReadInt64(); - long appletResourceUserId = context.RequestData.ReadInt64(); + BusType busType = (BusType)context.RequestData.ReadInt64(); + long appletResourceUserId = context.RequestData.ReadInt64(); context.ResponseData.Write(false); context.ResponseData.BaseStream.Position += 7; // Padding @@ -26,4 +28,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/ISystemServer.cs b/src/Ryujinx.HLE/HOS/Services/Hid/ISystemServer.cs index 713533442..daff6fda9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/ISystemServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/ISystemServer.cs @@ -5,4 +5,4 @@ { public ISystemServer(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs index 130fcf687..a13e77e72 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs @@ -65,8 +65,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs // StopImageProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId) public ResultCode StopImageProcessor(ServiceCtx context) { - IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); - ulong appletResourceUserId = context.RequestData.ReadUInt64(); + IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); + ulong appletResourceUserId = context.RequestData.ReadUInt64(); CheckCameraHandle(irCameraHandle); @@ -79,9 +79,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs // RunMomentProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, PackedMomentProcessorConfig) public ResultCode RunMomentProcessor(ServiceCtx context) { - IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); - ulong appletResourceUserId = context.RequestData.ReadUInt64(); - var packedMomentProcessorConfig = context.RequestData.ReadStruct(); + IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); + ulong appletResourceUserId = context.RequestData.ReadUInt64(); + var packedMomentProcessorConfig = context.RequestData.ReadStruct(); CheckCameraHandle(irCameraHandle); @@ -94,9 +94,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs // RunClusteringProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, PackedClusteringProcessorConfig) public ResultCode RunClusteringProcessor(ServiceCtx context) { - IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); - ulong appletResourceUserId = context.RequestData.ReadUInt64(); - var packedClusteringProcessorConfig = context.RequestData.ReadStruct(); + IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); + ulong appletResourceUserId = context.RequestData.ReadUInt64(); + var packedClusteringProcessorConfig = context.RequestData.ReadStruct(); CheckCameraHandle(irCameraHandle); @@ -109,9 +109,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs // RunImageTransferProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, PackedImageTransferProcessorConfig, u64 TransferMemorySize, TransferMemoryHandle) public ResultCode RunImageTransferProcessor(ServiceCtx context) { - IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); - ulong appletResourceUserId = context.RequestData.ReadUInt64(); - var packedImageTransferProcessorConfig = context.RequestData.ReadStruct(); + IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); + ulong appletResourceUserId = context.RequestData.ReadUInt64(); + var packedImageTransferProcessorConfig = context.RequestData.ReadStruct(); CheckCameraHandle(irCameraHandle); @@ -126,8 +126,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs // GetImageTransferProcessorState(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId) public ResultCode GetImageTransferProcessorState(ServiceCtx context) { - IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); - ulong appletResourceUserId = context.RequestData.ReadUInt64(); + IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); + ulong appletResourceUserId = context.RequestData.ReadUInt64(); // ulong imageTransferBufferAddress = context.Request.ReceiveBuff[0].Position; ulong imageTransferBufferSize = context.Request.ReceiveBuff[0].Size; @@ -144,8 +144,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs // TODO: Uses the buffer to copy the JoyCon IR data (by using a JoyCon driver) and update the following struct. context.ResponseData.WriteStruct(new ImageTransferProcessorState() { - SamplingNumber = 0, - AmbientNoiseLevel = 0 + SamplingNumber = 0, + AmbientNoiseLevel = 0, }); return ResultCode.Success; @@ -155,9 +155,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs // RunTeraPluginProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, PackedTeraPluginProcessorConfig) public ResultCode RunTeraPluginProcessor(ServiceCtx context) { - IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); - ulong appletResourceUserId = context.RequestData.ReadUInt64(); - var packedTeraPluginProcessorConfig = context.RequestData.ReadStruct(); + IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); + ulong appletResourceUserId = context.RequestData.ReadUInt64(); + var packedTeraPluginProcessorConfig = context.RequestData.ReadStruct(); CheckCameraHandle(irCameraHandle); @@ -172,7 +172,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs { NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32(); - if (npadIdType > NpadIdType.Player8 && + if (npadIdType > NpadIdType.Player8 && npadIdType != NpadIdType.Unknown && npadIdType != NpadIdType.Handheld) { @@ -193,10 +193,10 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs // CheckFirmwareVersion(nn::irsensor::IrCameraHandle, nn::irsensor::PackedMcuVersion, nn::applet::AppletResourceUserId, pid) public ResultCode CheckFirmwareVersion(ServiceCtx context) { - int irCameraHandle = context.RequestData.ReadInt32(); + int irCameraHandle = context.RequestData.ReadInt32(); short packedMcuVersionMajor = context.RequestData.ReadInt16(); short packedMcuVersionMinor = context.RequestData.ReadInt16(); - long appletResourceUserId = context.RequestData.ReadInt64(); + long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle, packedMcuVersionMajor, packedMcuVersionMinor }); @@ -207,7 +207,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs // StopImageProcessorAsync(nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, pid) public ResultCode StopImageProcessorAsync(ServiceCtx context) { - int irCameraHandle = context.RequestData.ReadInt32(); + int irCameraHandle = context.RequestData.ReadInt32(); long appletResourceUserId = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle }); @@ -220,7 +220,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs public ResultCode ActivateIrsensorWithFunctionLevel(ServiceCtx context) { long appletResourceUserId = context.RequestData.ReadInt64(); - long packedFunctionLevel = context.RequestData.ReadInt64(); + long packedFunctionLevel = context.RequestData.ReadInt64(); Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, packedFunctionLevel }); diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorSystemServer.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorSystemServer.cs index 99fcd5415..ad78d4f1e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorSystemServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorSystemServer.cs @@ -5,4 +5,4 @@ { public IIrSensorSystemServer(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/ResultCode.cs index 3afc03c27..322f9349b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/ResultCode.cs @@ -2,14 +2,14 @@ { public enum ResultCode { - ModuleId = 205, + ModuleId = 205, ErrorCodeShift = 9, Success = 0, InvalidCameraHandle = (204 << ErrorCodeShift) | ModuleId, - InvalidBufferSize = (207 << ErrorCodeShift) | ModuleId, + InvalidBufferSize = (207 << ErrorCodeShift) | ModuleId, HandlePointerIsNull = (212 << ErrorCodeShift) | ModuleId, - NpadIdOutOfRange = (709 << ErrorCodeShift) | ModuleId + NpadIdOutOfRange = (709 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/ImageTransferProcessorState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/ImageTransferProcessorState.cs index 647aef649..7f28667ce 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/ImageTransferProcessorState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/ImageTransferProcessorState.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs.Types struct ImageTransferProcessorState { public ulong SamplingNumber; - public uint AmbientNoiseLevel; - public uint Reserved; + public uint AmbientNoiseLevel; + public uint Reserved; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/IrCameraHandle.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/IrCameraHandle.cs index 8ed7201ed..282f92796 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/IrCameraHandle.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/IrCameraHandle.cs @@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs.Types [StructLayout(LayoutKind.Sequential, Size = 0x4)] struct IrCameraHandle { - public byte PlayerNumber; - public byte DeviceType; + public byte PlayerNumber; + public byte DeviceType; public ushort Reserved; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedClusteringProcessorConfig.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedClusteringProcessorConfig.cs index 735f78227..a65a1ba61 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedClusteringProcessorConfig.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedClusteringProcessorConfig.cs @@ -5,21 +5,21 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs.Types [StructLayout(LayoutKind.Sequential, Size = 0x28)] struct PackedClusteringProcessorConfig { - public long ExposureTime; - public byte LightTarget; - public byte Gain; - public byte IsNegativeImageUsed; - public byte Reserved1; - public uint Reserved2; + public long ExposureTime; + public byte LightTarget; + public byte Gain; + public byte IsNegativeImageUsed; + public byte Reserved1; + public uint Reserved2; public ushort WindowOfInterestX; public ushort WindowOfInterestY; public ushort WindowOfInterestWidth; public ushort WindowOfInterestHeight; - public uint RequiredMcuVersion; - public uint ObjectPixelCountMin; - public uint ObjectPixelCountMax; - public byte ObjectIntensityMin; - public byte IsExternalLightFilterEnabled; + public uint RequiredMcuVersion; + public uint ObjectPixelCountMin; + public uint ObjectPixelCountMax; + public byte ObjectIntensityMin; + public byte IsExternalLightFilterEnabled; public ushort Reserved3; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedImageTransferProcessorConfig.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedImageTransferProcessorConfig.cs index 094413e00..c97de27a8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedImageTransferProcessorConfig.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedImageTransferProcessorConfig.cs @@ -5,15 +5,15 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs.Types [StructLayout(LayoutKind.Sequential, Size = 0x18)] struct PackedImageTransferProcessorConfig { - public long ExposureTime; - public byte LightTarget; - public byte Gain; - public byte IsNegativeImageUsed; - public byte Reserved1; - public uint Reserved2; - public uint RequiredMcuVersion; - public byte Format; - public byte Reserved3; + public long ExposureTime; + public byte LightTarget; + public byte Gain; + public byte IsNegativeImageUsed; + public byte Reserved1; + public uint Reserved2; + public uint RequiredMcuVersion; + public byte Format; + public byte Reserved3; public ushort Reserved4; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedMomentProcessorConfig.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedMomentProcessorConfig.cs index a1b70b405..bbee28156 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedMomentProcessorConfig.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedMomentProcessorConfig.cs @@ -5,19 +5,19 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs.Types [StructLayout(LayoutKind.Sequential, Size = 0x20)] struct PackedMomentProcessorConfig { - public long ExposureTime; - public byte LightTarget; - public byte Gain; - public byte IsNegativeImageUsed; - public byte Reserved1; - public uint Reserved2; + public long ExposureTime; + public byte LightTarget; + public byte Gain; + public byte IsNegativeImageUsed; + public byte Reserved1; + public uint Reserved2; public ushort WindowOfInterestX; public ushort WindowOfInterestY; public ushort WindowOfInterestWidth; public ushort WindowOfInterestHeight; - public uint RequiredMcuVersion; - public byte Preprocess; - public byte PreprocessIntensityThreshold; + public uint RequiredMcuVersion; + public byte Preprocess; + public byte PreprocessIntensityThreshold; public ushort Reserved3; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedTeraPluginProcessorConfig.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedTeraPluginProcessorConfig.cs index 808b0b727..4fada04af 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedTeraPluginProcessorConfig.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/Types/PackedTeraPluginProcessorConfig.cs @@ -11,4 +11,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs.Types public byte Unknown2; public byte Unknown3; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Hid/ResultCode.cs index 9c87ac1dc..993ff7076 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/ResultCode.cs @@ -2,14 +2,14 @@ { enum ResultCode { - ModuleId = 202, + ModuleId = 202, ErrorCodeShift = 9, Success = 0, InvalidNpadDeviceType = (122 << ErrorCodeShift) | ModuleId, - InvalidNpadIdType = (123 << ErrorCodeShift) | ModuleId, - InvalidDeviceIndex = (124 << ErrorCodeShift) | ModuleId, - InvalidBufferSize = (131 << ErrorCodeShift) | ModuleId + InvalidNpadIdType = (123 << ErrorCodeShift) | ModuleId, + InvalidDeviceIndex = (124 << ErrorCodeShift) | ModuleId, + InvalidBufferSize = (131 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/AppletFooterUiType.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/AppletFooterUiType.cs index c4ff8d7ef..1eccd856e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/AppletFooterUiType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/AppletFooterUiType.cs @@ -25,6 +25,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types LarkNesLeft, LarkNesRight, Lucia, - Verification + Verification, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/HidVector.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/HidVector.cs index 18d9fd9c9..8d667796a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/HidVector.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/HidVector.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types public float Y; public float Z; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/BusHandle.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/BusHandle.cs index 936ee68c4..033eb3069 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/BusHandle.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/BusHandle.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid [StructLayout(LayoutKind.Sequential)] struct BusHandle { - public int AbstractedPadId; + public int AbstractedPadId; public byte InternalIndex; public byte PlayerNumber; public byte BusTypeId; diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/BusType.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/BusType.cs index 41852365b..25b36ca45 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/BusType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/BusType.cs @@ -2,8 +2,8 @@ { public enum BusType : long { - LeftJoyRail = 0, + LeftJoyRail = 0, RightJoyRail = 1, - InternalBus = 2 + InternalBus = 2, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/ControllerKeys.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/ControllerKeys.cs index c91636b2c..b43381e6d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/ControllerKeys.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/ControllerKeys.cs @@ -5,41 +5,41 @@ namespace Ryujinx.HLE.HOS.Services.Hid [Flags] public enum ControllerKeys : long { - A = 1 << 0, - B = 1 << 1, - X = 1 << 2, - Y = 1 << 3, - LStick = 1 << 4, - RStick = 1 << 5, - L = 1 << 6, - R = 1 << 7, - Zl = 1 << 8, - Zr = 1 << 9, - Plus = 1 << 10, - Minus = 1 << 11, - DpadLeft = 1 << 12, - DpadUp = 1 << 13, - DpadRight = 1 << 14, - DpadDown = 1 << 15, - LStickLeft = 1 << 16, - LStickUp = 1 << 17, + A = 1 << 0, + B = 1 << 1, + X = 1 << 2, + Y = 1 << 3, + LStick = 1 << 4, + RStick = 1 << 5, + L = 1 << 6, + R = 1 << 7, + Zl = 1 << 8, + Zr = 1 << 9, + Plus = 1 << 10, + Minus = 1 << 11, + DpadLeft = 1 << 12, + DpadUp = 1 << 13, + DpadRight = 1 << 14, + DpadDown = 1 << 15, + LStickLeft = 1 << 16, + LStickUp = 1 << 17, LStickRight = 1 << 18, - LStickDown = 1 << 19, - RStickLeft = 1 << 20, - RStickUp = 1 << 21, + LStickDown = 1 << 19, + RStickLeft = 1 << 20, + RStickUp = 1 << 21, RStickRight = 1 << 22, - RStickDown = 1 << 23, - SlLeft = 1 << 24, - SrLeft = 1 << 25, - SlRight = 1 << 26, - SrRight = 1 << 27, + RStickDown = 1 << 23, + SlLeft = 1 << 24, + SrLeft = 1 << 25, + SlRight = 1 << 26, + SrRight = 1 << 27, // Generic Catch-all - Up = DpadUp | LStickUp | RStickUp, - Down = DpadDown | LStickDown | RStickDown, - Left = DpadLeft | LStickLeft | RStickLeft, + Up = DpadUp | LStickUp | RStickUp, + Down = DpadDown | LStickDown | RStickDown, + Left = DpadLeft | LStickLeft | RStickLeft, Right = DpadRight | LStickRight | RStickRight, - Sl = SlLeft | SlRight, - Sr = SrLeft | SrRight + Sl = SlLeft | SlRight, + Sr = SrLeft | SrRight, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/ControllerType.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/ControllerType.cs index d830f46ad..1f5da3173 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/ControllerType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/ControllerType.cs @@ -6,14 +6,14 @@ namespace Ryujinx.HLE.HOS.Services.Hid public enum ControllerType { None, - ProController = 1 << 0, - Handheld = 1 << 1, - JoyconPair = 1 << 2, - JoyconLeft = 1 << 3, - JoyconRight = 1 << 4, - Invalid = 1 << 5, - Pokeball = 1 << 6, + ProController = 1 << 0, + Handheld = 1 << 1, + JoyconPair = 1 << 2, + JoyconLeft = 1 << 3, + JoyconRight = 1 << 4, + Invalid = 1 << 5, + Pokeball = 1 << 6, SystemExternal = 1 << 29, - System = 1 << 30 + System = 1 << 30, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadColor.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadColor.cs index 3c311e218..010cffbd2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadColor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadColor.cs @@ -1,37 +1,37 @@ namespace Ryujinx.HLE.HOS.Services.Hid { - public enum NpadColor : uint + public enum NpadColor : uint { - BodyGray = 0x828282, - BodyNeonRed = 0xFF3C28, - BodyNeonBlue = 0x0AB9E6, - BodyNeonYellow = 0xE6FF00, - BodyNeonGreen = 0x1EDC00, - BodyNeonPink = 0xFF3278, - BodyRed = 0xE10F00, - BodyBlue = 0x4655F5, - BodyNeonPurple = 0xB400E6, - BodyNeonOrange = 0xFAA005, - BodyPokemonLetsGoPikachu = 0xFFDC00, - BodyPokemonLetsGoEevee = 0xC88C32, - BodyNintendoLaboCreatorsContestEdition = 0xD7AA73, - BodyAnimalCrossingSpecialEditionLeftJoyCon = 0x82FF96, - BodyAnimalCrossingSpecialEditionRightJoyCon = 0x96F5F5, + BodyGray = 0x828282, + BodyNeonRed = 0xFF3C28, + BodyNeonBlue = 0x0AB9E6, + BodyNeonYellow = 0xE6FF00, + BodyNeonGreen = 0x1EDC00, + BodyNeonPink = 0xFF3278, + BodyRed = 0xE10F00, + BodyBlue = 0x4655F5, + BodyNeonPurple = 0xB400E6, + BodyNeonOrange = 0xFAA005, + BodyPokemonLetsGoPikachu = 0xFFDC00, + BodyPokemonLetsGoEevee = 0xC88C32, + BodyNintendoLaboCreatorsContestEdition = 0xD7AA73, + BodyAnimalCrossingSpecialEditionLeftJoyCon = 0x82FF96, + BodyAnimalCrossingSpecialEditionRightJoyCon = 0x96F5F5, - ButtonGray = 0x0F0F0F, - ButtonNeonRed = 0x1E0A0A, - ButtonNeonBlue = 0x001E1E, - ButtonNeonYellow = 0x142800, - ButtonNeonGreen = 0x002800, - ButtonNeonPink = 0x28001E, - ButtonRed = 0x280A0A, - ButtonBlue = 0x00000A, - ButtonNeonPurple = 0x140014, - ButtonNeonOrange = 0x0F0A00, - ButtonPokemonLetsGoPikachu = 0x322800, - ButtonPokemonLetsGoEevee = 0x281900, - ButtonNintendoLaboCreatorsContestEdition = 0x1E1914, - ButtonAnimalCrossingSpecialEditionLeftJoyCon = 0x0A1E0A, - ButtonAnimalCrossingSpecialEditionRightJoyCon = 0x0A1E28 + ButtonGray = 0x0F0F0F, + ButtonNeonRed = 0x1E0A0A, + ButtonNeonBlue = 0x001E1E, + ButtonNeonYellow = 0x142800, + ButtonNeonGreen = 0x002800, + ButtonNeonPink = 0x28001E, + ButtonRed = 0x280A0A, + ButtonBlue = 0x00000A, + ButtonNeonPurple = 0x140014, + ButtonNeonOrange = 0x0F0A00, + ButtonPokemonLetsGoPikachu = 0x322800, + ButtonPokemonLetsGoEevee = 0x281900, + ButtonNintendoLaboCreatorsContestEdition = 0x1E1914, + ButtonAnimalCrossingSpecialEditionLeftJoyCon = 0x0A1E0A, + ButtonAnimalCrossingSpecialEditionRightJoyCon = 0x0A1E28, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadIdType.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadIdType.cs index 4b488cd2c..5a9247d92 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadIdType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadIdType.cs @@ -2,15 +2,15 @@ { public enum NpadIdType { - Player1 = 0, - Player2 = 1, - Player3 = 2, - Player4 = 3, - Player5 = 4, - Player6 = 5, - Player7 = 6, - Player8 = 7, - Unknown = 16, - Handheld = 32 + Player1 = 0, + Player2 = 1, + Player3 = 2, + Player4 = 3, + Player5 = 4, + Player6 = 5, + Player7 = 6, + Player8 = 7, + Unknown = 16, + Handheld = 32, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadStyleIndex.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadStyleIndex.cs index ddf5d97f5..04550b6fe 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadStyleIndex.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/NpadStyleIndex.cs @@ -2,12 +2,12 @@ { public enum NpadStyleIndex : byte { - FullKey = 3, - Handheld = 4, - JoyDual = 5, - JoyLeft = 6, - JoyRight = 7, + FullKey = 3, + Handheld = 4, + JoyDual = 5, + JoyLeft = 6, + JoyRight = 7, SystemExt = 32, - System = 33 + System = 33, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/PlayerIndex.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/PlayerIndex.cs index 972d69b45..d68b6d938 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/PlayerIndex.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/Npad/PlayerIndex.cs @@ -2,16 +2,16 @@ namespace Ryujinx.HLE.HOS.Services.Hid { public enum PlayerIndex { - Player1 = 0, - Player2 = 1, - Player3 = 2, - Player4 = 3, - Player5 = 4, - Player6 = 5, - Player7 = 6, - Player8 = 7, + Player1 = 0, + Player2 = 1, + Player3 = 2, + Player4 = 3, + Player5 = 4, + Player6 = 5, + Player7 = 6, + Player8 = 7, Handheld = 8, - Unknown = 9, - Auto = 10 // Shouldn't be used directly + Unknown = 9, + Auto = 10, // Shouldn't be used directly } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/NpadJoyHoldType.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/NpadJoyHoldType.cs index d3b51a24c..19297de4c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/NpadJoyHoldType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/NpadJoyHoldType.cs @@ -3,6 +3,6 @@ enum NpadJoyHoldType { Vertical, - Horizontal + Horizontal, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/AtomicStorage.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/AtomicStorage.cs index da53e4211..b6bc288e6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/AtomicStorage.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/AtomicStorage.cs @@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common { - struct AtomicStorage where T: unmanaged, ISampledDataStruct + struct AtomicStorage where T : unmanaged, ISampledDataStruct { public ulong SamplingNumber; public T Object; diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/ISampledDataStruct.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/ISampledDataStruct.cs index a382c0c28..ae1997d4e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/ISampledDataStruct.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/ISampledDataStruct.cs @@ -11,9 +11,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common /// - use StructLayoutAttribute (and related attributes) to explicity control how the struct is laid out in memory. /// - ensure that the method ISampledDataStruct.GetSamplingNumberFieldOffset() correctly returns the offset, in bytes, /// to the ulong "Sampling Number" field within the struct. Most types have it as the first field, so the default offset is 0. - /// + /// /// Example: - /// + /// /// /// [StructLayout(LayoutKind.Sequential, Pack = 8)] /// struct DebugPadState : ISampledDataStruct @@ -45,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common if (fieldOffset > 0) { - byteSpan = byteSpan.Slice(fieldOffset); + byteSpan = byteSpan[fieldOffset..]; } ulong value = BinaryPrimitives.ReadUInt64LittleEndian(byteSpan); @@ -58,7 +58,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common return sampledDataStruct switch { Npad.SixAxisSensorState _ => sizeof(ulong), - _ => 0 + _ => 0, }; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/RingLifo.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/RingLifo.cs index ae654d6f8..26ea1cff1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/RingLifo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Common/RingLifo.cs @@ -5,16 +5,16 @@ using System.Threading; namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common { - struct RingLifo where T: unmanaged, ISampledDataStruct + struct RingLifo where T : unmanaged, ISampledDataStruct { private const ulong MaxEntries = 17; -#pragma warning disable CS0169 - private ulong _unused; -#pragma warning restore CS0169 -#pragma warning disable CS0414 +#pragma warning disable IDE0051, CS0169 // Remove unused private member + private readonly ulong _unused; +#pragma warning restore IDE0051, CS0169 +#pragma warning disable CS0414, IDE0052 // Remove unread private member private ulong _bufferCount; -#pragma warning restore CS0414 +#pragma warning restore CS0414, IDE0052 private ulong _index; private ulong _count; private Array17> _storage; @@ -32,7 +32,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static ulong GetNextIndexForWrite(ulong index) + private readonly ulong GetNextIndexForWrite(ulong index) { return (index + 1) % MaxEntries; } @@ -142,7 +142,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common { return new RingLifo { - _bufferCount = MaxEntries + _bufferCount = MaxEntries, }; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/DebugPad/DebugPadAttribute.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/DebugPad/DebugPadAttribute.cs index ec5bd3c88..abc6990b8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/DebugPad/DebugPadAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/DebugPad/DebugPadAttribute.cs @@ -6,6 +6,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugPad enum DebugPadAttribute : uint { None = 0, - Connected = 1 << 0 + Connected = 1 << 0, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/DebugPad/DebugPadButton.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/DebugPad/DebugPadButton.cs index e8f283170..dc713a038 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/DebugPad/DebugPadButton.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/DebugPad/DebugPadButton.cs @@ -19,6 +19,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugPad Left = 1 << 10, Up = 1 << 11, Right = 1 << 12, - Down = 1 << 13 + Down = 1 << 13, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardKey.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardKey.cs index 22df7c791..336037ab1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardKey.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardKey.cs @@ -26,4 +26,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardKeyShift.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardKeyShift.cs index 01c2bb304..46461ad84 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardKeyShift.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardKeyShift.cs @@ -133,6 +133,6 @@ RightControl = 228, RightShift = 229, RightAlt = 230, - RightGui = 231 + RightGui = 231, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardModifier.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardModifier.cs index 839a4e829..ad94619ed 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardModifier.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Keyboard/KeyboardModifier.cs @@ -15,6 +15,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard ScrollLock = 1 << 9, NumLock = 1 << 10, Katakana = 1 << 11, - Hiragana = 1 << 12 + Hiragana = 1 << 12, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Mouse/MouseAttribute.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Mouse/MouseAttribute.cs index 5ffba0d7b..ce3dd9462 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Mouse/MouseAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Mouse/MouseAttribute.cs @@ -7,6 +7,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse { None = 0, Transferable = 1 << 0, - IsConnected = 1 << 1 + IsConnected = 1 << 1, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Mouse/MouseButton.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Mouse/MouseButton.cs index 7e35140c6..3e0259938 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Mouse/MouseButton.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Mouse/MouseButton.cs @@ -10,6 +10,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse Right = 1 << 1, Middle = 1 << 2, Forward = 1 << 3, - Back = 1 << 4 + Back = 1 << 4, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/DeviceType.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/DeviceType.cs index 95b1cb518..259c712b8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/DeviceType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/DeviceType.cs @@ -24,6 +24,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad HandheldLarkNesRight = 1 << 14, Lucia = 1 << 15, - System = 1 << 31 + System = 1 << 31, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadAttribute.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadAttribute.cs index 0960b7bf3..6ad2531f4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadAttribute.cs @@ -11,6 +11,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad IsLeftConnected = 1 << 2, IsLeftWired = 1 << 3, IsRightConnected = 1 << 4, - IsRightWired = 1 << 5 + IsRightWired = 1 << 5, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadBatteryLevel.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadBatteryLevel.cs index e10e55cd8..a84e0259d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadBatteryLevel.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadBatteryLevel.cs @@ -6,6 +6,6 @@ Percent25, Percent50, Percent75, - Percent100 + Percent100, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadButton.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadButton.cs index 5b3e13a72..442d4089b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadButton.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadButton.cs @@ -39,6 +39,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad // FIXME: Probably a button on Lark. Unknown29 = 1 << 29, - HandheldLeftB = 1 << 30 + HandheldLeftB = 1 << 30, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadColorAttribute.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadColorAttribute.cs index 1e547cc8f..1a7846dbc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadColorAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadColorAttribute.cs @@ -4,6 +4,6 @@ { Ok, ReadError, - NoController + NoController, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadCommonState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadCommonState.cs index 64f75ce9a..e1d70a8a2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadCommonState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadCommonState.cs @@ -11,6 +11,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad public AnalogStickState AnalogStickL; public AnalogStickState AnalogStickR; public NpadAttribute Attributes; - private uint _reserved; + private readonly uint _reserved; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadFullKeyColorState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadFullKeyColorState.cs index 990eafb26..92d4a2ae0 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadFullKeyColorState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadFullKeyColorState.cs @@ -6,4 +6,4 @@ public uint FullKeyBody; public uint FullKeyButtons; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadGcTriggerState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadGcTriggerState.cs index bddd6212d..39453984f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadGcTriggerState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadGcTriggerState.cs @@ -6,10 +6,10 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad [StructLayout(LayoutKind.Sequential, Pack = 1)] struct NpadGcTriggerState : ISampledDataStruct { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public ulong SamplingNumber; public uint TriggerL; public uint TriggerR; #pragma warning restore CS0649 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadInternalState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadInternalState.cs index b009f95e5..60d16fd83 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadInternalState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadInternalState.cs @@ -23,7 +23,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad public RingLifo JoyLeftSixAxisSensor; public RingLifo JoyRightSixAxisSensor; public DeviceType DeviceType; - private uint _reserved1; +#pragma warning disable IDE0051 // Remove unused private member + private readonly uint _reserved1; +#pragma warning restore IDE0051 public NpadSystemProperties SystemProperties; public NpadSystemButtonProperties SystemButtonProperties; public NpadBatteryLevel BatteryLevelJoyDual; @@ -31,7 +33,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad public NpadBatteryLevel BatteryLevelJoyRight; public uint AppletFooterUiAttributes; public AppletFooterUiType AppletFooterUiType; - private Reserved2Struct _reserved2; +#pragma warning disable IDE0051 // Remove unused private member + private readonly Reserved2Struct _reserved2; +#pragma warning restore IDE0051 public RingLifo GcTrigger; public NpadLarkType LarkTypeLeftAndMain; public NpadLarkType LarkTypeRight; @@ -39,7 +43,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad public uint Unknown43EC; [StructLayout(LayoutKind.Sequential, Size = 123, Pack = 1)] - private struct Reserved2Struct {} + private struct Reserved2Struct { } public static NpadInternalState Create() { @@ -62,4 +66,4 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadJoyAssignmentMode.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadJoyAssignmentMode.cs index 871c4c5a4..c50abe16e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadJoyAssignmentMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadJoyAssignmentMode.cs @@ -3,6 +3,6 @@ enum NpadJoyAssignmentMode : uint { Dual, - Single + Single, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadJoyColorState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadJoyColorState.cs index 3986dd5e0..6fec613b6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadJoyColorState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadJoyColorState.cs @@ -8,4 +8,4 @@ public uint RightBody; public uint RightButtons; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadLuciaType.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadLuciaType.cs index 951484857..e12e84e4f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadLuciaType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadLuciaType.cs @@ -5,6 +5,6 @@ Invalid, J, E, - U + U, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadState.cs index ed9e7c0df..643234fc2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadState.cs @@ -11,7 +11,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad { return new NpadState { - InternalState = NpadInternalState.Create() + InternalState = NpadInternalState.Create(), }; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadStyleTag.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadStyleTag.cs index f31978e24..d9ecdcd1a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadStyleTag.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadStyleTag.cs @@ -71,6 +71,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad /// /// Generic controller. /// - System = 1 << 30 + System = 1 << 30, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadSystemButtonProperties.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadSystemButtonProperties.cs index 686032714..56a4a80f7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadSystemButtonProperties.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadSystemButtonProperties.cs @@ -6,6 +6,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad enum NpadSystemButtonProperties : uint { None = 0, - IsUnintendedHomeButtonInputProtectionEnabled = 1 << 0 + IsUnintendedHomeButtonInputProtectionEnabled = 1 << 0, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadSystemProperties.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadSystemProperties.cs index 13444555e..817c6c143 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadSystemProperties.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/NpadSystemProperties.cs @@ -19,6 +19,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad IsSlSrButtonOriented = 1 << 12, IsPlusAvailable = 1 << 13, IsMinusAvailable = 1 << 14, - IsDirectionalButtonsAvailable = 1 << 15 + IsDirectionalButtonsAvailable = 1 << 15, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/SixAxisSensorAttribute.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/SixAxisSensorAttribute.cs index 7ed46d981..0190f09d7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/SixAxisSensorAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/SixAxisSensorAttribute.cs @@ -7,6 +7,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad { None = 0, IsConnected = 1 << 0, - IsInterpolated = 1 << 1 + IsInterpolated = 1 << 1, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/SixAxisSensorState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/SixAxisSensorState.cs index 18be32763..25f65a0ef 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/SixAxisSensorState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/Npad/SixAxisSensorState.cs @@ -14,6 +14,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad public HidVector Angle; public Array9 Direction; public SixAxisSensorAttribute Attributes; - private uint _reserved; + private readonly uint _reserved; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/SharedMemory.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/SharedMemory.cs index 48acfc3f3..640076b34 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/SharedMemory.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/SharedMemory.cs @@ -47,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory public static SharedMemory Create() { - SharedMemory result = new SharedMemory + SharedMemory result = new() { DebugPad = RingLifo.Create(), TouchScreen = RingLifo.Create(), diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchAttribute.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchAttribute.cs index d2c5726a5..7c43e6cd4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchAttribute.cs @@ -7,6 +7,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen { None = 0, Start = 1 << 0, - End = 1 << 1 + End = 1 << 1, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchScreenState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchScreenState.cs index cdd4cc45e..5ce51ee3c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchScreenState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchScreenState.cs @@ -9,7 +9,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen { public ulong SamplingNumber; public int TouchesCount; - private int _reserved; + private readonly int _reserved; public Array16 Touches; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchState.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchState.cs index ba621a2b0..908f9ed5e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Types/SharedMemory/TouchScreen/TouchState.cs @@ -3,7 +3,7 @@ struct TouchState { public ulong DeltaTime; -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public TouchAttribute Attribute; #pragma warning restore CS0649 public uint FingerId; @@ -12,8 +12,8 @@ public uint DiameterX; public uint DiameterY; public uint RotationAngle; -#pragma warning disable CS0169 - private uint _reserved; -#pragma warning restore CS0169 +#pragma warning disable CS0169, IDE0051 // Remove unused private member + private readonly uint _reserved; +#pragma warning restore CS0169, IDE0051 } } diff --git a/src/Ryujinx.HLE/HOS/Services/Ins/IReceiverManager.cs b/src/Ryujinx.HLE/HOS/Services/Ins/IReceiverManager.cs index 34d4bdfd7..8ee00d0e9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ins/IReceiverManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ins/IReceiverManager.cs @@ -5,4 +5,4 @@ { public IReceiverManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ins/ISenderManager.cs b/src/Ryujinx.HLE/HOS/Services/Ins/ISenderManager.cs index 38a95ee7b..239c4cc83 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ins/ISenderManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ins/ISenderManager.cs @@ -5,4 +5,4 @@ { public ISenderManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/IpcService.cs b/src/Ryujinx.HLE/HOS/Services/IpcService.cs index 048a68a9e..eb9f6b2fd 100644 --- a/src/Ryujinx.HLE/HOS/Services/IpcService.cs +++ b/src/Ryujinx.HLE/HOS/Services/IpcService.cs @@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS.Services public ServerBase Server { get; private set; } private IpcService _parent; - private IdDictionary _domainObjects; + private readonly IdDictionary _domainObjects; private int _selfId; private bool _isDomain; @@ -106,7 +106,9 @@ namespace Ryujinx.HLE.HOS.Services } } +#pragma warning disable IDE0059 // Remove unnecessary value assignment long sfciMagic = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 int commandId = (int)context.RequestData.ReadInt64(); bool serviceExists = service.CmifCommands.TryGetValue(commandId, out MethodInfo processRequest); @@ -127,9 +129,8 @@ namespace Ryujinx.HLE.HOS.Services { string serviceName; - DummyService dummyService = service as DummyService; - serviceName = (dummyService == null) ? service.GetType().FullName : dummyService.ServiceName; + serviceName = (service is not DummyService dummyService) ? service.GetType().FullName : dummyService.ServiceName; Logger.Warning?.Print(LogClass.KernelIpc, $"Missing service {serviceName}: {commandId} ignored"); } @@ -181,9 +182,8 @@ namespace Ryujinx.HLE.HOS.Services { string serviceName; - DummyService dummyService = this as DummyService; - serviceName = (dummyService == null) ? GetType().FullName : dummyService.ServiceName; + serviceName = (this is not DummyService dummyService) ? GetType().FullName : dummyService.ServiceName; Logger.Warning?.Print(LogClass.KernelIpc, $"Missing service {serviceName}: {commandId} ignored"); } diff --git a/src/Ryujinx.HLE/HOS/Services/Lbl/ILblController.cs b/src/Ryujinx.HLE/HOS/Services/Lbl/ILblController.cs index 65074d5ff..75d787432 100644 --- a/src/Ryujinx.HLE/HOS/Services/Lbl/ILblController.cs +++ b/src/Ryujinx.HLE/HOS/Services/Lbl/ILblController.cs @@ -89,4 +89,4 @@ return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Lbl/LblControllerServer.cs b/src/Ryujinx.HLE/HOS/Services/Lbl/LblControllerServer.cs index b68be1f2f..899e882e5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Lbl/LblControllerServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Lbl/LblControllerServer.cs @@ -3,7 +3,7 @@ [Service("lbl")] class LblControllerServer : ILblController { - private bool _vrModeEnabled; + private bool _vrModeEnabled; private float _currentBrightnessSettingForVrMode; public LblControllerServer(ServiceCtx context) : base(context) { } diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/IMonitorServiceCreator.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/IMonitorServiceCreator.cs index 09dfa78fa..a7e99241c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/IMonitorServiceCreator.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/IMonitorServiceCreator.cs @@ -5,4 +5,4 @@ { public IMonitorServiceCreator(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/ISystemServiceCreator.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/ISystemServiceCreator.cs index b4dac449e..9acfef5c9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/ISystemServiceCreator.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/ISystemServiceCreator.cs @@ -5,4 +5,4 @@ { public ISystemServiceCreator(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/IUserServiceCreator.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/IUserServiceCreator.cs index 4f3094ae5..317b1dbe8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/IUserServiceCreator.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/IUserServiceCreator.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.Ldn return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/Lp2p/IServiceCreator.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/Lp2p/IServiceCreator.cs index 9c9ee3be2..f2fd482dd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/Lp2p/IServiceCreator.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/Lp2p/IServiceCreator.cs @@ -6,4 +6,4 @@ { public IServiceCreator(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/NetworkInterface.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/NetworkInterface.cs index 274b6132c..26696cbeb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/NetworkInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/NetworkInterface.cs @@ -7,15 +7,15 @@ namespace Ryujinx.HLE.HOS.Services.Ldn { internal class NetworkInterface { - public ResultCode NifmState { get; set; } - public KEvent StateChangeEvent { get; private set; } + public ResultCode NifmState { get; set; } + public KEvent StateChangeEvent { get; private set; } private NetworkState _state; public NetworkInterface(Horizon system) { // TODO(Ac_K): Determine where the internal state is set. - NifmState = ResultCode.Success; + NifmState = ResultCode.Success; StateChangeEvent = new KEvent(system.KernelContext); _state = NetworkState.None; @@ -56,4 +56,4 @@ namespace Ryujinx.HLE.HOS.Services.Ldn return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/ResultCode.cs index 87674f7c3..a9f2cbc33 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/ResultCode.cs @@ -2,15 +2,15 @@ namespace Ryujinx.HLE.HOS.Services.Ldn { enum ResultCode { - ModuleId = 203, + ModuleId = 203, ErrorCodeShift = 9, Success = 0, - DeviceDisabled = (22 << ErrorCodeShift) | ModuleId, - InvalidState = (32 << ErrorCodeShift) | ModuleId, - Unknown1 = (48 << ErrorCodeShift) | ModuleId, + DeviceDisabled = (22 << ErrorCodeShift) | ModuleId, + InvalidState = (32 << ErrorCodeShift) | ModuleId, + Unknown1 = (48 << ErrorCodeShift) | ModuleId, InvalidArgument = (96 << ErrorCodeShift) | ModuleId, - InvalidObject = (97 << ErrorCodeShift) | ModuleId, + InvalidObject = (97 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/Types/NetworkState.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/Types/NetworkState.cs index 6ac204833..61fd831df 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/Types/NetworkState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/Types/NetworkState.cs @@ -8,6 +8,6 @@ AccessPointCreated, Station, StationConnected, - Error + Error, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs index f425ddf78..d390a3e68 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs @@ -11,7 +11,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator // TODO(Ac_K): Determine what the hardcoded unknown value is. private const int UnknownValue = 90; - private NetworkInterface _networkInterface; + private readonly NetworkInterface _networkInterface; private int _stateChangeEventHandle = 0; @@ -79,10 +79,10 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator public ResultCode Initialize(ServiceCtx context) { // TODO(Ac_K): Determine what addresses are. - IPAddress unknownAddress1 = new IPAddress(context.RequestData.ReadUInt32()); - IPAddress unknownAddress2 = new IPAddress(context.RequestData.ReadUInt32()); + IPAddress unknownAddress1 = new(context.RequestData.ReadUInt32()); + IPAddress unknownAddress2 = new(context.RequestData.ReadUInt32()); return _networkInterface.Initialize(UnknownValue, version: 1, unknownAddress1, unknownAddress2); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Loader/IDebugMonitorInterface.cs b/src/Ryujinx.HLE/HOS/Services/Loader/IDebugMonitorInterface.cs index 82b24a35c..78c405b4e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Loader/IDebugMonitorInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Loader/IDebugMonitorInterface.cs @@ -5,4 +5,4 @@ { public IDebugMonitorInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Loader/IProcessManagerInterface.cs b/src/Ryujinx.HLE/HOS/Services/Loader/IProcessManagerInterface.cs index 2ecde2ade..693d68dac 100644 --- a/src/Ryujinx.HLE/HOS/Services/Loader/IProcessManagerInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Loader/IProcessManagerInterface.cs @@ -5,4 +5,4 @@ { public IProcessManagerInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Loader/IShellInterface.cs b/src/Ryujinx.HLE/HOS/Services/Loader/IShellInterface.cs index 362f82f03..d2dc57bdb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Loader/IShellInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Loader/IShellInterface.cs @@ -5,4 +5,4 @@ { public IShellInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Loader/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Loader/ResultCode.cs index 170dfa015..ec1166480 100644 --- a/src/Ryujinx.HLE/HOS/Services/Loader/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Loader/ResultCode.cs @@ -1,43 +1,46 @@ -namespace Ryujinx.HLE.HOS.Services.Loader +using System.Diagnostics.CodeAnalysis; + +namespace Ryujinx.HLE.HOS.Services.Loader { + [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")] enum ResultCode { - ModuleId = 9, + ModuleId = 9, ErrorCodeShift = 9, Success = 0, - ArgsTooLong = (1 << ErrorCodeShift) | ModuleId, - MaximumProcessesLoaded = (2 << ErrorCodeShift) | ModuleId, - NPDMTooBig = (3 << ErrorCodeShift) | ModuleId, - InvalidNPDM = (4 << ErrorCodeShift) | ModuleId, - InvalidNSO = (5 << ErrorCodeShift) | ModuleId, - InvalidPath = (6 << ErrorCodeShift) | ModuleId, - AlreadyRegistered = (7 << ErrorCodeShift) | ModuleId, - TitleNotFound = (8 << ErrorCodeShift) | ModuleId, - ACI0TitleIdNotMatchingRangeInACID = (9 << ErrorCodeShift) | ModuleId, - InvalidVersionInNPDM = (10 << ErrorCodeShift) | ModuleId, - InsufficientAddressSpace = (51 << ErrorCodeShift) | ModuleId, - InsufficientNRO = (52 << ErrorCodeShift) | ModuleId, - InvalidNRR = (53 << ErrorCodeShift) | ModuleId, - InvalidSignature = (54 << ErrorCodeShift) | ModuleId, - InsufficientNRORegistrations = (55 << ErrorCodeShift) | ModuleId, - InsufficientNRRRegistrations = (56 << ErrorCodeShift) | ModuleId, - NROAlreadyLoaded = (57 << ErrorCodeShift) | ModuleId, - UnalignedNRRAddress = (81 << ErrorCodeShift) | ModuleId, - BadNRRSize = (82 << ErrorCodeShift) | ModuleId, - NRRNotLoaded = (84 << ErrorCodeShift) | ModuleId, - BadNRRAddress = (85 << ErrorCodeShift) | ModuleId, - BadInitialization = (87 << ErrorCodeShift) | ModuleId, - UnknownACI0Descriptor = (100 << ErrorCodeShift) | ModuleId, - ACI0NotMatchingKernelFlagsDescriptor = (103 << ErrorCodeShift) | ModuleId, - ACI0NotMatchingSyscallMaskDescriptor = (104 << ErrorCodeShift) | ModuleId, - ACI0NotMatchingMapIoOrNormalRangeDescriptor = (106 << ErrorCodeShift) | ModuleId, - ACI0NotMatchingMapNormalPageDescriptor = (107 << ErrorCodeShift) | ModuleId, - ACI0NotMatchingInterruptPairDescriptor = (111 << ErrorCodeShift) | ModuleId, - ACI0NotMatchingApplicationTypeDescriptor = (113 << ErrorCodeShift) | ModuleId, + ArgsTooLong = (1 << ErrorCodeShift) | ModuleId, + MaximumProcessesLoaded = (2 << ErrorCodeShift) | ModuleId, + NPDMTooBig = (3 << ErrorCodeShift) | ModuleId, + InvalidNPDM = (4 << ErrorCodeShift) | ModuleId, + InvalidNSO = (5 << ErrorCodeShift) | ModuleId, + InvalidPath = (6 << ErrorCodeShift) | ModuleId, + AlreadyRegistered = (7 << ErrorCodeShift) | ModuleId, + TitleNotFound = (8 << ErrorCodeShift) | ModuleId, + ACI0TitleIdNotMatchingRangeInACID = (9 << ErrorCodeShift) | ModuleId, + InvalidVersionInNPDM = (10 << ErrorCodeShift) | ModuleId, + InsufficientAddressSpace = (51 << ErrorCodeShift) | ModuleId, + InsufficientNRO = (52 << ErrorCodeShift) | ModuleId, + InvalidNRR = (53 << ErrorCodeShift) | ModuleId, + InvalidSignature = (54 << ErrorCodeShift) | ModuleId, + InsufficientNRORegistrations = (55 << ErrorCodeShift) | ModuleId, + InsufficientNRRRegistrations = (56 << ErrorCodeShift) | ModuleId, + NROAlreadyLoaded = (57 << ErrorCodeShift) | ModuleId, + UnalignedNRRAddress = (81 << ErrorCodeShift) | ModuleId, + BadNRRSize = (82 << ErrorCodeShift) | ModuleId, + NRRNotLoaded = (84 << ErrorCodeShift) | ModuleId, + BadNRRAddress = (85 << ErrorCodeShift) | ModuleId, + BadInitialization = (87 << ErrorCodeShift) | ModuleId, + UnknownACI0Descriptor = (100 << ErrorCodeShift) | ModuleId, + ACI0NotMatchingKernelFlagsDescriptor = (103 << ErrorCodeShift) | ModuleId, + ACI0NotMatchingSyscallMaskDescriptor = (104 << ErrorCodeShift) | ModuleId, + ACI0NotMatchingMapIoOrNormalRangeDescriptor = (106 << ErrorCodeShift) | ModuleId, + ACI0NotMatchingMapNormalPageDescriptor = (107 << ErrorCodeShift) | ModuleId, + ACI0NotMatchingInterruptPairDescriptor = (111 << ErrorCodeShift) | ModuleId, + ACI0NotMatchingApplicationTypeDescriptor = (113 << ErrorCodeShift) | ModuleId, ACI0NotMatchingKernelReleaseVersionDescriptor = (114 << ErrorCodeShift) | ModuleId, - ACI0NotMatchingHandleTableSizeDescriptor = (115 << ErrorCodeShift) | ModuleId, - ACI0NotMatchingDebugFlagsDescriptor = (116 << ErrorCodeShift) | ModuleId + ACI0NotMatchingHandleTableSizeDescriptor = (115 << ErrorCodeShift) | ModuleId, + ACI0NotMatchingDebugFlagsDescriptor = (116 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mig/IService.cs b/src/Ryujinx.HLE/HOS/Services/Mig/IService.cs index 2f6eb99ee..81f858f8f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mig/IService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mig/IService.cs @@ -5,4 +5,4 @@ { public IService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseImpl.cs b/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseImpl.cs index 6d65de95d..d9bcecee1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseImpl.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseImpl.cs @@ -13,17 +13,14 @@ namespace Ryujinx.HLE.HOS.Services.Mii { get { - if (_instance == null) - { - _instance = new DatabaseImpl(); - } + _instance ??= new DatabaseImpl(); return _instance; } } private UtilityImpl _utilityImpl; - private MiiDatabaseManager _miiDatabase; + private readonly MiiDatabaseManager _miiDatabase; private bool _isBroken; public DatabaseImpl() diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseSessionMetadata.cs b/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseSessionMetadata.cs index 6982b0edd..56486c434 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseSessionMetadata.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/DatabaseSessionMetadata.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii { class DatabaseSessionMetadata { - public uint InterfaceVersion; + public uint InterfaceVersion; public ulong UpdateCounter; public SpecialMiiKeyCode MiiKeyCode { get; private set; } @@ -12,8 +12,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii public DatabaseSessionMetadata(ulong updateCounter, SpecialMiiKeyCode miiKeyCode) { InterfaceVersion = 0; - UpdateCounter = updateCounter; - MiiKeyCode = miiKeyCode; + UpdateCounter = updateCounter; + MiiKeyCode = miiKeyCode; } public bool IsInterfaceVersionSupported(uint interfaceVersion) diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Helper.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Helper.cs index b8dbce155..71b9ab43f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Helper.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Helper.cs @@ -39,10 +39,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii return UInt128Utils.FromHex("5279754d69694e780000000000000000"); // RyuMiiNx } +#pragma warning disable IDE0055 // Disable formatting public static ReadOnlySpan Ver3FacelineColorTable => new byte[] { 0, 1, 2, 3, 4, 5 }; public static ReadOnlySpan Ver3HairColorTable => new byte[] { 8, 1, 2, 3, 4, 5, 6, 7 }; public static ReadOnlySpan Ver3EyeColorTable => new byte[] { 8, 9, 10, 11, 12, 13 }; public static ReadOnlySpan Ver3MouthColorTable => new byte[] { 19, 20, 21, 22, 23 }; public static ReadOnlySpan Ver3GlassColorTable => new byte[] { 8, 14, 15, 16, 17, 18, 0 }; +#pragma warning restore IDE0055 } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/IImageDatabaseService.cs b/src/Ryujinx.HLE/HOS/Services/Mii/IImageDatabaseService.cs index 7d65c73fa..0a763da1c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/IImageDatabaseService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/IImageDatabaseService.cs @@ -18,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii bool useHardcodedData = context.RequestData.ReadBoolean(); _imageCount = 0; - _isDirty = false; + _isDirty = false; context.ResponseData.Write(_isDirty); @@ -38,4 +38,4 @@ namespace Ryujinx.HLE.HOS.Services.Mii return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/IStaticService.cs b/src/Ryujinx.HLE/HOS/Services/Mii/IStaticService.cs index a7fc71c96..acf358eea 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/IStaticService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/IStaticService.cs @@ -8,13 +8,13 @@ namespace Ryujinx.HLE.HOS.Services.Mii [Service("mii:u", false)] class IStaticService : IpcService { - private DatabaseImpl _databaseImpl; + private readonly DatabaseImpl _databaseImpl; - private bool _isSystem; + private readonly bool _isSystem; public IStaticService(ServiceCtx context, bool isSystem) { - _isSystem = isSystem; + _isSystem = isSystem; _databaseImpl = DatabaseImpl.Instance; } @@ -29,4 +29,4 @@ namespace Ryujinx.HLE.HOS.Services.Mii return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/MiiDatabaseManager.cs b/src/Ryujinx.HLE/HOS/Services/Mii/MiiDatabaseManager.cs index 682283b04..cb43ed2ad 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/MiiDatabaseManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/MiiDatabaseManager.cs @@ -11,17 +11,17 @@ namespace Ryujinx.HLE.HOS.Services.Mii { class MiiDatabaseManager { - private static bool IsTestModeEnabled = false; - private static uint MountCounter = 0; + private readonly bool _isTestModeEnabled = false; + private uint _mountCounter = 0; - private const ulong DatabaseTestSaveDataId = 0x8000000000000031; - private const ulong DatabaseSaveDataId = 0x8000000000000030; + private const ulong DatabaseTestSaveDataId = 0x8000000000000031; + private const ulong DatabaseSaveDataId = 0x8000000000000030; - private static U8String DatabasePath = new U8String("mii:/MiiDatabase.dat"); - private static U8String MountName = new U8String("mii"); + private readonly U8String _databasePath = new("mii:/MiiDatabase.dat"); + private readonly U8String _mountName = new("mii"); private NintendoFigurineDatabase _database; - private bool _isDirty; + private bool _isDirty; private HorizonClient _horizonClient; @@ -29,8 +29,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii public MiiDatabaseManager() { - _database = new NintendoFigurineDatabase(); - _isDirty = false; + _database = new NintendoFigurineDatabase(); + _isDirty = false; UpdateCounter = 0; } @@ -106,50 +106,63 @@ namespace Ryujinx.HLE.HOS.Services.Mii private Result MountSave() { - if (MountCounter != 0) + if (_mountCounter != 0) { - MountCounter++; + _mountCounter++; return Result.Success; } - ulong saveDataId = IsTestModeEnabled ? DatabaseTestSaveDataId : DatabaseSaveDataId; + ulong saveDataId = _isTestModeEnabled ? DatabaseTestSaveDataId : DatabaseSaveDataId; - Result result = _horizonClient.Fs.MountSystemSaveData(MountName, SaveDataSpaceId.System, saveDataId); + Result result = _horizonClient.Fs.MountSystemSaveData(_mountName, SaveDataSpaceId.System, saveDataId); if (result.IsFailure()) { if (!ResultFs.TargetNotFound.Includes(result)) + { return result; + } - if (IsTestModeEnabled) + if (_isTestModeEnabled) +#pragma warning disable CS0162 { result = _horizonClient.Fs.CreateSystemSaveData(saveDataId, 0x10000, 0x10000, SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData); - if (result.IsFailure()) return result; + if (result.IsFailure()) + { + return result; + } } +#pragma warning restore CS0162 else { result = _horizonClient.Fs.CreateSystemSaveData(saveDataId, SystemProgramId.Ns.Value, 0x10000, 0x10000, SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData); - if (result.IsFailure()) return result; + if (result.IsFailure()) + { + return result; + } } - result = _horizonClient.Fs.MountSystemSaveData(MountName, SaveDataSpaceId.System, saveDataId); - if (result.IsFailure()) return result; + result = _horizonClient.Fs.MountSystemSaveData(_mountName, SaveDataSpaceId.System, saveDataId); + if (result.IsFailure()) + { + return result; + } } if (result == Result.Success) { - MountCounter++; + _mountCounter++; } return result; } public ResultCode DeleteFile() { - ResultCode result = (ResultCode)_horizonClient.Fs.DeleteFile(DatabasePath).Value; + ResultCode result = (ResultCode)_horizonClient.Fs.DeleteFile(_databasePath).Value; - _horizonClient.Fs.Commit(MountName); + _horizonClient.Fs.Commit(_mountName); return result; } @@ -158,7 +171,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii { isBroken = false; - if (MountCounter == 0) + if (_mountCounter == 0) { return ResultCode.InvalidArgument; } @@ -167,7 +180,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii ResetDatabase(); - Result result = _horizonClient.Fs.OpenFile(out FileHandle handle, DatabasePath, OpenMode.Read); + Result result = _horizonClient.Fs.OpenFile(out FileHandle handle, _databasePath, OpenMode.Read); if (result.IsSuccess()) { @@ -213,11 +226,11 @@ namespace Ryujinx.HLE.HOS.Services.Mii private Result ForceSaveDatabase() { - Result result = _horizonClient.Fs.CreateFile(DatabasePath, Unsafe.SizeOf()); + Result result = _horizonClient.Fs.CreateFile(_databasePath, Unsafe.SizeOf()); if (result.IsSuccess() || ResultFs.PathAlreadyExists.Includes(result)) { - result = _horizonClient.Fs.OpenFile(out FileHandle handle, DatabasePath, OpenMode.Write); + result = _horizonClient.Fs.OpenFile(out FileHandle handle, _databasePath, OpenMode.Write); if (result.IsSuccess()) { @@ -230,15 +243,15 @@ namespace Ryujinx.HLE.HOS.Services.Mii { _horizonClient.Fs.CloseFile(handle); - result = _horizonClient.Fs.DeleteFile(DatabasePath); + result = _horizonClient.Fs.DeleteFile(_databasePath); if (result.IsSuccess()) { - result = _horizonClient.Fs.CreateFile(DatabasePath, Unsafe.SizeOf()); + result = _horizonClient.Fs.CreateFile(_databasePath, Unsafe.SizeOf()); if (result.IsSuccess()) { - result = _horizonClient.Fs.OpenFile(out handle, DatabasePath, OpenMode.Write); + result = _horizonClient.Fs.OpenFile(out handle, _databasePath, OpenMode.Write); } } @@ -259,7 +272,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii { _isDirty = false; - result = _horizonClient.Fs.Commit(MountName); + result = _horizonClient.Fs.Commit(_mountName); } return result; diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Mii/ResultCode.cs index 4a4c0c239..8611d5af1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/ResultCode.cs @@ -2,29 +2,29 @@ { public enum ResultCode { - ModuleId = 126, + ModuleId = 126, ErrorCodeShift = 9, Success = 0, - InvalidArgument = (1 << ErrorCodeShift) | ModuleId, - BufferTooSmall = (2 << ErrorCodeShift) | ModuleId, - NotUpdated = (3 << ErrorCodeShift) | ModuleId, - NotFound = (4 << ErrorCodeShift) | ModuleId, - DatabaseFull = (5 << ErrorCodeShift) | ModuleId, - InvalidDatabaseSignatureValue = (67 << ErrorCodeShift) | ModuleId, - InvalidDatabaseEntryCount = (69 << ErrorCodeShift) | ModuleId, - InvalidCharInfo = (100 << ErrorCodeShift) | ModuleId, - InvalidCrc = (101 << ErrorCodeShift) | ModuleId, - InvalidDeviceCrc = (102 << ErrorCodeShift) | ModuleId, - InvalidDatabaseMagic = (103 << ErrorCodeShift) | ModuleId, - InvalidDatabaseVersion = (104 << ErrorCodeShift) | ModuleId, - InvalidDatabaseSize = (105 << ErrorCodeShift) | ModuleId, - InvalidCreateId = (106 << ErrorCodeShift) | ModuleId, - InvalidCoreData = (108 << ErrorCodeShift) | ModuleId, - InvalidStoreData = (109 << ErrorCodeShift) | ModuleId, - InvalidOperationOnSpecialMii = (202 << ErrorCodeShift) | ModuleId, - PermissionDenied = (203 << ErrorCodeShift) | ModuleId, - TestModeNotEnabled = (204 << ErrorCodeShift) | ModuleId + InvalidArgument = (1 << ErrorCodeShift) | ModuleId, + BufferTooSmall = (2 << ErrorCodeShift) | ModuleId, + NotUpdated = (3 << ErrorCodeShift) | ModuleId, + NotFound = (4 << ErrorCodeShift) | ModuleId, + DatabaseFull = (5 << ErrorCodeShift) | ModuleId, + InvalidDatabaseSignatureValue = (67 << ErrorCodeShift) | ModuleId, + InvalidDatabaseEntryCount = (69 << ErrorCodeShift) | ModuleId, + InvalidCharInfo = (100 << ErrorCodeShift) | ModuleId, + InvalidCrc = (101 << ErrorCodeShift) | ModuleId, + InvalidDeviceCrc = (102 << ErrorCodeShift) | ModuleId, + InvalidDatabaseMagic = (103 << ErrorCodeShift) | ModuleId, + InvalidDatabaseVersion = (104 << ErrorCodeShift) | ModuleId, + InvalidDatabaseSize = (105 << ErrorCodeShift) | ModuleId, + InvalidCreateId = (106 << ErrorCodeShift) | ModuleId, + InvalidCoreData = (108 << ErrorCodeShift) | ModuleId, + InvalidStoreData = (109 << ErrorCodeShift) | ModuleId, + InvalidOperationOnSpecialMii = (202 << ErrorCodeShift) | ModuleId, + PermissionDenied = (203 << ErrorCodeShift) | ModuleId, + TestModeNotEnabled = (204 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/StaticService/DatabaseServiceImpl.cs b/src/Ryujinx.HLE/HOS/Services/Mii/StaticService/DatabaseServiceImpl.cs index 4b5ed0d0c..0d286e1cc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/StaticService/DatabaseServiceImpl.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/StaticService/DatabaseServiceImpl.cs @@ -6,9 +6,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService { class DatabaseServiceImpl : IDatabaseService { - private DatabaseImpl _database; - private DatabaseSessionMetadata _metadata; - private bool _isSystem; + private readonly DatabaseImpl _database; + private readonly DatabaseSessionMetadata _metadata; + private readonly bool _isSystem; public DatabaseServiceImpl(DatabaseImpl database, bool isSystem, SpecialMiiKeyCode miiKeyCode) { diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/StaticService/IDatabaseService.cs b/src/Ryujinx.HLE/HOS/Services/Mii/StaticService/IDatabaseService.cs index e95364be8..051921f50 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/StaticService/IDatabaseService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/StaticService/IDatabaseService.cs @@ -51,7 +51,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService ResultCode result = Get(flag, out int count, elementsSpan); - elementsSpan = elementsSpan.Slice(0, count); + elementsSpan = elementsSpan[..count]; context.ResponseData.Write(count); @@ -72,7 +72,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService ResultCode result = Get1(flag, out int count, elementsSpan); - elementsSpan = elementsSpan.Slice(0, count); + elementsSpan = elementsSpan[..count]; context.ResponseData.Write(count); @@ -85,8 +85,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService // UpdateLatest(nn::mii::CharInfo old_char_info, SourceFlag flag) -> nn::mii::CharInfo public ResultCode UpdateLatest(ServiceCtx context) { - CharInfo oldCharInfo = context.RequestData.ReadStruct(); - SourceFlag flag = (SourceFlag)context.RequestData.ReadInt32(); + CharInfo oldCharInfo = context.RequestData.ReadStruct(); + SourceFlag flag = (SourceFlag)context.RequestData.ReadInt32(); ResultCode result = UpdateLatest(oldCharInfo, flag, out CharInfo newCharInfo); @@ -99,9 +99,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService // BuildRandom(Age age, Gender gender, Race race) -> nn::mii::CharInfo public ResultCode BuildRandom(ServiceCtx context) { - Age age = (Age)context.RequestData.ReadInt32(); + Age age = (Age)context.RequestData.ReadInt32(); Gender gender = (Gender)context.RequestData.ReadInt32(); - Race race = (Race)context.RequestData.ReadInt32(); + Race race = (Race)context.RequestData.ReadInt32(); ResultCode result = BuildRandom(age, gender, race, out CharInfo charInfo); @@ -135,7 +135,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService ResultCode result = Get2(flag, out int count, elementsSpan); - elementsSpan = elementsSpan.Slice(0, count); + elementsSpan = elementsSpan[..count]; context.ResponseData.Write(count); @@ -156,7 +156,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService ResultCode result = Get3(flag, out int count, elementsSpan); - elementsSpan = elementsSpan.Slice(0, count); + elementsSpan = elementsSpan[..count]; context.ResponseData.Write(count); @@ -169,8 +169,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService // UpdateLatest1(nn::mii::StoreData old_store_data, SourceFlag flag) -> nn::mii::StoreData public ResultCode UpdateLatest1(ServiceCtx context) { - StoreData oldStoreData = context.RequestData.ReadStruct(); - SourceFlag flag = (SourceFlag)context.RequestData.ReadInt32(); + StoreData oldStoreData = context.RequestData.ReadStruct(); + SourceFlag flag = (SourceFlag)context.RequestData.ReadInt32(); ResultCode result = UpdateLatest1(oldStoreData, flag, out StoreData newStoreData); @@ -183,8 +183,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService // FindIndex(nn::mii::CreateId create_id, bool is_special) -> s32 public ResultCode FindIndex(ServiceCtx context) { - CreateId createId = context.RequestData.ReadStruct(); - bool isSpecial = context.RequestData.ReadBoolean(); + CreateId createId = context.RequestData.ReadStruct(); + bool isSpecial = context.RequestData.ReadBoolean(); ResultCode result = FindIndex(createId, isSpecial, out int index); @@ -198,7 +198,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService public ResultCode Move(ServiceCtx context) { CreateId createId = context.RequestData.ReadStruct(); - int newIndex = context.RequestData.ReadInt32(); + int newIndex = context.RequestData.ReadInt32(); return Move(createId, newIndex); } @@ -358,12 +358,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService return new Span(rawData); } - private Span CreateSpanFromBuffer(ServiceCtx context, IpcBuffDesc ipcBuff, bool isOutput) where T: unmanaged + private Span CreateSpanFromBuffer(ServiceCtx context, IpcBuffDesc ipcBuff, bool isOutput) where T : unmanaged { return MemoryMarshal.Cast(CreateByteSpanFromBuffer(context, ipcBuff, isOutput)); } - private void WriteSpanToBuffer(ServiceCtx context, IpcBuffDesc ipcBuff, Span span) where T: unmanaged + private void WriteSpanToBuffer(ServiceCtx context, IpcBuffDesc ipcBuff, Span span) where T : unmanaged { Span rawData = MemoryMarshal.Cast(span); diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Age.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Age.cs index 7beb6ec06..a443ad09a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Age.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Age.cs @@ -5,6 +5,6 @@ Young, Normal, Old, - All + All, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/BeardType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/BeardType.cs index a028b9be4..85fda6713 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/BeardType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/BeardType.cs @@ -9,7 +9,7 @@ LionsMane, Full, - Min = 0, - Max = 5 + Min = None, + Max = Full, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CharInfo.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CharInfo.cs index 256ec9e06..14b616870 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CharInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CharInfo.cs @@ -59,11 +59,11 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public byte MoleY; public byte Reserved; - byte IStoredData.Type => Type; + readonly byte IStoredData.Type => Type; - CreateId IStoredData.CreateId => CreateId; + readonly CreateId IStoredData.CreateId => CreateId; - public ResultCode InvalidData => ResultCode.InvalidCharInfo; + public readonly ResultCode InvalidData => ResultCode.InvalidCharInfo; public bool IsValid() { @@ -72,118 +72,271 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public uint Verify() { - if (!CreateId.IsValid) return 50; - if (!Nickname.IsValid()) return 51; - if ((byte)FontRegion > 3) return 23; - if (FavoriteColor > 11) return 22; - if (Gender > Gender.Max) return 24; - if ((sbyte)Height < 0) return 32; - if ((sbyte)Build < 0) return 3; - if (Type > 1) return 53; - if (RegionMove > 3) return 49; - if (FacelineType > FacelineType.Max) return 21; - if (FacelineColor > FacelineColor.Max) return 18; - if (FacelineWrinkle > FacelineWrinkle.Max) return 20; - if (FacelineMake > FacelineMake.Max) return 19; - if (HairType > HairType.Max) return 31; - if (HairColor > CommonColor.Max) return 29; - if (HairFlip > HairFlip.Max) return 30; - if (EyeType > EyeType.Max) return 8; - if (EyeColor > CommonColor.Max) return 5; - if (EyeScale > 7) return 7; - if (EyeAspect > 6) return 4; - if (EyeRotate > 7) return 6; - if (EyeX > 12) return 9; - if (EyeY > 18) return 10; - if (EyebrowType > EyebrowType.Max) return 15; - if (EyebrowColor > CommonColor.Max) return 12; - if (EyebrowScale > 8) return 14; - if (EyebrowAspect > 6) return 11; - if (EyebrowRotate > 11) return 13; - if (EyebrowX > 12) return 16; - if (EyebrowY - 3 > 15) return 17; - if (NoseType > NoseType.Max) return 47; - if (NoseScale > 8) return 46; - if (NoseY> 18) return 48; - if (MouthType > MouthType.Max) return 40; - if (MouthColor > CommonColor.Max) return 38; - if (MouthScale > 8) return 39; - if (MouthAspect > 6) return 37; - if (MouthY > 18) return 41; - if (BeardColor > CommonColor.Max) return 1; - if (BeardType > BeardType.Max) return 2; - if (MustacheType > MustacheType.Max) return 43; - if (MustacheScale > 8) return 42; - if (MustacheY > 16) return 44; - if (GlassType > GlassType.Max) return 27; - if (GlassColor > CommonColor.Max) return 25; - if (GlassScale > 7) return 26; - if (GlassY > 20) return 28; - if (MoleType > MoleType.Max) return 34; - if (MoleScale > 8) return 33; - if (MoleX > 16) return 35; - if (MoleY >= 31) return 36; + if (!CreateId.IsValid) + { + return 50; + } + if (!Nickname.IsValid()) + { + return 51; + } + if ((byte)FontRegion > 3) + { + return 23; + } + if (FavoriteColor > 11) + { + return 22; + } + if (Gender > Gender.Max) + { + return 24; + } + if ((sbyte)Height < 0) + { + return 32; + } + if ((sbyte)Build < 0) + { + return 3; + } + if (Type > 1) + { + return 53; + } + if (RegionMove > 3) + { + return 49; + } + if (FacelineType > FacelineType.Max) + { + return 21; + } + if (FacelineColor > FacelineColor.Max) + { + return 18; + } + if (FacelineWrinkle > FacelineWrinkle.Max) + { + return 20; + } + if (FacelineMake > FacelineMake.Max) + { + return 19; + } + if (HairType > HairType.Max) + { + return 31; + } + if (HairColor > CommonColor.Max) + { + return 29; + } + if (HairFlip > HairFlip.Max) + { + return 30; + } + if (EyeType > EyeType.Max) + { + return 8; + } + if (EyeColor > CommonColor.Max) + { + return 5; + } + if (EyeScale > 7) + { + return 7; + } + if (EyeAspect > 6) + { + return 4; + } + if (EyeRotate > 7) + { + return 6; + } + if (EyeX > 12) + { + return 9; + } + if (EyeY > 18) + { + return 10; + } + if (EyebrowType > EyebrowType.Max) + { + return 15; + } + if (EyebrowColor > CommonColor.Max) + { + return 12; + } + if (EyebrowScale > 8) + { + return 14; + } + if (EyebrowAspect > 6) + { + return 11; + } + if (EyebrowRotate > 11) + { + return 13; + } + if (EyebrowX > 12) + { + return 16; + } + if (EyebrowY - 3 > 15) + { + return 17; + } + if (NoseType > NoseType.Max) + { + return 47; + } + if (NoseScale > 8) + { + return 46; + } + if (NoseY > 18) + { + return 48; + } + if (MouthType > MouthType.Max) + { + return 40; + } + if (MouthColor > CommonColor.Max) + { + return 38; + } + if (MouthScale > 8) + { + return 39; + } + if (MouthAspect > 6) + { + return 37; + } + if (MouthY > 18) + { + return 41; + } + if (BeardColor > CommonColor.Max) + { + return 1; + } + if (BeardType > BeardType.Max) + { + return 2; + } + if (MustacheType > MustacheType.Max) + { + return 43; + } + if (MustacheScale > 8) + { + return 42; + } + if (MustacheY > 16) + { + return 44; + } + if (GlassType > GlassType.Max) + { + return 27; + } + if (GlassColor > CommonColor.Max) + { + return 25; + } + if (GlassScale > 7) + { + return 26; + } + if (GlassY > 20) + { + return 28; + } + if (MoleType > MoleType.Max) + { + return 34; + } + if (MoleScale > 8) + { + return 33; + } + if (MoleX > 16) + { + return 35; + } + if (MoleY >= 31) + { + return 36; + } return 0; } public void SetFromStoreData(StoreData storeData) { - Nickname = storeData.CoreData.Nickname; - CreateId = storeData.CreateId; - FontRegion = storeData.CoreData.FontRegion; - FavoriteColor = storeData.CoreData.FavoriteColor; - Gender = storeData.CoreData.Gender; - Height = storeData.CoreData.Height; - Build = storeData.CoreData.Build; - Type = storeData.CoreData.Type; - RegionMove = storeData.CoreData.RegionMove; - FacelineType = storeData.CoreData.FacelineType; - FacelineColor = storeData.CoreData.FacelineColor; + Nickname = storeData.CoreData.Nickname; + CreateId = storeData.CreateId; + FontRegion = storeData.CoreData.FontRegion; + FavoriteColor = storeData.CoreData.FavoriteColor; + Gender = storeData.CoreData.Gender; + Height = storeData.CoreData.Height; + Build = storeData.CoreData.Build; + Type = storeData.CoreData.Type; + RegionMove = storeData.CoreData.RegionMove; + FacelineType = storeData.CoreData.FacelineType; + FacelineColor = storeData.CoreData.FacelineColor; FacelineWrinkle = storeData.CoreData.FacelineWrinkle; - FacelineMake = storeData.CoreData.FacelineMake; - HairType = storeData.CoreData.HairType; - HairColor = storeData.CoreData.HairColor; - HairFlip = storeData.CoreData.HairFlip; - EyeType = storeData.CoreData.EyeType; - EyeColor = storeData.CoreData.EyeColor; - EyeScale = storeData.CoreData.EyeScale; - EyeAspect = storeData.CoreData.EyeAspect; - EyeRotate = storeData.CoreData.EyeRotate; - EyeX = storeData.CoreData.EyeX; - EyeY = storeData.CoreData.EyeY; - EyebrowType = storeData.CoreData.EyebrowType; - EyebrowColor = storeData.CoreData.EyebrowColor; - EyebrowScale = storeData.CoreData.EyebrowScale; - EyebrowAspect = storeData.CoreData.EyebrowAspect; - EyebrowRotate = storeData.CoreData.EyebrowRotate; - EyebrowX = storeData.CoreData.EyebrowX; - EyebrowY = storeData.CoreData.EyebrowY; - NoseType = storeData.CoreData.NoseType; - NoseScale = storeData.CoreData.NoseScale; - NoseY = storeData.CoreData.NoseY; - MouthType = storeData.CoreData.MouthType; - MouthColor = storeData.CoreData.MouthColor; - MouthScale = storeData.CoreData.MouthScale; - MouthAspect = storeData.CoreData.MouthAspect; - MouthY = storeData.CoreData.MouthY; - BeardColor = storeData.CoreData.BeardColor; - BeardType = storeData.CoreData.BeardType; - MustacheType = storeData.CoreData.MustacheType; - MustacheScale = storeData.CoreData.MustacheScale; - MustacheY = storeData.CoreData.MustacheY; - GlassType = storeData.CoreData.GlassType; - GlassColor = storeData.CoreData.GlassColor; - GlassScale = storeData.CoreData.GlassScale; - GlassY = storeData.CoreData.GlassY; - MoleType = storeData.CoreData.MoleType; - MoleScale = storeData.CoreData.MoleScale; - MoleX = storeData.CoreData.MoleX; - MoleY = storeData.CoreData.MoleY; - Reserved = 0; + FacelineMake = storeData.CoreData.FacelineMake; + HairType = storeData.CoreData.HairType; + HairColor = storeData.CoreData.HairColor; + HairFlip = storeData.CoreData.HairFlip; + EyeType = storeData.CoreData.EyeType; + EyeColor = storeData.CoreData.EyeColor; + EyeScale = storeData.CoreData.EyeScale; + EyeAspect = storeData.CoreData.EyeAspect; + EyeRotate = storeData.CoreData.EyeRotate; + EyeX = storeData.CoreData.EyeX; + EyeY = storeData.CoreData.EyeY; + EyebrowType = storeData.CoreData.EyebrowType; + EyebrowColor = storeData.CoreData.EyebrowColor; + EyebrowScale = storeData.CoreData.EyebrowScale; + EyebrowAspect = storeData.CoreData.EyebrowAspect; + EyebrowRotate = storeData.CoreData.EyebrowRotate; + EyebrowX = storeData.CoreData.EyebrowX; + EyebrowY = storeData.CoreData.EyebrowY; + NoseType = storeData.CoreData.NoseType; + NoseScale = storeData.CoreData.NoseScale; + NoseY = storeData.CoreData.NoseY; + MouthType = storeData.CoreData.MouthType; + MouthColor = storeData.CoreData.MouthColor; + MouthScale = storeData.CoreData.MouthScale; + MouthAspect = storeData.CoreData.MouthAspect; + MouthY = storeData.CoreData.MouthY; + BeardColor = storeData.CoreData.BeardColor; + BeardType = storeData.CoreData.BeardType; + MustacheType = storeData.CoreData.MustacheType; + MustacheScale = storeData.CoreData.MustacheScale; + MustacheY = storeData.CoreData.MustacheY; + GlassType = storeData.CoreData.GlassType; + GlassColor = storeData.CoreData.GlassColor; + GlassScale = storeData.CoreData.GlassScale; + GlassY = storeData.CoreData.GlassY; + MoleType = storeData.CoreData.MoleType; + MoleScale = storeData.CoreData.MoleScale; + MoleX = storeData.CoreData.MoleX; + MoleY = storeData.CoreData.MoleY; + Reserved = 0; } - public void SetSource(Source source) + public readonly void SetSource(Source source) { // Only implemented for Element variants. } @@ -198,12 +351,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types return !x.Equals(y); } - public override bool Equals(object obj) + public readonly override bool Equals(object obj) { return obj is CharInfo charInfo && Equals(charInfo); } - public bool Equals(CharInfo cmpObj) + public readonly bool Equals(CharInfo cmpObj) { if (!cmpObj.IsValid()) { @@ -267,9 +420,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types return result; } - public override int GetHashCode() + public readonly override int GetHashCode() { - HashCode hashCode = new HashCode(); + HashCode hashCode = new(); hashCode.Add(Nickname); hashCode.Add(CreateId); diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CharInfoElement.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CharInfoElement.cs index f1f850fd2..fead4861a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CharInfoElement.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CharInfoElement.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types struct CharInfoElement : IElement { public CharInfo CharInfo; - public Source Source; + public Source Source; public void SetFromStoreData(StoreData storeData) { diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CommonColor.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CommonColor.cs index 8b613850a..3f61232ce 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CommonColor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CommonColor.cs @@ -4,6 +4,6 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types enum CommonColor : byte { Min = 0, - Max = 99 + Max = 99, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CoreData.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CoreData.cs index abf18e36e..00e49ecb9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CoreData.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CoreData.cs @@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public void SetDefault() { - Storage.Fill(0); + Storage.Clear(); Nickname = Nickname.Default; } @@ -374,18 +374,18 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public Span GetNicknameStorage() { - return Storage.Slice(0x1c); + return Storage[0x1c..]; } public Nickname Nickname { get => Nickname.FromBytes(GetNicknameStorage()); - set => value.Raw.Slice(0, 20).CopyTo(GetNicknameStorage()); + set => value.Raw[..20].CopyTo(GetNicknameStorage()); } public static CoreData BuildRandom(UtilityImpl utilImpl, Age age, Gender gender, Race race) { - CoreData coreData = new CoreData(); + CoreData coreData = new(); coreData.SetDefault(); @@ -439,29 +439,29 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types int indexFor4 = 3 * (int)age + 9 * (int)gender + (int)race; - var facelineTypeInfo = RandomMiiFacelineArray[indexFor4]; - var facelineColorInfo = RandomMiiFacelineColorArray[3 * (int)gender + (int)race]; + var facelineTypeInfo = RandomMiiFacelineArray[indexFor4]; + var facelineColorInfo = RandomMiiFacelineColorArray[3 * (int)gender + (int)race]; var facelineWrinkleInfo = RandomMiiFacelineWrinkleArray[indexFor4]; - var facelineMakeInfo = RandomMiiFacelineMakeArray[indexFor4]; - var hairTypeInfo = RandomMiiHairTypeArray[indexFor4]; - var hairColorInfo = RandomMiiHairColorArray[3 * (int)race + (int)age]; - var eyeTypeInfo = RandomMiiEyeTypeArray[indexFor4]; - var eyeColorInfo = RandomMiiEyeColorArray[(int)race]; - var eyebrowTypeInfo = RandomMiiEyebrowTypeArray[indexFor4]; - var noseTypeInfo = RandomMiiNoseTypeArray[indexFor4]; - var mouthTypeInfo = RandomMiiMouthTypeArray[indexFor4]; - var glassTypeInfo = RandomMiiGlassTypeArray[(int)age]; + var facelineMakeInfo = RandomMiiFacelineMakeArray[indexFor4]; + var hairTypeInfo = RandomMiiHairTypeArray[indexFor4]; + var hairColorInfo = RandomMiiHairColorArray[3 * (int)race + (int)age]; + var eyeTypeInfo = RandomMiiEyeTypeArray[indexFor4]; + var eyeColorInfo = RandomMiiEyeColorArray[(int)race]; + var eyebrowTypeInfo = RandomMiiEyebrowTypeArray[indexFor4]; + var noseTypeInfo = RandomMiiNoseTypeArray[indexFor4]; + var mouthTypeInfo = RandomMiiMouthTypeArray[indexFor4]; + var glassTypeInfo = RandomMiiGlassTypeArray[(int)age]; // Faceline - coreData.FacelineType = (FacelineType)facelineTypeInfo.Values[utilImpl.GetRandom(facelineTypeInfo.ValuesCount)]; - coreData.FacelineColor = (FacelineColor)Helper.Ver3FacelineColorTable[facelineColorInfo.Values[utilImpl.GetRandom(facelineColorInfo.ValuesCount)]]; + coreData.FacelineType = (FacelineType)facelineTypeInfo.Values[utilImpl.GetRandom(facelineTypeInfo.ValuesCount)]; + coreData.FacelineColor = (FacelineColor)Helper.Ver3FacelineColorTable[facelineColorInfo.Values[utilImpl.GetRandom(facelineColorInfo.ValuesCount)]]; coreData.FacelineWrinkle = (FacelineWrinkle)facelineWrinkleInfo.Values[utilImpl.GetRandom(facelineWrinkleInfo.ValuesCount)]; - coreData.FacelineMake = (FacelineMake)facelineMakeInfo.Values[utilImpl.GetRandom(facelineMakeInfo.ValuesCount)]; + coreData.FacelineMake = (FacelineMake)facelineMakeInfo.Values[utilImpl.GetRandom(facelineMakeInfo.ValuesCount)]; // Hair - coreData.HairType = (HairType)hairTypeInfo.Values[utilImpl.GetRandom(hairTypeInfo.ValuesCount)]; + coreData.HairType = (HairType)hairTypeInfo.Values[utilImpl.GetRandom(hairTypeInfo.ValuesCount)]; coreData.HairColor = (CommonColor)Helper.Ver3HairColorTable[hairColorInfo.Values[utilImpl.GetRandom(hairColorInfo.ValuesCount)]]; - coreData.HairFlip = (HairFlip)utilImpl.GetRandom((int)HairFlip.Max + 1); + coreData.HairFlip = (HairFlip)utilImpl.GetRandom((int)HairFlip.Max + 1); // Eye coreData.EyeType = (EyeType)eyeTypeInfo.Values[utilImpl.GetRandom(eyeTypeInfo.ValuesCount)]; @@ -470,56 +470,56 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types int eyeRotateKey2 = gender != Gender.Male ? 3 : 4; byte eyeRotateOffset = (byte)(32 - EyeRotateTable[eyeRotateKey1] + eyeRotateKey2); - byte eyeRotate = (byte)(32 - EyeRotateTable[(int)coreData.EyeType]); + byte eyeRotate = (byte)(32 - EyeRotateTable[(int)coreData.EyeType]); - coreData.EyeColor = (CommonColor)Helper.Ver3EyeColorTable[eyeColorInfo.Values[utilImpl.GetRandom(eyeColorInfo.ValuesCount)]]; - coreData.EyeScale = 4; + coreData.EyeColor = (CommonColor)Helper.Ver3EyeColorTable[eyeColorInfo.Values[utilImpl.GetRandom(eyeColorInfo.ValuesCount)]]; + coreData.EyeScale = 4; coreData.EyeAspect = 3; coreData.EyeRotate = (byte)(eyeRotateOffset - eyeRotate); - coreData.EyeX = 2; - coreData.EyeY = (byte)(axisY + 12); + coreData.EyeX = 2; + coreData.EyeY = (byte)(axisY + 12); // Eyebrow coreData.EyebrowType = (EyebrowType)eyebrowTypeInfo.Values[utilImpl.GetRandom(eyebrowTypeInfo.ValuesCount)]; int eyebrowRotateKey = race == Race.Asian ? 6 : 0; - int eyebrowY = race == Race.Asian ? 9 : 10; + int eyebrowY = race == Race.Asian ? 9 : 10; byte eyebrowRotateOffset = (byte)(32 - EyebrowRotateTable[eyebrowRotateKey] + 6); - byte eyebrowRotate = (byte)(32 - EyebrowRotateTable[(int)coreData.EyebrowType]); + byte eyebrowRotate = (byte)(32 - EyebrowRotateTable[(int)coreData.EyebrowType]); - coreData.EyebrowColor = coreData.HairColor; - coreData.EyebrowScale = 4; + coreData.EyebrowColor = coreData.HairColor; + coreData.EyebrowScale = 4; coreData.EyebrowAspect = 3; coreData.EyebrowRotate = (byte)(eyebrowRotateOffset - eyebrowRotate); - coreData.EyebrowX = 2; - coreData.EyebrowY = (byte)(axisY + eyebrowY); + coreData.EyebrowX = 2; + coreData.EyebrowY = (byte)(axisY + eyebrowY); // Nose int noseScale = gender == Gender.Female ? 3 : 4; - coreData.NoseType = (NoseType)noseTypeInfo.Values[utilImpl.GetRandom(noseTypeInfo.ValuesCount)]; + coreData.NoseType = (NoseType)noseTypeInfo.Values[utilImpl.GetRandom(noseTypeInfo.ValuesCount)]; coreData.NoseScale = (byte)noseScale; - coreData.NoseY = (byte)(axisY + 9); + coreData.NoseY = (byte)(axisY + 9); // Mouth int mouthColor = gender == Gender.Female ? utilImpl.GetRandom(0, 4) : 0; - coreData.MouthType = (MouthType)mouthTypeInfo.Values[utilImpl.GetRandom(mouthTypeInfo.ValuesCount)]; - coreData.MouthColor = (CommonColor)Helper.Ver3MouthColorTable[mouthColor]; - coreData.MouthScale = 4; + coreData.MouthType = (MouthType)mouthTypeInfo.Values[utilImpl.GetRandom(mouthTypeInfo.ValuesCount)]; + coreData.MouthColor = (CommonColor)Helper.Ver3MouthColorTable[mouthColor]; + coreData.MouthScale = 4; coreData.MouthAspect = 3; - coreData.MouthY = (byte)(axisY + 13); + coreData.MouthY = (byte)(axisY + 13); // Beard & Mustache - coreData.BeardColor = coreData.HairColor; + coreData.BeardColor = coreData.HairColor; coreData.MustacheScale = 4; if (gender == Gender.Male && age != Age.Young && utilImpl.GetRandom(10) < 2) { BeardAndMustacheFlag mustacheAndBeardFlag = (BeardAndMustacheFlag)utilImpl.GetRandom(3); - BeardType beardType = BeardType.None; + BeardType beardType = BeardType.None; MustacheType mustacheType = MustacheType.None; if ((mustacheAndBeardFlag & BeardAndMustacheFlag.Beard) == BeardAndMustacheFlag.Beard) @@ -533,14 +533,14 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types } coreData.MustacheType = mustacheType; - coreData.BeardType = beardType; - coreData.MustacheY = 10; + coreData.BeardType = beardType; + coreData.MustacheY = 10; } else { coreData.MustacheType = MustacheType.None; - coreData.BeardType = BeardType.None; - coreData.MustacheY = (byte)(axisY + 10); + coreData.BeardType = BeardType.None; + coreData.MustacheY = (byte)(axisY + 10); } // Glass @@ -557,84 +557,84 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types } } - coreData.GlassType = glassType; + coreData.GlassType = glassType; coreData.GlassColor = (CommonColor)Helper.Ver3GlassColorTable[0]; coreData.GlassScale = 4; - coreData.GlassY = (byte)(axisY + 10); + coreData.GlassY = (byte)(axisY + 10); // Mole - coreData.MoleType = 0; + coreData.MoleType = 0; coreData.MoleScale = 4; - coreData.MoleX = 2; - coreData.MoleY = 20; + coreData.MoleX = 2; + coreData.MoleY = 20; // Body sizing coreData.Height = 64; - coreData.Build = 64; + coreData.Build = 64; // Misc - coreData.Nickname = Nickname.Default; - coreData.Gender = gender; + coreData.Nickname = Nickname.Default; + coreData.Gender = gender; coreData.FavoriteColor = (byte)utilImpl.GetRandom(0, 11); - coreData.RegionMove = 0; - coreData.FontRegion = 0; - coreData.Type = 0; + coreData.RegionMove = 0; + coreData.FontRegion = 0; + coreData.Type = 0; return coreData; } public void SetFromCharInfo(CharInfo charInfo) { - Nickname = charInfo.Nickname; - FontRegion = charInfo.FontRegion; - FavoriteColor = charInfo.FavoriteColor; - Gender = charInfo.Gender; - Height = charInfo.Height; - Build = charInfo.Build; - Type = charInfo.Type; - RegionMove = charInfo.RegionMove; - FacelineType = charInfo.FacelineType; - FacelineColor = charInfo.FacelineColor; + Nickname = charInfo.Nickname; + FontRegion = charInfo.FontRegion; + FavoriteColor = charInfo.FavoriteColor; + Gender = charInfo.Gender; + Height = charInfo.Height; + Build = charInfo.Build; + Type = charInfo.Type; + RegionMove = charInfo.RegionMove; + FacelineType = charInfo.FacelineType; + FacelineColor = charInfo.FacelineColor; FacelineWrinkle = charInfo.FacelineWrinkle; - FacelineMake = charInfo.FacelineMake; - HairType = charInfo.HairType; - HairColor = charInfo.HairColor; - HairFlip = charInfo.HairFlip; - EyeType = charInfo.EyeType; - EyeColor = charInfo.EyeColor; - EyeScale = charInfo.EyeScale; - EyeAspect = charInfo.EyeAspect; - EyeRotate = charInfo.EyeRotate; - EyeX = charInfo.EyeX; - EyeY = charInfo.EyeY; - EyebrowType = charInfo.EyebrowType; - EyebrowColor = charInfo.EyebrowColor; - EyebrowScale = charInfo.EyebrowScale; - EyebrowAspect = charInfo.EyebrowAspect; - EyebrowRotate = charInfo.EyebrowRotate; - EyebrowX = charInfo.EyebrowX; - EyebrowY = charInfo.EyebrowY; - NoseType = charInfo.NoseType; - NoseScale = charInfo.NoseScale; - NoseY = charInfo.NoseY; - MouthType = charInfo.MouthType; - MouthColor = charInfo.MouthColor; - MouthScale = charInfo.MouthScale; - MouthAspect = charInfo.MouthAspect; - MouthY = charInfo.MouthY; - BeardColor = charInfo.BeardColor; - BeardType = charInfo.BeardType; - MustacheType = charInfo.MustacheType; - MustacheScale = charInfo.MustacheScale; - MustacheY = charInfo.MustacheY; - GlassType = charInfo.GlassType; - GlassColor = charInfo.GlassColor; - GlassScale = charInfo.GlassScale; - GlassY = charInfo.GlassY; - MoleType = charInfo.MoleType; - MoleScale = charInfo.MoleScale; - MoleX = charInfo.MoleX; - MoleY = charInfo.MoleY; + FacelineMake = charInfo.FacelineMake; + HairType = charInfo.HairType; + HairColor = charInfo.HairColor; + HairFlip = charInfo.HairFlip; + EyeType = charInfo.EyeType; + EyeColor = charInfo.EyeColor; + EyeScale = charInfo.EyeScale; + EyeAspect = charInfo.EyeAspect; + EyeRotate = charInfo.EyeRotate; + EyeX = charInfo.EyeX; + EyeY = charInfo.EyeY; + EyebrowType = charInfo.EyebrowType; + EyebrowColor = charInfo.EyebrowColor; + EyebrowScale = charInfo.EyebrowScale; + EyebrowAspect = charInfo.EyebrowAspect; + EyebrowRotate = charInfo.EyebrowRotate; + EyebrowX = charInfo.EyebrowX; + EyebrowY = charInfo.EyebrowY; + NoseType = charInfo.NoseType; + NoseScale = charInfo.NoseScale; + NoseY = charInfo.NoseY; + MouthType = charInfo.MouthType; + MouthColor = charInfo.MouthColor; + MouthScale = charInfo.MouthScale; + MouthAspect = charInfo.MouthAspect; + MouthY = charInfo.MouthY; + BeardColor = charInfo.BeardColor; + BeardType = charInfo.BeardType; + MustacheType = charInfo.MustacheType; + MustacheScale = charInfo.MustacheScale; + MustacheY = charInfo.MustacheY; + GlassType = charInfo.GlassType; + GlassColor = charInfo.GlassColor; + GlassScale = charInfo.GlassScale; + GlassY = charInfo.GlassY; + MoleType = charInfo.MoleType; + MoleScale = charInfo.MoleScale; + MoleX = charInfo.MoleX; + MoleY = charInfo.MoleY; } public static bool operator ==(CoreData x, CoreData y) @@ -717,7 +717,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public override int GetHashCode() { - HashCode hashCode = new HashCode(); + HashCode hashCode = new(); hashCode.Add(Nickname); hashCode.Add(FontRegion); @@ -773,7 +773,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types return hashCode.ToHashCode(); } - private static ReadOnlySpan ElementInfos => MemoryMarshal.Cast(ElementInfoArray); + private readonly ReadOnlySpan ElementInfos => MemoryMarshal.Cast(ElementInfoArray); private enum ElementInfoIndex { @@ -825,11 +825,11 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types NoseScale, MouthScale, MustacheScale, - MoleScale + MoleScale, } #region "Element Info Array" - private static ReadOnlySpan ElementInfoArray => new byte[] + private readonly ReadOnlySpan ElementInfoArray => new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -904,7 +904,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 + 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, }; #endregion } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CreateId.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CreateId.cs index 283d82fc8..f61e83d73 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CreateId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CreateId.cs @@ -4,12 +4,12 @@ using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Services.Mii.Types { [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x10)] - struct CreateId : IEquatable + readonly struct CreateId : IEquatable { public readonly UInt128 Raw; - public bool IsNull => Raw == UInt128.Zero; - public bool IsValid => !IsNull && ((Raw >> 64) & 0xC0) == 0x80; + public readonly bool IsNull => Raw == UInt128.Zero; + public readonly bool IsValid => !IsNull && ((Raw >> 64) & 0xC0) == 0x80; public CreateId(UInt128 raw) { @@ -26,18 +26,18 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types return !x.Equals(y); } - public override bool Equals(object obj) + public readonly override bool Equals(object obj) { return obj is CreateId createId && Equals(createId); } - public bool Equals(CreateId cmpObj) + public readonly bool Equals(CreateId cmpObj) { // Nintendo additionally check that the CreatorId is valid before doing the actual comparison. return IsValid && Raw == cmpObj.Raw; } - public override int GetHashCode() + public readonly override int GetHashCode() { return Raw.GetHashCode(); } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/DefaultMii.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/DefaultMii.cs index 285a9242d..e3c6a42e6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/DefaultMii.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/DefaultMii.cs @@ -65,7 +65,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public Nickname Nickname { get => Nickname.FromBytes(NicknameStorage); - set => value.Raw.Slice(0, 20).CopyTo(NicknameStorage); + set => value.Raw[..20].CopyTo(NicknameStorage); } public static ReadOnlySpan Table => MemoryMarshal.Cast(TableRawArray); @@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types // The first 2 Mii in the default table are used as base for Male/Female in editor but not exposed via IPC. public static int TableLength => _fromIndex.Length; - private static readonly int[] _fromIndex = new int[] { 2, 3, 4, 5, 6, 7 }; + private static readonly int[] _fromIndex = { 2, 3, 4, 5, 6, 7 }; public static DefaultMii GetDefaultMii(uint index) { @@ -190,7 +190,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x6f, 0x00, - 0x20, 0x00, 0x6e, 0x00, 0x61, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x20, 0x00, 0x6e, 0x00, 0x61, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; #endregion } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/EyeType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/EyeType.cs index 2e4502ed7..70b6e31c5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/EyeType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/EyeType.cs @@ -63,7 +63,7 @@ RoundTired, WhiteLarge, - Min = 0, - Max = 59 + Min = Normal, + Max = WhiteLarge, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/EyebrowType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/EyebrowType.cs index af870e10c..3790128a8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/EyebrowType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/EyebrowType.cs @@ -27,7 +27,7 @@ Dotted, None, - Min = 0, - Max = 23 + Min = FlatAngledLarge, + Max = None, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineColor.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineColor.cs index 551f053d1..4571168f1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineColor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineColor.cs @@ -13,7 +13,7 @@ Almond, Espresso, - Min = 0, - Max = 9 + Min = Beige, + Max = Espresso, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineMake.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineMake.cs index af6d72764..acd94ca2e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineMake.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineMake.cs @@ -15,7 +15,7 @@ LionsManeBeard, StubbleBeard, - Min = 0, - Max = 11 + Min = None, + Max = StubbleBeard, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineType.cs index fe27636f4..29d14a126 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineType.cs @@ -15,7 +15,7 @@ FlatRounded, AngularSmall, - Min = 0, - Max = 11 + Min = Sharp, + Max = AngularSmall, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineWrinkle.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineWrinkle.cs index afb75dd8a..1a144748b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineWrinkle.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FacelineWrinkle.cs @@ -15,7 +15,7 @@ CrowsFeet, FoldsCrowsFrown, - Min = 0, - Max = 11 + Min = None, + Max = FoldsCrowsFrown, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FontRegion.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FontRegion.cs index d1d86f16d..c981a5ede 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/FontRegion.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/FontRegion.cs @@ -5,6 +5,6 @@ Standard, China, Korea, - Taiwan + Taiwan, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Gender.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Gender.cs index 75f9a745e..c120c7581 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Gender.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Gender.cs @@ -6,7 +6,7 @@ Female, All, - Min = 0, - Max = 1 + Min = Male, + Max = Female, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/GlassType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/GlassType.cs index ccfed0f60..e2b6e6f5b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/GlassType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/GlassType.cs @@ -23,7 +23,7 @@ OpaqueRectangle, OpaqueAviator, - Min = 0, - Max = 19 + Min = None, + Max = OpaqueAviator, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/HairFlip.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/HairFlip.cs index 2f7f1d734..dee42e0d1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/HairFlip.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/HairFlip.cs @@ -5,7 +5,7 @@ Left, Right, - Min = 0, - Max = 1 + Min = Left, + Max = Right, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/HairType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/HairType.cs index a8a611dac..a3e183961 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/HairType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/HairType.cs @@ -135,7 +135,7 @@ TwoLongSidedPonyTails, LongFrontTwoBackPonyTails, - Min = 0, - Max = 131 + Min = NormalLong, + Max = LongFrontTwoBackPonyTails, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/MoleType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/MoleType.cs index 12cb6dc3f..7ed274d2a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/MoleType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/MoleType.cs @@ -5,7 +5,7 @@ None, OneDot, - Min = 0, - Max = 1 + Min = None, + Max = OneDot, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/MouthType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/MouthType.cs index 2a8e7a00b..69236bd42 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/MouthType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/MouthType.cs @@ -39,7 +39,7 @@ SmileDownLine, Kiss, - Min = 0, - Max = 35 + Min = Neutral, + Max = Kiss, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/MustacheType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/MustacheType.cs index a15382dd5..7b0255f20 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/MustacheType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/MustacheType.cs @@ -9,7 +9,7 @@ Normal, Toothbrush, - Min = 0, - Max = 5 + Min = None, + Max = Toothbrush, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Nickname.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Nickname.cs index 677d81b00..dc21d8e56 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Nickname.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Nickname.cs @@ -48,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public bool IsValid() { // Create a new unicode encoding instance with error checking enabled - UnicodeEncoding unicodeEncoding = new UnicodeEncoding(false, false, true); + UnicodeEncoding unicodeEncoding = new(false, false, true); try { @@ -77,10 +77,10 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types { if (data.Length > SizeConst) { - data = data.Slice(0, SizeConst); + data = data[..SizeConst]; } - Nickname result = new Nickname(); + Nickname result = new(); data.CopyTo(result.Raw); diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/NintendoFigurineDatabase.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/NintendoFigurineDatabase.cs index 14eda2ed8..1e36788e7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/NintendoFigurineDatabase.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/NintendoFigurineDatabase.cs @@ -25,19 +25,19 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types // Set to true to allow fixing database with invalid storedata device crc instead of deleting them. private const bool AcceptInvalidDeviceCrc = true; - public int Length => _figurineCount; + public readonly int Length => _figurineCount; [StructLayout(LayoutKind.Sequential, Size = FigurineArraySize)] private struct FigurineStorageStruct { } private Span Figurines => SpanHelpers.AsSpan(ref _figurineStorage); - + public StoreData Get(int index) { return Figurines[index]; } - public bool IsFull() + public readonly bool IsFull() { return Length >= MaxMii; } @@ -74,14 +74,14 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types if (newIndex < oldIndex) { - targetLength = oldIndex - newIndex; - sourceIndex = newIndex; + targetLength = oldIndex - newIndex; + sourceIndex = newIndex; destinationIndex = newIndex + 1; } else { - targetLength = newIndex - oldIndex; - sourceIndex = oldIndex + 1; + targetLength = newIndex - oldIndex; + sourceIndex = oldIndex + 1; destinationIndex = oldIndex; } @@ -113,8 +113,8 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types // If this isn't the only element in the list, move the data in it. if (index < newCount) { - int targetLength = newCount - index; - int sourceIndex = index + 1; + int targetLength = newCount - index; + int sourceIndex = index + 1; int destinationIndex = index; Figurines.Slice(sourceIndex, targetLength).CopyTo(Figurines.Slice(destinationIndex, targetLength)); @@ -204,12 +204,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public void Format() { - _magic = DatabaseMagic; - _version = CurrentVersion; + _magic = DatabaseMagic; + _version = CurrentVersion; _figurineCount = 0; // Fill with empty data - Figurines.Fill(new StoreData()); + Figurines.Clear(); UpdateCrc(); } @@ -248,7 +248,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types private ReadOnlySpan AsSpanWithoutCrc() { - return AsReadOnlySpan().Slice(0, Unsafe.SizeOf() - 2); + return AsReadOnlySpan()[..(Unsafe.SizeOf() - 2)]; } } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/NoseType.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/NoseType.cs index e898a02ed..3144b132a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/NoseType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/NoseType.cs @@ -21,7 +21,7 @@ Droopy, ArrowLarge, - Min = 0, - Max = 17 + Min = Normal, + Max = ArrowLarge, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Race.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Race.cs index 8cf36c277..5f304a4e8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Race.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Race.cs @@ -5,6 +5,6 @@ Black, White, Asian, - All + All, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/RandomMiiConstants.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/RandomMiiConstants.cs index 6def469db..17333093e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/RandomMiiConstants.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/RandomMiiConstants.cs @@ -6,25 +6,23 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types { static class RandomMiiConstants { - public static int[] EyeRotateTable = new int[] - { + public static int[] EyeRotateTable = { 0x03, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x04, 0x04, 0x04, 0x03, 0x03, 0x04, 0x03, 0x04, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x03, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x04, 0x04, 0x03, 0x03, 0x03, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x03, 0x04, 0x04 + 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x03, 0x04, 0x04, }; - public static int[] EyebrowRotateTable = new int[] - { + public static int[] EyebrowRotateTable = { 0x06, 0x06, 0x05, 0x07, 0x06, 0x07, 0x06, 0x07, 0x04, 0x07, 0x06, 0x08, 0x05, 0x05, 0x06, 0x06, - 0x07, 0x07, 0x06, 0x06, 0x05, 0x06, 0x07, 0x05 + 0x07, 0x07, 0x06, 0x06, 0x05, 0x06, 0x07, 0x05, }; [Flags] public enum BeardAndMustacheFlag { Beard = 1, - Mustache + Mustache, } [StructLayout(LayoutKind.Sequential, Pack = 4, Size = ValuesArraySize)] @@ -32,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types { private const int ValuesArraySize = 0xbc; - private int _firstValueByte; + private readonly int _firstValueByte; public ReadOnlySpan Values => SpanHelpers.AsSpan(ref this); } @@ -44,34 +42,34 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public int Age; public int Race; public int ValuesCount; - - private RandomMiiValues _values; - public ReadOnlySpan Values => _values.Values.Slice(0, ValuesCount); + private readonly RandomMiiValues _values; + + public readonly ReadOnlySpan Values => _values.Values[..ValuesCount]; } [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 0xC8)] public struct RandomMiiData3 { - private int _argument1; - private int _argument2; + private readonly int _argument1; + private readonly int _argument2; public int ValuesCount; - - private RandomMiiValues _values; - public ReadOnlySpan Values => _values.Values.Slice(0, ValuesCount); + private readonly RandomMiiValues _values; + + public readonly ReadOnlySpan Values => _values.Values[..ValuesCount]; } [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 0xC4)] public struct RandomMiiData2 { - private int _argument; + private readonly int _argument; public int ValuesCount; - private RandomMiiValues _values; + private readonly RandomMiiValues _values; - public ReadOnlySpan Values => _values.Values.Slice(0, ValuesCount); + public readonly ReadOnlySpan Values => _values.Values[..ValuesCount]; } public static ReadOnlySpan RandomMiiFacelineArray => MemoryMarshal.Cast(RandomMiiFacelineRawArray); @@ -332,7 +330,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + , }; private static ReadOnlySpan RandomMiiFacelineColorRawArray => new byte[] { @@ -411,7 +409,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + , }; private static ReadOnlySpan RandomMiiFacelineWrinkleRawArray => new byte[] { @@ -645,7 +643,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + , }; private static ReadOnlySpan RandomMiiFacelineMakeRawArray => new byte[] { @@ -879,7 +877,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + , }; private static ReadOnlySpan RandomMiiHairTypeRawArray => new byte[] { @@ -1113,7 +1111,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + , }; private static ReadOnlySpan RandomMiiHairColorRawArray => new byte[] { @@ -1230,7 +1228,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + , }; private static ReadOnlySpan RandomMiiEyeTypeRawArray => new byte[] { @@ -1464,7 +1462,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + ,}; private static ReadOnlySpan RandomMiiEyeColorRawArray => new byte[] { diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Source.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Source.cs index 2ae02ea03..f4d2b8cb9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/Source.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/Source.cs @@ -3,6 +3,6 @@ enum Source { Database, - Default + Default, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/SourceFlag.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/SourceFlag.cs index c9682bdbb..c04eb0437 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/SourceFlag.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/SourceFlag.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types enum SourceFlag { Database = 1 << Source.Database, - Default = 1 << Source.Default, - All = Database | Default + Default = 1 << Source.Default, + All = Database | Default, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/SpecialMiiKeyCode.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/SpecialMiiKeyCode.cs index 7fe13238d..be2433ddf 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/SpecialMiiKeyCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/SpecialMiiKeyCode.cs @@ -9,7 +9,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public uint RawValue; - public bool IsEnabledSpecialMii() + public readonly bool IsEnabledSpecialMii() { return RawValue == SpecialMiiMagic; } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreData.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreData.cs index 8411693f4..994f6b7ce 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreData.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreData.cs @@ -9,16 +9,16 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types { public const int Size = 0x44; - public CoreData CoreData; + public CoreData CoreData; private CreateId _createId; - public ushort DataCrc; - public ushort DeviceCrc; + public ushort DataCrc; + public ushort DeviceCrc; public byte Type => CoreData.Type; - public CreateId CreateId => _createId; + public readonly CreateId CreateId => _createId; - public ResultCode InvalidData => ResultCode.InvalidStoreData; + public readonly ResultCode InvalidData => ResultCode.InvalidStoreData; private void UpdateDataCrc() { @@ -81,22 +81,23 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types private ReadOnlySpan AsSpanWithoutDeviceCrc() { - return AsSpan().Slice(0, Size - 2); + return AsSpan()[..(Size - 2)]; } public static StoreData BuildDefault(UtilityImpl utilImpl, uint index) { - StoreData result = new StoreData + StoreData result = new() { - _createId = utilImpl.MakeCreateId() + _createId = utilImpl.MakeCreateId(), }; - CoreData coreData = new CoreData(); + CoreData coreData = new(); DefaultMii template = DefaultMii.GetDefaultMii(index); coreData.SetDefault(); +#pragma warning disable IDE0055 // Disable formatting coreData.Nickname = template.Nickname; coreData.FontRegion = (FontRegion)template.FontRegion; coreData.FavoriteColor = (byte)template.FavoriteColor; @@ -147,6 +148,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types coreData.MoleScale = (byte)template.MoleScale; coreData.MoleX = (byte)template.MoleX; coreData.MoleY = (byte)template.MoleY; +#pragma warning restore IDE0055 result.CoreData = coreData; @@ -162,10 +164,10 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types public static StoreData BuildFromCoreData(UtilityImpl utilImpl, CoreData coreData) { - StoreData result = new StoreData + StoreData result = new() { - CoreData = coreData, - _createId = utilImpl.MakeCreateId() + CoreData = coreData, + _createId = utilImpl.MakeCreateId(), }; result.UpdateCrc(); @@ -178,7 +180,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types this = storeData; } - public void SetSource(Source source) + public readonly void SetSource(Source source) { // Only implemented for Element variants. } @@ -193,12 +195,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types return !x.Equals(y); } - public override bool Equals(object obj) + public readonly override bool Equals(object obj) { return obj is StoreData storeData && Equals(storeData); } - public bool Equals(StoreData cmpObj) + public readonly bool Equals(StoreData cmpObj) { if (!cmpObj.IsValid()) { @@ -215,9 +217,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types return result; } - public override int GetHashCode() + public readonly override int GetHashCode() { - HashCode hashCode = new HashCode(); + HashCode hashCode = new(); hashCode.Add(CreateId); hashCode.Add(CoreData); diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreDataElement.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreDataElement.cs index 8d3e96bea..2008c1ffa 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreDataElement.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/StoreDataElement.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types struct StoreDataElement : IElement { public StoreData StoreData; - public Source Source; + public Source Source; public void SetFromStoreData(StoreData storeData) { diff --git a/src/Ryujinx.HLE/HOS/Services/Mm/IRequest.cs b/src/Ryujinx.HLE/HOS/Services/Mm/IRequest.cs index fac425553..31d325a94 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mm/IRequest.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mm/IRequest.cs @@ -7,10 +7,10 @@ namespace Ryujinx.HLE.HOS.Services.Mm [Service("mm:u")] class IRequest : IpcService { - private static object _sessionListLock = new object(); - private static List _sessionList = new List(); + private readonly object _sessionListLock = new(); + private readonly List _sessionList = new(); - private static uint _uniqueId = 1; + private uint _uniqueId = 1; public IRequest(ServiceCtx context) { } @@ -18,9 +18,9 @@ namespace Ryujinx.HLE.HOS.Services.Mm // InitializeOld(u32, u32, u32) public ResultCode InitializeOld(ServiceCtx context) { - MultiMediaOperationType operationType = (MultiMediaOperationType)context.RequestData.ReadUInt32(); - int fgmId = context.RequestData.ReadInt32(); - bool isAutoClearEvent = context.RequestData.ReadInt32() != 0; + MultiMediaOperationType operationType = (MultiMediaOperationType)context.RequestData.ReadUInt32(); + int fgmId = context.RequestData.ReadInt32(); + bool isAutoClearEvent = context.RequestData.ReadInt32() != 0; Logger.Stub?.PrintStub(LogClass.ServiceMm, new { operationType, fgmId, isAutoClearEvent }); @@ -50,8 +50,8 @@ namespace Ryujinx.HLE.HOS.Services.Mm public ResultCode SetAndWaitOld(ServiceCtx context) { MultiMediaOperationType operationType = (MultiMediaOperationType)context.RequestData.ReadUInt32(); - uint frequenceHz = context.RequestData.ReadUInt32(); - int timeout = context.RequestData.ReadInt32(); + uint frequenceHz = context.RequestData.ReadUInt32(); + int timeout = context.RequestData.ReadInt32(); Logger.Stub?.PrintStub(LogClass.ServiceMm, new { operationType, frequenceHz, timeout }); @@ -87,9 +87,9 @@ namespace Ryujinx.HLE.HOS.Services.Mm // Initialize(u32, u32, u32) -> u32 public ResultCode Initialize(ServiceCtx context) { - MultiMediaOperationType operationType = (MultiMediaOperationType)context.RequestData.ReadUInt32(); - int fgmId = context.RequestData.ReadInt32(); - bool isAutoClearEvent = context.RequestData.ReadInt32() != 0; + MultiMediaOperationType operationType = (MultiMediaOperationType)context.RequestData.ReadUInt32(); + int fgmId = context.RequestData.ReadInt32(); + bool isAutoClearEvent = context.RequestData.ReadInt32() != 0; Logger.Stub?.PrintStub(LogClass.ServiceMm, new { operationType, fgmId, isAutoClearEvent }); @@ -120,9 +120,9 @@ namespace Ryujinx.HLE.HOS.Services.Mm // SetAndWait(u32, u32, u32) public ResultCode SetAndWait(ServiceCtx context) { - uint id = context.RequestData.ReadUInt32(); + uint id = context.RequestData.ReadUInt32(); uint frequenceHz = context.RequestData.ReadUInt32(); - int timeout = context.RequestData.ReadInt32(); + int timeout = context.RequestData.ReadInt32(); Logger.Stub?.PrintStub(LogClass.ServiceMm, new { id, frequenceHz, timeout }); @@ -185,7 +185,7 @@ namespace Ryujinx.HLE.HOS.Services.Mm lock (_sessionListLock) { // Nintendo ignore the fgm id as the other interfaces were deprecated. - MultiMediaSession session = new MultiMediaSession(_uniqueId++, type, isAutoClearEvent); + MultiMediaSession session = new(_uniqueId++, type, isAutoClearEvent); _sessionList.Add(session); @@ -193,4 +193,4 @@ namespace Ryujinx.HLE.HOS.Services.Mm } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Mm/Types/MultiMediaOperationType.cs b/src/Ryujinx.HLE/HOS/Services/Mm/Types/MultiMediaOperationType.cs index 2742af6c4..095dbfc31 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mm/Types/MultiMediaOperationType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mm/Types/MultiMediaOperationType.cs @@ -2,9 +2,9 @@ { enum MultiMediaOperationType : uint { - Ram = 2, + Ram = 2, NvEnc = 5, NvDec = 6, - NvJpg = 7 + NvJpg = 7, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Mm/Types/MultiMediaSession.cs b/src/Ryujinx.HLE/HOS/Services/Mm/Types/MultiMediaSession.cs index a6723ecab..32b52ca54 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mm/Types/MultiMediaSession.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mm/Types/MultiMediaSession.cs @@ -5,15 +5,15 @@ public MultiMediaOperationType Type { get; } public bool IsAutoClearEvent { get; } - public uint Id { get; } - public uint CurrentValue { get; private set; } + public uint Id { get; } + public uint CurrentValue { get; private set; } public MultiMediaSession(uint id, MultiMediaOperationType type, bool isAutoClearEvent) { - Type = type; - Id = id; + Type = type; + Id = id; IsAutoClearEvent = isAutoClearEvent; - CurrentValue = 0; + CurrentValue = 0; } public void SetAndWait(uint value, int timeout) diff --git a/src/Ryujinx.HLE/HOS/Services/Mnpp/IServiceForApplication.cs b/src/Ryujinx.HLE/HOS/Services/Mnpp/IServiceForApplication.cs index c2a4345c6..7c20579be 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mnpp/IServiceForApplication.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mnpp/IServiceForApplication.cs @@ -32,7 +32,7 @@ namespace Ryujinx.HLE.HOS.Services.Mnpp public ResultCode SendRawTelemetryData(ServiceCtx context) { ulong titleIdInputPosition = context.Request.SendBuff[0].Position; - ulong titleIdInputSize = context.Request.SendBuff[0].Size; + ulong titleIdInputSize = context.Request.SendBuff[0].Size; UserId userId = context.RequestData.ReadStruct(); @@ -60,4 +60,4 @@ namespace Ryujinx.HLE.HOS.Services.Mnpp return ResultCode.InvalidBufferSize; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Mnpp/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Mnpp/ResultCode.cs index dfc39a735..af3acf0ab 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mnpp/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mnpp/ResultCode.cs @@ -2,12 +2,12 @@ namespace Ryujinx.HLE.HOS.Services.Mnpp { enum ResultCode { - ModuleId = 239, + ModuleId = 239, ErrorCodeShift = 9, Success = 0, - InvalidArgument = (100 << ErrorCodeShift) | ModuleId, - InvalidBufferSize = (101 << ErrorCodeShift) | ModuleId + InvalidArgument = (100 << ErrorCodeShift) | ModuleId, + InvalidBufferSize = (101 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ncm/IContentManager.cs b/src/Ryujinx.HLE/HOS/Services/Ncm/IContentManager.cs index 7f05d9bed..cf0d41494 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ncm/IContentManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ncm/IContentManager.cs @@ -5,4 +5,4 @@ { public IContentManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/ILocationResolverManager.cs b/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/ILocationResolverManager.cs index 318ad30e6..f59216786 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/ILocationResolverManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/ILocationResolverManager.cs @@ -19,4 +19,4 @@ namespace Ryujinx.HLE.HOS.Services.Ncm.Lr return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/LocationResolverManager/ILocationResolver.cs b/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/LocationResolverManager/ILocationResolver.cs index 55b49bcec..f5a0c665c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/LocationResolverManager/ILocationResolver.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/LocationResolverManager/ILocationResolver.cs @@ -2,14 +2,13 @@ using LibHac.Tools.FsSystem.NcaUtils; using Ryujinx.HLE.FileSystem; using System.Text; - using static Ryujinx.HLE.Utilities.StringUtils; namespace Ryujinx.HLE.HOS.Services.Ncm.Lr.LocationResolverManager { class ILocationResolver : IpcService { - private StorageId _storageId; + private readonly StorageId _storageId; public ILocationResolver(StorageId storageId) { @@ -215,8 +214,8 @@ namespace Ryujinx.HLE.HOS.Services.Ncm.Lr.LocationResolverManager private void RedirectPath(ServiceCtx context, ulong titleId, int flag, NcaContentType contentType) { - string contentPath = ReadUtf8String(context); - LocationEntry newLocation = new LocationEntry(contentPath, flag, titleId, contentType); + string contentPath = ReadUtf8String(context); + LocationEntry newLocation = new(contentPath, flag, titleId, contentType); context.Device.System.ContentManager.RedirectLocation(newLocation, _storageId); } @@ -224,12 +223,14 @@ namespace Ryujinx.HLE.HOS.Services.Ncm.Lr.LocationResolverManager private bool ResolvePath(ServiceCtx context, ulong titleId, NcaContentType contentType) { ContentManager contentManager = context.Device.System.ContentManager; - string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, NcaContentType.Program); + string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, NcaContentType.Program); if (!string.IsNullOrWhiteSpace(contentPath)) { ulong position = context.Request.RecvListBuff[0].Position; - ulong size = context.Request.RecvListBuff[0].Size; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong size = context.Request.RecvListBuff[0].Size; +#pragma warning restore IDE0059 byte[] contentPathBuffer = Encoding.UTF8.GetBytes(contentPath); @@ -246,7 +247,9 @@ namespace Ryujinx.HLE.HOS.Services.Ncm.Lr.LocationResolverManager private void DeleteContentPath(ServiceCtx context, ulong titleId, NcaContentType contentType) { ContentManager contentManager = context.Device.System.ContentManager; - string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, NcaContentType.Manual); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, NcaContentType.Manual); +#pragma warning restore IDE0059 contentManager.ClearEntry(titleId, NcaContentType.Manual, _storageId); } diff --git a/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/ResultCode.cs index d21fe634e..3a027fd04 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ncm/Lr/ResultCode.cs @@ -2,19 +2,19 @@ { enum ResultCode { - ModuleId = 8, + ModuleId = 8, ErrorCodeShift = 9, Success = 0, - ProgramLocationEntryNotFound = (2 << ErrorCodeShift) | ModuleId, - InvalidContextForControlLocation = (3 << ErrorCodeShift) | ModuleId, - StorageNotFound = (4 << ErrorCodeShift) | ModuleId, - AccessDenied = (5 << ErrorCodeShift) | ModuleId, - OfflineManualHTMLLocationEntryNotFound = (6 << ErrorCodeShift) | ModuleId, - TitleIsNotRegistered = (7 << ErrorCodeShift) | ModuleId, - ControlLocationEntryForHostNotFound = (8 << ErrorCodeShift) | ModuleId, - LegalInfoHTMLLocationEntryNotFound = (9 << ErrorCodeShift) | ModuleId, - ProgramLocationForDebugEntryNotFound = (10 << ErrorCodeShift) | ModuleId + ProgramLocationEntryNotFound = (2 << ErrorCodeShift) | ModuleId, + InvalidContextForControlLocation = (3 << ErrorCodeShift) | ModuleId, + StorageNotFound = (4 << ErrorCodeShift) | ModuleId, + AccessDenied = (5 << ErrorCodeShift) | ModuleId, + OfflineManualHTMLLocationEntryNotFound = (6 << ErrorCodeShift) | ModuleId, + TitleIsNotRegistered = (7 << ErrorCodeShift) | ModuleId, + ControlLocationEntryForHostNotFound = (8 << ErrorCodeShift) | ModuleId, + LegalInfoHTMLLocationEntryNotFound = (9 << ErrorCodeShift) | ModuleId, + ProgramLocationForDebugEntryNotFound = (10 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/News/IServiceCreator.cs b/src/Ryujinx.HLE/HOS/Services/News/IServiceCreator.cs index 7ea89b20d..5d33e1a2b 100644 --- a/src/Ryujinx.HLE/HOS/Services/News/IServiceCreator.cs +++ b/src/Ryujinx.HLE/HOS/Services/News/IServiceCreator.cs @@ -9,4 +9,4 @@ { public IServiceCreator(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/IAmManager.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/IAmManager.cs index 33932568d..142c4da48 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/IAmManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/IAmManager.cs @@ -5,4 +5,4 @@ { public IAmManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/ISystemManager.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/ISystemManager.cs index ef90b6ad8..50453117d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/ISystemManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/ISystemManager.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.Nfc return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/IUserManager.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/IUserManager.cs index 97959a62f..69c3bd191 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/IUserManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/IUserManager.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.Nfc return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Mifare/IUserManager.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Mifare/IUserManager.cs index cc3cd3aa9..2c5aaa2e9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Mifare/IUserManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Mifare/IUserManager.cs @@ -5,4 +5,4 @@ { public IUserManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/INfc.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/INfc.cs index b091aabfc..dac0c4c33 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/INfc.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/INfc.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.NfcManager { class INfc : IpcService { - private NfcPermissionLevel _permissionLevel; + private readonly NfcPermissionLevel _permissionLevel; private State _state; public INfc(NfcPermissionLevel permissionLevel) @@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.NfcManager [CommandCmif(2)] [CommandCmif(402)] // 4.0.0+ // GetState() -> u32 - public ResultCode GetState(ServiceCtx context) + public ResultCode GetState(ServiceCtx context) { context.ResponseData.Write((int)_state); @@ -60,4 +60,4 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.NfcManager return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/Types/NfcPermissionLevel.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/Types/NfcPermissionLevel.cs index 39babc737..37a78dfd3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/Types/NfcPermissionLevel.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/Types/NfcPermissionLevel.cs @@ -3,6 +3,6 @@ enum NfcPermissionLevel { User, - System + System, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/Types/State.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/Types/State.cs index 85f999507..cfc86dfa6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/Types/State.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/Types/State.cs @@ -3,6 +3,6 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.NfcManager enum State { NonInitialized, - Initialized + Initialized, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/AmiiboJsonSerializerContext.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/AmiiboJsonSerializerContext.cs index e75f62004..d48671126 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/AmiiboJsonSerializerContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/AmiiboJsonSerializerContext.cs @@ -7,4 +7,4 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp internal partial class AmiiboJsonSerializerContext : JsonSerializerContext { } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IDebugManager.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IDebugManager.cs index fc4544739..8196f42d1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IDebugManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IDebugManager.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ISystemManager.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ISystemManager.cs index 3fcf7a87a..d5933a4ce 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ISystemManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ISystemManager.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IUserManager.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IUserManager.cs index 93da84194..fa80e9b86 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IUserManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IUserManager.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs index e25a2972a..9dc75cd2c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs @@ -18,8 +18,10 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp { class INfp : IpcService { - private ulong _appletResourceUserId; - private ulong _mcuVersionData; +#pragma warning disable IDE0052 // Remove unread private member + private ulong _appletResourceUserId; + private ulong _mcuVersionData; +#pragma warning restore IDE0052 private byte[] _mcuData; private State _state = State.NonInitialized; @@ -28,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp private CancellationTokenSource _cancelTokenSource; - private NfpPermissionLevel _permissionLevel; + private readonly NfpPermissionLevel _permissionLevel; public INfp(NfpPermissionLevel permissionLevel) { @@ -40,10 +42,10 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp public ResultCode Initialize(ServiceCtx context) { _appletResourceUserId = context.RequestData.ReadUInt64(); - _mcuVersionData = context.RequestData.ReadUInt64(); + _mcuVersionData = context.RequestData.ReadUInt64(); ulong inputPosition = context.Request.SendBuff[0].Position; - ulong inputSize = context.Request.SendBuff[0].Size; + ulong inputSize = context.Request.SendBuff[0].Size; _mcuData = new byte[inputSize]; @@ -53,11 +55,11 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp // TODO: Handle this in a controller class directly. // Every functions which use the Handle call nn::hid::system::GetXcdHandleForNpadWithNfc(). - NfpDevice devicePlayer1 = new NfpDevice + NfpDevice devicePlayer1 = new() { NpadIdType = NpadIdType.Player1, - Handle = HidUtils.GetIndexFromNpadIdType(NpadIdType.Player1), - State = NfpDeviceState.Initialized + Handle = HidUtils.GetIndexFromNpadIdType(NpadIdType.Player1), + State = NfpDeviceState.Initialized, }; context.Device.System.NfpDevices.Add(devicePlayer1); @@ -75,10 +77,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp { if (_state == State.Initialized) { - if (_cancelTokenSource != null) - { - _cancelTokenSource.Cancel(); - } + _cancelTokenSource?.Cancel(); // NOTE: All events are destroyed here. context.Device.System.NfpDevices.Clear(); @@ -99,7 +98,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp } ulong outputPosition = context.Request.RecvListBuff[0].Position; - ulong outputSize = context.Request.RecvListBuff[0].Size; + ulong outputSize = context.Request.RecvListBuff[0].Size; if (context.Device.System.NfpDevices.Count == 0) { @@ -187,10 +186,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp return resultCode; } - if (_cancelTokenSource != null) - { - _cancelTokenSource.Cancel(); - } + _cancelTokenSource?.Cancel(); uint deviceHandle = (uint)context.RequestData.ReadUInt64(); @@ -218,9 +214,9 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp return resultCode; } - uint deviceHandle = (uint)context.RequestData.ReadUInt64(); - DeviceType deviceType = (DeviceType)context.RequestData.ReadUInt32(); - MountTarget mountTarget = (MountTarget)context.RequestData.ReadUInt32(); + uint deviceHandle = (uint)context.RequestData.ReadUInt64(); + DeviceType deviceType = (DeviceType)context.RequestData.ReadUInt32(); + MountTarget mountTarget = (MountTarget)context.RequestData.ReadUInt32(); if (deviceType != 0) { @@ -382,7 +378,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp } ulong outputPosition = context.Request.ReceiveBuff[0].Position; - ulong outputSize = context.Request.ReceiveBuff[0].Size; + ulong outputSize = context.Request.ReceiveBuff[0].Size; MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize); @@ -450,7 +446,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp } ulong inputPosition = context.Request.SendBuff[0].Position; - ulong inputSize = context.Request.SendBuff[0].Size; + ulong inputSize = context.Request.SendBuff[0].Size; byte[] applicationArea = new byte[inputSize]; @@ -489,7 +485,9 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp // Flush(bytes<8, 4>) public ResultCode Flush(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment uint deviceHandle = (uint)context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 if (context.Device.System.NfpDevices.Count == 0) { @@ -529,7 +527,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp uint applicationAreaId = context.RequestData.ReadUInt32(); ulong inputPosition = context.Request.SendBuff[0].Position; - ulong inputSize = context.Request.SendBuff[0].Size; + ulong inputSize = context.Request.SendBuff[0].Size; byte[] applicationArea = new byte[inputSize]; @@ -612,23 +610,23 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp { if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted || context.Device.System.NfpDevices[i].State == NfpDeviceState.TagFound) { - byte[] Uuid = VirtualAmiibo.GenerateUuid(context.Device.System.NfpDevices[i].AmiiboId, context.Device.System.NfpDevices[i].UseRandomUuid); + byte[] uuid = VirtualAmiibo.GenerateUuid(context.Device.System.NfpDevices[i].AmiiboId, context.Device.System.NfpDevices[i].UseRandomUuid); - if (Uuid.Length > AmiiboConstants.UuidMaxLength) + if (uuid.Length > AmiiboConstants.UuidMaxLength) { - throw new ArgumentOutOfRangeException(); + throw new InvalidOperationException($"{nameof(uuid)} is too long: {uuid.Length}"); } - TagInfo tagInfo = new TagInfo + TagInfo tagInfo = new() { - UuidLength = (byte)Uuid.Length, - Reserved1 = new Array21(), - Protocol = uint.MaxValue, // All Protocol - TagType = uint.MaxValue, // All Type - Reserved2 = new Array6() + UuidLength = (byte)uuid.Length, + Reserved1 = new Array21(), + Protocol = uint.MaxValue, // All Protocol + TagType = uint.MaxValue, // All Type + Reserved2 = new Array6(), }; - Uuid.CopyTo(tagInfo.Uuid.AsSpan()); + uuid.CopyTo(tagInfo.Uuid.AsSpan()); context.Memory.Write(outputPosition, tagInfo); @@ -811,17 +809,16 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp { if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted) { - ModelInfo modelInfo = new ModelInfo + ModelInfo modelInfo = new() { - Reserved = new Array57() + Reserved = new Array57(), + CharacterId = BinaryPrimitives.ReverseEndianness(ushort.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(0, 4), NumberStyles.HexNumber)), + CharacterVariant = byte.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(4, 2), NumberStyles.HexNumber), + Series = byte.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(12, 2), NumberStyles.HexNumber), + ModelNumber = ushort.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(8, 4), NumberStyles.HexNumber), + Type = byte.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(6, 2), NumberStyles.HexNumber), }; - modelInfo.CharacterId = BinaryPrimitives.ReverseEndianness(ushort.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(0, 4), NumberStyles.HexNumber)); - modelInfo.CharacterVariant = byte.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(4, 2), NumberStyles.HexNumber); - modelInfo.Series = byte.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(12, 2), NumberStyles.HexNumber); - modelInfo.ModelNumber = ushort.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(8, 4), NumberStyles.HexNumber); - modelInfo.Type = byte.Parse(context.Device.System.NfpDevices[i].AmiiboId.AsSpan(6, 2), NumberStyles.HexNumber); - context.Memory.Write(outputPosition, modelInfo); resultCode = ResultCode.Success; @@ -912,7 +909,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp { if (context.Device.System.NfpDevices[i].State > NfpDeviceState.Finalized) { - throw new ArgumentOutOfRangeException(); + throw new InvalidOperationException($"{nameof(context.Device.System.NfpDevices)} contains an invalid state for device {i}: {context.Device.System.NfpDevices[i].State}"); } context.ResponseData.Write((uint)context.Device.System.NfpDevices[i].State); diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/AmiiboConstants.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/AmiiboConstants.cs index b06492e6e..a5d420cb1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/AmiiboConstants.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/AmiiboConstants.cs @@ -2,7 +2,7 @@ { static class AmiiboConstants { - public const int UuidMaxLength = 10; + public const int UuidMaxLength = 10; public const int ApplicationAreaSize = 0xD8; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/CommonInfo.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/CommonInfo.cs index a7976de9e..ba953125e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/CommonInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/CommonInfo.cs @@ -6,12 +6,12 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager [StructLayout(LayoutKind.Sequential, Size = 0x40)] struct CommonInfo { - public ushort LastWriteYear; - public byte LastWriteMonth; - public byte LastWriteDay; - public ushort WriteCounter; - public ushort Version; - public uint ApplicationAreaSize; + public ushort LastWriteYear; + public byte LastWriteMonth; + public byte LastWriteDay; + public ushort WriteCounter; + public ushort Version; + public uint ApplicationAreaSize; public Array52 Reserved; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/DeviceType.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/DeviceType.cs index 096522a0a..44c8a79a4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/DeviceType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/DeviceType.cs @@ -4,4 +4,4 @@ { Amiibo } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/ModelInfo.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/ModelInfo.cs index c66636ae0..48aba269d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/ModelInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/ModelInfo.cs @@ -6,11 +6,11 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager [StructLayout(LayoutKind.Sequential, Size = 0x40)] struct ModelInfo { - public ushort CharacterId; - public byte CharacterVariant; - public byte Series; - public ushort ModelNumber; - public byte Type; + public ushort CharacterId; + public byte CharacterVariant; + public byte Series; + public ushort ModelNumber; + public byte Type; public Array57 Reserved; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/MountTarget.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/MountTarget.cs index 4a1457738..d71d7eea8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/MountTarget.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/MountTarget.cs @@ -4,6 +4,6 @@ { Rom = 1, Ram = 2, - All = 3 + All = 3, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpDevice.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpDevice.cs index f56d33a95..82602837a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpDevice.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpDevice.cs @@ -8,16 +8,16 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager public KEvent ActivateEvent; public KEvent DeactivateEvent; - public void SignalActivate() => ActivateEvent.ReadableEvent.Signal(); + public void SignalActivate() => ActivateEvent.ReadableEvent.Signal(); public void SignalDeactivate() => DeactivateEvent.ReadableEvent.Signal(); public NfpDeviceState State = NfpDeviceState.Unavailable; public PlayerIndex Handle; - public NpadIdType NpadIdType; + public NpadIdType NpadIdType; public string AmiiboId; public bool UseRandomUuid; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpDeviceState.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpDeviceState.cs index 51e1d0608..d0e0c8baa 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpDeviceState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpDeviceState.cs @@ -2,12 +2,12 @@ { enum NfpDeviceState { - Initialized = 0, + Initialized = 0, SearchingForTag = 1, - TagFound = 2, - TagRemoved = 3, - TagMounted = 4, - Unavailable = 5, - Finalized = 6 + TagFound = 2, + TagRemoved = 3, + TagMounted = 4, + Unavailable = 5, + Finalized = 6, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpPermissionLevel.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpPermissionLevel.cs index 8b84dcfee..972f0af34 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpPermissionLevel.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/NfpPermissionLevel.cs @@ -4,6 +4,6 @@ { Debug, User, - System + System, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/RegisterInfo.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/RegisterInfo.cs index 6b30eb8ed..28d8fae20 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/RegisterInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/RegisterInfo.cs @@ -7,13 +7,13 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager [StructLayout(LayoutKind.Sequential, Size = 0x100)] struct RegisterInfo { - public CharInfo MiiCharInfo; - public ushort FirstWriteYear; - public byte FirstWriteMonth; - public byte FirstWriteDay; + public CharInfo MiiCharInfo; + public ushort FirstWriteYear; + public byte FirstWriteMonth; + public byte FirstWriteDay; public Array41 Nickname; - public byte FontRegion; + public byte FontRegion; public Array64 Reserved1; public Array58 Reserved2; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/State.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/State.cs index b38cf9e21..ca7faf042 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/State.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/State.cs @@ -3,6 +3,6 @@ enum State { NonInitialized = 0, - Initialized = 1 + Initialized = 1, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/TagInfo.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/TagInfo.cs index d2076b2a6..903743f13 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/TagInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/TagInfo.cs @@ -7,10 +7,10 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager struct TagInfo { public Array10 Uuid; - public byte UuidLength; + public byte UuidLength; public Array21 Reserved1; - public uint Protocol; - public uint TagType; - public Array6 Reserved2; + public uint Protocol; + public uint TagType; + public Array6 Reserved2; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/VirtualAmiiboFile.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/VirtualAmiiboFile.cs index be1877e50..51e04dcac 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/VirtualAmiiboFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/Types/VirtualAmiiboFile.cs @@ -5,18 +5,18 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager { struct VirtualAmiiboFile { - public uint FileVersion { get; set; } - public byte[] TagUuid { get; set; } - public string AmiiboId { get; set; } + public uint FileVersion { get; set; } + public byte[] TagUuid { get; set; } + public string AmiiboId { get; set; } public DateTime FirstWriteDate { get; set; } - public DateTime LastWriteDate { get; set; } - public ushort WriteCounter { get; set; } + public DateTime LastWriteDate { get; set; } + public ushort WriteCounter { get; set; } public List ApplicationAreas { get; set; } } struct VirtualAmiiboApplicationArea { - public uint ApplicationAreaId { get; set; } - public byte[] ApplicationArea { get; set; } + public uint ApplicationAreaId { get; set; } + public byte[] ApplicationArea { get; set; } } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ResultCode.cs index e0ccbc6d6..233877073 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ResultCode.cs @@ -2,17 +2,17 @@ { public enum ResultCode { - ModuleId = 115, + ModuleId = 115, ErrorCodeShift = 9, Success = 0, - DeviceNotFound = (64 << ErrorCodeShift) | ModuleId, - WrongArgument = (65 << ErrorCodeShift) | ModuleId, - WrongDeviceState = (73 << ErrorCodeShift) | ModuleId, - NfcDisabled = (80 << ErrorCodeShift) | ModuleId, - TagNotFound = (97 << ErrorCodeShift) | ModuleId, - ApplicationAreaIsNull = (128 << ErrorCodeShift) | ModuleId, - ApplicationAreaAlreadyCreated = (168 << ErrorCodeShift) | ModuleId + DeviceNotFound = (64 << ErrorCodeShift) | ModuleId, + WrongArgument = (65 << ErrorCodeShift) | ModuleId, + WrongDeviceState = (73 << ErrorCodeShift) | ModuleId, + NfcDisabled = (80 << ErrorCodeShift) | ModuleId, + TagNotFound = (97 << ErrorCodeShift) | ModuleId, + ApplicationAreaIsNull = (128 << ErrorCodeShift) | ModuleId, + ApplicationAreaAlreadyCreated = (168 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs index 9e1db7fcd..3d1426530 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs @@ -8,7 +8,6 @@ using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager; using System; using System.Collections.Generic; using System.IO; -using System.Linq; namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp { @@ -16,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp { private static uint _openedApplicationAreaId; - private static readonly AmiiboJsonSerializerContext SerializerContext = AmiiboJsonSerializerContext.Default; + private static readonly AmiiboJsonSerializerContext _serializerContext = AmiiboJsonSerializerContext.Default; public static byte[] GenerateUuid(string amiiboId, bool useRandomUuid) { @@ -43,7 +42,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp Random.Shared.NextBytes(uuid); - uuid[3] = (byte)(0x88 ^ uuid[0] ^ uuid[1] ^ uuid[2]); + uuid[3] = (byte)(0x88 ^ uuid[0] ^ uuid[1] ^ uuid[2]); uuid[8] = (byte)(uuid[3] ^ uuid[4] ^ uuid[5] ^ uuid[6]); return uuid; @@ -55,13 +54,13 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp return new CommonInfo() { - LastWriteYear = (ushort)amiiboFile.LastWriteDate.Year, - LastWriteMonth = (byte)amiiboFile.LastWriteDate.Month, - LastWriteDay = (byte)amiiboFile.LastWriteDate.Day, - WriteCounter = amiiboFile.WriteCounter, - Version = 1, + LastWriteYear = (ushort)amiiboFile.LastWriteDate.Year, + LastWriteMonth = (byte)amiiboFile.LastWriteDate.Month, + LastWriteDay = (byte)amiiboFile.LastWriteDate.Day, + WriteCounter = amiiboFile.WriteCounter, + Version = 1, ApplicationAreaSize = AmiiboConstants.ApplicationAreaSize, - Reserved = new Array52() + Reserved = new Array52(), }; } @@ -69,22 +68,22 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp { VirtualAmiiboFile amiiboFile = LoadAmiiboFile(amiiboId); - UtilityImpl utilityImpl = new UtilityImpl(tickSource); - CharInfo charInfo = new CharInfo(); + UtilityImpl utilityImpl = new(tickSource); + CharInfo charInfo = new(); charInfo.SetFromStoreData(StoreData.BuildDefault(utilityImpl, 0)); charInfo.Nickname = Nickname.FromString(nickname); - RegisterInfo registerInfo = new RegisterInfo() + RegisterInfo registerInfo = new() { - MiiCharInfo = charInfo, - FirstWriteYear = (ushort)amiiboFile.FirstWriteDate.Year, + MiiCharInfo = charInfo, + FirstWriteYear = (ushort)amiiboFile.FirstWriteDate.Year, FirstWriteMonth = (byte)amiiboFile.FirstWriteDate.Month, - FirstWriteDay = (byte)amiiboFile.FirstWriteDate.Day, - FontRegion = 0, - Reserved1 = new Array64(), - Reserved2 = new Array58() + FirstWriteDay = (byte)amiiboFile.FirstWriteDate.Day, + FontRegion = 0, + Reserved1 = new Array64(), + Reserved2 = new Array58(), }; "Ryujinx"u8.CopyTo(registerInfo.Nickname.AsSpan()); @@ -132,7 +131,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp virtualAmiiboFile.ApplicationAreas.Add(new VirtualAmiiboApplicationArea() { ApplicationAreaId = applicationAreaId, - ApplicationArea = applicationAreaData + ApplicationArea = applicationAreaData, }); SaveAmiiboFile(virtualAmiiboFile); @@ -153,7 +152,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp virtualAmiiboFile.ApplicationAreas[i] = new VirtualAmiiboApplicationArea() { ApplicationAreaId = _openedApplicationAreaId, - ApplicationArea = applicationAreaData + ApplicationArea = applicationAreaData, }; break; @@ -174,19 +173,19 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp if (File.Exists(filePath)) { - virtualAmiiboFile = JsonHelper.DeserializeFromFile(filePath, SerializerContext.VirtualAmiiboFile); + virtualAmiiboFile = JsonHelper.DeserializeFromFile(filePath, _serializerContext.VirtualAmiiboFile); } else { virtualAmiiboFile = new VirtualAmiiboFile() { - FileVersion = 0, - TagUuid = Array.Empty(), - AmiiboId = amiiboId, - FirstWriteDate = DateTime.Now, - LastWriteDate = DateTime.Now, - WriteCounter = 0, - ApplicationAreas = new List() + FileVersion = 0, + TagUuid = Array.Empty(), + AmiiboId = amiiboId, + FirstWriteDate = DateTime.Now, + LastWriteDate = DateTime.Now, + WriteCounter = 0, + ApplicationAreas = new List(), }; SaveAmiiboFile(virtualAmiiboFile); @@ -198,7 +197,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp private static void SaveAmiiboFile(VirtualAmiiboFile virtualAmiiboFile) { string filePath = Path.Join(AppDataManager.BaseDirPath, "system", "amiibo", $"{virtualAmiiboFile.AmiiboId}.json"); - JsonHelper.SerializeToFile(filePath, virtualAmiiboFile, SerializerContext.VirtualAmiiboFile); + JsonHelper.SerializeToFile(filePath, virtualAmiiboFile, _serializerContext.VirtualAmiiboFile); } } } diff --git a/src/Ryujinx.HLE/HOS/Services/Ngct/IService.cs b/src/Ryujinx.HLE/HOS/Services/Ngct/IService.cs index eacf35f32..802be7514 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ngct/IService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ngct/IService.cs @@ -19,4 +19,4 @@ return NgctServer.Filter(context); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ngct/IServiceWithManagementApi.cs b/src/Ryujinx.HLE/HOS/Services/Ngct/IServiceWithManagementApi.cs index 5ad056bab..7ef998359 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ngct/IServiceWithManagementApi.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ngct/IServiceWithManagementApi.cs @@ -19,4 +19,4 @@ return NgctServer.Filter(context); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ngct/NgctServer.cs b/src/Ryujinx.HLE/HOS/Services/Ngct/NgctServer.cs index 8d99721eb..ae00842d7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ngct/NgctServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ngct/NgctServer.cs @@ -12,10 +12,10 @@ namespace Ryujinx.HLE.HOS.Services.Ngct // If both conditions are true, it does this following code. Since we currently stub it, it's fine to don't check settings service values. ulong bufferPosition = context.Request.PtrBuff[0].Position; - ulong bufferSize = context.Request.PtrBuff[0].Size; + ulong bufferSize = context.Request.PtrBuff[0].Size; - bool isMatch = false; - string text = ""; + bool isMatch = false; + string text = ""; if (bufferSize != 0) { @@ -53,11 +53,11 @@ namespace Ryujinx.HLE.HOS.Services.Ngct // If both conditions are true, it does this following code. Since we currently stub it, it's fine to don't check settings service values. ulong bufferPosition = context.Request.PtrBuff[0].Position; - ulong bufferSize = context.Request.PtrBuff[0].Size; + ulong bufferSize = context.Request.PtrBuff[0].Size; ulong bufferFilteredPosition = context.Request.RecvListBuff[0].Position; - string text = ""; + string text = ""; string textFiltered = ""; if (bufferSize != 0) @@ -89,4 +89,4 @@ namespace Ryujinx.HLE.HOS.Services.Ngct return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/IStaticService.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/IStaticService.cs index d6a4a29fb..96e71cd07 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/IStaticService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/IStaticService.cs @@ -27,4 +27,4 @@ namespace Ryujinx.HLE.HOS.Services.Nifm return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/ResultCode.cs index 73cadb114..91a3d0af8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/ResultCode.cs @@ -2,14 +2,14 @@ namespace Ryujinx.HLE.HOS.Services.Nifm { enum ResultCode { - ModuleId = 110, + ModuleId = 110, ErrorCodeShift = 9, Success = 0, - Unknown112 = (112 << ErrorCodeShift) | ModuleId, // IRequest::GetResult - Unknown180 = (180 << ErrorCodeShift) | ModuleId, // IRequest::GetAppletInfo + Unknown112 = (112 << ErrorCodeShift) | ModuleId, // IRequest::GetResult + Unknown180 = (180 << ErrorCodeShift) | ModuleId, // IRequest::GetAppletInfo NoInternetConnection = (300 << ErrorCodeShift) | ModuleId, - ObjectIsNull = (350 << ErrorCodeShift) | ModuleId + ObjectIsNull = (350 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/GeneralService/GeneralServiceManager.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/GeneralService/GeneralServiceManager.cs index bbb218bbe..5f26f2114 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/GeneralService/GeneralServiceManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/GeneralService/GeneralServiceManager.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.GeneralService { static class GeneralServiceManager { - private static List _generalServices = new List(); + private static readonly List _generalServices = new(); public static int Count { @@ -27,4 +27,4 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.GeneralService return _generalServices.First(item => item.ClientId == clientId); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/GeneralService/Types/GeneralServiceDetail.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/GeneralService/Types/GeneralServiceDetail.cs index 3cf55345c..fab158515 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/GeneralService/Types/GeneralServiceDetail.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/GeneralService/Types/GeneralServiceDetail.cs @@ -2,7 +2,7 @@ { class GeneralServiceDetail { - public int ClientId; + public int ClientId; public bool IsAnyInternetRequestAccepted; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs index e9712e927..581a2906b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs @@ -11,7 +11,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService { class IGeneralService : DisposableIpcService { - private GeneralServiceDetail _generalServiceDetail; + private readonly GeneralServiceDetail _generalServiceDetail; private IPInterfaceProperties _targetPropertiesCache = null; private UnicastIPAddressInformation _targetAddressInfoCache = null; @@ -21,11 +21,11 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService { _generalServiceDetail = new GeneralServiceDetail { - ClientId = GeneralServiceManager.Count, - IsAnyInternetRequestAccepted = true // NOTE: Why not accept any internet request? + ClientId = GeneralServiceManager.Count, + IsAnyInternetRequestAccepted = true, // NOTE: Why not accept any internet request? }; - NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(LocalInterfaceCacheHandler); + NetworkChange.NetworkAddressChanged += LocalInterfaceCacheHandler; GeneralServiceManager.Add(_generalServiceDetail); } @@ -76,13 +76,13 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Unsafe.SizeOf()); - NetworkProfileData networkProfile = new NetworkProfileData + NetworkProfileData networkProfile = new() { - Uuid = UInt128Utils.CreateRandom() + Uuid = UInt128Utils.CreateRandom(), }; networkProfile.IpSettingData.IpAddressSetting = new IpAddressSetting(interfaceProperties, unicastAddress); - networkProfile.IpSettingData.DnsSetting = new DnsSetting(interfaceProperties); + networkProfile.IpSettingData.DnsSetting = new DnsSetting(interfaceProperties); "RyujinxNetwork"u8.CopyTo(networkProfile.Name.AsSpan()); @@ -137,11 +137,11 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService return ResultCode.NoInternetConnection; } - InternetConnectionStatus internetConnectionStatus = new InternetConnectionStatus + InternetConnectionStatus internetConnectionStatus = new() { - Type = InternetConnectionType.WiFi, + Type = InternetConnectionType.WiFi, WifiStrength = 3, - State = InternetConnectionState.Connected, + State = InternetConnectionState.Connected, }; context.ResponseData.WriteStruct(internetConnectionStatus); @@ -154,7 +154,9 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService public ResultCode IsAnyInternetRequestAccepted(ServiceCtx context) { ulong position = context.Request.PtrBuff[0].Position; - ulong size = context.Request.PtrBuff[0].Size; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong size = context.Request.PtrBuff[0].Size; +#pragma warning restore IDE0059 int clientId = context.Memory.Read(position); @@ -184,9 +186,9 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService private void LocalInterfaceCacheHandler(object sender, EventArgs e) { - Logger.Info?.Print(LogClass.ServiceNifm, $"NetworkAddress changed, invalidating cached data."); + Logger.Info?.Print(LogClass.ServiceNifm, "NetworkAddress changed, invalidating cached data."); - _targetPropertiesCache = null; + _targetPropertiesCache = null; _targetAddressInfoCache = null; } @@ -200,4 +202,4 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IRequest.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IRequest.cs index 87aad30be..577d03822 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IRequest.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IRequest.cs @@ -12,16 +12,18 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService { Error = 1, OnHold = 2, - Available = 3 + Available = 3, } - private KEvent _event0; - private KEvent _event1; + private readonly KEvent _event0; + private readonly KEvent _event1; private int _event0Handle; private int _event1Handle; - private uint _version; +#pragma warning disable IDE0052 // Remove unread private member + private readonly uint _version; +#pragma warning restore IDE0052 public IRequest(Horizon system, uint version) { @@ -116,7 +118,9 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService // GetAppletInfo(u32) -> (u32, u32, u32, buffer) public ResultCode GetAppletInfo(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment uint themeColor = context.RequestData.ReadUInt32(); +#pragma warning restore IDE0059 Logger.Stub?.PrintStub(LogClass.ServiceNifm); @@ -139,4 +143,4 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/DnsSetting.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/DnsSetting.cs index 374558eab..4a9d782db 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/DnsSetting.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/DnsSetting.cs @@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types struct DnsSetting { [MarshalAs(UnmanagedType.U1)] - public bool IsDynamicDnsEnabled; + public bool IsDynamicDnsEnabled; public IpV4Address PrimaryDns; public IpV4Address SecondaryDns; @@ -18,14 +18,14 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types if (interfaceProperties.DnsAddresses.Count == 0) { - PrimaryDns = new IpV4Address(); + PrimaryDns = new IpV4Address(); SecondaryDns = new IpV4Address(); } else { - PrimaryDns = new IpV4Address(interfaceProperties.DnsAddresses[0]); + PrimaryDns = new IpV4Address(interfaceProperties.DnsAddresses[0]); SecondaryDns = new IpV4Address(interfaceProperties.DnsAddresses[interfaceProperties.DnsAddresses.Count > 1 ? 1 : 0]); } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionState.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionState.cs index dfb8f76ca..8c9efa61e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionState.cs @@ -6,6 +6,6 @@ ConnectingType1 = 1, ConnectingType2 = 2, ConnectingType3 = 3, - Connected = 4, + Connected = 4, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionStatus.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionStatus.cs index ff944eca2..1bf41fc6b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionStatus.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionStatus.cs @@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types [StructLayout(LayoutKind.Sequential)] struct InternetConnectionStatus { - public InternetConnectionType Type; - public byte WifiStrength; + public InternetConnectionType Type; + public byte WifiStrength; public InternetConnectionState State; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionType.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionType.cs index af2bcfa18..ab03382d4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/InternetConnectionType.cs @@ -2,8 +2,8 @@ { enum InternetConnectionType : byte { - Invalid = 0, - WiFi = 1, + Invalid = 0, + WiFi = 1, Ethernet = 2, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/IpAddressSetting.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/IpAddressSetting.cs index 59c1f6a7f..5ea9d849c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/IpAddressSetting.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/IpAddressSetting.cs @@ -8,17 +8,17 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types struct IpAddressSetting { [MarshalAs(UnmanagedType.U1)] - public bool IsDhcpEnabled; + public bool IsDhcpEnabled; public IpV4Address Address; public IpV4Address IPv4Mask; public IpV4Address GatewayAddress; public IpAddressSetting(IPInterfaceProperties interfaceProperties, UnicastIPAddressInformation unicastIPAddressInformation) { - IsDhcpEnabled = OperatingSystem.IsMacOS() || interfaceProperties.DhcpServerAddresses.Count != 0; - Address = new IpV4Address(unicastIPAddressInformation.Address); - IPv4Mask = new IpV4Address(unicastIPAddressInformation.IPv4Mask); + IsDhcpEnabled = OperatingSystem.IsMacOS() || interfaceProperties.DhcpServerAddresses.Count != 0; + Address = new IpV4Address(unicastIPAddressInformation.Address); + IPv4Mask = new IpV4Address(unicastIPAddressInformation.IPv4Mask); GatewayAddress = (interfaceProperties.GatewayAddresses.Count == 0) ? new IpV4Address() : new IpV4Address(interfaceProperties.GatewayAddresses[0].Address); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/IpSettingData.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/IpSettingData.cs index 8ffe824c8..328dc7da6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/IpSettingData.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/IpSettingData.cs @@ -6,8 +6,8 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types struct IpSettingData { public IpAddressSetting IpAddressSetting; - public DnsSetting DnsSetting; - public ProxySetting ProxySetting; - public short Mtu; + public DnsSetting DnsSetting; + public ProxySetting ProxySetting; + public short Mtu; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/NetworkProfileData.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/NetworkProfileData.cs index e270c10ae..12a1c30fa 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/NetworkProfileData.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/NetworkProfileData.cs @@ -7,11 +7,11 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x17C)] struct NetworkProfileData { - public IpSettingData IpSettingData; - public UInt128 Uuid; - public Array64 Name; - public Array4 Unknown; + public IpSettingData IpSettingData; + public UInt128 Uuid; + public Array64 Name; + public Array4 Unknown; public WirelessSettingData WirelessSettingData; - public byte Padding; + public byte Padding; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/ProxySetting.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/ProxySetting.cs index 6e534fe1c..909138e80 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/ProxySetting.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/ProxySetting.cs @@ -9,19 +9,19 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types public struct ProxySetting { [MarshalAs(UnmanagedType.I1)] - public bool Enabled; - private byte _padding; - public short Port; - private NameStruct _name; + public bool Enabled; + private readonly byte _padding; + public short Port; + private NameStruct _name; [MarshalAs(UnmanagedType.I1)] - public bool AutoAuthEnabled; - public Array32 User; - public Array32 Pass; - private byte _padding2; + public bool AutoAuthEnabled; + public Array32 User; + public Array32 Pass; + private readonly byte _padding2; [StructLayout(LayoutKind.Sequential, Size = 0x64)] private struct NameStruct { } public Span Name => SpanHelpers.AsSpan(ref _name); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/WirelessSettingData.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/WirelessSettingData.cs index 8aa122c7d..53855a4ef 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/WirelessSettingData.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/Types/WirelessSettingData.cs @@ -6,10 +6,10 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x65)] struct WirelessSettingData { - public byte SsidLength; + public byte SsidLength; public Array32 Ssid; - public Array3 Unknown; + public Array3 Unknown; public Array64 Passphrase1; - public byte Passphrase2; + public byte Passphrase2; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/INetworkInstallManager.cs b/src/Ryujinx.HLE/HOS/Services/Nim/INetworkInstallManager.cs index ad79ca0de..7ed1ffa62 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/INetworkInstallManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/INetworkInstallManager.cs @@ -5,4 +5,4 @@ { public INetworkInstallManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessServer.cs b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessServer.cs index ab17871f8..29a47baf6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessServer.cs @@ -18,4 +18,4 @@ namespace Ryujinx.HLE.HOS.Services.Nim.ShopServiceAccessServerInterface return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessServerInterface.cs b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessServerInterface.cs index 950004fa4..847a432e9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessServerInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessServerInterface.cs @@ -41,4 +41,4 @@ namespace Ryujinx.HLE.HOS.Services.Nim return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessSystemInterface.cs b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessSystemInterface.cs index bf201b988..a57677aed 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessSystemInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessSystemInterface.cs @@ -5,4 +5,4 @@ { public IShopServiceAccessSystemInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessor.cs b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessor.cs index 3c0136faf..4d3002cc1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAccessor.cs @@ -39,4 +39,4 @@ namespace Ryujinx.HLE.HOS.Services.Nim.ShopServiceAccessServerInterface.ShopServ return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAsync.cs b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAsync.cs index 81d892c5d..150d48d4d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAsync.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceAsync.cs @@ -4,4 +4,4 @@ { public IShopServiceAsync() { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceManager.cs b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceManager.cs index 2420615a6..b5a2f6b55 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/IShopServiceManager.cs @@ -5,4 +5,4 @@ { public IShopServiceManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/Ntc/IStaticService.cs b/src/Ryujinx.HLE/HOS/Services/Nim/Ntc/IStaticService.cs index 4a63615bc..2b078be7d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/Ntc/IStaticService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/Ntc/IStaticService.cs @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Services.Nim.Ntc return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/Ntc/StaticService/IEnsureNetworkClockAvailabilityService.cs b/src/Ryujinx.HLE/HOS/Services/Nim/Ntc/StaticService/IEnsureNetworkClockAvailabilityService.cs index 82d0b5a80..9fee7b1ac 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/Ntc/StaticService/IEnsureNetworkClockAvailabilityService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/Ntc/StaticService/IEnsureNetworkClockAvailabilityService.cs @@ -8,13 +8,13 @@ namespace Ryujinx.HLE.HOS.Services.Nim.Ntc.StaticService { class IEnsureNetworkClockAvailabilityService : IpcService { - private KEvent _finishNotificationEvent; + private readonly KEvent _finishNotificationEvent; private ResultCode _taskResultCode; public IEnsureNetworkClockAvailabilityService(ServiceCtx context) { _finishNotificationEvent = new KEvent(context.Device.System.KernelContext); - _taskResultCode = ResultCode.Success; + _taskResultCode = ResultCode.Success; // NOTE: The service starts a thread that polls Nintendo NTP server and syncs the time with it. // Additionnally it gets and uses some settings too: @@ -74,4 +74,4 @@ namespace Ryujinx.HLE.HOS.Services.Nim.Ntc.StaticService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nim/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Nim/ResultCode.cs index 166e39a3c..3fcb90245 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nim/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nim/ResultCode.cs @@ -2,11 +2,11 @@ namespace Ryujinx.HLE.HOS.Services.Nim { enum ResultCode { - ModuleId = 137, + ModuleId = 137, ErrorCodeShift = 9, Success = 0, - NullArgument = (90 << ErrorCodeShift) | ModuleId + NullArgument = (90 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Notification/INotificationServicesForApplication.cs b/src/Ryujinx.HLE/HOS/Services/Notification/INotificationServicesForApplication.cs index c4a35b291..0d77dd6e6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Notification/INotificationServicesForApplication.cs +++ b/src/Ryujinx.HLE/HOS/Services/Notification/INotificationServicesForApplication.cs @@ -5,4 +5,4 @@ { public INotificationServicesForApplication(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Notification/INotificationServicesForSystem.cs b/src/Ryujinx.HLE/HOS/Services/Notification/INotificationServicesForSystem.cs index 0939dff62..8dc1dac3b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Notification/INotificationServicesForSystem.cs +++ b/src/Ryujinx.HLE/HOS/Services/Notification/INotificationServicesForSystem.cs @@ -5,4 +5,4 @@ { public INotificationServicesForSystem(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Npns/INpnsSystem.cs b/src/Ryujinx.HLE/HOS/Services/Npns/INpnsSystem.cs index fd8ccfb58..53c5b5392 100644 --- a/src/Ryujinx.HLE/HOS/Services/Npns/INpnsSystem.cs +++ b/src/Ryujinx.HLE/HOS/Services/Npns/INpnsSystem.cs @@ -5,4 +5,4 @@ { public INpnsSystem(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Npns/INpnsUser.cs b/src/Ryujinx.HLE/HOS/Services/Npns/INpnsUser.cs index 68e769385..cfa25255a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Npns/INpnsUser.cs +++ b/src/Ryujinx.HLE/HOS/Services/Npns/INpnsUser.cs @@ -5,4 +5,4 @@ { public INpnsUser(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IAddOnContentManager.cs b/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IAddOnContentManager.cs index b4b5bb1f5..083a83214 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IAddOnContentManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IAddOnContentManager.cs @@ -11,11 +11,11 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc class IAddOnContentManager : IpcService { private readonly KEvent _addOnContentListChangedEvent; - private int _addOnContentListChangedEventHandle; + private int _addOnContentListChangedEventHandle; private ulong _addOnContentBaseId; - private List _mountedAocTitleIds = new List(); + private readonly List _mountedAocTitleIds = new(); public IAddOnContentManager(ServiceCtx context) { @@ -44,7 +44,9 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // CountAddOnContent(pid) -> u32 public ResultCode CountAddOnContent(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pid = context.Request.HandleDesc.PId; +#pragma warning restore IDE0059 // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. @@ -55,7 +57,9 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // ListAddOnContent(u32 start_index, u32 buffer_size, pid) -> (u32 count, buffer) public ResultCode ListAddOnContent(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pid = context.Request.HandleDesc.PId; +#pragma warning restore IDE0059 // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. @@ -75,7 +79,9 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // GetAddOnContentBaseId(pid) -> u64 public ResultCode GetAddOnContentBaseId(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pid = context.Request.HandleDesc.PId; +#pragma warning restore IDE0059 // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. @@ -95,7 +101,9 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // PrepareAddOnContent(u32 index, pid) public ResultCode PrepareAddOnContent(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pid = context.Request.HandleDesc.PId; +#pragma warning restore IDE0059 // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. @@ -123,7 +131,9 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // GetAddOnContentListChangedEventWithProcessId(pid) -> handle public ResultCode GetAddOnContentListChangedEventWithProcessId(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pid = context.Request.HandleDesc.PId; +#pragma warning restore IDE0059 // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. @@ -142,7 +152,9 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // NotifyMountAddOnContent(pid, u64 title_id) public ResultCode NotifyMountAddOnContent(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pid = context.Request.HandleDesc.PId; +#pragma warning restore IDE0059 // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. @@ -160,7 +172,9 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // NotifyUnmountAddOnContent(pid, u64 title_id) public ResultCode NotifyUnmountAddOnContent(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pid = context.Request.HandleDesc.PId; +#pragma warning restore IDE0059 // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. @@ -175,7 +189,9 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // CheckAddOnContentMountStatus(pid) public ResultCode CheckAddOnContentMountStatus(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pid = context.Request.HandleDesc.PId; +#pragma warning restore IDE0059 // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. // Then it does some internal checks and returns InvalidBufferSize if they fail. @@ -239,10 +255,10 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // NOTE: Service call sys:set GetQuestFlag and store it internally. // If QuestFlag is true, counts some extra titles. - uint startIndex = context.RequestData.ReadUInt32(); - uint indexNumber = context.RequestData.ReadUInt32(); + uint startIndex = context.RequestData.ReadUInt32(); + uint indexNumber = context.RequestData.ReadUInt32(); ulong bufferPosition = context.Request.ReceiveBuff[0].Position; - ulong bufferSize = context.Request.ReceiveBuff[0].Size; + ulong bufferSize = context.Request.ReceiveBuff[0].Size; // TODO: This should use _addOnContentBaseId; uint aocTotalCount = (uint)context.Device.System.ContentManager.GetAocCount(); @@ -343,4 +359,4 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc return ((ulong)errorCode & 0x1FF | ((((ulong)errorCode >> 9) & 0x1FFF) << 32)) + 2000; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IContentsServiceManager.cs b/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IContentsServiceManager.cs index cb8903d42..40b0b2a8f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IContentsServiceManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IContentsServiceManager.cs @@ -4,4 +4,4 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc { public IContentsServiceManager() { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IPurchaseEventManager.cs b/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IPurchaseEventManager.cs index 1673fafc4..c92a10d66 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IPurchaseEventManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/IPurchaseEventManager.cs @@ -19,9 +19,9 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc // SetDefaultDeliveryTarget(pid, buffer unknown) public ResultCode SetDefaultDeliveryTarget(ServiceCtx context) { - ulong inBufferPosition = context.Request.SendBuff[0].Position; - ulong inBufferSize = context.Request.SendBuff[0].Size; - byte[] buffer = new byte[inBufferSize]; + ulong inBufferPosition = context.Request.SendBuff[0].Position; + ulong inBufferSize = context.Request.SendBuff[0].Size; + byte[] buffer = new byte[inBufferSize]; context.Memory.Read(inBufferPosition, buffer); @@ -65,4 +65,4 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/ResultCode.cs index 7602ecb36..b795a7563 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/Aoc/ResultCode.cs @@ -2,12 +2,12 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc { enum ResultCode { - ModuleId = 166, + ModuleId = 166, ErrorCodeShift = 9, Success = 0, InvalidBufferSize = (200 << ErrorCodeShift) | ModuleId, - InvalidPid = (300 << ErrorCodeShift) | ModuleId + InvalidPid = (300 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/IApplicationManagerInterface.cs b/src/Ryujinx.HLE/HOS/Services/Ns/IApplicationManagerInterface.cs index 06e911f8d..a8a2a8e0c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/IApplicationManagerInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/IApplicationManagerInterface.cs @@ -1,6 +1,5 @@ using LibHac.Ns; using Ryujinx.Common.Utilities; -using System; namespace Ryujinx.HLE.HOS.Services.Ns { @@ -13,8 +12,10 @@ namespace Ryujinx.HLE.HOS.Services.Ns // GetApplicationControlData(u8, u64) -> (unknown<4>, buffer) public ResultCode GetApplicationControlData(ServiceCtx context) { - byte source = (byte)context.RequestData.ReadInt64(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + byte source = (byte)context.RequestData.ReadInt64(); ulong titleId = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 ulong position = context.Request.ReceiveBuff[0].Position; @@ -25,4 +26,4 @@ namespace Ryujinx.HLE.HOS.Services.Ns return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/IDevelopInterface.cs b/src/Ryujinx.HLE/HOS/Services/Ns/IDevelopInterface.cs index c74ebd691..8f0f6cbe9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/IDevelopInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/IDevelopInterface.cs @@ -5,4 +5,4 @@ namespace Ryujinx.HLE.HOS.Services.Ns { public IDevelopInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/IReadOnlyApplicationControlDataInterface.cs b/src/Ryujinx.HLE/HOS/Services/Ns/IReadOnlyApplicationControlDataInterface.cs index aa37a1e7f..8327d6195 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/IReadOnlyApplicationControlDataInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/IReadOnlyApplicationControlDataInterface.cs @@ -11,8 +11,10 @@ namespace Ryujinx.HLE.HOS.Services.Ns // GetApplicationControlData(u8, u64) -> (unknown<4>, buffer) public ResultCode GetApplicationControlData(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment byte source = (byte)context.RequestData.ReadInt64(); ulong titleId = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 ulong position = context.Request.ReceiveBuff[0].Position; diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/IServiceGetterInterface.cs b/src/Ryujinx.HLE/HOS/Services/Ns/IServiceGetterInterface.cs index 886bffdd3..e45c6750c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/IServiceGetterInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/IServiceGetterInterface.cs @@ -27,4 +27,4 @@ namespace Ryujinx.HLE.HOS.Services.Ns return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/ISystemUpdateInterface.cs b/src/Ryujinx.HLE/HOS/Services/Ns/ISystemUpdateInterface.cs index 84ed3d0f0..1108778c3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/ISystemUpdateInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/ISystemUpdateInterface.cs @@ -5,4 +5,4 @@ namespace Ryujinx.HLE.HOS.Services.Ns { public ISystemUpdateInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ns/IVulnerabilityManagerInterface.cs b/src/Ryujinx.HLE/HOS/Services/Ns/IVulnerabilityManagerInterface.cs index 0b6409920..c1ec50bc8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ns/IVulnerabilityManagerInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ns/IVulnerabilityManagerInterface.cs @@ -5,4 +5,4 @@ namespace Ryujinx.HLE.HOS.Services.Ns { public IVulnerabilityManagerInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/Host1xContext.cs b/src/Ryujinx.HLE/HOS/Services/Nv/Host1xContext.cs index bb609fa4a..371edbecd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/Host1xContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/Host1xContext.cs @@ -11,7 +11,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv { public MemoryManager Smmu { get; } public NvMemoryAllocator MemoryAllocator { get; } - public Host1xDevice Host1x { get;} + public Host1xDevice Host1x { get; } public Host1xContext(GpuContext gpu, ulong pid) { @@ -29,4 +29,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv Host1x.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvDebugFSServices.cs b/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvDebugFSServices.cs index dffe8783d..22d0aacc5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvDebugFSServices.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvDebugFSServices.cs @@ -5,4 +5,4 @@ { public INvDrvDebugFSServices(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs b/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs index 1d075d43f..a0df66d00 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs @@ -25,13 +25,13 @@ namespace Ryujinx.HLE.HOS.Services.Nv [Service("nvdrv:t")] class INvDrvServices : IpcService { - private static readonly List _deviceFileDebugRegistry = new List() + private static readonly List _deviceFileDebugRegistry = new() { "/dev/nvhost-dbg-gpu", - "/dev/nvhost-prof-gpu" + "/dev/nvhost-prof-gpu", }; - private static readonly Dictionary _deviceFileRegistry = new Dictionary() + private static readonly Dictionary _deviceFileRegistry = new() { { "/dev/nvmap", typeof(NvMapDeviceFile) }, { "/dev/nvhost-ctrl", typeof(NvHostCtrlDeviceFile) }, @@ -47,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv { "/dev/nvhost-prof-gpu", typeof(NvHostProfGpuDeviceFile) }, }; - public static IdDictionary DeviceFileIdRegistry = new IdDictionary(); + public static IdDictionary DeviceFileIdRegistry = new(); private IVirtualMemoryManager _clientMemory; private ulong _owner; @@ -55,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv private bool _transferMemInitialized = false; // TODO: This should call set:sys::GetDebugModeFlag - private bool _debugModeEnabled = false; + private readonly bool _debugModeEnabled = false; public INvDrvServices(ServiceCtx context) : base(context.Device.System.NvDrvServer) { @@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv if (_deviceFileRegistry.TryGetValue(path, out Type deviceFileClass)) { - ConstructorInfo constructor = deviceFileClass.GetConstructor(new Type[] { typeof(ServiceCtx), typeof(IVirtualMemoryManager), typeof(ulong) }); + ConstructorInfo constructor = deviceFileClass.GetConstructor(new[] { typeof(ServiceCtx), typeof(IVirtualMemoryManager), typeof(ulong) }); NvDeviceFile deviceFile = (NvDeviceFile)constructor.Invoke(new object[] { context, _clientMemory, _owner }); @@ -91,13 +91,15 @@ namespace Ryujinx.HLE.HOS.Services.Nv private NvResult GetIoctlArgument(ServiceCtx context, NvIoctl ioctlCommand, out Span arguments) { - (ulong inputDataPosition, ulong inputDataSize) = context.Request.GetBufferType0x21(0); + (ulong inputDataPosition, ulong inputDataSize) = context.Request.GetBufferType0x21(0); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong outputDataPosition, ulong outputDataSize) = context.Request.GetBufferType0x22(0); +#pragma warning restore IDE0059 NvIoctl.Direction ioctlDirection = ioctlCommand.DirectionValue; - uint ioctlSize = ioctlCommand.Size; + uint ioctlSize = ioctlCommand.Size; - bool isRead = (ioctlDirection & NvIoctl.Direction.Read) != 0; + bool isRead = (ioctlDirection & NvIoctl.Direction.Read) != 0; bool isWrite = (ioctlDirection & NvIoctl.Direction.Write) != 0; if ((isWrite && ioctlSize > outputDataSize) || (isRead && ioctlSize > inputDataSize)) @@ -186,53 +188,29 @@ namespace Ryujinx.HLE.HOS.Services.Nv return NvResult.Success; } - private static NvResult ConvertInternalErrorCode(NvInternalResult errorCode) + private NvResult ConvertInternalErrorCode(NvInternalResult errorCode) { - switch (errorCode) + return errorCode switch { - case NvInternalResult.Success: - return NvResult.Success; - case NvInternalResult.Unknown0x72: - return NvResult.AlreadyAllocated; - case NvInternalResult.TimedOut: - case NvInternalResult.TryAgain: - case NvInternalResult.Interrupted: - return NvResult.Timeout; - case NvInternalResult.InvalidAddress: - return NvResult.InvalidAddress; - case NvInternalResult.NotSupported: - case NvInternalResult.Unknown0x18: - return NvResult.NotSupported; - case NvInternalResult.InvalidState: - return NvResult.InvalidState; - case NvInternalResult.ReadOnlyAttribute: - return NvResult.ReadOnlyAttribute; - case NvInternalResult.NoSpaceLeft: - case NvInternalResult.FileTooBig: - return NvResult.InvalidSize; - case NvInternalResult.FileTableOverflow: - case NvInternalResult.BadFileNumber: - return NvResult.FileOperationFailed; - case NvInternalResult.InvalidInput: - return NvResult.InvalidValue; - case NvInternalResult.NotADirectory: - return NvResult.DirectoryOperationFailed; - case NvInternalResult.Busy: - return NvResult.Busy; - case NvInternalResult.BadAddress: - return NvResult.InvalidAddress; - case NvInternalResult.AccessDenied: - case NvInternalResult.OperationNotPermitted: - return NvResult.AccessDenied; - case NvInternalResult.OutOfMemory: - return NvResult.InsufficientMemory; - case NvInternalResult.DeviceNotFound: - return NvResult.ModuleNotPresent; - case NvInternalResult.IoError: - return NvResult.ResourceError; - default: - return NvResult.IoctlFailed; - } + NvInternalResult.Success => NvResult.Success, + NvInternalResult.Unknown0x72 => NvResult.AlreadyAllocated, + NvInternalResult.TimedOut or NvInternalResult.TryAgain or NvInternalResult.Interrupted => NvResult.Timeout, + NvInternalResult.InvalidAddress => NvResult.InvalidAddress, + NvInternalResult.NotSupported or NvInternalResult.Unknown0x18 => NvResult.NotSupported, + NvInternalResult.InvalidState => NvResult.InvalidState, + NvInternalResult.ReadOnlyAttribute => NvResult.ReadOnlyAttribute, + NvInternalResult.NoSpaceLeft or NvInternalResult.FileTooBig => NvResult.InvalidSize, + NvInternalResult.FileTableOverflow or NvInternalResult.BadFileNumber => NvResult.FileOperationFailed, + NvInternalResult.InvalidInput => NvResult.InvalidValue, + NvInternalResult.NotADirectory => NvResult.DirectoryOperationFailed, + NvInternalResult.Busy => NvResult.Busy, + NvInternalResult.BadAddress => NvResult.InvalidAddress, + NvInternalResult.AccessDenied or NvInternalResult.OperationNotPermitted => NvResult.AccessDenied, + NvInternalResult.OutOfMemory => NvResult.InsufficientMemory, + NvInternalResult.DeviceNotFound => NvResult.ModuleNotPresent, + NvInternalResult.IoError => NvResult.ResourceError, + _ => NvResult.IoctlFailed, + }; } [CommandCmif(0)] @@ -240,7 +218,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv public ResultCode Open(ServiceCtx context) { NvResult errorCode = EnsureInitialized(); - int fd = -1; + int fd = -1; if (errorCode == NvResult.Success) { @@ -266,7 +244,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv if (errorCode == NvResult.Success) { - int fd = context.RequestData.ReadInt32(); + int fd = context.RequestData.ReadInt32(); NvIoctl ioctlCommand = context.RequestData.ReadStruct(); errorCode = GetIoctlArgument(context, ioctlCommand, out Span arguments); @@ -328,8 +306,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv // Initialize(u32 transfer_memory_size, handle current_process, handle transfer_memory) -> u32 error_code public ResultCode Initialize(ServiceCtx context) { - long transferMemSize = context.RequestData.ReadInt64(); - int transferMemHandle = context.Request.HandleDesc.ToCopy[1]; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + long transferMemSize = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 + int transferMemHandle = context.Request.HandleDesc.ToCopy[1]; // TODO: When transfer memory will be implemented, this could be removed. _transferMemInitialized = true; @@ -357,7 +337,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv if (errorCode == NvResult.Success) { - int fd = context.RequestData.ReadInt32(); + int fd = context.RequestData.ReadInt32(); uint eventId = context.RequestData.ReadUInt32(); errorCode = GetDeviceFileFromFd(fd, out NvDeviceFile deviceFile); @@ -393,9 +373,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv if (errorCode == NvResult.Success) { - int fd = context.RequestData.ReadInt32(); - uint argument = context.RequestData.ReadUInt32(); - int sharedMemoryHandle = context.Request.HandleDesc.ToCopy[0]; + int fd = context.RequestData.ReadInt32(); + uint argument = context.RequestData.ReadUInt32(); + int sharedMemoryHandle = context.Request.HandleDesc.ToCopy[0]; errorCode = GetDeviceFileFromFd(fd, out NvDeviceFile deviceFile); @@ -418,12 +398,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv if (_transferMemInitialized) { // TODO: Populate values when more RE will be done. - NvStatus nvStatus = new NvStatus + NvStatus nvStatus = new() { MemoryValue1 = 0, // GetMemStats(transfer_memory + 0x60, 3) MemoryValue2 = 0, // GetMemStats(transfer_memory + 0x60, 5) MemoryValue3 = 0, // transfer_memory + 0x78 - MemoryValue4 = 0 // transfer_memory + 0x80 + MemoryValue4 = 0, // transfer_memory + 0x80 }; context.ResponseData.WriteStruct(nvStatus); @@ -450,7 +430,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv // SetClientPID(u64, pid) -> u32 error_code public ResultCode SetClientPid(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment long pid = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 context.ResponseData.Write(0); @@ -481,7 +463,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv if (errorCode == NvResult.Success) { - int fd = context.RequestData.ReadInt32(); + int fd = context.RequestData.ReadInt32(); NvIoctl ioctlCommand = context.RequestData.ReadStruct(); (ulong inlineInBufferPosition, ulong inlineInBufferSize) = context.Request.GetBufferType0x21(1); @@ -492,7 +474,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv context.Memory.Read(inlineInBufferPosition, temp); - Span inlineInBuffer = new Span(temp); + Span inlineInBuffer = new(temp); if (errorCode == NvResult.Success) { @@ -530,7 +512,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv if (errorCode == NvResult.Success) { - int fd = context.RequestData.ReadInt32(); + int fd = context.RequestData.ReadInt32(); NvIoctl ioctlCommand = context.RequestData.ReadStruct(); (ulong inlineOutBufferPosition, ulong inlineOutBufferSize) = context.Request.GetBufferType0x22(1); @@ -541,7 +523,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv context.Memory.Read(inlineOutBufferPosition, temp); - Span inlineOutBuffer = new Span(temp); + Span inlineOutBuffer = new(temp); if (errorCode == NvResult.Success) { @@ -595,4 +577,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv DeviceFileIdRegistry.Clear(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/INvGemControl.cs b/src/Ryujinx.HLE/HOS/Services/Nv/INvGemControl.cs index 7bf99ed1a..2134c026e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/INvGemControl.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/INvGemControl.cs @@ -5,4 +5,4 @@ { public INvGemControl(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/INvGemCoreDump.cs b/src/Ryujinx.HLE/HOS/Services/Nv/INvGemCoreDump.cs index ff3774da1..ecbbe2226 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/INvGemCoreDump.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/INvGemCoreDump.cs @@ -5,4 +5,4 @@ { public INvGemCoreDump(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs index 9568fc84f..3eaf8a91b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs @@ -10,14 +10,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices abstract class NvDeviceFile { public readonly ServiceCtx Context; - public readonly ulong Owner; + public readonly ulong Owner; public string Path; public NvDeviceFile(ServiceCtx context, ulong owner) { Context = context; - Owner = owner; + Owner = owner; } public virtual NvInternalResult QueryEvent(out int eventHandle, uint eventId) diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs index 0e0fe7f2d..db460429d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs @@ -15,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu private const uint SmallPageSize = 0x1000; private const uint BigPageSize = 0x10000; - private static readonly uint[] _pageSizes = new uint[] { SmallPageSize, BigPageSize }; + private static readonly uint[] _pageSizes = { SmallPageSize, BigPageSize }; private const ulong SmallRegionLimit = 0x400000000UL; // 16 GiB private const ulong DefaultUserSize = 1UL << 37; @@ -32,10 +32,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu } } - private static readonly VmRegion[] _vmRegions = new VmRegion[] - { + private static readonly VmRegion[] _vmRegions = { new VmRegion((ulong)BigPageSize << 16, SmallRegionLimit), - new VmRegion(SmallRegionLimit, DefaultUserSize) + new VmRegion(SmallRegionLimit, DefaultUserSize), }; private readonly AddressSpaceContext _asContext; diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceContext.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceContext.cs index ab9d798e1..36aa10f34 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceContext.cs @@ -8,24 +8,24 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types private class Range { public ulong Start { get; } - public ulong End { get; } + public ulong End { get; } public Range(ulong address, ulong size) { Start = address; - End = size + Start; + End = size + Start; } } private class MappedMemory : Range { public ulong PhysicalAddress { get; } - public bool VaAllocated { get; } + public bool VaAllocated { get; } public MappedMemory(ulong address, ulong size, ulong physicalAddress, bool vaAllocated) : base(address, size) { PhysicalAddress = physicalAddress; - VaAllocated = vaAllocated; + VaAllocated = vaAllocated; } } @@ -38,7 +38,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types { Gmm = gmm; - _maps = new SortedList(); + _maps = new SortedList(); _reservations = new SortedList(); } @@ -123,9 +123,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types return _reservations.Remove(gpuVa); } - private static Range BinarySearch(SortedList list, ulong address) + private Range BinarySearch(SortedList list, ulong address) { - int left = 0; + int left = 0; int right = list.Count - 1; while (left <= right) @@ -154,11 +154,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types return null; } - private static Range BinarySearchLt(SortedList list, ulong address) + private Range BinarySearchLt(SortedList list, ulong address) { Range ltRg = null; - int left = 0; + int left = 0; int right = list.Count - 1; while (left <= right) diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceFlags.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceFlags.cs index 611cf78bf..0627d56f5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceFlags.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceFlags.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types [Flags] enum AddressSpaceFlags : uint { - FixedOffset = 1, + FixedOffset = 1, RemapSubRange = 0x100, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AllocSpaceArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AllocSpaceArguments.cs index d6dbbc261..c9d7724e8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AllocSpaceArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AllocSpaceArguments.cs @@ -5,10 +5,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types [StructLayout(LayoutKind.Sequential)] struct AllocSpaceArguments { - public uint Pages; - public uint PageSize; + public uint Pages; + public uint PageSize; public AddressSpaceFlags Flags; - public uint Padding; - public ulong Offset; + public uint Padding; + public ulong Offset; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/FreeSpaceArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/FreeSpaceArguments.cs index b25d295af..56e9028e5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/FreeSpaceArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/FreeSpaceArguments.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types struct FreeSpaceArguments { public ulong Offset; - public uint Pages; - public uint PageSize; + public uint Pages; + public uint PageSize; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/InitializeExArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/InitializeExArguments.cs index 882bda591..34b80bd31 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/InitializeExArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/InitializeExArguments.cs @@ -5,10 +5,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types [StructLayout(LayoutKind.Sequential)] struct InitializeExArguments { - public uint Flags; - public int AsFd; - public uint BigPageSize; - public uint Reserved; + public uint Flags; + public int AsFd; + public uint BigPageSize; + public uint Reserved; public ulong Unknown0; public ulong Unknown1; public ulong Unknown2; diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/MapBufferExArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/MapBufferExArguments.cs index 278793a02..fdeff9f8b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/MapBufferExArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/MapBufferExArguments.cs @@ -6,11 +6,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types struct MapBufferExArguments { public AddressSpaceFlags Flags; - public int Kind; - public int NvMapHandle; - public int PageSize; - public ulong BufferOffset; - public ulong MappingSize; - public ulong Offset; + public int Kind; + public int NvMapHandle; + public int PageSize; + public ulong BufferOffset; + public ulong MappingSize; + public ulong Offset; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/RemapArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/RemapArguments.cs index bc149d424..1fb224ff0 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/RemapArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/RemapArguments.cs @@ -7,9 +7,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types { public ushort Flags; public ushort Kind; - public int NvMapHandle; - public uint MapOffset; - public uint GpuOffset; - public uint Pages; + public int NvMapHandle; + public uint MapOffset; + public uint GpuOffset; + public uint Pages; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/UnmapBufferArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/UnmapBufferArguments.cs index 8fc4646ec..46a9659d5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/UnmapBufferArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/UnmapBufferArguments.cs @@ -2,7 +2,7 @@ { struct UnmapBufferArguments { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public ulong Offset; #pragma warning restore CS0649 } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/ChannelInitialization.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/ChannelInitialization.cs index 87a06bd39..59578775d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/ChannelInitialization.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/ChannelInitialization.cs @@ -1358,4 +1358,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel channel.Write(ClassId.Twod, 0x24C, 0x100); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs index 9f16a280f..bd2c5e4d0 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs @@ -19,9 +19,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private const uint MaxModuleSyncpoint = 16; +#pragma warning disable IDE0052 // Remove unread private member private uint _timeout; private uint _submitTimeout; private uint _timeslice; +#pragma warning restore IDE0052 private readonly Switch _device; @@ -34,7 +36,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel public enum ResourcePolicy { Device, - Channel + Channel, } protected static uint[] DeviceSyncpoints = new uint[MaxModuleSyncpoint]; @@ -47,14 +49,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel public NvHostChannelDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner) { - _device = context.Device; - _memory = memory; - _timeout = 3000; + _device = context.Device; + _memory = memory; + _timeout = 3000; _submitTimeout = 0; - _timeslice = 0; + _timeslice = 0; _host1xContext = GetHost1XContext(context.Device.Gpu, owner); - _contextId = _host1xContext.Host1x.CreateContext(); - Channel = _device.Gpu.CreateChannel(); + _contextId = _host1xContext.Host1x.CreateContext(); + Channel = _device.Gpu.CreateChannel(); ChannelInitialization.InitializeState(Channel); @@ -143,12 +145,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private NvInternalResult Submit(Span arguments) { - SubmitArguments submitHeader = GetSpanAndSkip(ref arguments, 1)[0]; - Span commandBuffers = GetSpanAndSkip(ref arguments, submitHeader.CmdBufsCount); - Span relocs = GetSpanAndSkip(ref arguments, submitHeader.RelocsCount); - Span relocShifts = GetSpanAndSkip(ref arguments, submitHeader.RelocsCount); - Span syncptIncrs = GetSpanAndSkip(ref arguments, submitHeader.SyncptIncrsCount); - Span fenceThresholds = GetSpanAndSkip(ref arguments, submitHeader.FencesCount); + SubmitArguments submitHeader = GetSpanAndSkip(ref arguments, 1)[0]; + Span commandBuffers = GetSpanAndSkip(ref arguments, submitHeader.CmdBufsCount); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + Span relocs = GetSpanAndSkip(ref arguments, submitHeader.RelocsCount); + Span relocShifts = GetSpanAndSkip(ref arguments, submitHeader.RelocsCount); +#pragma warning restore IDE0059 + Span syncptIncrs = GetSpanAndSkip(ref arguments, submitHeader.SyncptIncrsCount); + Span fenceThresholds = GetSpanAndSkip(ref arguments, submitHeader.FencesCount); lock (_device) { @@ -176,9 +180,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private Span GetSpanAndSkip(ref Span arguments, int count) where T : unmanaged { - Span output = MemoryMarshal.Cast(arguments).Slice(0, count); + Span output = MemoryMarshal.Cast(arguments)[..count]; - arguments = arguments.Slice(Unsafe.SizeOf() * count); + arguments = arguments[(Unsafe.SizeOf() * count)..]; return output; } @@ -227,9 +231,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private NvInternalResult MapCommandBuffer(Span arguments) { - int headerSize = Unsafe.SizeOf(); - MapCommandBufferArguments commandBufferHeader = MemoryMarshal.Cast(arguments)[0]; - Span commandBufferEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, commandBufferHeader.NumEntries); + int headerSize = Unsafe.SizeOf(); + MapCommandBufferArguments commandBufferHeader = MemoryMarshal.Cast(arguments)[0]; + Span commandBufferEntries = MemoryMarshal.Cast(arguments[headerSize..])[..commandBufferHeader.NumEntries]; foreach (ref CommandBufferHandle commandBufferEntry in commandBufferEntries) { @@ -269,9 +273,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private NvInternalResult UnmapCommandBuffer(Span arguments) { - int headerSize = Unsafe.SizeOf(); - MapCommandBufferArguments commandBufferHeader = MemoryMarshal.Cast(arguments)[0]; - Span commandBufferEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, commandBufferHeader.NumEntries); + int headerSize = Unsafe.SizeOf(); + MapCommandBufferArguments commandBufferHeader = MemoryMarshal.Cast(arguments)[0]; + Span commandBufferEntries = MemoryMarshal.Cast(arguments[headerSize..])[..commandBufferHeader.NumEntries]; foreach (ref CommandBufferHandle commandBufferEntry in commandBufferEntries) { @@ -320,9 +324,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private NvInternalResult SubmitGpfifo(Span arguments) { - int headerSize = Unsafe.SizeOf(); + int headerSize = Unsafe.SizeOf(); SubmitGpfifoArguments gpfifoSubmissionHeader = MemoryMarshal.Cast(arguments)[0]; - Span gpfifoEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, gpfifoSubmissionHeader.NumEntries); + Span gpfifoEntries = MemoryMarshal.Cast(arguments[headerSize..])[..gpfifoSubmissionHeader.NumEntries]; return SubmitGpfifo(ref gpfifoSubmissionHeader, gpfifoEntries); } @@ -473,7 +477,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel return ChannelSyncpoints[index]; } - public static uint GetSyncpointDevice(NvHostSyncpt syncpointManager, uint index, bool isClientManaged) + public uint GetSyncpointDevice(NvHostSyncpt syncpointManager, uint index, bool isClientManaged) { if (DeviceSyncpoints[index] != 0) { diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs index f33cc4601..5a1d1a68d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs @@ -8,9 +8,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel { internal class NvHostGpuDeviceFile : NvHostChannelDeviceFile { - private KEvent _smExceptionBptIntReportEvent; - private KEvent _smExceptionBptPauseReportEvent; - private KEvent _errorNotifierEvent; +#pragma warning disable IDE0052 // Remove unread private member + private readonly KEvent _smExceptionBptIntReportEvent; + private readonly KEvent _smExceptionBptPauseReportEvent; + private readonly KEvent _errorNotifierEvent; +#pragma warning restore IDE0052 private int _smExceptionBptIntReportEventHandle; private int _smExceptionBptPauseReportEventHandle; @@ -18,14 +20,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, memory, owner) { - _smExceptionBptIntReportEvent = CreateEvent(context, out _smExceptionBptIntReportEventHandle); + _smExceptionBptIntReportEvent = CreateEvent(context, out _smExceptionBptIntReportEventHandle); _smExceptionBptPauseReportEvent = CreateEvent(context, out _smExceptionBptPauseReportEventHandle); - _errorNotifierEvent = CreateEvent(context, out _errorNotifierEventHandle); + _errorNotifierEvent = CreateEvent(context, out _errorNotifierEventHandle); } - private static KEvent CreateEvent(ServiceCtx context, out int handle) + private KEvent CreateEvent(ServiceCtx context, out int handle) { - KEvent evnt = new KEvent(context.Device.System.KernelContext); + KEvent evnt = new(context.Device.System.KernelContext); if (context.Process.HandleTable.GenerateHandle(evnt.ReadableEvent, out handle) != Result.Success) { @@ -55,22 +57,13 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel public override NvInternalResult QueryEvent(out int eventHandle, uint eventId) { // TODO: accurately represent and implement those events. - switch (eventId) + eventHandle = eventId switch { - case 0x1: - eventHandle = _smExceptionBptIntReportEventHandle; - break; - case 0x2: - eventHandle = _smExceptionBptPauseReportEventHandle; - break; - case 0x3: - eventHandle = _errorNotifierEventHandle; - break; - default: - eventHandle = 0; - break; - } - + 0x1 => _smExceptionBptIntReportEventHandle, + 0x2 => _smExceptionBptPauseReportEventHandle, + 0x3 => _errorNotifierEventHandle, + _ => 0, + }; return eventHandle != 0 ? NvInternalResult.Success : NvInternalResult.InvalidInput; } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/AllocGpfifoExArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/AllocGpfifoExArguments.cs index 8e5a15235..37577a5f3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/AllocGpfifoExArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/AllocGpfifoExArguments.cs @@ -6,12 +6,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types [StructLayout(LayoutKind.Sequential)] struct AllocGpfifoExArguments { - public uint NumEntries; - public uint NumJobs; - public uint Flags; + public uint NumEntries; + public uint NumJobs; + public uint Flags; public NvFence Fence; - public uint Reserved1; - public uint Reserved2; - public uint Reserved3; + public uint Reserved1; + public uint Reserved2; + public uint Reserved3; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/AllocObjCtxArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/AllocObjCtxArguments.cs index fae91622c..1ffbb68fc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/AllocObjCtxArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/AllocObjCtxArguments.cs @@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types [StructLayout(LayoutKind.Sequential)] struct AllocObjCtxArguments { - public uint ClassNumber; - public uint Flags; + public uint ClassNumber; + public uint Flags; public ulong ObjectId; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs index 6a7e3da80..0777e6461 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs @@ -12,10 +12,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types [StructLayout(LayoutKind.Sequential, Pack = 1)] struct MapCommandBufferArguments { - public int NumEntries; - public int DataAddress; // Ignored by the driver. - public bool AttachHostChDas; - public byte Padding1; + public int NumEntries; + public int DataAddress; // Ignored by the driver. + public bool AttachHostChDas; + public byte Padding1; public short Padding2; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/NvChannel.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/NvChannel.cs index 8e2c6ca32..177f483f0 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/NvChannel.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/NvChannel.cs @@ -2,10 +2,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel { class NvChannel { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public int Timeout; public int SubmitTimeout; public int Timeslice; #pragma warning restore CS0649 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/NvChannelPriority.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/NvChannelPriority.cs index 4112a9fcc..c267e2df9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/NvChannelPriority.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/NvChannelPriority.cs @@ -2,8 +2,8 @@ { enum NvChannelPriority : uint { - Low = 50, + Low = 50, Medium = 100, - High = 150 + High = 150, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SetErrorNotifierArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SetErrorNotifierArguments.cs index 1aba53ca6..7e5a5e961 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SetErrorNotifierArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SetErrorNotifierArguments.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types { public ulong Offset; public ulong Size; - public uint Mem; - public uint Reserved; + public uint Mem; + public uint Reserved; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SubmitGpfifoArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SubmitGpfifoArguments.cs index a10abd4b5..1bb08da1b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SubmitGpfifoArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SubmitGpfifoArguments.cs @@ -6,9 +6,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types [StructLayout(LayoutKind.Sequential)] struct SubmitGpfifoArguments { - public long Address; - public int NumEntries; + public long Address; + public int NumEntries; public SubmitGpfifoFlags Flags; - public NvFence Fence; + public NvFence Fence; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SubmitGpfifoFlags.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SubmitGpfifoFlags.cs index d81fd3862..1f0609804 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SubmitGpfifoFlags.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/SubmitGpfifoFlags.cs @@ -6,10 +6,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types enum SubmitGpfifoFlags : uint { None, - FenceWait = 1 << 0, - FenceIncrement = 1 << 1, - HwFormat = 1 << 2, - SuppressWfi = 1 << 4, + FenceWait = 1 << 0, + FenceIncrement = 1 << 1, + HwFormat = 1 << 2, + SuppressWfi = 1 << 4, IncrementWithValue = 1 << 8, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/ZcullBindArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/ZcullBindArguments.cs index 19a997f43..71b124667 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/ZcullBindArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/ZcullBindArguments.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types struct ZcullBindArguments { public ulong GpuVirtualAddress; - public uint Mode; - public uint Reserved; + public uint Mode; + public uint Reserved; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs index f130c4558..6142611e5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs @@ -14,9 +14,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl { public const int EventsCount = 64; - private bool _isProductionMode; - private Switch _device; - private NvHostEvent[] _events; + private readonly bool _isProductionMode; + private readonly Switch _device; + private readonly NvHostEvent[] _events; public NvHostCtrlDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner) { diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/EventWaitArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/EventWaitArguments.cs index 16f970e86..84f678bab 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/EventWaitArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/EventWaitArguments.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl.Types struct EventWaitArguments { public NvFence Fence; - public int Timeout; - public uint Value; + public int Timeout; + public uint Value; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/GetConfigurationArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/GetConfigurationArguments.cs index 3ee318a37..a1400f8ef 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/GetConfigurationArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/GetConfigurationArguments.cs @@ -11,14 +11,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl.Types public static GetConfigurationArguments FromSpan(Span span) { - string domain = Encoding.ASCII.GetString(span.Slice(0, 0x41)); + string domain = Encoding.ASCII.GetString(span[..0x41]); string parameter = Encoding.ASCII.GetString(span.Slice(0x41, 0x41)); - GetConfigurationArguments result = new GetConfigurationArguments + GetConfigurationArguments result = new() { - Domain = domain.Substring(0, domain.IndexOf('\0')), - Parameter = parameter.Substring(0, parameter.IndexOf('\0')), - Configuration = span.Slice(0x82, 0x101).ToArray() + Domain = domain[..domain.IndexOf('\0')], + Parameter = parameter[..parameter.IndexOf('\0')], + Configuration = span.Slice(0x82, 0x101).ToArray(), }; return result; @@ -26,7 +26,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl.Types public void CopyTo(Span span) { - Encoding.ASCII.GetBytes(Domain + '\0').CopyTo(span.Slice(0, 0x41)); + Encoding.ASCII.GetBytes(Domain + '\0').CopyTo(span[..0x41]); Encoding.ASCII.GetBytes(Parameter + '\0').CopyTo(span.Slice(0x41, 0x41)); Configuration.CopyTo(span.Slice(0x82, 0x101)); } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostEvent.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostEvent.cs index 383fb3fbe..8f851f37a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostEvent.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostEvent.cs @@ -12,17 +12,19 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl { class NvHostEvent { - public NvFence Fence; + public NvFence Fence; public NvHostEventState State; - public KEvent Event; - public int EventHandle; + public KEvent Event; + public int EventHandle; - private uint _eventId; - private NvHostSyncpt _syncpointManager; + private readonly uint _eventId; +#pragma warning disable IDE0052 // Remove unread private member + private readonly NvHostSyncpt _syncpointManager; +#pragma warning restore IDE0052 private SyncpointWaiterHandle _waiterInformation; private NvFence _previousFailingFence; - private uint _failingCount; + private uint _failingCount; public readonly object Lock = new(); @@ -54,9 +56,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl private void ResetFailingState() { - _previousFailingFence.Id = NvFence.InvalidSyncPointId; + _previousFailingFence.Id = NvFence.InvalidSyncPointId; _previousFailingFence.Value = 0; - _failingCount = 0; + _failingCount = 0; } private void Signal() @@ -182,4 +184,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostEventState.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostEventState.cs index c7b4bc9fe..57c99d61f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostEventState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostEventState.cs @@ -2,11 +2,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl { enum NvHostEventState { - Available = 0, - Waiting = 1, + Available = 0, + Waiting = 1, Cancelling = 2, - Signaling = 3, - Signaled = 4, - Cancelled = 5 + Signaling = 3, + Signaled = 4, + Cancelled = 5, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostSyncPt.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostSyncPt.cs index 1b842aa17..9c6d025eb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostSyncPt.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/NvHostSyncPt.cs @@ -10,22 +10,22 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl public const int VBlank0SyncpointId = 26; public const int VBlank1SyncpointId = 27; - private int[] _counterMin; - private int[] _counterMax; - private bool[] _clientManaged; - private bool[] _assigned; + private readonly int[] _counterMin; + private readonly int[] _counterMax; + private readonly bool[] _clientManaged; + private readonly bool[] _assigned; - private Switch _device; + private readonly Switch _device; private readonly object _syncpointAllocatorLock = new(); public NvHostSyncpt(Switch device) { - _device = device; - _counterMin = new int[SynchronizationManager.MaxHardwareSyncpoints]; - _counterMax = new int[SynchronizationManager.MaxHardwareSyncpoints]; + _device = device; + _counterMin = new int[SynchronizationManager.MaxHardwareSyncpoints]; + _counterMax = new int[SynchronizationManager.MaxHardwareSyncpoints]; _clientManaged = new bool[SynchronizationManager.MaxHardwareSyncpoints]; - _assigned = new bool[SynchronizationManager.MaxHardwareSyncpoints]; + _assigned = new bool[SynchronizationManager.MaxHardwareSyncpoints]; // Reserve VBLANK syncpoints ReserveSyncpointLocked(VBlank0SyncpointId, true); @@ -39,7 +39,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl throw new ArgumentOutOfRangeException(nameof(id)); } - _assigned[id] = true; + _assigned[id] = true; _clientManaged[id] = isClientManaged; } @@ -76,7 +76,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl throw new ArgumentOutOfRangeException(nameof(id)); } - _assigned[id] = false; + _assigned[id] = false; _clientManaged[id] = false; SetSyncpointMinEqualSyncpointMax(id); @@ -196,4 +196,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/SyncptWaitArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/SyncptWaitArguments.cs index cda97f18a..b0efb7eda 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/SyncptWaitArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/SyncptWaitArguments.cs @@ -7,6 +7,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl.Types struct SyncptWaitArguments { public NvFence Fence; - public int Timeout; + public int Timeout; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/SyncptWaitExArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/SyncptWaitExArguments.cs index f2279c3de..7471274ba 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/SyncptWaitExArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/SyncptWaitExArguments.cs @@ -6,6 +6,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl.Types struct SyncptWaitExArguments { public SyncptWaitArguments Input; - public uint Value; + public uint Value; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs index d6a8e29fb..23cf1f002 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs @@ -10,15 +10,15 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu { class NvHostCtrlGpuDeviceFile : NvDeviceFile { - private static Stopwatch _pTimer = new Stopwatch(); - private static double _ticksToNs = (1.0 / Stopwatch.Frequency) * 1_000_000_000; + private static readonly Stopwatch _pTimer = new(); + private static readonly double _ticksToNs = (1.0 / Stopwatch.Frequency) * 1_000_000_000; - private KEvent _errorEvent; - private KEvent _unknownEvent; + private readonly KEvent _errorEvent; + private readonly KEvent _unknownEvent; public NvHostCtrlGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner) { - _errorEvent = new KEvent(context.Device.System.KernelContext); + _errorEvent = new KEvent(context.Device.System.KernelContext); _unknownEvent = new KEvent(context.Device.System.KernelContext); } @@ -125,6 +125,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu private NvInternalResult ZcullGetInfo(ref ZcullGetInfoArguments arguments) { +#pragma warning disable IDE0055 // Disable formatting arguments.WidthAlignPixels = 0x20; arguments.HeightAlignPixels = 0x20; arguments.PixelSquaresByAliquots = 0x400; @@ -135,6 +136,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu arguments.SubregionWidthAlignPixels = 0x20; arguments.SubregionHeightAlignPixels = 0x40; arguments.SubregionCount = 0x10; +#pragma warning restore IDE0055 return NvInternalResult.Success; } @@ -155,6 +157,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu { arguments.Header.BufferSize = 0xa0; +#pragma warning disable IDE0055 // Disable formatting characteristics.Arch = 0x120; characteristics.Impl = 0xb; characteristics.Rev = 0xa1; @@ -190,6 +193,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu characteristics.RopL2EnMask1 = 0x0; characteristics.ChipName = 0x6230326d67; characteristics.GrCompbitStoreBaseHw = 0x0; +#pragma warning restore IDE0055 arguments.Characteristics = characteristics; @@ -205,7 +209,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu { if (arguments.MaskBufferSize != 0) { - tpcMask = 3; + tpcMask = 3; arguments.TpcMask = tpcMask; } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/GetCharacteristicsArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/GetCharacteristicsArguments.cs index d66481781..64bfbe88d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/GetCharacteristicsArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/GetCharacteristicsArguments.cs @@ -5,46 +5,46 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu.Types [StructLayout(LayoutKind.Sequential)] struct GpuCharacteristics { - public int Arch; - public int Impl; - public int Rev; - public int NumGpc; + public int Arch; + public int Impl; + public int Rev; + public int NumGpc; public long L2CacheSize; public long OnBoardVideoMemorySize; - public int NumTpcPerGpc; - public int BusType; - public int BigPageSize; - public int CompressionPageSize; - public int PdeCoverageBitCount; - public int AvailableBigPageSizes; - public int GpcMask; - public int SmArchSmVersion; - public int SmArchSpaVersion; - public int SmArchWarpCount; - public int GpuVaBitCount; - public int Reserved; + public int NumTpcPerGpc; + public int BusType; + public int BigPageSize; + public int CompressionPageSize; + public int PdeCoverageBitCount; + public int AvailableBigPageSizes; + public int GpcMask; + public int SmArchSmVersion; + public int SmArchSpaVersion; + public int SmArchWarpCount; + public int GpuVaBitCount; + public int Reserved; public long Flags; - public int TwodClass; - public int ThreedClass; - public int ComputeClass; - public int GpfifoClass; - public int InlineToMemoryClass; - public int DmaCopyClass; - public int MaxFbpsCount; - public int FbpEnMask; - public int MaxLtcPerFbp; - public int MaxLtsPerLtc; - public int MaxTexPerTpc; - public int MaxGpcCount; - public int RopL2EnMask0; - public int RopL2EnMask1; + public int TwodClass; + public int ThreedClass; + public int ComputeClass; + public int GpfifoClass; + public int InlineToMemoryClass; + public int DmaCopyClass; + public int MaxFbpsCount; + public int FbpEnMask; + public int MaxLtcPerFbp; + public int MaxLtsPerLtc; + public int MaxTexPerTpc; + public int MaxGpcCount; + public int RopL2EnMask0; + public int RopL2EnMask1; public long ChipName; public long GrCompbitStoreBaseHw; } struct CharacteristicsHeader { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public long BufferSize; public long BufferAddress; #pragma warning restore CS0649 @@ -54,6 +54,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu.Types struct GetCharacteristicsArguments { public CharacteristicsHeader Header; - public GpuCharacteristics Characteristics; + public GpuCharacteristics Characteristics; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/GetTpcMasksArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/GetTpcMasksArguments.cs index 16ef2d6e1..dafde6e55 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/GetTpcMasksArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/GetTpcMasksArguments.cs @@ -6,10 +6,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu.Types [StructLayout(LayoutKind.Sequential)] struct GetTpcMasksArguments { - public int MaskBufferSize; - public int Reserved; + public int MaskBufferSize; + public int Reserved; public long MaskBufferAddress; - public int TpcMask; - public int Padding; + public int TpcMask; + public int Padding; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/ZbcSetTableArguments.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/ZbcSetTableArguments.cs index a4651f844..93c264332 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/ZbcSetTableArguments.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/ZbcSetTableArguments.cs @@ -1,5 +1,4 @@ using Ryujinx.Common.Memory; -using System; using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu.Types diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostDbgGpu/NvHostDbgGpuDeviceFile.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostDbgGpu/NvHostDbgGpuDeviceFile.cs index fe302b98e..667915787 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostDbgGpu/NvHostDbgGpuDeviceFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostDbgGpu/NvHostDbgGpuDeviceFile.cs @@ -1,5 +1,5 @@ using Ryujinx.Memory; -using System; + namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostDbgGpu { class NvHostDbgGpuDeviceFile : NvDeviceFile diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvInternalResult.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvInternalResult.cs index 9a3aa7aa1..c7746a556 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvInternalResult.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvInternalResult.cs @@ -2,31 +2,31 @@ { enum NvInternalResult { - Success = 0, + Success = 0, OperationNotPermitted = -1, - NoEntry = -2, - Interrupted = -4, - IoError = -5, - DeviceNotFound = -6, - BadFileNumber = -9, - TryAgain = -11, - OutOfMemory = -12, - AccessDenied = -13, - BadAddress = -14, - Busy = -16, - NotADirectory = -20, - InvalidInput = -22, - FileTableOverflow = -23, - Unknown0x18 = -24, - NotSupported = -25, - FileTooBig = -27, - NoSpaceLeft = -28, - ReadOnlyAttribute = -30, - NotImplemented = -38, - InvalidState = -40, - Restart = -85, - InvalidAddress = -99, - TimedOut = -110, - Unknown0x72 = -114, + NoEntry = -2, + Interrupted = -4, + IoError = -5, + DeviceNotFound = -6, + BadFileNumber = -9, + TryAgain = -11, + OutOfMemory = -12, + AccessDenied = -13, + BadAddress = -14, + Busy = -16, + NotADirectory = -20, + InvalidInput = -22, + FileTableOverflow = -23, + Unknown0x18 = -24, + NotSupported = -25, + FileTooBig = -27, + NoSpaceLeft = -28, + ReadOnlyAttribute = -30, + NotImplemented = -38, + InvalidState = -40, + Restart = -85, + InvalidAddress = -99, + TimedOut = -110, + Unknown0x72 = -114, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs index a52b36a22..06df5f93c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs @@ -10,7 +10,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap { private const int FlagNotFreedYet = 1; - private static NvMapIdDictionary _maps = new NvMapIdDictionary(); + private static readonly NvMapIdDictionary _maps = new(); public NvMapDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner) { @@ -125,8 +125,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap { map.Allocated = true; - map.Align = arguments.Align; - map.Kind = (byte)arguments.Kind; + map.Align = arguments.Align; + map.Kind = (byte)arguments.Kind; int size = BitUtils.AlignUp(map.Size, (int)MemoryManager.PageSize); @@ -142,7 +142,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap if (result == NvInternalResult.Success) { - map.Size = size; + map.Size = size; map.Address = address; } } @@ -164,12 +164,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap if (DecrementMapRefCount(Owner, arguments.Handle)) { arguments.Address = map.Address; - arguments.Flags = 0; + arguments.Flags = 0; } else { arguments.Address = 0; - arguments.Flags = FlagNotFreedYet; + arguments.Flags = FlagNotFreedYet; } arguments.Size = map.Size; @@ -190,15 +190,26 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap switch (arguments.Param) { - case NvMapHandleParam.Size: arguments.Result = map.Size; break; - case NvMapHandleParam.Align: arguments.Result = map.Align; break; - case NvMapHandleParam.Heap: arguments.Result = 0x40000000; break; - case NvMapHandleParam.Kind: arguments.Result = map.Kind; break; - case NvMapHandleParam.Compr: arguments.Result = 0; break; + case NvMapHandleParam.Size: + arguments.Result = map.Size; + break; + case NvMapHandleParam.Align: + arguments.Result = map.Align; + break; + case NvMapHandleParam.Heap: + arguments.Result = 0x40000000; + break; + case NvMapHandleParam.Kind: + arguments.Result = map.Kind; + break; + case NvMapHandleParam.Compr: + arguments.Result = 0; + break; // Note: Base is not supported and returns an error. // Any other value also returns an error. - default: return NvInternalResult.InvalidInput; + default: + return NvInternalResult.InvalidInput; } return NvInternalResult.Success; diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapAlloc.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapAlloc.cs index 2ec75fc96..dc4f5d608 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapAlloc.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapAlloc.cs @@ -5,11 +5,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap [StructLayout(LayoutKind.Sequential)] struct NvMapAlloc { - public int Handle; - public int HeapMask; - public int Flags; - public int Align; - public long Kind; + public int Handle; + public int HeapMask; + public int Flags; + public int Align; + public long Kind; public ulong Address; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapCreate.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapCreate.cs index b47e46294..5380c45c7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapCreate.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapCreate.cs @@ -8,4 +8,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap public int Size; public int Handle; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapFree.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapFree.cs index 34bcbc645..b0b3fa2d6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapFree.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapFree.cs @@ -5,10 +5,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap [StructLayout(LayoutKind.Sequential)] struct NvMapFree { - public int Handle; - public int Padding; + public int Handle; + public int Padding; public ulong Address; - public int Size; - public int Flags; + public int Size; + public int Flags; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapFromId.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapFromId.cs index 2e559534d..9ec81f9f3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapFromId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapFromId.cs @@ -8,4 +8,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap public int Id; public int Handle; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapGetId.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapGetId.cs index fe574eea5..8306ae4ca 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapGetId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapGetId.cs @@ -8,4 +8,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap public int Id; public int Handle; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapHandle.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapHandle.cs index c97cee492..301179747 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapHandle.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapHandle.cs @@ -4,15 +4,15 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap { class NvMapHandle { -#pragma warning disable CS0649 - public int Handle; - public int Id; +#pragma warning disable CS0649 // Field is never assigned to + public int Handle; + public int Id; #pragma warning restore CS0649 - public int Size; - public int Align; - public int Kind; + public int Size; + public int Align; + public int Kind; public ulong Address; - public bool Allocated; + public bool Allocated; public ulong DmaMapAddress; private long _dupes; @@ -37,4 +37,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap return Interlocked.Decrement(ref _dupes); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapHandleParam.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapHandleParam.cs index 9eb7efff9..21393e7a4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapHandleParam.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapHandleParam.cs @@ -2,11 +2,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap { enum NvMapHandleParam { - Size = 1, + Size = 1, Align = 2, - Base = 3, - Heap = 4, - Kind = 5, - Compr = 6 + Base = 3, + Heap = 4, + Kind = 5, + Compr = 6, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapIdDictionary.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapIdDictionary.cs index c4733e948..1b4d8dd42 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapIdDictionary.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapIdDictionary.cs @@ -58,4 +58,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap return values; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapParam.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapParam.cs index de5bab770..16fd78043 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapParam.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapParam.cs @@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap [StructLayout(LayoutKind.Sequential)] struct NvMapParam { - public int Handle; + public int Handle; public NvMapHandleParam Param; - public int Result; + public int Result; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvIoctl.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvIoctl.cs index 058586949..c9218e677 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvIoctl.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvIoctl.cs @@ -7,39 +7,39 @@ namespace Ryujinx.HLE.HOS.Services.Nv struct NvIoctl { public const int NvHostCustomMagic = 0x00; - public const int NvMapCustomMagic = 0x01; - public const int NvGpuAsMagic = 0x41; - public const int NvGpuMagic = 0x47; - public const int NvHostMagic = 0x48; + public const int NvMapCustomMagic = 0x01; + public const int NvGpuAsMagic = 0x41; + public const int NvGpuMagic = 0x47; + public const int NvHostMagic = 0x48; - private const int NumberBits = 8; - private const int TypeBits = 8; - private const int SizeBits = 14; + private const int NumberBits = 8; + private const int TypeBits = 8; + private const int SizeBits = 14; private const int DirectionBits = 2; - private const int NumberShift = 0; - private const int TypeShift = NumberShift + NumberBits; - private const int SizeShift = TypeShift + TypeBits; + private const int NumberShift = 0; + private const int TypeShift = NumberShift + NumberBits; + private const int SizeShift = TypeShift + TypeBits; private const int DirectionShift = SizeShift + SizeBits; - private const int NumberMask = (1 << NumberBits) - 1; - private const int TypeMask = (1 << TypeBits) - 1; - private const int SizeMask = (1 << SizeBits) - 1; + private const int NumberMask = (1 << NumberBits) - 1; + private const int TypeMask = (1 << TypeBits) - 1; + private const int SizeMask = (1 << SizeBits) - 1; private const int DirectionMask = (1 << DirectionBits) - 1; [Flags] public enum Direction : uint { - None = 0, - Read = 1, + None = 0, + Read = 1, Write = 2, } public uint RawValue; - public uint Number => (RawValue >> NumberShift) & NumberMask; - public uint Type => (RawValue >> TypeShift) & TypeMask; - public uint Size => (RawValue >> SizeShift) & SizeMask; - public Direction DirectionValue => (Direction)((RawValue >> DirectionShift) & DirectionMask); + public readonly uint Number => (RawValue >> NumberShift) & NumberMask; + public readonly uint Type => (RawValue >> TypeShift) & TypeMask; + public readonly uint Size => (RawValue >> SizeShift) & SizeMask; + public readonly Direction DirectionValue => (Direction)((RawValue >> DirectionShift) & DirectionMask); } } diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvMemoryAllocator.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvMemoryAllocator.cs index 341b5e576..66c953a2d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvMemoryAllocator.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvMemoryAllocator.cs @@ -20,10 +20,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv // Key --> Start Address of Region // Value --> End Address of Region - private readonly TreeDictionary _tree = new TreeDictionary(); + private readonly TreeDictionary _tree = new(); - private readonly Dictionary> _dictionary = new Dictionary>(); - private readonly LinkedList _list = new LinkedList(); + private readonly Dictionary> _dictionary = new(); + private readonly LinkedList _list = new(); public NvMemoryAllocator() { diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvFence.cs b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvFence.cs index 664610a43..5af613cd6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvFence.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvFence.cs @@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types public uint Id; public uint Value; - public bool IsValid() + public readonly bool IsValid() { return Id != InvalidSyncPointId; } @@ -28,7 +28,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types Value = gpuContext.Synchronization.IncrementSyncpoint(Id); } - public bool Wait(GpuContext gpuContext, TimeSpan timeout) + public readonly bool Wait(GpuContext gpuContext, TimeSpan timeout) { if (IsValid()) { diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvIoctlNotImplementedException.cs b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvIoctlNotImplementedException.cs index 9404c18ce..7af7e5337 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvIoctlNotImplementedException.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvIoctlNotImplementedException.cs @@ -6,9 +6,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types { class NvIoctlNotImplementedException : Exception { - public ServiceCtx Context { get; } + public ServiceCtx Context { get; } public NvDeviceFile DeviceFile { get; } - public NvIoctl Command { get; } + public NvIoctl Command { get; } public NvIoctlNotImplementedException(ServiceCtx context, NvDeviceFile deviceFile, NvIoctl command) : this(context, deviceFile, command, "The ioctl is not implemented.") @@ -17,9 +17,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types public NvIoctlNotImplementedException(ServiceCtx context, NvDeviceFile deviceFile, NvIoctl command, string message) : base(message) { - Context = context; + Context = context; DeviceFile = deviceFile; - Command = command; + Command = command; } public override string Message @@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types private string BuildMessage() { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new(); sb.AppendLine($"Device File: {DeviceFile.GetType().Name}"); sb.AppendLine(); diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs index b7a72eba0..844bce135 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs @@ -6,9 +6,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types { class NvQueryEventNotImplementedException : Exception { - public ServiceCtx Context { get; } + public ServiceCtx Context { get; } public NvDeviceFile DeviceFile { get; } - public uint EventId { get; } + public uint EventId { get; } public NvQueryEventNotImplementedException(ServiceCtx context, NvDeviceFile deviceFile, uint eventId) : this(context, deviceFile, eventId, "This query event is not implemented.") @@ -17,9 +17,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types public NvQueryEventNotImplementedException(ServiceCtx context, NvDeviceFile deviceFile, uint eventId, string message) : base(message) { - Context = context; + Context = context; DeviceFile = deviceFile; - EventId = eventId; + EventId = eventId; } public override string Message @@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types private string BuildMessage() { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new(); sb.AppendLine($"Device File: {DeviceFile.GetType().Name}"); sb.AppendLine(); diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvResult.cs b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvResult.cs index 1c9cae8ca..6f7e09a65 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvResult.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvResult.cs @@ -2,29 +2,29 @@ namespace Ryujinx.HLE.HOS.Services.Nv { enum NvResult : uint { - Success = 0, - NotImplemented = 1, - NotSupported = 2, - NotInitialized = 3, - InvalidParameter = 4, - Timeout = 5, - InsufficientMemory = 6, - ReadOnlyAttribute = 7, - InvalidState = 8, - InvalidAddress = 9, - InvalidSize = 10, - InvalidValue = 11, - AlreadyAllocated = 13, - Busy = 14, - ResourceError = 15, - CountMismatch = 16, - SharedMemoryTooSmall = 0x1000, - FileOperationFailed = 0x30003, + Success = 0, + NotImplemented = 1, + NotSupported = 2, + NotInitialized = 3, + InvalidParameter = 4, + Timeout = 5, + InsufficientMemory = 6, + ReadOnlyAttribute = 7, + InvalidState = 8, + InvalidAddress = 9, + InvalidSize = 10, + InvalidValue = 11, + AlreadyAllocated = 13, + Busy = 14, + ResourceError = 15, + CountMismatch = 16, + SharedMemoryTooSmall = 0x1000, + FileOperationFailed = 0x30003, DirectoryOperationFailed = 0x30004, NotAvailableInProduction = 0x30006, - IoctlFailed = 0x3000F, - AccessDenied = 0x30010, - FileNotFound = 0x30013, - ModuleNotPresent = 0xA000E, + IoctlFailed = 0x3000F, + AccessDenied = 0x30010, + FileNotFound = 0x30013, + ModuleNotPresent = 0xA000E, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvStatus.cs b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvStatus.cs index d5c35265a..ad4f70354 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvStatus.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/Types/NvStatus.cs @@ -12,4 +12,4 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types public long Padding1; public long Padding2; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Olsc/IOlscServiceForApplication.cs b/src/Ryujinx.HLE/HOS/Services/Olsc/IOlscServiceForApplication.cs index 89fe0c3a2..073e9b1b9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Olsc/IOlscServiceForApplication.cs +++ b/src/Ryujinx.HLE/HOS/Services/Olsc/IOlscServiceForApplication.cs @@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Services.Olsc [Service("olsc:u")] // 10.0.0+ class IOlscServiceForApplication : IpcService { - private bool _initialized; + private bool _initialized; private Dictionary _saveDataBackupSettingDatabase; public IOlscServiceForApplication(ServiceCtx context) { } @@ -65,8 +65,8 @@ namespace Ryujinx.HLE.HOS.Services.Olsc // SetSaveDataBackupSettingEnabled(nn::account::Uid, bool) public ResultCode SetSaveDataBackupSettingEnabled(ServiceCtx context) { - bool saveDataBackupSettingEnabled = context.RequestData.ReadUInt64() != 0; - UserId userId = context.RequestData.ReadStruct(); + bool saveDataBackupSettingEnabled = context.RequestData.ReadUInt64() != 0; + UserId userId = context.RequestData.ReadStruct(); if (!_initialized) { @@ -87,4 +87,4 @@ namespace Ryujinx.HLE.HOS.Services.Olsc return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Olsc/IOlscServiceForSystemService.cs b/src/Ryujinx.HLE/HOS/Services/Olsc/IOlscServiceForSystemService.cs index 52f74da92..27ac6b9cf 100644 --- a/src/Ryujinx.HLE/HOS/Services/Olsc/IOlscServiceForSystemService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Olsc/IOlscServiceForSystemService.cs @@ -5,4 +5,4 @@ { public IOlscServiceForSystemService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Olsc/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Olsc/ResultCode.cs index 141d1ae94..78392f6eb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Olsc/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Olsc/ResultCode.cs @@ -2,12 +2,12 @@ namespace Ryujinx.HLE.HOS.Services.Olsc { enum ResultCode { - ModuleId = 179, + ModuleId = 179, ErrorCodeShift = 9, Success = 0, - NullArgument = (100 << ErrorCodeShift) | ModuleId, - NotInitialized = (101 << ErrorCodeShift) | ModuleId + NullArgument = (100 << ErrorCodeShift) | ModuleId, + NotInitialized = (101 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Ovln/IReceiverService.cs b/src/Ryujinx.HLE/HOS/Services/Ovln/IReceiverService.cs index 67b82e424..99e929a70 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ovln/IReceiverService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ovln/IReceiverService.cs @@ -5,4 +5,4 @@ { public IReceiverService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ovln/ISenderService.cs b/src/Ryujinx.HLE/HOS/Services/Ovln/ISenderService.cs index 70c860e1c..e445c16cd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ovln/ISenderService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ovln/ISenderService.cs @@ -5,4 +5,4 @@ { public ISenderService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcie/ILogManager.cs b/src/Ryujinx.HLE/HOS/Services/Pcie/ILogManager.cs index 9c6387e15..78f927aa4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcie/ILogManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcie/ILogManager.cs @@ -5,4 +5,4 @@ { public ILogManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcie/IManager.cs b/src/Ryujinx.HLE/HOS/Services/Pcie/IManager.cs index f189dc8c8..0450a1ca4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcie/IManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcie/IManager.cs @@ -5,4 +5,4 @@ { public IManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pctl/IParentalControlServiceFactory.cs b/src/Ryujinx.HLE/HOS/Services/Pctl/IParentalControlServiceFactory.cs index 990aef092..707f6423c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pctl/IParentalControlServiceFactory.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pctl/IParentalControlServiceFactory.cs @@ -2,13 +2,13 @@ using Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory; namespace Ryujinx.HLE.HOS.Services.Pctl { - [Service("pctl", 0x303)] + [Service("pctl", 0x303)] [Service("pctl:a", 0x83BE)] [Service("pctl:r", 0x8040)] [Service("pctl:s", 0x838E)] class IParentalControlServiceFactory : IpcService { - private int _permissionFlag; + private readonly int _permissionFlag; public IParentalControlServiceFactory(ServiceCtx context, int permissionFlag) { @@ -37,4 +37,4 @@ namespace Ryujinx.HLE.HOS.Services.Pctl return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs b/src/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs index 594ee4e0e..cf8c1f78d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs @@ -1,31 +1,30 @@ using Ryujinx.Common.Logging; using Ryujinx.HLE.HOS.Services.Arp; using System; - using static LibHac.Ns.ApplicationControlProperty; namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory { class IParentalControlService : IpcService { - private ulong _pid; - private int _permissionFlag; - private ulong _titleId; + private readonly ulong _pid; + private readonly int _permissionFlag; + private ulong _titleId; private ParentalControlFlagValue _parentalControlFlag; - private int[] _ratingAge; +#pragma warning disable IDE0052, CS0414 // Remove unread private member + private int[] _ratingAge; -#pragma warning disable CS0414 // TODO: Find where they are set. - private bool _restrictionEnabled = false; - private bool _featuresRestriction = false; - private bool _freeCommunicationEnabled = false; - private bool _stereoVisionRestrictionConfigurable = true; - private bool _stereoVisionRestriction = false; -#pragma warning restore CS0414 + private readonly bool _restrictionEnabled = false; + private readonly bool _featuresRestriction = false; + private bool _freeCommunicationEnabled = false; + private readonly bool _stereoVisionRestrictionConfigurable = true; + private bool _stereoVisionRestriction = false; +#pragma warning restore IDE0052, CS0414 public IParentalControlService(ServiceCtx context, ulong pid, bool withInitialize, int permissionFlag) { - _pid = pid; + _pid = pid; _permissionFlag = permissionFlag; if (withInitialize) @@ -56,19 +55,19 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory _titleId = titleId; // TODO: Call nn::arp::GetApplicationControlProperty here when implemented, if it return ResultCode.Success we assign fields. - _ratingAge = Array.ConvertAll(context.Device.Processes.ActiveApplication.ApplicationControlProperties.RatingAge.ItemsRo.ToArray(), Convert.ToInt32); + _ratingAge = Array.ConvertAll(context.Device.Processes.ActiveApplication.ApplicationControlProperties.RatingAge.ItemsRo.ToArray(), Convert.ToInt32); _parentalControlFlag = context.Device.Processes.ActiveApplication.ApplicationControlProperties.ParentalControlFlag; } } if (_titleId != 0) { - // TODO: Service store some private fields in another static object. + // TODO: Service store some private fields in another object. if ((_permissionFlag & 0x8040) == 0) { - // TODO: Service store TitleId and FreeCommunicationEnabled in another static object. - // When it's done it signal an event in this static object. + // TODO: Service store TitleId and FreeCommunicationEnabled in another object. + // When it's done it signal an event in this object. Logger.Stub?.PrintStub(LogClass.ServicePctl); } } @@ -160,7 +159,9 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory } else { +#pragma warning disable CS0162 // Unreachable code return ResultCode.StereoVisionRestrictionConfigurableDisabled; +#pragma warning restore CS0162 } } @@ -173,7 +174,9 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory return ResultCode.PermissionDenied; } +#pragma warning disable // Remove unnecessary value assignment bool stereoVisionRestriction = false; +#pragma warning restore IDE0059 if (_stereoVisionRestrictionConfigurable) { @@ -202,7 +205,7 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory { _stereoVisionRestriction = stereoVisionRestriction; - // TODO: It signals an internal event of service. We have to determine where this event is used. + // TODO: It signals an internal event of service. We have to determine where this event is used. } } @@ -256,4 +259,4 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pctl/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Pctl/ResultCode.cs index fcf06ee97..86ff88142 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pctl/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pctl/ResultCode.cs @@ -2,15 +2,15 @@ { enum ResultCode { - ModuleId = 142, + ModuleId = 142, ErrorCodeShift = 9, Success = 0, - FreeCommunicationDisabled = (101 << ErrorCodeShift) | ModuleId, - StereoVisionDenied = (104 << ErrorCodeShift) | ModuleId, - InvalidPid = (131 << ErrorCodeShift) | ModuleId, - PermissionDenied = (133 << ErrorCodeShift) | ModuleId, + FreeCommunicationDisabled = (101 << ErrorCodeShift) | ModuleId, + StereoVisionDenied = (104 << ErrorCodeShift) | ModuleId, + InvalidPid = (131 << ErrorCodeShift) | ModuleId, + PermissionDenied = (133 << ErrorCodeShift) | ModuleId, StereoVisionRestrictionConfigurableDisabled = (181 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Pcv/Bpc/IBoardPowerControlManager.cs b/src/Ryujinx.HLE/HOS/Services/Pcv/Bpc/IBoardPowerControlManager.cs index 7d0222d55..e078de39a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcv/Bpc/IBoardPowerControlManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcv/Bpc/IBoardPowerControlManager.cs @@ -5,4 +5,4 @@ { public IBoardPowerControlManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/ClkrstManager/IClkrstSession.cs b/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/ClkrstManager/IClkrstSession.cs index b81e7fee0..a3ca56bf2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/ClkrstManager/IClkrstSession.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/ClkrstManager/IClkrstSession.cs @@ -6,32 +6,33 @@ namespace Ryujinx.HLE.HOS.Services.Pcv.Clkrst.ClkrstManager { class IClkrstSession : IpcService { - private DeviceCode _deviceCode; - private uint _unknown; - private uint _clockRate; + private readonly DeviceCode _deviceCode; +#pragma warning disable IDE0052 // Remove unread private member + private readonly uint _unknown; +#pragma warning restore IDE0052 + private uint _clockRate; - private DeviceCode[] allowedDeviceCodeTable = new DeviceCode[] - { + private readonly DeviceCode[] _allowedDeviceCodeTable = { DeviceCode.Cpu, DeviceCode.Gpu, DeviceCode.Disp1, DeviceCode.Disp2, DeviceCode.Tsec, DeviceCode.Mselect, DeviceCode.Sor1, DeviceCode.Host1x, DeviceCode.Vic, DeviceCode.Nvenc, DeviceCode.Nvjpg, DeviceCode.Nvdec, DeviceCode.Ape, DeviceCode.AudioDsp, DeviceCode.Emc, DeviceCode.Dsi, DeviceCode.SysBus, DeviceCode.XusbSs, DeviceCode.XusbHost, DeviceCode.XusbDevice, - DeviceCode.Gpuaux, DeviceCode.Pcie, DeviceCode.Apbdma, DeviceCode.Sdmmc1, - DeviceCode.Sdmmc2, DeviceCode.Sdmmc4 + DeviceCode.Gpuaux, DeviceCode.Pcie, DeviceCode.Apbdma, DeviceCode.Sdmmc1, + DeviceCode.Sdmmc2, DeviceCode.Sdmmc4, }; public IClkrstSession(DeviceCode deviceCode, uint unknown) { _deviceCode = deviceCode; - _unknown = unknown; + _unknown = unknown; } [CommandCmif(7)] // SetClockRate(u32 hz) public ResultCode SetClockRate(ServiceCtx context) { - if (!allowedDeviceCodeTable.Contains(_deviceCode)) + if (!_allowedDeviceCodeTable.Contains(_deviceCode)) { return ResultCode.InvalidArgument; } @@ -47,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Services.Pcv.Clkrst.ClkrstManager // GetClockRate() -> u32 hz public ResultCode GetClockRate(ServiceCtx context) { - if (!allowedDeviceCodeTable.Contains(_deviceCode)) + if (!_allowedDeviceCodeTable.Contains(_deviceCode)) { return ResultCode.InvalidArgument; } @@ -59,4 +60,4 @@ namespace Ryujinx.HLE.HOS.Services.Pcv.Clkrst.ClkrstManager return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/IArbitrationManager.cs b/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/IArbitrationManager.cs index 6f1e5d25d..492ffa57a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/IArbitrationManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/IArbitrationManager.cs @@ -5,4 +5,4 @@ { public IArbitrationManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/IClkrstManager.cs b/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/IClkrstManager.cs index 4ba2f0945..2e18dba74 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/IClkrstManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/IClkrstManager.cs @@ -19,7 +19,7 @@ namespace Ryujinx.HLE.HOS.Services.Pcv.Clkrst public ResultCode OpenSession(ServiceCtx context) { DeviceCode deviceCode = (DeviceCode)context.RequestData.ReadUInt32(); - uint unknown = context.RequestData.ReadUInt32(); + uint unknown = context.RequestData.ReadUInt32(); // TODO: Service checks the deviceCode and the unk value. @@ -54,4 +54,4 @@ namespace Ryujinx.HLE.HOS.Services.Pcv.Clkrst return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcv/IPcvService.cs b/src/Ryujinx.HLE/HOS/Services/Pcv/IPcvService.cs index 0e74dc3e5..5fd8493c9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcv/IPcvService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcv/IPcvService.cs @@ -5,4 +5,4 @@ { public IPcvService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcv/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Pcv/ResultCode.cs index 2041e423e..b1694b34d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcv/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcv/ResultCode.cs @@ -2,11 +2,11 @@ namespace Ryujinx.HLE.HOS.Services.Pcv { enum ResultCode { - ModuleId = 30, + ModuleId = 30, ErrorCodeShift = 9, Success = 0, - InvalidArgument = (5 << ErrorCodeShift) | ModuleId + InvalidArgument = (5 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcv/Rgltr/IRegulatorManager.cs b/src/Ryujinx.HLE/HOS/Services/Pcv/Rgltr/IRegulatorManager.cs index f7834777e..9a7d8a098 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcv/Rgltr/IRegulatorManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcv/Rgltr/IRegulatorManager.cs @@ -5,4 +5,4 @@ { public IRegulatorManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcv/Rtc/IRtcManager.cs b/src/Ryujinx.HLE/HOS/Services/Pcv/Rtc/IRtcManager.cs index 2b4a1239c..6e255a1dd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcv/Rtc/IRtcManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcv/Rtc/IRtcManager.cs @@ -5,4 +5,4 @@ { public IRtcManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pcv/Types/DeviceCode.cs b/src/Ryujinx.HLE/HOS/Services/Pcv/Types/DeviceCode.cs index 5380d82fb..79f13dbdf 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pcv/Types/DeviceCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pcv/Types/DeviceCode.cs @@ -2,93 +2,93 @@ { enum DeviceCode { - Cpu = 0x40000001, - Gpu = 0x40000002, - I2s1 = 0x40000003, - I2s2 = 0x40000004, - I2s3 = 0x40000005, - Pwm = 0x40000006, - I2c1 = 0x02000001, - I2c2 = 0x02000002, - I2c3 = 0x02000003, - I2c4 = 0x02000004, - I2c5 = 0x02000005, - I2c6 = 0x02000006, - Spi1 = 0x07000000, - Spi2 = 0x07000001, - Spi3 = 0x07000002, - Spi4 = 0x07000003, - Disp1 = 0x40000011, - Disp2 = 0x40000012, - Isp = 0x40000013, - Vi = 0x40000014, - Sdmmc1 = 0x40000015, - Sdmmc2 = 0x40000016, - Sdmmc3 = 0x40000017, - Sdmmc4 = 0x40000018, - Owr = 0x40000019, - Csite = 0x4000001A, - Tsec = 0x4000001B, - Mselect = 0x4000001C, - Hda2codec2x = 0x4000001D, - Actmon = 0x4000001E, - I2cSlow = 0x4000001F, - Sor1 = 0x40000020, - Sata = 0x40000021, - Hda = 0x40000022, + Cpu = 0x40000001, + Gpu = 0x40000002, + I2s1 = 0x40000003, + I2s2 = 0x40000004, + I2s3 = 0x40000005, + Pwm = 0x40000006, + I2c1 = 0x02000001, + I2c2 = 0x02000002, + I2c3 = 0x02000003, + I2c4 = 0x02000004, + I2c5 = 0x02000005, + I2c6 = 0x02000006, + Spi1 = 0x07000000, + Spi2 = 0x07000001, + Spi3 = 0x07000002, + Spi4 = 0x07000003, + Disp1 = 0x40000011, + Disp2 = 0x40000012, + Isp = 0x40000013, + Vi = 0x40000014, + Sdmmc1 = 0x40000015, + Sdmmc2 = 0x40000016, + Sdmmc3 = 0x40000017, + Sdmmc4 = 0x40000018, + Owr = 0x40000019, + Csite = 0x4000001A, + Tsec = 0x4000001B, + Mselect = 0x4000001C, + Hda2codec2x = 0x4000001D, + Actmon = 0x4000001E, + I2cSlow = 0x4000001F, + Sor1 = 0x40000020, + Sata = 0x40000021, + Hda = 0x40000022, XusbCoreHostSrc = 0x40000023, - XusbFalconSrc = 0x40000024, - XusbFsSrc = 0x40000025, - XusbCoreDevSrc = 0x40000026, - XusbSsSrc = 0x40000027, - UartA = 0x03000001, - UartB = 0x35000405, - UartC = 0x3500040F, - UartD = 0x37000001, - Host1x = 0x4000002C, - Entropy = 0x4000002D, - SocTherm = 0x4000002E, - Vic = 0x4000002F, - Nvenc = 0x40000030, - Nvjpg = 0x40000031, - Nvdec = 0x40000032, - Qspi = 0x40000033, - ViI2c = 0x40000034, - Tsecb = 0x40000035, - Ape = 0x40000036, - AudioDsp = 0x40000037, - AudioUart = 0x40000038, - Emc = 0x40000039, - Plle = 0x4000003A, - PlleHwSeq = 0x4000003B, - Dsi = 0x4000003C, - Maud = 0x4000003D, - Dpaux1 = 0x4000003E, - MipiCal = 0x4000003F, - UartFstMipiCal = 0x40000040, - Osc = 0x40000041, - SysBus = 0x40000042, - SorSafe = 0x40000043, - XusbSs = 0x40000044, - XusbHost = 0x40000045, - XusbDevice = 0x40000046, - Extperiph1 = 0x40000047, - Ahub = 0x40000048, - Hda2hdmicodec = 0x40000049, - Gpuaux = 0x4000004A, - UsbD = 0x4000004B, - Usb2 = 0x4000004C, - Pcie = 0x4000004D, - Afi = 0x4000004E, - PciExClk = 0x4000004F, - PExUsbPhy = 0x40000050, - XUsbPadCtl = 0x40000051, - Apbdma = 0x40000052, - Usb2TrkClk = 0x40000053, - XUsbIoPll = 0x40000054, - XUsbIoPllHwSeq = 0x40000055, - Cec = 0x40000056, - Extperiph2 = 0x40000057, - OscClk = 0x40000080 + XusbFalconSrc = 0x40000024, + XusbFsSrc = 0x40000025, + XusbCoreDevSrc = 0x40000026, + XusbSsSrc = 0x40000027, + UartA = 0x03000001, + UartB = 0x35000405, + UartC = 0x3500040F, + UartD = 0x37000001, + Host1x = 0x4000002C, + Entropy = 0x4000002D, + SocTherm = 0x4000002E, + Vic = 0x4000002F, + Nvenc = 0x40000030, + Nvjpg = 0x40000031, + Nvdec = 0x40000032, + Qspi = 0x40000033, + ViI2c = 0x40000034, + Tsecb = 0x40000035, + Ape = 0x40000036, + AudioDsp = 0x40000037, + AudioUart = 0x40000038, + Emc = 0x40000039, + Plle = 0x4000003A, + PlleHwSeq = 0x4000003B, + Dsi = 0x4000003C, + Maud = 0x4000003D, + Dpaux1 = 0x4000003E, + MipiCal = 0x4000003F, + UartFstMipiCal = 0x40000040, + Osc = 0x40000041, + SysBus = 0x40000042, + SorSafe = 0x40000043, + XusbSs = 0x40000044, + XusbHost = 0x40000045, + XusbDevice = 0x40000046, + Extperiph1 = 0x40000047, + Ahub = 0x40000048, + Hda2hdmicodec = 0x40000049, + Gpuaux = 0x4000004A, + UsbD = 0x4000004B, + Usb2 = 0x4000004C, + Pcie = 0x4000004D, + Afi = 0x4000004E, + PciExClk = 0x4000004F, + PExUsbPhy = 0x40000050, + XUsbPadCtl = 0x40000051, + Apbdma = 0x40000052, + Usb2TrkClk = 0x40000053, + XUsbIoPll = 0x40000054, + XUsbIoPllHwSeq = 0x40000055, + Cec = 0x40000056, + Extperiph2 = 0x40000057, + OscClk = 0x40000080, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pm/IBootModeInterface.cs b/src/Ryujinx.HLE/HOS/Services/Pm/IBootModeInterface.cs index 45771db6b..473f74135 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pm/IBootModeInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pm/IBootModeInterface.cs @@ -5,4 +5,4 @@ { public IBootModeInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs b/src/Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs index cce2967a7..82190b047 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs @@ -46,4 +46,4 @@ namespace Ryujinx.HLE.HOS.Services.Pm return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pm/IInformationInterface.cs b/src/Ryujinx.HLE/HOS/Services/Pm/IInformationInterface.cs index b3b5595fd..500d121ea 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pm/IInformationInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pm/IInformationInterface.cs @@ -24,4 +24,4 @@ namespace Ryujinx.HLE.HOS.Services.Pm return ResultCode.ProcessNotFound; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs index 92b5925e4..9894cd204 100644 --- a/src/Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs @@ -2,16 +2,16 @@ namespace Ryujinx.HLE.HOS.Services.Pm { enum ResultCode { - ModuleId = 15, + ModuleId = 15, ErrorCodeShift = 9, Success = 0, - ProcessNotFound = (1 << ErrorCodeShift) | ModuleId, - AlreadyStarted = (2 << ErrorCodeShift) | ModuleId, - NotTerminated = (3 << ErrorCodeShift) | ModuleId, - DebugHookInUse = (4 << ErrorCodeShift) | ModuleId, + ProcessNotFound = (1 << ErrorCodeShift) | ModuleId, + AlreadyStarted = (2 << ErrorCodeShift) | ModuleId, + NotTerminated = (3 << ErrorCodeShift) | ModuleId, + DebugHookInUse = (4 << ErrorCodeShift) | ModuleId, ApplicationRunning = (5 << ErrorCodeShift) | ModuleId, - InvalidSize = (6 << ErrorCodeShift) | ModuleId, + InvalidSize = (6 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Psc/IPmControl.cs b/src/Ryujinx.HLE/HOS/Services/Psc/IPmControl.cs index 3810c2826..6682a8481 100644 --- a/src/Ryujinx.HLE/HOS/Services/Psc/IPmControl.cs +++ b/src/Ryujinx.HLE/HOS/Services/Psc/IPmControl.cs @@ -5,4 +5,4 @@ { public IPmControl(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Psc/IPmService.cs b/src/Ryujinx.HLE/HOS/Services/Psc/IPmService.cs index c8dfb32e0..1be338660 100644 --- a/src/Ryujinx.HLE/HOS/Services/Psc/IPmService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Psc/IPmService.cs @@ -5,4 +5,4 @@ { public IPmService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Psc/IPmUnknown.cs b/src/Ryujinx.HLE/HOS/Services/Psc/IPmUnknown.cs index ef48fa41e..95aff9ece 100644 --- a/src/Ryujinx.HLE/HOS/Services/Psc/IPmUnknown.cs +++ b/src/Ryujinx.HLE/HOS/Services/Psc/IPmUnknown.cs @@ -5,4 +5,4 @@ { public IPmUnknown(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Fan/IManager.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Fan/IManager.cs index e2fe22356..8011f9193 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Fan/IManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Fan/IManager.cs @@ -5,4 +5,4 @@ { public IManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Fgm/IDebugger.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Fgm/IDebugger.cs index a93f52830..8cb671bc3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Fgm/IDebugger.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Fgm/IDebugger.cs @@ -5,4 +5,4 @@ { public IDebugger(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Fgm/ISession.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Fgm/ISession.cs index 0e3f965b3..1488c2886 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Fgm/ISession.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Fgm/ISession.cs @@ -7,4 +7,4 @@ { public ISession(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Pcm/IManager.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Pcm/IManager.cs index 0bec45fa3..53f3bc391 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Pcm/IManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Pcm/IManager.cs @@ -5,4 +5,4 @@ { public IManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/IPsmServer.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/IPsmServer.cs index 4e3d3e8e2..0c475150b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/IPsmServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/IPsmServer.cs @@ -42,4 +42,4 @@ namespace Ryujinx.HLE.HOS.Services.Ptm.Psm return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/IPsmSession.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/IPsmSession.cs index 5d11f227a..a603b7e41 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/IPsmSession.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/IPsmSession.cs @@ -7,12 +7,12 @@ namespace Ryujinx.HLE.HOS.Services.Ptm.Psm { class IPsmSession : IpcService { - private KEvent _stateChangeEvent; - private int _stateChangeEventHandle; + private readonly KEvent _stateChangeEvent; + private int _stateChangeEventHandle; public IPsmSession(Horizon system) { - _stateChangeEvent = new KEvent(system.KernelContext); + _stateChangeEvent = new KEvent(system.KernelContext); _stateChangeEventHandle = -1; } @@ -85,4 +85,4 @@ namespace Ryujinx.HLE.HOS.Services.Ptm.Psm return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/Types/ChargerType.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/Types/ChargerType.cs index 3e239711d..a0b0c3dd4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/Types/ChargerType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Psm/Types/ChargerType.cs @@ -4,6 +4,6 @@ { None, ChargerOrDock, - UsbC + UsbC, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Tc/IManager.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Tc/IManager.cs index 1daa4f5e8..0317e532b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Tc/IManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Tc/IManager.cs @@ -5,4 +5,4 @@ { public IManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Ts/IMeasurementServer.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Ts/IMeasurementServer.cs index 6ddc0aef2..07a067688 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Ts/IMeasurementServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Ts/IMeasurementServer.cs @@ -36,4 +36,4 @@ namespace Ryujinx.HLE.HOS.Services.Ptm.Ts return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ptm/Ts/Types/Location.cs b/src/Ryujinx.HLE/HOS/Services/Ptm/Ts/Types/Location.cs index e72491d51..c04db09ce 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ptm/Ts/Types/Location.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ptm/Ts/Types/Location.cs @@ -3,6 +3,6 @@ enum Location : byte { Internal, - External + External, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs b/src/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs index 966adcffe..3f31fe9f8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs @@ -18,16 +18,16 @@ namespace Ryujinx.HLE.HOS.Services.Ro [Service("ro:1")] // 7.0.0+ class IRoInterface : DisposableIpcService { - private const int MaxNrr = 0x40; - private const int MaxNro = 0x40; - private const int MaxMapRetries = 0x200; + private const int MaxNrr = 0x40; + private const int MaxNro = 0x40; + private const int MaxMapRetries = 0x200; private const int GuardPagesSize = 0x4000; private const uint NrrMagic = 0x3052524E; private const uint NroMagic = 0x304F524E; - private List _nrrInfos; - private List _nroInfos; + private readonly List _nrrInfos; + private readonly List _nroInfos; private KProcess _owner; private IVirtualMemoryManager _ownerMm; @@ -36,8 +36,8 @@ namespace Ryujinx.HLE.HOS.Services.Ro { _nrrInfos = new List(MaxNrr); _nroInfos = new List(MaxNro); - _owner = null; - _ownerMm = null; + _owner = null; + _ownerMm = null; } private ResultCode ParseNrr(out NrrInfo nrrInfo, ServiceCtx context, ulong nrrAddress, ulong nrrSize) @@ -64,7 +64,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro return ResultCode.InvalidSize; } - List hashes = new List(); + List hashes = new(); for (int i = 0; i < header.HashesCount; i++) { @@ -130,7 +130,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro return ResultCode.InvalidAddress; } - uint magic = _owner.CpuMemory.Read(nroAddress + 0x10); + uint magic = _owner.CpuMemory.Read(nroAddress + 0x10); uint nroFileSize = _owner.CpuMemory.Read(nroAddress + 0x18); if (magic != NroMagic || nroSize != nroFileSize) @@ -142,7 +142,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro _owner.CpuMemory.Read(nroAddress, nroData); - MemoryStream stream = new MemoryStream(nroData); + MemoryStream stream = new(nroData); byte[] nroHash = SHA256.HashData(stream); @@ -158,19 +158,19 @@ namespace Ryujinx.HLE.HOS.Services.Ro stream.Position = 0; - NroExecutable nro = new NroExecutable(stream.AsStorage(), nroAddress, bssAddress); + NroExecutable nro = new(stream.AsStorage(), nroAddress, bssAddress); // Check if everything is page align. if ((nro.Text.Length & 0xFFF) != 0 || (nro.Ro.Length & 0xFFF) != 0 || - (nro.Data.Length & 0xFFF) != 0 || (nro.BssSize & 0xFFF) != 0) + (nro.Data.Length & 0xFFF) != 0 || (nro.BssSize & 0xFFF) != 0) { return ResultCode.InvalidNro; } // Check if everything is contiguous. - if (nro.RoOffset != nro.TextOffset + nro.Text.Length || - nro.DataOffset != nro.RoOffset + nro.Ro.Length || - nroFileSize != nro.DataOffset + nro.Data.Length) + if (nro.RoOffset != nro.TextOffset + nro.Text.Length || + nro.DataOffset != nro.RoOffset + nro.Ro.Length || + nroFileSize != nro.DataOffset + nro.Data.Length) { return ResultCode.InvalidNro; } @@ -316,7 +316,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro private Result SetNroMemoryPermissions(KProcess process, IExecutable relocatableObject, ulong baseAddress) { ulong textStart = baseAddress + relocatableObject.TextOffset; - ulong roStart = baseAddress + relocatableObject.RoOffset; + ulong roStart = baseAddress + relocatableObject.RoOffset; ulong dataStart = baseAddress + relocatableObject.DataOffset; ulong bssStart = dataStart + (ulong)relocatableObject.Data.Length; @@ -324,7 +324,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro ulong bssEnd = BitUtils.AlignUp(bssStart + relocatableObject.BssSize, KPageTableBase.PageSize); process.CpuMemory.Write(textStart, relocatableObject.Text); - process.CpuMemory.Write(roStart, relocatableObject.Ro); + process.CpuMemory.Write(roStart, relocatableObject.Ro); process.CpuMemory.Write(dataStart, relocatableObject.Data); MemoryHelper.FillWithZeros(process.CpuMemory, bssStart, (int)(bssEnd - bssStart)); @@ -381,9 +381,9 @@ namespace Ryujinx.HLE.HOS.Services.Ro private ResultCode UnmapNroFromInfo(NroInfo info) { ulong textSize = (ulong)info.Executable.Text.Length; - ulong roSize = (ulong)info.Executable.Ro.Length; + ulong roSize = (ulong)info.Executable.Ro.Length; ulong dataSize = (ulong)info.Executable.Data.Length; - ulong bssSize = (ulong)info.Executable.BssSize; + ulong bssSize = (ulong)info.Executable.BssSize; Result result = Result.Success; @@ -434,17 +434,16 @@ namespace Ryujinx.HLE.HOS.Services.Ro context.RequestData.ReadUInt64(); ulong nroHeapAddress = context.RequestData.ReadUInt64(); - ulong nroSize = context.RequestData.ReadUInt64(); + ulong nroSize = context.RequestData.ReadUInt64(); ulong bssHeapAddress = context.RequestData.ReadUInt64(); - ulong bssSize = context.RequestData.ReadUInt64(); + ulong bssSize = context.RequestData.ReadUInt64(); ulong nroMappedAddress = 0; if (result == ResultCode.Success) { - NroInfo info; - result = ParseNro(out info, context, nroHeapAddress, nroSize, bssHeapAddress, bssSize); + result = ParseNro(out NroInfo info, context, nroHeapAddress, nroSize, bssHeapAddress, bssSize); if (result == ResultCode.Success) { @@ -503,12 +502,11 @@ namespace Ryujinx.HLE.HOS.Services.Ro context.RequestData.ReadUInt64(); ulong nrrAddress = context.RequestData.ReadUInt64(); - ulong nrrSize = context.RequestData.ReadUInt64(); + ulong nrrSize = context.RequestData.ReadUInt64(); if (result == ResultCode.Success) { - NrrInfo info; - result = ParseNrr(out info, context, nrrAddress, nrrSize); + result = ParseNrr(out NrrInfo info, context, nrrAddress, nrrSize); if (result == ResultCode.Success) { @@ -599,4 +597,4 @@ namespace Ryujinx.HLE.HOS.Services.Ro } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ro/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Ro/ResultCode.cs index 92bb55029..1e31e5760 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ro/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ro/ResultCode.cs @@ -2,26 +2,26 @@ { enum ResultCode { - ModuleId = 22, + ModuleId = 22, ErrorCodeShift = 9, Success = 0, InsufficientAddressSpace = (2 << ErrorCodeShift) | ModuleId, - AlreadyLoaded = (3 << ErrorCodeShift) | ModuleId, - InvalidNro = (4 << ErrorCodeShift) | ModuleId, - InvalidNrr = (6 << ErrorCodeShift) | ModuleId, - TooManyNro = (7 << ErrorCodeShift) | ModuleId, - TooManyNrr = (8 << ErrorCodeShift) | ModuleId, - NotAuthorized = (9 << ErrorCodeShift) | ModuleId, + AlreadyLoaded = (3 << ErrorCodeShift) | ModuleId, + InvalidNro = (4 << ErrorCodeShift) | ModuleId, + InvalidNrr = (6 << ErrorCodeShift) | ModuleId, + TooManyNro = (7 << ErrorCodeShift) | ModuleId, + TooManyNrr = (8 << ErrorCodeShift) | ModuleId, + NotAuthorized = (9 << ErrorCodeShift) | ModuleId, - InvalidNrrType = (10 << ErrorCodeShift) | ModuleId, + InvalidNrrType = (10 << ErrorCodeShift) | ModuleId, - InvalidAddress = (1025 << ErrorCodeShift) | ModuleId, - InvalidSize = (1026 << ErrorCodeShift) | ModuleId, - NotLoaded = (1028 << ErrorCodeShift) | ModuleId, - NotRegistered = (1029 << ErrorCodeShift) | ModuleId, - InvalidSession = (1030 << ErrorCodeShift) | ModuleId, - InvalidProcess = (1031 << ErrorCodeShift) | ModuleId, + InvalidAddress = (1025 << ErrorCodeShift) | ModuleId, + InvalidSize = (1026 << ErrorCodeShift) | ModuleId, + NotLoaded = (1028 << ErrorCodeShift) | ModuleId, + NotRegistered = (1029 << ErrorCodeShift) | ModuleId, + InvalidSession = (1030 << ErrorCodeShift) | ModuleId, + InvalidProcess = (1031 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ro/Types/NroInfo.cs b/src/Ryujinx.HLE/HOS/Services/Ro/Types/NroInfo.cs index 45daf1bda..fd4947c6f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ro/Types/NroInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ro/Types/NroInfo.cs @@ -6,30 +6,30 @@ namespace Ryujinx.HLE.HOS.Services.Ro { public NroExecutable Executable { get; private set; } - public byte[] Hash { get; private set; } - public ulong NroAddress { get; private set; } - public ulong NroSize { get; private set; } - public ulong BssAddress { get; private set; } - public ulong BssSize { get; private set; } - public ulong TotalSize { get; private set; } - public ulong NroMappedAddress { get; set; } + public byte[] Hash { get; private set; } + public ulong NroAddress { get; private set; } + public ulong NroSize { get; private set; } + public ulong BssAddress { get; private set; } + public ulong BssSize { get; private set; } + public ulong TotalSize { get; private set; } + public ulong NroMappedAddress { get; set; } public NroInfo( - NroExecutable executable, - byte[] hash, - ulong nroAddress, - ulong nroSize, - ulong bssAddress, - ulong bssSize, - ulong totalSize) + NroExecutable executable, + byte[] hash, + ulong nroAddress, + ulong nroSize, + ulong bssAddress, + ulong bssSize, + ulong totalSize) { Executable = executable; - Hash = hash; + Hash = hash; NroAddress = nroAddress; - NroSize = nroSize; + NroSize = nroSize; BssAddress = bssAddress; - BssSize = bssSize; - TotalSize = totalSize; + BssSize = bssSize; + TotalSize = totalSize; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ro/Types/NrrInfo.cs b/src/Ryujinx.HLE/HOS/Services/Ro/Types/NrrInfo.cs index 45c34f1c5..b322c06ed 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ro/Types/NrrInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ro/Types/NrrInfo.cs @@ -4,15 +4,15 @@ namespace Ryujinx.HLE.HOS.Services.Ro { class NrrInfo { - public NrrHeader Header { get; private set; } - public List Hashes { get; private set; } - public ulong NrrAddress { get; private set; } + public NrrHeader Header { get; private set; } + public List Hashes { get; private set; } + public ulong NrrAddress { get; private set; } public NrrInfo(ulong nrrAddress, NrrHeader header, List hashes) { NrrAddress = nrrAddress; - Header = header; - Hashes = hashes; + Header = header; + Hashes = hashes; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Avm/IAvmService.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Avm/IAvmService.cs index d65c8bbae..ec312108b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Avm/IAvmService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Avm/IAvmService.cs @@ -5,4 +5,4 @@ { public IAvmService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/INotifyService.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/INotifyService.cs index 5247a238d..c2e042901 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/INotifyService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/INotifyService.cs @@ -5,4 +5,4 @@ { public INotifyService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/IQueryService.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/IQueryService.cs index 1f66ff9de..c46050b85 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/IQueryService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/IQueryService.cs @@ -21,4 +21,4 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pdm return QueryPlayStatisticsManager.GetPlayStatistics(context, true); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/QueryPlayStatisticsManager.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/QueryPlayStatisticsManager.cs index 52a07d466..7017cc50c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/QueryPlayStatisticsManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/QueryPlayStatisticsManager.cs @@ -9,17 +9,17 @@ using System.Runtime.CompilerServices; namespace Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService { - static class QueryPlayStatisticsManager + class QueryPlayStatisticsManager { - private static Dictionary applicationPlayStatistics = new Dictionary(); + private static readonly Dictionary _applicationPlayStatistics = new(); internal static ResultCode GetPlayStatistics(ServiceCtx context, bool byUserId = false) { ulong inputPosition = context.Request.SendBuff[0].Position; - ulong inputSize = context.Request.SendBuff[0].Size; + ulong inputSize = context.Request.SendBuff[0].Size; ulong outputPosition = context.Request.ReceiveBuff[0].Position; - ulong outputSize = context.Request.ReceiveBuff[0].Size; + ulong outputSize = context.Request.ReceiveBuff[0].Size; UserId userId = byUserId ? context.RequestData.ReadStruct() : new UserId(); @@ -33,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService PlayLogQueryCapability queryCapability = (PlayLogQueryCapability)context.Device.Processes.ActiveApplication.ApplicationControlProperties.PlayLogQueryCapability; - List titleIds = new List(); + List titleIds = new(); for (ulong i = 0; i < inputSize / sizeof(ulong); i++) { @@ -55,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize); // Return ResultCode.ServiceUnavailable if data is locked by another process. - var filteredApplicationPlayStatistics = applicationPlayStatistics.AsEnumerable(); + var filteredApplicationPlayStatistics = _applicationPlayStatistics.AsEnumerable(); if (queryCapability == PlayLogQueryCapability.None) { @@ -81,4 +81,4 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/Types/ApplicationPlayStatistics.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/Types/ApplicationPlayStatistics.cs index c28d757e8..b58fd2191 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/Types/ApplicationPlayStatistics.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/Types/ApplicationPlayStatistics.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService.Types struct ApplicationPlayStatistics { public ulong TitleId; - public long TotalPlayTime; // In nanoseconds. - public long TotalLaunchCount; + public long TotalPlayTime; // In nanoseconds. + public long TotalLaunchCount; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/Types/PlayLogQueryCapability.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/Types/PlayLogQueryCapability.cs index 9e4b85dea..c1e77ed3b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/Types/PlayLogQueryCapability.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/QueryService/Types/PlayLogQueryCapability.cs @@ -4,6 +4,6 @@ { None, WhiteList, - All + All, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/ResultCode.cs index c337051b4..dd20220f2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Pdm/ResultCode.cs @@ -2,14 +2,14 @@ { enum ResultCode { - ModuleId = 178, + ModuleId = 178, ErrorCodeShift = 9, Success = 0, - InvalidUserID = (100 << ErrorCodeShift) | ModuleId, - UserNotFound = (101 << ErrorCodeShift) | ModuleId, + InvalidUserID = (100 << ErrorCodeShift) | ModuleId, + UserNotFound = (101 << ErrorCodeShift) | ModuleId, ServiceUnavailable = (150 << ErrorCodeShift) | ModuleId, - FileStorageFailure = (200 << ErrorCodeShift) | ModuleId + FileStorageFailure = (200 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/ISharedFontManager.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/ISharedFontManager.cs index 9e2f7a4e5..45c4ce7e1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/ISharedFontManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/ISharedFontManager.cs @@ -17,7 +17,9 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl // RequestLoad(u32) public ResultCode RequestLoad(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32(); +#pragma warning restore IDE0059 // We don't need to do anything here because we do lazy initialization // on SharedFontManager (the font is loaded when necessary). @@ -28,7 +30,9 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl // GetLoadState(u32) -> u32 public ResultCode GetLoadState(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32(); +#pragma warning restore IDE0059 // 1 (true) indicates that the font is already loaded. // All fonts are already loaded. @@ -82,8 +86,10 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl // GetSharedFontInOrderOfPriority(bytes<8, 1>) -> (u8, u32, buffer, buffer, buffer) public ResultCode GetSharedFontInOrderOfPriority(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment long languageCode = context.RequestData.ReadInt64(); - int loadedCount = 0; +#pragma warning restore IDE0059 + int loadedCount = 0; for (SharedFontType type = 0; type < SharedFontType.Count; type++) { @@ -115,15 +121,15 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl private bool AddFontToOrderOfPriorityList(ServiceCtx context, SharedFontType fontType, uint offset) { ulong typesPosition = context.Request.ReceiveBuff[0].Position; - ulong typesSize = context.Request.ReceiveBuff[0].Size; + ulong typesSize = context.Request.ReceiveBuff[0].Size; ulong offsetsPosition = context.Request.ReceiveBuff[1].Position; - ulong offsetsSize = context.Request.ReceiveBuff[1].Size; + ulong offsetsSize = context.Request.ReceiveBuff[1].Size; ulong fontSizeBufferPosition = context.Request.ReceiveBuff[2].Position; - ulong fontSizeBufferSize = context.Request.ReceiveBuff[2].Size; + ulong fontSizeBufferSize = context.Request.ReceiveBuff[2].Size; - if (offset + 4 > (uint)typesSize || + if (offset + 4 > (uint)typesSize || offset + 4 > (uint)offsetsSize || offset + 4 > (uint)fontSizeBufferSize) { @@ -137,4 +143,4 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl return true; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/SharedFontManager.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/SharedFontManager.cs index c0556c316..641795890 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/SharedFontManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/SharedFontManager.cs @@ -19,10 +19,10 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl { class SharedFontManager { - private static readonly uint FontKey = 0x06186249; - private static readonly uint BFTTFMagic = 0x18029a7f; + private const uint FontKey = 0x06186249; + private const uint BFTTFMagic = 0x18029a7f; - private readonly Switch _device; + private readonly Switch _device; private readonly SharedMemoryStorage _storage; private struct FontInfo @@ -33,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl public FontInfo(int offset, int size) { Offset = offset; - Size = size; + Size = size; } } @@ -41,7 +41,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl public SharedFontManager(Switch device, SharedMemoryStorage storage) { - _device = device; + _device = device; _storage = storage; } @@ -65,7 +65,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl if (contentManager.TryGetFontTitle(name, out ulong fontTitle) && contentManager.TryGetFontFilename(name, out string fontFilename)) { string contentPath = contentManager.GetInstalledContentPath(fontTitle, StorageId.BuiltInSystem, NcaContentType.Data); - string fontPath = _device.FileSystem.SwitchPathToSystemPath(contentPath); + string fontPath = VirtualFileSystem.SwitchPathToSystemPath(contentPath); if (!string.IsNullOrWhiteSpace(fontPath)) { @@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl using (IStorage ncaFileStream = new LocalStorage(fontPath, FileAccess.Read, FileMode.Open)) { - Nca nca = new Nca(_device.System.KeySet, ncaFileStream); + Nca nca = new(_device.System.KeySet, ncaFileStream); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel); using var fontFile = new UniqueRef(); @@ -83,7 +83,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl data = DecryptFont(fontFile.Get.AsStream()); } - FontInfo info = new FontInfo((int)fontOffset, data.Length); + FontInfo info = new((int)fontOffset, data.Length); WriteMagicAndSize(fontOffset, data.Length); @@ -121,7 +121,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl { SharedFontType.SimplifiedChineseEx, CreateFont("FontExtendedChineseSimplified") }, { SharedFontType.TraditionalChinese, CreateFont("FontChineseTraditional") }, { SharedFontType.Korean, CreateFont("FontKorean") }, - { SharedFontType.NintendoEx, CreateFont("FontNintendoExtended") } + { SharedFontType.NintendoEx, CreateFont("FontNintendoExtended") }, }; if (fontOffset > Horizon.FontSize) @@ -156,28 +156,27 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl return _fontData[fontType].Offset + 8; } - private static byte[] DecryptFont(Stream bfttfStream) + private byte[] DecryptFont(Stream bfttfStream) { static uint KXor(uint data) => data ^ FontKey; - using (BinaryReader reader = new BinaryReader(bfttfStream)) - using (MemoryStream ttfStream = MemoryStreamManager.Shared.GetStream()) - using (BinaryWriter output = new BinaryWriter(ttfStream)) + using BinaryReader reader = new(bfttfStream); + using MemoryStream ttfStream = MemoryStreamManager.Shared.GetStream(); + using BinaryWriter output = new(ttfStream); + + if (KXor(reader.ReadUInt32()) != BFTTFMagic) { - if (KXor(reader.ReadUInt32()) != BFTTFMagic) - { - throw new InvalidDataException("Error: Input file is not in BFTTF format!"); - } - - bfttfStream.Position += 4; - - for (int i = 0; i < (bfttfStream.Length - 8) / 4; i++) - { - output.Write(KXor(reader.ReadUInt32())); - } - - return ttfStream.ToArray(); + throw new InvalidDataException("Error: Input file is not in BFTTF format!"); } + + bfttfStream.Position += 4; + + for (int i = 0; i < (bfttfStream.Length - 8) / 4; i++) + { + output.Write(KXor(reader.ReadUInt32())); + } + + return ttfStream.ToArray(); } } } diff --git a/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/Types/SharedFontType.cs b/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/Types/SharedFontType.cs index 90ee4f037..273fcafbd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/Types/SharedFontType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sdb/Pl/Types/SharedFontType.cs @@ -2,12 +2,12 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl.Types { public enum SharedFontType { - JapanUsEurope = 0, - SimplifiedChinese = 1, + JapanUsEurope = 0, + SimplifiedChinese = 1, SimplifiedChineseEx = 2, - TraditionalChinese = 3, - Korean = 4, - NintendoEx = 5, - Count + TraditionalChinese = 3, + Korean = 4, + NintendoEx = 5, + Count, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/ServerBase.cs b/src/Ryujinx.HLE/HOS/Services/ServerBase.cs index 4cd55a2e9..f107f5026 100644 --- a/src/Ryujinx.HLE/HOS/Services/ServerBase.cs +++ b/src/Ryujinx.HLE/HOS/Services/ServerBase.cs @@ -23,26 +23,25 @@ namespace Ryujinx.HLE.HOS.Services // not large enough. private const int PointerBufferSize = 0x8000; - private readonly static uint[] DefaultCapabilities = new uint[] - { + private readonly static uint[] _defaultCapabilities = { 0x030363F7, 0x1FFFFFCF, 0x207FFFEF, 0x47E0060F, 0x0048BFFF, - 0x01007FFF + 0x01007FFF, }; // The amount of time Dispose() will wait to Join() the thread executing the ServerLoop() - private static readonly TimeSpan ThreadJoinTimeout = TimeSpan.FromSeconds(3); + private static readonly TimeSpan _threadJoinTimeout = TimeSpan.FromSeconds(3); private readonly KernelContext _context; private KProcess _selfProcess; private KThread _selfThread; - private readonly ReaderWriterLockSlim _handleLock = new ReaderWriterLockSlim(); - private readonly Dictionary _sessions = new Dictionary(); - private readonly Dictionary> _ports = new Dictionary>(); + private readonly ReaderWriterLockSlim _handleLock = new(); + private readonly Dictionary _sessions = new(); + private readonly Dictionary> _ports = new(); private readonly MemoryStream _requestDataStream; private readonly BinaryReader _requestDataReader; @@ -76,9 +75,9 @@ namespace Ryujinx.HLE.HOS.Services ProcessCreationFlags.Is64Bit | ProcessCreationFlags.PoolPartitionSystem; - ProcessCreationInfo creationInfo = new ProcessCreationInfo("Service", 1, 0, 0x8000000, 1, Flags, 0, 0); + ProcessCreationInfo creationInfo = new("Service", 1, 0, 0x8000000, 1, Flags, 0, 0); - KernelStatic.StartInitialProcess(context, creationInfo, DefaultCapabilities, 44, Main); + KernelStatic.StartInitialProcess(context, creationInfo, _defaultCapabilities, 44, Main); } private void AddPort(int serverPortHandle, Func objectFactory) @@ -281,7 +280,7 @@ namespace Ryujinx.HLE.HOS.Services { IpcMessage request = ReadRequest(); - IpcMessage response = new IpcMessage(); + IpcMessage response = new(); ulong tempAddr = recvListAddr; int sizesOffset = request.RawData.Length - ((request.RecvListBuff.Count * 2 + 3) & ~3); @@ -323,7 +322,7 @@ namespace Ryujinx.HLE.HOS.Services _responseDataStream.SetLength(0); - ServiceCtx context = new ServiceCtx( + ServiceCtx context = new( _context.Device, _selfProcess, _selfProcess.CpuMemory, @@ -340,7 +339,9 @@ namespace Ryujinx.HLE.HOS.Services else if (request.Type == IpcMessageType.CmifControl || request.Type == IpcMessageType.CmifControlWithContext) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment uint magic = (uint)_requestDataReader.ReadUInt64(); +#pragma warning restore IDE0059 uint cmdId = (uint)_requestDataReader.ReadUInt64(); switch (cmdId) @@ -382,7 +383,8 @@ namespace Ryujinx.HLE.HOS.Services break; } - default: throw new NotImplementedException(cmdId.ToString()); + default: + throw new NotImplementedException(cmdId.ToString()); } } else if (request.Type == IpcMessageType.CmifCloseSession || request.Type == IpcMessageType.TipcCloseSession) @@ -404,7 +406,7 @@ namespace Ryujinx.HLE.HOS.Services _responseDataStream.SetLength(0); - ServiceCtx context = new ServiceCtx( + ServiceCtx context = new( _context.Device, _selfProcess, _selfProcess.CpuMemory, @@ -437,15 +439,15 @@ namespace Ryujinx.HLE.HOS.Services private IpcMessage ReadRequest() { - const int messageSize = 0x100; + const int MessageSize = 0x100; - using IMemoryOwner reqDataOwner = ByteMemoryPool.Rent(messageSize); + using IMemoryOwner reqDataOwner = ByteMemoryPool.Rent(MessageSize); Span reqDataSpan = reqDataOwner.Memory.Span; _selfProcess.CpuMemory.Read(_selfThread.TlsAddress, reqDataSpan); - IpcMessage request = new IpcMessage(reqDataSpan, (long)_selfThread.TlsAddress); + IpcMessage request = new(reqDataSpan, (long)_selfThread.TlsAddress); return request; } @@ -480,9 +482,9 @@ namespace Ryujinx.HLE.HOS.Services { if (disposing && _selfThread != null) { - if (_selfThread.HostThread.ManagedThreadId != Environment.CurrentManagedThreadId && _selfThread.HostThread.Join(ThreadJoinTimeout) == false) + if (_selfThread.HostThread.ManagedThreadId != Environment.CurrentManagedThreadId && _selfThread.HostThread.Join(_threadJoinTimeout) == false) { - Logger.Warning?.Print(LogClass.Service, $"The ServerBase thread didn't terminate within {ThreadJoinTimeout:g}, waiting longer."); + Logger.Warning?.Print(LogClass.Service, $"The ServerBase thread didn't terminate within {_threadJoinTimeout:g}, waiting longer."); _selfThread.HostThread.Join(Timeout.Infinite); } diff --git a/src/Ryujinx.HLE/HOS/Services/ServiceAttributes.cs b/src/Ryujinx.HLE/HOS/Services/ServiceAttributes.cs index 1b896a277..c625af487 100644 --- a/src/Ryujinx.HLE/HOS/Services/ServiceAttributes.cs +++ b/src/Ryujinx.HLE/HOS/Services/ServiceAttributes.cs @@ -10,8 +10,8 @@ namespace Ryujinx.HLE.HOS.Services public ServiceAttribute(string name, object parameter = null) { - Name = name; + Name = name; Parameter = parameter; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Settings/IFactorySettingsServer.cs b/src/Ryujinx.HLE/HOS/Services/Settings/IFactorySettingsServer.cs index 4dd344f8e..174a1c981 100644 --- a/src/Ryujinx.HLE/HOS/Services/Settings/IFactorySettingsServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Settings/IFactorySettingsServer.cs @@ -5,4 +5,4 @@ { public IFactorySettingsServer(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Settings/IFirmwareDebugSettingsServer.cs b/src/Ryujinx.HLE/HOS/Services/Settings/IFirmwareDebugSettingsServer.cs index 3b7e1af2d..7368cf441 100644 --- a/src/Ryujinx.HLE/HOS/Services/Settings/IFirmwareDebugSettingsServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Settings/IFirmwareDebugSettingsServer.cs @@ -5,4 +5,4 @@ { public IFirmwareDebugSettingsServer(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs b/src/Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs index 17e9ec683..abb9b6d8e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs @@ -123,7 +123,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings public ResultCode GetDeviceNickName(ServiceCtx context) { ulong deviceNickNameBufferPosition = context.Request.ReceiveBuff[0].Position; - ulong deviceNickNameBufferSize = context.Request.ReceiveBuff[0].Size; + ulong deviceNickNameBufferSize = context.Request.ReceiveBuff[0].Size; if (deviceNickNameBufferPosition == 0) { diff --git a/src/Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs b/src/Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs index 07c9f6b3b..65748be33 100644 --- a/src/Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs @@ -30,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings // GetFirmwareVersion2() -> buffer public ResultCode GetFirmwareVersion2(ServiceCtx context) { - ulong replyPos = context.Request.RecvListBuff[0].Position; + ulong replyPos = context.Request.RecvListBuff[0].Position; context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x100L); @@ -46,43 +46,42 @@ namespace Ryujinx.HLE.HOS.Services.Settings const byte MajorFwVersion = 0x03; const byte MinorFwVersion = 0x00; const byte MicroFwVersion = 0x00; - const byte Unknown = 0x00; //Build? + const byte Unknown = 0x00; //Build? const int RevisionNumber = 0x0A; - const string Platform = "NX"; + const string Platform = "NX"; const string UnknownHex = "7fbde2b0bba4d14107bf836e4643043d9f6c8e47"; - const string Version = "3.0.0"; - const string Build = "NintendoSDK Firmware for NX 3.0.0-10.0"; + const string Version = "3.0.0"; + const string Build = "NintendoSDK Firmware for NX 3.0.0-10.0"; // http://switchbrew.org/index.php?title=System_Version_Title - using (MemoryStream ms = new MemoryStream(0x100)) - { - BinaryWriter writer = new BinaryWriter(ms); + using MemoryStream ms = new(0x100); - writer.Write(MajorFwVersion); - writer.Write(MinorFwVersion); - writer.Write(MicroFwVersion); - writer.Write(Unknown); + BinaryWriter writer = new(ms); - writer.Write(RevisionNumber); + writer.Write(MajorFwVersion); + writer.Write(MinorFwVersion); + writer.Write(MicroFwVersion); + writer.Write(Unknown); - writer.Write(Encoding.ASCII.GetBytes(Platform)); + writer.Write(RevisionNumber); - ms.Seek(0x28, SeekOrigin.Begin); + writer.Write(Encoding.ASCII.GetBytes(Platform)); - writer.Write(Encoding.ASCII.GetBytes(UnknownHex)); + ms.Seek(0x28, SeekOrigin.Begin); - ms.Seek(0x68, SeekOrigin.Begin); + writer.Write(Encoding.ASCII.GetBytes(UnknownHex)); - writer.Write(Encoding.ASCII.GetBytes(Version)); + ms.Seek(0x68, SeekOrigin.Begin); - ms.Seek(0x80, SeekOrigin.Begin); + writer.Write(Encoding.ASCII.GetBytes(Version)); - writer.Write(Encoding.ASCII.GetBytes(Build)); + ms.Seek(0x80, SeekOrigin.Begin); - context.Memory.Write(replyPos, ms.ToArray()); - } + writer.Write(Encoding.ASCII.GetBytes(Build)); + + context.Memory.Write(replyPos, ms.ToArray()); return ResultCode.Success; } @@ -111,10 +110,10 @@ namespace Ryujinx.HLE.HOS.Services.Settings // GetSettingsItemValueSize(buffer, buffer) -> u64 public ResultCode GetSettingsItemValueSize(ServiceCtx context) { - ulong classPos = context.Request.PtrBuff[0].Position; + ulong classPos = context.Request.PtrBuff[0].Position; ulong classSize = context.Request.PtrBuff[0].Size; - ulong namePos = context.Request.PtrBuff[1].Position; + ulong namePos = context.Request.PtrBuff[1].Position; ulong nameSize = context.Request.PtrBuff[1].Size; byte[] classBuffer = new byte[classSize]; @@ -160,13 +159,13 @@ namespace Ryujinx.HLE.HOS.Services.Settings // GetSettingsItemValue(buffer, buffer) -> (u64, buffer) public ResultCode GetSettingsItemValue(ServiceCtx context) { - ulong classPos = context.Request.PtrBuff[0].Position; + ulong classPos = context.Request.PtrBuff[0].Position; ulong classSize = context.Request.PtrBuff[0].Size; - ulong namePos = context.Request.PtrBuff[1].Position; + ulong namePos = context.Request.PtrBuff[1].Position; ulong nameSize = context.Request.PtrBuff[1].Size; - ulong replyPos = context.Request.ReceiveBuff[0].Position; + ulong replyPos = context.Request.ReceiveBuff[0].Position; ulong replySize = context.Request.ReceiveBuff[0].Size; byte[] classBuffer = new byte[classSize]; @@ -250,7 +249,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings public ResultCode GetDeviceNickName(ServiceCtx context) { ulong deviceNickNameBufferPosition = context.Request.ReceiveBuff[0].Position; - ulong deviceNickNameBufferSize = context.Request.ReceiveBuff[0].Size; + ulong deviceNickNameBufferSize = context.Request.ReceiveBuff[0].Size; if (deviceNickNameBufferPosition == 0) { @@ -272,7 +271,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings public ResultCode SetDeviceNickName(ServiceCtx context) { ulong deviceNickNameBufferPosition = context.Request.SendBuff[0].Position; - ulong deviceNickNameBufferSize = context.Request.SendBuff[0].Size; + ulong deviceNickNameBufferSize = context.Request.SendBuff[0].Size; byte[] deviceNickNameBuffer = new byte[deviceNickNameBufferSize]; @@ -306,43 +305,41 @@ namespace Ryujinx.HLE.HOS.Services.Settings return null; } - string firmwareTitlePath = device.FileSystem.SwitchPathToSystemPath(contentPath); + string firmwareTitlePath = FileSystem.VirtualFileSystem.SwitchPathToSystemPath(contentPath); - using(IStorage firmwareStorage = new LocalStorage(firmwareTitlePath, FileAccess.Read)) + using IStorage firmwareStorage = new LocalStorage(firmwareTitlePath, FileAccess.Read); + Nca firmwareContent = new(device.System.KeySet, firmwareStorage); + + if (!firmwareContent.CanOpenSection(NcaSectionType.Data)) { - Nca firmwareContent = new Nca(device.System.KeySet, firmwareStorage); - - if (!firmwareContent.CanOpenSection(NcaSectionType.Data)) - { - return null; - } - - IFileSystem firmwareRomFs = firmwareContent.OpenFileSystem(NcaSectionType.Data, device.System.FsIntegrityCheckLevel); - - using var firmwareFile = new UniqueRef(); - - Result result = firmwareRomFs.OpenFile(ref firmwareFile.Ref, "/file".ToU8Span(), OpenMode.Read); - if (result.IsFailure()) - { - return null; - } - - result = firmwareFile.Get.GetSize(out long fileSize); - if (result.IsFailure()) - { - return null; - } - - byte[] data = new byte[fileSize]; - - result = firmwareFile.Get.Read(out _, 0, data); - if (result.IsFailure()) - { - return null; - } - - return data; + return null; } + + IFileSystem firmwareRomFs = firmwareContent.OpenFileSystem(NcaSectionType.Data, device.System.FsIntegrityCheckLevel); + + using var firmwareFile = new UniqueRef(); + + Result result = firmwareRomFs.OpenFile(ref firmwareFile.Ref, "/file".ToU8Span(), OpenMode.Read); + if (result.IsFailure()) + { + return null; + } + + result = firmwareFile.Get.GetSize(out long fileSize); + if (result.IsFailure()) + { + return null; + } + + byte[] data = new byte[fileSize]; + + result = firmwareFile.Get.Read(out _, 0, data); + if (result.IsFailure()) + { + return null; + } + + return data; } } } diff --git a/src/Ryujinx.HLE/HOS/Services/Settings/KeyCodeMaps.cs b/src/Ryujinx.HLE/HOS/Services/Settings/KeyCodeMaps.cs index 67d1ac929..981fc18ea 100644 --- a/src/Ryujinx.HLE/HOS/Services/Settings/KeyCodeMaps.cs +++ b/src/Ryujinx.HLE/HOS/Services/Settings/KeyCodeMaps.cs @@ -1,6 +1,6 @@ namespace Ryujinx.HLE.HOS.Services.Settings { - class KeyCodeMaps + static class KeyCodeMaps { public static byte[] Default = { @@ -345,7 +345,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] EnglishUsInternational = @@ -691,7 +691,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] EnglishUk = @@ -1037,7 +1037,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] French = @@ -1383,7 +1383,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] FrenchCa = @@ -1729,7 +1729,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] Spanish = @@ -2075,7 +2075,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] SpanishLatin = @@ -2421,7 +2421,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] German = @@ -2767,7 +2767,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] Italian = @@ -3113,7 +3113,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] Portuguese = @@ -3459,7 +3459,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] Russian = @@ -3805,7 +3805,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] Korean = @@ -4151,7 +4151,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] ChineseSimplified = @@ -4497,7 +4497,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; public static byte[] ChineseTraditional = @@ -4843,7 +4843,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, }; }; } diff --git a/src/Ryujinx.HLE/HOS/Services/Settings/NxSettings.cs b/src/Ryujinx.HLE/HOS/Services/Settings/NxSettings.cs index e5f218a64..b2d4d55cc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Settings/NxSettings.cs +++ b/src/Ryujinx.HLE/HOS/Services/Settings/NxSettings.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings static class NxSettings { // Generated automatically from a Switch 3.0 config file (Tid: 0100000000000818). - public static Dictionary Settings = new Dictionary + public static Dictionary Settings = new() { { "account!na_required_for_network_service", true }, { "account.daemon!background_awaking_periodicity", 10800 }, @@ -1706,7 +1706,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings { "time!standard_network_clock_sufficient_accuracy_minutes", 43200 }, { "time!standard_user_clock_initial_year", 2019 }, { "usb!usb30_force_enabled", false }, - { "wlan_debug!skip_wlan_boot", false } + { "wlan_debug!skip_wlan_boot", false }, }; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Settings/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Settings/ResultCode.cs index 8b0fde6c7..9d4678091 100644 --- a/src/Ryujinx.HLE/HOS/Services/Settings/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Settings/ResultCode.cs @@ -2,125 +2,125 @@ { enum ResultCode { - ModuleId = 105, + ModuleId = 105, ErrorCodeShift = 9, Success = 0, - NullSettingsName = (201 << ErrorCodeShift) | ModuleId, - NullSettingsKey = (202 << ErrorCodeShift) | ModuleId, - NullSettingsValue = (203 << ErrorCodeShift) | ModuleId, - NullSettingsValueBuffer = (205 << ErrorCodeShift) | ModuleId, - NullSettingValueSizeBuffer = (208 << ErrorCodeShift) | ModuleId, - NullDebugModeFlagBuffer = (209 << ErrorCodeShift) | ModuleId, - SettingGroupNameHasZeroLength = (221 << ErrorCodeShift) | ModuleId, - EmptySettingsItemKey = (222 << ErrorCodeShift) | ModuleId, - SettingGroupNameIsTooLong = (241 << ErrorCodeShift) | ModuleId, - SettingNameIsTooLong = (242 << ErrorCodeShift) | ModuleId, - SettingGroupNameEndsWithDotOrContainsInvalidCharacters = (261 << ErrorCodeShift) | ModuleId, - SettingNameEndsWithDotOrContainsInvalidCharacters = (262 << ErrorCodeShift) | ModuleId, - NullLanguageCodeBuffer = (621 << ErrorCodeShift) | ModuleId, - LanguageOutOfRange = (625 << ErrorCodeShift) | ModuleId, - NullNetworkSettingsBuffer = (631 << ErrorCodeShift) | ModuleId, - NullNetworkSettingsOutputCountBuffer = (632 << ErrorCodeShift) | ModuleId, - NullBacklightSettingsBuffer = (641 << ErrorCodeShift) | ModuleId, - NullBluetoothDeviceSettingBuffer = (651 << ErrorCodeShift) | ModuleId, - NullBluetoothDeviceSettingOutputCountBuffer = (652 << ErrorCodeShift) | ModuleId, - NullBluetoothEnableFlagBuffer = (653 << ErrorCodeShift) | ModuleId, - NullBluetoothAFHEnableFlagBuffer = (654 << ErrorCodeShift) | ModuleId, - NullBluetoothBoostEnableFlagBuffer = (655 << ErrorCodeShift) | ModuleId, - NullBLEPairingSettingsBuffer = (656 << ErrorCodeShift) | ModuleId, - NullBLEPairingSettingsEntryCountBuffer = (657 << ErrorCodeShift) | ModuleId, - NullExternalSteadyClockSourceIDBuffer = (661 << ErrorCodeShift) | ModuleId, - NullUserSystemClockContextBuffer = (662 << ErrorCodeShift) | ModuleId, - NullNetworkSystemClockContextBuffer = (663 << ErrorCodeShift) | ModuleId, - NullUserSystemClockAutomaticCorrectionEnabledFlagBuffer = (664 << ErrorCodeShift) | ModuleId, - NullShutdownRTCValueBuffer = (665 << ErrorCodeShift) | ModuleId, - NullExternalSteadyClockInternalOffsetBuffer = (666 << ErrorCodeShift) | ModuleId, - NullAccountSettingsBuffer = (671 << ErrorCodeShift) | ModuleId, - NullAudioVolumeBuffer = (681 << ErrorCodeShift) | ModuleId, - NullForceMuteOnHeadphoneRemovedBuffer = (683 << ErrorCodeShift) | ModuleId, - NullHeadphoneVolumeWarningCountBuffer = (684 << ErrorCodeShift) | ModuleId, - InvalidAudioOutputMode = (687 << ErrorCodeShift) | ModuleId, - NullHeadphoneVolumeUpdateFlagBuffer = (688 << ErrorCodeShift) | ModuleId, - NullConsoleInformationUploadFlagBuffer = (691 << ErrorCodeShift) | ModuleId, - NullAutomaticApplicationDownloadFlagBuffer = (701 << ErrorCodeShift) | ModuleId, - NullNotificationSettingsBuffer = (702 << ErrorCodeShift) | ModuleId, - NullAccountNotificationSettingsEntryCountBuffer = (703 << ErrorCodeShift) | ModuleId, - NullAccountNotificationSettingsBuffer = (704 << ErrorCodeShift) | ModuleId, - NullVibrationMasterVolumeBuffer = (711 << ErrorCodeShift) | ModuleId, - NullNXControllerSettingsBuffer = (712 << ErrorCodeShift) | ModuleId, - NullNXControllerSettingsEntryCountBuffer = (713 << ErrorCodeShift) | ModuleId, - NullUSBFullKeyEnableFlagBuffer = (714 << ErrorCodeShift) | ModuleId, - NullTVSettingsBuffer = (721 << ErrorCodeShift) | ModuleId, - NullEDIDBuffer = (722 << ErrorCodeShift) | ModuleId, - NullDataDeletionSettingsBuffer = (731 << ErrorCodeShift) | ModuleId, - NullInitialSystemAppletProgramIDBuffer = (741 << ErrorCodeShift) | ModuleId, - NullOverlayDispProgramIDBuffer = (742 << ErrorCodeShift) | ModuleId, - NullIsInRepairProcessBuffer = (743 << ErrorCodeShift) | ModuleId, - NullRequiresRunRepairTimeReviserBuffer = (744 << ErrorCodeShift) | ModuleId, - NullDeviceTimezoneLocationNameBuffer = (751 << ErrorCodeShift) | ModuleId, - NullPrimaryAlbumStorageBuffer = (761 << ErrorCodeShift) | ModuleId, - NullUSB30EnableFlagBuffer = (771 << ErrorCodeShift) | ModuleId, - NullUSBTypeCPowerSourceCircuitVersionBuffer = (772 << ErrorCodeShift) | ModuleId, - NullBatteryLotBuffer = (781 << ErrorCodeShift) | ModuleId, - NullSerialNumberBuffer = (791 << ErrorCodeShift) | ModuleId, - NullLockScreenFlagBuffer = (801 << ErrorCodeShift) | ModuleId, - NullColorSetIDBuffer = (803 << ErrorCodeShift) | ModuleId, - NullQuestFlagBuffer = (804 << ErrorCodeShift) | ModuleId, - NullWirelessCertificationFileSizeBuffer = (805 << ErrorCodeShift) | ModuleId, - NullWirelessCertificationFileBuffer = (806 << ErrorCodeShift) | ModuleId, - NullInitialLaunchSettingsBuffer = (807 << ErrorCodeShift) | ModuleId, - NullDeviceNicknameBuffer = (808 << ErrorCodeShift) | ModuleId, - NullBatteryPercentageFlagBuffer = (809 << ErrorCodeShift) | ModuleId, - NullAppletLaunchFlagsBuffer = (810 << ErrorCodeShift) | ModuleId, - NullWirelessLANEnableFlagBuffer = (1012 << ErrorCodeShift) | ModuleId, - NullProductModelBuffer = (1021 << ErrorCodeShift) | ModuleId, - NullNFCEnableFlagBuffer = (1031 << ErrorCodeShift) | ModuleId, - NullECIDeviceCertificateBuffer = (1041 << ErrorCodeShift) | ModuleId, - NullETicketDeviceCertificateBuffer = (1042 << ErrorCodeShift) | ModuleId, - NullSleepSettingsBuffer = (1051 << ErrorCodeShift) | ModuleId, - NullEULAVersionBuffer = (1061 << ErrorCodeShift) | ModuleId, - NullEULAVersionEntryCountBuffer = (1062 << ErrorCodeShift) | ModuleId, - NullLDNChannelBuffer = (1071 << ErrorCodeShift) | ModuleId, - NullSSLKeyBuffer = (1081 << ErrorCodeShift) | ModuleId, - NullSSLCertificateBuffer = (1082 << ErrorCodeShift) | ModuleId, - NullTelemetryFlagsBuffer = (1091 << ErrorCodeShift) | ModuleId, - NullGamecardKeyBuffer = (1101 << ErrorCodeShift) | ModuleId, - NullGamecardCertificateBuffer = (1102 << ErrorCodeShift) | ModuleId, - NullPTMBatteryLotBuffer = (1111 << ErrorCodeShift) | ModuleId, - NullPTMFuelGaugeParameterBuffer = (1112 << ErrorCodeShift) | ModuleId, - NullECIDeviceKeyBuffer = (1121 << ErrorCodeShift) | ModuleId, - NullETicketDeviceKeyBuffer = (1122 << ErrorCodeShift) | ModuleId, - NullSpeakerParameterBuffer = (1131 << ErrorCodeShift) | ModuleId, - NullFirmwareVersionBuffer = (1141 << ErrorCodeShift) | ModuleId, - NullFirmwareVersionDigestBuffer = (1142 << ErrorCodeShift) | ModuleId, - NullRebootlessSystemUpdateVersionBuffer = (1143 << ErrorCodeShift) | ModuleId, - NullMiiAuthorIDBuffer = (1151 << ErrorCodeShift) | ModuleId, - NullFatalFlagsBuffer = (1161 << ErrorCodeShift) | ModuleId, - NullAutoUpdateEnableFlagBuffer = (1171 << ErrorCodeShift) | ModuleId, - NullExternalRTCResetFlagBuffer = (1181 << ErrorCodeShift) | ModuleId, - NullPushNotificationActivityModeBuffer = (1191 << ErrorCodeShift) | ModuleId, - NullServiceDiscoveryControlSettingBuffer = (1201 << ErrorCodeShift) | ModuleId, - NullErrorReportSharePermissionBuffer = (1211 << ErrorCodeShift) | ModuleId, - NullLCDVendorIDBuffer = (1221 << ErrorCodeShift) | ModuleId, - NullConsoleSixAxisSensorAccelerationBiasBuffer = (1231 << ErrorCodeShift) | ModuleId, - NullConsoleSixAxisSensorAngularVelocityBiasBuffer = (1232 << ErrorCodeShift) | ModuleId, - NullConsoleSixAxisSensorAccelerationGainBuffer = (1233 << ErrorCodeShift) | ModuleId, - NullConsoleSixAxisSensorAngularVelocityGainBuffer = (1234 << ErrorCodeShift) | ModuleId, - NullConsoleSixAxisSensorAngularVelocityTimeBiasBuffer = (1235 << ErrorCodeShift) | ModuleId, - NullConsoleSixAxisSensorAngularAccelerationBuffer = (1236 << ErrorCodeShift) | ModuleId, - NullKeyboardLayoutBuffer = (1241 << ErrorCodeShift) | ModuleId, - InvalidKeyboardLayout = (1245 << ErrorCodeShift) | ModuleId, - NullWebInspectorFlagBuffer = (1251 << ErrorCodeShift) | ModuleId, - NullAllowedSSLHostsBuffer = (1252 << ErrorCodeShift) | ModuleId, - NullAllowedSSLHostsEntryCountBuffer = (1253 << ErrorCodeShift) | ModuleId, - NullHostFSMountPointBuffer = (1254 << ErrorCodeShift) | ModuleId, - NullAmiiboKeyBuffer = (1271 << ErrorCodeShift) | ModuleId, - NullAmiiboECQVCertificateBuffer = (1272 << ErrorCodeShift) | ModuleId, - NullAmiiboECDSACertificateBuffer = (1273 << ErrorCodeShift) | ModuleId, - NullAmiiboECQVBLSKeyBuffer = (1274 << ErrorCodeShift) | ModuleId, - NullAmiiboECQVBLSCertificateBuffer = (1275 << ErrorCodeShift) | ModuleId, - NullAmiiboECQVBLSRootCertificateBuffer = (1276 << ErrorCodeShift) | ModuleId + NullSettingsName = (201 << ErrorCodeShift) | ModuleId, + NullSettingsKey = (202 << ErrorCodeShift) | ModuleId, + NullSettingsValue = (203 << ErrorCodeShift) | ModuleId, + NullSettingsValueBuffer = (205 << ErrorCodeShift) | ModuleId, + NullSettingValueSizeBuffer = (208 << ErrorCodeShift) | ModuleId, + NullDebugModeFlagBuffer = (209 << ErrorCodeShift) | ModuleId, + SettingGroupNameHasZeroLength = (221 << ErrorCodeShift) | ModuleId, + EmptySettingsItemKey = (222 << ErrorCodeShift) | ModuleId, + SettingGroupNameIsTooLong = (241 << ErrorCodeShift) | ModuleId, + SettingNameIsTooLong = (242 << ErrorCodeShift) | ModuleId, + SettingGroupNameEndsWithDotOrContainsInvalidCharacters = (261 << ErrorCodeShift) | ModuleId, + SettingNameEndsWithDotOrContainsInvalidCharacters = (262 << ErrorCodeShift) | ModuleId, + NullLanguageCodeBuffer = (621 << ErrorCodeShift) | ModuleId, + LanguageOutOfRange = (625 << ErrorCodeShift) | ModuleId, + NullNetworkSettingsBuffer = (631 << ErrorCodeShift) | ModuleId, + NullNetworkSettingsOutputCountBuffer = (632 << ErrorCodeShift) | ModuleId, + NullBacklightSettingsBuffer = (641 << ErrorCodeShift) | ModuleId, + NullBluetoothDeviceSettingBuffer = (651 << ErrorCodeShift) | ModuleId, + NullBluetoothDeviceSettingOutputCountBuffer = (652 << ErrorCodeShift) | ModuleId, + NullBluetoothEnableFlagBuffer = (653 << ErrorCodeShift) | ModuleId, + NullBluetoothAFHEnableFlagBuffer = (654 << ErrorCodeShift) | ModuleId, + NullBluetoothBoostEnableFlagBuffer = (655 << ErrorCodeShift) | ModuleId, + NullBLEPairingSettingsBuffer = (656 << ErrorCodeShift) | ModuleId, + NullBLEPairingSettingsEntryCountBuffer = (657 << ErrorCodeShift) | ModuleId, + NullExternalSteadyClockSourceIDBuffer = (661 << ErrorCodeShift) | ModuleId, + NullUserSystemClockContextBuffer = (662 << ErrorCodeShift) | ModuleId, + NullNetworkSystemClockContextBuffer = (663 << ErrorCodeShift) | ModuleId, + NullUserSystemClockAutomaticCorrectionEnabledFlagBuffer = (664 << ErrorCodeShift) | ModuleId, + NullShutdownRTCValueBuffer = (665 << ErrorCodeShift) | ModuleId, + NullExternalSteadyClockInternalOffsetBuffer = (666 << ErrorCodeShift) | ModuleId, + NullAccountSettingsBuffer = (671 << ErrorCodeShift) | ModuleId, + NullAudioVolumeBuffer = (681 << ErrorCodeShift) | ModuleId, + NullForceMuteOnHeadphoneRemovedBuffer = (683 << ErrorCodeShift) | ModuleId, + NullHeadphoneVolumeWarningCountBuffer = (684 << ErrorCodeShift) | ModuleId, + InvalidAudioOutputMode = (687 << ErrorCodeShift) | ModuleId, + NullHeadphoneVolumeUpdateFlagBuffer = (688 << ErrorCodeShift) | ModuleId, + NullConsoleInformationUploadFlagBuffer = (691 << ErrorCodeShift) | ModuleId, + NullAutomaticApplicationDownloadFlagBuffer = (701 << ErrorCodeShift) | ModuleId, + NullNotificationSettingsBuffer = (702 << ErrorCodeShift) | ModuleId, + NullAccountNotificationSettingsEntryCountBuffer = (703 << ErrorCodeShift) | ModuleId, + NullAccountNotificationSettingsBuffer = (704 << ErrorCodeShift) | ModuleId, + NullVibrationMasterVolumeBuffer = (711 << ErrorCodeShift) | ModuleId, + NullNXControllerSettingsBuffer = (712 << ErrorCodeShift) | ModuleId, + NullNXControllerSettingsEntryCountBuffer = (713 << ErrorCodeShift) | ModuleId, + NullUSBFullKeyEnableFlagBuffer = (714 << ErrorCodeShift) | ModuleId, + NullTVSettingsBuffer = (721 << ErrorCodeShift) | ModuleId, + NullEDIDBuffer = (722 << ErrorCodeShift) | ModuleId, + NullDataDeletionSettingsBuffer = (731 << ErrorCodeShift) | ModuleId, + NullInitialSystemAppletProgramIDBuffer = (741 << ErrorCodeShift) | ModuleId, + NullOverlayDispProgramIDBuffer = (742 << ErrorCodeShift) | ModuleId, + NullIsInRepairProcessBuffer = (743 << ErrorCodeShift) | ModuleId, + NullRequiresRunRepairTimeReviserBuffer = (744 << ErrorCodeShift) | ModuleId, + NullDeviceTimezoneLocationNameBuffer = (751 << ErrorCodeShift) | ModuleId, + NullPrimaryAlbumStorageBuffer = (761 << ErrorCodeShift) | ModuleId, + NullUSB30EnableFlagBuffer = (771 << ErrorCodeShift) | ModuleId, + NullUSBTypeCPowerSourceCircuitVersionBuffer = (772 << ErrorCodeShift) | ModuleId, + NullBatteryLotBuffer = (781 << ErrorCodeShift) | ModuleId, + NullSerialNumberBuffer = (791 << ErrorCodeShift) | ModuleId, + NullLockScreenFlagBuffer = (801 << ErrorCodeShift) | ModuleId, + NullColorSetIDBuffer = (803 << ErrorCodeShift) | ModuleId, + NullQuestFlagBuffer = (804 << ErrorCodeShift) | ModuleId, + NullWirelessCertificationFileSizeBuffer = (805 << ErrorCodeShift) | ModuleId, + NullWirelessCertificationFileBuffer = (806 << ErrorCodeShift) | ModuleId, + NullInitialLaunchSettingsBuffer = (807 << ErrorCodeShift) | ModuleId, + NullDeviceNicknameBuffer = (808 << ErrorCodeShift) | ModuleId, + NullBatteryPercentageFlagBuffer = (809 << ErrorCodeShift) | ModuleId, + NullAppletLaunchFlagsBuffer = (810 << ErrorCodeShift) | ModuleId, + NullWirelessLANEnableFlagBuffer = (1012 << ErrorCodeShift) | ModuleId, + NullProductModelBuffer = (1021 << ErrorCodeShift) | ModuleId, + NullNFCEnableFlagBuffer = (1031 << ErrorCodeShift) | ModuleId, + NullECIDeviceCertificateBuffer = (1041 << ErrorCodeShift) | ModuleId, + NullETicketDeviceCertificateBuffer = (1042 << ErrorCodeShift) | ModuleId, + NullSleepSettingsBuffer = (1051 << ErrorCodeShift) | ModuleId, + NullEULAVersionBuffer = (1061 << ErrorCodeShift) | ModuleId, + NullEULAVersionEntryCountBuffer = (1062 << ErrorCodeShift) | ModuleId, + NullLDNChannelBuffer = (1071 << ErrorCodeShift) | ModuleId, + NullSSLKeyBuffer = (1081 << ErrorCodeShift) | ModuleId, + NullSSLCertificateBuffer = (1082 << ErrorCodeShift) | ModuleId, + NullTelemetryFlagsBuffer = (1091 << ErrorCodeShift) | ModuleId, + NullGamecardKeyBuffer = (1101 << ErrorCodeShift) | ModuleId, + NullGamecardCertificateBuffer = (1102 << ErrorCodeShift) | ModuleId, + NullPTMBatteryLotBuffer = (1111 << ErrorCodeShift) | ModuleId, + NullPTMFuelGaugeParameterBuffer = (1112 << ErrorCodeShift) | ModuleId, + NullECIDeviceKeyBuffer = (1121 << ErrorCodeShift) | ModuleId, + NullETicketDeviceKeyBuffer = (1122 << ErrorCodeShift) | ModuleId, + NullSpeakerParameterBuffer = (1131 << ErrorCodeShift) | ModuleId, + NullFirmwareVersionBuffer = (1141 << ErrorCodeShift) | ModuleId, + NullFirmwareVersionDigestBuffer = (1142 << ErrorCodeShift) | ModuleId, + NullRebootlessSystemUpdateVersionBuffer = (1143 << ErrorCodeShift) | ModuleId, + NullMiiAuthorIDBuffer = (1151 << ErrorCodeShift) | ModuleId, + NullFatalFlagsBuffer = (1161 << ErrorCodeShift) | ModuleId, + NullAutoUpdateEnableFlagBuffer = (1171 << ErrorCodeShift) | ModuleId, + NullExternalRTCResetFlagBuffer = (1181 << ErrorCodeShift) | ModuleId, + NullPushNotificationActivityModeBuffer = (1191 << ErrorCodeShift) | ModuleId, + NullServiceDiscoveryControlSettingBuffer = (1201 << ErrorCodeShift) | ModuleId, + NullErrorReportSharePermissionBuffer = (1211 << ErrorCodeShift) | ModuleId, + NullLCDVendorIDBuffer = (1221 << ErrorCodeShift) | ModuleId, + NullConsoleSixAxisSensorAccelerationBiasBuffer = (1231 << ErrorCodeShift) | ModuleId, + NullConsoleSixAxisSensorAngularVelocityBiasBuffer = (1232 << ErrorCodeShift) | ModuleId, + NullConsoleSixAxisSensorAccelerationGainBuffer = (1233 << ErrorCodeShift) | ModuleId, + NullConsoleSixAxisSensorAngularVelocityGainBuffer = (1234 << ErrorCodeShift) | ModuleId, + NullConsoleSixAxisSensorAngularVelocityTimeBiasBuffer = (1235 << ErrorCodeShift) | ModuleId, + NullConsoleSixAxisSensorAngularAccelerationBuffer = (1236 << ErrorCodeShift) | ModuleId, + NullKeyboardLayoutBuffer = (1241 << ErrorCodeShift) | ModuleId, + InvalidKeyboardLayout = (1245 << ErrorCodeShift) | ModuleId, + NullWebInspectorFlagBuffer = (1251 << ErrorCodeShift) | ModuleId, + NullAllowedSSLHostsBuffer = (1252 << ErrorCodeShift) | ModuleId, + NullAllowedSSLHostsEntryCountBuffer = (1253 << ErrorCodeShift) | ModuleId, + NullHostFSMountPointBuffer = (1254 << ErrorCodeShift) | ModuleId, + NullAmiiboKeyBuffer = (1271 << ErrorCodeShift) | ModuleId, + NullAmiiboECQVCertificateBuffer = (1272 << ErrorCodeShift) | ModuleId, + NullAmiiboECDSACertificateBuffer = (1273 << ErrorCodeShift) | ModuleId, + NullAmiiboECQVBLSKeyBuffer = (1274 << ErrorCodeShift) | ModuleId, + NullAmiiboECQVBLSCertificateBuffer = (1275 << ErrorCodeShift) | ModuleId, + NullAmiiboECQVBLSRootCertificateBuffer = (1276 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Settings/Types/PlatformRegion.cs b/src/Ryujinx.HLE/HOS/Services/Settings/Types/PlatformRegion.cs index b8ef8e8ea..3953c050c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Settings/Types/PlatformRegion.cs +++ b/src/Ryujinx.HLE/HOS/Services/Settings/Types/PlatformRegion.cs @@ -3,6 +3,6 @@ enum PlatformRegion { Global = 1, - China = 2 + China = 2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sm/IManagerInterface.cs b/src/Ryujinx.HLE/HOS/Services/Sm/IManagerInterface.cs index f867f23a4..412a33246 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sm/IManagerInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sm/IManagerInterface.cs @@ -5,4 +5,4 @@ { public IManagerInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs b/src/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs index 005ec32d8..2d8502208 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs @@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Sm { class IUserInterface : IpcService { - private static Dictionary _services; + private static readonly Dictionary _services; private readonly SmRegistry _registry; private readonly ServerBase _commonServer; @@ -68,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Services.Sm return ResultCode.InvalidName; } - KSession session = new KSession(context.Device.System.KernelContext); + KSession session = new(context.Device.System.KernelContext); if (_registry.TryGetService(name, out KPort port)) { @@ -182,7 +182,7 @@ namespace Ryujinx.HLE.HOS.Services.Sm Logger.Debug?.Print(LogClass.ServiceSm, $"Register \"{name}\"."); - KPort port = new KPort(context.Device.System.KernelContext, maxSessions, isLight, null); + KPort port = new(context.Device.System.KernelContext, maxSessions, isLight, null); if (!_registry.TryRegister(name, port)) { @@ -215,9 +215,10 @@ namespace Ryujinx.HLE.HOS.Services.Sm context.RequestData.BaseStream.Seek(namePosition + 8, SeekOrigin.Begin); +#pragma warning disable IDE0059 // Remove unnecessary value assignment bool isLight = (context.RequestData.ReadInt32() & 1) != 0; - int maxSessions = context.RequestData.ReadInt32(); +#pragma warning restore IDE0059 if (string.IsNullOrEmpty(name)) { @@ -258,4 +259,4 @@ namespace Ryujinx.HLE.HOS.Services.Sm base.DestroyAtExit(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sm/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Sm/ResultCode.cs index f72bf0109..6db33d2aa 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sm/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sm/ResultCode.cs @@ -2,14 +2,14 @@ namespace Ryujinx.HLE.HOS.Services.Sm { enum ResultCode { - ModuleId = 21, + ModuleId = 21, ErrorCodeShift = 9, Success = 0, - NotInitialized = (2 << ErrorCodeShift) | ModuleId, + NotInitialized = (2 << ErrorCodeShift) | ModuleId, AlreadyRegistered = (4 << ErrorCodeShift) | ModuleId, - InvalidName = (6 << ErrorCodeShift) | ModuleId, - NotRegistered = (7 << ErrorCodeShift) | ModuleId + InvalidName = (6 << ErrorCodeShift) | ModuleId, + NotRegistered = (7 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sm/SmRegistry.cs b/src/Ryujinx.HLE/HOS/Services/Sm/SmRegistry.cs index e62e0eb53..3919eaae9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sm/SmRegistry.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sm/SmRegistry.cs @@ -46,4 +46,4 @@ namespace Ryujinx.HLE.HOS.Services.Sm _serviceRegistrationEvent.WaitOne(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs index b0ac6e680..254ad6675 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs @@ -8,11 +8,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd { class BsdContext { - private static ConcurrentDictionary _registry = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary _registry = new(); private readonly object _lock = new(); - private List _fds; + private readonly List _fds; private BsdContext() { @@ -181,4 +181,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd return processContext; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs index b63864c90..d16e7536e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs @@ -7,7 +7,6 @@ using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; -using System.Numerics; using System.Runtime.CompilerServices; using System.Text; @@ -17,14 +16,14 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd [Service("bsd:u", false)] class IClient : IpcService { - private static readonly List _pollManagers = new List + private static readonly List _pollManagers = new() { EventFileDescriptorPollManager.Instance, - ManagedSocketPollManager.Instance + ManagedSocketPollManager.Instance, }; private BsdContext _context; - private bool _isPrivileged; + private readonly bool _isPrivileged; public IClient(ServiceCtx context, bool isPrivileged) : base(context.Device.System.BsdServer) { @@ -46,19 +45,14 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd private static AddressFamily ConvertBsdAddressFamily(BsdAddressFamily family) { - switch (family) + return family switch { - case BsdAddressFamily.Unspecified: - return AddressFamily.Unspecified; - case BsdAddressFamily.InterNetwork: - return AddressFamily.InterNetwork; - case BsdAddressFamily.InterNetworkV6: - return AddressFamily.InterNetworkV6; - case BsdAddressFamily.Unknown: - return AddressFamily.Unknown; - default: - throw new NotImplementedException(family.ToString()); - } + BsdAddressFamily.Unspecified => AddressFamily.Unspecified, + BsdAddressFamily.InterNetwork => AddressFamily.InterNetwork, + BsdAddressFamily.InterNetworkV6 => AddressFamily.InterNetworkV6, + BsdAddressFamily.Unknown => AddressFamily.Unknown, + _ => throw new NotImplementedException(family.ToString()), + }; } private LinuxError SetResultErrno(IFileDescriptor socket, int result) @@ -68,9 +62,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd private ResultCode SocketInternal(ServiceCtx context, bool exempt) { - BsdAddressFamily domain = (BsdAddressFamily)context.RequestData.ReadInt32(); - BsdSocketType type = (BsdSocketType)context.RequestData.ReadInt32(); - ProtocolType protocol = (ProtocolType)context.RequestData.ReadInt32(); + BsdAddressFamily domain = (BsdAddressFamily)context.RequestData.ReadInt32(); + BsdSocketType type = (BsdSocketType)context.RequestData.ReadInt32(); + ProtocolType protocol = (ProtocolType)context.RequestData.ReadInt32(); BsdSocketCreationFlags creationFlags = (BsdSocketCreationFlags)((int)type >> (int)BsdSocketCreationFlags.FlagsShift); type &= BsdSocketType.TypeMask; @@ -101,8 +95,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd } } - ISocket newBsdSocket = new ManagedSocket(netDomain, (SocketType)type, protocol); - newBsdSocket.Blocking = !creationFlags.HasFlag(BsdSocketCreationFlags.NonBlocking); + ISocket newBsdSocket = new ManagedSocket(netDomain, (SocketType)type, protocol) + { + Blocking = !creationFlags.HasFlag(BsdSocketCreationFlags.NonBlocking), + }; LinuxError errno = LinuxError.SUCCESS; @@ -210,7 +206,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd public ResultCode Select(ServiceCtx context) { int fdsCount = context.RequestData.ReadInt32(); - int timeout = context.RequestData.ReadInt32(); + int timeout = context.RequestData.ReadInt32(); (ulong readFdsInBufferPosition, ulong readFdsInBufferSize) = context.Request.GetBufferType0x21(0); (ulong writeFdsInBufferPosition, ulong writeFdsInBufferSize) = context.Request.GetBufferType0x21(1); @@ -220,7 +216,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd (ulong writeFdsOutBufferPosition, ulong writeFdsOutBufferSize) = context.Request.GetBufferType0x22(1); (ulong errorFdsOutBufferPosition, ulong errorFdsOutBufferSize) = context.Request.GetBufferType0x22(2); - List readFds = _context.RetrieveFileDescriptorsFromMask(context.Memory.GetSpan(readFdsInBufferPosition, (int)readFdsInBufferSize)); + List readFds = _context.RetrieveFileDescriptorsFromMask(context.Memory.GetSpan(readFdsInBufferPosition, (int)readFdsInBufferSize)); List writeFds = _context.RetrieveFileDescriptorsFromMask(context.Memory.GetSpan(writeFdsInBufferPosition, (int)writeFdsInBufferSize)); List errorFds = _context.RetrieveFileDescriptorsFromMask(context.Memory.GetSpan(errorFdsInBufferPosition, (int)errorFdsInBufferSize)); @@ -312,7 +308,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd } } - using var readFdsOut = context.Memory.GetWritableRegion(readFdsOutBufferPosition, (int)readFdsOutBufferSize); + using var readFdsOut = context.Memory.GetWritableRegion(readFdsOutBufferPosition, (int)readFdsOutBufferSize); using var writeFdsOut = context.Memory.GetWritableRegion(writeFdsOutBufferPosition, (int)writeFdsOutBufferSize); using var errorFdsOut = context.Memory.GetWritableRegion(errorFdsOutBufferPosition, (int)errorFdsOutBufferSize); @@ -330,10 +326,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd public ResultCode Poll(ServiceCtx context) { int fdsCount = context.RequestData.ReadInt32(); - int timeout = context.RequestData.ReadInt32(); + int timeout = context.RequestData.ReadInt32(); (ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22(); +#pragma warning restore IDE0059 if (timeout < -1 || fdsCount < 0 || (ulong)(fdsCount * 8) > inputBufferSize) { @@ -356,7 +354,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd events[i] = new PollEvent(pollEventData, fileDescriptor); } - List discoveredEvents = new List(); + List discoveredEvents = new(); List[] eventsByPollManager = new List[_pollManagers.Count]; for (int i = 0; i < eventsByPollManager.Length; i++) @@ -389,7 +387,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd if (fdsCount != 0) { - bool IsUnexpectedLinuxError(LinuxError error) + static bool IsUnexpectedLinuxError(LinuxError error) { return error != LinuxError.SUCCESS && error != LinuxError.ETIMEDOUT; } @@ -478,16 +476,16 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // Recv(u32 socket, u32 flags) -> (i32 ret, u32 bsd_errno, array message) public ResultCode Recv(ServiceCtx context) { - int socketFd = context.RequestData.ReadInt32(); + int socketFd = context.RequestData.ReadInt32(); BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32(); (ulong receivePosition, ulong receiveLength) = context.Request.GetBufferType0x22(); WritableRegion receiveRegion = context.Memory.GetWritableRegion(receivePosition, (int)receiveLength); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); - int result = -1; + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); + int result = -1; if (socket != null) { @@ -508,17 +506,17 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // RecvFrom(u32 sock, u32 flags) -> (i32 ret, u32 bsd_errno, u32 addrlen, buffer message, buffer) public ResultCode RecvFrom(ServiceCtx context) { - int socketFd = context.RequestData.ReadInt32(); + int socketFd = context.RequestData.ReadInt32(); BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32(); - (ulong receivePosition, ulong receiveLength) = context.Request.GetBufferType0x22(0); + (ulong receivePosition, ulong receiveLength) = context.Request.GetBufferType0x22(0); (ulong sockAddrOutPosition, ulong sockAddrOutSize) = context.Request.GetBufferType0x22(1); WritableRegion receiveRegion = context.Memory.GetWritableRegion(receivePosition, (int)receiveLength); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); - int result = -1; + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); + int result = -1; if (socket != null) { @@ -530,7 +528,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd receiveRegion.Dispose(); - if (sockAddrOutSize != 0 && sockAddrOutSize >= (ulong) Unsafe.SizeOf()) + if (sockAddrOutSize != 0 && sockAddrOutSize >= (ulong)Unsafe.SizeOf()) { context.Memory.Write(sockAddrOutPosition, BsdSockAddr.FromIPEndPoint(endPoint)); } @@ -548,16 +546,16 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // Send(u32 socket, u32 flags, buffer) -> (i32 ret, u32 bsd_errno) public ResultCode Send(ServiceCtx context) { - int socketFd = context.RequestData.ReadInt32(); + int socketFd = context.RequestData.ReadInt32(); BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32(); (ulong sendPosition, ulong sendSize) = context.Request.GetBufferType0x21(); ReadOnlySpan sendBuffer = context.Memory.GetSpan(sendPosition, (int)sendSize); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); - int result = -1; + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); + int result = -1; if (socket != null) { @@ -576,17 +574,19 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // SendTo(u32 socket, u32 flags, buffer, buffer) -> (i32 ret, u32 bsd_errno) public ResultCode SendTo(ServiceCtx context) { - int socketFd = context.RequestData.ReadInt32(); + int socketFd = context.RequestData.ReadInt32(); BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32(); - (ulong sendPosition, ulong sendSize) = context.Request.GetBufferType0x21(0); + (ulong sendPosition, ulong sendSize) = context.Request.GetBufferType0x21(0); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21(1); +#pragma warning restore IDE0059 ReadOnlySpan sendBuffer = context.Memory.GetSpan(sendPosition, (int)sendSize); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); - int result = -1; + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); + int result = -1; if (socket != null) { @@ -609,10 +609,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd { int socketFd = context.RequestData.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x22(); +#pragma warning restore IDE0059 - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -652,10 +654,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd { int socketFd = context.RequestData.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21(); +#pragma warning restore IDE0059 - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -673,10 +677,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd { int socketFd = context.RequestData.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21(); +#pragma warning restore IDE0059 - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -694,10 +700,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd { int socketFd = context.RequestData.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x22(); +#pragma warning restore IDE0059 - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { errno = LinuxError.ENOTCONN; @@ -721,10 +729,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd { int socketFd = context.RequestData.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x22(); +#pragma warning restore IDE0059 - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -742,15 +752,15 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // GetSockOpt(u32 socket, u32 level, u32 option_name) -> (i32 ret, u32 bsd_errno, u32, buffer) public ResultCode GetSockOpt(ServiceCtx context) { - int socketFd = context.RequestData.ReadInt32(); - SocketOptionLevel level = (SocketOptionLevel)context.RequestData.ReadInt32(); - BsdSocketOption option = (BsdSocketOption)context.RequestData.ReadInt32(); + int socketFd = context.RequestData.ReadInt32(); + SocketOptionLevel level = (SocketOptionLevel)context.RequestData.ReadInt32(); + BsdSocketOption option = (BsdSocketOption)context.RequestData.ReadInt32(); (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x22(); WritableRegion optionValue = context.Memory.GetWritableRegion(bufferPosition, (int)bufferSize); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -770,10 +780,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd public ResultCode Listen(ServiceCtx context) { int socketFd = context.RequestData.ReadInt32(); - int backlog = context.RequestData.ReadInt32(); + int backlog = context.RequestData.ReadInt32(); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -787,12 +797,14 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // Ioctl(u32 fd, u32 request, u32 bufcount, buffer, buffer, buffer, buffer) -> (i32 ret, u32 bsd_errno, buffer, buffer, buffer, buffer) public ResultCode Ioctl(ServiceCtx context) { - int socketFd = context.RequestData.ReadInt32(); - BsdIoctl cmd = (BsdIoctl)context.RequestData.ReadInt32(); - int bufferCount = context.RequestData.ReadInt32(); + int socketFd = context.RequestData.ReadInt32(); + BsdIoctl cmd = (BsdIoctl)context.RequestData.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + int bufferCount = context.RequestData.ReadInt32(); +#pragma warning restore IDE0059 - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -801,7 +813,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd case BsdIoctl.AtMark: errno = LinuxError.SUCCESS; +#pragma warning disable IDE0059 // Remove unnecessary value assignment (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x22(); +#pragma warning restore IDE0059 // FIXME: OOB not implemented. context.Memory.Write(bufferPosition, 0); @@ -823,12 +837,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd public ResultCode Fcntl(ServiceCtx context) { int socketFd = context.RequestData.ReadInt32(); - int cmd = context.RequestData.ReadInt32(); - int arg = context.RequestData.ReadInt32(); + int cmd = context.RequestData.ReadInt32(); + int arg = context.RequestData.ReadInt32(); - int result = 0; - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + int result = 0; + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -856,16 +870,16 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // SetSockOpt(u32 socket, u32 level, u32 option_name, buffer option_value) -> (i32 ret, u32 bsd_errno) public ResultCode SetSockOpt(ServiceCtx context) { - int socketFd = context.RequestData.ReadInt32(); - SocketOptionLevel level = (SocketOptionLevel)context.RequestData.ReadInt32(); - BsdSocketOption option = (BsdSocketOption)context.RequestData.ReadInt32(); + int socketFd = context.RequestData.ReadInt32(); + SocketOptionLevel level = (SocketOptionLevel)context.RequestData.ReadInt32(); + BsdSocketOption option = (BsdSocketOption)context.RequestData.ReadInt32(); (ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x21(); ReadOnlySpan optionValue = context.Memory.GetSpan(bufferPos, (int)bufferSize); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -880,10 +894,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd public ResultCode Shutdown(ServiceCtx context) { int socketFd = context.RequestData.ReadInt32(); - int how = context.RequestData.ReadInt32(); + int how = context.RequestData.ReadInt32(); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); if (socket != null) { @@ -924,9 +938,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd ReadOnlySpan sendBuffer = context.Memory.GetSpan(sendPosition, (int)sendSize); - LinuxError errno = LinuxError.EBADF; - IFileDescriptor file = _context.RetrieveFileDescriptor(fd); - int result = -1; + LinuxError errno = LinuxError.EBADF; + IFileDescriptor file = _context.RetrieveFileDescriptor(fd); + int result = -1; if (file != null) { @@ -951,9 +965,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd WritableRegion receiveRegion = context.Memory.GetWritableRegion(receivePosition, (int)receiveLength); - LinuxError errno = LinuxError.EBADF; - IFileDescriptor file = _context.RetrieveFileDescriptor(fd); - int result = -1; + LinuxError errno = LinuxError.EBADF; + IFileDescriptor file = _context.RetrieveFileDescriptor(fd); + int result = -1; if (file != null) { @@ -990,8 +1004,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // DuplicateSocket(u32 fd, u64 reserved) -> (i32 ret, u32 bsd_errno) public ResultCode DuplicateSocket(ServiceCtx context) { - int fd = context.RequestData.ReadInt32(); + int fd = context.RequestData.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong reserved = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 LinuxError errno = LinuxError.ENOENT; int newSockFd = -1; @@ -1016,20 +1032,22 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // RecvMMsg(u32 fd, u32 vlen, u32 flags, u32 reserved, nn::socket::TimeVal timeout) -> (i32 ret, u32 bsd_errno, buffer message); public ResultCode RecvMMsg(ServiceCtx context) { - int socketFd = context.RequestData.ReadInt32(); - int vlen = context.RequestData.ReadInt32(); + int socketFd = context.RequestData.ReadInt32(); + int vlen = context.RequestData.ReadInt32(); BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32(); - uint reserved = context.RequestData.ReadUInt32(); - TimeVal timeout = context.RequestData.ReadStruct(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + uint reserved = context.RequestData.ReadUInt32(); +#pragma warning restore IDE0059 + TimeVal timeout = context.RequestData.ReadStruct(); ulong receivePosition = context.Request.ReceiveBuff[0].Position; ulong receiveLength = context.Request.ReceiveBuff[0].Size; WritableRegion receiveRegion = context.Memory.GetWritableRegion(receivePosition, (int)receiveLength); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); - int result = -1; + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); + int result = -1; if (socket != null) { @@ -1059,8 +1077,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd // SendMMsg(u32 fd, u32 vlen, u32 flags) -> (i32 ret, u32 bsd_errno, buffer message); public ResultCode SendMMsg(ServiceCtx context) { - int socketFd = context.RequestData.ReadInt32(); - int vlen = context.RequestData.ReadInt32(); + int socketFd = context.RequestData.ReadInt32(); + int vlen = context.RequestData.ReadInt32(); BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32(); ulong receivePosition = context.Request.ReceiveBuff[0].Position; @@ -1068,9 +1086,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd WritableRegion receiveRegion = context.Memory.GetWritableRegion(receivePosition, (int)receiveLength); - LinuxError errno = LinuxError.EBADF; - ISocket socket = _context.RetrieveSocket(socketFd); - int result = -1; + LinuxError errno = LinuxError.EBADF; + ISocket socket = _context.RetrieveSocket(socketFd); + int result = -1; if (socket != null) { @@ -1104,7 +1122,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd context.RequestData.BaseStream.Position += 4; // Padding ulong initialValue = context.RequestData.ReadUInt64(); - EventFileDescriptor newEventFile = new EventFileDescriptor(initialValue, flags); + EventFileDescriptor newEventFile = new(initialValue, flags); LinuxError errno = LinuxError.SUCCESS; @@ -1118,4 +1136,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd return WriteBsdResult(context, newSockFd, errno); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IFileDescriptor.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IFileDescriptor.cs index 9d4f81ce2..dbeb90222 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IFileDescriptor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IFileDescriptor.cs @@ -12,4 +12,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd LinuxError Write(out int writeSize, ReadOnlySpan buffer); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/EventFileDescriptor.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/EventFileDescriptor.cs index d7b53158a..937d2fd70 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/EventFileDescriptor.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/EventFileDescriptor.cs @@ -150,4 +150,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/EventFileDescriptorPollManager.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/EventFileDescriptorPollManager.cs index e0ab68c62..9039d49a7 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/EventFileDescriptorPollManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/EventFileDescriptorPollManager.cs @@ -13,10 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { get { - if (_instance == null) - { - _instance = new EventFileDescriptorPollManager(); - } + _instance ??= new EventFileDescriptorPollManager(); return _instance; } @@ -31,7 +28,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { updatedCount = 0; - List waiters = new List(); + List waiters = new(); for (int i = 0; i < events.Count; i++) { @@ -119,4 +116,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl return LinuxError.EOPNOTSUPP; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs index 75efc49a1..dfc2a6723 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs @@ -462,7 +462,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl if (!CanSupportMMsgHdr(message)) { - Logger.Warning?.Print(LogClass.ServiceBsd, $"Unsupported BsdMMsgHdr"); + Logger.Warning?.Print(LogClass.ServiceBsd, "Unsupported BsdMMsgHdr"); return LinuxError.EOPNOTSUPP; } @@ -500,7 +500,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl if (!CanSupportMMsgHdr(message)) { - Logger.Warning?.Print(LogClass.ServiceBsd, $"Unsupported BsdMMsgHdr"); + Logger.Warning?.Print(LogClass.ServiceBsd, "Unsupported BsdMMsgHdr"); return LinuxError.EOPNOTSUPP; } @@ -527,4 +527,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocketPollManager.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocketPollManager.cs index 1b305dfb7..10d9882c1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocketPollManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocketPollManager.cs @@ -13,10 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { get { - if (_instance == null) - { - _instance = new ManagedSocketPollManager(); - } + _instance ??= new ManagedSocketPollManager(); return _instance; } @@ -29,9 +26,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl public LinuxError Poll(List events, int timeoutMilliseconds, out int updatedCount) { - List readEvents = new List(); - List writeEvents = new List(); - List errorEvents = new List(); + List readEvents = new(); + List writeEvents = new(); + List errorEvents = new(); updatedCount = 0; @@ -174,4 +171,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl return LinuxError.SUCCESS; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/WSAError.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/WSAError.cs index 0f24a57f5..5f3495df5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/WSAError.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/WSAError.cs @@ -9,77 +9,77 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl * All Windows Sockets error constants are biased by WSABASEERR from * the "normal" */ - WSABASEERR = 10000, + WSABASEERR = 10000, /* * Windows Sockets definitions of regular Microsoft C error constants */ - WSAEINTR = (WSABASEERR + 4), - WSAEBADF = (WSABASEERR + 9), - WSAEACCES = (WSABASEERR + 13), - WSAEFAULT = (WSABASEERR + 14), - WSAEINVAL = (WSABASEERR + 22), - WSAEMFILE = (WSABASEERR + 24), + WSAEINTR = (WSABASEERR + 4), + WSAEBADF = (WSABASEERR + 9), + WSAEACCES = (WSABASEERR + 13), + WSAEFAULT = (WSABASEERR + 14), + WSAEINVAL = (WSABASEERR + 22), + WSAEMFILE = (WSABASEERR + 24), /* * Windows Sockets definitions of regular Berkeley error constants */ - WSAEWOULDBLOCK = (WSABASEERR + 35), - WSAEINPROGRESS = (WSABASEERR + 36), - WSAEALREADY = (WSABASEERR + 37), - WSAENOTSOCK = (WSABASEERR + 38), - WSAEDESTADDRREQ = (WSABASEERR + 39), - WSAEMSGSIZE = (WSABASEERR + 40), - WSAEPROTOTYPE = (WSABASEERR + 41), - WSAENOPROTOOPT = (WSABASEERR + 42), - WSAEPROTONOSUPPORT = (WSABASEERR + 43), - WSAESOCKTNOSUPPORT = (WSABASEERR + 44), - WSAEOPNOTSUPP = (WSABASEERR + 45), - WSAEPFNOSUPPORT = (WSABASEERR + 46), - WSAEAFNOSUPPORT = (WSABASEERR + 47), - WSAEADDRINUSE = (WSABASEERR + 48), - WSAEADDRNOTAVAIL = (WSABASEERR + 49), - WSAENETDOWN = (WSABASEERR + 50), - WSAENETUNREACH = (WSABASEERR + 51), - WSAENETRESET = (WSABASEERR + 52), - WSAECONNABORTED = (WSABASEERR + 53), - WSAECONNRESET = (WSABASEERR + 54), - WSAENOBUFS = (WSABASEERR + 55), - WSAEISCONN = (WSABASEERR + 56), - WSAENOTCONN = (WSABASEERR + 57), - WSAESHUTDOWN = (WSABASEERR + 58), - WSAETOOMANYREFS = (WSABASEERR + 59), - WSAETIMEDOUT = (WSABASEERR + 60), - WSAECONNREFUSED = (WSABASEERR + 61), - WSAELOOP = (WSABASEERR + 62), - WSAENAMETOOLONG = (WSABASEERR + 63), - WSAEHOSTDOWN = (WSABASEERR + 64), - WSAEHOSTUNREACH = (WSABASEERR + 65), - WSAENOTEMPTY = (WSABASEERR + 66), - WSAEPROCLIM = (WSABASEERR + 67), - WSAEUSERS = (WSABASEERR + 68), - WSAEDQUOT = (WSABASEERR + 69), - WSAESTALE = (WSABASEERR + 70), - WSAEREMOTE = (WSABASEERR + 71), + WSAEWOULDBLOCK = (WSABASEERR + 35), + WSAEINPROGRESS = (WSABASEERR + 36), + WSAEALREADY = (WSABASEERR + 37), + WSAENOTSOCK = (WSABASEERR + 38), + WSAEDESTADDRREQ = (WSABASEERR + 39), + WSAEMSGSIZE = (WSABASEERR + 40), + WSAEPROTOTYPE = (WSABASEERR + 41), + WSAENOPROTOOPT = (WSABASEERR + 42), + WSAEPROTONOSUPPORT = (WSABASEERR + 43), + WSAESOCKTNOSUPPORT = (WSABASEERR + 44), + WSAEOPNOTSUPP = (WSABASEERR + 45), + WSAEPFNOSUPPORT = (WSABASEERR + 46), + WSAEAFNOSUPPORT = (WSABASEERR + 47), + WSAEADDRINUSE = (WSABASEERR + 48), + WSAEADDRNOTAVAIL = (WSABASEERR + 49), + WSAENETDOWN = (WSABASEERR + 50), + WSAENETUNREACH = (WSABASEERR + 51), + WSAENETRESET = (WSABASEERR + 52), + WSAECONNABORTED = (WSABASEERR + 53), + WSAECONNRESET = (WSABASEERR + 54), + WSAENOBUFS = (WSABASEERR + 55), + WSAEISCONN = (WSABASEERR + 56), + WSAENOTCONN = (WSABASEERR + 57), + WSAESHUTDOWN = (WSABASEERR + 58), + WSAETOOMANYREFS = (WSABASEERR + 59), + WSAETIMEDOUT = (WSABASEERR + 60), + WSAECONNREFUSED = (WSABASEERR + 61), + WSAELOOP = (WSABASEERR + 62), + WSAENAMETOOLONG = (WSABASEERR + 63), + WSAEHOSTDOWN = (WSABASEERR + 64), + WSAEHOSTUNREACH = (WSABASEERR + 65), + WSAENOTEMPTY = (WSABASEERR + 66), + WSAEPROCLIM = (WSABASEERR + 67), + WSAEUSERS = (WSABASEERR + 68), + WSAEDQUOT = (WSABASEERR + 69), + WSAESTALE = (WSABASEERR + 70), + WSAEREMOTE = (WSABASEERR + 71), /* * Extended Windows Sockets error constant definitions */ - WSASYSNOTREADY = (WSABASEERR + 91), - WSAVERNOTSUPPORTED = (WSABASEERR + 92), - WSANOTINITIALISED = (WSABASEERR + 93), - WSAEDISCON = (WSABASEERR + 101), - WSAENOMORE = (WSABASEERR + 102), - WSAECANCELLED = (WSABASEERR + 103), - WSAEINVALIDPROCTABLE = (WSABASEERR + 104), - WSAEINVALIDPROVIDER = (WSABASEERR + 105), - WSAEPROVIDERFAILEDINIT = (WSABASEERR + 106), - WSASYSCALLFAILURE = (WSABASEERR + 107), - WSASERVICE_NOT_FOUND = (WSABASEERR + 108), - WSATYPE_NOT_FOUND = (WSABASEERR + 109), - WSA_E_NO_MORE = (WSABASEERR + 110), - WSA_E_CANCELLED = (WSABASEERR + 111), - WSAEREFUSED = (WSABASEERR + 112), + WSASYSNOTREADY = (WSABASEERR + 91), + WSAVERNOTSUPPORTED = (WSABASEERR + 92), + WSANOTINITIALISED = (WSABASEERR + 93), + WSAEDISCON = (WSABASEERR + 101), + WSAENOMORE = (WSABASEERR + 102), + WSAECANCELLED = (WSABASEERR + 103), + WSAEINVALIDPROCTABLE = (WSABASEERR + 104), + WSAEINVALIDPROVIDER = (WSABASEERR + 105), + WSAEPROVIDERFAILEDINIT = (WSABASEERR + 106), + WSASYSCALLFAILURE = (WSABASEERR + 107), + WSASERVICE_NOT_FOUND = (WSABASEERR + 108), + WSATYPE_NOT_FOUND = (WSABASEERR + 109), + WSA_E_NO_MORE = (WSABASEERR + 110), + WSA_E_CANCELLED = (WSABASEERR + 111), + WSAEREFUSED = (WSABASEERR + 112), /* * Error return codes from gethostbyname() and gethostbyaddr() @@ -93,42 +93,42 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl */ /* Authoritative Answer: Host not found */ - WSAHOST_NOT_FOUND = (WSABASEERR + 1001), + WSAHOST_NOT_FOUND = (WSABASEERR + 1001), /* Non-Authoritative: Host not found, or SERVERFAIL */ - WSATRY_AGAIN = (WSABASEERR + 1002), + WSATRY_AGAIN = (WSABASEERR + 1002), /* Non-recoverable errors, FORMERR, REFUSED, NOTIMP */ - WSANO_RECOVERY = (WSABASEERR + 1003), + WSANO_RECOVERY = (WSABASEERR + 1003), /* Valid name, no data record of requested type */ - WSANO_DATA = (WSABASEERR + 1004), + WSANO_DATA = (WSABASEERR + 1004), /* * Define QOS related error return codes * */ - WSA_QOS_RECEIVERS = (WSABASEERR + 1005), + WSA_QOS_RECEIVERS = (WSABASEERR + 1005), /* at least one Reserve has arrived */ - WSA_QOS_SENDERS = (WSABASEERR + 1006), + WSA_QOS_SENDERS = (WSABASEERR + 1006), /* at least one Path has arrived */ - WSA_QOS_NO_SENDERS = (WSABASEERR + 1007), + WSA_QOS_NO_SENDERS = (WSABASEERR + 1007), /* there are no senders */ - WSA_QOS_NO_RECEIVERS = (WSABASEERR + 1008), + WSA_QOS_NO_RECEIVERS = (WSABASEERR + 1008), /* there are no receivers */ - WSA_QOS_REQUEST_CONFIRMED = (WSABASEERR + 1009), + WSA_QOS_REQUEST_CONFIRMED = (WSABASEERR + 1009), /* Reserve has been confirmed */ - WSA_QOS_ADMISSION_FAILURE = (WSABASEERR + 1010), + WSA_QOS_ADMISSION_FAILURE = (WSABASEERR + 1010), /* error due to lack of resources */ - WSA_QOS_POLICY_FAILURE = (WSABASEERR + 1011), + WSA_QOS_POLICY_FAILURE = (WSABASEERR + 1011), /* rejected for administrative reasons - bad credentials */ - WSA_QOS_BAD_STYLE = (WSABASEERR + 1012), + WSA_QOS_BAD_STYLE = (WSABASEERR + 1012), /* unknown or conflicting style */ - WSA_QOS_BAD_OBJECT = (WSABASEERR + 1013), + WSA_QOS_BAD_OBJECT = (WSABASEERR + 1013), /* problem with some part of the filterspec or providerspecific * buffer in general */ WSA_QOS_TRAFFIC_CTRL_ERROR = (WSABASEERR + 1014), /* problem with some part of the flowspec */ - WSA_QOS_GENERIC_ERROR = (WSABASEERR + 1015) + WSA_QOS_GENERIC_ERROR = (WSABASEERR + 1015), } } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/WinSockHelper.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/WinSockHelper.cs index 5668d30b0..9df180235 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/WinSockHelper.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/WinSockHelper.cs @@ -1,5 +1,5 @@ using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types; -using System; +using System; using System.Collections.Generic; using System.Net.Sockets; @@ -88,7 +88,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl // WSAEFAULT { WsaError.WSAEFAULT, LinuxError.EFAULT }, // NOERROR - { 0, 0 } + { 0, 0 }, }; private static readonly Dictionary _errorMapMacOs = new() @@ -136,7 +136,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { 59, LinuxError.ETOOMANYREFS }, { 92, LinuxError.EILSEQ }, { 89, LinuxError.ECANCELED }, - { 84, LinuxError.EOVERFLOW } + { 84, LinuxError.EOVERFLOW }, }; private static readonly Dictionary _soSocketOptionMap = new() @@ -157,7 +157,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { BsdSocketOption.SoSndTimeo, SocketOptionName.SendTimeout }, { BsdSocketOption.SoRcvTimeo, SocketOptionName.ReceiveTimeout }, { BsdSocketOption.SoError, SocketOptionName.Error }, - { BsdSocketOption.SoType, SocketOptionName.Type } + { BsdSocketOption.SoType, SocketOptionName.Type }, }; private static readonly Dictionary _ipSocketOptionMap = new() @@ -172,7 +172,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { BsdSocketOption.IpDropMembership, SocketOptionName.DropMembership }, { BsdSocketOption.IpDontFrag, SocketOptionName.DontFragment }, { BsdSocketOption.IpAddSourceMembership, SocketOptionName.AddSourceMembership }, - { BsdSocketOption.IpDropSourceMembership, SocketOptionName.DropSourceMembership } + { BsdSocketOption.IpDropSourceMembership, SocketOptionName.DropSourceMembership }, }; private static readonly Dictionary _tcpSocketOptionMap = new() @@ -180,7 +180,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { BsdSocketOption.TcpNoDelay, SocketOptionName.NoDelay }, { BsdSocketOption.TcpKeepIdle, SocketOptionName.TcpKeepAliveTime }, { BsdSocketOption.TcpKeepIntvl, SocketOptionName.TcpKeepAliveInterval }, - { BsdSocketOption.TcpKeepCnt, SocketOptionName.TcpKeepAliveRetryCount } + { BsdSocketOption.TcpKeepCnt, SocketOptionName.TcpKeepAliveRetryCount }, }; public static LinuxError ConvertError(WsaError errorCode) @@ -210,7 +210,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl SocketOptionLevel.Socket => _soSocketOptionMap, SocketOptionLevel.IP => _ipSocketOptionMap, SocketOptionLevel.Tcp => _tcpSocketOptionMap, - _ => null + _ => null, }; if (table == null) @@ -222,4 +222,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl return table.TryGetValue(option, out name); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/ServerInterface.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/ServerInterface.cs index 798fc0157..9afdf2503 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/ServerInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/ServerInterface.cs @@ -5,4 +5,4 @@ { public ServerInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdAddressFamily.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdAddressFamily.cs index 37461bb25..747946386 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdAddressFamily.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdAddressFamily.cs @@ -6,6 +6,6 @@ InterNetwork = 2, InterNetworkV6 = 28, - Unknown = uint.MaxValue + Unknown = uint.MaxValue, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdIoctl.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdIoctl.cs index 1dfa5a5f9..9c330e35d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdIoctl.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdIoctl.cs @@ -2,6 +2,6 @@ { enum BsdIoctl { - AtMark = 0x40047307 + AtMark = 0x40047307, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSockAddr.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSockAddr.cs index 67c11e54d..af3a44e88 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSockAddr.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSockAddr.cs @@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types public IPEndPoint ToIPEndPoint() { - IPAddress address = new IPAddress(Address.AsSpan()); + IPAddress address = new(Address.AsSpan()); int port = (ushort)IPAddress.NetworkToHostOrder((short)Port); return new IPEndPoint(address, port); @@ -24,11 +24,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types public static BsdSockAddr FromIPEndPoint(IPEndPoint endpoint) { - BsdSockAddr result = new BsdSockAddr + BsdSockAddr result = new() { Length = 0, Family = (byte)endpoint.AddressFamily, - Port = (ushort)IPAddress.HostToNetworkOrder((short)endpoint.Port) + Port = (ushort)IPAddress.HostToNetworkOrder((short)endpoint.Port), }; endpoint.Address.GetAddressBytes().AsSpan().CopyTo(result.Address.AsSpan()); diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketCreationFlags.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketCreationFlags.cs index be5991ff6..ac79deb31 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketCreationFlags.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketCreationFlags.cs @@ -9,6 +9,6 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types CloseOnExecution = 1, NonBlocking = 2, - FlagsShift = 28 + FlagsShift = 28, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketFlags.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketFlags.cs index 4408c89af..639981291 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketFlags.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketFlags.cs @@ -17,6 +17,6 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types Compat = 0x8000, SoCallbck = 0x10000, NoSignal = 0x20000, - CMsgCloExec = 0x40000 + CMsgCloExec = 0x40000, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketOption.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketOption.cs index 4d0d1dcf3..5bc3e81f4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketOption.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketOption.cs @@ -1,5 +1,8 @@ +using System.Diagnostics.CodeAnalysis; + namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types { + [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")] enum BsdSocketOption { SoDebug = 0x1, @@ -114,6 +117,6 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types TcpKeepInit = 128, TcpKeepIdle = 256, TcpKeepIntvl = 512, - TcpKeepCnt = 1024 + TcpKeepCnt = 1024, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketShutdownFlags.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketShutdownFlags.cs index 13230ac39..883e3c31f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketShutdownFlags.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSocketShutdownFlags.cs @@ -4,6 +4,6 @@ { Receive, Send, - ReceiveAndSend + ReceiveAndSend, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/EventFdFlags.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/EventFdFlags.cs index e01d82267..996facd35 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/EventFdFlags.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/EventFdFlags.cs @@ -7,6 +7,6 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types { None = 0, Semaphore = 1 << 0, - NonBlocking = 1 << 2 + NonBlocking = 1 << 2, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/IPollManager.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/IPollManager.cs index d36638784..66b1bcf1b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/IPollManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/IPollManager.cs @@ -10,4 +10,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types LinuxError Select(List events, int timeout, out int updatedCount); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/LinuxError.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/LinuxError.cs index 96602830b..aaeee44d1 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/LinuxError.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/LinuxError.cs @@ -5,44 +5,44 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types [SuppressMessage("ReSharper", "InconsistentNaming")] enum LinuxError { - SUCCESS = 0, - EPERM = 1 /* Operation not permitted */, - ENOENT = 2 /* No such file or directory */, - ESRCH = 3 /* No such process */, - EINTR = 4 /* Interrupted system call */, - EIO = 5 /* I/O error */, - ENXIO = 6 /* No such device or address */, - E2BIG = 7 /* Argument list too long */, - ENOEXEC = 8 /* Exec format error */, - EBADF = 9 /* Bad file number */, - ECHILD = 10 /* No child processes */, - EAGAIN = 11 /* Try again */, - ENOMEM = 12 /* Out of memory */, - EACCES = 13 /* Permission denied */, - EFAULT = 14 /* Bad address */, - ENOTBLK = 15 /* Block device required */, - EBUSY = 16 /* Device or resource busy */, - EEXIST = 17 /* File exists */, - EXDEV = 18 /* Cross-device link */, - ENODEV = 19 /* No such device */, - ENOTDIR = 20 /* Not a directory */, - EISDIR = 21 /* Is a directory */, - EINVAL = 22 /* Invalid argument */, - ENFILE = 23 /* File table overflow */, - EMFILE = 24 /* Too many open files */, - ENOTTY = 25 /* Not a typewriter */, - ETXTBSY = 26 /* Text file busy */, - EFBIG = 27 /* File too large */, - ENOSPC = 28 /* No space left on device */, - ESPIPE = 29 /* Illegal seek */, - EROFS = 30 /* Read-only file system */, - EMLINK = 31 /* Too many links */, - EPIPE = 32 /* Broken pipe */, - EDOM = 33 /* Math argument out of domain of func */, - ERANGE = 34 /* Math result not representable */, - EDEADLK = 35 /* Resource deadlock would occur */, - ENAMETOOLONG = 36 /* File name too long */, - ENOLCK = 37 /* No record locks available */, + SUCCESS = 0, + EPERM = 1 /* Operation not permitted */, + ENOENT = 2 /* No such file or directory */, + ESRCH = 3 /* No such process */, + EINTR = 4 /* Interrupted system call */, + EIO = 5 /* I/O error */, + ENXIO = 6 /* No such device or address */, + E2BIG = 7 /* Argument list too long */, + ENOEXEC = 8 /* Exec format error */, + EBADF = 9 /* Bad file number */, + ECHILD = 10 /* No child processes */, + EAGAIN = 11 /* Try again */, + ENOMEM = 12 /* Out of memory */, + EACCES = 13 /* Permission denied */, + EFAULT = 14 /* Bad address */, + ENOTBLK = 15 /* Block device required */, + EBUSY = 16 /* Device or resource busy */, + EEXIST = 17 /* File exists */, + EXDEV = 18 /* Cross-device link */, + ENODEV = 19 /* No such device */, + ENOTDIR = 20 /* Not a directory */, + EISDIR = 21 /* Is a directory */, + EINVAL = 22 /* Invalid argument */, + ENFILE = 23 /* File table overflow */, + EMFILE = 24 /* Too many open files */, + ENOTTY = 25 /* Not a typewriter */, + ETXTBSY = 26 /* Text file busy */, + EFBIG = 27 /* File too large */, + ENOSPC = 28 /* No space left on device */, + ESPIPE = 29 /* Illegal seek */, + EROFS = 30 /* Read-only file system */, + EMLINK = 31 /* Too many links */, + EPIPE = 32 /* Broken pipe */, + EDOM = 33 /* Math argument out of domain of func */, + ERANGE = 34 /* Math result not representable */, + EDEADLK = 35 /* Resource deadlock would occur */, + ENAMETOOLONG = 36 /* File name too long */, + ENOLCK = 37 /* No record locks available */, /* * This error code is special: arch syscall entry code will return @@ -51,105 +51,105 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types * failures due to attempts to use a nonexistent syscall, syscall * implementations should refrain from returning -ENOSYS. */ - ENOSYS = 38 /* Invalid system call number */, - ENOTEMPTY = 39 /* Directory not empty */, - ELOOP = 40 /* Too many symbolic links encountered */, - EWOULDBLOCK = EAGAIN /* Operation would block */, - ENOMSG = 42 /* No message of desired type */, - EIDRM = 43 /* Identifier removed */, - ECHRNG = 44 /* Channel number out of range */, - EL2NSYNC = 45 /* Level 2 not synchronized */, - EL3HLT = 46 /* Level 3 halted */, - EL3RST = 47 /* Level 3 reset */, - ELNRNG = 48 /* Link number out of range */, - EUNATCH = 49 /* Protocol driver not attached */, - ENOCSI = 50 /* No CSI structure available */, - EL2HLT = 51 /* Level 2 halted */, - EBADE = 52 /* Invalid exchange */, - EBADR = 53 /* Invalid request descriptor */, - EXFULL = 54 /* Exchange full */, - ENOANO = 55 /* No anode */, - EBADRQC = 56 /* Invalid request code */, - EBADSLT = 57 /* Invalid slot */, - EDEADLOCK = EDEADLK, - EBFONT = 59 /* Bad font file format */, - ENOSTR = 60 /* Device not a stream */, - ENODATA = 61 /* No data available */, - ETIME = 62 /* Timer expired */, - ENOSR = 63 /* Out of streams resources */, - ENONET = 64 /* Machine is not on the network */, - ENOPKG = 65 /* Package not installed */, - EREMOTE = 66 /* Object is remote */, - ENOLINK = 67 /* Link has been severed */, - EADV = 68 /* Advertise error */, - ESRMNT = 69 /* Srmount error */, - ECOMM = 70 /* Communication error on send */, - EPROTO = 71 /* Protocol error */, - EMULTIHOP = 72 /* Multihop attempted */, - EDOTDOT = 73 /* RFS specific error */, - EBADMSG = 74 /* Not a data message */, - EOVERFLOW = 75 /* Value too large for defined data type */, - ENOTUNIQ = 76 /* Name not unique on network */, - EBADFD = 77 /* File descriptor in bad state */, - EREMCHG = 78 /* Remote address changed */, - ELIBACC = 79 /* Can not access a needed shared library */, - ELIBBAD = 80 /* Accessing a corrupted shared library */, - ELIBSCN = 81 /* .lib section in a.out corrupted */, - ELIBMAX = 82 /* Attempting to link in too many shared libraries */, - ELIBEXEC = 83 /* Cannot exec a shared library directly */, - EILSEQ = 84 /* Illegal byte sequence */, - ERESTART = 85 /* Interrupted system call should be restarted */, - ESTRPIPE = 86 /* Streams pipe error */, - EUSERS = 87 /* Too many users */, - ENOTSOCK = 88 /* Socket operation on non-socket */, - EDESTADDRREQ = 89 /* Destination address required */, - EMSGSIZE = 90 /* Message too long */, - EPROTOTYPE = 91 /* Protocol wrong type for socket */, - ENOPROTOOPT = 92 /* Protocol not available */, + ENOSYS = 38 /* Invalid system call number */, + ENOTEMPTY = 39 /* Directory not empty */, + ELOOP = 40 /* Too many symbolic links encountered */, + EWOULDBLOCK = EAGAIN /* Operation would block */, + ENOMSG = 42 /* No message of desired type */, + EIDRM = 43 /* Identifier removed */, + ECHRNG = 44 /* Channel number out of range */, + EL2NSYNC = 45 /* Level 2 not synchronized */, + EL3HLT = 46 /* Level 3 halted */, + EL3RST = 47 /* Level 3 reset */, + ELNRNG = 48 /* Link number out of range */, + EUNATCH = 49 /* Protocol driver not attached */, + ENOCSI = 50 /* No CSI structure available */, + EL2HLT = 51 /* Level 2 halted */, + EBADE = 52 /* Invalid exchange */, + EBADR = 53 /* Invalid request descriptor */, + EXFULL = 54 /* Exchange full */, + ENOANO = 55 /* No anode */, + EBADRQC = 56 /* Invalid request code */, + EBADSLT = 57 /* Invalid slot */, + EDEADLOCK = EDEADLK, + EBFONT = 59 /* Bad font file format */, + ENOSTR = 60 /* Device not a stream */, + ENODATA = 61 /* No data available */, + ETIME = 62 /* Timer expired */, + ENOSR = 63 /* Out of streams resources */, + ENONET = 64 /* Machine is not on the network */, + ENOPKG = 65 /* Package not installed */, + EREMOTE = 66 /* Object is remote */, + ENOLINK = 67 /* Link has been severed */, + EADV = 68 /* Advertise error */, + ESRMNT = 69 /* Srmount error */, + ECOMM = 70 /* Communication error on send */, + EPROTO = 71 /* Protocol error */, + EMULTIHOP = 72 /* Multihop attempted */, + EDOTDOT = 73 /* RFS specific error */, + EBADMSG = 74 /* Not a data message */, + EOVERFLOW = 75 /* Value too large for defined data type */, + ENOTUNIQ = 76 /* Name not unique on network */, + EBADFD = 77 /* File descriptor in bad state */, + EREMCHG = 78 /* Remote address changed */, + ELIBACC = 79 /* Can not access a needed shared library */, + ELIBBAD = 80 /* Accessing a corrupted shared library */, + ELIBSCN = 81 /* .lib section in a.out corrupted */, + ELIBMAX = 82 /* Attempting to link in too many shared libraries */, + ELIBEXEC = 83 /* Cannot exec a shared library directly */, + EILSEQ = 84 /* Illegal byte sequence */, + ERESTART = 85 /* Interrupted system call should be restarted */, + ESTRPIPE = 86 /* Streams pipe error */, + EUSERS = 87 /* Too many users */, + ENOTSOCK = 88 /* Socket operation on non-socket */, + EDESTADDRREQ = 89 /* Destination address required */, + EMSGSIZE = 90 /* Message too long */, + EPROTOTYPE = 91 /* Protocol wrong type for socket */, + ENOPROTOOPT = 92 /* Protocol not available */, EPROTONOSUPPORT = 93 /* Protocol not supported */, ESOCKTNOSUPPORT = 94 /* Socket type not supported */, - EOPNOTSUPP = 95 /* Operation not supported on transport endpoint */, - EPFNOSUPPORT = 96 /* Protocol family not supported */, - EAFNOSUPPORT = 97 /* Address family not supported by protocol */, - EADDRINUSE = 98 /* Address already in use */, - EADDRNOTAVAIL = 99 /* Cannot assign requested address */, - ENETDOWN = 100 /* Network is down */, - ENETUNREACH = 101 /* Network is unreachable */, - ENETRESET = 102 /* Network dropped connection because of reset */, - ECONNABORTED = 103 /* Software caused connection abort */, - ECONNRESET = 104 /* Connection reset by peer */, - ENOBUFS = 105 /* No buffer space available */, - EISCONN = 106 /* Transport endpoint is already connected */, - ENOTCONN = 107 /* Transport endpoint is not connected */, - ESHUTDOWN = 108 /* Cannot send after transport endpoint shutdown */, - ETOOMANYREFS = 109 /* Too many references: cannot splice */, - ETIMEDOUT = 110 /* Connection timed out */, - ECONNREFUSED = 111 /* Connection refused */, - EHOSTDOWN = 112 /* Host is down */, - EHOSTUNREACH = 113 /* No route to host */, - EALREADY = 114 /* Operation already in progress */, - EINPROGRESS = 115 /* Operation now in progress */, - ESTALE = 116 /* Stale file handle */, - EUCLEAN = 117 /* Structure needs cleaning */, - ENOTNAM = 118 /* Not a XENIX named type file */, - ENAVAIL = 119 /* No XENIX semaphores available */, - EISNAM = 120 /* Is a named type file */, - EREMOTEIO = 121 /* Remote I/O error */, - EDQUOT = 122 /* Quota exceeded */, - ENOMEDIUM = 123 /* No medium found */, - EMEDIUMTYPE = 124 /* Wrong medium type */, - ECANCELED = 125 /* Operation Canceled */, - ENOKEY = 126 /* Required key not available */, - EKEYEXPIRED = 127 /* Key has expired */, - EKEYREVOKED = 128 /* Key has been revoked */, - EKEYREJECTED = 129 /* Key was rejected by service */, + EOPNOTSUPP = 95 /* Operation not supported on transport endpoint */, + EPFNOSUPPORT = 96 /* Protocol family not supported */, + EAFNOSUPPORT = 97 /* Address family not supported by protocol */, + EADDRINUSE = 98 /* Address already in use */, + EADDRNOTAVAIL = 99 /* Cannot assign requested address */, + ENETDOWN = 100 /* Network is down */, + ENETUNREACH = 101 /* Network is unreachable */, + ENETRESET = 102 /* Network dropped connection because of reset */, + ECONNABORTED = 103 /* Software caused connection abort */, + ECONNRESET = 104 /* Connection reset by peer */, + ENOBUFS = 105 /* No buffer space available */, + EISCONN = 106 /* Transport endpoint is already connected */, + ENOTCONN = 107 /* Transport endpoint is not connected */, + ESHUTDOWN = 108 /* Cannot send after transport endpoint shutdown */, + ETOOMANYREFS = 109 /* Too many references: cannot splice */, + ETIMEDOUT = 110 /* Connection timed out */, + ECONNREFUSED = 111 /* Connection refused */, + EHOSTDOWN = 112 /* Host is down */, + EHOSTUNREACH = 113 /* No route to host */, + EALREADY = 114 /* Operation already in progress */, + EINPROGRESS = 115 /* Operation now in progress */, + ESTALE = 116 /* Stale file handle */, + EUCLEAN = 117 /* Structure needs cleaning */, + ENOTNAM = 118 /* Not a XENIX named type file */, + ENAVAIL = 119 /* No XENIX semaphores available */, + EISNAM = 120 /* Is a named type file */, + EREMOTEIO = 121 /* Remote I/O error */, + EDQUOT = 122 /* Quota exceeded */, + ENOMEDIUM = 123 /* No medium found */, + EMEDIUMTYPE = 124 /* Wrong medium type */, + ECANCELED = 125 /* Operation Canceled */, + ENOKEY = 126 /* Required key not available */, + EKEYEXPIRED = 127 /* Key has expired */, + EKEYREVOKED = 128 /* Key has been revoked */, + EKEYREJECTED = 129 /* Key was rejected by service */, /* for robust mutexes */ - EOWNERDEAD = 130 /* Owner died */, + EOWNERDEAD = 130 /* Owner died */, ENOTRECOVERABLE = 131 /* State not recoverable */, - ERFKILL = 132 /* Operation not possible due to RF-kill */, + ERFKILL = 132 /* Operation not possible due to RF-kill */, - EHWPOISON = 133 /* Memory page has hardware error */ + EHWPOISON = 133, /* Memory page has hardware error */ } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEvent.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEvent.cs index 8b77a6c2f..27a96bd81 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEvent.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEvent.cs @@ -11,4 +11,4 @@ FileDescriptor = fileDescriptor; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEventData.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEventData.cs index 546b738ee..16d01055c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEventData.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEventData.cs @@ -2,10 +2,10 @@ { struct PollEventData { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public int SocketFd; public PollEventTypeMask InputEvents; #pragma warning restore CS0649 public PollEventTypeMask OutputEvents; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEventTypeMask.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEventTypeMask.cs index f434fa032..d4c96c81f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEventTypeMask.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/PollEventTypeMask.cs @@ -10,6 +10,6 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types Output = 4, Error = 8, Disconnected = 0x10, - Invalid = 0x20 + Invalid = 0x20, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Ethc/IEthInterface.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Ethc/IEthInterface.cs index f58776977..1c216ea58 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Ethc/IEthInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Ethc/IEthInterface.cs @@ -5,4 +5,4 @@ { public IEthInterface(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Ethc/IEthInterfaceGroup.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Ethc/IEthInterfaceGroup.cs index 9832e4483..3147a8928 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Ethc/IEthInterfaceGroup.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Ethc/IEthInterfaceGroup.cs @@ -5,4 +5,4 @@ { public IEthInterfaceGroup(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs index 0b7adff4f..c991db3fb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs @@ -14,9 +14,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd class IManager : IpcService { public static readonly NsdSettings NsdSettings; +#pragma warning disable IDE0052 // Remove unread private member private readonly FqdnResolver _fqdnResolver; +#pragma warning restore IDE0052 - private bool _isInitialized = false; + private readonly bool _isInitialized = false; public IManager(ServiceCtx context) { @@ -43,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd { Initialized = true, TestMode = (bool)testMode, - Environment = (string)environmentIdentifier + Environment = (string)environmentIdentifier, }; } @@ -158,7 +160,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd public ResultCode Resolve(ServiceCtx context) { ulong outputPosition = context.Request.ReceiveBuff[0].Position; - ulong outputSize = context.Request.ReceiveBuff[0].Size; + ulong outputSize = context.Request.ReceiveBuff[0].Size; ResultCode result = _fqdnResolver.ResolveEx(context, out _, out string resolvedAddress); @@ -181,7 +183,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd public ResultCode ResolveEx(ServiceCtx context) { ulong outputPosition = context.Request.ReceiveBuff[0].Position; - ulong outputSize = context.Request.ReceiveBuff[0].Size; + ulong outputSize = context.Request.ReceiveBuff[0].Size; ResultCode result = _fqdnResolver.ResolveEx(context, out ResultCode errorCode, out string resolvedAddress); @@ -377,7 +379,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd "sd" => (byte)ApplicationServerEnvironmentType.Sd, "sp" => (byte)ApplicationServerEnvironmentType.Sp, "dp" => (byte)ApplicationServerEnvironmentType.Dp, - _ => (byte)ApplicationServerEnvironmentType.None + _ => (byte)ApplicationServerEnvironmentType.None, }; context.ResponseData.Write(environmentType); @@ -399,4 +401,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd throw new ServiceNotImplementedException(this, context); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Manager/FqdnResolver.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Manager/FqdnResolver.cs index 4096e431f..a8fbcf092 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Manager/FqdnResolver.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Manager/FqdnResolver.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager { class FqdnResolver { - private const string _dummyAddress = "unknown.dummy.nintendo.net"; + private const string DummyAddress = "unknown.dummy.nintendo.net"; public ResultCode GetEnvironmentIdentifier(out string identifier) { @@ -24,8 +24,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager public static ResultCode Resolve(string address, out string resolvedAddress) { - if (address == "api.sect.srv.nintendo.net" || - address == "ctest.cdn.nintendo.net" || + if (address == "api.sect.srv.nintendo.net" || + address == "ctest.cdn.nintendo.net" || address == "ctest.cdn.n.nintendoswitch.cn" || address == "unknown.dummy.nintendo.net") { @@ -50,6 +50,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager resolvedAddress = address switch { +#pragma warning disable IDE0055 // Disable formatting "e97b8a9d672e4ce4845ec6947cd66ef6-sb-api.accounts.nintendo.com" => "e97b8a9d672e4ce4845ec6947cd66ef6-sb.baas.nintendo.com", // dp1 environment "api.accounts.nintendo.com" => "e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com", // dp1 environment "e97b8a9d672e4ce4845ec6947cd66ef6-sb.accounts.nintendo.com" => "e97b8a9d672e4ce4845ec6947cd66ef6-sb.baas.nintendo.com", // lp1 environment @@ -60,6 +61,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager this + 0x2BE8 => this + 0x2BE8 + 0x300 */ _ => address, +#pragma warning restore IDE0055 }; } @@ -69,7 +71,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager public ResultCode ResolveEx(ServiceCtx context, out ResultCode resultCode, out string resolvedAddress) { ulong inputPosition = context.Request.SendBuff[0].Position; - ulong inputSize = context.Request.SendBuff[0].Size; + ulong inputSize = context.Request.SendBuff[0].Size; byte[] addressBuffer = new byte[inputSize]; @@ -81,7 +83,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager if (resultCode != ResultCode.Success) { - resolvedAddress = _dummyAddress; + resolvedAddress = DummyAddress; } if (IManager.NsdSettings.TestMode) @@ -94,4 +96,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/ResultCode.cs index 993fbe8af..5a62922fc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/ResultCode.cs @@ -2,18 +2,18 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd { enum ResultCode { - ModuleId = 141, + ModuleId = 141, ErrorCodeShift = 9, Success = 0, - InvalidSettingsValue = ( 1 << ErrorCodeShift) | ModuleId, - InvalidObject1 = ( 3 << ErrorCodeShift) | ModuleId, - InvalidObject2 = ( 4 << ErrorCodeShift) | ModuleId, - NullOutputObject = ( 5 << ErrorCodeShift) | ModuleId, - SettingsNotLoaded = ( 6 << ErrorCodeShift) | ModuleId, - InvalidArgument = ( 8 << ErrorCodeShift) | ModuleId, - SettingsNotInitialized = ( 10 << ErrorCodeShift) | ModuleId, - ServiceNotInitialized = (400 << ErrorCodeShift) | ModuleId, + InvalidSettingsValue = (1 << ErrorCodeShift) | ModuleId, + InvalidObject1 = (3 << ErrorCodeShift) | ModuleId, + InvalidObject2 = (4 << ErrorCodeShift) | ModuleId, + NullOutputObject = (5 << ErrorCodeShift) | ModuleId, + SettingsNotLoaded = (6 << ErrorCodeShift) | ModuleId, + InvalidArgument = (8 << ErrorCodeShift) | ModuleId, + SettingsNotInitialized = (10 << ErrorCodeShift) | ModuleId, + ServiceNotInitialized = (400 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Types/ApplicationServerEnvironmentType.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Types/ApplicationServerEnvironmentType.cs index 150bdab4f..1acb69fce 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Types/ApplicationServerEnvironmentType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Types/ApplicationServerEnvironmentType.cs @@ -6,6 +6,6 @@ Lp, Sd, Sp, - Dp + Dp, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Types/NsdSettings.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Types/NsdSettings.cs index 0a72fa874..08fb15e0a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Types/NsdSettings.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Types/NsdSettings.cs @@ -2,8 +2,8 @@ { class NsdSettings { - public bool Initialized; - public bool TestMode; + public bool Initialized; + public bool TestMode; public string Environment; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs index 64c3acbb5..93960d13e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs @@ -28,8 +28,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres public ResultCode SetDnsAddressesPrivateRequest(ServiceCtx context) { uint cancelHandleRequest = context.RequestData.ReadUInt32(); - ulong bufferPosition = context.Request.SendBuff[0].Position; - ulong bufferSize = context.Request.SendBuff[0].Size; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong bufferPosition = context.Request.SendBuff[0].Position; + ulong bufferSize = context.Request.SendBuff[0].Size; +#pragma warning restore IDE0059 // TODO: This is stubbed in 2.0.0+, reverse 1.0.0 version for the sake of completeness. Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest }); @@ -42,8 +44,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres public ResultCode GetDnsAddressPrivateRequest(ServiceCtx context) { uint cancelHandleRequest = context.RequestData.ReadUInt32(); - ulong bufferPosition = context.Request.ReceiveBuff[0].Position; - ulong bufferSize = context.Request.ReceiveBuff[0].Size; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong bufferPosition = context.Request.ReceiveBuff[0].Position; + ulong bufferSize = context.Request.ReceiveBuff[0].Size; +#pragma warning restore IDE0059 // TODO: This is stubbed in 2.0.0+, reverse 1.0.0 version for the sake of completeness. Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest }); @@ -56,10 +60,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres public ResultCode GetHostByNameRequest(ServiceCtx context) { ulong inputBufferPosition = context.Request.SendBuff[0].Position; - ulong inputBufferSize = context.Request.SendBuff[0].Size; + ulong inputBufferSize = context.Request.SendBuff[0].Size; ulong outputBufferPosition = context.Request.ReceiveBuff[0].Position; - ulong outputBufferSize = context.Request.ReceiveBuff[0].Size; + ulong outputBufferSize = context.Request.ReceiveBuff[0].Size; return GetHostByNameRequestImpl(context, inputBufferPosition, inputBufferSize, outputBufferPosition, outputBufferSize, false, 0, 0); } @@ -69,10 +73,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres public ResultCode GetHostByAddrRequest(ServiceCtx context) { ulong inputBufferPosition = context.Request.SendBuff[0].Position; - ulong inputBufferSize = context.Request.SendBuff[0].Size; + ulong inputBufferSize = context.Request.SendBuff[0].Size; ulong outputBufferPosition = context.Request.ReceiveBuff[0].Position; - ulong outputBufferSize = context.Request.ReceiveBuff[0].Size; + ulong outputBufferSize = context.Request.ReceiveBuff[0].Size; return GetHostByAddrRequestImpl(context, inputBufferPosition, inputBufferSize, outputBufferPosition, outputBufferSize, false, 0, 0); } @@ -82,20 +86,20 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres public ResultCode GetHostStringErrorRequest(ServiceCtx context) { ResultCode resultCode = ResultCode.NotAllocated; - NetDbError errorCode = (NetDbError)context.RequestData.ReadInt32(); + NetDbError errorCode = (NetDbError)context.RequestData.ReadInt32(); string errorString = errorCode switch { - NetDbError.Success => "Resolver Error 0 (no error)", + NetDbError.Success => "Resolver Error 0 (no error)", NetDbError.HostNotFound => "Unknown host", - NetDbError.TryAgain => "Host name lookup failure", - NetDbError.NoRecovery => "Unknown server error", - NetDbError.NoData => "No address associated with name", - _ => (errorCode <= NetDbError.Internal) ? "Resolver internal error" : "Unknown resolver error" + NetDbError.TryAgain => "Host name lookup failure", + NetDbError.NoRecovery => "Unknown server error", + NetDbError.NoData => "No address associated with name", + _ => (errorCode <= NetDbError.Internal) ? "Resolver internal error" : "Unknown resolver error", }; ulong bufferPosition = context.Request.ReceiveBuff[0].Position; - ulong bufferSize = context.Request.ReceiveBuff[0].Size; + ulong bufferSize = context.Request.ReceiveBuff[0].Size; if ((ulong)(errorString.Length + 1) <= bufferSize) { @@ -112,7 +116,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres public ResultCode GetGaiStringErrorRequest(ServiceCtx context) { ResultCode resultCode = ResultCode.NotAllocated; - GaiError errorCode = (GaiError)context.RequestData.ReadInt32(); + GaiError errorCode = (GaiError)context.RequestData.ReadInt32(); if (errorCode > GaiError.Max) { @@ -122,25 +126,25 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres string errorString = errorCode switch { GaiError.AddressFamily => "Address family for hostname not supported", - GaiError.Again => "Temporary failure in name resolution", - GaiError.BadFlags => "Invalid value for ai_flags", - GaiError.Fail => "Non-recoverable failure in name resolution", - GaiError.Family => "ai_family not supported", - GaiError.Memory => "Memory allocation failure", - GaiError.NoData => "No address associated with hostname", - GaiError.NoName => "hostname nor servname provided, or not known", - GaiError.Service => "servname not supported for ai_socktype", - GaiError.SocketType => "ai_socktype not supported", - GaiError.System => "System error returned in errno", - GaiError.BadHints => "Invalid value for hints", - GaiError.Protocol => "Resolved protocol is unknown", - GaiError.Overflow => "Argument buffer overflow", - GaiError.Max => "Unknown error", - _ => "Success" + GaiError.Again => "Temporary failure in name resolution", + GaiError.BadFlags => "Invalid value for ai_flags", + GaiError.Fail => "Non-recoverable failure in name resolution", + GaiError.Family => "ai_family not supported", + GaiError.Memory => "Memory allocation failure", + GaiError.NoData => "No address associated with hostname", + GaiError.NoName => "hostname nor servname provided, or not known", + GaiError.Service => "servname not supported for ai_socktype", + GaiError.SocketType => "ai_socktype not supported", + GaiError.System => "System error returned in errno", + GaiError.BadHints => "Invalid value for hints", + GaiError.Protocol => "Resolved protocol is unknown", + GaiError.Overflow => "Argument buffer overflow", + GaiError.Max => "Unknown error", + _ => "Success", }; ulong bufferPosition = context.Request.ReceiveBuff[0].Position; - ulong bufferSize = context.Request.ReceiveBuff[0].Size; + ulong bufferSize = context.Request.ReceiveBuff[0].Size; if ((ulong)(errorString.Length + 1) <= bufferSize) { @@ -157,7 +161,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres public ResultCode GetAddrInfoRequest(ServiceCtx context) { ulong responseBufferPosition = context.Request.ReceiveBuff[0].Position; - ulong responseBufferSize = context.Request.ReceiveBuff[0].Size; + ulong responseBufferSize = context.Request.ReceiveBuff[0].Size; return GetAddrInfoRequestImpl(context, responseBufferPosition, responseBufferSize, false, 0, 0); } @@ -166,8 +170,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres // GetCancelHandleRequest(u64, pid) -> u32 public ResultCode GetCancelHandleRequest(ServiceCtx context) { - ulong pidPlaceHolder = context.RequestData.ReadUInt64(); - uint cancelHandleRequest = 0; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong pidPlaceHolder = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 + uint cancelHandleRequest = 0; context.ResponseData.Write(cancelHandleRequest); @@ -180,8 +186,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres // CancelRequest(u32, u64, pid) public ResultCode CancelRequest(ServiceCtx context) { - uint cancelHandleRequest = context.RequestData.ReadUInt32(); - ulong pidPlaceHolder = context.RequestData.ReadUInt64(); + uint cancelHandleRequest = context.RequestData.ReadUInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong pidPlaceHolder = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest }); @@ -192,8 +200,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres // GetHostByNameRequestWithOptions(u8, u32, u64, pid, buffer, buffer) -> (u32, u32, u32, buffer) public ResultCode GetHostByNameRequestWithOptions(ServiceCtx context) { - (ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21(); - (ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22(); + (ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21(); + (ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22(); (ulong optionsBufferPosition, ulong optionsBufferSize) = context.Request.GetBufferType0x21(); return GetHostByNameRequestImpl( @@ -211,8 +219,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres // GetHostByAddrRequestWithOptions(u32, u32, u32, u64, pid, buffer, buffer) -> (u32, u32, u32, buffer) public ResultCode GetHostByAddrRequestWithOptions(ServiceCtx context) { - (ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21(); - (ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22(); + (ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21(); + (ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22(); (ulong optionsBufferPosition, ulong optionsBufferSize) = context.Request.GetBufferType0x21(); return GetHostByAddrRequestImpl( @@ -230,7 +238,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres // GetAddrInfoRequestWithOptions(bool enable_nsd_resolve, u32, u64 pid_placeholder, pid, buffer host, buffer service, buffer hints, buffer) -> (i32 ret, u32 bsd_errno, u32 unknown, u32 packed_addrinfo_size, buffer response) public ResultCode GetAddrInfoRequestWithOptions(ServiceCtx context) { - (ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22(); + (ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22(); (ulong optionsBufferPosition, ulong optionsBufferSize) = context.Request.GetBufferType0x21(); return GetAddrInfoRequestImpl(context, outputBufferPosition, outputBufferSize, true, optionsBufferPosition, optionsBufferSize); @@ -241,7 +249,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres public ResultCode ResolverSetOptionRequest(ServiceCtx context) { ulong bufferPosition = context.Request.SendBuff[0].Position; - ulong bufferSize = context.Request.SendBuff[0].Size; + ulong bufferSize = context.Request.SendBuff[0].Size; ulong unknown = context.RequestData.ReadUInt64(); @@ -254,7 +262,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { unknown }); NetDbError netDbErrorCode = NetDbError.Success; - GaiError errno = GaiError.Success; + GaiError errno = GaiError.Success; context.ResponseData.Write((int)errno); context.ResponseData.Write((int)netDbErrorCode); @@ -294,9 +302,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres } // TODO: Use params. - bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0; - int timeOut = context.RequestData.ReadInt32(); - ulong pidPlaceholder = context.RequestData.ReadUInt64(); + bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + int timeOut = context.RequestData.ReadInt32(); + ulong pidPlaceholder = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 if (withOptions) { @@ -306,8 +316,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres IPHostEntry hostEntry = null; NetDbError netDbErrorCode = NetDbError.Success; - GaiError errno = GaiError.Overflow; - int serializedSize = 0; + GaiError errno = GaiError.Overflow; + int serializedSize = 0; if (host.Length <= byte.MaxValue) { @@ -326,7 +336,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres Logger.Info?.Print(LogClass.ServiceSfdnsres, $"DNS Blocked: {host}"); netDbErrorCode = NetDbError.HostNotFound; - errno = GaiError.NoData; + errno = GaiError.NoData; } else { @@ -339,7 +349,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres catch (SocketException exception) { netDbErrorCode = ConvertSocketErrorCodeToNetDbError(exception.ErrorCode); - errno = ConvertSocketErrorCodeToGaiError(exception.ErrorCode, errno); + errno = ConvertSocketErrorCodeToGaiError(exception.ErrorCode, errno); } } } @@ -354,12 +364,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres if (!addresses.Any()) { - errno = GaiError.NoData; + errno = GaiError.NoData; netDbErrorCode = NetDbError.NoAddress; } else { - errno = GaiError.Success; + errno = GaiError.Success; serializedSize = SerializeHostEntries(context, outputBufferPosition, outputBufferSize, hostEntry, addresses); } } @@ -381,7 +391,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres { if (!context.Device.Configuration.EnableInternetAccess) { - Logger.Info?.Print(LogClass.ServiceSfdnsres, $"Guest network access disabled, DNS Blocked."); + Logger.Info?.Print(LogClass.ServiceSfdnsres, "Guest network access disabled, DNS Blocked."); WriteResponse(context, withOptions, 0, GaiError.NoData, NetDbError.HostNotFound); @@ -393,10 +403,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres context.Memory.Read(inputBufferPosition, rawIp); // TODO: Use params. - uint socketLength = context.RequestData.ReadUInt32(); - uint type = context.RequestData.ReadUInt32(); - int timeOut = context.RequestData.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + uint socketLength = context.RequestData.ReadUInt32(); + uint type = context.RequestData.ReadUInt32(); + int timeOut = context.RequestData.ReadInt32(); ulong pidPlaceholder = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 if (withOptions) { @@ -406,21 +418,21 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres IPHostEntry hostEntry = null; NetDbError netDbErrorCode = NetDbError.Success; - GaiError errno = GaiError.AddressFamily; - int serializedSize = 0; + GaiError errno = GaiError.AddressFamily; + int serializedSize = 0; if (rawIp.Length == 4) { try { - IPAddress address = new IPAddress(rawIp); + IPAddress address = new(rawIp); hostEntry = Dns.GetHostEntry(address); } catch (SocketException exception) { netDbErrorCode = ConvertSocketErrorCodeToNetDbError(exception.ErrorCode); - errno = ConvertSocketErrorCodeToGaiError(exception.ErrorCode, errno); + errno = ConvertSocketErrorCodeToGaiError(exception.ErrorCode, errno); } } else @@ -430,7 +442,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres if (hostEntry != null) { - errno = GaiError.Success; + errno = GaiError.Success; serializedSize = SerializeHostEntries(context, outputBufferPosition, outputBufferSize, hostEntry, GetIpv4Addresses(hostEntry)); } @@ -442,7 +454,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres private static int SerializeHostEntries(ServiceCtx context, ulong outputBufferPosition, ulong outputBufferSize, IPHostEntry hostEntry, IEnumerable addresses = null) { ulong originalBufferPosition = outputBufferPosition; - ulong bufferPosition = originalBufferPosition; + ulong bufferPosition = originalBufferPosition; string hostName = hostEntry.HostName + '\0'; @@ -494,9 +506,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres ulong optionsBufferSize) { bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0; - uint cancelHandle = context.RequestData.ReadUInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + uint cancelHandle = context.RequestData.ReadUInt32(); +#pragma warning restore IDE0059 - string host = MemoryHelper.ReadAsciiString(context.Memory, context.Request.SendBuff[0].Position, (long)context.Request.SendBuff[0].Size); + string host = MemoryHelper.ReadAsciiString(context.Memory, context.Request.SendBuff[0].Position, (long)context.Request.SendBuff[0].Size); string service = MemoryHelper.ReadAsciiString(context.Memory, context.Request.SendBuff[1].Position, (long)context.Request.SendBuff[1].Size); if (!context.Device.Configuration.EnableInternetAccess) @@ -509,21 +523,27 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres } // NOTE: We ignore hints for now. +#pragma warning disable IDE0059 // Remove unnecessary value assignment List hints = DeserializeAddrInfos(context.Memory, context.Request.SendBuff[2].Position, context.Request.SendBuff[2].Size); +#pragma warning restore IDE0059 if (withOptions) { // TODO: Find unknown, Parse and use options. +#pragma warning disable IDE0059 // Remove unnecessary value assignment uint unknown = context.RequestData.ReadUInt32(); +#pragma warning restore IDE0059 } +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong pidPlaceHolder = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 IPHostEntry hostEntry = null; NetDbError netDbErrorCode = NetDbError.Success; - GaiError errno = GaiError.AddressFamily; - int serializedSize = 0; + GaiError errno = GaiError.AddressFamily; + int serializedSize = 0; if (host.Length <= byte.MaxValue) { @@ -542,7 +562,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres Logger.Info?.Print(LogClass.ServiceSfdnsres, $"DNS Blocked: {host}"); netDbErrorCode = NetDbError.HostNotFound; - errno = GaiError.NoData; + errno = GaiError.NoData; } else { @@ -555,7 +575,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres catch (SocketException exception) { netDbErrorCode = ConvertSocketErrorCodeToNetDbError(exception.ErrorCode); - errno = ConvertSocketErrorCodeToGaiError(exception.ErrorCode, errno); + errno = ConvertSocketErrorCodeToGaiError(exception.ErrorCode, errno); } } } @@ -566,10 +586,15 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres if (hostEntry != null) { - int.TryParse(service, out int port); - - errno = GaiError.Success; - serializedSize = SerializeAddrInfos(context, responseBufferPosition, responseBufferSize, hostEntry, port); + if (int.TryParse(service, out int port)) + { + errno = GaiError.Success; + serializedSize = SerializeAddrInfos(context, responseBufferPosition, responseBufferSize, hostEntry, port); + } + else + { + errno = GaiError.Service; + } } WriteResponse(context, withOptions, serializedSize, errno, netDbErrorCode); @@ -601,37 +626,38 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres private static int SerializeAddrInfos(ServiceCtx context, ulong responseBufferPosition, ulong responseBufferSize, IPHostEntry hostEntry, int port) { ulong originalBufferPosition = responseBufferPosition; - ulong bufferPosition = originalBufferPosition; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong bufferPosition = originalBufferPosition; byte[] hostName = Encoding.ASCII.GetBytes(hostEntry.HostName + '\0'); +#pragma warning restore IDE0059 - using (WritableRegion region = context.Memory.GetWritableRegion(responseBufferPosition, (int)responseBufferSize)) + using WritableRegion region = context.Memory.GetWritableRegion(responseBufferPosition, (int)responseBufferSize); + + Span data = region.Memory.Span; + + for (int i = 0; i < hostEntry.AddressList.Length; i++) { - Span data = region.Memory.Span; + IPAddress ip = hostEntry.AddressList[i]; - for (int i = 0; i < hostEntry.AddressList.Length; i++) + if (ip.AddressFamily != AddressFamily.InterNetwork) { - IPAddress ip = hostEntry.AddressList[i]; - - if (ip.AddressFamily != AddressFamily.InterNetwork) - { - continue; - } - - // NOTE: 0 = Any - AddrInfoSerializedHeader header = new(ip, 0); - AddrInfo4 addr = new(ip, (short)port); - AddrInfoSerialized info = new(header, addr, null, hostEntry.HostName); - - data = info.Write(data); + continue; } - uint sentinel = 0; - MemoryMarshal.Write(data, ref sentinel); - data = data[sizeof(uint)..]; + // NOTE: 0 = Any + AddrInfoSerializedHeader header = new(ip, 0); + AddrInfo4 addr = new(ip, (short)port); + AddrInfoSerialized info = new(header, addr, null, hostEntry.HostName); - return region.Memory.Span.Length - data.Length; + data = info.Write(data); } + + uint sentinel = 0; + MemoryMarshal.Write(data, ref sentinel); + data = data[sizeof(uint)..]; + + return region.Memory.Span.Length - data.Length; } private static void WriteResponse( @@ -669,7 +695,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres 11002 => NetDbError.TryAgain, 11003 => NetDbError.NoRecovery, 11004 => NetDbError.NoData, - _ => NetDbError.Internal + _ => NetDbError.Internal, }; } @@ -679,8 +705,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres { 11001 => GaiError.NoData, 10060 => GaiError.Again, - _ => errno + _ => errno, }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsBlacklist.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsBlacklist.cs index 776a6f7cc..a2ccd190e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsBlacklist.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsBlacklist.cs @@ -19,18 +19,18 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Proxy [GeneratedRegex(@"^accounts\.nintendo\.com$", RegexOpts)] private static partial Regex BlockedHost6(); - private static readonly Regex[] BlockedHosts = { + private static readonly Regex[] _blockedHosts = { BlockedHost1(), BlockedHost2(), BlockedHost3(), BlockedHost4(), BlockedHost5(), - BlockedHost6() + BlockedHost6(), }; public static bool IsHostBlocked(string host) { - foreach (Regex regex in BlockedHosts) + foreach (Regex regex in _blockedHosts) { if (regex.IsMatch(host)) { @@ -41,4 +41,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Proxy return false; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs index 0e18c5705..d17a999dc 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs @@ -19,8 +19,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Proxy public void ReloadEntries(ServiceCtx context) { - string sdPath = context.Device.Configuration.VirtualFileSystem.GetSdCardPath(); - string filePath = context.Device.Configuration.VirtualFileSystem.GetFullPath(sdPath, HostsFilePath); + string sdPath = FileSystem.VirtualFileSystem.GetSdCardPath(); + string filePath = FileSystem.VirtualFileSystem.GetFullPath(sdPath, HostsFilePath); _mitmHostEntries.Clear(); @@ -94,7 +94,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Proxy { AddressList = new[] { hostEntry.Value }, HostName = hostEntry.Key, - Aliases = Array.Empty() + Aliases = Array.Empty(), }; } } @@ -103,4 +103,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Proxy return Dns.GetHostEntry(host); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfo4.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfo4.cs index 0a20e0572..68250022e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfo4.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfo4.cs @@ -10,17 +10,17 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x10)] struct AddrInfo4 { - public byte Length; - public byte Family; - public short Port; + public byte Length; + public byte Family; + public short Port; public Array4 Address; public Array8 Padding; public AddrInfo4(IPAddress address, short port) { - Length = (byte)Unsafe.SizeOf>(); - Family = (byte)AddressFamily.InterNetwork; - Port = IPAddress.HostToNetworkOrder(port); + Length = (byte)Unsafe.SizeOf>(); + Family = (byte)AddressFamily.InterNetwork; + Port = IPAddress.HostToNetworkOrder(port); Address = new Array4(); address.TryWriteBytes(Address.AsSpan(), out _); @@ -48,4 +48,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfoSerializedHeader.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfoSerializedHeader.cs index 8e304dfa4..9c50b1b86 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfoSerializedHeader.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfoSerializedHeader.cs @@ -10,19 +10,19 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types struct AddrInfoSerializedHeader { public uint Magic; - public int Flags; - public int Family; - public int SocketType; - public int Protocol; + public int Flags; + public int Family; + public int SocketType; + public int Protocol; public uint AddressLength; public AddrInfoSerializedHeader(IPAddress address, SocketType socketType) { - Magic = SfdnsresContants.AddrInfoMagic; - Flags = 0; - Family = (int)address.AddressFamily; + Magic = SfdnsresContants.AddrInfoMagic; + Flags = 0; + Family = (int)address.AddressFamily; SocketType = (int)socketType; - Protocol = 0; + Protocol = 0; if (address.AddressFamily == AddressFamily.InterNetwork) { @@ -36,22 +36,22 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types public void ToNetworkOrder() { - Magic = (uint)IPAddress.HostToNetworkOrder((int)Magic); - Flags = IPAddress.HostToNetworkOrder(Flags); - Family = IPAddress.HostToNetworkOrder(Family); - SocketType = IPAddress.HostToNetworkOrder(SocketType); - Protocol = IPAddress.HostToNetworkOrder(Protocol); + Magic = (uint)IPAddress.HostToNetworkOrder((int)Magic); + Flags = IPAddress.HostToNetworkOrder(Flags); + Family = IPAddress.HostToNetworkOrder(Family); + SocketType = IPAddress.HostToNetworkOrder(SocketType); + Protocol = IPAddress.HostToNetworkOrder(Protocol); AddressLength = (uint)IPAddress.HostToNetworkOrder((int)AddressLength); } public void ToHostOrder() { - Magic = (uint)IPAddress.NetworkToHostOrder((int)Magic); - Flags = IPAddress.NetworkToHostOrder(Flags); - Family = IPAddress.NetworkToHostOrder(Family); - SocketType = IPAddress.NetworkToHostOrder(SocketType); - Protocol = IPAddress.NetworkToHostOrder(Protocol); + Magic = (uint)IPAddress.NetworkToHostOrder((int)Magic); + Flags = IPAddress.NetworkToHostOrder(Flags); + Family = IPAddress.NetworkToHostOrder(Family); + SocketType = IPAddress.NetworkToHostOrder(SocketType); + Protocol = IPAddress.NetworkToHostOrder(Protocol); AddressLength = (uint)IPAddress.NetworkToHostOrder((int)AddressLength); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/GaiError.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/GaiError.cs index f9f28b44c..46682b3c8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/GaiError.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/GaiError.cs @@ -17,6 +17,6 @@ BadHints, Protocol, Overflow, - Max + Max, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/NetDBError.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/NetDBError.cs index 3c04c049a..0ded59603 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/NetDBError.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/NetDBError.cs @@ -8,6 +8,6 @@ TryAgain, NoRecovery, NoData, - NoAddress = NoData + NoAddress = NoData, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/SfdnsresContants.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/SfdnsresContants.cs index d194a3c66..7c51413cf 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/SfdnsresContants.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/SfdnsresContants.cs @@ -1,7 +1,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types { - static class SfdnsresContants + class SfdnsresContants { public const uint AddrInfoMagic = 0xBEEFCAFE; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/IGeneralInterface.cs b/src/Ryujinx.HLE/HOS/Services/Spl/IGeneralInterface.cs index aa350b734..951ed5301 100644 --- a/src/Ryujinx.HLE/HOS/Services/Spl/IGeneralInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Spl/IGeneralInterface.cs @@ -58,8 +58,10 @@ namespace Ryujinx.HLE.HOS.Services.Spl { configValue = default; - SystemVersion version = context.Device.System.ContentManager.GetCurrentFirmwareVersion(); - MemorySize memorySize = context.Device.Configuration.MemoryConfiguration.ToKernelMemorySize(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + SystemVersion version = context.Device.System.ContentManager.GetCurrentFirmwareVersion(); +#pragma warning restore IDE0059 + MemorySize memorySize = context.Device.Configuration.MemoryConfiguration.ToKernelMemorySize(); switch (configItem) { @@ -80,9 +82,9 @@ namespace Ryujinx.HLE.HOS.Services.Spl configValue = (ulong)DramId.IcosaSamsung4GiB; } break; - case ConfigItem.SecurityEngineInterruptNumber: + case ConfigItem.SecurityEngineInterruptNumber: return SmcResult.NotImplemented; - case ConfigItem.FuseVersion: + case ConfigItem.FuseVersion: return SmcResult.NotImplemented; case ConfigItem.HardwareType: configValue = (ulong)HardwareType.Icosa; @@ -93,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Services.Spl case ConfigItem.IsRecoveryBoot: configValue = 0; break; - case ConfigItem.DeviceId: + case ConfigItem.DeviceId: return SmcResult.NotImplemented; case ConfigItem.BootReason: // This was removed in firmware 4.0.0. @@ -123,4 +125,4 @@ namespace Ryujinx.HLE.HOS.Services.Spl return SmcResult.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/IRandomInterface.cs b/src/Ryujinx.HLE/HOS/Services/Spl/IRandomInterface.cs index db2241631..922fd34a6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Spl/IRandomInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Spl/IRandomInterface.cs @@ -5,9 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Spl [Service("csrng")] class IRandomInterface : DisposableIpcService { - private RandomNumberGenerator _rng; - - private readonly object _lock = new(); + private readonly RandomNumberGenerator _rng; public IRandomInterface(ServiceCtx context) { @@ -35,4 +33,4 @@ namespace Ryujinx.HLE.HOS.Services.Spl } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Spl/ResultCode.cs index 4f61998a6..fe77c753a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Spl/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Spl/ResultCode.cs @@ -2,11 +2,11 @@ namespace Ryujinx.HLE.HOS.Services.Spl { enum ResultCode { - ModuleId = 26, + ModuleId = 26, ErrorCodeShift = 9, Success = 0, - InvalidArguments = (101 << ErrorCodeShift) | ModuleId + InvalidArguments = (101 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/ConfigItem.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/ConfigItem.cs index f08bbeaa3..6822ad134 100644 --- a/src/Ryujinx.HLE/HOS/Services/Spl/Types/ConfigItem.cs +++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/ConfigItem.cs @@ -3,22 +3,22 @@ enum ConfigItem { // Standard config items. - DisableProgramVerification = 1, - DramId = 2, + DisableProgramVerification = 1, + DramId = 2, SecurityEngineInterruptNumber = 3, - FuseVersion = 4, - HardwareType = 5, - HardwareState = 6, - IsRecoveryBoot = 7, - DeviceId = 8, - BootReason = 9, - MemoryMode = 10, - IsDevelopmentFunctionEnabled = 11, - KernelConfiguration = 12, - IsChargerHiZModeEnabled = 13, - QuestState = 14, - RegulatorType = 15, - DeviceUniqueKeyGeneration = 16, - Package2Hash = 17 + FuseVersion = 4, + HardwareType = 5, + HardwareState = 6, + IsRecoveryBoot = 7, + DeviceId = 8, + BootReason = 9, + MemoryMode = 10, + IsDevelopmentFunctionEnabled = 11, + KernelConfiguration = 12, + IsChargerHiZModeEnabled = 13, + QuestState = 14, + RegulatorType = 15, + DeviceUniqueKeyGeneration = 16, + Package2Hash = 17, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/DramId.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/DramId.cs index 422c8d69f..05a465571 100644 --- a/src/Ryujinx.HLE/HOS/Services/Spl/Types/DramId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/DramId.cs @@ -30,6 +30,6 @@ IowaMicron1y4GiB, HoagMicron1y4GiB, AulaMicron1y4GiB, - AulaSamsung1y8GiBX + AulaSamsung1y8GiBX, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareState.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareState.cs index 414d0f118..8ab0ba9b0 100644 --- a/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareState.cs +++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareState.cs @@ -3,6 +3,6 @@ enum HardwareState { Development, - Production + Production, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareType.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareType.cs index 491eb943a..82d733308 100644 --- a/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareType.cs @@ -9,4 +9,4 @@ Calcio, Aula } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/SmcResult.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/SmcResult.cs index d5f424a63..ade0378c5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Spl/Types/SmcResult.cs +++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/SmcResult.cs @@ -2,19 +2,18 @@ { enum SmcResult { - Success = 0, - NotImplemented = 1, - InvalidArgument = 2, - Busy = 3, - NoAsyncOperation = 4, + Success = 0, + NotImplemented = 1, + InvalidArgument = 2, + Busy = 3, + NoAsyncOperation = 4, InvalidAsyncOperation = 5, - NotPermitted = 6, - NotInitialized = 7, + NotPermitted = 6, + NotInitialized = 7, - PsciSuccess = 0, - PsciNotSupported = -1, + PsciNotSupported = -1, PsciInvalidParameters = -2, - PsciDenied = -3, - PsciAlreadyOn = -4 + PsciDenied = -3, + PsciAlreadyOn = -4, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Srepo/ISrepoService.cs b/src/Ryujinx.HLE/HOS/Services/Srepo/ISrepoService.cs index 167dea677..f5467983a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Srepo/ISrepoService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Srepo/ISrepoService.cs @@ -6,4 +6,4 @@ { public ISrepoService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/BuiltInCertificateManager.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/BuiltInCertificateManager.cs index dae0698c3..e31092fda 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/BuiltInCertificateManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/BuiltInCertificateManager.cs @@ -23,7 +23,7 @@ namespace Ryujinx.HLE.HOS.Services.Ssl { private const long CertStoreTitleId = 0x0100000000000800; - private readonly string CertStoreTitleMissingErrorMessage = "CertStore system title not found! SSL CA retrieving will not work, provide the system archive to fix this error. (See https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide#initial-setup-continued---installation-of-firmware for more information)"; + private const string CertStoreTitleMissingErrorMessage = "CertStore system title not found! SSL CA retrieving will not work, provide the system archive to fix this error. (See https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide#initial-setup-continued---installation-of-firmware for more information)"; private static BuiltInCertificateManager _instance; @@ -31,10 +31,7 @@ namespace Ryujinx.HLE.HOS.Services.Ssl { get { - if (_instance == null) - { - _instance = new BuiltInCertificateManager(); - } + _instance ??= new BuiltInCertificateManager(); return _instance; } @@ -52,12 +49,12 @@ namespace Ryujinx.HLE.HOS.Services.Ssl { private const uint ValidMagic = 0x546C7373; -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public uint Magic; public uint EntriesCount; #pragma warning restore CS0649 - public bool IsValid() + public readonly bool IsValid() { return Magic == ValidMagic; } @@ -65,7 +62,7 @@ namespace Ryujinx.HLE.HOS.Services.Ssl private struct CertStoreFileEntry { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public CaCertificateId Id; public TrustedCertStatus Status; public uint DataSize; @@ -109,7 +106,7 @@ namespace Ryujinx.HLE.HOS.Services.Ssl { Id = entry.Id, Status = entry.Status, - Data = data + Data = data, }; } @@ -125,9 +122,9 @@ namespace Ryujinx.HLE.HOS.Services.Ssl if (HasCertStoreTitle()) { - using LocalStorage ncaFile = new LocalStorage(_virtualFileSystem.SwitchPathToSystemPath(GetCertStoreTitleContentPath()), FileAccess.Read, FileMode.Open); + using LocalStorage ncaFile = new(VirtualFileSystem.SwitchPathToSystemPath(GetCertStoreTitleContentPath()), FileAccess.Read, FileMode.Open); - Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile); + Nca nca = new(_virtualFileSystem.KeySet, ncaFile); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel); diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/ISslService.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/ISslService.cs index 7741ef7ed..5e4a0c53b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/ISslService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/ISslService.cs @@ -19,8 +19,10 @@ namespace Ryujinx.HLE.HOS.Services.Ssl // CreateContext(nn::ssl::sf::SslVersion, u64, pid) -> object public ResultCode CreateContext(ServiceCtx context) { - SslVersion sslVersion = (SslVersion)context.RequestData.ReadUInt32(); - ulong pidPlaceholder = context.RequestData.ReadUInt64(); + SslVersion sslVersion = (SslVersion)context.RequestData.ReadUInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong pidPlaceholder = context.RequestData.ReadUInt64(); +#pragma warning restore IDE0059 MakeObject(context, new ISslContext(context.Request.HandleDesc.PId, sslVersion)); @@ -71,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Ssl Id = entries[i].Id, Status = entries[i].Status, CertificateDataSize = (ulong)entries[i].Data.Length, - CertificateDataOffset = (ulong)(rawData.Length - certificatesData.Length) + CertificateDataOffset = (ulong)(rawData.Length - certificatesData.Length), }; certificatesData = certificatesData[entries[i].Data.Length..]; @@ -84,7 +86,7 @@ namespace Ryujinx.HLE.HOS.Services.Ssl Id = CaCertificateId.All, Status = TrustedCertStatus.Invalid, CertificateDataSize = 0, - CertificateDataOffset = 0 + CertificateDataOffset = 0, }; } } @@ -122,4 +124,4 @@ namespace Ryujinx.HLE.HOS.Services.Ssl return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/ResultCode.cs index 862c79cdc..6aae11feb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/ResultCode.cs @@ -2,19 +2,19 @@ { public enum ResultCode { - OsModuleId = 123, + OsModuleId = 123, ErrorCodeShift = 9, - Success = 0, - NoSocket = (103 << ErrorCodeShift) | OsModuleId, - InvalidSocket = (106 << ErrorCodeShift) | OsModuleId, + Success = 0, + NoSocket = (103 << ErrorCodeShift) | OsModuleId, + InvalidSocket = (106 << ErrorCodeShift) | OsModuleId, InvalidCertBufSize = (112 << ErrorCodeShift) | OsModuleId, - InvalidOption = (126 << ErrorCodeShift) | OsModuleId, + InvalidOption = (126 << ErrorCodeShift) | OsModuleId, CertBufferTooSmall = (202 << ErrorCodeShift) | OsModuleId, - AlreadyInUse = (203 << ErrorCodeShift) | OsModuleId, - WouldBlock = (204 << ErrorCodeShift) | OsModuleId, - Timeout = (205 << ErrorCodeShift) | OsModuleId, - ConnectionReset = (209 << ErrorCodeShift) | OsModuleId, - ConnectionAbort = (210 << ErrorCodeShift) | OsModuleId + AlreadyInUse = (203 << ErrorCodeShift) | OsModuleId, + WouldBlock = (204 << ErrorCodeShift) | OsModuleId, + Timeout = (205 << ErrorCodeShift) | OsModuleId, + ConnectionReset = (209 << ErrorCodeShift) | OsModuleId, + ConnectionAbort = (210 << ErrorCodeShift) | OsModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs index b9087f409..b5c608d3d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs @@ -15,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService private bool _skipDefaultVerify; private bool _enableAlpn; - private SslVersion _sslVersion; + private readonly SslVersion _sslVersion; private IoMode _ioMode; private VerifyOption _verifyOption; private SessionCacheMode _sessionCacheMode; @@ -206,13 +206,12 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService { if (_getServerCertChain) { - using (WritableRegion region = context.Memory.GetWritableRegion(context.Request.ReceiveBuff[0].Position, (int)context.Request.ReceiveBuff[0].Size)) - { - result = _connection.GetServerCertificate(_hostName, region.Memory.Span, out uint bufferSize, out uint certificateCount); + using WritableRegion region = context.Memory.GetWritableRegion(context.Request.ReceiveBuff[0].Position, (int)context.Request.ReceiveBuff[0].Size); - context.ResponseData.Write(bufferSize); - context.ResponseData.Write(certificateCount); - } + result = _connection.GetServerCertificate(_hostName, region.Memory.Span, out uint bufferSize, out uint certificateCount); + + context.ResponseData.Write(bufferSize); + context.ResponseData.Write(certificateCount); } else { @@ -235,15 +234,13 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService ResultCode result; - using (WritableRegion region = context.Memory.GetWritableRegion(context.Request.ReceiveBuff[0].Position, (int)context.Request.ReceiveBuff[0].Size)) - { - // TODO: Better error management. - result = _connection.Read(out int readCount, region.Memory); + using WritableRegion region = context.Memory.GetWritableRegion(context.Request.ReceiveBuff[0].Position, (int)context.Request.ReceiveBuff[0].Size); + // TODO: Better error management. + result = _connection.Read(out int readCount, region.Memory); - if (result == ResultCode.Success) - { - context.ResponseData.Write(readCount); - } + if (result == ResultCode.Success) + { + context.ResponseData.Write(readCount); } return result; @@ -297,15 +294,15 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService ResultCode result; - using (WritableRegion region = context.Memory.GetWritableRegion(context.Request.ReceiveBuff[0].Position, (int)context.Request.ReceiveBuff[0].Size)) - { - // TODO: Better error management. - result = _connection.Peek(out int peekCount, region.Memory); + using WritableRegion region = context.Memory.GetWritableRegion(context.Request.ReceiveBuff[0].Position, (int)context.Request.ReceiveBuff[0].Size); - if (result == ResultCode.Success) - { - context.ResponseData.Write(peekCount); - } + + // TODO: Better error management. + result = _connection.Peek(out int peekCount, region.Memory); + + if (result == ResultCode.Success) + { + context.ResponseData.Write(peekCount); } return result; @@ -381,7 +378,7 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService // SetOption(b8 value, nn::ssl::sf::OptionType option) public ResultCode SetOption(ServiceCtx context) { - bool value = context.RequestData.ReadUInt32() != 0; + bool value = context.RequestData.ReadUInt32() != 0; OptionType option = (OptionType)context.RequestData.ReadUInt32(); Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { option, value }); @@ -516,4 +513,4 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService _connection?.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnectionBase.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnectionBase.cs index 18e03e49d..500e2b896 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnectionBase.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnectionBase.cs @@ -3,7 +3,7 @@ using System; namespace Ryujinx.HLE.HOS.Services.Ssl.SslService { - interface ISslConnectionBase: IDisposable + interface ISslConnectionBase : IDisposable { int SocketFd { get; } diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs index b38ff9214..7b371d299 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs @@ -47,8 +47,10 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService { CertificateFormat certificateFormat = (CertificateFormat)context.RequestData.ReadUInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong certificateDataPosition = context.Request.SendBuff[0].Position; - ulong certificateDataSize = context.Request.SendBuff[0].Size; + ulong certificateDataSize = context.Request.SendBuff[0].Size; +#pragma warning restore IDE0059 context.ResponseData.Write(_serverCertificateId++); @@ -61,11 +63,13 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService // ImportClientPki(buffer certificate, buffer ascii_password) -> u64 certificateId public ResultCode ImportClientPki(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment ulong certificateDataPosition = context.Request.SendBuff[0].Position; - ulong certificateDataSize = context.Request.SendBuff[0].Size; + ulong certificateDataSize = context.Request.SendBuff[0].Size; +#pragma warning restore IDE0059 ulong asciiPasswordDataPosition = context.Request.SendBuff[1].Position; - ulong asciiPasswordDataSize = context.Request.SendBuff[1].Size; + ulong asciiPasswordDataSize = context.Request.SendBuff[1].Size; byte[] asciiPasswordData = new byte[asciiPasswordDataSize]; @@ -80,4 +84,4 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs index 47d3eddbe..dab099aab 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs @@ -15,8 +15,8 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService public ISocket Socket { get; } - private BsdContext _bsdContext; - private SslVersion _sslVersion; + private readonly BsdContext _bsdContext; + private readonly SslVersion _sslVersion; private SslStream _stream; private bool _isBlockingSocket; private int _previousReadTimeout; @@ -67,25 +67,19 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService EndSslOperation(); } -// NOTE: We silence warnings about TLS 1.0 and 1.1 as games will likely use it. + // NOTE: We silence warnings about TLS 1.0 and 1.1 as games will likely use it. #pragma warning disable SYSLIB0039 - private static SslProtocols TranslateSslVersion(SslVersion version) + private SslProtocols TranslateSslVersion(SslVersion version) { - switch (version & SslVersion.VersionMask) + return (version & SslVersion.VersionMask) switch { - case SslVersion.Auto: - return SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13; - case SslVersion.TlsV10: - return SslProtocols.Tls; - case SslVersion.TlsV11: - return SslProtocols.Tls11; - case SslVersion.TlsV12: - return SslProtocols.Tls12; - case SslVersion.TlsV13: - return SslProtocols.Tls13; - default: - throw new NotImplementedException(version.ToString()); - } + SslVersion.Auto => SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, + SslVersion.TlsV10 => SslProtocols.Tls, + SslVersion.TlsV11 => SslProtocols.Tls11, + SslVersion.TlsV12 => SslProtocols.Tls12, + SslVersion.TlsV13 => SslProtocols.Tls13, + _ => throw new NotImplementedException(version.ToString()), + }; } #pragma warning restore SYSLIB0039 @@ -114,7 +108,7 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService return 0; } - private static bool TryTranslateWinSockError(bool isBlocking, WsaError error, out ResultCode resultCode) + private bool TryTranslateWinSockError(bool isBlocking, WsaError error, out ResultCode resultCode) { switch (error) { diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/CaCertificateId.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/CaCertificateId.cs index 5c84579a7..a351ce545 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/CaCertificateId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/CaCertificateId.cs @@ -63,6 +63,6 @@ GTSRootR4, SecurityCommunicationRootCA, - All = uint.MaxValue + All = uint.MaxValue, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/CertificateFormat.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/CertificateFormat.cs index 1d80f739e..35842e85b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/CertificateFormat.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/CertificateFormat.cs @@ -3,6 +3,6 @@ enum CertificateFormat : uint { Pem = 1, - Der = 2 + Der = 2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/IoMode.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/IoMode.cs index 1cd06d6de..c8b3889c5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/IoMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/IoMode.cs @@ -2,7 +2,7 @@ { enum IoMode : uint { - Blocking = 1, - NonBlocking = 2 + Blocking = 1, + NonBlocking = 2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/OptionType.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/OptionType.cs index 3673200a4..85a813dca 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/OptionType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/OptionType.cs @@ -5,6 +5,6 @@ DoNotCloseSocket, GetServerCertChain, // 3.0.0+ SkipDefaultVerify, // 5.0.0+ - EnableAlpn // 9.0.0+ + EnableAlpn, // 9.0.0+ } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/SessionCacheMode.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/SessionCacheMode.cs index cec7b745e..b9c739376 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/SessionCacheMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/SessionCacheMode.cs @@ -4,6 +4,6 @@ { None, SessionId, - SessionTicket + SessionTicket, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/SslVersion.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/SslVersion.cs index 7110fd852..7026596e5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/SslVersion.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/SslVersion.cs @@ -5,12 +5,12 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.Types [Flags] enum SslVersion : uint { - Auto = 1 << 0, + Auto = 1 << 0, TlsV10 = 1 << 3, TlsV11 = 1 << 4, TlsV12 = 1 << 5, TlsV13 = 1 << 6, // 11.0.0+ - VersionMask = 0xFFFFFF + VersionMask = 0xFFFFFF, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/TrustedCertStatus.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/TrustedCertStatus.cs index 7fd5efd62..e9d348c12 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/TrustedCertStatus.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/TrustedCertStatus.cs @@ -7,6 +7,6 @@ EnabledNotTrusted, Revoked, - Invalid = uint.MaxValue + Invalid = uint.MaxValue, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/VerifyOption.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/VerifyOption.cs index d25bb6c34..1c13e80f3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/Types/VerifyOption.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/Types/VerifyOption.cs @@ -5,11 +5,11 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.Types [Flags] enum VerifyOption : uint { - PeerCa = 1 << 0, - HostName = 1 << 1, - DateCheck = 1 << 2, - EvCertPartial = 1 << 3, - EvPolicyOid = 1 << 4, // 6.0.0+ - EvCertFingerprint = 1 << 5 // 6.0.0+ + PeerCa = 1 << 0, + HostName = 1 << 1, + DateCheck = 1 << 2, + EvCertPartial = 1 << 3, + EvPolicyOid = 1 << 4, // 6.0.0+ + EvCertFingerprint = 1 << 5, // 6.0.0+ } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferItemConsumer.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferItemConsumer.cs index 3b33bf8bc..265962106 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferItemConsumer.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferItemConsumer.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { class BufferItemConsumer : ConsumerBase { - private GpuContext _gpuContext; + private readonly GpuContext _gpuContext; public BufferItemConsumer(Switch device, BufferQueueConsumer consumer, diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueue.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueue.cs index bc0901ab2..347eb8fba 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueue.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueue.cs @@ -4,7 +4,7 @@ { public static BufferQueueCore CreateBufferQueue(Switch device, ulong pid, out BufferQueueProducer producer, out BufferQueueConsumer consumer) { - BufferQueueCore core = new BufferQueueCore(device, pid); + BufferQueueCore core = new(device, pid); producer = new BufferQueueProducer(core, device.System.TickSource); consumer = new BufferQueueConsumer(core); diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueConsumer.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueConsumer.cs index c9bb0a655..4cd45d691 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueConsumer.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueConsumer.cs @@ -54,10 +54,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger if (Core.StillTracking(ref bufferItem)) { - Core.Slots[bufferItem.Slot].AcquireCalled = true; + Core.Slots[bufferItem.Slot].AcquireCalled = true; Core.Slots[bufferItem.Slot].NeedsCleanupOnRelease = true; - Core.Slots[bufferItem.Slot].BufferState = BufferState.Acquired; - Core.Slots[bufferItem.Slot].Fence = AndroidFence.NoFence; + Core.Slots[bufferItem.Slot].BufferState = BufferState.Acquired; + Core.Slots[bufferItem.Slot].Fence = AndroidFence.NoFence; ulong targetFrameNumber = Core.Slots[bufferItem.Slot].FrameNumber; @@ -159,12 +159,12 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger Core.Slots[slot].GraphicBuffer.Set(graphicBuffer); - Core.Slots[slot].BufferState = BufferState.Acquired; - Core.Slots[slot].AttachedByConsumer = true; + Core.Slots[slot].BufferState = BufferState.Acquired; + Core.Slots[slot].AttachedByConsumer = true; Core.Slots[slot].NeedsCleanupOnRelease = false; - Core.Slots[slot].Fence = AndroidFence.NoFence; - Core.Slots[slot].FrameNumber = 0; - Core.Slots[slot].AcquireCalled = false; + Core.Slots[slot].Fence = AndroidFence.NoFence; + Core.Slots[slot].FrameNumber = 0; + Core.Slots[slot].AcquireCalled = false; } return Status.Success; @@ -197,7 +197,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger if (Core.Slots[slot].BufferState == BufferState.Acquired) { Core.Slots[slot].BufferState = BufferState.Free; - Core.Slots[slot].Fence = fence; + Core.Slots[slot].Fence = fence; listener = Core.ProducerListener; } @@ -237,7 +237,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger return Status.NoInit; } - Core.ConsumerListener = consumerListener; + Core.ConsumerListener = consumerListener; Core.ConsumerControlledByApp = controlledByApp; } @@ -253,7 +253,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger return Status.BadValue; } - Core.IsAbandoned = true; + Core.IsAbandoned = true; Core.ConsumerListener = null; Core.Queue.Clear(); @@ -304,7 +304,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger lock (Core.Lock) { - Core.DefaultWidth = (int)width; + Core.DefaultWidth = (int)width; Core.DefaultHeight = (int)height; } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueCore.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueCore.cs index 8cf55912e..f1d2f84b5 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueCore.cs @@ -9,35 +9,35 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { class BufferQueueCore { - public BufferSlotArray Slots; - public int OverrideMaxBufferCount; - public bool UseAsyncBuffer; - public bool DequeueBufferCannotBlock; - public PixelFormat DefaultBufferFormat; - public int DefaultWidth; - public int DefaultHeight; - public int DefaultMaxBufferCount; - public int MaxAcquiredBufferCount; - public bool BufferHasBeenQueued; - public ulong FrameCounter; + public BufferSlotArray Slots; + public int OverrideMaxBufferCount; + public bool UseAsyncBuffer; + public bool DequeueBufferCannotBlock; + public PixelFormat DefaultBufferFormat; + public int DefaultWidth; + public int DefaultHeight; + public int DefaultMaxBufferCount; + public int MaxAcquiredBufferCount; + public bool BufferHasBeenQueued; + public ulong FrameCounter; public NativeWindowTransform TransformHint; - public bool IsAbandoned; - public NativeWindowApi ConnectedApi; - public bool IsAllocating; - public IProducerListener ProducerListener; - public IConsumerListener ConsumerListener; - public bool ConsumerControlledByApp; - public uint ConsumerUsageBits; - public List Queue; - public BufferInfo[] BufferHistory; - public uint BufferHistoryPosition; - public bool EnableExternalEvent; - public int MaxBufferCountCached; + public bool IsAbandoned; + public NativeWindowApi ConnectedApi; + public bool IsAllocating; + public IProducerListener ProducerListener; + public IConsumerListener ConsumerListener; + public bool ConsumerControlledByApp; + public uint ConsumerUsageBits; + public List Queue; + public BufferInfo[] BufferHistory; + public uint BufferHistoryPosition; + public bool EnableExternalEvent; + public int MaxBufferCountCached; public readonly object Lock = new(); - private KEvent _waitBufferFreeEvent; - private KEvent _frameAvailableEvent; + private readonly KEvent _waitBufferFreeEvent; + private readonly KEvent _frameAvailableEvent; public ulong Owner { get; } @@ -49,36 +49,36 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public BufferQueueCore(Switch device, ulong pid) { - Slots = new BufferSlotArray(); - IsAbandoned = false; - OverrideMaxBufferCount = 0; + Slots = new BufferSlotArray(); + IsAbandoned = false; + OverrideMaxBufferCount = 0; DequeueBufferCannotBlock = false; - UseAsyncBuffer = false; - DefaultWidth = 1; - DefaultHeight = 1; - DefaultMaxBufferCount = 2; - MaxAcquiredBufferCount = 1; - FrameCounter = 0; - TransformHint = 0; - DefaultBufferFormat = PixelFormat.Rgba8888; - IsAllocating = false; - ProducerListener = null; - ConsumerListener = null; - ConsumerUsageBits = 0; + UseAsyncBuffer = false; + DefaultWidth = 1; + DefaultHeight = 1; + DefaultMaxBufferCount = 2; + MaxAcquiredBufferCount = 1; + FrameCounter = 0; + TransformHint = 0; + DefaultBufferFormat = PixelFormat.Rgba8888; + IsAllocating = false; + ProducerListener = null; + ConsumerListener = null; + ConsumerUsageBits = 0; Queue = new List(); // TODO: CreateGraphicBufferAlloc? - _waitBufferFreeEvent = new KEvent(device.System.KernelContext); + _waitBufferFreeEvent = new KEvent(device.System.KernelContext); _frameAvailableEvent = new KEvent(device.System.KernelContext); Owner = pid; Active = true; - BufferHistory = new BufferInfo[BufferHistoryArraySize]; - EnableExternalEvent = true; + BufferHistory = new BufferInfo[BufferHistoryArraySize]; + EnableExternalEvent = true; MaxBufferCountCached = 0; } @@ -220,9 +220,9 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger Slots[slot].NeedsCleanupOnRelease = true; } - Slots[slot].BufferState = BufferState.Free; - Slots[slot].FrameNumber = uint.MaxValue; - Slots[slot].AcquireCalled = false; + Slots[slot].BufferState = BufferState.Free; + Slots[slot].FrameNumber = uint.MaxValue; + Slots[slot].AcquireCalled = false; Slots[slot].Fence.FenceCount = 0; } @@ -259,7 +259,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger return; } - bool needBufferReleaseSignal = false; + bool needBufferReleaseSignal = false; bool needFrameAvailableSignal = false; if (maxBufferCount > 1) diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueProducer.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueProducer.cs index fa840f2ad..887d1861f 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueProducer.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueProducer.cs @@ -15,7 +15,9 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger private readonly ITickSource _tickSource; +#pragma warning disable IDE0052 // Remove unread private member private uint _stickyTransform; +#pragma warning restore IDE0052 private uint _nextCallbackTicket; private uint _currentCallbackTicket; @@ -28,9 +30,9 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger Core = core; _tickSource = tickSource; - _stickyTransform = 0; - _callbackTicket = 0; - _nextCallbackTicket = 0; + _stickyTransform = 0; + _callbackTicket = 0; + _nextCallbackTicket = 0; _currentCallbackTicket = 0; } @@ -134,7 +136,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { if ((width == 0 && height != 0) || (height == 0 && width != 0)) { - slot = BufferSlotArray.InvalidBufferSlot; + slot = BufferSlotArray.InvalidBufferSlot; fence = AndroidFence.NoFence; return Status.BadValue; @@ -157,7 +159,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger if (status != Status.Success) { - slot = BufferSlotArray.InvalidBufferSlot; + slot = BufferSlotArray.InvalidBufferSlot; fence = AndroidFence.NoFence; return status; @@ -176,7 +178,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger if (width == 0 || height == 0) { - width = (uint)Core.DefaultWidth; + width = (uint)Core.DefaultWidth; height = (uint)Core.DefaultHeight; } @@ -190,7 +192,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { if (!Core.Slots[slot].IsPreallocated) { - slot = BufferSlotArray.InvalidBufferSlot; + slot = BufferSlotArray.InvalidBufferSlot; fence = AndroidFence.NoFence; return Status.NoMemory; @@ -202,7 +204,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger $"available: Width = {graphicBuffer.Width} Height = {graphicBuffer.Height} Format = {graphicBuffer.Format} Usage = {graphicBuffer.Usage:x} " + $"requested: Width = {width} Height = {height} Format = {format} Usage = {usage:x}"); - slot = BufferSlotArray.InvalidBufferSlot; + slot = BufferSlotArray.InvalidBufferSlot; fence = AndroidFence.NoFence; return Status.NoInit; @@ -215,8 +217,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger fence = Core.Slots[slot].Fence; - Core.Slots[slot].Fence = AndroidFence.NoFence; - Core.Slots[slot].QueueTime = TimeSpanType.Zero; + Core.Slots[slot].Fence = AndroidFence.NoFence; + Core.Slots[slot].QueueTime = TimeSpanType.Zero; Core.Slots[slot].PresentationTime = TimeSpanType.Zero; Core.CheckSystemEventsLocked(Core.GetMaxBufferCountLocked(async)); @@ -267,7 +269,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger if (Core.IsAbandoned) { graphicBuffer = default; - fence = AndroidFence.NoFence; + fence = AndroidFence.NoFence; return Status.NoInit; } @@ -288,13 +290,13 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger if (nextBufferSlot == BufferSlotArray.InvalidBufferSlot) { graphicBuffer = default; - fence = AndroidFence.NoFence; + fence = AndroidFence.NoFence; return Status.NoMemory; } graphicBuffer = Core.Slots[nextBufferSlot].GraphicBuffer; - fence = Core.Slots[nextBufferSlot].Fence; + fence = Core.Slots[nextBufferSlot].Fence; Core.FreeBufferLocked(nextBufferSlot); @@ -326,8 +328,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger Core.Slots[slot].GraphicBuffer.Set(graphicBuffer); - Core.Slots[slot].BufferState = BufferState.Dequeued; - Core.Slots[slot].Fence = AndroidFence.NoFence; + Core.Slots[slot].BufferState = BufferState.Dequeued; + Core.Slots[slot].Fence = AndroidFence.NoFence; Core.Slots[slot].RequestBufferCalled = true; return returnFlags; @@ -350,10 +352,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger return Status.BadValue; } - BufferItem item = new BufferItem(); + BufferItem item = new(); IConsumerListener frameAvailableListener = null; - IConsumerListener frameReplaceListener = null; + IConsumerListener frameReplaceListener = null; lock (Core.Lock) { @@ -388,25 +390,25 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger return Status.BadValue; } - Core.Slots[slot].Fence = input.Fence; + Core.Slots[slot].Fence = input.Fence; Core.Slots[slot].BufferState = BufferState.Queued; Core.FrameCounter++; - Core.Slots[slot].FrameNumber = Core.FrameCounter; - Core.Slots[slot].QueueTime = TimeSpanType.FromTimeSpan(_tickSource.ElapsedTime); + Core.Slots[slot].FrameNumber = Core.FrameCounter; + Core.Slots[slot].QueueTime = TimeSpanType.FromTimeSpan(_tickSource.ElapsedTime); Core.Slots[slot].PresentationTime = TimeSpanType.Zero; - item.AcquireCalled = Core.Slots[slot].AcquireCalled; - item.Crop = input.Crop; - item.Transform = input.Transform; + item.AcquireCalled = Core.Slots[slot].AcquireCalled; + item.Crop = input.Crop; + item.Transform = input.Transform; item.TransformToDisplayInverse = (input.Transform & NativeWindowTransform.InverseDisplay) == NativeWindowTransform.InverseDisplay; - item.ScalingMode = input.ScalingMode; - item.Timestamp = input.Timestamp; - item.IsAutoTimestamp = input.IsAutoTimestamp != 0; - item.SwapInterval = input.SwapInterval; - item.FrameNumber = Core.FrameCounter; - item.Slot = slot; - item.Fence = input.Fence; - item.IsDroppable = Core.DequeueBufferCannotBlock || input.Async != 0; + item.ScalingMode = input.ScalingMode; + item.Timestamp = input.Timestamp; + item.IsAutoTimestamp = input.IsAutoTimestamp != 0; + item.SwapInterval = input.SwapInterval; + item.FrameNumber = Core.FrameCounter; + item.Slot = slot; + item.Fence = input.Fence; + item.IsDroppable = Core.DequeueBufferCannotBlock || input.Async != 0; item.GraphicBuffer.Set(Core.Slots[slot].GraphicBuffer); item.GraphicBuffer.Object.IncrementNvMapHandleRefCount(Core.Owner); @@ -416,8 +418,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger Core.BufferHistory[Core.BufferHistoryPosition] = new BufferInfo { FrameNumber = Core.FrameCounter, - QueueTime = Core.Slots[slot].QueueTime, - State = BufferState.Queued + QueueTime = Core.Slots[slot].QueueTime, + State = BufferState.Queued, }; _stickyTransform = input.StickyTransform; @@ -460,10 +462,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger output = new QueueBufferOutput { - Width = (uint)Core.DefaultWidth, - Height = (uint)Core.DefaultHeight, - TransformHint = Core.TransformHint, - NumPendingBuffers = (uint)Core.Queue.Count + Width = (uint)Core.DefaultWidth, + Height = (uint)Core.DefaultHeight, + TransformHint = Core.TransformHint, + NumPendingBuffers = (uint)Core.Queue.Count, }; if ((input.StickyTransform & 8) != 0) @@ -506,7 +508,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger Core.Slots[slot].BufferState = BufferState.Free; Core.Slots[slot].FrameNumber = 0; - Core.Slots[slot].Fence = fence; + Core.Slots[slot].Fence = fence; Core.SignalDequeueEvent(); Core.SignalWaitBufferFreeEvent(); } @@ -568,7 +570,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger return Status.BadValue; } - Core.BufferHasBeenQueued = false; + Core.BufferHasBeenQueued = false; Core.DequeueBufferCannotBlock = Core.ConsumerControlledByApp && producerControlledByApp; switch (api) @@ -578,11 +580,11 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger case NativeWindowApi.Media: case NativeWindowApi.Camera: Core.ProducerListener = listener; - Core.ConnectedApi = api; + Core.ConnectedApi = api; - output.Width = (uint)Core.DefaultWidth; - output.Height = (uint)Core.DefaultHeight; - output.TransformHint = Core.TransformHint; + output.Width = (uint)Core.DefaultWidth; + output.Height = (uint)Core.DefaultHeight; + output.TransformHint = Core.TransformHint; output.NumPendingBuffers = (uint)Core.Queue.Count; if (NxSettings.Settings.TryGetValue("nv!nvn_no_vsync_capability", out object noVSyncCapability) && (bool)noVSyncCapability) @@ -627,7 +629,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger producerListener = Core.ProducerListener; Core.ProducerListener = null; - Core.ConnectedApi = NativeWindowApi.NoApi; + Core.ConnectedApi = NativeWindowApi.NoApi; Core.SignalWaitBufferFreeEvent(); Core.SignalFrameAvailableEvent(); @@ -667,13 +669,13 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger lock (Core.Lock) { - Core.Slots[slot].BufferState = BufferState.Free; - Core.Slots[slot].Fence = AndroidFence.NoFence; - Core.Slots[slot].RequestBufferCalled = false; - Core.Slots[slot].AcquireCalled = false; + Core.Slots[slot].BufferState = BufferState.Free; + Core.Slots[slot].Fence = AndroidFence.NoFence; + Core.Slots[slot].RequestBufferCalled = false; + Core.Slots[slot].AcquireCalled = false; Core.Slots[slot].NeedsCleanupOnRelease = false; - Core.Slots[slot].IsPreallocated = !graphicBuffer.IsNull; - Core.Slots[slot].FrameNumber = 0; + Core.Slots[slot].IsPreallocated = !graphicBuffer.IsNull; + Core.Slots[slot].FrameNumber = 0; Core.Slots[slot].GraphicBuffer.Set(graphicBuffer); @@ -689,8 +691,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { // NOTE: Nintendo set the default width, height and format from the GraphicBuffer.. // This is entirely wrong and should only be controlled by the consumer... - Core.DefaultWidth = graphicBuffer.Object.Width; - Core.DefaultHeight = graphicBuffer.Object.Height; + Core.DefaultWidth = graphicBuffer.Object.Width; + Core.DefaultHeight = graphicBuffer.Object.Height; Core.DefaultBufferFormat = graphicBuffer.Object.Format; } else @@ -729,7 +731,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { bool tryAgain = true; - freeSlot = BufferSlotArray.InvalidBufferSlot; + freeSlot = BufferSlotArray.InvalidBufferSlot; returnStatus = Status.Success; while (tryAgain) diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferSlot.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferSlot.cs index fb84934a2..4632053df 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferSlot.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferSlot.cs @@ -6,24 +6,24 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger class BufferSlot { public AndroidStrongPointer GraphicBuffer; - public BufferState BufferState; - public bool RequestBufferCalled; - public ulong FrameNumber; - public AndroidFence Fence; - public bool AcquireCalled; - public bool NeedsCleanupOnRelease; - public bool AttachedByConsumer; - public TimeSpanType QueueTime; - public TimeSpanType PresentationTime; - public bool IsPreallocated; + public BufferState BufferState; + public bool RequestBufferCalled; + public ulong FrameNumber; + public AndroidFence Fence; + public bool AcquireCalled; + public bool NeedsCleanupOnRelease; + public bool AttachedByConsumer; + public TimeSpanType QueueTime; + public TimeSpanType PresentationTime; + public bool IsPreallocated; public BufferSlot() { - GraphicBuffer = new AndroidStrongPointer(); - BufferState = BufferState.Free; - QueueTime = TimeSpanType.Zero; + GraphicBuffer = new AndroidStrongPointer(); + BufferState = BufferState.Free; + QueueTime = TimeSpanType.Zero; PresentationTime = TimeSpanType.Zero; - IsPreallocated = false; + IsPreallocated = false; } } } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferSlotArray.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferSlotArray.cs index d2404c587..5a6604f14 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferSlotArray.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferSlotArray.cs @@ -3,11 +3,11 @@ class BufferSlotArray { // TODO: move to BufferQueue - public const int NumBufferSlots = 0x40; + public const int NumBufferSlots = 0x40; public const int MaxAcquiredBuffers = NumBufferSlots - 2; - public const int InvalidBufferSlot = -1; + public const int InvalidBufferSlot = -1; - private BufferSlot[] _raw = new BufferSlot[NumBufferSlots]; + private readonly BufferSlot[] _raw = new BufferSlot[NumBufferSlots]; public BufferSlotArray() { diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/ConsumerBase.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/ConsumerBase.cs index 754fa7d73..d63019972 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/ConsumerBase.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/ConsumerBase.cs @@ -8,8 +8,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public class Slot { public AndroidStrongPointer GraphicBuffer; - public AndroidFence Fence; - public ulong FrameNumber; + public AndroidFence Fence; + public ulong FrameNumber; public Slot() { @@ -25,7 +25,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger protected readonly object Lock = new(); - private IConsumerListener _listener; + private readonly IConsumerListener _listener; public ConsumerBase(BufferQueueConsumer consumer, bool controlledByApp, IConsumerListener listener) { @@ -35,8 +35,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger } IsAbandoned = false; - Consumer = consumer; - _listener = listener; + Consumer = consumer; + _listener = listener; Status connectStatus = consumer.Connect(this, controlledByApp); @@ -81,7 +81,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { Slots[slotIndex].GraphicBuffer.Reset(); - Slots[slotIndex].Fence = AndroidFence.NoFence; + Slots[slotIndex].Fence = AndroidFence.NoFence; Slots[slotIndex].FrameNumber = 0; } @@ -123,7 +123,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger } Slots[bufferItem.Slot].FrameNumber = bufferItem.FrameNumber; - Slots[bufferItem.Slot].Fence = bufferItem.Fence; + Slots[bufferItem.Slot].Fence = bufferItem.Fence; return Status.Success; } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/HOSBinderDriverServer.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/HOSBinderDriverServer.cs index d6c98be1a..f89eaeeb6 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/HOSBinderDriverServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/HOSBinderDriverServer.cs @@ -7,11 +7,11 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { class HOSBinderDriverServer : IHOSBinderDriver { - private static Dictionary _registeredBinderObjects = new Dictionary(); + private static readonly Dictionary _registeredBinderObjects = new(); private static int _lastBinderId = 0; - private static object _lock = new object(); + private static readonly object _lock = new(); public static int RegisterBinderObject(IBinder binder) { diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IBinder.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IBinder.cs index 9003201ba..9690cd4a1 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IBinder.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IBinder.cs @@ -13,10 +13,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger ResultCode OnTransact(uint code, uint flags, ReadOnlySpan inputParcel, Span outputParcel) { - Parcel inputParcelReader = new Parcel(inputParcel.ToArray()); + Parcel inputParcelReader = new(inputParcel.ToArray()); // TODO: support objects? - Parcel outputParcelWriter = new Parcel((uint)(outputParcel.Length - Unsafe.SizeOf()), 0); + Parcel outputParcelWriter = new((uint)(outputParcel.Length - Unsafe.SizeOf()), 0); string inputInterfaceToken = inputParcelReader.ReadInterfaceToken(); diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IGraphicBufferProducer.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IGraphicBufferProducer.cs index f0b393a02..a70f7fe39 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IGraphicBufferProducer.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IGraphicBufferProducer.cs @@ -29,33 +29,33 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger SetPreallocatedBuffer, Reserved15, GetBufferInfo, - GetBufferHistory + GetBufferHistory, } [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x54)] public struct QueueBufferInput : IFlattenable { - public long Timestamp; - public int IsAutoTimestamp; - public Rect Crop; + public long Timestamp; + public int IsAutoTimestamp; + public Rect Crop; public NativeWindowScalingMode ScalingMode; - public NativeWindowTransform Transform; - public uint StickyTransform; - public int Async; - public int SwapInterval; - public AndroidFence Fence; + public NativeWindowTransform Transform; + public uint StickyTransform; + public int Async; + public int SwapInterval; + public AndroidFence Fence; public void Flatten(Parcel parcel) { parcel.WriteUnmanagedType(ref this); } - public uint GetFdCount() + public readonly uint GetFdCount() { return 0; } - public uint GetFlattenedSize() + public readonly uint GetFlattenedSize() { return (uint)Unsafe.SizeOf(); } @@ -68,11 +68,11 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public struct QueueBufferOutput { - public uint Width; - public uint Height; + public uint Width; + public uint Height; public NativeWindowTransform TransformHint; - public uint NumPendingBuffers; - public ulong FrameNumber; + public uint NumPendingBuffers; + public ulong FrameNumber; public void WriteToParcel(Parcel parcel) { @@ -108,15 +108,15 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public void OnTransact(uint code, uint flags, Parcel inputParcel, Parcel outputParcel) { - Status status = Status.Success; - int slot; - AndroidFence fence; - QueueBufferInput queueInput; + Status status = Status.Success; + int slot; + AndroidFence fence; + QueueBufferInput queueInput; QueueBufferOutput queueOutput; - NativeWindowApi api; + NativeWindowApi api; AndroidStrongPointer graphicBuffer; - AndroidStrongPointer strongFence; + AndroidStrongPointer strongFence; switch ((TransactionCode)code) { @@ -139,13 +139,13 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger break; case TransactionCode.DequeueBuffer: - bool async = inputParcel.ReadBoolean(); - uint width = inputParcel.ReadUInt32(); - uint height = inputParcel.ReadUInt32(); + bool async = inputParcel.ReadBoolean(); + uint width = inputParcel.ReadUInt32(); + uint height = inputParcel.ReadUInt32(); PixelFormat format = inputParcel.ReadUnmanagedType(); - uint usage = inputParcel.ReadUInt32(); + uint usage = inputParcel.ReadUInt32(); - status = DequeueBuffer(out int dequeueSlot, out fence, async, width, height, format, usage); + status = DequeueBuffer(out int dequeueSlot, out fence, async, width, height, format, usage); strongFence = new AndroidStrongPointer(fence); outputParcel.WriteInt32(dequeueSlot); @@ -163,7 +163,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger break; case TransactionCode.DetachNextBuffer: - status = DetachNextBuffer(out graphicBuffer, out fence); + status = DetachNextBuffer(out graphicBuffer, out fence); strongFence = new AndroidStrongPointer(fence); outputParcel.WriteStrongPointer(ref graphicBuffer); @@ -183,7 +183,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger break; case TransactionCode.QueueBuffer: - slot = inputParcel.ReadInt32(); + slot = inputParcel.ReadInt32(); queueInput = inputParcel.ReadFlattenable(); status = QueueBuffer(slot, ref queueInput, out queueOutput); @@ -194,7 +194,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger break; case TransactionCode.CancelBuffer: - slot = inputParcel.ReadInt32(); + slot = inputParcel.ReadInt32(); fence = inputParcel.ReadFlattenable(); CancelBuffer(slot, ref fence); diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IHOSBinderDriver.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IHOSBinderDriver.cs index 2f9f42914..3d44e23dc 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IHOSBinderDriver.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/IHOSBinderDriver.cs @@ -17,18 +17,18 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { int binderId = context.RequestData.ReadInt32(); - uint code = context.RequestData.ReadUInt32(); + uint code = context.RequestData.ReadUInt32(); uint flags = context.RequestData.ReadUInt32(); - ulong dataPos = context.Request.SendBuff[0].Position; + ulong dataPos = context.Request.SendBuff[0].Position; ulong dataSize = context.Request.SendBuff[0].Size; - ulong replyPos = context.Request.ReceiveBuff[0].Position; + ulong replyPos = context.Request.ReceiveBuff[0].Position; ulong replySize = context.Request.ReceiveBuff[0].Size; ReadOnlySpan inputParcel = context.Memory.GetSpan(dataPos, (int)dataSize); - Span outputParcel = new Span(new byte[replySize]); + Span outputParcel = new(new byte[replySize]); ResultCode result = OnTransact(binderId, code, flags, inputParcel, outputParcel); @@ -45,8 +45,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public ResultCode AdjustRefcount(ServiceCtx context) { int binderId = context.RequestData.ReadInt32(); - int addVal = context.RequestData.ReadInt32(); - int type = context.RequestData.ReadInt32(); + int addVal = context.RequestData.ReadInt32(); + int type = context.RequestData.ReadInt32(); return AdjustRefcount(binderId, addVal, type); } @@ -77,27 +77,26 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { int binderId = context.RequestData.ReadInt32(); - uint code = context.RequestData.ReadUInt32(); + uint code = context.RequestData.ReadUInt32(); uint flags = context.RequestData.ReadUInt32(); - (ulong dataPos, ulong dataSize) = context.Request.GetBufferType0x21(); + (ulong dataPos, ulong dataSize) = context.Request.GetBufferType0x21(); (ulong replyPos, ulong replySize) = context.Request.GetBufferType0x22(); ReadOnlySpan inputParcel = context.Memory.GetSpan(dataPos, (int)dataSize); - using (IMemoryOwner outputParcelOwner = ByteMemoryPool.RentCleared(replySize)) + using IMemoryOwner outputParcelOwner = ByteMemoryPool.RentCleared(replySize); + + Span outputParcel = outputParcelOwner.Memory.Span; + + ResultCode result = OnTransact(binderId, code, flags, inputParcel, outputParcel); + + if (result == ResultCode.Success) { - Span outputParcel = outputParcelOwner.Memory.Span; - - ResultCode result = OnTransact(binderId, code, flags, inputParcel, outputParcel); - - if (result == ResultCode.Success) - { - context.Memory.Write(replyPos, outputParcel); - } - - return result; + context.Memory.Write(replyPos, outputParcel); } + + return result; } protected abstract ResultCode AdjustRefcount(int binderId, int addVal, int type); diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/LayerState.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/LayerState.cs index 5f014e13a..af32be3d0 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/LayerState.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/LayerState.cs @@ -5,6 +5,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger NotInitialized, ManagedClosed, ManagedOpened, - Stray + Stray, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowApi.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowApi.cs index 794c48b82..b565f3f60 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowApi.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowApi.cs @@ -2,10 +2,10 @@ { enum NativeWindowApi { - NoApi = 0, - NVN = 1, - CPU = 2, - Media = 3, - Camera = 4 + NoApi = 0, + NVN = 1, + CPU = 2, + Media = 3, + Camera = 4, } } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowAttribute.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowAttribute.cs index c40b4fa10..075f81369 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowAttribute.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowAttribute.cs @@ -2,12 +2,12 @@ { enum NativeWindowAttribute : uint { - Width = 0, - Height = 1, - Format = 2, - MinUnqueuedBuffers = 3, + Width = 0, + Height = 1, + Format = 2, + MinUnqueuedBuffers = 3, ConsumerRunningBehind = 9, - ConsumerUsageBits = 10, - MaxBufferCountAsync = 12 + ConsumerUsageBits = 10, + MaxBufferCountAsync = 12, } } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowScalingMode.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowScalingMode.cs index 4194c9159..9b07e43bd 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowScalingMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowScalingMode.cs @@ -2,10 +2,10 @@ { enum NativeWindowScalingMode : uint { - Freeze = 0, + Freeze = 0, ScaleToWindow = 1, - ScaleCrop = 2, - Unknown = 3, - NoScaleCrop = 4, + ScaleCrop = 2, + Unknown = 3, + NoScaleCrop = 4, } } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowTransform.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowTransform.cs index 66482b123..1a0c7d13b 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowTransform.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NativeWindowTransform.cs @@ -5,14 +5,14 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger [Flags] enum NativeWindowTransform : uint { - None = 0, - FlipX = 1, - FlipY = 2, - Rotate90 = 4, - Rotate180 = FlipX | FlipY, - Rotate270 = Rotate90 | Rotate180, - InverseDisplay = 8, + None = 0, + FlipX = 1, + FlipY = 2, + Rotate90 = 4, + Rotate180 = FlipX | FlipY, + Rotate270 = Rotate90 | Rotate180, + InverseDisplay = 8, NoVSyncCapability = 0x10, - ReturnFrameNumber = 0x20 + ReturnFrameNumber = 0x20, } } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs index 19b221571..431c2cadc 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs @@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { private readonly byte[] _rawData; - private Span Raw => new Span(_rawData); + private Span Raw => new(_rawData); private ref ParcelHeader Header => ref MemoryMarshal.Cast(_rawData)[0]; @@ -26,10 +26,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public Parcel(byte[] rawData) { - _rawData = rawData; + _rawData = rawData; _payloadPosition = 0; - _objectPosition = 0; + _objectPosition = 0; } public Parcel(uint payloadSize, uint objectsSize) @@ -38,16 +38,18 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger _rawData = new byte[BitUtils.AlignUp(headerSize + payloadSize + objectsSize, 4)]; - Header.PayloadSize = payloadSize; - Header.ObjectsSize = objectsSize; + Header.PayloadSize = payloadSize; + Header.ObjectsSize = objectsSize; Header.PayloadOffset = headerSize; - Header.ObjectOffset = Header.PayloadOffset + Header.ObjectsSize; + Header.ObjectOffset = Header.PayloadOffset + Header.ObjectsSize; } public string ReadInterfaceToken() { // Ignore the policy flags +#pragma warning disable IDE0059 // Remove unnecessary value assignment int strictPolicy = ReadInt32(); +#pragma warning restore IDE0059 return ReadString16(); } @@ -64,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger ReadOnlySpan data = ReadInPlace((size + 1) * 2); // Return the unicode string without the last character (null terminator) - return Encoding.Unicode.GetString(data.Slice(0, size * 2)); + return Encoding.Unicode.GetString(data[..(size * 2)]); } public int ReadInt32() => ReadUnmanagedType(); @@ -77,7 +79,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { long flattenableSize = ReadInt64(); - T result = new T(); + T result = new(); Debug.Assert(flattenableSize == result.GetFlattenedSize()); @@ -86,7 +88,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger return result; } - public T ReadUnmanagedType() where T: unmanaged + public T ReadUnmanagedType() where T : unmanaged { ReadOnlySpan data = ReadInPlace(Unsafe.SizeOf()); @@ -105,8 +107,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger [StructLayout(LayoutKind.Sequential, Size = 0x28)] private struct FlatBinderObject { - public int Type; - public int Flags; + public int Type; + public int Flags; public long BinderId; public long Cookie; @@ -115,12 +117,12 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public Span ServiceName => MemoryMarshal.CreateSpan(ref _serviceNameStart, 0x8); } - public void WriteObject(T obj, string serviceName) where T: IBinder + public void WriteObject(T obj, string serviceName) where T : IBinder { - FlatBinderObject flatBinderObject = new FlatBinderObject + FlatBinderObject flatBinderObject = new() { - Type = 2, - Flags = 0, + Type = 2, + Flags = 0, BinderId = HOSBinderDriverServer.GetBinderId(obj), }; @@ -149,7 +151,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger } } - public void WriteStrongPointer(ref AndroidStrongPointer value) where T: unmanaged, IFlattenable + public void WriteStrongPointer(ref AndroidStrongPointer value) where T : unmanaged, IFlattenable { WriteBoolean(!value.IsNull); @@ -205,17 +207,17 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { uint headerSize = (uint)Unsafe.SizeOf(); - Header.PayloadSize = (uint)_payloadPosition; - Header.ObjectsSize = (uint)_objectPosition; + Header.PayloadSize = (uint)_payloadPosition; + Header.ObjectsSize = (uint)_objectPosition; Header.PayloadOffset = headerSize; - Header.ObjectOffset = Header.PayloadOffset + Header.PayloadSize; + Header.ObjectOffset = Header.PayloadOffset + Header.PayloadSize; } public ReadOnlySpan Finish() { UpdateHeader(); - return Raw.Slice(0, (int)(Header.PayloadSize + Header.ObjectsSize + Unsafe.SizeOf())); + return Raw[..(int)(Header.PayloadSize + Header.ObjectsSize + Unsafe.SizeOf())]; } } } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Status.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Status.cs index 925811fa2..d328aee9b 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Status.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Status.cs @@ -1,22 +1,25 @@ -namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger +using System.Diagnostics.CodeAnalysis; + +namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { + [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")] enum Status { - Success = 0, - WouldBlock = -11, - NoMemory = -12, - Busy = -16, - NoInit = -19, - BadValue = -22, + Success = 0, + WouldBlock = -11, + NoMemory = -12, + Busy = -16, + NoInit = -19, + BadValue = -22, InvalidOperation = -37, // Producer flags BufferNeedsReallocation = 1, - ReleaseAllBuffers = 2, + ReleaseAllBuffers = 2, // Consumer errors - StaleBufferSlot = 1, + StaleBufferSlot = 1, NoBufferAvailaible = 2, - PresentLater = 3, + PresentLater = 3, } } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs index 0c1cea517..d3d9dc030 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs @@ -11,49 +11,47 @@ using System.Threading; namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { - using ResultCode = Ryujinx.HLE.HOS.Services.Vi.ResultCode; - class SurfaceFlinger : IConsumerListener, IDisposable { private const int TargetFps = 60; - private Switch _device; + private readonly Switch _device; - private Dictionary _layers; + private readonly Dictionary _layers; private bool _isRunning; - private Thread _composerThread; + private readonly Thread _composerThread; - private Stopwatch _chrono; + private readonly Stopwatch _chrono; - private ManualResetEvent _event = new ManualResetEvent(false); - private AutoResetEvent _nextFrameEvent = new AutoResetEvent(true); + private readonly ManualResetEvent _event = new(false); + private readonly AutoResetEvent _nextFrameEvent = new(true); private long _ticks; private long _ticksPerFrame; - private long _spinTicks; - private long _1msTicks; + private readonly long _spinTicks; + private readonly long _1msTicks; private int _swapInterval; private int _swapIntervalDelay; - private readonly object Lock = new(); + private readonly object _lock = new(); public long RenderLayerId { get; private set; } private class Layer { - public int ProducerBinderId; + public int ProducerBinderId; public IGraphicBufferProducer Producer; - public BufferItemConsumer Consumer; - public BufferQueueCore Core; - public ulong Owner; - public LayerState State; + public BufferItemConsumer Consumer; + public BufferQueueCore Core; + public ulong Owner; + public LayerState State; } private class TextureCallbackInformation { - public Layer Layer; + public Layer Layer; public BufferItem Item; } @@ -65,7 +63,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger _composerThread = new Thread(HandleComposition) { - Name = "SurfaceFlinger.Composer" + Name = "SurfaceFlinger.Composer", }; _chrono = new Stopwatch(); @@ -100,7 +98,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { layerId = 1; - lock (Lock) + lock (_lock) { foreach (KeyValuePair pair in _layers) { @@ -118,7 +116,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger private void CreateLayerFromId(ulong pid, long layerId, LayerState initialState) { - lock (Lock) + lock (_lock) { Logger.Info?.Print(LogClass.SurfaceFlinger, $"Creating layer {layerId}"); @@ -132,16 +130,16 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger _layers.Add(layerId, new Layer { ProducerBinderId = HOSBinderDriverServer.RegisterBinderObject(producer), - Producer = producer, - Consumer = new BufferItemConsumer(_device, consumer, 0, -1, false, this), - Core = core, - Owner = pid, - State = initialState + Producer = producer, + Consumer = new BufferItemConsumer(_device, consumer, 0, -1, false, this), + Core = core, + Owner = pid, + State = initialState, }); } } - public ResultCode OpenLayer(ulong pid, long layerId, out IBinder producer) + public Vi.ResultCode OpenLayer(ulong pid, long layerId, out IBinder producer) { Layer layer = GetLayerByIdLocked(layerId); @@ -149,18 +147,18 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { producer = null; - return ResultCode.InvalidArguments; + return Vi.ResultCode.InvalidArguments; } layer.State = LayerState.ManagedOpened; producer = layer.Producer; - return ResultCode.Success; + return Vi.ResultCode.Success; } - public ResultCode CloseLayer(long layerId) + public Vi.ResultCode CloseLayer(long layerId) { - lock (Lock) + lock (_lock) { Layer layer = GetLayerByIdLocked(layerId); @@ -168,18 +166,18 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { Logger.Error?.Print(LogClass.SurfaceFlinger, $"Failed to close layer {layerId}"); - return ResultCode.InvalidValue; + return Vi.ResultCode.InvalidValue; } CloseLayer(layerId, layer); - return ResultCode.Success; + return Vi.ResultCode.Success; } } - public ResultCode DestroyManagedLayer(long layerId) + public Vi.ResultCode DestroyManagedLayer(long layerId) { - lock (Lock) + lock (_lock) { Layer layer = GetLayerByIdLocked(layerId); @@ -187,14 +185,14 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { Logger.Error?.Print(LogClass.SurfaceFlinger, $"Failed to destroy managed layer {layerId} (not found)"); - return ResultCode.InvalidValue; + return Vi.ResultCode.InvalidValue; } if (layer.State != LayerState.ManagedClosed && layer.State != LayerState.ManagedOpened) { Logger.Error?.Print(LogClass.SurfaceFlinger, $"Failed to destroy managed layer {layerId} (permission denied)"); - return ResultCode.PermissionDenied; + return Vi.ResultCode.PermissionDenied; } HOSBinderDriverServer.UnregisterBinderObject(layer.ProducerBinderId); @@ -204,13 +202,13 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger CloseLayer(layerId, layer); } - return ResultCode.Success; + return Vi.ResultCode.Success; } } - public ResultCode DestroyStrayLayer(long layerId) + public Vi.ResultCode DestroyStrayLayer(long layerId) { - lock (Lock) + lock (_lock) { Layer layer = GetLayerByIdLocked(layerId); @@ -218,14 +216,14 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { Logger.Error?.Print(LogClass.SurfaceFlinger, $"Failed to destroy stray layer {layerId} (not found)"); - return ResultCode.InvalidValue; + return Vi.ResultCode.InvalidValue; } if (layer.State != LayerState.Stray) { Logger.Error?.Print(LogClass.SurfaceFlinger, $"Failed to destroy stray layer {layerId} (permission denied)"); - return ResultCode.PermissionDenied; + return Vi.ResultCode.PermissionDenied; } HOSBinderDriverServer.UnregisterBinderObject(layer.ProducerBinderId); @@ -235,7 +233,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger CloseLayer(layerId, layer); } - return ResultCode.Success; + return Vi.ResultCode.Success; } } @@ -263,7 +261,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public void SetRenderLayer(long layerId) { - lock (Lock) + lock (_lock) { RenderLayerId = layerId; } @@ -284,7 +282,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public IGraphicBufferProducer GetProducerByLayerId(long layerId) { - lock (Lock) + lock (_lock) { Layer layer = GetLayerByIdLocked(layerId); @@ -365,7 +363,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public void Compose() { - lock (Lock) + lock (_lock) { // TODO: support multilayers (& multidisplay ?) if (RenderLayerId == 0) @@ -403,7 +401,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger private void PostFrameBuffer(Layer layer, BufferItem item) { - int frameBufferWidth = item.GraphicBuffer.Object.Width; + int frameBufferWidth = item.GraphicBuffer.Object.Width; int frameBufferHeight = item.GraphicBuffer.Object.Height; int nvMapHandle = item.GraphicBuffer.Object.Buffer.Surfaces[0].NvMapHandle; @@ -434,9 +432,9 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger bool flipY = item.Transform.HasFlag(NativeWindowTransform.FlipY); AspectRatio aspectRatio = _device.Configuration.AspectRatio; - bool isStretched = aspectRatio == AspectRatio.Stretched; + bool isStretched = aspectRatio == AspectRatio.Stretched; - ImageCrop crop = new ImageCrop( + ImageCrop crop = new( cropRect.Left, cropRect.Right, cropRect.Top, @@ -447,10 +445,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger aspectRatio.ToFloatX(), aspectRatio.ToFloatY()); - TextureCallbackInformation textureCallbackInformation = new TextureCallbackInformation + TextureCallbackInformation textureCallbackInformation = new() { Layer = layer, - Item = item + Item = item, }; if (_device.Gpu.Window.EnqueueFrameThreadSafe( @@ -543,6 +541,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger _device.Statistics.RecordGameFrameTime(); } - public void OnBuffersReleased() {} + public void OnBuffersReleased() { } } } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/AndroidFence.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/AndroidFence.cs index 5b72e257f..448074cd7 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/AndroidFence.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/AndroidFence.cs @@ -16,17 +16,17 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger private byte _fenceStorageStart; - private Span _storage => MemoryMarshal.CreateSpan(ref _fenceStorageStart, Unsafe.SizeOf() * 4); + private Span Storage => MemoryMarshal.CreateSpan(ref _fenceStorageStart, Unsafe.SizeOf() * 4); - public Span NvFences => MemoryMarshal.Cast(_storage); + public Span NvFences => MemoryMarshal.Cast(Storage); public static AndroidFence NoFence { get { - AndroidFence fence = new AndroidFence + AndroidFence fence = new() { - FenceCount = 0 + FenceCount = 0, }; fence.NvFences[0].Id = NvFence.InvalidSyncPointId; @@ -81,12 +81,12 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger } } - public uint GetFlattenedSize() + public readonly uint GetFlattenedSize() { return (uint)Unsafe.SizeOf(); } - public uint GetFdCount() + public readonly uint GetFdCount() { return 0; } @@ -101,4 +101,4 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger this = parcel.ReadUnmanagedType(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/AndroidStrongPointer.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/AndroidStrongPointer.cs index c356671bc..963a1fe42 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/AndroidStrongPointer.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/AndroidStrongPointer.cs @@ -1,6 +1,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger.Types { - class AndroidStrongPointer where T: unmanaged, IFlattenable + class AndroidStrongPointer where T : unmanaged, IFlattenable { public T Object; @@ -20,13 +20,13 @@ public void Set(AndroidStrongPointer other) { - Object = other.Object; + Object = other.Object; _hasObject = other._hasObject; } public void Set(T obj) { - Object = obj; + Object = obj; _hasObject = true; } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferInfo.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferInfo.cs index 12c41b0d4..faade87f8 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferInfo.cs @@ -6,9 +6,9 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger.Types [StructLayout(LayoutKind.Sequential, Size = 0x1C, Pack = 1)] struct BufferInfo { - public ulong FrameNumber; + public ulong FrameNumber; public TimeSpanType QueueTime; public TimeSpanType PresentationTime; - public BufferState State; + public BufferState State; } } diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferItem.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferItem.cs index 19fc79008..cbb5ce760 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferItem.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferItem.cs @@ -6,33 +6,33 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger class BufferItem : ICloneable { public AndroidStrongPointer GraphicBuffer; - public AndroidFence Fence; - public Rect Crop; - public NativeWindowTransform Transform; - public NativeWindowScalingMode ScalingMode; - public long Timestamp; - public bool IsAutoTimestamp; - public int SwapInterval; - public ulong FrameNumber; - public int Slot; - public bool IsDroppable; - public bool AcquireCalled; - public bool TransformToDisplayInverse; + public AndroidFence Fence; + public Rect Crop; + public NativeWindowTransform Transform; + public NativeWindowScalingMode ScalingMode; + public long Timestamp; + public bool IsAutoTimestamp; + public int SwapInterval; + public ulong FrameNumber; + public int Slot; + public bool IsDroppable; + public bool AcquireCalled; + public bool TransformToDisplayInverse; public BufferItem() { - GraphicBuffer = new AndroidStrongPointer(); - Transform = NativeWindowTransform.None; - ScalingMode = NativeWindowScalingMode.Freeze; - Timestamp = 0; - IsAutoTimestamp = false; - FrameNumber = 0; - Slot = BufferSlotArray.InvalidBufferSlot; - IsDroppable = false; - AcquireCalled = false; + GraphicBuffer = new AndroidStrongPointer(); + Transform = NativeWindowTransform.None; + ScalingMode = NativeWindowScalingMode.Freeze; + Timestamp = 0; + IsAutoTimestamp = false; + FrameNumber = 0; + Slot = BufferSlotArray.InvalidBufferSlot; + IsDroppable = false; + AcquireCalled = false; TransformToDisplayInverse = false; - SwapInterval = 1; - Fence = AndroidFence.NoFence; + SwapInterval = 1; + Fence = AndroidFence.NoFence; Crop = new Rect(); Crop.MakeInvalid(); @@ -40,19 +40,20 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public object Clone() { - BufferItem item = new BufferItem(); - - item.Transform = Transform; - item.ScalingMode = ScalingMode; - item.IsAutoTimestamp = IsAutoTimestamp; - item.FrameNumber = FrameNumber; - item.Slot = Slot; - item.IsDroppable = IsDroppable; - item.AcquireCalled = AcquireCalled; - item.TransformToDisplayInverse = TransformToDisplayInverse; - item.SwapInterval = SwapInterval; - item.Fence = Fence; - item.Crop = Crop; + BufferItem item = new() + { + Transform = Transform, + ScalingMode = ScalingMode, + IsAutoTimestamp = IsAutoTimestamp, + FrameNumber = FrameNumber, + Slot = Slot, + IsDroppable = IsDroppable, + AcquireCalled = AcquireCalled, + TransformToDisplayInverse = TransformToDisplayInverse, + SwapInterval = SwapInterval, + Fence = Fence, + Crop = Crop, + }; item.GraphicBuffer.Set(GraphicBuffer); diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferState.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferState.cs index 1787f5a62..d735a294e 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferState.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/BufferState.cs @@ -2,9 +2,9 @@ { internal enum BufferState { - Free = 0, + Free = 0, Dequeued = 1, - Queued = 2, - Acquired = 3 + Queued = 2, + Acquired = 3, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorBytePerPixel.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorBytePerPixel.cs index b47d35b47..ec119d687 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorBytePerPixel.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorBytePerPixel.cs @@ -2,16 +2,16 @@ { enum ColorBytePerPixel { - Bpp1 = 1, - Bpp2 = 2, - Bpp4 = 4, - Bpp8 = 8, - Bpp16 = 16, - Bpp24 = 24, - Bpp32 = 32, - Bpp48 = 48, - Bpp64 = 64, - Bpp96 = 96, - Bpp128 = 128 + Bpp1 = 1, + Bpp2 = 2, + Bpp4 = 4, + Bpp8 = 8, + Bpp16 = 16, + Bpp24 = 24, + Bpp32 = 32, + Bpp48 = 48, + Bpp64 = 64, + Bpp96 = 96, + Bpp128 = 128, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorComponent.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorComponent.cs index e9669f129..e3da29319 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorComponent.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorComponent.cs @@ -2,6 +2,7 @@ { enum ColorComponent : uint { +#pragma warning disable IDE0055 // Disable formatting X1 = (0x01 << ColorShift.Component) | ColorBytePerPixel.Bpp1, X2 = (0x02 << ColorShift.Component) | ColorBytePerPixel.Bpp2, X4 = (0x03 << ColorShift.Component) | ColorBytePerPixel.Bpp4, @@ -38,5 +39,6 @@ Y12X12 = (0x24 << ColorShift.Component) | ColorBytePerPixel.Bpp32, X20Y20Z20 = (0x26 << ColorShift.Component) | ColorBytePerPixel.Bpp64, X16Y16Z16W16 = (0x27 << ColorShift.Component) | ColorBytePerPixel.Bpp64, +#pragma warning restore IDE0055 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorDataType.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorDataType.cs index cfa3b018c..2daa73b80 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorDataType.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorDataType.cs @@ -3,7 +3,7 @@ enum ColorDataType { Integer = 0x0 << ColorShift.DataType, - Float = 0x1 << ColorShift.DataType, - Stencil = 0x2 << ColorShift.DataType + Float = 0x1 << ColorShift.DataType, + Stencil = 0x2 << ColorShift.DataType, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorFormat.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorFormat.cs index 227d648ac..e13dbd86a 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorFormat.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorFormat.cs @@ -1,7 +1,11 @@ -namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger +using System.Diagnostics.CodeAnalysis; + +namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { + [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")] enum ColorFormat : ulong { +#pragma warning disable IDE0055 // Disable formatting NonColor8 = ColorSpace.NonColor | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer, NonColor16 = ColorSpace.NonColor | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Integer, NonColor24 = ColorSpace.NonColor | ColorSwizzle.X000 | ColorComponent.X24 | ColorDataType.Integer, @@ -231,5 +235,6 @@ X4Bayer12GBRG = ColorSpace.BayerGBRG | ColorSwizzle.Y000 | ColorComponent.Y4X12 | ColorDataType.Integer, X6Bayer10GBRG = ColorSpace.BayerGBRG | ColorSwizzle.Y000 | ColorComponent.Y6X10 | ColorDataType.Integer, XYZ = ColorSpace.XYZ | ColorSwizzle.XYZ1 | ColorComponent.X20Y20Z20 | ColorDataType.Float, +#pragma warning restore IDE0055 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorShift.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorShift.cs index 3ad216a8e..e19ed3eff 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorShift.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorShift.cs @@ -2,9 +2,9 @@ { class ColorShift { - public const int Swizzle = 16; - public const int DataType = 14; - public const int Space = 32; + public const int Swizzle = 16; + public const int DataType = 14; + public const int Space = 32; public const int Component = 8; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorSpace.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorSpace.cs index 9003a00ba..5021e356e 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorSpace.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorSpace.cs @@ -2,32 +2,32 @@ { enum ColorSpace : ulong { - NonColor = 0x0L << ColorShift.Space, - LinearRGBA = 0x1L << ColorShift.Space, - SRGB = 0x2L << ColorShift.Space, + NonColor = 0x0L << ColorShift.Space, + LinearRGBA = 0x1L << ColorShift.Space, + SRGB = 0x2L << ColorShift.Space, - RGB709 = 0x3L << ColorShift.Space, - LinearRGB709 = 0x4L << ColorShift.Space, + RGB709 = 0x3L << ColorShift.Space, + LinearRGB709 = 0x4L << ColorShift.Space, - LinearScRGB = 0x5L << ColorShift.Space, + LinearScRGB = 0x5L << ColorShift.Space, - RGB2020 = 0x6L << ColorShift.Space, + RGB2020 = 0x6L << ColorShift.Space, LinearRGB2020 = 0x7L << ColorShift.Space, - RGB2020_PQ = 0x8L << ColorShift.Space, + RGB2020_PQ = 0x8L << ColorShift.Space, - ColorIndex = 0x9L << ColorShift.Space, + ColorIndex = 0x9L << ColorShift.Space, - YCbCr601 = 0xAL << ColorShift.Space, - YCbCr601_RR = 0xBL << ColorShift.Space, - YCbCr601_ER = 0xCL << ColorShift.Space, - YCbCr709 = 0xDL << ColorShift.Space, - YCbCr709_ER = 0xEL << ColorShift.Space, + YCbCr601 = 0xAL << ColorShift.Space, + YCbCr601_RR = 0xBL << ColorShift.Space, + YCbCr601_ER = 0xCL << ColorShift.Space, + YCbCr709 = 0xDL << ColorShift.Space, + YCbCr709_ER = 0xEL << ColorShift.Space, - BayerRGGB = 0x10L << ColorShift.Space, - BayerBGGR = 0x11L << ColorShift.Space, - BayerGRBG = 0x12L << ColorShift.Space, - BayerGBRG = 0x13L << ColorShift.Space, + BayerRGGB = 0x10L << ColorShift.Space, + BayerBGGR = 0x11L << ColorShift.Space, + BayerGRBG = 0x12L << ColorShift.Space, + BayerGBRG = 0x13L << ColorShift.Space, - XYZ = 0x14L << ColorShift.Space, + XYZ = 0x14L << ColorShift.Space, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorSwizzle.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorSwizzle.cs index 4c1370c71..0473d56b3 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorSwizzle.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Color/ColorSwizzle.cs @@ -2,6 +2,7 @@ { enum ColorSwizzle { +#pragma warning disable IDE0055 // Disable formatting XYZW = 0x688 << ColorShift.Swizzle, ZYXW = 0x60a << ColorShift.Swizzle, WZYX = 0x053 << ColorShift.Swizzle, @@ -26,6 +27,7 @@ _000X = 0x124 << ColorShift.Swizzle, _0XY0 = 0x844 << ColorShift.Swizzle, XXXY = 0x200 << ColorShift.Swizzle, - YYYX = 0x049 << ColorShift.Swizzle + YYYX = 0x049 << ColorShift.Swizzle, +#pragma warning restore IDE0055 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBuffer.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBuffer.cs index d1143225e..f7bd3b241 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBuffer.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBuffer.cs @@ -9,14 +9,14 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger struct GraphicBuffer : IFlattenable { public GraphicBufferHeader Header; - public NvGraphicBuffer Buffer; + public NvGraphicBuffer Buffer; - public int Width => Header.Width; - public int Height => Header.Height; - public PixelFormat Format => Header.Format; - public int Usage => Header.Usage; + public readonly int Width => Header.Width; + public readonly int Height => Header.Height; + public readonly PixelFormat Format => Header.Format; + public readonly int Usage => Header.Usage; - public Rect ToRect() + public readonly Rect ToRect() { return new Rect(Width, Height); } @@ -41,34 +41,34 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger Buffer = parcel.ReadUnmanagedType(); } - public void IncrementNvMapHandleRefCount(ulong pid) + public readonly void IncrementNvMapHandleRefCount(ulong pid) { NvMapDeviceFile.IncrementMapRefCount(pid, Buffer.NvMapId); - for (int i = 0; i < Buffer.Surfaces.Length; i++) + for (int i = 0; i < NvGraphicBufferSurfaceArray.Length; i++) { NvMapDeviceFile.IncrementMapRefCount(pid, Buffer.Surfaces[i].NvMapHandle); } } - public void DecrementNvMapHandleRefCount(ulong pid) + public readonly void DecrementNvMapHandleRefCount(ulong pid) { NvMapDeviceFile.DecrementMapRefCount(pid, Buffer.NvMapId); - for (int i = 0; i < Buffer.Surfaces.Length; i++) + for (int i = 0; i < NvGraphicBufferSurfaceArray.Length; i++) { NvMapDeviceFile.DecrementMapRefCount(pid, Buffer.Surfaces[i].NvMapHandle); } } - public uint GetFlattenedSize() + public readonly uint GetFlattenedSize() { return (uint)Unsafe.SizeOf(); } - public uint GetFdCount() + public readonly uint GetFdCount() { return 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBufferHeader.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBufferHeader.cs index 77495922c..c6413ec13 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBufferHeader.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBufferHeader.cs @@ -5,12 +5,12 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger [StructLayout(LayoutKind.Sequential, Size = 0x28, Pack = 1)] struct GraphicBufferHeader { - public int Magic; - public int Width; - public int Height; - public int Stride; + public int Magic; + public int Width; + public int Height; + public int Stride; public PixelFormat Format; - public int Usage; + public int Usage; public int Pid; public int RefCount; @@ -18,4 +18,4 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public int FdsCount; public int IntsCount; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBuffer.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBuffer.cs index 6bb47dccf..cbae4a902 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBuffer.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBuffer.cs @@ -38,4 +38,4 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger [FieldOffset(0x34)] public NvGraphicBufferSurfaceArray Surfaces; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBufferSurface.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBufferSurface.cs index e084bc73e..e0570c70a 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBufferSurface.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBufferSurface.cs @@ -41,4 +41,4 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger [FieldOffset(0x38)] public long Size; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBufferSurfaceArray.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBufferSurfaceArray.cs index 51ac98f82..8bc30c1f1 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBufferSurfaceArray.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/NvGraphicBufferSurfaceArray.cs @@ -15,27 +15,20 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger [FieldOffset(0xb0)] private NvGraphicBufferSurface Surface2; - public NvGraphicBufferSurface this[int index] + public readonly NvGraphicBufferSurface this[int index] { get { - if (index == 0) + return index switch { - return Surface0; - } - else if (index == 1) - { - return Surface1; - } - else if (index == 2) - { - return Surface2; - } - - throw new IndexOutOfRangeException(); + 0 => Surface0, + 1 => Surface1, + 2 => Surface2, + _ => throw new IndexOutOfRangeException(), + }; } } - public int Length => 3; + public static int Length => 3; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Rect.cs b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Rect.cs index a5dec9694..a5f7efa51 100644 --- a/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Rect.cs +++ b/src/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/Rect.cs @@ -11,18 +11,18 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public int Right; public int Bottom; - public int Width => Right - Left; - public int Height => Bottom - Top; + public readonly int Width => Right - Left; + public readonly int Height => Bottom - Top; public Rect(int width, int height) { - Left = 0; - Top = 0; - Right = width; + Left = 0; + Top = 0; + Right = width; Bottom = height; } - public bool IsEmpty() + public readonly bool IsEmpty() { return Width <= 0 || Height <= 0; } @@ -31,10 +31,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { result = new Rect { - Left = Math.Max(Left, other.Left), - Top = Math.Max(Top, other.Top), - Right = Math.Min(Right, other.Right), - Bottom = Math.Min(Bottom, other.Bottom) + Left = Math.Max(Left, other.Left), + Top = Math.Max(Top, other.Top), + Right = Math.Min(Right, other.Right), + Bottom = Math.Min(Bottom, other.Bottom), }; return !result.IsEmpty(); @@ -42,7 +42,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger public void MakeInvalid() { - Right = -1; + Right = -1; Bottom = -1; } @@ -56,16 +56,16 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger return !x.Equals(y); } - public override bool Equals(object obj) + public readonly override bool Equals(object obj) { return obj is Rect rect && Equals(rect); } - public bool Equals(Rect cmpObj) + public readonly bool Equals(Rect cmpObj) { return Left == cmpObj.Left && Top == cmpObj.Top && Right == cmpObj.Right && Bottom == cmpObj.Bottom; } - public override int GetHashCode() => HashCode.Combine(Left, Top, Right, Bottom); + public readonly override int GetHashCode() => HashCode.Combine(Left, Top, Right, Bottom); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/LocalSystemClockContextWriter.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/LocalSystemClockContextWriter.cs index fb7ebdc5b..49da1245f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/LocalSystemClockContextWriter.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/LocalSystemClockContextWriter.cs @@ -2,7 +2,7 @@ { class LocalSystemClockContextWriter : SystemClockContextUpdateCallback { - private TimeSharedMemory _sharedMemory; + private readonly TimeSharedMemory _sharedMemory; public LocalSystemClockContextWriter(TimeSharedMemory sharedMemory) { @@ -11,7 +11,7 @@ protected override ResultCode Update() { - _sharedMemory.UpdateLocalSystemClockContext(_context); + _sharedMemory.UpdateLocalSystemClockContext(Context); return ResultCode.Success; } diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/NetworkSystemClockContextWriter.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/NetworkSystemClockContextWriter.cs index 36468ec14..ef315ea4d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/NetworkSystemClockContextWriter.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/NetworkSystemClockContextWriter.cs @@ -2,7 +2,7 @@ { class NetworkSystemClockContextWriter : SystemClockContextUpdateCallback { - private TimeSharedMemory _sharedMemory; + private readonly TimeSharedMemory _sharedMemory; public NetworkSystemClockContextWriter(TimeSharedMemory sharedMemory) { @@ -11,7 +11,7 @@ protected override ResultCode Update() { - _sharedMemory.UpdateNetworkSystemClockContext(_context); + _sharedMemory.UpdateNetworkSystemClockContext(Context); return ResultCode.Success; } diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardLocalSystemClockCore.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardLocalSystemClockCore.cs index 20c334e86..458ec4057 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardLocalSystemClockCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardLocalSystemClockCore.cs @@ -2,6 +2,6 @@ { class StandardLocalSystemClockCore : SystemClockCore { - public StandardLocalSystemClockCore(StandardSteadyClockCore steadyClockCore) : base(steadyClockCore) {} + public StandardLocalSystemClockCore(StandardSteadyClockCore steadyClockCore) : base(steadyClockCore) { } } } diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs index aec034850..200ab6306 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs @@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock public bool IsStandardNetworkSystemClockAccuracySufficient(ITickSource tickSource) { - SteadyClockCore steadyClockCore = GetSteadyClockCore(); + SteadyClockCore steadyClockCore = GetSteadyClockCore(); SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(tickSource); bool isStandardNetworkClockSufficientAccuracy = false; diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs index 8392c4b50..3ae699ae0 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs @@ -11,18 +11,18 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock public StandardSteadyClockCore() { - _setupValue = TimeSpanType.Zero; - _testOffset = TimeSpanType.Zero; - _internalOffset = TimeSpanType.Zero; + _setupValue = TimeSpanType.Zero; + _testOffset = TimeSpanType.Zero; + _internalOffset = TimeSpanType.Zero; _cachedRawTimePoint = TimeSpanType.Zero; } public override SteadyClockTimePoint GetTimePoint(ITickSource tickSource) { - SteadyClockTimePoint result = new SteadyClockTimePoint + SteadyClockTimePoint result = new() { - TimePoint = GetCurrentRawTimePoint(tickSource).ToSeconds(), - ClockSourceId = GetClockSourceId() + TimePoint = GetCurrentRawTimePoint(tickSource).ToSeconds(), + ClockSourceId = GetClockSourceId(), }; return result; @@ -52,7 +52,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock { TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency); - TimeSpanType rawTimePoint = new TimeSpanType(_setupValue.NanoSeconds + ticksTimeSpan.NanoSeconds); + TimeSpanType rawTimePoint = new(_setupValue.NanoSeconds + ticksTimeSpan.NanoSeconds); if (rawTimePoint.NanoSeconds < _cachedRawTimePoint.NanoSeconds) { diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardUserSystemClockCore.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardUserSystemClockCore.cs index fa485437b..e50ee7da6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardUserSystemClockCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/StandardUserSystemClockCore.cs @@ -6,19 +6,19 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock { class StandardUserSystemClockCore : SystemClockCore { - private StandardLocalSystemClockCore _localSystemClockCore; - private StandardNetworkSystemClockCore _networkSystemClockCore; - private bool _autoCorrectionEnabled; - private SteadyClockTimePoint _autoCorrectionTime; - private KEvent _autoCorrectionEvent; + private readonly StandardLocalSystemClockCore _localSystemClockCore; + private readonly StandardNetworkSystemClockCore _networkSystemClockCore; + private bool _autoCorrectionEnabled; + private SteadyClockTimePoint _autoCorrectionTime; + private KEvent _autoCorrectionEvent; public StandardUserSystemClockCore(StandardLocalSystemClockCore localSystemClockCore, StandardNetworkSystemClockCore networkSystemClockCore) : base(localSystemClockCore.GetSteadyClockCore()) { - _localSystemClockCore = localSystemClockCore; + _localSystemClockCore = localSystemClockCore; _networkSystemClockCore = networkSystemClockCore; - _autoCorrectionEnabled = false; - _autoCorrectionTime = SteadyClockTimePoint.GetRandom(); - _autoCorrectionEvent = null; + _autoCorrectionEnabled = false; + _autoCorrectionTime = SteadyClockTimePoint.GetRandom(); + _autoCorrectionEvent = null; } protected override ResultCode Flush(SystemClockContext context) diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs index 18da4ed3e..2d12a2a06 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs @@ -7,14 +7,14 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock abstract class SteadyClockCore { private UInt128 _clockSourceId; - private bool _isRtcResetDetected; - private bool _isInitialized; + private bool _isRtcResetDetected; + private bool _isInitialized; public SteadyClockCore() { - _clockSourceId = UInt128Utils.CreateRandom(); + _clockSourceId = UInt128Utils.CreateRandom(); _isRtcResetDetected = false; - _isInitialized = false; + _isInitialized = false; } public UInt128 GetClockSourceId() @@ -37,7 +37,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock return new TimeSpanType(0); } - public virtual void SetTestOffset(TimeSpanType testOffset) {} + public virtual void SetTestOffset(TimeSpanType testOffset) { } public ResultCode GetRtcValue(out ulong rtcValue) { @@ -61,7 +61,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock return new TimeSpanType(0); } - public virtual void SetInternalOffset(TimeSpanType internalOffset) {} + public virtual void SetInternalOffset(TimeSpanType internalOffset) { } public virtual SteadyClockTimePoint GetTimePoint(ITickSource tickSource) { diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockContextUpdateCallback.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockContextUpdateCallback.cs index 6229f5edd..3f191820f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockContextUpdateCallback.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockContextUpdateCallback.cs @@ -6,22 +6,22 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock { abstract class SystemClockContextUpdateCallback { - private List _operationEventList; - protected SystemClockContext _context; - private bool _hasContext; + private readonly List _operationEventList; + protected SystemClockContext Context; + private bool _hasContext; public SystemClockContextUpdateCallback() { _operationEventList = new List(); - _context = new SystemClockContext(); - _hasContext = false; + Context = new SystemClockContext(); + _hasContext = false; } private bool NeedUpdate(SystemClockContext context) { if (_hasContext) { - return _context.Offset != context.Offset || _context.SteadyTimePoint.ClockSourceId != context.SteadyTimePoint.ClockSourceId; + return Context.Offset != context.Offset || Context.SteadyTimePoint.ClockSourceId != context.SteadyTimePoint.ClockSourceId; } return true; @@ -54,7 +54,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock if (NeedUpdate(context)) { - _context = context; + Context = context; _hasContext = true; result = Update(); diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockCore.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockCore.cs index f4bbaa604..f8a995b71 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockCore.cs @@ -5,19 +5,19 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock { abstract class SystemClockCore { - private SteadyClockCore _steadyClockCore; - private SystemClockContext _context; - private bool _isInitialized; + private readonly SteadyClockCore _steadyClockCore; + private SystemClockContext _context; + private bool _isInitialized; private SystemClockContextUpdateCallback _systemClockContextUpdateCallback; public SystemClockCore(SteadyClockCore steadyClockCore) { _steadyClockCore = steadyClockCore; - _context = new SystemClockContext(); - _isInitialized = false; + _context = new SystemClockContext(); + _isInitialized = false; _context.SteadyTimePoint.ClockSourceId = steadyClockCore.GetClockSourceId(); - _systemClockContextUpdateCallback = null; + _systemClockContextUpdateCallback = null; } public virtual SteadyClockCore GetSteadyClockCore() @@ -52,10 +52,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock { SteadyClockTimePoint currentTimePoint = _steadyClockCore.GetCurrentTimePoint(tickSource); - SystemClockContext clockContext = new SystemClockContext() + SystemClockContext clockContext = new() { - Offset = posixTime - currentTimePoint.TimePoint, - SteadyTimePoint = currentTimePoint + Offset = posixTime - currentTimePoint.TimePoint, + SteadyTimePoint = currentTimePoint, }; ResultCode result = SetClockContext(clockContext); @@ -99,10 +99,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock public void RegisterOperationEvent(KWritableEvent writableEvent) { - if (_systemClockContextUpdateCallback != null) - { - _systemClockContextUpdateCallback.RegisterOperationEvent(writableEvent); - } + _systemClockContextUpdateCallback?.RegisterOperationEvent(writableEvent); } public ResultCode SetSystemClockContext(SystemClockContext context) diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/TickBasedSteadyClockCore.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/TickBasedSteadyClockCore.cs index fe74da7e9..99e981ecd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/TickBasedSteadyClockCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/TickBasedSteadyClockCore.cs @@ -4,14 +4,14 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock { class TickBasedSteadyClockCore : SteadyClockCore { - public TickBasedSteadyClockCore() {} + public TickBasedSteadyClockCore() { } public override SteadyClockTimePoint GetTimePoint(ITickSource tickSource) { - SteadyClockTimePoint result = new SteadyClockTimePoint + SteadyClockTimePoint result = new() { - TimePoint = 0, - ClockSourceId = GetClockSourceId() + TimePoint = 0, + ClockSourceId = GetClockSourceId(), }; TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency); diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/ClockSnapshot.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/ClockSnapshot.cs index 07c1b405f..d0a74a935 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/ClockSnapshot.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/ClockSnapshot.cs @@ -7,23 +7,23 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock [StructLayout(LayoutKind.Sequential, Size = 0xD0)] struct ClockSnapshot { - public SystemClockContext UserContext; - public SystemClockContext NetworkContext; - public long UserTime; - public long NetworkTime; - public CalendarTime UserCalendarTime; - public CalendarTime NetworkCalendarTime; + public SystemClockContext UserContext; + public SystemClockContext NetworkContext; + public long UserTime; + public long NetworkTime; + public CalendarTime UserCalendarTime; + public CalendarTime NetworkCalendarTime; public CalendarAdditionalInfo UserCalendarAdditionalTime; public CalendarAdditionalInfo NetworkCalendarAdditionalTime; - public SteadyClockTimePoint SteadyClockTimePoint; + public SteadyClockTimePoint SteadyClockTimePoint; private LocationNameStorageHolder _locationName; public Span LocationName => MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref _locationName, LocationNameStorageHolder.Size)); [MarshalAs(UnmanagedType.I1)] - public bool IsAutomaticCorrectionEnabled; - public byte Type; + public bool IsAutomaticCorrectionEnabled; + public byte Type; public ushort Unknown; @@ -47,4 +47,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock return ResultCode.TimeMismatch; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SteadyClockTimePoint.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SteadyClockTimePoint.cs index 729e11b6b..2bc99ff81 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SteadyClockTimePoint.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SteadyClockTimePoint.cs @@ -7,10 +7,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock [StructLayout(LayoutKind.Sequential, Pack = 1)] struct SteadyClockTimePoint { - public long TimePoint; + public long TimePoint; public UInt128 ClockSourceId; - public ResultCode GetSpanBetween(SteadyClockTimePoint other, out long outSpan) + public readonly ResultCode GetSpanBetween(SteadyClockTimePoint other, out long outSpan) { outSpan = 0; @@ -35,9 +35,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock { return new SteadyClockTimePoint { - TimePoint = 0, - ClockSourceId = UInt128Utils.CreateRandom() + TimePoint = 0, + ClockSourceId = UInt128Utils.CreateRandom(), }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SystemClockContext.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SystemClockContext.cs index 6b589c28a..fc47e775f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SystemClockContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SystemClockContext.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock [StructLayout(LayoutKind.Sequential, Pack = 1)] struct SystemClockContext { - public long Offset; + public long Offset; public SteadyClockTimePoint SteadyTimePoint; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/TimeSpanType.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/TimeSpanType.cs index 0070193f2..a7ef81150 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/TimeSpanType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/TimeSpanType.cs @@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock { private const long NanoSecondsPerSecond = 1000000000; - public static readonly TimeSpanType Zero = new TimeSpanType(0); + public static readonly TimeSpanType Zero = new(0); public long NanoSeconds; @@ -17,17 +17,17 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock NanoSeconds = nanoSeconds; } - public long ToSeconds() + public readonly long ToSeconds() { return NanoSeconds / NanoSecondsPerSecond; } - public TimeSpanType AddSeconds(long seconds) + public readonly TimeSpanType AddSeconds(long seconds) { return new TimeSpanType(NanoSeconds + (seconds * NanoSecondsPerSecond)); } - public bool IsDaylightSavingTime() + public readonly bool IsDaylightSavingTime() { return DateTime.UnixEpoch.AddSeconds(ToSeconds()).ToLocalTime().IsDaylightSavingTime(); } @@ -47,4 +47,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock return FromSeconds((long)ticks / (long)frequency); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/IAlarmService.cs b/src/Ryujinx.HLE/HOS/Services/Time/IAlarmService.cs index 092fa8ce5..46b58408a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/IAlarmService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/IAlarmService.cs @@ -5,4 +5,4 @@ { public IAlarmService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/IPowerStateRequestHandler.cs b/src/Ryujinx.HLE/HOS/Services/Time/IPowerStateRequestHandler.cs index 8ec55c159..64b7e69c6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/IPowerStateRequestHandler.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/IPowerStateRequestHandler.cs @@ -5,4 +5,4 @@ { public IPowerStateRequestHandler(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForGlue.cs b/src/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForGlue.cs index 31548b80c..32aed90cb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForGlue.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForGlue.cs @@ -12,13 +12,13 @@ namespace Ryujinx.HLE.HOS.Services.Time [Service("time:u", TimePermissions.User)] class IStaticServiceForGlue : IpcService { - private IStaticServiceForPsc _inner; - private TimePermissions _permissions; + private readonly IStaticServiceForPsc _inner; + private readonly TimePermissions _permissions; public IStaticServiceForGlue(ServiceCtx context, TimePermissions permissions) : base(context.Device.System.TimeServer) { _permissions = permissions; - _inner = new IStaticServiceForPsc(context, permissions); + _inner = new IStaticServiceForPsc(context, permissions); _inner.TrySetServer(Server); _inner.SetParent(this); } @@ -83,7 +83,9 @@ namespace Ryujinx.HLE.HOS.Services.Time return ResultCode.PermissionDenied; } +#pragma warning disable IDE0059 // Remove unnecessary value assignment TimeSpanType internalOffset = context.RequestData.ReadStruct(); +#pragma warning restore IDE0059 // TODO: set:sys SetExternalSteadyClockInternalOffset(internalOffset.ToSeconds()) diff --git a/src/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs b/src/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs index 145d4e3b9..a6b33e4ae 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs @@ -18,12 +18,12 @@ namespace Ryujinx.HLE.HOS.Services.Time [Service("time:su", TimePermissions.SystemUpdate)] class IStaticServiceForPsc : IpcService { - private TimeManager _timeManager; - private TimePermissions _permissions; + private readonly TimeManager _timeManager; + private readonly TimePermissions _permissions; private int _timeSharedMemoryNativeHandle = 0; - public IStaticServiceForPsc(ServiceCtx context, TimePermissions permissions) : this(TimeManager.Instance, permissions) {} + public IStaticServiceForPsc(ServiceCtx context, TimePermissions permissions) : this(TimeManager.Instance, permissions) { } public IStaticServiceForPsc(TimeManager manager, TimePermissions permissions) { @@ -149,8 +149,8 @@ namespace Ryujinx.HLE.HOS.Services.Time // SetStandardUserSystemClockAutomaticCorrectionEnabled(b8) public ResultCode SetStandardUserSystemClockAutomaticCorrectionEnabled(ServiceCtx context) { - SteadyClockCore steadyClock = _timeManager.StandardSteadyClock; - StandardUserSystemClockCore userClock = _timeManager.StandardUserSystemClock; + SteadyClockCore steadyClock = _timeManager.StandardSteadyClock; + StandardUserSystemClockCore userClock = _timeManager.StandardUserSystemClock; if (!userClock.IsInitialized() || !steadyClock.IsInitialized()) { @@ -229,7 +229,7 @@ namespace Ryujinx.HLE.HOS.Services.Time ITickSource tickSource = context.Device.System.TickSource; - SystemClockContext otherContext = context.RequestData.ReadStruct(); + SystemClockContext otherContext = context.RequestData.ReadStruct(); SteadyClockTimePoint currentTimePoint = steadyClock.GetCurrentTimePoint(tickSource); ResultCode result = ResultCode.TimeMismatch; @@ -237,7 +237,7 @@ namespace Ryujinx.HLE.HOS.Services.Time if (currentTimePoint.ClockSourceId == otherContext.SteadyTimePoint.ClockSourceId) { TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency); - long baseTimePoint = otherContext.Offset + currentTimePoint.TimePoint - ticksTimeSpan.ToSeconds(); + long baseTimePoint = otherContext.Offset + currentTimePoint.TimePoint - ticksTimeSpan.ToSeconds(); context.ResponseData.Write(baseTimePoint); @@ -287,7 +287,7 @@ namespace Ryujinx.HLE.HOS.Services.Time context.RequestData.BaseStream.Position += 7; - SystemClockContext userContext = context.RequestData.ReadStruct(); + SystemClockContext userContext = context.RequestData.ReadStruct(); SystemClockContext networkContext = context.RequestData.ReadStruct(); ITickSource tickSource = context.Device.System.TickSource; @@ -308,7 +308,7 @@ namespace Ryujinx.HLE.HOS.Services.Time { ClockSnapshot clockSnapshotA = ReadClockSnapshotFromBuffer(context, context.Request.PtrBuff[0]); ClockSnapshot clockSnapshotB = ReadClockSnapshotFromBuffer(context, context.Request.PtrBuff[1]); - TimeSpanType difference = TimeSpanType.FromSeconds(clockSnapshotB.UserContext.Offset - clockSnapshotA.UserContext.Offset); + TimeSpanType difference = TimeSpanType.FromSeconds(clockSnapshotB.UserContext.Offset - clockSnapshotA.UserContext.Offset); if (clockSnapshotB.UserContext.SteadyTimePoint.ClockSourceId != clockSnapshotA.UserContext.SteadyTimePoint.ClockSourceId || (clockSnapshotB.IsAutomaticCorrectionEnabled && clockSnapshotA.IsAutomaticCorrectionEnabled)) { @@ -337,7 +337,7 @@ namespace Ryujinx.HLE.HOS.Services.Time if (clockSnapshotA.NetworkTime != 0 && clockSnapshotB.NetworkTime != 0) { - result = TimeSpanType.FromSeconds(clockSnapshotB.NetworkTime - clockSnapshotA.NetworkTime); + result = TimeSpanType.FromSeconds(clockSnapshotB.NetworkTime - clockSnapshotA.NetworkTime); resultCode = ResultCode.Success; } else @@ -359,13 +359,13 @@ namespace Ryujinx.HLE.HOS.Services.Time { clockSnapshot = new ClockSnapshot(); - SteadyClockCore steadyClockCore = _timeManager.StandardSteadyClock; + SteadyClockCore steadyClockCore = _timeManager.StandardSteadyClock; SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(tickSource); clockSnapshot.IsAutomaticCorrectionEnabled = _timeManager.StandardUserSystemClock.IsAutomaticCorrectionEnabled(); - clockSnapshot.UserContext = userContext; - clockSnapshot.NetworkContext = networkContext; - clockSnapshot.SteadyClockTimePoint = currentTimePoint; + clockSnapshot.UserContext = userContext; + clockSnapshot.NetworkContext = networkContext; + clockSnapshot.SteadyClockTimePoint = currentTimePoint; ResultCode result = _timeManager.TimeZone.Manager.GetDeviceLocationName(out string deviceLocationName); @@ -386,7 +386,7 @@ namespace Ryujinx.HLE.HOS.Services.Time if (result == ResultCode.Success) { - clockSnapshot.UserCalendarTime = userCalendarInfo.Time; + clockSnapshot.UserCalendarTime = userCalendarInfo.Time; clockSnapshot.UserCalendarAdditionalTime = userCalendarInfo.AdditionalInfo; if (ClockSnapshot.GetCurrentTime(out clockSnapshot.NetworkTime, currentTimePoint, clockSnapshot.NetworkContext) != ResultCode.Success) @@ -398,9 +398,9 @@ namespace Ryujinx.HLE.HOS.Services.Time if (result == ResultCode.Success) { - clockSnapshot.NetworkCalendarTime = networkCalendarInfo.Time; + clockSnapshot.NetworkCalendarTime = networkCalendarInfo.Time; clockSnapshot.NetworkCalendarAdditionalTime = networkCalendarInfo.AdditionalInfo; - clockSnapshot.Type = type; + clockSnapshot.Type = type; // Probably a version field? clockSnapshot.Unknown = 0; @@ -419,10 +419,9 @@ namespace Ryujinx.HLE.HOS.Services.Time context.Memory.Read(ipcDesc.Position, temp); - using (BinaryReader bufferReader = new BinaryReader(new MemoryStream(temp))) - { - return bufferReader.ReadStruct(); - } + using BinaryReader bufferReader = new(new MemoryStream(temp)); + + return bufferReader.ReadStruct(); } private void WriteClockSnapshotFromBuffer(ServiceCtx context, IpcRecvListBuffDesc ipcDesc, ClockSnapshot clockSnapshot) @@ -430,4 +429,4 @@ namespace Ryujinx.HLE.HOS.Services.Time MemoryHelper.Write(context.Memory, ipcDesc.Position, clockSnapshot); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/ITimeServiceManager.cs b/src/Ryujinx.HLE/HOS/Services/Time/ITimeServiceManager.cs index 6c9c15f1b..b690b708f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/ITimeServiceManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/ITimeServiceManager.cs @@ -13,12 +13,12 @@ namespace Ryujinx.HLE.HOS.Services.Time [Service("time:m")] // 9.0.0+ class ITimeServiceManager : IpcService { - private TimeManager _timeManager; - private int _automaticCorrectionEvent; + private readonly TimeManager _timeManager; + private int _automaticCorrectionEvent; public ITimeServiceManager(ServiceCtx context) { - _timeManager = TimeManager.Instance; + _timeManager = TimeManager.Instance; _automaticCorrectionEvent = 0; } @@ -62,11 +62,11 @@ namespace Ryujinx.HLE.HOS.Services.Time // SetupStandardSteadyClock(nn::util::Uuid clock_source_id, nn::TimeSpanType setup_value, nn::TimeSpanType internal_offset, nn::TimeSpanType test_offset, bool is_rtc_reset_detected) public ResultCode SetupStandardSteadyClock(ServiceCtx context) { - UInt128 clockSourceId = context.RequestData.ReadStruct(); - TimeSpanType setupValue = context.RequestData.ReadStruct(); - TimeSpanType internalOffset = context.RequestData.ReadStruct(); - TimeSpanType testOffset = context.RequestData.ReadStruct(); - bool isRtcResetDetected = context.RequestData.ReadBoolean(); + UInt128 clockSourceId = context.RequestData.ReadStruct(); + TimeSpanType setupValue = context.RequestData.ReadStruct(); + TimeSpanType internalOffset = context.RequestData.ReadStruct(); + TimeSpanType testOffset = context.RequestData.ReadStruct(); + bool isRtcResetDetected = context.RequestData.ReadBoolean(); ITickSource tickSource = context.Device.System.TickSource; @@ -80,7 +80,7 @@ namespace Ryujinx.HLE.HOS.Services.Time public ResultCode SetupStandardLocalSystemClock(ServiceCtx context) { SystemClockContext clockContext = context.RequestData.ReadStruct(); - long posixTime = context.RequestData.ReadInt64(); + long posixTime = context.RequestData.ReadInt64(); ITickSource tickSource = context.Device.System.TickSource; @@ -93,8 +93,8 @@ namespace Ryujinx.HLE.HOS.Services.Time // SetupStandardNetworkSystemClock(nn::time::SystemClockContext context, nn::TimeSpanType sufficient_accuracy) public ResultCode SetupStandardNetworkSystemClock(ServiceCtx context) { - SystemClockContext clockContext = context.RequestData.ReadStruct(); - TimeSpanType sufficientAccuracy = context.RequestData.ReadStruct(); + SystemClockContext clockContext = context.RequestData.ReadStruct(); + TimeSpanType sufficientAccuracy = context.RequestData.ReadStruct(); _timeManager.SetupStandardNetworkSystemClock(clockContext, sufficientAccuracy); @@ -122,10 +122,10 @@ namespace Ryujinx.HLE.HOS.Services.Time // SetupTimeZoneManager(nn::time::LocationName location_name, nn::time::SteadyClockTimePoint timezone_update_timepoint, u32 total_location_name_count, nn::time::TimeZoneRuleVersion timezone_rule_version, buffer timezone_binary) public ResultCode SetupTimeZoneManager(ServiceCtx context) { - string locationName = StringUtils.ReadInlinedAsciiString(context.RequestData, 0x24); + string locationName = StringUtils.ReadInlinedAsciiString(context.RequestData, 0x24); SteadyClockTimePoint timeZoneUpdateTimePoint = context.RequestData.ReadStruct(); - uint totalLocationNameCount = context.RequestData.ReadUInt32(); - UInt128 timeZoneRuleVersion = context.RequestData.ReadStruct(); + uint totalLocationNameCount = context.RequestData.ReadUInt32(); + UInt128 timeZoneRuleVersion = context.RequestData.ReadStruct(); (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21(); @@ -133,10 +133,9 @@ namespace Ryujinx.HLE.HOS.Services.Time context.Memory.Read(bufferPosition, temp); - using (MemoryStream timeZoneBinaryStream = new MemoryStream(temp)) - { - _timeManager.SetupTimeZoneManager(locationName, timeZoneUpdateTimePoint, totalLocationNameCount, timeZoneRuleVersion, timeZoneBinaryStream); - } + using MemoryStream timeZoneBinaryStream = new(temp); + + _timeManager.SetupTimeZoneManager(locationName, timeZoneUpdateTimePoint, totalLocationNameCount, timeZoneRuleVersion, timeZoneBinaryStream); return ResultCode.Success; } diff --git a/src/Ryujinx.HLE/HOS/Services/Time/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Time/ResultCode.cs index 3b042ec03..66ae67517 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/ResultCode.cs @@ -1,24 +1,27 @@ -namespace Ryujinx.HLE.HOS.Services.Time +using System.Diagnostics.CodeAnalysis; + +namespace Ryujinx.HLE.HOS.Services.Time { + [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")] public enum ResultCode { - ModuleId = 116, + ModuleId = 116, ErrorCodeShift = 9, Success = 0, - TimeServiceNotInitialized = (0 << ErrorCodeShift) | ModuleId, - PermissionDenied = (1 << ErrorCodeShift) | ModuleId, - TimeMismatch = (102 << ErrorCodeShift) | ModuleId, - UninitializedClock = (103 << ErrorCodeShift) | ModuleId, - TimeNotFound = (200 << ErrorCodeShift) | ModuleId, - Overflow = (201 << ErrorCodeShift) | ModuleId, - LocationNameTooLong = (801 << ErrorCodeShift) | ModuleId, - OutOfRange = (902 << ErrorCodeShift) | ModuleId, - TimeZoneConversionFailed = (903 << ErrorCodeShift) | ModuleId, - TimeZoneNotFound = (989 << ErrorCodeShift) | ModuleId, - NotImplemented = (990 << ErrorCodeShift) | ModuleId, - NetworkTimeNotAvailable = (1000 << ErrorCodeShift) | ModuleId, - NetworkTimeTaskCanceled = (1003 << ErrorCodeShift) | ModuleId, + TimeServiceNotInitialized = (0 << ErrorCodeShift) | ModuleId, + PermissionDenied = (1 << ErrorCodeShift) | ModuleId, + TimeMismatch = (102 << ErrorCodeShift) | ModuleId, + UninitializedClock = (103 << ErrorCodeShift) | ModuleId, + TimeNotFound = (200 << ErrorCodeShift) | ModuleId, + Overflow = (201 << ErrorCodeShift) | ModuleId, + LocationNameTooLong = (801 << ErrorCodeShift) | ModuleId, + OutOfRange = (902 << ErrorCodeShift) | ModuleId, + TimeZoneConversionFailed = (903 << ErrorCodeShift) | ModuleId, + TimeZoneNotFound = (989 << ErrorCodeShift) | ModuleId, + NotImplemented = (990 << ErrorCodeShift) | ModuleId, + NetworkTimeNotAvailable = (1000 << ErrorCodeShift) | ModuleId, + NetworkTimeTaskCanceled = (1003 << ErrorCodeShift) | ModuleId, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ISteadyClock.cs b/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ISteadyClock.cs index 97d7884ea..8ddb646b9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ISteadyClock.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ISteadyClock.cs @@ -6,14 +6,14 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService { class ISteadyClock : IpcService { - private SteadyClockCore _steadyClock; - private bool _writePermission; - private bool _bypassUninitializedClock; + private readonly SteadyClockCore _steadyClock; + private readonly bool _writePermission; + private readonly bool _bypassUninitializedClock; public ISteadyClock(SteadyClockCore steadyClock, bool writePermission, bool bypassUninitializedClock) { - _steadyClock = steadyClock; - _writePermission = writePermission; + _steadyClock = steadyClock; + _writePermission = writePermission; _bypassUninitializedClock = bypassUninitializedClock; } @@ -152,4 +152,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs b/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs index 3cd0a4a69..ada5f057a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs @@ -10,16 +10,16 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService { class ISystemClock : IpcService { - private SystemClockCore _clockCore; - private bool _writePermission; - private bool _bypassUninitializedClock; - private int _operationEventReadableHandle; + private readonly SystemClockCore _clockCore; + private readonly bool _writePermission; + private readonly bool _bypassUninitializedClock; + private int _operationEventReadableHandle; public ISystemClock(SystemClockCore clockCore, bool writePermission, bool bypassUninitializedClock) { - _clockCore = clockCore; - _writePermission = writePermission; - _bypassUninitializedClock = bypassUninitializedClock; + _clockCore = clockCore; + _writePermission = writePermission; + _bypassUninitializedClock = bypassUninitializedClock; _operationEventReadableHandle = 0; } @@ -113,7 +113,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService { if (_operationEventReadableHandle == 0) { - KEvent kEvent = new KEvent(context.Device.System.KernelContext); + KEvent kEvent = new(context.Device.System.KernelContext); _clockCore.RegisterOperationEvent(kEvent.WritableEvent); @@ -128,4 +128,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs b/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs index 96a7e604f..81944c835 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs @@ -12,15 +12,15 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService { class ITimeZoneServiceForGlue : IpcService { - private TimeZoneContentManager _timeZoneContentManager; - private ITimeZoneServiceForPsc _inner; - private bool _writePermission; + private readonly TimeZoneContentManager _timeZoneContentManager; + private readonly ITimeZoneServiceForPsc _inner; + private readonly bool _writePermission; public ITimeZoneServiceForGlue(TimeZoneContentManager timeZoneContentManager, bool writePermission) { _timeZoneContentManager = timeZoneContentManager; - _writePermission = writePermission; - _inner = new ITimeZoneServiceForPsc(timeZoneContentManager.Manager, writePermission); + _writePermission = writePermission; + _inner = new ITimeZoneServiceForPsc(timeZoneContentManager.Manager, writePermission); } [CommandCmif(0)] @@ -55,9 +55,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService // LoadLocationNameList(u32 index) -> (u32 outCount, buffer) public ResultCode LoadLocationNameList(ServiceCtx context) { - uint index = context.RequestData.ReadUInt32(); + uint index = context.RequestData.ReadUInt32(); ulong bufferPosition = context.Request.ReceiveBuff[0].Position; - ulong bufferSize = context.Request.ReceiveBuff[0].Size; + ulong bufferSize = context.Request.ReceiveBuff[0].Size; ResultCode errorCode = _timeZoneContentManager.LoadLocationNameList(index, out string[] locationNameArray, (uint)bufferSize / 0x24); @@ -91,7 +91,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService public ResultCode LoadTimeZoneRule(ServiceCtx context) { ulong bufferPosition = context.Request.ReceiveBuff[0].Position; - ulong bufferSize = context.Request.ReceiveBuff[0].Size; + ulong bufferSize = context.Request.ReceiveBuff[0].Size; if (bufferSize != 0x4000) { @@ -103,12 +103,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService string locationName = StringUtils.ReadInlinedAsciiString(context.RequestData, 0x24); - using (WritableRegion region = context.Memory.GetWritableRegion(bufferPosition, Unsafe.SizeOf())) - { - ref TimeZoneRule rules = ref MemoryMarshal.Cast(region.Memory.Span)[0]; + using WritableRegion region = context.Memory.GetWritableRegion(bufferPosition, Unsafe.SizeOf()); - return _timeZoneContentManager.LoadTimeZoneRule(ref rules, locationName); - } + ref TimeZoneRule rules = ref MemoryMarshal.Cast(region.Memory.Span)[0]; + + return _timeZoneContentManager.LoadTimeZoneRule(ref rules, locationName); } [CommandCmif(100)] @@ -139,4 +138,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService return _inner.ToPosixTimeWithMyRule(context); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs b/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs index 3c9ac71f3..b3a87b8a6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs @@ -14,8 +14,8 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService { class ITimeZoneServiceForPsc : IpcService { - private TimeZoneManager _timeZoneManager; - private bool _writePermission; + private readonly TimeZoneManager _timeZoneManager; + private readonly bool _writePermission; public ITimeZoneServiceForPsc(TimeZoneManager timeZoneManager, bool writePermission) { @@ -134,10 +134,8 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService context.Memory.Read(bufferPosition, temp); - using (MemoryStream timeZoneBinaryStream = new MemoryStream(temp)) - { - result = _timeZoneManager.SetDeviceLocationNameWithTimeZoneRule(locationName, timeZoneBinaryStream); - } + using MemoryStream timeZoneBinaryStream = new(temp); + result = _timeZoneManager.SetDeviceLocationNameWithTimeZoneRule(locationName, timeZoneBinaryStream); return result; } @@ -149,7 +147,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21(); ulong timeZoneRuleBufferPosition = context.Request.ReceiveBuff[0].Position; - ulong timeZoneRuleBufferSize = context.Request.ReceiveBuff[0].Size; + ulong timeZoneRuleBufferSize = context.Request.ReceiveBuff[0].Size; if (timeZoneRuleBufferSize != 0x4000) { @@ -165,15 +163,12 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService context.Memory.Read(bufferPosition, temp); - using (MemoryStream timeZoneBinaryStream = new MemoryStream(temp)) - { - using (WritableRegion region = context.Memory.GetWritableRegion(timeZoneRuleBufferPosition, Unsafe.SizeOf())) - { - ref TimeZoneRule rule = ref MemoryMarshal.Cast(region.Memory.Span)[0]; + using MemoryStream timeZoneBinaryStream = new(temp); + using WritableRegion region = context.Memory.GetWritableRegion(timeZoneRuleBufferPosition, Unsafe.SizeOf()); - result = _timeZoneManager.ParseTimeZoneRuleBinary(ref rule, timeZoneBinaryStream); - } - } + ref TimeZoneRule rule = ref MemoryMarshal.Cast(region.Memory.Span)[0]; + + result = _timeZoneManager.ParseTimeZoneRuleBinary(ref rule, timeZoneBinaryStream); return result; } @@ -189,9 +184,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService // ToCalendarTime(nn::time::PosixTime time, buffer rules) -> (nn::time::CalendarTime, nn::time::sf::CalendarAdditionalInfo) public ResultCode ToCalendarTime(ServiceCtx context) { - long posixTime = context.RequestData.ReadInt64(); + long posixTime = context.RequestData.ReadInt64(); ulong bufferPosition = context.Request.SendBuff[0].Position; - ulong bufferSize = context.Request.SendBuff[0].Size; + ulong bufferSize = context.Request.SendBuff[0].Size; if (bufferSize != 0x4000) { @@ -234,7 +229,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService public ResultCode ToPosixTime(ServiceCtx context) { ulong inBufferPosition = context.Request.SendBuff[0].Position; - ulong inBufferSize = context.Request.SendBuff[0].Size; + ulong inBufferSize = context.Request.SendBuff[0].Size; CalendarTime calendarTime = context.RequestData.ReadStruct(); @@ -253,7 +248,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService if (resultCode == ResultCode.Success) { ulong outBufferPosition = context.Request.RecvListBuff[0].Position; - ulong outBufferSize = context.Request.RecvListBuff[0].Size; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong outBufferSize = context.Request.RecvListBuff[0].Size; +#pragma warning restore IDE0059 context.Memory.Write(outBufferPosition, posixTime); context.ResponseData.Write(1); @@ -273,7 +270,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService if (resultCode == ResultCode.Success) { ulong outBufferPosition = context.Request.RecvListBuff[0].Position; - ulong outBufferSize = context.Request.RecvListBuff[0].Size; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + ulong outBufferSize = context.Request.RecvListBuff[0].Size; +#pragma warning restore IDE0059 context.Memory.Write(outBufferPosition, posixTime); diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs index e3b65f2ad..53c052e45 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs @@ -16,41 +16,38 @@ namespace Ryujinx.HLE.HOS.Services.Time { get { - if (_instance == null) - { - _instance = new TimeManager(); - } + _instance ??= new TimeManager(); return _instance; } } - public StandardSteadyClockCore StandardSteadyClock { get; } - public TickBasedSteadyClockCore TickBasedSteadyClock { get; } - public StandardLocalSystemClockCore StandardLocalSystemClock { get; } - public StandardNetworkSystemClockCore StandardNetworkSystemClock { get; } - public StandardUserSystemClockCore StandardUserSystemClock { get; } - public TimeZoneContentManager TimeZone { get; } - public EphemeralNetworkSystemClockCore EphemeralNetworkSystemClock { get; } - public TimeSharedMemory SharedMemory { get; } - public LocalSystemClockContextWriter LocalClockContextWriter { get; } - public NetworkSystemClockContextWriter NetworkClockContextWriter { get; } + public StandardSteadyClockCore StandardSteadyClock { get; } + public TickBasedSteadyClockCore TickBasedSteadyClock { get; } + public StandardLocalSystemClockCore StandardLocalSystemClock { get; } + public StandardNetworkSystemClockCore StandardNetworkSystemClock { get; } + public StandardUserSystemClockCore StandardUserSystemClock { get; } + public TimeZoneContentManager TimeZone { get; } + public EphemeralNetworkSystemClockCore EphemeralNetworkSystemClock { get; } + public TimeSharedMemory SharedMemory { get; } + public LocalSystemClockContextWriter LocalClockContextWriter { get; } + public NetworkSystemClockContextWriter NetworkClockContextWriter { get; } public EphemeralNetworkSystemClockContextWriter EphemeralClockContextWriter { get; } // TODO: 9.0.0+ power states and alarms public TimeManager() { - StandardSteadyClock = new StandardSteadyClockCore(); - TickBasedSteadyClock = new TickBasedSteadyClockCore(); - StandardLocalSystemClock = new StandardLocalSystemClockCore(StandardSteadyClock); - StandardNetworkSystemClock = new StandardNetworkSystemClockCore(StandardSteadyClock); - StandardUserSystemClock = new StandardUserSystemClockCore(StandardLocalSystemClock, StandardNetworkSystemClock); - TimeZone = new TimeZoneContentManager(); + StandardSteadyClock = new StandardSteadyClockCore(); + TickBasedSteadyClock = new TickBasedSteadyClockCore(); + StandardLocalSystemClock = new StandardLocalSystemClockCore(StandardSteadyClock); + StandardNetworkSystemClock = new StandardNetworkSystemClockCore(StandardSteadyClock); + StandardUserSystemClock = new StandardUserSystemClockCore(StandardLocalSystemClock, StandardNetworkSystemClock); + TimeZone = new TimeZoneContentManager(); EphemeralNetworkSystemClock = new EphemeralNetworkSystemClockCore(TickBasedSteadyClock); - SharedMemory = new TimeSharedMemory(); - LocalClockContextWriter = new LocalSystemClockContextWriter(SharedMemory); - NetworkClockContextWriter = new NetworkSystemClockContextWriter(SharedMemory); + SharedMemory = new TimeSharedMemory(); + LocalClockContextWriter = new LocalSystemClockContextWriter(SharedMemory); + NetworkClockContextWriter = new NetworkSystemClockContextWriter(SharedMemory); EphemeralClockContextWriter = new EphemeralNetworkSystemClockContextWriter(); } diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs index 6b1e16875..75479a173 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs @@ -11,10 +11,12 @@ namespace Ryujinx.HLE.HOS.Services.Time { class TimeSharedMemory { - private Switch _device; - private KSharedMemory _sharedMemory; + private Switch _device; + private KSharedMemory _sharedMemory; private SharedMemoryStorage _timeSharedMemoryStorage; - private int _timeSharedMemorySize; +#pragma warning disable IDE0052 // Remove unread private member + private int _timeSharedMemorySize; +#pragma warning restore IDE0052 private const uint SteadyClockContextOffset = 0x00; private const uint LocalSystemClockContextOffset = 0x38; @@ -24,10 +26,10 @@ namespace Ryujinx.HLE.HOS.Services.Time public void Initialize(Switch device, KSharedMemory sharedMemory, SharedMemoryStorage timeSharedMemoryStorage, int timeSharedMemorySize) { - _device = device; - _sharedMemory = sharedMemory; + _device = device; + _sharedMemory = sharedMemory; _timeSharedMemoryStorage = timeSharedMemoryStorage; - _timeSharedMemorySize = timeSharedMemorySize; + _timeSharedMemorySize = timeSharedMemorySize; // Clean the shared memory timeSharedMemoryStorage.ZeroFill(); @@ -60,7 +62,7 @@ namespace Ryujinx.HLE.HOS.Services.Time { TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency); - ContinuousAdjustmentTimePoint adjustmentTimePoint = new ContinuousAdjustmentTimePoint + ContinuousAdjustmentTimePoint adjustmentTimePoint = new() { ClockOffset = (ulong)ticksTimeSpan.NanoSeconds, Multiplier = 1, @@ -71,17 +73,17 @@ namespace Ryujinx.HLE.HOS.Services.Time SteadyTimePoint = new SteadyClockTimePoint { ClockSourceId = clockSourceId, - TimePoint = 0 - } - } + TimePoint = 0, + }, + }, }; WriteObjectToSharedMemory(ContinuousAdjustmentTimePointOffset, 4, adjustmentTimePoint); - SteadyClockContext context = new SteadyClockContext + SteadyClockContext context = new() { InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds), - ClockSourceId = clockSourceId + ClockSourceId = clockSourceId, }; WriteObjectToSharedMemory(SteadyClockContextOffset, 4, context); @@ -99,7 +101,7 @@ namespace Ryujinx.HLE.HOS.Services.Time private T ReadObjectFromSharedMemory(ulong offset, ulong padding) where T : unmanaged { - T result; + T result; uint index; uint possiblyNewIndex; diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs index f7477e97d..58ae1cd8c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs @@ -8,36 +8,34 @@ using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; - using static Ryujinx.HLE.HOS.Services.Time.TimeZone.TimeZoneRule; namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { public class TimeZone { - private const int TimeTypeSize = 8; - private const int EpochYear = 1970; - private const int YearBase = 1900; - private const int EpochWeekDay = 4; + private const int TimeTypeSize = 8; + private const int EpochYear = 1970; + private const int YearBase = 1900; + private const int EpochWeekDay = 4; private const int SecondsPerMinute = 60; - private const int MinutesPerHour = 60; - private const int HoursPerDays = 24; - private const int DaysPerWekk = 7; - private const int DaysPerNYear = 365; - private const int DaysPerLYear = 366; - private const int MonthsPerYear = 12; - private const int SecondsPerHour = SecondsPerMinute * MinutesPerHour; - private const int SecondsPerDay = SecondsPerHour * HoursPerDays; + private const int MinutesPerHour = 60; + private const int HoursPerDays = 24; + private const int DaysPerWeek = 7; + private const int DaysPerNYear = 365; + private const int DaysPerLYear = 366; + private const int MonthsPerYear = 12; + private const int SecondsPerHour = SecondsPerMinute * MinutesPerHour; + private const int SecondsPerDay = SecondsPerHour * HoursPerDays; - private const int YearsPerRepeat = 400; + private const int YearsPerRepeat = 400; private const long AverageSecondsPerYear = 31556952; - private const long SecondsPerRepeat = YearsPerRepeat * AverageSecondsPerYear; + private const long SecondsPerRepeat = YearsPerRepeat * AverageSecondsPerYear; - private static readonly int[] YearLengths = { DaysPerNYear, DaysPerLYear }; - private static readonly int[][] MonthsLengths = new int[][] - { - new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } + private static readonly int[] _yearLengths = { DaysPerNYear, DaysPerLYear }; + private static readonly int[][] _monthsLengths = { + new[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + new[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, }; private static ReadOnlySpan TimeZoneDefaultRule => ",M4.1.0,M10.5.0"u8; @@ -46,14 +44,14 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone private struct CalendarTimeInternal { // NOTE: On the IPC side this is supposed to be a 16 bits value but internally this need to be a 64 bits value for ToPosixTime. - public long Year; + public long Year; public sbyte Month; public sbyte Day; public sbyte Hour; public sbyte Minute; public sbyte Second; - public int CompareTo(CalendarTimeInternal other) + public readonly int CompareTo(CalendarTimeInternal other) { if (Year != other.Year) { @@ -98,16 +96,16 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { JulianDay, DayOfYear, - MonthNthDayOfWeek + MonthNthDayOfWeek, } private struct Rule { public RuleType Type; - public int Day; - public int Week; - public int Month; - public int TransitionTime; + public int Day; + public int Week; + public int Month; + public int TransitionTime; } private static int Detzcode32(ReadOnlySpan bytes) @@ -145,10 +143,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone TimeTypeInfo a = outRules.Ttis[aIndex]; TimeTypeInfo b = outRules.Ttis[bIndex]; - return a.GmtOffset == b.GmtOffset && - a.IsDaySavingTime == b.IsDaySavingTime && + return a.GmtOffset == b.GmtOffset && + a.IsDaySavingTime == b.IsDaySavingTime && a.IsStandardTimeDaylight == b.IsStandardTimeDaylight && - a.IsGMT == b.IsGMT && + a.IsGMT == b.IsGMT && StringUtils.CompareCStr(outRules.Chars[a.AbbreviationListIndex..], outRules.Chars[b.AbbreviationListIndex..]) == 0; } @@ -224,7 +222,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone seconds = 0; - bool isValid = GetNum(name, ref namePosition, out int num, 0, HoursPerDays * DaysPerWekk - 1); + bool isValid = GetNum(name, ref namePosition, out int num, 0, HoursPerDays * DaysPerWeek - 1); if (!isValid) { return false; @@ -310,7 +308,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { rule = new Rule(); - bool isValid = false; + bool isValid; if (name[namePosition] == 'J') { @@ -347,7 +345,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return false; } - isValid = GetNum(name, ref namePosition, out rule.Day, 0, DaysPerWekk - 1); + isValid = GetNum(name, ref namePosition, out rule.Day, 0, DaysPerWeek - 1); } else if (char.IsDigit((char)name[namePosition])) { @@ -391,7 +389,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { outRules = new TimeZoneRule(); - int stdLen; + int stdLen; ReadOnlySpan stdName = name; int namePosition = 0; @@ -408,7 +406,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { namePosition++; - stdName = name.Slice(namePosition); + stdName = name[namePosition..]; int stdNamePosition = namePosition; @@ -442,10 +440,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } int charCount = stdLen + 1; - int destLen = 0; + int destLen = 0; int dstOffset = 0; - ReadOnlySpan destName = name.Slice(namePosition); + ReadOnlySpan destName = name[namePosition..]; if (TzCharsArraySize < charCount) { @@ -456,7 +454,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { if (name[namePosition] == '<') { - destName = name.Slice(++namePosition); + destName = name[++namePosition..]; int destNamePosition = namePosition; namePosition = GetQZName(name.ToArray(), namePosition, '>'); @@ -471,9 +469,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } else { - destName = name.Slice(namePosition); + destName = name[namePosition..]; namePosition = GetTZName(name, namePosition); - destLen = namePosition; + destLen = namePosition; } if (destLen == 0) @@ -511,8 +509,8 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { namePosition++; - bool IsRuleValid = GetRule(name, ref namePosition, out Rule start); - if (!IsRuleValid) + bool isRuleValid = GetRule(name, ref namePosition, out Rule start); + if (!isRuleValid) { return false; } @@ -522,8 +520,8 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return false; } - IsRuleValid = GetRule(name, ref namePosition, out Rule end); - if (!IsRuleValid) + isRuleValid = GetRule(name, ref namePosition, out Rule end); + if (!isRuleValid) { return false; } @@ -537,28 +535,28 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone outRules.Ttis[0] = new TimeTypeInfo { - GmtOffset = -dstOffset, - IsDaySavingTime = true, - AbbreviationListIndex = stdLen + 1 + GmtOffset = -dstOffset, + IsDaySavingTime = true, + AbbreviationListIndex = stdLen + 1, }; outRules.Ttis[1] = new TimeTypeInfo { - GmtOffset = -stdOffset, - IsDaySavingTime = false, - AbbreviationListIndex = 0 + GmtOffset = -stdOffset, + IsDaySavingTime = false, + AbbreviationListIndex = 0, }; outRules.DefaultType = 0; - int timeCount = 0; - long janFirst = 0; - int janOffset = 0; - int yearBegining = EpochYear; + int timeCount = 0; + long janFirst = 0; + int janOffset = 0; + int yearBegining = EpochYear; do { - int yearSeconds = YearLengths[IsLeap(yearBegining - 1)] * SecondsPerDay; + int yearSeconds = _yearLengths[IsLeap(yearBegining - 1)] * SecondsPerDay; yearBegining--; if (IncrementOverflow64(ref janFirst, -yearSeconds)) { @@ -573,17 +571,14 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone for (year = yearBegining; year < yearLimit; year++) { int startTime = TransitionTime(year, start, stdOffset); - int endTime = TransitionTime(year, end, dstOffset); + int endTime = TransitionTime(year, end, dstOffset); - int yearSeconds = YearLengths[IsLeap(year)] * SecondsPerDay; + int yearSeconds = _yearLengths[IsLeap(year)] * SecondsPerDay; bool isReversed = endTime < startTime; if (isReversed) { - int swap = startTime; - - startTime = endTime; - endTime = swap; + (endTime, startTime) = (startTime, endTime); } if (isReversed || (startTime < endTime && (endTime - startTime < (yearSeconds + (stdOffset - dstOffset))))) @@ -632,7 +627,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } else if (YearsPerRepeat < year - yearBegining) { - outRules.GoBack = true; + outRules.GoBack = true; outRules.GoAhead = true; } } @@ -653,18 +648,22 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } } - long theirDstOffset = 0; + long theirDstOffset; for (int i = 0; i < outRules.TimeCount; i++) { int j = outRules.Types[i]; if (outRules.Ttis[j].IsDaySavingTime) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment theirDstOffset = -outRules.Ttis[j].GmtOffset; +#pragma warning restore IDE0059 } } bool isDaySavingTime = false; - long theirOffset = theirStdOffset; +#pragma warning disable IDE0059 // Remove unnecessary value assignment + long theirOffset = theirStdOffset; +#pragma warning restore IDE0059 for (int i = 0; i < outRules.TimeCount; i++) { int j = outRules.Types[i]; @@ -684,7 +683,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone theirOffset = -outRules.Ttis[j].GmtOffset; if (outRules.Ttis[j].IsDaySavingTime) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment theirDstOffset = theirOffset; +#pragma warning restore IDE0059 } else { @@ -694,33 +695,33 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone outRules.Ttis[0] = new TimeTypeInfo { - GmtOffset = -stdOffset, - IsDaySavingTime = false, - AbbreviationListIndex = 0 + GmtOffset = -stdOffset, + IsDaySavingTime = false, + AbbreviationListIndex = 0, }; outRules.Ttis[1] = new TimeTypeInfo { - GmtOffset = -dstOffset, - IsDaySavingTime = true, - AbbreviationListIndex = stdLen + 1 + GmtOffset = -dstOffset, + IsDaySavingTime = true, + AbbreviationListIndex = stdLen + 1, }; - outRules.TypeCount = 2; + outRules.TypeCount = 2; outRules.DefaultType = 0; } } else { // default is perpetual standard time - outRules.TypeCount = 1; - outRules.TimeCount = 0; + outRules.TypeCount = 1; + outRules.TimeCount = 0; outRules.DefaultType = 0; - outRules.Ttis[0] = new TimeTypeInfo + outRules.Ttis[0] = new TimeTypeInfo { - GmtOffset = -stdOffset, - IsDaySavingTime = false, - AbbreviationListIndex = 0 + GmtOffset = -stdOffset, + IsDaySavingTime = false, + AbbreviationListIndex = 0, }; } @@ -770,7 +771,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone case RuleType.MonthNthDayOfWeek: // Here we use Zeller's Congruence to get the day of week of the first month. - int m1 = (rule.Month + 9) % 12 + 1; + int m1 = (rule.Month + 9) % 12 + 1; int yy0 = (rule.Month <= 2) ? (year - 1) : year; int yy1 = yy0 / 100; int yy2 = yy0 % 100; @@ -779,7 +780,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (dayOfWeek < 0) { - dayOfWeek += DaysPerWekk; + dayOfWeek += DaysPerWeek; } // Get the zero origin @@ -787,23 +788,23 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (d < 0) { - d += DaysPerWekk; + d += DaysPerWeek; } for (int i = 1; i < rule.Week; i++) { - if (d + DaysPerWekk >= MonthsLengths[leapYear][rule.Month - 1]) + if (d + DaysPerWeek >= _monthsLengths[leapYear][rule.Month - 1]) { break; } - d += DaysPerWekk; + d += DaysPerWeek; } value = d * SecondsPerDay; for (int i = 0; i < rule.Month - 1; i++) { - value += MonthsLengths[leapYear][i] * SecondsPerDay; + value += _monthsLengths[leapYear][i] * SecondsPerDay; } break; @@ -887,7 +888,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { outRules = new TimeZoneRule(); - BinaryReader reader = new BinaryReader(inputData); + BinaryReader reader = new(inputData); long streamLength = reader.BaseStream.Length; @@ -902,10 +903,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone int ttisGMTCount = Detzcode32(header.TtisGMTCount); int ttisSTDCount = Detzcode32(header.TtisSTDCount); - int leapCount = Detzcode32(header.LeapCount); - int timeCount = Detzcode32(header.TimeCount); - int typeCount = Detzcode32(header.TypeCount); - int charCount = Detzcode32(header.CharCount); + int leapCount = Detzcode32(header.LeapCount); + int timeCount = Detzcode32(header.TimeCount); + int typeCount = Detzcode32(header.TypeCount); + int charCount = Detzcode32(header.CharCount); if (!(0 <= leapCount && leapCount < TzMaxLeaps @@ -1053,7 +1054,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } long position = (workBuffer.Length - p.Length); - long nRead = streamLength - position; + long nRead = streamLength - position; if (nRead < 0) { @@ -1077,7 +1078,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone byte[] name = new byte[TzNameMax]; Array.Copy(tempName, 1, name, 0, nRead - 1); - Box tempRulesBox = new Box(); + Box tempRulesBox = new(); ref TimeZoneRule tempRules = ref tempRulesBox.Data; if (ParsePosixName(name, ref tempRulesBox.Data, false)) @@ -1247,17 +1248,17 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone private static ResultCode CreateCalendarTime(long time, int gmtOffset, out CalendarTimeInternal calendarTime, out CalendarAdditionalInfo calendarAdditionalInfo) { - long year = EpochYear; - long timeDays = time / SecondsPerDay; + long year = EpochYear; + long timeDays = time / SecondsPerDay; long remainingSeconds = time % SecondsPerDay; - calendarTime = new CalendarTimeInternal(); + calendarTime = new CalendarTimeInternal(); calendarAdditionalInfo = new CalendarAdditionalInfo(); - while (timeDays < 0 || timeDays >= YearLengths[IsLeap((int)year)]) + while (timeDays < 0 || timeDays >= _yearLengths[IsLeap((int)year)]) { long timeDelta = timeDays / DaysPerLYear; - long delta = timeDelta; + long delta = timeDelta; if (delta == 0) { @@ -1298,12 +1299,12 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return ResultCode.OutOfRange; } - dayOfYear += YearLengths[IsLeap((int)year)]; + dayOfYear += _yearLengths[IsLeap((int)year)]; } - while (dayOfYear >= YearLengths[IsLeap((int)year)]) + while (dayOfYear >= _yearLengths[IsLeap((int)year)]) { - dayOfYear -= YearLengths[IsLeap((int)year)]; + dayOfYear -= _yearLengths[IsLeap((int)year)]; if (IncrementOverflow64(ref year, 1)) { @@ -1311,13 +1312,13 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } } - calendarTime.Year = year; + calendarTime.Year = year; calendarAdditionalInfo.DayOfYear = (uint)dayOfYear; - long dayOfWeek = (EpochWeekDay + ((year - EpochYear) % DaysPerWekk) * (DaysPerNYear % DaysPerWekk) + GetLeapDays(year - 1) - GetLeapDays(EpochYear - 1) + dayOfYear) % DaysPerWekk; + long dayOfWeek = (EpochWeekDay + ((year - EpochYear) % DaysPerWeek) * (DaysPerNYear % DaysPerWeek) + GetLeapDays(year - 1) - GetLeapDays(EpochYear - 1) + dayOfYear) % DaysPerWeek; if (dayOfWeek < 0) { - dayOfWeek += DaysPerWekk; + dayOfWeek += DaysPerWeek; } calendarAdditionalInfo.DayOfWeek = (uint)dayOfWeek; @@ -1328,7 +1329,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone calendarTime.Minute = (sbyte)(remainingSeconds / SecondsPerMinute); calendarTime.Second = (sbyte)(remainingSeconds % SecondsPerMinute); - int[] ip = MonthsLengths[IsLeap((int)year)]; + int[] ip = _monthsLengths[IsLeap((int)year)]; for (calendarTime.Month = 0; dayOfYear >= ip[calendarTime.Month]; ++calendarTime.Month) { @@ -1338,14 +1339,14 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone calendarTime.Day = (sbyte)(dayOfYear + 1); calendarAdditionalInfo.IsDaySavingTime = false; - calendarAdditionalInfo.GmtOffset = gmtOffset; + calendarAdditionalInfo.GmtOffset = gmtOffset; return 0; } private static ResultCode ToCalendarTimeInternal(in TimeZoneRule rules, long time, out CalendarTimeInternal calendarTime, out CalendarAdditionalInfo calendarAdditionalInfo) { - calendarTime = new CalendarTimeInternal(); + calendarTime = new CalendarTimeInternal(); calendarAdditionalInfo = new CalendarAdditionalInfo(); ResultCode result; @@ -1368,7 +1369,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone seconds -= 1; - years = (seconds / SecondsPerRepeat + 1) * YearsPerRepeat; + years = (seconds / SecondsPerRepeat + 1) * YearsPerRepeat; seconds = years * AverageSecondsPerYear; if (time < rules.Ats[0]) @@ -1411,7 +1412,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone } else { - int low = 1; + int low = 1; int high = rules.TimeCount; while (low < high) @@ -1451,7 +1452,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { posixTime = 0; - int hour = calendarTime.Hour; + int hour = calendarTime.Hour; int minute = calendarTime.Minute; if (NormalizeOverflow32(ref hour, ref minute, MinutesPerHour)) @@ -1467,10 +1468,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return ResultCode.Overflow; } - calendarTime.Day = (sbyte)day; + calendarTime.Day = (sbyte)day; calendarTime.Hour = (sbyte)hour; - long year = calendarTime.Year; + long year = calendarTime.Year; long month = calendarTime.Month; if (NormalizeOverflow64(ref year, ref month, MonthsPerYear)) @@ -1499,7 +1500,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone li++; } - day += YearLengths[IsLeap((int)li)]; + day += _yearLengths[IsLeap((int)li)]; } while (day > DaysPerLYear) @@ -1511,7 +1512,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone li++; } - day -= YearLengths[IsLeap((int)li)]; + day -= _yearLengths[IsLeap((int)li)]; if (IncrementOverflow64(ref year, 1)) { @@ -1521,7 +1522,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone while (true) { - int i = MonthsLengths[IsLeap((int)year)][calendarTime.Month]; + int i = _monthsLengths[IsLeap((int)year)][calendarTime.Month]; if (day <= i) { @@ -1573,7 +1574,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone calendarTime.Second = 0; } - long low = long.MinValue; + long low = long.MinValue; long high = long.MaxValue; while (true) @@ -1670,15 +1671,15 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { Time = new CalendarTime() { - Year = (short)calendarTime.Year, + Year = (short)calendarTime.Year, // NOTE: Nintendo's month range is 1-12, internal range is 0-11. Month = (sbyte)(calendarTime.Month + 1), - Day = calendarTime.Day, - Hour = calendarTime.Hour, + Day = calendarTime.Day, + Hour = calendarTime.Hour, Minute = calendarTime.Minute, - Second = calendarTime.Second + Second = calendarTime.Second, }, - AdditionalInfo = calendarAdditionalInfo + AdditionalInfo = calendarAdditionalInfo, }; return result; @@ -1686,18 +1687,18 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone internal static ResultCode ToPosixTime(in TimeZoneRule rules, CalendarTime calendarTime, out long posixTime) { - CalendarTimeInternal calendarTimeInternal = new CalendarTimeInternal() + CalendarTimeInternal calendarTimeInternal = new() { - Year = calendarTime.Year, + Year = calendarTime.Year, // NOTE: Nintendo's month range is 1-12, internal range is 0-11. - Month = (sbyte)(calendarTime.Month - 1), - Day = calendarTime.Day, - Hour = calendarTime.Hour, + Month = (sbyte)(calendarTime.Month - 1), + Day = calendarTime.Day, + Hour = calendarTime.Hour, Minute = calendarTime.Minute, - Second = calendarTime.Second + Second = calendarTime.Second, }; return ToPosixTimeInternal(in rules, calendarTimeInternal, out posixTime); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs index 9367024e4..67cb286ae 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs @@ -11,7 +11,6 @@ using Ryujinx.Cpu; using Ryujinx.HLE.Exceptions; using Ryujinx.HLE.FileSystem; using Ryujinx.HLE.HOS.Services.Time.Clock; -using Ryujinx.HLE.Utilities; using System; using System.Collections.Generic; using System.IO; @@ -24,11 +23,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { private const long TimeZoneBinaryTitleId = 0x010000000000080E; - private readonly string TimeZoneSystemTitleMissingErrorMessage = "TimeZoneBinary system title not found! TimeZone conversions will not work, provide the system archive to fix this error. (See https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide#initial-setup-continued---installation-of-firmware for more information)"; + private const string TimeZoneSystemTitleMissingErrorMessage = "TimeZoneBinary system title not found! TimeZone conversions will not work, provide the system archive to fix this error. (See https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide#initial-setup-continued---installation-of-firmware for more information)"; - private VirtualFileSystem _virtualFileSystem; + private VirtualFileSystem _virtualFileSystem; private IntegrityCheckLevel _fsIntegrityCheckLevel; - private ContentManager _contentManager; + private ContentManager _contentManager; public string[] LocationNameCache { get; private set; } @@ -41,8 +40,8 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public void InitializeInstance(VirtualFileSystem virtualFileSystem, ContentManager contentManager, IntegrityCheckLevel fsIntegrityCheckLevel) { - _virtualFileSystem = virtualFileSystem; - _contentManager = contentManager; + _virtualFileSystem = virtualFileSystem; + _contentManager = contentManager; _fsIntegrityCheckLevel = fsIntegrityCheckLevel; InitializeLocationNameCache(); @@ -90,31 +89,30 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { if (HasTimeZoneBinaryTitle()) { - using (IStorage ncaFileStream = new LocalStorage(_virtualFileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open)) + using IStorage ncaFileStream = new LocalStorage(VirtualFileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open); + + Nca nca = new(_virtualFileSystem.KeySet, ncaFileStream); + IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel); + + using var binaryListFile = new UniqueRef(); + + romfs.OpenFile(ref binaryListFile.Ref, "/binaryList.txt".ToU8Span(), OpenMode.Read).ThrowIfFailure(); + + StreamReader reader = new(binaryListFile.Get.AsStream()); + + List locationNameList = new(); + + string locationName; + while ((locationName = reader.ReadLine()) != null) { - Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFileStream); - IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel); - - using var binaryListFile = new UniqueRef(); - - romfs.OpenFile(ref binaryListFile.Ref, "/binaryList.txt".ToU8Span(), OpenMode.Read).ThrowIfFailure(); - - StreamReader reader = new StreamReader(binaryListFile.Get.AsStream()); - - List locationNameList = new List(); - - string locationName; - while ((locationName = reader.ReadLine()) != null) - { - locationNameList.Add(locationName); - } - - LocationNameCache = locationNameList.ToArray(); + locationNameList.Add(locationName); } + + LocationNameCache = locationNameList.ToArray(); } else { - LocationNameCache = new string[] { "UTC" }; + LocationNameCache = new[] { "UTC" }; Logger.Error?.Print(LogClass.ServiceTime, TimeZoneSystemTitleMissingErrorMessage); } @@ -129,9 +127,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone return new[] { (0, "UTC", "UTC") }; } - List<(int Offset, string Location, string Abbr)> outList = new List<(int Offset, string Location, string Abbr)>(); + List<(int Offset, string Location, string Abbr)> outList = new(); var now = DateTimeOffset.Now.ToUnixTimeSeconds(); - using (IStorage ncaStorage = new LocalStorage(_virtualFileSystem.SwitchPathToSystemPath(tzBinaryContentPath), FileAccess.Read, FileMode.Open)) + using (IStorage ncaStorage = new LocalStorage(VirtualFileSystem.SwitchPathToSystemPath(tzBinaryContentPath), FileAccess.Read, FileMode.Open)) using (IFileSystem romfs = new Nca(_virtualFileSystem.KeySet, ncaStorage).OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel)) { foreach (string locName in LocationNameCache) @@ -149,7 +147,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone continue; } - TimeZoneRuleBox tzRuleBox = new TimeZoneRuleBox(); + TimeZoneRuleBox tzRuleBox = new(); ref TimeZoneRule tzRule = ref tzRuleBox.Data; TimeZone.ParseTimeZoneBinary(ref tzRule, tzif.Get.AsStream()); @@ -219,7 +217,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public ResultCode LoadLocationNameList(uint index, out string[] outLocationNameArray, uint maxLength) { - List locationNameList = new List(); + List locationNameList = new(); for (int i = 0; i < LocationNameCache.Length && i < maxLength; i++) { @@ -259,16 +257,16 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone internal ResultCode GetTimeZoneBinary(string locationName, out Stream timeZoneBinaryStream, out LocalStorage ncaFile) { timeZoneBinaryStream = null; - ncaFile = null; + ncaFile = null; if (!HasTimeZoneBinaryTitle() || !IsLocationNameValid(locationName)) { return ResultCode.TimeZoneNotFound; } - ncaFile = new LocalStorage(_virtualFileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open); + ncaFile = new LocalStorage(VirtualFileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open); - Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile); + Nca nca = new(_virtualFileSystem.KeySet, ncaFile); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel); using var timeZoneBinaryFile = new UniqueRef(); diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs index 8b85d697b..219b1d9fb 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs @@ -7,20 +7,20 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { class TimeZoneManager { - private bool _isInitialized; - private Box _myRules; - private string _deviceLocationName; - private UInt128 _timeZoneRuleVersion; - private uint _totalLocationNameCount; + private bool _isInitialized; + private Box _myRules; + private string _deviceLocationName; + private UInt128 _timeZoneRuleVersion; + private uint _totalLocationNameCount; private SteadyClockTimePoint _timeZoneUpdateTimePoint; - private readonly object _lock = new(); + private readonly object _lock = new(); public TimeZoneManager() { - _isInitialized = false; - _deviceLocationName = "UTC"; + _isInitialized = false; + _deviceLocationName = "UTC"; _timeZoneRuleVersion = new UInt128(); - _myRules = new Box(); + _myRules = new Box(); _timeZoneUpdateTimePoint = SteadyClockTimePoint.GetRandom(); } @@ -56,7 +56,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (_isInitialized) { deviceLocationName = _deviceLocationName; - result = ResultCode.Success; + result = ResultCode.Success; } } @@ -69,15 +69,15 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone lock (_lock) { - Box rules = new Box(); + Box rules = new(); bool timeZoneConversionSuccess = TimeZone.ParseTimeZoneBinary(ref rules.Data, timeZoneBinaryStream); if (timeZoneConversionSuccess) { _deviceLocationName = locationName; - _myRules = rules; - result = ResultCode.Success; + _myRules = rules; + result = ResultCode.Success; } } @@ -103,7 +103,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (_isInitialized) { totalLocationNameCount = _totalLocationNameCount; - result = ResultCode.Success; + result = ResultCode.Success; } } @@ -119,7 +119,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (_isInitialized || bypassUninitialized) { _timeZoneUpdateTimePoint = timeZoneUpdatedTimePoint; - result = ResultCode.Success; + result = ResultCode.Success; } } @@ -135,12 +135,12 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (_isInitialized) { timeZoneUpdatedTimePoint = _timeZoneUpdateTimePoint; - result = ResultCode.Success; + result = ResultCode.Success; } else { timeZoneUpdatedTimePoint = SteadyClockTimePoint.GetRandom(); - result = ResultCode.UninitializedClock; + result = ResultCode.UninitializedClock; } } @@ -181,12 +181,12 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone if (_isInitialized) { timeZoneRuleVersion = _timeZoneRuleVersion; - result = ResultCode.Success; + result = ResultCode.Success; } else { timeZoneRuleVersion = new UInt128(); - result = ResultCode.UninitializedClock; + result = ResultCode.UninitializedClock; } } @@ -206,7 +206,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone else { calendar = new CalendarInfo(); - result = ResultCode.UninitializedClock; + result = ResultCode.UninitializedClock; } } @@ -238,7 +238,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone else { posixTime = 0; - result = ResultCode.UninitializedClock; + result = ResultCode.UninitializedClock; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarAdditionalInfo.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarAdditionalInfo.cs index a84a27859..8e7dc6d52 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarAdditionalInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarAdditionalInfo.cs @@ -18,4 +18,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public int GmtOffset; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarInfo.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarInfo.cs index 68e6245b3..7fc6f7a09 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarInfo.cs @@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone [StructLayout(LayoutKind.Sequential, Pack = 0x4, Size = 0x20, CharSet = CharSet.Ansi)] struct CalendarInfo { - public CalendarTime Time; + public CalendarTime Time; public CalendarAdditionalInfo AdditionalInfo; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarTime.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarTime.cs index d594223d4..fa082bde5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarTime.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/CalendarTime.cs @@ -12,4 +12,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public sbyte Minute; public sbyte Second; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeTypeInfo.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeTypeInfo.cs index b8b3d9171..47620f563 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeTypeInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeTypeInfo.cs @@ -25,4 +25,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public ushort Padding2; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeZoneRule.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeZoneRule.cs index 67237f3d2..b8dd2382a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeZoneRule.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeZoneRule.cs @@ -53,4 +53,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public int DefaultType; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TzifHeader.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TzifHeader.cs index 022c34a93..1d05ee246 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TzifHeader.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TzifHeader.cs @@ -16,4 +16,4 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public int TypeCount; public int CharCount; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Types/SteadyClockContext.cs b/src/Ryujinx.HLE/HOS/Services/Time/Types/SteadyClockContext.cs index 38d37055c..2b80604ac 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Types/SteadyClockContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Types/SteadyClockContext.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Types [StructLayout(LayoutKind.Sequential, Pack = 1)] struct SteadyClockContext { - public ulong InternalOffset; + public ulong InternalOffset; public UInt128 ClockSourceId; } } diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Types/TimePermissions.cs b/src/Ryujinx.HLE/HOS/Services/Time/Types/TimePermissions.cs index 3fcd3a144..34749c425 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Types/TimePermissions.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Types/TimePermissions.cs @@ -5,18 +5,18 @@ namespace Ryujinx.HLE.HOS.Services.Time [Flags] enum TimePermissions { - LocalSystemClockWritableMask = 0x1, - UserSystemClockWritableMask = 0x2, + LocalSystemClockWritableMask = 0x1, + UserSystemClockWritableMask = 0x2, NetworkSystemClockWritableMask = 0x4, - TimeZoneWritableMask = 0x8, - SteadyClockWritableMask = 0x10, - BypassUninitialized = 0x20, + TimeZoneWritableMask = 0x8, + SteadyClockWritableMask = 0x10, + BypassUninitialized = 0x20, - User = 0, - Admin = LocalSystemClockWritableMask | UserSystemClockWritableMask | TimeZoneWritableMask, - System = NetworkSystemClockWritableMask, + User = 0, + Admin = LocalSystemClockWritableMask | UserSystemClockWritableMask | TimeZoneWritableMask, + System = NetworkSystemClockWritableMask, SystemUpdate = BypassUninitialized, - Repair = SteadyClockWritableMask, - Manufacture = LocalSystemClockWritableMask | UserSystemClockWritableMask | NetworkSystemClockWritableMask | TimeZoneWritableMask | SteadyClockWritableMask + Repair = SteadyClockWritableMask, + Manufacture = LocalSystemClockWritableMask | UserSystemClockWritableMask | NetworkSystemClockWritableMask | TimeZoneWritableMask | SteadyClockWritableMask, } } diff --git a/src/Ryujinx.HLE/HOS/Services/Usb/IClientRootSession.cs b/src/Ryujinx.HLE/HOS/Services/Usb/IClientRootSession.cs index 56b12af08..b41b8a48c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Usb/IClientRootSession.cs +++ b/src/Ryujinx.HLE/HOS/Services/Usb/IClientRootSession.cs @@ -6,4 +6,4 @@ { public IClientRootSession(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Usb/IDsService.cs b/src/Ryujinx.HLE/HOS/Services/Usb/IDsService.cs index 4dbb6fc1d..ee6c8f070 100644 --- a/src/Ryujinx.HLE/HOS/Services/Usb/IDsService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Usb/IDsService.cs @@ -5,4 +5,4 @@ { public IDsService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Usb/IPdCradleManager.cs b/src/Ryujinx.HLE/HOS/Services/Usb/IPdCradleManager.cs index cecdbc313..18cbce79a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Usb/IPdCradleManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Usb/IPdCradleManager.cs @@ -5,4 +5,4 @@ { public IPdCradleManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Usb/IPdManager.cs b/src/Ryujinx.HLE/HOS/Services/Usb/IPdManager.cs index 1fb574d29..011debafd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Usb/IPdManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Usb/IPdManager.cs @@ -5,4 +5,4 @@ { public IPdManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Usb/IPmService.cs b/src/Ryujinx.HLE/HOS/Services/Usb/IPmService.cs index 38beee079..ed6bba694 100644 --- a/src/Ryujinx.HLE/HOS/Services/Usb/IPmService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Usb/IPmService.cs @@ -5,4 +5,4 @@ { public IPmService(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Usb/IUnknown1.cs b/src/Ryujinx.HLE/HOS/Services/Usb/IUnknown1.cs index 0981e4ff4..65bf1c9fa 100644 --- a/src/Ryujinx.HLE/HOS/Services/Usb/IUnknown1.cs +++ b/src/Ryujinx.HLE/HOS/Services/Usb/IUnknown1.cs @@ -5,4 +5,4 @@ { public IUnknown1(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Usb/IUnknown2.cs b/src/Ryujinx.HLE/HOS/Services/Usb/IUnknown2.cs index 563696bb8..e0bf0bf4a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Usb/IUnknown2.cs +++ b/src/Ryujinx.HLE/HOS/Services/Usb/IUnknown2.cs @@ -5,4 +5,4 @@ { public IUnknown2(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/IApplicationRootService.cs b/src/Ryujinx.HLE/HOS/Services/Vi/IApplicationRootService.cs index 526cecf84..9cc9d421f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/IApplicationRootService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/IApplicationRootService.cs @@ -24,4 +24,4 @@ namespace Ryujinx.HLE.HOS.Services.Vi return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/IManagerRootService.cs b/src/Ryujinx.HLE/HOS/Services/Vi/IManagerRootService.cs index d564dabe7..dd4b25a08 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/IManagerRootService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/IManagerRootService.cs @@ -25,4 +25,4 @@ namespace Ryujinx.HLE.HOS.Services.Vi return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/ISystemRootService.cs b/src/Ryujinx.HLE/HOS/Services/Vi/ISystemRootService.cs index 0dfd84f59..b2415f2e4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/ISystemRootService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/ISystemRootService.cs @@ -25,4 +25,4 @@ namespace Ryujinx.HLE.HOS.Services.Vi return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Vi/ResultCode.cs index c64339c91..3bed7e57d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/ResultCode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/ResultCode.cs @@ -2,16 +2,16 @@ namespace Ryujinx.HLE.HOS.Services.Vi { enum ResultCode { - ModuleId = 114, + ModuleId = 114, ErrorCodeShift = 9, Success = 0, - InvalidArguments = (1 << ErrorCodeShift) | ModuleId, - InvalidLayerSize = (4 << ErrorCodeShift) | ModuleId, - PermissionDenied = (5 << ErrorCodeShift) | ModuleId, + InvalidArguments = (1 << ErrorCodeShift) | ModuleId, + InvalidLayerSize = (4 << ErrorCodeShift) | ModuleId, + PermissionDenied = (5 << ErrorCodeShift) | ModuleId, InvalidScalingMode = (6 << ErrorCodeShift) | ModuleId, - InvalidValue = (7 << ErrorCodeShift) | ModuleId, - AlreadyOpened = (9 << ErrorCodeShift) | ModuleId + InvalidValue = (7 << ErrorCodeShift) | ModuleId, + AlreadyOpened = (9 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/AndroidSurfaceComposerClient.cs b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/AndroidSurfaceComposerClient.cs index 1fa99e65a..782bb7d7e 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/AndroidSurfaceComposerClient.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/AndroidSurfaceComposerClient.cs @@ -1,6 +1,6 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService { - static class AndroidSurfaceComposerClient + class AndroidSurfaceComposerClient { // NOTE: This is android::SurfaceComposerClient::getDisplayInfo. public static (ulong, ulong) GetDisplayInfo(ServiceCtx context, ulong displayId = 0) @@ -16,4 +16,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/IManagerDisplayService.cs b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/IManagerDisplayService.cs index 6093381cc..3a08cdd78 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/IManagerDisplayService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/IManagerDisplayService.cs @@ -4,7 +4,9 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService { class IManagerDisplayService : IpcService { - private IApplicationDisplayService _applicationDisplayService; +#pragma warning disable IDE0052 // Remove unread private member + private readonly IApplicationDisplayService _applicationDisplayService; +#pragma warning restore IDE0052 public IManagerDisplayService(IApplicationDisplayService applicationDisplayService) { @@ -29,8 +31,10 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService // CreateManagedLayer(u32, u64, nn::applet::AppletResourceUserId) -> u64 public ResultCode CreateManagedLayer(ServiceCtx context) { - long layerFlags = context.RequestData.ReadInt64(); - long displayId = context.RequestData.ReadInt64(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + long layerFlags = context.RequestData.ReadInt64(); + long displayId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 long appletResourceUserId = context.RequestData.ReadInt64(); ulong pid = context.Device.System.AppletState.AppletResourceUserIds.GetData((int)appletResourceUserId); @@ -77,4 +81,4 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/ISystemDisplayService.cs b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/ISystemDisplayService.cs index a24aa0798..12ac2cf4a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/ISystemDisplayService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/ISystemDisplayService.cs @@ -4,7 +4,9 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService { class ISystemDisplayService : IpcService { - private IApplicationDisplayService _applicationDisplayService; +#pragma warning disable IDE0052 // Remove unread private member + private readonly IApplicationDisplayService _applicationDisplayService; +#pragma warning restore IDE0052 public ISystemDisplayService(IApplicationDisplayService applicationDisplayService) { @@ -56,4 +58,4 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/DestinationScalingMode.cs b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/DestinationScalingMode.cs index cf459cb2e..c712bb1d3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/DestinationScalingMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/DestinationScalingMode.cs @@ -6,6 +6,6 @@ ScaleToWindow, ScaleAndCrop, None, - PreserveAspectRatio + PreserveAspectRatio, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/DisplayInfo.cs b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/DisplayInfo.cs index d46206d4a..eae8a8001 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/DisplayInfo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/DisplayInfo.cs @@ -7,10 +7,10 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService.Type struct DisplayInfo { public Array64 Name; - public bool LayerLimitEnabled; - public Array7 Padding; - public ulong LayerLimitMax; - public ulong Width; - public ulong Height; + public bool LayerLimitEnabled; + public Array7 Padding; + public ulong LayerLimitMax; + public ulong Width; + public ulong Height; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/SourceScalingMode.cs b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/SourceScalingMode.cs index ac8c3e027..536c0d46f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/SourceScalingMode.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/Types/SourceScalingMode.cs @@ -6,6 +6,6 @@ Freeze, ScaleToWindow, ScaleAndCrop, - PreserveAspectRatio + PreserveAspectRatio, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/IApplicationDisplayService.cs b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/IApplicationDisplayService.cs index 89eed5b57..3fbd7d20d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/RootService/IApplicationDisplayService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/RootService/IApplicationDisplayService.cs @@ -3,7 +3,6 @@ using Ryujinx.Common.Logging; using Ryujinx.Common.Memory; using Ryujinx.HLE.HOS.Applets; using Ryujinx.HLE.HOS.Ipc; -using Ryujinx.HLE.HOS.Kernel.Common; using Ryujinx.HLE.HOS.Services.SurfaceFlinger; using Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService; using Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService.Types; @@ -27,27 +26,27 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService public int RetrievedEventsCount; } - private readonly List _displayInfo; + private readonly List _displayInfo; private readonly Dictionary _openDisplays; private int _vsyncEventHandle; public IApplicationDisplayService(ViServiceType serviceType) { - _serviceType = serviceType; - _displayInfo = new List(); + _serviceType = serviceType; + _displayInfo = new List(); _openDisplays = new Dictionary(); void AddDisplayInfo(string name, bool layerLimitEnabled, ulong layerLimitMax, ulong width, ulong height) { - DisplayInfo displayInfo = new DisplayInfo() + DisplayInfo displayInfo = new() { - Name = new Array64(), + Name = new Array64(), LayerLimitEnabled = layerLimitEnabled, - Padding = new Array7(), - LayerLimitMax = layerLimitMax, - Width = width, - Height = height + Padding = new Array7(), + LayerLimitMax = layerLimitMax, + Width = width, + Height = height, }; Encoding.ASCII.GetBytes(name).AsSpan().CopyTo(displayInfo.Name.AsSpan()); @@ -55,11 +54,11 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService _displayInfo.Add(displayInfo); } - AddDisplayInfo("Default", true, 1, 1920, 1080); - AddDisplayInfo("External", true, 1, 1920, 1080); - AddDisplayInfo("Edid", true, 1, 0, 0); - AddDisplayInfo("Internal", true, 1, 1920, 1080); - AddDisplayInfo("Null", false, 0, 1920, 1080); + AddDisplayInfo("Default", true, 1, 1920, 1080); + AddDisplayInfo("External", true, 1, 1920, 1080); + AddDisplayInfo("Edid", true, 1, 0, 0); + AddDisplayInfo("Internal", true, 1, 1920, 1080); + AddDisplayInfo("Null", false, 0, 1920, 1080); } [CommandCmif(100)] @@ -232,10 +231,14 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService public ResultCode OpenLayer(ServiceCtx context) { // TODO: support multi display. +#pragma warning disable IDE0059 // Remove unnecessary value assignment byte[] displayName = context.RequestData.ReadBytes(0x40); +#pragma warning restore IDE0059 - long layerId = context.RequestData.ReadInt64(); - long userId = context.RequestData.ReadInt64(); + long layerId = context.RequestData.ReadInt64(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + long userId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 ulong parcelPtr = context.Request.ReceiveBuff[0].Position; ResultCode result = context.Device.System.SurfaceFlinger.OpenLayer(context.Request.HandleDesc.PId, layerId, out IBinder producer); @@ -247,7 +250,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService context.Device.System.SurfaceFlinger.SetRenderLayer(layerId); - Parcel parcel = new Parcel(0x28, 0x4); + Parcel parcel = new(0x28, 0x4); parcel.WriteObject(producer, "dispdrv\0"); @@ -273,8 +276,10 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService // CreateStrayLayer(u32, u64) -> (u64, u64, buffer) public ResultCode CreateStrayLayer(ServiceCtx context) { +#pragma warning disable IDE0059 // Remove unnecessary value assignment long layerFlags = context.RequestData.ReadInt64(); - long displayId = context.RequestData.ReadInt64(); + long displayId = context.RequestData.ReadInt64(); +#pragma warning restore IDE0059 ulong parcelPtr = context.Request.ReceiveBuff[0].Position; @@ -283,7 +288,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService context.Device.System.SurfaceFlinger.SetRenderLayer(layerId); - Parcel parcel = new Parcel(0x28, 0x4); + Parcel parcel = new(0x28, 0x4); parcel.WriteObject(producer, "dispdrv\0"); @@ -327,10 +332,10 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService DestinationScalingMode? convertedScalingMode = scalingMode switch { - SourceScalingMode.None => DestinationScalingMode.None, - SourceScalingMode.Freeze => DestinationScalingMode.Freeze, - SourceScalingMode.ScaleAndCrop => DestinationScalingMode.ScaleAndCrop, - SourceScalingMode.ScaleToWindow => DestinationScalingMode.ScaleToWindow, + SourceScalingMode.None => DestinationScalingMode.None, + SourceScalingMode.Freeze => DestinationScalingMode.Freeze, + SourceScalingMode.ScaleAndCrop => DestinationScalingMode.ScaleAndCrop, + SourceScalingMode.ScaleToWindow => DestinationScalingMode.ScaleToWindow, SourceScalingMode.PreserveAspectRatio => DestinationScalingMode.PreserveAspectRatio, _ => null, }; @@ -354,13 +359,13 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService private ulong GetA8B8G8R8LayerSize(int width, int height, out int pitch, out int alignment) { - const int DefaultAlignment = 0x1000; - const ulong DefaultSize = 0x20000; + const int DefaultAlignment = 0x1000; + const ulong DefaultSize = 0x20000; alignment = DefaultAlignment; - pitch = BitUtils.AlignUp(BitUtils.DivRoundUp(width * 32, 8), 64); + pitch = BitUtils.AlignUp(BitUtils.DivRoundUp(width * 32, 8), 64); - int memorySize = pitch * BitUtils.AlignUp(height, 64); + int memorySize = pitch * BitUtils.AlignUp(height, 64); ulong requiredMemorySize = (ulong)BitUtils.AlignUp(memorySize, alignment); return (requiredMemorySize + DefaultSize - 1) / DefaultSize * DefaultSize; @@ -373,18 +378,18 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService // The size of the layer buffer should be an aligned multiple of width * height // because it was created using GetIndirectLayerImageRequiredMemoryInfo as a guide. - long layerWidth = context.RequestData.ReadInt64(); - long layerHeight = context.RequestData.ReadInt64(); - long layerHandle = context.RequestData.ReadInt64(); + long layerWidth = context.RequestData.ReadInt64(); + long layerHeight = context.RequestData.ReadInt64(); + long layerHandle = context.RequestData.ReadInt64(); ulong layerBuffPosition = context.Request.ReceiveBuff[0].Position; - ulong layerBuffSize = context.Request.ReceiveBuff[0].Size; + ulong layerBuffSize = context.Request.ReceiveBuff[0].Size; // Get the pitch of the layer that is necessary to render correctly. ulong size = GetA8B8G8R8LayerSize((int)layerWidth, (int)layerHeight, out int pitch, out _); Debug.Assert(layerBuffSize == size); - RenderingSurfaceInfo surfaceInfo = new RenderingSurfaceInfo(ColorFormat.A8B8G8R8, (uint)layerWidth, (uint)layerHeight, (uint)pitch, (uint)layerBuffSize); + RenderingSurfaceInfo surfaceInfo = new(ColorFormat.A8B8G8R8, (uint)layerWidth, (uint)layerHeight, (uint)pitch, (uint)layerBuffSize); // Get the applet associated with the handle. object appletObject = context.Device.System.AppletState.IndirectLayerHandles.GetData((int)layerHandle); @@ -425,7 +430,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService } */ - int width = (int)context.RequestData.ReadUInt64(); + int width = (int)context.RequestData.ReadUInt64(); int height = (int)context.RequestData.ReadUInt64(); if (height < 0 || width < 0) @@ -445,7 +450,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService // NOTE: The official service setup a A8B8G8R8 texture with a linear layout and then query its size. // As we don't need this texture on the emulator, we can just simplify this logic and directly // do a linear layout size calculation. (stride * height * bytePerPixel) - ulong size = GetA8B8G8R8LayerSize(width, height, out int pitch, out int alignment); + ulong size = GetA8B8G8R8LayerSize(width, height, out _, out int alignment); context.ResponseData.Write(size); context.ResponseData.Write(alignment); diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/Types/ViServiceType.cs b/src/Ryujinx.HLE/HOS/Services/Vi/Types/ViServiceType.cs index ba6f8e5f8..41c8bbfaf 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/Types/ViServiceType.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/Types/ViServiceType.cs @@ -4,6 +4,6 @@ { Application, Manager, - System + System, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Wlan/IInfraManager.cs b/src/Ryujinx.HLE/HOS/Services/Wlan/IInfraManager.cs index 0416868a8..a84625780 100644 --- a/src/Ryujinx.HLE/HOS/Services/Wlan/IInfraManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Wlan/IInfraManager.cs @@ -5,4 +5,4 @@ { public IInfraManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalGetActionFrame.cs b/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalGetActionFrame.cs index 6c2e20a45..060e5854d 100644 --- a/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalGetActionFrame.cs +++ b/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalGetActionFrame.cs @@ -5,4 +5,4 @@ { public ILocalGetActionFrame(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalGetFrame.cs b/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalGetFrame.cs index a224a192d..d726b7d49 100644 --- a/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalGetFrame.cs +++ b/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalGetFrame.cs @@ -5,4 +5,4 @@ { public ILocalGetFrame(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalManager.cs b/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalManager.cs index 4cc2c4b2e..3db07ac73 100644 --- a/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Wlan/ILocalManager.cs @@ -5,4 +5,4 @@ { public ILocalManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Wlan/ISocketGetFrame.cs b/src/Ryujinx.HLE/HOS/Services/Wlan/ISocketGetFrame.cs index ab5b21933..5c9329234 100644 --- a/src/Ryujinx.HLE/HOS/Services/Wlan/ISocketGetFrame.cs +++ b/src/Ryujinx.HLE/HOS/Services/Wlan/ISocketGetFrame.cs @@ -5,4 +5,4 @@ { public ISocketGetFrame(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Wlan/ISocketManager.cs b/src/Ryujinx.HLE/HOS/Services/Wlan/ISocketManager.cs index afa1bede2..1b40b80e4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Wlan/ISocketManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Wlan/ISocketManager.cs @@ -5,4 +5,4 @@ { public ISocketManager(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Wlan/IUnknown1.cs b/src/Ryujinx.HLE/HOS/Services/Wlan/IUnknown1.cs index dfae18e5d..731f8c0a9 100644 --- a/src/Ryujinx.HLE/HOS/Services/Wlan/IUnknown1.cs +++ b/src/Ryujinx.HLE/HOS/Services/Wlan/IUnknown1.cs @@ -5,4 +5,4 @@ { public IUnknown1(ServiceCtx context) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs b/src/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs index 5704ef4b0..a2837e207 100644 --- a/src/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs +++ b/src/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs @@ -18,7 +18,7 @@ namespace Ryujinx.HLE.HOS.SystemState public AppletStateMgr(Horizon system) { - Messages = new ConcurrentQueue(); + Messages = new ConcurrentQueue(); MessageEvent = new KEvent(system.KernelContext); AppletResourceUserIds = new IdDictionary(); @@ -39,4 +39,4 @@ namespace Ryujinx.HLE.HOS.SystemState MessageEvent.ReadableEvent.Signal(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/SystemState/ColorSet.cs b/src/Ryujinx.HLE/HOS/SystemState/ColorSet.cs index 4d7a7e2f0..b19242065 100644 --- a/src/Ryujinx.HLE/HOS/SystemState/ColorSet.cs +++ b/src/Ryujinx.HLE/HOS/SystemState/ColorSet.cs @@ -3,6 +3,6 @@ namespace Ryujinx.HLE.HOS.SystemState public enum ColorSet { BasicWhite = 0, - BasicBlack = 1 + BasicBlack = 1, } } diff --git a/src/Ryujinx.HLE/HOS/SystemState/KeyboardLayout.cs b/src/Ryujinx.HLE/HOS/SystemState/KeyboardLayout.cs index ba35ea6bc..e3cb68a23 100644 --- a/src/Ryujinx.HLE/HOS/SystemState/KeyboardLayout.cs +++ b/src/Ryujinx.HLE/HOS/SystemState/KeyboardLayout.cs @@ -20,6 +20,6 @@ namespace Ryujinx.HLE.HOS.SystemState ChineseTraditional, Min = Default, - Max = ChineseTraditional + Max = ChineseTraditional, } } diff --git a/src/Ryujinx.HLE/HOS/SystemState/RegionCode.cs b/src/Ryujinx.HLE/HOS/SystemState/RegionCode.cs index dd6ed8fac..111227237 100644 --- a/src/Ryujinx.HLE/HOS/SystemState/RegionCode.cs +++ b/src/Ryujinx.HLE/HOS/SystemState/RegionCode.cs @@ -12,6 +12,6 @@ namespace Ryujinx.HLE.HOS.SystemState Taiwan, Min = Japan, - Max = Taiwan + Max = Taiwan, } } diff --git a/src/Ryujinx.HLE/HOS/SystemState/SystemLanguage.cs b/src/Ryujinx.HLE/HOS/SystemState/SystemLanguage.cs index 3f755105b..f5b7fc0f1 100644 --- a/src/Ryujinx.HLE/HOS/SystemState/SystemLanguage.cs +++ b/src/Ryujinx.HLE/HOS/SystemState/SystemLanguage.cs @@ -19,6 +19,6 @@ namespace Ryujinx.HLE.HOS.SystemState LatinAmericanSpanish, SimplifiedChinese, TraditionalChinese, - BrazilianPortuguese + BrazilianPortuguese, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs b/src/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs index 6627700f5..c650fe036 100644 --- a/src/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs +++ b/src/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs @@ -4,8 +4,7 @@ namespace Ryujinx.HLE.HOS.SystemState { public class SystemStateMgr { - internal static string[] LanguageCodes = new string[] - { + internal static string[] LanguageCodes = { "ja", "en-US", "fr", @@ -23,7 +22,7 @@ namespace Ryujinx.HLE.HOS.SystemState "es-419", "zh-Hans", "zh-Hant", - "pt-BR" + "pt-BR", }; internal long DesiredKeyboardLayout { get; private set; } @@ -46,21 +45,21 @@ namespace Ryujinx.HLE.HOS.SystemState { // TODO: Let user specify fields. DesiredKeyboardLayout = (long)KeyboardLayout.Default; - DeviceNickName = "Ryujinx's Switch"; + DeviceNickName = "Ryujinx's Switch"; } public void SetLanguage(SystemLanguage language) { DesiredSystemLanguage = language; - DesiredLanguageCode = GetLanguageCode((int)DesiredSystemLanguage); + DesiredLanguageCode = GetLanguageCode((int)DesiredSystemLanguage); DesiredTitleLanguage = language switch { SystemLanguage.Taiwanese or SystemLanguage.TraditionalChinese => TitleLanguage.TraditionalChinese, SystemLanguage.Chinese or - SystemLanguage.SimplifiedChinese => TitleLanguage.SimplifiedChinese, - _ => Enum.Parse(Enum.GetName(language)), + SystemLanguage.SimplifiedChinese => TitleLanguage.SimplifiedChinese, + _ => Enum.Parse(Enum.GetName(language)), }; } @@ -76,8 +75,8 @@ namespace Ryujinx.HLE.HOS.SystemState throw new ArgumentOutOfRangeException(nameof(index)); } - long code = 0; - int shift = 0; + long code = 0; + int shift = 0; foreach (char chr in LanguageCodes[index]) { @@ -87,4 +86,4 @@ namespace Ryujinx.HLE.HOS.SystemState return code; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/SystemState/TitleLanguage.cs b/src/Ryujinx.HLE/HOS/SystemState/TitleLanguage.cs index c612259b3..5a0b9f8c2 100644 --- a/src/Ryujinx.HLE/HOS/SystemState/TitleLanguage.cs +++ b/src/Ryujinx.HLE/HOS/SystemState/TitleLanguage.cs @@ -17,6 +17,6 @@ Korean, TraditionalChinese, SimplifiedChinese, - BrazilianPortuguese + BrazilianPortuguese, } } diff --git a/src/Ryujinx.HLE/HOS/Tamper/AtmosphereCompiler.cs b/src/Ryujinx.HLE/HOS/Tamper/AtmosphereCompiler.cs index 7d7af2085..e25ba7a55 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/AtmosphereCompiler.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/AtmosphereCompiler.cs @@ -9,29 +9,28 @@ namespace Ryujinx.HLE.HOS.Tamper { class AtmosphereCompiler { - private ulong _exeAddress; - private ulong _heapAddress; - private ulong _aliasAddress; - private ulong _aslrAddress; - private ITamperedProcess _process; + private readonly ulong _exeAddress; + private readonly ulong _heapAddress; + private readonly ulong _aliasAddress; + private readonly ulong _aslrAddress; + private readonly ITamperedProcess _process; public AtmosphereCompiler(ulong exeAddress, ulong heapAddress, ulong aliasAddress, ulong aslrAddress, ITamperedProcess process) { - _exeAddress = exeAddress; - _heapAddress = heapAddress; + _exeAddress = exeAddress; + _heapAddress = heapAddress; _aliasAddress = aliasAddress; - _aslrAddress = aslrAddress; - _process = process; + _aslrAddress = aslrAddress; + _process = process; } public ITamperProgram Compile(string name, IEnumerable rawInstructions) { - string[] addresses = new string[] - { + string[] addresses = { $" Executable address: 0x{_exeAddress:X16}", $" Heap address : 0x{_heapAddress:X16}", $" Alias address : 0x{_aliasAddress:X16}", - $" Aslr address : 0x{_aslrAddress:X16}" + $" Aslr address : 0x{_aslrAddress:X16}", }; Logger.Debug?.Print(LogClass.TamperMachine, $"Compiling Atmosphere cheat {name}...\n{string.Join('\n', addresses)}"); @@ -40,14 +39,14 @@ namespace Ryujinx.HLE.HOS.Tamper { return CompileImpl(name, rawInstructions); } - catch(TamperCompilationException exception) + catch (TamperCompilationException ex) { // Just print the message without the stack trace. - Logger.Error?.Print(LogClass.TamperMachine, exception.Message); + Logger.Error?.Print(LogClass.TamperMachine, ex.Message); } - catch (Exception exception) + catch (Exception ex) { - Logger.Error?.Print(LogClass.TamperMachine, exception.ToString()); + Logger.Error?.Print(LogClass.TamperMachine, ex.ToString()); } Logger.Error?.Print(LogClass.TamperMachine, "There was a problem while compiling the Atmosphere cheat"); @@ -57,7 +56,7 @@ namespace Ryujinx.HLE.HOS.Tamper private ITamperProgram CompileImpl(string name, IEnumerable rawInstructions) { - CompilationContext context = new CompilationContext(_exeAddress, _heapAddress, _aliasAddress, _aslrAddress, _process); + CompilationContext context = new(_exeAddress, _heapAddress, _aliasAddress, _aslrAddress, _process); context.BlockStack.Push(new OperationBlock(null)); // Parse the instructions. @@ -132,7 +131,7 @@ namespace Ryujinx.HLE.HOS.Tamper // Initialize only the registers used. - Value zero = new Value(0UL); + Value zero = new(0UL); int position = 0; foreach (Register register in context.Registers.Values) @@ -143,7 +142,7 @@ namespace Ryujinx.HLE.HOS.Tamper if (context.BlockStack.Count != 1) { - throw new TamperCompilationException($"Reached end of compilation with unmatched conditional(s) or loop(s)"); + throw new TamperCompilationException("Reached end of compilation with unmatched conditional(s) or loop(s)"); } return new AtmosphereProgram(name, _process, context.PressedKeys, new Block(context.CurrentOperations)); diff --git a/src/Ryujinx.HLE/HOS/Tamper/AtmosphereProgram.cs b/src/Ryujinx.HLE/HOS/Tamper/AtmosphereProgram.cs index a2aa73a4f..8171d2177 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/AtmosphereProgram.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/AtmosphereProgram.cs @@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Tamper { class AtmosphereProgram : ITamperProgram { - private Parameter _pressedKeys; - private IOperation _entryPoint; + private readonly Parameter _pressedKeys; + private readonly IOperation _entryPoint; public string Name { get; } public bool TampersCodeMemory { get; set; } = false; diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/Arithmetic.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/Arithmetic.cs index b7d46d3a2..c51630d64 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/Arithmetic.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/Arithmetic.cs @@ -27,7 +27,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters private const byte Lsh = 3; // lhs << rhs private const byte Rsh = 4; // lhs >> rhs private const byte And = 5; // lhs & rhs - private const byte Or = 6; // lhs | rhs + private const byte Or = 6; // lhs | rhs private const byte Not = 7; // ~lhs (discards right-hand operand) private const byte Xor = 8; // lhs ^ rhs private const byte Mov = 9; // lhs (discards right-hand operand) @@ -73,9 +73,11 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters void Emit(Type operationType, IOperand rhs = null) { - List operandList = new List(); - operandList.Add(destinationRegister); - operandList.Add(leftHandSideRegister); + List operandList = new() + { + destinationRegister, + leftHandSideRegister, + }; if (rhs != null) { @@ -87,16 +89,36 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters switch (operation) { - case Add: Emit(typeof(OpAdd<>), rightHandSideOperand); break; - case Sub: Emit(typeof(OpSub<>), rightHandSideOperand); break; - case Mul: Emit(typeof(OpMul<>), rightHandSideOperand); break; - case Lsh: Emit(typeof(OpLsh<>), rightHandSideOperand); break; - case Rsh: Emit(typeof(OpRsh<>), rightHandSideOperand); break; - case And: Emit(typeof(OpAnd<>), rightHandSideOperand); break; - case Or: Emit(typeof(OpOr<> ), rightHandSideOperand); break; - case Not: Emit(typeof(OpNot<>) ); break; - case Xor: Emit(typeof(OpXor<>), rightHandSideOperand); break; - case Mov: Emit(typeof(OpMov<>) ); break; + case Add: + Emit(typeof(OpAdd<>), rightHandSideOperand); + break; + case Sub: + Emit(typeof(OpSub<>), rightHandSideOperand); + break; + case Mul: + Emit(typeof(OpMul<>), rightHandSideOperand); + break; + case Lsh: + Emit(typeof(OpLsh<>), rightHandSideOperand); + break; + case Rsh: + Emit(typeof(OpRsh<>), rightHandSideOperand); + break; + case And: + Emit(typeof(OpAnd<>), rightHandSideOperand); + break; + case Or: + Emit(typeof(OpOr<>), rightHandSideOperand); + break; + case Not: + Emit(typeof(OpNot<>)); + break; + case Xor: + Emit(typeof(OpXor<>), rightHandSideOperand); + break; + case Mov: + Emit(typeof(OpMov<>)); + break; default: throw new TamperCompilationException($"Invalid arithmetic operation {operation} in Atmosphere cheat"); } diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/EndConditionalBlock.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/EndConditionalBlock.cs index a25dddde5..63625a556 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/EndConditionalBlock.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/EndConditionalBlock.cs @@ -12,7 +12,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters { const int TerminationTypeIndex = 1; - private const byte End = 0; // True end of the conditional. + private const byte End = 0; // True end of the conditional. private const byte Else = 1; // End of the 'then' block and beginning of 'else' block. public static void Emit(byte[] instruction, CompilationContext context) @@ -51,7 +51,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters // If the else operations are already set, then the upper block must not be another end. if (operationsElse != null && codeType == CodeType.EndConditionalBlock) { - throw new TamperCompilationException($"Expected an upper 'if' conditional instead of 'end conditional'"); + throw new TamperCompilationException("Expected an upper 'if' conditional instead of 'end conditional'"); } ICondition condition; @@ -84,7 +84,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters // Create a conditional block with the current operations and nest it in the upper // block of the stack. - IfBlock block = new IfBlock(condition, operations, operationsElse); + IfBlock block = new(condition, operations, operationsElse); context.CurrentOperations.Add(block); } } diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/LegacyArithmetic.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/LegacyArithmetic.cs index 479c80ec0..1c389cd7c 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/LegacyArithmetic.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/LegacyArithmetic.cs @@ -10,7 +10,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters /// class LegacyArithmetic { - const int OperationWidthIndex = 1; + const int OperationWidthIndex = 1; const int DestinationRegisterIndex = 3; const int OperationTypeIndex = 4; const int ValueImmediateIndex = 8; @@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters Register register = context.GetRegister(instruction[DestinationRegisterIndex]); byte operation = instruction[OperationTypeIndex]; ulong immediate = InstructionHelper.GetImmediate(instruction, ValueImmediateIndex, ValueImmediateSize); - Value rightHandSideValue = new Value(immediate); + Value rightHandSideValue = new(immediate); void Emit(Type operationType) { @@ -44,11 +44,21 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters switch (operation) { - case Add: Emit(typeof(OpAdd<>)); break; - case Sub: Emit(typeof(OpSub<>)); break; - case Mul: Emit(typeof(OpMul<>)); break; - case Lsh: Emit(typeof(OpLsh<>)); break; - case Rsh: Emit(typeof(OpRsh<>)); break; + case Add: + Emit(typeof(OpAdd<>)); + break; + case Sub: + Emit(typeof(OpSub<>)); + break; + case Mul: + Emit(typeof(OpMul<>)); + break; + case Lsh: + Emit(typeof(OpLsh<>)); + break; + case Rsh: + Emit(typeof(OpRsh<>)); + break; default: throw new TamperCompilationException($"Invalid arithmetic operation {operation} in Atmosphere cheat"); } diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/LoadRegisterWithConstant.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/LoadRegisterWithConstant.cs index e4a86d7b6..16500cf9e 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/LoadRegisterWithConstant.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/LoadRegisterWithConstant.cs @@ -20,7 +20,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters Register destinationRegister = context.GetRegister(instruction[RegisterIndex]); ulong immediate = InstructionHelper.GetImmediate(instruction, ValueImmediateIndex, ValueImmediateSize); - Value sourceValue = new Value(immediate); + Value sourceValue = new(immediate); context.CurrentOperations.Add(new OpMov(destinationRegister, sourceValue)); } diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/MemoryConditional.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/MemoryConditional.cs index 2048a67b3..272cf3d05 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/MemoryConditional.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/MemoryConditional.cs @@ -37,7 +37,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters int valueSize = operationWidth <= 4 ? ValueImmediateSize4 : ValueImmediateSize8; ulong value = InstructionHelper.GetImmediate(instruction, ValueImmediateIndex, valueSize); - Value compareToValue = new Value(value); + Value compareToValue = new(value); return InstructionHelper.CreateCondition(comparison, operationWidth, sourceMemory, compareToValue); } diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/ResumeProcess.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/ResumeProcess.cs index 02f76e224..7af327d3e 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/ResumeProcess.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/ResumeProcess.cs @@ -8,7 +8,6 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters class ResumeProcess { // FF1????? - public static void Emit(byte[] instruction, CompilationContext context) { context.CurrentOperations.Add(new OpProcCtrl(context.Process, false)); diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StartEndLoop.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StartEndLoop.cs index 1e399b598..51fc8f35c 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StartEndLoop.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StartEndLoop.cs @@ -64,7 +64,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters // Create a loop block with the current operations and nest it in the upper // block of the stack. - ForBlock block = new ForBlock(immediate, iterationRegister, context.CurrentOperations); + ForBlock block = new(immediate, iterationRegister, context.CurrentOperations); context.BlockStack.Pop(); context.CurrentOperations.Add(block); } diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StoreConstantToAddress.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StoreConstantToAddress.cs index 933646bd0..a2a62015a 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StoreConstantToAddress.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StoreConstantToAddress.cs @@ -33,7 +33,7 @@ int valueImmediateSize = operationWidth <= 4 ? ValueImmediateSize8 : ValueImmediateSize16; ulong valueImmediate = InstructionHelper.GetImmediate(instruction, ValueImmediateIndex, valueImmediateSize); - Value storeValue = new Value(valueImmediate); + Value storeValue = new(valueImmediate); InstructionHelper.EmitMov(operationWidth, context, dstMem, storeValue); } diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StoreConstantToMemory.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StoreConstantToMemory.cs index 5f0369693..d53b7a26f 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StoreConstantToMemory.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/StoreConstantToMemory.cs @@ -32,7 +32,7 @@ namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters byte incrementAddressRegister = instruction[IncrementAddressRegisterIndex]; byte useOffsetRegister = instruction[UseOffsetRegisterIndex]; ulong immediate = InstructionHelper.GetImmediate(instruction, ValueImmediateIndex, ValueImmediateSize); - Value storeValue = new Value(immediate); + Value storeValue = new(immediate); Pointer destinationMemory; diff --git a/src/Ryujinx.HLE/HOS/Tamper/CodeType.cs b/src/Ryujinx.HLE/HOS/Tamper/CodeType.cs index 7c4f22860..d65f8a2f6 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CodeType.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CodeType.cs @@ -105,6 +105,6 @@ /// /// Code type 0xFFF writes a debug log. /// - DebugLog = 0xFFF + DebugLog = 0xFFF, } } diff --git a/src/Ryujinx.HLE/HOS/Tamper/Comparison.cs b/src/Ryujinx.HLE/HOS/Tamper/Comparison.cs index cd162b1ce..dc0f02649 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Comparison.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Comparison.cs @@ -10,6 +10,6 @@ Less = 3, LessOrEqual = 4, Equal = 5, - NotEqual = 6 + NotEqual = 6, } } diff --git a/src/Ryujinx.HLE/HOS/Tamper/CompilationContext.cs b/src/Ryujinx.HLE/HOS/Tamper/CompilationContext.cs index 45a47f445..922e568a3 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/CompilationContext.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/CompilationContext.cs @@ -21,16 +21,16 @@ namespace Ryujinx.HLE.HOS.Tamper public CompilationContext(ulong exeAddress, ulong heapAddress, ulong aliasAddress, ulong aslrAddress, ITamperedProcess process) { - Process = process; - PressedKeys = new Parameter(0); - BlockStack = new Stack(); - Registers = new Dictionary(); - SavedRegisters = new Dictionary(); + Process = process; + PressedKeys = new Parameter(0); + BlockStack = new Stack(); + Registers = new Dictionary(); + SavedRegisters = new Dictionary(); StaticRegisters = new Dictionary(); - ExeAddress = exeAddress; - HeapAddress = heapAddress; - AliasAddress = aliasAddress; - AslrAddress = aslrAddress; + ExeAddress = exeAddress; + HeapAddress = heapAddress; + AliasAddress = aliasAddress; + AslrAddress = aslrAddress; } public Register GetRegister(byte index) diff --git a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondEQ.cs b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondEQ.cs index ad5bd2232..529ed25b6 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondEQ.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondEQ.cs @@ -4,8 +4,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Conditions { class CondEQ : ICondition where T : unmanaged { - private IOperand _lhs; - private IOperand _rhs; + private readonly IOperand _lhs; + private readonly IOperand _rhs; public CondEQ(IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondGE.cs b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondGE.cs index d9ad6d81d..94877c2a6 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondGE.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondGE.cs @@ -4,8 +4,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Conditions { class CondGE : ICondition where T : unmanaged { - private IOperand _lhs; - private IOperand _rhs; + private readonly IOperand _lhs; + private readonly IOperand _rhs; public CondGE(IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondGT.cs b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondGT.cs index 262457da0..350688164 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondGT.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondGT.cs @@ -4,8 +4,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Conditions { class CondGT : ICondition where T : unmanaged { - private IOperand _lhs; - private IOperand _rhs; + private readonly IOperand _lhs; + private readonly IOperand _rhs; public CondGT(IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondLE.cs b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondLE.cs index fd488bc1a..dd9cf70cc 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondLE.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondLE.cs @@ -4,8 +4,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Conditions { class CondLE : ICondition where T : unmanaged { - private IOperand _lhs; - private IOperand _rhs; + private readonly IOperand _lhs; + private readonly IOperand _rhs; public CondLE(IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondLT.cs b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondLT.cs index 744eb5dc7..0c85f5e47 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondLT.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondLT.cs @@ -4,8 +4,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Conditions { class CondLT : ICondition where T : unmanaged { - private IOperand _lhs; - private IOperand _rhs; + private readonly IOperand _lhs; + private readonly IOperand _rhs; public CondLT(IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondNE.cs b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondNE.cs index 2709ad925..b649eccee 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondNE.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Conditions/CondNE.cs @@ -4,8 +4,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Conditions { class CondNE : ICondition where T : unmanaged { - private IOperand _lhs; - private IOperand _rhs; + private readonly IOperand _lhs; + private readonly IOperand _rhs; public CondNE(IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Conditions/InputMask.cs b/src/Ryujinx.HLE/HOS/Tamper/Conditions/InputMask.cs index 8d75a0e18..6c72eb5c8 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Conditions/InputMask.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Conditions/InputMask.cs @@ -2,8 +2,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Conditions { class InputMask : ICondition { - private long _mask; - private Parameter _input; + private readonly long _mask; + private readonly Parameter _input; public InputMask(long mask, Parameter input) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/InstructionHelper.cs b/src/Ryujinx.HLE/HOS/Tamper/InstructionHelper.cs index a31c055fa..76ffefb66 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/InstructionHelper.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/InstructionHelper.cs @@ -32,33 +32,28 @@ namespace Ryujinx.HLE.HOS.Tamper return (ICondition)InstructionHelper.Create(conditionType, width, lhs, rhs); } - switch (comparison) + return comparison switch { - case Comparison.Greater : return Create(typeof(CondGT<>)); - case Comparison.GreaterOrEqual: return Create(typeof(CondGE<>)); - case Comparison.Less : return Create(typeof(CondLT<>)); - case Comparison.LessOrEqual : return Create(typeof(CondLE<>)); - case Comparison.Equal : return Create(typeof(CondEQ<>)); - case Comparison.NotEqual : return Create(typeof(CondNE<>)); - default: - throw new TamperCompilationException($"Invalid comparison {comparison} in Atmosphere cheat"); - } + Comparison.Greater => Create(typeof(CondGT<>)), + Comparison.GreaterOrEqual => Create(typeof(CondGE<>)), + Comparison.Less => Create(typeof(CondLT<>)), + Comparison.LessOrEqual => Create(typeof(CondLE<>)), + Comparison.Equal => Create(typeof(CondEQ<>)), + Comparison.NotEqual => Create(typeof(CondNE<>)), + _ => throw new TamperCompilationException($"Invalid comparison {comparison} in Atmosphere cheat"), + }; } public static Object Create(Type instruction, byte width, params Object[] operands) { - Type realType; - - switch (width) + Type realType = width switch { - case 1: realType = instruction.MakeGenericType(typeof(byte)); break; - case 2: realType = instruction.MakeGenericType(typeof(ushort)); break; - case 4: realType = instruction.MakeGenericType(typeof(uint)); break; - case 8: realType = instruction.MakeGenericType(typeof(ulong)); break; - default: - throw new TamperCompilationException($"Invalid instruction width {width} in Atmosphere cheat"); - } - + 1 => instruction.MakeGenericType(typeof(byte)), + 2 => instruction.MakeGenericType(typeof(ushort)), + 4 => instruction.MakeGenericType(typeof(uint)), + 8 => instruction.MakeGenericType(typeof(ulong)), + _ => throw new TamperCompilationException($"Invalid instruction width {width} in Atmosphere cheat"), + }; return Activator.CreateInstance(realType, operands); } diff --git a/src/Ryujinx.HLE/HOS/Tamper/MemoryHelper.cs b/src/Ryujinx.HLE/HOS/Tamper/MemoryHelper.cs index 1260ed9ac..52e12bfe5 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/MemoryHelper.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/MemoryHelper.cs @@ -7,23 +7,18 @@ namespace Ryujinx.HLE.HOS.Tamper { public static ulong GetAddressShift(MemoryRegion source, CompilationContext context) { - switch (source) + return source switch { - case MemoryRegion.NSO: - // Memory address is relative to the code start. - return context.ExeAddress; - case MemoryRegion.Heap: - // Memory address is relative to the heap. - return context.HeapAddress; - case MemoryRegion.Alias: - // Memory address is relative to the alias region. - return context.AliasAddress; - case MemoryRegion.Asrl: - // Memory address is relative to the asrl region, which matches the code region. - return context.AslrAddress; - default: - throw new TamperCompilationException($"Invalid memory source {source} in Atmosphere cheat"); - } + // Memory address is relative to the code start. + MemoryRegion.NSO => context.ExeAddress, + // Memory address is relative to the heap. + MemoryRegion.Heap => context.HeapAddress, + // Memory address is relative to the alias region. + MemoryRegion.Alias => context.AliasAddress, + // Memory address is relative to the asrl region, which matches the code region. + MemoryRegion.Asrl => context.AslrAddress, + _ => throw new TamperCompilationException($"Invalid memory source {source} in Atmosphere cheat"), + }; } private static void EmitAdd(Value finalValue, IOperand firstOperand, IOperand secondOperand, CompilationContext context) @@ -33,7 +28,7 @@ namespace Ryujinx.HLE.HOS.Tamper public static Pointer EmitPointer(ulong addressImmediate, CompilationContext context) { - Value addressImmediateValue = new Value(addressImmediate); + Value addressImmediateValue = new(addressImmediate); return new Pointer(addressImmediateValue, context.Process); } @@ -45,8 +40,8 @@ namespace Ryujinx.HLE.HOS.Tamper public static Pointer EmitPointer(Register addressRegister, ulong offsetImmediate, CompilationContext context) { - Value offsetImmediateValue = new Value(offsetImmediate); - Value finalAddressValue = new Value(0); + Value offsetImmediateValue = new(offsetImmediate); + Value finalAddressValue = new(0); EmitAdd(finalAddressValue, addressRegister, offsetImmediateValue, context); return new Pointer(finalAddressValue, context.Process); @@ -54,7 +49,7 @@ namespace Ryujinx.HLE.HOS.Tamper public static Pointer EmitPointer(Register addressRegister, Register offsetRegister, CompilationContext context) { - Value finalAddressValue = new Value(0); + Value finalAddressValue = new(0); EmitAdd(finalAddressValue, addressRegister, offsetRegister, context); return new Pointer(finalAddressValue, context.Process); @@ -62,10 +57,10 @@ namespace Ryujinx.HLE.HOS.Tamper public static Pointer EmitPointer(Register addressRegister, Register offsetRegister, ulong offsetImmediate, CompilationContext context) { - Value offsetImmediateValue = new Value(offsetImmediate); - Value finalOffsetValue = new Value(0); + Value offsetImmediateValue = new(offsetImmediate); + Value finalOffsetValue = new(0); EmitAdd(finalOffsetValue, offsetRegister, offsetImmediateValue, context); - Value finalAddressValue = new Value(0); + Value finalAddressValue = new(0); EmitAdd(finalAddressValue, addressRegister, finalOffsetValue, context); return new Pointer(finalAddressValue, context.Process); diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/Block.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/Block.cs index d81daa903..6d4b16373 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/Block.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/Block.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class Block : IOperation { - private IEnumerable _operations; + private readonly IEnumerable _operations; public Block(IEnumerable operations) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/ForBlock.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/ForBlock.cs index ef95fa2bf..1e8cafa84 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/ForBlock.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/ForBlock.cs @@ -4,9 +4,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class ForBlock : IOperation { - private ulong _count; - private Register _register; - private IEnumerable _operations; + private readonly ulong _count; + private readonly Register _register; + private readonly IEnumerable _operations; public ForBlock(ulong count, Register register, IEnumerable operations) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/IfBlock.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/IfBlock.cs index b7c5684ef..a6b31f252 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/IfBlock.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/IfBlock.cs @@ -5,9 +5,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class IfBlock : IOperation { - private ICondition _condition; - private IEnumerable _operationsThen; - private IEnumerable _operationsElse; + private readonly ICondition _condition; + private readonly IEnumerable _operationsThen; + private readonly IEnumerable _operationsElse; public IfBlock(ICondition condition, IEnumerable operationsThen, IEnumerable operationsElse) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpAdd.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpAdd.cs index 214518d7d..855245e34 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpAdd.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpAdd.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpAdd : IOperation where T : unmanaged { - IOperand _destination; - IOperand _lhs; - IOperand _rhs; + readonly IOperand _destination; + readonly IOperand _lhs; + readonly IOperand _rhs; public OpAdd(IOperand destination, IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpAnd.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpAnd.cs index 366a82b07..7d1fa10b9 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpAnd.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpAnd.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpAnd : IOperation where T : unmanaged { - IOperand _destination; - IOperand _lhs; - IOperand _rhs; + readonly IOperand _destination; + readonly IOperand _lhs; + readonly IOperand _rhs; public OpAnd(IOperand destination, IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpLog.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpLog.cs index 49f8b41e1..4017e5f75 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpLog.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpLog.cs @@ -4,8 +4,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpLog : IOperation where T : unmanaged { - int _logId; - IOperand _source; + readonly int _logId; + readonly IOperand _source; public OpLog(int logId, IOperand source) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpLsh.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpLsh.cs index 34e7c81a1..6c846425f 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpLsh.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpLsh.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpLsh : IOperation where T : unmanaged { - IOperand _destination; - IOperand _lhs; - IOperand _rhs; + readonly IOperand _destination; + readonly IOperand _lhs; + readonly IOperand _rhs; public OpLsh(IOperand destination, IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpMov.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpMov.cs index 5fad38f91..af82f18e0 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpMov.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpMov.cs @@ -2,8 +2,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpMov : IOperation where T : unmanaged { - IOperand _destination; - IOperand _source; + readonly IOperand _destination; + readonly IOperand _source; public OpMov(IOperand destination, IOperand source) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpMul.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpMul.cs index 5aa0e34ef..a1b080f00 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpMul.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpMul.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpMul : IOperation where T : unmanaged { - IOperand _destination; - IOperand _lhs; - IOperand _rhs; + readonly IOperand _destination; + readonly IOperand _lhs; + readonly IOperand _rhs; public OpMul(IOperand destination, IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpNot.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpNot.cs index 8a97c3fe8..034e22008 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpNot.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpNot.cs @@ -2,8 +2,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpNot : IOperation where T : unmanaged { - IOperand _destination; - IOperand _source; + readonly IOperand _destination; + readonly IOperand _source; public OpNot(IOperand destination, IOperand source) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpOr.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpOr.cs index d074de1c8..0afdc3f4b 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpOr.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpOr.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpOr : IOperation where T : unmanaged { - IOperand _destination; - IOperand _lhs; - IOperand _rhs; + readonly IOperand _destination; + readonly IOperand _lhs; + readonly IOperand _rhs; public OpOr(IOperand destination, IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpProcCtrl.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpProcCtrl.cs index 1b89f4507..5de225a19 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpProcCtrl.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpProcCtrl.cs @@ -2,8 +2,8 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpProcCtrl : IOperation { - private ITamperedProcess _process; - private bool _pause; + private readonly ITamperedProcess _process; + private readonly bool _pause; public OpProcCtrl(ITamperedProcess process, bool pause) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpRsh.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpRsh.cs index b08dd957c..e7e0f870e 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpRsh.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpRsh.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpRsh : IOperation where T : unmanaged { - IOperand _destination; - IOperand _lhs; - IOperand _rhs; + readonly IOperand _destination; + readonly IOperand _lhs; + readonly IOperand _rhs; public OpRsh(IOperand destination, IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpSub.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpSub.cs index b9c67d040..d860d66fd 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpSub.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpSub.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpSub : IOperation where T : unmanaged { - IOperand _destination; - IOperand _lhs; - IOperand _rhs; + readonly IOperand _destination; + readonly IOperand _lhs; + readonly IOperand _rhs; public OpSub(IOperand destination, IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpXor.cs b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpXor.cs index 3bbb76a1b..07ba6b335 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Operations/OpXor.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Operations/OpXor.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.HOS.Tamper.Operations { class OpXor : IOperation where T : unmanaged { - IOperand _destination; - IOperand _lhs; - IOperand _rhs; + readonly IOperand _destination; + readonly IOperand _lhs; + readonly IOperand _rhs; public OpXor(IOperand destination, IOperand lhs, IOperand rhs) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Pointer.cs b/src/Ryujinx.HLE/HOS/Tamper/Pointer.cs index 22acf4d56..c961e1a7d 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Pointer.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Pointer.cs @@ -6,8 +6,8 @@ namespace Ryujinx.HLE.HOS.Tamper { class Pointer : IOperand { - private IOperand _position; - private ITamperedProcess _process; + private readonly IOperand _position; + private readonly ITamperedProcess _process; public Pointer(IOperand position, ITamperedProcess process) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/Register.cs b/src/Ryujinx.HLE/HOS/Tamper/Register.cs index 01af20dea..cce13ee69 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Register.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Register.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Tamper class Register : IOperand { private ulong _register = 0; - private string _alias; + private readonly string _alias; public Register(string alias) { diff --git a/src/Ryujinx.HLE/HOS/Tamper/TamperedKProcess.cs b/src/Ryujinx.HLE/HOS/Tamper/TamperedKProcess.cs index be51264a2..c8768e88a 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/TamperedKProcess.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/TamperedKProcess.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Tamper { class TamperedKProcess : ITamperedProcess { - private KProcess _process; + private readonly KProcess _process; public ProcessState State => _process.State; @@ -65,4 +65,4 @@ namespace Ryujinx.HLE.HOS.Tamper Logger.Warning?.Print(LogClass.TamperMachine, "Process resuming is not supported!"); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Tamper/Value.cs b/src/Ryujinx.HLE/HOS/Tamper/Value.cs index 865f8e046..436fc13d3 100644 --- a/src/Ryujinx.HLE/HOS/Tamper/Value.cs +++ b/src/Ryujinx.HLE/HOS/Tamper/Value.cs @@ -2,11 +2,11 @@ using Ryujinx.HLE.HOS.Tamper.Operations; namespace Ryujinx.HLE.HOS.Tamper { - class Value

: IOperand where P : unmanaged + class Value : IOperand where TP : unmanaged { - private P _value; + private TP _value; - public Value(P value) + public Value(TP value) { _value = value; } @@ -18,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Tamper public void Set(T value) where T : unmanaged { - _value = (P)(dynamic)value; + _value = (TP)(dynamic)value; } } } diff --git a/src/Ryujinx.HLE/HOS/TamperMachine.cs b/src/Ryujinx.HLE/HOS/TamperMachine.cs index 596fc3ce8..f234e540e 100644 --- a/src/Ryujinx.HLE/HOS/TamperMachine.cs +++ b/src/Ryujinx.HLE/HOS/TamperMachine.cs @@ -17,16 +17,18 @@ namespace Ryujinx.HLE.HOS private const int TamperMachineSleepMs = 1000 / 12; private Thread _tamperThread = null; - private ConcurrentQueue _programs = new ConcurrentQueue(); + private readonly ConcurrentQueue _programs = new(); private long _pressedKeys = 0; - private Dictionary _programDictionary = new Dictionary(); + private readonly Dictionary _programDictionary = new(); private void Activate() { if (_tamperThread == null || !_tamperThread.IsAlive) { - _tamperThread = new Thread(this.TamperRunner); - _tamperThread.Name = "HLE.TamperMachine"; + _tamperThread = new Thread(this.TamperRunner) + { + Name = "HLE.TamperMachine", + }; _tamperThread.Start(); } } @@ -39,7 +41,7 @@ namespace Ryujinx.HLE.HOS } ITamperedProcess tamperedProcess = new TamperedKProcess(info.Process); - AtmosphereCompiler compiler = new AtmosphereCompiler(exeAddress, info.HeapAddress, info.AliasAddress, info.AslrAddress, tamperedProcess); + AtmosphereCompiler compiler = new(exeAddress, info.HeapAddress, info.AliasAddress, info.AslrAddress, tamperedProcess); ITamperProgram program = compiler.Compile(name, rawInstructions); if (program != null) @@ -53,7 +55,7 @@ namespace Ryujinx.HLE.HOS Activate(); } - private bool CanInstallOnPid(ulong pid) + private static bool CanInstallOnPid(ulong pid) { // Do not allow tampering of kernel processes. if (pid < KernelConstants.InitialProcessId) @@ -82,7 +84,7 @@ namespace Ryujinx.HLE.HOS } } - private bool IsProcessValid(ITamperedProcess process) + private static bool IsProcessValid(ITamperedProcess process) { return process.State != ProcessState.Crashed && process.State != ProcessState.Exiting && process.State != ProcessState.Exited; } diff --git a/src/Ryujinx.HLE/HOS/UserChannelPersistence.cs b/src/Ryujinx.HLE/HOS/UserChannelPersistence.cs index 4b041ce88..7c7448ba7 100644 --- a/src/Ryujinx.HLE/HOS/UserChannelPersistence.cs +++ b/src/Ryujinx.HLE/HOS/UserChannelPersistence.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS { public class UserChannelPersistence { - private Stack _userChannelStorages; + private readonly Stack _userChannelStorages; public int PreviousIndex { get; private set; } public int Index { get; private set; } public ProgramSpecifyKind Kind { get; private set; } diff --git a/src/Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs b/src/Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs index f489e85af..4cc1a9fea 100644 --- a/src/Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs +++ b/src/Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs @@ -8,8 +8,8 @@ namespace Ryujinx.HLE.Loaders.Elf public ElfDynamic(ElfDynamicTag tag, long value) { - Tag = tag; + Tag = tag; Value = value; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs b/src/Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs index eb37d612d..6505e17dd 100644 --- a/src/Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs +++ b/src/Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs @@ -3,73 +3,74 @@ using System.Diagnostics.CodeAnalysis; namespace Ryujinx.HLE.Loaders.Elf { [SuppressMessage("ReSharper", "InconsistentNaming")] + [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")] enum ElfDynamicTag { - DT_NULL = 0, - DT_NEEDED = 1, - DT_PLTRELSZ = 2, - DT_PLTGOT = 3, - DT_HASH = 4, - DT_STRTAB = 5, - DT_SYMTAB = 6, - DT_RELA = 7, - DT_RELASZ = 8, - DT_RELAENT = 9, - DT_STRSZ = 10, - DT_SYMENT = 11, - DT_INIT = 12, - DT_FINI = 13, - DT_SONAME = 14, - DT_RPATH = 15, - DT_SYMBOLIC = 16, - DT_REL = 17, - DT_RELSZ = 18, - DT_RELENT = 19, - DT_PLTREL = 20, - DT_DEBUG = 21, - DT_TEXTREL = 22, - DT_JMPREL = 23, - DT_BIND_NOW = 24, - DT_INIT_ARRAY = 25, - DT_FINI_ARRAY = 26, - DT_INIT_ARRAYSZ = 27, - DT_FINI_ARRAYSZ = 28, - DT_RUNPATH = 29, - DT_FLAGS = 30, - DT_ENCODING = 32, - DT_PREINIT_ARRAY = 32, + DT_NULL = 0, + DT_NEEDED = 1, + DT_PLTRELSZ = 2, + DT_PLTGOT = 3, + DT_HASH = 4, + DT_STRTAB = 5, + DT_SYMTAB = 6, + DT_RELA = 7, + DT_RELASZ = 8, + DT_RELAENT = 9, + DT_STRSZ = 10, + DT_SYMENT = 11, + DT_INIT = 12, + DT_FINI = 13, + DT_SONAME = 14, + DT_RPATH = 15, + DT_SYMBOLIC = 16, + DT_REL = 17, + DT_RELSZ = 18, + DT_RELENT = 19, + DT_PLTREL = 20, + DT_DEBUG = 21, + DT_TEXTREL = 22, + DT_JMPREL = 23, + DT_BIND_NOW = 24, + DT_INIT_ARRAY = 25, + DT_FINI_ARRAY = 26, + DT_INIT_ARRAYSZ = 27, + DT_FINI_ARRAYSZ = 28, + DT_RUNPATH = 29, + DT_FLAGS = 30, + DT_ENCODING = 32, + DT_PREINIT_ARRAY = 32, DT_PREINIT_ARRAYSZ = 33, - DT_GNU_PRELINKED = 0x6ffffdf5, - DT_GNU_CONFLICTSZ = 0x6ffffdf6, - DT_GNU_LIBLISTSZ = 0x6ffffdf7, - DT_CHECKSUM = 0x6ffffdf8, - DT_PLTPADSZ = 0x6ffffdf9, - DT_MOVEENT = 0x6ffffdfa, - DT_MOVESZ = 0x6ffffdfb, - DT_FEATURE_1 = 0x6ffffdfc, - DT_POSFLAG_1 = 0x6ffffdfd, - DT_SYMINSZ = 0x6ffffdfe, - DT_SYMINENT = 0x6ffffdff, - DT_GNU_HASH = 0x6ffffef5, - DT_TLSDESC_PLT = 0x6ffffef6, - DT_TLSDESC_GOT = 0x6ffffef7, - DT_GNU_CONFLICT = 0x6ffffef8, - DT_GNU_LIBLIST = 0x6ffffef9, - DT_CONFIG = 0x6ffffefa, - DT_DEPAUDIT = 0x6ffffefb, - DT_AUDIT = 0x6ffffefc, - DT_PLTPAD = 0x6ffffefd, - DT_MOVETAB = 0x6ffffefe, - DT_SYMINFO = 0x6ffffeff, - DT_VERSYM = 0x6ffffff0, - DT_RELACOUNT = 0x6ffffff9, - DT_RELCOUNT = 0x6ffffffa, - DT_FLAGS_1 = 0x6ffffffb, - DT_VERDEF = 0x6ffffffc, - DT_VERDEFNUM = 0x6ffffffd, - DT_VERNEED = 0x6ffffffe, - DT_VERNEEDNUM = 0x6fffffff, - DT_AUXILIARY = 0x7ffffffd, - DT_FILTER = 0x7fffffff + DT_GNU_PRELINKED = 0x6ffffdf5, + DT_GNU_CONFLICTSZ = 0x6ffffdf6, + DT_GNU_LIBLISTSZ = 0x6ffffdf7, + DT_CHECKSUM = 0x6ffffdf8, + DT_PLTPADSZ = 0x6ffffdf9, + DT_MOVEENT = 0x6ffffdfa, + DT_MOVESZ = 0x6ffffdfb, + DT_FEATURE_1 = 0x6ffffdfc, + DT_POSFLAG_1 = 0x6ffffdfd, + DT_SYMINSZ = 0x6ffffdfe, + DT_SYMINENT = 0x6ffffdff, + DT_GNU_HASH = 0x6ffffef5, + DT_TLSDESC_PLT = 0x6ffffef6, + DT_TLSDESC_GOT = 0x6ffffef7, + DT_GNU_CONFLICT = 0x6ffffef8, + DT_GNU_LIBLIST = 0x6ffffef9, + DT_CONFIG = 0x6ffffefa, + DT_DEPAUDIT = 0x6ffffefb, + DT_AUDIT = 0x6ffffefc, + DT_PLTPAD = 0x6ffffefd, + DT_MOVETAB = 0x6ffffefe, + DT_SYMINFO = 0x6ffffeff, + DT_VERSYM = 0x6ffffff0, + DT_RELACOUNT = 0x6ffffff9, + DT_RELCOUNT = 0x6ffffffa, + DT_FLAGS_1 = 0x6ffffffb, + DT_VERDEF = 0x6ffffffc, + DT_VERDEFNUM = 0x6ffffffd, + DT_VERNEED = 0x6ffffffe, + DT_VERNEEDNUM = 0x6fffffff, + DT_AUXILIARY = 0x7ffffffd, + DT_FILTER = 0x7fffffff, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs index 1cfc0bdcc..1ed61b2cb 100644 --- a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs +++ b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs @@ -4,32 +4,32 @@ namespace Ryujinx.HLE.Loaders.Elf { public string Name { get; private set; } - public ElfSymbolType Type { get; private set; } - public ElfSymbolBinding Binding { get; private set; } + public ElfSymbolType Type { get; private set; } + public ElfSymbolBinding Binding { get; private set; } public ElfSymbolVisibility Visibility { get; private set; } - public bool IsFuncOrObject => Type == ElfSymbolType.SttFunc || Type == ElfSymbolType.SttObject; - public bool IsGlobalOrWeak => Binding == ElfSymbolBinding.StbGlobal || Binding == ElfSymbolBinding.StbWeak; + public readonly bool IsFuncOrObject => Type == ElfSymbolType.SttFunc || Type == ElfSymbolType.SttObject; + public readonly bool IsGlobalOrWeak => Binding == ElfSymbolBinding.StbGlobal || Binding == ElfSymbolBinding.StbWeak; - public int ShIdx { get; private set; } + public int ShIdx { get; private set; } public ulong Value { get; private set; } - public ulong Size { get; private set; } + public ulong Size { get; private set; } public ElfSymbol( string name, - int info, - int other, - int shIdx, - ulong value, - ulong size) + int info, + int other, + int shIdx, + ulong value, + ulong size) { - Name = name; - Type = (ElfSymbolType)(info & 0xf); - Binding = (ElfSymbolBinding)(info >> 4); + Name = name; + Type = (ElfSymbolType)(info & 0xf); + Binding = (ElfSymbolBinding)(info >> 4); Visibility = (ElfSymbolVisibility)other; - ShIdx = shIdx; - Value = value; - Size = size; + ShIdx = shIdx; + Value = value; + Size = size; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs index 2f84796b8..945b0c8b2 100644 --- a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs +++ b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs @@ -2,13 +2,13 @@ { struct ElfSymbol32 { -#pragma warning disable CS0649 - public uint NameOffset; - public uint ValueAddress; - public uint Size; - public byte Info; - public byte Other; +#pragma warning disable CS0649 // Field is never assigned to + public uint NameOffset; + public uint ValueAddress; + public uint Size; + public byte Info; + public byte Other; public ushort SectionIndex; #pragma warning restore CS0649 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs index 665e65b0c..3a73ca4ed 100644 --- a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs +++ b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs @@ -2,13 +2,13 @@ { struct ElfSymbol64 { -#pragma warning disable CS0649 - public uint NameOffset; - public byte Info; - public byte Other; +#pragma warning disable CS0649 // Field is never assigned to + public uint NameOffset; + public byte Info; + public byte Other; public ushort SectionIndex; - public ulong ValueAddress; - public ulong Size; + public ulong ValueAddress; + public ulong Size; #pragma warning restore CS0649 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolBinding.cs b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolBinding.cs index 92274fded..cf504ae2d 100644 --- a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolBinding.cs +++ b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolBinding.cs @@ -2,8 +2,8 @@ namespace Ryujinx.HLE.Loaders.Elf { enum ElfSymbolBinding { - StbLocal = 0, + StbLocal = 0, StbGlobal = 1, - StbWeak = 2 + StbWeak = 2, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs index 4110d4c3e..9dc414360 100644 --- a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs +++ b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs @@ -2,12 +2,12 @@ namespace Ryujinx.HLE.Loaders.Elf { enum ElfSymbolType { - SttNoType = 0, - SttObject = 1, - SttFunc = 2, + SttNoType = 0, + SttObject = 1, + SttFunc = 2, SttSection = 3, - SttFile = 4, - SttCommon = 5, - SttTls = 6 + SttFile = 4, + SttCommon = 5, + SttTls = 6, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolVisibility.cs b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolVisibility.cs index f026fca89..6305ab1ca 100644 --- a/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolVisibility.cs +++ b/src/Ryujinx.HLE/Loaders/Elf/ElfSymbolVisibility.cs @@ -2,9 +2,9 @@ namespace Ryujinx.HLE.Loaders.Elf { enum ElfSymbolVisibility { - StvDefault = 0, - StvInternal = 1, - StvHidden = 2, - StvProtected = 3 + StvDefault = 0, + StvInternal = 1, + StvHidden = 2, + StvProtected = 3, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Executables/IExecutable.cs b/src/Ryujinx.HLE/Loaders/Executables/IExecutable.cs index 27479efe1..06f6d9694 100644 --- a/src/Ryujinx.HLE/Loaders/Executables/IExecutable.cs +++ b/src/Ryujinx.HLE/Loaders/Executables/IExecutable.cs @@ -6,13 +6,13 @@ namespace Ryujinx.HLE.Loaders.Executables { byte[] Program { get; } Span Text { get; } - Span Ro { get; } + Span Ro { get; } Span Data { get; } uint TextOffset { get; } - uint RoOffset { get; } + uint RoOffset { get; } uint DataOffset { get; } - uint BssOffset { get; } - uint BssSize { get; } + uint BssOffset { get; } + uint BssSize { get; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs b/src/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs index ad2b681cd..83380ff45 100644 --- a/src/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs +++ b/src/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs @@ -9,53 +9,53 @@ namespace Ryujinx.HLE.Loaders.Executables { public byte[] Program { get; } public Span Text => Program.AsSpan((int)TextOffset, (int)TextSize); - public Span Ro => Program.AsSpan((int)RoOffset, (int)RoSize); + public Span Ro => Program.AsSpan((int)RoOffset, (int)RoSize); public Span Data => Program.AsSpan((int)DataOffset, (int)DataSize); public uint TextOffset { get; } - public uint RoOffset { get; } + public uint RoOffset { get; } public uint DataOffset { get; } - public uint BssOffset { get; } + public uint BssOffset { get; } public uint TextSize { get; } - public uint RoSize { get; } + public uint RoSize { get; } public uint DataSize { get; } - public uint BssSize { get; } + public uint BssSize { get; } - public uint[] Capabilities { get; } - public bool UsesSecureMemory { get; } + public uint[] Capabilities { get; } + public bool UsesSecureMemory { get; } public bool Is64BitAddressSpace { get; } - public bool Is64Bit { get; } - public ulong ProgramId { get; } - public byte Priority { get; } - public int StackSize { get; } - public byte IdealCoreId { get; } - public int Version { get; } - public string Name { get; } + public bool Is64Bit { get; } + public ulong ProgramId { get; } + public byte Priority { get; } + public int StackSize { get; } + public byte IdealCoreId { get; } + public int Version { get; } + public string Name { get; } public KipExecutable(in SharedRef inStorage) { - KipReader reader = new KipReader(); + KipReader reader = new(); reader.Initialize(in inStorage).ThrowIfFailure(); TextOffset = (uint)reader.Segments[0].MemoryOffset; - RoOffset = (uint)reader.Segments[1].MemoryOffset; + RoOffset = (uint)reader.Segments[1].MemoryOffset; DataOffset = (uint)reader.Segments[2].MemoryOffset; - BssOffset = (uint)reader.Segments[3].MemoryOffset; - BssSize = (uint)reader.Segments[3].Size; + BssOffset = (uint)reader.Segments[3].MemoryOffset; + BssSize = (uint)reader.Segments[3].Size; StackSize = reader.StackSize; - UsesSecureMemory = reader.UsesSecureMemory; + UsesSecureMemory = reader.UsesSecureMemory; Is64BitAddressSpace = reader.Is64BitAddressSpace; - Is64Bit = reader.Is64Bit; + Is64Bit = reader.Is64Bit; - ProgramId = reader.ProgramId; - Priority = reader.Priority; + ProgramId = reader.ProgramId; + Priority = reader.Priority; IdealCoreId = reader.IdealCoreId; - Version = reader.Version; - Name = reader.Name.ToString(); + Version = reader.Version; + Name = reader.Name.ToString(); Capabilities = new uint[32]; @@ -68,7 +68,7 @@ namespace Ryujinx.HLE.Loaders.Executables Program = new byte[DataOffset + uncompressedSize]; TextSize = DecompressSection(reader, KipReader.SegmentType.Text, TextOffset, Program); - RoSize = DecompressSection(reader, KipReader.SegmentType.Ro, RoOffset, Program); + RoSize = DecompressSection(reader, KipReader.SegmentType.Ro, RoOffset, Program); DataSize = DecompressSection(reader, KipReader.SegmentType.Data, DataOffset, Program); } @@ -83,4 +83,4 @@ namespace Ryujinx.HLE.Loaders.Executables return (uint)uncompressedSize; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs b/src/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs index 621ab43b3..6b5a8c831 100644 --- a/src/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs +++ b/src/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs @@ -8,31 +8,31 @@ namespace Ryujinx.HLE.Loaders.Executables { public byte[] Program { get; } public Span Text => Program.AsSpan((int)TextOffset, (int)Header.NroSegments[0].Size); - public Span Ro => Program.AsSpan((int)RoOffset, (int)Header.NroSegments[1].Size); + public Span Ro => Program.AsSpan((int)RoOffset, (int)Header.NroSegments[1].Size); public Span Data => Program.AsSpan((int)DataOffset, (int)Header.NroSegments[2].Size); public uint TextOffset => Header.NroSegments[0].FileOffset; - public uint RoOffset => Header.NroSegments[1].FileOffset; + public uint RoOffset => Header.NroSegments[1].FileOffset; public uint DataOffset => Header.NroSegments[2].FileOffset; - public uint BssOffset => DataOffset + (uint)Data.Length; - public uint BssSize => Header.BssSize; + public uint BssOffset => DataOffset + (uint)Data.Length; + public uint BssSize => Header.BssSize; public uint Mod0Offset => (uint)Start.Mod0Offset; - public uint FileSize => Header.Size; + public uint FileSize => Header.Size; public ulong SourceAddress { get; private set; } - public ulong BssAddress { get; private set; } + public ulong BssAddress { get; private set; } public NroExecutable(IStorage inStorage, ulong sourceAddress = 0, ulong bssAddress = 0) : base(inStorage) { Program = new byte[FileSize]; SourceAddress = sourceAddress; - BssAddress = bssAddress; + BssAddress = bssAddress; OpenNroSegment(NroSegmentType.Text, false).Read(0, Text); - OpenNroSegment(NroSegmentType.Ro , false).Read(0, Ro); + OpenNroSegment(NroSegmentType.Ro, false).Read(0, Ro); OpenNroSegment(NroSegmentType.Data, false).Read(0, Data); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs b/src/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs index d695449be..83ad5d7e8 100644 --- a/src/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs +++ b/src/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs @@ -13,20 +13,20 @@ namespace Ryujinx.HLE.Loaders.Executables { public byte[] Program { get; } public Span Text => Program.AsSpan((int)TextOffset, (int)TextSize); - public Span Ro => Program.AsSpan((int)RoOffset, (int)RoSize); + public Span Ro => Program.AsSpan((int)RoOffset, (int)RoSize); public Span Data => Program.AsSpan((int)DataOffset, (int)DataSize); public uint TextOffset { get; } - public uint RoOffset { get; } + public uint RoOffset { get; } public uint DataOffset { get; } public uint BssOffset => DataOffset + (uint)Data.Length; public uint TextSize { get; } - public uint RoSize { get; } + public uint RoSize { get; } public uint DataSize { get; } - public uint BssSize { get; } + public uint BssSize { get; } - public string Name; + public string Name; public Array32 BuildId; [GeneratedRegex(@"[a-z]:[\\/][ -~]{5,}\.nss", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)] @@ -38,24 +38,24 @@ namespace Ryujinx.HLE.Loaders.Executables public NsoExecutable(IStorage inStorage, string name = null) { - NsoReader reader = new NsoReader(); + NsoReader reader = new(); reader.Initialize(inStorage.AsFile(OpenMode.Read)).ThrowIfFailure(); TextOffset = reader.Header.Segments[0].MemoryOffset; - RoOffset = reader.Header.Segments[1].MemoryOffset; + RoOffset = reader.Header.Segments[1].MemoryOffset; DataOffset = reader.Header.Segments[2].MemoryOffset; - BssSize = reader.Header.BssSize; + BssSize = reader.Header.BssSize; reader.GetSegmentSize(NsoReader.SegmentType.Data, out uint uncompressedSize).ThrowIfFailure(); Program = new byte[DataOffset + uncompressedSize]; TextSize = DecompressSection(reader, NsoReader.SegmentType.Text, TextOffset); - RoSize = DecompressSection(reader, NsoReader.SegmentType.Ro, RoOffset); + RoSize = DecompressSection(reader, NsoReader.SegmentType.Ro, RoOffset); DataSize = DecompressSection(reader, NsoReader.SegmentType.Data, DataOffset); - Name = name; + Name = name; BuildId = reader.Header.ModuleId; PrintRoSectionInfo(); @@ -74,12 +74,12 @@ namespace Ryujinx.HLE.Loaders.Executables private void PrintRoSectionInfo() { - string rawTextBuffer = Encoding.ASCII.GetString(Ro); - StringBuilder stringBuilder = new StringBuilder(); + string rawTextBuffer = Encoding.ASCII.GetString(Ro); + StringBuilder stringBuilder = new(); string modulePath = null; - if (BitConverter.ToInt32(Ro.Slice(0, 4)) == 0) + if (BitConverter.ToInt32(Ro[..4]) == 0) { int length = BitConverter.ToInt32(Ro.Slice(4, 4)); if (length > 0) @@ -108,7 +108,7 @@ namespace Ryujinx.HLE.Loaders.Executables MatchCollection sdkMwMatches = SdkMwRegex().Matches(rawTextBuffer); if (sdkMwMatches.Count != 0) { - string libHeader = " SDK Libraries: "; + string libHeader = " SDK Libraries: "; string libContent = string.Join($"\n{new string(' ', libHeader.Length)}", sdkMwMatches); stringBuilder.AppendLine($"{libHeader}{libContent}"); @@ -120,4 +120,4 @@ namespace Ryujinx.HLE.Loaders.Executables } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs b/src/Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs index 510fec059..cf316b565 100644 --- a/src/Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs +++ b/src/Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs @@ -1,13 +1,12 @@ using Ryujinx.Common.Logging; using System; using System.IO; -using System.Text; namespace Ryujinx.HLE.Loaders.Mods { class IpsPatcher { - MemPatch _patches; + readonly MemPatch _patches; public IpsPatcher(BinaryReader reader) { @@ -20,15 +19,15 @@ namespace Ryujinx.HLE.Loaders.Mods private static MemPatch ParseIps(BinaryReader reader) { - ReadOnlySpan IpsHeaderMagic = "PATCH"u8; - ReadOnlySpan IpsTailMagic = "EOF"u8; - ReadOnlySpan Ips32HeaderMagic = "IPS32"u8; - ReadOnlySpan Ips32TailMagic = "EEOF"u8; + ReadOnlySpan ipsHeaderMagic = "PATCH"u8; + ReadOnlySpan ipsTailMagic = "EOF"u8; + ReadOnlySpan ips32HeaderMagic = "IPS32"u8; + ReadOnlySpan ips32TailMagic = "EEOF"u8; - MemPatch patches = new MemPatch(); - var header = reader.ReadBytes(IpsHeaderMagic.Length).AsSpan(); + MemPatch patches = new(); + var header = reader.ReadBytes(ipsHeaderMagic.Length).AsSpan(); - if (header.Length != IpsHeaderMagic.Length) + if (header.Length != ipsHeaderMagic.Length) { return null; } @@ -36,15 +35,15 @@ namespace Ryujinx.HLE.Loaders.Mods bool is32; ReadOnlySpan tailSpan; - if (header.SequenceEqual(IpsHeaderMagic)) + if (header.SequenceEqual(ipsHeaderMagic)) { is32 = false; - tailSpan = IpsTailMagic; + tailSpan = ipsTailMagic; } - else if (header.SequenceEqual(Ips32HeaderMagic)) + else if (header.SequenceEqual(ips32HeaderMagic)) { is32 = true; - tailSpan = Ips32TailMagic; + tailSpan = ips32TailMagic; } else { @@ -114,4 +113,4 @@ namespace Ryujinx.HLE.Loaders.Mods patches.AddFrom(_patches); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs b/src/Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs index 416fc1b49..693e03888 100644 --- a/src/Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs +++ b/src/Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs @@ -14,7 +14,7 @@ namespace Ryujinx.HLE.Loaders.Mods Normal, String, EscapeChar, - Comment + Comment, } private readonly StreamReader _reader; @@ -31,13 +31,13 @@ namespace Ryujinx.HLE.Loaders.Mods } _reader = reader; - BuildId = header.Substring(BidHeader.Length).TrimEnd().TrimEnd('0'); + BuildId = header[BidHeader.Length..].TrimEnd().TrimEnd('0'); } // Uncomments line and unescapes C style strings within private static string PreprocessLine(string line) { - StringBuilder str = new StringBuilder(); + StringBuilder str = new(); Token state = Token.Normal; for (int i = 0; i < line.Length; ++i) @@ -56,29 +56,32 @@ namespace Ryujinx.HLE.Loaders.Mods case Token.String: state = c switch { - '"' => Token.Normal, + '"' => Token.Normal, '\\' => Token.EscapeChar, - _ => Token.String + _ => Token.String, }; break; case Token.EscapeChar: state = Token.String; c = c switch { - 'a' => '\a', - 'b' => '\b', - 'f' => '\f', - 'n' => '\n', - 'r' => '\r', - 't' => '\t', - 'v' => '\v', + 'a' => '\a', + 'b' => '\b', + 'f' => '\f', + 'n' => '\n', + 'r' => '\r', + 't' => '\t', + 'v' => '\v', '\\' => '\\', - _ => '?' + _ => '?', }; break; } - if (state == Token.Comment) break; + if (state == Token.Comment) + { + break; + } if (state < Token.EscapeChar) { @@ -112,14 +115,17 @@ namespace Ryujinx.HLE.Loaders.Mods // Big Endian static byte[] Hex2ByteArrayBE(string hexstr) { - if ((hexstr.Length & 1) == 1) return null; + if ((hexstr.Length & 1) == 1) + { + return null; + } byte[] bytes = new byte[hexstr.Length >> 1]; for (int i = 0; i < hexstr.Length; i += 2) { int high = ParseHexByte((byte)hexstr[i]); - int low = ParseHexByte((byte)hexstr[i + 1]); + int low = ParseHexByte((byte)hexstr[i + 1]); bytes[i >> 1] = (byte)((high << 4) | low); } @@ -147,11 +153,11 @@ namespace Ryujinx.HLE.Loaders.Mods return null; } - MemPatch patches = new MemPatch(); + MemPatch patches = new(); - bool enabled = false; + bool enabled = false; bool printValues = false; - int offset_shift = 0; + int offsetShift = 0; string line; int lineNum = 0; @@ -205,7 +211,7 @@ namespace Ryujinx.HLE.Loaders.Mods if (tokens[1] == "offset_shift") { - if (tokens.Length != 3 || !ParseInt(tokens[2], out offset_shift)) + if (tokens.Length != 3 || !ParseInt(tokens[2], out offsetShift)) { ParseWarn(); @@ -244,7 +250,7 @@ namespace Ryujinx.HLE.Loaders.Mods continue; } - offset += offset_shift; + offset += offsetShift; if (printValues) { @@ -272,4 +278,4 @@ namespace Ryujinx.HLE.Loaders.Mods patches.AddFrom(Parse()); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Mods/MemPatch.cs b/src/Ryujinx.HLE/Loaders/Mods/MemPatch.cs index f9db7c699..0a1f12b18 100644 --- a/src/Ryujinx.HLE/Loaders/Mods/MemPatch.cs +++ b/src/Ryujinx.HLE/Loaders/Mods/MemPatch.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.Loaders.Mods { public class MemPatch { - readonly Dictionary _patches = new Dictionary(); + readonly Dictionary _patches = new(); ///

/// Adds a patch to specified offset. Overwrites if already present. @@ -69,7 +69,7 @@ namespace Ryujinx.HLE.Loaders.Mods foreach (var (offset, patch) in _patches.OrderBy(item => item.Key)) { int patchOffset = (int)offset; - int patchSize = patch.Length; + int patchSize = patch.Length; if (patchOffset < protectedOffset || patchOffset > memory.Length) { @@ -93,4 +93,4 @@ namespace Ryujinx.HLE.Loaders.Mods return count; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Npdm/ACI0.cs b/src/Ryujinx.HLE/Loaders/Npdm/ACI0.cs index 209e79d1e..9a5b6b0aa 100644 --- a/src/Ryujinx.HLE/Loaders/Npdm/ACI0.cs +++ b/src/Ryujinx.HLE/Loaders/Npdm/ACI0.cs @@ -9,17 +9,17 @@ namespace Ryujinx.HLE.Loaders.Npdm public ulong TitleId { get; set; } - public int FsVersion { get; private set; } + public int FsVersion { get; private set; } public ulong FsPermissionsBitmask { get; private set; } public ServiceAccessControl ServiceAccessControl { get; private set; } - public KernelAccessControl KernelAccessControl { get; private set; } + public KernelAccessControl KernelAccessControl { get; private set; } public Aci0(Stream stream, int offset) { stream.Seek(offset, SeekOrigin.Begin); - BinaryReader reader = new BinaryReader(stream); + BinaryReader reader = new(stream); if (reader.ReadInt32() != Aci0Magic) { @@ -33,16 +33,16 @@ namespace Ryujinx.HLE.Loaders.Npdm // Reserved. stream.Seek(8, SeekOrigin.Current); - int fsAccessHeaderOffset = reader.ReadInt32(); - int fsAccessHeaderSize = reader.ReadInt32(); + int fsAccessHeaderOffset = reader.ReadInt32(); + int fsAccessHeaderSize = reader.ReadInt32(); int serviceAccessControlOffset = reader.ReadInt32(); - int serviceAccessControlSize = reader.ReadInt32(); - int kernelAccessControlOffset = reader.ReadInt32(); - int kernelAccessControlSize = reader.ReadInt32(); + int serviceAccessControlSize = reader.ReadInt32(); + int kernelAccessControlOffset = reader.ReadInt32(); + int kernelAccessControlSize = reader.ReadInt32(); - FsAccessHeader fsAccessHeader = new FsAccessHeader(stream, offset + fsAccessHeaderOffset, fsAccessHeaderSize); + FsAccessHeader fsAccessHeader = new(stream, offset + fsAccessHeaderOffset, fsAccessHeaderSize); - FsVersion = fsAccessHeader.Version; + FsVersion = fsAccessHeader.Version; FsPermissionsBitmask = fsAccessHeader.PermissionsBitmask; ServiceAccessControl = new ServiceAccessControl(stream, offset + serviceAccessControlOffset, serviceAccessControlSize); diff --git a/src/Ryujinx.HLE/Loaders/Npdm/ACID.cs b/src/Ryujinx.HLE/Loaders/Npdm/ACID.cs index 365495c60..ab30b40ca 100644 --- a/src/Ryujinx.HLE/Loaders/Npdm/ACID.cs +++ b/src/Ryujinx.HLE/Loaders/Npdm/ACID.cs @@ -8,25 +8,25 @@ namespace Ryujinx.HLE.Loaders.Npdm private const int AcidMagic = 'A' << 0 | 'C' << 8 | 'I' << 16 | 'D' << 24; public byte[] Rsa2048Signature { get; private set; } - public byte[] Rsa2048Modulus { get; private set; } - public int Unknown1 { get; private set; } - public int Flags { get; private set; } + public byte[] Rsa2048Modulus { get; private set; } + public int Unknown1 { get; private set; } + public int Flags { get; private set; } public long TitleIdRangeMin { get; private set; } public long TitleIdRangeMax { get; private set; } - public FsAccessControl FsAccessControl { get; private set; } + public FsAccessControl FsAccessControl { get; private set; } public ServiceAccessControl ServiceAccessControl { get; private set; } - public KernelAccessControl KernelAccessControl { get; private set; } + public KernelAccessControl KernelAccessControl { get; private set; } public Acid(Stream stream, int offset) { stream.Seek(offset, SeekOrigin.Begin); - BinaryReader reader = new BinaryReader(stream); + BinaryReader reader = new(stream); Rsa2048Signature = reader.ReadBytes(0x100); - Rsa2048Modulus = reader.ReadBytes(0x100); + Rsa2048Modulus = reader.ReadBytes(0x100); if (reader.ReadInt32() != AcidMagic) { @@ -44,12 +44,12 @@ namespace Ryujinx.HLE.Loaders.Npdm TitleIdRangeMin = reader.ReadInt64(); TitleIdRangeMax = reader.ReadInt64(); - int fsAccessControlOffset = reader.ReadInt32(); - int fsAccessControlSize = reader.ReadInt32(); + int fsAccessControlOffset = reader.ReadInt32(); + int fsAccessControlSize = reader.ReadInt32(); int serviceAccessControlOffset = reader.ReadInt32(); - int serviceAccessControlSize = reader.ReadInt32(); - int kernelAccessControlOffset = reader.ReadInt32(); - int kernelAccessControlSize = reader.ReadInt32(); + int serviceAccessControlSize = reader.ReadInt32(); + int kernelAccessControlOffset = reader.ReadInt32(); + int kernelAccessControlSize = reader.ReadInt32(); FsAccessControl = new FsAccessControl(stream, offset + fsAccessControlOffset, fsAccessControlSize); diff --git a/src/Ryujinx.HLE/Loaders/Npdm/FsAccessControl.cs b/src/Ryujinx.HLE/Loaders/Npdm/FsAccessControl.cs index d0f349eaf..e533f513c 100644 --- a/src/Ryujinx.HLE/Loaders/Npdm/FsAccessControl.cs +++ b/src/Ryujinx.HLE/Loaders/Npdm/FsAccessControl.cs @@ -4,25 +4,25 @@ namespace Ryujinx.HLE.Loaders.Npdm { public class FsAccessControl { - public int Version { get; private set; } + public int Version { get; private set; } public ulong PermissionsBitmask { get; private set; } - public int Unknown1 { get; private set; } - public int Unknown2 { get; private set; } - public int Unknown3 { get; private set; } - public int Unknown4 { get; private set; } + public int Unknown1 { get; private set; } + public int Unknown2 { get; private set; } + public int Unknown3 { get; private set; } + public int Unknown4 { get; private set; } public FsAccessControl(Stream stream, int offset, int size) { stream.Seek(offset, SeekOrigin.Begin); - BinaryReader reader = new BinaryReader(stream); + BinaryReader reader = new(stream); - Version = reader.ReadInt32(); + Version = reader.ReadInt32(); PermissionsBitmask = reader.ReadUInt64(); - Unknown1 = reader.ReadInt32(); - Unknown2 = reader.ReadInt32(); - Unknown3 = reader.ReadInt32(); - Unknown4 = reader.ReadInt32(); + Unknown1 = reader.ReadInt32(); + Unknown2 = reader.ReadInt32(); + Unknown3 = reader.ReadInt32(); + Unknown4 = reader.ReadInt32(); } } } diff --git a/src/Ryujinx.HLE/Loaders/Npdm/FsAccessHeader.cs b/src/Ryujinx.HLE/Loaders/Npdm/FsAccessHeader.cs index 564b8dc39..7336464f5 100644 --- a/src/Ryujinx.HLE/Loaders/Npdm/FsAccessHeader.cs +++ b/src/Ryujinx.HLE/Loaders/Npdm/FsAccessHeader.cs @@ -6,16 +6,16 @@ namespace Ryujinx.HLE.Loaders.Npdm { class FsAccessHeader { - public int Version { get; private set; } + public int Version { get; private set; } public ulong PermissionsBitmask { get; private set; } public FsAccessHeader(Stream stream, int offset, int size) { stream.Seek(offset, SeekOrigin.Begin); - BinaryReader reader = new BinaryReader(stream); + BinaryReader reader = new(stream); - Version = reader.ReadInt32(); + Version = reader.ReadInt32(); PermissionsBitmask = reader.ReadUInt64(); int dataSize = reader.ReadInt32(); @@ -24,8 +24,9 @@ namespace Ryujinx.HLE.Loaders.Npdm { throw new InvalidNpdmException("FsAccessHeader is corrupted!"); } - - int contentOwnerIdSize = reader.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + int contentOwnerIdSize = reader.ReadInt32(); +#pragma warning restore IDE0059 int dataAndContentOwnerIdSize = reader.ReadInt32(); if (dataAndContentOwnerIdSize != 0x1c) diff --git a/src/Ryujinx.HLE/Loaders/Npdm/KernelAccessControl.cs b/src/Ryujinx.HLE/Loaders/Npdm/KernelAccessControl.cs index 39803642c..bc8bdbaaa 100644 --- a/src/Ryujinx.HLE/Loaders/Npdm/KernelAccessControl.cs +++ b/src/Ryujinx.HLE/Loaders/Npdm/KernelAccessControl.cs @@ -12,7 +12,7 @@ namespace Ryujinx.HLE.Loaders.Npdm Capabilities = new int[size / 4]; - BinaryReader reader = new BinaryReader(stream); + BinaryReader reader = new(stream); for (int index = 0; index < Capabilities.Length; index++) { diff --git a/src/Ryujinx.HLE/Loaders/Npdm/Npdm.cs b/src/Ryujinx.HLE/Loaders/Npdm/Npdm.cs index 29a2b0fc0..622d7ee03 100644 --- a/src/Ryujinx.HLE/Loaders/Npdm/Npdm.cs +++ b/src/Ryujinx.HLE/Loaders/Npdm/Npdm.cs @@ -11,22 +11,22 @@ namespace Ryujinx.HLE.Loaders.Npdm { private const int MetaMagic = 'M' << 0 | 'E' << 8 | 'T' << 16 | 'A' << 24; - public byte ProcessFlags { get; private set; } - public bool Is64Bit { get; private set; } - public byte MainThreadPriority { get; private set; } - public byte DefaultCpuId { get; private set; } - public int PersonalMmHeapSize { get; private set; } - public int Version { get; private set; } - public int MainThreadStackSize { get; private set; } - public string TitleName { get; set; } - public byte[] ProductCode { get; private set; } + public byte ProcessFlags { get; private set; } + public bool Is64Bit { get; private set; } + public byte MainThreadPriority { get; private set; } + public byte DefaultCpuId { get; private set; } + public int PersonalMmHeapSize { get; private set; } + public int Version { get; private set; } + public int MainThreadStackSize { get; private set; } + public string TitleName { get; set; } + public byte[] ProductCode { get; private set; } public Aci0 Aci0 { get; private set; } public Acid Acid { get; private set; } public Npdm(Stream stream) { - BinaryReader reader = new BinaryReader(stream); + BinaryReader reader = new(stream); if (reader.ReadInt32() != MetaMagic) { @@ -42,7 +42,7 @@ namespace Ryujinx.HLE.Loaders.Npdm reader.ReadByte(); MainThreadPriority = reader.ReadByte(); - DefaultCpuId = reader.ReadByte(); + DefaultCpuId = reader.ReadByte(); reader.ReadInt32(); @@ -61,9 +61,11 @@ namespace Ryujinx.HLE.Loaders.Npdm stream.Seek(0x30, SeekOrigin.Current); int aci0Offset = reader.ReadInt32(); - int aci0Size = reader.ReadInt32(); +#pragma warning disable IDE0059 // Remove unnecessary value assignment + int aci0Size = reader.ReadInt32(); int acidOffset = reader.ReadInt32(); - int acidSize = reader.ReadInt32(); + int acidSize = reader.ReadInt32(); +#pragma warning restore IDE0059 Aci0 = new Aci0(stream, aci0Offset); Acid = new Acid(stream, acidOffset); diff --git a/src/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs b/src/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs index 54012b8a9..53c864346 100644 --- a/src/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs +++ b/src/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs @@ -13,11 +13,11 @@ namespace Ryujinx.HLE.Loaders.Npdm { stream.Seek(offset, SeekOrigin.Begin); - BinaryReader reader = new BinaryReader(stream); + BinaryReader reader = new(stream); int bytesRead = 0; - Dictionary services = new Dictionary(); + Dictionary services = new(); while (bytesRead != size) { @@ -28,7 +28,7 @@ namespace Ryujinx.HLE.Loaders.Npdm break; } - int length = (controlByte & 0x07) + 1; + int length = (controlByte & 0x07) + 1; bool registerAllowed = (controlByte & 0x80) != 0; services[Encoding.ASCII.GetString(reader.ReadBytes(length))] = registerAllowed; diff --git a/src/Ryujinx.HLE/Loaders/Processes/Extensions/FileSystemExtensions.cs b/src/Ryujinx.HLE/Loaders/Processes/Extensions/FileSystemExtensions.cs index b619a7134..040d1143d 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/Extensions/FileSystemExtensions.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/Extensions/FileSystemExtensions.cs @@ -86,7 +86,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions bool enablePtc = device.System.EnablePtc && !modLoadResult.Modified; if (!enablePtc) { - Logger.Warning?.Print(LogClass.Ptc, $"Detected unsupported ExeFs modifications. PTC disabled."); + Logger.Warning?.Print(LogClass.Ptc, "Detected unsupported ExeFs modifications. PTC disabled."); } // We allow it for nx-hbloader because it can be used to launch homebrew. @@ -131,4 +131,4 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions return processResult; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Processes/Extensions/LocalFileSystemExtensions.cs b/src/Ryujinx.HLE/Loaders/Processes/Extensions/LocalFileSystemExtensions.cs index fb85329d2..2b7e84734 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/Extensions/LocalFileSystemExtensions.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/Extensions/LocalFileSystemExtensions.cs @@ -1,10 +1,10 @@ using LibHac.Common; using LibHac.FsSystem; using LibHac.Loader; +using LibHac.Ncm; using LibHac.Ns; using Ryujinx.HLE.HOS; using Ryujinx.HLE.Loaders.Processes.Extensions; -using ApplicationId = LibHac.Ncm.ApplicationId; namespace Ryujinx.HLE.Loaders.Processes { @@ -13,8 +13,8 @@ namespace Ryujinx.HLE.Loaders.Processes public static ProcessResult Load(this LocalFileSystem exeFs, Switch device, string romFsPath = "") { MetaLoader metaLoader = exeFs.GetNpdm(); - var nacpData = new BlitStruct(1); - ulong programId = metaLoader.GetProgramId(); + var nacpData = new BlitStruct(1); + ulong programId = metaLoader.GetProgramId(); device.Configuration.VirtualFileSystem.ModLoader.CollectMods( new[] { programId }, @@ -37,4 +37,4 @@ namespace Ryujinx.HLE.Loaders.Processes return processResult; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Processes/Extensions/MetaLoaderExtensions.cs b/src/Ryujinx.HLE/Loaders/Processes/Extensions/MetaLoaderExtensions.cs index c639ee524..88f437591 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/Extensions/MetaLoaderExtensions.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/Extensions/MetaLoaderExtensions.cs @@ -58,4 +58,4 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions metaLoader.Load(npdmBuffer).ThrowIfFailure(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Processes/Extensions/NcaExtensions.cs b/src/Ryujinx.HLE/Loaders/Processes/Extensions/NcaExtensions.cs index e11b81d7f..4568b44da 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/Extensions/NcaExtensions.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/Extensions/NcaExtensions.cs @@ -20,7 +20,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions public static ProcessResult Load(this Nca nca, Switch device, Nca patchNca, Nca controlNca) { // Extract RomFs and ExeFs from NCA. - IStorage romFs = nca.GetRomFs(device, patchNca); + IStorage romFs = nca.GetRomFs(device, patchNca); IFileSystem exeFs = nca.GetExeFs(device, patchNca); if (exeFs == null) @@ -173,4 +173,4 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions return nacpData; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Processes/Extensions/PartitionFileSystemExtensions.cs b/src/Ryujinx.HLE/Loaders/Processes/Extensions/PartitionFileSystemExtensions.cs index e93802ae8..6de99131e 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/Extensions/PartitionFileSystemExtensions.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/Extensions/PartitionFileSystemExtensions.cs @@ -17,16 +17,16 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions { public static class PartitionFileSystemExtensions { - private static readonly DownloadableContentJsonSerializerContext ContentSerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); - private static readonly TitleUpdateMetadataJsonSerializerContext TitleSerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); + private static readonly DownloadableContentJsonSerializerContext _contentSerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); + private static readonly TitleUpdateMetadataJsonSerializerContext _titleSerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); internal static (bool, ProcessResult) TryLoad(this PartitionFileSystem partitionFileSystem, Switch device, string path, out string errorMessage) { errorMessage = null; // Load required NCAs. - Nca mainNca = null; - Nca patchNca = null; + Nca mainNca = null; + Nca patchNca = null; Nca controlNca = null; try @@ -88,7 +88,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions string titleUpdateMetadataPath = System.IO.Path.Combine(AppDataManager.GamesDirPath, titleIdBase.ToString("x16"), "updates.json"); if (File.Exists(titleUpdateMetadataPath)) { - string updatePath = JsonHelper.DeserializeFromFile(titleUpdateMetadataPath, TitleSerializerContext.TitleUpdateMetadata).Selected; + string updatePath = JsonHelper.DeserializeFromFile(titleUpdateMetadataPath, _titleSerializerContext.TitleUpdateMetadata).Selected; if (File.Exists(updatePath)) { PartitionFileSystem updatePartitionFileSystem = new(new FileStream(updatePath, FileMode.Open, FileAccess.Read).AsStorage()); @@ -142,7 +142,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions string addOnContentMetadataPath = System.IO.Path.Combine(AppDataManager.GamesDirPath, mainNca.Header.TitleId.ToString("x16"), "dlc.json"); if (File.Exists(addOnContentMetadataPath)) { - List dlcContainerList = JsonHelper.DeserializeFromFile(addOnContentMetadataPath, ContentSerializerContext.ListDownloadableContentContainer); + List dlcContainerList = JsonHelper.DeserializeFromFile(addOnContentMetadataPath, _contentSerializerContext.ListDownloadableContentContainer); foreach (DownloadableContentContainer downloadableContentContainer in dlcContainerList) { @@ -177,4 +177,4 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions return new Nca(device.Configuration.VirtualFileSystem.KeySet, ncaFile.Release().AsStorage()); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Processes/ProcessConst.cs b/src/Ryujinx.HLE/Loaders/Processes/ProcessConst.cs index 42ae2e89b..5df7be29f 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/ProcessConst.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/ProcessConst.cs @@ -17,7 +17,7 @@ "subsdk7", "subsdk8", "subsdk9", - "sdk" + "sdk", }; public static readonly string MainNpdmPath = "/main.npdm"; @@ -27,7 +27,7 @@ public const bool AslrEnabled = true; public const int NsoArgsHeaderSize = 8; - public const int NsoArgsDataSize = 0x9000; - public const int NsoArgsTotalSize = NsoArgsHeaderSize + NsoArgsDataSize; + public const int NsoArgsDataSize = 0x9000; + public const int NsoArgsTotalSize = NsoArgsHeaderSize + NsoArgsDataSize; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs b/src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs index f391f9656..51cbb6f99 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs @@ -12,7 +12,6 @@ using Ryujinx.HLE.Loaders.Processes.Extensions; using System; using System.Collections.Concurrent; using System.IO; -using System.Linq; using Path = System.IO.Path; namespace Ryujinx.HLE.Loaders.Processes @@ -29,14 +28,14 @@ namespace Ryujinx.HLE.Loaders.Processes public ProcessLoader(Switch device) { - _device = device; + _device = device; _processesByPid = new ConcurrentDictionary(); } public bool LoadXci(string path) { FileStream stream = new(path, FileMode.Open, FileAccess.Read); - Xci xci = new(_device.Configuration.VirtualFileSystem.KeySet, stream.AsStorage()); + Xci xci = new(_device.Configuration.VirtualFileSystem.KeySet, stream.AsStorage()); if (!xci.HasPartition(XciPartitionType.Secure)) { @@ -69,7 +68,7 @@ namespace Ryujinx.HLE.Loaders.Processes public bool LoadNsp(string path) { - FileStream file = new(path, FileMode.Open, FileAccess.Read); + FileStream file = new(path, FileMode.Open, FileAccess.Read); PartitionFileSystem partitionFileSystem = new(file.AsStorage()); (bool success, ProcessResult processResult) = partitionFileSystem.TryLoad(_device, path, out string errorMessage); @@ -101,7 +100,7 @@ namespace Ryujinx.HLE.Loaders.Processes public bool LoadNca(string path) { FileStream file = new(path, FileMode.Open, FileAccess.Read); - Nca nca = new(_device.Configuration.VirtualFileSystem.KeySet, file.AsStorage(false)); + Nca nca = new(_device.Configuration.VirtualFileSystem.KeySet, file.AsStorage(false)); ProcessResult processResult = nca.Load(_device, null, null); @@ -141,20 +140,20 @@ namespace Ryujinx.HLE.Loaders.Processes public bool LoadNxo(string path) { - var nacpData = new BlitStruct(1); - IFileSystem dummyExeFs = null; - Stream romfsStream = null; + var nacpData = new BlitStruct(1); + IFileSystem dummyExeFs = null; + Stream romfsStream = null; string programName = ""; - ulong programId = 0000000000000000; + ulong programId = 0000000000000000; // Load executable. IExecutable executable; if (Path.GetExtension(path).ToLower() == ".nro") { - FileStream input = new(path, FileMode.Open); - NroExecutable nro = new(input.AsStorage()); + FileStream input = new(path, FileMode.Open); + NroExecutable nro = new(input.AsStorage()); executable = nro; @@ -242,4 +241,4 @@ namespace Ryujinx.HLE.Loaders.Processes return false; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Processes/ProcessLoaderHelper.cs b/src/Ryujinx.HLE/Loaders/Processes/ProcessLoaderHelper.cs index d1c60f167..d14a013af 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/ProcessLoaderHelper.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/ProcessLoaderHelper.cs @@ -31,7 +31,7 @@ namespace Ryujinx.HLE.Loaders.Processes public static LibHac.Result RegisterProgramMapInfo(Switch device, PartitionFileSystem partitionFileSystem) { ulong applicationId = 0; - int programCount = 0; + int programCount = 0; Span hasIndex = stackalloc bool[0x10]; @@ -44,7 +44,7 @@ namespace Ryujinx.HLE.Loaders.Processes continue; } - ulong currentProgramId = nca.Header.TitleId; + ulong currentProgramId = nca.Header.TitleId; ulong currentMainProgramId = currentProgramId & ~0xFFFul; if (applicationId == 0 && currentMainProgramId != 0) @@ -82,9 +82,9 @@ namespace Ryujinx.HLE.Loaders.Processes for (int i = 0; i < programCount; i++) { - mapInfo[i].ProgramId = new ProgramId(applicationId + (uint)i); + mapInfo[i].ProgramId = new ProgramId(applicationId + (uint)i); mapInfo[i].MainProgramId = new ApplicationId(applicationId); - mapInfo[i].ProgramIndex = (byte)i; + mapInfo[i].ProgramIndex = (byte)i; } return device.System.LibHacHorizonManager.NsClient.Fs.RegisterProgramIndexMapInfo(mapInfo[..programCount]); @@ -102,9 +102,9 @@ namespace Ryujinx.HLE.Loaders.Processes control = ref new BlitStruct(1).Value; // The set sizes don't actually matter as long as they're non-zero because we use directory savedata. - control.UserAccountSaveDataSize = 0x4000; + control.UserAccountSaveDataSize = 0x4000; control.UserAccountSaveDataJournalSize = 0x4000; - control.SaveDataOwnerId = applicationId.Value; + control.SaveDataOwnerId = applicationId.Value; Logger.Warning?.Print(LogClass.Application, "No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games."); } @@ -137,10 +137,10 @@ namespace Ryujinx.HLE.Loaders.Processes endOffset = kip.BssOffset + kip.BssSize; } - uint codeSize = BitUtils.AlignUp(kip.TextOffset + endOffset, KPageTableBase.PageSize); - int codePagesCount = (int)(codeSize / KPageTableBase.PageSize); + uint codeSize = BitUtils.AlignUp(kip.TextOffset + endOffset, KPageTableBase.PageSize); + int codePagesCount = (int)(codeSize / KPageTableBase.PageSize); ulong codeBaseAddress = kip.Is64BitAddressSpace ? 0x8000000UL : 0x200000UL; - ulong codeAddress = codeBaseAddress + kip.TextOffset; + ulong codeAddress = codeBaseAddress + kip.TextOffset; ProcessCreationFlags flags = 0; @@ -161,9 +161,9 @@ namespace Ryujinx.HLE.Loaders.Processes flags |= ProcessCreationFlags.Is64Bit; } - ProcessCreationInfo creationInfo = new(kip.Name, kip.Version, kip.ProgramId, codeAddress, codePagesCount, flags, 0, 0); - MemoryRegion memoryRegion = kip.UsesSecureMemory ? MemoryRegion.Service : MemoryRegion.Application; - KMemoryRegionManager region = context.MemoryManager.MemoryRegions[(int)memoryRegion]; + ProcessCreationInfo creationInfo = new(kip.Name, kip.Version, kip.ProgramId, codeAddress, codePagesCount, flags, 0, 0); + MemoryRegion memoryRegion = kip.UsesSecureMemory ? MemoryRegion.Service : MemoryRegion.Application; + KMemoryRegionManager region = context.MemoryManager.MemoryRegions[(int)memoryRegion]; Result result = region.AllocatePages(out KPageList pageList, (ulong)codePagesCount); if (result != Result.Success) @@ -241,15 +241,15 @@ namespace Ryujinx.HLE.Loaders.Processes ref readonly var meta = ref npdm.Meta; ulong argsStart = 0; - uint argsSize = 0; + uint argsSize = 0; ulong codeStart = (meta.Flags & 1) != 0 ? 0x8000000UL : 0x200000UL; - uint codeSize = 0; + uint codeSize = 0; var buildIds = executables.Select(e => (e switch { NsoExecutable nso => Convert.ToHexString(nso.BuildId.ItemsRo.ToArray()), NroExecutable nro => Convert.ToHexString(nro.Header.BuildId), - _ => "" + _ => "", }).ToUpper()); ulong[] nsoBase = new ulong[executables.Length]; @@ -259,7 +259,7 @@ namespace Ryujinx.HLE.Loaders.Processes IExecutable nso = executables[index]; uint textEnd = nso.TextOffset + (uint)nso.Text.Length; - uint roEnd = nso.RoOffset + (uint)nso.Ro.Length; + uint roEnd = nso.RoOffset + (uint)nso.Ro.Length; uint dataEnd = nso.DataOffset + (uint)nso.Data.Length + nso.BssSize; uint nsoSize = textEnd; @@ -290,7 +290,7 @@ namespace Ryujinx.HLE.Loaders.Processes } } - int codePagesCount = (int)(codeSize / KPageTableBase.PageSize); + int codePagesCount = (int)(codeSize / KPageTableBase.PageSize); int personalMmHeapPagesCount = (int)(meta.SystemResourceSize / KPageTableBase.PageSize); ProcessCreationInfo creationInfo = new( @@ -335,7 +335,7 @@ namespace Ryujinx.HLE.Loaders.Processes if (result != Result.Success) { - Logger.Error?.Print(LogClass.Loader, $"Process initialization failed setting resource limit values."); + Logger.Error?.Print(LogClass.Loader, "Process initialization failed setting resource limit values."); return ProcessResult.Failed; } @@ -346,7 +346,7 @@ namespace Ryujinx.HLE.Loaders.Processes MemoryRegion memoryRegion = (MemoryRegion)(npdm.Acid.Flags >> 2 & 0xf); if (memoryRegion > MemoryRegion.NvServices) { - Logger.Error?.Print(LogClass.Loader, $"Process initialization failed due to invalid ACID flags."); + Logger.Error?.Print(LogClass.Loader, "Process initialization failed due to invalid ACID flags."); return ProcessResult.Failed; } @@ -420,9 +420,9 @@ namespace Ryujinx.HLE.Loaders.Processes public static Result LoadIntoMemory(KProcess process, IExecutable image, ulong baseAddress) { ulong textStart = baseAddress + image.TextOffset; - ulong roStart = baseAddress + image.RoOffset; + ulong roStart = baseAddress + image.RoOffset; ulong dataStart = baseAddress + image.DataOffset; - ulong bssStart = baseAddress + image.BssOffset; + ulong bssStart = baseAddress + image.BssOffset; ulong end = dataStart + (ulong)image.Data.Length; @@ -432,7 +432,7 @@ namespace Ryujinx.HLE.Loaders.Processes } process.CpuMemory.Write(textStart, image.Text); - process.CpuMemory.Write(roStart, image.Ro); + process.CpuMemory.Write(roStart, image.Ro); process.CpuMemory.Write(dataStart, image.Data); process.CpuMemory.Fill(bssStart, image.BssSize, 0); @@ -464,4 +464,4 @@ namespace Ryujinx.HLE.Loaders.Processes return SetProcessMemoryPermission(dataStart, end - dataStart, KMemoryPermission.ReadAndWrite); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs b/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs index 40b516cc8..9a7b3cd0e 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs @@ -7,7 +7,6 @@ using Ryujinx.HLE.HOS.SystemState; using Ryujinx.HLE.Loaders.Processes.Extensions; using Ryujinx.Horizon.Common; using System; -using System.Linq; namespace Ryujinx.HLE.Loaders.Processes { @@ -20,36 +19,36 @@ namespace Ryujinx.HLE.Loaders.Processes public readonly IDiskCacheLoadState DiskCacheLoadState; - public readonly MetaLoader MetaLoader; + public readonly MetaLoader MetaLoader; public readonly ApplicationControlProperty ApplicationControlProperties; - public readonly ulong ProcessId; + public readonly ulong ProcessId; public readonly string Name; public readonly string DisplayVersion; - public readonly ulong ProgramId; + public readonly ulong ProgramId; public readonly string ProgramIdText; - public readonly bool Is64Bit; - public readonly bool DiskCacheEnabled; - public readonly bool AllowCodeMemoryForJit; + public readonly bool Is64Bit; + public readonly bool DiskCacheEnabled; + public readonly bool AllowCodeMemoryForJit; public ProcessResult( - MetaLoader metaLoader, + MetaLoader metaLoader, BlitStruct applicationControlProperties, - bool diskCacheEnabled, - bool allowCodeMemoryForJit, - IDiskCacheLoadState diskCacheLoadState, - ulong pid, - byte mainThreadPriority, - uint mainThreadStackSize, - TitleLanguage titleLanguage) + bool diskCacheEnabled, + bool allowCodeMemoryForJit, + IDiskCacheLoadState diskCacheLoadState, + ulong pid, + byte mainThreadPriority, + uint mainThreadStackSize, + TitleLanguage titleLanguage) { - _mainThreadPriority = mainThreadPriority; + _mainThreadPriority = mainThreadPriority; _mainThreadStackSize = mainThreadStackSize; DiskCacheLoadState = diskCacheLoadState; - ProcessId = pid; + ProcessId = pid; - MetaLoader = metaLoader; + MetaLoader = metaLoader; ApplicationControlProperties = applicationControlProperties.Value; if (metaLoader is not null) @@ -64,12 +63,12 @@ namespace Ryujinx.HLE.Loaders.Processes } DisplayVersion = ApplicationControlProperties.DisplayVersionString.ToString(); - ProgramId = programId; - ProgramIdText = $"{programId:x16}"; - Is64Bit = metaLoader.IsProgram64Bit(); + ProgramId = programId; + ProgramIdText = $"{programId:x16}"; + Is64Bit = metaLoader.IsProgram64Bit(); } - DiskCacheEnabled = diskCacheEnabled; + DiskCacheEnabled = diskCacheEnabled; AllowCodeMemoryForJit = allowCodeMemoryForJit; } diff --git a/src/Ryujinx.HLE/MemoryConfiguration.cs b/src/Ryujinx.HLE/MemoryConfiguration.cs index 25044bb5f..45e8927db 100644 --- a/src/Ryujinx.HLE/MemoryConfiguration.cs +++ b/src/Ryujinx.HLE/MemoryConfiguration.cs @@ -5,18 +5,19 @@ namespace Ryujinx.HLE { public enum MemoryConfiguration { - MemoryConfiguration4GiB = 0, + MemoryConfiguration4GiB = 0, MemoryConfiguration4GiBAppletDev = 1, MemoryConfiguration4GiBSystemDev = 2, - MemoryConfiguration6GiB = 3, + MemoryConfiguration6GiB = 3, MemoryConfiguration6GiBAppletDev = 4, - MemoryConfiguration8GiB = 5 + MemoryConfiguration8GiB = 5, } static class MemoryConfigurationExtensions { private const ulong GiB = 1024 * 1024 * 1024; +#pragma warning disable IDE0055 // Disable formatting public static MemoryArrange ToKernelMemoryArrange(this MemoryConfiguration configuration) { return configuration switch @@ -27,7 +28,7 @@ namespace Ryujinx.HLE MemoryConfiguration.MemoryConfiguration6GiB => MemoryArrange.MemoryArrange6GiB, MemoryConfiguration.MemoryConfiguration6GiBAppletDev => MemoryArrange.MemoryArrange6GiBAppletDev, MemoryConfiguration.MemoryConfiguration8GiB => MemoryArrange.MemoryArrange8GiB, - _ => throw new AggregateException($"Invalid memory configuration \"{configuration}\".") + _ => throw new AggregateException($"Invalid memory configuration \"{configuration}\"."), }; } @@ -41,7 +42,7 @@ namespace Ryujinx.HLE MemoryConfiguration.MemoryConfiguration6GiB or MemoryConfiguration.MemoryConfiguration6GiBAppletDev => MemorySize.MemorySize6GiB, MemoryConfiguration.MemoryConfiguration8GiB => MemorySize.MemorySize8GiB, - _ => throw new AggregateException($"Invalid memory configuration \"{configuration}\".") + _ => throw new AggregateException($"Invalid memory configuration \"{configuration}\"."), }; } @@ -55,8 +56,9 @@ namespace Ryujinx.HLE MemoryConfiguration.MemoryConfiguration6GiB or MemoryConfiguration.MemoryConfiguration6GiBAppletDev => 6 * GiB, MemoryConfiguration.MemoryConfiguration8GiB => 8 * GiB, - _ => throw new AggregateException($"Invalid memory configuration \"{configuration}\".") + _ => throw new AggregateException($"Invalid memory configuration \"{configuration}\"."), }; } +#pragma warning restore IDE0055 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/PerformanceStatistics.cs b/src/Ryujinx.HLE/PerformanceStatistics.cs index 95fc2abe3..e7270db30 100644 --- a/src/Ryujinx.HLE/PerformanceStatistics.cs +++ b/src/Ryujinx.HLE/PerformanceStatistics.cs @@ -5,44 +5,44 @@ namespace Ryujinx.HLE { public class PerformanceStatistics { - private const int FrameTypeGame = 0; + private const int FrameTypeGame = 0; private const int PercentTypeFifo = 0; - private double[] _frameRate; - private double[] _accumulatedFrameTime; - private double[] _previousFrameTime; + private readonly double[] _frameRate; + private readonly double[] _accumulatedFrameTime; + private readonly double[] _previousFrameTime; - private double[] _averagePercent; - private double[] _accumulatedActiveTime; - private double[] _percentLastEndTime; - private double[] _percentStartTime; + private readonly double[] _averagePercent; + private readonly double[] _accumulatedActiveTime; + private readonly double[] _percentLastEndTime; + private readonly double[] _percentStartTime; - private long[] _framesRendered; - private double[] _percentTime; + private readonly long[] _framesRendered; + private readonly double[] _percentTime; - private object[] _frameLock; - private object[] _percentLock; + private readonly object[] _frameLock; + private readonly object[] _percentLock; - private double _ticksToSeconds; + private readonly double _ticksToSeconds; - private Timer _resetTimer; + private readonly Timer _resetTimer; public PerformanceStatistics() { - _frameRate = new double[1]; + _frameRate = new double[1]; _accumulatedFrameTime = new double[1]; - _previousFrameTime = new double[1]; + _previousFrameTime = new double[1]; - _averagePercent = new double[1]; + _averagePercent = new double[1]; _accumulatedActiveTime = new double[1]; - _percentLastEndTime = new double[1]; - _percentStartTime = new double[1]; + _percentLastEndTime = new double[1]; + _percentStartTime = new double[1]; _framesRendered = new long[1]; - _percentTime = new double[1]; + _percentTime = new double[1]; - _frameLock = new object[] { new object() }; - _percentLock = new object[] { new object() }; + _frameLock = new[] { new object() }; + _percentLock = new[] { new object() }; _resetTimer = new Timer(750); @@ -71,8 +71,8 @@ namespace Ryujinx.HLE frameRate = _framesRendered[frameType] / _accumulatedFrameTime[frameType]; } - _frameRate[frameType] = frameRate; - _framesRendered[frameType] = 0; + _frameRate[frameType] = frameRate; + _framesRendered[frameType] = 0; _accumulatedFrameTime[frameType] = 0; } } @@ -90,8 +90,8 @@ namespace Ryujinx.HLE percent = (_accumulatedActiveTime[percentType] / _percentTime[percentType]) * 100; } - _averagePercent[percentType] = percent; - _percentTime[percentType] = 0; + _averagePercent[percentType] = percent; + _percentTime[percentType] = 0; _accumulatedActiveTime[percentType] = 0; } } @@ -120,18 +120,18 @@ namespace Ryujinx.HLE private void EndPercentTime(int percentType) { - double currentTime = PerformanceCounter.ElapsedTicks * _ticksToSeconds; - double elapsedTime = currentTime - _percentLastEndTime[percentType]; + double currentTime = PerformanceCounter.ElapsedTicks * _ticksToSeconds; + double elapsedTime = currentTime - _percentLastEndTime[percentType]; double elapsedActiveTime = currentTime - _percentStartTime[percentType]; lock (_percentLock[percentType]) { _accumulatedActiveTime[percentType] += elapsedActiveTime; - _percentTime[percentType] += elapsedTime; + _percentTime[percentType] += elapsedTime; } _percentLastEndTime[percentType] = currentTime; - _percentStartTime[percentType] = 0; + _percentStartTime[percentType] = 0; } private void RecordFrameTime(int frameType) @@ -164,4 +164,4 @@ namespace Ryujinx.HLE return 1000 / _frameRate[FrameTypeGame]; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Switch.cs b/src/Ryujinx.HLE/Switch.cs index 62d14a546..ae063a47d 100644 --- a/src/Ryujinx.HLE/Switch.cs +++ b/src/Ryujinx.HLE/Switch.cs @@ -15,17 +15,17 @@ namespace Ryujinx.HLE { public class Switch : IDisposable { - public HLEConfiguration Configuration { get; } + public HLEConfiguration Configuration { get; } public IHardwareDeviceDriver AudioDeviceDriver { get; } - public MemoryBlock Memory { get; } - public GpuContext Gpu { get; } - public VirtualFileSystem FileSystem { get; } - public HOS.Horizon System { get; } - public ProcessLoader Processes { get; } - public PerformanceStatistics Statistics { get; } - public Hid Hid { get; } - public TamperMachine TamperMachine { get; } - public IHostUiHandler UiHandler { get; } + public MemoryBlock Memory { get; } + public GpuContext Gpu { get; } + public VirtualFileSystem FileSystem { get; } + public HOS.Horizon System { get; } + public ProcessLoader Processes { get; } + public PerformanceStatistics Statistics { get; } + public Hid Hid { get; } + public TamperMachine TamperMachine { get; } + public IHostUiHandler UiHandler { get; } public bool EnableDeviceVsync { get; set; } = true; @@ -38,13 +38,14 @@ namespace Ryujinx.HLE ArgumentNullException.ThrowIfNull(configuration.UserChannelPersistence); Configuration = configuration; - FileSystem = Configuration.VirtualFileSystem; - UiHandler = Configuration.HostUiHandler; + FileSystem = Configuration.VirtualFileSystem; + UiHandler = Configuration.HostUiHandler; MemoryAllocationFlags memoryAllocationFlags = configuration.MemoryManagerMode == MemoryManagerMode.SoftwarePageTable ? MemoryAllocationFlags.Reserve : MemoryAllocationFlags.Reserve | MemoryAllocationFlags.Mirrorable; +#pragma warning disable IDE0055 // Disable formatting AudioDeviceDriver = new CompatLayerHardwareDeviceDriver(Configuration.AudioDeviceDriver); Memory = new MemoryBlock(Configuration.MemoryConfiguration.ToDramSize(), memoryAllocationFlags); Gpu = new GpuContext(Configuration.GpuRenderer); @@ -63,6 +64,7 @@ namespace Ryujinx.HLE System.EnablePtc = Configuration.EnablePtc; System.FsIntegrityCheckLevel = Configuration.FsIntegrityCheckLevel; System.GlobalAccessLogMode = Configuration.FsGlobalAccessLogMode; +#pragma warning restore IDE0055 } public bool LoadCart(string exeFsDir, string romFsFile = null) @@ -124,7 +126,7 @@ namespace Ryujinx.HLE public void EnableCheats() { - FileSystem.ModLoader.EnableCheats(Processes.ActiveApplication.ProgramId, TamperMachine); + ModLoader.EnableCheats(Processes.ActiveApplication.ProgramId, TamperMachine); } public bool IsAudioMuted() @@ -139,6 +141,7 @@ namespace Ryujinx.HLE public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } diff --git a/src/Ryujinx.HLE/Ui/DynamicTextChangedHandler.cs b/src/Ryujinx.HLE/Ui/DynamicTextChangedHandler.cs index c571fb683..cb9ca0dec 100644 --- a/src/Ryujinx.HLE/Ui/DynamicTextChangedHandler.cs +++ b/src/Ryujinx.HLE/Ui/DynamicTextChangedHandler.cs @@ -1,4 +1,4 @@ namespace Ryujinx.HLE.Ui { public delegate void DynamicTextChangedHandler(string text, int cursorBegin, int cursorEnd, bool overwriteMode); -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Ui/IDynamicTextInputHandler.cs b/src/Ryujinx.HLE/Ui/IDynamicTextInputHandler.cs index 6e7b4c495..e530d2c4e 100644 --- a/src/Ryujinx.HLE/Ui/IDynamicTextInputHandler.cs +++ b/src/Ryujinx.HLE/Ui/IDynamicTextInputHandler.cs @@ -13,4 +13,4 @@ namespace Ryujinx.HLE.Ui void SetText(string text, int cursorBegin); void SetText(string text, int cursorBegin, int cursorEnd); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Ui/IHostUiHandler.cs b/src/Ryujinx.HLE/Ui/IHostUiHandler.cs index 91d8be857..68f78f22d 100644 --- a/src/Ryujinx.HLE/Ui/IHostUiHandler.cs +++ b/src/Ryujinx.HLE/Ui/IHostUiHandler.cs @@ -48,4 +48,4 @@ namespace Ryujinx.HLE.Ui /// IHostUiTheme HostUiTheme { get; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Ui/Input/NpadReader.cs b/src/Ryujinx.HLE/Ui/Input/NpadReader.cs index a0d78d03a..c4ef5da50 100644 --- a/src/Ryujinx.HLE/Ui/Input/NpadReader.cs +++ b/src/Ryujinx.HLE/Ui/Input/NpadReader.cs @@ -9,7 +9,7 @@ namespace Ryujinx.HLE.Ui.Input class NpadReader { private readonly Switch _device; - private NpadCommonState[] _lastStates; + private readonly NpadCommonState[] _lastStates; public event NpadButtonHandler NpadButtonUpEvent; public event NpadButtonHandler NpadButtonDownEvent; @@ -37,7 +37,7 @@ namespace Ryujinx.HLE.Ui.Input return buttons; } - private ref RingLifo GetCommonStateLifo(ref NpadInternalState npad) + private static ref RingLifo GetCommonStateLifo(ref NpadInternalState npad) { switch (npad.StyleSet) { @@ -58,7 +58,7 @@ namespace Ryujinx.HLE.Ui.Input } } - public void Update(bool supressEvents=false) + public void Update(bool supressEvents = false) { ref var npads = ref _device.Hid.SharedMemory.Npads; @@ -81,7 +81,11 @@ namespace Ryujinx.HLE.Ui.Input int firstEntryNum; // Scan the LIFO for the first entry that is newer that what's already processed. - for (firstEntryNum = fullKeyEntries.Length - 1; firstEntryNum >= 0 && fullKeyEntries[firstEntryNum].Object.SamplingNumber <= lastEntry.SamplingNumber; firstEntryNum--) ; + for (firstEntryNum = fullKeyEntries.Length - 1; + firstEntryNum >= 0 && fullKeyEntries[firstEntryNum].Object.SamplingNumber <= lastEntry.SamplingNumber; + firstEntryNum--) + { + } if (firstEntryNum == -1) { diff --git a/src/Ryujinx.HLE/Ui/KeyPressedHandler.cs b/src/Ryujinx.HLE/Ui/KeyPressedHandler.cs index 096bf7314..31e754377 100644 --- a/src/Ryujinx.HLE/Ui/KeyPressedHandler.cs +++ b/src/Ryujinx.HLE/Ui/KeyPressedHandler.cs @@ -3,4 +3,4 @@ using Ryujinx.Common.Configuration.Hid; namespace Ryujinx.HLE.Ui { public delegate bool KeyPressedHandler(Key key); -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Ui/KeyReleasedHandler.cs b/src/Ryujinx.HLE/Ui/KeyReleasedHandler.cs index 4faaa529c..d5b6d2019 100644 --- a/src/Ryujinx.HLE/Ui/KeyReleasedHandler.cs +++ b/src/Ryujinx.HLE/Ui/KeyReleasedHandler.cs @@ -3,4 +3,4 @@ using Ryujinx.Common.Configuration.Hid; namespace Ryujinx.HLE.Ui { public delegate bool KeyReleasedHandler(Key key); -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Ui/RenderingSurfaceInfo.cs b/src/Ryujinx.HLE/Ui/RenderingSurfaceInfo.cs index 0ba116add..10da74ef3 100644 --- a/src/Ryujinx.HLE/Ui/RenderingSurfaceInfo.cs +++ b/src/Ryujinx.HLE/Ui/RenderingSurfaceInfo.cs @@ -26,10 +26,20 @@ namespace Ryujinx.HLE.Ui public bool Equals(RenderingSurfaceInfo other) { return ColorFormat == other.ColorFormat && - Width == other.Width && - Height == other.Height && - Pitch == other.Pitch && - Size == other.Size; + Width == other.Width && + Height == other.Height && + Pitch == other.Pitch && + Size == other.Size; + } + + public override bool Equals(object obj) + { + return obj is RenderingSurfaceInfo info && Equals(info); + } + + public override int GetHashCode() + { + return BitConverter.ToInt32(BitConverter.GetBytes(((ulong)ColorFormat) ^ Width ^ Height ^ Pitch ^ Size)); } } } diff --git a/src/Ryujinx.HLE/Utilities/StringUtils.cs b/src/Ryujinx.HLE/Utilities/StringUtils.cs index 1810b1ad7..9b3479eec 100644 --- a/src/Ryujinx.HLE/Utilities/StringUtils.cs +++ b/src/Ryujinx.HLE/Utilities/StringUtils.cs @@ -77,30 +77,28 @@ namespace Ryujinx.HLE.Utilities public static string ReadUtf8String(ServiceCtx context, int index = 0) { ulong position = context.Request.PtrBuff[index].Position; - ulong size = context.Request.PtrBuff[index].Size; + ulong size = context.Request.PtrBuff[index].Size; - using (RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream()) + using RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream(); + while (size-- > 0) { - while (size-- > 0) + byte value = context.Memory.Read(position++); + + if (value == 0) { - byte value = context.Memory.Read(position++); - - if (value == 0) - { - break; - } - - ms.WriteByte(value); + break; } - return Encoding.UTF8.GetString(ms.GetReadOnlySequence()); + ms.WriteByte(value); } + + return Encoding.UTF8.GetString(ms.GetReadOnlySequence()); } public static U8Span ReadUtf8Span(ServiceCtx context, int index = 0) { ulong position = context.Request.PtrBuff[index].Position; - ulong size = context.Request.PtrBuff[index].Size; + ulong size = context.Request.PtrBuff[index].Size; ReadOnlySpan buffer = context.Memory.GetSpan(position, (int)size); @@ -110,24 +108,23 @@ namespace Ryujinx.HLE.Utilities public static string ReadUtf8StringSend(ServiceCtx context, int index = 0) { ulong position = context.Request.SendBuff[index].Position; - ulong size = context.Request.SendBuff[index].Size; + ulong size = context.Request.SendBuff[index].Size; - using (RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream()) + using RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream(); + + while (size-- > 0) { - while (size-- > 0) + byte value = context.Memory.Read(position++); + + if (value == 0) { - byte value = context.Memory.Read(position++); - - if (value == 0) - { - break; - } - - ms.WriteByte(value); + break; } - return Encoding.UTF8.GetString(ms.GetReadOnlySequence()); + ms.WriteByte(value); } + + return Encoding.UTF8.GetString(ms.GetReadOnlySequence()); } public static int CompareCStr(ReadOnlySpan s1, ReadOnlySpan s2) @@ -156,4 +153,4 @@ namespace Ryujinx.HLE.Utilities return i; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx/Ui/MainWindow.cs b/src/Ryujinx/Ui/MainWindow.cs index 7625e9e6f..a022b5535 100644 --- a/src/Ryujinx/Ui/MainWindow.cs +++ b/src/Ryujinx/Ui/MainWindow.cs @@ -891,7 +891,7 @@ namespace Ryujinx.Ui if (path.StartsWith("@SystemContent")) { - path = _virtualFileSystem.SwitchPathToSystemPath(path); + path = VirtualFileSystem.SwitchPathToSystemPath(path); isFirmwareTitle = true; } diff --git a/src/Ryujinx/Ui/Widgets/GameTableContextMenu.cs b/src/Ryujinx/Ui/Widgets/GameTableContextMenu.cs index 8170b9317..c2e0d8ebc 100644 --- a/src/Ryujinx/Ui/Widgets/GameTableContextMenu.cs +++ b/src/Ryujinx/Ui/Widgets/GameTableContextMenu.cs @@ -139,7 +139,7 @@ namespace Ryujinx.Ui.Widgets return; } - string saveRootPath = System.IO.Path.Combine(_virtualFileSystem.GetNandPath(), $"user/save/{saveDataId:x16}"); + string saveRootPath = System.IO.Path.Combine(VirtualFileSystem.GetNandPath(), $"user/save/{saveDataId:x16}"); if (!Directory.Exists(saveRootPath)) { diff --git a/src/Ryujinx/Ui/Windows/AvatarWindow.cs b/src/Ryujinx/Ui/Windows/AvatarWindow.cs index 3940f17d6..826b0e056 100644 --- a/src/Ryujinx/Ui/Windows/AvatarWindow.cs +++ b/src/Ryujinx/Ui/Windows/AvatarWindow.cs @@ -119,7 +119,7 @@ namespace Ryujinx.Ui.Windows } string contentPath = contentManager.GetInstalledContentPath(0x010000000000080A, StorageId.BuiltInSystem, NcaContentType.Data); - string avatarPath = virtualFileSystem.SwitchPathToSystemPath(contentPath); + string avatarPath = VirtualFileSystem.SwitchPathToSystemPath(contentPath); if (!string.IsNullOrWhiteSpace(avatarPath)) {