From 430dff37f38882c5071be50d8c80dfd80e7f8e3d Mon Sep 17 00:00:00 2001 From: Lexi Date: Fri, 12 Jan 2024 12:14:06 -0500 Subject: [PATCH] Move the disabled check to a method instead of a delegate --- src/SpaceWarp.Patches/ChainloaderPatch.cs | 32 ++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/SpaceWarp.Patches/ChainloaderPatch.cs b/src/SpaceWarp.Patches/ChainloaderPatch.cs index 2031627..ca0566a 100644 --- a/src/SpaceWarp.Patches/ChainloaderPatch.cs +++ b/src/SpaceWarp.Patches/ChainloaderPatch.cs @@ -1,3 +1,4 @@ +using System.Reflection; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Logging; @@ -40,12 +41,25 @@ private static void PreStartActions() } } + private static bool CheckIfModIsDisabled(PluginInfo plugin, HashSet deniedSet) + { + if (Array.IndexOf(ModList.DisabledPluginGuids, plugin.Metadata.GUID) == -1) + { + return true; + } + + deniedSet.Add(plugin.Metadata.GUID); + ModList.DisabledPlugins.Add(plugin); + Entrypoint.LogSource.LogInfo($"{plugin.Metadata.GUID} was disabled, skipping loading..."); + return false; + + } [HarmonyILManipulator] [HarmonyPatch(typeof(Chainloader), nameof(Chainloader.Start))] private static void DisablePluginsIL(ILContext il) { ILCursor c = new(il); - + ILLabel continueLabel = default; c.GotoNext( MoveType.After, @@ -54,23 +68,11 @@ private static void DisablePluginsIL(ILContext il) x => x.MatchLdcI4(0), // false x => x.MatchStloc(24) // someBool = false ); - + c.Emit(OpCodes.Ldloc, 23); // current PluginInfo c.Emit(OpCodes.Ldloc, 5); // set of denied plugins so far // false means skip to this plugin, true means continue loading it - c.EmitDelegate(static bool (PluginInfo plugin, HashSet deniedSet) => - { - if (Array.IndexOf(ModList.DisabledPluginGuids, plugin.Metadata.GUID) == -1) - { - return true; - } - - deniedSet.Add(plugin.Metadata.GUID); - ModList.DisabledPlugins.Add(plugin); - Entrypoint.LogSource.LogInfo($"{plugin.Metadata.GUID} was disabled, skipping loading..."); - return false; - - }); + c.EmitDelegate(CheckIfModIsDisabled); c.Emit(OpCodes.Brfalse, continueLabel); } } \ No newline at end of file