Decompiled source of HoardFinder v1.4.1

plugins/HoardFinder.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HoardFinder.Commands;
using HoardFinder.Config;
using HoardFinder.Drawers;
using HoardFinder.Highlighting;
using HoardFinder.I18n;
using HoardFinder.Search;
using HoardFinder.Storage;
using HoardFinder.UI;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.U2D;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("HoardFinder")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyInformationalVersion("1.4.1+7ecccce0bfea0d6b38fa7b086c9cfcf606849697")]
[assembly: AssemblyProduct("HoardFinder")]
[assembly: AssemblyTitle("HoardFinder")]
[assembly: AssemblyVersion("1.4.1.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 HoardFinder
{
	internal static class Log
	{
		private static ManualLogSource _source;

		private static ConfigEntry<bool> _debug;

		public static bool DebugEnabled
		{
			get
			{
				if (_debug != null)
				{
					return _debug.Value;
				}
				return false;
			}
		}

		public static void Init(ManualLogSource source, ConfigEntry<bool> debug)
		{
			_source = source;
			_debug = debug;
		}

		public static void Info(string message)
		{
			ManualLogSource source = _source;
			if (source != null)
			{
				source.LogInfo((object)message);
			}
		}

		public static void Warning(string message)
		{
			ManualLogSource source = _source;
			if (source != null)
			{
				source.LogWarning((object)message);
			}
		}

		public static void Error(string message)
		{
			ManualLogSource source = _source;
			if (source != null)
			{
				source.LogError((object)message);
			}
		}

		public static void Debug(string message)
		{
			if (DebugEnabled)
			{
				ManualLogSource source = _source;
				if (source != null)
				{
					source.LogInfo((object)("[debug] " + message));
				}
			}
		}
	}
	[BepInPlugin("heido.valheim.hoardfinder", "HoardFinder", "1.4.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInIncompatibility("heido.valheim.betrdrawerfinder")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "heido.valheim.hoardfinder";

		public const string Name = "HoardFinder";

		public const string Version = "1.4.1";

		private const string JotunnGuid = "com.jotunn.jotunn";

		private const string LegacyGuid = "heido.valheim.betrdrawerfinder";

		private readonly List<StorageEntry> _holding = new List<StorageEntry>(64);

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

		private readonly HashSet<int> _storageScratch = new HashSet<int>();

		private readonly HashSet<StorageKind> _enabledKinds = new HashSet<StorageKind>();

		private readonly StorageIndex _storage = new StorageIndex();

		private readonly Toast _toast = new Toast();

		private FinderConfig _config;

		private Harmony _harmony;

		private StorageSearch _search;

		private HighlightManager _highlights;

		private SearchWindow _window;

		private bool _wasInWorld;

		private bool _updateErrorLogged;

		private void Awake()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			ConfigMigration.FromLegacy(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
			_config = new FinderConfig(((BaseUnityPlugin)this).Config);
			Log.Init(((BaseUnityPlugin)this).Logger, _config.EnableDebugLogging);
			if (_config.DetectItemMods.Value)
			{
				ModLookup.Enable();
			}
			ApplySourceSettings();
			((BaseUnityPlugin)this).Config.SettingChanged += OnSettingChanged;
			_harmony = new Harmony("heido.valheim.hoardfinder");
			_harmony.PatchAll(typeof(Plugin).Assembly);
		}

		private void Start()
		{
			//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)
			BetrDrawerApi betrDrawerApi = BetrDrawerApi.TryCreate();
			if (betrDrawerApi != null)
			{
				betrDrawerApi.EnabledKinds = _enabledKinds;
				_storage.Add(betrDrawerApi);
			}
			_storage.Add(new ContainerSource(_enabledKinds));
			_search = new StorageSearch(_storage);
			_highlights = new HighlightManager();
			_window = new SearchWindow(_config, _search, OnResultsSelected, delegate(string text)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				_toast.Show(text, Palette.Gold);
			});
			ConsoleCommands.Register(_storage, _search, _highlights, _config);
			Log.Info("HoardFinder 1.4.1 ready. Hotkey: " + ((object)_config.OpenSearchHotkey.Value/*cast due to .constrained prefix*/).ToString());
		}

		private void OnSettingChanged(object sender, SettingChangedEventArgs e)
		{
			ApplySourceSettings();
			_search?.Invalidate();
		}

		private void ApplySourceSettings()
		{
			_config.FillEnabledKinds(_enabledKinds);
			StorageAccess.Enabled = _config.RespectStorageAccess.Value;
		}

		private void Update()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if (_window == null)
			{
				return;
			}
			try
			{
				InputGuard.Tick();
				TrackWorld();
				if (!_config.Enabled.Value)
				{
					_window.Close();
					_highlights.Clear();
					return;
				}
				_window.Update();
				KeyboardShortcut value = _config.ClearHighlightHotkey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown() && _highlights.Active)
				{
					_highlights.Clear();
					_toast.Show(Tr.T("toast_cleared"), Palette.Gold);
				}
				_highlights.Tick();
			}
			catch (Exception e)
			{
				ReportOnce(e);
			}
		}

		private void TrackWorld()
		{
			bool flag = (Object)(object)Player.m_localPlayer != (Object)null;
			if (flag != _wasInWorld)
			{
				_wasInWorld = flag;
				if (flag)
				{
					Log.Info("Entered world. Loaded " + _storage.LoadedCount + " storages so far.");
					return;
				}
				_window.Close();
				_highlights.Clear();
				_search.ResetSession();
				ItemNames.Clear();
				Log.Debug("Left world; caches cleared.");
			}
		}

		private void OnGUI()
		{
			if (_window == null || !_config.Enabled.Value)
			{
				return;
			}
			try
			{
				_highlights.OnGUI();
				_window.OnGUI();
				_toast.OnGUI();
			}
			catch (Exception e)
			{
				ReportOnce(e);
			}
		}

		private void OnResultsSelected(List<SearchResult> results, SearchOptions options)
		{
			//IL_0082: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			_chosenItems.Clear();
			foreach (SearchResult result in results)
			{
				_chosenItems.Add(result.Name.Prefab);
			}
			float value = _config.SearchRadius.Value;
			_search.CollectHolding(_chosenItems, ((Component)localPlayer).transform.position, value, options, _holding);
			_highlights.Show(_holding, _config.HighlightDuration.Value);
			int num = StorageIndex.CountStorages(_holding, _storageScratch);
			string text = ((num == 0) ? Tr.T("toast_none") : Tr.F("toast_highlight", num));
			_toast.Show(text, (num == 0) ? Palette.ForIndex(3) : Palette.Gold);
		}

		private void ReportOnce(Exception e)
		{
			if (!_updateErrorLogged)
			{
				_updateErrorLogged = true;
				Log.Error("Unexpected error; further errors are suppressed. Closing the window. " + e);
				_window?.Close();
				_highlights?.Clear();
			}
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.SettingChanged -= OnSettingChanged;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			_window?.Dispose();
			_highlights?.Dispose();
			_toast.Dispose();
		}
	}
}
namespace HoardFinder.UI
{
	internal static class Anim
	{
		public static float Now => Time.unscaledTime;

		public static float Progress(float start, float duration)
		{
			if (!(duration <= 0f))
			{
				return Mathf.Clamp01((Now - start) / duration);
			}
			return 1f;
		}

		public static float EaseOutCubic(float t)
		{
			float num = 1f - t;
			return 1f - num * num * num;
		}

		public static float EaseOutBack(float t)
		{
			float num = t - 1f;
			return 1f + 2.70158f * num * num * num + 1.70158f * num * num;
		}

		public static float Approach(float current, float target, float sharpness)
		{
			return Mathf.Lerp(current, target, 1f - Mathf.Exp((0f - sharpness) * Time.unscaledDeltaTime));
		}

