Decompiled source of QoL SortBy RepairALL v1.0.1

SortByQoL.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SortByQoL
{
	internal static class Drawer
	{
		private enum Look
		{
			Normal,
			Current,
			Danger
		}

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

			public static Func<Image, bool> <>9__47_0;

			public static Func<Image, float> <>9__47_2;

			public static UnityAction <>9__61_0;

			public static UnityAction <>9__64_0;

			public static Func<Mat, bool> <>9__82_2;

			public static Action <>9__82_3;

			internal bool <Discover>b__47_0(Image i)
			{
				string text = (((Object)i).name + " " + ((Object)i.sprite).name).ToLowerInvariant();
				string[] array = new string[12]
				{
					"darken", "blob", "shadow", "glow", "select", "icon", "scroll", "handle", "bar", "highlight",
					"button", "tab"
				};
				foreach (string value in array)
				{
					if (text.Contains(value))
					{
						return true;
					}
				}
				return false;
			}

			internal float <Discover>b__47_2(Image i)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				Rect rect = ((Graphic)i).rectTransform.rect;
				float width = ((Rect)(ref rect)).width;
				rect = ((Graphic)i).rectTransform.rect;
				return width * ((Rect)(ref rect)).height;
			}

			internal void <BuildTab>b__61_0()
			{
				ClickSound();
				Toggle();
			}

			internal void <BuildSearch>b__64_0()
			{
				ClickSound();
				if ((Object)(object)input != (Object)null)
				{
					input.ActivateInputField();
					((Selectable)input).Select();
				}
			}

			internal bool <RebuildMenu>b__82_2(Mat m)
			{
				return m.Key == view.Material;
			}

			internal void <RebuildMenu>b__82_3()
			{
				Filter.Expanded = ((Filter.Expanded == "res") ? "" : "res");
				signature = "";
				Sync(view, model, mats);
			}
		}

		private static InventoryGui builtFor;

		private static GameObject tab;

		private static GameObject plate;

		private static GameObject glow;

		private static GameObject menu;

		private static GameObject searchButton;

		private static GameObject searchBox;

		private static GameObject clearX;

		private static RectTransform menuRect;

		private static TMP_InputField input;

		private static UITooltip tabTip;

		private static Button craftTemplate;

		private static bool open;

		private static bool failed;

		private static TMP_FontAsset font;

		private static string signature = "";

		private static Filter.View view;

		private static Model model;

		private static List<Mat> mats = new List<Mat>();

		private const float MenuW = 224f;

		private const float Pad = 8f;

		private const float RowH = 38f;

		private const float RowGap = 4f;

		private const float SubH = 30f;

		private const float SubGap = 4f;

		private const float TileSize = 46f;

		private const float TileGap = 6f;

		private static readonly Color ChipOff = new Color(0f, 0f, 0f, 0.5f);

		private static readonly Color ChipOn = new Color(1f, 0.63f, 0.235f, 0.47f);

		private static readonly Color ChipDim = new Color(1f, 0.63f, 0.235f, 0.2f);

		private static readonly Color Beige = new Color(0.98f, 0.95f, 0.9f);

		private static readonly Color Grey = new Color(0.65f, 0.62f, 0.58f);

		private static readonly Color Green = new Color(0.45f, 0.9f, 0.45f, 1f);

		private static readonly Color Orange = new Color(1f, 0.63f, 0.235f, 1f);

		private static readonly Color Red = new Color(0.96f, 0.36f, 0.28f, 1f);

		private static int typingFrame = -100;

		private static Sprite panelSprite;

		private static Type panelType;

		private static Color panelColor = Color.white;

		private static float panelPpu = 1f;

		private static Material panelMaterial;

		private static bool skin;

		private static readonly Dictionary<string, Sprite> sprites = new Dictionary<string, Sprite>();

		private static readonly MethodInfo UpdatePanel = AccessTools.Method(typeof(InventoryGui), "UpdateCraftingPanel", new Type[1] { typeof(bool) }, (Type[])null);

		private static Sprite sortIcon;

		private static Sprite arrow;

		internal static bool Typing => Time.frameCount - typingFrame <= 1;

		internal static void MarkTyping()
		{
			typingFrame = Time.frameCount;
		}

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

		private static void Discover(InventoryGui gui)
		{
			//IL_0092: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			skin = false;
			try
			{
				List<Image> source = ((Component)gui.m_crafting).GetComponentsInChildren<Image>(true).ToList();
				Func<Image, bool> bad = delegate(Image i)
				{
					string text = (((Object)i).name + " " + ((Object)i.sprite).name).ToLowerInvariant();
					string[] array = new string[12]
					{
						"darken", "blob", "shadow", "glow", "select", "icon", "scroll", "handle", "bar", "highlight",
						"button", "tab"
					};
					foreach (string value in array)
					{
						if (text.Contains(value))
						{
							return true;
						}
					}
					return false;
				};
				Image val = source.Where((Image i) => (Object)(object)i.sprite != (Object)null && !bad(i) && ((Graphic)i).color.a > 0.5f).OrderByDescending(delegate(Image i)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0019: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					Rect rect = ((Graphic)i).rectTransform.rect;
					float width = ((Rect)(ref rect)).width;
					rect = ((Graphic)i).rectTransform.rect;
					return width * ((Rect)(ref rect)).height;
				}).FirstOrDefault();
				if ((Object)(object)val != (Object)null)
				{
					panelSprite = val.sprite;
					panelType = val.type;
					panelColor = ((Graphic)val).color;
					panelPpu = val.pixelsPerUnitMultiplier;
					panelMaterial = ((Graphic)val).material;
				}
				font = PickFont(((Object)(object)gui.m_recipeDecription != (Object)null) ? gui.m_recipeDecription.font : null);
				skin = (Object)(object)val != (Object)null;
			}
			catch (Exception ex)
			{
				SortByQoLPlugin.Log.LogWarning((object)("The game's panel skin was not found (" + ex.Message + "), plain colours are used."));
			}
		}

		private static bool Draws(TMP_FontAsset f)
		{
			if ((Object)(object)f == (Object)null)
			{
				return false;
			}
			try
			{
				return f.HasCharacter('A', true, true) && f.HasCharacter('g', true, true) && f.HasCharacter('7', true, true);
			}
			catch
			{
				return false;
			}
		}

		private static TMP_FontAsset PickFont(TMP_FontAsset wanted)
		{
			TMP_FontAsset val = (Draws(wanted) ? wanted : null);
			string text = (((Object)(object)val != (Object)null) ? "the game's own" : null);
			if ((Object)(object)val == (Object)null)
			{
				TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				foreach (TMP_FontAsset val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && ((Object)val2).name.IndexOf("Averia", StringComparison.OrdinalIgnoreCase) >= 0 && Draws(val2))
					{
						val = val2;
						text = "another Averia font";
						break;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				try
				{
					TMP_FontAsset defaultFontAsset = TMP_Settings.defaultFontAsset;
					if (Draws(defaultFontAsset))
					{
						val = defaultFontAsset;
						text = "TextMeshPro's default";
					}
				}
				catch
				{
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				foreach (TMP_FontAsset val3 in array)
				{
					if (Draws(val3))
					{
						val = val3;
						text = "another font that draws letters";
						break;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = wanted;
				text = "none that draws letters was found, the game's own kept";
			}
			SortByQoLPlugin.Log.LogInfo((object)("SortByQoL font: " + (((Object)(object)val != (Object)null) ? ((Object)val).name : "none") + " (" + text + "); the wanted one was " + (((Object)(object)wanted != (Object)null) ? ((Object)wanted).name : "null") + (Draws(wanted) ? "" : ", it cannot draw plain letters") + "."));
			return val;
		}

		private static RectTransform Rect(string name, Transform parent, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) })
			{
				layer = LayerMask.NameToLayer("UI")
			}.GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			component.anchorMin = aMin;
			component.anchorMax = aMax;
			component.offsetMin = oMin;
			component.offsetMax = oMax;
			return component;
		}

		private static RectTransform Fill(string name, Transform parent, float left, float top, float right, float bottom)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			return Rect(name, parent, Vector2.zero, Vector2.one, new Vector2(left, bottom), new Vector2(0f - right, 0f - top));
		}

		private static RectTransform Top(string name, Transform parent, float x0, float yTop, float x1, float yBottom)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			return Rect(name, parent, val, val, new Vector2(x0, 0f - yBottom), new Vector2(x1, 0f - yTop));
		}

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

		private static TMP_Text Label(RectTransform rt, string text, float size, Color color, TextAlignmentOptions align)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = ((Component)rt).gameObject.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)val).font = font;
			}
			((TMP_Text)val).text = text;
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = color;
			((TMP_Text)val).alignment = align;
			((Graphic)val).raycastTarget = false;
			((TMP_Text)val).enableWordWrapping = false;
			((TMP_Text)val).overflowMode = (TextOverflowModes)1;
			return (TMP_Text)(object)val;
		}

		private static Button Click(Image image, Action click)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			Button obj = ((Component)image).gameObject.AddComponent<Button>();
			((Selectable)obj).targetGraphic = (Graphic)(object)image;
			ColorBlock colors = ((Selectable)obj).colors;
			((ColorBlock)(ref colors)).highlightedColor = new Color(1.3f, 1.2f, 1.1f, 1f);
			((Selectable)obj).colors = colors;
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				ClickSound();
				click();
			});
			return obj;
		}

		private static void ClickSound()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("sfx_gui_button") : null);
			if ((Object)(object)val != (Object)null && (Object)(object)Utils.GetMainCamera() != (Object)null)
			{
				Object.Instantiate<GameObject>(val, ((Component)Utils.GetMainCamera()).transform.position, Quaternion.identity);
			}
		}

		private static bool Keep(Component c)
		{
			if (!(c is Graphic) && !(c is Selectable) && !(c is Mask) && !(c is RectMask2D) && !(c is LayoutGroup) && !(c is ContentSizeFitter) && !(c is LayoutElement) && !(c is BaseMeshEffect))
			{
				return c is UITooltip;
			}
			return true;
		}

		private static GameObject CloneButton(Button source, Transform parent, string name)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			GameObject val = new GameObject("SBQ_Holder");
			val.SetActive(false);
			GameObject val2 = Object.Instantiate<GameObject>(((Component)source).gameObject, val.transform, false);
			((Object)val2).name = name;
			foreach (MonoBehaviour item in val2.GetComponentsInChildren<MonoBehaviour>(true).ToList())
			{
				if ((Object)(object)item != (Object)null && !Keep((Component)(object)item))
				{
					Object.DestroyImmediate((Object)(object)item);
				}
			}
			val2.transform.SetParent(parent, false);
			Object.Destroy((Object)(object)val);
			Image component = val2.GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				((Graphic)component).color = Color.white;
			}
			Button component2 = val2.GetComponent<Button>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Selectable)component2).interactable = true;
				component2.onClick = new ButtonClickedEvent();
			}
			string[] array = new string[2] { "gamepad_hint", "Selected" };
			foreach (string text in array)
			{
				Transform val3 = val2.transform.Find(text);
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)val3).gameObject.SetActive(false);
				}
			}
			return val2;
		}

		internal static void Ensure(InventoryGui gui)
		{
			if ((Object)(object)gui == (Object)null || (Object)(object)gui.m_crafting == (Object)null || (Object)(object)gui.m_repairButton == (Object)null || ((Object)(object)builtFor == (Object)(object)gui && (failed || ((Object)(object)tab != (Object)null && (Object)(object)menu != (Object)null))))
			{
				return;
			}
			Destroy();
			failed = false;
			builtFor = gui;
			craftTemplate = gui.m_craftButton;
			try
			{
				Discover(gui);
				BuildTab(gui);
				BuildMenu(gui);
				BuildSearch(gui);
				menu.SetActive(false);
				if ((Object)(object)glow != (Object)null)
				{
					glow.SetActive(false);
				}
				Place();
			}
			catch (Exception ex)
			{
				failed = true;
				SortByQoLPlugin.Log.LogError((object)("The sort drawer could not be built: " + ex));
			}
			builtFor = gui;
			open = false;
		}

		private static void Destroy()
		{
			GameObject[] array = (GameObject[])(object)new GameObject[5] { tab, plate, menu, searchButton, searchBox };
			foreach (GameObject val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
			tab = (plate = (menu = (glow = (searchButton = (searchBox = (clearX = null))))));
			menuRect = null;
			input = null;
			tabTip = null;
			signature = "";
			open = false;
			builtFor = null;
		}

		private static void BuildTab(InventoryGui gui)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//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_0120: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			Button repairButton = gui.m_repairButton;
			if ((Object)(object)gui.m_repairPanel != (Object)null)
			{
				GameObject val = new GameObject("SBQ_Holder");
				val.SetActive(false);
				GameObject val2 = Object.Instantiate<GameObject>(((Component)gui.m_repairPanel).gameObject, val.transform, false);
				((Object)val2).name = "SBQ_Plate";
				foreach (MonoBehaviour item in val2.GetComponentsInChildren<MonoBehaviour>(true).ToList())
				{
					if ((Object)(object)item != (Object)null && !Keep((Component)(object)item))
					{
						Object.DestroyImmediate((Object)(object)item);
					}
				}
				val2.transform.SetParent((Transform)(object)gui.m_crafting, false);
				Object.Destroy((Object)(object)val);
				val2.SetActive(true);
				plate = val2;
			}
			GameObject obj = CloneButton(repairButton, (Transform)(object)gui.m_crafting, "SBQ_Tab");
			obj.SetActive(true);
			tab = obj;
			Button component = obj.GetComponent<Button>();
			if ((Object)(object)component != (Object)null)
			{
				ButtonClickedEvent onClick = component.onClick;
				object obj2 = <>c.<>9__61_0;
				if (obj2 == null)
				{
					UnityAction val3 = delegate
					{
						ClickSound();
						Toggle();
					};
					<>c.<>9__61_0 = val3;
					obj2 = (object)val3;
				}
				((UnityEvent)onClick).AddListener((UnityAction)obj2);
			}
			Transform val4 = obj.transform.Find("Text");
			if ((Object)(object)val4 != (Object)null)
			{
				((Component)val4).gameObject.SetActive(false);
			}
			Transform val5 = obj.transform.Find("Image");
			if ((Object)(object)val5 != (Object)null)
			{
				RectTransform val6 = (RectTransform)val5;
				Vector2 val7 = default(Vector2);
				((Vector2)(ref val7))..ctor(0.5f, 0.5f);
				val6.anchorMax = val7;
				val6.anchorMin = val7;
				val6.anchoredPosition = Vector2.zero;
				val6.sizeDelta = new Vector2(64f, 64f);
				Image component2 = ((Component)val5).GetComponent<Image>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.sprite = SortSprite();
					component2.type = (Type)0;
					component2.preserveAspect = true;
					((Graphic)component2).color = Color.white;
					((Graphic)component2).raycastTarget = false;
				}
			}
			Transform val8 = obj.transform.Find("Glow");
			glow = (((Object)(object)val8 != (Object)null) ? ((Component)val8).gameObject : null);
			tabTip = obj.GetComponent<UITooltip>();
			if ((Object)(object)tabTip != (Object)null)
			{
				tabTip.m_topic = "Sort and filter";
				tabTip.m_text = "Pick a group, a kind or a resource. Reset clears it.";
			}
			obj.AddComponent<TabFollower>();
			if ((Object)(object)plate != (Object)null && (Object)(object)gui.m_repairPanel != (Object)null)
			{
				plate.transform.SetSiblingIndex(gui.m_repairPanel.GetSiblingIndex());
			}
		}

		internal static void Place()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_0127: 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_0143: 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_015b: 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_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			InventoryGui val = builtFor;
			if (!((Object)(object)val == (Object)null) && !((Object)(object)tab == (Object)null) && !((Object)(object)val.m_repairButton == (Object)null))
			{
				float num = (((Component)val.m_repairButton).gameObject.activeSelf ? 80f : 0f);
				RectTransform val2 = (RectTransform)tab.transform;
				val2.anchoredPosition = ((RectTransform)((Component)val.m_repairButton).transform).anchoredPosition + new Vector2(0f, 0f - num);
				if ((Object)(object)plate != (Object)null && (Object)(object)val.m_repairPanel != (Object)null)
				{
					((RectTransform)plate.transform).anchoredPosition = ((RectTransform)val.m_repairPanel).anchoredPosition + new Vector2(0f, 0f - num);
				}
				if (!((Object)(object)menuRect == (Object)null))
				{
					RectTransform crafting = val.m_crafting;
					Rect rect = crafting.rect;
					float num2 = ((Rect)(ref rect)).height * (1f - val2.anchorMin.y) - val2.anchoredPosition.y;
					rect = val2.rect;
					float num3 = num2 + ((Rect)(ref rect)).height * val2.pivot.y;
					rect = crafting.rect;
					float num4 = ((Rect)(ref rect)).width * val2.anchorMin.x + val2.anchoredPosition.x;
					rect = val2.rect;
					float num5 = num4 + ((Rect)(ref rect)).width * (1f - val2.pivot.x);
					menuRect.anchoredPosition = new Vector2(num5, 0f - (num3 + 6f));
				}
			}
		}

		private static void BuildMenu(InventoryGui gui)
		{
			//IL_0015: 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)
			//IL_002e: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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)
			RectTransform obj = Rect("SBQ_Menu", (Transform)(object)gui.m_crafting, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, Vector2.zero);
			obj.pivot = new Vector2(1f, 1f);
			obj.sizeDelta = new Vector2(224f, 100f);
			menu = ((Component)obj).gameObject;
			menuRect = obj;
			Image val = Box(obj, new Color(0.25f, 0.17f, 0.1f, 0.97f));
			if (skin)
			{
				val.sprite = panelSprite;
				val.type = panelType;
				((Graphic)val).color = panelColor;
				val.pixelsPerUnitMultiplier = panelPpu;
				if ((Object)(object)panelMaterial != (Object)null)
				{
					((Graphic)val).material = panelMaterial;
				}
			}
		}

		private static void BuildSearch(InventoryGui gui)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: 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_0450: 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_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_052f: 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_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Expected O, but got Unknown
			RectTransform crafting = gui.m_crafting;
			Button tabUpgrade = gui.m_tabUpgrade;
			if ((Object)(object)tabUpgrade == (Object)null)
			{
				return;
			}
			RectTransform val = (RectTransform)((Component)tabUpgrade).transform;
			Vector3 val2 = ((Transform)crafting).InverseTransformPoint(((Transform)val).position);
			Rect rect = crafting.rect;
			float width = ((Rect)(ref rect)).width;
			rect = crafting.rect;
			float height = ((Rect)(ref rect)).height;
			float num = val2.x + width * crafting.pivot.x;
			float num2 = val2.y - height * (1f - crafting.pivot.y);
			rect = val.rect;
			float height2 = ((Rect)(ref rect)).height;
			rect = val.rect;
			float num3 = num + ((Rect)(ref rect)).width * (1f - val.pivot.x) + 8f;
			float num4 = 80f;
			float num5 = num3 + num4 + 4f;
			float num6 = width - 10f;
			if (num6 - num5 < 80f)
			{
				return;
			}
			GameObject obj = CloneButton(tabUpgrade, (Transform)(object)crafting, "SBQ_SearchButton");
			RectTransform val3 = (RectTransform)obj.transform;
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(0f, 1f);
			val3.anchorMax = val4;
			val3.anchorMin = val4;
			val3.pivot = new Vector2(0f, 0.5f);
			val3.anchoredPosition = new Vector2(num3, num2);
			val3.sizeDelta = new Vector2(num4, height2);
			obj.SetActive(true);
			searchButton = obj;
			Transform val5 = obj.transform.Find("Text");
			if ((Object)(object)val5 != (Object)null)
			{
				((Component)val5).gameObject.SetActive(true);
				TMP_Text component = ((Component)val5).GetComponent<TMP_Text>();
				if ((Object)(object)component != (Object)null)
				{
					component.text = "SEARCH";
				}
			}
			Button component2 = obj.GetComponent<Button>();
			if ((Object)(object)component2 != (Object)null)
			{
				ButtonClickedEvent onClick = component2.onClick;
				object obj2 = <>c.<>9__64_0;
				if (obj2 == null)
				{
					UnityAction val6 = delegate
					{
						ClickSound();
						if ((Object)(object)input != (Object)null)
						{
							input.ActivateInputField();
							((Selectable)input).Select();
						}
					};
					<>c.<>9__64_0 = val6;
					obj2 = (object)val6;
				}
				((UnityEvent)onClick).AddListener((UnityAction)obj2);
			}
			GameObject val7 = new GameObject("SBQ_Search", new Type[1] { typeof(RectTransform) });
			val7.layer = LayerMask.NameToLayer("UI");
			val7.SetActive(false);
			RectTransform component3 = val7.GetComponent<RectTransform>();
			((Transform)component3).SetParent((Transform)(object)crafting, false);
			((Vector2)(ref val4))..ctor(0f, 1f);
			component3.anchorMax = val4;
			component3.anchorMin = val4;
			component3.pivot = new Vector2(0f, 0.5f);
			component3.anchoredPosition = new Vector2(num5, num2);
			component3.sizeDelta = new Vector2(num6 - num5, height2);
			Image val8 = val7.AddComponent<Image>();
			((Graphic)val8).color = new Color(0f, 0f, 0f, 0.55f);
			Outline obj3 = val7.AddComponent<Outline>();
			((Shadow)obj3).effectColor = new Color(1f, 0.63f, 0.235f, 0.6f);
			((Shadow)obj3).effectDistance = new Vector2(1f, -1f);
			RectTransform val9 = Fill("viewport", (Transform)(object)component3, 8f, 2f, 28f, 2f);
			((Component)val9).gameObject.AddComponent<RectMask2D>();
			TMP_Text val10 = Label(Fill("text", (Transform)(object)val9, 0f, 0f, 0f, 0f), "", 18f, Beige, (TextAlignmentOptions)513);
			val10.overflowMode = (TextOverflowModes)0;
			TMP_Text val11 = Label(Fill("hint", (Transform)(object)val9, 0f, 0f, 0f, 0f), "type what you look for", 18f, Grey, (TextAlignmentOptions)513);
			val11.fontStyle = (FontStyles)2;
			val11.overflowMode = (TextOverflowModes)0;
			TMP_InputField field = val7.AddComponent<TMP_InputField>();
			field.textViewport = val9;
			field.textComponent = val10;
			field.placeholder = (Graphic)(object)val11;
			((Selectable)field).targetGraphic = (Graphic)(object)val8;
			field.lineType = (LineType)0;
			field.characterLimit = 24;
			field.richText = false;
			field.customCaretColor = true;
			field.caretColor = Beige;
			field.selectionColor = new Color(1f, 0.63f, 0.235f, 0.4f);
			field.onFocusSelectAll = false;
			field.restoreOriginalTextOnEscape = false;
			((UnityEvent<string>)(object)field.onValueChanged).AddListener((UnityAction<string>)OnSearchChanged);
			val7.AddComponent<TypingWatch>().Field = field;
			Image obj4 = Box(Top("clear", (Transform)(object)component3, 0f, 0f, 0f, 0f), Color.clear);
			RectTransform rectTransform = ((Graphic)obj4).rectTransform;
			rectTransform.anchorMin = new Vector2(1f, 0.5f);
			rectTransform.anchorMax = new Vector2(1f, 0.5f);
			rectTransform.offsetMin = new Vector2(-24f, -10f);
			rectTransform.offsetMax = new Vector2(-4f, 10f);
			((Graphic)obj4).color = ChipOff;
			Click(obj4, delegate
			{
				field.text = "";
			});
			Label(Fill("text", (Transform)(object)rectTransform, 0f, 0f, 0f, 0f), "x", 16f, Beige, (TextAlignmentOptions)514);
			((Component)obj4).gameObject.SetActive(false);
			clearX = ((Component)obj4).gameObject;
			input = field;
			searchBox = val7;
			val7.SetActive(true);
		}

		private static void OnSearchChanged(string text)
		{
			Filter.Search = text ?? "";
			if ((Object)(object)clearX != (Object)null)
			{
				clearX.SetActive(Filter.Search.Length > 0);
			}
			Rebuild();
		}

		internal static void Close()
		{
			open = false;
			if ((Object)(object)menu != (Object)null)
			{
				menu.SetActive(false);
			}
			if ((Object)(object)glow != (Object)null)
			{
				glow.SetActive(false);
			}
			if (Filter.Search.Length > 0)
			{
				Filter.Search = "";
				if ((Object)(object)input != (Object)null)
				{
					input.SetTextWithoutNotify("");
				}
				if ((Object)(object)clearX != (Object)null)
				{
					clearX.SetActive(false);
				}
			}
		}

		private static void Toggle()
		{
			open = !open;
			if ((Object)(object)menu != (Object)null)
			{
				menu.SetActive(open);
			}
			if ((Object)(object)glow != (Object)null)
			{
				glow.SetActive(open);
			}
		}

		internal static void Rebuild()
		{
			if ((Object)(object)builtFor != (Object)null && UpdatePanel != null)
			{
				UpdatePanel.Invoke(builtFor, new object[1] { false });
			}
		}

		private static void ResetAll()
		{
			Filter.Reset();
			if ((Object)(object)input != (Object)null)
			{
				input.SetTextWithoutNotify("");
			}
			if ((Object)(object)clearX != (Object)null)
			{
				clearX.SetActive(false);
			}
			Rebuild();
		}

		private static void ClickGroup(Rank.Group g, bool split)
		{
			if (Filter.Group == g && Filter.Kind < 0)
			{
				Filter.Group = Rank.Group.None;
				if (Filter.Expanded == g.ToString())
				{
					Filter.Expanded = "";
				}
			}
			else
			{
				Filter.Group = g;
				Filter.Kind = -1;
				Filter.Expanded = (split ? g.ToString() : "");
			}
			Rebuild();
		}

		private static void ClickKind(Rank.Group g, int kind)
		{
			if (Filter.Group == g && Filter.Kind == kind)
			{
				Filter.Kind = -1;
			}
			else
			{
				Filter.Group = g;
				Filter.Kind = kind;
			}
			Rebuild();
		}

		private static void ClickMaterial(string key)
		{
			Filter.Material = ((Filter.Material == key) ? null : key);
			Rebuild();
		}

		internal static void Sync(Filter.View v, Model m, List<Mat> materials)
		{
			if (failed || (Object)(object)menuRect == (Object)null)
			{
				return;
			}
			view = v;
			model = m;
			mats = materials;
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(v.Food).Append('|').Append((int)v.Group)
				.Append('|')
				.Append(v.Kind)
				.Append('|')
				.Append(v.Material)
				.Append('|')
				.Append(v.FoodMode)
				.Append('|')
				.Append(Filter.Expanded);
			for (int i = 1; i <= 6; i++)
			{
				stringBuilder.Append('|').Append(m.Total[i]);
				int[] array = m.Kinds[i];
				foreach (int value in array)
				{
					stringBuilder.Append(',').Append(value);
				}
			}
			foreach (Mat material in materials)
			{
				stringBuilder.Append('|').Append(material.Key).Append(':')
					.Append(material.Count);
			}
			if (!(stringBuilder.ToString() == signature))
			{
				signature = stringBuilder.ToString();
				RebuildMenu();
			}
		}

		private static Color LookColor(Look look)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return (Color)(look switch
			{
				Look.Danger => Red, 
				Look.Current => Green, 
				_ => Orange, 
			});
		}

		private static Button SkinButton(string name, Transform parent, float x0, float yTop, float x1, float yBottom, Look look, Action click)
		{
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: 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_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: 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_0331: Expected O, but got Unknown
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			Button val3;
			if ((Object)(object)craftTemplate != (Object)null)
			{
				GameObject val2 = Object.Instantiate<GameObject>(((Component)craftTemplate).gameObject, parent, false);
				((Object)val2).name = name;
				val2.SetActive(true);
				ColorBlock colors = ((Selectable)craftTemplate).colors;
				Transition transition = ((Selectable)craftTemplate).transition;
				SpriteState spriteState = ((Selectable)craftTemplate).spriteState;
				foreach (MonoBehaviour item in val2.GetComponentsInChildren<MonoBehaviour>(true).ToList())
				{
					if ((Object)(object)item != (Object)null && !Keep((Component)(object)item))
					{
						Object.DestroyImmediate((Object)(object)item);
					}
				}
				foreach (Selectable item2 in val2.GetComponentsInChildren<Selectable>(true).ToList())
				{
					if ((Object)(object)item2 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)item2);
					}
				}
				Image component = val2.GetComponent<Image>();
				val3 = val2.AddComponent<Button>();
				((Selectable)val3).targetGraphic = (Graphic)(object)component;
				((Selectable)val3).transition = transition;
				((Selectable)val3).colors = colors;
				((Selectable)val3).spriteState = spriteState;
				TMP_Text[] componentsInChildren = val2.GetComponentsInChildren<TMP_Text>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Component)componentsInChildren[i]).gameObject.SetActive(false);
				}
				RectTransform val4 = (RectTransform)val2.transform;
				Vector2 anchorMin = (val4.anchorMax = val);
				val4.anchorMin = anchorMin;
				val4.offsetMin = new Vector2(x0, 0f - yBottom);
				val4.offsetMax = new Vector2(x1, 0f - yTop);
			}
			else
			{
				Image component = Box(Top(name, parent, x0, yTop, x1, yBottom), new Color(0.1f, 0.07f, 0.04f, 0.9f));
				val3 = ((Component)component).gameObject.AddComponent<Button>();
				((Selectable)val3).targetGraphic = (Graphic)(object)component;
			}
			Color val6 = LookColor(look);
			RectTransform val7 = Rect("edge", ((Component)val3).transform, Vector2.zero, Vector2.one, new Vector2(-1f, -1f), new Vector2(1f, 1f));
			Image val8 = ((Component)val7).gameObject.AddComponent<Image>();
			((Graphic)val8).raycastTarget = false;
			Sprite val9 = FindSprite("selection_frame");
			if ((Object)(object)val9 != (Object)null)
			{
				Vector4 border = val9.border;
				if (((Vector4)(ref border)).sqrMagnitude > 0f)
				{
					val8.sprite = val9;
					val8.type = (Type)1;
					((Graphic)val8).color = new Color(val6.r, val6.g, val6.b, 0.95f);
					goto IL_0313;
				}
			}
			((Graphic)val8).color = new Color(val6.r, val6.g, val6.b, 0f);
			Outline obj = ((Component)val7).gameObject.AddComponent<Outline>();
			((Shadow)obj).effectColor = new Color(val6.r, val6.g, val6.b, 0.9f);
			((Shadow)obj).effectDistance = new Vector2(2f, -2f);
			goto IL_0313;
			IL_0313:
			((Transform)val7).SetAsFirstSibling();
			((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
			{
				ClickSound();
				click();
			});
			return val3;
		}

		private static void Mark(Transform parent, float size, Vector2 anchor, Vector2 offset)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_007e: 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)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			Sprite val = FindSprite("checkbox");
			Sprite val2 = FindSprite("checkbox_marker");
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(size / 2f, size / 2f);
			Image val4 = Box(Rect("mark", parent, anchor, anchor, offset - val3, offset + val3), ((Object)(object)val != (Object)null) ? new Color(1f, 1f, 1f, 1f) : new Color(0f, 0f, 0f, 0.45f));
			((Graphic)val4).raycastTarget = false;
			if ((Object)(object)val != (Object)null)
			{
				val4.sprite = val;
			}
			Vector2 val5 = default(Vector2);
			((Vector2)(ref val5))..ctor(0.5f, 0.5f);
			float num = (((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null) ? size : (size * 0.7f));
			Image val6 = Box(Rect("fill", ((Component)val4).transform, val5, val5, new Vector2((0f - num) / 2f, (0f - num) / 2f), new Vector2(num / 2f, num / 2f)), Green);
			((Graphic)val6).raycastTarget = false;
			if ((Object)(object)val2 != (Object)null)
			{
				val6.sprite = val2;
			}
		}

		private static float Row(float y, string label, Look look, bool arrow, bool arrowOpen, Action click, bool marked = false)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			Button val = SkinButton("row", (Transform)(object)menuRect, 8f, y, 216f, y + 38f, look, click);
			Color color = LookColor(look);
			if (marked)
			{
				Mark(((Component)val).transform, 22f, new Vector2(0f, 0.5f), new Vector2(19f, 0f));
			}
			Label(Fill("text", ((Component)val).transform, marked ? 38f : 12f, 0f, arrow ? 32f : 8f, 0f), label, 22f, color, (TextAlignmentOptions)513);
			if (arrow)
			{
				Image val2 = Box(Rect("arrow", ((Component)val).transform, new Vector2(1f, 0.5f), new Vector2(1f, 0.5f), new Vector2(-30f, -9f), new Vector2(-12f, 9f)), color);
				val2.sprite = ArrowSprite();
				((Graphic)val2).raycastTarget = false;
				if (arrowOpen)
				{
					((Transform)((Graphic)val2).rectTransform).localRotation = Quaternion.Euler(0f, 0f, -90f);
				}
			}
			return y + 38f + 4f;
		}

		private static float KindGrid(float y, Rank.Group group, List<int> kinds, string[] labels)
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			float num = 20f;
			float num2 = (216f - num - 4f) / 2f;
			for (int i = 0; i < kinds.Count; i++)
			{
				int kind = kinds[i];
				int num3 = i % 2;
				int num4 = i / 2;
				float num5 = num + (float)num3 * (num2 + 4f);
				float num6 = y + (float)num4 * 34f;
				bool flag = view.Group == group && view.Kind == kind;
				Look look = (flag ? Look.Current : Look.Normal);
				Button val = SkinButton("kind", (Transform)(object)menuRect, num5, num6, num5 + num2, num6 + 30f, look, delegate
				{
					ClickKind(group, kind);
				});
				if (flag)
				{
					Mark(((Component)val).transform, 16f, new Vector2(0f, 0.5f), new Vector2(14f, 0f));
				}
				TMP_Text obj = Label(Fill("text", ((Component)val).transform, flag ? 26f : 5f, 0f, 5f, 0f), labels[kind], 20f, LookColor(look), (TextAlignmentOptions)514);
				obj.enableAutoSizing = true;
				obj.fontSizeMin = 13f;
				obj.fontSizeMax = 20f;
			}
			return y + (float)((kinds.Count + 1) / 2) * 34f + 2f;
		}

		private static float TileGrid(float y)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			float num = 11f;
			for (int i = 0; i < mats.Count; i++)
			{
				Mat mat = mats[i];
				int num2 = i % 4;
				int num3 = i / 4;
				float num4 = num + (float)num2 * 52f;
				float num5 = y + (float)num3 * 52f;
				bool flag = view.Material == mat.Key;
				Button val = SkinButton("tile", (Transform)(object)menuRect, num4, num5, num4 + 46f, num5 + 46f, flag ? Look.Current : Look.Normal, delegate
				{
					ClickMaterial(mat.Key);
				});
				Image obj = Box(Fill("icon", ((Component)val).transform, 6f, 6f, 6f, 6f), Color.white);
				obj.sprite = mat.Icon;
				obj.preserveAspect = true;
				((Graphic)obj).raycastTarget = false;
				if (flag)
				{
					Mark(((Component)val).transform, 18f, new Vector2(1f, 1f), new Vector2(-8f, -8f));
				}
				if ((Object)(object)tabTip != (Object)null && (Object)(object)tabTip.m_tooltipPrefab != (Object)null)
				{
					UITooltip obj2 = ((Component)val).gameObject.AddComponent<UITooltip>();
					obj2.m_tooltipPrefab = tabTip.m_tooltipPrefab;
					obj2.m_topic = mat.Display;
					obj2.m_text = "Used by " + mat.Count + ((mat.Count == 1) ? " recipe" : " recipes");
				}
			}
			int num6 = (mats.Count + 4 - 1) / 4;
			return y + (float)num6 * 52f + 2f;
		}

		private static void RebuildMenu()
		{
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			for (int num = ((Transform)menuRect).childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)((Transform)menuRect).GetChild(num)).gameObject);
			}
			float num2 = 8f;
			if (view.Food)
			{
				string[] array = new string[4] { "Stamina", "Health", "Eitr", "Biome" };
				for (int i = 1; i <= 4; i++)
				{
					int mode = i;
					bool flag = view.FoodMode == i;
					num2 = Row(num2, array[i - 1], flag ? Look.Current : Look.Normal, arrow: false, arrowOpen: false, delegate
					{
						Filter.FoodMode = ((Filter.FoodMode != mode) ? mode : 0);
						Rebuild();
					}, flag);
				}
			}
			else
			{
				for (int num3 = 1; num3 <= 6; num3++)
				{
					Rank.Group group = (Rank.Group)num3;
					if (model.Total[num3] == 0)
					{
						continue;
					}
					string[] array2 = Rank.KindLabels(group);
					List<int> list = new List<int>();
					if (array2 != null)
					{
						for (int num4 = 0; num4 < array2.Length && num4 < 16; num4++)
						{
							if (array2[num4] != null && model.Kinds[num3][num4] > 0)
							{
								list.Add(num4);
							}
						}
					}
					bool flag2 = list.Count >= 2;
					bool flag3 = view.Group == group;
					bool marked = flag3 && view.Kind < 0;
					bool flag4 = flag2 && Filter.Expanded == group.ToString();
					bool isSplit = flag2;
					num2 = Row(num2, Rank.GroupLabel(group), flag3 ? Look.Current : Look.Normal, flag2, flag4, delegate
					{
						ClickGroup(group, isSplit);
					}, marked);
					if (flag4)
					{
						num2 = KindGrid(num2, group, list, array2);
					}
				}
				if (mats.Count > 0)
				{
					bool flag5 = Filter.Expanded == "res";
					Mat mat = ((view.Material != null) ? mats.FirstOrDefault((Mat m) => m.Key == view.Material) : null);
					num2 = Row(num2, (mat != null) ? ("Resources: " + mat.Display) : "Resources", (mat != null) ? Look.Current : Look.Normal, arrow: true, flag5, delegate
					{
						Filter.Expanded = ((Filter.Expanded == "res") ? "" : "res");
						signature = "";
						Sync(view, model, mats);
					});
					if (flag5)
					{
						num2 = TileGrid(num2);
					}
				}
			}
			num2 = Row(num2 + 4f, "Reset", Look.Danger, arrow: false, arrowOpen: false, ResetAll);
			menuRect.sizeDelta = new Vector2(224f, num2 - 4f + 8f);
		}

		private static float Cover(float d)
		{
			return Mathf.Clamp01(0.5f - d);
		}

		private static float RoundBox(float px, float py, float cx, float cy, float hw, float hh, float r)
		{
			float num = Mathf.Abs(px - cx) - (hw - r);
			float num2 = Mathf.Abs(py - cy) - (hh - r);
			return Mathf.Sqrt(Mathf.Max(num, 0f) * Mathf.Max(num, 0f) + Mathf.Max(num2, 0f) * Mathf.Max(num2, 0f)) + Mathf.Min(Mathf.Max(num, num2), 0f) - r;
		}

		private static float Polygon(float px, float py, float[] cx, float[] cy)
		{
			float num = -1E+09f;
			for (int i = 0; i < cx.Length; i++)
			{
				int num2 = (i + 1) % cx.Length;
				float num3 = cx[num2] - cx[i];
				float num4 = cy[num2] - cy[i];
				float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4);
				num = Mathf.Max(num, (0f - (num3 * (py - cy[i]) - num4 * (px - cx[i]))) / num5);
			}
			return num;
		}

		private static Sprite SortSprite()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: 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_0201: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)sortIcon != (Object)null)
			{
				return sortIcon;
			}
			sortIcon = EmbeddedIcon();
			if ((Object)(object)sortIcon != (Object)null)
			{
				return sortIcon;
			}
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				hideFlags = (HideFlags)61
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.98f, 0.93f, 0.82f);
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = ((float)j + 0.5f) / 2f - 32f;
					float num2 = ((float)i + 0.5f) / 2f - 32f;
					float num3 = RoundBox(num, num2, -15.3f, 10.5f, 4.6f, 4.6f, 0.6f);
					float num4 = ((num3 < 0f && RoundBox(num, num2, -15.3f, 10.5f, 3f, 3f, 0.3f) >= 0f) ? 1f : 0f);
					num3 = Mathf.Min(num3, Diamond(num, num2, 0.4f, 10.5f, 5.9f));
					num3 = Mathf.Min(num3, Mathf.Sqrt((num - 16.3f) * (num - 16.3f) + (num2 - 10.5f) * (num2 - 10.5f)) - 4.5f);
					num3 = Mathf.Min(num3, RoundBox(num, num2, 0.4f, -2.35f, 21.8f, 1.75f, 0.8f));
					num3 = Mathf.Min(num3, Diamond(num, num2, 0.4f, -15.8f, 5.9f));
					val.SetPixel(j, i, new Color(Mathf.Lerp(val2.r, 1f, num4 * 0.8f), Mathf.Lerp(val2.g, 1f, num4 * 0.8f), Mathf.Lerp(val2.b, 0.95f, num4 * 0.8f), Cover(num3 * 2f)));
				}
			}
			val.Apply();
			sortIcon = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 100f);
			((Object)sortIcon).hideFlags = (HideFlags)61;
			return sortIcon;
		}

		private static Sprite EmbeddedIcon()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				using Stream stream = typeof(Drawer).Assembly.GetManifestResourceStream("sortbyqol.sort_icon.png");
				if (stream == null)
				{
					return null;
				}
				byte[] array = new byte[stream.Length];
				int num;
				for (int i = 0; i < array.Length; i += num)
				{
					num = stream.Read(array, i, array.Length - i);
					if (num <= 0)
					{
						break;
					}
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					filterMode = (FilterMode)1,
					hideFlags = (HideFlags)61
				};
				if (!ImageConversion.LoadImage(val, array))
				{
					return null;
				}
				Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)obj).hideFlags = (HideFlags)61;
				return obj;
			}
			catch (Exception ex)
			{
				SortByQoLPlugin.Log.LogWarning((object)("The built-in sort icon could not be read (" + ex.Message + "), the drawn one is used."));
				return null;
			}
		}

		private static float Diamond(float px, float py, float cx, float cy, float half)
		{
			return (Mathf.Abs(px - cx) + Mathf.Abs(py - cy) - half) * 0.7071f;
		}

		private static Sprite ArrowSprite()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_00c5: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)arrow != (Object)null)
			{
				return arrow;
			}
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				hideFlags = (HideFlags)61
			};
			float[] cx = new float[3] { 9f, 25f, 9f };
			float[] cy = new float[3] { 6f, 16f, 26f };
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					val.SetPixel(j, i, new Color(1f, 1f, 1f, Cover(Polygon((float)j + 0.5f, (float)i + 0.5f, cx, cy))));
				}
			}
			val.Apply();
			arrow = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f);
			((Object)arrow).hideFlags = (HideFlags)61;
			return arrow;
		}
	}
	public sealed class TabFollower : MonoBehaviour
	{
		private void LateUpdate()
		{
			Drawer.Place();
		}
	}
	public sealed class TypingWatch : MonoBehaviour
	{
		public TMP_InputField Field;

		private void Update()
		{
			if ((Object)(object)Field != (Object)null && Field.isFocused)
			{
				Drawer.MarkTyping();
			}
		}
	}
	internal static class Filter
	{
		internal sealed class View
		{
			public bool Food;

			public Rank.Group Group;

			public int Kind = -1;

			public string Material;

			public int FoodMode;

			public string[] Words = new string[0];

			public bool Filtering;

			public bool Sorting;
		}

		internal static Rank.Group Group = Rank.Group.None;

		internal static int Kind = -1;

		internal static string Material;

		internal static int FoodMode;

		internal static string Search = "";

		internal static string Expanded = "";

		internal static void Reset()
		{
			Group = Rank.Group.None;
			Kind = -1;
			Material = null;
			FoodMode = 0;
			Search = "";
			Expanded = "";
		}

		internal static View Begin(bool food, Model model)
		{
			View view = new View
			{
				Food = food
			};
			view.Words = (from w in (Search ?? "").Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				select w.ToLowerInvariant()).ToArray();
			if (food)
			{
				view.FoodMode = FoodMode;
			}
			else if (Group != Rank.Group.None && model.Total[(int)Group] > 0)
			{
				view.Group = Group;
				if (Kind >= 0 && Kind < 16 && model.Kinds[(int)Group][Kind] > 0)
				{
					view.Kind = Kind;
				}
			}
			return view;
		}

		internal static bool InScope(View v, Recipe r)
		{
			if (v.Food || v.Group == Rank.Group.None)
			{
				return true;
			}
			SharedData val = Rank.Shared(r);
			if (val == null || !Rank.InGroup(val, v.Group))
			{
				return false;
			}
			if (v.Kind >= 0)
			{
				return Rank.KindOf(val, v.Group) == v.Kind;
			}
			return true;
		}

		internal static void Finish(View v, List<Mat> mats)
		{
			if (v.Food)
			{
				v.Filtering = v.Words.Length != 0 || v.FoodMode == 3;
				v.Sorting = v.FoodMode != 0;
				return;
			}
			if (Material != null && mats.Any((Mat m) => m.Key == Material))
			{
				v.Material = Material;
			}
			v.Filtering = v.Words.Length != 0 || v.Group != Rank.Group.None || v.Material != null;
			v.Sorting = v.Group != Rank.Group.None;
		}

		internal static bool Pass(View v, Recipe r, CraftingStation station)
		{
			SharedData val = Rank.Shared(r);
			if (val == null)
			{
				return false;
			}
			if (v.Words.Length != 0)
			{
				string text = Rank.DisplayName(r).ToLowerInvariant();
				string[] words = v.Words;
				foreach (string value in words)
				{
					if (!text.Contains(value))
					{
						return false;
					}
				}
			}
			if (v.Food)
			{
				if (v.FoodMode == 3)
				{
					return val.m_foodEitr > 0f;
				}
				return true;
			}
			if (!InScope(v, r))
			{
				return false;
			}
			if (v.Material != null)
			{
				return Rank.Uses(r, v.Material, station);
			}
			return true;
		}
	}
	internal static class Pins
	{
		private const string DataKey = "SortByQoL.pins";

		private static HashSet<string> set = new HashSet<string>();

		private static Player loadedFor;

		private static Sprite sprite;

		private static readonly Color Pinned = new Color(1f, 0.63f, 0.235f, 1f);

		private static readonly Color Faint = new Color(1f, 1f, 1f, 0.5f);

		private static readonly Color Hover = new Color(1f, 1f, 1f, 0.6f);

		internal static bool Any
		{
			get
			{
				Load();
				return set.Count > 0;
			}
		}

		internal static string IdOf(Recipe r)
		{
			try
			{
				return ((Object)(object)r != (Object)null && (Object)(object)r.m_item != (Object)null) ? ((Object)((Component)r.m_item).gameObject).name : null;
			}
			catch
			{
				return null;
			}
		}

		private static void Load()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || localPlayer == loadedFor)
			{
				return;
			}
			loadedFor = localPlayer;
			set = new HashSet<string>();
			if (localPlayer.m_customData != null && localPlayer.m_customData.TryGetValue("SortByQoL.pins", out var value) && !string.IsNullOrEmpty(value))
			{
				string[] array = value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				foreach (string item in array)
				{
					set.Add(item);
				}
			}
		}

		internal static bool Has(Recipe r)
		{
			Load();
			string text = IdOf(r);
			if (text != null)
			{
				return set.Contains(text);
			}
			return false;
		}

		private static void Toggle(Recipe r)
		{
			Load();
			string text = IdOf(r);
			Player localPlayer = Player.m_localPlayer;
			if (text == null || (Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			if (!set.Remove(text))
			{
				set.Add(text);
			}
			if (localPlayer.m_customData != null)
			{
				localPlayer.m_customData["SortByQoL.pins"] = string.Join(",", set.OrderBy((string s) => s).ToArray());
			}
		}

		internal static void Decorate(Entry e)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00eb: 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_00fd: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Expected O, but got Unknown
			if (e == null || (Object)(object)e.Element == (Object)null || (Object)(object)e.Recipe == (Object)null)
			{
				return;
			}
			Transform val = e.Element.transform.Find("SBQ_Pin");
			if ((Object)(object)val != (Object)null)
			{
				Image component = ((Component)val).GetComponent<Image>();
				if ((Object)(object)component != (Object)null)
				{
					((Graphic)component).color = (Has(e.Recipe) ? Pinned : Faint);
				}
				return;
			}
			GameObject val2 = new GameObject("SBQ_Pin", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			val2.transform.SetParent(e.Element.transform, false);
			RectTransform val3 = (RectTransform)val2.transform;
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(1f, 0.5f);
			val3.anchorMax = val4;
			val3.anchorMin = val4;
			val3.pivot = new Vector2(1f, 0.5f);
			val3.sizeDelta = new Vector2(24f, 24f);
			Transform val5 = e.Element.transform.Find("QualityLevel");
			val3.anchoredPosition = new Vector2(((Object)(object)val5 != (Object)null && ((Component)val5).gameObject.activeSelf) ? (-34f) : (-8f), 0f);
			Image component2 = val2.GetComponent<Image>();
			component2.sprite = Sprite();
			((Graphic)component2).color = (Has(e.Recipe) ? Pinned : Faint);
			((Graphic)component2).raycastTarget = true;
			Button component3 = val2.GetComponent<Button>();
			((Selectable)component3).targetGraphic = (Graphic)(object)component2;
			((Selectable)component3).transition = (Transition)0;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)component3).navigation = navigation;
			Recipe recipe = e.Recipe;
			((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
			{
				Toggle(recipe);
				Drawer.Rebuild();
			});
		}

		private static Sprite Embedded()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_009c: 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)
			try
			{
				using Stream stream = typeof(Pins).Assembly.GetManifestResourceStream("sortbyqol.pin.png");
				if (stream == null)
				{
					return null;
				}
				byte[] array = new byte[stream.Length];
				int num;
				for (int i = 0; i < array.Length; i += num)
				{
					num = stream.Read(array, i, array.Length - i);
					if (num <= 0)
					{
						break;
					}
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
				{
					filterMode = (FilterMode)1,
					wrapMode = (TextureWrapMode)1,
					hideFlags = (HideFlags)61
				};
				if (!ImageConversion.LoadImage(val, array))
				{
					return null;
				}
				Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)obj).hideFlags = (HideFlags)61;
				return obj;
			}
			catch (Exception ex)
			{
				SortByQoLPlugin.Log.LogWarning((object)("The nail picture could not be read (" + ex.Message + "), a drawn pin is used."));
				return null;
			}
		}

		private static Sprite Sprite()
		{
			//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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)sprite != (Object)null)
			{
				return sprite;
			}
			sprite = Embedded();
			if ((Object)(object)sprite != (Object)null)
			{
				return sprite;
			}
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			Color32[] array = (Color32[])(object)new Color32[1024];
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = (float)j - 15.5f;
					float num2 = (float)i - 21f;
					bool num3 = num * num + num2 * num2 <= 67.24f;
					bool flag = !num3 && Math.Abs(num) <= 10.5f && i >= 11 && i <= 13;
					bool flag2 = Math.Abs(num) <= 2.6f && i >= 9 && i <= 13;
					bool flag3 = Math.Abs(num) <= 1.1f && i >= 2 && i < 9;
					bool flag4 = num3 && num * num + (num2 - 3f) * (num2 - 3f) < 10.240001f && num < 0f;
					byte b = (byte)(((num3 || flag || flag2 || flag3) && !flag4) ? byte.MaxValue : 0);
					array[i * 32 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, b);
				}
			}
			val.SetPixels32(array);
			val.Apply(false, true);
			sprite = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f);
			((Object)sprite).hideFlags = (HideFlags)61;
			return sprite;
		}
	}
	[BepInPlugin("p0kahontazz.sortbyqol", "SortByQoL", "1.0.1")]
	[BepInProcess("valheim.exe")]
	public sealed class SortByQoLPlugin : BaseUnityPlugin
	{
		public const string Id = "p0kahontazz.sortbyqol";

		public const string Version = "1.0.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> AutoRepair;

		internal static ConfigEntry<bool> HighestFirst;

		internal static ConfigEntry<bool> CraftableFirst;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			AutoRepair = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AutoRepair", true, "Opening a crafting station repairs every worn item in your inventory that this station can repair (the same rule as the Repair button, one go, nothing extra to pay).");
			HighestFirst = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HighestFirst", true, "Inside a group the strongest / highest tier is at the top. Off = weakest first.");
			CraftableFirst = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CraftableFirst", false, "Recipes you can craft right now come first, before the sort groups (the vanilla habit). Off = the sort groups come first.");
			harmony = new Harmony("p0kahontazz.sortbyqol");
			Type[] array = new Type[3]
			{
				typeof(ListPatch),
				typeof(ShowPatch),
				typeof(HidePatch)
			};
			foreach (Type type in array)
			{
				try
				{
					harmony.CreateClassProcessor(type).Patch();
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Patch " + type.Name + " failed: " + ex));
				}
			}
			HarmonyMethod block = new HarmonyMethod(typeof(TypingBlock), "Block", (Type[])null);
			string[] array2 = new string[3] { "GetButtonDown", "GetButtonUp", "GetButton" };
			foreach (string text in array2)
			{
				Block(AccessTools.Method(typeof(ZInput), text, new Type[1] { typeof(string) }, (Type[])null), block);
			}
			array2 = new string[3] { "GetKeyDown", "GetKeyUp", "GetKey" };
			foreach (string text2 in array2)
			{
				Block(AccessTools.Method(typeof(ZInput), text2, new Type[2]
				{
					typeof(KeyCode),
					typeof(bool)
				}, (Type[])null), block);
			}
			Log.LogInfo((object)"SortByQoL 1.0.1 loaded.");
		}

		private void Block(MethodInfo method, HarmonyMethod block)
		{
			try
			{
				if (method != null)
				{
					harmony.Patch((MethodBase)method, block, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				else
				{
					Log.LogWarning((object)"An input method of ZInput was not found, typing in the search field may reach the game.");
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Patching " + ((method != null) ? method.Name : "ZInput") + " failed: " + ex));
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	internal static class TypingBlock
	{
		internal static bool Block(ref bool __result)
		{
			if (!Drawer.Typing)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateRecipeList")]
	internal static class ListPatch
	{
		private static void Postfix(InventoryGui __instance)
		{
			try
			{
				RecipeList.Apply(__instance);
			}
			catch (Exception ex)
			{
				SortByQoLPlugin.Log.LogError((object)("Sorting the recipes failed: " + ex));
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Show")]
	internal static class ShowPatch
	{
		private static void Postfix(InventoryGui __instance)
		{
			try
			{
				Drawer.Ensure(__instance);
			}
			catch (Exception ex)
			{
				SortByQoLPlugin.Log.LogError((object)("Building the sort drawer failed: " + ex));
			}
			try
			{
				Repairs.Run(__instance);
			}
			catch (Exception ex2)
			{
				SortByQoLPlugin.Log.LogError((object)("Repairing at the station failed: " + ex2));
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Hide")]
	internal static class HidePatch
	{
		private static void Postfix()
		{
			Drawer.Close();
		}
	}
	internal sealed class Entry
	{
		public object Boxed;

		public Recipe Recipe;

		public GameObject Element;

		public bool Can;

		public float[] Key;

		public string Name;
	}
	internal sealed class Mat
	{
		public string Key;

		public string Display;

		public Sprite Icon;

		public int Count;
	}
	internal sealed class Model
	{
		public readonly int[] Total = new int[7];

		public readonly int[][] Kinds = new int[7][]
		{
			new int[16],
			new int[16],
			new int[16],
			new int[16],
			new int[16],
			new int[16],
			new int[16]
		};
	}
	internal static class Rank
	{
		internal enum Group
		{
			None,
			Armor,
			Weapon,
			Ammo,
			Tools,
			Components,
			Other
		}

		internal sealed class EntryComparer : IComparer<Entry>
		{
			public int Compare(Entry a, Entry b)
			{
				for (int i = 0; i < a.Key.Length; i++)
				{
					int num = a.Key[i].CompareTo(b.Key[i]);
					if (num != 0)
					{
						return num;
					}
				}
				return string.Compare(a.Name, b.Name, StringComparison.CurrentCultureIgnoreCase);
			}
		}

		private static readonly string[] ArmorLabels = new string[7] { "Helmets", "Chests", "Legs", "Gloves", "Capes", "Belts", "Trinkets" };

		private static readonly string[] WeaponLabels = new string[14]
		{
			"Swords", "Knives", "Spears", "Polearms", "Axes", "Clubs", "Fists", "Bows", "Crossbows", "Staffs",
			null, "Shields", null, "Other"
		};

		private static readonly string[] ToolLabels = new string[6] { "Pickaxes", "Axes", "Farming", "Fishing", "Light", "Other" };

		private static readonly string[] AmmoLabels = new string[4] { "Arrows", "Bolts", "Bombs", "Other" };

		private static readonly string[] TierLists = new string[8] { "Wood Stone Flint Resin LeatherScraps DeerHide Feathers BoneFragments Coal RoundLog HardAntler Dandelion Raspberry Honey Mushroom RawMeat CookedMeat NeckTail CookedDeerMeat DeerMeat BoarMeat Fish1 Fish2 FishRaw TrophyDeer TrophyBoar TrophyNeck TrophyGreydwarf", "FineWood Copper Tin Bronze TrollHide ElderBark Blueberries Carrot Thistle GreydwarfEye AncientSeed SurtlingCore ChickenEgg BjornHide BjornPaw CookedBjornMeat BjornMeat CuredSquirrelHamstring Ruby AmberPearl Guck Amber TrophyBjorn TrophyGreydwarfShaman TrophySkeleton TrophyTroll SpiceForests", "Iron Chain Root Entrails Bloodbag Ooze Turnip WitheredBone SerpentMeat SerpentMeatCooked SerpentScale Chitin GiantBloodSack FishCooked Fish3 Fish4_cave Fish5 Fish6 FreshSeaweed TrophyLeech TrophySurtling TrophyAbomination TrophySerpent TrophyDraugr SpiceOceans", "Silver WolfPelt WolfFang WolfMeat CookedWolfMeat WolfClaw WolfHairBundle DragonTear Obsidian Crystal FreezeGland Onion YmirRemains UndeadBjornRibcage Fish7 Fish8 TrophyWolf TrophyFenring TrophyHatchling TrophySGolem TrophyCultist TrophyDraugrElite SpiceMountains", "BlackMetal LinenThread Flax Barley BarleyFlour Cloudberry LoxMeat CookedLoxMeat LoxPelt Needle Tar Bread BreadDough LoxPie Fish9 Fish10 TrophyGoblin TrophyGoblinBrute TrophyLox SpicePlains", "Eitr Carapace YggdrasilWood Sap MushroomJotunPuffs MushroomMagecap Mandible BugMeat CookedBugMeat HareMeat MisthareSupreme RoyalJelly ScaleHide Wisp BlackMarble BlackCore CeramicPlate DvergrKeyFragment YggdrasilPorridge ChickenMeat Fish11 TrophySeeker TrophyGjall TrophyTick SpiceMistlands", "FlametalNew Vineberry Fiddleheadfern AsksvinMeat CookedAsksvinMeat VoltureMeat VoltureEgg MushroomSmokePuff AskHide AskBladder CharredBone Grausten MorgenSinew MorgenHeart SulfurStone Blackwood ProustitePowder GemstoneRed GemstoneBlue GemstoneGreen BonemawSerpentTooth FaderEmber MoltenCore ScorchingMedley CelestialFeather Voidplasm Ectoplasm TrophyMorgen TrophyCharredMelee TrophyFallenValkyrie SpiceAshlands", "Gold Frostwood MooseMeat CookedMooseMeat MooseHide MooseSinew ElakingHairBundle SealBlubber SealHide Oat OatFlour OatMilk Poteitr Kale Lingonberry Ice NornThread BarkaBranch MoleClaws CrownJewel Fish12 TrophyMoose TrophyFrostTroll SpiceDeepNorth" };

		private static readonly Dictionary<string, int> Tiers = BuildTiers();

		private static readonly Dictionary<Recipe, int> tierCache = new Dictionary<Recipe, int>();

		private static readonly string[] KeyResources = new string[28]
		{
			"Wood", "Flint", "Stone", "LeatherScraps", "DeerHide", "FineWood", "Tin", "Copper", "Bronze", "TrollHide",
			"ElderBark", "Iron", "Root", "Silver", "WolfPelt", "BlackMetal", "LinenThread", "LoxPelt", "Eitr", "Carapace",
			"YggdrasilWood", "FlametalNew", "AskHide", "CharredBone", "Blackwood", "Gold", "Frostwood", "MooseHide"
		};

		internal static string GroupLabel(Group g)
		{
			return g switch
			{
				Group.Armor => "Armor", 
				Group.Weapon => "Weapons", 
				Group.Ammo => "Ammunition", 
				Group.Tools => "Tools", 
				Group.Components => "Components", 
				Group.Other => "Other", 
				_ => "", 
			};
		}

		internal static string[] KindLabels(Group g)
		{
			return g switch
			{
				Group.Armor => ArmorLabels, 
				Group.Weapon => WeaponLabels, 
				Group.Ammo => AmmoLabels, 
				Group.Tools => ToolLabels, 
				_ => null, 
			};
		}

		private static bool WeaponType(SharedData sh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			ItemType itemType = sh.m_itemType;
			if ((int)itemType <= 14)
			{
				if (itemType - 3 <= 2 || (int)itemType == 14)
				{
					goto IL_0023;
				}
			}
			else if ((int)itemType == 20 || (int)itemType == 22)
			{
				goto IL_0023;
			}
			return false;
			IL_0023:
			return true;
		}

		private static bool AmmoType(SharedData sh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			if ((int)sh.m_itemType != 9)
			{
				return (int)sh.m_itemType == 23;
			}
			return true;
		}

		private static bool IsBomb(SharedData sh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			if ((int)sh.m_itemType == 3 || (int)sh.m_itemType == 14)
			{
				return (int)sh.m_skillType == 0;
			}
			return false;
		}

		private static bool ArmorType(SharedData sh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			ItemType itemType = sh.m_itemType;
			if ((int)itemType <= 12)
			{
				if (itemType - 6 <= 1 || itemType - 11 <= 1)
				{
					goto IL_0027;
				}
			}
			else if (itemType - 17 <= 1 || (int)itemType == 24)
			{
				goto IL_0027;
			}
			return false;
			IL_0027:
			return true;
		}

		private static bool ToolSkill(SkillType s)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			if ((int)s != 12 && (int)s != 13 && (int)s != 106)
			{
				return (int)s == 104;
			}
			return true;
		}

		private static bool ToolOnly(SharedData sh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			ItemType itemType = sh.m_itemType;
			if ((int)itemType == 19 || (int)itemType == 15)
			{
				return true;
			}
			if (WeaponType(sh) && (int)itemType != 5)
			{
				return ToolSkill(sh.m_skillType);
			}
			return false;
		}

		private static bool IsTool(SharedData sh)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			if (ToolOnly(sh))
			{
				return true;
			}
			ItemType itemType = sh.m_itemType;
			if ((int)itemType != 3 && (int)itemType != 14)
			{
				return false;
			}
			if (!(sh.m_damages.m_chop > 0f))
			{
				return sh.m_damages.m_pickaxe > 0f;
			}
			return true;
		}

		internal static bool InGroup(SharedData sh, Group g)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Invalid comparison between Unknown and I4
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Invalid comparison between Unknown and I4
			switch (g)
			{
			case Group.Armor:
				return ArmorType(sh);
			case Group.Weapon:
				if (WeaponType(sh) && !ToolOnly(sh))
				{
					return !IsBomb(sh);
				}
				return false;
			case Group.Ammo:
				if (!AmmoType(sh))
				{
					return IsBomb(sh);
				}
				return true;
			case Group.Tools:
				return IsTool(sh);
			case Group.Components:
				return (int)sh.m_itemType == 1;
			case Group.Other:
				if (!ArmorType(sh) && !WeaponType(sh) && !AmmoType(sh) && !IsTool(sh))
				{
					return (int)sh.m_itemType != 1;
				}
				return false;
			default:
				return true;
			}
		}

		private static int WeaponKind(SharedData sh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected I4, but got Unknown
			if ((int)sh.m_itemType == 5)
			{
				return 11;
			}
			SkillType skillType = sh.m_skillType;
			switch (skillType - 1)
			{
			case 0:
				return 0;
			case 1:
				return 1;
			case 4:
				return 2;
			case 3:
				return 3;
			case 6:
				return 4;
			case 2:
				return 5;
			case 10:
				return 6;
			case 7:
				return 7;
			case 13:
				return 8;
			case 8:
			case 9:
				return 9;
			default:
				return 13;
			}
		}

		private static int AmmoKind(SharedData sh)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			if (IsBomb(sh))
			{
				return 2;
			}
			if ((int)sh.m_skillType == 8)
			{
				return 0;
			}
			if ((int)sh.m_skillType == 14)
			{
				return 1;
			}
			return 3;
		}

		private static int ArmorKind(SharedData sh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected I4, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			ItemType itemType = sh.m_itemType;
			switch (itemType - 6)
			{
			default:
				if ((int)itemType != 17)
				{
					if ((int)itemType != 18)
					{
						break;
					}
					return 5;
				}
				return 4;
			case 0:
				return 0;
			case 1:
				return 1;
			case 5:
				return 2;
			case 6:
				return 3;
			case 2:
			case 3:
			case 4:
				break;
			}
			return 6;
		}

		private static int ToolKind(SharedData sh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_002a: 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_0041: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			DamageTypes damages = sh.m_damages;
			if ((int)sh.m_skillType == 12 || damages.m_pickaxe > 0f)
			{
				return 0;
			}
			if ((int)sh.m_skillType == 13 || damages.m_chop > 0f)
			{
				return 1;
			}
			if ((int)sh.m_skillType == 106)
			{
				return 2;
			}
			if ((int)sh.m_skillType == 104)
			{
				return 3;
			}
			if ((int)sh.m_itemType == 15)
			{
				return 4;
			}
			return 5;
		}

		internal static int KindOf(SharedData sh, Group g)
		{
			return g switch
			{
				Group.Armor => ArmorKind(sh), 
				Group.Weapon => WeaponKind(sh), 
				Group.Ammo => AmmoKind(sh), 
				Group.Tools => ToolKind(sh), 
				_ => -1, 
			};
		}

		private static float Strength(SharedData sh, Group g)
		{
			switch (g)
			{
			case Group.Armor:
				return sh.m_armor;
			case Group.Tools:
			{
				float num = sh.m_damages.m_chop + sh.m_damages.m_pickaxe;
				if (!(num > 0f))
				{
					return ((DamageTypes)(ref sh.m_damages)).GetTotalDamage();
				}
				return num;
			}
			case Group.Weapon:
			case Group.Ammo:
				return ((DamageTypes)(ref sh.m_damages)).GetTotalDamage();
			default:
				return 0f;
			}
		}

		internal static SharedData Shared(Recipe r)
		{
			if (!((Object)(object)r != (Object)null) || !((Object)(object)r.m_item != (Object)null))
			{
				return null;
			}
			return r.m_item.m_itemData.m_shared;
		}

		internal static Model Build(IEnumerable<Recipe> recipes)
		{
			Model model = new Model();
			foreach (Recipe recipe in recipes)
			{
				SharedData val = Shared(recipe);
				if (val == null)
				{
					continue;
				}
				for (int i = 1; i <= 6; i++)
				{
					if (InGroup(val, (Group)i))
					{
						model.Total[i]++;
						int num = KindOf(val, (Group)i);
						if (num >= 0 && num < 16)
						{
							model.Kinds[i][num]++;
						}
					}
				}
			}
			return model;
		}

		internal static bool IsFoodList(IEnumerable<Recipe> recipes)
		{
			int num = 0;
			int num2 = 0;
			foreach (Recipe recipe in recipes)
			{
				SharedData val = Shared(recipe);
				if (val != null)
				{
					num++;
					if (val.m_food > 0f || val.m_foodStamina > 0f || val.m_foodEitr > 0f)
					{
						num2++;
					}
				}
			}
			if (num > 0)
			{
				return num2 * 5 >= num * 2;
			}
			return false;
		}

		internal static float[] GroupKey(Recipe r, bool can, Group g)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			SharedData val = Shared(r);
			float num = (SortByQoLPlugin.HighestFirst.Value ? (-1f) : 1f);
			float num2 = ((SortByQoLPlugin.CraftableFirst.Value && !can) ? 1f : 0f);
			if (val != null)
			{
				float num3 = ((g == Group.Components || g == Group.Other) ? ((float)val.m_itemType) : ((float)KindOf(val, g)));
				return new float[6]
				{
					num2,
					num3,
					num * Strength(val, g),
					0f,
					0f,
					0f
				};
			}
			return new float[6] { num2, 99f, 0f, 0f, 0f, 0f };
		}

		internal static float[] FoodKey(Recipe r, bool can, int mode)
		{
			SharedData val = Shared(r);
			float num = (SortByQoLPlugin.HighestFirst.Value ? (-1f) : 1f);
			float num2 = ((SortByQoLPlugin.CraftableFirst.Value && !can) ? 1f : 0f);
			if (val != null)
			{
				float food = val.m_food;
				float foodStamina = val.m_foodStamina;
				float foodEitr = val.m_foodEitr;
				bool flag = food > 0f || foodStamina > 0f || foodEitr > 0f;
				float num3 = BiomeTier(r);
				float num4 = mode switch
				{
					3 => foodEitr, 
					2 => food, 
					1 => foodStamina, 
					_ => num3, 
				};
				return new float[6]
				{
					num2,
					flag ? 0f : 1f,
					num * num4,
					num * num3,
					num * (float)r.m_minStationLevel,
					num * (food + foodStamina + foodEitr)
				};
			}
			return new float[6] { num2, 1f, 0f, 0f, 0f, 0f };
		}

		internal static string DisplayName(Recipe r)
		{
			SharedData val = Shared(r);
			if (val != null)
			{
				return Localization.instance.Localize(val.m_name);
			}
			return "";
		}

		private static Dictionary<string, int> BuildTiers()
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
			for (int i = 0; i < TierLists.Length; i++)
			{
				string[] array = TierLists[i].Split(' ');
				foreach (string text in array)
				{
					if (text.Length > 0)
					{
						dictionary[text] = i;
					}
				}
			}
			return dictionary;
		}

		internal static int IngredientTier(string prefab)
		{
			if (prefab == null || !Tiers.TryGetValue(prefab, out var value))
			{
				return -1;
			}
			return value;
		}

		internal static int BiomeTier(Recipe r)
		{
			if (tierCache.TryGetValue(r, out var value))
			{
				return value;
			}
			value = -1;
			if (r.m_resources != null)
			{
				Requirement[] resources = r.m_resources;
				foreach (Requirement val in resources)
				{
					if (val != null && (Object)(object)val.m_resItem != (Object)null)
					{
						value = Math.Max(value, IngredientTier(((Object)val.m_resItem).name));
					}
				}
			}
			if (value < 0)
			{
				value = Mathf.Clamp(r.m_minStationLevel - 1, 0, 7);
			}
			tierCache[r] = value;
			return value;
		}

		private static bool Counts(Requirement req, CraftingStation station)
		{
			if (req == null || (Object)(object)req.m_resItem == (Object)null)
			{
				return false;
			}
			if (req.m_amount <= 0 && req.m_amountPerLevel <= 0)
			{
				return false;
			}
			if (!((Object)(object)station == (Object)null))
			{
				return station.m_upgrader == req.m_upgraderResource;
			}
			return !req.m_upgraderResource;
		}

		internal static bool Uses(Recipe r, string key, CraftingStation station)
		{
			if ((Object)(object)r == (Object)null || r.m_resources == null)
			{
				return false;
			}
			Requirement[] resources = r.m_resources;
			foreach (Requirement val in resources)
			{
				if (Counts(val, station) && val.m_resItem.m_itemData.m_shared.m_name == key)
				{
					return true;
				}
			}
			return false;
		}

		internal static List<Mat> Materials(IEnumerable<Recipe> recipes, CraftingStation station)
		{
			Dictionary<string, Mat> dictionary = new Dictionary<string, Mat>();
			Dictionary<string, int> order = new Dictionary<string, int>();
			foreach (Recipe recipe in recipes)
			{
				if ((Object)(object)recipe == (Object)null || recipe.m_resources == null)
				{
					continue;
				}
				HashSet<string> hashSet = new HashSet<string>();
				Requirement[] resources = recipe.m_resources;
				foreach (Requirement val in resources)
				{
					if (!Counts(val, station))
					{
						continue;
					}
					int num = Array.IndexOf(KeyResources, ((Object)val.m_resItem).name);
					if (num < 0)
					{
						continue;
					}
					SharedData shared = val.m_resItem.m_itemData.m_shared;
					if (!hashSet.Add(shared.m_name))
					{
						continue;
					}
					if (!dictionary.TryGetValue(shared.m_name, out var value))
					{
						Sprite icon = val.m_resItem.m_itemData.GetIcon();
						if ((Object)(object)icon == (Object)null)
						{
							continue;
						}
						value = new Mat
						{
							Key = shared.m_name,
							Display = Localization.instance.Localize(shared.m_name),
							Icon = icon
						};
						dictionary[shared.m_name] = value;
						order[shared.m_name] = num;
					}
					value.Count++;
				}
			}
			return dictionary.Values.OrderBy((Mat m) => order[m.Key]).ToList();
		}
	}
	internal static class RecipeList
	{
		private static readonly FieldInfo Available = AccessTools.Field(typeof(InventoryGui), "m_availableRecipes");

		private static readonly FieldInfo BaseSize = AccessTools.Field(typeof(InventoryGui), "m_recipeListBaseSize");

		private static PropertyInfo pRecipe;

		private static PropertyInfo pCan;

		private static PropertyInfo pElement;

		private static void Bind(IList list)
		{
			if (!(pRecipe != null) && list.Count != 0)
			{
				Type type = list[0]