Decompiled source of StageTracker v1.0.2

plugins\StageTracker\StageTracker.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using StageTracker.Config;
using StageTracker.Tracking;
using StageTracker.UI;
using StageTracker.Util;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace StageTracker
{
	[BepInPlugin("Kyle.StageTracker", "StageTracker", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static ShouldHudDisplayDelegate <0>__OnShouldHudDisplay;
		}

		public const string Author = "Kyle";

		public const string Name = "StageTracker";

		public const string GUID = "Kyle.StageTracker";

		public const string Version = "1.0.2";

		internal static ManualLogSource Log;

		internal static ModConfig Config { get; private set; }

		private void Awake()
		{
			//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_0036: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Config = new ModConfig(((BaseUnityPlugin)this).Config);
			object obj = <>O.<0>__OnShouldHudDisplay;
			if (obj == null)
			{
				ShouldHudDisplayDelegate val = OnShouldHudDisplay;
				<>O.<0>__OnShouldHudDisplay = val;
				obj = (object)val;
			}
			HUD.shouldHudDisplay += (ShouldHudDisplayDelegate)obj;
			Log.LogInfo((object)"StageTracker v1.0.2 loaded.");
		}

		private void Start()
		{
			Config.RegisterRiskOfOptions("StageTracker", "Loot and drone panels that track everything left on the stage — all shown at once, no teleporter gating.", "Kyle.StageTracker");
		}

		private void OnDestroy()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			object obj = <>O.<0>__OnShouldHudDisplay;
			if (obj == null)
			{
				ShouldHudDisplayDelegate val = OnShouldHudDisplay;
				<>O.<0>__OnShouldHudDisplay = val;
				obj = (object)val;
			}
			HUD.shouldHudDisplay -= (ShouldHudDisplayDelegate)obj;
		}

		private static void OnShouldHudDisplay(HUD hud, ref bool shouldDisplay)
		{
			if (Object.op_Implicit((Object)(object)hud) && !Object.op_Implicit((Object)(object)((Component)hud).gameObject.GetComponent<PanelsController>()))
			{
				((Component)hud).gameObject.AddComponent<PanelsController>();
			}
		}
	}
}
namespace StageTracker.Util
{
	public static class Diagnostics
	{
		[ConCommand(/*Could not decode attribute arguments.*/)]
		public static void ScanStage(ConCommandArgs args)
		{
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder(4096);
			stringBuilder.AppendLine("=== StageTracker stage scan ===");
			List<PurchaseInteraction> instancesList = InstanceTracker.GetInstancesList<PurchaseInteraction>();
			stringBuilder.AppendLine($"PurchaseInteractions: {instancesList.Count}");
			for (int i = 0; i < instancesList.Count; i++)
			{
				PurchaseInteraction val = instancesList[i];
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>();
				StringBuilder stringBuilder2 = new StringBuilder();
				foreach (MonoBehaviour val2 in components)
				{
					if (!Object.op_Implicit((Object)(object)val2))
					{
						continue;
					}
					Type type = ((object)val2).GetType();
					if (type.Namespace != null && (type.Namespace.StartsWith("RoR2") || type.Namespace.StartsWith("EntityStates")))
					{
						if (stringBuilder2.Length > 0)
						{
							stringBuilder2.Append(", ");
						}
						stringBuilder2.Append(type.FullName);
					}
				}
				stringBuilder.AppendLine($"  [{((Object)((Component)val).gameObject).name}] token='{val.displayNameToken}' name='{val.GetDisplayName()}' cost={val.cost}({val.costType}) available={val.available} isShrine={val.isShrine} isDrone={val.isDrone} goldShrine={val.isGoldShrine} components=[{stringBuilder2}]");
				ChestBehavior componentInChildren = ((Component)val).GetComponentInChildren<ChestBehavior>(true);
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					stringBuilder.AppendLine(string.Format("      chest: dropTable={0} tag={1} tiers={2:P0}/{3:P0}/{4:P0} lunar={5:P0} drops={6}-{7}", Object.op_Implicit((Object)(object)componentInChildren.dropTable) ? (((object)componentInChildren.dropTable).GetType().Name + "/" + ((Object)componentInChildren.dropTable).name) : "null", componentInChildren.requiredItemTag, componentInChildren.tier1Chance, componentInChildren.tier2Chance, componentInChildren.tier3Chance, componentInChildren.lunarChance, componentInChildren.minDropCount, componentInChildren.maxDropCount));
				}
			}
			ReadOnlyCollection<CharacterBody> readOnlyInstancesList = CharacterBody.readOnlyInstancesList;
			stringBuilder.AppendLine($"CharacterBodies with purchase interactions: (scanning {readOnlyInstancesList.Count})");
			for (int k = 0; k < readOnlyInstancesList.Count; k++)
			{
				CharacterBody val3 = readOnlyInstancesList[k];
				if (Object.op_Implicit((Object)(object)val3))
				{
					PurchaseInteraction componentInChildren2 = ((Component)val3).GetComponentInChildren<PurchaseInteraction>();
					if (Object.op_Implicit((Object)(object)componentInChildren2))
					{
						DroneIndex droneIndexFromBodyIndex = DroneCatalog.GetDroneIndexFromBodyIndex(val3.bodyIndex);
						stringBuilder.AppendLine($"  [{((Object)((Component)val3).gameObject).name}] body='{val3.GetDisplayName()}' droneIndex={droneIndexFromBodyIndex} token='{componentInChildren2.displayNameToken}' available={componentInChildren2.available}");
					}
				}
			}
			stringBuilder.AppendLine("=== end scan ===");
			Debug.Log((object)stringBuilder.ToString());
		}
	}
	public static class Palette
	{
		public const string ChestGold = "E5C962";

		public const string ShrineYellow = "EFEB1A";

		public const string GoldPortal = "FFFCC4";

		public const string AlloyedTeal = "1CB8DB";

		public const string Gray = "8B8B8B";

		public const string EnemyRed = "E58262";

		public static string Hex(ColorIndex index)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return ColorUtility.ToHtmlStringRGB(Color32.op_Implicit(ColorCatalog.GetColor(index)));
		}

		public static string Hex(ItemTier tier)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected I4, but got Unknown
			//IL_0041: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			ColorIndex index;
			switch ((int)tier)
			{
			case 0:
				index = (ColorIndex)1;
				break;
			case 1:
				index = (ColorIndex)2;
				break;
			case 2:
				index = (ColorIndex)3;
				break;
			case 3:
				index = (ColorIndex)4;
				break;
			case 4:
				index = (ColorIndex)13;
				break;
			case 6:
			case 7:
			case 8:
			case 9:
				index = (ColorIndex)25;
				break;
			case 10:
				index = (ColorIndex)2;
				break;
			case 11:
				index = (ColorIndex)34;
				break;
			case 13:
				index = (ColorIndex)35;
				break;
			default:
				index = (ColorIndex)1;
				break;
			}
			return Hex(index);
		}

		public static string Colored(string text, string hex)
		{
			return "<color=#" + hex + ">" + text + "</color>";
		}

		public static int CostBucket(CostTypeIndex costType, string gameObjectName)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected I4, but got Unknown
			switch (costType - 4)
			{
			case 0:
				return 0;
			case 1:
				return 1;
			case 2:
				return 2;
			case 6:
				return 3;
			default:
				if (gameObjectName == null || !gameObjectName.Contains("Void"))
				{
					return 0;
				}
				return 4;
			}
		}

		public static string BucketHex(int bucket)
		{
			return bucket switch
			{
				0 => Hex((ColorIndex)1), 
				1 => Hex((ColorIndex)2), 
				2 => Hex((ColorIndex)3), 
				3 => Hex((ColorIndex)13), 
				_ => Hex((ColorIndex)25), 
			};
		}
	}
	public static class Lang
	{
		public static string TryGet(string token)
		{
			if (string.IsNullOrEmpty(token))
			{
				return null;
			}
			string text = Language.GetString(token);
			if (string.IsNullOrEmpty(text) || text == token)
			{
				return null;
			}
			return text;
		}
	}
}
namespace StageTracker.UI
{
	public sealed class HudPanel
	{
		public GameObject Root;

