Przeglądaj źródła

Roll back Color converter

ManlyMarco 5 lat temu
rodzic
commit
ee782a00c4

+ 5 - 13
BepInEx/Configuration/ConfigEntryBase.cs

@@ -2,7 +2,6 @@
 using System.IO;
 using System.Linq;
 using BepInEx.Logging;
-using UnityEngine;
 
 namespace BepInEx.Configuration
 {
@@ -128,19 +127,12 @@ namespace BepInEx.Configuration
 			{
 				writer.WriteLine(Description.AcceptableValues.ToSerializedString());
 			}
-			else
+			else if (SettingType.IsEnum)
 			{
-				if (SettingType.IsEnum)
-				{
-					writer.WriteLine("# Acceptable values: " + string.Join(", ", Enum.GetNames(SettingType)));
-
-					if (SettingType.GetCustomAttributes(typeof(FlagsAttribute), true).Any())
-						writer.WriteLine("# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning)");
-				}
-				else if (SettingType == typeof(bool))
-					writer.WriteLine("# Acceptable values: True, False");
-				else if (SettingType == typeof(Color))
-					writer.WriteLine("# Acceptable values: Hex HTML color codes");
+				writer.WriteLine("# Acceptable values: " + string.Join(", ", Enum.GetNames(SettingType)));
+
+				if (SettingType.GetCustomAttributes(typeof(FlagsAttribute), true).Any())
+					writer.WriteLine("# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning)");
 			}
 		}
 	}

+ 3 - 17
BepInEx/Configuration/TomlTypeConverter.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Globalization;
 using System.Text.RegularExpressions;
-using UnityEngine;
 
 namespace BepInEx.Configuration
 {
@@ -11,6 +10,7 @@ namespace BepInEx.Configuration
 	/// </summary>
 	public static class TomlTypeConverter
 	{
+		// Don't put anything from UnityEngine here or it will break preloader (loads the assembly before it's patched)
 		private static Dictionary<Type, TypeConverter> TypeConverters { get; } = new Dictionary<Type, TypeConverter>
 		{
 			[typeof(string)] = new TypeConverter
@@ -103,21 +103,6 @@ namespace BepInEx.Configuration
 				ConvertToString = (obj, type) => obj.ToString(),
 				ConvertToObject = (str, type) => Enum.Parse(type, str, true),
 			},
-
-			//unity types
-
-			[typeof(Color)] = new TypeConverter
-			{
-				ConvertToString = (obj, type) => ColorUtility.ToHtmlStringRGBA((Color)obj),
-				ConvertToObject = (str, type) =>
-				{
-					if (string.IsNullOrEmpty(str)) return Color.clear;
-					Color c;
-					if (!ColorUtility.TryParseHtmlString("#" + str.Trim('#', ' '), out c))
-						throw new FormatException("Invalid color string, expected hex #RRGGBBAA");
-					return c;
-				},
-			},
 		};
 
 		/// <summary>
@@ -167,7 +152,8 @@ namespace BepInEx.Configuration
 		}
 
 		/// <summary>
-		/// Add a new type converter for a given type.
+		/// Add a new type converter for a given type. 
+		/// If a different converter is already added, an ArgumentException is thrown.
 		/// </summary>
 		public static void AddConverter(Type type, TypeConverter converter)
 		{