Use copy of patcher plugin list to allow for better loader support

This commit is contained in:
ghorsington committed 2020-08-06 22:50:02 +03:00
1 parent 9ff80ca1a2
commit 897f37d241
1 file changed
+7 -3
@@ -32,6 +32,10 @@ namespace BepInEx.Preloader.Patching
/// </summary> /// </summary>
public static List<PatcherPlugin> PatcherPlugins { get; } = new List<PatcherPlugin>(); public static List<PatcherPlugin> PatcherPlugins { get; } = new List<PatcherPlugin>();
// We make use the safe version for possible cases where a mod loader wants to modify the original patcher
// plugins list
private static IEnumerable<PatcherPlugin> PatcherPluginsSafe => PatcherPlugins.ToList();
private static readonly string DumpedAssembliesPath = Path.Combine(Paths.BepInExRootPath, "DumpedAssemblies"); private static readonly string DumpedAssembliesPath = Path.Combine(Paths.BepInExRootPath, "DumpedAssemblies");
/// <summary> /// <summary>
@@ -154,7 +158,7 @@ namespace BepInEx.Preloader.Patching
private static void InitializePatchers() private static void InitializePatchers()
{ {
foreach (var assemblyPatcher in PatcherPlugins) foreach (var assemblyPatcher in PatcherPluginsSafe)
{ {
try try
{ {
@@ -169,7 +173,7 @@ namespace BepInEx.Preloader.Patching
private static void FinalizePatching() private static void FinalizePatching()
{ {
foreach (var assemblyPatcher in PatcherPlugins) foreach (var assemblyPatcher in PatcherPluginsSafe)
{ {
try try
{ {
@@ -255,7 +259,7 @@ namespace BepInEx.Preloader.Patching
var resolvedAssemblies = new Dictionary<string, string>(); var resolvedAssemblies = new Dictionary<string, string>();
// TODO: Maybe instead reload the assembly and repatch with other valid patchers? // TODO: Maybe instead reload the assembly and repatch with other valid patchers?
var invalidAssemblies = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase); var invalidAssemblies = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
foreach (var assemblyPatcher in PatcherPlugins) foreach (var assemblyPatcher in PatcherPluginsSafe)
foreach (string targetDll in assemblyPatcher.TargetDLLs()) foreach (string targetDll in assemblyPatcher.TargetDLLs())
if (assemblies.TryGetValue(targetDll, out var assembly) && !invalidAssemblies.Contains(targetDll)) if (assemblies.TryGetValue(targetDll, out var assembly) && !invalidAssemblies.Contains(targetDll))
{ {