ISystemSettingsServer.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using Ryujinx.HLE.OsHle.Ipc;
  2. using Ryujinx.HLE.Settings;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Text;
  7. namespace Ryujinx.HLE.OsHle.Services.Set
  8. {
  9. class ISystemSettingsServer : IpcService
  10. {
  11. private Dictionary<int, ServiceProcessRequest> m_Commands;
  12. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  13. public ISystemSettingsServer()
  14. {
  15. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  16. {
  17. { 4, GetFirmwareVersion2 },
  18. { 23, GetColorSetId },
  19. { 24, SetColorSetId },
  20. { 38, GetSettingsItemValue }
  21. };
  22. }
  23. public static long GetFirmwareVersion2(ServiceCtx Context)
  24. {
  25. long ReplyPos = Context.Request.RecvListBuff[0].Position;
  26. long ReplySize = Context.Request.RecvListBuff[0].Size;
  27. const byte MajorFWVersion = 0x03;
  28. const byte MinorFWVersion = 0x00;
  29. const byte MicroFWVersion = 0x00;
  30. const byte Unknown = 0x00; //Build?
  31. const int RevisionNumber = 0x0A;
  32. const string Platform = "NX";
  33. const string UnknownHex = "7fbde2b0bba4d14107bf836e4643043d9f6c8e47";
  34. const string Version = "3.0.0";
  35. const string Build = "NintendoSDK Firmware for NX 3.0.0-10.0";
  36. //http://switchbrew.org/index.php?title=System_Version_Title
  37. using (MemoryStream MS = new MemoryStream(0x100))
  38. {
  39. BinaryWriter Writer = new BinaryWriter(MS);
  40. Writer.Write(MajorFWVersion);
  41. Writer.Write(MinorFWVersion);
  42. Writer.Write(MicroFWVersion);
  43. Writer.Write(Unknown);
  44. Writer.Write(RevisionNumber);
  45. Writer.Write(Encoding.ASCII.GetBytes(Platform));
  46. MS.Seek(0x28, SeekOrigin.Begin);
  47. Writer.Write(Encoding.ASCII.GetBytes(UnknownHex));
  48. MS.Seek(0x68, SeekOrigin.Begin);
  49. Writer.Write(Encoding.ASCII.GetBytes(Version));
  50. MS.Seek(0x80, SeekOrigin.Begin);
  51. Writer.Write(Encoding.ASCII.GetBytes(Build));
  52. Context.Memory.WriteBytes(ReplyPos, MS.ToArray());
  53. }
  54. return 0;
  55. }
  56. public static long GetColorSetId(ServiceCtx Context)
  57. {
  58. Context.ResponseData.Write((int)Context.Ns.Settings.ThemeColor);
  59. return 0;
  60. }
  61. public static long SetColorSetId(ServiceCtx Context)
  62. {
  63. int ColorSetId = Context.RequestData.ReadInt32();
  64. Context.Ns.Settings.ThemeColor = (ColorSet)ColorSetId;
  65. return 0;
  66. }
  67. public static long GetSettingsItemValue(ServiceCtx Context)
  68. {
  69. long ClassPos = Context.Request.PtrBuff[0].Position;
  70. long ClassSize = Context.Request.PtrBuff[0].Size;
  71. long NamePos = Context.Request.PtrBuff[1].Position;
  72. long NameSize = Context.Request.PtrBuff[1].Size;
  73. long ReplyPos = Context.Request.ReceiveBuff[0].Position;
  74. long ReplySize = Context.Request.ReceiveBuff[0].Size;
  75. byte[] Class = Context.Memory.ReadBytes(ClassPos, ClassSize);
  76. byte[] Name = Context.Memory.ReadBytes(NamePos, NameSize);
  77. string AskedSetting = Encoding.ASCII.GetString(Class).Trim('\0') + "!" + Encoding.ASCII.GetString(Name).Trim('\0');
  78. NxSettings.Settings.TryGetValue(AskedSetting, out object NxSetting);
  79. if (NxSetting != null)
  80. {
  81. byte[] SettingBuffer = new byte[ReplySize];
  82. if (NxSetting is string StringValue)
  83. {
  84. if (StringValue.Length + 1 > ReplySize)
  85. {
  86. Context.Ns.Log.PrintError(Logging.LogClass.ServiceSet, $"{AskedSetting} String value size is too big!");
  87. }
  88. else
  89. {
  90. SettingBuffer = Encoding.ASCII.GetBytes(StringValue + "\0");
  91. }
  92. }
  93. if (NxSetting is int IntValue)
  94. {
  95. SettingBuffer = BitConverter.GetBytes(IntValue);
  96. }
  97. else if (NxSetting is bool BoolValue)
  98. {
  99. SettingBuffer[0] = BoolValue ? (byte)1 : (byte)0;
  100. }
  101. else
  102. {
  103. throw new NotImplementedException(NxSetting.GetType().Name);
  104. }
  105. Context.Memory.WriteBytes(ReplyPos, SettingBuffer);
  106. Context.Ns.Log.PrintDebug(Logging.LogClass.ServiceSet, $"{AskedSetting} set value: {NxSetting} as {NxSetting.GetType()}");
  107. }
  108. else
  109. {
  110. Context.Ns.Log.PrintError(Logging.LogClass.ServiceSet, $"{AskedSetting} not found!");
  111. }
  112. return 0;
  113. }
  114. }
  115. }