Gatt.dll

Decompiled 15 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Splatform;
using UnityEngine;
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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RazaSquadPortalNetworkMultiplayer
{
	[BepInPlugin("br.com.raza.portalnetwork.multiplayer", "Gátt", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class PortalNetworkPlugin : BaseUnityPlugin
	{
		private enum Phase
		{
			Entering,
			Selecting,
			Authorizing,
			Preparing,
			Verifying,
			Returning
		}

		private sealed class Session
		{
			public Player Player;

			public Rigidbody? Body;

			public bool WasKinematic;

			public bool WasDetectingCollisions;

			public ZDOID Origin;

			public Vector3 OriginPosition;

			public Vector3 LogoutPosition;

			public Quaternion OriginRotation;

			public Vector3 ParkingPosition;

			public ZDOID Selected;

			public ZDOID Destination;

			public Vector3 Arrival;

			public Quaternion ArrivalRotation;

			public Phase Phase;

			public float PhaseStart;

			public string SelectedName = "";

			public bool OriginInactiveLogged;

			public bool OriginStillActiveWarned;

			public bool ForeignReferenceLogged;

			public float NextWaitLog;

			public float NextZoneBoost;

			public long Nonce;

			public bool SnapshotReady;

			public bool DepartureConfirmed;

			public float NextDepartureCheck;

			public bool UsingReturnFallback;

			public float PreparingStartedAt;

			public float NextVerificationAt;

			public readonly Dictionary<ZDOID, ObjectType> RequiredSupports = new Dictionary<ZDOID, ObjectType>();
		}

		private sealed class RectSnapshot
		{
			public RectTransform Rect;

			public Vector2 AnchorMin;

			public Vector2 AnchorMax;

			public Vector2 OffsetMin;

			public Vector2 OffsetMax;
		}

		[HarmonyPatch(typeof(TeleportWorldTrigger), "OnTriggerEnter")]
		private static class EnterPatch
		{
			private static bool Prefix(TeleportWorldTrigger __instance, Collider colliderIn)
			{
				Player component = ((Component)colliderIn).GetComponent<Player>();
				if ((Object)(object)component == (Object)null || (Object)(object)component != (Object)(object)Player.m_localPlayer)
				{
					return true;
				}
				if ((Object)(object)Instance != (Object)null && Time.realtimeSinceStartup < Instance._arrivalIgnoreUntil)
				{
					return false;
				}
				if ((Object)(object)Instance == (Object)null || !Instance.ServerSupportsNetwork)
				{
					return true;
				}
				TeleportWorld componentInParent = ((Component)__instance).GetComponentInParent<TeleportWorld>();
				if (!((Object)(object)componentInParent == (Object)null))
				{
					ZNetView component2 = ((Component)componentInParent).GetComponent<ZNetView>();
					if (IsVanillaPortal((component2 != null) ? component2.GetZDO() : null))
					{
						Instance?.Enter(component, componentInParent);
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Player), "SetLocalPlayer")]
		private static class PlayerStartPatch
		{
			private static void Postfix(Player __instance)
			{
				if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && (Object)(object)Instance != (Object)null)
				{
					Instance._localPlayerStartedAt = Time.realtimeSinceStartup;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "OnDeath")]
		private static class TransitDeathPatch
		{
			private static void Prefix(Player __instance)
			{
				Instance?.AbortForDeath(__instance);
			}
		}

		[HarmonyPatch(typeof(TeleportWorld), "HaveTarget")]
		private static class HaveTargetPatch
		{
			private static bool Prefix(TeleportWorld __instance, ref bool __result)
			{
				if ((Object)(object)Instance == (Object)null || !Instance.ServerSupportsNetwork)
				{
					return true;
				}
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!IsVanillaPortal((component != null) ? component.GetZDO() : null))
				{
					return true;
				}
				__result = true;
				return false;
			}
		}

		[HarmonyPatch(typeof(TeleportWorld), "TargetFound")]
		private static class TargetFoundPatch
		{
			private static bool Prefix(TeleportWorld __instance, ref bool __result)
			{
				if ((Object)(object)Instance == (Object)null || !Instance.ServerSupportsNetwork)
				{
					return true;
				}
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!IsVanillaPortal((component != null) ? component.GetZDO() : null))
				{
					return true;
				}
				__result = true;
				return false;
			}
		}

		[HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")]
		private static class PortalEffectDiagnosticPatch
		{
			private unsafe static void Postfix(TeleportWorld __instance)
			{
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				if ((Object)(object)Instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null || PortalHadTarget == null || PortalEffectActive == null || (Object)(object)__instance.m_target_found == (Object)null)
				{
					return;
				}
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				ZDO val = ((component != null) ? component.GetZDO() : null);
				if (IsVanillaPortal(val) && !(Vector3.Distance(((Component)Player.m_localPlayer).transform.position, ((Component)__instance).transform.position) > 8f))
				{
					bool flag = (bool)PortalEffectActive.GetValue(__instance.m_target_found);
					if (Instance._observedPortalEffects.TryGetValue(val.m_uid, out var value) && value != flag)
					{
						ManualLogSource logger = ((BaseUnityPlugin)Instance).Logger;
						string[] obj = new string[8] { "Portal effect ", null, null, null, null, null, null, null };
						ZDOID uid = val.m_uid;
						obj[1] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
						obj[2] = " changed to ";
						obj[3] = flag.ToString();
						obj[4] = "; target=";
						obj[5] = PortalHadTarget.GetValue(__instance)?.ToString();
						obj[6] = "; connection=";
						obj[7] = ((object)val.GetConnectionZDOID((ConnectionType)1)/*cast due to .constrained prefix*/).ToString();
						logger.LogInfo((object)string.Concat(obj));
					}
					Instance._observedPortalEffects[val.m_uid] = flag;
				}
			}
		}

		[HarmonyPatch(typeof(ZDO), "Set", new Type[]
		{
			typeof(int),
			typeof(string)
		})]
		private static class PersistPortalNamePatch
		{
			private unsafe static void Postfix(ZDO __instance, int hash)
			{
				//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)
				if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || ZDOMan.instance == null || (hash != ZDOVars.s_tag && hash != ZDOVars.s_tagauthor) || !IsVanillaPortal(__instance))
				{
					return;
				}
				ZDOMan.instance.SetDirtyPortals();
				if (hash == ZDOVars.s_tag)
				{
					PortalNetworkPlugin? instance = Instance;
					if (instance != null)
					{
						ManualLogSource logger = ((BaseUnityPlugin)instance).Logger;
						ZDOID uid = __instance.m_uid;
						logger.LogInfo((object)("Portal name marked for saving: " + ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString()));
					}
				}
			}
		}

		[HarmonyPatch(typeof(SEMan), "Update")]
		private static class PauseTransitStatusEffectsPatch
		{
			private static bool Prefix(Character ___m_character)
			{
				Session session = Instance?._session;
				if (session != null)
				{
					return (Object)(object)session.Player != (Object)(object)___m_character;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Player), "UpdateStats", new Type[] { typeof(float) })]
		private static class PauseTransitRegenPatch
		{
			private static bool Prefix(Player __instance)
			{
				return (Object)(object)Instance?._session?.Player != (Object)(object)__instance;
			}
		}

		[HarmonyPatch(typeof(Character), "UpdateSmoke")]
		private static class HoldTransitSmokeEnvironmentPatch
		{
			private static bool Prefix(Character __instance)
			{
				return (Object)(object)Instance?._session?.Player != (Object)(object)__instance;
			}
		}

		[HarmonyPatch(typeof(Player), "UpdateTeleport")]
		private static class HoldTravelPatch
		{
			private static bool Prefix(Player __instance)
			{
				return (Object)(object)Instance?._session?.Player != (Object)(object)__instance;
			}
		}

		[HarmonyPatch(typeof(Character), "UpdateMotion")]
		private static class HoldTransitMotionPatch
		{
			private static bool Prefix(Character __instance)
			{
				return (Object)(object)Instance?._session?.Player != (Object)(object)__instance;
			}
		}

		[HarmonyPatch(typeof(Player), "UpdateBiome")]
		private static class IgnoreTransitBiomePatch
		{
			private static bool Prefix(Player __instance)
			{
				return (Object)(object)Instance?._session?.Player != (Object)(object)__instance;
			}
		}

		[HarmonyPatch(typeof(ZNet), "SetReferencePosition")]
		private static class HoldTravelReferencePatch
		{
			private unsafe static void Prefix(ref Vector3 pos)
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Unknown result type (might be due to invalid IL or missing references)
				Session session = Instance?._session;
				if (session == null)
				{
					return;
				}
				Phase phase = session.Phase;
				bool flag = (uint)phase <= 2u;
				Vector3 val = (flag ? session.ParkingPosition : session.Arrival);
				Vector3 val2 = pos - val;
				if (!(((Vector3)(ref val2)).sqrMagnitude <= 1f))
				{
					if (!session.ForeignReferenceLogged)
					{
						session.ForeignReferenceLogged = true;
						StackFrame frame = new StackTrace(2, fNeedFileInfo: false).GetFrame(0);
						ManualLogSource logger = ((BaseUnityPlugin)Instance).Logger;
						string[] obj = new string[8] { "Network reference pulled to ", null, null, null, null, null, null, null };
						val2 = pos;
						obj[1] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
						obj[2] = " by ";
						obj[3] = frame?.GetMethod()?.DeclaringType?.FullName ?? "unknown";
						obj[4] = " during ";
						obj[5] = session.Phase.ToString();
						obj[6] = "; kept at ";
						val2 = val;
						obj[7] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
						logger.LogWarning((object)string.Concat(obj));
					}
					pos = val;
				}
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "RemoveObjects")]
		[HarmonyPriority(800)]
		private static class PreserveTravellingPlayerPatch
		{
			private static void Prefix(List<ZDO> currentNearObjects)
			{
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				Session session = Instance?._session;
				if (session != null && !((Object)(object)session.Player == (Object)null))
				{
					ZNetView component = ((Component)session.Player).GetComponent<ZNetView>();
					ZDO val = ((component != null) ? component.GetZDO() : null);
					if (val != null && !currentNearObjects.Contains(val))
					{
						currentNearObjects.Add(val);
						((BaseUnityPlugin)Instance).Logger.LogWarning((object)("Keeping player in transit in the scene; player=" + ((object)((Component)session.Player).transform.position/*cast due to .constrained prefix*/).ToString() + "; ZDO=" + ((object)val.GetPosition()/*cast due to .constrained prefix*/).ToString() + "; reference=" + ((object)ZNet.instance.GetReferencePosition()/*cast due to .constrained prefix*/).ToString()));
					}
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
		private static class MapClickPatch
		{
			private static bool Prefix(Minimap __instance)
			{
				PortalNetworkPlugin? instance = Instance;
				if (instance == null || instance._session?.Phase != Phase.Selecting)
				{
					return true;
				}
				Instance.SelectAtPointer(__instance);
				Instance.Confirm();
				return false;
			}
		}

		[HarmonyPatch(typeof(Minimap), "Update")]
		private static class BrowsePortalPinsPatch
		{
			private static void Prefix(Minimap __instance)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Invalid comparison between Unknown and I4
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)Instance == (Object)null) && (int)__instance.m_mode == 2 && Instance._session == null && !((Object)(object)Player.m_localPlayer == (Object)null))
				{
					KeyboardShortcut value = Instance._portalMapKey.Value;
					if (((KeyboardShortcut)(ref value)).IsDown() && ((Object)(object)Chat.instance == (Object)null || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsActive() && !InventoryGui.IsVisible())
					{
						Instance.ToggleBrowsePins();
					}
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "SetMapMode")]
		private static class KeepMapOpenPatch
		{
			private static bool Prefix(MapMode mode)
			{
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Invalid comparison between Unknown and I4
				PortalNetworkPlugin? instance = Instance;
				if (instance == null || instance._session?.Phase != Phase.Selecting || (int)mode == 2)
				{
					return true;
				}
				Instance.BeginReturn("Travel cancelled");
				return false;
			}
		}

		[HarmonyPatch(typeof(Minimap), "UpdateExplore")]
		private static class LimboExplorationPatch
		{
			private static bool Prefix()
			{
				bool flag = Instance?._session == null;
				if (!flag)
				{
					Phase phase = Instance._session.Phase;
					bool flag2 = (uint)phase <= 1u;
					flag = !flag2;
				}
				return flag;
			}
		}

		[HarmonyPatch(typeof(Hud), "UpdateBlackScreen")]
		private static class LoadingScreenPatch
		{
			private static void Postfix(Hud __instance)
			{
				PortalNetworkPlugin? instance = Instance;
				if (instance != null && instance._session?.Phase == Phase.Selecting)
				{
					((Component)__instance.m_loadingScreen).gameObject.SetActive(false);
				}
			}
		}

		[HarmonyPatch(typeof(Game), "Start")]
		[HarmonyPriority(0)]
		private static class RecipePatch
		{
			private static void Postfix()
			{
				Instance?.ApplyRecipeMultiplier();
			}
		}

		[HarmonyPatch(typeof(PlayerProfile), "SaveLogoutPoint")]
		private static class SafeLogoutPatch
		{
			private static bool Prefix(PlayerProfile __instance)
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				Session session = Instance?._session;
				if (session == null)
				{
					return true;
				}
				__instance.SetLogoutPoint(session.LogoutPosition);
				return false;
			}
		}

		private sealed class PortalRecord
		{
			public ZDOID Id;

			public Vector3 Position;

			public Quaternion Rotation;

			public string Name = "";
		}

		private sealed class ServerTravel
		{
			public long Nonce;

			public ZDOID Origin;

			public Vector3 OriginPosition;

			public Vector3 ParkingPosition;

			public ZDOID Destination;

			public Vector3 DestinationPosition;

			public float LastSeen;
		}

		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static class RpcRegistrationPatch
		{
			private static void Postfix()
			{
				Instance?.RegisterNetworkRpc();
			}
		}

		[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
		private static class DirectConnectionPatch
		{
			private static void Postfix(ZNetPeer peer)
			{
				Instance?.RegisterDirectRpc(peer);
			}
		}

		[HarmonyPatch(typeof(ZRoutedRpc), "RPC_RoutedRPC")]
		private static class AuthenticatePortalRoutePatch
		{
			private static readonly HashSet<int> Methods = new HashSet<int>(new string[12]
			{
				"RazaPortal2_Hello", "RazaPortal2_HelloReply", "RazaPortal2_State", "RazaPortal2_Snapshot", "RazaPortal2_SnapshotReply", "RazaPortal2_Depart", "RazaPortal2_DepartReply", "RazaPortal2_Complete", "RazaPortal2_Resolve", "RazaPortal2_ResolveReply",
				"RazaPortal2_Verify", "RazaPortal2_VerifyReply"
			}.Select((string name) => StringExtensionMethods.GetStableHashCode(name)));

			private static bool Prefix(ZRpc rpc, ZPackage pkg)
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)ZNet.instance == (Object)null)
				{
					return true;
				}
				int pos = pkg.GetPos();
				long num;
				int item;
				try
				{
					pkg.ReadLong();
					num = pkg.ReadLong();
					pkg.ReadLong();
					pkg.ReadZDOID();
					item = pkg.ReadInt();
				}
				catch (Exception)
				{
					return true;
				}
				finally
				{
					pkg.SetPos(pos);
				}
				if (!Methods.Contains(item))
				{
					return true;
				}
				if (ZNet.instance.IsServer())
				{
					ZNetPeer val = ((IEnumerable<ZNetPeer>)ZNet.instance.GetPeers()).FirstOrDefault((Func<ZNetPeer, bool>)((ZNetPeer p) => p.m_rpc == rpc && p.IsReady()));
					if (val != null)
					{
						return val.m_uid == num;
					}
					return false;
				}
				if (rpc == ZNet.instance.GetServerRPC() && (Object)(object)Instance != (Object)null)
				{
					return Instance.IsServerReply(num);
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(Piece), "SetCreator")]
		private static class RecordPortalCostPatch
		{
			private static void Prefix(Piece __instance, out bool __state)
			{
				__state = IsPortalPiece(__instance) && __instance.GetCreator() == 0;
			}

			private static void Postfix(Piece __instance, bool __state)
			{
				if (__state && __instance.GetCreator() != 0L)
				{
					Instance?.RecordPaidResources(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(Piece), "DropResources")]
		private static class RefundPortalCostPatch
		{
			[HarmonyPriority(0)]
			private static void Prefix(Piece __instance, out Requirement[]? __state)
			{
				__state = null;
				if (!((Object)(object)Instance == (Object)null) && IsPortalPiece(__instance))
				{
					Requirement[] resources = Instance.RefundResources(__instance);
					__state = __instance.m_resources;
					__instance.m_resources = resources;
				}
			}

			private static Exception? Finalizer(Piece __instance, Requirement[]? __state, Exception? __exception)
			{
				if (__state != null)
				{
					__instance.m_resources = __state;
				}
				return __exception;
			}
		}

		public const string Guid = "br.com.raza.portalnetwork.multiplayer";

		public const string Version = "1.0.0";

		private static readonly int WoodPortal = StringExtensionMethods.GetStableHashCode("portal_wood");

		private static readonly int StonePortal = StringExtensionMethods.GetStableHashCode("portal_stone");

		private static readonly FieldInfo Teleporting = AccessTools.Field(typeof(Player), "m_teleporting");

		private static readonly FieldInfo DistantTeleport = AccessTools.Field(typeof(Player), "m_distantTeleport");

		private static readonly FieldInfo TeleportTimer = AccessTools.Field(typeof(Player), "m_teleportTimer");

		private static readonly FieldInfo TeleportTargetPos = AccessTools.Field(typeof(Player), "m_teleportTargetPos");

		private static readonly FieldInfo TeleportTargetRot = AccessTools.Field(typeof(Player), "m_teleportTargetRot");

		private static readonly FieldInfo TeleportFromPos = AccessTools.Field(typeof(Player), "m_teleportFromPos");

		private static readonly FieldInfo TeleportFromRot = AccessTools.Field(typeof(Player), "m_teleportFromRot");

		private static readonly FieldInfo MaxAirAltitude = AccessTools.Field(typeof(Character), "m_maxAirAltitude");

		private static readonly FieldInfo PortalHadTarget = AccessTools.Field(typeof(TeleportWorld), "m_hadTarget");

		private static readonly FieldInfo PortalEffectActive = AccessTools.Field(typeof(EffectFade), "m_active");

		private static readonly FieldInfo TerrainQueue = AccessTools.Field(typeof(HeightmapBuilder), "m_toBuild");

		private static readonly FieldInfo TerrainLock = AccessTools.Field(typeof(HeightmapBuilder), "m_lock");

		private static readonly MethodInfo CreateLocalZones = AccessTools.Method(typeof(ZoneSystem), "CreateLocalZones", (Type[])null, (Type[])null);

		private static readonly MethodInfo ScreenToWorld = AccessTools.Method(typeof(Minimap), "ScreenToWorldPoint", (Type[])null, (Type[])null);

		private static readonly MethodInfo GetClosestPin = AccessTools.Method(typeof(Minimap), "GetClosestPin", new Type[3]
		{
			typeof(Vector3),
			typeof(float),
			typeof(bool)
		}, (Type[])null);

		private readonly Dictionary<PinData, ZDOID> _pins = new Dictionary<PinData, ZDOID>();

		private readonly Dictionary<ZDOID, PinData> _browsePins = new Dictionary<ZDOID, PinData>();

		private readonly Dictionary<ZDOID, bool> _observedPortalEffects = new Dictionary<ZDOID, bool>();

		private readonly Dictionary<Requirement, int> _baseCosts = new Dictionary<Requirement, int>();

		private readonly List<RectSnapshot> _mapLayout = new List<RectSnapshot>();

		private GameObject? _spaceBackdrop;

		private ConfigEntry<float> _costMultiplier;

		private ConfigEntry<bool> _enabled;

		private ConfigEntry<float> _selectionTimeout;

		private ConfigEntry<KeyboardShortcut> _portalMapKey;

		private Session? _session;

		private float _nextRefresh;

		private float _nextSelectionSnapshot;

		private float _localPlayerStartedAt = float.NegativeInfinity;

		private float _arrivalIgnoreUntil = float.NegativeInfinity;

		private float _arrivalGroundWatchUntil = float.NegativeInfinity;

		private float _arrivalInitialGround;

		private Vector3 _arrivalGroundWatchPoint;

		private float _nextBrowseRefresh;

		private bool _browsePinsVisible;

		private bool _zoneBoostFailed;

		private bool _oldNoMap;

		private static PortalNetworkPlugin? Instance;

		private static MethodInfo? _progressionPortalGuard;

		private const string RpcHello = "RazaPortal2_Hello";

		private const string RpcHelloReply = "RazaPortal2_HelloReply";

		private const string RpcState = "RazaPortal2_State";

		private const string RpcSnapshot = "RazaPortal2_Snapshot";

		private const string RpcSnapshotReply = "RazaPortal2_SnapshotReply";

		private const string RpcDepart = "RazaPortal2_Depart";

		private const string RpcDepartReply = "RazaPortal2_DepartReply";

		private const string RpcComplete = "RazaPortal2_Complete";

		private const string RpcResolve = "RazaPortal2_Resolve";

		private const string RpcResolveReply = "RazaPortal2_ResolveReply";

		private const string RpcVerify = "RazaPortal2_Verify";

		private const string RpcVerifyReply = "RazaPortal2_VerifyReply";

		private const int Protocol = 6;

		private const float ArrivalSupportRadius = 32f;

		private readonly Dictionary<ZDOID, PortalRecord> _serverPortals = new Dictionary<ZDOID, PortalRecord>();

		private readonly Dictionary<long, ServerTravel> _serverTravels = new Dictionary<long, ServerTravel>();

		private ZRoutedRpc? _registeredRpc;

		private bool _remoteServerSupportsNetwork;

		private bool _remoteNetworkEnabled;

		private readonly HashSet<long> _networkClients = new HashSet<long>();

		private int _stateRevision;

		private int _remoteStateRevision = -1;

		private float _nextConfigCheck;

		private DateTime _configWriteTime;

		private float _nextHello;

		private float _remoteCostMultiplier = 1f;

		private float _remoteSelectionTimeout = 60f;

		private long _pendingBrowseNonce;

		private const string PaidCostKey = "Portais.PaidResources.v1";

		private static readonly MethodInfo CloneResource = AccessTools.Method(typeof(object), "MemberwiseClone", (Type[])null, (Type[])null);

		private float EffectiveSelectionTimeout
		{
			get
			{
				if (!((Object)(object)ZNet.instance != (Object)null) || ZNet.instance.IsServer())
				{
					return _selectionTimeout.Value;
				}
				return _remoteSelectionTimeout;
			}
		}

		private float EffectiveCostMultiplier
		{
			get
			{
				if (ServerSupportsNetwork)
				{
					if (!ZNet.instance.IsServer())
					{
						return _remoteCostMultiplier;
					}
					return _costMultiplier.Value;
				}
				return 1f;
			}
		}

		private bool ServerSupportsNetwork
		{
			get
			{
				if ((Object)(object)ZNet.instance != (Object)null)
				{
					if (!ZNet.instance.IsServer())
					{
						if (_remoteServerSupportsNetwork)
						{
							return _remoteNetworkEnabled;
						}
						return false;
					}
					return _enabled.Value;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enables the portal network. In multiplayer only the server value controls the clients. Disabling restores vanilla behaviour and safely returns players in transit.");
			_enabled.SettingChanged += delegate
			{
				OnEnabledSettingChanged();
			};
			if (Chainloader.PluginInfos.TryGetValue("com.orianaventure.mod.WorldAdvancementProgression", out var value))
			{
				Type type = ((object)value.Instance).GetType().Assembly.GetTypes().FirstOrDefault((Type type2) => type2.Name == "Patch_TeleportWorld_Teleport");
				_progressionPortalGuard = ((type == null) ? null : AccessTools.Method(type, "Prefix", (Type[])null, (Type[])null));
			}
			_costMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "PortalCostMultiplier", 1f, new ConfigDescription("Multiplier for the portal build recipe. Amounts are rounded up.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
			_costMultiplier.SettingChanged += delegate
			{
				OnEnabledSettingChanged();
			};
			_selectionTimeout = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SelectionTimeout", 60f, new ConfigDescription("Seconds to pick a destination in the limbo before returning to the origin. 0 = no limit. In multiplayer the server value is used.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f), Array.Empty<object>()));
			_selectionTimeout.SettingChanged += delegate
			{
				OnEnabledSettingChanged();
			};
			_portalMapKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Map", "PortalMarkersKey", new KeyboardShortcut((KeyCode)112, Array.Empty<KeyCode>()), "Key to show or hide portals while the regular map is open.");
			new Harmony("br.com.raza.portalnetwork.multiplayer").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded. Clients without the mod use vanilla portals.");
		}

		private static bool IsVanillaPortal(ZDO? zdo)
		{
			if (zdo != null)
			{
				if (zdo.GetPrefab() != WoodPortal)
				{
					return zdo.GetPrefab() == StonePortal;
				}
				return true;
			}
			return false;
		}

		private static ZDO? GetLivePortal(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)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (ZDOMan.instance == null || id == ZDOID.None)
			{
				return null;
			}
			ZDO zDO = ZDOMan.instance.GetZDO(id);
			if (!IsVanillaPortal(zDO))
			{
				return null;
			}
			if (!ZDOMan.instance.GetPortalList().Contains(zDO))
			{
				return null;
			}
			return zDO;
		}

		private static bool CanUse(Player player, TeleportWorld portal)
		{
			if ((Object)(object)ZoneSystem.instance == (Object)null || (Object)(object)ZNet.instance == (Object)null)
			{
				return false;
			}
			if (_progressionPortalGuard != null)
			{
				object obj = _progressionPortalGuard.Invoke(null, new object[1] { player });
				if (obj is bool && !(bool)obj)
				{
					return false;
				}
			}
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)32))
			{
				((Character)player).Message((MessageType)2, "$msg_blocked", 0, (Sprite)null, false);
				return false;
			}
			float num = default(float);
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)33) && (RandEventSystem.instance.GetBossEvent() != null || (ZoneSystem.instance.GetGlobalKey((GlobalKeys)50, ref num) && num > 0f)))
			{
				((Character)player).Message((MessageType)2, "$msg_blockedbyboss", 0, (Sprite)null, false);
				return false;
			}
			if (!((Humanoid)player).IsTeleportable(portal.m_allowAllItems))
			{
				((Character)player).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false);
				return false;
			}
			return true;
		}

		private unsafe void Enter(Player player, TeleportWorld portal)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			if (!ServerSupportsNetwork || _session != null || ((Character)player).IsTeleporting() || (Object)(object)Minimap.instance == (Object)null)
			{
				return;
			}
			if (Time.realtimeSinceStartup - _localPlayerStartedAt < 5f)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Portal entry ignored while the character is loading");
			}
			else
			{
				if (Time.realtimeSinceStartup < _arrivalIgnoreUntil)
				{
					return;
				}
				ZNetView component = ((Component)portal).GetComponent<ZNetView>();
				ZDO val = ((component != null) ? component.GetZDO() : null);
				if (!IsVanillaPortal(val) || !CanUse(player, portal))
				{
					return;
				}
				Session session = new Session
				{
					Player = player,
					Origin = val.m_uid,
					OriginPosition = ((Component)player).transform.position,
					LogoutPosition = ((Component)player).transform.position,
					OriginRotation = ((Component)player).transform.rotation,
					ParkingPosition = ParkingFor(player),
					Phase = Phase.Entering,
					PhaseStart = Time.realtimeSinceStartup,
					Nonce = DateTime.UtcNow.Ticks,
					Body = ((Component)player).GetComponent<Rigidbody>()
				};
				if ((Object)(object)session.Body != (Object)null)
				{
					session.WasKinematic = session.Body.isKinematic;
					session.WasDetectingCollisions = session.Body.detectCollisions;
					if (!session.Body.isKinematic)
					{
						session.Body.linearVelocity = Vector3.zero;
					}
					session.Body.isKinematic = true;
					session.Body.detectCollisions = false;
				}
				_oldNoMap = Game.m_noMap;
				_session = session;
				SetTravelTarget(session, session.ParkingPosition, session.OriginRotation);
				Game instance = Game.instance;
				if (instance != null)
				{
					PlayerProfile playerProfile = instance.GetPlayerProfile();
					if (playerProfile != null)
					{
						playerProfile.SetLogoutPoint(session.LogoutPosition);
					}
				}
				SetTravelFlag(player, active: true);
				Move(session, session.ParkingPosition, session.OriginRotation);
				RequestPortalSnapshot(session);
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				ZDOID uid = val.m_uid;
				string? text = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
				Vector3 parkingPosition = session.ParkingPosition;
				logger.LogInfo((object)("Entry animation started at origin " + text + "; limbo=" + ((object)(*(Vector3*)(&parkingPosition))/*cast due to .constrained prefix*/).ToString()));
			}
		}

		private void OpenDestinationMap(Session session)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Minimap.instance == (Object)null || !session.SnapshotReady)
			{
				BeginReturn("Portal network unavailable; returning");
				return;
			}
			session.Phase = Phase.Selecting;
			session.PhaseStart = Time.realtimeSinceStartup;
			SetTravelFlag(session.Player, active: false);
			Game.m_noMap = false;
			ExpandDestinationMap();
			ShowSpaceBackdrop();
			Minimap.instance.ShowPointOnMap(session.OriginPosition);
			HideTravelScreen();
			RefreshPins();
			_nextSelectionSnapshot = Time.realtimeSinceStartup;
			((Character)session.Player).Message((MessageType)2, "Select a destination portal", 0, (Sprite)null, false);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Destination map opened; map=" + ((object)Unsafe.As<MapMode, MapMode>(ref Minimap.instance.m_mode)/*cast due to .constrained prefix*/).ToString() + "; portals=" + _pins.Count));
		}

		private static void SetTravelTarget(Session session, Vector3 position, Quaternion rotation)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			TeleportTargetPos?.SetValue(session.Player, position);
			TeleportTargetRot?.SetValue(session.Player, rotation);
			TeleportFromPos?.SetValue(session.Player, session.OriginPosition);
			TeleportFromRot?.SetValue(session.Player, session.OriginRotation);
		}

		private static void SetTravelFlag(Player player, bool active)
		{
			Teleporting.SetValue(player, active);
			DistantTeleport.SetValue(player, active);
			TeleportTimer.SetValue(player, 0f);
		}

		private static Vector3 ParkingSlot(int slot)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(12000f + (float)(slot % 64) * 512f, 1000f, 12000f + (float)(slot / 64) * 512f);
		}

		private static Vector3 ParkingFor(Player player)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			ulong playerID = (ulong)player.GetPlayerID();
			playerID ^= playerID >> 33;
			playerID *= 18397679294719823053uL;
			playerID ^= playerID >> 33;
			return ParkingSlot(1024 + (int)(playerID % 3072));
		}

		private void ApplyRecipeMultiplier()
		{
			if ((Object)(object)ObjectDB.instance == (Object)null)
			{
				return;
			}
			float effectiveCostMultiplier = EffectiveCostMultiplier;
			foreach (Piece allBuildPiece in ObjectDB.instance.GetAllBuildPieces(true))
			{
				string prefabName = Utils.GetPrefabName(((Component)allBuildPiece).gameObject);
				if (prefabName != "portal_wood" && prefabName != "portal_stone")
				{
					continue;
				}
				Requirement[] resources = allBuildPiece.m_resources;
				foreach (Requirement val in resources)
				{
					if (!_baseCosts.TryGetValue(val, out var value))
					{
						value = val.m_amount;
						_baseCosts.Add(val, value);
					}
					val.m_amount = ((effectiveCostMultiplier == 1f) ? value : Mathf.Max(1, Mathf.CeilToInt((float)value * effectiveCostMultiplier)));
				}
			}
		}

		private static void Move(Session session, Vector3 position, Quaternion rotation)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			ZNetView component = ((Component)session.Player).GetComponent<ZNetView>();
			ZDO obj = ((component != null) ? component.GetZDO() : null);
			if (obj != null)
			{
				obj.SetPosition(position);
			}
			SetTravelTarget(session, position, rotation);
			((Component)session.Player).transform.SetPositionAndRotation(position, rotation);
			MaxAirAltitude.SetValue(session.Player, position.y);
			if ((Object)(object)session.Body != (Object)null)
			{
				session.Body.position = position;
				session.Body.rotation = rotation;
				if (!session.Body.isKinematic)
				{
					session.Body.linearVelocity = Vector3.zero;
				}
			}
			ZNet.instance.SetReferencePosition(position);
		}

		private void RefreshPins()
		{
			//IL_0039: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			if (_session == null || (Object)(object)Minimap.instance == (Object)null)
			{
				return;
			}
			KeyValuePair<PinData, ZDOID>[] array = _pins.ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				KeyValuePair<PinData, ZDOID> keyValuePair = array[i];
				if (!_serverPortals.TryGetValue(keyValuePair.Value, out PortalRecord value) || !(value.Id != _session.Origin) || !(keyValuePair.Key.m_pos == value.Position) || !(keyValuePair.Key.m_name == DisplayPortalName(value.Name)))
				{
					Minimap.instance.RemovePin(keyValuePair.Key);
					_pins.Remove(keyValuePair.Key);
				}
			}
			HashSet<ZDOID> hashSet = new HashSet<ZDOID>(_pins.Values);
			foreach (PortalRecord value2 in _serverPortals.Values)
			{
				if (!(value2.Id == _session.Origin) && !hashSet.Contains(value2.Id))
				{
					string text = value2.Name;
					if (string.IsNullOrWhiteSpace(text))
					{
						text = "Unnamed portal";
					}
					PinData key = Minimap.instance.AddPin(value2.Position, (PinType)3, text, false, false, 0L, default(PlatformUserID));
					_pins.Add(key, value2.Id);
				}
			}
			if (_session.Selected != ZDOID.None && !_serverPortals.ContainsKey(_session.Selected))
			{
				_session.Selected = ZDOID.None;
				_session.SelectedName = "";
			}
			_nextRefresh = Time.realtimeSinceStartup + 1f;
		}

		private void ToggleBrowsePins()
		{
			if (_session != null || (Object)(object)Minimap.instance == (Object)null || !ServerSupportsNetwork)
			{
				return;
			}
			_browsePinsVisible = !_browsePinsVisible;
			if (_browsePinsVisible)
			{
				RequestBrowseSnapshot();
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)2, "Loading portals...", 0, (Sprite)null, false);
				}
			}
			else
			{
				ClearBrowsePins();
			}
		}

		private void RefreshBrowsePins()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			if (!_browsePinsVisible || (Object)(object)Minimap.instance == (Object)null || _session != null)
			{
				return;
			}
			KeyValuePair<ZDOID, PinData>[] array = _browsePins.ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				KeyValuePair<ZDOID, PinData> keyValuePair = array[i];
				if (!_serverPortals.TryGetValue(keyValuePair.Key, out PortalRecord value) || !(keyValuePair.Value.m_pos == value.Position) || !(keyValuePair.Value.m_name == DisplayPortalName(value.Name)))
				{
					Minimap.instance.RemovePin(keyValuePair.Value);
					_browsePins.Remove(keyValuePair.Key);
				}
			}
			foreach (PortalRecord value2 in _serverPortals.Values)
			{
				if (!_browsePins.ContainsKey(value2.Id))
				{
					_browsePins.Add(value2.Id, Minimap.instance.AddPin(value2.Position, (PinType)3, DisplayPortalName(value2.Name), false, false, 0L, default(PlatformUserID)));
				}
			}
		}

		private static string DisplayPortalName(string name)
		{
			if (!string.IsNullOrWhiteSpace(name))
			{
				return name;
			}
			return "Unnamed portal";
		}

		private void ClearBrowsePins()
		{
			if ((Object)(object)Minimap.instance != (Object)null)
			{
				foreach (PinData value in _browsePins.Values)
				{
					Minimap.instance.RemovePin(value);
				}
			}
			_browsePins.Clear();
		}

		private void UpdateBrowseMap()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			if (_browsePinsVisible)
			{
				if (_session != null || (Object)(object)Minimap.instance == (Object)null || (int)Minimap.instance.m_mode != 2)
				{
					ClearBrowsePins();
					_browsePinsVisible = false;
				}
				else if (Time.realtimeSinceStartup >= _nextBrowseRefresh)
				{
					RequestBrowseSnapshot();
				}
			}
		}

		private unsafe void SelectAtPointer(Minimap map)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			if (_session == null || _session.Phase != Phase.Selecting)
			{
				return;
			}
			Vector3 val = (Vector3)ScreenToWorld.Invoke(map, new object[1] { Input.mousePosition });
			foreach (PinData key in _pins.Keys)
			{
				key.m_save = true;
			}
			PinData val2;
			try
			{
				val2 = (PinData)GetClosestPin.Invoke(map, new object[3]
				{
					val,
					map.m_removeRadius * map.LargeZoom * 2f,
					true
				});
			}
			finally
			{
				foreach (PinData key2 in _pins.Keys)
				{
					key2.m_save = false;
				}
			}
			if (val2 != null && _pins.ContainsKey(val2))
			{
				_session.Selected = _pins[val2];
				_session.SelectedName = val2.m_name;
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				string[] obj = new string[5] { "Destination selected: ", val2.m_name, " (", null, null };
				ZDOID selected = _session.Selected;
				obj[3] = ((object)(*(ZDOID*)(&selected))/*cast due to .constrained prefix*/).ToString();
				obj[4] = ")";
				logger.LogInfo((object)string.Concat(obj));
			}
		}

		private unsafe void Confirm()
		{
			//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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			Session session = _session;
			if (session != null && session.Phase == Phase.Selecting && !(session.Selected == ZDOID.None))
			{
				if (!_serverPortals.ContainsKey(session.Selected))
				{
					((Character)session.Player).Message((MessageType)2, "Destination portal is no longer available", 0, (Sprite)null, false);
					session.Selected = ZDOID.None;
					RefreshPins();
					return;
				}
				session.Destination = session.Selected;
				session.Phase = Phase.Authorizing;
				session.PhaseStart = Time.realtimeSinceStartup;
				PortalRecord portalRecord = _serverPortals[session.Destination];
				SetTravelTarget(session, portalRecord.Position + portalRecord.Rotation * Vector3.forward + Vector3.up, portalRecord.Rotation);
				PrioritizeTerrain(portalRecord.Position);
				SetTravelFlag(session.Player, active: true);
				CoverWorld();
				ClearPins();
				Game.m_noMap = _oldNoMap;
				Minimap.instance.SetMapMode((MapMode)1);
				RequestDestinationAuthorization(session);
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				ZDOID destination = session.Destination;
				logger.LogInfo((object)("Requesting destination authorization " + ((object)(*(ZDOID*)(&destination))/*cast due to .constrained prefix*/).ToString()));
			}
		}

		private void BeginReturn(string message)
		{
			//IL_0045: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			Session session = _session;
			if (session != null)
			{
				((Character)session.Player).Message((MessageType)2, message, 0, (Sprite)null, false);
				CoverWorld();
				ClearPins();
				Game.m_noMap = _oldNoMap;
				session.Phase = Phase.Returning;
				session.PhaseStart = Time.realtimeSinceStartup;
				SetTravelTarget(session, session.OriginPosition, session.OriginRotation);
				SetTravelFlag(session.Player, active: true);
				if ((Object)(object)Minimap.instance != (Object)null)
				{
					Minimap.instance.SetMapMode((MapMode)1);
				}
				session.Arrival = session.OriginPosition;
				session.ArrivalRotation = session.OriginRotation;
				PrioritizeTerrain(session.Arrival);
				Move(session, session.Arrival, session.ArrivalRotation);
			}
		}

		private unsafe void AbortForDeath(Player player)
		{
			//IL_0033: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Invalid comparison between Unknown and I4
			Session session = _session;
			if (session != null && !((Object)(object)session.Player != (Object)(object)player))
			{
				_session = null;
				ClearPins();
				Game.m_noMap = _oldNoMap;
				Move(session, session.LogoutPosition, session.OriginRotation);
				if ((Object)(object)session.Body != (Object)null)
				{
					session.Body.detectCollisions = session.WasDetectingCollisions;
					session.Body.isKinematic = session.WasKinematic;
				}
				SetTravelFlag(player, active: false);
				if ((Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode == 2)
				{
					Minimap.instance.SetMapMode((MapMode)1);
				}
				CompleteServerTravel(session);
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				Vector3 logoutPosition = session.LogoutPosition;
				logger.LogWarning((object)("Death during travel; tombstone position restored to " + ((object)(*(Vector3*)(&logoutPosition))/*cast due to .constrained prefix*/).ToString()));
			}
		}

		private void PrioritizeTerrain(Vector3 point)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			HeightmapBuilder instance = HeightmapBuilder.instance;
			if (instance == null || (Object)(object)ZoneSystem.instance == (Object)null || WorldGenerator.instance == null)
			{
				return;
			}
			GameObject zonePrefab = ZoneSystem.instance.m_zonePrefab;
			Heightmap terrain = ((zonePrefab != null) ? zonePrefab.GetComponentInChildren<Heightmap>() : null);
			if ((Object)(object)terrain == (Object)null)
			{
				return;
			}
			Vector3 center = ZoneSystem.GetZonePos(ZoneSystem.GetZone(point));
			instance.IsTerrainReady(center, terrain.m_width, terrain.m_scale, terrain.IsDistantLod, WorldGenerator.instance);
			if (TerrainQueue == null || TerrainLock == null)
			{
				return;
			}
			object value = TerrainLock.GetValue(instance);
			if (value == null)
			{
				return;
			}
			lock (value)
			{
				if (TerrainQueue.GetValue(instance) is List<HMBuildData> list)
				{
					int num = list.FindIndex((HMBuildData data) => data.IsEqual(center, terrain.m_width, terrain.m_scale, terrain.IsDistantLod, WorldGenerator.instance));
					if (num > 0)
					{
						HMBuildData item = list[num];
						list.RemoveAt(num);
						list.Insert(0, item);
					}
				}
			}
		}

		private void BoostDestinationZones(Session session)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (_zoneBoostFailed || (Object)(object)ZoneSystem.instance == (Object)null || CreateLocalZones == null || ZoneSystem.instance.IsActiveAreaLoaded() || Time.realtimeSinceStartup < session.NextZoneBoost)
			{
				return;
			}
			session.NextZoneBoost = Time.realtimeSinceStartup + 0.05f;
			try
			{
				CreateLocalZones.Invoke(ZoneSystem.instance, new object[1] { session.Arrival });
			}
			catch (Exception ex)
			{
				_zoneBoostFailed = true;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Extra zone preloading unavailable; keeping vanilla loading: " + ex.Message));
			}
		}

		private void ClearPins()
		{
			HideSpaceBackdrop();
			RestoreDestinationMap();
			if ((Object)(object)Minimap.instance != (Object)null)
			{
				foreach (PinData key in _pins.Keys)
				{
					Minimap.instance.RemovePin(key);
				}
			}
			_pins.Clear();
		}

		private void ShowSpaceBackdrop()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00c7: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_spaceBackdrop != (Object)null) && !((Object)(object)Minimap.instance == (Object)null))
			{
				Texture texture = ((Graphic)Minimap.instance.m_mapImageLarge).material.GetTexture("_SpaceTex");
				Transform transform = Minimap.instance.m_largeRoot.transform;
				if ((Object)(object)texture == (Object)null || (Object)(object)transform.parent == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Vanilla space texture unavailable for the map backdrop");
					return;
				}
				_spaceBackdrop = new GameObject("PortalSpaceBackdrop", new Type[2]
				{
					typeof(RectTransform),
					typeof(RawImage)
				});
				RectTransform val = (RectTransform)_spaceBackdrop.transform;
				((Transform)val).SetParent(transform.parent, false);
				val.anchorMin = Vector2.zero;
				val.anchorMax = Vector2.one;
				val.offsetMin = Vector2.zero;
				val.offsetMax = Vector2.zero;
				((Transform)val).SetSiblingIndex(transform.GetSiblingIndex());
				RawImage component = _spaceBackdrop.GetComponent<RawImage>();
				component.texture = texture;
				((Graphic)component).color = Color.white;
				((Graphic)component).raycastTarget = false;
				component.uvRect = new Rect(0f, 0f, (float)Screen.width / 1024f, (float)Screen.height / 1024f);
			}
		}

		private void HideSpaceBackdrop()
		{
			if (!((Object)(object)_spaceBackdrop == (Object)null))
			{
				Object.Destroy((Object)(object)_spaceBackdrop);
				_spaceBackdrop = null;
			}
		}

		private void ExpandDestinationMap()
		{
			if (_mapLayout.Count == 0 && !((Object)(object)Minimap.instance == (Object)null))
			{
				Transform transform = Minimap.instance.m_largeRoot.transform;
				ExpandToRoot(((Graphic)Minimap.instance.m_mapImageLarge).rectTransform, transform);
				ExpandToRoot(Minimap.instance.m_pinRootLarge, transform);
				ExpandToRoot(Minimap.instance.m_pinNameRootLarge, transform);
			}
		}

		private void ExpandToRoot(RectTransform rect, Transform root)
		{
			Transform val = (Transform)(object)rect;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
			{
				RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
				if (val2 != null)
				{
					ExpandRect(val2);
				}
				val = val.parent;
			}
		}

		private void ExpandRect(RectTransform rect)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (!_mapLayout.Any((RectSnapshot snapshot) => (Object)(object)snapshot.Rect == (Object)(object)rect))
			{
				_mapLayout.Add(new RectSnapshot
				{
					Rect = rect,
					AnchorMin = rect.anchorMin,
					AnchorMax = rect.anchorMax,
					OffsetMin = rect.offsetMin,
					OffsetMax = rect.offsetMax
				});
				rect.anchorMin = Vector2.zero;
				rect.anchorMax = Vector2.one;
				rect.offsetMin = Vector2.zero;
				rect.offsetMax = Vector2.zero;
			}
		}

		private void RestoreDestinationMap()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			foreach (RectSnapshot item in _mapLayout)
			{
				if (!((Object)(object)item.Rect == (Object)null))
				{
					item.Rect.anchorMin = item.AnchorMin;
					item.Rect.anchorMax = item.AnchorMax;
					item.Rect.offsetMin = item.OffsetMin;
					item.Rect.offsetMax = item.OffsetMax;
				}
			}
			_mapLayout.Clear();
		}

		private static void CoverWorld()
		{
			if (!((Object)(object)Hud.instance == (Object)null))
			{
				((Component)Hud.instance.m_loadingScreen).gameObject.SetActive(true);
				Hud.instance.m_loadingScreen.alpha = 1f;
				Hud.instance.m_teleportingProgress.SetActive(true);
			}
		}

		private static void HideTravelScreen()
		{
			if ((Object)(object)Hud.instance != (Object)null)
			{
				((Component)Hud.instance.m_loadingScreen).gameObject.SetActive(false);
			}
		}

		private void Finish()
		{
			//IL_0016: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			Session session = _session;
			if (session == null)
			{
				return;
			}
			if (session.Phase == Phase.Verifying)
			{
				ArmArrivalGroundWatch(session.Arrival);
			}
			if ((Object)(object)session.Body != (Object)null)
			{
				session.Body.detectCollisions = session.WasDetectingCollisions;
				session.Body.isKinematic = session.WasKinematic;
			}
			SetTravelFlag(session.Player, active: false);
			Game instance = Game.instance;
			if (instance != null)
			{
				PlayerProfile playerProfile = instance.GetPlayerProfile();
				if (playerProfile != null)
				{
					playerProfile.SetLogoutPoint(((Component)session.Player).transform.position);
				}
			}
			CompleteServerTravel(session);
			if (session.Phase == Phase.Verifying)
			{
				Game instance2 = Game.instance;
				if (instance2 != null)
				{
					instance2.IncrementPlayerStat((PlayerStatType)15, 1f, false);
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Travel finished at " + ((object)((Component)session.Player).transform.position/*cast due to .constrained prefix*/).ToString() + "; preparation=" + (Time.realtimeSinceStartup - session.PhaseStart).ToString("F2") + " s"));
			_arrivalIgnoreUntil = Time.realtimeSinceStartup + 2f;
			_session = null;
		}

		private unsafe void TryReturnFallback(Session session)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			if (session.UsingReturnFallback || Time.realtimeSinceStartup - session.PhaseStart < 30f)
			{
				return;
			}
			Game instance = Game.instance;
			PlayerProfile val = ((instance != null) ? instance.GetPlayerProfile() : null);
			if (val != null)
			{
				Vector3 val2 = (val.HaveCustomSpawnPoint() ? val.GetCustomSpawnPoint() : val.GetHomePoint());
				if (!(val2 == Vector3.zero) && !(val2 == session.OriginPosition))
				{
					session.UsingReturnFallback = true;
					session.LogoutPosition = val2;
					val.SetLogoutPoint(val2);
					session.Arrival = val2 + Vector3.up;
					session.ArrivalRotation = Quaternion.identity;
					PrioritizeTerrain(session.Arrival);
					Move(session, session.Arrival, session.ArrivalRotation);
					ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
					Vector3 val3 = val2;
					logger.LogWarning((object)("Origin did not load for return; preparing spawn point " + ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString()));
				}
			}
		}

		private void ArmArrivalGroundWatch(Vector3 arrival)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ZoneSystem.instance == (Object)null) && ZoneSystem.instance.GetGroundHeight(arrival, ref _arrivalInitialGround))
			{
				_arrivalGroundWatchPoint = arrival;
				_arrivalGroundWatchUntil = Time.realtimeSinceStartup + 3f;
			}
		}

		private unsafe void UpdateArrivalGroundWatch()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			if (Time.realtimeSinceStartup > _arrivalGroundWatchUntil)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null)
			{
				return;
			}
			Vector3 position = ((Component)localPlayer).transform.position;
			Vector3 val = position - _arrivalGroundWatchPoint;
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude > 16f)
			{
				_arrivalGroundWatchUntil = float.NegativeInfinity;
			}
			else
			{
				float num = default(float);
				float num2 = default(float);
				if (!ZoneSystem.instance.GetGroundHeight(_arrivalGroundWatchPoint, ref num) || num < _arrivalInitialGround + 0.25f || !ZoneSystem.instance.GetGroundHeight(position, ref num2) || position.y >= num2 - 0.05f)
				{
					return;
				}
				position.y = num2 + 0.1f;
				((Component)localPlayer).transform.position = position;
				Rigidbody component = ((Component)localPlayer).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.position = position;
					component.linearVelocity = Vector3.zero;
				}
				ZNetView component2 = ((Component)localPlayer).GetComponent<ZNetView>();
				if (component2 != null)
				{
					ZDO zDO = component2.GetZDO();
					if (zDO != null)
					{
						zDO.SetPosition(position);
					}
				}
				MaxAirAltitude.SetValue(localPlayer, position.y);
				_arrivalGroundWatchUntil = float.NegativeInfinity;
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				Vector3 val2 = position;
				logger.LogWarning((object)("Terrain finished loading after arrival; position corrected to " + ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString()));
			}
		}

		private unsafe void Update()
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00dd: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Expected O, but got Unknown
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Invalid comparison between Unknown and I4
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: 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_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0692: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b9: Unknown result type (might be due to invalid IL or missing references)
			UpdateNetwork();
			UpdateBrowseMap();
			UpdateArrivalGroundWatch();
			Session session = _session;
			if (session == null)
			{
				return;
			}
			if ((Object)(object)session.Player == (Object)null || (Object)(object)ZNet.instance == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Travel session lost; player or network unavailable. Phase=" + session.Phase));
				_session = null;
				ClearPins();
				return;
			}
			Phase phase = session.Phase;
			Vector3 val;
			if ((uint)phase <= 1u)
			{
				val = ((Component)session.Player).transform.position - session.ParkingPosition;
				if (!(((Vector3)(ref val)).sqrMagnitude > 1f))
				{
					val = ZNet.instance.GetReferencePosition() - session.ParkingPosition;
					if (!(((Vector3)(ref val)).sqrMagnitude > 1f))
					{
						goto IL_00e7;
					}
				}
				Move(session, session.ParkingPosition, session.OriginRotation);
			}
			goto IL_00e7;
			IL_00e7:
			if (session.Phase == Phase.Entering)
			{
				float num = Time.realtimeSinceStartup - session.PhaseStart;
				if (session.SnapshotReady && !session.DepartureConfirmed && Time.realtimeSinceStartup >= session.NextDepartureCheck)
				{
					session.NextDepartureCheck = Time.realtimeSinceStartup + 0.25f;
					RequestDepartureConfirmation(session);
				}
				bool flag = (Object)(object)ZNetScene.instance != (Object)null && !ZNetScene.InActiveArea(session.OriginPosition, ZNet.instance.GetReferencePosition()) && (Object)(object)ZNetScene.instance.FindInstance(session.Origin) == (Object)null;
				if (session.SnapshotReady && session.DepartureConfirmed && flag && (Object)(object)Hud.instance != (Object)null && num >= 1f && Hud.instance.m_loadingScreen.alpha >= 0.99f && Hud.instance.m_teleportingProgress.activeSelf)
				{
					OpenDestinationMap(session);
				}
				else if (session.SnapshotReady && session.DepartureConfirmed && flag && num > 3f)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Animation not ready after 3 s; opening map. HUD=" + (((Object)(object)Hud.instance == (Object)null) ? "missing" : Hud.instance.m_loadingScreen.alpha.ToString("F2"))));
					OpenDestinationMap(session);
				}
				else if (num > 15f)
				{
					BeginReturn("Origin was not released safely; returning");
				}
			}
			else if (session.Phase == Phase.Selecting)
			{
				if (Time.realtimeSinceStartup >= _nextSelectionSnapshot)
				{
					_nextSelectionSnapshot = Time.realtimeSinceStartup + 1f;
					ZPackage val2 = new ZPackage();
					val2.Write(session.Nonce);
					val2.Write(ZDOID.None);
					ZRoutedRpc.instance.InvokeRoutedRPC("RazaPortal2_Snapshot", new object[1] { val2 });
				}
				float num2 = Time.realtimeSinceStartup - session.PhaseStart;
				float effectiveSelectionTimeout = EffectiveSelectionTimeout;
				if (effectiveSelectionTimeout > 0f && num2 >= effectiveSelectionTimeout)
				{
					BeginReturn("Time to choose ran out");
					return;
				}
				if (!session.OriginInactiveLogged && (Object)(object)ZNetScene.instance != (Object)null && num2 >= 2f)
				{
					Vector3 referencePosition = ZNet.instance.GetReferencePosition();
					bool flag2 = ZNetScene.InActiveArea(session.OriginPosition, referencePosition);
					bool flag3 = (Object)(object)ZNetScene.instance.FindInstance(session.Origin) != (Object)null;
					if (!flag2 && !flag3)
					{
						session.OriginInactiveLogged = true;
						ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
						val = referencePosition;
						string? text = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
						val = session.OriginPosition;
						logger.LogInfo((object)("Origin unloaded during selection; reference=" + text + "; origin=" + ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString()));
					}
					else if (num2 >= 5f && !session.OriginStillActiveWarned)
					{
						session.OriginStillActiveWarned = true;
						ManualLogSource logger2 = ((BaseUnityPlugin)this).Logger;
						string[] obj = new string[6]
						{
							"Origin still active after 5 s of selection; area=",
							flag2.ToString(),
							"; portal loaded=",
							flag3.ToString(),
							"; reference=",
							null
						};
						val = referencePosition;
						obj[5] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
						logger2.LogWarning((object)string.Concat(obj));
					}
				}
				if (Time.realtimeSinceStartup >= _nextRefresh)
				{
					RefreshPins();
				}
				if ((Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode != 2)
				{
					Game.m_noMap = false;
					Minimap.instance.ShowPointOnMap(session.OriginPosition);
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Map closed during selection; reopened in " + ((object)Unsafe.As<MapMode, MapMode>(ref Minimap.instance.m_mode)/*cast due to .constrained prefix*/).ToString()));
				}
			}
			else if (session.Phase == Phase.Authorizing || session.Phase == Phase.Verifying)
			{
				if (Time.realtimeSinceStartup - session.PhaseStart > 10f)
				{
					BeginReturn("Server did not confirm the destination; returning");
				}
			}
			else
			{
				if ((Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null)
				{
					return;
				}
				if (session.Phase == Phase.Returning)
				{
					TryReturnFallback(session);
				}
				BoostDestinationZones(session);
				bool flag4 = ZNetScene.instance.IsAreaReady(session.Arrival);
				float num3 = default(float);
				bool flag5 = ZoneSystem.instance.FindFloor(session.Arrival, ref num3);
				bool flag6 = session.Phase == Phase.Returning || (Object)(object)ZNetScene.instance.FindInstance(session.Destination) != (Object)null;
				float num4 = Time.realtimeSinceStartup - ((session.Phase == Phase.Preparing) ? session.PreparingStartedAt : session.PhaseStart);
				if (flag4 && flag5 && num3 > session.Arrival.y)
				{
					session.Arrival.y = num3 + 0.05f;
					Move(session, session.Arrival, session.ArrivalRotation);
				}
				if (flag4 && !flag5 && num4 > 15f)
				{
					session.Arrival.y = ZoneSystem.instance.GetSolidHeight(session.Arrival) + 0.5f;
					Move(session, session.Arrival, session.ArrivalRotation);
					flag5 = true;
				}
				bool flag7 = flag5;
				if (Time.realtimeSinceStartup >= session.NextWaitLog)
				{
					session.NextWaitLog = Time.realtimeSinceStartup + 5f;
					if (num4 >= 4f)
					{
						ManualLogSource logger3 = ((BaseUnityPlugin)this).Logger;
						string[] obj2 = new string[14]
						{
							"Waiting for arrival (",
							session.Phase.ToString(),
							", ",
							num4.ToString("F0"),
							" s): area=",
							flag4.ToString(),
							"; floor=",
							flag5 ? ((session.Arrival.y - num3).ToString("F2") + " m") : "no",
							"; portal=",
							flag6.ToString(),
							"; reference=",
							null,
							null,
							null
						};
						val = ZNet.instance.GetReferencePosition();
						obj2[11] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
						obj2[12] = "; arrival=";
						val = session.Arrival;
						obj2[13] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
						logger3.LogInfo((object)string.Concat(obj2));
					}
				}
				if (session.Phase == Phase.Preparing && Time.realtimeSinceStartup - session.PreparingStartedAt > 30f)
				{
					BeginReturn("Destination did not load safely; returning");
				}
				else
				{
					if (!(flag4 && flag7 && flag6))
					{
						return;
					}
					if (session.Phase == Phase.Preparing)
					{
						if (Time.realtimeSinceStartup >= session.NextVerificationAt || SupportsReady(session))
						{
							RequestFinalValidation(session);
						}
					}
					else
					{
						Finish();
					}
				}
			}
		}

		private static bool SupportsReady(Session session)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNetScene.instance == (Object)null)
			{
				return false;
			}
			foreach (KeyValuePair<ZDOID, ObjectType> requiredSupport in session.RequiredSupports)
			{
				if ((int)requiredSupport.Value == 3)
				{
					ZDOMan instance = ZDOMan.instance;
					if (((instance != null) ? instance.GetZDO(requiredSupport.Key) : null) == null)
					{
						return false;
					}
				}
				else if ((Object)(object)ZNetScene.instance.FindInstance(requiredSupport.Key) == (Object)null)
				{
					return false;
				}
			}
			return true;
		}

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

		private void OnEnabledSettingChanged()
		{
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			_stateRevision++;
			ApplyNetworkSwitch();
			foreach (long networkClient in _networkClients)
			{
				SendNetworkState(networkClient, "RazaPortal2_State");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Portal network " + (_enabled.Value ? "enabled" : "disabled") + " by the server"));
		}

		private void ApplyNetworkSwitch()
		{
			ApplyRecipeMultiplier();
			if (!ServerSupportsNetwork)
			{
				ClearBrowsePins();
				_browsePinsVisible = false;
				_pendingBrowseNonce = 0L;
				_serverPortals.Clear();
				if (_session != null && _session.Phase != Phase.Returning)
				{
					BeginReturn("Portal network disabled by the server; returning to origin");
				}
			}
		}

		private void ReloadServerConfiguration()
		{
			if (Time.realtimeSinceStartup < _nextConfigCheck)
			{
				return;
			}
			_nextConfigCheck = Time.realtimeSinceStartup + 1f;
			try
			{
				DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(((BaseUnityPlugin)this).Config.ConfigFilePath);
				if (!(lastWriteTimeUtc == _configWriteTime) && File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath))
				{
					((BaseUnityPlugin)this).Config.Reload();
					_configWriteTime = lastWriteTimeUtc;
				}
			}
			catch (IOException ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Configuration could not be reloaded yet: " + ex.Message));
			}
		}

		private void SendNetworkState(long client, string method)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			if (ZRoutedRpc.instance != null && !((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				ZPackage val = new ZPackage();
				val.Write(6);
				val.Write(_stateRevision);
				val.Write(_enabled.Value);
				val.Write(_costMultiplier.Value);
				val.Write(_selectionTimeout.Value);
				ZNetPeer peer = ZNet.instance.GetPeer(client);
				if (peer != null)
				{
					peer.m_rpc.Invoke(method, new object[1] { val });
				}
			}
		}

		private void OnNetworkState(ZRpc rpc, ZPackage pkg)
		{
			if ((Object)(object)ZNet.instance == (Object)null || ZNet.instance.IsServer() || rpc != ZNet.instance.GetServerRPC() || pkg.ReadInt() != 6)
			{
				return;
			}
			int num = pkg.ReadInt();
			bool flag = pkg.ReadBool();
			float num2 = pkg.ReadSingle();
			float num3 = pkg.ReadSingle();
			if (!float.IsNaN(num2) && !float.IsInfinity(num2) && !(num2 < 0.1f) && !(num2 > 10f) && !float.IsNaN(num3) && !(num3 < 0f) && !(num3 > 600f) && num >= _remoteStateRevision)
			{
				bool num4 = !_remoteServerSupportsNetwork || _remoteNetworkEnabled != flag || _remoteCostMultiplier != num2;
				_remoteSelectionTimeout = num3;
				_remoteStateRevision = num;
				_remoteServerSupportsNetwork = true;
				_remoteNetworkEnabled = flag;
				_remoteCostMultiplier = num2;
				if (num4)
				{
					ApplyNetworkSwitch();
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Server confirmed portal network " + (flag ? "enabled" : "disabled")));
				}
			}
		}

		private void RegisterNetworkRpc()
		{
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance == null || instance == _registeredRpc)
			{
				return;
			}
			_registeredRpc = instance;
			_remoteServerSupportsNetwork = false;
			_remoteNetworkEnabled = false;
			_remoteStateRevision = -1;
			_remoteCostMultiplier = 1f;
			_remoteSelectionTimeout = 60f;
			_stateRevision = 0;
			_networkClients.Clear();
			_configWriteTime = File.GetLastWriteTimeUtc(((BaseUnityPlugin)this).Config.ConfigFilePath);
			_nextConfigCheck = 0f;
			_serverPortals.Clear();
			_serverTravels.Clear();
			ClearBrowsePins();
			_browsePinsVisible = false;
			_pendingBrowseNonce = 0L;
			_nextHello = 0f;
			foreach (ZNetPeer peer in ZNet.instance.GetPeers())
			{
				RegisterDirectRpc(peer);
			}
			instance.Register<ZPackage>("RazaPortal2_Snapshot", (Action<long, ZPackage>)OnSnapshotRequest);
			instance.Register<ZPackage>("RazaPortal2_SnapshotReply", (Action<long, ZPackage>)OnSnapshotReply);
			instance.Register<ZPackage>("RazaPortal2_Depart", (Action<long, ZPackage>)OnDepartRequest);
			instance.Register<ZPackage>("RazaPortal2_DepartReply", (Action<long, ZPackage>)OnDepartReply);
			instance.Register<ZPackage>("RazaPortal2_Complete", (Action<long, ZPackage>)OnCompleteRequest);
			instance.Register<ZPackage>("RazaPortal2_Resolve", (Action<long, ZPackage>)OnResolveRequest);
			instance.Register<ZPackage>("RazaPortal2_ResolveReply", (Action<long, ZPackage>)OnResolveReply);
			instance.Register<ZPackage>("RazaPortal2_Verify", (Action<long, ZPackage>)OnVerifyRequest);
			instance.Register<ZPackage>("RazaPortal2_VerifyReply", (Action<long, ZPackage>)OnVerifyReply);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Portal network RPC registered; server=" + ZNet.instance.IsServer()));
		}

		private void UpdateNetwork()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			if ((Object)(object)ZNet.instance == (Object)null || ZRoutedRpc.instance == null || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return;
			}
			if (!ZNet.instance.IsServer() && Time.realtimeSinceStartup >= _nextHello)
			{
				_nextHello = Time.realtimeSinceStartup + 2f;
				ZPackage val = new ZPackage();
				val.Write(6);
				ZRpc serverRPC = ZNet.instance.GetServerRPC();
				if (serverRPC != null)
				{
					serverRPC.Invoke("RazaPortal2_Hello", new object[1] { val });
				}
			}
			if (!ZNet.instance.IsServer())
			{
				return;
			}
			ReloadServerConfiguration();
			_networkClients.RemoveWhere((long id) => ZNet.instance.GetPeer(id) == null);
			List<long> list = new List<long>();
			foreach (KeyValuePair<long, ServerTravel> serverTravel in _serverTravels)
			{
				if (Time.realtimeSinceStartup - serverTravel.Value.LastSeen > 180f || (serverTravel.Key != ZNet.GetUID() && ZNet.instance.GetPeer(serverTravel.Key) == null))
				{
					list.Add(serverTravel.Key);
				}
			}
			foreach (long item in list)
			{
				_serverTravels.Remove(item);
			}
		}

		private void OnHello(ZRpc rpc, ZPackage pkg)
		{
			if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer() && pkg.ReadInt() == 6)
			{
				ZNetPeer val = ((IEnumerable<ZNetPeer>)ZNet.instance.GetPeers()).FirstOrDefault((Func<ZNetPeer, bool>)((ZNetPeer p) => p.m_rpc == rpc && p.IsReady()));
				if (val != null)
				{
					_networkClients.Add(val.m_uid);
					SendNetworkState(val.m_uid, "RazaPortal2_HelloReply");
				}
			}
		}

		private void RegisterDirectRpc(ZNetPeer peer)
		{
			peer.m_rpc.Register<ZPackage>("RazaPortal2_Hello", (Action<ZRpc, ZPackage>)OnHello);
			peer.m_rpc.Register<ZPackage>("RazaPortal2_HelloReply", (Action<ZRpc, ZPackage>)OnNetworkState);
			peer.m_rpc.Register<ZPackage>("RazaPortal2_State", (Action<ZRpc, ZPackage>)OnNetworkState);
		}

		private void RequestPortalSnapshot(Session session)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(session.Nonce);
			val.Write(session.Origin);
			ZRoutedRpc.instance.InvokeRoutedRPC("RazaPortal2_Snapshot", new object[1] { val });
		}

		private void RequestBrowseSnapshot()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (ServerSupportsNetwork && ZRoutedRpc.instance != null)
			{
				_pendingBrowseNonce = DateTime.UtcNow.Ticks;
				_nextBrowseRefresh = Time.realtimeSinceStartup + 5f;
				ZPackage val = new ZPackage();
				val.Write(_pendingBrowseNonce);
				val.Write(ZDOID.None);
				ZRoutedRpc.instance.InvokeRoutedRPC("RazaPortal2_Snapshot", new object[1] { val });
			}
		}

		private void OnSnapshotRequest(long sender, ZPackage pkg)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Expected O, but got Unknown
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_0152: 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_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			long num = pkg.ReadLong();
			ZDOID val = pkg.ReadZDOID();
			ZDO val2 = ((val == ZDOID.None) ? null : GetLivePortal(val));
			if (!_enabled.Value || !WorldAllowsPortals() || (val != ZDOID.None && val2 == null))
			{
				return;
			}
			Vector3 val3 = Vector3.zero;
			if (val == ZDOID.None && _serverTravels.TryGetValue(sender, out ServerTravel value) && value.Nonce == num)
			{
				value.LastSeen = Time.realtimeSinceStartup;
			}
			if (val != ZDOID.None)
			{
				HashSet<Vector3> hashSet = new HashSet<Vector3>();
				foreach (KeyValuePair<long, ServerTravel> serverTravel in _serverTravels)
				{
					if (serverTravel.Key != sender)
					{
						hashSet.Add(serverTravel.Value.ParkingPosition);
					}
				}
				for (int i = 0; i < 1024; i++)
				{
					Vector3 val4 = ParkingSlot(i);
					if (!hashSet.Contains(val4))
					{
						val3 = val4;
						break;
					}
				}
				if (val3 == Vector3.zero)
				{
					return;
				}
				_serverTravels[sender] = new ServerTravel
				{
					Nonce = num,
					Origin = val,
					OriginPosition = val2.GetPosition(),
					ParkingPosition = val3,
					LastSeen = Time.realtimeSinceStartup
				};
			}
			List<ZDO> list = new List<ZDO>();
			foreach (ZDO portal in ZDOMan.instance.GetPortalList())
			{
				if (IsVanillaPortal(portal))
				{
					list.Add(portal);
				}
			}
			ZPackage val5 = new ZPackage();
			val5.Write(num);
			val5.Write(val3);
			val5.Write(list.Count);
			foreach (ZDO item in list)
			{
				val5.Write(item.m_uid);
				val5.Write(item.GetPosition());
				val5.Write(item.GetRotation());
				val5.Write(item.GetString("tag", ""));
			}
			ZRoutedRpc.instance.InvokeRoutedRPC(sender, "RazaPortal2_SnapshotReply", new object[1] { val5 });
		}

		private void OnSnapshotReply(long sender, ZPackage pkg)
		{
			//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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			if (!ServerSupportsNetwork || !IsServerReply(sender))
			{
				return;
			}
			Session session = _session;
			long num = pkg.ReadLong();
			bool flag = session != null && session.Phase == Phase.Entering && num == session.Nonce;
			bool flag2 = session != null && session.Phase == Phase.Selecting && num == session.Nonce;
			bool flag3 = _browsePinsVisible && session == null && num == _pendingBrowseNonce;
			if (!flag && !flag2 && !flag3)
			{
				return;
			}
			Vector3 val = pkg.ReadVector3();
			int num2 = pkg.ReadInt();
			if (num2 < 0 || num2 > 10000)
			{
				return;
			}
			if (flag)
			{
				if (!IsServerParkingSlot(val))
				{
					BeginReturn("Invalid transit position");
					return;
				}
				session.ParkingPosition = val;
				Move(session, val, session.OriginRotation);
			}
			_serverPortals.Clear();
			for (int i = 0; i < num2; i++)
			{
				PortalRecord portalRecord = new PortalRecord
				{
					Id = pkg.ReadZDOID(),
					Position = pkg.ReadVector3(),
					Rotation = pkg.ReadQuaternion(),
					Name = pkg.ReadString()
				};
				_serverPortals[portalRecord.Id] = portalRecord;
			}
			if (flag)
			{
				session.SnapshotReady = true;
			}
			if (flag2)
			{
				RefreshPins();
			}
			if (flag3)
			{
				RefreshBrowsePins();
			}
			if (!flag2)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Server sent " + num2 + " portals for " + (flag ? "travel" : "map")));
			}
		}

		private static bool IsServerParkingSlot(Vector3 point)
		{
			//IL_0000: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			if (point.y != 1000f)
			{
				return false;
			}
			float num = (point.x - 12000f) / 512f;
			float num2 = (point.z - 12000f) / 512f;
			if (num >= 0f && num < 64f && num2 >= 0f && num2 < 16f && num == Mathf.Floor(num))
			{
				return num2 == Mathf.Floor(num2);
			}
			return false;
		}

		private void RequestDepartureConfirmation(Session session)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			if (ZRoutedRpc.instance != null)
			{
				ZPackage val = new ZPackage();
				val.Write(session.Nonce);
				ZRoutedRpc.instance.InvokeRoutedRPC("RazaPortal2_Depart", new object[1] { val });
			}
		}

		private void OnDepartRequest(long sender, ZPackage pkg)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing refer