Browse Source

Add ability to break before patched assemblies are loaded

ghorsington 5 years ago
parent
commit
150f812ece
1 changed files with 14 additions and 0 deletions
  1. 14 0
      BepInEx.Preloader/Patching/AssemblyPatcher.cs

+ 14 - 0
BepInEx.Preloader/Patching/AssemblyPatcher.cs

@@ -153,6 +153,14 @@ namespace BepInEx.Preloader.Patching
 				}
             }
 
+			if (ConfigBreakBeforeLoadAssemblies.Value)
+			{
+				Logger.LogInfo($"BepInEx is about load the following assemblies:\n{string.Join("\n", patchedAssemblies.ToArray())}");
+				Logger.LogInfo($"The assemblies were dumped into {DumpedAssembliesPath}");
+				Logger.LogInfo("Load any assemblies into the debugger, set breakpoints and continue execution.");
+				Debugger.Break();
+			}
+
 			foreach (var kv in assemblies)
 			{
 				string filename = kv.Key;
@@ -202,6 +210,12 @@ namespace BepInEx.Preloader.Patching
             "If enabled, BepInEx will load patched assemblies from BepInEx/DumpedAssemblies instead of memory.\nThis can be used to be able to load patched assemblies into debuggers like dnSpy.\nIf set to true, will override DumpAssemblies.",
 			false);
 
+		private static readonly ConfigWrapper<bool> ConfigBreakBeforeLoadAssemblies = ConfigFile.CoreConfig.Wrap(
+			"Preloader",
+			"BreakBeforeLoadAssemblies",
+			"If enabled, BepInEx will call Debugger.Break() once before loading patched assemblies.\nThis can be used with debuggers like dnSpy to install breakpoints into patched assemblies before they are loaded.",
+			false);
+
         #endregion
     }
 }