From 8405ffe41543085ee694d9d87c5577f5085519ea Mon Sep 17 00:00:00 2001 From: ghorsington Date: Fri, 23 Oct 2020 22:09:55 +0300 Subject: [PATCH] Fix HarmonyInterop initializer order --- BepInEx.Preloader/Entrypoint.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/BepInEx.Preloader/Entrypoint.cs b/BepInEx.Preloader/Entrypoint.cs index c8c227e..00b8aa7 100644 --- a/BepInEx.Preloader/Entrypoint.cs +++ b/BepInEx.Preloader/Entrypoint.cs @@ -39,23 +39,29 @@ namespace BepInEx.Preloader } } + // Do this in a separate method to not trigger cctor prematurely + private static void InitializeAssemblyResolvers() + { + // Need to initialize interop first because it installs its own special assembly resolver + HarmonyInterop.Initialize(); + AppDomain.CurrentDomain.AssemblyResolve += LocalResolve; + // Remove temporary resolver early so it won't override local resolver + AppDomain.CurrentDomain.AssemblyResolve -= Entrypoint.ResolveCurrentDirectory; + } + public static void PreloaderPreMain() { string bepinPath = Utility.ParentDirectory(Path.GetFullPath(EnvVars.DOORSTOP_INVOKE_DLL_PATH), 2); Paths.SetExecutablePath(EnvVars.DOORSTOP_PROCESS_PATH, bepinPath, EnvVars.DOORSTOP_MANAGED_FOLDER_DIR); - AppDomain.CurrentDomain.AssemblyResolve += LocalResolve; - // Remove temporary resolver early so it won't override local resolver - AppDomain.CurrentDomain.AssemblyResolve -= Entrypoint.ResolveCurrentDirectory; - LoadCriticalAssemblies(); + InitializeAssemblyResolvers(); PreloaderMain(); } private static void PreloaderMain() { - HarmonyInterop.Initialize(); if (Preloader.ConfigApplyRuntimePatches.Value) { XTermFix.Apply();