Decompiled source of AdminQoL v1.0.9

AdminQoL.dll

Decompiled 16 hours 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.Text;
using System.Text.RegularExpressions;
using System.Threading;
using AdminQoL.LightweightXRay;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ConsolePanel;
using HarmonyLib;
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.9")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.9.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 ConsolePanel
{
	internal static class ConsoleCommandOwnership
	{
		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 void EnterTerminalInit()
		{
			_terminalInitDepth++;
		}

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

		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;
				}
			}
		}

		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;
			}
		}

		private static IEnumerable<string> GetPluginAliases(PluginInfo pluginInfo)
		{
			HashSet<string> aliases = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			AddAlias(pluginInfo.Metadata.Name);
			AddAlias(pluginInfo.Metadata.GUID);
			string location = pluginInfo.Location;
			if (!string.IsNullOrWhiteSpace(location))
			{
				AddAlias(Path.GetFileNameWithoutExtension(location));
				string fileName = Path.GetFileName(Path.GetDirectoryName(location) ?? "");
				AddAlias(fileName);
				if (!string.IsNullOrWhiteSpace(fileName))
				{
					int num = fileName.IndexOf('-');
					if (num >= 0 && num + 1 < fileName.Length)
					{
						AddAlias(fileName.Substring(num + 1));
					}
				}
			}
			foreach (string item in aliases)
			{
				yield return item;
			}
			void AddAlias(string? raw)
			{
				if (!string.IsNullOrWhiteSpace(raw))
				{
					string text = NormalizeIdentifier(raw);
					if (text.Length >= 3 && !CommonAliasTokens.Contains(text))
					{
						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 item2 in list)
					{
						aliases.Add(item2);
					}
					string text2 = string.Concat(list.Select((string token) => token[0]));
					if (text2.Length >= 2 && !CommonAliasTokens.Contains(text2))
					{
						aliases.Add(text2);
					}
				}
			}
		}

		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 ?? "";
			}
		}
	}
	internal static class ConsoleCommandCatalog
	{
		private static readonly FieldInfo? CommandsField = AccessTools.Field(typeof(Terminal), "commands");

		private static readonly FieldRef<Dictionary<string, ConsoleCommand>>? CommandsAccessor = CreateCommandsAccessor();

		internal static List<CommandEntry> CaptureVisibleCommands(Console? console)
		{
			List<CommandEntry> list = new List<CommandEntry>();
			FieldRef<Dictionary<string, ConsoleCommand>> commandsAccessor = CommandsAccessor;
			if (commandsAccessor == null)
			{
				AddCompatibilityCommands(list);
				return list;
			}
			Dictionary<string, ConsoleCommand> dictionary = commandsAccessor.Invoke();
			if (dictionary == null)
			{
				AddCompatibilityCommands(list);
				return list;
			}
			foreach (KeyValuePair<string, ConsoleCommand> item in dictionary)
			{
				ConsoleCommand value = item.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;
		}

		private static FieldRef<Dictionary<string, ConsoleCommand>>? CreateCommandsAccessor()
		{
			if (!(CommandsField == null))
			{
				return AccessTools.StaticFieldRefAccess<Dictionary<string, ConsoleCommand>>(CommandsField);
			}
			return null;
		}

		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)
		{
			return Chainloader.PluginInfos.Values.Any((PluginInfo pluginInfo) => string.Equals(pluginInfo.Metadata.GUID, guid, StringComparison.OrdinalIgnoreCase));
		}

		private static bool IsLikelyValheimCommand(string 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(command, 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 ManualClickSuppressionFrames = 3;
	}
	internal static class ConsolePanelInputBlock
	{
		private static readonly FieldRef<GameCamera, bool>? MouseCaptureAccessor = CreateMouseCaptureAccessor();

		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;
			FieldRef<GameCamera, bool> mouseCaptureAccessor = MouseCaptureAccessor;
			if (!((Object)(object)instance == (Object)null) && mouseCaptureAccessor != null)
			{
				if (!_hasStoredMouseCapture)
				{
					_previousMouseCapture = mouseCaptureAccessor.Invoke(instance);
					_hasStoredMouseCapture = true;
				}
				mouseCaptureAccessor.Invoke(instance) = false;
				instance.UpdateMouseCapture();
			}
		}

		private static void RestoreMouseCapture()
		{
			GameCamera instance = GameCamera.instance;
			FieldRef<GameCamera, bool> mouseCaptureAccessor = MouseCaptureAccessor;
			if ((Object)(object)instance != (Object)null && mouseCaptureAccessor != null && _hasStoredMouseCapture)
			{
				mouseCaptureAccessor.Invoke(instance) = _previousMouseCapture;
				instance.UpdateMouseCapture();
			}
			_hasStoredMouseCapture = false;
		}

		private static FieldRef<GameCamera, bool>? CreateMouseCaptureAccessor()
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(GameCamera), "m_mouseCapture");
			if (!(fieldInfo == null))
			{
				return AccessTools.FieldRefAccess<GameCamera, bool>(fieldInfo);
			}
			return null;
		}
	}
	internal static class ConsolePanelModule
	{
		private sealed class ConfigurationManagerAttributes
		{
			public int? Order { get; set; }
		}

		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_0045: 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)
			//IL_0127: Expected O, but got Unknown
			UnsubscribeFavoriteConfigEvents();
			ConfigFile = config;
			VisualStyle = config.Bind<PanelVisualStyle>("3 - Console Panel", "Panel Visual Style", PanelVisualStyle.Modern, OrderedDescription("Visual style for ConsolePanel. Off disables ConsolePanel entirely, Wood uses Valheim-style wood panels, Modern uses ConfigurationManager-like flat panels.", 600));
			TogglePanelKey = config.Bind<KeyboardShortcut>("3 - Console Panel", "Toggle Panel Key", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), OrderedDescription("Keyboard shortcut that toggles ConsolePanel while Valheim's F5 console is visible.", 500));
			PanelWidth = config.Bind<float>("3 - Console Panel", "Panel Width", 900f, OrderedDescription("Width of the command browser panel.", 400));
			PanelHeight = config.Bind<float>("3 - Console Panel", "Panel Height", 450f, OrderedDescription("Maximum height of the command browser panel. The panel shrinks if needed to preserve the fixed gap below the console.", 300));
			VanillaConsoleBottomOffset = config.Bind<float>("3 - Console Panel", "Vanilla Console Bottom Offset", 120f, OrderedDescription("Bottom Y offset applied to Valheim's own console rect while the console panel is visible.", 200));
			ReleaseMouseCursor = config.Bind<bool>("3 - Console Panel", "Release Mouse Cursor", true, OrderedDescription("Unlock and show the mouse cursor while the F5 console panel is visible so category, command, and favorite buttons can be clicked.", 100));
			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 += OnFavoriteConfigSettingChanged;
			for (int j = 0; j < 5; j++)
			{
				FavoriteTabCommands[j].SettingChanged += OnFavoriteConfigSettingChanged;
			}
			if ((Object)(object)Controller == (Object)null)
			{
				Controller = host.AddComponent<ConsolePanelController>();
			}
		}

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

		private static void OnFavoriteConfigSettingChanged(object sender, EventArgs args)
		{
			Controller?.OnFavoriteConfigChanged();
		}

		private static void UnsubscribeFavoriteConfigEvents()
		{
			if (FavoriteTabCommands == null)
			{
				return;
			}
			if (FavoriteTabCount != null)
			{
				FavoriteTabCount.SettingChanged -= OnFavoriteConfigSettingChanged;
			}
			for (int i = 0; i < FavoriteTabCommands.Length; i++)
			{
				ConfigEntry<string> val = FavoriteTabCommands[i];
				if (val != null)
				{
					val.SettingChanged -= OnFavoriteConfigSettingChanged;
				}
			}
		}

		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;
				}
			}
			update();
		}

		private static ConfigDescription OrderedDescription(string description, int order)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			return new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = order
				}
			});
		}
	}
	[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 Exception? Finalizer(Exception? __exception)
		{
			ConsoleCommandOwnership.ExitTerminalInit();
			return __exception;
		}
	}
	[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,
			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 ManualHoverTooltip? _tooltip;

			private CommandEntry _entry;

			private bool _hasEntry;

			internal RectTransform RectTransform { get; }

			internal CommandRowView(ConsolePanelController owner, Transform parent)
			{
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Expected O, but got Unknown
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: 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;
				}
				int favoriteTabCount = GetFavoriteTabCount();
				EnsureFavoriteButtons(favoriteTabCount);
				float favoriteActionAreaWidth = GetFavoriteActionAreaWidth();
				_actionElement.minWidth = favoriteActionAreaWidth;
				_actionElement.preferredWidth = favoriteActionAreaWidth;
				_actionElement.flexibleWidth = 0f;
				for (int i = 0; i < _favoriteButtons.Count; i++)
				{
					Button val = _favoriteButtons[i];
					bool flag = i < favoriteTabCount;
					((Component)val).gameObject.SetActive(flag);
					if (flag)
					{
						_owner.RegisterFavoriteActionButton(entry.Command, i, val);
						_owner.ApplySelectedButtonColor(val, _owner.IsFavoriteInTab(i, entry.Command));
					}
				}
				LayoutRebuilder.MarkLayoutForRebuild(RectTransform);
			}

			private void EnsureFavoriteButtons(int count)
			{
				while (_favoriteButtons.Count < count)
				{
					int targetIndex = _favoriteButtons.Count;
					Button item = _owner.CreateFavoriteActionButton(_actionsTransform, (targetIndex + 1).ToString(), delegate
					{
						if (_hasEntry)
						{
							_owner.ToggleFavorite(targetIndex, _entry.Command);
						}
					});
					_favoriteButtons.Add(item);
				}
			}
		}

		private static ConsolePanelController? ActiveInstance;

		private static Sprite? SolidUiSprite;

		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 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 ((object)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 (IsPanelEnabled() && Console.IsVisible())
			{
				return (Object)(object)Console.instance != (Object)null;
			}
			return false;
		}

		private static bool IsPanelEnabled()
		{
			return ConsolePanelModule.VisualStyle.Value != PanelVisualStyle.Off;
		}

		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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = FindVanillaConsoleRect();
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)_vanillaConsoleRect != (Object)(object)val)
				{
					RestoreVanillaConsoleLayout();
					_vanillaConsoleRect = val;
					_originalVanillaConsoleRectState = RectTransformState.Capture(val);
				}
				RectTransformState rectTransformState = _originalVanillaConsoleRectState ?? RectTransformState.Capture(val);
				float vanillaConsoleBottomOffset = GetVanillaConsoleBottomOffset();
				rectTransformState.Apply(val);
				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 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)
		{
			if (force || !(Time.unscaledTime < _nextRefresh))
			{
				_nextRefresh = Time.unscaledTime + 3f;
				RebuildCommandModel();
				RefreshSelectionViews();
			}
		}

		private void RefreshSelectionViews()
		{
			RefreshFavoriteProfileButtons();
			RefreshCategoryRows();
			RefreshCommandRows();
		}

		private void RebuildCommandModel()
		{
			_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(_commandsByName.Values.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));
			if (!IsBuiltInOwner(_selectedOwner) && !_owners.Contains<string>(_selectedOwner, StringComparer.OrdinalIgnoreCase))
			{
				_selectedOwner = _owners.FirstOrDefault() ?? "All";
			}
		}

		private void AddCommandEntry(CommandEntry entry)
		{
			if (!string.IsNullOrWhiteSpace(entry.Command) && !_commandsByName.ContainsKey(entry.Command))
			{
				_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 owner in _owners)
			{
				AddCategoryButton(owner, owner);
			}
			void AddCategoryButton(string label, string owner)
			{
				string capturedOwner = owner;
				Button button = CreateTabButton(_categoryContent, label, delegate
				{
					_selectedOwner = (string.Equals(_selectedOwner, capturedOwner, StringComparison.OrdinalIgnoreCase) ? "All" : capturedOwner);
					RefreshSelectionViews();
				});
				ApplySelectedButtonColor(button, string.Equals(owner, _selectedOwner, StringComparison.OrdinalIgnoreCase));
			}
		}

		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);
					RefreshSelectionViews();
				});
				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);
			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 text2 = (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(text2);
				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 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 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 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 * 20f + (float)Mathf.Max(0, favoriteTabCount - 1) * 3f;
		}

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

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

		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 || !ConsolePanelPointer.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)_searchInputField == (Object)null)
			{
				ClearSearchFocusState();
				return;
			}
			if (!_searchInputWanted && !_searchInputField.isFocused)
			{
				ClearSearchFocusState();
				return;
			}
			TMP_InputField consoleInputField = GetConsoleInputField();
			if (!((Object)(object)consoleInputField == (Object)null) && consoleInputField != _searchInputField)
			{
				CaptureConsoleInputLock(consoleInputField);
				consoleInputField.readOnly = true;
				((Selectable)consoleInputField).interactable = false;
				if (!_hasConsoleInputSnapshot)
				{
					_consoleInputSnapshot = consoleInputField.text ?? "";
					_hasConsoleInputSnapshot = true;
				}
				if (!string.Equals(consoleInputField.text, _consoleInputSnapshot, StringComparison.Ordinal))
				{
					consoleInputField.text = _consoleInputSnapshot;
					consoleInputField.caretPosition = consoleInputField.text.Length;
				}
				if (consoleInputField.isFocused)
				{
					consoleInputField.DeactivateInputField(false);
				}
				EventSystem current = EventSystem.current;
				if (current != null)
				{
					current.SetSelectedGameObject(((Component)_searchInputField).gameObject);
				}
				((Selectable)_searchInputField).Select();
				_searchInputField.ActivateInputField();
			}
		}

		private void CaptureConsoleInputLock(TMP_InputField consoleInput)
		{
			if (!_hasConsoleReadOnlySnapshot)
			{
				_consoleReadOnlySnapshot = consoleInput.readOnly;
				_consoleInteractableSnapshot = ((Selectable)consoleInput).interactable;
				_hasConsoleReadOnlySnapshot = true;
			}
		}

		private void RestoreConsoleInputLock()
		{
			if (_hasConsoleReadOnlySnapshot)
			{
				TMP_InputField consoleInputField = GetConsoleInputField();
				if ((Object)(object)consoleInputField != (Object)null)
				{
					consoleInputField.readOnly = _consoleReadOnlySnapshot;
					((Selectable)consoleInputField).interactable = _consoleInteractableSnapshot;
				}
				_hasConsoleReadOnlySnapshot = false;
				_consoleReadOnlySnapshot = false;
				_consoleInteractableSnapshot = false;
			}
		}

		private static bool IsPointerInsideInput(TMP_InputField input)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)input).transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if (val == null)
			{
				return false;
			}
			return RectTransformUtility.RectangleContainsScreenPoint(val, Vector2.op_Implicit(ConsolePanelPointer.GetMousePosition()), (Camera)null);
		}

		private static TMP_InputField? GetConsoleInputField()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			if ((Object)(object)((Terminal)(Console.instance?)).m_input == (Object)null)
			{
				return null;
			}
			try
			{
				return (TMP_InputField)((Terminal)Console.instance).m_input;
			}
			catch
			{
				return null;
			}
		}

		private void ApplySurfaceImage(Image image, SurfaceRole role, Color fallbackColor, bool preferInventoryPanel = false)
		{
			//IL_0041: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)image).raycastTarget = true;
			if (ConsolePanelModule.VisualStyle.Value == PanelVisualStyle.Modern)
			{
				image.sprite = GetSolidUiSprite();
				((Graphic)image).material = null;
				image.type = (Type)0;
				((Graphic)image).color = ModernColor(role, fallbackColor.a);
				return;
			}
			((Graphic)image).color = fallbackColor;
			bool flag = preferInventoryPanel;
			if (!flag)
			{
				bool flag2 = (((uint)(role - 1) <= 1u || (uint)(role - 5) <= 1u) ? true : false);
				flag = flag2;
			}
			if (flag)
			{
				if (_inventoryPanelStyle == null)
				{
					_inventoryPanelStyle = FindInventoryPanelStyle();
				}
				PanelImageStyle inventoryPanelStyle = _inventoryPanelStyle;
				if (inventoryPanelStyle != null)
				{
					image.sprite = inventoryPanelStyle.Sprite;
					((Graphic)image).material = inventoryPanelStyle.Material;
					((Graphic)image).color = ((role == SurfaceRole.Panel) ? WithAlpha(inventoryPanelStyle.Color, fallbackColor.a) : WithAlpha(MultiplyColor(inventoryPanelStyle.Color, WoodSpriteTint()), fallbackColor.a * WoodSpriteTint().a));
					image.type = inventoryPanelStyle.Type;
					return;
				}
			}
			image.sprite = null;
			((Graphic)image).material = null;
			image.type = (Type)0;
		}

		private static Sprite GetSolidUiSprite()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			if ((Object)(object)SolidUiSprite != (Object)null)
			{
				return SolidUiSprite;
			}
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				name = "ConsolePanel_SolidUiTexture",
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)0
			};
			val.SetPixel(0, 0, Color.white);
			val.Apply(false, true);
			Object.DontDestroyOnLoad((Object)val);
			SolidUiSprite = Sprite.Create(val, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f), 100f);
			((Object)SolidUiSprite).name = "ConsolePanel_SolidUiSprite";
			Object.DontDestroyOnLoad((Object)(object)SolidUiSprite);
			return SolidUiSprite;
		}

		private static Color ModernColor(SurfaceRole role, float alpha)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			Color val = (Color)(role switch
			{
				SurfaceRole.Panel => new Color(0.12f, 0.115f, 0.105f, 0.66f), 
				SurfaceRole.Header => new Color(0.55f, 0.42f, 0.3f, 0.76f), 
				SurfaceRole.Search => new Color(0.2f, 0.18f, 0.16f, 0.82f), 
				SurfaceRole.Scroll => new Color(0.28f, 0.25f, 0.23f, 0.42f), 
				SurfaceRole.MutedInfo => new Color(0.36f, 0.32f, 0.3f, 0.58f), 
				SurfaceRole.Button => new Color(0.38f, 0.34f, 0.31f, 0.82f), 
				SurfaceRole.FavoriteBar => new Color(0.28f, 0.25f, 0.23f, 0.78f), 
				SurfaceRole.Tooltip => new Color(0.16f, 0.14f, 0.13f, 0.94f), 
				SurfaceRole.ScrollbarBackground => new Color(0.08f, 0.075f, 0.07f, 0.55f), 
				SurfaceRole.ScrollbarHandle => AccentColor(alpha), 
				_ => new Color(0.36f, 0.32f, 0.3f, alpha), 
			});
			if (role != SurfaceRole.ScrollbarHandle)
			{
				val.a = Mathf.Min(val.a, alpha);
			}
			return val;
		}

		private static PanelImageStyle? FindInventoryPanelStyle()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Sprite val = FindLoadedSprite("woodpanel_trophys");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material material = FindLoadedMaterial("litpanel");
			return PanelImageStyle.From(val, material, Color.white, (Type)1);
		}

		private static TMP_FontAsset? FindFontAsset()
		{
			Console instance = Console.instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				TextMeshProUGUI output = ((Terminal)instance).m_output;
				obj = ((output != null) ? ((TMP_Text)output).font : null);
			}
			if (obj == null)
			{
				Console instance2 = Console.instance;
				if (instance2 == null)
				{
					obj = null;
				}
				else
				{
					TMP_Text search = ((Terminal)instance2).m_search;
					obj = ((search != null) ? search.font : null);
				}
			}
			TMP_FontAsset val = (TMP_FontAsset)obj;
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			try
			{
				string[] obj2 = new string[5] { "Valheim-AveriaSansLibre", "Valheim-Norse", "AveriaSansLibre", "Norse", "LiberationSans SDF" };
				List<TMP_FontAsset> source = (from font in Resources.FindObjectsOfTypeAll<TMP_FontAsset>()
					where (Object)(object)font != (Object)null
					select font).ToList();
				string[] array = obj2;
				foreach (string name in array)
				{
					TMP_FontAsset val2 = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset font) => string.Equals(((Object)font).name, name, StringComparison.OrdinalIgnoreCase))) ?? ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset font) => ((Object)font).name.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0));
					if ((Object)(object)val2 != (Object)null)
					{
						return val2;
					}
				}
				TMP_FontAsset val3 = source.FirstOrDefault();
				if ((Object)(object)val3 != (Object)null)
				{
					return val3;
				}
			}
			catch
			{
			}
			try
			{
				TMP_FontAsset obj4 = TMP_FontAsset.CreateFontAsset(Font.CreateDynamicFontFromOSFont(new string[3] { "Arial", "Segoe UI", "Malgun Gothic" }, 16));
				((Object)obj4).name = "ConsolePanel_RuntimeTMPFont";
				return obj4;
			}
			catch
			{
				return null;
			}
		}

		private void EnsureTmpDefaultFont()
		{
			if (_font == null)
			{
				_font = FindFontAsset();
			}
			if ((Object)(object)_font == (Object)null || _tmpDefaultFontApplied)
			{
				return;
			}
			try
			{
				TMP_Settings.defaultFontAsset = _font;
				_tmpDefaultFontApplied = true;
			}
			catch
			{
			}
		}

		private static Sprite? FindLoadedSprite(string spriteName)
		{
			try
			{
				Sprite val = ((IEnumerable<Sprite>)Resources.FindObjectsOfTypeAll<Sprite>()).FirstOrDefault((Func<Sprite, bool>)((Sprite val2) => (Object)(object)val2 != (Object)null && string.Equals(((Object)val2).name, spriteName, StringComparison.OrdinalIgnoreCase)));
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
				SpriteAtlas[] array = Resources.FindObjectsOfTypeAll<SpriteAtlas>();
				for (int num = 0; num < array.Length; num++)
				{
					Sprite sprite = array[num].GetSprite(spriteName);
					if ((Object)(object)sprite != (Object)null)
					{
						return sprite;
					}
				}
			}
			catch
			{
				return null;
			}
			return null;
		}

		private static Material? FindLoadedMaterial(string materialName)
		{
			try
			{
				return ((IEnumerable<Material>)Resources.FindObjectsOfTypeAll<Material>()).FirstOrDefault((Func<Material, bool>)((Material material) => (Object)(object)material != (Object)null && string.Equals(((Object)material).name, materialName, StringComparison.OrdinalIgnoreCase)));
			}
			catch
			{
				return null;
			}
		}

		private static Color WithAlpha(Color color, float alpha)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			color.a = alpha;
			return color;
		}

		private static Color MultiplyColor(Color baseColor, Color tint)
		{
			//IL_0000: 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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			return new Color(Mathf.Clamp01(baseColor.r * tint.r), Mathf.Clamp01(baseColor.g * tint.g), Mathf.Clamp01(baseColor.b * tint.b), Mathf.Clamp01(baseColor.a * tint.a));
		}

		private static Color AccentColor(float alpha = 1f)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (ConsolePanelModule.VisualStyle.Value != PanelVisualStyle.Modern)
			{
				return new Color(1f, 0.7f, 0.32f, alpha);
			}
			return new Color(1f, 0.9f, 0.16f, alpha);
		}

		private static Color ButtonTextColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(1f, 0.92f, 0.7f, 1f);
		}

		private static Color SelectedButtonTextColor()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (ConsolePanelModule.VisualStyle.Value != PanelVisualStyle.Modern)
			{
				return ButtonTextColor();
			}
			return new Color(0.12f, 0.08f, 0.035f, 1f);
		}

		private static Color SelectedButtonBackgroundColor(float alpha = 1f)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (ConsolePanelModule.VisualStyle.Value == PanelVisualStyle.Modern)
			{
				return new Color(0.78f, 0.57f, 0.29f, alpha);
			}
			Color val = WoodSelectedTint();
			val.a = Mathf.Clamp01(val.a * alpha);
			return val;
		}

		private static Color WoodSpriteTint()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(1f, 1f, 1f, 0.29803923f);
		}

		private static Color WoodSelectedTint()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 1f, 1f, 1f);
		}

		private static Color ButtonNormalColor()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (ConsolePanelModule.VisualStyle.Value != PanelVisualStyle.Modern)
			{
				return new Color(0.42f, 0.32f, 0.16f, 0.95f);
			}
			return new Color(0.43f, 0.38f, 0.34f, 0.86f);
		}

		private static Color ButtonHighlightColor()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (ConsolePanelModule.VisualStyle.Value != PanelVisualStyle.Modern)
			{
				return new Color(0.6f, 0.48f, 0.25f, 1f);
			}
			return new Color(0.56f, 0.45f, 0.34f, 0.96f);
		}

		private static Color ButtonPressedColor()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (ConsolePanelModule.VisualStyle.Value != PanelVisualStyle.Modern)
			{
				return new Color(0.78f, 0.64f, 0.32f, 1f);
			}
			return new Color(0.88f, 0.5f, 0.1f, 1f);
		}

		private static void ClearChildren(Transform parent)
		{
			for (int num = parent.childCount - 1; num >= 0; num--)
			{
				Transform child = parent.GetChild(num);
				((Component)child).gameObject.SetActive(false);
				child.SetParent((Transform)null, false);
				Object.Destroy((Object)(object)((Component)child).gameObject);
			}
		}

		private static GameObject CreateUiObject(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) })
			{
				layer = 5
			};
			val.transform.SetParent(parent, false);
			return val;
		}

		private static void Stretch(RectTransform rect)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			rect.offsetMin = Vector2.zero;
			rect.offsetMax = Vector2.zero;
			rect.pivot = new Vector2(0.5f, 0.5f);
		}

		private void ConfigureVirtualCommandContent()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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;
			}
			VerticalLayoutGroup[] components = ((Component)val).GetComponents<VerticalLayoutGroup>();
			foreach (VerticalLayoutGroup obj in components)
			{
				((Behaviour)obj).enabled = false;
				Object.Destroy((Object)(object)obj);
			}
			ContentSizeFitter[] components2 = ((Component)val).GetComponents<ContentSizeFitter>();
			foreach (ContentSizeFitter obj2 in components2)
			{
				((Behaviour)obj2).enabled = false;
				Object.Destroy((Object)(object)obj2);
			}
			val.anchorMin = new Vector2(0f, 1f);
			val.anchorMax = new Vector2(1f, 1f);
			val.pivot = new Vector2(0.5f, 1f);
			val.anchoredPosition = Vector2.zero;
			val.sizeDelta = Vector2.zero;
			if ((Object)(object)_commandScrollRect != (Object)null)
			{
				((UnityEvent<Vector2>)(object)_commandScrollRect.onValueChanged).AddListener((UnityAction<Vector2>)delegate
				{
					UpdateVirtualCommandRows();
				});
			}
		}

		private RectTransform CreateScrollArea(RectTransform parent, string name, out Transform content)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_011c: Expected O, but got Unknown
			GameObject obj = CreateUiObject(name, (Transform)(object)parent);
			RectTransform component = obj.GetComponent<RectTransform>();
			Image image = obj.AddComponent<Image>();
			ApplySurfaceImage(image, SurfaceRole.Scroll, new Color(0.08f, 0.1f, 0.1f, 0.45f));
			GameObject obj2 = CreateUiObject("Viewport", (Transform)(object)component);
			RectTransform component2 = obj2.GetComponent<RectTransform>();
			Stretch(component2);
			component2.offsetMax = new Vector2(-5f, 0f);
			((Graphic)obj2.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.01f);
			obj2.AddComponent<RectMask2D>();
			GameObject val = CreateUiObject("Content", (Transform)(object)component2);
			RectTransform component3 = val.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 1f);
			com