Decompiled source of Wheres My Loot v1.0.0

wheres_my_loot.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PerfectRandom.Sulfur.Core;
using PerfectRandom.Sulfur.Core.Items;
using PerfectRandom.Sulfur.Core.UI;
using PerfectRandom.Sulfur.Core.UI.Inventory;
using PerfectRandom.Sulfur.Gameplay.Input;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;
using WheresMyLoot.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("wheres_my_loot")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("wheres_my_loot")]
[assembly: AssemblyTitle("wheres_my_loot")]
[assembly: AssemblyVersion("1.0.0.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 WheresMyLoot.Unity
{
	internal static class GameBridge
	{
		private static Dictionary<string, ItemDefinition> byKey;

		private static ItemDatabase indexedDb;

		public static ItemDatabase ItemDb
		{
			get
			{
				AsyncAssetLoading instance = StaticInstance<AsyncAssetLoading>.Instance;
				if (instance == null)
				{
					return null;
				}
				return instance.itemDatabase;
			}
		}

		public static bool InventoryOpen
		{
			get
			{
				UIManager instance = StaticInstance<UIManager>.Instance;
				if ((Object)(object)instance != (Object)null && (Object)(object)instance.InventoryUI != (Object)null && instance.InventoryUI.IsOpened)
				{
					return SulfurSaveState.active != null;
				}
				return false;
			}
		}

		public static bool DraggingItem
		{
			get
			{
				UIManager instance = StaticInstance<UIManager>.Instance;
				if ((Object)(object)instance != (Object)null && (Object)(object)instance.InventoryUI != (Object)null)
				{
					return (Object)(object)instance.InventoryUI.draggingItem != (Object)null;
				}
				return false;
			}
		}

		public static int Slot => SulfurSaveState.active?.slotIndex ?? (-1);

		public static SulfurSaveState Save => SulfurSaveState.active;

		public static IReadOnlyDictionary<string, ItemDefinition> Items
		{
			get
			{
				ItemDatabase itemDb = ItemDb;
				if ((Object)(object)itemDb == (Object)null)
				{
					return new Dictionary<string, ItemDefinition>();
				}
				if (byKey != null && (Object)(object)indexedDb == (Object)(object)itemDb)
				{
					return byKey;
				}
				Dictionary<string, ItemDefinition> dictionary = new Dictionary<string, ItemDefinition>(StringComparer.Ordinal);
				foreach (ItemDefinition raw in itemDb.GetRawList())
				{
					if (!((Object)(object)raw == (Object)null) && !string.IsNullOrEmpty(((Object)raw).name) && !raw.deprecated)
					{
						bool flag;
						try
						{
							flag = raw.AllowedInGame;
						}
						catch (Exception)
						{
							flag = raw.includedInEarlyAccess;
						}
						if (flag && !dictionary.ContainsKey(((Object)raw).name))
						{
							dictionary[((Object)raw).name] = raw;
						}
					}
				}
				byKey = dictionary;
				indexedDb = itemDb;
				return dictionary;
			}
		}

		public static ItemDefinition Find(string key)
		{
			if (key == null || !Items.TryGetValue(key, out var value))
			{
				return null;
			}
			return value;
		}

		public static string NameOf(ItemDefinition def)
		{
			if ((Object)(object)def == (Object)null)
			{
				return "?";
			}
			try
			{
				string localizedDisplayName = def.LocalizedDisplayName;
				return string.IsNullOrWhiteSpace(localizedDisplayName) ? ((Object)def).name : localizedDisplayName.Trim();
			}
			catch (Exception)
			{
				return string.IsNullOrWhiteSpace(def.displayName) ? ((Object)def).name : def.displayName;
			}
		}

		public static string NameOf(string key)
		{
			ItemDefinition val = Find(key);
			if (val == null)
			{
				return key;
			}
			return NameOf(val);
		}

		public static Sprite IconOf(string key)
		{
			return Find(key)?.artwork;
		}

		public static Color? QualityColor(ItemDefinition def)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)def == (Object)null)
			{
				return null;
			}
			try
			{
				LootManager instance = StaticInstance<LootManager>.Instance;
				if ((Object)(object)instance == (Object)null)
				{
					return null;
				}
				Color qualityColor = instance.GetQualityColor(def.itemQuality);
				return (qualityColor == Color.white) ? ((Color?)null) : new Color?(qualityColor);
			}
			catch (Exception)
			{
				return null;
			}
		}

		public static string CategoryOf(ItemDefinition def)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Invalid comparison between Unknown and I4
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between Unknown and I4
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected I4, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)def == (Object)null)
			{
				return "";
			}
			string text = ((Object)def).name ?? "";
			if (text.StartsWith("Valuable", StringComparison.Ordinal))
			{
				return "Valuable";
			}
			if ((int)def.slotType == 7)
			{
				return "Weapon";
			}
			if (text.StartsWith("Ammo", StringComparison.Ordinal))
			{
				return "Ammo";
			}
			UseType useType = def.useType;
			if ((int)useType != 2)
			{
				if ((int)useType == 3)
				{
					return "Scroll / oil";
				}
				SlotType slotType = def.slotType;
				switch (slotType - 1)
				{
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
					return "Armor";
				case 0:
					return "Gadget";
				case 8:
					return "Amulet";
				default:
					if ((int)def.useType != 0)
					{
						return "";
					}
					return "Consumable";
				}
			}
			return "Attachment";
		}

		public static List<ItemEntry> SearchEntries()
		{
			return Items.Values.Select((ItemDefinition d) => new ItemEntry(((Object)d).name, NameOf(d), CategoryOf(d))).ToList();
		}

		public static RecipeBook Recipes()
		{
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_006b: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			AsyncAssetLoading instance = StaticInstance<AsyncAssetLoading>.Instance;
			RecipeDatabase val = ((instance != null) ? instance.recipeDatabase : null);
			ItemDatabase itemDb = ItemDb;
			if ((Object)(object)val == (Object)null || (Object)(object)itemDb == (Object)null)
			{
				return RecipeBook.Empty;
			}
			List<RecipeInfo> list = new List<RecipeInfo>();
			RecipeData[] rawList;
			try
			{
				rawList = val.GetRawList();
			}
			catch (Exception)
			{
				return RecipeBook.Empty;
			}
			if (rawList == null)
			{
				return RecipeBook.Empty;
			}
			RecipeData[] array = rawList;
			for (int i = 0; i < array.Length; i++)
			{
				RecipeData val2 = array[i];
				if (!val2.canBeCrafted)
				{
					continue;
				}
				ItemId createsItem = val2.createsItem;
				if (!((ItemId)(ref createsItem)).IsValid || val2.itemsNeeded == null || val2.itemsNeeded.Count == 0)
				{
					continue;
				}
				string text = KeyOf(itemDb, val2.createsItem);
				if (text == null)
				{
					continue;
				}
				List<Ingredient> list2 = new List<Ingredient>();
				bool flag = true;
				foreach (IngredientDefinition item in val2.itemsNeeded)
				{
					string text2 = KeyOf(itemDb, item.item);
					if (text2 == null || item.quantity <= 0)
					{
						flag = false;
						break;
					}
					list2.Add(new Ingredient(text2, item.quantity));
				}
				if (flag)
				{
					bool learned;
					try
					{
						learned = ((RecipeData)(ref val2)).IsLearned;
					}
					catch (Exception)
					{
						learned = false;
					}
					list.Add(new RecipeInfo(val2.name, text, val2.quantityCreated, list2, learned));
				}
			}
			return new RecipeBook(list);
		}

		private static string KeyOf(ItemDatabase db, ItemId id)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (!((ItemId)(ref id)).IsValid)
			{
				return null;
			}
			try
			{
				ItemDefinition obj = db[id];
				return (obj != null) ? ((Object)obj).name : null;
			}
			catch (Exception)
			{
				return null;
			}
		}

		public static int CountOf(string key, bool countEquipped)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			ItemDefinition val = Find(key);
			UIManager instance = StaticInstance<UIManager>.Instance;
			ItemGrid val2 = ((instance != null) ? instance.PlayerBackpackGrid : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return 0;
			}
			try
			{
				if (countEquipped)
				{
					return val2.ItemCount(val.id);
				}
				int num = 0;
				foreach (InventoryItem item in val2.AllItemsInGridOnly())
				{
					if ((Object)(object)item != (Object)null && (Object)(object)item.itemDefinition != (Object)null && item.itemDefinition.id == val.id)
					{
						num++;
					}
				}
				return num;
			}
			catch (Exception)
			{
				return 0;
			}
		}

		public static Dictionary<ItemId, int> StashCounts()
		{
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<ItemId, int> dictionary = new Dictionary<ItemId, int>();
			try
			{
				SulfurSaveState active = SulfurSaveState.active;
				if (active == null || active.STASH == null)
				{
					return dictionary;
				}
				UIManager instance = StaticInstance<UIManager>.Instance;
				InventoryUI val = ((instance != null) ? instance.InventoryUI : null);
				HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
				foreach (KeyValuePair<string, SerializableList<InventoryData>> item in (Dictionary<string, SerializableList<InventoryData>>)(object)active.STASH)
				{
					string text = ((item.Key == "Stash") ? "" : ((item.Key != null && item.Key.StartsWith("Stash_", StringComparison.Ordinal)) ? item.Key.Substring(6) : null));
					if (text == null)
					{
						continue;
					}
					hashSet.Add(text);
					ItemGrid val2 = LiveStash(val, text);
					if ((Object)(object)val2 != (Object)null)
					{
						CountGrid(val2, dictionary);
					}
					else
					{
						if (item.Value?.list == null)
						{
							continue;
						}
						foreach (InventoryData item2 in item.Value.list)
						{
							if (item2 != null && !item2.equipped)
							{
								Add(dictionary, item2.id);
							}
						}
					}
				}
				string text2 = (((Object)(object)val != (Object)null) ? val.CurrentStashIdentifier : null);
				if (text2 != null && !hashSet.Contains(text2))
				{
					ItemGrid val3 = LiveStash(val, text2);
					if (val3 != null)
					{
						CountGrid(val3, dictionary);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Where's My Loot: could not count the stash: " + ex.Message));
				}
			}
			return dictionary;
		}

		private static ItemGrid LiveStash(InventoryUI inv, string id)
		{
			if ((Object)(object)inv == (Object)null)
			{
				return null;
			}
			try
			{
				ItemGrid stashItemGrid = inv.GetStashItemGrid(id);
				return ((Object)(object)stashItemGrid != (Object)null) ? stashItemGrid : null;
			}
			catch (Exception)
			{
				return null;
			}
		}

		private static void CountGrid(ItemGrid grid, Dictionary<ItemId, int> res)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			foreach (GridSlot usedSlot in grid.GetUsedSlots())
			{
				InventoryItem val = ((usedSlot != null) ? usedSlot.ItemInSlot : null);
				if ((Object)(object)val != (Object)null && (Object)(object)val.itemDefinition != (Object)null)
				{
					Add(res, val.itemDefinition.id);
				}
			}
		}

		private static void Add(Dictionary<ItemId, int> res, ItemId id)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			res[id] = ((!res.TryGetValue(id, out var value)) ? 1 : (value + 1));
		}

		public static ItemId? IdOf(string key)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			return Find(key)?.id;
		}

		public static IEnumerable<InputActionMap> KeyboardMaps()
		{
			GameManager instance = StaticInstance<GameManager>.Instance;
			PlayerInputActions actions = ((instance != null) ? instance.InputActions : null);
			if (actions != null)
			{
				InventoryActions inventory = actions.Inventory;
				yield return ((InventoryActions)(ref inventory)).Get();
				OnFootActions onFoot = actions.OnFoot;
				yield return ((OnFootActions)(ref onFoot)).Get();
				FKeysActions fKeys = actions.FKeys;
				yield return ((FKeysActions)(ref fKeys)).Get();
			}
		}

		public static TMP_FontAsset FindFont(params string[] names)
		{
			TMP_FontAsset[] source = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			foreach (string n in names)
			{
				TMP_FontAsset val = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset a) => (Object)(object)a != (Object)null && ((Object)a).name == n));
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset a) => (Object)(object)a != (Object)null && ((Object)a).name.StartsWith("Fredoka", StringComparison.Ordinal))) ?? TMP_Settings.defaultFontAsset;
		}
	}
	internal sealed class GoalsWindow
	{
		private const float W = 660f;

		private const float H = 840f;

		private const float Pad = 10f;

		private const float RowH = 60f;

		private const float ChildRowH = 48f;

		private const float VariantH = 30f;

		private const float ConfirmH = 34f;

		private const float TickSeconds = 0.25f;

		private const int MaxResults = 8;

		private const int MaxVisibleVariants = 6;

		private readonly Plugin plugin;

		private GameObject root;

		private RectTransform panel;

		private TextMeshProUGUI subtitle;

		private TextMeshProUGUI keyLabel;

		private TextMeshProUGUI amountText;

		private RectTransform recsArea;

		private RectTransform listViewport;

		private RectTransform listContent;

		private RectTransform dropdown;

		private TMP_InputField search;

		private Image hideKnob;

		private RectTransform hideTrack;

		private Image panelFill;

		private TextMeshProUGUI ownedNote;

		private List<RowState> rows = new List<RowState>();

		private Recommendation rec = new Recommendation();

		private List<ItemEntry> results = new List<ItemEntry>();

		private int highlight;

		private int addAmount = 1;

		private Goal variantsOpen;

		private Goal confirmRemove;

		private float variantScrollY = -1f;

		private string lastSignature;

		private float nextTick;

		public Action RequestClose;

		private GoalsModel Model => plugin.Model;

		public bool IsOpen
		{
			get
			{
				if ((Object)(object)root != (Object)null)
				{
					return root.activeSelf;
				}
				return false;
			}
		}

		public bool IsTyping
		{
			get
			{
				if (IsOpen && (Object)(object)search != (Object)null)
				{
					return search.isFocused;
				}
				return false;
			}
		}

		private string OwnedText()
		{
			return "Owned = backpack" + (plugin.CountEquipped.Value ? " + equipped" : "") + (plugin.CountStash.Value ? " + stash" : "");
		}

		public GoalsWindow(Plugin plugin)
		{
			this.plugin = plugin;
		}

		public void Show()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_005d: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)root == (Object)null)
			{
				Build();
			}
			root.SetActive(true);
			Color val = Theme.Panel;
			((Graphic)panelFill).color = new Color(val.r, val.g, val.b, Mathf.Clamp(plugin.Opacity.Value, 0.5f, 1f));
			Ui.SetText(keyLabel, ((object)plugin.OpenKey.Value/*cast due to .constrained prefix*/).ToString());
			Ui.SetText(ownedNote, OwnedText());
			variantsOpen = (confirmRemove = null);
			Refresh(force: true);
		}

		public void Hide()
		{
			if (!((Object)(object)root == (Object)null))
			{
				if ((Object)(object)search != (Object)null)
				{
					search.DeactivateInputField(false);
					search.text = "";
				}
				results.Clear();
				if ((Object)(object)EventSystem.current != (Object)null && (Object)(object)EventSystem.current.currentSelectedGameObject != (Object)null && EventSystem.current.currentSelectedGameObject.transform.IsChildOf(root.transform))
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
				root.SetActive(false);
			}
		}

		public void Dispose()
		{
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			root = null;
		}

		public void Tick()
		{
			HandleSearchKeys();
			if (Time.unscaledTime >= nextTick)
			{
				Refresh(force: false);
			}
		}

		private void Refresh(bool force)
		{
			nextTick = Time.unscaledTime + 0.25f;
			rows = Model.Evaluate(plugin.CountEquipped.Value, plugin.CountStash.Value);
			rec = Recommender.Recommend(rows, Model.Drops);
			string text = Signature();
			if (force || !(text == lastSignature))
			{
				lastSignature = text;
				RenderHeader();
				RenderRecommendations();
				RenderList();
				RenderHideToggle();
			}
		}

		private string Signature()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(Model.Book.HideDone).Append('|').Append(variantsOpen?.GetHashCode())
				.Append('|')
				.Append(confirmRemove?.GetHashCode())
				.Append('|');
			foreach (RowState row in rows)
			{
				stringBuilder.Append(row.Goal.GetHashCode()).Append(':').Append(row.Target)
					.Append('/')
					.Append(row.Owned)
					.Append(row.Done ? 'D' : '-')
					.Append(row.Crafts)
					.Append(row.Recipe?.Name)
					.Append(row.Goal.ShowMaterials ? 'M' : '-')
					.Append(';');
			}
			stringBuilder.Append('|').Append(rec.State);
			foreach (AreaPick pick in rec.Picks)
			{
				stringBuilder.Append(pick.Area).Append(string.Join(",", pick.Items)).Append(';');
			}
			return stringBuilder.ToString();
		}

		private void Changed()
		{
			Model.Save();
			Refresh(force: true);
		}

		private void Build()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00e2: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			Ui.Font = GameBridge.FindFont("Fredoka-Medium SDF", "Fredoka-Regular SDF", "Fredoka-SemiBold SDF");
			Ui.FontBold = GameBridge.FindFont("Fredoka-SemiBold SDF", "Fredoka-Medium SDF");
			root = new GameObject("WheresMyLootCanvas", new Type[4]
			{
				typeof(RectTransform),
				typeof(Canvas),
				typeof(CanvasScaler),
				typeof(GraphicRaycaster)
			});
			root.layer = 5;
			Object.DontDestroyOnLoad((Object)(object)root);
			Canvas component = root.GetComponent<Canvas>();
			component.renderMode = (RenderMode)0;
			component.sortingOrder = 31000;
			CanvasScaler component2 = root.GetComponent<CanvasScaler>();
			component2.uiScaleMode = (ScaleMode)1;
			component2.referenceResolution = new Vector2(1920f, 1080f);
			component2.matchWidthOrHeight = 0.5f;
			panel = Ui.Rect("Window", root.transform);
			RectTransform obj = panel;
			RectTransform obj2 = panel;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 0.5f);
			obj2.anchorMax = val;
			obj.anchorMin = val;
			panel.pivot = new Vector2(1f, 0.5f);
			panel.sizeDelta = new Vector2(660f, 840f);
			panel.anchoredPosition = new Vector2(plugin.WindowX.Value, plugin.WindowY.Value);
			RectTransform val2 = Ui.Frame(panel, Theme.Amber, Theme.Panel);
			panelFill = ((Component)val2).GetComponent<Image>();
			((Graphic)panelFill).raycastTarget = true;
			BuildHeader(val2);
			float num = 50f;
			Ui.Tab(val2, "Recommended next", 10f, num);
			recsArea = Ui.Place(Ui.Rect("Recommended", (Transform)(object)val2), 10f, num + 19f, 638f, 62f);
			num += 93f;
			BuildAddRow(val2, num);
			num += 48f;
			Ui.Tab(val2, "Goals", 10f, num);
			num += 19f;
			float num2 = 38f;
			RectTransform frame = Ui.Place(Ui.Rect("List", (Transform)(object)val2), 10f, num, 638f, 838f - num - num2 - 10f);
			BuildList(frame);
			BuildFooter(val2, num2);
			BuildDropdown(val2);
		}

		private void BuildHeader(RectTransform inside)
		{
			//IL_0026: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = Ui.Place(Ui.Rect("Header", (Transform)(object)inside), 0f, 0f, 658f, 40f);
			Ui.Image(val, Theme.Amber, raycast: true);
			DragHandle dragHandle = ((Component)val).gameObject.AddComponent<DragHandle>();
			dragHandle.Target = panel;
			dragHandle.OnMoved = delegate
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				plugin.WindowX.Value = panel.anchoredPosition.x;
				plugin.WindowY.Value = panel.anchoredPosition.y;
			};
			TextMeshProUGUI obj = Ui.Label(val, "Title", "Where's My Loot?!?!", 22f, Theme.Ink, bold: true, (TextAlignmentOptions)4097);
			float num = Mathf.Ceil(Ui.Width(obj)) + 2f;
			Ui.Place(((TMP_Text)obj).rectTransform, 14f, 0f, num, 40f);
			float num2 = 14f + num + 12f;
			subtitle = Ui.Label(val, "Subtitle", "", 14f, new Color(0f, 0f, 0f, 0.7f), bold: false, (TextAlignmentOptions)4097);
			Ui.Place(((TMP_Text)subtitle).rectTransform, num2, 0f, Mathf.Max(60f, 536f - num2), 40f);
			RectTransform parent = Ui.Frame(Ui.Place(Ui.Rect("Key", (Transform)(object)val), 544f, 10f, 62f, 20f), Theme.Ink, Theme.Amber, 1.5f);
			keyLabel = Ui.Text(parent, "F9", 12f, Theme.Ink, bold: true, (TextAlignmentOptions)514);
			RectTransform obj2 = Ui.Place(Ui.Rect("Close", (Transform)(object)val), 622f, 8f, 26f, 24f);
			Ui.Button(obj2, delegate
			{
				RequestClose?.Invoke();
			}, Theme.Ink, Theme.Hex(3811856));
			Ui.Cross(obj2, Theme.Amber, 14f, 2.5f);
		}

		private void BuildAddRow(RectTransform inside, float y)
		{
			//IL_0032: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			float num = 10f;
			float num2 = 442f;
			RectTransform val = Ui.Place(Ui.Rect("Search", (Transform)(object)inside), num, y, num2, 36f);
			((Component)val).gameObject.SetActive(false);
			RectTransform val2 = Ui.Frame(val, Theme.Line, Theme.Cell);
			((Graphic)((Component)val2).GetComponent<Image>()).raycastTarget = true;
			RectTransform val3 = Ui.Fill(Ui.Rect("TextArea", (Transform)(object)val2), 12f, 2f, 8f, 2f);
			((Component)val3).gameObject.AddComponent<RectMask2D>();
			TextMeshProUGUI val4 = Ui.Text(val3, "Search item to track…", 16f, Theme.Text3, bold: false, (TextAlignmentOptions)4097);
			((TMP_Text)val4).fontStyle = (FontStyles)2;
			TextMeshProUGUI textComponent = Ui.Text(val3, "", 16f, Theme.Text, bold: false, (TextAlignmentOptions)4097);
			search = ((Component)val).gameObject.AddComponent<TMP_InputField>();
			search.textViewport = val3;
			search.textComponent = (TMP_Text)(object)textComponent;
			search.placeholder = (Graphic)(object)val4;
			if ((Object)(object)Ui.Font != (Object)null)
			{
				search.fontAsset = Ui.Font;
			}
			search.pointSize = 16f;
			search.lineType = (LineType)0;
			search.characterLimit = 48;
			search.customCaretColor = true;
			search.caretColor = Theme.Amber;
			search.selectionColor = new Color(0.984f, 0.69f, 0.251f, 0.35f);
			((Selectable)search).targetGraphic = (Graphic)(object)((Component)val2).GetComponent<Image>();
			TMP_InputField obj = search;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj).navigation = navigation;
			search.restoreOriginalTextOnEscape = false;
			search.resetOnDeActivation = false;
			((UnityEvent<string>)(object)search.onValueChanged).AddListener((UnityAction<string>)OnQuery);
			((UnityEvent<string>)(object)search.onSubmit).AddListener((UnityAction<string>)delegate
			{
				SubmitHighlighted();
			});
			((Component)val).gameObject.SetActive(true);
			num += num2 + 8f;
			RectTransform parent = Ui.Frame(Ui.Place(Ui.Rect("Amount", (Transform)(object)inside), num, y, 104f, 36f), Theme.Line, Theme.Cell);
			RectTransform obj2 = Ui.Place(Ui.Rect("Minus", (Transform)(object)parent), 0f, 0f, 30f, 34f);
			Ui.Button(obj2, delegate
			{
				StepAmount(-1);
			}, Theme.Clear, Theme.Hover);
			Ui.Text(obj2, "−", 20f, Theme.Amber, bold: true, (TextAlignmentOptions)514);
			amountText = Ui.Label(parent, "Value", "1", 17f, Theme.Text, bold: true, (TextAlignmentOptions)514);
			Ui.Place(((TMP_Text)amountText).rectTransform, 30f, 0f, 42f, 34f);
			RectTransform obj3 = Ui.Place(Ui.Rect("Plus", (Transform)(object)parent), 72f, 0f, 30f, 34f);
			Ui.Button(obj3, delegate
			{
				StepAmount(1);
			}, Theme.Clear, Theme.Hover);
			Ui.Text(obj3, "+", 20f, Theme.Amber, bold: true, (TextAlignmentOptions)514);
			num += 112f;
			Ui.Primary(Ui.Place(Ui.Rect("Add", (Transform)(object)inside), num, y, 76f, 36f), "Add", 16f, SubmitHighlighted);
		}

		private void BuildList(RectTransform frame)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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)
			RectTransform val = Ui.Frame(frame, Theme.Line, new Color(0f, 0f, 0f, 0.2f));
			ScrollRect obj = ((Component)val).gameObject.AddComponent<ScrollRect>();
			listViewport = Ui.Fill(Ui.Rect("Viewport", (Transform)(object)val));
			((Component)listViewport).gameObject.AddComponent<RectMask2D>();
			Ui.Image(listViewport, Theme.Clear, raycast: true);
			listContent = Ui.Rect("Content", (Transform)(object)listViewport);
			listContent.anchorMin = new Vector2(0f, 1f);
			listContent.anchorMax = new Vector2(1f, 1f);
			listContent.pivot = new Vector2(0.5f, 1f);
			listContent.anchoredPosition = Vector2.zero;
			listContent.sizeDelta = new Vector2(0f, 0f);
			obj.viewport = listViewport;
			obj.content = listContent;
			obj.horizontal = false;
			obj.vertical = true;
			obj.movementType = (MovementType)2;
			obj.scrollSensitivity = 40f;
			obj.inertia = false;
		}

		private void BuildFooter(RectTransform inside, float h)
		{
			//IL_0047: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			RectTransform parent = Ui.Place(Ui.Rect("Footer", (Transform)(object)inside), 0f, 838f - h, 658f, h);
			Ui.Image(Ui.Place(Ui.Rect("Line", (Transform)(object)parent), 0f, 0f, 658f, 1f), Theme.Line);
			ownedNote = Ui.Label(parent, "Note", OwnedText(), 13f, Theme.Text3, bold: false, (TextAlignmentOptions)4097);
			Ui.Place(((TMP_Text)ownedNote).rectTransform, 12f, 0f, 300f, h);
			Ui.Ghost(Ui.Place(Ui.Rect("ClearDone", (Transform)(object)parent), 552f, 7f, 96f, h - 14f), "Clear done", 13f, delegate
			{
				Model.Book.ClearDone(rows);
				Changed();
			});
			RectTransform val = Ui.Place(Ui.Rect("HideDone", (Transform)(object)parent), 430f, 7f, 110f, h - 14f);
			Ui.Button(val, delegate
			{
				Model.Book.HideDone = !Model.Book.HideDone;
				Changed();
			}, Theme.Clear, Theme.Hover);
			hideTrack = Ui.Place(Ui.Rect("Track", (Transform)(object)val), 4f, 5f, 28f, 14f);
			Ui.Frame(hideTrack, Theme.Line, Theme.Clear);
			hideKnob = Ui.Image(Ui.Place(Ui.Rect("Knob", (Transform)(object)hideTrack), 2f, 2f, 10f, 10f), Theme.Amber);
			Ui.Place(((TMP_Text)Ui.Label(val, "Label", "Hide done", 13f, Theme.Text2, bold: false, (TextAlignmentOptions)4097)).rectTransform, 38f, 0f, 72f, h - 14f);
		}

		private void BuildDropdown(RectTransform inside)
		{
			dropdown = Ui.Place(Ui.Rect("Results", (Transform)(object)inside), 10f, 179f, 442f, 10f);
			((Component)dropdown).gameObject.SetActive(false);
		}

		private void RenderHeader()
		{
			List<RowState> list = rows.Where((RowState r) => r.Parent == null).ToList();
			Ui.SetText(subtitle, (list.Count == 0) ? "nothing tracked" : $"{list.Count} tracked · {list.Count((RowState r) => r.Done)} done");
		}

		private void RenderRecommendations()
		{
			//IL_00c1: 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_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_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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			Clear(recsArea);
			if (rec.State != RecommendState.Ok)
			{
				RectTransform parent = Ui.Frame(Ui.Fill(Ui.Rect("Message", (Transform)(object)recsArea)), Theme.Line, Theme.Cell);
				((TMP_Text)Ui.Text(parent, rec.State switch
				{
					RecommendState.NoGoals => "Add an item below to get suggestions.", 
					RecommendState.AllDone => "All goals done.", 
					RecommendState.NoData => "Drop data missing (drop_sources.json): see the mod's README.", 
					_ => "What's left is found about the same everywhere, or not in runs at all.", 
				}, 14f, Theme.Text2, bold: false, (TextAlignmentOptions)514)).textWrappingMode = (TextWrappingModes)1;
				return;
			}
			Rect rect = recsArea.rect;
			float num;
			if (!(((Rect)(ref rect)).width > 0f))
			{
				num = 638f;
			}
			else
			{
				rect = recsArea.rect;
				num = ((Rect)(ref rect)).width;
			}
			float num2 = num / 3f;
			for (int i = 0; i < 3; i++)
			{
				RectTransform parent2 = Ui.Frame(Ui.Place(Ui.Rect("Cell" + i, (Transform)(object)recsArea), (float)i * num2 - (float)((i > 0) ? 1 : 0), 0f, num2 + (float)((i > 0) ? 1 : 0), 62f), Theme.Line, Theme.Cell);
				if (i < rec.Picks.Count)
				{
					AreaPick areaPick = rec.Picks[i];
					RectTransform obj = Ui.Place(Ui.Rect("Rank", (Transform)(object)parent2), 8f, 9f, 20f, 20f);
					Ui.Image(obj, (Color)(i switch
					{
						1 => Theme.AmberDim, 
						0 => Theme.Amber, 
						_ => Theme.AmberDark, 
					}));
					Ui.Text(obj, (i + 1).ToString(), 12f, Theme.Ink, bold: true, (TextAlignmentOptions)514);
					Ui.Place(((TMP_Text)Ui.Label(parent2, "Area", Model.Drops.Areas[areaPick.Area], 17f, Theme.Amber, bold: true, (TextAlignmentOptions)4097)).rectTransform, 34f, 5f, num2 - 42f, 28f);
					List<string> list = areaPick.Items.Select(GameBridge.NameOf).ToList();
					Ui.Place(((TMP_Text)Ui.Label(parent2, "Helps", (list.Count == 0) ? "small chance for several goals" : string.Join(" · ", list), 12.5f, Theme.Text2, bold: false, (TextAlignmentOptions)4097)).rectTransform, 10f, 34f, num2 - 18f, 20f);
				}
			}
		}

		private void RenderHideToggle()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			bool hideDone = Model.Book.HideDone;
			((RectTransform)((Component)hideKnob).transform).anchoredPosition = new Vector2((float)(hideDone ? 16 : 2), -2f);
			((Graphic)hideKnob).color = (hideDone ? Theme.Amber : Theme.Text3);
		}

		private void RenderList()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			Clear(listContent);
			Rect rect = listViewport.rect;
			float num;
			if (!(((Rect)(ref rect)).width > 0f))
			{
				num = 636f;
			}
			else
			{
				rect = listViewport.rect;
				num = ((Rect)(ref rect)).width;
			}
			float num2 = num;
			float num3 = 0f;
			if (rows.Count == 0)
			{
				Ui.Place(((TMP_Text)Ui.Label(listContent, "Empty", "No goals yet. Search for an item above and press Add.", 15f, Theme.Text3, bold: false, (TextAlignmentOptions)514)).rectTransform, 0f, 30f, num2, 30f);
				listContent.sizeDelta = new Vector2(0f, 90f);
				return;
			}
			bool hideDone = Model.Book.HideDone;
			int num4 = int.MaxValue;
			bool flag = true;
			foreach (RowState row in rows)
			{
				if (row.Depth > num4)
				{
					continue;
				}
				num4 = int.MaxValue;
				if (hideDone && row.Done)
				{
					num4 = row.Depth;
					continue;
				}
				num3 = RenderRow(row, num3, num2, flag);
				flag = false;
				if (variantsOpen == row.Goal && row.Recipe != null)
				{
					num3 = RenderVariants(row, num3, num2);
				}
				if (confirmRemove == row.Goal)
				{
					num3 = RenderConfirm(row, num3, num2);
				}
			}
			if (flag)
			{
				Ui.Place(((TMP_Text)Ui.Label(listContent, "AllHidden", "Everything is done (hidden).", 15f, Theme.Text3, bold: false, (TextAlignmentOptions)514)).rectTransform, 0f, 30f, num2, 30f);
				num3 = 90f;
			}
			listContent.sizeDelta = new Vector2(0f, num3 + 4f);
		}

		private float RenderRow(RowState r, float y, float width, bool first)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: 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_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: 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_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0570: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			bool flag = r.Parent == null;
			float num = (flag ? 60f : 48f);
			float num2 = (float)r.Depth * 26f;
			RectTransform val = Ui.Place(Ui.Rect("Row", (Transform)(object)listContent), 0f, y, width, num);
			if (!first)
			{
				Ui.Image(Ui.Place(Ui.Rect("Sep", (Transform)(object)val), num2, 0f, width - num2, 1f), (Color)(flag ? Theme.LineFaint : new Color(0.984f, 0.69f, 0.251f, 0.14f)));
			}
			ItemDefinition val2 = GameBridge.Find(r.Goal.Item);
			float num3 = (r.Done ? 0.45f : 1f);
			float num4 = 18f;
			RectTransform val3 = Ui.Frame(Ui.Place(Ui.Rect("Check", (Transform)(object)val), num2 + 10f, (num - num4) / 2f, num4, num4), Theme.Amber, r.Done ? Theme.Amber : Theme.Clear, 1.5f);
			Ui.Button(val3, delegate
			{
				r.Goal.ManualDone = !r.Goal.ManualDone;
				Changed();
			}, r.Done ? Theme.Amber : Theme.Clear, r.Done ? Theme.Hex(16762983) : Theme.Hover);
			if (r.Done)
			{
				Ui.Image(Ui.Fill(Ui.Rect("Tick", (Transform)(object)val3), 3f, 3f, 3f, 3f), Theme.Ink);
			}
			float num5 = (flag ? 42 : 32);
			float num6 = num2 + 38f;
			RectTransform parent = Ui.Frame(Ui.Place(Ui.Rect("Slot", (Transform)(object)val), num6, (num - num5) / 2f, num5, num5), Theme.Line, Theme.Cell);
			Sprite val4 = val2?.artwork;
			if ((Object)(object)val4 != (Object)null)
			{
				Image obj = Ui.Image(Ui.Fill(Ui.Rect("Art", (Transform)(object)parent), 3f, 3f, 3f, 3f), new Color(1f, 1f, 1f, num3));
				obj.sprite = val4;
				obj.preserveAspect = true;
			}
			else
			{
				Ui.Text(parent, "?", 14f, Theme.Text3, bold: true, (TextAlignmentOptions)514);
			}
			float num7 = (flag ? 156 : 76);
			float num8 = num6 + num5 + 10f;
			float num9 = width - num8 - num7 - 6f;
			RenderCount(val, r, width - num7, num, num7, flag, num3);
			float num10 = (flag ? 9 : 5);
			float y2 = (flag ? 33 : 26);
			float num11 = num8;
			float num12 = num8 + num9;
			Color color = (Color)(((??)(((Object)(object)val2 != (Object)null) ? GameBridge.QualityColor(val2) : ((Color?)null))) ?? Theme.Text);
			if (r.Done)
			{
				color = Theme.Text3;
			}
			string text = (((Object)(object)val2 != (Object)null) ? GameBridge.NameOf(val2) : (r.Goal.Item + " (unknown)"));
			float num13 = ((r.Recipe != null) ? 92 : 0) + ((r.VariantCount > 1) ? 104 : 0) + ((!flag) ? 110 : 0);
			num11 += Text(val, text, num11, num10, Mathf.Max(60f, num12 - num11 - num13), 20f, flag ? 16.5f : 14.5f, color, bold: true) + 8f;
			if (!flag)
			{
				string arg = GameBridge.NameOf(r.Parent.Item);
				num11 += Text(val, $"for {arg} · {r.PerCraft} per craft", num11, num10 + 2f, Mathf.Max(40f, num12 - num11), 18f, 11.5f, Theme.Text3) + 8f;
			}
			if (r.Recipe != null && num11 < num12 - 40f)
			{
				num11 += Chip(val, "CRAFTABLE", num11, num10 + 1f, 18f, 10.5f, Theme.Ink, Theme.Amber, null) + 6f;
				if (r.VariantCount > 1 && num11 < num12 - 60f)
				{
					int num14 = Model.Recipes.For(r.Goal.Item).ToList().IndexOf(r.Recipe) + 1;
					string arg2 = ((variantsOpen == r.Goal) ? " –" : " +");
					num11 += Chip(val, $"Recipe {num14} of {r.VariantCount}{arg2}", num11, num10 + 1f, 18f, 11.5f, Theme.Amber, Theme.Clear, delegate
					{
						variantsOpen = ((variantsOpen == r.Goal) ? null : r.Goal);
						variantScrollY = -1f;
						Refresh(force: true);
					}) + 6f;
				}
				if (num11 < num12 - 50f)
				{
					string text2 = (r.Goal.ShowMaterials ? "− Materials" : "+ Materials");
					num11 += Chip(val, text2, num11, num10 + 1f, 18f, 11.5f, Theme.Amber, Theme.Clear, delegate
					{
						Model.Book.SetShowMaterials(r.Goal, !r.Goal.ShowMaterials, Model.Recipes);
						Changed();
					}) + 6f;
				}
			}
			RenderAreas(val, r, num8, y2, num12);
			return y + num;
		}

		private void RenderCount(RectTransform row, RowState r, float x, float h, float w, bool top, float alpha)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			float num = x;
			if (top)
			{
				RectTransform obj = Ui.Place(Ui.Rect("Less", (Transform)(object)row), num, (h - 24f) / 2f, 22f, 24f);
				Ui.Button(obj, delegate
				{
					Model.Book.SetTarget(r.Goal, r.Goal.Target - Step());
					Changed();
				}, Theme.Clear, Theme.Hover);
				Ui.Text(obj, "−", 18f, Theme.Amber, bold: true, (TextAlignmentOptions)514);
				num += 22f;
			}
			float num2 = 70f;
			TextMeshProUGUI obj2 = Ui.Label(row, "Count", "", 17f, r.Done ? Theme.Text3 : Theme.Amber, bold: true, (TextAlignmentOptions)514);
			((TMP_Text)obj2).richText = true;
			((TMP_Text)obj2).text = $"{r.Owned} <size=13><color=#8E8A82>/ {r.Target}</color></size>";
			Ui.Place(((TMP_Text)obj2).rectTransform, num, (h - 34f) / 2f - 2f, num2, 30f);
			RectTransform val = Ui.Place(Ui.Rect("Bar", (Transform)(object)row), num + 8f, (h - 34f) / 2f + 28f, num2 - 16f, 3f);
			Ui.Image(val, new Color(1f, 1f, 1f, 0.08f));
			float num3 = ((r.Target <= 0) ? 1f : Mathf.Clamp01((float)r.Owned / (float)r.Target));
			if (r.Done)
			{
				num3 = 1f;
			}
			if (num3 > 0f)
			{
				Ui.Image(Ui.Place(Ui.Rect("Fill", (Transform)(object)val), 0f, 0f, (num2 - 16f) * num3, 3f), r.Done ? Theme.Text3 : Theme.Amber);
			}
			num += num2;
			if (!top)
			{
				return;
			}
			RectTransform obj3 = Ui.Place(Ui.Rect("More", (Transform)(object)row), num, (h - 24f) / 2f, 22f, 24f);
			Ui.Button(obj3, delegate
			{
				Model.Book.SetTarget(r.Goal, r.Goal.Target + Step());
				Changed();
			}, Theme.Clear, Theme.Hover);
			Ui.Text(obj3, "+", 18f, Theme.Amber, bold: true, (TextAlignmentOptions)514);
			num += 30f;
			RectTransform obj4 = Ui.Place(Ui.Rect("Remove", (Transform)(object)row), num, (h - 24f) / 2f, 24f, 24f);
			Ui.Button(obj4, delegate
			{
				if (r.Goal.ShowMaterials && r.Goal.Materials.Count > 0)
				{
					confirmRemove = ((confirmRemove == r.Goal) ? null : r.Goal);
					Refresh(force: true);
				}
				else
				{
					Model.Book.Remove(r.Goal);
					if (variantsOpen == r.Goal)
					{
						variantsOpen = null;
					}
					Changed();
				}
			}, Theme.Clear, Theme.Hover);
			Ui.Cross(obj4, Theme.Text2, 12f);
		}

		private void RenderAreas(RectTransform row, RowState r, float x, float y, float maxX)
		{
			//IL_0029: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			if (Model.Drops.IsEmpty)
			{
				Text(row, "no drop data", x, y, maxX - x, 18f, 12f, Theme.Text3);
				return;
			}
			BestAreas bestAreas = AreaRanking.Rank(Model.Drops, r.Goal.Item);
			string text = ((r.Recipe != null && !r.Done && r.Crafts > 0) ? string.Format("{0} craft{1} left", r.Crafts, (r.Crafts == 1) ? "" : "s") : null);
			if (!bestAreas.Found)
			{
				string text2 = "Not found in runs";
				if (text != null)
				{
					text2 = text2 + " · " + text;
				}
				Text(row, text2, x, y, maxX - x, 18f, 12f, Theme.Text3);
				return;
			}
			x += Text(row, "Best areas", x, y, 80f, 18f, 11.5f, Theme.Text3) + 6f;
			if (bestAreas.Everywhere)
			{
				x += Chip(row, "Everywhere", x, y, 18f, 12f, Theme.Amber, Theme.Clear, null, Theme.Line) + 6f;
			}
			else
			{
				for (int i = 0; i < bestAreas.Top.Count; i++)
				{
					if (!(x < maxX - 40f))
					{
						break;
					}
					x += AreaChip(row, i, Model.Drops.Areas[bestAreas.Top[i]], x, y, maxX - x) + 5f;
				}
				if (bestAreas.MoreTied > 0 && x < maxX - 40f)
				{
					x += Text(row, $"+{bestAreas.MoreTied} more", x, y, maxX - x, 18f, 11.5f, Theme.Text3) + 6f;
				}
			}
			if (text != null && x < maxX - 60f)
			{
				Text(row, "· " + text, x, y, maxX - x, 18f, 11.5f, Theme.Text3);
			}
		}

		private float RenderVariants(RowState r, float y, float width)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0617: Unknown result type (might be due to invalid IL or missing references)
			//IL_0664: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			IReadOnlyList<RecipeInfo> readOnlyList = Model.Recipes.For(r.Goal.Item);
			float num = (float)r.Depth * 26f + 88f;
			float num2 = width - num - 12f;
			int num3 = Math.Min(readOnlyList.Count, 6);
			RectTransform parent = Ui.Frame(Ui.Place(Ui.Rect("Variants", (Transform)(object)listContent), num, y, num2, 22f + (float)num3 * 30f + 2f), Theme.Amber, Theme.Popup);
			int num4 = readOnlyList.Count((RecipeInfo recipeInfo) => recipeInfo.Learned);
			Text(parent, $"{readOnlyList.Count} recipes · {num4} learned · learned first, then fewest ingredients", 10f, 3f, num2 - 20f, 16f, 11f, Theme.Text3);
			RectTransform val = Ui.Place(Ui.Rect("View", (Transform)(object)parent), 0f, 22f, num2 - 2f, (float)num3 * 30f);
			((Component)val).gameObject.AddComponent<RectMask2D>();
			Ui.Image(val, Theme.Clear, raycast: true);
			RectTransform content = Ui.Rect("Content", (Transform)(object)val);
			content.anchorMin = new Vector2(0f, 1f);
			content.anchorMax = new Vector2(1f, 1f);
			content.pivot = new Vector2(0.5f, 1f);
			content.sizeDelta = new Vector2(0f, (float)readOnlyList.Count * 30f);
			ScrollRect obj = ((Component)val).gameObject.AddComponent<ScrollRect>();
			obj.viewport = val;
			obj.content = content;
			obj.horizontal = false;
			obj.movementType = (MovementType)2;
			obj.scrollSensitivity = 30f;
			obj.inertia = false;
			float num5 = Math.Max(0f, (float)readOnlyList.Count * 30f - (float)num3 * 30f);
			if (variantScrollY < 0f)
			{
				int num6 = Math.Max(0, IndexOf(readOnlyList, r.Recipe));
				variantScrollY = Mathf.Clamp((float)(num6 - 1) * 30f, 0f, num5);
			}
			content.anchoredPosition = new Vector2(0f, Mathf.Clamp(variantScrollY, 0f, num5));
			((UnityEvent<Vector2>)(object)obj.onValueChanged).AddListener((UnityAction<Vector2>)delegate
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				variantScrollY = content.anchoredPosition.y;
			});
			int needed = Math.Max(0, r.Target - r.Owned);
			for (int num7 = 0; num7 < readOnlyList.Count; num7++)
			{
				RecipeInfo v = readOnlyList[num7];
				bool flag = v == r.Recipe;
				RectTransform val2 = Ui.Place(Ui.Rect("Variant" + num7, (Transform)(object)content), 0f, (float)num7 * 30f, num2 - 2f, 30f);
				Ui.Button(val2, delegate
				{
					Model.Book.SetRecipe(r.Goal, v.Name, Model.Recipes);
					variantsOpen = null;
					Changed();
				}, (Color)(flag ? new Color(0.984f, 0.69f, 0.251f, 0.14f) : Theme.Clear), Theme.Hover);
				if (num7 > 0)
				{
					Ui.Image(Ui.Place(Ui.Rect("Sep", (Transform)(object)val2), 0f, 0f, num2 - 2f, 1f), Theme.LineFaint);
				}
				float num8 = (v.Learned ? 1f : 0.5f);
				Ui.Frame(Ui.Place(Ui.Rect("Radio", (Transform)(object)val2), 9f, 9f, 12f, 12f), Theme.Amber, flag ? Theme.Amber : Theme.Clear, 1.5f);
				float num9 = 30f;
				foreach (Ingredient ingredient in v.Ingredients)
				{
					if (num9 > num2 - 150f)
					{
						num9 += Text(val2, "…", num9, 6f, 20f, 18f, 13f, Theme.Text2);
						break;
					}
					num9 += Text(val2, ingredient.Count + "×", num9, 6f, 30f, 18f, 13f, Fade(Theme.Text, num8), bold: true) + 3f;
					Sprite val3 = GameBridge.IconOf(ingredient.Item);
					if ((Object)(object)val3 != (Object)null)
					{
						RectTransform parent2 = Ui.Frame(Ui.Place(Ui.Rect("Ing", (Transform)(object)val2), num9, 5f, 20f, 20f), Theme.LineFaint, Theme.Cell);
						Image obj2 = Ui.Image(Ui.Fill(Ui.Rect("Art", (Transform)(object)parent2), 1f, 1f, 1f, 1f), new Color(1f, 1f, 1f, num8));
						obj2.sprite = val3;
						obj2.preserveAspect = true;
						num9 += 24f;
					}
					num9 += Text(val2, GameBridge.NameOf(ingredient.Item), num9, 6f, 120f, 18f, 12.5f, Fade(Theme.Text2, num8)) + 10f;
				}
				num9 += Text(val2, "»", num9, 6f, 20f, 18f, 13f, Theme.Text3) + 4f;
				num9 += Text(val2, "×" + v.Yield, num9, 6f, 34f, 18f, 13f, Fade(Theme.Amber, num8), bold: true) + 8f;
				if (!v.Learned)
				{
					Chip(val2, "NOT LEARNED", num9, 6f, 17f, 9.5f, Theme.Ink, Theme.Text3, null);
				}
				int num10 = CraftMath.Crafts(needed, v.Yield);
				Ui.Place(((TMP_Text)Ui.Label(val2, "Crafts", string.Format("{0} craft{1}", num10, (num10 == 1) ? "" : "s"), 11.5f, Theme.Text3, bold: false, (TextAlignmentOptions)4100)).rectTransform, num2 - 2f - 78f, 6f, 70f, 18f);
			}
			return y + 22f + (float)num3 * 30f + 2f + 6f;
		}

		private static int IndexOf(IReadOnlyList<RecipeInfo> list, RecipeInfo r)
		{
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i] == r)
				{
					return i;
				}
			}
			return -1;
		}

		private float RenderConfirm(RowState r, float y, float width)
		{
			//IL_0052: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)r.Depth * 26f + 38f;
			RectTransform parent = Ui.Frame(Ui.Place(Ui.Rect("Confirm", (Transform)(object)listContent), num, y, width - num - 8f, 30f), Theme.Warn, Theme.Popup);
			float num2 = 10f;
			num2 += Text(parent, "Remove its materials too?", num2, 6f, 200f, 20f, 13f, Theme.Text) + 12f;
			num2 += Chip(parent, "Remove all", num2, 5f, 20f, 12f, Theme.Ink, Theme.Amber, delegate
			{
				Model.Book.Remove(r.Goal);
				confirmRemove = null;
				Changed();
			}) + 6f;
			num2 += Chip(parent, "Keep materials", num2, 5f, 20f, 12f, Theme.Amber, Theme.Clear, delegate
			{
				Model.Book.Remove(r.Goal, keepMaterials: true, rows);
				confirmRemove = null;
				Changed();
			}) + 6f;
			Chip(parent, "Cancel", num2, 5f, 20f, 12f, Theme.Text2, Theme.Clear, delegate
			{
				confirmRemove = null;
				Refresh(force: true);
			});
			return y + 34f;
		}

		private void OnQuery(string q)
		{
			results = ItemSearch.Search(Model.SearchEntries, q);
			highlight = 0;
			RenderDropdown();
		}

		private void HandleSearchKeys()
		{
			if (!IsTyping || results.Count == 0)
			{
				return;
			}
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				int num = highlight;
				if (((ButtonControl)current.downArrowKey).wasPressedThisFrame)
				{
					highlight = Math.Min(results.Count - 1, highlight + 1);
				}
				if (((ButtonControl)current.upArrowKey).wasPressedThisFrame)
				{
					highlight = Math.Max(0, highlight - 1);
				}
				if (num != highlight)
				{
					RenderDropdown();
				}
			}
		}

		private void SubmitHighlighted()
		{
			if (results.Count != 0)
			{
				Add(results[Mathf.Clamp(highlight, 0, results.Count - 1)].Key);
			}
		}

		private void Add(string key)
		{
			Model.Book.Add(key, addAmount);
			addAmount = 1;
			((TMP_Text)amountText).text = "1";
			search.text = "";
			results.Clear();
			RenderDropdown();
			Changed();
		}

		private void StepAmount(int dir)
		{
			addAmount = Mathf.Clamp(addAmount + dir * Step(), 1, 9999);
			((TMP_Text)amountText).text = addAmount.ToString();
		}

		private static int Step()
		{
			Keyboard current = Keyboard.current;
			if (current == null || (!((ButtonControl)current.leftShiftKey).isPressed && !((ButtonControl)current.rightShiftKey).isPressed))
			{
				return 1;
			}
			return 10;
		}

		private void RenderDropdown()
		{
			//IL_004c: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			Clear(dropdown);
			if (results.Count == 0)
			{
				((Component)dropdown).gameObject.SetActive(false);
				return;
			}
			((Component)dropdown).gameObject.SetActive(true);
			((Transform)dropdown).SetAsLastSibling();
			float x = dropdown.sizeDelta.x;
			dropdown.sizeDelta = new Vector2(x, (float)results.Count * 34f + 2f);
			RectTransform val = Ui.Frame(Ui.Fill(Ui.Rect("Box", (Transform)(object)dropdown)), Theme.Amber, Theme.Popup);
			((Graphic)((Component)val).GetComponent<Image>()).raycastTarget = true;
			for (int i = 0; i < results.Count; i++)
			{
				ItemEntry e = results[i];
				ItemDefinition val2 = GameBridge.Find(e.Key);
				RectTransform val3 = Ui.Place(Ui.Rect("Result" + i, (Transform)(object)val), 0f, (float)i * 34f, x - 2f, 34f);
				Ui.Button(val3, delegate
				{
					Add(e.Key);
				}, (i == highlight) ? Theme.Hover : Theme.Clear, new Color(0.984f, 0.69f, 0.251f, 0.25f));
				RectTransform parent = Ui.Frame(Ui.Place(Ui.Rect("Slot", (Transform)(object)val3), 8f, 4f, 26f, 26f), Theme.LineFaint, Theme.Cell);
				if ((Object)(object)val2?.artwork != (Object)null)
				{
					Image obj = Ui.Image(Ui.Fill(Ui.Rect("Art", (Transform)(object)parent), 2f, 2f, 2f, 2f), Color.white);
					obj.sprite = val2.artwork;
					obj.preserveAspect = true;
				}
				float num = 44f;
				bool flag = Model.Recipes.IsCraftable(e.Key);
				float num2 = 96f;
				num += Text(val3, e.Name, num, 7f, x - num - num2 - (float)(flag ? 90 : 10), 20f, 15f, (Color)(((??)(((Object)(object)val2 != (Object)null) ? GameBridge.QualityColor(val2) : ((Color?)null))) ?? Theme.Text), bold: true) + 8f;
				if (flag)
				{
					Chip(val3, "CRAFTABLE", num, 8f, 18f, 10.5f, Theme.Ink, Theme.Amber, null);
				}
				Ui.Place(((TMP_Text)Ui.Label(val3, "Cat", e.Category, 11.5f, Theme.Text3, bold: false, (TextAlignmentOptions)4100)).rectTransform, x - 2f - num2 - 10f, 7f, num2, 20f);
			}
		}

		private static float Text(RectTransform parent, string text, float x, float y, float maxW, float h, float size, Color color, bool bold = false)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = Ui.Label(parent, "T", text, size, color, bold, (TextAlignmentOptions)4097);
			float num = Mathf.Min(Mathf.Max(0f, maxW), Mathf.Ceil(Ui.Width(val)) + 1f);
			Ui.Place(((TMP_Text)val).rectTransform, x, y, num, h);
			return num;
		}

		private static float Chip(RectTransform parent, string text, float x, float y, float h, float size, Color textColor, Color fill, Action onClick, Color? border = null)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = Ui.Label(parent, "ChipText", text, size, textColor, bold: true, (TextAlignmentOptions)514);
			float num = Mathf.Ceil(Ui.Width(obj)) + 14f;
			RectTransform val = Ui.Place(Ui.Rect("Chip", (Transform)(object)parent), x, y, num, h);
			bool flag = fill.a < 0.01f;
			RectTransform val2 = (flag ? Ui.Frame(val, border ?? textColor, Theme.Clear) : val);
			if (!flag)
			{
				Ui.Image(val, fill);
			}
			if (onClick != null)
			{
				Ui.Button(val2, onClick, flag ? Theme.Clear : fill, flag ? Theme.Hover : Theme.Hex(16762983));
			}
			((TMP_Text)obj).transform.SetParent((Transform)(object)val2, false);
			Ui.Fill(((TMP_Text)obj).rectTransform);
			return num;
		}

		private static float AreaChip(RectTransform parent, int rank, string area, float x, float y, float maxW)
		{
			//IL_000c: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = Ui.Label(parent, "Area", area, 12f, Theme.Text2, bold: false, (TextAlignmentOptions)4097);
			float num = Mathf.Min(Mathf.Ceil(Ui.Width(obj)) + 1f, Mathf.Max(30f, maxW - 30f));
			float num2 = num + 28f;
			RectTransform val = Ui.Frame(Ui.Place(Ui.Rect("AreaChip", (Transform)(object)parent), x, y, num2, 18f), Theme.LineFaint, Theme.Cell);
			RectTransform obj2 = Ui.Place(Ui.Rect("Badge", (Transform)(object)val), 2f, 1f, 15f, 15f);
			Ui.Image(obj2, (Color)(rank switch
			{
				1 => Theme.AmberDim, 
				0 => Theme.Amber, 
				_ => Theme.AmberDark, 
			}));
			Ui.Text(obj2, (rank + 1).ToString(), 10f, Theme.Ink, bold: true, (TextAlignmentOptions)514);
			((TMP_Text)obj).transform.SetParent((Transform)(object)val, false);
			Ui.Place(((TMP_Text)obj).rectTransform, 21f, 0f, num, 16f);
			return num2;
		}

		private static Color Fade(Color c, float a)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			return new Color(c.r, c.g, c.b, c.a * a);
		}

		private static void Clear(RectTransform rt)
		{
			for (int num = ((Transform)rt).childCount - 1; num >= 0; num--)
			{
				GameObject gameObject = ((Component)((Transform)rt).GetChild(num)).gameObject;
				gameObject.SetActive(false);
				Object.Destroy((Object)(object)gameObject);
			}
		}
	}
	[BepInPlugin("local.sulfur.wheresmyloot", "Where's My Loot?!?!", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "local.sulfur.wheresmyloot";

		public const string Name = "Where's My Loot?!?!";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		internal static Plugin Instance;

		internal ConfigEntry<Key> OpenKey;

		internal ConfigEntry<bool> CountEquipped;

		internal ConfigEntry<bool> CountStash;

		internal ConfigEntry<float> WindowX;

		internal ConfigEntry<float> WindowY;

		internal ConfigEntry<float> Opacity;

		internal GoalsModel Model;

		private GoalsWindow window;

		private Harmony harmony;

		private readonly List<InputActionMap> blockedMaps = new List<InputActionMap>();

		private bool typingLastFrame;

		internal static bool BlockGameKeys;

		private const string OldGuid = "local.sulfur.lootgoals";

		private const string OldSaveFolder = "loot_goals";

		public const string SaveFolder = "wheres_my_loot";

		private void MigrateFromOldName()
		{
			try
			{
				string text = Path.Combine(Paths.ConfigPath, "local.sulfur.lootgoals.cfg");
				if (!File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath) && File.Exists(text))
				{
					File.Copy(text, ((BaseUnityPlugin)this).Config.ConfigFilePath);
					((BaseUnityPlugin)this).Config.Reload();
					Log.LogInfo((object)"Copied your settings from local.sulfur.lootgoals.cfg");
				}
				string path = Path.Combine(Paths.ConfigPath, "loot_goals");
				string text2 = Path.Combine(Paths.ConfigPath, "wheres_my_loot");
				if (!Directory.Exists(text2) && Directory.Exists(path))
				{
					Directory.CreateDirectory(text2);
					int num = 0;
					string[] files = Directory.GetFiles(path, "*.json");
					foreach (string text3 in files)
					{
						File.Copy(text3, Path.Combine(text2, Path.GetFileName(text3)));
						num++;
					}
					Log.LogInfo((object)string.Format("Copied {0} saved goal list(s) from config\\{1}", num, "loot_goals"));
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not copy the old Loot Goals settings/goals: " + ex.Message));
			}
		}

		private void Awake()
		{
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			MigrateFromOldName();
			OpenKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "OpenKey", (Key)102, "Opens/closes the Where's My Loot?!?! window. Only works while the inventory is open.");
			CountEquipped = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CountEquipped", true, "Count items in equipped slots as owned too (this is what the game's own crafting does). Off: only the backpack grid counts.");
			CountStash = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CountStash", true, "Count items in your stashes (the church stash and weapon racks) as owned too. Works during runs as well (it reads the saved stash).");
			WindowX = ((BaseUnityPlugin)this).Config.Bind<float>("Window", "X", -40f, "Window position (set by dragging its header).");
			WindowY = ((BaseUnityPlugin)this).Config.Bind<float>("Window", "Y", 0f, "Window position (set by dragging its header).");
			Opacity = ((BaseUnityPlugin)this).Config.Bind<float>("Window", "Opacity", 0.9f, new ConfigDescription("How solid the window background is: 1 = fully opaque, 0.5 = half see-through. Read again each time the window opens, so you can change it while the game runs.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 1f), Array.Empty<object>()));
			string path = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? Paths.PluginPath;
			Model = new GoalsModel(Path.Combine(Paths.ConfigPath, "wheres_my_loot"), LoadDrops(Path.Combine(path, "drop_sources.json")));
			if (Chainloader.PluginInfos.ContainsKey("local.sulfur.lootgoals"))
			{
				Log.LogWarning((object)"The old \"Loot Goals\" plugin is installed too (plugins\\loot_goals). Remove it, or both windows open on F9.");
			}
			harmony = new Harmony("local.sulfur.wheresmyloot");
			try
			{
				harmony.Patch((MethodBase)AccessTools.Method(typeof(InventoryUI), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin), "InventoryUpdatePrefix", (Type[])null)
				{
					priority = 800
				}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not patch InventoryUI.Update; typing in the search box may also trigger game keys. " + ex.Message));
			}
			Log.LogInfo((object)string.Format("{0} {1} loaded. Press {2} with the inventory open.", "Where's My Loot?!?!", "1.0.0", OpenKey.Value));
		}

		private static DropData LoadDrops(string path)
		{
			try
			{
				if (File.Exists(path))
				{
					DropData dropData = DropData.Parse(File.ReadAllText(path));
					Log.LogInfo((object)$"Drop data: {dropData.Areas.Count} areas from {path}");
					return dropData;
				}
				Log.LogWarning((object)(path + " is missing: best areas can't be shown. Rebuild it with `SulfurExtract droptable`."));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Could not read " + path + ": " + ex.Message));
			}
			return DropData.Empty;
		}

		private static bool InventoryUpdatePrefix()
		{
			return !BlockGameKeys;
		}

		private void Update()
		{
			try
			{
				Tick();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Where's My Loot: " + ex));
				Close();
			}
		}

		private void Tick()
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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)
			Keyboard current = Keyboard.current;
			if (window != null && window.IsOpen)
			{
				bool isTyping = window.IsTyping;
				SetKeyBlock(isTyping);
				bool flag = current != null && ((ButtonControl)current.escapeKey).wasPressedThisFrame;
				bool flag2 = current != null && (int)OpenKey.Value != 0 && ((ButtonControl)current[OpenKey.Value]).wasPressedThisFrame;
				if (!GameBridge.InventoryOpen || GameBridge.Slot != Model.Slot)
				{
					Close();
				}
				else if (!isTyping && !typingLastFrame && (flag || flag2))
				{
					Close();
				}
				else
				{
					window.Tick();
				}
				typingLastFrame = isTyping;
			}
			else
			{
				SetKeyBlock(block: false);
				if (current != null && (int)OpenKey.Value != 0 && ((ButtonControl)current[OpenKey.Value]).wasPressedThisFrame && GameBridge.InventoryOpen && !GameBridge.DraggingItem)
				{
					Open();
				}
			}
		}

		private void Open()
		{
			try
			{
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not reload the config: " + ex.Message));
			}
			Model.EnsureSlot(GameBridge.Slot);
			Model.RefreshGameData();
			if (window == null)
			{
				window = new GoalsWindow(this)
				{
					RequestClose = Close
				};
			}
			window.Show();
			typingLastFrame = false;
		}

		private void Close()
		{
			SetKeyBlock(block: false);
			window?.Hide();
			Model?.Save();
		}

		private void SetKeyBlock(bool block)
		{
			if (block == BlockGameKeys)
			{
				return;
			}
			BlockGameKeys = block;
			if (block)
			{
				foreach (InputActionMap item in GameBridge.KeyboardMaps())
				{
					if (item != null && item.enabled)
					{
						item.Disable();
						blockedMaps.Add(item);
					}
				}
				return;
			}
			foreach (InputActionMap blockedMap in blockedMaps)
			{
				if (blockedMap != null && !blockedMap.enabled)
				{
					blockedMap.Enable();
				}
			}
			blockedMaps.Clear();
		}

		private void OnDestroy()
		{
			Close();
			window?.Dispose();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	internal sealed class GoalsModel
	{
		private readonly string dir;

		public GoalBook Book { get; private set; } = new GoalBook();

		public int Slot { get; private set; } = int.MinValue;

		public RecipeBook Recipes { get; private set; } = RecipeBook.Empty;

		public DropData Drops { get; }

		public List<ItemEntry> SearchEntries { get; private set; } = new List<ItemEntry>();

		public GoalsModel(string dir, DropData drops)
		{
			this.dir = dir;
			Drops = drops ?? DropData.Empty;
		}

		public void EnsureSlot(int slot)
		{
			if (slot != Slot)
			{
				if (Slot >= 0)
				{
					Save();
				}
				Slot = slot;
				Book = ((slot >= 0) ? GoalStore.Load(GoalStore.PathFor(dir, slot), delegate(string w)
				{
					Plugin.Log.LogWarning((object)w);
				}) : new GoalBook());
			}
		}

		public void RefreshGameData()
		{
			RecipeBook recipeBook = GameBridge.Recipes();
			if (recipeBook.ProductCount > 0)
			{
				Recipes = recipeBook;
				Book.Normalize(Recipes);
			}
			else
			{
				Plugin.Log.LogWarning((object)"No recipes found (game data not loaded yet?); craftable items won't show recipes.");
			}
			SearchEntries = GameBridge.SearchEntries();
		}

		public List<RowState> Evaluate(bool countEquipped, bool countStash)
		{
			Dictionary<string, int> counts = new Dictionary<string, int>(StringComparer.Ordinal);
			Dictionary<ItemId, int> stash = (countStash ? GameBridge.StashCounts() : null);
			return Book.Evaluate(Recipes, delegate(string k)
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				if (counts.TryGetValue(k, out var value))
				{
					return value;
				}
				value = GameBridge.CountOf(k, countEquipped);
				if (stash != null)
				{
					ItemId? val = GameBridge.IdOf(k);
					if (val.HasValue)
					{
						ItemId valueOrDefault = val.GetValueOrDefault();
						if (stash.TryGetValue(valueOrDefault, out var value2))
						{
							value += value2;
						}
					}
				}
				counts[k] = value;
				return value;
			});
		}

		public void Save()
		{
			if (Slot < 0)
			{
				return;
			}
			try
			{
				GoalStore.Save(GoalStore.PathFor(dir, Slot), Book);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Could not save goals: " + ex.Message));
			}
		}
	}
	internal static class Theme
	{
		public static readonly Color Amber = Hex(16494656);

		public static readonly Color AmberDim = Hex(14392121);

		public static readonly Color AmberDark = Hex(9071162);

		public static readonly Color Line = new Color(0.984f, 0.69f, 0.251f, 0.55f);

		public static readonly Color LineFaint = new Color(0.984f, 0.69f, 0.251f, 0.25f);

		public static readonly Color Panel = new Color(0.024f, 0.04f, 0.047f, 0.86f);

		public static readonly Color Cell = new Color(0f, 0f, 0f, 0.42f);

		public static readonly Color Popup = new Color(0.016f, 0.027f, 0.031f, 0.97f);

		public static readonly Color Text = Hex(15854818);

		public static readonly Color Text2 = Hex(13223098);

		public static readonly Color Text3 = Hex(9341570);

		public static readonly Color Ink = Color.black;

		public static readonly Color Warn = Hex(10689825);

		public static readonly Color Hover = new Color(0.984f, 0.69f, 0.251f, 0.16f);

		public static readonly Color Clear = new Color(0f, 0f, 0f, 0f);

		public static Color Hex(int rgb)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)((rgb >> 16) & 0xFF) / 255f, (float)((rgb >> 8) & 0xFF) / 255f, (float)(rgb & 0xFF) / 255f, 1f);
		}
	}
	internal static class Ui
	{
		public static TMP_FontAsset Font;

		public static TMP_FontAsset FontBold;

		private static readonly Dictionary<char, string> Fallbacks = new Dictionary<char, string>
		{
			['×'] = "x",
			['·'] = "-",
			['−'] = "-",
			['–'] = "-",
			['—'] = "-",
			['»'] = ">",
			['…'] = "...",
			['•'] = "-"
		};

		private static readonly Dictionary<(TMP_FontAsset, char), bool> hasChar = new Dictionary<(TMP_FontAsset, char), bool>();

		private static readonly HashSet<char> reported = new HashSet<char>();

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

		public static RectTransform Place(RectTransform rt, float x, float y, float w, float h)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			rt.anchorMax = val;
			rt.anchorMin = val;
			rt.pivot = new Vector2(0f, 1f);
			rt.anchoredPosition = new Vector2(x, 0f - y);
			rt.sizeDelta = new Vector2(w, h);
			return rt;
		}

		public static RectTransform Fill(RectTransform rt, float l = 0f, float t = 0f, float r = 0f, float b = 0f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = Vector2.zero;
			rt.anchorMax = Vector2.one;
			rt.pivot = new Vector2(0.5f, 0.5f);
			rt.offsetMin = new Vector2(l, b);
			rt.offsetMax = new Vector2(0f - r, 0f - t);
			return rt;
		}

		public static Image Image(RectTransform rt, Color color, bool raycast = false)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Image obj = ((Component)rt).gameObject.AddComponent<Image>();
			((Graphic)obj).color = color;
			((Graphic)obj).raycastTarget = raycast;
			return obj;
		}

		public static TextMeshProUGUI Text(RectTransform parent, string text, float size, Color color, bool bold = false, TextAlignmentOptions align = (TextAlignmentOptions)4097)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = ((Component)Fill(Rect("Text", (Transform)(object)parent))).gameObject.AddComponent<TextMeshProUGUI>();
			Style(obj, text, size, color, bold, align);
			return obj;
		}

		public static TextMeshProUGUI Label(RectTransform parent, string name, string text, float size, Color color, bool bold = false, TextAlignmentOptions align = (TextAlignmentOptions)4097)
		{
			//IL_0014: 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)
			TextMeshProUGUI obj = ((Component)Rect(name, (Transform)(object)parent)).gameObject.AddComponent<TextMeshProUGUI>();
			Style(obj, text, size, color, bold, align);
			return obj;
		}

		public static void Style(TextMeshProUGUI t, string text, float size, Color color, bool bold, TextAlignmentOptions align)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			TMP_FontAsset val = (bold ? (FontBold ?? Font) : Font);
			if ((Object)(object)val != (Object)null)
			{
				((TMP_Text)t).font = val;
			}
			((TMP_Text)t).fontSize = size;
			((Graphic)t).color = color;
			((TMP_Text)t).richText = false;
			((Graphic)t).raycastTarget = false;
			((TMP_Text)t).alignment = align;
			((TMP_Text)t).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)t).overflowMode = (TextOverflowModes)1;
			SetText(t, text);
		}

		public static void SetText(TextMeshProUGUI t, string text)
		{
			((TMP_Text)t).text = Safe(text, ((TMP_Text)t).font);
		}

		public static string Safe(string text, TMP_FontAsset font)
		{
			if (string.IsNullOrEmpty(text))
			{
				return text ?? "";
			}
			StringBuilder stringBuilder = null;
			for (int i = 0; i < text.Length; i++)
			{
				char c = text[i];
				if (c < '\u0080' || (Object)(object)font == (Object)null || Has(font, c))
				{
					stringBuilder?.Append(c);
					continue;
				}
				if (stringBuilder == null)
				{
					stringBuilder = new StringBuilder(text, 0, i, text.Length + 8);
				}
				stringBuilder.Append(Fallbacks.TryGetValue(c, out var value) ? value : "?");
				if (reported.Add(c))
				{
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogInfo((object)string.Format("Font has no '{0}' (U+{1:X4}), drawing \"{2}\" instead.", c, (int)c, Fallbacks.TryGetValue(c, out var value2) ? value2 : "?"));
					}
				}
			}
			return stringBuilder?.ToString() ?? text;
		}

		private static bool Has(TMP_FontAsset font, char c)
		{
			if (hasChar.TryGetValue((font, c), out var value))
			{
				return value;
			}
			try
			{
				value = font.HasCharacter(c, true, true);
			}
			catch (Exception)
			{
				value = false;
			}
			hasChar[(font, c)] = value;
			return value;
		}

		public static RectTransform Frame(RectTransform rt, Color border, Color fill, float width = 1f)
		{
			//IL_0010: 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_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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			Edge(rt, "Top", new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0f, 0f - width), Vector2.zero, border);
			Edge(rt, "Bottom", Vector2.zero, new Vector2(1f, 0f), Vector2.zero, new Vector2(0f, width), border);
			Edge(rt, "Left", Vector2.zero, new Vector2(0f, 1f), new Vector2(0f, width), new Vector2(width, 0f - width), border);
			Edge(rt, "Right", new Vector2(1f, 0f), Vector2.one, new Vector2(0f - width, width), new Vector2(0f, 0f - width), border);
			RectTransform obj = Fill(Rect("Fill", (Transform)(object)rt), width, width, width, width);
			Image(obj, fill);
			return obj;
		}

		private static void Edge(RectTransform parent, string name, Vector2 aMin, Vector2 aMax, Vector2 offMin, Vector2 offMax, Color c)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = Rect(name, (Transform)(object)parent);
			obj.anchorMin = aMin;
			obj.anchorMax = aMax;
			obj.pivot = new Vector2(0.5f, 0.5f);
			obj.offsetMin = offMin;
			obj.offsetMax = offMax;
			Image(obj, c);
		}

		public static void Cross(RectTransform parent, Color color, float size, float thickness = 2f)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			float[] array = new float[2] { 45f, -45f };
			Vector2 val = default(Vector2);
			foreach (float num in array)
			{
				RectTransform obj = Rect("Bar", (Transform)(object)parent);
				((Vector2)(ref val))..ctor(0.5f, 0.5f);
				obj.anchorMax = val;
				obj.anchorMin = val;
				obj.pivot = new Vector2(0.5f, 0.5f);
				obj.anchoredPosition = Vector2.zero;
				obj.sizeDelta = new Vector2(size, thickness);
				((Transform)obj).localRotation = Quaternion.Euler(0f, 0f, num);
				Image(obj, color);
			}
		}

		public static Button Button(RectTransform rt, Action onClick, Color normal, Color hover)
		{
			//IL_0021: 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_004a: 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_0055: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Image val = ((Component)rt).GetComponent<Image>() ?? Image(rt, normal);
			((Graphic)val).color = Color.white;
			((Graphic)val).raycastTarget = true;
			Button obj = ((Component)rt).gameObject.AddComponent<Button>();
			((Selectable)obj).targetGraphic = (Graphic)(object)val;
			ColorBlock colors = ((Selectable)obj).colors;
			((ColorBlock)(ref colors)).normalColor = normal;
			((ColorBlock)(ref colors)).highlightedColor = hover;
			((ColorBlock)(ref colors)).pressedColor = hover;
			((ColorBlock)(ref colors)).selectedColor = normal;
			((ColorBlock)(ref colors)).disabledColor = new Color(normal.r, normal.g, normal.b, normal.a * 0.4f);
			((ColorBlock)(ref colors)).colorMultiplier = 1f;
			((ColorBlock)(ref colors)).fadeDuration = 0.05f;
			((Selectable)obj).colors = colors;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj).navigation = navigation;
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				try
				{
					onClick();
				}
				catch (Exception ex)
				{
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogError((object)("Where's My Loot?!?! button: " + ex));
					}
				}
			});
			return obj;
		}

		public static Button Primary(RectTransform rt, string label, float size, Action onClick)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Button result = Button(rt, onClick, Theme.Amber, Theme.Hex(16762983));
			Text(rt, label, size, Theme.Ink, bold: true, (TextAlignmentOptions)514);
			return result;
		}

		public static Button Ghost(RectTransform rt, string label, float size, Action onClick)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = Frame(rt, Theme.Line, Theme.Clear);
			Button result = Button(obj, onClick, Theme.Clear, Theme.Hover);
			Text(obj, label, size, Theme.Amber, bold: false, (TextAlignmentOptions)514);
			return result;
		}

		public static void Tab(RectTransform parent, string label, float x, float y)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = Label(parent, "Tab", label, 13f, Theme.Ink, bold: true, (TextAlignmentOptions)4097);
			RectTransform val = Place(w: ((TMP_Text)obj).GetPreferredValues(label).x + 22f, rt: Rect("TabBg", (Transform)(object)parent), x: x, y: y, h: 19f);
			Image(val, Theme.Amber);
			((TMP_Text)obj).transform.SetParent((Transform)(object)val, false);
			Fill(((TMP_Text)obj).rectTransform, 7f, 0f, 4f);
		}

		public static float Width(TextMeshProUGUI t)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return ((TMP_Text)t).GetPreferredValues(((TMP_Text)t).text).x;
		}
	}
	internal sealed class DragHandle : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler
	{
		public RectTransform Target;

		public Action OnMoved;

		private Canvas canvas;

		public void OnBeginDrag(PointerEventData e)
		{
			canvas = ((Component)this).GetComponentInParent<Canvas>();
		}

		public void OnDrag(PointerEventData e)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!((Object)(object)Target == (Object)null))
			{
				float num = (((Object)(object)canvas != (Object)null) ? canvas.scaleFactor : 1f);
				RectTransform target = Target;
				target.anchoredPosition += e.delta / Mathf.Max(0.01f, num);
			}
		}

		public void OnEndDrag(PointerEventData e)
		{
			OnMoved?.Invoke();
		}
	}
}
namespace WheresMyLoot.Core
{
	public sealed class BestAreas
	{
		public bool Found { get; internal set; }

