Decompiled source of Name Designer v0.1.1

NameDesigner.dll

Decompiled 2 hours 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using OnTogetherMods.Shared;
using PurrNet;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
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("NameDesigner")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+622bd7ccbb267719684ff770ce18e1834dc51b45")]
[assembly: AssemblyProduct("NameDesigner")]
[assembly: AssemblyTitle("NameDesigner")]
[assembly: AssemblyVersion("0.1.1.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 OnTogetherMods.Shared
{
	internal static class PanelStack
	{
		private const string TableKey = "OnTogetherMods.PanelStack.Panels";

		private const string HiddenKey = "OnTogetherMods.PanelStack.Hidden";

		private const string IconBarKey = "OnTogetherMods.IconBar.Rect";

		private const float Margin = 20f;

		private const float FromRight = 0.15f;

		private const float Gap = 10f;

		private const int WorldScene = 2;

		public const int PhotoModeOrder = 0;

		public const int EmoteSyncOrder = 10;

		public const int TeleportSpotsOrder = 20;

		public const int SongPlayerOrder = 30;

		public const int TraceOverlayOrder = 40;

		public const int NameDesignerOrder = 50;

		public const string CanvasPrefix = "OnTogetherMods ";

		private static int _deskFrame = -1;

		private static bool _desk;

		public static float Width => (float)Screen.width * 1080f / (float)Screen.height;

		public static bool Hidden
		{
			get
			{
				if (!(AppDomain.CurrentDomain.GetData("OnTogetherMods.PanelStack.Hidden") is int num) || Time.frameCount > num)
				{
					return InDeskMode;
				}
				return true;
			}
		}

		public static bool InDeskMode
		{
			get
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Invalid comparison between Unknown and I4
				int frameCount = Time.frameCount;
				if (_deskFrame != frameCount)
				{
					_deskFrame = frameCount;
					_desk = false;
					Scene activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).buildIndex == 2)
					{
						OverlayManager i = MonoSingleton<OverlayManager>.I;
						_desk = (Object)(object)i != (Object)null && (int)i.ResolutionMode == 3;
					}
				}
				return _desk;
			}
		}

		public static bool IsModCanvas(Canvas canvas)
		{
			Canvas val = canvas;
			Transform parent = ((Component)canvas).transform.parent;
			while ((Object)(object)parent != (Object)null)
			{
				Canvas component = ((Component)parent).GetComponent<Canvas>();
				val = (((Object)(object)component != (Object)null) ? component : val);
				parent = parent.parent;
			}
			return ((Object)((Component)val).gameObject).name.StartsWith("OnTogetherMods ", StringComparison.Ordinal);
		}

		public static void HideForCapture()
		{
			AppDomain.CurrentDomain.SetData("OnTogetherMods.PanelStack.Hidden", Time.frameCount + 1);
		}

		public static Rect Place(string id, int order, Vector2 size)
		{
			//IL_001b: 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_004d: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			Hashtable hashtable = Panels();
			int frameCount = Time.frameCount;
			hashtable[id] = new double[3] { order, size.y, frameCount };
			float width = Width;
			float num = Mathf.Max(20f, width * 0.85f - size.x);
			float num2 = Bottom(num + size.x, frameCount) - size.y;
			foreach (DictionaryEntry item in hashtable)
			{
				string text = (string)item.Key;
				double[] array = (double[])item.Value;
				bool flag = (double)frameCount - array[2] <= 2.0;
				bool flag2 = array[0] < (double)order || (array[0] == (double)order && string.CompareOrdinal(text, id) < 0);
				if (text != id && flag && flag2)
				{
					num2 -= (float)array[1] + 10f;
				}
			}
			return new Rect(num, num2, size.x, size.y);
		}

		private static float Bottom(float windowRight, int frame)
		{
			float num = 1060f;
			if (AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.Rect") is double[] array && (double)frame - array[4] <= 2.0)
			{
				float num2 = 1080f / (float)Screen.height;
				if (array[0] * (double)num2 < (double)(windowRight + 10f))
				{
					num = Mathf.Min(num, (float)array[1] * num2 - 10f);
				}
			}
			return num;
		}

		public static Matrix4x4 Begin(out float width)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)Screen.height / 1080f;
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
			width = (float)Screen.width / num;
			return matrix;
		}

		public static void End(Matrix4x4 previous)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GUI.matrix = previous;
		}

		public static GUIStyle MakeStyle(TextAnchor alignment)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.box)
			{
				alignment = alignment,
				fontSize = 15,
				richText = true,
				wordWrap = false,
				padding = new RectOffset(12, 12, 10, 10)
			};
			val.normal.textColor = Color.white;
			return val;
		}

		private static Hashtable Panels()
		{
			Hashtable hashtable = AppDomain.CurrentDomain.GetData("OnTogetherMods.PanelStack.Panels") as Hashtable;
			if (hashtable == null)
			{
				hashtable = new Hashtable();
				AppDomain.CurrentDomain.SetData("OnTogetherMods.PanelStack.Panels", hashtable);
			}
			return hashtable;
		}
	}
	internal static class IconBar
	{
		public enum State
		{
			Plain,
			Open,
			On,
			Off
		}

		public enum Click
		{
			None,
			Left,
			Right
		}

		private struct Metrics
		{
			public float Unit;

			public int Art;

			public int Button;

			public int Gap;

			public int Margin;
		}

		private static class Patches
		{
			private static Action<InputManager, bool> _setMouse0Down;

			private static Action<InputManager, bool> _setMouse1;

			private static Action<InputManager, bool> _setMouse1Up;

			private static FieldRef<QuadPainterGPU, Vector2> _previousUV;

			private static bool _leftOnBar;

			private static bool _rightOnBar;

			public static void Apply(Harmony harmony)
			{
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Expected O, but got Unknown
				_setMouse0Down = Setter("IsMouseButton0Down");
				_setMouse1 = Setter("IsMouseButton1");
				_setMouse1Up = Setter("IsMouseButton1Up");
				harmony.Patch((MethodBase)AccessTools.Method(typeof(InputManager), "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "InputPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_previousUV = AccessTools.FieldRefAccess<QuadPainterGPU, Vector2>("previousUV");
				harmony.Patch((MethodBase)AccessTools.Method(typeof(QuadPainterGPU), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "PaintPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}

			private static void InputPostfix(InputManager __instance)
			{
				bool mouseOver = MouseOver;
				if (Input.GetMouseButtonDown(0))
				{
					_leftOnBar = mouseOver;
				}
				if (Input.GetMouseButtonDown(1))
				{
					_rightOnBar = mouseOver;
				}
				if (mouseOver)
				{
					_setMouse0Down(__instance, arg2: false);
				}
				if (_rightOnBar)
				{
					_setMouse1(__instance, arg2: false);
					_setMouse1Up(__instance, arg2: false);
				}
				if (!Input.GetMouseButton(0))
				{
					_leftOnBar = false;
				}
				if (!Input.GetMouseButton(1))
				{
					_rightOnBar = false;
				}
			}

			private static bool PaintPrefix(QuadPainterGPU __instance)
			{
				if (__instance.IsActive && (_leftOnBar || MouseOver))
				{
					_previousUV.Invoke(__instance).x = -1f;
					return false;
				}
				return true;
			}

			private static Action<InputManager, bool> Setter(string property)
			{
				return (Action<InputManager, bool>)Delegate.CreateDelegate(typeof(Action<InputManager, bool>), AccessTools.PropertySetter(typeof(InputManager), property));
			}
		}

		public const int PhotoModeOrder = 0;

		public const int EmoteSyncOrder = 10;

		public const int TeleportSpotsOrder = 20;

		public const int NameDesignerOrder = 30;

		public const int DeskSnapOrder = 40;

		public const int FocusAnywhereOrder = 50;

		public const int SongPlayerOrder = 60;

		public const int TraceOverlayOrder = 70;

		public const int ChatRangeOrder = 80;

		private const string RectKey = "OnTogetherMods.IconBar.Rect";

		private const string TableKey = "OnTogetherMods.IconBar.Icons";

		private const string PatchedKey = "OnTogetherMods.IconBar.Patched";

		private const string BlockerKey = "OnTogetherMods.IconBar.Blocker";

		private const string BlockerFrameKey = "OnTogetherMods.IconBar.BlockerFrame";

		private const string HiddenKey = "OnTogetherMods.IconBar.HiddenUntil";

		private const int WorldScene = 2;

		private const int TooltipDepth = -100;

		private static readonly Dictionary<char, Color32> Palette = new Dictionary<char, Color32>
		{
			{
				'K',
				new Color32((byte)42, (byte)36, (byte)51, byte.MaxValue)
			},
			{
				'W',
				new Color32((byte)247, (byte)243, (byte)234, byte.MaxValue)
			},
			{
				'G',
				new Color32((byte)201, (byte)198, (byte)207, byte.MaxValue)
			},
			{
				'g',
				new Color32((byte)143, (byte)138, (byte)153, byte.MaxValue)
			},
			{
				'D',
				new Color32((byte)87, (byte)82, (byte)95, byte.MaxValue)
			},
			{
				'B',
				new Color32((byte)168, (byte)107, (byte)60, byte.MaxValue)
			},
			{
				'b',
				new Color32((byte)217, (byte)160, (byte)102, byte.MaxValue)
			},
			{
				'd',
				new Color32((byte)110, (byte)67, (byte)37, byte.MaxValue)
			},
			{
				'R',
				new Color32((byte)224, (byte)90, (byte)90, byte.MaxValue)
			},
			{
				'r',
				new Color32((byte)168, (byte)58, (byte)70, byte.MaxValue)
			},
			{
				'p',
				new Color32((byte)246, (byte)165, (byte)165, byte.MaxValue)
			},
			{
				'Y',
				new Color32((byte)245, (byte)208, (byte)97, byte.MaxValue)
			},
			{
				'y',
				new Color32((byte)201, (byte)150, (byte)50, byte.MaxValue)
			},
			{
				'O',
				new Color32((byte)232, (byte)146, (byte)74, byte.MaxValue)
			},
			{
				'L',
				new Color32((byte)159, (byte)214, (byte)245, byte.MaxValue)
			},
			{
				'U',
				new Color32((byte)74, (byte)143, (byte)217, byte.MaxValue)
			},
			{
				'u',
				new Color32((byte)47, (byte)90, (byte)158, byte.MaxValue)
			},
			{
				'N',
				new Color32((byte)116, (byte)192, (byte)105, byte.MaxValue)
			},
			{
				'n',
				new Color32((byte)63, (byte)138, (byte)74, byte.MaxValue)
			},
			{
				'P',
				new Color32((byte)246, (byte)207, (byte)174, byte.MaxValue)
			},
			{
				'V',
				new Color32((byte)154, (byte)114, (byte)214, byte.MaxValue)
			},
			{
				'v',
				new Color32((byte)105, (byte)72, (byte)160, byte.MaxValue)
			},
			{
				'S',
				new Color32((byte)233, (byte)139, (byte)181, byte.MaxValue)
			},
			{
				'H',
				new Color32((byte)60, (byte)48, (byte)56, byte.MaxValue)
			}
		};

		private static readonly Color32 ButtonFill = new Color32((byte)28, (byte)26, (byte)34, (byte)200);

		private static readonly Color32 ButtonEdge = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)30);

		private static readonly Color32 HoverFill = new Color32((byte)48, (byte)45, (byte)58, (byte)225);

		private static readonly Color32 HoverEdge = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)80);

		private static readonly Color32 OpenFill = new Color32((byte)70, (byte)64, (byte)88, (byte)235);

		private static readonly Color32 OpenEdge = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)150);

		private static readonly Color32 DotFill = new Color32((byte)140, (byte)220, (byte)120, byte.MaxValue);

		private static readonly Color32 DotEdge = new Color32((byte)20, (byte)40, (byte)20, byte.MaxValue);

		private static readonly Dictionary<string[], Texture2D[]> Icons = new Dictionary<string[], Texture2D[]>();

		private static Texture2D _buttonTexture;

		private static Texture2D _hoverTexture;

		private static Texture2D _openTexture;

		private static Texture2D _dotTexture;

		private static GUIStyle _buttonStyle;

		private static GUIStyle _tipStyle;

		private static int _builtFor;

		private static int _cachedFrame = -1;

		private static bool _inWorld;

		private static bool _visible;

		private static int _pressedButton;

		private static bool RowHidden
		{
			get
			{
				if (AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.HiddenUntil") is int num)
				{
					return Time.frameCount <= num;
				}
				return false;
			}
		}

		public static bool MouseOver
		{
			get
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				if (!(AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.Rect") is double[] array) || array[5] < 0.5 || (double)Time.frameCount - array[4] > 2.0)
				{
					return false;
				}
				Vector3 mousePosition = Input.mousePosition;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor((float)array[0], (float)array[1], (float)array[2], (float)array[3]);
				return ((Rect)(ref val)).Contains(new Vector2(mousePosition.x, (float)Screen.height - mousePosition.y));
			}
		}

		public static Click Draw(string id, int order, string[] pixels, State state, string name, KeyCode key, string hint = null)
		{
			//IL_0086: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			int controlID = GUIUtility.GetControlID((FocusType)2);
			Event current = Event.current;
			Refresh();
			if (!_inWorld)
			{
				Hide(controlID, current);
				UpdateBlocker(shown: false, default(Rect));
				return Click.None;
			}
			Rect bar;
			Metrics m;
			Rect icon = Place(id, order, out bar, out m);
			Share(bar);
			UpdateBlocker(_visible, bar);
			if (!_visible)
			{
				Hide(controlID, current);
				return Click.None;
			}
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.identity;
			try
			{
				return Handle(controlID, current, icon, m, pixels, state, name, key, hint);
			}
			finally
			{
				GUI.matrix = matrix;
			}
		}

		public static void HideRow()
		{
			AppDomain.CurrentDomain.SetData("OnTogetherMods.IconBar.HiddenUntil", Time.frameCount + 1);
		}

		public static string KeyText(KeyCode key)
		{
			//IL_0000: 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)
			if ((int)key != 0)
			{
				return $" ({key})";
			}
			return "";
		}

		private static Click Handle(int control, Event e, Rect icon, Metrics m, string[] pixels, State state, string name, KeyCode key, string hint)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected I4, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			bool flag = ((Rect)(ref icon)).Contains(e.mousePosition);
			EventType typeForControl = e.GetTypeForControl(control);
			switch ((int)typeForControl)
			{
			default:
			{
				if ((int)typeForControl != 7)
				{
					break;
				}
				BuildStyles(m);
				bool flag2 = GUIUtility.hotControl == control;
				_buttonStyle.normal.background = ((state == State.Open || (flag2 && flag)) ? _openTexture : (flag ? _hoverTexture : _buttonTexture));
				_buttonStyle.Draw(icon, false, false, false, false);
				Texture2D[] array = IconTextures(pixels);
				GUI.DrawTexture(new Rect(((Rect)(ref icon)).x + (((Rect)(ref icon)).width - (float)m.Art) / 2f, ((Rect)(ref icon)).y + (((Rect)(ref icon)).height - (float)m.Art) / 2f, (float)m.Art, (float)m.Art), (Texture)(object)((state == State.Off) ? array[1] : array[0]));
				if (state == State.On)
				{
					float num = Mathf.Max(1, Mathf.RoundToInt(2f * m.Unit));
					float num2 = ((Texture)_dotTexture).width;
					GUI.DrawTexture(new Rect(((Rect)(ref icon)).xMax - num - num2, ((Rect)(ref icon)).yMax - num - num2, num2, num2), (Texture)(object)_dotTexture);
				}
				int num3;
				if (flag)
				{
					num3 = ((GUIUtility.hotControl == 0 || flag2) ? 1 : 0);
					if (num3 != 0)
					{
						DrawTooltip(icon, m, Tooltip(state, name, key, hint));
					}
				}
				else
				{
					num3 = 0;
				}
				GUI.depth = ((num3 != 0) ? (-100) : 0);
				break;
			}
			case 0:
				if (flag && (e.button == 0 || e.button == 1))
				{
					GUIUtility.hotControl = control;
					_pressedButton = e.button;
					e.Use();
				}
				break;
			case 3:
				if (GUIUtility.hotControl == control)
				{
					e.Use();
				}
				break;
			case 1:
				if (GUIUtility.hotControl != control)
				{
					break;
				}
				GUIUtility.hotControl = 0;
				e.Use();
				if (flag && e.button == _pressedButton)
				{
					if (e.button != 0)
					{
						return Click.Right;
					}
					return Click.Left;
				}
				break;
			case 2:
				break;
			}
			return Click.None;
		}

		private static string Tooltip(State state, string name, KeyCode key, string hint)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			string text = name + KeyText(key);
			switch (state)
			{
			case State.On:
				text += ": on";
				break;
			case State.Off:
				text += ": off";
				break;
			}
			if (hint == null)
			{
				return text;
			}
			return text + "\n" + hint;
		}

		private static void DrawTooltip(Rect icon, Metrics m, string text)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_001f: 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)
			//IL_0068: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			GUIContent val = new GUIContent(text);
			Vector2 val2 = _tipStyle.CalcSize(val);
			float num = Mathf.Clamp(((Rect)(ref icon)).center.x - val2.x / 2f, (float)m.Margin, Mathf.Max((float)m.Margin, (float)(Screen.width - m.Margin) - val2.x));
			float num2 = ((Rect)(ref icon)).y - (float)m.Gap - val2.y;
			_tipStyle.Draw(new Rect(Mathf.Round(num), Mathf.Round(num2), val2.x, val2.y), val, false, false, false, false);
		}

		private static void Hide(int control, Event e)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			if (GUIUtility.hotControl == control)
			{
				GUIUtility.hotControl = 0;
			}
			if ((int)e.type == 7)
			{
				GUI.depth = 0;
			}
		}

		private static Metrics Measure()
		{
			float num = (float)Screen.height / 1080f;
			int num2 = Mathf.Max(1, Mathf.RoundToInt(2f * num));
			int num3 = Mathf.Max(2, Mathf.RoundToInt(4f * num));
			return new Metrics
			{
				Unit = num,
				Art = 16 * num2,
				Button = 16 * num2 + 2 * num3,
				Gap = Mathf.Max(2, Mathf.RoundToInt(6f * num)),
				Margin = Mathf.RoundToInt(20f * num)
			};
		}

		private static Rect Place(string id, int order, out Rect bar, out Metrics m)
		{
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			Hashtable hashtable = Table();
			int frameCount = Time.frameCount;
			if (hashtable[id] is double[] array)
			{
				array[0] = order;
				array[1] = frameCount;
			}
			else
			{
				hashtable[id] = new double[2] { order, frameCount };
			}
			int num = 0;
			int num2 = 0;
			foreach (DictionaryEntry item in hashtable)
			{
				string text = (string)item.Key;
				double[] array2 = (double[])item.Value;
				if (!((double)frameCount - array2[1] > 2.0))
				{
					num2++;
					if (text != id && (array2[0] < (double)order || (array2[0] == (double)order && string.CompareOrdinal(text, id) < 0)))
					{
						num++;
					}
				}
			}
			m = Measure();
			int num3 = num2 * m.Button + (num2 - 1) * m.Gap;
			int num4 = Screen.width - m.Margin - num3;
			int num5 = Screen.height - m.Margin - m.Button;
			bar = new Rect((float)num4, (float)num5, (float)num3, (float)m.Button);
			return new Rect((float)(num4 + num * (m.Button + m.Gap)), (float)num5, (float)m.Button, (float)m.Button);
		}

		private static void Share(Rect bar)
		{
			AppDomain currentDomain = AppDomain.CurrentDomain;
			int frameCount = Time.frameCount;
			if (!(currentDomain.GetData("OnTogetherMods.IconBar.Rect") is double[] array) || (int)array[4] != frameCount || !(array[2] >= (double)((Rect)(ref bar)).width))
			{
				currentDomain.SetData("OnTogetherMods.IconBar.Rect", new double[6]
				{
					((Rect)(ref bar)).x,
					((Rect)(ref bar)).y,
					((Rect)(ref bar)).width,
					((Rect)(ref bar)).height,
					frameCount,
					_visible ? 1 : 0
				});
			}
		}

		private static Hashtable Table()
		{
			Hashtable hashtable = AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.Icons") as Hashtable;
			if (hashtable == null)
			{
				hashtable = new Hashtable();
				AppDomain.CurrentDomain.SetData("OnTogetherMods.IconBar.Icons", hashtable);
			}
			return hashtable;
		}

		private static void Refresh()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between Unknown and I4
			int frameCount = Time.frameCount;
			if (_cachedFrame != frameCount)
			{
				_cachedFrame = frameCount;
				Scene activeScene = SceneManager.GetActiveScene();
				_inWorld = ((Scene)(ref activeScene)).buildIndex == 2;
				_visible = false;
				if (_inWorld && !PanelStack.Hidden && !RowHidden)
				{
					TaskManager i = MonoSingleton<TaskManager>.I;
					_visible = (Object)(object)i != (Object)null && ((int)i.LockState == 0 || (int)i.LockState == 5);
				}
			}
		}

		private static void UpdateBlocker(bool shown, Rect bar)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			AppDomain currentDomain = AppDomain.CurrentDomain;
			int frameCount = Time.frameCount;
			if (currentDomain.GetData("OnTogetherMods.IconBar.BlockerFrame") is int num && num == frameCount)
			{
				return;
			}
			currentDomain.SetData("OnTogetherMods.IconBar.BlockerFrame", frameCount);
			object? data = currentDomain.GetData("OnTogetherMods.IconBar.Blocker");
			GameObject val = (GameObject)((data is GameObject) ? data : null);
			if ((Object)(object)val == (Object)null)
			{
				if (!shown)
				{
					return;
				}
				val = CreateBlocker();
				currentDomain.SetData("OnTogetherMods.IconBar.Blocker", val);
			}
			if (shown)
			{
				RectTransform val2 = (RectTransform)val.transform.GetChild(0);
				Vector2 val3 = default(Vector2);
				((Vector2)(ref val3))..ctor(((Rect)(ref bar)).x, (float)Screen.height - ((Rect)(ref bar)).yMax);
				if (val2.anchoredPosition != val3)
				{
					val2.anchoredPosition = val3;
				}
				if (val2.sizeDelta != ((Rect)(ref bar)).size)
				{
					val2.sizeDelta = ((Rect)(ref bar)).size;
				}
			}
			if (val.activeSelf != shown)
			{
				val.SetActive(shown);
			}
		}

		private static GameObject CreateBlocker()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_0093: 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_009e: 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)
			GameObject val = new GameObject("OnTogetherMods IconBar ClickBlocker");
			Object.DontDestroyOnLoad((Object)(object)val);
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 32767;
			val.AddComponent<GraphicRaycaster>();
			GameObject val2 = new GameObject("Area", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val2.transform.SetParent(val.transform, false);
			((Graphic)val2.GetComponent<Image>()).color = Color.clear;
			RectTransform val3 = (RectTransform)val2.transform;
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = Vector2.zero;
			val3.pivot = Vector2.zero;
			val.SetActive(false);
			return val;
		}

		public static void Patch()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			AppDomain currentDomain = AppDomain.CurrentDomain;
			if (currentDomain.GetData("OnTogetherMods.IconBar.Patched") != null)
			{
				return;
			}
			currentDomain.SetData("OnTogetherMods.IconBar.Patched", true);
			try
			{
				Patches.Apply(new Harmony("nelphei.ontogether.iconbar"));
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"[OnTogetherMods] Icon bar patches failed, so clicks on it may reach the game: {arg}");
			}
		}

		private static Texture2D[] IconTextures(string[] pixels)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00b2: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			if (Icons.TryGetValue(pixels, out var value) && (Object)(object)value[0] != (Object)null && (Object)(object)value[1] != (Object)null)
			{
				return value;
			}
			Color32[] array = (Color32[])(object)new Color32[256];
			Color32[] array2 = (Color32[])(object)new Color32[256];
			for (int i = 0; i < 16; i++)
			{
				string text = ((i < pixels.Length) ? pixels[i] : "");
				for (int j = 0; j < 16; j++)
				{
					char key = ((j < text.Length) ? text[j] : '.');
					Color32 value2;
					Color32 val = (Color32)(Palette.TryGetValue(key, out value2) ? value2 : new Color32((byte)0, (byte)0, (byte)0, (byte)0));
					int num = (15 - i) * 16 + j;
					array[num] = val;
					byte b = (byte)Mathf.RoundToInt(0.3f * (float)(int)val.r + 0.59f * (float)(int)val.g + 0.11f * (float)(int)val.b);
					array2[num] = new Color32(b, b, b, (byte)((float)(int)val.a * 0.45f));
				}
			}
			value = (Texture2D[])(object)new Texture2D[2]
			{
				NewTexture(16, 16, array, (FilterMode)0),
				NewTexture(16, 16, array2, (FilterMode)0)
			};
			Icons[pixels] = value;
			return value;
		}

		private static void BuildStyles(Metrics m)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0105: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			if (_builtFor != Screen.height || _buttonStyle == null || !((Object)(object)_buttonTexture != (Object)null) || !((Object)(object)_dotTexture != (Object)null))
			{
				_builtFor = Screen.height;
				int num = Mathf.Max(2, Mathf.RoundToInt(6f * m.Unit));
				Destroy(_buttonTexture);
				Destroy(_hoverTexture);
				Destroy(_openTexture);
				Destroy(_dotTexture);
				_buttonTexture = RoundedBox(num, ButtonFill, ButtonEdge);
				_hoverTexture = RoundedBox(num, HoverFill, HoverEdge);
				_openTexture = RoundedBox(num, OpenFill, OpenEdge);
				int num2 = Mathf.Max(2, Mathf.RoundToInt(3f * m.Unit));
				_dotTexture = RoundedBox(num2, DotFill, DotEdge, 2 * num2);
				int num3 = num + 1;
				_buttonStyle = new GUIStyle
				{
					border = new RectOffset(num3, num3, num3, num3)
				};
				_tipStyle = new GUIStyle
				{
					border = new RectOffset(num3, num3, num3, num3),
					padding = new RectOffset(Mathf.RoundToInt(10f * m.Unit), Mathf.RoundToInt(10f * m.Unit), Mathf.RoundToInt(6f * m.Unit), Mathf.RoundToInt(6f * m.Unit)),
					fontSize = Mathf.Max(8, Mathf.RoundToInt(15f * m.Unit)),
					alignment = (TextAnchor)3,
					wordWrap = false,
					richText = false
				};
				_tipStyle.normal.background = _hoverTexture;
				_tipStyle.normal.textColor = Color.white;
			}
		}

		private static Texture2D RoundedBox(int radius, Color32 fill, Color32 edge, int size = 0)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			if (size <= 0)
			{
				size = 2 * radius + 4;
			}
			Color32[] array = (Color32[])(object)new Color32[size * size];
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num = (float)j + 0.5f;
					float num2 = (float)i + 0.5f;
					float num3 = Mathf.Max(Mathf.Max((float)radius - num, num - (float)(size - radius)), 0f);
					float num4 = Mathf.Max(Mathf.Max((float)radius - num2, num2 - (float)(size - radius)), 0f);
					float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4) - (float)radius;
					float num6 = Mathf.Clamp01(0.5f - num5);
					Color val = Color.Lerp(Color32.op_Implicit(fill), Color32.op_Implicit(edge), Mathf.Clamp01(num5 + 1.5f));
					val.a *= num6;
					array[i * size + j] = Color32.op_Implicit(val);
				}
			}
			return NewTexture(size, size, array, (FilterMode)1);
		}

		private static Texture2D NewTexture(int width, int height, Color32[] pixels, FilterMode filter)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false)
			{
				filterMode = filter,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			val.SetPixels32(pixels);
			val.Apply(false, true);
			return val;
		}

		private static void Destroy(Texture2D texture)
		{
			if ((Object)(object)texture != (Object)null)
			{
				Object.Destroy((Object)(object)texture);
			}
		}
	}
	internal sealed class ClickBlocker
	{
		private readonly GameObject _root;

		private readonly RectTransform _area;

		public ClickBlocker(string name)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			_root = new GameObject(name);
			Object.DontDestroyOnLoad((Object)(object)_root);
			Canvas obj = _root.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 32767;
			_root.AddComponent<GraphicRaycaster>();
			GameObject val = new GameObject("Area", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(_root.transform, false);
			((Graphic)val.GetComponent<Image>()).color = Color.clear;
			_area = (RectTransform)val.transform;
			_area.anchorMin = Vector2.zero;
			_area.anchorMax = Vector2.zero;
			_area.pivot = Vector2.zero;
			_root.SetActive(false);
		}

		public void Update(bool shown, Rect screenRect)
		{
			//IL_002d: 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)
			if (!((Object)(object)_root == (Object)null))
			{
				if (shown)
				{
					_area.anchoredPosition = new Vector2(((Rect)(ref screenRect)).x, (float)Screen.height - ((Rect)(ref screenRect)).yMax);
					_area.sizeDelta = ((Rect)(ref screenRect)).size;
				}
				if (_root.activeSelf != shown)
				{
					_root.SetActive(shown);
				}
			}
		}

		public void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
		}

		public static bool MouseIn(Rect screenRect)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 mousePosition = Input.mousePosition;
			return ((Rect)(ref screenRect)).Contains(new Vector2(mousePosition.x, (float)Screen.height - mousePosition.y));
		}
	}
	internal sealed class TextBox
	{
		public const float FontSize = 18f;

		private static readonly RectOffset Padding = new RectOffset(12, 12, 10, 10);

		private static Sprite _boxSprite;

		private static bool _lookedForBox;

		private readonly string _name;

		private readonly TextAlignmentOptions _alignment;

		private GameObject _root;

		private RectTransform _box;

		private TextMeshProUGUI _text;

		private int _drawnFrame = -100;

		private string _measured;

		private TMP_FontAsset _measuredFont;

		private Vector2 _measuredSize;

		public TMP_FontAsset Font { get; set; }

		public TextBox(string name, TextAlignmentOptions alignment)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			_name = name;
			_alignment = alignment;
		}

		public Vector2 Measure(string text)
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			Prepare();
			if (text != _measured || (Object)(object)((TMP_Text)_text).font != (Object)(object)_measuredFont)
			{
				Vector2 preferredValues = ((TMP_Text)_text).GetPreferredValues(text);
				_measuredSize = new Vector2(Mathf.Ceil(preferredValues.x) + (float)Padding.horizontal, Mathf.Ceil(preferredValues.y) + (float)Padding.vertical);
				_measured = text;
				_measuredFont = ((TMP_Text)_text).font;
			}
			return _measuredSize;
		}

		public void Draw(Rect rect, string text)
		{
			//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)
			Prepare();
			if (((TMP_Text)_text).text != text)
			{
				((TMP_Text)_text).text = text;
			}
			_box.anchoredPosition = new Vector2(((Rect)(ref rect)).x, 0f - ((Rect)(ref rect)).y);
			_box.sizeDelta = ((Rect)(ref rect)).size;
			_drawnFrame = Time.frameCount;
		}

		public void LateUpdate()
		{
			if (!((Object)(object)_root == (Object)null))
			{
				bool flag = Time.frameCount - _drawnFrame <= 1 && !PanelStack.Hidden;
				if (_root.activeSelf != flag)
				{
					_root.SetActive(flag);
				}
			}
		}

		public void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
		}

		private void Prepare()
		{
			if ((Object)(object)_root == (Object)null)
			{
				Build();
			}
			TMP_FontAsset val = (((Object)(object)Font != (Object)null) ? Font : PlayerNames.NameTagFont());
			if ((Object)(object)val != (Object)null && (Object)(object)((TMP_Text)_text).font != (Object)(object)val)
			{
				((TMP_Text)_text).font = val;
			}
			if (!_root.activeSelf && !PanelStack.Hidden)
			{
				_root.SetActive(true);
			}
		}

		private void Build()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			_root = new GameObject("OnTogetherMods " + _name);
			Object.DontDestroyOnLoad((Object)(object)_root);
			Canvas obj = _root.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 32766;
			CanvasScaler obj2 = _root.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			obj2.screenMatchMode = (ScreenMatchMode)0;
			obj2.matchWidthOrHeight = 1f;
			GameObject val = new GameObject("Box", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(_root.transform, false);
			_box = (RectTransform)val.transform;
			RectTransform box = _box;
			RectTransform box2 = _box;
			RectTransform box3 = _box;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 1f);
			box3.pivot = val2;
			Vector2 anchorMin = (box2.anchorMax = val2);
			box.anchorMin = anchorMin;
			Image component = val.GetComponent<Image>();
			((Graphic)component).raycastTarget = false;
			Sprite val4 = BoxSprite();
			if ((Object)(object)val4 != (Object)null)
			{
				component.sprite = val4;
				component.type = (Type)1;
			}
			else
			{
				((Graphic)component).color = new Color(0f, 0f, 0f, 0.65f);
			}
			GameObject val5 = new GameObject("Text", new Type[2]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer)
			});
			val5.transform.SetParent(val.transform, false);
			RectTransform val6 = (RectTransform)val5.transform;
			val6.anchorMin = Vector2.zero;
			val6.anchorMax = Vector2.one;
			val6.offsetMin = new Vector2((float)Padding.left, (float)Padding.bottom);
			val6.offsetMax = new Vector2((float)(-Padding.right), (float)(-Padding.top));
			_text = val5.AddComponent<TextMeshProUGUI>();
			((Graphic)_text).raycastTarget = false;
			((TMP_Text)_text).richText = true;
			((TMP_Text)_text).fontSize = 18f;
			((Graphic)_text).color = Color.white;
			((TMP_Text)_text).alignment = _alignment;
			((TMP_Text)_text).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)_text).overflowMode = (TextOverflowModes)0;
			_root.SetActive(false);
		}

		private static Sprite BoxSprite()
		{
			//IL_0050: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			if (!_lookedForBox)
			{
				_lookedForBox = true;
				GUIStyle box = GUI.skin.box;
				Texture2D background = box.normal.background;
				if ((Object)(object)background != (Object)null)
				{
					RectOffset border = box.border;
					_boxSprite = Sprite.Create(background, new Rect(0f, 0f, (float)((Texture)background).width, (float)((Texture)background).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4((float)border.left, (float)border.bottom, (float)border.right, (float)border.top));
				}
			}
			return _boxSprite;
		}
	}
	internal static class PlayerNames
	{
		private static readonly HashSet<string> Closable = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
		{
			"color", "b", "i", "u", "s", "size", "font", "font-weight", "material", "mark",
			"gradient", "cspace", "mspace", "voffset", "alpha", "indent", "line-height", "line-indent", "align", "rotate",
			"lowercase", "uppercase", "allcaps", "smallcaps", "sup", "sub", "width", "margin", "nobr", "link",
			"style", "noparse"
		};

		private static readonly Regex Tag = new Regex("<(/?)(#|[A-Za-z][\\w-]*)[^<>]*>");

		private static TMP_FontAsset _font;

		private static float _nextFontLookup;

		public static string Of(PlayerController player)
		{
			string text = (((Object)(object)player != (Object)null && (Object)(object)player.PlayerNameText != (Object)null) ? ((TMP_Text)player.PlayerNameText).text : null);
			if (!string.IsNullOrWhiteSpace(text))
			{
				return ForText(text.Trim());
			}
			return null;
		}

		public static string Plain(string name)
		{
			return name.Replace("<", "‹");
		}

		public static string WithoutTags(string name)
		{
			return Tag.Replace(name, "");
		}

		public static string ForText(string name)
		{
			List<string> list = new List<string>();
			bool flag = false;
			foreach (Match item in Tag.Matches(name))
			{
				string text = ((item.Groups[2].Value == "#") ? "color" : item.Groups[2].Value.ToLowerInvariant());
				bool flag2 = item.Groups[1].Value == "/";
				if (!Closable.Contains(text) || (flag && (!flag2 || !(text == "noparse"))))
				{
					continue;
				}
				if (flag2)
				{
					int num = list.LastIndexOf(text);
					if (num >= 0)
					{
						list.RemoveAt(num);
					}
				}
				else
				{
					list.Add(text);
				}
				flag = list.Contains("noparse");
			}
			StringBuilder stringBuilder = new StringBuilder(name);
			for (int num2 = list.Count - 1; num2 >= 0; num2--)
			{
				stringBuilder.Append("</").Append(list[num2]).Append('>');
			}
			return stringBuilder.ToString();
		}

		public static TMP_FontAsset NameTagFont()
		{
			if ((Object)(object)_font == (Object)null && Time.unscaledTime >= _nextFontLookup)
			{
				_nextFontLookup = Time.unscaledTime + 1f;
				PlayerController val = Object.FindAnyObjectByType<PlayerController>();
				if ((Object)(object)val != (Object)null && (Object)(object)val.PlayerNameText != (Object)null)
				{
					_font = ((TMP_Text)val.PlayerNameText).font;
				}
			}
			return _font;
		}
	}
}
namespace NameDesigner
{
	internal sealed class ColorPicker
	{
		private const int SquareSize = 64;

