summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-09 18:52:21 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-09 18:52:21 -0500
commit441ded8c9a9e3dea39cb180df429d3fcc5f3cc96 (patch)
tree7bcbb78b60fbff28a65dd806ee9c5fb6cb3cfb31 /src/SMAPI
parent13ed6decf55a7fd72c34b965397011d3012cb9cc (diff)
downloadSMAPI-441ded8c9a9e3dea39cb180df429d3fcc5f3cc96.tar.gz
SMAPI-441ded8c9a9e3dea39cb180df429d3fcc5f3cc96.tar.bz2
SMAPI-441ded8c9a9e3dea39cb180df429d3fcc5f3cc96.zip
fix error when a mod makes invalid changes to an NPC schedule
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/ContentCoordinator.cs2
-rw-r--r--src/SMAPI/Metadata/CoreAssetPropagator.cs12
2 files changed, 12 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs
index 08a32a9b..7e256939 100644
--- a/src/SMAPI/Framework/ContentCoordinator.cs
+++ b/src/SMAPI/Framework/ContentCoordinator.cs
@@ -81,7 +81,7 @@ namespace StardewModdingAPI.Framework
this.ContentManagers.Add(
this.MainContentManager = new GameContentManager("Game1.content", serviceProvider, rootDirectory, currentCulture, this, monitor, reflection, this.OnDisposing)
);
- this.CoreAssets = new CoreAssetPropagator(this.MainContentManager.AssertAndNormaliseAssetName, reflection);
+ this.CoreAssets = new CoreAssetPropagator(this.MainContentManager.AssertAndNormaliseAssetName, reflection, monitor);
}
/// <summary>Get a new content manager which handles reading files from the game content folder with support for interception.</summary>
diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs
index 90629d7f..4667be7e 100644
--- a/src/SMAPI/Metadata/CoreAssetPropagator.cs
+++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs
@@ -31,6 +31,9 @@ namespace StardewModdingAPI.Metadata
/// <summary>Simplifies access to private game code.</summary>
private readonly Reflector Reflection;
+ /// <summary>Encapsulates monitoring and logging.</summary>
+ private readonly IMonitor Monitor;
+
/*********
** Public methods
@@ -38,10 +41,12 @@ namespace StardewModdingAPI.Metadata
/// <summary>Initialise the core asset data.</summary>
/// <param name="getNormalisedPath">Normalises an asset key to match the cache key.</param>
/// <param name="reflection">Simplifies access to private code.</param>
- public CoreAssetPropagator(Func<string, string> getNormalisedPath, Reflector reflection)
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ public CoreAssetPropagator(Func<string, string> getNormalisedPath, Reflector reflection, IMonitor monitor)
{
this.GetNormalisedPath = getNormalisedPath;
this.Reflection = reflection;
+ this.Monitor = monitor;
}
/// <summary>Reload one of the game's core assets (if applicable).</summary>
@@ -619,6 +624,11 @@ namespace StardewModdingAPI.Metadata
{
// reload schedule
villager.Schedule = villager.getSchedule(Game1.dayOfMonth);
+ if (villager.Schedule == null)
+ {
+ this.Monitor.Log($"A mod set an invalid schedule for {villager.Name ?? key}, so the NPC may not behave correctly.", LogLevel.Warn);
+ return true;
+ }
// switch to new schedule if needed
int lastScheduleTime = villager.Schedule.Keys.Where(p => p <= Game1.timeOfDay).OrderByDescending(p => p).FirstOrDefault();