瀏覽代碼

Fix HarmonyInterop initializer order

ghorsington 4 年之前
父節點
當前提交
8405ffe415
共有 1 個文件被更改,包括 11 次插入5 次删除
  1. 11 5
      BepInEx.Preloader/Entrypoint.cs

+ 11 - 5
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();