Decompiled source of CDEV PortalPins v0.2.0

plugins\CDEV.PortalPins\CDEV.PortalPins.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CDEV.PortalPins.Client;
using CDEV.PortalPins.Net;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CDEV.PortalPins")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+dc973356a9e1d4377ae0cec010ca435f57d87290")]
[assembly: AssemblyProduct("CDEV.PortalPins")]
[assembly: AssemblyTitle("CDEV.PortalPins")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.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 CDEV.PortalPins
{
	internal static class ModConfig
	{
		internal static ConfigEntry<bool> AllowRemoving;

		internal static ConfigEntry<bool> AdminsOnly;

		internal static ConfigEntry<bool> ConfirmRemoval;

		internal static ConfigEntry<string> NamePrefix;

		internal static ConfigEntry<bool> ShowPortalList;

		internal static void Bind(ConfigFile config)
		{
			//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_0027: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			AllowRemoving = config.Bind<bool>("Pins", "AllowRemoving", false, new ConfigDescription("Server: right click (long touch) on a portal pin removes it for EVERY player; the portal itself stays. The server remembers it next to the world, so it also survives a restart. Off: portal pins cannot be removed at all.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			AdminsOnly = config.Bind<bool>("Pins", "AdminsOnly", true, new ConfigDescription("Server: only admins (adminlist.txt) and whoever hosts the world may remove a portal pin. Off: every player may, and it applies to everybody.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			ConfirmRemoval = config.Bind<bool>("Pins", "ConfirmRemoval", true, "Client: ask before a portal pin is removed. Local to this machine.");
			NamePrefix = config.Bind<string>("Pins", "NamePrefix", "*", "Client: put in front of every pin name of this mod, so a portal pin is recognisable among your own pins. Empty: no prefix.");
			ShowPortalList = config.Bind<bool>("Portals", "ShowPortalList", true, "Client: in the portal's tag window, clicking the name field opens the list of every portal of the world with a mark whether it is linked to another one. Clicking an entry writes its name into the field.");
		}
	}
	[BepInPlugin("cdev.portalpins", "CDEV.PortalPins", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class PortalPinsPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static PortalPinsPlugin Instance;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new SelfTestCommand());
			_harmony = new Harmony("cdev.portalpins");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		private void Update()
		{
			PortalServer.Tick();
			PortalPinLayer.Tick();
			PortalPinLayer.AnimatePulse();
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal sealed class SelfTestCommand : ConsoleCommand
	{
		private const long FakeUser = -7770001L;

		public override string Name => "pp_selftest";

		public override string Help => "CDEV.PortalPins self-test (two fake portal pins in a map corner for a moment)";

		public override void Run(string[] args)
		{
			((ConsoleCommand)this).Run(args, (Terminal)null);
		}

		public override void Run(string[] args, Terminal context)
		{
			List<string> report = new List<string>();
			int failures = 0;
			int checks = 0;
			List<PortalRecord> list = new List<PortalRecord>(PortalPinLayer.Current);
			bool received = PortalPinLayer.Received;
			try
			{
				CodecChecks(Check);
				ServerChecks(Check, Note);
				LayerChecks(list, Check, Note);
				HandlerChecks(list, Check, Note);
			}
			catch (Exception ex)
			{
				Check(ok: false, "no exception during the checks", ex.ToString());
			}
			finally
			{
				PortalPinLayer.Apply(list);
				PortalPinLayer.Received = received;
			}
			report.Add("pp_selftest: " + ((failures == 0) ? $"PASS ({checks} checks)" : $"FAIL ({failures} of {checks} checks)"));
			foreach (string item in report)
			{
				if (context != null)
				{
					context.AddString(item);
				}
				if (item.StartsWith("FAIL", StringComparison.Ordinal))
				{
					PortalPinsPlugin.Log.LogWarning((object)item);
				}
				else
				{
					PortalPinsPlugin.Log.LogInfo((object)item);
				}
			}
			void Check(bool ok, string what, string detail)
			{
				checks++;
				failures += ((!ok) ? 1 : 0);
				report.Add((ok ? "ok   " : "FAIL ") + what + ((ok || string.IsNullOrEmpty(detail)) ? "" : (" - " + detail)));
			}
			void Note(string what)
			{
				report.Add("skip " + what);
			}
		}

		private static PortalRecord Fake(uint id, string tag, float offset = 0f)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			return new PortalRecord
			{
				Id = new ZDOID(-7770001L, id),
				Position = new Vector3(-7000f + offset, 30f, -7000f),
				Tag = tag,
				Author = ""
			};
		}

		private static void CodecChecks(Action<bool, string, string> check)
		{
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Expected O, but got Unknown
			//IL_0071: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			List<PortalRecord> list = new List<PortalRecord>
			{
				Fake(1u, "Дом / Home"),
				Fake(2u, "", 40f)
			};
			List<PortalRecord> list2 = new List<PortalRecord>();
			ZPackage val = Protocol.WriteList(list);
			val.SetPos(0);
			string error;
			bool flag = Protocol.TryReadList(val, list2, out error) && list2.Count == 2;
			int num = 0;
			while (flag && num < 2)
			{
				flag = list2[num].Id == list[num].Id && list2[num].Position == list[num].Position && list2[num].Tag == list[num].Tag && list2[num].Author == list[num].Author;
				num++;
			}
			check(flag, "codec: list survives the round trip", error ?? "fields differ");
			ZPackage val2 = new ZPackage();
			val2.Write(4);
			val2.Write(0);
			val2.SetPos(0);
			check(!Protocol.TryReadList(val2, list2, out var error2), "control: other schema is rejected", "accepted");
			byte[] array = Protocol.WriteList(list).GetArray();
			check(!Protocol.TryReadList(new ZPackage(array, array.Length - 5), list2, out error2) && list2.Count == 0, "control: truncated list is rejected and leaves nothing", "accepted or left data");
			ZPackage val3 = new ZPackage();
			val3.Write(3);
			val3.Write(20001);
			val3.SetPos(0);
			check(!Protocol.TryReadList(val3, list2, out error2), "control: count over the limit is rejected", "accepted");
		}

		private static void ServerChecks(Action<bool, string, string> check, Action<string> note)
		{
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || ZDOMan.instance == null)
			{
				note("server: not the server here (the scan runs on the server), scan check skipped");
				return;
			}
			PortalServer.Scan();
			int count = ZDOMan.instance.GetPortalList().Count;
			check(PortalServer.Portals.Count == count, $"server: scan finds every portal ZDO ({count})", $"scan {PortalServer.Portals.Count}");
		}

		private static void LayerChecks(List<PortalRecord> real, Action<bool, string, string> check, Action<string> note)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Invalid comparison between Unknown and I4
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: 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_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				note("pins: no minimap or local player, pin checks skipped");
				return;
			}
			PortalRecord portalRecord = Fake(1u, "Selftest Portal");
			PortalRecord portalRecord2 = Fake(2u, "", 40f);
			PortalPinLayer.Apply(new List<PortalRecord>(real) { portalRecord, portalRecord2 });
			PinData pin;
			bool flag = PortalPinLayer.TryGetPin(portalRecord.Id, out pin);
			PortalPinLayer.TryGetPin(portalRecord2.Id, out var pin2);
			check(flag && instance.m_pins.Contains(pin), "pins: portal gets a pin on the map", "no pin");
			if (flag)
			{
				string text = ModConfig.NamePrefix.Value ?? "";
				check(!pin.m_save && (int)pin.m_type == 6 && pin.m_name == text + "Selftest Portal", "pins: unsaved portal-icon pin named after the tag, with the prefix", $"save {pin.m_save}, type {pin.m_type}, name '{pin.m_name}'");
				check(pin2 != null && pin2.m_name == PortalPinLayer.DisplayName(portalRecord2) && pin2.m_name.Length > 0, "pins: untagged portal is named 'Portal'", (pin2 != null) ? pin2.m_name : "no pin");
				check(PortalPinLayer.Count == real.Count + 2 || (real.Count == 0 && PortalPinLayer.Count == 2), "pins: real portals keep their pins", $"{PortalPinLayer.Count} pins for {real.Count} + 2 portals");
				check(!instance.RemovePin(pin.m_pos, 5f) && instance.m_pins.Contains(pin), "pins: right-click removal does not remove it", "removed");
				check(instance.GetClosestPin(pin.m_pos, 5f, false) != pin, "pins: left click cannot cross it out", "found by GetClosestPin");
				Vector3 val = pin.m_pos + new Vector3(10f, 0f, 0f);
				PinData val2 = instance.AddPin(val, (PinType)3, "Selftest player pin", true, false, 0L, default(PlatformUserID));
				bool arg = instance.RemovePin(val, 5f);
				if (instance.m_pins.Contains(val2))
				{
					instance.RemovePin(val2);
				}
				check(arg, "control: a player's saved pin there is removable", "not removed");
				instance.RemovePin(pin);
				int num = PortalPinLayer.Guard();
				check(num >= 1 && PortalPinLayer.TryGetPin(portalRecord.Id, out var pin3) && instance.m_pins.Contains(pin3), "pins: a pin removed by code comes back", $"restored {num}");
				PortalRecord item = portalRecord;
				item.Tag = "Selftest Renamed";
				PortalPinLayer.Apply(new List<PortalRecord>(real) { item, portalRecord2 });
				check(PortalPinLayer.TryGetPin(portalRecord.Id, out var pin4) && pin4.m_name == text + "Selftest Renamed" && instance.m_pins.Contains(pin4), "pins: renamed portal renames its pin", (pin4 != null) ? pin4.m_name : "no pin");
				PortalPinLayer.TryGetPin(portalRecord2.Id, out var pin5);
				PortalPinLayer.Apply(real);
				check(!PortalPinLayer.TryGetPin(portalRecord.Id, out var _) && !instance.m_pins.Contains(pin4) && !instance.m_pins.Contains(pin5), "pins: destroyed portal loses its pin", "pin left");
			}
		}

		private static void HandlerChecks(List<PortalRecord> real, Action<bool, string, string> check, Action<string> note)
		{
			//IL_009f: 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)
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance == null || (Object)(object)ZNet.instance == (Object)null || ZNet.instance.IsServer() || (Object)(object)Minimap.instance == (Object)null)
			{
				note("rpc: not a client connected to a server, list handler checks skipped");
				return;
			}
			RoutedMethodBase value;
			bool flag = instance.m_functions.TryGetValue(StringExtensionMethods.GetStableHashCode("CDEV_PortalPins_List"), out value);
			check(flag, "rpc: CDEV_PortalPins_List is registered", "missing");
			if (flag)
			{
				List<PortalRecord> list = new List<PortalRecord>(real) { Fake(3u, "Selftest Rpc") };
				value.Invoke(-7770001L, RoutedParameters(list));
				check(!PortalPinLayer.TryGetPin(new ZDOID(-7770001L, 3u), out var pin), "control: a list from another client is ignored", "applied");
				value.Invoke(instance.GetServerPeerID(), RoutedParameters(list));
				check(PortalPinLayer.TryGetPin(new ZDOID(-7770001L, 3u), out pin), "rpc: the server's list is applied", "not applied");
			}
		}

		private static ZPackage RoutedParameters(List<PortalRecord> list)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			ZRpc.Serialize(new object[1] { Protocol.WriteList(list) }, ref val);
			val.SetPos(0);
			return val;
		}
	}
	internal static class BuildInfo
	{
		public const string Name = "CDEV.PortalPins";

		public const string Guid = "cdev.portalpins";

		public const string Version = "0.2.0";
	}
}
namespace CDEV.PortalPins.Patches
{
	[HarmonyPatch(typeof(ZNet), "Awake")]
	internal static class ZNet_Awake
	{
		private static void Postfix()
		{
			PortalServer.Reset();
			PortalPinLayer.Reset();
			HiddenPortals.Reset();
			try
			{
				ZRoutedRpc instance = ZRoutedRpc.instance;
				instance.Register<ZPackage>("CDEV_PortalPins_Request", (Action<long, ZPackage>)PortalServer.OnRequest);
				instance.Register<ZPackage>("CDEV_PortalPins_Hide", (Action<long, ZPackage>)PortalServer.OnHide);
				instance.Register<ZPackage>("CDEV_PortalPins_List", (Action<long, ZPackage>)PortalPinLayer.OnList);
				instance.Register<ZPackage>("CDEV_PortalPins_HideResult", (Action<long, ZPackage>)PortalPinLayer.OnHideResult);
			}
			catch (Exception arg)
			{
				PortalPinsPlugin.Log.LogError((object)$"Registering RPCs failed: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(Minimap), "UpdatePins")]
	internal static class Minimap_UpdatePins
	{
		private static void Postfix()
		{
			PortalPinLayer.AfterUpdatePins();
		}
	}
	[HarmonyPatch(typeof(ZNet), "OnDestroy")]
	internal static class ZNet_OnDestroy
	{
		private static void Postfix()
		{
			PortalServer.Reset();
			PortalPinLayer.Reset();
		}
	}
}
namespace CDEV.PortalPins.Net
{
	internal static class HiddenPortals
	{
		internal const string FileSuffix = ".mod.portalpins.hidden";

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

		private static string _file;

		private static string _worldKey;

		internal static int Count => Hidden.Count;

		internal static bool IsHidden(ZDOID portal)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (Hidden.Count > 0)
			{
				return Hidden.Contains(portal);
			}
			return false;
		}

		internal static void Reset()
		{
			Hidden.Clear();
			_file = null;
			_worldKey = null;
		}

		internal static void EnsureLoaded()
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			World val = (((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()) ? ZNet.World : null);
			if (val == null)
			{
				return;
			}
			string text = val.m_name + "|" + val.m_seed;
			if (_worldKey == text)
			{
				return;
			}
			Hidden.Clear();
			_worldKey = text;
			_file = null;
			try
			{
				_file = WorldFiles.BasePath(val) + ".mod.portalpins.hidden";
				if (!File.Exists(_file))
				{
					return;
				}
				string[] array = File.ReadAllLines(_file, Encoding.UTF8);
				foreach (string text2 in array)
				{
					if (TryParse(text2, out var id))
					{
						Hidden.Add(id);
					}
				}
				PortalPinsPlugin.Log.LogInfo((object)$"Hidden portal pins: {Hidden.Count} from {_file}");
			}
			catch (Exception ex)
			{
				PortalPinsPlugin.Log.LogWarning((object)("Could not read the hidden portal pins: " + ex.Message));
			}
		}

		internal static bool Set(ZDOID portal, bool hidden)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			EnsureLoaded();
			bool flag = (hidden ? Hidden.Add(portal) : Hidden.Remove(portal));
			if (flag)
			{
				Save();
			}
			return flag;
		}

		private static bool TryParse(string text, out ZDOID id)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			id = ZDOID.None;
			string[] array = (text ?? "").Trim().Split(new char[1] { ':' });
			if (array.Length != 2 || !long.TryParse(array[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) || !uint.TryParse(array[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2))
			{
				return false;
			}
			id = new ZDOID(result, result2);
			return true;
		}

		private static void Save()
		{
			//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)
			if (_file == null)
			{
				return;
			}
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				foreach (ZDOID item in Hidden)
				{
					ZDOID current = item;
					stringBuilder.Append(((ZDOID)(ref current)).UserID.ToString(CultureInfo.InvariantCulture)).Append(':').Append(((ZDOID)(ref current)).ID.ToString(CultureInfo.InvariantCulture))
						.Append('\n');
				}
				File.WriteAllText(_file, stringBuilder.ToString(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
			}
			catch (Exception ex)
			{
				PortalPinsPlugin.Log.LogWarning((object)("Could not write " + _file + ": " + ex.Message));
			}
		}
	}
	internal static class PortalServer
	{
		private const float ScanInterval = 2f;

		internal static readonly List<PortalRecord> Portals = new List<PortalRecord>();

		private static float _nextScanAt;

		private static long _lastSignature;

		private static bool _haveList;

		private static readonly Comparison<PortalRecord> ById = delegate(PortalRecord a, PortalRecord b)
		{
			int num = ((ZDOID)(ref a.Id)).UserID.CompareTo(((ZDOID)(ref b.Id)).UserID);
			return (num == 0) ? ((ZDOID)(ref a.Id)).ID.CompareTo(((ZDOID)(ref b.Id)).ID) : num;
		};

		internal static void Reset()
		{
			Portals.Clear();
			_nextScanAt = 0f;
			_lastSignature = 0L;
			_haveList = false;
		}

		internal static void Tick()
		{
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null || !instance.IsServer() || ZDOMan.instance == null || (Object)(object)Game.instance == (Object)null || Time.time < _nextScanAt)
			{
				return;
			}
			_nextScanAt = Time.time + 2f;
			try
			{
				HiddenPortals.EnsureLoaded();
				long num = Scan();
				if (!_haveList || num != _lastSignature)
				{
					bool flag = !_haveList;
					_haveList = true;
					_lastSignature = num;
					PortalPinsPlugin.Log.LogInfo((object)string.Format("Portal list {0}: {1} portals.", flag ? "built" : "changed", Portals.Count));
					Publish(0L);
				}
			}
			catch (Exception arg)
			{
				PortalPinsPlugin.Log.LogError((object)$"Portal scan failed: {arg}");
				_nextScanAt = Time.time + 30f;
			}
		}

		internal static void OnHide(long sender, ZPackage pkg)
		{
			//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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ZNet instance = ZNet.instance;
				if ((Object)(object)instance == (Object)null || !instance.IsServer() || pkg.ReadInt() != 3)
				{
					return;
				}
				ZDOID val = pkg.ReadZDOID();
				bool hidden = pkg.ReadBool();
				if (!ModConfig.AllowRemoving.Value)
				{
					Answer(sender, ok: false, "off");
					return;
				}
				if (!MayChange(sender, out var who))
				{
					PortalPinsPlugin.Log.LogInfo((object)(who + " may not remove portal pins (AdminsOnly)."));
					Answer(sender, ok: false, "denied");
					return;
				}
				bool flag = false;
				foreach (PortalRecord portal in Portals)
				{
					flag |= portal.Id == val;
				}
				if (!flag)
				{
					Answer(sender, ok: false, "unknown");
					return;
				}
				if (HiddenPortals.Set(val, hidden))
				{
					PortalPinsPlugin.Log.LogInfo((object)$"{who} removed the pin of portal {val} for everybody.");
				}
				Answer(sender, ok: true, "hidden");
				Refresh();
			}
			catch (Exception arg)
			{
				PortalPinsPlugin.Log.LogError((object)$"Hiding a portal pin for peer {sender} failed: {arg}");
			}
		}

		private static bool MayChange(long sender, out string who)
		{
			ZNet instance = ZNet.instance;
			if (sender == ZDOMan.GetSessionID())
			{
				who = "the host";
				return true;
			}
			ZNetPeer peer = instance.GetPeer(sender);
			who = peer?.m_playerName ?? sender.ToString();
			if (!ModConfig.AdminsOnly.Value)
			{
				return true;
			}
			object obj;
			if (peer == null)
			{
				obj = null;
			}
			else
			{
				ISocket socket = peer.m_socket;
				obj = ((socket != null) ? socket.GetHostName() : null);
			}
			string text = (string)obj;
			if (!string.IsNullOrEmpty(text))
			{
				return instance.IsAdmin(text);
			}
			return false;
		}

		private static void Answer(long sender, bool ok, string code)
		{
			if (sender == ZDOMan.GetSessionID())
			{
				ZPackage val = Result(ok, code);
				val.SetPos(0);
				PortalPinLayer.OnHideResult(sender, val);
				return;
			}
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null)
			{
				instance.InvokeRoutedRPC(sender, "CDEV_PortalPins_HideResult", new object[1] { Result(ok, code) });
			}
		}

		private static ZPackage Result(bool ok, string code)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(3);
			val.Write(ok);
			val.Write(code);
			return val;
		}

