Decompiled source of CommandQueuePlus v0.5.9

plugins/CommandQueuePlus.dll

Decompiled 16 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HG;
using HarmonyLib;
using Rewired;
using Rewired.Integration.UnityUI;
using RoR2;
using RoR2.Artifacts;
using RoR2.ContentManagement;
using RoR2.UI;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace CommandQueue;

[BepInPlugin("ror_mods.commandqueue", "CommandQueuePlus", "0.5.9")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	private enum QueueControl
	{
		DPad,
		RightStick
	}

	private sealed class GuestSelection
	{
		internal readonly PickupPickerController Picker;

		internal readonly int Index;

		internal readonly TierQueues<QueueGroup, PickupIndex>.Entry Entry;

		internal readonly CharacterMaster Master;

		internal readonly bool DirectGrant;

		internal bool Acknowledged;

		internal bool SawResult;

		private readonly NetworkUIPromptController prompt;

		private readonly Run run;

		private readonly Stage stage;

		private readonly Vector3 position;

		private readonly float deadline;

		private readonly UniquePickup expectedPickup;

		internal bool CanWait => NetworkClient.active && Run.instance == run && Stage.instance == stage && Time.unscaledTime < deadline && (!Object.op_Implicit((Object)(object)Picker) || !Object.op_Implicit((Object)(object)prompt) || !Object.op_Implicit((Object)(object)prompt.currentParticipantMaster) || (Object)(object)prompt.currentParticipantMaster == (Object)(object)Master);

		internal bool IsConfirmed => Acknowledged || (!Object.op_Implicit((Object)(object)Picker) && SawResult);

		internal GuestSelection(PickupPickerController picker, NetworkUIPromptController prompt, LocalUser user, int index, TierQueues<QueueGroup, PickupIndex>.Entry entry, Run run, Stage stage)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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)
			Picker = picker;
			Index = index;
			Entry = entry;
			Master = user.cachedMaster;
			this.prompt = prompt;
			this.run = run;
			this.stage = stage;
			position = ((Component)picker).transform.position;
			expectedPickup = picker.options[index].pickup;
			deadline = Time.unscaledTime + 5f;
			UniquePickupUnityEvent onUniquePickupSelected = picker.onUniquePickupSelected;
			if (onUniquePickupSelected == null)
			{
				return;
			}
			for (int i = 0; i < ((UnityEventBase)onUniquePickupSelected).GetPersistentEventCount(); i++)
			{
				if (((UnityEventBase)onUniquePickupSelected).GetPersistentMethodName(i) == "AttemptGrantPickupDirectly")
				{
					DirectGrant = true;
				}
			}
		}

		internal bool MatchesDrop(UniquePickup pickup, Vector3 origin)
		{
			//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_0014: 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_0033: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			int result;
			if (CanWait && pickup.pickupIndex == Entry.Item && pickup.isRental == expectedPickup.isRental && pickup.upgradeValue == expectedPickup.upgradeValue)
			{
				Vector3 val = origin - position;
				result = ((((Vector3)(ref val)).sqrMagnitude <= 0.0625f) ? 1 : 0);
			}
			else
			{
				result = 0;
			}
			return (byte)result != 0;
		}
	}

	private const string PluginId = "ror_mods.commandqueue";

	private const string PluginName = "CommandQueuePlus";

	private const string RiskOfOptionsId = "com.rune580.riskofoptions";

	private const int MinimumSensitivity = 50;

	private const int MaximumSensitivity = 200;

	private ConfigEntry<QueueControl> controllerNavigation;

	private ConfigEntry<int> controllerSensitivity;

	private readonly HashSet<ItemDef> officialItems = new HashSet<ItemDef>();

	private readonly HashSet<EquipmentDef> officialEquipment = new HashSet<EquipmentDef>();

	private readonly List<EquipmentDef> availableEquipment = new List<EquipmentDef>();

	private readonly List<EquipmentDef> availableOfficialEquipment = new List<EquipmentDef>();

	private readonly List<EquipmentDef> availableQualityEquipment = new List<EquipmentDef>();

	private readonly Dictionary<ItemTier, List<ItemDef>> allByTier = new Dictionary<ItemTier, List<ItemDef>>();

	private readonly Dictionary<ItemTier, List<ItemDef>> officialByTier = new Dictionary<ItemTier, List<ItemDef>>();

	private static readonly ItemDef[] empty = (ItemDef[])(object)new ItemDef[0];

	private Run indexedRun;

	private const string QualityPluginId = "com.Gorakh.ItemQualities";

	private readonly HashSet<ItemDef> qualityPackItems = new HashSet<ItemDef>();

	private readonly HashSet<EquipmentDef> qualityPackEquipment = new HashSet<EquipmentDef>();

	private readonly Dictionary<ItemIndex, QualityLevel> qualityByItem = new Dictionary<ItemIndex, QualityLevel>();

	private readonly Dictionary<EquipmentIndex, QualityLevel> qualityByEquipment = new Dictionary<EquipmentIndex, QualityLevel>();

	private readonly Dictionary<EquipmentIndex, EquipmentDef> baseEquipmentByVariant = new Dictionary<EquipmentIndex, EquipmentDef>();

	private readonly Dictionary<ItemTier, List<ItemDef>> qualityByTier = new Dictionary<ItemTier, List<ItemDef>>();

	private FieldInfo qualityAvailability;

	private MethodInfo getQualityTier;

	private MethodInfo getEquipmentQualityTier;

	private MethodInfo getEquipmentIndexOfQuality;

	private bool qualityIndexed;

	private const string LookingGlassId = "droppod.lookingglass";

	private Func<ItemDef, int, CharacterMaster, bool, bool, string> lookingGlassItemDescription;

	private Func<CharacterMaster, EquipmentIndex, string> lookingGlassEquipmentExtras;

	private ConfigEntry<bool> lookingGlassFullDescriptions;

	private bool loggedLookingGlassDescriptionFailure;

	private TierQueues<QueueGroup, PickupIndex> queues = new TierQueues<QueueGroup, PickupIndex>();

	private ScoreboardController scoreboard;

	private NativeQueueView queueView;

	private Run queueRun;

	private static Plugin active;

	private readonly Harmony pickerHarmony = new Harmony("ror_mods.commandqueue.picker");

	private readonly Dictionary<PickupPickerController, CameraRigController> pendingPickers = new Dictionary<PickupPickerController, CameraRigController>();

	private readonly Dictionary<QueueGroup, GuestSelection> guestSelections = new Dictionary<QueueGroup, GuestSelection>();

	private static readonly MethodInfo localParticipantGetter = AccessTools.PropertyGetter(typeof(NetworkUIPromptController), "currentLocalParticipant");

	private static readonly MethodInfo promptCameraGetter = AccessTools.PropertyGetter(typeof(NetworkUIPromptController), "currentCamera");

	private static readonly MethodInfo nativeServerSelection = AccessTools.Method(typeof(PickupPickerController), "HandlePickupSelected", new Type[1] { typeof(int) }, (Type[])null);

	internal const string ScoreboardAction = "info";

	private readonly Harmony inputHarmony = new Harmony("ror_mods.commandqueue.input");

	private static Action<PlayerCharacterMasterController> suppressPrimary;

	private static Action<PlayerCharacterMasterController> suppressSecondary;

	private static Action<PlayerCharacterMasterController> suppressControllerActions;

	private readonly Dictionary<NetworkUIPromptController, LocalUser> controllerPrompts = new Dictionary<NetworkUIPromptController, LocalUser>();

	internal bool UseRightStick => controllerNavigation.Value == QueueControl.RightStick;

	internal int ControllerSensitivity => controllerSensitivity.Value;

	internal ConfigEntry<ItemSource> BrowserSource { get; private set; }

	internal ConfigEntry<QualityLevels> BrowserQualityLevels { get; private set; }

	internal ItemSource ActiveSource => (BrowserSource.Value != ItemSource.Quality || QualitySupported) ? BrowserSource.Value : ItemSource.Official;

	internal bool QualitySupported
	{
		get
		{
			//IL_0044: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			if (qualityIndexed)
			{
				return true;
			}
			if (getQualityTier == null)
			{
				return false;
			}
			try
			{
				if (!(qualityAvailability.GetValue(null) is ResourceAvailability val) || !((ResourceAvailability)(ref val)).available)
				{
					return false;
				}
				Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						ItemDef current = enumerator.Current;
						if (Object.op_Implicit((Object)(object)current))
						{
							QualityLevel qualityLevel = (QualityLevel)(Convert.ToInt32(getQualityTier.Invoke(null, new object[1] { current.itemIndex })) + 1);
							if (qualityLevel >= QualityLevel.Uncommon && qualityLevel <= QualityLevel.Legendary)
							{
								qualityByItem[current.itemIndex] = qualityLevel;
							}
						}
					}
				}
				finally
				{
					((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
				}
				IndexEquipmentQuality();
				qualityIndexed = true;
				indexedRun = null;
				return true;
			}
			catch (Exception ex)
			{
				qualityByItem.Clear();
				getQualityTier = null;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not read the Quality catalog. Quality-specific filtering and selection are unavailable. " + ex.Message));
				return false;
			}
		}
	}

	internal bool HasLookingGlassDetails => lookingGlassItemDescription != null || lookingGlassEquipmentExtras != null;

	internal TierQueues<QueueGroup, PickupIndex> Queues => queues;

	internal IReadOnlyList<ItemDef> GetAvailableItems(ItemTier tier, bool includeAllQualityLevels = false)
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		Run instance = Run.instance;
		if (!Object.op_Implicit((Object)(object)instance))
		{
			return empty;
		}
		bool qualitySupported = QualitySupported;
		if ((Object)(object)indexedRun != (Object)(object)instance)
		{
			IndexRun(instance);
		}
		if (BrowserSource.Value == ItemSource.All)
		{
			IReadOnlyList<ItemDef> result;
			if (!allByTier.TryGetValue(tier, out var value))
			{
				IReadOnlyList<ItemDef> readOnlyList = empty;
				result = readOnlyList;
			}
			else
			{
				IReadOnlyList<ItemDef> readOnlyList = value;
				result = readOnlyList;
			}
			return result;
		}
		if (BrowserSource.Value != ItemSource.Quality || !qualitySupported)
		{
			IReadOnlyList<ItemDef> result2;
			if (!officialByTier.TryGetValue(tier, out var value2))
			{
				IReadOnlyList<ItemDef> readOnlyList = empty;
				result2 = readOnlyList;
			}
			else
			{
				IReadOnlyList<ItemDef> readOnlyList = value2;
				result2 = readOnlyList;
			}
			return result2;
		}
		if (!qualityByTier.TryGetValue(tier, out var value3))
		{
			return empty;
		}
		QualityLevels levels = SingleQualityLevelOrAll(BrowserQualityLevels.Value);
		if (includeAllQualityLevels || levels == QualityLevels.All)
		{
			return value3;
		}
		return value3.FindAll((ItemDef item) => levels == LevelFlag(qualityByItem[item.itemIndex]));
	}

	private unsafe void IndexRun(Run run)
	{
		//IL_0026: 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_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_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: 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_0188: Unknown result type (might be due to invalid IL or missing references)
		allByTier.Clear();
		officialByTier.Clear();
		qualityByTier.Clear();
		Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				ItemDef current = enumerator.Current;
				if (Object.op_Implicit((Object)(object)current) && !current.hidden && run.IsItemAvailable(current.itemIndex))
				{
					AddToTier(allByTier, current);
					if (officialItems.Contains(current))
					{
						AddToTier(officialByTier, current);
					}
					if (qualityByItem.ContainsKey(current.itemIndex))
					{
						AddToTier(qualityByTier, current);
					}
				}
			}
		}
		finally
		{
			((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
		}
		availableEquipment.Clear();
		availableOfficialEquipment.Clear();
		availableQualityEquipment.Clear();
		GenericStaticEnumerable<EquipmentIndex, AllEquipmentEnumerator> allEquipment = EquipmentCatalog.allEquipment;
		AllEquipmentEnumerator enumerator2 = allEquipment.GetEnumerator();
		try
		{
			while (((AllEquipmentEnumerator)(ref enumerator2)).MoveNext())
			{
				EquipmentIndex current2 = ((AllEquipmentEnumerator)(ref enumerator2)).Current;
				EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(current2);
				if (Object.op_Implicit((Object)(object)equipmentDef) && GetBaseEquipment(equipmentDef).canDrop && run.IsEquipmentAvailable(current2))
				{
					availableEquipment.Add(equipmentDef);
					if (officialEquipment.Contains(equipmentDef))
					{
						availableOfficialEquipment.Add(equipmentDef);
					}
					if (qualityByEquipment.ContainsKey(current2))
					{
						availableQualityEquipment.Add(equipmentDef);
					}
				}
			}
		}
		finally
		{
			((IDisposable)(*(AllEquipmentEnumerator*)(&enumerator2))/*cast due to .constrained prefix*/).Dispose();
		}
		indexedRun = run;
	}

	internal IReadOnlyList<EquipmentDef> GetAvailableEquipment(bool includeAllQualityLevels = false)
	{
		Run instance = Run.instance;
		if (!Object.op_Implicit((Object)(object)instance))
		{
			return Array.Empty<EquipmentDef>();
		}
		bool qualitySupported = QualitySupported;
		ItemSource value = BrowserSource.Value;
		if ((Object)(object)indexedRun != (Object)(object)instance)
		{
			IndexRun(instance);
		}
		switch (value)
		{
		case ItemSource.All:
			return availableEquipment;
		case ItemSource.Quality:
			if (qualitySupported)
			{
				QualityLevels levels = SingleQualityLevelOrAll(BrowserQualityLevels.Value);
				if (includeAllQualityLevels || levels == QualityLevels.All)
				{
					return availableQualityEquipment;
				}
				return availableQualityEquipment.FindAll((EquipmentDef equipment) => levels == LevelFlag(qualityByEquipment[equipment.equipmentIndex]));
			}
			goto default;
		default:
			return availableOfficialEquipment;
		}
	}

	private void InvalidateRun(Run run)
	{
		if ((Object)(object)indexedRun == (Object)(object)run)
		{
			indexedRun = null;
		}
		if (Object.op_Implicit((Object)(object)queueView))
		{
			queueView.MarkItemsDirty();
		}
	}

	private static void AddToTier(Dictionary<ItemTier, List<ItemDef>> groups, ItemDef item)
	{
		//IL_0003: 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 (!groups.TryGetValue(item.tier, out var value))
		{
			groups.Add(item.tier, value = new List<ItemDef>());
		}
		value.Add(item);
	}

	private void Awake()
	{
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Expected O, but got Unknown
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Expected O, but got Unknown
		ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Browser", "OfficialItemsOnly", true, "Legacy source preference.");
		BrowserSource = ((BaseUnityPlugin)this).Config.Bind<ItemSource>("Browser", "ItemSource", (!val.Value) ? ItemSource.All : ItemSource.Official, "Which items the browser shows.");
		BrowserQualityLevels = ((BaseUnityPlugin)this).Config.Bind<QualityLevels>("Browser", "QualityLevels", QualityLevels.All, "Quality level selected in the Quality Only browser, or All.");
		BrowserQualityLevels.Value = SingleQualityLevelOrAll(BrowserQualityLevels.Value);
		controllerNavigation = ((BaseUnityPlugin)this).Config.Bind<QueueControl>("Controller", "Queue Navigation", QueueControl.DPad, "Choose the D-pad or right stick to move through the Command Queue. Right stick navigation takes over camera control while the queue is open.");
		controllerSensitivity = ((BaseUnityPlugin)this).Config.Bind<int>("Controller", "Sensitivity", 100, new ConfigDescription("Navigation repeat speed as a percentage of the default. Applies when holding the D-pad or right stick.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 200), Array.Empty<object>()));
		RegisterControllerOptions();
		FindQualityPlugin();
		FindLookingGlassPlugin();
		ContentManager.onContentPacksAssigned += IndexOfficialItems;
		Run.onAvailablePickupsModified += InvalidateRun;
		ScoreboardController.onScoreboardOpen += new UnityAction(OpenBrowser);
		InstallPickerHook();
		try
		{
			InstallInputHooks();
		}
		catch (Exception ex)
		{
			RemoveInputHooks();
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Using native input because the queue input hooks could not be installed. " + ex.Message));
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"CommandQueuePlus loaded.");
	}

	private void RegisterControllerOptions()
	{
		if (!Chainloader.PluginInfos.TryGetValue("com.rune580.riskofoptions", out var value) || !Object.op_Implicit((Object)(object)value.Instance))
		{
			return;
		}
		try
		{
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			Type type = assembly.GetType("RiskOfOptions.Options.ChoiceOption", throwOnError: true);
			Type type2 = assembly.GetType("RiskOfOptions.Options.BaseOption", throwOnError: true);
			Type type3 = assembly.GetType("RiskOfOptions.ModSettingsManager", throwOnError: true);
			ConstructorInfo constructor = type.GetConstructor(new Type[1] { typeof(ConfigEntryBase) });
			MethodInfo method = type3.GetMethod("AddOption", new Type[3]
			{
				type2,
				typeof(string),
				typeof(string)
			});
			object obj = constructor.Invoke(new object[1] { controllerNavigation });
			method.Invoke(null, new object[3] { obj, "ror_mods.commandqueue", "CommandQueuePlus" });
			Type type4 = assembly.GetType("RiskOfOptions.Options.IntSliderOption", throwOnError: true);
			Type type5 = assembly.GetType("RiskOfOptions.OptionConfigs.IntSliderConfig", throwOnError: true);
			object obj2 = Activator.CreateInstance(type5);
			type5.GetField("min").SetValue(obj2, 50);
			type5.GetField("max").SetValue(obj2, 200);
			ConstructorInfo constructor2 = type4.GetConstructor(new Type[2]
			{
				typeof(ConfigEntry<int>),
				type5
			});
			obj = constructor2.Invoke(new object[2] { controllerSensitivity, obj2 });
			method.Invoke(null, new object[3] { obj, "ror_mods.commandqueue", "CommandQueuePlus" });
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not register controller settings with Risk of Options. " + ex.GetBaseException().Message));
		}
	}

	private void IndexOfficialItems(ReadOnlyArray<ReadOnlyContentPack> packs)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: 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_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: 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_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		officialItems.Clear();
		officialEquipment.Clear();
		qualityPackItems.Clear();
		qualityPackEquipment.Clear();
		qualityByItem.Clear();
		qualityByEquipment.Clear();
		baseEquipmentByVariant.Clear();
		qualityIndexed = false;
		indexedRun = null;
		Enumerator<ReadOnlyContentPack> enumerator = packs.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				ReadOnlyContentPack current = enumerator.Current;
				switch (((ReadOnlyContentPack)(ref current)).identifier)
				{
				case "RoR2.BaseContent":
				case "RoR2.DLC1":
				case "RoR2.DLC2":
				case "RoR2.DLC3":
				case "RoR2.DLC4":
				{
					AssetEnumerator<ItemDef> enumerator4 = ((ReadOnlyContentPack)(ref current)).itemDefs.GetEnumerator();
					try
					{
						while (enumerator4.MoveNext())
						{
							ItemDef current4 = enumerator4.Current;
							officialItems.Add(current4);
						}
					}
					finally
					{
						((IDisposable)enumerator4/*cast due to .constrained prefix*/).Dispose();
					}
					AssetEnumerator<EquipmentDef> enumerator5 = ((ReadOnlyContentPack)(ref current)).equipmentDefs.GetEnumerator();
					try
					{
						while (enumerator5.MoveNext())
						{
							EquipmentDef current5 = enumerator5.Current;
							officialEquipment.Add(current5);
						}
					}
					finally
					{
						((IDisposable)enumerator5/*cast due to .constrained prefix*/).Dispose();
					}
					break;
				}
				case "com.Gorakh.ItemQualities":
				{
					AssetEnumerator<ItemDef> enumerator2 = ((ReadOnlyContentPack)(ref current)).itemDefs.GetEnumerator();
					try
					{
						while (enumerator2.MoveNext())
						{
							ItemDef current2 = enumerator2.Current;
							qualityPackItems.Add(current2);
						}
					}
					finally
					{
						((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
					}
					AssetEnumerator<EquipmentDef> enumerator3 = ((ReadOnlyContentPack)(ref current)).equipmentDefs.GetEnumerator();
					try
					{
						while (enumerator3.MoveNext())
						{
							EquipmentDef current3 = enumerator3.Current;
							qualityPackEquipment.Add(current3);
						}
					}
					finally
					{
						((IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose();
					}
					break;
				}
				}
			}
		}
		finally
		{
			((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Indexed {officialItems.Count} official item definitions.");
	}

	private void OnDestroy()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		ContentManager.onContentPacksAssigned -= IndexOfficialItems;
		Run.onAvailablePickupsModified -= InvalidateRun;
		ScoreboardController.onScoreboardOpen -= new UnityAction(OpenBrowser);
		RemovePickerHook();
		RemoveInputHooks();
		if (Object.op_Implicit((Object)(object)queueView))
		{
			Object.Destroy((Object)(object)((Component)queueView).gameObject);
		}
	}

	private unsafe void IndexEquipmentQuality()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		if (getEquipmentQualityTier == null)
		{
			return;
		}
		try
		{
			object obj = Enum.ToObject(getEquipmentQualityTier.ReturnType, -1);
			GenericStaticEnumerable<EquipmentIndex, AllEquipmentEnumerator> allEquipment = EquipmentCatalog.allEquipment;
			AllEquipmentEnumerator enumerator = allEquipment.GetEnumerator();
			try
			{
				while (((AllEquipmentEnumerator)(ref enumerator)).MoveNext())
				{
					EquipmentIndex current = ((AllEquipmentEnumerator)(ref enumerator)).Current;
					QualityLevel qualityLevel = (QualityLevel)(Convert.ToInt32(getEquipmentQualityTier.Invoke(null, new object[1] { current })) + 1);
					if (qualityLevel < QualityLevel.Uncommon || qualityLevel > QualityLevel.Legendary)
					{
						continue;
					}
					qualityByEquipment[current] = qualityLevel;
					if (!(getEquipmentIndexOfQuality == null))
					{
						EquipmentIndex val = (EquipmentIndex)getEquipmentIndexOfQuality.Invoke(null, new object[2] { current, obj });
						EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(val);
						if (Object.op_Implicit((Object)(object)equipmentDef))
						{
							baseEquipmentByVariant[current] = equipmentDef;
						}
					}
				}
			}
			finally
			{
				((IDisposable)(*(AllEquipmentEnumerator*)(&enumerator))/*cast due to .constrained prefix*/).Dispose();
			}
		}
		catch (Exception ex)
		{
			qualityByEquipment.Clear();
			baseEquipmentByVariant.Clear();
			getEquipmentQualityTier = null;
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not read the Quality equipment catalog. " + ex.Message));
		}
	}

	private void FindQualityPlugin()
	{
		if (!Chainloader.PluginInfos.TryGetValue("com.Gorakh.ItemQualities", out var value) || !Object.op_Implicit((Object)(object)value.Instance))
		{
			return;
		}
		Type type = ((object)value.Instance).GetType().Assembly.GetType("ItemQualities.QualityCatalog");
		qualityAvailability = type?.GetField("Availability");
		MethodInfo methodInfo = type?.GetMethod("GetQualityTier", new Type[1] { typeof(ItemIndex) });
		if (qualityAvailability?.FieldType == typeof(ResourceAvailability) && methodInfo != null && methodInfo.ReturnType.IsEnum && HasQualityValue(methodInfo.ReturnType, "None", -1) && HasQualityValue(methodInfo.ReturnType, "Uncommon", 0) && HasQualityValue(methodInfo.ReturnType, "Rare", 1) && HasQualityValue(methodInfo.ReturnType, "Epic", 2) && HasQualityValue(methodInfo.ReturnType, "Legendary", 3))
		{
			getQualityTier = methodInfo;
			MethodInfo method = type.GetMethod("GetQualityTier", new Type[1] { typeof(EquipmentIndex) });
			if (method?.ReturnType == methodInfo.ReturnType)
			{
				getEquipmentQualityTier = method;
			}
			MethodInfo method2 = type.GetMethod("GetEquipmentIndexOfQuality", new Type[2]
			{
				typeof(EquipmentIndex),
				methodInfo.ReturnType
			});
			if (method2?.ReturnType == typeof(EquipmentIndex))
			{
				getEquipmentIndexOfQuality = method2;
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"This version of Quality does not expose the expected item catalog.");
		}
	}

	private static bool HasQualityValue(Type enumType, string name, int value)
	{
		return Enum.IsDefined(enumType, name) && Convert.ToInt32(Enum.Parse(enumType, name)) == value;
	}

	internal QueueGroup GetQueueGroup(ItemDef item)
	{
		//IL_0010: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		if (QualitySupported && qualityByItem.TryGetValue(item.itemIndex, out var value))
		{
			return new QueueGroup(item.tier, value);
		}
		return new QueueGroup(item.tier, (qualityPackItems.Contains(item) && !qualityIndexed) ? QualityLevel.Unknown : QualityLevel.Standard);
	}

	internal QueueGroup GetQueueGroup(EquipmentDef equipment)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		if (QualitySupported && qualityByEquipment.TryGetValue(equipment.equipmentIndex, out var value))
		{
			return new QueueGroup(GetBaseEquipment(equipment), value);
		}
		return new QueueGroup(equipment, (qualityPackEquipment.Contains(equipment) && (!qualityIndexed || getEquipmentQualityTier == null)) ? QualityLevel.Unknown : QualityLevel.Standard);
	}

	private EquipmentDef GetBaseEquipment(EquipmentDef equipment)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		EquipmentDef value;
		return baseEquipmentByVariant.TryGetValue(equipment.equipmentIndex, out value) ? value : equipment;
	}

	private static QualityLevels SingleQualityLevelOrAll(QualityLevels levels)
	{
		if ((uint)(levels - 1) <= 1u || levels == QualityLevels.Epic || levels == QualityLevels.Legendary)
		{
			return levels;
		}
		return QualityLevels.All;
	}

	internal static QualityLevels LevelFlag(QualityLevel level)
	{
		return (QualityLevels)(1 << (int)(level - 1));
	}

	private void FindLookingGlassPlugin()
	{
		if (!Chainloader.PluginInfos.TryGetValue("droppod.lookingglass", out var value) || !Object.op_Implicit((Object)(object)value.Instance))
		{
			return;
		}
		try
		{
			Type type = ((object)value.Instance).GetType().Assembly.GetType("LookingGlass.ItemStatsNameSpace.ItemStats");
			lookingGlassFullDescriptions = type?.GetField("fullDescInHud")?.GetValue(null) as ConfigEntry<bool>;
			MethodInfo methodInfo = type?.GetMethod("GetItemDescription", new Type[5]
			{
				typeof(ItemDef),
				typeof(int),
				typeof(CharacterMaster),
				typeof(bool),
				typeof(bool)
			});
			if (methodInfo?.ReturnType == typeof(string) && methodInfo.IsStatic)
			{
				lookingGlassItemDescription = (Func<ItemDef, int, CharacterMaster, bool, bool, string>)methodInfo.CreateDelegate(typeof(Func<ItemDef, int, CharacterMaster, bool, bool, string>));
			}
			MethodInfo methodInfo2 = type?.GetMethod("GetEquipmentExtras", new Type[2]
			{
				typeof(CharacterMaster),
				typeof(EquipmentIndex)
			});
			if (methodInfo2?.ReturnType == typeof(string) && methodInfo2.IsStatic)
			{
				lookingGlassEquipmentExtras = (Func<CharacterMaster, EquipmentIndex, string>)methodInfo2.CreateDelegate(typeof(Func<CharacterMaster, EquipmentIndex, string>));
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not initialize LookingGlass item details. " + ex.GetBaseException().Message));
		}
	}

	internal string GetLookingGlassDescription(ItemDef item, EquipmentDef equipment, CharacterMaster master, string description)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)master) && Object.op_Implicit((Object)(object)master.inventory))
		{
			ConfigEntry<bool> obj = lookingGlassFullDescriptions;
			if (obj == null || obj.Value)
			{
				try
				{
					if (Object.op_Implicit((Object)(object)item) && lookingGlassItemDescription != null)
					{
						int itemCountEffective = master.inventory.GetItemCountEffective(item.itemIndex);
						string text = lookingGlassItemDescription(item, itemCountEffective, master, itemCountEffective == 0, arg5: false);
						if (!string.IsNullOrEmpty(text))
						{
							return text;
						}
					}
					else if (Object.op_Implicit((Object)(object)equipment) && lookingGlassEquipmentExtras != null)
					{
						string text2 = lookingGlassEquipmentExtras(master, equipment.equipmentIndex);
						if (!string.IsNullOrWhiteSpace(text2))
						{
							return description + "\n\n" + text2.TrimStart(Array.Empty<char>());
						}
					}
				}
				catch (Exception ex)
				{
					if (!loggedLookingGlassDescriptionFailure)
					{
						loggedLookingGlassDescriptionFailure = true;
						((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not format a LookingGlass description. " + ex.GetBaseException().Message));
					}
				}
				return description;
			}
		}
		return description;
	}

	private void OpenBrowser()
	{
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Expected O, but got Unknown
		if (!Object.op_Implicit((Object)(object)scoreboard) || !((Behaviour)scoreboard).isActiveAndEnabled)
		{
			scoreboard = Object.FindObjectOfType<ScoreboardController>();
		}
		if (!Object.op_Implicit((Object)(object)scoreboard) || !Object.op_Implicit((Object)(object)Run.instance))
		{
			return;
		}
		if ((Object)(object)queueRun != (Object)(object)Run.instance)
		{
			queueRun = Run.instance;
			queues = new TierQueues<QueueGroup, PickupIndex>();
		}
		if (!Object.op_Implicit((Object)(object)queueView))
		{
			GameObject val = new GameObject("CommandQueueView", new Type[1] { typeof(RectTransform) });
			val.SetActive(false);
			val.layer = ((Component)scoreboard).gameObject.layer;
			val.transform.SetParent(((Component)scoreboard).transform, false);
			try
			{
				NativeQueueView nativeQueueView = val.AddComponent<NativeQueueView>();
				nativeQueueView.Initialize(this, scoreboard);
				if (Object.op_Implicit((Object)(object)((Component)scoreboard).GetComponentInParent<MPEventSystemProvider>()))
				{
					val.AddComponent<MPEventSystemLocator>();
					val.AddComponent<CursorOpener>();
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find the scoreboard's event system for the queue cursor.");
				}
				val.SetActive(true);
				queueView = nativeQueueView;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not create the Command Queue scoreboard view: " + ex));
				Object.Destroy((Object)(object)val);
				return;
			}
		}
		try
		{
			queueView.Open();
		}
		catch (Exception ex2)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Could not open the Command Queue scoreboard view: " + ex2));
			((Component)queueView).gameObject.SetActive(false);
			Object.Destroy((Object)(object)((Component)queueView).gameObject);
			queueView = null;
		}
	}

	private void InstallPickerHook()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Expected O, but got Unknown
		active = this;
		pickerHarmony.Patch((MethodBase)AccessTools.PropertySetter(typeof(NetworkUIPromptController), "currentCamera"), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "DeferCommandPickerDisplay", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
		pickerHarmony.Patch((MethodBase)AccessTools.Method(typeof(PickupPickerController), "RpcHandlePickupSelected", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "OnNativeSelectionAcknowledged", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		pickerHarmony.Patch((MethodBase)AccessTools.Method(typeof(GenericPickupController), "OnStartClient", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "OnNativePickupSpawned", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		GlobalEventManager.onCharacterPickupItem += OnNativePickupReceived;
	}

	private void RemovePickerHook()
	{
		pickerHarmony.UnpatchSelf();
		GlobalEventManager.onCharacterPickupItem -= OnNativePickupReceived;
		pendingPickers.Clear();
		guestSelections.Clear();
		active = null;
	}

	private static IEnumerable<CodeInstruction> DeferCommandPickerDisplay(IEnumerable<CodeInstruction> instructions)
	{
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		FieldInfo displayBegin = AccessTools.Field(typeof(NetworkUIPromptController), "onDisplayBegin");
		MethodInfo invoke = AccessTools.Method(typeof(Action<NetworkUIPromptController, LocalUser, CameraRigController>), "Invoke", (Type[])null, (Type[])null);
		int num = ((displayBegin == null) ? (-1) : list.FindIndex((CodeInstruction instruction) => CodeInstructionExtensions.LoadsField(instruction, displayBegin, false)));
		int num2 = ((num < 0) ? (-1) : list.FindIndex(num + 1, (CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, invoke)));
		if (num2 < 0 || list.FindLastIndex((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, invoke)) != num2)
		{
			if (Object.op_Implicit((Object)(object)active))
			{
				((BaseUnityPlugin)active).Logger.LogWarning((object)"Using the manual Command picker because the prompt display hook changed.");
			}
			return list;
		}
		list[num2].opcode = OpCodes.Call;
		list[num2].operand = AccessTools.Method(typeof(Plugin), "DispatchPickerDisplay", (Type[])null, (Type[])null);
		return list;
	}

	private static void DispatchPickerDisplay(Action<NetworkUIPromptController, LocalUser, CameraRigController> display, NetworkUIPromptController prompt, LocalUser user, CameraRigController camera)
	{
		if (!Object.op_Implicit((Object)(object)active) || !active.TryDeferPickerDisplay(display, prompt, user, camera))
		{
			display(prompt, user, camera);
		}
	}

	private bool TryDeferPickerDisplay(Action<NetworkUIPromptController, LocalUser, CameraRigController> display, NetworkUIPromptController prompt, LocalUser user, CameraRigController camera)
	{
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		Run instance = Run.instance;
		if ((Object)(object)queueRun != (Object)(object)instance || !Object.op_Implicit((Object)(object)prompt) || user == null || !Object.op_Implicit((Object)(object)camera) || localParticipantGetter == null || promptCameraGetter == null || (!NetworkServer.active && !NetworkClient.active))
		{
			return false;
		}
		PickupPickerController component = ((Component)prompt).GetComponent<PickupPickerController>();
		if (!Object.op_Implicit((Object)(object)component) || component.isDelusionChoice || component.isRebirthChoice || component.options == null)
		{
			return false;
		}
		if (pendingPickers.TryGetValue(component, out var value))
		{
			return value == camera;
		}
		GameObject commandCubePrefab = CommandArtifactManager.commandCubePrefab;
		PickupPickerController val = (Object.op_Implicit((Object)(object)commandCubePrefab) ? commandCubePrefab.GetComponent<PickupPickerController>() : null);
		if (!Object.op_Implicit((Object)(object)val) || !IsCommandPicker(component, val))
		{
			return false;
		}
		if (!TryGetPickerGroup(component, component.options, out var group) || guestSelections.ContainsKey(group))
		{
			return false;
		}
		TierQueues<QueueGroup, PickupIndex>.Entry entry = queues.PeekEntry(group);
		if (entry == null || FindAvailableOption(component.options, entry.Item) < 0)
		{
			return false;
		}
		pendingPickers.Add(component, camera);
		try
		{
			((MonoBehaviour)this).StartCoroutine(SubmitQueuedChoice(component, prompt, user, camera, display, entry, queues, instance, Stage.instance));
			return true;
		}
		catch (Exception ex)
		{
			pendingPickers.Remove(component);
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not start the queued Command selection. " + ex.GetBaseException().Message));
			return false;
		}
	}

	private static bool IsCommandPicker(PickupPickerController picker, PickupPickerController cubePrefab)
	{
		//IL_004a: 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_005b: 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)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)cubePrefab.panelPrefab != (Object)null && (Object)(object)picker.panelPrefab == (Object)(object)cubePrefab.panelPrefab)
		{
			return true;
		}
		NetworkIdentity component = ((Component)cubePrefab).GetComponent<NetworkIdentity>();
		NetworkIdentity component2 = ((Component)picker).GetComponent<NetworkIdentity>();
		int result;
		if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component2))
		{
			NetworkHash128 assetId = component.assetId;
			if (((NetworkHash128)(ref assetId)).IsValid())
			{
				assetId = component.assetId;
				result = (((NetworkHash128)(ref assetId)).Equals(component2.assetId) ? 1 : 0);
				goto IL_0072;
			}
		}
		result = 0;
		goto IL_0072;
		IL_0072:
		return (byte)result != 0;
	}

	internal bool TryGetPickupGroup(PickupIndex pickupIndex, out QueueGroup group)
	{
		//IL_0008: 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_0044: Unknown result type (might be due to invalid IL or missing references)
		group = default(QueueGroup);
		PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
		if (pickupDef == null)
		{
			return false;
		}
		ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);
		if (Object.op_Implicit((Object)(object)itemDef))
		{
			group = GetQueueGroup(itemDef);
		}
		else
		{
			EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex);
			if (!Object.op_Implicit((Object)(object)equipmentDef))
			{
				return false;
			}
			group = GetQueueGroup(equipmentDef);
		}
		return group.Quality != QualityLevel.Unknown;
	}

	private bool TryGetPickerGroup(PickupPickerController picker, Option[] options, out QueueGroup group)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		group = default(QueueGroup);
		PickupIndex pickupIndex = picker.GetPickupIndex();
		if (!((PickupIndex)(ref pickupIndex)).isValid)
		{
			PickupIndexNetworker component = ((Component)picker).GetComponent<PickupIndexNetworker>();
			if (Object.op_Implicit((Object)(object)component))
			{
				pickupIndex = component.pickupState.pickupIndex;
			}
		}
		if (((PickupIndex)(ref pickupIndex)).isValid)
		{
			return TryGetPickupGroup(pickupIndex, out group);
		}
		bool flag = false;
		foreach (Option val in options)
		{
			if (!TryGetPickupGroup(val.pickup.pickupIndex, out var group2) || (flag && !group.Equals(group2)))
			{
				return false;
			}
			group = group2;
			flag = true;
		}
		return flag;
	}

	private static int FindAvailableOption(Option[] options, PickupIndex pickup)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		if (options == null)
		{
			return -1;
		}
		for (int i = 0; i < options.Length; i++)
		{
			if (options[i].available && options[i].pickup.pickupIndex == pickup)
			{
				return i;
			}
		}
		return -1;
	}

	private IEnumerator SubmitQueuedChoice(PickupPickerController picker, NetworkUIPromptController prompt, LocalUser user, CameraRigController camera, Action<NetworkUIPromptController, LocalUser, CameraRigController> display, TierQueues<QueueGroup, PickupIndex>.Entry entry, TierQueues<QueueGroup, PickupIndex> queue, Run run, Stage stage)
	{
		yield return null;
		GuestSelection guest = null;
		bool confirmed = false;
		try
		{
			QueueGroup group = entry.Tier;
			if (!IsCurrentDisplay(picker, prompt, user, camera, run, stage) || queues != queue || picker.options == null || !TryGetPickerGroup(picker, picker.options, out var currentGroup) || !group.Equals(currentGroup) || queue.PeekEntry(group) != entry)
			{
				yield break;
			}
			int index = FindAvailableOption(picker.options, entry.Item);
			if (index < 0)
			{
				yield break;
			}
			if (!NetworkServer.active)
			{
				if (!NetworkClient.active || guestSelections.ContainsKey(group))
				{
					yield break;
				}
				guest = new GuestSelection(picker, prompt, user, index, entry, run, stage);
				guestSelections.Add(group, guest);
				if (!TrySendNativeSelection(prompt, index))
				{
					yield break;
				}
				while (guest.CanWait && queues == queue)
				{
					if (guest.IsConfirmed)
					{
						confirmed = true;
						queue.ConsumeEntry(entry);
						break;
					}
					yield return null;
				}
				yield break;
			}
			UniquePickupUnityEvent selected = picker.onUniquePickupSelected;
			if (selected == null || nativeServerSelection == null)
			{
				yield break;
			}
			UnityAction<UniquePickup> confirm = delegate(UniquePickup value)
			{
				//IL_0001: 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_000d: Unknown result type (might be due to invalid IL or missing references)
				if (!(value.pickupIndex != entry.Item))
				{
					confirmed = true;
					queue.ConsumeEntry(entry);
				}
			};
			((UnityEvent<UniquePickup>)(object)selected).AddListener(confirm);
			try
			{
				nativeServerSelection.Invoke(picker, new object[1] { index });
			}
			catch (Exception ex)
			{
				Exception exception = ex;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not finish the queued Command selection. " + exception.GetBaseException().Message));
			}
			finally
			{
				((UnityEvent<UniquePickup>)(object)selected).RemoveListener(confirm);
			}
		}
		finally
		{
			if (guest != null)
			{
				guestSelections.Remove(entry.Tier);
			}
			pendingPickers.Remove(picker);
			if (!confirmed && IsCurrentDisplay(picker, prompt, user, camera, run, stage))
			{
				display(prompt, user, camera);
			}
		}
	}

	private static bool IsCurrentDisplay(PickupPickerController picker, NetworkUIPromptController prompt, LocalUser user, CameraRigController camera, Run run, Stage stage)
	{
		return Object.op_Implicit((Object)(object)picker) && Object.op_Implicit((Object)(object)prompt) && Object.op_Implicit((Object)(object)camera) && (NetworkServer.active || NetworkClient.active) && Stage.instance == stage && Run.instance == run && localParticipantGetter.Invoke(prompt, null) == user && promptCameraGetter.Invoke(prompt, null) == camera;
	}

	private bool TrySendNativeSelection(NetworkUIPromptController prompt, int index)
	{
		try
		{
			NetworkWriter val = prompt.BeginMessageToServer();
			val.Write((byte)0);
			val.Write(index);
			prompt.FinishMessageToServer(val);
			return true;
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not send the queued Command selection. " + ex.GetBaseException().Message));
			return false;
		}
	}

	private static void OnNativeSelectionAcknowledged(PickupPickerController __instance, int __0)
	{
		//IL_0088: 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)
		if (!Object.op_Implicit((Object)(object)active) || NetworkServer.active)
		{
			return;
		}
		foreach (GuestSelection value in active.guestSelections.Values)
		{
			if (!value.CanWait || (Object)(object)value.Picker != (Object)(object)__instance || value.Index != __0)
			{
				continue;
			}
			Option[] options = __instance.options;
			if (options != null && __0 < options.Length && options[__0].pickup.pickupIndex == value.Entry.Item)
			{
				value.Acknowledged = true;
			}
			break;
		}
	}

	private static void OnNativePickupSpawned(GenericPickupController __instance)
	{
		//IL_0054: 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)
		if (!Object.op_Implicit((Object)(object)active) || NetworkServer.active || active.guestSelections.Count == 0)
		{
			return;
		}
		GuestSelection guestSelection = null;
		foreach (GuestSelection value in active.guestSelections.Values)
		{
			if (value.MatchesDrop(__instance.pickup, ((Component)__instance).transform.position))
			{
				if (guestSelection != null)
				{
					return;
				}
				guestSelection = value;
			}
		}
		if (guestSelection != null)
		{
			guestSelection.SawResult = true;
		}
	}

	private void OnNativePickupReceived(CharacterBody body, PickupIndex pickup, int count)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		if (NetworkServer.active || !Object.op_Implicit((Object)(object)body) || count <= 0)
		{
			return;
		}
		GuestSelection guestSelection = null;
		foreach (GuestSelection value in guestSelections.Values)
		{
			if (value.CanWait && value.DirectGrant && !(value.Entry.Item != pickup) && !((Object)(object)value.Master != (Object)(object)body.master))
			{
				if (guestSelection != null)
				{
					return;
				}
				guestSelection = value;
			}
		}
		if (guestSelection != null)
		{
			guestSelection.SawResult = true;
		}
	}

	private void InstallInputHooks()
	{
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Expected O, but got Unknown
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Expected O, but got Unknown
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Expected O, but got Unknown
		//IL_01a0: Expected O, but got Unknown
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Expected O, but got Unknown
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Expected O, but got Unknown
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Expected O, but got Unknown
		//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Expected O, but got Unknown
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Expected O, but got Unknown
		Type typeFromHandle = typeof(PlayerCharacterMasterController);
		suppressPrimary = CreateButtonSuppressor("skill1");
		suppressSecondary = CreateButtonSuppressor("skill2");
		suppressControllerActions = CreateButtonSuppressor("skill1", "skill2", "skill3", "skill4", "jump", "interact", "activateEquipment", "activateKeyItem", "ping", "keyItemNextElement", "keyItemPrevElement");
		HarmonyMethod val = new HarmonyMethod(typeof(Plugin), "AllowScoreboardMovement", (Type[])null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeFromHandle, "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeFromHandle, "CanSendBodyInput", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeof(CameraRigController), "GenerateCameraModeContext", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeFromHandle, "PollInputToButtonBuffers", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "BlockQueueAttacks", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeof(MPEventSystem), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin), "UpdateControllerFocus", (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "PreventPauseAfterControllerAction", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeof(MPEventSystem), "SetCursorIndicatorEnabled", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin), "HideControllerQueueCursor", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeof(MPButton), "FindSelectableOnUp", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "NavigateFromScoreboard", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeof(RewiredStandaloneInputModule), "SendSubmitEventToSelectedObject", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin), "AllowNativeSubmit", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeof(NetworkUIPromptController), "OnControlBegin", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "TrackControllerPrompt", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeof(NetworkUIPromptController), "OnControlEnd", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "UntrackControllerPrompt", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		inputHarmony.Patch((MethodBase)AccessTools.Method(typeof(HUD), "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "ToggleControllerScoreboard", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static IEnumerable<CodeInstruction> ToggleControllerScoreboard(IEnumerable<CodeInstruction> instructions)
	{
		FieldInfo forceToggle = AccessTools.Field(typeof(HUD), "shouldForceScoreboardToggle");
		MethodInfo setState = AccessTools.Method(typeof(HUD), "SetScoreboardState", (Type[])null, (Type[])null);
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		int num = list.FindIndex((CodeInstruction instruction) => CodeInstructionExtensions.LoadsField(instruction, forceToggle, false));
		int num2 = list.FindIndex((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, setState));
		if (num < 0 || num2 <= num || list.FindLastIndex((CodeInstruction instruction) => CodeInstructionExtensions.LoadsField(instruction, forceToggle, false)) != num || list.FindLastIndex((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, setState)) != num2)
		{
			if (Object.op_Implicit((Object)(object)active))
			{
				((BaseUnityPlugin)active).Logger.LogWarning((object)"Using native scoreboard controls because the controller toggle hook changed.");
			}
			return list;
		}
		list[num].opcode = OpCodes.Call;
		list[num].operand = AccessTools.Method(typeof(Plugin), "ShouldToggleScoreboard", (Type[])null, (Type[])null);
		list[num2].opcode = OpCodes.Call;
		list[num2].operand = AccessTools.Method(typeof(Plugin), "SetScoreboardFromBinding", (Type[])null, (Type[])null);
		return list;
	}

	private static bool ShouldToggleScoreboard(HUD hud)
	{
		return hud.shouldForceScoreboardToggle || IsControllerScoreboardPress(hud);
	}

	private static bool IsControllerScoreboardPress(HUD hud)
	{
		LocalUser localUserViewer = hud.localUserViewer;
		Player val = ((localUserViewer != null) ? localUserViewer.inputPlayer : null);
		return Object.op_Implicit((Object)(object)active) && Object.op_Implicit((Object)(object)Run.instance) && val != null && val.GetButtonDown("info") && val.IsCurrentInputSource("info", (ControllerType)2) && !active.HasBlockingControllerPrompt(localUserViewer);
	}

	private static void SetScoreboardFromBinding(HUD hud, bool open)
	{
		bool flag = open && IsControllerScoreboardPress(hud);
		hud.SetScoreboardState(open);
		if (flag && hud.scoreboardPanel.activeSelf)
		{
			hud.shouldForceScoreboardToggle = true;
			if (Object.op_Implicit((Object)(object)active.queueView) && ((Component)active.queueView).transform.IsChildOf(hud.scoreboardPanel.transform))
			{
				active.queueView.OpenQueueFromController();
			}
		}
	}

	private static Action<PlayerCharacterMasterController> CreateButtonSuppressor(params string[] buttonNames)
	{
		Type typeFromHandle = typeof(PlayerCharacterMasterController);
		FieldInfo fieldInfo = AccessTools.Field(typeFromHandle, "buttonBuffers");
		DynamicMethod dynamicMethod = new DynamicMethod("CommandQueueSuppress_" + buttonNames[0], typeof(void), new Type[1] { typeFromHandle }, typeof(Plugin), skipVisibility: true);
		ILGenerator iLGenerator = dynamicMethod.GetILGenerator();
		foreach (string text in buttonNames)
		{
			FieldInfo fieldInfo2 = AccessTools.Field(fieldInfo.FieldType, text);
			MethodInfo meth = AccessTools.Method(fieldInfo2.FieldType, "SuppressUntilReleased", (Type[])null, (Type[])null);
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Ldflda, fieldInfo);
			iLGenerator.Emit(OpCodes.Ldflda, fieldInfo2);
			iLGenerator.Emit(OpCodes.Call, meth);
		}
		iLGenerator.Emit(OpCodes.Ret);
		return (Action<PlayerCharacterMasterController>)dynamicMethod.CreateDelegate(typeof(Action<PlayerCharacterMasterController>));
	}

	private void RemoveInputHooks()
	{
		inputHarmony.UnpatchSelf();
		suppressPrimary = null;
		suppressSecondary = null;
		suppressControllerActions = null;
		controllerPrompts.Clear();
	}

	private static IEnumerable<CodeInstruction> AllowScoreboardMovement(IEnumerable<CodeInstruction> instructions, MethodBase original)
	{
		MethodInfo getter = AccessTools.PropertyGetter(typeof(LocalUser), "isUIFocused");
		MethodInfo operand = AccessTools.Method(typeof(Plugin), (original.DeclaringType == typeof(CameraRigController)) ? "CameraIsFocused" : "GameplayIsFocused", (Type[])null, (Type[])null);
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		int count = list.FindAll((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, getter)).Count;
		if (count != 1)
		{
			if (Object.op_Implicit((Object)(object)active))
			{
				((BaseUnityPlugin)active).Logger.LogWarning((object)("Using native input focus for " + original.Name + " because its input hook changed."));
			}
			return list;
		}
		foreach (CodeInstruction item in list)
		{
			if (!CodeInstructionExtensions.Calls(item, getter))
			{
				continue;
			}
			item.opcode = OpCodes.Call;
			item.operand = operand;
			break;
		}
		return list;
	}

	private static bool GameplayIsFocused(LocalUser user)
	{
		return user.isUIFocused && !IsQueueInput(user) && !HasStaleQueueFocus(user);
	}

	private static bool CameraIsFocused(LocalUser user)
	{
		return IsControllerQueue(user.eventSystem) ? active.UseRightStick : user.isUIFocused;
	}

	private static bool IsControllerQueue(MPEventSystem owner)
	{
		return Object.op_Implicit((Object)(object)active) && Object.op_Implicit((Object)(object)active.queueView) && (Object)(object)active.queueView.EventSystem == (Object)(object)owner && active.queueView.UsesControllerNavigation && active.queueView.HasScoreboardOwnership();
	}

	private static void HideControllerQueueCursor(MPEventSystem __instance, ref bool __0)
	{
		if (__0 && IsControllerQueue(__instance))
		{
			__0 = false;
		}
	}

	private static bool HasStaleQueueFocus(LocalUser user)
	{
		if (!Object.op_Implicit((Object)(object)active) || !Object.op_Implicit((Object)(object)active.queueView) || Object.op_Implicit((Object)(object)user.pauseScreenController) || active.HasBlockingControllerPrompt(user))
		{
			return false;
		}
		MPEventSystem eventSystem = user.eventSystem;
		return Object.op_Implicit((Object)(object)eventSystem) && active.queueView.HasJustClosedFor(eventSystem) && eventSystem.cursorOpenerCount == 0 && eventSystem.cursorOpenerForGamepadCount == 0 && !Object.op_Implicit((Object)(object)((EventSystem)eventSystem).currentSelectedGameObject);
	}

	private static bool IsQueueInput(LocalUser user)
	{
		return Object.op_Implicit((Object)(object)active) && Object.op_Implicit((Object)(object)active.queueView) && user != null && Object.op_Implicit((Object)(object)user.eventSystem) && (Object)(object)active.queueView.EventSystem == (Object)(object)user.eventSystem && active.queueView.HasScoreboardOwnership();
	}

	private static void BlockQueueAttacks(PlayerCharacterMasterController __instance)
	{
		NetworkUser networkUser = __instance.networkUser;
		if (!Object.op_Implicit((Object)(object)networkUser) || networkUser.localUser == null)
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)active) && Object.op_Implicit((Object)(object)active.queueView) && active.queueView.ShouldBlockControllerGameplay(networkUser.localUser.eventSystem))
		{
			suppressControllerActions(__instance);
		}
		else if (IsQueueInput(networkUser.localUser))
		{
			suppressPrimary(__instance);
			if (active.queueView.IsQueueTabVisible)
			{
				suppressSecondary(__instance);
			}
		}
	}

	private static void UpdateControllerFocus(MPEventSystem __instance)
	{
		if (Object.op_Implicit((Object)(object)active) && Object.op_Implicit((Object)(object)active.queueView))
		{
			active.queueView.UpdateController(__instance);
		}
	}

	private static void NavigateFromScoreboard(MPButton __instance, ref Selectable __result)
	{
		if (Object.op_Implicit((Object)(object)active) && Object.op_Implicit((Object)(object)active.queueView))
		{
			__result = active.queueView.NavigateUpFromPlayers(__instance, __result);
		}
	}

	private static bool AllowNativeSubmit(RewiredStandaloneInputModule __instance)
	{
		return !Object.op_Implicit((Object)(object)active) || !Object.op_Implicit((Object)(object)active.queueView) || !active.queueView.ConsumedControllerAction || !Object.op_Implicit((Object)(object)active.queueView.EventSystem) || (Object)(object)((EventSystem)active.queueView.EventSystem).currentInputModule != (Object)(object)__instance;
	}

	private static IEnumerable<CodeInstruction> PreventPauseAfterControllerAction(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo getButtonDown = AccessTools.Method(typeof(Player), "GetButtonDown", new Type[1] { typeof(int) }, (Type[])null);
		MethodInfo allowPause = AccessTools.Method(typeof(Plugin), "AllowNativePause", (Type[])null, (Type[])null);
		CodeInstruction previous = null;
		foreach (CodeInstruction instruction in instructions)
		{
			yield return instruction;
			if (previous != null && CodeInstructionExtensions.LoadsConstant(previous, 25L) && CodeInstructionExtensions.Calls(instruction, getButtonDown))
			{
				yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				yield return new CodeInstruction(OpCodes.Call, (object)allowPause);
			}
			previous = instruction;
		}
	}

	private static bool AllowNativePause(bool pressed, MPEventSystem owner)
	{
		return pressed && (!Object.op_Implicit((Object)(object)active) || !Object.op_Implicit((Object)(object)active.queueView) || (Object)(object)active.queueView.EventSystem != (Object)(object)owner || !active.queueView.ConsumedControllerPauseBinding);
	}

	private static void TrackControllerPrompt(NetworkUIPromptController __instance)
	{
		if (Object.op_Implicit((Object)(object)active))
		{
			object? obj = localParticipantGetter.Invoke(__instance, null);
			LocalUser val = (LocalUser)((obj is LocalUser) ? obj : null);
			if (val != null)
			{
				active.controllerPrompts[__instance] = val;
			}
		}
	}

	private static void UntrackControllerPrompt(NetworkUIPromptController __instance)
	{
		if (Object.op_Implicit((Object)(object)active))
		{
			active.controllerPrompts.Remove(__instance);
		}
	}

	internal bool HasBlockingControllerPrompt(LocalUser user)
	{
		foreach (KeyValuePair<NetworkUIPromptController, LocalUser> controllerPrompt in controllerPrompts)
		{
			if (controllerPrompt.Value == user && Object.op_Implicit((Object)(object)controllerPrompt.Key) && controllerPrompt.Key.isDisplaying)
			{
				return true;
			}
		}
		foreach (SimpleDialogBox instances in SimpleDialogBox.instancesList)
		{
			if (Object.op_Implicit((Object)(object)instances) && Object.op_Implicit((Object)(object)instances.rootObject) && instances.rootObject.activeInHierarchy)
			{
				MPEventSystemLocator componentInChildren = instances.rootObject.GetComponentInChildren<MPEventSystemLocator>();
				if (!Object.op_Implicit((Object)(object)componentInChildren) || !Object.op_Implicit((Object)(object)componentInChildren.eventSystem) || (Object)(object)componentInChildren.eventSystem == (Object)(object)user.eventSystem)
				{
					return true;
				}
			}
		}
		return false;
	}
}
internal sealed class TierQueues<TTier, TItem>
{
	public sealed class Entry
	{
		public TTier Tier { get; }

