ISelfController.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Ryujinx.HLE.HOS.Services.Am
  7. {
  8. class ISelfController : IpcService
  9. {
  10. private Dictionary<int, ServiceProcessRequest> _commands;
  11. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  12. private KEvent _launchableEvent;
  13. private int _idleTimeDetectionExtension;
  14. public ISelfController(Horizon system)
  15. {
  16. _commands = new Dictionary<int, ServiceProcessRequest>
  17. {
  18. { 0, Exit },
  19. { 1, LockExit },
  20. { 2, UnlockExit },
  21. { 9, GetLibraryAppletLaunchableEvent },
  22. { 10, SetScreenShotPermission },
  23. { 11, SetOperationModeChangedNotification },
  24. { 12, SetPerformanceModeChangedNotification },
  25. { 13, SetFocusHandlingMode },
  26. { 14, SetRestartMessageEnabled },
  27. { 16, SetOutOfFocusSuspendingEnabled },
  28. { 19, SetScreenShotImageOrientation },
  29. { 50, SetHandlesRequestToDisplay },
  30. { 62, SetIdleTimeDetectionExtension },
  31. { 63, GetIdleTimeDetectionExtension }
  32. };
  33. _launchableEvent = new KEvent(system);
  34. }
  35. public long Exit(ServiceCtx context)
  36. {
  37. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  38. return 0;
  39. }
  40. public long LockExit(ServiceCtx context)
  41. {
  42. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  43. return 0;
  44. }
  45. public long UnlockExit(ServiceCtx context)
  46. {
  47. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  48. return 0;
  49. }
  50. public long GetLibraryAppletLaunchableEvent(ServiceCtx context)
  51. {
  52. _launchableEvent.ReadableEvent.Signal();
  53. if (context.Process.HandleTable.GenerateHandle(_launchableEvent.ReadableEvent, out int handle) != KernelResult.Success)
  54. {
  55. throw new InvalidOperationException("Out of handles!");
  56. }
  57. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  58. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  59. return 0;
  60. }
  61. public long SetScreenShotPermission(ServiceCtx context)
  62. {
  63. bool enable = context.RequestData.ReadByte() != 0;
  64. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  65. return 0;
  66. }
  67. public long SetOperationModeChangedNotification(ServiceCtx context)
  68. {
  69. bool enable = context.RequestData.ReadByte() != 0;
  70. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  71. return 0;
  72. }
  73. public long SetPerformanceModeChangedNotification(ServiceCtx context)
  74. {
  75. bool enable = context.RequestData.ReadByte() != 0;
  76. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  77. return 0;
  78. }
  79. public long SetFocusHandlingMode(ServiceCtx context)
  80. {
  81. bool flag1 = context.RequestData.ReadByte() != 0;
  82. bool flag2 = context.RequestData.ReadByte() != 0;
  83. bool flag3 = context.RequestData.ReadByte() != 0;
  84. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  85. return 0;
  86. }
  87. public long SetRestartMessageEnabled(ServiceCtx context)
  88. {
  89. bool enable = context.RequestData.ReadByte() != 0;
  90. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  91. return 0;
  92. }
  93. public long SetOutOfFocusSuspendingEnabled(ServiceCtx context)
  94. {
  95. bool enable = context.RequestData.ReadByte() != 0;
  96. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  97. return 0;
  98. }
  99. public long SetScreenShotImageOrientation(ServiceCtx context)
  100. {
  101. int orientation = context.RequestData.ReadInt32();
  102. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  103. return 0;
  104. }
  105. public long SetHandlesRequestToDisplay(ServiceCtx context)
  106. {
  107. bool enable = context.RequestData.ReadByte() != 0;
  108. Logger.PrintStub(LogClass.ServiceAm, "Stubbed.");
  109. return 0;
  110. }
  111. // SetIdleTimeDetectionExtension(u32)
  112. public long SetIdleTimeDetectionExtension(ServiceCtx context)
  113. {
  114. _idleTimeDetectionExtension = context.RequestData.ReadInt32();
  115. Logger.PrintStub(LogClass.ServiceAm, $"Stubbed. IdleTimeDetectionExtension: {_idleTimeDetectionExtension}");
  116. return 0;
  117. }
  118. // GetIdleTimeDetectionExtension() -> u32
  119. public long GetIdleTimeDetectionExtension(ServiceCtx context)
  120. {
  121. context.ResponseData.Write(_idleTimeDetectionExtension);
  122. Logger.PrintStub(LogClass.ServiceAm, $"Stubbed. IdleTimeDetectionExtension: {_idleTimeDetectionExtension}");
  123. return 0;
  124. }
  125. }
  126. }