using System;
using System.Diagnostics.CodeAnalysis;
using HarmonyLib;
using StardewModdingAPI.Enums;
using StardewModdingAPI.Framework.Patching;
using StardewValley.Menus;
namespace StardewModdingAPI.Patches
{
/// Harmony patches which notify SMAPI for save creation load stages.
/// 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 : IHarmonyPatch
{
/*********
** Fields
*********/
/// A callback to invoke when the load stage changes.
private static Action OnStageChanged;
/*********
** Public methods
*********/
/// Construct an instance.
/// A callback to invoke when the load stage changes.
public TitleMenuPatcher(Action onStageChanged)
{
TitleMenuPatcher.OnStageChanged = onStageChanged;
}
///
public void Apply(Harmony harmony)
{
// detect CreatedBasicInfo
harmony.Patch(
original: AccessTools.Method(typeof(TitleMenu), nameof(TitleMenu.createdNewCharacter)),
prefix: new HarmonyMethod(this.GetType(), nameof(TitleMenuPatcher.Before_TitleMenu_CreatedNewCharacter))
);
}
/*********
** Private methods
*********/
/// 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_TitleMenu_CreatedNewCharacter()
{
TitleMenuPatcher.OnStageChanged(LoadStage.CreatedBasicInfo);
return true;
}
}
}