mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Actually use the patched entrypoint assembly instead of only pretending to
This commit is contained in:
2 files changed
+29
-4
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using BepInEx.Bootstrap;
|
||||
using BepInEx.Configuration;
|
||||
@@ -71,6 +72,7 @@ namespace BepInEx.NetLauncher
|
||||
|
||||
Log.LogMessage("Preloader started");
|
||||
|
||||
Assembly entrypointAssembly;
|
||||
|
||||
using (var assemblyPatcher = new AssemblyPatcher())
|
||||
{
|
||||
@@ -83,6 +85,21 @@ namespace BepInEx.NetLauncher
|
||||
Log.LogInfo($"{assemblyPatcher.AssembliesToPatch.Count} assemblies discovered");
|
||||
|
||||
assemblyPatcher.PatchAndLoad();
|
||||
|
||||
|
||||
var assemblyName = AssemblyName.GetAssemblyName(executablePath);
|
||||
|
||||
entrypointAssembly = assemblyPatcher.LoadedAssemblies.Values.FirstOrDefault(x => x.FullName == assemblyName.FullName);
|
||||
|
||||
if (entrypointAssembly != null)
|
||||
{
|
||||
Log.LogDebug("Found patched entrypoint assembly! Using it");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.LogDebug("Using entrypoint assembly from disk");
|
||||
entrypointAssembly = Assembly.LoadFrom(executablePath);
|
||||
}
|
||||
}
|
||||
|
||||
Log.LogMessage("Preloader finished");
|
||||
@@ -91,8 +108,6 @@ namespace BepInEx.NetLauncher
|
||||
chainloader.Initialize();
|
||||
chainloader.Execute();
|
||||
|
||||
var assemblyName = AssemblyName.GetAssemblyName(executablePath);
|
||||
var entrypointAssembly = Assembly.Load(assemblyName);
|
||||
|
||||
AssemblyFix.Execute(entrypointAssembly);
|
||||
|
||||
|
||||
@@ -38,6 +38,12 @@ namespace BepInEx.Preloader.Core
|
||||
/// </summary>
|
||||
public Dictionary<string, AssemblyDefinition> AssembliesToPatch { get; } = new Dictionary<string, AssemblyDefinition>();
|
||||
|
||||
/// <summary>
|
||||
/// <para>Contains a dictionary of assemblies that have been loaded as part of executing this assembly patcher..</para>
|
||||
/// <para>The key is the same key as used in <see cref="LoadedAssemblies"/>, while the value is the actual assembly itself.</para>
|
||||
/// </summary>
|
||||
public Dictionary<string, Assembly> LoadedAssemblies { get; } = new Dictionary<string, Assembly>();
|
||||
|
||||
/// <summary>
|
||||
/// The directory location as to where patched assemblies will be saved to and loaded from disk, for debugging purposes. Defaults to BepInEx/DumpedAssemblies
|
||||
/// </summary>
|
||||
@@ -335,17 +341,21 @@ namespace BepInEx.Preloader.Core
|
||||
// but because some games *rely* on that because of messed up internal dependencies.
|
||||
if (patchedAssemblies.Contains(filename))
|
||||
{
|
||||
Assembly loadedAssembly;
|
||||
|
||||
if (ConfigLoadDumpedAssemblies.Value)
|
||||
Assembly.LoadFile(Path.Combine(DumpedAssembliesPath, filename));
|
||||
loadedAssembly = Assembly.LoadFile(Path.Combine(DumpedAssembliesPath, filename));
|
||||
else
|
||||
{
|
||||
using (var assemblyStream = new MemoryStream())
|
||||
{
|
||||
assembly.Write(assemblyStream);
|
||||
Assembly.Load(assemblyStream.ToArray());
|
||||
loadedAssembly =Assembly.Load(assemblyStream.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
LoadedAssemblies.Add(filename, loadedAssembly);
|
||||
|
||||
Logger.LogDebug($"Loaded '{assembly.FullName}' into memory");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user