Decompiled source of PotatoDye v1.0.0

plugins/PotatoDye.dll

Decompiled 20 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace PotatoDye;

[BepInPlugin("potato.dye", "Potato Dye", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "Update")]
	internal static class Publish
	{
		private static float next;

		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || (!Previewing && Time.time < next))
			{
				return;
			}
			if (Previewing && !((Character)__instance).IsAttached())
			{
				Previewing = false;
				Preview = null;
			}
			next = Time.time + 0.25f;
			ZNetView obj = CharacterView.Invoke((Character)(object)__instance);
			ZDO val = ((obj != null) ? obj.GetZDO() : null);
			if (val != null && val.IsOwner())
			{
				int num = val.GetInt(ZDOVars.s_shoulderItem, 0);
				int num2 = ((num != 0) ? Packed(Previewing ? Preview : SavedColor(__instance, num)) : 0);
				if (val.GetInt(ZdoKey, 0) != num2)
				{
					val.Set(ZdoKey, num2, false);
				}
				if (val.GetInt(ZdoFor, 0) != num)
				{
					val.Set(ZdoFor, num, false);
				}
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")]
	internal static class Draw
	{
		private sealed class State
		{
			internal List<GameObject> Instances;

			internal int Packed;

			internal float Next;

			internal readonly List<GameObject> Tinted = new List<GameObject>();
		}

		private static readonly ConditionalWeakTable<VisEquipment, State> States = new ConditionalWeakTable<VisEquipment, State>();

		private static readonly FieldRef<VisEquipment, ZNetView> View = AccessTools.FieldRefAccess<VisEquipment, ZNetView>("m_nview");

		private static readonly FieldRef<VisEquipment, List<GameObject>> Instances = AccessTools.FieldRefAccess<VisEquipment, List<GameObject>>("m_shoulderItemInstances");

		private static readonly FieldRef<VisEquipment, int> Drawn = AccessTools.FieldRefAccess<VisEquipment, int>("m_currentShoulderItemHash");

		private static readonly int ColorId = Shader.PropertyToID("_Color");

		private static void Postfix(VisEquipment __instance)
		{
			if (!__instance.m_isPlayer || __instance.m_isArmorStand || (Object)(object)MaterialMan.instance == (Object)null)
			{
				return;
			}
			ZNetView obj = View.Invoke(__instance);
			ZDO val = ((obj != null) ? obj.GetZDO() : null);
			int num = ((ShowColors.Value && val != null && val.GetInt(ZdoFor, 0) == Drawn.Invoke(__instance)) ? val.GetInt(ZdoKey, 0) : 0);
			List<GameObject> list = Instances.Invoke(__instance);
			State orCreateValue = States.GetOrCreateValue(__instance);
			if (orCreateValue.Instances == list && orCreateValue.Packed == num && (num == 0 || Time.time < orCreateValue.Next))
			{
				return;
			}
			if (orCreateValue.Instances != list)
			{
				orCreateValue.Tinted.Clear();
			}
			orCreateValue.Instances = list;
			orCreateValue.Packed = num;
			orCreateValue.Next = Time.time + 2f;
			try
			{
				Apply(list, num, orCreateValue);
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Couldn't color a cape: " + ex.Message));
			}
		}

		private static void Apply(List<GameObject> instances, int packed, State state)
		{
			//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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			if (packed == 0)
			{
				foreach (GameObject item in state.Tinted)
				{
					if (Object.op_Implicit((Object)(object)item))
					{
						MaterialMan.instance.ResetValue(item, ColorId);
					}
				}
				state.Tinted.Clear();
			}
			else
			{
				if (instances == null)
				{
					return;
				}
				Color val = FromRgb(packed & 0xFFFFFF);
				foreach (GameObject instance in instances)
				{
					if (!Object.op_Implicit((Object)(object)instance))
					{
						continue;
					}
					ItemStyle componentInChildren = instance.GetComponentInChildren<ItemStyle>(true);
					GameObject val2 = (Object.op_Implicit((Object)(object)componentInChildren) ? ((Component)componentInChildren).gameObject : instance);
					Color val3 = Color.white;
					Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						Material sharedMaterial = componentsInChildren[i].sharedMaterial;
						if (Object.op_Implicit((Object)(object)sharedMaterial) && sharedMaterial.HasProperty(ColorId))
						{
							val3 = sharedMaterial.GetColor(ColorId);
							break;
						}
					}
					MaterialMan.instance.SetValue<Color>(val2, ColorId, val3 * val, true);
					if (!state.Tinted.Contains(val2))
					{
						state.Tinted.Add(val2);
					}
				}
			}
		}
	}

	public const string Id = "potato.dye";

	public const string Version = "1.0.0";

	internal const string SaveKey = "PotatoDye.Capes";

	internal static readonly int ZdoKey = StringExtensionMethods.GetStableHashCode("PotatoDye.Cape");

	internal static readonly int ZdoFor = StringExtensionMethods.GetStableHashCode("PotatoDye.CapeFor");

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> ShowColors;

	internal static ConfigEntry<bool> BarberPanel;

	private static readonly FieldRef<Character, ZNetView> CharacterView = AccessTools.FieldRefAccess<Character, ZNetView>("m_nview");

	internal static Color? Preview;

	internal static bool Previewing;

	private void Awake()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		ShowColors = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Show cape colors", true, "Show dyed capes in their colors, yours and other players'.");
		BarberPanel = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Barber panel", true, "Show the Cape color panel at the barber.");
		new Harmony("potato.dye").PatchAll(typeof(Plugin).Assembly);
	}

	internal static bool TryParse(string text, out Color color)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: 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)
		color = Color.white;
		if (string.IsNullOrEmpty(text) || text.Length != 6 || !int.TryParse(text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result))
		{
			return false;
		}
		color = FromRgb(result);
		return true;
	}

	internal static string ToHex(Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		return (ToRgb(color) & 0xFFFFFF).ToString("X6", CultureInfo.InvariantCulture);
	}

	internal static int ToRgb(Color color)
	{
		//IL_0000: 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_0032: Unknown result type (might be due to invalid IL or missing references)
		return (Mathf.RoundToInt(Mathf.Clamp01(color.r) * 255f) << 16) | (Mathf.RoundToInt(Mathf.Clamp01(color.g) * 255f) << 8) | Mathf.RoundToInt(Mathf.Clamp01(color.b) * 255f);
	}

	internal static Color FromRgb(int rgb)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		return new Color((float)((rgb >> 16) & 0xFF) / 255f, (float)((rgb >> 8) & 0xFF) / 255f, (float)(rgb & 0xFF) / 255f, 1f);
	}

	internal static bool IsPlain(Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		return ToRgb(color) == 16777215;
	}

	internal static int Packed(Color? color)
	{
		//IL_000b: 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)
		if (!color.HasValue || IsPlain(color.Value))
		{
			return 0;
		}
		return 0x1000000 | ToRgb(color.Value);
	}

	internal static Dictionary<string, Color> Saved(Player player)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<string, Color> dictionary = new Dictionary<string, Color>();
		if ((Object)(object)player == (Object)null || !player.m_customData.TryGetValue("PotatoDye.Capes", out var value))
		{
			return dictionary;
		}
		string[] array = value.Split(';');
		foreach (string text in array)
		{
			int num = text.IndexOf('=');
			if (num > 0 && TryParse(text.Substring(num + 1), out var color))
			{
				dictionary[text.Substring(0, num)] = color;
			}
		}
		return dictionary;
	}

	internal static void Save(Player player, string cape, Color? color)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null || string.IsNullOrEmpty(cape))
		{
			return;
		}
		Dictionary<string, Color> dictionary = Saved(player);
		if (!color.HasValue || IsPlain(color.Value))
		{
			dictionary.Remove(cape);
		}
		else
		{
			dictionary[cape] = color.Value;
		}
		if (dictionary.Count == 0)
		{
			player.m_customData.Remove("PotatoDye.Capes");
			return;
		}
		player.m_customData["PotatoDye.Capes"] = string.Join(";", dictionary.Select((KeyValuePair<string, Color> pair) => pair.Key + "=" + ToHex(pair.Value)));
	}

	internal static int ShownCape(Player player)
	{
		if (!Object.op_Implicit((Object)(object)player))
		{
			return 0;
		}
		ZNetView obj = CharacterView.Invoke((Character)(object)player);
		int? obj2;
		if (obj == null)
		{
			obj2 = null;
		}
		else
		{
			ZDO zDO = obj.GetZDO();
			obj2 = ((zDO != null) ? new int?(zDO.GetInt(ZDOVars.s_shoulderItem, 0)) : ((int?)null));
		}
		int? num = obj2;
		return num.GetValueOrDefault();
	}

	internal static GameObject CapePrefab(int hash)
	{
		if (hash == 0 || !Object.op_Implicit((Object)(object)ObjectDB.instance))
		{
			return null;
		}
		return ObjectDB.instance.GetItemPrefab(hash);
	}

	internal static Color? SavedColor(Player player, int hash)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = CapePrefab(hash);
		if (!Object.op_Implicit((Object)(object)val) || !Saved(player).TryGetValue(((Object)val).name, out var value))
		{
			return null;
		}
		return value;
	}
}
internal static class BarberPanel
{
	[HarmonyPatch(typeof(PlayerCustomizaton), "ShowBarberGui")]
	internal static class Show
	{
		private static void Prefix(out bool __state)
		{
			__state = WasHidden.Invoke();
		}

