Decompiled source of ColorfulPieces v1.15.1

ColorfulPieces.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComfyLib;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ColorfulPieces")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ColorfulPieces")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bfaa6b86-51a5-42a3-83a5-af812a989c5a")]
[assembly: AssemblyFileVersion("1.15.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.15.1.0")]
[module: UnverifiableCode]
namespace ComfyLib
{
	public sealed class ComfyArgs
	{
		public static readonly Regex CommandRegex = new Regex("^(?<command>\\w[\\w-]*)(?:\\s+--(?:(?<arg>\\w[\\w-]*)=(?:\"(?<value>[^\"]*?)\"|(?<value>\\S+))|no(?<argfalse>\\w[\\w-]*)|(?<argtrue>\\w[\\w-]*)))*");

		public static readonly char[] CommaSeparator = new char[1] { ',' };

		public readonly Dictionary<string, string> ArgsValueByName = new Dictionary<string, string>();

		public ConsoleEventArgs Args { get; }

		public string Command { get; private set; }

		public ComfyArgs(ConsoleEventArgs args)
		{
			Args = args;
			ParseArgs(Args);
		}

		private void ParseArgs(ConsoleEventArgs args)
		{
			Match match = CommandRegex.Match(args.FullLine);
			Command = match.Groups["command"].Value;
			foreach (Capture capture3 in match.Groups["argtrue"].Captures)
			{
				ArgsValueByName[capture3.Value] = "true";
			}
			foreach (Capture capture4 in match.Groups["argfalse"].Captures)
			{
				ArgsValueByName[capture4.Value] = "false";
			}
			CaptureCollection captures = match.Groups["arg"].Captures;
			CaptureCollection captures2 = match.Groups["value"].Captures;
			for (int i = 0; i < captures.Count; i++)
			{
				ArgsValueByName[captures[i].Value] = ((i < captures2.Count) ? captures2[i].Value : string.Empty);
			}
		}

		public bool TryGetValue(string argName, string argShortName, out string argValue)
		{
			if (!ArgsValueByName.TryGetValue(argName, out argValue))
			{
				return ArgsValueByName.TryGetValue(argShortName, out argValue);
			}
			return true;
		}

		public bool TryGetValue<T>(string argName, string argShortName, out T argValue)
		{
			argValue = default(T);
			if (TryGetValue(argName, argShortName, out var argValue2))
			{
				return TryConvertValue<T>(argName, argValue2, out argValue);
			}
			return false;
		}

		public bool TryGetListValue<T>(string argName, string argShortName, out List<T> argListValue)
		{
			if (!TryGetValue(argName, argShortName, out var argValue))
			{
				argListValue = null;
				return false;
			}
			string[] array = argValue.Split(CommaSeparator, StringSplitOptions.RemoveEmptyEntries);
			argListValue = new List<T>(array.Length);
			for (int i = 0; i < array.Length; i++)
			{
				if (!TryConvertValue<T>(argName, array[i], out var argValue2))
				{
					return false;
				}
				argListValue.Add(argValue2);
			}
			return true;
		}

