IApplicationFunctions.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. using Ryujinx.HLE.HOS.Services.Am.AppletAE;
  6. using Ryujinx.HLE.HOS.Services.Am.AppletAE.Storage;
  7. using System;
  8. namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy
  9. {
  10. class IApplicationFunctions : IpcService
  11. {
  12. private KEvent _gpuErrorDetectedSystemEvent;
  13. public IApplicationFunctions(Horizon system)
  14. {
  15. _gpuErrorDetectedSystemEvent = new KEvent(system);
  16. }
  17. [Command(1)]
  18. // PopLaunchParameter(u32) -> object<nn::am::service::IStorage>
  19. public ResultCode PopLaunchParameter(ServiceCtx context)
  20. {
  21. // Only the first 0x18 bytes of the Data seems to be actually used.
  22. MakeObject(context, new IStorage(StorageHelper.MakeLaunchParams()));
  23. return ResultCode.Success;
  24. }
  25. [Command(20)]
  26. // EnsureSaveData(nn::account::Uid) -> u64
  27. public ResultCode EnsureSaveData(ServiceCtx context)
  28. {
  29. long uIdLow = context.RequestData.ReadInt64();
  30. long uIdHigh = context.RequestData.ReadInt64();
  31. Logger.PrintStub(LogClass.ServiceAm);
  32. context.ResponseData.Write(0L);
  33. return ResultCode.Success;
  34. }
  35. [Command(21)]
  36. // GetDesiredLanguage() -> nn::settings::LanguageCode
  37. public ResultCode GetDesiredLanguage(ServiceCtx context)
  38. {
  39. context.ResponseData.Write(context.Device.System.State.DesiredLanguageCode);
  40. return ResultCode.Success;
  41. }
  42. [Command(22)]
  43. // SetTerminateResult(u32)
  44. public ResultCode SetTerminateResult(ServiceCtx context)
  45. {
  46. int errorCode = context.RequestData.ReadInt32();
  47. string result = GetFormattedErrorCode(errorCode);
  48. Logger.PrintInfo(LogClass.ServiceAm, $"Result = 0x{errorCode:x8} ({result}).");
  49. return ResultCode.Success;
  50. }
  51. private string GetFormattedErrorCode(int errorCode)
  52. {
  53. int module = (errorCode >> 0) & 0x1ff;
  54. int description = (errorCode >> 9) & 0x1fff;
  55. return $"{(2000 + module):d4}-{description:d4}";
  56. }
  57. [Command(23)]
  58. // GetDisplayVersion() -> nn::oe::DisplayVersion
  59. public ResultCode GetDisplayVersion(ServiceCtx context)
  60. {
  61. // FIXME: Need to check correct version on a switch.
  62. context.ResponseData.Write(1L);
  63. context.ResponseData.Write(0L);
  64. return ResultCode.Success;
  65. }
  66. [Command(40)]
  67. // NotifyRunning() -> b8
  68. public ResultCode NotifyRunning(ServiceCtx context)
  69. {
  70. context.ResponseData.Write(1);
  71. return ResultCode.Success;
  72. }
  73. [Command(50)] // 2.0.0+
  74. // GetPseudoDeviceId() -> nn::util::Uuid
  75. public ResultCode GetPseudoDeviceId(ServiceCtx context)
  76. {
  77. Logger.PrintStub(LogClass.ServiceAm);
  78. context.ResponseData.Write(0L);
  79. context.ResponseData.Write(0L);
  80. return ResultCode.Success;
  81. }
  82. [Command(66)] // 3.0.0+
  83. // InitializeGamePlayRecording(u64, handle<copy>)
  84. public ResultCode InitializeGamePlayRecording(ServiceCtx context)
  85. {
  86. Logger.PrintStub(LogClass.ServiceAm);
  87. return ResultCode.Success;
  88. }
  89. [Command(67)] // 3.0.0+
  90. // SetGamePlayRecordingState(u32)
  91. public ResultCode SetGamePlayRecordingState(ServiceCtx context)
  92. {
  93. int state = context.RequestData.ReadInt32();
  94. Logger.PrintStub(LogClass.ServiceAm);
  95. return ResultCode.Success;
  96. }
  97. [Command(130)] // 8.0.0+
  98. // GetGpuErrorDetectedSystemEvent() -> handle<copy>
  99. public ResultCode GetGpuErrorDetectedSystemEvent(ServiceCtx context)
  100. {
  101. if (context.Process.HandleTable.GenerateHandle(_gpuErrorDetectedSystemEvent.ReadableEvent, out int gpuErrorDetectedSystemEventHandle) != KernelResult.Success)
  102. {
  103. throw new InvalidOperationException("Out of handles!");
  104. }
  105. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(gpuErrorDetectedSystemEventHandle);
  106. // NOTE: This is used by "sdk" NSO during applet-application initialization.
  107. // A seperate thread is setup where event-waiting is handled.
  108. // When the Event is signaled, official sw will assert.
  109. return ResultCode.Success;
  110. }
  111. }
  112. }