ISettingsServer.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using Ryujinx.Core.OsHle.Ipc;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. namespace Ryujinx.Core.OsHle.Services.Set
  6. {
  7. class ISettingsServer : IpcService
  8. {
  9. private static string[] LanguageCodes = new string[]
  10. {
  11. "ja",
  12. "en-US",
  13. "fr",
  14. "de",
  15. "it",
  16. "es",
  17. "zh-CN",
  18. "ko",
  19. "nl",
  20. "pt",
  21. "ru",
  22. "zh-TW",
  23. "en-GB",
  24. "fr-CA",
  25. "es-419",
  26. "zh-Hans",
  27. "zh-Hant"
  28. };
  29. private Dictionary<int, ServiceProcessRequest> m_Commands;
  30. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  31. public ISettingsServer()
  32. {
  33. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  34. {
  35. { 0, GetLanguageCode },
  36. { 1, GetAvailableLanguageCodes },
  37. { 3, GetAvailableLanguageCodeCount }
  38. };
  39. }
  40. public static long GetLanguageCode(ServiceCtx Context)
  41. {
  42. Context.ResponseData.Write(LanguageCodetoLongBE(LanguageCodes[1]));
  43. return 0;
  44. }
  45. private static long LanguageCodetoLongBE(string LanguageCode)
  46. {
  47. using (MemoryStream MS = new MemoryStream())
  48. {
  49. foreach (char Chr in LanguageCode)
  50. {
  51. MS.WriteByte((byte)Chr);
  52. }
  53. for (int Offs = 0; Offs < (8 - LanguageCode.Length); Offs++)
  54. {
  55. MS.WriteByte(0);
  56. }
  57. return BitConverter.ToInt64(MS.ToArray(), 0);
  58. }
  59. }
  60. public static long GetAvailableLanguageCodes(ServiceCtx Context)
  61. {
  62. long Position = Context.Request.RecvListBuff[0].Position;
  63. short Size = Context.Request.RecvListBuff[0].Size;
  64. int Count = (int)((uint)Size / 8);
  65. if (Count > LanguageCodes.Length)
  66. {
  67. Count = LanguageCodes.Length;
  68. }
  69. for (int Index = 0; Index < Count; Index++)
  70. {
  71. string LanguageCode = LanguageCodes[Index];
  72. foreach (char Chr in LanguageCode)
  73. {
  74. Context.Memory.WriteByte(Position++, (byte)Chr);
  75. }
  76. for (int Offs = 0; Offs < (8 - LanguageCode.Length); Offs++)
  77. {
  78. Context.Memory.WriteByte(Position++, 0);
  79. }
  80. }
  81. Context.ResponseData.Write(Count);
  82. return 0;
  83. }
  84. public static long GetAvailableLanguageCodeCount(ServiceCtx Context)
  85. {
  86. Context.ResponseData.Write(LanguageCodes.Length);
  87. return 0;
  88. }
  89. }
  90. }