2018-10-17 19:15:50 +02:00
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2019-04-20 04:23:13 +02:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
2019-09-19 02:45:11 +02:00
|
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.HidServer;
|
2019-04-20 03:56:55 +02:00
|
|
|
|
using System;
|
2018-10-07 17:12:11 +02:00
|
|
|
|
|
2019-06-27 18:02:41 +02:00
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Hid.Irs
|
2018-10-07 17:12:11 +02:00
|
|
|
|
{
|
2019-07-10 17:59:54 +02:00
|
|
|
|
[Service("irs")]
|
2018-10-07 17:12:11 +02:00
|
|
|
|
class IIrSensorServer : IpcService
|
|
|
|
|
{
|
2019-06-27 18:02:41 +02:00
|
|
|
|
private int _irsensorSharedMemoryHandle = 0;
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
public IIrSensorServer(ServiceCtx context) { }
|
2018-10-07 17:12:11 +02:00
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(302)]
|
2018-10-07 17:12:11 +02:00
|
|
|
|
// ActivateIrsensor(nn::applet::AppletResourceUserId, pid)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode ActivateIrsensor(ServiceCtx context)
|
2018-10-07 17:12:11 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
2018-10-07 17:12:11 +02:00
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
|
2018-10-07 17:12:11 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-10-07 17:12:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(303)]
|
2018-10-07 17:12:11 +02:00
|
|
|
|
// DeactivateIrsensor(nn::applet::AppletResourceUserId, pid)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode DeactivateIrsensor(ServiceCtx context)
|
2018-10-07 17:12:11 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
2018-10-07 17:12:11 +02:00
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
|
2018-10-07 17:12:11 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2018-10-07 17:12:11 +02:00
|
|
|
|
}
|
2019-04-20 03:56:55 +02:00
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(304)]
|
2019-04-20 04:23:13 +02:00
|
|
|
|
// GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle<copy>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetIrsensorSharedMemoryHandle(ServiceCtx context)
|
2019-04-20 04:23:13 +02:00
|
|
|
|
{
|
2019-06-27 18:02:41 +02:00
|
|
|
|
if (_irsensorSharedMemoryHandle == 0)
|
2019-04-20 04:23:13 +02:00
|
|
|
|
{
|
2019-06-27 18:02:41 +02:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(context.Device.System.IirsSharedMem, out _irsensorSharedMemoryHandle) != KernelResult.Success)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
2019-04-20 04:23:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 18:02:41 +02:00
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_irsensorSharedMemoryHandle);
|
2019-04-20 04:23:13 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-04-20 04:23:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(311)]
|
2019-04-20 03:56:55 +02:00
|
|
|
|
// GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetNpadIrCameraHandle(ServiceCtx context)
|
2019-04-20 03:56:55 +02:00
|
|
|
|
{
|
2020-04-03 02:10:02 +02:00
|
|
|
|
NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32();
|
2019-04-20 03:56:55 +02:00
|
|
|
|
|
2020-04-03 02:10:02 +02:00
|
|
|
|
if (npadIdType > NpadIdType.Player8 &&
|
|
|
|
|
npadIdType != NpadIdType.Unknown &&
|
|
|
|
|
npadIdType != NpadIdType.Handheld)
|
2019-04-20 03:56:55 +02:00
|
|
|
|
{
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.NpadIdOutOfRange;
|
2019-04-20 03:56:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-03 02:10:02 +02:00
|
|
|
|
PlayerIndex irCameraHandle = HidUtils.GetIndexFromNpadIdType(npadIdType);
|
2019-04-20 03:56:55 +02:00
|
|
|
|
|
2019-06-27 18:02:41 +02:00
|
|
|
|
context.ResponseData.Write((int)irCameraHandle);
|
2019-04-20 03:56:55 +02:00
|
|
|
|
|
2019-06-27 18:02:41 +02:00
|
|
|
|
// NOTE: If the irCameraHandle pointer is null this error is returned, Doesn't occur in our case.
|
2019-07-14 21:04:38 +02:00
|
|
|
|
// return ResultCode.HandlePointerIsNull;
|
2019-04-20 03:56:55 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-04-20 03:56:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(319)] // 4.0.0+
|
2019-04-25 15:03:00 +02:00
|
|
|
|
// ActivateIrsensorWithFunctionLevel(nn::applet::AppletResourceUserId, nn::irsensor::PackedFunctionLevel, pid)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode ActivateIrsensorWithFunctionLevel(ServiceCtx context)
|
2019-04-25 15:03:00 +02:00
|
|
|
|
{
|
|
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
|
|
|
|
long packedFunctionLevel = context.RequestData.ReadInt64();
|
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, packedFunctionLevel });
|
2019-04-25 15:03:00 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-04-25 15:03:00 +02:00
|
|
|
|
}
|
2018-10-07 17:12:11 +02:00
|
|
|
|
}
|
|
|
|
|
}
|