		public TItem Item { get; }

		internal Entry(TTier tier, TItem item)
		{
			Tier = tier;
			Item = item;
		}
	}

	internal readonly struct Stack
	{
		internal TItem Item { get; }

		internal int StartIndex { get; }

		internal int Count { get; }

		internal Stack(TItem item, int startIndex, int count)
		{
			Item = item;
			StartIndex = startIndex;
			Count = count;
		}
	}

	private readonly Dictionary<TTier, List<TItem>> queues = new Dictionary<TTier, List<TItem>>();

	private readonly List<Entry> allItems = new List<Entry>();

	private static readonly TItem[] empty = new TItem[0];

	public int Version { get; private set; }

	public int Add(TTier tier, TItem item)
	{
		if (!queues.TryGetValue(tier, out var value))
		{
			value = new List<TItem>();
			queues.Add(tier, value);
		}
		value.Add(item);
		allItems.Add(new Entry(tier, item));
		Version++;
		return value.Count;
	}

	public bool TryPeek(TTier tier, out TItem item)
	{
		if (queues.TryGetValue(tier, out var value) && value.Count > 0)
		{
			item = value[0];
			return true;
		}
		item = default(TItem);
		return false;
	}

	internal Entry PeekEntry(TTier tier)
	{
		foreach (Entry allItem in allItems)
		{
			if (EqualityComparer<TTier>.Default.Equals(allItem.Tier, tier))
			{
				return allItem;
			}
		}
		return null;
	}

