diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-02-28 14:17:41 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-02-28 14:17:41 -0500 |
commit | b2d47e29ffe58142efd0a5084f33fefffd87a460 (patch) | |
tree | d2a3a78a264ea8a4cf08269cb8b9b4b3945b1171 | |
parent | 403616b07c6da6479ce77fd45b41f622e9972915 (diff) | |
download | SMAPI-b2d47e29ffe58142efd0a5084f33fefffd87a460.tar.gz SMAPI-b2d47e29ffe58142efd0a5084f33fefffd87a460.tar.bz2 SMAPI-b2d47e29ffe58142efd0a5084f33fefffd87a460.zip |
add ReturningToTitle stage
-rw-r--r-- | docs/release-notes.md | 2 | ||||
-rw-r--r-- | src/SMAPI/Enums/LoadStage.cs | 5 | ||||
-rw-r--r-- | src/SMAPI/Patches/LoadContextPatch.cs | 15 |
3 files changed, 20 insertions, 2 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index d3b0698f..833e2130 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -12,7 +12,7 @@ * Fixed console showing _found 1 mod with warnings_ with no mods listed. * For mod authors: - * Added two stages to the `LoadStageChanged` event: `CreatedInitialLocations` and `SaveAddedLocations`, raised immediately after the game adds its vanilla locations but before they're initialized. + * Added three stages to the `LoadStageChanged` event: `CreatedInitialLocations`/`SaveAddedLocations` (raised immediately after the game adds locations but before they're initialized), and `ReturningToTitle` (raised before exiting to the title screen). ## 3.9.2 Released 21 February 2021 for Stardew Valley 1.5.4 or later. 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, /// <summary>The save is fully loaded, the world has been initialized, and <see cref="Context.IsWorldReady"/> is now true.</summary> - Ready + Ready, + + /// <summary>The game is exiting the loaded save and returning to the title screen. This happens before it returns to title; see <see cref="None"/> after it returns.</summary> + 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; } + /// <summary>Called before <see cref="Game1.CleanupReturningToTitle"/>.</summary> + /// <returns>Returns whether to execute the original method.</returns> + /// <remarks>This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments.</remarks> + private static bool Before_Game1_CleanupReturningToTitle() + { + LoadContextPatch.OnStageChanged(LoadStage.ReturningToTitle); + return true; + } + /// <summary>Called before <see cref="Game1.loadForNewGame"/>.</summary> /// <returns>Returns whether to execute the original method.</returns> /// <remarks>This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments.</remarks> |