Decompiled source of PortalNetwork v0.7.0

PortalNetwork.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using PortalNetwork.Core;
using PortalNetwork.Home;
using PortalNetwork.Map;
using PortalNetwork.Network;
using PortalNetwork.Portals;
using PortalNetwork.UI;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("PortalNetwork")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Teleport to any portal through a map interface without tag linking. Search, group and rename portals, travel home or back with a key, and keep portals public or private.")]
[assembly: AssemblyFileVersion("0.7.0.0")]
[assembly: AssemblyInformationalVersion("0.7.0+1b6937bed9d7b0861c9ac0213fbcc981fb6de923")]
[assembly: AssemblyProduct("PortalNetwork")]
[assembly: AssemblyTitle("PortalNetwork")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.7.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PortalNetwork
{
	[BepInPlugin("javidahmed64592.portalnetwork", "PortalNetwork", "0.7.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class PortalNetworkPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "javidahmed64592.portalnetwork";

		public const string PluginName = "PortalNetwork";

		public const string PluginVersion = "0.7.0";

		internal static ManualLogSource _log;

		internal static ConfigEntry<KeyboardShortcut> _toggleKey;

		internal static ConfigEntry<KeyboardShortcut> _pingKey;

		internal static ConfigEntry<KeyboardShortcut> _travelHomeKey;

		internal static ConfigEntry<KeyboardShortcut> _setHomeKey;

		internal static ConfigEntry<KeyboardShortcut> _goBackKey;

		internal static ConfigEntry<float> _otherPinOpacity;

		internal static ConfigEntry<bool> _groupByBiome;

		internal static ConfigEntry<bool> _groupByDistance;

		internal static ConfigEntry<float> _groupDistance;

		internal static ConfigEntry<float> _playerIconTeleportSeconds;

		internal static ConfigEntry<Color> _portalIconColour;

		internal static ConfigEntry<Color> _homeIconColour;

		internal static ConfigEntry<Color> _favouriteRingColour;

		internal static ConfigEntry<float> _favouriteRingSize;

		internal static ConfigEntry<float> _favouriteRingThickness;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Expected O, but got Unknown
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Expected O, but got Unknown
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Expected O, but got Unknown
			_log = ((BaseUnityPlugin)this).Logger;
			_toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Map", "TogglePortalIcons", new KeyboardShortcut((KeyCode)112, Array.Empty<KeyCode>()), "Press while the map is open to show or hide portal icons on it.");
			_pingKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Map", "PingLocation", new KeyboardShortcut((KeyCode)112, Array.Empty<KeyCode>()), "Press while no map or menu is open to ping the spot you are looking at on everyone's map (where you stand if you look at the sky).");
			_travelHomeKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Home", "TravelHomeKey", new KeyboardShortcut((KeyCode)104, Array.Empty<KeyCode>()), "Press while looking at a portal, or with the portal map open, to travel to the home portal.");
			_setHomeKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Home", "SetHomeKey", new KeyboardShortcut((KeyCode)104, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Press while looking at a portal to make it the world's home portal (admins and the host only).");
			_goBackKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Travel", "GoBackKey", new KeyboardShortcut((KeyCode)98, Array.Empty<KeyCode>()), "Press while looking at a portal, or with the portal map open, to go back to the portal of your last trip, like the portal list's \"Go back to\" button.");
			_groupByBiome = ((BaseUnityPlugin)this).Config.Bind<bool>("PortalList", "GroupByBiome", false, "Split the portal list into a section per biome. Also set by the Biome button above the list.");
			_groupByDistance = ((BaseUnityPlugin)this).Config.Bind<bool>("PortalList", "GroupByDistance", false, "Split the portal list into sections of portals near each other, such as the portals around one island. Also set by the Distance button above the list.");
			_groupDistance = ((BaseUnityPlugin)this).Config.Bind<float>("PortalList", "GroupDistance", 600f, new ConfigDescription("When grouping by distance, portals this many metres or closer to each other share a section, and so do portals linked through others. Lower it if portals on different islands end up together, raise it if one island's portals are split.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(50f, 5000f), Array.Empty<object>()));
			_otherPinOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("Map", "PickerOtherIconOpacity", 0.4f, new ConfigDescription("Opacity of non-portal map icons while choosing a destination portal (1 = unchanged, 0 = hidden).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			_playerIconTeleportSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Map", "PlayerIconTeleportSeconds", 2f, new ConfigDescription("Seconds another player's map icon takes to move to where they teleported, however far it is (0 = instant).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), Array.Empty<object>()));
			_portalIconColour = ((BaseUnityPlugin)this).Config.Bind<Color>("Icons", "PortalIconColour", Color.red, "Colour of portal icons on the map and minimap, as RRGGBBAA hex.");
			_homeIconColour = ((BaseUnityPlugin)this).Config.Bind<Color>("Icons", "HomePortalColour", new Color(0.3f, 0.85f, 0.3f, 1f), "Colour of the home portal's icon on the map, its house in the portal list and its hover text, as RRGGBBAA hex.");
			_favouriteRingColour = ((BaseUnityPlugin)this).Config.Bind<Color>("Icons", "FavouriteColour", new Color(1f, 0.8f, 0.2f, 1f), "Colour of the ring around favourite portals' icons and of the favourite star in the portal list, as RRGGBBAA hex.");
			_favouriteRingSize = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "FavouriteRingSize", 0.1f, new ConfigDescription("How far the ring around favourite portals' icons sits outside the icon, as a fraction of the icon's size.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.5f), Array.Empty<object>()));
			_favouriteRingThickness = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "FavouriteRingThickness", 0.04f, new ConfigDescription("Thickness of the ring around favourite portals' icons, as a fraction of the ring's size (0.5 = a filled circle).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 0.5f), Array.Empty<object>()));
			PortalNetworkLocalization.Register();
			PortalNetworkRpc.Register();
			_harmony = new Harmony("javidahmed64592.portalnetwork");
			_harmony.PatchAll();
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace PortalNetwork.UI
{
	internal static class PortalKeyHint
	{
		private sealed class Hint(string name, Func<KeyboardShortcut> key, Func<string> label, Func<bool> show)
		{
			public readonly string Name = name;

			public readonly Func<KeyboardShortcut> Key = key;

			public readonly Func<string> Label = label;

			public readonly Func<bool> Show = show;

			public GameObject Item;

			public string BuiltFor;
		}

		private const float KeyBoxMinWidth = 30f;

		private static readonly Regex WordBreak = new Regex("(?<=[a-z0-9])(?=[A-Z])");

		private static readonly Vector4 KeyBoxPadding = new Vector4(8f, 8f, 4f, 4f);

		private static readonly Hint[] Hints = new Hint[4]
		{
			new Hint("PortalNetwork_TogglePortalIcons", () => PortalNetworkPlugin._toggleKey.Value, () => "$portalnetwork_toggle_icons_hint", () => !PortalMapPicker.IsActive),
			new Hint("PortalNetwork_TravelHome", () => PortalNetworkPlugin._travelHomeKey.Value, () => "$portalnetwork_travel_home_hint", () => PortalMapPicker.CanTravelHome),
			new Hint("PortalNetwork_GoBack", () => PortalNetworkPlugin._goBackKey.Value, () => "$portalnetwork_go_back_hint", () => PortalMapPicker.CanGoBack),
			new Hint("PortalNetwork_SetHome", () => PortalNetworkPlugin._setHomeKey.Value, () => (!PortalMapPicker.AtHome) ? "$portalnetwork_set_home_hint" : "$portalnetwork_remove_home_hint", () => PortalMapPicker.CanSetHome)
		};

		private static bool _failed;

		private static Sprite _keySprite;

		internal static void Tick()
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			if (!Minimap.IsOpen())
			{
				if (Hints[0].Item != null && (Object)(object)Hints[0].Item == (Object)null)
				{
					Reset();
				}
				return;
			}
			Transform val = (((Object)(object)Minimap.instance.m_largeRoot != (Object)null) ? Minimap.instance.m_largeRoot.transform.Find("KeyHints/keyboard_hints") : null);
			if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy || ((Object)(object)Hints[0].Item == (Object)null && (_failed || !Create(val))))
			{
				return;
			}
			bool flag = false;
			Hint[] hints = Hints;
			foreach (Hint hint in hints)
			{
				bool flag2 = hint.show();
				if (hint.Item.activeSelf != flag2)
				{
					hint.Item.SetActive(flag2);
					flag = true;
				}
				if (flag2 && hint.BuiltFor != BuildKey(hint))
				{
					BuildContents(hint);
					flag = true;
				}
			}
			if (flag)
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)val);
			}
		}

		private static bool Create(Transform keyboardHints)
		{
			Transform val = keyboardHints.Find("RemovePin");
			if ((Object)(object)val == (Object)null || (Object)(object)val.Find("Label") == (Object)null)
			{
				_failed = true;
				PortalNetworkPlugin._log.LogWarning((object)"Vanilla map key hints layout not as expected, not adding the portal key hints.");
				return false;
			}
			Hint[] hints = Hints;
			foreach (Hint hint in hints)
			{
				hint.Item = Object.Instantiate<GameObject>(((Component)val).gameObject, keyboardHints, false);
				((Object)hint.Item).name = hint.name;
				hint.Item.SetActive(false);
				hint.BuiltFor = null;
			}
			return true;
		}

		private static string BuildKey(Hint hint)
		{
			//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)
			return ((object)hint.key()/*cast due to .constrained prefix*/).ToString() + "|" + hint.label();
		}

		private static void BuildContents(Hint hint)
		{
			//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_00b2: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut val = hint.key();
			hint.BuiltFor = BuildKey(hint);
			Transform transform = hint.Item.transform;
			Transform val2 = transform.Find("Label");
			for (int num = transform.childCount - 1; num >= 0; num--)
			{
				Transform child = transform.GetChild(num);
				if ((Object)(object)child != (Object)(object)val2)
				{
					Object.DestroyImmediate((Object)(object)((Component)child).gameObject);
				}
			}
			((TMP_Text)((Component)val2).GetComponent<TextMeshProUGUI>()).text = PortalNetworkLocalization.Localize(hint.label());
			List<string> list = ((KeyboardShortcut)(ref val)).Modifiers.Select(KeyName).ToList();
			list.Add(KeyName(((KeyboardShortcut)(ref val)).MainKey));
			for (int i = 0; i < list.Count; i++)
			{
				if (i > 0)
				{
					AddPlus(val2, transform);
				}
				AddKey(val2, transform, list[i]);
			}
		}

		private static void AddPlus(Transform labelTemplate, Transform parent)
		{
			GameObject obj = Object.Instantiate<GameObject>(((Component)labelTemplate).gameObject, parent, false);
			((Object)obj).name = "Plus";
			((TMP_Text)obj.GetComponent<TextMeshProUGUI>()).text = "+";
		}

		private static void AddKey(Transform labelTemplate, Transform parent, string key)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			GameObject val = new GameObject("key_bkg", new Type[6]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image),
				typeof(HorizontalLayoutGroup),
				typeof(ContentSizeFitter),
				typeof(LayoutElement)
			});
			val.transform.SetParent(parent, false);
			Sprite val2 = FindKeySprite();
			Image component = val.GetComponent<Image>();
			component.sprite = val2;
			component.type = (Type)1;
			((Behaviour)component).enabled = (Object)(object)val2 != (Object)null;
			HorizontalLayoutGroup component2 = val.GetComponent<HorizontalLayoutGroup>();
			((LayoutGroup)component2).padding = new RectOffset((int)KeyBoxPadding.x, (int)KeyBoxPadding.y, (int)KeyBoxPadding.z, (int)KeyBoxPadding.w);
			((LayoutGroup)component2).childAlignment = (TextAnchor)4;
			((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component2).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = false;
			ContentSizeFitter component3 = val.GetComponent<ContentSizeFitter>();
			component3.horizontalFit = (FitMode)2;
			component3.verticalFit = (FitMode)2;
			val.GetComponent<LayoutElement>().minWidth = 30f;
			GameObject obj = Object.Instantiate<GameObject>(((Component)labelTemplate).gameObject, val.transform, false);
			((Object)obj).name = "Key";
			ContentSizeFitter component4 = obj.GetComponent<ContentSizeFitter>();
			if ((Object)(object)component4 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component4);
			}
			TextMeshProUGUI component5 = obj.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component5).text = key;
			((TMP_Text)component5).fontStyle = (FontStyles)1;
			((TMP_Text)component5).alignment = (TextAlignmentOptions)514;
		}

		private static Sprite FindKeySprite()
		{
			if ((Object)(object)_keySprite == (Object)null)
			{
				_keySprite = ((IEnumerable<Sprite>)Resources.FindObjectsOfTypeAll<Sprite>()).FirstOrDefault((Func<Sprite, bool>)((Sprite s) => ((Object)s).name == "key_base"));
			}
			return _keySprite;
		}

		private unsafe static string KeyName(KeyCode key)
		{
			string text = ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
			if (text.StartsWith("Alpha", StringComparison.Ordinal))
			{
				return text.Substring(5);
			}
			if (text.StartsWith("Keypad", StringComparison.Ordinal))
			{
				return "Num " + text.Substring(6);
			}
			text = text.Replace("Control", "Ctrl");
			return WordBreak.Replace(text, " ");
		}

		private static void Reset()
		{
			Hint[] hints = Hints;
			foreach (Hint obj in hints)
			{
				obj.Item = null;
				obj.BuiltFor = null;
			}
			_failed = false;
		}
	}
	internal static class PortalPickerPanel
	{
		private readonly struct RowData
		{
			public readonly PortalInfo Portal;

			public readonly bool Current;

			public readonly bool Favourite;

			public readonly string Label;

			public RowData(PortalInfo portal, bool current, bool favourite, string label)
			{
				Portal = portal;
				Current = current;
				Favourite = favourite;
				Label = label;
			}
		}

		private sealed class RowHover : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
		{
			public ZDOID Portal;

			public void OnPointerEnter(PointerEventData eventData)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				PortalMapPicker.Highlight(Portal);
			}

			public void OnPointerExit(PointerEventData eventData)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				PortalMapPicker.Unhighlight(Portal);
			}

			private void OnDisable()
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				PortalMapPicker.Unhighlight(Portal);
			}
		}

		private sealed class RenameReceiver(PortalInfo portal) : TextReceiver
		{
			public string GetText()
			{
				return portal.Name ?? "";
			}

			public void SetText(string text)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				PortalNetworkRpc.SendRenameRequest(portal.Id, text);
			}
		}

		private const float PanelWidth = 440f;

		private const float PanelHeight = 600f;

		private const float PanelMarginLeft = 40f;

		private const float RowHeight = 34f;

		private const float StarSize = 26f;

		private const float DistanceWidth = 64f;

		private const float IconButtonSize = 22f;

		private const int Padding = 16;

		private const float FallbackScrollSensitivity = 3000f;

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

		private static readonly Color ListBackground = new Color(0f, 0f, 0f, 0.35f);

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

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

		private static GameObject _panel;

		private static Button _goBackButton;

		private static Text _goBackText;

		private static RectTransform _content;

		private static ScrollRect _scroll;

		private static Text _emptyText;

		private static Sprite _starSprite;

		private static Sprite _homeSprite;

		private static Sprite _pencilSprite;

		private static Sprite _lockSprite;

		private static InputField _search;

		private static Text _biomeButtonText;

		private static Text _distanceButtonText;

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

		private static readonly List<GameObject> Rows = new List<GameObject>();

		private static readonly Dictionary<ZDOID, Image> RowBackgrounds = new Dictionary<ZDOID, Image>();

		private static ZDOID _shownHighlight = ZDOID.None;

		private static Vector3 _origin;

		private static ZDOID _current;

		private const int SpriteSize = 64;

		private static Color StarOn => PortalPinStyle.FavouriteColor;

		private static Color RowHighlight => new Color(StarOn.r, StarOn.g, StarOn.b, 0.25f);

		internal static bool SearchFocused
		{
			get
			{
				if ((Object)(object)_search != (Object)null && _search.isFocused && (Object)(object)_panel != (Object)null)
				{
					return _panel.activeInHierarchy;
				}
				return false;
			}
		}

		internal static bool IsPointerOver()
		{
			//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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if ((Object)(object)_panel != (Object)null && _panel.activeInHierarchy)
			{
				return RectTransformUtility.RectangleContainsScreenPoint((RectTransform)_panel.transform, Vector2.op_Implicit(ZInput.pointerPosition), (Camera)null);
			}
			return false;
		}

		internal static void Show(IEnumerable<PortalInfo> portals, ZDOID current, Vector3 origin)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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)
			Minimap instance = Minimap.instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.m_largeRoot == (Object)null) && (!((Object)(object)_panel == (Object)null) || Create(instance.m_largeRoot.transform)))
			{
				Portals.Clear();
				Portals.AddRange(portals);
				_origin = origin;
				_current = current;
				_search.SetTextWithoutNotify("");
				_scroll.scrollSensitivity = VanillaScrollSensitivity();
				_panel.transform.SetAsLastSibling();
				_panel.SetActive(true);
				Rebuild();
				_scroll.verticalNormalizedPosition = 1f;
			}
		}

		internal static void SetHome(ZDOID home)
		{
			//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)
			if (!((Object)(object)_panel == (Object)null) && _panel.activeSelf)
			{
				for (int i = 0; i < Portals.Count; i++)
				{
					PortalInfo value = Portals[i];
					value.IsHome = value.Id == home;
					Portals[i] = value;
				}
				Rebuild();
			}
		}

		internal static void UpdatePortal(PortalInfo changed)
		{
			//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)
			if ((Object)(object)_panel == (Object)null || !_panel.activeSelf)
			{
				return;
			}
			for (int i = 0; i < Portals.Count; i++)
			{
				if (Portals[i].Id == changed.Id)
				{
					changed.IsHome = Portals[i].IsHome;
					Portals[i] = changed;
				}
			}
			Rebuild();
		}

		internal static void Hide()
		{
			Portals.Clear();
			ClearRows();
			if ((Object)(object)_panel != (Object)null)
			{
				_panel.SetActive(false);
			}
		}

		private static float VanillaScrollSensitivity()
		{
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_recipeEnsureVisible == (Object)null)
			{
				return 3000f;
			}
			ScrollRect component = ((Component)instance.m_recipeEnsureVisible).GetComponent<ScrollRect>();
			if (!((Object)(object)component != (Object)null))
			{
				return 3000f;
			}
			return component.scrollSensitivity;
		}

		private static bool Create(Transform parent)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_00a1: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			GUIManager instance = GUIManager.Instance;
			if (instance == null || (Object)(object)instance.AveriaSerifBold == (Object)null)
			{
				PortalNetworkPlugin._log.LogWarning((object)"Jotunn GUI resources not ready, not showing the portal list.");
				return false;
			}
			_panel = instance.CreateWoodpanel(parent, Vector2.zero, Vector2.zero, Vector2.zero, 0f, 0f, false);
			((Object)_panel).name = "PortalNetwork_PortalList";
			RectTransform val = (RectTransform)_panel.transform;
			val.anchorMin = new Vector2(0f, 0.5f);
			val.anchorMax = new Vector2(0f, 0.5f);
			val.pivot = new Vector2(0f, 0.5f);
			val.sizeDelta = new Vector2(440f, 600f);
			val.anchoredPosition = new Vector2(40f, 0f);
			VerticalLayoutGroup obj = _panel.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj).padding = new RectOffset(16, 16, 16, 16);
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 8f;
			SetControl((HorizontalOrVerticalLayoutGroup)(object)obj);
			AddLayout(((Component)CreateText(_panel.transform, "$portalnetwork_panel_title", instance.NorseBold, 30, instance.ValheimOrange, (TextAnchor)4)).gameObject, -1f, 36f);
			GameObject obj2 = instance.CreateButton("", _panel.transform, Vector2.zero, Vector2.zero, Vector2.zero, 0f, 0f);
			AddLayout(obj2, -1f, 38f);
			_goBackButton = obj2.GetComponent<Button>();
			_goBackText = obj2.GetComponentInChildren<Text>();
			_goBackText.horizontalOverflow = (HorizontalWrapMode)0;
			CreateSearch(_panel.transform);
			CreateGroupButtons(_panel.transform);
			CreateList(_panel.transform);
			return true;
		}

		private static void CreateGroupButtons(Transform parent)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0061: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Grouping", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 8f;
			SetControl((HorizontalOrVerticalLayoutGroup)(object)obj);
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
			AddLayout(val, -1f, 32f);
			_biomeButtonText = CreateGroupButton(val.transform, "$portalnetwork_group_biome", PortalNetworkPlugin._groupByBiome);
			_distanceButtonText = CreateGroupButton(val.transform, "$portalnetwork_group_distance", PortalNetworkPlugin._groupByDistance);
		}

		private static Text CreateGroupButton(Transform row, string label, ConfigEntry<bool> setting)
		{
			//IL_0019: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			GameObject obj = GUIManager.Instance.CreateButton(Localize(label), row, Vector2.zero, Vector2.zero, Vector2.zero, 0f, 0f);
			AddLayout(obj, -1f, 30f, 1f);
			((UnityEvent)obj.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				setting.Value = !setting.Value;
				Rebuild();
				_scroll.verticalNormalizedPosition = 1f;
			});
			return obj.GetComponentInChildren<Text>();
		}

		private static void UpdateGroupButtons()
		{
			//IL_0022: 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_004e: 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)
			((Graphic)_biomeButtonText).color = (PortalNetworkPlugin._groupByBiome.Value ? GUIManager.Instance.ValheimOrange : GUIManager.Instance.ValheimBeige);
			((Graphic)_distanceButtonText).color = (PortalNetworkPlugin._groupByDistance.Value ? GUIManager.Instance.ValheimOrange : GUIManager.Instance.ValheimBeige);
		}

		private static void CreateSearch(Transform parent)
		{
			//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)
			GameObject obj = GUIManager.Instance.CreateInputField(parent, Vector2.zero, Vector2.zero, Vector2.zero, (ContentType)0, Localize("$portalnetwork_search_placeholder"), 16, 0f, 0f);
			((Object)obj).name = "Search";
			AddLayout(obj, -1f, 32f);
			_search = obj.GetComponent<InputField>();
			_search.characterLimit = 40;
			((UnityEvent<string>)(object)_search.onValueChanged).AddListener((UnityAction<string>)delegate
			{
				Rebuild();
				_scroll.verticalNormalizedPosition = 1f;
			});
		}

		private static void CreateList(Transform parent)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_004b: 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_009a: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("List", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(ScrollRect)
			});
			val.transform.SetParent(parent, false);
			((Graphic)val.GetComponent<Image>()).color = ListBackground;
			AddLayout(val, -1f, -1f, -1f, 1f);
			GameObject val2 = new GameObject("Viewport", new Type[2]
			{
				typeof(RectTransform),
				typeof(RectMask2D)
			});
			val2.transform.SetParent(val.transform, false);
			RectTransform val3 = (RectTransform)val2.transform;
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = Vector2.one;
			val3.offsetMin = new Vector2(4f, 4f);
			val3.offsetMax = new Vector2(-16f, -4f);
			GameObject val4 = new GameObject("Content", new Type[1] { typeof(RectTransform) });
			val4.transform.SetParent(val2.transform, false);
			_content = (RectTransform)val4.transform;
			_content.anchorMin = new Vector2(0f, 1f);
			_content.anchorMax = new Vector2(1f, 1f);
			_content.pivot = new Vector2(0.5f, 1f);
			_content.sizeDelta = Vector2.zero;
			VerticalLayoutGroup obj = val4.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 4f;
			((LayoutGroup)obj).padding = new RectOffset(4, 4, 4, 4);
			SetControl((HorizontalOrVerticalLayoutGroup)(object)obj);
			val4.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			GameObject obj2 = DefaultControls.CreateScrollbar(GUIManager.Instance.ValheimControlResources);
			obj2.transform.SetParent(val.transform, false);
			Scrollbar component = obj2.GetComponent<Scrollbar>();
			component.direction = (Direction)2;
			GUIManager.Instance.ApplyScrollbarStyle(component);
			RectTransform val5 = (RectTransform)obj2.transform;
			val5.anchorMin = new Vector2(1f, 0f);
			val5.anchorMax = new Vector2(1f, 1f);
			val5.pivot = new Vector2(1f, 0.5f);
			val5.sizeDelta = new Vector2(10f, -8f);
			val5.anchoredPosition = new Vector2(-3f, 0f);
			_scroll = val.GetComponent<ScrollRect>();
			_scroll.viewport = val3;
			_scroll.content = _content;
			_scroll.horizontal = false;
			_scroll.vertical = true;
			_scroll.movementType = (MovementType)2;
			_scroll.verticalScrollbar = component;
			_scroll.verticalScrollbarVisibility = (ScrollbarVisibility)1;
			_emptyText = CreateText(val4.transform, "", GUIManager.Instance.AveriaSerifBold, 16, GUIManager.Instance.ValheimBeige, (TextAnchor)4);
			_emptyText.horizontalOverflow = (HorizontalWrapMode)0;
			AddLayout(((Component)_emptyText).gameObject, -1f, 60f);
		}

		private static void Rebuild()
		{
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			ClearRows();
			if ((Object)(object)_panel == (Object)null)
			{
				return;
			}
			UpdateGoBack();
			UpdateGroupButtons();
			HashSet<string> favourites = PortalFavourites.GetFavourites();
			string filter = (((Object)(object)_search != (Object)null) ? _search.text.Trim() : "");
			List<RowData> source = (from p in Portals
				select new RowData(p, p.Id == _current, favourites.Contains(PortalFavourites.Key(p.Position)), Label(p)) into r
				where filter.Length == 0 || r.Label.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0
				select r).ToList();
			foreach (RowData item in source.Where((RowData r) => r.Portal.IsHome))
			{
				Rows.Add(CreateRow(item.Portal, item.Current, item.Favourite, item.Label));
			}
			List<RowData> list = source.Where((RowData r) => !r.Portal.IsHome).ToList();
			bool value = PortalNetworkPlugin._groupByBiome.Value;
			bool value2 = PortalNetworkPlugin._groupByDistance.Value;
			if (!value && !value2)
			{
				AddRows(list);
			}
			else
			{
				foreach (PortalGroups.Group<RowData> item2 in PortalGroups.Build(list, (RowData r) => r.Portal.Position, BiomeAt, value, value2, _origin, PortalNetworkPlugin._groupDistance.Value))
				{
					Rows.Add(CreateHeader(GroupTitle(item2, value, value2)));
					AddRows(item2.Items);
				}
			}
			((Component)_emptyText).gameObject.SetActive(Rows.Count == 0);
			_emptyText.text = Localize((filter.Length > 0) ? "$portalnetwork_no_matches" : "$portalnetwork_no_other_portals");
		}

		private static void AddRows(IEnumerable<RowData> rows)
		{
			foreach (RowData item in (from r in rows
				orderby r.Current descending, r.Favourite descending
				select r).ThenBy<RowData, string>((RowData r) => r.Label, StringComparer.CurrentCultureIgnoreCase))
			{
				Rows.Add(CreateRow(item.Portal, item.Current, item.Favourite, item.Label));
			}
		}

		private static string GroupTitle(PortalGroups.Group<RowData> group, bool byBiome, bool byDistance)
		{
			//IL_0001: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			string text = (((int)group.Biome == 0) ? Localize("$portalnetwork_group_other") : Localize("$biome_" + ((object)Unsafe.As<Biome, Biome>(ref group.Biome)/*cast due to .constrained prefix*/).ToString().ToLowerInvariant()));
			if (!byDistance)
			{
				return text;
			}
			string text2 = (group.Items.Any((RowData r) => r.Current) ? Localize("$portalnetwork_group_here") : (FormatDistance(Utils.DistanceXZ(_origin, group.Centre)) + " " + Localize(PortalGroups.DirectionToken(_origin, group.Centre))));
			if (!byBiome)
			{
				return text2;
			}
			return text + " · " + text2;
		}

		private static GameObject CreateHeader(string title)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			GUIManager instance = GUIManager.Instance;
			Text obj = CreateText((Transform)(object)_content, title, instance.AveriaSerifBold, 16, instance.ValheimOrange, (TextAnchor)6);
			obj.text = title;
			AddLayout(((Component)obj).gameObject, -1f, 26f);
			return ((Component)obj).gameObject;
		}

		private static void UpdateGoBack()
		{
			//IL_0021: 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_0091: Expected O, but got Unknown
			((UnityEventBase)_goBackButton.onClick).RemoveAllListeners();
			PortalInfo target = default(PortalInfo);
			string key;
			bool flag = PortalFavourites.TryGetGoBackKey(_origin, out key) && TryFind(key, out target);
			((Selectable)_goBackButton).interactable = flag;
			if (flag)
			{
				_goBackText.text = Localize("$portalnetwork_go_back") + " " + Label(target);
				((UnityEvent)_goBackButton.onClick).AddListener((UnityAction)delegate
				{
					PortalMapPicker.Teleport(target);
				});
			}
			else
			{
				_goBackText.text = Localize("$portalnetwork_no_last_portal");
			}
		}

		private static bool TryFind(string key, out PortalInfo portal)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			foreach (PortalInfo portal2 in Portals)
			{
				if (portal2.Id != _current && PortalFavourites.Key(portal2.Position) == key)
				{
					portal = portal2;
					return true;
				}
			}
			portal = default(PortalInfo);
			return false;
		}

		private static GameObject CreateRow(PortalInfo portal, bool current, bool favourite, string label)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_005e: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Expected O, but got Unknown
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Expected O, but got Unknown
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Expected O, but got Unknown
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			GUIManager instance = GUIManager.Instance;
			GameObject val = new GameObject("Row", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent((Transform)(object)_content, false);
			Image component = val.GetComponent<Image>();
			((Graphic)component).color = Color.clear;
			RowBackgrounds[portal.Id] = component;
			val.AddComponent<RowHover>().Portal = portal.Id;
			HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 6f;
			((LayoutGroup)obj).childAlignment = (TextAnchor)3;
			SetControl((HorizontalOrVerticalLayoutGroup)(object)obj);
			AddLayout(val, -1f, 34f);
			if (portal.IsHome)
			{
				GameObject val2 = new GameObject("Home", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val2.transform.SetParent(val.transform, false);
				AddLayout(val2, 26f, 26f);
				Image component2 = val2.GetComponent<Image>();
				component2.sprite = HomeSprite();
				component2.preserveAspect = true;
				((Graphic)component2).color = PortalPinStyle.HomeColor;
				((Graphic)component2).raycastTarget = false;
			}
			else
			{
				GameObject val3 = new GameObject("Star", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Button)
				});
				val3.transform.SetParent(val.transform, false);
				AddLayout(val3, 26f, 26f);
				Image component3 = val3.GetComponent<Image>();
				component3.sprite = StarSprite();
				component3.preserveAspect = true;
				((Graphic)component3).color = (favourite ? StarOn : StarOff);
				Button component4 = val3.GetComponent<Button>();
				((Selectable)component4).transition = (Transition)0;
				((UnityEvent)component4.onClick).AddListener((UnityAction)delegate
				{
					PortalFavourites.SetFavourite(portal, !favourite);
					Rebuild();
				});
			}
			GameObject obj2 = instance.CreateButton(label, val.transform, Vector2.zero, Vector2.zero, Vector2.zero, 0f, 0f);
			AddLayout(obj2, -1f, 30f, 1f);
			Text componentInChildren = obj2.GetComponentInChildren<Text>();
			componentInChildren.alignment = (TextAnchor)3;
			componentInChildren.horizontalOverflow = (HorizontalWrapMode)0;
			componentInChildren.resizeTextForBestFit = true;
			componentInChildren.resizeTextMinSize = 11;
			componentInChildren.resizeTextMaxSize = 16;
			RectTransform val4 = (RectTransform)((Component)componentInChildren).transform;
			val4.anchorMin = Vector2.zero;
			val4.anchorMax = Vector2.one;
			val4.offsetMin = new Vector2(10f, 0f);
			val4.offsetMax = new Vector2(-6f, 0f);
			Button component5 = obj2.GetComponent<Button>();
			((Selectable)component5).interactable = !current;
			if (!current)
			{
				((UnityEvent)component5.onClick).AddListener((UnityAction)delegate
				{
					PortalMapPicker.Teleport(portal);
				});
			}
			string text = (current ? Localize("$portalnetwork_here") : FormatDistance(Vector3.Distance(_origin, portal.Position)));
			AddLayout(((Component)CreateText(val.transform, text, instance.AveriaSerifBold, 14, instance.ValheimBeige, (TextAnchor)5)).gameObject, 64f, 34f);
			AddRenameButton(val.transform, portal);
			AddLockButton(val.transform, portal);
			return val;
		}

		private static Requester LocalRequester()
		{
			Player localPlayer = Player.m_localPlayer;
			return new Requester(((Object)(object)localPlayer != (Object)null) ? localPlayer.GetPlayerID() : 0, PlayerIdentity.LocalIsAdmin());
		}

		private static void AddRenameButton(Transform row, PortalInfo portal)
		{
			//IL_0031: 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_0051: Expected O, but got Unknown
			if (!PortalRegistry.CanRename(portal, LocalRequester()))
			{
				AddSpacer(row);
				return;
			}
			((UnityEvent)CreateIconButton(row, "Rename", PencilSprite(), IconIdle).onClick).AddListener((UnityAction)delegate
			{
				TextInput.instance.RequestText((TextReceiver)(object)new RenameReceiver(portal), "$piece_portal_tag", 10);
			});
		}

		private static void AddLockButton(Transform row, PortalInfo portal)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			bool flag = PortalRegistry.CanChange(portal, LocalRequester());
			if (!flag && !portal.NameLocked)
			{
				AddSpacer(row);
				return;
			}
			Button val = CreateIconButton(row, "NameLock", LockSprite(), portal.NameLocked ? StarOn : LockOff);
			((Selectable)val).interactable = flag;
			if (flag)
			{
				((UnityEvent)val.onClick).AddListener((UnityAction)delegate
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					PortalNetworkRpc.SendNameLockRequest(portal.Id, !portal.NameLocked);
				});
			}
		}

		private static Button CreateIconButton(Transform row, string name, Sprite sprite, Color color)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_005a: 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)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			val.transform.SetParent(row, false);
			AddLayout(val, 22f, 22f);
			Image component = val.GetComponent<Image>();
			component.sprite = sprite;
			component.preserveAspect = true;
			((Graphic)component).color = color;
			Button component2 = val.GetComponent<Button>();
			((Selectable)component2).transition = (Transition)0;
			return component2;
		}

		private static void AddSpacer(Transform row)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			GameObject val = new GameObject("Spacer", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(row, false);
			AddLayout(val, 22f, 22f);
		}

		internal static void ShowHighlight(ZDOID portal)
		{
			//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_0013: 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_0058: 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_002b: 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)
			if (!(portal == _shownHighlight))
			{
				if (RowBackgrounds.TryGetValue(_shownHighlight, out var value) && (Object)(object)value != (Object)null)
				{
					((Graphic)value).color = Color.clear;
				}
				if (RowBackgrounds.TryGetValue(portal, out var value2) && (Object)(object)value2 != (Object)null)
				{
					((Graphic)value2).color = RowHighlight;
				}
				_shownHighlight = portal;
			}
		}

		private static void ClearRows()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			RowBackgrounds.Clear();
			_shownHighlight = ZDOID.None;
			foreach (GameObject row in Rows)
			{
				if ((Object)(object)row != (Object)null)
				{
					row.SetActive(false);
					Object.Destroy((Object)(object)row);
				}
			}
			Rows.Clear();
		}

		internal static string Label(PortalInfo portal)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			string text = BiomeName(portal.Position);
			if (portal.Visibility == PortalVisibility.Private)
			{
				string text2 = Localize("$portalnetwork_private_suffix");
				text = (string.IsNullOrEmpty(text) ? text2 : (text + ", " + text2));
			}
			string text3 = PortalNames.Display(portal);
			if (!string.IsNullOrEmpty(text))
			{
				return text3 + " (" + text + ")";
			}
			return text3;
		}

		private static Biome BiomeAt(Vector3 position)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (WorldGenerator.instance == null)
			{
				return (Biome)0;
			}
			return WorldGenerator.instance.GetBiome(position);
		}

		private unsafe static string BiomeName(Vector3 position)
		{
			//IL_000d: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			if (WorldGenerator.instance == null)
			{
				return "";
			}
			Biome val = BiomeAt(position);
			if ((int)val != 0)
			{
				return Localize("$biome_" + ((object)(*(Biome*)(&val))/*cast due to .constrained prefix*/).ToString().ToLowerInvariant());
			}
			return "";
		}

		private static string FormatDistance(float metres)
		{
			if (!(metres < 1000f))
			{
				return (metres / 1000f).ToString("0.0", CultureInfo.InvariantCulture) + " km";
			}
			return Mathf.RoundToInt(metres).ToString(CultureInfo.InvariantCulture) + " m";
		}

		private static Text CreateText(Transform parent, string text, Font font, int size, Color color, TextAnchor alignment)
		{
			//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_0044: 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)
			GameObject val = new GameObject("Text", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val.transform.SetParent(parent, false);
			Text component = val.GetComponent<Text>();
			GUIManager.Instance.ApplyTextStyle(component, font, color, size, true);
			component.alignment = alignment;
			component.text = Localize(text);
			((Graphic)component).raycastTarget = false;
			return component;
		}

		private static void SetControl(HorizontalOrVerticalLayoutGroup layout)
		{
			layout.childControlWidth = true;
			layout.childControlHeight = true;
			layout.childForceExpandWidth = layout is VerticalLayoutGroup;
			layout.childForceExpandHeight = false;
		}

		private static void AddLayout(GameObject target, float width = -1f, float height = -1f, float flexibleWidth = -1f, float flexibleHeight = -1f)
		{
			LayoutElement val = default(LayoutElement);
			if (!target.TryGetComponent<LayoutElement>(ref val))
			{
				val = target.AddComponent<LayoutElement>();
			}
			val.minWidth = width;
			val.preferredWidth = width;
			val.minHeight = height;
			val.preferredHeight = height;
			val.flexibleWidth = flexibleWidth;
			val.flexibleHeight = flexibleHeight;
		}

		private static string Localize(string text)
		{
			if (!string.IsNullOrEmpty(text))
			{
				return PortalNetworkLocalization.Localize(text);
			}
			return text;
		}

		private static Sprite StarSprite()
		{
			//IL_005a: 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_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)
			if ((Object)(object)_starSprite != (Object)null)
			{
				return _starSprite;
			}
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(32f, 32f);
			Vector2[] array = (Vector2[])(object)new Vector2[10];
			for (int i = 0; i < array.Length; i++)
			{
				float num = (90f + (float)i * 36f) * ((float)Math.PI / 180f);
				float num2 = ((i % 2 == 0) ? 30.72f : 12.8f);
				array[i] = val + new Vector2(Mathf.Cos(num), Mathf.Sin(num)) * num2;
			}
			_starSprite = PolygonSprite(array);
			return _starSprite;
		}

		private static Sprite HomeSprite()
		{
			//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_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_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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_homeSprite != (Object)null)
			{
				return _homeSprite;
			}
			Vector2[] array = (Vector2[])(object)new Vector2[11]
			{
				new Vector2(0.18f, 0.04f),
				new Vector2(0.42f, 0.04f),
				new Vector2(0.42f, 0.32f),
				new Vector2(0.58f, 0.32f),
				new Vector2(0.58f, 0.04f),
				new Vector2(0.82f, 0.04f),
				new Vector2(0.82f, 0.5f),
				new Vector2(0.96f, 0.5f),
				new Vector2(0.5f, 0.94f),
				new Vector2(0.04f, 0.5f),
				new Vector2(0.18f, 0.5f)
			};
			Vector2[] array2 = (Vector2[])(object)new Vector2[array.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array2[i] = array[i] * 64f;
			}
			_homeSprite = PolygonSprite(array2);
			return _homeSprite;
		}

		private static Sprite PencilSprite()
		{
			//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_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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			if ((Object)(object)_pencilSprite != (Object)null)
			{
				return _pencilSprite;
			}
			_pencilSprite = PolygonSprite(Scale((Vector2[])(object)new Vector2[5]
			{
				new Vector2(0.06f, 0.06f),
				new Vector2(0.32f, 0.14f),
				new Vector2(0.94f, 0.76f),
				new Vector2(0.76f, 0.94f),
				new Vector2(0.14f, 0.32f)
			}));
			return _pencilSprite;
		}

		private static Sprite LockSprite()
		{
			//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_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_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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_lockSprite != (Object)null)
			{
				return _lockSprite;
			}
			_lockSprite = PolygonSprite(Scale((Vector2[])(object)new Vector2[18]
			{
				new Vector2(0.16f, 0.04f),
				new Vector2(0.84f, 0.04f),
				new Vector2(0.84f, 0.52f),
				new Vector2(0.74f, 0.52f),
				new Vector2(0.74f, 0.72f),
				new Vector2(0.66f, 0.88f),
				new Vector2(0.5f, 0.94f),
				new Vector2(0.34f, 0.88f),
				new Vector2(0.26f, 0.72f),
				new Vector2(0.26f, 0.52f),
				new Vector2(0.38f, 0.52f),
				new Vector2(0.38f, 0.7f),
				new Vector2(0.43f, 0.79f),
				new Vector2(0.5f, 0.82f),
				new Vector2(0.57f, 0.79f),
				new Vector2(0.62f, 0.7f),
				new Vector2(0.62f, 0.52f),
				new Vector2(0.16f, 0.52f)
			}));
			return _lockSprite;
		}

		private static Vector2[] Scale(Vector2[] outline)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			Vector2[] array = (Vector2[])(object)new Vector2[outline.Length];
			for (int i = 0; i < outline.Length; i++)
			{
				array[i] = outline[i] * 64f;
			}
			return array;
		}

		private static Sprite PolygonSprite(Vector2[] points)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006c: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			Color32[] array = (Color32[])(object)new Color32[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					int num = 0;
					for (int k = 0; k < 4; k++)
					{
						for (int l = 0; l < 4; l++)
						{
							if (InPolygon(new Vector2((float)j + ((float)l + 0.5f) / 4f, (float)i + ((float)k + 0.5f) / 4f), points))
							{
								num++;
							}
						}
					}
					byte b = (byte)(255 * num / 16);
					array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, b);
				}
			}
			val.SetPixels32(array);
			val.Apply();
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static bool InPolygon(Vector2 point, Vector2[] polygon)
		{
			//IL_001b: 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_0039: 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)
			bool flag = false;
			int num = 0;
			int num2 = polygon.Length - 1;
			while (num < polygon.Length)
			{
				if (polygon[num].y > point.y != polygon[num2].y > point.y && point.x < (polygon[num2].x - polygon[num].x) * (point.y - polygon[num].y) / (polygon[num2].y - polygon[num].y) + polygon[num].x)
				{
					flag = !flag;
				}
				num2 = num++;
			}
			return flag;
		}
	}
}
namespace PortalNetwork.Portals
{
	internal static class PortalFavourites
	{
		private const string FavouritesPrefix = "PortalNetwork_Favourites_";

