Decompiled source of ChatPlus v1.6.0

ChatPlus.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using PurrNet;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem.UI;
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("ChatPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyInformationalVersion("1.6.0+ec9b69c737a511ca8bc978d9ad845775168f1199")]
[assembly: AssemblyProduct("ChatPlus")]
[assembly: AssemblyTitle("ChatPlus")]
[assembly: AssemblyVersion("1.6.0.0")]
namespace ChatPlus;

internal sealed class BackgroundOpacity : BaseMeshEffect
{
	private Image _image;

	internal static void Attach(Image image)
	{
		if (!((Object)(object)image == (Object)null) && !((Object)(object)((Component)image).GetComponent<Mask>() != (Object)null))
		{
			BackgroundOpacity obj = ((Component)image).GetComponent<BackgroundOpacity>() ?? ((Component)image).gameObject.AddComponent<BackgroundOpacity>();
			obj._image = image;
			obj.Refresh();
		}
	}

	internal void Refresh()
	{
		Image image = _image;
		if (image != null)
		{
			((Graphic)image).SetVerticesDirty();
		}
	}

	public override void ModifyMesh(VertexHelper mesh)
	{
		//IL_0041: 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)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		Plugin instance = Plugin.Instance;
		if (((UIBehaviour)this).IsActive() && !((Object)(object)instance == (Object)null) && instance.BackgroundOpacity.Value != 100)
		{
			float num = Mathf.Clamp01((float)instance.BackgroundOpacity.Value / 100f);
			UIVertex val = default(UIVertex);
			for (int i = 0; i < mesh.currentVertCount; i++)
			{
				mesh.PopulateUIVertex(ref val, i);
				Color32 color = val.color;
				color.a = (byte)Mathf.RoundToInt((float)(int)color.a * num);
				val.color = color;
				mesh.SetUIVertex(val, i);
			}
		}
	}
}
internal sealed class ChatChrome : MonoBehaviour
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static UnityAction <>9__22_0;

		internal void <Create>b__22_0()
		{
			Plugin.Instance?.ToggleWindow();
		}
	}

	private const float HeaderHeight = 86f;

	private static readonly Color Ink = new Color(0.325f, 0.263f, 0.204f, 1f);

	private static readonly Color Coral = new Color(0.976f, 0.867f, 0.784f, 1f);

	private RectTransform _global;

	private RectTransform _local;

	private RectTransform _footer;

	private TMP_Text _hint;

	private Image _gearImage;

	private Image _frame;

	private Image _buttonImage;

	private Button _button;

	private Texture2D _texture;

	private Sprite _sprite;

	private Texture2D _gearTexture;

	private Sprite _gearSprite;

	private Material _fontMaterial;

	private string _hintText;

	private Lang _lang;

	private bool _selection;

	private KeyboardShortcut _shortcut;

	private bool _textsReady;

	internal static void Attach(RectTransform root, Image frame, Transform global, Transform local)
	{
		if (!((Object)(object)root == (Object)null) && !((Object)(object)frame == (Object)null) && !((Object)(object)((Component)root).GetComponent<ChatChrome>() != (Object)null))
		{
			ChatChrome chatChrome = ((Component)root).gameObject.AddComponent<ChatChrome>();
			chatChrome._frame = frame;
			chatChrome._global = (RectTransform)(object)((global is RectTransform) ? global : null);
			chatChrome._local = (RectTransform)(object)((local is RectTransform) ? local : null);
			chatChrome.Create(((Graphic)frame).rectTransform);
		}
	}

	private void Create(RectTransform frame)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_004c: 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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Expected O, but got Unknown
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Expected O, but got Unknown
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Expected O, but got Unknown
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: 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_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: 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_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Expected O, but got Unknown
		GameObject val = new GameObject("ChatPlus.ChatHeader", new Type[1] { typeof(RectTransform) });
		_footer = (RectTransform)val.transform;
		((Transform)_footer).SetParent((Transform)(object)frame, false);
		_footer.anchorMin = new Vector2(0f, 1f);
		_footer.anchorMax = Vector2.one;
		_footer.pivot = new Vector2(0.5f, 1f);
		_footer.offsetMin = new Vector2(48f, -116f);
		_footer.offsetMax = new Vector2(-48f, -48f);
		_hint = Text("Gestures", _footer);
		_hint.rectTransform.offsetMin = Vector2.zero;
		_hint.rectTransform.offsetMax = new Vector2(-88f, 0f);
		_hint.fontSize = 22f;
		_hint.enableAutoSizing = true;
		_hint.fontSizeMin = 18f;
		_hint.fontSizeMax = 22f;
		_hint.alignment = (TextAlignmentOptions)4097;
		GameObject val2 = new GameObject("ChatPlus.SettingsButton", new Type[3]
		{
			typeof(RectTransform),
			typeof(Image),
			typeof(Button)
		});
		RectTransform val3 = (RectTransform)val2.transform;
		((Transform)val3).SetParent((Transform)(object)_footer, false);
		Vector2 val4 = default(Vector2);
		((Vector2)(ref val4))..ctor(1f, 0.5f);
		val3.anchorMax = val4;
		val3.anchorMin = val4;
		val3.pivot = new Vector2(1f, 0.5f);
		val3.sizeDelta = new Vector2(72f, 68f);
		val3.anchoredPosition = Vector2.zero;
		_buttonImage = val2.GetComponent<Image>();
		_texture = ButtonTexture();
		_sprite = Sprite.Create(_texture, new Rect(0f, 0f, 48f, 48f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(12f, 12f, 12f, 12f));
		_buttonImage.sprite = _sprite;
		_buttonImage.type = (Type)1;
		BackgroundOpacity.Attach(_buttonImage);
		_button = val2.GetComponent<Button>();
		((Selectable)_button).targetGraphic = (Graphic)(object)_buttonImage;
		Button button = _button;
		Navigation navigation = default(Navigation);
		((Navigation)(ref navigation)).mode = (Mode)0;
		((Selectable)button).navigation = navigation;
		ButtonClickedEvent onClick = _button.onClick;
		object obj = <>c.<>9__22_0;
		if (obj == null)
		{
			UnityAction val5 = delegate
			{
				Plugin.Instance?.ToggleWindow();
			};
			<>c.<>9__22_0 = val5;
			obj = (object)val5;
		}
		((UnityEvent)onClick).AddListener((UnityAction)obj);
		GameObject val6 = new GameObject("Gear", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		RectTransform val7 = (RectTransform)val6.transform;
		((Transform)val7).SetParent((Transform)(object)val3, false);
		Vector2 val8 = default(Vector2);
		((Vector2)(ref val8))..ctor(0.5f, 0.5f);
		val7.pivot = val8;
		val4 = (val7.anchorMin = (val7.anchorMax = val8));
		val7.sizeDelta = new Vector2(44f, 44f);
		val7.anchoredPosition = Vector2.zero;
		_gearTexture = GearTexture();
		_gearSprite = Sprite.Create(_gearTexture, new Rect(0f, 0f, 48f, 48f), new Vector2(0.5f, 0.5f), 100f);
		_gearImage = val6.GetComponent<Image>();
		_gearImage.sprite = _gearSprite;
		((Graphic)_gearImage).raycastTarget = false;
		BackgroundOpacity.Attach(_gearImage);
		val2.AddComponent<SettingsButtonHint>();
		ReserveScroll(_global, 86f);
		ReserveScroll(_local, 86f);
	}

	private static void ReserveScroll(RectTransform scroll, float height)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)scroll != (Object)null)
		{
			scroll.offsetMax -= new Vector2(0f, height);
		}
	}

	private static TMP_Text Text(string name, RectTransform parent)
	{
		//IL_0021: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		TextMeshProUGUI component = new GameObject(name, new Type[2]
		{
			typeof(RectTransform),
			typeof(TextMeshProUGUI)
		}).GetComponent<TextMeshProUGUI>();
		((Transform)((TMP_Text)component).rectTransform).SetParent((Transform)(object)parent, false);
		((TMP_Text)component).rectTransform.anchorMin = Vector2.zero;
		((TMP_Text)component).rectTransform.anchorMax = Vector2.one;
		RectTransform rectTransform = ((TMP_Text)component).rectTransform;
		Vector2 offsetMin = (((TMP_Text)component).rectTransform.offsetMax = Vector2.zero);
		rectTransform.offsetMin = offsetMin;
		((Graphic)component).raycastTarget = false;
		((TMP_Text)component).richText = false;
		((TMP_Text)component).overflowMode = (TextOverflowModes)1;
		return (TMP_Text)(object)component;
	}

	private unsafe void LateUpdate()
	{
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Expected O, but got Unknown
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		Plugin instance = Plugin.Instance;
		if ((Object)(object)instance == (Object)null || (Object)(object)_footer == (Object)null || (Object)(object)_frame == (Object)null)
		{
			return;
		}
		TMP_Text val = GameAccess.TextPrefab(GameAccess.Chat);
		if ((Object)(object)val != (Object)null && (Object)(object)val.font != (Object)null && (Object)(object)_hint.font != (Object)(object)val.font)
		{
			_hint.font = val.font;
			if ((Object)(object)_fontMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)_fontMaterial);
			}
			if ((Object)(object)val.fontSharedMaterial != (Object)null)
			{
				_fontMaterial = new Material(val.fontSharedMaterial)
				{
					hideFlags = (HideFlags)61
				};
				_fontMaterial.DisableKeyword("UNDERLAY_ON");
				_hint.fontSharedMaterial = _fontMaterial;
			}
		}
		Lang current = Lang.Current;
		KeyboardShortcut value = instance.WindowKey.Value;
		if (!_textsReady || current != _lang || _selection != instance.SelectText.Value || !((object)(*(KeyboardShortcut*)(&value))/*cast due to .constrained prefix*/).Equals((object?)_shortcut))
		{
			_lang = current;
			_selection = instance.SelectText.Value;
			_shortcut = value;
			_textsReady = true;
			string text = current.ChatScrollHint + (_selection ? (" · " + current.ChatSelectHint + "\n" + current.ChatCopyHint) : string.Empty);
			if (_hintText != text)
			{
				_hint.text = (_hintText = text);
			}
		}
		float num = (((Component)_frame).gameObject.activeInHierarchy ? ((Graphic)_frame).color.a : 0f);
		((Graphic)_hint).color = new Color(0.96f, 0.93f, 0.88f, num);
		((Graphic)_gearImage).color = new Color(Ink.r, Ink.g, Ink.b, num);
		((Graphic)_buttonImage).color = new Color(Coral.r, Coral.g, Coral.b, num);
		((Selectable)_button).interactable = num > 0.05f;
		((Graphic)_buttonImage).raycastTarget = num > 0.05f;
	}

	private static Texture2D ButtonTexture()
	{
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: 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_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		Color[] array = (Color[])(object)new Color[2304];
		for (int i = 0; i < 48; i++)
		{
			for (int j = 0; j < 48; j++)
			{
				float num = Mathf.Max(Mathf.Abs((float)j + 0.5f - 24f) - 14f, 0f);
				float num2 = Mathf.Max(Mathf.Abs((float)i + 0.5f - 24f) - 14f, 0f);
				array[i * 48 + j] = new Color(1f, 1f, 1f, Mathf.Clamp01(10.5f - Mathf.Sqrt(num * num + num2 * num2)));
			}
		}
		Texture2D val = new Texture2D(48, 48, (TextureFormat)4, false)
		{
			name = "ChatPlus.SettingsButton",
			hideFlags = (HideFlags)61,
			wrapMode = (TextureWrapMode)1
		};
		val.SetPixels(array);
		val.Apply(false, true);
		return val;
	}

	private static Texture2D GearTexture()
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		Color[] array = (Color[])(object)new Color[2304];
		for (int i = 0; i < 48; i++)
		{
			for (int j = 0; j < 48; j++)
			{
				float num = (float)j + 0.5f - 24f;
				float num2 = (float)i + 0.5f - 24f;
				float num3 = Mathf.Sqrt(num * num + num2 * num2);
				float num4 = Mathf.Clamp01((Mathf.Cos(Mathf.Atan2(num2, num) * 8f) - 0.1f) * 2f);
				float num5 = Mathf.Clamp01(16.5f + 3f * num4 - num3) * Mathf.Clamp01(num3 - 5.5f);
				array[i * 48 + j] = new Color(1f, 1f, 1f, num5);
			}
		}
		Texture2D val = new Texture2D(48, 48, (TextureFormat)4, false)
		{
			name = "ChatPlus.SettingsGear",
			hideFlags = (HideFlags)61,
			wrapMode = (TextureWrapMode)1
		};
		val.SetPixels(array);
		val.Apply(false, true);
		return val;
	}

	private void OnDestroy()
	{
		ReserveScroll(_global, -86f);
		ReserveScroll(_local, -86f);
		if ((Object)(object)_footer != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_footer).gameObject);
		}
		if ((Object)(object)_fontMaterial != (Object)null)
		{
			Object.Destroy((Object)(object)_fontMaterial);
		}
		if ((Object)(object)_sprite != (Object)null)
		{
			Object.Destroy((Object)(object)_sprite);
		}
		if ((Object)(object)_texture != (Object)null)
		{
			Object.Destroy((Object)(object)_texture);
		}
		if ((Object)(object)_gearSprite != (Object)null)
		{
			Object.Destroy((Object)(object)_gearSprite);
		}
		if ((Object)(object)_gearTexture != (Object)null)
		{
			Object.Destroy((Object)(object)_gearTexture);
		}
	}
}
internal sealed class SettingsButtonHint : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler
{
	public unsafe void OnPointerEnter(PointerEventData pointer)
	{
		//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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)Plugin.Instance == (Object)null))
		{
			KeyboardShortcut value = Plugin.Instance.WindowKey.Value;
			string settingsShort = Lang.Current.SettingsShort;
			string text;
			if ((int)((KeyboardShortcut)(ref value)).MainKey != 0)
			{
				KeyboardShortcut val = value;
				text = " · " + ((object)(*(KeyboardShortcut*)(&val))/*cast due to .constrained prefix*/).ToString();
			}
			else
			{
				text = string.Empty;
			}
			Toast.Show(settingsShort + text);
		}
	}
}
internal static class ChatCommands
{
	public const string CommandApiGuid = "com.on-together-mods.commandapi";

