Skip to content

Commit

Permalink
-fixed Positioning of LoadDatas() reading closer
Browse files Browse the repository at this point in the history
-Added Data Corruption flags for failure to load save data
  • Loading branch information
Nagord committed Nov 15, 2022
1 parent b24cc9b commit 47ee650
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions PulsarModLoader/SaveData/SaveDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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}");
}
}

Expand Down

0 comments on commit 47ee650

Please sign in to comment.