		private const string LastTripPrefix = "PortalNetwork_LastTrip_";

		private const char ListSeparator = ';';

		private const char TripSeparator = '|';

		private static string _cachedValue;

		private static HashSet<string> _cachedFavourites = new HashSet<string>();

		internal static string Key(Vector3 position)
		{
			//IL_000a: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y), Mathf.RoundToInt(position.z));
		}

		internal static HashSet<string> GetFavourites()
		{
			string value;
			string text = (TryGet("PortalNetwork_Favourites_", out value) ? value : "");
			if (text == _cachedValue)
			{
				return _cachedFavourites;
			}
			HashSet<string> hashSet = new HashSet<string>();
			string[] array = text.Split(new char[1] { ';' });
			foreach (string text2 in array)
			{
				if (text2.Length > 0)
				{
					hashSet.Add(text2);
				}
			}
			_cachedValue = text;
			_cachedFavourites = hashSet;
			return hashSet;
		}

		internal static void SetFavourite(PortalInfo portal, bool favourite)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			HashSet<string> hashSet = new HashSet<string>();
			foreach (string favourite2 in GetFavourites())
			{
				hashSet.Add(favourite2);
			}
			HashSet<string> hashSet2 = hashSet;
			string item = Key(portal.Position);
			if (favourite ? hashSet2.Add(item) : hashSet2.Remove(item))
			{
				Set("PortalNetwork_Favourites_", string.Join(';'.ToString(), hashSet2));
			}
		}

