Decompiled source of Runegate v0.4.7

plugins/Runegate/SfantulPortals.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: AssemblyTitle("SfantulPortals")]
[assembly: AssemblyCompany("Sfantul")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.4.7.0")]
namespace SfantulPortals;

[BepInIncompatibility("yay.spikehimself.xportal")]
[BepInPlugin("sfantul.portals", "Runegate", "0.4.7")]
public sealed class Plugin : BaseUnityPlugin
{
	private sealed class Destination
	{
		internal ZDOID id;

		internal string name;

		internal Vector3 position;
	}

	private sealed class PortalTextReceiver : TextReceiver
	{
		private readonly Func<string> read;

		private readonly Action<string> write;

		internal PortalTextReceiver(Func<string> read, Action<string> write)
		{
			this.read = read;
			this.write = write;
		}

		public string GetText()
		{
			return read();
		}

		public void SetText(string value)
		{
			write(value);
		}
	}

	private sealed class PortalMeta
	{
		internal ZDOID target = ZDOID.None;
	}

	public const string Id = "sfantul.portals";

	private const string Request = "SfantulPortals.List.v1";

	private const string Response = "SfantulPortals.ListReply.v1";

	private const string MetaRequest = "Runegate.Meta.v1";

	private const string MetaReply = "Runegate.MetaReply.v1";

	internal static Plugin Instance;

	internal static readonly Dictionary<ZDOID, ZDOID> Choices = new Dictionary<ZDOID, ZDOID>();

	private Harmony harmony;

	private ConfigEntry<float> uiScale;

	private ConfigEntry<bool> rememberRoutes;

	private string routeFile;

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

	private ZRoutedRpc rpc;

	private TeleportWorld source;

	private readonly List<Destination> destinations = new List<Destination>();

	private readonly Dictionary<long, float> lastRequest = new Dictionary<long, float>();

	private Rect window = new Rect(0f, 0f, 800f, 600f);

	private Vector2 scroll;

	private string filter = "";

	private string status = "";

	private string rename = "";

	private float requestedAt;

	private float nextRefresh;

	private float renameAt;

	private string pendingRename;

	private int sequence;

	private float reopenAfter;

	internal readonly Dictionary<ZDOID, string> portalNames = new Dictionary<ZDOID, string>();

	private ZDOID selectedId = ZDOID.None;

	private GUIStyle panelStyle;

	private GUIStyle titleStyle;

	private GUIStyle labelStyle;

	private GUIStyle smallStyle;

	private GUIStyle headingStyle;

	private GUIStyle inputStyle;

	private GUIStyle buttonStyle;

	private GUIStyle primaryStyle;

	private GUIStyle rowStyle;

	private GUIStyle selectedStyle;

	private readonly List<Texture2D> uiTextures = new List<Texture2D>();

	private readonly Color gold = new Color(0.83f, 0.65f, 0.33f);

	private readonly Color muted = new Color(0.62f, 0.59f, 0.52f);

	private float lastPing = -10f;

	private GUISkin portalScrollSkin;

	private readonly Dictionary<Button, bool> pausedButtons = new Dictionary<Button, bool>();

	private bool dropdownOpen;

	private GUIStyle leatherLabel;

	private Button nativeButton;

	private Image nativeButtonImage;

	private readonly Dictionary<Texture2D, Texture2D> nativeAtlasCopies = new Dictionary<Texture2D, Texture2D>();

	private string focusedPortalControl = "";

	private int navIndex;

	private int navCount;

	private int drawIndex;

	private int activateIndex = -1;

	private bool controllerMode;

	private bool inPortalList;

	private bool textDialog;

	private string fullNameHint = "";

	private bool settingsOpen;

	private float scalePreview = -1f;

	private GUIStyle settingsText;

	private GUIStyle settingsHeading;

	private readonly Dictionary<ZDOID, PortalMeta> metadata = new Dictionary<ZDOID, PortalMeta>();

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

	private readonly Dictionary<long, float> metaRequests = new Dictionary<long, float>();

	private string metaFile;

	private string favouriteFile;

	private float nextMeta;

	private bool metadataReady;

	private bool metadataWritable;

	internal static bool Open
	{
		get
		{
			if ((Object)(object)Instance != (Object)null)
			{
				return (Object)(object)Instance.source != (Object)null;
			}
			return false;
		}
	}

	private static bool NeedsGuiCompensation
	{
		get
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if ((int)QualitySettings.activeColorSpace == 1)
			{
				return (int)SystemInfo.graphicsDeviceType == 21;
			}
			return false;
		}
	}

	private void UpdateRouteContext()
	{
		string text = null;
		if ((Object)(object)ZNet.instance != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null)
		{
			text = Path.Combine(Paths.ConfigPath, "Runegate", ZNet.instance.GetWorldUID().ToString("X16") + "-" + Player.m_localPlayer.GetPlayerID().ToString("X16") + ".routes");
		}
		if (!(text == routeFile))
		{
			Choices.Clear();
			routeFile = text;
			if (rememberRoutes == null || rememberRoutes.Value)
			{
				LoadRoutes(text);
			}
		}
	}

	private void LoadRoutes(string next)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_005f: 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_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_006e: 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_007c: 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_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: 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)
		Choices.Clear();
		if (next == null || !File.Exists(next))
		{
			return;
		}
		try
		{
			ZPackage val = new ZPackage(File.ReadAllBytes(next));
			if (val.ReadInt() != 1)
			{
				throw new InvalidOperationException("Unknown route file version");
			}
			int num = val.ReadInt();
			if (num < 0 || num > 10000)
			{
				throw new InvalidOperationException("Invalid route count");
			}
			Dictionary<ZDOID, ZDOID> dictionary = new Dictionary<ZDOID, ZDOID>();
			for (int i = 0; i < num; i++)
			{
				ZDOID val2 = val.ReadZDOID();
				ZDOID val3 = val.ReadZDOID();
				if (val2 != ZDOID.None && val3 != ZDOID.None && val2 != val3)
				{
					dictionary[val2] = val3;
				}
			}
			foreach (KeyValuePair<ZDOID, ZDOID> item in dictionary)
			{
				Choices[item.Key] = item.Value;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Restored " + Choices.Count + " personal portal routes."));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not load personal routes: " + ex.Message));
		}
	}

	private void SaveRoutes()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		if (routeFile == null || (rememberRoutes != null && !rememberRoutes.Value))
		{
			return;
		}
		try
		{
			ZPackage val = new ZPackage();
			val.Write(1);
			val.Write(Choices.Count);
			foreach (KeyValuePair<ZDOID, ZDOID> choice in Choices)
			{
				val.Write(choice.Key);
				val.Write(choice.Value);
			}
			Directory.CreateDirectory(Path.GetDirectoryName(routeFile));
			string text = routeFile + ".tmp";
			File.WriteAllBytes(text, val.GetArray());
			if (File.Exists(routeFile))
			{
				File.Replace(text, routeFile, null);
			}
			else
			{
				File.Move(text, routeFile);
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not save personal routes: " + ex.Message));
		}
	}

	private void Awake()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		Instance = this;
		rememberRoutes = ((BaseUnityPlugin)this).Config.Bind<bool>("Portals", "RememberAfterRestart", true, "Remember personal portal destinations after reconnecting. False keeps choices for this session only.");
		uiScale = ((BaseUnityPlugin)this).Config.Bind<float>("Interface", "UIScale", 1f, new ConfigDescription("Menu scale relative to the default size.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.7f, 1.5f), new object[0]));
		if (Chainloader.PluginInfos.ContainsKey("yay.spikehimself.xportal"))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Disable XPortal before using SfantulPortals.");
			((Behaviour)this).enabled = false;
			return;
		}
		try
		{
			harmony = new Harmony("sfantul.portals");
			if (ServerPeer == null)
			{
				throw new MissingMethodException("GetServerPeerID");
			}
			string[] array = new string[3] { "HaveTarget", "TargetFound", "Teleport" };
			foreach (string text in array)
			{
				MethodInfo method = typeof(TeleportWorld).GetMethod(text, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method == null)
				{
					throw new MissingMethodException(text);
				}
			}
			harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SfantulPortals 0.4.7 by Sfantul loaded. BepInEx only; vanilla teleport checks preserved.");
		}
		catch (Exception ex)
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
			((Behaviour)this).enabled = false;
		}
	}

	private void OnDestroy()
	{
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		DisposeStyles();
		Choices.Clear();
		if ((Object)(object)Instance == (Object)(object)this)
		{
			Instance = null;
		}
	}

	private void Update()
	{
		//IL_00eb: 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)
		if (rpc != ZRoutedRpc.instance)
		{
			rpc = ZRoutedRpc.instance;
			source = null;
			routeFile = null;
			Choices.Clear();
			destinations.Clear();
			portalNames.Clear();
			lastRequest.Clear();
			RegisterMetadata();
			if (rpc != null)
			{
				rpc.Register<ZPackage>("SfantulPortals.List.v1", (Action<long, ZPackage>)OnRequest);
				rpc.Register<ZPackage>("SfantulPortals.ListReply.v1", (Action<long, ZPackage>)OnResponse);
			}
		}
		UpdateRouteContext();
		UpdateMetadata();
		if (!Open)
		{
			if (settingsOpen)
			{
				HandlePortalNavigation();
			}
			return;
		}
		if ((Object)(object)Player.m_localPlayer == (Object)null || ((Character)Player.m_localPlayer).IsDead() || ((Character)Player.m_localPlayer).IsTeleporting() || Vector3.Distance(((Component)Player.m_localPlayer).transform.position, ((Component)source).transform.position) > 6f)
		{
			Close();
			return;
		}
		if (textDialog)
		{
			HandlePortalNavigation();
			return;
		}
		if (Input.GetKeyDown((KeyCode)27) || Input.GetKeyDown((KeyCode)331))
		{
			Close();
			return;
		}
		HandlePortalNavigation();
		if (pendingRename != null)
		{
			ZNetView component = ((Component)source).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.GetZDO() != null && component.GetZDO().GetString("tag", "") == pendingRename)
			{
				status = "Name confirmed: " + pendingRename;
				((BaseUnityPlugin)this).Logger.LogInfo((object)status);
				pendingRename = null;
			}
			else if (Time.realtimeSinceStartup - renameAt > 8f)
			{
				status = "Rename not confirmed. Check your connection and try again.";
				pendingRename = null;
			}
		}
		if (requestedAt > 0f && Time.realtimeSinceStartup - requestedAt > 8f)
		{
			status = "No reply. Install SfantulPortals on the server too, then reconnect.";
			requestedAt = 0f;
		}
		if (requestedAt == 0f && pendingRename == null && Time.realtimeSinceStartup >= nextRefresh)
		{
			Refresh();
		}
	}

	internal void Show(TeleportWorld portal)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: 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_0099: 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_00ce: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
		if (!((Behaviour)this).enabled || rpc == null || Open || Time.realtimeSinceStartup < reopenAfter)
		{
			return;
		}
		navIndex = 0;
		activateIndex = -1;
		controllerMode = false;
		source = portal;
		filter = "";
		scroll = Vector2.zero;
		rename = portal.GetText();
		destinations.Clear();
		pendingRename = null;
		ZNetView component = ((Component)portal).GetComponent<ZNetView>();
		selectedId = (((Object)(object)component != (Object)null && component.GetZDO() != null && Choices.TryGetValue(component.GetZDO().m_uid, out var value)) ? value : ZDOID.None);
		if ((Object)(object)component != (Object)null && component.GetZDO() != null)
		{
			ZDO zDO = component.GetZDO();
			if (IsShared(zDO.m_uid))
			{
				selectedId = GetTarget(zDO, (ConnectionType)1);
			}
		}
		Refresh();
	}

	private void Close()
	{
		settingsOpen = false;
		reopenAfter = Time.realtimeSinceStartup + 0.35f;
		dropdownOpen = false;
		source = null;
		requestedAt = 0f;
		pendingRename = null;
	}

	private void Refresh()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		if (destinations.Count == 0)
		{
			status = "Loading portals...";
		}
		requestedAt = Time.realtimeSinceStartup;
		nextRefresh = requestedAt + 10f;
		ZPackage val = new ZPackage();
		val.Write(++sequence);
		long num = ServerID();
		if (num == 0)
		{
			status = "Not connected to a server yet.";
			requestedAt = 0f;
		}
		else
		{
			rpc.InvokeRoutedRPC(num, "SfantulPortals.List.v1", new object[1] { val });
		}
	}

	private void OnRequest(long sender, ZPackage request)
	{
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		//IL_00cb: 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)
		if (!((Behaviour)this).enabled || (Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || ZDOMan.instance == null || (lastRequest.TryGetValue(sender, out var value) && Time.realtimeSinceStartup - value < 0.5f))
		{
			return;
		}
		lastRequest[sender] = Time.realtimeSinceStartup;
		try
		{
			int num = request.ReadInt();
			List<ZDO> list = (from z in ZDOMan.instance.GetPortalList()
				where z != null
				select z).Take(1000).ToList();
			ZPackage val = new ZPackage();
			val.Write(num);
			val.Write(list.Count);
			foreach (ZDO item in list)
			{
				val.Write(item.m_uid);
				val.Write(Clean(item.GetString("tag", "")));
				val.Write(item.GetPosition());
			}
			rpc.InvokeRoutedRPC(sender, "SfantulPortals.ListReply.v1", new object[1] { val });
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Portal list request rejected: " + ex.Message));
		}
	}

	private void OnResponse(long sender, ZPackage reply)
	{
		//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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		if (!((Behaviour)this).enabled || !Open || sender != ServerID())
		{
			return;
		}
		try
		{
			if (reply.ReadInt() != sequence)
			{
				return;
			}
			int num = reply.ReadInt();
			if (num < 0 || num > 1000)
			{
				throw new InvalidOperationException("Invalid portal count");
			}
			List<Destination> list = new List<Destination>();
			ZDO zDO = ((Component)source).GetComponent<ZNetView>().GetZDO();
			for (int i = 0; i < num; i++)
			{
				Destination destination = new Destination();
				destination.id = reply.ReadZDOID();
				destination.name = Clean(reply.ReadString());
				destination.position = reply.ReadVector3();
				Destination destination2 = destination;
				if (destination2.id != zDO.m_uid)
				{
					list.Add(destination2);
				}
			}
			portalNames.Clear();
			foreach (Destination item in list)
			{
				portalNames[item.id] = item.name;
			}
			destinations.Clear();
			destinations.AddRange(list.OrderBy<Destination, string>((Destination d) => d.name, StringComparer.OrdinalIgnoreCase));
			status = ((destinations.Count == 0) ? "No other portals yet. Name this portal, then close the menu." : (destinations.Count + " destinations available."));
			requestedAt = 0f;
			if (Choices.TryGetValue(zDO.m_uid, out var chosen) && !list.Any((Destination d) => d.id == chosen))
			{
				Choices.Remove(zDO.m_uid);
				SaveRoutes();
				status = "Previous destination is no longer listed. Choose another portal.";
			}
		}
		catch (Exception ex)
		{
			status = "Could not read portal list.";
			requestedAt = 0f;
			((BaseUnityPlugin)this).Logger.LogWarning((object)ex.Message);
		}
	}

	internal static string Clean(string text)
	{
		if (text == null)
		{
			return "";
		}
		return new string(text.Where((char c) => !char.IsControl(c) && c != '<' && c != '>').Take(64).ToArray());
	}

	private long ServerID()
	{
		return (long)ServerPeer.Invoke(rpc, null);
	}

	internal static bool HasAccess(TeleportWorld portal)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		return PrivateArea.CheckAccess(((Component)portal).transform.position, 0f, true, false);
	}

	internal static ZDOID GetTarget(ZDO source, ConnectionType kind)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Invalid comparison between Unknown and I4
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Invalid comparison between Unknown and I4
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		if ((int)kind == 1 && (Object)(object)Instance != (Object)null && Instance.metadata.TryGetValue(source.m_uid, out var value) && value.target != ZDOID.None)
		{
			return value.target;
		}
		if ((int)kind == 1 && Choices.TryGetValue(source.m_uid, out var value2))
		{
			return value2;
		}
		return source.GetConnectionZDOID(kind);
	}

	private Texture2D Texture(Color color, bool wood = false)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		int num = (wood ? 128 : 2);
		Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
		((Object)val).hideFlags = (HideFlags)61;
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num2 = (wood ? (0.92f + 0.06f * Mathf.Sin((float)i * 0.42f + Mathf.Sin((float)j * 0.035f) * 2f) + 0.025f * Mathf.Sin((float)i * 2.3f + (float)j * 0.11f)) : 1f);
				val.SetPixel(j, i, new Color(color.r * num2, color.g * num2, color.b * num2, color.a));
			}
		}
		val.Apply();
		uiTextures.Add(val);
		return val;
	}

	private GUIStyle TextStyle(int size, Color color, bool bold = false)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.label);
		val.fontSize = size;
		val.normal.textColor = color;
		val.richText = false;
		val.fontStyle = (FontStyle)(bold ? 1 : 0);
		return val;
	}

	private bool LoadUiImage(Texture2D texture, byte[] bytes)
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		if (!(bool)typeof(ImageConversion).GetMethod("LoadImage", new Type[3]
		{
			typeof(Texture2D),
			typeof(byte[]),
			typeof(bool)
		}).Invoke(null, new object[3] { texture, bytes, false }))
		{
			return false;
		}
		if (NeedsGuiCompensation)
		{
			Color[] pixels = texture.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				float a = pixels[i].a;
				ref Color reference = ref pixels[i];
				reference = ((Color)(ref pixels[i])).linear;
				pixels[i].a = a;
			}
			texture.SetPixels(pixels);
		}
		texture.Apply(false, true);
		return true;
	}

	private void CreateStyles()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_003e: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Expected O, but got Unknown
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Expected O, but got Unknown
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: 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_00ca: Expected O, but got Unknown
		//IL_038f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0453: Unknown result type (might be due to invalid IL or missing references)
		//IL_0475: Unknown result type (might be due to invalid IL or missing references)
		//IL_058d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0597: Expected O, but got Unknown
		//IL_05ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_05df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0604: Unknown result type (might be due to invalid IL or missing references)
		//IL_062f: Unknown result type (might be due to invalid IL or missing references)
		//IL_065a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0671: Unknown result type (might be due to invalid IL or missing references)
		//IL_067b: Expected O, but got Unknown
		//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_06cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_06dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e7: Expected O, but got Unknown
		//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0709: Expected O, but got Unknown
		//IL_0731: Unknown result type (might be due to invalid IL or missing references)
		//IL_0748: Unknown result type (might be due to invalid IL or missing references)
		//IL_0752: Expected O, but got Unknown
		//IL_076d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0797: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_07de: Expected O, but got Unknown
		//IL_0864: Unknown result type (might be due to invalid IL or missing references)
		//IL_086e: Expected O, but got Unknown
		//IL_0884: Unknown result type (might be due to invalid IL or missing references)
		//IL_0895: Unknown result type (might be due to invalid IL or missing references)
		if (panelStyle != null)
		{
			return;
		}
		panelStyle = new GUIStyle(GUI.skin.box);
		panelStyle.normal.background = Texture(new Color(0.105f, 0.088f, 0.071f, 0.99f), wood: true);
		using (Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("SfantulPortals.portal-panel.png"))
		{
			if (stream != null)
			{
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				((Object)val).hideFlags = (HideFlags)61;
				if (LoadUiImage(val, memoryStream.ToArray()))
				{
					uiTextures.Add(val);
					panelStyle.normal.background = val;
					panelStyle.border = new RectOffset(0, 0, 0, 0);
				}
				else
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}
		titleStyle = TextStyle(27, new Color(0.16f, 0.09f, 0.035f), bold: true);
		((IEnumerable<Font>)Resources.FindObjectsOfTypeAll<Font>()).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("Averia", StringComparison.OrdinalIgnoreCase) >= 0));
		titleStyle.font = Font.CreateDynamicFontFromOSFont("Georgia", 27);
		titleStyle.fontStyle = (FontStyle)1;
		titleStyle.alignment = (TextAnchor)4;
		labelStyle = TextStyle(17, new Color(0.91f, 0.87f, 0.77f));
		labelStyle.wordWrap = true;
		labelStyle.font = titleStyle.font;
		smallStyle = TextStyle(15, new Color(0.1f, 0.055f, 0.02f));
		smallStyle.wordWrap = true;
		headingStyle = TextStyle(18, new Color(0.1f, 0.055f, 0.02f), bold: true);
		smallStyle.font = titleStyle.font;
		headingStyle.font = titleStyle.font;
		inputStyle = new GUIStyle(GUI.skin.textField);
		inputStyle.fontSize = 18;
		inputStyle.font = titleStyle.font;
		inputStyle.richText = false;
		inputStyle.padding = new RectOffset(12, 10, 4, 4);
		inputStyle.normal.textColor = new Color(0.94f, 0.9f, 0.81f);
		inputStyle.focused.textColor = inputStyle.normal.textColor;
		Texture2D background = Texture(new Color(0.075f, 0.06f, 0.04f, 1f));
		GUIStyleState[] array = (GUIStyleState[])(object)new GUIStyleState[8] { inputStyle.normal, inputStyle.hover, inputStyle.active, inputStyle.focused, inputStyle.onNormal, inputStyle.onHover, inputStyle.onActive, inputStyle.onFocused };
		foreach (GUIStyleState val2 in array)
		{
			val2.background = background;
			val2.textColor = new Color(0.94f, 0.9f, 0.81f);
		}
		Font val3 = ((IEnumerable<Font>)Resources.FindObjectsOfTypeAll<Font>()).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("Norse", StringComparison.OrdinalIgnoreCase) >= 0));
		if ((Object)(object)val3 != (Object)null)
		{
			titleStyle.font = val3;
			titleStyle.fontSize = 34;
			titleStyle.fontStyle = (FontStyle)0;
		}
		else
		{
			titleStyle.font = FindGameButtonFont();
			titleStyle.fontSize = 30;
		}
		portalScrollSkin = Object.Instantiate<GUISkin>(GUI.skin);
		((Object)portalScrollSkin).hideFlags = (HideFlags)61;
		Texture2D background2 = Texture(new Color(0.026f, 0.018f, 0.01f, 1f));
		Texture2D background3 = Texture(new Color(0.15f, 0.095f, 0.044f, 1f));
		GUIStyleState[] array2 = (GUIStyleState[])(object)new GUIStyleState[3]
		{
			portalScrollSkin.verticalScrollbar.normal,
			portalScrollSkin.verticalScrollbar.hover,
			portalScrollSkin.verticalScrollbar.active
		};
		foreach (GUIStyleState val4 in array2)
		{
			val4.background = background2;
		}
		GUIStyleState[] array3 = (GUIStyleState[])(object)new GUIStyleState[3]
		{
			portalScrollSkin.verticalScrollbarThumb.normal,
			portalScrollSkin.verticalScrollbarThumb.hover,
			portalScrollSkin.verticalScrollbarThumb.active
		};
		foreach (GUIStyleState val5 in array3)
		{
			val5.background = background3;
		}
		portalScrollSkin.verticalScrollbar.fixedWidth = 12f;
		portalScrollSkin.verticalScrollbarThumb.fixedWidth = 10f;
		buttonStyle = new GUIStyle(GUI.skin.button);
		buttonStyle.fontSize = 14;
		buttonStyle.richText = false;
		buttonStyle.normal.textColor = new Color(0.9f, 0.83f, 0.67f);
		buttonStyle.hover.textColor = Color.white;
		buttonStyle.normal.background = Texture(new Color(0.19f, 0.17f, 0.13f));
		buttonStyle.hover.background = Texture(new Color(0.29f, 0.24f, 0.16f));
		buttonStyle.active.background = Texture(new Color(0.35f, 0.28f, 0.17f));
		primaryStyle = new GUIStyle(buttonStyle);
		primaryStyle.fontStyle = (FontStyle)1;
		primaryStyle.normal.background = Texture(new Color(0.6f, 0.43f, 0.19f));
		primaryStyle.normal.textColor = new Color(1f, 0.95f, 0.82f);
		rowStyle = new GUIStyle(buttonStyle);
		rowStyle.alignment = (TextAnchor)3;
		rowStyle.padding = new RectOffset(16, 12, 0, 0);
		rowStyle.fontSize = 17;
		rowStyle.normal.background = Texture(new Color(0.14f, 0.13f, 0.105f));
		selectedStyle = new GUIStyle(rowStyle);
		selectedStyle.normal.background = Texture(new Color(0.32f, 0.255f, 0.145f));
		selectedStyle.normal.textColor = new Color(1f, 0.86f, 0.57f);
		using Stream stream2 = typeof(Plugin).Assembly.GetManifestResourceStream("SfantulPortals.leather-button.png");
		if (stream2 == null)
		{
			return;
		}
		using MemoryStream memoryStream2 = new MemoryStream();
		stream2.CopyTo(memoryStream2);
		Texture2D val6 = new Texture2D(2, 2, (TextureFormat)4, false);
		((Object)val6).hideFlags = (HideFlags)61;
		if (LoadUiImage(val6, memoryStream2.ToArray()))
		{
			uiTextures.Add(val6);
			GUIStyle[] array4 = (GUIStyle[])(object)new GUIStyle[2] { buttonStyle, primaryStyle };
			foreach (GUIStyle val7 in array4)
			{
				val7.normal.background = val6;
				val7.hover.background = val6;
				val7.active.background = val6;
				val7.border = new RectOffset(0, 0, 0, 0);
				val7.hover.textColor = new Color(1f, 0.86f, 0.45f);
				val7.active.textColor = Color.white;
			}
		}
		else
		{
			Object.Destroy((Object)(object)val6);
		}
	}

	private void NormalizeStyle(GUIStyle style)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		style.border = new RectOffset(0, 0, 0, 0);
		style.overflow = new RectOffset(0, 0, 0, 0);
	}

	private void Line(Rect rect, Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: 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)
		Color color2 = GUI.color;
		GUI.color = color;
		GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture);
		GUI.color = color2;
	}

	private void SetPauseButtonsBlocked(bool blocked)
	{
		if (blocked && pausedButtons.Count == 0)
		{
			Menu[] array = Resources.FindObjectsOfTypeAll<Menu>();
			foreach (Menu val in array)
			{
				Button[] componentsInChildren = ((Component)val).GetComponentsInChildren<Button>(true);
				foreach (Button val2 in componentsInChildren)
				{
					if (!pausedButtons.ContainsKey(val2))
					{
						pausedButtons[val2] = ((Selectable)val2).interactable;
					}
					((Selectable)val2).interactable = false;
				}
			}
		}
		if (blocked)
		{
			return;
		}
		foreach (KeyValuePair<Button, bool> pausedButton in pausedButtons)
		{
			if ((Object)(object)pausedButton.Key != (Object)null)
			{
				((Selectable)pausedButton.Key).interactable = pausedButton.Value;
			}
		}
		pausedButtons.Clear();
	}

	private void OnGUI()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: 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)
		Color color = GUI.color;
		Color backgroundColor = GUI.backgroundColor;
		Color contentColor = GUI.contentColor;
		bool enabled = GUI.enabled;
		GUISkin skin = GUI.skin;
		try
		{
			GUI.color = Color.white;
			GUI.backgroundColor = Color.white;
			GUI.contentColor = Color.white;
			GUI.enabled = true;
			DrawPortalGui();
		}
		finally
		{
			GUI.color = color;
			GUI.backgroundColor = backgroundColor;
			GUI.contentColor = contentColor;
			GUI.enabled = enabled;
			GUI.skin = skin;
		}
	}

	private void DrawPortalGui()
	{
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Invalid comparison between Unknown and I4
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Invalid comparison between Unknown and I4
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Expected O, but got Unknown
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		if (textDialog && TextInput.IsVisible())
		{
			return;
		}
		bool flag = (Object)(object)Player.m_localPlayer != (Object)null && Menu.IsVisible();
		if (!flag)
		{
			settingsOpen = false;
		}
		SetPauseButtonsBlocked(settingsOpen);
		if (!Open && !flag)
		{
			return;
		}
		if ((int)Event.current.type == 4 && (int)Event.current.keyCode == 27)
		{
			Close();
			Event.current.Use();
			return;
		}
		if (panelStyle == null)
		{
			CreateStyles();
			GUIStyle[] array = (GUIStyle[])(object)new GUIStyle[6] { panelStyle, inputStyle, buttonStyle, primaryStyle, rowStyle, selectedStyle };
			foreach (GUIStyle style in array)
			{
				NormalizeStyle(style);
			}
		}
		if (!Open && !settingsOpen)
		{
			if (SolidButton(new Rect(24f, (float)(Screen.height - 70), 220f, 40f), "Runegate settings"))
			{
				settingsOpen = true;
				scalePreview = uiScale.Value;
			}
			return;
		}
		Matrix4x4 matrix = GUI.matrix;
		float num = Mathf.Min(Mathf.Min(new float[3]
		{
			(float)Screen.width / 850f,
			(float)Screen.height / 650f,
			1.6f
		}) * 0.64f * ((uiScale == null) ? 1f : uiScale.Value), Mathf.Min((float)Screen.width / 820f, (float)Screen.height / 620f));
		GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(num, num, 1f));
		window = new Rect(((float)Screen.width / num - 800f) / 2f, ((float)Screen.height / num - 600f) / 2f, 800f, 600f);
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(0.58f, 0.55f, 0.5f, 1f);
		try
		{
			Color color = GUI.color;
			GUI.color = Color.white;
			GUI.DrawTexture(window, (Texture)(object)panelStyle.normal.background);
			GUI.color = color;
			GUI.Window(187462, window, new WindowFunction(DrawWindow), "", GUIStyle.none);
		}
		finally
		{
			focusedPortalControl = GUI.GetNameOfFocusedControl();
			GUI.matrix = matrix;
			GUI.backgroundColor = backgroundColor;
		}
	}

	private Font FindGameButtonFont(Button button = null)
	{
		if ((Object)(object)button != (Object)null)
		{
			Component[] componentsInChildren = ((Component)button).GetComponentsInChildren<Component>(true);
			foreach (Component val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || ((object)val).GetType().Namespace != "TMPro")
				{
					continue;
				}
				PropertyInfo property = ((object)val).GetType().GetProperty("font");
				object obj = ((property == null) ? null : property.GetValue(val, null));
				if (obj != null)
				{
					PropertyInfo property2 = obj.GetType().GetProperty("sourceFontFile");
					Font val2 = (Font)((property2 == null) ? null : /*isinst with value type is only supported in some contexts*/);
					if ((Object)(object)val2 != (Object)null)
					{
						return val2;
					}
				}
			}
		}
		Font[] array = Resources.FindObjectsOfTypeAll<Font>();
		Font val3 = ((IEnumerable<Font>)array).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("AveriaSerif", StringComparison.OrdinalIgnoreCase) >= 0)) ?? ((IEnumerable<Font>)array).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("Averia", StringComparison.OrdinalIgnoreCase) >= 0));
		if (!((Object)(object)val3 != (Object)null))
		{
			return GUI.skin.button.font;
		}
		return val3;
	}

	private bool SolidButton(Rect rect, string text, bool enabled = true, bool alignLeft = false)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_006c: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Expected O, but got Unknown
		//IL_00f3: 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_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Expected O, but got Unknown
		//IL_0191: 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_0177: Expected O, but got Unknown
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0391: Unknown result type (might be due to invalid IL or missing references)
		//IL_037b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
		if (leatherLabel == null)
		{
			leatherLabel = new GUIStyle(GUIStyle.none);
			leatherLabel.alignment = (TextAnchor)4;
			leatherLabel.fontSize = 18;
			leatherLabel.font = FindGameButtonFont();
			leatherLabel.richText = false;
			leatherLabel.normal.textColor = new Color(0.9f, 0.82f, 0.65f);
			leatherLabel.hover.textColor = new Color(1f, 0.91f, 0.7f);
			leatherLabel.active.textColor = new Color(0.96f, 0.83f, 0.54f);
		}
		leatherLabel.alignment = (TextAnchor)(alignLeft ? 3 : 4);
		leatherLabel.padding = (alignLeft ? new RectOffset(14, 36, 0, 0) : new RectOffset());
		bool result = NavigationControl(rect, enabled);
		bool flag = enabled && (((Rect)(ref rect)).Contains(Event.current.mousePosition) || (controllerMode && drawIndex - 1 == navIndex));
		string text2 = text;
		leatherLabel.fontSize = 18;
		while (leatherLabel.fontSize > 15 && leatherLabel.CalcSize(new GUIContent(text)).x > ((Rect)(ref rect)).width)
		{
			GUIStyle obj = leatherLabel;
			obj.fontSize -= 1;
		}
		if (leatherLabel.CalcSize(new GUIContent(text)).x > ((Rect)(ref rect)).width)
		{
			while (text.Length > 0 && leatherLabel.CalcSize(new GUIContent(text + "...")).x > ((Rect)(ref rect)).width)
			{
				text = text.Substring(0, text.Length - 1);
			}
			text += "...";
		}
		if (flag && text2 != text)
		{
			fullNameHint = text2;
		}
		bool pressed = flag && Input.GetMouseButton(0);
		Line(rect, new Color(0.045f, 0.035f, 0.025f, 1f));
		Color color = GUI.color;
		float num = 1f;
		GUI.color = new Color(num, num, num, 1f);
		DrawNativeButton(rect, flag, pressed, enabled);
		GUI.color = color;
		if (flag)
		{
			Color color2 = default(Color);
			((Color)(ref color2))..ctor(0.42f, 0.31f, 0.15f, 1f);
			Line(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, 1f), color2);
			Line(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - 1f, ((Rect)(ref rect)).width, 1f), color2);
		}
		leatherLabel.fontStyle = (FontStyle)1;
		leatherLabel.normal.textColor = Color.black;
		for (int i = -1; i <= 1; i++)
		{
			for (int j = -1; j <= 1; j++)
			{
				if (j != 0 || i != 0)
				{
					GUI.Label(new Rect(((Rect)(ref rect)).x + (float)j, ((Rect)(ref rect)).y + (float)i, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), text, leatherLabel);
				}
			}
		}
		leatherLabel.normal.textColor = ((!enabled) ? new Color(0.58f, 0.58f, 0.58f) : (flag ? new Color(1f, 0.78f, 0.3f) : new Color(1f, 0.65f, 0.12f)));
		GUI.Label(rect, text, leatherLabel);
		if (!enabled || !GUI.Button(rect, "", GUIStyle.none))
		{
			return result;
		}
		return true;
	}

	private Texture2D NativeAtlasForGui(Texture2D source)
	{
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		if (!NeedsGuiCompensation)
		{
			return source;
		}
		if (nativeAtlasCopies.TryGetValue(source, out var value))
		{
			return value;
		}
		RenderTexture active = RenderTexture.active;
		bool sRGBWrite = GL.sRGBWrite;
		RenderTexture val = null;
		Texture2D val2 = null;
		try
		{
			val = RenderTexture.GetTemporary(((Texture)source).width, ((Texture)source).height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)1);
			GL.sRGBWrite = false;
			Graphics.Blit((Texture)(object)source, val);
			RenderTexture.active = val;
			val2 = new Texture2D(((Texture)source).width, ((Texture)source).height, (TextureFormat)4, false);
			((Object)val2).hideFlags = (HideFlags)61;
			((Texture)val2).filterMode = ((Texture)source).filterMode;
			((Texture)val2).wrapMode = ((Texture)source).wrapMode;
			val2.ReadPixels(new Rect(0f, 0f, (float)((Texture)source).width, (float)((Texture)source).height), 0, 0, false);
			val2.Apply(false, true);
			nativeAtlasCopies.Add(source, val2);
			uiTextures.Add(val2);
			return val2;
		}
		catch (Exception ex)
		{
			if ((Object)(object)val2 != (Object)null)
			{
				Object.Destroy((Object)(object)val2);
			}
			nativeAtlasCopies[source] = source;
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Native button colour conversion unavailable: " + ex.Message));
			return source;
		}
		finally
		{
			RenderTexture.active = active;
			GL.sRGBWrite = sRGBWrite;
			if ((Object)(object)val != (Object)null)
			{
				RenderTexture.ReleaseTemporary(val);
			}
		}
	}

	private bool DrawNativeButton(Rect rect, bool hover, bool pressed, bool enabled)
	{
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Invalid comparison between Unknown and I4
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0352: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_0327: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)nativeButton == (Object)null || (Object)(object)nativeButtonImage == (Object)null)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
			InventoryGui[] array = Resources.FindObjectsOfTypeAll<InventoryGui>();
			foreach (InventoryGui obj in array)
			{
				FieldInfo field = typeof(InventoryGui).GetField("m_craftButton", bindingAttr);
				Button val = (Button)((field == null) ? null : /*isinst with value type is only supported in some contexts*/);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Graphic targetGraphic = ((Selectable)val).targetGraphic;
				Image val2 = (Image)(object)((targetGraphic is Image) ? targetGraphic : null);
				if ((Object)(object)val2 == (Object)null || (Object)(object)val2.sprite == (Object)null)
				{
					val2 = ((IEnumerable<Image>)((Component)val).GetComponentsInChildren<Image>(true)).FirstOrDefault((Func<Image, bool>)((Image val7) => (Object)(object)val7.sprite != (Object)null && (int)val7.type == 1));
				}
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.sprite == (Object)null))
				{
					nativeButton = val;
					nativeButtonImage = val2;
					Text componentInChildren = ((Component)val).GetComponentInChildren<Text>(true);
					if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.font != (Object)null)
					{
						leatherLabel.font = componentInChildren.font;
					}
					else
					{
						leatherLabel.font = FindGameButtonFont(val);
					}
					break;
				}
			}
			if ((Object)(object)nativeButtonImage == (Object)null)
			{
				Menu[] array2 = Resources.FindObjectsOfTypeAll<Menu>();
				foreach (Menu obj2 in array2)
				{
					string[] array3 = new string[4] { "m_continueButton", "m_saveButton", "m_settingsButton", "m_logoutButton" };
					foreach (string name in array3)
					{
						FieldInfo field2 = typeof(Menu).GetField(name, bindingAttr);
						Button val3 = (Button)((field2 == null) ? null : /*isinst with value type is only supported in some contexts*/);
						if ((Object)(object)val3 == (Object)null)
						{
							continue;
						}
						Graphic targetGraphic2 = ((Selectable)val3).targetGraphic;
						Image val4 = (Image)(object)((targetGraphic2 is Image) ? targetGraphic2 : null);
						if ((Object)(object)val4 == (Object)null || (Object)(object)val4.sprite == (Object)null)
						{
							val4 = ((IEnumerable<Image>)((Component)val3).GetComponentsInChildren<Image>(true)).FirstOrDefault((Func<Image, bool>)((Image val7) => (Object)(object)val7.sprite != (Object)null && (int)val7.type == 1));
						}
						if (!((Object)(object)val4 == (Object)null) && !((Object)(object)val4.sprite == (Object)null))
						{
							nativeButton = val3;
							nativeButtonImage = val4;
							break;
						}
					}
					if ((Object)(object)nativeButtonImage != (Object)null)
					{
						break;
					}
				}
			}
		}
		if ((Object)(object)nativeButton == (Object)null || (Object)(object)nativeButtonImage == (Object)null || (Object)(object)nativeButtonImage.sprite == (Object)null)
		{
			return false;
		}
		Sprite sprite = nativeButtonImage.sprite;
		Color val5 = ((Graphic)nativeButtonImage).color;
		if ((int)((Selectable)nativeButton).transition == 1)
		{
			ColorBlock colors = ((Selectable)nativeButton).colors;
			Color val6 = ((!enabled) ? ((ColorBlock)(ref colors)).disabledColor : (pressed ? ((ColorBlock)(ref colors)).pressedColor : (hover ? ((ColorBlock)(ref colors)).highlightedColor : ((ColorBlock)(ref colors)).normalColor)));
			val5 *= val6 * ((ColorBlock)(ref colors)).colorMultiplier;
		}
		if (NeedsGuiCompensation)
		{
			float a = val5.a;
			val5 = ((Color)(ref val5)).linear;
			val5.a = a;
		}
		SpriteState spriteState = ((Selectable)nativeButton).spriteState;
		if (!enabled && (Object)(object)((SpriteState)(ref spriteState)).disabledSprite != (Object)null)
		{
			sprite = ((SpriteState)(ref spriteState)).disabledSprite;
		}
		else if (pressed && (Object)(object)((SpriteState)(ref spriteState)).pressedSprite != (Object)null)
		{
			sprite = ((SpriteState)(ref spriteState)).pressedSprite;
		}
		else if (hover && (Object)(object)((SpriteState)(ref spriteState)).highlightedSprite != (Object)null)
		{
			sprite = ((SpriteState)(ref spriteState)).highlightedSprite;
		}
		return DrawUiSprite(sprite, rect, val5);
	}

	private bool DrawUiSprite(Sprite sprite, Rect rect, Color drawTint)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = NativeAtlasForGui(sprite.texture);
		Rect textureRect;
		try
		{
			textureRect = sprite.textureRect;
		}
		catch (InvalidOperationException)
		{
			return false;
		}
		if (sprite.packed && (int)sprite.packingRotation != 0)
		{
			return false;
		}
		Vector4 border = sprite.border;
		float num = Mathf.Min(border.x, ((Rect)(ref rect)).width / 3f);
		float num2 = Mathf.Min(border.z, ((Rect)(ref rect)).width / 3f);
		float num3 = Mathf.Min(border.y, ((Rect)(ref rect)).height / 3f);
		float num4 = Mathf.Min(border.w, ((Rect)(ref rect)).height / 3f);
		float[] array = new float[4]
		{
			((Rect)(ref rect)).x,
			((Rect)(ref rect)).x + num,
			((Rect)(ref rect)).xMax - num2,
			((Rect)(ref rect)).xMax
		};
		float[] array2 = new float[4]
		{
			((Rect)(ref rect)).y,
			((Rect)(ref rect)).y + num4,
			((Rect)(ref rect)).yMax - num3,
			((Rect)(ref rect)).yMax
		};
		float[] array3 = new float[4]
		{
			((Rect)(ref textureRect)).x / (float)((Texture)val).width,
			(((Rect)(ref textureRect)).x + border.x) / (float)((Texture)val).width,
			(((Rect)(ref textureRect)).xMax - border.z) / (float)((Texture)val).width,
			((Rect)(ref textureRect)).xMax / (float)((Texture)val).width
		};
		float[] array4 = new float[4]
		{
			((Rect)(ref textureRect)).yMax / (float)((Texture)val).height,
			(((Rect)(ref textureRect)).yMax - border.w) / (float)((Texture)val).height,
			(((Rect)(ref textureRect)).y + border.y) / (float)((Texture)val).height,
			((Rect)(ref textureRect)).y / (float)((Texture)val).height
		};
		Color color = GUI.color;
		GUI.color = drawTint;
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				if (array[j + 1] > array[j] && array2[i + 1] > array2[i])
				{
					GUI.DrawTextureWithTexCoords(new Rect(array[j], array2[i], array[j + 1] - array[j], array2[i + 1] - array2[i]), (Texture)(object)val, new Rect(array3[j], array4[i + 1], array3[j + 1] - array3[j], array4[i] - array4[i + 1]));
				}
			}
		}
		GUI.color = color;
		return true;
	}

	private static Color ControlColor(Color color)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		if (!NeedsGuiCompensation)
		{
			return color;
		}
		float a = color.a;
		color = ((Color)(ref color)).linear;
		color.a = a;
		return color;
	}

	private string NativeInput(Rect rect, string value, int limit, string placeholder)
	{
		//IL_0001: 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_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Expected O, but got Unknown
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Expected O, but got Unknown
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		Line(rect, ControlColor(new Color(0.43f, 0.4f, 0.33f, 1f)));
		Line(new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, ((Rect)(ref rect)).width - 2f, ((Rect)(ref rect)).height - 2f), ControlColor(new Color(0.16f, 0.15f, 0.13f, 1f)));
		Line(new Rect(((Rect)(ref rect)).x + 3f, ((Rect)(ref rect)).y + 3f, ((Rect)(ref rect)).width - 6f, ((Rect)(ref rect)).height - 6f), ControlColor(new Color(0.25f, 0.24f, 0.21f, 1f)));
		bool flag = true;
		GUIStyle val = new GUIStyle(inputStyle);
		if (flag)
		{
			GUIStyleState[] array = (GUIStyleState[])(object)new GUIStyleState[8] { val.normal, val.hover, val.active, val.focused, val.onNormal, val.onHover, val.onActive, val.onFocused };
			foreach (GUIStyleState val2 in array)
			{
				val2.background = null;
			}
		}
		if (NavigationControl(rect, enabled: true) && (Object)(object)TextInput.instance != (Object)null)
		{
			bool search = placeholder == "Search portals...";
			TextInput.instance.RequestText((TextReceiver)(object)new PortalTextReceiver(() => (!search) ? rename : filter, delegate(string v)
			{
				if (search)
				{
					filter = v;
				}
				else
				{
					rename = v;
				}
			}), placeholder, limit);
			textDialog = true;
		}
		GUI.SetNextControlName(placeholder);
		string text = GUI.TextField(rect, value, limit, val);
		if (text.Length == 0)
		{
			GUIStyle val3 = new GUIStyle(val);
			val3.fontStyle = (FontStyle)2;
			val3.normal.textColor = new Color(0.74f, 0.71f, 0.64f, 1f);
			GUI.Label(rect, placeholder, val3);
		}
		return text;
	}

	private bool DropdownButton(Rect rect, string text)
	{
		//IL_0001: 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_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)
		bool result = SolidButton(rect, text, enabled: true, alignLeft: true);
		Color color = default(Color);
		((Color)(ref color))..ctor(1f, 0.65f, 0.12f, 1f);
		float num = ((Rect)(ref rect)).xMax - 22f;
		for (int i = 0; i < 7; i++)
		{
			int num2 = (dropdownOpen ? (1 + i * 2) : (13 - i * 2));
			Line(new Rect(num - (float)num2 / 2f, ((Rect)(ref rect)).center.y - 3f + (float)i, (float)num2, 1f), color);
		}
		return result;
	}

	private bool NavigationControl(Rect rect, bool enabled)
	{
		//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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		int num = drawIndex++;
		if (controllerMode && num == navIndex && enabled)
		{
			Color color = default(Color);
			((Color)(ref color))..ctor(1f, 0.75f, 0.2f);
			Line(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, 2f), color);
			Line(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - 2f, ((Rect)(ref rect)).width, 2f), color);
			if (inPortalList)
			{
				scroll.y = Mathf.Clamp(scroll.y, Mathf.Max(0f, ((Rect)(ref rect)).yMax - 228f), Mathf.Max(0f, ((Rect)(ref rect)).y));
			}
		}
		if (num != activateIndex)
		{
			return false;
		}
		activateIndex = -1;
		return enabled;
	}

	private void HandlePortalNavigation()
	{
		if (textDialog)
		{
			if (!TextInput.IsVisible())
			{
				textDialog = false;
				activateIndex = -1;
			}
			return;
		}
		if (settingsOpen && controllerMode && navIndex == 0)
		{
			int num = (ZInput.GetButtonDown("JoyDPadRight") ? 1 : 0) - (ZInput.GetButtonDown("JoyDPadLeft") ? 1 : 0);
			if (num != 0)
			{
				scalePreview = Mathf.Clamp(uiScale.Value + (float)num * 0.05f, 0.7f, 1.5f);
				uiScale.Value = scalePreview;
				((BaseUnityPlugin)this).Config.Save();
				return;
			}
		}
		bool flag = ZInput.GetButtonDown("JoyDPadDown") || ZInput.GetButtonDown("JoyDPadRight");
		bool flag2 = ZInput.GetButtonDown("JoyDPadUp") || ZInput.GetButtonDown("JoyDPadLeft");
		bool flag3 = focusedPortalControl == "Enter name" || focusedPortalControl == "Search portals...";
		if (!flag3)
		{
			flag |= Input.GetKeyDown((KeyCode)274);
			flag2 |= Input.GetKeyDown((KeyCode)273);
		}
		if (flag || flag2)
		{
			controllerMode = true;
			navIndex = ((navCount != 0) ? ((navIndex + (flag ? 1 : (-1)) + navCount) % navCount) : 0);
		}
		if (Input.GetKeyDown((KeyCode)330) || (!flag3 && Input.GetKeyDown((KeyCode)13)))
		{
			controllerMode = true;
			activateIndex = navIndex;
		}
		if (Input.GetMouseButtonDown(0))
		{
			controllerMode = false;
		}
	}

	private void EnsureSettingsStyles()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_0046: 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_0061: Expected O, but got Unknown
		if (settingsText == null)
		{
			settingsText = new GUIStyle(smallStyle);
			settingsText.fontSize = 20;
			settingsText.normal.textColor = new Color(0.1f, 0.055f, 0.02f, 1f);
			settingsHeading = new GUIStyle(settingsText);
			settingsHeading.fontSize = 24;
			settingsHeading.fontStyle = (FontStyle)1;
		}
	}

	private void DrawScaleControl()
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		if (uiScale != null)
		{
			if (scalePreview < 0f)
			{
				scalePreview = uiScale.Value;
			}
			GUI.Label(new Rect(140f, 222f, 200f, 36f), "UI size: " + Mathf.RoundToInt(scalePreview * 100f) + "%", settingsText);
			NavigationControl(new Rect(350f, 230f, 300f, 30f), enabled: true);
			float num = GUI.HorizontalSlider(new Rect(350f, 236f, 300f, 24f), scalePreview, 0.7f, 1.5f);
			scalePreview = Mathf.Round(num * 100f) / 100f;
			if (!Input.GetMouseButton(0) && Mathf.Abs(scalePreview - uiScale.Value) > 0.001f)
			{
				uiScale.Value = scalePreview;
				((BaseUnityPlugin)this).Config.Save();
			}
		}
	}

	private void DrawWindow(int id)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: 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_0099: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_067f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0691: Unknown result type (might be due to invalid IL or missing references)
		//IL_0698: Expected O, but got Unknown
		//IL_06b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0713: Unknown result type (might be due to invalid IL or missing references)
		//IL_072c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0731: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_043c: Unknown result type (might be due to invalid IL or missing references)
		//IL_048c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0492: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_077c: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0753: Unknown result type (might be due to invalid IL or missing references)
		//IL_0509: Unknown result type (might be due to invalid IL or missing references)
		//IL_051b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0521: Unknown result type (might be due to invalid IL or missing references)
		//IL_063e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0850: Unknown result type (might be due to invalid IL or missing references)
		//IL_098a: Unknown result type (might be due to invalid IL or missing references)
		//IL_09b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0885: Unknown result type (might be due to invalid IL or missing references)
		//IL_0571: Unknown result type (might be due to invalid IL or missing references)
		//IL_0578: Unknown result type (might be due to invalid IL or missing references)
		//IL_080e: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a13: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a1a: Expected O, but got Unknown
		//IL_0a32: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a44: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a53: Expected O, but got Unknown
		//IL_0a81: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a97: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aa1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_081f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0817: Unknown result type (might be due to invalid IL or missing references)
		//IL_090d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0605: Unknown result type (might be due to invalid IL or missing references)
		//IL_0931: Unknown result type (might be due to invalid IL or missing references)
		//IL_095f: Unknown result type (might be due to invalid IL or missing references)
		drawIndex = 0;
		fullNameHint = "";
		GUI.backgroundColor = Color.white;
		GUI.Label(new Rect(55f, 65f, 690f, 40f), "RUNEGATE", titleStyle);
		if (settingsOpen)
		{
			EnsureSettingsStyles();
			GUI.Label(new Rect(140f, 155f, 520f, 40f), "SETTINGS", settingsHeading);
			DrawScaleControl();
			GUI.Label(new Rect(140f, 275f, 520f, 56f), "Release the slider to apply. Changes save automatically.", settingsText);
			GUI.Label(new Rect(140f, 345f, 520f, 36f), "PORTAL MEMORY", settingsHeading);
			if (SolidButton(new Rect(140f, 385f, 520f, 40f), rememberRoutes.Value ? "After restarts" : "This session only"))
			{
				rememberRoutes.Value = !rememberRoutes.Value;
				((BaseUnityPlugin)this).Config.Save();
				if (rememberRoutes.Value)
				{
					SaveRoutes();
				}
			}
			if (SolidButton(new Rect(140f, 450f, 200f, 40f), "Reset size"))
			{
				scalePreview = 1f;
				uiScale.Value = 1f;
				((BaseUnityPlugin)this).Config.Save();
			}
			if (SolidButton(new Rect(560f, 502f, 150f, 32f), "Back"))
			{
				settingsOpen = false;
			}
			navCount = drawIndex;
			if (navIndex >= navCount)
			{
				navIndex = 0;
			}
			return;
		}
		Line(new Rect(65f, 115f, 670f, 1f), new Color(0.25f, 0.17f, 0.08f));
		if (!dropdownOpen)
		{
			GUI.Label(new Rect(90f, 145f, 620f, 27f), "THIS PORTAL", headingStyle);
			rename = NativeInput(new Rect(90f, 174f, 420f, 40f), rename, 20, "Enter name");
			if (SolidButton(new Rect(525f, 174f, 185f, 40f), "Save name") && HasAccess(source))
			{
				pendingRename = Clean(rename);
				renameAt = Time.realtimeSinceStartup;
				status = "Confirming name...";
				source.SetText(pendingRename);
			}
		}
		GUI.Label(new Rect(90f, (float)(dropdownOpen ? 130 : 242), 620f, 27f), "DESTINATION", headingStyle);
		Destination destination = destinations.FirstOrDefault((Destination d) => d.id == selectedId);
		string text = ((destination == null) ? "Choose a portal" : (string.IsNullOrEmpty(destination.name) ? "Unnamed portal" : destination.name));
		if (DropdownButton(new Rect(90f, (float)(dropdownOpen ? 157 : 273), 620f, 44f), text))
		{
			dropdownOpen = !dropdownOpen;
		}
		if (dropdownOpen)
		{
			Line(new Rect(90f, 207f, 620f, 295f), new Color(0.12f, 0.075f, 0.035f, 1f));
			Line(new Rect(92f, 209f, 616f, 291f), ControlColor(new Color(0.22f, 0.18f, 0.13f, 1f)));
			filter = NativeInput(new Rect(100f, 214f, 600f, 32f), filter, 64, "Search portals...");
			List<Destination> list = VisibleDestinations();
			GUISkin skin = GUI.skin;
			GUI.skin = portalScrollSkin;
			inPortalList = true;
			scroll = GUI.BeginScrollView(new Rect(100f, 252f, 600f, 228f), scroll, new Rect(0f, 0f, 575f, (float)Mathf.Max(228, list.Count * 38)), false, true, portalScrollSkin.horizontalScrollbar, portalScrollSkin.verticalScrollbar);
			for (int num = 0; num < list.Count; num++)
			{
				Destination destination2 = list[num];
				if (SolidButton(new Rect(0f, (float)(num * 38), 522f, 34f), ((destination2.id == selectedId) ? "> " : "") + (string.IsNullOrEmpty(destination2.name) ? "Unnamed portal" : destination2.name) + "   -   " + Vector3.Distance(((Component)source).transform.position, destination2.position).ToString("0") + " m", enabled: true, alignLeft: true))
				{
					selectedId = destination2.id;
					dropdownOpen = false;
				}
				if (SolidButton(new Rect(530f, (float)(num * 38), 40f, 34f), favourites.Contains(destination2.id) ? "*" : "+"))
				{
					ToggleFavourite(destination2.id);
				}
			}
			if (list.Count == 0)
			{
				GUI.Label(new Rect(10f, 10f, 540f, 50f), "No portals found", labelStyle);
			}
			GUI.EndScrollView();
			inPortalList = false;
			GUI.skin = skin;
		}
		else
		{
			ZDO zDO = ((Component)source).GetComponent<ZNetView>().GetZDO();
			bool flag = IsShared(zDO.m_uid);
			GUIStyle val = new GUIStyle(labelStyle);
			val.fontSize = 18;
			val.normal.textColor = new Color(0.1f, 0.055f, 0.02f);
			Line(new Rect(90f, 321f, 22f, 22f), ControlColor(new Color(0.65f, 0.48f, 0.24f, 1f)));
			Line(new Rect(92f, 323f, 18f, 18f), ControlColor(new Color(0.25f, 0.24f, 0.21f, 1f)));
			if (flag)
			{
				GUI.Label(new Rect(93f, 319f, 24f, 26f), "X", labelStyle);
			}
			GUI.Label(new Rect(121f, 318f, 480f, 30f), "Share destination with friends", val);
			bool flag2 = ((NavigationControl(new Rect(90f, 318f, 510f, 30f), metadataReady) | GUI.Button(new Rect(90f, 318f, 510f, 30f), "", GUIStyle.none)) ? (!flag) : flag);
			if (flag2 != flag && metadataReady && HasAccess(source))
			{
				if (!flag2 || destination != null)
				{
					SendMetadata(1, zDO.m_uid, flag2 ? destination.id : ZDOID.None, "");
				}
				else
				{
					status = "Choose a destination first.";
				}
			}
			if (SolidButton(new Rect(90f, 353f, 300f, 44f), "Select destination", destination != null))
			{
				SelectDestination(destination);
			}
			if (SolidButton(new Rect(410f, 353f, 300f, 44f), "Ping on map", destination != null && !Game.m_noMap && Time.realtimeSinceStartup - lastPing >= 2f))
			{
				PingDestination(destination);
			}
			GUI.Label(new Rect(410f, 398f, 300f, 24f), Game.m_noMap ? "Map disabled" : "Ping visible to friends", smallStyle);
			if (SolidButton(new Rect(245f, 445f, 310f, 35f), "Use vanilla pairing"))
			{
				if (IsShared(((Component)source).GetComponent<ZNetView>().GetZDO().m_uid))
				{
					status = "Turn off sharing first.";
				}
				else
				{
					Choices.Remove(((Component)source).GetComponent<ZNetView>().GetZDO().m_uid);
					SaveRoutes();
					Close();
				}
			}
		}
		GUI.Label(new Rect(90f, 501f, 455f, 44f), status, smallStyle);
		if (SolidButton(new Rect(560f, 502f, 150f, 32f), "Close"))
		{
			Close();
		}
		navCount = drawIndex;
		if (navIndex >= navCount)
		{
			navIndex = Mathf.Max(0, navCount - 1);
		}
		if (fullNameHint.Length > 0)
		{
			GUIStyle val2 = new GUIStyle(inputStyle);
			val2.wordWrap = true;
			val2.fontSize = 18;
			val2.normal.textColor = Color.white;
			float num2 = val2.CalcHeight(new GUIContent(fullNameHint), 610f) + 12f;
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(90f, Mathf.Max(115f, 490f - num2), 620f, num2);
			Line(val3, new Color(0.12f, 0.11f, 0.09f, 1f));
			GUI.Label(val3, fullNameHint, val2);
		}
	}

	private void SelectDestination(Destination destination)
	{
		//IL_0046: 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_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		if (destination == null || (Object)(object)source == (Object)null || !HasAccess(source))
		{
			return;
		}
		ZDO zDO = ((Component)source).GetComponent<ZNetView>().GetZDO();
		if (zDO != null && !(zDO.m_uid == destination.id) && destinations.Any((Destination d) => d.id == destination.id))
		{
			if (IsShared(zDO.m_uid))
			{
				SendMetadata(1, zDO.m_uid, destination.id, "");
				status = "Updating shared destination...";
				return;
			}
			Choices[zDO.m_uid] = destination.id;
			SaveRoutes();
			ZDOMan.instance.RequestZDO(destination.id);
			((Character)Player.m_localPlayer).Message((MessageType)2, "Destination: " + destination.name + " - walk through the portal", 0, (Sprite)null, false);
			Close();
		}
	}

	private void PingDestination(Destination destination)
	{
		//IL_0043: 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)
		if (destination == null || Game.m_noMap || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)Chat.instance == (Object)null || (Object)(object)Minimap.instance == (Object)null)
		{
			return;
		}
		try
		{
			lastPing = Time.realtimeSinceStartup;
			Chat.instance.SendPing(destination.position);
			Close();
			Minimap.instance.ShowPointOnMap(destination.position);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Map ping sent for portal: " + destination.name));
		}
		catch (Exception ex)
		{
			status = "Could not ping this portal. See the log.";
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
	}

	private void DisposeStyles()
	{
		SetPauseButtonsBlocked(blocked: false);
		foreach (Texture2D uiTexture in uiTextures)
		{
			if ((Object)(object)uiTexture != (Object)null)
			{
				Object.Destroy((Object)(object)uiTexture);
			}
		}
		uiTextures.Clear();
		nativeAtlasCopies.Clear();
		if ((Object)(object)portalScrollSkin != (Object)null)
		{
			Object.Destroy((Object)(object)portalScrollSkin);
		}
	}

	private void RegisterMetadata()
	{
		metadata.Clear();
		metaRequests.Clear();
		metaFile = null;
		metadataWritable = false;
		metadataReady = false;
		nextMeta = 0f;
		if (rpc != null)
		{
			rpc.Register<ZPackage>("Runegate.Meta.v1", (Action<long, ZPackage>)OnMetadataRequest);
			rpc.Register<ZPackage>("Runegate.MetaReply.v1", (Action<long, ZPackage>)OnMetadataReply);
		}
	}

	private void UpdateMetadata()
	{
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Expected O, but got Unknown
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)ZNet.instance == (Object)null || rpc == null)
		{
			return;
		}
		if (ZNet.instance.IsServer())
		{
			long worldUID;
			try
			{
				worldUID = ZNet.instance.GetWorldUID();
			}
			catch (NullReferenceException)
			{
				return;
			}
			if (worldUID == 0)
			{
				return;
			}
			string text = Path.Combine(Paths.ConfigPath, "Runegate", "World-" + worldUID.ToString("X16") + ".shared");
			if (metaFile != text)
			{
				LoadSharedFile(text);
			}
		}
		if (favouriteFile != routeFile)
		{
			favouriteFile = routeFile;
			favourites.Clear();
			if (routeFile != null)
			{
				try
				{
					if (File.Exists(routeFile + ".favourites"))
					{
						ZPackage val = new ZPackage(File.ReadAllBytes(routeFile + ".favourites"));
						int num = val.ReadInt();
						if (num < 0 || num > 10000)
						{
							throw new Exception("Invalid favourites count");
						}
						for (int i = 0; i < num; i++)
						{
							favourites.Add(val.ReadZDOID());
						}
					}
				}
				catch (Exception ex2)
				{
					favourites.Clear();
					((BaseUnityPlugin)this).Logger.LogWarning((object)ex2.Message);
				}
			}
		}
		if (!ZNet.instance.IsServer() && (Object)(object)Player.m_localPlayer != (Object)null && Time.realtimeSinceStartup >= nextMeta)
		{
			nextMeta = Time.realtimeSinceStartup + 5f;
			SendMetadata(0, ZDOID.None, ZDOID.None, "");
		}
	}

	private void LoadSharedFile(string file)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		metadata.Clear();
		metaFile = file;
		metadataWritable = false;
		metadataReady = false;
		try
		{
			bool flag = File.Exists(file);
			if (flag)
			{
				ReadMetadata(new ZPackage(File.ReadAllBytes(file)), metadata);
			}
			metadataWritable = true;
			metadataReady = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Shared destinations: " + (flag ? "restored " : "new file, ") + metadata.Count + " records from " + file));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Shared destination load failed; edits blocked to protect saved data: " + file + " - " + ex.Message));
		}
	}

	private bool ShouldThrottleMetadata(long sender, int op, float now)
	{
		if (op != 0)
		{
			return false;
		}
		if (metaRequests.TryGetValue(sender, out var value) && now - value < 0.2f)
		{
			return true;
		}
		metaRequests[sender] = now;
		return false;
	}

	private static void ReadMetadata(ZPackage p, Dictionary<ZDOID, PortalMeta> result)
	{
		//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_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		int num = p.ReadInt();
		int num2 = p.ReadInt();
		if (num != 1 || num2 < 0 || num2 > 10000)
		{
			throw new Exception("Invalid metadata");
		}
		Dictionary<ZDOID, PortalMeta> dictionary = new Dictionary<ZDOID, PortalMeta>();
		for (int i = 0; i < num2; i++)
		{
			ZDOID key = p.ReadZDOID();
			ZDOID target = p.ReadZDOID();
			p.ReadString();
			dictionary[key] = new PortalMeta
			{
				target = target
			};
		}
		result.Clear();
		foreach (KeyValuePair<ZDOID, PortalMeta> item in dictionary)
		{
			result[item.Key] = item.Value;
		}
	}

	private ZPackage MetadataPackage()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_0037: 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)
		ZPackage val = new ZPackage();
		val.Write(1);
		val.Write(metadata.Count);
		foreach (KeyValuePair<ZDOID, PortalMeta> metadatum in metadata)
		{
			val.Write(metadatum.Key);
			val.Write(metadatum.Value.target);
			val.Write("");
		}
		return val;
	}

	private void SaveMetadata()
	{
		if (metaFile == null || !metadataWritable)
		{
			throw new Exception("World not ready");
		}
		Directory.CreateDirectory(Path.GetDirectoryName(metaFile));
		string text = metaFile + ".tmp";
		File.WriteAllBytes(text, MetadataPackage().GetArray());
		if (File.Exists(metaFile))
		{
			File.Replace(text, metaFile, null);
		}
		else
		{
			File.Move(text, metaFile);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Shared destinations saved: " + metadata.Count + " records to " + metaFile));
	}

	private void SendMetadata(int op, ZDOID id, ZDOID target, string group)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		//IL_001b: 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)
		long num = ServerID();
		if (num != 0)
		{
			ZPackage val = new ZPackage();
			val.Write(op);
			val.Write(id);
			val.Write(target);
			val.Write(group);
			rpc.InvokeRoutedRPC(num, "Runegate.Meta.v1", new object[1] { val });
		}
	}

	private bool IsMetadataAdmin(long sender)
	{
		ZNetPeer peer = ZNet.instance.GetPeer(sender);
		if (peer != null)
		{
			return ZNet.instance.IsAdmin(peer.m_rpc.GetSocket().GetHostName());
		}
		if (ZNet.instance.IsServer() && sender == ServerID())
		{
			return (Object)(object)Player.m_localPlayer != (Object)null;
		}
		return false;
	}

	private bool MayEditRoute(long sender, ZDO portal)
	{
		//IL_0023: 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_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		ZNetPeer peer = ZNet.instance.GetPeer(sender);
		if (peer == null && sender != ServerID())
		{
			return false;
		}
		ZDO val = ((peer != null) ? ZDOMan.instance.GetZDO(peer.m_characterID) : (((Object)(object)Player.m_localPlayer == (Object)null) ? null : ((Component)Player.m_localPlayer).GetComponent<ZNetView>().GetZDO()));
		if (val == null || Vector3.Distance(val.GetPosition(), portal.GetPosition()) > 8f)
		{
			return false;
		}
		long num = val.GetLong("playerID", 0L);
		if (num == 0)
		{
			return false;
		}
		FieldInfo field = typeof(ZDOMan).GetField("m_objectsByID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (!(field.GetValue(ZDOMan.instance) is Dictionary<ZDOID, ZDO> dictionary) || (Object)(object)ZNetScene.instance == (Object)null)
		{
			return false;
		}
		foreach (ZDO value in dictionary.Values)
		{
			GameObject prefab = ZNetScene.instance.GetPrefab(value.GetPrefab());
			PrivateArea val2 = (((Object)(object)prefab == (Object)null) ? null : prefab.GetComponent<PrivateArea>());
			if ((Object)(object)val2 == (Object)null || !value.GetBool("enabled", false))
			{
				continue;
			}
			Vector3 val3 = value.GetPosition() - portal.GetPosition();
			val3.y = 0f;
			if (((Vector3)(ref val3)).magnitude > val2.m_radius)
			{
				continue;
			}
			bool flag = value.GetLong("creator", 0L) == num;
			int num2 = Math.Min(value.GetInt("permitted", 0), 1000);
			for (int i = 0; i < num2; i++)
			{
				if (flag)
				{
					break;
				}
				flag = value.GetLong("pu_id" + i, 0L) == num;
			}
			if (!flag)
			{
				return false;
			}
		}
		return true;
	}

	private void OnMetadataRequest(long sender, ZPackage p)
	{
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Expected O, but got Unknown
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Expected O, but got Unknown
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Expected O, but got Unknown
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || metaFile == null)
		{
			return;
		}
		try
		{
			int num = p.ReadInt();
			if (ShouldThrottleMetadata(sender, num, Time.realtimeSinceStartup))
			{
				return;
			}
			ZDOID id = p.ReadZDOID();
			ZDOID target = p.ReadZDOID();
			string text = Clean(p.ReadString());
			if (text.Length > 24)
			{
				text = text.Substring(0, 24);
			}
			bool flag = IsMetadataAdmin(sender);
			string text2 = "";
			if (num != 0)
			{
				if (!metadataWritable || metadata.Count >= 10000)
				{
					throw new Exception("Shared metadata unavailable");
				}
				List<ZDO> portalList = ZDOMan.instance.GetPortalList();
				ZDO val = ((IEnumerable<ZDO>)portalList).FirstOrDefault((Func<ZDO, bool>)((ZDO v) => v.m_uid == id));
				if (val == null)
				{
					throw new Exception("Portal no longer exists");
				}
				if (num == 1 && !MayEditRoute(sender, val))
				{
					throw new Exception("Portal access denied");
				}
				if (num != 1)
				{
					throw new Exception("Unknown edit");
				}
				if (num == 1 && target != ZDOID.None && (target == id || !portalList.Any((ZDO v) => v.m_uid == target)))
				{
					throw new Exception("Invalid destination");
				}
				PortalMeta value;
				bool flag2 = metadata.TryGetValue(id, out value);
				PortalMeta portalMeta = new PortalMeta();
				portalMeta.target = target;
				PortalMeta value2 = portalMeta;
				metadata[id] = value2;
				try
				{
					SaveMetadata();
				}
				catch
				{
					if (flag2)
					{
						metadata[id] = value;
					}
					else
					{
						metadata.Remove(id);
					}
					throw;
				}
				text2 = "Shared destination saved";
			}
			ZPackage val2 = new ZPackage();
			val2.Write(flag);
			val2.Write(text2);
			val2.Write(MetadataPackage().GetArray());
			rpc.InvokeRoutedRPC(sender, "Runegate.MetaReply.v1", new object[1] { val2 });
			if (num == 0)
			{
				return;
			}
			foreach (ZNetPeer peer in ZNet.instance.GetPeers())
			{
				if (peer.m_uid != sender)
				{
					ZPackage val3 = new ZPackage();
					val3.Write(IsMetadataAdmin(peer.m_uid));
					val3.Write("");
					val3.Write(MetadataPackage().GetArray());
					rpc.InvokeRoutedRPC(peer.m_uid, "Runegate.MetaReply.v1", new object[1] { val3 });
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Shared destination request failed: " + ex.Message));
			ZPackage val4 = new ZPackage();
			val4.Write(false);
			val4.Write(ex.Message);
			val4.Write(MetadataPackage().GetArray());
			rpc.InvokeRoutedRPC(sender, "Runegate.MetaReply.v1", new object[1] { val4 });
		}
	}

	private void OnMetadataReply(long sender, ZPackage p)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0054: 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_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_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		if (sender != ServerID())
		{
			return;
		}
		try
		{
			p.ReadBool();
			string text = p.ReadString();
			Dictionary<ZDOID, PortalMeta> dictionary = new Dictionary<ZDOID, PortalMeta>();
			ReadMetadata(new ZPackage(p.ReadByteArray()), dictionary);
			metadata.Clear();
			foreach (KeyValuePair<ZDOID, PortalMeta> item in dictionary)
			{
				metadata[item.Key] = item.Value;
			}
			metadataReady = true;
			if (Open)
			{
				ZNetView component = ((Component)source).GetComponent<ZNetView>();
				ZDO val = (((Object)(object)component == (Object)null) ? null : component.GetZDO());
				if (val != null && metadata.TryGetValue(val.m_uid, out var value) && value.target != ZDOID.None)
				{
					selectedId = value.target;
				}
			}
			if (Open && text.Length > 0)
			{
				status = text;
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Metadata rejected: " + ex.Message));
		}
	}

	internal bool IsShared(ZDOID id)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		if (metadata.TryGetValue(id, out var value))
		{
			return value.target != ZDOID.None;
		}
		return false;
	}

	private List<Destination> VisibleDestinations()
	{
		return (from d in destinations
			where (d.name ?? "").IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0
			orderby favourites.Contains(d.id) descending
			select d).ThenBy<Destination, string>((Destination d) => d.name, StringComparer.OrdinalIgnoreCase).ToList();
	}

	private void ToggleFavourite(ZDOID id)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_004a: Expected O, but got Unknown
		//IL_006b: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		if (favourites.Contains(id))
		{
			favourites.Remove(id);
		}
		else
		{
			favourites.Add(id);
		}
		if (routeFile == null)
		{
			return;
		}
		try
		{
			Directory.CreateDirectory(Path.GetDirectoryName(routeFile));
			ZPackage val = new ZPackage();
			val.Write(favourites.Count);
			foreach (ZDOID favourite in favourites)
			{
				val.Write(favourite);
			}
			File.WriteAllBytes(routeFile + ".favourites", val.GetArray());
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)ex.Message);
		}
	}
}
[HarmonyPatch(typeof(TeleportWorld), "Interact")]
internal static class InteractPatch
{
	private static bool Prefix(TeleportWorld __instance, Humanoid __0, bool __1, bool __2, ref bool __result)
	{
		if ((Object)(object)Plugin.Instance == (Object)null || !((Behaviour)Plugin.Instance).enabled || __2 || (Object)(object)__0 != (Object)(object)Player.m_localPlayer)
		{
			return true;
		}
		__result = !__1;
		if (!__1 && Plugin.HasAccess(__instance))
		{
			Plugin.Instance.Show(__instance);
		}
		return false;
	}
}
[HarmonyPatch(typeof(TeleportWorld), "GetHoverText")]
internal static class HoverPatch
{
	private static void Postfix(TeleportWorld __instance, ref string __result)
	{
		//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_0051: 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_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Plugin.Instance == (Object)null || !((Behaviour)Plugin.Instance).enabled)
		{
			return;
		}
		ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
		if (!((Object)(object)component == (Object)null) && component.GetZDO() != null)
		{
			ZDOID target = Plugin.GetTarget(component.GetZDO(), (ConnectionType)1);
			string value = null;
			ZDO val = ((ZDOMan.instance != null) ? ZDOMan.instance.GetZDO(target) : null);
			if (val != null)
			{
				value = val.GetString("tag", "");
			}
			else
			{
				Plugin.Instance.portalNames.TryGetValue(target, out value);
			}
			string text = ((target == ZDOID.None) ? "Not linked" : (string.IsNullOrEmpty(value) ? "Unnamed destination" : Plugin.Clean(value)));
			__result = Plugin.Clean(__instance.GetText()) + " → " + text + (Plugin.Instance.IsShared(component.GetZDO().m_uid) ? " (Shared)" : "") + "\n" + Localization.instance.Localize("[$KEY_Use] Open Runegate");
		}
	}
}
[HarmonyPatch]
internal static class RoutePatch
{
	private static IEnumerable<MethodBase> TargetMethods()
	{
		return ((IEnumerable<string>)new string[3] { "HaveTarget", "TargetFound", "Teleport" }).Select((Func<string, MethodBase>)((string n) => typeof(TeleportWorld).GetMethod(n, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)));
	}

