From 12d4372aab8a515078ed5b8e8c9b2a068a45bc90 Mon Sep 17 00:00:00 2001 From: Arne Kiesewetter Date: Fri, 16 Feb 2024 03:12:29 +0100 Subject: [PATCH] Call hooks in correct order. --- MonkeyLoader.Unity.Integration/UnityHooks.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/MonkeyLoader.Unity.Integration/UnityHooks.cs b/MonkeyLoader.Unity.Integration/UnityHooks.cs index 2163dcf..6c1089d 100644 --- a/MonkeyLoader.Unity.Integration/UnityHooks.cs +++ b/MonkeyLoader.Unity.Integration/UnityHooks.cs @@ -15,8 +15,19 @@ internal sealed class UnityHooks : Monkey { public override string Name { get; } = "Unity Hooks"; - private static IEnumerable UnityMonkeys - => Mod.Loader.Monkeys.SelectCastable(); + private static IUnityMonkeyInternal[] UnityMonkeys + { + get + { + var monkeys = Mod.Loader.Monkeys + .SelectCastable() + .ToArray(); + + Array.Sort(monkeys, Monkey.AscendingComparer); + + return monkeys; + } + } protected override IEnumerable GetFeaturePatches() => Enumerable.Empty(); @@ -32,14 +43,14 @@ private void SceneManager_sceneLoaded(Scene scene, LoadSceneMode sceneMode) { Info(() => "First Scene Loaded! Executing OnFirstSceneReady hooks on UnityMonkeys!"); - var unityMonkeys = UnityMonkeys.ToArray(); + var unityMonkeys = UnityMonkeys; Logger.Trace(() => "Running FirstSceneReady hooks in this order:"); Logger.Trace(unityMonkeys.Select(uM => new Func(() => $"{uM.Mod.Title}/{uM.Name}"))); SceneManager.sceneLoaded -= SceneManager_sceneLoaded; var sw = Stopwatch.StartNew(); - foreach (var unityMonkey in UnityMonkeys) + foreach (var unityMonkey in unityMonkeys) unityMonkey.FirstSceneReady(scene); Info(() => $"Done executing OnFirstSceneReady hooks on UnityMonkeys in {sw.ElapsedMilliseconds}ms!");