From ba9aa61cc323f7482b172c7ce4d362e005aa6462 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sun, 10 Mar 2024 15:18:54 +0000 Subject: [PATCH] Implement most of Irs --- .../HOS/Services/Hid/Irs/IIrSensorServer.cs | 101 --------- .../Services/Hid/Irs/IIrSensorSystemServer.cs | 8 - src/Ryujinx.Horizon/Hid/HidIpcServer.cs | 47 ++++ src/Ryujinx.Horizon/Hid/HidMain.cs | 17 ++ src/Ryujinx.Horizon/Irs/IrSensorServer.cs | 203 ++++++++++++++++++ .../Irs/IrSensorSystemServer.cs | 43 ++++ src/Ryujinx.Horizon/Irs/IrsIpcServer.cs | 45 ++++ src/Ryujinx.Horizon/Irs/IrsMain.cs | 17 ++ .../Sdk/Irs/IIrSensorServer.cs | 30 +++ .../Sdk/Irs/IIrSensorSystemServer.cs | 14 ++ .../ImageTransferProcessorState.cs | 2 +- .../Sdk/{Irsensor => Irs}/IrCameraHandle.cs | 2 +- .../PackedClusteringProcessorConfig.cs | 2 +- .../{Irsensor => Irs}/PackedFunctionLevel.cs | 2 +- .../PackedImageTransferProcessorConfig.cs | 2 +- .../PackedImageTransferProcessorExConfig.cs | 2 +- .../PackedIrLedProcessorConfig.cs | 2 +- .../Sdk/{Irsensor => Irs}/PackedMcuVersion.cs | 2 +- .../PackedMomentProcessorConfig.cs | 2 +- .../PackedPointingProcessorConfig.cs | 2 +- .../PackedTeraPluginProcessorConfig.cs | 2 +- .../Sdk/Irsensor/IIrSensorServer.cs | 29 --- src/Ryujinx.Horizon/ServiceTable.cs | 4 + 23 files changed, 431 insertions(+), 149 deletions(-) delete mode 100644 src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorSystemServer.cs create mode 100644 src/Ryujinx.Horizon/Hid/HidIpcServer.cs create mode 100644 src/Ryujinx.Horizon/Hid/HidMain.cs create mode 100644 src/Ryujinx.Horizon/Irs/IrSensorServer.cs create mode 100644 src/Ryujinx.Horizon/Irs/IrSensorSystemServer.cs create mode 100644 src/Ryujinx.Horizon/Irs/IrsIpcServer.cs create mode 100644 src/Ryujinx.Horizon/Irs/IrsMain.cs create mode 100644 src/Ryujinx.Horizon/Sdk/Irs/IIrSensorServer.cs create mode 100644 src/Ryujinx.Horizon/Sdk/Irs/IIrSensorSystemServer.cs rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/ImageTransferProcessorState.cs (86%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/IrCameraHandle.cs (85%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/PackedClusteringProcessorConfig.cs (95%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/PackedFunctionLevel.cs (82%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/PackedImageTransferProcessorConfig.cs (92%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/PackedImageTransferProcessorExConfig.cs (93%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/PackedIrLedProcessorConfig.cs (85%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/PackedMcuVersion.cs (84%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/PackedMomentProcessorConfig.cs (94%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/PackedPointingProcessorConfig.cs (90%) rename src/Ryujinx.Horizon/Sdk/{Irsensor => Irs}/PackedTeraPluginProcessorConfig.cs (89%) delete mode 100644 src/Ryujinx.Horizon/Sdk/Irsensor/IIrSensorServer.cs diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs index ff0bb4401..fb0f4fb36 100644 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs @@ -15,32 +15,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs public IIrSensorServer(ServiceCtx context) { } - [CommandCmif(302)] - // ActivateIrsensor(nn::applet::AppletResourceUserId, pid) - public ResultCode ActivateIrsensor(ServiceCtx context) - { - ulong appletResourceUserId = context.RequestData.ReadUInt64(); - - // NOTE: This seems to initialize the shared memory for irs service. - - Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId }); - - return ResultCode.Success; - } - - [CommandCmif(303)] - // DeactivateIrsensor(nn::applet::AppletResourceUserId, pid) - public ResultCode DeactivateIrsensor(ServiceCtx context) - { - ulong appletResourceUserId = context.RequestData.ReadUInt64(); - - // NOTE: This seems to deinitialize the shared memory for irs service. - - Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId }); - - return ResultCode.Success; - } - [CommandCmif(304)] // GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle public ResultCode GetIrsensorSharedMemoryHandle(ServiceCtx context) @@ -61,67 +35,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs return ResultCode.Success; } - [CommandCmif(305)] - // StopImageProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId) - public ResultCode StopImageProcessor(ServiceCtx context) - { - IrCameraHandle irCameraHandle = context.RequestData.ReadStruct(); - ulong appletResourceUserId = context.RequestData.ReadUInt64(); - - CheckCameraHandle(irCameraHandle); - - Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType }); - - return ResultCode.Success; - } - - [CommandCmif(306)] - // 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(); - - CheckCameraHandle(irCameraHandle); - - Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, packedMomentProcessorConfig.ExposureTime }); - - return ResultCode.Success; - } - - [CommandCmif(307)] - // 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(); - - CheckCameraHandle(irCameraHandle); - - Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, packedClusteringProcessorConfig.ExposureTime }); - - return ResultCode.Success; - } - - [CommandCmif(308)] - // 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(); - - CheckCameraHandle(irCameraHandle); - - // TODO: Handle the Transfer Memory. - - Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, packedImageTransferProcessorConfig.ExposureTime }); - - return ResultCode.Success; - } - [CommandCmif(309)] // GetImageTransferProcessorState(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId) public ResultCode GetImageTransferProcessorState(ServiceCtx context) @@ -189,20 +102,6 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs return ResultCode.Success; } - [CommandCmif(314)] // 3.0.0+ - // CheckFirmwareVersion(nn::irsensor::IrCameraHandle, nn::irsensor::PackedMcuVersion, nn::applet::AppletResourceUserId, pid) - public ResultCode CheckFirmwareVersion(ServiceCtx context) - { - int irCameraHandle = context.RequestData.ReadInt32(); - short packedMcuVersionMajor = context.RequestData.ReadInt16(); - short packedMcuVersionMinor = context.RequestData.ReadInt16(); - long appletResourceUserId = context.RequestData.ReadInt64(); - - Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle, packedMcuVersionMajor, packedMcuVersionMinor }); - - return ResultCode.Success; - } - [CommandCmif(318)] // 4.0.0+ // StopImageProcessorAsync(nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, pid) public ResultCode StopImageProcessorAsync(ServiceCtx context) diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorSystemServer.cs b/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorSystemServer.cs deleted file mode 100644 index 5046268cb..000000000 --- a/src/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorSystemServer.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Ryujinx.HLE.HOS.Services.Hid.Irs -{ - [Service("irs:sys")] - class IIrSensorSystemServer : IpcService - { - public IIrSensorSystemServer(ServiceCtx context) { } - } -} diff --git a/src/Ryujinx.Horizon/Hid/HidIpcServer.cs b/src/Ryujinx.Horizon/Hid/HidIpcServer.cs new file mode 100644 index 000000000..84c85b3d7 --- /dev/null +++ b/src/Ryujinx.Horizon/Hid/HidIpcServer.cs @@ -0,0 +1,47 @@ +using Ryujinx.Horizon.Sdk.Sf.Hipc; +using Ryujinx.Horizon.Sdk.Sm; + +namespace Ryujinx.Horizon.Hid +{ + class HidIpcServer + { + // TODO: RE These values + private const int MaxSessionsCount = 30; + + private const int PointerBufferSize = 0xB40; + private const int MaxDomains = 0; + private const int MaxDomainObjects = 0; + private const int MaxPortsCount = 1; + + private static readonly ManagerOptions _options = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false); + + private SmApi _sm; + private ServerManager _serverManager; + + public void Initialize() + { + HeapAllocator allocator = new(); + + _sm = new SmApi(); + _sm.Initialize().AbortOnFailure(); + + _serverManager = new ServerManager(allocator, _sm, MaxPortsCount, _options, MaxSessionsCount); + + // _serverManager.RegisterObjectForServer(, ServiceName.Encode("hid"), MaxSessionsCount); + // _serverManager.RegisterObjectForServer(, ServiceName.Encode("hidbus"), MaxSessionsCount); + // _serverManager.RegisterObjectForServer(, ServiceName.Encode("hid:sys"), MaxSessionsCount); + // _serverManager.RegisterObjectForServer(, ServiceName.Encode("hid:dbg"), MaxSessionsCount); + } + + public void ServiceRequests() + { + _serverManager.ServiceRequests(); + } + + public void Shutdown() + { + _serverManager.Dispose(); + _sm.Dispose(); + } + } +} diff --git a/src/Ryujinx.Horizon/Hid/HidMain.cs b/src/Ryujinx.Horizon/Hid/HidMain.cs new file mode 100644 index 000000000..42fe0523b --- /dev/null +++ b/src/Ryujinx.Horizon/Hid/HidMain.cs @@ -0,0 +1,17 @@ +namespace Ryujinx.Horizon.Hid +{ + class HidMain : IService + { + public static void Main(ServiceTable serviceTable) + { + HidIpcServer ipcServer = new(); + + ipcServer.Initialize(); + + serviceTable.SignalServiceReady(); + + ipcServer.ServiceRequests(); + ipcServer.Shutdown(); + } + } +} diff --git a/src/Ryujinx.Horizon/Irs/IrSensorServer.cs b/src/Ryujinx.Horizon/Irs/IrSensorServer.cs new file mode 100644 index 000000000..a7baf1c54 --- /dev/null +++ b/src/Ryujinx.Horizon/Irs/IrSensorServer.cs @@ -0,0 +1,203 @@ +using Ryujinx.Common.Logging; +using Ryujinx.Horizon.Common; +using Ryujinx.Horizon.Sdk.Applet; +using Ryujinx.Horizon.Sdk.Hid.Npad; +using Ryujinx.Horizon.Sdk.Irs; +using Ryujinx.Horizon.Sdk.Sf; +using Ryujinx.Horizon.Sdk.Sf.Hipc; +using System; + +namespace Ryujinx.Horizon.Irs +{ + class IrSensorServer : IIrSensorServer + { + [CmifCommand(302)] + public Result ActivateIrsensor(AppletResourceUserId appletResourceUserId, [ClientProcessId] ulong pid) + { + // NOTE: This seems to initialize the shared memory for irs service. + + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id }); + + return Result.Success; + } + + [CmifCommand(303)] + public Result DeactivateIrsensor(AppletResourceUserId appletResourceUserId, [ClientProcessId] ulong pid) + { + // NOTE: This seems to deinitialize the shared memory for irs service. + + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id }); + + return Result.Success; + } + + [CmifCommand(304)] + public Result GetIrsensorSharedMemoryHandle([CopyHandle] out int arg0, AppletResourceUserId appletResourceUserId, [ClientProcessId] ulong pid) + { + // NOTE: Shared memory should use the appletResourceUserId. + + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(305)] + public Result StopImageProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType }); + + return Result.Success; + } + + [CmifCommand(306)] + public Result RunMomentProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedMomentProcessorConfig config, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, config.ExposureTime }); + + return Result.Success; + } + + [CmifCommand(307)] + public Result RunClusteringProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedClusteringProcessorConfig config, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, config.ExposureTime }); + + return Result.Success; + } + + [CmifCommand(308)] + public Result RunImageTransferProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedImageTransferProcessorConfig config, [CopyHandle] int arg3, ulong arg4, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + // TODO: Handle the Transfer Memory. + + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, config.ExposureTime }); + + return Result.Success; + } + + [CmifCommand(309)] + public Result GetImageTransferProcessorState(AppletResourceUserId appletResourceUserId, out ImageTransferProcessorState arg1, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span arg2, IrCameraHandle irCameraHandle, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(310)] + public Result RunTeraPluginProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedTeraPluginProcessorConfig config, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(311)] + public Result GetNpadIrCameraHandle(out IrCameraHandle irCameraHandle, NpadIdType npadIdType) + { + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(312)] + public Result RunPointingProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedPointingProcessorConfig config, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(313)] + public Result SuspendImageProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(314)] + public Result CheckFirmwareVersion(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedMcuVersion mcuVersion, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, mcuVersion.MajorVersion, mcuVersion.MinorVersion }); + + return Result.Success; + } + + [CmifCommand(315)] + public Result SetFunctionLevel(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedFunctionLevel functionLevel, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(316)] + public Result RunImageTransferExProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedImageTransferProcessorExConfig config, int arg3, ulong arg4, ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(317)] + public Result RunIrLedProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedIrLedProcessorConfig config, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(318)] + public Result StopImageProcessorAsync(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, [ClientProcessId] ulong pid) + { + CheckCameraHandle(irCameraHandle); + + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + [CmifCommand(319)] + public Result ActivateIrsensorWithFunctionLevel(AppletResourceUserId appletResourceUserId, PackedFunctionLevel arg1, [ClientProcessId] ulong pid) + { + Logger.Stub?.PrintStub(LogClass.ServiceIrs); + + return Result.Success; + } + + private Result CheckCameraHandle(IrCameraHandle irCameraHandle) + { + if (irCameraHandle.DeviceType == 1 || (PlayerIndex)irCameraHandle.PlayerNumber >= PlayerIndex.Unknown) + { + // InvalidCameraHandle + return new Result(204); + } + + return Result.Success; + } + } +} diff --git a/src/Ryujinx.Horizon/Irs/IrSensorSystemServer.cs b/src/Ryujinx.Horizon/Irs/IrSensorSystemServer.cs new file mode 100644 index 000000000..f774ff5f9 --- /dev/null +++ b/src/Ryujinx.Horizon/Irs/IrSensorSystemServer.cs @@ -0,0 +1,43 @@ +using Ryujinx.Common.Logging; +using Ryujinx.Horizon.Common; +using Ryujinx.Horizon.Sdk.Applet; +using Ryujinx.Horizon.Sdk.Irs; +using Ryujinx.Horizon.Sdk.Sf; + +namespace Ryujinx.Horizon.Irs +{ + class IrSensorSystemServer : IIrSensorSystemServer + { + [CmifCommand(500)] + public Result SetAppletResourceUserId(AppletResourceUserId appletResourceUserId) + { + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id }); + + return Result.Success; + } + + [CmifCommand(501)] + public Result RegisterAppletResourceUserId(AppletResourceUserId appletResourceUserId, bool arg1) + { + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id, arg1 }); + + return Result.Success; + } + + [CmifCommand(502)] + public Result UnregisterAppletResourceUserId(AppletResourceUserId appletResourceUserId) + { + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id }); + + return Result.Success; + } + + [CmifCommand(503)] + public Result EnableAppletToGetInput(AppletResourceUserId appletResourceUserId, bool arg1) + { + Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId.Id, arg1 }); + + return Result.Success; + } + } +} diff --git a/src/Ryujinx.Horizon/Irs/IrsIpcServer.cs b/src/Ryujinx.Horizon/Irs/IrsIpcServer.cs new file mode 100644 index 000000000..ae6626423 --- /dev/null +++ b/src/Ryujinx.Horizon/Irs/IrsIpcServer.cs @@ -0,0 +1,45 @@ +using Ryujinx.Horizon.Sdk.Sf.Hipc; +using Ryujinx.Horizon.Sdk.Sm; + +namespace Ryujinx.Horizon.Irs +{ + class IrsIpcServer + { + // TODO: RE These values + private const int MaxSessionsCount = 30; + + private const int PointerBufferSize = 0xB40; + private const int MaxDomains = 0; + private const int MaxDomainObjects = 0; + private const int MaxPortsCount = 1; + + private static readonly ManagerOptions _options = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false); + + private SmApi _sm; + private ServerManager _serverManager; + + public void Initialize() + { + HeapAllocator allocator = new(); + + _sm = new SmApi(); + _sm.Initialize().AbortOnFailure(); + + _serverManager = new ServerManager(allocator, _sm, MaxPortsCount, _options, MaxSessionsCount); + + _serverManager.RegisterObjectForServer(new IrSensorServer(), ServiceName.Encode("irs"), MaxSessionsCount); + _serverManager.RegisterObjectForServer(new IrSensorSystemServer(), ServiceName.Encode("irs:sys"), MaxSessionsCount); + } + + public void ServiceRequests() + { + _serverManager.ServiceRequests(); + } + + public void Shutdown() + { + _serverManager.Dispose(); + _sm.Dispose(); + } + } +} diff --git a/src/Ryujinx.Horizon/Irs/IrsMain.cs b/src/Ryujinx.Horizon/Irs/IrsMain.cs new file mode 100644 index 000000000..6f8652e9a --- /dev/null +++ b/src/Ryujinx.Horizon/Irs/IrsMain.cs @@ -0,0 +1,17 @@ +namespace Ryujinx.Horizon.Irs +{ + class IrsMain : IService + { + public static void Main(ServiceTable serviceTable) + { + IrsIpcServer ipcServer = new(); + + ipcServer.Initialize(); + + serviceTable.SignalServiceReady(); + + ipcServer.ServiceRequests(); + ipcServer.Shutdown(); + } + } +} diff --git a/src/Ryujinx.Horizon/Sdk/Irs/IIrSensorServer.cs b/src/Ryujinx.Horizon/Sdk/Irs/IIrSensorServer.cs new file mode 100644 index 000000000..0929f1a3c --- /dev/null +++ b/src/Ryujinx.Horizon/Sdk/Irs/IIrSensorServer.cs @@ -0,0 +1,30 @@ +using Ryujinx.Horizon.Common; +using Ryujinx.Horizon.Sdk.Applet; +using Ryujinx.Horizon.Sdk.Hid.Npad; +using Ryujinx.Horizon.Sdk.Sf; +using System; + +namespace Ryujinx.Horizon.Sdk.Irs +{ + interface IIrSensorServer : IServiceObject + { + Result ActivateIrsensor(AppletResourceUserId appletResourceUserId, ulong pid); + Result DeactivateIrsensor(AppletResourceUserId appletResourceUserId, ulong pid); + Result GetIrsensorSharedMemoryHandle(out int arg0, AppletResourceUserId appletResourceUserId, ulong pid); + Result StopImageProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, ulong pid); + Result RunMomentProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedMomentProcessorConfig config, ulong pid); + Result RunClusteringProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedClusteringProcessorConfig config, ulong pid); + Result RunImageTransferProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedImageTransferProcessorConfig config, int arg3, ulong arg4, ulong pid); + Result GetImageTransferProcessorState(AppletResourceUserId appletResourceUserId, out ImageTransferProcessorState arg1, Span arg2, IrCameraHandle irCameraHandle, ulong pid); + Result RunTeraPluginProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedTeraPluginProcessorConfig config, ulong pid); + Result GetNpadIrCameraHandle(out IrCameraHandle irCameraHandle, NpadIdType npadIdType); + Result RunPointingProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedPointingProcessorConfig config, ulong pid); + Result SuspendImageProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, ulong pid); + Result CheckFirmwareVersion(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedMcuVersion mcuVersion, ulong pid); + Result SetFunctionLevel(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedFunctionLevel functionLevel, ulong pid); + Result RunImageTransferExProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedImageTransferProcessorExConfig config, int arg3, ulong arg4, ulong pid); + Result RunIrLedProcessor(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, PackedIrLedProcessorConfig config, ulong pid); + Result StopImageProcessorAsync(AppletResourceUserId appletResourceUserId, IrCameraHandle irCameraHandle, ulong pid); + Result ActivateIrsensorWithFunctionLevel(AppletResourceUserId appletResourceUserId, PackedFunctionLevel arg1, ulong pid); + } +} diff --git a/src/Ryujinx.Horizon/Sdk/Irs/IIrSensorSystemServer.cs b/src/Ryujinx.Horizon/Sdk/Irs/IIrSensorSystemServer.cs new file mode 100644 index 000000000..5736d975a --- /dev/null +++ b/src/Ryujinx.Horizon/Sdk/Irs/IIrSensorSystemServer.cs @@ -0,0 +1,14 @@ +using Ryujinx.Horizon.Common; +using Ryujinx.Horizon.Sdk.Applet; +using Ryujinx.Horizon.Sdk.Sf; + +namespace Ryujinx.Horizon.Sdk.Irs +{ + interface IIrSensorSystemServer : IServiceObject + { + Result SetAppletResourceUserId(AppletResourceUserId appletResourceUserId); + Result RegisterAppletResourceUserId(AppletResourceUserId appletResourceUserId, bool arg1); + Result UnregisterAppletResourceUserId(AppletResourceUserId appletResourceUserId); + Result EnableAppletToGetInput(AppletResourceUserId appletResourceUserId, bool arg1); + } +} diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/ImageTransferProcessorState.cs b/src/Ryujinx.Horizon/Sdk/Irs/ImageTransferProcessorState.cs similarity index 86% rename from src/Ryujinx.Horizon/Sdk/Irsensor/ImageTransferProcessorState.cs rename to src/Ryujinx.Horizon/Sdk/Irs/ImageTransferProcessorState.cs index 1084d9a3c..6a3a0d587 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/ImageTransferProcessorState.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/ImageTransferProcessorState.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x10)] struct ImageTransferProcessorState diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/IrCameraHandle.cs b/src/Ryujinx.Horizon/Sdk/Irs/IrCameraHandle.cs similarity index 85% rename from src/Ryujinx.Horizon/Sdk/Irsensor/IrCameraHandle.cs rename to src/Ryujinx.Horizon/Sdk/Irs/IrCameraHandle.cs index d04105d57..e58a59200 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/IrCameraHandle.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/IrCameraHandle.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x4)] struct IrCameraHandle diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedClusteringProcessorConfig.cs b/src/Ryujinx.Horizon/Sdk/Irs/PackedClusteringProcessorConfig.cs similarity index 95% rename from src/Ryujinx.Horizon/Sdk/Irsensor/PackedClusteringProcessorConfig.cs rename to src/Ryujinx.Horizon/Sdk/Irs/PackedClusteringProcessorConfig.cs index aa469bf4c..5279a6c26 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedClusteringProcessorConfig.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/PackedClusteringProcessorConfig.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x28)] struct PackedClusteringProcessorConfig diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedFunctionLevel.cs b/src/Ryujinx.Horizon/Sdk/Irs/PackedFunctionLevel.cs similarity index 82% rename from src/Ryujinx.Horizon/Sdk/Irsensor/PackedFunctionLevel.cs rename to src/Ryujinx.Horizon/Sdk/Irs/PackedFunctionLevel.cs index b1c01483c..25dfee9ae 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedFunctionLevel.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/PackedFunctionLevel.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x4)] struct PackedFunctionLevel diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedImageTransferProcessorConfig.cs b/src/Ryujinx.Horizon/Sdk/Irs/PackedImageTransferProcessorConfig.cs similarity index 92% rename from src/Ryujinx.Horizon/Sdk/Irsensor/PackedImageTransferProcessorConfig.cs rename to src/Ryujinx.Horizon/Sdk/Irs/PackedImageTransferProcessorConfig.cs index 796a4bcba..3a02354ae 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedImageTransferProcessorConfig.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/PackedImageTransferProcessorConfig.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x18)] struct PackedImageTransferProcessorConfig diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedImageTransferProcessorExConfig.cs b/src/Ryujinx.Horizon/Sdk/Irs/PackedImageTransferProcessorExConfig.cs similarity index 93% rename from src/Ryujinx.Horizon/Sdk/Irsensor/PackedImageTransferProcessorExConfig.cs rename to src/Ryujinx.Horizon/Sdk/Irs/PackedImageTransferProcessorExConfig.cs index c3d420e73..5d29fe8c3 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedImageTransferProcessorExConfig.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/PackedImageTransferProcessorExConfig.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x20)] struct PackedImageTransferProcessorExConfig diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedIrLedProcessorConfig.cs b/src/Ryujinx.Horizon/Sdk/Irs/PackedIrLedProcessorConfig.cs similarity index 85% rename from src/Ryujinx.Horizon/Sdk/Irsensor/PackedIrLedProcessorConfig.cs rename to src/Ryujinx.Horizon/Sdk/Irs/PackedIrLedProcessorConfig.cs index 2f081f329..2f05f46db 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedIrLedProcessorConfig.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/PackedIrLedProcessorConfig.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x8)] struct PackedIrLedProcessorConfig diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedMcuVersion.cs b/src/Ryujinx.Horizon/Sdk/Irs/PackedMcuVersion.cs similarity index 84% rename from src/Ryujinx.Horizon/Sdk/Irsensor/PackedMcuVersion.cs rename to src/Ryujinx.Horizon/Sdk/Irs/PackedMcuVersion.cs index 1bd198528..fb4480cd3 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedMcuVersion.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/PackedMcuVersion.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x4)] public struct PackedMcuVersion diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedMomentProcessorConfig.cs b/src/Ryujinx.Horizon/Sdk/Irs/PackedMomentProcessorConfig.cs similarity index 94% rename from src/Ryujinx.Horizon/Sdk/Irsensor/PackedMomentProcessorConfig.cs rename to src/Ryujinx.Horizon/Sdk/Irs/PackedMomentProcessorConfig.cs index 408a4adbd..62b195e12 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedMomentProcessorConfig.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/PackedMomentProcessorConfig.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x20)] struct PackedMomentProcessorConfig diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedPointingProcessorConfig.cs b/src/Ryujinx.Horizon/Sdk/Irs/PackedPointingProcessorConfig.cs similarity index 90% rename from src/Ryujinx.Horizon/Sdk/Irsensor/PackedPointingProcessorConfig.cs rename to src/Ryujinx.Horizon/Sdk/Irs/PackedPointingProcessorConfig.cs index 71a09fb55..a7efd5cd2 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedPointingProcessorConfig.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/PackedPointingProcessorConfig.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x20)] struct PackedPointingProcessorConfig diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedTeraPluginProcessorConfig.cs b/src/Ryujinx.Horizon/Sdk/Irs/PackedTeraPluginProcessorConfig.cs similarity index 89% rename from src/Ryujinx.Horizon/Sdk/Irsensor/PackedTeraPluginProcessorConfig.cs rename to src/Ryujinx.Horizon/Sdk/Irs/PackedTeraPluginProcessorConfig.cs index 20170cd31..34b575d98 100644 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/PackedTeraPluginProcessorConfig.cs +++ b/src/Ryujinx.Horizon/Sdk/Irs/PackedTeraPluginProcessorConfig.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace Ryujinx.Horizon.Sdk.Irsensor +namespace Ryujinx.Horizon.Sdk.Irs { [StructLayout(LayoutKind.Sequential, Size = 0x8)] struct PackedTeraPluginProcessorConfig diff --git a/src/Ryujinx.Horizon/Sdk/Irsensor/IIrSensorServer.cs b/src/Ryujinx.Horizon/Sdk/Irsensor/IIrSensorServer.cs deleted file mode 100644 index e27bedb71..000000000 --- a/src/Ryujinx.Horizon/Sdk/Irsensor/IIrSensorServer.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Ryujinx.Horizon.Common; -using Ryujinx.Horizon.Sdk.Applet; -using Ryujinx.Horizon.Sdk.Sf; -using System; - -namespace Ryujinx.Horizon.Sdk.Irsensor -{ - interface IIrSensorServer : IServiceObject - { - Result ActivateIrsensor(AppletResourceUserId arg0, ulong pid); - Result DeactivateIrsensor(AppletResourceUserId arg0, ulong pid); - Result GetIrsensorSharedMemoryHandle(out int arg0, AppletResourceUserId arg1, ulong pid); - Result StopImageProcessor(AppletResourceUserId arg0, IrCameraHandle arg1, ulong pid); - Result RunMomentProcessor(AppletResourceUserId arg0, IrCameraHandle arg1, PackedMomentProcessorConfig arg2, ulong pid); - Result RunClusteringProcessor(AppletResourceUserId arg0, IrCameraHandle arg1, PackedClusteringProcessorConfig arg2, ulong pid); - Result RunImageTransferProcessor(AppletResourceUserId arg0, IrCameraHandle arg1, PackedImageTransferProcessorConfig arg2, int arg3, ulong arg4, ulong pid); - Result GetImageTransferProcessorState(AppletResourceUserId arg0, out ImageTransferProcessorState arg1, Span arg2, IrCameraHandle arg3, ulong pid); - Result RunTeraPluginProcessor(AppletResourceUserId arg0, IrCameraHandle arg1, PackedTeraPluginProcessorConfig arg2, ulong pid); - Result GetNpadIrCameraHandle(out IrCameraHandle arg0, uint arg1); - Result RunPointingProcessor(AppletResourceUserId arg0, IrCameraHandle arg1, PackedPointingProcessorConfig arg2, ulong pid); - Result SuspendImageProcessor(AppletResourceUserId arg0, IrCameraHandle arg1, ulong pid); - Result CheckFirmwareVersion(AppletResourceUserId arg0, IrCameraHandle arg1, PackedMcuVersion arg2, ulong pid); - Result SetFunctionLevel(AppletResourceUserId arg0, IrCameraHandle arg1, PackedFunctionLevel arg2, ulong pid); - Result RunImageTransferExProcessor(AppletResourceUserId arg0, IrCameraHandle arg1, PackedImageTransferProcessorExConfig arg2, int arg3, ulong arg4, ulong pid); - Result RunIrLedProcessor(AppletResourceUserId arg0, IrCameraHandle arg1, PackedIrLedProcessorConfig arg2, ulong pid); - Result StopImageProcessorAsync(AppletResourceUserId arg0, IrCameraHandle arg1, ulong pid); - Result ActivateIrsensorWithFunctionLevel(AppletResourceUserId arg0, PackedFunctionLevel arg1, ulong pid); - } -} diff --git a/src/Ryujinx.Horizon/ServiceTable.cs b/src/Ryujinx.Horizon/ServiceTable.cs index 28c43a716..2e6ebb3fc 100644 --- a/src/Ryujinx.Horizon/ServiceTable.cs +++ b/src/Ryujinx.Horizon/ServiceTable.cs @@ -2,8 +2,10 @@ using Ryujinx.Horizon.Arp; using Ryujinx.Horizon.Audio; using Ryujinx.Horizon.Bcat; using Ryujinx.Horizon.Friends; +using Ryujinx.Horizon.Hid; using Ryujinx.Horizon.Hshl; using Ryujinx.Horizon.Ins; +using Ryujinx.Horizon.Irs; using Ryujinx.Horizon.Lbl; using Ryujinx.Horizon.LogManager; using Ryujinx.Horizon.MmNv; @@ -58,6 +60,8 @@ namespace Ryujinx.Horizon RegisterService(); RegisterService(); RegisterService(); + RegisterService(); + RegisterService(); _totalServices = entries.Count;