From e16584527c9467c77f56cc2857279d550feae6ad Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 3 Dec 2018 19:41:47 -0500 Subject: [PATCH] fix changes to save handling The postfix for an enumerable method is raised when the enumerable is returned, not when it finishes enumerating. --- src/SMAPI/Framework/SCore.cs | 2 +- src/SMAPI/Framework/SGame.cs | 19 ++++++++++++------- src/SMAPI/Patches/SaveGamePatch.cs | 17 +---------------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 89f2d6c4..81b4e99e 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -282,7 +282,7 @@ namespace StardewModdingAPI.Framework // apply game patches new GamePatcher(this.Monitor).Apply( new DialogueErrorPatch(this.MonitorForGame, this.Reflection), - new SaveGamePatch(onSaving: this.GameInstance.OnSaving, onSaved: this.GameInstance.OnSaved) + new SaveGamePatch(onSaving: this.GameInstance.OnSaving) ); // start game diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index ebf2872d..a0f611f1 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -199,7 +199,7 @@ namespace StardewModdingAPI.Framework } /// A callback invoked before runs. - protected void OnNewDayAfterFade() + private void OnNewDayAfterFade() { this.Events.DayEnding.RaiseEmpty(); } @@ -229,7 +229,7 @@ namespace StardewModdingAPI.Framework } /// A callback invoked after runs. - internal void OnSaved() + private void OnSaved() { // reset flags this.IsBetweenCreateEvents = false; @@ -420,13 +420,18 @@ namespace StardewModdingAPI.Framework // is in progress. if (this.IsBetweenCreateEvents || this.IsBetweenSaveEvents) { - this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed)); - base.Update(gameTime); - this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed)); + if (!Context.IsSaving) + this.OnSaved(); + else + { + this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed)); + base.Update(gameTime); + this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed)); #if !SMAPI_3_0_STRICT - this.Events.Legacy_BeforeCreateSave.Raise(); + this.Events.Legacy_BeforeCreateSave.Raise(); #endif - return; + return; + } } /********* diff --git a/src/SMAPI/Patches/SaveGamePatch.cs b/src/SMAPI/Patches/SaveGamePatch.cs index 96b23d71..1e6f414a 100644 --- a/src/SMAPI/Patches/SaveGamePatch.cs +++ b/src/SMAPI/Patches/SaveGamePatch.cs @@ -16,9 +16,6 @@ namespace StardewModdingAPI.Patches /// A callback to invoke before runs. private static Action OnSaving; - /// A callback to invoke before runs. - private static Action OnSaved; - /********* ** Accessors @@ -32,11 +29,9 @@ namespace StardewModdingAPI.Patches *********/ /// Construct an instance. /// A callback to invoke before runs. - /// A callback to invoke after runs. - public SaveGamePatch(Action onSaving, Action onSaved) + public SaveGamePatch(Action onSaving) { SaveGamePatch.OnSaving = onSaving; - SaveGamePatch.OnSaved = onSaved; } @@ -46,10 +41,8 @@ namespace StardewModdingAPI.Patches { MethodInfo method = AccessTools.Method(typeof(SaveGame), nameof(SaveGame.Save)); MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(SaveGamePatch.Prefix)); - MethodInfo postfix = AccessTools.Method(this.GetType(), nameof(SaveGamePatch.Postfix)); harmony.Patch(method, prefix: new HarmonyMethod(prefix)); - harmony.Patch(method, postfix: new HarmonyMethod(postfix)); } @@ -65,13 +58,5 @@ namespace StardewModdingAPI.Patches SaveGamePatch.OnSaving(); return true; } - - /// The method to call after . - /// This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments. - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony.")] - private static void Postfix() - { - SaveGamePatch.OnSaved(); - } } }