Decompiled source of ItemFinder v1.3.2

ChineseCanFly.ItemFinder.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ChineseCanFly.ItemFinder")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ChineseCanFly.ItemFinder")]
[assembly: AssemblyTitle("ChineseCanFly.ItemFinder")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ChineseCanFly.ItemFinder
{
	internal static class Pinyin
	{
		private static readonly Encoding Gb;

		private static readonly Dictionary<char, char> Fallback;

		static Pinyin()
		{
			Fallback = new Dictionary<char, char>();
			try
			{
				Gb = Encoding.GetEncoding(936);
			}
			catch
			{
				Gb = null;
			}
			string[] array = new string[80]
			{
				"铁t", "锭d", "矿k", "木m", "石s", "皮p", "肉r", "骨g", "线x", "布b",
				"银y", "铜t", "锡x", "金j", "黑h", "青q", "食s", "材c", "料l", "箭j",
				"弓g", "剑j", "斧f", "锤c", "盾d", "甲j", "药y", "麦m", "米m", "种z",
				"血x", "龙l", "狼l", "熊x", "猪z", "鸡j", "蛋d", "鱼y", "虾x", "蟹x",
				"果g", "莓m", "菇g", "蜜m", "酒j", "面m", "包b", "油y", "盐y", "糖t",
				"香x", "玉y", "晶j", "碎s", "片p", "头t", "盔k", "裤k", "靴x", "手s",
				"披p", "风f", "火h", "冰b", "毒d", "灵l", "魔m", "法f", "杖z", "石s",
				"砖z", "板b", "条t", "钉d", "锁s", "钥y", "箱x", "柜g", "桶t", "瓶p"
			};
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].Length == 2)
				{
					Fallback[array[i][0]] = array[i][1];
				}
			}
		}

		public static string Initials(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder(text.Length);
			foreach (char c in text)
			{
				if (c < '\u0080')
				{
					if (char.IsLetterOrDigit(c))
					{
						stringBuilder.Append(char.ToLowerInvariant(c));
					}
					continue;
				}
				char c2 = Resolve(c);
				if (c2 != 0)
				{
					stringBuilder.Append(c2);
				}
			}
			return stringBuilder.ToString();
		}

		private static char Resolve(char c)
		{
			if (Gb != null)
			{
				try
				{
					byte[] bytes = Gb.GetBytes(new char[1] { c });
					if (bytes.Length == 2 && bytes[0] >= 176)
					{
						char c2 = FromGbRange(bytes[0], bytes[1]);
						if (c2 != 0)
						{
							return c2;
						}
					}
				}
				catch
				{
				}
			}
			if (Fallback.TryGetValue(c, out var value))
			{
				return value;
			}
			return '\0';
		}

		private static char FromGbRange(byte high, byte low)
		{
			int num = (high << 8) | low;
			if (num >= 45217 && num <= 45252)
			{
				return 'a';
			}
			if (num >= 45253 && num <= 45760)
			{
				return 'b';
			}
			if (num >= 45761 && num <= 46317)
			{
				return 'c';
			}
			if (num >= 46318 && num <= 46825)
			{
				return 'd';
			}
			if (num >= 46826 && num <= 47009)
			{
				return 'e';
			}
			if (num >= 47010 && num <= 47296)
			{
				return 'f';
			}
			if (num >= 47297 && num <= 47613)
			{
				return 'g';
			}
			if (num >= 47614 && num <= 48118)
			{
				return 'h';
			}
			if (num >= 48119 && num <= 49061)
			{
				return 'j';
			}
			if (num >= 49062 && num <= 49323)
			{
				return 'k';
			}
			if (num >= 49324 && num <= 49895)
			{
				return 'l';
			}
			if (num >= 49896 && num <= 50370)
			{
				return 'm';
			}
			if (num >= 50371 && num <= 50613)
			{
				return 'n';
			}
			if (num >= 50614 && num <= 50621)
			{
				return 'o';
			}
			if (num >= 50622 && num <= 50905)
			{
				return 'p';
			}
			if (num >= 50906 && num <= 51386)
			{
				return 'q';
			}
			if (num >= 51387 && num <= 51445)
			{
				return 'r';
			}
			if (num >= 51446 && num <= 52217)
			{
				return 's';
			}
			if (num >= 52218 && num <= 52697)
			{
				return 't';
			}
			if (num >= 52698 && num <= 52979)
			{
				return 'w';
			}
			if (num >= 52980 && num <= 53688)
			{
				return 'x';
			}
			if (num >= 53689 && num <= 54480)
			{
				return 'y';
			}
			if (num >= 54481 && num <= 55289)
			{
				return 'z';
			}
			return '\0';
		}
	}
	[BepInPlugin("ChineseCanFly.ItemFinder", "Item Finder", "1.3.2")]
	public class Plugin : BaseUnityPlugin
	{
		private sealed class Entry
		{
			public Container Box;

			public string Display;

			public string English;

			public string Initials;

			public string Key;

			public int Count;

			public float Distance;
		}

		public const string Guid = "ChineseCanFly.ItemFinder";

		internal static bool WindowOpen;

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private static float _blockLogTimer;

		private static float _useLogTimer;

		private ConfigEntry<bool> _showButton;

		private ConfigEntry<bool> _anchorToInventory;

		private ConfigEntry<float> _buttonX;

		private ConfigEntry<float> _buttonY;

		private ConfigEntry<float> _searchRadius;

		private ConfigEntry<bool> _pinyin;

		private ConfigEntry<int> _maxResults;

		private ConfigEntry<bool> _includeShips;

		private ConfigEntry<bool> _sound;

		private ConfigEntry<float> _soundInterval;

		private ConfigEntry<float> _markerScale;

		private ConfigEntry<KeyboardShortcut> _measureKey;

		private ConfigEntry<bool> _measurePlayer;

		private ConfigEntry<float> _measureRange;

		private bool _searchOpen;

		private string _query = "";

		private bool _focusSearch;

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

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

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

		private Vector2 _listScroll;

		private Container _target;

		private float _soundTimer;

		private Rect _windowRect = new Rect(0f, 0f, 680f, 620f);

		private Vector3 _pointA;

		private Vector3 _pointB;

		private int _measureStage;

		private float _pulse;

		private GUIStyle _windowStyle;

		private GUIStyle _labelStyle;

		private GUIStyle _textFieldStyle;

		private GUIStyle _buttonStyle;

		private GUIStyle _listStyle;

		private GUIStyle _worldLabelStyle;

		private Texture2D _panelTex;

		private Texture2D _fieldTex;

		private Texture2D _buttonTex;

		private Texture2D _buttonHoverTex;

		private Texture2D _worldLabelTex;

		private bool _stylesReady;

		private bool _dumpedLayout;

		private Button _inventoryButton;

		private Button _template;

		private RectTransform _gridRect;

		private RectTransform _panelRect;

		private Texture2D _ring;

		private Texture2D _arrow;

		private static Dictionary<string, string> _lang = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

		private static MethodInfo _localizeMethod;

		private static object _localizeInstance;

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

		internal static void NoteBlockedHide()
		{
			if (Log == null || Time.unscaledTime < _blockLogTimer)
			{
				return;
			}
			_blockLogTimer = Time.unscaledTime + 1f;
			string text = "?";
			try
			{
				StackFrame[] frames = new StackTrace(1, fNeedFileInfo: false).GetFrames();
				if (frames != null)
				{
					for (int i = 0; i < frames.Length; i++)
					{
						MethodBase method = frames[i].GetMethod();
						if (!(method == null) && !(method.DeclaringType == typeof(Plugin)) && !(method.DeclaringType == typeof(InventoryGuiHideGuard)))
						{
							text = method.DeclaringType.Name + "." + method.Name;
							break;
						}
					}
				}
			}
			catch
			{
			}
			Log.LogInfo((object)("Kept the inventory open while searching (blocked InventoryGui.Hide from " + text + ")."));
		}

		internal static void NoteSuppressedUse()
		{
			if (Log != null && !(Time.unscaledTime < _useLogTimer))
			{
				_useLogTimer = Time.unscaledTime + 1f;
				Log.LogInfo((object)"Swallowed ZInput.GetButtonDown(\"Use\") while searching.");
			}
		}

		private void Awake()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Expected O, but got Unknown
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Expected O, but got Unknown
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Expected O, but got Unknown
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Expected O, but got Unknown
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Expected O, but got Unknown
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Expected O, but got Unknown
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Expected O, but got Unknown
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			LoadLanguage();
			_showButton = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "Show Inventory Button", true, new ConfigDescription(T("ShowButton", "Show a search button next to the inventory grid."), (AcceptableValueBase)null, Array.Empty<object>()));
			_anchorToInventory = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "Anchor To Inventory", true, new ConfigDescription(T("Anchor", "Attach the button to the inventory panel. Turn off to attach it to the item grid instead, for custom inventory layouts."), (AcceptableValueBase)null, Array.Empty<object>()));
			_buttonX = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "Button X Percent", 100f, new ConfigDescription(T("BtnX", "Horizontal position in percent of the anchored panel width. 100 = flush with the right edge, 0 = left edge."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			_buttonY = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "Button Y Pixels", -6f, new ConfigDescription(T("BtnY", "Pixels from the bottom edge of the anchored panel. Negative puts the button below it, positive moves it up inside the panel."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(-250f, 250f), Array.Empty<object>()));
			_searchRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Search", "Search Radius", 0f, new ConfigDescription(T("Radius", "Only list chests within this many meters. 0 = every loaded container."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 500f), Array.Empty<object>()));
			_pinyin = ((BaseUnityPlugin)this).Config.Bind<bool>("Search", "Pinyin Search", true, new ConfigDescription(T("Pinyin", "Allow pinyin initials, e.g. 'td' finds 铁锭."), (AcceptableValueBase)null, Array.Empty<object>()));
			_maxResults = ((BaseUnityPlugin)this).Config.Bind<int>("Search", "Max Results", 24, new ConfigDescription(T("MaxResults", "How many results to show."), (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 60), Array.Empty<object>()));
			_includeShips = ((BaseUnityPlugin)this).Config.Bind<bool>("Search", "Include Ships And Carts", true, new ConfigDescription(T("IncludeShips", "Include containers on ships and carts."), (AcceptableValueBase)null, Array.Empty<object>()));
			_sound = ((BaseUnityPlugin)this).Config.Bind<bool>("Guide", "Use Sound", true, new ConfigDescription(T("Sound", "Play the wishbone ping while a target is selected."), (AcceptableValueBase)null, Array.Empty<object>()));
			_soundInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Guide", "Sound Interval", 1.5f, new ConfigDescription(T("SoundInterval", "Seconds between pings when far away; it speeds up as you get closer."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.4f, 5f), Array.Empty<object>()));
			_markerScale = ((BaseUnityPlugin)this).Config.Bind<float>("Guide", "Marker Scale", 1f, new ConfigDescription(T("MarkerScale", "Size multiplier for the on-screen marker and arrow."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>()));
			_measureKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Measure", "Measure Hotkey", new KeyboardShortcut((KeyCode)112, Array.Empty<KeyCode>()), new ConfigDescription(T("MeasureKey", "First press sets the start point, second sets the end point, third clears it."), (AcceptableValueBase)null, Array.Empty<object>()));
			_measurePlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("Measure", "Show Player Distance", true, new ConfigDescription(T("MeasurePlayer", "Also show the live distance from you to the start point."), (AcceptableValueBase)null, Array.Empty<object>()));
			_measureRange = ((BaseUnityPlugin)this).Config.Bind<float>("Measure", "Place Range", 60f, new ConfigDescription(T("MeasureRange", "How far you can place a point with the crosshair."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 200f), Array.Empty<object>()));
			MakeTextures();
			try
			{
				_harmony = new Harmony("ChineseCanFly.ItemFinder");
				_harmony.PatchAll(typeof(TextInputVisibilityPatch));
				_harmony.PatchAll(typeof(ZInputUsePatch));
				_harmony.PatchAll(typeof(InventoryGuiHideGuard));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not apply input patches: " + ex.Message));
			}
			LogPatchState();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Item Finder 1.3.2 loaded.");
		}

		private void LogPatchState()
		{
			try
			{
				MethodInfo method = AccessTools.Method(typeof(ZInput), "GetButtonDown", new Type[1] { typeof(string) }, (Type[])null);
				MethodInfo method2 = AccessTools.Method(typeof(InventoryGui), "Hide", (Type[])null, (Type[])null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Patch state: ZInput.GetButtonDown = " + DescribePatches(method) + " | InventoryGui.Hide = " + DescribePatches(method2)));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not inspect Harmony patches: " + ex.Message));
			}
		}

		private static string DescribePatches(MethodBase method)
		{
			if (method == null)
			{
				return "missing method";
			}
			Patches patchInfo = Harmony.GetPatchInfo(method);
			if (patchInfo == null || patchInfo.Prefixes == null || patchInfo.Prefixes.Count == 0)
			{
				return "no prefixes";
			}
			StringBuilder stringBuilder = new StringBuilder();
			bool flag = false;
			for (int i = 0; i < patchInfo.Prefixes.Count; i++)
			{
				Patch val = patchInfo.Prefixes[i];
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append(", ");
				}
				stringBuilder.Append(val.owner);
				if (val.owner == "ChineseCanFly.ItemFinder")
				{
					flag = true;
				}
			}
			stringBuilder.Append(flag ? " [ours present]" : " [OURS MISSING]");
			return stringBuilder.ToString();
		}

		private void Update()
		{
			//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_00e1: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				_pulse += Time.unscaledDeltaTime;
				KeepInventoryButton();
				if (_searchOpen && Input.GetKeyDown((KeyCode)27))
				{
					CloseSearch();
					return;
				}
				if (_searchOpen && ZInput.GetButtonDown("Inventory"))
				{
					CloseSearch();
				}
				if (_searchOpen && !InventoryGui.IsVisible())
				{
					CloseSearch();
				}
				if (!_searchOpen && !InventoryGui.IsVisible() && !Console.IsVisible() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Menu.IsVisible())
				{
					KeyboardShortcut value = _measureKey.Value;
					if (((KeyboardShortcut)(ref value)).IsDown())
					{
						PlaceMeasurePoint();
					}
				}
				if ((Object)(object)_target != (Object)null && _sound.Value)
				{
					float num = DistanceTo(((Component)_target).transform.position);
					float soundTimer = Mathf.Clamp(_soundInterval.Value * (0.35f + num / 40f), 0.35f, _soundInterval.Value);
					_soundTimer -= Time.deltaTime;
					if (_soundTimer <= 0f)
					{
						_soundTimer = soundTimer;
						PlayPing(num);
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Item Finder update failed: " + ex));
			}
		}

		private void KeepInventoryButton()
		{
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			bool flag = InventoryGui.IsVisible();
			if (!_showButton.Value || !flag)
			{
				if ((Object)(object)_inventoryButton != (Object)null)
				{
					((Component)_inventoryButton).gameObject.SetActive(false);
				}
				return;
			}
			if ((Object)(object)_inventoryButton == (Object)null || (Object)(object)_template == (Object)null)
			{
				TryCreateInventoryButton(instance);
			}
			if ((Object)(object)_inventoryButton != (Object)null)
			{
				((Component)_inventoryButton).gameObject.SetActive(true);
				ApplyButtonPlacement(instance);
			}
			DumpInventoryLayout(instance);
		}

		private void ApplyButtonPlacement(InventoryGui gui)
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_inventoryButton == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)_inventoryButton).transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			RectTransform val2 = (_anchorToInventory.Value ? InventoryPanel(gui) : _gridRect);
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = _gridRect;
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			float num = Mathf.Clamp((_buttonX != null) ? _buttonX.Value : 100f, 0f, 100f) / 100f;
			float num2 = ((_buttonY != null) ? _buttonY.Value : (-6f));
			if ((Object)(object)((Transform)val).parent != (Object)(object)val2 || Mathf.Abs(val.anchorMin.x - num) > 0.0001f || Mathf.Abs(val.anchorMax.x - num) > 0.0001f || Mathf.Abs(val.anchoredPosition.y - num2) > 0.01f)
			{
				if ((Object)(object)((Transform)val).parent != (Object)(object)val2)
				{
					((Transform)val).SetParent((Transform)(object)val2, false);
				}
				val.anchorMin = new Vector2(num, 0f);
				val.anchorMax = new Vector2(num, 0f);
				val.pivot = new Vector2(1f, 1f);
				val.anchoredPosition = new Vector2(0f, num2);
				((Transform)val).localScale = Vector3.one;
			}
		}

		private RectTransform InventoryPanel(InventoryGui gui)
		{
			if ((Object)(object)_panelRect != (Object)null)
			{
				return _panelRect;
			}
			if ((Object)(object)gui.m_player != (Object)null)
			{
				Transform val = ((Transform)gui.m_player).Find("Bkg");
				if ((Object)(object)val != (Object)null)
				{
					_panelRect = (RectTransform)(object)((val is RectTransform) ? val : null);
				}
				if ((Object)(object)_panelRect == (Object)null)
				{
					_panelRect = gui.m_player;
				}
			}
			return _panelRect;
		}

		private void DumpInventoryLayout(InventoryGui gui)
		{
			if (_dumpedLayout)
			{
				return;
			}
			_dumpedLayout = true;
			try
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("INVDUMP screen=" + Screen.width + "x" + Screen.height));
				FieldInfo field = typeof(InventoryGui).GetField("m_playerGrid", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				Component val = (Component)((field != null) ? /*isinst with value type is only supported in some contexts*/: null);
				RectTransform rt = (((Object)(object)val != (Object)null) ? val.GetComponent<RectTransform>() : null);
				Transform inventoryRoot = gui.m_inventoryRoot;
				DumpRectNode("m_inventoryRoot", (RectTransform)(object)((inventoryRoot is RectTransform) ? inventoryRoot : null));
				DumpRectNode("m_player", gui.m_player);
				DumpRectNode("m_container", gui.m_container);
				DumpRectNode("m_info", gui.m_info);
				DumpRectNode("m_playerGrid", rt);
				int count = 0;
				Transform transform = ((Component)gui).transform;
				WalkRects((RectTransform)(object)((transform is RectTransform) ? transform : null), 0, ref count);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("INVDUMP end, " + count + " nodes"));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Inventory layout dump failed: " + ex.Message));
			}
		}

		private void WalkRects(RectTransform rt, int depth, ref int count)
		{
			//IL_0028: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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)
			if (!((Object)(object)rt == (Object)null) && depth <= 5 && count < 150)
			{
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				rt.GetWorldCorners(array);
				Vector2 val = RectTransformUtility.WorldToScreenPoint((Camera)null, array[0]);
				Vector2 val2 = RectTransformUtility.WorldToScreenPoint((Camera)null, array[2]);
				float num = val2.x - val.x;
				float num2 = val2.y - val.y;
				if (num > 40f && num2 > 40f)
				{
					Image component = ((Component)rt).GetComponent<Image>();
					string text = (((Object)(object)component == (Object)null) ? "-" : (((Object)(object)component.sprite != (Object)null) ? ((Object)component.sprite).name : "flat"));
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"INVDUMP n d{depth} '{RectPath((Transform)(object)rt)}' img={text} px=({val.x:F0},{val.y:F0})-({val2.x:F0},{val2.y:F0}) norm=({val.x / (float)Screen.width:F3},{val.y / (float)Screen.height:F3})-({val2.x / (float)Screen.width:F3},{val2.y / (float)Screen.height:F3})");
					count++;
				}
				for (int i = 0; i < ((Transform)rt).childCount; i++)
				{
					Transform child = ((Transform)rt).GetChild(i);
					WalkRects((RectTransform)(object)((child is RectTransform) ? child : null), depth + 1, ref count);
				}
			}
		}

		private void DumpRectNode(string label, RectTransform rt)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rt == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("INVDUMP " + label + " = null"));
				return;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rt.GetWorldCorners(array);
			string text;
			try
			{
				Vector2 val = RectTransformUtility.WorldToScreenPoint((Camera)null, array[0]);
				Vector2 val2 = RectTransformUtility.WorldToScreenPoint((Camera)null, array[2]);
				text = $"screen=({val.x:F0},{val.y:F0})-({val2.x:F0},{val2.y:F0})";
			}
			catch
			{
				text = "screen=?";
			}
			ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
			object[] obj2 = new object[8]
			{
				label,
				RectPath((Transform)(object)rt),
				rt.anchorMin,
				rt.anchorMax,
				rt.pivot,
				rt.sizeDelta,
				null,
				null
			};
			Rect rect = rt.rect;
			obj2[6] = ((Rect)(ref rect)).size;
			obj2[7] = text;
			logger.LogInfo((object)string.Format("INVDUMP {0} path='{1}' anchorMin={2} anchorMax={3} pivot={4} sizeDelta={5} rect={6} {7}", obj2));
		}

		private static string RectPath(Transform t)
		{
			string text = ((Object)t).name;
			Transform parent = t.parent;
			int num = 0;
			while ((Object)(object)parent != (Object)null && num++ < 6)
			{
				text = ((Object)parent).name + "/" + text;
				parent = parent.parent;
			}
			return text;
		}

		private void TryCreateInventoryButton(InventoryGui gui)
		{
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			//IL_0156: 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: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				_template = gui.m_takeAllButton;
				if ((Object)(object)_template == (Object)null)
				{
					return;
				}
				FieldInfo field = typeof(InventoryGui).GetField("m_playerGrid", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				Component val = (Component)((field != null) ? /*isinst with value type is only supported in some contexts*/: null);
				RectTransform val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<RectTransform>() : null);
				RectTransform component = ((Component)_template).GetComponent<RectTransform>();
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)component == (Object)null))
				{
					_gridRect = val2;
					_panelRect = null;
					RectTransform val3 = (_anchorToInventory.Value ? InventoryPanel(gui) : val2);
					if ((Object)(object)val3 == (Object)null)
					{
						val3 = val2;
					}
					GameObject val4 = Object.Instantiate<GameObject>(((Component)_template).gameObject, (Transform)(object)val3);
					((Object)val4).name = "ItemFinder_SearchButton";
					_inventoryButton = val4.GetComponent<Button>();
					if (!((Object)(object)_inventoryButton == (Object)null))
					{
						((UnityEventBase)_inventoryButton.onClick).RemoveAllListeners();
						((UnityEvent)_inventoryButton.onClick).AddListener(new UnityAction(OpenSearch));
						SetButtonLabel(_inventoryButton, T("Button", "查找"));
						RectTransform component2 = val4.GetComponent<RectTransform>();
						((Transform)component2).SetParent((Transform)(object)val3, false);
						component2.sizeDelta = new Vector2(140f, Mathf.Max(component.sizeDelta.y, 40f));
						((Transform)component2).localScale = Vector3.one;
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not create the inventory button: " + ex.Message));
			}
		}

		private static void SetButtonLabel(Button button, string label)
		{
			if (!((Object)(object)button == (Object)null))
			{
				Text[] componentsInChildren = ((Component)button).GetComponentsInChildren<Text>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].text = label;
				}
				TMP_Text[] componentsInChildren2 = ((Component)button).GetComponentsInChildren<TMP_Text>(true);
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					componentsInChildren2[j].text = label;
				}
			}
		}

		private void PlaceMeasurePoint()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			Camera main = Camera.main;
			if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)main == (Object)null))
			{
				RaycastHit val = default(RaycastHit);
				if (!Physics.Raycast(((Component)main).transform.position, ((Component)main).transform.forward, ref val, _measureRange.Value, -1, (QueryTriggerInteraction)1))
				{
					((Character)localPlayer).Message((MessageType)2, T("MeasureMiss", "对着地面或建筑按 P"), 0, (Sprite)null, false);
				}
				else if (_measureStage == 0)
				{
					_pointA = ((RaycastHit)(ref val)).point;
					_pointB = Vector3.zero;
					_measureStage = 1;
					((Character)localPlayer).Message((MessageType)2, T("MeasureStart", "起点已记录,再按一次设置终点"), 0, (Sprite)null, false);
				}
				else if (_measureStage == 1)
				{
					_pointB = ((RaycastHit)(ref val)).point;
					_measureStage = 2;
					((Character)localPlayer).Message((MessageType)2, string.Format(T("MeasureDone", "起点 → 终点:{0:F1} 米"), Vector3.Distance(_pointA, _pointB)), 0, (Sprite)null, false);
				}
				else
				{
					_measureStage = 0;
					_pointA = Vector3.zero;
					_pointB = Vector3.zero;
					((Character)localPlayer).Message((MessageType)2, T("MeasureCleared", "测量已清除"), 0, (Sprite)null, false);
				}
			}
		}

		private void OpenSearch()
		{
			_searchOpen = true;
			WindowOpen = true;
			_focusSearch = true;
			_query = "";
			PositionWindow();
			BuildIndex();
			Refresh();
		}

		private void CloseSearch()
		{
			_searchOpen = false;
			WindowOpen = false;
			_query = "";
			_results.Clear();
			_suggestions.Clear();
		}

		private void PositionWindow()
		{
			((Rect)(ref _windowRect)).width = Mathf.Clamp((float)Screen.width * 0.44f, 680f, 900f);
			((Rect)(ref _windowRect)).height = Mathf.Clamp((float)Screen.height * 0.72f, 620f, 920f);
			((Rect)(ref _windowRect)).x = ((float)Screen.width - ((Rect)(ref _windowRect)).width) * 0.5f;
			((Rect)(ref _windowRect)).y = ((float)Screen.height - ((Rect)(ref _windowRect)).height) * 0.5f;
		}

		private void BuildIndex()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			_index.Clear();
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			Vector3 position = ((Component)localPlayer).transform.position;
			Container[] array = Object.FindObjectsOfType<Container>();
			foreach (Container val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Inventory inventory = val.GetInventory();
				if (inventory == null)
				{
					continue;
				}
				float num = Vector3.Distance(position, ((Component)val).transform.position);
				if ((_searchRadius.Value > 0f && num > _searchRadius.Value) || (!_includeShips.Value && IsVehicle(val)))
				{
					continue;
				}
				List<ItemData> allItems = inventory.GetAllItems();
				for (int j = 0; j < allItems.Count; j++)
				{
					ItemData val2 = allItems[j];
					if (val2 == null || val2.m_shared == null)
					{
						continue;
					}
					string name = val2.m_shared.m_name;
					string text = name + "@" + ((Object)val).GetInstanceID();
					Entry entry = null;
					for (int k = 0; k < _index.Count; k++)
					{
						if (_index[k].Key == text)
						{
							entry = _index[k];
							break;
						}
					}
					if (entry != null)
					{
						entry.Count += val2.m_stack;
						continue;
					}
					string text2 = Localize(name);
					_index.Add(new Entry
					{
						Box = val,
						Display = text2,
						English = (((Object)(object)val2.m_dropPrefab != (Object)null) ? ((Object)val2.m_dropPrefab).name : name),
						Initials = (_pinyin.Value ? Pinyin.Initials(text2) : ""),
						Key = text,
						Count = val2.m_stack,
						Distance = num
					});
				}
			}
		}

		private static bool IsVehicle(Container box)
		{
			if (!((Object)(object)((Component)box).GetComponentInParent<Ship>() != (Object)null))
			{
				return (Object)(object)((Component)box).GetComponentInParent<Vagon>() != (Object)null;
			}
			return true;
		}

		private void Refresh()
		{
			//IL_0079: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			_results.Clear();
			_suggestions.Clear();
			string q = Normalize(_query);
			if (q.Length == 0)
			{
				return;
			}
			HashSet<string> hashSet = new HashSet<string>();
			for (int i = 0; i < _index.Count; i++)
			{
				Entry entry = _index[i];
				if (Match(q, entry) >= 0)
				{
					entry.Distance = DistanceTo(((Component)entry.Box).transform.position);
					_results.Add(entry);
					string item = entry.Display + "|" + entry.English;
					if (hashSet.Add(item) && _suggestions.Count < 10)
					{
						_suggestions.Add(entry.Display + "  –  " + entry.English);
					}
				}
			}
			_results.Sort(delegate(Entry a, Entry b)
			{
				int num = Match(q, a);
				int num2 = Match(q, b);
				return (num != num2) ? num.CompareTo(num2) : a.Distance.CompareTo(b.Distance);
			});
			if (_results.Count > _maxResults.Value)
			{
				_results.RemoveRange(_maxResults.Value, _results.Count - _maxResults.Value);
			}
			_listScroll = Vector2.zero;
		}

		private int Match(string q, Entry e)
		{
			string text = Normalize(e.Display);
			string text2 = Normalize(e.English);
			if (text == q || text2 == q)
			{
				return 0;
			}
			if (text.StartsWith(q) || text2.StartsWith(q))
			{
				return 1;
			}
			if (text.Contains(q) || text2.Contains(q))
			{
				return 2;
			}
			if (e.Initials.Length > 0 && e.Initials.Contains(q))
			{
				return 3;
			}
			return -1;
		}

		private static string Normalize(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder(s.Length);
			foreach (char c in s)
			{
				if (!char.IsWhiteSpace(c) && c != '$' && c != '_' && c != '-' && c != '.')
				{
					stringBuilder.Append(char.ToLowerInvariant(c));
				}
			}
			return stringBuilder.ToString();
		}

		private void OnGUI()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (_searchOpen)
				{
					GUI.depth = -2000;
					if ((int)Event.current.type == 0 && !((Rect)(ref _windowRect)).Contains(Event.current.mousePosition))
					{
						Event.current.Use();
					}
					EnsureStyles();
					_windowRect = GUI.Window(735881, _windowRect, new WindowFunction(DrawWindow), T("Title", "物品查找 / Item Search"), _windowStyle);
				}
				EnsureWorldStyles();
				DrawGuidance();
				DrawMeasure();
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Item Finder GUI failed: " + ex));
			}
		}

		private void DrawWindow(int id)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			Event current = Event.current;
			if ((int)current.type == 4 && ((int)current.keyCode == 13 || (int)current.keyCode == 271))
			{
				current.Use();
				if (_results.Count > 0)
				{
					SelectResult(0);
				}
				return;
			}
			if ((int)current.type == 4 && (int)current.keyCode == 27)
			{
				current.Use();
				CloseSearch();
				return;
			}
			GUILayout.Label(T("WindowHint", "查找附近箱子里的物品"), _labelStyle, Array.Empty<GUILayoutOption>());
			GUI.SetNextControlName("ItemFinderSearch");
			string text = GUILayout.TextField(_query ?? "", _textFieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) });
			if (_focusSearch)
			{
				GUI.FocusControl("ItemFinderSearch");
				_focusSearch = false;
			}
			if (text != _query)
			{
				_query = text;
				Refresh();
			}
			if (GUILayout.Button(T("SearchBtn", "搜索"), _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }))
			{
				BuildIndex();
				Refresh();
			}
			GUILayout.Space(10f);
			GUILayout.Label(T("SuggestHeader", "搜索建议"), _labelStyle, Array.Empty<GUILayoutOption>());
			for (int i = 0; i < _suggestions.Count; i++)
			{
				GUILayout.Label(_suggestions[i], _listStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.Space(8f);
			GUILayout.Label(T("MatchHeader", "附近匹配"), _labelStyle, Array.Empty<GUILayoutOption>());
			_listScroll = GUILayout.BeginScrollView(_listScroll, Array.Empty<GUILayoutOption>());
			for (int j = 0; j < _results.Count; j++)
			{
				Entry entry = _results[j];
				if (GUILayout.Button($"{entry.Display}  –  {entry.English}    ({entry.Distance:0} m)  x{entry.Count}", _listStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(27f) }))
				{
					SelectResult(j);
					return;
				}
			}
			GUILayout.EndScrollView();
			GUILayout.Label((_results.Count == 0 && _query.Length > 0) ? T("Empty", "附近没有找到这个物品") : T("Footer", "回车选第一个结果,Esc 关闭"), _listStyle, Array.Empty<GUILayoutOption>());
		}

		private void SelectResult(int index)
		{
			if (index >= 0 && index < _results.Count)
			{
				Entry entry = _results[index];
				_target = entry.Box;
				_soundTimer = 0f;
				CloseSearch();
				InventoryGui instance = InventoryGui.instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance.Hide();
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer != (Object)null)
				{
					((Character)localPlayer).Message((MessageType)2, string.Format(T("Selected", "已锁定目标:{0}"), entry.Display), 0, (Sprite)null, false);
				}
			}
		}

		private void DrawGuidance()
		{
			//IL_001b: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_target == (Object)null)
			{
				return;
			}
			if (DistanceTo(((Component)_target).transform.position) < 2.5f)
			{
				_target = null;
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer != (Object)null)
				{
					((Character)localPlayer).Message((MessageType)2, T("Arrived", "已到达目标箱子"), 0, (Sprite)null, false);
				}
				return;
			}
			Vector3 val = ((Component)_target).transform.position + Vector3.up * 0.6f;
			DrawWorldMarker(val, T("Target", "箱子"), new Color(0.55f, 1f, 0.6f, 1f));
			DrawCenterArrow(val);
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null && main.WorldToScreenPoint(val).z >= 0f)
			{
				GUI.Label(new Rect((float)Screen.width / 2f - 90f, (float)Screen.height / 2f - 150f, 180f, 26f), string.Format(T("Distance", "{0:F1} 米"), DistanceTo(val)), _labelStyle);
			}
		}

		private void DrawWorldMarker(Vector3 world, string text, Color color)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				Vector3 val = main.WorldToScreenPoint(world);
				if (val.z < 0f)
				{
					val.x = (float)Screen.width - val.x;
					val.y = (float)Screen.height - val.y;
				}
				float num = Mathf.Clamp(val.x, 30f, (float)Screen.width - 30f);
				float num2 = Mathf.Clamp((float)Screen.height - val.y, 30f, (float)Screen.height - 30f);
				float num3 = DistanceTo(world);
				float num4 = 0.75f + 0.25f * Mathf.Sin(_pulse * Mathf.Lerp(6f, 14f, Mathf.Clamp01(1f - num3 / 40f)));
				float num5 = Mathf.Clamp(26f + 140f / Mathf.Max(num3, 2f), 22f, 90f) * _markerScale.Value * num4;
				GUI.color = color;
				GUI.DrawTexture(new Rect(num - num5 / 2f, num2 - num5 / 2f, num5, num5), (Texture)(object)_ring);
				GUI.color = Color.white;
				GUIContent val2 = new GUIContent(text);
				Vector2 val3 = _worldLabelStyle.CalcSize(val2);
				float num6 = val3.x + 18f;
				float num7 = val3.y + 12f;
				GUI.Label(new Rect(num + num5 / 2f + 6f, num2 - num7 / 2f, num6, num7), val2, _worldLabelStyle);
			}
		}

		private void DrawCenterArrow(Vector3 world)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_009d: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				Vector3 val = main.WorldToScreenPoint(world);
				Vector2 val2 = new Vector2(val.x, (float)Screen.height - val.y);
				Vector2 val3 = default(Vector2);
				((Vector2)(ref val3))..ctor((float)Screen.width / 2f, (float)Screen.height / 2f);
				Vector2 val4 = val2 - val3;
				if (!(((Vector2)(ref val4)).sqrMagnitude < 4f))
				{
					float num = DistanceTo(world);
					float num2 = Mathf.Clamp(90f / Mathf.Max(num, 3f), 0.5f, 2.2f) * _markerScale.Value;
					float num3 = Mathf.Atan2(val4.y, val4.x) * 57.29578f + 90f;
					float num4 = 34f * num2;
					GUIUtility.RotateAroundPivot(num3, val3);
					GUI.color = new Color(0.55f, 1f, 0.6f, 0.85f);
					GUI.DrawTexture(new Rect(val3.x - num4 / 2f, val3.y - 90f - num4, num4, num4), (Texture)(object)_arrow);
					GUI.color = Color.white;
					GUIUtility.RotateAroundPivot(0f - num3, val3);
				}
			}
		}

		private void DrawMeasure()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			if (_measureStage == 0)
			{
				return;
			}
			if (_measureStage >= 1)
			{
				DrawWorldMarker(_pointA, T("PointA", "起点"), new Color(1f, 0.86f, 0.42f, 1f));
			}
			if (_measureStage >= 2)
			{
				DrawWorldMarker(_pointB, T("PointB", "终点"), new Color(1f, 0.6f, 0.35f, 1f));
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			string text = "";
			if (_measureStage >= 2)
			{
				text = string.Format(T("MeasureAB", "起点 → 终点:{0:F1} 米"), Vector3.Distance(_pointA, _pointB));
				if (_measurePlayer.Value)
				{
					text = text + "\n" + string.Format(T("MeasureAP", "你 → 起点:{0:F1} 米"), Vector3.Distance(((Component)localPlayer).transform.position, _pointA));
				}
			}
			else if (_measurePlayer.Value)
			{
				text = string.Format(T("MeasureAP", "你 → 起点:{0:F1} 米"), Vector3.Distance(((Component)localPlayer).transform.position, _pointA));
			}
			if (text.Length > 0)
			{
				GUI.Label(new Rect((float)Screen.width / 2f - 170f, 56f, 340f, 54f), text, _labelStyle);
			}
		}

		private void EnsureStyles()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Expected O, but got Unknown
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Expected O, but got Unknown
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Expected O, but got Unknown
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			if (!_stylesReady)
			{
				Color color = default(Color);
				((Color)(ref color))..ctor(0.105f, 0.075f, 0.065f, 1f);
				Color color2 = default(Color);
				((Color)(ref color2))..ctor(0.22f, 0.12f, 0.06f, 1f);
				Color color3 = default(Color);
				((Color)(ref color3))..ctor(0.38f, 0.2f, 0.08f, 1f);
				Color val = default(Color);
				((Color)(ref val))..ctor(1f, 0.91f, 0.7f, 1f);
				_panelTex = MakeTexture(color);
				_fieldTex = MakeTexture(new Color(0.07f, 0.05f, 0.035f, 1f));
				_buttonTex = MakeTexture(color2);
				_buttonHoverTex = MakeTexture(color3);
				_windowStyle = new GUIStyle(GUI.skin.window);
				_windowStyle.fontSize = 20;
				_windowStyle.alignment = (TextAnchor)1;
				_windowStyle.padding = new RectOffset(14, 14, 38, 14);
				SetStyleState(_windowStyle.normal, _panelTex, val);
				SetStyleState(_windowStyle.hover, _panelTex, val);
				SetStyleState(_windowStyle.active, _panelTex, val);
				SetStyleState(_windowStyle.focused, _panelTex, val);
				SetStyleState(_windowStyle.onNormal, _panelTex, val);
				SetStyleState(_windowStyle.onHover, _panelTex, val);
				SetStyleState(_windowStyle.onActive, _panelTex, val);
				SetStyleState(_windowStyle.onFocused, _panelTex, val);
				_labelStyle = new GUIStyle(GUI.skin.label);
				_labelStyle.fontSize = 18;
				_labelStyle.normal.textColor = val;
				_textFieldStyle = new GUIStyle(GUI.skin.textField);
				_textFieldStyle.fontSize = 19;
				_textFieldStyle.normal.textColor = Color.white;
				_textFieldStyle.normal.background = _fieldTex;
				_buttonStyle = new GUIStyle(GUI.skin.button);
				_buttonStyle.fontSize = 18;
				_buttonStyle.fontStyle = (FontStyle)1;
				_buttonStyle.normal.textColor = val;
				_buttonStyle.normal.background = _buttonTex;
				_buttonStyle.hover.textColor = Color.white;
				_buttonStyle.hover.background = _buttonHoverTex;
				_listStyle = new GUIStyle(GUI.skin.label);
				_listStyle.fontSize = 17;
				_listStyle.normal.textColor = Color.white;
				_stylesReady = true;
			}
		}

		private void EnsureWorldStyles()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			if (_worldLabelStyle == null)
			{
				_worldLabelTex = MakeTexture(new Color(0.08f, 0.05f, 0.03f, 0.9f));
				_worldLabelStyle = new GUIStyle(GUI.skin.box);
				_worldLabelStyle.fontSize = 22;
				_worldLabelStyle.fontStyle = (FontStyle)1;
				_worldLabelStyle.alignment = (TextAnchor)4;
				_worldLabelStyle.wordWrap = false;
				_worldLabelStyle.clipping = (TextClipping)0;
				_worldLabelStyle.padding = new RectOffset(8, 8, 4, 4);
				_worldLabelStyle.border = new RectOffset(0, 0, 0, 0);
				_worldLabelStyle.normal.textColor = new Color(1f, 0.82f, 0.12f, 1f);
				_worldLabelStyle.normal.background = _worldLabelTex;
			}
		}

		private static void SetStyleState(GUIStyleState state, Texture2D texture, Color color)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			state.background = texture;
			state.textColor = color;
		}

		private static Texture2D MakeTexture(Color color)
		{
			//IL_0004: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			val.SetPixel(0, 0, color);
			val.Apply();
			return val;
		}

		private void MakeTextures()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			int num = 64;
			_ring = new Texture2D(num, num, (TextureFormat)4, false);
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					float num2 = (float)j - (float)num / 2f + 0.5f;
					float num3 = (float)i - (float)num / 2f + 0.5f;
					float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3) / ((float)num / 2f);
					float num5 = Mathf.Clamp01(1f - Mathf.Abs(num4 - 0.82f) * 6f) * Mathf.Clamp01(1f - num4 * 0.2f);
					_ring.SetPixel(j, i, new Color(1f, 1f, 1f, num5 * 0.9f));
				}
			}
			_ring.Apply();
			int num6 = 48;
			_arrow = new Texture2D(num6, num6, (TextureFormat)4, false);
			for (int k = 0; k < num6; k++)
			{
				for (int l = 0; l < num6; l++)
				{
					float num7 = ((float)l - (float)num6 / 2f) / ((float)num6 / 2f);
					float num8 = ((float)k - (float)num6 / 2f) / ((float)num6 / 2f);
					bool flag = num8 > -0.2f && Mathf.Abs(num7) < (1f - num8) * 0.95f;
					_arrow.SetPixel(l, k, flag ? new Color(1f, 1f, 1f, 1f) : new Color(1f, 1f, 1f, 0f));
				}
			}
			_arrow.Apply();
		}

		private float DistanceTo(Vector3 pos)
		{
			//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)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return 0f;
			}
			return Vector3.Distance(((Component)localPlayer).transform.position, pos);
		}

		private void PlayPing(float dist)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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)
			try
			{
				ObjectDB instance = ObjectDB.instance;
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)instance == (Object)null || (Object)(object)localPlayer == (Object)null)
				{
					return;
				}
				for (int i = 0; i < instance.m_StatusEffects.Count; i++)
				{
					StatusEffect obj = instance.m_StatusEffects[i];
					SE_Finder val = (SE_Finder)(object)((obj is SE_Finder) ? obj : null);
					if (!((Object)(object)val == (Object)null))
					{
						((dist < 15f) ? val.m_pingEffectNear : ((dist < 40f) ? val.m_pingEffectMed : val.m_pingEffectFar)).Create(((Component)localPlayer).transform.position, ((Component)localPlayer).transform.rotation, ((Component)localPlayer).transform, 1f, -1, default(ZDOID));
						break;
					}
				}
			}
			catch
			{
			}
		}

		private void LoadLanguage()
		{
			try
			{
				string text = PlayerPrefs.GetString("language", "English");
				if (string.IsNullOrEmpty(text))
				{
					text = "English";
				}
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
				string path = Path.Combine(directoryName, "ItemFinder." + text + ".yml");
				if (!File.Exists(path))
				{
					path = Path.Combine(directoryName, "ItemFinder.English.yml");
				}
				if (!File.Exists(path))
				{
					return;
				}
				string[] array = File.ReadAllLines(path, Encoding.UTF8);
				for (int i = 0; i < array.Length; i++)
				{
					string text2 = array[i].Trim();
					if (text2.Length == 0 || text2.StartsWith("#"))
					{
						continue;
					}
					int num = text2.IndexOf(':');
					if (num > 0)
					{
						string key = text2.Substring(0, num).Trim();
						string text3 = text2.Substring(num + 1).Trim();
						if (text3.Length >= 2 && text3[0] == '"' && text3[text3.Length - 1] == '"')
						{
							text3 = text3.Substring(1, text3.Length - 2).Replace("\\\"", "\"").Replace("\\n", "\n");
						}
						_lang[key] = text3;
					}
				}
			}
			catch
			{
			}
		}

		private static string T(string key, string fallback)
		{
			if (_lang.TryGetValue(key, out var value) && !string.IsNullOrEmpty(value))
			{
				return value;
			}
			return fallback;
		}

		private static string Localize(string token)
		{
			if (string.IsNullOrEmpty(token))
			{
				return "";
			}
			if (NameCache.TryGetValue(token, out var value))
			{
				return value;
			}
			string text = token;
			try
			{
				if (_localizeMethod == null && _localizeInstance == null)
				{
					ResolveLocalizer();
				}
				if (_localizeMethod != null && _localizeInstance != null)
				{
					string text2 = (string)_localizeMethod.Invoke(_localizeInstance, new object[1] { token });
					if (!string.IsNullOrEmpty(text2))
					{
						text = text2;
					}
				}
			}
			catch
			{
				text = token;
			}
			NameCache[token] = text;
			return text;
		}

		private static void ResolveLocalizer()
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				Type[] types;
				try
				{
					types = assemblies[i].GetTypes();
				}
				catch
				{
					continue;
				}
				for (int j = 0; j < types.Length; j++)
				{
					if (types[j].Name != "Localization")
					{
						continue;
					}
					Type type = types[j];
					PropertyInfo[] properties = type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					for (int k = 0; k < properties.Length; k++)
					{
						if (!(properties[k].PropertyType != type))
						{
							try
							{
								_localizeInstance = properties[k].GetValue(null);
							}
							catch
							{
							}
							if (_localizeInstance != null)
							{
								break;
							}
						}
					}
					_localizeMethod = type.GetMethod("Localize", new Type[1] { typeof(string) });
					return;
				}
			}
		}
	}
	[HarmonyPatch(typeof(TextInput), "IsVisible")]
	internal static class TextInputVisibilityPatch
	{
		private static bool Prefix(ref bool __result)
		{
			if (!Plugin.WindowOpen)
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(ZInput), "GetButtonDown")]
	internal static class ZInputUsePatch
	{
		private static bool Prefix(string name, ref bool __result)
		{
			if (!Plugin.WindowOpen)
			{
				return true;
			}
			if (name == "Use")
			{
				Plugin.NoteSuppressedUse();
				__result = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Hide")]
	internal static class InventoryGuiHideGuard
	{
		private static bool Prefix()
		{
			if (!Plugin.WindowOpen)
			{
				return true;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting() || ((Character)localPlayer).InCutscene())
			{
				return true;
			}
			Plugin.NoteBlockedHide();
			return false;
		}
	}
}