Decompiled source of LocalChatRange v1.1.2

LocalChatRange.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Rendering;
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("LocalChatRange")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+b1076dc22b10be00321e51453a39415973772279")]
[assembly: AssemblyProduct("LocalChatRange")]
[assembly: AssemblyTitle("LocalChatRange")]
[assembly: AssemblyVersion("1.1.2.0")]
namespace LocalChatRange;

internal static class ChatCommands
{
	public const string CommandApiGuid = "com.on-together-mods.commandapi";

	private static readonly string[] Names = new string[2] { "chatrange", "lcr" };

	private const string Usage = "/chatrange - show/hide the local chat area (hotkey: {0})\n/chatrange on | off\n/chatrange mode always | local | typing\n/chatrange players on | off - highlight players in range\n/chatrange status";

	public static bool TryExecute(string text)
	{
		if (string.IsNullOrEmpty(text) || text[0] != '/')
		{
			return false;
		}
		string[] array = text.Substring(1).Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
		if (array.Length == 0 || Array.IndexOf(Names, array[0].ToLowerInvariant()) < 0)
		{
			return false;
		}
		Execute(array.Skip(1).ToArray());
		return true;
	}

	public static void Execute(string[] args)
	{
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		Plugin instance = Plugin.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		string text = ((args.Length != 0) ? args[0].ToLowerInvariant() : "toggle");
		string text2 = ((args.Length > 1) ? args[1].ToLowerInvariant() : null);
		switch (text)
		{
		case "toggle":
			instance.SetEnabled(!instance.Enabled.Value, notify: true);
			break;
		case "show":
		case "on":
			instance.SetEnabled(enabled: true, notify: true);
			break;
		case "hide":
		case "off":
			instance.SetEnabled(enabled: false, notify: true);
			break;
		case "mode":
		{
			if (TryParseMode(text2, out var mode))
			{
				instance.Mode.Value = mode;
				GameAccess.Notify("Mode: " + Plugin.Describe(mode));
			}
			else
			{
				GameAccess.Notify("Usage: /chatrange mode always | local | typing");
			}
			break;
		}
		case "players":
			if (text2 == "on" || text2 == "off")
			{
				instance.HighlightPlayers.Value = text2 == "on";
				GameAccess.Notify("Highlight players in range: " + text2);
			}
			else
			{
				GameAccess.Notify("Usage: /chatrange players on | off");
			}
			break;
		case "status":
			GameAccess.Notify(instance.DescribeStatus());
			break;
		default:
			GameAccess.Notify($"/chatrange - show/hide the local chat area (hotkey: {instance.ToggleKey.Value})\n/chatrange on | off\n/chatrange mode always | local | typing\n/chatrange players on | off - highlight players in range\n/chatrange status");
			break;
		}
	}

	private static bool TryParseMode(string value, out VisibilityMode mode)
	{
		switch (value)
		{
		case "always":
			mode = VisibilityMode.Always;
			return true;
		case "local":
			mode = VisibilityMode.LocalTabOnly;
			return true;
		case "typing":
			mode = VisibilityMode.WhileTypingLocal;
			return true;
		default:
			mode = VisibilityMode.Always;
			return false;
		}
	}

	public static void RegisterWithCommandApi()
	{
		if (!Chainloader.PluginInfos.TryGetValue("com.on-together-mods.commandapi", out var value) || (Object)(object)value.Instance == (Object)null)
		{
			return;
		}
		try
		{
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			Type type = assembly.GetType("CommandAPI.CommandRegistry");
			Type type2 = assembly.GetType("CommandAPI.Parameter");
			Type type3 = assembly.GetType("CommandAPI.ParameterType");
			MethodInfo methodInfo = type?.GetMethod("Register", new Type[5]
			{
				typeof(string),
				typeof(string),
				typeof(Action<string[]>),
				typeof(string),
				type2.MakeArrayType()
			});
			if (!(methodInfo == null))
			{
				object obj = Enum.Parse(type3, "String");
				Array array = Array.CreateInstance(type2, 2);
				array.SetValue(Activator.CreateInstance(type2, "action", obj, true, null, null), 0);
				array.SetValue(Activator.CreateInstance(type2, "value", obj, true, null, null), 1);
				Action<string[]> action = Execute;
				string[] names = Names;
				foreach (string text in names)
				{
					methodInfo.Invoke(null, new object[5] { text, "LocalChatRange", action, "Show/hide the local chat range area: on, off, mode, players, status", array });
				}
				Plugin.Log.LogInfo((object)"Registered /chatrange with CommandAPI.");
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not register with CommandAPI (the command still works): " + ex.Message));
		}
	}
}
[HarmonyPatch(typeof(TextChannelManager), "OnEnterPressed")]
internal static class ChatCommandPatch
{
	[HarmonyPrefix]
	[HarmonyPriority(800)]
	private static void Prefix()
	{
		try
		{
			UIManager i = MonoSingleton<UIManager>.I;
			TMP_InputField val = (((Object)(object)i != (Object)null) ? i.MessageInput : null);
			if ((Object)(object)val != (Object)null && ChatCommands.TryExecute(val.text))
			{
				val.text = string.Empty;
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Chat command failed: " + ex));
		}
	}
}
internal sealed class ConfigMenu : MonoBehaviour
{
	private ConfigFile _config;

	private string _title;

	private string _symbol;

	private ConfigEntryBase[] _entries;

	private string[] _tabs;

	private int _tab;

	private int _pendingTab = -1;

	private Rect _rect;

	private bool _placed;

	private UiSkin _skin;

	private GUISkin _guiSkin;

	private WindowInputShield _shield;

	private ModDock _dock;

	private Vector2[] _scroll;

	private readonly Dictionary<ConfigEntryBase, string> _drafts = new Dictionary<ConfigEntryBase, string>();

	private readonly HashSet<string> _expanded = new HashSet<string>();

	private readonly Dictionary<string, bool> _pendingExpand = new Dictionary<string, bool>();

	private string _error;

	private int _hotControl;

	internal Action ExtraControls { get; set; }

	internal bool IsOpen => ((Behaviour)this).enabled;

	internal static ConfigMenu Create(GameObject parent, string title, string symbol, ConfigFile config, Func<bool> visible = null)
	{
		ConfigMenu menu = parent.AddComponent<ConfigMenu>();
		((Behaviour)menu).enabled = false;
		menu._title = title;
		menu._symbol = symbol;
		menu._config = config;
		menu._entries = ((IEnumerable<KeyValuePair<ConfigDefinition, ConfigEntryBase>>)config).Select((KeyValuePair<ConfigDefinition, ConfigEntryBase> p) => p.Value).ToArray();
		menu._tabs = menu._entries.Select((ConfigEntryBase e) => Root(e.Definition.Section)).Distinct().ToArray();
		menu._scroll = (Vector2[])(object)new Vector2[menu._tabs.Length];
		menu._shield = new WindowInputShield(title);
		menu._dock = ModDock.Register(title, symbol, menu.Toggle, () => ((Behaviour)menu).enabled, () => title + " · " + UiEnvironment.L("Settings", "Настройки"), visible);
		return menu;
	}

	internal void Toggle()
	{
		SetOpen(!((Behaviour)this).enabled);
	}