	internal static List<CodeInstruction> Rewrite(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo original = typeof(ZDO).GetMethod("GetConnectionZDOID", new Type[1] { typeof(ConnectionType) });
		MethodInfo method = typeof(Plugin).GetMethod("GetTarget", BindingFlags.Static | BindingFlags.NonPublic);
		List<CodeInstruction> list = instructions.Select((Func<CodeInstruction, CodeInstruction>)((CodeInstruction i) => new CodeInstruction(i))).ToList();
		List<CodeInstruction> list2 = list.Where((CodeInstruction i) => (i.opcode == OpCodes.Call || i.opcode == OpCodes.Callvirt) && original.Equals(i.operand)).ToList();
		if (list2.Count != 1)
		{
			throw new InvalidOperationException("Unexpected portal IL; refusing routing patch.");
		}
		list2[0].opcode = OpCodes.Call;
		list2[0].operand = method;
		return list;
	}

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		return Rewrite(instructions);
	}
}
[HarmonyPatch(typeof(ZInput), "GetMouseScrollWheel")]
internal static class ScrollInputPatch
{
	private static void Postfix(ref float __result)
	{
		if (Plugin.Open)
		{
			__result = 0f;
		}
	}
}
[HarmonyPatch(typeof(Player), "TakeInput")]
internal static class InputPatch
{
	private static void Postfix(ref bool __result)
	{
		if (Plugin.Open)
		{
			__result = false;
		}
	}
}
[HarmonyPatch(typeof(TextInput), "IsVisible")]
internal static class FocusPatch
{
	private static void Postfix(ref bool __result)
	{
		if (Plugin.Open)
		{
			__result = true;
		}
	}
}