		public static bool TryConvertValue<T>(string argName, string argStringValue, out T argValue)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (typeof(T) == typeof(string))
				{
					argValue = (T)(object)argStringValue;
				}
				else if (typeof(T) == typeof(Vector2))
				{
					argValue = (T)(object)ParseVector2(argStringValue);
				}
				else if (typeof(T) == typeof(Vector3))
				{
					argValue = (T)(object)ParseVector3(argStringValue);
				}
				else
				{
					argValue = (T)Convert.ChangeType(argStringValue, typeof(T));
				}
				return true;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)$"Failed to convert arg '{argName}' value '{argStringValue}' to type {typeof(T)}: {ex}");
			}
			argValue = default(T);
			return false;
		}

		public static Vector2 ParseVector2(string text)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			string[] array = text.Split(CommaSeparator, 2, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length == 2)
			{
				return new Vector2(float.Parse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture), float.Parse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture));
			}
			throw new InvalidOperationException("Could not parse " + text + " as Vector2.");
		}

		public static Vector3 ParseVector3(string text)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			string[] array = text.Split(CommaSeparator, 3, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length == 3 && float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
			{
				return new Vector3(result, result2, result3);
			}
			throw new InvalidOperationException("Could not parse " + text + " as Vector3.");
		}
	}
	[AttributeUsage(AttributeTargets.Method)]
	public sealed class ComfyCommand : Attribute
	{
	}
	public static class ComfyCommandUtils
	{
		private static readonly List<ConsoleCommand> _commands = new List<ConsoleCommand>();

		public static void ToggleCommands(bool toggleOn)
		{
			DeregisterCommands(_commands);
			_commands.Clear();
			if (toggleOn)
			{
				_commands.AddRange(RegisterCommands(Assembly.GetExecutingAssembly()));
			}
			UpdateCommandLists();
		}

		private static void UpdateCommandLists()
		{
			Terminal[] array = Object.FindObjectsOfType<Terminal>(true);
			for (int i = 0; i < array.Length; i++)
			{
				array[i].updateCommandList();
			}
		}

		private static void DeregisterCommands(List<ConsoleCommand> commands)
		{
			foreach (ConsoleCommand command in commands)
			{
				if (Terminal.commands[command.Command] == command)
				{
					Terminal.commands.Remove(command.Command);
				}
			}
		}

		private static IEnumerable<ConsoleCommand> RegisterCommands(Assembly assembly)
		{
			return (from method in assembly.GetTypes().SelectMany((Type type) => type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
				where method.GetCustomAttributes(typeof(ComfyCommand), inherit: false).Length != 0
				where IsRegisterCommandMethod(method) || IsRegisterCommandsMethod(method)
				select method).SelectMany((MethodInfo method) => RegisterCommands(method));
		}

		private static IEnumerable<ConsoleCommand> RegisterCommands(MethodInfo method)
		{
			if (IsRegisterCommandMethod(method))
			{
				yield return (ConsoleCommand)method.Invoke(null, null);
			}
			else
			{
				if (!IsRegisterCommandsMethod(method))
				{
					yield break;
				}
				foreach (ConsoleCommand item in (IEnumerable<ConsoleCommand>)method.Invoke(null, null))
				{
					yield return item;
				}
			}
		}

		private static bool IsRegisterCommandMethod(MethodInfo method)
		{
			if (method.GetParameters().Length == 0)
			{
				return typeof(ConsoleCommand).IsAssignableFrom(method.ReturnType);
			}
			return false;
		}

		private static bool IsRegisterCommandsMethod(MethodInfo method)
		{
			if (method.GetParameters().Length == 0)
			{
				return typeof(IEnumerable<ConsoleCommand>).IsAssignableFrom(method.ReturnType);
			}
			return false;
		}
	}
	public static class ConfigFileExtensions
	{
		internal sealed class ConfigurationManagerAttributes
		{
			public Action<ConfigEntryBase> CustomDrawer;

			public bool? Browsable;

			public bool? HideDefaultButton;

			public int? Order;
		}

		private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>();

		private static int GetSettingOrder(string section)
		{
			if (!_sectionToSettingOrder.TryGetValue(section, out var value))
			{
				value = 0;
			}
			_sectionToSettingOrder[section] = value - 1;
			return value;
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = GetSettingOrder(section)
				}
			}));
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Browsable = browsable,
					CustomDrawer = customDrawer,
					HideDefaultButton = hideDefaultButton,
					Order = GetSettingOrder(section)
				}
			}));
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler)
		{
			configEntry.SettingChanged += delegate
			{
				settingChangedHandler();
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}
	}
	public sealed class ExtendedColorConfigEntry
	{
		private static readonly Texture2D _colorTexture = GUIBuilder.CreateColorTexture(10, 10, Color.white);

		private readonly HexColorTextField _hexInput = new HexColorTextField();

		private readonly ColorPalette _colorPalette;

		private bool _showSliders;

		public ConfigEntry<Color> ConfigEntry { get; }

		public Color Value { get; private set; }

		public ColorFloatTextField RedInput { get; } = new ColorFloatTextField("R");


		public ColorFloatTextField GreenInput { get; } = new ColorFloatTextField("G");


		public ColorFloatTextField BlueInput { get; } = new ColorFloatTextField("B");


		public ColorFloatTextField AlphaInput { get; } = new ColorFloatTextField("A");


		public ExtendedColorConfigEntry(ConfigFile config, string section, string key, Color defaultValue, string description)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry = config.BindInOrder<Color>(section, key, defaultValue, description, Drawer, browsable: true, hideDefaultButton: false, hideSettingName: false);
			SetValue(ConfigEntry.Value);
		}

		public ExtendedColorConfigEntry(ConfigFile config, string section, string key, Color defaultValue, string description, string colorPaletteKey)
			: this(config, section, key, defaultValue, description)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<string> paletteConfigEntry = config.BindInOrder(section, colorPaletteKey, ColorUtility.ToHtmlStringRGBA(defaultValue) + ",FF0000FF,00FF00FF,0000FFFF", "Color palette for: [" + section + "] " + key, null, browsable: false);
			_colorPalette = new ColorPalette(this, paletteConfigEntry);
		}

		public void SetValue(Color value)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry.Value = value;
			Value = value;
			RedInput.SetValue(value.r);
			GreenInput.SetValue(value.g);
			BlueInput.SetValue(value.b);
			AlphaInput.SetValue(value.a);
			_hexInput.SetValue(value);
		}

		public void Drawer(ConfigEntryBase configEntry)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			Color val = (Color)configEntry.BoxedValue;
			if (GUIFocus.HasChanged() || GUIHelper.IsEnterPressed() || Value != val)
			{
				SetValue(val);
			}
			GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			_hexInput.DrawField();
			GUILayout.Space(3f);
			GUIHelper.BeginColor(val);
			GUILayout.Label(string.Empty, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if ((int)Event.current.type == 7)
			{
				GUI.DrawTexture(GUILayoutUtility.GetLastRect(), (Texture)(object)_colorTexture);
			}
			GUIHelper.EndColor();
			GUILayout.Space(3f);
			if (GUILayout.Button(_showSliders ? "∨" : "≡", (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MinWidth(40f),
				GUILayout.ExpandWidth(false)
			}))
			{
				_showSliders = !_showSliders;
			}
			GUILayout.EndHorizontal();
			if (_showSliders)
			{
				GUILayout.Space(4f);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				RedInput.DrawField();
				GUILayout.Space(3f);
				GreenInput.DrawField();
				GUILayout.Space(3f);
				BlueInput.DrawField();
				GUILayout.Space(3f);
				AlphaInput.DrawField();
				GUILayout.EndHorizontal();
			}
			if (_colorPalette != null)
			{
				GUILayout.Space(5f);
				_colorPalette.DrawColorPalette();
			}
			GUILayout.EndVertical();
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(RedInput.CurrentValue, GreenInput.CurrentValue, BlueInput.CurrentValue, AlphaInput.CurrentValue);
			if (val2 != val)
			{
				configEntry.BoxedValue = val2;
				SetValue(val2);
			}
			else if (_hexInput.CurrentValue != val)
			{
				configEntry.BoxedValue = _hexInput.CurrentValue;
				SetValue(_hexInput.CurrentValue);
			}
		}
	}
	public sealed class ColorPalette
	{
		private static readonly char[] _partSeparator = new char[1] { ',' };

		private static readonly string _partJoiner = ",";

		private static readonly Texture2D _colorTexture = GUIBuilder.CreateColorTexture(10, 10, Color.white);

		private readonly ExtendedColorConfigEntry _colorConfigEntry;

		private readonly ConfigEntry<string> _paletteConfigEntry;

		private readonly List<Color> _paletteColors;

		public ColorPalette(ExtendedColorConfigEntry colorConfigEntry, ConfigEntry<string> paletteConfigEntry)
		{
			_colorConfigEntry = colorConfigEntry;
			_paletteConfigEntry = paletteConfigEntry;
			_paletteColors = new List<Color>();
			LoadPalette();
		}

		private void LoadPalette()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			_paletteColors.Clear();
			string[] array = _paletteConfigEntry.Value.Split(_partSeparator, StringSplitOptions.RemoveEmptyEntries);
			Color item = default(Color);
			foreach (string text in array)
			{
				if (ColorUtility.TryParseHtmlString("#" + text, ref item))
				{
					_paletteColors.Add(item);
				}
			}
		}

		private void SavePalette()
		{
			((ConfigEntryBase)_paletteConfigEntry).BoxedValue = string.Join(_partJoiner, _paletteColors.Select((Color color) => ColorUtility.ToHtmlStringRGBA(color)));
		}

		private bool PaletteColorButtons(out int colorIndex)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			Texture2D background = GUI.skin.button.normal.background;
			GUI.skin.button.normal.background = _colorTexture;
			colorIndex = -1;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			for (int i = 0; i < _paletteColors.Count; i++)
			{
				GUIHelper.BeginColor(_paletteColors[i]);
				if (GUILayout.Button(string.Empty, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(20f),
					GUILayout.ExpandWidth(false)
				}))
				{
					colorIndex = i;
				}
				GUIHelper.EndColor();
				if (i + 1 < _paletteColors.Count && (i + 1) % 8 == 0)
				{
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			GUI.skin.button.normal.background = background;
			return colorIndex >= 0;
		}

		private bool AddColorButton()
		{
			return GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MinWidth(25f),
				GUILayout.ExpandWidth(false)
			});
		}

		private bool RemoveColorButton()
		{
			return GUILayout.Button("−", (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MinWidth(25f),
				GUILayout.ExpandWidth(false)
			});
		}

		private bool ResetColorsButton()
		{
			return GUILayout.Button("❇", (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MinWidth(25f),
				GUILayout.ExpandWidth(false)
			});
		}

		public void DrawColorPalette()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (AddColorButton())
			{
				_paletteColors.Add(_colorConfigEntry.Value);
				SavePalette();
			}
			GUILayout.Space(2f);
			if (PaletteColorButtons(out var colorIndex))
			{
				if (Event.current.button == 0)
				{
					_colorConfigEntry.SetValue(_paletteColors[colorIndex]);
				}
				else if (Event.current.button == 1 && colorIndex >= 0 && colorIndex < _paletteColors.Count)
				{
					_paletteColors.RemoveAt(colorIndex);
					SavePalette();
				}
			}
			GUILayout.FlexibleSpace();
			if (_paletteColors.Count > 0)
			{
				if (RemoveColorButton())
				{
					_paletteColors.RemoveAt(_paletteColors.Count - 1);
					SavePalette();
				}
			}
			else if (ResetColorsButton())
			{
				((ConfigEntryBase)_paletteConfigEntry).BoxedValue = ((ConfigEntryBase)_paletteConfigEntry).DefaultValue;
				LoadPalette();
			}
			GUILayout.EndHorizontal();
		}
	}
	public sealed class ColorFloatTextField
	{
		private string _fieldText;

		private Color _fieldColor;

		public string Label { get; set; }

		public float CurrentValue { get; private set; }

		public float MinValue { get; private set; }

		public float MaxValue { get; private set; }

		public void SetValue(float value)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			CurrentValue = Mathf.Clamp(value, MinValue, MaxValue);
			_fieldText = value.ToString("F3", CultureInfo.InvariantCulture);
			_fieldColor = GUI.color;
		}

		public void SetValueRange(float minValue, float maxValue)
		{
			MinValue = Mathf.Min(minValue, minValue);
			MaxValue = Mathf.Max(maxValue, maxValue);
		}

		public ColorFloatTextField(string label)
		{
			Label = label;
			SetValueRange(0f, 1f);
		}

		public void DrawField()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(Label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUIHelper.BeginColor(_fieldColor);
			string text = GUILayout.TextField(_fieldText, (GUILayoutOption[])(object)new GUILayoutOption[3]
			{
				GUILayout.MinWidth(45f),
				GUILayout.MaxWidth(55f),
				GUILayout.ExpandWidth(true)
			});
			GUIHelper.EndColor();
			GUILayout.EndHorizontal();
			GUILayout.Space(2f);
			float num = GUILayout.HorizontalSlider(CurrentValue, MinValue, MaxValue, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndVertical();
			if (num != CurrentValue)
			{
				SetValue(num);
			}
			else if (!(text == _fieldText))
			{
				if (float.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var result) && result >= MinValue && result <= MaxValue)
				{
					CurrentValue = result;
					_fieldColor = GUI.color;
				}
				else
				{
					_fieldColor = Color.red;
				}
				_fieldText = text;
			}
		}
	}
	public sealed class HexColorTextField
	{
		private Color _textColor = GUI.color;

		public Color CurrentValue { get; private set; }

		public string CurrentText { get; private set; }

		public void SetValue(Color value)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			CurrentValue = value;
			CurrentText = "#" + ((value.a == 1f) ? ColorUtility.ToHtmlStringRGB(value) : ColorUtility.ToHtmlStringRGBA(value));
			_textColor = GUI.color;
		}

		public void DrawField()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			GUIHelper.BeginColor(_textColor);
			string text = GUILayout.TextField(CurrentText, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(90f),
				GUILayout.ExpandWidth(false)
			});
			GUIHelper.EndColor();
			if (!(text == CurrentText))
			{
				CurrentText = text;
				Color currentValue = default(Color);
				if (ColorUtility.TryParseHtmlString(text, ref currentValue))
				{
					CurrentValue = currentValue;
				}
				else
				{
					_textColor = Color.red;
				}
			}
		}
	}
	public static class GUIBuilder
	{
		public static Texture2D CreateColorTexture(int width, int height, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			return CreateColorTexture(width, height, color, 0, color);
		}

		public static Texture2D CreateColorTexture(int width, int height, Color color, int radius, Color outsideColor)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			if (width <= 0 || height <= 0)
			{
				throw new ArgumentException("Texture width and height must be > 0.");
			}
			if (radius < 0 || radius > width || radius > height)
			{
				throw new ArgumentException("Texture radius must be >= 0 and < width/height.");
			}
			Texture2D val = new Texture2D(width, height, (TextureFormat)5, false);
			((Object)val).name = $"w-{width}-h-{height}-rad-{radius}-color-{ColorId(color)}-ocolor-{ColorId(outsideColor)}";
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)2;
			Texture2D val2 = val;
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					array[i * width + j] = (IsCornerPixel(j, i, width, height, radius) ? outsideColor : color);
				}
			}
			val2.SetPixels(array);
			val2.Apply();
			return val2;
		}

		private static string ColorId(Color color)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			return $"{color.r:F3}r-{color.g:F3}g-{color.b:F3}b-{color.a:F3}a";
		}

		private static bool IsCornerPixel(int x, int y, int w, int h, int rad)
		{
			if (rad == 0)
			{
				return false;
			}
			int num = Math.Min(x, w - x);
			int num2 = Math.Min(y, h - y);
			if (num == 0 && num2 == 0)
			{
				return true;
			}
			if (num > rad || num2 > rad)
			{
				return false;
			}
			num = rad - num;
			num2 = rad - num2;
			return Math.Round(Math.Sqrt(num * num + num2 * num2)) > (double)rad;
		}
	}
	public static class GUIFocus
	{
		private static int _lastFrameCount;

		private static int _lastHotControl;

		private static int _lastKeyboardControl;

		private static bool _hasChanged;

		public static bool HasChanged()
		{
			int frameCount = Time.frameCount;
			if (_lastFrameCount == frameCount)
			{
				return _hasChanged;
			}
			_lastFrameCount = frameCount;
			int hotControl = GUIUtility.hotControl;
			int keyboardControl = GUIUtility.keyboardControl;
			_hasChanged = hotControl != _lastHotControl || keyboardControl != _lastKeyboardControl;
			if (_hasChanged)
			{
				_lastHotControl = hotControl;
				_lastKeyboardControl = keyboardControl;
			}
			return _hasChanged;
		}
	}
	public static class GUIHelper
	{
		private static readonly Stack<Color> _colorStack = new Stack<Color>();

		public static void BeginColor(Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			_colorStack.Push(GUI.color);
			GUI.color = color;
		}

		public static void EndColor()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			GUI.color = _colorStack.Pop();
		}

		public static bool IsEnterPressed()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			if (Event.current.isKey)
			{
				if ((int)Event.current.keyCode != 13)
				{
					return (int)Event.current.keyCode == 271;
				}
				return true;
			}
			return false;
		}
	}
	public static class ComponentExtensions
	{
		public static bool TryGetComponentInParent<T>(this GameObject gameObject, out T component) where T : Component
		{
			component = gameObject.GetComponentInParent<T>();
			return Object.op_Implicit((Object)(object)component);
		}
	}
	public static class ObjectExtensions
	{
		public static T Ref<T>(this T unityObject) where T : Object
		{
			if (!Object.op_Implicit((Object)(object)unityObject))
			{
				return default(T);
			}
			return unityObject;
		}
	}
	public static class ZDOExtensions
	{
		public static bool TryGetVector3(this ZDO zdo, int keyHashCode, out Vector3 value)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (ZDOExtraData.s_vec3.TryGetValue(zdo.m_uid, out var value2) && value2.TryGetValue(keyHashCode, ref value))
			{
				return true;
			}
			value = default(Vector3);
			return false;
		}

		public static bool TryGetFloat(this ZDO zdo, int keyHashCode, out float value)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (ZDOExtraData.s_floats.TryGetValue(zdo.m_uid, out var value2) && value2.TryGetValue(keyHashCode, ref value))
			{
				return true;
			}
			value = 0f;
			return false;
		}
	}
}
namespace ColorfulPieces
{
	[BepInPlugin("redseiko.valheim.colorfulpieces", "ColorfulPieces", "1.15.1")]
	public sealed class ColorfulPieces : BaseUnityPlugin
	{
		public const string PluginGUID = "redseiko.valheim.colorfulpieces";