	internal void SetOpen(bool open)
	{
		((Behaviour)this).enabled = open;
		_shield?.Set(open);
		if (!open && _hotControl != 0 && GUIUtility.hotControl == _hotControl)
		{
			GUIUtility.hotControl = 0;
		}
		if (!open)
		{
			_hotControl = 0;
			GUI.FocusControl((string)null);
		}
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)27))
		{
			SetOpen(open: false);
		}
	}

	private void OnDisable()
	{
		_shield?.Set(open: false);
	}

	private void OnGUI()
	{
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Expected O, but got Unknown
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		if (UiEnvironment.PreviewRendering)
		{
			return;
		}
		if (_skin == null)
		{
			_skin = new UiSkin();
			_guiSkin = _skin.CreateGuiSkin(GUI.skin);
		}
		float scale = UiEnvironment.Scale;
		float num = Mathf.Min(600f, (float)Screen.width / scale - 24f);
		float num2 = (float)Screen.height / scale;
		if (!_placed)
		{
			_rect = new Rect(((float)Screen.width / scale - num) * 0.5f, num2 * 0.06f, num, 0f);
			_placed = true;
		}
		((Rect)(ref _rect)).width = num;
		Matrix4x4 matrix = GUI.matrix;
		GUISkin skin = GUI.skin;
		try
		{
			GUI.matrix = Matrix4x4.Scale(new Vector3(scale, scale, 1f));
			GUI.skin = _guiSkin;
			GUI.skin.settings.selectionColor = new Color(0.95f, 0.72f, 0.58f, 0.7f);
			_rect = GUILayout.Window((_title.GetHashCode() & 0x3FFFFFFF) + 3000, _rect, new WindowFunction(DrawWindow), GUIContent.none, _skin.Window, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) });
			((Rect)(ref _rect)).x = Mathf.Clamp(((Rect)(ref _rect)).x, 12f, Mathf.Max(12f, (float)Screen.width / scale - num - 12f));
			((Rect)(ref _rect)).y = Mathf.Clamp(((Rect)(ref _rect)).y, 8f, Mathf.Max(8f, num2 - ((Rect)(ref _rect)).height - 8f));
			_shield.Place(_rect, scale);
		}
		finally
		{
			GUI.skin = skin;
			GUI.matrix = matrix;
		}
	}

	private void DrawWindow(int id)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		if ((int)Event.current.type == 8)
		{
			if (_pendingTab >= 0)
			{
				_tab = _pendingTab;
				_pendingTab = -1;
				GUI.FocusControl((string)null);
			}
			foreach (KeyValuePair<string, bool> item in _pendingExpand)
			{
				if (item.Value)
				{
					_expanded.Add(item.Key);
				}
				else
				{
					_expanded.Remove(item.Key);
				}
			}
			_pendingExpand.Clear();
		}
		int hotControl = GUIUtility.hotControl;
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label((_symbol == "camera") ? "CU" : ((_symbol == "range") ? "LR" : "PV"), _skin.Logo, Array.Empty<GUILayoutOption>());
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Label(_title, _skin.Title, Array.Empty<GUILayoutOption>());
		GUILayout.Label(UiEnvironment.L("Settings", "Настройки"), _skin.Subtitle, Array.Empty<GUILayoutOption>());
		GUILayout.EndVertical();
		GUILayout.FlexibleSpace();
		if (GUILayout.Button("×", _skin.CloseButton, Array.Empty<GUILayoutOption>()))
		{
			SetOpen(open: false);
		}
		GUILayout.EndHorizontal();
		GUILayout.Space(8f);
		int num = ((((Rect)(ref _rect)).width < 480f) ? 2 : 4);
		for (int i = 0; i < _tabs.Length; i += num)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			for (int j = i; j < Mathf.Min(i + num, _tabs.Length); j++)
			{
				if (GUILayout.Button(UiLabels.Name(_tabs[j]), (j == _tab) ? _skin.SelectedTab : _skin.Tab, Array.Empty<GUILayoutOption>()))
				{
					_pendingTab = j;
				}
			}
			GUILayout.EndHorizontal();
		}
		GUILayout.Space(8f);
		float num2 = Mathf.Min(520f, Mathf.Max(80f, (float)Screen.height / UiEnvironment.Scale - 220f - (float)(34 * ((_tabs.Length + num - 1) / num))));
		_scroll[_tab] = GUILayout.BeginScrollView(_scroll[_tab], (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(num2) });
		foreach (IGrouping<string, ConfigEntryBase> item2 in from e in _entries
			where Root(e.Definition.Section) == _tabs[_tab]
			group e by e.Definition.Section)
		{
			bool num3 = item2.Key.Contains(".") || item2.Key == "Quality";
			GUILayout.BeginVertical(_skin.Panel, Array.Empty<GUILayoutOption>());
			bool flag = !num3 || _expanded.Contains(item2.Key);
			if (num3)
			{
				if (GUILayout.Button((flag ? "▼ " : "► ") + UiLabels.Name(item2.Key), _skin.SectionTitle, Array.Empty<GUILayoutOption>()))
				{
					_pendingExpand[item2.Key] = !flag;
				}
			}
			else
			{
				GUILayout.Label(UiLabels.Name(item2.Key), _skin.SectionTitle, Array.Empty<GUILayoutOption>());
			}
			if (flag)
			{
				foreach (ConfigEntryBase item3 in item2)
				{
					DrawEntry(item3);
				}
			}
			GUILayout.EndVertical();
		}
		ExtraControls?.Invoke();
		GUILayout.EndScrollView();
		GUILayout.Space(8f);
		GUILayout.Label(_error ?? UiEnvironment.L("Changes save automatically. Fields: Apply to save.", "Изменения сохраняются сразу. Для полей нажмите «Применить»."), _skin.Hint, Array.Empty<GUILayoutOption>());
		GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref _rect)).width - 48f, 62f));
		if (hotControl != GUIUtility.hotControl)
		{
			_hotControl = GUIUtility.hotControl;
		}
	}

	private void DrawEntry(ConfigEntryBase entry)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_0490: Unknown result type (might be due to invalid IL or missing references)
		//IL_0495: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c2: Invalid comparison between Unknown and I4
		//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_04da: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0506: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		string text = UiLabels.Name(entry.Definition.Key);
		GUILayout.BeginHorizontal(_skin.Row, Array.Empty<GUILayoutOption>());
		GUIContent val = new GUIContent(text, entry.Description.Description);
		if (entry.SettingType == typeof(bool))
		{
			bool flag = GUILayout.Toggle((bool)entry.BoxedValue, GUIContent.none, _skin.Check, Array.Empty<GUILayoutOption>());
			if (GUILayout.Button(val, _skin.ToggleLabel, Array.Empty<GUILayoutOption>()))
			{
				flag = !(bool)entry.BoxedValue;
			}
			if (flag != (bool)entry.BoxedValue)
			{
				entry.BoxedValue = flag;
			}
		}
		else
		{
			GUILayout.Label(val, _skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(Mathf.Clamp((((Rect)(ref _rect)).width - 64f) * 0.4f, 105f, 190f)) });
			bool num = entry.SettingType == typeof(float) || entry.SettingType == typeof(int);
			AcceptableValueBase acceptableValues = entry.Description.AcceptableValues;
			PropertyInfo propertyInfo = ((object)acceptableValues)?.GetType().GetProperty("MinValue");
			PropertyInfo propertyInfo2 = ((object)acceptableValues)?.GetType().GetProperty("MaxValue");
			if (num && propertyInfo != null && propertyInfo2 != null)
			{
				float num2 = Convert.ToSingle(entry.BoxedValue, CultureInfo.InvariantCulture);
				float num3 = GUILayout.HorizontalSlider(num2, Convert.ToSingle(propertyInfo.GetValue(acceptableValues), CultureInfo.InvariantCulture), Convert.ToSingle(propertyInfo2.GetValue(acceptableValues), CultureInfo.InvariantCulture), _skin.Slider, _skin.Thumb, Array.Empty<GUILayoutOption>());
				GUILayout.Label(num2.ToString((entry.SettingType == typeof(int)) ? "0" : "0.##", CultureInfo.InvariantCulture), _skin.Value, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(54f) });
				if (num3 != num2)
				{
					entry.BoxedValue = ((entry.SettingType == typeof(int)) ? ((object)Mathf.RoundToInt(num3)) : ((object)(float)Math.Round(num3, 3)));
				}
			}
			else if (entry.SettingType.IsEnum && entry.SettingType != typeof(KeyCode))
			{
				Array values = Enum.GetValues(entry.SettingType);
				int num4 = Array.IndexOf(values.Cast<object>().ToArray(), entry.BoxedValue);
				if (GUILayout.Button("◄", _skin.SmallButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(26f) }))
				{
					entry.BoxedValue = values.GetValue((num4 + values.Length - 1) % values.Length);
				}
				GUILayout.Label(UiLabels.Name(entry.BoxedValue.ToString()), _skin.Field, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
				if (GUILayout.Button("►", _skin.SmallButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(26f) }))
				{
					entry.BoxedValue = values.GetValue((num4 + 1) % values.Length);
				}
			}
			else
			{
				if (!_drafts.TryGetValue(entry, out var value))
				{
					value = ((entry.SettingType == typeof(Color)) ? ("#" + ColorUtility.ToHtmlStringRGBA((Color)entry.BoxedValue)) : entry.GetSerializedValue());
				}
				string text2 = GUILayout.TextField(value, _skin.EditorHex, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.MinWidth(40f),
					GUILayout.ExpandWidth(true)
				});
				if (text2 != value)
				{
					_drafts[entry] = text2;
				}
				if (GUILayout.Button(UiEnvironment.L("Apply", "Применить"), _skin.SmallButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width((float)(UiEnvironment.Russian ? 86 : 54)) }))
				{
					Apply(entry, text2);
				}
			}
		}
		GUILayout.EndHorizontal();
		if (entry.SettingType == typeof(Color))
		{
			Color val2 = (Color)entry.BoxedValue;
			Rect rect = GUILayoutUtility.GetRect(0f, 24f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if ((int)Event.current.type == 7)
			{
				_skin.PreviewPaper.Draw(rect, false, false, false, false);
				GUI.DrawTexture(rect, (Texture)(object)_skin.White, (ScaleMode)0, true, 0f, val2, 0f, 6f);
				GUI.Label(rect, "#" + ColorUtility.ToHtmlStringRGBA(val2), _skin.Value);
			}
		}
	}

	private void Apply(ConfigEntryBase entry, string text)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (entry.SettingType == typeof(Color))
			{
				Color val = default(Color);
				if (!ColorUtility.TryParseHtmlString("#" + text.Trim().TrimStart('#'), ref val))
				{
					throw new FormatException();
				}
				entry.BoxedValue = val;
			}
			else if (entry.SettingType == typeof(KeyCode))
			{
				entry.BoxedValue = Enum.Parse(typeof(KeyCode), text.Trim(), ignoreCase: true);
			}
			else if (entry.SettingType == typeof(KeyboardShortcut))
			{
				string[] array = text.Split('+');
				for (int i = 0; i < array.Length; i++)
				{
					if (!Enum.TryParse<KeyCode>(array[i].Trim(), ignoreCase: true, out KeyCode result) || !Enum.IsDefined(typeof(KeyCode), result))
					{
						throw new FormatException();
					}
				}
				entry.BoxedValue = KeyboardShortcut.Deserialize(text.Trim());
			}
			else if (entry.SettingType == typeof(float))
			{
				if (!float.TryParse(text.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || float.IsNaN(result2) || float.IsInfinity(result2))
				{
					throw new FormatException();
				}
				entry.BoxedValue = result2;
			}
			else if (entry.SettingType == typeof(int))
			{
				entry.BoxedValue = int.Parse(text, NumberStyles.Integer, CultureInfo.InvariantCulture);
			}
			else
			{
				if (!(entry.SettingType == typeof(string)))
				{
					throw new FormatException();
				}
				entry.BoxedValue = text;
			}
			_drafts.Remove(entry);
			_error = null;
		}
		catch (Exception)
		{
			_error = UiEnvironment.L("Invalid value. The saved setting is unchanged.", "Некорректное значение. Сохранённая настройка не изменена.");
		}
	}

	private static string Root(string section)
	{
		return section.Split('.')[0];
	}

	private void OnDestroy()
	{
		_shield?.Dispose();
		if ((Object)(object)_dock != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_dock).gameObject);
		}
		_skin?.Destroy();
		if ((Object)(object)_guiSkin != (Object)null)
		{
			Object.Destroy((Object)(object)_guiSkin);
		}
	}
}
internal static class DockLayout
{
	internal readonly struct Box
	{
		internal readonly float X;

		internal readonly float Y;

		internal readonly float Width;

		internal readonly float Height;

		internal Box(float x, float y, float width, float height)
		{
			X = x;
			Y = y;
			Width = width;
			Height = height;
		}

		internal bool Overlaps(Box b)
		{
			if (X < b.X + b.Width && X + Width > b.X && Y < b.Y + b.Height)
			{
				return Y + Height > b.Y;
			}
			return false;
		}
	}

	internal static bool Find(float width, float height, float scale, int count, IReadOnlyList<Box> obstacles, out Box result)
	{
		return Find(width, height, 36f * scale, 36f * scale, 6f * scale, 12f * scale, count, obstacles, out result);
	}

