IApplicationFunctions.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Ryujinx.Core.OsHle.Ipc;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using static Ryujinx.Core.OsHle.IpcServices.ObjHelper;
  5. namespace Ryujinx.Core.OsHle.IpcServices.Am
  6. {
  7. class IApplicationFunctions : IIpcService
  8. {
  9. private Dictionary<int, ServiceProcessRequest> m_Commands;
  10. public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  11. public IApplicationFunctions()
  12. {
  13. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  14. {
  15. { 1, PopLaunchParameter },
  16. { 20, EnsureSaveData },
  17. { 21, GetDesiredLanguage },
  18. { 22, SetTerminateResult },
  19. { 40, NotifyRunning }
  20. };
  21. }
  22. private const uint LaunchParamsMagic = 0xc79497ca;
  23. public long PopLaunchParameter(ServiceCtx Context)
  24. {
  25. //Only the first 0x18 bytes of the Data seems to be actually used.
  26. MakeObject(Context, new IStorage(MakeLaunchParams()));
  27. return 0;
  28. }
  29. public long EnsureSaveData(ServiceCtx Context)
  30. {
  31. long UIdLow = Context.RequestData.ReadInt64();
  32. long UIdHigh = Context.RequestData.ReadInt64();
  33. Context.ResponseData.Write(0L);
  34. return 0;
  35. }
  36. public long GetDesiredLanguage(ServiceCtx Context)
  37. {
  38. //This is an enumerator where each number is a differnet language.
  39. //0 is Japanese and 1 is English, need to figure out the other codes.
  40. Context.ResponseData.Write(1L);
  41. return 0;
  42. }
  43. public long SetTerminateResult(ServiceCtx Context)
  44. {
  45. int ErrorCode = Context.RequestData.ReadInt32();
  46. int Module = ErrorCode & 0xFF;
  47. int Description = (ErrorCode >> 9) & 0xFFF;
  48. Logging.Info($"({(ErrorModule)Module}){2000 + Module}-{Description}");
  49. return 0;
  50. }
  51. public long NotifyRunning(ServiceCtx Context)
  52. {
  53. Context.ResponseData.Write(1);
  54. return 0;
  55. }
  56. private byte[] MakeLaunchParams()
  57. {
  58. //Size needs to be at least 0x88 bytes otherwise application errors.
  59. using (MemoryStream MS = new MemoryStream())
  60. {
  61. BinaryWriter Writer = new BinaryWriter(MS);
  62. MS.SetLength(0x88);
  63. Writer.Write(LaunchParamsMagic);
  64. Writer.Write(1); //IsAccountSelected? Only lower 8 bits actually used.
  65. Writer.Write(1L); //User Id Low (note: User Id needs to be != 0)
  66. Writer.Write(0L); //User Id High
  67. return MS.ToArray();
  68. }
  69. }
  70. }
  71. }