From 1a4cdd71a5d5bd69a76d67c346562fdc2ccef22b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 2 Apr 2021 21:18:18 -0400 Subject: fix asset propagation for localized movie data --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/SMAPI/Metadata') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 52da3946..83ed52ad 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -286,6 +286,10 @@ namespace StardewModdingAPI.Metadata Game1.clothingInformation = content.Load>(key); return true; + case "data\\concessions": // MovieTheater.GetConcessions + MovieTheater.ClearCachedLocalizedData(); + return true; + case "data\\concessiontastes": // MovieTheater.GetConcessionTasteForCharacter this.Reflection .GetField>(typeof(MovieTheater), "_concessionTastes") @@ -306,16 +310,9 @@ namespace StardewModdingAPI.Metadata case "data\\hairdata": // Farmer.GetHairStyleMetadataFile return this.ReloadHairData(); - case "data\\moviesreactions": // MovieTheater.GetMovieReactions - this.Reflection - .GetField>(typeof(MovieTheater), "_genericReactions") - .SetValue(content.Load>(key)); - return true; - case "data\\movies": // MovieTheater.GetMovieData - this.Reflection - .GetField>(typeof(MovieTheater), "_movieData") - .SetValue(content.Load>(key)); + case "data\\moviesreactions": // MovieTheater.GetMovieReactions + MovieTheater.ClearCachedLocalizedData(); return true; case "data\\npcdispositions": // NPC constructor -- cgit From 2b1b3b19a507876e106a444c93b4c33aca35c353 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 4 Apr 2021 11:40:08 -0400 Subject: improve error-handling during asset propagation --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/SMAPI/Metadata') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 83ed52ad..3146ceaf 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using Microsoft.Xna.Framework.Graphics; using Netcode; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.ContentManagers; using StardewModdingAPI.Framework.Reflection; using StardewModdingAPI.Toolkit.Utilities; @@ -36,15 +37,18 @@ namespace StardewModdingAPI.Metadata /// An internal content manager used only for asset propagation. See remarks on . private readonly GameContentManagerForAssetPropagation DisposableContentManager; + /// Writes messages to the console. + private readonly IMonitor Monitor; + + /// Simplifies access to private game code. + private readonly Reflector Reflection; + /// Whether to enable more aggressive memory optimizations. private readonly bool AggressiveMemoryOptimizations; /// Normalizes an asset key to match the cache key and assert that it's valid. private readonly Func AssertAndNormalizeAssetName; - /// Simplifies access to private game code. - private readonly Reflector Reflection; - /// Optimized bucket categories for batch reloading assets. private enum AssetBucket { @@ -65,12 +69,14 @@ namespace StardewModdingAPI.Metadata /// Initialize the core asset data. /// The main content manager through which to reload assets. /// An internal content manager used only for asset propagation. + /// Writes messages to the console. /// Simplifies access to private code. /// Whether to enable more aggressive memory optimizations. - public CoreAssetPropagator(LocalizedContentManager mainContent, GameContentManagerForAssetPropagation disposableContent, Reflector reflection, bool aggressiveMemoryOptimizations) + public CoreAssetPropagator(LocalizedContentManager mainContent, GameContentManagerForAssetPropagation disposableContent, IMonitor monitor, Reflector reflection, bool aggressiveMemoryOptimizations) { this.MainContentManager = mainContent; this.DisposableContentManager = disposableContent; + this.Monitor = monitor; this.Reflection = reflection; this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations; @@ -116,7 +122,17 @@ namespace StardewModdingAPI.Metadata default: foreach (var entry in bucket) { - bool changed = this.PropagateOther(entry.Key, entry.Value, ignoreWorld, out bool curChangedMapWarps); + bool changed = false; + bool curChangedMapWarps = false; + try + { + changed = this.PropagateOther(entry.Key, entry.Value, ignoreWorld, out curChangedMapWarps); + } + catch (Exception ex) + { + this.Monitor.Log($"An error occurred while propagating asset changes. Error details:\n{ex.GetLogSummary()}", LogLevel.Error); + } + propagatedAssets[entry.Key] = changed; updatedNpcWarps = updatedNpcWarps || curChangedMapWarps; } -- cgit From bca1e63c3e66011aef8cb9736e091ced05aa4992 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 4 Apr 2021 12:11:06 -0400 Subject: fix error when mod edits bundle data while a split-screen player is joining --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/SMAPI/Metadata') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 3146ceaf..623c65d5 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -274,6 +274,7 @@ namespace StardewModdingAPI.Metadata return true; case "data\\bundles": // NetWorldState constructor + if (Context.IsMainPlayer && Game1.netWorldState != null) { var bundles = this.Reflection.GetField(Game1.netWorldState.Value, "bundles").GetValue(); var rewards = this.Reflection.GetField>(Game1.netWorldState.Value, "bundleRewards").GetValue(); -- cgit