Decompiled source of Wayfare v0.4.0

plugins\Wayfare.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using AreaLoading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Charter;
using ConfigReload;
using HarmonyLib;
using Hotkeys;
using MapClicks;
using Microsoft.CodeAnalysis;
using PatchGuard;
using SyncedConfig;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;
using Valheim.SettingsGui;
using Wayfare.Core;
using Wayfare.Portals;
using Wayfare.QuickJumps;
using Wayfare.SeaGates;
using Wayfare.Targeting;
using WindowInput;
using YamlConfig;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Wayfare")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Wayfare: map-based portal targeting for Valheim")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0+3d8cf0092a6bce80eac91090e355d40c4c33d1cd")]
[assembly: AssemblyProduct("Wayfare")]
[assembly: AssemblyTitle("Wayfare")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 Wayfare
{
	[BepInPlugin("com.Wayfare", "Wayfare", "0.4.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.Wayfare";

		public const string PluginName = "Wayfare";

		public const string PluginVersion = "0.4.0";

		public static ManualLogSource Log { get; private set; }

		public static SyncedConfiguration Synced { get; private set; }

		private void Awake()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Synced = new SyncedConfiguration((BaseUnityPlugin)(object)this, ((BaseUnityPlugin)this).Logger, "Wayfare", "0.4.0");
			WayfareConfig.Initialize(Synced);
			Words.Touch();
			SeaGateWords.Touch();
			Harmony val = new Harmony("com.Wayfare");
			val.PatchAll(Assembly.GetExecutingAssembly());
			JumpSpeed.Install(val);
			IconClick.Install(val);
			GameWindow.Install(val);
			GameWindow.Add(() => PortalPicker.IsOpen, PortalPicker.Close);
			PortalDiscovery.EnsureRunning();
			PortalRegistry.EnsureRunning();
			MapOverlay.EnsureRunning();
			SeaGateDriver.EnsureRunning();
			Synced.Finish(val);
			Guard.Install(val, ((BaseUnityPlugin)this).Logger, Assembly.GetExecutingAssembly());
		}
	}
}
namespace Wayfare.Targeting
{
	public static class FavouritesPanel
	{
		private sealed class Row
		{
			public GameObject Root;

			public Text Label;

			public ZDOID Target;
		}

		private const float RowHeight = 26f;

		private const float PanelWidth = 180f;

		private const float PanelHeight = 400f;

		private static RectTransform root;

		private static RectTransform content;

		private static readonly List<Row> rows = new List<Row>();

		private static float scrollOffset;

		private static int shownPortals = -1;

		private static int shownFavourites = -1;

		private static long shownPlayer;

		private static bool shownAdmin;

		public static void Tick()
		{
			if (!TargetingSession.Active || (Object)(object)Minimap.instance == (Object)null || (Object)(object)Minimap.instance.m_largeRoot == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				Clear();
				return;
			}
			EnsureRoot();
			RefreshIfChanged();
			PollScroll();
		}

		public static void Clear()
		{
			if (rows.Count != 0 || (!((Object)(object)root == (Object)null) && ((Component)root).gameObject.activeSelf))
			{
				DestroyRows(0);
				scrollOffset = 0f;
				shownPortals = -1;
				if ((Object)(object)root != (Object)null)
				{
					((Component)root).gameObject.SetActive(false);
				}
			}
		}

		private static void PollScroll()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			float y = Input.mouseScrollDelta.y;
			if (y != 0f && RectTransformUtility.RectangleContainsScreenPoint(root, Vector2.op_Implicit(ZInput.pointerPosition), (Camera)null))
			{
				ScrollBy((0f - y) * 26f);
			}
		}

		private static void ScrollBy(float amount)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(0f, (float)rows.Count * 26f - 400f);
			scrollOffset = Mathf.Clamp(scrollOffset + amount, 0f, num);
			content.anchoredPosition = new Vector2(0f, scrollOffset);
		}

		private static void EnsureRoot()
		{
			if ((Object)(object)root != (Object)null)
			{
				if (!((Component)root).gameObject.activeSelf)
				{
					((Component)root).gameObject.SetActive(true);
				}
			}
			else
			{
				rows.Clear();
				shownPortals = -1;
				BuildPanel();
			}
		}

		private static void BuildPanel()
		{
			//IL_0049: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			root = NewRect("Wayfare.Favourites", Minimap.instance.m_largeRoot.transform);
			((Component)root).gameObject.AddComponent<RectMask2D>();
			RectTransform obj = root;
			RectTransform obj2 = root;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 0.5f);
			obj2.anchorMax = val;
			obj.anchorMin = val;
			root.pivot = new Vector2(0f, 0.5f);
			root.anchoredPosition = new Vector2(20f, 0f);
			root.sizeDelta = new Vector2(180f, 400f);
			content = NewRect("Rows", (Transform)(object)root);
			content.anchorMin = new Vector2(0f, 1f);
			content.anchorMax = Vector2.one;
			content.pivot = new Vector2(0f, 1f);
			content.sizeDelta = Vector2.zero;
		}

		private static void RefreshIfChanged()
		{
			long playerID = Player.m_localPlayer.GetPlayerID();
			bool flag = (Object)(object)ZNet.instance != (Object)null && ZNet.instance.LocalPlayerIsAdminOrHost();
			int version = PortalRegistry.Version;
			int version2 = PlayerFavourites.Version;
			if (version != shownPortals || version2 != shownFavourites || playerID != shownPlayer || flag != shownAdmin)
			{
				shownPortals = version;
				shownFavourites = version2;
				shownPlayer = playerID;
				shownAdmin = flag;
				Show(Collect(playerID, flag));
			}
		}

		private static List<PortalInfo> Collect(long playerId, bool isAdmin)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			List<PortalInfo> list = new List<PortalInfo>();
			foreach (PortalInfo portal in PortalRegistry.Portals)
			{
				if (PlayerFavourites.IsFavourite(portal.Id) && PortalAccess.MayTarget(portal.Mode, portal.Owner, playerId, isAdmin))
				{
					list.Add(portal);
				}
			}
			return list;
		}

		private static void Show(List<PortalInfo> favourites)
		{
			//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)
			for (int i = 0; i < favourites.Count; i++)
			{
				if (i == rows.Count)
				{
					rows.Add(BuildRow(i));
				}
				rows[i].Target = favourites[i].Id;
				rows[i].Label.text = (string.IsNullOrEmpty(favourites[i].Tag) ? "(unnamed portal)" : favourites[i].Tag);
			}
			DestroyRows(favourites.Count);
			ScrollBy(0f);
		}

		private static void DestroyRows(int keep)
		{
			for (int num = rows.Count - 1; num >= keep; num--)
			{
				if ((Object)(object)rows[num].Root != (Object)null)
				{
					Object.Destroy((Object)(object)rows[num].Root);
				}
				rows.RemoveAt(num);
			}
		}

		private static Row BuildRow(int index)
		{
			//IL_0029: 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_0040: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			RectTransform val = NewRect("Row", (Transform)(object)content);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 1f);
			val.anchorMax = val2;
			val.anchorMin = val2;
			val.pivot = new Vector2(0f, 1f);
			val.anchoredPosition = new Vector2(0f, (float)(-index) * 26f);
			val.sizeDelta = new Vector2(180f, 24f);
			Image image = ((Component)val).gameObject.AddComponent<Image>();
			Button obj = ((Component)val).gameObject.AddComponent<Button>();
			Tint(obj, image);
			Row row = new Row
			{
				Root = ((Component)val).gameObject,
				Label = AddLabel(val)
			};
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				TargetingSession.Select(row.Target);
			});
			return row;
		}

		private static void Tint(Button button, Image image)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_004f: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)image).color = Color.white;
			((Selectable)button).targetGraphic = (Graphic)(object)image;
			ColorBlock colors = ((Selectable)button).colors;
			((ColorBlock)(ref colors)).normalColor = new Color(0f, 0f, 0f, 0.55f);
			((ColorBlock)(ref colors)).highlightedColor = new Color(0.32f, 0.26f, 0.1f, 0.8f);
			((ColorBlock)(ref colors)).pressedColor = new Color(0.5f, 0.4f, 0.15f, 0.9f);
			((ColorBlock)(ref colors)).selectedColor = ((ColorBlock)(ref colors)).highlightedColor;
			((ColorBlock)(ref colors)).colorMultiplier = 1f;
			((Selectable)button).colors = colors;
		}

		private static Text AddLabel(RectTransform parent)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = NewRect("Label", (Transform)(object)parent);
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = Vector2.one;
			obj.offsetMin = new Vector2(6f, 0f);
			obj.offsetMax = new Vector2(-6f, 0f);
			Text obj2 = ((Component)obj).gameObject.AddComponent<Text>();
			obj2.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			obj2.fontSize = 13;
			obj2.alignment = (TextAnchor)3;
			((Graphic)obj2).color = Color.white;
			((Graphic)obj2).raycastTarget = false;
			return obj2;
		}

		private static RectTransform NewRect(string name, Transform parent)
		{
			//IL_0014: 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_002c: Expected O, but got Unknown
			RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val).SetParent(parent, false);
			return val;
		}
	}
	public static class HotkeyToggle
	{
		public static bool IconsOn { get; private set; }

		public static void Toggle()
		{
			IconsOn = !IconsOn;
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	public static class HotkeyTogglePatch
	{
		[HarmonyPostfix]
		public static void Postfix(Player __instance)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && WayfareConfig.Enabled.Value && Minimap.IsOpen() && !TargetingSession.Active && Input.anyKeyDown && Hotkey.Pressed(WayfareConfig.ToggleIconsKey))
			{
				HotkeyToggle.Toggle();
			}
		}
	}
	public static class IconFactory
	{
		private const int Size = 32;

		public static readonly Color Gold = new Color(1f, 0.8f, 0.25f, 1f);

		public static readonly Color HereRed = new Color(1f, 0.25f, 0.2f, 1f);

		private static readonly Color FavouriteRingColor = new Color(1f, 0.92f, 0.6f, 0.95f);

		private static Sprite portal;

		private static Sprite circle;

		private static Sprite favourite;

		public static Sprite Portal
		{
			get
			{
				if ((Object)(object)portal == (Object)null)
				{
					portal = GamePortal();
				}
				if (!((Object)(object)portal != (Object)null))
				{
					return Circle;
				}
				return portal;
			}
		}

		public static Sprite Favourite
		{
			get
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)favourite != (Object)null))
				{
					return favourite = BuildRing(FavouriteRingColor);
				}
				return favourite;
			}
		}

		private static Sprite Circle
		{
			get
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)circle != (Object)null))
				{
					return circle = BuildCircle(Color.white);
				}
				return circle;
			}
		}

		private static Sprite GamePortal()
		{
			//IL_0023: 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_0030: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Minimap.instance == (Object)null)
			{
				return null;
			}
			foreach (SpriteData icon in Minimap.instance.m_icons)
			{
				if ((int)icon.m_name == 6)
				{
					return icon.m_icon;
				}
			}
			return null;
		}

		private static Sprite BuildCircle(Color color)
		{
			//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)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = NewTexture();
			float num = 15.5f;
			float num2 = 15f;
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num3 = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(num, num));
					val.SetPixel(j, i, (num3 <= num2) ? color : Color.clear);
				}
			}
			val.Apply();
			return ToSprite(val);
		}

		private static Sprite BuildRing(Color ringColor)
		{
			//IL_002a: 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_005f: 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)
			Texture2D val = NewTexture();
			float num = 15.5f;
			float num2 = 15f;
			float num3 = num2 - 3f;
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num4 = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(num, num));
					bool flag = num4 <= num2 && num4 >= num3;
					val.SetPixel(j, i, flag ? ringColor : Color.clear);
				}
			}
			val.Apply();
			return ToSprite(val);
		}

		private static Texture2D NewTexture()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			return new Texture2D(32, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1
			};
		}

		private static Sprite ToSprite(Texture2D texture)
		{
			//IL_0015: 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)
			return Sprite.Create(texture, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 32f);
		}
	}
	[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
	public static class MapLeftClickPatch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (SeaGatePicker.Active)
			{
				return !SeaGatePicker.TryClick(Vector2.op_Implicit(ZInput.pointerPosition));
			}
			if (!WayfareConfig.PortalsOn || !TargetingSession.Active || !MapOverlay.TryHitTest(Vector2.op_Implicit(ZInput.pointerPosition), out var hit))
			{
				return true;
			}
			IconClick.Hold(delegate
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				TargetingSession.Select(hit);
			});
			return false;
		}
	}
	[HarmonyPatch(typeof(Minimap), "RemovePinUnderPointer")]
	public static class MapRightClickPatch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			if (!WayfareConfig.PortalsOn || !MapOverlay.TryHitTest(Vector2.op_Implicit(ZInput.pointerPosition), out var hit))
			{
				return true;
			}
			if (IconClick.PinUnderPointer(Minimap.instance))
			{
				return true;
			}
			bool flag = PlayerFavourites.Toggle(hit);
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				((Character)Player.m_localPlayer).Message((MessageType)1, flag ? Words.Favourited : Words.Unfavourited, 0, (Sprite)null, false);
			}
			return false;
		}
	}
	internal static class MapFit
	{
		private const float Margin = 1.3f;

		private const float MinSpan = 500f;

		public static void FitPortals(Minimap map, Player player, Vector3 here)
		{
			//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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			Bounds val = PortalBounds(player, here);
			Rect rect = ((Graphic)map.m_mapImageLarge).rectTransform.rect;
			float num = ((((Rect)(ref rect)).height > 0f) ? (((Rect)(ref rect)).width / ((Rect)(ref rect)).height) : 1f);
			float num2 = Mathf.Max(Mathf.Max(((Bounds)(ref val)).size.z, ((Bounds)(ref val)).size.x / num) * 1.3f, 500f);
			map.LargeZoom = num2 / ((float)map.m_textureSize * map.m_pixelSize);
			map.m_mapOffset = ((Bounds)(ref val)).center - Flat(((Component)player).transform.position);
		}

		private static Bounds PortalBounds(Player player, Vector3 here)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0069: 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)
			long playerID = player.GetPlayerID();
			bool isAdmin = (Object)(object)ZNet.instance != (Object)null && ZNet.instance.LocalPlayerIsAdminOrHost();
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(Flat(here), Vector3.zero);
			foreach (PortalInfo portal in PortalRegistry.Portals)
			{
				if (PortalAccess.MayTarget(portal.Mode, portal.Owner, playerID, isAdmin))
				{
					((Bounds)(ref result)).Encapsulate(Flat(portal.Position));
				}
			}
			return result;
		}

		private static Vector3 Flat(Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(point.x, 0f, point.z);
		}
	}
	public static class MapIconLayer
	{
		private const float NormalSize = 24f;

		private const float ChoosingSize = 36f;

		private const float PulseAmount = 0.15f;

		private const float PulseSeconds = 1.2f;

		private static RectTransform layer;

		public static RectTransform Root
		{
			get
			{
				Minimap instance = Minimap.instance;
				RectTransform val = (RectTransform)(((Object)(object)instance != (Object)null && (Object)(object)instance.m_pinRootLarge != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val == (Object)null)
				{
					return null;
				}
				if ((Object)(object)layer == (Object)null)
				{
					layer = Build(val);
				}
				if (((Transform)layer).GetSiblingIndex() != ((Transform)val).childCount - 1)
				{
					((Transform)layer).SetAsLastSibling();
				}
				return layer;
			}
		}

		public static bool Choosing
		{
			get
			{
				if (!TargetingSession.Active)
				{
					return SeaGatePicker.Active;
				}
				return true;
			}
		}

		public static float IconSize(float factor = 1f, bool pulse = true)
		{
			float num = StillSize(factor);
			if (!(Choosing && pulse))
			{
				return num;
			}
			return num * (1f + 0.15f * Mathf.Sin(Time.unscaledTime * 2f * (float)Math.PI / 1.2f));
		}

		public static float ClickSize()
		{
			return StillSize(1f) * (Choosing ? 1.15f : 1f);
		}

		private static float StillSize(float factor)
		{
			return (Choosing ? 36f : 24f) * factor * Mathf.Max(0.25f, WayfareConfig.IconScale.Value);
		}

		private static RectTransform Build(RectTransform mapRect)
		{
			//IL_0018: 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_0027: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0051: 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_0062: Expected O, but got Unknown
			RectTransform val = (RectTransform)new GameObject("Wayfare.MapIcons", new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val).SetParent((Transform)(object)mapRect, false);
			val.anchorMin = Vector2.zero;
			val.anchorMax = Vector2.one;
			val.offsetMin = Vector2.zero;
			val.offsetMax = Vector2.zero;
			((Transform)val).SetAsLastSibling();
			return val;
		}
	}
	internal static class MapOpening
	{
		public static void Large(Minimap map)
		{
			if (InventoryGui.IsVisible() && (Object)(object)InventoryGui.instance != (Object)null)
			{
				InventoryGui.instance.Hide();
			}
			map.SetMapMode((MapMode)2);
		}
	}
	public static class MapOverlay
	{
		private sealed class Ticker : MonoBehaviour
		{
			private void LateUpdate()
			{
				Tick();
			}
		}

		private static readonly Dictionary<ZDOID, PortalIcon> icons = new Dictionary<ZDOID, PortalIcon>();

		private static readonly List<PortalIcon> spare = new List<PortalIcon>();

		private static readonly HashSet<ZDOID> seen = new HashSet<ZDOID>();

		private static readonly HashSet<ZDOID> listed = new HashSet<ZDOID>();

		private static readonly List<ZDOID> gone = new List<ZDOID>();

		private static GameObject driver;

		private static bool showing;

		private static int keptFor = -1;

		public static void EnsureRunning()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			if (!((Object)(object)driver != (Object)null))
			{
				driver = new GameObject("Wayfare.MapOverlay")
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)(object)driver);
				driver.AddComponent<Ticker>();
			}
		}

		public static bool TryHitTest(Vector2 screenPos, out ZDOID hit)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0063: 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_0073: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			hit = ZDOID.None;
			ZDOID sourceId = TargetingSession.SourceId;
			float num = float.MaxValue;
			foreach (KeyValuePair<ZDOID, PortalIcon> icon in icons)
			{
				RectTransform zone = icon.Value.Zone;
				if (!(icon.Key == sourceId) && !((Object)(object)zone == (Object)null) && ((Component)zone).gameObject.activeInHierarchy && RectTransformUtility.RectangleContainsScreenPoint(zone, screenPos, (Camera)null))
				{
					Vector2 val = Vector2.op_Implicit(((Transform)zone).position) - screenPos;
					float sqrMagnitude = ((Vector2)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						hit = icon.Key;
					}
				}
			}
			return hit != ZDOID.None;
		}

		private static bool ShouldShow()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			if (WayfareConfig.PortalsOn && (Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode == 2 && (TargetingSession.Active || HotkeyToggle.IconsOn))
			{
				return !SeaGatePicker.Active;
			}
			return false;
		}

		private static void Tick()
		{
			if (!ShouldShow())
			{
				HideAll();
				FavouritesPanel.Clear();
			}
			else
			{
				Rebuild();
				FavouritesPanel.Tick();
			}
		}

		private static void Rebuild()
		{
			//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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)MapIconLayer.Root == (Object)null)
			{
				return;
			}
			ReleaseGone();
			long playerID = Player.m_localPlayer.GetPlayerID();
			bool isAdmin = (Object)(object)ZNet.instance != (Object)null && ZNet.instance.LocalPlayerIsAdminOrHost();
			ZDOID sourceId = TargetingSession.SourceId;
			seen.Clear();
			foreach (PortalInfo portal in PortalRegistry.Portals)
			{
				if (Shown(portal, portal.Id == sourceId, playerID, isAdmin))
				{
					seen.Add(portal.Id);
					Place(portal, portal.Id == sourceId);
				}
			}
			HideUnseen();
			showing = true;
		}

		private static bool Shown(PortalInfo info, bool isHere, long playerId, bool isAdmin)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!isHere && !PortalAccess.MayTarget(info.Mode, info.Owner, playerId, isAdmin))
			{
				return false;
			}
			return Minimap.instance.IsPointVisible(info.Position, Minimap.instance.m_mapImageLarge);
		}

		private static void Place(PortalInfo info, bool isHere)
		{
			//IL_0006: 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_0062: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (!icons.TryGetValue(info.Id, out var value) || (Object)(object)value.Root == (Object)null)
			{
				value = (icons[info.Id] = Take());
			}
			if (!((Component)value.Root).gameObject.activeSelf)
			{
				((Component)value.Root).gameObject.SetActive(true);
			}
			float num = default(float);
			float num2 = default(float);
			Minimap.instance.WorldToMapPoint(info.Position, ref num, ref num2);
			value.Root.anchoredPosition = Minimap.instance.MapPointToLocalGuiPos(num, num2, Minimap.instance.m_mapImageLarge);
			float num3 = MapIconLayer.IconSize(1f, !isHere);
			value.Root.sizeDelta = new Vector2(num3, num3);
			float num4 = MapIconLayer.ClickSize();
			value.Zone.sizeDelta = new Vector2(num4, num4);
			value.Show(info.Id, isHere, WayfareConfig.ShowTags.Value ? (info.Tag ?? "") : null);
		}

		private static PortalIcon Take()
		{
			while (spare.Count > 0)
			{
				PortalIcon portalIcon = spare[spare.Count - 1];
				spare.RemoveAt(spare.Count - 1);
				if ((Object)(object)portalIcon.Root != (Object)null)
				{
					return portalIcon;
				}
			}
			return PortalIcon.Make(MapIconLayer.Root);
		}

		private static void HideUnseen()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<ZDOID, PortalIcon> icon in icons)
			{
				if (!seen.Contains(icon.Key))
				{
					Hide(icon.Value);
				}
			}
		}

		private static void ReleaseGone()
		{
			//IL_003b: 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_00a7: 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_00df: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			if (keptFor == PortalRegistry.Version)
			{
				return;
			}
			keptFor = PortalRegistry.Version;
			listed.Clear();
			foreach (PortalInfo portal in PortalRegistry.Portals)
			{
				listed.Add(portal.Id);
			}
			gone.Clear();
			foreach (KeyValuePair<ZDOID, PortalIcon> icon in icons)
			{
				if (!listed.Contains(icon.Key) || (Object)(object)icon.Value.Root == (Object)null)
				{
					gone.Add(icon.Key);
				}
			}
			foreach (ZDOID item in gone)
			{
				PortalIcon portalIcon = icons[item];
				icons.Remove(item);
				if ((Object)(object)portalIcon.Root != (Object)null)
				{
					spare.Add(Hide(portalIcon));
				}
			}
		}

		private static void HideAll()
		{
			if (!showing)
			{
				return;
			}
			showing = false;
			foreach (PortalIcon value in icons.Values)
			{
				Hide(value);
			}
		}

		private static PortalIcon Hide(PortalIcon icon)
		{
			if ((Object)(object)icon.Root != (Object)null && ((Component)icon.Root).gameObject.activeSelf)
			{
				((Component)icon.Root).gameObject.SetActive(false);
			}
			return icon;
		}
	}
	internal static class PickerChoices
	{
		private const string DistanceColour = "#A0A0A0";

		public static void Fill(List<PortalInfo> into, ZDOID here, Vector3 from)
		{
			//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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			into.Clear();
			long playerID = Player.m_localPlayer.GetPlayerID();
			bool isAdmin = (Object)(object)ZNet.instance != (Object)null && ZNet.instance.LocalPlayerIsAdminOrHost();
			foreach (PortalInfo portal in PortalRegistry.Portals)
			{
				if (portal.Id != here && PortalFields.HasName(portal.Tag) && PortalAccess.MayTarget(portal.Mode, portal.Owner, playerID, isAdmin))
				{
					into.Add(portal);
				}
			}
			into.Sort((PortalInfo a, PortalInfo b) => Compare(a, b, from));
		}

		private static int Compare(PortalInfo a, PortalInfo b, Vector3 from)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			bool flag = PlayerFavourites.IsFavourite(a.Id);
			if (flag != PlayerFavourites.IsFavourite(b.Id))
			{
				if (!flag)
				{
					return 1;
				}
				return -1;
			}
			int num = string.Compare(a.Tag.Trim(), b.Tag.Trim(), StringComparison.CurrentCultureIgnoreCase);
			if (num != 0)
			{
				return num;
			}
			return Vector3.Distance(from, a.Position).CompareTo(Vector3.Distance(from, b.Position));
		}

		public static List<string> Labels(List<PortalInfo> choices, Vector3 from)
		{
			//IL_002e: 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)
			List<string> list = new List<string>(choices.Count);
			foreach (PortalInfo choice in choices)
			{
				list.Add(choice.Tag.Trim() + "  <color=#A0A0A0>" + Distance(Vector3.Distance(from, choice.Position)) + "</color>");
			}
			return list;
		}

		private static string Distance(float metres)
		{
			if (!(metres < 1000f))
			{
				return (metres / 1000f).ToString("0.0") + " km";
			}
			return Mathf.RoundToInt(metres) + " m";
		}
	}
	internal static class PickerDropdown
	{
		private const string Preferred = "Radial Size";

		private const float TextSize = 20f;

		public static TMP_Dropdown Source()
		{
			GameObject val = (((Object)(object)Menu.instance != (Object)null) ? Menu.instance.m_settingsPrefab : null);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			TMP_Dropdown[] componentsInChildren = val.GetComponentsInChildren<TMP_Dropdown>(true);
			return ((IEnumerable<TMP_Dropdown>)componentsInChildren).FirstOrDefault((Func<TMP_Dropdown, bool>)((TMP_Dropdown dropdown) => ((Object)dropdown).name == "Radial Size")) ?? componentsInChildren.FirstOrDefault();
		}

		public static TMP_Dropdown Make(TMP_Dropdown source, RectTransform field)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			TMP_Dropdown val = Object.Instantiate<TMP_Dropdown>(source, ((Transform)field).parent, false);
			((Object)val).name = "Destination";
			Strip(val);
			Place((RectTransform)((Component)val).transform, field);
			HideName(val);
			if ((Object)(object)val.captionText != (Object)null)
			{
				val.captionText.enableAutoSizing = false;
				val.captionText.fontSize = 20f;
			}
			return val;
		}

		private static void Strip(TMP_Dropdown dropdown)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			dropdown.onValueChanged = new DropdownEvent();
			SettingsTooltip component = ((Component)dropdown).GetComponent<SettingsTooltip>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
		}

		private static void Place(RectTransform rect, RectTransform field)
		{
			//IL_0002: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = field.anchorMin;
			rect.anchorMax = field.anchorMax;
			rect.pivot = field.pivot;
			rect.anchoredPosition = field.anchoredPosition;
			rect.sizeDelta = field.sizeDelta;
			((Transform)rect).SetSiblingIndex(((Transform)field).GetSiblingIndex());
		}

		private static void HideName(TMP_Dropdown dropdown)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			foreach (Transform item in ((Component)dropdown).transform)
			{
				Transform val = item;
				TMP_Text component = ((Component)val).GetComponent<TMP_Text>();
				if ((Object)(object)component != (Object)null && (Object)(object)component != (Object)(object)dropdown.captionText)
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}
	}
	internal sealed class PickerWindow : MonoBehaviour
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Go;

			public static UnityAction <1>__Close;
		}

		private TMP_Text topic;

		private TMP_Text goText;

		public TMP_Dropdown Dropdown { get; private set; }

		public Button Go { get; private set; }

		public bool Visible => ((Component)this).gameObject.activeSelf;

		public static PickerWindow Build()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			TextInput instance = TextInput.instance;
			TMP_Dropdown val = PickerDropdown.Source();
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_panel == (Object)null || (Object)(object)val == (Object)null)
			{
				return null;
			}
			GameObject val2 = new GameObject("Wayfare_PickerHolder");
			val2.SetActive(false);
			GameObject val3 = Object.Instantiate<GameObject>(instance.m_panel, val2.transform, false);
			((Object)val3).name = "Wayfare_PortalPicker";
			PickerWindow pickerWindow = Assemble(val3, val);
			if ((Object)(object)pickerWindow != (Object)null)
			{
				val3.SetActive(false);
				val3.transform.SetParent(((Component)instance).transform, false);
			}
			Object.Destroy((Object)(object)val2);
			return pickerWindow;
		}

		private static PickerWindow Assemble(GameObject copy, TMP_Dropdown source)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00de: 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_00e9: Expected O, but got Unknown
			Transform val = copy.transform.Find("TextField");
			Transform val2 = copy.transform.Find("Topic");
			Button val3 = Part<Button>(copy, "OK");
			Button val4 = Part<Button>(copy, "Cancel");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null)
			{
				return null;
			}
			PickerWindow pickerWindow = copy.AddComponent<PickerWindow>();
			pickerWindow.Dropdown = PickerDropdown.Make(source, (RectTransform)val);
			Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
			pickerWindow.topic = ((Component)val2).GetComponent<TMP_Text>();
			pickerWindow.Go = val3;
			pickerWindow.goText = Part<TMP_Text>(((Component)val3).gameObject, "Text");
			object obj = <>O.<0>__Go;
			if (obj == null)
			{
				UnityAction val5 = PortalPicker.Go;
				<>O.<0>__Go = val5;
				obj = (object)val5;
			}
			Rewire(val3, (UnityAction)obj);
			object obj2 = <>O.<1>__Close;
			if (obj2 == null)
			{
				UnityAction val6 = PortalPicker.Close;
				<>O.<1>__Close = val6;
				obj2 = (object)val6;
			}
			Rewire(val4, (UnityAction)obj2);
			return pickerWindow;
		}

		private static T Part<T>(GameObject parent, string name) where T : Component
		{
			Transform val = parent.transform.Find(name);
			if (!((Object)(object)val != (Object)null))
			{
				return default(T);
			}
			return ((Component)val).GetComponent<T>();
		}

		private static void Rewire(Button button, UnityAction onClick)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			button.onClick = new ButtonClickedEvent();
			((UnityEvent)button.onClick).AddListener(onClick);
		}

		public void Show(string topicToken, string goToken)
		{
			if ((Object)(object)topic != (Object)null)
			{
				topic.text = Localization.instance.Localize(topicToken);
			}
			if ((Object)(object)goText != (Object)null)
			{
				goText.text = Localization.instance.Localize(goToken);
			}
			((Component)this).gameObject.SetActive(true);
		}

		public void Hide()
		{
			if ((Object)(object)Dropdown != (Object)null && Dropdown.IsExpanded)
			{
				Dropdown.Hide();
			}
			((Component)this).gameObject.SetActive(false);
		}

		private void Update()
		{
			PortalPicker.Tick();
		}
	}
	public static class PlayerFavourites
	{
		private const string Key = "Wayfare.favourites";

		private static Player cachedFor;

		private static HashSet<string> cache;

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

		private static int keysVersion = -1;

		private static int version;

		public static int Version
		{
			get
			{
				Set();
				return version;
			}
		}

		public static bool IsFavourite(ZDOID id)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (TryKey(id, out var key))
			{
				return Set().Contains(key);
			}
			return false;
		}

		public static bool Toggle(ZDOID id)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (!TryKey(id, out var key))
			{
				return false;
			}
			HashSet<string> hashSet = Set();
			bool num = !hashSet.Remove(key);
			if (num)
			{
				hashSet.Add(key);
			}
			Save(hashSet);
			version++;
			return num;
		}

		private static bool TryKey(ZDOID id, out string key)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (keysVersion != PortalRegistry.Version)
			{
				keysVersion = PortalRegistry.Version;
				keys.Clear();
				foreach (PortalInfo portal in PortalRegistry.Portals)
				{
					keys[portal.Id] = KeyOf(portal.Position);
				}
			}
			return keys.TryGetValue(id, out key);
		}

		private static string KeyOf(Vector3 position)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.RoundToInt(position.x) + "/" + Mathf.RoundToInt(position.y) + "/" + Mathf.RoundToInt(position.z);
		}

		private static HashSet<string> Set()
		{
			if ((Object)(object)cachedFor != (Object)(object)Player.m_localPlayer)
			{
				cachedFor = Player.m_localPlayer;
				cache = Load();
				version++;
			}
			return cache ?? (cache = new HashSet<string>());
		}

		private static HashSet<string> Load()
		{
			HashSet<string> hashSet = new HashSet<string>();
			if ((Object)(object)Player.m_localPlayer == (Object)null || !Player.m_localPlayer.m_customData.TryGetValue("Wayfare.favourites", out var value) || string.IsNullOrEmpty(value))
			{
				return hashSet;
			}
			string[] array = value.Split(new char[1] { ',' });
			foreach (string text in array)
			{
				if (text.Split(new char[1] { '/' }).Length == 3)
				{
					hashSet.Add(text);
				}
			}
			return hashSet;
		}

		private static void Save(HashSet<string> set)
		{
			if (!((Object)(object)Player.m_localPlayer == (Object)null))
			{
				Player.m_localPlayer.m_customData["Wayfare.favourites"] = string.Join(",", set);
			}
		}
	}
	public sealed class PortalIcon
	{
		private const float RingOverhang = 0.2f;

		private static readonly LocalWord youAreHere = new LocalWord(Words.YouAreHere);

		public RectTransform Root;

		public Image Image;

		public Image Ring;

		public RectTransform Zone;

		public Text Label;

		public Text Here;

		private Sprite shownSprite;

		private bool ringShown;

		private bool hereShown;

		private bool labelShown = true;

		private ZDOID favouriteFor = ZDOID.None;

		private int favouriteVersion = -1;

		private int favouriteListVersion = -1;

		private bool favourite;

		public static string YouAreHere => youAreHere.Text;

		public void Show(ZDOID id, bool here, string tag)
		{
			//IL_003e: 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)
			Sprite portal = IconFactory.Portal;
			if (portal != shownSprite)
			{
				shownSprite = portal;
				Image.sprite = portal;
				((Graphic)Image).color = IconFactory.Gold;
			}
			SetShown(((Component)Ring).gameObject, IsFavourite(id), ref ringShown);
			SetShown(((Component)Here).gameObject, here, ref hereShown);
			if (here)
			{
				Here.text = YouAreHere;
			}
			SetShown(((Component)Label).gameObject, tag != null, ref labelShown);
			if (tag != null)
			{
				Label.text = tag;
			}
		}

		private bool IsFavourite(ZDOID id)
		{
			//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_0032: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			int version = PlayerFavourites.Version;
			if (id == favouriteFor && version == favouriteVersion && PortalRegistry.Version == favouriteListVersion)
			{
				return favourite;
			}
			favouriteFor = id;
			favouriteVersion = version;
			favouriteListVersion = PortalRegistry.Version;
			favourite = PlayerFavourites.IsFavourite(id);
			return favourite;
		}

		private static void SetShown(GameObject go, bool on, ref bool shown)
		{
			if (on != shown)
			{
				shown = on;
				go.SetActive(on);
			}
		}

		public static PortalIcon Make(RectTransform layer)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Wayfare.PortalIcon", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)layer, false);
			Vector2 anchorMin = (val2.anchorMax = Vector2.zero);
			val2.anchorMin = anchorMin;
			val2.pivot = new Vector2(0.5f, 0.5f);
			Image component = val.GetComponent<Image>();
			((Graphic)component).raycastTarget = false;
			component.preserveAspect = true;
			return new PortalIcon
			{
				Root = val2,
				Image = component,
				Ring = MakeRing(val2),
				Zone = MakeZone(val2),
				Label = MakeText(val2, below: true),
				Here = MakeHere(val2)
			};
		}

		private static Image MakeRing(RectTransform parent)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_006e: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Ring", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)parent, false);
			val2.anchorMin = new Vector2(-0.2f, -0.2f);
			val2.anchorMax = new Vector2(1.2f, 1.2f);
			Vector2 offsetMin = (val2.offsetMax = Vector2.zero);
			val2.offsetMin = offsetMin;
			Image component = val.GetComponent<Image>();
			component.sprite = IconFactory.Favourite;
			((Graphic)component).raycastTarget = false;
			val.SetActive(false);
			return component;
		}

		private static RectTransform MakeZone(RectTransform parent)
		{
			//IL_0018: 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_0027: 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_0030: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			RectTransform val = (RectTransform)new GameObject("ClickArea", new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val).SetParent((Transform)(object)parent, false);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			val.pivot = val2;
			Vector2 anchorMin = (val.anchorMax = val2);
			val.anchorMin = anchorMin;
			val.anchoredPosition = Vector2.zero;
			return val;
		}

		private static Text MakeHere(RectTransform parent)
		{
			//IL_003a: 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)
			Text obj = MakeText(parent, below: false);
			obj.text = ((Localization.instance != null) ? Localization.instance.Localize(Words.YouAreHere) : "You are here");
			obj.fontSize = 11;
			obj.fontStyle = (FontStyle)1;
			((Graphic)obj).color = IconFactory.HereRed;
			((Shadow)((Component)obj).gameObject.AddComponent<Outline>()).effectColor = new Color(0f, 0f, 0f, 0.8f);
			((Component)obj).gameObject.SetActive(false);
			return obj;
		}

		private static Text MakeText(RectTransform parent, bool below)
		{
			//IL_0022: 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_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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0063: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(below ? "Label" : "Here", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)parent, false);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, below ? 0f : 1f);
			val2.anchorMax = val3;
			val2.anchorMin = val3;
			val2.pivot = new Vector2(0.5f, below ? 1f : 0f);
			val2.anchoredPosition = new Vector2(0f, below ? (-2f) : 2f);
			val2.sizeDelta = new Vector2(160f, 20f);
			Text obj = val.AddComponent<Text>();
			obj.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			obj.fontSize = 12;
			obj.alignment = (TextAnchor)(below ? 1 : 7);
			((Graphic)obj).color = Color.white;
			((Graphic)obj).raycastTarget = false;
			obj.horizontalOverflow = (HorizontalWrapMode)1;
			obj.verticalOverflow = (VerticalWrapMode)1;
			return obj;
		}
	}
	public static class PortalPicker
	{
		private const float LeaveDistance = 4f;

		private static readonly List<PortalInfo> choices = new List<PortalInfo>();

		private static PickerWindow window;

		private static TeleportWorld source;

		private static ZDOID chosen = ZDOID.None;

		private static int filledPortals = -1;

		private static int filledFavourites = -1;

		public static bool IsOpen
		{
			get
			{
				if ((Object)(object)window != (Object)null)
				{
					return window.Visible;
				}
				return false;
			}
		}

		public static void Open(TeleportWorld portal)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)portal == (Object)null || (Object)(object)portal.m_nview == (Object)null || !portal.m_nview.IsValid() || (IsOpen && (Object)(object)portal == (Object)(object)source))
			{
				return;
			}
			if (!PortalFields.HasName(portal.m_nview.GetZDO()))
			{
				((Character)localPlayer).Message((MessageType)2, Words.PickerUnnamed, 0, (Sprite)null, false);
				return;
			}
			if ((Object)(object)window == (Object)null)
			{
				window = PickerWindow.Build();
			}
			if (!((Object)(object)window == (Object)null))
			{
				if (InventoryGui.IsVisible() && (Object)(object)InventoryGui.instance != (Object)null)
				{
					InventoryGui.instance.Hide();
				}
				Show(portal);
			}
		}

		private static void Show(TeleportWorld portal)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			source = portal;
			chosen = ZDOID.None;
			PortalRegistry.Refresh();
			Refill();
			window.Show(Words.PickerTopic, Words.PickerGo);
		}

		public static void Close()
		{
			if ((Object)(object)window != (Object)null)
			{
				window.Hide();
			}
			source = null;
		}

		public static void Go()
		{
			//IL_0010: 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_0022: 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)
			if (IsOpen && Here(out var here) && !(chosen == ZDOID.None))
			{
				TeleportGate.RequestTeleport(here, chosen);
			}
		}

		public static void Complete(Vector3 targetPos, Quaternion targetRot)
		{
			//IL_0005: 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)
			if (PortalTravel.Go(source, targetPos, targetRot))
			{
				Close();
			}
		}

		internal static void Tick()
		{
			if (MustClose())
			{
				Close();
			}
			else if (!window.Dropdown.IsExpanded && (filledPortals != PortalRegistry.Version || filledFavourites != PlayerFavourites.Version))
			{
				Refill();
			}
		}

		private static bool MustClose()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!WayfareConfig.InMode(TeleportMode.TargetTeleport) || (Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || !Here(out var _))
			{
				return true;
			}
			return Vector3.Distance(((Component)localPlayer).transform.position, ((Component)source).transform.position) > 4f;
		}

		private static bool Here(out ZDOID here)
		{
			//IL_004c: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (Object)(object)source != (Object)null && (Object)(object)source.m_nview != (Object)null && source.m_nview.IsValid();
			here = (flag ? source.m_nview.GetZDO().m_uid : ZDOID.None);
			return flag;
		}

		private static void Refill()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			filledPortals = PortalRegistry.Version;
			filledFavourites = PlayerFavourites.Version;
			if (Here(out var here) && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				Vector3 position = ((Component)source).transform.position;
				PickerChoices.Fill(choices, here, position);
				Present((choices.Count > 0) ? PickerChoices.Labels(choices, position) : null);
			}
		}

		private static void Present(List<string> labels)
		{
			//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)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			Button go = window.Go;
			TMP_Dropdown dropdown = window.Dropdown;
			((UnityEventBase)dropdown.onValueChanged).RemoveAllListeners();
			dropdown.ClearOptions();
			((Selectable)go).interactable = labels != null;
			((Selectable)dropdown).interactable = labels != null;
			if (labels == null)
			{
				chosen = ZDOID.None;
				dropdown.AddOptions(new List<string> { Localization.instance.Localize(Words.PickerNone) });
				return;
			}
			dropdown.AddOptions(labels);
			int num = Mathf.Max(0, choices.FindIndex((PortalInfo info) => info.Id == chosen));
			chosen = choices[num].Id;
			dropdown.SetValueWithoutNotify(num);
			((UnityEvent<int>)(object)dropdown.onValueChanged).AddListener((UnityAction<int>)Choose);
		}

		private static void Choose(int index)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (index >= 0 && index < choices.Count)
			{
				chosen = choices[index].Id;
			}
		}
	}
	public static class PortalTravel
	{
		public static void Granted(Vector3 targetPos, Quaternion targetRot)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (PortalPicker.IsOpen)
			{
				PortalPicker.Complete(targetPos, targetRot);
			}
			else
			{
				TargetingSession.CompleteTeleport(targetPos, targetRot);
			}
		}

		public static bool Go(TeleportWorld source, Vector3 targetPos, Quaternion targetRot)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)source == (Object)null)
			{
				return false;
			}
			if (!((Humanoid)localPlayer).IsTeleportable(source.m_allowAllItems))
			{
				((Character)localPlayer).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false);
				return false;
			}
			Vector3 val = targetPos + targetRot * Vector3.forward * source.m_exitDistance + Vector3.up;
			((Character)localPlayer).TeleportTo(val, targetRot, true);
			Game.instance.IncrementPlayerStat((PlayerStatType)15, 1f, false);
			return true;
		}
	}
	public static class TargetingSession
	{
		public static bool Active { get; private set; }

		public static TeleportWorld SourcePortal { get; private set; }

		public static ZDOID SourceId
		{
			get
			{
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				if (!Active || (Object)(object)SourcePortal == (Object)null || (Object)(object)SourcePortal.m_nview == (Object)null || !SourcePortal.m_nview.IsValid())
				{
					return ZDOID.None;
				}
				return SourcePortal.m_nview.GetZDO().m_uid;
			}
		}

		public static void Open(TeleportWorld source)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)source == (Object)null) && !((Object)(object)Minimap.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && WayfareConfig.PortalsOn)
			{
				SourcePortal = source;
				Active = true;
				PortalRegistry.Refresh();
				MapOpening.Large(Minimap.instance);
				MapFit.FitPortals(Minimap.instance, Player.m_localPlayer, ((Component)source).transform.position);
			}
		}

		public static void Close()
		{
			Active = false;
			SourcePortal = null;
		}

		public static void Select(ZDOID target)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0013: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			ZDOID sourceId = SourceId;
			if (!(sourceId == ZDOID.None) && !(target == sourceId))
			{
				TeleportGate.RequestTeleport(sourceId, target);
			}
		}

		public static void CompleteTeleport(Vector3 targetPos, Quaternion targetRot)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)SourcePortal == (Object)null)
			{
				Close();
			}
			else if (PortalTravel.Go(SourcePortal, targetPos, targetRot) && (Object)(object)Minimap.instance != (Object)null)
			{
				Minimap.instance.SetMapMode((MapMode)1);
			}
		}

		public static void Deny(string localizedReasonToken)
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, localizedReasonToken, 0, (Sprite)null, false);
			}
		}
	}
	[HarmonyPatch(typeof(TeleportWorldTrigger), "OnTriggerEnter")]
	public static class PortalTriggerPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(TeleportWorldTrigger __instance, Collider colliderIn)
		{
			if (!WayfareConfig.PortalsOn)
			{
				return true;
			}
			Player val = (((Object)(object)colliderIn != (Object)null) ? ((Component)colliderIn).GetComponent<Player>() : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			TeleportWorld componentInParent = ((Component)__instance).GetComponentInParent<TeleportWorld>();
			if (WayfareConfig.InMode(TeleportMode.TargetTeleport))
			{
				PortalPicker.Open(componentInParent);
			}
			else
			{
				TargetingSession.Open(componentInParent);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Minimap), "SetMapMode")]
	public static class MapModeChangePatch
	{
		[HarmonyPostfix]
		public static void Postfix(MapMode mode)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			if (TargetingSession.Active && (int)mode != 2)
			{
				TargetingSession.Close();
			}
		}
	}
	[HarmonyPatch(typeof(Game), "OnDestroy")]
	public static class GameTeardownPatch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			TargetingSession.Close();
			PortalPicker.Close();
		}
	}
	public static class TeleportGate
	{
		public const string RequestRpc = "wf_RequestTeleport";

		public const string GrantedRpc = "wf_TeleportGranted";

		public const string DeniedRpc = "wf_TeleportDenied";

		private static ZRoutedRpc registeredOn;

		public static void EnsureRegistered()
		{
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null && registeredOn != instance)
			{
				registeredOn = instance;
				instance.Register<ZDOID, ZDOID>("wf_RequestTeleport", (Action<long, ZDOID, ZDOID>)OnRequestTeleport);
				instance.Register<ZDOID, Vector3, Quaternion>("wf_TeleportGranted", (Action<long, ZDOID, Vector3, Quaternion>)OnGranted);
				instance.Register<ZDOID, string>("wf_TeleportDenied", (Action<long, ZDOID, string>)OnDenied);
			}
		}

		public static void RequestTeleport(ZDOID source, ZDOID target)
		{
			//IL_0017: 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)
			EnsureRegistered();
			ZRoutedRpc.instance.InvokeRoutedRPC("wf_RequestTeleport", new object[2] { source, target });
		}

		private static void OnRequestTeleport(long sender, ZDOID sourceId, ZDOID targetId)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0058: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				string text = Evaluate(sender, sourceId, targetId);
				if (text != null)
				{
					Deny(sender, targetId, text);
					return;
				}
				ZDO zDO = ZDOMan.instance.GetZDO(targetId);
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "wf_TeleportGranted", new object[3]
				{
					targetId,
					zDO.GetPosition(),
					zDO.GetRotation()
				});
			}
		}

		private static string Evaluate(long sender, ZDOID sourceId, ZDOID targetId)
		{
			//IL_0022: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (!WayfareConfig.PortalsOn)
			{
				return Words.DeniedGeneric;
			}
			PortalDiscovery.EnsureDiscovered();
			if (Blocked(out var reason))
			{
				return reason;
			}
			ZDO zDO = ZDOMan.instance.GetZDO(sourceId);
			ZDO zDO2 = ZDOMan.instance.GetZDO(targetId);
			if (zDO == null || zDO2 == null || !PortalDiscovery.IsPortalPrefab(zDO2.GetPrefab()) || sourceId == targetId)
			{
				return Words.DeniedGeneric;
			}
			if (WayfareConfig.InMode(TeleportMode.TargetTeleport) && (!PortalFields.HasName(zDO) || !PortalFields.HasName(zDO2)))
			{
				return Words.DeniedGeneric;
			}
			if (!PortalAccess.MayTarget(zDO2, SenderIdentity.PlayerId(sender), SenderIdentity.IsAdmin(sender)))
			{
				return DenialReason(zDO2);
			}
			return null;
		}

		internal static bool Blocked(out string reason)
		{
			reason = Words.DeniedBlocked;
			ZoneSystem instance = ZoneSystem.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			if (instance.GetGlobalKey((GlobalKeys)32))
			{
				return true;
			}
			bool flag = (Object)(object)RandEventSystem.instance != (Object)null && RandEventSystem.instance.GetBossEvent() != null;
			if (instance.GetGlobalKey((GlobalKeys)33))
			{
				if (!flag)
				{
					float num = default(float);
					if (instance.GetGlobalKey((GlobalKeys)47, ref num))
					{
						return num > 0f;
					}
					return false;
				}
				return true;
			}
			return false;
		}

		private static string DenialReason(ZDO targetZdo)
		{
			if (PortalFields.GetMode(targetZdo) != PortalMode.Admin)
			{
				return Words.DeniedPrivate;
			}
			return Words.DeniedAdmin;
		}

		private static void Deny(long sender, ZDOID targetId, string reasonToken)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			ZRoutedRpc.instance.InvokeRoutedRPC(sender, "wf_TeleportDenied", new object[2] { targetId, reasonToken });
		}

		private static void OnGranted(long sender, ZDOID targetId, Vector3 targetPos, Quaternion targetRot)
		{
			//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)
			if (SenderIdentity.IsFromServer(sender))
			{
				PortalTravel.Granted(targetPos, targetRot);
			}
		}

		private static void OnDenied(long sender, ZDOID targetId, string reasonToken)
		{
			if (SenderIdentity.IsFromServer(sender))
			{
				TargetingSession.Deny(reasonToken);
			}
		}
	}
	[HarmonyPatch(typeof(ZRoutedRpc))]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	[HarmonyPatch(new Type[] { typeof(bool) })]
	public static class ZRoutedRpcConstructedPatch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			TeleportGate.EnsureRegistered();
			PortalSync.EnsureRegistered();
			ModeCycle.EnsureRegistered();
			SeaGateIndex.EnsureRegistered();
			SeaGateGrant.EnsureRegistered();
			CrewJump.EnsureRegistered();
		}
	}
}
namespace Wayfare.SeaGates
{
	public static class CargoCheck
	{
		private const float IntervalSeconds = 1f;

