Skip to content

Commit

Permalink
Merge pull request #184 from BUTR/dev
Browse files Browse the repository at this point in the history
v2.1.7
  • Loading branch information
Aragas authored Jun 28, 2022
2 parents dfe9f55 + 505d28d commit 32bd064
Show file tree
Hide file tree
Showing 19 changed files with 806 additions and 23 deletions.
10 changes: 9 additions & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
<!--Development Variables-->
<PropertyGroup>
<!--Module Version-->
<Version>2.1.5</Version>
<Version>2.1.7</Version>
<!--Harmony Version-->
<HarmonyVersion>2.2.1</HarmonyVersion>
<HarmonyExtensionsVersion>3.1.0.61</HarmonyExtensionsVersion>
<HarmonyAnalyzerVersion>1.0.1.44</HarmonyAnalyzerVersion>
<!--Microsoft Extension Libraries Version-->
<!--Serilog depends on abstraction 2.0.0, and since we can't do app redirects, we're stuck with that-->
<ExtensionVersion>2.0.0</ExtensionVersion>
Expand Down Expand Up @@ -119,4 +120,11 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(GITHUB_ACTIONS)' != 'true'">
<PackageReference Include="BUTR.Harmony.Analyzer" Version="$(HarmonyAnalyzerVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
---------------------------------------------------------------------------------------------------
Version: 2.1.7
Game Versions: e1.7.2,e1.8.0
* Workaround for the language issue
---------------------------------------------------------------------------------------------------
Version: 2.1.6
Game Versions: e1.7.2,e1.8.0
* Restored translation, fixed SubModule metadata
---------------------------------------------------------------------------------------------------
Version: 2.1.5
Game Versions: e1.7.2,e1.8.0
* InformationManager fix
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LanguageData xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/BUTR/Bannerlord.XmlSchemas/master/ModuleLanguageData.xsd"

id="English"
name="English"
subtitle_extension="en-GB"
supported_iso="en-GB,en-US,en,eng,en-us,en-gb,en-au,en-bz,en-ca,en-ie,en-jm,en-nz,en-za,en-tt"
under_development="false">
<LanguageFile xml_path="sta_strings.xml" />
</LanguageData>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<base xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="https://www.w3schools.com/xml ../../../../../../resources/language.xsd" type="string">
<base xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/BUTR/Bannerlord.XmlSchemas/master/ModuleLanguage.xsd" >
<tags>
<tag language="English" />
</tags>
Expand All @@ -23,5 +24,8 @@
<string id="FcR4BXnhx8" text="{MODULE} has mutually exclusive mod order directives specified for the {REQUIRED_MODULE}!" />
<string id="eXs6FLm5DP" text="It's strongly recommended to terminate the game now. Do you wish to terminate it?" />
<string id="aGg5Gh64gH" text="This version of ButterLib is intended for e1.7.2 and higher! You are running {GAMEVERSION}!" />

<string id="B7bfrDNzIk" text="Disable when Debugger is Attached" />
<string id="r3ktQzFMRz" text="Stops the Exception Handler when a debugger is attached." />
</strings>
</base>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LanguageData xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/BUTR/Bannerlord.XmlSchemas/master/ModuleLanguageData.xsd"