		private static void Postfix(bool __state)
		{
			PlayerCustomizaton barberInstance = PlayerCustomizaton.m_barberInstance;
			if (!Plugin.BarberPanel.Value || !Object.op_Implicit((Object)(object)barberInstance) || !Object.op_Implicit((Object)(object)barberInstance.m_rootPanel) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			try
			{
				if (!Object.op_Implicit((Object)(object)panel) || (Object)(object)owner != (Object)(object)barberInstance)
				{
					Build(barberInstance);
				}
				if (Object.op_Implicit((Object)(object)panel))
				{
					panel.SetActive(true);
					Fit();
					if (!__state || !Plugin.Previewing)
					{
						Load();
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Couldn't open the cape color panel: " + ex));
				if (Object.op_Implicit((Object)(object)panel))
				{
					panel.SetActive(false);
				}
			}
		}
	}

	[HarmonyPatch(typeof(PlayerCustomizaton), "OnApply")]
	internal static class Apply
	{
		private static void Prefix()
		{
			if (Plugin.Previewing)
			{
				Player localPlayer = Player.m_localPlayer;
				GameObject val = Plugin.CapePrefab(Plugin.ShownCape(localPlayer));
				if (Object.op_Implicit((Object)(object)val))
				{
					Plugin.Save(localPlayer, ((Object)val).name, Plugin.Preview);
				}
				Stop();
			}
		}
	}

	[HarmonyPatch(typeof(PlayerCustomizaton), "OnCancel")]
	internal static class Cancel
	{
		private static void Prefix()
		{
			Stop();
		}
	}

	private static GameObject panel;

	private static PlayerCustomizaton owner;

	private static readonly Slider[] Sliders = (Slider[])(object)new Slider[3];

	private static readonly TMP_Text[] Values = (TMP_Text[])(object)new TMP_Text[3];

	private static TMP_Text note;

	private static Image swatch;

	private static bool syncing;

	private static readonly string[] Names = new string[3] { "Hue", "Saturation", "Brightness" };

	private static readonly Texture2D[] Strips = (Texture2D[])(object)new Texture2D[3];

	private const int StripWidth = 64;

	private static readonly FieldRef<bool> WasHidden = AccessTools.StaticFieldRefAccess<bool>(AccessTools.Field(typeof(PlayerCustomizaton), "m_barberWasHidden"));

	private static void Stop()
	{
		Plugin.Previewing = false;
		Plugin.Preview = null;
	}

	private static void Load()
	{
		//IL_002d: 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)
		Player localPlayer = Player.m_localPlayer;
		int hash = Plugin.ShownCape(localPlayer);
		GameObject val = Plugin.CapePrefab(hash);
		float value = default(float);
		float value2 = default(float);
		float value3 = default(float);
		Color.RGBToHSV((Color)(((??)Plugin.SavedColor(localPlayer, hash)) ?? Color.white), ref value, ref value2, ref value3);
		syncing = true;
		Sliders[0].value = value;
		Sliders[1].value = value2;
		Sliders[2].value = value3;
		syncing = false;
		bool flag = Object.op_Implicit((Object)(object)val);
		Slider[] sliders = Sliders;
		for (int i = 0; i < sliders.Length; i++)
		{
			((Selectable)sliders[i]).interactable = flag;
		}
		note.text = (flag ? Localization.instance.Localize(val.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_name ?? ((Object)val).name) : "Wear a cape to dye it");
		Stop();
		Refresh();
	}

	private static void Changed()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		if (!syncing && Plugin.ShownCape(Player.m_localPlayer) != 0)
		{
			Plugin.Preview = Current();
			Plugin.Previewing = true;
			Refresh();
		}
	}

	private static Color Current()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		return Color.HSVToRGB(Sliders[0].value, Sliders[1].value, Sliders[2].value);
	}

