IIrSensorServer.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. };
  24. _irsSharedMem = irsSharedMem;
  25. }
  26. // ActivateIrsensor(nn::applet::AppletResourceUserId, pid)
  27. public long ActivateIrsensor(ServiceCtx context)
  28. {
  29. long appletResourceUserId = context.RequestData.ReadInt64();
  30. Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
  31. return 0;
  32. }
  33. // DeactivateIrsensor(nn::applet::AppletResourceUserId, pid)
  34. public long DeactivateIrsensor(ServiceCtx context)
  35. {
  36. long appletResourceUserId = context.RequestData.ReadInt64();
  37. Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
  38. return 0;
  39. }
  40. // GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle<copy>
  41. public long GetIrsensorSharedMemoryHandle(ServiceCtx context)
  42. {
  43. var handleTable = context.Process.HandleTable;
  44. if (handleTable.GenerateHandle(_irsSharedMem, out int handle) != KernelResult.Success)
  45. {
  46. throw new InvalidOperationException("Out of handles!");
  47. }
  48. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  49. return 0;
  50. }
  51. // GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
  52. public long GetNpadIrCameraHandle(ServiceCtx context)
  53. {
  54. uint npadId = context.RequestData.ReadUInt32();
  55. if (npadId >= 8 && npadId != 16 && npadId != 32)
  56. {
  57. return ErrorCode.MakeError(ErrorModule.Hid, 0x2c5);
  58. }
  59. if (((1 << (int)npadId) & 0x1000100FF) == 0)
  60. {
  61. return ErrorCode.MakeError(ErrorModule.Hid, 0x2c5);
  62. }
  63. int npadTypeId = GetNpadTypeId(npadId);
  64. context.ResponseData.Write(npadTypeId);
  65. return 0;
  66. }
  67. private int GetNpadTypeId(uint npadId)
  68. {
  69. switch(npadId)
  70. {
  71. case 0: return 0;
  72. case 1: return 1;
  73. case 2: return 2;
  74. case 3: return 3;
  75. case 4: return 4;
  76. case 5: return 5;
  77. case 6: return 6;
  78. case 7: return 7;
  79. case 32: return 8;
  80. case 16: return 9;
  81. default: throw new ArgumentOutOfRangeException(nameof(npadId));
  82. }
  83. }
  84. }
  85. }