From b2d47e29ffe58142efd0a5084f33fefffd87a460 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 28 Feb 2021 14:17:41 -0500 Subject: add ReturningToTitle stage --- src/SMAPI/Enums/LoadStage.cs | 5 ++++- src/SMAPI/Patches/LoadContextPatch.cs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/SMAPI/Enums/LoadStage.cs b/src/SMAPI/Enums/LoadStage.cs index aa95d201..250c88e9 100644 --- a/src/SMAPI/Enums/LoadStage.cs +++ b/src/SMAPI/Enums/LoadStage.cs @@ -37,6 +37,9 @@ namespace StardewModdingAPI.Enums Loaded, /// The save is fully loaded, the world has been initialized, and is now true. - Ready + Ready, + + /// The game is exiting the loaded save and returning to the title screen. This happens before it returns to title; see after it returns. + ReturningToTitle } } diff --git a/src/SMAPI/Patches/LoadContextPatch.cs b/src/SMAPI/Patches/LoadContextPatch.cs index 9fddcc50..28bc23b6 100644 --- a/src/SMAPI/Patches/LoadContextPatch.cs +++ b/src/SMAPI/Patches/LoadContextPatch.cs @@ -77,6 +77,12 @@ namespace StardewModdingAPI.Patches prefix: new HarmonyMethod(this.GetType(), nameof(LoadContextPatch.Before_Game1_LoadForNewGame)), postfix: new HarmonyMethod(this.GetType(), nameof(LoadContextPatch.After_Game1_LoadForNewGame)) ); + + // detect ReturningToTitle + harmony.Patch( + original: AccessTools.Method(typeof(Game1), nameof(Game1.CleanupReturningToTitle)), + prefix: new HarmonyMethod(this.GetType(), nameof(LoadContextPatch.Before_Game1_CleanupReturningToTitle)) + ); } @@ -110,6 +116,15 @@ namespace StardewModdingAPI.Patches return true; } + /// Called before . + /// Returns whether to execute the original method. + /// This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments. + private static bool Before_Game1_CleanupReturningToTitle() + { + LoadContextPatch.OnStageChanged(LoadStage.ReturningToTitle); + return true; + } + /// Called before . /// Returns whether to execute the original method. /// This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments. -- cgit