	internal static bool FindRight(float width, float height, float x, float buttonWidth, float buttonHeight, float gap, float preferredTop, float margin, int count, IReadOnlyList<Box> obstacles, out Box result)
	{
		result = default(Box);
		float num = buttonHeight + gap;
		float num2 = (float)count * num - gap;
		if (count <= 0 || buttonWidth <= 0f || buttonHeight <= 0f || gap < 0f || x < 0f || x >= width || x + buttonWidth < width || num2 + 2f * margin > height)
		{
			return false;
		}
		int num3 = (int)Math.Ceiling((margin - preferredTop) / num);
		int num4 = (int)Math.Floor((height - margin - num2 - preferredTop) / num);
		List<int> list = new List<int>();
		for (int i = Math.Max(0, num3); i <= num4; i++)
		{
			list.Add(i);
		}
		for (int num5 = Math.Min(-1, num4); num5 >= num3; num5--)
		{
			list.Add(num5);
		}
		foreach (int item in list)
		{
			float y = preferredTop + (float)item * num;
			Box b = new Box(x, y, width - x, num2);
			bool flag = false;
			foreach (Box obstacle in obstacles)
			{
				if (obstacle.Overlaps(b))
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				result = new Box(x, y, buttonWidth, num2);
				return true;
			}
		}
		return false;
	}

	internal static bool Find(float width, float height, float buttonWidth, float buttonHeight, float gap, float margin, int count, IReadOnlyList<Box> obstacles, out Box result)
	{
		float num = (float)count * (buttonHeight + gap) - gap;
		result = default(Box);
		if (count <= 0 || width < buttonWidth + 2f * margin || height < num + 24f || buttonWidth <= 0f || buttonHeight <= 0f)
		{
			return false;
		}
		bool[] array = new bool[2] { true, false };
		for (int i = 0; i < array.Length; i++)
		{
			float x = (array[i] ? (width - margin - buttonWidth) : margin);
			float num2 = Math.Max(12f, Math.Min((height - num) * 0.5f, height - num - 12f));
			for (int j = 0; (float)j < height / (buttonHeight + gap) + 2f; j++)
			{
				int[] array2 = new int[2] { 1, -1 };
				foreach (int num3 in array2)
				{
					float num4 = num2 + (float)j * (buttonHeight + gap) * (float)num3;
					if (num4 < 12f || num4 + num > height - 12f)
					{
						continue;
					}
					Box box = new Box(x, num4, buttonWidth, num);
					bool flag = false;
					foreach (Box obstacle in obstacles)
					{
						if (obstacle.Overlaps(box))
						{
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						result = box;
						return true;
					}
				}
			}
		}
		return false;
	}
}
internal static class SidebarVisibility
{
	internal static bool Show(bool desktop, bool nativeActive, bool canvasEnabled, float alpha)
	{
		if (!desktop && nativeActive && canvasEnabled)
		{
			return alpha > 0.01f;
		}
		return false;
	}
}
internal static class GameAccess
{
	private const float LookupInterval = 1f;

	private static TextChannelManager _chat;

	private static UIManager _ui;

	private static PlayerPanelController _playerPanel;

	private static float _nextChatLookup;

	private static float _nextUiLookup;

	private static float _nextPlayerPanelLookup;

	private static readonly FieldRef<TextChannelManager, TMP_Text> TextPrefabRef = TryFieldRef<TMP_Text>("_textPrefab");

	private static readonly FieldRef<TextChannelManager, List<GameObject>> LocalMessagesRef = TryFieldRef<List<GameObject>>("_messageObjectsLocal");

	public static TextChannelManager Chat
	{
		get
		{
			if ((Object)(object)_chat == (Object)null && Time.unscaledTime >= _nextChatLookup)
			{
				_nextChatLookup = Time.unscaledTime + 1f;
				_chat = NetworkSingleton<TextChannelManager>.I;
			}
			return _chat;
		}
	}

	public static UIManager UI
	{
		get
		{
			if ((Object)(object)_ui == (Object)null && Time.unscaledTime >= _nextUiLookup)
			{
				_nextUiLookup = Time.unscaledTime + 1f;
				_ui = MonoSingleton<UIManager>.I;
			}
			return _ui;
		}
	}

	public static PlayerPanelController PlayerPanel
	{
		get
		{
			if ((Object)(object)_playerPanel == (Object)null && Time.unscaledTime >= _nextPlayerPanelLookup)
			{
				_nextPlayerPanelLookup = Time.unscaledTime + 1f;
				_playerPanel = NetworkSingleton<PlayerPanelController>.I;
			}
			return _playerPanel;
		}
	}

	public static bool IsChatInputFocused()
	{
		UIManager uI = UI;
		if ((Object)(object)uI == (Object)null)
		{
			return false;
		}
		TMP_InputField messageInput = uI.MessageInput;
		if ((Object)(object)messageInput != (Object)null && messageInput.isFocused)
		{
			return true;
		}
		TMP_InputField messageInputField = uI.MessageInputField;
		if ((Object)(object)messageInputField != (Object)null)
		{
			return messageInputField.isFocused;
		}
		return false;
	}

	public static bool IsAnyTextFieldFocused()
	{
		EventSystem current = EventSystem.current;
		if ((Object)(object)current == (Object)null)
		{
			return false;
		}
		GameObject currentSelectedGameObject = current.currentSelectedGameObject;
		if ((Object)(object)currentSelectedGameObject == (Object)null)
		{
			return false;
		}
		TMP_InputField component = currentSelectedGameObject.GetComponent<TMP_InputField>();
		if ((Object)(object)component != (Object)null && component.isFocused)
		{
			return true;
		}
		InputField component2 = currentSelectedGameObject.GetComponent<InputField>();
		if ((Object)(object)component2 != (Object)null)
		{
			return component2.isFocused;
		}
		return false;
	}

	public static float? DetectRadiusFromGameCode()
	{
		MethodInfo methodInfo = AccessTools.Method(typeof(TextChannelManager), "OnChannelMessageReceived", (Type[])null, (Type[])null);
		if (methodInfo == null)
		{
			return null;
		}
		byte[] array = methodInfo.GetMethodBody()?.GetILAsByteArray();
		if (array == null)
		{
			return null;
		}
		for (int i = 0; i + 10 <= array.Length; i++)
		{
			if (array[i] != 40 || array[i + 5] != 34)
			{
				continue;
			}
			MethodBase methodBase;
			try
			{
				methodBase = methodInfo.Module.ResolveMethod(BitConverter.ToInt32(array, i + 1));
			}
			catch (Exception)
			{
				continue;
			}
			if (!(methodBase == null) && !(methodBase.Name != "SqrMagnitude") && !(methodBase.DeclaringType != typeof(Vector3)))
			{
				float num = BitConverter.ToSingle(array, i + 6);
				if (num > 0f && num < 1000000f)
				{
					return Mathf.Sqrt(num);
				}
			}
		}
		return null;
	}

	public static void Notify(string message)
	{
		TextChannelManager chat = Chat;
		if ((Object)(object)chat == (Object)null)
		{
			return;
		}
		string text = "<color=#7FD8FF>[LocalChatRange]</color> " + message;
		try
		{
			if (!chat.Islocal || !TryAddLocalLine(chat, text))
			{
				chat.AddNotification(text);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not show chat notification: " + ex.Message));
		}
	}

	private static bool TryAddLocalLine(TextChannelManager chat, string text)
	{
		if (TextPrefabRef == null)
		{
			return false;
		}
		UIManager uI = UI;
		Transform val = (((Object)(object)uI != (Object)null) ? uI.TextContentLocalTransform : null);
		TMP_Text val2 = TextPrefabRef.Invoke(chat);
		if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
		{
			return false;
		}
		TMP_Text val3 = Object.Instantiate<TMP_Text>(val2, val);
		Button component = ((Component)val3).GetComponent<Button>();
		if ((Object)(object)component != (Object)null)
		{
			((Selectable)component).interactable = false;
		}
		val3.text = text;
		List<GameObject> list = ((LocalMessagesRef != null) ? LocalMessagesRef.Invoke(chat) : null);
		if (list != null)
		{
			list.Add(((Component)val3).gameObject);
			int localMessageLimitCount = ScriptableSingleton<GameSettings>.I.LocalMessageLimitCount;
			while (list.Count > localMessageLimitCount && list.Count > 0)
			{
				GameObject val4 = list[0];
				list.RemoveAt(0);
				if ((Object)(object)val4 != (Object)null)
				{
					Object.Destroy((Object)(object)val4);
				}
			}
		}
		return true;
	}

	private static FieldRef<TextChannelManager, T> TryFieldRef<T>(string fieldName)
	{
		try
		{
			return AccessTools.FieldRefAccess<TextChannelManager, T>(fieldName);
		}
		catch (Exception)
		{
			return null;
		}
	}
}
internal static class Materials
{
	private const string InternalColored = "Hidden/Internal-Colored";

	private const string SpritesDefault = "Sprites/Default";

	private const string UrpUnlit = "Universal Render Pipeline/Unlit";

	public const int Queue = 3050;

	private static string _shaderInUse;

	public static string ShaderInUse => _shaderInUse ?? "none";

	public static Material Create(string name)
	{
		//IL_005a: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		Shader val = null;
		string[] array = new string[3] { "Hidden/Internal-Colored", "Sprites/Default", "Universal Render Pipeline/Unlit" };
		foreach (string text in array)
		{
			val = Shader.Find(text);
			if ((Object)(object)val != (Object)null)
			{
				_shaderInUse = text;
				break;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		Material val2 = new Material(val)
		{
			name = name,
			hideFlags = (HideFlags)61,
			renderQueue = 3050
		};
		if (_shaderInUse == "Hidden/Internal-Colored")
		{
			val2.SetInt("_SrcBlend", 5);
			val2.SetInt("_DstBlend", 10);
			val2.SetInt("_ZWrite", 0);
			val2.SetInt("_Cull", 0);
			val2.SetInt("_ZTest", 4);
			val2.SetFloat("_ZBias", -1f);
		}
		else if (_shaderInUse == "Universal Render Pipeline/Unlit")
		{
			val2.SetFloat("_Surface", 1f);
			val2.SetFloat("_Blend", 0f);
			val2.SetFloat("_SrcBlend", 5f);
			val2.SetFloat("_DstBlend", 10f);
			val2.SetFloat("_ZWrite", 0f);
			val2.SetFloat("_Cull", 0f);
			val2.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
		}
		return val2;
	}

	public static void SetColor(Material material, Color color)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)material != (Object)null)
		{
			material.color = color;
		}
	}

	public static void SetAlwaysOnTop(Material material, bool onTop)
	{
		if ((Object)(object)material != (Object)null && material.HasProperty("_ZTest"))
		{
			material.SetInt("_ZTest", onTop ? 8 : 4);
		}
	}

