Decompiled source of RustyHeathensTargetPortal v2.1.9

plugins/RustyHeathensTargetPortal/RustyHeathensTargetPortal.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RustyHeathensTargetPortal.Features;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("2.1.9.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 RustyHeathensTargetPortal
{
	[BepInPlugin("com.rustylasergaming.targetportal", "Rusty Heathens Target Portal", "2.1.9")]
	[BepInIncompatibility("org.bepinex.plugins.targetportal")]
	[BepInIncompatibility("com.xman0922.unifiedtargetportal")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.rustylasergaming.targetportal";

		public const string PluginName = "Rusty Heathens Target Portal";

		public const string PluginVersion = "2.1.9";

		internal static ManualLogSource Log;

		private Harmony? harmony;

		private PortalFeature? feature;

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			PortalStoneRunes.Configure(((BaseUnityPlugin)this).Config);
			Log = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("com.rustylasergaming.targetportal");
			feature = new PortalFeature(((BaseUnityPlugin)this).Config);
			feature.Initialize(harmony);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Rusty Heathens Target Portal 2.1.9 loaded. Public portals, reverse-ring travel with inward energy, mist, sparks and random lightning, configurable portal colors and server observer refresh.");
			PortalBlueEffects.Install(harmony);
			PortalPresentation.Install(harmony);
			PortalStoneRunes.Install(harmony);
			PortalObserverSync.Install(harmony);
		}

		private void Update()
		{
			feature?.Update();
		}

		private void OnDestroy()
		{
			PortalObserverSync.Shutdown();
			PortalStoneRunes.Shutdown();
			PortalPresentation.Shutdown();
			feature?.Shutdown();
			Harmony? obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
}
namespace RustyHeathensTargetPortal.Features
{
	internal interface IFeatureModule
	{
		void Initialize(Harmony harmony);

		void DrawGui();

		void Shutdown();
	}
	internal interface IUpdatableFeature
	{
		void Update();
	}
	internal static class Loc
	{
		internal static bool IsKorean
		{
			get
			{
				Localization instance = Localization.instance;
				if (instance != null)
				{
					return string.Equals(instance.GetSelectedLanguage(), "Korean", StringComparison.OrdinalIgnoreCase);
				}
				return false;
			}
		}

		internal static string Text(string korean, string english)
		{
			if (!IsKorean)
			{
				return english;
			}
			return korean;
		}
	}
	internal sealed class PortalFeature : IFeatureModule, IUpdatableFeature
	{
		private enum PortalMode
		{
			Public,
			Private
		}

		private enum ItemRestrictionMode
		{
			Never,
			Default,
			Always
		}

		private sealed class PortalEntry
		{
			internal ZDOID Id;

			internal string Tag = string.Empty;

			internal Vector3 Position;

			internal Quaternion Rotation;

			internal PortalMode Mode;

			internal string OwnerId = string.Empty;

			internal string OwnerName = string.Empty;
		}

		private sealed class FavoritePortalClick : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
		{
			internal PortalFeature Owner;

			internal PortalEntry Portal;

			public void OnPointerClick(PointerEventData eventData)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Invalid comparison between Unknown and I4
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				if ((int)eventData.button == 1)
				{
					Owner.ToggleFavorite(Portal);
				}
				else if ((int)eventData.button == 0)
				{
					Owner.Travel(Portal);
				}
			}
		}

		private const string ListRpc = "VU_PortalList";

		private const string RequestRpc = "VU_PortalRequest";

		private const string ChangeModeRpc = "VU_PortalMode";

		private const string ModeKey = "TargetPortal PortalMode";

		private const string OwnerIdKey = "TargetPortal PortalOwnerId";

		private const string OwnerNameKey = "TargetPortal PortalOwnerName";

		private const string FavoritesKey = "TargetPortal Favorites";

		private static PortalFeature? current;

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

		private static readonly MethodInfo? InteractRadiusGetter = AccessTools.PropertyGetter(typeof(Minimap), "PinInteractRadius");

		private static int portalPinType = -1;

		private static Sprite? portalIcon;

		private readonly ConfigEntry<bool> enabled;

		private readonly ConfigEntry<float> broadcastInterval;

		private readonly ConfigEntry<bool> showUntagged;

		private readonly ConfigEntry<bool> allowPrivatePortals;

		private readonly ConfigEntry<KeyboardShortcut> modeToggleShortcut;

		private readonly ConfigEntry<int> portalNameLength;

		private readonly ConfigEntry<int> maximumNumberOfPortals;

		private readonly ConfigEntry<ItemRestrictionMode> itemRestrictionMode;

		private readonly ConfigEntry<PortalMode> defaultPortalMode;

		private readonly List<PortalEntry> portals = new List<PortalEntry>();

		private readonly List<PinData> pickerPins = new List<PinData>();

		private readonly Dictionary<PinData, PortalEntry> pinToPortal = new Dictionary<PinData, PortalEntry>();

		private TeleportWorld? pickerSource;

		private bool pickerFromTrigger;

		private const float LeavePortalDistance = 4f;

		private ConfigEntry<bool> openMapOnEnter;

		private ConfigEntry<bool> portalAnimation;

		private bool[]? savedIconTypes;

		private static readonly FieldInfo? VisibleIconTypesField = AccessTools.Field(typeof(Minimap), "m_visibleIconTypes");

		private static readonly FieldInfo? PinUpdateRequiredField = AccessTools.Field(typeof(Minimap), "m_pinUpdateRequired");

		private static readonly FieldInfo? DragViewField = AccessTools.Field(typeof(Minimap), "m_dragView");

		private static readonly FieldInfo? PlacementGhostField = AccessTools.Field(typeof(Player), "m_placementGhost");

		private GameObject? favoriteList;

		private ZRoutedRpc? registeredWith;

		private bool listReceived;

		private float nextListRequest;

		private float sessionStarted;

		private float nextBroadcast;

		private int lastBroadcastHash;

		private static readonly FieldInfo? TriggerPortalField = AccessTools.Field(typeof(TeleportWorldTrigger), "m_teleportWorld");

		private bool rpcRegistered
		{
			get
			{
				if (registeredWith != null)
				{
					return registeredWith == ZRoutedRpc.instance;
				}
				return false;
			}
		}

		private static bool Active => current?.enabled.Value ?? false;

		internal PortalFeature(ConfigFile config)
		{
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			enabled = config.Bind<bool>("Portals", "Enabled", true, "Choose a destination on the map when using a portal. Hold Use to rename instead.");
			broadcastInterval = config.Bind<float>("Portals", "BroadcastInterval", 5f, "Seconds between server checks for portal changes.");
			showUntagged = config.Bind<bool>("Portals", "ShowUntagged", true, "List portals that have no tag.");
			openMapOnEnter = config.Bind<bool>("Portals", "OpenMapOnEnter", true, "Walk into a portal to open the destination map, like TargetPortal. Off: press Use to open it instead.");
			portalAnimation = config.Bind<bool>("Portals", "PortalAnimation", true, "Show the active portal swirl on every portal, since any portal can now reach any other.");
			portalNameLength = config.Bind<int>("Portals", "PortalNameLength", 10, new ConfigDescription("Maximum portal-name length.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 100), Array.Empty<object>()));
			maximumNumberOfPortals = config.Bind<int>("Portals", "MaximumNumberOfPortals", 0, new ConfigDescription("Maximum portals allowed in the world. 0 means unlimited.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), Array.Empty<object>()));
			itemRestrictionMode = config.Bind<ItemRestrictionMode>("Portals", "IgnoreItemTeleportRestrictions", ItemRestrictionMode.Default, "Never: enforce restrictions for every portal. Default: use the portal's vanilla rule. Always: ignore restrictions.");
		}

		private static void Patch(Harmony harmony, MethodBase? original, HarmonyMethod? prefix = null, HarmonyMethod? postfix = null)
		{
			if (original == null)
			{
				Plugin.Log.LogWarning((object)"Rusty Heathens Target Portal: a game method was not found; that part of the feature stays inactive.");
				return;
			}
			try
			{
				harmony.Patch(original, prefix, postfix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Rusty Heathens Target Portal: could not patch " + original.DeclaringType?.Name + "." + original.Name + ": " + ex.Message));
			}
		}

		public void Initialize(Harmony harmony)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Expected O, but got Unknown
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Expected O, but got Unknown
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Expected O, but got Unknown
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Expected O, but got Unknown
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Expected O, but got Unknown
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Expected O, but got Unknown
			current = this;
			Patch(harmony, AccessTools.Method(typeof(TeleportWorld), "Interact", (Type[])null, (Type[])null), new HarmonyMethod(typeof(PortalFeature), "InteractPrefix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(TeleportWorld), "GetHoverText", (Type[])null, (Type[])null), null, new HarmonyMethod(typeof(PortalFeature), "HoverTextPostfix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(ZDOMan), "AddPeer", (Type[])null, (Type[])null), null, new HarmonyMethod(typeof(PortalFeature), "ZdoAddPeerPostfix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(Piece), "SetCreator", (Type[])null, (Type[])null), null, new HarmonyMethod(typeof(PortalFeature), "PieceSetCreatorPostfix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(Minimap), "OnMapLeftClick", (Type[])null, (Type[])null), new HarmonyMethod(typeof(PortalFeature), "MapLeftClickPrefix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(Minimap), "RemovePinUnderPointer", (Type[])null, (Type[])null), new HarmonyMethod(typeof(PortalFeature), "RemovePinUnderPointerPrefix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(Minimap), "SetMapMode", (Type[])null, (Type[])null), null, new HarmonyMethod(typeof(PortalFeature), "SetMapModePostfix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(Minimap), "Start", (Type[])null, (Type[])null), null, new HarmonyMethod(typeof(PortalFeature), "MinimapStartPostfix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(Game), "Start", (Type[])null, (Type[])null), null, new HarmonyMethod(typeof(PortalFeature), "GameStartPostfix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(TeleportWorldTrigger), "OnTriggerEnter", (Type[])null, (Type[])null), new HarmonyMethod(typeof(PortalFeature), "TriggerEnterPrefix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(Player), "PlacePiece", (Type[])null, (Type[])null), new HarmonyMethod(typeof(PortalFeature), "PlacePiecePrefix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(TeleportWorld), "HaveTarget", (Type[])null, (Type[])null), new HarmonyMethod(typeof(PortalFeature), "HaveTargetPrefix", (Type[])null));
			Patch(harmony, AccessTools.Method(typeof(TeleportWorld), "TargetFound", (Type[])null, (Type[])null), new HarmonyMethod(typeof(PortalFeature), "TargetFoundPrefix", (Type[])null));
			string[] array = new string[2] { "OnMapDblClick", "OnMapMiddleClick" };
			foreach (string text in array)
			{
				MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(Minimap), text, (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(PortalFeature), "BlockWhilePickingPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			Plugin.Log.LogInfo((object)("PortalFeature: " + (enabled.Value ? ("enabled, open on " + (openMapOnEnter.Value ? "enter" : "use")) : "disabled") + "."));
		}

		private static void GameStartPostfix()
		{
			current?.RegisterRpcs();
		}

		private static void MinimapStartPostfix(Minimap __instance)
		{
			//IL_0077: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			if (!(VisibleIconTypesField?.GetValue(__instance) is bool[] array))
			{
				Plugin.Log.LogError((object)"Rusty Heathens Target Portal: could not register the dedicated portal map icon.");
				return;
			}
			portalPinType = array.Length;
			bool[] array2 = new bool[portalPinType + 1];
			Array.Copy(array, array2, array.Length);
			array2[portalPinType] = true;
			VisibleIconTypesField.SetValue(__instance, array2);
			if (portalIcon == null)
			{
				portalIcon = CreatePortalIcon();
			}
			__instance.m_icons.Add(new SpriteData
			{
				m_name = (PinType)portalPinType,
				m_icon = portalIcon
			});
			Plugin.Log.LogInfo((object)$"Rusty Heathens Target Portal: registered dedicated map icon as pin type {portalPinType}.");
		}

		private static Sprite CreatePortalIcon()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				name = "RustyHeathensPortalMarker",
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Type type = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule");
			if (((type == null) ? null : AccessTools.Method(type, "LoadImage", new Type[3]
			{
				typeof(Texture2D),
				typeof(byte[]),
				typeof(bool)
			}, (Type[])null))?.Invoke(null, new object[3]
			{
				val,
				Convert.FromBase64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fDL6pOwY/Lrtqui+kunCRbO+3QAC8cr6uQp11H/H/c/r7vLdeMyu068+pba5Adz+PDH8dcYpy2FwGk4riFjvi7z2p9tR6CDogNg38XiR7Erwpqtoi0asXkVjazPBXj6LTasRMLCVc36/M8HTy54o1hvVGd2v/uWeD/8sDsc//5Fpejxm/3rD0ajV8RmzJLUNlw/NiX2hY6K6KVdh4YqZnyovD8KWdGobDIoW84wRf7lfOnUQ4AUMHkHAQoiVI9ZsIk1PA9FP5hgYSt5Zx5osZ6C9AZZGNzLPULzEyb5G4nd2Gfd/yjwW7g/fKU4mtemFE/3cwLP2T+PEFCb15bAGlbn10prm7YYl5m53qGL9Didb5fna/aPeLoB2Ae14YyQr9ccGF2LV1dva7HBomWja9ECqdAtZIqlS8onkCZ0P6T9v+3v32ZY5kPiBPlB/Q/w52v9Nx+Z8gQYyKXhhgZ7Vh5cdvNvXuwtQs5+0zbnBnTWmAvacgGIGSKZCyqHQSJios+Qpxe9JCbgwmJcE4cPg4jL3snxg+xA7O6fc5aHeVzcsODq4rH75YZef14jd7ZWZ8DAU+I1b0QjS6LDuJNzhvpyicI75TEi9i2InY6ki5LKmb4RaPpQ2du/0DmtbnosbKWI4hfGeMvqCHLXY9p1PdryzyN31bBH7bl6ZmI9wl4SuV1x9nJmfi3FIxj6hTiWeLGM7v4Omy9p9dkMI4qYcRHsH+uv5+Mfz27+epCuswtKKsFYuqYETRH//5fxv6CmYjrGO8gvsbkvqr4X/4guIr8r2gEODHu/vbNfT3+D1+j4vivwDETJG06F4blAAAAABJRU5ErkJggg=="),
				true
			}) as bool? != true)
			{
				Plugin.Log.LogError((object)"Rusty Heathens Target Portal: failed to decode the original portal map icon.");
			}
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 64f);
		}

		private void RegisterRpcs()
		{
			if (ZRoutedRpc.instance != null && registeredWith != ZRoutedRpc.instance)
			{
				ZRoutedRpc.instance.Register<ZPackage>("VU_PortalList", (Action<long, ZPackage>)OnPortalList);
				ZRoutedRpc.instance.Register("VU_PortalRequest", (Action<long>)OnPortalRequest);
				ZRoutedRpc.instance.Register<ZDOID, int, string, string>("VU_PortalMode", (Method<ZDOID, int, string, string>)OnPortalModeChange);
				registeredWith = ZRoutedRpc.instance;
				lastBroadcastHash = 0;
				nextBroadcast = 0f;
				portals.Clear();
				listReceived = false;
				nextListRequest = 0f;
				sessionStarted = Time.time;
				Plugin.Log.LogInfo((object)"Rusty Heathens Target Portal: portal list handlers registered for this session.");
			}
		}

		private void UpdateClientList()
		{
			if ((Object)(object)ZNet.instance == (Object)null || ZNet.instance.IsServer() || listReceived || Time.time < nextListRequest)
			{
				return;
			}
			if (ZNet.instance.GetServerPeer() == null)
			{
				nextListRequest = Time.time + 1f;
				return;
			}
			ZRoutedRpc.instance.InvokeRoutedRPC("VU_PortalRequest", Array.Empty<object>());
			float num = Time.time - sessionStarted;
			nextListRequest = Time.time + ((num < 20f) ? 2f : 10f);
			if (num > 10f && portals.Count == 0)
			{
				UseLocalPortalList();
			}
		}

		private void UseLocalPortalList()
		{
			if (ZDOMan.instance != null)
			{
				int hash;
				ZPackage val = BuildPackage(out hash);
				val.SetPos(0);
				ReadPortalList(val);
			}
		}

		private static void ZdoAddPeerPostfix()
		{
			if (current != null && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
			{
				current.lastBroadcastHash = 0;
				current.nextBroadcast = Mathf.Min(current.nextBroadcast, Time.time + 2f);
			}
		}

		public void Update()
		{
			if (Active && ZRoutedRpc.instance != null && !rpcRegistered)
			{
				RegisterRpcs();
			}
			if (Active && rpcRegistered)
			{
				UpdateClientList();
			}
			if (Active && rpcRegistered && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer() && ZDOMan.instance != null && Time.time >= nextBroadcast)
			{
				nextBroadcast = Time.time + Mathf.Max(1f, broadcastInterval.Value);
				int hash;
				ZPackage package = BuildPackage(out hash);
				if (hash != lastBroadcastHash)
				{
					lastBroadcastHash = hash;
					Broadcast(package, 0L);
				}
			}
			UpdateMapControls();
			UpdateLeftPortal();
		}

		private void OnPortalRequest(long sender)
		{
			if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				Broadcast(BuildPackage(out var _), sender);
			}
		}

		private void Broadcast(ZPackage package, long target)
		{
			ZRoutedRpc.instance.InvokeRoutedRPC(target, "VU_PortalList", new object[1] { package });
			if (target == 0L)
			{
				package.SetPos(0);
				OnPortalList(ZNet.GetUID(), package);
			}
		}

		private static ZPackage BuildPackage(out int hash)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_004c: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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)
			List<ZDO> portalList = ZDOMan.instance.GetPortalList();
			ZPackage val = new ZPackage();
			val.Write(portalList.Count);
			hash = portalList.Count;
			foreach (ZDO item in portalList)
			{
				string text = item.GetString(ZDOVars.s_tag, "");
				Vector3 position = item.GetPosition();
				val.Write(item.m_uid);
				val.Write(text);
				val.Write(position);
				val.Write(item.GetRotation());
				PortalMode portalMode = SquashMode(item.GetInt("TargetPortal PortalMode", 0));
				string text2 = item.GetString("TargetPortal PortalOwnerId", string.Empty);
				string text3 = item.GetString("TargetPortal PortalOwnerName", string.Empty);
				val.Write((int)portalMode);
				val.Write(text2);
				val.Write(text3);
				hash = hash * 31 + ((object)Unsafe.As<ZDOID, ZDOID>(ref item.m_uid)/*cast due to .constrained prefix*/).GetHashCode();
				hash = hash * 31 + text.GetHashCode();
				hash = hash * 31 + Mathf.RoundToInt(position.x) + Mathf.RoundToInt(position.z) * 977;
				hash = (int)(hash * 31 + portalMode);
				hash = hash * 31 + text2.GetHashCode();
			}
			return val;
		}

		private void OnPortalList(long sender, ZPackage package)
		{
			listReceived = true;
			ReadPortalList(package);
		}

		private void ReadPortalList(ZPackage package)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			portals.Clear();
			int num = package.ReadInt();
			for (int i = 0; i < num; i++)
			{
				portals.Add(new PortalEntry
				{
					Id = package.ReadZDOID(),
					Tag = package.ReadString(),
					Position = package.ReadVector3(),
					Rotation = package.ReadQuaternion(),
					Mode = SquashMode(package.ReadInt()),
					OwnerId = package.ReadString(),
					OwnerName = package.ReadString()
				});
			}
		}

		private static bool InteractPrefix(TeleportWorld __instance, Humanoid human, bool hold, ref bool __result)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			if (!Active || current == null || (Object)(object)human != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if (!PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, true, false))
			{
				((Character)human).Message((MessageType)2, "$piece_noaccess", 0, (Sprite)null, false);
				__result = true;
				return false;
			}
			if (!hold)
			{
				_ = current;
				if (false)
				{
					KeyboardShortcut value = current.modeToggleShortcut.Value;
					if (((KeyboardShortcut)(ref value)).IsPressed())
					{
						current.TogglePortalMode(__instance, human);
						__result = true;
						return false;
					}
				}
			}
			if (current.openMapOnEnter.Value)
			{
				if (hold)
				{
					__result = false;
					return false;
				}
				if (!CanModifyPortal(__instance, showMessage: true))
				{
					__result = true;
					return false;
				}
				if (!TextInput.IsVisible() && (Object)(object)TextInput.instance != (Object)null)
				{
					TextInput.instance.RequestText((TextReceiver)(object)__instance, "$piece_portal_tag", Mathf.Clamp(current.portalNameLength.Value, 5, 100));
				}
				__result = true;
				return false;
			}
			if (hold)
			{
				if (!CanModifyPortal(__instance, showMessage: true))
				{
					__result = true;
					return false;
				}
				if (!TextInput.IsVisible() && (Object)(object)TextInput.instance != (Object)null)
				{
					TextInput.instance.RequestText((TextReceiver)(object)__instance, "$piece_portal_tag", Mathf.Clamp(current.portalNameLength.Value, 5, 100));
				}
				__result = true;
				return false;
			}
			current.OpenPicker(__instance, (Player)human, fromTrigger: false);
			__result = true;
			return false;
		}

		private static bool TriggerEnterPrefix(TeleportWorldTrigger __instance, Collider colliderIn)
		{
			if (!Active || current == null || !current.openMapOnEnter.Value)
			{
				return true;
			}
			Player component = ((Component)colliderIn).GetComponent<Player>();
			if ((Object)(object)component == (Object)null || (Object)(object)component != (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			if (((Character)component).IsTeleporting() || (Object)(object)current.pickerSource != (Object)null)
			{
				return false;
			}
			object? obj = TriggerPortalField?.GetValue(__instance);
			TeleportWorld val = (TeleportWorld)((obj is TeleportWorld) ? obj : null);
			if (val != null)
			{
				current.OpenPicker(val, component, fromTrigger: true);
			}
			return false;
		}

		private void UpdateLeftPortal()
		{
			//IL_002e: 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)pickerSource == (Object)null) && pickerFromTrigger && !((Object)(object)Player.m_localPlayer == (Object)null) && !(Vector3.Distance(((Component)Player.m_localPlayer).transform.position, ((Component)pickerSource).transform.position) <= 4f))
			{
				if ((Object)(object)Minimap.instance != (Object)null)
				{
					DragViewField?.SetValue(Minimap.instance, false);
				}
				ClosePicker();
			}
		}

		private static bool PlacePiecePrefix(Player __instance)
		{
			if (Active && current != null && current.maximumNumberOfPortals.Value > 0)
			{
				object? obj = PlacementGhostField?.GetValue(__instance);
				GameObject val = (GameObject)((obj is GameObject) ? obj : null);
				if (val != null && !((Object)(object)val.GetComponent<TeleportWorld>() == (Object)null) && current.portals.Count >= current.maximumNumberOfPortals.Value)
				{
					((Character)__instance).Message((MessageType)2, Loc.Text($"이 월드에는 포털을 {current.maximumNumberOfPortals.Value}개보다 더 설치할 수 없습니다.", $"You cannot place more than {current.maximumNumberOfPortals.Value} portals in this world."), 0, (Sprite)null, false);
					return false;
				}
			}
			return true;
		}

		private static bool HaveTargetPrefix(ref bool __result)
		{
			if (!Active)
			{
				return true;
			}
			__result = true;
			return false;
		}

		private static bool TargetFoundPrefix(ref bool __result)
		{
			if (!Active || current == null)
			{
				return true;
			}
			__result = current.portalAnimation.Value;
			return false;
		}

		private static bool BlockWhilePickingPrefix()
		{
			if (current != null)
			{
				return (Object)(object)current.pickerSource == (Object)null;
			}
			return true;
		}

		private static void HoverTextPostfix(TeleportWorld __instance, ref string __result)
		{
			if (!Active)
			{
				return;
			}
			int num = __result.LastIndexOf('\n');
			string text = ((num >= 0) ? __result.Substring(0, num) : __result);
			string text2 = Localization.instance.Localize("$KEY_Use");
			PortalFeature? portalFeature = current;
			if (portalFeature != null && portalFeature.openMapOnEnter.Value)
			{
				__result = text + "\n" + Loc.Text("포털에 들어가면 목적지를 선택합니다", "Walk in to choose a destination") + "\n" + Loc.Text("[<color=yellow><b>" + text2 + "</b></color>] 이름 변경", "[<color=yellow><b>" + text2 + "</b></color>] Rename");
			}
			else
			{
				__result = text + "\n" + Loc.Text("[<color=yellow><b>" + text2 + "</b></color>] 목적지 선택", "[<color=yellow><b>" + text2 + "</b></color>] Choose destination") + "\n" + Loc.Text("[<color=yellow><b>" + text2 + "</b></color> 길게] 이름 변경", "[Hold <color=yellow><b>" + text2 + "</b></color>] Rename");
			}
			if (current == null && false)
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				ZDO obj = ((component != null) ? component.GetZDO() : null);
				PortalMode portalMode = SquashMode((obj != null) ? obj.GetInt("TargetPortal PortalMode", 0) : 0);
				string text3 = ((obj != null) ? obj.GetString("TargetPortal PortalOwnerName", string.Empty) : null) ?? string.Empty;
				string text4 = ModeText(portalMode);
				if (portalMode == PortalMode.Private && !string.IsNullOrEmpty(text3))
				{
					text4 += Loc.Text(" (소유자: " + StringExtensionMethods.RemoveRichTextTags(text3) + ")", " (Owner: " + StringExtensionMethods.RemoveRichTextTags(text3) + ")");
				}
				__result = __result + "\n" + Loc.Text("공개 범위: " + text4, "Visibility: " + text4) + "\n" + Loc.Text("[<color=yellow><b>Shift + " + text2 + "</b></color>] 공개/비공개 전환", "[<color=yellow><b>Shift + " + text2 + "</b></color>] Toggle public/private");
			}
		}

		private static void PieceSetCreatorPostfix(Piece __instance)
		{
			if (!Active || current == null || 0 == 0 || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)((Component)__instance).GetComponent<TeleportWorld>() == (Object)null)
			{
				return;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			ZDO val = ((component != null) ? component.GetZDO() : null);
			if (val != null && val.GetInt("TargetPortal PortalMode", -1) == -1 && __instance.GetCreator() == Player.m_localPlayer.GetPlayerID())
			{
				_ = current;
				SetMode(val, PortalMode.Public, LocalOwnerId(), Player.m_localPlayer.GetPlayerName());
				if (current != null)
				{
					current.nextBroadcast = 0f;
				}
			}
		}

		private void TogglePortalMode(TeleportWorld portal, Humanoid human)
		{
		}

		private void OnPortalModeChange(long sender, ZDOID portalId, int rawMode, string ownerId, string ownerName)
		{
		}

		private static void SetMode(ZDO zdo, PortalMode mode, string ownerId, string ownerName)
		{
			zdo.Set("TargetPortal PortalMode", 0);
			zdo.Set("TargetPortal PortalOwnerId", ownerId);
			zdo.Set("TargetPortal PortalOwnerName", ownerName);
		}

		private static bool CanModifyPortal(TeleportWorld portal, bool showMessage)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (PrivateArea.CheckAccess(((Component)portal).transform.position, 0f, true, false))
			{
				return true;
			}
			if (showMessage)
			{
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)2, "$piece_noaccess", 0, (Sprite)null, false);
				}
			}
			return false;
		}

		private static PortalMode SquashMode(int rawMode)
		{
			return PortalMode.Public;
		}

		private static string LocalOwnerId()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return ((object)((IUser)PlatformManager.DistributionPlatform.LocalUser).PlatformUserID/*cast due to .constrained prefix*/).ToString().Replace("Steam_", string.Empty);
		}

		private static string ModeText(PortalMode mode)
		{
			if (mode != PortalMode.Public)
			{
				return Loc.Text("비공개", "Private");
			}
			return Loc.Text("공개", "Public");
		}

		private void OpenPicker(TeleportWorld source, Player player, bool fromTrigger)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)32))
			{
				((Character)player).Message((MessageType)2, "$msg_blocked", 0, (Sprite)null, false);
				return;
			}
			if (!CanTeleport(player, source))
			{
				((Character)player).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false);
				return;
			}
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			ClearPickerPins();
			if (portals.Count == 0 && (Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer())
			{
				nextListRequest = 0f;
				UpdateClientList();
				UseLocalPortalList();
			}
			ZNetView component = ((Component)source).GetComponent<ZNetView>();
			ZDOID val = (ZDOID)(((??)((component == null) ? ((ZDOID?)null) : component.GetZDO()?.m_uid)) ?? ZDOID.None);
			int num = 0;
			int num2 = 0;
			foreach (PortalEntry portal in portals)
			{
				if (portal.Id == val || (string.IsNullOrEmpty(portal.Tag) && !showUntagged.Value))
				{
					continue;
				}
				if (false && portal.Mode == PortalMode.Private && !string.Equals(portal.OwnerId, LocalOwnerId(), StringComparison.Ordinal))
				{
					num2++;
					continue;
				}
				string text = (string.IsNullOrEmpty(portal.Tag) ? Loc.Text("(이름 없음)", "(untagged)") : StringExtensionMethods.RemoveRichTextTags(portal.Tag));
				if (portalPinType < 0)
				{
					Plugin.Log.LogError((object)"Rusty Heathens Target Portal picker cannot open because its map icon was not registered.");
					((Character)player).Message((MessageType)2, Loc.Text("포털 지도 아이콘을 준비하지 못했습니다.", "The portal map icon is not ready."), 0, (Sprite)null, false);
					ClearPickerPins();
					return;
				}
				PinData val2 = instance.AddPin(portal.Position, (PinType)portalPinType, text, false, false, 0L, default(PlatformUserID));
				pickerPins.Add(val2);
				pinToPortal[val2] = portal;
				num++;
			}
			if (num == 0)
			{
				string text2 = ((portals.Count == 0 && !listReceived && (Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer()) ? Loc.Text("서버에서 포털 목록을 받는 중입니다. 잠시 후 다시 들어가 보세요.", "Waiting for the portal list from the server. Try again in a moment.") : ((num2 <= 0) ? Loc.Text("이동할 수 있는 다른 포털이 없습니다.", "No other portal to travel to.") : Loc.Text($"이동할 수 있는 공개 포털이 없습니다. (다른 사람의 비공개 포털 {num2}개 제외)", $"No public portal to travel to ({num2} private portal(s) of other players hidden).")));
				ManualLogSource log = Plugin.Log;
				string text3 = $"Rusty Heathens Target Portal picker empty: list={portals.Count}, received={listReceived}, ";
				ZNet instance2 = ZNet.instance;
				log.LogInfo((object)(text3 + $"server={((instance2 != null) ? new bool?(instance2.IsServer()) : ((bool?)null))}, hiddenPrivate={num2}, untaggedShown={showUntagged.Value}."));
				((Character)player).Message((MessageType)2, text2, 0, (Sprite)null, false);
				ClearPickerPins();
				return;
			}
			pickerSource = source;
			pickerFromTrigger = fromTrigger;
			if (InventoryGui.IsVisible())
			{
				InventoryGui.instance.Hide();
			}
			bool noMap = Game.m_noMap;
			Game.m_noMap = false;
			if (fromTrigger)
			{
				instance.ShowPointOnMap(((Component)source).transform.position);
			}
			else
			{
				instance.SetMapMode((MapMode)2);
			}
			Game.m_noMap = noMap;
			HideOtherPins(instance);
			BuildFavoriteList();
			((Character)player).Message((MessageType)2, Loc.Text("포털 클릭: 이동 · 우클릭: 즐겨찾기", "Rusty Heathens | Click: travel · Right-click: favourite"), 0, (Sprite)null, false);
		}

		private static bool MapLeftClickPrefix(Minimap __instance)
		{
			if (current == null || (Object)(object)current.pickerSource == (Object)null || current.pickerPins.Count == 0)
			{
				return true;
			}
			if (!current.TryGetClosestPickerPortal(__instance, out PinData _, out PortalEntry portal))
			{
				return true;
			}
			current.Travel(portal);
			return false;
		}

		private static bool RemovePinUnderPointerPrefix(Minimap __instance)
		{
			if (current == null || (Object)(object)current.pickerSource == (Object)null)
			{
				return true;
			}
			if (!current.TryGetClosestPickerPortal(__instance, out PinData _, out PortalEntry portal))
			{
				return true;
			}
			current.ToggleFavorite(portal);
			return false;
		}

		private bool TryGetClosestPickerPortal(Minimap map, out PinData pin, out PortalEntry portal)
		{
			//IL_0030: 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_0075: 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)
			pin = null;
			portal = null;
			if (ScreenToWorldMethod == null || InteractRadiusGetter == null)
			{
				return false;
			}
			Vector3 val = (Vector3)ScreenToWorldMethod.Invoke(map, new object[1] { ZInput.pointerPosition });
			float num = (float)InteractRadiusGetter.Invoke(map, null);
			float num2 = float.MaxValue;
			foreach (PinData pickerPin in pickerPins)
			{
				float num3 = Utils.DistanceXZ(val, pickerPin.m_pos);
				if (num3 < num && num3 < num2)
				{
					pin = pickerPin;
					num2 = num3;
				}
			}
			if (pin != null)
			{
				return pinToPortal.TryGetValue(pin, out portal);
			}
			return false;
		}

		private HashSet<string> FavoriteIds()
		{
			HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || !localPlayer.m_customData.TryGetValue("TargetPortal Favorites", out var value))
			{
				return hashSet;
			}
			string[] array = value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string item in array)
			{
				hashSet.Add(item);
			}
			return hashSet;
		}

		private void ToggleFavorite(PortalEntry portal)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				HashSet<string> hashSet = FavoriteIds();
				string item = ((object)Unsafe.As<ZDOID, ZDOID>(ref portal.Id)/*cast due to .constrained prefix*/).ToString();
				bool flag = hashSet.Add(item);
				if (!flag)
				{
					hashSet.Remove(item);
				}
				localPlayer.m_customData["TargetPortal Favorites"] = string.Join(",", hashSet);
				BuildFavoriteList();
				((Character)localPlayer).Message((MessageType)2, flag ? Loc.Text("포털을 즐겨찾기에 추가했습니다.", "Portal added to favourites.") : Loc.Text("포털을 즐겨찾기에서 제거했습니다.", "Portal removed from favourites."), 0, (Sprite)null, false);
			}
		}

		private unsafe void BuildFavoriteList()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00c5: 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_00d5: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			DestroyFavoriteList();
			Minimap instance = Minimap.instance;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)instance == (Object)null || (Object)(object)localPlayer == (Object)null || (Object)(object)pickerSource == (Object)null)
			{
				return;
			}
			Transform obj = instance.m_largeRoot.transform.Find("KeyHints/keyboard_hints/AddPin");
			GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Portal favourites: native AddPin key-hint template was not found.");
				return;
			}
			favoriteList = new GameObject("RustyHeathensTargetPortal Favorites", new Type[2]
			{
				typeof(RectTransform),
				typeof(VerticalLayoutGroup)
			});
			favoriteList.transform.SetParent(instance.m_largeRoot.transform, false);
			RectTransform val2 = (RectTransform)favoriteList.transform;
			val2.anchorMin = new Vector2(0f, 0.5f);
			val2.anchorMax = new Vector2(0f, 0.5f);
			val2.pivot = new Vector2(0f, 0.5f);
			val2.anchoredPosition = new Vector2(15f, 0f);
			val2.sizeDelta = new Vector2(240f, 500f);
			VerticalLayoutGroup component = favoriteList.GetComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)component).spacing = 3f;
			HashSet<string> hashSet = FavoriteIds();
			foreach (KeyValuePair<PinData, PortalEntry> item in pinToPortal)
			{
				PortalEntry value = item.Value;
				if (hashSet.Contains(((object)Unsafe.As<ZDOID, ZDOID>(ref value.Id)/*cast due to .constrained prefix*/).ToString()))
				{
					GameObject obj2 = Object.Instantiate<GameObject>(val, favoriteList.transform, false);
					ZDOID id = value.Id;
					((Object)obj2).name = "FavoritePortal_" + ((object)(*(ZDOID*)(&id))/*cast due to .constrained prefix*/).ToString();
					obj2.SetActive(true);
					HorizontalLayoutGroup component2 = obj2.GetComponent<HorizontalLayoutGroup>();
					if ((Object)(object)component2 != (Object)null)
					{
						((LayoutGroup)component2).childAlignment = (TextAnchor)3;
					}
					Transform obj3 = obj2.transform.Find("Label");
					TMP_Text val3 = ((obj3 != null) ? ((Component)obj3).GetComponent<TMP_Text>() : null);
					if ((Object)(object)val3 != (Object)null)
					{
						val3.text = (string.IsNullOrEmpty(value.Tag) ? Loc.Text("(이름 없음)", "(untagged)") : StringExtensionMethods.RemoveRichTextTags(value.Tag));
						val3.transform.SetAsLastSibling();
					}
					Transform obj4 = obj2.transform.Find("keyboard_hint");
					Image val4 = ((obj4 != null) ? ((Component)obj4).GetComponent<Image>() : null);
					if ((Object)(object)val4 != (Object)null)
					{
						val4.sprite = item.Key.m_icon;
					}
					FavoritePortalClick favoritePortalClick = obj2.AddComponent<FavoritePortalClick>();
					favoritePortalClick.Owner = this;
					favoritePortalClick.Portal = value;
				}
			}
		}

		private void UpdateMapControls()
		{
			Minimap instance = Minimap.instance;
			if (Active)
			{
				_ = (Object)(object)instance == (Object)null;
			}
		}

		private void Travel(PortalEntry destination)
		{
			//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_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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			TeleportWorld val = pickerSource;
			ClosePicker();
			if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)val == (Object)null))
			{
				if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)32))
				{
					((Character)localPlayer).Message((MessageType)2, "$msg_blocked", 0, (Sprite)null, false);
					return;
				}
				float num = default(float);
				if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)33) && (RandEventSystem.instance.GetBossEvent() != null || (ZoneSystem.instance.GetGlobalKey((GlobalKeys)47, ref num) && num > 0f)))
				{
					((Character)localPlayer).Message((MessageType)2, "$msg_blockedbyboss", 0, (Sprite)null, false);
					return;
				}
				if (!CanTeleport(localPlayer, val))
				{
					((Character)localPlayer).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false);
					return;
				}
				Vector3 val2 = destination.Rotation * Vector3.forward;
				Vector3 val3 = destination.Position + val2 * val.m_exitDistance + Vector3.up;
				Plugin.Log.LogInfo((object)$"Portal travel to '{destination.Tag}' at {destination.Position}.");
				((Character)localPlayer).TeleportTo(val3, destination.Rotation, true);
				Game.instance.IncrementPlayerStat((PlayerStatType)15, 1f, false);
			}
		}

		private static void SetMapModePostfix(MapMode mode)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			if (current != null && (Object)(object)current.pickerSource != (Object)null && (int)mode != 2)
			{
				current.ClosePicker();
			}
		}

		private void HideOtherPins(Minimap map)
		{
			if (savedIconTypes == null && VisibleIconTypesField?.GetValue(map) is bool[] array)
			{
				savedIconTypes = (bool[])array.Clone();
				HashSet<int> hashSet = new HashSet<int> { portalPinType };
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = hashSet.Contains(i);
				}
				PinUpdateRequiredField?.SetValue(map, true);
			}
		}

		private bool CanTeleport(Player player, TeleportWorld source)
		{
			if (itemRestrictionMode.Value != ItemRestrictionMode.Always)
			{
				return ((Humanoid)player).IsTeleportable(itemRestrictionMode.Value == ItemRestrictionMode.Default && source.m_allowAllItems);
			}
			return true;
		}

		private void RestorePins()
		{
			Minimap instance = Minimap.instance;
			if (savedIconTypes == null || (Object)(object)instance == (Object)null || !(VisibleIconTypesField?.GetValue(instance) is bool[] array))
			{
				savedIconTypes = null;
				return;
			}
			Array.Copy(savedIconTypes, array, Math.Min(savedIconTypes.Length, array.Length));
			savedIconTypes = null;
			PinUpdateRequiredField?.SetValue(instance, true);
		}

		private void ClosePicker()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			bool num = (Object)(object)pickerSource != (Object)null;
			pickerSource = null;
			RestorePins();
			ClearPickerPins();
			if (num && (Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode == 2)
			{
				Minimap.instance.SetMapMode((MapMode)1);
			}
		}

		private void ClearPickerPins()
		{
			Minimap instance = Minimap.instance;
			foreach (PinData pickerPin in pickerPins)
			{
				if ((Object)(object)instance != (Object)null)
				{
					instance.RemovePin(pickerPin);
				}
			}
			pickerPins.Clear();
			pinToPortal.Clear();
			DestroyFavoriteList();
		}

		private void DestroyFavoriteList()
		{
			if ((Object)(object)favoriteList != (Object)null)
			{
				Object.Destroy((Object)(object)favoriteList);
				favoriteList = null;
			}
		}

		public void DrawGui()
		{
		}

		public void Shutdown()
		{
			ClosePicker();
			portals.Clear();
			current = null;
		}
	}
	internal static class PortalIconData
	{
		internal const string PngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAejklEQVR4nO2bebhdZXX/P+vde5/5zvOQ3Aw3w81IQhJAICTMAUEJBhW1VUR+1qpVf49VbH8msdX+2lr7q3aiWrVoRYiAiiKEAJlIQgYy3oSM92a4Q+48nXHv/a7+cUOdgiJqfZ7f4/c55zl/nXPe9X2/a71rr7Ve+D1+j98l5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GobDIoW84wRf7lfOnUQ4AUMHkHAQoiVI9ZsIk1PA9FP5hgYSt5Zx5osZ6C9AZZGNzLPULzEyb5G4nd2Gfd/yjwW7g/fKU4mtemFE/3cwLP2T+PEFCb15bAGlbn10prm7YYl5m53qGL9Didb5fna/aPeLoB2Ae14YyQr9ccGF2LV1dva7HBomWja9ECqdAtZIqlS8onkCZ0P6T9v+3v32ZY5kPiBPlB/Q/w52v9Nx+Z8gQYyKXhhgZ7Vh5cdvNvXuwtQs5+0zbnBnTWmAvacgGIGSKZCyqHQSJios+Qpxe9JCbgwmJcE4cPg4jL3snxg+xA7O6fc5aHeVzcsODq4rH75YZef14jd7ZWZ8DAU+I1b0QjS6LDuJNzhvpyicI75TEi9i2InY6ki5LKmb4RaPpQ2du/0DmtbnosbKWI4hfGeMvqCHLXY9p1PdryzyN31bBH7bl6ZmI9wl4SuV1x9nJmfi3FIxj6hTiWeLGM7v4Omy9p9dkMI4qYcRHsH+uv5+Mfz27+epCuswtKKsFYuqYETRH//5fxv6CmYjrGO8gvsbkvqr4X/4guIr8r2gEODHu/vbNfT3+D1+j4vivwDETJG06F4blAAAAABJRU5ErkJggg==";
	}
}
namespace RustyHeathensTargetPortal
{
	public static class PortalBlueEffects
	{
		public static void Install(Harmony harmony)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(TeleportWorld), "Awake", (Type[])null, (Type[])null);
				if (methodInfo == null)
				{
					Debug.LogWarning((object)"Rusty Heathens: portal glow hook unavailable.");
				}
				else
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(PortalBlueEffects), "PortalAwake", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("Rusty Heathens: portal glow hook failed: " + ex.Message));
			}
		}

		public static Color Blue(Color old)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return PortalStoneRunes.Tint(old);
		}

		public static Gradient BlueGradient(Gradient original)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0024: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (original == null)
			{
				return null;
			}
			Gradient val = new Gradient();
			GradientColorKey[] colorKeys = original.colorKeys;
			for (int i = 0; i < colorKeys.Length; i++)
			{
				colorKeys[i].color = Blue(colorKeys[i].color);
			}
			val.SetKeys(colorKeys, original.alphaKeys);
			val.mode = original.mode;
			return val;
		}

		public static MinMaxGradient BlueCurve(MinMaxGradient original)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected I4, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			MinMaxGradient result = original;
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref original)).mode;
			switch ((int)mode)
			{
			case 0:
				((MinMaxGradient)(ref result)).color = Blue(((MinMaxGradient)(ref original)).color);
				break;
			case 2:
				((MinMaxGradient)(ref result)).colorMin = Blue(((MinMaxGradient)(ref original)).colorMin);
				((MinMaxGradient)(ref result)).colorMax = Blue(((MinMaxGradient)(ref original)).colorMax);
				break;
			case 1:
			case 4:
				((MinMaxGradient)(ref result)).gradient = BlueGradient(((MinMaxGradient)(ref original)).gradient);
				break;
			case 3:
				((MinMaxGradient)(ref result)).gradientMin = BlueGradient(((MinMaxGradient)(ref original)).gradientMin);
				((MinMaxGradient)(ref result)).gradientMax = BlueGradient(((MinMaxGradient)(ref original)).gradientMax);
				break;
			}
			return result;
		}

		public static void PortalAwake(TeleportWorld __instance)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null || (int)SystemInfo.graphicsDeviceType == 4)
			{
				return;
			}
			try
			{
				ParticleSystem[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem val in componentsInChildren)
				{
					MainModule main = val.main;
					((MainModule)(ref main)).startColor = BlueCurve(((MainModule)(ref main)).startColor);
					ColorOverLifetimeModule colorOverLifetime = val.colorOverLifetime;
					if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
					{
						((ColorOverLifetimeModule)(ref colorOverLifetime)).color = BlueCurve(((ColorOverLifetimeModule)(ref colorOverLifetime)).color);
					}
					ColorBySpeedModule colorBySpeed = val.colorBySpeed;
					if (((ColorBySpeedModule)(ref colorBySpeed)).enabled)
					{
						((ColorBySpeedModule)(ref colorBySpeed)).color = BlueCurve(((ColorBySpeedModule)(ref colorBySpeed)).color);
					}
					TrailModule trails = val.trails;
					if (((TrailModule)(ref trails)).enabled)
					{
						((TrailModule)(ref trails)).colorOverLifetime = BlueCurve(((TrailModule)(ref trails)).colorOverLifetime);
						((TrailModule)(ref trails)).colorOverTrail = BlueCurve(((TrailModule)(ref trails)).colorOverTrail);
					}
					if (val.particleCount > 0)
					{
						Particle[] array = (Particle[])(object)new Particle[val.particleCount];
						int particles = val.GetParticles(array);
						for (int j = 0; j < particles; j++)
						{
							((Particle)(ref array[j])).startColor = Color32.op_Implicit(Blue(Color32.op_Implicit(((Particle)(ref array[j])).startColor)));
						}
						val.SetParticles(array, particles);
					}
					ParticleSystemRenderer component = ((Component)val).GetComponent<ParticleSystemRenderer>();
					if ((Object)(object)component != (Object)null)
					{
						TintRenderer((Renderer)(object)component);
					}
				}
				Light[] componentsInChildren2 = ((Component)__instance).GetComponentsInChildren<Light>(true);
				foreach (Light obj in componentsInChildren2)
				{
					obj.color = Blue(obj.color);
				}
				FieldInfo fieldInfo = AccessTools.Field(typeof(TeleportWorld), "m_target_found");
				Component val2 = (Component)((fieldInfo == null) ? null : /*isinst with value type is only supported in some contexts*/);
				if ((Object)(object)val2 != (Object)null)
				{
					Renderer[] componentsInChildren3 = val2.GetComponentsInChildren<Renderer>(true);
					for (int i = 0; i < componentsInChildren3.Length; i++)
					{
						TintRenderer(componentsInChildren3[i]);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("Rusty Heathens: unable to tint a portal: " + ex.Message));
			}
		}

		public static void TintRenderer(Renderer renderer)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//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)
			Material[] sharedMaterials = renderer.sharedMaterials;
			for (int i = 0; i < sharedMaterials.Length; i++)
			{
				Material val = sharedMaterials[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				MaterialPropertyBlock val2 = new MaterialPropertyBlock();
				renderer.GetPropertyBlock(val2, i);
				string[] array = new string[4] { "_Color", "_TintColor", "_BaseColor", "_EmissionColor" };
				foreach (string text in array)
				{
					if (val.HasProperty(text))
					{
						val2.SetColor(text, Blue(val.GetColor(text)));
					}
				}
				renderer.SetPropertyBlock(val2, i);
			}
		}
	}
	public static class PortalPresentation
	{
		private static FieldInfo teleportField;

		private static FieldInfo loadingField;

		private static Hud owner;

		private static GameObject original;

		private static GameObject replacement;

		private static Texture2D artwork;

		private static Texture2D vortexTexture;

		private static Texture2D sparkTexture;

		private static Texture2D pulseTexture;

		private static RectTransform vortex;

		private static RawImage pulse;

		private static RawImage[] sparks;

		private static RectTransform[] sparkRects;

		private static float animationTime;

		private const float CenterX = 0.5083732f;

		private const float CenterY = 0.4176408f;

		private const float RadiusX = 0.11004785f;

		private const float RadiusY = 0.19553666f;

		private static Texture2D outerTexture;

		private static Texture2D[] lightningTextures;

		private static RectTransform outerRing;

		private static RawImage[] lightning;

		private static bool travelWasActive;

		private static Random stormRandom;

		public static float[] storm;

		public static float stormTime;

		private static float nextStorm;

		private static int stormSlot;

		private static float[] appliedBirth;

		private static float flowTime;

		private static Texture2D wispTexture;

		private static Texture2D[] mistTextures;

		private static RawImage[] wisps;

		private static RawImage[] mist;

		private static RawImage[] drift;

		private static Texture2D tunnelTexture;

		private static RawImage[] tunnel;

		private static Texture2D fogTexture;

		private static RawImage fogImage;

		private static float[] fogNoise;

		private static float[] fogMask;

		private static float[] fogBolts;

		public static Color32[] fogPixels;

		private static int fogBoltCount;

		private static float nextFogTime;

		public const int FogWidth = 240;

		public const int FogHeight = 135;

		public static void Install(Harmony harmony)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			if ((int)SystemInfo.graphicsDeviceType == 4)
			{
				return;
			}
			try
			{
				teleportField = AccessTools.Field(typeof(Hud), "m_teleportingProgress");
				loadingField = AccessTools.Field(typeof(Hud), "m_loadingScreen");
				MethodInfo methodInfo = AccessTools.Method(typeof(Hud), "Awake", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(typeof(Hud), "Update", (Type[])null, (Type[])null);
				if (teleportField == null || loadingField == null || methodInfo == null || methodInfo2 == null)
				{
					throw new Exception("HUD teleport fields or update were not found");
				}
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(PortalPresentation), "HudAwake", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(PortalPresentation), "HudUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				MethodInfo methodInfo3 = AccessTools.Method(typeof(Hud), "OnDestroy", (Type[])null, (Type[])null);
				if (methodInfo3 != null)
				{
					harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(PortalPresentation), "HudDestroy", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				Debug.Log((object)"Rusty Heathens: custom portal travel screen registered.");
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("Rusty Heathens: keeping vanilla travel screen: " + ex.Message));
			}
		}

		public static Texture2D LoadArtwork()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			if ((Object)(object)artwork != (Object)null)
			{
				return artwork;
			}
			Texture2D val = null;
			try
			{
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RustyHeathens.PortalTravel.jpg");
				if (stream == null)
				{
					throw new Exception("Embedded travel artwork missing");
				}
				byte[] array = new byte[(int)stream.Length];
				int num;
				for (int i = 0; i < array.Length; i += num)
				{
					num = stream.Read(array, i, array.Length - i);
					if (num == 0)
					{
						throw new EndOfStreamException();
					}
				}
				val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, array, false))
				{
					throw new Exception("Travel artwork could not be decoded");
				}
				((Object)val).name = "Rusty Heathens Portal Travel";
				((Texture)val).filterMode = (FilterMode)1;
				((Texture)val).wrapMode = (TextureWrapMode)1;
				((Object)val).hideFlags = (HideFlags)52;
				PrepareMotionTextures(val);
				val.Apply(false, true);
				artwork = val;
				return artwork;
			}
			catch
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				ReleaseMotionTextures();
				throw;
			}
		}

		public static void Stretch(RectTransform rect)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			rect.offsetMin = Vector2.zero;
			rect.offsetMax = Vector2.zero;
			((Transform)rect).localScale = Vector3.one;
		}

		public static void HudAwake(Hud __instance)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00bb: 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_012d: 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_0159: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null || (int)SystemInfo.graphicsDeviceType == 4)
			{
				return;
			}
			GameObject val = null;
			try
			{
				Restore();
				object? value = teleportField.GetValue(__instance);
				GameObject val2 = (GameObject)((value is GameObject) ? value : null);
				object? value2 = loadingField.GetValue(__instance);
				CanvasGroup val3 = (CanvasGroup)((value2 is CanvasGroup) ? value2 : null);
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val3 == (Object)null))
				{
					Texture2D val4 = LoadArtwork();
					val = new GameObject("RustyHeathensPortalTravel", new Type[3]
					{
						typeof(RectTransform),
						typeof(CanvasRenderer),
						typeof(Image)
					});
					val.SetActive(false);
					RectTransform component = val.GetComponent<RectTransform>();
					((Transform)component).SetParent(((Component)val3).transform, false);
					Stretch(component);
					Image component2 = val.GetComponent<Image>();
					((Graphic)component2).color = Color.black;
					((Graphic)component2).raycastTarget = false;
					GameObject val5 = new GameObject("RustyHeathensTravelArtwork", new Type[4]
					{
						typeof(RectTransform),
						typeof(CanvasRenderer),
						typeof(RawImage),
						typeof(AspectRatioFitter)
					});
					RectTransform component3 = val5.GetComponent<RectTransform>();
					((Transform)component3).SetParent((Transform)(object)component, false);
					component3.anchorMin = new Vector2(0.5f, 0.5f);
					component3.anchorMax = new Vector2(0.5f, 0.5f);
					component3.pivot = new Vector2(0.5f, 0.5f);
					component3.anchoredPosition = Vector2.zero;
					((Transform)component3).localScale = Vector3.one;
					RawImage component4 = val5.GetComponent<RawImage>();
					component4.texture = (Texture)(object)val4;
					((Graphic)component4).color = Color.white;
					((Graphic)component4).raycastTarget = false;
					AspectRatioFitter component5 = val5.GetComponent<AspectRatioFitter>();
					component5.aspectMode = (AspectMode)3;
					component5.aspectRatio = (float)((Texture)val4).width / (float)((Texture)val4).height;
					CreateMotion(component3);
					bool activeSelf = val2.activeSelf;
					teleportField.SetValue(__instance, val);
					owner = __instance;
					original = val2;
					replacement = val;
					val2.SetActive(false);
					val.SetActive(activeSelf);
					Debug.Log((object)"Rusty Heathens: animated portal travel screen ready (always enabled; rolling foreground fog illuminated by local lightning, reverse outer ring, inward wisps and drifting sparks).");
				}
			}
			catch (Exception ex)
			{
				Restore();
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				Debug.LogWarning((object)("Rusty Heathens: keeping vanilla travel screen: " + ex.Message));
			}
		}

		public static void Restore()
		{
			if ((Object)(object)owner != (Object)null && (Object)(object)original != (Object)null && teleportField != null)
			{
				bool active = (Object)(object)replacement != (Object)null && replacement.activeSelf;
				teleportField.SetValue(owner, original);
				original.SetActive(active);
			}
			if ((Object)(object)replacement != (Object)null)
			{
				Object.Destroy((Object)(object)replacement);
			}
			replacement = null;
			original = null;
			owner = null;
			ReleaseFog();
			tunnel = null;
			wisps = null;
			drift = null;
			flowTime = 0f;
			vortex = null;
			outerRing = null;
			lightning = null;
			appliedBirth = null;
			storm = null;
			stormRandom = null;
			travelWasActive = false;
			pulse = null;
			sparks = null;
			sparkRects = null;
			animationTime = 0f;
		}

		public static void HudDestroy(Hud __instance)
		{
			if ((Object)(object)owner == (Object)(object)__instance)
			{
				Restore();
			}
		}

		public static void Shutdown()
		{
			Restore();
			if ((Object)(object)artwork != (Object)null)
			{
				Object.Destroy((Object)(object)artwork);
			}
			artwork = null;
			ReleaseMotionTextures();
		}

		public static float Feather(float radius)
		{
			return 1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.8f, 1f, radius));
		}

		public static void PrepareMotionTextures(Texture2D source)
		{
			//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_00a5: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Expected O, but got Unknown
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			Color[] array = (Color[])(object)new Color[78400];
			for (int i = 0; i < 280; i++)
			{
				for (int j = 0; j < 280; j++)
				{
					float num = ((float)j + 0.5f - 140f) / 140f;
					float num2 = ((float)i + 0.5f - 140f) / 140f;
					Color pixelBilinear = source.GetPixelBilinear(0.5083732f + num * 140f / (float)((Texture)source).width, 0.4176408f + num2 * 140f / (float)((Texture)source).height);
					pixelBilinear.a = Feather(Mathf.Sqrt(num * num + num2 * num2));
					array[i * 280 + j] = pixelBilinear;
				}
			}
			vortexTexture = MakeTexture(280, array, "RustyHeathens_VortexMotion");
			Color[] array2 = (Color[])(object)new Color[135424];
			for (int k = 0; k < 368; k++)
			{
				for (int l = 0; l < 368; l++)
				{
					float num3 = (float)l + 0.5f - 184f;
					float num4 = (float)k + 0.5f - 184f;
					Color pixelBilinear2 = source.GetPixelBilinear(0.5083732f + num3 / (float)((Texture)source).width, 0.4176408f + num4 / (float)((Texture)source).height);
					pixelBilinear2.a = OuterMask(Mathf.Sqrt(num3 * num3 + num4 * num4));
					array2[k * 368 + l] = pixelBilinear2;
				}
			}
			outerTexture = MakeTexture(368, array2, "RustyHeathens_ReverseEnergyRing");
			lightningTextures = (Texture2D[])(object)new Texture2D[6];
			for (int m = 0; m < 6; m++)
			{
				Texture2D val = new Texture2D(256, 768, (TextureFormat)4, false);
				lightningTextures[m] = val;
				((Object)val).name = "RustyHeathens_Lightning_" + m;
				((Texture)val).filterMode = (FilterMode)1;
				((Texture)val).wrapMode = (TextureWrapMode)1;
				((Object)val).hideFlags = (HideFlags)52;
				val.SetPixels(BoltPixels(m));
				val.Apply(false, true);
			}
			Color[] array3 = (Color[])(object)new Color[4096];
			Color[] array4 = (Color[])(object)new Color[4096];
			for (int n = 0; n < 64; n++)
			{
				for (int num5 = 0; num5 < 64; num5++)
				{
					float num6 = ((float)num5 + 0.5f - 32f) / 32f;
					float num7 = ((float)n + 0.5f - 32f) / 32f;
					float num8 = Mathf.Sqrt(num6 * num6 + num7 * num7);
					array3[n * 64 + num5] = new Color(0.43f, 0.86f, 1f, Mathf.Pow(Mathf.Clamp01(1f - num8), 3f));
					array4[n * 64 + num5] = new Color(0f, 0.45f, 1f, Mathf.Clamp01(1f - Mathf.Abs(num8 - 0.7f) / 0.3f));
				}
			}
			sparkTexture = MakeTexture(64, array3, "RustyHeathens_TravelSpark");
			pulseTexture = MakeTexture(64, array4, "RustyHeathens_TravelPulse");
			Color[] array5 = (Color[])(object)new Color[147456];
			for (int num9 = 0; num9 < 384; num9++)
			{
				for (int num10 = 0; num10 < 384; num10++)
				{
					float num11 = ((float)num10 + 0.5f) / 192f - 1f;
					float num12 = ((float)num9 + 0.5f) / 192f - 1f;
					float radius = Mathf.Sqrt(num11 * num11 + num12 * num12);
					Color pixelBilinear3 = source.GetPixelBilinear(0.5083732f + num11 * 200f / (float)((Texture)source).width, 0.4176408f + num12 * 200f / (float)((Texture)source).height);
					pixelBilinear3.a = TunnelMask(radius);
					array5[num9 * 384 + num10] = pixelBilinear3;
				}
			}
			tunnelTexture = MakeTexture(384, array5, "RustyHeathens_InwardArtworkEnergy");
			wispTexture = MakeTexture(128, AtmospherePixels(-1), "RustyHeathens_InwardWisp");
		}

		public static Texture2D MakeTexture(int side, Color[] pixels, string name)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			Texture2D val = new Texture2D(side, side, (TextureFormat)4, false)
			{
				name = name,
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)52
			};
			val.SetPixels(pixels);
			val.Apply(false, true);
			return val;
		}

		public static RawImage MakeLayer(RectTransform parent, string name, Texture texture, float radiusScale)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(RawImage)
			});
			RectTransform component = val.GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)parent, false);
			component.anchorMin = new Vector2(0.5083732f - 0.11004785f * radiusScale, 0.4176408f - 0.19553666f * radiusScale);
			component.anchorMax = new Vector2(0.5083732f + 0.11004785f * radiusScale, 0.4176408f + 0.19553666f * radiusScale);
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			((Transform)component).localScale = Vector3.one;
			RawImage component2 = val.GetComponent<RawImage>();
			component2.texture = texture;
			((Graphic)component2).raycastTarget = false;
			return component2;
		}

		public static void CreateMotion(RectTransform picture)
		{
			vortex = ((Graphic)MakeLayer(picture, "RustyHeathens_MovingVortex", (Texture)(object)vortexTexture, 35f / 46f)).rectTransform;
			outerRing = ((Graphic)MakeLayer(picture, "RustyHeathens_ReverseEnergyRing", (Texture)(object)outerTexture, 1f)).rectTransform;
			pulse = MakeLayer(picture, "RustyHeathens_PulsingEnergy", (Texture)(object)pulseTexture, 1.18f);
			sparks = (RawImage[])(object)new RawImage[32];
			sparkRects = (RectTransform[])(object)new RectTransform[32];
			for (int i = 0; i < sparks.Length; i++)
			{
				sparks[i] = MakeLayer(picture, "RustyHeathens_Spark_" + i, (Texture)(object)sparkTexture, 0.018f);
				sparkRects[i] = ((Graphic)sparks[i]).rectTransform;
			}
			CreateAtmosphere(picture);
			CreateFog(picture);
			lightning = (RawImage[])(object)new RawImage[8];
			appliedBirth = new float[8];
			for (int j = 0; j < 8; j++)
			{
				lightning[j] = MakeLayer(picture, "RustyHeathens_StormLightning_" + j, (Texture)(object)lightningTextures[j % 6], 1f);
				appliedBirth[j] = float.NaN;
			}
			ResetLightning(Environment.TickCount ^ Guid.NewGuid().GetHashCode());
			travelWasActive = false;
			animationTime = 0f;
			Animate(0f);
			AnimateFog(0f);
		}

		public static void HudUpdate(Hud __instance)
		{
			if ((Object)(object)owner != (Object)(object)__instance || (Object)(object)replacement == (Object)null || (Object)(object)vortex == (Object)null)
			{
				return;
			}
			if (!replacement.activeInHierarchy)
			{
				travelWasActive = false;
				return;
			}
			if (!travelWasActive)
			{
				flowTime = 0f;
				nextFogTime = -1f;
				ResetLightning(Environment.TickCount ^ Guid.NewGuid().GetHashCode());
				for (int i = 0; i < 8; i++)
				{
					appliedBirth[i] = float.NaN;
				}
				travelWasActive = true;
			}
			StepLightning(Time.unscaledDeltaTime);
			animationTime = Mathf.Repeat(animationTime + Time.unscaledDeltaTime, 30f);
			Animate(animationTime);
			flowTime += Mathf.Clamp(Time.unscaledDeltaTime, 0f, 0.