		public static Matrix4x4 ScaleAround(Matrix4x4 baseMatrix, Vector2 pivot, float scale)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 val = Matrix4x4.Translate(new Vector3(pivot.x, pivot.y, 0f));
			Matrix4x4 val2 = Matrix4x4.Translate(new Vector3(0f - pivot.x, 0f - pivot.y, 0f));
			return baseMatrix * val * Matrix4x4.Scale(new Vector3(scale, scale, 1f)) * val2;
		}
	}
	internal static class GameFonts
	{
		private static bool _resolved;

		private static Font _regular;

		private static Font _bold;

		public static Font Regular
		{
			get
			{
				Resolve();
				if (!Tr.UsesLatin1)
				{
					return null;
				}
				return _regular;
			}
		}

		public static Font Bold
		{
			get
			{
				Resolve();
				if (!Tr.UsesLatin1)
				{
					return null;
				}
				return _bold ?? _regular;
			}
		}

		private static void Resolve()
		{
			if (_resolved)
			{
				return;
			}
			_resolved = true;
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			foreach (Font val in array)
			{
				if (((Object)val).name == "AveriaSerifLibre-Regular")
				{
					_regular = val;
				}
				else if (((Object)val).name == "AveriaSerifLibre-Bold")
				{
					_bold = val;
				}
			}
			Log.Debug("Game font: " + (((Object)(object)_regular != (Object)null) ? ((Object)_regular).name : "not found, using IMGUI default"));
		}
	}
	internal static class GameState
	{
		public static bool InWorld()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && !((Character)localPlayer).IsDead() && !((Character)localPlayer).IsTeleporting())
			{
				return (Object)(object)ZNetScene.instance != (Object)null;
			}
			return false;
		}

		public static bool CanOpenWindow()
		{
			if (InWorld() && ((Object)(object)Chat.instance == (Object)null || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsVisible() && !InventoryGui.IsVisible() && !StoreGui.IsVisible() && !Minimap.IsOpen() && !Minimap.InTextInput() && !Hud.IsPieceSelectionVisible() && !Hud.InRadial())
			{
				if (!((Object)(object)TextViewer.instance == (Object)null))
				{
					return !TextViewer.instance.IsVisible();
				}
				return true;
			}
			return false;
		}

		public static bool MustCloseWindow()
		{
			if (InWorld() && !Console.IsVisible() && !InventoryGui.IsVisible())
			{
				return Minimap.IsOpen();
			}
			return true;
		}
	}
	internal sealed class HotkeyCapture
	{
		private static readonly HashSet<KeyCode> ModifierKeys = new HashSet<KeyCode>
		{
			(KeyCode)306,
			(KeyCode)305,
			(KeyCode)304,
			(KeyCode)303,
			(KeyCode)308,
			(KeyCode)307,
			(KeyCode)310,
			(KeyCode)309,
			(KeyCode)313
		};

		private readonly ConfigEntry<KeyboardShortcut> _entry;

		public bool Active { get; private set; }

		public float StartedAt { get; private set; }

		public HotkeyCapture(ConfigEntry<KeyboardShortcut> entry)
		{
			_entry = entry;
		}

		public void Begin()
		{
			Active = true;
			StartedAt = Anim.Now;
		}

		public void Cancel()
		{
			Active = false;
		}

		public unsafe KeyboardShortcut? Handle(Event e)
		{
			//IL_0001: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			//IL_006e: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			if ((int)e.keyCode == 0 || ModifierKeys.Contains(e.keyCode) || ReservedWithoutModifier(e))
			{
				return null;
			}
			Active = false;
			if ((int)e.keyCode == 27)
			{
				return null;
			}
			KeyboardShortcut val = (((int)e.keyCode == 8) ? ((KeyboardShortcut)((ConfigEntryBase)_entry).DefaultValue) : new KeyboardShortcut(e.keyCode, Modifiers(e)));
			_entry.Value = val;
			KeyboardShortcut val2 = val;
			Log.Info("Search hotkey set to " + ((object)(*(KeyboardShortcut*)(&val2))/*cast due to .constrained prefix*/).ToString() + ".");
			return val;
		}

		private static bool ReservedWithoutModifier(Event e)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			bool num = !e.control && !e.alt && !e.shift;
			KeyCode keyCode = e.keyCode;
			if (num)
			{
				if ((int)keyCode != 13 && (int)keyCode != 271)
				{
					return (int)keyCode == 9;
				}
				return true;
			}
			return false;
		}

		private static KeyCode[] Modifiers(Event e)
		{
			List<KeyCode> list = new List<KeyCode>(3);
			if (e.control)
			{
				list.Add((KeyCode)306);
			}
			if (e.alt)
			{
				list.Add((KeyCode)308);
			}
			if (e.shift)
			{
				list.Add((KeyCode)304);
			}
			return list.ToArray();
		}

		public static string Format(KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0)
			{
				return "-";
			}
			StringBuilder stringBuilder = new StringBuilder(24);
			foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers)
			{
				stringBuilder.Append(KeyName(modifier)).Append(" + ");
			}
			return stringBuilder.Append(KeyName(((KeyboardShortcut)(ref shortcut)).MainKey)).ToString();
		}

		private unsafe static string KeyName(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected I4, but got Unknown
			switch (key - 303)
			{
			case 2:
			case 3:
				return "Ctrl";
			case 0:
			case 1:
				return "Shift";
			case 4:
			case 5:
				return "Alt";
			default:
			{
				string text = ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
				if (text.StartsWith("Alpha") && text.Length == 6)
				{
					return text.Substring(5);
				}
				if (!text.StartsWith("Keypad"))
				{
					return text;
				}
				return "Num " + text.Substring(6);
			}
			}
		}
	}
	internal static class InputGuard
	{
		private const int MinFrames = 2;

		private const float MaxSeconds = 1f;

		private static int _minFrame;

		private static float _deadline;

		public static bool Active { get; private set; }

		public static void Engage()
		{
			Active = true;
			_minFrame = Time.frameCount + 2;
			_deadline = Time.unscaledTime + 1f;
			ZInput.ResetAllButtonStates();
		}

		public static void Tick()
		{
			if (Active && (Time.unscaledTime > _deadline || (Time.frameCount > _minFrame && !ClosingInputHeld())))
			{
				Active = false;
				ZInput.ResetAllButtonStates();
			}
		}

		private static bool ClosingInputHeld()
		{
			IInputSystem current = UnityInput.Current;
			if (!current.GetMouseButton(0) && !current.GetMouseButton(1) && !current.GetMouseButton(2) && !current.GetKey((KeyCode)13) && !current.GetKey((KeyCode)271))
			{
				return current.GetKey((KeyCode)27);
			}
			return true;
		}
	}
	internal static class NineSlice
	{
		private static readonly float[] Xs = new float[4];

		private static readonly float[] Ys = new float[4];

		private static readonly float[] Us = new float[4];

		private static readonly float[] Vs = new float[4];

		public static void Draw(Sprite sprite, Rect uv, Rect rect, float borderScale)
		{
			//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_001d: 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_0054: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: 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)
			Texture2D texture = sprite.texture;
			Vector4 border = sprite.border;
			float num = ((Texture)texture).width;
			float num2 = ((Texture)texture).height;
			float num3 = Mathf.Min(border.x * borderScale, ((Rect)(ref rect)).width / 2f);
			float num4 = Mathf.Min(border.z * borderScale, ((Rect)(ref rect)).width / 2f);
			float num5 = Mathf.Min(border.w * borderScale, ((Rect)(ref rect)).height / 2f);
			float num6 = Mathf.Min(border.y * borderScale, ((Rect)(ref rect)).height / 2f);
			Set(Xs, ((Rect)(ref rect)).x, ((Rect)(ref rect)).x + num3, ((Rect)(ref rect)).xMax - num4, ((Rect)(ref rect)).xMax);
			Set(Ys, ((Rect)(ref rect)).y, ((Rect)(ref rect)).y + num5, ((Rect)(ref rect)).yMax - num6, ((Rect)(ref rect)).yMax);
			Set(Us, ((Rect)(ref uv)).xMin, ((Rect)(ref uv)).xMin + border.x / num, ((Rect)(ref uv)).xMax - border.z / num, ((Rect)(ref uv)).xMax);
			Set(Vs, ((Rect)(ref uv)).yMax, ((Rect)(ref uv)).yMax - border.w / num2, ((Rect)(ref uv)).yMin + border.y / num2, ((Rect)(ref uv)).yMin);
			DrawPatches(texture);
		}

		private static void DrawPatches(Texture2D texture)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			Rect val = default(Rect);
			Rect val2 = default(Rect);
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					((Rect)(ref val))..ctor(Xs[j], Ys[i], Xs[j + 1] - Xs[j], Ys[i + 1] - Ys[i]);
					if (!(((Rect)(ref val)).width <= 0f) && !(((Rect)(ref val)).height <= 0f))
					{
						((Rect)(ref val2))..ctor(Us[j], Vs[i + 1], Us[j + 1] - Us[j], Vs[i] - Vs[i + 1]);
						GUI.DrawTextureWithTexCoords(val, (Texture)(object)texture, val2);
					}
				}
			}
		}

		private static void Set(float[] target, float a, float b, float c, float d)
		{
			target[0] = a;
			target[1] = b;
			target[2] = c;
			target[3] = d;
		}

		public static Rect UvRect(Sprite sprite)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			Vector2[] uv = sprite.uv;
			if (uv == null || uv.Length == 0)
			{
				return new Rect(0f, 0f, 1f, 1f);
			}
			Vector2 val = uv[0];
			Vector2 val2 = uv[0];
			for (int i = 1; i < uv.Length; i++)
			{
				val = Vector2.Min(val, uv[i]);
				val2 = Vector2.Max(val2, uv[i]);
			}
			return Rect.MinMaxRect(val.x, val.y, val2.x, val2.y);
		}
	}
	internal static class OptionCycling
	{
		public static T Step<T>(T value, int step) where T : Enum
		{
			int length = Enum.GetValues(typeof(T)).Length;
			int value2 = ((Convert.ToInt32(value) + step) % length + length) % length;
			return (T)Enum.ToObject(typeof(T), value2);
		}

		public static string StepMod(List<string> mods, string current, int step)
		{
			int num = ((current == null) ? (-1) : mods.IndexOf(current)) + step;
			if (num < -1)
			{
				num = mods.Count - 1;
			}
			if (num >= 0 && num < mods.Count)
			{
				return mods[num];
			}
			return null;
		}
	}
	internal sealed class ResultRows
	{
		private const float IconSize = 22f;

		private const float TotalColumn = 90f;

		private const float DrawersColumn = 70f;

		private const float DistanceColumn = 60f;

		private const float GlideSharpness = 24f;

		private const float FlashSeconds = 0.16f;

		private readonly SearchWindowStyles _styles;

		private readonly float _rowHeight;

		private readonly Dictionary<string, float> _tagWidths = new Dictionary<string, float>();

		private readonly GUIContent _measure = new GUIContent();

		private int _tagVersion = -1;

		private float _selectionY;

		private int _glideFrame = -1;

		public ResultRows(SearchWindowStyles styles, float rowHeight)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			_styles = styles;
			_rowHeight = rowHeight;
		}

		public void DrawColumns(Rect rect)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0068: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(((Rect)(ref rect)).x + 22f + 16f, ((Rect)(ref rect)).y, 220f, ((Rect)(ref rect)).height), Tr.T("col_item"), _styles.Column);
			GUI.Label(ColumnRect(rect, 2), Tr.T("col_places"), _styles.ColumnRight);
			GUI.Label(ColumnRect(rect, 1), Tr.T("col_total"), _styles.ColumnRight);
			GUI.Label(ColumnRect(rect, 0), Tr.T("col_near"), _styles.ColumnRight);
		}

		private static Rect ColumnRect(Rect row, int fromRight)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref row)).xMax - 8f;
			if (fromRight >= 1)
			{
				num -= 60f;
			}
			if (fromRight >= 2)
			{
				num -= 90f;
			}
			float num2 = fromRight switch
			{
				1 => 90f, 
				0 => 60f, 
				_ => 70f, 
			};
			return new Rect(num - num2, ((Rect)(ref row)).y, num2, ((Rect)(ref row)).height);
		}

		public void DrawSelection(SearchWindow window, Rect list)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_00a9: 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)
			int num = window.Selected - window.Scroll;
			if (num >= 0 && num < 12 && (int)Event.current.type == 7)
			{
				float num2 = (float)num * _rowHeight;
				if (_glideFrame != Time.frameCount)
				{
					bool flag = Mathf.Abs(_selectionY - num2) > _rowHeight * 4f;
					_selectionY = (flag ? num2 : Anim.Approach(_selectionY, num2, 24f));
					_glideFrame = Time.frameCount;
				}
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(((Rect)(ref list)).x, ((Rect)(ref list)).y + _selectionY, ((Rect)(ref list)).width, _rowHeight);
				GUI.DrawTexture(val, (Texture)(object)_styles.Selection);
				GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, 3f, ((Rect)(ref val)).height), (Texture)(object)_styles.Accent);
			}
		}

		public bool Draw(SearchWindow window, SearchResult result, Rect row, int index, bool interactive)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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)
			Event current = Event.current;
			bool flag = interactive && ((Rect)(ref row)).Contains(current.mousePosition);
			if ((int)current.type == 7)
			{
				DrawBackground(window, row, index, flag);
				float num = ((Rect)(ref row)).y + (_rowHeight - 22f) / 2f;
				DrawIcon(result.Name.Icon, new Rect(((Rect)(ref row)).x + 8f, num, 22f, 22f));
			}
			if (flag && (int)current.type == 0 && current.button == 0)
			{
				bool shift = current.shift;
				current.Use();
				window.Choose(index, shift);
				return true;
			}
			DrawName(window, result, row, index);
			GUI.Label(ColumnRect(row, 2), result.PlacesText, _styles.Muted);
			GUI.Label(ColumnRect(row, 1), result.TotalText, _styles.Number);
			GUI.Label(ColumnRect(row, 0), result.ClosestText, _styles.Muted);
			return false;
		}

		private void DrawName(SearchWindow window, SearchResult result, Rect row, int index)
		{
			//IL_0048: 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)
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref row)).x + 22f + 16f, ((Rect)(ref row)).y, ((Rect)(ref row)).width - 22f - 250f, ((Rect)(ref row)).height);
			if (!result.Name.IsVanilla)
			{
				GUI.Label(val, result.Name.Mod, _styles.ModTag);
				((Rect)(ref val)).width = ((Rect)(ref val)).width - Mathf.Min(((Rect)(ref val)).width * 0.45f, TagWidth(result.Name.Mod) + 8f);
			}
			GUIStyle val2 = ((index == window.Selected) ? _styles.NameSelected : _styles.Name);
			GUI.Label(val, result.Name.Display, val2);
		}

		private float TagWidth(string mod)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (_tagVersion != Tr.Version)
			{
				_tagVersion = Tr.Version;
				_tagWidths.Clear();
			}
			if (!_tagWidths.TryGetValue(mod, out var value))
			{
				_measure.text = mod;
				value = _styles.ModTag.CalcSize(_measure).x;
				_tagWidths[mod] = value;
			}
			return value;
		}

		private void DrawBackground(SearchWindow window, Rect row, int index, bool hover)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_005f: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!SearchWindow.IsOpen && (window.ChosenIndex == index || window.ChosenIndex == int.MaxValue))
			{
				Color color = GUI.color;
				float num = 1f - Anim.Progress(window.ClosedAt, 0.16f);
				GUI.color = new Color(color.r, color.g, color.b, num);
				GUI.DrawTexture(row, (Texture)(object)_styles.Flash);
				GUI.color = color;
			}
			else if (hover && index != window.Selected)
			{
				GUI.DrawTexture(row, (Texture)(object)_styles.Hover);
			}
		}

		private static void DrawIcon(Sprite icon, Rect rect)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			if (!((Object)(object)icon == (Object)null) && !((Object)(object)icon.texture == (Object)null))
			{
				Texture2D texture = icon.texture;
				Rect textureRect = icon.textureRect;
				float num = ((Texture)texture).width;
				float num2 = ((Texture)texture).height;
				GUI.DrawTextureWithTexCoords(rect, (Texture)(object)texture, new Rect(((Rect)(ref textureRect)).x / num, ((Rect)(ref textureRect)).y / num2, ((Rect)(ref textureRect)).width / num, ((Rect)(ref textureRect)).height / num2));
			}
		}

		public void DrawScrollbar(SearchWindow window, Rect list)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			int count = window.Results.Count;
			int num = 12;
			if (count > num && (int)Event.current.type == 7)
			{
				float num2 = Mathf.Max(18f, ((Rect)(ref list)).height * (float)num / (float)count);
				float num3 = ((Rect)(ref list)).y + (((Rect)(ref list)).height - num2) * (float)window.Scroll / (float)(count - num);
				GUI.DrawTexture(new Rect(((Rect)(ref list)).xMax + 4f, ((Rect)(ref list)).y, 3f, ((Rect)(ref list)).height), (Texture)(object)_styles.Track);
				GUI.DrawTexture(new Rect(((Rect)(ref list)).xMax + 4f, num3, 3f, num2), (Texture)(object)_styles.Accent);
			}
		}
	}
	internal sealed class SearchWindow
	{
		public const float OpenDuration = 0.2f;

		public const float CloseDuration = 0.16f;

		private const float RefreshInterval = 1f;

		private readonly FinderConfig _config;

		private readonly StorageSearch _search;

		private readonly Action<List<SearchResult>, SearchOptions> _onSelect;

		private readonly Action<string> _notify;

		private readonly SearchWindowView _view = new SearchWindowView();

		private readonly List<SearchResult> _chosen = new List<SearchResult>(32);

		private string _searchedQuery;

		private int _openedFrame;

		private float _nextRefresh;

		public string Query = string.Empty;

		public List<SearchResult> Results = new List<SearchResult>();

		public int Selected;

		public int Scroll;

		public bool SelectAllPending;

		public string Status = string.Empty;

		public string RadiusText = string.Empty;

		public string HotkeyText = string.Empty;

		public float OpenedAt = float.NegativeInfinity;

		public float ClosedAt = float.NegativeInfinity;

		public float ResultsChangedAt = float.NegativeInfinity;

		public int ChosenIndex = -1;

		public static bool IsOpen { get; private set; }

		public static bool InputLocked
		{
			get
			{
				if (!IsOpen)
				{
					return InputGuard.Active;
				}
				return true;
			}
		}

		public HotkeyCapture Capture { get; }

		public SearchOptions Options { get; } = new SearchOptions();

		public bool Visible
		{
			get
			{
				if (!IsOpen)
				{
					return Anim.Now - ClosedAt < 0.16f;
				}
				return true;
			}
		}

		public SearchWindow(FinderConfig config, StorageSearch search, Action<List<SearchResult>, SearchOptions> onSelect, Action<string> notify)
		{
			_config = config;
			_search = search;
			_onSelect = onSelect;
			_notify = notify;
			Capture = new HotkeyCapture(config.OpenSearchHotkey);
			Options.Sort = config.Sort.Value;
			Options.Type = config.TypeFilter.Value;
			Options.Source = config.SourceFilter.Value;
		}

		public void Update()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!Capture.Active)
			{
				KeyboardShortcut value = _config.OpenSearchHotkey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					if (IsOpen)
					{
						Close();
						return;
					}
					if (GameState.CanOpenWindow())
					{
						Open();
					}
				}
			}
			if (IsOpen)
			{
				if (GameState.MustCloseWindow())
				{
					Close();
				}
				else if (Query != _searchedQuery || Time.unscaledTime >= _nextRefresh)
				{
					Refresh();
				}
			}
		}

		private void Open()
		{
			IsOpen = true;
			Selected = 0;
			Scroll = 0;
			ChosenIndex = -1;
			SelectAllPending = Query.Length > 0;
			_openedFrame = Time.frameCount;
			OpenedAt = Anim.Now;
			ResultsChangedAt = Anim.Now + 0.1f;
			_search.Invalidate();
			_view.OnOpened();
			Refresh();
			Log.Info("Loaded " + _search.LastStorageCount + " nearby storages.");
		}

		public void Close()
		{
			if (IsOpen)
			{
				IsOpen = false;
				InputGuard.Engage();
				Capture.Cancel();
				ClosedAt = Anim.Now;
				GUIUtility.keyboardControl = 0;
			}
		}

		private void Refresh()
		{
			//IL_0063: 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)
			_nextRefresh = Time.unscaledTime + 1f;
			bool flag = Query != _searchedQuery;
			_searchedQuery = Query;
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				float value = _config.SearchRadius.Value;
				Results = _search.Search(Query, ((Component)localPlayer).transform.position, value, _config.MaxSearchResults.Value, Options);
				RadiusText = Mathf.RoundToInt(value) + "m";
				Status = Tr.F("status", Results.Count, _search.LastStorageCount, RadiusText);
				HotkeyText = HotkeyCapture.Format(_config.OpenSearchHotkey.Value);
				if (flag)
				{
					Selected = 0;
					Scroll = 0;
					ResultsChangedAt = Mathf.Max(ResultsChangedAt, Anim.Now);
					Log.Debug("Search \"" + Query + "\": " + Results.Count + " results / " + _search.LastStorageCount + " storages.");
				}
				Selected = Mathf.Clamp(Selected, 0, Mathf.Max(0, Results.Count - 1));
			}
		}

		public void OnGUI()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			if (!IsOpen)
			{
				if (Visible)
				{
					_view.Draw(this, interactive: false);
				}
				return;
			}
			Event current = Event.current;
			if ((int)current.type == 4 && ConsumeKey(current))
			{
				current.Use();
			}
			else
			{
				_view.Draw(this, interactive: true);
			}
		}

		private bool ConsumeKey(Event e)
		{
			if (Time.frameCount == _openedFrame || IsHotkeyCharacter(e))
			{
				return true;
			}
			if (Capture.Active)
			{
				OnCaptured(Capture.Handle(e));
				return true;
			}
			if (!IsHotkeyEvent(e))
			{
				return HandleKey(e);
			}
			return true;
		}

		private void OnCaptured(KeyboardShortcut? saved)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if (saved.HasValue)
			{
				HotkeyText = HotkeyCapture.Format(saved.Value);
				_notify(Tr.F("hotkey_saved", HotkeyText));
			}
		}

		private bool IsHotkeyCharacter(Event e)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected I4, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if (Time.frameCount > _openedFrame + 3)
			{
				return false;
			}
			KeyboardShortcut value = _config.OpenSearchHotkey.Value;
			int num = (int)((KeyboardShortcut)(ref value)).MainKey;
			bool flag = num >= 32 && num < 127;
			if ((int)e.keyCode != num)
			{
				if (flag)
				{
					return char.ToLowerInvariant(e.character) == (ushort)num;
				}
				return false;
			}
			return true;
		}

		private bool IsHotkeyEvent(Event e)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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)
			KeyboardShortcut value = _config.OpenSearchHotkey.Value;
			if (e.keyCode == ((KeyboardShortcut)(ref value)).MainKey)
			{
				if (!e.control && !e.alt)
				{
					return e.command;
				}
				return true;
			}
			return false;
		}

		public void Move(int delta)
		{
			Selected = Mathf.Clamp(Selected + delta, 0, Mathf.Max(0, Results.Count - 1));
			if (Selected < Scroll)
			{
				Scroll = Selected;
			}
			else if (Selected >= Scroll + 12)
			{
				Scroll = Selected - 12 + 1;
			}
		}

		public void ScrollBy(int delta)
		{
			int num = Mathf.Max(0, Results.Count - 12);
			Scroll = Mathf.Clamp(Scroll + delta, 0, num);
		}

		public void Choose(int index, bool all)
		{
			if (index >= 0 && index < Results.Count)
			{
				_chosen.Clear();
				if (all)
				{
					_chosen.AddRange(Results);
				}
				else
				{
					_chosen.Add(Results[index]);
				}
				Close();
				ChosenIndex = (all ? int.MaxValue : index);
				_onSelect(_chosen, Options);
			}
		}

		public void Cycle(ToolbarAction action, int step)
		{
			switch (action)
			{
			case ToolbarAction.Sort:
				_config.Sort.Value = (Options.Sort = OptionCycling.Step(Options.Sort, step));
				break;
			case ToolbarAction.Type:
				_config.TypeFilter.Value = (Options.Type = OptionCycling.Step(Options.Type, step));
				break;
			case ToolbarAction.Source:
				_config.SourceFilter.Value = (Options.Source = OptionCycling.Step(Options.Source, step));
				break;
			case ToolbarAction.Mod:
				Options.Mod = OptionCycling.StepMod(_search.Mods, Options.Mod, step);
				break;
			}
			_searchedQuery = null;
			Refresh();
		}

		public void Dispose()
		{
			Close();
			ClosedAt = float.NegativeInfinity;
			_view.Dispose();
		}

		private bool HandleKey(Event e)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_0020: 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_003c: Expected I4, but got Unknown
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			KeyCode keyCode = e.keyCode;
			if ((int)keyCode <= 27)
			{
				if ((int)keyCode == 9)
				{
					Cycle(ToolbarAction.Sort, (!e.shift) ? 1 : (-1));
					return true;
				}
				if ((int)keyCode == 13)
				{
					goto IL_007c;
				}
				if ((int)keyCode == 27)
				{
					Close();
					return true;
				}
			}
			else
			{
				switch (keyCode - 271)
				{
				case 2:
					Move(-1);
					return true;
				case 3:
					Move(1);
					return true;
				case 0:
					goto IL_007c;
				case 1:
					goto IL_00a5;
				}
				if ((int)keyCode == 280)
				{
					Move(-12);
					return true;
				}
				if ((int)keyCode == 281)
				{
					Move(12);
					return true;
				}
			}
			goto IL_00a5;
			IL_007c:
			Choose(Selected, e.shift);
			return true;
			IL_00a5:
			return false;
		}
	}
	internal sealed class SearchWindowStyles
	{
		private static readonly Color Text = new Color(0.94f, 0.9f, 0.8f, 1f);

		private static readonly Color Dim = new Color(0.8f, 0.74f, 0.62f, 1f);

		public static readonly Color Orange = new Color(1f, 0.64f, 0.24f, 1f);

		private Texture2D _inputBackground;

		private int _stylesVersion = -1;

		public Texture2D Background { get; private set; }

		public Texture2D Border { get; private set; }

		public Texture2D Accent { get; private set; }

		public Texture2D Selection { get; private set; }

		public Texture2D Hover { get; private set; }

		public Texture2D Track { get; private set; }

		public Texture2D Flash { get; private set; }

		public Texture2D Scrim { get; private set; }

		public GUIStyle Title { get; private set; }

		public GUIStyle Status { get; private set; }

		public GUIStyle Input { get; private set; }

		public GUIStyle Placeholder { get; private set; }

		public GUIStyle Column { get; private set; }

		public GUIStyle ColumnRight { get; private set; }

		public GUIStyle Name { get; private set; }

		public GUIStyle NameSelected { get; private set; }

		public GUIStyle Number { get; private set; }

		public GUIStyle Muted { get; private set; }

		public GUIStyle Empty { get; private set; }

		public GUIStyle Footer { get; private set; }

		public GUIStyle Hotkey { get; private set; }

		public GUIStyle HotkeyHover { get; private set; }

		public GUIStyle HotkeyActive { get; private set; }

		public GUIStyle ButtonLabel { get; private set; }

		public GUIStyle ButtonActive { get; private set; }

		public GUIStyle ModTag { get; private set; }

		public void Ensure()
		{
			Tr.Refresh();
			if ((Object)(object)Background == (Object)null)
			{
				CreateTextures();
				Title = null;
			}
			if (Title == null || _stylesVersion != Tr.Version)
			{
				_stylesVersion = Tr.Version;
				CreateStyles();
			}
		}

		private void CreateTextures()
		{
			//IL_0015: 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)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			Background = Solid(new Color(0.05f, 0.04f, 0.03f, 0.96f));
			Border = Solid(new Color(0.55f, 0.42f, 0.18f, 0.9f));
			Accent = Solid(Orange);
			Selection = Solid(new Color(1f, 0.64f, 0.24f, 0.2f));
			Hover = Solid(new Color(1f, 1f, 1f, 0.06f));
			Track = Solid(new Color(1f, 1f, 1f, 0.08f));
			Flash = Solid(new Color(1f, 0.85f, 0.4f, 0.55f));
			_inputBackground = Solid(new Color(0f, 0f, 0f, 0.68f));
			Scrim = Solid(new Color(0.035f, 0.025f, 0.015f, 0.9f));
		}

		private void CreateStyles()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0081: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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)
			Font regular = GameFonts.Regular;
			Font bold = GameFonts.Bold;
			Title = Label(bold, 20, (TextAnchor)3, Orange);
			Status = Label(regular, 13, (TextAnchor)5, Dim);
			Placeholder = Label(regular, 16, (TextAnchor)3, new Color(Dim.r, Dim.g, Dim.b, 0.7f));
			Placeholder.padding = new RectOffset(10, 10, 0, 0);
			Column = Label(bold, 12, (TextAnchor)3, Dim);
			ColumnRight = Label(bold, 12, (TextAnchor)5, Dim);
			Name = Label(regular, 16, (TextAnchor)3, Text);
			NameSelected = Label(bold, 16, (TextAnchor)3, Orange);
			Number = Label(bold, 16, (TextAnchor)5, Text);
			Muted = Label(regular, 15, (TextAnchor)5, Dim);
			Empty = Label(regular, 15, (TextAnchor)4, Dim);
			Footer = Label(regular, 13, (TextAnchor)4, Dim);
			Hotkey = Label(regular, 12, (TextAnchor)4, new Color(0.8f, 0.7f, 0.45f, 1f));
			HotkeyHover = Label(bold, 12, (TextAnchor)4, Orange);
			HotkeyActive = Label(bold, 13, (TextAnchor)4, Orange);
			ButtonLabel = Label(regular, 13, (TextAnchor)4, Text);
			ButtonActive = Label(bold, 13, (TextAnchor)4, Orange);
			ModTag = Label(regular, 12, (TextAnchor)5, Dim);
			Input = InputStyle(regular);
		}

		private GUIStyle InputStyle(Font font)
		{
			//IL_000a: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0037: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.textField)
			{
				font = font,
				fontSize = 17,
				alignment = (TextAnchor)3,
				padding = new RectOffset(10, 10, 4, 4)
			};
			GUIStyleState[] array = (GUIStyleState[])(object)new GUIStyleState[4] { val.normal, val.focused, val.hover, val.active };
			foreach (GUIStyleState obj in array)
			{
				obj.background = _inputBackground;
				obj.textColor = Text;
			}
			return val;
		}

		private static GUIStyle Label(Font font, int size, TextAnchor anchor, Color color)
		{
			//IL_000a: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				font = font,
				fontSize = size,
				alignment = anchor,
				wordWrap = false,
				clipping = (TextClipping)1
			};
			val.normal.textColor = color;
			return val;
		}

		public static Texture2D Solid(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_0014: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				name = "HoardFinder_UI"
			};
			val.SetPixel(0, 0, color);
			val.Apply();
			return val;
		}

		public void Dispose()
		{
			Texture2D[] array = (Texture2D[])(object)new Texture2D[9] { Background, Border, Accent, Selection, Hover, Track, Flash, Scrim, _inputBackground };
			foreach (Texture2D val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
			Background = null;
			Title = null;
		}
	}
	internal sealed class SearchWindowView
	{
		public const int VisibleRows = 12;

		private const string QueryControl = "HoardFinderQuery";

		private const float Width = 600f;

		private const float Pad = 24f;

		private const float ToolbarHeight = 28f;

		private const float RowHeight = 28f;

		private const float RowStagger = 0.018f;

		private const float RowFade = 0.16f;

		private readonly SearchWindowStyles _styles = new SearchWindowStyles();

		private readonly ValheimSkin _skin = new ValheimSkin();

		private readonly ResultRows _rows;

		private readonly Toolbar _toolbar;

		private readonly GUIContent _content = new GUIContent();

		private string _hints;

		private int _hintsVersion = -1;

		public SearchWindowView()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			_rows = new ResultRows(_styles, 28f);
			_toolbar = new Toolbar(_styles, _skin);
		}

		public void OnOpened()
		{
			_skin.Resolve();
		}

		public void Draw(SearchWindow window, bool interactive)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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)
			_styles.Ensure();
			float num = Mathf.Max(1f, (float)Screen.height / 1080f);
			int num2 = Mathf.Clamp(window.Results.Count, 1, 12);
			float num3 = 146f + (float)num2 * 28f + 52f + 24f;
			Transition(window, out var alpha, out var offset, out var zoom);
			Rect frame = default(Rect);
			((Rect)(ref frame))..ctor(((float)Screen.width / num - 600f) / 2f, 90f + offset, 600f, num3);
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			GUI.matrix = Anim.ScaleAround(Matrix4x4.Scale(new Vector3(num, num, 1f)), ((Rect)(ref frame)).center, zoom);
			GUI.color = new Color(1f, 1f, 1f, alpha);
			DrawContent(window, frame, num2, interactive, alpha);
			GUI.color = color;
			GUI.matrix = matrix;
		}

		private static void Transition(SearchWindow window, out float alpha, out float offset, out float zoom)
		{
			if (SearchWindow.IsOpen)
			{
				float num = (alpha = Anim.EaseOutCubic(Anim.Progress(window.OpenedAt, 0.2f)));
				offset = (num - 1f) * 16f;
				zoom = 0.96f + 0.04f * num;
			}
			else
			{
				float num2 = Anim.EaseOutCubic(Anim.Progress(window.ClosedAt, 0.16f));
				alpha = 1f - num2;
				offset = -10f * num2;
				zoom = 1f - 0.03f * num2;
			}
		}

		private void DrawContent(SearchWindow window, Rect frame, int rows, bool interactive, float alpha)
		{
			//IL_0001: 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)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00f8: 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)
			DrawFrame(frame);
			float num = ((Rect)(ref frame)).x + 24f;
			float num2 = ((Rect)(ref frame)).width - 48f;
			float num3 = ((Rect)(ref frame)).y + 24f;
			GUI.Label(new Rect(num, num3, num2, 24f), Tr.T("title"), _styles.Title);
			GUI.Label(new Rect(num, num3, num2, 24f), window.Status, _styles.Status);
			num3 += 28f;
			DrawQuery(window, new Rect(num, num3, num2, 30f), interactive);
			num3 += 36f;
			_toolbar.Draw(window, new Rect(num, num3, num2, 28f), interactive);
			num3 += 34f;
			_rows.DrawColumns(new Rect(num, num3, num2, 20f));
			num3 += 24f;
			Rect list = default(Rect);
			((Rect)(ref list))..ctor(num, num3, num2, (float)rows * 28f);
			DrawList(window, list, interactive, alpha);
			DrawFooter(window, new Rect(num, ((Rect)(ref list)).yMax + 8f, num2, 20f), interactive);
		}

		private void DrawFrame(Rect frame)
		{
			//IL_000b: 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_003b: Invalid comparison between Unknown and I4
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			if (_skin.Draw("woodpanel_trophys", frame) || _skin.Draw("woodpanel_settings", frame))
			{
				if ((int)Event.current.type == 7)
				{
					GUI.DrawTexture(new Rect(((Rect)(ref frame)).x + 10f, ((Rect)(ref frame)).y + 10f, ((Rect)(ref frame)).width - 20f, ((Rect)(ref frame)).height - 20f), (Texture)(object)_styles.Scrim);
				}
			}
			else
			{
				GUI.DrawTexture(new Rect(((Rect)(ref frame)).x - 1f, ((Rect)(ref frame)).y - 1f, ((Rect)(ref frame)).width + 2f, ((Rect)(ref frame)).height + 2f), (Texture)(object)_styles.Border);
				GUI.DrawTexture(frame, (Texture)(object)_styles.Background);
				GUI.DrawTexture(new Rect(((Rect)(ref frame)).x, ((Rect)(ref frame)).y, ((Rect)(ref frame)).width, 3f), (Texture)(object)_styles.Accent);
			}
		}

		private void DrawQuery(SearchWindow window, Rect rect, bool interactive)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0094: Invalid comparison between Unknown and I4
			//IL_00c8: 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)
			_skin.Draw("text_field", rect, 0.5f);
			if (!interactive)
			{
				GUI.Label(rect, window.Query, _styles.Input);
				return;
			}
			GUI.SetNextControlName("HoardFinderQuery");
			window.Query = GUI.TextField(rect, window.Query ?? string.Empty, 64, _styles.Input);
			if (GUI.GetNameOfFocusedControl() != "HoardFinderQuery")
			{
				GUI.FocusControl("HoardFinderQuery");
			}
			else if (window.SelectAllPending && (int)Event.current.type == 7)
			{
				window.SelectAllPending = false;
				((TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl)).SelectAll();
			}
			if (window.Query.Length == 0)
			{
				GUI.Label(rect, Tr.T("placeholder"), _styles.Placeholder);
			}
		}

		private void DrawList(SearchWindow window, Rect list, bool interactive, float alpha)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0095: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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)
			Event current = Event.current;
			if (interactive && (int)current.type == 6 && ((Rect)(ref list)).Contains(current.mousePosition))
			{
				window.ScrollBy((current.delta.y > 0f) ? 3 : (-3));
				current.Use();
			}
			if (window.Results.Count == 0)
			{
				string text = ((window.Query.Length == 0) ? Tr.F("empty_none", window.RadiusText) : Tr.T("empty_match"));
				GUI.Label(list, text, _styles.Empty);
				return;
			}
			_rows.DrawSelection(window, list);
			if (!DrawVisibleRows(window, list, interactive, alpha))
			{
				GUI.color = new Color(1f, 1f, 1f, alpha);
				_rows.DrawScrollbar(window, list);
			}
		}

		private bool DrawVisibleRows(SearchWindow window, Rect list, bool interactive, float alpha)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Min(window.Results.Count, window.Scroll + 12);
			Rect row = default(Rect);
			for (int i = window.Scroll; i < num; i++)
			{
				int num2 = i - window.Scroll;
				float num3 = Anim.EaseOutCubic(Anim.Progress(window.ResultsChangedAt + (float)num2 * 0.018f, 0.16f));
				((Rect)(ref row))..ctor(((Rect)(ref list)).x + (1f - num3) * 10f, ((Rect)(ref list)).y + (float)num2 * 28f, ((Rect)(ref list)).width, 28f);
				GUI.color = new Color(1f, 1f, 1f, alpha * num3);
				if (_rows.Draw(window, window.Results[i], row, i, interactive))
				{
					return true;
				}
			}
			return false;
		}

		private void DrawFooter(SearchWindow window, Rect rect, bool interactive)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			if (_hintsVersion != Tr.Version)
			{
				_hintsVersion = Tr.Version;
				_hints = "Enter  " + Tr.T("hint_highlight") + "     Shift+Enter  " + Tr.T("hint_all") + "     Tab  " + Tr.T("hint_sort") + "     Up/Down  " + Tr.T("hint_select") + "     Esc  " + Tr.T("hint_close");
			}
			GUI.Label(rect, _hints, _styles.Footer);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax + 4f, ((Rect)(ref rect)).width, 20f);
			if (window.Capture.Active)
			{
				float num = 0.55f + 0.45f * Mathf.Sin((Anim.Now - window.Capture.StartedAt) * 7f);
				Color color = GUI.color;
				GUI.color = new Color(color.r, color.g, color.b, color.a * num);
				GUI.Label(val, Tr.T("hotkey_press"), _styles.HotkeyActive);
				GUI.color = color;
				return;
			}
			_content.text = Tr.F("hotkey", window.HotkeyText) + "   [" + Tr.T("hotkey_change") + "]";
			float x = _styles.Hotkey.CalcSize(_content).x;
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(((Rect)(ref val)).center.x - x / 2f, ((Rect)(ref val)).y, x, ((Rect)(ref val)).height);
			bool flag = ((Rect)(ref val2)).Contains(Event.current.mousePosition);
			GUI.Label(val, _content, (flag && interactive) ? _styles.HotkeyHover : _styles.Hotkey);
			if (interactive && GUI.Button(val2, GUIContent.none, GUIStyle.none))
			{
				window.Capture.Begin();
			}
		}

		public void Dispose()
		{
			_styles.Dispose();
			_skin.Dispose();
		}
	}
	internal sealed class Toast
	{
		private const float In = 0.22f;

		private const float Hold = 2.2f;

		private const float Out = 0.45f;

		private readonly GUIContent _content = new GUIContent();

		private Texture2D _background;

		private Texture2D _accent;

		private GUIStyle _style;

		private int _styleVersion = -1;

		private string _text;

		private Color _color = Palette.Gold;

		private float _shownAt = float.NegativeInfinity;

		public void Show(string text, Color color)
		{
			//IL_0008: 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)
			_text = text;
			_color = color;
			_shownAt = Anim.Now;
		}

		public void OnGUI()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			float num = Anim.Now - _shownAt;
			if (_text != null && !(num > 2.8700001f) && (int)Event.current.type == 7)
			{
				Ensure();
				float num2 = Anim.EaseOutCubic(Anim.Progress(_shownAt, 0.22f));
				float num3 = num2 * (1f - Anim.Progress(_shownAt + 0.22f + 2.2f, 0.45f));
				float num4 = Mathf.Max(1f, (float)Screen.height / 1080f);
				Matrix4x4 matrix = GUI.matrix;
				GUI.matrix = Matrix4x4.Scale(new Vector3(num4, num4, 1f));
				_content.text = _text;
				Vector2 val = _style.CalcSize(_content);
				Rect val2 = default(Rect);
				((Rect)(ref val2))..ctor(((float)Screen.width / num4 - val.x) / 2f, 28f + (num2 - 1f) * 18f, val.x, val.y);
				Color color = GUI.color;
				GUI.color = new Color(1f, 1f, 1f, num3);
				GUI.DrawTexture(val2, (Texture)(object)_background);
				GUI.color = new Color(_color.r, _color.g, _color.b, num3);
				GUI.DrawTexture(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).yMax - 2f, ((Rect)(ref val2)).width * num2, 2f), (Texture)(object)_accent);
				GUI.color = new Color(1f, 1f, 1f, num3);
				GUI.Label(val2, _content, _style);
				GUI.color = color;
				GUI.matrix = matrix;
			}
		}

		private void Ensure()
		{
			//IL_0023: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00a3: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_background == (Object)null)
			{
				_background = SearchWindowStyles.Solid(new Color(0.07f, 0.06f, 0.05f, 0.92f));
				_accent = SearchWindowStyles.Solid(Color.white);
			}
			if (_style == null || _styleVersion != Tr.Version)
			{
				_styleVersion = Tr.Version;
				_style = new GUIStyle(GUI.skin.label)
				{
					font = GameFonts.Bold,
					fontSize = 16,
					alignment = (TextAnchor)4,
					padding = new RectOffset(18, 18, 8, 10)
				};
				_style.normal.textColor = new Color(0.95f, 0.92f, 0.85f, 1f);
			}
		}

		public void Dispose()
		{
			if ((Object)(object)_background != (Object)null)
			{
				Object.Destroy((Object)(object)_background);
				Object.Destroy((Object)(object)_accent);
			}
			_background = null;
			_accent = null;
			_style = null;
		}
	}
	internal sealed class Toolbar
	{
		private const float Gap = 6f;

		private readonly SearchWindowStyles _styles;

		private readonly ValheimSkin _skin;

		private readonly GUIContent _content = new GUIContent();

		public Toolbar(SearchWindowStyles styles, ValheimSkin skin)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			_styles = styles;
			_skin = skin;
		}

		public void Draw(SearchWindow window, Rect rect, bool interactive)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			SearchOptions options = window.Options;
			int num = (ModLookup.Available ? 4 : 3);
			float num2 = (((Rect)(ref rect)).width - 6f * (float)(num - 1)) / (float)num;
			Rect rect2 = default(Rect);
			((Rect)(ref rect2))..ctor(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, num2, ((Rect)(ref rect)).height);
			string label = Tr.F("sort", Tr.T("sort_" + options.Sort.ToString().ToLowerInvariant()));
			Button(window, rect2, label, options.Sort != SortMode.Relevance, interactive, ToolbarAction.Sort);
			((Rect)(ref rect2)).x = ((Rect)(ref rect2)).x + (num2 + 6f);
			string label2 = Tr.F("filter_type", TypeLabel(options.Type));
			Button(window, rect2, label2, options.Type != HoardFinder.Search.TypeFilter.All, interactive, ToolbarAction.Type);
			((Rect)(ref rect2)).x = ((Rect)(ref rect2)).x + (num2 + 6f);
			string label3 = Tr.F("filter_source", SourceLabel(options.Source));
			Button(window, rect2, label3, options.Source != HoardFinder.Search.SourceFilter.All, interactive, ToolbarAction.Source);
			if (num == 4)
			{
				((Rect)(ref rect2)).x = ((Rect)(ref rect2)).x + (num2 + 6f);
				string label4 = Tr.F("filter_mod", options.Mod ?? Tr.T("all"));
				Button(window, rect2, label4, options.Mod != null, interactive, ToolbarAction.Mod);
			}
		}

		private void Button(SearchWindow window, Rect rect, string label, bool active, bool interactive, ToolbarAction action)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			Event current = Event.current;
			bool flag = interactive && ((Rect)(ref rect)).Contains(current.mousePosition);
			DrawBackground(rect, active, flag);
			_content.text = label;
			GUI.Label(rect, _content, active ? _styles.ButtonActive : _styles.ButtonLabel);
			if (flag && (int)current.type == 0 && (current.button == 0 || current.button == 1))
			{
				int step = ((current.button == 0) ? 1 : (-1));
				current.Use();
				window.Cycle(action, step);
			}
		}

		private void DrawBackground(Rect rect, bool active, bool hover)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_006c: Invalid comparison between Unknown and I4
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			Color color = GUI.color;
			if (hover)
			{
				GUI.color = new Color(color.r * 1.15f, color.g * 1.15f, color.b * 1.15f, color.a);
			}
			string name = (active ? "button_highlight" : "button");
			if (!_skin.Draw(name, rect, 0.5f) && (int)Event.current.type == 7)
			{
				GUI.DrawTexture(rect, (Texture)(object)(active ? _styles.Selection : _styles.Hover));
			}
			GUI.color = color;
		}

		private static string TypeLabel(HoardFinder.Search.TypeFilter filter)
		{
			if (filter != HoardFinder.Search.TypeFilter.All)
			{
				return Tr.T(ItemCategories.Key((ItemCategory)(filter - 1)));
			}
			return Tr.T("all");
		}

		private static string SourceLabel(HoardFinder.Search.SourceFilter filter)
		{
			return filter switch
			{
				HoardFinder.Search.SourceFilter.Drawers => Tr.T("src_drawers"), 
				HoardFinder.Search.SourceFilter.Chests => Tr.T("src_chests"), 
				HoardFinder.Search.SourceFilter.Vehicles => Tr.T("src_vehicles"), 
				HoardFinder.Search.SourceFilter.Tombstones => Tr.T("src_tombstones"), 
				HoardFinder.Search.SourceFilter.World => Tr.T("src_world"), 
				_ => Tr.T("all"), 
			};
		}
	}
	internal enum ToolbarAction
	{
		Sort,
		Type,
		Source,
		Mod
	}
	internal sealed class ValheimSkin
	{
		public const string Panel = "woodpanel_settings";

		public const string PanelAlt = "woodpanel_trophys";

		public const string Field = "text_field";

		public const string Button = "button";

		public const string ButtonOn = "button_highlight";

		private static readonly string[] Wanted = new string[5] { "woodpanel_settings", "woodpanel_trophys", "text_field", "button", "button_highlight" };

		private const int MaxResolveAttempts = 3;

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

		private readonly Dictionary<string, Rect> _uvs = new Dictionary<string, Rect>();

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

		private int _attempts;

		public bool Has(string name)
		{
			return _sprites.ContainsKey(name);
		}

		public void Resolve()
		{
			if (_sprites.Count == Wanted.Length || _attempts >= 3)
			{
				return;
			}
			_attempts++;
			Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
			foreach (Sprite val in array)
			{
				if (Array.IndexOf(Wanted, ((Object)val).name) >= 0 && !_sprites.ContainsKey(((Object)val).name))
				{
					_sprites[((Object)val).name] = val;
				}
			}
			if (_sprites.Count < Wanted.Length)
			{
				ResolveFromAtlas();
			}
			Log.Info("Valheim UI sprites found: " + _sprites.Count + "/" + Wanted.Length + ".");
		}

		private void ResolveFromAtlas()
		{
			SpriteAtlas[] array = Resources.FindObjectsOfTypeAll<SpriteAtlas>();
			foreach (SpriteAtlas val in array)
			{
				if (((Object)val).name != "UIAtlas")
				{
					continue;
				}
				string[] wanted = Wanted;
				foreach (string text in wanted)
				{
					Sprite val2 = (_sprites.ContainsKey(text) ? null : val.GetSprite(text));
					if ((Object)(object)val2 != (Object)null)
					{
						_sprites[text] = val2;
						_atlasClones.Add(val2);
					}
				}
			}
		}

		public bool Draw(string name, Rect rect, float borderScale = 1f)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			//IL_005b: 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_0047: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			if (!_sprites.TryGetValue(name, out var value) || (Object)(object)value == (Object)null || (Object)(object)value.texture == (Object)null)
			{
				return false;
			}
			if ((int)Event.current.type == 7)
			{
				if (!_uvs.TryGetValue(name, out var value2))
				{
					value2 = NineSlice.UvRect(value);
					_uvs[name] = value2;
				}
				NineSlice.Draw(value, value2, rect, borderScale);
			}
			return true;
		}

		public void Dispose()
		{
			foreach (Sprite atlasClone in _atlasClones)
			{
				if ((Object)(object)atlasClone != (Object)null)
				{
					Object.Destroy((Object)(object)atlasClone);
				}
			}
			_atlasClones.Clear();
			_sprites.Clear();
			_uvs.Clear();
			_attempts = 0;
		}
	}
}
namespace HoardFinder.Storage
{
	internal sealed class ContainerSource : IStorageSource
	{
		private sealed class Registered
		{
			public Container Container;

