Decompiled source of AdminQoL v1.0.2

AdminQoL.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ConsolePanel;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.U2D;
using UnityEngine.UI;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.ObjectPool;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AdminQoL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("sighsorry")]
[assembly: AssemblyProduct("AdminQoL")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 LocalizationManager
{
	[PublicAPI]
	public class Localizer
	{
		private static readonly Dictionary<string, Dictionary<string, Func<string>>> PlaceholderProcessors;

		private static readonly Dictionary<string, Dictionary<string, string>> loadedTexts;

		private static readonly ConditionalWeakTable<Localization, string> localizationLanguage;

		private static readonly List<WeakReference<Localization>> localizationObjects;

		private static BaseUnityPlugin? _plugin;

		private static readonly List<string> fileExtensions;

		private static BaseUnityPlugin plugin
		{
			get
			{
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Expected O, but got Unknown
				if (_plugin == null)
				{
					IEnumerable<TypeInfo> source;
					try
					{
						source = Assembly.GetExecutingAssembly().DefinedTypes.ToList();
					}
					catch (ReflectionTypeLoadException ex)
					{
						source = from t in ex.Types
							where t != null
							select t.GetTypeInfo();
					}
					_plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		public static event Action? OnLocalizationComplete;

		private static void UpdatePlaceholderText(Localization localization, string key)
		{
			localizationLanguage.TryGetValue(localization, out string value);
			string text = loadedTexts[value][key];
			if (PlaceholderProcessors.TryGetValue(key, out Dictionary<string, Func<string>> value2))
			{
				text = value2.Aggregate(text, (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value()));
			}
			localization.AddWord(key, text);
		}

		public static void AddPlaceholder<T>(string key, string placeholder, ConfigEntry<T> config, Func<T, string>? convertConfigValue = null) where T : notnull
		{
			string key2 = key;
			string placeholder2 = placeholder;
			Func<T, string> convertConfigValue2 = convertConfigValue;
			ConfigEntry<T> config2 = config;
			if (convertConfigValue2 == null)
			{
				convertConfigValue2 = (T val) => val.ToString();
			}
			if (!PlaceholderProcessors.ContainsKey(key2))
			{
				PlaceholderProcessors[key2] = new Dictionary<string, Func<string>>();
			}
			config2.SettingChanged += delegate
			{
				UpdatePlaceholder();
			};
			if (loadedTexts.ContainsKey(Localization.instance.GetSelectedLanguage()))
			{
				UpdatePlaceholder();
			}
			void UpdatePlaceholder()
			{
				PlaceholderProcessors[key2][placeholder2] = () => convertConfigValue2(config2.Value);
				UpdatePlaceholderText(Localization.instance, key2);
			}
		}

		public static void AddText(string key, string text)
		{
			List<WeakReference<Localization>> list = new List<WeakReference<Localization>>();
			foreach (WeakReference<Localization> localizationObject in localizationObjects)
			{
				if (localizationObject.TryGetTarget(out var target))
				{
					Dictionary<string, string> dictionary = loadedTexts[localizationLanguage.GetOrCreateValue(target)];
					if (!target.m_translations.ContainsKey(key))
					{
						dictionary[key] = text;
						target.AddWord(key, text);
					}
				}
				else
				{
					list.Add(localizationObject);
				}
			}
			foreach (WeakReference<Localization> item in list)
			{
				localizationObjects.Remove(item);
			}
		}

		public static void Load()
		{
			_ = plugin;
		}

		public static void LoadLocalizationLater(Localization __instance)
		{
			LoadLocalization(Localization.instance, __instance.GetSelectedLanguage());
		}

		public static void SafeCallLocalizeComplete()
		{
			Localizer.OnLocalizationComplete?.Invoke();
		}

		private static void LoadLocalization(Localization __instance, string language)
		{
			if (!localizationLanguage.Remove(__instance))
			{
				localizationObjects.Add(new WeakReference<Localization>(__instance));
			}
			localizationLanguage.Add(__instance, language);
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (string item in from f in Directory.GetFiles(Path.GetDirectoryName(Paths.PluginPath), plugin.Info.Metadata.Name + ".*", SearchOption.AllDirectories)
				where fileExtensions.IndexOf(Path.GetExtension(f)) >= 0
				select f)
			{
				string[] array = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' });
				if (array.Length >= 2)
				{
					string text = array[1];
					if (dictionary.ContainsKey(text))
					{
						Debug.LogWarning((object)("Duplicate key " + text + " found for " + plugin.Info.Metadata.Name + ". The duplicate file found at " + item + " will be skipped."));
					}
					else
					{
						dictionary[text] = item;
					}
				}
			}
			byte[] array2 = LoadTranslationFromAssembly("English");
			if (array2 == null)
			{
				throw new Exception("Found no English localizations in mod " + plugin.Info.Metadata.Name + ". Expected an embedded resource translations/English.json or translations/English.yml.");
			}
			Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(Encoding.UTF8.GetString(array2));
			if (dictionary2 == null)
			{
				throw new Exception("Localization for mod " + plugin.Info.Metadata.Name + " failed: Localization file was empty.");
			}
			string text2 = null;
			if (language != "English")
			{
				if (dictionary.TryGetValue(language, out var value))
				{
					text2 = File.ReadAllText(value);
				}
				else
				{
					byte[] array3 = LoadTranslationFromAssembly(language);
					if (array3 != null)
					{
						text2 = Encoding.UTF8.GetString(array3);
					}
				}
			}
			if (text2 == null && dictionary.TryGetValue("English", out var value2))
			{
				text2 = File.ReadAllText(value2);
			}
			if (text2 != null)
			{
				foreach (KeyValuePair<string, string> item2 in new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(text2) ?? new Dictionary<string, string>())
				{
					dictionary2[item2.Key] = item2.Value;
				}
			}
			loadedTexts[language] = dictionary2;
			foreach (KeyValuePair<string, string> item3 in dictionary2)
			{
				UpdatePlaceholderText(__instance, item3.Key);
			}
		}

		static Localizer()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			PlaceholderProcessors = new Dictionary<string, Dictionary<string, Func<string>>>();
			loadedTexts = new Dictionary<string, Dictionary<string, string>>();
			localizationLanguage = new ConditionalWeakTable<Localization, string>();
			localizationObjects = new List<WeakReference<Localization>>();
			fileExtensions = new List<string>(2) { ".json", ".yml" };
			Harmony val = new Harmony("org.bepinex.helpers.LocalizationManager");
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "SetupLanguage", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "SetupGui", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalizationLater", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "SafeCallLocalizeComplete", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static byte[]? LoadTranslationFromAssembly(string language)
		{
			foreach (string fileExtension in fileExtensions)
			{
				byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension);
				if (array != null)
				{
					return array;
				}
			}
			return null;
		}

		public static byte[]? ReadEmbeddedFileBytes(string resourceFileName, Assembly? containingAssembly = null)
		{
			string resourceFileName2 = resourceFileName;
			using MemoryStream memoryStream = new MemoryStream();
			if ((object)containingAssembly == null)
			{
				containingAssembly = Assembly.GetCallingAssembly();
			}
			string text = containingAssembly.GetManifestResourceNames().FirstOrDefault((string str) => str.EndsWith(resourceFileName2, StringComparison.Ordinal));
			if (text != null)
			{
				containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream);
			}
			return (memoryStream.Length == 0L) ? null : memoryStream.ToArray();
		}
	}
	public static class LocalizationManagerVersion
	{
		public const string Version = "1.4.1";
	}
}
namespace ConsolePanel
{
	internal static class ConsoleCommandOwnership
	{
		[StructLayout(LayoutKind.Auto)]
		[CompilerGenerated]
		private struct <>c__DisplayClass21_0
		{
			public HashSet<string> aliases;
		}

		[CompilerGenerated]
		private sealed class <GetPluginAliases>d__21 : IEnumerable<string>, IEnumerable, IEnumerator<string>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private string <>2__current;

			private int <>l__initialThreadId;

			private PluginInfo pluginInfo;

			public PluginInfo <>3__pluginInfo;

			private HashSet<string>.Enumerator <>7__wrap1;

			string IEnumerator<string>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GetPluginAliases>d__21(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>7__wrap1 = default(HashSet<string>.Enumerator);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
					{
						<>1__state = -1;
						<>c__DisplayClass21_0 <>c__DisplayClass21_ = default(<>c__DisplayClass21_0);
						<>c__DisplayClass21_.aliases = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
						<GetPluginAliases>g__AddAlias|21_0(pluginInfo.Metadata.Name, ref <>c__DisplayClass21_);
						<GetPluginAliases>g__AddAlias|21_0(pluginInfo.Metadata.GUID, ref <>c__DisplayClass21_);
						string location = pluginInfo.Location;
						if (!string.IsNullOrWhiteSpace(location))
						{
							<GetPluginAliases>g__AddAlias|21_0(Path.GetFileNameWithoutExtension(location), ref <>c__DisplayClass21_);
							string fileName = Path.GetFileName(Path.GetDirectoryName(location) ?? "");
							<GetPluginAliases>g__AddAlias|21_0(fileName, ref <>c__DisplayClass21_);
							if (!string.IsNullOrWhiteSpace(fileName))
							{
								int num = fileName.IndexOf('-');
								if (num >= 0 && num + 1 < fileName.Length)
								{
									<GetPluginAliases>g__AddAlias|21_0(fileName.Substring(num + 1), ref <>c__DisplayClass21_);
								}
							}
						}
						<>7__wrap1 = <>c__DisplayClass21_.aliases.GetEnumerator();
						<>1__state = -3;
						break;
					}
					case 1:
						<>1__state = -3;
						break;
					}
					if (<>7__wrap1.MoveNext())
					{
						string current = <>7__wrap1.Current;
						<>2__current = current;
						<>1__state = 1;
						return true;
					}
					<>m__Finally1();
					<>7__wrap1 = default(HashSet<string>.Enumerator);
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap1).Dispose();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<string> IEnumerable<string>.GetEnumerator()
			{
				<GetPluginAliases>d__21 <GetPluginAliases>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<GetPluginAliases>d__ = this;
				}
				else
				{
					<GetPluginAliases>d__ = new <GetPluginAliases>d__21(0);
				}
				<GetPluginAliases>d__.pluginInfo = <>3__pluginInfo;
				return <GetPluginAliases>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<string>)this).GetEnumerator();
			}
		}

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

		private static readonly HashSet<string> CommonAliasTokens = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
		{
			"a", "an", "and", "the", "mod", "mods", "plugin", "plugins", "valheim", "configuration",
			"config", "manager", "command", "commands", "data", "world", "expand", "json", "yaml", "dotnet",
			"detector"
		};

		private static int _terminalInitDepth;

		internal static int Version { get; private set; }

		internal static void EnterTerminalInit()
		{
			_terminalInitDepth++;
		}

		internal static void ExitTerminalInit()
		{
			_terminalInitDepth = Mathf.Max(0, _terminalInitDepth - 1);
		}

		internal static void MarkDirty()
		{
			Version++;
		}

		internal static void Record(ConsoleCommand command)
		{
			if (command != null && !string.IsNullOrWhiteSpace(command.Command))
			{
				string value = DetectOwner(command.Command);
				if (!string.IsNullOrWhiteSpace(value))
				{
					Owners[command.Command] = value;
				}
				Version++;
			}
		}

		internal static string GetOwner(string commandName)
		{
			if (!string.IsNullOrWhiteSpace(commandName) && Owners.TryGetValue(commandName, out string value))
			{
				return value;
			}
			return InferOwner(commandName);
		}

		private static string DetectOwner(string commandName)
		{
			string text = InferOwnerFromExplicitCommandName(commandName);
			if (!string.IsNullOrWhiteSpace(text))
			{
				return text;
			}
			StackTrace stackTrace = new StackTrace(fNeedFileInfo: false);
			bool flag = _terminalInitDepth > 0;
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			for (int i = 0; i < stackTrace.FrameCount; i++)
			{
				Assembly assembly = (stackTrace.GetFrame(i)?.GetMethod())?.DeclaringType?.Assembly;
				if (assembly == null)
				{
					continue;
				}
				string text2 = assembly.GetName().Name ?? "";
				if (text2.Equals("assembly_valheim", StringComparison.OrdinalIgnoreCase))
				{
					flag = true;
				}
				else if ((object)assembly != executingAssembly && !ShouldSkipAssembly(text2))
				{
					string text3 = TryFindPluginName(assembly);
					if (string.IsNullOrWhiteSpace(text3))
					{
						return text2;
					}
					if (!ShouldSkipOwner(text3))
					{
						return text3;
					}
				}
			}
			string text4 = InferOwner(commandName);
			if (!string.Equals(text4, "Other Mods", StringComparison.OrdinalIgnoreCase))
			{
				return text4;
			}
			if (!flag)
			{
				return text4;
			}
			return "Valheim";
		}

		private static bool ShouldSkipAssembly(string assemblyName)
		{
			if (string.IsNullOrWhiteSpace(assemblyName))
			{
				return true;
			}
			switch (assemblyName.ToLowerInvariant())
			{
			case "0harmony":
			case "mscorlib":
			case "jotunn":
			case "system":
			case "system.core":
			case "unityengine":
			case "bepinex":
			case "unityengine.coremodule":
				return true;
			default:
				return false;
			}
		}

		private static bool ShouldSkipOwner(string owner)
		{
			string text = NormalizeIdentifier(owner);
			if (text == "jotunn" || text == "valheimmoddingjotunn")
			{
				return true;
			}
			return false;
		}

		private static string? TryFindPluginName(Assembly assembly)
		{
			string text = SafeLocation(assembly);
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				BaseUnityPlugin instance = value.Instance;
				if ((Object)(object)instance != (Object)null && (object)((object)instance).GetType().Assembly == assembly)
				{
					return value.Metadata.Name;
				}
				if (!string.IsNullOrWhiteSpace(text) && string.Equals(SafePath(value.Location), text, StringComparison.OrdinalIgnoreCase))
				{
					return value.Metadata.Name;
				}
			}
			return null;
		}

		private static string InferOwner(string commandName)
		{
			string text = commandName?.Trim().ToLowerInvariant() ?? "";
			if (text.Length == 0)
			{
				return "Other Mods";
			}
			string text2 = InferOwnerFromExplicitCommandName(text);
			if (!string.IsNullOrWhiteSpace(text2))
			{
				return text2;
			}
			string text3 = InferOwnerFromLoadedPlugins(text);
			if (!string.IsNullOrWhiteSpace(text3))
			{
				return text3;
			}
			return "Other Mods";
		}

		private static string? InferOwnerFromExplicitCommandName(string? commandName)
		{
			string text = commandName?.Trim().ToLowerInvariant() ?? "";
			if (text.Length == 0)
			{
				return null;
			}
			if (text.StartsWith("adminqol_", StringComparison.OrdinalIgnoreCase))
			{
				return "AdminQoL";
			}
			if (text.StartsWith("dns:", StringComparison.OrdinalIgnoreCase) || text.StartsWith("dns_", StringComparison.OrdinalIgnoreCase))
			{
				return "DropNSpawn";
			}
			if (text.StartsWith("jewelcrafting", StringComparison.OrdinalIgnoreCase))
			{
				return "Jewelcrafting";
			}
			if (text.StartsWith("epicloot", StringComparison.OrdinalIgnoreCase) || text.StartsWith("magic", StringComparison.OrdinalIgnoreCase))
			{
				return "Epic Loot";
			}
			if (text.StartsWith("vnei_", StringComparison.OrdinalIgnoreCase))
			{
				return "VNEI";
			}
			if (text.StartsWith("esp_", StringComparison.OrdinalIgnoreCase) || string.Equals(text, "esp", StringComparison.OrdinalIgnoreCase))
			{
				return "ESP";
			}
			if (text.StartsWith("ew_mus", StringComparison.OrdinalIgnoreCase) || text.StartsWith("ew_music", StringComparison.OrdinalIgnoreCase))
			{
				return "Expand World Music";
			}
			if (text.StartsWith("ew_event", StringComparison.OrdinalIgnoreCase) || text.StartsWith("expand_events", StringComparison.OrdinalIgnoreCase))
			{
				return "Expand World Events";
			}
			if (text.StartsWith("ew_faction", StringComparison.OrdinalIgnoreCase) || text.StartsWith("expand_factions", StringComparison.OrdinalIgnoreCase))
			{
				return "Expand World Factions";
			}
			if (text.StartsWith("ew_", StringComparison.OrdinalIgnoreCase) || text.StartsWith("expand_", StringComparison.OrdinalIgnoreCase))
			{
				return "Expand World Data";
			}
			if (text.StartsWith("hammer_", StringComparison.OrdinalIgnoreCase) || string.Equals(text, "hammer", StringComparison.OrdinalIgnoreCase))
			{
				return "Infinity Hammer";
			}
			if (text.StartsWith("world_edit", StringComparison.OrdinalIgnoreCase))
			{
				return "World Edit Commands";
			}
			if (text.StartsWith("xray", StringComparison.OrdinalIgnoreCase))
			{
				return "XRayVision";
			}
			return null;
		}

		private static string? InferOwnerFromLoadedPlugins(string commandName)
		{
			string text = commandName?.Trim().ToLowerInvariant() ?? "";
			if (text.Length == 0)
			{
				return null;
			}
			string normalizedCommand = NormalizeIdentifier(text);
			string result = null;
			int num = 0;
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if (ShouldSkipOwner(value.Metadata.Name))
				{
					continue;
				}
				foreach (string pluginAlias in GetPluginAliases(value))
				{
					if (pluginAlias.Length > num && CommandStartsWithAlias(text, normalizedCommand, pluginAlias))
					{
						result = value.Metadata.Name;
						num = pluginAlias.Length;
					}
				}
			}
			return result;
		}

		private static bool CommandStartsWithAlias(string command, string normalizedCommand, string alias)
		{
			if (command.StartsWith(alias, StringComparison.OrdinalIgnoreCase))
			{
				if (command.Length != alias.Length)
				{
					return IsAliasBoundary(command[alias.Length]);
				}
				return true;
			}
			return normalizedCommand.StartsWith(alias, StringComparison.OrdinalIgnoreCase);
		}

		private static bool IsAliasBoundary(char value)
		{
			switch (value)
			{
			case ' ':
			case '-':
			case '.':
			case ':':
			case '_':
				return true;
			default:
				return false;
			}
		}

		[IteratorStateMachine(typeof(<GetPluginAliases>d__21))]
		private static IEnumerable<string> GetPluginAliases(PluginInfo pluginInfo)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetPluginAliases>d__21(-2)
			{
				<>3__pluginInfo = pluginInfo
			};
		}

		private static IEnumerable<string> SplitIdentifierTokens(string value)
		{
			return value.Replace('.', ' ').Replace('_', ' ').Replace('-', ' ')
				.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
		}

		private static string NormalizeIdentifier(string value)
		{
			if (string.IsNullOrWhiteSpace(value))
			{
				return "";
			}
			return new string(value.Where(char.IsLetterOrDigit).Select(char.ToLowerInvariant).ToArray());
		}

		private static string SafeLocation(Assembly assembly)
		{
			try
			{
				return SafePath(assembly.Location);
			}
			catch
			{
				return "";
			}
		}

		private static string SafePath(string path)
		{
			try
			{
				return string.IsNullOrWhiteSpace(path) ? "" : Path.GetFullPath(path);
			}
			catch
			{
				return path ?? "";
			}
		}

		[CompilerGenerated]
		internal static void <GetPluginAliases>g__AddAlias|21_0(string? raw, ref <>c__DisplayClass21_0 P_1)
		{
			if (string.IsNullOrWhiteSpace(raw))
			{
				return;
			}
			string text = NormalizeIdentifier(raw);
			if (text.Length >= 3 && !CommonAliasTokens.Contains(text))
			{
				P_1.aliases.Add(text);
			}
			List<string> list = (from token in SplitIdentifierTokens(raw).Select(NormalizeIdentifier)
				where token.Length >= 3 && !CommonAliasTokens.Contains(token)
				select token).ToList();
			foreach (string item in list)
			{
				P_1.aliases.Add(item);
			}
			string text2 = string.Concat(list.Select((string token) => token[0]));
			if (text2.Length >= 2 && !CommonAliasTokens.Contains(text2))
			{
				P_1.aliases.Add(text2);
			}
		}
	}
	internal static class ConsoleCommandCatalog
	{
		internal static List<CommandEntry> CaptureVisibleCommands(Console? console)
		{
			List<CommandEntry> list = new List<CommandEntry>();
			foreach (KeyValuePair<string, ConsoleCommand> command in Terminal.commands)
			{
				ConsoleCommand value = command.Value;
				if (value == null || string.IsNullOrWhiteSpace(value.Command))
				{
					continue;
				}
				if ((Object)(object)console != (Object)null)
				{
					try
					{
						if (!value.ShowCommand((Terminal)(object)console))
						{
							continue;
						}
					}
					catch
					{
						continue;
					}
				}
				string text = ConsoleCommandOwnership.GetOwner(value.Command);
				if (string.Equals(text, "Other Mods", StringComparison.OrdinalIgnoreCase) && IsLikelyValheimCommand(value.Command))
				{
					text = "Valheim";
				}
				list.Add(new CommandEntry(value.Command, value.Description ?? "", text));
			}
			AddCompatibilityCommands(list);
			return list;
		}

		internal static int OwnerSortWeight(string owner)
		{
			if (string.Equals(owner, "Valheim", StringComparison.OrdinalIgnoreCase))
			{
				return 0;
			}
			if (string.Equals(owner, "AdminQoL", StringComparison.OrdinalIgnoreCase))
			{
				return 1;
			}
			if (string.Equals(owner, "Other Mods", StringComparison.OrdinalIgnoreCase))
			{
				return 1000;
			}
			return 10;
		}

		private static void AddCompatibilityCommands(List<CommandEntry> entries)
		{
			AddCreatureLevelControlCommands(entries);
		}

		private static void AddCreatureLevelControlCommands(List<CommandEntry> entries)
		{
			if (IsPluginLoaded("org.bepinex.plugins.creaturelevelcontrol"))
			{
				entries.Add(new CommandEntry("cllc", "Show Creature Level & Loot Control command help.", "Creature Level & Loot Control"));
				entries.Add(new CommandEntry("cllc killall", "Remove all nearby creatures.", "Creature Level & Loot Control"));
				entries.Add(new CommandEntry("cllc killhighstars", "Remove nearby creatures with at least the given stars. Optional: [stars], default 6.", "Creature Level & Loot Control"));
				entries.Add(new CommandEntry("cllc worldlevel", "Display the current world level.", "Creature Level & Loot Control"));
				entries.Add(new CommandEntry("cllc sectorkills", "Display creatures killed in the current sector.", "Creature Level & Loot Control"));
				entries.Add(new CommandEntry("cllc resetsector", "Reset nearby creature sectors.", "Creature Level & Loot Control"));
				entries.Add(new CommandEntry("cllc starchance", "Display current star chances. Optional: [creature].", "Creature Level & Loot Control"));
				entries.Add(new CommandEntry("cllc spawn", "Spawn a creature. Args: [creature] [level] [affix] [extraeffect] [infusion].", "Creature Level & Loot Control"));
			}
		}

		private static bool IsPluginLoaded(string guid)
		{
			string guid2 = guid;
			return Chainloader.PluginInfos.Values.Any((PluginInfo pluginInfo) => string.Equals(pluginInfo.Metadata.GUID, guid2, StringComparison.OrdinalIgnoreCase));
		}

		private static bool IsLikelyValheimCommand(string command)
		{
			string command2 = command;
			return new string[25]
			{
				"help", "devcommands", "debugmode", "spawn", "itemset", "god", "fly", "ghost", "freefly", "save",
				"ping", "kick", "ban", "unban", "banned", "resetknownitems", "resetcharacter", "resetplayerprefs", "setkey", "removekey",
				"resetkeys", "players", "fov", "info", "gc"
			}.Any((string hint) => string.Equals(command2, hint, StringComparison.OrdinalIgnoreCase));
		}
	}
	internal static class ConsolePanelConfig
	{
		internal const string PanelSection = "3 - Console Panel";

		internal const string FavoritesSection = "4 - Console Panel Favorites";
	}
	internal static class ConsolePanelLayout
	{
		internal const int MaxFavoriteTabs = 5;

		internal const int CanvasSortingOrder = 5000;

		internal const int UiLayer = 5;

		internal const float DefaultPanelWidth = 900f;

		internal const float DefaultPanelHeight = 450f;

		internal const float DefaultVanillaConsoleBottomOffset = 120f;

		internal const float PanelLeft = 5f;

		internal const float RowHeight = 30f;

		internal const float ScrollbarWidth = 2f;

		internal const float ScrollSensitivity = 240f;

		internal const float CommandRefreshSeconds = 3f;

		internal const float PanelGapBelowConsole = 30f;

		internal const float CategoryWidth = 150f;

		internal const float MinPanelWidth = 360f;

		internal const float MinPanelHeight = 180f;

		internal const float MinCategoryWidth = 80f;

		internal const float MaxCategoryWidthRatio = 0.45f;

		internal const float Gutter = 8f;

		internal const float MinCommandHeaderWidth = 160f;

		internal const float SearchReservedWidth = 180f;

		internal const float SearchExtraWidth = 120f;

		internal const float SearchMinWidth = 150f;

		internal const float FavoriteActionSpacing = 3f;

		internal const float FavoriteActionButtonWidth = 20f;

		internal const float CompactButtonMinWidth = 14f;

		internal const float CompactButtonPreferredWidth = 18f;

		internal const float VirtualCommandPadding = 4f;

		internal const float VirtualCommandSpacing = 4f;

		internal const int VirtualCommandLookBehindRows = 2;

		internal const int VirtualCommandLookAheadRows = 6;

		internal const int CommandPreviewCount = 5;

		internal const int ManualClickSuppressionFrames = 3;
	}
	internal static class ConsolePanelInputBlock
	{
		private static bool _active;

		private static bool _hasStoredMouseCapture;

		private static bool _previousMouseCapture;

		internal static bool IsActive => _active;

		internal static void SetActive(bool active, bool releaseMouseCapture = false)
		{
			if (_active == active)
			{
				if (active && releaseMouseCapture)
				{
					ApplyMouseCaptureBlock();
				}
				else if (active)
				{
					RestoreMouseCapture();
				}
			}
			else
			{
				_active = active;
				if (active && releaseMouseCapture)
				{
					ApplyMouseCaptureBlock();
				}
				else
				{
					RestoreMouseCapture();
				}
			}
		}

		private static void ApplyMouseCaptureBlock()
		{
			GameCamera instance = GameCamera.instance;
			if (!((Object)(object)instance == (Object)null))
			{
				if (!_hasStoredMouseCapture)
				{
					_previousMouseCapture = instance.m_mouseCapture;
					_hasStoredMouseCapture = true;
				}
				instance.m_mouseCapture = false;
				instance.UpdateMouseCapture();
			}
		}

		private static void RestoreMouseCapture()
		{
			GameCamera instance = GameCamera.instance;
			if ((Object)(object)instance != (Object)null && _hasStoredMouseCapture)
			{
				instance.m_mouseCapture = _previousMouseCapture;
				instance.UpdateMouseCapture();
			}
			_hasStoredMouseCapture = false;
		}
	}
	internal static class ConsolePanelModule
	{
		internal static ConfigEntry<float> PanelWidth;

		internal static ConfigEntry<float> PanelHeight;

		internal static ConfigEntry<float> VanillaConsoleBottomOffset;

		internal static ConfigEntry<bool> ReleaseMouseCursor;

		internal static ConfigEntry<KeyboardShortcut> TogglePanelKey;

		internal static ConfigEntry<PanelVisualStyle> VisualStyle;

		internal static ConfigEntry<int> FavoriteTabCount;

		internal static ConfigEntry<string>[] FavoriteTabCommands;

		private static ConfigFile? ConfigFile;

		private static ConsolePanelController? Controller;

		internal static void Initialize(GameObject host, ConfigFile config)
		{
			//IL_00ae: 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_00e9: Expected O, but got Unknown
			ConfigFile = config;
			PanelWidth = config.Bind<float>("3 - Console Panel", "Panel Width", 900f, "Width of the command browser panel.");
			PanelHeight = config.Bind<float>("3 - Console Panel", "Panel Height", 450f, "Maximum height of the command browser panel. The panel shrinks if needed to preserve the fixed gap below the console.");
			VanillaConsoleBottomOffset = config.Bind<float>("3 - Console Panel", "Vanilla Console Bottom Offset", 120f, "Bottom Y offset applied to Valheim's own console rect while the console is visible.");
			VisualStyle = config.Bind<PanelVisualStyle>("3 - Console Panel", "Panel Visual Style", PanelVisualStyle.Modern, "Visual style for ConsolePanel. Wood uses Valheim-style wood panels, Modern uses ConfigurationManager-like flat panels.");
			ReleaseMouseCursor = config.Bind<bool>("3 - Console Panel", "Release Mouse Cursor", true, "Unlock and show the mouse cursor while the F5 console panel is visible so category, command, and favorite buttons can be clicked.");
			TogglePanelKey = config.Bind<KeyboardShortcut>("3 - Console Panel", "Toggle Panel Key", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), "Keyboard shortcut that toggles ConsolePanel while Valheim's F5 console is visible.");
			FavoriteTabCount = config.Bind<int>("4 - Console Panel Favorites", "Favorite Tab Count", 3, new ConfigDescription("Number of numbered favorite command tabs to show.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5), Array.Empty<object>()));
			FavoriteTabCommands = new ConfigEntry<string>[5];
			for (int i = 0; i < 5; i++)
			{
				FavoriteTabCommands[i] = config.Bind<string>("4 - Console Panel Favorites", $"Favorite {i + 1} Commands", "", $"Pipe-separated favorite console commands for numbered favorite tab {i + 1}.");
			}
			FavoriteTabCount.SettingChanged += delegate
			{
				Controller?.OnFavoriteConfigChanged();
			};
			for (int j = 0; j < 5; j++)
			{
				FavoriteTabCommands[j].SettingChanged += delegate
				{
					Controller?.OnFavoriteConfigChanged();
				};
			}
			if ((Object)(object)Controller == (Object)null)
			{
				Controller = host.AddComponent<ConsolePanelController>();
			}
		}

		internal static void Shutdown()
		{
			if ((Object)(object)Controller != (Object)null)
			{
				Object.Destroy((Object)(object)Controller);
				Controller = null;
			}
			ConfigFile? configFile = ConfigFile;
			if (configFile != null)
			{
				configFile.Save();
			}
			ConfigFile = null;
		}

		internal static void SaveConfig()
		{
			ConfigFile? configFile = ConfigFile;
			if (configFile != null)
			{
				configFile.Save();
			}
		}

		internal static void UpdateConfigWithoutImmediateSave(Func<bool> update)
		{
			if (ConfigFile != null)
			{
				bool saveOnConfigSet = ConfigFile.SaveOnConfigSet;
				ConfigFile.SaveOnConfigSet = false;
				try
				{
					if (update())
					{
						ConfigFile.Save();
					}
					return;
				}
				finally
				{
					ConfigFile.SaveOnConfigSet = saveOnConfigSet;
				}
			}
			if (update())
			{
				SaveConfig();
			}
		}

		internal static void Diagnostic(string message)
		{
		}
	}
	[HarmonyPatch]
	internal static class ConsoleCommandConstructorPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return typeof(ConsoleCommand).GetConstructors(BindingFlags.Instance | BindingFlags.Public);
		}

		private static void Postfix(ConsoleCommand __instance)
		{
			ConsoleCommandOwnership.Record(__instance);
		}
	}
	[HarmonyPatch(typeof(Terminal), "InitTerminal")]
	internal static class TerminalInitPatch
	{
		private static void Prefix()
		{
			ConsoleCommandOwnership.EnterTerminalInit();
		}

		private static void Postfix()
		{
			ConsoleCommandOwnership.ExitTerminalInit();
			ConsoleCommandOwnership.MarkDirty();
		}
	}
	[HarmonyPatch(typeof(Console), "Update")]
	internal static class ConsoleUpdateLayoutPatch
	{
		[HarmonyPriority(800)]
		private static void Postfix()
		{
			ConsolePanelController.ApplyAfterVanillaConsoleUpdate();
		}
	}
	[HarmonyPatch(typeof(TMP_InputField), "ActivateInputField")]
	internal static class ConsoleInputActivatePatch
	{
		private static bool Prefix(TMP_InputField __instance)
		{
			return !ConsolePanelController.ShouldBlockConsoleInputActivation(__instance);
		}
	}
	[HarmonyPatch(typeof(Player), "TakeInput")]
	internal static class PlayerTakeInputPatch
	{
		private static void Postfix(ref bool __result)
		{
			if (ConsolePanelInputBlock.IsActive)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController), "TakeInput")]
	internal static class PlayerControllerTakeInputPatch
	{
		private static void Postfix(ref bool __result)
		{
			if (ConsolePanelInputBlock.IsActive)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(TextInput), "IsVisible")]
	internal static class ConsolePanelTextInputVisiblePatch
	{
		private static void Postfix(ref bool __result)
		{
			if (ConsolePanelInputBlock.IsActive && ConsolePanelModule.ReleaseMouseCursor.Value)
			{
				__result = true;
			}
		}
	}
	internal sealed class ConsolePanelController : MonoBehaviour
	{
		private enum SurfaceRole
		{
			Panel,
			Header,
			Search,
			Scroll,
			Info,
			MutedInfo,
			Button,
			FavoriteBar,
			Tooltip,
			ScrollbarBackground,
			ScrollbarHandle
		}

		private sealed class CommandRowView
		{
			private readonly ConsolePanelController _owner;

			private readonly Button _commandButton;

			private readonly TextMeshProUGUI? _commandLabel;

			private readonly Transform _actionsTransform;

			private readonly LayoutElement _actionElement;

			private readonly List<Button> _favoriteButtons = new List<Button>();

			private readonly List<LayoutElement> _favoriteButtonLayouts = new List<LayoutElement>();

			private ManualHoverTooltip? _tooltip;

			private CommandEntry _entry;

			private bool _hasEntry;

			internal RectTransform RectTransform { get; }

			internal CommandRowView(ConsolePanelController owner, Transform parent)
			{
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Expected O, but got Unknown
				//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: Expected O, but got Unknown
				_owner = owner;
				GameObject val = CreateUiObject("CommandRow", parent);
				RectTransform = val.GetComponent<RectTransform>();
				HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)obj).spacing = 6f;
				((LayoutGroup)obj).padding = new RectOffset(4, 4, 2, 2);
				((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = true;
				((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false;
				_commandButton = owner.CreateButton(val.transform, "", delegate
				{
					if (_hasEntry)
					{
						_owner.PutCommandInInput(_entry);
					}
				});
				_commandLabel = ((Component)_commandButton).GetComponentInChildren<TextMeshProUGUI>(true);
				((Component)_commandButton).gameObject.AddComponent<LayoutElement>().flexibleWidth = 1f;
				GameObject val2 = CreateUiObject("FavoriteActions", val.transform);
				_actionsTransform = val2.transform;
				HorizontalLayoutGroup obj2 = val2.AddComponent<HorizontalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)obj2).spacing = 3f;
				((LayoutGroup)obj2).padding = new RectOffset(0, 0, 0, 0);
				((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = true;
				((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
				((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
				_actionElement = val2.AddComponent<LayoutElement>();
			}

			internal void SetActive(bool active)
			{
				if (((Component)RectTransform).gameObject.activeSelf != active)
				{
					((Component)RectTransform).gameObject.SetActive(active);
				}
			}

			internal void Bind(CommandEntry entry)
			{
				_entry = entry;
				_hasEntry = true;
				if ((Object)(object)_commandLabel != (Object)null)
				{
					((TMP_Text)_commandLabel).text = FormatCommandRowText(entry);
				}
				if (_owner.ShouldShowCommandSourceTooltip())
				{
					if (_tooltip == null)
					{
						_tooltip = ((Component)_commandButton).gameObject.AddComponent<ManualHoverTooltip>();
					}
					((Behaviour)_tooltip).enabled = true;
					_tooltip.Configure("Source: " + entry.Owner, _owner.ShowOwnerTooltip, _owner.HideOwnerTooltip);
				}
				else if ((Object)(object)_tooltip != (Object)null)
				{
					((Behaviour)_tooltip).enabled = false;
				}
				EnsureFavoriteButtons();
				float favoriteActionAreaWidth = GetFavoriteActionAreaWidth();
				_actionElement.minWidth = favoriteActionAreaWidth;
				_actionElement.preferredWidth = favoriteActionAreaWidth;
				_actionElement.flexibleWidth = 0f;
				int favoriteTabCount = GetFavoriteTabCount();
				for (int i = 0; i < _favoriteButtons.Count; i++)
				{
					Button val = _favoriteButtons[i];
					bool flag = i < favoriteTabCount;
					((Component)val).gameObject.SetActive(flag);
					if (flag)
					{
						if ((Object)(object)_favoriteButtonLayouts[i] != (Object)null)
						{
							float favoriteActionButtonWidth = GetFavoriteActionButtonWidth();
							_favoriteButtonLayouts[i].minWidth = favoriteActionButtonWidth;
							_favoriteButtonLayouts[i].preferredWidth = favoriteActionButtonWidth;
						}
						_owner.RegisterFavoriteActionButton(entry.Command, i, val);
						_owner.ApplySelectedButtonColor(val, _owner.IsFavoriteInTab(i, entry.Command));
					}
				}
				LayoutRebuilder.MarkLayoutForRebuild(RectTransform);
			}

			private void EnsureFavoriteButtons()
			{
				while (_favoriteButtons.Count < 5)
				{
					int targetIndex = _favoriteButtons.Count;
					Button val = _owner.CreateFavoriteActionButton(_actionsTransform, (targetIndex + 1).ToString(), delegate
					{
						if (_hasEntry)
						{
							_owner.ToggleFavorite(targetIndex, _entry.Command);
						}
					});
					_favoriteButtons.Add(val);
					_favoriteButtonLayouts.Add(((Component)val).GetComponent<LayoutElement>());
				}
			}
		}

		[CompilerGenerated]
		private sealed class <GetCategoryDisplayOrder>d__89 : IEnumerable<string>, IEnumerable, IEnumerator<string>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private string <>2__current;

			private int <>l__initialThreadId;

			public ConsolePanelController <>4__this;

			private List<string>.Enumerator <>7__wrap1;

			string IEnumerator<string>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GetCategoryDisplayOrder>d__89(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>7__wrap1 = default(List<string>.Enumerator);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				try
				{
					int num = <>1__state;
					ConsolePanelController consolePanelController = <>4__this;
					switch (num)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>7__wrap1 = consolePanelController._owners.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					}
					if (<>7__wrap1.MoveNext())
					{
						string current = <>7__wrap1.Current;
						<>2__current = current;
						<>1__state = 1;
						return true;
					}
					<>m__Finally1();
					<>7__wrap1 = default(List<string>.Enumerator);
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap1).Dispose();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<string> IEnumerable<string>.GetEnumerator()
			{
				<GetCategoryDisplayOrder>d__89 result;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					result = this;
				}
				else
				{
					result = new <GetCategoryDisplayOrder>d__89(0)
					{
						<>4__this = <>4__this
					};
				}
				return result;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<string>)this).GetEnumerator();
			}
		}

		private static ConsolePanelController? ActiveInstance;

		private static Sprite? SolidUiSprite;

		private readonly List<CommandEntry> _commands = new List<CommandEntry>();

		private readonly List<CommandEntry> _allRows = new List<CommandEntry>();

		private readonly Dictionary<string, List<CommandEntry>> _commandsByOwner = new Dictionary<string, List<CommandEntry>>(StringComparer.OrdinalIgnoreCase);

		private readonly Dictionary<string, CommandEntry> _commandsByName = new Dictionary<string, CommandEntry>(StringComparer.OrdinalIgnoreCase);

		private readonly Dictionary<string, List<FavoriteActionBinding>> _favoriteActionBindingsByCommand = new Dictionary<string, List<FavoriteActionBinding>>(StringComparer.OrdinalIgnoreCase);

		private readonly List<string> _owners = new List<string>();

		private readonly ConsolePanelFavoriteStore _favorites = new ConsolePanelFavoriteStore();

		private readonly List<CommandEntry> _renderedCommandRows = new List<CommandEntry>();

		private readonly List<CommandRowView> _commandRowPool = new List<CommandRowView>();

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

		private Canvas? _canvas;

		private RectTransform? _panel;

		private RectTransform? _headerRoot;

		private TextMeshProUGUI? _headerLabel;

		private RectTransform? _searchInputRoot;

		private TMP_InputField? _searchInputField;

		private RectTransform? _favoriteProfileRoot;

		private Transform? _favoriteProfileContent;

		private RectTransform? _categoryScroll;

		private RectTransform? _commandScroll;

		private RectTransform? _tooltipRoot;

		private TextMeshProUGUI? _tooltipLabel;

		private ScrollRect? _commandScrollRect;

		private ScrollRect? _categoryScrollRect;

		private Transform? _categoryContent;

		private Transform? _commandContent;

		private RectTransform? _emptyCommandRow;

		private TextMeshProUGUI? _emptyCommandLabel;

		private PanelImageStyle? _inventoryPanelStyle;

		private TMP_FontAsset? _font;

		private RectTransform? _vanillaConsoleRect;

		private RectTransformState? _originalVanillaConsoleRectState;

		private string _selectedOwner = "All";

		private string _searchText = "";

		private string _consoleInputSnapshot = "";

		private bool _visible;

		private bool _hasConsoleInputSnapshot;

		private bool _searchInputWanted;

		private bool _hasConsoleReadOnlySnapshot;

		private bool _consoleReadOnlySnapshot;

		private bool _consoleInteractableSnapshot;

		private bool _cursorCaptured;

		private bool _panelHiddenByHotkey;

		private bool _previousCursorVisible;

		private CursorLockMode _previousCursorLockState;

		private float _nextRefresh;

		private int _lastOwnershipVersion = -1;

		private int _lastCommandCount = -1;

		private bool _tmpDefaultFontApplied;

		private float _vanillaConsoleBottomFromPanelCanvas = -1f;

		private string? _lastRenderedOwner;

		private int _lastVirtualFirstIndex = -1;

		private int _lastVirtualRowCount = -1;

		private PanelVisualStyle _createdVisualStyle = (PanelVisualStyle)(-1);

		private const string AllOwner = "All";

		private const string FavoriteOwnerPrefix = "Favorite ";

		private const float VirtualCommandPadding = 4f;

		private const float VirtualCommandSpacing = 4f;

		private void Awake()
		{
			ActiveInstance = this;
			LoadFavorites();
		}

		private void OnDestroy()
		{
			if ((Object)(object)ActiveInstance == (Object)(object)this)
			{
				ActiveInstance = null;
			}
			ConsolePanelInputBlock.SetActive(active: false);
			RestoreCursor();
			RestoreVanillaConsoleLayout();
			if ((Object)(object)_canvas != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_canvas).gameObject);
			}
		}

		internal static void ApplyAfterVanillaConsoleUpdate()
		{
			ActiveInstance?.ApplyAfterVanillaConsoleUpdateInternal();
		}

		internal static bool ShouldBlockConsoleInputActivation(TMP_InputField input)
		{
			ConsolePanelController? activeInstance = ActiveInstance;
			if (activeInstance == null || !activeInstance._searchInputWanted || (Object)(object)((Terminal)(Console.instance?)).m_input == (Object)null)
			{
				return false;
			}
			if (input != ((Terminal)Console.instance).m_input)
			{
				return false;
			}
			return !ActiveInstance.ReleaseSearchFocusForConsoleClick();
		}

		private void Update()
		{
			bool flag = ShouldManageVanillaConsole();
			if (flag)
			{
				HandlePanelToggleHotkey();
			}
			bool num = ShouldShowPanel();
			if (flag)
			{
				ApplyVanillaConsoleLayout();
			}
			if (num)
			{
				EnsureUi();
				bool visible = _visible;
				SetVisible(visible: true);
				ApplyLayout();
				RefreshIfNeeded(!visible);
				ConsolePanelInputBlock.SetActive(active: true, ConsolePanelModule.ReleaseMouseCursor.Value);
				ApplyCursorRelease();
				if (!ReleaseSearchFocusForConsoleClick())
				{
					EnforceExclusiveInputFocus();
				}
			}
			else
			{
				SetVisible(visible: false);
				ClearSearchFocusState();
				ConsolePanelInputBlock.SetActive(active: false);
				RestoreCursor();
				if (!flag)
				{
					RestoreVanillaConsoleLayout();
				}
			}
		}

		private static bool ShouldManageVanillaConsole()
		{
			if (Console.IsVisible())
			{
				return (Object)(object)Console.instance != (Object)null;
			}
			return false;
		}

		private bool ShouldShowPanel()
		{
			if (ShouldManageVanillaConsole() && !_panelHiddenByHotkey)
			{
				return (Object)(object)Console.instance != (Object)null;
			}
			return false;
		}

		private void HandlePanelToggleHotkey()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				KeyboardShortcut value = ConsolePanelModule.TogglePanelKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					_panelHiddenByHotkey = !_panelHiddenByHotkey;
				}
			}
			catch
			{
			}
		}

		private void ApplyAfterVanillaConsoleUpdateInternal()
		{
			if (ShouldManageVanillaConsole())
			{
				ApplyVanillaConsoleLayout();
			}
			if (_visible && ShouldShowPanel() && !ReleaseSearchFocusForConsoleClick())
			{
				EnforceExclusiveInputFocus();
			}
		}

		private void EnsureUi()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			PanelVisualStyle value = ConsolePanelModule.VisualStyle.Value;
			if ((Object)(object)_canvas != (Object)null && _createdVisualStyle != value)
			{
				Object.Destroy((Object)(object)((Component)_canvas).gameObject);
				ClearUiReferences();
			}
			if (!((Object)(object)_canvas != (Object)null))
			{
				_font = FindFontAsset();
				EnsureTmpDefaultFont();
				_inventoryPanelStyle = FindInventoryPanelStyle();
				GameObject val = new GameObject("ConsolePanel.Canvas");
				Object.DontDestroyOnLoad((Object)(object)val);
				val.layer = 5;
				val.AddComponent<GuiPixelFix>();
				_canvas = val.AddComponent<Canvas>();
				_canvas.renderMode = (RenderMode)0;
				_canvas.overrideSorting = true;
				_canvas.additionalShaderChannels = (AdditionalCanvasShaderChannels)25;
				_canvas.sortingOrder = 5000;
				CanvasScaler obj = val.AddComponent<CanvasScaler>();
				obj.uiScaleMode = (ScaleMode)1;
				obj.referenceResolution = new Vector2(1920f, 1080f);
				obj.matchWidthOrHeight = 0.5f;
				val.AddComponent<GraphicRaycaster>();
				RectTransform component = val.GetComponent<RectTransform>();
				Stretch(component);
				GameObject val2 = CreateUiObject("Panel", (Transform)(object)component);
				_panel = val2.GetComponent<RectTransform>();
				Image image = val2.AddComponent<Image>();
				ApplySurfaceImage(image, SurfaceRole.Panel, new Color(0.33f, 0.22f, 0.12f, 0.88f), preferInventoryPanel: true);
				Outline obj2 = val2.AddComponent<Outline>();
				((Shadow)obj2).effectColor = new Color(0.06f, 0.035f, 0.01f, 0.9f);
				((Shadow)obj2).effectDistance = new Vector2(2f, -2f);
				_headerRoot = CreateHeaderLabel(_panel, out _headerLabel);
				_searchInputRoot = CreateSearchInput(_panel);
				_favoriteProfileRoot = CreateFavoriteProfileBar(_panel, out _favoriteProfileContent);
				_commandScroll = CreateScrollArea(_panel, "Commands", out _commandContent);
				_commandScrollRect = ((Component)_commandScroll).GetComponent<ScrollRect>();
				ConfigureVirtualCommandContent();
				_categoryScroll = CreateScrollArea(_panel, "Categories", out _categoryContent);
				_categoryScrollRect = ((Component)_categoryScroll).GetComponent<ScrollRect>();
				_tooltipRoot = CreateTooltip(component, out _tooltipLabel);
				_createdVisualStyle = value;
				ApplyLayout();
				SetVisible(visible: false);
			}
		}

		private void ClearUiReferences()
		{
			_canvas = null;
			_panel = null;
			_headerRoot = null;
			_headerLabel = null;
			_searchInputRoot = null;
			_searchInputField = null;
			_favoriteProfileRoot = null;
			_favoriteProfileContent = null;
			_categoryScroll = null;
			_commandScroll = null;
			_tooltipRoot = null;
			_tooltipLabel = null;
			_commandScrollRect = null;
			_categoryScrollRect = null;
			_categoryContent = null;
			_commandContent = null;
			_emptyCommandRow = null;
			_emptyCommandLabel = null;
			_commandRowPool.Clear();
			_renderedCommandRows.Clear();
			_favoriteActionBindingsByCommand.Clear();
			_lastVirtualFirstIndex = -1;
			_lastVirtualRowCount = -1;
			_lastRenderedOwner = null;
			ClearSearchFocusState();
		}

		private void ApplyLayout()
		{
			//IL_013a: 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)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_panel == (Object)null) && !((Object)(object)_headerRoot == (Object)null) && !((Object)(object)_searchInputRoot == (Object)null) && !((Object)(object)_favoriteProfileRoot == (Object)null) && !((Object)(object)_commandScroll == (Object)null) && !((Object)(object)_categoryScroll == (Object)null))
			{
				if ((Object)(object)_canvas != (Object)null)
				{
					_canvas.sortingOrder = 5000;
				}
				float num = Mathf.Max(360f, ConsolePanelModule.PanelWidth.Value);
				float num2 = Mathf.Max(180f, ConsolePanelModule.PanelHeight.Value);
				float panelTopOffset = GetPanelTopOffset();
				float num3 = Mathf.Max(1f, Mathf.Min(num2, panelTopOffset));
				float num4 = Mathf.Clamp(150f, 80f, num * 0.45f);
				float num5 = 8f;
				float num6 = 30f;
				float num7 = Mathf.Max(160f, num - num4 - num5 * 3f);
				float favoriteActionAreaWidth = GetFavoriteActionAreaWidth();
				float num8 = Mathf.Max(120f, num7 - 180f - num5);
				float num9 = Mathf.Min(Mathf.Max(favoriteActionAreaWidth + 120f, 150f), num8);
				_panel.anchorMin = new Vector2(0f, 0f);
				_panel.anchorMax = new Vector2(0f, 0f);
				_panel.pivot = new Vector2(0f, 0f);
				_panel.anchoredPosition = new Vector2(5f, Mathf.Max(0f, panelTopOffset - num3));
				_panel.sizeDelta = new Vector2(num, num3);
				_headerRoot.anchorMin = new Vector2(0f, 1f);
				_headerRoot.anchorMax = new Vector2(1f, 1f);
				_headerRoot.pivot = new Vector2(0f, 1f);
				_headerRoot.offsetMin = new Vector2(num5, 0f - (num6 + num5));
				_headerRoot.offsetMax = new Vector2(0f - (num4 + num9 + num5 * 3f), 0f - num5);
				_searchInputRoot.anchorMin = new Vector2(1f, 1f);
				_searchInputRoot.anchorMax = new Vector2(1f, 1f);
				_searchInputRoot.pivot = new Vector2(1f, 1f);
				_searchInputRoot.anchoredPosition = new Vector2(0f - (num4 + num5 * 2f), 0f - num5);
				_searchInputRoot.sizeDelta = new Vector2(num9, num6);
				_favoriteProfileRoot.anchorMin = new Vector2(1f, 1f);
				_favoriteProfileRoot.anchorMax = new Vector2(1f, 1f);
				_favoriteProfileRoot.pivot = new Vector2(1f, 1f);
				_favoriteProfileRoot.anchoredPosition = new Vector2(0f - num5, 0f - num5);
				_favoriteProfileRoot.sizeDelta = new Vector2(num4, num6);
				_commandScroll.anchorMin = new Vector2(0f, 0f);
				_commandScroll.anchorMax = new Vector2(1f, 1f);
				_commandScroll.pivot = new Vector2(0f, 0.5f);
				_commandScroll.offsetMin = new Vector2(num5, num5);
				_commandScroll.offsetMax = new Vector2(0f - (num4 + num5 * 2f), 0f - (num6 + num5 * 2f));
				_categoryScroll.anchorMin = new Vector2(1f, 0f);
				_categoryScroll.anchorMax = new Vector2(1f, 1f);
				_categoryScroll.pivot = new Vector2(1f, 0.5f);
				_categoryScroll.offsetMin = new Vector2(0f - (num4 + num5), num5);
				_categoryScroll.offsetMax = new Vector2(0f - num5, 0f - (num6 + num5 * 2f));
				ApplyScrollSettings(_commandScrollRect);
				ApplyScrollSettings(_categoryScrollRect);
				((Transform)_commandScroll).SetAsLastSibling();
				((Transform)_headerRoot).SetAsLastSibling();
				((Transform)_searchInputRoot).SetAsLastSibling();
				((Transform)_favoriteProfileRoot).SetAsLastSibling();
				((Transform)_categoryScroll).SetAsLastSibling();
				RectTransform? tooltipRoot = _tooltipRoot;
				if (tooltipRoot != null)
				{
					((Transform)tooltipRoot).SetAsLastSibling();
				}
			}
		}

		private void ApplyVanillaConsoleLayout()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = FindVanillaConsoleRect();
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)_vanillaConsoleRect != (Object)(object)val)
				{
					RestoreVanillaConsoleLayout();
					_vanillaConsoleRect = val;
					_originalVanillaConsoleRectState = RectTransformState.Capture(val);
					ConsolePanelModule.Diagnostic("captured vanilla console rect '" + GetTransformPath((Transform)(object)val) + "': " + $"anchorMin={val.anchorMin}, anchorMax={val.anchorMax}, offsetMin={val.offsetMin}, offsetMax={val.offsetMax}");
				}
				RectTransformState rectTransformState = _originalVanillaConsoleRectState ?? RectTransformState.Capture(val);
				float vanillaConsoleBottomOffset = GetVanillaConsoleBottomOffset();
				val.anchorMin = rectTransformState.AnchorMin;
				val.anchorMax = rectTransformState.AnchorMax;
				val.pivot = rectTransformState.Pivot;
				val.anchoredPosition = rectTransformState.AnchoredPosition;
				val.sizeDelta = rectTransformState.SizeDelta;
				val.offsetMax = rectTransformState.OffsetMax;
				val.offsetMin = new Vector2(rectTransformState.OffsetMin.x, vanillaConsoleBottomOffset);
				_vanillaConsoleBottomFromPanelCanvas = (TryGetRectBottomFromPanelCanvas(val, out var bottom) ? bottom : (-1f));
			}
		}

		private void RestoreVanillaConsoleLayout()
		{
			if ((Object)(object)_vanillaConsoleRect != (Object)null && _originalVanillaConsoleRectState.HasValue)
			{
				_originalVanillaConsoleRectState.Value.Apply(_vanillaConsoleRect);
			}
			_vanillaConsoleRect = null;
			_originalVanillaConsoleRectState = null;
			_vanillaConsoleBottomFromPanelCanvas = -1f;
		}

		private static float GetVanillaConsoleBottomOffset()
		{
			return Mathf.Max(0f, ConsolePanelModule.VanillaConsoleBottomOffset.Value);
		}

		private float GetPanelTopOffset()
		{
			float consoleBottomFromPanelCanvas = GetConsoleBottomFromPanelCanvas();
			return Mathf.Max(0f, consoleBottomFromPanelCanvas - 30f);
		}

		private float GetConsoleBottomFromPanelCanvas()
		{
			if ((Object)(object)_vanillaConsoleRect != (Object)null && TryGetRectBottomFromPanelCanvas(_vanillaConsoleRect, out var bottom))
			{
				_vanillaConsoleBottomFromPanelCanvas = bottom;
				return bottom;
			}
			if (!(_vanillaConsoleBottomFromPanelCanvas >= 0f))
			{
				return GetVanillaConsoleBottomOffset();
			}
			return _vanillaConsoleBottomFromPanelCanvas;
		}

		private bool TryGetRectBottomFromPanelCanvas(RectTransform rect, out float bottom)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			bottom = 0f;
			if (!((Object)(object)_canvas == (Object)null))
			{
				Transform transform = ((Component)_canvas).transform;
				RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if (val != null)
				{
					rect.GetWorldCorners(RectWorldCorners);
					Canvas componentInParent = ((Component)rect).GetComponentInParent<Canvas>();
					Vector2 val2 = RectTransformUtility.WorldToScreenPoint(((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null, RectWorldCorners[0]);
					Camera val3 = (((int)_canvas.renderMode != 0) ? _canvas.worldCamera : null);
					Vector2 val4 = default(Vector2);
					if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(val, val2, val3, ref val4))
					{
						return false;
					}
					float y = val4.y;
					Rect rect2 = val.rect;
					bottom = Mathf.Max(0f, y - ((Rect)(ref rect2)).yMin);
					return true;
				}
			}
			return false;
		}

		private static RectTransform? FindVanillaConsoleRect()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			Console instance = Console.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			if ((Object)(object)((Terminal)instance).m_chatWindow != (Object)null)
			{
				RectTransform val = FindConsoleBuddyStyleVisualRect((Transform?)(object)((Terminal)instance).m_chatWindow);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			RectTransform val2 = FindConsoleBuddyStyleVisualRect(((Component)instance).transform);
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
			if ((Object)(object)((Terminal)instance).m_chatWindow != (Object)null)
			{
				return ((Terminal)instance).m_chatWindow;
			}
			if ((Object)(object)((Terminal)instance).m_input != (Object)null)
			{
				Transform transform = ((Component)((Terminal)instance).m_input).transform;
				RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if (val3 != null)
				{
					RectTransform val4 = (from rect in ((Component)val3).GetComponentsInParent<RectTransform>(true)
						where (Object)(object)rect != (Object)null
						select rect).OrderByDescending(delegate(RectTransform rect)
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						//IL_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)
						Rect rect2 = rect.rect;
						float width = ((Rect)(ref rect2)).width;
						rect2 = rect.rect;
						return width * ((Rect)(ref rect2)).height;
					}).FirstOrDefault();
					if ((Object)(object)val4 != (Object)null)
					{
						return val4;
					}
				}
			}
			return null;
		}

		private static RectTransform? FindConsoleBuddyStyleVisualRect(Transform? root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return null;
			}
			Queue<Transform> queue = new Queue<Transform>();
			queue.Enqueue(root);
			while (queue.Count > 0)
			{
				Transform val = queue.Dequeue();
				for (int i = 0; i < val.childCount; i++)
				{
					Transform child = val.GetChild(i);
					queue.Enqueue(child);
				}
				if (!string.Equals(((Object)val).name, "Image", StringComparison.OrdinalIgnoreCase))
				{
					continue;
				}
				RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
				if (val2 != null && !((Object)(object)((Component)val).GetComponent<Image>() == (Object)null))
				{
					Transform val3 = val.Find("Text");
					if ((Object)(object)val3 != (Object)null && (Object)(object)((Component)val3).GetComponent<TextMeshProUGUI>() != (Object)null)
					{
						return val2;
					}
				}
			}
			return null;
		}

		private static string GetTransformPath(Transform transform)
		{
			List<string> list = new List<string>();
			Transform val = transform;
			while ((Object)(object)val != (Object)null)
			{
				list.Add(((Object)val).name);
				val = val.parent;
			}
			list.Reverse();
			return string.Join("/", list);
		}

		private void SetVisible(bool visible)
		{
			_visible = visible;
			if ((Object)(object)_canvas != (Object)null && ((Component)_canvas).gameObject.activeSelf != visible)
			{
				((Component)_canvas).gameObject.SetActive(visible);
			}
		}

		private void ApplyCursorRelease()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (!ConsolePanelModule.ReleaseMouseCursor.Value)
			{
				RestoreCursor();
				return;
			}
			if (!_cursorCaptured)
			{
				_previousCursorVisible = Cursor.visible;
				_previousCursorLockState = Cursor.lockState;
				_cursorCaptured = true;
			}
			Cursor.visible = true;
			Cursor.lockState = (CursorLockMode)0;
		}

		private void RestoreCursor()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (_cursorCaptured)
			{
				Cursor.visible = _previousCursorVisible;
				Cursor.lockState = _previousCursorLockState;
				_cursorCaptured = false;
			}
		}

		private void RefreshIfNeeded(bool force)
		{
			int count = Terminal.commands.Count;
			if (force || !(Time.unscaledTime < _nextRefresh))
			{
				_nextRefresh = Time.unscaledTime + 3f;
				if (force || _lastOwnershipVersion != ConsoleCommandOwnership.Version || _lastCommandCount != count)
				{
					_lastOwnershipVersion = ConsoleCommandOwnership.Version;
					_lastCommandCount = count;
					RebuildCommandModel();
					RefreshFavoriteProfileButtons();
					RefreshCategoryRows();
					RefreshCommandRows();
				}
			}
		}

		private void RebuildCommandModel()
		{
			_commands.Clear();
			_allRows.Clear();
			_commandsByOwner.Clear();
			_commandsByName.Clear();
			_owners.Clear();
			foreach (CommandEntry item in ConsoleCommandCatalog.CaptureVisibleCommands(Console.instance))
			{
				AddCommandEntry(item);
			}
			foreach (List<CommandEntry> value in _commandsByOwner.Values)
			{
				value.Sort((CommandEntry left, CommandEntry right) => string.Compare(left.Command, right.Command, StringComparison.OrdinalIgnoreCase));
			}
			_owners.AddRange(_commandsByOwner.Keys.OrderBy(ConsoleCommandCatalog.OwnerSortWeight).ThenBy<string, string>((string owner) => owner, StringComparer.OrdinalIgnoreCase));
			_allRows.AddRange(_commands.OrderBy((CommandEntry entry) => ConsoleCommandCatalog.OwnerSortWeight(entry.Owner)).ThenBy<CommandEntry, string>((CommandEntry entry) => entry.Owner, StringComparer.OrdinalIgnoreCase).ThenBy<CommandEntry, string>((CommandEntry entry) => entry.Command, StringComparer.OrdinalIgnoreCase));
			ConsolePanelModule.Diagnostic(string.Format("captured {0} visible commands in {1} groups: {2}", _commands.Count, _owners.Count, string.Join(", ", _owners.Select((string owner) => $"{owner}={_commandsByOwner[owner].Count}"))));
			if (!IsBuiltInOwner(_selectedOwner) && !_owners.Contains<string>(_selectedOwner, StringComparer.OrdinalIgnoreCase))
			{
				_selectedOwner = _owners.FirstOrDefault() ?? "All";
				ConsolePanelModule.Diagnostic("selected owner changed to '" + _selectedOwner + "' after rebuild");
			}
		}

		private void AddCommandEntry(CommandEntry entry)
		{
			if (!string.IsNullOrWhiteSpace(entry.Command) && !_commandsByName.ContainsKey(entry.Command))
			{
				_commands.Add(entry);
				_commandsByName[entry.Command] = entry;
				if (!_commandsByOwner.TryGetValue(entry.Owner, out List<CommandEntry> value))
				{
					value = new List<CommandEntry>();
					_commandsByOwner[entry.Owner] = value;
				}
				value.Add(entry);
			}
		}

		private void RefreshCategoryRows()
		{
			if ((Object)(object)_categoryContent == (Object)null)
			{
				return;
			}
			ClearChildren(_categoryContent);
			foreach (string item in GetCategoryDisplayOrder())
			{
				AddCategoryButton(item, item);
			}
			void AddCategoryButton(string label, string owner)
			{
				string capturedOwner = owner;
				Button button = CreateTabButton(_categoryContent, label, delegate
				{
					ConsolePanelModule.Diagnostic("category clicked: '" + capturedOwner + "'");
					_selectedOwner = (string.Equals(_selectedOwner, capturedOwner, StringComparison.OrdinalIgnoreCase) ? "All" : capturedOwner);
					RefreshCommandRows();
					RefreshCategoryRows();
					RefreshFavoriteProfileButtons();
				});
				ApplySelectedButtonColor(button, string.Equals(owner, _selectedOwner, StringComparison.OrdinalIgnoreCase));
			}
		}

		[IteratorStateMachine(typeof(<GetCategoryDisplayOrder>d__89))]
		private IEnumerable<string> GetCategoryDisplayOrder()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetCategoryDisplayOrder>d__89(-2)
			{
				<>4__this = this
			};
		}

		private void RefreshFavoriteProfileButtons()
		{
			if ((Object)(object)_favoriteProfileContent == (Object)null)
			{
				return;
			}
			ClearChildren(_favoriteProfileContent);
			for (int i = 0; i < GetFavoriteTabCount(); i++)
			{
				int capturedIndex = i;
				Button button = CreateCompactButton(_favoriteProfileContent, (i + 1).ToString(), delegate
				{
					string text = FavoriteOwner(capturedIndex);
					_selectedOwner = (string.Equals(_selectedOwner, text, StringComparison.OrdinalIgnoreCase) ? "All" : text);
					RefreshCommandRows();
					RefreshCategoryRows();
					RefreshFavoriteProfileButtons();
				});
				ApplySelectedButtonColor(button, string.Equals(_selectedOwner, FavoriteOwner(i), StringComparison.OrdinalIgnoreCase));
			}
		}

		private void RefreshCommandRows()
		{
			if ((Object)(object)_commandContent == (Object)null)
			{
				return;
			}
			Transform? commandContent = _commandContent;
			RectTransform val = (RectTransform)(object)((commandContent is RectTransform) ? commandContent : null);
			if (val == null)
			{
				return;
			}
			_favoriteActionBindingsByCommand.Clear();
			List<CommandEntry> list = ApplySearch(GetSelectedRows());
			string text = _selectedOwner + "|" + _searchText;
			bool flag = !string.Equals(_lastRenderedOwner, text, StringComparison.OrdinalIgnoreCase);
			string text2 = ((list.Count == 0) ? "" : (", preview=" + string.Join(", ", from row in list.Take(5)
				select row.Command)));
			ConsolePanelModule.Diagnostic($"refresh command rows: selected='{_selectedOwner}', rows={list.Count}, contentActive={((Component)_commandContent).gameObject.activeInHierarchy}{text2}");
			if ((Object)(object)_headerLabel != (Object)null)
			{
				((TMP_Text)_headerLabel).text = $"{GetOwnerDisplayName(_selectedOwner)} commands ({list.Count})";
			}
			_renderedCommandRows.Clear();
			_renderedCommandRows.AddRange(list);
			SetVirtualCommandContentHeight(list.Count);
			if (list.Count == 0)
			{
				int index;
				string text3 = (TryGetFavoriteIndex(_selectedOwner, out index) ? "No favorite commands yet. Use row number buttons to add commands to this profile." : "No visible commands were captured for this group.");
				ShowVirtualInfoRow(text3);
				HidePooledCommandRows();
				if (flag)
				{
					ResetScrollToTop(_commandScrollRect, val);
				}
				_lastRenderedOwner = text;
			}
			else
			{
				HideVirtualInfoRow();
				if (flag)
				{
					ResetScrollToTop(_commandScrollRect, val);
				}
				ClampCommandScrollPosition(val);
				UpdateVirtualCommandRows(force: true);
				_lastRenderedOwner = text;
			}
		}

		private void SetVirtualCommandContentHeight(int rowCount)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Transform? commandContent = _commandContent;
			RectTransform val = (RectTransform)(object)((commandContent is RectTransform) ? commandContent : null);
			if (val != null)
			{
				float num = 30f;
				float num2 = ((rowCount <= 0) ? (num + 8f) : (8f + (float)rowCount * num + (float)Mathf.Max(0, rowCount - 1) * 4f));
				val.sizeDelta = new Vector2(val.sizeDelta.x, num2);
			}
		}

		private void UpdateVirtualCommandRows(bool force = false)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			Transform? commandContent = _commandContent;
			RectTransform val = (RectTransform)(object)((commandContent is RectTransform) ? commandContent : null);
			if (val == null)
			{
				return;
			}
			ScrollRect? commandScrollRect = _commandScrollRect;
			if ((Object)(object)((commandScrollRect != null) ? commandScrollRect.viewport : null) == (Object)null)
			{
				return;
			}
			if (_renderedCommandRows.Count == 0)
			{
				HidePooledCommandRows();
				_lastVirtualFirstIndex = -1;
				_lastVirtualRowCount = -1;
				return;
			}
			HideVirtualInfoRow();
			ClampCommandScrollPosition(val);
			float num = 30f + 4f;
			float num2 = Mathf.Max(0f, val.anchoredPosition.y);
			Rect rect = _commandScrollRect.viewport.rect;
			float num3 = Mathf.Max(1f, ((Rect)(ref rect)).height);
			int num4 = Mathf.Clamp(Mathf.FloorToInt((num2 - 4f) / num) - 2, 0, _renderedCommandRows.Count - 1);
			int num5 = Mathf.Clamp(Mathf.CeilToInt(num3 / num) + 6, 0, _renderedCommandRows.Count - num4);
			if (!force && num4 == _lastVirtualFirstIndex && num5 == _lastVirtualRowCount)
			{
				return;
			}
			EnsureCommandRowPool(num5);
			_favoriteActionBindingsByCommand.Clear();
			for (int i = 0; i < _commandRowPool.Count; i++)
			{
				CommandRowView commandRowView = _commandRowPool[i];
				if (i >= num5)
				{
					commandRowView.SetActive(active: false);
					continue;
				}
				int num6 = num4 + i;
				commandRowView.SetActive(active: true);
				PositionVirtualCommandRow(commandRowView.RectTransform, num6);
				commandRowView.Bind(_renderedCommandRows[num6]);
			}
			_lastVirtualFirstIndex = num4;
			_lastVirtualRowCount = num5;
		}

		private void EnsureCommandRowPool(int visibleCount)
		{
			if (!((Object)(object)_commandContent == (Object)null))
			{
				while (_commandRowPool.Count < visibleCount)
				{
					_commandRowPool.Add(new CommandRowView(this, _commandContent));
				}
			}
		}

		private static void PositionVirtualCommandRow(RectTransform rowRect, int rowIndex)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f - (4f + (float)rowIndex * 34f);
			rowRect.anchorMin = new Vector2(0f, 1f);
			rowRect.anchorMax = new Vector2(1f, 1f);
			rowRect.pivot = new Vector2(0.5f, 1f);
			rowRect.offsetMin = new Vector2(4f, num - 30f);
			rowRect.offsetMax = new Vector2(-4f, num);
		}

		private void ClampCommandScrollPosition(RectTransform contentRect)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			ScrollRect? commandScrollRect = _commandScrollRect;
			if (!((Object)(object)((commandScrollRect != null) ? commandScrollRect.viewport : null) == (Object)null))
			{
				Rect rect = contentRect.rect;
				float height = ((Rect)(ref rect)).height;
				rect = _commandScrollRect.viewport.rect;
				float num = Mathf.Max(0f, height - ((Rect)(ref rect)).height);
				Vector2 anchoredPosition = contentRect.anchoredPosition;
				float num2 = Mathf.Clamp(anchoredPosition.y, 0f, num);
				if (!Mathf.Approximately(anchoredPosition.y, num2))
				{
					contentRect.anchoredPosition = new Vector2(anchoredPosition.x, num2);
				}
			}
		}

		private void HidePooledCommandRows()
		{
			foreach (CommandRowView item in _commandRowPool)
			{
				item.SetActive(active: false);
			}
			_favoriteActionBindingsByCommand.Clear();
		}

		private void ShowVirtualInfoRow(string text)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			Transform? commandContent = _commandContent;
			RectTransform val = (RectTransform)(object)((commandContent is RectTransform) ? commandContent : null);
			if (val != null)
			{
				if ((Object)(object)_emptyCommandRow == (Object)null)
				{
					GameObject val2 = CreateUiObject("InfoRow", (Transform)(object)val);
					_emptyCommandRow = val2.GetComponent<RectTransform>();
					Image image = val2.AddComponent<Image>();
					ApplySurfaceImage(image, SurfaceRole.MutedInfo, new Color(0f, 0f, 0f, 0.18f));
					GameObject val3 = CreateUiObject("Label", val2.transform);
					RectTransform component = val3.GetComponent<RectTransform>();
					Stretch(component);
					component.offsetMin = new Vector2(8f, 2f);
					component.offsetMax = new Vector2(-8f, -2f);
					EnsureTmpDefaultFont();
					_emptyCommandLabel = val3.AddComponent<TextMeshProUGUI>();
					((TMP_Text)_emptyCommandLabel).font = _font;
					((TMP_Text)_emptyCommandLabel).fontSize = 14f;
					((Graphic)_emptyCommandLabel).color = ButtonTextColor();
					((TMP_Text)_emptyCommandLabel).alignment = (TextAlignmentOptions)4097;
					((TMP_Text)_emptyCommandLabel).textWrappingMode = (TextWrappingModes)0;
					((TMP_Text)_emptyCommandLabel).overflowMode = (TextOverflowModes)1;
					((Graphic)_emptyCommandLabel).raycastTarget = false;
				}
				((Component)_emptyCommandRow).gameObject.SetActive(true);
				PositionVirtualCommandRow(_emptyCommandRow, 0);
				if ((Object)(object)_emptyCommandLabel != (Object)null)
				{
					((TMP_Text)_emptyCommandLabel).text = text;
				}
			}
		}

		private void HideVirtualInfoRow()
		{
			if ((Object)(object)_emptyCommandRow != (Object)null)
			{
				((Component)_emptyCommandRow).gameObject.SetActive(false);
			}
		}

		private void RebuildCommandLayout(bool resetScroll)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			Transform? commandContent = _commandContent;
			RectTransform val = (RectTransform)(object)((commandContent is RectTransform) ? commandContent : null);
			if (val != null)
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate(val);
				Canvas.ForceUpdateCanvases();
				if (resetScroll)
				{
					ResetScrollToTop(_commandScrollRect, val);
				}
				ScrollRect? commandScrollRect = _commandScrollRect;
				RectTransform val2 = ((commandScrollRect != null) ? commandScrollRect.viewport : null);
				object arg = ((Transform)val).childCount;
				Rect rect = val.rect;
				string text = $"rebuilt command layout: children={arg}, height={((Rect)(ref rect)).height:0.0}, ";
				object arg2 = val.anchoredPosition;
				object obj;
				if (val2 == null)
				{
					obj = null;
				}
				else
				{
					rect = val2.rect;
					Vector2 size = ((Rect)(ref rect)).size;
					obj = ((object)(Vector2)(ref size)).ToString();
				}
				if (obj == null)
				{
					obj = "null";
				}
				ConsolePanelModule.Diagnostic(text + $"contentPos={arg2}, viewport={obj}, active={((Component)val).gameObject.activeInHierarchy}");
			}
		}

		private static void ResetScrollToTop(ScrollRect? scrollRect, RectTransform contentRect)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			contentRect.anchoredPosition = Vector2.zero;
			if (!((Object)(object)scrollRect == (Object)null))
			{
				scrollRect.StopMovement();
				scrollRect.verticalNormalizedPosition = 1f;
			}
		}

		private void CreateInfoRow(Transform parent, string text, bool muted = false)
		{
			//IL_0069: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = CreateUiObject("InfoRow", parent);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.minHeight = 30f;
			obj.preferredHeight = 30f;
			Image image = val.AddComponent<Image>();
			ApplySurfaceImage(image, muted ? SurfaceRole.MutedInfo : SurfaceRole.Info, muted ? new Color(0f, 0f, 0f, 0.18f) : new Color(0f, 0f, 0f, 0.38f));
			GameObject obj2 = CreateUiObject("Label", val.transform);
			RectTransform component = obj2.GetComponent<RectTransform>();
			Stretch(component);
			component.offsetMin = new Vector2(8f, 2f);
			component.offsetMax = new Vector2(-8f, -2f);
			EnsureTmpDefaultFont();
			TextMeshProUGUI obj3 = obj2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj3).font = _font;
			((TMP_Text)obj3).text = text;
			((TMP_Text)obj3).fontSize = (muted ? 13f : 15f);
			((Graphic)obj3).color = (muted ? new Color(0.78f, 0.7f, 0.55f, 1f) : new Color(1f, 0.86f, 0.36f, 1f));
			((TMP_Text)obj3).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)obj3).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)obj3).overflowMode = (TextOverflowModes)1;
			((Graphic)obj3).raycastTarget = false;
		}

		private RectTransform CreateHeaderLabel(RectTransform parent, out TextMeshProUGUI label)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = CreateUiObject("CommandHeader", (Transform)(object)parent);
			RectTransform component = val.GetComponent<RectTransform>();
			Image image = val.AddComponent<Image>();
			ApplySurfaceImage(image, SurfaceRole.Header, new Color(0.16f, 0.08f, 0.04f, 0.9f));
			GameObject val2 = CreateUiObject("Label", val.transform);
			RectTransform component2 = val2.GetComponent<RectTransform>();
			Stretch(component2);
			component2.offsetMin = new Vector2(10f, 2f);
			component2.offsetMax = new Vector2(-10f, -2f);
			EnsureTmpDefaultFont();
			label = val2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)label).font = _font;
			((TMP_Text)label).text = "Commands";
			((TMP_Text)label).fontSize = 15f;
			((Graphic)label).color = new Color(1f, 0.86f, 0.36f, 1f);
			((TMP_Text)label).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)label).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)label).overflowMode = (TextOverflowModes)1;
			((Graphic)label).raycastTarget = false;
			return component;
		}

		private List<CommandEntry> GetSelectedRows()
		{
			if (string.Equals(_selectedOwner, "All", StringComparison.OrdinalIgnoreCase))
			{
				return _allRows;
			}
			if (TryGetFavoriteIndex(_selectedOwner, out var favoriteIndex))
			{
				return (from command in _favorites.GetCommands(favoriteIndex).OrderBy<string, string>((string command) => command, StringComparer.OrdinalIgnoreCase)
					select ResolveFavoriteCommand(command, favoriteIndex)).ToList();
			}
			if (!_commandsByOwner.TryGetValue(_selectedOwner, out List<CommandEntry> value))
			{
				return new List<CommandEntry>();
			}
			return value;
		}

		private List<CommandEntry> ApplySearch(List<CommandEntry> rows)
		{
			string text = _searchText.Trim();
			if (text.Length == 0)
			{
				return rows;
			}
			string[] terms = (from term in text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				select term.Trim() into term
				where term.Length > 0
				select term).ToArray();
			if (terms.Length == 0)
			{
				return rows;
			}
			return rows.Where((CommandEntry entry) => terms.All((string term) => entry.Command.IndexOf(term, StringComparison.OrdinalIgnoreCase) >= 0 || entry.Description.IndexOf(term, StringComparison.OrdinalIgnoreCase) >= 0 || entry.Owner.IndexOf(term, StringComparison.OrdinalIgnoreCase) >= 0)).ToList();
		}

		private CommandEntry ResolveFavoriteCommand(string command, int favoriteIndex)
		{
			if (_commandsByName.TryGetValue(command, out var value))
			{
				return value;
			}
			return new CommandEntry(command, "", FavoriteOwner(favoriteIndex));
		}

		private void CreateCommandRow(Transform parent, CommandEntry entry)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			GameObject val = CreateUiObject("CommandRow", parent);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.minHeight = 30f;
			obj.preferredHeight = 30f;
			HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = 6f;
			((LayoutGroup)obj2).padding = new RectOffset(4, 4, 2, 2);
			((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
			Button val2 = CreateButton(val.transform, FormatCommandRowText(entry), delegate
			{
				PutCommandInInput(entry);
			});
			if (ShouldShowCommandSourceTooltip())
			{
				((Component)val2).gameObject.AddComponent<ManualHoverTooltip>().Configure("Source: " + entry.Owner, ShowOwnerTooltip, HideOwnerTooltip);
			}
			((Component)val2).gameObject.AddComponent<LayoutElement>().flexibleWidth = 1f;
			GameObject val3 = CreateUiObject("FavoriteActions", val.transform);
			HorizontalLayoutGroup obj3 = val3.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj3).spacing = 3f;
			((LayoutGroup)obj3).padding = new RectOffset(0, 0, 0, 0);
			((HorizontalOrVerticalLayoutGroup)obj3).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandWidth = false;
			((LayoutGroup)obj3).childAlignment = (TextAnchor)4;
			LayoutElement obj4 = val3.AddComponent<LayoutElement>();
			float preferredWidth = (obj4.minWidth = GetFavoriteActionAreaWidth());
			obj4.preferredWidth = preferredWidth;
			obj4.flexibleWidth = 0f;
			for (int i = 0; i < GetFavoriteTabCount(); i++)
			{
				int targetIndex = i;
				Button button = CreateFavoriteActionButton(val3.transform, (i + 1).ToString(), delegate
				{
					ToggleFavorite(targetIndex, entry.Command);
				});
				RegisterFavoriteActionButton(entry.Command, targetIndex, button);
				ApplySelectedButtonColor(button, IsFavoriteInTab(targetIndex, entry.Command));
			}
		}

		private static string FormatCommandRowText(CommandEntry entry)
		{
			if (!string.IsNullOrWhiteSpace(entry.Description))
			{
				return entry.Command + "  <color=#d9d1b8>" + entry.Description + "</color>";
			}
			return entry.Command;
		}

		private void RegisterFavoriteActionButton(string command, int favoriteIndex, Button button)
		{
			if (!_favoriteActionBindingsByCommand.TryGetValue(command, out List<FavoriteActionBinding> value))
			{
				value = new List<FavoriteActionBinding>();
				_favoriteActionBindingsByCommand[command] = value;
			}
			value.Add(new FavoriteActionBinding(favoriteIndex, button));
		}

		private void RefreshFavoriteActionButtons(string command)
		{
			if (!_favoriteActionBindingsByCommand.TryGetValue(command, out List<FavoriteActionBinding> value))
			{
				return;
			}
			foreach (FavoriteActionBinding item in value)
			{
				if ((Object)(object)item.Button != (Object)null)
				{
					ApplySelectedButtonColor(item.Button, IsFavoriteInTab(item.FavoriteIndex, command));
				}
			}
		}

		private bool ShouldShowCommandSourceTooltip()
		{
			if (TryGetFavoriteIndex(_selectedOwner, out var _))
			{
				return true;
			}
			if (!string.IsNullOrWhiteSpace(_searchText))
			{
				return string.Equals(_selectedOwner, "All", StringComparison.OrdinalIgnoreCase);
			}
			return false;
		}

		private static float GetFavoriteActionAreaWidth()
		{
			int favoriteTabCount = GetFavoriteTabCount();
			return (float)favoriteTabCount * GetFavoriteActionButtonWidth() + (float)Mathf.Max(0, favoriteTabCount - 1) * 3f;
		}

		private static float GetFavoriteActionButtonWidth()
		{
			return 20f;
		}

		private void LoadFavorites()
		{
			_favorites.LoadFromConfig();
		}

		internal void ReloadFavoritesFromConfig()
		{
			LoadFavorites();
			if (_visible)
			{
				if (TryGetFavoriteIndex(_selectedOwner, out var index) && index >= GetFavoriteTabCount())
				{
					_selectedOwner = "All";
				}
				RefreshCommandRows();
				RefreshCategoryRows();
				RefreshFavoriteProfileButtons();
			}
		}

		internal void OnFavoriteConfigChanged()
		{
			if (!_favorites.IsSaving)
			{
				ReloadFavoritesFromConfig();
			}
		}

		private void SaveFavorites()
		{
			_favorites.SaveToConfig();
		}

		private void ToggleFavorite(int targetIndex, string command)
		{
			if (_favorites.Toggle(targetIndex, command))
			{
				SaveFavorites();
				if (TryGetFavoriteIndex(_selectedOwner, out var index) && index == targetIndex)
				{
					RefreshCommandRows();
				}
				else
				{
					RefreshFavoriteActionButtons(command);
				}
			}
		}

		private bool IsFavoriteInTab(int index, string command)
		{
			return _favorites.Contains(index, command);
		}

		private static bool IsValidFavoriteIndex(int index)
		{
			return ConsolePanelFavoriteStore.IsValidIndex(index);
		}

		private static int GetFavoriteTabCount()
		{
			return ConsolePanelFavoriteStore.GetVisibleTabCount();
		}

		private static string FavoriteOwner(int index)
		{
			return string.Format("{0}{1}", "Favorite ", index + 1);
		}

		private static bool TryGetFavoriteIndex(string owner, out int index)
		{
			index = -1;
			if (!owner.StartsWith("Favorite ", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			if (!int.TryParse(owner.Substring("Favorite ".Length), out var result))
			{
				return false;
			}
			index = result - 1;
			return IsValidFavoriteIndex(index);
		}

		private static bool IsBuiltInOwner(string owner)
		{
			int index;
			if (!string.Equals(owner, "All", StringComparison.OrdinalIgnoreCase))
			{
				return TryGetFavoriteIndex(owner, out index);
			}
			return true;
		}

		private static string GetOwnerDisplayName(string owner)
		{
			if (TryGetFavoriteIndex(owner, out var index))
			{
				return $"Favorite {index + 1}";
			}
			return owner;
		}

		private void PutCommandInInput(CommandEntry entry)
		{
			PutCommandInInput(entry.Command);
		}

		private void PutCommandInInput(string command)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)((Terminal)(Console.instance?)).m_input == (Object)null))
			{
				EndSearchInputFocus();
				TMP_InputField val = (TMP_InputField)((Terminal)Console.instance).m_input;
				val.text = command;
				val.caretPosition = val.text.Length;
				((Terminal)Console.instance).m_input.ActivateInputField();
			}
		}

		private void BeginSearchInputFocus()
		{
			_searchInputWanted = true;
			TMP_InputField consoleInputField = GetConsoleInputField();
			if ((Object)(object)consoleInputField != (Object)null)
			{
				CaptureConsoleInputLock(consoleInputField);
				_consoleInputSnapshot = consoleInputField.text ?? "";
				_hasConsoleInputSnapshot = true;
				consoleInputField.readOnly = true;
				((Selectable)consoleInputField).interactable = false;
				consoleInputField.DeactivateInputField(false);
			}
		}

		private void EndSearchInputFocus()
		{
			if ((Object)(object)_searchInputField != (Object)null)
			{
				_searchInputField.DeactivateInputField(false);
			}
			ClearSearchFocusState();
		}

		private bool ReleaseSearchFocusForConsoleClick()
		{
			if (!_searchInputWanted || !IsPrimaryMouseDown())
			{
				return false;
			}
			TMP_InputField consoleInputField = GetConsoleInputField();
			if ((Object)(object)consoleInputField == (Object)null || !IsPointerInsideInput(consoleInputField))
			{
				return false;
			}
			EndSearchInputFocus();
			EventSystem current = EventSystem.current;
			if (current != null)
			{
				current.SetSelectedGameObject(((Component)consoleInputField).gameObject);
			}
			((Selectable)consoleInputField).Select();
			consoleInputField.ActivateInputField();
			consoleInputField.caretPosition = consoleInputField.text?.Length ?? 0;
			return true;
		}

		private void ClearSearchFocusState()
		{
			_searchInputWanted = false;
			_hasConsoleInputSnapshot = false;
			_consoleInputSnapshot = "";
			RestoreConsoleInputLock();
		}

		private void EnforceExclusiveInputFocus()
		{
			if ((Object)(object)_searchInp