summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-30 01:48:22 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-30 01:48:22 -0400
commitdc78d944e8663c02f305bbadff1c13e8c63eb42f (patch)
tree2e18bc4766d5499cc9807d555cfb78cb850da561 /src
parent940bf922418da9ddac10c67cc5682a9bbf13c063 (diff)
downloadSMAPI-dc78d944e8663c02f305bbadff1c13e8c63eb42f.tar.gz
SMAPI-dc78d944e8663c02f305bbadff1c13e8c63eb42f.tar.bz2
SMAPI-dc78d944e8663c02f305bbadff1c13e8c63eb42f.zip
recover save when mods leave null objects in the world
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs b/src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs
index 635a01c1..2a43cb10 100644
--- a/src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs
+++ b/src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs
@@ -8,6 +8,7 @@ using StardewModdingAPI.Internal.Patching;
using StardewValley;
using StardewValley.Buildings;
using StardewValley.Locations;
+using SObject = StardewValley.Object;
namespace StardewModdingAPI.Mods.ErrorHandler.Patches
{
@@ -126,6 +127,18 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
}
}
+ // check objects
+ foreach (var pair in location.objects.Pairs.ToArray())
+ {
+ // SpaceCore can leave null values when removing its custom content
+ if (pair.Value == null)
+ {
+ location.Objects.Remove(pair.Key);
+ SaveGamePatcher.Monitor.Log($"Removed invalid null object in {location.Name} ({pair.Key}) to avoid a crash when loading save '{Constants.SaveFolderName}'. (Did you remove a custom item mod?)", LogLevel.Warn);
+ removedAny = true;
+ }
+ }
+
return removedAny;
}
}