Decompiled source of The Editor Was Replaced v1.1.0

plugins/TheEditorWasReplaced.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using TheEditorWasReplaced.Api;
using TheEditorWasReplaced.CodeFiles;
using TheEditorWasReplaced.Core;
using TheEditorWasReplaced.Docs;
using TheEditorWasReplaced.Editor;
using TheEditorWasReplaced.Options;
using TheEditorWasReplaced.Output;
using TheEditorWasReplaced.Shared;
using TheEditorWasReplaced.Sidebar;
using TheEditorWasReplaced.Windows;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.TextCore;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("TheEditorWasReplaced")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+44eb21926d02102fe03961e9a3635f82eb72e692")]
[assembly: AssemblyProduct("The Editor Was Replaced")]
[assembly: AssemblyTitle("TheEditorWasReplaced")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TheEditorWasReplaced.Windows
{
	internal static class EditorWindows
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static OptionChangedAction <0>__onOptionChanged;
		}

		private static readonly Dictionary<string, TrackedWindow> _windows = new Dictionary<string, TrackedWindow>(StringComparer.OrdinalIgnoreCase);

		private static object _workspace;

		private static bool _optionsSubscribed;

		private static readonly Dictionary<string, bool> _savedShown = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);

		private static readonly HashSet<string> _executing = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		private static readonly List<string> _sortedKeys = new List<string>();

		private static bool _keysDirty = true;

		internal static object CurrentWorkspace => _workspace;

		internal static void Init()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if (!_optionsSubscribed)
			{
				_optionsSubscribed = true;
				object obj = <>O.<0>__onOptionChanged;
				if (obj == null)
				{
					OptionChangedAction val = onOptionChanged;
					<>O.<0>__onOptionChanged = val;
					obj = (object)val;
				}
				OptionHolder.OnOptionChanged += (OptionChangedAction)obj;
			}
		}

		public static void OnCodeWindowOpened(object workspace, string fileName)
		{
			if (workspace == null || fileName == null)
			{
				Plugin.Logger.LogWarning((object)$"OnCodeWindowOpened skipped (workspace={workspace != null}, fileName={fileName}).");
				return;
			}
			if ((Object)(object)findCodeWindow(workspace, fileName) == (Object)null)
			{
				Plugin.Logger.LogWarning((object)("OnCodeWindowOpened: no CodeWindow registered for '" + fileName + "'."));
				return;
			}
			if (_workspace != workspace)
			{
				resetForNewWorkspace(workspace);
			}
			registerUntracked(workspace);
		}

		public static void OnWindowRemoved(object window)
		{
			Component val = (Component)((window is Component) ? window : null);
			if (val != null)
			{
				pruneDestroyed();
				TrackedWindow trackedWindow = findByGameObject(val.gameObject);
				if (trackedWindow != null)
				{
					_windows.Remove(trackedWindow.Key);
					_keysDirty = true;
					Plugin.Logger.LogInfo((object)("Untracked code window '" + trackedWindow.Key + "'."));
				}
			}
		}

		public static void OnWindowRenamed(object window, string newWindowName)
		{
			Component val = (Component)((window is Component) ? window : null);
			if (val != null && newWindowName != null)
			{
				pruneDestroyed();
				TrackedWindow trackedWindow = findByGameObject(val.gameObject);
				if (trackedWindow != null)
				{
					_windows.Remove(trackedWindow.Key);
					trackedWindow.Key = newWindowName;
					_windows[newWindowName] = trackedWindow;
					_keysDirty = true;
					Plugin.Logger.LogInfo((object)("Renamed tracked window to '" + newWindowName + "'."));
				}
			}
		}

		public static bool TryHide(string key)
		{
			return setActive(key, shown: false);
		}

		public static bool TryToggle(string key)
		{
			pruneDestroyed();
			if (_windows.TryGetValue(key, out var value))
			{
				return setActive(key, !value.Shown);
			}
			return false;
		}

		public static bool IsShown(string key)
		{
			if (_windows.TryGetValue(key, out var value))
			{
				return value.Shown;
			}
			return false;
		}

		internal static List<string> SortedKeys()
		{
			if (_keysDirty)
			{
				_sortedKeys.Clear();
				_sortedKeys.AddRange(_windows.Keys);
				_sortedKeys.Sort(StringComparer.Ordinal);
				_keysDirty = false;
			}
			return _sortedKeys;
		}

		public static bool IsExecuting(string key)
		{
			return _executing.Contains(key);
		}

		public static void ApplyShown(string key, bool shown)
		{
			if (_windows.TryGetValue(key, out var value) && value.Shown != shown)
			{
				setShown(value, shown);
			}
		}

		public static void CloseAll()
		{
			pruneDestroyed();
			foreach (TrackedWindow item in _windows.Values.ToList())
			{
				setShown(item, shown: false);
			}
		}

		public static IEnumerable<KeyValuePair<string, bool>> ShownSnapshot()
		{
			pruneDestroyed();
			return _windows.Values.Select((TrackedWindow e) => new KeyValuePair<string, bool>(e.Key, e.Shown));
		}

		internal static IEnumerable<TrackedWindow> TrackedSnapshot()
		{
			return _windows.Values;
		}

		internal static TrackedWindow FindTracked(string key)
		{
			if (!_windows.TryGetValue(key, out var value))
			{
				return null;
			}
			return value;
		}

		internal static void SetLoadedShown(Dictionary<string, bool> states)
		{
			_savedShown.Clear();
			if (states == null)
			{
				return;
			}
			foreach (KeyValuePair<string, bool> state in states)
			{
				_savedShown[state.Key] = state.Value;
			}
		}

		internal static bool? SavedShownFor(string key)
		{
			if (!_savedShown.TryGetValue(key, out var value))
			{
				return null;
			}
			return value;
		}

		public static void Tick()
		{
			if (_windows.Count != 0)
			{
				pruneDestroyed();
				refreshExecuting();
				WindowTitleUi.Tick(_windows.Values);
			}
		}

		private static void refreshExecuting()
		{
			_executing.Clear();
			MainSim inst = MainSim.Inst;
			if ((Object)(object)inst == (Object)null || !inst.IsExecuting() || GameApi.IsExecuting == null)
			{
				return;
			}
			foreach (TrackedWindow value2 in _windows.Values)
			{
				object value = GameApi.IsExecuting.GetValue(value2.CodeWindow);
				if (value is bool && (bool)value)
				{
					_executing.Add(value2.Key);
				}
			}
		}

		public static void ApplyHideDefault()
		{
			pruneDestroyed();
			bool flag = !ModConfig.HideDefaultFileWindows;
			foreach (TrackedWindow value in _windows.Values)
			{
				if (value.Go.activeSelf != flag)
				{
					setShown(value, flag);
				}
			}
		}

		private static void onOptionChanged(string option)
		{
			if (option == "hide default file windows")
			{
				ApplyHideDefault();
			}
		}

		private static bool setActive(string key, bool shown)
		{
			pruneDestroyed();
			if (!_windows.TryGetValue(key, out var value))
			{
				return false;
			}
			setShown(value, shown);
			return true;
		}

		private static void setShown(TrackedWindow entry, bool shown)
		{
			entry.Go.SetActive(shown);
			entry.Shown = shown;
			if (!shown)
			{
				Plugin.Logger.LogDebug((object)("Hid code window '" + entry.Key + "'."));
			}
		}

		private static Component findCodeWindow(object workspace, string fileName)
		{
			if (!(GameApi.CodeWindows?.GetValue(workspace) is IDictionary dictionary) || !dictionary.Contains(fileName))
			{
				return null;
			}
			object? obj = dictionary[fileName];
			return (Component)((obj is Component) ? obj : null);
		}

		internal static string GetFileName(Component codeWindow)
		{
			return GameApi.FileName?.GetValue(codeWindow) as string;
		}

		private static TrackedWindow findByGameObject(GameObject go)
		{
			foreach (TrackedWindow value in _windows.Values)
			{
				if ((Object)(object)value.Go == (Object)(object)go)
				{
					return value;
				}
			}
			return null;
		}

		private static void pruneDestroyed()
		{
			List<string> list = null;
			foreach (TrackedWindow value in _windows.Values)
			{
				if ((Object)(object)value.Go == (Object)null)
				{
					(list ?? (list = new List<string>())).Add(value.Key);
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (string item in list)
			{
				_windows.Remove(item);
			}
			_keysDirty = true;
		}

		private static void resetForNewWorkspace(object workspace)
		{
			_workspace = workspace;
			_windows.Clear();
			_keysDirty = true;
			WindowTitleUi.Reset();
			Plugin.Logger.LogInfo((object)"New workspace detected; window registry reset.");
		}

		private static void registerUntracked(object workspace)
		{
			if (!(GameApi.CodeWindows?.GetValue(workspace) is IDictionary dictionary))
			{
				return;
			}
			foreach (DictionaryEntry item in dictionary)
			{
				object? value = item.Value;
				Component val = (Component)((value is Component) ? value : null);
				if (val == null || (Object)(object)val.gameObject == (Object)null)
				{
					continue;
				}
				string text = GetFileName(val) ?? (item.Key as string);
				if (text != null && !_windows.ContainsKey(text))
				{
					_windows[text] = new TrackedWindow
					{
						Key = text,
						Go = val.gameObject,
						CodeWindow = val,
						Shown = val.gameObject.activeSelf
					};
					WindowChrome.Apply(_windows[text]);
					bool flag = SavedShownFor(text) ?? (!ModConfig.HideDefaultFileWindows);
					if (val.gameObject.activeSelf != flag)
					{
						setShown(_windows[text], flag);
					}
					_keysDirty = true;
					Plugin.Logger.LogInfo((object)("Tracking code window '" + text + "'."));
				}
			}
		}
	}
	internal sealed class TrackedWindow
	{
		public Component CodeWindow;

		public GameObject Go;

		public string Key;

		public bool Shown;

		public RectTransform FileNameRect;

		public RectTransform MinimizeRect;
	}
	internal static class WindowCapturePatches
	{
		public static void OpenCodeWindowPostfix(object __instance, string fileName)
		{
			EditorWindows.OnCodeWindowOpened(__instance, fileName);
		}

		public static void RemoveWindowPostfix(object __instance, object window)
		{
			EditorWindows.OnWindowRemoved(window);
		}

		public static void RenameWindowPostfix(object __instance, object window, string newWindowName)
		{
			EditorWindows.OnWindowRenamed(window, newWindowName);
		}

		public static bool GetWorldWordRectPrefix(int start, int end, CodeWindow codeWindow, RectTransform topWindowRect)
		{
			if (!((Object)(object)codeWindow == (Object)null))
			{
				return ((Component)codeWindow).gameObject.activeInHierarchy;
			}
			return true;
		}

		public static bool GetWorldLineRectPrefix(int stringIndex, CodeWindow codeWindow, RectTransform topWindowRect)
		{
			if (!((Object)(object)codeWindow == (Object)null))
			{
				return ((Component)codeWindow).gameObject.activeInHierarchy;
			}
			return true;
		}

		public static void GetOpenWindowPostfix(ref object __result)
		{
			object obj = __result;
			Component val = (Component)((obj is Component) ? obj : null);
			if (val != null && !val.gameObject.activeInHierarchy)
			{
				__result = null;
			}
		}
	}
	internal static class WindowChrome
	{
		internal static void Apply(TrackedWindow entry)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Expected O, but got Unknown
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Expected O, but got Unknown
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			Component codeWindow = entry.CodeWindow;
			Button val = ((IEnumerable<Button>)codeWindow.GetComponentsInChildren<Button>(true)).FirstOrDefault((Func<Button, bool>)((Button b) => ((Object)b).name == "DeleteButton"));
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			RectTransform val2 = (RectTransform)((Component)val).transform;
			if ((Object)(object)((Transform)val2).parent.Find("TEWR_HideButton") != (Object)null)
			{
				return;
			}
			Transform obj = ((Transform)val2).Find("Image");
			Image val3 = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
			Rect rect;
			if ((Object)(object)val3 != (Object)null && ((Object)(object)val3.sprite == (Object)null || ((Object)val3.sprite).name != "TEWR_Trash"))
			{
				Transform obj2 = ((Component)val).transform.Find("TextTitle");
				if (obj2 != null)
				{
					((Component)obj2).gameObject.SetActive(false);
				}
				rect = ((RectTransform)((Component)val3).transform).rect;
				val3.sprite = ModIcons.TrashSprite(((Rect)(ref rect)).height);
				val3.type = (Type)0;
				val3.preserveAspect = true;
				((Graphic)val3).color = Color.white;
				((Graphic)val3).raycastTarget = false;
			}
			Vector2 anchoredPosition = val2.anchoredPosition;
			float num = val2.sizeDelta.x + 12f;
			Button val4 = ((IEnumerable<Button>)codeWindow.GetComponentsInChildren<Button>(true)).FirstOrDefault((Func<Button, bool>)((Button b) => ((Object)b).name == "MinimizeButton"));
			if ((Object)(object)val4 != (Object)null)
			{
				RectTransform val5 = (RectTransform)((Component)val4).transform;
				val5.anchoredPosition -= new Vector2(num, 0f);
			}
			val2.anchoredPosition -= new Vector2(num, 0f);
			string key = entry.Key;
			TMP_InputField componentInChildren = codeWindow.GetComponentInChildren<TMP_InputField>(true);
			if ((Object)(object)componentInChildren != (Object)null && ((Object)componentInChildren).name == "FileNameText")
			{
				componentInChildren.characterLimit = 60;
			}
			GameObject obj3 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Transform)val2).parent);
			((Object)obj3).name = "TEWR_HideButton";
			((RectTransform)obj3.transform).anchoredPosition = anchoredPosition;
			Transform obj4 = obj3.transform.Find("Image");
			Image val6 = ((obj4 != null) ? ((Component)obj4).GetComponent<Image>() : null);
			if ((Object)(object)val6 != (Object)null)
			{
				rect = ((RectTransform)((Component)val6).transform).rect;
				val6.sprite = ModIcons.XMarkSprite(((Rect)(ref rect)).height);
			}
			Button component = obj3.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener((UnityAction)delegate
			{
				EditorWindows.TryHide(key);
			});
			ColoredButton component2 = obj3.GetComponent<ColoredButton>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.SetTooltipDescription("button_tooltip_close_docs");
			}
		}
	}
	internal static class WindowTitleUi
	{
		private sealed class TitleUi
		{
			public TMP_Text Label;

			public TMP_InputField EditField;

			public bool Editing;
		}

		private static readonly Dictionary<int, TitleUi> _titles = new Dictionary<int, TitleUi>();

		internal static void Reset()
		{
			_titles.Clear();
		}

		internal static void Tick(IEnumerable<TrackedWindow> windows)
		{
			foreach (TrackedWindow window in windows)
			{
				if ((Object)(object)window.CodeWindow == (Object)null)
				{
					continue;
				}
				RectTransform val = window.FileNameRect;
				if ((Object)(object)val == (Object)null)
				{
					Transform obj = window.CodeWindow.transform.Find("FileNameText");
					RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
					if (val2 == null)
					{
						continue;
					}
					val = (window.FileNameRect = val2);
				}
				if (!_titles.TryGetValue(((Object)val).GetInstanceID(), out var value))
				{
					if (!window.CodeWindow.gameObject.activeInHierarchy)
					{
						continue;
					}
					RectTransform val3 = window.MinimizeRect;
					if ((Object)(object)val3 == (Object)null)
					{
						Transform obj2 = window.CodeWindow.transform.Find("MinimizeButton");
						RectTransform val4 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
						if (val4 == null)
						{
							continue;
						}
						val3 = (window.MinimizeRect = val4);
					}
					_titles[((Object)val).GetInstanceID()] = createTitle(window, val, val3);
				}
				else if ((Object)(object)value.Label == (Object)null || (Object)(object)value.EditField == (Object)null)
				{
					_titles.Remove(((Object)val).GetInstanceID());
				}
				else if (!value.Editing && value.Label.text != window.Key)
				{
					value.Label.text = window.Key;
				}
			}
		}

		private static TitleUi createTitle(TrackedWindow entry, RectTransform field, RectTransform minimize)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_009e: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Expected O, but got Unknown
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			//IL_024a: 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)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: 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_0382: Unknown result type (might be due to invalid IL or missing references)
			TMP_InputField component = ((Component)field).GetComponent<TMP_InputField>();
			if ((Object)(object)component != (Object)null)
			{
				((Component)component).gameObject.SetActive(false);
			}
			TitleUi title = new TitleUi();
			GameObject val = new GameObject("TEWR_TitleLabel", new Type[2]
			{
				typeof(RectTransform),
				typeof(TextMeshProUGUI)
			});
			title.Label = (TMP_Text)(object)val.GetComponent<TextMeshProUGUI>();
			val.transform.SetParent(((Transform)field).parent, false);
			RectTransform rectTransform = title.Label.rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = new Vector2(1f, 1f);
			rectTransform.offsetMin = new Vector2(field.offsetMin.x, field.offsetMin.y - 6f);
			rectTransform.offsetMax = new Vector2(minimize.offsetMin.x - 8f, field.offsetMax.y + 6f);
			title.Label.fontSize = (((Object)(object)component != (Object)null && (Object)(object)component.textComponent != (Object)null) ? component.textComponent.fontSize : 24f);
			((Graphic)title.Label).color = Color.white;
			title.Label.alignment = (TextAlignmentOptions)4097;
			title.Label.overflowMode = (TextOverflowModes)1;
			title.Label.richText = false;
			((Graphic)title.Label).raycastTarget = true;
			title.Label.text = entry.Key;
			TewrNameTooltip.Attach(title.Label);
			Button obj = val.AddComponent<Button>();
			((Selectable)obj).targetGraphic = (Graphic)(object)title.Label;
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				beginTitleEdit(entry, title);
			});
			GameObject val2 = new GameObject("TEWR_TitleEdit", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform component2 = val2.GetComponent<RectTransform>();
			val2.transform.SetParent(((Transform)field).parent, false);
			component2.anchorMin = rectTransform.anchorMin;
			component2.anchorMax = rectTransform.anchorMax;
			component2.offsetMin = rectTransform.offsetMin;
			component2.offsetMax = rectTransform.offsetMax;
			Image component3 = val2.GetComponent<Image>();
			((Graphic)component3).color = new Color(0.15f, 0.17f, 0.2f);
			title.EditField = val2.AddComponent<TMP_InputField>();
			GameObject val3 = new GameObject("Text Area", new Type[2]
			{
				typeof(RectTransform),
				typeof(RectMask2D)
			});
			RectTransform component4 = val3.GetComponent<RectTransform>();
			val3.transform.SetParent((Transform)(object)component2, false);
			component4.anchorMin = Vector2.zero;
			component4.anchorMax = Vector2.one;
			component4.offsetMin = new Vector2(10f, 3f);
			component4.offsetMax = new Vector2(-10f, -3f);
			TextMeshProUGUI textComponent = UiFactory.CreateTmpText(component4, "Value", title.Label.fontSize, Color.white, (TextAlignmentOptions)4097);
			TextMeshProUGUI val4 = UiFactory.CreateTmpText(component4, "Placeholder", title.Label.fontSize, new Color(0.45f, 0.48f, 0.53f), (TextAlignmentOptions)4097);
			((TMP_Text)val4).text = "name...";
			title.EditField.textViewport = component4;
			title.EditField.textComponent = (TMP_Text)(object)textComponent;
			title.EditField.placeholder = (Graphic)(object)val4;
			((Selectable)title.EditField).targetGraphic = (Graphic)(object)component3;
			title.EditField.characterLimit = 60;
			((UnityEvent<string>)(object)title.EditField.onEndEdit).AddListener((UnityAction<string>)delegate(string value)
			{
				endTitleEdit(entry, title, value);
			});
			val2.SetActive(false);
			Plugin.Logger.LogInfo((object)("Own title created for '" + entry.Key + "'."));
			return title;
		}

		private static void beginTitleEdit(TrackedWindow entry, TitleUi title)
		{
			if (!title.Editing && !((Object)(object)title.EditField == (Object)null))
			{
				title.Editing = true;
				((Component)title.Label).gameObject.SetActive(false);
				((Component)title.EditField).gameObject.SetActive(true);
				title.EditField.text = currentKeyFor(entry);
				((Selectable)title.EditField).Select();
				title.EditField.ActivateInputField();
			}
		}

		private static void endTitleEdit(TrackedWindow entry, TitleUi title, string value)
		{
			title.Editing = false;
			if ((Object)(object)title.Label != (Object)null)
			{
				((Component)title.Label).gameObject.SetActive(true);
			}
			if ((Object)(object)title.EditField != (Object)null)
			{
				((Component)title.EditField).gameObject.SetActive(false);
			}
			if (!string.IsNullOrEmpty(value) && !string.Equals(value, currentKeyFor(entry)))
			{
				MethodInfo renameCodeWindow = GameApi.RenameCodeWindow;
				if ((object)renameCodeWindow != null)
				{
					Component codeWindow = entry.CodeWindow;
					object[] parameters = new string[1] { value };
					renameCodeWindow.Invoke(codeWindow, parameters);
				}
			}
		}

		private static string currentKeyFor(TrackedWindow entry)
		{
			return EditorWindows.GetFileName(entry.CodeWindow) ?? entry.Key;
		}
	}
}
namespace TheEditorWasReplaced.Sidebar
{
	internal static class GameInputPatches
	{
		public static bool OpenPrefix()
		{
			if (SidebarSearch.ConsumeSearchReveal())
			{
				SidebarSearch.SetSearchVisible(visible: false);
				return false;
			}
			if (!SidebarSearch.HasSearchText)
			{
				return true;
			}
			SidebarSearch.ClearSearch();
			return false;
		}
	}
	internal static class ScrollPatches
	{
		public static bool ScrollPrefix()
		{
			if (!SidebarPanel.IsPointerOver)
			{
				return !OutputBar.IsPointerOver;
			}
			return false;
		}
	}
	internal static class SidebarPanel
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__createFile;