		public HGTextMeshProUGUI Label;

		public HGTextMeshProUGUI Body;

		public static HudPanel Clone(ObjectivePanelController template, string panelName, string headerText)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			GameObject val = Object.Instantiate<GameObject>(((Component)template).gameObject, ((Component)template).transform.parent);
			((Object)val).name = panelName;
			Object.DestroyImmediate((Object)(object)val.GetComponent<ObjectivePanelController>());
			HudObjectiveTargetSetter component = val.GetComponent<HudObjectiveTargetSetter>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			HGTextMeshProUGUI componentInChildren = val.GetComponentInChildren<HGTextMeshProUGUI>(true);
			if (!Object.op_Implicit((Object)(object)componentInChildren))
			{
				Object.DestroyImmediate((Object)(object)val);
				return null;
			}
			Transform parent = ((TMP_Text)componentInChildren).transform.parent;
			if (!Object.op_Implicit((Object)(object)parent))
			{
				Object.DestroyImmediate((Object)(object)val);
				return null;
			}
			HGTextMeshProUGUI component2 = Object.Instantiate<GameObject>(((Component)componentInChildren).gameObject, parent).GetComponent<HGTextMeshProUGUI>();
			HGTextMeshProUGUI component3 = Object.Instantiate<GameObject>(((Component)componentInChildren).gameObject, parent).GetComponent<HGTextMeshProUGUI>();
			bool flag = true;
			while (flag)
			{
				flag = false;
				Transform val2 = null;
				foreach (Transform item in parent)
				{
					Transform val3 = item;
					if ((Object)(object)val3 != (Object)(object)((TMP_Text)component2).transform && (Object)(object)val3 != (Object)(object)((TMP_Text)component3).transform)
					{
						val2 = val3;
						flag = true;
						break;
					}
				}
				if (Object.op_Implicit((Object)(object)val2))
				{
					Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
				}
			}
			HGTextMeshProUGUI[] array = (HGTextMeshProUGUI[])(object)new HGTextMeshProUGUI[2] { component2, component3 };
			foreach (HGTextMeshProUGUI obj in array)
			{
				LanguageTextMeshController component4 = ((Component)obj).GetComponent<LanguageTextMeshController>();
				if (Object.op_Implicit((Object)(object)component4))
				{
					Object.DestroyImmediate((Object)(object)component4);
				}
				LayoutElement component5 = ((Component)obj).GetComponent<LayoutElement>();
				if (Object.op_Implicit((Object)(object)component5))
				{
					Object.DestroyImmediate((Object)(object)component5);
				}
				((TMP_Text)obj).fontSize = 12f;
				((TMP_Text)obj).fontSizeMax = 12f;
				((TMP_Text)obj).fontSizeMin = 6f;
				((TMP_Text)obj).alignment = (TextAlignmentOptions)257;
			}
			((TMP_Text)component2).text = headerText;
			((TMP_Text)component3).text = string.Empty;
			LogHierarchy(val.transform, 0);
			return new HudPanel
			{
				Root = val,
				Label = component2,
				Body = component3
			};
		}

