-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from BUTR/dev
Release
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.