Skip to content

Commit

Permalink
Merge pull request #237 from Aragas/dev
Browse files Browse the repository at this point in the history
v4.7.5
  • Loading branch information
Aragas authored Jun 28, 2022
2 parents ca1b214 + ea044ce commit 0bb10de
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<GameVersion>1.7.2</GameVersion>
<Version>4.7.4</Version>
<Version>4.7.5</Version>
<HarmonyVersion>2.2.1</HarmonyVersion>
<ButterLibVersion>2.1.5</ButterLibVersion>
<UIExtenderExVersion>2.2.1</UIExtenderExVersion>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
13 changes: 12 additions & 1 deletion src/MCM/MCMSubModule.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,6 +10,7 @@
using MCM.Abstractions.Settings.Providers;
using MCM.Extensions;
using MCM.LightInject;
using MCM.Utils;

using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
Expand Down Expand Up @@ -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()
Expand Down
41 changes: 41 additions & 0 deletions src/MCM/Utils/LocalizedTextManagerUtils.cs
Original file line number Diff line number Diff line change
@@ -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<LoadXmlFileDelegate>("TaleWorlds.Localization.LocalizedTextManager:LoadXmlFile");

private delegate void LoadFromXmlDelegate(XmlDocument doc, string modulePath);
private static readonly LoadFromXmlDelegate? LoadFromXml =
AccessTools2.GetDeclaredDelegate<LoadFromXmlDelegate>("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);
}
}
}
}

0 comments on commit 0bb10de

Please sign in to comment.