			public Piece Piece;

			public GameObject Target;

			public StorageKind Kind;
		}

		private static readonly List<Registered> All = new List<Registered>(256);

		private readonly Dictionary<string, int> _perItem = new Dictionary<string, int>(32);

		private readonly HashSet<StorageKind> _enabled;

		public string Description => "Container (chests, carts, ships, tombstones, world)";

		public int LoadedCount => All.Count;

		public ContainerSource(HashSet<StorageKind> enabledKinds)
		{
			_enabled = enabledKinds;
		}

		public static void Register(Container container)
		{
			if (!((Object)(object)container == (Object)null) && container.GetInventory() != null)
			{
				ZNetView rootObjectOverride = container.m_rootObjectOverride;
				All.Add(new Registered
				{
					Container = container,
					Piece = ((Component)container).GetComponentInParent<Piece>(),
					Target = (((Object)(object)rootObjectOverride != (Object)null) ? ((Component)rootObjectOverride).gameObject : ((Component)container).gameObject),
					Kind = Classify(container, rootObjectOverride)
				});
			}
		}

		private static StorageKind Classify(Container container, ZNetView root)
		{
			if ((Object)(object)((Component)container).GetComponent<TombStone>() != (Object)null)
			{
				return StorageKind.Tombstone;
			}
			bool flag = (Object)(object)((Component)container).GetComponentInParent<Ship>() != (Object)null || (Object)(object)((Component)container).GetComponentInParent<Vagon>() != (Object)null;
			if ((Object)(object)root != (Object)null || flag)
			{
				return StorageKind.Vehicle;
			}
			if (!((Object)(object)((Component)container).GetComponentInParent<Piece>() != (Object)null))
			{
				return StorageKind.World;
			}
			return StorageKind.Chest;
		}

