diff --git a/.github/workflows/dotnet-format-daily.yml b/.github/workflows/dotnet-format-daily.yml index 82ce206e..b68c1fe3 100644 --- a/.github/workflows/dotnet-format-daily.yml +++ b/.github/workflows/dotnet-format-daily.yml @@ -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 }} diff --git a/build/common.props b/build/common.props index 8ef0d87e..f1dc52d7 100644 --- a/build/common.props +++ b/build/common.props @@ -4,7 +4,7 @@ - 2.8.8 + 2.8.9 2.2.2 3.2.0.77 diff --git a/changelog.txt b/changelog.txt index 73b81af6..74ccc082 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/src/Bannerlord.ButterLib.Implementation/DistanceMatrix/DistanceMatrixSubSystem.cs b/src/Bannerlord.ButterLib.Implementation/DistanceMatrix/DistanceMatrixSubSystem.cs index ded711cc..58a4f5b5 100644 --- a/src/Bannerlord.ButterLib.Implementation/DistanceMatrix/DistanceMatrixSubSystem.cs +++ b/src/Bannerlord.ButterLib.Implementation/DistanceMatrix/DistanceMatrixSubSystem.cs @@ -24,7 +24,7 @@ public DistanceMatrixSubSystem() public void Enable() { if (GameInitialized) - throw new Exception("Distance Matrix SubSystem can't be enabled after campaign start!"); + return; IsEnabled = true; } @@ -32,7 +32,7 @@ public void Enable() public void Disable() { if (GameInitialized) - throw new Exception("Distance Matrix SubSystem can't be disabled after campaign start!"); + return; IsEnabled = false; } diff --git a/src/Bannerlord.ButterLib.Implementation/MBSubModuleBaseExtended/Patches/MBGameManagerPatch.cs b/src/Bannerlord.ButterLib.Implementation/MBSubModuleBaseExtended/Patches/MBGameManagerPatch.cs index 1487a6c1..b2c4b3ba 100644 --- a/src/Bannerlord.ButterLib.Implementation/MBSubModuleBaseExtended/Patches/MBGameManagerPatch.cs +++ b/src/Bannerlord.ButterLib.Implementation/MBSubModuleBaseExtended/Patches/MBGameManagerPatch.cs @@ -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>() ?? NullLogger.Instance; + _log = provider?.GetService>() ?? NullLogger.Instance; return CheckRequiredMethodInfos() diff --git a/src/Bannerlord.ButterLib.Implementation/MBSubModuleBaseExtended/Patches/ModulePatch.cs b/src/Bannerlord.ButterLib.Implementation/MBSubModuleBaseExtended/Patches/ModulePatch.cs index 7c450e1e..1b52dd4f 100644 --- a/src/Bannerlord.ButterLib.Implementation/MBSubModuleBaseExtended/Patches/ModulePatch.cs +++ b/src/Bannerlord.ButterLib.Implementation/MBSubModuleBaseExtended/Patches/ModulePatch.cs @@ -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>() ?? NullLogger.Instance; + _log = provider?.GetService>() ?? NullLogger.Instance; return CheckRequiredMethodInfos() && harmony.Patch(miTargetMethodUnLoad, postfix: new HarmonyMethod(miPatchMethodUnLoad)) is not null diff --git a/src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs b/src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs index 5b885942..e23291aa 100755 --- a/src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs +++ b/src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs @@ -22,7 +22,7 @@ public override void RegisterEvents() { } public override void SyncData(IDataStore dataStore) { - var keeper = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService(); + var keeper = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); keeper?.Sync(dataStore); if (dataStore.IsSaving) diff --git a/src/Bannerlord.ButterLib.Implementation/ObjectSystem/Patches/CampaignBehaviorManagerPatch.cs b/src/Bannerlord.ButterLib.Implementation/ObjectSystem/Patches/CampaignBehaviorManagerPatch.cs index f38c9cc7..fb10cc00 100755 --- a/src/Bannerlord.ButterLib.Implementation/ObjectSystem/Patches/CampaignBehaviorManagerPatch.cs +++ b/src/Bannerlord.ButterLib.Implementation/ObjectSystem/Patches/CampaignBehaviorManagerPatch.cs @@ -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>() ?? NullLogger.Instance; + _log = provider?.GetService>() ?? NullLogger.Instance; if (OnGameLoadedTargetMI is null) _log.LogError("{Method} is null", nameof(OnGameLoadedTargetMI)); @@ -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(); + var mbObjectVariableStorage = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); if (mbObjectVariableStorage is null) { @@ -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(); + var mbObjectVariableStorage = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); if (mbObjectVariableStorage is null) { diff --git a/src/Bannerlord.ButterLib.Implementation/SaveSystem/Patches/DefinitionContextPatch.cs b/src/Bannerlord.ButterLib.Implementation/SaveSystem/Patches/DefinitionContextPatch.cs index 1c5c849d..827bf90d 100644 --- a/src/Bannerlord.ButterLib.Implementation/SaveSystem/Patches/DefinitionContextPatch.cs +++ b/src/Bannerlord.ButterLib.Implementation/SaveSystem/Patches/DefinitionContextPatch.cs @@ -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>() ?? NullLogger.Instance; + _log = provider?.GetService>() ?? NullLogger.Instance; return Patches.Select(p => p.IsReady).All(ready => ready) && Patches.All(p => p.EnablePatch(harmony)); } diff --git a/src/Bannerlord.ButterLib.Implementation/SaveSystem/Patches/TypeExtensionsPatch.cs b/src/Bannerlord.ButterLib.Implementation/SaveSystem/Patches/TypeExtensionsPatch.cs index b8705114..6fb66d94 100644 --- a/src/Bannerlord.ButterLib.Implementation/SaveSystem/Patches/TypeExtensionsPatch.cs +++ b/src/Bannerlord.ButterLib.Implementation/SaveSystem/Patches/TypeExtensionsPatch.cs @@ -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>() ?? NullLogger.Instance; + _log = provider?.GetService>() ?? NullLogger.Instance; return NotNull(TargetType, nameof(TargetType)) & NotNull(TargetMethod, nameof(TargetMethod)) diff --git a/src/Bannerlord.ButterLib.Implementation/_Module/ModuleData/Languages/CNs/sta_strings.xml b/src/Bannerlord.ButterLib.Implementation/_Module/ModuleData/Languages/CNs/sta_strings.xml index a21e1a63..47174d4d 100644 --- a/src/Bannerlord.ButterLib.Implementation/_Module/ModuleData/Languages/CNs/sta_strings.xml +++ b/src/Bannerlord.ButterLib.Implementation/_Module/ModuleData/Languages/CNs/sta_strings.xml @@ -16,5 +16,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Bannerlord.ButterLib.Implementation/_Module/ModuleData/Languages/JP/sta_strings.xml b/src/Bannerlord.ButterLib.Implementation/_Module/ModuleData/Languages/JP/sta_strings.xml new file mode 100644 index 00000000..33b4d512 --- /dev/null +++ b/src/Bannerlord.ButterLib.Implementation/_Module/ModuleData/Languages/JP/sta_strings.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrix.cs b/src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrix.cs index 0f27945d..a4486307 100644 --- a/src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrix.cs +++ b/src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrix.cs @@ -20,7 +20,7 @@ public abstract class DistanceMatrix { private static IDistanceMatrixStatic? _staticInstance; internal static IDistanceMatrixStatic? StaticInstance => - _staticInstance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService(); + _staticInstance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); /// diff --git a/src/Bannerlord.ButterLib/DynamicAPI/DynamicApiProvider.cs b/src/Bannerlord.ButterLib/DynamicAPI/DynamicApiProvider.cs index 03b2682b..651fb330 100644 --- a/src/Bannerlord.ButterLib/DynamicAPI/DynamicApiProvider.cs +++ b/src/Bannerlord.ButterLib/DynamicAPI/DynamicApiProvider.cs @@ -102,6 +102,10 @@ internal static void Initialize() { return e.Types.Select(GetDynamicAPIClass); } + catch (Exception) + { + return Enumerable.Empty(); + } }) .OfType() .ToDictionary(DynamicAPIClassAttributeName, x => x.Type); diff --git a/src/Bannerlord.ButterLib/ExceptionHandler/HtmlBuilder.cs b/src/Bannerlord.ButterLib/ExceptionHandler/HtmlBuilder.cs index 3b4edaf0..dd6fcd7d 100644 --- a/src/Bannerlord.ButterLib/ExceptionHandler/HtmlBuilder.cs +++ b/src/Bannerlord.ButterLib/ExceptionHandler/HtmlBuilder.cs @@ -747,7 +747,7 @@ private static string GetLogFilesListHtml(CrashReport crashReport) var sb = new StringBuilder(); sb.AppendLine("
    "); - foreach (var logSource in ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService>() ?? Enumerable.Empty()) + foreach (var logSource in ButterLibSubModule.Instance?.GetServiceProvider()?.GetService>() ?? Enumerable.Empty()) { sb.Append("
  • ").Append("").Append(logSource.Name).Append("
    ").Append("
      "); diff --git a/src/Bannerlord.ButterLib/ExceptionHandler/WinForms/HtmlCrashReportForm.cs b/src/Bannerlord.ButterLib/ExceptionHandler/WinForms/HtmlCrashReportForm.cs index 8ea51eff..3656fe25 100644 --- a/src/Bannerlord.ButterLib/ExceptionHandler/WinForms/HtmlCrashReportForm.cs +++ b/src/Bannerlord.ButterLib/ExceptionHandler/WinForms/HtmlCrashReportForm.cs @@ -217,7 +217,7 @@ public async void CopyAsHTML() public async void UploadReport() { - var crashUploader = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService(); + var crashUploader = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); if (crashUploader is null) { MessageBox.Show("Failed to get the crash uploader!", "Error!"); diff --git a/src/Bannerlord.ButterLib/Extensions/CampaignExtensions.cs b/src/Bannerlord.ButterLib/Extensions/CampaignExtensions.cs index 1312df6c..7d8457b8 100644 --- a/src/Bannerlord.ButterLib/Extensions/CampaignExtensions.cs +++ b/src/Bannerlord.ButterLib/Extensions/CampaignExtensions.cs @@ -18,6 +18,6 @@ public static partial class CampaignExtensions { private static ICampaignExtensions? _instance; private static ICampaignExtensions? Instance => - _instance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService(); + _instance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); } } \ No newline at end of file diff --git a/src/Bannerlord.ButterLib/Extensions/DependencyInjectionExtensions.cs b/src/Bannerlord.ButterLib/Extensions/DependencyInjectionExtensions.cs index e9c8f770..44544c7a 100644 --- a/src/Bannerlord.ButterLib/Extensions/DependencyInjectionExtensions.cs +++ b/src/Bannerlord.ButterLib/Extensions/DependencyInjectionExtensions.cs @@ -147,8 +147,8 @@ public static IServiceCollection AddSubSystem(this IServiceColl where TImplementation : class, ISubSystem, new() { var instance = new TImplementation(); - services.AddSingleton(sp => instance); - services.AddSingleton(sp => sp.GetRequiredService()); + services.AddSingleton(_ => instance); + services.AddSingleton(sp => sp.GetService()); return services; } diff --git a/src/Bannerlord.ButterLib/HotKeys/HotKeyManager.cs b/src/Bannerlord.ButterLib/HotKeys/HotKeyManager.cs index 5bb57741..3e123866 100644 --- a/src/Bannerlord.ButterLib/HotKeys/HotKeyManager.cs +++ b/src/Bannerlord.ButterLib/HotKeys/HotKeyManager.cs @@ -22,7 +22,7 @@ public abstract class HotKeyManager { private static IHotKeyManagerStatic? _staticInstance; internal static IHotKeyManagerStatic? StaticInstance => - _staticInstance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService(); + _staticInstance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); /// /// The available categories in the main menu for your hotkey to appear under. diff --git a/src/Bannerlord.ButterLib/ImplementationLoaderSubModule.cs b/src/Bannerlord.ButterLib/ImplementationLoaderSubModule.cs index 4514c7d3..dbe6a944 100644 --- a/src/Bannerlord.ButterLib/ImplementationLoaderSubModule.cs +++ b/src/Bannerlord.ButterLib/ImplementationLoaderSubModule.cs @@ -230,7 +230,7 @@ public override void OnServiceRegistration() { ServiceRegistrationWasCalled = true; - var logger = this.GetTempServiceProvider()?.GetRequiredService>() ?? NullLogger.Instance; + var logger = this.GetTempServiceProvider()?.GetService>() ?? NullLogger.Instance; _subModules.AddRange(LoadAllImplementations(logger).Select(x => new MBSubModuleBaseWrapper(x)).ToList()); base.OnServiceRegistration(); @@ -240,7 +240,7 @@ public override void OnSubModuleLoad() { if (!ServiceRegistrationWasCalled) { - var logger = this.GetTempServiceProvider()?.GetRequiredService>() ?? NullLogger.Instance; + var logger = this.GetTempServiceProvider()?.GetService>() ?? NullLogger.Instance; _subModules.AddRange(LoadAllImplementations(logger).Select(x => new MBSubModuleBaseWrapper(x)).ToList()); } diff --git a/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs b/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs index 50a9482d..9061a514 100644 --- a/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs +++ b/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs @@ -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 str) { if (str.IndexOf(':') is var logLevelIdx && logLevelIdx == -1) diff --git a/src/Bannerlord.ButterLib/ObjectSystem/Extensions/MBObjectBaseExtensions.cs b/src/Bannerlord.ButterLib/ObjectSystem/Extensions/MBObjectBaseExtensions.cs index ed6e82e2..347faef6 100755 --- a/src/Bannerlord.ButterLib/ObjectSystem/Extensions/MBObjectBaseExtensions.cs +++ b/src/Bannerlord.ButterLib/ObjectSystem/Extensions/MBObjectBaseExtensions.cs @@ -16,7 +16,7 @@ public static class MBObjectBaseExtensions private static IMBObjectExtensionDataStore? _instance; private static IMBObjectExtensionDataStore? Instance => - _instance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService(); + _instance ??= ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); internal static void OnGameEnd() => _instance = null; diff --git a/src/Bannerlord.ButterLib/SaveSystem/MBObjectBaseConverter.cs b/src/Bannerlord.ButterLib/SaveSystem/MBObjectBaseConverter.cs index 21e40f44..0218afa4 100644 --- a/src/Bannerlord.ButterLib/SaveSystem/MBObjectBaseConverter.cs +++ b/src/Bannerlord.ButterLib/SaveSystem/MBObjectBaseConverter.cs @@ -19,7 +19,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer { if (value is MBObjectBase mbObject) { - var keeper = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService(); + var keeper = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); keeper?.Keep(mbObject); serializer.Serialize(writer, mbObject.Id); @@ -33,7 +33,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer { if (serializer.Deserialize(reader) is { } mbguid) { - var finder = ButterLibSubModule.Instance?.GetServiceProvider()?.GetRequiredService(); + var finder = ButterLibSubModule.Instance?.GetServiceProvider()?.GetService(); return finder?.Find(mbguid, objectType); } return null; diff --git a/tests/Bannerlord.ButterLib.Implementation.Tests/DependencyInjectionTests.cs b/tests/Bannerlord.ButterLib.Implementation.Tests/DependencyInjectionTests.cs index 5504a861..f8f5720c 100644 --- a/tests/Bannerlord.ButterLib.Implementation.Tests/DependencyInjectionTests.cs +++ b/tests/Bannerlord.ButterLib.Implementation.Tests/DependencyInjectionTests.cs @@ -109,7 +109,7 @@ public void ICampaignExtensions_Test() { var serviceProvider = ButterLibSubModule.Instance!.GetServiceProvider()!; - var campaignExtensions = serviceProvider.GetRequiredService(); + var campaignExtensions = serviceProvider.GetService(); Assert.NotNull(campaignExtensions); Assert.True(campaignExtensions is CampaignExtensionsImplementation); } @@ -125,7 +125,7 @@ public void DistanceMatrix_Test() var serviceProvider = ButterLibSubModule.Instance!.GetServiceProvider()!; var scope = serviceProvider.CreateScope(); - var distanceMatrix = scope.ServiceProvider.GetRequiredService>(); + var distanceMatrix = scope.ServiceProvider.GetService>(); Assert.NotNull(distanceMatrix); Assert.True(distanceMatrix.GetType().GetGenericTypeDefinition() == typeof(DistanceMatrixImplementation<>)); Assert.AreEqual(distanceMatrix.GetType().GenericTypeArguments, new[] { typeof(Settlement) }); diff --git a/tests/Bannerlord.ButterLib.ObjectSystem.Test/TestCampaignBehavior.cs b/tests/Bannerlord.ButterLib.ObjectSystem.Test/TestCampaignBehavior.cs index 4c20dce9..84adb6e0 100644 --- a/tests/Bannerlord.ButterLib.ObjectSystem.Test/TestCampaignBehavior.cs +++ b/tests/Bannerlord.ButterLib.ObjectSystem.Test/TestCampaignBehavior.cs @@ -30,8 +30,7 @@ internal sealed class TestCampaignBehavior : CampaignBehaviorBase public TestCampaignBehavior() { - _log = this.GetServiceProvider()?.GetRequiredService>() - ?? NullLogger.Instance; + _log = this.GetServiceProvider()?.GetService>() ?? NullLogger.Instance; _log.LogTrace("{Behavior} initialized", nameof(TestCampaignBehavior)); }