		public const string PluginName = "ColorfulPieces";

		public const string PluginVersion = "1.15.1";

		private static ManualLogSource _logger;

		private Harmony _harmony;

		private static readonly List<Piece> _piecesCache = new List<Piece>();

		private void Awake()
		{
			_logger = ((BaseUnityPlugin)this).Logger;
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.colorfulpieces");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private static bool ClaimOwnership(WearNTear wearNTear)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)wearNTear) || !Object.op_Implicit((Object)(object)wearNTear.m_nview) || !wearNTear.m_nview.IsValid() || !PrivateArea.CheckAccess(((Component)wearNTear).transform.position, 0f, true, false))
			{
				return false;
			}
			wearNTear.m_nview.ClaimOwnership();
			return true;
		}

		public static void ChangePieceColorAction(WearNTear wearNTear)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (!ClaimOwnership(wearNTear))
			{
				return;
			}
			ChangePieceColorZdo(wearNTear.m_nview);
			PieceColor pieceColor = default(PieceColor);
			if (((Component)wearNTear).TryGetComponent<PieceColor>(ref pieceColor))
			{
				pieceColor.UpdateColors();
			}
			Piece obj = wearNTear.m_piece.Ref<Piece>();
			if (obj != null)
			{
				EffectList placeEffect = obj.m_placeEffect;
				if (placeEffect != null)
				{
					placeEffect.Create(((Component)wearNTear).transform.position, ((Component)wearNTear).transform.rotation, (Transform)null, 1f, -1);
				}
			}
		}