	internal bool ConsumeEntry(Entry entry)
	{
		return entry != null && PeekEntry(entry.Tier) == entry && Consume(entry.Tier, entry.Item);
	}

	public bool Consume(TTier tier, TItem confirmedItem)
	{
		if (!TryPeek(tier, out var item) || !EqualityComparer<TItem>.Default.Equals(item, confirmedItem))
		{
			return false;
		}
		queues[tier].RemoveAt(0);
		RemoveOverallEntry(tier, 0);
		Version++;
		return true;
	}

	public IReadOnlyList<TItem> GetItems(TTier tier)
	{
		if (queues.TryGetValue(tier, out var value))
		{
			return value;
		}
		return empty;
	}

	public IReadOnlyList<Entry> GetAllItems()
	{
		return allItems;
	}

	internal void CopyStacksTo(List<Stack> stacks)
	{
		stacks.Clear();
		int num = 0;
		while (num < allItems.Count)
		{
			int num2 = FindStackEnd(num);
			stacks.Add(new Stack(allItems[num].Item, num, num2 - num));
			num = num2;
		}
	}

	private int FindStackEnd(int start)
	{
		Entry entry = allItems[start];
		int i;
		for (i = start + 1; i < allItems.Count && EqualityComparer<TTier>.Default.Equals(entry.Tier, allItems[i].Tier) && EqualityComparer<TItem>.Default.Equals(entry.Item, allItems[i].Item); i++)
		{
		}
		return i;
	}

