|
@@ -6,7 +6,6 @@ using BepInEx.Harmony;
|
|
|
using BepInEx.Logging;
|
|
|
using Harmony;
|
|
|
using Mono.Cecil;
|
|
|
-using UnityEngine;
|
|
|
|
|
|
namespace BepInEx.Bootstrap
|
|
|
{
|
|
@@ -153,99 +152,11 @@ namespace BepInEx.Bootstrap
|
|
|
assembly.Dispose();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- FinalizePatching();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public static void PatchAll(string directory, IDictionary<AssemblyPatcherDelegate, IEnumerable<string>> patcherMethodDictionary, IEnumerable<Action> initializers = null, IEnumerable<Action> finalizers = null)
|
|
|
- {
|
|
|
-
|
|
|
- if (initializers != null)
|
|
|
- foreach (Action init in initializers)
|
|
|
- init.Invoke();
|
|
|
-
|
|
|
-
|
|
|
- Dictionary<string, AssemblyDefinition> assemblies = new Dictionary<string, AssemblyDefinition>();
|
|
|
-
|
|
|
- foreach (string assemblyPath in Directory.GetFiles(directory, "*.dll"))
|
|
|
- {
|
|
|
- var assembly = AssemblyDefinition.ReadAssembly(assemblyPath);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (assembly.Name.Name == "System"
|
|
|
- || assembly.Name.Name == "mscorlib")
|
|
|
- {
|
|
|
- assembly.Dispose();
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- assemblies.Add(Path.GetFileName(assemblyPath), assembly);
|
|
|
- PatchedAssemblyResolver.AssemblyLocations.Add(assembly.FullName, Path.GetFullPath(assemblyPath));
|
|
|
- }
|
|
|
-
|
|
|
- HashSet<string> patchedAssemblies = new HashSet<string>();
|
|
|
-
|
|
|
-
|
|
|
- foreach (var patcherMethod in patcherMethodDictionary)
|
|
|
- {
|
|
|
- foreach (string assemblyFilename in patcherMethod.Value)
|
|
|
- {
|
|
|
- if (assemblies.TryGetValue(assemblyFilename, out var assembly))
|
|
|
- {
|
|
|
- Patch(ref assembly, patcherMethod.Key);
|
|
|
- assemblies[assemblyFilename] = assembly;
|
|
|
- patchedAssemblies.Add(assemblyFilename);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- foreach (var kv in assemblies)
|
|
|
- {
|
|
|
- string filename = kv.Key;
|
|
|
- var assembly = kv.Value;
|
|
|
-
|
|
|
- if (DumpingEnabled && patchedAssemblies.Contains(filename))
|
|
|
- {
|
|
|
- string dirPath = Path.Combine(Paths.PluginPath, "DumpedAssemblies");
|
|
|
-
|
|
|
- if (!Directory.Exists(dirPath))
|
|
|
- Directory.CreateDirectory(dirPath);
|
|
|
-
|
|
|
- assembly.Write(Path.Combine(dirPath, filename));
|
|
|
- }
|
|
|
-
|
|
|
- Load(assembly);
|
|
|
- assembly.Dispose();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
PatchedAssemblyResolver.ApplyPatch();
|
|
|
|
|
|
|
|
|
- if (finalizers != null)
|
|
|
- foreach (Action finalizer in finalizers)
|
|
|
- finalizer.Invoke();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public static void Patch(ref AssemblyDefinition assembly, AssemblyPatcherDelegate patcherMethod)
|
|
|
- {
|
|
|
- patcherMethod.Invoke(ref assembly);
|
|
|
+ FinalizePatching();
|
|
|
}
|
|
|
|
|
|
|