	public static void ConfigureRenderer(Renderer renderer)
	{
		renderer.shadowCastingMode = (ShadowCastingMode)0;
		renderer.receiveShadows = false;
		renderer.lightProbeUsage = (LightProbeUsage)0;
		renderer.reflectionProbeUsage = (ReflectionProbeUsage)0;
		renderer.motionVectorGenerationMode = (MotionVectorGenerationMode)2;
		renderer.allowOcclusionWhenDynamic = false;
	}
}
internal sealed class ModDock : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
{
	private Func<string> _hint;

	private Func<bool> _isOpen;

	private Func<bool> _visible;

	private Image _image;

	private Image _iconImage;

	private Image _outlineImage;

	private Button _control;

	private Button _native;

	private Image _nativeBackground;

	private Image _nativeIcon;

	private Image _nativeOutline;

	private Text _tooltip;

	private RectTransform _tooltipRect;

	private Sprite _background;

	private Sprite _icon;

	private Texture2D _backgroundTexture;

	private Texture2D _iconTexture;

	private CanvasGroup _group;

	private float _nextLayout;

	private bool _hover;

	private readonly List<DockLayout.Box> _obstacles = new List<DockLayout.Box>();

	private readonly Vector3[] _corners = (Vector3[])(object)new Vector3[4];

	internal static ModDock Register(string name, string symbol, Action toggle, Func<bool> open, Func<string> hint, Func<bool> visible = null)
	{
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: 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_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Expected O, but got Unknown
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Expected O, but got Unknown
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Expected O, but got Unknown
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Unknown result type (might be due to invalid IL or missing references)
		//IL_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0425: Unknown result type (might be due to invalid IL or missing references)
		//IL_042c: Expected O, but got Unknown
		//IL_0473: Unknown result type (might be due to invalid IL or missing references)
		//IL_047d: Expected O, but got Unknown
		//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a9: Expected O, but got Unknown
		//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04df: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0546: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("LightShaper.ModDock.v1");
		if ((Object)(object)val == (Object)null)
		{
			val = new GameObject("LightShaper.ModDock.v1", new Type[3]
			{
				typeof(RectTransform),
				typeof(Canvas),
				typeof(GraphicRaycaster)
			});
			Object.DontDestroyOnLoad((Object)(object)val);
			Canvas component = val.GetComponent<Canvas>();
			component.renderMode = (RenderMode)0;
			component.sortingOrder = 32765;
		}
		GameObject val2 = new GameObject(name, new Type[4]
		{
			typeof(RectTransform),
			typeof(Image),
			typeof(Button),
			typeof(CanvasGroup)
		});
		val2.transform.SetParent(val.transform, false);
		ModDock modDock = val2.AddComponent<ModDock>();
		modDock._hint = hint;
		modDock._isOpen = open;
		modDock._visible = visible ?? ((Func<bool>)(() => true));
		modDock._group = val2.GetComponent<CanvasGroup>();
		modDock._group.alpha = 0f;
		((RectTransform)val2.transform).anchoredPosition = new Vector2(-10000f, -10000f);
		modDock._image = val2.GetComponent<Image>();
		modDock._backgroundTexture = RoundedTexture();
		modDock._background = Sprite.Create(modDock._backgroundTexture, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(16f, 16f, 16f, 16f));
		modDock._image.sprite = modDock._background;
		modDock._image.type = (Type)1;
		Button val3 = (modDock._control = val2.GetComponent<Button>());
		((Selectable)val3).targetGraphic = (Graphic)(object)modDock._image;
		Navigation navigation = default(Navigation);
		((Navigation)(ref navigation)).mode = (Mode)0;
		((Selectable)val3).navigation = navigation;
		ColorBlock colors = ((Selectable)val3).colors;
		((ColorBlock)(ref colors)).normalColor = Color.white;
		((ColorBlock)(ref colors)).highlightedColor = new Color(1f, 0.88f, 0.8f);
		((ColorBlock)(ref colors)).pressedColor = new Color(0.95f, 0.8f, 0.68f);
		((Selectable)val3).colors = colors;
		((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
		{
			toggle();
			EventSystem current = EventSystem.current;
			if (current != null)
			{
				current.SetSelectedGameObject((GameObject)null);
			}
		});
		GameObject val4 = new GameObject("Outline", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val4.transform.SetParent(val2.transform, false);
		modDock._outlineImage = val4.GetComponent<Image>();
		((Graphic)modDock._outlineImage).raycastTarget = false;
		((Behaviour)modDock._outlineImage).enabled = false;
		GameObject val5 = new GameObject("Icon", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val5.transform.SetParent(val2.transform, false);
		RectTransform val6 = (RectTransform)val5.transform;
		val6.anchorMin = new Vector2(0.19f, 0.19f);
		val6.anchorMax = new Vector2(0.81f, 0.81f);
		Vector2 offsetMin = (val6.offsetMax = Vector2.zero);
		val6.offsetMin = offsetMin;
		modDock._iconTexture = IconTexture(symbol);
		modDock._icon = Sprite.Create(modDock._iconTexture, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f));
		val5.GetComponent<Image>().sprite = modDock._icon;
		((Graphic)val5.GetComponent<Image>()).color = new Color(0.67f, 0.31f, 0.24f);
		((Graphic)val5.GetComponent<Image>()).raycastTarget = false;
		val5.GetComponent<Image>().preserveAspect = true;
		modDock._iconImage = val5.GetComponent<Image>();
		GameObject val7 = new GameObject("Tooltip", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val7.transform.SetParent(val2.transform, false);
		val7.GetComponent<Image>().sprite = modDock._background;
		val7.GetComponent<Image>().type = (Type)1;
		((Graphic)val7.GetComponent<Image>()).raycastTarget = false;
		modDock._tooltipRect = (RectTransform)val7.transform;
		GameObject val8 = new GameObject("Text", new Type[2]
		{
			typeof(RectTransform),
			typeof(Text)
		});
		val8.transform.SetParent(val7.transform, false);
		RectTransform val9 = (RectTransform)val8.transform;
		val9.anchorMin = Vector2.zero;
		val9.anchorMax = Vector2.one;
		val9.offsetMin = new Vector2(10f, 4f);
		val9.offsetMax = new Vector2(-10f, -4f);
		modDock._tooltip = val8.GetComponent<Text>();
		modDock._tooltip.font = UiEnvironment.GameFont ?? Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
		modDock._tooltip.fontSize = 13;
		((Graphic)modDock._tooltip).color = UiSkin.TextColor;
		modDock._tooltip.alignment = (TextAnchor)4;
		((Graphic)modDock._tooltip).raycastTarget = false;
		modDock._tooltip.supportRichText = false;
		val7.SetActive(false);
		Transform[] array = ((IEnumerable)val.transform).Cast<Transform>().OrderBy<Transform, string>((Transform t) => ((Object)t).name, StringComparer.Ordinal).ToArray();
		for (int num = 0; num < array.Length; num++)
		{
			array[num].SetAsLastSibling();
		}
		return modDock;
	}

	private void Update()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Expected O, but got Unknown
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: 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_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		ApplyNativeStyle();
		float opacity = NativeSidebar.Opacity;
		bool flag = _visible() && opacity > 0.01f && ((RectTransform)((Component)this).transform).anchoredPosition.x > -9000f;
		_group.alpha = (flag ? opacity : 0f);
		_group.blocksRaycasts = flag;
		_group.interactable = flag;
		if (!flag)
		{
			_hover = false;
		}
		((Graphic)_image).color = (((Object)(object)_native != (Object)null) ? NativeSidebar.SurfaceColor(_hover || _isOpen()) : Color.white);
		((Graphic)_iconImage).color = (Color)(((Object)(object)_nativeOutline != (Object)null) ? ((Graphic)_nativeOutline).color : new Color(0.43f, 0.34f, 0.35f, 1f));
		if (((Component)this).transform.GetSiblingIndex() == 0 && Time.unscaledTime >= _nextLayout)
		{
			_nextLayout = Time.unscaledTime + 0.15f;
			LayoutGroup();
		}
		bool flag2 = _hover && _group.alpha > 0f && _group.blocksRaycasts;
		((Component)_tooltipRect).gameObject.SetActive(flag2);
		if (flag2)
		{
			float scale = UiEnvironment.Scale;
			_tooltip.text = _hint();
			_tooltip.fontSize = Mathf.RoundToInt(13f * scale);
			float num = Mathf.Min((float)Screen.width - 24f, Mathf.Max(140f * scale, _tooltip.preferredWidth + 24f));
			RectTransform val = (RectTransform)((Component)this).transform;
			_tooltipRect.pivot = new Vector2(1f, 0.5f);
			RectTransform tooltipRect = _tooltipRect;
			RectTransform tooltipRect2 = _tooltipRect;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 0.5f);
			tooltipRect2.anchorMax = val2;
			tooltipRect.anchorMin = val2;
			_tooltipRect.sizeDelta = new Vector2(num, 32f * scale);
			float num2 = Mathf.Min((float)Screen.width - 12f, val.anchoredPosition.x - 8f);
			num2 = Mathf.Max(num + 12f, num2);
			_tooltipRect.anchoredPosition = new Vector2(num2 - val.anchoredPosition.x, 0f);
		}
	}

	private void ApplyNativeStyle()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Invalid comparison between Unknown and I4
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		Button button = NativeSidebar.Button;
		if ((Object)(object)button == (Object)null)
		{
			return;
		}
		Image val = NativeSidebar.Background(button);
		if (!((Object)(object)val == (Object)null))
		{
			_native = button;
			_nativeBackground = val;
			_nativeIcon = NativeSidebar.Icon(button);
			_nativeOutline = NativeSidebar.Outline(button);
			((Selectable)_control).transition = (Transition)(((int)((Selectable)button).transition == 1) ? ((int)((Selectable)button).transition) : 0);
			((Selectable)_control).colors = ((Selectable)button).colors;
			NativeSidebar.CopyImage(_nativeBackground, _image);
			float num = NativeSidebar.PixelScale(val);
			if ((Object)(object)_nativeOutline != (Object)null)
			{
				((Behaviour)_outlineImage).enabled = true;
				NativeSidebar.CopyImage(_nativeOutline, _outlineImage);
				NativeSidebar.CopyRect(((Graphic)_nativeOutline).rectTransform, ((Graphic)_outlineImage).rectTransform, num);
			}
			else
			{
				((Behaviour)_outlineImage).enabled = false;
			}
			if ((Object)(object)_nativeIcon != (Object)null)
			{
				NativeSidebar.CopyRect(((Graphic)_nativeIcon).rectTransform, ((Graphic)_iconImage).rectTransform, num);
				Rect rect = ((Graphic)_nativeIcon).rectTransform.rect;
				float width = ((Rect)(ref rect)).width;
				rect = ((Graphic)_nativeIcon).rectTransform.rect;
				float num2 = Mathf.Min(width, ((Rect)(ref rect)).height) * num;
				((Graphic)_iconImage).rectTransform.sizeDelta = new Vector2(num2, num2);
			}
		}
	}