		private static void LogHierarchy(Transform node, int depth)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			RectTransform val = (RectTransform)(object)((node is RectTransform) ? node : null);
			string text;
			if (!((Object)(object)val != (Object)null))
			{
				text = string.Empty;
			}
			else
			{
				Rect rect = val.rect;
				object arg = ((Rect)(ref rect)).width;
				rect = val.rect;
				text = $" size={arg:F0}x{((Rect)(ref rect)).height:F0}";
			}
			string text2 = text;
			Plugin.Log.LogInfo((object)(new string(' ', depth * 2) + ((Object)node).name + text2));
			foreach (Transform item in node)
			{
				LogHierarchy(item, depth + 1);
			}
		}
	}
	public sealed class PanelsController : MonoBehaviour
	{
		private const float RescanInterval = 1f / 30f;

		private const int CreateAttempts = 240;

		private HUD _hud;

		private HudPanel _loot;

		private HudPanel _drone;

		private LootData _lootData;

		private DroneData _droneData;

		private float _lastScan;

		private int _framesSinceStart;

		private void Awake()
		{
			_hud = ((Component)this).GetComponent<HUD>();
		}

		private void Update()
		{
			if (_loot == null || _drone == null)
			{
				_framesSinceStart++;
				if (_framesSinceStart % 30 == 0 && _framesSinceStart <= 7200)
				{
					TryCreatePanels();
				}
				if (_loot == null || _drone == null)
				{
					return;
				}
			}
			ModConfig config = Plugin.Config;
			if (config == null)
			{
				return;
			}
			int num;
			int num2;
			if (config.PanelMode.Value != DisplayMode.AlwaysVisible)
			{
				if (Object.op_Implicit((Object)(object)_hud) && Object.op_Implicit((Object)(object)_hud.scoreboardPanel))
				{
					num = (_hud.scoreboardPanel.activeSelf ? 1 : 0);
					if (num != 0)
					{
						goto IL_009d;
					}
				}
				else
				{
					num = 0;
				}
				num2 = 0;
				goto IL_00ab;
			}
			num = 1;
			goto IL_009d;
			IL_00ab:
			bool active = (byte)num2 != 0;
			bool active2 = num != 0 && config.ShowDronePanel.Value;
			_loot.Root.SetActive(active);
			_drone.Root.SetActive(active2);
			if (num != 0 && !(Time.unscaledTime - _lastScan < 1f / 30f))
			{
				_lastScan = Time.unscaledTime;
				_lootData = LootScan.Scan();
				_droneData = DroneScan.Scan();
				((TMP_Text)_loot.Body).text = PanelText.BuildLoot(_lootData, config);
				((TMP_Text)_drone.Body).text = PanelText.BuildDrones(_droneData, config);
			}
			return;
			IL_009d:
			num2 = (config.ShowLootPanel.Value ? 1 : 0);
			goto IL_00ab;
		}

		private void TryCreatePanels()
		{
			ObjectivePanelController val = (Object.op_Implicit((Object)(object)_hud) ? ((Component)_hud).GetComponentInChildren<ObjectivePanelController>(true) : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				_loot = HudPanel.Clone(val, "StageTrackerLootPanel", "Loot:");
				_drone = HudPanel.Clone(val, "StageTrackerDronePanel", "Drones:");
				if (_loot == null || _drone == null)
				{
					((Behaviour)this).enabled = false;
					return;
				}
				_loot.Root.SetActive(false);
				_drone.Root.SetActive(false);
			}
		}
	}
	public static class PanelText
	{
		private const string Stack = "<style=cStack>";

		private const string Sub = "<style=cSub>";

		private const string Close = "</style>";

		private const string Separator = "<style=cStack> · </style>";

		public static string BuildLoot(LootData data, ModConfig config)
		{
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder(1024);
			string text = null;
			for (int i = 0; i < Categories.Loot.Length; i++)
			{
				CategoryDef categoryDef = Categories.Loot[i];
				if (categoryDef.Id == Cat.Uncategorized)
				{
					if (!config.TrackUncategorized.Value)
					{
						continue;
					}
					for (int j = 0; j < data.Unknown.Count; j++)
					{
						(string, int, int) tuple = data.Unknown[j];
						if (tuple.Item3 > 0)
						{
							stringBuilder.Append('\n');
							stringBuilder.Append(FormatLine(tuple.Item1, "8B8B8B", tuple.Item2, tuple.Item3, config.ShowUsedOverTotal.Value)).Append('\n');
						}
					}
				}
				else
				{
					if (!config.Enabled(categoryDef.Id) || !data.Counts.TryGetValue(categoryDef.Id, out (int, int) value) || value.Item2 <= 0)
					{
						continue;
					}
					if (categoryDef.Section != text)
					{
						if (text != null)
						{
							stringBuilder.Append('\n');
						}
						text = categoryDef.Section;
					}
					string label = Lang.TryGet(categoryDef.Token) ?? categoryDef.Label;
					stringBuilder.Append(FormatLine(label, categoryDef.ColorIdx.HasValue ? Palette.Hex(categoryDef.ColorIdx.Value) : categoryDef.Hex, value.Item1, value.Item2, config.ShowUsedOverTotal.Value)).Append('\n');
					if (categoryDef.Id == Cat.ShrineChance && data.ChancePurchasesLeft > 0)
					{
						stringBuilder.Length--;
						stringBuilder.Append(' ').Append(Palette.Colored($"({data.ChancePurchasesLeft})", "EFEB1A")).Append('\n');
					}
				}
			}
			AppendTierLine(stringBuilder, data.PrinterAvailable, data.PrinterTotal, Lang.TryGet("DUPLICATOR_NAME") ?? "3D Printer", config.Enabled(Cat.Printers), config.ShowUsedOverTotal.Value);
			AppendTierLine(stringBuilder, data.CauldronAvailable, data.CauldronTotal, "Cauldron", config.Enabled(Cat.Cauldrons), config.ShowUsedOverTotal.Value);
			if (config.ShowEnemies.Value && (data.MonsterEnemies > 0 || data.VoidEnemies > 0))
			{
				stringBuilder.Append('\n');
				stringBuilder.Append("<style=cStack>> </style>").Append(Palette.Colored("Enemies", "E58262")).Append("<style=cStack>: </style>");
				bool flag = false;
				if (data.MonsterEnemies > 0)
				{
					stringBuilder.Append(Palette.Colored(data.MonsterEnemies.ToString(), "E58262"));
					flag = true;
				}
				if (data.VoidEnemies > 0)
				{
					if (flag)
					{
						stringBuilder.Append("<style=cStack> · </style>");
					}
					stringBuilder.Append(Palette.Colored(data.VoidEnemies.ToString(), Palette.Hex((ColorIndex)25)));
				}
				stringBuilder.Append('\n');
			}
			if (config.ShowInvitations.Value && data.Invitations > 0)
			{
				stringBuilder.Append("<style=cStack>> </style>").Append(Palette.Colored("Invitations", "EFEB1A")).Append("<style=cStack>: </style>")
					.Append(Palette.Colored(data.Invitations.ToString(), "EFEB1A"))
					.Append('\n');
			}
			if (config.ShowStageName.Value && !string.IsNullOrEmpty(data.StageName))
			{
				stringBuilder.Append('\n');
				stringBuilder.Append("<style=cStack>-- ").Append(data.StageName).Append(" --")
					.Append("</style>");
			}
			return stringBuilder.ToString();
		}

		public static string BuildDrones(DroneData data, ModConfig config)
		{
			StringBuilder stringBuilder = new StringBuilder(512);
			if (config.Enabled(DroneCat.GunnerTurret) && data.TurretTotal > 0)
			{
				stringBuilder.Append(FormatLine("Gunner Turret", Palette.Hex((ColorIndex)1), data.TurretAvailable, data.TurretTotal, config.ShowUsedOverTotal.Value)).Append('\n');
			}
			if (config.Enabled(DroneCat.BrokenDrones))
			{
				for (int i = 0; i < data.Broken.Count; i++)
				{
					DroneData.BrokenGroup brokenGroup = data.Broken[i];
					if (brokenGroup.Total > 0)
					{
						stringBuilder.Append(FormatLine(brokenGroup.Label, brokenGroup.ColorHex, brokenGroup.Available, brokenGroup.Total, config.ShowUsedOverTotal.Value)).Append('\n');
					}
				}
			}
			if (config.Enabled(DroneCat.TripleShop) && data.TripleShopTotal > 0)
			{
				stringBuilder.Append('\n');
				stringBuilder.Append(FormatLine("Triple Drone Shop", Palette.Hex((ColorIndex)31), data.TripleShopAvailable, data.TripleShopTotal, config.ShowUsedOverTotal.Value)).Append('\n');
			}
			if (config.Enabled(DroneCat.DroneScrapper) || config.Enabled(DroneCat.DroneCombiner))
			{
				stringBuilder.Append('\n');
				if (config.Enabled(DroneCat.DroneScrapper))
				{
					AppendPresence(stringBuilder, "Drone Scrapper", data.DroneScrapperPresent);
				}
				if (config.Enabled(DroneCat.DroneCombiner))
				{
					AppendPresence(stringBuilder, "Drone Combiner Station", data.DroneCombinerPresent);
				}
			}
			return stringBuilder.ToString();
		}

		private static void AppendTierLine(StringBuilder sb, int[] available, int[] total, string label, bool enabled, bool alwaysUsedOverTotal)
		{
			if (!enabled)
			{
				return;
			}
			bool flag = false;
			for (int i = 0; i < total.Length; i++)
			{
				if (total[i] > 0)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				return;
			}
			sb.Append('\n');
			sb.Append("<style=cStack>> </style>").Append(Palette.Colored(label, "8B8B8B")).Append("<style=cStack>: </style>");
			bool flag2 = true;
			for (int j = 0; j < total.Length; j++)
			{
				if (total[j] > 0)
				{
					if (!flag2)
					{
						sb.Append("<style=cStack> · </style>");
					}
					flag2 = false;
					string hex = Palette.BucketHex(j);
					sb.Append((available[j] == total[j] && !alwaysUsedOverTotal) ? Palette.Colored(total[j].ToString(), hex) : Palette.Colored($"{available[j]}/{total[j]}", hex));
				}
			}
			sb.Append('\n');
		}

		private static void AppendPresence(StringBuilder sb, string label, bool present)
		{
			sb.Append("<style=cStack>> </style>").Append(Palette.Colored(label, "8B8B8B")).Append("<style=cStack>: </style>")
				.Append(present ? Palette.Colored("@", Palette.Hex((ColorIndex)30)) : "<style=cSub>×</style>")
				.Append('\n');
		}

		private static string FormatLine(string label, string colorHex, int available, int total, bool alwaysUsedOverTotal)
		{
			StringBuilder stringBuilder = new StringBuilder(64);
			stringBuilder.Append("<style=cStack>> </style>").Append(Palette.Colored(label, colorHex)).Append("<style=cStack>: </style>");
			if (available == total && !alwaysUsedOverTotal)
			{
				stringBuilder.Append(total);
			}
			else if (available == 0)
			{
				stringBuilder.Append("<style=cSub>0</style>").Append("<style=cStack>/" + total + "</style>");
			}
			else
			{
				stringBuilder.Append(available).Append("<style=cStack>/" + total + "</style>");
			}
			return stringBuilder.ToString();
		}
	}
}
namespace StageTracker.Tracking
{
	public enum Cat
	{
		Multishop,
		EquipmentMultishop,
		CrashedMultishop,
		ChestSmall,
		ChestLarge,
		ChestLegendary,
		ChestDamage,
		ChestHealing,
		ChestUtility,
		CloakedChest,
		AdaptiveChest,
		SecurityChest,
		ScavengerPack,
		ShippingRequests,
		EquipmentBarrel,
		RustyLockbox,
		EncrustedCache,
		ShrineChance,
		ShrineMountain,
		ShrineBlood,
		ShrineOrder,
		ShrineCombat,
		ShrineCombatCollective,
		ShrineWoods,
		ShrineHalcyon,
		ShrineShaping,
		ShrineRebirth,
		ShrineCompulsion,
		ShrineHallowed,
		ShrineDescent,
		AltarOfGold,
		NewtAltar,
		CleansingPool,
		Scrapper,
		Printers,
		Cauldrons,
		VoidChests,
		LunarPod,
		LunarSeer,
		Geodes,
		AccessNodes,
		TempItemDistributors,
		WanderingChef,
		ConceptReliquaries,
		GhostlyChests,
		Gongs,
		AnimaPortals,
		Uncategorized
	}
	public enum DroneCat
	{
		GunnerTurret,
		TripleShop,
		DroneScrapper,
		DroneCombiner,
		BrokenDrones
	}
	public sealed class CategoryDef
	{
		public Cat Id;