		public void Collect(Vector3 center, float radius, List<StorageEntry> results)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			float num = radius * radius;
			for (int num2 = All.Count - 1; num2 >= 0; num2--)
			{
				Registered registered = All[num2];
				if ((Object)(object)registered.Container == (Object)null || (Object)(object)registered.Target == (Object)null)
				{
					All.RemoveAt(num2);
				}
				else
				{
					Vector3 val = ((Component)registered.Container).transform.position - center;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude <= num && _enabled.Contains(registered.Kind) && StorageAccess.Container(registered.Container, registered.Piece))
					{
						AddItems(registered, Mathf.Sqrt(sqrMagnitude), results);
					}
				}
			}
		}

		private void AddItems(Registered entry, float distance, List<StorageEntry> results)
		{
			Inventory inventory = entry.Container.GetInventory();
			if (inventory == null)
			{
				return;
			}
			_perItem.Clear();
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				string text = (((Object)(object)allItem?.m_dropPrefab != (Object)null) ? ((Object)allItem.m_dropPrefab).name : null);
				if (text != null && allItem.m_stack > 0)
				{
					_perItem.TryGetValue(text, out var value);
					_perItem[text] = value + allItem.m_stack;
				}
			}
			foreach (KeyValuePair<string, int> item in _perItem)
			{
				results.Add(new StorageEntry
				{
					Source = (Component)(object)entry.Container,
					Target = entry.Target,
					Item = item.Key,
					Count = item.Value,
					Distance = distance,
					Kind = entry.Kind
				});
			}
		}

		public void ResetSession()
		{
			All.Clear();
		}
	}
	internal static class StorageAccess
	{
		public static bool Enabled = true;

		public static bool Ward(Vector3 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (Enabled)
			{
				return PrivateArea.CheckAccess(position, 0f, false, false);
			}
			return true;
		}

		public static bool Container(Container container, Piece piece)
		{
			//IL_000a: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_001d: 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)
			if (!Enabled)
			{
				return true;
			}
			PrivacySetting privacy = container.m_privacy;
			if ((int)privacy != 0)
			{
				if ((int)privacy == 2)
				{
					return Ward(((Component)container).transform.position);
				}
				return false;
			}
			if ((Object)(object)piece != (Object)null && piece.GetCreator() == LocalPlayerId())
			{
				return Ward(((Component)container).transform.position);
			}
			return false;
		}

		private static long LocalPlayerId()
		{
			PlayerProfile val = (((Object)(object)Game.instance != (Object)null) ? Game.instance.GetPlayerProfile() : null);
			if (val == null)
			{
				return 0L;
			}
			return val.GetPlayerID();
		}
	}
	internal enum StorageKind
	{
		Drawer,
		Chest,
		Vehicle,
		Tombstone,
		World
	}
	internal struct StorageEntry
	{
		public Component Source;

		public GameObject Target;

		public string Item;

		public int Count;

		public float Distance;

		public StorageKind Kind;
	}
	internal interface IStorageSource
	{
		string Description { get; }

		int LoadedCount { get; }

		void Collect(Vector3 center, float radius, List<StorageEntry> results);

		void ResetSession();
	}
	internal sealed class StorageIndex
	{
		private readonly List<IStorageSource> _sources = new List<IStorageSource>(2);

		private readonly HashSet<IStorageSource> _failed = new HashSet<IStorageSource>();

		public int LoadedCount
		{
			get
			{
				int num = 0;
				foreach (IStorageSource source in _sources)
				{
					num += source.LoadedCount;
				}
				return num;
			}
		}

		public void Add(IStorageSource source)
		{
			if (source != null)
			{
				_sources.Add(source);
				Log.Info("Storage source: " + source.Description + ".");
			}
		}

		public void Collect(Vector3 center, float radius, List<StorageEntry> results)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			results.Clear();
			foreach (IStorageSource source in _sources)
			{
				try
				{
					source.Collect(center, radius, results);
				}
				catch (Exception ex)
				{
					if (_failed.Add(source))
					{
						Log.Warning("Storage source failed, skipping it: " + source.Description + ": " + ex.Message);
					}
				}
			}
		}

		public static int CountStorages(List<StorageEntry> entries, HashSet<int> scratch)
		{
			scratch.Clear();
			foreach (StorageEntry entry in entries)
			{
				if ((Object)(object)entry.Source != (Object)null)
				{
					scratch.Add(((Object)entry.Source).GetInstanceID());
				}
			}
			return scratch.Count;
		}

		public void ResetSession()
		{
			foreach (IStorageSource source in _sources)
			{
				source.ResetSession();
			}
			_failed.Clear();
		}
	}
}
namespace HoardFinder.Search
{
	internal enum ItemCategory
	{
		Materials,
		Food,
		Potions,
		Ammo,
		Equipment,
		Trophies,
		Other
	}
	internal static class ItemCategories
	{
		public static ItemCategory Of(SharedData shared)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (shared == null)
			{
				return ItemCategory.Other;
			}
			ItemType itemType = shared.m_itemType;
			if ((int)itemType <= 2)
			{
				if ((int)itemType != 1)
				{
					if ((int)itemType != 2)
					{
						goto IL_005c;
					}
					if (!(shared.m_food > 0f) && !(shared.m_foodStamina > 0f) && !(shared.m_foodEitr > 0f))
					{
						return ItemCategory.Potions;
					}
					return ItemCategory.Food;
				}
				return ItemCategory.Materials;
			}
			if ((int)itemType != 9)
			{
				if ((int)itemType == 13)
				{
					return ItemCategory.Trophies;
				}
				if ((int)itemType != 23)
				{
					goto IL_005c;
				}
			}
			return ItemCategory.Ammo;
			IL_005c:
			if (!IsEquipment(shared.m_itemType))
			{
				return ItemCategory.Other;
			}
			return ItemCategory.Equipment;
		}