		private static void Refresh()
		{
			_lastSignature = Scan();
			_haveList = true;
			Publish(0L);
		}

		internal static void OnRequest(long sender, ZPackage pkg)
		{
			try
			{
				if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
				{
					if (!_haveList)
					{
						Scan();
						_haveList = true;
						_lastSignature = Signature();
					}
					Publish(sender);
				}
			}
			catch (Exception arg)
			{
				PortalPinsPlugin.Log.LogError((object)$"Answering the portal request of peer {sender} failed: {arg}");
			}
		}

		private static void Publish(long target)
		{
			if (!ZNet.instance.IsDedicated() && (target == 0L || target == ZDOMan.GetSessionID()))
			{
				PortalPinLayer.Apply(Portals);
			}
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance == null || ZNet.instance.GetPeers().Count == 0 || target == ZDOMan.GetSessionID())
			{
				return;
			}
			ZPackage val = Protocol.WriteList(Portals);
			if (target == 0L)
			{
				foreach (ZNetPeer peer in ZNet.instance.GetPeers())
				{
					if (peer.IsReady())
					{
						instance.InvokeRoutedRPC(peer.m_uid, "CDEV_PortalPins_List", new object[1] { val });
					}
				}
				return;
			}
			instance.InvokeRoutedRPC(target, "CDEV_PortalPins_List", new object[1] { val });
		}