		internal static void RecordTrip(Vector3 from, Vector3 to)
		{
			//IL_0005: 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)
			Set("PortalNetwork_LastTrip_", Key(from) + "|" + Key(to));
		}

		internal static bool TryGetGoBackKey(Vector3 current, out string key)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			key = null;
			if (!TryGet("PortalNetwork_LastTrip_", out var value))
			{
				return false;
			}
			string[] array = value.Split(new char[1] { '|' });
			if (array.Length != 2)
			{
				return false;
			}
			string text = Key(current);
			key = ((text == array[1]) ? array[0] : array[1]);
			return key != text;
		}

		private static bool TryGet(string prefix, out string value)
		{
			value = null;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && TryGetWorldKey(prefix, out var fullKey))
			{
				return localPlayer.m_customData.TryGetValue(fullKey, out value);
			}
			return false;
		}

		private static void Set(string prefix, string value)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && TryGetWorldKey(prefix, out var fullKey))
			{
				localPlayer.m_customData[fullKey] = value;
			}
		}

		private static bool TryGetWorldKey(string prefix, out string fullKey)
		{
			World world = ZNet.World;
			fullKey = ((world != null) ? (prefix + world.m_uid.ToString(CultureInfo.InvariantCulture)) : null);
			return world != null;
		}
	}
	internal static class PortalGroups
	{
		internal sealed class Group<T>
		{
			public Biome Biome;

			public Vector3 Centre;

			public readonly List<T> Items = new List<T>();
		}

		private static readonly Biome[] BiomeOrder;

		internal static List<Group<T>> Build<T>(IEnumerable<T> items, Func<T, Vector3> position, Func<Vector3, Biome> biomeOf, bool byBiome, bool byDistance, Vector3 origin, float linkDistance)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			List<T> list = items.ToList();
			List<Group<T>> result = new List<Group<T>>();
			if (!byBiome)
			{
				AddGroups(result, list, (Biome)0, position, byDistance, origin, linkDistance);
				return result;
			}
			ILookup<Biome, T> lookup = list.ToLookup((T item) => biomeOf(position(item)));
			foreach (Biome item in lookup.Select((IGrouping<Biome, T> g) => g.Key).OrderBy(BiomeRank))
			{
				AddGroups(result, lookup[item].ToList(), item, position, byDistance, origin, linkDistance);
			}
			return result;
		}

		private static int BiomeRank(Biome biome)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			int num = Array.IndexOf(BiomeOrder, biome);
			if (num < 0)
			{
				return BiomeOrder.Length;
			}
			return num;
		}

		private static void AddGroups<T>(List<Group<T>> result, List<T> items, Biome biome, Func<T, Vector3> position, bool byDistance, Vector3 origin, float linkDistance)
		{
			//IL_000e: 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_002d: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			if (items.Count == 0)
			{
				return;
			}
			if (!byDistance)
			{
				Group<T> obj = new Group<T>
				{
					Biome = biome
				};
				obj.Items.AddRange(items);
				obj.Centre = Centre(obj.Items, position);
				result.Add(obj);
				return;
			}
			List<Vector3> list = new List<Vector3>();
			foreach (T item in items)
			{
				list.Add(position(item));
			}
			List<Group<T>> list2 = new List<Group<T>>();
			foreach (List<int> item2 in Clusters(list, linkDistance))
			{
				Group<T> obj2 = new Group<T>
				{
					Biome = biome
				};
				obj2.Items.AddRange(item2.Select((int i) => items[i]));
				obj2.Centre = Centre(obj2.Items, position);
				list2.Add(obj2);
			}
			result.AddRange(list2.OrderBy((Group<T> g) => Utils.DistanceXZ(g.Centre, origin)));
		}

		internal static List<List<int>> Clusters(IReadOnlyList<Vector3> points, float linkDistance)
		{
			//IL_0023: 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_003d: 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)
			int[] array = Enumerable.Range(0, points.Count).ToArray();
			float num = linkDistance * linkDistance;
			for (int i = 0; i < points.Count; i++)
			{
				for (int j = i + 1; j < points.Count; j++)
				{
					float num2 = points[i].x - points[j].x;
					float num3 = points[i].z - points[j].z;
					if (num2 * num2 + num3 * num3 <= num)
					{
						array[Find(array, i)] = Find(array, j);
					}
				}
			}
			Dictionary<int, List<int>> dictionary = new Dictionary<int, List<int>>();
			for (int k = 0; k < points.Count; k++)
			{
				int key = Find(array, k);
				if (!dictionary.TryGetValue(key, out var value))
				{
					value = (dictionary[key] = new List<int>());
				}
				value.Add(k);
			}
			return dictionary.Values.ToList();
		}

		private static int Find(int[] parent, int i)
		{
			while (parent[i] != i)
			{
				parent[i] = parent[parent[i]];
				i = parent[i];
			}
			return i;
		}

		private static Vector3 Centre<T>(List<T> items, Func<T, Vector3> position)
		{
			//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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			foreach (T item in items)
			{
				val += position(item);
			}
			return val / (float)items.Count;
		}

		internal static string DirectionToken(Vector3 from, Vector3 to)
		{
			//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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			string[] obj = new string[8] { "$portalnetwork_dir_n", "$portalnetwork_dir_ne", "$portalnetwork_dir_e", "$portalnetwork_dir_se", "$portalnetwork_dir_s", "$portalnetwork_dir_sw", "$portalnetwork_dir_w", "$portalnetwork_dir_nw" };
			int num = Mathf.RoundToInt(Mathf.Repeat(Mathf.Atan2(to.x - from.x, to.z - from.z) * 57.29578f, 360f) / 45f) % 8;
			return obj[num];
		}

		static PortalGroups()
		{
			Biome[] array = new Biome[9];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			BiomeOrder = (Biome[])(object)array;
		}
	}
	internal static class PortalNames
	{
		internal static string Display(PortalInfo portal)
		{
			//IL_0029: 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_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)
			string obj = portal.Name ?? "";
			PlatformUserID val = (PlatformUserID)(string.IsNullOrEmpty(portal.TagAuthor) ? PlatformUserID.None : new PlatformUserID(portal.TagAuthor));
			string text = CensorShittyWords.FilterUGC(obj, (UGCType)4, val, 0L, (GetUserProfileCompletedHandler)null);
			if (!string.IsNullOrEmpty(text))
			{
				return StringExtensionMethods.RemoveRichTextTags(text);
			}
			return PortalNetworkLocalization.Localize("$portalnetwork_default_name");
		}
	}
	internal enum PortalVisibility
	{
		Private,
		Public
	}
	internal struct PortalInfo
	{
		public ZDOID Id;

		public string Name;

		public string TagAuthor;

		public Vector3 Position;

		public Quaternion Rotation;

		public long OwnerId;

		public PortalVisibility Visibility;

		public bool IsHome;

		public bool NameLocked;
	}
	internal static class PortalRegistry
	{
		internal static readonly int VisibilityHash = StringExtensionMethods.GetStableHashCode("PortalNetwork_Visibility");

		internal static readonly int HomeHash = StringExtensionMethods.GetStableHashCode("PortalNetwork_Home");

		internal static readonly int NameLockHash = StringExtensionMethods.GetStableHashCode("PortalNetwork_NameLocked");

		internal const int MaxNameLength = 10;

		private const PortalVisibility DefaultVisibility = PortalVisibility.Public;

		private const float ChangeGraceSeconds = 5f;

		private static ZDOID _changedHome = ZDOID.None;

		private static float _changedAt = float.NegativeInfinity;

		internal static bool TryGetPortal(ZDOID id, out ZDO zdo)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			zdo = ((ZDOMan.instance != null) ? ZDOMan.instance.GetZDO(id) : null);
			if (zdo != null)
			{
				return Game.instance.PortalPrefabHash.Contains(zdo.GetPrefab());
			}
			return false;
		}

		internal static bool IsVisibleTo(PortalInfo info, Requester who)
		{
			if (!who.IsAdmin && info.Visibility != PortalVisibility.Public)
			{
				if (who.PlayerId != 0L)
				{
					return info.OwnerId == who.PlayerId;
				}
				return false;
			}
			return true;
		}

		internal static bool CanChange(PortalInfo info, Requester who)
		{
			if (!who.IsAdmin && info.OwnerId != 0L)
			{
				if (who.PlayerId != 0L)
				{
					return info.OwnerId == who.PlayerId;
				}
				return false;
			}
			return true;
		}

		internal static bool CanRename(PortalInfo info, Requester who)
		{
			if (info.NameLocked)
			{
				return CanChange(info, who);
			}
			return true;
		}

		internal static bool CanSetHome(Requester who)
		{
			return who.IsAdmin;
		}

		internal static void OnHomeChanged(ZDOID home)
		{
			//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)
			_changedHome = home;
			_changedAt = Time.unscaledTime;
		}

		internal static ZDOID FindHome()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_009a: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime - _changedAt < 5f)
			{
				return _changedHome;
			}
			ZDOID result = ZDOID.None;
			long num = 0L;
			if (ZDOMan.instance == null)
			{
				return result;
			}
			foreach (ZDO portal in ZDOMan.instance.GetPortalList())
			{
				long num2 = portal.GetLong(HomeHash, 0L);
				long num3 = Math.Abs(num2);
				if (num3 > num)
				{
					num = num3;
					result = ((num2 > 0 && GetVisibility(portal) == PortalVisibility.Public) ? portal.m_uid : ZDOID.None);
				}
			}
			return result;
		}

		internal static List<PortalInfo> GetVisibleTo(Requester who)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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)
			List<PortalInfo> list = new List<PortalInfo>();
			if (ZDOMan.instance == null)
			{
				return list;
			}
			ZDOID val = FindHome();
			foreach (ZDO portal in ZDOMan.instance.GetPortalList())
			{
				PortalInfo portalInfo = ToInfo(portal);
				portalInfo.IsHome = portal.m_uid == val;
				if (IsVisibleTo(portalInfo, who))
				{
					list.Add(portalInfo);
				}
			}
			return list;
		}

		private static PortalVisibility GetVisibility(ZDO zdo)
		{
			return (PortalVisibility)zdo.GetInt(VisibilityHash, 1);
		}

		internal static PortalInfo ToInfo(ZDO zdo)
		{
			//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_0046: 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_0053: 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)
			return new PortalInfo
			{
				Id = zdo.m_uid,
				Name = zdo.GetString(ZDOVars.s_tag, ""),
				TagAuthor = zdo.GetString(ZDOVars.s_tagauthor, ""),
				Position = zdo.GetPosition(),
				Rotation = zdo.GetRotation(),
				OwnerId = zdo.GetLong(ZDOVars.s_creator, 0L),
				Visibility = GetVisibility(zdo),
				NameLocked = zdo.GetBool(NameLockHash, false)
			};
		}
	}
}
namespace PortalNetwork.Patches
{
	[HarmonyPatch(typeof(Minimap), "InTextInput")]
	internal static class Minimap_InTextInput_Patch
	{
		private static void Postfix(ref bool __result)
		{
			__result = __result || PortalPickerPanel.SearchFocused;
		}
	}
	[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
	internal static class Minimap_OnMapLeftClick_Patch
	{
		private static bool Prefix()
		{
			if (!PortalMapPicker.IsActive)
			{
				return true;
			}
			PortalMapPicker.HandleClick();
			return false;
		}
	}
	[HarmonyPatch(typeof(Minimap), "ShowPinNameInput")]
	internal static class Minimap_ShowPinNameInput_Patch
	{
		private static bool Prefix()
		{
			if (!PortalMapPicker.IsActive)
			{
				return true;
			}
			if (!ZInput.IsMouseActive())
			{
				PortalMapPicker.HandleGamepadConfirm();
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Minimap), "SetMapMode")]
	internal static class Minimap_SetMapMode_Patch
	{
		private static void Postfix(MapMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 2)
			{
				PortalMapPicker.Close();
			}
		}
	}
	[HarmonyPatch(typeof(Minimap), "UpdateMap")]
	internal static class Minimap_UpdateMap_Patch
	{
		private static void Prefix(ref bool takeInput)
		{
			if (takeInput && PortalPickerPanel.IsPointerOver())
			{
				takeInput = false;
			}
		}
	}
	[HarmonyPatch(typeof(Minimap), "Update")]
	internal static class Minimap_Update_Patch
	{
		private static void Postfix()
		{
			PortalMapPicker.Tick();
			PortalMapOverlay.Tick();
			PortalKeyHint.Tick();
			LocationPing.Tick();
			HomePortal.Tick();
		}
	}
	[HarmonyPatch(typeof(Minimap), "UpdatePlayerPins")]
	internal static class Minimap_UpdatePlayerPins_Patch
	{
		private sealed class PinTravel
		{
			public Vector3 Target;