id="Русский"
name="Русский"
subtitle_extension="ru"
supported_iso="ru,rus,ru-ru,ru-md"
under_development="false">
<LanguageFile xml_path="sta_strings.xml" />
</LanguageData>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<base xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="https://www.w3schools.com/xml ../../../../../../resources/language.xsd" type="string">
<base xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/BUTR/Bannerlord.XmlSchemas/master/ModuleLanguage.xsd" >
<tags>
<tag language="Русский" />
</tags>
Expand Down
30 changes: 20 additions & 10 deletions src/Bannerlord.ButterLib.Implementation/_Module/SubModule.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<Name value="$modulename$" />
<Module xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/BUTR/Bannerlord.XmlSchemas/master/SubModule.xsd" >
<Id value="$moduleid$" />
<Name value="$modulename$" />
<Version value="v$version$" />
<Official value="false" />
<DefaultModule value="false" />
<SingleplayerModule value="true" />
<MultiplayerModule value="false" />
<ModuleCategory value="Singleplayer" />
<Url value="https://www.nexusmods.com/mountandblade2bannerlord/mods/2018" />
<DependedModules>
<DependedModule Id="Bannerlord.Harmony" DependentVersion="v$harmonyversion$" />
<!--<DependedModule Id="Bannerlord.ModuleLoader" />-->
</DependedModules>
<!-- Prototype -->
<ModulesToLoadAfterThis>
<Module Id="Native" />
<Module Id="SandBoxCore" />
<Module Id="Sandbox" />
<Module Id="StoryMode" />
<Module Id="CustomBattle" />
</ModulesToLoadAfterThis>
<!-- Community Dependency Metadata -->
<!-- https://github.com/BUTR/Bannerlord.BUTRLoader#for-modders -->
<DependedModuleMetadatas>
<DependedModuleMetadata id="Bannerlord.Harmony" order="LoadBeforeThis" version="v$harmonyversion$" />
<DependedModuleMetadata id="BetterExceptionWindow" order="LoadBeforeThis" optional="true" />
<DependedModuleMetadata id="Bannerlord.ModuleLoader" order="LoadBeforeThis" optional="true" />

<DependedModuleMetadata id="Native" order="LoadAfterThis" />
<DependedModuleMetadata id="SandBoxCore" order="LoadAfterThis" optional="true" />
<DependedModuleMetadata id="Sandbox" order="LoadAfterThis" optional="true" />
<DependedModuleMetadata id="StoryMode" order="LoadAfterThis" />
<DependedModuleMetadata id="CustomBattle" order="LoadAfterThis" optional="true" />
<DependedModuleMetadata id="Native" order="LoadAfterThis" version="e$gameversion$.*" />
<DependedModuleMetadata id="SandBoxCore" order="LoadAfterThis" version="e$gameversion$.*" optional="true" />
<DependedModuleMetadata id="Sandbox" order="LoadAfterThis" version="e$gameversion$.*" optional="true" />
<DependedModuleMetadata id="StoryMode" order="LoadAfterThis" version="e$gameversion$.*" />
<DependedModuleMetadata id="CustomBattle" order="LoadAfterThis" version="e$gameversion$.*" optional="true" />
</DependedModuleMetadatas>
<!-- Prototype -->
<!-- Community Dependency Metadata -->
<SubModules>
<SubModule>
<Name value="ButterLib" />
Expand Down Expand Up @@ -59,4 +69,4 @@
<Tags />
</SubModule>
</SubModules>
</Module>
</Module>
11 changes: 11 additions & 0 deletions src/Bannerlord.ButterLib/ButterLibSubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using Bannerlord.ButterLib.CrashUploader;
using Bannerlord.ButterLib.DelayedSubModule;
using Bannerlord.ButterLib.ExceptionHandler;
using Bannerlord.ButterLib.Helpers;
using Bannerlord.ButterLib.ObjectSystem.Extensions;
using Bannerlord.ButterLib.Options;
using Bannerlord.ButterLib.SubModuleWrappers2;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -79,6 +81,7 @@ public void OnServiceRegistration()
Services.AddSubSystem<DelayedSubModuleSubSystem>();
Services.AddSubSystem<ExceptionHandlerSubSystem>();
Services.AddSubSystem<CrashUploaderSubSystem>();
Services.AddSubSystem<SubModuleWrappers2SubSystem>();

Services.AddSingleton<ICrashUploader, BUTRCrashUploader>();
}
Expand Down Expand Up @@ -112,6 +115,14 @@ protected override void OnSubModuleLoad()
Trace.Listeners.Add(TextWriterTraceListener = new TextWriterTraceListener(new StreamWriter(new MemoryStream(), Encoding.UTF8, 1024, true)));
Trace.AutoFlush = true;
Logger.LogTrace("Added System.Diagnostics.Trace temporary listener.");

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