	private static readonly string[] Names = new string[2] { "chatplus", "chp" };

	public static bool TryParse(string text, out string[] args)
	{
		args = null;
		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;
		}
		args = array.Skip(1).ToArray();
		return true;
	}

	public static void Execute(string[] args)
	{
		//IL_03af: Unknown result type (might be due to invalid IL or missing references)
		Plugin instance = Plugin.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		Lang current = Lang.Current;
		if (args.Length == 0)
		{
			instance.ToggleWindow();
			return;
		}
		switch (args[0].ToLowerInvariant())
		{
		case "ui":
		case "window":
		case "settings":
			instance.ToggleWindow();
			break;
		case "time":
		case "timestamps":
			Timestamps(instance, current, args);
			break;
		case "size":
			Size(instance, current, args);
			break;
		case "font":
		case "text":
			TextSize(instance, current, args);
			break;
		case "lines":
		case "limit":
		case "history":
			Lines(instance, current, args);
			break;
		case "clear":
			GameAccess.Notify(string.Format(current.ChatCleared, ChatLines.Clear()));
			break;
		case "clearhistory":
			instance.History.Clear();
			GameAccess.Notify(current.HistoryCleared);
			break;
		case "folder":
		case "open":
			instance.OpenHistoryFolder();
			break;
		case "reset":
			instance.ResetWindow();
			GameAccess.Notify(current.WindowReset);
			break;
		case "kw":
		case "keywords":
		case "keyword":
			Keyword(instance, current, args);
			break;
		case "status":
			GameAccess.Notify(instance.DescribeStatus(current));
			break;
		default:
			GameAccess.Notify(string.Format(current.Help, instance.WindowKey.Value));
			break;
		}
	}

	private static void Timestamps(Plugin plugin, Lang lang, string[] args)
	{
		string text = ((args.Length > 1) ? args[1].ToLowerInvariant() : "toggle");
		switch (text)
		{
		case "toggle":
		case "on":
		case "off":
			plugin.Timestamps.Value = ((text == "toggle") ? (!plugin.Timestamps.Value) : (text == "on"));
			GameAccess.Notify(plugin.Timestamps.Value ? lang.TimeOn : lang.TimeOff);
			return;
		case "format":
			if (args.Length >= 3)
			{
				string text2 = string.Join(" ", args, 2, args.Length - 2);
				plugin.TimeFormat.Value = text2;
				plugin.Timestamps.Value = true;
				GameAccess.Notify(string.Format(lang.TimeFormatSet, text2, ChatFormat.FormatTime(DateTime.Now, text2)));
				return;
			}
			break;
		}
		GameAccess.Notify(lang.UsageTime);
	}

	private static void Size(Plugin plugin, Lang lang, string[] args)
	{
		if (args.Length > 1 && args[1].Equals("reset", StringComparison.OrdinalIgnoreCase))
		{
			ChatWindow.ResetSize();
		}
		else
		{
			if (args.Length <= 1 || !TryParsePercent(args[1], out var percent))
			{
				GameAccess.Notify(lang.UsageSize);
				return;
			}
			int percent2 = plugin.Height.Value;
			if (args.Length > 2 && !TryParsePercent(args[2], out percent2))
			{
				GameAccess.Notify(lang.UsageSize);
				return;
			}
			plugin.Width.Value = percent;
			plugin.Height.Value = percent2;
		}
		GameAccess.Notify(string.Format(lang.SizeSet, plugin.Width.Value, plugin.Height.Value));
	}

	private static void TextSize(Plugin plugin, Lang lang, string[] args)
	{
		if (args.Length < 2 || !TryParsePercent(args[1], out var percent))
		{
			GameAccess.Notify(lang.UsageText);
			return;
		}
		plugin.TextSize.Value = percent;
		GameAccess.Notify(string.Format(lang.TextSizeSet, plugin.TextSize.Value));
	}

	private static void Lines(Plugin plugin, Lang lang, string[] args)
	{
		if (args.Length < 2 || !int.TryParse(args[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
		{
			GameAccess.Notify(lang.UsageLimit);
			return;
		}
		int result2 = plugin.LocalLimit.Value;
		if (args.Length > 2 && !int.TryParse(args[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out result2))
		{
			GameAccess.Notify(lang.UsageLimit);
			return;
		}
		plugin.GlobalLimit.Value = result;
		plugin.LocalLimit.Value = result2;
		GameAccess.Notify(string.Format(lang.LimitsSet, plugin.GlobalLimit.Value, plugin.LocalLimit.Value));
	}

	private static void Keyword(Plugin plugin, Lang lang, string[] args)
	{
		string text = ((args.Length > 1) ? args[1].ToLowerInvariant() : "list");
		List<string> list = TextUtil.ParseKeywords((args.Length > 2) ? string.Join(" ", args, 2, args.Length - 2) : null);
		List<string> list2 = TextUtil.ParseKeywords(plugin.Keywords.Value);
		switch (text)
		{
		case "add":
			if (list.Count == 0)
			{
				break;
			}
			foreach (string word2 in list)
			{
				if (!list2.Exists((string w) => string.Equals(w, word2, StringComparison.OrdinalIgnoreCase)))
				{
					list2.Add(word2);
				}
			}
			plugin.Keywords.Value = TextUtil.JoinKeywords(list2);
			GameAccess.Notify(string.Format(lang.KeywordAdded, TextUtil.JoinKeywords(list)));
			return;
		case "remove":
		case "delete":
		{
			if (list.Count == 0)
			{
				break;
			}
			int num = 0;
			foreach (string word in list)
			{
				num += list2.RemoveAll((string w) => string.Equals(w, word, StringComparison.OrdinalIgnoreCase));
			}
			if (num == 0)
			{
				GameAccess.Notify(string.Format(lang.KeywordMissing, TextUtil.JoinKeywords(list)));
				return;
			}
			plugin.Keywords.Value = TextUtil.JoinKeywords(list2);
			GameAccess.Notify(string.Format(lang.KeywordRemoved, TextUtil.JoinKeywords(list)));
			return;
		}
		case "clear":
			plugin.Keywords.Value = string.Empty;
			GameAccess.Notify(lang.KeywordsCleared);
			return;
		case "list":
			GameAccess.Notify(string.Format(lang.KeywordsList, (list2.Count > 0) ? TextUtil.JoinKeywords(list2) : lang.None));
			return;
		}
		GameAccess.Notify(lang.UsageKeyword);
	}

	private static bool TryParsePercent(string text, out int percent)
	{
		return int.TryParse((text ?? string.Empty).TrimEnd('%'), NumberStyles.Integer, CultureInfo.InvariantCulture, out percent);
	}

	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");
			if (type == null || type2 == null || type3 == null)
			{
				return;
			}
			MethodInfo method = type.GetMethod("Register", new Type[5]
			{
				typeof(string),
				typeof(string),
				typeof(Action<string[]>),
				typeof(string),
				type2.MakeArrayType()
			});
			if (!(method == 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)
				{
					method.Invoke(null, new object[5] { text, "ChatPlus", action, "Chat Plus: settings window, message time, chat size, text size, lines kept, clear, history folder", array });
				}
				Plugin.Log.LogInfo((object)"Registered /chatplus with CommandAPI.");
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not register with CommandAPI (the command still works): " + ex.Message));
		}
	}
}
internal enum ChatKind
{
	Player,
	Own,
	Notification
}
internal sealed class ChatEntry
{
	public DateTime Time;

	public bool IsLocal;

	public ChatKind Kind;

	public string SteamId = string.Empty;

	public string Name = string.Empty;

	public string Message = string.Empty;

	public string Line = string.Empty;
}
internal sealed class LineStyle
{
	public bool Timestamps = true;

	public string TimeFormat = "HH:mm";

	public string TimeColor;

	public int TimeSize = 100;

	public bool TimeOnNotifications = true;

	public string DateFormat = "dd.MM";

	public bool Highlight;

	public string HighlightColor;

	public string MyName = string.Empty;

	public IList<string> Keywords = new List<string>();
}
internal static class ChatFormat
{
	public const string DefaultTimeFormat = "HH:mm";

	private static readonly CultureInfo Invariant = CultureInfo.InvariantCulture;

	public static string Compose(ChatEntry entry, LineStyle style, DateTime now)
	{
		string text = entry.Line ?? string.Empty;
		if (style == null)
		{
			return text;
		}
		if (style.Highlight && style.HighlightColor != null && entry.Kind == ChatKind.Player && TextUtil.IsMention(entry.Message, style.MyName, style.Keywords))
		{
			text = "<mark=" + style.HighlightColor + ">" + text + "</mark>";
		}
		if (style.Timestamps && (entry.Kind != ChatKind.Notification || style.TimeOnNotifications))
		{
			text = Stamp(entry.Time, now, style) + text;
		}
		return text;
	}

	public static string Stamp(DateTime time, DateTime now, LineStyle style)
	{
		string text = FormatTime(time, style.TimeFormat);
		if (time.Date != now.Date)
		{
			text = FormatDate(time, style.DateFormat) + " " + text;
		}
		bool num = !string.IsNullOrEmpty(style.TimeColor);
		bool flag = style.TimeSize > 0 && style.TimeSize != 100;
		bool flag2 = text.IndexOf('<') >= 0 || text.IndexOf('>') >= 0;
		StringBuilder stringBuilder = new StringBuilder(text.Length + 48);
		if (num)
		{
			stringBuilder.Append("<color=").Append(style.TimeColor).Append('>');
		}
		if (flag)
		{
			stringBuilder.Append("<size=").Append(style.TimeSize.ToString(Invariant)).Append("%>");
		}
		if (flag2)
		{
			stringBuilder.Append("<noparse>");
		}
		stringBuilder.Append(text);
		if (flag2)
		{
			stringBuilder.Append("</noparse>");
		}
		if (flag)
		{
			stringBuilder.Append("</size>");
		}
		if (num)
		{
			stringBuilder.Append("</color>");
		}
		return stringBuilder.Append(' ').ToString();
	}

	public static string FormatTime(DateTime time, string format)
	{
		if (string.IsNullOrEmpty(format))
		{
			format = "HH:mm";
		}
		try
		{
			return time.ToString(format, Invariant);
		}
		catch (FormatException)
		{
			return time.ToString("HH:mm", Invariant);
		}
	}

	private static string FormatDate(DateTime time, string format)
	{
		try
		{
			return time.ToString(string.IsNullOrEmpty(format) ? "dd.MM" : format, Invariant);
		}
		catch (FormatException)
		{
			return time.ToString("dd.MM", Invariant);
		}
	}

	public static string CopyText(ChatEntry entry)
	{
		return TextUtil.StripTags(entry.Message).Trim();
	}

	public static bool TryParseColor(string value, out string normalized)
	{
		normalized = null;
		if (string.IsNullOrEmpty(value))
		{
			return false;
		}
		string text = value.Trim();
		if (text.StartsWith("#", StringComparison.Ordinal))
		{
			text = text.Substring(1);
		}
		if (text.Length != 3 && text.Length != 4 && text.Length != 6 && text.Length != 8)
		{
			return false;
		}
		string text2 = text;
		for (int i = 0; i < text2.Length; i++)
		{
			if (!Uri.IsHexDigit(text2[i]))
			{
				return false;
			}
		}
		if (text.Length <= 4)
		{
			StringBuilder stringBuilder = new StringBuilder(text.Length * 2);
			text2 = text;
			foreach (char value2 in text2)
			{
				stringBuilder.Append(value2).Append(value2);
			}
			text = stringBuilder.ToString();
		}
		normalized = "#" + text.ToUpperInvariant();
		return true;
	}

	public static string WithAlpha(string normalized, byte alpha)
	{
		if (string.IsNullOrEmpty(normalized) || normalized.Length < 7)
		{
			return normalized;
		}
		return normalized.Substring(0, 7) + alpha.ToString("X2", Invariant);
	}
}
internal sealed class ChatHistory
{
	public const string FileName = "chat-history.tsv";

	public const string PreviousFileName = "chat-history.previous.tsv";

	public const string LogFolderName = "logs";

	private const string NewLine = "\r\n";

	private static readonly Encoding Utf8Bom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: true);

	private static readonly Encoding Utf8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);

	private readonly List<ChatEntry> _entries = new List<ChatEntry>();

	private readonly int _capacity;

	private readonly Action<string> _warn;

	private bool _saving;

	private bool _fileBehind;

	private string _lastError;

	public string Folder { get; }

	public string FilePath => Path.Combine(Folder, "chat-history.tsv");

	public string LogFolder => Path.Combine(Folder, "logs");

	public int Count => _entries.Count;

	public bool Saving => _saving;

	public bool DailyLogs { get; set; }

	public ChatHistory(string folder, int capacity, Action<string> warn)
	{
		Folder = folder;
		_capacity = Math.Max(1, capacity);
		_warn = warn;
	}

	public void Open(bool keepPrevious, bool saving)
	{
		_saving = saving;
		if (keepPrevious)
		{
			Load();
		}
		else
		{
			ArchivePrevious();
		}
	}

	public void Add(ChatEntry entry)
	{
		if (entry == null)
		{
			return;
		}
		_entries.Add(entry);
		if (_entries.Count > _capacity)
		{
			_entries.RemoveRange(0, _entries.Count - _capacity);
		}
		if (_saving)
		{
			if (_fileBehind)
			{
				Rewrite();
			}
			else
			{
				Append(entry);
			}
		}
		if (DailyLogs)
		{
			AppendDailyLog(entry);
		}
	}

	public List<ChatEntry> Snapshot()
	{
		return new List<ChatEntry>(_entries);
	}

	public void SetSaving(bool saving)
	{
		if (saving != _saving)
		{
			_saving = saving;
			if (saving)
			{
				Rewrite();
			}
		}
	}

	public void Clear()
	{
		_entries.Clear();
		if (_saving || File.Exists(FilePath))
		{
			Rewrite();
		}
	}

	private void Load()
	{
		string filePath = FilePath;
		if (!File.Exists(filePath))
		{
			return;
		}
		string[] array;
		try
		{
			array = File.ReadAllLines(filePath, Utf8);
		}
		catch (Exception ex)
		{
			Warn("Could not read the chat history: " + ex.Message);
			return;
		}
		int num = 0;
		string[] array2 = array;
		foreach (string text in array2)
		{
			if (text.Length != 0 && !text.StartsWith("time\t", StringComparison.Ordinal))
			{
				num++;
				if (HistoryFormat.TryParse(text, out var entry))
				{
					_entries.Add(entry);
				}
			}
		}
		if (_entries.Count > _capacity)
		{
			_entries.RemoveRange(0, _entries.Count - _capacity);
		}
		if (_saving && num != _entries.Count)
		{
			Rewrite();
		}
	}

	private void ArchivePrevious()
	{
		string filePath = FilePath;
		try
		{
			if (File.Exists(filePath))
			{
				string text = Path.Combine(Folder, "chat-history.previous.tsv");
				if (File.Exists(text))
				{
					File.Delete(text);
				}
				File.Move(filePath, text);
			}
		}
		catch (Exception ex)
		{
			Warn("Could not move the old chat history aside: " + ex.Message);
			Rewrite();
		}
	}

	private void Append(ChatEntry entry)
	{
		try
		{
			string filePath = FilePath;
			if (!File.Exists(filePath))
			{
				Directory.CreateDirectory(Folder);
				File.WriteAllText(filePath, "time\tchannel\ttype\tsteam_id\tname\tmessage\tline\r\n", Utf8Bom);
			}
			File.AppendAllText(filePath, HistoryFormat.ToRecord(entry) + "\r\n", Utf8);
			_lastError = null;
		}
		catch (Exception ex)
		{
			_fileBehind = true;
			Warn("Could not write the chat history, will try again with the next message: " + ex.Message);
		}
	}

	private void Rewrite()
	{
		string filePath = FilePath;
		string text = filePath + ".tmp";
		try
		{
			Directory.CreateDirectory(Folder);
			StringBuilder stringBuilder = new StringBuilder("time\tchannel\ttype\tsteam_id\tname\tmessage\tline".Length + 2 + _entries.Count * 96);
			stringBuilder.Append("time\tchannel\ttype\tsteam_id\tname\tmessage\tline").Append("\r\n");
			foreach (ChatEntry entry in _entries)
			{
				stringBuilder.Append(HistoryFormat.ToRecord(entry)).Append("\r\n");
			}
			File.WriteAllText(text, stringBuilder.ToString(), Utf8Bom);
			if (File.Exists(filePath))
			{
				File.Delete(filePath);
			}
			File.Move(text, filePath);
			_fileBehind = false;
			_lastError = null;
		}
		catch (Exception ex)
		{
			_fileBehind = true;
			Warn("Could not write the chat history, will try again with the next message: " + ex.Message);
			try
			{
				if (File.Exists(text))
				{
					File.Delete(text);
				}
			}
			catch (Exception)
			{
			}
		}
	}

	private void AppendDailyLog(ChatEntry entry)
	{
		try
		{
			string logFolder = LogFolder;
			string path = Path.Combine(logFolder, entry.Time.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
			if (!File.Exists(path))
			{
				Directory.CreateDirectory(logFolder);
				File.WriteAllText(path, string.Empty, Utf8Bom);
			}
			File.AppendAllText(path, HistoryFormat.ToReadable(entry) + "\r\n", Utf8);
		}
		catch (Exception ex)
		{
			Warn("Could not write the chat log: " + ex.Message);
		}
	}

	private void Warn(string message)
	{
		if (!(message == _lastError))
		{
			_lastError = message;
			_warn?.Invoke(message);
		}
	}
}
internal sealed class ChatLine : MonoBehaviour, IPointerClickHandler, IEventSystemHandler, IPointerDownHandler, IInitializePotentialDragHandler, IBeginDragHandler, IDragHandler, IEndDragHandler
{
	internal ChatEntry Entry;

	private TMP_Text _text;

	private ScrollRect _scroll;

	private bool _selecting;

	private PointerEventData _dragEvent;

	internal static ChatLine MakeSelectable(TMP_Text text)
	{
		ChatLine obj = ((Component)text).GetComponent<ChatLine>() ?? ((Component)text).gameObject.AddComponent<ChatLine>();
		obj._text = text;
		((Graphic)text).raycastTarget = true;
		return obj;
	}

	internal static ChatLine Attach(TMP_Text text, ChatEntry entry)
	{
		ChatLine chatLine = MakeSelectable(text);
		chatLine.Entry = entry;
		chatLine.Render(ChatLines.Style, DateTime.Now);
		LineSizer.Apply(text);
		return chatLine;
	}

	internal void Render(LineStyle style, DateTime now)
	{
		if (!((Object)(object)_text == (Object)null) && Entry != null)
		{
			string text = ChatFormat.Compose(Entry, style, now);
			if (!string.Equals(_text.text, text, StringComparison.Ordinal))
			{
				_text.text = text;
			}
		}
	}

	public void OnPointerClick(PointerEventData eventData)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Invalid comparison between Unknown and I4
		if (eventData == null || (int)eventData.button != 1)
		{
			return;
		}
		Plugin instance = Plugin.Instance;
		if (!((Object)(object)instance == (Object)null) && instance.RightClickCopy.Value && (!ChatSelection.Contains(_text) || !ChatSelection.Copy()) && Entry != null)
		{
			string text = ChatFormat.CopyText(Entry);
			if (text.Length != 0)
			{
				GUIUtility.systemCopyBuffer = text;
				Toast.Show(Lang.Current.Copied);
			}
		}
	}

	public void OnPointerDown(PointerEventData eventData)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		if (eventData != null && (int)eventData.button == 0)
		{
			StopDrag();
			_scroll = ((Component)this).GetComponentInParent<ScrollRect>();
			_selecting = ChatSelection.Enabled && IsMousePointer(eventData) && (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303));
			if (_selecting)
			{
				ChatSelection.Begin(_text, eventData);
			}
			else
			{
				ChatSelection.Clear();
			}
		}
	}

	internal static bool IsMousePointer(PointerEventData pointer)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Invalid comparison between Unknown and I4
		ExtendedPointerEventData val = (ExtendedPointerEventData)(object)((pointer is ExtendedPointerEventData) ? pointer : null);
		if (val != null)
		{
			return (int)val.pointerType == 1;
		}
		return pointer.pointerId < 0;
	}

	public void OnInitializePotentialDrag(PointerEventData eventData)
	{
		if ((Object)(object)_scroll == (Object)null)
		{
			_scroll = ((Component)this).GetComponentInParent<ScrollRect>();
		}
		ScrollRect scroll = _scroll;
		if (scroll != null)
		{
			scroll.OnInitializePotentialDrag(eventData);
		}
	}

	public void OnBeginDrag(PointerEventData eventData)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		if (eventData == null || (int)eventData.button != 0)
		{
			return;
		}
		eventData.eligibleForClick = false;
		_dragEvent = eventData;
		_selecting = _selecting && ChatSelection.BeginDrag(_text, eventData);
		if (!_selecting)
		{
			ScrollRect scroll = _scroll;
			if (scroll != null)
			{
				scroll.OnBeginDrag(eventData);
			}
		}
	}

	public void OnDrag(PointerEventData eventData)
	{
		if (_dragEvent == null)
		{
			return;
		}
		if (_selecting)
		{
			ChatSelection.Drag(eventData);
			return;
		}
		ScrollRect scroll = _scroll;
		if (scroll != null)
		{
			scroll.OnDrag(eventData);
		}
	}

	public void OnEndDrag(PointerEventData eventData)
	{
		if (_dragEvent != null)
		{
			_dragEvent = eventData;
			StopDrag();
		}
	}

	private void StopDrag()
	{
		if (_dragEvent != null)
		{
			if (_selecting)
			{
				ChatSelection.EndDrag(_dragEvent);
			}
			else
			{
				ScrollRect scroll = _scroll;
				if (scroll != null)
				{
					scroll.OnEndDrag(_dragEvent);
				}
			}
		}
		_dragEvent = null;
		_selecting = false;
		_scroll = null;
	}

	private void OnDisable()
	{
		if (!OutlineResets.Resetting)
		{
			bool selecting = _selecting;
			StopDrag();
			if (selecting)
			{
				ChatSelection.Clear();
			}
		}
	}
}
internal static class ChatLines
{
	internal static bool Suppress;

	internal static int StyleVersion;

	private static LineStyle _style;

	private static int _builtVersion = -1;

	private static string _builtName;

	private static Lang _builtLang;

	internal static LineStyle Style
	{
		get
		{
			string localPlayerName = GameAccess.LocalPlayerName;
			Lang current = Lang.Current;
			if (_style == null || _builtVersion != StyleVersion || localPlayerName != _builtName || current != _builtLang)
			{
				_style = Plugin.Instance.BuildStyle(localPlayerName, current);
				_builtVersion = StyleVersion;
				_builtName = localPlayerName;
				_builtLang = current;
			}
			return _style;
		}
	}

	internal static void ApplyLimits()
	{
		Plugin instance = Plugin.Instance;
		if ((Object)(object)instance != (Object)null)
		{
			GameAccess.SetLineLimits(instance.GlobalLimit.Value, instance.LocalLimit.Value);
		}
	}

	internal static void Trim(List<GameObject> lines, int limit)
	{
		if (lines == null)
		{
			return;
		}
		limit = Math.Max(1, limit);
		while (lines.Count > limit)
		{
			GameObject val = lines[0];
			lines.RemoveAt(0);
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
		}
	}

	private static int Limit(bool isLocal)
	{
		Plugin instance = Plugin.Instance;
		if (!isLocal)
		{
			return instance.GlobalLimit.Value;
		}
		return instance.LocalLimit.Value;
	}

