From 215574f2b9bb18f98bd9ce208c58e741384aada6 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 8 Feb 2019 18:19:28 -0500 Subject: [PATCH] fix error when swapping maps mid-session for a location with interior doors --- docs/release-notes.md | 1 + src/SMAPI/Metadata/CoreAssetPropagator.cs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index e6ad4c63..e0bf3935 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -19,6 +19,7 @@ * Asset changes are now propagated into the parsed save being loaded if applicable. * Added locale to context trace logs. * Fixed error loading custom map tilesheets in some cases. + * Fixed error when swapping maps mid-session for a location with interior doors. * Fixed `Constants.SaveFolderName` and `CurrentSavePath` not available during early load stages when using `Specialised.LoadStageChanged` event. * Fixed `LoadStage.SaveParsed` raised before the parsed save data is available. * Fixed 'unknown mod' deprecation warnings showing the wrong stack trace. diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 53d930f5..a64dc89b 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.Xna.Framework; +using System.Reflection; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.Reflection; using StardewValley; @@ -99,8 +99,21 @@ namespace StardewModdingAPI.Metadata { if (!string.IsNullOrWhiteSpace(location.mapPath.Value) && this.GetNormalisedPath(location.mapPath.Value) == key) { + // reload map data this.Reflection.GetMethod(location, "reloadMap").Invoke(); this.Reflection.GetMethod(location, "updateWarps").Invoke(); + + // reload doors + { + Type interiorDoorDictType = Type.GetType($"StardewValley.InteriorDoorDictionary, {Constants.GameAssemblyName}", throwOnError: true); + ConstructorInfo constructor = interiorDoorDictType.GetConstructor(new[] { typeof(GameLocation) }); + if (constructor == null) + throw new InvalidOperationException("Can't reset location doors: constructor not found for InteriorDoorDictionary type."); + object instance = constructor.Invoke(new object[] { location }); + + this.Reflection.GetField(location, "interiorDoors").SetValue(instance); + } + anyChanged = true; } }