		private static bool IsEquipment(ItemType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected I4, but got Unknown
			switch (type - 3)
			{
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
			case 8:
			case 9:
			case 11:
			case 12:
			case 14:
			case 15:
			case 16:
			case 17:
			case 19:
			case 21:
				return true;
			default:
				return false;
			}
		}

		public static string Key(ItemCategory category)
		{
			return "cat_" + category.ToString().ToLowerInvariant();
		}
	}
	internal sealed class ItemName
	{
		public string Prefab;

		public string Display;

		public string DisplayKey;

		public string PrefabKey;

		public Sprite Icon;

		public ItemCategory Category;

		public string Mod;

		public bool IsVanilla => Mod == "Valheim";
	}
	internal static class ItemNames
	{
		private static readonly Dictionary<string, ItemName> Cache = new Dictionary<string, ItemName>(256);

		private static readonly StringBuilder Buffer = new StringBuilder(64);

		private static ObjectDB _cachedFor;

		private static string _cachedLanguage;

		private static bool _decomposeFailed;

		public static ItemName Get(string prefab)
		{
			Validate();
			if (!Cache.TryGetValue(prefab, out var value))
			{
				value = Build(prefab);
				Cache[prefab] = value;
			}
			return value;
		}

		public static void Clear()
		{
			Cache.Clear();
			_cachedFor = null;
			_cachedLanguage = null;
		}

		private static void Validate()
		{
			Localization instance = Localization.instance;
			string text = ((instance != null) ? instance.GetSelectedLanguage() : null);
			if ((Object)(object)_cachedFor != (Object)(object)ObjectDB.instance || _cachedLanguage != text)
			{
				Cache.Clear();
				_cachedFor = ObjectDB.instance;
				_cachedLanguage = text;
			}
		}

		private static ItemName Build(string prefab)
		{
			ItemDrop val = null;
			GameObject val2 = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefab) : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val = val2.GetComponent<ItemDrop>();
			}
			SharedData val3 = ((!((Object)(object)val != (Object)null)) ? null : val.m_itemData?.m_shared);
			string text = ((val3 != null && Localization.instance != null) ? Localization.instance.Localize(val3.m_name) : prefab);
			if (string.IsNullOrEmpty(text))
			{
				text = prefab;
			}
			Sprite icon = ((val3?.m_icons != null && val3.m_icons.Length != 0) ? val3.m_icons[0] : null);
			return new ItemName
			{
				Prefab = prefab,
				Display = text,
				DisplayKey = Normalize(text),
				PrefabKey = Normalize(prefab),
				Icon = icon,
				Category = ItemCategories.Of(val3),
				Mod = ModLookup.ModOf(prefab)
			};
		}

		public static string Normalize(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return string.Empty;
			}
			Buffer.Length = 0;
			string text2 = Decompose(text);
			foreach (char c in text2)
			{
				if (!char.IsWhiteSpace(c) && c != '_' && c != '-' && CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
				{
					Buffer.Append(char.ToLowerInvariant(c));
				}
			}
			return Buffer.ToString();
		}

		private static string Decompose(string text)
		{
			if (_decomposeFailed)
			{
				return text;
			}
			try
			{
				return text.Normalize(NormalizationForm.FormD);
			}
			catch (Exception ex)
			{
				_decomposeFailed = true;
				Log.Warning("Unicode normalization unavailable; accent-insensitive search disabled. " + ex.Message);
				return text;
			}
		}
	}
	internal static class ModLookup
	{
		public const string Vanilla = "Valheim";

		private static MethodInfo _getPrefab;

		private static PropertyInfo _sourceMod;

		public static bool Available => _getPrefab != null;

		public static void Enable()
		{
			try
			{
				Type? type = Type.GetType("Jotunn.Utils.ModQuery, Jotunn", throwOnError: false);
				Type type2 = Type.GetType("Jotunn.Utils.IModPrefab, Jotunn", throwOnError: false);
				MethodInfo methodInfo = type?.GetMethod("Enable", BindingFlags.Static | BindingFlags.Public);
				MethodInfo methodInfo2 = type?.GetMethod("GetPrefab", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(string) }, null);
				PropertyInfo propertyInfo = type2?.GetProperty("SourceMod");
				if (methodInfo == null || methodInfo2 == null || propertyInfo == null)
				{
					Log.Info("Jotunn ModQuery not available; the mod filter is disabled.");
					return;
				}
				methodInfo.Invoke(null, null);
				_getPrefab = methodInfo2;
				_sourceMod = propertyInfo;
				Log.Info("Item mod detection enabled through Jotunn ModQuery.");
			}
			catch (Exception ex)
			{
				Log.Warning("Jotunn ModQuery could not be enabled; the mod filter is disabled. " + ex.Message);
			}
		}

		public static string ModOf(string prefab)
		{
			if (_getPrefab == null)
			{
				return "Valheim";
			}
			try
			{
				object obj = _getPrefab.Invoke(null, new object[1] { prefab });
				BepInPlugin val = (BepInPlugin)((obj != null) ? /*isinst with value type is only supported in some contexts*/: null);
				return (val != null) ? val.Name : "Valheim";
			}
			catch (Exception)
			{
				return "Valheim";
			}
		}
	}
	internal enum SortMode
	{
		Relevance,
		Name,
		Amount,
		Distance,
		Type,
		Mod
	}
	internal enum TypeFilter
	{
		All,
		Materials,
		Food,
		Potions,
		Ammo,
		Equipment,
		Trophies,
		Other
	}
	internal enum SourceFilter
	{
		All,
		Drawers,
		Chests,
		Vehicles,
		Tombstones,
		World
	}
	internal sealed class SearchOptions
	{
		public SortMode Sort;

		public TypeFilter Type;

		public SourceFilter Source;

		public string Mod;

		public int SnapshotKey => (int)Source;

		public bool Accepts(ItemName name)
		{
			if (Type != TypeFilter.All && name.Category != (ItemCategory)(Type - 1))
			{
				return false;
			}
			if (Mod != null)
			{
				return name.Mod == Mod;
			}
			return true;
		}

		public bool Accepts(StorageKind kind)
		{
			if (Source != SourceFilter.All)
			{
				return kind == (StorageKind)(Source - 1);
			}
			return true;
		}
	}
	internal static class SearchSort
	{
		private static readonly Comparison<SearchResult> ByName = (SearchResult a, SearchResult b) => string.Compare(a.Name.Display, b.Name.Display, StringComparison.CurrentCultureIgnoreCase);

		private static readonly Comparison<SearchResult> ByRelevance = delegate(SearchResult a, SearchResult b)
		{
			int num = a.Rank.CompareTo(b.Rank);
			return (num == 0) ? ThenAmount(a, b) : num;
		};

		private static readonly Comparison<SearchResult> ByAmount = ThenAmount;

		private static readonly Comparison<SearchResult> ByDistance = delegate(SearchResult a, SearchResult b)
		{
			int num = a.Closest.CompareTo(b.Closest);
			return (num == 0) ? ByName(a, b) : num;
		};

		private static readonly Comparison<SearchResult> ByType = delegate(SearchResult a, SearchResult b)
		{
			int num = a.Name.Category.CompareTo(b.Name.Category);
			return (num == 0) ? ByName(a, b) : num;
		};

		private static readonly Comparison<SearchResult> ByMod = delegate(SearchResult a, SearchResult b)
		{
			int num = b.Name.IsVanilla.CompareTo(a.Name.IsVanilla);
			if (num != 0)
			{
				return num;
			}
			int num2 = string.Compare(a.Name.Mod, b.Name.Mod, StringComparison.OrdinalIgnoreCase);
			return (num2 == 0) ? ByName(a, b) : num2;
		};

		private static int ThenAmount(SearchResult a, SearchResult b)
		{
			int num = b.Total.CompareTo(a.Total);
			if (num == 0)
			{
				return ByName(a, b);
			}
			return num;
		}

		public static Comparison<SearchResult> For(SortMode mode)
		{
			return mode switch
			{
				SortMode.Name => ByName, 
				SortMode.Amount => ByAmount, 
				SortMode.Distance => ByDistance, 
				SortMode.Type => ByType, 
				SortMode.Mod => ByMod, 
				_ => ByRelevance, 
			};
		}
	}
	internal sealed class SearchResult
	{
		public ItemName Name;

		public int Total;

		public int Places;

		public float Closest;

		public int Rank;

		public string TotalText;

		public string ClosestText;

		public string PlacesText;
	}
	internal sealed class StorageSearch
	{
		private const int NoMatch = -1;

		private const float SnapshotLifetime = 1f;

		private const float SnapshotMoveTolerance = 1f;

		private readonly StorageIndex _index;

		private readonly List<StorageEntry> _entries = new List<StorageEntry>(1024);

		private readonly List<StorageEntry> _fresh = new List<StorageEntry>(1024);

		private readonly HashSet<int> _storages = new HashSet<int>();

		private readonly Dictionary<string, SearchResult> _byItem = new Dictionary<string, SearchResult>(256);

		private readonly List<SearchResult> _pool = new List<SearchResult>(256);

		private readonly List<SearchResult> _results = new List<SearchResult>(256);

		private readonly SortedSet<string> _modSet = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);

		private int _poolUsed;

		private float _snapshotTime = float.NegativeInfinity;

		private Vector3 _snapshotCenter;

		private float _snapshotRadius;

		private int _snapshotKey = -1;

		public int LastStorageCount { get; private set; }

		public List<string> Mods { get; } = new List<string>();

		public StorageSearch(StorageIndex index)
		{
			_index = index;
		}

		public void Invalidate()
		{
			_snapshotTime = float.NegativeInfinity;
		}

		public List<SearchResult> Search(string query, Vector3 center, float radius, int maxResults, SearchOptions options)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (SnapshotStale(center, radius, options))
			{
				Group(center, radius, options);
			}
			string text = ItemNames.Normalize(query);
			_results.Clear();
			foreach (SearchResult value in _byItem.Values)
			{
				value.Rank = ((text.Length != 0) ? RankOf(value.Name, text) : 0);
				if (value.Rank != -1 && options.Accepts(value.Name))
				{
					_results.Add(value);
				}
			}
			_results.Sort(SearchSort.For(options.Sort));
			if (_results.Count > maxResults)
			{
				_results.RemoveRange(maxResults, _results.Count - maxResults);
			}
			return _results;
		}

		private bool SnapshotStale(Vector3 center, float radius, SearchOptions options)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!(Time.unscaledTime - _snapshotTime > 1f) && options.SnapshotKey == _snapshotKey && Mathf.Approximately(radius, _snapshotRadius))
			{
				Vector3 val = center - _snapshotCenter;
				return ((Vector3)(ref val)).sqrMagnitude > 1f;
			}
			return true;
		}

		public void CollectHolding(HashSet<string> prefabs, Vector3 center, float radius, SearchOptions options, List<StorageEntry> results)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			_index.Collect(center, radius, _fresh);
			results.Clear();
			foreach (StorageEntry item in _fresh)
			{
				if (prefabs.Contains(item.Item) && options.Accepts(item.Kind))
				{
					results.Add(item);
				}
			}
		}

		private static int RankOf(ItemName name, string key)
		{
			int num = MatchLevel(name.DisplayKey, key);
			if (num != -1)
			{
				return num;
			}
			int num2 = MatchLevel(name.PrefabKey, key);
			if (num2 != -1)
			{
				return num2 + 3;
			}
			return -1;
		}

		private static int MatchLevel(string candidate, string key)
		{
			if (candidate == key)
			{
				return 0;
			}
			if (candidate.StartsWith(key, StringComparison.Ordinal))
			{
				return 1;
			}
			if (candidate.IndexOf(key, StringComparison.Ordinal) < 0)
			{
				return -