IIrSensorServer.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.Exceptions;
  3. using Ryujinx.HLE.HOS.Ipc;
  4. using Ryujinx.HLE.HOS.Kernel.Common;
  5. using Ryujinx.HLE.HOS.Kernel.Memory;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace Ryujinx.HLE.HOS.Services.Irs
  9. {
  10. class IIrSensorServer : IpcService
  11. {
  12. private Dictionary<int, ServiceProcessRequest> _commands;
  13. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  14. private KSharedMemory _irsSharedMem;
  15. public IIrSensorServer(KSharedMemory irsSharedMem)
  16. {
  17. _commands = new Dictionary<int, ServiceProcessRequest>
  18. {
  19. { 302, ActivateIrsensor },
  20. { 303, DeactivateIrsensor },
  21. { 304, GetIrsensorSharedMemoryHandle },
  22. { 311, GetNpadIrCameraHandle },
  23. { 319, ActivateIrsensorWithFunctionLevel }
  24. };
  25. _irsSharedMem = irsSharedMem;
  26. }
  27. // ActivateIrsensor(nn::applet::AppletResourceUserId, pid)
  28. public long ActivateIrsensor(ServiceCtx context)
  29. {
  30. long appletResourceUserId = context.RequestData.ReadInt64();
  31. Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
  32. return 0;
  33. }
  34. // DeactivateIrsensor(nn::applet::AppletResourceUserId, pid)
  35. public long DeactivateIrsensor(ServiceCtx context)
  36. {
  37. long appletResourceUserId = context.RequestData.ReadInt64();
  38. Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
  39. return 0;
  40. }
  41. // GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle<copy>
  42. public long GetIrsensorSharedMemoryHandle(ServiceCtx context)
  43. {
  44. var handleTable = context.Process.HandleTable;
  45. if (handleTable.GenerateHandle(_irsSharedMem, out int handle) != KernelResult.Success)
  46. {
  47. throw new InvalidOperationException("Out of handles!");
  48. }
  49. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  50. return 0;
  51. }
  52. // GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
  53. public long GetNpadIrCameraHandle(ServiceCtx context)
  54. {
  55. uint npadId = context.RequestData.ReadUInt32();
  56. if (npadId >= 8 && npadId != 16 && npadId != 32)
  57. {
  58. return ErrorCode.MakeError(ErrorModule.Hid, 0x2c5);
  59. }
  60. if (((1 << (int)npadId) & 0x1000100FF) == 0)
  61. {
  62. return ErrorCode.MakeError(ErrorModule.Hid, 0x2c5);
  63. }
  64. int npadTypeId = GetNpadTypeId(npadId);
  65. context.ResponseData.Write(npadTypeId);
  66. return 0;
  67. }
  68. private int GetNpadTypeId(uint npadId)
  69. {
  70. switch(npadId)
  71. {
  72. case 0: return 0;
  73. case 1: return 1;
  74. case 2: return 2;
  75. case 3: return 3;
  76. case 4: return 4;
  77. case 5: return 5;
  78. case 6: return 6;
  79. case 7: return 7;
  80. case 32: return 8;
  81. case 16: return 9;
  82. default: throw new ArgumentOutOfRangeException(nameof(npadId));
  83. }
  84. }
  85. // ActivateIrsensorWithFunctionLevel(nn::applet::AppletResourceUserId, nn::irsensor::PackedFunctionLevel, pid)
  86. public long ActivateIrsensorWithFunctionLevel(ServiceCtx context)
  87. {
  88. long appletResourceUserId = context.RequestData.ReadInt64();
  89. long packedFunctionLevel = context.RequestData.ReadInt64();
  90. Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, packedFunctionLevel });
  91. return 0;
  92. }
  93. }
  94. }