Decompiled source of Portal Atlas Map v0.2.10

BepInEx/plugins/OctoberJemini-Portal_Atlas_Map/PortalAtlas.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OctoberJemini.PortalAtlas
{
	[Serializable]
	public sealed class AtlasWorldData
	{
		public int version = 1;

		public List<BiomeCounter> counters = new List<BiomeCounter>();

		public List<AtlasName> names = new List<AtlasName>();

		public void Observe(string biome, int number)
		{
			BiomeCounter biomeCounter = counters.FirstOrDefault((BiomeCounter c) => c.biome == biome);
			if (biomeCounter == null)
			{
				biomeCounter = new BiomeCounter
				{
					biome = biome
				};
				counters.Add(biomeCounter);
			}
			biomeCounter.last = Math.Max(biomeCounter.last, number);
		}

		public int Next(string biome)
		{
			Observe(biome, 0);
			BiomeCounter biomeCounter = counters.First((BiomeCounter c) => c.biome == biome);
			checked
			{
				biomeCounter.last++;
				return biomeCounter.last;
			}
		}

		public AtlasName Find(string id)
		{
			return names.FirstOrDefault((AtlasName n) => n.id == id);
		}

		public AtlasName Assign(string id, string biome, int savedNumber, string savedName)
		{
			AtlasName atlasName = Find(id);
			if (atlasName != null)
			{
				Observe(atlasName.biome, atlasName.number);
				return atlasName;
			}
			int number = ((savedNumber > 0) ? savedNumber : Next(biome));
			Observe(biome, number);
			atlasName = new AtlasName
			{
				id = id,
				biome = biome,
				number = number,
				label = Clean(savedName)
			};
			names.Add(atlasName);
			return atlasName;
		}

		public static string DefaultName(string biome, int number)
		{
			return "Atlas-" + number.ToString("D3", CultureInfo.InvariantCulture);
		}

		public static string WithBiome(string name, string biome)
		{
			string text = " (" + biome + ")";
			if (!(name ?? "").EndsWith(text, StringComparison.OrdinalIgnoreCase))
			{
				return name + text;
			}
			return name;
		}

		public static string Clean(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return "";
			}
			return new string(value.Where((char c) => !char.IsControl(c) && c != '<' && c != '>').Take(48).ToArray()).Trim();
		}

		public static bool Search(string label, string biome, string query)
		{
			if (!string.IsNullOrWhiteSpace(query))
			{
				return (label + " " + biome).IndexOf(query.Trim(), StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return true;
		}
	}
	[Serializable]
	public sealed class BiomeCounter
	{
		public string biome = "";

		public int last;
	}
	[Serializable]
	public sealed class AtlasName
	{
		public string id = "";

		public string biome = "";

		public int number;

		public string label = "";

		public string Display
		{
			get
			{
				if (!string.IsNullOrEmpty(label))
				{
					return label;
				}
				return AtlasWorldData.DefaultName(biome, number);
			}
		}
	}
	internal sealed class Destination
	{
		internal string id;

		internal string name;

		internal string biome;

		internal bool pillar;

		internal bool allowAll;

		internal Vector3 position;

		internal Quaternion rotation;

		internal float exit;

		internal ZDOID Uid => AtlasNetwork.ParseId(id);
	}
	internal sealed class AtlasNetwork
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static CoroutineHandler <0>__Ignore;
		}

		private CustomRPC request;

		private CustomRPC response;

		private CustomRPC registerPillar;

		private long world;

		private AtlasWorldData data;

		private string file;

		private bool dirty;

		private bool storageFailed;

		private bool scanActive;

		private bool refreshAfterRename;

		private bool firstScan = true;

		private float nextScan;

		private float nextRefresh;

		private float nextSave;

		private float nextRequest;

		private int scanIndex;

		private int nonce;

		private int pendingTravel;

		private float travelDeadline;

		private readonly List<ZDO> scan = new List<ZDO>();

		private readonly HashSet<ZDOID> pillars = new HashSet<ZDOID>();

		private readonly Dictionary<string, Destination> authoritative = new Dictionary<string, Destination>();

		private readonly Dictionary<string, float> limits = new Dictionary<string, float>();

		internal readonly List<Destination> Destinations = new List<Destination>();

		private string signature = "";

		private static readonly MethodInfo ServerMethod = typeof(ZRoutedRpc).GetMethod("GetServerPeerID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		internal int Revision { get; private set; }

		internal static long ServerPeer
		{
			get
			{
				if (ZRoutedRpc.instance != null)
				{
					return (long)ServerMethod.Invoke(ZRoutedRpc.instance, null);
				}
				return 0L;
			}
		}

		internal static string Id(ZDOID id)
		{
			return ((ZDOID)(ref id)).UserID.ToString(CultureInfo.InvariantCulture) + ":" + ((ZDOID)(ref id)).ID.ToString(CultureInfo.InvariantCulture);
		}

		internal static ZDOID ParseId(string value)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			string[] array = (value ?? "").Split(new char[1] { ':' });
			if (array.Length != 2 || !long.TryParse(array[0], out var result) || !uint.TryParse(array[1], out var result2))
			{
				return ZDOID.None;
			}
			return new ZDOID(result, result2);
		}

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

		internal void Register()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_00af: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			NetworkManager instance = NetworkManager.Instance;
			CoroutineHandler val = OnRequest;
			object obj = <>O.<0>__Ignore;
			if (obj == null)
			{
				CoroutineHandler val2 = Ignore;
				<>O.<0>__Ignore = val2;
				obj = (object)val2;
			}
			request = instance.AddRPC("OCT_PortalAtlas_Request", val, (CoroutineHandler)obj);
			NetworkManager instance2 = NetworkManager.Instance;
			object obj2 = <>O.<0>__Ignore;
			if (obj2 == null)
			{
				CoroutineHandler val3 = Ignore;
				<>O.<0>__Ignore = val3;
				obj2 = (object)val3;
			}
			response = instance2.AddRPC("OCT_PortalAtlas_Response", (CoroutineHandler)obj2, new CoroutineHandler(OnResponse));
			NetworkManager instance3 = NetworkManager.Instance;
			CoroutineHandler val4 = OnRegisterPillar;
			object obj3 = <>O.<0>__Ignore;
			if (obj3 == null)
			{
				CoroutineHandler val5 = Ignore;
				<>O.<0>__Ignore = val5;
				obj3 = (object)val5;
			}
			registerPillar = instance3.AddRPC("OCT_PortalAtlas_RegisterPillar", val4, (CoroutineHandler)obj3);
		}

		private IEnumerator OnRegisterPillar(long sender, ZPackage package)
		{
			try
			{
				if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer() || ZNet.instance.GetPeer(sender) == null || package.ReadLong() != world)
				{
					yield break;
				}
				string key = "register:" + sender;
				if (!limits.TryGetValue(key, out var value) || Time.unscaledTime >= value)
				{
					limits[key] = Time.unscaledTime + 0.05f;
					ZDO zDO = ZDOMan.instance.GetZDO(ParseId(package.ReadString()));
					if (zDO != null && zDO.GetOwner() == sender)
					{
						Track(zDO);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("Rejected malformed pillar registration: " + ex.Message);
			}
		}

		internal void RegisterPillar(ZDO zdo)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)ZNet.instance) && zdo != null)
			{
				if (ZNet.instance.IsServer())
				{
					Track(zdo);
					return;
				}
				ZPackage val = new ZPackage();
				val.Write(ZNet.instance.GetWorldUID());
				val.Write(Id(zdo.m_uid));
				registerPillar.SendPackage(ServerPeer, val);
			}
		}

		private static IEnumerator Ignore(long sender, ZPackage package)
		{
			yield break;
		}

		private IEnumerator OnRequest(long sender, ZPackage package)
		{
			try
			{
				if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer())
				{
					ProcessRequest(sender, package);
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("Rejected malformed Atlas request: " + ex.Message);
			}
			yield break;
		}

		private IEnumerator OnResponse(long sender, ZPackage package)
		{
			try
			{
				if (sender == ServerPeer)
				{
					Receive(package);
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("Rejected malformed Atlas response: " + ex.Message);
			}
			yield break;
		}

		internal void Tick()
		{
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || ZDOMan.instance == null || ZNet.instance.GetWorldUID() == 0L)
			{
				if (world != 0L)
				{
					Reset();
				}
				return;
			}
			long worldUID = ZNet.instance.GetWorldUID();
			if (world != worldUID)
			{
				Reset();
				world = worldUID;
				if (ZNet.instance.IsServer())
				{
					Load();
				}
			}
			if (ZNet.instance.IsServer())
			{
				if (!scanActive && Time.unscaledTime >= nextScan)
				{
					scanActive = true;
					scanIndex = 0;
					scan.Clear();
					nextScan = Time.unscaledTime + 30f;
				}
				if (scanActive && ZDOMan.instance.GetAllZDOsWithPrefabIterative("OCT_AtlasPillar", scan, ref scanIndex))
				{
					foreach (ZDO item in scan)
					{
						pillars.Add(item.m_uid);
						data.Observe(item.GetString("oct_atlas_biome", Biome(item.GetPosition())), item.GetInt("oct_atlas_number", 0));
					}
					scanActive = false;
					firstScan = false;
					nextRefresh = 0f;
				}
				if (Time.unscaledTime >= nextRefresh)
				{
					nextRefresh = Time.unscaledTime + 2f;
					Refresh();
				}
				if (dirty && Time.unscaledTime >= nextSave)
				{
					Save();
					nextSave = Time.unscaledTime + 5f;
				}
			}
			if (refreshAfterRename)
			{
				RequestList();
			}
			if (pendingTravel != 0 && Time.unscaledTime > travelDeadline)
			{
				pendingTravel = 0;
				Plugin.Notice("Atlas travel request timed out. Please try again.");
			}
		}

		private void Reset()
		{
			Save();
			world = 0L;
			data = null;
			file = null;
			dirty = false;
			storageFailed = false;
			pillars.Clear();
			authoritative.Clear();
			Destinations.Clear();
			scan.Clear();
			limits.Clear();
			scanActive = false;
			refreshAfterRename = false;
			scanIndex = 0;
			firstScan = true;
			nextScan = (nextRefresh = (nextRequest = 0f));
			pendingTravel = 0;
			signature = "";
			Revision++;
		}

		private void Load()
		{
			file = Path.Combine(Paths.ConfigPath, "OctoberJemini.PortalAtlas", "world-" + world + ".json");
			data = new AtlasWorldData();
			if (!File.Exists(file))
			{
				return;
			}
			try
			{
				AtlasWorldData atlasWorldData = JsonUtility.FromJson<AtlasWorldData>(File.ReadAllText(file));
				if (atlasWorldData == null || atlasWorldData.names == null || atlasWorldData.counters == null || atlasWorldData.version != 1)
				{
					throw new InvalidDataException("Unsupported or invalid save data");
				}
				data = atlasWorldData;
				foreach (AtlasName name in data.names)
				{
					data.Observe(name.biome, name.number);
				}
			}
			catch (Exception ex)
			{
				storageFailed = true;
				Plugin.Warn("Atlas naming data needs recovery; original file preserved: " + file + " " + ex.Message);
			}
		}

		internal void Save()
		{
			if (!dirty || data == null || string.IsNullOrEmpty(file) || storageFailed)
			{
				return;
			}
			try
			{
				Directory.CreateDirectory(Path.GetDirectoryName(file));
				string text = file + ".tmp";
				File.WriteAllText(text, JsonUtility.ToJson((object)data, true));
				if (File.Exists(file))
				{
					File.Replace(text, file, file + ".bak");
				}
				else
				{
					File.Move(text, file);
				}
				dirty = false;
			}
			catch (Exception ex)
			{
				Plugin.Warn("Could not save Atlas names: " + ex.Message);
			}
		}

		private void Refresh()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			if (data == null || !Object.op_Implicit((Object)(object)Game.instance) || WorldGenerator.instance == null)
			{
				return;
			}
			authoritative.Clear();
			foreach (ZDO portal in ZDOMan.instance.GetPortalList())
			{
				if (portal != null && Game.instance.PortalPrefabHash.Contains(portal.GetPrefab()))
				{
					string text = Id(portal.m_uid);
					AtlasName atlasName = data.Find(text);
					string biome = Biome(portal.GetPosition());
					string value = ((atlasName != null && atlasName.label.Length > 0) ? atlasName.label : portal.GetString(ZDOVars.s_tag, ""));
					if (string.IsNullOrWhiteSpace(value))
					{
						value = "Unnamed portal";
					}
					GameObject val = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.GetPrefab(portal.GetPrefab()) : null);
					TeleportWorld val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<TeleportWorld>() : null);
					authoritative[text] = new Destination
					{
						id = text,
						name = AtlasWorldData.Clean(value),
						biome = biome,
						position = portal.GetPosition(),
						rotation = portal.GetRotation(),
						exit = (Object.op_Implicit((Object)(object)val2) ? val2.m_exitDistance : 1.5f),
						allowAll = (Object.op_Implicit((Object)(object)val2) && val2.m_allowAllItems)
					};
				}
			}
			List<ZDOID> list = new List<ZDOID>();
			foreach (ZDOID pillar in pillars)
			{
				ZDO zDO = ZDOMan.instance.GetZDO(pillar);
				if (zDO == null || zDO.GetPrefab() != StringExtensionMethods.GetStableHashCode("OCT_AtlasPillar"))
				{
					list.Add(pillar);
					continue;
				}
				string text2 = Id(pillar);
				AtlasName atlasName2 = data.Find(text2);
				if (atlasName2 == null)
				{
					if (firstScan || storageFailed)
					{
						continue;
					}
					atlasName2 = data.Assign(text2, Biome(zDO.GetPosition()), zDO.GetInt("oct_atlas_number", 0), zDO.GetString("oct_atlas_label", ""));
					dirty = true;
					WritePillarName(zDO, atlasName2);
				}
				authoritative[text2] = new Destination
				{
					id = text2,
					name = atlasName2.Display,
					biome = atlasName2.biome,
					pillar = true,
					position = zDO.GetPosition(),
					rotation = zDO.GetRotation(),
					exit = 1.5f
				};
			}
			foreach (ZDOID item in list)
			{
				pillars.Remove(item);
			}
		}

		internal static string Biome(Vector3 position)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			string text = ((object)WorldGenerator.instance.GetBiome(position)/*cast due to .constrained prefix*/).ToString();
			return text switch
			{
				"BlackForest" => "Black Forest", 
				"Mountain" => "Mountains", 
				"AshLands" => "Ashlands", 
				"DeepNorth" => "Deep North", 
				_ => text, 
			};
		}

		internal void Track(ZDO zdo)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (zdo != null && Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer() && zdo.GetPrefab() == StringExtensionMethods.GetStableHashCode("OCT_AtlasPillar"))
			{
				pillars.Add(zdo.m_uid);
				nextRefresh = 0f;
			}
		}

		private static void WritePillarName(ZDO zdo, AtlasName record)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (zdo.GetOwner() == ZDOMan.GetSessionID())
			{
				zdo.Set("oct_atlas_biome", record.biome);
				zdo.Set("oct_atlas_number", record.number);
				zdo.Set("oct_atlas_label", record.label);
			}
			else if (zdo.GetOwner() != 0L && ZRoutedRpc.instance != null)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(zdo.GetOwner(), zdo.m_uid, "OCT_AtlasLabel", new object[3] { record.biome, record.number, record.label });
			}
		}

		private bool Authorized(long sender, string source, bool readOnly)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if (sender == ZDOMan.GetSessionID())
			{
				if (Plugin.HasAtlas(Player.m_localPlayer) || (readOnly && Plugin.Unlocked(Player.m_localPlayer)))
				{
					return true;
				}
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					return IsNearPortal(ParseId(source), ((Component)Player.m_localPlayer).transform.position);
				}
				return false;
			}
			ZNetPeer peer = ZNet.instance.GetPeer(sender);
			ZDO val = ((peer == null) ? null : ZDOMan.instance.GetZDO(peer.m_characterID));
			if (val != null)
			{
				if (!val.GetBool("oct_atlas_carried", false) && (!readOnly || !val.GetBool("oct_atlas_unlocked", false)))
				{
					return IsNearPortal(ParseId(source), val.GetPosition());
				}
				return true;
			}
			return false;
		}

		internal static bool IsNearPortal(ZDOID source, Vector3 playerPosition)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (((ZDOID)(ref source)).Equals(ZDOID.None) || ZDOMan.instance == null || !Object.op_Implicit((Object)(object)Game.instance))
			{
				return false;
			}
			ZDO zDO = ZDOMan.instance.GetZDO(source);
			if (zDO != null && Game.instance.PortalPrefabHash.Contains(zDO.GetPrefab()))
			{
				Vector3 val = zDO.GetPosition() - playerPosition;
				return ((Vector3)(ref val)).sqrMagnitude <= 36f;
			}
			return false;
		}

		private void ProcessRequest(long sender, ZPackage package)
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Expected O, but got Unknown
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			if (world == 0L || package.ReadLong() != world)
			{
				return;
			}
			int num = package.ReadInt();
			int num2 = package.ReadInt();
			string text = package.ReadString();
			string text2 = package.ReadString();
			string text3 = package.ReadString();
			if (num < 0 || num > 2 || text.Length > 80 || text3.Length > 80 || text2.Length > 200 || !Authorized(sender, text3, num == 0))
			{
				return;
			}
			string key = sender + ":" + num;
			if (limits.TryGetValue(key, out var value) && Time.unscaledTime < value)
			{
				return;
			}
			limits[key] = Time.unscaledTime + ((num == 0) ? 0.75f : ((float)((num != 1) ? 1 : 3)));
			Refresh();
			ZPackage val = new ZPackage();
			val.Write(world);
			val.Write(num);
			val.Write(num2);
			if (num == 0)
			{
				val.Write("");
				val.Write(authoritative.Count);
				foreach (Destination item in authoritative.Values.OrderBy((Destination d) => d.id))
				{
					WriteEntry(val, item);
				}
			}
			else
			{
				ZDO zDO = ZDOMan.instance.GetZDO(ParseId(text));
				if (!authoritative.TryGetValue(text, out var value2) || zDO == null)
				{
					val.Write("That destination no longer exists.");
				}
				else if (num == 1)
				{
					string text4 = WorldTravelBlock();
					val.Write(text4);
					if (text4.Length == 0)
					{
						val.Write(value2.position + value2.rotation * Vector3.forward * value2.exit + Vector3.up);
						val.Write(value2.rotation);
						val.Write(value2.allowAll);
						ZDOMan.instance.ForceSendZDO(sender, zDO.m_uid);
					}
				}
				else if (storageFailed)
				{
					val.Write("Atlas naming data needs recovery before it can be changed.");
				}
				else
				{
					AtlasName atlasName = data.Find(text);
					if (atlasName == null)
					{
						atlasName = new AtlasName
						{
							id = text,
							biome = value2.biome
						};
						data.names.Add(atlasName);
					}
					atlasName.label = AtlasWorldData.Clean(text2);
					dirty = true;
					if (value2.pillar)
					{
						WritePillarName(zDO, atlasName);
					}
					Save();
					nextRefresh = 0f;
					val.Write("Renamed to " + (value2.pillar ? atlasName.Display : ((atlasName.label.Length > 0) ? atlasName.label : "the portal's tag")) + ".");
				}
			}
			if (sender == ZDOMan.GetSessionID())
			{
				Receive(new ZPackage(val.GetArray()));
			}
			else
			{
				response.SendPackage(sender, val);
			}
		}

		private static void WriteEntry(ZPackage package, Destination d)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			package.Write(d.id);
			package.Write(d.name);
			package.Write(d.biome);
			package.Write(d.pillar);
			package.Write(d.position);
		}

		private void Send(int op, string id = "", string label = "", string sourceOverride = null)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			string text = sourceOverride ?? Id(Plugin.UI.Source);
			if (Object.op_Implicit((Object)(object)ZNet.instance) && ZDOMan.instance != null && Object.op_Implicit((Object)(object)Player.m_localPlayer) && (Plugin.HasAtlas(Player.m_localPlayer) || (op == 0 && Plugin.Unlocked(Player.m_localPlayer)) || IsNearPortal(ParseId(text), ((Component)Player.m_localPlayer).transform.position)))
			{
				int num = ++nonce;
				if (op == 1)
				{
					pendingTravel = num;
					travelDeadline = Time.unscaledTime + 12f;
				}
				ZPackage val = new ZPackage();
				val.Write(world);
				val.Write(op);
				val.Write(num);
				val.Write(id);
				val.Write(label ?? "");
				val.Write(text);
				if (ZNet.instance.IsServer())
				{
					ProcessRequest(ZDOMan.GetSessionID(), new ZPackage(val.GetArray()));
				}
				else
				{
					request.SendPackage(ServerPeer, val);
				}
			}
		}

		internal void RequestList(bool force = false)
		{
			if (!(Time.unscaledTime < nextRequest))
			{
				nextRequest = Time.unscaledTime + (float)(force ? 1 : 3);
				Send(0);
			}
		}

		internal void Rename(ZDOID id, string text)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			Send(2, Id(id), AtlasWorldData.Clean(text));
			nextRequest = 0f;
		}

		internal void RenameAtPortal(ZDOID id, string text)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			Send(2, Id(id), AtlasWorldData.Clean(text), Id(id));
			nextRequest = 0f;
		}

		internal void Travel(Destination destination)
		{
			if (destination != null && pendingTravel == 0 && Plugin.UI.Active)
			{
				string text = ClientTravelBlock(allowAll: true);
				if (text.Length > 0)
				{
					Plugin.Notice(text);
				}
				else
				{
					Send(1, destination.id);
				}
			}
		}

		private void Receive(ZPackage package)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			if (package.ReadLong() != world)
			{
				return;
			}
			int num = package.ReadInt();
			int num2 = package.ReadInt();
			string text = package.ReadString();
			switch (num)
			{
			case 0:
				if (text.Length <= 0)
				{
					ReceiveCatalogue(package);
					refreshAfterRename = false;
				}
				break;
			case 1:
			{
				if (num2 != pendingTravel || Time.unscaledTime > travelDeadline)
				{
					break;
				}
				pendingTravel = 0;
				if (text.Length > 0)
				{
					Plugin.Notice(text);
					break;
				}
				Vector3 val = package.ReadVector3();
				Quaternion val2 = package.ReadQuaternion();
				string text2 = ClientTravelBlock(package.ReadBool());
				if (text2.Length > 0)
				{
					Plugin.Notice(text2);
					break;
				}
				if (!Plugin.UI.Active)
				{
					Plugin.Notice("Atlas travel cancelled because the map was closed.");
					break;
				}
				Plugin.UI.SuppressPortalUntil = Time.unscaledTime + 5f;
				Plugin.UI.Close();
				if (!((Character)Player.m_localPlayer).TeleportTo(val, val2, true))
				{
					Plugin.Notice("Unable to travel right now.");
				}
				break;
			}
			case 2:
				Plugin.Notice(text);
				nextRequest = 0f;
				refreshAfterRename = true;
				break;
			}
		}

		private unsafe void ReceiveCatalogue(ZPackage package)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			int num = package.ReadInt();
			if (num < 0 || num > 100000)
			{
				throw new InvalidDataException("Invalid catalogue length");
			}
			List<Destination> list = new List<Destination>();
			for (int i = 0; i < num; i++)
			{
				Destination destination = new Destination
				{
					id = package.ReadString(),
					name = package.ReadString(),
					biome = package.ReadString(),
					pillar = package.ReadBool(),
					position = package.ReadVector3()
				};
				if (destination.id.Length > 80 || destination.name.Length > 200 || destination.biome.Length > 80)
				{
					throw new InvalidDataException("Invalid destination");
				}
				list.Add(destination);
			}
			string text = string.Join("|", list.Select(delegate(Destination e)
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				string[] obj = new string[7] { e.id, "/", e.name, "/", null, null, null };
				Vector3 position = e.position;
				obj[4] = ((object)(*(Vector3*)(&position))/*cast due to .constrained prefix*/).ToString();
				obj[5] = "/";
				obj[6] = e.pillar.ToString();
				return string.Concat(obj);
			}));
			if (text != signature)
			{
				signature = text;
				Destinations.Clear();
				Destinations.AddRange(list);
				Revision++;
			}
		}

		internal static string WorldTravelBlock()
		{
			if (!Object.op_Implicit((Object)(object)ZoneSystem.instance))
			{
				return "The world is not ready yet.";
			}
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)32))
			{
				return "Portals are disabled in this world.";
			}
			float num = default(float);
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)33) && ((Object.op_Implicit((Object)(object)RandEventSystem.instance) && !string.IsNullOrEmpty(RandEventSystem.instance.GetBossEvent())) || (ZoneSystem.instance.GetGlobalKey((GlobalKeys)47, ref num) && num > 0f)))
			{
				return "Portal travel is blocked while a boss is active.";
			}
			return "";
		}

		internal static string ClientTravelBlock(bool allowAll)
		{
			//IL_001b: 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)
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || (!Plugin.HasAtlas(localPlayer) && !IsNearPortal(Plugin.UI.Source, ((Component)localPlayer).transform.position)))
			{
				return "Carry a Portal Atlas or stand beside a portal to travel.";
			}
			if (((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting() || localPlayer.IsSleeping() || ((Character)localPlayer).InCutscene())
			{
				return "You cannot travel right now.";
			}
			string text = WorldTravelBlock();
			if (text.Length > 0)
			{
				return text;
			}
			if (!((Humanoid)localPlayer).IsTeleportable(allowAll))
			{
				return "An item in your inventory prevents teleporting.";
			}
			return "";
		}
	}
	internal static class AtlasPillarVisual
	{
		internal static void Build(GameObject prefab)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_072c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0755: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00ee: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0130: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Expected O, but got Unknown
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: 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_026b: Expected O, but got Unknown
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Expected O, but got Unknown
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Expected O, but got Unknown
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Expected O, but got Unknown
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Expected O, but got Unknown
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Expected O, but got Unknown
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_045e: Expected O, but got Unknown
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0566: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0604: Unknown result type (might be due to invalid IL or missing references)
			//IL_061e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0632: Unknown result type (might be due to invalid IL or missing references)
			//IL_064c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0660: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_068e: Unknown result type (might be due to invalid IL or missing references)
			prefab.transform.localRotation = Quaternion.identity;
			LODGroup[] componentsInChildren = prefab.GetComponentsInChildren<LODGroup>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			Renderer[] componentsInChildren2 = prefab.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			MeshFilter[] componentsInChildren3 = prefab.GetComponentsInChildren<MeshFilter>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			Collider[] componentsInChildren4 = prefab.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren4[i]);
			}
			Material val = new Material(((Renderer)PrefabManager.Instance.GetPrefab("stone_wall_2x1").GetComponent<WearNTear>().m_new.GetComponentInChildren<MeshRenderer>(true)).sharedMaterial)
			{
				name = "Atlas native stone finish"
			};
			val.mainTexture = (Texture)(object)PaintedStone();
			val.color = Color.white;
			val.mainTextureScale = Vector2.one;
			val.mainTextureOffset = Vector2.zero;
			Texture2D val2 = new Texture2D(1, 1, (TextureFormat)4, false, true);
			val2.SetPixel(0, 0, new Color(0.5f, 0.5f, 1f, 0.5f));
			val2.Apply();
			val.SetTexture("_BumpMap", (Texture)(object)val2);
			val.SetFloat("_Glossiness", 0f);
			val.SetColor("_EmissionColor", Color.black);
			val.DisableKeyword("_EMISSION");
			val.SetFloat("_ValueNoise", 0f);
			val.SetFloat("_ValueNoiseVertex", 0f);
			val.SetFloat("_AddRain", 0f);
			val.SetFloat("_RippleDistance", 0f);
			val.SetFloat("_SpecularHighlights", 0f);
			val.SetFloat("_GlossyReflections", 0f);
			Texture2D val3 = (Texture2D)val.mainTexture;
			Color32[] pixels = val3.GetPixels32();
			for (int j = 0; j < pixels.Length; j++)
			{
				Color32 val4 = pixels[j];
				if (val4.r <= 180 || val4.r - val4.b <= 100 || val4.g - val4.b <= 35)
				{
					pixels[j] = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
				}
			}
			Texture2D val5 = new Texture2D(((Texture)val3).width, ((Texture)val3).height, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			val5.SetPixels32(pixels);
			val5.Apply();
			val.SetTexture("_EmissionMap", (Texture)(object)val5);
			val.SetColor("_EmissionColor", new Color(1.2f, 1.2f, 1.2f, 1f));
			val.EnableKeyword("_EMISSION");
			Material val6 = new Material(val)
			{
				name = "Atlas painted carved stone"
			};
			Material val7 = new Material(val)
			{
				name = "Atlas painted orange insets"
			};
			Material val8 = new Material(val)
			{
				name = "Atlas unlit direction insets"
			};
			Color32[] pixels2 = val3.GetPixels32();
			for (int k = 0; k < pixels2.Length; k++)
			{
				Color32 val9 = pixels2[k];
				byte b = (byte)(((float)(int)val9.r * 0.2126f + (float)(int)val9.g * 0.7152f + (float)(int)val9.b * 0.0722f) * 0.45f);
				pixels2[k] = new Color32(b, b, b, val9.a);
			}
			Texture2D val10 = new Texture2D(((Texture)val3).width, ((Texture)val3).height, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			val10.SetPixels32(pixels2);
			val10.Apply();
			val8.mainTexture = (Texture)(object)val10;
			val8.SetColor("_EmissionColor", Color.black);
			val8.DisableKeyword("_EMISSION");
			Material val11 = new Material(val)
			{
				name = "Atlas painted masonry"
			};
			val11.mainTexture = (Texture)(object)PaintedStone("waystone-masonry");
			val11.mainTexture.wrapMode = (TextureWrapMode)0;
			val11.SetColor("_EmissionColor", Color.black);
			val11.DisableKeyword("_EMISSION");
			WaystonePart[] array;
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PortalAtlas.waystone.mesh"))
			{
				array = WaystoneModel.Read(stream);
			}
			WaystonePart[] array2 = array;
			foreach (WaystonePart waystonePart in array2)
			{
				Mesh val12 = new Mesh
				{
					name = "Atlas waystone " + waystonePart.name
				};
				val12.vertices = waystonePart.vertices;
				val12.uv = waystonePart.uv;
				val12.triangles = waystonePart.triangles;
				val12.RecalculateNormals();
				val12.RecalculateTangents();
				val12.RecalculateBounds();
				GameObject val13 = new GameObject("AtlasWaystone_" + waystonePart.name)
				{
					layer = prefab.layer
				};
				val13.transform.SetParent(prefab.transform, false);
				val13.AddComponent<MeshFilter>().sharedMesh = val12;
				((Renderer)val13.AddComponent<MeshRenderer>()).sharedMaterial = ((waystonePart.name == "muted") ? val8 : ((waystonePart.name == "masonry") ? val11 : ((waystonePart.name == "orange") ? val7 : ((waystonePart.name == "recess") ? val6 : val))));
			}
			Collider(prefab, new Vector3(0f, 0.035f, 0f), new Vector3(0.75f, 0.07f, 0.75f));
			Collider(prefab, new Vector3(0f, 0.135f, 0f), new Vector3(0.69f, 0.13f, 0.69f));
			Collider(prefab, new Vector3(0f, 0.25f, 0f), new Vector3(0.6f, 0.1f, 0.6f));
			Collider(prefab, new Vector3(0f, 0.5f, 0f), new Vector3(0.526f, 0.4f, 0.526f));
			Collider(prefab, new Vector3(0f, 0.735f, 0f), new Vector3(0.62f, 0.075f, 0.62f));
			Collider(prefab, new Vector3(0f, 1.08f, 0f), new Vector3(0.44f, 0.62f, 0.44f));
			Collider(prefab, new Vector3(0f, 1.445f, 0f), new Vector3(0.49f, 0.11f, 0.49f));
			Transform[] componentsInChildren5 = prefab.GetComponentsInChildren<Transform>(true);
			foreach (Transform val14 in componentsInChildren5)
			{
				if (Object.op_Implicit((Object)(object)val14) && (Object)(object)val14 != (Object)(object)prefab.transform && ((Component)val14).CompareTag("snappoint"))
				{
					Object.DestroyImmediate((Object)(object)((Component)val14).gameObject);
				}
			}
			try
			{
				AddCrownWisp(prefab);
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[Portal Atlas] Crown wisp could not render: " + ex));
			}
			Light(prefab, "AtlasWindowGlow", new Vector3(0f, 0.94f, 0f), 1.2f, 0.45f);
			Light(prefab, "AtlasBaseGlow", new Vector3(0f, 0.18f, 0f), 0.75f, 0.25f);
			Debug.Log((object)"[Portal Atlas] Approved waystone built: 1.50 m shoulder height, 0.75 m footprint; native wisp crown and orange insets.");
		}

		private static void Collider(GameObject parent, Vector3 center, Vector3 size)
		{
			//IL_0007: 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)
			BoxCollider obj = parent.AddComponent<BoxCollider>();
			obj.center = center;
			obj.size = size;
		}

		private static void Light(GameObject parent, string name, Vector3 position, float range, float intensity)
		{
			//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_0018: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent.transform, false);
			val.transform.localPosition = position;
			Light obj = val.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.color = new Color(1f, 0.33f, 0.05f);
			obj.range = range;
			obj.intensity = intensity;
			obj.shadows = (LightShadows)0;
		}

		private static Texture2D PaintedStone(string resource = "waystone-painted")
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
			{
				name = "Atlas approved painted finish",
				wrapMode = (TextureWrapMode)1
			};
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PortalAtlas." + resource + ".png"))
			{
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				ImageConversion.LoadImage(val, memoryStream.ToArray());
			}
			Color32[] pixels = val.GetPixels32();
			for (int i = 0; i < pixels.Length; i++)
			{
				pixels[i] = WaystoneColours.StoneGrey(pixels[i]);
			}
			val.SetPixels32(pixels);
			val.Apply();
			return val;
		}

		private static void AddCrownWisp(GameObject parent)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			if ((int)SystemInfo.graphicsDeviceType != 4)
			{
				GameObject val = PrefabManager.Instance.GetPrefab("Demister");
				if (!Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)ObjectDB.instance))
				{
					val = ObjectDB.instance.GetItemPrefab("Demister");
				}
				SE_Demister val2 = (SE_Demister)(Object.op_Implicit((Object)(object)val) ? /*isinst with value type is only supported in some contexts*/: null);
				GameObject obj = (Object.op_Implicit((Object)(object)val2) ? val2.m_ballPrefab : PrefabManager.Instance.GetPrefab("demister_ball"));
				if (!Object.op_Implicit((Object)(object)obj))
				{
					throw new InvalidOperationException("Native wisplight visual prefab is unavailable");
				}
				GameObject val3 = new GameObject("AtlasCrownWisp");
				val3.SetActive(false);
				val3.transform.SetParent(parent.transform, false);
				val3.transform.localPosition = new Vector3(0f, 1.59f, 0f);
				CopyWispVisual(obj.transform.Find("demister_ball"), val3.transform, "AtlasWispCore");
				GameObject val4 = CopyWispVisual(obj.transform.Find("effects/flame/sparcs_front"), val3.transform, "AtlasWispSparks");
				if (Object.op_Implicit((Object)(object)val4))
				{
					ConfigureSparks(val4);
				}
				CopyWispVisual(obj.transform.Find("effects/flame/flare"), val3.transform, "AtlasWispHalo");
				Light obj2 = val3.AddComponent<Light>();
				obj2.color = new Color(0.35f, 0.8f, 1f);
				obj2.range = 0.8f;
				obj2.intensity = 0.55f;
				obj2.shadows = (LightShadows)0;
				val3.AddComponent<AtlasCrownWispBob>();
				val3.SetActive(true);
			}
		}

		private static GameObject CopyWispVisual(Transform source, Transform parent, string name)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)source))
			{
				return null;
			}
			GameObject val = Object.Instantiate<GameObject>(((Component)source).gameObject, parent, false);
			((Object)val).name = name;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = source.localScale * 0.5f;
			MeshFilter component = val.GetComponent<MeshFilter>();
			Transform transform = val.transform;
			Vector3 localPosition;
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.sharedMesh))
			{
				localPosition = Vector3.zero;
			}
			else
			{
				Bounds bounds = component.sharedMesh.bounds;
				localPosition = -Vector3.Scale(((Bounds)(ref bounds)).center, val.transform.localScale);
			}
			transform.localPosition = localPosition;
			MonoBehaviour[] componentsInChildren = val.GetComponentsInChildren<MonoBehaviour>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			Rigidbody[] componentsInChildren3 = val.GetComponentsInChildren<Rigidbody>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			Renderer[] componentsInChildren4 = val.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren4)
			{
				Material[] sharedMaterials = val2.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (!Object.op_Implicit((Object)(object)sharedMaterials[j]))
					{
						continue;
					}
					sharedMaterials[j] = new Material(sharedMaterials[j]);
					sharedMaterials[j].DisableKeyword("_DISTORTION_ON");
					string[] array = new string[3] { "_DistortionEnabled", "_DistortionStrength", "_DistortionBlend" };
					foreach (string text in array)
					{
						if (sharedMaterials[j].HasProperty(text))
						{
							sharedMaterials[j].SetFloat(text, 0f);
						}
					}
					if (Object.op_Implicit((Object)(object)sharedMaterials[j].shader) && ((Object)sharedMaterials[j].shader).name.ToLowerInvariant().Contains("distort"))
					{
						val2.enabled = false;
					}
				}
				val2.sharedMaterials = sharedMaterials;
			}
			val.SetActive(true);
			return val;
		}

		private static void ConfigureSparks(GameObject sparks)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c6: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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_0164: 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_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: 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_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem[] componentsInChildren = sparks.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				val.Stop(true, (ParticleSystemStopBehavior)0);
				MainModule main = val.main;
				((MainModule)(ref main)).loop = true;
				((MainModule)(ref main)).playOnAwake = true;
				((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
				((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Color.white);
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.8f, 0.95f);
				((MainModule)(ref main)).startSize = new MinMaxCurve(0.012f, 0.022f);
				((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.7f, 0.85f);
				((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f);
				((MainModule)(ref main)).maxParticles = 12;
				EmissionModule emission = val.emission;
				((EmissionModule)(ref emission)).enabled = true;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(5f);
				((EmissionModule)(ref emission)).rateOverDistance = MinMaxCurve.op_Implicit(0f);
				ShapeModule shape = val.shape;
				((ShapeModule)(ref shape)).enabled = true;
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
				((ShapeModule)(ref shape)).radius = 0.06f;
				((ShapeModule)(ref shape)).position = Vector3.zero;
				((ShapeModule)(ref shape)).scale = Vector3.one;
				NoiseModule noise = val.noise;
				((NoiseModule)(ref noise)).enabled = false;
				ColorOverLifetimeModule colorOverLifetime = val.colorOverLifetime;
				((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
				Gradient val2 = new Gradient();
				val2.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
				{
					new GradientColorKey(Color.white, 0f),
					new GradientColorKey(Color.white, 1f)
				}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
				{
					new GradientAlphaKey(0f, 0f),
					new GradientAlphaKey(1f, 0.08f),
					new GradientAlphaKey(0.85f, 0.7f),
					new GradientAlphaKey(0f, 1f)
				});
				((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val2);
				SizeOverLifetimeModule sizeOverLifetime = val.sizeOverLifetime;
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0.25f));
				ExternalForcesModule externalForces = val.externalForces;
				((ExternalForcesModule)(ref externalForces)).enabled = false;
				VelocityOverLifetimeModule velocityOverLifetime = val.velocityOverLifetime;
				((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = false;
				InheritVelocityModule inheritVelocity = val.inheritVelocity;
				((InheritVelocityModule)(ref inheritVelocity)).enabled = false;
				val.Play(true);
			}
			Renderer[] componentsInChildren2 = sparks.GetComponentsInChildren<Renderer>(true);
			Color val4 = default(Color);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Material[] sharedMaterials = componentsInChildren2[i].sharedMaterials;
				foreach (Material val3 in sharedMaterials)
				{
					((Color)(ref val4))..ctor(1.5f, 1.5f, 1.5f, 1f);
					string[] array = new string[3] { "_Color", "_TintColor", "_EmissionColor" };
					foreach (string text in array)
					{
						if (val3.HasProperty(text))
						{
							val3.SetColor(text, val4);
						}
					}
				}
			}
		}
	}
	internal sealed class AtlasCrownWispBob : MonoBehaviour
	{
		private void Update()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.localPosition = WaystoneModel.CrownPosition(Mathf.Sin(Time.time * 1.4f) * 0.02f);
		}
	}
	internal static class AtlasRenameDialog
	{
		[HarmonyPatch(typeof(TextInput), "Hide")]
		private static class Closed
		{
			private static void Postfix()
			{
				Detach();
			}
		}

		[HarmonyPatch(typeof(TextInput), "RequestText")]
		private static class Requested
		{
			private static void Prefix()
			{
				Detach();
			}
		}

		private static TMP_InputField input;

		private static UnityAction<string> submit;

		internal static void Open(TextReceiver receiver, string topic)
		{
			Detach();
			TextInput dialog = TextInput.instance;
			dialog.RequestText(receiver, topic, 48);
			object? value = AccessTools.Field(typeof(TextInput), "m_inputField").GetValue(dialog);
			input = (TMP_InputField)((value is TMP_InputField) ? value : null);
			if (!Object.op_Implicit((Object)(object)input))
			{
				return;
			}
			submit = delegate
			{
				if (Object.op_Implicit((Object)(object)dialog) && dialog.m_panel.activeInHierarchy)
				{
					dialog.OnEnter();
				}
			};
			((UnityEvent<string>)(object)input.onSubmit).AddListener(submit);
		}

		internal static void Detach()
		{
			if (Object.op_Implicit((Object)(object)input) && submit != null)
			{
				((UnityEvent<string>)(object)input.onSubmit).RemoveListener(submit);
			}
			input = null;
			submit = null;
		}
	}
	internal sealed class AtlasUi
	{
		private sealed class AtlasRename : TextReceiver
		{
			private readonly Destination entry;

			internal AtlasRename(Destination entry)
			{
				this.entry = entry;
			}

			public string GetText()
			{
				return entry.name;
			}

			public void SetText(string text)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				Plugin.Network.Rename(entry.Uid, text);
			}
		}

		private sealed class MapMarker
		{
			internal GameObject root;

			internal RectTransform rect;

			internal Image image;

			internal Destination entry;

			internal TMP_Text caption;

			internal readonly List<PinData> pins = new List<PinData>();
		}

		private GameObject panel;

		private GameObject markerLayer;

		private RectTransform content;

		private InputField search;

		private Text count;

		private string selected = "";

		private string hovered = "";

		private string favouritesKey = "";

		private string favouritesIdentity = "";

		private string favouritesPath;

		private readonly HashSet<string> favourites = new HashSet<string>();

		private readonly Dictionary<string, MapMarker> markers = new Dictionary<string, MapMarker>();

		private int revision = -1;

		private bool active;

		private bool rebuild;

		private float nextPinBinding;

		private static readonly FieldInfo NativePins = typeof(Minimap).GetField("m_pins", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo NativeNamePrefab = typeof(Minimap).GetField("m_pinNamePrefab", BindingFlags.Instance | BindingFlags.NonPublic);

		private readonly Dictionary<Graphic, bool> mutedGraphics = new Dictionary<Graphic, bool>();

		internal float SuppressPortalUntil;

		internal ZDOID Source { get; private set; } = ZDOID.None;

		internal bool Active => active;

		internal bool SearchFocused
		{
			get
			{
				if (active && Object.op_Implicit((Object)(object)search))
				{
					return search.isFocused;
				}
				return false;
			}
		}

		private static Color Gold => new Color(1f, 0.73f, 0.31f);

		internal bool PointerOverPanel
		{
			get
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				if (active && Object.op_Implicit((Object)(object)panel))
				{
					if (!Over((RectTransform)panel.transform))
					{
						if (Object.op_Implicit((Object)(object)search))
						{
							return search.isFocused;
						}
						return false;
					}
					return true;
				}
				return false;
			}
		}

		internal bool PointerOverAtlas
		{
			get
			{
				if (active)
				{
					if (!PointerOverPanel)
					{
						return markers.Values.Any((MapMarker m) => Object.op_Implicit((Object)(object)m.root) && m.root.activeInHierarchy && (Over(m.rect) || Over(m.caption.rectTransform)));
					}
					return true;
				}
				return false;
			}
		}

		private static bool Over(RectTransform rect)
		{
			//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)
			return RectTransformUtility.RectangleContainsScreenPoint(rect, Vector2.op_Implicit(Input.mousePosition), (Camera)null);
		}

		internal void Open()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Open(ZDOID.None);
		}

		internal void Open(ZDOID source)
		{
			//IL_0018: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Invalid comparison between Unknown and I4
			Player localPlayer = Player.m_localPlayer;
			bool flag = Plugin.HasAtlas(localPlayer);
			if (!flag && (!Object.op_Implicit((Object)(object)localPlayer) || !AtlasNetwork.IsNearPortal(source, ((Component)localPlayer).transform.position)))
			{
				Plugin.Notice("Carry a Portal Atlas or enter a portal to choose a destination.");
			}
			else
			{
				if (((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting() || ((Character)localPlayer).InCutscene() || !Object.op_Implicit((Object)(object)Minimap.instance) || (Object)(object)GUIManager.CustomGUIFront == (Object)null)
				{
					return;
				}
				if (flag)
				{
					Plugin.Unlock(localPlayer);
				}
				LoadFavourites();
				Source = source;
				if (Object.op_Implicit((Object)(object)InventoryGui.instance))
				{
					InventoryGui.instance.Hide();
				}
				Minimap.instance.SetMapMode((MapMode)2);
				if ((int)Minimap.instance.m_mode != 2)
				{
					Plugin.Notice("Maps are disabled in this world.");
					return;
				}
				if (!Object.op_Implicit((Object)(object)panel))
				{
					CreatePanel();
				}
				panel.SetActive(true);
				active = true;
				rebuild = true;
				Plugin.Network.RequestList(force: true);
			}
		}

		internal void Close()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Invalid comparison between Unknown and I4
			active = false;
			hovered = "";
			Source = ZDOID.None;
			RestoreNativeGraphics();
			if (Object.op_Implicit((Object)(object)markerLayer))
			{
				markerLayer.SetActive(false);
			}
			if (Object.op_Implicit((Object)(object)panel))
			{
				panel.SetActive(false);
			}
			if (Object.op_Implicit((Object)(object)Minimap.instance) && (int)Minimap.instance.m_mode == 2)
			{
				Minimap.instance.SetMapMode((MapMode)1);
			}
		}

		internal void Tick()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Invalid comparison between Unknown and I4
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Invalid comparison between Unknown and I4
			Minimap instance = Minimap.instance;
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)localPlayer))
			{
				Dispose();
				return;
			}
			bool flag = Plugin.HasAtlas(localPlayer) || (active && AtlasNetwork.IsNearPortal(Source, ((Component)localPlayer).transform.position));
			if (active && (!flag || (int)instance.m_mode != 2 || ((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting()))
			{
				active = false;
				hovered = "";
				Source = ZDOID.None;
				if (Object.op_Implicit((Object)(object)panel))
				{
					panel.SetActive(false);
				}
			}
			if (active && (int)instance.m_mode == 2 && flag)
			{
				Plugin.Network.RequestList();
			}
			if (revision != Plugin.Network.Revision)
			{
				revision = Plugin.Network.Revision;
				rebuild = true;
				SyncMarkers();
			}
			if (active && rebuild)
			{
				rebuild = false;
				BuildRows();
			}
		}

		private void LoadFavourites()
		{
			long worldUID = ZNet.instance.GetWorldUID();
			string text = Player.m_localPlayer.GetPlayerID() + "-" + worldUID;
			if (text == favouritesIdentity)
			{
				return;
			}
			favouritesIdentity = text;
			favouritesKey = "OCT_Atlas_Favourites_v2_" + worldUID;
			favourites.Clear();
			selected = "";
			favouritesPath = Path.Combine(Paths.ConfigPath, "OctoberJemini.PortalAtlas", "client-favourites", text + ".v2.txt");
			HashSet<string> hashSet = null;
			try
			{
				hashSet = FavouriteStore.Read(favouritesPath);
			}
			catch (Exception ex)
			{
				Plugin.Warn("Could not read favourite backup: " + ex.Message);
			}
			if (hashSet != null)
			{
				favourites.UnionWith(hashSet);
				return;
			}
			if (Player.m_localPlayer.m_customData.TryGetValue(favouritesKey, out var value))
			{
				string[] array = value.Split(new char[1] { ',' });
				foreach (string text2 in array)
				{
					if (text2.Length > 0)
					{
						favourites.Add(text2);
					}
				}
			}
			SaveFavourites();
			if (favourites.Count == 0 && File.Exists(Path.Combine(Paths.ConfigPath, "OctoberJemini.PortalAtlas", "client-favourites", text + ".txt")))
			{
				Plugin.Notice("Favourite storage fixed for world reloads. Please star your destinations again; the previous list is preserved.");
			}
		}

		private static string FavouriteKey(Destination entry)
		{
			return FavouriteStore.Key(entry.pillar, entry.position.x, entry.position.y, entry.position.z);
		}

		private void ToggleFavourite(string id)
		{
			if (!favourites.Remove(id))
			{
				favourites.Add(id);
			}
			SaveFavourites();
			rebuild = true;
		}

		private void SaveFavourites()
		{
			Player.m_localPlayer.m_customData[favouritesKey] = string.Join(",", favourites.OrderBy((string x) => x));
			try
			{
				FavouriteStore.Save(favouritesPath, favourites);
			}
			catch (Exception ex)
			{
				Plugin.Warn("Could not save favourite backup: " + ex.Message);
				Plugin.Notice("Favourite changed, but its immediate backup could not be saved.");
			}
		}

		private static RectTransform Rect(GameObject go, Vector2 anchor, Vector2 pivot, Vector2 position, Vector2 size)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			RectTransform val = (RectTransform)go.transform;
			Vector2 anchorMin = (val.anchorMax = anchor);
			val.anchorMin = anchorMin;
			val.pivot = pivot;
			val.anchoredPosition = position;
			val.sizeDelta = size;
			return val;
		}

		private static GameObject Child(string name, Transform parent)
		{
			//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_0027: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			return val;
		}

		private static Text Label(string text, Transform parent, int size, TextAnchor alignment)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Text obj = Child("Label", parent).AddComponent<Text>();
			obj.font = GUIManager.Instance.AveriaSerifBold;
			obj.fontSize = size;
			((Graphic)obj).color = Gold;
			obj.text = text;
			obj.alignment = alignment;
			obj.supportRichText = false;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private static Button Button(string text, Transform parent, Action action)
		{
			//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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			GameObject obj = GUIManager.Instance.CreateButton(text, parent, Vector2.zero, Vector2.zero, Vector2.zero, 10f, 10f);
			Button component = obj.GetComponent<Button>();
			((UnityEvent)component.onClick).AddListener((UnityAction)delegate
			{
				action();
			});
			Text componentInChildren = obj.GetComponentInChildren<Text>();
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				componentInChildren.fontSize = 17;
				componentInChildren.supportRichText = false;
			}
			return component;
		}

		private static Image Icon(string name, Transform parent, float size)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Child(name, parent);
			Image obj = val.AddComponent<Image>();
			obj.sprite = Icons.Get(name);
			obj.preserveAspect = true;
			((Graphic)obj).raycastTarget = false;
			Rect(val, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(size, size));
			return obj;
		}

		private void CreatePanel()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: 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_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0559: Expected O, but got Unknown
			//IL_0569: Unknown result type (might be due to invalid IL or missing references)
			//IL_0583: Unknown result type (might be due to invalid IL or missing references)
			//IL_059d: 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_05d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e1: Expected O, but got Unknown
			//IL_0645: Unknown result type (might be due to invalid IL or missing references)
			//IL_0654: Unknown result type (might be due to invalid IL or missing references)
			//IL_0659: Unknown result type (might be due to invalid IL or missing references)
			//IL_0668: Unknown result type (might be due to invalid IL or missing references)
			//IL_068e: 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_06c6: Expected O, but got Unknown
			//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0700: Unknown result type (might be due to invalid IL or missing references)
			//IL_071b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0722: Expected O, but got Unknown
			//IL_0724: Unknown result type (might be due to invalid IL or missing references)
			//IL_0730: Unknown result type (might be due to invalid IL or missing references)
			//IL_073e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_0744: Unknown result type (might be due to invalid IL or missing references)
			//IL_074b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0762: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_07dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			GUIManager instance = GUIManager.Instance;
			panel = instance.CreateWoodpanel(mapParent(), Vector2.zero, Vector2.zero, Vector2.zero, 0f, 0f, false);
			((Object)panel).name = "OCT_PortalAtlas_Panel";
			Rect(panel, new Vector2(0f, 0.5f), new Vector2(0f, 0.5f), new Vector2(28f, 0f), new Vector2(440f, 620f));
			Text obj = Label("PORTAL ATLAS", panel.transform, 32, (TextAnchor)4);
			obj.font = instance.NorseBold;
			Rect(((Component)obj).gameObject, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(-10f, -16f), new Vector2(325f, 44f));
			Button val = Button("", panel.transform, Close);
			Rect(((Component)val).gameObject, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-15f, -18f), new Vector2(32f, 32f));
			Icon("close", ((Component)val).transform, 18f);
			GameObject val2 = instance.CreateInputField(panel.transform, Vector2.zero, Vector2.zero, Vector2.zero, (ContentType)0, "Search by name or biome", 18, 400f, 38f);
			((Object)val2).name = "AtlasSearch";
			Rect(val2, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -72f), new Vector2(400f, 38f));
			search = val2.GetComponent<InputField>();
			search.characterLimit = 48;
			search.lineType = (LineType)0;
			search.customCaretColor = true;
			search.caretColor = new Color(1f, 0.95f, 0.86f);
			search.caretWidth = 2;
			search.selectionColor = new Color(0.7f, 0.45f, 0.15f, 0.5f);
			Text textComponent = search.textComponent;
			textComponent.font = instance.AveriaSerifBold;
			textComponent.fontSize = 18;
			((Graphic)textComponent).color = new Color(1f, 0.95f, 0.86f);
			textComponent.supportRichText = false;
			textComponent.alignment = (TextAnchor)3;
			textComponent.horizontalOverflow = (HorizontalWrapMode)1;
			((Graphic)textComponent).rectTransform.anchorMin = Vector2.zero;
			((Graphic)textComponent).rectTransform.anchorMax = Vector2.one;
			((Graphic)textComponent).rectTransform.offsetMin = new Vector2(12f, 5f);
			((Graphic)textComponent).rectTransform.offsetMax = new Vector2(-40f, -5f);
			Graphic placeholder = search.placeholder;
			Text val3 = (Text)(object)((placeholder is Text) ? placeholder : null);
			if (Object.op_Implicit((Object)(object)val3))
			{
				val3.font = instance.AveriaSerif;
				val3.fontSize = 18;
				((Graphic)val3).color = new Color(0.8f, 0.77f, 0.7f, 0.8f);
				val3.alignment = (TextAnchor)3;
				((Graphic)val3).rectTransform.anchorMin = Vector2.zero;
				((Graphic)val3).rectTransform.anchorMax = Vector2.one;
				((Graphic)val3).rectTransform.offsetMin = new Vector2(12f, 5f);
				((Graphic)val3).rectTransform.offsetMax = new Vector2(-40f, -5f);
			}
			((UnityEvent<string>)(object)search.onValueChanged).AddListener((UnityAction<string>)delegate
			{
				rebuild = true;
			});
			Image val4 = Icon("search", val2.transform, 18f);
			RectTransform rectTransform = ((Graphic)val4).rectTransform;
			RectTransform rectTransform2 = ((Graphic)val4).rectTransform;
			Vector2 val5 = default(Vector2);
			((Vector2)(ref val5))..ctor(1f, 0.5f);
			rectTransform2.anchorMax = val5;
			rectTransform.anchorMin = val5;
			((Graphic)val4).rectTransform.anchoredPosition = new Vector2(-15f, 0f);
			GameObject val6 = Child("AtlasScroll", panel.transform);
			Rect(val6, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -124f), new Vector2(400f, 432f));
			ScrollRect obj2 = val6.AddComponent<ScrollRect>();
			obj2.horizontal = false;
			obj2.vertical = true;
			obj2.movementType = (MovementType)2;
			obj2.scrollSensitivity = 480f;
			GameObject val7 = Child("AtlasDestinations", val6.transform);
			RectTransform viewport = Rect(val7, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, new Vector2(372f, 432f));
			((Graphic)val7.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.18f);
			val7.AddComponent<RectMask2D>();
			content = (RectTransform)Child("Content", val7.transform).transform;
			content.anchorMin = new Vector2(0f, 1f);
			content.anchorMax = new Vector2(1f, 1f);
			content.pivot = new Vector2(0.5f, 1f);
			content.sizeDelta = Vector2.zero;
			VerticalLayoutGroup obj3 = ((Component)content).gameObject.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj3).spacing = 5f;
			((LayoutGroup)obj3).padding = new RectOffset(0, 0, 2, 2);
			((HorizontalOrVerticalLayoutGroup)obj3).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandHeight = false;
			((Component)content).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			obj2.content = content;
			obj2.viewport = viewport;
			GameObject val8 = Child("VerticalScrollbar", val6.transform);
			Rect(val8, new Vector2(1f, 0.5f), new Vector2(1f, 0.5f), Vector2.zero, new Vector2(18f, 432f));
			((Graphic)val8.AddComponent<Image>()).color = new Color(0.1f, 0.085f, 0.06f, 0.95f);
			Scrollbar val9 = val8.AddComponent<Scrollbar>();
			val9.direction = (Direction)2;
			RectTransform val10 = (RectTransform)Child("SlidingArea", val8.transform).transform;
			val10.anchorMin = Vector2.zero;
			val10.anchorMax = Vector2.one;
			val10.offsetMin = new Vector2(2f, 2f);
			val10.offsetMax = new Vector2(-2f, -2f);
			RectTransform val11 = (RectTransform)Child("Handle", (Transform)(object)val10).transform;
			val11.anchorMin = Vector2.zero;
			val11.anchorMax = Vector2.one;
			val5 = (val11.offsetMin = (val11.offsetMax = Vector2.zero));
			Image val13 = ((Component)val11).gameObject.AddComponent<Image>();
			((Graphic)val13).color = Gold;
			val9.handleRect = val11;
			((Selectable)val9).targetGraphic = (Graphic)(object)val13;
			obj2.verticalScrollbar = val9;
			obj2.verticalScrollbarVisibility = (ScrollbarVisibility)0;
			count = Label("Loading destinations...", panel.transform, 15, (TextAnchor)3);
			Rect(((Component)count).gameObject, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 24f), new Vector2(400f, 24f));
		}

		private static Transform mapParent()
		{
			return Minimap.instance.m_largeRoot.transform;
		}

		private void BuildRows()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)content))
			{
				return;
			}
			foreach (Transform item in (Transform)content)
			{
				((Component)item).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			string query = (Object.op_Implicit((Object)(object)search) ? search.text : "");
			List<Destination> list = (from d in Plugin.Network.Destinations
				where AtlasWorldData.Search(d.name, d.biome, query)
				orderby favourites.Contains(FavouriteKey(d)) descending
				select d).ThenBy<Destination, string>((Destination d) => d.name, StringComparer.OrdinalIgnoreCase).ThenBy((Destination d) => d.id).ToList();
			count.text = list.Count + " / " + Plugin.Network.Destinations.Count + " destinations  •  click to travel";
			foreach (Destination item2 in list)
			{
				Destination entry = item2;
				GameObject val2 = Child("Destination_" + entry.id, (Transform)(object)content);
				val2.AddComponent<LayoutElement>().preferredHeight = 36f;
				HorizontalLayoutGroup obj = val2.AddComponent<HorizontalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)obj).spacing = 5f;
				((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false;
				((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = true;
				Button val3 = Button("", val2.transform, delegate
				{
					ToggleFavourite(FavouriteKey(entry));
				});
				((Component)val3).gameObject.AddComponent<LayoutElement>().preferredWidth = 34f;
				Icon(favourites.Contains(FavouriteKey(entry)) ? "star-on" : "star-off", ((Component)val3).transform, 26f);
				Button val4 = Button(AtlasWorldData.WithBiome(entry.name, entry.biome), val2.transform, delegate
				{
					TravelTo(entry.id);
				});
				((Component)val4).gameObject.AddComponent<LayoutElement>().flexibleWidth = 1f;
				Text componentInChildren = ((Component)val4).GetComponentInChildren<Text>();
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					componentInChildren.fontSize = 17;
					componentInChildren.alignment = (TextAnchor)3;
					((Graphic)componentInChildren).rectTransform.offsetMin = new Vector2(12f, ((Graphic)componentInChildren).rectTransform.offsetMin.y);
					((Graphic)componentInChildren).rectTransform.offsetMax = new Vector2(-10f, ((Graphic)componentInChildren).rectTransform.offsetMax.y);
					componentInChildren.horizontalOverflow = (HorizontalWrapMode)1;
					componentInChildren.verticalOverflow = (VerticalWrapMode)0;
					componentInChildren.resizeTextForBestFit = true;
					componentInChildren.resizeTextMinSize = 10;
					componentInChildren.resizeTextMaxSize = 17;
				}
				((Component)val4).gameObject.AddComponent<RectMask2D>();
				if (entry.id == selected)
				{
					ColorBlock colors = ((Selectable)val4).colors;
					((ColorBlock)(ref colors)).normalColor = new Color(1f, 0.8f, 0.44f);
					((Selectable)val4).colors = colors;
				}
				Button val5 = Button("", val2.transform, delegate
				{
					Rename(entry);
				});
				((Component)val5).gameObject.AddComponent<LayoutElement>().preferredWidth = 30f;
				Icon("rename", ((Component)val5).transform, 22f);
				AtlasHover atlasHover = val2.AddComponent<AtlasHover>();
				atlasHover.enter = delegate
				{
					hovered = entry.id;
				};
				atlasHover.exit = delegate
				{
					if (hovered == entry.id)
					{
						hovered = "";
					}
				};
			}
			if (list.Count == 0)
			{
				((Component)Label((Plugin.Network.Destinations.Count == 0) ? "No destinations yet. Build a pillar or a portal.\nThe world catalogue may take a moment to load." : "No matching destinations.", (Transform)(object)content, 18, (TextAnchor)4)).gameObject.AddComponent<LayoutElement>().preferredHeight = 100f;
			}
			if (!Plugin.Network.Destinations.Any((Destination d) => d.id == selected))
			{
				selected = "";
			}
		}

		private void TravelTo(string id)
		{
			if (active)
			{
				selected = id;
				Destination destination = Plugin.Network.Destinations.FirstOrDefault((Destination d) => d.id == id);
				if (destination != null)
				{
					Plugin.Network.Travel(destination);
				}
			}
		}

		private void Rename(Destination entry)
		{
			AtlasRenameDialog.Open((TextReceiver)(object)new AtlasRename(entry), entry.pillar ? "Name Atlas pillar" : "Atlas label (portal link stays unchanged)");
		}

		private void SyncMarkers()
		{
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Expected O, but got Unknown
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Expected O, but got Unknown
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			Minimap instance = Minimap.instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				return;
			}
			EnsureMarkerLayer(instance);
			HashSet<string> current = new HashSet<string>(Plugin.Network.Destinations.Select((Destination d) => d.id));
			string[] array = markers.Keys.Where((string item) => !current.Contains(item)).ToArray();
			foreach (string key in array)
			{
				if (Object.op_Implicit((Object)(object)markers[key].root))
				{
					Object.Destroy((Object)(object)markers[key].root);
				}
				markers.Remove(key);
			}
			foreach (Destination destination in Plugin.Network.Destinations)
			{
				if (!markers.TryGetValue(destination.id, out var value) || !Object.op_Implicit((Object)(object)value.root))
				{
					GameObject val = Child("OCT_AtlasMarker_" + destination.id, markerLayer.transform);
					RectTransform rect = Rect(val, Vector2.zero, new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(28f, 28f));
					Image val2 = val.AddComponent<Image>();
					val2.preserveAspect = true;
					Button obj = val.AddComponent<Button>();
					((Selectable)obj).targetGraphic = (Graphic)(object)val2;
					string id = destination.id;
					((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
					{
						TravelTo(id);
					});
					GameObject obj2 = Object.Instantiate<GameObject>((GameObject)NativeNamePrefab.GetValue(instance), val.transform, false);
					((Object)obj2).name = "AtlasNativePinName";
					obj2.SetActive(true);
					TMP_Text componentInChildren = obj2.GetComponentInChildren<TMP_Text>(true);
					componentInChildren.richText = false;
					((Graphic)componentInChildren).raycastTarget = true;
					componentInChildren.textWrappingMode = (TextWrappingModes)0;
					((Graphic)componentInChildren).color = Color.white;
					RectTransform val3 = (RectTransform)obj2.transform;
					Vector2 anchorMin = (val3.anchorMax = new Vector2(0.5f, 0.5f));
					val3.anchorMin = anchorMin;
					val3.anchoredPosition = Vector2.zero;
					AtlasHover atlasHover = val.AddComponent<AtlasHover>();
					atlasHover.enter = delegate
					{
						hovered = id;
					};
					atlasHover.exit = delegate
					{
						if (hovered == id)
						{
							hovered = "";
						}
					};
					value = new MapMarker
					{
						root = val,
						rect = rect,
						image = val2,
						caption = componentInChildren
					};
					markers[destination.id] = value;
				}
				value.entry = destination;
				value.caption.text = AtlasWorldData.WithBiome(destination.name, destination.biome);
			}
			nextPinBinding = 0f;
		}

		private void EnsureMarkerLayer(Minimap map)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)markerLayer))
			{
				markerLayer = Child("OCT_AtlasInteractivePins", map.m_largeRoot.transform);
				RectTransform val = (RectTransform)markerLayer.transform;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0.5f, 0.5f);
				val.anchorMax = val2;
				val.anchorMin = val2;
				markerLayer.AddComponent<RectMask2D>();
				markerLayer.SetActive(false);
			}
		}

		private void BindNativePins(Minimap map)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Invalid comparison between Unknown and I4
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			foreach (MapMarker value in markers.Values)
			{
				value.pins.Clear();
			}
			if (!(NativePins.GetValue(map) is List<PinData> list))
			{
				return;
			}
			foreach (PinData item in list)
			{
				if ((int)item.m_type != 6)
				{
					continue;
				}
				MapMarker mapMarker = null;
				float num = 4f;
				foreach (MapMarker value2 in markers.Values)
				{
					if (value2.entry.pillar == Plugin.PillarPins.Owns(item))
					{
						Vector3 val = value2.entry.position - item.m_pos;
						float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
						if (sqrMagnitude < num)
						{
							num = sqrMagnitude;
							mapMarker = value2;
						}
					}
				}
				mapMarker?.pins.Add(item);
			}
		}

		private void Mute(Graphic graphic)
		{
			if (Object.op_Implicit((Object)(object)graphic))
			{
				if (!mutedGraphics.ContainsKey(graphic))
				{
					mutedGraphics[graphic] = ((Behaviour)graphic).enabled;
				}
				((Behaviour)graphic).enabled = false;
			}
		}

		private void RestoreNativeGraphics()
		{
			foreach (KeyValuePair<Graphic, bool> mutedGraphic in mutedGraphics)
			{
				if (Object.op_Implicit((Object)(object)mutedGraphic.Key))
				{
					((Behaviour)mutedGraphic.Key).enabled = mutedGraphic.Value;
				}
			}
			mutedGraphics.Clear();
		}

		internal void RenderAboveMap()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			RestoreNativeGraphics();
			Minimap instance = Minimap.instance;
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)localPlayer))
			{
				return;
			}
			bool flag = active && (int)instance.m_mode == 2 && (Plugin.HasAtlas(localPlayer) || AtlasNetwork.IsNearPortal(Source, ((Component)localPlayer).transform.position));
			if (Object.op_Implicit((Object)(object)markerLayer))
			{
				markerLayer.SetActive(flag);
			}
			if (flag)
			{
				if (Object.op_Implicit((Object)(object)markerLayer))
				{
					markerLayer.transform.SetAsLastSibling();
				}
				if (Object.op_Implicit((Object)(object)panel))
				{
					panel.transform.SetAsLastSibling();
				}
				UpdateMarkers(instance, flag);
			}
		}

		private void UpdateMarkers(Minimap map, bool carried)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_0067: Unknown result typ