Logger.LogTrace("OnSubModuleLoad: Done");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class ExceptionHandlerSubSystem : ISubSystem
{
public static ExceptionHandlerSubSystem? Instance { get; private set; }

internal static readonly Harmony Harmony = new("Bannerlord.ButterLib.ExceptionHandler.BEW");
internal readonly Harmony Harmony = new("Bannerlord.ButterLib.ExceptionHandler.BEW");

public string Id => "ExceptionHandler";
public string Description => "Captures game crashes and creates reports out of them.";
Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.ButterLib/ExceptionHandler/HtmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ void AppendPatches(string name, IReadOnlyCollection<Patch> patches)
patchBuilder.Clear();
foreach (var patch in patches)
{
if (string.Equals(patch.owner, ExceptionHandlerSubSystem.Harmony.Id, StringComparison.InvariantCultureIgnoreCase))
if (string.Equals(patch.owner, ExceptionHandlerSubSystem.Instance?.Harmony.Id, StringComparison.InvariantCultureIgnoreCase))
continue;

patchBuilder.Append("<li>")
Expand Down
41 changes: 41 additions & 0 deletions src/Bannerlord.ButterLib/Helpers/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.ButterLib.Helpers
{
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);
}
}
}
}
8 changes: 4 additions & 4 deletions src/Bannerlord.ButterLib/ImplementationLoaderSubModule.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Bannerlord.BUTR.Shared.Helpers;
using Bannerlord.ButterLib.Common.Extensions;
using Bannerlord.ButterLib.Common.Helpers;
using Bannerlord.ButterLib.SubModuleWrappers;
using Bannerlord.ButterLib.SubModuleWrappers2;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -231,17 +231,17 @@ public override void OnServiceRegistration()
ServiceRegistrationWasCalled = true;

var logger = this.GetTempServiceProvider()?.GetRequiredService<ILogger<ImplementationLoaderSubModule>>() ?? NullLogger<ImplementationLoaderSubModule>.Instance;
SubModules.AddRange(LoadAllImplementations(logger).Select(x => new MBSubModuleBaseWrapper(x)).ToList());
_subModules.AddRange(LoadAllImplementations(logger).Select(x => new MBSubModuleBaseWrapper(x)).ToList());

base.OnServiceRegistration();
}

protected override void OnSubModuleLoad()
public override void OnSubModuleLoad()
{
if (!ServiceRegistrationWasCalled)
{
var logger = this.GetTempServiceProvider()?.GetRequiredService<ILogger<ImplementationLoaderSubModule>>() ?? NullLogger<ImplementationLoaderSubModule>.Instance;
SubModules.AddRange(LoadAllImplementations(logger).Select(x => new MBSubModuleBaseWrapper(x)).ToList());
_subModules.AddRange(LoadAllImplementations(logger).Select(x => new MBSubModuleBaseWrapper(x)).ToList());
}

base.OnSubModuleLoad();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;

using TaleWorlds.Core;
Expand All @@ -10,6 +11,7 @@ namespace Bannerlord.ButterLib.SubModuleWrappers
/// Wraps several <see cref="MBSubModuleBase"/> so when the game calls any method, it
/// will be passed to its children.
/// </summary>
[Obsolete("Use Bannerlord.ButterLib.SubModuleWrappers2 instead!", true)]
public class MBSubModuleBaseListWrapper : MBSubModuleBase
{
protected List<MBSubModuleBaseWrapper> SubModules { get; } = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using HarmonyLib.BUTR.Extensions;

using System;

using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;

Expand All @@ -9,6 +11,7 @@ namespace Bannerlord.ButterLib.SubModuleWrappers
/// Wraps a <see cref="MBSubModuleBase"/> so protected methods could be called
/// without a performance hit
/// </summary>
[Obsolete("Use Bannerlord.ButterLib.SubModuleWrappers2 instead!", true)]
public class MBSubModuleBaseWrapper : MBSubModuleBase
{
private delegate void OnSubModuleLoadDelegate();
Expand Down
Loading

0 comments on commit 32bd064

Please sign in to comment.