|
@@ -7,7 +7,7 @@ using Mono.Cecil;
|
|
|
|
|
|
namespace BepInEx.Bootstrap
|
|
namespace BepInEx.Bootstrap
|
|
{
|
|
{
|
|
- public delegate void AssemblyPatcherDelegate(AssemblyDefinition assembly);
|
|
+ public delegate void AssemblyPatcherDelegate(ref AssemblyDefinition assembly);
|
|
|
|
|
|
public static class AssemblyPatcher
|
|
public static class AssemblyPatcher
|
|
{
|
|
{
|
|
@@ -57,46 +57,44 @@ namespace BepInEx.Bootstrap
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- IEnumerable<AssemblyDefinition> sortedAssemblies = Utility.TopologicalSort(assemblies, x => assemblyDependencyDict[x]);
|
|
+ AssemblyDefinition[] sortedAssemblies = Utility.TopologicalSort(assemblies, x => assemblyDependencyDict[x]).ToArray();
|
|
|
|
|
|
|
|
|
|
- foreach (var assembly in sortedAssemblies)
|
|
+ for (int i = 0; i < sortedAssemblies.Length; i++)
|
|
- {
|
|
+ {
|
|
-#if CECIL_10
|
|
+ string filename = Path.GetFileName(assemblyFilenames[sortedAssemblies[i]]);
|
|
- using (assembly)
|
|
|
|
-#endif
|
|
|
|
- {
|
|
|
|
- string filename = Path.GetFileName(assemblyFilenames[assembly]);
|
|
|
|
|
|
|
|
-
|
|
+
|
|
- if (!patcherMethodDictionary.TryGetValue(filename, out IList<AssemblyPatcherDelegate> patcherMethods))
|
|
+ if (!patcherMethodDictionary.TryGetValue(filename, out IList<AssemblyPatcherDelegate> patcherMethods))
|
|
- continue;
|
|
+ continue;
|
|
|
|
|
|
- Patch(assembly, patcherMethods);
|
|
+ Patch(ref sortedAssemblies[i], patcherMethods);
|
|
|
|
|
|
- if (DumpingEnabled)
|
|
+ if (DumpingEnabled)
|
|
|
|
+ {
|
|
|
|
+ using (MemoryStream mem = new MemoryStream())
|
|
{
|
|
{
|
|
- using (MemoryStream mem = new MemoryStream())
|
|
+ string dirPath = Path.Combine(Preloader.PluginPath, "DumpedAssemblies");
|
|
- {
|
|
|
|
- string dirPath = Path.Combine(Preloader.PluginPath, "DumpedAssemblies");
|
|
|
|
|
|
|
|
- if (!Directory.Exists(dirPath))
|
|
+ if (!Directory.Exists(dirPath))
|
|
- Directory.CreateDirectory(dirPath);
|
|
+ Directory.CreateDirectory(dirPath);
|
|
|
|
|
|
- assembly.Write(mem);
|
|
+ sortedAssemblies[i].Write(mem);
|
|
- File.WriteAllBytes(Path.Combine(dirPath, filename), mem.ToArray());
|
|
+ File.WriteAllBytes(Path.Combine(dirPath, filename), mem.ToArray());
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+#if CECIL_10
|
|
|
|
+ sortedAssemblies[i].Dispose();
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void Patch(AssemblyDefinition assembly, IEnumerable<AssemblyPatcherDelegate> patcherMethods)
|
|
+ public static void Patch(ref AssemblyDefinition assembly, IEnumerable<AssemblyPatcherDelegate> patcherMethods)
|
|
{
|
|
{
|
|
using (MemoryStream assemblyStream = new MemoryStream())
|
|
using (MemoryStream assemblyStream = new MemoryStream())
|
|
{
|
|
{
|
|
foreach (AssemblyPatcherDelegate method in patcherMethods)
|
|
foreach (AssemblyPatcherDelegate method in patcherMethods)
|
|
- method.Invoke(assembly);
|
|
+ method.Invoke(ref assembly);
|
|
|
|
|
|
assembly.Write(assemblyStream);
|
|
assembly.Write(assemblyStream);
|
|
Assembly.Load(assemblyStream.ToArray());
|
|
Assembly.Load(assemblyStream.ToArray());
|