diff --git a/build/common.props b/build/common.props index e160aa43..60220daf 100644 --- a/build/common.props +++ b/build/common.props @@ -4,7 +4,7 @@ - 2.8.14 + 2.8.15 2.2.2 3.2.0.77 diff --git a/changelog.txt b/changelog.txt index bdcaf008..e5ad2e81 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,8 @@ --------------------------------------------------------------------------------------------------- +Version: 2.8.15 +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.1.6,v1.2.4 +* Fixed an issue with the new JsonSerializer overload +--------------------------------------------------------------------------------------------------- Version: 2.8.14 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.1.6,v1.2.4 * Added a SyncDataAsJson overload that takes a JsonSerializer diff --git a/src/Bannerlord.ButterLib.Implementation/HotKeys/HotKeyManagerImplementation.cs b/src/Bannerlord.ButterLib.Implementation/HotKeys/HotKeyManagerImplementation.cs index 27d649a2..f11cf93a 100644 --- a/src/Bannerlord.ButterLib.Implementation/HotKeys/HotKeyManagerImplementation.cs +++ b/src/Bannerlord.ButterLib.Implementation/HotKeys/HotKeyManagerImplementation.cs @@ -53,7 +53,7 @@ public override IReadOnlyList Build() #if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 TWHotKeyManager.RegisterInitialContexts(new[] { hotKeyCategoryContainer }, true); -#elif v120 || v121 || v122 || v123 +#elif v120 || v121 || v122 || v123 || v124 TWHotKeyManager.RegisterInitialContexts(TWHotKeyManager.GetAllCategories().ToList().Concat(new[] { hotKeyCategoryContainer }), true); #else #error DEFINE diff --git a/src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs b/src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs index 9032038d..0ac6e0b2 100755 --- a/src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs +++ b/src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs @@ -108,7 +108,7 @@ private sealed record DataKey([field: SaveableField(0)] MBGUID ObjectId, [field: #if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 private sealed class SavedTypeDefiner : SaveableCampaignBehaviorTypeDefiner -#elif v120 || v121 || v122 || v123 +#elif v120 || v121 || v122 || v123 || v124 private sealed class SavedTypeDefiner : SaveableTypeDefiner #else #error DEFINE diff --git a/src/Bannerlord.ButterLib.Implementation/ObjectSystem/Patches/CampaignBehaviorManagerPatch.cs b/src/Bannerlord.ButterLib.Implementation/ObjectSystem/Patches/CampaignBehaviorManagerPatch.cs index 8c40139f..67a9fb87 100755 --- a/src/Bannerlord.ButterLib.Implementation/ObjectSystem/Patches/CampaignBehaviorManagerPatch.cs +++ b/src/Bannerlord.ButterLib.Implementation/ObjectSystem/Patches/CampaignBehaviorManagerPatch.cs @@ -57,7 +57,7 @@ internal static void Disable(Harmony harmony) { } [MethodImpl(MethodImplOptions.NoInlining)] private static void OnGameLoadedPrefix(object? ____campaignBehaviorDataStore) { - var provider = ButterLibSubModule.Instance?.GetServiceProvider() ?? ButterLibSubModule.Instance?.GetTempServiceProvider(); + var provider = ButterLibSubModule.Instance?.GetServiceProvider(); var log = provider?.GetService>() ?? NullLogger.Instance; if (____campaignBehaviorDataStore is null) @@ -66,7 +66,7 @@ private static void OnGameLoadedPrefix(object? ____campaignBehaviorDataStore) return; } - if (ButterLibSubModule.Instance?.GetServiceProvider()?.GetService() is not { } mbObjectVariableStorage) + if (provider?.GetService() is not { } mbObjectVariableStorage) { log.LogError("{Method}: {Variable} is null", nameof(OnGameLoadedPrefix), nameof(mbObjectVariableStorage)); return; @@ -80,7 +80,7 @@ private static void OnGameLoadedPrefix(object? ____campaignBehaviorDataStore) if (AccessTools2.GetDelegate(____campaignBehaviorDataStore, ____campaignBehaviorDataStore.GetType(), "LoadBehaviorData") is not { } loadBehaviorData) { - log.LogError("{Method}: {Variable} is not a SaveBehaviorDataDelegate", nameof(OnGameLoadedPrefix), nameof(loadBehaviorData)); + log.LogError("{Method}: {Variable} is not a LoadBehaviorDataDelegate", nameof(OnGameLoadedPrefix), nameof(loadBehaviorData)); return; } @@ -98,7 +98,7 @@ private static void OnGameLoadedPrefix(object? ____campaignBehaviorDataStore) [MethodImpl(MethodImplOptions.NoInlining)] private static void OnBeforeSavePostfix(object? ____campaignBehaviorDataStore) { - var provider = ButterLibSubModule.Instance?.GetServiceProvider() ?? ButterLibSubModule.Instance?.GetTempServiceProvider(); + var provider = ButterLibSubModule.Instance?.GetServiceProvider(); var log = provider?.GetService>() ?? NullLogger.Instance; if (____campaignBehaviorDataStore is null) @@ -107,7 +107,7 @@ private static void OnBeforeSavePostfix(object? ____campaignBehaviorDataStore) return; } - if (ButterLibSubModule.Instance?.GetServiceProvider()?.GetService() is not { } mbObjectVariableStorage) + if (provider?.GetService() is not { } mbObjectVariableStorage) { log.LogError("{Method}: {Variable} is null", nameof(OnBeforeSavePostfix), nameof(mbObjectVariableStorage)); return; diff --git a/src/Bannerlord.ButterLib.Implementation/_Module/SubModule.xml b/src/Bannerlord.ButterLib.Implementation/_Module/SubModule.xml index b2dc20bb..94e57376 100644 --- a/src/Bannerlord.ButterLib.Implementation/_Module/SubModule.xml +++ b/src/Bannerlord.ButterLib.Implementation/_Module/SubModule.xml @@ -4,10 +4,11 @@ - + + @@ -53,6 +54,7 @@ + diff --git a/src/Bannerlord.ButterLib/ButterLibSubModule.cs b/src/Bannerlord.ButterLib/ButterLibSubModule.cs index 765ec964..19fac309 100644 --- a/src/Bannerlord.ButterLib/ButterLibSubModule.cs +++ b/src/Bannerlord.ButterLib/ButterLibSubModule.cs @@ -192,12 +192,15 @@ private static void ValidateLoadOrder() sb.AppendLine(report); sb.AppendLine(); sb.AppendLine(new TextObject(SMessageContinue).ToString()); +#if !NETSTANDARD2_0 + switch (System.Windows.Forms.MessageBox.Show(sb.ToString(), new TextObject(SWarningTitle).ToString(), System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning, System.Windows.Forms.MessageBoxDefaultButton.Button1, (System.Windows.Forms.MessageBoxOptions) 0x40000)) { case System.Windows.Forms.DialogResult.Yes: Environment.Exit(1); break; } +#endif } } diff --git a/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs b/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs index 9061a514..79cda695 100644 --- a/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs +++ b/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs @@ -86,7 +86,7 @@ private void Log(ParseResult result) } } - public override void Write(string message) + public override void Write(string? message) { if (Parse(message.AsSpan()) is { } result) Log(result); @@ -94,7 +94,7 @@ public override void Write(string message) _logger.LogInformation("{Message}", message); } - public override void WriteLine(string message) + public override void WriteLine(string? message) { if (Parse(message.AsSpan()) is { } result) Log(result); diff --git a/src/Bannerlord.ButterLib/SaveSystem/Extensions/IDataStoreExtensions.cs b/src/Bannerlord.ButterLib/SaveSystem/Extensions/IDataStoreExtensions.cs index 50d61b1c..2c4231c6 100644 --- a/src/Bannerlord.ButterLib/SaveSystem/Extensions/IDataStoreExtensions.cs +++ b/src/Bannerlord.ButterLib/SaveSystem/Extensions/IDataStoreExtensions.cs @@ -33,7 +33,7 @@ private static string ChunksToString(IReadOnlyList chunks) private static string Serialize(ref T? data, JsonSerializer serializer) { var sb = new StringBuilder(256); - var sw = new StringWriter(sb, CultureInfo.InvariantCulture); + using var sw = new StringWriter(sb, CultureInfo.InvariantCulture); using var jsonWriter = new JsonTextWriter(sw); jsonWriter.Formatting = Formatting.None; serializer.Serialize(jsonWriter, data, typeof(T)); @@ -72,8 +72,7 @@ public static bool SyncDataAsJson(this IDataStore dataStore, string key, ref if (dataStore.IsSaving) { var dataJson = Serialize(ref data, serializer); - var jsonData = new JsonData(2, dataJson); - var jsonDataJson = Serialize(ref jsonData, serializer); + var jsonDataJson = JsonConvert.SerializeObject(new JsonData(2, dataJson)); var chunks = ToChunks(jsonDataJson, short.MaxValue - 1024).ToArray(); return dataStore.SyncData(key, ref chunks); } @@ -87,7 +86,7 @@ public static bool SyncDataAsJson(this IDataStore dataStore, string key, ref var jsonDataChunks = Array.Empty(); if (dataStore.SyncData(key, ref jsonDataChunks)) { - var (format, jsonData) = Deserialize(ChunksToString(jsonDataChunks ?? Array.Empty()), serializer) ?? new(-1, string.Empty); + var (format, jsonData) = JsonConvert.DeserializeObject(ChunksToString(jsonDataChunks ?? Array.Empty())) ?? new(-1, string.Empty); data = format switch { 2 => Deserialize(jsonData, serializer), diff --git a/supported-game-versions.txt b/supported-game-versions.txt index 4430573f..ca8d081b 100644 --- a/supported-game-versions.txt +++ b/supported-game-versions.txt @@ -1,7 +1,5 @@ -v1.2.3 -v1.2.2 -v1.2.1 -v1.2.0 +v1.2.4 +v1.1.6 v1.1.5 v1.1.4 v1.1.3