Decompiled source of Nicks Command Queue Flavour v2.1.1

CommandQueue.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using CommandQueue.Features;
using CommandQueue.UI;
using HG;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using RiskOfOptions;
using RiskOfOptions.Components.Options;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Artifacts;
using RoR2.UI;
using RoR2.UI.SkinControllers;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Ak.Wwise.Api.WAAPI")]
[assembly: IgnoresAccessChecksTo("AK.Wwise.Unity.API")]
[assembly: IgnoresAccessChecksTo("AK.Wwise.Unity.API.WwiseTypes")]
[assembly: IgnoresAccessChecksTo("AK.Wwise.Unity.MonoBehaviour")]
[assembly: IgnoresAccessChecksTo("AK.Wwise.Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("AsyncManagement")]
[assembly: IgnoresAccessChecksTo("com.unity.multiplayer-hlapi.Runtime")]
[assembly: IgnoresAccessChecksTo("Decalicious")]
[assembly: IgnoresAccessChecksTo("Grumpy")]
[assembly: IgnoresAccessChecksTo("HGCSharpUtils")]
[assembly: IgnoresAccessChecksTo("HGUnityUtils")]
[assembly: IgnoresAccessChecksTo("KinematicCharacterController")]
[assembly: IgnoresAccessChecksTo("LegacyResourcesAPI")]
[assembly: IgnoresAccessChecksTo("Newtonsoft.Json")]
[assembly: IgnoresAccessChecksTo("Rewired_Core")]
[assembly: IgnoresAccessChecksTo("Rewired_CSharp")]
[assembly: IgnoresAccessChecksTo("RiskOfOptions")]
[assembly: IgnoresAccessChecksTo("RoR2")]
[assembly: IgnoresAccessChecksTo("SimpleJSON")]
[assembly: IgnoresAccessChecksTo("Unity.Addressables")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.ResourceManager")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CommandQueue")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+59c69fbbcad4e7a2eee17df9c66e8f0766c20df7")]
[assembly: AssemblyProduct("CommandQueue")]
[assembly: AssemblyTitle("CommandQueue")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CommandQueue
{
	[BepInPlugin("com.kuberoot.commandqueue", "CommandQueue", "2.1.1")]
	public class CommandQueue : BaseUnityPlugin
	{
		public static bool IsLoaded;

		private static GameObject commandUIPrefab;

		public RiskOfOptionsIntegration ROOIntegration;

		private static bool rooOptionsRegistered;

		internal static GameObject CommandUIPrefab
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)commandUIPrefab))
				{
					GameObject commandCubePrefab = CommandArtifactManager.commandCubePrefab;
					commandUIPrefab = ((!Object.op_Implicit((Object)(object)commandCubePrefab)) ? null : commandCubePrefab.GetComponent<PickupPickerController>()?.panelPrefab);
				}
				return commandUIPrefab;
			}
		}

		public static event Action PluginUnloaded;

		public void Awake()
		{
			ModConfig.OnReady += delegate
			{
				ModConfig.enabledTabs.SettingChanged += delegate
				{
					PartialReload();
				};
				ModConfig.bigItemButtonContainer.SettingChanged += delegate
				{
					PartialReload();
				};
				ModConfig.bigItemButtonScale.SettingChanged += delegate
				{
					PartialReload();
				};
				ModConfig.showQueuePreview.SettingChanged += delegate
				{
					UpdateQueuePreview();
				};
				UpdateQueuePreview();
			};
			TierInfo.Init();
			ModConfig.InitConfig(((BaseUnityPlugin)this).Config);
		}

		private static void UpdateQueuePreview()
		{
			if (IsLoaded && ModConfig.Ready && ModConfig.showQueuePreview.Value)
			{
				QueuePreviewHud.Enable();
			}
			else
			{
				QueuePreviewHud.Disable();
			}
		}

		private void PartialReload()
		{
			QueueManager.UpdateQueueAvailability();
			UIManager[] array = Object.FindObjectsOfType<UIManager>(true);
			for (int i = 0; i < array.Length; i++)
			{
				array[i].RebuildUI();
			}
		}

		public void OnEnable()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			IsLoaded = true;
			PickupPickerController.OnDisplayBegin += new hook_OnDisplayBegin(HandleCommandDisplayBegin);
			PickupMessage.Deserialize += new hook_Deserialize(HandlePickupMessage);
			ScoreboardController.Awake += new hook_Awake(ScoreboardController_Awake);
			QueueManager.Enable();
			UpdateQueuePreview();
			ScoreboardController[] array = Object.FindObjectsOfType<ScoreboardController>(true);
			foreach (ScoreboardController val in array)
			{
				if (!Object.op_Implicit((Object)(object)((Component)val).GetComponent<UIManager>()))
				{
					((Component)val).gameObject.AddComponent<UIManager>();
				}
			}
			TryEnableROOIntegration();
		}

		public void OnDisable()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			IsLoaded = false;
			CommandQueue.PluginUnloaded?.Invoke();
			PickupPickerController.OnDisplayBegin -= new hook_OnDisplayBegin(HandleCommandDisplayBegin);
			PickupMessage.Deserialize -= new hook_Deserialize(HandlePickupMessage);
			ScoreboardController.Awake -= new hook_Awake(ScoreboardController_Awake);
			QueueManager.Disable();
			QueuePreviewHud.Disable();
			TryDisableROOIntegration();
		}

		public void Start()
		{
			TryEnableROOIntegration();
		}

		private void TryEnableROOIntegration()
		{
			if (ROOIntegration == null && !rooOptionsRegistered && Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				ROOIntegration = new RiskOfOptionsIntegration();
				ROOIntegration.Enable();
				rooOptionsRegistered = true;
			}
		}

		private void TryDisableROOIntegration()
		{
			ROOIntegration?.Disable();
			ROOIntegration = null;
		}

		private void HandleCommandDisplayBegin(orig_OnDisplayBegin orig, PickupPickerController self, NetworkUIPromptController networkUIPromptController, LocalUser localUser, CameraRigController cameraRigController)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = CommandUIPrefab;
			if (Object.op_Implicit((Object)(object)val) && (Object)(object)self.panelPrefab == (Object)(object)val)
			{
				foreach (var (tier, val2) in QueueManager.PeekAllUnreserved())
				{
					if (self.IsChoiceAvailable(val2))
					{
						((MonoBehaviour)self).StartCoroutine(SubmitQueuedChoiceNextFrame(self, tier, val2, networkUIPromptController, localUser, cameraRigController));
						return;
					}
				}
			}
			orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
		}

		private static IEnumerator SubmitQueuedChoiceNextFrame(PickupPickerController self, ItemTier tier, PickupIndex pickupIndex, NetworkUIPromptController networkUIPromptController, LocalUser localUser, CameraRigController cameraRigController)
		{
			//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_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)
			yield return null;
			if (!Object.op_Implicit((Object)(object)self))
			{
				yield break;
			}
			int num = FindAvailableOption(self, pickupIndex);
			if (num < 0)
			{
				self.OnDisplayBegin(networkUIPromptController, localUser, cameraRigController);
				yield break;
			}
			if (IsPermanent(self.options[num].pickup) && QueueManager.PeekUnreserved(tier) == pickupIndex)
			{
				QueueManager.Reserve(tier, pickupIndex);
			}
			SubmitChoiceDirect(self, num);
		}

		private static int FindAvailableOption(PickupPickerController self, PickupIndex pickupIndex)
		{
			//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)
			Option[] options = self.options;
			for (int i = 0; i < options.Length; i++)
			{
				if (options[i].pickup.pickupIndex == pickupIndex && options[i].available)
				{
					return i;
				}
			}
			return -1;
		}

		private static void SubmitChoiceDirect(PickupPickerController self, int choiceIndex)
		{
			if (NetworkServer.active)
			{
				self.HandlePickupSelected(choiceIndex);
				return;
			}
			NetworkUIPromptController networkUIPromptController = self.networkUIPromptController;
			NetworkWriter val = networkUIPromptController.BeginMessageToServer();
			val.Write((byte)0);
			val.Write(choiceIndex);
			networkUIPromptController.FinishMessageToServer(val);
		}

		private static bool IsPermanent(UniquePickup pickup)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (!((UniquePickup)(ref pickup)).isTempItem)
			{
				return !pickup.isRental;
			}
			return false;
		}

		private void HandlePickupMessage(orig_Deserialize orig, PickupMessage self, NetworkReader reader)
		{
			//IL_0037: 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)
			orig.Invoke(self, reader);
			LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
			CharacterMaster val = ((firstLocalUser != null) ? firstLocalUser.cachedMaster : null);
			if (Object.op_Implicit((Object)(object)val) && !((Object)(object)self.masterGameObject != (Object)(object)((Component)val).gameObject) && IsPermanent(self.pickupState))
			{
				QueueManager.OnItemPickedUp(self.pickupState.pickupIndex);
			}
		}

		private void ScoreboardController_Awake(orig_Awake orig, ScoreboardController self)
		{
			((Component)self).gameObject.AddComponent<UIManager>();
			orig.Invoke(self);
		}
	}
	public static class ModConfig
	{
		public class ItemTierSet : SortedSet<ItemTier>
		{
			public static Dictionary<ItemTier, string> ItemTierToName = new Dictionary<ItemTier, string>();

			public static Dictionary<string, ItemTier> NameToItemTier = new Dictionary<string, ItemTier>();

			public ItemTierSet()
			{
			}

			public ItemTierSet(IEnumerable<ItemTier> tiers)
				: base(tiers)
			{
			}

			internal static void Initialize()
			{
				//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_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				ItemTierToName.Clear();
				NameToItemTier.Clear();
				Enumerator<ItemTierDef> enumerator = ItemTierCatalog.allItemTierDefs.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						ItemTierDef current = enumerator.Current;
						ItemTierToName[current.tier] = ((Object)current).name;
						NameToItemTier[((Object)current).name] = current.tier;
					}
				}
				finally
				{
					((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
				}
			}

			public unsafe static string Serialize(ItemTierSet self)
			{
				string value;
				return string.Join(", ", self.Select((ItemTier x) => (!ItemTierToName.TryGetValue(x, out value)) ? ((object)(*(ItemTier*)(&x))/*cast due to .constrained prefix*/).ToString() : value));
			}

			public static ItemTierSet Deserialize(string src)
			{
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				ItemTierSet itemTierSet = new ItemTierSet();
				foreach (string item in from s in src.Split(',')
					select s.Trim())
				{
					int result;
					if (NameToItemTier.TryGetValue(item, out var value))
					{
						itemTierSet.Add(value);
					}
					else if (Enum.TryParse<ItemTier>(item, out value))
					{
						itemTierSet.Add(value);
					}
					else if (int.TryParse(item, out result))
					{
						itemTierSet.Add((ItemTier)result);
					}
				}
				return itemTierSet;
			}

			public override string ToString()
			{
				return Serialize(this);
			}
		}

		public static bool Ready = false;

		private static ConfigFile config;

		public static ConfigEntry<ItemTierSet> enabledTabs;

		public static ConfigEntry<bool> bigItemButtonContainer;

		public static ConfigEntry<float> bigItemButtonScale;

		public static ConfigEntry<bool> rightClickRemovesStack;

		public static ConfigEntry<bool> pauseWhileOpen;

		public static ConfigEntry<bool> matchItemBarWidth;

		public static ConfigEntry<bool> showQueuePreview;

		public static ConfigEntry<float> queuePreviewX;

		public static ConfigEntry<float> queuePreviewY;

		private static ConfigEntry<int> configVersion;

		private const int CurrentConfigVersion = 3;

		private static readonly ItemTier[] DefaultTiers;

		public static event Action OnReady;

		internal static void InitConfig(ConfigFile _config)
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			config = _config;
			TomlTypeConverter.AddConverter(typeof(ItemTierSet), new TypeConverter
			{
				ConvertToObject = (string str, Type type) => ItemTierSet.Deserialize(str),
				ConvertToString = (object obj, Type type) => obj.ToString()
			});
			((ResourceAvailability)(ref ItemTierCatalog.availability)).CallWhenAvailable((Action)InitConfigInternal);
		}

		internal static void InitConfigInternal()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_007d: Expected O, but got Unknown
			//IL_0091: 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_00ac: Expected O, but got Unknown
			//IL_00ac: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_00df: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_010e: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			//IL_013d: Expected O, but got Unknown
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			//IL_016c: Expected O, but got Unknown
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_019b: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Expected O, but got Unknown
			//IL_01dc: Expected O, but got Unknown
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Expected O, but got Unknown
			//IL_021d: Expected O, but got Unknown
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Expected O, but got Unknown
			//IL_024c: Expected O, but got Unknown
			if (!Ready)
			{
				ItemTierSet.Initialize();
				enabledTabs = config.Bind<ItemTierSet>(new ConfigDefinition("General", "EnabledQueues"), new ItemTierSet(DefaultTiers), new ConfigDescription("Which item tiers should have queues?\nValid values: " + string.Join(", ", ((IEnumerable<ItemTierDef>)(object)ItemTierCatalog.allItemTierDefs).Select((ItemTierDef def) => GetTierName(def.tier) + " (" + TierInfo.GetDisplayName(def.tier) + ")")), (AcceptableValueBase)null, Array.Empty<object>()));
				bigItemButtonContainer = config.Bind<bool>(new ConfigDefinition("General", "BigItemSelectionContainer"), true, new ConfigDescription("false: Default command button layout\ntrue: Increase the space for buttons, helps avoid overflow with modded items", (AcceptableValueBase)null, Array.Empty<object>()));
				bigItemButtonScale = config.Bind<float>(new ConfigDefinition("General", "BigItemSelectionScale"), 1f, new ConfigDescription("Scale applied to item buttons in the menu - decrease it if your buttons don't fit\nApplies only if BigItemSelectionContainer is true", (AcceptableValueBase)null, Array.Empty<object>()));
				rightClickRemovesStack = config.Bind<bool>(new ConfigDefinition("General", "RightClickRemovesStack"), true, new ConfigDescription("Should right-clicking an item in the queue remove the whole stack?", (AcceptableValueBase)null, Array.Empty<object>()));
				pauseWhileOpen = config.Bind<bool>(new ConfigDefinition("General", "PauseWhileQueueOpen"), true, new ConfigDescription("Pause the game while the Command Queue or Saves page is open. Single player only, like the game's inspect auto-pause.\nTip: the game's \"Toggle Inventory\" control setting keeps the scoreboard open without holding the key.", (AcceptableValueBase)null, Array.Empty<object>()));
				matchItemBarWidth = config.Bind<bool>(new ConfigDefinition("General", "MatchItemBarWidth"), true, new ConfigDescription("Narrow the scoreboard (and the Command Queue and Saves pages) to the width and position of the item bar at the top of the screen, so it doesn't overlap the HUD on the sides.", (AcceptableValueBase)null, Array.Empty<object>()));
				showQueuePreview = config.Bind<bool>(new ConfigDefinition("QueuePreview", "Enabled"), true, new ConfigDescription("Show the Command Queue Preview: the next queued item of each tier on the HUD during Command runs, under the objectives panel. Set to false to turn it off.", (AcceptableValueBase)null, Array.Empty<object>()));
				queuePreviewX = config.Bind<float>(new ConfigDefinition("QueuePreview", "PositionX"), 0.985f, new ConfigDescription("Only used when the preview can't attach under the objectives panel (other game modes, HUD mods). Horizontal position, 0 = left edge, 1 = right edge.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
				queuePreviewY = config.Bind<float>(new ConfigDefinition("QueuePreview", "PositionY"), 0.6f, new ConfigDescription("Only used when the preview can't attach under the objectives panel (other game modes, HUD mods). Vertical position, 0 = bottom, 1 = top.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
				configVersion = config.Bind<int>(new ConfigDefinition("Internal", "ConfigVersion"), 0, new ConfigDescription("Used to migrate settings between mod versions, don't edit.", (AcceptableValueBase)null, Array.Empty<object>()));
				MigrateConfig();
				Ready = true;
				ModConfig.OnReady?.Invoke();
			}
		}

		private static void MigrateConfig()
		{
			if (configVersion.Value >= 3)
			{
				return;
			}
			if (configVersion.Value < 2)
			{
				enabledTabs.Value = new ItemTierSet(enabledTabs.Value)
				{
					(ItemTier)11,
					(ItemTier)13
				};
			}
			if (configVersion.Value < 3)
			{
				ItemTierSet other = new ItemTierSet
				{
					(ItemTier)0,
					(ItemTier)1,
					(ItemTier)2,
					(ItemTier)11,
					(ItemTier)13
				};
				ItemTierSet value = enabledTabs.Value;
				if (value.IsSubsetOf(other) && value.Contains((ItemTier)0) && value.Contains((ItemTier)1) && value.Contains((ItemTier)2))
				{
					enabledTabs.Value = new ItemTierSet(DefaultTiers);
				}
			}
			configVersion.Value = 3;
		}

		public unsafe static string GetTierName(ItemTier tier)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (ItemTierSet.ItemTierToName.TryGetValue(tier, out var value))
			{
				return value;
			}
			return ((object)(*(ItemTier*)(&tier))/*cast due to .constrained prefix*/).ToString();
		}

		static ModConfig()
		{
			ItemTier[] array = new ItemTier[11];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			DefaultTiers = (ItemTier[])(object)array;
		}
	}
	public static class QueueManager
	{
		public struct QueueEntry
		{
			public PickupIndex pickupIndex;

			public int count;
		}

		public enum QueueChange
		{
			Removed,
			Added,
			Changed,
			Moved,
			Reset
		}

		public static Dictionary<ItemTier, List<QueueEntry>> mainQueues = new Dictionary<ItemTier, List<QueueEntry>>
		{
			{
				(ItemTier)0,
				new List<QueueEntry>()
			},
			{
				(ItemTier)1,
				new List<QueueEntry>()
			},
			{
				(ItemTier)2,
				new List<QueueEntry>()
			}
		};

		public static Dictionary<ItemTier, bool> queueRepeat = new Dictionary<ItemTier, bool>();

		private static readonly List<(ItemTier tier, PickupIndex pickupIndex)> reservations = new List<(ItemTier, PickupIndex)>();

		public static event Action<Run> OnRunQueueInit;

		public static event Action<QueueChange, ItemTier, int> OnQueueChanged;

		internal static void Enable()
		{
			Run.onRunStartGlobal += InitQueues;
			Stage.onStageStartGlobal += ClearReservations;
			ModConfig.OnReady += UpdateQueueAvailability;
			UpdateQueueAvailability();
		}

		internal static void Disable()
		{
			Run.onRunStartGlobal -= InitQueues;
			Stage.onStageStartGlobal -= ClearReservations;
			ModConfig.OnReady -= UpdateQueueAvailability;
			reservations.Clear();
		}

		public static void UpdateQueueAvailability()
		{
			//IL_002a: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.Ready)
			{
				return;
			}
			ModConfig.ItemTierSet value = ModConfig.enabledTabs.Value;
			ItemTier[] array = mainQueues.Keys.ToArray();
			foreach (ItemTier val in array)
			{
				if (!value.Contains(val))
				{
					mainQueues.Remove(val);
				}
			}
			foreach (ItemTier item in value)
			{
				if (!mainQueues.ContainsKey(item))
				{
					mainQueues.Add(item, new List<QueueEntry>());
				}
			}
		}

		private static void InitQueues(Run run)
		{
			ClearAllQueues();
			QueueManager.OnRunQueueInit?.Invoke(run);
		}

		public static bool DoesRepeat(ItemTier tier)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			bool value;
			return queueRepeat.TryGetValue(tier, out value) && value;
		}

		public static void ToggleRepeat(ItemTier tier)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			queueRepeat[tier] = !DoesRepeat(tier);
		}

		public static bool TryGetTier(PickupIndex pickupIndex, out ItemTier tier)
		{
			//IL_0003: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected I4, but got Unknown
			tier = (ItemTier)5;
			PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
			if (pickupDef == null)
			{
				return false;
			}
			ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);
			if (!Object.op_Implicit((Object)(object)itemDef))
			{
				return false;
			}
			tier = (ItemTier)(int)itemDef.tier;
			return true;
		}

		public static void Enqueue(PickupIndex pickupIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			TryEnqueue(pickupIndex, 1);
		}

		public static bool TryEnqueue(PickupIndex pickupIndex, int count)
		{
			//IL_0004: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_00aa: 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)
			if (count <= 0 || !TryGetTier(pickupIndex, out var tier) || !mainQueues.TryGetValue(tier, out var value))
			{
				return false;
			}
			if (value.Count > 0)
			{
				QueueEntry value2 = value[value.Count - 1];
				if (value2.pickupIndex == pickupIndex)
				{
					value2.count += count;
					value[value.Count - 1] = value2;
					QueueManager.OnQueueChanged?.Invoke(QueueChange.Changed, tier, value.Count - 1);
					return true;
				}
			}
			QueueEntry item = new QueueEntry
			{
				pickupIndex = pickupIndex,
				count = count
			};
			value.Add(item);
			QueueManager.OnQueueChanged?.Invoke(QueueChange.Added, tier, value.Count - 1);
			return true;
		}

		public static PickupIndex Peek(ItemTier tier)
		{
			//IL_0005: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			if (!mainQueues.TryGetValue(tier, out var value) || value.Count == 0)
			{
				return PickupIndex.none;
			}
			return value[0].pickupIndex;
		}

		public static PickupIndex Pop(ItemTier tier)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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_0009: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			PickupIndex val = Remove(tier, 0);
			if (DoesRepeat(tier))
			{
				Enqueue(val);
			}
			return val;
		}

		public static PickupIndex Remove(ItemTier tier, int index, int count = 1)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0043: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			List<QueueEntry> list = mainQueues[tier];
			QueueEntry value = list[index];
			value.count -= count;
			if (value.count <= 0)
			{
				list.RemoveAt(index);
				QueueManager.OnQueueChanged?.Invoke(QueueChange.Removed, tier, index);
				if (TryMerge(tier, index - 1, index))
				{
					QueueManager.OnQueueChanged?.Invoke(QueueChange.Removed, tier, index);
					QueueManager.OnQueueChanged?.Invoke(QueueChange.Changed, tier, index - 1);
				}
			}
			else
			{
				list[index] = value;
				QueueManager.OnQueueChanged?.Invoke(QueueChange.Changed, tier, index);
			}
			return value.pickupIndex;
		}

		public static PickupIndex PeekUnreserved(ItemTier tier)
		{
			//IL_0005: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0082: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			if (!mainQueues.TryGetValue(tier, out var value) || value.Count == 0)
			{
				return PickupIndex.none;
			}
			Dictionary<PickupIndex, int> dictionary = new Dictionary<PickupIndex, int>();
			int num = 0;
			foreach (var (val, key) in reservations)
			{
				if (val == tier)
				{
					dictionary.TryGetValue(key, out var value2);
					dictionary[key] = value2 + 1;
					num++;
				}
			}
			int num2 = ((!DoesRepeat(tier)) ? 1 : (num + 1));
			for (int i = 0; i < num2; i++)
			{
				foreach (QueueEntry item in value)
				{
					dictionary.TryGetValue(item.pickupIndex, out var value3);
					int num3 = Math.Min(value3, item.count);
					if (num3 < item.count)
					{
						return item.pickupIndex;
					}
					dictionary[item.pickupIndex] = value3 - num3;
				}
			}
			return PickupIndex.none;
		}

		public static IEnumerable<(ItemTier, PickupIndex)> PeekAllUnreserved()
		{
			foreach (ItemTier key in mainQueues.Keys)
			{
				PickupIndex val = PeekUnreserved(key);
				if (val != PickupIndex.none)
				{
					yield return (key, val);
				}
			}
		}

		public static void Reserve(ItemTier tier, PickupIndex pickupIndex)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			reservations.Add((tier, pickupIndex));
		}

		public static void OnItemPickedUp(PickupIndex pickupIndex)
		{
			//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_0034: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			int num = reservations.FindIndex(((ItemTier tier, PickupIndex pickupIndex) r) => r.pickupIndex == pickupIndex);
			if (num < 0)
			{
				return;
			}
			ItemTier item = reservations[num].tier;
			reservations.RemoveAt(num);
			if (!mainQueues.TryGetValue(item, out var value))
			{
				return;
			}
			int num2 = value.FindIndex((QueueEntry entry) => entry.pickupIndex == pickupIndex);
			if (num2 >= 0)
			{
				Remove(item, num2);
				if (DoesRepeat(item))
				{
					Enqueue(pickupIndex);
				}
			}
		}

		private static void ClearReservations(Stage stage)
		{
			reservations.Clear();
		}

		private static bool TryMerge(ItemTier tier, int into, int from)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			List<QueueEntry> list = mainQueues[tier];
			if (into < 0 || into >= list.Count || from < 0 || from >= list.Count)
			{
				return false;
			}
			QueueEntry value = list[into];
			QueueEntry queueEntry = list[from];
			if (value.pickupIndex != queueEntry.pickupIndex)
			{
				return false;
			}
			value.count += queueEntry.count;
			list[into] = value;
			list.RemoveAt(from);
			return true;
		}

		public static void ClearAllQueues()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			UpdateQueueAvailability();
			reservations.Clear();
			foreach (KeyValuePair<ItemTier, List<QueueEntry>> mainQueue in mainQueues)
			{
				mainQueue.Value.Clear();
				QueueManager.OnQueueChanged?.Invoke(QueueChange.Reset, mainQueue.Key, -1);
			}
		}

		public static void Move(ItemTier tier, int oldIndex, int newIndex, int count = 1)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			List<QueueEntry> list = mainQueues[tier];
			newIndex = Math.Max(0, Math.Min(list.Count, newIndex));
			if (newIndex == oldIndex)
			{
				return;
			}
			QueueEntry item = list[oldIndex];
			if (item.count < count)
			{
				return;
			}
			if (item.count == count)
			{
				list.RemoveAt(oldIndex);
				if (newIndex > oldIndex)
				{
					newIndex--;
				}
			}
			else
			{
				QueueEntry value = list[oldIndex];
				value.count -= count;
				list[oldIndex] = value;
			}
			item.count = count;
			if (TryMerge(tier, oldIndex - 1, oldIndex) && newIndex > oldIndex)
			{
				newIndex--;
			}
			list.Insert(newIndex, item);
			TryMerge(tier, newIndex - 1, newIndex);
			TryMerge(tier, newIndex, newIndex + 1);
			QueueManager.OnQueueChanged?.Invoke(QueueChange.Moved, tier, -1);
		}
	}
	public class RiskOfOptionsIntegration
	{
		public class ItemTierCheckboxOption : CheckBoxOption
		{
			public ConfigEntry<ModConfig.ItemTierSet> SourceConfigEntry;

			public ItemTier BoundItemTier;

			public string CategoryName;

			public string BoundItemTierName;

			public override ConfigEntryBase ConfigEntry => null;

			public override bool Value
			{
				get
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					return SourceConfigEntry.Value.Contains(BoundItemTier);
				}
				set
				{
					//IL_0025: 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)
					ModConfig.ItemTierSet itemTierSet = new ModConfig.ItemTierSet(SourceConfigEntry.Value);
					if (value)
					{
						itemTierSet.Add(BoundItemTier);
					}
					else
					{
						itemTierSet.Remove(BoundItemTier);
					}
					SourceConfigEntry.Value = itemTierSet;
				}
			}

			public ItemTierCheckboxOption(ConfigEntry<ModConfig.ItemTierSet> sourceConfigEntry, ItemTier itemTier, string categoryName)
				: base(new CheckBoxConfig(), sourceConfigEntry.Value.Contains(itemTier))
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Expected O, but got Unknown
				//IL_001f: 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_002d: Unknown result type (might be due to invalid IL or missing references)
				SourceConfigEntry = sourceConfigEntry;
				BoundItemTier = itemTier;
				CategoryName = categoryName;
				BoundItemTierName = TierInfo.GetDisplayName(itemTier);
			}

			public override GameObject CreateOptionGameObject(GameObject prefab, Transform parent)
			{
				GameObject obj = Object.Instantiate<GameObject>(prefab, parent);
				ModSettingsBool componentInChildren = obj.GetComponentInChildren<ModSettingsBool>();
				((ModSetting)componentInChildren).nameToken = ((BaseOption)this).GetNameToken();
				((ModSetting)componentInChildren).settingToken = ((BaseOption)this).Identifier;
				((Object)obj).name = "Mod Option ItemTierCheckBox, " + ((BaseOption)this).Name + " " + BoundItemTierName;
				return obj;
			}

			public override void SetProperties()
			{
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				((BaseOption)this).SetCategoryName(CategoryName, (BaseOptionConfig)(object)base.config);
				((BaseOption)this).SetName(BoundItemTierName, (BaseOptionConfig)(object)base.config);
				((BaseOption)this).SetDescription("Show a queue tab for " + BoundItemTierName + " items (" + ModConfig.GetTierName(BoundItemTier) + ")", (BaseOptionConfig)(object)base.config);
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static IsDisabledDelegate <>9__3_0;

			internal bool <InitInternal>b__3_0()
			{
				return !ModConfig.showQueuePreview.Value;
			}
		}

		private static Texture2D modIcon;

		private static Sprite modIconSprite;

		public void Enable()
		{
			if (ModConfig.Ready)
			{
				InitInternal();
			}
			else
			{
				ModConfig.OnReady += InitInternal;
			}
		}

		internal void InitInternal()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0077: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00f7: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Expected O, but got Unknown
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Expected O, but got Unknown
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Invalid comparison between Unknown and I4
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Invalid comparison between Unknown and I4
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			modIcon = new Texture2D(0, 0);
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CommandQueue.icon.png"))
			{
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				byte[] array = memoryStream.ToArray();
				ImageConversion.LoadImage(modIcon, array);
			}
			modIconSprite = Sprite.Create(modIcon, new Rect(0f, 0f, (float)((Texture)modIcon).width, (float)((Texture)modIcon).height), new Vector2(0.5f, 0.5f));
			ModSettingsManager.SetModIcon(modIconSprite);
			ModSettingsManager.SetModDescription("Queue up items to automatically pick from command drops");
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ModConfig.rightClickRemovesStack));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ModConfig.bigItemButtonContainer));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(ModConfig.bigItemButtonScale, new SliderConfig
			{
				min = 0.1f,
				max = 10f,
				FormatString = "{0:F2}"
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ModConfig.matchItemBarWidth));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ModConfig.pauseWhileOpen));
			object obj = <>c.<>9__3_0;
			if (obj == null)
			{
				IsDisabledDelegate val = () => !ModConfig.showQueuePreview.Value;
				<>c.<>9__3_0 = val;
				obj = (object)val;
			}
			IsDisabledDelegate checkIfDisabled = (IsDisabledDelegate)obj;
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ModConfig.showQueuePreview, new CheckBoxConfig
			{
				category = "Command Queue Preview",
				name = "Show Command Queue Preview"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(ModConfig.queuePreviewX, new SliderConfig
			{
				category = "Command Queue Preview",
				name = "Fallback Position X",
				min = 0f,
				max = 1f,
				FormatString = "{0:F3}",
				checkIfDisabled = checkIfDisabled
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(ModConfig.queuePreviewY, new SliderConfig
			{
				category = "Command Queue Preview",
				name = "Fallback Position Y",
				min = 0f,
				max = 1f,
				FormatString = "{0:F3}",
				checkIfDisabled = checkIfDisabled
			}));
			Enumerator<ItemTierDef> enumerator = ItemTierCatalog.allItemTierDefs.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ItemTierDef current = enumerator.Current;
					if ((int)current.tier != 5 && (int)current.tier != 1000)
					{
						ModSettingsManager.AddOption((BaseOption)(object)new ItemTierCheckboxOption(ModConfig.enabledTabs, current.tier, "Enabled Tabs"));
					}
				}
			}
			finally
			{
				((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			ModConfig.OnReady -= InitInternal;
		}

		public void Disable()
		{
			ModConfig.OnReady -= InitInternal;
		}
	}
	public static class SaveManager
	{
		[Serializable]
		public class SavedEntry
		{
			public string pickup;

			public int count;
		}

		[Serializable]
		public class SavedQueue
		{
			public string id;

			public string name;

			public long createdAt;

			public long updatedAt;

			public List<SavedEntry> entries = new List<SavedEntry>();

			public List<string> repeatTiers = new List<string>();

			public int ItemCount => entries.Sum((SavedEntry e) => Math.Max(0, e.count));
		}

		[Serializable]
		private class SaveFileData
		{
			public int version = 1;

			public bool importedLegacySlots;

			public bool importedCommandQueueExtended;

			public List<SavedQueue> saves = new List<SavedQueue>();
		}

		public struct LoadResult
		{
			public int loadedItems;

			public int unknownItems;

			public int disabledTierItems;
		}

		public const int MaxStackCount = 999;

		public const int MaxNameLength = 40;

		private static SaveFileData data;

		private static string SaveFilePath => Path.Combine(Paths.ConfigPath, "CommandQueue.saves.json");

		public static IReadOnlyList<SavedQueue> Saves
		{
			get
			{
				EnsureLoaded();
				return data.saves;
			}
		}

		public static event Action OnSavesChanged;

		private static void EnsureLoaded()
		{
			if (data == null)
			{
				data = ReadSaveFile() ?? new SaveFileData();
				bool flag = false;
				if (!data.importedLegacySlots)
				{
					ImportLegacySlots();
					data.importedLegacySlots = true;
					flag = true;
				}
				if (!data.importedCommandQueueExtended)
				{
					ImportCommandQueueExtended();
					data.importedCommandQueueExtended = true;
					flag = true;
				}
				if (flag)
				{
					WriteSaveFile();
				}
			}
		}

		private static SaveFileData ReadSaveFile()
		{
			string saveFilePath = SaveFilePath;
			if (!File.Exists(saveFilePath))
			{
				return null;
			}
			try
			{
				SaveFileData saveFileData = JsonUtility.FromJson<SaveFileData>(File.ReadAllText(saveFilePath));
				if (saveFileData?.saves == null)
				{
					throw new FormatException("missing saves list");
				}
				saveFileData.saves.RemoveAll((SavedQueue s) => s == null);
				foreach (SavedQueue safe in saveFileData.saves)
				{
					if (string.IsNullOrEmpty(safe.id))
					{
						safe.id = NewId();
					}
					if (safe.entries == null)
					{
						safe.entries = new List<SavedEntry>();
					}
					if (safe.repeatTiers == null)
					{
						safe.repeatTiers = new List<string>();
					}
				}
				return saveFileData;
			}
			catch (Exception ex)
			{
				string text = $"{saveFilePath}.corrupt-{DateTime.Now:yyyyMMdd-HHmmss}";
				Debug.LogError((object)("[CommandQueue] Could not read " + saveFilePath + " (" + ex.Message + "). Moving it to " + text + " and starting with no saves."));
				try
				{
					File.Move(saveFilePath, text);
				}
				catch (Exception ex2)
				{
					Debug.LogError((object)ex2);
				}
				return null;
			}
		}

		private static void WriteSaveFile()
		{
			string saveFilePath = SaveFilePath;
			string text = saveFilePath + ".tmp";
			try
			{
				Directory.CreateDirectory(Path.GetDirectoryName(saveFilePath));
				File.WriteAllText(text, JsonUtility.ToJson((object)data, true));
				if (!File.Exists(saveFilePath))
				{
					File.Move(text, saveFilePath);
				}
				else
				{
					try
					{
						File.Replace(text, saveFilePath, saveFilePath + ".bak");
					}
					catch (PlatformNotSupportedException)
					{
						File.Copy(saveFilePath, saveFilePath + ".bak", overwrite: true);
						File.Delete(saveFilePath);
						File.Move(text, saveFilePath);
					}
				}
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"[CommandQueue] Failed to write saves to {saveFilePath}: {arg}");
			}
			SaveManager.OnSavesChanged?.Invoke();
		}

		private static string NewId()
		{
			return Guid.NewGuid().ToString("N").Substring(0, 8);
		}

		private static long Now()
		{
			return DateTimeOffset.UtcNow.ToUnixTimeSeconds();
		}

		public static string SanitizeName(string name)
		{
			name = (name ?? "").Trim();
			name = new string(name.Where((char c) => !char.IsControl(c)).ToArray());
			if (name.Length > 40)
			{
				name = name.Substring(0, 40);
			}
			return name;
		}

		private unsafe static List<SavedEntry> CaptureCurrentQueues(out List<string> repeatTiers)
		{
			repeatTiers = QueueManager.mainQueues.Keys.Where(QueueManager.DoesRepeat).Select(ModConfig.GetTierName).ToList();
			return (from entry in QueueManager.mainQueues.SelectMany((KeyValuePair<ItemTier, List<QueueManager.QueueEntry>> pair) => pair.Value)
				select new SavedEntry
				{
					pickup = ((object)(*(PickupIndex*)(&entry.pickupIndex))/*cast due to .constrained prefix*/).ToString(),
					count = entry.count
				}).ToList();
		}

		public static SavedQueue CreateSave(string name)
		{
			EnsureLoaded();
			name = SanitizeName(name);
			if (name.Length == 0)
			{
				name = $"Save {data.saves.Count + 1}";
			}
			List<string> repeatTiers;
			SavedQueue savedQueue = new SavedQueue
			{
				id = NewId(),
				name = name,
				createdAt = Now(),
				updatedAt = Now(),
				entries = CaptureCurrentQueues(out repeatTiers),
				repeatTiers = repeatTiers
			};
			data.saves.Insert(0, savedQueue);
			WriteSaveFile();
			return savedQueue;
		}

		public static void OverwriteSave(string id)
		{
			SavedQueue savedQueue = Find(id);
			if (savedQueue != null)
			{
				savedQueue.entries = CaptureCurrentQueues(out var repeatTiers);
				savedQueue.repeatTiers = repeatTiers;
				savedQueue.updatedAt = Now();
				WriteSaveFile();
			}
		}

		public static void RenameSave(string id, string newName)
		{
			SavedQueue savedQueue = Find(id);
			newName = SanitizeName(newName);
			if (savedQueue != null && newName.Length != 0)
			{
				savedQueue.name = newName;
				WriteSaveFile();
			}
		}

		public static void DeleteSave(string id)
		{
			EnsureLoaded();
			if (data.saves.RemoveAll((SavedQueue s) => s.id == id) > 0)
			{
				WriteSaveFile();
			}
		}

		public static SavedQueue Find(string id)
		{
			EnsureLoaded();
			return data.saves.FirstOrDefault((SavedQueue s) => s.id == id);
		}

		public static LoadResult LoadSave(string id)
		{
			//IL_0068: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: 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)
			LoadResult result = default(LoadResult);
			SavedQueue savedQueue = Find(id);
			if (savedQueue == null)
			{
				return result;
			}
			List<(PickupIndex, int)> list = new List<(PickupIndex, int)>();
			foreach (SavedEntry entry in savedQueue.entries)
			{
				int num = Mathf.Clamp(entry.count, 0, 999);
				if (num != 0)
				{
					PickupIndex val = (string.IsNullOrEmpty(entry.pickup) ? PickupIndex.none : PickupCatalog.FindPickupIndex(entry.pickup));
					if (!QueueManager.TryGetTier(val, out var tier))
					{
						result.unknownItems += num;
					}
					else if (!QueueManager.mainQueues.ContainsKey(tier))
					{
						result.disabledTierItems += num;
					}
					else
					{
						list.Add((val, num));
					}
				}
			}
			if (list.Count == 0 && savedQueue.entries.Count > 0)
			{
				return result;
			}
			QueueManager.ClearAllQueues();
			foreach (var (pickupIndex, num2) in list)
			{
				if (QueueManager.TryEnqueue(pickupIndex, num2))
				{
					result.loadedItems += num2;
				}
			}
			QueueManager.queueRepeat.Clear();
			foreach (string repeatTier in savedQueue.repeatTiers)
			{
				foreach (ItemTier item in ModConfig.ItemTierSet.Deserialize(repeatTier))
				{
					QueueManager.queueRepeat[item] = true;
				}
			}
			if (result.unknownItems > 0 || result.disabledTierItems > 0)
			{
				Debug.LogWarning((object)$"[CommandQueue] Loaded save '{savedQueue.name}' partially: {result.unknownItems} unknown item(s), {result.disabledTierItems} item(s) in disabled tiers were skipped.");
			}
			return result;
		}

		private static List<SavedEntry> ParseLegacyQueue(string queueData)
		{
			List<SavedEntry> list = new List<SavedEntry>();
			if (string.IsNullOrEmpty(queueData))
			{
				return list;
			}
			string[] array = queueData.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				int num = text.LastIndexOf('*');
				if (num > 0 && int.TryParse(text.Substring(num + 1), NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && result > 0)
				{
					list.Add(new SavedEntry
					{
						pickup = text.Substring(0, num),
						count = Math.Min(result, 999)
					});
				}
			}
			return list;
		}

		private static void ImportLegacySlots()
		{
			foreach (string item in new string[2]
			{
				Directory.GetCurrentDirectory(),
				Paths.GameRootPath
			}.Distinct())
			{
				for (int i = 1; i <= 10; i++)
				{
					string text = Path.Combine(item, $"commandQueueSlot_{i}.save");
					try
					{
						if (File.Exists(text))
						{
							List<SavedEntry> list = ParseLegacyQueue(File.ReadAllText(text).Trim());
							if (list.Count != 0)
							{
								data.saves.Add(new SavedQueue
								{
									id = NewId(),
									name = $"Slot {i}",
									createdAt = Now(),
									updatedAt = Now(),
									entries = list
								});
							}
						}
					}
					catch (Exception ex)
					{
						Debug.LogWarning((object)("[CommandQueue] Could not import " + text + ": " + ex.Message));
					}
				}
			}
		}

		private static void ImportCommandQueueExtended()
		{
			string text = Path.Combine(Paths.ConfigPath, "commandQueueSaves.json");
			try
			{
				if (!File.Exists(text))
				{
					return;
				}
				string[] array = File.ReadAllLines(text);
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Split('|');
					if (array2.Length >= 4)
					{
						List<SavedEntry> list = ParseLegacyQueue(array2[^2]);
						if (list.Count != 0)
						{
							long.TryParse(array2[^1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result);
							string text2 = SanitizeName(string.Join("|", array2, 1, array2.Length - 3));
							data.saves.Add(new SavedQueue
							{
								id = NewId(),
								name = ((text2.Length > 0) ? text2 : "Imported"),
								createdAt = result,
								updatedAt = result,
								entries = list
							});
						}
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[CommandQueue] Could not import CommandQueueExtended saves from " + text + ": " + ex.Message));
			}
		}
	}
	public static class TierInfo
	{
		private static readonly Dictionary<ItemTier, string> displayNameOverrides = new Dictionary<ItemTier, string>
		{
			{
				(ItemTier)0,
				"White"
			},
			{
				(ItemTier)1,
				"Green"
			},
			{
				(ItemTier)2,
				"Red"
			},
			{
				(ItemTier)4,
				"Boss"
			},
			{
				(ItemTier)3,
				"Lunar"
			},
			{
				(ItemTier)6,
				"Void White"
			},
			{
				(ItemTier)7,
				"Void Green"
			},
			{
				(ItemTier)8,
				"Void Red"
			},
			{
				(ItemTier)9,
				"Void Boss"
			},
			{
				(ItemTier)10,
				"Food"
			},
			{
				(ItemTier)11,
				"Hallowed"
			},
			{
				(ItemTier)12,
				"Page"
			},
			{
				(ItemTier)13,
				"Hex"
			}
		};

		private static readonly Dictionary<ItemTier, PickupIndex[]> pickupCache = new Dictionary<ItemTier, PickupIndex[]>();

		public static string GetDisplayName(ItemTier tier)
		{
			//IL_0005: 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)
			if (displayNameOverrides.TryGetValue(tier, out var value))
			{
				return value;
			}
			value = ModConfig.GetTierName(tier);
			if (value.EndsWith("TierDef") && value.Length > "TierDef".Length)
			{
				return value.Substring(0, value.Length - "TierDef".Length);
			}
			if (value.EndsWith("Def") && value.Length > "Def".Length)
			{
				return value.Substring(0, value.Length - "Def".Length);
			}
			return value;
		}

		public static ItemTier? GetMirroredTier(ItemTier tier)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected I4, but got Unknown
			return (tier - 6) switch
			{
				0 => (ItemTier)0, 
				1 => (ItemTier)1, 
				2 => (ItemTier)2, 
				3 => (ItemTier)4, 
				_ => null, 
			};
		}

		public static Color GetColor(ItemTier tier)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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)
			ItemTierDef itemTierDef = ItemTierCatalog.GetItemTierDef(tier);
			if (!Object.op_Implicit((Object)(object)itemTierDef))
			{
				return Color.white;
			}
			return Color32.op_Implicit(ColorCatalog.GetColor(itemTierDef.colorIndex));
		}

		internal static void Init()
		{
			Run.onRunStartGlobal += delegate
			{
				pickupCache.Clear();
			};
		}

		public static PickupIndex[] GetPickups(ItemTier tier)
		{
			//IL_0005: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!pickupCache.TryGetValue(tier, out var value))
			{
				value = (pickupCache[tier] = BuildPickups(tier));
			}
			return value;
		}

		private static PickupIndex[] BuildPickups(ItemTier tier)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//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_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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			List<PickupIndex> list = new List<PickupIndex>();
			HashSet<PickupIndex> hashSet = new HashSet<PickupIndex>();
			HashSet<PickupIndex[]> hashSet2 = new HashSet<PickupIndex[]>();
			Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ItemDef current = enumerator.Current;
					if (!Object.op_Implicit((Object)(object)current) || current.tier != tier)
					{
						continue;
					}
					PickupIndex[] groupFromPickupIndex = PickupTransmutationManager.GetGroupFromPickupIndex(PickupCatalog.FindPickupIndex(current.itemIndex));
					if (groupFromPickupIndex == null || !hashSet2.Add(groupFromPickupIndex))
					{
						continue;
					}
					PickupIndex[] array = groupFromPickupIndex;
					foreach (PickupIndex val in array)
					{
						if (TierOf(val) == (ItemTier?)tier && hashSet.Add(val))
						{
							list.Add(val);
						}
					}
				}
			}
			finally
			{
				((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			return list.ToArray();
		}

		public static bool IsAvailable(PickupIndex pickupIndex)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Run.instance))
			{
				return Run.instance.IsPickupAvailable(pickupIndex);
			}
			return true;
		}

		private static ItemTier? TierOf(PickupIndex pickupIndex)
		{
			//IL_0000: 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 (!QueueManager.TryGetTier(pickupIndex, out var tier))
			{
				return null;
			}
			return tier;
		}

		public static bool AnyAvailable(IEnumerable<PickupIndex> pickups)
		{
			return pickups.Any(IsAvailable);
		}
	}
}
namespace CommandQueue.UI
{
	internal class QueueDisplay : MonoBehaviour
	{
		public class QueueItemBehavior : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler, IPointerClickHandler
		{
			private GameObject m_DraggingIcon;

