Decompiled source of MasterPortal Ymiron v1.3.0

MasterPortal.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MasterPortal.Visuals;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MasterPortal")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0")]
[assembly: AssemblyProduct("MasterPortal")]
[assembly: AssemblyTitle("MasterPortal")]
[assembly: AssemblyVersion("1.3.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MasterPortal
{
	public class HubPortal : MonoBehaviour
	{
		internal const int NameMaxLength = 32;

		private const float MenuRange = 6f;

		private const string RpcSetNames = "MasterPortal_SetNames";

		private const string KeyNetwork = "MasterPortal_Network";

		private const string KeyName = "MasterPortal_Name";

		private static readonly int NetworkHash = StringExtensionMethods.GetStableHashCode("MasterPortal_Network");

		private static readonly int NameHash = StringExtensionMethods.GetStableHashCode("MasterPortal_Name");

		public bool m_isMaster;

		private ZNetView _nview;

		private TeleportWorld _teleport;

		internal bool IsMaster => m_isMaster;

		private ZDO Zdo
		{
			get
			{
				if (!((Object)(object)_nview != (Object)null) || !_nview.IsValid())
				{
					return null;
				}
				return _nview.GetZDO();
			}
		}

		internal Vector3 Position => ((Component)this).transform.position;

		private void Awake()
		{
			_nview = ((Component)this).GetComponent<ZNetView>();
			_teleport = ((Component)this).GetComponent<TeleportWorld>();
			if ((Object)(object)_nview != (Object)null && _nview.GetZDO() != null)
			{
				_nview.Register<string, string>("MasterPortal_SetNames", (Action<long, string, string>)RPC_SetNames);
			}
		}

		internal static void ReadNames(ZDO zdo, bool isMaster, out string network, out string name)
		{
			network = zdo.GetString(NetworkHash, "").Trim();
			name = (isMaster ? string.Empty : zdo.GetString(NameHash, "").Trim());
			if (network.Length <= 0 && name.Length <= 0)
			{
				string text = zdo.GetString(ZDOVars.s_tag, "").Trim();
				int num = (isMaster ? (-1) : text.IndexOf('/'));
				network = ((num < 0) ? text : text.Substring(0, num).Trim());
				name = ((num < 0) ? string.Empty : text.Substring(num + 1).Trim());
			}
		}

		internal static string NetworkKey(string network)
		{
			return (network ?? string.Empty).Trim().ToLowerInvariant();
		}

		internal void ReadNames(out string network, out string name)
		{
			ZDO zdo = Zdo;
			if (zdo == null)
			{
				network = (name = string.Empty);
			}
			else
			{
				ReadNames(zdo, m_isMaster, out network, out name);
			}
		}

		internal void SetNames(string network, string name)
		{
			if (!((Object)(object)_nview == (Object)null) && _nview.IsValid())
			{
				_nview.InvokeRPC("MasterPortal_SetNames", new object[2]
				{
					Clean(network),
					m_isMaster ? string.Empty : Clean(name)
				});
				PortalDirectory.RequestRescan();
			}
		}

		private static string Clean(string value)
		{
			value = (value ?? string.Empty).Trim();
			if (value.Length <= 32)
			{
				return value;
			}
			return value.Substring(0, 32);
		}

		private void RPC_SetNames(long sender, string network, string name)
		{
			if (_nview.IsValid() && _nview.IsOwner())
			{
				ZDO zDO = _nview.GetZDO();
				zDO.Set(NetworkHash, Clean(network));
				zDO.Set(NameHash, Clean(name));
				zDO.Set(ZDOVars.s_tag, string.Empty);
			}
		}

		internal bool IsLinked()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			ZDO zdo = Zdo;
			if (zdo == null || !PortalDirectory.HasData)
			{
				return false;
			}
			ReadNames(out var network, out var _);
			string text = NetworkKey(network);
			if (text.Length == 0)
			{
				return false;
			}
			if (m_isMaster)
			{
				return PortalDirectory.GetMinors(text).Count > 0;
			}
			PortalEntry portalEntry = PortalDirectory.Find(zdo.m_uid);
			if (portalEntry != null && !portalEntry.Active)
			{
				return false;
			}
			return PortalDirectory.FindMaster(text, Position) != null;
		}

		internal string GetHoverName()
		{
			if (!m_isMaster)
			{
				return ModConfig.MinorName.Value;
			}
			return ModConfig.MasterName.Value;
		}

		internal string GetHoverText()
		{
			ReadNames(out var network, out var name);
			string text = NetworkKey(network);
			StringBuilder stringBuilder = new StringBuilder();
			if (m_isMaster)
			{
				stringBuilder.Append((text.Length == 0) ? (ModConfig.MasterName.Value + " <color=orange>(unnamed)</color>") : (ModConfig.MasterName.Value + " \"" + network + "\""));
				stringBuilder.Append('\n');
				if (text.Length > 0)
				{
					AppendMasterStatus(stringBuilder, text);
				}
				stringBuilder.Append("[<color=yellow><b>$KEY_Use</b></color>] Set name");
				if (text.Length > 0)
				{
					stringBuilder.Append("\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] Choose destination");
				}
			}
			else
			{
				stringBuilder.Append(ModConfig.MinorName.Value + " \"" + ((name.Length > 0) ? name : "unnamed") + "\"");
				stringBuilder.Append((text.Length == 0) ? " <color=orange>(no Master)</color>" : (" - Master \"" + network + "\""));
				stringBuilder.Append('\n');
				if (text.Length > 0)
				{
					AppendMinorStatus(stringBuilder, text);
				}
				stringBuilder.Append("[<color=yellow><b>$KEY_Use</b></color>] Set Master and name");
			}
			return Localization.instance.Localize(stringBuilder.ToString());
		}

		private void AppendMasterStatus(StringBuilder lines, string key)
		{
			if (!PortalDirectory.HasData)
			{
				lines.Append("<color=orange>Waiting for the portal list from the server...</color>\n");
				return;
			}
			int count = PortalDirectory.GetMinors(key).Count;
			lines.Append(count switch
			{
				1 => "1 Minor portal linked\n", 
				0 => "<color=orange>No Minor portals linked</color>\n", 
				_ => $"{count} Minor portals linked\n", 
			});
			if (PortalDirectory.CountMasters(key) > 1)
			{
				lines.Append("<color=orange>Warning: several Masters share this name, Minors lead to the nearest one</color>\n");
			}
		}

		private void AppendMinorStatus(StringBuilder lines, string key)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!PortalDirectory.HasData)
			{
				lines.Append("<color=orange>Waiting for the portal list from the server...</color>\n");
				return;
			}
			ZDO zdo = Zdo;
			PortalEntry portalEntry = ((zdo != null) ? PortalDirectory.Find(zdo.m_uid) : null);
			if (portalEntry != null && !portalEntry.Active)
			{
				lines.Append($"<color=orange>Inactive: the Master already has {PortalDirectory.MaxMinors} Minor portals</color>\n");
			}
			else if (PortalDirectory.FindMaster(key, Position) == null)
			{
				lines.Append("<color=orange>No Master portal with this name</color>\n");
			}
			else
			{
				lines.Append("[linked to the Master]\n");
			}
		}

		internal bool Interact(Humanoid human, bool hold, bool alt)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (hold || Zdo == null)
			{
				return false;
			}
			if (m_isMaster && alt)
			{
				Player val = (Player)(object)((human is Player) ? human : null);
				if (val != null)
				{
					OpenMenu(val);
				}
				return true;
			}
			if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false))
			{
				((Character)human).Message((MessageType)2, "$piece_noaccess", 0, (Sprite)null, false);
				return true;
			}
			ReadNames(out var network, out var name);
			PortalNameDialog.Open(this, network, name);
			return true;
		}

		internal void OnPlayerEnter(Player player)
		{
			if (!((Object)(object)player == (Object)null) && !((Character)player).IsTeleporting())
			{
				if (m_isMaster)
				{
					OpenMenu(player);
				}
				else
				{
					JumpToMaster(player);
				}
			}
		}

		private void OpenMenu(Player player)
		{
			ReadNames(out var network, out var _);
			string text = NetworkKey(network);
			if (text.Length == 0)
			{
				((Character)player).Message((MessageType)2, "Give this Master portal a name first", 0, (Sprite)null, false);
			}
			else if (!PortalDirectory.HasData)
			{
				((Character)player).Message((MessageType)2, "Portal list not received from the server yet", 0, (Sprite)null, false);
			}
			else
			{
				PortalMenu.Open(this, network, text);
			}
		}

		private void JumpToMaster(Player player)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			ReadNames(out var network, out var _);
			string text = NetworkKey(network);
			if (text.Length == 0)
			{
				((Character)player).Message((MessageType)2, "Choose which Master this portal links to", 0, (Sprite)null, false);
				return;
			}
			if (!PortalDirectory.HasData)
			{
				((Character)player).Message((MessageType)2, "Portal list not received from the server yet", 0, (Sprite)null, false);
				return;
			}
			ZDO zdo = Zdo;
			PortalEntry portalEntry = ((zdo != null) ? PortalDirectory.Find(zdo.m_uid) : null);
			if (portalEntry != null && !portalEntry.Active)
			{
				((Character)player).Message((MessageType)2, $"Master \"{network}\" already has {PortalDirectory.MaxMinors} Minor portals", 0, (Sprite)null, false);
				return;
			}
			PortalEntry portalEntry2 = PortalDirectory.FindMaster(text, Position);
			if (portalEntry2 == null)
			{
				((Character)player).Message((MessageType)2, "No Master portal named \"" + network + "\"", 0, (Sprite)null, false);
			}
			else
			{
				TeleportTo(player, portalEntry2);
			}
		}

		internal bool TeleportTo(Player player, PortalEntry target)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)32))
			{
				((Character)player).Message((MessageType)2, "$msg_blocked", 0, (Sprite)null, false);
				return false;
			}
			float num = default(float);
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)33) && (RandEventSystem.instance.GetBossEvent() != null || (ZoneSystem.instance.GetGlobalKey((GlobalKeys)47, ref num) && num > 0f)))
			{
				((Character)player).Message((MessageType)2, "$msg_blockedbyboss", 0, (Sprite)null, false);
				return false;
			}
			if (!((Humanoid)player).IsTeleportable(PortalDirectory.AllowAllItems))
			{
				((Character)player).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false);
				return false;
			}
			float num2 = (((Object)(object)_teleport != (Object)null) ? _teleport.m_exitDistance : 1f);
			Vector3 val = target.Rotation * Vector3.forward;
			Vector3 val2 = target.Position + val * num2 + Vector3.up;
			MasterPortalPlugin.Log.LogInfo((object)("Teleporting " + player.GetPlayerName() + " to " + target.DisplayName + " (" + target.Network + ")."));
			((Character)player).TeleportTo(val2, target.Rotation, true);
			Game.instance.IncrementPlayerStat((PlayerStatType)15, 1f, false);
			return true;
		}

		internal bool IsInMenuRange(Player player)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player != (Object)null)
			{
				return Vector3.Distance(((Component)player).transform.position, ((Component)this).transform.position) <= 6f;
			}
			return false;
		}
	}
	internal static class ModConfig
	{
		internal static ConfigEntry<int> MaxMinorsPerNetwork;

		internal static ConfigEntry<bool> AllowAllItems;

		internal static ConfigEntry<float> ScanInterval;

		internal static ConfigEntry<string> MasterName;

		internal static ConfigEntry<string> MasterDescription;

		internal static ConfigEntry<string> MasterRequirements;

		internal static ConfigEntry<string> MasterGlowColor;

		internal static ConfigEntry<string> MinorName;

		internal static ConfigEntry<string> MinorDescription;

		internal static ConfigEntry<string> MinorRequirements;

		internal static ConfigEntry<bool> CustomModels;

		internal static ConfigEntry<float> PlatformRadius;

		internal static ConfigEntry<float> PillarHeight;

		internal static ConfigEntry<float> MinorRingRadius;

		internal static void Bind(ConfigFile cfg)
		{
			MaxMinorsPerNetwork = cfg.Bind<int>("1 - Network", "MaxMinorsPerMaster", 0, "Maximum number of Minor portals that can link to one Master (0 = unlimited). Extra Minors stay dark. In multiplayer the server's value applies.");
			AllowAllItems = cfg.Bind<bool>("1 - Network", "AllowAllItems", false, "If true, ores and metals can be carried through, like the stone portal. In multiplayer the server's value applies.");
			ScanInterval = cfg.Bind<float>("1 - Network", "ScanInterval", 5f, "How often (seconds) the server rechecks the portal list (new, renamed or destroyed portals).");
			MasterName = cfg.Bind<string>("2 - Master Portal", "Name", "Master Portal", "Name shown in the hammer menu and on the portal.");
			MasterDescription = cfg.Bind<string>("2 - Master Portal", "Description", "Hub of the network: step into the bubble to choose which Minor portal to travel to.", "Description shown in the hammer menu.");
			MasterRequirements = cfg.Bind<string>("2 - Master Portal", "Requirements", "FineWood:40,GreydwarfEye:20,SurtlingCore:4", "Build materials as Prefab:Amount, separated by commas.");
			MasterGlowColor = cfg.Bind<string>("2 - Master Portal", "EnergyColor", "#7A3CFF", "Hex color of the network's energy, for both Master and Minor: bubble, veil, beams, crystals and runes.");
			MinorName = cfg.Bind<string>("3 - Minor Portal", "Name", "Minor Portal", "Name shown in the hammer menu and on the portal.");
			MinorDescription = cfg.Bind<string>("3 - Minor Portal", "Description", "Step through to return to the Master portal it is linked to.", "Description shown in the hammer menu.");
			MinorRequirements = cfg.Bind<string>("3 - Minor Portal", "Requirements", "FineWood:20,GreydwarfEye:10,SurtlingCore:2", "Build materials as Prefab:Amount, separated by commas.");
			CustomModels = cfg.Bind<bool>("4 - Visuals", "CustomModels", true, "false = both portals use the vanilla wooden portal model.");
			PlatformRadius = cfg.Bind<float>("4 - Visuals", "MasterPlatformRadius", 4.5f, "Radius in meters of the Master's round platform (3 to 8); bubble, pillars and crystals scale with it.");
			PillarHeight = cfg.Bind<float>("4 - Visuals", "MasterPillarHeight", 1.3f, "Height in meters of the Master's three pillars (the crystal floats on top). The bubble's center follows the crystals' height, so the beams stay level: taller pillars = higher bubble.");
			MinorRingRadius = cfg.Bind<float>("4 - Visuals", "MinorRingRadius", 1.75f, "Inner radius in meters of the Minor's ring (1 to 3); base, legs, runes and veil scale with it.");
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	internal static class ZNetScene_Awake_Patch
	{
		private static void Postfix()
		{
			PortalFactory.Rebuild();
			PortalFactory.TryFinalize();
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	internal static class ObjectDB_Awake_Patch
	{
		private static void Postfix()
		{
			PortalFactory.TryFinalize();
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
	internal static class ObjectDB_CopyOtherDB_Patch
	{
		private static void Postfix()
		{
			PortalFactory.TryFinalize();
		}
	}
	[HarmonyPatch(typeof(Game), "Start")]
	internal static class Game_Start_Patch
	{
		private static void Postfix(Game __instance)
		{
			((Component)__instance).gameObject.AddComponent<PortalDirectory>();
			((Component)__instance).gameObject.AddComponent<PortalMenu>();
			((Component)__instance).gameObject.AddComponent<PortalNameDialog>();
			PortalFactory.RenderIcons();
		}
	}
	[HarmonyPatch(typeof(TextInput), "IsVisible")]
	internal static class TextInput_IsVisible_Patch
	{
		private static void Postfix(ref bool __result)
		{
			__result |= PortalMenu.IsVisible || PortalNameDialog.IsVisible;
		}
	}
	[HarmonyPatch(typeof(ZInput), "Internal_GetMouseScrollWheel")]
	internal static class ZInput_MouseScrollWheel_Patch
	{
		internal static bool Bypass;

		private static void Postfix(ref float __result)
		{
			if (!Bypass && (PortalMenu.IsVisible || PortalNameDialog.IsVisible))
			{
				__result = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Update")]
	internal static class InventoryGui_Update_Patch
	{
		private static bool Prefix()
		{
			return !PortalNameDialog.IsVisible;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "GetHoverText")]
	internal static class TeleportWorld_GetHoverText_Patch
	{
		private static bool Prefix(TeleportWorld __instance, ref string __result)
		{
			HubPortal component = ((Component)__instance).GetComponent<HubPortal>();
			if ((Object)(object)component == (Object)null)
			{
				return true;
			}
			__result = component.GetHoverText();
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "GetHoverName")]
	internal static class TeleportWorld_GetHoverName_Patch
	{
		private static bool Prefix(TeleportWorld __instance, ref string __result)
		{
			HubPortal component = ((Component)__instance).GetComponent<HubPortal>();
			if ((Object)(object)component == (Object)null)
			{
				return true;
			}
			__result = component.GetHoverName();
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "Interact")]
	internal static class TeleportWorld_Interact_Patch
	{
		private static bool Prefix(TeleportWorld __instance, Humanoid human, bool hold, bool alt, ref bool __result)
		{
			HubPortal component = ((Component)__instance).GetComponent<HubPortal>();
			if ((Object)(object)component == (Object)null)
			{
				return true;
			}
			__result = component.Interact(human, hold, alt);
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
	internal static class TeleportWorld_Teleport_Patch
	{
		private static bool Prefix(TeleportWorld __instance, Player player)
		{
			HubPortal component = ((Component)__instance).GetComponent<HubPortal>();
			if ((Object)(object)component == (Object)null)
			{
				return true;
			}
			component.OnPlayerEnter(player);
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "HaveTarget")]
	internal static class TeleportWorld_HaveTarget_Patch
	{
		private static bool Prefix(TeleportWorld __instance, ref bool __result)
		{
			HubPortal component = ((Component)__instance).GetComponent<HubPortal>();
			if ((Object)(object)component == (Object)null)
			{
				return true;
			}
			__result = component.IsLinked();
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "TargetFound")]
	internal static class TeleportWorld_TargetFound_Patch
	{
		private static bool Prefix(TeleportWorld __instance, ref bool __result)
		{
			HubPortal component = ((Component)__instance).GetComponent<HubPortal>();
			if ((Object)(object)component == (Object)null)
			{
				return true;
			}
			__result = component.IsLinked();
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")]
	internal static class TeleportWorld_UpdatePortal_Patch
	{
		private static void Prefix(TeleportWorld __instance)
		{
			if (PortalDirectory.HasData && (Object)(object)((Component)__instance).GetComponent<HubPortal>() != (Object)null)
			{
				__instance.m_allowAllItems = PortalDirectory.AllowAllItems;
			}
		}
	}
	[BepInPlugin("ymiron.valheim.masterportal", "MasterPortal-Ymiron", "1.3.0")]
	[BepInProcess("valheim.exe")]
	[BepInProcess("valheim_server.exe")]
	public class MasterPortalPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "ymiron.valheim.masterportal";

		public const string PluginName = "MasterPortal-Ymiron";

		public const string PluginVersion = "1.3.0";

		private Harmony _harmony;

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("ymiron.valheim.masterportal");
			_harmony.PatchAll(typeof(MasterPortalPlugin).Assembly);
			Log.LogInfo((object)"MasterPortal-Ymiron 1.3.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal sealed class PortalEntry
	{
		public ZDOID Id;

		public bool IsMaster;

		public string Network;

		public string Name;

		public Vector3 Position;

		public Quaternion Rotation;

		public bool Active;

		public string NetworkKey => HubPortal.NetworkKey(Network);

		public string DisplayName
		{
			get
			{
				if (!string.IsNullOrEmpty(Name))
				{
					return Name;
				}
				return $"Unnamed ({Position.x:0}, {Position.z:0})";
			}
		}
	}
	internal sealed class PortalDirectory : MonoBehaviour
	{
		private const string RpcRequest = "MasterPortal_RequestDirectory";

		private const string RpcDirectory = "MasterPortal_Directory";

		private const string RpcRescan = "MasterPortal_Rescan";

		private const int FormatVersion = 1;

		private const float RequestRetrySeconds = 3f;

		private const float RescanDelaySeconds = 1.5f;

		private static PortalDirectory _instance;

		private static List<PortalEntry> _entries = new List<PortalEntry>();

		private byte[] _lastPayload;

		private bool _rescanRequested;

		private float _nextRequest;

		internal static bool HasData { get; private set; }

		internal static bool AllowAllItems { get; private set; }

		internal static int MaxMinors { get; private set; }

		private static bool IsServer
		{
			get
			{
				if ((Object)(object)ZNet.instance != (Object)null)
				{
					return ZNet.instance.IsServer();
				}
				return false;
			}
		}

		private void Start()
		{
			_instance = this;
			HasData = false;
			_entries = new List<PortalEntry>();
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance == null)
			{
				MasterPortalPlugin.Log.LogError((object)"ZRoutedRpc not available: the portal network will not work.");
				return;
			}
			instance.Register("MasterPortal_RequestDirectory", (Action<long>)RPC_Request);
			instance.Register<ZPackage>("MasterPortal_Directory", (Action<long, ZPackage>)RPC_Directory);
			instance.Register("MasterPortal_Rescan", (Action<long>)RPC_Rescan);
			if (IsServer)
			{
				((MonoBehaviour)this).StartCoroutine(ServerLoop());
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
				HasData = false;
				_entries = new List<PortalEntry>();
			}
		}

		internal static PortalEntry FindMaster(string networkKey, Vector3 from)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return _entries.Where((PortalEntry e) => e.IsMaster && e.NetworkKey == networkKey).OrderBy(delegate(PortalEntry e)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = e.Position - from;
				return ((Vector3)(ref val)).sqrMagnitude;
			}).FirstOrDefault();
		}

		internal static int CountMasters(string networkKey)
		{
			return _entries.Count((PortalEntry e) => e.IsMaster && e.NetworkKey == networkKey);
		}

		internal static List<PortalEntry> GetMinors(string networkKey)
		{
			return _entries.Where((PortalEntry e) => !e.IsMaster && e.Active && e.NetworkKey == networkKey).OrderBy<PortalEntry, string>((PortalEntry e) => e.DisplayName, StringComparer.CurrentCultureIgnoreCase).ToList();
		}

		internal static List<string> GetMasterNames()
		{
			return (from e in _entries
				where e.IsMaster
				group e by e.NetworkKey into g
				select g.First().Network).OrderBy<string, string>((string n) => n, StringComparer.CurrentCultureIgnoreCase).ToList();
		}

		internal static PortalEntry Find(ZDOID id)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return _entries.FirstOrDefault((PortalEntry e) => e.Id == id);
		}

		internal static void RequestRescan()
		{
			if ((Object)(object)_instance != (Object)null && ZRoutedRpc.instance != null)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC("MasterPortal_Rescan", Array.Empty<object>());
			}
		}

		private void Update()
		{
			if (!HasData && !IsServer && !(Time.time < _nextRequest))
			{
				ZNetPeer val = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetServerPeer() : null);
				if (val != null && val.IsReady())
				{
					_nextRequest = Time.time + 3f;
					ZRoutedRpc.instance.InvokeRoutedRPC("MasterPortal_RequestDirectory", Array.Empty<object>());
				}
			}
		}

		private void RPC_Directory(long sender, ZPackage pkg)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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)
			if (!IsTrustedSender(sender))
			{
				return;
			}
			try
			{
				int num = pkg.ReadInt();
				if (num != 1)
				{
					MasterPortalPlugin.Log.LogWarning((object)$"Portal list in format {num}, expected {1}: server and client run different versions of the mod.");
					return;
				}
				bool allowAllItems = pkg.ReadBool();
				int maxMinors = pkg.ReadInt();
				int num2 = pkg.ReadInt();
				List<PortalEntry> list = new List<PortalEntry>(num2);
				for (int i = 0; i < num2; i++)
				{
					list.Add(new PortalEntry
					{
						Id = pkg.ReadZDOID(),
						IsMaster = pkg.ReadBool(),
						Network = pkg.ReadString(),
						Name = pkg.ReadString(),
						Position = pkg.ReadVector3(),
						Rotation = pkg.ReadQuaternion(),
						Active = pkg.ReadBool()
					});
				}
				_entries = list;
				AllowAllItems = allowAllItems;
				MaxMinors = maxMinors;
				HasData = true;
			}
			catch (Exception ex)
			{
				MasterPortalPlugin.Log.LogError((object)("Unreadable portal list: " + ex.Message));
			}
		}

		private static bool IsTrustedSender(long sender)
		{
			if ((Object)(object)ZNet.instance == (Object)null)
			{
				return false;
			}
			if (ZNet.instance.IsServer())
			{
				return sender == ZDOMan.GetSessionID();
			}
			ZNetPeer serverPeer = ZNet.instance.GetServerPeer();
			if (serverPeer != null)
			{
				return serverPeer.m_uid == sender;
			}
			return false;
		}

		private void RPC_Request(long sender)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			if (IsServer && _lastPayload != null)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "MasterPortal_Directory", new object[1] { (object)new ZPackage(_lastPayload) });
			}
		}

		private void RPC_Rescan(long sender)
		{
			if (IsServer)
			{
				_rescanRequested = true;
			}
		}

		private IEnumerator ServerLoop()
		{
			while (true)
			{
				yield return Scan();
				float until = Time.time + Mathf.Max(1f, ModConfig.ScanInterval.Value);
				while (Time.time < until && !_rescanRequested)
				{
					yield return null;
				}
				if (_rescanRequested)
				{
					_rescanRequested = false;
					yield return (object)new WaitForSeconds(1.5f);
				}
			}
		}

		private IEnumerator Scan()
		{
			ZDOMan zdoMan = ZDOMan.instance;
			if (zdoMan == null)
			{
				yield break;
			}
			List<ZDO> masters = new List<ZDO>();
			int index = 0;
			while (!zdoMan.GetAllZDOsWithPrefabIterative("MasterPortal", masters, ref index))
			{
				yield return null;
			}
			List<ZDO> minors = new List<ZDO>();
			index = 0;
			while (!zdoMan.GetAllZDOsWithPrefabIterative("MinorPortal", minors, ref index))
			{
				yield return null;
			}
			List<PortalEntry> list = BuildEntries(masters, minors);
			byte[] array = Serialize(list).GetArray();
			if (_lastPayload == null || !array.SequenceEqual(_lastPayload))
			{
				_lastPayload = array;
				int num = list.Count((PortalEntry e) => e.IsMaster);
				MasterPortalPlugin.Log.LogInfo((object)$"Portal network updated: {num} Master, {list.Count - num} Minor. Sending to players.");
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "MasterPortal_Directory", new object[1] { (object)new ZPackage(array) });
			}
		}

		private static List<PortalEntry> BuildEntries(List<ZDO> masters, List<ZDO> minors)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			int stableHashCode = StringExtensionMethods.GetStableHashCode("MasterPortal");
			int stableHashCode2 = StringExtensionMethods.GetStableHashCode("MinorPortal");
			List<PortalEntry> list = new List<PortalEntry>();
			foreach (ZDO item in masters.Concat(minors))
			{
				if (item == null || !item.IsValid())
				{
					continue;
				}
				int prefab = item.GetPrefab();
				if (prefab == stableHashCode || prefab == stableHashCode2)
				{
					bool isMaster = prefab == stableHashCode;
					HubPortal.ReadNames(item, isMaster, out var network, out var name);
					if (!string.IsNullOrEmpty(network))
					{
						list.Add(new PortalEntry
						{
							Id = item.m_uid,
							IsMaster = isMaster,
							Network = network,
							Name = name,
							Position = item.GetPosition(),
							Rotation = item.GetRotation(),
							Active = true
						});
					}
				}
			}
			ApplyMinorLimit(list);
			return list.OrderBy<PortalEntry, string>((PortalEntry e) => e.NetworkKey, StringComparer.Ordinal).ThenBy((PortalEntry e) => (!e.IsMaster) ? 1 : 0).ThenBy((PortalEntry e) => ((ZDOID)(ref e.Id)).UserID)
				.ThenBy((PortalEntry e) => ((ZDOID)(ref e.Id)).ID)
				.ToList();
		}

		private static void ApplyMinorLimit(List<PortalEntry> entries)
		{
			int value = ModConfig.MaxMinorsPerNetwork.Value;
			if (value <= 0)
			{
				return;
			}
			foreach (IGrouping<string, PortalEntry> item in from e in entries
				where !e.IsMaster
				group e by e.NetworkKey)
			{
				List<PortalEntry> list = (from e in item
					orderby ((ZDOID)(ref e.Id)).UserID, ((ZDOID)(ref e.Id)).ID
					select e).ToList();
				for (int num = value; num < list.Count; num++)
				{
					list[num].Active = false;
				}
			}
		}

		private static ZPackage Serialize(List<PortalEntry> entries)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(1);
			val.Write(ModConfig.AllowAllItems.Value);
			val.Write(ModConfig.MaxMinorsPerNetwork.Value);
			val.Write(entries.Count);
			foreach (PortalEntry entry in entries)
			{
				val.Write(entry.Id);
				val.Write(entry.IsMaster);
				val.Write(entry.Network);
				val.Write(entry.Name);
				val.Write(entry.Position);
				val.Write(entry.Rotation);
				val.Write(entry.Active);
			}
			return val;
		}
	}
	internal static class PortalFactory
	{
		internal const string BasePrefabName = "portal_wood";

		internal const string MasterPrefabName = "MasterPortal";

		internal const string MinorPrefabName = "MinorPortal";

		private const float MaxRuneIntensity = 1.4f;

		private static readonly FieldInfo NamedPrefabsField = typeof(ZNetScene).GetField("m_namedPrefabs", BindingFlags.Instance | BindingFlags.NonPublic);

		private static GameObject _holder;

		internal static GameObject MasterPrefab { get; private set; }

		internal static GameObject MinorPrefab { get; private set; }

		internal static void Rebuild()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			ZNetScene instance = ZNetScene.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			GameObject prefab = instance.GetPrefab("portal_wood");
			if ((Object)(object)prefab == (Object)null)
			{
				MasterPortalPlugin.Log.LogError((object)"Base prefab 'portal_wood' not found: the portals will not be registered.");
				return;
			}
			if ((Object)(object)_holder != (Object)null)
			{
				Object.Destroy((Object)(object)_holder);
			}
			PortalModels.ReleaseCreated();
			_holder = new GameObject("MasterPortalPrefabHolder");
			_holder.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)_holder);
			MasterPrefab = CreateVariant(instance, prefab, "MasterPortal", isMaster: true);
			MinorPrefab = CreateVariant(instance, prefab, "MinorPortal", isMaster: false);
			MasterPortalPlugin.Log.LogInfo((object)"Prefabs 'MasterPortal' and 'MinorPortal' created from 'portal_wood'.");
		}

		private static GameObject CreateVariant(ZNetScene scene, GameObject basePrefab, string name, bool isMaster)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(basePrefab, _holder.transform, false);
			((Object)val).name = name;
			Piece component = val.GetComponent<Piece>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_name = (isMaster ? ModConfig.MasterName.Value : ModConfig.MinorName.Value);
				component.m_description = (isMaster ? ModConfig.MasterDescription.Value : ModConfig.MinorDescription.Value);
				component.m_enabled = true;
				component.m_clipGround = true;
			}
			val.AddComponent<HubPortal>().m_isMaster = isMaster;
			TeleportWorld component2 = val.GetComponent<TeleportWorld>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.m_allowAllItems = ModConfig.AllowAllItems.Value;
				component2.m_colorTargetfound = Recolor(component2.m_colorTargetfound, ModConfig.MasterGlowColor.Value);
			}
			if (ModConfig.CustomModels.Value)
			{
				PortalModels.Apply(val, isMaster, scene);
			}
			RegisterInScene(scene, val);
			return val;
		}

		internal static void RenderIcons()
		{
			if (!ModConfig.CustomModels.Value)
			{
				return;
			}
			GameObject[] array = (GameObject[])(object)new GameObject[2] { MasterPrefab, MinorPrefab };
			foreach (GameObject val in array)
			{
				Piece val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Piece>() : null);
				Sprite val3 = (((Object)(object)val2 != (Object)null) ? IconRenderer.Render(val, "MasterPortal_Model") : null);
				if ((Object)(object)val3 != (Object)null)
				{
					val2.m_icon = val3;
					MasterPortalPlugin.Log.LogInfo((object)("Icon for '" + ((Object)val).name + "' rendered from the model."));
				}
			}
		}

		private static Color Recolor(Color original, string hex)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			if (!ColorUtility.TryParseHtmlString(hex, ref val))
			{
				MasterPortalPlugin.Log.LogWarning((object)("Invalid color '" + hex + "': the portals will use the vanilla color."));
				return original;
			}
			float num = Mathf.Min(1.4f, Mathf.Max(original.r, Mathf.Max(original.g, original.b)));
			float num2 = Mathf.Max(val.r, Mathf.Max(val.g, val.b));
			if (num <= 0f || num2 <= 0f)
			{
				return original;
			}
			float num3 = num / num2;
			return new Color(val.r * num3, val.g * num3, val.b * num3, original.a);
		}

		private static void RegisterInScene(ZNetScene scene, GameObject prefab)
		{
			if (!scene.m_prefabs.Contains(prefab))
			{
				scene.m_prefabs.Add(prefab);
			}
			if (NamedPrefabsField?.GetValue(scene) is Dictionary<int, GameObject> dictionary)
			{
				dictionary[StringExtensionMethods.GetStableHashCode(((Object)prefab).name)] = prefab;
			}
			else
			{
				MasterPortalPlugin.Log.LogError((object)("Cannot access ZNetScene.m_namedPrefabs: '" + ((Object)prefab).name + "' will not be buildable."));
			}
		}

		internal static void TryFinalize()
		{
			if ((Object)(object)MasterPrefab == (Object)null || (Object)(object)MinorPrefab == (Object)null)
			{
				return;
			}
			ObjectDB instance = ObjectDB.instance;
			if (!((Object)(object)instance == (Object)null) && instance.m_items.Count != 0)
			{
				GameObject itemPrefab = instance.GetItemPrefab("Hammer");
				PieceTable val = ((!((Object)(object)itemPrefab != (Object)null)) ? null : itemPrefab.GetComponent<ItemDrop>()?.m_itemData?.m_shared?.m_buildPieces);
				if (!((Object)(object)val == (Object)null))
				{
					ApplyRequirements(instance, MasterPrefab, ModConfig.MasterRequirements.Value);
					ApplyRequirements(instance, MinorPrefab, ModConfig.MinorRequirements.Value);
					AddToTable(val, MasterPrefab);
					AddToTable(val, MinorPrefab);
				}
			}
		}

		private static void AddToTable(PieceTable table, GameObject prefab)
		{
			table.m_pieces.RemoveAll((GameObject p) => (Object)(object)p == (Object)null || ((Object)(object)p != (Object)(object)prefab && ((Object)p).name == ((Object)prefab).name));
			if (table.m_pieces.Contains(prefab))
			{
				return;
			}
			int num = table.m_pieces.FindIndex((GameObject p) => ((Object)p).name == "portal_wood");
			if (num >= 0)
			{
				int num2;
				for (num2 = num + 1; num2 < table.m_pieces.Count && (Object)(object)table.m_pieces[num2].GetComponent<HubPortal>() != (Object)null; num2++)
				{
				}
				table.m_pieces.Insert(num2, prefab);
			}
			else
			{
				table.m_pieces.Add(prefab);
			}
			MasterPortalPlugin.Log.LogInfo((object)("'" + ((Object)prefab).name + "' added to the hammer."));
		}

		private static void ApplyRequirements(ObjectDB odb, GameObject prefab, string raw)
		{
			Piece component = prefab.GetComponent<Piece>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_resources = ParseRequirements(odb, raw, component.m_resources);
			}
		}

		private static Requirement[] ParseRequirements(ObjectDB odb, string raw, Requirement[] fallback)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			List<Requirement> list = new List<Requirement>();
			string[] array = (raw ?? string.Empty).Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text in array)
			{
				string[] array2 = text.Trim().Split(':');
				if (array2.Length != 2 || !int.TryParse(array2[1].Trim(), out var result) || result <= 0)
				{
					MasterPortalPlugin.Log.LogWarning((object)("Invalid requirement '" + text + "'. Expected format Prefab:Amount."));
					continue;
				}
				GameObject itemPrefab = odb.GetItemPrefab(array2[0].Trim());
				ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val == (Object)null)
				{
					MasterPortalPlugin.Log.LogWarning((object)("Item '" + array2[0].Trim() + "' not found in ObjectDB: skipped."));
					continue;
				}
				list.Add(new Requirement
				{
					m_resItem = val,
					m_amount = result,
					m_recover = true
				});
			}
			if (list.Count == 0)
			{
				MasterPortalPlugin.Log.LogWarning((object)"No valid requirements in the config: keeping the vanilla portal recipe.");
				return fallback ?? Array.Empty<Requirement>();
			}
			return list.ToArray();
		}
	}
	internal sealed class PortalMap
	{
		private const float MinSpanMeters = 250f;

		private const float FitPadding = 1.35f;

		private static bool _diagnosed;

		private static bool? _srgbWriteInGui;

		private static readonly FieldRef<Minimap, Material> LargeMaterial = AccessTools.FieldRefAccess<Minimap, Material>("m_mapLargeShader");

		private Material _material;

		private Material _source;

		private Vector2 _center = new Vector2(0.5f, 0.5f);

		private float _span = 0.05f;

		internal static bool Available
		{
			get
			{
				if (!Game.m_noMap && (Object)(object)Minimap.instance != (Object)null)
				{
					return (Object)(object)Minimap.instance.m_mapTexture != (Object)null;
				}
				return false;
			}
		}

		private static float WorldSize => (float)Minimap.instance.m_textureSize * Minimap.instance.m_pixelSize;

		private float MinSpan => Mathf.Clamp(250f / WorldSize, 0.002f, 1f);

		internal float MetersPerUnit(Rect rect)
		{
			return _span * WorldSize / ((Rect)(ref rect)).height;
		}

		internal void Fit(Rect rect, Vector3 origin, IEnumerable<Vector3> points, float minMeters)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = WorldToUv(origin);
			Vector2 val2 = val;
			foreach (Vector3 point in points)
			{
				Vector2 val3 = WorldToUv(point);
				val = Vector2.Min(val, val3);
				val2 = Vector2.Max(val2, val3);
			}
			float num = ((Rect)(ref rect)).width / Mathf.Max(1f, ((Rect)(ref rect)).height);
			Vector2 val4 = (val2 - val) * 1.35f;
			_center = (val + val2) * 0.5f;
			_span = Mathf.Max(new float[3]
			{
				val4.y,
				val4.x / num,
				minMeters / WorldSize
			});
			Clamp();
		}

		internal void Zoom(Rect rect, Vector2 pivot, float factor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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)
			Vector2 val = GuiToUv(rect, pivot);
			_span = Mathf.Clamp(_span * factor, MinSpan, 1f);
			Vector2 val2 = GuiToUv(rect, pivot);
			_center += val - val2;
			Clamp();
		}

		internal void Pan(Rect rect, Vector2 guiDelta)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			float num = _span / ((Rect)(ref rect)).height;
			_center += new Vector2((0f - guiDelta.x) * num, guiDelta.y * num);
			Clamp();
		}

		private void Clamp()
		{
			_span = Mathf.Clamp(_span, MinSpan, 1f);
			_center.x = Mathf.Clamp01(_center.x);
			_center.y = Mathf.Clamp01(_center.y);
		}

		private Rect UvRect(Rect rect)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			float num = _span * ((Rect)(ref rect)).width / Mathf.Max(1f, ((Rect)(ref rect)).height);
			return new Rect(_center.x - num / 2f, _center.y - _span / 2f, num, _span);
		}

		private static Vector2 WorldToUv(Vector3 p)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			float worldSize = WorldSize;
			return new Vector2(p.x / worldSize + 0.5f, p.z / worldSize + 0.5f);
		}

		internal Vector2 WorldToGui(Rect rect, Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			Vector2 val = WorldToUv(p);
			Rect val2 = UvRect(rect);
			return new Vector2((val.x - ((Rect)(ref val2)).xMin) / ((Rect)(ref val2)).width * ((Rect)(ref rect)).width, (1f - (val.y - ((Rect)(ref val2)).yMin) / ((Rect)(ref val2)).height) * ((Rect)(ref rect)).height);
		}

		private Vector2 GuiToUv(Rect rect, Vector2 gui)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Rect val = UvRect(rect);
			return new Vector2(((Rect)(ref val)).xMin + gui.x / ((Rect)(ref rect)).width * ((Rect)(ref val)).width, ((Rect)(ref val)).yMin + (1f - gui.y / ((Rect)(ref rect)).height) * ((Rect)(ref val)).height);
		}

		internal void Draw(Rect rect, float scale)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Invalid comparison between Unknown and I4
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Minimap instance = Minimap.instance;
			Rect val = UvRect(rect);
			Material val2 = PrepareMaterial(instance, val);
			if ((Object)(object)val2 == (Object)null)
			{
				GUI.DrawTextureWithTexCoords(rect, (Texture)(object)instance.m_mapTexture, val);
				return;
			}
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.identity;
			Rect val3 = new Rect(((Rect)(ref rect)).x * scale, ((Rect)(ref rect)).y * scale, ((Rect)(ref rect)).width * scale, ((Rect)(ref rect)).height * scale);
			bool sRGBWrite = GL.sRGBWrite;
			_srgbWriteInGui = _srgbWriteInGui ?? sRGBWrite;
			GL.sRGBWrite = (int)QualitySettings.activeColorSpace == 1;
			Graphics.DrawTexture(val3, (Texture)(object)instance.m_mapTexture, val, 0, 0, 0, 0, Color.white, val2);
			GL.sRGBWrite = sRGBWrite;
			GUI.matrix = matrix;
		}

		private Material PrepareMaterial(Minimap minimap, Rect view)
		{
			//IL_0058: 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_006a: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			Material val;
			try
			{
				val = LargeMaterial.Invoke(minimap);
			}
			catch
			{
				val = null;
			}
			if ((Object)(object)val == (Object)null || (Object)(object)val.shader == (Object)null || !val.shader.isSupported)
			{
				return null;
			}
			if ((Object)(object)_material == (Object)null || (Object)(object)_source != (Object)(object)val)
			{
				_material = new Material(val)
				{
					hideFlags = (HideFlags)61
				};
				_source = val;
			}
			else
			{
				_material.CopyPropertiesFromMaterial(val);
			}
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor((((Rect)(ref view)).center.x - 0.5f) * WorldSize, 0f, (((Rect)(ref view)).center.y - 0.5f) * WorldSize);
			_material.SetFloat("_zoom", ((Rect)(ref view)).height);
			_material.SetFloat("_pixelSize", 200f / ((Rect)(ref view)).height);
			_material.SetVector("_mapCenter", Vector4.op_Implicit(val2));
			return _material;
		}

		internal void Diagnose()
		{
			//IL_0057: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected I4, but got Unknown
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			if (_diagnosed || (Object)(object)_material == (Object)null || (Object)(object)Minimap.instance == (Object)null)
			{
				return;
			}
			_diagnosed = true;
			try
			{
				Shader shader = _material.shader;
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append($"Map shader '{((Object)shader).name}', queue {_material.renderQueue}, color space {QualitySettings.activeColorSpace}, " + "sRGB write in OnGUI " + (_srgbWriteInGui.HasValue ? _srgbWriteInGui.Value.ToString() : "?") + ".");
				for (int i = 0; i < shader.GetPropertyCount(); i++)
				{
					string propertyName = shader.GetPropertyName(i);
					ShaderPropertyType propertyType = shader.GetPropertyType(i);
					string arg;
					switch ((int)propertyType)
					{
					case 2:
					case 3:
						arg = _material.GetFloat(propertyName).ToString("0.###");
						break;
					case 0:
						arg = ((object)_material.GetColor(propertyName)/*cast due to .constrained prefix*/).ToString();
						break;
					case 1:
						arg = ((object)_material.GetVector(propertyName)/*cast due to .constrained prefix*/).ToString();
						break;
					default:
					{
						Texture texture = _material.GetTexture(propertyName);
						arg = (((Object)(object)texture != (Object)null) ? ((Object)texture).name : "none");
						break;
					}
					}
					stringBuilder.Append($"\n  {propertyName} ({propertyType}) = {arg}");
				}
				Texture2D mapTexture = Minimap.instance.m_mapTexture;
				stringBuilder.Append($"\n  average biome texture: {Average((Texture)(object)mapTexture, null)}");
				stringBuilder.Append($"\n  average shader output: {Average((Texture)(object)mapTexture, _material)}");
				MasterPortalPlugin.Log.LogInfo((object)stringBuilder.ToString());
			}
			catch (Exception ex)
			{
				MasterPortalPlugin.Log.LogWarning((object)("Map diagnostics failed: " + ex.Message));
			}
		}

		private static Color Average(Texture source, Material material)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			RenderTexture temporary = RenderTexture.GetTemporary(32, 32, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			try
			{
				RenderTexture.active = temporary;
				GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));
				if ((Object)(object)material != (Object)null)
				{
					Graphics.Blit(source, temporary, material);
				}
				else
				{
					Graphics.Blit(source, temporary);
				}
				Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false);
				RenderTexture.active = temporary;
				val.ReadPixels(new Rect(0f, 0f, 32f, 32f), 0, 0);
				val.Apply();
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
				Color[] pixels = val.GetPixels();
				foreach (Color val3 in pixels)
				{
					val2 += val3;
				}
				Object.Destroy((Object)(object)val);
				return val2 / 1024f;
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
			}
		}

		internal void Dispose()
		{
			if ((Object)(object)_material != (Object)null)
			{
				Object.Destroy((Object)(object)_material);
				_material = null;
				_source = null;
			}
		}
	}
	internal sealed class PortalMenu : MonoBehaviour
	{
		private enum Area
		{
			None,
			Map,
			List
		}

		private const float MapWindowWidth = 1240f;

		private const float MapWindowHeight = 740f;

		private const float ListWindowWidth = 500f;

		private const float SideWidth = 340f;

		private const float Pad = 22f;

		private const float HeaderHeight = 58f;

		private const float FooterHeight = 26f;

		private const float CardHeight = 60f;

		private const float CardGap = 8f;

		private const int MaxListRows = 7;

		private const float RefreshSeconds = 1f;

		private const float FitMinMeters = 900f;

		private const float MarkerHitRadius = 18f;

		private const float DragThreshold = 4f;

		private const float WheelPixels = 600f;

		private const float WheelZoom = 0.8f;

		private static PortalMenu _instance;

		private HubPortal _source;

		private string _network;

		private string _networkKey;

		private List<PortalEntry> _items = new List<PortalEntry>();

		private float _nextRefresh;

		private int _closedFrame = -10;

		private readonly PortalMap _map = new PortalMap();

		private bool _fitPending;

		private Rect _mapRect;

		private float _scroll;

		private float _maxScroll;

		private Area _mouseArea;

		private Vector2 _mouseOnMap;

		private int _mapHover = -1;

		private int _listHover = -1;

		private bool _pressedOnMap;

		private bool _dragging;

		private Vector2 _pressPosition;

		private int _pressedCard = -1;

		internal static bool IsVisible
		{
			get
			{
				if ((Object)(object)_instance != (Object)null)
				{
					if (!((Object)(object)_instance._source != (Object)null))
					{
						return Time.frameCount <= _instance._closedFrame + 1;
					}
					return true;
				}
				return false;
			}
		}

		private static bool ShowMap => PortalMap.Available;

		internal static void Open(HubPortal source, string network, string networkKey)
		{
			if (!((Object)(object)_instance == (Object)null))
			{
				_instance._source = source;
				_instance._network = network;
				_instance._networkKey = networkKey;
				_instance._scroll = 0f;
				_instance._fitPending = true;
				_instance._mapHover = (_instance._listHover = (_instance._pressedCard = -1));
				_instance._pressedOnMap = (_instance._dragging = false);
				_instance.Refresh();
			}
		}

		private void Awake()
		{
			_instance = this;
		}

		private void OnDestroy()
		{
			_map.Dispose();
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
			}
		}

		private void Close()
		{
			_source = null;
			_closedFrame = Time.frameCount;
		}

		private void Refresh()
		{
			_items = PortalDirectory.GetMinors(_networkKey);
			_nextRefresh = Time.time + 1f;
		}

		private void Update()
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_source == (Object)null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting() || !_source.IsInMenuRange(localPlayer))
			{
				Close();
				return;
			}
			if (ZInput.GetKeyDown((KeyCode)27, true))
			{
				Close();
				return;
			}
			if (Time.time >= _nextRefresh)
			{
				Refresh();
			}
			if (ShowMap)
			{
				_map.Diagnose();
			}
			float num = Mathf.Clamp(ReadWheel(), -0.3f, 0.3f);
			if (num != 0f)
			{
				if (_mouseArea == Area.Map && ShowMap)
				{
					_map.Zoom(_mapRect, _mouseOnMap, Mathf.Pow(0.8f, num * 10f));
				}
				else
				{
					_scroll = Mathf.Clamp(_scroll - num * 600f, 0f, _maxScroll);
				}
			}
			for (int i = 0; i < 9 && i < _items.Count; i++)
			{
				if (ZInput.GetKeyDown((KeyCode)(49 + i), true) || ZInput.GetKeyDown((KeyCode)(257 + i), true))
				{
					Select(_items[i]);
					break;
				}
			}
		}

		private static float ReadWheel()
		{
			ZInput_MouseScrollWheel_Patch.Bypass = true;
			try
			{
				return ZInput.GetMouseScrollWheel();
			}
			finally
			{
				ZInput_MouseScrollWheel_Patch.Bypass = false;
			}
		}

		private void Select(PortalEntry target)
		{
			HubPortal source = _source;
			Player localPlayer = Player.m_localPlayer;
			Close();
			if ((Object)(object)source != (Object)null && (Object)(object)localPlayer != (Object)null)
			{
				source.TeleportTo(localPlayer, target);
			}
		}

		private void OnGUI()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: 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_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_source == (Object)null)
			{
				return;
			}
			if ((int)Event.current.type == 6)
			{
				Event.current.Use();
			}
			UiTheme.Ensure();
			Matrix4x4 matrix = GUI.matrix;
			float num = UiTheme.BeginScaled();
			float num2 = (float)Screen.width / num;
			float num3 = (float)Screen.height / num;
			bool showMap = ShowMap;
			Rect val;
			if (showMap)
			{
				val = UiTheme.Centered(num, Mathf.Min(1240f, num2 - 40f), Mathf.Min(740f, num3 - 40f));
			}
			else
			{
				float num4 = (float)Mathf.Clamp(_items.Count, 2, 7) * 68f;
				val = UiTheme.Centered(num, 500f, 108f + num4 + 40f + 26f + 22f);
			}
			UiTheme.Fill(new Rect(0f, 0f, num2, num3), new Color(0f, 0f, 0f, 0.45f));
			GUI.Box(val, GUIContent.none, UiTheme.Window);
			UiTheme.GlowAt(new Vector2(((Rect)(ref val)).x + 120f, ((Rect)(ref val)).y + 30f), 220f, UiTheme.Alpha(UiTheme.Energy, 0.12f));
			if (DrawHeader(val))
			{
				GUI.matrix = matrix;
				return;
			}
			float num5 = ((Rect)(ref val)).y + 22f + 58f + 18f;
			float num6 = ((Rect)(ref val)).yMax - 22f - 26f - 12f;
			Vector2 mousePosition = Event.current.mousePosition;
			_mouseArea = Area.None;
			Rect rect = default(Rect);
			if (showMap)
			{
				((Rect)(ref rect))..ctor(((Rect)(ref val)).xMax - 22f - 340f, num5, 340f, num6 - num5);
				_mapRect = new Rect(((Rect)(ref val)).x + 22f, num5, ((Rect)(ref rect)).x - 16f - ((Rect)(ref val)).x - 22f, num6 - num5);
				if (((Rect)(ref _mapRect)).Contains(mousePosition))
				{
					_mouseArea = Area.Map;
					_mouseOnMap = mousePosition - ((Rect)(ref _mapRect)).position;
				}
			}
			else
			{
				((Rect)(ref rect))..ctor(((Rect)(ref val)).x + 22f, num5, ((Rect)(ref val)).width - 44f, num6 - num5);
			}
			if (((Rect)(ref rect)).Contains(mousePosition))
			{
				_mouseArea = Area.List;
			}
			if (showMap)
			{
				if (_fitPending && ((Rect)(ref _mapRect)).width > 0f)
				{
					_fitPending = false;
					FitAll();
				}
				_mapHover = FindMapHover(mousePosition);
				if (HandleMapInput(mousePosition))
				{
					GUI.matrix = matrix;
					return;
				}
			}
			else
			{
				_mapHover = -1;
			}
			int hovered = ((_mapHover >= 0) ? _mapHover : _listHover);
			if (showMap)
			{
				DrawMap(num, hovered);
			}
			if (DrawList(rect, hovered, !showMap))
			{
				GUI.matrix = matrix;
				return;
			}
			DrawFooter(new Rect(((Rect)(ref val)).x + 22f, ((Rect)(ref val)).yMax - 22f - 26f, ((Rect)(ref val)).width - 44f, 26f), showMap);
			GUI.matrix = matrix;
		}

		private bool DrawHeader(Rect rect)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_020d: 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_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: 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_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref rect)).x + 22f;
			float num2 = ((Rect)(ref rect)).y + 22f;
			UiTheme.DrawLabel(new Rect(num, num2 - 4f, 400f, 20f), ModConfig.MasterName.Value.ToUpperInvariant(), UiTheme.Overline, UiTheme.Alpha(UiTheme.Energy, 0.95f));
			UiTheme.Shadowed(new Rect(num, num2 + 14f, ((Rect)(ref rect)).width - 44f - 260f, 44f), _network, UiTheme.HeadingFor(_network), UiTheme.Gold);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref rect)).xMax - 22f - 34f, num2 + 6f, 34f, 34f);
			bool flag = ((Rect)(ref val)).Contains(Event.current.mousePosition);
			UiTheme.Fill(val, flag ? new Color(0.75f, 0.2f, 0.15f, 0.85f) : new Color(1f, 1f, 1f, 0.06f), 17f);
			UiTheme.Outline(val, new Color(1f, 1f, 1f, flag ? 0.35f : 0.12f), 1f, 17f);
			UiTheme.DrawLabel(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y - 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), "×", UiTheme.Symbol, UiTheme.Text);
			if (GUI.Button(val, GUIContent.none, GUIStyle.none))
			{
				Close();
				return true;
			}
			string text = ((_items.Count == 1) ? "1 destination" : $"{_items.Count} destinations");
			float num3 = UiTheme.Width(UiTheme.CardInfo, text) + 34f;
			Rect rect2 = default(Rect);
			((Rect)(ref rect2))..ctor(((Rect)(ref val)).x - 12f - num3, num2 + 9f, num3, 28f);
			UiTheme.Fill(rect2, UiTheme.Alpha(UiTheme.Energy, 0.16f), 14f);
			UiTheme.Outline(rect2, UiTheme.Alpha(UiTheme.Energy, 0.5f), 1f, 14f);
			UiTheme.Circle(new Vector2(((Rect)(ref rect2)).x + 14f, ((Rect)(ref rect2)).center.y), 3.5f, (_items.Count > 0) ? UiTheme.Energy : UiTheme.Muted);
			UiTheme.DrawLabel(new Rect(((Rect)(ref rect2)).x + 24f, ((Rect)(ref rect2)).y, num3 - 24f, ((Rect)(ref rect2)).height), text, UiTheme.CardInfo, UiTheme.Text);
			UiTheme.Tinted(new Rect(((Rect)(ref rect)).x + 22f, ((Rect)(ref rect)).y + 22f + 58f + 4f, ((Rect)(ref rect)).width - 44f, 1f), (Texture)(object)UiTheme.FadeLine, UiTheme.Alpha(UiTheme.Gold, 0.45f));
			return false;
		}

		private void DrawFooter(Rect rect, bool showMap)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			float x = ((Rect)(ref rect)).x;
			if (_items.Count > 0)
			{
				x = KeyHint(x, rect, "Click", "travel");
				x = KeyHint(x, rect, (_items.Count > 1) ? $"1-{Mathf.Min(9, _items.Count)}" : "1", "quick travel");
			}
			if (showMap)
			{
				x = KeyHint(x, rect, "Wheel", "zoom");
				x = KeyHint(x, rect, "Drag", "move map");
			}
			KeyHint(x, rect, "Esc", "close");
		}

		private static float KeyHint(float x, Rect row, string key, string action)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			float num = UiTheme.Width(UiTheme.KeyCap, key) + 14f;
			Rect rect = default(Rect);
			((Rect)(ref rect))..ctor(x, ((Rect)(ref row)).y + 2f, num, ((Rect)(ref row)).height - 4f);
			UiTheme.Fill(rect, new Color(1f, 1f, 1f, 0.07f), 5f);
			UiTheme.Outline(rect, new Color(1f, 1f, 1f, 0.18f), 1f, 5f);
			UiTheme.DrawLabel(rect, key, UiTheme.KeyCap, UiTheme.Text);
			float num2 = UiTheme.Width(UiTheme.CardInfo, action);
			UiTheme.DrawLabel(new Rect(((Rect)(ref rect)).xMax + 7f, ((Rect)(ref row)).y, num2 + 4f, ((Rect)(ref row)).height), action, UiTheme.CardInfo, UiTheme.Muted);
			return ((Rect)(ref rect)).xMax + 7f + num2 + 22f;
		}

		private void FitAll()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			_map.Fit(_mapRect, _source.Position, _items.Select((PortalEntry i) => i.Position), 900f);
		}

		private Rect MapButton(int index)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(((Rect)(ref _mapRect)).xMax - 12f - 32f, ((Rect)(ref _mapRect)).y + 12f + (float)index * 38f, 32f, 32f);
		}

		private int FindMapHover(Vector2 mouse)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Rect)(ref _mapRect)).Contains(mouse) || _dragging)
			{
				return -1;
			}
			for (int i = 0; i < 3; i++)
			{
				Rect val = MapButton(i);
				if (((Rect)(ref val)).Contains(mouse))
				{
					return -1;
				}
			}
			Vector2 val2 = mouse - ((Rect)(ref _mapRect)).position;
			int result = -1;
			float num = 18f;
			for (int j = 0; j < _items.Count; j++)
			{
				float num2 = Vector2.Distance(_map.WorldToGui(_mapRect, _items[j].Position), val2);
				if (num2 < num)
				{
					result = j;
					num = num2;
				}
			}
			return result;
		}

		private bool HandleMapInput(Vector2 mouse)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected I4, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			Event current = Event.current;
			EventType type = current.type;
			switch ((int)type)
			{
			case 0:
			{
				if (current.button != 0 || !((Rect)(ref _mapRect)).Contains(mouse))
				{
					break;
				}
				for (int i = 0; i < 3; i++)
				{
					Rect val = MapButton(i);
					if (((Rect)(ref val)).Contains(mouse))
					{
						Vector2 pivot = ((Rect)(ref _mapRect)).size / 2f;
						switch (i)
						{
						case 0:
							_map.Zoom(_mapRect, pivot, 0.64000005f);
							break;
						case 1:
							_map.Zoom(_mapRect, pivot, 1.5624999f);
							break;
						default:
							FitAll();
							break;
						}
						current.Use();
						return false;
					}
				}
				_pressedOnMap = true;
				_dragging = false;
				_pressPosition = mouse;
				current.Use();
				break;
			}
			case 3:
				if (_pressedOnMap)
				{
					if (!_dragging && Vector2.Distance(mouse, _pressPosition) > 4f)
					{
						_dragging = true;
					}
					if (_dragging)
					{
						_map.Pan(_mapRect, current.delta);
					}
					current.Use();
				}
				break;
			case 1:
				if (_pressedOnMap)
				{
					int num = ((!_dragging) ? FindMapHover(mouse) : (-1));
					_pressedOnMap = false;
					_dragging = false;
					current.Use();
					if (num >= 0)
					{
						Select(_items[num]);
						return true;
					}
				}
				break;
			}
			return false;
		}

		private void DrawMap(float scale, int hovered)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: 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_01d6: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type != 7)
			{
				return;
			}
			UiTheme.Fill(_mapRect, UiTheme.Ink);
			_map.Draw(_mapRect, scale);
			GUI.DrawTexture(_mapRect, (Texture)(object)UiTheme.Vignette);
			GUI.BeginGroup(_mapRect);
			Vector2 size = ((Rect)(ref _mapRect)).size;
			float unscaledTime = Time.unscaledTime;
			Vector2 val = _map.WorldToGui(_mapRect, _source.Position);
			List<Vector2> list = _items.Select((PortalEntry i) => _map.WorldToGui(_mapRect, i.Position)).ToList();
			if (hovered >= 0)
			{
				DrawRoute(val, list[hovered], unscaledTime);
			}
			List<Rect> list2 = new List<Rect> { MarkerRect(val) };
			list2.AddRange(list.Select(MarkerRect));
			Rect bounds = default(Rect);
			((Rect)(ref bounds))..ctor(Vector2.zero, size);
			DrawMapLabel(list2, bounds, val, "You are here", UiTheme.Gold, -1);
			for (int num = 0; num < _items.Count; num++)
			{
				if (num != hovered)
				{
					DrawMapLabel(list2, bounds, list[num], _items[num].DisplayName, UiTheme.Text, num + 1);
				}
			}
			DrawMaster(val, unscaledTime);
			for (int num2 = 0; num2 < _items.Count; num2++)
			{
				if (num2 != hovered)
				{
					DrawMinor(list[num2], num2, hovered: false, unscaledTime);
				}
			}
			if (hovered >= 0)
			{
				DrawMinor(list[hovered], hovered, hovered: true, unscaledTime);
				DrawTooltip(list[hovered], _items[hovered], size);
			}
			DrawScaleBar(size);
			GUI.EndGroup();
			UiTheme.Outline(_mapRect, UiTheme.Alpha(UiTheme.Gold, 0.35f), 1.5f);
			DrawMapButtons();
			if (_items.Count == 0)
			{
				DrawEmptyBanner();
			}
		}

		private static Rect MarkerRect(Vector2 marker)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(marker.x - 12f, marker.y - 12f, 24f, 24f);
		}

		private static void DrawMapLabel(List<Rect> taken, Rect bounds, Vector2 marker, string text, Color color, int owner)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0079: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			float num = UiTheme.Width(UiTheme.MapLabel, text) + 6f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(marker.x - num / 2f, marker.y + 14f, num, 20f);
			int num2 = ((owner >= 0) ? owner : 0);
			for (int i = 0; i < taken.Count; i++)
			{
				if (i != num2)
				{
					Rect val2 = taken[i];
					if (((Rect)(ref val2)).Overlaps(val))
					{
						return;
					}
				}
			}
			if (((Rect)(ref bounds)).Overlaps(val))
			{
				taken.Add(val);
				UiTheme.Shadowed(val, text, UiTheme.MapLabel, color);
			}
		}

		private static void DrawMaster(Vector2 p, float time)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 2; i++)
			{
				float num = Mathf.Repeat(time * 0.5f + (float)i * 0.5f, 1f);
				UiTheme.Ring(p, 10f + num * 26f, 2f, UiTheme.Alpha(UiTheme.Gold, (1f - num) * 0.7f));
			}
			UiTheme.GlowAt(p, 34f, UiTheme.Alpha(UiTheme.Gold, 0.55f));
			UiTheme.Tinted(new Rect(p.x - 13f, p.y - 13f, 26f, 26f), (Texture)(object)UiTheme.Diamond, UiTheme.Gold);
			UiTheme.Tinted(new Rect(p.x - 5f, p.y - 5f, 10f, 10f), (Texture)(object)UiTheme.Diamond, new Color(1f, 0.97f, 0.85f));
		}

		private static void DrawMinor(Vector2 p, int index, bool hovered, float time)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_0053: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			float num = (hovered ? 13f : 10f);
			UiTheme.GlowAt(p, hovered ? 40f : 24f, UiTheme.Alpha(UiTheme.Energy, hovered ? 0.8f : 0.5f));
			if (hovered)
			{
				float num2 = Mathf.Repeat(time * 1.2f, 1f);
				UiTheme.Ring(p, num + 2f + num2 * 14f, 2f, UiTheme.Alpha(UiTheme.Energy, 1f - num2));
			}
			UiTheme.Circle(p, num + 2f, UiTheme.Ink);
			UiTheme.Circle(p, num, UiTheme.Energy);
			UiTheme.Ring(p, num + 1.5f, 1.5f, (Color)(hovered ? Color.white : new Color(1f, 1f, 1f, 0.55f)));
			string text = ((index < 9) ? (index + 1).ToString() : string.Empty);
			if (text.Length > 0)
			{
				UiTheme.DrawLabel(new Rect(p.x - num, p.y - num, num * 2f, num * 2f), text, UiTheme.Badge, Color.white);
			}
		}

		private static void DrawRoute(Vector2 from, Vector2 to, float time)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = to - from;
			float magnitude = ((Vector2)(ref val)).magnitude;
			if (!(magnitude < 30f))
			{
				Vector2 val2 = val / magnitude;
				float num = Mathf.Repeat(time * 30f, 11f);
				for (float num2 = 16f + num; num2 < magnitude - 14f; num2 += 11f)
				{
					float num3 = Mathf.Clamp01(Mathf.Min(num2 - 16f, magnitude - 14f - num2) / 30f);
					UiTheme.Circle(from + val2 * num2, 2.2f, UiTheme.Alpha(Color.Lerp(UiTheme.Gold, UiTheme.Energy, num2 / magnitude), 0.9f * num3));
				}
			}
		}

		private void DrawTooltip(Vector2 p, PortalEntry item, Vector2 bounds)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: 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)
			string text = Describe(item);
			float num = Mathf.Max(new float[3]
			{
				UiTheme.Width(UiTheme.Tooltip, item.DisplayName),
				UiTheme.Width(UiTheme.TooltipInfo, text),
				120f
			}) + 28f;
			Rect rect = default(Rect);
			((Rect)(ref rect))..ctor(p.x + 22f, p.y - 38f, num, 76f);
			if (((Rect)(ref rect)).xMax > bounds.x - 8f)
			{
				((Rect)(ref rect)).x = p.x - 22f - num;
			}
			((Rect)(ref rect)).y = Mathf.Clamp(((Rect)(ref rect)).y, 8f, bounds.y - ((Rect)(ref rect)).height - 8f);
			UiTheme.Fill(new Rect(((Rect)(ref rect)).x + 2f, ((Rect)(ref rect)).y + 4f, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), new Color(0f, 0f, 0f, 0.35f), 9f);
			UiTheme.Fill(rect, new Color(0.08f, 0.07f, 0.065f, 0.96f), 9f);
			UiTheme.Outline(rect, UiTheme.Alpha(UiTheme.Energy, 0.8f), 1.5f, 9f);
			UiTheme.Fill(new Rect(((Rect)(ref rect)).x + 1.5f, ((Rect)(ref rect)).y + 10f, 3f, ((Rect)(ref rect)).height - 20f), UiTheme.Energy, 1.5f);
			UiTheme.DrawLabel(new Rect(((Rect)(ref rect)).x + 14f, ((Rect)(ref rect)).y + 8f, num - 20f, 24f), item.DisplayName, UiTheme.Tooltip, UiTheme.Text);
			UiTheme.DrawLabel(new Rect(((Rect)(ref rect)).x + 14f, ((Rect)(ref rect)).y + 29f, num - 20f, 22f), text, UiTheme.TooltipInfo, UiTheme.Muted);
			UiTheme.DrawLabel(new Rect(((Rect)(ref rect)).x + 14f, ((Rect)(ref rect)).y + 48f, num - 20f, 22f), "Click to travel", UiTheme.TooltipInfo, UiTheme.Energy);
		}

		private void DrawScaleBar(Vector2 size)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			float num = _map.MetersPerUnit(_mapRect);
			float[] obj = new float[10] { 50f, 100f, 200f, 250f, 500f, 1000f, 2000f, 2500f, 5000f, 10000f };
			float num2 = obj[0];
			float[] array = obj;
			foreach (float num3 in array)
			{
				if (num3 / num <= 130f)
				{
					num2 = num3;
				}
			}
			float num4 = num2 / num;
			float num5 = size.y - 20f;
			UiTheme.Fill(new Rect(16f - 8f, num5 - 22f, num4 + 16f, 34f), new Color(0f, 0f, 0f, 0.35f), 6f);
			UiTheme.Fill(new Rect(16f, num5, num4, 2f), UiTheme.Text);
			UiTheme.Fill(new Rect(16f, num5 - 5f, 2f, 7f), UiTheme.Text);
			UiTheme.Fill(new Rect(16f + num4 - 2f, num5 - 5f, 2f, 7f), UiTheme.Text);
			UiTheme.Shadowed(new Rect(16f, num5 - 21f, num4, 18f), FormatDistance(num2), UiTheme.CardInfo, UiTheme.Text);
		}

		private void DrawMapButtons()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_003b: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: 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)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Un