		public string Key;

		public string Label;

		public string Token;

		public string Section;

		public ColorIndex? ColorIdx;

		public string Hex;
	}
	public sealed class DroneCategoryDef
	{
		public DroneCat Id;

		public string Key;

		public string Label;
	}
	public static class Categories
	{
		public static readonly CategoryDef[] Loot = new CategoryDef[48]
		{
			new CategoryDef
			{
				Id = Cat.Multishop,
				Key = "MultishopTerminals",
				Label = "Multishop Terminal",
				Token = "MULTISHOP_TERMINAL_NAME",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)31
			},
			new CategoryDef
			{
				Id = Cat.EquipmentMultishop,
				Key = "EquipmentMultishops",
				Label = "Equipment Multishop",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)5
			},
			new CategoryDef
			{
				Id = Cat.CrashedMultishop,
				Key = "CrashedMultishops",
				Label = "Crashed Multishop",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)8
			},
			new CategoryDef
			{
				Id = Cat.ChestSmall,
				Key = "ChestSmall",
				Label = "Chest",
				Section = "Chests & Terminals",
				Hex = "E5C962"
			},
			new CategoryDef
			{
				Id = Cat.ChestLarge,
				Key = "ChestLarge",
				Label = "Large Chest",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)2
			},
			new CategoryDef
			{
				Id = Cat.ChestLegendary,
				Key = "ChestLegendary",
				Label = "Legendary Chest",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)13
			},
			new CategoryDef
			{
				Id = Cat.ChestDamage,
				Key = "ChestDamage",
				Label = "Damage Chest",
				Section = "Chests & Terminals",
				Hex = "E5C962"
			},
			new CategoryDef
			{
				Id = Cat.ChestHealing,
				Key = "ChestHealing",
				Label = "Healing Chest",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)30
			},
			new CategoryDef
			{
				Id = Cat.ChestUtility,
				Key = "ChestUtility",
				Label = "Utility Chest",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)31
			},
			new CategoryDef
			{
				Id = Cat.CloakedChest,
				Key = "CloakedChests",
				Label = "Cloaked Chest",
				Token = "CHEST1_STEALTHED_NAME",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)6
			},
			new CategoryDef
			{
				Id = Cat.AdaptiveChest,
				Key = "AdaptiveChests",
				Label = "Adaptive Chest",
				Token = "CASINOCHEST_NAME",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)25
			},
			new CategoryDef
			{
				Id = Cat.SecurityChest,
				Key = "SecurityChests",
				Label = "Timed Security Chest",
				Section = "Chests & Terminals",
				Hex = "E5C962"
			},
			new CategoryDef
			{
				Id = Cat.ScavengerPack,
				Key = "ScavengerPacks",
				Label = "Scavenger Backpack",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)13
			},
			new CategoryDef
			{
				Id = Cat.ShippingRequests,
				Key = "ShippingRequests",
				Label = "Shipping Request",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)6
			},
			new CategoryDef
			{
				Id = Cat.EquipmentBarrel,
				Key = "EquipmentBarrels",
				Label = "Equipment Barrel",
				Token = "EQUIPMENTBARREL_NAME",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)5
			},
			new CategoryDef
			{
				Id = Cat.RustyLockbox,
				Key = "RustyLockboxes",
				Label = "Rusty Lockbox",
				Token = "LOCKBOX_NAME",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)13
			},
			new CategoryDef
			{
				Id = Cat.EncrustedCache,
				Key = "EncrustedCaches",
				Label = "Encrusted Cache",
				Token = "VOIDLOCKBOX_NAME",
				Section = "Chests & Terminals",
				ColorIdx = (ColorIndex)25
			},
			new CategoryDef
			{
				Id = Cat.ShrineChance,
				Key = "ShrineOfChance",
				Label = "Shrine of Chance",
				Token = "SHRINE_CHANCE_NAME",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineMountain,
				Key = "ShrineOfTheMountain",
				Label = "Shrine of the Mountain",
				Token = "SHRINE_BOSS_NAME",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineBlood,
				Key = "ShrineOfBlood",
				Label = "Shrine of Blood",
				Token = "SHRINE_BLOOD_NAME",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineOrder,
				Key = "ShrineOfOrder",
				Label = "Shrine of Order",
				Token = "SHRINE_RESTACK_OPTION_NAME",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineCombat,
				Key = "ShrineOfCombat",
				Label = "Shrine of Combat",
				Token = "SHRINE_COMBAT_NAME",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineCombatCollective,
				Key = "CollectiveShrineOfCombat",
				Label = "Collective Shrine of Combat",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineWoods,
				Key = "ShrineOfTheWoods",
				Label = "Shrine of the Woods",
				Token = "SHRINE_WOODS_NAME",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineHalcyon,
				Key = "HalcyonShrines",
				Label = "Halcyon Shrine",
				Section = "Shrines",
				Hex = "FFFCC4"
			},
			new CategoryDef
			{
				Id = Cat.ShrineShaping,
				Key = "ShrineOfShaping",
				Label = "Shrine of Shaping",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineRebirth,
				Key = "ShrineOfRebirth",
				Label = "Shrine of Rebirth",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineCompulsion,
				Key = "ShrineOfCompulsion",
				Label = "Shrine of Compulsion",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.ShrineHallowed,
				Key = "HallowedShrines",
				Label = "Hallowed Shrine",
				Section = "Shrines",
				ColorIdx = (ColorIndex)35
			},
			new CategoryDef
			{
				Id = Cat.ShrineDescent,
				Key = "ShrineOfDescent",
				Label = "Shrine of Descent",
				Section = "Shrines",
				Hex = "EFEB1A"
			},
			new CategoryDef
			{
				Id = Cat.AltarOfGold,
				Key = "AltarsOfGold",
				Label = "Altar of Gold",
				Section = "Shrines",
				Hex = "FFFCC4"
			},
			new CategoryDef
			{
				Id = Cat.NewtAltar,
				Key = "NewtAltars",
				Label = "Newt Altar",
				Section = "Shrines",
				ColorIdx = (ColorIndex)4
			},
			new CategoryDef
			{
				Id = Cat.CleansingPool,
				Key = "CleansingPools",
				Label = "Cleansing Pool",
				Token = "SHRINE_CLEANSE_NAME",
				Section = "Shrines",
				ColorIdx = (ColorIndex)4
			},
			new CategoryDef
			{
				Id = Cat.Scrapper,
				Key = "Scrappers",
				Label = "Scrapper",
				Section = "Machines",
				Hex = "8B8B8B"
			},
			new CategoryDef
			{
				Id = Cat.Printers,
				Key = "Printers",
				Label = "3D Printer",
				Section = "Machines",
				Hex = "8B8B8B"
			},
			new CategoryDef
			{
				Id = Cat.Cauldrons,
				Key = "Cauldrons",
				Label = "Cauldron",
				Section = "Machines",
				Hex = "8B8B8B"
			},
			new CategoryDef
			{
				Id = Cat.VoidChests,
				Key = "VoidChests",
				Label = "Void Chest",
				Token = "VOID_CHEST_NAME",
				Section = "Void & Lunar",
				ColorIdx = (ColorIndex)25
			},
			new CategoryDef
			{
				Id = Cat.LunarPod,
				Key = "LunarPods",
				Label = "Lunar Pod",
				Token = "LUNAR_CHEST_NAME",
				Section = "Void & Lunar",
				ColorIdx = (ColorIndex)4
			},
			new CategoryDef
			{
				Id = Cat.LunarSeer,
				Key = "LunarSeers",
				Label = "Lunar Seer",
				Section = "Void & Lunar",
				ColorIdx = (ColorIndex)4
			},
			new CategoryDef
			{
				Id = Cat.Geodes,
				Key = "AurelioniteGeodes",
				Label = "Aurelionite Geode",
				Section = "Storm & Collective",
				Hex = "FFFCC4"
			},
			new CategoryDef
			{
				Id = Cat.AccessNodes,
				Key = "AccessNodes",
				Label = "Access Node",
				Section = "Storm & Collective",
				Hex = "1CB8DB"
			},
			new CategoryDef
			{
				Id = Cat.TempItemDistributors,
				Key = "TempItemDistributors",
				Label = "Temporary Item Distributor",
				Section = "Storm & Collective",
				Hex = "1CB8DB"
			},
			new CategoryDef
			{
				Id = Cat.WanderingChef,
				Key = "WanderingChef",
				Label = "Wandering CHEF",
				Section = "Storm & Collective",
				Hex = "1CB8DB"
			},
			new CategoryDef
			{
				Id = Cat.ConceptReliquaries,
				Key = "ConceptReliquaries",
				Label = "Concept Reliquary",
				Section = "Hallowed",
				ColorIdx = (ColorIndex)35
			},
			new CategoryDef
			{
				Id = Cat.GhostlyChests,
				Key = "GhostlyChests",
				Label = "Ghostly Chest",
				Section = "Hallowed",
				ColorIdx = (ColorIndex)35
			},
			new CategoryDef
			{
				Id = Cat.Gongs,
				Key = "Gongs",
				Label = "Gong",
				Section = "Hallowed",
				ColorIdx = (ColorIndex)40
			},
			new CategoryDef
			{
				Id = Cat.AnimaPortals,
				Key = "AnimaPortals",
				Label = "Anima Portal",
				Section = "Hallowed",
				ColorIdx = (ColorIndex)24
			},
			new CategoryDef
			{
				Id = Cat.Uncategorized,
				Key = "Uncategorized",
				Label = "Other",
				Section = "Other",
				Hex = "8B8B8B"
			}
		};

		public static readonly DroneCategoryDef[] DroneTypes = new DroneCategoryDef[5]
		{
			new DroneCategoryDef
			{
				Id = DroneCat.GunnerTurret,
				Key = "GunnerTurret",
				Label = "Gunner Turret"
			},
			new DroneCategoryDef
			{
				Id = DroneCat.TripleShop,
				Key = "TripleDroneShop",
				Label = "Triple Drone Shop"
			},
			new DroneCategoryDef
			{
				Id = DroneCat.DroneScrapper,
				Key = "DroneScrapper",
				Label = "Drone Scrapper"
			},
			new DroneCategoryDef
			{
				Id = DroneCat.DroneCombiner,
				Key = "DroneCombiner",
				Label = "Drone Combiner Station"
			},
			new DroneCategoryDef
			{
				Id = DroneCat.BrokenDrones,
				Key = "BrokenDronesByType",
				Label = "Broken Drones"
			}
		};

		public static readonly Dictionary<string, Cat> DisplayNameMap = new Dictionary<string, Cat>
		{
			["Shipping Request Form"] = Cat.ShippingRequests,
			["Aurelionite Fragment"] = Cat.Geodes,
			["Aurelionite Geode"] = Cat.Geodes
		};

		public static CategoryDef Get(Cat id)
		{
			for (int i = 0; i < Loot.Length; i++)
			{
				if (Loot[i].Id == id)
				{
					return Loot[i];
				}
			}
			return null;
		}
	}
	public sealed class DroneData
	{
		public readonly struct BrokenGroup
		{
			public int DroneIndex { get; }

			public string Label { get; }

			public string ColorHex { get; }

			public int Available { get; }

			public int Total { get; }

			public BrokenGroup(int droneIndex, string label, string colorHex, int available, int total)
			{
				DroneIndex = droneIndex;
				Label = label;
				ColorHex = colorHex;
				Available = available;
				Total = total;
			}
		}

		public int TurretAvailable;

		public int TurretTotal;

		public int TripleShopAvailable;

		public int TripleShopTotal;

		public bool DroneScrapperPresent;

		public bool DroneCombinerPresent;

		public readonly List<BrokenGroup> Broken = new List<BrokenGroup>();
	}
	public static class DroneScan
	{
		private static readonly Dictionary<string, DroneDef> BrokenPrefabMap = new Dictionary<string, DroneDef>();

		private static bool BrokenPrefabMapBuilt;

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

		private static void EnsureBrokenPrefabMap()
		{
			if (BrokenPrefabMapBuilt)
			{
				return;
			}
			BrokenPrefabMapBuilt = true;
			foreach (DroneDef allDroneDef in DroneCatalog.allDroneDefs)
			{
				if (!Object.op_Implicit((Object)(object)allDroneDef))
				{
					continue;
				}
				SpawnCard droneBrokenSpawnCard = allDroneDef.droneBrokenSpawnCard;
				GameObject val = (Object.op_Implicit((Object)(object)droneBrokenSpawnCard) ? droneBrokenSpawnCard.prefab : null);
				if (Object.op_Implicit((Object)(object)val))
				{
					string key = StripClone(((Object)val).name);
					if (!BrokenPrefabMap.ContainsKey(key))
					{
						BrokenPrefabMap[key] = allDroneDef;
					}
				}
			}
		}

		private static string StripClone(string name)
		{
			if (name == null || !name.EndsWith("(Clone)"))
			{
				return name;
			}
			return name.Substring(0, name.Length - 7);
		}

		public static DroneData Scan()
		{
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected I4, but got Unknown
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Expected I4, but got Unknown
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			EnsureBrokenPrefabMap();
			DroneData droneData = new DroneData();
			SortedDictionary<int, (string, string, int, int)> sortedDictionary = new SortedDictionary<int, (string, string, int, int)>();
			SortedDictionary<string, (int, int)> sortedDictionary2 = new SortedDictionary<string, (int, int)>();
			List<PurchaseInteraction> instancesList = InstanceTracker.GetInstancesList<PurchaseInteraction>();
			for (int i = 0; i < instancesList.Count; i++)
			{
				PurchaseInteraction val = instancesList[i];
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				GameObject gameObject = ((Component)val).gameObject;
				string displayNameToken = val.displayNameToken;
				if (displayNameToken != null && displayNameToken.StartsWith("TURRET1"))
				{
					droneData.TurretTotal++;
					if (val.available)
					{
						droneData.TurretAvailable++;
					}
					continue;
				}
				if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<DroneVendorTerminalBehavior>(true)) || Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<DroneVendorMultiShopController>(true)) || displayNameToken == "DRONE_VENDOR_TERMINAL_NAME")
				{
					droneData.TripleShopTotal++;
					if (val.available)
					{
						droneData.TripleShopAvailable++;
					}
					continue;
				}
				if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<DroneScrapperController>(true)) || displayNameToken == "DRONE_SCRAPPER_NAME")
				{
					droneData.DroneScrapperPresent = true;
					continue;
				}
				if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<DroneCombinerController>(true)))
				{
					droneData.DroneCombinerPresent = true;
					continue;
				}
				DroneDef value;
				DroneDef val2 = (BrokenPrefabMap.TryGetValue(StripClone(((Object)gameObject).name), out value) ? value : null);
				if (Object.op_Implicit((Object)(object)val2))
				{
					sortedDictionary.TryGetValue((int)val2.droneIndex, out var value2);
					value2.Item4++;
					if (val.available)
					{
						value2.Item3++;
					}
					if (value2.Item1 == null)
					{
						value2.Item1 = Lang.TryGet(val2.nameToken) ?? ((Object)val2).name;
						value2.Item2 = (((int)val2.colorOverride != 0) ? Palette.Hex(val2.colorOverride) : Palette.Hex(val2.tier));
					}
					sortedDictionary[(int)val2.droneIndex] = value2;
				}
				else if (val.isDrone || (displayNameToken != null && displayNameToken.Contains("DRONE")))
				{
					string text = val.GetDisplayName();
					if (string.IsNullOrEmpty(text))
					{
						text = ((Object)gameObject).name;
					}
					if (_loggedFallbacks.Add(text))
					{
						Plugin.Log.LogInfo((object)("Unmapped drone interactable '" + text + "' (token='" + displayNameToken + "', go='" + ((Object)gameObject).name + "') — shown gray in the drone panel."));
					}
					sortedDictionary2.TryGetValue(text, out var value3);
					value3.Item2++;
					if (val.available)
					{
						value3.Item1++;
					}
					sortedDictionary2[text] = value3;
				}
			}
			foreach (KeyValuePair<int, (string, string, int, int)> item in sortedDictionary)
			{
				droneData.Broken.Add(new DroneData.BrokenGroup(item.Key, item.Value.Item1, item.Value.Item2 ?? "8B8B8B", item.Value.Item3, item.Value.Item4));
			}
			foreach (KeyValuePair<string, (int, int)> item2 in sortedDictionary2)
			{
				droneData.Broken.Add(new DroneData.BrokenGroup(int.MaxValue, item2.Key, "8B8B8B", item2.Value.Item1, item2.Value.Item2));
			}
			return droneData;
		}
	}
	public sealed class LootData
	{
		public readonly Dictionary<Cat, (int available, int total)> Counts = new Dictionary<Cat, (int, int)>();

		public readonly List<(string label, int available, int total)> Unknown = new List<(string, int, int)>();

		public readonly int[] PrinterAvailable = new int[5];

		public readonly int[] PrinterTotal = new int[5];

		public readonly int[] CauldronAvailable = new int[5];

		public readonly int[] CauldronTotal = new int[5];

		public int MonsterEnemies;

		public int VoidEnemies;

		public int Invitations;

		public int ChancePurchasesLeft;

		public bool IsHost;

		public string StageName;
	}
	public static class LootScan
	{
		private static readonly Dictionary<string, Cat> TokenMap = new Dictionary<string, Cat>
		{
			["CHEST1_STEALTHED_NAME"] = Cat.CloakedChest,
			["CASINOCHEST_NAME"] = Cat.AdaptiveChest,
			["EQUIPMENTBARREL_NAME"] = Cat.EquipmentBarrel,
			["LOCKBOX_NAME"] = Cat.RustyLockbox,
			["VOIDLOCKBOX_NAME"] = Cat.EncrustedCache,
			["SHRINE_CHANCE_NAME"] = Cat.ShrineChance,
			["SHRINE_CLEANSE_NAME"] = Cat.CleansingPool,
			["LUNAR_CHEST_NAME"] = Cat.LunarPod,
			["LUNARSEER_NAME"] = Cat.LunarSeer,
			["VOID_CHEST_NAME"] = Cat.VoidChests,
			["VOID_TRIPLE_NAME"] = Cat.VoidChests
		};

		private static readonly FieldInfo ChanceSuccessField = typeof(ShrineChanceBehavior).GetField("successfulPurchaseCount", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo BossPurchaseField = typeof(ShrineBossBehavior).GetField("purchaseCount", BindingFlags.Instance | BindingFlags.NonPublic);

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

		private static bool BelongsToDronePanel(PurchaseInteraction purchase)
		{
			if (purchase.isDrone)
			{
				return true;
			}
			string displayNameToken = purchase.displayNameToken;
			if (displayNameToken != null)
			{
				if (!displayNameToken.StartsWith("TURRET1"))
				{
					return displayNameToken == "DRONE_SCRAPPER_NAME";
				}
				return true;
			}
			return false;
		}

		public static LootData Scan()
		{
			//IL_0124: 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)
			LootData lootData = new LootData();
			lootData.IsHost = NetworkServer.active;
			Dictionary<string, (int, int)> dictionary = new Dictionary<string, (int, int)>();
			List<PurchaseInteraction> instancesList = InstanceTracker.GetInstancesList<PurchaseInteraction>();
			for (int i = 0; i < instancesList.Count; i++)
			{
				PurchaseInteraction val = instancesList[i];
				if (!Object.op_Implicit((Object)(object)val) || BelongsToDronePanel(val))
				{
					continue;
				}
				Cat? cat = Classify(val);
				if (!cat.HasValue)
				{
					string text = val.GetDisplayName();
					if (string.IsNullOrEmpty(text))
					{
						text = ((Object)((Component)val).gameObject).name;
					}
					if (_loggedUnknowns.Add(text))
					{
						Plugin.Log.LogInfo((object)$"Uncategorized interactable '{text}' (token='{val.displayNameToken}', cost={val.costType}, go='{((Object)((Component)val).gameObject).name}') — it will show gray under Other until it gets its own category.");
					}
					dictionary.TryGetValue(text, out var value);
					value.Item2++;
					if (val.available)
					{
						value.Item1++;
					}
					dictionary[text] = value;
				}
				else if (cat == Cat.Printers || cat == Cat.Cauldrons)
				{
					int num = Palette.CostBucket(val.costType, ((Object)((Component)val).gameObject).name);
					int[] obj = ((cat == Cat.Printers) ? lootData.PrinterTotal : lootData.CauldronTotal);
					int[] array = ((cat == Cat.Printers) ? lootData.PrinterAvailable : lootData.CauldronAvailable);
					obj[num]++;
					if (val.available)
					{
						array[num]++;
					}
				}
				else
				{
					lootData.Counts.TryGetValue(cat.Value, out (int, int) value2);
					value2.Item2++;
					if (val.available)
					{
						value2.Item1++;
					}
					lootData.Counts[cat.Value] = value2;
				}
			}
			foreach (KeyValuePair<string, (int, int)> item in dictionary)
			{
				lootData.Unknown.Add((item.Key, item.Value.Item1, item.Value.Item2));
			}
			lootData.Unknown.Sort(((string label, int available, int total) a, (string label, int available, int total) b) => string.CompareOrdinal(a.label, b.label));
			if (lootData.IsHost && ChanceSuccessField != null)
			{
				List<ShrineChanceBehavior> instancesList2 = InstanceTracker.GetInstancesList<ShrineChanceBehavior>();
				for (int num2 = 0; num2 < instancesList2.Count; num2++)
				{
					ShrineChanceBehavior val2 = instancesList2[num2];
					if (Object.op_Implicit((Object)(object)val2))
					{
						int num3 = (int)ChanceSuccessField.GetValue(val2);
						int num4 = val2.maxPurchaseCount - num3;
						if (num4 > 0)
						{
							lootData.ChancePurchasesLeft += num4;
						}
					}
				}
			}
			List<ShrineBossBehavior> instancesList3 = InstanceTracker.GetInstancesList<ShrineBossBehavior>();
			for (int num5 = 0; num5 < instancesList3.Count; num5++)
			{
				ShrineBossBehavior val3 = instancesList3[num5];
				if (Object.op_Implicit((Object)(object)val3))
				{
					int num6 = ((BossPurchaseField != null) ? ((int)BossPurchaseField.GetValue(val3)) : 0);
					int num7 = val3.maxPurchaseCount - num6;
					if (num7 > 0)
					{
						lootData.Invitations += num7;
					}
				}
			}
			lootData.MonsterEnemies = TeamComponent.GetTeamMembers((TeamIndex)2).Count;
			lootData.VoidEnemies = TeamComponent.GetTeamMembers((TeamIndex)4).Count;
			SceneInfo instance = SceneInfo.instance;
			if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.sceneDef))
			{
				lootData.StageName = Language.GetString(instance.sceneDef.nameToken);
			}
			return lootData;
		}

		private static Cat? Classify(PurchaseInteraction purchase)
		{
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Expected I4, but got Unknown
			if (!string.IsNullOrEmpty(purchase.displayNameToken))
			{
				if (TokenMap.TryGetValue(purchase.displayNameToken, out var value))
				{
					return value;
				}
				if (purchase.displayNameToken.StartsWith("DUPLICATOR"))
				{
					return Cat.Printers;
				}
				if (purchase.displayNameToken == "BAZAAR_CAULDRON_NAME")
				{
					return Cat.Cauldrons;
				}
				if (purchase.displayNameToken.StartsWith("SHRINE_BOSS"))
				{
					return Cat.ShrineMountain;
				}
			}
			if (purchase.isGoldShrine)
			{
				return Cat.AltarOfGold;
			}
			GameObject gameObject = ((Component)purchase).gameObject;
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineCompulsionBehaviour>(true)))
			{
				return Cat.ShrineCompulsion;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<HallowingShrineSplitBase>(true)))
			{
				return Cat.ShrineHallowed;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineRebirthController>(true)))
			{
				return Cat.ShrineRebirth;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<HalcyoniteShrineInteractable>(true)))
			{
				return Cat.ShrineHalcyon;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineCombatTroopBehavior>(true)))
			{
				return Cat.ShrineCombatCollective;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineCombatBehavior>(true)))
			{
				return Cat.ShrineCombat;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineDeathBehavior>(true)))
			{
				return Cat.ShrineCombat;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineHealingBehavior>(true)))
			{
				return Cat.ShrineWoods;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineRestackBehavior>(true)))
			{
				return Cat.ShrineOrder;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineBloodBehavior>(true)))
			{
				return Cat.ShrineBlood;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineChanceBehavior>(true)))
			{
				return Cat.ShrineChance;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineBossBehavior>(true)))
			{
				return Cat.ShrineMountain;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ShrineCleanseBehavior>(true)))
			{
				return Cat.CleansingPool;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<SolusVendorShrineController>(true)))
			{
				return Cat.TempItemDistributors;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<ScrapperController>(true)))
			{
				return Cat.Scrapper;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<BarrelInteraction>(true)))
			{
				return Cat.EquipmentBarrel;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<PortalStatueBehavior>(true)))
			{
				return Cat.NewtAltar;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<DroneVendorTerminalBehavior>(true)))
			{
				return null;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<DroneVendorMultiShopController>(true)))
			{
				return null;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<DroneCombinerController>(true)))
			{
				return null;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<DroneScrapperController>(true)))
			{
				return null;
			}
			if (Object.op_Implicit((Object)(object)gameObject.GetComponentInChildren<MultiShopController>(true)))
			{
				if (((Object)gameObject).name.Contains("Equipment"))
				{
					return Cat.EquipmentMultishop;
				}
				return Cat.Multishop;
			}
			if (((Object)gameObject).name.Contains("SecurityChest") || ((Object)gameObject).name.Contains("TimedChest"))
			{
				return Cat.SecurityChest;
			}
			if (((Object)gameObject).name.Contains("ScavengerBackpack"))
			{
				return Cat.ScavengerPack;
			}
			ChestBehavior componentInChildren = gameObject.GetComponentInChildren<ChestBehavior>(true);
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				if (componentInChildren.dropTable is FreeChestDropTable)
				{
					return Cat.CrashedMultishop;
				}
				ItemTag requiredItemTag = componentInChildren.requiredItemTag;
				switch (requiredItemTag - 1)
				{
				case 0:
					return Cat.ChestDamage;
				case 1:
					return Cat.ChestHealing;
				case 2:
					return Cat.ChestUtility;
				default:
					if (componentInChildren.tier3Chance >= 0.99f)
					{
						return Cat.ChestLegendary;
					}
					if (componentInChildren.tier2Chance >= 0.99f)
					{
						return Cat.ChestLarge;
					}
					return Cat.ChestSmall;
				}
			}
			string displayName = purchase.GetDisplayName();
			if (!string.IsNullOrEmpty(displayName) && Categories.DisplayNameMap.TryGetValue(displayName, out var value2))
			{
				return value2;
			}
			return null;
		}
	}
}
namespace StageTracker.Config
{
	public enum DisplayMode
	{
		HoldTab,
		AlwaysVisible
	}
	public sealed class ModConfig
	{
		public readonly ConfigEntry<DisplayMode> PanelMode;