			public float Speed;
		}

		private const float TeleportDistance = 100f;

		private static readonly ConditionalWeakTable<PinData, PinTravel> Travels = new ConditionalWeakTable<PinData, PinTravel>();

		private static readonly List<PinData> PinsBefore = new List<PinData>();

		private static readonly List<Vector3> PositionsBefore = new List<Vector3>();

		private static readonly List<string> NamesBefore = new List<string>();

		private static void Prefix(Minimap __instance)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			PinsBefore.Clear();
			PositionsBefore.Clear();
			NamesBefore.Clear();
			foreach (PinData playerPin in __instance.m_playerPins)
			{
				PinsBefore.Add(playerPin);
				PositionsBefore.Add(playerPin.m_pos);
				NamesBefore.Add(playerPin.m_name);
			}
		}

		private static void Postfix(Minimap __instance, float dt)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			List<PinData> playerPins = __instance.m_playerPins;
			List<PlayerInfo> tempPlayerInfo = __instance.m_tempPlayerInfo;
			float value = PortalNetworkPlugin._playerIconTeleportSeconds.Value;
			for (int i = 0; i < playerPins.Count && i < tempPlayerInfo.Count; i++)
			{
				PinData val = playerPins[i];
				Vector3 target = tempPlayerInfo[i].m_position;
				if (i >= PinsBefore.Count || PinsBefore[i] != val || !(NamesBefore[i] == tempPlayerInfo[i].m_name))
				{
					Travels.Remove(val);
					Travels.Add(val, new PinTravel
					{
						Target = target
					});
					continue;
				}
				PinTravel value2 = Travels.GetValue(val, (PinData _) => new PinTravel
				{
					Target = target
				});
				Vector3 val2 = PositionsBefore[i];
				if (Vector3.Distance(target, value2.Target) > 100f)
				{
					value2.Speed = ((value > 0f) ? (Vector3.Distance(val2, target) / value) : float.PositiveInfinity);
				}
				value2.Target = target;
				if (!(value2.Speed <= 0f))
				{
					Vector3 val3 = (float.IsPositiveInfinity(value2.Speed) ? target : Vector3.MoveTowards(val2, target, value2.Speed * dt));
					if (val3 == target)
					{
						value2.Speed = 0f;
					}
					if (val3 != val.m_pos)
					{
						val.m_pos = val3;
						__instance.m_pinUpdateRequired = true;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(ZDOMan), "PrepareSave")]
	internal static class ZDOMan_PrepareSave_Patch
	{
		private static void Prefix(ZDOMan __instance)
		{
			if (__instance.m_portalObjects.Count > 0)
			{
				__instance.SetDirtyPortals();
			}
		}
	}
	internal static class PortalOwnership
	{
		internal const string SetVisibilityRpc = "RPC_PortalNetwork_SetVisibility";

		internal const string SetHomeRpc = "RPC_PortalNetwork_SetHome";

		internal const string SetNameLockRpc = "RPC_PortalNetwork_SetNameLock";
	}
	[HarmonyPatch(typeof(TeleportWorld), "Awake")]
	internal static class TeleportWorld_Awake_Patch
	{
		private static void Postfix(TeleportWorld __instance)
		{
			ZNetView nview = ((Component)__instance).GetComponent<ZNetView>();
			if (!((Object)(object)nview == (Object)null) && nview.GetZDO() != null)
			{
				nview.Register<int>("RPC_PortalNetwork_SetVisibility", (Action<long, int>)delegate(long sender, int value)
				{
					OnSetVisibility(nview, sender, value);
				});
				nview.Register<long>("RPC_PortalNetwork_SetHome", (Action<long, long>)delegate(long sender, long stamp)
				{
					OnSetHome(nview, sender, stamp);
				});
				nview.Register<bool>("RPC_PortalNetwork_SetNameLock", (Action<long, bool>)delegate(long sender, bool locked)
				{
					OnSetNameLock(nview, sender, locked);
				});
			}
		}

		private static void OnSetNameLock(ZNetView nview, long sender, bool locked)
		{
			if (sender == ZRoutedRpc.instance.GetServerPeerID() && nview.IsValid() && nview.IsOwner())
			{
				nview.GetZDO().Set(PortalRegistry.NameLockHash, locked);
			}
		}

		private static void OnSetVisibility(ZNetView nview, long sender, int value)
		{
			if (sender == ZRoutedRpc.instance.GetServerPeerID() && nview.IsValid() && nview.IsOwner() && Enum.IsDefined(typeof(PortalVisibility), value))
			{
				nview.GetZDO().Set(PortalRegistry.VisibilityHash, value, false);
			}
		}

		private static void OnSetHome(ZNetView nview, long sender, long stamp)
		{
			if (sender == ZRoutedRpc.instance.GetServerPeerID() && nview.IsValid() && nview.IsOwner())
			{
				ZDO zDO = nview.GetZDO();
				zDO.Set(PortalRegistry.HomeHash, stamp);
				if (stamp > 0)
				{
					zDO.Set(PortalRegistry.VisibilityHash, 1, false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "Interact")]
	internal static class TeleportWorld_Interact_Patch
	{
		private static bool Prefix(TeleportWorld __instance, Humanoid human, bool hold, bool alt, ref bool __result)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (hold)
			{
				return true;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null);
			if (val != null)
			{
				Player val2 = (Player)(object)((human is Player) ? human : null);
				if (val2 != null)
				{
					if (!alt)
					{
						if (PortalRegistry.CanRename(who: new Requester(val2.GetPlayerID(), PlayerIdentity.LocalIsAdmin()), info: PortalRegistry.ToInfo(val)))
						{
							return true;
						}
						((Character)val2).Message((MessageType)2, "$portalnetwork_name_locked", 0, (Sprite)null, false);
						__result = false;
						return false;
					}
					__result = true;
					PortalVisibility visibility = ((PortalRegistry.ToInfo(val).Visibility != PortalVisibility.Public) ? PortalVisibility.Public : PortalVisibility.Private);
					PortalNetworkRpc.SendVisibilityRequest(val.m_uid, visibility);
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "GetHoverText")]
	internal static class TeleportWorld_GetHoverText_Patch
	{
		private static string HomeColorHex => "#" + ColorUtility.ToHtmlStringRGB(PortalPinStyle.HomeColor);

		private static void Postfix(TeleportWorld __instance, ref string __result)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null);
			if (val == null)
			{
				return;
			}
			PortalInfo info = PortalRegistry.ToInfo(val);
			string text = ((info.Visibility == PortalVisibility.Public) ? "$portalnetwork_visibility_public" : "$portalnetwork_visibility_private");
			string text2 = "\n$portalnetwork_visibility: " + text;
			bool flag = HomePortal.IsHome(val.m_uid);
			if (flag)
			{
				text2 = text2 + "\n<color=" + HomeColorHex + ">$portalnetwork_home_portal</color>";
			}
			if (info.NameLocked)
			{
				text2 += "\n$portalnetwork_name_locked_status";
			}
			else if (HomePortal.HasHome)
			{
				text2 += Hint(HomePortal.KeyText(PortalNetworkPlugin._travelHomeKey.Value), "$portalnetwork_travel_home_hint");
			}
			if (PortalFavourites.TryGetGoBackKey(val.GetPosition(), out var _))
			{
				text2 += Hint(HomePortal.KeyText(PortalNetworkPlugin._goBackKey.Value), "$portalnetwork_go_back_hint");
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				Requester who = new Requester(localPlayer.GetPlayerID(), PlayerIdentity.LocalIsAdmin());
				if (!flag && PortalRegistry.CanChange(info, who))
				{
					text2 += Hint("Shift + $KEY_Use", "$portalnetwork_toggle_hint");
				}
				if (PortalRegistry.CanSetHome(who))
				{
					text2 += Hint(HomePortal.KeyText(PortalNetworkPlugin._setHomeKey.Value), flag ? "$portalnetwork_remove_home_hint" : "$portalnetwork_set_home_hint");
				}
			}
			__result += PortalNetworkLocalization.Localize(text2);
		}

		private static string Hint(string keys, string label)
		{
			return "\n[<color=yellow><b>" + keys + "</b></color>] " + label;
		}
	}
	internal static class PortalVisualPatches
	{
		private static readonly HashSet<string> Logged = new HashSet<string>();

		internal static bool IsPlacedPortal(TeleportWorld portal)
		{
			ZNetView component = ((Component)portal).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null)
			{
				return component.GetZDO() != null;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "HaveTarget")]
	internal static class TeleportWorld_HaveTarget_Patch
	{
		private static bool Prefix(TeleportWorld __instance, ref bool __result)
		{
			if (!PortalVisualPatches.IsPlacedPortal(__instance))
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "TargetFound")]
	internal static class TeleportWorld_TargetFound_Patch
	{
		private static bool Prefix(TeleportWorld __instance, ref bool __result)
		{
			if (!PortalVisualPatches.IsPlacedPortal(__instance))
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "Update")]
	internal static class TeleportWorld_Update_Patch
	{
		private static void Postfix(TeleportWorld __instance)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance.m_model == (Object)null) && PortalVisualPatches.IsPlacedPortal(__instance))
			{
				((Renderer)__instance.m_model).material.SetColor("_EmissionColor", __instance.m_colorTargetfound);
			}
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")]
	internal static class TeleportWorld_UpdatePortal_Patch
	{
		private static void Postfix(TeleportWorld __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance.m_proximityRoot == (Object)null) && !((Object)(object)__instance.m_target_found == (Object)null) && PortalVisualPatches.IsPlacedPortal(__instance))
			{
				Player closestPlayer = Player.GetClosestPlayer(__instance.m_proximityRoot.position, __instance.m_activationRange);
				bool active = (Object)(object)closestPlayer != (Object)null && ((Humanoid)closestPlayer).IsTeleportable(__instance.m_allowAllItems);
				__instance.m_target_found.SetActive(active);
			}
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
	internal static class TeleportWorld_Teleport_Patch
	{
		private static bool Prefix(TeleportWorld __instance, Player player)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null);
			if (val == null)
			{
				return true;
			}
			if (!PortalNetworkClient.CanUsePortals(player, __instance))
			{
				return false;
			}
			PortalNetworkClient.RequestPortalList(val.m_uid, val.GetPosition());
			return false;
		}
	}
	[HarmonyPatch(typeof(ZInput), "Update")]
	internal static class ZInput_Update_Patch
	{
		private static void Postfix()
		{
			if (HomePortal.PortalKeyUsedThisFrame())
			{
				KeyInput.CancelButtonsPressedThisFrame();
			}
		}
	}
}
namespace PortalNetwork.Network
{
	internal static class PortalNetworkClient
	{
		private enum ListPurpose
		{
			Picker,
			Overlay,
			GoBack
		}