			private QueueDisplay m_Queue;

			private ItemIcon m_ItemIcon;

			public void Init(QueueDisplay queue)
			{
				m_Queue = queue;
				m_ItemIcon = ((Component)this).GetComponent<ItemIcon>();
			}

			public void OnBeginDrag(PointerEventData eventData)
			{
				//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_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Invalid comparison between Unknown and I4
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c9: 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)
				InputButton button = eventData.button;
				if ((int)button <= 1)
				{
					m_DraggingIcon = new GameObject("QueueItemDragIcon");
					m_DraggingIcon.transform.SetParent(((Component)m_Queue).transform, false);
					m_DraggingIcon.transform.SetAsLastSibling();
					m_DraggingIcon.AddComponent<LayoutElement>().ignoreLayout = true;
					RawImage obj = m_DraggingIcon.AddComponent<RawImage>();
					obj.texture = m_ItemIcon.image.texture;
					((Graphic)obj).raycastTarget = false;
					RectTransform rectTransform = ((Graphic)obj).rectTransform;
					float x = m_Queue.grid.cellSize.x;
					rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
					rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
					rectTransform.sizeDelta = new Vector2(x, x);
					((Graphic)obj).color = new Color(1f, 1f, 1f, 0.6f);
					SetDraggedPosition(eventData);
					((AbstractEventData)eventData).Use();
				}
			}