		public readonly ConfigEntry<bool> ShowLootPanel;

		public readonly ConfigEntry<bool> ShowDronePanel;

		public readonly ConfigEntry<bool> ShowEnemies;

		public readonly ConfigEntry<bool> ShowInvitations;

		public readonly ConfigEntry<bool> ShowStageName;

		public readonly ConfigEntry<bool> TrackUncategorized;

		public readonly ConfigEntry<bool> ShowUsedOverTotal;

		public readonly IReadOnlyDictionary<Cat, ConfigEntry<bool>> LootToggles;

		public readonly IReadOnlyDictionary<DroneCat, ConfigEntry<bool>> DroneToggles;

		public bool Enabled(Cat id)
		{
			if (LootToggles.TryGetValue(id, out var value))
			{
				return value.Value;
			}
			return false;
		}

		public bool Enabled(DroneCat id)
		{
			if (DroneToggles.TryGetValue(id, out var value))
			{
				return value.Value;
			}
			return false;
		}

		public ModConfig(ConfigFile file)
		{
			PanelMode = file.Bind<DisplayMode>("Display", "DisplayMode", DisplayMode.HoldTab, "HoldTab: panels only appear while the scoreboard (Tab) is held. AlwaysVisible: panels stay docked on the right side of the screen.");
			ShowLootPanel = file.Bind<bool>("Display", "ShowLootPanel", true, "Show the loot panel.");
			ShowDronePanel = file.Bind<bool>("Display", "ShowDronePanel", true, "Show the drone panel.");
			ShowUsedOverTotal = file.Bind<bool>("Display", "ShowUsedOverTotal", true, "Always show counts as used/total (e.g. 'Chest: 5/6') instead of only the remaining amount (e.g. 'Chest: 6') when nothing has been used yet.");
			ShowEnemies = file.Bind<bool>("Footer", "ShowEnemyCounts", true, "Show remaining enemy counts by team.");
			ShowInvitations = file.Bind<bool>("Footer", "ShowInvitations", true, "Show how many Shrine of the Mountain invitations are still pending. Accurate on the host; approximate for clients.");
			ShowStageName = file.Bind<bool>("Footer", "ShowStageName", true, "Show the stage name at the bottom of the loot panel.");
			TrackUncategorized = file.Bind<bool>("Loot", "TrackUncategorized", true, "Also list interactables this mod doesn't know yet (e.g. content from a future update), grouped by their in-game name.");
			Dictionary<Cat, ConfigEntry<bool>> dictionary = new Dictionary<Cat, ConfigEntry<bool>>();
			CategoryDef[] loot = Categories.Loot;
			foreach (CategoryDef categoryDef in loot)
			{
				if (categoryDef.Id == Cat.Uncategorized)
				{
					dictionary[categoryDef.Id] = TrackUncategorized;
				}
				else
				{
					dictionary[categoryDef.Id] = file.Bind<bool>("Loot", categoryDef.Key, true, "Track " + categoryDef.Label + ".");
				}
			}
			LootToggles = dictionary;
			Dictionary<DroneCat, ConfigEntry<bool>> dictionary2 = new Dictionary<DroneCat, ConfigEntry<bool>>();
			DroneCategoryDef[] droneTypes = Categories.DroneTypes;
			foreach (DroneCategoryDef droneCategoryDef in droneTypes)
			{
				dictionary2[droneCategoryDef.Id] = file.Bind<bool>("Drones", droneCategoryDef.Key, true, "Track " + droneCategoryDef.Label + " in the drone panel.");
			}
			DroneToggles = dictionary2;
		}

