Переглянути джерело

Merge branch 'v40-framework' of https://github.com/bbepis/BepInEx into v40-framework

Bepis 6 роки тому
батько
коміт
d93434d931
2 змінених файлів з 18 додано та 16 видалено
  1. 12 10
      BepInEx/Bootstrap/AssemblyPatcher.cs
  2. 6 6
      BepInEx/Bootstrap/Preloader.cs

+ 12 - 10
BepInEx/Bootstrap/AssemblyPatcher.cs

@@ -24,16 +24,18 @@ namespace BepInEx.Bootstrap
 		/// </summary>
         private static bool DumpingEnabled => bool.TryParse(Config.GetEntry("preloader-dumpassemblies", "false"), out bool result) ? result : false;
 
-		/// <summary>
-		/// Patches and loads an entire directory of assemblies.
-		/// </summary>
-		/// <param name="directory">The directory to load assemblies from.</param>
-		/// <param name="patcherMethodDictionary">The dictionary of patchers and their targeted assembly filenames which they are patching.</param>
-        public static void PatchAll(string directory, IDictionary<AssemblyPatcherDelegate, IEnumerable<string>> patcherMethodDictionary, IEnumerable<Action> Initializers = null, IEnumerable<Action> Finalizers = null)
+        /// <summary>
+        /// Patches and loads an entire directory of assemblies.
+        /// </summary>
+        /// <param name="directory">The directory to load assemblies from.</param>
+        /// <param name="patcherMethodDictionary">The dictionary of patchers and their targeted assembly filenames which they are patching.</param>
+        /// <param name="initializers">List of initializers to run before any patching starts</param>
+        /// <param name="finalizers">List of finalizers to run before returning</param>
+        public static void PatchAll(string directory, IDictionary<AssemblyPatcherDelegate, IEnumerable<string>> patcherMethodDictionary, IEnumerable<Action> initializers = null, IEnumerable<Action> finalizers = null)
         {
 			//run all initializers
-			if (Initializers != null)
-				foreach (Action init in Initializers)
+			if (initializers != null)
+				foreach (Action init in initializers)
 					init.Invoke();
 
             //load all the requested assemblies
@@ -122,8 +124,8 @@ namespace BepInEx.Bootstrap
             }
 			
 	        //run all finalizers
-	        if (Finalizers != null)
-		        foreach (Action finalizer in Finalizers)
+	        if (finalizers != null)
+		        foreach (Action finalizer in finalizers)
 			        finalizer.Invoke();
         }
 

+ 6 - 6
BepInEx/Bootstrap/Preloader.cs

@@ -42,12 +42,12 @@ namespace BepInEx.Bootstrap
 		/// <summary>
 		/// The path to the core BepInEx DLL.
 		/// </summary>
-        public static string CurrentExecutingAssemblyPath { get; } = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace('/', '\\');
+        public static string BepInExAssemblyPath { get; } = typeof(Preloader).Assembly.CodeBase.Replace("file:///", "").Replace('/', '\\');
 
 		/// <summary>
 		/// The directory that the core BepInEx DLLs reside in.
 		/// </summary>
-	    public static string CurrentExecutingAssemblyDirectoryPath { get; } = Path.GetDirectoryName(CurrentExecutingAssemblyPath);
+	    public static string BepInExAssemblyDirectory { get; } = Path.GetDirectoryName(BepInExAssemblyPath);
 
 		/// <summary>
 		/// The name of the currently executing process.
@@ -198,7 +198,7 @@ namespace BepInEx.Bootstrap
                         catch (ReflectionTypeLoadException) { } //invalid references
                     }
 
-                AssemblyPatcher.PatchAll(ManagedPath, PatcherDictionary);
+                AssemblyPatcher.PatchAll(ManagedPath, PatcherDictionary, Initializers, Finalizers);
             }
             catch (Exception ex)
             {
@@ -332,9 +332,9 @@ namespace BepInEx.Bootstrap
             if (assembly.Name.Name == "UnityEngine")
             {
 #if CECIL_10
-                using (AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(CurrentExecutingAssemblyPath))
+                using (AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(BepInExAssemblyPath))
 #elif CECIL_9
-                AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(CurrentExecutingAssemblyPath);
+                AssemblyDefinition injected = AssemblyDefinition.ReadAssembly(BepInExAssemblyPath);
 #endif
                 {
                     var originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Chainloader")
@@ -380,7 +380,7 @@ namespace BepInEx.Bootstrap
             if (foundAssembly != null)
                 return foundAssembly;
 
-            if (Utility.TryResolveDllAssembly(assemblyName, CurrentExecutingAssemblyDirectoryPath, out foundAssembly) ||
+            if (Utility.TryResolveDllAssembly(assemblyName, BepInExAssemblyDirectory, out foundAssembly) ||
                 Utility.TryResolveDllAssembly(assemblyName, PatcherPluginPath, out foundAssembly) ||
                 Utility.TryResolveDllAssembly(assemblyName, PluginPath, out foundAssembly))
                 return foundAssembly;