	public bool RemoveAtOverall(int index, bool wholeStack = false)
	{
		if (index < 0 || index >= allItems.Count)
		{
			return false;
		}
		TTier tier = allItems[index].Tier;
		int count = ((!wholeStack) ? 1 : (FindStackEnd(index) - index));
		int num = 0;
		for (int i = 0; i < index; i++)
		{
			if (EqualityComparer<TTier>.Default.Equals(allItems[i].Tier, tier))
			{
				num++;
			}
		}
		queues[tier].RemoveRange(num, count);
		allItems.RemoveRange(index, count);
		Version++;
		return true;
	}

	public bool RemoveAt(TTier tier, int index)
	{
		if (!queues.TryGetValue(tier, out var value) || index < 0 || index >= value.Count)
		{
			return false;
		}
		value.RemoveAt(index);
		RemoveOverallEntry(tier, index);
		Version++;
		return true;
	}

	private void RemoveOverallEntry(TTier tier, int tierIndex)
	{
		for (int i = 0; i < allItems.Count; i++)
		{
			if (EqualityComparer<TTier>.Default.Equals(allItems[i].Tier, tier) && tierIndex-- == 0)
			{
				allItems.RemoveAt(i);
				break;
			}
		}
	}
}
internal enum QualityLevel
{
	Unknown = -1,
	Standard,
	Uncommon,
	Rare,
	Epic,
	Legendary
}
internal readonly struct QueueGroup : IEquatable<QueueGroup>
{
	private enum Kind
	{
		Item,
		Equipment,
		LunarEquipment,
		BossEquipment
	}

	private readonly Kind kind;

	internal ItemTier Tier { get; }

	internal QualityLevel Quality { get; }

	internal QueueGroup(ItemTier tier, QualityLevel quality = QualityLevel.Standard)
		: this(Kind.Item, tier, quality)
	{
	}//IL_0002: Unknown result type (might be due to invalid IL or missing references)


	internal QueueGroup(EquipmentDef equipment, QualityLevel quality = QualityLevel.Standard)
		: this(equipment.isLunar ? Kind.LunarEquipment : ((!equipment.isBoss) ? Kind.Equipment : Kind.BossEquipment), (ItemTier)0, quality)
	{
	}

	private QueueGroup(Kind kind, ItemTier tier, QualityLevel quality)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		this.kind = kind;
		Tier = tier;
		Quality = quality;
	}

	public bool Equals(QueueGroup other)
	{
		//IL_000f: 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)
		return kind == other.kind && Tier == other.Tier && Quality == other.Quality;
	}

	public override bool Equals(object obj)
	{
		return obj is QueueGroup other && Equals(other);
	}

	public override int GetHashCode()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected I4, but got Unknown
		return ((((int)kind * 397) ^ Tier) * 397) ^ Quality;
	}
}
internal enum ItemSource
{
	Official,
	All,
	Quality
}
[Flags]
internal enum QualityLevels
{
	None = 0,
	Uncommon = 1,
	Rare = 2,
	Epic = 4,
	Legendary = 8,
	All = 0xF
}
internal static class TierOrder
{
	private static readonly ItemTier[] preferred = (ItemTier[])(object)new ItemTier[3]
	{
		default(ItemTier),
		(ItemTier)1,
		(ItemTier)2
	};

