Decompiled source of PerfectCraftTable v0.10.9

PerfectCraftTable.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CraftingTabs.Search;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace CraftingTabs
{
	internal static class CatalogRules
	{
		internal static string Identity(string name, string description, string type, string icon)
		{
			return string.Join("\u001f", name, description, type, icon);
		}

		internal static bool Matches(string name, string prefab, string query)
		{
			string[] array = query.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string value in array)
			{
				if (name.IndexOf(value, StringComparison.OrdinalIgnoreCase) < 0 && prefab.IndexOf(value, StringComparison.OrdinalIgnoreCase) < 0)
				{
					return false;
				}
			}
			return true;
		}

		internal static int Category(string prefab, string type, string skill, bool build, float health, float stamina, float eitr, bool unnamed)
		{
			string text = prefab.ToLowerInvariant();
			if (unnamed || text.Contains("_test") || text.StartsWith("test") || text.Contains("cheat") || text.StartsWith("dev"))
			{
				return 10;
			}
			if (type == "Trophy")
			{
				return 8;
			}
			if (text.StartsWith("mead") || text.StartsWith("barleywine"))
			{
				return 6;
			}
			if (health > 0f || stamina > 0f || eitr > 0f || type == "Consumable")
			{
				return 5;
			}
			switch (Categories.Classify(prefab, type, skill, build, ""))
			{
			case 1:
				return 1;
			case 2:
				return 2;
			case 3:
				return 4;
			case 4:
				return 3;
			default:
				if (!(type == "Material"))
				{
					return 9;
				}
				return 7;
			}
		}
	}
	public static class Categories
	{
		public static int StationMode(string station)
		{
			string text = station.ToLowerInvariant();
			if (text.Contains("artisan"))
			{
				return -1;
			}
			if (text.Contains("stonecutter"))
			{
				return 4;
			}
			if (text.Contains("meadcauldron"))
			{
				return 2;
			}
			if (text.Contains("preptable"))
			{
				return 3;
			}
			if (!text.Contains("cauldron"))
			{
				return 0;
			}
			return 1;
		}

		public static int Food(float health, float stamina, float eitr)
		{
			if (eitr > 0f)
			{
				return 2;
			}
			if (health <= 0f && stamina <= 0f)
			{
				return -1;
			}
			if (Math.Abs(health - stamina) < 0.001f)
			{
				return 3;
			}
			if (!(health > stamina))
			{
				return 1;
			}
			return 0;
		}

		public static int Mead(string prefab)
		{
			string text = prefab.Replace("(Clone)", "").Trim().ToLowerInvariant();
			switch (text)
			{
			case "barleywinebase":
			case "barleywine":
			case "meadbasepoisonresist":
			case "meadpoisonresist":
			case "meadbasefrostresist":
			case "meadfrostresist":
				return 1;
			default:
				if (text.StartsWith("meadbasehealth") || text.StartsWith("meadhealth") || text.StartsWith("meadbasestamina") || text.StartsWith("meadstamina") || text.StartsWith("meadbaseeitr") || text.StartsWith("meadeitr"))
				{
					return 0;
				}
				return 2;
			}
		}

		public static int Prep(string prefab, int food)
		{
			string text = prefab.Replace("(Clone)", "").Trim().ToLowerInvariant();
			if (text == "roastedcrustpieuncooked")
			{
				return 1;
			}
			if (text == "ovenpancakeuncooked")
			{
				return 2;
			}
			if (text.StartsWith("fishingbait"))
			{
				return 4;
			}
			if (text.StartsWith("feast") && text != "feaster")
			{
				return 3;
			}
			if (food < 0 || food >= 3)
			{
				return -1;
			}
			return food;
		}

		public static int WeaponOrder(string type, string skill)
		{
			if (type == "Shield")
			{
				return 10;
			}
			return skill switch
			{
				"Swords" => 0, 
				"Knives" => 1, 
				"Axes" => 2, 
				"Clubs" => 3, 
				"Polearms" => 4, 
				"Spears" => 5, 
				"Bows" => 6, 
				"Crossbows" => 7, 
				"Unarmed" => 8, 
				"ElementalMagic" => 11, 
				"BloodMagic" => 12, 
				_ => 20, 
			};
		}

		public static int Classify(string prefab, string type, string skill, bool buildTool, string station)
		{
			string text = prefab.Replace("(Clone)", "").Trim().ToLowerInvariant();
			string text2 = station.ToLowerInvariant();
			if ((text2.Contains("blackforge") || text2.Contains("magetable")) && text.EndsWith("uncooked"))
			{
				return 5;
			}
			switch (text)
			{
			case "scythe":
			case "knifebutcher":
			case "grapplinghook":
			case "shovel":
			case "bomblava":
			case "bombdynamite":
			case "demister":
			case "axestone":
			case "axeflint":
				return 3;
			default:
			{
				if (text.StartsWith("tankard") || text.StartsWith("snowball") || text == "bombsmoke")
				{
					return 5;
				}
				bool flag = skill == "Axes" || text.StartsWith("axe") || text.StartsWith("battleaxe") || text.StartsWith("thaxe");
				if (flag && text2.Contains("blackforge"))
				{
					return 1;
				}
				if (flag && type == "OneHandedWeapon" && text2.Contains("forge"))
				{
					return 3;
				}
				switch (type)
				{
				case "Ammo":
				case "AmmoNonEquipable":
					return 4;
				default:
					if (!(skill == "Pickaxes") && !buildTool)
					{
						switch (type)
						{
						case "Helmet":
						case "Chest":
						case "Legs":
						case "Hands":
						case "Shoulder":
						case "Utility":
						case "Trinket":
							return 2;
						default:
							if (!flag)
							{
								switch (type)
								{
								case "OneHandedWeapon":
								case "TwoHandedWeapon":
								case "TwoHandedWeaponLeft":
								case "Bow":
								case "Shield":
								case "Attach_Atgeir":
									break;
								default:
									return 5;
								}
							}
							return 1;
						}
					}
					goto case "Tool";
				case "Tool":
					return 3;
				}
			}
			}
		}
	}
	internal sealed class CategorySelection
	{
		private int mask;

		internal int Snapshot => mask;

		internal bool All => mask == 0;

		internal void Restore(int saved, int count)
		{
			int num = (1 << count - 1) - 1;
			mask = saved & num;
			if (mask == num)
			{
				Reset();
			}
		}

		internal void Reset()
		{
			mask = 0;
		}

		internal bool Contains(int index)
		{
			if (index != 0)
			{
				if (index > 0)
				{
					return (mask & (1 << index - 1)) != 0;
				}
				return false;
			}
			return All;
		}

		internal void Click(int index, bool shift, int count)
		{
			if (index <= 0 || count <= 1)
			{
				Reset();
			}
			else if (index < count)
			{
				int num = 1 << index - 1;
				mask = (shift ? (mask ^ num) : num);
				if (mask == (1 << count - 1) - 1)
				{
					Reset();
				}
			}
		}
	}
	public class FoodSymbol : MaskableGraphic
	{
		public bool Heart;

		protected override void OnPopulateMesh(VertexHelper mesh)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_004f: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			mesh.Clear();
			Rect rect = ((Graphic)this).rectTransform.rect;
			float num = Mathf.Min(((Rect)(ref rect)).width, ((Rect)(ref rect)).height);
			if (Heart)
			{
				mesh.AddVert(new Vector3(0f, (0f - num) * 0.06f, 0f), Color32.op_Implicit(((Graphic)this).color), Vector4.op_Implicit(Vector2.zero));
				for (int i = 0; i < 128; i++)
				{
					float num2 = (float)Math.PI * 2f * (float)i / 128f;
					float num3 = 16f * Mathf.Pow(Mathf.Sin(num2), 3f);
					float num4 = 13f * Mathf.Cos(num2) - 5f * Mathf.Cos(2f * num2) - 2f * Mathf.Cos(3f * num2) - Mathf.Cos(4f * num2);
					mesh.AddVert(new Vector3(num3 / 36f * num, (num4 + 2f) / 40f * num, 0f), Color32.op_Implicit(((Graphic)this).color), Vector4.op_Implicit(Vector2.zero));
				}
				for (int j = 0; j < 128; j++)
				{
					mesh.AddTriangle(0, j + 1, (j + 1) % 128 + 1);
				}
				return;
			}
			Vector2[] array = (Vector2[])(object)new Vector2[6]
			{
				new Vector2(0.12f, 0.48f),
				new Vector2(-0.34f, -0.05f),
				new Vector2(-0.06f, -0.05f),
				new Vector2(-0.16f, -0.48f),
				new Vector2(0.34f, 0.12f),
				new Vector2(0.05f, 0.12f)
			};
			Vector2[] array2 = array;
			for (int k = 0; k < array2.Length; k++)
			{
				Vector2 val = array2[k];
				mesh.AddVert(new Vector3(val.x * num, val.y * num, 0f), Color32.op_Implicit(((Graphic)this).color), Vector4.op_Implicit(Vector2.zero));
			}
			mesh.AddTriangle(0, 1, 2);
			mesh.AddTriangle(0, 2, 5);
			mesh.AddTriangle(2, 3, 4);
			mesh.AddTriangle(2, 4, 5);
		}
	}
	internal static class NativeSkin
	{
		private static readonly Dictionary<string, Sprite> sprites = new Dictionary<string, Sprite>();

		internal static Sprite Find(string name)
		{
			if (sprites.TryGetValue(name, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
			foreach (Sprite val in array)
			{
				if (((Object)val).name == name)
				{
					sprites[name] = val;
					return val;
				}
			}
			return null;
		}

		internal static void Field(TMP_InputField input, Sprite sprite)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)input) && Object.op_Implicit((Object)(object)sprite))
			{
				Image component = ((Component)input).GetComponent<Image>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.sprite = sprite;
					component.overrideSprite = null;
					component.type = (Type)1;
					((Graphic)component).color = Color.white;
				}
				((Selectable)input).transition = (Transition)0;
				Graphic placeholder = input.placeholder;
				TMP_Text val = (TMP_Text)(object)((placeholder is TMP_Text) ? placeholder : null);
				if (Object.op_Implicit((Object)(object)val))
				{
					Loc.Set(val, "filter");
					((Graphic)val).color = new Color(0.55f, 0.55f, 0.55f, 1f);
					val.fontStyle = (FontStyles)2;
				}
			}
		}

		internal static RectTransform Rect(string name, Transform parent, float x, float y, float w, float h)
		{
			//IL_0016: 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_0042: 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_0044: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			Vector2 val = (component.pivot = new Vector2(0f, 1f));
			Vector2 anchorMin = (component.anchorMax = val);
			component.anchorMin = anchorMin;
			component.anchoredPosition = new Vector2(x, 0f - y);
			component.sizeDelta = new Vector2(w, h);
			return component;
		}

		internal static Image Image(RectTransform r, Sprite sprite, Color color)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			Image val = ((Component)r).gameObject.AddComponent<Image>();
			val.sprite = sprite;
			((Graphic)val).color = color;
			val.type = (Type)((Object.op_Implicit((Object)(object)sprite) && sprite.border != Vector4.zero) ? 1 : 0);
			return val;
		}

		internal static TMP_Text Text(Transform parent, TMP_Text template, string value, float x, float y, float w, float h, float size)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = Rect("Label", parent, x, y, w, h);
			TextMeshProUGUI val2 = ((Component)val).gameObject.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val2).font = template.font;
			((TMP_Text)val2).fontSharedMaterial = template.fontSharedMaterial;
			((TMP_Text)val2).fontSize = size;
			((TMP_Text)val2).text = value;
			((Graphic)val2).color = Color.white;
			((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
			((Graphic)val2).raycastTarget = false;
			((TMP_Text)val2).richText = false;
			((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
			return (TMP_Text)(object)val2;
		}
	}
	[DefaultExecutionOrder(10000)]
	public class CraftSearchSkin : MonoBehaviour
	{
		private Sprite field;

		private TMP_InputField input;

		private TMP_InputField styledInput;

		private Sprite styledSprite;

		private float retry;

		private void LateUpdate()
		{
			if (!Object.op_Implicit((Object)(object)InventoryGui.instance))
			{
				input = null;
				styledInput = null;
				styledSprite = null;
				return;
			}
			if (!Object.op_Implicit((Object)(object)input) && Time.unscaledTime >= retry)
			{
				retry = Time.unscaledTime + 1f;
				TMP_InputField[] componentsInChildren = ((Component)InventoryGui.instance).GetComponentsInChildren<TMP_InputField>(true);
				foreach (TMP_InputField val in componentsInChildren)
				{
					if (((Object)val).name == "PerfectCraftTableSearch")
					{
						input = val;
						break;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)field) && Object.op_Implicit((Object)(object)input))
			{
				field = NativeSkin.Find("text_field");
			}
			if (Object.op_Implicit((Object)(object)input) && ((Object)(object)input != (Object)(object)styledInput || (Object)(object)field != (Object)(object)styledSprite))
			{
				NativeSkin.Field(input, field);
				styledInput = input;
				styledSprite = field;
			}
		}
	}
	public class CatalogCell : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
	{
		internal Action<InputButton> Click;

		public void OnPointerClick(PointerEventData data)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (Click != null)
			{
				Click(data.button);
			}
		}
	}
	public class ItemCatalog : MonoBehaviour
	{
		private class Entry
		{
			internal GameObject Prefab;

			internal string Name;

			internal int Category;
		}

		private class Cell
		{
			internal RectTransform Root;

			internal Image Icon;

			internal TMP_Text Count;

			internal UITooltip Tip;

			internal Entry Entry;
		}

		[HarmonyPatch(typeof(Chat), "HasFocus")]
		private class Focus
		{
			private static void Postfix(ref bool __result)
			{
				if (Visible && Object.op_Implicit((Object)(object)Current.filter) && ((Behaviour)Current.filter).isActiveAndEnabled && Current.filter.isFocused)
				{
					__result = true;
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Hide")]
		private class Hide
		{
			private static void Prefix()
			{
				if (Object.op_Implicit((Object)(object)Current))
				{
					Current.Close();
				}
			}
		}

		private const int Columns = 8;

		private const float Pitch = 70f;

		private const float CellSize = 64f;

		private const float ViewportHeight = 280f;

		internal static ItemCatalog Current;

		private InventoryGui gui;

		private RectTransform toggle;

		private RectTransform toggleBacking;

		private RectTransform overlay;

		private RectTransform panel;

		private RectTransform content;

		private Image toggleFace;

		private TMP_InputField filter;

		private TMP_Text hint;

		private ScrollRect scroll;

		private Sprite fieldSprite;

		private Sprite normalButton;

		private Sprite activeButton;

		private TMP_Text font;

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

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

		private readonly List<Cell> cells = new List<Cell>();

		private readonly List<Image> tabs = new List<Image>();

		private int selectedCategory;

		private int firstRow = -1;

		private bool rebuilding;

		private static readonly string[] Labels = new string[11]
		{
			"all", "weapons", "equipment", "ammo", "tools", "food", "meads", "materials", "trophies", "misc",
			"dev"
		};

		private string catalogLanguage;

		private Texture2D starTexture;

		private Sprite starSprite;

		internal static bool Visible
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Current) && Object.op_Implicit((Object)(object)Current.overlay))
				{
					return ((Component)Current.overlay).gameObject.activeSelf;
				}
				return false;
			}
		}

		internal static bool Allowed
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					return Player.m_debugMode;
				}
				return false;
			}
		}

		private void Awake()
		{
			Current = this;
		}

		private void Update()
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)gui))
			{
				gui = InventoryGui.instance;
			}
			if (!Object.op_Implicit((Object)(object)gui))
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)toggle) && Allowed && InventoryGui.IsVisible())
			{
				BuildToggle();
			}
			if (Object.op_Implicit((Object)(object)toggle))
			{
				((Component)toggle).gameObject.SetActive(Allowed && InventoryGui.IsVisible());
			}
			if (Object.op_Implicit((Object)(object)toggleBacking))
			{
				((Component)toggleBacking).gameObject.SetActive(Allowed && InventoryGui.IsVisible());
			}
			if (!Allowed || !InventoryGui.IsVisible())
			{
				Close();
				return;
			}
			if (Object.op_Implicit((Object)(object)toggle))
			{
				Transform parent = Plugin.Field<TMP_Text>(gui, "m_armor").transform.parent;
				Transform parent2 = Plugin.Field<TMP_Text>(gui, "m_weight").transform.parent;
				Vector3 val = (parent.position + parent2.position) * 0.5f + ((Transform)toggle).parent.TransformVector(new Vector3(0f, 6f, 0f));
				((Transform)toggle).position = val + ((Transform)toggle).parent.TransformVector(new Vector3(6f, 0f, 0f));
				if (Object.op_Implicit((Object)(object)toggleBacking))
				{
					((Transform)toggleBacking).position = val;
				}
			}
			if (Visible)
			{
				if (catalogLanguage != Loc.Language)
				{
					LoadEntries();
					ApplyFilter();
				}
				if (Input.GetKeyDown((KeyCode)27))
				{
					Close();
					return;
				}
				Fit();
				RefreshCells();
			}
		}

		private void BuildToggle()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Expected O, but got Unknown
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			font = Plugin.Field<TMP_Text>(gui, "m_craftingStationName");
			Button val = Plugin.Field<Button>(gui, "m_repairButton");
			Graphic targetGraphic = ((Selectable)val).targetGraphic;
			Image val2 = (Image)(object)((targetGraphic is Image) ? targetGraphic : null);
			SpriteState spriteState = ((Selectable)val).spriteState;
			Sprite obj;
			if (!Object.op_Implicit((Object)(object)((SpriteState)(ref spriteState)).disabledSprite))
			{
				obj = val2.sprite;
			}
			else
			{
				SpriteState spriteState2 = ((Selectable)val).spriteState;
				obj = ((SpriteState)(ref spriteState2)).disabledSprite;
			}
			normalButton = obj;
			activeButton = val2.sprite;
			Transform parent = Plugin.Field<TMP_Text>(gui, "m_armor").transform.parent.parent;
			toggle = NativeSkin.Rect("PerfectCraftTableDebug", parent, 0f, 0f, 64f, 64f);
			toggle.pivot = new Vector2(0.5f, 0.5f);
			((Transform)toggle).localScale = new Vector3(0.8f, 0.8f, 1f);
			Image component = ((Component)Plugin.Field<TMP_Text>(gui, "m_armor").transform.parent.Find("bkg")).GetComponent<Image>();
			toggleBacking = NativeSkin.Rect("PerfectCraftTableDebugBacking", parent, 0f, 0f, 80f, 72f);
			toggleBacking.pivot = new Vector2(0.5f, 0.5f);
			((Transform)toggleBacking).localScale = Vector3.one;
			Image val3 = NativeSkin.Image(toggleBacking, component.sprite, ((Graphic)component).color);
			((Graphic)val3).material = ((Graphic)component).material;
			val3.type = component.type;
			((Graphic)val3).raycastTarget = false;
			Transform val4 = parent.Find("Bkg");
			((Transform)toggleBacking).SetSiblingIndex(Object.op_Implicit((Object)(object)val4) ? val4.GetSiblingIndex() : 0);
			toggleFace = NativeSkin.Image(toggle, normalButton, Color.white);
			Button val5 = ((Component)toggle).gameObject.AddComponent<Button>();
			((Selectable)val5).targetGraphic = (Graphic)(object)toggleFace;
			((UnityEvent)val5.onClick).AddListener(new UnityAction(Toggle));
			Navigation navigation = ((Selectable)val5).navigation;
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)val5).navigation = navigation;
			Image val6 = NativeSkin.Image(NativeSkin.Rect("Star", (Transform)(object)toggle, 10f, 10f, 44f, 44f), LoadStar(), Color.white);
			val6.preserveAspect = true;
			((Graphic)val6).raycastTarget = false;
			UITooltip tip = ((Component)toggle).gameObject.AddComponent<UITooltip>();
			Loc.Tip(tip, "catalog", " (debugmode)");
		}

		private Sprite LoadStar()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)starSprite))
			{
				return starSprite;
			}
			using (Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("CraftingTabs.CatalogStar.png"))
			{
				if (stream == null)
				{
					throw new InvalidOperationException("Catalog star resource missing");
				}
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				starTexture = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(starTexture, memoryStream.ToArray()))
				{
					throw new InvalidOperationException("Invalid catalog star PNG");
				}
			}
			((Texture)starTexture).filterMode = (FilterMode)1;
			((Texture)starTexture).wrapMode = (TextureWrapMode)1;
			Color32[] pixels = starTexture.GetPixels32();
			int width = ((Texture)starTexture).width;
			int height = ((Texture)starTexture).height;
			int num = width;
			int num2 = height;
			int num3 = 0;
			int num4 = 0;
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					if (pixels[i * width + j].a > 8)
					{
						num = Math.Min(j, num);
						num2 = Math.Min(i, num2);
						num3 = Math.Max(j, num3);
						num4 = Math.Max(i, num4);
					}
				}
			}
			if (num > num3 || num2 > num4)
			{
				throw new InvalidOperationException("Empty catalog star");
			}
			num = Math.Max(0, num - 2);
			num2 = Math.Max(0, num2 - 2);
			num3 = Math.Min(width - 1, num3 + 2);
			num4 = Math.Min(height - 1, num4 + 2);
			starSprite = Sprite.Create(starTexture, new Rect((float)num, (float)num2, (float)(num3 - num + 1), (float)(num4 - num2 + 1)), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
			return starSprite;
		}

		private void Toggle()
		{
			if (Allowed)
			{
				if (Visible)
				{
					Close();
				}
				else
				{
					Open();
				}
			}
		}

		private void Open()
		{
			if (Allowed && InventoryGui.IsVisible())
			{
				if (!Object.op_Implicit((Object)(object)overlay))
				{
					BuildPanel();
				}
				LoadEntries();
				filter.SetTextWithoutNotify("");
				selectedCategory = 0;
				ApplyFilter();
				((Component)overlay).gameObject.SetActive(true);
				((Transform)overlay).SetAsLastSibling();
				toggleFace.sprite = activeButton;
				Fit();
			}
		}

		private void Close()
		{
			if (Object.op_Implicit((Object)(object)overlay))
			{
				((Component)overlay).gameObject.SetActive(false);
			}
			if (Object.op_Implicit((Object)(object)filter))
			{
				filter.DeactivateInputField(false);
			}
			if (Object.op_Implicit((Object)(object)toggleFace))
			{
				toggleFace.sprite = normalButton;
			}
		}

		private void Fit()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007e: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = Plugin.Field<TMP_Text>(gui, "m_armor").transform.parent.parent.Find("Bkg");
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			val.GetWorldCorners(array);
			((Transform)panel).localScale = Vector3.one;
			((Transform)panel).position = array[0] + ((Transform)val).parent.TransformVector(new Vector3(0f, -18f, 0f));
		}

		private void BuildPanel()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Expected O, but got Unknown
			//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Expected O, but got Unknown
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: 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_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Expected O, but got Unknown
			//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0604: Unknown result type (might be due to invalid IL or missing references)
			//IL_0606: Unknown result type (might be due to invalid IL or missing references)
			//IL_0607: Unknown result type (might be due to invalid IL or missing references)
			//IL_060e: Unknown result type (might be due to invalid IL or missing references)
			//IL_061c: Unknown result type (might be due to invalid IL or missing references)
			//IL_063e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0648: Expected O, but got Unknown
			//IL_064f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0654: Unknown result type (might be due to invalid IL or missing references)
			//IL_0665: Unknown result type (might be due to invalid IL or missing references)
			//IL_082e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0860: Unknown result type (might be due to invalid IL or missing references)
			//IL_0865: Unknown result type (might be due to invalid IL or missing references)
			//IL_0871: Unknown result type (might be due to invalid IL or missing references)
			//IL_0969: Unknown result type (might be due to invalid IL or missing references)
			//IL_099a: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a4: Expected O, but got Unknown
			//IL_08d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e0: Expected O, but got Unknown
			cells.Clear();
			tabs.Clear();
			fieldSprite = NativeSkin.Find("text_field");
			RectTransform parent = (RectTransform)Plugin.Field<TMP_Text>(gui, "m_armor").transform.parent.parent.parent;
			overlay = NativeSkin.Rect("PerfectCraftTableCatalog", (Transform)(object)parent, 0f, 0f, 0f, 0f);
			overlay.anchorMax = Vector2.one;
			RectTransform obj = overlay;
			Vector2 offsetMin = (overlay.offsetMax = Vector2.zero);
			obj.offsetMin = offsetMin;
			panel = NativeSkin.Rect("Panel", (Transform)(object)overlay, 0f, 0f, 718f, 390f);
			RectTransform obj2 = panel;
			RectTransform obj3 = panel;
			Vector2 val = (panel.pivot = new Vector2(0f, 1f));
			Vector2 anchorMin = (obj3.anchorMax = val);
			obj2.anchorMin = anchorMin;
			panel.anchoredPosition = Vector2.zero;
			Transform val4 = Plugin.Field<TMP_Text>(gui, "m_armor").transform.parent.parent.Find("Bkg");
			Image val5 = (Object.op_Implicit((Object)(object)val4) ? ((Component)val4).GetComponent<Image>() : null);
			Image val6 = NativeSkin.Image(NativeSkin.Rect("Wood", (Transform)(object)panel, 0f, 0f, 590f, 390f), Object.op_Implicit((Object)(object)val5) ? val5.sprite : NativeSkin.Find("woodpanel"), Object.op_Implicit((Object)(object)val5) ? ((Graphic)val5).color : Color.white);
			val6.type = (Type)1;
			if (Object.op_Implicit((Object)(object)val5))
			{
				((Graphic)val6).material = ((Graphic)val5).material;
				val6.pixelsPerUnitMultiplier = val5.pixelsPerUnitMultiplier;
			}
			Loc.Set(NativeSkin.Text((Transform)(object)panel, font, "", 215f, 10f, 350f, 36f, 24f), "catalog");
			RectTransform val7 = NativeSkin.Rect("CatalogFilter", (Transform)(object)panel, 18f, 12f, 190f, 32f);
			Image targetGraphic = NativeSkin.Image(val7, fieldSprite, Color.white);
			RectTransform val8 = NativeSkin.Rect("TextViewport", (Transform)(object)val7, 10f, 2f, 170f, 28f);
			((Component)val8).gameObject.AddComponent<RectMask2D>();
			TMP_Text val9 = NativeSkin.Text((Transform)(object)val8, font, "", 0f, 0f, 170f, 28f, 18f);
			val9.alignment = (TextAlignmentOptions)4097;
			TMP_Text val10 = NativeSkin.Text((Transform)(object)val8, font, "", 0f, 0f, 170f, 28f, 18f);
			val10.alignment = (TextAlignmentOptions)4097;
			filter = ((Component)val7).gameObject.AddComponent<TMP_InputField>();
			((Selectable)filter).targetGraphic = (Graphic)(object)targetGraphic;
			filter.textViewport = val8;
			filter.textComponent = val9;
			filter.placeholder = (Graphic)(object)val10;
			filter.characterLimit = 100;
			filter.richText = false;
			filter.lineType = (LineType)0;
			((UnityEvent<string>)(object)filter.onValueChanged).AddListener((UnityAction<string>)delegate
			{
				ApplyFilter();
			});
			NativeSkin.Field(filter, fieldSprite);
			RectTransform val11 = NativeSkin.Rect("ItemsViewport", (Transform)(object)panel, 15f, 60f, 560f, 280f);
			NativeSkin.Image(val11, null, Color.clear);
			((Component)val11).gameObject.AddComponent<RectMask2D>();
			content = NativeSkin.Rect("Items", (Transform)(object)val11, 0f, 0f, 560f, 280f);
			scroll = ((Component)val11).gameObject.AddComponent<ScrollRect>();
			scroll.viewport = val11;
			scroll.content = content;
			scroll.horizontal = false;
			scroll.vertical = true;
			scroll.movementType = (MovementType)2;
			scroll.scrollSensitivity = 118.3f;
			scroll.inertia = false;
			Scrollbar val12 = Object.Instantiate<Scrollbar>(Plugin.Field<Scrollbar>(gui, "m_recipeListScroll"), (Transform)(object)panel, false);
			((Object)val12).name = "CatalogScrollbar";
			val12.onValueChanged = new ScrollEvent();
			((Component)val12).gameObject.SetActive(true);
			RectTransform val13 = (RectTransform)((Component)val12).transform;
			Vector2 val14 = (val13.pivot = new Vector2(0f, 1f));
			Vector2 anchorMin2 = (val13.anchorMax = val14);
			val13.anchorMin = anchorMin2;
			val13.anchoredPosition = new Vector2(577f, -60f);
			val13.sizeDelta = new Vector2(8f, 280f);
			((Transform)val13).localScale = Vector3.one;
			scroll.verticalScrollbar = val12;
			val12.direction = (Direction)2;
			Transform parent2 = Plugin.Field<TMP_Text>(gui, "m_armor").transform.parent.parent;
			InventoryGrid componentInChildren = ((Component)parent2).GetComponentInChildren<InventoryGrid>(true);
			InventoryElement component = componentInChildren.m_elementPrefab.GetComponent<InventoryElement>();
			Graphic targetGraphic2 = ((Selectable)component.m_button).targetGraphic;
			Image val17 = (Image)(object)((targetGraphic2 is Image) ? targetGraphic2 : null);
			_ = val17.sprite;
			for (int num = 0; num < 40; num++)
			{
				Cell cell = new Cell();
				GameObject val18 = Object.Instantiate<GameObject>(componentInChildren.m_elementPrefab, (Transform)(object)content, false);
				((Object)val18).name = "CatalogItem";
				val18.SetActive(true);
				cell.Root = (RectTransform)val18.transform;
				RectTransform root = cell.Root;
				RectTransform root2 = cell.Root;
				Vector2 val19 = (cell.Root.pivot = new Vector2(0f, 1f));
				Vector2 anchorMin3 = (root2.anchorMax = val19);
				root.anchorMin = anchorMin3;
				((Transform)cell.Root).localScale = Vector3.one;
				InventoryElement component2 = val18.GetComponent<InventoryElement>();
				((Behaviour)component2).enabled = false;
				component2.m_button.onClick = new ButtonClickedEvent();
				Navigation navigation = ((Selectable)component2.m_button).navigation;
				((Navigation)(ref navigation)).mode = (Mode)0;
				((Selectable)component2.m_button).navigation = navigation;
				MonoBehaviour[] componentsInChildren = val18.GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val22 in componentsInChildren)
				{
					if (!(val22 is Graphic) && !(val22 is Button) && !(val22 is UITooltip))
					{
						((Behaviour)val22).enabled = false;
					}
				}
				Graphic[] componentsInChildren2 = val18.GetComponentsInChildren<Graphic>(true);
				foreach (Graphic val23 in componentsInChildren2)
				{
					if ((Object)(object)val23 != (Object)(object)((Selectable)component2.m_button).targetGraphic && (Object)(object)val23 != (Object)(object)component2.m_icon && (Object)(object)val23 != (Object)(object)component2.m_amount)
					{
						((Behaviour)val23).enabled = false;
					}
				}
				cell.Icon = component2.m_icon;
				((Component)cell.Icon).gameObject.SetActive(true);
				((Behaviour)cell.Icon).enabled = true;
				cell.Count = component2.m_amount;
				((Component)cell.Count).gameObject.SetActive(true);
				((Behaviour)cell.Count).enabled = true;
				cell.Tip = component2.m_tooltip;
				CatalogCell catalogCell = ((Component)cell.Root).gameObject.AddComponent<CatalogCell>();
				Cell captured = cell;
				catalogCell.Click = delegate(InputButton which)
				{
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					Give(captured.Entry, which);
				};
				cells.Add(cell);
			}
			Sprite sprite = NativeSkin.Find("button");
			for (int num4 = 0; num4 < Labels.Length; num4++)
			{
				int index = num4;
				RectTransform val24 = NativeSkin.Rect("Category" + num4, (Transform)(object)panel, 594f, 12 + num4 * 33, 120f, 31f);
				Image val25 = NativeSkin.Image(val24, sprite, Color.white);
				tabs.Add(val25);
				Button val26 = ((Component)val24).gameObject.AddComponent<Button>();
				((Selectable)val26).targetGraphic = (Graphic)(object)val25;
				Navigation navigation2 = ((Selectable)val26).navigation;
				((Navigation)(ref navigation2)).mode = (Mode)0;
				((Selectable)val26).navigation = navigation2;
				Loc.Set(NativeSkin.Text((Transform)(object)val24, font, "", 2f, 0f, 116f, 31f, (num4 == 2 || num4 == 3 || num4 == 4) ? 14 : 17), Labels[num4]);
				((UnityEvent)val26.onClick).AddListener((UnityAction)delegate
				{
					selectedCategory = index;
					ApplyFilter();
				});
			}
			hint = NativeSkin.Text((Transform)(object)panel, font, "", 15f, 342f, 560f, 22f, 15f);
			Loc.Set(hint, "controls");
			RectTransform val27 = NativeSkin.Rect("Close", (Transform)(object)panel, 445f, 364f, 130f, 24f);
			Image targetGraphic3 = NativeSkin.Image(val27, sprite, Color.white);
			Button val28 = ((Component)val27).gameObject.AddComponent<Button>();
			((Selectable)val28).targetGraphic = (Graphic)(object)targetGraphic3;
			((UnityEvent)val28.onClick).AddListener(new UnityAction(Close));
			Loc.Set(NativeSkin.Text((Transform)(object)val27, font, "", 0f, 0f, 130f, 24f, 16f), "close");
			((Component)overlay).gameObject.SetActive(false);
		}

		private void LoadEntries()
		{
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: 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_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			catalogLanguage = Loc.Language;
			entries.Clear();
			if (!Object.op_Implicit((Object)(object)ObjectDB.instance))
			{
				return;
			}
			HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
			HashSet<string> hashSet2 = new HashSet<string>(StringComparer.Ordinal);
			HashSet<GameObject> recipeItems = new HashSet<GameObject>();
			foreach (Recipe recipe in ObjectDB.instance.m_recipes)
			{
				if (Object.op_Implicit((Object)(object)recipe) && Object.op_Implicit((Object)(object)recipe.m_item))
				{
					recipeItems.Add(((Component)recipe.m_item).gameObject);
				}
			}
			IOrderedEnumerable<GameObject> orderedEnumerable = (from p in ObjectDB.instance.m_items
				where Object.op_Implicit((Object)(object)p)
				orderby recipeItems.Contains(p) descending
				select p).ThenBy<GameObject, string>((GameObject p) => ((Object)p).name, StringComparer.Ordinal);
			foreach (GameObject item in orderedEnumerable)
			{
				if (!Object.op_Implicit((Object)(object)item) || !hashSet.Add(((Object)item).name))
				{
					continue;
				}
				ItemDrop component = item.GetComponent<ItemDrop>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					continue;
				}
				ItemData itemData = component.m_itemData;
				if (itemData != null && itemData.m_shared != null && itemData.m_shared.m_maxStackSize >= 1 && itemData.m_shared.m_icons != null && itemData.m_shared.m_icons.Length != 0 && Object.op_Implicit((Object)(object)itemData.GetIcon()))
				{
					SharedData shared = itemData.m_shared;
					string text = CatalogRules.Identity(shared.m_name, shared.m_description, ((object)shared.m_itemType).ToString(), ((Object)itemData.GetIcon()).GetInstanceID().ToString());
					object obj = text;
					text = string.Concat(obj, "\n", JsonUtility.ToJson((object)shared.m_damages), "\n", shared.m_food, "/", shared.m_foodStamina, "/", shared.m_foodEitr);
					string text2 = text;
					text = text2 + "\n" + (Object.op_Implicit((Object)(object)shared.m_attackStatusEffect) ? ((Object)shared.m_attackStatusEffect).name : "") + "/" + (Object.op_Implicit((Object)(object)shared.m_equipStatusEffect) ? ((Object)shared.m_equipStatusEffect).name : "") + "/" + (Object.op_Implicit((Object)(object)shared.m_consumeStatusEffect) ? ((Object)shared.m_consumeStatusEffect).name : "");
					object obj2 = text;
					text = string.Concat(obj2, "\n", shared.m_maxStackSize, "/", shared.m_armor, "/", shared.m_armorPerLevel, "/", shared.m_skillType);
					if (hashSet2.Add(text))
					{
						string text3 = Localization.instance.Localize(shared.m_name);
						entries.Add(new Entry
						{
							Prefab = item,
							Name = text3,
							Category = CatalogRules.Category(((Object)item).name, ((object)itemData.m_shared.m_itemType).ToString(), ((object)itemData.m_shared.m_skillType).ToString(), (Object)(object)itemData.m_shared.m_buildPieces != (Object)null, itemData.m_shared.m_food, itemData.m_shared.m_foodStamina, itemData.m_shared.m_foodEitr, text3.StartsWith("$") || string.IsNullOrEmpty(text3))
						});
					}
				}
			}
			entries.Sort(delegate(Entry a, Entry b)
			{
				int num = StringComparer.CurrentCultureIgnoreCase.Compare(a.Name, b.Name);
				return (num == 0) ? StringComparer.Ordinal.Compare(((Object)a.Prefab).name, ((Object)b.Prefab).name) : num;
			});
		}

		private void ApplyFilter()
		{
			//IL_00c0: 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)
			rebuilding = true;
			filtered.Clear();
			string query = filter.text.Trim();
			foreach (Entry entry in entries)
			{
				if ((selectedCategory == 0 || entry.Category == selectedCategory) && CatalogRules.Matches(entry.Name, ((Object)entry.Prefab).name, query))
				{
					filtered.Add(entry);
				}
			}
			content.sizeDelta = new Vector2(560f, Mathf.Max(280f, Mathf.Ceil((float)filtered.Count / 8f) * 70f));
			scroll.StopMovement();
			content.anchoredPosition = Vector2.zero;
			scroll.verticalNormalizedPosition = 1f;
			firstRow = -1;
			Sprite val = NativeSkin.Find("button");
			Sprite val2 = NativeSkin.Find("button_pressed");
			for (int i = 0; i < tabs.Count; i++)
			{
				tabs[i].sprite = ((i == selectedCategory && Object.op_Implicit((Object)(object)val2)) ? val2 : val);
			}
			Loc.Set(hint, (filtered.Count == 0) ? "empty" : "controls");
			rebuilding = false;
			RefreshCells();
		}

		private void RefreshCells()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			if (rebuilding || !Object.op_Implicit((Object)(object)content))
			{
				return;
			}
			int num = Mathf.Max(0, Mathf.FloorToInt(content.anchoredPosition.y / 70f));
			if (num == firstRow)
			{
				return;
			}
			firstRow = num;
			for (int i = 0; i < cells.Count; i++)
			{
				int num2 = num * 8 + i;
				Cell cell = cells[i];
				bool flag = num2 < filtered.Count;
				((Component)cell.Root).gameObject.SetActive(flag);
				cell.Entry = (flag ? filtered[num2] : null);
				if (flag)
				{
					cell.Root.anchoredPosition = new Vector2((float)(num2 % 8) * 70f, (float)(-(num2 / 8)) * 70f);
					ItemData itemData = cell.Entry.Prefab.GetComponent<ItemDrop>().m_itemData;
					cell.Icon.sprite = itemData.GetIcon();
					cell.Count.text = itemData.m_shared.m_maxStackSize + "/" + itemData.m_shared.m_maxStackSize;
					cell.Tip.m_topic = cell.Entry.Name;
					Loc.Tip(cell.Tip, "controls");
				}
			}
		}

		private void Give(Entry entry, InputButton button)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			if (!Allowed || !Visible || !InventoryGui.IsVisible() || entry == null || !Object.op_Implicit((Object)(object)entry.Prefab) || ((int)button != 0 && (int)button != 1))
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			ItemData itemData = entry.Prefab.GetComponent<ItemDrop>().m_itemData;
			int num = (((int)button != 0) ? 1 : itemData.m_shared.m_maxStackSize);
			if (!inventory.CanAddItem(entry.Prefab, num))
			{
				Loc.Set(hint, "full");
				return;
			}
			ItemData val = inventory.AddItem(((Object)entry.Prefab).name, num, 1, 0, 0L, "", new Vector2i(-1, -1), true, false, false);
			if (val != null)
			{
				Loc.Set(hint, "added", entry.Name, num);
			}
			else
			{
				Loc.Set(hint, "failed");
			}
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)starSprite))
			{
				Object.Destroy((Object)(object)starSprite);
			}
			if (Object.op_Implicit((Object)(object)starTexture))
			{
				Object.Destroy((Object)(object)starTexture);
			}
			if (Object.op_Implicit((Object)(object)toggle))
			{
				Object.Destroy((Object)(object)((Component)toggle).gameObject);
			}
			if (Object.op_Implicit((Object)(object)toggleBacking))
			{
				Object.Destroy((Object)(object)((Component)toggleBacking).gameObject);
			}
			if (Object.op_Implicit((Object)(object)overlay))
			{
				Object.Destroy((Object)(object)((Component)overlay).gameObject);
			}
			if ((Object)(object)Current == (Object)(object)this)
			{
				Current = null;
			}
		}
	}
	internal static class Loc
	{
		private static int frame = -1;

		private static string language = "English";

		internal static string Language
		{
			get
			{
				if (frame != Time.frameCount)
				{
					frame = Time.frameCount;
					language = ((Localization.instance != null) ? Localization.instance.GetSelectedLanguage() : "English");
				}
				return language;
			}
		}

		internal static string Get(string key, params object[] args)
		{
			string text = TranslationData.Get(Language, key);
			if (Language == "Abenaki" && Localization.instance != null)
			{
				string text2 = key switch
				{
					"misc" => "$hud_misc", 
					"food" => "$tag_food", 
					"materials" => "$hud_materials", 
					"all" => "$radial_all", 
					"trophies" => "$inventory_trophies", 
					"stamina" => "$se_stamina", 
					"health" => "$se_health", 
					"close" => "$menu_close", 
					_ => null, 
				};
				if (text2 != null)
				{
					string text3 = Localization.instance.Localize(text2);
					if (text3 != text2)
					{
						text = text3;
					}
				}
			}
			if (args.Length != 0)
			{
				return string.Format(text, args);
			}
			return text;
		}

		internal static void Set(TMP_Text text, string key, params object[] args)
		{
			if (Object.op_Implicit((Object)(object)text))
			{
				LocalizedLabel localizedLabel = ((Component)text).GetComponent<LocalizedLabel>();
				if (!Object.op_Implicit((Object)(object)localizedLabel))
				{
					localizedLabel = ((Component)text).gameObject.AddComponent<LocalizedLabel>();
				}
				localizedLabel.Set(key, args);
			}
		}

		internal static void Tip(UITooltip tip, string key, string suffix = "")
		{
			LocalizedTip localizedTip = ((Component)tip).GetComponent<LocalizedTip>();
			if (!Object.op_Implicit((Object)(object)localizedTip))
			{
				localizedTip = ((Component)tip).gameObject.AddComponent<LocalizedTip>();
			}
			((Behaviour)localizedTip).enabled = true;
			localizedTip.Set(tip, key, suffix);
		}
	}
	public class LocalizedLabel : MonoBehaviour
	{
		private TMP_Text label;

		private string key;

		private string language;

		private object[] args;

		internal void Set(string newKey, object[] values)
		{
			if (!Object.op_Implicit((Object)(object)label))
			{
				label = ((Component)this).GetComponent<TMP_Text>();
				label.enableAutoSizing = true;
				label.fontSizeMax = label.fontSize;
				label.fontSizeMin = 9f;
			}
			key = newKey;
			args = values;
			Refresh();
		}

		private void Refresh()
		{
			language = Loc.Language;
			label.text = Loc.Get(key, args);
		}

		private void LateUpdate()
		{
			if (Object.op_Implicit((Object)(object)label) && language != Loc.Language)
			{
				Refresh();
			}
		}
	}
	public class LocalizedTip : MonoBehaviour
	{
		private UITooltip tip;

		private string key;

		private string suffix;

		private string language;

		internal void Set(UITooltip target, string newKey, string extra)
		{
			tip = target;
			key = newKey;
			suffix = extra;
			Refresh();
		}

		private void Refresh()
		{
			language = Loc.Language;
			tip.m_text = Loc.Get(key) + suffix;
		}

		private void LateUpdate()
		{
			if (Object.op_Implicit((Object)(object)tip) && language != Loc.Language)
			{
				Refresh();
			}
		}
	}
	[BepInPlugin("yadren1y.PerfectCraftTable", "PerfectCraftTable", "0.10.9")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(InventoryGui), "UpdateRecipeList")]
		private class Filter
		{
			private static void Prefix(InventoryGui __instance, ref List<Recipe> __0)
			{
				Tabs tabs = ((Component)__instance).GetComponent<Tabs>();
				if ((Object)(object)tabs == (Object)null)
				{
					tabs = ((Component)__instance).gameObject.AddComponent<Tabs>();
				}
				tabs.Ensure(__instance);
				if (!TabsAllowed() || tabs.Selection.All)
				{
					return;
				}
				List<Recipe> list = new List<Recipe>();
				foreach (Recipe item in __0)
				{
					if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.m_item) && tabs.MatchesSelected(item))
					{
						list.Add(item);
					}
				}
				__0 = list;
			}
		}

		public class Tabs : MonoBehaviour
		{
			internal readonly CategorySelection Selection = new CategorySelection();

			private int mode = -2;

			private static readonly Dictionary<string, int> stationSelections = new Dictionary<string, int>();

			private string stationKey;

			private InventoryGui gui;

			private RectTransform root;

			private RectTransform backingRoot;

			private readonly Dictionary<RectTransform, Vector2> repairPositions = new Dictionary<RectTransform, Vector2>();

			private readonly List<Image> frames = new List<Image>();

			private readonly List<Sprite> normalFrames = new List<Sprite>();

			private readonly List<Sprite> selectedFrames = new List<Sprite>();

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

			private readonly List<Image> categoryIcons = new List<Image>();

			private readonly List<Shadow> iconShadows = new List<Shadow>();

			private readonly List<Color> inactiveIconColors = new List<Color>();

			private static readonly string[] Names = new string[6] { "all", "weapons", "equipment", "tools", "ammo", "misc" };

			private static readonly string[] Prefabs = new string[6] { "SwordBlackmetal", "SwordBlackmetal", "ArmorWolfChest", "PickaxeStone", "ArrowBronze", "Torch" };

			private Texture2D customHeartTexture;

			private Sprite customHeartSprite;

			private Image houseImage;

			private Texture2D categoryAtlas;

			private readonly List<Sprite> categorySprites = new List<Sprite>();

			private readonly Dictionary<Sprite, Sprite> monochromeSprites = new Dictionary<Sprite, Sprite>();

			private readonly List<Texture2D> monochromeTextures = new List<Texture2D>();

			public bool FoodMode => mode == 1;

			private static string CurrentStationKey()
			{
				Player localPlayer = Player.m_localPlayer;
				if (!Object.op_Implicit((Object)(object)localPlayer))
				{
					return null;
				}
				CraftingStation currentCraftingStation = localPlayer.GetCurrentCraftingStation();
				if (!Object.op_Implicit((Object)(object)currentCraftingStation))
				{
					return null;
				}
				ZNetView component = ((Component)currentCraftingStation).GetComponent<ZNetView>();
				ZDO val = (Object.op_Implicit((Object)(object)component) ? component.GetZDO() : null);
				if (val == null)
				{
					return "instance:" + ((Object)currentCraftingStation).GetInstanceID();
				}
				return "zdo:" + ((object)Unsafe.As<ZDOID, ZDOID>(ref val.m_uid)/*cast due to .constrained prefix*/).ToString();
			}

			private void RememberSelection()
			{
				if (stationKey != null)
				{
					stationSelections[stationKey] = Selection.Snapshot;
				}
			}

			internal bool MatchesSelected(Recipe recipe)
			{
				if (mode == 1)
				{
					int num = FoodCategory(recipe);
					if (num >= 0)
					{
						return Selection.Contains(num + 1);
					}
					return false;
				}
				if (mode == 2)
				{
					return Selection.Contains(Categories.Mead(((Object)recipe.m_item).name) + 1);
				}
				if (mode == 3)
				{
					int num2 = Categories.Prep(((Object)recipe.m_item).name, FoodCategory(recipe));
					if (num2 >= 0)
					{
						return Selection.Contains(num2 + 1);
					}
					return false;
				}
				for (int i = 1; i < buttons.Count; i++)
				{
					if (Selection.Contains(i) && Matches(recipe, i))
					{
						return true;
					}
				}
				return false;
			}

			private void PositionRepair(InventoryGui owner, int stationMode)
			{
				//IL_007d: 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_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				Transform[] array = (Transform[])(object)new Transform[3]
				{
					((Component)Field<Button>(owner, "m_repairButton")).transform,
					Field<Transform>(owner, "m_repairPanel"),
					Field<Transform>(owner, "m_repairPanelSelection")
				};
				Transform[] array2 = array;
				foreach (Transform val in array2)
				{
					RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
					if (Object.op_Implicit((Object)(object)val2))
					{
						if (!repairPositions.ContainsKey(val2))
						{
							repairPositions[val2] = val2.anchoredPosition;
						}
						val2.anchoredPosition = repairPositions[val2] + new Vector2(0f, (float)((stationMode == 0 || stationMode == 3) ? 64 : 0));
					}
				}
			}

			public void Ensure(InventoryGui owner)
			{
				//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0220: Unknown result type (might be due to invalid IL or missing references)
				//IL_024c: Unknown result type (might be due to invalid IL or missing references)
				//IL_025c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0272: Unknown result type (might be due to invalid IL or missing references)
				//IL_0277: Unknown result type (might be due to invalid IL or missing references)
				//IL_0278: Unknown result type (might be due to invalid IL or missing references)
				//IL_027f: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f9: Expected O, but got Unknown
				//IL_031d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0322: Unknown result type (might be due to invalid IL or missing references)
				//IL_0327: Unknown result type (might be due to invalid IL or missing references)
				//IL_033c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0341: Unknown result type (might be due to invalid IL or missing references)
				//IL_0346: Unknown result type (might be due to invalid IL or missing references)
				//IL_037d: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0411: Unknown result type (might be due to invalid IL or missing references)
				//IL_0418: Expected O, but got Unknown
				//IL_0426: Unknown result type (might be due to invalid IL or missing references)
				//IL_042b: Unknown result type (might be due to invalid IL or missing references)
				//IL_042c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0433: Unknown result type (might be due to invalid IL or missing references)
				//IL_0446: Unknown result type (might be due to invalid IL or missing references)
				//IL_0452: Unknown result type (might be due to invalid IL or missing references)
				//IL_045e: Unknown result type (might be due to invalid IL or missing references)
				//IL_047c: Unknown result type (might be due to invalid IL or missing references)
				//IL_048c: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_04bd: Expected O, but got Unknown
				//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_05fc: Expected O, but got Unknown
				//IL_0515: Unknown result type (might be due to invalid IL or missing references)
				//IL_051a: Unknown result type (might be due to invalid IL or missing references)
				//IL_053a: Unknown result type (might be due to invalid IL or missing references)
				//IL_053f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0543: Unknown result type (might be due to invalid IL or missing references)
				//IL_0563: Unknown result type (might be due to invalid IL or missing references)
				//IL_056f: Unknown result type (might be due to invalid IL or missing references)
				//IL_057b: Unknown result type (might be due to invalid IL or missing references)
				//IL_062c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0636: Expected O, but got Unknown
				//IL_0951: Unknown result type (might be due to invalid IL or missing references)
				//IL_0958: Expected O, but got Unknown
				//IL_095a: Unknown result type (might be due to invalid IL or missing references)
				//IL_095f: Unknown result type (might be due to invalid IL or missing references)
				//IL_096a: Unknown result type (might be due to invalid IL or missing references)
				//IL_096f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0ad9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0ad0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a78: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a8e: Unknown result type (might be due to invalid IL or missing references)
				gui = owner;
				int num = StationMode();
				string text = CurrentStationKey();
				PositionRepair(owner, num);
				if (mode != num || stationKey != text)
				{
					RememberSelection();
					stationKey = text;
					if (Object.op_Implicit((Object)(object)root))
					{
						((Component)root).gameObject.SetActive(false);
						Object.Destroy((Object)(object)((Component)root).gameObject);
						root = null;
					}
					if (Object.op_Implicit((Object)(object)backingRoot))
					{
						((Component)backingRoot).gameObject.SetActive(false);
						Object.Destroy((Object)(object)((Component)backingRoot).gameObject);
						backingRoot = null;
					}
					frames.Clear();
					normalFrames.Clear();
					selectedFrames.Clear();
					buttons.Clear();
					categoryIcons.Clear();
					iconShadows.Clear();
					inactiveIconColors.Clear();
					houseImage = null;
					mode = num;
					Selection.Reset();
					if (stationKey != null && stationSelections.TryGetValue(stationKey, out var value))
					{
						Selection.Restore(value, (mode == 4) ? 1 : ((mode == 2) ? 4 : ((mode == 1) ? 5 : 6)));
					}
				}
				if (mode < 0 || Object.op_Implicit((Object)(object)root) || !Object.op_Implicit((Object)(object)ObjectDB.instance))
				{
					return;
				}
				int num2 = ((mode == 4) ? 1 : ((mode == 2) ? 4 : (FoodMode ? 5 : 6)));
				Button val = Field<Button>(owner, "m_repairButton");
				if (!Object.op_Implicit((Object)(object)val))
				{
					return;
				}
				root = new GameObject("CraftingCategoryTabs", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
				((Transform)root).SetParent((Transform)(object)Field<RectTransform>(owner, "m_crafting"), false);
				backingRoot = new GameObject("CraftingCategoryBackings", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
				((Transform)backingRoot).SetParent(((Transform)root).parent, false);
				backingRoot.anchorMin = Vector2.zero;
				backingRoot.anchorMax = Vector2.one;
				RectTransform obj = backingRoot;
				Vector2 offsetMin = (backingRoot.offsetMax = Vector2.zero);
				obj.offsetMin = offsetMin;
				((Transform)backingRoot).SetAsFirstSibling();
				RectTransform obj2 = root;
				Vector2 anchorMin = (root.anchorMax = new Vector2(0f, 1f));
				obj2.anchorMin = anchorMin;
				root.pivot = new Vector2(1f, 1f);
				Transform panel = Field<Transform>(owner, "m_repairPanel");
				GameObject gameObject = ((Component)val).gameObject;
				RectTransform val3 = (RectTransform)gameObject.transform;
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				val3.GetWorldCorners(array);
				Vector3 val4 = ((Transform)root).parent.InverseTransformPoint(array[0]);
				Vector3 val5 = ((Transform)root).parent.InverseTransformPoint(array[2]);
				float num3 = val5.x - val4.x;
				float num4 = val5.y - val4.y;
				root.sizeDelta = new Vector2(num3, (num4 + 16f) * (float)num2);
				((Transform)root).position = ((Transform)root).parent.TransformPoint(new Vector3(val5.x, val4.y - 16f, val4.z));
				for (int i = 0; i < num2; i++)
				{
					int index = i;
					GameObject val6 = Object.Instantiate<GameObject>(gameObject, (Transform)(object)root, false);
					((Object)val6).name = "Category_" + i;
					RectTransform val7 = (RectTransform)val6.transform;
					Vector2 anchorMin2 = (val7.anchorMax = new Vector2(0f, 1f));
					val7.anchorMin = anchorMin2;
					val7.pivot = new Vector2(0f, 1f);
					((Transform)val7).localScale = Vector3.one;
					((Transform)val7).localRotation = Quaternion.identity;
					val7.anchoredPosition = new Vector2(0f, (float)(-i) * (num4 + 16f));
					val7.sizeDelta = new Vector2(num3, num4);
					Button componentInChildren = val6.GetComponentInChildren<Button>(true);
					CopyRepairBacking(panel, ((Component)val).transform, val7);
					componentInChildren.onClick = new ButtonClickedEvent();
					Graphic targetGraphic = ((Selectable)componentInChildren).targetGraphic;
					Image val9 = (Image)(object)((targetGraphic is Image) ? targetGraphic : null);
					Graphic targetGraphic2 = ((Selectable)val).targetGraphic;
					Image val10 = (Image)(object)((targetGraphic2 is Image) ? targetGraphic2 : null);
					if (Object.op_Implicit((Object)(object)val9) && Object.op_Implicit((Object)(object)val10))
					{
						SpriteState spriteState = ((Selectable)val).spriteState;
						Sprite sprite;
						if (!Object.op_Implicit((Object)(object)((SpriteState)(ref spriteState)).disabledSprite))
						{
							sprite = val10.overrideSprite;
						}
						else
						{
							SpriteState spriteState2 = ((Selectable)val).spriteState;
							sprite = ((SpriteState)(ref spriteState2)).disabledSprite;
						}
						val9.sprite = sprite;
						val9.overrideSprite = null;
						((Selectable)componentInChildren).transition = (Transition)1;
						ColorBlock colors = ((Selectable)componentInChildren).colors;
						((ColorBlock)(ref colors)).normalColor = Color.white;
						((ColorBlock)(ref colors)).highlightedColor = new Color(1.08f, 1.08f, 1.08f, 1f);
						((ColorBlock)(ref colors)).selectedColor = Color.white;
						((Selectable)componentInChildren).colors = colors;
					}
					MonoBehaviour[] componentsInChildren = val6.GetComponentsInChildren<MonoBehaviour>(true);
					foreach (MonoBehaviour val11 in componentsInChildren)
					{
						if (!(val11 is Graphic) && !(val11 is Button) && !(val11 is UITooltip))
						{
							((Behaviour)val11).enabled = false;
						}
					}
					Navigation navigation = ((Selectable)componentInChildren).navigation;
					((Navigation)(ref navigation)).mode = (Mode)0;
					((Selectable)componentInChildren).navigation = navigation;
					((UnityEvent)componentInChildren.onClick).AddListener((UnityAction)delegate
					{
						if (!(Field<float>(gui, "m_craftTimer") >= 0f))
						{
							Selection.Click(index, Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303), buttons.Count);
							RememberSelection();
							Paint();
							Refresh.Invoke(gui, new object[1] { true });
							Scrollbar val19 = Field<Scrollbar>(gui, "m_recipeListScroll");
							if (Object.op_Implicit((Object)(object)val19))
							{
								val19.value = 1f;
							}
						}
					});
					buttons.Add(componentInChildren);
					Button[] componentsInChildren2 = val6.GetComponentsInChildren<Button>(true);
					foreach (Button val12 in componentsInChildren2)
					{
						if ((Object)(object)val12 != (Object)(object)componentInChildren)
						{
							val12.onClick = new ButtonClickedEvent();
							((Selectable)val12).interactable = false;
						}
					}
					Transform[] componentsInChildren3 = val6.GetComponentsInChildren<Transform>(true);
					foreach (Transform val13 in componentsInChildren3)
					{
						string text2 = ((Object)val13).name.ToLowerInvariant();
						if ((Object)(object)val13 != (Object)(object)val6.transform && (text2.Contains("selection") || text2.Contains("selected") || text2.Contains("glow")))
						{
							((Component)val13).gameObject.SetActive(false);
						}
					}
					Image val14 = null;
					Image[] componentsInChildren4 = val6.GetComponentsInChildren<Image>(true);
					foreach (Image val15 in componentsInChildren4)
					{
						val15.overrideSprite = null;
						string text3 = (((Object)val15).name + " " + (Object.op_Implicit((Object)(object)val15.sprite) ? ((Object)val15.sprite).name : "")).ToLowerInvariant();
						if (text3.Contains("glow") || text3.Contains("selected") || text3.Contains("selection"))
						{
							((Behaviour)val15).enabled = false;
						}
						else if (text3.Contains("icon") || text3.Contains("hammer") || ((Object)(object)((Component)val15).transform != (Object)(object)val6.transform && text3.Contains("repair") && !text3.Contains("bkg") && !text3.Contains("background") && !text3.Contains("border")))
						{
							((Behaviour)val15).enabled = false;
							val14 = val15;
						}
					}
					if (Object.op_Implicit((Object)(object)val14))
					{
						((Behaviour)val14).enabled = false;
					}
					frames.Add(val9);
					normalFrames.Add(Object.op_Implicit((Object)(object)val9) ? val9.sprite : null);
					selectedFrames.Add(Object.op_Implicit((Object)(object)val10) ? val10.sprite : null);
					UITooltip val16 = ((Component)componentInChildren).GetComponent<UITooltip>();
					if (!Object.op_Implicit((Object)(object)val16))
					{
						val16 = ((Component)componentInChildren).gameObject.AddComponent<UITooltip>();
					}
					Loc.Tip(val16, (mode == 2) ? (new string[4] { "all", "restoration", "resistance", "effects" })[i] : ((mode == 3) ? (new string[6] { "all", "health", "stamina", "eitr", "feasts", "baits" })[i] : (FoodMode ? (new string[5] { "all", "health", "stamina", "eitr", "neutral" })[i] : Names[i])));
					val16.m_topic = "";
					RectTransform val17 = (RectTransform)((Component)componentInChildren).transform;
					Rect rect = val17.rect;
					float width = ((Rect)(ref rect)).width;
					Rect rect2 = val17.rect;
					float size = Mathf.Min(width, ((Rect)(ref rect2)).height) * 0.73f;
					if (mode == 2 || mode == 3)
					{
						if (i == 0)
						{
							HouseIcon(val17, size);
						}
						else
						{
							SpriteIcon(val17, StationIcons.Get((mode == 2) ? i : (3 + i)), size, "StationCategoryIcon");
						}
					}
					else if (FoodMode)
					{
						if (i == 0)
						{
							HouseIcon(val17, size);
						}
						else
						{
							SpriteIcon(val17, StationIcons.Get((i == 4) ? 9 : (3 + i)), size, "CauldronCategoryIcon");
						}
					}
					else
					{
						CustomCategoryIcon(val17, i, size);
					}
					Image component = ((Component)((Transform)val17).GetChild(((Transform)val17).childCount - 1)).GetComponent<Image>();
					categoryIcons.Add(component);
					Shadow val18 = null;
					if (Object.op_Implicit((Object)(object)component) && (Object)(object)component != (Object)(object)houseImage)
					{
						val18 = ((Component)component).gameObject.AddComponent<Shadow>();
						val18.effectColor = new Color(0f, 0f, 0f, 0.65f);
						val18.effectDistance = new Vector2(1f, -2f);
						val18.useGraphicAlpha = true;
					}
					iconShadows.Add(val18);
					inactiveIconColors.Add((Color)(Object.op_Implicit((Object)(object)component) ? ((Graphic)component).color : new Color(0f, 0f, 0f, 0.62f)));
					val6.SetActive(true);
				}
				Paint();
			}

			private void CopyRepairBacking(Transform panel, Transform repair, RectTransform target)
			{
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Expected O, but got Unknown
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Expected O, but got Unknown
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Expected O, but got Unknown
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: 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_00bd: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0143: Unknown result type (might be due to invalid IL or missing references)
				//IL_0147: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_015e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0163: 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_016c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0192: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)panel))
				{
					Image component = ((Component)panel).GetComponent<Image>();
					if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sprite))
					{
						GameObject val = new GameObject("RepairSimpleBacking", new Type[2]
						{
							typeof(RectTransform),
							typeof(Image)
						});
						RectTransform val2 = (RectTransform)val.transform;
						((Transform)val2).SetParent(((Transform)target).parent, false);
						((Transform)val2).SetAsFirstSibling();
						RectTransform val3 = (RectTransform)panel;
						Vector2 anchorMin = (val2.anchorMax = target.anchorMin);
						val2.anchorMin = anchorMin;
						val2.pivot = val3.pivot;
						Transform parent = ((Transform)target).parent;
						Vector3 val4 = parent.InverseTransformPoint(panel.position) - parent.InverseTransformPoint(repair.position);
						Vector2 pivot = ((RectTransform)repair).pivot;
						Vector2 anchoredPosition = target.anchoredPosition;
						float x = pivot.x;
						Rect rect = target.rect;
						float num = x * ((Rect)(ref rect)).width;
						float num2 = pivot.y - 1f;
						Rect rect2 = target.rect;
						Vector2 val5 = anchoredPosition + new Vector2(num, num2 * ((Rect)(ref rect2)).height);
						val2.anchoredPosition = val5 + new Vector2(val4.x, val4.y);
						Rect rect3 = val3.rect;
						val2.sizeDelta = ((Rect)(ref rect3)).size;
						((Transform)val2).rotation = panel.rotation;
						Vector3 lossyScale = panel.lossyScale;
						Vector3 lossyScale2 = parent.lossyScale;
						((Transform)val2).localScale = new Vector3(lossyScale.x / lossyScale2.x, lossyScale.y / lossyScale2.y, 1f);
						Image component2 = val.GetComponent<Image>();
						component2.sprite = component.sprite;
						component2.type = component.type;
						((Graphic)component2).color = ((Graphic)component).color;
						((Graphic)component2).material = ((Graphic)component).material;
						component2.preserveAspect = component.preserveAspect;
						component2.fillCenter = component.fillCenter;
						component2.pixelsPerUnitMultiplier = component.pixelsPerUnitMultiplier;
						((Graphic)component2).raycastTarget = false;
						((Transform)val2).SetParent((Transform)(object)backingRoot, true);
					}
				}
			}

			private void TamingHeart(RectTransform parent, float size)
			{
				//IL_0135: 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_0054: Expected O, but got Unknown
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)customHeartSprite))
				{
					using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("CraftingTabs.Heart.png");
					if (stream == null)
					{
						throw new InvalidOperationException("Embedded heart image is missing");
					}
					using MemoryStream memoryStream = new MemoryStream();
					stream.CopyTo(memoryStream);
					customHeartTexture = new Texture2D(2, 2, (TextureFormat)4, false);
					((Object)customHeartTexture).name = "CraftingTabsHeart";
					if (!ImageConversion.LoadImage(customHeartTexture, memoryStream.ToArray()))
					{
						throw new InvalidOperationException("Unable to decode heart PNG");
					}
					((Texture)customHeartTexture).filterMode = (FilterMode)1;
					((Texture)customHeartTexture).wrapMode = (TextureWrapMode)1;
					customHeartSprite = Sprite.Create(customHeartTexture, new Rect(0f, 0f, (float)((Texture)customHeartTexture).width, (float)((Texture)customHeartTexture).height), new Vector2(0.5f, 0.5f), 100f);
				}
				SpriteIcon(parent, customHeartSprite, size, "CustomHeart");
				((Graphic)((Component)((Transform)parent).Find("CustomHeart")).GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.5f);
			}

			private void SpriteIcon(RectTransform parent, Sprite sprite, float size, string name)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_0041: 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)
				GameObject val = new GameObject(name, new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				RectTransform val2 = (RectTransform)val.transform;
				((Transform)val2).SetParent((Transform)(object)parent, false);
				val2.sizeDelta = new Vector2(size, size);
				Image component = val.GetComponent<Image>();
				component.sprite = sprite;
				component.preserveAspect = true;
				((Graphic)component).raycastTarget = false;
				((Graphic)component).color = new Color(0f, 0f, 0f, 0.62f);
				((Behaviour)component).enabled = (Object)(object)sprite != (Object)null;
			}

			private void LoadCategoryIcons()
			{
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Expected O, but got Unknown
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)categoryAtlas))
				{
					return;
				}
				using (Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("CraftingTabs.CategoryIcons.png"))
				{
					if (stream == null)
					{
						throw new InvalidOperationException("Category icon atlas is missing");
					}
					using MemoryStream memoryStream = new MemoryStream();
					stream.CopyTo(memoryStream);
					categoryAtlas = new Texture2D(2, 2, (TextureFormat)4, false);
					if (!ImageConversion.LoadImage(categoryAtlas, memoryStream.ToArray()))
					{
						throw new InvalidOperationException("Cannot decode category icons");
					}
				}
				((Texture)categoryAtlas).filterMode = (FilterMode)1;
				((Texture)categoryAtlas).wrapMode = (TextureWrapMode)1;
				int num = ((Texture)categoryAtlas).width / 3;
				int num2 = ((Texture)categoryAtlas).height / 2;
				Color32[] pixels = categoryAtlas.GetPixels32();
				for (int i = 0; i < 6; i++)
				{
					int num3 = i % 3 * num;
					int num4 = (1 - i / 3) * num2;
					int num5 = num3 + num;
					int num6 = num4 + num2;
					int num7 = num3;
					int num8 = num4;
					for (int j = num4; j < num4 + num2; j++)
					{
						for (int k = num3; k < num3 + num; k++)
						{
							if (pixels[j * ((Texture)categoryAtlas).width + k].a > 8)
							{
								num5 = Math.Min(num5, k);
								num6 = Math.Min(num6, j);
								num7 = Math.Max(num7, k);
								num8 = Math.Max(num8, j);
							}
						}
					}
					if (num7 < num5 || num8 < num6)
					{
						throw new InvalidOperationException("Empty category icon: " + i);
					}
					num5 = Math.Max(num3, num5 - 2);
					num6 = Math.Max(num4, num6 - 2);
					num7 = Math.Min(num3 + num - 1, num7 + 2);
					num8 = Math.Min(num4 + num2 - 1, num8 + 2);
					Sprite val = Sprite.Create(categoryAtlas, new Rect((float)num5, (float)num6, (float)(num7 - num5 + 1), (float)(num8 - num6 + 1)), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
					((Object)val).name = "PerfectCraftCategory" + i;
					categorySprites.Add(val);
				}
			}

			private void CustomCategoryIcon(RectTransform parent, int index, float size)
			{
				LoadCategoryIcons();
				SpriteIcon(parent, categorySprites[index], size, "CategoryArtwork");
			}

			private void HouseIcon(RectTransform parent, float size)
			{
				CustomCategoryIcon(parent, 0, size);
				houseImage = ((Component)((Transform)parent).GetChild(((Transform)parent).childCount - 1)).GetComponent<Image>();
			}

			private void ResolveHouseIcon()
			{
			}

			private void Icon(RectTransform parent, string prefab, Vector2 pos, float size)
			{
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Expected O, but got Unknown
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				//IL_006f: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0148: Unknown result type (might be due to invalid IL or missing references)
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefab);
				if (!Object.op_Implicit((Object)(object)itemPrefab))
				{
					return;
				}
				ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
				if (Object.op_Implicit((Object)(object)component))
				{
					GameObject val = new GameObject("Icon", new Type[2]
					{
						typeof(RectTransform),
						typeof(Image)
					});
					RectTransform val2 = (RectTransform)val.transform;
					((Transform)val2).SetParent((Transform)(object)parent, false);
					val2.sizeDelta = new Vector2(size, size);
					val2.anchoredPosition = pos;
					Image component2 = val.GetComponent<Image>();
					component2.sprite = component.m_itemData.GetIcon();
					component2.preserveAspect = true;
					((Graphic)component2).raycastTarget = false;
					((Graphic)component2).color = new Color(0f, 0f, 0f, 0.62f);
					if (prefab == "PickaxeStone")
					{
						((Transform)val2).localScale = new Vector3(1.15f, 1.15f, 1f);
						val2.anchoredPosition += new Vector2(0f, 5f);
					}
					if (prefab == "ArrowBronze")
					{
						((Transform)val2).localRotation = Quaternion.Euler(0f, 0f, 45f);
						((Transform)val2).localScale = new Vector3(1.23f, 1.55f, 1f);
					}
				}
			}

			private Sprite Monochrome(Sprite original)
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Expected O, but got Unknown
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fd: 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_0202: Invalid comparison between Unknown and I4
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0204: Unknown result type (might be due to invalid IL or missing references)
				//IL_0207: Invalid comparison between Unknown and I4
				//IL_0209: Unknown result type (might be due to invalid IL or missing references)
				//IL_020c: Invalid comparison between Unknown and I4
				//IL_0226: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: Invalid comparison between Unknown and I4
				//IL_022b: Unknown result type (might be due to invalid IL or missing references)
				//IL_022e: Invalid comparison between Unknown and I4
				//IL_023d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0240: Invalid comparison between Unknown and I4
				//IL_0242: Unknown result type (might be due to invalid IL or missing references)
				//IL_0245: Invalid comparison between Unknown and I4
				//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0272: Unknown result type (might be due to invalid IL or missing references)
				//IL_0277: Unknown result type (might be due to invalid IL or missing references)
				if (monochromeSprites.ContainsValue(original))
				{
					return original;
				}
				if (monochromeSprites.TryGetValue(original, out var value))
				{
					return value;
				}
				Rect textureRect = original.textureRect;
				Texture2D texture = original.texture;
				RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0);
				RenderTexture active = RenderTexture.active;
				Texture2D val = null;
				try
				{
					Graphics.Blit((Texture)(object)texture, temporary);
					RenderTexture.active = temporary;
					val = new Texture2D((int)((Rect)(ref textureRect)).width, (int)((Rect)(ref textureRect)).height, (TextureFormat)4, false);
					val.ReadPixels(textureRect, 0, 0, false);
					Color32[] array = val.GetPixels32();
					Color32[] array2 = (Color32[])array.Clone();
					int width = ((Texture)val).width;
					int height = ((Texture)val).height;
					for (int i = 0; i < height; i++)
					{
						for (int j = 0; j < width; j++)
						{
							int num = i * width + j;
							Color32 val2 = array2[num];
							float num2 = ((j > 0) ? ((float)(int)array2[num - 1].a / 255f) : 0f);
							float num3 = ((j + 1 < width) ? ((float)(int)array2[num + 1].a / 255f) : 0f);
							float num4 = ((i > 0) ? ((float)(int)array2[num - width].a / 255f) : 0f);
							float num5 = ((i + 1 < height) ? ((float)(int)array2[num + width].a / 255f) : 0f);
							float num6 = (num3 - num2 + num4 - num5) * 0.16f;
							byte b = (byte)Mathf.RoundToInt(Mathf.Clamp01(0.82f + num6) * 255f);
							ref Color32 reference = ref array[num];
							reference = new Color32(b, b, b, val2.a);
						}
					}
					if (original.packed)
					{
						int width2 = ((Texture)val).width;
						int height2 = ((Texture)val).height;
						SpritePackingRotation packingRotation = original.packingRotation;
						if ((int)packingRotation == 1 || (int)packingRotation == 2 || (int)packingRotation == 3)
						{
							Color32[] array3 = (Color32[])(object)new Color32[array.Length];
							for (int k = 0; k < height2; k++)
							{
								for (int l = 0; l < width2; l++)
								{
									int num7 = (((int)packingRotation == 1 || (int)packingRotation == 3) ? (width2 - 1 - l) : l);
									int num8 = (((int)packingRotation == 2 || (int)packingRotation == 3) ? (height2 - 1 - k) : k);
									ref Color32 reference2 = ref array3[k * width2 + l];
									reference2 = array[num8 * width2 + num7];
								}
							}
							array = array3;
						}
					}
					val.SetPixels32(array);
					val.Apply(false, true);
					((Texture)val).filterMode = (FilterMode)1;
					((Texture)val).wrapMode = (TextureWrapMode)1;
					Sprite val3 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
					monochromeTextures.Add(val);
					monochromeSprites.Add(original, val3);
					return val3;
				}
				catch
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						Object.Destroy((Object)(object)val);
					}
					throw;
				}
				finally
				{
					RenderTexture.active = active;
					RenderTexture.ReleaseTemporary(temporary);
				}
			}

			private Color SelectedColor(int index)
			{
				//IL_0050: 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)
				if ((FoodMode || mode == 3) && index > 0 && index < 4)
				{
					InventoryGrid componentInChildren = ((Component)gui).GetComponentInChildren<InventoryGrid>(true);
					if (Object.op_Implicit((Object)(object)componentInChildren))
					{
						return Field<Color>(componentInChildren, index switch
						{
							2 => "m_foodStaminaColor", 
							1 => "m_foodHealthColor", 
							_ => "m_foodEitrColor", 
						});
					}
				}
				return Color.white;
			}

			private void Paint()
			{
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < frames.Count; i++)
				{
					bool flag = Selection.Contains(i);
					if (Object.op_Implicit((Object)(object)frames[i]))
					{
						frames[i].sprite = ((flag && Object.op_Implicit((Object)(object)selectedFrames[i])) ? selectedFrames[i] : normalFrames[i]);
					}
					if (Object.op_Implicit((Object)(object)iconShadows[i]))
					{
						((Behaviour)iconShadows[i]).enabled = flag;
					}
					if (Object.op_Implicit((Object)(object)categoryIcons[i]))
					{
						((Graphic)categoryIcons[i]).color = (flag ? SelectedColor(i) : inactiveIconColors[i]);
					}
				}
			}

			private void Update()
			{
				if (!Object.op_Implicit((Object)(object)root))
				{
					return;
				}
				ResolveHouseIcon();
				bool flag = TabsAllowed();
				if (((Component)root).gameObject.activeSelf != flag)
				{
					((Component)root).gameObject.SetActive(flag);
				}
				if (Object.op_Implicit((Object)(object)backingRoot) && ((Component)backingRoot).gameObject.activeSelf != flag)
				{
					((Component)backingRoot).gameObject.SetActive(flag);
				}
				foreach (Button button in buttons)
				{
					if (Object.op_Implicit((Object)(object)button) && !((Selectable)button).interactable)
					{
						((Selectable)button).interactable = true;
					}
				}
			}

			private void OnDestroy()
			{
				//IL_013b: Unknown result type (might be due to invalid IL or missing references)
				RememberSelection();
				foreach (Sprite categorySprite in categorySprites)
				{
					if (Object.op_Implicit((Object)(object)categorySprite))
					{
						Object.Destroy((Object)(object)categorySprite);
					}
				}
				if (Object.op_Implicit((Object)(object)categoryAtlas))
				{
					Object.Destroy((Object)(object)categoryAtlas);
				}
				foreach (Sprite value in monochromeSprites.Values)
				{
					if (Object.op_Implicit((Object)(object)value))
					{
						Object.Destroy((Object)(object)value);
					}
				}
				foreach (Texture2D monochromeTexture in monochromeTextures)
				{
					if (Object.op_Implicit((Object)(object)monochromeTexture))
					{
						Object.Destroy((Object)(object)monochromeTexture);
					}
				}
				if (Object.op_Implicit((Object)(object)customHeartSprite))
				{
					Object.Destroy((Object)(object)customHeartSprite);
				}
				if (Object.op_Implicit((Object)(object)customHeartTexture))
				{
					Object.Destroy((Object)(object)customHeartTexture);
				}
				foreach (KeyValuePair<RectTransform, Vector2> repairPosition in repairPositions)
				{
					if (Object.op_Implicit((Object)(object)repairPosition.Key))
					{
						repairPosition.Key.anchoredPosition = repairPosition.Value;
					}
				}
				if (Object.op_Implicit((Object)(object)root))
				{
					Object.Destroy((Object)(object)((Component)root).gameObject);
				}
				if (Object.op_Implicit((Object)(object)backingRoot))
				{
					Object.Destroy((Object)(object)((Component)backingRoot).gameObject);
				}
			}
		}

		private static Harmony patches;

		private static readonly MethodInfo Refresh = AccessTools.Method(typeof(InventoryGui), "UpdateCraftingPanel", (Type[])null, (Type[])null);

		private static readonly Dictionary<string, ItemDrop> Cooked = new Dictionary<string, ItemDrop>();

		private static ObjectDB foodDatabase;

		internal static T Field<T>(object o, string name)
		{
			return (T)AccessTools.Field(o.GetType(), name).GetValue(o);
		}

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			SearchIntegration.Initialize(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
			patches = new Harmony("yadren1y.PerfectCraftTable");
			patches.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PerfectCraftTable 0.10.9 loaded");
		}

		private void Start()
		{
			SearchIntegration.AttachExisting();
			((Component)this).gameObject.AddComponent<CraftSearchSkin>();
			((Component)this).gameObject.AddComponent<ItemCatalog>();
		}

		private void OnDestroy()
		{
			SearchIntegration.Cleanup();
			if (patches != null)
			{
				patches.UnpatchSelf();
			}
			StationChanges.Restore();
			RepairIcon[] array = Resources.FindObjectsOfTypeAll<RepairIcon>();
			foreach (RepairIcon repairIcon in array)
			{
				Object.DestroyImmediate((Object)(object)repairIcon);
			}
			StationIcons.Release();
		}

		internal static int StationMode()
		{
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return -1;
			}
			CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation();
			if (!Object.op_Implicit((Object)(object)currentCraftingStation))
			{
				return -1;
			}
			return Categories.StationMode(((Object)currentCraftingStation).name + " " + currentCraftingStation.m_name);
		}

		internal static bool TabsAllowed()
		{
			return StationMode() >= 0;
		}

		private static void LoadFoodConversions()
		{
			if ((Object)(object)foodDatabase == (Object)(object)ObjectDB.instance)
			{
				return;
			}
			foodDatabase = ObjectDB.instance;
			Cooked.Clear();
			CookingStation[] array = Resources.FindObjectsOfTypeAll<CookingStation>();
			foreach (CookingStation val in array)
			{
				foreach (ItemConversion item in val.m_conversion)
				{
					if (Object.op_Implicit((Object)(object)item.m_from) && Object.op_Implicit((Object)(object)item.m_to))
					{
						Cooked[item.m_from.m_itemData.m_shared.m_name] = item.m_to;
					}
				}
			}
		}

		private static int FoodCategory(Recipe recipe)
		{
			LoadFoodConversions();
			ItemDrop val = recipe.m_item;
			for (int i = 0; i < 4; i++)
			{
				SharedData shared = val.m_itemData.m_shared;
				if (shared.m_food > 0f || shared.m_foodStamina > 0f || shared.m_foodEitr > 0f)
				{
					return Categories.Food(shared.m_food, shared.m_foodStamina, shared.m_foodEitr);
				}
				if (!Cooked.TryGetValue(shared.m_name, out var value) || (Object)(object)value == (Object)(object)val)
				{
					break;
				}
				val = value;
			}
			return -1;
		}

		internal static bool Matches(Recipe recipe, int category)
		{
			//IL_0028: 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)
			SharedData shared = recipe.m_item.m_itemData.m_shared;
			CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation();
			return Categories.Classify(((Object)recipe.m_item).name, ((object)shared.m_itemType).ToString(), ((object)shared.m_skillType).ToString(), (Object)(object)shared.m_buildPieces != (Object)null, Object.op_Implicit((Object)(object)currentCraftingStation) ? ((Object)currentCraftingStation).name : "") == category;
		}
	}
}
namespace CraftingTabs.Search
{
	public sealed class SearchController : MonoBehaviour
	{
		private static readonly MethodInfo Refresh = AccessTools.Method(typeof(InventoryGui), "UpdateCraftingPanel", new Type[1] { typeof(bool) }, (Type[])null);

		private static readonly FieldInfo CraftTimer = AccessTools.Field(typeof(InventoryGui), "m_craftTimer");

		internal static SearchController Current;

		internal SearchQuery Query = new SearchQuery("");

		private InventoryGui gui;

		private TMP_InputField input;

		private TMP_Text placeholder;

		private