Decompiled source of CommandItemQueue v1.2.0

plugins/CommandItemQueue/CommandItemQueue.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RoR2;
using RoR2.UI;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CommandItemQueue")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+20cd3786800eb943022d50e44005a57675df6b85")]
[assembly: AssemblyProduct("CommandItemQueue")]
[assembly: AssemblyTitle("CommandItemQueue")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CommandItemQueue
{
	internal static class AutoPicker
	{
		private const BindingFlags AnyInstance = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly List<PickupPickerController> pending = new List<PickupPickerController>();

		private static bool disabled;

		private static readonly FieldInfo OptionsField = typeof(PickupPickerController).GetField("options", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo PromptField = typeof(PickupPickerController).GetField("networkUIPromptController", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo PanelField = typeof(PickupPickerController).GetField("panelInstance", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly MethodInfo SubmitChoiceMethod = typeof(PickupPickerController).GetMethod("SubmitChoice", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(int) }, null);

		private static Type optionType;

		private static FieldInfo optionPickupField;

		private static FieldInfo uniquePickupIndexField;

		private static FieldInfo optionDirectIndexField;

		private static FieldInfo optionAvailableField;

		private static bool loggedSample;

		public static void Install(Harmony harmony)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(PickupPickerController), "OnDisplayBegin", (Type[])null, (Type[])null);
				if (methodInfo == null || OptionsField == null || PromptField == null || SubmitChoiceMethod == null)
				{
					disabled = true;
					Log.Error($"Command cube API not found (OnDisplayBegin={methodInfo != null}, options={OptionsField != null}, prompt={PromptField != null}, SubmitChoice={SubmitChoiceMethod != null}) - auto picking is disabled.");
				}
				else
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(AutoPicker), "OnDisplayBeginPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					Log.Info("Command cube hook installed.");
				}
			}
			catch (Exception ex)
			{
				disabled = true;
				Log.Error("Could not patch command cubes, auto picking is disabled: " + ex);
			}
		}

		private static void OnDisplayBeginPostfix(PickupPickerController __instance)
		{
			try
			{
				if (Object.op_Implicit((Object)(object)__instance) && !pending.Contains(__instance))
				{
					pending.Add(__instance);
				}
			}
			catch (Exception data)
			{
				Log.Error(data);
			}
		}

		public static void Update()
		{
			if (pending.Count == 0)
			{
				return;
			}
			PickupPickerController[] array = pending.ToArray();
			pending.Clear();
			PickupPickerController[] array2 = array;
			foreach (PickupPickerController picker in array2)
			{
				try
				{
					Process(picker);
				}
				catch (Exception ex)
				{
					Log.Error("Auto pick failed: " + ex);
				}
			}
		}

		private static void Process(PickupPickerController picker)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)picker) || disabled)
			{
				return;
			}
			string name = ((Object)((Component)picker).gameObject).name;
			if (!IsQueueablePicker(name))
			{
				return;
			}
			object? value = PromptField.GetValue(picker);
			if (!Object.op_Implicit((Object)((value is NetworkUIPromptController) ? value : null)))
			{
				Log.Info("[" + name + "] no prompt controller - skipped.");
				return;
			}
			if (!ReadOptions(picker, out var pickups, out var available))
			{
				Log.Info("[" + name + "] could not read options - skipped.");
				return;
			}
			PickupGroups.LearnFromOptions(pickups);
			KeyboardShortcut value2 = CommandItemQueuePlugin.Cfg.ManualPickKey.Value;
			if (((KeyboardShortcut)(ref value2)).IsPressed())
			{
				Log.Info("[" + name + "] manual pick key held - choose yourself.");
			}
			else
			{
				if (pickups.Count < 2 && !IsVoidPotential(name))
				{
					return;
				}
				QueueManager queues = CommandItemQueuePlugin.Instance.Queues;
				HashSet<string> hashSet = new HashSet<string>();
				for (int i = 0; i < pickups.Count; i++)
				{
					string text = PickupGroups.KeyFor(pickups[i]);
					if (text == null || !hashSet.Add(text))
					{
						continue;
					}
					GroupQueue groupQueue = queues.TryGet(text);
					if (groupQueue == null || groupQueue.Entries.Count == 0)
					{
						continue;
					}
					if (!groupQueue.TryTake((PickupIndex p) => IndexOfOption(pickups, available, p), out var optionIndex, out var taken))
					{
						Log.Info("[" + name + "] queue '" + text + "' has entries, but none of them is offered by this cube.");
						continue;
					}
					object? obj = PanelField?.GetValue(picker);
					GameObject val = (GameObject)((obj is GameObject) ? obj : null);
					if (Object.op_Implicit((Object)(object)val))
					{
						val.SetActive(false);
					}
					SubmitChoiceMethod.Invoke(picker, new object[1] { optionIndex });
					Log.Info($"[{name}] picked {PickupGroups.DisplayName(taken)} from queue '{text}' ({groupQueue.TotalCount} left).");
					return;
				}
				Log.Info(string.Format("[{0}] {1} options ({2}) - nothing queued, choose yourself.", name, pickups.Count, string.Join(", ", new List<string>(hashSet).ToArray())));
			}
		}

		private static bool ReadOptions(PickupPickerController picker, out List<PickupIndex> pickups, out List<bool> available)
		{
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			pickups = new List<PickupIndex>();
			available = new List<bool>();
			if (!(OptionsField.GetValue(picker) is Array { Length: not 0 } array))
			{
				return false;
			}
			Type elementType = array.GetType().GetElementType();
			if (elementType != optionType)
			{
				optionType = elementType;
				optionPickupField = elementType.GetField("pickup", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				uniquePickupIndexField = optionPickupField?.FieldType.GetField("pickupIndex", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (uniquePickupIndexField == null)
				{
					optionPickupField = null;
				}
				optionDirectIndexField = ((optionPickupField == null) ? elementType.GetField("pickupIndex", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) : null);
				optionAvailableField = elementType.GetField("available", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (optionPickupField == null && optionDirectIndexField == null)
				{
					Log.Error($"Option type {elementType} has no pickup index - auto picking cannot work with this game version.");
					return false;
				}
				Log.Info("Reading command options via " + ((optionPickupField != null) ? "Option.pickup.pickupIndex" : "Option.pickupIndex") + ".");
			}
			bool flag = default(bool);
			for (int i = 0; i < array.Length; i++)
			{
				object value = array.GetValue(i);
				object value3;
				if (optionPickupField != null)
				{
					object value2 = optionPickupField.GetValue(value);
					value3 = uniquePickupIndexField.GetValue(value2);
				}
				else
				{
					value3 = optionDirectIndexField.GetValue(value);
				}
				object obj = ((optionAvailableField != null) ? optionAvailableField.GetValue(value) : ((object)true));
				pickups.Add((value3 is PickupIndex val) ? val : PickupIndex.none);
				List<bool> obj2 = available;
				int num;
				if (obj is bool)
				{
					flag = (bool)obj;
					num = ((1 == 0) ? 1 : 0);
				}
				else
				{
					num = 1;
				}
				obj2.Add((byte)((uint)num | (flag ? 1u : 0u)) != 0);
			}
			if (!loggedSample)
			{
				loggedSample = true;
				List<string> list = new List<string>();
				for (int j = 0; j < Math.Min(3, pickups.Count); j++)
				{
					PickupDef pickupDef = PickupCatalog.GetPickupDef(pickups[j]);
					list.Add(string.Format("{0}={1}", pickups[j].value, (pickupDef != null) ? pickupDef.internalName : "null"));
				}
				Log.Info("First command options: " + string.Join(", ", list.ToArray()));
			}
			return true;
		}

		private static int IndexOfOption(List<PickupIndex> pickups, List<bool> available, PickupIndex pickup)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < pickups.Count; i++)
			{
				if (pickups[i] == pickup && available[i])
				{
					return i;
				}
			}
			return -1;
		}

		private static bool IsQueueablePicker(string objectName)
		{
			if (objectName.StartsWith("CommandCube", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (IsVoidPotential(objectName))
			{
				return CommandItemQueuePlugin.Cfg.ApplyToVoidPotentials.Value;
			}
			return false;
		}

		private static bool IsVoidPotential(string objectName)
		{
			return objectName.StartsWith("OptionPickup", StringComparison.OrdinalIgnoreCase);
		}
	}
	internal sealed class BuildEntry
	{
		public string InternalName;

		public int Count;
	}
	internal sealed class BuildData
	{
		public string Name;

		public DateTime Created;

		public bool AutoLoad;

		public readonly Dictionary<string, List<BuildEntry>> Queues = new Dictionary<string, List<BuildEntry>>();

		public readonly HashSet<string> RepeatKeys = new HashSet<string>();

		public int TotalCount
		{
			get
			{
				int num = 0;
				foreach (List<BuildEntry> value in Queues.Values)
				{
					foreach (BuildEntry item in value)
					{
						num += item.Count;
					}
				}
				return num;
			}
		}

		public void CopyContentFrom(BuildData other)
		{
			Queues.Clear();
			foreach (KeyValuePair<string, List<BuildEntry>> queue in other.Queues)
			{
				Queues[queue.Key] = queue.Value;
			}
			RepeatKeys.Clear();
			foreach (string repeatKey in other.RepeatKeys)
			{
				RepeatKeys.Add(repeatKey);
			}
			Created = other.Created;
		}
	}
	internal sealed class BuildStore
	{
		private const string DateFormat = "yyyy-MM-dd HH:mm";

		private readonly string path;

		public readonly List<BuildData> Builds = new List<BuildData>();

		public BuildStore(string path)
		{
			this.path = path;
		}

		public BuildData GetAutoLoadBuild()
		{
			foreach (BuildData build in Builds)
			{
				if (build.AutoLoad)
				{
					return build;
				}
			}
			return null;
		}

		public void SetAutoLoad(BuildData build, bool value)
		{
			foreach (BuildData build2 in Builds)
			{
				build2.AutoLoad = false;
			}
			if (build != null)
			{
				build.AutoLoad = value;
			}
			Save();
		}

		public void Add(BuildData build)
		{
			Builds.Insert(0, build);
			Save();
		}

		public void Remove(BuildData build)
		{
			Builds.Remove(build);
			Save();
		}

		public void Load()
		{
			Builds.Clear();
			if (!File.Exists(path))
			{
				return;
			}
			try
			{
				BuildData buildData = null;
				string[] array = File.ReadAllLines(path, Encoding.UTF8);
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i].Trim();
					if (text.Length == 0 || text.StartsWith("#"))
					{
						continue;
					}
					if (text.Equals("[build]", StringComparison.OrdinalIgnoreCase))
					{
						buildData = new BuildData
						{
							Name = "Build",
							Created = DateTime.Now
						};
						Builds.Add(buildData);
					}
					else
					{
						if (buildData == null)
						{
							continue;
						}
						int num = text.IndexOf('=');
						if (num <= 0)
						{
							continue;
						}
						string text2 = text.Substring(0, num).Trim().ToLowerInvariant();
						string text3 = text.Substring(num + 1).Trim();
						switch (text2)
						{
						case "name":
							buildData.Name = text3;
							break;
						case "autoload":
							buildData.AutoLoad = text3 == "1" || text3.Equals("true", StringComparison.OrdinalIgnoreCase);
							break;
						case "created":
						{
							if (DateTime.TryParseExact(text3, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out var result))
							{
								buildData.Created = result;
							}
							break;
						}
						case "repeat":
						{
							string[] array2 = text3.Split(';');
							foreach (string text4 in array2)
							{
								if (text4.Trim().Contains(":"))
								{
									buildData.RepeatKeys.Add(text4.Trim());
								}
							}
							break;
						}
						case "queue":
							ParseQueue(buildData, text3);
							break;
						}
					}
				}
			}
			catch (Exception arg)
			{
				Log.Error($"Could not read builds from {path}: {arg}");
			}
		}

		private static void ParseQueue(BuildData build, string value)
		{
			int num = value.IndexOf('=');
			if (num <= 0)
			{
				return;
			}
			string key = value.Substring(0, num).Trim();
			List<BuildEntry> list = new List<BuildEntry>();
			string[] array = value.Substring(num + 1).Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length != 0)
				{
					int num2 = text.LastIndexOf('*');
					int num3 = 1;
					string internalName = text;
					if (num2 > 0 && int.TryParse(text.Substring(num2 + 1), out var result))
					{
						num3 = result;
						internalName = text.Substring(0, num2);
					}
					if (num3 > 0)
					{
						list.Add(new BuildEntry
						{
							InternalName = internalName,
							Count = num3
						});
					}
				}
			}
			if (list.Count > 0)
			{
				build.Queues[key] = list;
			}
		}

		public void Save()
		{
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("# CommandItemQueue builds. Builds can be renamed in game (Tab -> Item Queue -> Builds -> Rename).");
				stringBuilder.AppendLine("# Format: queue=<category>=<item internal name>*<count>,...");
				foreach (BuildData build in Builds)
				{
					stringBuilder.AppendLine();
					stringBuilder.AppendLine("[build]");
					stringBuilder.AppendLine("name=" + (build.Name ?? "Build").Replace("\n", " ").Replace("\r", " "));
					stringBuilder.AppendLine("autoload=" + (build.AutoLoad ? "1" : "0"));
					stringBuilder.AppendLine("created=" + build.Created.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture));
					if (build.RepeatKeys.Count > 0)
					{
						stringBuilder.AppendLine("repeat=" + string.Join(";", new List<string>(build.RepeatKeys).ToArray()));
					}
					foreach (KeyValuePair<string, List<BuildEntry>> queue in build.Queues)
					{
						List<string> list = new List<string>();
						foreach (BuildEntry item in queue.Value)
						{
							list.Add(item.InternalName + "*" + item.Count);
						}
						stringBuilder.AppendLine("queue=" + queue.Key + "=" + string.Join(",", list.ToArray()));
					}
				}
				string directoryName = Path.GetDirectoryName(path);
				if (!string.IsNullOrEmpty(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				string sourceFileName = path + ".tmp";
				File.WriteAllText(sourceFileName, stringBuilder.ToString(), Encoding.UTF8);
				if (File.Exists(path))
				{
					File.Delete(path);
				}
				File.Move(sourceFileName, path);
			}
			catch (Exception arg)
			{
				Log.Error($"Could not save builds to {path}: {arg}");
			}
		}
	}
	internal static class CursorOverlay
	{
		private static readonly FieldInfo IndicatorField = typeof(MPEventSystem).GetField("cursorIndicatorController", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

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

		private static Image cachedImage;

		private static float nextSearchTime;

		private static Texture2D fallbackArrow;

		public static void Draw()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_004e: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001a: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type != 7)
			{
				return;
			}
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			GUI.matrix = Matrix4x4.identity;
			try
			{
				Image val = FindCursorImage();
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.sprite))
				{
					DrawImage(val);
				}
				else
				{
					DrawFallback();
				}
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.color = color;
			}
		}

		private static Image FindCursorImage()
		{
			if (Object.op_Implicit((Object)(object)cachedImage) && ((Behaviour)cachedImage).isActiveAndEnabled && Object.op_Implicit((Object)(object)cachedImage.sprite))
			{
				return cachedImage;
			}
			cachedImage = null;
			if (Time.unscaledTime < nextSearchTime)
			{
				return null;
			}
			nextSearchTime = Time.unscaledTime + 0.25f;
			LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
			MPEventSystem val = ((firstLocalUser != null) ? firstLocalUser.eventSystem : null);
			if (!Object.op_Implicit((Object)(object)val) || IndicatorField == null)
			{
				return null;
			}
			object? value = IndicatorField.GetValue(val);
			Component val2 = (Component)((value is Component) ? value : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return null;
			}
			Image[] componentsInChildren = val2.GetComponentsInChildren<Image>(false);
			foreach (Image val3 in componentsInChildren)
			{
				if (((Behaviour)val3).isActiveAndEnabled && Object.op_Implicit((Object)(object)val3.sprite))
				{
					cachedImage = val3;
					return val3;
				}
			}
			return null;
		}

		private static void DrawImage(Image image)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)image).rectTransform.GetWorldCorners(corners);
			Canvas canvas = ((Graphic)image).canvas;
			Camera obj = ((Object.op_Implicit((Object)(object)canvas) && (int)canvas.renderMode != 0) ? canvas.worldCamera : null);
			Vector2 val = RectTransformUtility.WorldToScreenPoint(obj, corners[0]);
			Vector2 val2 = RectTransformUtility.WorldToScreenPoint(obj, corners[2]);
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(val.x, (float)Screen.height - val2.y, val2.x - val.x, val2.y - val.y);
			if (((Rect)(ref val3)).width < 1f || ((Rect)(ref val3)).height < 1f)
			{
				DrawFallback();
				return;
			}
			Sprite sprite = image.sprite;
			Texture2D texture = sprite.texture;
			Rect val4 = default(Rect);
			((Rect)(ref val4))..ctor(0f, 0f, 1f, 1f);
			try
			{
				Rect textureRect = sprite.textureRect;
				val4 = new Rect(((Rect)(ref textureRect)).x / (float)((Texture)texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)texture).height);
			}
			catch
			{
			}
			GUI.color = ((Graphic)image).color;
			GUI.DrawTextureWithTexCoords(val3, (Texture)(object)texture, val4, true);
		}

		private static void DrawFallback()
		{
			//IL_001b: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)fallbackArrow))
			{
				fallbackArrow = CreateArrow();
			}
			Vector2 mousePosition = Event.current.mousePosition;
			float num = Mathf.Round(32f * (float)Screen.height / 1080f);
			GUI.color = Color.white;
			GUI.DrawTexture(new Rect(mousePosition.x, mousePosition.y, num, num), (Texture)(object)fallbackArrow);
		}

		private static Texture2D CreateArrow()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_00a8: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					int num = 31 - i;
					bool flag = (float)j <= (float)num * 0.62f && num < 26 && (num <= 18 || j <= 10);
					bool flag2 = flag && (j == 0 || (float)j >= (float)num * 0.62f - 1.5f || num >= 25 || (num > 17 && j > 9));
					val.SetPixel(j, i, flag ? (flag2 ? Color.black : Color.white) : val2);
				}
			}
			val.Apply();
			return val;
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	internal sealed class PickupGroup
	{
		public string Key;

		public string DisplayName;

		public Color Color;

		public int SortOrder;

		public readonly List<PickupIndex> Members = new List<PickupIndex>();

		public readonly HashSet<PickupIndex> Available = new HashSet<PickupIndex>();

		public bool IsAvailable(PickupIndex p)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return Available.Contains(p);
		}
	}
	internal static class PickupGroups
	{
		private const string ItemPrefix = "item:";

		private const string EquipPrefix = "equip:";

		private const string OtherPrefix = "other:";

		private static readonly Dictionary<string, string> KnownTierNames = new Dictionary<string, string>
		{
			{ "Tier1Def", "Common" },
			{ "Tier2Def", "Uncommon" },
			{ "Tier3Def", "Legendary" },
			{ "BossTierDef", "Boss" },
			{ "LunarTierDef", "Lunar" },
			{ "VoidTier1Def", "Void Common" },
			{ "VoidTier2Def", "Void Uncommon" },
			{ "VoidTier3Def", "Void Legendary" },
			{ "VoidBossDef", "Void Boss" }
		};

		private static readonly string[] KnownTierOrder = new string[9] { "Tier1Def", "Tier2Def", "Tier3Def", "BossTierDef", "LunarTierDef", "VoidTier1Def", "VoidTier2Def", "VoidTier3Def", "VoidBossDef" };

		private static readonly Dictionary<string, PickupGroup> groups = new Dictionary<string, PickupGroup>();

		private static readonly List<PickupGroup> ordered = new List<PickupGroup>();

		private static readonly HashSet<string> discoveredOtherKeys = new HashSet<string>();

		private static readonly Dictionary<string, HashSet<PickupIndex>> seenInCubes = new Dictionary<string, HashSet<PickupIndex>>();

		private static bool dirty = true;

		private static float lastBuildTime = -999f;

		private static Run lastRun;

		private static readonly Dictionary<PickupIndex, string> nameCache = new Dictionary<PickupIndex, string>();

		private static string cachedLanguage;

		private static readonly Dictionary<PickupIndex, Sprite> loadedIcons = new Dictionary<PickupIndex, Sprite>();

		private static readonly List<object> iconHandles = new List<object>();

		private static readonly MethodInfo GetIconAodrMethod = typeof(PickupDef).GetMethod("GetIconAODR", BindingFlags.Instance | BindingFlags.Public);

		private static readonly MethodInfo GetIconMethod = typeof(PickupDef).GetMethod("GetIcon", BindingFlags.Instance | BindingFlags.Public, null, Type.EmptyTypes, null);

		private static bool loggedIconError;

		private static readonly Dictionary<PickupIndex, float> requestTimes = new Dictionary<PickupIndex, float>();

		public static void Invalidate()
		{
			dirty = true;
		}

		public static IReadOnlyList<PickupGroup> GetAll()
		{
			if (dirty || (Object)(object)lastRun != (Object)(object)Run.instance || Time.unscaledTime - lastBuildTime > 3f)
			{
				Rebuild();
			}
			return ordered;
		}

		public static PickupGroup Find(string key)
		{
			if (key == null)
			{
				return null;
			}
			GetAll();
			groups.TryGetValue(key, out var value);
			return value;
		}

		public static string KeyFor(PickupIndex pickupIndex)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (!((PickupIndex)(ref pickupIndex)).isValid)
			{
				return null;
			}
			return KeyFor(PickupCatalog.GetPickupDef(pickupIndex));
		}

		public static string KeyFor(PickupDef def)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			//IL_000f: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			if (def == null)
			{
				return null;
			}
			if ((int)def.itemIndex != -1)
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(def.itemIndex);
				if (!Object.op_Implicit((Object)(object)itemDef) || itemDef.hidden)
				{
					return null;
				}
				ItemTierDef itemTierDef = ItemTierCatalog.GetItemTierDef(itemDef.tier);
				if (!Object.op_Implicit((Object)(object)itemTierDef))
				{
					return null;
				}
				return "item:" + ((Object)itemTierDef).name;
			}
			if ((int)def.equipmentIndex != -1)
			{
				EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(def.equipmentIndex);
				if (!Object.op_Implicit((Object)(object)equipmentDef))
				{
					return null;
				}
				if (equipmentDef.isBoss)
				{
					return "equip:boss";
				}
				if (equipmentDef.isLunar)
				{
					return "equip:lunar";
				}
				return "equip:normal";
			}
			string text = def.internalName ?? "";
			int num = text.IndexOf('.');
			return "other:" + ((num > 0) ? text.Substring(0, num) : text);
		}

		public static void LearnFromOptions(IList<PickupIndex> offered)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (offered == null)
			{
				return;
			}
			bool flag = false;
			foreach (PickupIndex item in offered)
			{
				string text = KeyFor(item);
				if (text != null)
				{
					if (!seenInCubes.TryGetValue(text, out var value))
					{
						value = (seenInCubes[text] = new HashSet<PickupIndex>());
					}
					if (value.Add(item))
					{
						dirty = true;
					}
					if (text.StartsWith("other:", StringComparison.Ordinal) && text != "other:ItemTier" && discoveredOtherKeys.Add(text))
					{
						flag = true;
					}
				}
			}
			if (flag)
			{
				dirty = true;
				CommandItemQueuePlugin.Instance?.SaveDiscoveredCategories();
			}
		}

		public static void LoadDiscovered(string serialized)
		{
			discoveredOtherKeys.Clear();
			if (string.IsNullOrEmpty(serialized))
			{
				return;
			}
			string[] array = serialized.Split(';');
			foreach (string text in array)
			{
				if (text.StartsWith("other:", StringComparison.Ordinal) && text.Trim() != "other:ItemTier")
				{
					discoveredOtherKeys.Add(text.Trim());
				}
			}
		}

		public static string SerializeDiscovered()
		{
			return string.Join(";", discoveredOtherKeys.ToArray());
		}

		private static void Rebuild()
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			dirty = false;
			lastBuildTime = Time.unscaledTime;
			if ((Object)(object)lastRun != (Object)(object)Run.instance)
			{
				seenInCubes.Clear();
				lastRun = Run.instance;
			}
			groups.Clear();
			ordered.Clear();
			foreach (PickupDef allPickup in PickupCatalog.allPickups)
			{
				string text;
				try
				{
					text = KeyFor(allPickup);
				}
				catch
				{
					continue;
				}
				if (text == null || (text.StartsWith("other:", StringComparison.Ordinal) && !discoveredOtherKeys.Contains(text)))
				{
					continue;
				}
				if (!groups.TryGetValue(text, out var value))
				{
					value = CreateGroup(text, allPickup);
					if (value == null)
					{
						continue;
					}
					groups[text] = value;
				}
				value.Members.Add(allPickup.pickupIndex);
			}
			Run instance = Run.instance;
			foreach (PickupGroup value3 in groups.Values)
			{
				seenInCubes.TryGetValue(value3.Key, out var value2);
				foreach (PickupIndex member in value3.Members)
				{
					if ((value2 != null && value2.Contains(member)) || IsAvailableInRun(instance, member))
					{
						value3.Available.Add(member);
					}
				}
				value3.Members.Sort((PickupIndex a, PickupIndex b) => string.Compare(DisplayName(a), DisplayName(b), StringComparison.CurrentCultureIgnoreCase));
				ordered.Add(value3);
			}
			ordered.Sort(delegate(PickupGroup a, PickupGroup b)
			{
				int num = a.SortOrder.CompareTo(b.SortOrder);
				return (num == 0) ? string.Compare(a.DisplayName, b.DisplayName, StringComparison.Ordinal) : num;
			});
		}

		private static bool IsAvailableInRun(Run run, PickupIndex p)
		{
			//IL_000b: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)run))
			{
				return true;
			}
			try
			{
				PickupIndex[] availableGroupFromPickupIndex = PickupTransmutationManager.GetAvailableGroupFromPickupIndex(p);
				if (availableGroupFromPickupIndex != null && availableGroupFromPickupIndex.Length != 0)
				{
					return Array.IndexOf(availableGroupFromPickupIndex, p) >= 0;
				}
			}
			catch
			{
			}
			try
			{
				return run.IsPickupAvailable(p);
			}
			catch
			{
				return true;
			}
		}

		private static PickupGroup CreateGroup(string key, PickupDef firstMember)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			PickupGroup pickupGroup = new PickupGroup
			{
				Key = key,
				Color = firstMember.baseColor
			};
			if (key.StartsWith("item:", StringComparison.Ordinal))
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(firstMember.itemIndex);
				ItemTierDef val = (Object.op_Implicit((Object)(object)itemDef) ? ItemTierCatalog.GetItemTierDef(itemDef.tier) : null);
				string text = key.Substring("item:".Length);
				pickupGroup.DisplayName = (KnownTierNames.TryGetValue(text, out var value) ? value : Prettify(text));
				int num = Array.IndexOf(KnownTierOrder, text);
				pickupGroup.SortOrder = ((num >= 0) ? num : (100 + (Object.op_Implicit((Object)(object)val) ? ((int)val.tier) : 0)));
				if (Object.op_Implicit((Object)(object)val))
				{
					try
					{
						pickupGroup.Color = Color32.op_Implicit(ColorCatalog.GetColor(val.colorIndex));
					}
					catch
					{
					}
				}
			}
			else if (key.StartsWith("equip:", StringComparison.Ordinal))
			{
				string text2 = key.Substring("equip:".Length);
				if (!(text2 == "lunar"))
				{
					if (text2 == "boss")
					{
						pickupGroup.DisplayName = "Boss Equipment";
						pickupGroup.SortOrder = 202;
					}
					else
					{
						pickupGroup.DisplayName = "Equipment";
						pickupGroup.SortOrder = 200;
					}
				}
				else
				{
					pickupGroup.DisplayName = "Lunar Equipment";
					pickupGroup.SortOrder = 201;
				}
			}
			else
			{
				pickupGroup.DisplayName = Prettify(key.Substring("other:".Length).Replace("Index", ""));
				pickupGroup.SortOrder = 300;
			}
			if (string.IsNullOrEmpty(pickupGroup.DisplayName))
			{
				pickupGroup.DisplayName = key;
			}
			pickupGroup.Color.a = 1f;
			return pickupGroup;
		}

		internal static string Prettify(string raw)
		{
			if (string.IsNullOrEmpty(raw))
			{
				return raw;
			}
			string text = raw;
			if (text.EndsWith("Def", StringComparison.Ordinal))
			{
				text = text.Substring(0, text.Length - 3);
			}
			if (text.EndsWith("Tier", StringComparison.Ordinal) && text.Length > 4)
			{
				text = text.Substring(0, text.Length - 4);
			}
			text = text.Replace("_", " ");
			text = Regex.Replace(text, "(?<=[a-z])(?=[A-Z0-9])", " ").Trim();
			if (!string.IsNullOrEmpty(text))
			{
				return text;
			}
			return raw;
		}

		public static string DisplayName(PickupIndex p)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			string currentLanguageName = Language.currentLanguageName;
			if (currentLanguageName != cachedLanguage)
			{
				nameCache.Clear();
				cachedLanguage = currentLanguageName;
			}
			if (nameCache.TryGetValue(p, out var value))
			{
				return value;
			}
			PickupDef pickupDef = PickupCatalog.GetPickupDef(p);
			value = ((pickupDef != null) ? Language.GetString(pickupDef.nameToken) : "?");
			if (string.IsNullOrEmpty(value) && pickupDef != null)
			{
				value = pickupDef.internalName;
			}
			nameCache[p] = value;
			return value;
		}

		public static string LongDescription(PickupIndex p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_001c: 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)
			PickupDef pickupDef = PickupCatalog.GetPickupDef(p);
			if (pickupDef == null)
			{
				return "";
			}
			string text = null;
			if ((int)pickupDef.itemIndex != -1)
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);
				if (Object.op_Implicit((Object)(object)itemDef))
				{
					text = itemDef.descriptionToken;
				}
			}
			else if ((int)pickupDef.equipmentIndex != -1)
			{
				EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex);
				if (Object.op_Implicit((Object)(object)equipmentDef))
				{
					text = equipmentDef.descriptionToken;
				}
			}
			if (!string.IsNullOrEmpty(text))
			{
				return Language.GetString(text);
			}
			return "";
		}

		public static string Description(PickupIndex p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_001c: 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)
			PickupDef pickupDef = PickupCatalog.GetPickupDef(p);
			if (pickupDef == null)
			{
				return "";
			}
			string text = null;
			if ((int)pickupDef.itemIndex != -1)
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);
				if (Object.op_Implicit((Object)(object)itemDef))
				{
					text = itemDef.pickupToken;
				}
			}
			else if ((int)pickupDef.equipmentIndex != -1)
			{
				EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex);
				if (Object.op_Implicit((Object)(object)equipmentDef))
				{
					text = equipmentDef.pickupToken;
				}
			}
			if (!string.IsNullOrEmpty(text))
			{
				return Language.GetString(text);
			}
			return "";
		}

		public static bool TryGetIcon(PickupIndex p, out Texture texture, out Rect uv, out float aspect)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_00ca: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			texture = null;
			uv = new Rect(0f, 0f, 1f, 1f);
			aspect = 1f;
			PickupDef pickupDef = PickupCatalog.GetPickupDef(p);
			if (pickupDef == null)
			{
				return false;
			}
			if (loadedIcons.TryGetValue(p, out var value))
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					return FromSprite(value, out texture, out uv, out aspect);
				}
				loadedIcons.Remove(p);
				requestTimes.Remove(p);
			}
			if (Object.op_Implicit((Object)(object)pickupDef.iconSprite))
			{
				return FromSprite(pickupDef.iconSprite, out texture, out uv, out aspect);
			}
			if (Object.op_Implicit((Object)(object)pickupDef.iconTexture))
			{
				texture = pickupDef.iconTexture;
				aspect = ((texture.height > 0) ? ((float)texture.width / (float)texture.height) : 1f);
				return true;
			}
			if (!requestTimes.TryGetValue(p, out var value2) || Time.unscaledTime - value2 > 3f)
			{
				requestTimes[p] = Time.unscaledTime;
				RequestIcon(p, pickupDef);
			}
			return false;
		}

		private static void RequestIcon(PickupIndex p, PickupDef def)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (GetIconMethod != null)
				{
					object? obj = GetIconMethod.Invoke(def, null);
					Sprite val = (Sprite)((obj is Sprite) ? obj : null);
					if (val != null && Object.op_Implicit((Object)(object)val))
					{
						loadedIcons[p] = val;
						return;
					}
				}
				if (!(GetIconAodrMethod != null))
				{
					return;
				}
				Action<Sprite> action = delegate(Sprite sprite)
				{
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					if (Object.op_Implicit((Object)(object)sprite))
					{
						loadedIcons[p] = sprite;
					}
				};
				object[] array = new object[GetIconAodrMethod.GetParameters().Length];
				if (array.Length != 0)
				{
					array[0] = true;
				}
				if (array.Length > 1)
				{
					array[1] = action;
				}
				object obj2 = GetIconAodrMethod.Invoke(def, array);
				if (obj2 != null)
				{
					iconHandles.Add(obj2);
				}
			}
			catch (Exception ex)
			{
				if (!loggedIconError)
				{
					loggedIconError = true;
					Log.Warning("Could not load item icons: " + ex);
				}
			}
		}

		private static bool FromSprite(Sprite sprite, out Texture texture, out Rect uv, out float aspect)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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)
			texture = (Texture)(object)sprite.texture;
			uv = new Rect(0f, 0f, 1f, 1f);
			aspect = 1f;
			if (!Object.op_Implicit((Object)(object)texture))
			{
				return false;
			}
			try
			{
				Vector2[] uv2 = sprite.uv;
				if (uv2 != null && uv2.Length != 0)
				{
					float num = 1f;
					float num2 = 1f;
					float num3 = 0f;
					float num4 = 0f;
					Vector2[] array = uv2;
					foreach (Vector2 val in array)
					{
						if (val.x < num)
						{
							num = val.x;
						}
						if (val.y < num2)
						{
							num2 = val.y;
						}
						if (val.x > num3)
						{
							num3 = val.x;
						}
						if (val.y > num4)
						{
							num4 = val.y;
						}
					}
					if (num3 > num && num4 > num2)
					{
						uv = new Rect(num, num2, num3 - num, num4 - num2);
					}
				}
				float num5 = ((Rect)(ref uv)).width * (float)texture.width;
				float num6 = ((Rect)(ref uv)).height * (float)texture.height;
				if (num5 > 0f && num6 > 0f)
				{
					aspect = num5 / num6;
				}
			}
			catch
			{
			}
			return true;
		}

		public static Color PickupColor(PickupIndex p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			PickupDef pickupDef = PickupCatalog.GetPickupDef(p);
			if (pickupDef == null)
			{
				return Color.white;
			}
			Color baseColor = pickupDef.baseColor;
			baseColor.a = 1f;
			return baseColor;
		}
	}
	[BepInPlugin("AllOfThem.CommandItemQueue", "CommandItemQueue", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CommandItemQueuePlugin : BaseUnityPlugin
	{
		public const string PluginAuthor = "AllOfThem";

		public const string PluginName = "CommandItemQueue";

		public const string PluginGUID = "AllOfThem.CommandItemQueue";

		public const string PluginVersion = "1.2.0";

		private Harmony harmony;

		internal static CommandItemQueuePlugin Instance { get; private set; }

		internal static PluginConfig Cfg { get; private set; }

		internal QueueManager Queues { get; private set; }

		internal BuildStore Builds { get; private set; }

		internal ScoreboardBridge Scoreboard { get; private set; }

		internal QueueWindow Window { get; private set; }

		public void Awake()
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			Instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			Cfg = new PluginConfig(((BaseUnityPlugin)this).Config);
			PickupGroups.LoadDiscovered(Cfg.DiscoveredCategories.Value);
			RiskOfOptionsCompat.TryRegister(Cfg, ((BaseUnityPlugin)this).Info.Location);
			Queues = new QueueManager();
			Builds = new BuildStore(Path.Combine(Paths.ConfigPath, "CommandItemQueue.builds.txt"));
			Builds.Load();
			Scoreboard = new ScoreboardBridge();
			Window = new QueueWindow(this);
			harmony = new Harmony("AllOfThem.CommandItemQueue");
			AutoPicker.Install(harmony);
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(CreateCategorySwitches));
			Run.onRunStartGlobal += OnRunStart;
			Run.onRunDestroyGlobal += OnRunDestroy;
		}

		public void OnDestroy()
		{
			Run.onRunStartGlobal -= OnRunStart;
			Run.onRunDestroyGlobal -= OnRunDestroy;
			try
			{
				Harmony obj = harmony;
				if (obj != null)
				{
					obj.UnpatchSelf();
				}
			}
			catch (Exception data)
			{
				Log.Warning(data);
			}
			Scoreboard?.SetHidden(hide: false);
		}

		private static void CreateCategorySwitches()
		{
			try
			{
				PickupGroups.Invalidate();
				foreach (PickupGroup item in PickupGroups.GetAll())
				{
					Cfg.CategoryToggle(item);
				}
			}
			catch (Exception ex)
			{
				Log.Error("Could not create category settings: " + ex);
			}
		}

		private void OnRunStart(Run run)
		{
			try
			{
				PickupGroups.Invalidate();
				if (!Cfg.KeepQueueBetweenRuns.Value)
				{
					Queues.ClearAll();
				}
				Queues.ResetRepeat();
				Queues.ResetCursors();
				BuildData autoLoadBuild = Builds.GetAutoLoadBuild();
				if (autoLoadBuild != null)
				{
					Queues.Apply(autoLoadBuild);
					Log.Info("Auto-loaded build '" + autoLoadBuild.Name + "'.");
				}
			}
			catch (Exception data)
			{
				Log.Error(data);
			}
		}

		private void OnRunDestroy(Run run)
		{
			PickupGroups.Invalidate();
			Scoreboard?.SetHidden(hide: false);
		}

		public void Update()
		{
			try
			{
				AutoPicker.Update();
			}
			catch (Exception data)
			{
				Log.Error(data);
			}
			try
			{
				Window.Update();
			}
			catch (Exception data2)
			{
				Log.Error(data2);
			}
		}

		public void OnGUI()
		{
			Window.OnGUI();
		}

		internal void SaveDiscoveredCategories()
		{
			Cfg.DiscoveredCategories.Value = PickupGroups.SerializeDiscovered();
		}
	}
	public enum StartView
	{
		RememberLast,
		Scoreboard,
		ItemQueue
	}
	internal sealed class PluginConfig
	{
		public readonly ConfigEntry<bool> KeepQueueBetweenRuns;

		public readonly ConfigEntry<bool> OnlyWithArtifactOfCommand;

		public readonly ConfigEntry<bool> ApplyToVoidPotentials;

		public readonly ConfigEntry<KeyboardShortcut> ManualPickKey;

		public readonly ConfigEntry<StartView> DefaultView;

		public readonly ConfigEntry<KeyboardShortcut> SwitchViewKey;

		public readonly ConfigEntry<float> UiScale;

		public readonly ConfigEntry<bool> ShowUnavailableItems;

		public readonly ConfigEntry<bool> ShowTooltips;

		private readonly ConfigFile file;

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

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

		public readonly ConfigEntry<bool> LastViewWasQueue;

		public readonly ConfigEntry<string> DiscoveredCategories;

		public PluginConfig(ConfigFile cfg)
		{
			//IL_008d: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			file = cfg;
			KeepQueueBetweenRuns = cfg.Bind<bool>("General", "KeepQueueBetweenRuns", false, "Keep the current queue when a new run starts. If false, the queue is cleared (an auto-load build is still applied).");
			OnlyWithArtifactOfCommand = cfg.Bind<bool>("General", "OnlyWithArtifactOfCommand", true, "Only show the Item Queue tab in the scoreboard when the Artifact of Command is enabled.");
			ApplyToVoidPotentials = cfg.Bind<bool>("General", "ApplyToVoidPotentials", false, "Also auto-pick from Void Potentials / option pickups if one of the offered items is in your queue.");
			ManualPickKey = cfg.Bind<KeyboardShortcut>("General", "ManualPickKey", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), "Hold this key while opening a command cube to ignore the queue and choose manually.");
			DefaultView = cfg.Bind<StartView>("UI", "DefaultView", StartView.RememberLast, "Which view is shown when you open the scoreboard (Tab).");
			SwitchViewKey = cfg.Bind<KeyboardShortcut>("UI", "SwitchViewKey", KeyboardShortcut.Empty, "Optional key to switch between Scoreboard and Item Queue while the scoreboard is open (you can always click the tabs).");
			UiScale = cfg.Bind<float>("UI", "Scale", 1f, new ConfigDescription("Size of the Item Queue window. 1 = as large as fits the screen, smaller values shrink it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.6f, 1f), Array.Empty<object>()));
			ShowUnavailableItems = cfg.Bind<bool>("UI", "ShowUnavailableItems", false, "Also show items that cannot drop in the current run (locked, disabled expansion, ...). They are skipped when picking.");
			ShowTooltips = cfg.Bind<bool>("UI", "ShowTooltips", true, "Show item name and description when hovering an icon.");
			LastViewWasQueue = cfg.Bind<bool>("Internal", "LastViewWasQueue", false, "Remembers the last selected view. No need to edit.");
			DiscoveredCategories = cfg.Bind<string>("Internal", "DiscoveredCategories", "", "Extra command categories that were discovered at runtime (non-item, non-equipment pickups). No need to edit.");
		}

		public ConfigEntry<bool> CategoryToggle(PickupGroup group)
		{
			if (categoryVisibility.TryGetValue(group.Key, out var value))
			{
				return value;
			}
			string text = ConfigSafe(group.DisplayName);
			if (string.IsNullOrEmpty(text) || usedCategoryNames.Contains(text))
			{
				text = ConfigSafe(group.DisplayName + " " + group.Key);
			}
			usedCategoryNames.Add(text);
			value = file.Bind<bool>("Categories", text, true, "Show the " + group.DisplayName + " category in the Item Queue window. Hiding only affects the window; queued items of a hidden category are still picked.");
			categoryVisibility[group.Key] = value;
			RiskOfOptionsCompat.AddCategoryToggle(value);
			return value;
		}

		public bool IsCategoryVisible(PickupGroup group)
		{
			return CategoryToggle(group).Value;
		}

		private static string ConfigSafe(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return s;
			}
			char[] array = new char[10] { '=', '\n', '\t', '\\', '"', '\'', '[', ']', ':', ';' };
			foreach (char c in array)
			{
				s = s.Replace(c.ToString(), " ");
			}
			return s.Trim();
		}
	}
	internal sealed class QueueEntry
	{
		public PickupIndex Pickup;

		public int Count;

		public QueueEntry(PickupIndex pickup, int count)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			Pickup = pickup;
			Count = count;
		}
	}
	internal sealed class GroupQueue
	{
		public readonly string Key;

		public readonly List<QueueEntry> Entries = new List<QueueEntry>();

		public bool Repeat;

		public int Cursor;

		public int UsedAtCursor;

		public int TotalCount
		{
			get
			{
				int num = 0;
				foreach (QueueEntry entry in Entries)
				{
					num += entry.Count;
				}
				return num;
			}
		}

		public GroupQueue(string key)
		{
			Key = key;
		}

		public int CountOf(PickupIndex pickup)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			foreach (QueueEntry entry in Entries)
			{
				if (entry.Pickup == pickup)
				{
					num += entry.Count;
				}
			}
			return num;
		}

		public void Add(PickupIndex pickup, int amount = 1)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (amount > 0)
			{
				if (Entries.Count > 0 && Entries[Entries.Count - 1].Pickup == pickup)
				{
					Entries[Entries.Count - 1].Count += amount;
				}
				else
				{
					Entries.Add(new QueueEntry(pickup, amount));
				}
				Clamp();
			}
		}

		public void RemoveOne(PickupIndex pickup)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			for (int num = Entries.Count - 1; num >= 0; num--)
			{
				if (!(Entries[num].Pickup != pickup))
				{
					ChangeEntry(num, -1);
					break;
				}
			}
		}

		public void RemoveAllOf(PickupIndex pickup)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			for (int num = Entries.Count - 1; num >= 0; num--)
			{
				if (Entries[num].Pickup == pickup)
				{
					RemoveEntry(num);
				}
			}
		}

		public void ChangeEntry(int index, int delta)
		{
			if (index >= 0 && index < Entries.Count)
			{
				Entries[index].Count += delta;
				if (Entries[index].Count <= 0)
				{
					RemoveEntry(index);
				}
				else
				{
					Clamp();
				}
			}
		}

		public void RemoveEntry(int index)
		{
			if (index >= 0 && index < Entries.Count)
			{
				Entries.RemoveAt(index);
				if (index < Cursor)
				{
					Cursor--;
				}
				else if (index == Cursor)
				{
					UsedAtCursor = 0;
				}
				Clamp();
			}
		}

		public void Move(int index, int direction)
		{
			int num = index + direction;
			if (index >= 0 && index < Entries.Count && num >= 0 && num < Entries.Count)
			{
				QueueEntry value = Entries[index];
				Entries[index] = Entries[num];
				Entries[num] = value;
				if (Cursor == index)
				{
					Cursor = num;
				}
				else if (Cursor == num)
				{
					Cursor = index;
				}
				MergeNeighbours();
				Clamp();
			}
		}

		public void MoveTo(int from, int insertIndex)
		{
			if (from < 0 || from >= Entries.Count)
			{
				return;
			}
			insertIndex = Math.Max(0, Math.Min(insertIndex, Entries.Count));
			if (insertIndex != from && insertIndex != from + 1)
			{
				QueueEntry item = Entries[from];
				Entries.RemoveAt(from);
				if (insertIndex > from)
				{
					insertIndex--;
				}
				Entries.Insert(insertIndex, item);
				MergeNeighbours();
				Cursor = 0;
				UsedAtCursor = 0;
			}
		}

		public void Insert(int insertIndex, PickupIndex pickup, int amount = 1)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			if (amount > 0)
			{
				insertIndex = Math.Max(0, Math.Min(insertIndex, Entries.Count));
				QueueEntry current = ((Entries.Count > 0) ? Entries[Cursor] : null);
				if (insertIndex > 0 && Entries[insertIndex - 1].Pickup == pickup)
				{
					Entries[insertIndex - 1].Count += amount;
				}
				else if (insertIndex < Entries.Count && Entries[insertIndex].Pickup == pickup)
				{
					Entries[insertIndex].Count += amount;
				}
				else
				{
					Entries.Insert(insertIndex, new QueueEntry(pickup, amount));
				}
				RestoreCursor(current);
			}
		}

		private void RestoreCursor(QueueEntry current)
		{
			int num = ((current != null) ? Entries.IndexOf(current) : (-1));
			if (num < 0)
			{
				Cursor = 0;
				UsedAtCursor = 0;
			}
			else
			{
				Cursor = num;
			}
			Clamp();
		}

		public void Clear()
		{
			Entries.Clear();
			Cursor = 0;
			UsedAtCursor = 0;
		}

		public void ResetCursor()
		{
			Cursor = 0;
			UsedAtCursor = 0;
		}

		private void MergeNeighbours()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			for (int num = Entries.Count - 1; num > 0; num--)
			{
				if (!(Entries[num].Pickup != Entries[num - 1].Pickup))
				{
					Entries[num - 1].Count += Entries[num].Count;
					Entries.RemoveAt(num);
					if (Cursor >= num)
					{
						Cursor = Math.Max(0, Cursor - 1);
					}
				}
			}
		}

		private void Clamp()
		{
			if (Entries.Count == 0)
			{
				Cursor = 0;
				UsedAtCursor = 0;
				return;
			}
			if (Cursor < 0 || Cursor >= Entries.Count)
			{
				Cursor = 0;
				UsedAtCursor = 0;
			}
			if (UsedAtCursor >= Entries[Cursor].Count)
			{
				UsedAtCursor = 0;
			}
		}

		public int PeekNextIndex(Func<PickupIndex, bool> isAvailable)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (Entries.Count == 0)
			{
				return -1;
			}
			int num = (Repeat ? Cursor : 0);
			for (int i = 0; i < Entries.Count; i++)
			{
				int num2 = (num + i) % Entries.Count;
				if (isAvailable == null || isAvailable(Entries[num2].Pickup))
				{
					return num2;
				}
			}
			return -1;
		}

		public bool TryTake(Func<PickupIndex, int> optionIndexOf, out int optionIndex, out PickupIndex taken)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			optionIndex = -1;
			taken = PickupIndex.none;
			if (Entries.Count == 0)
			{
				return false;
			}
			if (!Repeat)
			{
				for (int i = 0; i < Entries.Count; i++)
				{
					int num = optionIndexOf(Entries[i].Pickup);
					if (num >= 0)
					{
						optionIndex = num;
						taken = Entries[i].Pickup;
						ChangeEntry(i, -1);
						return true;
					}
				}
				return false;
			}
			Clamp();
			for (int j = 0; j < Entries.Count; j++)
			{
				int num2 = (Cursor + j) % Entries.Count;
				int num3 = optionIndexOf(Entries[num2].Pickup);
				if (num3 >= 0)
				{
					if (num2 != Cursor)
					{
						Cursor = num2;
						UsedAtCursor = 0;
					}
					optionIndex = num3;
					taken = Entries[num2].Pickup;
					UsedAtCursor++;
					if (UsedAtCursor >= Entries[num2].Count)
					{
						Cursor = (Cursor + 1) % Entries.Count;
						UsedAtCursor = 0;
					}
					return true;
				}
			}
			return false;
		}
	}
	internal sealed class QueueManager
	{
		private readonly Dictionary<string, GroupQueue> queues = new Dictionary<string, GroupQueue>();

		public int TotalQueued
		{
			get
			{
				int num = 0;
				foreach (GroupQueue value in queues.Values)
				{
					num += value.TotalCount;
				}
				return num;
			}
		}

		public void ResetRepeat()
		{
			foreach (GroupQueue value in queues.Values)
			{
				value.Repeat = false;
				value.ResetCursor();
			}
		}

		public GroupQueue Get(string key)
		{
			if (!queues.TryGetValue(key, out var value))
			{
				value = (queues[key] = new GroupQueue(key));
			}
			return value;
		}

		public GroupQueue TryGet(string key)
		{
			if (key == null)
			{
				return null;
			}
			queues.TryGetValue(key, out var value);
			return value;
		}

		public void ClearAll()
		{
			foreach (GroupQueue value in queues.Values)
			{
				value.Clear();
			}
		}

		public void ResetCursors()
		{
			foreach (GroupQueue value in queues.Values)
			{
				value.ResetCursor();
			}
		}

		public BuildData Snapshot(string name)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			BuildData buildData = new BuildData
			{
				Name = name,
				Created = DateTime.Now
			};
			foreach (GroupQueue value in queues.Values)
			{
				if (value.Repeat)
				{
					buildData.RepeatKeys.Add(value.Key);
				}
				if (value.Entries.Count == 0)
				{
					continue;
				}
				List<BuildEntry> list = new List<BuildEntry>();
				foreach (QueueEntry entry in value.Entries)
				{
					PickupDef pickupDef = PickupCatalog.GetPickupDef(entry.Pickup);
					if (pickupDef != null)
					{
						list.Add(new BuildEntry
						{
							InternalName = pickupDef.internalName,
							Count = entry.Count
						});
					}
				}
				buildData.Queues[value.Key] = list;
			}
			return buildData;
		}

		public int Apply(BuildData build)
		{
			//IL_003d: 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_0050: 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)
			ClearAll();
			int num = 0;
			foreach (KeyValuePair<string, List<BuildEntry>> queue in build.Queues)
			{
				foreach (BuildEntry item in queue.Value)
				{
					PickupIndex val = PickupCatalog.FindPickupIndex(item.InternalName);
					string text = (((PickupIndex)(ref val)).isValid ? PickupGroups.KeyFor(val) : null);
					if (text == null)
					{
						num++;
					}
					else
					{
						Get(text).Add(val, item.Count);
					}
				}
			}
			ResetRepeat();
			foreach (string repeatKey in build.RepeatKeys)
			{
				Get(repeatKey).Repeat = true;
			}
			ResetCursors();
			if (num > 0)
			{
				Log.Warning($"Build '{build.Name}': {num} entries could not be found and were skipped.");
			}
			return num;
		}
	}
	internal sealed class QueueWindow
	{
		private enum DragSource
		{
			None,
			Queue,
			Grid
		}

		private enum ButtonKind
		{
			Normal,
			Active,
			Danger
		}

		private static readonly Color PanelColor = new Color(0.13f, 0.16f, 0.2f, 0.55f);

		private static readonly Color StripColor = new Color(0.27f, 0.31f, 0.38f, 0.62f);

		private static readonly Color StripHover = new Color(0.36f, 0.41f, 0.49f, 0.75f);

		private static readonly Color StripSelected = new Color(0.4f, 0.44f, 0.51f, 0.82f);

		private static readonly Color SlotColor = new Color(0.17f, 0.2f, 0.25f, 0.55f);

		private static readonly Color BracketColor = new Color(0.04f, 0.045f, 0.06f, 0.95f);

		private static readonly Color Gold = new Color(0.93f, 0.8f, 0.33f, 1f);

		private static readonly Color GoldFill = new Color(0.8f, 0.64f, 0.18f, 0.95f);

		private static readonly Color GoldHover = new Color(0.9f, 0.74f, 0.25f, 1f);

		private static readonly Color ButtonColor = new Color(0.12f, 0.15f, 0.19f, 0.85f);

		private static readonly Color ButtonHover = new Color(0.22f, 0.26f, 0.32f, 0.9f);

		private static readonly Color DangerFill = new Color(0.62f, 0.18f, 0.16f, 0.9f);

		private static readonly Color DangerHover = new Color(0.78f, 0.24f, 0.2f, 1f);

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

		private static readonly Color Muted = new Color(0.78f, 0.81f, 0.86f, 1f);

		private static readonly Color Dim = new Color(0.6f, 0.64f, 0.7f, 1f);

		private static readonly Color Red = new Color(0.9f, 0.36f, 0.3f, 1f);

		private static readonly Color Shadow = new Color(0f, 0f, 0f, 0.75f);

		private static readonly Color TooltipBody = new Color(0.27f, 0.3f, 0.36f, 0.94f);

		private const float ConfirmSeconds = 3f;

		private readonly CommandItemQueuePlugin plugin;

		private bool offered;

		private bool wasOpen;

		private bool showQueue;

		private string selectedKey;

		private Vector2 categoryScroll;

		private Vector2 queueScroll;

		private Vector2 itemScroll;

		private Vector2 buildScroll;

		private PickupIndex hoverPickup = PickupIndex.none;

		private string hoverHint;

		private Vector2 outerMouse;

		private string status;

		private bool statusIsError;

		private float statusUntil;

		private object pendingConfirm;

		private string pendingConfirmAction;

		private float pendingConfirmUntil;

		private bool loggedGuiError;

		private bool loggedCursorError;

		private bool stylesReady;

		private Font gameFont;

		private GUIStyle titleStyle;

		private GUIStyle headerStyle;

		private GUIStyle nameStyle;

		private GUIStyle textStyle;

		private GUIStyle smallStyle;

		private GUIStyle smallWrapStyle;

		private GUIStyle centerStyle;

		private GUIStyle countStyle;

		private GUIStyle slotNumberStyle;

		private GUIStyle buttonStyle;

		private GUIStyle buttonDarkStyle;

		private GUIStyle tabStyle;

		private GUIStyle tabActiveStyle;

		private GUIStyle tooltipTitleStyle;

		private GUIStyle tooltipBodyStyle;

		private GUIStyle tooltipHintStyle;

		private GUIStyle iconFallbackStyle;

		private const float QueueSlot = 76f;

		private const float QueueGap = 10f;

		private DragSource dragSource;

		private int dragIndex;

		private PickupIndex dragPickup = PickupIndex.none;

		private Vector2 dragStart;

		private bool dragging;

		private float lastMouseHeldTime;

		private Rect queueViewRect;

		private readonly List<PickupGroup> visibleGroups = new List<PickupGroup>();

		private bool editCategories;

		private int hiddenCategoryCount;

		private readonly List<PickupIndex> visibleItems = new List<PickupIndex>();

		private static ArtifactDef commandArtifact;

		private static bool commandLookupDone;

		private const string RenameControl = "CommandItemQueue_Rename";

		private BuildData renaming;

		private string renameText = "";

		private bool focusRename;

		private bool pinnedForRename;

		private static readonly Regex StyleTag = new Regex("<style=([^>]+)>(.*?)</style>", RegexOptions.Compiled | RegexOptions.Singleline);

		private static readonly Regex UnsupportedTags = new Regex("<(?!/?(b|i|color)\\b)[^>]*>", RegexOptions.Compiled);

		private static readonly Regex AnyTag = new Regex("<[^>]*>", RegexOptions.Compiled);

		private static readonly Dictionary<string, string> StyleColors = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
		{
			{ "cIsDamage", "#E5C962" },
			{ "cIsHealing", "#C9F24D" },
			{ "cIsUtility", "#95CDE5" },
			{ "cIsHealth", "#E25F5F" },
			{ "cDeath", "#E25F5F" },
			{ "cStack", "#A6A6A6" },
			{ "cSub", "#A6A6A6" },
			{ "cMono", "#A6A6A6" },
			{ "cShrine", "#DFA0FF" },
			{ "cArtifact", "#A07FDF" },
			{ "cIsVoid", "#ED7FCD" },
			{ "cIsLunar", "#307FFF" },
			{ "cKeywordName", "#FFFFFF" },
			{ "cHumanObjective", "#E5C962" },
			{ "cLunarObjective", "#307FFF" },
			{ "cWorldEvent", "#FFA34C" },
			{ "cUserSetting", "#A6A6A6" }
		};

		private GUIStyle centeredSmall;

		private GUIStyle centeredSmallRed;

		private GUIStyle goldSmallLeft;

		private GUIStyle centeredSmallRedLeft;

		private GUIStyle textFieldStyle;

		public QueueWindow(CommandItemQueuePlugin plugin)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			this.plugin = plugin;
			showQueue = CommandItemQueuePlugin.Cfg.LastViewWasQueue.Value;
		}

		public void Update()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			PluginConfig cfg = CommandItemQueuePlugin.Cfg;
			ScoreboardBridge scoreboard = plugin.Scoreboard;
			scoreboard.Update();
			bool flag = Object.op_Implicit((Object)(object)Run.instance) && (!cfg.OnlyWithArtifactOfCommand.Value || IsCommandEnabled());
			offered = scoreboard.IsOpen && flag;
			if (offered && !wasOpen)
			{
				switch (cfg.DefaultView.Value)
				{
				case StartView.Scoreboard:
					showQueue = false;
					break;
				case StartView.ItemQueue:
					showQueue = true;
					break;
				default:
					showQueue = cfg.LastViewWasQueue.Value;
					break;
				}
			}
			wasOpen = offered;
			if (offered)
			{
				KeyboardShortcut value = cfg.SwitchViewKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					SetView(!showQueue);
				}
			}
			scoreboard.SetHidden(offered && showQueue);
		}

		private void SetView(bool queue)
		{
			showQueue = queue;
			if (CommandItemQueuePlugin.Cfg.LastViewWasQueue.Value != queue)
			{
				CommandItemQueuePlugin.Cfg.LastViewWasQueue.Value = queue;
			}
		}

		private static bool IsCommandEnabled()
		{
			RunArtifactManager instance = RunArtifactManager.instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				return false;
			}
			if (!commandLookupDone)
			{
				commandLookupDone = true;
				commandArtifact = ArtifactCatalog.FindArtifactDef("Command");
				if (!Object.op_Implicit((Object)(object)commandArtifact))
				{
					Log.Warning("Artifact of Command not found by name - the Item Queue tab will always be shown.");
				}
			}
			if (Object.op_Implicit((Object)(object)commandArtifact))
			{
				return instance.IsArtifactEnabled(commandArtifact);
			}
			return true;
		}

		public void OnGUI()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!offered)
			{
				return;
			}
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			try
			{
				Draw();
			}
			catch (Exception ex)
			{
				if (!loggedGuiError)
				{
					loggedGuiError = true;
					Log.Error("Item Queue window error: " + ex);
				}
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.color = color;
			}
			try
			{
				CursorOverlay.Draw();
			}
			catch (Exception ex2)
			{
				if (!loggedCursorError)
				{
					loggedCursorError = true;
					Log.Warning("Cursor overlay error: " + ex2);
				}
			}
		}

		private void Draw()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			EnsureStyles();
			PluginConfig cfg = CommandItemQueuePlugin.Cfg;
			float num = Mathf.Min((float)Screen.width / 1760f, (float)Screen.height / 1000f);
			float num2 = Mathf.Max(0.2f, num * Mathf.Clamp(cfg.UiScale.Value, 0.6f, 1f));
			GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(num2, num2, 1f));
			float num3 = (float)Screen.width / num2;
			float num4 = (float)Screen.height / num2;
			outerMouse = Event.current.mousePosition;
			hoverPickup = PickupIndex.none;
			hoverHint = null;
			float num5 = Mathf.Max(0f, (num4 - 1000f) / 2f);
			DrawTabs(num3, num5);
			if (!showQueue)
			{
				CancelDrag();
				return;
			}
			HandleDragEvents();
			float num6 = Mathf.Min(1640f, num3 - 40f);
			float num7 = Mathf.Min(860f, num4 - num5 - 110f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor((num3 - num6) / 2f, num5 + 92f, num6, num7);
			Rect area = default(Rect);
			((Rect)(ref area))..ctor(((Rect)(ref val)).x, ((Rect)(ref val)).y, 260f, num7);
			Rect area2 = default(Rect);
			((Rect)(ref area2))..ctor(((Rect)(ref val)).xMax - 330f, ((Rect)(ref val)).y, 330f, num7);
			Rect area3 = default(Rect);
			((Rect)(ref area3))..ctor(((Rect)(ref area)).xMax + 18f, ((Rect)(ref val)).y, ((Rect)(ref area2)).x - 18f - (((Rect)(ref area)).xMax + 18f), num7);
			CollectVisibleGroups();
			DrawCategories(area);
			DrawMain(area3);
			DrawBuilds(area2);
			Event current = Event.current;
			if ((int)current.type == 0 && ((Rect)(ref val)).Contains(current.mousePosition))
			{
				current.Use();
			}
			if (dragging)
			{
				DrawDragGhost();
			}
			else if (cfg.ShowTooltips.Value)
			{
				DrawTooltip(num3, num4);
			}
		}

		private void StartPress(DragSource source, int index, PickupIndex pickup)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			dragSource = source;
			dragIndex = index;
			dragPickup = pickup;
			dragStart = outerMouse;
			dragging = false;
			lastMouseHeldTime = Time.unscaledTime;
		}

		private void CancelDrag()
		{
			//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)
			dragSource = DragSource.None;
			dragging = false;
			dragPickup = PickupIndex.none;
		}

		private void HandleDragEvents()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Invalid comparison between Unknown and I4
			//IL_0021: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (dragSource == DragSource.None)
			{
				return;
			}
			Event current = Event.current;
			if ((int)current.type == 3 && !dragging)
			{
				Vector2 val = outerMouse - dragStart;
				if (((Vector2)(ref val)).sqrMagnitude > 64f)
				{
					dragging = true;
				}
			}
			if ((int)current.type == 1 && current.button == 0)
			{
				FinishPress();
				current.Use();
			}
			else if ((int)current.type == 7)
			{
				bool flag = true;
				try
				{
					flag = Input.GetMouseButton(0);
				}
				catch
				{
				}
				if (flag)
				{
					lastMouseHeldTime = Time.unscaledTime;
				}
				else if (Time.unscaledTime - lastMouseHeldTime > 0.3f)
				{
					CancelDrag();
				}
			}
		}

		private void FinishPress()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			PickupGroup pickupGroup = PickupGroups.Find(selectedKey);
			GroupQueue groupQueue = ((pickupGroup != null) ? plugin.Queues.Get(pickupGroup.Key) : null);
			DragSource dragSource = this.dragSource;
			bool flag = dragging;
			int num = dragIndex;
			PickupIndex val = dragPickup;
			CancelDrag();
			if (groupQueue == null)
			{
				return;
			}
			bool flag2 = ((Rect)(ref queueViewRect)).Contains(outerMouse);
			switch (dragSource)
			{
			case DragSource.Queue:
				if (!flag)
				{
					groupQueue.ChangeEntry(num, 1);
					break;
				}
				if (flag2)
				{
					groupQueue.MoveTo(num, DropIndex(groupQueue));
					break;
				}
				groupQueue.RemoveEntry(num);
				SetStatus("Removed " + PickupGroups.DisplayName(val) + " from the queue.");
				break;
			case DragSource.Grid:
				if (!flag)
				{
					groupQueue.Add(val);
				}
				else if (flag2)
				{
					groupQueue.Insert(DropIndex(groupQueue), val);
				}
				break;
			}
		}

		private int DropIndex(GroupQueue queue)
		{
			return Mathf.Clamp(Mathf.FloorToInt((outerMouse.x - ((Rect)(ref queueViewRect)).x + queueScroll.x + 38f) / 86f), 0, queue.Entries.Count);
		}

		private void DrawDragGhost()
		{
			//IL_0041: 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_0065: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			if (((PickupIndex)(ref dragPickup)).isValid)
			{
				Rect r = default(Rect);
				((Rect)(ref r))..ctor(outerMouse.x - 32f, outerMouse.y - 32f, 64f, 64f);
				Color color = GUI.color;
				GUI.color = new Color(1f, 1f, 1f, 0.85f);
				DrawIcon(r, dragPickup, available: true);
				GUI.color = color;
				bool flag = ((Rect)(ref queueViewRect)).Contains(outerMouse);
				string text = (flag ? "Drop to place here" : ((dragSource == DragSource.Queue) ? "Drop outside to remove" : "Drop onto the queue"));
				ShadowLabel(new Rect(outerMouse.x + 36f, outerMouse.y - 10f, 260f, 22f), text, (dragSource == DragSource.Queue && !flag) ? centeredSmallRedLeft : goldSmallLeft);
			}
		}

		private void DrawTabs(float vw, float top)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			float num = top + 14f;
			int totalQueued = plugin.Queues.TotalQueued;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(vw / 2f - 250f - 4f, num, 250f, 40f);
			Rect r2 = default(Rect);
			((Rect)(ref r2))..ctor(vw / 2f + 4f, num, 250f, 40f);
			if (Tab(r, "Scoreboard", !showQueue))
			{
				SetView(queue: false);
			}
			if (Tab(r2, (totalQueued > 0) ? $"Item Queue  ·  {totalQueued}" : "Item Queue", showQueue))
			{
				SetView(queue: true);
			}
			ScoreboardBridge scoreboard = plugin.Scoreboard;
			Rect r3 = default(Rect);
			((Rect)(ref r3))..ctor(((Rect)(ref r2)).xMax + 14f, num + 4f, 190f, 32f);
			if (Button(r3, scoreboard.Pinned ? "Pinned · Tab closes" : "Keep open", scoreboard.Pinned ? ButtonKind.Active : ButtonKind.Normal))
			{
				scoreboard.SetPinned(!scoreboard.Pinned);
			}
		}

		private bool Tab(Rect r, string text, bool active)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			Event current = Event.current;
			bool flag = ((Rect)(ref r)).Contains(current.mousePosition);
			if ((int)current.type == 7)
			{
				Fill(r, active ? GoldFill : (flag ? ButtonHover : ButtonColor));
				Brackets(r, BracketColor, 10f, 2f);
				ShadowLabel(r, text, active ? tabActiveStyle : tabStyle, !active);
			}
			if ((int)current.type == 0 && current.button == 0 && flag)
			{
				current.Use();
				return !active;
			}
			return false;
		}

		private void CollectVisibleGroups()
		{
			PluginConfig cfg = CommandItemQueuePlugin.Cfg;
			bool value = cfg.ShowUnavailableItems.Value;
			visibleGroups.Clear();
			hiddenCategoryCount = 0;
			foreach (PickupGroup item in PickupGroups.GetAll())
			{
				GroupQueue groupQueue = plugin.Queues.TryGet(item.Key);
				bool flag = groupQueue != null && groupQueue.Entries.Count > 0;
				if (!(item.Available.Count > 0 || flag) && (!value || item.Members.Count <= 0))
				{
					continue;
				}
				if (!cfg.IsCategoryVisible(item))
				{
					hiddenCategoryCount++;
					if (!editCategories)
					{
						continue;
					}
				}
				visibleGroups.Add(item);
			}
			bool flag2 = false;
			foreach (PickupGroup visibleGroup in visibleGroups)
			{
				if (visibleGroup.Key == selectedKey)
				{
					flag2 = true;
					break;
				}
			}
			if (!flag2)
			{
				selectedKey = ((visibleGroups.Count > 0) ? visibleGroups[0].Key : null);
			}
		}

		private void DrawCategories(Rect area)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Invalid comparison between Unknown and I4
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: 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_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			Section(area);
			ShadowLabel(new Rect(((Rect)(ref area)).x + 14f, ((Rect)(ref area)).y + 8f, ((Rect)(ref area)).width - 28f, 30f), "Categories", headerStyle);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref area)).x + 10f, ((Rect)(ref area)).y + 46f, ((Rect)(ref area)).width - 20f, ((Rect)(ref area)).height - 46f - 108f);
			bool flag = (float)visibleGroups.Count * 60f > ((Rect)(ref val)).height;
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(0f, 0f, ((Rect)(ref val)).width - (flag ? 16f : 0f), (float)visibleGroups.Count * 60f);
			bool flag2 = ((Rect)(ref val)).Contains(Event.current.mousePosition);
			categoryScroll = GUI.BeginScrollView(val, categoryScroll, val2, false, false);
			Rect r = default(Rect);
			Rect r2 = default(Rect);
			for (int i = 0; i < visibleGroups.Count; i++)
			{
				PickupGroup pickupGroup = visibleGroups[i];
				((Rect)(ref r))..ctor(0f, (float)i * 60f + 2f, ((Rect)(ref val2)).width, 52f);
				GroupQueue groupQueue = plugin.Queues.TryGet(pickupGroup.Key);
				bool flag3 = pickupGroup.Key == selectedKey;
				bool flag4 = flag2 && ((Rect)(ref r)).Contains(Event.current.mousePosition);
				bool flag5 = !editCategories || CommandItemQueuePlugin.Cfg.IsCategoryVisible(pickupGroup);
				if ((int)Event.current.type == 7)
				{
					Color color = GUI.color;
					if (!flag5)
					{
						GUI.color = new Color(1f, 1f, 1f, 0.4f);
					}
					Fill(r, flag3 ? StripSelected : (flag4 ? StripHover : StripColor));
					if (flag3)
					{
						GoldLines(r);
					}
					Fill(new Rect(((Rect)(ref r)).x + 8f, ((Rect)(ref r)).y + 10f, 4f, ((Rect)(ref r)).height - 20f), pickupGroup.Color);
					Brackets(r, BracketColor, 9f, 2f);
					ShadowLabel(new Rect(((Rect)(ref r)).x + 22f, ((Rect)(ref r)).y + 6f, ((Rect)(ref r)).width - 90f, 24f), pickupGroup.DisplayName, nameStyle);
					ShadowLabel(new Rect(((Rect)(ref r)).x + 22f, ((Rect)(ref r)).y + 29f, ((Rect)(ref r)).width - 90f, 18f), (!flag5) ? "hidden" : ($"{pickupGroup.Available.Count} items" + ((groupQueue != null && groupQueue.Repeat) ? "  ·  repeat" : "")), smallStyle);
					int num = groupQueue?.TotalCount ?? 0;
					if (num > 0 && !editCategories)
					{
						ShadowLabel(new Rect(((Rect)(ref r)).xMax - 70f, ((Rect)(ref r)).y, 58f, 52f), "x" + num, countStyle);
					}
					GUI.color = color;
				}
				if (editCategories)
				{
					((Rect)(ref r2))..ctor(((Rect)(ref r)).xMax - 74f, ((Rect)(ref r)).y + 10f, 64f, 32f);
					if (Button(r2, flag5 ? "Hide" : "Show", (!flag5) ? ButtonKind.Active : ButtonKind.Normal, flag2))
					{
						CommandItemQueuePlugin.Cfg.CategoryToggle(pickupGroup).Value = !flag5;
						continue;
					}
				}
				if (flag2 && Clicked(r) == 0)
				{
					selectedKey = pickupGroup.Key;
					itemScroll = Vector2.zero;
					queueScroll = Vector2.zero;
				}
			}
			GUI.EndScrollView();
			if (visibleGroups.Count == 0)
			{
				ShadowLabel(new Rect(((Rect)(ref area)).x + 14f, ((Rect)(ref area)).y + 50f, ((Rect)(ref area)).width - 28f, 60f), "No categories yet.\nThey appear once the run is loaded.", smallWrapStyle);
			}
			Rect r3 = default(Rect);
			((Rect)(ref r3))..ctor(((Rect)(ref area)).x + 10f, ((Rect)(ref area)).yMax - 98f, ((Rect)(ref area)).width - 20f, 40f);
			string text = (editCategories ? "Done" : ((hiddenCategoryCount > 0) ? $"Show / hide categories ({hiddenCategoryCount} hidden)" : "Show / hide categories"));
			if (Button(r3, text, editCategories ? ButtonKind.Active : ButtonKind.Normal))
			{
				editCategories = !editCategories;
				if (editCategories)
				{
					SetStatus("Click Hide / Show next to a category. Hidden categories stay hidden in every run (also in Mod Options).");
				}
			}
			Rect r4 = default(Rect);
			((Rect)(ref r4))..ctor(((Rect)(ref area)).x + 10f, ((Rect)(ref area)).yMax - 52f, ((Rect)(ref area)).width - 20f, 40f);
			bool flag6 = IsConfirming("clearall", this);
			if (Button(r4, flag6 ? "Click again to clear all" : "Clear all queues", flag6 ? ButtonKind.Danger : ButtonKind.Normal))
			{
				if (flag6)
				{
					plugin.Queues.ClearAll();
					ClearConfirm();
					SetStatus("All queues cleared.");
				}
				else
				{
					StartConfirm("clearall", this);
				}
			}
		}

		private void DrawMain(Rect area)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: 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)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			PickupGroup pickupGroup = PickupGroups.Find(selectedKey);
			if (pickupGroup == null)
			{
				Section(area);
				ShadowLabel(area, "Nothing to show yet.", centerStyle);
				return;
			}
			GroupQueue groupQueue = plugin.Queues.Get(pickupGroup.Key);
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(((Rect)(ref area)).x, ((Rect)(ref area)).y, ((Rect)(ref area)).width, 60f);
			Fill(r, StripSelected);
			GoldLines(r);
			Brackets(r, BracketColor, 12f, 2f);
			Fill(new Rect(((Rect)(ref r)).x + 10f, ((Rect)(ref r)).y + 12f, 5f, ((Rect)(ref r)).height - 24f), pickupGroup.Color);
			Color textColor = titleStyle.normal.textColor;
			titleStyle.normal.textColor = pickupGroup.Color;
			ShadowLabel(new Rect(((Rect)(ref r)).x + 26f, ((Rect)(ref r)).y + 4f, ((Rect)(ref r)).width - 440f, 34f), pickupGroup.DisplayName, titleStyle);
			titleStyle.normal.textColor = textColor;
			ShadowLabel(new Rect(((Rect)(ref r)).x + 26f, ((Rect)(ref r)).y + 36f, ((Rect)(ref r)).width - 440f, 18f), $"{pickupGroup.Available.Count} items available this run  ·  {groupQueue.TotalCount} queued", smallStyle);
			float num = ((Rect)(ref r)).xMax - 14f;
			Rect r2 = default(Rect);
			((Rect)(ref r2))..ctor(num - 96f, ((Rect)(ref r)).y + 12f, 96f, 36f);
			Rect r3 = default(Rect);
			((Rect)(ref r3))..ctor(((Rect)(ref r2)).x - 10f - 130f, ((Rect)(ref r)).y + 12f, 130f, 36f);
			Rect r4 = default(Rect);
			((Rect)(ref r4))..ctor(((Rect)(ref r3)).x - 4f - 130f, ((Rect)(ref r)).y + 12f, 130f, 36f);
			if (Button(r4, "Run once", (!groupQueue.Repeat) ? ButtonKind.Active : ButtonKind.Normal))
			{
				groupQueue.Repeat = false;
				groupQueue.ResetCursor();
				SetStatus(pickupGroup.DisplayName + ": the queue is used up entry by entry.");
			}
			if (Button(r3, "Repeat", groupQueue.Repeat ? ButtonKind.Active : ButtonKind.Normal))
			{
				groupQueue.Repeat = true;
				groupQueue.ResetCursor();
				SetStatus(pickupGroup.DisplayName + ": the queue starts over when it reaches the end.");
			}
			if (Button(r2, "Clear", ButtonKind.Normal))
			{
				groupQueue.Clear();
				SetStatus(pickupGroup.DisplayName + " queue cleared.");
			}
			Rect area2 = default(Rect);
			((Rect)(ref area2))..ctor(((Rect)(ref area)).x, ((Rect)(ref r)).yMax + 12f, ((Rect)(ref area)).width, 150f);
			DrawQueueStrip(area2, pickupGroup, groupQueue);
			Rect area3 = default(Rect);
			((Rect)(ref area3))..ctor(((Rect)(ref area)).x, ((Rect)(ref area2)).yMax + 12f, ((Rect)(ref area)).width, ((Rect)(ref area)).yMax - 28f - 6f - (((Rect)(ref area2)).yMax + 12f));
			DrawItemGrid(area3, pickupGroup, groupQueue);
			Rect r5 = default(Rect);
			((Rect)(ref r5))..ctor(((Rect)(ref area)).x + 6f, ((Rect)(ref area)).yMax - 28f, ((Rect)(ref area)).width - 12f, 28f);
			if (!string.IsNullOrEmpty(status) && Time.unscaledTime < statusUntil)
			{
				Color textColor2 = textStyle.normal.textColor;
				textStyle.normal.textColor = (statusIsError ? Red : Gold);
				ShadowLabel(r5, status, textStyle);
				textStyle.normal.textColor = textColor2;
			}
			else
			{
				KeyboardShortcut value = CommandItemQueuePlugin.Cfg.ManualPickKey.Value;
				string text = (((int)((KeyboardShortcut)(ref value)).MainKey != 0) ? $"  ·  Hold {value} while opening a cube to choose yourself" : "");
				ShadowLabel(r5, "Items a cube can't offer are skipped automatically." + text, smallStyle);
			}
		}

		private void DrawQueueStrip(Rect area, PickupGroup group, GroupQueue queue)
		{
			//IL_0000: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_051c: Invalid comparison between Unknown and I4
			//IL_0550: Un