Browse Source

Merge branch 'master' of https://github.com/BepInEx/BepInEx

 Conflicts:
	BepInEx.Preloader/Preloader.cs
ghorsington 4 years ago
parent
commit
1644e5c5e4
1 changed files with 28 additions and 0 deletions
  1. 28 0
      BepInEx.Preloader/Preloader.cs

+ 28 - 0
BepInEx.Preloader/Preloader.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
@@ -31,6 +32,8 @@ namespace BepInEx.Preloader
 		{
 			try
 			{
+				InitializeHarmony();
+
 				ConsoleManager.Initialize(false);
 				AllocateConsole();
 
@@ -239,6 +242,31 @@ namespace BepInEx.Preloader
 			return $"Unknown ({(IsPostUnity2017 ? "post" : "pre")}-2017)";
 		}
 
+		private static void InitializeHarmony()
+		{
+			switch (HarmonyBackend.Value)
+			{
+				case MonoModBackend.auto:
+					break;
+				case MonoModBackend.dynamicmethod:
+				case MonoModBackend.methodbuilder:
+				case MonoModBackend.cecil:
+					Environment.SetEnvironmentVariable("MONOMOD_DMD_TYPE", HarmonyBackend.Value.ToString());
+					break;
+				default:
+					throw new ArgumentOutOfRangeException(nameof(HarmonyBackend), HarmonyBackend.Value, "Unknown backend");
+			}
+		}
+
+		private enum MonoModBackend
+		{
+			// Enum names are important!
+			[Description("Auto")] auto = 0,
+			[Description("DynamicMethod")] dynamicmethod,
+			[Description("MethodBuilder")] methodbuilder,
+			[Description("Cecil")] cecil
+		}
+
 		#region Config
 
 		private static readonly ConfigEntry<string> ConfigEntrypointAssembly = ConfigFile.CoreConfig.Bind(