	public static void Prioritize(List<ItemTier> tiers)
	{
		//IL_0011: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		ItemTier[] array = preferred;
		foreach (ItemTier item in array)
		{
			int num2 = tiers.IndexOf(item);
			if (num2 >= 0)
			{
				tiers.RemoveAt(num2);
				tiers.Insert(num++, item);
			}
		}
	}
}
internal sealed class NativeQueueView : MonoBehaviour
{
	private sealed class Tile
	{
		public Button button;

		public Image icon;

		public TextMeshProUGUI fallback;

		public TextMeshProUGUI badge;

		public PickupDef pickup;

		public int index;

		public int queueVersion;

		public TierQueues<QueueGroup, PickupIndex> boundQueue;
	}

	private sealed class TierTab
	{
		public Button button;

		public TextMeshProUGUI label;

		public ItemTier? tier;
	}

	private enum QueueShortcut
	{
		None,
		PreviousTier,
		NextTier,
		NextSource,
		NextQualityLevel,
		RemoveOne
	}

	private static readonly Color Background = new Color(0.025f, 0.045f, 0.055f, 0.86f);

	private static readonly Color Surface = new Color(0.075f, 0.105f, 0.12f, 0.78f);

	private static readonly Color Accent = new Color(0.45f, 0.84f, 0.86f, 1f);