	private void LayoutGroup()
	{
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Invalid comparison between Unknown and I4
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: 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)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: 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_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: 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_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: 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_01b4: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		_obstacles.Clear();
		Graphic[] array = GraphicRegistryAll();
		foreach (Graphic val in array)
		{
			if (!((Behaviour)val).isActiveAndEnabled || (Object)(object)val.canvas == (Object)null || (int)val.canvas.renderMode == 2 || ((Component)val).transform.IsChildOf(((Component)this).transform.parent))
			{
				continue;
			}
			bool flag = false;
			Transform val2 = ((Component)val).transform;
			while ((Object)(object)val2 != (Object)null)
			{
				if (((Object)val2).name.IndexOf("chat", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					flag = true;
					break;
				}
				val2 = val2.parent;
			}
			if (!val.raycastTarget && !flag)
			{
				continue;
			}
			bool flag2 = ((Object)((Component)val).transform.root).name == "LightShaper.ModWindows.v1";
			if (flag2 || (!((flag ? 1f : val.color.a) * val.canvasRenderer.GetInheritedAlpha() < 0.03f) && !val.canvasRenderer.cull))
			{
				val.rectTransform.GetWorldCorners(_corners);
				Camera obj = (((int)val.canvas.renderMode == 0) ? null : val.canvas.worldCamera);
				Vector2 val3 = RectTransformUtility.WorldToScreenPoint(obj, _corners[0]);
				Vector2 val4 = RectTransformUtility.WorldToScreenPoint(obj, _corners[2]);
				Rect val5 = Rect.MinMaxRect(Mathf.Min(val3.x, val4.x), (float)Screen.height - Mathf.Max(val3.y, val4.y), Mathf.Max(val3.x, val4.x), (float)Screen.height - Mathf.Min(val3.y, val4.y));
				if (!(((Rect)(ref val5)).width > (float)Screen.width * 0.95f) || !(((Rect)(ref val5)).height > (float)Screen.height * 0.95f) || flag2)
				{
					((Rect)(ref val5)).xMin = ((Rect)(ref val5)).xMin - 6f;
					((Rect)(ref val5)).yMin = ((Rect)(ref val5)).yMin - 6f;
					((Rect)(ref val5)).xMax = ((Rect)(ref val5)).xMax + 6f;
					((Rect)(ref val5)).yMax = ((Rect)(ref val5)).yMax + 6f;
					_obstacles.Add(new DockLayout.Box(((Rect)(ref val5)).x, ((Rect)(ref val5)).y, ((Rect)(ref val5)).width, ((Rect)(ref val5)).height));
				}
			}
		}
		Transform[] array2 = (from Transform t in (IEnumerable)((Component)this).transform.parent
			where (Object)(object)((Component)t).GetComponent<Button>() != (Object)null
			select t).ToArray();
		float scale = UiEnvironment.Scale;
		Rect bounds;
		float gap;
		float preferredTop;
		bool num = NativeSidebar.TryGeometry(out bounds, out gap, out preferredTop);
		Vector2 size = ((Rect)(ref bounds)).size;
		DockLayout.Box result = default(DockLayout.Box);
		bool flag3 = num && DockLayout.FindRight(Screen.width, Screen.height, ((Rect)(ref bounds)).x, size.x, size.y, gap, preferredTop, 6f * scale, array2.Length, _obstacles, out result);
		Vector2 val7 = default(Vector2);
		for (int num2 = 0; num2 < array2.Length; num2++)
		{
			RectTransform val6 = (RectTransform)array2[num2];
			((Vector2)(ref val7))..ctor(0f, 1f);
			val6.pivot = val7;
			Vector2 anchorMin = (val6.anchorMax = val7);
			val6.anchorMin = anchorMin;
			val6.sizeDelta = size;
			val6.anchoredPosition = (flag3 ? new Vector2(result.X, 0f - result.Y - (float)num2 * (size.y + gap)) : new Vector2(-10000f, -10000f));
		}
	}

	private static Graphic[] GraphicRegistryAll()
	{
		return Object.FindObjectsByType<Graphic>((FindObjectsInactive)0, (FindObjectsSortMode)0);
	}

	public void OnPointerEnter(PointerEventData data)
	{
		_hover = true;
	}

	public void OnPointerExit(PointerEventData data)
	{
		_hover = false;
	}

	private void OnDestroy()
	{
		Object.Destroy((Object)(object)_background);
		Object.Destroy((Object)(object)_icon);
		Object.Destroy((Object)(object)_backgroundTexture);
		Object.Destroy((Object)(object)_iconTexture);
		if ((Object)(object)((Component)this).transform.parent != (Object)null && ((Component)this).transform.parent.childCount == 1)
		{
			Object.Destroy((Object)(object)((Component)((Component)this).transform.parent).gameObject);
		}
	}

	private static Texture2D RoundedTexture()
	{
		//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_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		Color[] array = (Color[])(object)new Color[4096];
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 64; j++)
			{
				float num = Mathf.Abs((float)j + 0.5f - 32f) - 18f;
				float num2 = Mathf.Abs((float)i + 0.5f - 32f) - 18f;
				Vector2 val = new Vector2(Mathf.Max(num, 0f), Mathf.Max(num2, 0f));
				float num3 = ((Vector2)(ref val)).magnitude + Mathf.Min(Mathf.Max(num, num2), 0f) - 14f;
				Color val2 = Color.Lerp(new Color(0.43f, 0.34f, 0.35f, 1f), new Color(1f, 0.95f, 0.86f, 1f), Mathf.Clamp01(0.5f - num3 - 4f));
				val2.a = Mathf.Clamp01(0.5f - num3);
				array[i * 64 + j] = val2;
			}
		}
		return Texture(array, 64);
	}

	private static Texture2D IconTexture(string symbol)
	{
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_0489: Unknown result type (might be due to invalid IL or missing references)
		//IL_048d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0494: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04be: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_053f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0544: Unknown result type (might be due to invalid IL or missing references)
		List<Vector4> lines = new List<Vector4>();
		switch (symbol)
		{
		case "camera":
			Box(4f, 9f, 24f, 17f);
			Box(10f, 5f, 10f, 4f);
			Circle(lines, 16f, 17f, 6f);
			break;
		case "sound":
			Box(4f, 13f, 6f, 8f);
			Line(10f, 13f, 17f, 7f);
			Line(17f, 7f, 17f, 26f);
			Line(17f, 26f, 10f, 21f);
			Line(22f, 11f, 26f, 15f);
			Line(26f, 15f, 26f, 19f);
			Line(26f, 19f, 22f, 23f);
			break;
		case "range":
			Circle(lines, 16f, 16f, 11f);
			Line(16f, 2f, 16f, 9f);
			Line(16f, 23f, 16f, 30f);
			Line(2f, 16f, 9f, 16f);
			Line(23f, 16f, 30f, 16f);
			break;
		case "voice":
			Box(12f, 4f, 8f, 17f);
			Line(7f, 16f, 7f, 23f);
			Line(7f, 23f, 25f, 23f);
			Line(25f, 23f, 25f, 16f);
			Line(16f, 23f, 16f, 29f);
			Line(10f, 29f, 22f, 29f);
			break;
		case "move":
			Line(16f, 29f, 16f, 3f);
			Line(16f, 3f, 10f, 9f);
			Line(16f, 3f, 22f, 9f);
			Line(16f, 29f, 10f, 23f);
			Line(16f, 29f, 22f, 23f);
			Line(3f, 16f, 29f, 16f);
			Line(3f, 16f, 9f, 10f);
			Line(3f, 16f, 9f, 22f);
			Line(29f, 16f, 23f, 10f);
			Line(29f, 16f, 23f, 22f);
			break;
		default:
			Box(4f, 5f, 24f, 18f);
			Line(9f, 23f, 9f, 28f);
			Line(9f, 28f, 15f, 23f);
			Line(10f, 11f, 22f, 11f);
			Line(10f, 17f, 18f, 17f);
			break;
		}
		Color[] array = (Color[])(object)new Color[1024];
		Vector2 val = default(Vector2);
		Vector2 val2 = default(Vector2);
		for (int i = 0; i < 32; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				((Vector2)(ref val))..ctor((float)j + 0.5f, 31.5f - (float)i);
				float num = 100f;
				foreach (Vector4 item in lines)
				{
					((Vector2)(ref val2))..ctor(item.x, item.y);
					Vector2 val3 = new Vector2(item.z, item.w) - val2;
					float num2 = num;
					Vector2 val4 = val - val2 - val3 * Mathf.Clamp01(Vector2.Dot(val - val2, val3) / ((Vector2)(ref val3)).sqrMagnitude);
					num = Mathf.Min(num2, ((Vector2)(ref val4)).magnitude);
				}
				array[i * 32 + j] = new Color(1f, 1f, 1f, Mathf.Clamp01(2.2f - num));
			}
		}
		return Texture(array);
		void Box(float x, float y, float w, float h)
		{
			Line(x, y, x + w, y);
			Line(x + w, y, x + w, y + h);
			Line(x + w, y + h, x, y + h);
			Line(x, y + h, x, y);
		}
		void Line(float x, float y, float a, float b)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			lines.Add(new Vector4(x, y, a, b));
		}
	}

	private static void Circle(List<Vector4> lines, float x, float y, float radius)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < 32; i++)
		{
			float num = (float)i * MathF.PI / 16f;
			float num2 = (float)(i + 1) * MathF.PI / 16f;
			lines.Add(new Vector4(x + Mathf.Cos(num) * radius, y + Mathf.Sin(num) * radius, x + Mathf.Cos(num2) * radius, y + Mathf.Sin(num2) * radius));
		}
	}

	private static Texture2D Texture(Color[] pixels, int size = 32)
	{
		//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_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_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(size, size, (TextureFormat)4, false)
		{
			hideFlags = (HideFlags)61,
			filterMode = (FilterMode)1,
			wrapMode = (TextureWrapMode)1
		};
		val.SetPixels(pixels);
		val.Apply(false, true);
		return val;
	}
}
internal static class NativeSidebar
{
	private static readonly FieldInfo RightButtons = AccessTools.Field(typeof(OverlayManager), "_rightTopButtons");

