diff options
-rw-r--r-- | docs/release-notes.md | 1 | ||||
-rw-r--r-- | src/SMAPI.Mods.ErrorHandler/Patches/SaveGamePatcher.cs | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 0f144bf5..44807dcb 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,6 +3,7 @@ # Release notes ## Upcoming release * For players: + * Added automatic save recovery when custom content mods leave null objects in the save. * Added error if the wrong SMAPI bitness is installed (e.g. 32-bit SMAPI with 64-bit game). * Added error if some SMAPI files aren't updated correctly. * Added `removable` option to the `world_clear` console command (thanks to bladeoflight16!). 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; } } |