From 7489ecb7f8977d199d06812f4b2b8bb3f7ad43e2 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 1 Jun 2024 00:43:31 -0700 Subject: [PATCH] MAYBE fix eye softlock (and use owml methods instead of copied qsb ones) --- NewHorizons/Main.cs | 8 +++-- NewHorizons/Patches/RigidbodyPatches.cs | 2 +- NewHorizons/Utility/NewHorizonExtensions.cs | 34 --------------------- 3 files changed, 7 insertions(+), 37 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index df767fe7..0f8eebea 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -388,7 +388,9 @@ namespace NewHorizons { IsWarpingBackToEye = false; OWTime.Pause(OWTime.PauseType.Loading); - LoadManager.LoadScene(OWScene.EyeOfTheUniverse); // LoadScene loads one frame later in Update. will this break since we unpause before that in the next line? + // fire OnStartSceneLoad so qsb and other mods are happy + ((Delegate)AccessTools.Field(typeof(LoadManager), nameof(LoadManager.OnStartSceneLoad)).GetValue(null)).DynamicInvoke(); + LoadManager.LoadSceneImmediate(OWScene.EyeOfTheUniverse); OWTime.Unpause(OWTime.PauseType.Loading); return; } @@ -936,11 +938,13 @@ namespace NewHorizons OWInput.ChangeInputMode(InputMode.None); // Hide unloading + // fire OnStartSceneLoad so qsb and other mods are happy + ((Delegate)AccessTools.Field(typeof(LoadManager), nameof(LoadManager.OnStartSceneLoad)).GetValue(null)).DynamicInvoke(); FadeHandler.FadeThen(1f, () => { // Slide reel unloading is tied to being removed from the sector, so we do that here to prevent a softlock Locator.GetPlayerSectorDetector().RemoveFromAllSectors(); - LoadManager.LoadScene(sceneToLoad); // this used to be LoadSceneImmediate, but that breaks with qsb. hopefully it doesnt break nh + LoadManager.LoadSceneImmediate(sceneToLoad); }); } } diff --git a/NewHorizons/Patches/RigidbodyPatches.cs b/NewHorizons/Patches/RigidbodyPatches.cs index 22ad16dc..963a6406 100644 --- a/NewHorizons/Patches/RigidbodyPatches.cs +++ b/NewHorizons/Patches/RigidbodyPatches.cs @@ -1,5 +1,5 @@ using HarmonyLib; -using NewHorizons.Utility; +using OWML.Utils; using System.Collections.Generic; using UnityEngine; diff --git a/NewHorizons/Utility/NewHorizonExtensions.cs b/NewHorizons/Utility/NewHorizonExtensions.cs index 3ba29885..7236af7e 100644 --- a/NewHorizons/Utility/NewHorizonExtensions.cs +++ b/NewHorizons/Utility/NewHorizonExtensions.cs @@ -372,40 +372,6 @@ namespace NewHorizons.Utility return curve; } - // From QSB - public static void RaiseEvent(this T instance, string eventName, params object[] args) - { - const BindingFlags flags = BindingFlags.Instance - | BindingFlags.Static - | BindingFlags.Public - | BindingFlags.NonPublic - | BindingFlags.DeclaredOnly; - if (typeof(T) - .GetField(eventName, flags)? - .GetValue(instance) is not MulticastDelegate multiDelegate) - { - return; - } - - multiDelegate.SafeInvoke(args); - } - - // From QSB - public static void SafeInvoke(this MulticastDelegate multicast, params object[] args) - { - foreach (var del in multicast.GetInvocationList()) - { - try - { - del.DynamicInvoke(args); - } - catch (TargetInvocationException ex) - { - NHLogger.LogError($"Error invoking delegate! {ex.InnerException}"); - } - } - } - public static List GetChildNodes(this XmlNode parentNode, string tagName) { return parentNode.ChildNodes.Cast().Where(node => node.LocalName == tagName).ToList();