From e5f2ee0f011c4786623b1b4fa5377634e4069fed Mon Sep 17 00:00:00 2001 From: Krzyhau Date: Sun, 22 Jan 2023 20:23:40 +0100 Subject: [PATCH] fix crash when trying to switch savestates --- Installers/ModMenuInstaller.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Installers/ModMenuInstaller.cs b/Installers/ModMenuInstaller.cs index 2ef3225..6f5d18f 100644 --- a/Installers/ModMenuInstaller.cs +++ b/Installers/ModMenuInstaller.cs @@ -1,4 +1,5 @@ -using FezGame; +using Common; +using FezGame; using HatModLoader.Source; using MonoMod.RuntimeDetour; using System; @@ -44,17 +45,24 @@ private static void CreateAndAddModLevel(object MenuBase) const BindingFlags privBind = BindingFlags.NonPublic | BindingFlags.Instance; // prepare main menu object - object MenuRoot; + object MenuRoot = null; if (MenuBase.GetType() == MainMenuType) { MenuRoot = MainMenuType.GetField("RealMenuRoot", privBind).GetValue(MenuBase); } - else + + if(MenuBase.GetType() != MainMenuType || MenuRoot == null) { MenuRoot = MenuBaseType.GetField("MenuRoot", privBind).GetValue(MenuBase); } - MenuLevelType.GetField("IsDynamic").SetValue(MenuRoot, true); + if(MenuRoot == null) + { + Logger.Log("HAT", LogSeverity.Warning, "Unable to create MODS menu!"); + return; + } + + MenuLevelType.GetField("IsDynamic").SetValue(MenuRoot, true); // create new level object ModLevel = Activator.CreateInstance(MenuLevelType); MenuLevelType.GetField("IsDynamic").SetValue(ModLevel, true);