Skip to content

Commit

Permalink
Merge pull request #357 from BUTR/dev
Browse files Browse the repository at this point in the history
v2.8.15
  • Loading branch information
Aragas authored Nov 13, 2023
2 parents 9449659 + 24b6fc3 commit 6c2dd06
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 24 deletions.
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.14</Version>
<Version>2.8.15</Version>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<HarmonyExtensionsVersion>3.2.0.77</HarmonyExtensionsVersion>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override IReadOnlyList<HotKeyBase> 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

Check failure on line 59 in src/Bannerlord.ButterLib.Implementation/HotKeys/HotKeyManagerImplementation.cs

View workflow job for this annotation

GitHub Actions / Build Module

#error: 'DEFINE'

Check failure on line 59 in src/Bannerlord.ButterLib.Implementation/HotKeys/HotKeyManagerImplementation.cs

View workflow job for this annotation

GitHub Actions / Build Module

#error: 'DEFINE'

Check failure on line 59 in src/Bannerlord.ButterLib.Implementation/HotKeys/HotKeyManagerImplementation.cs

View workflow job for this annotation

GitHub Actions / Build Module

#error: 'DEFINE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 114 in src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs

View workflow job for this annotation

GitHub Actions / Build Module

#error: 'DEFINE'

Check failure on line 114 in src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs

View workflow job for this annotation

GitHub Actions / Build Module

#error: 'DEFINE'

Check failure on line 114 in src/Bannerlord.ButterLib.Implementation/ObjectSystem/MBObjectExtensionDataStore.cs

View workflow job for this annotation

GitHub Actions / Build Module

#error: 'DEFINE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ILogger<CampaignBehaviorManagerPatch>>() ?? NullLogger<CampaignBehaviorManagerPatch>.Instance;

if (____campaignBehaviorDataStore is null)
Expand All @@ -66,7 +66,7 @@ private static void OnGameLoadedPrefix(object? ____campaignBehaviorDataStore)
return;
}

if (ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IMBObjectExtensionDataStore>() is not { } mbObjectVariableStorage)
if (provider?.GetService<IMBObjectExtensionDataStore>() is not { } mbObjectVariableStorage)
{
log.LogError("{Method}: {Variable} is null", nameof(OnGameLoadedPrefix), nameof(mbObjectVariableStorage));
return;
Expand All @@ -80,7 +80,7 @@ private static void OnGameLoadedPrefix(object? ____campaignBehaviorDataStore)

if (AccessTools2.GetDelegate<LoadBehaviorDataDelegate>(____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;
}

Expand All @@ -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<ILogger<CampaignBehaviorManagerPatch>>() ?? NullLogger<CampaignBehaviorManagerPatch>.Instance;

if (____campaignBehaviorDataStore is null)
Expand All @@ -107,7 +107,7 @@ private static void OnBeforeSavePostfix(object? ____campaignBehaviorDataStore)
return;
}

if (ButterLibSubModule.Instance?.GetServiceProvider()?.GetService<IMBObjectExtensionDataStore>() is not { } mbObjectVariableStorage)
if (provider?.GetService<IMBObjectExtensionDataStore>() is not { } mbObjectVariableStorage)
{
log.LogError("{Method}: {Variable} is null", nameof(OnBeforeSavePostfix), nameof(mbObjectVariableStorage));
return;
Expand Down
14 changes: 8 additions & 6 deletions src/Bannerlord.ButterLib.Implementation/_Module/SubModule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
<Id value="$moduleid$" />
<Name value="$modulename$" />
<Version value="v$version$" />
<ModuleType value="Community"/>
<DefaultModule value="false" />
<ModuleCategory value="Singleplayer" />
<ModuleType value="Community"/>
<Url value="https://www.nexusmods.com/mountandblade2bannerlord/mods/2018" />
<UpdateInfo value="NexusMods:2018" />
<DependedModules>
<!-- Uncomment when doing ExtensionVersion > 2.0.0
<DependedModule Id="BLSE.AssemblyResolver" />
Expand All @@ -27,11 +28,11 @@
<DependedModuleMetadata id="Bannerlord.Harmony" order="LoadBeforeThis" version="v$harmonyversion$" />
<DependedModuleMetadata id="BetterExceptionWindow" order="LoadBeforeThis" 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$.*" optional="true" />
<DependedModuleMetadata id="CustomBattle" order="LoadAfterThis" version="e$gameversion$.*" optional="true" />
<DependedModuleMetadata id="Native" order="LoadAfterThis" version="$gameversion$.*" />
<DependedModuleMetadata id="SandBoxCore" order="LoadAfterThis" version="$gameversion$.*" optional="true" />
<DependedModuleMetadata id="Sandbox" order="LoadAfterThis" version="$gameversion$.*" optional="true" />
<DependedModuleMetadata id="StoryMode" order="LoadAfterThis" version="$gameversion$.*" optional="true" />
<DependedModuleMetadata id="CustomBattle" order="LoadAfterThis" version="$gameversion$.*" optional="true" />
</DependedModuleMetadatas>
<!-- Community Dependency Metadata -->
<SubModules>
Expand All @@ -53,6 +54,7 @@
<Name value="ButterLib Implementation Loader" />
<DLLName value="$moduleid$.dll" />
<SubModuleClassType value="$moduleid$.ImplementationLoaderSubModule" />
<Assemblies/>
<Tags />
</SubModule>
</SubModules>
Expand Down
3 changes: 3 additions & 0 deletions src/Bannerlord.ButterLib/ButterLibSubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ 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);
else
_logger.LogInformation("{Message}", message);
}

public override void WriteLine(string message)
public override void WriteLine(string? message)
{
if (Parse(message.AsSpan()) is { } result)
Log(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static string ChunksToString(IReadOnlyList<string> chunks)
private static string Serialize<T>(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));
Expand Down Expand Up @@ -72,8 +72,7 @@ public static bool SyncDataAsJson<T>(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);
}
Expand All @@ -87,7 +86,7 @@ public static bool SyncDataAsJson<T>(this IDataStore dataStore, string key, ref
var jsonDataChunks = Array.Empty<string>();
if (dataStore.SyncData(key, ref jsonDataChunks))
{
var (format, jsonData) = Deserialize<JsonData?>(ChunksToString(jsonDataChunks ?? Array.Empty<string>()), serializer) ?? new(-1, string.Empty);
var (format, jsonData) = JsonConvert.DeserializeObject<JsonData?>(ChunksToString(jsonDataChunks ?? Array.Empty<string>())) ?? new(-1, string.Empty);
data = format switch
{
2 => Deserialize<T>(jsonData, serializer),
Expand Down
6 changes: 2 additions & 4 deletions supported-game-versions.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6c2dd06

Please sign in to comment.