IApplicationFunctions.cs 2.7 KB

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