From 47ee650f6075b0f0c847e2400063e7dd7b9995b4 Mon Sep 17 00:00:00 2001 From: DragonFire47 <46509577+DragonFire47@users.noreply.github.com> Date: Mon, 14 Nov 2022 23:17:00 -0800 Subject: [PATCH] -fixed Positioning of LoadDatas() reading closer -Added Data Corruption flags for failure to load save data --- PulsarModLoader/SaveData/SaveDataManager.cs | 35 +++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/PulsarModLoader/SaveData/SaveDataManager.cs b/PulsarModLoader/SaveData/SaveDataManager.cs index 28515d5..f7be642 100644 --- a/PulsarModLoader/SaveData/SaveDataManager.cs +++ b/PulsarModLoader/SaveData/SaveDataManager.cs @@ -91,7 +91,11 @@ public void SaveDatas(BinaryWriter writer) } catch (Exception ex) { - Logger.Info($"Failed to save a mod data.\n{ex.Message}"); + writer.Write("PMLSaveDataManager.DataCorruptionWarning"); + writer.Write("DataCorruptionWarning"); + writer.Write((uint)0); + writer.Write(0); + Logger.Info($"Failed to save a mod data.\n{ex.Message}\n"); } } writer.Write(ulong.MaxValue); @@ -117,7 +121,6 @@ public void LoadDatas(BinaryReader reader, bool ldarg3) for (int i = 0; i < count; i++) { //SaveDataHeader - Logger.Info($"{reader.BaseStream.Position}"); string harmonyIdent = reader.ReadString(); //HarmonyIdentifier string SavDatIdent = reader.ReadString(); //SaveDataIdentifier uint VersionID = reader.ReadUInt32(); //VersionID @@ -156,22 +159,22 @@ public void LoadDatas(BinaryReader reader, bool ldarg3) reader.BaseStream.Position += bytecount; missingMods += ("\n" + harmonyIdent); } + } - //Finish Reading - reader.Close(); - Logger.Info("PMLSaveManager has finished reading file"); - ReadMods = readMods; + //Finish Reading + reader.Close(); + Logger.Info("PMLSaveManager has finished reading file"); + ReadMods = readMods; - if (missingMods.Length > 0) - { - PLNetworkManager.Instance.MainMenu.AddActiveMenu(new PLErrorMessageMenu($"Warning: Found save data for following missing mods: {missingMods}")); - Logger.Info($"Warning: Found save data for following missing mods: {missingMods}"); - } - if (!string.IsNullOrEmpty(VersionMismatchedMods)) - { - PLNetworkManager.Instance.MainMenu.AddActiveMenu(new PLErrorMessageMenu($"Warning: The following mods used in this save have been updated: {VersionMismatchedMods}")); - Logger.Info($"Warning: The following mods used in this save have been updated: {VersionMismatchedMods}"); - } + if (missingMods.Length > 0) + { + PLNetworkManager.Instance.MainMenu.AddActiveMenu(new PLErrorMessageMenu($"Warning: Found save data for following missing mods: {missingMods}")); + Logger.Info($"Warning: Found save data for following missing mods: {missingMods}"); + } + if (!string.IsNullOrEmpty(VersionMismatchedMods)) + { + PLNetworkManager.Instance.MainMenu.AddActiveMenu(new PLErrorMessageMenu($"Warning: The following mods used in this save have been updated: {VersionMismatchedMods}")); + Logger.Info($"Warning: The following mods used in this save have been updated: {VersionMismatchedMods}"); } }