		public bool Everywhere { get; internal set; }

		public IReadOnlyList<int> Top { get; internal set; } = new int[0];

		public int MoreTied { get; internal set; }

		internal double[] Values { get; set; }
	}
	public static class AreaRanking
	{
		public const double RelativeEpsilon = 1E-06;

		public const double EverywhereRatio = 0.75;

		public const double MinRelative = 0.05;

		public static BestAreas Rank(DropData data, string itemKey, int take = 3)
		{
			return Rank(data?.Score(itemKey), take);
		}

		public static BestAreas Rank(double[] values, int take = 3)
		{
			BestAreas bestAreas = new BestAreas
			{
				Values = values
			};
			if (!HasAny(values))
			{
				bestAreas.Values = null;
				return bestAreas;
			}
			bestAreas.Found = true;
			double max = values.Max();
			double eps = max * 1E-06;
			if (values.Length > 1 && values.All((double v) => v > 0.0 && v >= max * 0.75 - eps))
			{
				bestAreas.Everywhere = true;
				return bestAreas;
			}
			double floor = max * 0.05;
			List<int> order = (from i in Enumerable.Range(0, values.Length)
				where values[i] > 0.0 && values[i] >= floor
				orderby values[i] descending, i
				select i).ToList();
			order = StableTieOrder(order, values, eps);
			List<int> list = (List<int>)(bestAreas.Top = order.Take(Math.Max(0, take)).ToList());
			if (list.Count > 0)
			{
				double last = values[list[list.Count - 1]];
				bestAreas.MoreTied = order.Skip(list.Count).Count((int i) => Math.Abs(values[i] - last) <= eps);
			}
			return bestAreas;
		}

		public static double[] Relative(double[] values)