From ea044ce9c3d14cb175092c5a4a7978effa6dab72 Mon Sep 17 00:00:00 2001 From: Aragas Date: Wed, 29 Jun 2022 00:18:29 +0300 Subject: [PATCH] Workaround for the language issue --- build/common.props | 2 +- changelog.txt | 4 ++ .../{language_data.xml => language_data.xml_} | 0 src/MCM/MCMSubModule.cs | 13 +++++- src/MCM/Utils/LocalizedTextManagerUtils.cs | 41 +++++++++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) rename src/MCM.Publish/_Module/ModuleData/Languages/EN/{language_data.xml => language_data.xml_} (100%) create mode 100644 src/MCM/Utils/LocalizedTextManagerUtils.cs diff --git a/build/common.props b/build/common.props index 7a9f8080..d5338e1e 100644 --- a/build/common.props +++ b/build/common.props @@ -3,7 +3,7 @@ 1.7.2 - 4.7.4 + 4.7.5 2.2.1 2.1.5 2.2.1 diff --git a/changelog.txt b/changelog.txt index d2882732..77aa3f85 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,8 @@ --------------------------------------------------------------------------------------------------- +Version: 4.7.5 +Game Versions: e1.7.2,e1.8.0 +* Workaround for the language issue +--------------------------------------------------------------------------------------------------- Version: 4.7.4 Game Versions: e1.7.2,e1.8.0 * Restored translation, fixed SubModule metadata! diff --git a/src/MCM.Publish/_Module/ModuleData/Languages/EN/language_data.xml b/src/MCM.Publish/_Module/ModuleData/Languages/EN/language_data.xml_ similarity index 100% rename from src/MCM.Publish/_Module/ModuleData/Languages/EN/language_data.xml rename to src/MCM.Publish/_Module/ModuleData/Languages/EN/language_data.xml_ diff --git a/src/MCM/MCMSubModule.cs b/src/MCM/MCMSubModule.cs index 58df65e4..8910e940 100644 --- a/src/MCM/MCMSubModule.cs +++ b/src/MCM/MCMSubModule.cs @@ -1,4 +1,6 @@ -using BUTR.DependencyInjection; +using Bannerlord.BUTR.Shared.Helpers; + +using BUTR.DependencyInjection; using BUTR.DependencyInjection.Extensions; using BUTR.DependencyInjection.LightInject; using BUTR.DependencyInjection.Logger; @@ -8,6 +10,7 @@ using MCM.Abstractions.Settings.Providers; using MCM.Extensions; using MCM.LightInject; +using MCM.Utils; using TaleWorlds.CampaignSystem; using TaleWorlds.Core; @@ -57,6 +60,14 @@ protected override void OnSubModuleLoad() if (!ServiceRegistrationWasCalled) OnServiceRegistration(); + + if (ApplicationVersionHelper.GameVersion() is { } gameVersion) + { + if (gameVersion.Major is 1 && gameVersion.Minor is 8 && gameVersion.Revision is >= 0) + { + LocalizedTextManagerUtils.LoadLanguageData(); + } + } } protected override void OnSubModuleUnloaded() diff --git a/src/MCM/Utils/LocalizedTextManagerUtils.cs b/src/MCM/Utils/LocalizedTextManagerUtils.cs new file mode 100644 index 00000000..a47da1a2 --- /dev/null +++ b/src/MCM/Utils/LocalizedTextManagerUtils.cs @@ -0,0 +1,41 @@ +using Bannerlord.BUTR.Shared.Helpers; + +using HarmonyLib.BUTR.Extensions; + +using System.IO; +using System.Xml; + +using TaleWorlds.Engine; + +using Path = System.IO.Path; + +namespace MCM.Utils +{ + internal static class LocalizedTextManagerUtils + { + private delegate XmlDocument? LoadXmlFileDelegate(string path); + private static readonly LoadXmlFileDelegate? LoadXmlFile = + AccessTools2.GetDeclaredDelegate("TaleWorlds.Localization.LocalizedTextManager:LoadXmlFile"); + + private delegate void LoadFromXmlDelegate(XmlDocument doc, string modulePath); + private static readonly LoadFromXmlDelegate? LoadFromXml = + AccessTools2.GetDeclaredDelegate("TaleWorlds.Localization.LanguageData:LoadFromXml"); + + public static void LoadLanguageData() + { + if (LoadXmlFile is null || LoadFromXml is null) return; + + var moduleInfo = ModuleInfoHelper.GetModuleByType(typeof(LocalizedTextManagerUtils)); + if (moduleInfo is null) return; + + var path = Path.Combine(Utilities.GetBasePath(), "Modules", moduleInfo.Id, "ModuleData", "Languages"); + if (!Directory.Exists(path)) return; + + foreach (var file in Directory.GetFiles(path, "language_data.xml_", SearchOption.AllDirectories)) + { + if (LoadXmlFile(file) is { } xmlDocument) + LoadFromXml(xmlDocument, path); + } + } + } +} \ No newline at end of file