	private static readonly Color Muted = new Color(0.65f, 0.73f, 0.74f, 1f);

	private static readonly string[] QualityLabels = new string[4] { "1 Uncommon", "2 Rare", "3 Epic", "4 Legendary" };

	private readonly Dictionary<PickupIndex, AsyncOperationHandle<Sprite>> iconLoads = new Dictionary<PickupIndex, AsyncOperationHandle<Sprite>>();

	private readonly HashSet<PickupIndex> invalidIcons = new HashSet<PickupIndex>();

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

	private readonly List<Tile> itemTiles = new List<Tile>();

	private readonly List<Tile> queueTiles = new List<Tile>();

	private readonly List<TierQueues<QueueGroup, PickupIndex>.Stack> queueStacks = new List<TierQueues<QueueGroup, PickupIndex>.Stack>();

	private readonly List<TierTab> tierTabs = new List<TierTab>();

	private readonly Dictionary<RectTransform, Tile> tileLookup = new Dictionary<RectTransform, Tile>();

	private readonly Dictionary<Graphic, bool> scoreboardGraphics = new Dictionary<Graphic, bool>();

	private Plugin plugin;

	private ScoreboardController scoreboard;

	private MPEventSystem eventSystem;

	private RectTransform root;

	private RectTransform panel;

	private RectTransform tierBar;

	private VirtualizedGrid itemGrid;

	private VirtualizedGrid queueGrid;

	private TMP_FontAsset font;

	private TMP_StyleSheet styleSheet;

	private TMP_SpriteAsset spriteAsset;

	private Button playersTab;

	private Button queueTab;

	private Button officialButton;

	private Button allItemsButton;

	private Button qualityButton;

	private Button allLevelsButton;

	private readonly Button[] levelButtons = (Button[])(object)new Button[QualityLabels.Length];

	private readonly TextMeshProUGUI[] levelLabels = (TextMeshProUGUI[])(object)new TextMeshProUGUI[QualityLabels.Length];

	private RectTransform qualityControls;

	private TextMeshProUGUI officialLabel;

	private TextMeshProUGUI allItemsLabel;

	private TextMeshProUGUI qualityLabel;

	private TextMeshProUGUI queueTitle;

	private TextMeshProUGUI itemTitle;

	private TextMeshProUGUI detailName;

	private TextMeshProUGUI detailText;

	private TextMeshProUGUI emptyItemsLabel;

	private ItemTier? tier = (ItemTier)0;

	private int queueVersion = -1;

	private int scoreboardClosedFrame = -2;

	private IReadOnlyList<ItemDef> visibleItems = Array.Empty<ItemDef>();

	private IReadOnlyList<EquipmentDef> visibleEquipment = Array.Empty<EquipmentDef>();

	private TierQueues<QueueGroup, PickupIndex> displayedQueue;

	private bool queueVisible;

	private bool itemsDirty = true;

	private bool iconsPending;

	private Tile hoveredTile;

	private PickupDef detailedPickup;

	private float nextDetailsRefresh;

	private static readonly FieldInfo glyphMap = typeof(Glyphs).GetField("glyphMap", BindingFlags.Static | BindingFlags.NonPublic);

	private static readonly ConstructorInfo glyphKey = typeof(Glyphs).GetNestedType("GlyphKey", BindingFlags.NonPublic)?.GetConstructor(new Type[2]
	{
		typeof(string),
		typeof(int)
	});

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

	private QueueNavigation navigation;

	private RectTransform tierViewport;

	private ScrollRect tierScroll;

	private Button removeStackButton;

	private Button focusedFilter;

	private TextMeshProUGUI playersTabLabel;

	private TextMeshProUGUI queueTabLabel;

	private TextMeshProUGUI queueHelp;

	private TextMeshProUGUI controllerCloseHint;