	private static void Refresh()
	{
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		float hue = Sliders[0].value;
		float saturation = Sliders[1].value;
		float brightness = Sliders[2].value;
		Values[0].text = Mathf.RoundToInt(hue * 360f).ToString(CultureInfo.InvariantCulture) + "°";
		Values[1].text = Mathf.RoundToInt(saturation * 100f).ToString(CultureInfo.InvariantCulture) + "%";
		Values[2].text = Mathf.RoundToInt(brightness * 100f).ToString(CultureInfo.InvariantCulture) + "%";
		((Graphic)swatch).color = Current();
		Paint(0, (float x) => Color.HSVToRGB(x, 1f, 1f));
		Paint(1, (float x) => Color.HSVToRGB(hue, x, brightness));
		Paint(2, (float x) => Color.HSVToRGB(hue, saturation, x));
	}

	private static void Paint(int index, Func<float, Color> at)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = Strips[index];
		if (Object.op_Implicit((Object)(object)val))
		{
			for (int i = 0; i < 64; i++)
			{
				val.SetPixel(i, 0, at((float)i / 63f));
			}
			val.Apply(false);
		}
	}

	private static void Reset()
	{
		syncing = true;
		Sliders[1].value = 0f;
		Sliders[2].value = 1f;
		syncing = false;
		Changed();
	}

