using ADOFAIRenderer.Localization; using HarmonyLib; using UnityEngine; namespace ADOFAIRenderer.Patch.Game; /// /// Keeps the mod UI language () equal to the game language. /// /// Patched members: RDString.Setup(), which initializes the game's string table and sets RDString.language from /// Persistence.language (it returns immediately when already initialized); and RDString.ChangeLanguage(SystemLanguage), /// which stores the language in Persistence.language, clears the initialized flag and calls Setup again. /// /// Always active (independent of the render stage). Runs on the main Unity thread. /// [HarmonyPatch(typeof(RDString))] internal static class LanguageSyncPatch { /// Postfix of RDString.ChangeLanguage: applies the selected language to the mod UI. /// Language passed to ChangeLanguage. [HarmonyPatch(nameof(RDString.ChangeLanguage))] [HarmonyPostfix] public static void OnChangeLanguage(SystemLanguage language) { LocalizationManager.SetLanguage(language); } /// /// Postfix of RDString.Setup: applies RDString.language (the language resolved by the game) to the mod UI. /// Runs on every Setup call, including the early-return calls made when the string table is already initialized. /// [HarmonyPatch(nameof(RDString.Setup))] [HarmonyPostfix] public static void OnSetup() { LocalizationManager.SetLanguage(RDString.language); } }