	private static readonly FieldInfo IdleColor = AccessTools.Field(typeof(UIManager), "_extraButtonColor");

	private static readonly FieldInfo HoverColor = AccessTools.Field(typeof(UIManager), "_extraButtonHoverColor");

	private static UIManager _ui;

	private static OverlayManager _overlay;

	private static Button _button;

	private static float _retry;

	private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4];

	internal static Button Button
	{
		get
		{
			if (((Object)(object)_overlay == (Object)null || (Object)(object)_button == (Object)null) && Time.unscaledTime >= _retry)
			{
				_retry = Time.unscaledTime + 0.5f;
				_overlay = Object.FindAnyObjectByType<OverlayManager>();
				if ((Object)(object)_overlay != (Object)null && RightButtons?.GetValue(_overlay) is List<GameObject> list)
				{
					foreach (GameObject item in list)
					{
						if ((Object)(object)item == (Object)null)
						{
							continue;
						}
						Button componentInChildren = item.GetComponentInChildren<Button>(true);
						if (!((Object)(object)componentInChildren == (Object)null))
						{
							Image obj = Background(componentInChildren);
							if (!((Object)(object)((obj != null) ? obj.sprite : null) == (Object)null))
							{
								_button = componentInChildren;
								break;
							}
						}
					}
				}
			}
			return _button;
		}
	}

	internal static float Opacity
	{
		get
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Invalid comparison between Unknown and I4
			Button button = Button;
			Image val = Background(button);
			if ((Object)(object)_overlay == (Object)null || (Object)(object)button == (Object)null || (Object)(object)val == (Object)null)
			{
				return 0f;
			}
			Canvas canvas = ((Graphic)val).canvas;
			float inheritedAlpha = ((Graphic)val).canvasRenderer.GetInheritedAlpha();
			if (!SidebarVisibility.Show((int)_overlay.ResolutionMode == 3, ((Component)button).gameObject.activeInHierarchy, (Object)(object)canvas != (Object)null && ((Behaviour)canvas).isActiveAndEnabled, inheritedAlpha))
			{
				return 0f;
			}
			return inheritedAlpha;
		}
	}

	internal static Vector2 Size
	{
		get
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0044: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			Button button = Button;
			Image val = Background(button);
			if ((Object)(object)button == (Object)null || (Object)(object)val == (Object)null || (Object)(object)((Graphic)val).canvas == (Object)null)
			{
				return Vector2.zero;
			}
			Rect val2 = ScreenRect((RectTransform)((Component)button).transform, ((Graphic)val).canvas);
			return ((Rect)(ref val2)).size;
		}
	}

	internal static Image Background(Button button)
	{
		object obj;
		if (!((Object)(object)button == (Object)null))
		{
			obj = ((Component)button).GetComponent<Image>();
			if (obj == null)
			{
				Graphic targetGraphic = ((Selectable)button).targetGraphic;
				return (Image)(object)((targetGraphic is Image) ? targetGraphic : null);
			}
		}
		else
		{
			obj = null;
		}
		return (Image)obj;
	}

	internal static Image Outline(Button button)
	{
		if (!((Object)(object)button == (Object)null))
		{
			Transform obj = ((Component)button).transform.Find("Image_Outline");
			if (obj == null)
			{
				return null;
			}
			return ((Component)obj).GetComponent<Image>();
		}
		return null;
	}

	internal static Image Icon(Button button)
	{
		if (!((Object)(object)button == (Object)null))
		{
			Transform obj = ((Component)button).transform.Find("Image_Icon");
			if (obj == null)
			{
				return null;
			}
			return ((Component)obj).GetComponent<Image>();
		}
		return null;
	}

	internal static Color SurfaceColor(bool highlighted)
	{
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_ui == (Object)null)
		{
			_ui = Object.FindAnyObjectByType<UIManager>();
		}
		FieldInfo fieldInfo = (highlighted ? HoverColor : IdleColor);
		if ((Object)(object)_ui != (Object)null)
		{
			object obj = fieldInfo?.GetValue(_ui);
			if (obj is Color)
			{
				return (Color)obj;
			}
		}
		return new Color(0.9608f, 0.9294f, 0.8824f, highlighted ? 1f : 0.749f);
	}

	internal static Rect ScreenRect(RectTransform rect, Canvas canvas)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: 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_0045: 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_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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		rect.GetWorldCorners(Corners);
		Camera obj = (((int)canvas.renderMode == 0) ? null : canvas.worldCamera);
		Vector2 val = RectTransformUtility.WorldToScreenPoint(obj, Corners[0]);
		Vector2 val2 = RectTransformUtility.WorldToScreenPoint(obj, Corners[2]);
		return Rect.MinMaxRect(Mathf.Min(val.x, val2.x), (float)Screen.height - Mathf.Max(val.y, val2.y), Mathf.Max(val.x, val2.x), (float)Screen.height - Mathf.Min(val.y, val2.y));
	}

	internal static float PixelScale(Image image)
	{
		//IL_000c: 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)
		//IL_0024: 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)
		Rect val = ScreenRect(((Graphic)image).rectTransform, ((Graphic)image).canvas);
		float height = ((Rect)(ref val)).height;
		val = ((Graphic)image).rectTransform.rect;
		return height / Mathf.Max(1f, ((Rect)(ref val)).height);
	}

	internal static void CopyImage(Image source, Image target)
	{
		//IL_000e: 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)
		target.sprite = source.sprite;
		target.type = source.type;
		((Graphic)target).material = ((Graphic)source).material;
		((Graphic)target).color = ((Graphic)source).color;
		target.preserveAspect = source.preserveAspect;
		target.fillCenter = source.fillCenter;
		((MaskableGraphic)target).maskable = ((MaskableGraphic)source).maskable;
		float num = ((Graphic)target).canvas.referencePixelsPerUnit / ((Graphic)source).canvas.referencePixelsPerUnit;
		target.pixelsPerUnitMultiplier = source.pixelsPerUnitMultiplier * num / Mathf.Max(0.01f, PixelScale(source));
	}

	internal static void CopyRect(RectTransform source, RectTransform target, float scale)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_002c: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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)
		target.anchorMin = source.anchorMin;
		target.anchorMax = source.anchorMax;
		target.pivot = source.pivot;
		target.sizeDelta = source.sizeDelta * scale;
		target.anchoredPosition = source.anchoredPosition * scale;
		((Transform)target).localScale = ((Transform)source).localScale;
		((Transform)target).localRotation = ((Transform)source).localRotation;
	}

	internal static bool TryGeometry(out Rect bounds, out float gap, out float preferredTop)
	{
		//IL_0001: 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_0052: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Expected O, but got Unknown
		//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)
		bounds = default(Rect);
		gap = (preferredTop = 0f);
		Button button = Button;
		Image val = Background(button);
		if ((Object)(object)val == (Object)null || (Object)(object)((Graphic)val).canvas == (Object)null)
		{
			return false;
		}
		bounds = ScreenRect((RectTransform)((Component)button).transform, ((Graphic)val).canvas);
		if (((Rect)(ref bounds)).width < 1f || ((Rect)(ref bounds)).height < 1f)
		{
			return false;
		}
		float num = float.MaxValue;
		float num2 = ((Rect)(ref bounds)).y;
		if ((Object)(object)_overlay != (Object)null && RightButtons?.GetValue(_overlay) is List<GameObject> list)
		{
			foreach (GameObject item in list)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				Button[] componentsInChildren = item.GetComponentsInChildren<Button>(true);
				foreach (Button val2 in componentsInChildren)
				{
					Image val3 = Background(val2);
					if (!((Component)val2).gameObject.activeInHierarchy || (Object)(object)val3 == (Object)null || (Object)(object)((Graphic)val3).canvas == (Object)null || (Object)(object)val3.sprite != (Object)(object)val.sprite)
					{
						continue;
					}
					Rect val4 = ScreenRect((RectTransform)((Component)val2).transform, ((Graphic)val3).canvas);
					if (!(Mathf.Abs(((Rect)(ref val4)).x - ((Rect)(ref bounds)).x) > ((Rect)(ref bounds)).height * 0.15f) && !(Mathf.Abs(((Rect)(ref val4)).height - ((Rect)(ref bounds)).height) > ((Rect)(ref bounds)).height * 0.15f))
					{
						num2 = Mathf.Max(num2, ((Rect)(ref val4)).y);
						float num3 = Mathf.Abs(((Rect)(ref val4)).y - ((Rect)(ref bounds)).y);
						if (num3 > ((Rect)(ref bounds)).height)
						{
							num = Mathf.Min(num, num3);
						}
					}
				}
			}
		}
		gap = ((num < float.MaxValue) ? (num - ((Rect)(ref bounds)).height) : (((Rect)(ref bounds)).height * 0.35f));
		preferredTop = num2 + ((Rect)(ref bounds)).height + gap;
		return true;
	}
}
internal static class PlayersInRange
{
	private const float FallbackSearchInterval = 2f;

	private static PlayerController[] _fallbackPlayers = (PlayerController[])(object)new PlayerController[0];

	private static float _nextFallbackSearch;

	public static void Find(Transform localPlayer, float radius, List<Vector3> positions)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		positions.Clear();
		Vector3 position = localPlayer.position;
		float num = radius * radius;
		IList<PlayerController> players = GetPlayers();
		for (int i = 0; i < players.Count; i++)
		{
			PlayerController val = players[i];
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			Transform transform = ((Component)val).transform;
			if (!((Object)(object)transform == (Object)(object)localPlayer))
			{
				Vector3 position2 = transform.position;
				Vector3 val2 = position2 - position;
				if (((Vector3)(ref val2)).sqrMagnitude <= num)
				{
					positions.Add(position2);
				}
			}
		}
	}

	private static IList<PlayerController> GetPlayers()
	{
		PlayerPanelController playerPanel = GameAccess.PlayerPanel;
		List<PlayerController> list = (((Object)(object)playerPanel != (Object)null) ? playerPanel.PlayerControllers : null);
		if (list != null && list.Count > 0)
		{
			return list;
		}
		if (Time.unscaledTime >= _nextFallbackSearch)
		{
			_nextFallbackSearch = Time.unscaledTime + 2f;
			_fallbackPlayers = Object.FindObjectsByType<PlayerController>((FindObjectsSortMode)0);
		}
		return _fallbackPlayers;
	}
}
internal sealed class PlayerMarkers
{
	private const float MarkerRadius = 0.45f;

	private const float RingWidth = 0.2f;

	private const int RingSegments = 40;

	private readonly GameObject _container;

	private readonly Mesh _ringMesh;

	private readonly Material _material;

	private readonly List<GameObject> _pool = new List<GameObject>();

	public bool IsAlive
	{
		get
		{
			if ((Object)(object)_container != (Object)null)
			{
				return (Object)(object)_ringMesh != (Object)null;
			}
			return false;
		}
	}

	public PlayerMarkers()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		_container = new GameObject("LocalChatRange.PlayerMarkers");
		Object.DontDestroyOnLoad((Object)(object)_container);
		_ringMesh = BuildRingMesh();
		_material = Materials.Create("LocalChatRange.Marker");
	}

	public void SetColor(Color color)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Materials.SetColor(_material, color);
	}

	public void Show(List<Vector3> playerPositions, in AreaSettings s)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < playerPositions.Count; i++)
		{
			Place(GetMarker(i), playerPositions[i], in s);
		}
		for (int j = playerPositions.Count; j < _pool.Count; j++)
		{
			if ((Object)(object)_pool[j] != (Object)null && _pool[j].activeSelf)
			{
				_pool[j].SetActive(false);
			}
		}
	}

	public void HideAll()
	{
		foreach (GameObject item in _pool)
		{
			if ((Object)(object)item != (Object)null && item.activeSelf)
			{
				item.SetActive(false);
			}
		}
	}

	public void Destroy()
	{
		if ((Object)(object)_container != (Object)null)
		{
			Object.Destroy((Object)(object)_container);
		}
		if ((Object)(object)_ringMesh != (Object)null)
		{
			Object.Destroy((Object)(object)_ringMesh);
		}
		if ((Object)(object)_material != (Object)null)
		{
			Object.Destroy((Object)(object)_material);
		}
	}

	private static void Place(GameObject marker, Vector3 playerPosition, in AreaSettings s)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = playerPosition;
		Quaternion val2 = Quaternion.identity;
		RaycastHit val3 = default(RaycastHit);
		if (Physics.Raycast(playerPosition + Vector3.up * 0.5f, Vector3.down, ref val3, 3f, s.LayerMask, (QueryTriggerInteraction)1))
		{
			val = ((RaycastHit)(ref val3)).point;
			val2 = Quaternion.FromToRotation(Vector3.up, ((RaycastHit)(ref val3)).normal);
		}
		marker.transform.SetPositionAndRotation(val + Vector3.up * (s.SurfaceOffset * 2f), val2);
		if (!marker.activeSelf)
		{
			marker.SetActive(true);
		}
	}

	private GameObject GetMarker(int index)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//IL_0065: 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)
		while (_pool.Count <= index)
		{
			_pool.Add(null);
		}
		if ((Object)(object)_pool[index] != (Object)null)
		{
			return _pool[index];
		}
		GameObject val = new GameObject("LocalChatRange.Marker");
		val.transform.SetParent(_container.transform, false);
		val.transform.localScale = Vector3.one * 0.45f;
		val.AddComponent<MeshFilter>().sharedMesh = _ringMesh;
		MeshRenderer obj = val.AddComponent<MeshRenderer>();
		((Renderer)obj).sharedMaterial = _material;
		Materials.ConfigureRenderer((Renderer)(object)obj);
		val.SetActive(false);
		_pool[index] = val;
		return val;
	}

	private static Mesh BuildRingMesh()
	{
		//IL_0006: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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_0098: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: 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_0182: 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: Expected O, but got Unknown
		List<Vector3> list = new List<Vector3> { Vector3.zero };
		List<Color> list2 = new List<Color>
		{
			new Color(1f, 1f, 1f, 0.1f)
		};
		List<int> list3 = new List<int>();
		float num = 0.8f;
		Vector3 val = default(Vector3);
		for (int i = 0; i < 40; i++)
		{
			float num2 = (float)i * 2f * MathF.PI / 40f;
			((Vector3)(ref val))..ctor(Mathf.Cos(num2), 0f, Mathf.Sin(num2));
			list.Add(val * num);
			list.Add(val * num);
			list.Add(val);
			list2.Add(new Color(1f, 1f, 1f, 0.25f));
			list2.Add(Color.white);
			list2.Add(Color.white);
		}
		for (int j = 0; j < 40; j++)
		{
			int num3 = 1 + 3 * j;
			int num4 = 1 + 3 * ((j + 1) % 40);
			list3.Add(0);
			list3.Add(num3);
			list3.Add(num4);
			list3.Add(num3 + 1);
			list3.Add(num3 + 2);
			list3.Add(num4 + 2);
			list3.Add(num3 + 1);
			list3.Add(num4 + 2);
			list3.Add(num4 + 1);
		}
		Mesh val2 = new Mesh
		{
			name = "LocalChatRange.Marker",
			hideFlags = (HideFlags)61
		};
		val2.SetVertices(list);
		val2.SetColors(list2);
		val2.SetTriangles(list3, 0);
		val2.RecalculateBounds();
		return val2;
	}
}
public enum VisibilityMode
{
	Always,
	LocalTabOnly,
	WhileTypingLocal
}
[BepInPlugin("ontogether.localchatrange", "LocalChatRange", "1.1.2")]
[BepInProcess("OnTogether.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	public const string PluginGuid = "ontogether.localchatrange";

	public const string PluginName = "LocalChatRange";

	public const string PluginVersion = "1.1.2";

	internal ConfigEntry<bool> Enabled;

	internal ConfigEntry<KeyboardShortcut> ToggleKey;

	internal ConfigEntry<VisibilityMode> Mode;

	internal ConfigEntry<bool> HighlightPlayers;

	private ConfigEntry<bool> _autoDetectRadius;

	private ConfigEntry<float> _radius;

	private ConfigEntry<Color> _fillColor;

	private ConfigEntry<Color> _outlineColor;

	private ConfigEntry<float> _outlineWidth;

	private ConfigEntry<bool> _outlineOnTop;

	private ConfigEntry<Color> _markerColor;

	private ConfigEntry<int> _segments;

	private ConfigEntry<int> _rings;

	private ConfigEntry<int> _refineSteps;

	private ConfigEntry<float> _updateInterval;

	private ConfigEntry<float> _maxStepUp;

	private ConfigEntry<float> _surfaceOffset;

	private float? _detectedRadius;

	private Harmony _harmony;

	private RangeArea _area;

	private PlayerMarkers _markers;

	private int _layerMask;

	private readonly List<Vector3> _playersInRange = new List<Vector3>();

	private bool _visualsFailed;

	private string _lastError;

	private Transform _pivotOwner;

	private CharacterController _pivotController;

	private float _pivotHeight;

	internal static Plugin Instance { get; private set; }

	internal static ManualLogSource Log { get; private set; }

	internal float Radius
	{
		get
		{
			if (!_autoDetectRadius.Value || !_detectedRadius.HasValue)
			{
				return _radius.Value;
			}
			return _detectedRadius.Value;
		}
	}

	private void Awake()
	{
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		BindConfig();
		ConfigMenu.Create(((Component)this).gameObject, "LocalChatRange", "range", ((BaseUnityPlugin)this).Config, () => (Object)(object)GameAccess.Chat != (Object)null);
		try
		{
			_detectedRadius = GameAccess.DetectRadiusFromGameCode();
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("Radius auto-detection failed: " + ex.Message));
		}
		if (_detectedRadius.HasValue)
		{
			Log.LogInfo((object)$"Local chat radius read from the game code: {_detectedRadius.Value:0.##} m");
		}
		else
		{
			Log.LogWarning((object)$"Could not read the local chat radius from the game code; using Range.Radius = {_radius.Value} m");
		}
		try
		{
			_harmony = Harmony.CreateAndPatchAll(typeof(ChatCommandPatch), "ontogether.localchatrange");
		}
		catch (Exception ex2)
		{
			Log.LogError((object)("Could not patch the chat; /chatrange will not work: " + ex2));
		}
		ChatCommands.RegisterWithCommandApi();
		((BaseUnityPlugin)this).Config.SettingChanged += OnSettingChanged;
		if (_harmony != null)
		{
			UiEnvironment.InstallInputGuard(_harmony);
		}
		Log.LogInfo((object)string.Format("{0} {1} loaded. Toggle with {2} or /chatrange", "LocalChatRange", "1.1.2", ToggleKey.Value));
	}

	private void BindConfig()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Expected O, but got Unknown
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Expected O, but got Unknown
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Expected O, but got Unknown
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Expected O, but got Unknown
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Expected O, but got Unknown
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Expected O, but got Unknown
		//IL_0305: Unknown result type (might be due to invalid IL or missing references)
		//IL_030f: Expected O, but got Unknown
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Expected O, but got Unknown
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the local text chat range around your character.");
		ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Hotkey that shows/hides the area (ignored while typing in a text field).");
		Mode = ((BaseUnityPlugin)this).Config.Bind<VisibilityMode>("General", "VisibilityMode", VisibilityMode.Always, "When the area is drawn:\nAlways - whenever it is enabled;\nLocalTabOnly - only while the chat is switched to the Local tab;\nWhileTypingLocal - only while you are typing a message in the Local tab.");
		HighlightPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HighlightPlayersInRange", true, "Draw a ring under every player who would receive your local messages.");
		_autoDetectRadius = ((BaseUnityPlugin)this).Config.Bind<bool>("Range", "AutoDetectRadius", true, "Read the local chat distance from the game code at startup (recommended). If it cannot be read, Radius is used.");
		_radius = ((BaseUnityPlugin)this).Config.Bind<float>("Range", "Radius", 5f, new ConfigDescription("Local chat distance in metres, used when auto-detection is off or fails.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 100f), Array.Empty<object>()));
		_fillColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Appearance", "FillColor", new Color(0.55f, 0.85f, 1f, 0.12f), "Colour of the area (RRGGBBAA). The fill fades towards the centre.");
		_outlineColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Appearance", "OutlineColor", new Color(0.55f, 0.85f, 1f, 0.9f), "Colour of the area's edge (RRGGBBAA).");
		_outlineWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "OutlineWidth", 0.08f, new ConfigDescription("Width of the edge line in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 1f), Array.Empty<object>()));
		_outlineOnTop = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "OutlineOnTop", false, "Draw the edge line on top of walls and furniture.");
		_markerColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Appearance", "PlayerMarkerColor", new Color(0.55f, 1f, 0.55f, 0.9f), "Colour of the rings under players in range (RRGGBBAA).");
		_segments = ((BaseUnityPlugin)this).Config.Bind<int>("Quality", "Segments", 64, new ConfigDescription("Points around the circle.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(16, 256), Array.Empty<object>()));
		_rings = ((BaseUnityPlugin)this).Config.Bind<int>("Quality", "Rings", 8, new ConfigDescription("Surface samples from the centre to the edge. More rings follow stairs and bumps more closely.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 32), Array.Empty<object>()));
		_refineSteps = ((BaseUnityPlugin)this).Config.Bind<int>("Quality", "EdgeRefineSteps", 4, new ConfigDescription("Extra samples used to place the edge precisely where the ground leaves the range.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 8), Array.Empty<object>()));
		_updateInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Quality", "UpdateInterval", 0.05f, new ConfigDescription("Seconds between surface re-samples while moving. The area follows you every frame regardless.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		_maxStepUp = ((BaseUnityPlugin)this).Config.Bind<float>("Quality", "MaxStepUp", 2f, new ConfigDescription("Ignore surfaces higher than this above your feet (ceilings, upper floors), in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 10f), Array.Empty<object>()));
		_surfaceOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Quality", "SurfaceOffset", 0.03f, new ConfigDescription("Lift above the surface to avoid flickering, in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.5f), Array.Empty<object>()));
	}

	private void Update()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (Pressed(ToggleKey.Value) && !UiEnvironment.AnyWindowOpen && !GameAccess.IsAnyTextFieldFocused())
		{
			SetEnabled(!Enabled.Value, notify: false);
		}
	}

	private static bool Pressed(KeyboardShortcut shortcut)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_000b: 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)
		KeyCode mainKey = ((KeyboardShortcut)(ref shortcut)).MainKey;
		if ((int)mainKey == 0 || !Input.GetKeyDown(mainKey))
		{
			return false;
		}
		foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers)
		{
			if (!Input.GetKey(modifier))
			{
				return false;
			}
		}
		return true;
	}

	private void LateUpdate()
	{
		try
		{
			Tick();
		}
		catch (Exception ex)
		{
			string text = ex.GetType().Name + ": " + ex.Message;
			if (text != _lastError)
			{
				_lastError = text;
				Log.LogError((object)("Update failed: " + ex));
			}
			HideVisuals();
		}
	}

	private void Tick()
	{
		//IL_003a: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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)
		TextChannelManager chat = GameAccess.Chat;
		Transform val = (((Object)(object)chat != (Object)null) ? chat.MainPlayer : null);
		if (!ShouldShow(chat, val) || !EnsureVisuals())
		{
			HideVisuals();
			return;
		}
		AreaSettings settings = CurrentSettings();
		Vector3 center = val.position + Vector3.down * PivotHeight(val);
		_area.SetVisible(visible: true);
		_area.Tick(center, in settings);
		if (HighlightPlayers.Value)
		{
			PlayersInRange.Find(val, settings.Radius, _playersInRange);
			_markers.Show(_playersInRange, in settings);
		}
		else
		{
			_markers.HideAll();
		}
	}

	private bool ShouldShow(TextChannelManager chat, Transform player)
	{
		if (!Enabled.Value || (Object)(object)chat == (Object)null || (Object)(object)player == (Object)null)
		{
			return false;
		}
		switch (Mode.Value)
		{
		case VisibilityMode.LocalTabOnly:
			return chat.Islocal;
		case VisibilityMode.WhileTypingLocal:
			if (chat.Islocal)
			{
				return GameAccess.IsChatInputFocused();
			}
			return false;
		default:
			return true;
		}
	}

	private float PivotHeight(Transform player)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_pivotOwner != (Object)(object)player)
		{
			_pivotOwner = player;
			_pivotController = ((Component)player).GetComponentInChildren<CharacterController>(true);
			_pivotHeight = 0f;
		}
		if ((Object)(object)_pivotController != (Object)null && ((Collider)_pivotController).enabled && ((Component)_pivotController).gameObject.activeInHierarchy)
		{
			float y = player.position.y;
			Bounds bounds = ((Collider)_pivotController).bounds;
			float num = y - ((Bounds)(ref bounds)).min.y + _pivotController.skinWidth;
			_pivotHeight = Mathf.Clamp(num, 0f, 3f);
		}
		return _pivotHeight;
	}

	private AreaSettings CurrentSettings()
	{
		return new AreaSettings
		{
			Radius = Radius,
			Segments = _segments.Value,
			Rings = _rings.Value,
			RefineSteps = _refineSteps.Value,
			UpdateInterval = _updateInterval.Value,
			MaxStepUp = _maxStepUp.Value,
			SurfaceOffset = _surfaceOffset.Value,
			OutlineWidth = _outlineWidth.Value,
			LayerMask = _layerMask
		};
	}

	private bool EnsureVisuals()
	{
		if (_visualsFailed)
		{
			return false;
		}
		if (_area != null && _area.IsAlive && _markers != null && _markers.IsAlive)
		{
			return true;
		}
		DestroyVisuals();
		_layerMask = -5 & ~LayerMask.GetMask(new string[20]
		{
			"Player", "PlayerRender", "NPC", "Customization", "IsGroundedChecker", "Area", "AreaChecker", "AreaTrigger", "AntiPlayer", "IgnorePlayer",
			"BasketBall", "BasketBallPlayer", "BasketBoundaryLayer", "Umbrella", "Drawing", "UI", "Indicator", "Overlay", "PostProcess1", "PostProcess2"
		});
		_area = new RangeArea();
		_markers = new PlayerMarkers();
		if (!_area.HasMaterials)
		{
			_visualsFailed = true;
			Log.LogError((object)"No usable shader found; the area cannot be drawn.");
			DestroyVisuals();
			return false;
		}
		ApplyAppearance();
		Log.LogInfo((object)("Area visuals created (shader: " + Materials.ShaderInUse + ")"));
		return true;
	}

	private void ApplyAppearance()
	{
		//IL_0014: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		if (_area != null)
		{
			_area.ApplyAppearance(_fillColor.Value, _outlineColor.Value, _outlineOnTop.Value);
			_area.MarkDirty();
		}
		if (_markers != null)
		{
			_markers.SetColor(_markerColor.Value);
		}
	}

	private void HideVisuals()
	{
		if (_area != null && _area.IsAlive)
		{
			_area.SetVisible(visible: false);
		}
		if (_markers != null && _markers.IsAlive)
		{
			_markers.HideAll();
		}
	}

	private void DestroyVisuals()
	{
		if (_area != null)
		{
			_area.Destroy();
		}
		if (_markers != null)
		{
			_markers.Destroy();
		}
		_area = null;
		_markers = null;
	}

	private void OnSettingChanged(object sender, SettingChangedEventArgs e)
	{
		ApplyAppearance();
	}

	internal void SetEnabled(bool enabled, bool notify)
	{
		Enabled.Value = enabled;
		if (notify)
		{
			string text = (enabled ? "Local chat area: shown" : "Local chat area: hidden");
			if (enabled && Mode.Value != VisibilityMode.Always)
			{
				text = text + " (" + Describe(Mode.Value) + ")";
			}
			GameAccess.Notify(text);
		}
	}

	internal string DescribeStatus()
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		string arg = ((_autoDetectRadius.Value && _detectedRadius.HasValue) ? "from game code" : "from config");
		string text = (Enabled.Value ? "shown" : "hidden") + ", mode: " + Describe(Mode.Value) + ", " + $"radius: {Radius:0.##} m ({arg}), hotkey: {ToggleKey.Value}";
		TextChannelManager chat = GameAccess.Chat;
		Transform val = (((Object)(object)chat != (Object)null) ? chat.MainPlayer : null);
		if ((Object)(object)val == (Object)null)
		{
			return text;
		}
		List<Vector3> list = new List<Vector3>();
		PlayersInRange.Find(val, Radius, list);
		return text + $", players in range: {list.Count}";
	}

	internal static string Describe(VisibilityMode mode)
	{
		return mode switch
		{
			VisibilityMode.LocalTabOnly => "only on the Local chat tab", 
			VisibilityMode.WhileTypingLocal => "only while typing in the Local tab", 
			_ => "always", 
		};
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.SettingChanged -= OnSettingChanged;
		if (_harmony != null)
		{
			_harmony.UnpatchSelf();
		}
		DestroyVisuals();
	}
}
internal struct AreaSettings
{
	public float Radius;

	public int Segments;

	public int Rings;

	public int RefineSteps;

	public float UpdateInterval;

	public float MaxStepUp;

	public float SurfaceOffset;

	public float OutlineWidth;

	public int LayerMask;
}
internal sealed class RangeArea
{
	private const float VerticalTolerance = 0.05f;

	private const float IdleRefreshInterval = 0.5f;

	private const float MoveThresholdSqr = 0.0009f;

	private const float CenterAlpha = 0.35f;

	private const float TentMinHeight = 0.35f;

	private static readonly float TentMaxSlopeCos = Mathf.Cos(0.87266463f);

	private readonly GameObject _root;

	private readonly Mesh _mesh;

	private readonly Material _fillMaterial;

	private readonly Material _outlineMaterial;

	private readonly List<Vector3> _vertices = new List<Vector3>();

	private readonly List<Color> _colors = new List<Color>();

	private readonly List<int> _fillTriangles = new List<int>();

	private readonly List<int> _outlineTriangles = new List<int>();

	private Vector3[] _samples = (Vector3[])(object)new Vector3[0];

	private bool[] _sampleHit = new bool[0];

	private bool[] _vertexUsable = new bool[0];

	private float[] _boundaryRadius = new float[0];

	private Vector3[] _boundaryPoint = (Vector3[])(object)new Vector3[0];

	private Vector3[] _innerPoint = (Vector3[])(object)new Vector3[0];

	private int[] _outermostHit = new int[0];

	private Vector3 _builtCenter;

	private float _lastBuildTime = float.NegativeInfinity;

	private bool _dirty = true;

	public bool IsAlive
	{
		get
		{
			if ((Object)(object)_root != (Object)null)
			{
				return (Object)(object)_mesh != (Object)null