			public static UnityAction <1>__ExpandAllDirectories;

			public static UnityAction <2>__CollapseAllDirectories;

			public static UnityAction <3>__CloseAll;

			public static UnityAction <4>__refresh;

			public static UnityAction <5>__ToggleSearch;

			public static OptionChangedAction <6>__onOptionChanged;

			public static Action<PointerEventData> <7>__BeginResize;

			public static Action<PointerEventData> <8>__UpdateResize;
		}

		private const string _panelName = "TEWR_Sidebar";

		internal const float DefaultWidth = 400f;

		internal const float MinWidth = 400f;

		internal const float MaxWidth = 1200f;

		private const float _handleThickness = 12f;

		internal const float HudInset = 105f;

		internal const float Margin = 18.6f;

		internal const float SearchHeight = 60f;

		internal const float ButtonRowGap = 9f;

		private const float _scrollbarWidth = 6f;

		internal const float ScrollbarGap = 6f;

		internal const float RowHeight = 48f;

		internal const float RowGap = 4f;

		internal static RectTransform _panel;

		internal static RectTransform _content;

		internal static RectTransform _viewportRect;

		internal static RectTransform _trackRect;

		private static Canvas _rootCanvas;

		private static bool _uiScaleSubscribed;

		private static object _workspace;

		private static bool _ensureFailed;

		private static readonly HashSet<string> _expandedDirs = new HashSet<string>(StringComparer.Ordinal);

		private static readonly StringBuilder _signatureBuilder = new StringBuilder(2048);

		private static readonly List<SidebarTree.RowInfo> _visibleRows = new List<SidebarTree.RowInfo>();

		private static long _signatureHash;

		private static int _signatureLength = -1;

		private static Vector2 _resizeStartPointer;

		private static float _resizeStartWidth;

		internal static RectTransform Panel => _panel;

		internal static float Width { get; private set; } = 400f;

		internal static bool IsPointerOver
		{
			get
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_panel != (Object)null && Object.op_Implicit((Object)(object)_panel))
				{
					return RectTransformUtility.RectangleContainsScreenPoint(_panel, Vector2.op_Implicit(Input.mousePosition));
				}
				return false;
			}
		}

		internal static bool IsExpanded(string dir)
		{
			return _expandedDirs.Contains(dir);
		}

		internal static void ToggleExpanded(string dir)
		{
			if (!_expandedDirs.Remove(dir))
			{
				_expandedDirs.Add(dir);
			}
		}

		internal static IEnumerable<string> ExpandedDirsSnapshot()
		{
			return _expandedDirs;
		}

		internal static void SetExpandedDirs(IEnumerable<string> dirs)
		{
			_expandedDirs.Clear();
			foreach (string dir in dirs)
			{
				_expandedDirs.Add(dir);
			}
		}

		internal static void IndentChanged()
		{
			_signatureLength = -1;
		}

		internal static void SetWidth(float width)
		{
			if ((Object)(object)_panel != (Object)null && Object.op_Implicit((Object)(object)_panel))
			{
				Width = Mathf.Clamp(width, 400f, effectiveMaxWidth());
				applyUiScale();
				SidebarTopButtons.Reflow();
			}
			else
			{
				Width = ((float.IsNaN(width) || float.IsInfinity(width)) ? 400f : width);
			}
		}

		internal static void BeginResize(PointerEventData eventData)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_panel == (Object)null) && Object.op_Implicit((Object)(object)_panel))
			{
				RectTransformUtility.ScreenPointToLocalPointInRectangle(_panel, eventData.position, eventData.pressEventCamera, ref _resizeStartPointer);
				_resizeStartWidth = Width;
			}
		}

		internal static void UpdateResize(PointerEventData eventData)
		{
			//IL_0020: 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)
			Vector2 val = default(Vector2);
			if (!((Object)(object)_panel == (Object)null) && Object.op_Implicit((Object)(object)_panel) && RectTransformUtility.ScreenPointToLocalPointInRectangle(_panel, eventData.position, eventData.pressEventCamera, ref val))
			{
				SetWidth(_resizeStartWidth + (val.x - _resizeStartPointer.x));
			}
		}

		internal static void Tick()
		{
			syncWorkspace();
			if (!((Object)(object)_panel == (Object)null) && Object.op_Implicit((Object)(object)_panel))
			{
				updatePauseVisibility();
				syncWidthClamp();
				if (!((Object)(object)_content == (Object)null) && Object.op_Implicit((Object)(object)_content) && signatureChanged())
				{
					rebuildRows();
				}
			}
		}

		internal static void CollapseAllDirectories()
		{
			_expandedDirs.Clear();
		}

		internal static void ExpandAllDirectories()
		{
			_expandedDirs.Clear();
			List<string> list = new List<string>();
			SidebarTree.CollectDirectories(SidebarTree.BuildTree(EditorWindows.SortedKeys()), list);
			foreach (string item in list)
			{
				_expandedDirs.Add(item);
			}
		}

		private static void reset()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			_panel = null;
			_content = null;
			_viewportRect = null;
			_trackRect = null;
			_rootCanvas = null;
			_signatureLength = -1;
			_resizeStartPointer = Vector2.zero;
			SidebarSearch.Reset();
			SidebarRows.Reset();
			SidebarTopButtons.Reset();
		}

		private static void syncWorkspace()
		{
			object currentWorkspace = EditorWindows.CurrentWorkspace;
			if (_workspace != currentWorkspace)
			{
				_workspace = currentWorkspace;
				_ensureFailed = false;
				reset();
				ensureForWorkspace();
			}
		}

		private static void ensureForWorkspace()
		{
			object workspace = _workspace;
			Component val = (Component)((workspace is Component) ? workspace : null);
			if (val == null)
			{
				return;
			}
			Canvas componentInParent = val.GetComponentInParent<Canvas>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				if (!_ensureFailed)
				{
					_ensureFailed = true;
					Plugin.Logger.LogWarning((object)"No canvas found above the workspace; sidebar unavailable.");
				}
			}
			else
			{
				ensure(componentInParent);
			}
		}

		private static void ensure(Canvas rootCanvas)
		{
			//IL_003f: 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_0073: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Expected O, but got Unknown
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Expected O, but got Unknown
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Expected O, but got Unknown
			//IL_033f: 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_034a: Expected O, but got Unknown
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Expected O, but got Unknown
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Expected O, but got Unknown
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Expected O, but got Unknown
			if ((Object)(object)_panel != (Object)null && Object.op_Implicit((Object)(object)_panel))
			{
				return;
			}
			_panel = new GameObject("TEWR_Sidebar", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<RectTransform>();
			((Transform)_panel).SetParent(((Component)rootCanvas).transform, false);
			_panel.anchorMin = Vector2.zero;
			_panel.anchorMax = Vector2.up;
			_panel.pivot = new Vector2(0f, 0.5f);
			_panel.offsetMin = Vector2.zero;
			_panel.offsetMax = new Vector2(Width, 0f);
			Image component = ((Component)_panel).GetComponent<Image>();
			((Graphic)component).color = new Color(0.09f, 0.1f, 0.12f, 0.95f);
			((Graphic)component).raycastTarget = true;
			RectTransform component2 = new GameObject("TEWR_Viewport", new Type[4]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Mask),
				typeof(ScrollRect)
			}).GetComponent<RectTransform>();
			((Transform)component2).SetParent((Transform)(object)_panel, false);
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			_viewportRect = component2;
			component2.offsetMin = new Vector2(0f, 18.6f);
			component2.offsetMax = new Vector2(-24.6f, -261.6f);
			((Component)component2).GetComponent<Mask>().showMaskGraphic = false;
			ScrollRect component3 = ((Component)component2).GetComponent<ScrollRect>();
			component3.horizontal = false;
			component3.vertical = true;
			component3.movementType = (MovementType)2;
			component3.scrollSensitivity = 24f;
			component3.verticalScrollbar = createScrollbar();
			component3.verticalScrollbarSpacing = 4f;
			_content = new GameObject("TEWR_Content", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)_content).SetParent((Transform)(object)component2, false);
			_content.anchorMin = new Vector2(0f, 1f);
			_content.anchorMax = new Vector2(1f, 1f);
			_content.pivot = new Vector2(0.5f, 1f);
			_content.anchoredPosition = Vector2.zero;
			_content.sizeDelta = new Vector2(0f, 0f);
			component3.content = _content;
			component3.viewport = component2;
			SidebarSearch.CreateSearchField();
			Sprite iconSprite = ModIcons.PlusSprite(28f);
			object obj = <>O.<0>__createFile;
			if (obj == null)
			{
				UnityAction val = createFile;
				<>O.<0>__createFile = val;
				obj = (object)val;
			}
			SidebarTopButtons.Create("TEWR_CreateFile", iconSprite, 4, (UnityAction)obj);
			Sprite iconSprite2 = ModIcons.CaretDownSprite(28f);
			object obj2 = <>O.<1>__ExpandAllDirectories;
			if (obj2 == null)
			{
				UnityAction val2 = ExpandAllDirectories;
				<>O.<1>__ExpandAllDirectories = val2;
				obj2 = (object)val2;
			}
			SidebarTopButtons.Create("TEWR_ExpandAll", iconSprite2, 3, (UnityAction)obj2);
			Sprite iconSprite3 = ModIcons.CaretUpSprite(28f);
			object obj3 = <>O.<2>__CollapseAllDirectories;
			if (obj3 == null)
			{
				UnityAction val3 = CollapseAllDirectories;
				<>O.<2>__CollapseAllDirectories = val3;
				obj3 = (object)val3;
			}
			SidebarTopButtons.Create("TEWR_CollapseAll", iconSprite3, 2, (UnityAction)obj3);
			Sprite iconSprite4 = ModIcons.XMarkSprite(28f);
			object obj4 = <>O.<3>__CloseAll;
			if (obj4 == null)
			{
				UnityAction val4 = EditorWindows.CloseAll;
				<>O.<3>__CloseAll = val4;
				obj4 = (object)val4;
			}
			SidebarTopButtons.Create("TEWR_CloseAll", iconSprite4, 1, (UnityAction)obj4);
			Sprite iconSprite5 = ModIcons.RotateSprite(28f);
			object obj5 = <>O.<4>__refresh;
			if (obj5 == null)
			{
				UnityAction val5 = refresh;
				<>O.<4>__refresh = val5;
				obj5 = (object)val5;
			}
			SidebarTopButtons.Create("TEWR_Refresh", iconSprite5, 0, (UnityAction)obj5);
			Sprite iconSprite6 = ModIcons.SearchSprite(28f);
			object obj6 = <>O.<5>__ToggleSearch;
			if (obj6 == null)
			{
				UnityAction val6 = SidebarSearch.ToggleSearch;
				<>O.<5>__ToggleSearch = val6;
				obj6 = (object)val6;
			}
			SidebarTopButtons.Create("TEWR_SearchToggle", iconSprite6, 5, (UnityAction)obj6);
			SidebarSearch.SetSearchVisible(SidebarSearch.SearchVisible);
			createHandle();
			_signatureLength = -1;
			Plugin.Logger.LogInfo((object)string.Format("Created {0} ({1:0} canvas units wide).", "TEWR_Sidebar", Width));
			_rootCanvas = rootCanvas;
			applyUiScale();
			if (!_uiScaleSubscribed)
			{
				_uiScaleSubscribed = true;
				object obj7 = <>O.<6>__onOptionChanged;
				if (obj7 == null)
				{
					OptionChangedAction val7 = onOptionChanged;
					<>O.<6>__onOptionChanged = val7;
					obj7 = (object)val7;
				}
				OptionHolder.OnOptionChanged += (OptionChangedAction)obj7;
			}
		}

		private static void onOptionChanged(string option)
		{
			switch (option)
			{
			case "UI size":
				applyUiScale();
				break;
			case "sidebar indent":
			case "show file paths":
			case "show delete buttons":
				IndentChanged();
				break;
			}
		}

		private static void applyUiScale()
		{
			//IL_0069: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_panel == (Object)null) && Object.op_Implicit((Object)(object)_panel) && !((Object)(object)_rootCanvas == (Object)null))
			{
				Width = Mathf.Clamp(Width, 400f, effectiveMaxWidth());
				float num = Mathf.Max(0.5f, OptionHolder.GetFloat("UI size", 1f));
				_panel.anchorMin = new Vector2(0f, 0f);
				_panel.anchorMax = new Vector2(0f, 1f / num);
				_panel.pivot = new Vector2(0f, 0f);
				_panel.offsetMin = Vector2.zero;
				_panel.offsetMax = new Vector2(Width, 0f);
				((Transform)_panel).localScale = new Vector3(num, num, 1f);
			}
		}

		private static float effectiveMaxWidth()
		{
			//IL_001d: 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)
			if ((Object)(object)_rootCanvas == (Object)null)
			{
				return 1200f;
			}
			Rect rect = ((RectTransform)((Component)_rootCanvas).transform).rect;
			float width = ((Rect)(ref rect)).width;
			float num = Mathf.Max(0.5f, OptionHolder.GetFloat("UI size", 1f));
			return Mathf.Max(400f, Mathf.Min(1200f, width / num * 0.5f));
		}

		private static void syncWidthClamp()
		{
			if (!(Width <= effectiveMaxWidth()))
			{
				SetWidth(Width);
			}
		}

		private static void createHandle()
		{
			//IL_0025: 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_005b: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject("TEWR_SidebarResizeHandle", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)_panel, false);
			component.anchorMin = new Vector2(1f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(1f, 0.5f);
			component.offsetMin = new Vector2(-12f, 0f);
			component.offsetMax = new Vector2(0f, 0f);
			TewrResizeHandle.Attach(((Component)component).gameObject, BeginResize, UpdateResize, null);
			TewrTextTooltip.Attach(((Component)component).gameObject, "Drag to resize");
		}

		private static void updatePauseVisibility()
		{
			Menu val = (((Object)(object)MainSim.Inst != (Object)null) ? MainSim.Inst.menu : null);
			if (!((Object)(object)val == (Object)null))
			{
				bool activeInHierarchy = ((Component)val).gameObject.activeInHierarchy;
				if (((Component)_panel).gameObject.activeSelf == activeInHierarchy)
				{
					((Component)_panel).gameObject.SetActive(!activeInHierarchy);
				}
			}
		}

		private static bool signatureChanged()
		{
			StringBuilder signatureBuilder = _signatureBuilder;
			signatureBuilder.Clear();
			signatureBuilder.Append(SidebarSearch.Query()).Append('|');
			List<string> list = EditorWindows.SortedKeys();
			for (int i = 0; i < list.Count; i++)
			{
				signatureBuilder.Append(list[i]).Append(':').Append(EditorWindows.IsShown(list[i]) ? '1' : '0')
					.Append(';');
			}
			signatureBuilder.Append('#').Append(_expandedDirs.Count);
			foreach (string expandedDir in _expandedDirs)
			{
				signatureBuilder.Append(expandedDir).Append(';');
			}
			signatureBuilder.Append('#');
			for (int j = 0; j < list.Count; j++)
			{
				if (EditorWindows.IsExecuting(list[j]))
				{
					signatureBuilder.Append(list[j]).Append(';');
				}
			}
			long num = -3750763034362895579L;
			for (int k = 0; k < signatureBuilder.Length; k++)
			{
				num ^= signatureBuilder[k];
				num *= 1099511628211L;
			}
			if (num == _signatureHash && signatureBuilder.Length == _signatureLength)
			{
				return false;
			}
			_signatureHash = num;
			_signatureLength = signatureBuilder.Length;
			return true;
		}

		private static void rebuildRows()
		{
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			SidebarRows.ReleaseRows();
			string text = SidebarSearch.Query();
			float num = 0f;
			int num2 = 0;
			if (text.Length > 0)
			{
				List<string> list = EditorWindows.SortedKeys();
				for (int i = 0; i < list.Count; i++)
				{
					if (list[i].IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
					{
						SidebarRows.CreateFileRow(list[i], 0, num);
						num -= 52f;
						num2++;
					}
				}
			}
			else
			{
				_visibleRows.Clear();
				SidebarTree.FlattenVisible(SidebarTree.BuildTree(EditorWindows.SortedKeys()), 0, _visibleRows);
				foreach (SidebarTree.RowInfo visibleRow in _visibleRows)
				{
					if (visibleRow.IsDir)
					{
						SidebarRows.CreateDirRow(visibleRow.Key, visibleRow.Name, visibleRow.Depth, visibleRow.IsExpanded, num);
					}
					else
					{
						SidebarRows.CreateFileRow(visibleRow.Key, visibleRow.Depth, num);
					}
					num -= 52f;
					num2++;
				}
			}
			_content.sizeDelta = new Vector2(0f, (num2 > 0) ? ((float)num2 * 48f + (float)(num2 - 1) * 4f) : 0f);
		}

		private static Scrollbar createScrollbar()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject("TEWR_Scrollbar", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)_panel, false);
			component.anchorMin = new Vector2(1f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(1f, 0.5f);
			component.offsetMin = new Vector2(-24.6f, 18.6f);
			component.offsetMax = new Vector2(-18.6f, -261.6f);
			((Graphic)((Component)component).GetComponent<Image>()).color = new Color(0.13f, 0.15f, 0.18f);
			_trackRect = component;
			Scrollbar val = ((Component)component).gameObject.AddComponent<Scrollbar>();
			val.direction = (Direction)2;
			Image component2 = new GameObject("Handle", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<Image>();
			((Component)component2).transform.SetParent((Transform)(object)component, false);
			((Graphic)component2).rectTransform.anchorMin = new Vector2(0f, 0f);
			((Graphic)component2).rectTransform.anchorMax = new Vector2(1f, 0f);
			((Graphic)component2).rectTransform.sizeDelta = Vector2.zero;
			((Graphic)component2).color = new Color(0.36f, 0.41f, 0.47f);
			val.handleRect = ((Graphic)component2).rectTransform;
			((Selectable)val).targetGraphic = (Graphic)(object)component2;
			return val;
		}

		private static void refresh()
		{
			object currentWorkspace = EditorWindows.CurrentWorkspace;
			Workspace val = (Workspace)((currentWorkspace is Workspace) ? currentWorkspace : null);
			if (!((Object)(object)val == (Object)null))
			{
				WorkspaceFiles.OpenExternalFiles(val);
				StatePersistence.ApplyLoadedState();
				Plugin.Logger.LogInfo((object)"Sidebar refresh: rescanned the save directory.");
			}
		}

		private static void createFile()
		{
			object currentWorkspace = EditorWindows.CurrentWorkspace;
			Workspace val = (Workspace)((currentWorkspace is Workspace) ? currentWorkspace : null);
			if (!((Object)(object)val == (Object)null))
			{
				GameApi.AddNewWindow?.Invoke(val, Array.Empty<object>());
			}
		}
	}
	internal static class SidebarRows
	{
		private sealed class FileRow
		{
			public string Key;

			public RectTransform Rect;

			public Image Background;

			public Button Button;

			public TMP_Text Label;

			public RectTransform RunRect;

			public Image RunIcon;

			public Button RunButton;

			public RectTransform DeleteRect;

			public Button DeleteButton;
		}

		private sealed class DirRow
		{
			public string Path;

			public RectTransform Rect;

			public Image Background;

			public Button Button;

			public Image Chevron;

			public TMP_Text Label;
		}

		private sealed class WindowSprites
		{
			public Sprite Execute;

			public Sprite Stop;
		}

		private const float _runButtonSize = 36f;

		private static readonly Color _buttonBackground = new Color(0.17f, 0.2f, 0.24f);

		private static readonly Color _fileShown = new Color(0.22f, 0.26f, 0.3f);

		private static readonly Color _fileHidden = new Color(0.15f, 0.17f, 0.2f);

		private static readonly Color _labelShown = new Color(0.92f, 0.93f, 0.95f);

		private static readonly Color _labelHidden = new Color(0.55f, 0.58f, 0.62f);

		private static readonly Color _dirBackground = new Color(0.15f, 0.17f, 0.2f);

		private static readonly Color _dirLabel = new Color(0.75f, 0.78f, 0.82f);

		private static WindowSprites _windowSprites;

		private static readonly Stack<FileRow> _filePool = new Stack<FileRow>();

		private static readonly Stack<DirRow> _dirPool = new Stack<DirRow>();

		private static readonly List<FileRow> _boundFiles = new List<FileRow>();

		private static readonly List<DirRow> _boundDirs = new List<DirRow>();

		private static readonly Color _runIdleColor = new Color(0.3f, 0.62f, 0.94f);

		private static readonly Color _runExecColor = new Color(0.95f, 0.32f, 0.32f);

		internal static void Reset()
		{
			_windowSprites = null;
			_filePool.Clear();
			_dirPool.Clear();
			_boundFiles.Clear();
			_boundDirs.Clear();
		}

		internal static void ReleaseRows()
		{
			for (int i = 0; i < _boundFiles.Count; i++)
			{
				((Component)_boundFiles[i].Rect).gameObject.SetActive(false);
				_filePool.Push(_boundFiles[i]);
			}
			_boundFiles.Clear();
			for (int j = 0; j < _boundDirs.Count; j++)
			{
				((Component)_boundDirs[j].Rect).gameObject.SetActive(false);
				_dirPool.Push(_boundDirs[j]);
			}
			_boundDirs.Clear();
		}

		internal static void CreateFileRow(string key, int depth, float y)
		{
			//IL_0044: 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_007e: 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_009d: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			FileRow row = acquireFileRow();
			row.Key = key;
			bool flag = EditorWindows.IsShown(key);
			row.Rect.offsetMin = new Vector2(18.6f + (float)depth * ModConfig.SidebarIndentWidth, y - 48f);
			row.Rect.offsetMax = new Vector2(-6f, y);
			((Graphic)row.Background).color = (flag ? _fileShown : _fileHidden);
			((Graphic)row.Label).color = (flag ? _labelShown : _labelHidden);
			row.Label.text = ((depth > 0 && !ModConfig.ShowFilePaths) ? key.Substring(key.LastIndexOf('.') + 1) : key);
			row.RunIcon.sprite = (EditorWindows.IsExecuting(key) ? executeStopSprite() : executeRunSprite());
			((Component)row.DeleteRect).gameObject.SetActive(ModConfig.ShowDeleteButtons);
			((UnityEventBase)row.Button.onClick).RemoveAllListeners();
			((UnityEvent)row.Button.onClick).AddListener((UnityAction)delegate
			{
				EditorWindows.TryToggle(row.Key);
			});
			((UnityEventBase)row.RunButton.onClick).RemoveAllListeners();
			((UnityEvent)row.RunButton.onClick).AddListener((UnityAction)delegate
			{
				runClicked(row.Key);
			});
			((UnityEventBase)row.DeleteButton.onClick).RemoveAllListeners();
			((UnityEvent)row.DeleteButton.onClick).AddListener((UnityAction)delegate
			{
				TrackedWindow trackedWindow = EditorWindows.FindTracked(row.Key);
				if (trackedWindow != null)
				{
					CodeWindow component = trackedWindow.CodeWindow.GetComponent<CodeWindow>();
					if (component != null)
					{
						component.PromptDelete();
					}
				}
			});
			_boundFiles.Add(row);
		}

		internal static void CreateDirRow(string fullPath, string name, int depth, bool expanded, float y)
		{
			//IL_003e: 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_006f: 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_00c8: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			DirRow row = acquireDirRow();
			row.Path = fullPath;
			row.Rect.offsetMin = new Vector2(18.6f + (float)depth * ModConfig.SidebarIndentWidth, y - 48f);
			row.Rect.offsetMax = new Vector2(-6f, y);
			((Graphic)row.Background).color = _dirBackground;
			((Graphic)row.Label).color = _dirLabel;
			row.Label.text = name;
			((Transform)((Graphic)row.Chevron).rectTransform).localEulerAngles = (Vector3)(expanded ? new Vector3(0f, 0f, -90f) : Vector3.zero);
			((UnityEventBase)row.Button.onClick).RemoveAllListeners();
			((UnityEvent)row.Button.onClick).AddListener((UnityAction)delegate
			{
				SidebarPanel.ToggleExpanded(row.Path);
			});
			_boundDirs.Add(row);
		}

		private static void runClicked(string key)
		{
			TrackedWindow trackedWindow = EditorWindows.FindTracked(key);
			CodeWindow val = ((trackedWindow != null) ? trackedWindow.CodeWindow.GetComponent<CodeWindow>() : null);
			if (!((Object)(object)val == (Object)null))
			{
				MainSim inst = MainSim.Inst;
				if (EditorWindows.IsExecuting(key) && (Object)(object)inst != (Object)null && inst.IsExecuting())
				{
					GameApi.StopMainExecution?.Invoke(GameApi.MainSimInstance(), Array.Empty<object>());
				}
				else
				{
					val.PressExecuteOrStop();
				}
			}
		}

		private static FileRow acquireFileRow()
		{
			while (_filePool.Count > 0)
			{
				FileRow fileRow = _filePool.Pop();
				if ((Object)(object)fileRow.Rect != (Object)null && Object.op_Implicit((Object)(object)fileRow.Rect))
				{
					((Component)fileRow.Rect).gameObject.SetActive(true);
					return fileRow;
				}
			}
			return buildFileRow();
		}

		private static DirRow acquireDirRow()
		{
			while (_dirPool.Count > 0)
			{
				DirRow dirRow = _dirPool.Pop();
				if ((Object)(object)dirRow.Rect != (Object)null && Object.op_Implicit((Object)(object)dirRow.Rect))
				{
					((Component)dirRow.Rect).gameObject.SetActive(true);
					return dirRow;
				}
			}
			return buildDirRow();
		}

		private static FileRow buildFileRow()
		{
			//IL_0032: 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_0069: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: 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)
			RectTransform component = new GameObject("TEWR_FileRow", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			}).GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)SidebarPanel._content, false);
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			FileRow fileRow = new FileRow
			{
				Rect = component,
				Background = ((Component)component).GetComponent<Image>(),
				Button = ((Component)component).GetComponent<Button>()
			};
			((Selectable)fileRow.Button).targetGraphic = (Graphic)(object)fileRow.Background;
			fileRow.Label = (TMP_Text)(object)UiFactory.CreateTmpText(component, "Label", 24f, Color.white, (TextAlignmentOptions)4097);
			fileRow.Label.overflowMode = (TextOverflowModes)1;
			fileRow.Label.rectTransform.offsetMin = new Vector2(16f, 6f);
			fileRow.Label.rectTransform.offsetMax = new Vector2(-90f, -6f);
			TewrNameTooltip.Attach(fileRow.Label);
			((Component)component).gameObject.AddComponent<TooltipAccessor>().tooltipHandler = ((Component)fileRow.Label).gameObject;
			fileRow.RunRect = UiFactory.CreateIconButton("Run", (Transform)(object)component, _buttonBackground, null, new Vector2(6f, 6f), out var button);
			placeActionButton(fileRow.RunRect, 0);
			fileRow.RunButton = button;
			fileRow.RunIcon = ((Component)((Transform)fileRow.RunRect).Find("Icon")).GetComponent<Image>();
			fileRow.DeleteRect = UiFactory.CreateIconButton("Delete", (Transform)(object)component, _buttonBackground, ModIcons.TrashSprite(14.400001f), new Vector2(6f, 6f), out var button2);
			placeActionButton(fileRow.DeleteRect, 1);
			fileRow.DeleteButton = button2;
			return fileRow;
		}

		private static DirRow buildDirRow()
		{
			//IL_0032: 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_0069: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject("TEWR_DirRow", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			}).GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)SidebarPanel._content, false);
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			DirRow dirRow = new DirRow
			{
				Rect = component,
				Background = ((Component)component).GetComponent<Image>(),
				Button = ((Component)component).GetComponent<Button>()
			};
			((Selectable)dirRow.Button).targetGraphic = (Graphic)(object)dirRow.Background;
			dirRow.Chevron = UiFactory.CreateIcon(component, "Chevron", ModIcons.ChevronSprite(20f), new Color(0.55f, 0.58f, 0.62f), 20f, new Vector2(26f, 0f));
			UiFactory.CreateIcon(component, "FolderIcon", ModIcons.FolderSprite(24f), new Color(0.75f, 0.78f, 0.82f), 24f, new Vector2(56f, 0f));
			dirRow.Label = (TMP_Text)(object)UiFactory.CreateTmpText(component, "Label", 24f, _dirLabel, (TextAlignmentOptions)4097);
			dirRow.Label.overflowMode = (TextOverflowModes)1;
			dirRow.Label.rectTransform.offsetMin = new Vector2(74f, 6f);
			dirRow.Label.rectTransform.offsetMax = new Vector2(-16f, -6f);
			TewrNameTooltip.Attach(dirRow.Label);
			((Component)component).gameObject.AddComponent<TooltipAccessor>().tooltipHandler = ((Component)dirRow.Label).gameObject;
			return dirRow;
		}

		private static void placeActionButton(RectTransform rect, int index)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = new Vector2(1f, 0.5f);
			rect.anchorMax = new Vector2(1f, 0.5f);
			rect.pivot = new Vector2(0.5f, 0.5f);
			rect.sizeDelta = new Vector2(36f, 36f);
			rect.anchoredPosition = new Vector2(0f - (22f + (float)index * 40f), 0f);
		}

		private static Sprite executeRunSprite()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			return ModIcons.Tinted(fetchWindowSprites().Execute, _runIdleColor);
		}

		private static Sprite executeStopSprite()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			return ModIcons.Tinted(fetchWindowSprites().Stop, _runExecColor);
		}

		private static WindowSprites fetchWindowSprites()
		{
			if (_windowSprites != null)
			{
				return _windowSprites;
			}
			foreach (TrackedWindow item in EditorWindows.TrackedSnapshot())
			{
				if (!((Object)(object)item.CodeWindow == (Object)null) && !(GameApi.ExecuteSprite == null))
				{
					object? value = GameApi.ExecuteSprite.GetValue(item.CodeWindow);
					Sprite val = (Sprite)((value is Sprite) ? value : null);
					if (!((Object)(object)val == (Object)null))
					{
						_windowSprites = new WindowSprites
						{
							Execute = val,
							Stop = (Sprite)/*isinst with value type is only supported in some contexts*/
						};
						break;
					}
				}
			}
			return _windowSprites;
		}
	}
	internal static class SidebarSearch
	{
		private static TMP_InputField _search;

		private static RectTransform _searchRect;

		private static bool _searchVisible = true;

		private static string _lastQuery;

		private static bool _searchRevealedByHotkey;

		internal static bool SearchVisible => _searchVisible;

		internal static bool HasSearchText => !string.IsNullOrEmpty(_lastQuery);

		internal static string Query()
		{
			if (!((Object)(object)_search != (Object)null) || !Object.op_Implicit((Object)(object)_search))
			{
				return string.Empty;
			}
			return _search.text;
		}

		internal static void CreateSearchField()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_00a1: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (_searchRect = new GameObject("TEWR_Search", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<RectTransform>());
			((Transform)val).SetParent((Transform)(object)SidebarPanel._panel, false);
			val.anchorMin = new Vector2(0f, 1f);
			val.anchorMax = new Vector2(1f, 1f);
			val.pivot = new Vector2(0.5f, 1f);
			val.offsetMin = new Vector2(18.6f, -183.6f);
			val.offsetMax = new Vector2(-18.6f, -123.6f);
			((Graphic)((Component)val).GetComponent<Image>()).color = new Color(0.15f, 0.17f, 0.2f);
			_search = ((Component)val).gameObject.AddComponent<TMP_InputField>();
			_search.textComponent = (TMP_Text)(object)UiFactory.CreateTmpText(val, "Value", 24f, new Color(0.92f, 0.93f, 0.95f), (TextAlignmentOptions)4097);
			_search.textComponent.rectTransform.offsetMin = new Vector2(14f, 6f);
			_search.textComponent.rectTransform.offsetMax = new Vector2(-14f, -6f);
			TextMeshProUGUI val2 = UiFactory.CreateTmpText(val, "Placeholder", 24f, new Color(0.45f, 0.48f, 0.53f), (TextAlignmentOptions)4097);
			((TMP_Text)val2).rectTransform.offsetMin = new Vector2(14f, 6f);
			((TMP_Text)val2).rectTransform.offsetMax = new Vector2(-14f, -6f);
			((TMP_Text)val2).text = "Search files...";
			_search.placeholder = (Graphic)(object)val2;
			((Selectable)_search).targetGraphic = (Graphic)(object)((Component)val).GetComponent<Image>();
			((UnityEvent<string>)(object)_search.onValueChanged).AddListener((UnityAction<string>)delegate(string value)
			{
				if (!string.IsNullOrEmpty(value) || !Input.GetKeyDown((KeyCode)27))
				{
					_lastQuery = value;
				}
			});
			_search.text = "";
		}

		internal static void FocusSearch()
		{
			if (!((Object)(object)_search == (Object)null) && Object.op_Implicit((Object)(object)_search))
			{
				if (!_searchVisible)
				{
					SetSearchVisible(visible: true);
					_searchRevealedByHotkey = true;
				}
				((Selectable)_search).Select();
				_search.ActivateInputField();
			}
		}

		internal static bool ConsumeSearchReveal()
		{
			if (!_searchRevealedByHotkey)
			{
				return false;
			}
			_searchRevealedByHotkey = false;
			return true;
		}

		internal static void ToggleSearch()
		{
			_searchRevealedByHotkey = false;
			SetSearchVisible(!_searchVisible);
		}

		internal static void SetSearchVisible(bool visible)
		{
			_searchVisible = visible;
			if (!visible)
			{
				_searchRevealedByHotkey = false;
			}
			if (!((Object)(object)SidebarPanel._panel == (Object)null) && Object.op_Implicit((Object)(object)SidebarPanel._panel) && !((Object)(object)_searchRect == (Object)null))
			{
				((Component)_searchRect).gameObject.SetActive(visible);
				applySearchLayout();
			}
		}

		internal static void ClearSearch()
		{
			_lastQuery = "";
			if (!((Object)(object)_search == (Object)null) && Object.op_Implicit((Object)(object)_search))
			{
				_search.text = "";
				_search.DeactivateInputField(false);
			}
		}

		internal static void Reset()
		{
			_search = null;
			_searchRect = null;
			_lastQuery = "";
		}

		private static void applySearchLayout()
		{
			//IL_005b: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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)
			if (!((Object)(object)SidebarPanel._viewportRect == (Object)null) && !((Object)(object)_searchRect == (Object)null))
			{
				((Component)_searchRect).gameObject.SetActive(_searchVisible);
				float num = (_searchVisible ? 69f : 0f);
				float num2 = 192.6f;
				_searchRect.offsetMin = new Vector2(18.6f, 0f - (num2 + 60f));
				_searchRect.offsetMax = new Vector2(-18.6f, 0f - num2);
				float num3 = num2 + num;
				SidebarPanel._viewportRect.offsetMax = new Vector2(SidebarPanel._viewportRect.offsetMax.x, 0f - num3);
				if ((Object)(object)SidebarPanel._trackRect != (Object)null)
				{
					SidebarPanel._trackRect.offsetMax = new Vector2(SidebarPanel._trackRect.offsetMax.x, 0f - num3);
				}
			}
		}
	}
	internal static class SidebarTopButtons
	{
		private struct ButtonLayout
		{
			public RectTransform Rect;

			public int Index;
		}

		private const int _topButtonCount = 6;

		private static readonly Color _backgroundColor = new Color(0.15f, 0.17f, 0.2f);

		private static readonly List<ButtonLayout> _buttons = new List<ButtonLayout>();

		internal static void Create(string name, Sprite iconSprite, int index, UnityAction onClick)
		{
			//IL_0006: 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)
			Button button;
			RectTransform rect = UiFactory.CreateIconButton(name, (Transform)(object)SidebarPanel._panel, _backgroundColor, iconSprite, new Vector2(9f, 9f), out button);
			place(rect, index);
			((UnityEvent)button.onClick).AddListener(onClick);
			_buttons.Add(new ButtonLayout
			{
				Rect = rect,
				Index = index
			});
		}

		internal static void Reflow()
		{
			for (int num = _buttons.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)_buttons[num].Rect == (Object)null || !Object.op_Implicit((Object)(object)_buttons[num].Rect))
				{
					_buttons.RemoveAt(num);
				}
			}
			for (int i = 0; i < _buttons.Count; i++)
			{
				place(_buttons[i].Rect, _buttons[i].Index);
			}
		}

		internal static void Reset()
		{
			_buttons.Clear();
		}

		private static void place(RectTransform rect, int index)
		{
			//IL_002b: 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_0055: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			float num = 60f;
			float num2 = (SidebarPanel.Width - 37.2f - 6f * num) / 5f;
			rect.anchorMin = new Vector2(1f, 1f);
			rect.anchorMax = new Vector2(1f, 1f);
			rect.pivot = new Vector2(1f, 0.5f);
			rect.offsetMin = new Vector2(0f - (18.6f + (float)(index + 1) * num + (float)index * num2), -183.6f);
			rect.offsetMax = new Vector2(0f - (18.6f + (float)index * (num + num2)), -123.6f);
		}
	}
	internal static class SidebarTree
	{
		internal sealed class RowInfo
		{
			public bool IsDir;

			public bool IsExpanded;

			public int Depth;

			public string Key;

			public string Name;
		}

		internal sealed class TreeNode
		{
			public bool IsDir;

			public string Name;

			public string FullPath;

			public List<TreeNode> Children = new List<TreeNode>();
		}

		internal static TreeNode BuildTree(IEnumerable<string> keys)
		{
			TreeNode treeNode = new TreeNode
			{
				IsDir = true
			};
			foreach (string item in keys.OrderBy<string, string>((string k) => k, StringComparer.Ordinal))
			{
				string[] array = item.Split(new char[1] { '.' });
				TreeNode treeNode2 = treeNode;
				for (int num = 0; num < array.Length; num++)
				{
					bool flag = num == array.Length - 1;
					string name = array[num];
					string fullPath = string.Join(".", array.Take(num + 1));
					TreeNode treeNode3 = treeNode2.Children.FirstOrDefault((TreeNode c) => c.Name == name);
					if (treeNode3 == null)
					{
						treeNode3 = new TreeNode
						{
							Name = name,
							FullPath = fullPath,
							IsDir = !flag
						};
						treeNode2.Children.Add(treeNode3);
					}
					else
					{
						if (flag && treeNode3.IsDir)
						{
							if (!treeNode3.Children.Any((TreeNode c) => c.Name == name && !c.IsDir))
							{
								treeNode3.Children.Insert(0, new TreeNode
								{
									Name = name,
									FullPath = fullPath,
									IsDir = false
								});
							}
							break;
						}
						if (!flag && !treeNode3.IsDir)
						{
							treeNode3.IsDir = true;
							if (!treeNode3.Children.Any((TreeNode c) => c.Name == name && !c.IsDir))
							{
								treeNode3.Children.Insert(0, new TreeNode
								{
									Name = name,
									FullPath = fullPath,
									IsDir = false
								});
							}
						}
					}
					treeNode2 = treeNode3;
				}
			}
			return treeNode;
		}

		internal static void FlattenVisible(TreeNode node, int depth, List<RowInfo> rows)
		{
			foreach (TreeNode child in node.Children)
			{
				if (child.IsDir)
				{
					bool flag = SidebarPanel.IsExpanded(child.FullPath);
					rows.Add(new RowInfo
					{
						IsDir = true,
						IsExpanded = flag,
						Depth = depth,
						Key = child.FullPath,
						Name = child.Name
					});
					if (flag)
					{
						FlattenVisible(child, depth + 1, rows);
					}
				}
				else
				{
					rows.Add(new RowInfo
					{
						Key = child.FullPath,
						Depth = depth,
						Name = child.Name
					});
				}
			}
		}

		internal static void CollectDirectories(TreeNode node, List<string> dirs)
		{
			foreach (TreeNode child in node.Children)
			{
				if (child.IsDir)
				{
					dirs.Add(child.FullPath);
					CollectDirectories(child, dirs);
				}
			}
		}
	}
	internal static class StatePersistence
	{
		[Serializable]
		private class StateData
		{
			public string shown;

			public string expandedDirs;

			public string search;

			public string bar;

			public string barh;

			public string sidebarw;
		}

		private const string _sectionKey = "_tewr";

		public static void ApplyLoadedState()
		{
			EditorWindows.SetLoadedShown(null);
			SidebarPanel.SetExpandedDirs(Enumerable.Empty<string>());
			string text = GameApi.GetCurrentSaveGameJson?.Invoke(null, Array.Empty<object>()) as string;
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			Match match = Regex.Match(text, "\"_tewr\":\\{[^}]*\"shown\":\"([^\"]*)\"");
			Match match2 = Regex.Match(text, "\"_tewr\":\\{[^}]*\"expandedDirs\":\"([^\"]*)\"");
			Match match3 = Regex.Match(text, "\"_tewr\":\\{[^}]*\"search\":\"([^\"]*)\"");
			Match match4 = Regex.Match(text, "\"_tewr\":\\{[^}]*\"bar\":\"([^\"]*)\"");
			Match match5 = Regex.Match(text, "\"_tewr\":\\{[^}]*\"barh\":\"([^\"]*)\"");
			Match match6 = Regex.Match(text, "\"_tewr\":\\{[^}]*\"sidebarw\":\"([^\"]*)\"");
			if (!match.Success && !match2.Success && !match3.Success && !match4.Success && !match5.Success && !match6.Success)
			{
				return;
			}
			SidebarPanel.SetExpandedDirs(unpack(match2.Success ? match2.Groups[1].Value : ""));
			SidebarSearch.SetSearchVisible(!match3.Success || match3.Groups[1].Value != "0");
			OutputBar.SetExpanded(!match4.Success || match4.Groups[1].Value != "0");
			if (match5.Success && float.TryParse(match5.Groups[1].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				OutputBar.SetHeight(result);
			}
			if (match6.Success && float.TryParse(match6.Groups[1].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
			{
				SidebarPanel.SetWidth(result2);
			}
			Dictionary<string, bool> dictionary = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
			string[] array = unpack(match.Success ? match.Groups[1].Value : "");
			for (int i = 0; i + 1 < array.Length; i += 2)
			{
				dictionary[array[i]] = array[i + 1] == "1";
			}
			EditorWindows.SetLoadedShown(dictionary);
			foreach (string item in EditorWindows.SortedKeys())
			{
				if (dictionary.TryGetValue(item, out var value))
				{
					EditorWindows.ApplyShown(item, value);
				}
			}
			Plugin.Logger.LogInfo((object)$"Loaded sidebar state ({dictionary.Count} window states).");
		}

		public static string InjectInto(string json)
		{
			if (string.IsNullOrEmpty(json) || json[0] != '{')
			{
				return json;
			}
			StateData stateData = new StateData
			{
				shown = pack(from p in EditorWindows.ShownSnapshot()
					select p.Key + "|" + (p.Value ? "1" : "0")),
				expandedDirs = pack(SidebarPanel.ExpandedDirsSnapshot()),
				search = (SidebarSearch.SearchVisible ? "1" : "0"),
				bar = (OutputBar.Expanded ? "1" : "0"),
				barh = Mathf.RoundToInt(OutputBar.Height).ToString(CultureInfo.InvariantCulture),
				sidebarw = Mathf.RoundToInt(SidebarPanel.Width).ToString(CultureInfo.InvariantCulture)
			};
			string text = "\"_tewr\":" + JsonUtility.ToJson((object)stateData);
			if (json.Contains("\"_tewr\":"))
			{
				return Regex.Replace(json, "\"_tewr\":\\{[^}]*\\}", text);
			}
			return json.Insert(1, text + ",");
		}

		private static string pack(IEnumerable<string> values)
		{
			return string.Join("|", values);
		}

		private static string[] unpack(string packed)
		{
			return packed.Split(new char[1] { '|' });
		}

		public static void WriteSaveGamePrefix(ref string json)
		{
			json = InjectInto(json);
		}
	}
}
namespace TheEditorWasReplaced.Shared
{
	internal static class EmbeddedResources
	{
		public static byte[] ReadBytes(string resourceName)
		{
			Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (manifestResourceStream == null)
			{
				Plugin.Logger.LogWarning((object)("Embedded resource '" + resourceName + "' not found."));
				return Array.Empty<byte>();
			}
			using (manifestResourceStream)
			{
				using MemoryStream memoryStream = new MemoryStream();
				manifestResourceStream.CopyTo(memoryStream);
				return memoryStream.ToArray();
			}
		}

		public static string ReadText(string resourceName)
		{
			Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (manifestResourceStream == null)
			{
				Plugin.Logger.LogWarning((object)("Embedded resource '" + resourceName + "' not found."));
				return "";
			}
			using (manifestResourceStream)
			{
				using StreamReader streamReader = new StreamReader(manifestResourceStream);
				return streamReader.ReadToEnd();
			}
		}
	}
	internal static class ModIcons
	{
		private const string _resourcePrefix = "TheEditorWasReplaced.assets.";

		private static Sprite _rotate;

		private static Sprite _trash;

		private static Sprite _chevron;

		private static Sprite _caretUp;

		private static Sprite _caretDown;

		private static Sprite _xmark;

		private static Sprite _plus;

		private static Sprite _folder;

		private static Sprite _search;

		private static Sprite _terminal;

		private static readonly Dictionary<string, Sprite> _tinted = new Dictionary<string, Sprite>();

		public unsafe static Sprite Tinted(Sprite source, Color color)
		{
			//IL_001e: 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_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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			if ((Object)(object)source == (Object)null)
			{
				return null;
			}
			string text = ((Object)source).GetInstanceID().ToString();
			Color val = color;
			string key = text + ":" + ((object)(*(Color*)(&val))/*cast due to .constrained prefix*/).ToString();
			if (_tinted.TryGetValue(key, out var value))
			{
				return value;
			}
			try
			{
				Texture2D texture = source.texture;
				Rect textureRect = source.textureRect;
				int num = Mathf.Clamp((int)((Rect)(ref textureRect)).x, 0, ((Texture)texture).width - 1);
				int num2 = Mathf.Clamp((int)((Rect)(ref textureRect)).y, 0, ((Texture)texture).height - 1);
				int num3 = Mathf.Clamp(Mathf.CeilToInt(((Rect)(ref textureRect)).width), 1, ((Texture)texture).width - num);
				int num4 = Mathf.Clamp(Mathf.CeilToInt(((Rect)(ref textureRect)).height), 1, ((Texture)texture).height - num2);
				Color[] pixels;
				try
				{
					pixels = texture.GetPixels(num, num2, num3, num4);
				}
				catch (Exception)
				{
					Plugin.Logger.LogInfo((object)"ModIcons: atlas texture not readable, blitting for tint.");
					Texture2D obj = blitToReadable(texture);
					pixels = obj.GetPixels(num, num2, num3, num4);
					Object.Destroy((Object)(object)obj);
				}
				for (int i = 0; i < pixels.Length; i++)
				{
					ref Color reference = ref pixels[i];
					reference *= color;
				}
				Texture2D val2 = new Texture2D(num3, num4, (TextureFormat)4, false);
				val2.SetPixels(pixels);
				val2.Apply(false, true);
				Sprite val3 = Sprite.Create(val2, new Rect(0f, 0f, (float)num3, (float)num4), new Vector2(0.5f, 0.5f), source.pixelsPerUnit);
				_tinted[key] = val3;
				return val3;
			}
			catch (Exception ex2)
			{
				Plugin.Logger.LogWarning((object)("ModIcons: tint failed, using untinted sprite (" + ex2.Message + ")."));
				_tinted[key] = source;
				return source;
			}
		}

		private static Texture2D blitToReadable(Texture2D atlas)
		{
			//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_0053: 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_0074: Expected O, but got Unknown
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)atlas).width, ((Texture)atlas).height, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = temporary;
			Graphics.Blit((Texture)(object)atlas, temporary);
			Texture2D val = new Texture2D(((Texture)atlas).width, ((Texture)atlas).height, (TextureFormat)4, false);
			val.ReadPixels(new Rect(0f, 0f, (float)((Texture)atlas).width, (float)((Texture)atlas).height), 0, 0);
			val.Apply(false, false);
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return val;
		}

		public static Sprite RotateSprite(float designSize)
		{
			return _rotate ?? (_rotate = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.rotate.png"), designSize));
		}

		public static Sprite TrashSprite(float designSize)
		{
			return _trash ?? (_trash = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.trash.png"), designSize));
		}

		public static Sprite ChevronSprite(float designSize)
		{
			return _chevron ?? (_chevron = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.chevron-right.png"), designSize));
		}

		public static Sprite FolderSprite(float designSize)
		{
			return _folder ?? (_folder = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.folder.png"), designSize));
		}

		public static Sprite CaretUpSprite(float designSize)
		{
			return _caretUp ?? (_caretUp = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.caret-up.png"), designSize));
		}

		public static Sprite CaretDownSprite(float designSize)
		{
			return _caretDown ?? (_caretDown = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.caret-down.png"), designSize));
		}

		public static Sprite XMarkSprite(float designSize)
		{
			return _xmark ?? (_xmark = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.xmark.png"), designSize));
		}

		public static Sprite PlusSprite(float designSize)
		{
			return _plus ?? (_plus = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.plus.png"), designSize));
		}

		public static Sprite SearchSprite(float designSize)
		{
			return _search ?? (_search = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.search.png"), designSize));
		}

		public static Sprite TerminalSprite(float designSize)
		{
			return _terminal ?? (_terminal = createSprite(EmbeddedResources.ReadBytes("TheEditorWasReplaced.assets.terminal.png"), designSize));
		}

		private static Sprite createSprite(byte[] png, float designSize)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			int width;
			int height;
			Color32[] pixels = decodeRgba(png, out width, out height);
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false);
			val.SetPixels32(pixels);
			val.Apply(false, true);
			((Object)val).name = "TEWR_Icon";
			return Sprite.Create(val, new Rect(0f, 0f, (float)width, (float)height), new Vector2(0.5f, 0.5f), (float)height / designSize);
		}

		private static Color32[] decodeRgba(byte[] png, out int width, out int height)
		{
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			width = (height = 0);
			List<byte> list = new List<byte>();
			int num;
			for (int i = 8; i + 8 <= png.Length; i += 12 + num)
			{
				num = readInt(png, i);
				switch (Encoding.ASCII.GetString(png, i + 4, 4))
				{
				case "IHDR":
				{
					width = readInt(png, i + 8);
					height = readInt(png, i + 12);
					int num2 = png[i + 16];
					int num3 = png[i + 17];
					if (num2 == 8 && num3 == 6)
					{
						continue;
					}
					throw new InvalidDataException($"Unsupported PNG: depth {num2}, color {num3}");
				}
				case "IDAT":
				{
					for (int j = 0; j < num; j++)
					{
						list.Add(png[i + 8 + j]);
					}
					continue;
				}
				default:
					continue;
				case "IEND":
					break;
				}
				break;
			}
			using MemoryStream stream = new MemoryStream(list.ToArray(), 2, list.Count - 2);
			using DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress);
			byte[] array = new byte[(width * 4 + 1) * height];
			int num4;
			for (int k = 0; k < array.Length; k += num4)
			{
				num4 = deflateStream.Read(array, k, array.Length - k);
				if (num4 == 0)
				{
					throw new InvalidDataException("Truncated PNG data.");
				}
			}
			Color32[] array2 = (Color32[])(object)new Color32[width * height];
			for (int l = 0; l < height; l++)
			{
				int num5 = l * (width * 4 + 1);
				int num6 = array[num5];
				if (num6 != 0)
				{
					throw new InvalidDataException($"Unsupported PNG filter {num6}.");
				}
				int num7 = height - 1 - l;
				for (int m = 0; m < width; m++)
				{
					int num8 = num5 + 1 + m * 4;
					array2[num7 * width + m] = new Color32(array[num8], array[num8 + 1], array[num8 + 2], array[num8 + 3]);
				}
			}
			return array2;
		}

		private static int readInt(byte[] data, int offset)
		{
			return (data[offset] << 24) | (data[offset + 1] << 16) | (data[offset + 2] << 8) | data[offset + 3];
		}
	}
	internal static class SavePaths
	{
		public static string SaveDirectory()
		{
			string pathOfSaveDirectory = Saver.GetPathOfSaveDirectory(OptionHolder.GetString("activeSave", "Save0"));
			if (!Directory.Exists(pathOfSaveDirectory))
			{
				return null;
			}
			return pathOfSaveDirectory;
		}

		public static string RelativePath(string basePath, string fullPath)
		{
			return Path.GetFullPath(fullPath).Substring(Path.GetFullPath(basePath).Length).Replace('\\', '/')
				.TrimStart(new char[1] { '/' });
		}

		public static string RelativePathOrNull(string basePath, string fullPath)
		{
			string fullPath2 = Path.GetFullPath(basePath);
			string fullPath3 = Path.GetFullPath(fullPath);
			if (!fullPath3.StartsWith(fullPath2))
			{
				return null;
			}
			return RelativePath(fullPath2, fullPath3);
		}

		public static string DottedName(string relativePath)
		{
			return (relativePath.EndsWith(".py", StringComparison.OrdinalIgnoreCase) ? relativePath.Substring(0, relativePath.Length - ".py".Length) : relativePath).Replace('\\', '.').Replace('/', '.');
		}
	}
	internal sealed class TewrNameTooltip : MonoBehaviour, ITooltipHandler
	{
		private const float _delay = 0.4f;

		private TMP_Text _label;

		public TooltipInfo GetTooltipInfo(Action updateCallback)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			TMP_TextInfo val = (((Object)(object)_label == (Object)null) ? null : _label.textInfo);
			if (val == null || val.characterCount >= _label.text.Length)
			{
				return null;
			}
			return new TooltipInfo(_label.text, 0.4f, default(Vector3), (Anchor)0, "");
		}

		public void TooltipGone()
		{
		}

		internal static void Attach(TMP_Text label)
		{
			if (!((Object)(object)label == (Object)null) && !((Object)(object)((Component)label).gameObject.GetComponent<TewrNameTooltip>() != (Object)null))
			{
				GameObject gameObject = ((Component)label).gameObject;
				gameObject.AddComponent<TewrNameTooltip>()._label = label;
				gameObject.AddComponent<TooltipAccessor>().tooltipHandler = gameObject;
			}
		}
	}
	internal sealed class TewrResizeHandle : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IBeginDragHandler, IDragHandler, IEndDragHandler
	{
		private static readonly Color _idleColor = new Color(1f, 1f, 1f, 0f);

		private static readonly Color _hoverColor = new Color(1f, 1f, 1f, 0.18f);

		private static readonly Color _dragColor = new Color(1f, 1f, 1f, 0.3f);

		private Image _image;

		private bool _hot;

		private Action<PointerEventData> _onBegin;

		private Action<PointerEventData> _onUpdate;

		private Action _onEnd;

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			_image = ((Component)this).GetComponent<Image>();
			((Graphic)_image).color = _idleColor;
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			_hot = true;
			((Graphic)_image).color = _hoverColor;
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			_hot = false;
			((Graphic)_image).color = _idleColor;
		}

		public void OnBeginDrag(PointerEventData eventData)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)_image).color = _dragColor;
			_onBegin?.Invoke(eventData);
		}

		public void OnDrag(PointerEventData eventData)
		{
			_onUpdate?.Invoke(eventData);
		}

		public void OnEndDrag(PointerEventData eventData)
		{
			//IL_0015: 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)
			((Graphic)_image).color = (_hot ? _hoverColor : _idleColor);
			_onEnd?.Invoke();
		}

		internal static TewrResizeHandle Attach(GameObject target, Action<PointerEventData> onBegin, Action<PointerEventData> onUpdate, Action onEnd)
		{
			if ((Object)(object)target == (Object)null)
			{
				return null;
			}
			TewrResizeHandle tewrResizeHandle = target.GetComponent<TewrResizeHandle>();
			if ((Object)(object)tewrResizeHandle == (Object)null)
			{
				tewrResizeHandle = target.AddComponent<TewrResizeHandle>();
			}
			tewrResizeHandle._onBegin = onBegin;
			tewrResizeHandle._onUpdate = onUpdate;
			tewrResizeHandle._onEnd = onEnd;
			return tewrResizeHandle;
		}
	}
	internal sealed class TewrScrollForwarder : MonoBehaviour, IScrollHandler, IEventSystemHandler
	{
		private ScrollRect _target;

		public void OnScroll(PointerEventData eventData)
		{
			if ((Object)(object)_target != (Object)null && ((Behaviour)_target).enabled && ((Component)_target).gameObject.activeInHierarchy)
			{
				_target.OnScroll(eventData);
			}
		}

		internal static void Attach(GameObject target, ScrollRect scroll)
		{
			if (!((Object)(object)target == (Object)null))
			{
				TewrScrollForwarder tewrScrollForwarder = target.GetComponent<TewrScrollForwarder>();
				if ((Object)(object)tewrScrollForwarder == (Object)null)
				{
					tewrScrollForwarder = target.AddComponent<TewrScrollForwarder>();
				}
				tewrScrollForwarder._target = scroll;
			}
		}
	}
	internal sealed class TewrTextTooltip : MonoBehaviour, ITooltipHandler
	{
		private const float _delay = 0.4f;

		private string _text;

		internal string Text
		{
			get
			{
				return _text;
			}
			set
			{
				_text = value;
			}
		}

		public TooltipInfo GetTooltipInfo(Action updateCallback)
		{
			//IL_001a: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			if (!string.IsNullOrEmpty(_text))
			{
				return new TooltipInfo(_text, 0.4f, default(Vector3), (Anchor)0, "");
			}
			return null;
		}

		public void TooltipGone()
		{
		}

		internal static TewrTextTooltip Attach(GameObject target, string text)
		{
			if ((Object)(object)target == (Object)null)
			{
				return null;
			}
			TewrTextTooltip tewrTextTooltip = target.GetComponent<TewrTextTooltip>();
			if ((Object)(object)tewrTextTooltip == (Object)null)
			{
				tewrTextTooltip = target.AddComponent<TewrTextTooltip>();
			}
			tewrTextTooltip._text = text;
			if ((Object)(object)target.GetComponent<TooltipAccessor>() == (Object)null)
			{
				target.AddComponent<TooltipAccessor>().tooltipHandler = target;
			}
			return tewrTextTooltip;
		}
	}
	internal static class UiFactory
	{
		public static TextMeshProUGUI CreateTmpText(RectTransform parent, string name, float fontSize, Color color, TextAlignmentOptions alignment)
		{
			//IL_0021: 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_004e: 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_006e: 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_0088: 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>();
			((TMP_Text)component).transform.SetParent((Transform)(object)parent, false);
			((TMP_Text)component).rectTransform.anchorMin = Vector2.zero;
			((TMP_Text)component).rectTransform.anchorMax = Vector2.one;
			((TMP_Text)component).rectTransform.offsetMin = Vector2.zero;
			((TMP_Text)component).rectTransform.offsetMax = Vector2.zero;
			((TMP_Text)component).fontSize = fontSize;
			((TMP_Text)component).alignment = alignment;
			((Graphic)component).color = color;
			((TMP_Text)component).richText = false;
			return component;
		}

		public static Image CreateIcon(RectTransform parent, string name, Sprite sprite, Color color, float size, Vector2 position)
		{
			//IL_0021: 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_0064: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			Image component = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<Image>();
			((Component)component).transform.SetParent((Transform)(object)parent, false);
			component.sprite = sprite;
			((Graphic)component).color = color;
			((Graphic)component).raycastTarget = false;
			component.preserveAspect = true;
			((Graphic)component).rectTransform.anchorMin = new Vector2(0f, 0.5f);
			((Graphic)component).rectTransform.anchorMax = new Vector2(0f, 0.5f);
			((Graphic)component).rectTransform.pivot = new Vector2(0.5f, 0.5f);
			((Graphic)component).rectTransform.sizeDelta = new Vector2(size, size);
			((Graphic)component).rectTransform.anchoredPosition = position;
			return component;
		}

		public static RectTransform CreateIconButton(string name, Transform parent, Color backgroundColor, Sprite iconSprite, Vector2 iconInset, out Button button)
		{
			//IL_002e: 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_0079: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			}).GetComponent<RectTransform>();
			((Component)component).transform.SetParent(parent, false);
			Image component2 = ((Component)component).GetComponent<Image>();
			((Graphic)component2).color = backgroundColor;
			Image component3 = new GameObject("Icon", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<Image>();
			((Component)component3).transform.SetParent((Transform)(object)component, false);
			component3.sprite = iconSprite;
			((Graphic)component3).color = Color.white;
			((Graphic)component3).raycastTarget = false;
			component3.preserveAspect = true;
			((Graphic)component3).rectTransform.anchorMin = Vector2.zero;
			((Graphic)component3).rectTransform.anchorMax = Vector2.one;
			((Graphic)component3).rectTransform.offsetMin = iconInset;
			((Graphic)component3).rectTransform.offsetMax = -iconInset;
			button = ((Component)component