	private static void Build(PlayerCustomizaton barber)
	{
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Expected O, but got Unknown
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Expected O, but got Unknown
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: 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_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Expected O, but got Unknown
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b6: Expected O, but got Unknown
		//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04db: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0502: Expected O, but got Unknown
		//IL_0537: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Expected O, but got Unknown
		//IL_054d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0557: Expected O, but got Unknown
		//IL_0406: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Expected O, but got Unknown
		//IL_057a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0595: Expected O, but got Unknown
		if (Object.op_Implicit((Object)(object)panel))
		{
			Object.Destroy((Object)(object)panel);
		}
		owner = barber;
		RectTransform root = default(RectTransform);
		ref RectTransform reference = ref root;
		Transform transform = barber.m_rootPanel.transform;
		reference = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		Slider val = (Object.op_Implicit((Object)(object)barber.m_hairLevel) ? barber.m_hairLevel : barber.m_hairTone);
		TMP_Text selectedHair = barber.m_selectedHair;
		if (!Object.op_Implicit((Object)(object)root) || !Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)selectedHair) || !Object.op_Implicit((Object)(object)barber.m_cancel))
		{
			Plugin.Log.LogWarning((object)"The barber window changed; the cape color panel stays off.");
			return;
		}
		Image val2 = ((Component)root).GetComponent<Image>() ?? (from image in ((Component)root).GetComponentsInChildren<Image>(true)
			where Object.op_Implicit((Object)(object)image.sprite) && (Object)(object)((Component)image).transform != (Object)(object)root && !Object.op_Implicit((Object)(object)((Component)image).GetComponentInParent<Selectable>())
			select image).OrderByDescending(delegate(Image image)
		{
			//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_0010: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Rect rect2 = ((RectTransform)((Component)image).transform).rect;
			float width = ((Rect)(ref rect2)).width;
			rect2 = ((RectTransform)((Component)image).transform).rect;
			return width * ((Rect)(ref rect2)).height;
		}).FirstOrDefault();
		Canvas componentInParent = ((Component)root).GetComponentInParent<Canvas>();
		Canvas val3 = ((componentInParent != null) ? componentInParent.rootCanvas : null);
		RectTransform val4 = root;
		if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val3))
		{
			Rect rect = ((RectTransform)((Component)val2).transform).rect;
			Vector2 size = ((Rect)(ref rect)).size;
			rect = ((RectTransform)((Component)val3).transform).rect;
			Vector2 size2 = ((Rect)(ref rect)).size;
			if (size.x < size2.x * 0.8f)
			{
				val4 = (RectTransform)((Component)val2).transform;
			}
		}
		panel = new GameObject("PotatoDye_CapePanel", new Type[1] { typeof(RectTransform) });
		RectTransform val5 = (RectTransform)panel.transform;
		((Transform)val5).SetParent((Transform)(object)val4, false);
		Vector2 val6 = default(Vector2);
		((Vector2)(ref val6))..ctor(1f, 1f);
		val5.anchorMax = val6;
		val5.anchorMin = val6;
		val5.pivot = new Vector2(0f, 1f);
		val5.anchoredPosition = new Vector2(12f, 0f);
		val5.sizeDelta = new Vector2(340f, 250f);
		Image val7 = panel.AddComponent<Image>();
		if (Object.op_Implicit((Object)(object)val2))
		{
			val7.sprite = val2.sprite;
			val7.type = val2.type;
			((Graphic)val7).color = ((Graphic)val2).color;
			((Graphic)val7).material = ((Graphic)val2).material;
		}
		else
		{
			((Graphic)val7).color = new Color(0f, 0f, 0f, 0.75f);
		}
		float num = 16f;
		TMP_Text obj = Text(selectedHair, "Title", 16f, num, 308f, 30f);
		obj.text = "Cape color";
		obj.alignment = (TextAlignmentOptions)514;
		num += 32f;
		note = Text(selectedHair, "Cape", 16f, num, 308f, 22f);
		note.alignment = (TextAlignmentOptions)514;
		note.fontSize = Mathf.Max(12f, selectedHair.fontSize * 0.8f);
		num += 30f;
		for (int num2 = 0; num2 < 3; num2++)
		{
			TMP_Text obj2 = Text(selectedHair, Names[num2], 16f, num, 92f, 26f);
			obj2.text = Names[num2];
			obj2.alignment = (TextAlignmentOptions)513;
			obj2.fontSize = Mathf.Max(12f, selectedHair.fontSize * 0.8f);
			GameObject obj3 = Object.Instantiate<GameObject>(((Component)val).gameObject, (Transform)(object)val5, false);
			((Object)obj3).name = "PotatoDye_" + Names[num2];
			Clean(obj3);
			Slider component = obj3.GetComponent<Slider>();
			component.onValueChanged = new SliderEvent();
			component.minValue = 0f;
			component.maxValue = 1f;
			component.wholeNumbers = false;
			((UnityEvent<float>)(object)component.onValueChanged).AddListener((UnityAction<float>)delegate
			{
				Changed();
			});
			Place((RectTransform)obj3.transform, 112f, num + 3f, 162f, 20f);
			Strip(component, num2);
			Sliders[num2] = component;
			TMP_Text val8 = Text(selectedHair, Names[num2] + "Value", 278f, num, 46f, 26f);
			val8.alignment = (TextAlignmentOptions)516;
			val8.fontSize = Mathf.Max(12f, selectedHair.fontSize * 0.8f);
			Values[num2] = val8;
			num += 34f;
		}
		GameObject val9 = new GameObject("PotatoDye_Swatch", new Type[1] { typeof(RectTransform) });
		val9.transform.SetParent((Transform)(object)val5, false);
		Place((RectTransform)val9.transform, 16f, num + 4f, 40f, 32f);
		swatch = val9.AddComponent<Image>();
		GameObject obj4 = Object.Instantiate<GameObject>(((Component)barber.m_cancel).gameObject, (Transform)(object)val5, false);
		((Object)obj4).name = "PotatoDye_Reset";
		Clean(obj4);
		Button component2 = obj4.GetComponent<Button>();
		component2.onClick = new ButtonClickedEvent();
		((UnityEvent)component2.onClick).AddListener(new UnityAction(Reset));
		TMP_Text componentInChildren = obj4.GetComponentInChildren<TMP_Text>(true);
		if (Object.op_Implicit((Object)(object)componentInChildren))
		{
			componentInChildren.text = "No dye";
		}
		Place((RectTransform)obj4.transform, 184f, num, 140f, 40f);
		panel.SetActive(false);
	}

	private static void Strip(Slider slider, int index)
	{
		//IL_0056: 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)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: 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)
		RectTransform val = (Object.op_Implicit((Object)(object)slider.handleRect) ? slider.handleRect : null);
		Image[] componentsInChildren = ((Component)slider).GetComponentsInChildren<Image>(true);
		foreach (Image val2 in componentsInChildren)
		{
			if (!Object.op_Implicit((Object)(object)val) || !((Component)val2).transform.IsChildOf((Transform)(object)val))
			{
				((Behaviour)val2).enabled = false;
			}
		}
		Texture2D val3 = new Texture2D(64, 1, (TextureFormat)4, false)
		{
			wrapMode = (TextureWrapMode)1,
			filterMode = (FilterMode)1
		};
		Strips[index] = val3;
		GameObject val4 = new GameObject("PotatoDye_Strip", new Type[1] { typeof(RectTransform) });
		RectTransform val5 = (RectTransform)val4.transform;
		((Transform)val5).SetParent(((Component)slider).transform, false);
		((Transform)val5).SetAsFirstSibling();
		val5.anchorMin = new Vector2(0f, 0.25f);
		val5.anchorMax = new Vector2(1f, 0.75f);
		Vector2 offsetMin = (val5.offsetMax = Vector2.zero);
		val5.offsetMin = offsetMin;
		Image obj = val4.AddComponent<Image>();
		obj.sprite = Sprite.Create(val3, new Rect(0f, 0f, 64f, 1f), new Vector2(0.5f, 0.5f));
		((Graphic)obj).raycastTarget = true;
	}

	private static void Fit()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: 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_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = (RectTransform)panel.transform;
		Canvas componentInParent = ((Component)val).GetComponentInParent<Canvas>();
		Canvas val2 = ((componentInParent != null) ? componentInParent.rootCanvas : null);
		if (Object.op_Implicit((Object)(object)val2))
		{
			Canvas.ForceUpdateCanvases();
			RectTransform val3 = (RectTransform)((Component)val2).transform;
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			val.GetWorldCorners(array);
			float num = float.MaxValue;
			float num2 = float.MinValue;
			float num3 = float.MaxValue;
			float num4 = float.MinValue;
			Vector3[] array2 = array;
			foreach (Vector3 val4 in array2)
			{
				Vector3 val5 = ((Transform)val3).InverseTransformPoint(val4);
				num = Mathf.Min(num, val5.x);
				num2 = Mathf.Max(num2, val5.x);
				num3 = Mathf.Min(num3, val5.y);
				num4 = Mathf.Max(num4, val5.y);
			}
			Rect rect = val3.rect;
			float num5 = 0f;
			float num6 = 0f;
			if (num2 > ((Rect)(ref rect)).xMax)
			{
				num5 = ((Rect)(ref rect)).xMax - num2;
			}
			if (num + num5 < ((Rect)(ref rect)).xMin)
			{
				num5 = ((Rect)(ref rect)).xMin - num;
			}
			if (num3 < ((Rect)(ref rect)).yMin)
			{
				num6 = ((Rect)(ref rect)).yMin - num3;
			}
			if (num4 + num6 > ((Rect)(ref rect)).yMax)
			{
				num6 = ((Rect)(ref rect)).yMax - num4;
			}
			if (num5 != 0f || num6 != 0f)
			{
				Vector3 val6 = ((Transform)val).parent.InverseTransformVector(((Transform)val3).TransformVector(new Vector3(num5, num6, 0f)));
				val.anchoredPosition += new Vector2(val6.x, val6.y);
			}
		}
	}

	private static TMP_Text Text(TMP_Text source, string name, float x, float y, float w, float h)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		GameObject val = Object.Instantiate<GameObject>(((Component)source).gameObject, panel.transform, false);
		((Object)val).name = "PotatoDye_" + name;
		Clean(val);
		foreach (Transform item in val.transform)
		{
			Object.Destroy((Object)(object)((Component)item).gameObject);
		}
		TMP_Text component = val.GetComponent<TMP_Text>();
		component.text = "";
		component.textWrappingMode = (TextWrappingModes)0;
		component.overflowMode = (TextOverflowModes)1;
		Place((RectTransform)val.transform, x, y, w, h);
		return component;
	}

	private static void Clean(GameObject copy)
	{
		Localize[] componentsInChildren = copy.GetComponentsInChildren<Localize>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			Object.Destroy((Object)(object)componentsInChildren[i]);
		}
		UIGamePad[] componentsInChildren2 = copy.GetComponentsInChildren<UIGamePad>(true);
		for (int i = 0; i < componentsInChildren2.Length; i++)
		{
			Object.Destroy((Object)(object)componentsInChildren2[i]);
		}
		LayoutElement[] components = copy.GetComponents<LayoutElement>();
		for (int i = 0; i < components.Length; i++)
		{
			Object.Destroy((Object)(object)components[i]);
		}
		ContentSizeFitter[] components2 = copy.GetComponents<ContentSizeFitter>();
		for (int i = 0; i < components2.Length; i++)
		{
			Object.Destroy((Object)(object)components2[i]);
		}
	}

	private static void Place(RectTransform rect, float x, float y, float w, float h)
	{
		//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_002a: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(0f, 1f);
		rect.anchorMax = val;
		rect.anchorMin = val;
		rect.pivot = new Vector2(0f, 1f);
		rect.anchoredPosition = new Vector2(x, 0f - y);
		rect.sizeDelta = new Vector2(w, h);
	}
}