Skip to content

Commit

Permalink
Merge pull request #64 from BUTR/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Aragas authored Jun 28, 2022
2 parents d69aaf3 + 28fa6e3 commit 920ab1d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Bannerlord.Harmony/SubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ protected override void OnSubModuleLoad()
base.OnSubModuleLoad();

LoadHarmony();

if (ApplicationVersionHelper.GameVersion() is { } gameVersion)
{
if (gameVersion.Major is 1 && gameVersion.Minor is 8 && gameVersion.Revision is >= 0)
{
LocalizedTextManagerUtils.LoadLanguageData();
}
}
}

protected override void OnBeforeInitialModuleScreenSetAsRoot()
Expand Down
41 changes: 41 additions & 0 deletions src/Bannerlord.Harmony/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 Bannerlord.Harmony.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 920ab1d

Please sign in to comment.