diff --git a/Ryujinx.Core/OsHle/Horizon.cs b/Ryujinx.Core/OsHle/Horizon.cs index 3b31bfc6..0cc3d815 100644 --- a/Ryujinx.Core/OsHle/Horizon.cs +++ b/Ryujinx.Core/OsHle/Horizon.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Core.OsHle private ConcurrentDictionary Processes; - internal SystemStateMgr SystemState { get; private set; } + public SystemStateMgr SystemState { get; private set; } internal HSharedMem HidSharedMem { get; private set; } internal HSharedMem FontSharedMem { get; private set; } diff --git a/Ryujinx.Core/OsHle/Services/Am/IApplicationFunctions.cs b/Ryujinx.Core/OsHle/Services/Am/IApplicationFunctions.cs index 8433f9d5..47152cd9 100644 --- a/Ryujinx.Core/OsHle/Services/Am/IApplicationFunctions.cs +++ b/Ryujinx.Core/OsHle/Services/Am/IApplicationFunctions.cs @@ -48,11 +48,7 @@ namespace Ryujinx.Core.OsHle.Services.Am public long GetDesiredLanguage(ServiceCtx Context) { - Context.Ns.Log.PrintStub(LogClass.ServiceAm, "Stubbed."); - - //This is an enumerator where each number is a differnet language. - //0 is Japanese and 1 is English, need to figure out the other codes. - Context.ResponseData.Write(1L); + Context.ResponseData.Write(Context.Ns.Os.SystemState.DesiredLanguageCode); return 0; } diff --git a/Ryujinx.Core/OsHle/Services/Set/ISettingsServer.cs b/Ryujinx.Core/OsHle/Services/Set/ISettingsServer.cs index ea0303f0..c80de80c 100644 --- a/Ryujinx.Core/OsHle/Services/Set/ISettingsServer.cs +++ b/Ryujinx.Core/OsHle/Services/Set/ISettingsServer.cs @@ -1,33 +1,10 @@ using Ryujinx.Core.OsHle.Ipc; -using System; using System.Collections.Generic; -using System.IO; namespace Ryujinx.Core.OsHle.Services.Set { class ISettingsServer : IpcService { - private static string[] LanguageCodes = new string[] - { - "ja", - "en-US", - "fr", - "de", - "it", - "es", - "zh-CN", - "ko", - "nl", - "pt", - "ru", - "zh-TW", - "en-GB", - "fr-CA", - "es-419", - "zh-Hans", - "zh-Hant" - }; - private Dictionary m_Commands; public override IReadOnlyDictionary Commands => m_Commands; @@ -44,29 +21,11 @@ namespace Ryujinx.Core.OsHle.Services.Set public static long GetLanguageCode(ServiceCtx Context) { - Context.ResponseData.Write(LanguageCodetoLongBE(LanguageCodes[1])); + Context.ResponseData.Write(Context.Ns.Os.SystemState.DesiredLanguageCode); return 0; } - private static long LanguageCodetoLongBE(string LanguageCode) - { - using (MemoryStream MS = new MemoryStream()) - { - foreach (char Chr in LanguageCode) - { - MS.WriteByte((byte)Chr); - } - - for (int Offs = 0; Offs < (8 - LanguageCode.Length); Offs++) - { - MS.WriteByte(0); - } - - return BitConverter.ToInt64(MS.ToArray(), 0); - } - } - public static long GetAvailableLanguageCodes(ServiceCtx Context) { long Position = Context.Request.RecvListBuff[0].Position; @@ -74,24 +33,16 @@ namespace Ryujinx.Core.OsHle.Services.Set int Count = (int)((uint)Size / 8); - if (Count > LanguageCodes.Length) + if (Count > SystemStateMgr.LanguageCodes.Length) { - Count = LanguageCodes.Length; + Count = SystemStateMgr.LanguageCodes.Length; } for (int Index = 0; Index < Count; Index++) { - string LanguageCode = LanguageCodes[Index]; + Context.Memory.WriteInt64(Position, SystemStateMgr.GetLanguageCode(Index)); - foreach (char Chr in LanguageCode) - { - Context.Memory.WriteByte(Position++, (byte)Chr); - } - - for (int Offs = 0; Offs < (8 - LanguageCode.Length); Offs++) - { - Context.Memory.WriteByte(Position++, 0); - } + Position += 8; } Context.ResponseData.Write(Count); @@ -101,7 +52,7 @@ namespace Ryujinx.Core.OsHle.Services.Set public static long GetAvailableLanguageCodeCount(ServiceCtx Context) { - Context.ResponseData.Write(LanguageCodes.Length); + Context.ResponseData.Write(SystemStateMgr.LanguageCodes.Length); return 0; } diff --git a/Ryujinx.Core/OsHle/SystemLanguage.cs b/Ryujinx.Core/OsHle/SystemLanguage.cs new file mode 100644 index 00000000..470362c0 --- /dev/null +++ b/Ryujinx.Core/OsHle/SystemLanguage.cs @@ -0,0 +1,23 @@ +namespace Ryujinx.Core.OsHle +{ + public enum SystemLanguage + { + Japanese, + AmericanEnglish, + French, + German, + Italian, + Spanish, + Chinese, + Korean, + Dutch, + Portuguese, + Russian, + Taiwanese, + BritishEnglish, + CanadianFrench, + LatinAmericanSpanish, + SimplifiedChinese, + TraditionalChinese + } +} \ No newline at end of file diff --git a/Ryujinx.Core/OsHle/SystemStateMgr.cs b/Ryujinx.Core/OsHle/SystemStateMgr.cs index 3223abfb..0756c7d1 100644 --- a/Ryujinx.Core/OsHle/SystemStateMgr.cs +++ b/Ryujinx.Core/OsHle/SystemStateMgr.cs @@ -1,7 +1,30 @@ +using System; + namespace Ryujinx.Core.OsHle { - class SystemStateMgr + public class SystemStateMgr { + internal static string[] LanguageCodes = new string[] + { + "ja", + "en-US", + "fr", + "de", + "it", + "es", + "zh-CN", + "ko", + "nl", + "pt", + "ru", + "zh-TW", + "en-GB", + "fr-CA", + "es-419", + "zh-Hans", + "zh-Hant" + }; + internal static string[] AudioOutputs = new string[] { "AudioTvOutput", @@ -9,13 +32,22 @@ namespace Ryujinx.Core.OsHle "AudioBuiltInSpeakerOutput" }; - public string ActiveAudioOutput { get; private set; } + internal long DesiredLanguageCode { get; private set; } + + internal string ActiveAudioOutput { get; private set; } public SystemStateMgr() { + SetLanguage(SystemLanguage.AmericanEnglish); + SetAudioOutputAsBuiltInSpeaker(); } + public void SetLanguage(SystemLanguage Language) + { + DesiredLanguageCode = GetLanguageCode((int)Language); + } + public void SetAudioOutputAsTv() { ActiveAudioOutput = AudioOutputs[0]; @@ -30,5 +62,23 @@ namespace Ryujinx.Core.OsHle { ActiveAudioOutput = AudioOutputs[2]; } + + internal static long GetLanguageCode(int Index) + { + if ((uint)Index >= LanguageCodes.Length) + { + throw new ArgumentOutOfRangeException(nameof(Index)); + } + + long Code = 0; + int Shift = 0; + + foreach (char Chr in LanguageCodes[Index]) + { + Code |= (long)(byte)Chr << Shift++ * 8; + } + + return Code; + } } } \ No newline at end of file