	internal static void OnMessageAdded(TextChannelManager chat, string userName, string text, bool isLocal, int senderIndex, bool own, LineMark mark)
	{
		List<GameObject> lines = GameAccess.Lines(chat, isLocal);
		TMP_Text val = FindNewLine(lines, mark);
		if (!((Object)(object)val == (Object)null))
		{
			HiddenChatNotifications.MessageAdded(chat, isLocal, own);
			ChatEntry entry = new ChatEntry
			{
				Time = DateTime.Now,
				IsLocal = isLocal,
				Kind = (own ? ChatKind.Own : ChatKind.Player),
				SteamId = (own ? GameAccess.OwnSteamId(chat) : GameAccess.SteamIdAt(senderIndex)),
				Name = (userName ?? string.Empty),
				Message = (text ?? string.Empty),
				Line = (val.text ?? string.Empty)
			};
			ChatLine.Attach(val, entry);
			Plugin.Instance.History.Add(entry);
			Trim(lines, Limit(isLocal));
		}
	}

	internal static void OnNotificationAdded(TextChannelManager chat, string text, LineMark mark)
	{
		List<GameObject> lines = GameAccess.Lines(chat, isLocal: false);
		TMP_Text val = FindNewLine(lines, mark);
		if (!((Object)(object)val == (Object)null))
		{
			ChatEntry entry = new ChatEntry
			{
				Time = DateTime.Now,
				IsLocal = false,
				Kind = ChatKind.Notification,
				Message = (text ?? string.Empty),
				Line = (val.text ?? string.Empty)
			};
			ChatLine.Attach(val, entry);
			if (!Suppress)
			{
				Plugin.Instance.History.Add(entry);
			}
			Trim(lines, Limit(isLocal: false));
		}
	}