		private static readonly List<Container> containers = new List<Container>();

		private static float nextAt;

		public static void Tick()
		{
			if (Time.time < nextAt)
			{
				return;
			}
			nextAt = Time.time + 1f;
			Player localPlayer = Player.m_localPlayer;
			ZDO val = OwnZdo(localPlayer);
			if (val != null)
			{
				bool flag = IsAboard(localPlayer) && !((Humanoid)localPlayer).IsTeleportable(false);
				if (val.GetBool(SeaGateFields.HeavyKey, false) != flag)
				{
					val.Set(SeaGateFields.HeavyKey, flag);
				}
			}
		}

		public static bool Blocked(Ship ship, out string reasonToken)
		{
			reasonToken = null;
			if ((Object)(object)ship == (Object)null || WayfareConfig.AllowRestrictedCargo.Value)
			{
				return false;
			}
			if (ContainersTeleportable(ship) && CrewTeleportable(ship))
			{
				return false;
			}
			reasonToken = SeaGateWords.DeniedCargo;
			return true;
		}

		private static ZDO OwnZdo(Player player)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)((Character)player).m_nview == (Object)null || !((Character)player).m_nview.IsValid() || !((Character)player).m_nview.IsOwner())
			{
				return null;
			}
			return ((Character)player).m_nview.GetZDO();
		}

		private static bool IsAboard(Player player)
		{
			foreach (Ship s_currentShip in Ship.s_currentShips)
			{
				if ((Object)(object)s_currentShip != (Object)null && s_currentShip.IsPlayerInBoat(player))
				{
					return true;
				}
			}
			return false;
		}

		private static bool ContainersTeleportable(Ship ship)
		{
			((Component)ship).GetComponentsInChildren<Container>(containers);
			try
			{
				foreach (Container container in containers)
				{
					Inventory val = (((Object)(object)container != (Object)null) ? container.GetInventory() : null);
					if (val != null && !val.IsTeleportable(false))
					{
						return false;
					}
				}
				return true;
			}
			finally
			{
				containers.Clear();
			}
		}

		private static bool CrewTeleportable(Ship ship)
		{
			foreach (Player player in ship.m_players)
			{
				if (!((Object)(object)player == (Object)null) && (((Object)(object)player == (Object)(object)Player.m_localPlayer) ? (!((Humanoid)player).IsTeleportable(false)) : HasHeavyFlag(player)))
				{
					return false;
				}
			}
			return true;
		}

		private static bool HasHeavyFlag(Player player)
		{
			ZNetView nview = ((Character)player).m_nview;
			ZDO val = (((Object)(object)nview != (Object)null && nview.IsValid()) ? nview.GetZDO() : null);
			if (val != null)
			{
				return val.GetBool(SeaGateFields.HeavyKey, false);
			}
			return false;
		}
	}
	internal static class CrewFallback
	{
		private const float SearchSeconds = 0.25f;

		private const float GiveUpSeconds = 10f;

		private const float DryMargin = 0.3f;

		private const float MaxAboveGround = 3f;

		private const float Lift = 0.05f;

		private const float HoldOut = 2f;

		private const float HoldUp = 1f;

		private const int Directions = 8;

		private static readonly float[] Radii = new float[5] { 2f, 3f, 4f, 6f, 8f };

		private static float nextSearch;

		private static float readySince;

		private static bool haveBest;

		private static Vector3 best;

		internal static void Reset()
		{
			nextSearch = 0f;
			readySince = -1f;
			haveBest = false;
		}

		internal static void HoldPoint(JumpOrder order, Player p, out Vector3 pos, out Quaternion rot)
		{
			//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0045: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0076: 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_007d: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (Known(order.DestAnchor) ? order.DestAnchor : order.DestPartner);
			if (!Known(val))
			{
				pos = p.m_teleportFromPos;
				rot = p.m_teleportFromRot;
			}
			else
			{
				Vector3 val2 = Mid(order);
				pos = val + Outward(val, val2) * 2f + Vector3.up * 1f;
				rot = CrewSpot.Facing(val2 - pos);
			}
		}

		internal static bool TryFind(JumpOrder order, Player p, out Vector3 pos, out Quaternion rot)
		{
			//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_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)
			//IL_004f: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			pos = Vector3.zero;
			rot = Quaternion.identity;
			if (Time.time < nextSearch || (Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null)
			{
				return false;
			}
			nextSearch = Time.time + 0.25f;
			if (!Known(order.DestAnchor) && !Known(order.DestPartner))
			{
				return BackToStart(p, out pos, out rot);
			}
			if (!Search(order, out pos) && !GivenUp(out pos))
			{
				return false;
			}
			rot = CrewSpot.Facing(Mid(order) - pos);
			return true;
		}

		private static bool Search(JumpOrder order, out Vector3 pos)
		{
			//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_0014: 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)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_008e: 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)
			Vector3 mid = Mid(order);
			bool flag = Ready(order.DestAnchor);
			bool flag2 = Ready(order.DestPartner);
			if ((flag || flag2) && readySince < 0f)
			{
				readySince = Time.time;
			}
			if (flag && Around(order.DestAnchor, mid, out pos))
			{
				return true;
			}
			if (flag2 && Around(order.DestPartner, mid, out pos))
			{
				return true;
			}
			if (flag && OnTop(order.DestAnchor, out pos))
			{
				return true;
			}
			if (flag2 && OnTop(order.DestPartner, out pos))
			{
				return true;
			}
			pos = Vector3.zero;
			return false;
		}

		private static bool Around(Vector3 pillar, Vector3 mid, out Vector3 pos)
		{
			//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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Outward(pillar, mid);
			float[] radii = Radii;
			foreach (float num in radii)
			{
				for (int j = 0; j < 8; j++)
				{
					Vector3 val2 = Quaternion.Euler(0f, Turn(j), 0f) * val;
					if (DryAt(pillar + val2 * num, out pos))
					{
						return true;
					}
				}
			}
			pos = Vector3.zero;
			return false;
		}

		private static float Turn(int i)
		{
			int num = (i + 1) / 2;
			float num2 = ((i % 2 == 1) ? 1f : (-1f));
			return (float)num * 45f * num2;
		}

		private static bool DryAt(Vector3 point, out Vector3 pos)
		{
			//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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			pos = point;
			ZoneSystem instance = ZoneSystem.instance;
			float num = default(float);
			if (!instance.IsZoneLoaded(point) || !instance.GetSolidHeight(point, ref num, 1000))
			{
				return false;
			}
			pos.y = num + 0.05f;
			Remember(pos);
			if (num < SeaGateFields.WaterLevel + 0.3f)
			{
				return false;
			}
			float num2 = default(float);
			if (instance.GetGroundHeight(point, ref num2))
			{
				return num - num2 <= 3f;
			}
			return true;
		}

		private static bool OnTop(Vector3 pillar, out Vector3 pos)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			pos = pillar;
			float num = default(float);
			if (!ZoneSystem.instance.GetSolidHeight(pillar, ref num, 1000) || num < SeaGateFields.WaterLevel + 0.3f)
			{
				return false;
			}
			pos.y = num + 0.05f;
			return true;
		}

		private static void Remember(Vector3 pos)
		{
			//IL_001a: 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_0007: Unknown result type (might be due to invalid IL or missing references)
			if (!haveBest || !(pos.y <= best.y))
			{
				best = pos;
				haveBest = true;
			}
		}

		private static bool GivenUp(out Vector3 pos)
		{
			//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_003d: Unknown result type (might be due to invalid IL or missing references)
			pos = best;
			if (!haveBest || readySince < 0f || Time.time - readySince < 10f)
			{
				return false;
			}
			Plugin.Log.LogWarning((object)$"Sea gate: no dry ground beside the destination gate; setting the player on the highest spot found ({pos}).");
			return true;
		}

		private static bool BackToStart(Player p, out Vector3 pos, out Quaternion rot)
		{
			//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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			pos = p.m_teleportFromPos;
			rot = p.m_teleportFromRot;
			if (!ZNetScene.instance.IsAreaReady(pos))
			{
				return false;
			}
			Plugin.Log.LogError((object)"Sea gate: the jump order named no destination pillars; returning the player to where they jumped from.");
			return true;
		}

		private static bool Ready(Vector3 pillar)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (Known(pillar))
			{
				return ZNetScene.instance.IsAreaReady(pillar);
			}
			return false;
		}

		private static bool Known(Vector3 pillar)
		{
			//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)
			return pillar != Vector3.zero;
		}

		private static Vector3 Mid(JumpOrder order)
		{
			//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (Known(order.DestAnchor) && Known(order.DestPartner))
			{
				return (order.DestAnchor + order.DestPartner) * 0.5f;
			}
			if (!Known(order.DestAnchor))
			{
				return order.DestPartner;
			}
			return order.DestAnchor;
		}

		private static Vector3 Outward(Vector3 pillar, Vector3 mid)
		{
			//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_002a: 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)
			Vector3 val = pillar - mid;
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude > 0.0001f))
			{
				return Vector3.forward;
			}
			return ((Vector3)(ref val)).normalized;
		}
	}
	internal static class CrewHelm
	{
		private const float RetrySeconds = 0.5f;

		private const float GiveUpSeconds = 8f;

		private static ZDOID pending = ZDOID.None;

		private static float until;

		private static float nextTry;

		internal static bool Release(Player player, Ship ship)
		{
			bool result = (Object)(object)ship != (Object)null && (Object)(object)player.GetControlledShip() == (Object)(object)ship;
			if (player.GetDoodadController() != null)
			{
				player.StopDoodadControl();
			}
			if (player.m_attached)
			{
				((Character)player).AttachStop();
			}
			return result;
		}

		internal static void Request(ZDOID ship)
		{
			//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)
			pending = ship;
			until = Time.time + 8f;
			nextTry = 0f;
		}

		internal static void Clear()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			pending = ZDOID.None;
		}

		internal static void Tick(Player player)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!((ZDOID)(ref pending)).IsNone() && !(Time.time < nextTry))
			{
				nextTry = Time.time + 0.5f;
				Ship val = CrewShip.Find(pending);
				if (Time.time > until || Done(player, val))
				{
					Clear();
				}
				else if (!((Object)(object)val == (Object)null) && !((Object)(object)val.m_nview == (Object)null) && val.m_nview.IsValid() && val.IsPlayerInBoat(player))
				{
					val.m_nview.InvokeRPC("RequestControl", new object[1] { player.GetPlayerID() });
				}
			}
		}

		private static bool Done(Player player, Ship ship)
		{
			if (((Character)player).IsDead() || ((Character)player).IsTeleporting() || ((Character)player).IsEncumbered())
			{
				return true;
			}
			if ((Object)(object)ship == (Object)null)
			{
				return false;
			}
			if ((Object)(object)player.GetControlledShip() == (Object)(object)ship || player.m_attached || player.GetDoodadController() != null)
			{
				return true;
			}
			ShipControlls shipControlls = ship.m_shipControlls;
			if (!((Object)(object)shipControlls == (Object)null))
			{
				if (shipControlls.HaveValidUser())
				{
					return shipControlls.GetUser() != player.GetPlayerID();
				}
				return false;
			}
			return true;
		}
	}
	public static class CrewHold
	{
		private const float FadeSeconds = 2f;

		private const float LandTolerance = 1f;

		private const float AngleTolerance = 5f;

		private const float DeckLift = 0.05f;

		private const float MinWaitSeconds = 5f;

		private const float DeckCutoffSeconds = 2f;

		private const float SteadySeconds = 1f;

		private static Player player;

		private static JumpOrder order;

		private static CrewSpot spot;

		private static bool hadHelm;

		private static float timer;

		private static long startedAt;

		private static bool failed;

		private static bool fadePinned;

		private static float landReadySince = -1f;

		private static float fallbackReadySince = -1f;

		private static Vector3 fadePos;

		private static Quaternion fadeRot;

		public static bool Holding { get; private set; }

		public static int JumpId
		{
			get
			{
				if (!Holding || order == null)
				{
					return 0;
				}
				return order.JumpId;
			}
		}

		private static float WaitSeconds => Mathf.Max(order.WaitSeconds, 5f);

		private static bool WaitOver => SeaGateFields.Now - startedAt > (long)(WaitSeconds * 10000000f);

		internal static void Begin(Player p, JumpOrder o, CrewSpot s, bool helm)
		{
			player = p;
			order = o;
			spot = s;
			hadHelm = helm;
			timer = 0f;
			startedAt = SeaGateFields.Now;
			failed = false;
			fadePinned = false;
			landReadySince = -1f;
			fallbackReadySince = -1f;
			Holding = true;
			CrewHelm.Clear();
			CrewFallback.Reset();
		}

		internal static void Clear()
		{
			Holding = false;
			player = null;
			order = null;
		}

		internal static bool TryLogoutPoint(out Vector3 point)
		{
			//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)
			point = Vector3.zero;
			if (!Holding || order == null || (Object)(object)player == (Object)null)
			{
				return false;
			}
			CrewFallback.HoldPoint(order, player, out point, out var _);
			return true;
		}

		internal static void Forget(Player p)
		{
			if (!((Object)(object)p == (Object)null) && (!((Object)(object)p != (Object)(object)player) || !((Object)(object)p != (Object)(object)Player.m_localPlayer)))
			{
				Clear();
				CrewHelm.Clear();
				CrewReport.Clear();
				JumpProtection.Clear();
			}
		}

		internal static bool Step(Player p, float dt)
		{
			try
			{
				return Advance(p, dt);
			}
			catch (Exception arg)
			{
				if (!failed)
				{
					Plugin.Log.LogError((object)$"Sea gate crew hold failed, the game finishes the teleport: {arg}");
				}
				failed = true;
				Clear();
				return false;
			}
		}

		internal static void Between(Player p)
		{
			CrewReport.Tick();
			if (WayfareConfig.Enabled.Value && WayfareConfig.SeaGatesEnabled.Value)
			{
				CrewHelm.Tick(p);
			}
		}

		private static bool Advance(Player p, float dt)
		{
			if ((Object)(object)p != (Object)(object)player || order == null || !p.m_teleporting)
			{
				Clear();
				return false;
			}
			timer += dt;
			p.m_teleportTimer = timer;
			p.m_teleportCooldown = 0f;
			if (timer > 2f && TryLand(p))
			{
				return true;
			}
			if (WaitOver && TryFallback(p))
			{
				return true;
			}
			Hold(p);
			return true;
		}

		private static bool TryLand(Player p)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missin