	private TextMeshProUGUI controllerShortcutHint;

	private TextMeshProUGUI previousTierHint;

	private TextMeshProUGUI nextTierHint;

	private TextMeshProUGUI cycleSourceHint;

	private TextMeshProUGUI cycleQualityHint;

	private TextMeshProUGUI removeOneHint;

	private string confirmHint = "CONFIRM";

	private string backHint = "BACK";

	private UILayerKey scoreboardLayer;

	private LocalUser controllerUser;

	private QueueFocus queueFocus = new QueueFocus(QueueSection.Filters, 0);

	private PickupDef focusedPickup;

	private ItemTier? focusedTier;

	private TierQueues<QueueGroup, PickupIndex> focusedStackQueue;

	private TierQueues<QueueGroup, PickupIndex>.Entry focusedStackEntry;

	private GameObject playersSelection;

	private GameObject focusBorder;

	private QueueButton highlightedButton;

	private bool controllerFocusPending;

	private bool controllerWasActive;

	private bool openedWithController;

	private int openFrame;

	private int controllerActionFrame = -2;

	private int confirmFrame = -2;

	private int handoffFrame = -2;

	private int tierCount;

	private float tierWidth;

	private Controller shortcutDevice;

	private IGamepadTemplate shortcutGamepad;

	private bool leftTriggerHeld;

	private bool rightTriggerHeld;

	private MoveDirection heldDirection = (MoveDirection)4;

	private float nextNavigationMove;

	private bool rightStickWasSelected;

	internal bool IsQueueTabVisible => queueVisible;

	internal MPEventSystem EventSystem => eventSystem;

	private bool IsGamepad => Object.op_Implicit((Object)(object)eventSystem) && (int)eventSystem.currentInputSource == 1;

	internal bool UsesControllerNavigation => queueVisible && IsGamepad;

	internal bool ConsumedControllerAction => controllerActionFrame == Time.frameCount;

	internal bool ConsumedControllerPauseBinding => ConsumedControllerAction || confirmFrame == Time.frameCount;

	internal bool IsControllerInput => IsGamepad;