	private static TMP_Text FindNewLine(List<GameObject> lines, LineMark mark)
	{
		if (lines == null || lines.Count == 0)
		{
			return null;
		}
		int num = ((mark != null) ? Math.Max(0, lines.Count - 8) : (lines.Count - 1));
		for (int num2 = lines.Count - 1; num2 >= num; num2--)
		{
			GameObject val = lines[num2];
			if (mark != null && val == mark.Newest)
			{
				return null;
			}
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.GetComponent<ChatLine>() != (Object)null))
			{
				return val.GetComponent<TMP_Text>();
			}
		}
		return null;
	}

	internal static void OnChatStarted(TextChannelManager chat)
	{
		GameAccess.SetChat(chat);
		ApplyLimits();
		TMP_Text val = GameAccess.TextPrefab(chat);
		if ((Object)(object)val != (Object)null && val.fontSize > 1f)
		{
			LineSizer.BaseSize = val.fontSize;
		}
		Plugin instance = Plugin.Instance;
		if (!instance.RestoreHistory.Value)
		{
			return;
		}
		List<ChatEntry> list = instance.History.Snapshot();
		if (list.Count != 0)
		{
			UIManager ui = GameAccess.FindUI();
			int num = Restore(chat, ui, val, list, isLocal: false, instance.RestoreNotifications.Value) + Restore(chat, ui, val, list, isLocal: true, notifications: false);
			if (num > 0)
			{
				Plugin.Log.LogInfo((object)$"Restored {num} chat lines from earlier in this session.");
			}
		}
	}

	private static int Restore(TextChannelManager chat, UIManager ui, TMP_Text prefab, List<ChatEntry> entries, bool isLocal, bool notifications)
	{
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Expected O, but got Unknown
		Transform val = GameAccess.Content(ui, isLocal);
		List<GameObject> list = GameAccess.Lines(chat, isLocal);
		if ((Object)(object)val == (Object)null || list == null || (Object)(object)prefab == (Object)null)
		{
			return 0;
		}
		HashSet<ChatEntry> hashSet = new HashSet<ChatEntry>();
		foreach (GameObject item in list)
		{
			ChatLine chatLine = (((Object)(object)item != (Object)null) ? item.GetComponent<ChatLine>() : null);
			if ((Object)(object)chatLine != (Object)null && chatLine.Entry != null)
			{
				hashSet.Add(chatLine.Entry);
			}
		}
		int num = Limit(isLocal) - 1;
		List<ChatEntry> list2 = new List<ChatEntry>();
		int num2 = entries.Count - 1;
		while (num2 >= 0 && list2.Count < num)
		{
			ChatEntry chatEntry = entries[num2];
			if (chatEntry.IsLocal == isLocal && !hashSet.Contains(chatEntry) && (chatEntry.Kind != ChatKind.Notification || notifications) && (chatEntry.Kind != ChatKind.Player || !GameAccess.IsBlocked(chatEntry.SteamId)))
			{
				list2.Add(chatEntry);
			}
			num2--;
		}
		if (list2.Count == 0)
		{
			return 0;
		}
		list2.Reverse();
		int num3 = 0;
		foreach (ChatEntry item2 in list2)
		{
			TMP_Text val2 = CreateLine(prefab, val, item2.Line);
			Button component = ((Component)val2).GetComponent<Button>();
			if ((Object)(object)component != (Object)null)
			{
				if (item2.Kind == ChatKind.Notification)
				{
					((Selectable)component).interactable = false;
				}
				else if (item2.Kind == ChatKind.Player && !string.IsNullOrEmpty(item2.SteamId))
				{
					string name = item2.Name;
					string steamId = item2.SteamId;
					((UnityEvent)component.onClick).AddListener((UnityAction)delegate
					{
						GameAccess.OpenIdCard(name, steamId);
					});
				}
			}
			ChatLine.Attach(val2, item2);
			val2.transform.SetSiblingIndex(num3);
			list.Insert(num3, ((Component)val2).gameObject);
			num3++;
		}
		TMP_Text val3 = CreateLine(prefab, val, Lang.Current.EarlierMessages);
		Button component2 = ((Component)val3).GetComponent<Button>();
		if ((Object)(object)component2 != (Object)null)
		{
			((Selectable)component2).interactable = false;
		}
		LineSizer.Apply(val3);
		val3.transform.SetSiblingIndex(num3);
		list.Insert(num3, ((Component)val3).gameObject);
		Trim(list, Limit(isLocal));
		return list2.Count;
	}

	private static TMP_Text CreateLine(TMP_Text prefab, Transform parent, string text)
	{
		TMP_Text obj = Object.Instantiate<TMP_Text>(prefab, parent);
		obj.text = text ?? string.Empty;
		return obj;
	}

	internal static void RenderAll()
	{
		ChatSelection.Clear();
		UIManager uI = GameAccess.UI;
		if ((Object)(object)uI == (Object)null)
		{
			return;
		}
		LineStyle style = Style;
		DateTime now = DateTime.Now;
		for (int i = 0; i < 2; i++)
		{
			Transform val = GameAccess.Content(uI, i == 1);
			if (!((Object)(object)val == (Object)null))
			{
				ChatLine[] componentsInChildren = ((Component)val).GetComponentsInChildren<ChatLine>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					componentsInChildren[j].Render(style, now);
				}
			}
		}
	}

	internal static int Clear()
	{
		ChatSelection.Clear();
		TextChannelManager chat = GameAccess.Chat;
		int num = 0;
		for (int i = 0; i < 2; i++)
		{
			List<GameObject> list = GameAccess.Lines(chat, i == 1);
			if (list == null)
			{
				continue;
			}
			foreach (GameObject item in list)
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)item);
					num++;
				}
			}
			list.Clear();
		}
		return num;
	}
}
internal static class ChatSelection
{
	private static TMP_Text _anchor;

	private static TMP_Text _caret;

	private static int _anchorIndex;

	private static int _caretIndex;

	private static Transform _content;

	private static Camera _camera;

	private static UIManager _heldUi;

	private static ScrollRect _scroll;

	private static bool _dragging;

	private static bool _isLocal;

	private static int _startedFrame;

	private static readonly Dictionary<TMP_Text, SelectionHighlight> Highlights = new Dictionary<TMP_Text, SelectionHighlight>();

	internal static bool Enabled
	{
		get
		{
			if ((Object)(object)Plugin.Instance != (Object)null)
			{
				return Plugin.Instance.SelectText.Value;
			}
			return false;
		}
	}

	internal static bool HasSelection
	{
		get
		{
			if ((Object)(object)_anchor != (Object)null && (Object)(object)_caret != (Object)null)
			{
				if (!((Object)(object)_anchor != (Object)(object)_caret))
				{
					return _anchorIndex != _caretIndex;
				}
				return true;
			}
			return false;
		}
	}

	internal static void Begin(TMP_Text text, PointerEventData pointer)
	{
		//IL_0011: 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)
		if (Enabled && !((Object)(object)text == (Object)null) && (int)pointer.button == 0)
		{
			Clear();
			if (GameAccess.IsAnyTextFieldFocused() && (Object)(object)EventSystem.current != (Object)null)
			{
				EventSystem.current.SetSelectedGameObject((GameObject)null);
			}
			_anchor = (_caret = text);
			_startedFrame = Time.frameCount;
			_content = text.transform.parent;
			_isLocal = (Object)(object)_content == (Object)(object)GameAccess.Content(GameAccess.UI, isLocal: true);
			_camera = pointer.pressEventCamera;
			_anchorIndex = (_caretIndex = Boundary(text, pointer.position));
			_scroll = ((Component)text).GetComponentInParent<ScrollRect>();
		}
	}

