Skip to content

Commit

Permalink
fix crash when trying to switch savestates
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzyhau committed Jan 22, 2023
1 parent bffbf5c commit e5f2ee0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Installers/ModMenuInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FezGame;
using Common;
using FezGame;
using HatModLoader.Source;
using MonoMod.RuntimeDetour;
using System;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e5f2ee0

Please sign in to comment.