Browse Source

Remove accidental trigger of SRE types in preloader

ghorsington 5 years ago
parent
commit
d84da485aa
2 changed files with 12 additions and 10 deletions
  1. 9 6
      BepInEx.Preloader/Preloader.cs
  2. 3 4
      BepInEx.Preloader/RuntimeFixes/UnityPatches.cs

+ 9 - 6
BepInEx.Preloader/Preloader.cs

@@ -34,17 +34,19 @@ namespace BepInEx.Preloader
 			{
 				AllocateConsole();
 
-				Utility.TryDo(() =>
+				bool bridgeInitialized = Utility.TryDo(() =>
 				{
 					if (ConfigShimHarmony.Value)
 						HarmonyDetourBridge.Init();
 				}, out var harmonyBridgeException);
 
-				Utility.TryDo(() =>
-				{
-					if (ConfigApplyRuntimePatches.Value)
-						UnityPatches.Apply();
-				}, out var runtimePatchException);
+				Exception runtimePatchException = null;
+				if(bridgeInitialized)
+					Utility.TryDo(() =>
+					{
+						if (ConfigApplyRuntimePatches.Value)
+							UnityPatches.Apply();
+					}, out runtimePatchException);
 
 				Logger.Sources.Add(TraceLogSource.CreateSource());
 
@@ -100,6 +102,7 @@ namespace BepInEx.Preloader
 			}
 			catch (Exception ex)
 			{
+				File.WriteAllText("err.log", ex.ToString());
 				try
 				{
 					Logger.LogFatal("Could not run preloader!");

+ 3 - 4
BepInEx.Preloader/RuntimeFixes/UnityPatches.cs

@@ -8,14 +8,13 @@ namespace BepInEx.Preloader.RuntimeFixes
 {
 	internal static class UnityPatches
 	{
-		public static HarmonyLib.Harmony HarmonyInstance { get; } = new HarmonyLib.Harmony("com.bepinex.unitypatches");
+		private static HarmonyLib.Harmony HarmonyInstance { get; set; }
 
-		public static Dictionary<string, string> AssemblyLocations { get; } =
-			new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
+		public static Dictionary<string, string> AssemblyLocations { get; } = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
 
 		public static void Apply()
 		{
-			HarmonyWrapper.PatchAll(typeof(UnityPatches), HarmonyInstance);
+			HarmonyInstance = HarmonyWrapper.PatchAll(typeof(UnityPatches), HarmonyInstance);
 
 			try
 			{