Skip to content

Commit

Permalink
Merge pull request #346 from BUTR/dev
Browse files Browse the repository at this point in the history
v2.8.9
  • Loading branch information
Aragas authored Jul 11, 2023
2 parents 41744b6 + 2bfd751 commit 5d75fa7
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Code Formatting
uses: butr/actions-code-format-setup@v1.5
uses: butr/actions-code-format-setup@v1
with:
workspace: "src/Bannerlord.ButterLib.sln"
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!--Development Variables-->
<PropertyGroup>
<!--Module Version-->
<Version>2.8.8</Version>
<Version>2.8.9</Version>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<HarmonyExtensionsVersion>3.2.0.77</HarmonyExtensionsVersion>
Expand Down
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---------------------------------------------------------------------------------------------------
Version: 2.8.9
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0,v1.2.1
* Fixed unintentional crash with Distance Matrix
* Further unintentional crash fixes
* Added Chinese Simplified and Japanese
---------------------------------------------------------------------------------------------------
Version: 2.8.8
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0,v1.2.1
* Support for v1.2.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public DistanceMatrixSubSystem()
public void Enable()
{
if (GameInitialized)
throw new Exception("Distance Matrix SubSystem can't be enabled after campaign start!");
return;

IsEnabled = true;
}

public void Disable()
{
if (GameInitialized)
throw new Exception("Distance Matrix SubSystem can't be disabled after campaign start!");
return;

IsEnabled = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal sealed class MBGameManagerPatch
internal static bool Enable(Harmony harmony)
{
var provider = ButterLibSubModule.Instance?.GetServiceProvider() ?? ButterLibSubModule.Instance?.GetTempServiceProvider();
_log = provider?.GetRequiredService<ILogger<ModulePatch>>() ?? NullLogger<ModulePatch>.Instance;
_log = provider?.GetService<ILogger<ModulePatch>>() ?? NullLogger<ModulePatch>.Instance;

return
CheckRequiredMethodInfos()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal sealed class ModulePatch
internal static bool Enable(Harmony harmony)
{
var provider = ButterLibSubModule.Instance?.GetServiceProvider() ?? ButterLibSubModule.Instance?.GetTempServiceProvider();
_log = provider?.GetRequiredService<ILogger<ModulePatch>>() ?? NullLogger<ModulePatch>.Instance;
_log = provider?.GetService<ILogger<ModulePatch>>() ?? NullLogger<ModulePatch>.Instance;

return CheckRequiredMethodInfos()
&& harmony.Patch(miTargetMethodUnLoad, postfix: new HarmonyMethod(miPatchMethodUnLoad)) is not null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override void RegisterEvents() { }

public override void SyncData(IDataStore dataStore)
{
var keeper = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<IMBObjectKeeper>();
var keeper = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IMBObjectKeeper>();
keeper?.Sync(dataStore);

if (dataStore.IsSaving)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal sealed class CampaignBehaviorManagerPatch
internal static void Enable(Harmony harmony)
{
var provider = ButterLibSubModule.Instance?.GetServiceProvider() ?? ButterLibSubModule.Instance?.GetTempServiceProvider();
_log = provider?.GetRequiredService<ILogger<CampaignBehaviorManagerPatch>>() ?? NullLogger<CampaignBehaviorManagerPatch>.Instance;
_log = provider?.GetService<ILogger<CampaignBehaviorManagerPatch>>() ?? NullLogger<CampaignBehaviorManagerPatch>.Instance;

if (OnGameLoadedTargetMI is null)
_log.LogError("{Method} is null", nameof(OnGameLoadedTargetMI));
Expand Down Expand Up @@ -87,7 +87,7 @@ internal static void Disable(Harmony harmony) { }
[MethodImpl(MethodImplOptions.NoInlining)]
private static void OnGameLoadedPrefix(object? ____campaignBehaviorDataStore)
{
var mbObjectVariableStorage = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<IMBObjectExtensionDataStore>();
var mbObjectVariableStorage = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IMBObjectExtensionDataStore>();

if (mbObjectVariableStorage is null)
{
Expand All @@ -114,7 +114,7 @@ private static void OnGameLoadedPrefix(object? ____campaignBehaviorDataStore)
[MethodImpl(MethodImplOptions.NoInlining)]
private static void OnBeforeSavePostfix(object? ____campaignBehaviorDataStore)
{
var mbObjectVariableStorage = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<IMBObjectExtensionDataStore>();
var mbObjectVariableStorage = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IMBObjectExtensionDataStore>();

if (mbObjectVariableStorage is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal sealed class DefinitionContextPatch
internal static bool Enable(Harmony harmony)
{
var provider = ButterLibSubModule.Instance?.GetServiceProvider() ?? ButterLibSubModule.Instance?.GetTempServiceProvider();
_log = provider?.GetRequiredService<ILogger<DefinitionContextPatch>>() ?? NullLogger<DefinitionContextPatch>.Instance;
_log = provider?.GetService<ILogger<DefinitionContextPatch>>() ?? NullLogger<DefinitionContextPatch>.Instance;

return Patches.Select(p => p.IsReady).All(ready => ready) && Patches.All(p => p.EnablePatch(harmony));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal sealed class TypeExtensionsPatch
internal static bool Enable(Harmony harmony)
{
var provider = ButterLibSubModule.Instance?.GetServiceProvider() ?? ButterLibSubModule.Instance?.GetTempServiceProvider();
_log = provider?.GetRequiredService<ILogger<TypeExtensionsPatch>>() ?? NullLogger<TypeExtensionsPatch>.Instance;
_log = provider?.GetService<ILogger<TypeExtensionsPatch>>() ?? NullLogger<TypeExtensionsPatch>.Instance;

return NotNull(TargetType, nameof(TargetType))
& NotNull(TargetMethod, nameof(TargetMethod))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,30 @@

<string id="B7bfrDNzIk" text="调试启动时禁用"/>
<string id="r3ktQzFMRz" text="调试启动时,禁用异常处理程序。"/>

<string id="jorWb502pD" text="捕捉自动生成的代码异常。(低性能)&#10;(禁用)"/>
<string id="ji1brrsEZz" text="捕捉每个 本机 -&gt; 托管 的调用。应该能捕捉每一个没有正常捕捉到的异常。可能会稍微降低整体性能。"/>

<string id="ZD69h3IpF5" text="使用原版崩溃处理程序。"/>
<string id="o0DgSNv5V1" text="使用新的 Watchdog 崩溃处理程序时,禁用 ButterLib 的和 BEW 的崩溃处理程序。如果不确定,不要启用。"/>

<string id="Ox6uK8fZWs" text="距离矩阵"/>
<string id="WQ4r2n0mYj" text="Mod 开发者功能!辅助计算地图上物体间的距离。"/>
<string id="jvV6QDc7AJ" text="热键"/>
<string id="wNNYwgUeus" text="Mod 开发者功能!方便各个 mods 创建热键。"/>
<string id="JGylAT3SrB" text="MBSubModuleBase 拓展"/>
<string id="XfveBQYVWH" text="Mod 开发者功能!引入 MBSubModuleBase-衍生抽象类,这提供了新的 SubModule 事件。"/>
<string id="IA0mVgHJgo" text="对象系统"/>
<string id="mFZTv1nwOx" text="Mod 开发者功能!"/>
<string id="66A5N9278w" text="保存系统"/>
<string id="9ybOxGpWb5" text="扩展并修复了游戏的保存系统:{NL}* 修复了因存档名相同导致的冲突;{NL}* 修复了因重复类型定义导致的存档损坏&amp;崩溃;{NL}* 增加了对更多容器类型的存档支持;{NL}这可能会改变存档文件,禁用该功能可能会导致存档无法加载!"/>
<string id="UsLlrwMTjJ" text="崩溃上传器"/>
<string id="hjeoN9NwZm" text="上传崩溃报告到 BUTR ,方便文件存储。"/>
<string id="joCJ9xpDvM" text="延迟 SubModule"/>
<string id="Gznum6kuzv" text="Mod 开发者功能!辅助开发者在 SubModule 事件之后,去跑 methods。"/>
<string id="ZypQtNNcVN" text="异常处理程序"/>
<string id="UreeIeLQYS" text="捕捉游戏崩溃,创建报告。"/>
<string id="NkAAB8EEu2" text="SubModule 包装器"/>
<string id="izmKJPjkjN" text="Mod 开发者功能!基于 Harmony patches 包装 MBSubModuleBase。"/>
</strings>
</base>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<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>
<strings>
<string id="BguqytVG3q" text="Bannerlord.ButterLib からの警告!"/>
<string id="FE6ya1gzZR" text="モジュール {REQUIRED_MODULE} が見つかりません!"/>
<string id="EvI6KPAqTT" text="互換性のないモジュール {DENIED_MODULE} が検出されました!"/>
<string id="5G9zffrgMh" text="{MODULE} が {REQUIRED_MODULE} より前に読み込まれています!{NL}{MODULE} が後に読み込まれるように確認してください!"/>
<string id="UZ8zfvudMs" text="{MODULE} が {REQUIRED_MODULE} より後に読み込まれています!{NL}{MODULE} が先に読み込まれるように確認してください!"/>
<string id="FcR4BXnhx8" text="{MODULE} は {REQUIRED_MODULE} に対して互いに矛盾するロード順が指定されています!"/>
<string id="eXs6FLm5DP" text="すぐにゲームを終了することを強く推奨します。すぐに終了しますか?"/>

<string id="JLkq0ZkOSI" text="{START}{?IS_PLURAL} と {?}{\\?}{END}"/>

<string id="B7bfrDNzIk" text="デバッガが作動しているときは無効にする"/>
<string id="r3ktQzFMRz" text="デバッガがある場合は、例外ハンドラを停止してください。"/>
</strings>
</base>
2 changes: 1 addition & 1 deletion src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class DistanceMatrix
{
private static IDistanceMatrixStatic? _staticInstance;
internal static IDistanceMatrixStatic? StaticInstance =>
_staticInstance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<IDistanceMatrixStatic>();
_staticInstance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IDistanceMatrixStatic>();


/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/Bannerlord.ButterLib/DynamicAPI/DynamicApiProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ internal static void Initialize()
{
return e.Types.Select(GetDynamicAPIClass);
}
catch (Exception)
{
return Enumerable.Empty<TypeWithAttribute?>();
}
})
.OfType<TypeWithAttribute>()
.ToDictionary(DynamicAPIClassAttributeName, x => x.Type);
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 @@ -747,7 +747,7 @@ private static string GetLogFilesListHtml(CrashReport crashReport)
var sb = new StringBuilder();

sb.AppendLine("<ul>");
foreach (var logSource in ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<IEnumerable<ILogSource>>() ?? Enumerable.Empty<ILogSource>())
foreach (var logSource in ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IEnumerable<ILogSource>>() ?? Enumerable.Empty<ILogSource>())
{
sb.Append("<li>").Append("<a>").Append(logSource.Name).Append("</a></br>").Append("<ul>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public async void CopyAsHTML()

public async void UploadReport()
{
var crashUploader = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<ICrashUploader>();
var crashUploader = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<ICrashUploader>();
if (crashUploader is null)
{
MessageBox.Show("Failed to get the crash uploader!", "Error!");
Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.ButterLib/Extensions/CampaignExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public static partial class CampaignExtensions
{
private static ICampaignExtensions? _instance;
private static ICampaignExtensions? Instance =>
_instance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<ICampaignExtensions>();
_instance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<ICampaignExtensions>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public static IServiceCollection AddSubSystem<TImplementation>(this IServiceColl
where TImplementation : class, ISubSystem, new()
{
var instance = new TImplementation();
services.AddSingleton<TImplementation>(sp => instance);
services.AddSingleton<ISubSystem>(sp => sp.GetRequiredService<TImplementation>());
services.AddSingleton<TImplementation>(_ => instance);
services.AddSingleton<ISubSystem>(sp => sp.GetService<TImplementation>());
return services;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.ButterLib/HotKeys/HotKeyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class HotKeyManager
{
private static IHotKeyManagerStatic? _staticInstance;
internal static IHotKeyManagerStatic? StaticInstance =>
_staticInstance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<IHotKeyManagerStatic>();
_staticInstance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IHotKeyManagerStatic>();

/// <summary>
/// The available categories in the main menu for your hotkey to appear under.
Expand Down
4 changes: 2 additions & 2 deletions src/Bannerlord.ButterLib/ImplementationLoaderSubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public override void OnServiceRegistration()
{
ServiceRegistrationWasCalled = true;

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

base.OnServiceRegistration();
Expand All @@ -240,7 +240,7 @@ public override void OnSubModuleLoad()
{
if (!ServiceRegistrationWasCalled)
{
var logger = this.GetTempServiceProvider()?.GetRequiredService<ILogger<ImplementationLoaderSubModule>>() ?? NullLogger<ImplementationLoaderSubModule>.Instance;
var logger = this.GetTempServiceProvider()?.GetService<ILogger<ImplementationLoaderSubModule>>() ?? NullLogger<ImplementationLoaderSubModule>.Instance;
_subModules.AddRange(LoadAllImplementations(logger).Select(x => new MBSubModuleBaseWrapper(x)).ToList());
}

Expand Down
2 changes: 2 additions & 0 deletions src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ private record ParseResult
public string Message { get; init; } = default!;
}

// There are some cases when System.Numerics.Vectors is not found
// BLSE fixes that, but we might revert to string handling before BLSE is mandatory
private static ParseResult? Parse(ReadOnlySpan<char> str)
{
if (str.IndexOf(':') is var logLevelIdx && logLevelIdx == -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class MBObjectBaseExtensions
private static IMBObjectExtensionDataStore? _instance;

private static IMBObjectExtensionDataStore? Instance =>
_instance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<IMBObjectExtensionDataStore>();
_instance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IMBObjectExtensionDataStore>();

internal static void OnGameEnd() => _instance = null;

Expand Down
4 changes: 2 additions & 2 deletions src/Bannerlord.ButterLib/SaveSystem/MBObjectBaseConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer
{
if (value is MBObjectBase mbObject)
{
var keeper = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<IMBObjectKeeper>();
var keeper = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IMBObjectKeeper>();
keeper?.Keep(mbObject);

serializer.Serialize(writer, mbObject.Id);
Expand All @@ -33,7 +33,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer
{
if (serializer.Deserialize<MBGUID?>(reader) is { } mbguid)
{
var finder = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService<IMBObjectFinder>();
var finder = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IMBObjectFinder>();
return finder?.Find(mbguid, objectType);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void ICampaignExtensions_Test()
{
var serviceProvider = ButterLibSubModule.Instance!.GetServiceProvider()!;

var campaignExtensions = serviceProvider.GetRequiredService<ICampaignExtensions>();
var campaignExtensions = serviceProvider.GetService<ICampaignExtensions>();
Assert.NotNull(campaignExtensions);
Assert.True(campaignExtensions is CampaignExtensionsImplementation);
}
Expand All @@ -125,7 +125,7 @@ public void DistanceMatrix_Test()
var serviceProvider = ButterLibSubModule.Instance!.GetServiceProvider()!;
var scope = serviceProvider.CreateScope();

var distanceMatrix = scope.ServiceProvider.GetRequiredService<DistanceMatrix<Settlement>>();
var distanceMatrix = scope.ServiceProvider.GetService<DistanceMatrix<Settlement>>();
Assert.NotNull(distanceMatrix);
Assert.True(distanceMatrix.GetType().GetGenericTypeDefinition() == typeof(DistanceMatrixImplementation<>));
Assert.AreEqual(distanceMatrix.GetType().GenericTypeArguments, new[] { typeof(Settlement) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ internal sealed class TestCampaignBehavior : CampaignBehaviorBase

public TestCampaignBehavior()
{
_log = this.GetServiceProvider()?.GetRequiredService<ILogger<TestCampaignBehavior>>()
?? NullLogger<TestCampaignBehavior>.Instance;
_log = this.GetServiceProvider()?.GetService<ILogger<TestCampaignBehavior>>() ?? NullLogger<TestCampaignBehavior>.Instance;

_log.LogTrace("{Behavior} initialized", nameof(TestCampaignBehavior));
}
Expand Down

0 comments on commit 5d75fa7

Please sign in to comment.