		internal static long Scan()
		{
			//IL_0063: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			Portals.Clear();
			foreach (KeyValuePair<SectorIndex, List<ZDO>> portal in ZDOMan.instance.GetPortals())
			{
				List<ZDO> value = portal.Value;
				for (int i = 0; i < value.Count; i++)
				{
					ZDO val = value[i];
					if (val != null && val.IsValid())
					{
						Portals.Add(new PortalRecord
						{
							Id = val.m_uid,
							Position = val.GetPosition(),
							Tag = val.GetString(ZDOVars.s_tag, ""),
							Author = val.GetString(ZDOVars.s_tagauthor, ""),
							Target = val.GetConnectionZDOID((ConnectionType)1),
							Hidden = HiddenPortals.IsHidden(val.m_uid)
						});
					}
				}
			}
			Portals.Sort(ById);
			return Signature();
		}

		private unsafe static long Signature()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			long num = 17L;
			foreach (PortalRecord portal in Portals)
			{
				long num2 = num * 31;
				ZDOID id = portal.Id;
				num = num2 + ((object)(*(ZDOID*)(&id))/*cast due to .constrained prefix*/).GetHashCode();
				long num3 = num * 31;
				Vector3 position = portal.Position;
				num = num3 + ((object)(*(Vector3*)(&position))/*cast due to .constrained prefix*/).GetHashCode();
				num = num * 31 + (portal.Tag ?? "").GetHashCode();
				num = num * 31 + (portal.Author ?? "").GetHashCode();
				long num4 = num * 31;
				id = portal.Target;
				num = num4 + ((object)(*(ZDOID*)(&id))/*cast due to .constrained prefix*/).GetHashCode();
				num = num * 31 + (portal.Hidden ? 1 : 0);
			}
			return num * 31 + Portals.Count;
		}
	}
	internal struct PortalRecord
	{
		public ZDOID Id;

		public Vector3 Position;

		public string Tag;

		public string Author;

		public ZDOID Target;

		public bool Hidden;

		public bool Linked => Target != ZDOID.None;
	}
	internal static class Protocol
	{
		internal const int Schema = 3;

		internal const string RequestRpc = "CDEV_PortalPins_Request";

		internal const string HideRpc = "CDEV_PortalPins_Hide";

		internal const string HideResultRpc = "CDEV_PortalPins_HideResult";

		internal const string ListRpc = "CDEV_PortalPins_List";

		internal const int MaxPortals = 20000;

		internal const int MaxTagLength = 256;

		internal static ZPackage WriteList(List<PortalRecord> portals)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(3);
			val.Write(portals.Count);
			foreach (PortalRecord portal in portals)
			{
				val.Write(portal.Id);
				val.Write(portal.Position);
				val.Write(Clip(portal.Tag));
				val.Write(Clip(portal.Author));
				val.Write(portal.Target);
				val.Write(portal.Hidden);
			}
			return val;
		}

		internal static bool TryReadList(ZPackage pkg, List<PortalRecord> portals, out string error)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_00b6: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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)
			portals.Clear();
			try
			{
				int num = pkg.ReadInt();
				if (num != 3)
				{
					error = $"schema {num}, expected {3}";
					return false;
				}
				int num2 = pkg.ReadInt();
				if (num2 < 0 || num2 > 20000)
				{
					error = $"{num2} portals, limit {20000}";
					return false;
				}
				for (int i = 0; i < num2; i++)
				{
					PortalRecord item = new PortalRecord
					{
						Id = pkg.ReadZDOID(),
						Position = pkg.ReadVector3(),
						Tag = Clip(pkg.ReadString()),
						Author = Clip(pkg.ReadString()),
						Target = pkg.ReadZDOID(),
						Hidden = pkg.ReadBool()
					};
					if (!float.IsNaN(item.Position.x) && !float.IsNaN(item.Position.y) && !float.IsNaN(item.Position.z) && !float.IsInfinity(item.Position.x) && !float.IsInfinity(item.Position.y) && !float.IsInfinity(item.Position.z))
					{
						portals.Add(item);
					}
				}
				error = null;
				return true;
			}
			catch (Exception ex)
			{
				portals.Clear();
				error = ex.GetType().Name + ": " + ex.Message;
				return false;
			}
		}

		private static string Clip(string text)
		{
			if (text == null)
			{
				return "";
			}
			if (text.Length <= 256)
			{
				return text;
			}
			return text.Substring(0, 256);
		}
	}
	internal static class WorldFiles
	{
		internal static string BasePath(World world)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			string path = (string.IsNullOrEmpty(Utils.GetSaveDataPath(world.m_fileSource)) ? world.GetDBPath((FileSource)2) : world.GetDBPath());
			string text = Path.ChangeExtension(path, null);
			string directoryName = Path.GetDirectoryName(text);
			if (!string.IsNullOrEmpty(directoryName))
			{
				Directory.CreateDirectory(directoryName);
			}
			return text;
		}
	}
}
namespace CDEV.PortalPins.Client
{
	internal static class Icons
	{
		private static Sprite _mapPin;