	internal static bool BeginDrag(TMP_Text text, PointerEventData pointer)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		if (!Enabled || (Object)(object)text != (Object)(object)_anchor || (int)pointer.button != 0)
		{
			return false;
		}
		_dragging = true;
		pointer.eligibleForClick = false;
		if ((Object)(object)_scroll != (Object)null)
		{
			_scroll.StopMovement();
		}
		if ((Object)(object)EventSystem.current != (Object)null)
		{
			EventSystem.current.SetSelectedGameObject((GameObject)null);
		}
		_heldUi = GameAccess.UI;
		GameAccess.SetPanelHeld(_heldUi, held: true);
		Drag(pointer);
		return true;
	}

	internal static void Drag(PointerEventData pointer)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		if (_dragging)
		{
			MoveCaret(pointer.position);
		}
	}

	internal static void EndDrag(PointerEventData pointer)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		if (_dragging)
		{
			MoveCaret(pointer.position);
			ReleaseDrag();
		}
	}

	private static void ReleaseDrag()
	{
		_dragging = false;
		GameAccess.SetPanelHeld(_heldUi, held: false);
		_heldUi = null;
	}

	internal static void Tick(bool settingsOpen)
	{
		if ((Object)(object)_anchor == (Object)null)
		{
			if ((Object)(object)_content != (Object)null || Highlights.Count > 0)
			{
				Clear();
			}
			return;
		}
		UIManager uI = GameAccess.UI;
		if (!Enabled || settingsOpen || (Object)(object)uI == (Object)null || uI.IsMessagePanelHidden || !((Component)_anchor).gameObject.activeInHierarchy || (Object)(object)_content != (Object)(object)GameAccess.Content(uI, _isLocal) || (Object)(object)GameAccess.Chat == (Object)null || GameAccess.Chat.Islocal != _isLocal || (Object)(object)_caret == (Object)null || GameAccess.IsAnyTextFieldFocused() || Input.GetKeyDown((KeyCode)27) || (Input.GetMouseButtonDown(0) && Time.frameCount != _startedFrame))
		{
			Clear();
		}
		else if (HasSelection && Input.GetKeyDown((KeyCode)99) && (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305)))
		{
			Copy();
		}
	}

	internal static void LateTick()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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)
		if ((Object)(object)_anchor == (Object)null || (Object)(object)_caret == (Object)null)
		{
			return;
		}
		if (_dragging)
		{
			if (!Input.GetMouseButton(0))
			{
				ReleaseDrag();
			}
			else
			{
				AutoScroll(Vector2.op_Implicit(Input.mousePosition));
				MoveCaret(Vector2.op_Implicit(Input.mousePosition));
			}
		}
		RefreshHighlights();
	}

	private static void AutoScroll(Vector2 point)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = default(Vector2);
		if (!((Object)(object)_scroll == (Object)null) && !((Object)(object)_scroll.viewport == (Object)null) && RectTransformUtility.ScreenPointToLocalPointInRectangle(_scroll.viewport, point, _camera, ref val))
		{
			Rect rect = _scroll.viewport.rect;
			float num = ((val.y > ((Rect)(ref rect)).yMax) ? 1f : ((val.y < ((Rect)(ref rect)).yMin) ? (-1f) : 0f));
			float num2;
			if (!((Object)(object)_scroll.content != (Object)null))
			{
				num2 = 0f;
			}
			else
			{
				Rect rect2 = _scroll.content.rect;
				num2 = ((Rect)(ref rect2)).height - ((Rect)(ref rect)).height;
			}
			float num3 = num2;
			if (num != 0f && num3 > 0f)
			{
				_scroll.verticalNormalizedPosition = Mathf.Clamp01(_scroll.verticalNormalizedPosition + num * Time.unscaledDeltaTime * ((Rect)(ref rect)).height / num3);
			}
		}
	}

	private static void MoveCaret(Vector2 point)
	{
		//IL_00c6: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_content == (Object)null)
		{
			return;
		}
		TMP_Text val = null;
		float num = float.MaxValue;
		Vector2 val2 = default(Vector2);
		for (int i = 0; i < _content.childCount; i++)
		{
			TMP_Text component = ((Component)_content.GetChild(i)).GetComponent<TMP_Text>();
			if (!((Object)(object)component == (Object)null) && ((Component)component).gameObject.activeInHierarchy && RectTransformUtility.ScreenPointToLocalPointInRectangle(component.rectTransform, point, _camera, ref val2))
			{
				Rect rect = component.rectTransform.rect;
				float num2 = Mathf.Max(new float[3]
				{
					((Rect)(ref rect)).yMin - val2.y,
					val2.y - ((Rect)(ref rect)).yMax,
					0f
				});
				if (num2 < num)
				{
					num = num2;
					val = component;
				}
			}
		}
		if (!((Object)(object)val == (Object)null))
		{
			_caret = val;
			_caretIndex = Boundary(val, point);
		}
	}

	private static void PrepareText(TMP_Text text)
	{
		if (text.havePropertiesChanged || text.textInfo.characterCount == 0)
		{
			text.ForceMeshUpdate(false, false);
		}
	}

	private static int Boundary(TMP_Text text, Vector2 point)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		PrepareText(text);
		int characterCount = text.textInfo.characterCount;
		if (characterCount == 0)
		{
			return 0;
		}
		int num = TMP_TextUtilities.FindNearestCharacter(text, Vector2.op_Implicit(point), _camera, false);
		num = Mathf.Clamp(num, 0, characterCount - 1);
		TMP_CharacterInfo val = text.textInfo.characterInfo[num];
		Vector2 val2 = default(Vector2);
		if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(text.rectTransform, point, _camera, ref val2))
		{
			return num;
		}
		TMP_LineInfo val3 = text.textInfo.lineInfo[0];
		TMP_LineInfo val4 = text.textInfo.lineInfo[text.textInfo.lineCount - 1];
		if (val2.y > val3.ascender)
		{
			return 0;
		}
		if (val2.y < val4.descender)
		{
			return characterCount;
		}
		if (!(val2.x < (val.origin + val.xAdvance) * 0.5f))
		{
			return num + 1;
		}
		return num;
	}

	private static void Ordered(out TMP_Text first, out int start, out TMP_Text last, out int end)
	{
		bool flag = _anchor.transform.GetSiblingIndex() < _caret.transform.GetSiblingIndex() || ((Object)(object)_anchor == (Object)(object)_caret && _anchorIndex <= _caretIndex);
		first = (flag ? _anchor : _caret);
		start = (flag ? _anchorIndex : _caretIndex);
		last = (flag ? _caret : _anchor);
		end = (flag ? _caretIndex : _anchorIndex);
	}

	private static void RefreshHighlights()
	{
		if (!HasSelection || (Object)(object)_content == (Object)null)
		{
			foreach (SelectionHighlight value2 in Highlights.Values)
			{
				if ((Object)(object)value2 != (Object)null)
				{
					value2.Show(0, 0);
				}
			}
			return;
		}
		Ordered(out var first, out var start, out var last, out var end);
		foreach (KeyValuePair<TMP_Text, SelectionHighlight> highlight in Highlights)
		{
			if ((Object)(object)highlight.Value != (Object)null && ((Object)(object)highlight.Key == (Object)null || highlight.Key.transform.GetSiblingIndex() < first.transform.GetSiblingIndex() || highlight.Key.transform.GetSiblingIndex() > last.transform.GetSiblingIndex()))
			{
				highlight.Value.Show(0, 0);
			}
		}
		for (int i = first.transform.GetSiblingIndex(); i <= last.transform.GetSiblingIndex(); i++)
		{
			TMP_Text component = ((Component)_content.GetChild(i)).GetComponent<TMP_Text>();
			if (!((Object)(object)component == (Object)null))
			{
				PrepareText(component);
				int first2 = (((Object)(object)component == (Object)(object)first) ? start : 0);
				int last2 = (((Object)(object)component == (Object)(object)last) ? end : component.textInfo.characterCount);
				if (!Highlights.TryGetValue(component, out var value) || (Object)(object)value == (Object)null)
				{
					value = SelectionHighlight.Create(component);
					Highlights[component] = value;
				}
				value.Show(first2, last2);
			}
		}
	}

	internal static bool Contains(TMP_Text text)
	{
		if (!HasSelection || (Object)(object)text == (Object)null || (Object)(object)text.transform.parent != (Object)(object)_content)
		{
			return false;
		}
		Ordered(out var first, out var _, out var last, out var _);
		int siblingIndex = text.transform.GetSiblingIndex();
		if (siblingIndex >= first.transform.GetSiblingIndex())
		{
			return siblingIndex <= last.transform.GetSiblingIndex();
		}
		return false;
	}

	internal static bool Copy()
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: 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_009e: Invalid comparison between Unknown and I4
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		if (!HasSelection || (Object)(object)_content == (Object)null)
		{
			return false;
		}
		Ordered(out var first, out var start, out var last, out var end);
		StringBuilder stringBuilder = new StringBuilder();
		bool flag = false;
		for (int i = first.transform.GetSiblingIndex(); i <= last.transform.GetSiblingIndex(); i++)
		{
			TMP_Text component = ((Component)_content.GetChild(i)).GetComponent<TMP_Text>();
			if (!((Object)(object)component == (Object)null))
			{
				PrepareText(component);
				SelectionGlyph[] array = new SelectionGlyph[component.textInfo.characterCount];
				for (int j = 0; j < array.Length; j++)
				{
					TMP_CharacterInfo val = component.textInfo.characterInfo[j];
					string replacement = (((int)val.elementType == 1) ? "" : ((val.character == '\n') ? "\n" : ((val.character == '\r') ? "\r" : ((val.stringLength > 1 && val.index >= 0 && val.index < component.text.Length && component.text[val.index] == '<') ? val.character.ToString() : null))));
					array[j] = new SelectionGlyph(val.index, val.stringLength, replacement);
				}
				if (flag)
				{
					stringBuilder.AppendLine();
				}
				stringBuilder.Append(SelectionText.Slice(component.text, array, ((Object)(object)component == (Object)(object)first) ? start : 0, ((Object)(object)component == (Object)(object)last) ? end : array.Length));
				flag = true;
			}
		}
		if (stringBuilder.Length == 0)
		{
			return false;
		}
		GUIUtility.systemCopyBuffer = stringBuilder.ToString();
		Toast.Show(Lang.Current.Copied);
		return true;
	}

	internal static void Clear()
	{
		ReleaseDrag();
		foreach (SelectionHighlight value in Highlights.Values)
		{
			if ((Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
		}
		Highlights.Clear();
		_anchor = (_caret = null);
		_content = null;
		_scroll = null;
		_camera = null;
	}
}
internal static class ChatWindow
{
	private sealed class Viewport
	{
		public Mask Mask;

		public Image MaskImage;

		public RectMask2D RectMask;
	}

	private const string FrameName = "Panel_Bg";

	private const string InputBackgroundName = "ImageInputFieldBg";

	private const string MoveHandleName = "Image_Drag";

	private static readonly Vector2 FrameSpriteSize = new Vector2(1644f, 1876f);

	private static readonly Vector4 FrameBorder = new Vector4(108f, 366f, 114f, 120f);

	private const float DefaultLineWidth = 697.1f;

	private const float TopMargin = 25f;

	private const float GameRightLimit = 120f;

	private const float MinWidthFactor = 0.7f;

	private const float MinHeightFactor = 0.5f;

	private const float GripSize = 46f;

	private static readonly Vector2 GripOffset = new Vector2(5f, 6f);

	private const float ReflowDelay = 0.3f;

	private static UIManager _ui;

	private static RectTransform _root;

	private static GameObject _grip;

	private static Vector2 _defaultSize;

	private static Vector2 _defaultCorner;

	private static float _rightMargin;

	private static bool _resizing;

	private static float _reflowAt = -1f;

	private static readonly List<VerticalLayoutGroup> Layouts = new List<VerticalLayoutGroup>();

	private static readonly List<Viewport> Viewports = new List<Viewport>();

	private static Texture2D _gripTexture;

	private static Sprite _gripSprite;

	private static Sprite _slicedFrame;

	private static Sprite _slicedFrameSource;

	private static ChatChrome _chrome;

	internal static bool Ready
	{
		get
		{
			if ((Object)(object)_ui != (Object)null)
			{
				return (Object)(object)_root != (Object)null;
			}
			return false;
		}
	}

	internal static Vector2 Size
	{
		get
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root != (Object)null))
			{
				return Vector2.zero;
			}
			return _root.sizeDelta;
		}
	}

	private static Vector2 Corner => _root.anchoredPosition - Vector2.Scale(_root.pivot, _root.sizeDelta);

	private static Vector2 Area
	{
		get
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Transform)_root).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if (!((Object)(object)val != (Object)null))
			{
				return Vector2.zero;
			}
			Rect rect = val.rect;
			return ((Rect)(ref rect)).size;
		}
	}

	internal static void Prepare(UIManager ui)
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: 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)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_036e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: 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_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_03db: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: 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_044d: Unknown result type (might be due to invalid IL or missing references)
		GameAccess.SetUI(ui);
		RectTransform val = GameAccess.PanelRoot(ui);
		if ((Object)(object)val == (Object)null || ((Object)(object)ui == (Object)(object)_ui && (Object)(object)val == (Object)(object)_root))
		{
			return;
		}
		_ui = null;
		_root = null;
		_grip = null;
		_resizing = false;
		ChatSelection.Clear();
		_reflowAt = -1f;
		Layouts.Clear();
		Viewports.Clear();
		Vector2 sizeDelta = val.sizeDelta;
		RectTransform val2 = GameAccess.CornerBottomLeft(ui);
		if ((Object)(object)val2 != (Object)null)
		{
			Reanchor(val2, Vector2.zero, Vector2.zero);
		}
		GameObject val3 = GameAccess.PanelBackground(ui);
		RectTransform val4 = (RectTransform)(((Object)(object)val3 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
		if ((Object)(object)val4 != (Object)null)
		{
			Reanchor(val4, Vector2.zero, Vector2.one);
			Transform obj = ((Transform)val4).Find("Panel_Bg");
			RectTransform val5 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			if ((Object)(object)val5 != (Object)null)
			{
				SliceFrame(((Component)val5).GetComponent<Image>());
				BackgroundOpacity.Attach(((Component)val5).GetComponent<Image>());
				Reanchor(val5, Vector2.zero, Vector2.one);
			}
			Transform obj2 = ((Transform)val4).Find("ImageInputFieldBg");
			RectTransform val6 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
			if ((Object)(object)val6 != (Object)null)
			{
				BackgroundOpacity.Attach(((Component)val6).GetComponent<Image>());
				Reanchor(val6, Vector2.zero, new Vector2(1f, 0f));
			}
			Transform obj3 = ((Transform)val4).Find("Image_Drag");
			RectTransform val7 = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null);
			if ((Object)(object)val7 != (Object)null)
			{
				Reanchor(val7, new Vector2(1f, 0f), new Vector2(1f, 0f));
			}
			CreateGrip(ui, val4);
		}
		Transform val8 = GameAccess.GlobalScroll(ui);
		Transform val9 = GameAccess.LocalScroll(ui);
		RectTransform val10 = (RectTransform)(object)((val8 is RectTransform) ? val8 : null);
		if (val10 != null)
		{
			Reanchor(val10, Vector2.zero, Vector2.one);
		}
		RectTransform val11 = (RectTransform)(object)((val9 is RectTransform) ? val9 : null);
		if (val11 != null)
		{
			Reanchor(val11, Vector2.zero, Vector2.one);
		}
		TMP_InputField messageInput = ui.MessageInput;
		if ((Object)(object)messageInput != (Object)null)
		{
			Transform transform = ((Component)messageInput).transform;
			RectTransform val12 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if (val12 != null)
			{
				Reanchor(val12, Vector2.zero, new Vector2(1f, 0f));
			}
		}
		object obj4;
		if (!((Object)(object)val4 != (Object)null))
		{
			obj4 = null;
		}
		else
		{
			Transform obj5 = ((Transform)val4).Find("Panel_Bg");
			obj4 = ((obj5 != null) ? ((Component)obj5).GetComponent<Image>() : null);
		}
		Image frame = (Image)obj4;
		if ((Object)(object)messageInput != (Object)null)
		{
			ChatChrome.Attach(val, frame, val8, val9);
			_chrome = ((Component)val).GetComponent<ChatChrome>();
		}
		Image[] componentsInChildren = ((Component)val).GetComponentsInChildren<Image>(true);
		foreach (Image val13 in componentsInChildren)
		{
			bool flag = false;
			Transform val14 = ((Component)val13).transform;
			while ((Object)(object)val14 != (Object)null && (Object)(object)val14 != (Object)(object)val)
			{
				if (((Object)val14).name.StartsWith("ChatPlus.", StringComparison.Ordinal))
				{
					flag = true;
					break;
				}
				val14 = val14.parent;
			}
			if (!flag)
			{
				BackgroundOpacity.Attach(val13);
			}
		}
		RectTransform[] array = (RectTransform[])(object)new RectTransform[2]
		{
			GameAccess.TabButton(ui, local: false),
			GameAccess.TabButton(ui, local: true)
		};
		foreach (RectTransform val15 in array)
		{
			if ((Object)(object)val15 != (Object)null)
			{
				componentsInChildren = ((Component)val15).GetComponentsInChildren<Image>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					BackgroundOpacity.Attach(componentsInChildren[j]);
				}
			}
		}
		TMP_Text val16 = GameAccess.TextPrefab(GameAccess.FindChat());
		float lineWidth = (((Object)(object)val16 != (Object)null && val16.rectTransform.sizeDelta.x > 1f) ? val16.rectTransform.sizeDelta.x : 697.1f);
		PrepareContent(GameAccess.Content(ui, isLocal: false), lineWidth);
		PrepareContent(GameAccess.Content(ui, isLocal: true), lineWidth);
		PrepareViewport(val8);
		PrepareViewport(val9);
		ApplyCulling();
		_defaultSize = sizeDelta;
		_defaultCorner = val.anchoredPosition - Vector2.Scale(val.pivot, sizeDelta);
		_rightMargin = 120f - (1f - val.pivot.x) * sizeDelta.x;
		_ui = ui;
		_root = val;
		Plugin instance = Plugin.Instance;
		Vector2? corner = null;
		if (instance.RememberPosition.Value && TryParsePosition(instance.Position.Value, out var corner2))
		{
			corner = corner2;
		}
		Apply(corner);
	}

	internal static void Apply()
	{
		Apply(null);
	}

	private static void Apply(Vector2? corner)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		if (Ready)
		{
			Plugin instance = Plugin.Instance;
			? corner2 = ((??)corner) ?? Corner;
			Vector2 val = ClampSize(new Vector2(_defaultSize.x * (float)instance.Width.Value / 100f, _defaultSize.y * (float)instance.Height.Value / 100f));
			if (Mathf.Abs(val.x - _root.sizeDelta.x) > 0.01f)
			{
				HoldReflow();
			}
			_root.sizeDelta = val;
			SetCorner((Vector2)corner2);
			if ((Object)(object)_grip != (Object)null && _grip.activeSelf != instance.ResizeHandle.Value)
			{
				_grip.SetActive(instance.ResizeHandle.Value);
			}
		}
	}

	internal static void ApplyPosition()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		Plugin instance = Plugin.Instance;
		if (Ready && instance.RememberPosition.Value && TryParsePosition(instance.Position.Value, out var corner))
		{
			Vector2 val = corner - Corner;
			if (((Vector2)(ref val)).sqrMagnitude > 0.25f)
			{
				SetCorner(corner);
			}
		}
	}

	internal static void ApplyOpacity()
	{
		if (!Ready)
		{
			return;
		}
		BackgroundOpacity[] componentsInChildren = ((Component)_root).GetComponentsInChildren<BackgroundOpacity>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			componentsInChildren[i].Refresh();
		}
		RectTransform[] array = (RectTransform[])(object)new RectTransform[2]
		{
			GameAccess.TabButton(_ui, local: false),
			GameAccess.TabButton(_ui, local: true)
		};
		foreach (RectTransform val in array)
		{
			if ((Object)(object)val != (Object)null)
			{
				componentsInChildren = ((Component)val).GetComponentsInChildren<BackgroundOpacity>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					componentsInChildren[j].Refresh();
				}
			}
		}
	}

	internal static void Tick()
	{
		if (_reflowAt < 0f || _resizing || Time.unscaledTime < _reflowAt)
		{
			return;
		}
		_reflowAt = -1f;
		foreach (VerticalLayoutGroup layout in Layouts)
		{
			if ((Object)(object)layout != (Object)null)
			{
				((HorizontalOrVerticalLayoutGroup)layout).childControlWidth = true;
			}
		}
	}

	private static void HoldReflow()
	{
		foreach (VerticalLayoutGroup layout in Layouts)
		{
			if ((Object)(object)layout != (Object)null && ((HorizontalOrVerticalLayoutGroup)layout).childControlWidth)
			{
				((HorizontalOrVerticalLayoutGroup)layout).childControlWidth = false;
			}
		}
		_reflowAt = Time.unscaledTime + 0.3f;
	}

	internal static void OnBeginMove(UIManager ui)
	{
		if (Ready && (Object)(object)ui == (Object)(object)_ui)
		{
			UpdateDragLimits(includeRight: true);
		}
	}

	internal static void OnEndMove(UIManager ui)
	{
		if (Ready && (Object)(object)ui == (Object)(object)_ui)
		{
			SavePosition();
		}
	}

	internal static void BeginResize()
	{
		if (Ready)
		{
			_resizing = true;
			GameAccess.SetPanelHeld(_ui, held: true);
		}
	}

	internal static void ResizeTo(Vector2 size)
	{
		//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_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		if (Ready)
		{
			size = ClampSize(size);
			Plugin instance = Plugin.Instance;
			instance.Width.Value = Mathf.RoundToInt(size.x / _defaultSize.x * 100f);
			instance.Height.Value = Mathf.RoundToInt(size.y / _defaultSize.y * 100f);
		}
	}

	internal static void EndResize()
	{
		if (_resizing)
		{
			_resizing = false;
			if (_reflowAt >= 0f)
			{
				_reflowAt = Time.unscaledTime;
			}
			if (Ready)
			{
				GameAccess.SetPanelHeld(_ui, held: false);
				SavePosition();
			}
		}
	}

	internal static void ResetSize()
	{
		Plugin instance = Plugin.Instance;
		instance.Width.Value = 100;
		instance.Height.Value = 100;
	}

	internal static void ResetPosition()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		Plugin.Instance.Position.Value = string.Empty;
		if (Ready)
		{
			SetCorner(_defaultCorner);
		}
	}

	internal static void ApplyCulling()
	{
		bool value = Plugin.Instance.CullHiddenLines.Value;
		foreach (Viewport viewport in Viewports)
		{
			if ((Object)(object)viewport.Mask == (Object)null || (Object)(object)viewport.RectMask == (Object)null)
			{
				continue;
			}
			if (value)
			{
				((Behaviour)viewport.Mask).enabled = false;
				if ((Object)(object)viewport.MaskImage != (Object)null && !viewport.Mask.showMaskGraphic)
				{
					((Behaviour)viewport.MaskImage).enabled = false;
				}
				((Behaviour)viewport.RectMask).enabled = true;
			}
			else
			{
				((Behaviour)viewport.RectMask).enabled = false;
				if ((Object)(object)viewport.MaskImage != (Object)null)
				{
					((Behaviour)viewport.MaskImage).enabled = true;
				}
				((Behaviour)viewport.Mask).enabled = true;
			}
		}
	}

	internal static bool TryPointer(Vector2 screenPosition, Camera camera, out Vector2 point)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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_0051: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		point = Vector2.zero;
		if (Ready)
		{
			Transform parent = ((Transform)_root).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if (val != null)
			{
				if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(val, screenPosition, camera, ref point))
				{
					return false;
				}
				Vector3 localScale = ((Transform)_root).localScale;
				if (Mathf.Abs(localScale.x) > 0.0001f && Mathf.Abs(localScale.y) > 0.0001f)
				{
					point = new Vector2(point.x / localScale.x, point.y / localScale.y);
				}
				return true;
			}
		}
		return false;
	}

	private static void SetCorner(Vector2 corner)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		Vector2 sizeDelta = _root.sizeDelta;
		_root.anchoredPosition = ClampCorner(corner, sizeDelta) + Vector2.Scale(_root.pivot, sizeDelta);
		UpdateDragLimits(includeRight: false);
	}

	private static Vector2 ClampCorner(Vector2 corner, Vector2 size)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: 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_004e: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		Vector2 area = Area;
		if (area.x < 100f || area.y < 100f)
		{
			return corner;
		}
		float num = area.x - size.x - _rightMargin;
		float num2 = area.y - 25f - size.y - _root.pivot.y * size.y;
		corner.x = Mathf.Max(_defaultCorner.x, Mathf.Min(corner.x, num));
		corner.y = Mathf.Max(_defaultCorner.y, Mathf.Min(corner.y, num2));
		return corner;
	}

	private static Vector2 ClampSize(Vector2 size)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		float num = _defaultSize.x * 0.7f;
		float num2 = _defaultSize.y * 0.5f;
		Vector2 area = Area;
		float num3 = ((area.x > 100f) ? (area.x - _defaultCorner.x - _rightMargin) : float.MaxValue);
		float num4 = ((area.y > 100f) ? ((area.y - 25f - _defaultCorner.y) / (1f + _root.pivot.y)) : float.MaxValue);
		size.x = Mathf.Clamp(size.x, num, Mathf.Max(num, num3));
		size.y = Mathf.Clamp(size.y, num2, Mathf.Max(num2, num4));
		return size;
	}

	private static void UpdateDragLimits(bool includeRight)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: 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_003f: 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_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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		Vector2 sizeDelta = _root.sizeDelta;
		Vector2 pivot = _root.pivot;
		float num = _defaultCorner.x + pivot.x * sizeDelta.x;
		float minY = _defaultCorner.y + pivot.y * sizeDelta.y;
		float? maxX = null;
		Vector2 area = Area;
		if (includeRight && area.x > 100f)
		{
			maxX = Mathf.Max(num, area.x - (1f - pivot.x) * sizeDelta.x - _rightMargin);
		}
		GameAccess.SetDragLimits(_ui, num, minY, maxX);
	}

	private static void SavePosition()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		Plugin instance = Plugin.Instance;
		if (instance.RememberPosition.Value)
		{
			Vector2 corner = Corner;
			instance.Position.Value = corner.x.ToString("0.#", CultureInfo.InvariantCulture) + ";" + corner.y.ToString("0.#", CultureInfo.InvariantCulture);
		}
	}

	internal static bool TryParsePosition(string value, out Vector2 corner)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		corner = Vector2.zero;
		if (string.IsNullOrEmpty(value))
		{
			return false;
		}
		string[] array = value.Split(';');
		if (array.Length != 2 || !float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || !float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
		{
			return false;
		}
		corner = new Vector2(result, result2);
		return true;
	}

	private static void Reanchor(RectTransform rect, Vector2 anchorMin, Vector2 anchorMax)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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_0027: 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_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_004a: 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_0051: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		Transform parent = ((Transform)rect).parent;
		RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
		if (val != null)
		{
			Rect rect2 = val.rect;
			Vector2 size = ((Rect)(ref rect2)).size;
			Vector2 val2 = Vector2.Scale(rect.anchorMin, size) + rect.offsetMin;
			Vector2 val3 = Vector2.Scale(rect.anchorMax, size) + rect.offsetMax;
			rect.anchorMin = anchorMin;
			rect.anchorMax = anchorMax;
			rect.offsetMin = val2 - Vector2.Scale(anchorMin, size);
			rect.offsetMax = val3 - Vector2.Scale(anchorMax, size);
		}
	}

	private static void PrepareContent(Transform content, float lineWidth)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		if ((Object)(object)content == (Object)null)
		{
			return;
		}
		VerticalLayoutGroup component = ((Component)content).GetComponent<VerticalLayoutGroup>();
		if ((Object)(object)component != (Object)null && !((HorizontalOrVerticalLayoutGroup)component).childControlWidth)
		{
			RectTransform val = (RectTransform)(object)((content is RectTransform) ? content : null);
			if (val != null)
			{
				Rect rect = val.rect;
				if (((Rect)(ref rect)).width > lineWidth * 0.5f)
				{
					RectOffset padding = ((LayoutGroup)component).padding;
					rect = val.rect;
					int num = Mathf.RoundToInt(((Rect)(ref rect)).width - (float)padding.left - lineWidth);
					((LayoutGroup)component).padding = new RectOffset(padding.left, num, padding.top, padding.bottom);
					((HorizontalOrVerticalLayoutGroup)component).childControlWidth = true;
					((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = true;
					Layouts.Add(component);
				}
			}
		}
		if ((Object)(object)((Component)content).GetComponent<LineSizer>() == (Object)null)
		{
			((Component)content).gameObject.AddComponent<LineSizer>();
		}
	}

	private static void PrepareViewport(Transform scroll)
	{
		ScrollRect val = (((Object)(object)scroll != (Object)null) ? ((Component)scroll).GetComponent<ScrollRect>() : null);
		RectTransform val2 = (((Object)(object)val != (Object)null) ? val.viewport : null);
		Mask val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<Mask>() : null);
		if (!((Object)(object)val3 == (Object)null))
		{
			RectMask2D val4 = ((Component)val2).GetComponent<RectMask2D>();
			if ((Object)(object)val4 == (Object)null)
			{
				val4 = ((Component)val2).gameObject.AddComponent<RectMask2D>();
				((Behaviour)val4).enabled = false;
			}
			Viewports.Add(new Viewport
			{
				Mask = val3,
				MaskImage = ((Component)val2).GetComponent<Image>(),
				RectMask = val4
			});
		}
	}

	private static void SliceFrame(Image image)
	{
		//IL_000a: 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_0030: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)image == (Object)null || (int)image.type != 0)
		{
			return;
		}
		Sprite sprite = image.sprite;
		if ((Object)(object)sprite == (Object)null || sprite.packed || sprite.border != Vector4.zero)
		{
			return;
		}
		Rect rect = sprite.rect;
		if (Mathf.Abs(((Rect)(ref rect)).width - FrameSpriteSize.x) > 0.5f || Mathf.Abs(((Rect)(ref rect)).height - FrameSpriteSize.y) > 0.5f)
		{
			return;
		}
		Rect rect2 = ((Graphic)image).rectTransform.rect;
		float width = ((Rect)(ref rect2)).width;
		float pixelsPerUnit = image.pixelsPerUnit;
		if (!(width <= 1f) && !(pixelsPerUnit <= 0f))
		{
			if ((Object)(object)_slicedFrame == (Object)null || (Object)(object)_slicedFrameSource != (Object)(object)sprite)
			{
				_slicedFrame = Sprite.Create(sprite.texture, rect, new Vector2(sprite.pivot.x / ((Rect)(ref rect)).width, sprite.pivot.y / ((Rect)(ref rect)).height), sprite.pixelsPerUnit, 0u, (SpriteMeshType)0, FrameBorder);
				((Object)_slicedFrame).name = ((Object)sprite).name + " (ChatPlus 9-slice)";
				_slicedFrameSource = sprite;
			}
			image.sprite = _slicedFrame;
			image.type = (Type)1;
			image.fillCenter = true;
			image.pixelsPerUnitMultiplier = ((Rect)(ref rect)).width / (width * pixelsPerUnit);
		}
	}

	private static void CreateGrip(UIManager ui, RectTransform background)
	{
		//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_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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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_010f: Expected O, but got Unknown
		//IL_00c2: 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)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("ChatPlus.ResizeHandle", new Type[1] { typeof(RectTransform) });
		RectTransform val2 = (RectTransform)val.transform;
		((Transform)val2).SetParent((Transform)(object)background, false);
		val2.anchorMin = Vector2.one;
		val2.anchorMax = Vector2.one;
		val2.pivot = new Vector2(0.5f, 0.5f);
		val2.sizeDelta = new Vector2(46f, 46f);
		val2.anchoredPosition = GripOffset;
		((Transform)val2).SetAsLastSibling();
		Image val3 = val.AddComponent<Image>();
		val3.sprite = GripSprite();
		BackgroundOpacity.Attach(val3);
		((Graphic)val3).raycastTarget = true;
		List<Image> list = GameAccess.PanelImages(ui);
		if (list != null)
		{
			if (list.Count > 0 && (Object)(object)list[0] != (Object)null)
			{
				Color color = ((Graphic)val3).color;
				color.a = ((Graphic)list[0]).color.a;
				((Graphic)val3).color = color;
			}
			list.Add(val3);
		}
		val.AddComponent<ResizeGrip>();
		val.SetActive(Plugin.Instance.ResizeHandle.Value);
		_grip = val;
	}

	private static Sprite GripSprite()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_gripSprite != (Object)null)
		{
			return _gripSprite;
		}
		_gripTexture = GripArt.Draw();
		_gripSprite = Sprite.Create(_gripTexture, new Rect(0f, 0f, (float)((Texture)_gripTexture).width, (float)((Texture)_gripTexture).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
		((Object)_gripSprite).name = "ChatPlus.ResizeHandle";
		return _gripSprite;
	}

	internal static void Unload()
	{
		if ((Object)(object)_chrome != (Object)null)
		{
			Object.Destroy((Object)(object)_chrome);
		}
		_chrome = null;
		if ((Object)(object)_grip != (Object)null)
		{
			Object.Destroy((Object)(object)_grip);
		}
		_grip = null;
		if ((Object)(object)_gripSprite != (Object)null)
		{
			Object.Destroy((Object)(object)_gripSprite);
		}
		if ((Object)(object)_gripTexture != (Object)null)
		{
			Object.Destroy((Object)(object)_gripTexture);
		}
		_gripSprite = null;
		_gripTexture