		public void RegisterRiskOfOptions(string modName, string description, string modGuid)
		{
			if (!Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				Plugin.Log.LogInfo((object)"Risk of Options not installed; settings stay in the BepInEx config file.");
				return;
			}
			try
			{
				RegisterInternal(modName, description, modGuid);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Risk of Options registration failed (" + ex.GetType().Name + ": " + ex.Message + "); settings stay in the BepInEx config file."));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void RegisterInternal(string modName, string description, string modGuid)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			ModSettingsManager.SetModDescription(description, modGuid, modName);
			ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)PanelMode), modGuid, modName);
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ShowLootPanel), modGuid, modName);
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ShowDronePanel), modGuid, modName);
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ShowUsedOverTotal), modGuid, modName);
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ShowEnemies), modGuid, modName);
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ShowInvitations), modGuid, modName);
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ShowStageName), modGuid, modName);
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(TrackUncategorized), modGuid, modName);
			CategoryDef[] loot = Categories.Loot;
			foreach (CategoryDef categoryDef in loot)
			{
				if (categoryDef.Id != Cat.Uncategorized)
				{
					ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(LootToggles[categoryDef.Id]), modGuid, modName);
				}
			}
			DroneCategoryDef[] droneTypes = Categories.DroneTypes;
			foreach (DroneCategoryDef droneCategoryDef in droneTypes)
			{
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(DroneToggles[droneCategoryDef.Id]), modGuid, modName);
			}
			try
			{
				object obj = typeof(ModSettingsManager).GetField("OptionCollection", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null);
				object obj2 = (obj?.GetType().GetProperty("Item", BindingFlags.Instance | BindingFlags.NonPublic))?.GetValue(obj, new object[1] { modGuid });
				PropertyInfo? obj3 = obj2?.GetType().GetProperty("CategoryCount", BindingFlags.Instance | BindingFlags.NonPublic);
				Plugin.Log.LogInfo((object)$"RiskOfOptions self-check: categories for {modGuid} = {obj3?.GetValue(obj2)}");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("RiskOfOptions self-check failed: " + ex.Message));
			}
		}
	}
}