From ddd119e60339d256fb2e43fac0ef08165ca59c10 Mon Sep 17 00:00:00 2001 From: Conqu3red Date: Fri, 26 Mar 2021 18:50:34 +0000 Subject: [PATCH] fixed layout saving --- PolyTechMain.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/PolyTechMain.cs b/PolyTechMain.cs index aa5379b..907f955 100644 --- a/PolyTechMain.cs +++ b/PolyTechMain.cs @@ -24,7 +24,7 @@ public class PolyTechMain : PolyTechMod public new const string PluginGuid = "polytech.polytechframework", PluginName = "PolyTech Framework", - PluginVersion = "0.9.4"; + PluginVersion = "0.9.5"; private static BindingList noncheatMods = new BindingList { }, cheatMods = new BindingList { }; @@ -707,7 +707,7 @@ static void patchSerializerOne(SandboxLayoutData __instance, List bytes) { ptfInstance.ptfLogger.LogMessage($"Layout pre version: {__instance.m_Version}"); if (GameStateManager.GetState() != GameState.BUILD && GameStateManager.GetState() != GameState.SANDBOX) return; - if (noncheatMods.Where(x => x.shouldSaveData).Count() + cheatMods.Where(x => x.shouldSaveData).Count() == 0) return; + if (noncheatMods.Where(x => x.shouldSaveData).Count() + cheatMods.Where(x => x.isEnabled).Count() == 0) return; __instance.m_Version *= -1; //PopUpMessage.Display("You have cheat mods enabled, do you want to store them?\n(This will make the layout incompatible with vanilla PB2)", yes, no); ptfInstance.ptfLogger.LogMessage($"Version after cheat question: {__instance.m_Version.ToString()}"); @@ -732,7 +732,10 @@ private static void patchSerializerTwo(SandboxLayoutData __instance, List if (__instance.m_Version >= 0) return; bytes.AddRange(ByteSerializer.SerializeStrings(mods)); - bytes.AddRange(ByteSerializer.SerializeInt(modData.Count)); + // add an int indicating the number of mods that will save binary data + int modsSavingBinary = noncheatMods.Where(x => x.shouldSaveData).Count() + cheatMods.Where(x => x.shouldSaveData).Count(); + bytes.AddRange(ByteSerializer.SerializeInt(modsSavingBinary)); + foreach (var mod in noncheatMods){ if (mod.isEnabled && mod.shouldSaveData){ bytes.AddRange(ByteSerializer.SerializeString(