	internal void Initialize(Plugin owner, ScoreboardController controller)
	{
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_063a: Unknown result type (might be due to invalid IL or missing references)
		//IL_068a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0778: Unknown result type (might be due to invalid IL or missing references)
		//IL_0816: Unknown result type (might be due to invalid IL or missing references)
		//IL_0882: Unknown result type (might be due to invalid IL or missing references)
		//IL_08a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_08e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0974: Unknown result type (might be due to invalid IL or missing references)
		//IL_09f3: Unknown result type (might be due to invalid IL or missing references)
		plugin = owner;
		scoreboard = controller;
		TextMeshProUGUI[] componentsInChildren = ((Component)controller).GetComponentsInChildren<TextMeshProUGUI>(true);
		font = componentsInChildren.Select((TextMeshProUGUI text) => ((TMP_Text)text).font).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset asset) => Object.op_Implicit((Object)(object)asset))) ?? TMP_Settings.defaultFontAsset;
		styleSheet = componentsInChildren.Select((TextMeshProUGUI text) => ((TMP_Text)text).styleSheet).FirstOrDefault((Func<TMP_StyleSheet, bool>)((TMP_StyleSheet sheet) => Object.op_Implicit((Object)(object)sheet))) ?? TMP_Settings.defaultStyleSheet;
		spriteAsset = componentsInChildren.Select((TextMeshProUGUI text) => ((TMP_Text)text).spriteAsset).FirstOrDefault((Func<TMP_SpriteAsset, bool>)((TMP_SpriteAsset asset) => Object.op_Implicit((Object)(object)asset))) ?? TMP_Settings.defaultSpriteAsset;
		root = ((Component)this).GetComponent<RectTransform>();
		RectTransform obj = root;
		RectTransform obj2 = root;
		RectTransform obj3 = root;
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(0.5f, 0.5f);
		obj3.pivot = val;
		Vector2 anchorMin = (obj2.anchorMax = val);
		obj.anchorMin = anchorMin;
		root.sizeDelta = new Vector2(1280f, 720f);
		((Component)this).gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
		Canvas val3 = ((Component)this).gameObject.AddComponent<Canvas>();
		val3.overrideSorting = true;
		val3.sortingOrder = 40;
		((Component)this).gameObject.AddComponent<GraphicRaycaster>();
		RectTransform parent = Box("View tabs", (Transform)(object)root, 0f, 0.946f, 1f, 1f, Background);
		playersTab = MakeButton((Transform)(object)parent, "PLAYERS", 0.01f, 0.08f, 0.15f, 0.92f, delegate
		{
			SetView(showQueue: false);
		}, out playersTabLabel);
		queueTab = MakeButton((Transform)(object)parent, "COMMAND QUEUE", 0.155f, 0.08f, 0.35f, 0.92f, delegate
		{
			SetView(showQueue: true);
		}, out queueTabLabel);
		controllerCloseHint = Label((Transform)(object)parent, "", 15f, (TextAlignmentOptions)4097, Muted);
		Place(((TMP_Text)controllerCloseHint).rectTransform, 0.38f, 0f, 0.7f, 1f);
		TextMeshProUGUI val4 = Label((Transform)(object)parent, "ARTIFACT OF COMMAND", 17f, (TextAlignmentOptions)4100, Muted);
		Place(((TMP_Text)val4).rectTransform, 0.7f, 0f, 0.985f, 1f);
		panel = Box("Queue panel", (Transform)(object)root, 0f, 0f, 1f, 0.936f, Background);
		RectTransform val5 = Box("Accent", (Transform)(object)panel, 0f, 0.992f, 1f, 1f, Accent);
		((Graphic)((Component)val5).GetComponent<Image>()).raycastTarget = false;
		TextMeshProUGUI val6 = Label((Transform)(object)panel, "SHOW ITEMS", 14f, (TextAlignmentOptions)4097, Color.white);
		Place(((TMP_Text)val6).rectTransform, 0.02f, 0.925f, 0.13f, 0.982f);
		officialButton = MakeButton((Transform)(object)panel, "", 0.13f, 0.925f, 0.265f, 0.982f, delegate
		{
			SetSource(ItemSource.Official);
		}, out officialLabel);
		allItemsButton = MakeButton((Transform)(object)panel, "", 0.265f, 0.925f, 0.44f, 0.982f, delegate
		{
			SetSource(ItemSource.All);
		}, out allItemsLabel);
		qualityButton = MakeButton((Transform)(object)panel, "", 0.44f, 0.925f, 0.554f, 0.982f, delegate
		{
			SetSource(ItemSource.Quality);
		}, out qualityLabel);
		cycleSourceHint = MakeShortcutHint("Y", 0.554f, 0.925f, 0.589f, 0.982f);
		cycleQualityHint = MakeShortcutHint("R3", 0.589f, 0.925f, 0.625f, 0.982f);
		qualityControls = Rect("Quality levels", (Transform)(object)panel, 0.625f, 0.925f, 0.98f, 0.982f);
		allLevelsButton = MakeButton((Transform)(object)qualityControls, "All levels", 0f, 0f, 0.2f, 1f, delegate
		{
			SetQualityLevels(QualityLevels.All);
		}, out var label);
		for (int num = 0; num < levelButtons.Length; num++)
		{
			QualityLevels flag = Plugin.LevelFlag((QualityLevel)(num + 1));
			levelButtons[num] = MakeButton((Transform)(object)qualityControls, QualityLabels[num], (float)(num + 1) / 5f, 0f, (float)(num + 2) / 5f, 1f, delegate
			{
				SetQualityLevels(flag);
			}, out levelLabels[num]);
			((TMP_Text)levelLabels[num]).fontSize = 13f;
		}
		((Component)qualityControls).gameObject.SetActive(false);
		((Component)qualityButton).gameObject.SetActive(false);
		InitializeTierStrip();
		queueTitle = Label((Transform)(object)panel, "QUEUE", 18f, (TextAlignmentOptions)4097, Color.white);
		Place(((TMP_Text)queueTitle).rectTransform, 0.02f, 0.79f, 0.14f, 0.83f);
		removeOneHint = Label((Transform)(object)panel, "", 13f, (TextAlignmentOptions)4097, Accent);
		Place(((TMP_Text)removeOneHint).rectTransform, 0.15f, 0.79f, 0.37f, 0.83f);
		queueHelp = Label((Transform)(object)panel, "LEFT-CLICK TO REMOVE ONE  ·  RIGHT-CLICK TO REMOVE STACK", 12f, (TextAlignmentOptions)4100, Muted);
		Place(((TMP_Text)queueHelp).rectTransform, 0.37f, 0.79f, 0.98f, 0.83f);
		removeStackButton = MakeButton((Transform)(object)panel, "REMOVE STACK", 0.77f, 0.79f, 0.98f, 0.83f, RemoveFocusedStack, out label);
		((Component)removeStackButton).gameObject.SetActive(false);
		RectTransform parent2 = Rect("Queued items", (Transform)(object)panel, 0.02f, 0.675f, 0.98f, 0.785f);
		queueGrid = CreateGrid(parent2, "Queue scroll", 16, 1, CreateQueueTile, BindQueueTile);
		itemTitle = Label((Transform)(object)panel, "AVAILABLE ITEMS", 18f, (TextAlignmentOptions)4097, Color.white);
		Place(((TMP_Text)itemTitle).rectTransform, 0.02f, 0.625f, 0.54f, 0.67f);
		RectTransform parent3 = Rect("Available items", (Transform)(object)panel, 0.02f, 0.085f, 0.73f, 0.62f);
		itemGrid = CreateGrid(parent3, "Item scroll", 8, 5, CreateItemTile, BindItemTile);
		emptyItemsLabel = Label((Transform)(object)parent3, "", 18f, (TextAlignmentOptions)257, Muted);
		Place(((TMP_Text)emptyItemsLabel).rectTransform, 0f, 0f, 0.96f, 0.98f);
		RectTransform parent4 = Box("Item details", (Transform)(object)panel, 0.75f, 0.085f, 0.98f, 0.67f, new Color(0.035f, 0.055f, 0.065f, 0.96f));
		TextMeshProUGUI val7 = Label((Transform)(object)parent4, "ITEM DETAILS", 16f, (TextAlignmentOptions)4097, Accent);
		Place(((TMP_Text)val7).rectTransform, 0.055f, 0.91f, 0.945f, 0.98f);
		detailName = Label((Transform)(object)parent4, "", 25f, (TextAlignmentOptions)257, Color.white);
		Place(((TMP_Text)detailName).rectTransform, 0.055f, 0.775f, 0.945f, 0.9f);
		((TMP_Text)detailName).enableAutoSizing = true;
		((TMP_Text)detailName).fontSizeMin = 16f;
		((TMP_Text)detailName).fontSizeMax = 25f;
		detailText = Label((Transform)(object)parent4, "Hover over an item to see its description.", 20f, (TextAlignmentOptions)257, new Color(0.88f, 0.93f, 0.94f, 1f));
		Place(((TMP_Text)detailText).rectTransform, 0.055f, 0.045f, 0.945f, 0.76f);
		((TMP_Text)detailText).enableAutoSizing = true;
		((TMP_Text)detailText).fontSizeMin = 13f;
		((TMP_Text)detailText).fontSizeMax = 20f;
		controllerShortcutHint = Label((Transform)(object)panel, "", 13f, (TextAlignmentOptions)4097, Muted);
		Place(((TMP_Text)controllerShortcutHint).rectTransform, 0.02f, 0.018f, 0.98f, 0.07f);
		InitializeControllerNavigation();
		SetView(showQueue: false);
	}

	internal void Open()
	{
		scoreboardClosedFrame = -2;
		MPEventSystemLocator component = ((Component)scoreboard).GetComponent<MPEventSystemLocator>();
		eventSystem = (Object.op_Implicit((Object)(object)component) ? component.eventSystem : null);
		if (!Object.op_Implicit((Object)(object)eventSystem))
		{
			component = ((Component)this).GetComponent<MPEventSystemLocator>();
			eventSystem = (Object.op_Implicit((Object)(object)component) ? component.eventSystem : null);
		}
		BeginControllerOpen();
		itemsDirty = true;
		displayedQueue = null;
		if (queueVisible)
		{
			HideScoreboardGraphics();
			RefreshItems();
		}
		UpdateScale();
	}

	internal void MarkItemsDirty()
	{
		itemsDirty = true;
	}

	internal void OpenQueueFromController()
	{
		if (!queueVisible)
		{
			SetView(showQueue: true);
		}
	}

	internal bool HasJustClosedFor(MPEventSystem playerEventSystem)
	{
		return (Object)(object)eventSystem == (Object)(object)playerEventSystem && Time.frameCount - scoreboardClosedFrame <= 1;
	}

	private void Update()
	{
		if (!Object.op_Implicit((Object)(object)scoreboard) || !((Behaviour)scoreboard).isActiveAndEnabled)
		{
			return;
		}
		UpdateScale();
		if (queueVisible)
		{
			if (itemsDirty)
			{
				RefreshItems();
			}
			if (displayedQueue != plugin.Queues || queueVersion != plugin.Queues.Version)
			{
				RefreshQueue();
			}
			if (iconsPending)
			{
				RefreshPendingIcons();
			}
			if (detailedPickup != null && plugin.HasLookingGlassDetails && Time.unscaledTime >= nextDetailsRefresh)
			{
				RefreshPickupDescription();
			}
		}
	}

	private void OnDisable()
	{
		bool flag = Object.op_Implicit((Object)(object)scoreboard) && !((Component)scoreboard).gameObject.activeInHierarchy;
		if (flag)
		{
			scoreboardClosedFrame = Time.frameCount;
		}
		hoveredTile = null;
		ClearPickupDetails();
		EndControllerOpen();
		Transform parent = (Transform)(flag ? ((object)((Component)scoreboard).transform) : ((object)root));
		ClearSelectionUnder(parent);
		RestoreScoreboardGraphics();
	}

	private void ClearSelectionUnder(Transform parent)
	{
		if (Object.op_Implicit((Object)(object)eventSystem) && Object.op_Implicit((Object)(object)parent))
		{
			GameObject currentSelectedGameObject = ((EventSystem)eventSystem).currentSelectedGameObject;
			if (Object.op_Implicit((Object)(object)currentSelectedGameObject) && currentSelectedGameObject.transform.IsChildOf(parent))
			{
				((EventSystem)eventSystem).SetSelectedGameObject((GameObject)null);
			}
		}
	}

	private void OnDestroy()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		RestoreScoreboardGraphics();
		foreach (AsyncOperationHandle<Sprite> value in iconLoads.Values)
		{
			if (value.IsValid())
			{
				Addressables.Release<Sprite>(value);
			}
		}
		iconLoads.Clear();
	}

	private void UpdateScale()
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		Canvas componentInParent = ((Component)this).GetComponentInParent<Canvas>();
		if (Object.op_Implicit((Object)(object)componentInParent) && Object.op_Implicit((Object)(object)componentInParent.rootCanvas))
		{
			RectTransform component = ((Component)componentInParent.rootCanvas).GetComponent<RectTransform>();
			if (Object.op_Implicit((Object)(object)component))
			{
				float[] obj = new float[3] { 1f, 0f, 0f };
				Rect rect = component.rect;
				obj[1] = (((Rect)(ref rect)).width - 20f) / 1280f;
				rect = component.rect;
				obj[2] = (((Rect)(ref rect)).height - 20f) / 720f;
				float num = Mathf.Min(obj);
				((Transform)root).localScale = Vector3.one * Mathf.Max(0.1f, num);
			}
		}
	}

	private void SetView(bool showQueue)
	{
		bool flag = IsGamepad && HasScoreboardOwnership();
		if (flag && queueVisible && !showQueue)
		{
			BeginControllerHandoff();
		}
		if (flag && !queueVisible && showQueue)
		{
			RememberPlayersSelection();
		}
		queueVisible = showQueue;
		if (!showQueue)
		{
			ClearSelectionUnder((Transform)(object)panel);
		}
		((Component)panel).gameObject.SetActive(showQueue);
		if (showQueue)
		{
			HideScoreboardGraphics();
		}
		else
		{
			RestoreScoreboardGraphics();
		}
		SetTabColor(playersTab, !showQueue);
		SetTabColor(queueTab, showQueue);
		if (showQueue)
		{
			RefreshItems();
		}
		if (flag)
		{
			if (showQueue)
			{
				RestoreQueueFocus();
			}
			else
			{
				RestorePlayersFocus();
			}
		}
	}

	private void HideScoreboardGraphics()
	{
		if (!Object.op_Implicit((Object)(object)scoreboard) || !Object.op_Implicit((Object)(object)root))
		{
			return;
		}
		Graphic[] componentsInChildren = ((Component)scoreboard).GetComponentsInChildren<Graphic>(true);
		foreach (Graphic val in componentsInChildren)
		{
			if (Object.op_Implicit((Object)(object)val) && !((Component)val).transform.IsChildOf((Transform)(object)root))
			{
				if (!scoreboardGraphics.ContainsKey(val))
				{
					scoreboardGraphics.Add(val, ((Behaviour)val).enabled);
				}
				((Behaviour)val).enabled = false;
			}
		}
	}

	private void RestoreScoreboardGraphics()
	{
		foreach (KeyValuePair<Graphic, bool> scoreboardGraphic in scoreboardGraphics)
		{
			if (Object.op_Implicit((Object)(object)scoreboardGraphic.Key))
			{
				((Behaviour)scoreboardGraphic.Key).enabled = scoreboardGraphic.Value;
			}
		}
		scoreboardGraphics.Clear();
	}

	private void SetSource(ItemSource source)
	{
		if (plugin.BrowserSource.Value != source)
		{
			plugin.BrowserSource.Value = source;
			RefreshItems(resetScroll: true);
		}
	}

	private void SetQualityLevels(QualityLevels levels)
	{
		if (plugin.BrowserQualityLevels.Value != levels)
		{
			plugin.BrowserQualityLevels.Value = levels;
			RefreshItems(resetScroll: true);
		}
	}

	private void RefreshItems(bool resetScroll = false)
	{
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		itemsDirty = false;
		ItemSource activeSource = plugin.ActiveSource;
		SetSourceButton(officialButton, officialLabel, "OFFICIAL ONLY", activeSource == ItemSource.Official);
		SetSourceButton(allItemsButton, allItemsLabel, "OFFICIAL + MODDED", activeSource == ItemSource.All);
		SetSourceButton(qualityButton, qualityLabel, "QUALITY ONLY", activeSource == ItemSource.Quality);
		((Component)qualityButton).gameObject.SetActive(plugin.QualitySupported);
		((Component)qualityControls).gameObject.SetActive(activeSource == ItemSource.Quality);
		UpdateFilterShortcutHints();
		QualityLevels value = plugin.BrowserQualityLevels.Value;
		SetTabColor(allLevelsButton, value == QualityLevels.All);
		for (int i = 0; i < levelButtons.Length; i++)
		{
			bool flag = value == Plugin.LevelFlag((QualityLevel)(i + 1));
			SetTabColor(levelButtons[i], flag);
			((Graphic)levelLabels[i]).color = (flag ? Color.white : Muted);
		}
		List<ItemTier> list = new List<ItemTier>();
		Enumerator<ItemTierDef> enumerator = ItemTierCatalog.allItemTierDefs.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				ItemTierDef current = enumerator.Current;
				if (Object.op_Implicit((Object)(object)current) && !list.Contains(current.tier) && plugin.GetAvailableItems(current.tier, includeAllQualityLevels: true).Count > 0)
				{
					list.Add(current.tier);
				}
			}
		}
		finally
		{
			((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
		}
		TierOrder.Prioritize(list);
		List<ItemTier?> list2 = new List<ItemTier?>(list.Count + 1);
		foreach (ItemTier item in list)
		{
			list2.Add(item);
		}
		if (plugin.GetAvailableEquipment(includeAllQualityLevels: true).Count > 0)
		{
			int num = list.FindIndex((ItemTier val) => (int)val != 0 && (int)val != 1 && (int)val != 2);
			list2.Insert((num < 0) ? list2.Count : num, null);
		}
		if (list2.Count > 0 && !list2.Contains(tier))
		{
			tier = list2[0];
			resetScroll = true;
		}
		BuildTierTabs(list2);
		IReadOnlyList<ItemDef> readOnlyList2;
		if (!tier.HasValue)
		{
			IReadOnlyList<ItemDef> readOnlyList = Array.Empty<ItemDef>();
			readOnlyList2 = readOnlyList;
		}
		else
		{
			readOnlyList2 = plugin.GetAvailableItems(tier.Value);
		}
		visibleItems = readOnlyList2;
		IReadOnlyList<EquipmentDef> readOnlyList3;
		if (!tier.HasValue)
		{
			readOnlyList3 = plugin.GetAvailableEquipment();
		}
		else
		{
			IReadOnlyList<EquipmentDef> readOnlyList4 = Array.Empty<EquipmentDef>();
			readOnlyList3 = readOnlyList4;
		}
		visibleEquipment = readOnlyList3;
		int num2 = visibleItems.Count + visibleEquipment.Count;
		string text = (tier.HasValue ? (TierName(tier.Value).ToUpperInvariant() + " ITEMS") : "EQUIPMENT");
		((TMP_Text)itemTitle).text = text + "  ·  " + num2;
		((Component)emptyItemsLabel).gameObject.SetActive(num2 == 0);
		((TMP_Text)emptyItemsLabel).text = (tier.HasValue ? "No available items match these filters." : "No available equipment matches these filters.");
		itemGrid.SetCount(num2, resetScroll);
		RefreshQueue();
		RecoverControllerSelection();
	}

	private static void SetSourceButton(Button button, TextMeshProUGUI label, string name, bool selected)
	{
		((TMP_Text)label).text = (selected ? ("[ON] " + name) : name);
		SetTabColor(button, selected);
	}

	private void BuildTierTabs(List<ItemTier?> tiers)
	{
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		while (tierTabs.Count < tiers.Count)
		{
			TierTab tab = new TierTab();
			tab.button = MakeButton((Transform)(object)tierBar, "", 0f, 0f, 1f, 1f, delegate
			{
				SelectTier(tab.tier);
			}, out tab.label);
			tierTabs.Add(tab);
		}
		for (int num = 0; num < tierTabs.Count; num++)
		{
			TierTab tierTab = tierTabs[num];
			((Component)tierTab.button).gameObject.SetActive(num < tiers.Count);
			if (num < tiers.Count)
			{
				tierTab.tier = tiers[num];
				((TMP_Text)tierTab.label).text = (tierTab.tier.HasValue ? TierName(tierTab.tier.Value).ToUpperInvariant() : "EQUIPMENT");
				((TMP_Text)tierTab.l