			public void OnDrag(PointerEventData eventData)
			{
				if (Object.op_Implicit((Object)(object)m_DraggingIcon))
				{
					SetDraggedPosition(eventData);
					((AbstractEventData)eventData).Use();
				}
			}

			public void OnEndDrag(PointerEventData eventData)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Invalid comparison between Unknown and I4
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)m_DraggingIcon))
				{
					return;
				}
				Object.Destroy((Object)(object)m_DraggingIcon);
				Vector2 localPos = default(Vector2);
				if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Queue.rectTransform, eventData.position, eventData.pressEventCamera, ref localPos))
				{
					int insertIndex = m_Queue.GetInsertIndex(localPos);
					int num = m_Queue.icons.IndexOf(m_ItemIcon);
					List<QueueManager.QueueEntry> queue = m_Queue.queue;
					if (num < 0 || num >= queue.Count)
					{
						return;
					}
					int num2 = queue[num].count;
					if ((int)eventData.button == 1 && num2 > 1)
					{
						num2 /= 2;
					}
					QueueManager.Move(m_Queue.tier, num, insertIndex, num2);
				}
				((AbstractEventData)eventData).Use();
			}

			private void SetDraggedPosition(PointerEventData data)
			{
				//IL_0018: 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)
				RectTransform component = m_DraggingIcon.GetComponent<RectTransform>();
				Vector3 position = default(Vector3);
				if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_Queue.rectTransform, data.position, data.pressEventCamera, ref position))
				{
					((Transform)component).position = position;
				}
			}

			public void OnPointerClick(PointerEventData eventData)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Invalid comparison between Unknown and I4
				//IL_0036: 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)
				if ((int)eventData.button == 1 && ModConfig.rightClickRemovesStack.Value)
				{
					int num = m_Queue.icons.IndexOf(m_ItemIcon);
					if (num >= 0)
					{
						QueueManager.Remove(m_Queue.tier, num, m_Queue.queue[num].count);
					}
					((AbstractEventData)eventData).Use();
				}
			}
		}

		public const int Padding = 5;

		public const float BaseIconSize = 40f;

		public const int MaxRows = 3;

		private const float MinIconSize = 20f;

		private const float Spacing = 8f;

		public GameObject itemIconPrefab;

		public ItemTier tier;

		private RectTransform rectTransform;

		private GridLayoutGroup grid;

		private float lastWidth = -1f;

		private readonly List<ItemIcon> icons = new List<ItemIcon>();

		private List<QueueManager.QueueEntry> queue;

		private float Step => grid.cellSize.x + grid.spacing.x;

		private int IconsPerRow
		{
			get
			{
				//IL_0007: 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_0020: Unknown result type (might be due to invalid IL or missing references)
				Rect rect = rectTransform.rect;
				return Mathf.Max(1, Mathf.FloorToInt((((Rect)(ref rect)).width - 10f + grid.spacing.x) / Step));
			}
		}

		public void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			ref RectTransform reference = ref rectTransform;
			Transform transform = ((Component)this).transform;
			reference = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			grid = ((Component)this).gameObject.AddComponent<GridLayoutGroup>();
			((LayoutGroup)grid).padding = new RectOffset(5, 5, 5, 5);
			grid.spacing = new Vector2(8f, 8f);
			grid.cellSize = new Vector2(40f, 40f);
			grid.startCorner = (Corner)0;
			grid.startAxis = (Axis)0;
			((LayoutGroup)grid).childAlignment = (TextAnchor)0;
			grid.constraint = (Constraint)0;
		}

		private void OnRectTransformDimensionsChange()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)grid))
			{
				Rect rect = rectTransform.rect;
				if (!Mathf.Approximately(((Rect)(ref rect)).width, lastWidth))
				{
					UpdateIconSize();
				}
			}
		}

		private void UpdateIconSize()
		{
			//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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = rectTransform.rect;
			float num = Mathf.Max(0f, (lastWidth = ((Rect)(ref rect)).width) - 10f);
			float num2;
			for (num2 = 40f; num2 > 20f; num2 = Mathf.Max(20f, num2 * 0.9f))
			{
				int num3 = Mathf.Max(1, Mathf.FloorToInt((num + 8f) / (num2 + 8f)));
				if (Mathf.CeilToInt((float)icons.Count / (float)num3) <= 3)
				{
					break;
				}
			}
			if (Mathf.Approximately(grid.cellSize.x, num2))
			{
				return;
			}
			grid.cellSize = new Vector2(num2, num2);
			foreach (ItemIcon icon in icons)
			{
				ScaleIcon(icon);
			}
		}

		private void ScaleIcon(ItemIcon icon)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			UIFactory.FitItemIcon(icon, grid.cellSize.x);
		}

		private int GetInsertIndex(Vector2 localPos)
		{
			//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_000c: 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)
			Rect rect = rectTransform.rect;
			float num = localPos.x - ((Rect)(ref rect)).xMin - 5f;
			float num2 = ((Rect)(ref rect)).yMax - localPos.y - 5f;
			int iconsPerRow = IconsPerRow;
			int num3 = Mathf.Max(1, Mathf.CeilToInt((float)icons.Count / (float)iconsPerRow));
			int num4 = Mathf.Clamp(Mathf.RoundToInt(num / Step), 0, iconsPerRow);
			return Mathf.Clamp(Mathf.FloorToInt(num2 / Step), 0, num3 - 1) * iconsPerRow + num4;
		}

		private ItemIcon AllocateIcon(int index)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = UIFactory.CreateRect(((Component)this).transform, "QueueCell");
			((Transform)val).SetSiblingIndex(index);
			ItemIcon icon = Object.Instantiate<GameObject>(itemIconPrefab, (Transform)(object)val, false).GetComponent<ItemIcon>();
			ScaleIcon(icon);
			Button obj = ((Component)icon).gameObject.AddComponent<Button>();
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				int num = icons.IndexOf(icon);
				if (num >= 0)
				{
					QueueManager.Remove(tier, num);
				}
			});
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj).navigation = navigation;
			((Component)icon).gameObject.AddComponent<QueueItemBehavior>().Init(this);
			icons.Insert(index, icon);
			UpdateIconSize();
			return icon;
		}

		private void RemoveIcon(int index)
		{
			Transform parent = ((Component)icons[index]).transform.parent;
			parent.SetParent((Transform)null, false);
			Object.Destroy((Object)(object)((Component)parent).gameObject);
			icons.RemoveAt(index);
			UpdateIconSize();
		}

		private void AllocateIcons(int count)
		{
			for (int num = icons.Count - 1; num >= count; num--)
			{
				RemoveIcon(num);
			}
			for (int i = icons.Count; i < count; i++)
			{
				AllocateIcon(i);
			}
		}

		public void UpdateUI()
		{
			AllocateIcons(queue.Count);
			for (int i = 0; i < icons.Count; i++)
			{
				UpdateIcon(i);
			}
		}

		private void UpdateIcon(int i)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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)
			QueueManager.QueueEntry queueEntry = queue[i];
			icons[i].SetItemIndex(new SetItemIndexArgs
			{
				newItemIndex = PickupCatalog.GetPickupDef(queueEntry.pickupIndex).itemIndex,
				newItemCount = queueEntry.count
			});
		}

		private void HandleQueueChange(QueueManager.QueueChange change, ItemTier tier, int index)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			if (tier == this.tier)
			{
				switch (change)
				{
				case QueueManager.QueueChange.Changed:
					UpdateIcon(index);
					break;
				case QueueManager.QueueChange.Added:
					AllocateIcon(index);
					UpdateIcon(index);
					break;
				case QueueManager.QueueChange.Removed:
					RemoveIcon(index);
					break;
				case QueueManager.QueueChange.Moved:
				case QueueManager.QueueChange.Reset:
					UpdateUI();
					break;
				}
			}
		}

		public void OnEnable()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)itemIconPrefab) && QueueManager.mainQueues.TryGetValue(tier, out queue))
			{
				UpdateUI();
				QueueManager.OnQueueChanged += HandleQueueChange;
			}
		}

		public void OnDisable()
		{
			QueueManager.OnQueueChanged -= HandleQueueChange;
		}
	}
	internal class QueuePage
	{
		private class SidebarEntry
		{
			public UIFactory.ButtonWrapper button;

			public TextMeshProUGUI countLabel;
		}

		private readonly RectTransform panelArea;

		private readonly GameObject itemIconPrefab;

		private readonly ItemInventoryDisplay inventoryDisplayPrefab;

		private readonly Dictionary<ItemTier, PickupIndex[]> tierPickups = new Dictionary<ItemTier, PickupIndex[]>();

		private readonly Dictionary<ItemTier, SidebarEntry> sidebarEntries = new Dictionary<ItemTier, SidebarEntry>();

		private readonly Dictionary<ItemTier, TierPanel> panels = new Dictionary<ItemTier, TierPanel>();

		private static ItemTier selectedTier;

		private const float SidebarWidth = 210f;

		public QueuePage(RectTransform root, GameObject itemIconPrefab, ItemInventoryDisplay inventoryDisplayPrefab)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			this.itemIconPrefab = itemIconPrefab;
			this.inventoryDisplayPrefab = inventoryDisplayPrefab;
			HorizontalLayoutGroup obj = UIFactory.AddHorizontalLayout((Component)(object)root, 10f);
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = true;
			((LayoutGroup)obj).padding = new RectOffset(10, 10, 10, 10);
			List<(ItemTier, PickupIndex[])> visibleTiers = GetVisibleTiers();
			BuildSidebar((Transform)(object)root, visibleTiers);
			panelArea = UIFactory.CreateRect((Transform)(object)root, "TierPanelArea");
			UIFactory.Layout((Component)(object)panelArea, 0f, -1f, 1f);
			if (visibleTiers.Count == 0)
			{
				UIFactory.Stretch(((TMP_Text)UIFactory.CreateLabel((Transform)(object)panelArea, "No item tiers are enabled. Enable some in the config (EnabledQueues).", 18f, (TextAlignmentOptions)514)).rectTransform);
			}
			else
			{
				if (!tierPickups.ContainsKey(selectedTier))
				{
					selectedTier = visibleTiers[0].Item1;
				}
				Select(selectedTier);
			}
			QueueManager.OnQueueChanged += HandleQueueChanged;
		}

		private List<(ItemTier tier, PickupIndex[] pickups)> GetVisibleTiers()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0055: 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)
			List<(ItemTier, PickupIndex[])> list = new List<(ItemTier, PickupIndex[])>();
			foreach (ItemTier item in ModConfig.enabledTabs.Value)
			{
				PickupIndex[] pickups = TierInfo.GetPickups(item);
				List<QueueManager.QueueEntry> value;
				bool flag = QueueManager.mainQueues.TryGetValue(item, out value) && value.Count > 0;
				if (pickups.Length != 0 && (TierInfo.AnyAvailable(pickups) || flag))
				{
					list.Add((item, pickups));
					tierPickups[item] = pickups;
				}
			}
			return list;
		}

		private void BuildSidebar(Transform parent, List<(ItemTier tier, PickupIndex[] pickups)> tiers)
		{
			//IL_0063: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: 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_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: 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)
			ScrollRect scrollRect;
			RectTransform val = UIFactory.CreateScrollView(parent, "TierSidebar", out scrollRect);
			UIFactory.Layout((Component)(object)scrollRect, 210f).minWidth = 210f;
			UIFactory.AddVerticalLayout((Component)(object)val, 4f);
			foreach (var tier2 in tiers)
			{
				ItemTier tier = tier2.tier;
				UIFactory.ButtonWrapper button = UIFactory.CreateButton((Transform)(object)val, TierInfo.GetDisplayName(tier), (UnityAction)delegate
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					Select(tier);
				});
				UIFactory.Layout((Component)(object)button.rectTransform, -1f, 40f);
				if (Object.op_Implicit((Object)(object)button.textComponent))
				{
					((TMP_Text)button.textComponent).margin = new Vector4(16f, 0f, 34f, 0f);
				}
				RectTransform obj = UIFactory.CreateTierStripe((Transform)(object)button.rectTransform, tier, vertical: true);
				obj.anchorMin = new Vector2(0f, 0f);
				obj.anchorMax = new Vector2(0f, 1f);
				obj.pivot = new Vector2(0f, 0.5f);
				obj.sizeDelta = new Vector2(5f, -10f);
				obj.anchoredPosition = new Vector2(5f, 0f);
				TextMeshProUGUI val2 = UIFactory.CreateLabel((Transform)(object)button.rectTransform, "", 16f, (TextAlignmentOptions)4100);
				((Graphic)val2).color = UIFactory.SubtleTextColor;
				RectTransform rectTransform = ((TMP_Text)val2).rectTransform;
				rectTransform.anchorMin = new Vector2(1f, 0f);
				rectTransform.anchorMax = new Vector2(1f, 1f);
				rectTransform.pivot = new Vector2(1f, 0.5f);
				rectTransform.sizeDelta = new Vector2(40f, 0f);
				rectTransform.anchoredPosition = new Vector2(-8f, 0f);
				sidebarEntries[tier] = new SidebarEntry
				{
					button = button,
					countLabel = val2
				};
				UpdateCount(tier);
			}
		}

		private void Select(ItemTier tier)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			if (!tierPickups.TryGetValue(tier, out var value))
			{
				return;
			}
			foreach (TierPanel value2 in panels.Values)
			{
				value2.root.SetActive(value2.tier == tier);
			}
			if (!panels.ContainsKey(tier))
			{
				panels[tier] = new TierPanel(tier, value, (Transform)(object)panelArea, itemIconPrefab, inventoryDisplayPrefab);
			}
			foreach (KeyValuePair<ItemTier, SidebarEntry> sidebarEntry in sidebarEntries)
			{
				UIFactory.MarkButton(sidebarEntry.Value.button, sidebarEntry.Key == tier);
			}
			selectedTier = tier;
		}

		public void RefreshSelection()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (sidebarEntries.TryGetValue(selectedTier, out var value))
			{
				UIFactory.MarkButton(value.button, selected: true);
			}
		}

		private void UpdateCount(ItemTier tier)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (sidebarEntries.TryGetValue(tier, out var value))
			{
				List<QueueManager.QueueEntry> value2;
				int num = (QueueManager.mainQueues.TryGetValue(tier, out value2) ? value2.Sum((QueueManager.QueueEntry e) => e.count) : 0);
				((TMP_Text)value.countLabel).text = ((num > 0) ? num.ToString() : "");
			}
		}

		private void HandleQueueChanged(QueueManager.QueueChange change, ItemTier tier, int index)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			UpdateCount(tier);
		}

		public void Destroy()
		{
			QueueManager.OnQueueChanged -= HandleQueueChanged;
			foreach (TierPanel value in panels.Values)
			{
				value.Destroy();
			}
			panels.Clear();
		}
	}
	internal class QueueRowLayout : LayoutGroup
	{
		public float spacing = 5f;

		public float minRowHeight = 50f;

		public override void CalculateLayoutInputHorizontal()
		{
			((LayoutGroup)this).CalculateLayoutInputHorizontal();
			((LayoutGroup)this).SetLayoutInputForAxis(minRowHeight, minRowHeight, 1f, 0);
		}

		public override void CalculateLayoutInputVertical()
		{
			float num = minRowHeight;
			if (((LayoutGroup)this).rectChildren.Count > 0)
			{
				num = Mathf.Max(num, LayoutUtility.GetPreferredHeight(((LayoutGroup)this).rectChildren[0]));
			}
			((LayoutGroup)this).SetLayoutInputForAxis(num, num, 0f, 1);
		}

		public override void SetLayoutHorizontal()
		{
			//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)
			Rect rect = ((LayoutGroup)this).rectTransform.rect;
			float width = ((Rect)(ref rect)).width;
			if (((LayoutGroup)this).rectChildren.Count > 0)
			{
				((LayoutGroup)this).SetChildAlongAxis(((LayoutGroup)this).rectChildren[0], 0, 0f, Mathf.Max(0f, width - minRowHeight - spacing));
			}
			if (((LayoutGroup)this).rectChildren.Count > 1)
			{
				((LayoutGroup)this).SetChildAlongAxis(((LayoutGroup)this).rectChildren[1], 0, width - minRowHeight, minRowHeight);
			}
		}

		public override void SetLayoutVertical()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (((LayoutGroup)this).rectChildren.Count > 0)
			{
				RectTransform obj = ((LayoutGroup)this).rectChildren[0];
				Rect rect = ((LayoutGroup)this).rectTransform.rect;
				((LayoutGroup)this).SetChildAlongAxis(obj, 1, 0f, ((Rect)(ref rect)).height);
			}
			if (((LayoutGroup)this).rectChildren.Count > 1)
			{
				((LayoutGroup)this).SetChildAlongAxis(((LayoutGroup)this).rectChildren[1], 1, 0f, minRowHeight);
			}
		}
	}
	internal class SavesPage
	{
		private const int SavesPerPage = 5;

		private const float RowHeight = 52f;

		private const float FontSize = 20f;

		private const float PagerHeight = 52f;

		private const float PagerFontSize = 14f;

		private const float EditButtonWidth = 110f;

		private const float EditButtonSpacing = 12f;

		private const float EditGroupWidth = 354f;

		private const float GroupGap = 36f;

		private readonly RectTransform list;

		private readonly TMP_InputField nameInput;

		private readonly TextMeshProUGUI statusLabel;

		private UIFactory.ButtonWrapper saveButton;

		private UIFactory.ButtonWrapper pageIndicator;

		private readonly List<GameObject> rows = new List<GameObject>();

		private static int pageIndex;

		private string renamingSaveId;

		private string pendingConfirmation;

		public SavesPage(RectTransform root)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Expected O, but got Unknown
			((LayoutGroup)UIFactory.AddVerticalLayout((Component)(object)root, 10f)).padding = new RectOffset(24, 24, 16, 16);
			RectTransform parent = CreateRow((Transform)(object)root, "Header");
			nameInput = UIFactory.CreateInputField((Transform)(object)parent, "Save name...", 40, 20f);
			PlaceLeft(((Component)nameInput).GetComponent<RectTransform>());
			saveButton = CreateButton((Transform)(object)parent, "Save current queue", new UnityAction(HandleSaveClicked));
			PlaceRight(saveButton.rectTransform, 354f);
			statusLabel = UIFactory.CreateLabel((Transform)(object)root, "", 20f, (TextAlignmentOptions)514);
			((Graphic)statusLabel).color = UIFactory.SubtleTextColor;
			UIFactory.Layout((Component)(object)statusLabel, -1f, 22f);
			list = UIFactory.CreateRect((Transform)(object)root, "SaveList");
			UIFactory.Layout((Component)(object)list, -1f, -1f, -1f, 1f);
			UIFactory.AddVerticalLayout((Component)(object)list, 8f);
			RectTransform val = UIFactory.CreateRect((Transform)(object)root, "Pager");
			UIFactory.Layout((Component)(object)val, -1f, 52f, -1f, 0f);
			HorizontalLayoutGroup obj = UIFactory.AddHorizontalLayout((Component)(object)val, 6f);
			((LayoutGroup)obj).childAlignment = (TextAnchor)4;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			PinPagerSize(CreateButton((Transform)(object)val, "<", (UnityAction)delegate
			{
				pageIndex--;
				Refresh();
			}, null, 14f), 32f);
			pageIndicator = CreateButton((Transform)(object)val, null, null, "Page 1/1", 14f);
			((Selectable)pageIndicator.hgButton).interactable = false;
			PinPagerSize(pageIndicator, 84f);
			PinPagerSize(CreateButton((Transform)(object)val, ">", (UnityAction)delegate
			{
				pageIndex++;
				Refresh();
			}, null, 14f), 32f);
			Refresh();
		}

		private static void PinPagerSize(UIFactory.ButtonWrapper button, float width)
		{
			UIFactory.Layout((Component)(object)button.rectTransform, width, 52f, 0f, 0f).minWidth = width;
		}

		private static RectTransform CreateRow(Transform parent, string name)
		{
			RectTransform obj = UIFactory.CreateRect(parent, name);
			UIFactory.Layout((Component)(object)obj, -1f, 52f);
			return obj;
		}

		private static UIFactory.ButtonWrapper CreateButton(Transform parent, string text, UnityAction onClick, string rawText = null, float fontSize = 20f)
		{
			UIFactory.ButtonWrapper buttonWrapper = UIFactory.CreateButton(parent, text, onClick, rawText);
			UIFactory.SetLabelStyle(buttonWrapper, fontSize);
			return buttonWrapper;
		}

		private static void PlaceLeft(RectTransform transform)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			transform.anchorMin = new Vector2(0f, 0f);
			transform.anchorMax = new Vector2(1f, 1f);
			transform.offsetMin = Vector2.zero;
			transform.offsetMax = new Vector2(-390f, 0f);
		}

		private static void PlaceRight(RectTransform transform, float width, float rightOffset = 0f)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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)
			transform.anchorMin = new Vector2(1f, 0f);
			transform.anchorMax = new Vector2(1f, 1f);
			transform.pivot = new Vector2(1f, 0.5f);
			transform.sizeDelta = new Vector2(width, 0f);
			transform.anchoredPosition = new Vector2(0f - rightOffset, 0f);
		}

		private void HandleSaveClicked()
		{
			if (renamingSaveId != null)
			{
				SaveManager.RenameSave(renamingSaveId, nameInput.text);
				SetStatus("Renamed save.");
				renamingSaveId = null;
			}
			else
			{
				SaveManager.SavedQueue savedQueue = SaveManager.CreateSave(nameInput.text);
				pageIndex = 0;
				SetStatus($"Saved '{savedQueue.name}' ({savedQueue.ItemCount} items).");
			}
			nameInput.text = "";
			Refresh();
		}

		private void SetStatus(string text)
		{
			((TMP_Text)statusLabel).text = text;
		}

		public void Refresh()
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject row in rows)
			{
				row.transform.SetParent((Transform)null, false);
				Object.Destroy((Object)(object)row);
			}
			rows.Clear();
			IReadOnlyList<SaveManager.SavedQueue> saves = SaveManager.Saves;
			int num = Mathf.Max(1, Mathf.CeilToInt((float)saves.Count / 5f));
			pageIndex = Mathf.Clamp(pageIndex, 0, num - 1);
			pageIndicator.rawText = $"Page {pageIndex + 1}/{num}";
			saveButton.text = ((renamingSaveId != null) ? "Apply rename" : "Save current queue");
			if (saves.Count == 0)
			{
				TextMeshProUGUI val = UIFactory.CreateLabel((Transform)(object)list, "No saves yet. Type a name and press Save.", 20f, (TextAlignmentOptions)514);
				((Graphic)val).color = UIFactory.SubtleTextColor;
				UIFactory.Layout((Component)(object)val, -1f, 52f);
				rows.Add(((Component)val).gameObject);
				return;
			}
			foreach (SaveManager.SavedQueue item in saves.Skip(pageIndex * 5).Take(5).ToList())
			{
				rows.Add(CreateSaveRow(item));
			}
		}

		private GameObject CreateSaveRow(SaveManager.SavedQueue save)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			string saveId = save.id;
			RectTransform val = CreateRow((Transform)(object)list, "SaveRow");
			UIFactory.ButtonWrapper buttonWrapper = CreateButton((Transform)(object)val, null, (UnityAction)delegate
			{
				SaveManager.LoadResult loadResult = SaveManager.LoadSave(saveId);
				string text = $"Loaded '{save.name}': {loadResult.loadedItems} items.";
				if (loadResult.unknownItems > 0)
				{
					text += $" {loadResult.unknownItems} unknown skipped.";
				}
				if (loadResult.disabledTierItems > 0)
				{
					text += $" {loadResult.disabledTierItems} in disabled tiers skipped.";
				}
				SetStatus(text);
			}, $"{save.name} ({save.ItemCount} items)");
			PlaceLeft(buttonWrapper.rectTransform);
			UIFactory.SetTooltip(buttonWrapper.gameObject, save.name, "Replace the current queue with this save.", Color.white);
			PlaceRight(CreateConfirmedButton((Transform)(object)val, "overwrite:" + saveId, "Overwrite", delegate
			{
				SaveManager.OverwriteSave(saveId);
				SetStatus("Overwrote '" + save.name + "' with the current queue.");
			}).rectTransform, 110f, Offset(0));
			PlaceRight(CreateButton((Transform)(object)val, (renamingSaveId == saveId) ? "Cancel" : "Rename", (UnityAction)delegate
			{
				if (renamingSaveId == saveId)
				{
					renamingSaveId = null;
					nameInput.text = "";
				}
				else
				{
					renamingSaveId = saveId;
					nameInput.text = save.name;
					((Selectable)nameInput).Select();
					nameInput.ActivateInputField();
				}
				Refresh();
			}).rectTransform, 110f, Offset(1));
			PlaceRight(CreateConfirmedButton((Transform)(object)val, "delete:" + saveId, "Delete", delegate
			{
				SaveManager.DeleteSave(saveId);
				SetStatus("Deleted '" + save.name + "'.");
				if (renamingSaveId == saveId)
				{
					renamingSaveId = null;
				}
			}).rectTransform, 110f, Offset(2));
			return ((Component)val).gameObject;
			static float Offset(int index)
			{
				return (float)(2 - index) * 122f;
			}
		}

		private UIFactory.ButtonWrapper CreateConfirmedButton(Transform row, string confirmationKey, string label, Action action)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			bool flag = pendingConfirmation == confirmationKey;
			UIFactory.ButtonWrapper buttonWrapper = CreateButton(row, flag ? "Confirm?" : label, (UnityAction)delegate
			{
				if (pendingConfirmation == confirmationKey)
				{
					action();
					pendingConfirmation = null;
				}
				else
				{
					pendingConfirmation = confirmationKey;
				}
				Refresh();
			});
			if (flag)
			{
				UIFactory.MarkButton(buttonWrapper, selected: true);
			}
			return buttonWrapper;
		}
	}
	internal class TierPanel
	{
		public readonly ItemTier tier;

		public readonly GameObject root;

		private readonly List<AsyncOperationHandle<Sprite>> iconHandles = new List<AsyncOperationHandle<Sprite>>();

		private const float ItemButtonScale = 0.9f;

		private const int CtrlClickCount = 10;

		private static bool ControlHeld
		{
			get
			{
				if (!Input.GetKey((KeyCode)306))
				{
					return Input.GetKey((KeyCode)305);
				}
				return true;
			}
		}

		public TierPanel(ItemTier tier, PickupIndex[] pickups, Transform parent, GameObject itemIconPrefab, ItemInventoryDisplay inventoryDisplayPrefab)
		{
			//IL_0012: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			this.tier = tier;
			RectTransform val = UIFactory.CreateRect(parent, $"{tier}QueuePanel");
			UIFactory.Stretch(val);
			root = ((Component)val).gameObject;
			UIFactory.AddVerticalLayout((Component)(object)val);
			BuildQueueRow((Transform)(object)val, itemIconPrefab, inventoryDisplayPrefab);
			BuildItemGrid((Transform)(object)val, pickups);
		}

		private void BuildQueueRow(Transform parent, GameObject itemIconPrefab, ItemInventoryDisplay inventoryDisplayPrefab)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: