Decompiled source of LocationFinder v1.0.50

LocationFinder.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LocationFinder.Core;
using LocationFinder.Patches;
using LocationFinder.UI;
using Splatform;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LocationFinder")]
[assembly: AssemblyDescription("Pins world locations on the minimap by category.")]
[assembly: AssemblyProduct("LocationFinder")]
[assembly: AssemblyCopyright("YouDied")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LocationFinder
{
	[BepInPlugin("YouDied.LocationFinder", "Location Finder", "1.0.50")]
	[BepInProcess("valheim.exe")]
	public class LocationFinderPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "YouDied.LocationFinder";

		public const string PluginName = "Location Finder";

		public const string PluginVersion = "1.0.50";

		public static ManualLogSource Log;

		public static ConfigEntry<KeyCode> PanelKey;

		public static ConfigEntry<float> ServerSearchRadius;

		public static ConfigEntry<bool> ServerFullMap;

		public static ConfigEntry<bool> ExportWorldLocations;

		public static ConfigEntry<bool> ShareToMapTable;

		private readonly Harmony _harmony = new Harmony("YouDied.LocationFinder");

		private void Awake()
		{
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			PanelKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "PanelKey", (KeyCode)39, "Key to open/close the Location Finder panel (default: ' key)");
			ServerSearchRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Servers", "ServerSearchRadius", 400f, "On a SERVER, locations are pinned as they load near you, within this many meters of your character. Private and player-hosted worlds always find everything world-wide and ignore this. 0 = no limit (everything the game has loaded around you).");
			ServerFullMap = ((BaseUnityPlugin)this).Config.Bind<bool>("Servers", "ServerFullMap", false, "Advanced. On a server, also try to load the WHOLE map (from a saved world export or a server-side component) instead of only searching near you. Off by default.");
			ExportWorldLocations = ((BaseUnityPlugin)this).Config.Bind<bool>("Servers", "ExportWorldLocations", false, "Advanced. Only needed with ServerFullMap. Saves each world's location list to the config folder whenever you load it locally (e.g. a copy of a server's world file), so it can be loaded when you join that same world on a server.");
			ShareToMapTable = ((BaseUnityPlugin)this).Config.Bind<bool>("Sharing", "ShareToMapTable", false, "If true, when you record your map on a Cartography Table, Location Finder's pins are included so friends (even without the mod) can copy them onto their own maps. Your own saved pins are not affected; the mod's pins stay session-only for you.");
			Application.quitting += OnQuitting;
			_harmony.CreateClassProcessor(typeof(Patch_HudAwake)).Patch();
			_harmony.CreateClassProcessor(typeof(Patch_ZoneSystemStart)).Patch();
			_harmony.CreateClassProcessor(typeof(Patch_ZoneSystemOnDestroy)).Patch();
			SafePatch(typeof(Patch_ZoneSystemAwake));
			SafePatch(typeof(Patch_GameCameraUpdateCamera));
			SafePatch(typeof(Patch_GameCameraMouseCapture));
			SafePatch(typeof(Patch_PlayerUpdate));
			SafePatch(typeof(Patch_PlayerFixedUpdate));
			SafePatch(typeof(Patch_PlayerTakeInput));
			SafePatch(typeof(Patch_HumanoidStartAttack));
			SafePatch(typeof(Patch_HumanoidUpdateEquipment));
			SafePatch(typeof(Patch_ChatUpdate));
			SafePatch(typeof(Patch_ChatHasFocus));
			SafePatch(typeof(Patch_MenuUpdate));
			SafePatch(typeof(Patch_TerminalUpdate));
			SafePatch(typeof(Patch_MinimapUpdate));
			SafePatch(typeof(Patch_MinimapSetMapMode));
			SafePatch(typeof(Patch_MinimapUpdateMap));
			SafePatch(typeof(Patch_MinimapOnMapLeftDown));
			SafePatch(typeof(Patch_MinimapOnMapLeftUp));
			SafePatch(typeof(Patch_MinimapOnMapDblClick));
			SafePatch(typeof(Patch_MinimapOnMapLeftClick));
			SafePatch(typeof(Patch_MinimapOnMapMiddleClick));
			SafePatch(typeof(Patch_MinimapOnMapRightClick));
			SafePatch(typeof(Patch_ContainerAwake));
			SafePatch(typeof(Patch_LeviathanAwake));
			SafePatch(typeof(Patch_PickableAwake));
			SafePatch(typeof(Patch_PickableInteract));
			SafePatch(typeof(Patch_MapTableOnWrite));
			Assets.Load();
			Log.LogInfo((object)string.Format("{0} {1} loaded. Press {2} to open.", "Location Finder", "1.0.50", PanelKey.Value));
		}

		private void SafePatch(Type patchType)
		{
			try
			{
				_harmony.CreateClassProcessor(patchType).Patch();
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[LocationFinder] Optional patch " + patchType.Name + " failed: " + ex.Message));
			}
		}

		private void OnQuitting()
		{
			WorldMapPinner.Shutdown();
		}

		private void OnDestroy()
		{
			WorldMapPinner.Shutdown();
			_harmony.UnpatchSelf();
		}
	}
}
namespace LocationFinder.Patches
{
	[HarmonyPatch(typeof(Hud), "Awake")]
	public static class Patch_HudAwake
	{
		[HarmonyPostfix]
		public static void Postfix(Hud __instance)
		{
			((Component)__instance).gameObject.AddComponent<LocationPanel>();
			LocationFinderPlugin.Log.LogInfo((object)"Location Finder UI attached.");
		}
	}
	[HarmonyPatch(typeof(ZoneSystem), "Start")]
	public static class Patch_ZoneSystemStart
	{
		[HarmonyPostfix]
		public static void Postfix(ZoneSystem __instance)
		{
			LocationConfig.LoadUserCategories();
			WorldMapPinner.BeginInit((MonoBehaviour)(object)__instance);
		}
	}
	[HarmonyPatch(typeof(ZoneSystem), "Awake")]
	public static class Patch_ZoneSystemAwake
	{
		[HarmonyPostfix]
		public static void Postfix(ZoneSystem __instance)
		{
			WorldMapPinner.BeginInit((MonoBehaviour)(object)__instance);
		}
	}
	[HarmonyPatch(typeof(ZoneSystem), "OnDestroy")]
	public static class Patch_ZoneSystemOnDestroy
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			WorldMapPinner.Shutdown();
		}
	}
	[HarmonyPatch(typeof(Container), "Awake")]
	public static class Patch_ContainerAwake
	{
		[HarmonyPostfix]
		public static void Postfix(Container __instance)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				((MonoBehaviour)__instance).StartCoroutine(IndexAfterLoad(__instance));
			}
		}

		private static IEnumerator IndexAfterLoad(Container container)
		{
			yield return (object)new WaitForSeconds(0.1f);
			if ((Object)(object)container != (Object)null)
			{
				WorldMapPinner.RegisterContainer(container);
			}
		}
	}
	[HarmonyPatch(typeof(Leviathan), "Awake")]
	public static class Patch_LeviathanAwake
	{
		[HarmonyPostfix]
		public static void Postfix(Leviathan __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)null)
			{
				WorldMapPinner.RegisterLeviathan(((Component)__instance).transform.position);
			}
		}
	}
	[HarmonyPatch(typeof(Pickable), "Awake")]
	public static class Patch_PickableAwake
	{
		[HarmonyPostfix]
		public static void Postfix(Pickable __instance)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				WorldMapPinner.RegisterPickable(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Pickable), "Interact")]
	public static class Patch_PickableInteract
	{
		[HarmonyPostfix]
		public static void Postfix(Pickable __instance)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				WorldMapPinner.UnregisterPickable(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	public static class Patch_PlayerUpdate
	{
		[HarmonyPrefix]
		public static bool Prefix(Player __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "FixedUpdate")]
	public static class Patch_PlayerFixedUpdate
	{
		[HarmonyPrefix]
		public static bool Prefix(Player __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "TakeInput")]
	public static class Patch_PlayerTakeInput
	{
		[HarmonyPrefix]
		public static bool Prefix(Player __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Humanoid), "StartAttack")]
	public static class Patch_HumanoidStartAttack
	{
		[HarmonyPrefix]
		public static bool Prefix(Humanoid __instance, ref bool __result)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				__result = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Humanoid), "UpdateEquipment")]
	public static class Patch_HumanoidUpdateEquipment
	{
		[HarmonyPrefix]
		public static bool Prefix(Humanoid __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
	public static class Patch_GameCameraUpdateCamera
	{
		private static bool _wasBlocking = false;

		private static readonly FieldInfo s_yawField = typeof(Player).GetField("m_lookYaw", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo s_pitchField = typeof(Player).GetField("m_lookPitch", BindingFlags.Instance | BindingFlags.NonPublic);

		private static Quaternion _savedYaw;

		private static float _savedPitch;

		[HarmonyPrefix]
		public static bool Prefix()
		{
			//IL_00b7: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				if (!_wasBlocking && (Object)(object)Player.m_localPlayer != (Object)null)
				{
					try
					{
						_savedYaw = (Quaternion)s_yawField.GetValue(Player.m_localPlayer);
						_savedPitch = (float)s_pitchField.GetValue(Player.m_localPlayer);
					}
					catch
					{
					}
				}
				_wasBlocking = true;
				Input.ResetInputAxes();
				return false;
			}
			if (_wasBlocking)
			{
				_wasBlocking = false;
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					try
					{
						s_yawField.SetValue(Player.m_localPlayer, _savedYaw);
						s_pitchField.SetValue(Player.m_localPlayer, _savedPitch);
					}
					catch
					{
					}
				}
				Input.ResetInputAxes();
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	public static class Patch_GameCameraMouseCapture
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Chat), "Update")]
	public static class Patch_ChatUpdate
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Chat), "HasFocus")]
	public static class Patch_ChatHasFocus
	{
		[HarmonyPostfix]
		public static void Postfix(ref bool __result)
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(Menu), "Update")]
	public static class Patch_MenuUpdate
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Terminal), "Update")]
	public static class Patch_TerminalUpdate
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Minimap), "Update")]
	public static class Patch_MinimapUpdate
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsBlockingInput)
			{
				Input.ResetInputAxes();
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Minimap), "SetMapMode")]
	public static class Patch_MinimapSetMapMode
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsVisible)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Minimap), "UpdateMap")]
	public static class Patch_MinimapUpdateMap
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsMouseOverPanel)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Minimap), "OnMapLeftDown")]
	public static class Patch_MinimapOnMapLeftDown
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsMouseOverPanel)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Minimap), "OnMapLeftUp")]
	public static class Patch_MinimapOnMapLeftUp
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsMouseOverPanel)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Minimap), "OnMapDblClick")]
	public static class Patch_MinimapOnMapDblClick
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsMouseOverPanel)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
	public static class Patch_MinimapOnMapLeftClick
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsMouseOverPanel)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Minimap), "OnMapMiddleClick")]
	public static class Patch_MinimapOnMapMiddleClick
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsMouseOverPanel)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	public static class Patch_MinimapOnMapRightClick
	{
		private static MethodBase _target;

		private static bool _searched;

		private static MethodBase Find()
		{
			if (_searched)
			{
				return _target;
			}
			_searched = true;
			string[] array = new string[2] { "OnMapRightClick", "RemovePinUnderPointer" };
			foreach (string text in array)
			{
				MethodInfo[] methods = typeof(Minimap).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name == text && methodInfo.ReturnType == typeof(void) && methodInfo.GetParameters().Length == 0)
					{
						_target = methodInfo;
						return _target;
					}
				}
			}
			MethodInfo[] methods2 = typeof(Minimap).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo2 in methods2)
			{
				if (methodInfo2.Name.IndexOf("RightClick", StringComparison.OrdinalIgnoreCase) >= 0 && methodInfo2.ReturnType == typeof(void) && methodInfo2.GetParameters().Length == 0 && !methodInfo2.IsGenericMethod)
				{
					_target = methodInfo2;
					return _target;
				}
			}
			return null;
		}

		[HarmonyPrepare]
		public static bool Prepare()
		{
			return Find() != null;
		}

		[HarmonyTargetMethod]
		public static MethodBase TargetMethod()
		{
			return Find();
		}

		[HarmonyPrefix]
		public static bool Prefix()
		{
			if ((Object)(object)LocationPanel.Instance != (Object)null && LocationPanel.Instance.IsMouseOverPanel)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MapTable), "OnWrite")]
	public static class Patch_MapTableOnWrite
	{
		[HarmonyPrefix]
		public static void Prefix()
		{
			if (LocationFinderPlugin.ShareToMapTable != null && LocationFinderPlugin.ShareToMapTable.Value)
			{
				WorldMapPinner.SetPinsSaved(saved: true);
			}
		}

		[HarmonyFinalizer]
		public static Exception Finalizer(Exception __exception)
		{
			WorldMapPinner.SetPinsSaved(saved: false);
			return __exception;
		}
	}
}
namespace LocationFinder.UI
{
	public class LocationPanel : MonoBehaviour
	{
		private struct POINT
		{
			public int X;

			public int Y;
		}

		private bool _visible = false;

		private float _closedAt = -10f;

		private const float CloseCooldown = 0.05f;

		private int _tab = 0;

		private string _searchInput = "";

		private string _searchStatus = "";

		private float _statusTimer = 0f;

		private const float StatusDuration = 4f;

		private Vector2 _scrollPos = Vector2.zero;

		private const float PanelW = 420f;

		private const float PanelH = 520f;

		private const float TabH = 32f;

		private const float FootH = 80f;

		private const float Pad = 12f;

		private static readonly Color C_Yellow = new Color(1f, 0.85f, 0.35f, 1f);

		private static readonly Color C_YellowDim = new Color(0.78f, 0.62f, 0.2f, 1f);

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

		private static readonly Color C_SubText = new Color(0.75f, 0.75f, 0.75f, 1f);

		private static readonly Color C_Shadow = new Color(0f, 0f, 0f, 0.85f);

		private static readonly Color C_DarkBox = new Color(0.05f, 0.03f, 0.01f, 0.94f);

		private static readonly Color C_TabOn = new Color(0.2f, 0.14f, 0.03f, 1f);

		private static readonly Color C_TabOff = new Color(0.1f, 0.07f, 0.01f, 0.9f);

		private static readonly Color C_RowHover = new Color(1f, 0.75f, 0.2f, 0.1f);

		private static readonly Color C_Green = new Color(0.4f, 0.9f, 0.4f, 1f);

		private static readonly Color C_Red = new Color(0.9f, 0.4f, 0.4f, 1f);

		private static readonly Color C_Border = new Color(0.55f, 0.42f, 0.12f, 1f);

		private GUIStyle _titleStyle;

		private GUIStyle _tabOnStyle;

		private GUIStyle _tabOffStyle;

		private GUIStyle _labelStyle;

		private GUIStyle _subStyle;

		private GUIStyle _btnStyle;

		private GUIStyle _inputStyle;

		private GUIStyle _statusOkStyle;

		private GUIStyle _statusErrStyle;

		private GUIStyle _checkStyle;

		private bool _stylesBuilt = false;

		private static readonly bool _isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

		private const int WindowId = 1280262977;

		public static LocationPanel Instance { get; private set; }

		public bool IsVisible => _visible;

		public bool IsBlockingInput => _visible || Time.time - _closedAt < 0.05f;

		public bool IsMouseOverPanel { get; private set; } = false;

		[DllImport("user32.dll")]
		private static extern bool SetCursorPos(int x, int y);

		[DllImport("user32.dll")]
		private static extern bool GetCursorPos(out POINT p);

		private static void WarpCursor()
		{
			if (!_isWindows)
			{
				return;
			}
			try
			{
				if (GetCursorPos(out var p))
				{
					SetCursorPos(p.X, p.Y);
				}
			}
			catch (Exception ex)
			{
				LocationFinderPlugin.Log.LogWarning((object)("[LocationFinder] WarpCursor failed: " + ex.Message));
			}
		}

		private void Awake()
		{
			Instance = this;
		}

		private void Update()
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (_statusTimer > 0f)
			{
				_statusTimer -= Time.deltaTime;
			}
			if (_visible)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
				if (Input.GetKeyDown((KeyCode)27) || Input.GetKeyDown(LocationFinderPlugin.PanelKey.Value))
				{
					Close();
				}
				if (_tab == 1 && (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271)))
				{
					DoSearch();
				}
				Input.ResetInputAxes();
			}
			else if ((Object)(object)Player.m_localPlayer != (Object)null && Input.GetKeyDown(LocationFinderPlugin.PanelKey.Value))
			{
				Chat instance = Chat.instance;
				if (instance != null && !instance.HasFocus() && !Console.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible() && !TextInput.IsVisible())
				{
					Open();
				}
			}
		}

		public void Open()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			_visible = true;
			_scrollPos = Vector2.zero;
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			WarpCursor();
		}

		public void Close()
		{
			_visible = false;
			_closedAt = Time.time;
			IsMouseOverPanel = false;
			WarpCursor();
			Cursor.lockState = (CursorLockMode)1;
			Cursor.visible = false;
		}

		private void BuildStyles()
		{
			//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)
			//IL_0026: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_005a: 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_0068: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_009f: 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_00b5: 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_00c6: 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_00d5: Expected O, but got Unknown
			//IL_00db: Expected O, but got Unknown
			//IL_00e2: 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_00ed: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Expected O, but got Unknown
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Expected O, but got Unknown
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Expected O, but got Unknown
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Expected O, but got Unknown
			if (!_stylesBuilt)
			{
				_stylesBuilt = true;
				GUIStyle val = new GUIStyle
				{
					fontSize = 15,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				val.normal.background = null;
				val.normal.textColor = C_Yellow;
				_titleStyle = val;
				GUIStyle val2 = new GUIStyle
				{
					fontSize = 12,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				val2.normal.background = MakeTex(C_TabOn);
				val2.normal.textColor = C_Yellow;
				val2.hover.background = MakeTex(C_TabOn);
				val2.hover.textColor = C_White;
				val2.padding = new RectOffset(4, 4, 4, 4);
				_tabOnStyle = val2;
				GUIStyle val3 = new GUIStyle(_tabOnStyle);
				val3.normal.background = MakeTex(C_TabOff);
				val3.normal.textColor = C_SubText;
				val3.hover.background = MakeTex(C_TabOn);
				val3.hover.textColor = C_Yellow;
				_tabOffStyle = val3;
				GUIStyle val4 = new GUIStyle
				{
					fontSize = 12,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)3
				};
				val4.normal.background = null;
				val4.normal.textColor = C_White;
				_labelStyle = val4;
				GUIStyle val5 = new GUIStyle
				{
					fontSize = 11,
					alignment = (TextAnchor)4
				};
				val5.normal.background = null;
				val5.normal.textColor = C_SubText;
				_subStyle = val5;
				GUIStyle val6 = new GUIStyle(GUI.skin.button)
				{
					fontSize = 11,
					fontStyle = (FontStyle)1
				};
				val6.normal.textColor = C_Yellow;
				val6.hover.textColor = C_White;
				_btnStyle = val6;
				GUIStyle val7 = new GUIStyle(GUI.skin.textField)
				{
					fontSize = 13
				};
				val7.normal.textColor = C_White;
				_inputStyle = val7;
				GUIStyle val8 = new GUIStyle
				{
					fontSize = 11,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4,
					wordWrap = true
				};
				val8.normal.background = null;
				val8.normal.textColor = C_Green;
				_statusOkStyle = val8;
				GUIStyle val9 = new GUIStyle(_statusOkStyle);
				val9.normal.background = null;
				val9.normal.textColor = C_Red;
				_statusErrStyle = val9;
				GUIStyle val10 = new GUIStyle(GUI.skin.toggle)
				{
					fontSize = 12
				};
				val10.normal.textColor = C_White;
				val10.hover.textColor = C_Yellow;
				val10.onNormal.textColor = C_Yellow;
				_checkStyle = val10;
			}
		}

		private void OnGUI()
		{
			//IL_0040: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_0084: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			if (_visible)
			{
				BuildStyles();
				float num = (float)Screen.width * 0.5f - 210f;
				float num2 = (float)Screen.height * 0.5f - 260f;
				GUIStyle val = new GUIStyle();
				val.normal.background = MakeTex(C_DarkBox);
				GUIStyle val2 = val;
				GUI.Window(1280262977, new Rect(num, num2, 420f, 520f), new WindowFunction(DrawWindow), "", val2);
				Rect val3 = new Rect(num, num2, 420f, 520f);
				IsMouseOverPanel = ((Rect)(ref val3)).Contains(Event.current.mousePosition);
			}
		}

		private void DrawWindow(int id)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_002e: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: 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_006d: Invalid comparison between Unknown and I4
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Invalid comparison between Unknown and I4
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			float num2 = 0f;
			Event current = Event.current;
			if ((int)current.type == 4)
			{
				if ((int)current.keyCode == 27 || current.keyCode == LocationFinderPlugin.PanelKey.Value)
				{
					Close();
					current.Use();
					return;
				}
				if (_tab == 1 && ((int)current.keyCode == 13 || (int)current.keyCode == 271))
				{
					DoSearch();
					current.Use();
				}
			}
			DrawBorder(num, num2, 420f, 520f, C_Border, 2f);
			float num3 = num2 + 12f;
			ShadowLabel(new Rect(num, num3, 420f, 22f), "⚑  LOCATION FINDER", _titleStyle);
			num3 += 26f;
			string text = ((!WorldMapPinner.IsReady) ? "Loading world data..." : ((WorldMapPinner.LocationCount > 0) ? $"{WorldMapPinner.PinCount} mod pin(s) on map" : ("Server — searching within " + ((LocationFinderPlugin.ServerSearchRadius.Value > 0f) ? (LocationFinderPlugin.ServerSearchRadius.Value.ToString("0") + "m of you") : "the loaded area"))));
			GUI.Label(new Rect(num, num3, 420f, 16f), text, _subStyle);
			num3 += 20f;
			if (GUI.Button(new Rect(num + 420f - 30f, num2 + 8f, 22f, 22f), "✕", _btnStyle))
			{
				Close();
			}
			float num4 = 132f;
			if (GUI.Button(new Rect(num + 12f, num3, num4, 32f), "Locations", (_tab == 0) ? _tabOnStyle : _tabOffStyle))
			{
				_tab = 0;
				_scrollPos = Vector2.zero;
			}
			if (GUI.Button(new Rect(num + 12f + num4, num3, num4, 32f), "Custom Search", (_tab == 1) ? _tabOnStyle : _tabOffStyle))
			{
				_tab = 1;
				_scrollPos = Vector2.zero;
			}
			if (GUI.Button(new Rect(num + 12f + num4 * 2f, num3, num4, 32f), "Quick Find", (_tab == 2) ? _tabOnStyle : _tabOffStyle))
			{
				_tab = 2;
				_scrollPos = Vector2.zero;
			}
			num3 += 36f;
			float num5 = 520f - (num3 - num2) - 80f - 12f;
			Rect area = default(Rect);
			((Rect)(ref area))..ctor(num + 12f, num3, 396f, num5);
			Fill(((Rect)(ref area)).x, ((Rect)(ref area)).y, ((Rect)(ref area)).width, ((Rect)(ref area)).height, new Color(0f, 0f, 0f, 0.3f));
			if (_tab == 0)
			{
				DrawChecklistTab(area);
			}
			else if (_tab == 1)
			{
				DrawSearchTab(area);
			}
			else
			{
				DrawQuickFindTab(area);
			}
			num3 += num5 + 12f;
			DrawBorder(num, num3 - 2f, 420f, 2f, C_Border, 2f);
			if (_tab == 0)
			{
				float num6 = 80f;
				float num7 = 6f;
				float num8 = num + (420f - num6 * 4f - num7 * 3f) * 0.5f;
				if (GUI.Button(new Rect(num8, num3 + 8f, num6, 28f), "APPLY", _btnStyle))
				{
					WorldMapPinner.ApplyCheckedCategories();
				}
				if (GUI.Button(new Rect(num8 + (num6 + num7), num3 + 8f, num6, 28f), "SEL ALL", _btnStyle))
				{
					SetAllChecked(value: true);
				}
				if (GUI.Button(new Rect(num8 + (num6 + num7) * 2f, num3 + 8f, num6, 28f), "DESEL ALL", _btnStyle))
				{
					SetAllChecked(value: false);
				}
				if (GUI.Button(new Rect(num8 + (num6 + num7) * 3f, num3 + 8f, num6, 28f), "CLR LAST", _btnStyle))
				{
					WorldMapPinner.ClearLastPin();
				}
				float num9 = num + (420f - num6 * 2f - num7) * 0.5f;
				if (GUI.Button(new Rect(num9, num3 + 40f, num6, 24f), "CLR ALL", _btnStyle))
				{
					WorldMapPinner.ClearAllPins();
				}
				if (GUI.Button(new Rect(num9 + num6 + num7, num3 + 40f, num6, 24f), "CLOSE", _btnStyle))
				{
					Close();
				}
			}
			else
			{
				float num10 = 95f;
				float num11 = 8f;
				float num12 = num + (420f - num10 * 3f - num11 * 2f) * 0.5f;
				if (GUI.Button(new Rect(num12, num3 + 8f, num10, 28f), "CLR LAST", _btnStyle))
				{
					WorldMapPinner.ClearLastPin();
				}
				if (GUI.Button(new Rect(num12 + num10 + num11, num3 + 8f, num10, 28f), "CLEAR PINS", _btnStyle))
				{
					WorldMapPinner.ClearAllPins();
				}
				if (GUI.Button(new Rect(num12 + (num10 + num11) * 2f, num3 + 8f, num10, 28f), "CLOSE", _btnStyle))
				{
					Close();
				}
			}
		}

		private static void SetAllChecked(bool value)
		{
			foreach (LocationCategory category in LocationConfig.Categories)
			{
				category.Checked = value;
			}
			foreach (LocationCategory userCategory in LocationConfig.UserCategories)
			{
				userCategory.Checked = value;
			}
		}

		private void DrawChecklistTab(Rect area)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			List<LocationCategory> list = new List<LocationCategory>();
			list.AddRange(LocationConfig.Categories);
			list.AddRange(LocationConfig.UserCategories);
			float num = 26f;
			float num2 = (float)list.Count * num + 12f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(0f, 0f, ((Rect)(ref area)).width - 16f, num2);
			_scrollPos = GUI.BeginScrollView(area, _scrollPos, val);
			float num3 = 6f;
			Rect val2 = default(Rect);
			foreach (LocationCategory item in list)
			{
				((Rect)(ref val2))..ctor(12f, num3, ((Rect)(ref area)).width - 16f - 24f, num);
				if (((Rect)(ref val2)).Contains(Event.current.mousePosition))
				{
					Fill(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, ((Rect)(ref val2)).width, ((Rect)(ref val2)).height, C_RowHover);
				}
				item.Checked = GUI.Toggle(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).y + 4f, ((Rect)(ref val2)).width, 20f), item.Checked, "  " + item.Name, _checkStyle);
				num3 += num;
			}
			GUI.EndScrollView();
		}

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

		private void DrawQuickFindTab(Rect area)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			List<QuickEntry> entries = QuickFindData.Entries;
			int num = 0;
			string text = null;
			foreach (QuickEntry item in entries)
			{
				if (item.Category != text)
				{
					num++;
					text = item.Category;
				}
			}
			float num2 = (float)entries.Count * 26f + (float)num * 24f + 24f + 22f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(0f, 0f, ((Rect)(ref area)).width - 16f, num2);
			_scrollPos = GUI.BeginScrollView(area, _scrollPos, val);
			float num3 = 6f;
			GUI.Label(new Rect(12f, num3, ((Rect)(ref area)).width - 16f - 24f, 18f), "Tick what you want and it's pinned with its own icon as it loads near you.", _subStyle);
			num3 += 22f;
			GUIStyle val2 = new GUIStyle(_subStyle)
			{
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)3
			};
			val2.normal.textColor = C_Yellow;
			GUIStyle val3 = val2;
			bool flag = false;
			List<QuickEntry> list = new List<QuickEntry>();
			string text2 = null;
			Rect val4 = default(Rect);
			foreach (QuickEntry item2 in entries)
			{
				if (item2.Category != text2)
				{
					text2 = item2.Category;
					GUI.Label(new Rect(12f, num3, ((Rect)(ref area)).width - 16f - 24f, 24f), text2.ToUpperInvariant(), val3);
					Fill(12f, num3 + 24f - 3f, ((Rect)(ref area)).width - 16f - 24f, 1f, new Color(0.55f, 0.42f, 0.12f, 0.5f));
					num3 += 24f;
				}
				((Rect)(ref val4))..ctor(12f, num3, ((Rect)(ref area)).width - 16f - 24f, 26f);
				if (((Rect)(ref val4)).Contains(Event.current.mousePosition))
				{
					Fill(((Rect)(ref val4)).x, ((Rect)(ref val4)).y, ((Rect)(ref val4)).width, ((Rect)(ref val4)).height, C_RowHover);
				}
				bool flag2 = WorldMapPinner.IsQuickActive(item2.Id);
				bool flag3 = GUI.Toggle(new Rect(((Rect)(ref val4)).x, ((Rect)(ref val4)).y + 4f, ((Rect)(ref val4)).width - 30f, 20f), flag2, "  " + item2.Name, _checkStyle);
				DrawSprite(new Rect(((Rect)(ref val4)).xMax - 26f, ((Rect)(ref val4)).y + 1f, 24f, 24f), WorldMapPinner.GetEntryIcon(item2));
				if (flag3 != flag2)
				{
					flag = true;
				}
				if (flag3)
				{
					list.Add(item2);
				}
				num3 += 26f;
			}
			GUI.EndScrollView();
			if (flag)
			{
				int num4 = WorldMapPinner.SetQuickFind(list);
				_searchStatus = ((list.Count == 0) ? "" : $"Watching {list.Count} thing(s).");
				_statusTimer = 4f;
			}
		}

		private void DrawSearchTab(Rect area)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Expected O, but got Unknown
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref area)).y + 12f;
			GUI.Label(new Rect(((Rect)(ref area)).x + 12f, num, ((Rect)(ref area)).width - 24f, 18f), "Search locations or creatures (e.g. WoodHouse, Crypt, Abomination)", _subStyle);
			num += 22f;
			GUI.SetNextControlName("LocationSearch");
			_searchInput = GUI.TextField(new Rect(((Rect)(ref area)).x + 12f, num, ((Rect)(ref area)).width - 24f - 90f, 26f), _searchInput, _inputStyle);
			GUI.FocusControl("LocationSearch");
			if (GUI.Button(new Rect(((Rect)(ref area)).x + ((Rect)(ref area)).width - 12f - 84f, num, 84f, 26f), "SEARCH", _btnStyle))
			{
				DoSearch();
			}
			num += 34f;
			if (_statusTimer > 0f && !string.IsNullOrEmpty(_searchStatus))
			{
				bool flag = _searchStatus.Contains("Pinned");
				GUI.Label(new Rect(((Rect)(ref area)).x + 12f, num, ((Rect)(ref area)).width - 24f, 40f), _searchStatus, flag ? _statusOkStyle : _statusErrStyle);
				num += 44f;
			}
			float num2 = num + 8f;
			float num3 = (((Rect)(ref area)).width - 24f) * 0.5f;
			float num4 = ((Rect)(ref area)).x + 12f;
			float num5 = ((Rect)(ref area)).x + 12f + num3;
			GUIStyle val = new GUIStyle(_subStyle)
			{
				fontStyle = (FontStyle)1
			};
			val.normal.textColor = C_Yellow;
			GUIStyle val2 = val;
			GUI.Label(new Rect(num4, num2, num3, 18f), "Seeds & Loot", val2);
			GUI.Label(new Rect(num5, num2, num3, 18f), "Rare Items", val2);
			num2 += 20f;
			Fill(num4, num2, ((Rect)(ref area)).width - 24f, 1f, new Color(0.55f, 0.42f, 0.12f, 0.5f));
			num2 += 4f;
			string[] array = new string[12]
			{
				"OnionSeeds", "Pickable_SeedCarrot", "Pickable_SeedTurnip", "Pickable_Barley", "Pickable_Flax", "Pickable_Mushroom", "Pickable_Thistle", "BlueberryBush", "RaspberryBush", "Pickable_Flint",
				"Pickable_Obsidian", "Pickable_Meteorite"
			};
			string[] array2 = new string[12]
			{
				"DragonEgg", "AncientSeed", "WitheredBone", "GoblinTotem", "BellFragment", "DvergrKeyFragment", "Obsidian", "Coins", "Ruby", "Amber",
				"AxeHead1", "AxeHead2"
			};
			GUIStyle val3 = new GUIStyle(_subStyle)
			{
				alignment = (TextAnchor)3
			};
			val3.normal.textColor = new Color(0.85f, 0.85f, 0.85f, 1f);
			GUIStyle val4 = val3;
			GUIStyle val5 = new GUIStyle(val4);
			float num6 = 18f;
			for (int i = 0; i < array.Length; i++)
			{
				float num7 = num2 + (float)i * num6;
				if (GUI.Button(new Rect(num4, num7, num3 - 4f, num6 - 1f), array[i], val4))
				{
					_searchInput = array[i];
				}
				if (i < array2.Length && GUI.Button(new Rect(num5, num7, num3 - 4f, num6 - 1f), array2[i], val4))
				{
					_searchInput = array2[i];
				}
			}
			float num8 = ((Rect)(ref area)).y + ((Rect)(ref area)).height - 18f;
			string text = ((!string.IsNullOrEmpty(WorldMapPinner.LastSearchTerm)) ? ("Tracking: " + WorldMapPinner.LastSearchTerm) : "Tip: comma-separate terms  e.g. AxeHead1, AxeHead2");
			GUI.Label(new Rect(num4, num8, ((Rect)(ref area)).width - 24f, 16f), text, _subStyle);
		}

		private void DoSearch()
		{
			string text = _searchInput.Trim();
			if (string.IsNullOrEmpty(text))
			{
				_searchStatus = "Enter a location name.";
				_statusTimer = 4f;
				return;
			}
			if (!WorldMapPinner.IsReady)
			{
				_searchStatus = "Still loading world data...";
				_statusTimer = 4f;
				return;
			}
			int num = WorldMapPinner.SearchAndPin(text);
			if (num < 0)
			{
				_searchStatus = "Not ready yet.";
			}
			else if (num == 0)
			{
				_searchStatus = "Nothing found for '" + text + "'.";
			}
			else
			{
				_searchStatus = $"Pinned {num} result(s) for '{text}'.";
			}
			_statusTimer = 4f;
		}

		private static void ShadowLabel(Rect r, string text, GUIStyle style)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(style);
			val.normal.textColor = C_Shadow;
			GUI.Label(new Rect(((Rect)(ref r)).x + 1f, ((Rect)(ref r)).y + 1f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text, val);
			GUI.Label(r, text, style);
		}

		private static void Fill(float x, float y, float w, float h, Color c)
		{
			//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)
			GUI.DrawTexture(new Rect(x, y, w, h), (Texture)(object)MakeTex(c));
		}

		private static void DrawBorder(float x, float y, float w, float h, Color c, float t)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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)
			Fill(x, y, w, t, c);
			Fill(x, y + h - t, w, t, c);
			Fill(x, y, t, h, c);
			Fill(x + w - t, y, t, h, c);
		}

		private static Texture2D MakeTex(Color c)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, c);
			val.Apply();
			return val;
		}
	}
}
namespace LocationFinder.Core
{
	public static class Assets
	{
		public static Texture2D PanelHeader;

		public static Texture2D BtnNormal;

		public static Texture2D BtnHover;

		public static Texture2D Separator;

		private static readonly Assembly _asm = Assembly.GetExecutingAssembly();

		private const string NS = "LocationFinder";

		public static bool Loaded { get; private set; }

		public static void Load()
		{
			if (!Loaded)
			{
				PanelHeader = LoadTex("woodpanel_flik.png");
				BtnNormal = LoadTex("button_tab.png");
				BtnHover = LoadTex("button_tab_hover.png");
				Separator = LoadTex("panel_separator.png");
				Loaded = true;
				LocationFinderPlugin.Log.LogInfo((object)"Assets loaded.");
			}
		}

		private static Texture2D LoadTex(string filename)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			byte[] array = ReadResource(filename);
			if (array == null)
			{
				return Fallback();
			}
			Texture2D val = new Texture2D(2, 2);
			try
			{
				Type type = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule");
				if (type != null)
				{
					MethodInfo method = type.GetMethod("LoadImage", new Type[2]
					{
						typeof(Texture2D),
						typeof(byte[])
					});
					if (method != null)
					{
						method.Invoke(null, new object[2] { val, array });
						return val;
					}
				}
				MethodInfo method2 = typeof(Texture2D).GetMethod("LoadImage", new Type[1] { typeof(byte[]) });
				if (method2 != null)
				{
					method2.Invoke(val, new object[1] { array });
					return val;
				}
			}
			catch
			{
			}
			return Fallback();
		}

		private static byte[] ReadResource(string filename)
		{
			string name = "LocationFinder.Resources." + filename;
			using Stream stream = _asm.GetManifestResourceStream(name);
			if (stream == null)
			{
				return null;
			}
			MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		private static Texture2D Fallback()
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, new Color(0.1f, 0.08f, 0.04f));
			val.Apply();
			return val;
		}
	}
	public class LocationCategory
	{
		public string Name;

		public string[] Prefabs;

		public bool Checked;

		public LocationCategory(string name, bool defaultChecked, params string[] prefabs)
		{
			Name = name;
			Prefabs = prefabs;
			Checked = defaultChecked;
		}
	}
	public static class LocationConfig
	{
		public static readonly List<LocationCategory> Categories = new List<LocationCategory>
		{
			new LocationCategory("Haldor", true, "Vendor_BlackForest"),
			new LocationCategory("Hildir", true, "Hildir_camp"),
			new LocationCategory("Bog Witch", true, "BogWitch_Camp"),
			new LocationCategory("Eikthyr Altar", false, "Eikthyrnir"),
			new LocationCategory("Elder Altar", false, "GDKing"),
			new LocationCategory("Bonemass Altar", false, "Bonemass"),
			new LocationCategory("Moder Altar", false, "Dragonqueen"),
			new LocationCategory("Yagluth Altar", false, "GoblinKing"),
			new LocationCategory("Queen Altar", false, "Mistlands_DvergrBossEntrance1"),
			new LocationCategory("Fader Altar", false, "FaderLocation"),
			new LocationCategory("Hildir Quest", false, "Hildir_plainsfortress", "Hildir_cave", "Hildir_crypt"),
			new LocationCategory("Dyrnwyn Piece", false, "PlaceofMystery1", "PlaceofMystery2", "PlaceofMystery3"),
			new LocationCategory("Burial Chamber", false, "Crypt2", "Crypt3", "Crypt4"),
			new LocationCategory("Sunken Crypt", false, "SunkenCrypt4"),
			new LocationCategory("Troll Cave", false, "TrollCave02"),
			new LocationCategory("Frost Cave", false, "MountainCave02"),
			new LocationCategory("Infested Mine", false, "Mistlands_DvergrTownEntrance1", "Mistlands_DvergrTownEntrance2"),
			new LocationCategory("Morgen Cave", false, "MorgenHole1", "MorgenHole2", "MorgenHole3"),
			new LocationCategory("Charred Fortress", false, "CharredFortress"),
			new LocationCategory("Fuling Village", false, "GoblinCamp2"),
			new LocationCategory("Draugr Village", false, "WoodVillage1", "WoodVillage2"),
			new LocationCategory("Dvergr Guard Tower", false, "Mistlands_GuardTower1_new", "Mistlands_GuardTower2_new", "Mistlands_GuardTower3_new", "Mistlands_GuardTower1_ruined_new", "Mistlands_GuardTower1_ruined_new2", "Mistlands_GuardTower3_ruined_new"),
			new LocationCategory("Forge of Potential", false, "AncientUpgradeStation"),
			new LocationCategory("Dvergr Excavation", false, "Mistlands_Excavation1", "Mistlands_Excavation2", "Mistlands_Excavation3"),
			new LocationCategory("Dvergr Harbour", false, "Mistlands_Harbour1"),
			new LocationCategory("Abandoned Cabin", false, "AbandonedLogCabin02", "AbandonedLogCabin03", "AbandonedLogCabin04"),
			new LocationCategory("Abandoned Outpost", false, "CharredTowerRuins1_dvergr"),
			new LocationCategory("Wood House", false, "WoodHouse1", "WoodHouse2", "WoodHouse3", "WoodHouse4", "WoodHouse5", "WoodHouse6", "WoodHouse7", "WoodHouse8", "WoodHouse9", "WoodHouse10", "WoodHouse11", "WoodHouse12", "WoodHouse13"),
			new LocationCategory("Dragon Egg Nest", false, "DrakeNest01"),
			new LocationCategory("Giant Remain", false, "Mistlands_Giant1", "Mistlands_Giant2"),
			new LocationCategory("Giant Scrap", false, "Mistlands_Swords1", "Mistlands_Swords2", "Mistlands_Swords3"),
			new LocationCategory("Lava Leviathan", false, "LeviathanLava"),
			new LocationCategory("Sulfur Arch", false, "SulfurArch"),
			new LocationCategory("Fire Hole", false, "FireHole"),
			new LocationCategory("Tar Pit", false, "TarPit1", "TarPit2", "TarPit3"),
			new LocationCategory("Volture Nest", false, "VoltureNest"),
			new LocationCategory("Greydwarf Nest", false, "Greydwarf_camp1"),
			new LocationCategory("Bear Cave", false, "BearCave"),
			new LocationCategory("Mountain Grave", false, "MountainGrave01"),
			new LocationCategory("Mountain Well", false, "MountainWell1"),
			new LocationCategory("Goblin Hut", false, "GoblinHut01", "GoblinHut02", "GoblinHut03"),
			new LocationCategory("Lumber Camp", false, "LumberCamp"),
			new LocationCategory("Infested Tree", false, "InfestedTree01"),
			new LocationCategory("Charred Stone Spawner", false, "CharredStone_Spawner"),
			new LocationCategory("Waymarker", false, "Waymarker01", "Waymarker02"),
			new LocationCategory("Stone Henge", false, "StoneHenge1", "StoneHenge2", "StoneHenge3", "StoneHenge4", "StoneHenge5", "StoneHenge6"),
			new LocationCategory("Stone Circle", false, "StoneCircle"),
			new LocationCategory("Fuling Tower", false, "StoneTower1", "StoneTower3"),
			new LocationCategory("Stone Tower Ruin", false, "StoneTowerRuins03", "StoneTowerRuins04", "StoneTowerRuins05", "StoneTowerRuins07", "StoneTowerRuins08", "StoneTowerRuins09", "StoneTowerRuins10", "StoneTowerRuins07_sunk", "StoneTowerRuins08_sunk", "StoneTowerRuins09_sunk", "StoneTowerRuins10_sunk"),
			new LocationCategory("Ruin", false, "Ruin1", "Ruin2", "Ruin3"),
			new LocationCategory("Combat Ruin", false, "CombatRuin01"),
			new LocationCategory("Swamp Ruin", false, "SwampRuin1", "SwampRuin2"),
			new LocationCategory("Swamp Hut", false, "SwampHut1", "SwampHut2", "SwampHut3", "SwampHut4", "SwampHut5", "SwampHut1_1", "SwampHut2_1"),
			new LocationCategory("Swamp Well", false, "SwampWell1"),
			new LocationCategory("Stone House", false, "StoneHouse3", "StoneHouse4"),
			new LocationCategory("Wood Farm", false, "WoodFarm1"),
			new LocationCategory("Ship Setting", false, "ShipSetting01", "ShipSetting02", "ShipSetting03"),
			new LocationCategory("Grave", false, "Grave1"),
			new LocationCategory("The Hole", false, "TheHole01"),
			new LocationCategory("Dolmen", false, "Dolmen01", "Dolmen02", "Dolmen03"),
			new LocationCategory("Shipwreck", false, "ShipWreck01", "ShipWreck02", "ShipWreck03", "ShipWreck04"),
			new LocationCategory("Ashlands Ruin", false, "CharredRuins1", "CharredRuins2", "CharredRuins3", "CharredRuins4", "CharredTowerRuins1", "CharredTowerRuins2", "CharredTowerRuins3", "AshlandRuins", "FortressRuins"),
			new LocationCategory("Mistlands Structure", false, "Mistlands_Viaduct1", "Mistlands_Viaduct2", "Mistlands_RockSpire1", "Mistlands_RoadPost1", "Mistlands_StatueGroup1", "Mistlands_Statue1", "Mistlands_Statue2", "Mistlands_Lighthouse1_new"),
			new LocationCategory("Runestone", false, "Runestone_Boars", "Runestone_BlackForest", "Runestone_Draugr", "Runestone_Greydwarfs", "Runestone_Swamps", "Runestone_Mountains", "Runestone_Plains", "Runestone_Mistlands", "Runestone_Ashlands", "Runestone_Meadows", "Runestone_DeepNorth", "DrakeLorestone"),
			new LocationCategory("Big Rock Clearing", false, "BigRockClearing"),
			new LocationCategory("Start Temple", false, "StartTemple"),
			new LocationCategory("Kall Fimbulbringer Lair", false, "DN_Bossroom"),
			new LocationCategory("Gammeltroll Lair", false, "DN_gammeltrollFrac01", "DN_gammeltrollFrac02"),
			new LocationCategory("Deep North Village", false, "NorthVillage"),
			new LocationCategory("Deep North Hut", false, "DN_hut01"),
			new LocationCategory("Deep North Memorial", false, "NorthMemorialPlace"),
			new LocationCategory("Frozen Shipwreck", false, "FrozenShip01_DN", "FrozenShip02_DN", "FrozenShip03_DN", "ShipWreck01_DN", "ShipWreck02_DN"),
			new LocationCategory("Ice Pond", false, "IcePond1"),
			new LocationCategory("Unknown (MorkBorg)", false, "MorkBorg")
		};

		public static readonly List<LocationCategory> UserCategories = new List<LocationCategory>();

		private static string ConfigPath => Path.Combine(Paths.ConfigPath, "YouDied.LocationFinder.checklist.txt");

		private static string UserConfigPath => Path.Combine(Paths.ConfigPath, "YouDied.LocationFinder.custom.txt");

		public static void SaveChecked()
		{
			try
			{
				List<string> list = new List<string>();
				foreach (LocationCategory category in Categories)
				{
					list.Add($"{category.Name}={category.Checked}");
				}
				foreach (LocationCategory userCategory in UserCategories)
				{
					list.Add(string.Format("[user]{0}={1}|{2}", userCategory.Name, userCategory.Checked, string.Join(",", userCategory.Prefabs)));
				}
				File.WriteAllLines(ConfigPath, list);
			}
			catch (Exception ex)
			{
				LocationFinderPlugin.Log.LogWarning((object)("[LocationFinder] Could not save checklist: " + ex.Message));
			}
		}

		public static void LoadChecked()
		{
			if (!File.Exists(ConfigPath))
			{
				return;
			}
			try
			{
				string[] array = File.ReadAllLines(ConfigPath);
				foreach (string text in array)
				{
					if (string.IsNullOrWhiteSpace(text))
					{
						continue;
					}
					if (text.StartsWith("[user]"))
					{
						string text2 = text.Substring("[user]".Length);
						int num = text2.IndexOf('=');
						if (num < 0)
						{
							continue;
						}
						string text3 = text2.Substring(0, num);
						string text4 = text2.Substring(num + 1);
						int num2 = text4.IndexOf('|');
						if (num2 < 0)
						{
							continue;
						}
						bool.TryParse(text4.Substring(0, num2), out var result);
						string[] prefabs = text4.Substring(num2 + 1).Split(new char[1] { ',' });
						bool flag = false;
						foreach (LocationCategory userCategory in UserCategories)
						{
							if (userCategory.Name == text3)
							{
								userCategory.Checked = result;
								flag = true;
								break;
							}
						}
						if (!flag)
						{
							UserCategories.Add(new LocationCategory(text3, result, prefabs));
						}
						continue;
					}
					string[] array2 = text.Split(new char[1] { '=' });
					if (array2.Length != 2)
					{
						continue;
					}
					bool.TryParse(array2[1].Trim(), out var result2);
					foreach (LocationCategory category in Categories)
					{
						if (category.Name == array2[0].Trim())
						{
							category.Checked = result2;
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				LocationFinderPlugin.Log.LogWarning((object)("[LocationFinder] Could not load checklist: " + ex.Message));
			}
		}

		public static void LoadUserCategories()
		{
			if (!File.Exists(UserConfigPath))
			{
				File.WriteAllText(UserConfigPath, "# Location Finder - Custom Categories\n# Format: CategoryName=PrefabName1,PrefabName2\n# Example:\n# My Spots=SomeLocation1,SomeLocation2\n");
				return;
			}
			string[] array = File.ReadAllLines(UserConfigPath);
			foreach (string text in array)
			{
				if (string.IsNullOrWhiteSpace(text) || text.TrimStart(Array.Empty<char>()).StartsWith("#"))
				{
					continue;
				}
				string[] array2 = text.Split(new char[1] { '=' });
				if (array2.Length != 2)
				{
					continue;
				}
				string name = array2[0].Trim();
				string[] array3 = array2[1].Split(new char[1] { ',' });
				List<string> list = new List<string>();
				string[] array4 = array3;
				foreach (string text2 in array4)
				{
					if (!string.IsNullOrWhiteSpace(text2))
					{
						list.Add(text2.Trim());
					}
				}
				if (list.Count != 0)
				{
					UserCategories.Add(new LocationCategory(name, defaultChecked: false, list.ToArray()));
				}
			}
			LocationFinderPlugin.Log.LogInfo((object)$"[LocationFinder] Loaded {UserCategories.Count} custom categories.");
		}
	}
	public static class LocationSync
	{
		public const string RpcRequest = "YouDied_LF_RequestLocations";

		public const string RpcResponse = "YouDied_LF_Locations";

		private const int FormatVersion = 1;

		private const string FileMagic = "LF1";

		private static FieldInfo FindLocationDictField()
		{
			FieldInfo field = typeof(ZoneSystem).GetField("m_locationInstances", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return field;
			}
			FieldInfo[] fields = typeof(ZoneSystem).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				Type fieldType = fieldInfo.FieldType;
				if (fieldType.IsGenericType)
				{
					Type[] genericArguments = fieldType.GetGenericArguments();
					if (genericArguments.Length == 2 && genericArguments[1].Name.Contains("LocationInstance"))
					{
						return fieldInfo;
					}
				}
			}
			return null;
		}

		public static List<(string prefab, Vector3 pos)> ReadFromZoneSystem()
		{
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			List<(string, Vector3)> list = new List<(string, Vector3)>();
			if ((Object)(object)ZoneSystem.instance == (Object)null)
			{
				return list;
			}
			FieldInfo fieldInfo = FindLocationDictField();
			if (fieldInfo == null)
			{
				return list;
			}
			if (!(fieldInfo.GetValue(ZoneSystem.instance) is IDictionary { Count: not 0 } dictionary))
			{
				return list;
			}
			FieldInfo fieldInfo2 = null;
			FieldInfo fieldInfo3 = null;
			FieldInfo fieldInfo4 = null;
			foreach (object value2 in dictionary.Values)
			{
				if (value2 == null)
				{
					continue;
				}
				if (fieldInfo2 == null)
				{
					Type type = value2.GetType();
					fieldInfo2 = type.GetField("m_location");
					fieldInfo3 = type.GetField("m_position");
					if (fieldInfo2 == null || fieldInfo3 == null)
					{
						return list;
					}
				}
				object value = fieldInfo2.GetValue(value2);
				if (value != null)
				{
					if (fieldInfo4 == null)
					{
						fieldInfo4 = value.GetType().GetField("m_prefabName");
					}
					if (fieldInfo4 == null)
					{
						return list;
					}
					string text = fieldInfo4.GetValue(value) as string;
					if (!string.IsNullOrEmpty(text))
					{
						list.Add((text, (Vector3)fieldInfo3.GetValue(value2)));
					}
				}
			}
			return list;
		}

		public static string ExportPath(string dir, long worldUid)
		{
			return Path.Combine(dir, "YouDied.LocationFinder.world-" + worldUid + ".txt");
		}

		public static bool SaveExport(string path, long worldUid, string worldName, List<(string prefab, Vector3 pos)> locations)
		{
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			if (locations == null || locations.Count == 0)
			{
				return false;
			}
			if (File.Exists(path))
			{
				try
				{
					using StreamReader streamReader = new StreamReader(path);
					string[] array = (streamReader.ReadLine() ?? "").Split(new char[1] { '|' });
					if (array.Length >= 4 && array[0] == "LF1" && array[1] == worldUid.ToString(CultureInfo.InvariantCulture) && array[3] == locations.Count.ToString(CultureInfo.InvariantCulture))
					{
						return false;
					}
				}
				catch
				{
				}
			}
			StringBuilder stringBuilder = new StringBuilder(locations.Count * 40 + 128);
			stringBuilder.Append("LF1").Append('|').Append(worldUid.ToString(CultureInfo.InvariantCulture))
				.Append('|')
				.Append((worldName ?? "").Replace('|', '_').Replace('\n', ' '))
				.Append('|')
				.Append(locations.Count.ToString(CultureInfo.InvariantCulture))
				.Append('\n');
			foreach (var location in locations)
			{
				StringBuilder stringBuilder2 = stringBuilder.Append(location.prefab).Append('|');
				float x = location.pos.x;
				StringBuilder stringBuilder3 = stringBuilder2.Append(x.ToString("R", CultureInfo.InvariantCulture)).Append('|');
				x = location.pos.y;
				StringBuilder stringBuilder4 = stringBuilder3.Append(x.ToString("R", CultureInfo.InvariantCulture)).Append('|');
				x = location.pos.z;
				stringBuilder4.Append(x.ToString("R", CultureInfo.InvariantCulture)).Append('\n');
			}
			File.WriteAllText(path, stringBuilder.ToString());
			return true;
		}

		public static List<(string prefab, Vector3 pos)> LoadExport(string path, long worldUid, out string worldName)
		{
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			worldName = null;
			if (!File.Exists(path))
			{
				return null;
			}
			using StreamReader streamReader = new StreamReader(path);
			string[] array = (streamReader.ReadLine() ?? "").Split(new char[1] { '|' });
			if (array.Length < 4 || array[0] != "LF1")
			{
				return null;
			}
			if (array[1] != worldUid.ToString(CultureInfo.InvariantCulture))
			{
				return null;
			}
			worldName = array[2];
			int.TryParse(array[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result);
			List<(string, Vector3)> list = new List<(string, Vector3)>((result > 0) ? result : 1024);
			string text;
			while ((text = streamReader.ReadLine()) != null)
			{
				string[] array2 = text.Split(new char[1] { '|' });
				if (array2.Length == 4 && float.TryParse(array2[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3) && float.TryParse(array2[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result4))
				{
					list.Add((array2[0], new Vector3(result2, result3, result4)));
				}
			}
			return list;
		}

		public static ZPackage Build(List<(string prefab, Vector3 pos)> locations)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_0102: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			List<string> list = new List<string>();
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			foreach (var location in locations)
			{
				if (!dictionary.ContainsKey(location.prefab))
				{
					dictionary[location.prefab] = list.Count;
					list.Add(location.prefab);
				}
			}
			ZPackage val = new ZPackage();
			val.Write(1);
			val.Write(list.Count);
			foreach (string item in list)
			{
				val.Write(item);
			}
			val.Write(locations.Count);
			foreach (var location2 in locations)
			{
				val.Write(dictionary[location2.prefab]);
				val.Write(location2.pos.x);
				val.Write(location2.pos.y);
				val.Write(location2.pos.z);
			}
			ZPackage val2 = new ZPackage();
			val2.WriteCompressed(val);
			return val2;
		}

		public static List<(string prefab, Vector3 pos)> Parse(ZPackage outer)
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = outer.ReadCompressedPackage();
			int num = val.ReadInt();
			if (num != 1)
			{
				return null;
			}
			int num2 = val.ReadInt();
			string[] array = new string[num2];
			for (int i = 0; i < num2; i++)
			{
				array[i] = val.ReadString();
			}
			int num3 = val.ReadInt();
			List<(string, Vector3)> list = new List<(string, Vector3)>(num3);
			for (int j = 0; j < num3; j++)
			{
				int num4 = val.ReadInt();
				float num5 = val.ReadSingle();
				float num6 = val.ReadSingle();
				float num7 = val.ReadSingle();
				if (num4 >= 0 && num4 < num2)
				{
					list.Add((array[num4], new Vector3(num5, num6, num7)));
				}
			}
			return list;
		}
	}
	public class QuickEntry
	{
		public string Id;

		public string Name;

		public string Category;

		public string[] Tokens;

		public string Icon;

		public bool Creature;

		public bool Chest;

		public QuickEntry AsChest()
		{
			Chest = true;
			return this;
		}

		public QuickEntry(string category, string name, bool creature, string icon, params string[] tokens)
		{
			Category = category;
			Name = name;
			Creature = creature;
			Icon = icon;
			Tokens = tokens;
			Id = (category + "_" + name).Replace(' ', '_');
		}

		public bool Matches(string objectName)
		{
			string[] tokens = Tokens;
			foreach (string value in tokens)
			{
				if (objectName.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			return false;
		}
	}
	public static class QuickFindData
	{
		public static readonly List<QuickEntry> Entries = new List<QuickEntry>
		{
			new QuickEntry("Plants", "Dandelion", false, "Dandelion", "dandelion"),
			new QuickEntry("Plants", "Mushrooms", false, "Mushroom", "pickable_mushroom"),
			new QuickEntry("Plants", "Blueberries", false, "Blueberries", "blueberry"),
			new QuickEntry("Plants", "Raspberries", false, "Raspberry", "raspberry"),
			new QuickEntry("Plants", "Cloudberries", false, "Cloudberry", "cloudberry"),
			new QuickEntry("Plants", "Thistle", false, "Thistle", "thistle"),
			new QuickEntry("Plants", "Wild Flax", false, "Flax", "pickable_flax"),
			new QuickEntry("Plants", "Wild Barley", false, "Barley", "pickable_barley"),
			new QuickEntry("Plants", "Carrot Seeds", false, "CarrotSeeds", "seedcarrot"),
			new QuickEntry("Plants", "Turnip Seeds", false, "TurnipSeeds", "seedturnip"),
			new QuickEntry("Plants", "Jotun Puffs", false, "MushroomJotunPuffs", "jotunpuffs"),
			new QuickEntry("Plants", "Magecap", false, "MushroomMagecap", "magecap"),
			new QuickEntry("Plants", "Flint", false, "Flint", "pickable_flint"),
			new QuickEntry("Plants", "Bee Nest", false, "Honey", "beenest"),
			new QuickEntry("Chest loot", "Onion Seeds", false, "Onion", "OnionSeeds").AsChest(),
			new QuickEntry("Ores", "Copper", false, "CopperOre", "copper"),
			new QuickEntry("Ores", "Tin", false, "TinOre", "minerock_tin", "_tin"),
			new QuickEntry("Ores", "Iron (scrap piles)", false, "IronScrap", "mudpile"),
			new QuickEntry("Ores", "Silver", false, "SilverOre", "silver"),
			new QuickEntry("Ores", "Obsidian", false, "Obsidian", "obsidian"),
			new QuickEntry("Ores", "Flametal", false, "FlametalOreNew", "flametal"),
			new QuickEntry("Animals", "Boar", true, null, "boar"),
			new QuickEntry("Animals", "Deer", true, null, "deer"),
			new QuickEntry("Animals", "Wolf", true, null, "wolf"),
			new QuickEntry("Animals", "Lox", true, null, "lox"),
			new QuickEntry("Animals", "Hare", true, null, "hare"),
			new QuickEntry("Animals", "Serpent", true, null, "serpent"),
			new QuickEntry("Enemies", "Neck", true, null, "neck"),
			new QuickEntry("Enemies", "Greydwarf", true, null, "greydwarf"),
			new QuickEntry("Enemies", "Troll", true, null, "troll"),
			new QuickEntry("Enemies", "Skeleton", true, null, "skeleton"),
			new QuickEntry("Enemies", "Draugr", true, null, "draugr"),
			new QuickEntry("Enemies", "Blob", true, null, "blob"),
			new QuickEntry("Enemies", "Leech", true, null, "leech"),
			new QuickEntry("Enemies", "Abomination", true, null, "abomination"),
			new QuickEntry("Enemies", "Surtling", true, null, "surtling"),
			new QuickEntry("Enemies", "Wraith", true, null, "wraith"),
			new QuickEntry("Enemies", "Fenring", true, null, "fenring"),
			new QuickEntry("Enemies", "Goblin", true, null, "goblin"),
			new QuickEntry("Enemies", "Deathsquito", true, null, "deathsquito"),
			new QuickEntry("Enemies", "Seeker", true, null, "seeker"),
			new QuickEntry("Enemies", "Gjall", true, null, "gjall"),
			new QuickEntry("Enemies", "Tick", true, null, "tick"),
			new QuickEntry("Enemies", "Dvergr", true, null, "dverger")
		};
	}
	public static class WorldMapPinner
	{
		private static readonly Dictionary<string, PinData> _pins = new Dictionary<string, PinData>();

		private static readonly List<(string prefab, Vector3 pos)> _locationCache = new List<(string, Vector3)>();

		private static readonly HashSet<string> _exclusiveLocationPrefabs = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Vendor_BlackForest", "Hildir_camp", "BogWitch_Camp", "AncientUpgradeStation" };

		private static readonly Dictionary<string, string> _exclusiveSpawnMarkers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
		{
			{ "UpgradeStation", "AncientUpgradeStation" },
			{ "Hildir", "Hildir_camp" },
			{ "Haldor", "Vendor_BlackForest" },
			{ "BogWitch", "BogWitch_Camp" }
		};

		private static readonly Dictionary<string, Vector3> _resolvedExclusivePositions = new Dictionary<string, Vector3>(StringComparer.OrdinalIgnoreCase);

		private static bool _ready = false;

		private static bool _shutdown = false;

		private static IDictionary _locationDict = null;

		private static FieldInfo _locField = null;

		private static FieldInfo _posField = null;

		private static FieldInfo _nameField = null;

		private static bool _initStarted = false;

		private static MonoBehaviour _host;

		private static bool _liveMode;

		private static readonly HashSet<string> _liveKeys = new HashSet<string>();

		private static int _zdoLocationHash;

		private static bool _liveReflectionFailed;

		private static IDictionary _locationsByHash;

		private static FieldInfo _liveNameField;

		private static int _liveScanCount;

		private static ZRoutedRpc _rpcRegisteredOn;

		private static readonly List<(string prefab, Vector3 pos)> _exclusiveCandidates = new List<(string, Vector3)>();

		private static readonly HashSet<string> _diagnosedNearbyNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		private static string[] _activeTerms = new string[0];

		private static readonly Dictionary<string, (Vector3 pos, List<string> items)> _chestRegistry = new Dictionary<string, (Vector3, List<string>)>();

		private static QuickEntry[] _activeQuick = new QuickEntry[0];

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

		private static readonly Dictionary<string, (Vector3 pos, List<string> items)> _qfChests = new Dictionary<string, (Vector3, List<string>)>();

		private static int _zdoItemsHash;

		private static int _zdoRolledHash;

		private static bool _zdoHashTried;

		private static int _chestMismatchLogged;

		private static bool _zdoParseWarned;

		private static int _chestScanCount;

		private static int _chestSeen;

		private static int _chestNatural;

		private static int _chestDiagLogged;

		private static int _chestUnknown;

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

		public static bool IsReady => _ready;

		public static int PinCount => _pins.Count;

		public static int LocationCount => _locationCache.Count;

		public static string LastSearchTerm { get; private set; } = null;

		public static int ChestRegistryCount => _chestRegistry.Count;

		public static void SetPinsSaved(bool saved)
		{
			foreach (PinData value in _pins.Values)
			{
				if (value != null)
				{
					value.m_save = saved;
				}
			}
		}

		public static void BeginInit(MonoBehaviour host)
		{
			if (!_initStarted && !_shutdown)
			{
				_initStarted = true;
				_shutdown = false;
				_host = host;
				MonoBehaviour val = (MonoBehaviour)(((object)LocationPanel.Instance) ?? ((object)host));
				val.StartCoroutine(WaitForReady());
				val.StartCoroutine(RpcRegistrationWatch());
				LocationFinderPlugin.Log.LogInfo((object)("[LocationFinder] BeginInit on " + ((object)val).GetType().Name));
			}
		}

		private static IEnumerator WaitForReady()
		{
			while (!_shutdown && (Object)(object)ZoneSystem.instance == (Object)null)
			{
				yield return null;
			}
			if (_shutdown)
			{
				yield break;
			}
			FieldInfo locField = FindLocationInstancesField();
			if (locField != null)
			{
				float waited = 0f;
				while (!_shutdown && waited < 10f)
				{
					if ((Object)(object)ZoneSystem.instance == (Object)null)
					{
						yield break;
					}
					if ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer())
					{
						break;
					}
					object raw = locField.GetValue(ZoneSystem.instance);
					IDictionary dict = raw as IDictionary;
					if (dict != null && dict.Count > 0)
					{
						_locationDict = dict;
						break;
					}
					yield return (object)new WaitForSeconds(0.5f);
					waited += 0.5f;
				}
			}
			if (_shutdown)
			{
				yield break;
			}
			while (!_shutdown && (Object)(object)Minimap.instance == (Object)null)
			{
				yield return null;
			}
			if (_shutdown)
			{
				yield break;
			}
			SafeStep("cache", BuildLocationCache);
			SafeStep("export", TryExportWorldLocations);
			if (_locationCache.Count == 0 && (Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer() && LocationFinderPlugin.ServerFullMap.Value)
			{
				SafeStep("import", delegate
				{
					TryImportWorldLocations();
				});
			}
			SafeStep("uncategorized", LogUncategorizedPrefabs);
			SafeStep("config", LocationConfig.LoadChecked);
			_ready = true;
			bool needsServerData = _locationCache.Count == 0 && (Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer();
			LocationFinderPlugin.Log.LogInfo((object)($"[LocationFinder] Ready. {_locationCache.Count} world locations cached." + (needsServerData ? " (server — no full location list; searching near you)" : "")));
			if (needsServerData)
			{
				_liveMode = true;
				float r = LocationFinderPlugin.ServerSearchRadius.Value;
				LocationFinderPlugin.Log.LogInfo((object)("[LocationFinder] Live mode on: locations within " + ((r > 0f) ? (r.ToString("0") + "m of you") : "the loaded area") + " are pinned as they load."));
				if (LocationFinderPlugin.ServerFullMap.Value)
				{
					MonoBehaviour requester = (MonoBehaviour)(((object)LocationPanel.Instance) ?? ((object)_host));
					if ((Object)(object)requester != (Object)null)
					{
						requester.StartCoroutine(RequestLocationsFromServer());
					}
				}
			}
			SafeStep("apply", ApplyCheckedCategories);
			if ((Object)(object)LocationPanel.Instance != (Object)null)
			{
				((MonoBehaviour)LocationPanel.Instance).StartCoroutine(ScanAfterSpawn());
			}
			else if ((Object)(object)_host != (Object)null)
			{
				_host.StartCoroutine(ScanAfterSpawn());
			}
		}

		private static IEnumerator ScanAfterSpawn()
		{
			while ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				yield return (object)new WaitForSeconds(0.5f);
			}
			yield return (object)new WaitForSeconds(2f);
			LocationFinderPlugin.Log.LogInfo((object)"[LocationFinder] Running post-spawn scan...");
			ScanLoadedBeehivesAndExclusives();
			ScanLoadedPickables();
			while (!_shutdown && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				bool fast = false;
				QuickEntry[] activeQuick = _activeQuick;
				foreach (QuickEntry qe in activeQuick)
				{
					if (qe.Chest)
					{
						fast = true;
						break;
					}
				}
				yield return (object)new WaitForSeconds(fast ? 1.5f : 4f);
				if (_shutdown)
				{
					break;
				}
				ScanLoadedBeehivesAndExclusives();
				if (_activeTerms.Length != 0)
				{
					ScanLoadedPickables();
				}
			}
		}

		private static void BuildLocationCache()
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			_locationCache.Clear();
			if (_locationDict == null)
			{
				return;
			}
			foreach (object value in _locationDict.Values)
			{
				if (value == null)
				{
					continue;
				}
				if (_locField == null)
				{
					Type type = value.GetType();
					_locField = type.GetField("m_location");
					_posField = type.GetField("m_position");
				}
				object obj = _locField?.GetValue(value);
				if (obj != null)
				{
					if (_nameField == null)
					{
						_nameField = obj.GetType().GetField("m_prefabName");
					}
					string text = _nameField?.GetValue(obj) as string;
					if (!string.IsNullOrEmpty(text))
					{
						Vector3 item = (Vector3)_posField.GetValue(value);
						_locationCache.Add((text, item));
					}
				}
			}
			RebuildExclusiveCandidates();
			LocationFinderPlugin.Log.LogInfo((object)$"[LocationFinder] Cache built: {_locationCache.Count} entries.");
		}

		private static void RebuildExclusiveCandidates()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			_exclusiveCandidates.Clear();
			foreach (var (text, item) in _locationCache)
			{
				if (_exclusiveLocationPrefabs.Contains(text))
				{
					_exclusiveCandidates.Add((text, item));
				}
			}
		}

		private static void EnsureLiveReflection()
		{
			if (_zdoLocationHash == 0 && !_liveReflectionFailed)
			{
				try
				{
					FieldInfo fieldInfo = typeof(ZNetView).Assembly.GetType("ZDOVars")?.GetField("s_location", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (fieldInfo != null)
					{
						_zdoLocationHash = (int)fieldInfo.GetValue(null);
					}
				}
				catch
				{
				}
				if (_zdoLocationHash == 0)
				{
					_liveReflectionFailed = true;
					LocationFinderPlugin.Log.LogWarning((object)"[LocationFinder] Live discovery unavailable: couldn't find ZDOVars.s_location in this game version.");
				}
			}
			if (_locationsByHash == null && (Object)(object)ZoneSystem.instance != (Object)null)
			{
				try
				{
					_locationsByHash = typeof(ZoneSystem).GetField("m_locationsByHash", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(ZoneSystem.instance) as IDictionary;
				}
				catch
				{
				}
			}
		}

		private static void ScanLiveLocations(ZNetView[] allViews)
		{
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			EnsureLiveReflection();
			List<(string, Vector3)> list = new List<(string, Vector3)>();
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			if (_zdoLocationHash != 0 && _locationsByHash != null)
			{
				foreach (ZNetView val in allViews)
				{
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					string name = ((Object)((Component)val).gameObject).name;
					if (string.CompareOrdinal(name, 0, "LocationProxy", 0, 13) != 0)
					{
						continue;
					}
					num++;
					ZDO zDO = val.GetZDO();
					if (zDO == null)
					{
						continue;
					}
					int num4 = zDO.GetInt(_zdoLocationHash, 0);
					if (num4 == 0)
					{
						continue;
					}
					num2++;
					if (!_locationsByHash.Contains(num4))
					{
						continue;
					}
					object obj = _locationsByHash[num4];
					if (obj != null)
					{
						if (_liveNameField == null)
						{
							_liveNameField = obj.GetType().GetField("m_prefabName");
						}
						string text = _liveNameField?.GetValue(obj) as string;
						if (!string.IsNullOrEmpty(text))
						{
							num3++;
							list.Add((text, ((Component)val).transform.position));
						}
					}
				}
			}
			int num5 = 0;
			try
			{
				Location[] array = Object.FindObjectsOfType<Location>();
				Location[] array2 = array;
				foreach (Location val2 in array2)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						num5++;
						string text2 = ((Object)((Component)val2).gameObject).name.Replace("(Clone)", "").Trim();
						if (text2.Length != 0)
						{
							list.Add((text2, ((Component)val2).transform.position));
						}
					}
				}
			}
			catch (Exception ex)
			{
				if (_liveScanCount == 0)
				{
					LocationFinderPlugin.Log.LogWarning((object)("[LocationFinder] Location component scan failed: " + ex.Message));
				}
			}
			_liveScanCount++;
			if (_liveScanCount <= 3 || _liveScanCount % 15 == 0)
			{
				LocationFinderPlugin.Log.LogInfo((object)($"[LocationFinder] Live scan #{_liveScanCount}: {allViews.Length} objects, " + $"{num} proxies ({num2} with hash, {num3} resolved), " + $"{num5} Location components; hashVar={_zdoLocationHash != 0}, " + "hashTable=" + ((_locationsByHash != null) ? _locationsByHash.Count.ToString() : "null") + "."));
			}
			HashSet<string> pinnedPrefabs = null;
			Dictionary<string, string> prefabToLabel = null;
			int num6 = 0;
			List<string> list2 = new List<string>();
			float value = LocationFinderPlugin.ServerSearchRadius.Value;
			Player localPlayer = Player.m_localPlayer;
			bool flag = value > 0f && (Object)(object)localPlayer != (Object)null;
			Vector3 val3 = (Vector3)(flag ? ((Component)localPlayer).transform.position : default(Vector3));
			float num7 = value * value;
			foreach (var (text3, val4) in list)
			{
				if (flag)
				{
					float num8 = val4.x - val3.x;
					float num9 = val4.z - val3.z;
					if (num8 * num8 + num9 * num9 > num7)
					{
						continue;
					}
				}
				string item = $"{text3}|{Mathf.RoundToInt(val4.x)}|{Mathf.RoundToInt(val4.z)}";
				if (_liveKeys.Add(item))
				{
					_locationCache.Add((text3, val4));
					if (_exclusiveLocationPrefabs.Contains(text3))
					{
						_exclusiveCandidates.Add((text3, val4));
					}
					num6++;
					if (list2.Count < 6)
					{
						list2.Add(text3);
					}
					if (pinnedPrefabs == null)
					{
						BuildWantedSet(out pinnedPrefabs, out prefabToLabel);
					}
					if (pinnedPrefabs.Contains(text3) && (!_resolvedExclusivePositions.TryGetValue(text3, out var value2) || !(Vector3.Distance(val4, value2) > 5f)))
					{
						PinLocation(text3, val4, prefabToLabel);
					}
				}
			}
			if (num6 > 0)
			{
				LocationFinderPlugin.Log.LogInfo((object)(string.Format("[LocationFinder] Live: {0} new location(s) near you ({1}", num6, string.Join(", ", list2)) + string.Format("{0}); {1} known.", (num6 > list2.Count) ? ", ..." : "", _locationCache.Count)));
			}
		}

		private static long WorldUid()
		{
			try
			{
				MethodInfo method = typeof(ZNet).GetMethod("GetWorldUID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					return Convert.ToInt64(method.Invoke(ZNet.instance, null));
				}
			}
			catch
			{
			}
			return 0L;
		}

		private static string WorldName()
		{
			try
			{
				MethodInfo method = typeof(ZNet).GetMethod("GetWorldName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					return (method.Invoke(ZNet.instance, null) as string) ?? "";
				}
			}
			catch
			{
			}
			return "";
		}

		private static void SafeStep(string name, Action a)
		{
			try
			{
				a();
			}
			catch (Exception ex)
			{
				LocationFinderPlugin.Log.LogWarning((object)("[LocationFinder] Startup step '" + name + "' failed: " + ex.GetType().Name + ": " + ex.Message));
			}
		}

		private static void TryExportWorldLocations()
		{
			try
			{
				if (LocationFinderPlugin.ExportWorldLocations.Value && _locationCache.Count != 0 && !((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
				{
					long worldUid = WorldUid();
					string path = LocationSync.ExportPath(Paths.ConfigPath, worldUid);
					if (LocationSync.SaveExport(path, worldUid, WorldName(), _locationCache))
					{
						LocationFinderPlugin.Log.LogInfo((object)($"[LocationFinder] Saved {_locationCache.Count} locations for world " + "'" + WorldName() + "' to " + Path.GetFileName(path) + "."));
					}
				}
			}
			catch (Exception ex)
			{
				LocationFinderPlugin.Log.LogWarning((object)("[LocationFinder] Could not save world locations: " + ex.Message));
			}
		}

		private static bool TryImportWorldLocations()
		{
			try
			{
				if ((Object)(object)ZNet.instance == (Object)null)
				{
					return false;
				}
				long num = WorldUid();
				if (num == 0)
				{
					return false;
				}
				string path = LocationSync.ExportPath(Paths.ConfigPath, num);
				string worldName;
				List<(string, Vector3)> list = LocationSync.LoadExport(path, num, out worldName);
				if (list == null || list.Count == 0)
				{
					return false;
				}
				_locationCache.Clear();
				_locationCache.AddRange(list);
				RebuildExclusiveCandidates();
				LocationFinderPlugin.Log.LogInfo((object)($"[LocationFinder] Loaded {_locationCache.Count} locations for world '{worldName}' " + "from saved export " + Path.GetFileName(path) + "."));
				return true;
			}
			catch (Exception ex)
			{
				LocationFinderPlugin.Log.LogWarning((object)("[LocationFinder] Could not read saved world locations: " + ex.Message));
				return false;
			}
		}

		private static void EnsureRpcRegistered()
		{
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null && instance != _rpcRegisteredOn)
			{
				instance.Register("YouDied_LF_RequestLocations", (Action<long>)RPC_Request);
				instance.Register<ZPackage>("YouDied_LF_Locations", (Action<long, ZPackage>)RPC_Locations);
				_rpcRegisteredOn = instance;
			}
		}

		private static IEnumerator RpcRegistrationWatch()
		{
			while (!_shutdown)
			{
				try
				{
					EnsureRpcRegistered();
				}
				catch
				{
				}
				yield return (object)new WaitForSeconds(1f);
			}
		}

		private static void RPC_Request(long sender)
		{
			if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer() && _locationCache.Count != 0)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "YouDied_LF_Locations", new object[1] { LocationSync.Build(_locationCache) });
			}
		}

		private static void RPC_Locations(long sender, ZPackage pkg)
		{
			List<(string, Vector3)> list;
			try
			{
				list = LocationSync.Parse(pkg);
			}
			catch (Exception ex)
			{
				LocationFinderPlugin.Log.LogWarning((object)("[LocationFinder] Could not read location data from server: " + ex.Message));
				return;
			}
			if (list == null)
			{
				LocationFinderPlugin.Log.LogWarning((object)"[LocationFinder] Server sent location data in an incompatible format — update LocationFinder and LocationFinderServer to matching versions.");
				return;
			}
			_locationCache.Clear();
			_locationCache.AddRange(list);
			_liveMode = false;
			_liveScanCount = 0;
			_activeQuick = new QuickEntry[0];
			_spriteCache.Clear();
			_qfChests.Clear();
			_qfStable.Clear();
			_chestUnknown = 0;
			RebuildExclusiveCandidates();
			LocationFinderPlugin.Log.LogInfo((object)$"[LocationFinder] Received {_locationCache.Count} locations from server.");
			LogUncategorizedPrefabs();
			if (_ready)
			{
				ApplyCheckedCategories();
			}
		}

		private static long GetServerPeerId()
		{
			try
			{
				ZRoutedRpc instance = ZRoutedRpc.instance;
				MethodInfo methodInfo = ((object)instance)?.GetType().GetMethod("GetServerPeerID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (methodInfo != null)
				{
					return (long)methodInfo.Invoke(instance, null);
				}
				ZNet instance2 = ZNet.instance;
				object obj = (((object)instance2)?.GetType().GetMethod("GetServerPeer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))?.Invoke(instance2, null);
				if (obj == null)
				{
					return 0L;
				}
				FieldInfo field = obj.GetType().GetField("m_uid", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					return (long)field.GetValue(obj);
				}
				MethodInfo method = obj.GetType().GetMethod("GetUID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					return (long)method.Invoke(obj, null);
				}
			}
			catch
			{
			}
			return 0L;
		}

		private static IEnumerator RequestLocationsFromServer()
		{
			int requestsSent = 0;
			for (int attempt = 1; attempt <= 8; attempt++)
			{
				if (_shutdown)
				{
					break;
				}
				if (_locationCache.Count != 0)
				{
					break;
				}
				if (TryImportWorldLocations())
				{
					_liveMode = false;
					LogUncategorizedPrefabs();
					ApplyCheckedCategories();
					yield break;
				}
				try
				{
					EnsureRpcRegistered();
				}
				catch
				{
				}
				ZRoutedRpc rpc = ZRoutedRpc.instance;
				long serverId = ((requestsSent < 2 && rpc != null) ? GetServerPeerId() : 0);
				if (serverId != 0)
				{
					rpc.InvokeRoutedRPC(serverId, "YouDied_LF_RequestLocations", Array.Empty<object>());
					requestsSent++;
					LocationFinderPlugin.Log.LogInfo((object)$"[LocationFinder] Requested location data from server ({requestsSent}/2).");
				}
				yield return (object)new WaitForSeconds(5f);
			}
			if (!_shutdown && _locationCache.Count == 0)
			{
				LocationFinderPlugin.Log.LogInfo((object)"[LocationFinder] No full location list for this server world — staying in live mode: locations are pinned as they load around you. For the whole map, load a COPY of this server's world file in single player once (the mod saves its list automatically), then rejoin.");
			}
		}

		private static void LogUncategorizedPrefabs()
		{
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			foreach (LocationCategory category in LocationConfig.Categories)
			{
				string[] prefabs = category.Prefabs;
				foreach (string item in prefabs)
				{
					hashSet.Add(item);
				}
			}
			foreach (LocationCategory userCategory in LocationConfig.UserCategories)
			{
				string[] prefabs2 = userCategory.Prefabs;
				foreach (string item2 in prefabs2)
				{
					hashSet.Add(item2);
				}
			}
			HashSet<string> hashSet2 = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			List<string> list = new List<string>();
			foreach (var item3 in _locationCache)
			{
				if (hashSet2.Add(item3.prefab) && !hashSet.Contains(i