Decompiled source of ReLoupKing v2.1.0

plugins/ReLoupKing/ReLoupKing.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using Fusion;
using HarmonyLib;
using Managers;
using Microsoft.CodeAnalysis;
using ReLoupKing.Compat;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ReLoupKing")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyInformationalVersion("2.1.0")]
[assembly: AssemblyProduct("ReLoupKing")]
[assembly: AssemblyTitle("ReLoupKing")]
[assembly: AssemblyVersion("2.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ReLoupKing
{
	public enum Slot
	{
		Style,
		Hair,
		Skin,
		PantsCut,
		Pants,
		Boots
	}
	public readonly struct Rgb : IEquatable<Rgb>
	{
		public readonly byte R;

		public readonly byte G;

		public readonly byte B;

		public Rgb(byte r, byte g, byte b)
		{
			R = r;
			G = g;
			B = b;
		}

		public static bool TryParseHex(string text, out Rgb color)
		{
			color = default(Rgb);
			if (text == null)
			{
				return false;
			}
			string text2 = text.Trim();
			if (text2.Length > 0 && text2[0] == '#')
			{
				text2 = text2.Substring(1);
			}
			if (text2.Length != 6)
			{
				return false;
			}
			if (!uint.TryParse(text2, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out var result))
			{
				return false;
			}
			color = new Rgb((byte)(result >> 16), (byte)(result >> 8), (byte)result);
			return true;
		}

		public string ToHex()
		{
			return $"{R:X2}{G:X2}{B:X2}";
		}

		public static Rgb FromHsv(float h, float s, float v)
		{
			h = Clamp01(h);
			if (h >= 1f)
			{
				h = 0f;
			}
			s = Clamp01(s);
			v = Clamp01(v);
			if (s <= 0f)
			{
				byte num = ToByte(v);
				return new Rgb(num, num, num);
			}
			float num2 = h * 6f;
			int num3 = (int)Math.Floor(num2);
			float num4 = num2 - (float)num3;
			float num5 = v * (1f - s);
			float num6 = v * (1f - s * num4);
			float num7 = v * (1f - s * (1f - num4));
			float channel;
			float channel2;
			float channel3;
			switch (num3 % 6)
			{
			case 0:
				channel = v;
				channel2 = num7;
				channel3 = num5;
				break;
			case 1:
				channel = num6;
				channel2 = v;
				channel3 = num5;
				break;
			case 2:
				channel = num5;
				channel2 = v;
				channel3 = num7;
				break;
			case 3:
				channel = num5;
				channel2 = num6;
				channel3 = v;
				break;
			case 4:
				channel = num7;
				channel2 = num5;
				channel3 = v;
				break;
			default:
				channel = v;
				channel2 = num5;
				channel3 = num6;
				break;
			}
			return new Rgb(ToByte(channel), ToByte(channel2), ToByte(channel3));
		}

		public void ToHsv(out float h, out float s, out float v)
		{
			float num = (float)(int)R / 255f;
			float num2 = (float)(int)G / 255f;
			float num3 = (float)(int)B / 255f;
			float num4 = Math.Max(num, Math.Max(num2, num3));
			float num5 = Math.Min(num, Math.Min(num2, num3));
			float num6 = num4 - num5;
			v = num4;
			s = ((num4 > 0f) ? (num6 / num4) : 0f);
			if (num6 <= 0f)
			{
				h = 0f;
				return;
			}
			if (num4 == num)
			{
				h = (num2 - num3) / num6 + ((num2 < num3) ? 6f : 0f);
			}
			else if (num4 == num2)
			{
				h = (num3 - num) / num6 + 2f;
			}
			else
			{
				h = (num - num2) / num6 + 4f;
			}
			h /= 6f;
			if (h < 0f)
			{
				h += 1f;
			}
			else if (h >= 1f)
			{
				h -= 1f;
			}
		}

		private static float Clamp01(float value)
		{
			if (!(value < 0f))
			{
				if (!(value > 1f))
				{
					return value;
				}
				return 1f;
			}
			return 0f;
		}

		private static byte ToByte(float channel)
		{
			return (byte)Math.Round(Clamp01(channel) * 255f);
		}

		public int ToInt()
		{
			return (R << 16) | (G << 8) | B;
		}

		public static Rgb FromInt(int rgb)
		{
			return new Rgb((byte)(rgb >> 16), (byte)(rgb >> 8), (byte)rgb);
		}

		public bool Equals(Rgb other)
		{
			if (R == other.R && G == other.G)
			{
				return B == other.B;
			}
			return false;
		}

		public override bool Equals(object obj)
		{
			if (obj is Rgb other)
			{
				return Equals(other);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return ToInt();
		}

		public override string ToString()
		{
			return "#" + ToHex();
		}
	}
	public readonly struct ColorChoice : IEquatable<ColorChoice>
	{
		public readonly int Preset;

		public readonly Rgb Color;

		public bool IsCustom => Preset < 0;

		public bool IsDefault => Preset == 0;

		private ColorChoice(int preset, Rgb color)
		{
			Preset = preset;
			Color = color;
		}

		public static ColorChoice FromPreset(Slot slot, int index)
		{
			Rgb[] array = Catalog.Palette(slot);
			index = Catalog.Clamp(index, array.Length);
			return new ColorChoice(index, array[index]);
		}

		public static ColorChoice FromCustom(Rgb color)
		{
			return new ColorChoice(-1, color);
		}

		public bool Equals(ColorChoice other)
		{
			if (Preset == other.Preset)
			{
				return Color.Equals(other.Color);
			}
			return false;
		}

		public override bool Equals(object obj)
		{
			if (obj is ColorChoice other)
			{
				return Equals(other);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return (Preset * 397) ^ Color.GetHashCode();
		}
	}
	public readonly struct Appearance : IEquatable<Appearance>
	{
		public readonly int Style;

		public readonly int PantsCut;

		public readonly ColorChoice Hair;

		public readonly ColorChoice Skin;

		public readonly ColorChoice Pants;

		public readonly ColorChoice Boots;

		public static Appearance Default => new Appearance(0, 0, ColorChoice.FromPreset(Slot.Hair, 0), ColorChoice.FromPreset(Slot.Skin, 0), ColorChoice.FromPreset(Slot.Pants, 0), ColorChoice.FromPreset(Slot.Boots, 0));

		public bool IsShorts => PantsCut == 1;

		public Appearance(int style, int pantsCut, ColorChoice hair, ColorChoice skin, ColorChoice pants, ColorChoice boots)
		{
			Style = Catalog.Clamp(style, Catalog.Options(Slot.Style).Length);
			PantsCut = Catalog.Clamp(pantsCut, Catalog.Options(Slot.PantsCut).Length);
			Hair = hair;
			Skin = skin;
			Pants = pants;
			Boots = boots;
		}

		public int GetOption(Slot slot)
		{
			return slot switch
			{
				Slot.Style => Style, 
				Slot.PantsCut => PantsCut, 
				_ => throw new ArgumentException($"{slot} is not an option slot"), 
			};
		}

		public ColorChoice GetColor(Slot slot)
		{
			return slot switch
			{
				Slot.Hair => Hair, 
				Slot.Skin => Skin, 
				Slot.Pants => Pants, 
				Slot.Boots => Boots, 
				_ => throw new ArgumentException($"{slot} is not a color slot"), 
			};
		}

		public Appearance WithOption(Slot slot, int value)
		{
			return new Appearance((slot == Slot.Style) ? value : Style, (slot == Slot.PantsCut) ? value : PantsCut, Hair, Skin, Pants, Boots);
		}

		public Appearance WithDefault(Slot slot)
		{
			if (!Catalog.IsColor(slot))
			{
				return WithOption(slot, 0);
			}
			return WithColor(slot, ColorChoice.FromPreset(slot, 0));
		}

		public Appearance WithColor(Slot slot, ColorChoice value)
		{
			return new Appearance(Style, PantsCut, (slot == Slot.Hair) ? value : Hair, (slot == Slot.Skin) ? value : Skin, (slot == Slot.Pants) ? value : Pants, (slot == Slot.Boots) ? value : Boots);
		}

		public bool Equals(Appearance o)
		{
			if (Style == o.Style && PantsCut == o.PantsCut && Hair.Equals(o.Hair) && Skin.Equals(o.Skin) && Pants.Equals(o.Pants))
			{
				return Boots.Equals(o.Boots);
			}
			return false;
		}

		public override bool Equals(object obj)
		{
			if (obj is Appearance o)
			{
				return Equals(o);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return ((((Style * 31 + PantsCut) * 31 + Hair.GetHashCode()) * 31 + Skin.GetHashCode()) * 31 + Pants.GetHashCode()) * 31 + Boots.GetHashCode();
		}

		public override string ToString()
		{
			return "style=" + Catalog.Options(Slot.Style)[Style] + " hair=" + Describe(Hair) + " skin=" + Describe(Skin) + " cut=" + Catalog.Options(Slot.PantsCut)[PantsCut] + " pants=" + Describe(Pants) + " boots=" + Describe(Boots);
		}

		private static string Describe(ColorChoice c)
		{
			if (!c.IsCustom)
			{
				return $"preset {c.Preset}";
			}
			return c.Color.ToString();
		}
	}
	public static class Catalog
	{
		public static readonly Slot[] Slots = (Slot[])Enum.GetValues(typeof(Slot));

		private static readonly string[] StyleNames = new string[2] { "Classique", "Mi-longue" };

		private static readonly string[] PantsCutNames = new string[2] { "Pantalon", "Short" };

		private static readonly Rgb[] HairPalette = new Rgb[20]
		{
			new Rgb(90, 68, 40),
			new Rgb(240, 210, 110),
			new Rgb(40, 40, 45),
			new Rgb(210, 85, 30),
			new Rgb(225, 225, 235),
			new Rgb(210, 35, 45),
			new Rgb(45, 95, 225),
			new Rgb(40, 195, 80),
			new Rgb(245, 95, 175),
			new Rgb(165, 55, 225),
			new Rgb(45, 225, 225),
			new Rgb(245, 135, 35),
			new Rgb(60, 42, 30),
			new Rgb(140, 75, 40),
			new Rgb(205, 190, 160),
			new Rgb(235, 150, 115),
			new Rgb(120, 25, 50),
			new Rgb(195, 160, 230),
			new Rgb(110, 225, 170),
			new Rgb(115, 120, 130)
		};

		private static readonly Rgb[] SkinPalette = new Rgb[20]
		{
			new Rgb(245, 215, 195),
			new Rgb(250, 225, 205),
			new Rgb(240, 205, 180),
			new Rgb(230, 195, 165),
			new Rgb(225, 185, 150),
			new Rgb(215, 175, 140),
			new Rgb(200, 160, 125),
			new Rgb(185, 145, 110),
			new Rgb(165, 125, 95),
			new Rgb(145, 105, 80),
			new Rgb(120, 85, 60),
			new Rgb(85, 60, 45),
			new Rgb(byte.MaxValue, 240, 235),
			new Rgb(235, 190, 185),
			new Rgb(205, 205, 215),
			new Rgb(210, 120, 110),
			new Rgb(160, 170, 175),
			new Rgb(145, 185, 140),
			new Rgb(140, 170, 205),
			new Rgb(75, 75, 90)
		};

		private static readonly Rgb[] PantsPalette = new Rgb[20]
		{
			new Rgb(95, 78, 62),
			new Rgb(45, 45, 48),
			new Rgb(25, 25, 28),
			new Rgb(50, 85, 55),
			new Rgb(40, 55, 95),
			new Rgb(45, 95, 185),
			new Rgb(135, 40, 48),
			new Rgb(200, 45, 45),
			new Rgb(85, 95, 50),
			new Rgb(195, 150, 45),
			new Rgb(180, 150, 115),
			new Rgb(220, 215, 205),
			new Rgb(240, 240, 245),
			new Rgb(115, 120, 130),
			new Rgb(195, 95, 40),
			new Rgb(125, 50, 155),
			new Rgb(225, 120, 150),
			new Rgb(40, 160, 165),
			new Rgb(235, 195, 55),
			new Rgb(60, 42, 32)
		};

		private static readonly Rgb[] BootsPalette = new Rgb[20]
		{
			new Rgb(95, 60, 45),
			new Rgb(65, 42, 32),
			new Rgb(28, 28, 30),
			new Rgb(55, 55, 58),
			new Rgb(165, 125, 85),
			new Rgb(125, 45, 38),
			new Rgb(185, 40, 45),
			new Rgb(45, 75, 50),
			new Rgb(40, 65, 145),
			new Rgb(30, 42, 75),
			new Rgb(190, 145, 65),
			new Rgb(125, 130, 135),
			new Rgb(235, 235, 240),
			new Rgb(215, 155, 45),
			new Rgb(95, 35, 75),
			new Rgb(120, 55, 165),
			new Rgb(75, 85, 50),
			new Rgb(45, 165, 175),
			new Rgb(225, 75, 140),
			new Rgb(205, 185, 150)
		};

		public static bool IsColor(Slot slot)
		{
			if (slot != Slot.Style)
			{
				return slot != Slot.PantsCut;
			}
			return false;
		}

		public static Rgb[] Palette(Slot slot)
		{
			return slot switch
			{
				Slot.Hair => HairPalette, 
				Slot.Skin => SkinPalette, 
				Slot.Pants => PantsPalette, 
				Slot.Boots => BootsPalette, 
				_ => throw new ArgumentException($"{slot} has no palette"), 
			};
		}

		public static string[] Options(Slot slot)
		{
			return slot switch
			{
				Slot.Style => StyleNames, 
				Slot.PantsCut => PantsCutNames, 
				_ => throw new ArgumentException($"{slot} has no options"), 
			};
		}

		public static int Count(Slot slot)
		{
			if (!IsColor(slot))
			{
				return Options(slot).Length;
			}
			return Palette(slot).Length;
		}

		public static string Label(Slot slot, Appearance appearance)
		{
			switch (slot)
			{
			case Slot.Style:
				return "Coiffure";
			case Slot.Hair:
				return "Cheveux";
			case Slot.Skin:
				return "Peau";
			case Slot.PantsCut:
				return "Jambes";
			case Slot.Pants:
				if (!appearance.IsShorts)
				{
					return "Pantalon";
				}
				return "Short";
			case Slot.Boots:
				return "Bottes";
			default:
				return slot.ToString();
			}
		}

		public static int Clamp(int index, int count)
		{
			if (index < 0 || index >= count)
			{
				return 0;
			}
			return index;
		}

		public static int Wrap(int index, int delta, int count)
		{
			return ((index + delta) % count + count) % count;
		}
	}
	public static class AppearanceCodec
	{
		public const int MaxIdLength = 64;

		private const string Tag = "#rk=";

		private const string PresetDigits = "0123456789abcdefghijklmnopqrstuvwxyz";

		private const string Base64Url = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";

		private const char CustomMarker = 'X';

		private static readonly Regex TagRegex = new Regex("#rk=[0-9A-Za-z_\\-]*", RegexOptions.Compiled);

		private static readonly Regex LegacyHairRegex = new Regex("#hair=(?:H([0-9a-fA-F]{6})|(\\d+))", RegexOptions.Compiled);

		public static string StripTags(string id)
		{
			if (string.IsNullOrEmpty(id))
			{
				return string.Empty;
			}
			return LegacyHairRegex.Replace(TagRegex.Replace(id, string.Empty), string.Empty);
		}

		public static string Encode(string id, Appearance appearance)
		{
			string text = StripTags(id);
			if (appearance.Equals(Appearance.Default))
			{
				return text;
			}
			StringBuilder stringBuilder = new StringBuilder(text, text.Length + 32);
			stringBuilder.Append("#rk=");
			stringBuilder.Append((char)(48 + appearance.PantsCut + 2 * appearance.Style));
			Slot[] slots = Catalog.Slots;
			foreach (Slot slot in slots)
			{
				if (!Catalog.IsColor(slot))
				{
					continue;
				}
				ColorChoice color = appearance.GetColor(slot);
				if (color.IsCustom)
				{
					int num = color.Color.ToInt();
					stringBuilder.Append('X');
					for (int num2 = 18; num2 >= 0; num2 -= 6)
					{
						stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"[(num >> num2) & 0x3F]);
					}
				}
				else
				{
					stringBuilder.Append("0123456789abcdefghijklmnopqrstuvwxyz"[color.Preset]);
				}
			}
			return stringBuilder.ToString();
		}

		public static Appearance? Decode(string id)
		{
			if (string.IsNullOrEmpty(id))
			{
				return null;
			}
			Match match = TagRegex.Match(id);
			if (match.Success)
			{
				return DecodePayload(match.Value.Substring("#rk=".Length));
			}
			Match match2 = LegacyHairRegex.Match(id);
			if (match2.Success)
			{
				ColorChoice value;
				if (match2.Groups[1].Success && Rgb.TryParseHex(match2.Groups[1].Value, out var color))
				{
					value = ColorChoice.FromCustom(color);
				}
				else
				{
					if (!int.TryParse(match2.Groups[2].Value, out var result))
					{
						return null;
					}
					value = ColorChoice.FromPreset(Slot.Hair, result);
				}
				return Appearance.Default.WithColor(Slot.Hair, value);
			}
			return null;
		}

		private static Appearance? DecodePayload(string payload)
		{
			int pos = 0;
			if (!TryReadDigit(payload, ref pos, out var value))
			{
				return null;
			}
			Appearance value2 = Appearance.Default.WithOption(Slot.PantsCut, value % 2).WithOption(Slot.Style, value / 2);
			Slot[] slots = Catalog.Slots;
			foreach (Slot slot in slots)
			{
				if (Catalog.IsColor(slot))
				{
					if (!TryReadColor(payload, ref pos, slot, out var color))
					{
						return null;
					}
					value2 = value2.WithColor(slot, color);
				}
			}
			if (pos != payload.Length)
			{
				return null;
			}
			return value2;
		}

		private static bool TryReadDigit(string s, ref int pos, out int value)
		{
			value = 0;
			if (pos >= s.Length || s[pos] < '0' || s[pos] > '9')
			{
				return false;
			}
			value = s[pos++] - 48;
			return true;
		}

		private static bool TryReadColor(string s, ref int pos, Slot slot, out ColorChoice color)
		{
			color = default(ColorChoice);
			if (pos >= s.Length)
			{
				return false;
			}
			if (s[pos] == 'X')
			{
				if (pos + 5 > s.Length)
				{
					return false;
				}
				int num = 0;
				for (int i = 1; i <= 4; i++)
				{
					int num2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".IndexOf(s[pos + i]);
					if (num2 < 0)
					{
						return false;
					}
					num = (num << 6) | num2;
				}
				pos += 5;
				color = ColorChoice.FromCustom(Rgb.FromInt(num));
				return true;
			}
			int num3 = "0123456789abcdefghijklmnopqrstuvwxyz".IndexOf(s[pos]);
			if (num3 < 0 || num3 >= Catalog.Palette(slot).Length)
			{
				return false;
			}
			pos++;
			color = ColorChoice.FromPreset(slot, num3);
			return true;
		}
	}
	public static class AppearanceService
	{
		private static readonly FieldInfo VillagerRendererField = AccessTools.Field(typeof(PlayerController), "villagerMeshRenderer");

		private static readonly MethodInfo RpcDefinePlayerData = AccessTools.Method(typeof(PlayerController), "Rpc_DefinePlayerData", new Type[1] { typeof(NetworkPlayerData) }, (Type[])null);

		private const float ApplyDelay = 0.1f;

		private const float SyncDelay = 0.4f;

		private static Appearance? _local;

		private static bool _longIdWarned;

		private static float _applyAt = -1f;

		private static float _syncAt = -1f;

		public static Appearance Local
		{
			get
			{
				Appearance? local = _local;
				if (!local.HasValue)
				{
					Appearance? appearance = (_local = SavedAppearance.Load());
					return appearance.Value;
				}
				return local.GetValueOrDefault();
			}
		}

		public static Slot ActiveSlot { get; internal set; } = Slot.Hair;

		public static Appearance Resolve(PlayerController player)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (((SimulationBehaviour)player).HasInputAuthority)
			{
				return Local;
			}
			return AppearanceCodec.Decode(((object)player.PlayerData.ID/*cast due to .constrained prefix*/).ToString()) ?? Appearance.Default;
		}

		public static bool ShowsWolfModel(PlayerController player)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkBool.op_Implicit(player.IsWolf))
			{
				return player.IsWolfMeshEnabled();
			}
			return true;
		}

		public static SkinnedMeshRenderer GetVillagerRenderer(PlayerController player)
		{
			if (!((Object)(object)player != (Object)null))
			{
				return null;
			}
			object? obj = VillagerRendererField?.GetValue(player);
			return (SkinnedMeshRenderer)((obj is SkinnedMeshRenderer) ? obj : null);
		}

		public static void Apply(PlayerController player, Appearance? appearance = null, int outfitIndex = -1)
		{
			//IL_010c: 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)
			if ((Object)(object)player == (Object)null || ShowsWolfModel(player))
			{
				return;
			}
			try
			{
				SkinnedMeshRenderer villagerRenderer = GetVillagerRenderer(player);
				if ((Object)(object)villagerRenderer == (Object)null)
				{
					return;
				}
				Material material = ((Renderer)villagerRenderer).material;
				if (!((Object)(object)material == (Object)null))
				{
					PlayerController player2 = ((!appearance.HasValue) ? LycansNewRolesCompat.ShownIdentity(player) : player);
					Appearance appearance2 = appearance ?? Resolve(player2);
					if (outfitIndex < 0)
					{
						outfitIndex = LycansNewRolesCompat.GetOutfitIndex(player2);
					}
					Hairstyles.Apply(villagerRenderer, appearance2.Style, appearance2.Hair.Color);
					Texture baseTexture = GetOutfitTexture(outfitIndex) ?? TextureTinter.BaseOf(material.mainTexture);
					Texture val = TextureTinter.Get((Renderer)(object)villagerRenderer, baseTexture, appearance2);
					if ((Object)(object)val != (Object)null && (Object)(object)material.mainTexture != (Object)(object)val)
					{
						material.mainTexture = val;
						Plugin.Logger.LogInfo((object)$"[Appearance] {player.Ref} (outfit {outfitIndex}): {appearance2}");
					}
				}
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Error applying appearance to {player.Ref}: {arg}");
			}
		}

		public static void ApplyTexture(SkinnedMeshRenderer renderer, Appearance a, int outfitIndex)
		{
			Hairstyles.Apply(renderer, a.Style, a.Hair.Color);
			Material material = ((Renderer)renderer).material;
			Texture val = TextureTinter.Get((Renderer)(object)renderer, GetOutfitTexture(outfitIndex), a);
			if ((Object)(object)material != (Object)null && (Object)(object)val != (Object)null)
			{
				material.mainTexture = val;
			}
		}

		public static void ApplyAll()
		{
			PlayerController[] array = Object.FindObjectsOfType<PlayerController>();
			for (int i = 0; i < array.Length; i++)
			{
				Apply(array[i]);
			}
		}

		private static Texture GetOutfitTexture(int outfitIndex)
		{
			try
			{
				return ColorManager.GetTexture(outfitIndex);
			}
			catch (Exception)
			{
				return null;
			}
		}

		public static void CycleSlot(Slot slot, int delta)
		{
			ActiveSlot = slot;
			Appearance local = Local;
			if (Catalog.IsColor(slot))
			{
				ColorChoice color = local.GetColor(slot);
				int index = ((!color.IsCustom) ? Catalog.Wrap(color.Preset, delta, Catalog.Count(slot)) : ((delta < 0) ? (Catalog.Count(slot) - 1) : 0));
				SetLocal(local.WithColor(slot, ColorChoice.FromPreset(slot, index)));
			}
			else
			{
				SetLocal(local.WithOption(slot, Catalog.Wrap(local.GetOption(slot), delta, Catalog.Count(slot))));
			}
		}

		public static void SetCustomColor(Rgb color)
		{
			if (Catalog.IsColor(ActiveSlot))
			{
				SetLocal(Local.WithColor(ActiveSlot, ColorChoice.FromCustom(color)));
			}
		}

		public static void SetColor(Slot slot, ColorChoice choice)
		{
			if (Catalog.IsColor(slot))
			{
				SetLocal(Local.WithColor(slot, choice));
			}
		}

		public static void ToggleMenuLock()
		{
			CustomizerHUD.ToggleLock();
		}

		public static void ResetSlot(Slot slot)
		{
			ActiveSlot = slot;
			SetLocal(Local.WithDefault(slot));
		}

		public static void Reset()
		{
			ResetSlot(ActiveSlot);
		}

		public static void SetLocal(Appearance a)
		{
			_local = a;
			_applyAt = Time.unscaledTime + 0.1f;
			_syncAt = Time.unscaledTime + 0.4f;
			CustomizerHUD.ClearError();
			CustomizerHUD.Refresh();
		}

		public static void FlushPending()
		{
			if (_applyAt < 0f && _syncAt < 0f)
			{
				return;
			}
			float unscaledTime = Time.unscaledTime;
			PlayerController local = PlayerController.Local;
			if (_applyAt >= 0f && unscaledTime >= _applyAt)
			{
				_applyAt = -1f;
				if ((Object)(object)local != (Object)null)
				{
					Apply(local);
				}
			}
			if (_syncAt >= 0f && unscaledTime >= _syncAt)
			{
				_syncAt = -1f;
				SavedAppearance.Save(Local);
				if ((Object)(object)local != (Object)null)
				{
					Broadcast(local);
				}
			}
		}

		public static void SaveNow()
		{
			if (!(_syncAt < 0f))
			{
				_syncAt = -1f;
				SavedAppearance.Save(Local);
			}
		}

		private static void Broadcast(PlayerController local)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				NetworkPlayerData val = default(NetworkPlayerData);
				((NetworkPlayerData)(ref val))..ctor(((object)local.PlayerData.ID/*cast due to .constrained prefix*/).ToString(), ((object)local.PlayerData.Username/*cast due to .constrained prefix*/).ToString());
				RpcDefinePlayerData.Invoke(local, new object[1] { val });
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Error broadcasting appearance: {arg}");
			}
		}

		public static string TagLocalId(string id)
		{
			string text = AppearanceCodec.Encode(id, Local);
			if (text.Length > 64)
			{
				if (!_longIdWarned)
				{
					_longIdWarned = true;
					Plugin.Logger.LogWarning((object)$"Player ID too long to carry the appearance ({text.Length} > {64}); other players will see the default look.");
				}
				return AppearanceCodec.StripTags(id);
			}
			return text;
		}
	}
	public static class CustomizerHUD
	{
		private enum DragTarget
		{
			None,
			Sv,
			Hue
		}

		private sealed class Row
		{
			public Slot Slot;

			public GameObject PrevObj;

			public RectTransform PrevRect;

			public Image PrevBg;

			public Image Swatch;

			public TextMeshProUGUI LabelText;

			public GameObject NextObj;

			public RectTransform NextRect;

			public Image NextBg;

			public TextMeshProUGUI ValueText;

			public GameObject PaletteObj;

			public RectTransform PaletteRect;

			public Image PaletteBg;

			public GameObject PaletteSpacerObj;

			public GameObject ResetObj;

			public RectTransform ResetRect;

			public Image ResetBg;
		}

		private const string Accent = "#FFCC00";

		private const string Muted = "#7E8299";

		private const string LabelIdle = "#A0A5B8";

		private const float RowHeight = 40f;

		private const float SwatchSize = 26f;

		private const float ErrorDuration = 3.5f;

		private const int SvTexSize = 128;

		private const int HueTexSize = 128;

		private static readonly Color BorderColor = new Color(0.28f, 0.32f, 0.45f, 0.85f);

		private static readonly Color ButtonNormal = new Color(0.11f, 0.13f, 0.2f, 0.96f);

		private static readonly Color ButtonHover = new Color(0.18f, 0.22f, 0.34f, 0.98f);

		private static GameObject _root;

		private static Canvas _canvas;

		private static GameObject _listView;

		private static GameObject _pickerView;

		private static Row[] _rows;

		private static TextMeshProUGUI _error;

		private static TextMeshProUGUI _controls;

		private static GameObject _tooltipObj;

		private static RectTransform _tooltipRect;

		private static TextMeshProUGUI _tooltipText;

		private static Sprite _circle;

		private static Sprite _ring;

		private static Sprite _paletteIcon;

		private static Sprite _eraserIcon;

		private static float _errorUntil;

		private static Image _pickerSwatch;

		private static TextMeshProUGUI _pickerSlotText;

		private static RectTransform _cancelRect;

		private static Image _cancelBg;

		private static RectTransform _confirmRect;

		private static Image _confirmBg;

		private static GameObject _clipboardRow;

		private static RectTransform _clipboardRect;

		private static Image _clipboardBg;

		private static Image _clipboardSwatch;

		private static TextMeshProUGUI _clipboardText;

		private static RectTransform _svRect;

		private static Texture2D _svTex;

		private static RectTransform _svCursor;

		private static RectTransform _hueRect;

		private static Texture2D _hueTex;

		private static RectTransform _hueCursor;

		private static float _h;

		private static float _s;

		private static float _v;

		private static float _renderedHue = -1f;

		private static DragTarget _drag;

		private static ColorChoice _previousColor;

		private static bool _pickerEdited;

		private static bool _clipboardValid;

		private static string _clipboardHex;

		private static int _closedFrame = -10;

		public static bool IsShown
		{
			get
			{
				if ((Object)(object)_root != (Object)null)
				{
					return _root.activeSelf;
				}
				return false;
			}
		}

		public static bool IsUnlocked { get; private set; }

		public static bool IsPickerOpen { get; private set; }

		public static bool IsClipboardOptionShown
		{
			get
			{
				if (IsUnlocked && IsPickerOpen && (Object)(object)_clipboardRow != (Object)null)
				{
					return _clipboardRow.gameObject.activeSelf;
				}
				return false;
			}
		}

		public static bool ShouldBlockGameInput
		{
			get
			{
				if (!IsUnlocked)
				{
					return Time.frameCount <= _closedFrame + 1;
				}
				return true;
			}
		}

		public static void SetVisible(bool visible, GameUI gameUI = null)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			if (visible && (Object)(object)_root == (Object)null)
			{
				Build(gameUI ?? GameManager.Instance?.gameUI);
			}
			if (!((Object)(object)_root == (Object)null))
			{
				if (!visible)
				{
					LockMenu((int)GameManager.LocalGameState > 0);
				}
				_root.SetActive(visible);
				if (visible)
				{
					Refresh();
				}
				else
				{
					ClearError();
				}
			}
		}

		public static void ToggleLock()
		{
			if (IsUnlocked)
			{
				LockMenu();
			}
			else
			{
				UnlockMenu();
			}
		}

		public static void UnlockMenu()
		{
			if (!IsShown)
			{
				return;
			}
			IsUnlocked = true;
			IsPickerOpen = false;
			_drag = DragTarget.None;
			ResetButtonColors();
			GameManager instance = GameManager.Instance;
			if (instance != null)
			{
				GameUI gameUI = instance.gameUI;
				if (gameUI != null)
				{
					gameUI.UpdateCursor(true);
				}
			}
			UnlockCursor();
			ClearError();
			Refresh();
		}

		public static void LockMenu(bool restoreCursor = true)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (!IsUnlocked && !IsPickerOpen)
			{
				return;
			}
			IsUnlocked = false;
			IsPickerOpen = false;
			_closedFrame = Time.frameCount;
			_drag = DragTarget.None;
			ResetButtonColors();
			if (restoreCursor && (int)GameManager.LocalGameState != 0)
			{
				GameManager instance = GameManager.Instance;
				if (instance != null)
				{
					GameUI gameUI = instance.gameUI;
					if (gameUI != null)
					{
						gameUI.UpdateCursor(false);
					}
				}
			}
			Refresh();
		}

		public static void OpenPicker()
		{
			OpenPicker(AppearanceService.ActiveSlot);
		}

		public static void OpenPicker(Slot slot)
		{
			if (IsShown && Catalog.IsColor(slot))
			{
				if (!IsUnlocked)
				{
					UnlockMenu();
				}
				AppearanceService.ActiveSlot = slot;
				_previousColor = AppearanceService.Local.GetColor(slot);
				_previousColor.Color.ToHsv(out _h, out _s, out _v);
				_pickerEdited = false;
				_renderedHue = -1f;
				_drag = DragTarget.None;
				IsPickerOpen = true;
				ResetButtonColors();
				RebuildSvTexture();
				UnlockCursor();
				ClearError();
				Refresh();
			}
		}

		public static void ConfirmPicker()
		{
			if (IsPickerOpen)
			{
				if (_pickerEdited)
				{
					AppearanceService.SetCustomColor(Rgb.FromHsv(_h, _s, _v));
				}
				IsPickerOpen = false;
				_pickerEdited = false;
				_drag = DragTarget.None;
				ResetButtonColors();
				Refresh();
			}
		}

		public static void CancelPicker()
		{
			if (IsPickerOpen)
			{
				Slot activeSlot = AppearanceService.ActiveSlot;
				IsPickerOpen = false;
				_pickerEdited = false;
				_drag = DragTarget.None;
				ResetButtonColors();
				if (Catalog.IsColor(activeSlot))
				{
					AppearanceService.SetColor(activeSlot, _previousColor);
				}
				Refresh();
			}
		}

		public static void ClosePicker()
		{
			ConfirmPicker();
		}

		public static bool ClickClipboardOption()
		{
			if (!IsShown || !IsUnlocked || !IsPickerOpen)
			{
				return false;
			}
			if (!TryGetClipboardColor(out var color))
			{
				return false;
			}
			_pickerEdited = false;
			AppearanceService.SetCustomColor(color);
			ClosePicker();
			return true;
		}

		public static void PickColor(float h, float s, float v)
		{
			if (IsShown && Catalog.IsColor(AppearanceService.ActiveSlot))
			{
				if (!IsPickerOpen)
				{
					OpenPicker(AppearanceService.ActiveSlot);
				}
				_h = Mathf.Clamp01(h);
				if (_h >= 1f)
				{
					_h = 0f;
				}
				_s = Mathf.Clamp01(s);
				_v = Mathf.Clamp01(v);
				ApplyPickerColor();
			}
		}

		public static void ShowError(string message)
		{
			if (IsShown)
			{
				((TMP_Text)_error).text = "<color=#FF5566>" + message + "</color>";
				((Component)_error).gameObject.SetActive(true);
				_errorUntil = Time.time + 3.5f;
			}
		}

		public static void ClearError()
		{
			if ((Object)(object)_error != (Object)null)
			{
				((Component)_error).gameObject.SetActive(false);
			}
		}

		public static void Tick()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_error != (Object)null && ((Component)_error).gameObject.activeSelf && Time.time >= _errorUntil)
			{
				ClearError();
			}
			if (IsShown && IsUnlocked)
			{
				UnlockCursor();
				Vector2 mouse = Vector2.op_Implicit(Input.mousePosition);
				if (IsPickerOpen)
				{
					TickPicker(mouse);
				}
				else
				{
					TickList(mouse);
				}
			}
		}

		private static void TickList(Vector2 mouse)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			if (_rows == null)
			{
				return;
			}
			bool mouseButtonDown = Input.GetMouseButtonDown(0);
			string text = null;
			RectTransform targetRect = null;
			Row[] rows = _rows;
			foreach (Row row in rows)
			{
				bool flag = UpdateHover(row.PrevBg, row.PrevRect, mouse);
				bool flag2 = UpdateHover(row.NextBg, row.NextRect, mouse);
				bool flag3 = (Object)(object)row.PaletteBg != (Object)null && UpdateHover(row.PaletteBg, row.PaletteRect, mouse);
				bool flag4 = (Object)(object)row.ResetBg != (Object)null && UpdateHover(row.ResetBg, row.ResetRect, mouse);
				if (flag)
				{
					text = "précédent";
					targetRect = row.PrevRect;
				}
				else if (flag2)
				{
					text = "suivant";
					targetRect = row.NextRect;
				}
				else if (flag3)
				{
					text = "colorpicker";
					targetRect = row.PaletteRect;
				}
				else if (flag4)
				{
					text = "reset";
					targetRect = row.ResetRect;
				}
				if (mouseButtonDown)
				{
					if (flag)
					{
						HideTooltip();
						AppearanceService.CycleSlot(row.Slot, -1);
						return;
					}
					if (flag2)
					{
						HideTooltip();
						AppearanceService.CycleSlot(row.Slot, 1);
						return;
					}
					if (flag3)
					{
						HideTooltip();
						OpenPicker(row.Slot);
						return;
					}
					if (flag4)
					{
						HideTooltip();
						AppearanceService.ResetSlot(row.Slot);
						return;
					}
				}
			}
			if (text != null)
			{
				ShowTooltip(text, targetRect);
			}
			else
			{
				HideTooltip();
			}
		}

		private static void TickPicker(Vector2 mouse)
		{
			//IL_0010: 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_0039: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			RefreshClipboardOption();
			bool flag = UpdateHover(_cancelBg, _cancelRect, mouse);
			bool flag2 = UpdateHover(_confirmBg, _confirmRect, mouse);
			bool flag3 = IsClipboardOptionShown && UpdateHover(_clipboardBg, _clipboardRect, mouse);
			if (!IsClipboardOptionShown && (Object)(object)_clipboardBg != (Object)null)
			{
				((Graphic)_clipboardBg).color = ButtonNormal;
			}
			float nx2;
			if (Input.GetMouseButtonDown(0))
			{
				if (flag)
				{
					CancelPicker();
					return;
				}
				if (flag2)
				{
					ConfirmPicker();
					return;
				}
				if (flag3)
				{
					ClickClipboardOption();
					return;
				}
				float ny2;
				if (TryGetNormalizedPoint(_svRect, mouse, out var nx, out var ny))
				{
					_drag = DragTarget.Sv;
					_s = nx;
					_v = ny;
					ApplyPickerColor();
				}
				else if (TryGetNormalizedPoint(_hueRect, mouse, out nx2, out ny2))
				{
					_drag = DragTarget.Hue;
					_h = ((ny2 >= 1f) ? 0f : ny2);
					if (_s < 0.02f)
					{
						_s = 1f;
					}
					if (_v < 0.02f)
					{
						_v = 1f;
					}
					ApplyPickerColor();
				}
			}
			else if (Input.GetMouseButton(0) && _drag != DragTarget.None)
			{
				float ny4;
				if (_drag == DragTarget.Sv && TryGetNormalizedPoint(_svRect, mouse, out var nx3, out var ny3, clamp: true))
				{
					_s = nx3;
					_v = ny3;
					ApplyPickerColor();
				}
				else if (_drag == DragTarget.Hue && TryGetNormalizedPoint(_hueRect, mouse, out nx2, out ny4, clamp: true))
				{
					_h = ((ny4 >= 1f) ? 0f : ny4);
					ApplyPickerColor();
				}
			}
			if (!Input.GetMouseButton(0))
			{
				_drag = DragTarget.None;
			}
		}

		public static void Refresh()
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			if (!IsShown)
			{
				return;
			}
			try
			{
				Appearance local = AppearanceService.Local;
				Slot activeSlot = AppearanceService.ActiveSlot;
				bool flag = IsUnlocked && IsPickerOpen && Catalog.IsColor(activeSlot);
				if (IsPickerOpen && !flag)
				{
					IsPickerOpen = false;
				}
				if ((Object)(object)_listView != (Object)null)
				{
					_listView.SetActive(!flag);
				}
				if ((Object)(object)_pickerView != (Object)null)
				{
					_pickerView.SetActive(flag);
				}
				if (flag)
				{
					ColorChoice color = local.GetColor(activeSlot);
					if ((Object)(object)_pickerSwatch != (Object)null)
					{
						((Graphic)_pickerSwatch).color = Color32.op_Implicit(new Color32(color.Color.R, color.Color.G, color.Color.B, byte.MaxValue));
					}
					if ((Object)(object)_pickerSlotText != (Object)null)
					{
						string text = Catalog.Label(activeSlot, local);
						((TMP_Text)_pickerSlotText).text = "<b><color=#FFFFFF>" + text + "</color></b>  <color=#FFCC00>#" + color.Color.ToHex() + "</color>";
					}
					UpdatePickerCursors();
					RefreshClipboardOption(force: true);
					((TMP_Text)_controls).text = "<color=#7E8299>[K] Verrouiller</color>";
					return;
				}
				Row[] rows = _rows;
				foreach (Row row in rows)
				{
					string text2;
					if (Catalog.IsColor(row.Slot))
					{
						ColorChoice color2 = local.GetColor(row.Slot);
						((Graphic)row.Swatch).color = Color32.op_Implicit(new Color32(color2.Color.R, color2.Color.G, color2.Color.B, byte.MaxValue));
						text2 = (color2.IsCustom ? ("#" + color2.Color.ToHex()) : $"{color2.Preset + 1}/{Catalog.Count(row.Slot)}");
					}
					else
					{
						text2 = Catalog.Options(row.Slot)[local.GetOption(row.Slot)];
					}
					row.PrevObj.SetActive(IsUnlocked);
					row.NextObj.SetActive(IsUnlocked);
					if ((Object)(object)row.PaletteObj != (Object)null)
					{
						row.PaletteObj.SetActive(IsUnlocked);
					}
					if ((Object)(object)row.PaletteSpacerObj != (Object)null)
					{
						row.PaletteSpacerObj.SetActive(IsUnlocked);
					}
					if ((Object)(object)row.ResetObj != (Object)null)
					{
						row.ResetObj.SetActive(IsUnlocked);
					}
					string text3 = Catalog.Label(row.Slot, local);
					((TMP_Text)row.LabelText).text = (IsUnlocked ? ("<b><color=#FFFFFF>" + text3 + "</color></b>") : ("<color=#A0A5B8>" + text3 + "</color>"));
					((TMP_Text)row.ValueText).alignment = (TextAlignmentOptions)(IsUnlocked ? 4098 : 4097);
					((TMP_Text)row.ValueText).text = (IsUnlocked ? ("<color=#FFCC00>" + text2 + "</color>") : ("<color=#7E8299>" + text2 + "</color>"));
				}
				((TMP_Text)_controls).text = (IsUnlocked ? "<color=#7E8299>[K] Verrouiller</color>" : "<color=#7E8299>[K] Personnaliser</color>");
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Error refreshing CustomizerHUD: {arg}");
			}
		}

		private static void Build(GameUI gameUI)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_00ce: 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)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0182: 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_01a2: Expected O, but got Unknown
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)gameUI == (Object)null)
			{
				return;
			}
			try
			{
				TextMeshProUGUI value = Traverse.Create((object)gameUI).Field<TextMeshProUGUI>("pgmShortcutSkinText").Value;
				if (!((Object)(object)value == (Object)null))
				{
					object obj = ((Component)gameUI).transform.Find("Canvas");
					if (obj == null)
					{
						Canvas componentInChildren = ((Component)gameUI).GetComponentInChildren<Canvas>(true);
						obj = ((componentInChildren != null) ? ((Component)componentInChildren).transform : null) ?? ((TMP_Text)value).transform.parent;
					}
					Transform val = (Transform)obj;
					_canvas = ((Component)val).GetComponent<Canvas>() ?? ((Component)val).GetComponentInParent<Canvas>();
					_root = new GameObject("ReLoupKingHUD", new Type[1] { typeof(RectTransform) });
					_root.transform.SetParent(val, false);
					_root.transform.SetAsLastSibling();
					RectTransform val2 = (RectTransform)_root.transform;
					Vector2 val3 = (val2.pivot = new Vector2(1f, 0.5f));
					Vector2 anchorMin = (val2.anchorMax = val3);
					val2.anchorMin = anchorMin;
					val2.anchoredPosition = new Vector2(-40f, 0f);
					val2.sizeDelta = new Vector2(520f, 600f);
					Image val6 = CreateImage("Border", _root.transform, new Color(0.22f, 0.25f, 0.35f, 0.65f));
					Stretch((RectTransform)((Component)val6).transform, 0f);
					Image val7 = CreateImage("Background", ((Component)val6).transform, new Color(0.06f, 0.07f, 0.11f, 0.94f));
					Stretch((RectTransform)((Component)val7).transform, 1f);
					((LayoutGroup)AddVerticalLayout(((Component)val7).gameObject, 10f)).padding = new RectOffset(22, 22, 18, 18);
					Transform parent = CreateHorizontalRow("Header", ((Component)val7).transform, 32f, 12f);
					((TMP_Text)CreateText(value, parent, "Title", 24f, (TextAlignmentOptions)257, 260f, 32f)).text = "<b><color=#FFFFFF>ReLoupKing</color></b>  <size=18><color=#8888AA>v2.1.0</color></size>";
					_error = CreateText(value, parent, "Error", 19f, (TextAlignmentOptions)4100, 170f, 32f);
					((Component)_error).gameObject.GetComponent<LayoutElement>().flexibleWidth = 1f;
					((TMP_Text)_error).overflowMode = (TextOverflowModes)0;
					((Component)_error).gameObject.SetActive(false);
					CreateFixedBox("HeaderMargin", ((Component)val7).transform, 6f);
					BuildListView(value, ((Component)val7).transform);
					BuildPickerView(value, ((Component)val7).transform);
					GameObject val8 = new GameObject("Spacer", new Type[1] { typeof(RectTransform) });
					val8.transform.SetParent(((Component)val7).transform, false);
					val8.AddComponent<LayoutElement>().flexibleHeight = 1f;
					_controls = CreateText(value, ((Component)val7).transform, "Controls", 24f, (TextAlignmentOptions)1025, -1f, 36f);
					((TMP_Text)_controls).enableWordWrapping = true;
					((TMP_Text)_controls).lineSpacing = 3f;
					BuildTooltip(value, _root.transform);
					_pickerView.SetActive(false);
					_root.SetActive(false);
				}
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Error building CustomizerHUD: {arg}");
				if ((Object)(object)_root != (Object)null)
				{
					Object.Destroy((Object)(object)_root);
				}
				_root = null;
				_listView = null;
				_pickerView = null;
				IsUnlocked = false;
				IsPickerOpen = false;
			}
		}

		private static void BuildListView(TextMeshProUGUI template, Transform parent)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			_listView = new GameObject("ListView", new Type[1] { typeof(RectTransform) });
			_listView.transform.SetParent(parent, false);
			AddVerticalLayout(_listView, 8f);
			_rows = new Row[Catalog.Slots.Length];
			CreateSectionHeader(template, _listView.transform, "Style");
			BuildSlotRow(template, _listView.transform, Slot.Style);
			BuildSlotRow(template, _listView.transform, Slot.PantsCut);
			CreateFixedBox("SectionGap", _listView.transform, 4f);
			CreateSectionHeader(template, _listView.transform, "Couleurs");
			BuildSlotRow(template, _listView.transform, Slot.Hair);
			BuildSlotRow(template, _listView.transform, Slot.Skin);
			BuildSlotRow(template, _listView.transform, Slot.Pants);
			BuildSlotRow(template, _listView.transform, Slot.Boots);
		}

		private static void CreateSectionHeader(TextMeshProUGUI template, Transform parent, string title)
		{
			((TMP_Text)CreateText(template, parent, title + "Header", 18f, (TextAlignmentOptions)1025, 200f, 24f)).text = "<b><color=#8F96B0>" + title + "</color></b>";
		}

		private static void BuildSlotRow(TextMeshProUGUI template, Transform parent, Slot slot)
		{
			Transform parent2 = CreateHorizontalRow(slot.ToString() + "Row", parent, 40f, 6f);
			Row row = new Row
			{
				Slot = slot
			};
			bool num = Catalog.IsColor(slot);
			if (num)
			{
				row.Swatch = CreateSwatch(parent2);
			}
			float width = (num ? 128f : 160f);
			row.LabelText = CreateText(template, parent2, "Label", 22f, (TextAlignmentOptions)4097, width, 40f);
			row.PrevObj = CreateButton(template, parent2, "PrevBtn", "<", 34f, 34f, out row.PrevRect, out row.PrevBg);
			row.PrevObj.SetActive(false);
			row.ValueText = CreateText(template, parent2, "Value", 22f, (TextAlignmentOptions)4097, 144f, 40f);
			((Component)row.ValueText).gameObject.GetComponent<LayoutElement>().flexibleWidth = 1f;
			row.NextObj = CreateButton(template, parent2, "NextBtn", ">", 34f, 34f, out row.NextRect, out row.NextBg);
			row.NextObj.SetActive(false);
			if (num)
			{
				row.PaletteObj = CreateIconButton(parent2, "PaletteBtn", PaletteIconSprite(), 36f, 34f, out row.PaletteRect, out row.PaletteBg);
				row.PaletteObj.SetActive(false);
			}
			else
			{
				row.PaletteSpacerObj = CreateFixedBox("PaletteSpacer", parent2, 36f);
				row.PaletteSpacerObj.SetActive(false);
			}
			row.ResetObj = CreateIconButton(parent2, "ResetBtn", EraserIconSprite(), 36f, 34f, out row.ResetRect, out row.ResetBg);
			row.ResetObj.SetActive(false);
			_rows[(int)slot] = row;
		}

		private static void BuildPickerView(TextMeshProUGUI template, Transform parent)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			//IL_010a: 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_0132: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Expected O, but got Unknown
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Expected O, but got Unknown
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Expected O, but got Unknown
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Expected O, but got Unknown
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Expected O, but got Unknown
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Expected O, but got Unknown
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Expected O, but got Unknown
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Expected O, but got Unknown
			_pickerView = new GameObject("PickerView", new Type[1] { typeof(RectTransform) });
			_pickerView.transform.SetParent(parent, false);
			AddVerticalLayout(_pickerView, 10f);
			Transform parent2 = CreateHorizontalRow("PickerSlotRow", _pickerView.transform, 38f, 10f);
			_pickerSwatch = CreateSwatch(parent2);
			_pickerSlotText = CreateText(template, parent2, "SlotText", 22f, (TextAlignmentOptions)4097, 260f, 36f);
			((Component)_pickerSlotText).gameObject.GetComponent<LayoutElement>().flexibleWidth = 1f;
			_clipboardRow = ((Component)CreateImage("ClipboardOption", _pickerView.transform, BorderColor)).gameObject;
			_clipboardRow.AddComponent<LayoutElement>().preferredHeight = 42f;
			_clipboardRect = (RectTransform)_clipboardRow.transform;
			_clipboardBg = CreateImage("ClipboardBg", _clipboardRow.transform, ButtonNormal);
			Stretch((RectTransform)((Component)_clipboardBg).transform, 1f);
			HorizontalLayoutGroup obj = ((Component)_clipboardBg).gameObject.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)obj).padding = new RectOffset(12, 12, 6, 6);
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 10f;
			((LayoutGroup)obj).childAlignment = (TextAnchor)3;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false);
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = childControlWidth;
			_clipboardSwatch = CreateSwatch(((Component)_clipboardBg).transform);
			_clipboardText = CreateText(template, ((Component)_clipboardBg).transform, "ClipboardText", 20f, (TextAlignmentOptions)4097, 380f, 30f);
			_clipboardRow.SetActive(false);
			Transform parent3 = CreateHorizontalRow("HsvPickerRow", _pickerView.transform, 220f, 14f);
			Image val = CreateBorderedBox("SvBox", parent3, 380f, 220f, 1f);
			_svTex = new Texture2D(128, 128, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Image val2 = CreateImage("SvMap", ((Component)val).transform, Color.white);
			val2.sprite = Sprite.Create(_svTex, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 100f);
			Stretch((RectTransform)((Component)val2).transform, 1f);
			_svRect = (RectTransform)((Component)val2).transform;
			Image obj2 = CreateImage("SvCursor", ((Component)val2).transform, Color.white);
			obj2.sprite = PickerRingSprite();
			_svCursor = (RectTransform)((Component)obj2).transform;
			_svCursor.pivot = new Vector2(0.5f, 0.5f);
			_svCursor.sizeDelta = new Vector2(16f, 16f);
			Image val3 = CreateBorderedBox("HueBox", parent3, 36f, 220f);
			Image val4 = CreateImage("HueMap", ((Component)val3).transform, Color.white);
			val4.sprite = CreateHueSprite();
			Stretch((RectTransform)((Component)val4).transform, 1f);
			_hueRect = (RectTransform)((Component)val4).transform;
			Image val5 = CreateImage("HueCursor", ((Component)val4).transform, new Color(0.08f, 0.09f, 0.13f, 0.95f));
			_hueCursor = (RectTransform)((Component)val5).transform;
			_hueCursor.pivot = new Vector2(0.5f, 0.5f);
			_hueCursor.sizeDelta = new Vector2(6f, 8f);
			Stretch((RectTransform)((Component)CreateImage("HueCursorInner", ((Component)val5).transform, Color.white)).transform, 2f);
			Transform parent4 = CreateHorizontalRow("PickerActionsRow", _pickerView.transform, 36f, 12f);
			CreateButton(template, parent4, "CancelBtn", "Annuler", 231f, 36f, out _cancelRect, out _cancelBg).GetComponent<LayoutElement>().flexibleWidth = 1f;
			CreateButton(template, parent4, "ConfirmBtn", "Valider", 231f, 36f, out _confirmRect, out _confirmBg).GetComponent<LayoutElement>().flexibleWidth = 1f;
		}

		private static bool UpdateHover(Image bg, RectTransform rect, Vector2 mouse)
		{
			//IL_0001: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			float nx;
			float ny;
			bool flag = TryGetNormalizedPoint(rect, mouse, out nx, out ny);
			if ((Object)(object)bg != (Object)null)
			{
				((Graphic)bg).color = (flag ? ButtonHover : ButtonNormal);
			}
			return flag;
		}

		private static void ResetButtonColors()
		{
			//IL_0017: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			HideTooltip();
			if ((Object)(object)_cancelBg != (Object)null)
			{
				((Graphic)_cancelBg).color = ButtonNormal;
			}
			if ((Object)(object)_confirmBg != (Object)null)
			{
				((Graphic)_confirmBg).color = ButtonNormal;
			}
			if ((Object)(object)_clipboardBg != (Object)null)
			{
				((Graphic)_clipboardBg).color = ButtonNormal;
			}
			if (_rows == null)
			{
				return;
			}
			Row[] rows = _rows;
			foreach (Row row in rows)
			{
				if (row != null)
				{
					if ((Object)(object)row.PrevBg != (Object)null)
					{
						((Graphic)row.PrevBg).color = ButtonNormal;
					}
					if ((Object)(object)row.NextBg != (Object)null)
					{
						((Graphic)row.NextBg).color = ButtonNormal;
					}
					if ((Object)(object)row.PaletteBg != (Object)null)
					{
						((Graphic)row.PaletteBg).color = ButtonNormal;
					}
					if ((Object)(object)row.ResetBg != (Object)null)
					{
						((Graphic)row.ResetBg).color = ButtonNormal;
					}
				}
			}
		}

		private static void BuildTooltip(TextMeshProUGUI template, Transform root)
		{
			//IL_0006: 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_002c: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_007b: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			Image val = CreateImage("Tooltip", root, BorderColor);
			_tooltipObj = ((Component)val).gameObject;
			_tooltipRect = (RectTransform)((Component)val).transform;
			RectTransform tooltipRect = _tooltipRect;
			RectTransform tooltipRect2 = _tooltipRect;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(1f, 0.5f);
			tooltipRect2.anchorMax = val2;
			tooltipRect.anchorMin = val2;
			_tooltipRect.pivot = new Vector2(0.5f, 0f);
			_tooltipRect.sizeDelta = new Vector2(110f, 28f);
			Image val3 = CreateImage("Bg", ((Component)val).transform, new Color(0.08f, 0.09f, 0.14f, 0.98f));
			Stretch((RectTransform)((Component)val3).transform, 1f);
			_tooltipText = CreateText(template, ((Component)val3).transform, "Text", 17f, (TextAlignmentOptions)514, -1f, -1f);
			Stretch((RectTransform)((TMP_Text)_tooltipText).transform, 0f);
			_tooltipObj.SetActive(false);
		}

		private static void ShowTooltip(string text, RectTransform targetRect)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_tooltipObj == (Object)null) && !((Object)(object)targetRect == (Object)null))
			{
				((TMP_Text)_tooltipText).text = text;
				_tooltipObj.SetActive(true);
				float num = Mathf.Max(68f, ((TMP_Text)_tooltipText).preferredWidth + 20f);
				_tooltipRect.sizeDelta = new Vector2(num, 28f);
				_tooltipObj.transform.SetAsLastSibling();
				Rect rect = targetRect.rect;
				float x = ((Rect)(ref rect)).center.x;
				rect = targetRect.rect;
				Vector3 val = ((Transform)targetRect).TransformPoint(new Vector3(x, ((Rect)(ref rect)).yMax, 0f));
				Vector3 val2 = _root.transform.InverseTransformPoint(val);
				_tooltipRect.anchoredPosition = new Vector2(val2.x, val2.y + 4f);
			}
		}

		private static void HideTooltip()
		{
			if ((Object)(object)_tooltipObj != (Object)null && _tooltipObj.activeSelf)
			{
				_tooltipObj.SetActive(false);
			}
		}

		private static GameObject CreateButton(TextMeshProUGUI template, Transform parent, string name, string label, float width, float height, out RectTransform rect, out Image bg)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			Image val = CreateBorderedBox(name, parent, width, height);
			rect = (RectTransform)((Component)val).transform;
			bg = CreateImage("Bg", ((Component)val).transform, ButtonNormal);
			Stretch((RectTransform)((Component)bg).transform, 1f);
			if (label != null)
			{
				TextMeshProUGUI obj = CreateText(template, ((Component)bg).transform, "Label", 20f, (TextAlignmentOptions)514, -1f, -1f);
				Stretch((RectTransform)((TMP_Text)obj).transform, 0f);
				((TMP_Text)obj).text = "<b>" + label + "</b>";
			}
			return ((Component)val).gameObject;
		}

		private static GameObject CreateIconButton(Transform parent, string name, Sprite sprite, float width, float height, out RectTransform rect, out Image bg)
		{
			//IL_001d: 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_003a: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_005a: 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)
			GameObject result = CreateButton(null, parent, name, null, width, height, out rect, out bg);
			Image obj = CreateImage("Icon", ((Component)bg).transform, Color.white);
			obj.sprite = sprite;
			RectTransform val = (RectTransform)((Component)obj).transform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			val.pivot = val2;
			Vector2 anchorMin = (val.anchorMax = val2);
			val.anchorMin = anchorMin;
			val.sizeDelta = new Vector2(22f, 22f);
			return result;
		}

		private static void UnlockCursor()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Cursor.lockState != 0)
			{
				Cursor.lockState = (CursorLockMode)0;
			}
			if (!Cursor.visible)
			{
				Cursor.visible = true;
			}
		}

		private static void ApplyPickerColor()
		{
			_pickerEdited = true;
			RebuildSvTexture();
			AppearanceService.SetCustomColor(Rgb.FromHsv(_h, _s, _v));
		}

		private static void UpdatePickerCursors()
		{
			//IL_0028: 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)
			//IL_0039: 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)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_svCursor != (Object)null)
			{
				RectTransform svCursor = _svCursor;
				RectTransform svCursor2 = _svCursor;
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(_s, _v);
				svCursor2.anchorMax = val;
				svCursor.anchorMin = val;
				_svCursor.anchoredPosition = Vector2.zero;
			}
			if ((Object)(object)_hueCursor != (Object)null)
			{
				_hueCursor.anchorMin = new Vector2(0f, _h);
				_hueCursor.anchorMax = new Vector2(1f, _h);
				_hueCursor.anchoredPosition = Vector2.zero;
			}
		}

		private static void RefreshClipboardOption(bool force = false)
		{
			//IL_0081: 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)
			if ((Object)(object)_clipboardRow == (Object)null)
			{
				return;
			}
			Rgb color;
			bool flag = TryGetClipboardColor(out color);
			string text = (flag ? color.ToHex() : null);
			if (!force && flag == _clipboardValid && text == _clipboardHex)
			{
				return;
			}
			_clipboardValid = flag;
			_clipboardHex = text;
			_clipboardRow.SetActive(flag);
			if (flag)
			{
				if ((Object)(object)_clipboardSwatch != (Object)null)
				{
					((Graphic)_clipboardSwatch).color = Color32.op_Implicit(new Color32(color.R, color.G, color.B, byte.MaxValue));
				}
				if ((Object)(object)_clipboardText != (Object)null)
				{
					((TMP_Text)_clipboardText).text = "Coller presse-papier   <color=#FFCC00>#" + text + "</color>";
				}
			}
		}

		private static bool TryGetClipboardColor(out Rgb color)
		{
			try
			{
				return Rgb.TryParseHex(GUIUtility.systemCopyBuffer, out color);
			}
			catch (Exception)
			{
				color = default(Rgb);
				return false;
			}
		}

		private static Camera GetEventCamera()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_canvas != (Object)null) || (int)_canvas.renderMode == 0)
			{
				return null;
			}
			return _canvas.worldCamera;
		}

		private static bool TryGetNormalizedPoint(RectTransform rt, Vector2 screenPos, out float nx, out float ny, bool clamp = false)
		{
			//IL_0025: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			nx = (ny = 0f);
			if ((Object)(object)rt == (Object)null || !((Component)rt).gameObject.activeInHierarchy)
			{
				return false;
			}
			Vector2 val = default(Vector2);
			if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rt, screenPos, GetEventCamera(), ref val))
			{
				return false;
			}
			Rect rect = rt.rect;
			if (((Rect)(ref rect)).width <= 0f || ((Rect)(ref rect)).height <= 0f)
			{
				return false;
			}
			if (!clamp && !((Rect)(ref rect)).Contains(val))
			{
				return false;
			}
			nx = Mathf.Clamp01((val.x - ((Rect)(ref rect)).xMin) / ((Rect)(ref rect)).width);
			ny = Mathf.Clamp01((val.y - ((Rect)(ref rect)).yMin) / ((Rect)(ref rect)).height);
			return true;
		}

		private static void RebuildSvTexture()
		{
			//IL_0089: 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)
			if ((Object)(object)_svTex == (Object)null || Mathf.Abs(_h - _renderedHue) < 0.0001f)
			{
				return;
			}
			_renderedHue = _h;
			Color32[] array = (Color32[])(object)new Color32[16384];
			float num = 127f;
			for (int i = 0; i < 128; i++)
			{
				float v = (float)i / num;
				int num2 = i * 128;
				for (int j = 0; j < 128; j++)
				{
					Rgb rgb = Rgb.FromHsv(_h, (float)j / num, v);
					array[num2 + j] = new Color32(rgb.R, rgb.G, rgb.B, byte.MaxValue);
				}
			}
			_svTex.SetPixels32(array);
			_svTex.Apply();
		}

		private static Sprite CreateHueSprite()
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0030: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_hueTex == (Object)null)
			{
				_hueTex = new Texture2D(8, 128, (TextureFormat)4, false)
				{
					filterMode = (FilterMode)1,
					wrapMode = (TextureWrapMode)1
				};
				Color32[] array = (Color32[])(object)new Color32[1024];
				float num = 127f;
				Color32 val = default(Color32);
				for (int i = 0; i < 128; i++)
				{
					Rgb rgb = Rgb.FromHsv((float)i / num, 1f, 1f);
					((Color32)(ref val))..ctor(rgb.R, rgb.G, rgb.B, byte.MaxValue);
					int num2 = i * 8;
					for (int j = 0; j < 8; j++)
					{
						array[num2 + j] = val;
					}
				}
				_hueTex.SetPixels32(array);
				_hueTex.Apply();
			}
			return Sprite.Create(_hueTex, new Rect(0f, 0f, (float)((Texture)_hueTex).width, 128f), new Vector2(0.5f, 0.5f), 100f);
		}

		private static VerticalLayoutGroup AddVerticalLayout(GameObject go, float spacing)
		{
			VerticalLayoutGroup obj = go.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing;
			((LayoutGroup)obj).childAlignment = (TextAnchor)0;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			return obj;
		}

		private static Image CreateBorderedBox(string name, Transform parent, float width, float height, float flexibleWidth = 0f)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			Image obj = CreateImage(name, parent, BorderColor);
			LayoutElement val = ((Component)obj).gameObject.AddComponent<LayoutElement>();
			float minWidth = (val.preferredWidth = width);
			val.minWidth = minWidth;
			minWidth = (val.preferredHeight = height);
			val.minHeight = minWidth;
			if (flexibleWidth > 0f)
			{
				val.flexibleWidth = flexibleWidth;
			}
			return obj;
		}

		private static void Stretch(RectTransform rt, float inset)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = Vector2.zero;
			rt.anchorMax = Vector2.one;
			rt.offsetMin = new Vector2(inset, inset);
			rt.offsetMax = new Vector2(0f - inset, 0f - inset);
		}

		private static Image CreateImage(string name, Transform parent, Color color)
		{
			//IL_002e: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			Image component = val.GetComponent<Image>();
			((Graphic)component).color = color;
			((Graphic)component).raycastTarget = false;
			return component;
		}

		private static Transform CreateHorizontalRow(string name, Transform parent, float height, float spacing)
		{
			//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)
			//IL_0026: 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)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing;
			((LayoutGroup)obj).childAlignment = (TextAnchor)3;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false);
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = childControlWidth;
			val.AddComponent<LayoutElement>().preferredHeight = height;
			return val.transform;
		}

		private static GameObject CreateFixedBox(string name, Transform parent, float size)
		{
			//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)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			float num = (obj.preferredHeight = size);
			float num3 = (obj.minHeight = num);
			float minWidth = (obj.preferredWidth = num3);
			obj.minWidth = minWidth;
			return val;
		}

		private static Image CreateSwatch(Transform parent, float size = 26f)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Image obj = CreateImage("Swatch", parent, Color.white);
			obj.sprite = CircleSprite();
			LayoutElement obj2 = ((Component)obj).gameObject.AddComponent<LayoutElement>();
			float num = (obj2.preferredHeight = size);
			float num3 = (obj2.minHeight = num);
			float minWidth = (obj2.preferredWidth = num3);
			obj2.minWidth = minWidth;
			return obj;
		}

		private static TextMeshProUGUI CreateText(TextMeshProUGUI template, Transform parent, string name, float fontSize, TextAlignmentOptions alignment, float width, float height)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer)
			});
			val.transform.SetParent(parent, false);
			TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).font = ((TMP_Text)template).font;
			((TMP_Text)obj).fontSharedMaterial = ((TMP_Text)template).fontSharedMaterial;
			((Graphic)obj).color = Color.white;
			((TMP_Text)obj).richText = true;
			((TMP_Text)obj).enableAutoSizing = false;
			((TMP_Text)obj).enableWordWrapping = false;
			((TMP_Text)obj).margin = Vector4.zero;
			((TMP_Text)obj).fontSize = fontSize;
			((TMP_Text)obj).alignment = alignment;
			((Graphic)obj).raycastTarget = false;
			((TMP_Text)obj).text = string.Empty;
			if (width > 0f || height > 0f)
			{
				LayoutElement val2 = val.AddComponent<LayoutElement>();
				if (width > 0f)
				{
					float minWidth = (val2.preferredWidth = width);
					val2.minWidth = minWidth;
				}
				if (height > 0f)
				{
					val2.preferredHeight = height;
				}
			}
			return obj;
		}

		private static Sprite CircleSprite()
		{
			//IL_0019: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_circle != (Object)null)
			{
				return _circle;
			}
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[4096];
			float num = 32f;
			float num2 = 31.5f;
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num3 = Mathf.Sqrt(((float)j - num2) * ((float)j - num2) + ((float)i - num2) * ((float)i - num2));
					array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(Mathf.Clamp01(num - num3) * 255f));
				}
			}
			val.SetPixels32(array);
			val.Apply();
			_circle = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
			return _circle;
		}

		private static Sprite PickerRingSprite()
		{
			//IL_0019: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//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)
			//IL_00c0: 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)
			if ((Object)(object)_ring != (Object)null)
			{
				return _ring;
			}
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[1024];
			float num = 15.5f;
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num2 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num));
					float num3 = Mathf.Min(Mathf.Clamp01(13f - num2), Mathf.Clamp01(num2 - 5.5f));
					byte b = (byte)Mathf.Lerp(20f, 255f, Mathf.Clamp01(9.5f - num2));
					array[i * 32 + j] = new Color32(b, b, b, (byte)(num3 * 255f));
				}
			}
			val.SetPixels32(array);
			val.Apply();
			_ring = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f);
			return _ring;
		}

		private static Sprite PaletteIconSprite()
		{
			//IL_0019: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_paletteIcon != (Object)null)
			{
				return _paletteIcon;
			}
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[1024];
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.93f, 0.87f, 0.75f, 1f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.18f, 0.14f, 0.1f, 1f);
			(float, float, Color)[] array2 = new(float, float, Color)[4]
			{
				(9.5f, 19f, new Color(1f, 0.23f, 0.19f, 1f)),
				(15f, 22f, new Color(1f, 0.8f, 0f, 1f)),
				(21f, 19.5f, new Color(0.2f, 0.78f, 0.35f, 1f)),
				(10f, 12f, new Color(0f, 0.48f, 1f, 1f))
			};
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = ((float)j - 15.5f) / 13f;
					float num2 = ((float)i - 15.5f) / 11f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					float num4 = Mathf.Clamp01((1f - num3) * 11f);
					float num5 = Mathf.Sqrt(((float)j - 21.5f) * ((float)j - 21.5f) + ((float)i - 10.5f) * ((float)i - 10.5f));
					float a = num4 * Mathf.Clamp01(num5 - 2f);
					float num6 = Mathf.Max(Mathf.Clamp01((num3 - 0.84f) * 12f), Mathf.Clamp01(3.3f - num5));
					Color val4 = Color.Lerp(val2, val3, num6);
					(float, float, Color)[] array3 = array2;
					for (int k = 0; k < array3.Length; k++)
					{
						(float, float, Color) tuple = array3[k];
						float num7 = Mathf.Sqrt(((float)j - tuple.Item1) * ((float)j - tuple.Item1) + ((float)i - tuple.Item2) * ((float)i - tuple.Item2));
						float num8 = Mathf.Clamp01(2.6f - num7);
						if (num8 > 0f)
						{
							val4 = Color.Lerp(val4, tuple.Item3, num8);
						}
					}
					val4.a = a;
					array[i * 32 + j] = Color32.op_Implicit(val4);
				}
			}
			val.SetPixels32(array);
			val.Apply();
			_paletteIcon = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f);
			return _paletteIcon;
		}

		private static Sprite EraserIconSprite()
		{
			//IL_0019: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_eraserIcon != (Object)null)
			{
				return _eraserIcon;
			}
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[1024];
			Color32 val2 = default(Color32);
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = (float)j - 15.5f;
					float num2 = (float)i - 16.5f;
					float num3 = num * 0.788f + num2 * 0.616f;
					float num4 = (0f - num) * 0.616f + num2 * 0.788f;
					float num5 = Mathf.Max(Mathf.Abs(num3) - 9.4f, 0f);
					float num6 = Mathf.Max(Mathf.Abs(num4) - 4.2f, 0f);
					float num7 = Mathf.Sqrt(num5 * num5 + num6 * num6) - 1.8f;
					if (num7 <= 0.7f)
					{
						float num8 = Mathf.Clamp01(0.7f - num7);
						if (num7 > -1.3f)
						{
							((Color32)(ref val2))..ctor((byte)45, (byte)50, (byte)70, byte.MaxValue);
						}
						else if (!(Mathf.Abs(num3 - 0.8f) < 0.8f))
						{
							val2 = ((!(num3 < 0.8f)) ? ((num4 < -2.2f) ? new Color32((byte)186, (byte)196, (byte)218, byte.MaxValue) : new Color32((byte)236, (byte)240, (byte)248, byte.MaxValue)) : ((num4 < -2.2f) ? new Color32((byte)204, (byte)88, (byte)120, byte.MaxValue) : new Color32((byte)244, (byte)128, (byte)158, byte.MaxValue)));
						}
						else
						{
							((Color32)(ref val2))..ctor((byte)55, (byte)60, (byte)82, byte.MaxValue);
						}
						val2.a = (byte)Mathf.RoundToInt(num8 * 255f);
						array[i * 32 + j] = val2;
					}
					else if (i >= 4 && i <= 5 && j >= 11 && j <= 27)
					{
						array[i * 32 + j] = new Color32((byte)200, (byte)210, (byte)232, (byte)230);
					}
				}
			}
			val.SetPixels32(array);
			val.Apply();
			_eraserIcon = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f);
			return _eraserIcon;
		}
	}
	public static class Hairstyles
	{
		private sealed class Part
		{
			public Mesh Mesh;

			public string[] BoneNames;

			public Texture2D Albedo;

			public Texture2D Normal;
		}

		private sealed class HairFollower : MonoBehaviour
		{
			private SkinnedMeshRenderer _body;

			private SkinnedMeshRenderer _hair;

			private Mesh _gameMesh;

			private Transform[] _gameBones;

			private Material _material;

			private Color _tint = Color.white;

			private Texture2D _albedo;

			private Texture2D _normal;

			public void Init(SkinnedMeshRenderer body)
			{
				_body = body;
				_gameMesh = body.sharedMesh;
				_gameBones = body.bones;
			}

			public void Show(int style, Mesh mesh, Transform[] bones, Texture2D albedo, Texture2D normal, Color tint)
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_hair == (Object)null)
				{
					GameObject val = new GameObject("ReLoupKing_Hair")
					{
						layer = ((Component)this).gameObject.layer
					};
					val.transform.SetParent(((Component)this).transform, false);
					_hair = val.AddComponent<SkinnedMeshRenderer>();
					_hair.updateWhenOffscreen = true;
				}
				if ((Object)(object)_hair.sharedMesh != (Object)(object)mesh)
				{
					_hair.sharedMesh = mesh;
					_hair.bones = bones;
					_hair.rootBone = _body.rootBone;
					Plugin.Logger.LogInfo((object)$"[Hairstyles] Style {style} on {((Object)((Component)_body).transform.root).name}");
				}
				((Renderer)_hair).shadowCastingMode = ((Renderer)_body).shadowCastingMode;
				_albedo = albedo;
				_normal = normal;
				_tint = tint;
				((Component)_hair).gameObject.SetActive(true);
				Sync(force: true);
			}

			public void Restore()
			{
				if ((Object)(object)_body.sharedMesh != (Object)(object)_gameMesh)
				{
					_body.sharedMesh = _gameMesh;
					_body.bones = _gameBones;
				}
				if ((Object)(object)_hair != (Object)null)
				{
					((Component)_hair).gameObject.SetActive(false);
				}
			}

			private void LateUpdate()
			{
				Sync(force: false);
			}

			private void Sync(bool force)
			{
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Expected O, but got Unknown
				//IL_0145: 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_0195: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_hair == (Object)null || !((Component)_hair).gameObject.activeSelf)
				{
					return;
				}
				if (((Renderer)_hair).enabled != ((Renderer)_body).enabled)
				{
					((Renderer)_hair).enabled = ((Renderer)_body).enabled;
				}
				Material sharedMaterial = ((Renderer)_body).sharedMaterial;
				if ((Object)(object)sharedMaterial == (Object)null)
				{
					return;
				}
				if ((Object)(object)_material == (Object)null)
				{
					_material = new Material(sharedMaterial)
					{
						name = "ReLoupKing_Hair"
					};
					((Renderer)_hair).sharedMaterial = _material;
					force = true;
				}
				if (force || (Object)(object)_material.shader != (Object)(object)sharedMaterial.shader)
				{
					_material.shader = sharedMaterial.shader;
					_material.mainTexture = (Texture)(object)_albedo;
					if ((Object)(object)_normal != (Object)null)
					{
						_material.SetTexture("_BumpMap", (Texture)(object)_normal);
						_material.EnableKeyword("_NORMALMAP");
					}
					_material.SetFloat("_Cull", 0f);
				}
				if (sharedMaterial.HasProperty("_BaseColor") || sharedMaterial.HasProperty("_Color"))
				{
					_material.color = _tint * sharedMaterial.color;
				}
				if (sharedMaterial.IsKeywordEnabled("_EMISSION") && sharedMaterial.HasProperty("_EmissionColor"))
				{
					_material.EnableKeyword("_EMISSION");
					_material.SetColor("_EmissionColor", sharedMaterial.GetColor("_EmissionColor"));
				}
				else
				{
					_material.DisableKeyword("_EMISSION");
				}
			}

			private void OnDestroy()
			{
				if ((Object)(object)_material != (Object)null)
				{
					Object.Destroy((Object)(object)_material);
				}
			}
		}

		private const string BundleName = "hairstyles";

		private const string BodyMeshName = "Peasant Nolant";

		private const string HairObjectName = "ReLoupKing_Hair";

		private const float TintGain = 1.25f;

		private static bool _loadAttempted;

		private static Part _bald;

		private static readonly Dictionary<int, Part> Hair = new Dictionary<int, Part>();

		public static void Apply(SkinnedMeshRenderer body, int style, Rgb hairColor)
		{
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)body == (Object)null)
			{
				return;
			}
			EnsureLoaded();
			HairFollower hairFollower = ((Component)body).GetComponent<HairFollower>();
			if ((Object)(object)hairFollower == (Object)null)
			{
				if (style == 0 || _bald == null || !Hair.ContainsKey(style) || (Object)(object)body.sharedMesh == (Object)null || ((Object)body.sharedMesh).name != "Peasant Nolant")
				{
					return;
				}
				hairFollower = ((Component)body).gameObject.AddComponent<HairFollower>();
				hairFollower.Init(body);
			}
			if (style == 0 || !Hair.TryGetValue(style, out var value) || _bald == null)
			{
				hairFollower.Restore();
				return;
			}
			Transform[] componentsInChildren = ((Component)((Component)body).transform.parent).GetComponentsInChildren<Transform>(true);
			Transform[] array = MapBones(componentsInChildren, _bald.BoneNames);
			Transform[] array2 = MapBones(componentsInChildren, value.BoneNames);
			if (array.Contains(null) || array2.Contains(null))
			{
				Plugin.Logger.LogWarning((object)("[Hairstyles] " + ((Object)((Component)body).transform.root).name + ": rig incomplete, game mesh kept."));
				hairFollower.Restore();
				return;
			}
			if ((Object)(object)body.sharedMesh != (Object)(object)_bald.Mesh)
			{
				body.sharedMesh = _bald.Mesh;
				body.bones = array;
			}
			hairFollower.Show(style, value.Mesh, array2, value.Albedo, value.Normal, Tint(hairColor));
		}

		private static Color Tint(Rgb c)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)(int)c.R / 255f * 1.25f, (float)(int)c.G / 255f * 1.25f, (float)(int)c.B / 255f * 1.25f, 1f);
		}

		private static Transform[] MapBones(Transform[] rig, string[] names)
		{
			Dictionary<string, Transform> byName = new Dictionary<string, Transform>();
			foreach (Transform val in rig)
			{
				if (!byName.ContainsKey(((Object)val).name))
				{
					byName[((Object)val).name] = val;
				}
			}
			Transform value;
			return names.Select((string n) => (!byName.TryGetValue(n, out value)) ? null : value).ToArray();
		}

		private static void EnsureLoaded()
		{
			if (_loadAttempted)
			{
				return;
			}
			_loadAttempted = true;
			try
			{
				string text = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "assets", "hairstyles");
				AssetBundle val = (File.Exists(text) ? AssetBundle.LoadFromFile(text) : null);
				if ((Object)(object)val == (Object)null)
				{
					Plugin.Logger.LogWarning((object)("[Hairstyles] AssetBundle not found or unreadable at " + text + "; hairstyles disabled."));
					return;
				}
				Dictionary<string, Texture2D> dictionary = val.LoadAllAssets<Texture2D>().ToDictionary((Texture2D t) => ((Object)t).name);
				GameObject[] array = val.LoadAllAssets<GameObject>();
				for (int num = 0; num < array.Length; num++)
				{
					SkinnedMeshRenderer[] componentsInChildren = array[num].GetComponentsInChildren<SkinnedMeshRenderer>(true);
					foreach (SkinnedMeshRenderer val2 in componentsInChildren)
					{
						Mesh sharedMesh = val2.sharedMesh;
						if (!((Object)(object)sharedMesh == (Object)null))
						{
							Part part = new Part
							{
								Mesh = sharedMesh,
								BoneNames = val2.bones.Select((Transform b) => (!((Object)(object)b != (Object)null)) ? string.Empty : ((Object)b).name).ToArray()
							};
							int result;
							if (((Object)sharedMesh).name == "Peasant Nolant")
							{
								_bald = part;
							}
							else if (((Object)sharedMesh).name.StartsWith("Hair") && int.TryParse(((Object)sharedMesh).name.Substring(4), out result) && result > 0)
							{
								dictionary.TryGetValue(((Object)sharedMesh).name + "_Albedo", out part.Albedo);
								dictionary.TryGetValue(((Object)sharedMesh).name + "_Normal", out part.Normal);
								Hair[result] = part;
							}
						}
					}
				}
				ManualLogSource logger = Plugin.Logger;
				Part bald = _bald;
				logger.LogInfo((object)($"[Hairstyles] Bald body: {((bald != null) ? new int?(bald.Mesh.vertexCount) : ((int?)null))} verts; styles: " + string.Join(", ", from h in Hair
					orderby h.Key
					select $"{h.Key} '{((Object)h.Value.Mesh).name}' ({h.Value.Mesh.vertexCount} verts)")));
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"[Hairstyles] Error loading the AssetBundle: {arg}");
			}
		}
	}
	public static class PluginInfo
	{
		public const string Guid = "com.dev.reloupking";

		public const string Name = "ReLoupKing";

		public const string Version = "2.1.0";
	}
	[BepInPlugin("com.dev.reloupking", "ReLoupKing", "2.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private void OnApplicationQuit()
		{
			AppearanceService.SaveNow();
		}

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			try
			{
				Harmony val = new Harmony("com.dev.reloupking");
				val.PatchAll(typeof(Plugin).Assembly);
				LycansNewRolesCompat.TryHook(val);
				Logger.LogInfo((object)"ReLoupKing v2.1.0 loaded");
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Failed to apply Harmony patches: {arg}");
			}
		}
	}
	public static class SavedAppearance
	{
		private const string StyleKey = "CUSTOM_HAIRSTYLE_INDEX";

		private const string PantsCutKey = "CUSTOM_PANTS_CUT_INDEX";

		private static string IndexKey(Slot slot)
		{
			return "CUSTOM_" + slot.ToString().ToUpperInvariant() + "_COLOR_INDEX";
		}

		private static string HexKey(Slot slot)
		{
			return "CUSTOM_" + slot.ToString().ToUpperInvariant() + "_COLOR_HEX";
		}

		public static Appearance Load()
		{
			return new Appearance(PlayerPrefs.GetInt("CUSTOM_HAIRSTYLE_INDEX", 0), PlayerPrefs.GetInt("CUSTOM_PANTS_CUT_INDEX", 0), LoadColor(Slot.Hair), LoadColor(Slot.Skin), LoadColor(Slot.Pants), LoadColor(Slot.Boots));
		}

		public static void Save(Appearance a)
		{
			PlayerPrefs.SetInt("CUSTOM_HAIRSTYLE_INDEX", a.Style);
			PlayerPrefs.SetInt("CUSTOM_PANTS_CUT_INDEX", a.PantsCut);
			Slot[] slots = Catalog.Slots;
			foreach (Slot slot in slots)
			{
				if (Catalog.IsColor(slot))
				{
					ColorChoice color = a.GetColor(slot);
					PlayerPrefs.SetInt(IndexKey(slot), (!color.IsCustom) ? color.Preset : 0);
					PlayerPrefs.SetString(HexKey(slot), color.IsCustom ? color.Color.ToHex() : string.Empty);
				}
			}
			PlayerPrefs.Save();
		}

		private static ColorChoice LoadColor(Slot slot)
		{
			if (Rgb.TryParseHex(PlayerPrefs.GetString(HexKey(slot), string.Empty), out var color))
			{
				return ColorChoice.FromCustom(color);
			}
			return ColorChoice.FromPreset(slot, PlayerPrefs.GetInt(IndexKey(slot), 0));
		}
	}
	public static class TextureCachePolicy
	{
		public const int MaxCount = 32;

		public const long MaxBytes = 268435456L;

		public static List<TKey> KeysToEvict<TKey>(IEnumerable<(TKey Key, long Bytes, bool InUse)> oldestFirst, int count, long totalBytes, long incomingBytes)
		{
			List<TKey> list = new List<TKey>();
			foreach (var item in oldestFirst)
			{
				if (count < 32 && totalBytes + incomingBytes <= 268435456)
				{
					break;
				}
				if (!item.InUse)
				{
					list.Add(item.Key);
					count--;
					totalBytes -= item.Bytes;
				}
			}
			return list;
		}
	}
	public static class TextureTinter
	{
		private sealed class Entry
		{
			public Texture2D Texture;

			public LinkedListNode<string> Node;

			public long Bytes;
		}

		private readonly struct Image
		{
			private readonly Color32[] _pixels;

			private readonly Color32[] _base;

			private readonly int _w;

			private readonly int _h;

			private readonly float _sx;

			private readonly float _sy;

			public Image(Color32[] pixels, Color32[] basePixels, int w, int h)
			{
				_pixels = pixels;
				_base = basePixels;
				_w = w;
				_h = h;
				_sx = (float)w / 2048f;
				_sy = (float)h / 2048f;
			}

			public void Tint(float minX, float maxX, float minY, float maxY, Rgb color, float baseLum, Func<Color32, bool> match)
			{
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				int num = Mathf.Clamp((int)(minX * _sx), 0, _w - 1);
				int num2 = Mathf.Clamp((int)(maxX * _sx), 0, _w - 1);
				int num3 = Mathf.Clamp((int)(minY * _sy), 0, _h - 1);
				int num4 = Mathf.Clamp((int)(maxY * _sy), 0, _h - 1);
				for (int i = num3; i <= num4; i++)
				{
					for (int j = num; j <= num2; j++)
					{
						int num5 = i * _w + j;
						if (match(_base[num5]))
						{
							Shade(num5, color, baseLum);
						}
					}
				}
			}

			public void TintShorts(ColorChoice pants, Rgb skin)
			{
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				int num = Mathf.Clamp((int)(1300f * _sx), 0, _