		private const float ExitDistance = 1f;

		private const float RequestCooldownSeconds = 1f;

		private static ZDOID _enteredPortal = ZDOID.None;

		private static Vector3 _enteredPosition;

		private static float _lastRequestTime = -10f;

		private static readonly Queue<ListPurpose> PendingRequests = new Queue<ListPurpose>();

		internal static bool CanUsePortals(Player player, TeleportWorld portal)
		{
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)32))
			{
				((Character)player).Message((MessageType)2, "$msg_blocked", 0, (Sprite)null, false);
				return false;
			}
			float num = default(float);
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)33) && (RandEventSystem.instance.GetBossEvent() != null || (ZoneSystem.instance.GetGlobalKey((GlobalKeys)47, ref num) && num > 0f)))
			{
				((Character)player).Message((MessageType)2, "$msg_blockedbyboss", 0, (Sprite)null, false);
				return false;
			}
			if (!((Humanoid)player).IsTeleportable(portal.m_allowAllItems))
			{
				((Character)player).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false);
				return false;
			}
			return true;
		}

		internal static void RequestPortalList(ZDOID enteredPortal, Vector3 enteredPosition)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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)
			if (!(Time.unscaledTime - _lastRequestTime < 1f))
			{
				_lastRequestTime = Time.unscaledTime;
				_entere