Decompiled source of SearchEverything v1.0.0

plugins/SearchEverything.dll

Decompiled 18 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GUIFramework;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using ValheimMods.Shared;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SearchEverything")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Search crafting recipes and chests, and find items in nearby chests with a quick-search window that marks where they are.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SearchEverything")]
[assembly: AssemblyTitle("SearchEverything")]
[assembly: InternalsVisibleTo("ValheimMods.Tests")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 SearchEverything
{
	internal static class ChestSearch
	{
		private static GuiInputField s_field;

		private static string[] s_words = Array.Empty<string>();

		private static Container s_container;

		private static bool s_nameHidden;

		private static readonly HashSet<InventoryGrid> s_faded = new HashSet<InventoryGrid>();

		public static void Update(InventoryGui gui)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00dd: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Expected O, but got Unknown
			if (!Settings.ChestSearch.Value || !gui.IsContainerOpen())
			{
				if (Object.op_Implicit((Object)(object)s_field) && ((Component)s_field).gameObject.activeSelf)
				{
					Clear();
					((Component)s_field).gameObject.SetActive(false);
				}
				ShowName(gui, show: true);
				s_container = null;
				return;
			}
			if (!Object.op_Implicit((Object)(object)s_field))
			{
				s_field = SearchField.Create((Transform)(object)gui.m_container, "SearchEverything_ChestSearch", "");
				if (!Object.op_Implicit((Object)(object)s_field))
				{
					return;
				}
				SearchField.Place((RectTransform)((Component)s_field).transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 0.5f), new Vector2(0f, -19f), new Vector2(270f, 31f));
				SearchField.Fit(s_field, 18f);
				((UnityEvent<string>)(object)((TMP_InputField)s_field).onValueChanged).AddListener((UnityAction<string>)delegate(string query)
				{
					s_words = Matcher.Parse(query);
				});
				SearchField.LogLayout("Chest search box", (RectTransform)((Component)s_field).transform);
			}
			if (!((Component)s_field).gameObject.activeSelf)
			{
				((Component)s_field).gameObject.SetActive(true);
			}
			ShowName(gui, show: false);
			if ((Object)(object)gui.m_currentContainer != (Object)(object)s_container)
			{
				s_container = gui.m_currentContainer;
				Clear();
				string text = (Object.op_Implicit((Object)(object)s_container) ? Matcher.Localize(s_container.GetInventory().GetName()) : "");
				SearchField.SetPlaceholder(s_field, ("Search " + text).Trim());
			}
		}

		public static void Clear()
		{
			s_words = Array.Empty<string>();
			if (Object.op_Implicit((Object)(object)s_field) && ((TMP_InputField)s_field).text.Length > 0)
			{
				((TMP_InputField)s_field).SetTextWithoutNotify("");
			}
		}

		private static void ShowName(InventoryGui gui, bool show)
		{
			if (Object.op_Implicit((Object)(object)gui.m_containerName) && s_nameHidden != !show)
			{
				((Component)gui.m_containerName).gameObject.SetActive(show);
				s_nameHidden = !show;
			}
		}

		public static void Apply(InventoryGrid grid)
		{
			bool flag = s_words.Length != 0;
			if (!flag && !s_faded.Contains(grid))
			{
				return;
			}
			float value = Settings.DimOpacity.Value;
			foreach (InventoryElement element2 in grid.m_elements)
			{
				SetAlpha(element2, flag ? value : 1f);
			}
			if (flag)
			{
				foreach (ItemData allItem in grid.m_inventory.GetAllItems())
				{
					if (Matcher.Matches(allItem, s_words))
					{
						InventoryElement element = grid.GetElement(allItem.m_gridPos.x, allItem.m_gridPos.y, grid.m_inventory.GetWidth());
						if (Object.op_Implicit((Object)(object)element))
						{
							SetAlpha(element, 1f);
						}
					}
				}
				s_faded.Add(grid);
			}
			else
			{
				s_faded.Remove(grid);
			}
		}

		private static void SetAlpha(InventoryElement element, float alpha)
		{
			CanvasGroup val = ((Component)element).GetComponent<CanvasGroup>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				if (alpha >= 1f)
				{
					return;
				}
				val = ((Component)element).gameObject.AddComponent<CanvasGroup>();
			}
			val.alpha = alpha;
		}
	}
	[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
	internal static class InventoryGridUpdateGuiPatch
	{
		private static void Postfix(InventoryGrid __instance)
		{
			InventoryGui instance = InventoryGui.instance;
			if (Object.op_Implicit((Object)(object)instance) && ((Object)(object)__instance == (Object)(object)instance.m_playerGrid || (Object)(object)__instance == (Object)(object)instance.m_containerGrid))
			{
				ChestSearch.Apply(__instance);
			}
		}

		private static Exception Finalizer(Exception __exception)
		{
			return PatchGuard.Contain(__exception, "the chest search");
		}
	}
	internal class Finder : MonoBehaviour
	{
		private sealed class Group
		{
			public string Key;

			public string Name;

			public Sprite Icon;

			public int Total;

			public int Rank;

			public readonly List<Entry> Chests = new List<Entry>();
		}

		private sealed class Entry
		{
			public Container Chest;

			public string Name;

			public int Count;

			public float Distance;

			public float Height;
		}

		private sealed class RowView
		{
			public RectTransform Rect;

			public Image Background;

			public GameObject Toggle;

			public TMP_Text ToggleText;

			public Image Icon;

			public TMP_Text Name;

			public TMP_Text Detail;
		}

		private const int VisibleRows = 10;

		private const float RowHeight = 36f;

		private const float PanelWidth = 640f;

		private const float RowsTop = 132f;

		private const float RescanSeconds = 1f;

		private GameObject m_root;

		private RectTransform m_panel;

		private GuiInputField m_field;

		private TMP_Text m_status;

		private TMP_Text m_empty;

		private TMP_Text m_footer;

		private readonly List<RowView> m_rows = new List<RowView>();

		private Canvas m_canvas;

		private string[] m_words = Array.Empty<string>();

		private readonly List<Group> m_groups = new List<Group>();

		private readonly List<(Group Group, Entry Entry)> m_flat = new List<(Group, Entry)>();

		private readonly HashSet<string> m_expanded = new HashSet<string>();

		private int m_selected;

		private int m_scroll;

		private float m_nextScan;

		private bool m_focusNextFrame;

		private FrameGuard m_guard;

		public static Finder Instance { get; private set; }

		public bool IsOpen
		{
			get
			{
				if (Object.op_Implicit((Object)(object)m_root))
				{
					return m_root.activeSelf;
				}
				return false;
			}
		}

		private void Awake()
		{
			Instance = this;
			m_guard = new FrameGuard((Behaviour)(object)this, "the nearby search");
		}

		public void Open()
		{
			if (Settings.Finder.Value && Object.op_Implicit((Object)(object)Player.m_localPlayer) && !IsOpen && (Object.op_Implicit((Object)(object)m_root) || Build()))
			{
				m_root.transform.SetAsLastSibling();
				m_root.SetActive(true);
				InputGuard.WindowOpen = true;
				((TMP_InputField)m_field).SetTextWithoutNotify("");
				m_words = Array.Empty<string>();
				m_expanded.Clear();
				m_selected = (m_scroll = 0);
				Rebuild();
				m_focusNextFrame = true;
			}
		}

		public void Close()
		{
			if (Object.op_Implicit((Object)(object)m_root))
			{
				m_root.SetActive(false);
			}
			InputGuard.WindowOpen = false;
			InputGuard.MarkActive();
			if (Object.op_Implicit((Object)(object)m_field))
			{
				((TMP_InputField)m_field).DeactivateInputField(false);
			}
		}

		private void Update()
		{
			try
			{
				Tick();
			}
			catch (Exception e)
			{
				m_guard.Report(e);
			}
		}

		private void OnDisable()
		{
			Close();
		}

		private void Tick()
		{
			if (!IsOpen)
			{
				InputGuard.WindowOpen = false;
				if (Settings.Finder.Value && Object.op_Implicit((Object)(object)Player.m_localPlayer) && CanOpenNow() && Hotkeys.Pressed(Settings.FinderKey))
				{
					Open();
				}
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).IsDead() || !Settings.Finder.Value || Menu.IsVisible())
			{
				Close();
				return;
			}
			if (SearchKeys.Down((KeyCode)27))
			{
				Close();
				return;
			}
			if (m_focusNextFrame)
			{
				m_focusNextFrame = false;
				m_field.ActivateInputField();
			}
			if (SearchKeys.Down((KeyCode)274))
			{
				MoveSelection(1);
			}
			if (SearchKeys.Down((KeyCode)273))
			{
				MoveSelection(-1);
			}
			if (SearchKeys.Down((KeyCode)281))
			{
				MoveSelection(10);
			}
			if (SearchKeys.Down((KeyCode)280))
			{
				MoveSelection(-10);
			}
			if (SearchKeys.Down((KeyCode)275))
			{
				SetExpanded(m_selected, expanded: true);
			}
			if (SearchKeys.Down((KeyCode)276))
			{
				SetExpanded(m_selected, expanded: false);
			}
			if (SearchKeys.Down((KeyCode)13) || SearchKeys.Down((KeyCode)271))
			{
				if (m_flat.Count > 0)
				{
					Pick(m_selected);
					return;
				}
				m_focusNextFrame = true;
			}
			float mouseScrollWheel = ZInput.GetMouseScrollWheel();
			if (mouseScrollWheel != 0f && IsPointerOver(m_panel))
			{
				Scroll((mouseScrollWheel > 0f) ? (-3) : 3);
			}
			if (Time.time >= m_nextScan)
			{
				Rebuild();
			}
			Render();
		}

		private void OnDestroy()
		{
			InputGuard.WindowOpen = false;
			if (Object.op_Implicit((Object)(object)m_root))
			{
				Object.Destroy((Object)(object)m_root);
			}
		}

		private static bool CanOpenNow()
		{
			if (!SearchKeys.IsTyping() && !Minimap.IsOpen() && !StoreGui.IsVisible() && !Hud.InRadial() && !Hud.IsPieceSelectionVisible())
			{
				return !GameCamera.InFreeFly();
			}
			return false;
		}

		private void Rebuild()
		{
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			m_nextScan = Time.time + 1f;
			(string Key, bool IsChest, Container Chest) selectedKey = SelectedKey();
			NearbyChests.Scan();
			Dictionary<string, Group> dictionary = new Dictionary<string, Group>();
			foreach (var item3 in NearbyChests.Found)
			{
				Container item = item3.Chest;
				float item2 = item3.Distance;
				Dictionary<string, Entry> dictionary2 = new Dictionary<string, Entry>();
				foreach (ItemData allItem in item.GetInventory().GetAllItems())
				{
					if (Matcher.Matches(allItem, m_words))
					{
						string name = allItem.m_shared.m_name;
						if (!dictionary.TryGetValue(name, out var value))
						{
							string text = Matcher.Localize(name);
							value = (dictionary[name] = new Group
							{
								Key = name,
								Name = text,
								Icon = allItem.GetIcon(),
								Rank = Matcher.NameRank(text, m_words)
							});
						}
						value.Total += allItem.m_stack;
						if (!dictionary2.TryGetValue(name, out var value2))
						{
							value2 = (dictionary2[name] = new Entry
							{
								Chest = item,
								Name = Matcher.Localize(item.GetInventory().GetName()),
								Distance = item2,
								Height = ((Component)item).transform.position.y - NearbyChests.Origin.y
							});
							value.Chests.Add(value2);
						}
						value2.Count += allItem.m_stack;
					}
				}
			}
			m_groups.Clear();
			m_groups.AddRange(dictionary.Values.OrderBy((Group g) => g.Rank).ThenBy<Group, string>((Group g) => g.Name, StringComparer.CurrentCultureIgnoreCase));
			m_flat.Clear();
			foreach (Group group in m_groups)
			{
				m_flat.Add((group, null));
				if (!m_expanded.Contains(group.Key))
				{
					continue;
				}
				foreach (Entry chest in group.Chests)
				{
					m_flat.Add((group, chest));
				}
			}
			int num = m_flat.FindIndex(((Group Group, Entry Entry) row) => row.Group.Key == selectedKey.Key && row.Entry != null == selectedKey.IsChest && (!selectedKey.IsChest || (Object)(object)row.Entry.Chest == (Object)(object)selectedKey.Chest));
			m_selected = ((num >= 0) ? num : Mathf.Clamp(m_selected, 0, Mathf.Max(0, m_flat.Count - 1)));
			KeepSelectionVisible();
		}

		private (string, bool, Container) SelectedKey()
		{
			if (m_selected < 0 || m_selected >= m_flat.Count)
			{
				return (null, false, null);
			}
			var (obj, entry) = m_flat[m_selected];
			return (obj.Key, entry != null, entry?.Chest);
		}

		private void OnQueryChanged(string text)
		{
			m_words = Matcher.Parse(text);
			m_selected = (m_scroll = 0);
			Rebuild();
			m_selected = (m_scroll = 0);
		}

		private void MoveSelection(int delta)
		{
			if (m_flat.Count != 0)
			{
				m_selected = Mathf.Clamp(m_selected + delta, 0, m_flat.Count - 1);
				KeepSelectionVisible();
			}
		}

		private void Scroll(int delta)
		{
			m_scroll = Mathf.Clamp(m_scroll + delta, 0, Mathf.Max(0, m_flat.Count - 10));
			m_selected = Mathf.Clamp(m_selected, m_scroll, Mathf.Min(m_flat.Count - 1, m_scroll + 10 - 1));
		}

		private void KeepSelectionVisible()
		{
			if (m_selected < m_scroll)
			{
				m_scroll = m_selected;
			}
			if (m_selected >= m_scroll + 10)
			{
				m_scroll = m_selected - 10 + 1;
			}
			m_scroll = Mathf.Clamp(m_scroll, 0, Mathf.Max(0, m_flat.Count - 10));
		}

		private void SetExpanded(int index, bool expanded)
		{
			if (index < 0 || index >= m_flat.Count)
			{
				return;
			}
			Group group = m_flat[index].Group;
			if (expanded != m_expanded.Contains(group.Key))
			{
				if (expanded)
				{
					m_expanded.Add(group.Key);
				}
				else
				{
					m_expanded.Remove(group.Key);
				}
				m_selected = m_flat.FindIndex(((Group Group, Entry Entry) row) => row.Group == group && row.Entry == null);
				Rebuild();
			}
		}

		private void Pick(int index)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			if (index >= 0 && index < m_flat.Count)
			{
				(Group Group, Entry Entry) tuple = m_flat[index];
				Group item = tuple.Group;
				Entry item2 = tuple.Entry;
				List<Container> list = ((item2 != null) ? new List<Container> { item2.Chest } : item.Chests.Select((Entry e) => e.Chest).ToList());
				Markers.Mark(list, item.Icon);
				Close();
				string text = ((list.Count == 1) ? "1 chest" : $"{list.Count} chests");
				KeyboardShortcut value = Settings.DismissKey.Value;
				string text2 = (((int)((KeyboardShortcut)(ref value)).MainKey != 0) ? $" ({Settings.DismissKey.Value} clears)" : "");
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					((Character)Player.m_localPlayer).Message((MessageType)1, item.Name + ": marked " + text + text2, 0, (Sprite)null, false);
				}
			}
		}

		private void Render()
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: 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_019e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < m_rows.Count; i++)
			{
				RowView rowView = m_rows[i];
				int num = m_scroll + i;
				bool flag = num < m_flat.Count;
				if (((Component)rowView.Rect).gameObject.activeSelf != flag)
				{
					((Component)rowView.Rect).gameObject.SetActive(flag);
				}
				if (flag)
				{
					(Group Group, Entry Entry) tuple = m_flat[num];
					Group item = tuple.Group;
					Entry item2 = tuple.Entry;
					bool flag2 = IsPointerOver(rowView.Rect);
					((Graphic)rowView.Background).color = ((num == m_selected) ? new Color(1f, 0.63f, 0.24f, 0.28f) : (flag2 ? new Color(1f, 1f, 1f, 0.07f) : new Color(0f, 0f, 0f, 0f)));
					if (item2 == null)
					{
						bool active = item.Chests.Count > 0;
						rowView.Toggle.SetActive(active);
						rowView.ToggleText.text = (m_expanded.Contains(item.Key) ? "-" : "+");
						((Behaviour)rowView.Icon).enabled = Object.op_Implicit((Object)(object)item.Icon);
						rowView.Icon.sprite = item.Icon;
						rowView.Name.rectTransform.offsetMin = new Vector2(78f, 0f);
						rowView.Name.text = item.Name;
						((Graphic)rowView.Name).color = Ui.TextColor;
						string arg = ((item.Chests.Count == 1) ? "1 chest" : $"{item.Chests.Count} chests");
						rowView.Detail.text = $"×{item.Total}  ·  {arg}  ·  {item.Chests[0].Distance:0} m";
					}
					else
					{
						rowView.Toggle.SetActive(false);
						((Behaviour)rowView.Icon).enabled = false;
						rowView.Name.rectTransform.offsetMin = new Vector2(96f, 0f);
						rowView.Name.text = item2.Name;
						((Graphic)rowView.Name).color = Ui.DimTextColor;
						rowView.Detail.text = $"×{item2.Count}  ·  {item2.Distance:0} m{Height(item2.Height)}";
					}
				}
			}
			int count = NearbyChests.Found.Count;
			string text = ((count == 1) ? $"1 chest within {Settings.Range.Value} m" : $"{count} chests within {Settings.Range.Value} m");
			if (NearbyChests.LoadedRadius > 0f && (float)Settings.Range.Value > NearbyChests.LoadedRadius)
			{
				text += $"  ·  chests more than ~{NearbyChests.LoadedRadius:0} m from you may not be loaded";
			}
			m_status.text = text;
			((Component)m_empty).gameObject.SetActive(m_flat.Count == 0);
			if (m_flat.Count == 0)
			{
				m_empty.text = ((count == 0) ? "No chests you can open nearby" : ((m_words.Length != 0) ? "Nothing in nearby chests matches" : "Nearby chests are empty"));
			}
			m_footer.text = ((m_flat.Count > 10) ? $"{m_scroll + 1}-{Mathf.Min(m_flat.Count, m_scroll + 10)} of {m_flat.Count}     Up/Down choose   Right/Left show chests   Enter mark   Esc close" : "Up/Down choose   Right/Left show chests   Enter mark   Esc close");
		}

		private static string Height(float height)
		{
			if (height > 2.5f)
			{
				return $"  ·  {height:0} m up";
			}
			if (height < -2.5f)
			{
				return $"  ·  {0f - height:0} m down";
			}
			return "";
		}

		private bool IsPointerOver(RectTransform rect)
		{
			//IL_001d: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)rect) || !Object.op_Implicit((Object)(object)m_canvas))
			{
				return false;
			}
			Camera val = (((int)m_canvas.renderMode == 0) ? null : m_canvas.worldCamera);
			return RectTransformUtility.RectangleContainsScreenPoint(rect, Vector2.op_Implicit(ZInput.pointerPosition), val);
		}

		private bool Build()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Expected O, but got Unknown
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)Hud.instance) || !Object.op_Implicit((Object)(object)InventoryGui.instance))
			{
				return false;
			}
			Canvas componentInParent = ((Component)Hud.instance).GetComponentInParent<Canvas>();
			Canvas val = (Object.op_Implicit((Object)(object)componentInParent) ? componentInParent.rootCanvas : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			m_root = new GameObject("SearchEverything_Finder", new Type[1] { typeof(RectTransform) });
			m_root.transform.SetParent(((Component)val).transform, false);
			Ui.Stretch((RectTransform)m_root.transform, 0f);
			m_canvas = m_root.AddComponent<Canvas>();
			m_canvas.overrideSorting = true;
			int num = 0;
			Canvas[] componentsInChildren = ((Component)val).GetComponentsInChildren<Canvas>(true);
			foreach (Canvas val2 in componentsInChildren)
			{
				if ((Object)(object)val2 != (Object)(object)m_canvas)
				{
					num = Mathf.Max(num, val2.sortingOrder);
				}
			}
			m_canvas.sortingOrder = num + 1;
			m_root.AddComponent<GraphicRaycaster>();
			Image obj = Ui.AddImage(m_root.transform, "Backdrop", null, new Color(0f, 0f, 0f, 0.35f));
			Ui.Stretch(((Graphic)obj).rectTransform, 0f);
			((Graphic)obj).raycastTarget = true;
			((UnityEvent)((Component)obj).gameObject.AddComponent<Button>().onClick).AddListener(new UnityAction(Close));
			float num2 = 538f;
			Image val3 = Ui.AddImage(m_root.transform, "Panel", null, Color.white);
			Ui.CopyPanelLook(val3);
			((Graphic)val3).raycastTarget = true;
			m_panel = ((Graphic)val3).rectTransform;
			RectTransform panel = m_panel;
			RectTransform panel2 = m_panel;
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(0.5f, 0.5f);
			panel2.anchorMax = val4;
			panel.anchorMin = val4;
			m_panel.pivot = new Vector2(0.5f, 0.5f);
			m_panel.anchoredPosition = new Vector2(0f, 30f);
			m_panel.sizeDelta = new Vector2(640f, num2);
			TMP_Text obj2 = Ui.AddText((Transform)(object)m_panel, "Title", 26f, TitleColor(), (TextAlignmentOptions)514);
			PlaceTop(obj2.rectTransform, 12f, 34f, 20f);
			obj2.text = "Find in nearby chests";
			m_field = SearchField.Create((Transform)(object)m_panel, "SearchEverything_FinderSearch", "Item name or type (bow, food...)");
			if (!Object.op_Implicit((Object)(object)m_field))
			{
				Object.Destroy((Object)(object)m_root);
				return false;
			}
			PlaceTop((RectTransform)((Component)m_field).transform, 52f, 38f, 28f);
			((UnityEvent<string>)(object)((TMP_InputField)m_field).onValueChanged).AddListener((UnityAction<string>)OnQueryChanged);
			m_status = Ui.AddText((Transform)(object)m_panel, "Status", 16f, Ui.DimTextColor, (TextAlignmentOptions)513);
			PlaceTop(m_status.rectTransform, 98f, 24f, 28f);
			for (int j = 0; j < 10; j++)
			{
				m_rows.Add(BuildRow(j));
			}
			m_empty = Ui.AddText((Transform)(object)m_panel, "Empty", 20f, Ui.DimTextColor, (TextAlignmentOptions)514);
			PlaceTop(m_empty.rectTransform, 204f, 30f, 20f);
			m_footer = Ui.AddText((Transform)(object)m_panel, "Footer", 15f, Ui.DimTextColor, (TextAlignmentOptions)514);
			m_footer.rectTransform.anchorMin = new Vector2(0f, 0f);
			m_footer.rectTransform.anchorMax = new Vector2(1f, 0f);
			m_footer.rectTransform.pivot = new Vector2(0.5f, 0f);
			m_footer.rectTransform.anchoredPosition = new Vector2(0f, 14f);
			m_footer.rectTransform.sizeDelta = new Vector2(-40f, 22f);
			m_root.SetActive(false);
			SearchField.LogLayout("Nearby search box", (RectTransform)((Component)m_field).transform);
			return true;
		}

		private RowView BuildRow(int i)
		{
			//IL_003e: 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)
			//IL_00b0: 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
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			RowView rowView = new RowView();
			Image val = Ui.AddImage((Transform)(object)m_panel, $"Row{i}", null, new Color(0f, 0f, 0f, 0f));
			((Graphic)val).raycastTarget = true;
			rowView.Background = val;
			rowView.Rect = ((Graphic)val).rectTransform;
			PlaceTop(rowView.Rect, 132f + (float)i * 36f, 34f, 16f);
			int row = i;
			Button obj = ((Component)val).gameObject.AddComponent<Button>();
			((Selectable)obj).transition = (Transition)0;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj).navigation = navigation;
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				Pick(m_scroll + row);
			});
			Image val2 = Ui.AddImage((Transform)(object)rowView.Rect, "Toggle", Ui.SlotSprite(), new Color(1f, 1f, 1f, 0.5f));
			((Graphic)val2).raycastTarget = true;
			RectTransform rectTransform = ((Graphic)val2).rectTransform;
			RectTransform rectTransform2 = ((Graphic)val2).rectTransform;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 0.5f);
			rectTransform2.anchorMax = val3;
			rectTransform.anchorMin = val3;
			((Graphic)val2).rectTransform.pivot = new Vector2(0f, 0.5f);
			((Graphic)val2).rectTransform.anchoredPosition = new Vector2(6f, 0f);
			((Graphic)val2).rectTransform.sizeDelta = new Vector2(24f, 24f);
			Button obj2 = ((Component)val2).gameObject.AddComponent<Button>();
			navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj2).navigation = navigation;
			((UnityEvent)obj2.onClick).AddListener((UnityAction)delegate
			{
				int num = m_scroll + row;
				if (num < m_flat.Count)
				{
					SetExpanded(num, !m_expanded.Contains(m_flat[num].Group.Key));
				}
				m_focusNextFrame = true;
			});
			rowView.Toggle = ((Component)val2).gameObject;
			rowView.ToggleText = Ui.AddText(((Component)val2).transform, "Text", 20f, Ui.TextColor, (TextAlignmentOptions)514);
			Ui.Stretch(rowView.ToggleText.rectTransform, 0f);
			rowView.Icon = Ui.AddImage((Transform)(object)rowView.Rect, "Icon", null, Color.white);
			rowView.Icon.preserveAspect = true;
			RectTransform rectTransform3 = ((Graphic)rowView.Icon).rectTransform;
			RectTransform rectTransform4 = ((Graphic)rowView.Icon).rectTransform;
			((Vector2)(ref val3))..ctor(0f, 0.5f);
			rectTransform4.anchorMax = val3;
			rectTransform3.anchorMin = val3;
			((Graphic)rowView.Icon).rectTransform.pivot = new Vector2(0f, 0.5f);
			((Graphic)rowView.Icon).rectTransform.anchoredPosition = new Vector2(38f, 0f);
			((Graphic)rowView.Icon).rectTransform.sizeDelta = new Vector2(32f, 32f);
			rowView.Name = Ui.AddText((Transform)(object)rowView.Rect, "Name", 19f, Ui.TextColor, (TextAlignmentOptions)513);
			rowView.Name.rectTransform.anchorMin = new Vector2(0f, 0f);
			rowView.Name.rectTransform.anchorMax = new Vector2(0.55f, 1f);
			rowView.Name.rectTransform.offsetMin = new Vector2(78f, 0f);
			rowView.Name.rectTransform.offsetMax = Vector2.zero;
			rowView.Detail = Ui.AddText((Transform)(object)rowView.Rect, "Detail", 17f, Ui.DimTextColor, (TextAlignmentOptions)516);
			rowView.Detail.rectTransform.anchorMin = new Vector2(0.55f, 0f);
			rowView.Detail.rectTransform.anchorMax = new Vector2(1f, 1f);
			rowView.Detail.rectTransform.offsetMin = new Vector2(8f, 0f);
			rowView.Detail.rectTransform.offsetMax = new Vector2(-10f, 0f);
			return rowView;
		}

		private static void PlaceTop(RectTransform rect, float top, float height, float sideMargin)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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)
			rect.anchorMin = new Vector2(0f, 1f);
			rect.anchorMax = new Vector2(1f, 1f);
			rect.pivot = new Vector2(0.5f, 1f);
			rect.anchoredPosition = new Vector2(0f, 0f - top);
			rect.sizeDelta = new Vector2(-2f * sideMargin, height);
		}

		private static Color TitleColor()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			InventoryGui instance = InventoryGui.instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.m_containerName))
			{
				return new Color(1f, 0.76f, 0.4f);
			}
			return ((Graphic)instance.m_containerName).color;
		}
	}
	internal static class InputGuard
	{
		private static readonly List<GuiInputField> s_fields = new List<GuiInputField>();

		private static int s_lastActiveFrame = -10;

		public static bool WindowOpen;

		public static bool Active
		{
			get
			{
				if (IsActiveNow())
				{
					s_lastActiveFrame = Time.frameCount;
				}
				return Time.frameCount - s_lastActiveFrame <= 1;
			}
		}

		public static void Register(GuiInputField field)
		{
			s_fields.Add(field);
		}

		public static void MarkActive()
		{
			s_lastActiveFrame = Time.frameCount;
		}

		private static bool IsActiveNow()
		{
			if (WindowOpen)
			{
				return true;
			}
			for (int num = s_fields.Count - 1; num >= 0; num--)
			{
				GuiInputField val = s_fields[num];
				if (!Object.op_Implicit((Object)(object)val))
				{
					s_fields.RemoveAt(num);
				}
				else if (((TMP_InputField)val).isFocused)
				{
					return true;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(TextInput), "IsVisible")]
	internal static class TextInputIsVisiblePatch
	{
		private static void Postfix(ref bool __result)
		{
			__result = __result || InputGuard.Active;
		}

		private static Exception Finalizer(Exception __exception)
		{
			return PatchGuard.Contain(__exception, "search box typing");
		}
	}
	[HarmonyPatch(typeof(Player), "TakeInput")]
	internal static class PlayerTakeInputPatch
	{
		private static void Postfix(ref bool __result)
		{
			__result = __result && !InputGuard.Active && !SearchKeys.OurKeyPressed();
		}

		private static Exception Finalizer(Exception __exception)
		{
			return PatchGuard.Contain(__exception, "search box typing");
		}
	}
	[HarmonyPatch(typeof(PlayerController), "TakeInput")]
	internal static class PlayerControllerTakeInputPatch
	{
		private static void Postfix(ref bool __result)
		{
			__result = __result && !InputGuard.Active;
		}

		private static Exception Finalizer(Exception __exception)
		{
			return PatchGuard.Contain(__exception, "search box typing");
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	internal static class UpdateMouseCapturePatch
	{
		private static void Postfix()
		{
			if (InputGuard.WindowOpen)
			{
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
			}
		}

		private static Exception Finalizer(Exception __exception)
		{
			return PatchGuard.Contain(__exception, "the nearby search");
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
	internal static class UpdateCameraZoomPatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo wheel = AccessTools.Method(typeof(ZInput), "GetMouseScrollWheel", (Type[])null, (Type[])null);
			MethodInfo replacement = AccessTools.Method(typeof(UpdateCameraZoomPatch), "ScrollWheel", (Type[])null, (Type[])null);
			int replaced = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, wheel))
				{
					replaced++;
					yield return new CodeInstruction(OpCodes.Call, (object)replacement)
					{
						labels = instruction.labels,
						blocks = instruction.blocks
					};
				}
				else
				{
					yield return instruction;
				}
			}
			SafePatching.ExpectReplaced(replaced, 2, "GameCamera.UpdateCamera mouse wheel reads");
		}

		private static float ScrollWheel()
		{
			if (!InputGuard.WindowOpen)
			{
				return ZInput.GetMouseScrollWheel();
			}
			return 0f;
		}
	}
	[HarmonyPatch(typeof(Menu), "Update")]
	internal static class MenuUpdatePatch
	{
		private static bool Prefix()
		{
			if (!Menu.IsVisible())
			{
				return !InputGuard.Active;
			}
			return true;
		}

		private static Exception Finalizer(Exception __exception)
		{
			return PatchGuard.Contain(__exception, "search box typing");
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Update")]
	internal static class InventoryGuiUpdatePatch
	{
		internal static bool BlockHide;

		private static void Prefix()
		{
			Player localPlayer = Player.m_localPlayer;
			if (InputGuard.Active && Object.op_Implicit((Object)(object)localPlayer) && !((Character)localPlayer).IsDead())
			{
				ZInput.ResetButtonStatus("Inventory");
				ZInput.ResetButtonStatus("Use");
				ZInput.ResetButtonStatus("JoyButtonB");
				ZInput.ResetButtonStatus("JoyButtonY");
				BlockHide = SearchKeys.Down((KeyCode)27);
			}
		}

		private static Exception Finalizer(Exception __exception)
		{
			BlockHide = false;
			return PatchGuard.Contain(__exception, "search box typing");
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Hide")]
	internal static class InventoryGuiHidePatch
	{
		private static bool Prefix()
		{
			return !InventoryGuiUpdatePatch.BlockHide;
		}

		private static void Postfix()
		{
			if (!InventoryGuiUpdatePatch.BlockHide)
			{
				RecipeSearch.Clear();
				ChestSearch.Clear();
			}
		}

		private static Exception Finalizer(Exception __exception)
		{
			return PatchGuard.Contain(__exception, "the search boxes");
		}
	}
	internal static class InventoryButton
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__2_0;

			internal void <Create>b__2_0()
			{
				if (Object.op_Implicit((Object)(object)Finder.Instance))
				{
					Finder.Instance.Open();
				}
			}
		}

		private static Button s_button;

		public static void Update(InventoryGui gui)
		{
			if (!Settings.Finder.Value || !Settings.InventoryButton.Value)
			{
				if (Object.op_Implicit((Object)(object)s_button) && ((Component)s_button).gameObject.activeSelf)
				{
					((Component)s_button).gameObject.SetActive(false);
				}
				return;
			}
			if (!Object.op_Implicit((Object)(object)s_button))
			{
				s_button = Create(gui);
			}
			if (Object.op_Implicit((Object)(object)s_button) && !((Component)s_button).gameObject.activeSelf)
			{
				((Component)s_button).gameObject.SetActive(true);
			}
		}

		private static Button Create(InventoryGui gui)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			//IL_0119: 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_00ff: 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_010a: Expected O, but got Unknown
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Expected O, but got Unknown
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)gui.m_takeAllButton))
			{
				return null;
			}
			GameObject val = Object.Instantiate<GameObject>(((Component)gui.m_takeAllButton).gameObject, (Transform)(object)gui.m_player, false);
			((Object)val).name = "SearchEverything_FinderButton";
			UIGamePad[] componentsInChildren = val.GetComponentsInChildren<UIGamePad>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			foreach (Transform item in val.transform)
			{
				Transform val2 = item;
				if (((Object)val2).name.StartsWith("gamepad_hint", StringComparison.Ordinal))
				{
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
			}
			Localize[] componentsInChildren2 = val.GetComponentsInChildren<Localize>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			Button component = val.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = component.onClick;
			object obj = <>c.<>9__2_0;
			if (obj == null)
			{
				UnityAction val3 = delegate
				{
					if (Object.op_Implicit((Object)(object)Finder.Instance))
					{
						Finder.Instance.Open();
					}
				};
				<>c.<>9__2_0 = val3;
				obj = (object)val3;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			((Selectable)component).interactable = true;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)component).navigation = navigation;
			TMP_Text text = val.GetComponentInChildren<TMP_Text>(true);
			if (Object.op_Implicit((Object)(object)text))
			{
				text.text = $"Search chests ({Settings.FinderKey.Value})";
				text.enableAutoSizing = true;
				text.fontSizeMin = 10f;
				text.fontSizeMax = text.fontSize;
			}
			SearchField.Place((RectTransform)val.transform, new Vector2(1f, 1f), new Vector2(1f, 0f), new Vector2(0f, 4f), new Vector2(190f, 32f));
			SearchField.LogLayout("Nearby search button", (RectTransform)val.transform);
			Settings.FinderKey.SettingChanged += delegate
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)text))
				{
					text.text = $"Search chests ({Settings.FinderKey.Value})";
				}
			};
			return component;
		}
	}
	internal class Markers : MonoBehaviour
	{
		private sealed class Marker
		{
			public Container Chest;

			public float Until;

			public RectTransform Rect;

			public TMP_Text Text;
		}

		private static readonly List<Marker> s_markers = new List<Marker>();

		private static RectTransform s_layer;

		private static Canvas s_canvas;

		private FrameGuard m_guard;

		public static int Count => s_markers.Count;

		public static void Mark(IEnumerable<Container> chests, Sprite icon)
		{
			Clear();
			if (!EnsureLayer())
			{
				return;
			}
			float until = ((Settings.MarkerSeconds.Value > 0) ? (Time.time + (float)Settings.MarkerSeconds.Value) : float.MaxValue);
			foreach (Container chest in chests)
			{
				if (Object.op_Implicit((Object)(object)chest))
				{
					s_markers.Add(Create(chest, icon, until));
				}
			}
		}

		public static void Clear()
		{
			foreach (Marker s_marker in s_markers)
			{
				if (Object.op_Implicit((Object)(object)s_marker.Rect))
				{
					Object.Destroy((Object)(object)((Component)s_marker.Rect).gameObject);
				}
			}
			s_markers.Clear();
		}

		private void Awake()
		{
			m_guard = new FrameGuard((Behaviour)(object)this, "the chest markers");
		}

		private void Update()
		{
			try
			{
				Tick();
			}
			catch (Exception e)
			{
				m_guard.Report(e);
			}
		}

		private void LateUpdate()
		{
			try
			{
				Position();
			}
			catch (Exception e)
			{
				m_guard.Report(e);
			}
		}

		private void OnDisable()
		{
			Clear();
		}

		private static void Tick()
		{
			if (s_markers.Count == 0)
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)s_layer))
			{
				Clear();
				return;
			}
			if (Hotkeys.Pressed(Settings.DismissKey) && !SearchKeys.IsTyping())
			{
				Clear();
				((Character)Player.m_localPlayer).Message((MessageType)1, "Chest markers cleared", 0, (Sprite)null, false);
				return;
			}
			Container val = (Object.op_Implicit((Object)(object)InventoryGui.instance) ? InventoryGui.instance.m_currentContainer : null);
			for (int num = s_markers.Count - 1; num >= 0; num--)
			{
				Marker marker = s_markers[num];
				if (!Object.op_Implicit((Object)(object)marker.Chest) || !((Object)(object)marker.Chest != (Object)(object)val) || !(Time.time < marker.Until) || !Object.op_Implicit((Object)(object)marker.Rect))
				{
					if (Object.op_Implicit((Object)(object)marker.Rect))
					{
						Object.Destroy((Object)(object)((Component)marker.Rect).gameObject);
					}
					s_markers.RemoveAt(num);
				}
			}
		}

		private static void Position()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00c5: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			if (s_markers.Count == 0)
			{
				return;
			}
			Camera mainCamera = Utils.GetMainCamera();
			if (!Object.op_Implicit((Object)(object)mainCamera) || !Object.op_Implicit((Object)(object)s_canvas))
			{
				return;
			}
			Camera val = (((int)s_canvas.renderMode == 0) ? null : s_canvas.worldCamera);
			float num = 1f + 0.06f * Mathf.Sin(Time.time * 4f);
			foreach (Marker s_marker in s_markers)
			{
				Vector3 val2 = ((Component)s_marker.Chest).transform.position + Vector3.up * 1.4f;
				Vector3 val3 = mainCamera.WorldToScreenPoint(val2);
				Vector2 zero = Vector2.zero;
				bool flag = val3.z > 0f && RectTransformUtility.ScreenPointToLocalPointInRectangle(s_layer, Vector2.op_Implicit(val3), val, ref zero);
				if (((Component)s_marker.Rect).gameObject.activeSelf != flag)
				{
					((Component)s_marker.Rect).gameObject.SetActive(flag);
				}
				if (flag)
				{
					s_marker.Rect.anchoredPosition = zero;
					((Transform)s_marker.Rect).localScale = Vector3.one * num;
					s_marker.Text.text = $"{Vector3.Distance(((Component)mainCamera).transform.position, ((Component)s_marker.Chest).transform.position):0} m";
				}
			}
		}

		private void OnDestroy()
		{
			Clear();
		}

		private static bool EnsureLayer()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0075: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)s_layer))
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)Hud.instance) || !Object.op_Implicit((Object)(object)Hud.instance.m_rootObject))
			{
				return false;
			}
			GameObject val = new GameObject("SearchEverything_Markers", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(Hud.instance.m_rootObject.transform, false);
			s_layer = (RectTransform)val.transform;
			s_layer.anchorMin = Vector2.zero;
			s_layer.anchorMax = Vector2.one;
			RectTransform obj = s_layer;
			Vector2 offsetMin = (s_layer.offsetMax = Vector2.zero);
			obj.offsetMin = offsetMin;
			Canvas componentInParent = val.GetComponentInParent<Canvas>();
			s_canvas = (Object.op_Implicit((Object)(object)componentInParent) ? componentInParent.rootCanvas : null);
			return true;
		}

		private static Marker Create(Container chest, Sprite icon, float until)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Marker", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent((Transform)(object)s_layer, false);
			RectTransform val2 = (RectTransform)val.transform;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			val2.anchorMax = val3;
			val2.anchorMin = val3;
			val2.sizeDelta = new Vector2(48f, 48f);
			Ui.Stretch(((Graphic)Ui.AddImage(val.transform, "Frame", Ui.SlotSprite(), new Color(0f, 0f, 0f, 0.6f))).rectTransform, 0f);
			if (Object.op_Implicit((Object)(object)icon))
			{
				Image obj = Ui.AddImage(val.transform, "Icon", icon, Color.white);
				Ui.Stretch(((Graphic)obj).rectTransform, 6f);
				obj.preserveAspect = true;
			}
			Image val4 = Ui.AddImage(val.transform, "DistancePlate", null, new Color(0f, 0f, 0f, 0.6f));
			RectTransform rectTransform = ((Graphic)val4).rectTransform;
			RectTransform rectTransform2 = ((Graphic)val4).rectTransform;
			((Vector2)(ref val3))..ctor(0.5f, 0f);
			rectTransform2.anchorMax = val3;
			rectTransform.anchorMin = val3;
			((Graphic)val4).rectTransform.pivot = new Vector2(0.5f, 1f);
			((Graphic)val4).rectTransform.anchoredPosition = new Vector2(0f, -2f);
			((Graphic)val4).rectTransform.sizeDelta = new Vector2(64f, 22f);
			TMP_Text val5 = Ui.AddText(((Component)val4).transform, "Distance", 17f, Color.white, (TextAlignmentOptions)514);
			Ui.Stretch(val5.rectTransform, 0f);
			return new Marker
			{
				Chest = chest,
				Until = until,
				Rect = val2,
				Text = val5
			};
		}
	}
	internal static class Matcher
	{
		private static readonly Dictionary<SharedData, string> s_itemText = new Dictionary<SharedData, string>();

		private static readonly Dictionary<Recipe, string> s_recipeText = new Dictionary<Recipe, string>();

		private static string s_language;

		public static string[] Parse(string query)
		{
			if (!string.IsNullOrWhiteSpace(query))
			{
				return query.ToLowerInvariant().Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
			}
			return Array.Empty<string>();
		}

		public static bool Matches(ItemData item, string[] words)
		{
			if (words.Length != 0 && item?.m_shared != null)
			{
				return ContainsAll(ItemText(item.m_shared), words);
			}
			return true;
		}

		public static bool Matches(Recipe recipe, string[] words)
		{
			if (words.Length != 0 && Object.op_Implicit((Object)(object)recipe))
			{
				return ContainsAll(RecipeText(recipe), words);
			}
			return true;
		}

		public static int NameRank(string localizedName, string[] words)
		{
			if (words.Length == 0)
			{
				return 0;
			}
			string text = localizedName.ToLowerInvariant();
			if (text.StartsWith(words[0], StringComparison.Ordinal))
			{
				return 0;
			}
			if (!text.Contains(words[0]))
			{
				return 2;
			}
			return 1;
		}

		public static string Localize(string token)
		{
			if (Localization.instance == null)
			{
				return token;
			}
			return Localization.instance.Localize(token);
		}

		internal static bool ContainsAll(string text, string[] words)
		{
			foreach (string value in words)
			{
				if (text.IndexOf(value, StringComparison.Ordinal) < 0)
				{
					return false;
				}
			}
			return true;
		}

		private static void CheckLanguage()
		{
			string text = ((Localization.instance != null) ? Localization.instance.GetSelectedLanguage() : "");
			if (!(text == s_language))
			{
				s_language = text;
				s_itemText.Clear();
				s_recipeText.Clear();
			}
		}

		private static string ItemText(SharedData shared)
		{
			CheckLanguage();
			if (s_itemText.TryGetValue(shared, out var value))
			{
				return value;
			}
			value = BuildItemText(shared, Localize);
			s_itemText[shared] = value;
			return value;
		}

		internal static string BuildItemText(SharedData shared, Func<string, string> localize)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(localize(shared.m_name)).Append('\n');
			AppendTypeWords(stringBuilder, shared, localize);
			return stringBuilder.ToString().ToLowerInvariant();
		}

		private static string RecipeText(Recipe recipe)
		{
			CheckLanguage();
			if (s_recipeText.TryGetValue(recipe, out var value))
			{
				return value;
			}
			StringBuilder stringBuilder = new StringBuilder();
			if (Object.op_Implicit((Object)(object)recipe.m_item))
			{
				stringBuilder.Append(ItemText(recipe.m_item.m_itemData.m_shared));
			}
			Requirement[] resources = recipe.m_resources;
			foreach (Requirement val in resources)
			{
				if (Object.op_Implicit((Object)(object)val.m_resItem))
				{
					stringBuilder.Append(Localize(val.m_resItem.m_itemData.m_shared.m_name).ToLowerInvariant()).Append('\n');
				}
			}
			value = stringBuilder.ToString();
			s_recipeText[recipe] = value;
			return value;
		}

		private static void AppendTypeWords(StringBuilder builder, SharedData shared, Func<string, string> localize)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0077: Expected I4, but got Unknown
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Invalid comparison between Unknown and I4
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Invalid comparison between Unknown and I4
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Invalid comparison between Unknown and I4
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: 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_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Expected I4, but got Unknown
			ItemType itemType = shared.m_itemType;
			switch (itemType - 1)
			{
			case 0:
				Add("material");
				break;
			case 1:
				Add((shared.m_food > 0f || shared.m_foodStamina > 0f || shared.m_foodEitr > 0f) ? "food" : "potion mead consumable");
				break;
			case 2:
			case 3:
			case 13:
			case 19:
			case 21:
				Add("weapon");
				break;
			case 4:
				Add("shield");
				break;
			case 5:
				Add("helmet head armor armour");
				break;
			case 6:
				Add("chest body armor armour");
				break;
			case 10:
				Add("legs armor armour");
				break;
			case 11:
				Add("hands gloves armor armour");
				break;
			case 16:
				Add("cape shoulder armor armour");
				break;
			case 17:
				Add("utility belt");
				break;
			case 23:
				Add("trinket");
				break;
			case 8:
			case 22:
				Add("ammo ammunition arrow bolt");
				break;
			case 14:
				Add("torch");
				break;
			case 18:
				Add("tool");
				break;
			case 12:
				Add("trophy");
				break;
			case 20:
				Add("fish");
				break;
			case 9:
				Add("customization");
				break;
			case 15:
				Add("misc");
				break;
			}
			if ((int)shared.m_itemType != 1 && (int)shared.m_itemType != 2 && (int)shared.m_skillType > 0)
			{
				Add(localize("$skill_" + ((object)Unsafe.As<SkillType, SkillType>(ref shared.m_skillType)/*cast due to .constrained prefix*/).ToString().ToLowerInvariant()));
				SkillType skillType = shared.m_skillType;
				switch (skillType - 1)
				{
				case 0:
					Add("sword");
					break;
				case 1:
					Add("knife dagger");
					break;
				case 2:
					Add("club mace");
					break;
				case 3:
					Add("polearm atgeir");
					break;
				case 4:
					Add("spear");
					break;
				case 6:
					Add("axe");
					break;
				case 7:
					Add("bow");
					break;
				case 13:
					Add("crossbow");
					break;
				case 8:
				case 9:
					Add("staff magic");
					break;
				case 11:
					Add("pickaxe");
					break;
				case 10:
					Add("fists unarmed");
					break;
				case 5:
				case 12:
					break;
				}
			}
			void Add(string words)
			{
				builder.Append(words).Append('\n');
			}
		}
	}
	internal static class NearbyChests
	{
		private static readonly List<Container> s_all = new List<Container>();

		private static readonly Dictionary<Container, bool> s_built = new Dictionary<Container, bool>();

		public static readonly List<(Container Chest, float Distance)> Found = new List<(Container, float)>();

		private static SimulationDistance s_radiusFor;

		private static float s_radius;

		public static Vector3 Origin { get; private set; }

		public static float LoadedRadius { get; private set; }

		public static void Register(Container container)
		{
			if (Object.op_Implicit((Object)(object)container) && container.GetInventory() != null)
			{
				s_all.Add(container);
			}
		}

		public static void Scan()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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)
			Found.Clear();
			Prune();
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || !Object.op_Implicit((Object)(object)ZNet.instance))
			{
				return;
			}
			LoadedRadius = GuaranteedLoadedRadius(ZNet.instance.GetSyncedSimulationDistance());
			Camera mainCamera = Utils.GetMainCamera();
			Origin = (Object.op_Implicit((Object)(object)mainCamera) ? ((Component)mainCamera).transform.position : ((Component)localPlayer).transform.position);
			float num = Settings.Range.Value;
			long playerID = localPlayer.GetPlayerID();
			foreach (Container item in s_all)
			{
				if (!((Behaviour)item).isActiveAndEnabled || !IsPlayerBuilt(item) || (!Settings.CartsAndShips.Value && (Object.op_Implicit((Object)(object)item.m_wagon) || Object.op_Implicit((Object)(object)((Component)item).GetComponentInParent<Ship>()))))
				{
					continue;
				}
				ZNetView nview = item.m_nview;
				if (Object.op_Implicit((Object)(object)nview) && nview.IsValid())
				{
					float num2 = Vector3.Distance(Origin, ((Component)item).transform.position);
					if (!(num2 > num) && item.CheckAccess(playerID) && (!item.m_checkGuardStone || PrivateArea.CheckAccess(((Component)item).transform.position, 0f, false, false)))
					{
						Found.Add((item, num2));
					}
				}
			}
			Found.Sort(((Container Chest, float Distance) a, (Container Chest, float Distance) b) => a.Distance.CompareTo(b.Distance));
		}

		private static void Prune()
		{
			if (s_all.RemoveAll((Container c) => !Object.op_Implicit((Object)(object)c)) == 0)
			{
				return;
			}
			List<Container> list = new List<Container>();
			foreach (Container key in s_built.Keys)
			{
				if (!Object.op_Implicit((Object)(object)key))
				{
					list.Add(key);
				}
			}
			foreach (Container item in list)
			{
				s_built.Remove(item);
			}
		}

		private static bool IsPlayerBuilt(Container chest)
		{
			if (s_built.TryGetValue(chest, out var value))
			{
				return value;
			}
			Piece componentInParent = ((Component)chest).GetComponentInParent<Piece>();
			value = !Object.op_Implicit((Object)(object)((Component)chest).GetComponentInParent<Player>()) && !Object.op_Implicit((Object)(object)((Component)chest).GetComponentInParent<TombStone>()) && Object.op_Implicit((Object)(object)componentInParent) && componentInParent.IsPlacedByPlayer();
			s_built[chest] = value;
			return value;
		}

		private static float GuaranteedLoadedRadius(SimulationDistance distance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (((SimulationDistance)(ref distance)).Equals(s_radiusFor) && s_radius > 0f)
			{
				return s_radius;
			}
			int num = Mathf.Max(0, ((SimulationDistance)(ref distance)).NearSimulationDistance);
			float num2 = 64f;
			float num3 = (float)(num + 1) * num2;
			for (int i = -(num + 1); i <= num + 1; i++)
			{
				for (int j = -(num + 1); j <= num + 1; j++)
				{
					bool num4 = Mathf.Abs(i) > num || Mathf.Abs(j) > num;
					int num5;
					if (!((SimulationDistance)(ref distance)).IsClassic)
					{
						Vector2 val = new Vector2((float)i, (float)j);
						num5 = ((((Vector2)(ref val)).magnitude * num2 >= ((float)num + 0.5f) * num2) ? 1 : 0);
					}
					else
					{
						num5 = 0;
					}
					bool flag = (byte)num5 != 0;
					if (num4 || flag)
					{
						float num6 = (float)Mathf.Max(0, Mathf.Abs(i) - 1) * num2;
						float num7 = (float)Mathf.Max(0, Mathf.Abs(j) - 1) * num2;
						num3 = Mathf.Min(num3, Mathf.Sqrt(num6 * num6 + num7 * num7));
					}
				}
			}
			s_radiusFor = distance;
			s_radius = Mathf.Max(num2, num3);
			return s_radius;
		}
	}
	[HarmonyPatch(typeof(Container), "Awake")]
	internal static class ContainerAwakePatch
	{
		private static void Postfix(Container __instance)
		{
			NearbyChests.Register(__instance);
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Update")]
	internal static class InventoryGuiUpdatePostfix
	{
		private static void Postfix(InventoryGui __instance)
		{
			if (InventoryGui.IsVisible() && Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				RecipeSearch.Update(__instance);
				ChestSearch.Update(__instance);
				InventoryButton.Update(__instance);
			}
		}

		private static Exception Finalizer(Exception __exception)
		{
			return PatchGuard.Contain(__exception, "the search boxes");
		}
	}
	[BepInPlugin("s992.SearchEverything", "SearchEverything", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			Settings.Bind(((BaseUnityPlugin)this).Config);
			if (SafePatching.PatchAll(new Harmony("s992.SearchEverything"), ((BaseUnityPlugin)this).Logger))
			{
				((Component)this).gameObject.AddComponent<Finder>();
				((Component)this).gameObject.AddComponent<Markers>();
				((BaseUnityPlugin)this).Logger.LogInfo((object)(ModInfo.Name + " " + ModInfo.Version + " loaded"));
			}
		}
	}
	internal static class RecipeSearch
	{
		private static GuiInputField s_field;

		private static string[] s_words = Array.Empty<string>();

		public static string[] Words => s_words;

		public static void Update(InventoryGui gui)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			if (!Settings.RecipeSearch.Value)
			{
				if (Object.op_Implicit((Object)(object)s_field) && ((Component)s_field).gameObject.activeSelf)
				{
					bool num = s_words.Length != 0;
					Clear();
					((Component)s_field).gameObject.SetActive(false);
					if (num)
					{
						gui.UpdateCraftingPanel(false);
					}
				}
				return;
			}
			if (!Object.op_Implicit((Object)(object)s_field))
			{
				s_field = SearchField.Create((Transform)(object)gui.m_crafting, "SearchEverything_RecipeSearch", "Search recipes");
				if (!Object.op_Implicit((Object)(object)s_field))
				{
					return;
				}
				SearchField.Place((RectTransform)((Component)s_field).transform, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-10f, -69f), new Vector2(296f, 31f));
				SearchField.Fit(s_field, 18f);
				((UnityEvent<string>)(object)((TMP_InputField)s_field).onValueChanged).AddListener((UnityAction<string>)delegate(string text)
				{
					s_words = Matcher.Parse(text);
					if (Object.op_Implicit((Object)(object)InventoryGui.instance) && InventoryGui.IsVisible())
					{
						InventoryGui.instance.UpdateCraftingPanel(false);
					}
				});
				SearchField.LogLayout("Recipe search box", (RectTransform)((Component)s_field).transform);
			}
			if (!((Component)s_field).gameObject.activeSelf)
			{
				((Component)s_field).gameObject.SetActive(true);
			}
		}

		public static void Clear()
		{
			s_words = Array.Empty<string>();
			if (Object.op_Implicit((Object)(object)s_field) && ((TMP_InputField)s_field).text.Length > 0)
			{
				((TMP_InputField)s_field).SetTextWithoutNotify("");
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateRecipeList")]
	internal static class UpdateRecipeListPatch
	{
		private static void Prefix(List<Recipe> recipes)
		{
			string[] words = RecipeSearch.Words;
			if (words.Length != 0)
			{
				recipes?.RemoveAll((Recipe recipe) => !Matcher.Matches(recipe, words));
			}
		}

		private static Exception Finalizer(Exception __exception)
		{
			return PatchGuard.Contain(__exception, "the recipe search");
		}
	}
	internal static class SearchField
	{
		public static GuiInputField Create(Transform parent, string name, string placeholder)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00f9: 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)
			GuiInputField val = (Object.op_Implicit((Object)(object)Hud.instance) ? Hud.instance.m_buildUi.m_searchField : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				ModInfo.Log.LogWarning((object)"The build menu's search box wasn't found; search boxes are disabled");
				return null;
			}
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent, false);
			((Object)val2).name = name;
			val2.SetActive(true);
			Transform val3 = val2.transform.Find("SearchBarHint");
			if (Object.op_Implicit((Object)(object)val3))
			{
				((Component)val3).gameObject.SetActive(false);
			}
			Localize[] componentsInChildren = val2.GetComponentsInChildren<Localize>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			GuiInputField component = val2.GetComponent<GuiInputField>();
			((TMP_InputField)component).onValueChanged = new OnChangeEvent();
			((TMP_InputField)component).onSelect = new SelectionEvent();
			((TMP_InputField)component).onDeselect = new SelectionEvent();
			((TMP_InputField)component).onSubmit = new SubmitEvent();
			((TMP_InputField)component).onEndEdit = new SubmitEvent();
			component.OnInputSubmit = new OnInputSubmitEvent();
			((TMP_InputField)component).text = "";
			((TMP_InputField)component).restoreOriginalTextOnEscape = false;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)component).navigation = navigation;
			SetPlaceholder(component, placeholder);
			InputGuard.Register(component);
			return component;
		}

		public static void Fit(GuiInputField field, float fontSize)
		{
			//IL_001d: 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)
			if (Object.op_Implicit((Object)(object)((TMP_InputField)field).textViewport))
			{
				((TMP_InputField)field).textViewport.offsetMin = new Vector2(10f, 2f);
				((TMP_InputField)field).textViewport.offsetMax = new Vector2(-10f, -2f);
			}
			TMP_Text[] array = (TMP_Text[])(object)new TMP_Text[2]
			{
				((TMP_InputField)field).textComponent,
				(TMP_Text)/*isinst with value type is only supported in some contexts*/
			};
			foreach (TMP_Text val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					val.enableAutoSizing = false;
					val.fontSize = fontSize;
				}
			}
			((TMP_InputField)field).pointSize = fontSize;
		}

		public static void SetPlaceholder(GuiInputField field, string text)
		{
			if (Object.op_Implicit((Object)(object)field))
			{
				Graphic placeholder = ((TMP_InputField)field).placeholder;
				TMP_Text val = (TMP_Text)(object)((placeholder is TMP_Text) ? placeholder : null);
				if (val != null)
				{
					val.text = text;
				}
			}
		}

		public static void Place(RectTransform rect, Vector2 anchor, Vector2 pivot, Vector2 position, Vector2 size)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Vector2 anchorMin = (rect.anchorMax = anchor);
			rect.anchorMin = anchorMin;
			rect.pivot = pivot;
			rect.anchoredPosition = position;
			rect.sizeDelta = size;
		}

		public static void LogLayout(string what, RectTransform box)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			if (!Settings.LogLayout.Value || !Object.op_Implicit((Object)(object)box))
			{
				return;
			}
			ModInfo.Log.LogInfo((object)(what + ": " + Describe(box)));
			Transform parent = ((Transform)box).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if (val == null)
			{
				return;
			}
			ModInfo.Log.LogInfo((object)("  in " + ((Object)val).name + ": " + Describe(val)));
			foreach (RectTransform item in (Transform)val)
			{
				RectTransform val2 = item;
				if ((Object)(object)val2 != (Object)(object)box && ((Component)val2).gameObject.activeSelf)
				{
					ModInfo.Log.LogInfo((object)("    " + ((Object)val2).name + ": " + Describe(val2)));
				}
			}
		}

		private static string Describe(RectTransform rect)
		{
			//IL_000e: 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_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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[5];
			Rect rect2 = rect.rect;
			array[0] = ((Rect)(ref rect2)).xMin;
			rect2 = rect.rect;
			array[1] = ((Rect)(ref rect2)).yMin;
			rect2 = rect.rect;
			array[2] = ((Rect)(ref rect2)).width;
			rect2 = rect.rect;
			array[3] = ((Rect)(ref rect2)).height;
			array[4] = rect.anchoredPosition;
			return string.Format("rect {0:0},{1:0} {2:0}x{3:0} anchored {4} ", array) + $"anchors {rect.anchorMin}-{rect.anchorMax} pivot {rect.pivot}";
		}
	}
	internal static class SearchKeys
	{
		public static bool OurKeyPressed()
		{
			if (!Settings.Finder.Value || !Hotkeys.Pressed(Settings.FinderKey))
			{
				if (Markers.Count > 0)
				{
					return Hotkeys.Pressed(Settings.DismissKey);
				}
				return false;
			}
			return true;
		}

		public static bool IsTyping()
		{
			if (!InputGuard.Active && !Hotkeys.IsTyping())
			{
				if (Object.op_Implicit((Object)(object)Hud.instance))
				{
					return Hud.instance.m_buildUi.SearchFieldFocused;
				}
				return false;
			}
			return true;
		}

		public static bool Down(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ZInput.GetKeyDown(key, false);
		}
	}
	internal static class Settings
	{
		public static ConfigEntry<bool> RecipeSearch;

		public static ConfigEntry<bool> ChestSearch;

		public static ConfigEntry<float> DimOpacity;

		public static ConfigEntry<bool> Finder;

		public static ConfigEntry<KeyboardShortcut> FinderKey;

		public static ConfigEntry<bool> InventoryButton;

		public static ConfigEntry<int> Range;

		public static ConfigEntry<bool> CartsAndShips;

		public static ConfigEntry<int> MarkerSeconds;

		public static ConfigEntry<KeyboardShortcut> DismissKey;

		public static ConfigEntry<bool> LogLayout;

		public static int Version { get; private set; }

		public static void Bind(ConfigFile config)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			RecipeSearch = config.Bind<bool>("1. Recipes", "Recipe search", true, "A search box next to the Craft and Upgrade tabs filters the recipe list. Matches the item's name, its ingredients and its type (bow, helmet, food...).");
			ChestSearch = config.Bind<bool>("2. Chests", "Chest search", true, "A search box at the top of an open chest. Items that don't match fade out, in the chest and in your inventory.");
			DimOpacity = config.Bind<float>("2. Chests", "Faded opacity", 0.25f, new ConfigDescription("How visible items that don't match the chest search stay (0 = hidden, 1 = not faded).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			Finder = config.Bind<bool>("3. Nearby chests", "Nearby search", true, "A search window for everything in nearby chests. Picking a result marks the chests that hold it.");
			FinderKey = config.Bind<KeyboardShortcut>("3. Nearby chests", "Open key", new KeyboardShortcut((KeyCode)107, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Opens the nearby search, in the world or in the inventory. Escape closes it. The game doesn't act on this key while it opens the search (e.g. debug mode's K, which kills nearby enemies).");
			InventoryButton = config.Bind<bool>("3. Nearby chests", "Inventory button", true, "Shows a button above your inventory that opens the nearby search.");
			Range = config.Bind<int>("3. Nearby chests", "Range", 64, new ConfigDescription("Chests within this many metres of the camera are searched. Chests further than the game keeps loaded (128 m from you on the default simulation distance) can't be seen; the window's status line says when that applies.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 250), Array.Empty<object>()));
			CartsAndShips = config.Bind<bool>("3. Nearby chests", "Carts and ships", true, "Carts and ships count as chests.");
			MarkerSeconds = config.Bind<int>("4. Markers", "Marker duration", 60, new ConfigDescription("Seconds a chest stays marked. A marker also goes away when you open its chest. 0: until opened or dismissed.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 600), Array.Empty<object>()));
			DismissKey = config.Bind<KeyboardShortcut>("4. Markers", "Dismiss key", new KeyboardShortcut((KeyCode)107, (KeyCode[])(object)new KeyCode[2]
			{
				(KeyCode)306,
				(KeyCode)304
			}), "Removes every marker.");
			LogLayout = config.Bind<bool>("5. Diagnostics", "Log UI layout", false, "Writes where the search boxes were placed, and the panels around them, to the BepInEx log. Useful when a box overlaps something.");
			config.SettingChanged += delegate
			{
				Version++;
			};
		}
	}
	internal static class Ui
	{
		public static readonly Color TextColor = new Color(0.92f, 0.9f, 0.86f);

		public static readonly Color DimTextColor = new Color(0.68f, 0.66f, 0.62f);

		public static Image AddImage(Transform parent, string name, Sprite sprite, Color color)
		{
			//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_0033: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			Image obj = val.AddComponent<Image>();
			obj.sprite = sprite;
			((Graphic)obj).color = color;
			obj.type = (Type)((Object.op_Implicit((Object)(object)sprite) && sprite.border != Vector4.zero) ? 1 : 0);
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		public static TMP_Text AddText(Transform parent, string name, float size, Color color, TextAlignmentOptions alignment)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.SetActive(false);
			val.transform.SetParent(parent, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			TMP_Text val3 = (Object.op_Implicit((Object)(object)InventoryGui.instance) ? InventoryGui.instance.m_containerName : null);
			if (Object.op_Implicit((Object)(object)val3))
			{
				((TMP_Text)val2).font = val3.font;
				((TMP_Text)val2).fontSharedMaterial = val3.fontSharedMaterial;
			}
			val.SetActive(true);
			((TMP_Text)val2).fontSize = size;
			((Graphic)val2).color = color;
			((TMP_Text)val2).alignment = alignment;
			((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)1;
			((Graphic)val2).raycastTarget = false;
			return (TMP_Text)(object)val2;
		}

		public static void Stretch(RectTransform rect, float inset)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			rect.offsetMin = new Vector2(inset, inset);
			rect.offsetMax = new Vector2(0f - inset, 0f - inset);
		}

		public static Sprite SlotSprite()
		{
			InventoryGui instance = InventoryGui.instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.m_playerGrid) || !Object.op_Implicit((Object)(object)instance.m_playerGrid.m_elementPrefab))
			{
				return null;
			}
			Image component = instance.m_playerGrid.m_elementPrefab.GetComponent<Image>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return null;
			}
			return component.sprite;
		}

		public static void CopyPanelLook(Image target)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			InventoryGui instance = InventoryGui.instance;
			Transform val = ((Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.m_container)) ? ((Transform)instance.m_container).Find("Bkg") : null);
			Image val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<Image>() : null);
			if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.sprite))
			{
				((Graphic)target).color = new Color(0.1f, 0.09f, 0.08f, 0.95f);
				return;
			}
			target.sprite = val2.sprite;
			target.type = val2.type;
			((Graphic)target).color = ((Graphic)val2).color;
			((Graphic)target).material = ((Graphic)val2).material;
			target.pixelsPerUnitMultiplier = val2.pixelsPerUnitMultiplier;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "s992.SearchEverything";

		public const string PLUGIN_NAME = "SearchEverything";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace ValheimMods.Shared
{
	internal sealed class FrameGuard
	{
		private const int MaxErrors = 10;

		private readonly Behaviour m_owner;

		private readonly string m_feature;

		private int m_errors;

		public FrameGuard(Behaviour owner, string feature)
		{
			m_owner = owner;
			m_feature = feature;
		}

		public void Report(Exception e)
		{
			m_errors++;
			if (m_errors == 1)
			{
				ModInfo.Log.LogError((object)$"Error in {m_feature}: {e}");
			}
			if (m_errors >= 10)
			{
				m_owner.enabled = false;
				string text = ModInfo.Name + ": " + m_feature + " kept failing and is off until the game restarts. Details are in BepInEx/LogOutput.log.";
				ModInfo.Log.LogError((object)text);
				PlayerNotice.Show(text);
			}
		}
	}
	internal static class Hotkeys
	{
		private static readonly KeyCode[] s_modifierKeys;

		public static bool Pressed(ConfigEntry<KeyboardShortcut> entry)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = entry.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey == 0 || !ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, false))
			{
				return false;
			}
			List<KeyCode> modifiers = ((KeyboardShortcut)(ref value)).Modifiers.ToList();
			if (modifiers.Any((KeyCode key) => !ZInput.GetKey(key, false)))
			{
				return false;
			}
			return !s_modifierKeys.Any((KeyCode key) => !modifiers.Contains(key) && ZInput.GetKey(key, false));
		}

		public static bool Held(ConfigEntry<KeyboardShortcut> entry)
		{
			//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_0009: 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)
			KeyboardShortcut value = entry.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey != 0 && ZInput.GetKey(((KeyboardShortcut)(ref value)).MainKey, false))
			{
				return ((KeyboardShortcut)(ref value)).Modifiers.All((KeyCode key) => ZInput.GetKey(key, false));
			}
			return false;
		}

		public static bool IsTyping()
		{
			if (!Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsVisible() && !Minimap.InTextInput())
			{
				if (Object.op_Implicit((Object)(object)Chat.instance))
				{
					return Chat.instance.HasFocus();
				}
				return false;
			}
			return true;
		}

		static Hotkeys()
		{
			KeyCode[] array = new KeyCode[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			s_modifierKeys = (KeyCode[])(object)array;
		}
	}
	internal static class ModInfo
	{
		public static readonly string Name = typeof(ModInfo).Assembly.GetName().Name;

		public static readonly string Version = typeof(ModInfo).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? typeof(ModInfo).Assembly.GetName().Version.ToString(3);

		private static ManualLogSource s_log;

		public static ManualLogSource Log => s_log ?? (s_log = Logger.CreateLogSource(Name));
	}
	internal static class PatchGuard
	{
		private static readonly HashSet<string> s_reported = new HashSet<string>();

		public static Exception Contain(Exception exception, string feature)
		{
			if (exception == null || !FromThisMod(exception))
			{
				return exception;
			}
			if (s_reported.Add(feature))
			{
				ModInfo.Log.LogError((object)$"Error in {feature} (further errors there aren't logged): {exception}");
				PlayerNotice.Show(ModInfo.Name + ": " + feature + " hit an error and may not work until the game restarts. Details are in BepInEx/LogOutput.log.");
			}
			return null;
		}

		private static bool FromThisMod(Exception exception)
		{
			Assembly assembly = typeof(PatchGuard).Assembly;
			for (Exception ex = exception; ex != null; ex = ex.InnerException)
			{
				StackFrame[] array = new StackTrace(ex, fNeedFileInfo: false).GetFrames() ?? Array.Empty<StackFrame>();
				for (int i = 0; i < array.Length; i++)
				{
					if (array[i].GetMethod()?.DeclaringType?.Assembly == assembly)
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	internal sealed class PlayerNotice : MonoBehaviour
	{
		private static PlayerNotice s_instance;

		private readonly List<string> m_pending = new List<string>();

		public static void Show(string message)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)s_instance))
			{
				GameObject val = new GameObject(ModInfo.Name + ".PlayerNotice");
				Object.DontDestroyOnLoad((Object)val);
				s_instance = val.AddComponent<PlayerNotice>();
			}
			s_instance.m_pending.Add(message);
		}

		private void Update()
		{
			if (m_pending.Count == 0 || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)MessageHud.instance))
			{
				return;
			}
			try
			{
				foreach (string item in m_pending)
				{
					Send(item);
				}
			}
			catch (Exception ex)
			{
				ModInfo.Log.LogWarning((object)("Couldn't show a message in game: " + ex.Message));
			}
			m_pending.Clear();
		}

		private static void Send(string message)
		{
			((Character)Player.m_localPlayer).Message((MessageType)1, message, 0, (Sprite)null, false);
			if (Object.op_Implicit((Object)(object)Console.instance))
			{
				Console.instance.Print(message);
			}
		}
	}
	internal static class SafePatching
	{
		public static bool PatchAll(Harmony harmony, ManualLogSource log)
		{
			List<string> list = new List<string>();
			Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(typeof(SafePatching).Assembly);
			foreach (Type type in typesFromAssembly)
			{
				try
				{
					harmony.CreateClassProcessor(type).Patch();
				}
				catch (Exception arg)
				{
					list.Add(type.Name);
					log.LogError((object)$"Patch {type.Name} failed: {arg}");
				}
			}
			if (list.Count == 0)
			{
				return true;
			}
			harmony.UnpatchSelf();
			string text = ModInfo.Name + " is turned off: this game version changed something it relies on (" + string.Join(", ", list) + "). Check for an update to " + ModInfo.Name + ".";
			log.LogError((object)text);
			PlayerNotice.Show(text);
			return false;
		}

		public static void ExpectReplaced(int replaced, int expected, string what)
		{
			if (replaced != expected)
			{
				throw new InvalidOperationException($"{what}: expected {expected} change(s), made {replaced}");
			}
		}
	}
}