		private const int StripSize = 128;

		public float H;

		public float S;

		public float V = 1f;

		private Texture2D _square;

		private Texture2D _strip;

		private float _squareHue = -1f;

		private int _dragging;

		public Color Value => Color.HSVToRGB(H, S, V);

		public void Set(Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			float h = default(float);
			float num = default(float);
			float num2 = default(float);
			Color.RGBToHSV(color, ref h, ref num, ref num2);
			if (num > 0.001f && num2 > 0.001f)
			{
				H = h;
			}
			S = num;
			V = num2;
		}

		public bool Draw(Rect square, Rect strip)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected I4, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			int controlID = GUIUtility.GetControlID((FocusType)2);
			Event current = Event.current;
			bool result = false;
			EventType typeForControl = current.GetTypeForControl(controlID);
			switch ((int)typeForControl)
			{
			default:
				if ((int)typeForControl == 7)
				{
					Paint(square, strip);
				}
				break;
			case 0:
				if (current.button != 0)
				{
					break;
				}
				if (((Rect)(ref square)).Contains(current.mousePosition))
				{
					_dragging = 1;
				}
				else
				{
					if (!((Rect)(ref strip)).Contains(current.mousePosition))
					{
						break;
					}
					_dragging = 2;
				}
				GUIUtility.hotControl = controlID;
				GUIUtility.keyboardControl = 0;
				result = Move(current.mousePosition, square, strip);
				current.Use();
				break;
			case 3:
				if (GUIUtility.hotControl == controlID)
				{
					result = Move(current.mousePosition, square, strip);
					current.Use();
				}
				break;
			case 1:
				if (GUIUtility.hotControl == controlID)
				{
					GUIUtility.hotControl = 0;
					_dragging = 0;
					current.Use();
				}
				break;
			case 2:
				break;
			}
			return result;
		}

