IApplicationFunctions.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Ryujinx.Core.OsHle.Ipc;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using static Ryujinx.Core.OsHle.Objects.ObjHelper;
  5. namespace Ryujinx.Core.OsHle.Objects.Am
  6. {
  7. class IApplicationFunctions : IIpcInterface
  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. { 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 NotifyRunning(ServiceCtx Context)
  43. {
  44. Context.ResponseData.Write(1);
  45. return 0;
  46. }
  47. private byte[] MakeLaunchParams()
  48. {
  49. //Size needs to be at least 0x88 bytes otherwise application errors.
  50. using (MemoryStream MS = new MemoryStream())
  51. {
  52. BinaryWriter Writer = new BinaryWriter(MS);
  53. MS.SetLength(0x88);
  54. Writer.Write(LaunchParamsMagic);
  55. Writer.Write(1); //IsAccountSelected? Only lower 8 bits actually used.
  56. Writer.Write(1L); //User Id Low (note: User Id needs to be != 0)
  57. Writer.Write(0L); //User Id High
  58. return MS.ToArray();
  59. }
  60. }
  61. }
  62. }