		internal static Sprite MapPin()
		{
			//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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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)
			if ((Object)(object)_mapPin != (Object)null)
			{
				return _mapPin;
			}
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				name = "CDEV_PortalPins_MapPin",
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float x = ((float)j + 0.5f) * 32f / 64f;
					float y = ((float)(63 - i) + 0.5f) * 32f / 64f;
					float num = Circle(x, y, 16f, 13f, 9f);
					float num2 = Triangle(x, y, 16f, 29f, 7.5f, 12f);
					float num3 = Mathf.Min(num, num2);
					float num4 = Circle(x, y, 16f, 13f, 3.6f);
					num3 = Mathf.Max(num3, 0f - num4);
					float num5 = Mathf.Clamp01(0.5f - num3 * 2f);
					array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num5 * 255f));
				}
			}
			val.SetPixels32(array);
			val.Apply(false, true);
			_mapPin = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
			((Object)_mapPin).name = "CDEV_PortalPins_MapPin";
			return _mapPin;
		}

		private static float Circle(float x, float y, float cx, float cy, float radius)
		{
			//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)
			Vector2 val = new Vector2(x - cx, y - cy);
			return ((Vector2)(ref val)).magnitude - radius;
		}

		private static float Triangle(float x, float y, float cx, float tipY, float halfWidth, float height)
		{
			//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)
			float num = Mathf.Abs(x - cx);
			float num2 = tipY - height;
			if (y < num2)
			{
				Vector2 val = new Vector2(num, num2 - y);
				return ((Vector2)(ref val)).magnitude;
			}
			float num3 = Mathf.Clamp01((tipY - y) / height);
			float num4 = halfWidth * num3;
			return Mathf.Max(num - num4, y - tipY);
		}
	}
	internal static class PinRemoval
	{
		[HarmonyPatch(typeof(Minimap), "RemovePinUnderPointer")]
		private static class RightClick
		{
			[CompilerGenerated]
			private static class <>O
			{
				public static PopupButtonCallback <0>__Pop;
			}

			private static bool Prefix(Minimap __instance)
			{
				//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_0025: 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_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Expected O, but got Unknown
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Expected O, but got Unknown
				//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_0095: Expected O, but got Unknown
				try
				{
					if (!ModConfig.AllowRemoving.Value)
					{
						return true;
					}
					Vector3 world = __instance.ScreenToWorldPoint(ZInput.pointerPosition);
					if (!PortalPinLayer.TryGetPortalAt(world, __instance.PinInteractRadius, out var portal))
					{
						return true;
					}
					if (!ModConfig.ConfirmRemoval.Value)
					{
						Remove(portal);
						return false;
					}
					ZDOID id = portal.Id;
					string removeTitle = Texts.RemoveTitle;
					string text = Texts.RemoveQuestion(PortalPinLayer.PortalName(portal));
					PopupButtonCallback val = delegate
					{
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						UnifiedPopup.Pop();
						Remove(id);
					};
					object obj = <>O.<0>__Pop;
					if (obj == null)
					{
						PopupButtonCallback val2 = UnifiedPopup.Pop;
						<>O.<0>__Pop = val2;
						obj = (object)val2;
					}
					UnifiedPopup.Push((PopupBase)new YesNoPopup(removeTitle, text, val, (PopupButtonCallback)obj, false, false));
					return false;
				}
				catch (Exception ex)
				{
					PortalPinsPlugin.Log.LogError((object)("Removing a portal pin failed: " + ex));
					return true;
				}
			}
		}

		private static void Remove(PortalRecord portal)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Remove(portal.Id);
		}

		private unsafe static void Remove(ZDOID portal)
		{
			//IL_000a: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource log = PortalPinsPlugin.Log;
			ZDOID val = portal;
			log.LogInfo((object)("Asking the server to remove the pin of portal " + ((object)(*(ZDOID*)(&val))/*cast due to .constrained prefix*/).ToString() + " for everybody."));
			PortalPinLayer.RequestHide(portal);
		}
	}
	internal static class PortalListUi
	{
		[HarmonyPatch(typeof(ZInput), "GetMouseScrollWheel")]
		private static class BlockZoom
		{
			private static bool Prefix(ref float __result)
			{
				if (!IsOpen)
				{
					return true;
				}
				__result = 0f;
				return false;
			}
		}

		[HarmonyPatch(typeof(TextInput), "RequestText")]
		private static class Requested
		{
			private static void Postfix(TextInput __instance, TextReceiver sign)
			{
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				Close();
				try
				{
					if (ModConfig.ShowPortalList.Value)
					{
						TeleportWorld val = (TeleportWorld)(object)((sign is TeleportWorld) ? sign : null);
						if (val != null && !((Object)(object)__instance.m_inputField == (Object)null) && !((Object)(object)__instance.m_panel == (Object)null) && GUIManager.Instance != null)
						{
							ZNetView nview = val.m_nview;
							_editing = (((Object)(object)nview != (Object)null && nview.IsValid()) ? nview.GetZDO().m_uid : ZDOID.None);
							_sign = val;
							Build(__instance);
						}
					}
				}
				catch (Exception ex)
				{
					PortalPinsPlugin.Log.LogError((object)("Portal list could not be built: " + ex));
					Close();
				}
			}
		}

		[HarmonyPatch(typeof(TextInput), "Hide")]
		private static class Hidden
		{
			private static void Postfix()
			{
				Close();
			}
		}

		[HarmonyPatch(typeof(Minimap), "SetMapMode")]
		private static class MapClosed
		{
			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 || (Object)(object)_reopenFor == (Object)null)
				{
					return;
				}
				TeleportWorld reopenFor = _reopenFor;
				string reopenText = _reopenText;
				_reopenFor = null;
				_reopenText = null;
				try
				{
					ZNetView nview = reopenFor.m_nview;
					if (!((Object)(object)TextInput.instance == (Object)null) && !((Object)(object)nview == (Object)null) && nview.IsValid())
					{
						TextInput.instance.RequestText((TextReceiver)(object)reopenFor, "$piece_portal_tag", 10);
						if (reopenText != null && (Object)(object)TextInput.instance.m_inputField != (Object)null)
						{
							((TMP_InputField)TextInput.instance.m_inputField).text = reopenText;
							((TMP_InputField)TextInput.instance.m_inputField).caretPosition = reopenText.Length;
						}
					}
				}
				catch (Exception ex)
				{
					PortalPinsPlugin.Log.LogError((object)("The portal's tag window could not be opened again: " + ex));
				}
			}
		}

		private const float RowHeight = 30f;

		private const float MaxListHeight = 220f;

		private const float ScrollbarWidth = 10f;

		private const float MarkSize = 22f;

		private const float RowGap = 4f;

		private const int PairBarWidth = 3;

		private const float MapButtonSize = 24f;

		private const float Gap = 10f;

		private static readonly Color Orange = new Color(1f, 0.71f, 0.29f);

		private static readonly Color Hint = new Color(0.78f, 0.72f, 0.62f);

		private static GameObject _list;

		private static GameObject _shade;

		private static RectTransform _content;

		private static ZDOID _editing = ZDOID.None;

		private static TeleportWorld _sign;

		private static TeleportWorld _reopenFor;

		private static string _reopenText;

		private static List<PortalRecord> _all = new List<PortalRecord>();

		private static TextInput _input;

		private static float _rowWidth;

		private static Text _message;

		private static UnityAction<string> _filter;

		private static RectTransform _panel;

		private static Vector2 _panelSize;

		private static Vector2 _panelPosition;

		private static readonly List<RectTransform> Moved = new List<RectTransform>();

		private static readonly List<Vector2> MovedFrom = new List<Vector2>();

		internal static bool IsOpen => (Object)(object)_list != (Object)null;

		private static void Build(TextInput input)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: 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_015b: 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_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Expected O, but got Unknown
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Expected O, but got Unknown
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Expected O, but got Unknown
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Expected O, but got Unknown
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Expected O, but got Unknown
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Expected O, but got Unknown
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Expected O, but got Unknown
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Unknown result type (might be due to invalid IL or missing references)
			//IL_0510: Unknown result type (might be due to invalid IL or missing references)
			//IL_0536: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Expected O, but got Unknown
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0578: Expected O, but got Unknown
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05df: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0602: Expected O, but got Unknown
			//IL_06b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: 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_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			List<PortalRecord> list = Sorted();
			float num = ((list.Count == 0) ? 48f : Mathf.Min(220f, (float)list.Count * 34f + 4f));
			float num2 = num + 20f;
			_panel = (RectTransform)input.m_panel.transform;
			_panelSize = _panel.sizeDelta;
			_panelPosition = _panel.anchoredPosition;
			_panel.sizeDelta = new Vector2(_panelSize.x, _panelSize.y + num2);
			if (Mathf.Approximately(_panel.anchorMin.y, 0.5f) && Mathf.Approximately(_panel.anchorMax.y, 0.5f))
			{
				_panel.anchoredPosition = Vector2.zero;
			}
			Moved.Clear();
			MovedFrom.Clear();
			foreach (Transform item in (Transform)_panel)
			{
				Transform val = item;
				RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
				if (val2 != null && Mathf.Approximately(val2.anchorMin.y, 0.5f) && Mathf.Approximately(val2.anchorMax.y, 0.5f))
				{
					Moved.Add(val2);
					MovedFrom.Add(val2.anchoredPosition);
					val2.anchoredPosition += new Vector2(0f, num2 / 2f);
				}
			}
			Rect rect = _panel.rect;
			float num3 = (0f - ((Rect)(ref rect)).height) / 2f;
			Button[] componentsInChildren = input.m_panel.GetComponentsInChildren<Button>(true);
			foreach (Button val3 in componentsInChildren)
			{
				RectTransform val4 = (RectTransform)((Component)val3).transform;
				if (!((Object)(object)((Transform)val4).parent != (Object)(object)_panel) && Mathf.Approximately(val4.anchorMin.y, 0.5f))
				{
					int num4 = Moved.IndexOf(val4);
					if (num4 < 0)
					{
						Moved.Add(val4);
						MovedFrom.Add(val4.anchoredPosition);
					}
					val4.anchoredPosition -= new Vector2(0f, num2);
					float num5 = num3;
					float y = val4.anchoredPosition.y;
					rect = val4.rect;
					num3 = Mathf.Max(num5, y + ((Rect)(ref rect)).height / 2f);
				}
			}
			_shade = new GameObject("CDEV_PortalListShade", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform val5 = (RectTransform)_shade.transform;
			((Transform)val5).SetParent(((Transform)_panel).parent, false);
			((Transform)val5).SetSiblingIndex(((Transform)_panel).GetSiblingIndex());
			val5.anchorMin = Vector2.zero;
			val5.anchorMax = Vector2.one;
			Vector2 val6 = (val5.offsetMin = (val5.offsetMax = Vector2.zero));
			Image component = _shade.GetComponent<Image>();
			((Graphic)component).color = new Color(0f, 0f, 0f, 0.55f);
			((Graphic)component).raycastTarget = false;
			RectTransform val8 = (RectTransform)((Component)input.m_inputField).transform;
			float y2 = val8.anchoredPosition.y;
			rect = val8.rect;
			float num6 = y2 - ((Rect)(ref rect)).height / 2f - 10f;
			num = Mathf.Max(30f, num6 - num3 - 10f);
			rect = val8.rect;
			float num7;
			if (!(((Rect)(ref rect)).width > 10f))
			{
				num7 = _panelSize.x - 56f;
			}
			else
			{
				rect = val8.rect;
				num7 = ((Rect)(ref rect)).width;
			}
			float num8 = num7;
			_list = new GameObject("CDEV_PortalList", new Type[1] { typeof(RectTransform) });
			RectTransform val9 = (RectTransform)_list.transform;
			((Transform)val9).SetParent((Transform)(object)_panel, false);
			((Vector2)(ref val6))..ctor(0.5f, 0.5f);
			val9.anchorMax = val6;
			val9.anchorMin = val6;
			val9.pivot = new Vector2(0.5f, 1f);
			val9.anchoredPosition = new Vector2(0f, num6);
			val9.sizeDelta = new Vector2(num8, num);
			GameObject val10 = new GameObject("Viewport", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(RectMask2D)
			});
			RectTransform val11 = (RectTransform)val10.transform;
			((Transform)val11).SetParent((Transform)(object)val9, false);
			val11.anchorMin = Vector2.zero;
			val11.anchorMax = Vector2.one;
			val6 = (val11.offsetMin = (val11.offsetMax = Vector2.zero));
			Image component2 = val10.GetComponent<Image>();
			((Graphic)component2).color = new Color(0f, 0f, 0f, 0.25f);
			((Graphic)component2).raycastTarget = true;
			GameObject val13 = new GameObject("Content", new Type[1] { typeof(RectTransform) });
			_content = (RectTransform)val13.transform;
			((Transform)_content).SetParent((Transform)(object)val11, false);
			_content.anchorMin = new Vector2(0f, 1f);
			_content.anchorMax = new Vector2(1f, 1f);
			_content.pivot = new Vector2(0.5f, 1f);
			_content.sizeDelta = new Vector2(-12f, 0f);
			VerticalLayoutGroup val14 = val13.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)val14).padding = new RectOffset(0, 0, 4, 4);
			((HorizontalOrVerticalLayoutGroup)val14).spacing = 4f;
			((HorizontalOrVerticalLayoutGroup)val14).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)val14).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val14).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)val14).childForceExpandWidth = true;
			ContentSizeFitter val15 = val13.AddComponent<ContentSizeFitter>();
			val15.verticalFit = (FitMode)2;
			ScrollRect val16 = _list.AddComponent<ScrollRect>();
			val16.viewport = val11;
			val16.content = _content;
			val16.horizontal = false;
			val16.vertical = true;
			val16.movementType = (MovementType)2;
			val16.scrollSensitivity = 272f;
			val16.verticalScrollbar = Scrollbar(val9);
			val16.verticalScrollbarVisibility = (ScrollbarVisibility)1;
			GameObject val17 = GUIManager.Instance.CreateText("", (Transform)(object)val11, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, GUIManager.Instance.AveriaSerif, 17, Hint, true, Color.black, num8 - 20f, num, false);
			_message = val17.GetComponent<Text>();
			_message.alignment = (TextAnchor)4;
			((Graphic)_message).raycastTarget = false;
			_all = list;
			_input = input;
			_rowWidth = num8;
			Fill(((TMP_InputField)input.m_inputField).text);
			_filter = delegate(string text)
			{
				Fill(text);
			};
			((UnityEvent<string>)(object)((TMP_InputField)input.m_inputField).onValueChanged).AddListener(_filter);
		}

		internal static void Refresh()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			if (!IsOpen || (Object)(object)_input == (Object)null || (Object)(object)_list == (Object)null)
			{
				return;
			}
			try
			{
				List<PortalRecord> list = Sorted();
				float num = ((list.Count == 0) ? 48f : Mathf.Min(220f, (float)list.Count * 34f + 4f));
				Rect rect = ((RectTransform)_list.transform).rect;
				if (!(Mathf.Abs(((Rect)(ref rect)).height - num) < 1f))
				{
					rect = ((RectTransform)_list.transform).rect;
					if (!(((Rect)(ref rect)).height >= 220f) || !(num >= 220f))
					{
						TextInput input = _input;
						Close();
						Build(input);
						return;
					}
				}
				_all = list;
				Fill(((Object)(object)_input.m_inputField != (Object)null) ? ((TMP_InputField)_input.m_inputField).text : "");
			}
			catch (Exception ex)
			{
				PortalPinsPlugin.Log.LogError((object)("Portal list could not be refreshed: " + ex));
				Close();
			}
		}

		private static void Fill(string search)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_0169: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_content == (Object)null || (Object)(object)_input == (Object)null)
			{
				return;
			}
			for (int num = ((Transform)_content).childCount - 1; num >= 0; num--)
			{
				Transform child = ((Transform)_content).GetChild(num);
				child.SetParent((Transform)null, false);
				Object.Destroy((Object)(object)((Component)child).gameObject);
			}
			string text = (search ?? "").Trim();
			int num2 = 0;
			HashSet<ZDOID> hashSet = new HashSet<ZDOID>();
			foreach (PortalRecord item in _all)
			{
				if (!hashSet.Add(item.Id))
				{
					continue;
				}
				bool flag = _editing != ZDOID.None && item.Id == _editing;
				PortalRecord partner = default(PortalRecord);
				bool flag2 = TryGetPartner(item, out partner);
				if (flag2)
				{
					hashSet.Add(partner.Id);
				}
				if (flag || text.Length <= 0 || Matches(item, text) || (flag2 && Matches(partner, text)))
				{
					RectTransform host = (flag2 ? PairBlock() : _content);
					AddRow(_input, item, _rowWidth, host, flag2);
					num2 += ((!flag) ? 1 : 0);
					if (flag2)
					{
						AddRow(_input, partner, _rowWidth, host, inPair: true);
						num2 += ((!(_editing != ZDOID.None) || !(partner.Id == _editing)) ? 1 : 0);
					}
				}
			}
			if ((Object)(object)_message != (Object)null)
			{
				_message.text = ((_all.Count == 0) ? Texts.ListEmpty : ((num2 == 0) ? Texts.NothingFound : ""));
			}
		}

		private static bool Matches(PortalRecord portal, string needle)
		{
			return PortalPinLayer.PortalName(portal).IndexOf(needle, StringComparison.CurrentCultureIgnoreCase) >= 0;
		}

		private static bool TryGetPartner(PortalRecord portal, out PortalRecord partner)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			partner = default(PortalRecord);
			if (portal.Target == ZDOID.None)
			{
				return false;
			}
			foreach (PortalRecord item in _all)
			{
				if (item.Id == portal.Target)
				{
					partner = item;
					return true;
				}
			}
			return false;
		}

		private static RectTransform PairBlock()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_006a: 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_008a: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Pair", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(VerticalLayoutGroup)
			});
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)_content, false);
			((Graphic)val.GetComponent<Image>()).color = new Color(0.32f, 0.24f, 0.12f, 0.45f);
			VerticalLayoutGroup component = val.GetComponent<VerticalLayoutGroup>();
			((LayoutGroup)component).padding = new RectOffset(7, 2, 2, 2);
			((HorizontalOrVerticalLayoutGroup)component).spacing = 1f;
			((HorizontalOrVerticalLayoutGroup)component).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)component).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = true;
			val.AddComponent<LayoutElement>().preferredHeight = 66f;
			GameObject val3 = new GameObject("Bar", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform val4 = (RectTransform)val3.transform;
			((Transform)val4).SetParent((Transform)(object)val2, false);
			val4.anchorMin = new Vector2(0f, 0f);
			val4.anchorMax = new Vector2(0f, 1f);
			val4.pivot = new Vector2(0f, 0.5f);
			val4.offsetMin = new Vector2(2f, 3f);
			val4.offsetMax = new Vector2(5f, -3f);
			val4.sizeDelta = new Vector2(3f, val4.sizeDelta.y);
			Image component2 = val3.GetComponent<Image>();
			((Graphic)component2).color = Orange;
			((Graphic)component2).raycastTarget = false;
			return val2;
		}

		private static Scrollbar Scrollbar(RectTransform parent)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00bc: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_0161: 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)
			GameObject val = new GameObject("Scrollbar", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)parent, false);
			val2.anchorMin = new Vector2(1f, 0f);
			val2.anchorMax = new Vector2(1f, 1f);
			val2.pivot = new Vector2(1f, 0.5f);
			val2.offsetMin = new Vector2(-10f, 0f);
			val2.offsetMax = Vector2.zero;
			GameObject val3 = new GameObject("Sliding Area", new Type[1] { typeof(RectTransform) });
			RectTransform val4 = (RectTransform)val3.transform;
			((Transform)val4).SetParent((Transform)(object)val2, false);
			val4.anchorMin = Vector2.zero;
			val4.anchorMax = Vector2.one;
			Vector2 offsetMin = (val4.offsetMax = Vector2.zero);
			val4.offsetMin = offsetMin;
			GameObject val5 = new GameObject("Handle", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform val6 = (RectTransform)val5.transform;
			((Transform)val6).SetParent((Transform)(object)val4, false);
			val6.anchorMin = Vector2.zero;
			val6.anchorMax = Vector2.one;
			offsetMin = (val6.offsetMax = Vector2.zero);
			val6.offsetMin = offsetMin;
			Scrollbar val7 = val.AddComponent<Scrollbar>();
			val7.handleRect = val6;
			((Selectable)val7).targetGraphic = (Graphic)(object)val5.GetComponent<Image>();
			val7.direction = (Direction)2;
			GUIManager.Instance.ApplyScrollbarStyle(val7);
			return val7;
		}

		private static void AddRow(TextInput input, PortalRecord portal, float width, RectTransform host, bool inPair)
		{
			//IL_0014: 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_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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: 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_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Expected O, but got Unknown
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Expected O, but got Unknown
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Expected O, but got Unknown
			string text = PortalPinLayer.PortalName(portal);
			bool flag = _editing != ZDOID.None && portal.Id == _editing;
			bool flag2 = !flag && !string.IsNullOrEmpty((portal.Tag ?? "").Trim());
			GameObject val = new GameObject("Row", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)host, false);
			val.AddComponent<LayoutElement>().preferredHeight = 30f;
			Image component = val.GetComponent<Image>();
			((Graphic)component).color = (inPair ? new Color(0f, 0f, 0f, 0.2f) : new Color(0f, 0f, 0f, 0.32f));
			Button component2 = val.GetComponent<Button>();
			((Selectable)component2).targetGraphic = (Graphic)(object)component;
			ColorBlock colors = ((Selectable)component2).colors;
			((ColorBlock)(ref colors)).normalColor = Color.white;
			((ColorBlock)(ref colors)).highlightedColor = new Color(2.2f, 1.9f, 1.3f, 1.4f);
			((ColorBlock)(ref colors)).pressedColor = new Color(1.6f, 1.4f, 1f, 1.6f);
			((ColorBlock)(ref colors)).selectedColor = Color.white;
			((ColorBlock)(ref colors)).disabledColor = new Color(1f, 1f, 1f, 0.6f);
			((ColorBlock)(ref colors)).fadeDuration = 0.05f;
			((Selectable)component2).colors = colors;
			string text2 = (flag ? ("  (" + Texts.ThisPortal + ")") : (IsPartnerOfEdited(portal) ? ("  (" + Texts.PartnerPortal + ")") : ""));
			GameObject val3 = GUIManager.Instance.CreateText(text + text2, (Transform)(object)val2, new Vector2(0f, 0.5f), new Vector2(0f, 0.5f), new Vector2(10f, 0f), GUIManager.Instance.AveriaSerif, 15, (Color)(flag2 ? new Color(0.95f, 0.9f, 0.82f) : Hint), true, Color.black, width - 22f - 24f - 56f - (float)(inPair ? 9 : 0), 30f, false);
			((RectTransform)val3.transform).pivot = new Vector2(0f, 0.5f);
			Text component3 = val3.GetComponent<Text>();
			component3.alignment = (TextAnchor)3;
			component3.horizontalOverflow = (HorizontalWrapMode)0;
			((Graphic)component3).raycastTarget = false;
			GameObject val4 = new GameObject("Mark", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform val5 = (RectTransform)val4.transform;
			((Transform)val5).SetParent((Transform)(object)val2, false);
			Vector2 val6 = default(Vector2);
			((Vector2)(ref val6))..ctor(1f, 0.5f);
			val5.anchorMax = val6;
			val5.anchorMin = val6;
			val5.pivot = new Vector2(1f, 0.5f);
			val5.anchoredPosition = new Vector2(-10f, 0f);
			val5.sizeDelta = new Vector2(22f, 22f);
			Image component4 = val4.GetComponent<Image>();
			component4.sprite = PortalIcon();
			component4.preserveAspect = true;
			((Graphic)component4).raycastTarget = false;
			((Graphic)component4).color = (Color)(portal.Linked ? Color.white : new Color(0.93f, 0.33f, 0.28f));
			((Behaviour)component4).enabled = (Object)(object)component4.sprite != (Object)null;
			((Graphic)component4).raycastTarget = true;
			GameObject val7 = TooltipPrefab();
			if ((Object)(object)val7 != (Object)null)
			{
				UITooltip val8 = val4.AddComponent<UITooltip>();
				val8.m_tooltipPrefab = val7;
				val8.m_topic = text;
				val8.m_text = (portal.Linked ? LinkedText(portal) : Texts.TooltipNotLinked);
			}
			AddMapButton(val2, portal);
			((Selectable)component2).interactable = flag2;
			if (!flag2)
			{
				return;
			}
			string tag = portal.Tag;
			((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
			{
				if (!((Object)(object)input.m_inputField == (Object)null))
				{
					((TMP_InputField)input.m_inputField).text = tag;
					input.m_inputField.ActivateInputField();
					((TMP_InputField)input.m_inputField).caretPosition = ((TMP_InputField)input.m_inputField).text.Length;
				}
			});
		}

		private static void AddMapButton(RectTransform row, PortalRecord portal)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0065: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			GameObject val = new GameObject("ShowOnMap", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)row, false);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(1f, 0.5f);
			val2.anchorMax = val3;
			val2.anchorMin = val3;
			val2.pivot = new Vector2(1f, 0.5f);
			val2.anchoredPosition = new Vector2(-40f, 0f);
			val2.sizeDelta = new Vector2(24f, 24f);
			Image component = val.GetComponent<Image>();
			component.sprite = Icons.MapPin();
			component.preserveAspect = true;
			((Graphic)component).color = new Color(0.85f, 0.8f, 0.7f, 0.85f);
			Button component2 = val.GetComponent<Button>();
			((Selectable)component2).targetGraphic = (Graphic)(object)component;
			ColorBlock colors = ((Selectable)component2).colors;
			((ColorBlock)(ref colors)).normalColor = Color.white;
			((ColorBlock)(ref colors)).highlightedColor = new Color(1.4f, 1.25f, 0.9f, 1.4f);
			((ColorBlock)(ref colors)).pressedColor = new Color(1f, 0.9f, 0.7f, 1.6f);
			((ColorBlock)(ref colors)).fadeDuration = 0.05f;
			((Selectable)component2).colors = colors;
			GameObject val4 = TooltipPrefab();
			if ((Object)(object)val4 != (Object)null)
			{
				UITooltip val5 = val.AddComponent<UITooltip>();
				val5.m_tooltipPrefab = val4;
				val5.m_topic = Texts.ShowOnMap;
				val5.m_text = Texts.ShowOnMapText;
			}
			PortalRecord target = portal;
			((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
			{
				_reopenFor = _sign;
				_reopenText = (((Object)(object)TextInput.instance != (Object)null && (Object)(object)TextInput.instance.m_inputField != (Object)null) ? ((TMP_InputField)TextInput.instance.m_inputField).text : null);
				if ((Object)(object)TextInput.instance != (Object)null)
				{
					TextInput.instance.Hide();
				}
				PortalPinLayer.ShowOnMap(target);
			});
		}

		private static bool IsPartnerOfEdited(PortalRecord portal)
		{
			//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_0012: 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_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_004f: 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_0061: 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)
			if (_editing == ZDOID.None || portal.Target == ZDOID.None)
			{
				return false;
			}
			if (portal.Target == _editing)
			{
				return true;
			}
			foreach (PortalRecord item in _all)
			{
				if (item.Id == _editing)
				{
					return item.Target == portal.Id;
				}
			}
			return false;
		}

		private static string LinkedText(PortalRecord portal)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			foreach (PortalRecord item in _all)
			{
				if (item.Id == portal.Target)
				{
					return Texts.TooltipLinkedTo(PortalPinLayer.PortalName(item));
				}
			}
			return Texts.TooltipLinked;
		}

		private static GameObject TooltipPrefab()
		{
			InventoryGrid val = (((Object)(object)InventoryGui.instance != (Object)null) ? InventoryGui.instance.m_playerGrid : null);
			UITooltip val2 = (((Object)(object)val != (Object)null && (Object)(object)val.m_elementPrefab != (Object)null) ? val.m_elementPrefab.GetComponent<UITooltip>() : null);
			if (!((Object)(object)val2 != (Object)null))
			{
				return null;
			}
			return val2.m_tooltipPrefab;
		}

		private static Sprite PortalIcon()
		{
			Minimap instance = Minimap.instance;
			if (!((Object)(object)instance != (Object)null))
			{
				return null;
			}
			return instance.GetSprite((PinType)6);
		}

		private static List<PortalRecord> Sorted()
		{
			List<PortalRecord> list = new List<PortalRecord>(PortalPinLayer.Current);
			list.Sort(delegate(PortalRecord a, PortalRecord b)
			{
				//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_0012: 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_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_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				bool flag = _editing != ZDOID.None && a.Id == _editing;
				bool flag2 = _editing != ZDOID.None && b.Id == _editing;
				if (flag != flag2)
				{
					if (!flag)
					{
						return 1;
					}
					return -1;
				}
				if (a.Linked != b.Linked)
				{
					if (!a.Linked)
					{
						return -1;
					}
					return 1;
				}
				int num = string.Compare(PortalPinLayer.PortalName(a), PortalPinLayer.PortalName(b), StringComparison.CurrentCultureIgnoreCase);
				return (num == 0) ? ((ZDOID)(ref a.Id)).ID.CompareTo(((ZDOID)(ref b.Id)).ID) : num;
			});
			return list;
		}

		internal static void Close()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_list != (Object)null)
			{
				Object.Destroy((Object)(object)_list);
			}
			if ((Object)(object)_shade != (Object)null)
			{
				Object.Destroy((Object)(object)_shade);
			}
			if ((Object)(object)_input != (Object)null && (Object)(object)_input.m_inputField != (Object)null && _filter != null)
			{
				((UnityEvent<string>)(object)((TMP_InputField)_input.m_inputField).onValueChanged).RemoveListener(_filter);
			}
			_list = null;
			_shade = null;
			_content = null;
			_message = null;
			_input = null;
			_filter = null;
			_sign = null;
			_all = new List<PortalRecord>();
			_editing = ZDOID.None;
			for (int i = 0; i < Moved.Count; i++)
			{
				if ((Object)(object)Moved[i] != (Object)null)
				{
					Moved[i].anchoredPosition = MovedFrom[i];
				}
			}
			Moved.Clear();
			MovedFrom.Clear();
			if ((Object)(object)_panel != (Object)null)
			{
				_panel.sizeDelta = _panelSize;
				_panel.anchoredPosition = _panelPosition;
			}
			_panel = null;
		}
	}
	internal static class PortalPinLayer
	{
		private sealed class Entry
		{
			public PortalRecord Record;

			public string Name;

			public PinData Pin;
		}

		private const float GuardInterval = 2f;

		private const float RequestInterval = 10f;

		private const float PulseSeconds = 6f;

		private static ZDOID _pulse = ZDOID.None;

		private static float _pulseUntil;

		private static readonly Dictionary<ZDOID, Entry> Entries = new Dictionary<ZDOID, Entry>();

		private static readonly List<PortalRecord> Incoming = new List<PortalRecord>();

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

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

		internal static readonly List<PortalRecord> Current = new List<PortalRecord>();

		private static Minimap _minimap;

		private static bool _received;

		private static float _nextRequestAt;

		private static float _nextGuardAt;

		internal static int Count => Entries.Count;

		internal static bool Received
		{
			get
			{
				return _received;
			}
			set
			{
				_received = value;
			}
		}

		internal static int HiddenCount
		{
			get
			{
				int num = 0;
				foreach (Entry value in Entries.Values)
				{
					num += (value.Record.Hidden ? 1 : 0);
				}
				return num;
			}
		}

		internal static void Reset()
		{
			Entries.Clear();
			Current.Clear();
			_minimap = null;
			_received = false;
			_nextRequestAt = 0f;
			_nextGuardAt = 0f;
		}

		internal static bool TryGetPin(ZDOID id, out PinData pin)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			pin = (Entries.TryGetValue(id, out var value) ? value.Pin : null);
			return pin != null;
		}

		internal static void Tick()
		{
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null || instance.IsDedicated())
			{
				return;
			}
			try
			{
				if (!_received && !instance.IsServer() && Time.time >= _nextRequestAt)
				{
					_nextRequestAt = Time.time + 10f;
					RequestList();
				}
				if (Time.time >= _nextGuardAt)
				{
					_nextGuardAt = Time.time + 2f;
					Guard();
				}
			}
			catch (Exception arg)
			{
				PortalPinsPlugin.Log.LogError((object)$"Portal pin update failed: {arg}");
				_nextGuardAt = Time.time + 30f;
			}
		}

		internal static void OnList(long sender, ZPackage pkg)
		{
			try
			{
				ZRoutedRpc instance = ZRoutedRpc.instance;
				if (!((Object)(object)ZNet.instance == (Object)null) && !ZNet.instance.IsServer() && instance != null && sender == instance.GetServerPeerID())
				{
					if (!Protocol.TryReadList(pkg, Incoming, out var error))
					{
						PortalPinsPlugin.Log.LogWarning((object)("Dropped the portal list from the server: " + error + " (other mod version?)."));
					}
					else
					{
						Apply(Incoming);
					}
				}
			}
			catch (Exception arg)
			{
				PortalPinsPlugin.Log.LogError((object)$"Handling the portal list failed: {arg}");
			}
		}

		internal static void Apply(List<PortalRecord> portals)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			_received = true;
			if (portals != Current)
			{
				Current.Clear();
				Current.AddRange(portals);
			}
			Minimap map = CurrentMinimap();
			Seen.Clear();
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			foreach (PortalRecord portal in portals)
			{
				if (!Seen.Add(portal.Id))
				{
					continue;
				}
				string text = DisplayName(portal);
				if (Entries.TryGetValue(portal.Id, out var value))
				{
					if (value.Name == text && value.Record.Position == portal.Position && value.Record.Hidden == portal.Hidden)
					{
						value.Record = portal;
						continue;
					}
					RemovePin(map, value);
					num2++;
				}
				else
				{
					value = new Entry();
					Entries.Add(portal.Id, value);
					num++;
				}
				value.Record = portal;
				value.Name = text;
				AddPin(map, value);
			}
			Gone.Clear();
			foreach (KeyValuePair<ZDOID, Entry> entry in Entries)
			{
				if (!Seen.Contains(entry.Key))
				{
					Gone.Add(entry.Key);
				}
			}
			foreach (ZDOID item in Gone)
			{
				RemovePin(map, Entries[item]);
				Entries.Remove(item);
				num3++;
			}
			if (num + num2 + num3 > 0)
			{
				PortalPinsPlugin.Log.LogInfo((object)$"Portal pins: {Entries.Count} ({num} added, {num2} changed, {num3} removed).");
			}
			PortalListUi.Refresh();
		}

		internal static int Guard()
		{
			Minimap val = CurrentMinimap();
			if ((Object)(object)val == (Object)null)
			{
				return 0;
			}
			int num = 0;
			foreach (Entry value in Entries.Values)
			{
				if (!value.Record.Hidden && (value.Pin == null || !val.m_pins.Contains(value.Pin)))
				{
					AddPin(val, value);
					num++;
				}
			}
			return num;
		}

		private static Minimap CurrentMinimap()
		{
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance != (Object)(object)_minimap)
			{
				_minimap = instance;
				foreach (Entry value in Entries.Values)
				{
					value.Pin = null;
				}
			}
			return instance;
		}

		private static void AddPin(Minimap map, Entry entry)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)map == (Object)null || entry.Record.Hidden)
			{
				entry.Pin = null;
			}
			else
			{
				entry.Pin = map.AddPin(entry.Record.Position, (PinType)6, entry.Name, false, false, 0L, default(PlatformUserID));
			}
		}

		internal static void ShowOnMap(PortalRecord portal)
		{
			if (!((Object)(object)Minimap.instance == (Object)null) && !((Object)(object)PortalPinsPlugin.Instance == (Object)null))
			{
				((MonoBehaviour)PortalPinsPlugin.Instance).StartCoroutine(Focus(portal));
			}
		}

		private static IEnumerator Focus(PortalRecord portal)
		{
			yield return null;
			Minimap map = Minimap.instance;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)map == (Object)null || (Object)(object)localPlayer == (Object)null)
			{
				yield break;
			}
			map.ShowPointOnMap(portal.Position);
			map.LargeZoom = Mathf.Clamp(map.m_minZoom * 1.1f * 1.1f, map.m_minZoom, map.m_maxZoom);
			_pulse = portal.Id;
			_pulseUntil = Time.time + 6f;
			for (int i = 0; i < 3; i++)
			{
				if (!((Object)(object)Player.m_localPlayer != (Object)null))
				{
					break;
				}
				map.m_mapOffset = portal.Position - ((Component)Player.m_localPlayer).transform.position;
				yield return null;
			}
		}

		internal static void AnimatePulse()
		{
			//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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			if (_pulse == ZDOID.None)
			{
				return;
			}
			if (Time.time >= _pulseUntil)
			{
				StopPulse();
				return;
			}
			Image val = PulseIcon();
			if (!((Object)(object)val == (Object)null))
			{
				float num = 0.5f + 0.5f * Mathf.Sin(Time.time * 6f);
				((Transform)((Graphic)val).rectTransform).localScale = Vector3.one * (1f + 0.45f * num);
				((Graphic)val).color = Color.Lerp(Color.white, new Color(1f, 0.72f, 0.2f), num);
			}
		}

		internal static void AfterUpdatePins()
		{
			//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)
			if (_pulse != ZDOID.None && Time.time < _pulseUntil)
			{
				AnimatePulse();
			}
		}

		private static void StopPulse()
		{
			//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_0015: 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)
			Image val = PulseIcon();
			if ((Object)(object)val != (Object)null)
			{
				((Transform)((Graphic)val).rectTransform).localScale = Vector3.one;
				((Graphic)val).color = Color.white;
			}
			_pulse = ZDOID.None;
		}

		private static Image PulseIcon()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (!TryGetPin(_pulse, out var pin))
			{
				return null;
			}
			return pin.m_iconElement;
		}

		internal static void RequestHide(ZDOID portal)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null)
			{
				ZPackage val = new ZPackage();
				val.Write(3);
				val.Write(portal);
				val.Write(true);
				instance.InvokeRoutedRPC(instance.GetServerPeerID(), "CDEV_PortalPins_Hide", new object[1] { val });
			}
		}

		internal static void OnHideResult(long sender, ZPackage pkg)
		{
			try
			{
				ZRoutedRpc instance = ZRoutedRpc.instance;
				if (instance != null && sender == instance.GetServerPeerID() && pkg.ReadInt() == 3)
				{
					pkg.ReadBool();
					Texts.Message(Texts.ForHideCode(pkg.ReadString()));
				}
			}
			catch (Exception ex)
			{
				PortalPinsPlugin.Log.LogWarning((object)("Could not read the answer about a portal pin: " + ex.Message));
			}
		}

		internal static bool TryGetPortalAt(Vector3 world, float radius, out PortalRecord portal)
		{
			//IL_008f: 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)
			portal = default(PortalRecord);
			Minimap instance = Minimap.instance;
			float num = radius;
			bool result = false;
			foreach (Entry value in Entries.Values)
			{
				if (!value.Record.Hidden && value.Pin != null && !((Object)(object)instance == (Object)null) && instance.m_pins.Contains(value.Pin) && (!((Object)(object)value.Pin.m_uiElement != (Object)null) || ((Component)value.Pin.m_uiElement).gameObject.activeInHierarchy))
				{
					float num2 = Utils.DistanceXZ(world, value.Record.Position);
					if (num2 < num)
					{
						num = num2;
						portal = value.Record;
						result = true;
					}
				}
			}
			return result;
		}

		private static void RemovePin(Minimap map, Entry entry)
		{
			if ((Object)(object)map != (Object)null && entry.Pin != null)
			{
				map.RemovePin(entry.Pin);
			}
			entry.Pin = null;
		}

		private static void RequestList()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			ZRoutedRpc instance = ZRoutedRpc.instance;
			ZNetPeer serverPeer = ZNet.instance.GetServerPeer();
			if (instance != null && serverPeer != null && serverPeer.IsReady() && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				ZPackage val = new ZPackage();
				val.Write(3);
				instance.InvokeRoutedRPC(instance.GetServerPeerID(), "CDEV_PortalPins_Request", new object[1] { val });
			}
		}

		internal static string DisplayName(PortalRecord portal)
		{
			string text = ((ModConfig.NamePrefix != null) ? (ModConfig.NamePrefix.Value ?? "") : "");
			return text + PortalName(portal);
		}

		internal static string PortalName(PortalRecord portal)
		{
			//IL_0055: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			string text = portal.Tag ?? "";
			if (text.Trim().Length == 0)
			{
				if (Localization.instance == null)
				{
					return "Portal";
				}
				return Localization.instance.Localize("$piece_portal");
			}
			try
			{
				PlatformUserID val = (PlatformUserID)(string.IsNullOrEmpty(portal.Author) ? PlatformUserID.None : new PlatformUserID(portal.Author));
				return CensorShittyWords.FilterUGC(text, (UGCType)4, val, 0L, (GetUserProfileCompletedHandler)null);
			}
			catch (Exception)
			{
				return text;
			}
		}
	}
	internal static class Texts
	{
		private static bool Ru
		{
			get
			{
				if (Localization.instance != null)
				{
					return Localization.instance.GetSelectedLanguage() == "Russian";
				}
				return false;
			}
		}

		internal static string RemoveTitle
		{
			get
			{
				if (!Ru)
				{
					return "Remove portal pin";
				}
				return "Убрать метку портала";
			}
		}

		internal static string ListTitle
		{
			get
			{
				if (!Ru)
				{
					return "Portals of the world";
				}
				return "Порталы мира";
			}
		}

		internal static string Linked
		{
			get
			{
				if (!Ru)
				{
					return "linked";
				}
				return "связан";
			}
		}

		internal static string Unlinked
		{
			get
			{
				if (!Ru)
				{
					return "not linked";
				}
				return "не связан";
			}
		}

		internal static string ListEmpty
		{
			get
			{
				if (!Ru)
				{
					return "No other portals yet";
				}
				return "Других порталов пока нет";
			}
		}

		internal static string NothingFound
		{
			get
			{
				if (!Ru)
				{
					return "Nothing found";
				}
				return "Ничего не найдено";
			}
		}

		internal static string ThisPortal
		{
			get
			{
				if (!Ru)
				{
					return "this portal";
				}
				return "этот портал";
			}
		}

		internal static string PartnerPortal
		{
			get
			{
				if (!Ru)
				{
					return "its partner";
				}
				return "пара этого";
			}
		}

		internal static string TooltipLinked
		{
			get
			{
				if (!Ru)
				{
					return "Linked to another portal";
				}
				return "Связан с другим порталом";
			}
		}

		internal static string ShowOnMap
		{
			get
			{
				if (!Ru)
				{
					return "Show on the map";
				}
				return "Показать на карте";
			}
		}

		internal static string ShowOnMapText
		{
			get
			{
				if (!Ru)
				{
					return "Opens the map on this portal; its pin blinks for a few seconds.";
				}
				return "Откроет карту на этом портале, его метка несколько секунд помигает.";
			}
		}

		internal static string TooltipNotLinked
		{
			get
			{
				if (!Ru)
				{
					return "Linked to nothing. Give two portals the same name and they pair up.";
				}
				return "Ни с чем не связан. Дайте двум порталам одинаковое имя, и они соединятся.";
			}
		}

		internal static string RemoveQuestion(string name)
		{
			if (!Ru)
			{
				return "<color=#FFD27F>" + Clean(name) + "</color>\nThe pin disappears for every player. The portal itself stays.";
			}
			return "<color=#FFD27F>" + Clean(name) + "</color>\nМетка пропадёт у всех игроков. Сам портал останется.";
		}

		internal static string ForHideCode(string code)
		{
			switch (code)
			{
			case "hidden":
				if (!Ru)
				{
					return "Portal pin removed for everybody";
				}
				return "Метка портала убрана у всех";
			case "denied":
				if (!Ru)
				{
					return "Only an admin may remove portal pins";
				}
				return "Убирать метки порталов может только админ";
			case "off":
				if (!Ru)
				{
					return "Portal pins cannot be removed on this server";
				}
				return "На этом сервере метки порталов убирать нельзя";
			case "unknown":
				if (!Ru)
				{
					return "That portal is gone";
				}
				return "Этого портала уже нет";
			default:
				if (!Ru)
				{
					return "The server did not change the portal pin";
				}
				return "Сервер не изменил метку портала";
			}
		}

		internal static string TooltipLinkedTo(string name)
		{
			if (!Ru)
			{
				return "Linked to the portal \"" + Clean(name) + "\"";
			}
			return "Связан с порталом «" + Clean(name) + "»";
		}

		internal static void Message(string text)
		{
			if ((Object)(object)MessageHud.instance != (Object)null)
			{
				MessageHud.instance.ShowMessage((MessageType)1, text, 0, (Sprite)null, true, false);
			}
		}

		private static string Clean(string text)
		{
			return (text ?? "").Replace('<', ' ').Replace('>', ' ');
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}