diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-07-30 01:48:22 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-07-30 01:48:22 -0400 |
commit | dc78d944e8663c02f305bbadff1c13e8c63eb42f (patch) | |
tree | 2e18bc4766d5499cc9807d555cfb78cb850da561 /src | |
parent | 940bf922418da9ddac10c67cc5682a9bbf13c063 (diff) | |
download | SMAPI-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.cs | 13 |
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; } } |