using System; using System.Diagnostics.CodeAnalysis; using HarmonyLib; using StardewModdingAPI.Enums; using StardewModdingAPI.Internal.Patching; using StardewValley.Menus; namespace StardewModdingAPI.Patches { /// Harmony patches for which notify SMAPI when a new character was created. /// Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments. [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony and methods are named for clarity.")] [SuppressMessage("ReSharper", "IdentifierTypo", Justification = "Argument names are defined by Harmony and methods are named for clarity.")] internal class TitleMenuPatcher : BasePatcher { /********* ** Fields *********/ /// A callback to invoke when the load stage changes. private static Action OnStageChanged = null!; // initialized in constructor /********* ** Public methods *********/ /// Construct an instance. /// A callback to invoke when the load stage changes. public TitleMenuPatcher(Action onStageChanged) { TitleMenuPatcher.OnStageChanged = onStageChanged; } /// public override void Apply(Harmony harmony, IMonitor monitor) { harmony.Patch( original: this.RequireMethod(nameof(TitleMenu.createdNewCharacter)), prefix: this.GetHarmonyMethod(nameof(TitleMenuPatcher.Before_CreatedNewCharacter)) ); } /********* ** Private methods *********/ /// The method to call 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_CreatedNewCharacter() { TitleMenuPatcher.OnStageChanged(LoadStage.CreatedBasicInfo); return true; } } }