Skip to content

Commit

Permalink
feat: after enter save hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Clazex committed Jul 13, 2022
1 parent 0d5fa92 commit 85cf1d0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Osmi/OsmiHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@ private static void OnMenuBuild() {
}


/// <summary>
/// Called after entering a new or existing save,
/// ensures to be after <see cref="On.HeroController.Start"/>
/// </summary>
public static event Action AfterEnterSaveHook = null!;

private static void OnAfterEnterSave() {
Ref.GM.OnFinishedEnteringScene -= OnAfterEnterSave;
Logger.LogFine($"{nameof(OnAfterEnterSave)} Invoked");

if (AfterEnterSaveHook == null) {
return;
}

foreach (Action a in AfterEnterSaveHook.GetInvocationList()) {
try {
a.Invoke();
} catch (Exception e) {
Logger.LogError(e.ToString());
}
}
}

private static void HookOnAfterEnterSave(On.HeroController.orig_Start orig, HeroController self) {
orig(self);
Ref.GM.OnFinishedEnteringScene -= OnAfterEnterSave;
Ref.GM.OnFinishedEnteringScene += OnAfterEnterSave;
}


/// <summary>
/// Equivalent to
/// <see cref="UnityEngine.SceneManagement.SceneManager.activeSceneChanged"/>,
Expand Down Expand Up @@ -169,6 +199,8 @@ private static void OnGameUnpause() {
static OsmiHooks() {
GameInitializedHook += () => UIManager.EditMenus += OnMenuBuild;

On.HeroController.Start += HookOnAfterEnterSave;

USceneManager.activeSceneChanged += OnSceneChange;

IL.HealthManager.Hit += il => new ILCursor(il)
Expand Down

0 comments on commit 85cf1d0

Please sign in to comment.