		public static void ChangePieceColorAction(PieceColor pieceColor)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			ZNetView val = default(ZNetView);
			if (((Component)pieceColor).TryGetComponent<ZNetView>(ref val) && Object.op_Implicit((Object)(object)val) && val.IsValid() && PrivateArea.CheckAccess(((Component)pieceColor).transform.position, 0f, true, false))
			{
				val.ClaimOwnership();
				ChangePieceColorZdo(val);
				pieceColor.UpdateColors();
				Object.Instantiate<GameObject>(ZNetScene.s_instance.GetPrefab("vfx_boar_love"), ((Component)pieceColor).transform.position, ((Component)pieceColor).transform.rotation);
			}
		}

		private static void ChangePieceColorZdo(ZNetView netView)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			SetPieceColorZdoValues(netView.m_zdo, PluginConstants.ColorToVector3(PluginConfig.TargetPieceColor.Value), PluginConfig.TargetPieceEmissionColorFactor.Value);
		}

		public static IEnumerator ChangeColorsInRadiusCoroutine(Vector3 position, float radius, IReadOnlyCollection<int> prefabHashCodes)
		{
			yield return null;
			_piecesCache.Clear();
			GetAllPiecesInRadius(((Component)Player.m_localPlayer).transform.position, radius, _piecesCache);
			_piecesCache.RemoveAll((Piece piece) => !Object.op_Implicit((Object)(object)piece) || !Object.op_Implicit((Object)(object)piece.m_nview) || !piece.m_nview.IsValid());
			if (prefabHashCodes.Count() > 0)
			{
				_piecesCache.RemoveAll((Piece piece) => !prefabHashCodes.Contains(piece.m_nview.m_zdo.m_prefab));
			}
			long changeColorCount = 0L;
			WearNTear wearNTear = default(WearNTear);
			foreach (Piece piece2 in _piecesCache)
			{
				if (changeColorCount % 5 == 0L)
				{
					yield return null;
				}
				if (Object.op_Implicit((Object)(object)piece2) && ((Component)piece2).TryGetComponent<WearNTear>(ref wearNTear))
				{
					ChangePieceColorAction(wearNTear);
					changeColorCount++;
				}
			}
			LogInfo($"Changed color of {changeColorCount} pieces within {radius} meters.");
			_piecesCache.Clear();
		}

		public static void ClearPieceColorAction(WearNTear wearNTear)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if (!ClaimOwnership(wearNTear))
			{
				return;
			}
			SetPieceColorZdoValues(wearNTear.m_nview.m_zdo, PluginConstants.NoColorVector3, PluginConstants.NoEmissionColorFactor);
			PieceColor pieceColor = default(PieceColor);
			if (((Component)wearNTear).TryGetComponent<PieceColor>(ref pieceColor))
			{
				pieceColor.UpdateColors();
			}
			Piece obj = wearNTear.m_piece.Ref<Piece>();
			if (obj != null)
			{
				EffectList placeEffect = obj.m_placeEffect;
				if (placeEffect != null)
				{
					placeEffect.Create(((Component)wearNTear).transform.position, ((Component)wearNTear).transform.rotation, (Transform)null, 1f, -1);
				}
			}
		}

		public static IEnumerator ClearColorsInRadiusCoroutine(Vector3 position, float radius, IReadOnlyCollection<int> prefabHashCodes)
		{
			yield return null;
			_piecesCache.Clear();
			GetAllPiecesInRadius(((Component)Player.m_localPlayer).transform.position, radius, _piecesCache);
			_piecesCache.RemoveAll((Piece piece) => !Object.op_Implicit((Object)(object)piece) || !Object.op_Implicit((Object)(object)piece.m_nview) || !piece.m_nview.IsValid());
			if (prefabHashCodes.Count() > 0)
			{
				_piecesCache.RemoveAll((Piece piece) => !prefabHashCodes.Contains(piece.m_nview.m_zdo.m_prefab));
			}
			long clearColorCount = 0L;
			WearNTear wearNTear = default(WearNTear);
			foreach (Piece piece2 in _piecesCache)
			{
				if (clearColorCount % 5 == 0L)
				{
					yield return null;
				}
				if (Object.op_Implicit((Object)(object)piece2) && ((Component)piece2).TryGetComponent<WearNTear>(ref wearNTear))
				{
					ClearPieceColorAction(wearNTear);
					clearColorCount++;
				}
			}
			LogInfo($"Cleared colors from {clearColorCount} pieces within {radius} meters.");
		}

		public static bool CopyPieceColorAction(ZNetView netView)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)netView) || !netView.IsValid() || !netView.m_zdo.TryGetVector3(PluginConstants.PieceColorHashCode, out var value))
			{
				return false;
			}
			Color val = PluginConstants.Vector3ToColor(value);
			PluginConfig.TargetPieceColor.SetValue(val);
			if (netView.m_zdo.TryGetFloat(PluginConstants.PieceEmissionColorFactorHashCode, out var value2))
			{
				PluginConfig.TargetPieceEmissionColorFactor.Value = value2;
			}
			MessageHud obj = MessageHud.m_instance.Ref<MessageHud>();
			if (obj != null)
			{
				obj.ShowMessage((MessageType)1, $"Copied piece color: #{ColorUtility.ToHtmlStringRGB(val)} (f: {PluginConfig.TargetPieceEmissionColorFactor.Value})", 0, (Sprite)null);
			}
			return true;
		}

		public static void SetPieceColorZdoValues(ZDO zdo, Vector3 colorVector3, float emissionColorFactor)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			zdo.Set(PluginConstants.PieceColorHashCode, colorVector3);
			zdo.Set(PluginConstants.PieceEmissionColorFactorHashCode, emissionColorFactor);
			zdo.Set(PluginConstants.PieceLastColoredByHashCode, Player.m_localPlayer.GetPlayerID());
			zdo.Set(PluginConstants.PieceLastColoredByHostHashCode, PrivilegeManager.GetNetworkUserId());
		}

		public static void GetAllPiecesInRadius(Vector3 position, float radius, List<Piece> pieces)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			foreach (Piece s_allPiece in Piece.s_allPieces)
			{
				if (((Component)s_allPiece).gameObject.layer != Piece.s_ghostLayer && !(Vector3.Distance(position, ((Component)s_allPiece).transform.position) >= radius))
				{
					pieces.Add(s_allPiece);
				}
			}
		}

		public static void LogInfo(object obj)
		{
			_logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
			Chat obj2 = Chat.m_instance.Ref<Chat>();
			if (obj2 != null)
			{
				((Terminal)obj2).AddString(obj.ToString());
			}
		}

		public static void LogError(object obj)
		{
			_logger.LogError((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
			Chat obj2 = Chat.m_instance.Ref<Chat>();
			if (obj2 != null)
			{
				((Terminal)obj2).AddString(obj.ToString());
			}
		}
	}
	public static class ChangeColorCommand
	{
		[ComfyCommand]
		public static IEnumerable<ConsoleCommand> Register()
		{
			yield return new ConsoleCommand("changecolor", "(ColorfulPieces) Changes the color of all pieces within radius of player to the currently set color.", new ConsoleEventFailable(RunLegacy), false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			yield return new ConsoleCommand("change-color", "(ColorfulPieces) change-color --radius=<r> [--prefab=<name1>]", new ConsoleEventFailable(Run), false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}

		public static object RunLegacy(ConsoleEventArgs args)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (args.Length < 2 || !float.TryParse(args.Args[1], out var result) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return false;
			}
			((MonoBehaviour)Game.instance).StartCoroutine(ColorfulPieces.ChangeColorsInRadiusCoroutine(((Component)Player.m_localPlayer).transform.position, result, (IReadOnlyCollection<int>)(object)Array.Empty<int>()));
			return true;
		}

		public static object Run(ConsoleEventArgs args)
		{
			return Run(new ComfyArgs(args));
		}

		public static bool Run(ComfyArgs args)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			ColorfulPieces.LogInfo(args.Args.FullLine);
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				ColorfulPieces.LogError("Missing local player.");
				return false;
			}
			if (!args.TryGetValue("radius", "r", out float argValue))
			{
				ColorfulPieces.LogError("Missing --radius arg.");
				return false;
			}
			if (argValue < 0f)
			{
				ColorfulPieces.LogError("Invalid --radius arg, cannot be less than 0.");
				return false;
			}
			HashSet<int> hashSet = new HashSet<int>();
			if (args.TryGetListValue("prefab", "p", out List<string> argListValue))
			{
				foreach (string item in argListValue)
				{
					hashSet.Add(StringExtensionMethods.GetStableHashCode(item));
				}
			}
			((MonoBehaviour)Game.instance).StartCoroutine(ColorfulPieces.ChangeColorsInRadiusCoroutine(((Component)Player.m_localPlayer).transform.position, argValue, hashSet));
			return true;
		}
	}
	public static class ClearColorCommand
	{
		[ComfyCommand]
		public static IEnumerable<ConsoleCommand> Register()
		{
			yield return new ConsoleCommand("clearcolor", "(ColorfulPieces) Clears all colors applied to all pieces within radius of player.", new ConsoleEventFailable(RunLegacy), false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			yield return new ConsoleCommand("clear-color", "(ColorfulPieces) clear-color --radius=<r> [--prefab=<name1>]", new ConsoleEventFailable(Run), false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}

		public static object RunLegacy(ConsoleEventArgs args)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (args.Length < 2 || !float.TryParse(args.Args[1], out var result) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return false;
			}
			((MonoBehaviour)Game.instance).StartCoroutine(ColorfulPieces.ClearColorsInRadiusCoroutine(((Component)Player.m_localPlayer).transform.position, result, (IReadOnlyCollection<int>)(object)Array.Empty<int>()));
			return true;
		}

		public static object Run(ConsoleEventArgs args)
		{
			return Run(new ComfyArgs(args));
		}

		public static bool Run(ComfyArgs args)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			ColorfulPieces.LogInfo(args.Args.FullLine);
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				ColorfulPieces.LogError("Missing local player.");
				return false;
			}
			if (!args.TryGetValue("radius", "r", out float argValue))
			{
				ColorfulPieces.LogError("Missing --radius arg.");
				return false;
			}
			if (argValue < 0f)
			{
				ColorfulPieces.LogError("Invalid --radius arg, cannot be less than 0.");
				return false;
			}
			HashSet<int> hashSet = new HashSet<int>();
			if (args.TryGetListValue("prefab", "p", out List<string> argListValue))
			{
				foreach (string item in argListValue)
				{
					hashSet.Add(StringExtensionMethods.GetStableHashCode(item));
				}
			}
			((MonoBehaviour)Game.instance).StartCoroutine(ColorfulPieces.ClearColorsInRadiusCoroutine(((Component)Player.m_localPlayer).transform.position, argValue, hashSet));
			return true;
		}
	}
	public sealed class PieceColor : MonoBehaviour
	{
		public static readonly Dictionary<int, int> RendererCountCache = new Dictionary<int, int>();

		public static readonly List<PieceColor> PieceColorCache = new List<PieceColor>();

		private readonly List<Renderer> _renderers = new List<Renderer>(0);

		private IPieceColorRenderer _pieceColorRenderer;

		private int _cacheIndex;

		private long _lastDataRevision;

		private Vector3 _lastColorVec3;

		private float _lastEmissionColorFactor;

		private Color _lastColor;

		private Color _lastEmissionColor;

		private ZNetView _netView;

		public Color TargetColor { get; set; } = Color.clear;


		public float TargetEmissionColorFactor { get; set; }

		private void Awake()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			_renderers.Clear();
			_lastDataRevision = -1L;
			_lastColorVec3 = PluginConstants.NoColorVector3;
			_lastEmissionColorFactor = PluginConstants.NoEmissionColorFactor;
			_cacheIndex = -1;
			_netView = ((Component)this).GetComponent<ZNetView>();
			if (Object.op_Implicit((Object)(object)_netView) && _netView.IsValid())
			{
				PieceColorCache.Add(this);
				_cacheIndex = PieceColorCache.Count - 1;
				int prefab = _netView.m_zdo.m_prefab;
				CacheRenderers(prefab);
				_pieceColorRenderer = GetPieceColorRenderer(prefab);
			}
		}

		private static IPieceColorRenderer GetPieceColorRenderer(int prefabHash)
		{
			if (prefabHash == PluginConstants.GuardStoneHashCode)
			{
				return GuardStonePieceColorRenderer.Instance;
			}
			if (prefabHash == PluginConstants.PortalWoodHashCode)
			{
				return PortalWoodPieceColorRenderer.Instance;
			}
			return DefaultPieceColorRenderer.Instance;
		}

		private void OnDestroy()
		{
			if (_cacheIndex >= 0 && _cacheIndex < PieceColorCache.Count)
			{
				PieceColorCache[_cacheIndex] = PieceColorCache[PieceColorCache.Count - 1];
				PieceColorCache[_cacheIndex]._cacheIndex = _cacheIndex;
				PieceColorCache.RemoveAt(PieceColorCache.Count - 1);
			}
			_renderers.Clear();
		}

		private void CacheRenderers(int prefabHash)
		{
			if (RendererCountCache.TryGetValue(prefabHash, out var value))
			{
				_renderers.Capacity = value;
			}
			_renderers.AddRange((IEnumerable<Renderer>)(object)((Component)this).gameObject.GetComponentsInChildren<MeshRenderer>(true));
			_renderers.AddRange((IEnumerable<Renderer>)(object)((Component)this).gameObject.GetComponentsInChildren<SkinnedMeshRenderer>(true));
			if (_renderers.Count != value)
			{
				RendererCountCache[prefabHash] = _renderers.Count;
				_renderers.Capacity = _renderers.Count;
			}
		}

		public void UpdateColors(bool forceUpdate = false)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_netView) || !_netView.IsValid() || (!forceUpdate && _lastDataRevision >= _netView.m_zdo.DataRevision))
			{
				return;
			}
			bool flag = true;
			_lastDataRevision = _netView.m_zdo.DataRevision;
			if (!_netView.m_zdo.TryGetVector3(PluginConstants.PieceColorHashCode, out var value) || value == PluginConstants.NoColorVector3)
			{
				value = PluginConstants.NoColorVector3;
				flag = false;
			}
			if (!_netView.m_zdo.TryGetFloat(PluginConstants.PieceEmissionColorFactorHashCode, out var value2) || value2 == PluginConstants.NoEmissionColorFactor)
			{
				value2 = PluginConstants.NoEmissionColorFactor;
				flag = false;
			}
			if (forceUpdate || !(value == _lastColorVec3) || value2 != _lastEmissionColorFactor)
			{
				_lastColorVec3 = value;
				_lastEmissionColorFactor = value2;
				if (flag)
				{
					TargetColor = PluginConstants.Vector3ToColor(value);
					TargetEmissionColorFactor = value2;
					_pieceColorRenderer.SetColors(_renderers, TargetColor, TargetColor * TargetEmissionColorFactor);
				}
				else
				{
					TargetColor = Color.clear;
					TargetEmissionColorFactor = 0f;
					_pieceColorRenderer.ClearColors(_renderers);
				}
				_lastColor = TargetColor;
				_lastEmissionColor = TargetColor * TargetEmissionColorFactor;
			}
		}

		public void OverrideColors(Color color, Color emissionColor)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!(color == _lastColor) || !(emissionColor == _lastEmissionColor))
			{
				_lastColor = color;
				_lastEmissionColor = emissionColor;
				_pieceColorRenderer.SetColors(_renderers, color, emissionColor);
			}
		}
	}
	public interface IPieceColorRenderer
	{
		void SetColors(List<Renderer> renderers, Color color, Color emissionColor);

		void ClearColors(List<Renderer> renderers);
	}
	public sealed class DefaultPieceColorRenderer : IPieceColorRenderer
	{
		private readonly MaterialPropertyBlock _propertyBlock = new MaterialPropertyBlock();

		public static DefaultPieceColorRenderer Instance { get; } = new DefaultPieceColorRenderer();


		public void SetColors(List<Renderer> renderers, Color color, Color emissionColor)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			_propertyBlock.SetColor(PluginConstants.ColorShaderId, color);
			_propertyBlock.SetColor(PluginConstants.EmissionColorShaderId, emissionColor);
			foreach (Renderer renderer in renderers)
			{
				renderer.SetPropertyBlock(_propertyBlock);
			}
		}

		public void ClearColors(List<Renderer> renderers)
		{
			_propertyBlock.Clear();
			foreach (Renderer renderer in renderers)
			{
				renderer.SetPropertyBlock((MaterialPropertyBlock)null);
			}
		}
	}
	public sealed class GuardStonePieceColorRenderer : IPieceColorRenderer
	{
		private readonly MaterialPropertyBlock _propertyBlock = new MaterialPropertyBlock();

		public static GuardStonePieceColorRenderer Instance { get; } = new GuardStonePieceColorRenderer();


		public void SetColors(List<Renderer> renderers, Color color, Color emissionColor)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			_propertyBlock.SetColor(PluginConstants.ColorShaderId, color);
			_propertyBlock.SetColor(PluginConstants.EmissionColorShaderId, emissionColor);
			foreach (Renderer renderer in renderers)
			{
				renderer.SetPropertyBlock(_propertyBlock, 1);
			}
		}

		public void ClearColors(List<Renderer> renderers)
		{
			_propertyBlock.Clear();
			foreach (Renderer renderer in renderers)
			{
				renderer.SetPropertyBlock((MaterialPropertyBlock)null, 1);
			}
		}
	}
	public sealed class PortalWoodPieceColorRenderer : IPieceColorRenderer
	{
		private readonly MaterialPropertyBlock _propertyBlock = new MaterialPropertyBlock();

		public static PortalWoodPieceColorRenderer Instance { get; } = new PortalWoodPieceColorRenderer();


		public void SetColors(List<Renderer> renderers, Color color, Color emissionColor)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			_propertyBlock.SetColor(PluginConstants.ColorShaderId, color);
			foreach (Renderer renderer in renderers)
			{
				renderer.SetPropertyBlock(_propertyBlock);
			}
		}

		public void ClearColors(List<Renderer> renderers)
		{
			_propertyBlock.Clear();
			foreach (Renderer renderer in renderers)
			{
				renderer.SetPropertyBlock((MaterialPropertyBlock)null);
			}
		}
	}
	public sealed class PieceColorUpdater : MonoBehaviour
	{
		private void Awake()
		{
			((MonoBehaviour)this).StartCoroutine(UpdatePieceColors());
		}

		private IEnumerator UpdatePieceColors()
		{
			WaitForSeconds waitInterval = new WaitForSeconds(PluginConfig.UpdateColorsWaitInterval.Value);
			while (true)
			{
				int frameLimit = PluginConfig.UpdateColorsFrameLimit.Value;
				int index = 0;
				while (index < PieceColor.PieceColorCache.Count)
				{
					for (int i = 0; i < frameLimit; i++)
					{
						if (PieceColor.PieceColorCache.Count <= 0)
						{
							break;
						}
						if (index >= PieceColor.PieceColorCache.Count)
						{
							break;
						}
						PieceColor.PieceColorCache[index].UpdateColors();
						index++;
					}
					yield return null;
				}
				yield return waitInterval;
			}
		}
	}
	public static class ShortcutUtils
	{
		public static bool OnChangePieceColorShortcut(GameObject hovering)
		{
			if (hovering.TryGetComponentInParent<WearNTear>(out WearNTear component))
			{
				ColorfulPieces.ChangePieceColorAction(component);
				return true;
			}
			return false;
		}

		public static bool OnClearPieceColorShortcut(GameObject hovering)
		{
			if (hovering.TryGetComponentInParent<WearNTear>(out WearNTear component))
			{
				ColorfulPieces.ClearPieceColorAction(component);
				return true;
			}
			return false;
		}

		public static bool OnCopyPieceColorShortcut(GameObject hovering)
		{
			if (hovering.TryGetComponentInParent<WearNTear>(out WearNTear component))
			{
				ColorfulPieces.CopyPieceColorAction(component.m_nview);
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Hud))]
	internal static class HudPatch
	{
		private static readonly string HoverNameTextTemplate = "{0}{1}<size={9}>[<color={2}>{3}</color>] Set piece color: <color=#{4}>#{4}</color> (<color=#{4}>{5}</color>)\n[<color={6}>{7}</color>] Clear piece color\n[<color={6}>{8}</color>] Copy piece color\n</size>";

		[HarmonyPostfix]
		[HarmonyPatch("UpdateCrosshair")]
		private static void UpdateCrosshairPostfix(ref Hud __instance, ref Player player)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			if (PluginConfig.IsModEnabled.Value && PluginConfig.ShowChangeRemoveColorPrompt.Value && Object.op_Implicit((Object)(object)Player.m_localPlayer.Ref<Player>()?.m_hovering))
			{
				WearNTear componentInParent = player.m_hovering.GetComponentInParent<WearNTear>();
				if (Object.op_Implicit((Object)(object)componentInParent.Ref<WearNTear>()?.m_nview) && componentInParent.m_nview.IsValid())
				{
					((TMP_Text)__instance.m_hoverName).text = string.Format(HoverNameTextTemplate, ((TMP_Text)__instance.m_hoverName).text, (((TMP_Text)__instance.m_hoverName).text.Length > 0) ? "\n" : string.Empty, "#FFA726", PluginConfig.ChangePieceColorShortcut.Value, ColorUtility.ToHtmlStringRGB(PluginConfig.TargetPieceColor.Value), PluginConfig.TargetPieceEmissionColorFactor.Value.ToString("N2"), "#EF5350", PluginConfig.ClearPieceColorShortcut.Value, PluginConfig.CopyPieceColorShortcut.Value, PluginConfig.ColorPromptFontSize.Value);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player))]
	internal static class PlayerPatch
	{
		[HarmonyTranspiler]
		[HarmonyPatch("Update")]
		private static IEnumerable<CodeInstruction> UpdateTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Player), "UpdateHover", (Type[])null, (Type[])null), (string)null)
			}).Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Ldloc_1, (object)null),
				Transpilers.EmitDelegate<Action<bool>>((Action<bool>)UpdateHoverPostDelegate)
			})
				.InstructionEnumeration();
		}

		private static void UpdateHoverPostDelegate(bool takeInput)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (takeInput && PluginConfig.IsModEnabled.Value && Player.m_localPlayer.TryGetHovering(out var hovering))
			{
				KeyboardShortcut value = PluginConfig.ChangePieceColorShortcut.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					ShortcutUtils.OnChangePieceColorShortcut(hovering);
				}
				value = PluginConfig.ClearPieceColorShortcut.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					ShortcutUtils.OnClearPieceColorShortcut(hovering);
				}
				value = PluginConfig.CopyPieceColorShortcut.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					ShortcutUtils.OnCopyPieceColorShortcut(hovering);
				}
			}
		}

		private static bool TryGetHovering(this Player player, out GameObject hovering)
		{
			hovering = (Object.op_Implicit((Object)(object)player) ? player.m_hovering : null);
			return Object.op_Implicit((Object)(object)hovering);
		}
	}
	[HarmonyPatch(typeof(StaticPhysics))]
	internal static class StaticPhysicsPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void Awake(StaticPhysics __instance)
		{
			PieceColor pieceColor = default(PieceColor);
			if (PluginConfig.IsModEnabled.Value && !((Component)__instance).gameObject.TryGetComponent<PieceColor>(ref pieceColor))
			{
				((Component)__instance).gameObject.AddComponent<PieceColor>();
			}
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal static class TerminalPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("InitTerminal")]
		private static void InitTerminalPrefix(ref bool __state)
		{
			__state = Terminal.m_terminalInitialized;
		}

		[HarmonyPostfix]
		[HarmonyPatch("InitTerminal")]
		private static void InitTerminalPostfix(bool __state)
		{
			if (!__state)
			{
				ComfyCommandUtils.ToggleCommands(PluginConfig.IsModEnabled.Value);
			}
		}
	}
	[HarmonyPatch(typeof(Game))]
	internal static class GamePatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void StartPostfix(Game __instance)
		{
			if (PluginConfig.IsModEnabled.Value)
			{
				((Component)__instance).gameObject.AddComponent<PieceColorUpdater>();
			}
		}
	}
	[HarmonyPatch(typeof(WearNTear))]
	internal static class WearNTearPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(WearNTear __instance)
		{
			if (PluginConfig.IsModEnabled.Value)
			{
				((Component)__instance).gameObject.AddComponent<PieceColor>();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Highlight")]
		private static bool HighlightPrefix(WearNTear __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			PieceColor pieceColor = default(PieceColor);
			if (PluginConfig.IsModEnabled.Value && ((Component)__instance).TryGetComponent<PieceColor>(ref pieceColor))
			{
				Color supportColor = GetSupportColor(__instance.GetSupportColorValue());
				pieceColor.OverrideColors(supportColor, supportColor * 0.4f);
				((MonoBehaviour)__instance).CancelInvoke("ResetHighlight");
				((MonoBehaviour)__instance).Invoke("ResetHighlight", 0.2f);
				return false;
			}
			return true;
		}

		private static Color GetSupportColor(float supportColorValue)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			((Color)(ref val))..ctor(0.6f, 0.8f, 1f);
			if (supportColorValue >= 0f)
			{
				val = Color.Lerp(PluginConfig.PieceStabilityMinColor.Value, PluginConfig.PieceStabilityMaxColor.Value, supportColorValue);
				float num = default(float);
				float num2 = default(float);
				float num3 = default(float);
				Color.RGBToHSV(val, ref num, ref num2, ref num3);
				float num4 = Mathf.Lerp(1f, 0.5f, supportColorValue);
				float num5 = Mathf.Lerp(1.2f, 0.9f, supportColorValue);
				val = Color.HSVToRGB(num, num4, num5);
			}
			return val;
		}

		[HarmonyPrefix]
		[HarmonyPatch("ResetHighlight")]
		private static void ResetHighlightPrefix(ref WearNTear __instance)
		{
			PieceColor pieceColor = default(PieceColor);
			if (PluginConfig.IsModEnabled.Value && ((Component)__instance).TryGetComponent<PieceColor>(ref pieceColor))
			{
				pieceColor.UpdateColors(forceUpdate: true);
			}
		}
	}
	public static class PluginConfig
	{
		public static ConfigEntry<bool> IsModEnabled { get; private set; }

		public static ConfigEntry<KeyboardShortcut> ChangePieceColorShortcut { get; private set; }

		public static ConfigEntry<KeyboardShortcut> ClearPieceColorShortcut { get; private set; }

		public static ConfigEntry<KeyboardShortcut> CopyPieceColorShortcut { get; private set; }

		public static ExtendedColorConfigEntry TargetPieceColor { get; private set; }

		public static ConfigEntry<float> TargetPieceEmissionColorFactor { get; private set; }

		public static ConfigEntry<bool> ShowChangeRemoveColorPrompt { get; private set; }

		public static ConfigEntry<int> ColorPromptFontSize { get; private set; }

		public static ConfigEntry<int> UpdateColorsFrameLimit { get; private set; }

		public static ConfigEntry<float> UpdateColorsWaitInterval { get; private set; }

		public static ExtendedColorConfigEntry PieceStabilityMinColor { get; private set; }

		public static ExtendedColorConfigEntry PieceStabilityMaxColor { get; private set; }

		public static void BindConfig(ConfigFile config)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod.");
			IsModEnabled.OnSettingChanged<bool>(ComfyCommandUtils.ToggleCommands);
			ChangePieceColorShortcut = config.BindInOrder<KeyboardShortcut>("Hotkeys", "changePieceColorShortcut", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Shortcut to change the color of the hovered piece.");
			ClearPieceColorShortcut = config.BindInOrder<KeyboardShortcut>("Hotkeys", "clearPieceColorShortcut", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Shortcut to clear the color of the hovered piece.");
			CopyPieceColorShortcut = config.BindInOrder<KeyboardShortcut>("Hotkeys", "copyPieceColorShortcut", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Shortcut to copy the color of the hovered piece.");
			TargetPieceColor = new ExtendedColorConfigEntry(config, "Color", "targetPieceColor", Color.cyan, "Target color to set the piece material to.", "targetPieceColorPalette");
			TargetPieceColor.AlphaInput.SetValueRange(1f, 1f);
			TargetPieceEmissionColorFactor = config.BindInOrder("Color", "targetPieceEmissionColorFactor", 0.4f, "Factor to multiply the target color by and set as emission color.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.8f));
			ShowChangeRemoveColorPrompt = config.BindInOrder("Hud", "showChangeRemoveColorPrompt", defaultValue: false, "Show the 'change/remove/copy' color text prompt.");
			ColorPromptFontSize = config.BindInOrder("Hud", "colorPromptFontSize", 15, "Font size for the 'change/remove/copy' color text prompt.");
			BindUpdateColorsConfig(config);
			BindPieceStabilityColorsConfig(config);
		}

		private static void BindUpdateColorsConfig(ConfigFile config)
		{
			UpdateColorsFrameLimit = config.BindInOrder("UpdateColors", "updateColorsFrameLimit", 100, "Limit for how many PieceColor.UpdateColors to process per update frame.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 250));
			UpdateColorsWaitInterval = config.BindInOrder("UpdateColors", "updateColorsWaitInterval", 5f, "Interval to wait after each PieceColor.UpdateColors loop. *Restart required!*", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f));
		}

		private static void BindPieceStabilityColorsConfig(ConfigFile config)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			PieceStabilityMinColor = new ExtendedColorConfigEntry(config, "PieceStabilityColors", "pieceStabilityMinColor", Color.red, "Color for the Piece Stability highlighting gradient to use for minimum stability.");
			PieceStabilityMaxColor = new ExtendedColorConfigEntry(config, "PieceStabilityColors", "pieceStabilityMaxColor", Color.green, "Color for the Piece Stability highlighting gradient to use for maximum stability.");
		}
	}
	public static class PluginConstants
	{
		public static readonly int ColorShaderId = Shader.PropertyToID("_Color");

		public static readonly int EmissionColorShaderId = Shader.PropertyToID("_EmissionColor");

		public static readonly int PieceColorHashCode = StringExtensionMethods.GetStableHashCode("PieceColor");

		public static readonly int PieceEmissionColorFactorHashCode = StringExtensionMethods.GetStableHashCode("PieceEmissionColorFactor");

		public static readonly int PieceLastColoredByHashCode = StringExtensionMethods.GetStableHashCode("PieceLastColoredBy");

		public static readonly int PieceLastColoredByHostHashCode = StringExtensionMethods.GetStableHashCode("PieceLastColoredByHost");

		public static readonly int GuardStoneHashCode = StringExtensionMethods.GetStableHashCode("guard_stone");

		public static readonly int PortalWoodHashCode = StringExtensionMethods.GetStableHashCode("portal_wood");

		public static readonly Vector3 NoColorVector3 = new Vector3(-1f, -1f, -1f);

		public static readonly float NoEmissionColorFactor = -1f;

		public static readonly Vector3 ColorBlackVector3 = new Vector3(0.00012345f, 0.00012345f, 0.00012345f);

		public static Vector3 ColorToVector3(Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!(color == Color.black))
			{
				return new Vector3(color.r, color.g, color.b);
			}
			return ColorBlackVector3;
		}

		public static Color Vector3ToColor(Vector3 vector3)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!(vector3 == ColorBlackVector3))
			{
				return new Color(vector3.x, vector3.y, vector3.z);
			}
			return Color.black;
		}
	}
}