		public void Destroy()
		{
			if ((Object)(object)_square != (Object)null)
			{
				Object.Destroy((Object)(object)_square);
			}
			if ((Object)(object)_strip != (Object)null)
			{
				Object.Destroy((Object)(object)_strip);
			}
		}

		private bool Move(Vector2 mouse, Rect square, Rect strip)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			if (_dragging == 1)
			{
				S = Mathf.Clamp01((mouse.x - ((Rect)(ref square)).x) / ((Rect)(ref square)).width);
				V = 1f - Mathf.Clamp01((mouse.y - ((Rect)(ref square)).y) / ((Rect)(ref square)).height);
				return true;
			}
			if (_dragging == 2)
			{
				H = Mathf.Clamp01(1f - (mouse.y - ((Rect)(ref strip)).y) / ((Rect)(ref strip)).height);
				return true;
			}
			return false;
		}

		private void Paint(Rect square, Rect strip)
		{
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: 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_0042: 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)
			//IL_004c: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_strip == (Object)null)
			{
				_strip = NewTexture(1, 128);
				Color32[] array = (Color32[])(object)new Color32[128];
				for (int i = 0; i < 128; i++)
				{
					array[i] = Color32.op_Implicit(Color.HSVToRGB((float)i / 127f, 1f, 1f));
				}
				_strip.SetPixels32(array);
				_strip.Apply();
			}
			if ((Object)(object)_square == (Object)null)
			{
				_square = NewTexture(64, 64);
			}
			if (!Mathf.Approximately(_squareHue, H))
			{
				Color32[] array2 = (Color32[])(object)new Color32[4096];
				for (int j = 0; j < 64; j++)
				{
					for (int k = 0; k < 64; k++)
					{
						array2[j * 64 + k] = Color32.op_Implicit(Color.HSVToRGB(H, (float)k / 63f, (float)j / 63f));
					}
				}
				_square.SetPixels32(array2);
				_square.Apply();
				_squareHue = H;
			}
			GUI.DrawTexture(square, (Texture)(object)_square);
			GUI.DrawTexture(strip, (Texture)(object)_strip);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(((Rect)(ref square)).x + S * ((Rect)(ref square)).width, ((Rect)(ref square)).y + (1f - V) * ((Rect)(ref square)).height);
			Outline(new Rect(val.x - 5f, val.y - 5f, 10f, 10f), Color.black);
			Outline(new Rect(val.x - 4f, val.y - 4f, 8f, 8f), Color.white);
			float num = ((Rect)(ref strip)).y + (1f - H) * ((Rect)(ref strip)).height;
			Outline(new Rect(((Rect)(ref strip)).x - 3f, num - 3f, ((Rect)(ref strip)).width + 6f, 6f), Color.black);
			Outline(new Rect(((Rect)(ref strip)).x - 2f, num - 2f, ((Rect)(ref strip)).width + 4f, 4f), Color.white);
		}

		public static void Outline(Rect rect, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			Color color2 = GUI.color;
			GUI.color = color;
			Texture2D whiteTexture = Texture2D.whiteTexture;
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, 1f), (Texture)(object)whiteTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - 1f, ((Rect)(ref rect)).width, 1f), (Texture)(object)whiteTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)whiteTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).xMax - 1f, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)whiteTexture);
			GUI.color = color2;
		}

		public static void Fill(Rect rect, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Color color2 = GUI.color;
			GUI.color = color;
			GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color2;
		}

		private static Texture2D NewTexture(int width, int height)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			return new Texture2D(width, height, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1,
				hideFlags = (HideFlags)61
			};
		}
	}
	internal sealed class Letter
	{
		public string Text;

		public string Color;

		public bool IsBlank => string.IsNullOrWhiteSpace(Text);
	}
	internal sealed class Design
	{
		public const int MaxLetters = 40;

		private static readonly Dictionary<string, string> NamedColors = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
		{
			{ "red", "FF0000" },
			{ "lightblue", "ADD8E6" },
			{ "blue", "0000FF" },
			{ "grey", "808080" },
			{ "black", "000000" },
			{ "green", "00FF00" },
			{ "white", "FFFFFF" },
			{ "orange", "FF8000" },
			{ "purple", "A020F0" },
			{ "yellow", "FFFF00" }
		};

		public readonly List<Letter> Letters = new List<Letter>();

		public int Count => Letters.Count;

		public string Plain
		{
			get
			{
				StringBuilder stringBuilder = new StringBuilder();
				foreach (Letter letter in Letters)
				{
					stringBuilder.Append(letter.Text);
				}
				return stringBuilder.ToString();
			}
		}

		public bool IsBlank => string.IsNullOrWhiteSpace(Plain);

		public Design Clone()
		{
			Design design = new Design();
			foreach (Letter letter in Letters)
			{
				design.Letters.Add(new Letter
				{
					Text = letter.Text,
					Color = letter.Color
				});
			}
			return design;
		}

		public void Trim(int maxLetters)
		{
			if (Letters.Count > maxLetters)
			{
				Letters.RemoveRange(maxLetters, Letters.Count - maxLetters);
			}
		}

		public void SetText(string text, int maxLetters)
		{
			List<string> list = SplitLetters(Clean(text));
			if (list.Count > maxLetters)
			{
				list.RemoveRange(maxLetters, list.Count - maxLetters);
			}
			int i;
			for (i = 0; i < list.Count && i < Letters.Count && list[i] == Letters[i].Text; i++)
			{
			}
			int j;
			for (j = 0; j < list.Count - i && j < Letters.Count - i && list[list.Count - 1 - j] == Letters[Letters.Count - 1 - j].Text; j++)
			{
			}
			List<Letter> range = Letters.GetRange(i, Letters.Count - i - j);
			string text2 = ((i > 0) ? Letters[i - 1].Color : ((j > 0) ? Letters[Letters.Count - j].Color : null));
			List<Letter> list2 = new List<Letter>();
			for (int k = i; k < list.Count - j; k++)
			{
				int num = k - i;
				string color = ((num < range.Count) ? range[num].Color : ((range.Count > 0) ? range[range.Count - 1].Color : text2));
				list2.Add(new Letter
				{
					Text = list[k],
					Color = color
				});
			}
			Letters.RemoveRange(i, range.Count);
			Letters.InsertRange(i, list2);
		}

		public string ToRichText()
		{
			StringBuilder stringBuilder = new StringBuilder();
			string text = null;
			foreach (Letter letter in Letters)
			{
				if (!letter.IsBlank && letter.Color != text)
				{
					if (text != null)
					{
						stringBuilder.Append("</color>");
					}
					if (letter.Color != null)
					{
						stringBuilder.Append("<#").Append(letter.Color).Append('>');
					}
					text = letter.Color;
				}
				stringBuilder.Append(letter.Text);
			}
			if (text != null)
			{
				stringBuilder.Append("</color>");
			}
			return stringBuilder.ToString();
		}

		public string ToGuiText()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (Letter letter in Letters)
			{
				if (letter.Color != null && !letter.IsBlank)
				{
					stringBuilder.Append("<color=#").Append(letter.Color).Append('>')
						.Append(letter.Text)
						.Append("</color>");
				}
				else
				{
					stringBuilder.Append(letter.Text);
				}
			}
			return stringBuilder.ToString();
		}

		public static Design Parse(string styled, out bool dropped)
		{
			dropped = false;
			Design design = new Design();
			if (string.IsNullOrEmpty(styled))
			{
				return design;
			}
			StringBuilder stringBuilder = new StringBuilder();
			List<string> list = new List<string>();
			List<string> list2 = new List<string>();
			for (int i = 0; i < styled.Length; i++)
			{
				char c = styled[i];
				if (c == '<')
				{
					int num = styled.IndexOf('>', i + 1);
					if (num > i)
					{
						if (!ReadTag(styled.Substring(i + 1, num - i - 1).Trim(), list2))
						{
							dropped = true;
						}
						i = num;
						continue;
					}
				}
				if (IsAllowed(c))
				{
					stringBuilder.Append(c);
					list.Add((list2.Count > 0) ? list2[list2.Count - 1] : null);
				}
			}
			string text = stringBuilder.ToString();
			int[] array = StringInfo.ParseCombiningCharacters(text);
			for (int j = 0; j < array.Length; j++)
			{
				if (design.Letters.Count >= 40)
				{
					break;
				}
				int num2 = array[j];
				int length = ((j + 1 < array.Length) ? array[j + 1] : text.Length) - num2;
				design.Letters.Add(new Letter
				{
					Text = text.Substring(num2, length),
					Color = list[num2]
				});
			}
			return design;
		}

		private static bool ReadTag(string tag, List<string> stack)
		{
			if (tag.Equals("/color", StringComparison.OrdinalIgnoreCase))
			{
				if (stack.Count > 0)
				{
					stack.RemoveAt(stack.Count - 1);
				}
				return true;
			}
			string text = null;
			if (tag.StartsWith("#", StringComparison.Ordinal))
			{
				text = tag;
			}
			else if (tag.StartsWith("color=", StringComparison.OrdinalIgnoreCase))
			{
				text = tag.Substring(6).Trim().Trim('"', '\'');
			}
			if (text == null)
			{
				return false;
			}
			string value;
			string text2 = (text.StartsWith("#", StringComparison.Ordinal) ? NormalizeHex(text.Substring(1)) : (NamedColors.TryGetValue(text, out value) ? value : null));
			if (text2 == null)
			{
				return false;
			}
			stack.Add(text2);
			return true;
		}

		public static string NormalizeHex(string hex)
		{
			if (hex == null)
			{
				return null;
			}
			hex = hex.Trim().TrimStart('#');
			string text = hex;
			for (int i = 0; i < text.Length; i++)
			{
				if (!Uri.IsHexDigit(text[i]))
				{
					return null;
				}
			}
			switch (hex.Length)
			{
			case 3:
			case 4:
				return new string(new char[6]
				{
					hex[0],
					hex[0],
					hex[1],
					hex[1],
					hex[2],
					hex[2]
				}).ToUpperInvariant();
			case 6:
			case 8:
				return hex.Substring(0, 6).ToUpperInvariant();
			default:
				return null;
			}
		}

		public static string ToHex(Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ColorUtility.ToHtmlStringRGB(color);
		}

		public static Color FromHex(string hex)
		{
			//IL_0017: 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)
			Color result = default(Color);
			if (hex == null || !ColorUtility.TryParseHtmlString("#" + hex, ref result))
			{
				return Color.white;
			}
			return result;
		}

		private static List<string> SplitLetters(string text)
		{
			List<string> list = new List<string>();
			TextElementEnumerator textElementEnumerator = StringInfo.GetTextElementEnumerator(text);
			while (textElementEnumerator.MoveNext())
			{
				list.Add(textElementEnumerator.GetTextElement());
			}
			return list;
		}

		private static string Clean(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder(text.Length);
			foreach (char c in text)
			{
				if (IsAllowed(c))
				{
					stringBuilder.Append(c);
				}
			}
			return stringBuilder.ToString();
		}

		private static bool IsAllowed(char c)
		{
			if (c != '<' && c != '>')
			{
				return !char.IsControl(c);
			}
			return false;
		}
	}
	internal sealed class DesignerWindow : MonoBehaviour
	{
		private enum Tab
		{
			Name,
			Session
		}

		private sealed class TabState
		{
			public Design Design = new Design();

			public readonly SortedSet<int> Picked = new SortedSet<int>();

			public int Anchor = -1;
		}

		private const string PanelId = "NameDesigner";

		private const string TextFieldName = "NameDesigner.Text";

		private const string HexFieldName = "NameDesigner.Hex";

		private const float Width = 500f;

		private const float Pad = 10f;

		private const float Gap = 6f;

		private const float HeaderHeight = 26f;

		private const float RowHeight = 30f;

		private const float LetterWidth = 28f;

		private const float LetterHeight = 38f;

		private const float LetterGap = 3f;

		private const float TipHeight = 18f;

		private const float ToolsHeight = 28f;

		private const float PickerSize = 150f;

		private const float StripWidth = 22f;

		private const float SwatchSize = 26f;

		private const float LabelHeight = 20f;

		private const float SaveHeight = 22f;

		private const float BoxGap = 20f;

		private const float StatusSeconds = 5f;

		private const float ConfirmSeconds = 3f;

		private static readonly string[] Swatches = new string[16]
		{
			"FF5C5C", "FF9F43", "FFD93D", "6BCB77", "4D96FF", "9B5DE5", "F15BB5", "00BBF9", "FFADAD", "FFD6A5",
			"FDFFB6", "CAFFBF", "A0C4FF", "BDB2FF", "FFFFFF", "303030"
		};

		private static DesignerWindow _instance;

		private readonly PresetStore _presets = new PresetStore();

		private readonly ColorPicker _picker = new ColorPicker();

		private readonly TabState _name = new TabState();

		private readonly TabState _session = new TabState();

		private readonly TextBox _preview = new TextBox("NameDesigner Preview", (TextAlignmentOptions)514);

		private ClickBlocker _blocker;

		private bool _open;

		private bool _iconClicked;

		private Tab _tab;

		private bool _autoOpened;

		private bool _boxWasShowing;

		private bool _nameLoaded;

		private string _sessionWritten;

		private string _hexText = "FFFFFF";

		private bool _typing;

		private bool _clearFocus;

		private int _dragFrom = -1;

		private int _confirmSlot = -1;

		private float _confirmUntil;

		private string _status;

		private float _statusUntil;

		private Rect _screenRect;

		private int _drawnFrame = -100;

		private GUIStyle _boxStyle;

		private GUIStyle _titleStyle;

		private GUIStyle _keyStyle;

		private GUIStyle _tabStyle;

		private GUIStyle _buttonStyle;

		private GUIStyle _fieldStyle;

		private GUIStyle _letterStyle;

		private GUIStyle _presetStyle;

		private GUIStyle _labelStyle;

		private GUIStyle _tipStyle;

		private GUIStyle _hintStyle;

		private GUIStyle _statusStyle;

		internal static bool IsTyping
		{
			get
			{
				if ((Object)(object)_instance != (Object)null && _instance._open)
				{
					return _instance._typing;
				}
				return false;
			}
		}

		internal static bool HoldsKeys
		{
			get
			{
				if (IsTyping)
				{
					return !PanelStack.Hidden;
				}
				return false;
			}
		}

		internal static bool IsMouseOver { get; private set; }

		private static Settings S => Plugin.Settings;

		private TabState Current
		{
			get
			{
				if (_tab != Tab.Name)
				{
					return _session;
				}
				return _name;
			}
		}

		private Design[] Slots
		{
			get
			{
				if (_tab != Tab.Name)
				{
					return _presets.Sessions;
				}
				return _presets.Names;
			}
		}

		private void Awake()
		{
			_instance = this;
			_presets.Load();
			_blocker = new ClickBlocker("NameDesigner ClickBlocker");
		}

		private void OnDestroy()
		{
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
				IsMouseOver = false;
			}
			_blocker?.Destroy();
			_preview.Destroy();
			_picker.Destroy();
		}

		private void Update()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				bool sessionBoxShowing = Game.SessionBoxShowing;
				if (sessionBoxShowing != _boxWasShowing)
				{
					_boxWasShowing = sessionBoxShowing;
					if (sessionBoxShowing)
					{
						BoxAppeared();
					}
					else if (_autoOpened)
					{
						Close();
					}
				}
				bool iconClicked = _iconClicked;
				_iconClicked = false;
				if ((Input.GetKeyDown(S.ToggleKey.Value) && !IsChatOpen()) || iconClicked)
				{
					if (_open)
					{
						Close();
					}
					else
					{
						Open(_tab);
					}
				}
				if (_open && _tab == Tab.Session && sessionBoxShowing)
				{
					string text = Game.SessionField.text;
					if (text != _sessionWritten)
					{
						ImportSession(text);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
			}
			UpdateMouseOver();
		}

		private void LateUpdate()
		{
			_preview.LateUpdate();
		}

		private void BoxAppeared()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (S.DebugLog.Value)
			{
				Plugin.Log.LogInfo((object)(Game.SessionBoxBounds(out var bounds) ? $"Create Session box at {bounds} (1080p units, screen {PanelStack.Width:0} wide)." : "Create Session box is showing, but its spot on screen wasn't found."));
			}
			if (_open)
			{
				if (_tab == Tab.Session)
				{
					StartSessionSync();
				}
			}
			else if (S.OpenWithCreateSession.Value)
			{
				Open(Tab.Session);
				_autoOpened = true;
			}
		}

		private void Open(Tab tab)
		{
			_open = true;
			_autoOpened = false;
			_status = null;
			if (!_nameLoaded)
			{
				LoadName();
				_nameLoaded = true;
			}
			SwitchTab(tab);
		}

		private void Close()
		{
			_open = false;
			_autoOpened = false;
			_typing = false;
			_dragFrom = -1;
			_confirmSlot = -1;
			_clearFocus = true;
		}

		private void SwitchTab(Tab tab)
		{
			_tab = tab;
			_dragFrom = -1;
			_confirmSlot = -1;
			GUIUtility.keyboardControl = 0;
			if (tab == Tab.Session && Game.SessionBoxShowing)
			{
				StartSessionSync();
			}
			SyncPicker(Current);
		}

		private void UpdateMouseOver()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			bool flag = _open && Time.frameCount - _drawnFrame <= 2;
			IsMouseOver = flag && ClickBlocker.MouseIn(_screenRect);
			_blocker?.Update(flag, _screenRect);
		}

		private static bool IsChatOpen()
		{
			TaskManager i = MonoSingleton<TaskManager>.I;
			if ((Object)(object)i != (Object)null)
			{
				return i.IsWriting;
			}
			return false;
		}

		private bool LoadName()
		{
			_name.Design = Design.Parse(Game.CurrentName(), out var dropped);
			ClearPicked(_name);
			if (dropped)
			{
				Status("Some styling in your name (like sizes) can't be edited here, so it's left out.");
			}
			return !dropped;
		}

		private void ApplyName()
		{
			if (_name.Design.IsBlank)
			{
				Status("Type a name first");
				return;
			}
			try
			{
				bool flag = Game.ApplyName(_name.Design.ToRichText());
				Status(flag ? "Name applied. Everyone sees it now." : "Name saved. Everyone sees it when you join a world.");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
				Status("Couldn't apply the name. See the BepInEx log.");
			}
		}

		private void StartSessionSync()
		{
			string text = Game.SessionField.text;
			if (string.IsNullOrEmpty(text) && _session.Design.Count > 0)
			{
				WriteSession();
			}
			else
			{
				ImportSession(text);
			}
		}

		private void ImportSession(string text)
		{
			_session.Design = Design.Parse(text, out var dropped);
			_sessionWritten = text;
			ClampPicked(_session);
			if (dropped)
			{
				Status("Some styling in the box (like sizes) can't be edited here, so it's left out.");
			}
		}

		private void WriteSession()
		{
			_sessionWritten = Game.WriteSession(_session.Design.ToRichText());
		}

		private void Changed(TabState tab)
		{
			if (tab == _session && Game.SessionBoxShowing)
			{
				WriteSession();
			}
		}

		private static List<int> Targets(TabState tab, bool skipBlank)
		{
			IEnumerable<int> source;
			if (tab.Picked.Count <= 0)
			{
				source = Enumerable.Range(0, tab.Design.Count);
			}
			else
			{
				IEnumerable<int> picked = tab.Picked;
				source = picked;
			}
			return source.Where((int i) => i < tab.Design.Count && (!skipBlank || !tab.Design.Letters[i].IsBlank)).ToList();
		}

		private void SetColour(TabState tab, string hex)
		{
			foreach (int item in Targets(tab, skipBlank: false))
			{
				tab.Design.Letters[item].Color = hex;
			}
			Changed(tab);
		}

		private void SyncPicker(TabState tab)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			foreach (int item in Targets(tab, skipBlank: true))
			{
				string color = tab.Design.Letters[item].Color;
				if (color != null)
				{
					_picker.Set(Design.FromHex(color));
					_hexText = color;
					break;
				}
			}
		}

		private void Gradient(TabState tab)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			List<int> list = Targets(tab, skipBlank: true);
			if (list.Count < 2)
			{
				Status("A gradient needs at least 2 letters");
				return;
			}
			Letter letter = tab.Design.Letters[list[0]];
			Letter letter2 = tab.Design.Letters[list[list.Count - 1]];
			Color val = Design.FromHex(letter.Color);
			Color val2 = Design.FromHex(letter2.Color);
			if (letter.Color == letter2.Color)
			{
				Status("Give the first and last letters different colours, then click Gradient.");
				return;
			}
			for (int i = 0; i < list.Count; i++)
			{
				tab.Design.Letters[list[i]].Color = Design.ToHex(Color.Lerp(val, val2, (float)i / ((float)list.Count - 1f)));
			}
			Changed(tab);
		}

		private void Rainbow(TabState tab)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			List<int> list = Targets(tab, skipBlank: true);
			if (list.Count != 0)
			{
				float num = ((_picker.S < 0.25f) ? 0.75f : _picker.S);
				float num2 = ((_picker.V < 0.35f) ? 1f : _picker.V);
				for (int i = 0; i < list.Count; i++)
				{
					float num3 = ((list.Count == 1) ? 0f : (0.8f * (float)i / ((float)list.Count - 1f)));
					tab.Design.Letters[list[i]].Color = Design.ToHex(Color.HSVToRGB(num3, num, num2));
				}
				Changed(tab);
			}
		}

		private static void ClearPicked(TabState tab)
		{
			tab.Picked.Clear();
			tab.Anchor = -1;
		}

		private static void ClampPicked(TabState tab)
		{
			tab.Picked.RemoveWhere((int i) => i >= tab.Design.Count);
			if (tab.Anchor >= tab.Design.Count)
			{
				tab.Anchor = -1;
			}
		}

		private static void PickRange(TabState tab, int a, int b)
		{
			tab.Picked.Clear();
			for (int i = Math.Min(a, b); i <= Math.Max(a, b); i++)
			{
				tab.Picked.Add(i);
			}
		}

		private void LoadPreset(TabState tab, int slot)
		{
			Design design = Slots[slot];
			if (design != null)
			{
				tab.Design = design.Clone();
				tab.Design.Trim(Limit());
				ClearPicked(tab);
				SyncPicker(tab);
				Changed(tab);
				Status((_tab == Tab.Name) ? $"Loaded preset {slot + 1}. Click Apply name to use it." : $"Loaded preset {slot + 1}");
			}
		}

		private void SavePreset(TabState tab, int slot)
		{
			if (tab.Design.IsBlank)
			{
				Status("Type a name first");
			}
			else if (Slots[slot] != null && (_confirmSlot != slot || !(Time.unscaledTime < _confirmUntil)))
			{
				_confirmSlot = slot;
				_confirmUntil = Time.unscaledTime + 3f;
			}
			else
			{
				_confirmSlot = -1;
				Slots[slot] = tab.Design.Clone();
				Status(_presets.Save() ? $"Saved to preset {slot + 1}" : "Couldn't save the presets file. See the BepInEx log.");
			}
		}

		private void Status(string text)
		{
			_status = text;
			_statusUntil = Time.unscaledTime + 5f;
		}

		private int Limit()
		{
			if (_tab != Tab.Name)
			{
				return Game.SessionLimit();
			}
			return Game.NameLimit();
		}

		private void OnGUI()
		{
			//IL_00bd: 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_0082: 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 (S.ShowIcon.Value && IconBar.Draw("NameDesigner", 30, Icon.Pixels, _open ? IconBar.State.Open : IconBar.State.Plain, "Name Designer", S.ToggleKey.Value) == IconBar.Click.Left)
			{
				_iconClicked = true;
			}
			if (_clearFocus)
			{
				GUIUtility.keyboardControl = 0;
				_clearFocus = false;
			}
			if (!_open || PanelStack.Hidden)
			{
				return;
			}
			if (_boxStyle == null)
			{
				MakeStyles();
			}
			float width;
			Matrix4x4 previous = PanelStack.Begin(out width);
			try
			{
				DrawWindow(width);
			}
			catch (Exception ex) when (!(ex is ExitGUIException))
			{
				Plugin.Log.LogError((object)ex);
			}
			finally
			{
				PanelStack.End(previous);
			}
		}

		private void DrawWindow(float screenWidth)
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: 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_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			TabState current = Current;
			int limit = Limit();
			float num = 480f;
			int num2 = Mathf.Max(1, Mathf.FloorToInt((num + 3f) / 31f));
			int num3 = Mathf.Max(1, Mathf.CeilToInt((float)current.Design.Count / (float)num2));
			float num4 = (float)num3 * 38f + (float)(num3 - 1) * 3f;
			float num5 = 78f + num4 + 4f + 18f + 6f + 28f + 8f + 150f + 10f + 20f + 30f + 3f + 22f + 10f + 30f + 10f;
			string text = current.Design.ToRichText();
			string text2 = ((current.Design.Count > 0) ? text : "<color=#FFFFFF66>(empty)</color>");
			_preview.Font = ((_tab == Tab.Session) ? (Game.SessionFont() ?? Game.NameFont()) : Game.NameFont());
			Vector2 val = _preview.Measure(text2);
			val.x = Mathf.Clamp(val.x, 160f, 500f);
			Rect area = Place(new Vector2(500f, val.y + 6f + num5), screenWidth);
			_preview.Draw(new Rect(((Rect)(ref area)).x + (500f - val.x) / 2f, ((Rect)(ref area)).y, val.x, val.y), text2);
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(((Rect)(ref area)).x, ((Rect)(ref area)).y + val.y + 6f, 500f, num5);
			float num6 = (float)Screen.height / 1080f;
			_screenRect = new Rect(((Rect)(ref area)).x * num6, ((Rect)(ref area)).y * num6, ((Rect)(ref area)).width * num6, ((Rect)(ref area)).height * num6);
			_drawnFrame = Time.frameCount;
			HandleKeys();
			HandleClickAway(area);
			GUI.Box(val2, GUIContent.none, _boxStyle);
			float num7 = ((Rect)(ref val2)).x + 10f;
			float num8 = ((Rect)(ref val2)).y + 10f;
			DrawHeader(new Rect(num7, num8, num, 26f));
			num8 += 32f;
			DrawTextRow(new Rect(num7, num8, num, 30f), current, limit);
			num8 += 36f;
			DrawLetters(new Rect(num7, num8, num, num4), current, num2);
			num8 += num4 + 4f;
			GUI.Label(new Rect(num7, num8, num, 18f), PickTip(current), _tipStyle);
			num8 += 24f;
			DrawTools(new Rect(num7, num8, num, 28f), current);
			num8 += 36f;
			DrawPicker(new Rect(num7, num8, num, 150f), current);
			num8 += 160f;
			DrawPresets(new Rect(num7, num8, num, 75f), current);
			num8 += 85f;
			DrawAction(new Rect(num7, num8, num, 30f), current);
			string nameOfFocusedControl = GUI.GetNameOfFocusedControl();
			_typing = nameOfFocusedControl == "NameDesigner.Text" || nameOfFocusedControl == "NameDesigner.Hex";
		}

		private static Rect Place(Vector2 size, float screenWidth)
		{
			//IL_00ad: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			if (Game.SessionBoxShowing && Game.SessionBoxBounds(out var bounds))
			{
				float num = ((Rect)(ref bounds)).xMax + 20f;
				if (num + size.x > screenWidth - 10f)
				{
					num = ((Rect)(ref bounds)).x - 20f - size.x;
				}
				if (num >= 10f)
				{
					float num2 = Mathf.Clamp(((Rect)(ref bounds)).center.y - size.y / 2f, 10f, Mathf.Max(10f, 1080f - size.y - 10f));
					return new Rect(num, num2, size.x, size.y);
				}
			}
			return PanelStack.Place("NameDesigner", 50, size);
		}

		private void HandleKeys()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			Event current = Event.current;
			if ((int)current.type == 4 && _typing && ((int)current.keyCode == 13 || (int)current.keyCode == 271 || (int)current.keyCode == 27))
			{
				GUIUtility.keyboardControl = 0;
				current.Use();
			}
		}

		private static void HandleClickAway(Rect area)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			Event current = Event.current;
			if ((int)current.type == 0 && !((Rect)(ref area)).Contains(current.mousePosition))
			{
				GUIUtility.keyboardControl = 0;
			}
		}

		private void DrawHeader(Rect row)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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)
			GUI.Label(row, "<b>NAME DESIGNER</b>", _titleStyle);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref row)).x + 150f, ((Rect)(ref row)).y, 84f, ((Rect)(ref row)).height);
			Rect val2 = new Rect(((Rect)(ref val)).xMax + 4f, ((Rect)(ref row)).y, 84f, ((Rect)(ref row)).height);
			if (GUI.Toggle(val, _tab == Tab.Name, "Name", _tabStyle) && _tab != Tab.Name)
			{
				SwitchTab(Tab.Name);
			}
			if (GUI.Toggle(val2, _tab == Tab.Session, "Session", _tabStyle) && _tab != Tab.Session)
			{
				SwitchTab(Tab.Session);
			}
			GUI.Label(row, $"{S.ToggleKey.Value} to close", _keyStyle);
		}

		private void DrawTextRow(Rect row, TabState tab, int limit)
		{
			//IL_0028: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			Rect val = new Rect(((Rect)(ref row)).x, ((Rect)(ref row)).y, ((Rect)(ref row)).width - 90f - 6f, ((Rect)(ref row)).height);
			string plain = tab.Design.Plain;
			GUI.SetNextControlName("NameDesigner.Text");
			string text = GUI.TextField(val, plain, limit * 2, _fieldStyle);
			if (text != plain)
			{
				tab.Design.SetText(text, limit);
				ClampPicked(tab);
				Changed(tab);
			}
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(((Rect)(ref row)).xMax - 90f, ((Rect)(ref row)).y, 90f, ((Rect)(ref row)).height);
			if (_tab == Tab.Name)
			{
				if (GUI.Button(val2, "Reset", _buttonStyle))
				{
					GUIUtility.keyboardControl = 0;
					if (LoadName())
					{
						Status("Back to your current name");
					}
					SyncPicker(_name);
				}
				return;
			}
			GUI.enabled = tab.Design.Count > 0;
			if (GUI.Button(val2, "Clear", _buttonStyle))
			{
				GUIUtility.keyboardControl = 0;
				tab.Design = new Design();
				ClearPicked(tab);
				Changed(tab);
			}
			GUI.enabled = true;
		}

		private void DrawLetters(Rect area, TabState tab, int perRow)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected I4, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Invalid comparison between Unknown and I4
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			int controlID = GUIUtility.GetControlID((FocusType)2);
			Event current = Event.current;
			List<Letter> letters = tab.Design.Letters;
			EventType typeForControl = current.GetTypeForControl(controlID);
			switch ((int)typeForControl)
			{
			case 0:
			{
				if (current.button != 0 || !((Rect)(ref area)).Contains(current.mousePosition))
				{
					break;
				}
				GUIUtility.keyboardControl = 0;
				int num = LetterAt(area, perRow, letters.Count, current.mousePosition, nearest: false);
				if (num < 0)
				{
					ClearPicked(tab);
				}
				else if (current.shift && tab.Anchor >= 0)
				{
					PickRange(tab, tab.Anchor, num);
				}
				else if (current.control || current.command)
				{
					if (!tab.Picked.Remove(num))
					{
						tab.Picked.Add(num);
					}
					tab.Anchor = num;
				}
				else if (tab.Picked.Count == 1 && tab.Picked.Contains(num))
				{
					ClearPicked(tab);
				}
				else
				{
					PickRange(tab, num, num);
					tab.Anchor = num;
					_dragFrom = num;
					GUIUtility.hotControl = controlID;
				}
				SyncPicker(tab);
				current.Use();
				break;
			}
			case 3:
				if (GUIUtility.hotControl == controlID && _dragFrom >= 0)
				{
					int num2 = LetterAt(area, perRow, letters.Count, current.mousePosition, nearest: true);
					if (num2 >= 0)
					{
						PickRange(tab, _dragFrom, num2);
					}
					current.Use();
				}
				break;
			case 1:
				if (GUIUtility.hotControl == controlID)
				{
					GUIUtility.hotControl = 0;
					_dragFrom = -1;
					current.Use();
				}
				break;
			}
			if ((int)current.type != 7)
			{
				return;
			}
			if (letters.Count == 0)
			{
				GUI.Label(area, "Type a name above", _hintStyle);
				return;
			}
			Rect rect2 = default(Rect);
			for (int i = 0; i < letters.Count; i++)
			{
				Rect rect = LetterRect(area, perRow, i);
				bool flag = tab.Picked.Contains(i);
				ColorPicker.Fill(rect, flag ? new Color(0.3f, 0.55f, 1f, 0.85f) : new Color(1f, 1f, 1f, 0.1f));
				Letter letter = letters[i];
				_letterStyle.normal.textColor = ((letter.Color != null) ? Design.FromHex(letter.Color) : Color.white);
				GUI.Label(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height - 8f), letter.IsBlank ? "·" : letter.Text, _letterStyle);
				((Rect)(ref rect2))..ctor(((Rect)(ref rect)).x + 3f, ((Rect)(ref rect)).yMax - 7f, ((Rect)(ref rect)).width - 6f, 4f);
				if (letter.Color != null)
				{
					ColorPicker.Fill(rect2, Design.FromHex(letter.Color));
				}
				else
				{
					ColorPicker.Outline(rect2, new Color(1f, 1f, 1f, 0.35f));
				}
			}
		}

		private static Rect LetterRect(Rect area, int perRow, int index)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			int num = index % perRow;
			int num2 = index / perRow;
			return new Rect(((Rect)(ref area)).x + (float)num * 31f, ((Rect)(ref area)).y + (float)num2 * 41f, 28f, 38f);
		}

		private static int LetterAt(Rect area, int perRow, int count, Vector2 mouse, bool nearest)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0018: Unknown result type (might be due to invalid IL or missing references)
			if (count == 0)
			{
				return -1;
			}
			if (!nearest)
			{
				for (int i = 0; i < count; i++)
				{
					Rect val = LetterRect(area, perRow, i);
					if (((Rect)(ref val)).Contains(mouse))
					{
						return i;
					}
				}
				return -1;
			}
			int num = (count + perRow - 1) / perRow;
			int num2 = Mathf.Clamp(Mathf.FloorToInt((mouse.y - ((Rect)(ref area)).y) / 41f), 0, num - 1);
			int num3 = Mathf.Clamp(Mathf.FloorToInt((mouse.x - ((Rect)(ref area)).x) / 31f), 0, perRow - 1);
			return Mathf.Min(num2 * perRow + num3, count - 1);
		}

		private static string PickTip(TabState tab)
		{
			if (tab.Design.Count == 0)
			{
				return "";
			}
			int count = tab.Picked.Count;
			if (count != 0)
			{
				return string.Format("Colouring {0} letter{1}. Shift-click for a range, Ctrl-click to add one.", count, (count == 1) ? "" : "s");
			}
			return "Colouring the whole name. Click letters to colour just those.";
		}

		private void DrawTools(Rect row, TabState tab)
		{
			//IL_004b: 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_00d4: 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)
			float num = (((Rect)(ref row)).width - 18f) / 4f;
			bool enabled = tab.Design.Count > 0;
			GUI.enabled = tab.Picked.Count > 0;
			if (GUI.Button(new Rect(((Rect)(ref row)).x, ((Rect)(ref row)).y, num, ((Rect)(ref row)).height), "Whole name", _buttonStyle))
			{
				ClearPicked(tab);
				SyncPicker(tab);
			}
			GUI.enabled = enabled;
			if (GUI.Button(new Rect(((Rect)(ref row)).x + (num + 6f), ((Rect)(ref row)).y, num, ((Rect)(ref row)).height), "Gradient", _buttonStyle))
			{
				Gradient(tab);
			}
			if (GUI.Button(new Rect(((Rect)(ref row)).x + 2f * (num + 6f), ((Rect)(ref row)).y, num, ((Rect)(ref row)).height), "Rainbow", _buttonStyle))
			{
				Rainbow(tab);
			}
			if (GUI.Button(new Rect(((Rect)(ref row)).x + 3f * (num + 6f), ((Rect)(ref row)).y, num, ((Rect)(ref row)).height), "No colour", _buttonStyle))
			{
				SetColour(tab, null);
			}
			GUI.enabled = true;
		}

		private void DrawPicker(Rect area, TabState tab)
		{
			//IL_004a: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result typ