IManagerForApplication.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.Cpu;
  3. using Ryujinx.HLE.HOS.Kernel.Threading;
  4. using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
  5. using Ryujinx.HLE.HOS.Services.Arp;
  6. using System;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace Ryujinx.HLE.HOS.Services.Account.Acc
  11. {
  12. class IManagerForApplication : IpcService
  13. {
  14. // TODO: Determine where and how NetworkServiceAccountId is set.
  15. private const long NetworkServiceAccountId = 0xcafe;
  16. private UserId _userId;
  17. private ApplicationLaunchProperty _applicationLaunchProperty;
  18. public IManagerForApplication(UserId userId, ApplicationLaunchProperty applicationLaunchProperty)
  19. {
  20. _userId = userId;
  21. _applicationLaunchProperty = applicationLaunchProperty;
  22. }
  23. [Command(0)]
  24. // CheckAvailability()
  25. public ResultCode CheckAvailability(ServiceCtx context)
  26. {
  27. // NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x".
  28. // Then it searches the Availability of Online Services related to the UserId in this file and returns it.
  29. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  30. // NOTE: Even if we try to return different error codes here, the guest still needs other calls.
  31. return ResultCode.Success;
  32. }
  33. [Command(1)]
  34. // GetAccountId() -> nn::account::NetworkServiceAccountId
  35. public ResultCode GetAccountId(ServiceCtx context)
  36. {
  37. // NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted
  38. // as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the account:/ savedata.
  39. // Then it searches the NetworkServiceAccountId related to the UserId in this file and returns it.
  40. Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { NetworkServiceAccountId });
  41. context.ResponseData.Write(NetworkServiceAccountId);
  42. return ResultCode.Success;
  43. }
  44. [Command(2)]
  45. // EnsureIdTokenCacheAsync() -> object<nn::account::detail::IAsyncContext>
  46. public ResultCode EnsureIdTokenCacheAsync(ServiceCtx context)
  47. {
  48. KEvent asyncEvent = new KEvent(context.Device.System.KernelContext);
  49. AsyncExecution asyncExecution = new AsyncExecution(asyncEvent);
  50. asyncExecution.Initialize(1000, EnsureIdTokenCacheAsyncImpl);
  51. MakeObject(context, new IAsyncContext(asyncExecution));
  52. // return ResultCode.NullObject if the IAsyncContext pointer is null. Doesn't occur in our case.
  53. return ResultCode.Success;
  54. }
  55. private async Task EnsureIdTokenCacheAsyncImpl(CancellationToken token)
  56. {
  57. // NOTE: This open the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
  58. // in the "account:/" savedata.
  59. // Then its read data, use dauth API with this data to get the Token Id and probably store the dauth response
  60. // in "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the "account:/" savedata.
  61. // Since we don't support online services, we can stub it.
  62. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  63. // TODO: Use a real function instead, with the CancellationToken.
  64. await Task.CompletedTask;
  65. }
  66. [Command(3)]
  67. // LoadIdTokenCache() -> (u32 id_token_cache_size, buffer<bytes, 6>)
  68. public ResultCode LoadIdTokenCache(ServiceCtx context)
  69. {
  70. long bufferPosition = context.Request.ReceiveBuff[0].Position;
  71. long bufferSize = context.Request.ReceiveBuff[0].Size;
  72. // NOTE: This opens the file at "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
  73. // in the "account:/" savedata and writes some data in the buffer.
  74. // Since we don't support online services, we can stub it.
  75. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  76. /*
  77. if (internal_object != null)
  78. {
  79. if (bufferSize > 0xC00)
  80. {
  81. return ResultCode.InvalidIdTokenCacheBufferSize;
  82. }
  83. }
  84. */
  85. int idTokenCacheSize = 0;
  86. MemoryHelper.FillWithZeros(context.Memory, bufferPosition, (int)bufferSize);
  87. context.ResponseData.Write(idTokenCacheSize);
  88. return ResultCode.Success;
  89. }
  90. [Command(130)]
  91. // GetNintendoAccountUserResourceCacheForApplication() -> (nn::account::NintendoAccountId, buffer<nn::account::nas::NasUserBaseForApplication, 0x1a>, buffer<bytes, 6>)
  92. public ResultCode GetNintendoAccountUserResourceCacheForApplication(ServiceCtx context)
  93. {
  94. Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { NetworkServiceAccountId });
  95. context.ResponseData.Write(NetworkServiceAccountId);
  96. // TODO: determine and fill the two output IPC buffers.
  97. return ResultCode.Success;
  98. }
  99. [Command(160)] // 5.0.0+
  100. // StoreOpenContext()
  101. public ResultCode StoreOpenContext(ServiceCtx context)
  102. {
  103. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  104. return ResultCode.Success;
  105. }
  106. }
  107. }