Decompiled source of Portaler v1.0.13

plugins/Portaler.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Splatform;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Profiling;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Portaler")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.13.0")]
[assembly: AssemblyInformationalVersion("1.0.13")]
[assembly: AssemblyProduct("Portaler")]
[assembly: AssemblyTitle("Portaler")]
[assembly: AssemblyVersion("1.0.13.0")]
namespace Portaler;

public static class Art
{
	private static readonly Dictionary<int, Sprite> PinSprites = new Dictionary<int, Sprite>();

	private static readonly Dictionary<int, Texture2D> CatIcons = new Dictionary<int, Texture2D>();

	private static Sprite _softDot;

	private static Color Px(Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		return c;
	}

	private static Texture2D LoadPng(string resource)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		try
		{
			using Stream stream = typeof(Art).Assembly.GetManifestResourceStream("Portaler." + resource);
			if (stream == null)
			{
				return null;
			}
			MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, memoryStream.ToArray()))
			{
				return null;
			}
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return val;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not load " + resource + ": " + ex.Message));
			return null;
		}
	}

	public static Sprite PinSprite(int category = 0)
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		category = Categories.Clamp(category);
		if (PinSprites.TryGetValue(category, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		Texture2D val = LoadPng("pin_" + Categories.Keys[category] + ".png") ?? LoadPng("pin_none.png") ?? FallbackRing(64);
		value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		PinSprites[category] = value;
		return value;
	}

	public static Texture2D CategoryIcon(int category)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Invalid comparison between Unknown and I4
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		category = Categories.Clamp(category);
		if (category == 0)
		{
			return null;
		}
		if (CatIcons.TryGetValue(category, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		value = LoadPng("cat_" + Categories.Keys[category] + ".png");
		if ((Object)(object)value != (Object)null && (int)QualitySettings.activeColorSpace == 1)
		{
			Color[] pixels = value.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				pixels[i] = Px(pixels[i]);
			}
			value.SetPixels(pixels);
			value.Apply();
		}
		if ((Object)(object)value != (Object)null)
		{
			((Object)value).hideFlags = (HideFlags)61;
		}
		CatIcons[category] = value;
		return value;
	}

	private static Texture2D FallbackRing(int size)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: 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_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		float num = (float)(size - 1) / 2f;
		float num2 = (float)size / 2f - 1f;
		float num3 = num2 * 0.55f;
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				float num4 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num));
				Color val2 = ((num4 > num2 || num4 < num3) ? Color.clear : Color.Lerp(new Color(1f, 0.7f, 0.15f), new Color(0.8f, 0.1f, 0.05f), (num4 - num3) / (num2 - num3)));
				val.SetPixel(j, i, val2);
			}
		}
		val.Apply();
		return val;
	}

	public static Texture2D Box(Color fill, Color border, Color highlight, int borderPx = 2)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_003c: 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)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(16, 16, (TextureFormat)4, false);
		for (int i = 0; i < 16; i++)
		{
			for (int j = 0; j < 16; j++)
			{
				int num = Mathf.Min(Mathf.Min(j, i), Mathf.Min(15 - j, 15 - i));
				Color val2 = ((num < borderPx) ? border : ((num == borderPx) ? highlight : fill));
				if (num > borderPx)
				{
					val2 = Color.Lerp(val2, Color.black, (1f - (float)i / 16f) * 0.12f);
				}
				val.SetPixel(j, i, Px(val2));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)0;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	private static float Hash(int ix, int iy, int seed)
	{
		int num = ix * 374761393 + iy * 668265263 + seed * 1442695041;
		int num2 = (num ^ (num >>> 13)) * 1274126177;
		return (float)(uint)((num2 ^ (num2 >>> 16)) & 0xFFFF) / 65535f;
	}

	private static float Noise(float x, float y, int seed)
	{
		int num = Mathf.FloorToInt(x);
		int num2 = Mathf.FloorToInt(y);
		float num3 = x - (float)num;
		float num4 = y - (float)num2;
		float num5 = num3 * num3 * (3f - 2f * num3);
		float num6 = num4 * num4 * (3f - 2f * num4);
		float num7 = Hash(num, num2, seed);
		float num8 = Hash(num + 1, num2, seed);
		float num9 = Hash(num, num2 + 1, seed);
		float num10 = Hash(num + 1, num2 + 1, seed);
		float num11 = num7 + (num8 - num7) * num5;
		float num12 = num9 + (num10 - num9) * num5;
		return num11 + (num12 - num11) * num6;
	}

	private static Color Mul(Color c, float r, float g, float b)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		return new Color(c.r * r, c.g * g, c.b * b, 1f);
	}

	public static Texture2D Wood(int w, int h, float frame, Color fill, Color frameCol, int seed, float rough)
	{
		//IL_0015: 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)
		w = Mathf.Max(8, w);
		h = Mathf.Max(8, h);
		return ToTexture(WoodPixels(w, h, frame, fill, frameCol, seed, rough), w, h);
	}

	public static Texture2D ToTexture(Color32[] px, int w, int h)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		Texture2D val = new Texture2D(w, h, (TextureFormat)4, false);
		val.SetPixels32(px);
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	public static Color32[] WoodPixels(int w, int h, float frame, Color fill, Color frameCol, int seed, float rough)
	{
		//IL_0022: 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_0050: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: 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)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_030f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: 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_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: 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_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: 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_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		w = Mathf.Max(8, w);
		h = Mathf.Max(8, h);
		Color32[] array = (Color32[])(object)new Color32[w * h];
		Color val = default(Color);
		((Color)(ref val))..ctor(Mathf.Min(1f, frameCol.r * 1.25f), Mathf.Min(1f, frameCol.g * 1.22f), Mathf.Min(1f, frameCol.b * 1.18f), 1f);
		Color val2 = Mul(frameCol, 0.72f, 0.7f, 0.68f);
		Color val3 = Mul(fill, 0.8f, 0.78f, 0.76f);
		Color val4 = Mul(fill, 0.55f, 0.55f, 0.55f);
		Color val5 = default(Color);
		((Color)(ref val5))..ctor(4f / 51f, 4f / 85f, 0.02745098f, 1f);
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				int num = j;
				int num2 = w - 1 - j;
				int num3 = i;
				int num4 = h - 1 - i;
				int num5 = Mathf.Min(Mathf.Min(num, num2), Mathf.Min(num3, num4));
				bool num6 = Mathf.Min(num3, num4) <= Mathf.Min(num, num2);
				int num7 = (num6 ? j : i);
				int num8 = (num6 ? ((num3 != num5) ? 1 : 0) : ((num == num5) ? 2 : 3));
				float num9 = Noise((float)num7 * 0.08f, (float)num8 * 7.3f, seed) * rough;
				float num10 = frame + (Noise((float)num7 * 0.05f, (float)num8 * 5.1f + 50f, seed) - 0.5f) * rough * 1.6f;
				if ((float)num5 < num9 - 0.5f)
				{
					array[i * w + j] = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
					continue;
				}
				float a = (((float)num5 >= num9 + 0.5f) ? 1f : ((float)num5 - num9 + 0.5f));
				Color val6;
				if ((float)num5 < num10)
				{
					float num11 = Noise((float)num7 * 0.03f, (float)num5 * 0.9f + (float)num8 * 11f, seed + 1);
					float num12 = Noise((float)num7 * 0.15f, (float)num5 * 0.4f + (float)num8 * 3f, seed + 2);
					val6 = Color.Lerp(frameCol, val2, Mathf.Clamp01(num11 * 0.8f + num12 * 0.3f));
					float num13 = ((float)num5 - num9) / Mathf.Max(1f, num10 - num9);
					if (num13 < 0.25f)
					{
						val6 = Color.Lerp(val6, val, 0.5f * (1f - num13 / 0.25f));
					}
					if (num10 - (float)num5 < 1.6f)
					{
						val6 = Color.Lerp(val6, val5, 0.65f);
					}
				}
				else
				{
					float num14 = Noise((float)j * 0.012f, (float)i * 0.22f, seed + 3);
					float num15 = Noise((float)j * 0.06f, (float)i * 0.6f, seed + 4);
					val6 = Color.Lerp(fill, val3, Mathf.Clamp01(num14 * 0.7f + num15 * 0.3f));
					float num16 = (float)num5 - num10;
					if (num16 < 5f)
					{
						val6 = Color.Lerp(val6, val4, (5f - num16) / 5f * 0.6f);
					}
				}
				val6.a = a;
				array[i * w + j] = Color32.op_Implicit(Px(val6));
			}
		}
		return array;
	}

	public static Texture2D Arrow(Color col, int size = 24)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_0066: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				float num = (float)j + 0.5f;
				float num2 = (float)i + 0.5f;
				float num3 = ((float)size - num) * 0.5f;
				float num4 = Mathf.Abs(num2 - (float)size / 2f) - num3;
				float num5 = Mathf.Clamp01(0.5f - num4);
				if (num < 2f)
				{
					num5 = 0f;
				}
				val.SetPixel(j, i, Px(new Color(col.r, col.g, col.b, num5)));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	public static Sprite SoftDot()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_softDot != (Object)null)
		{
			return _softDot;
		}
		Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false);
		float num = 15.5f;
		for (int i = 0; i < 32; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				float num2 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num)) / 16f;
				float num3 = Mathf.Clamp01(1f - num2);
				val.SetPixel(j, i, new Color(1f, 1f, 1f, num3 * num3));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		_softDot = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f));
		return _softDot;
	}

	public static Texture2D ArrowLeft(Color col, int size = 24)
	{
		//IL_0000: 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_0012: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = Arrow(col, size);
		Texture2D val2 = new Texture2D(size, size, (TextureFormat)4, false);
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				val2.SetPixel(j, i, val.GetPixel(size - 1 - j, i));
			}
		}
		val2.Apply();
		((Texture)val2).filterMode = (FilterMode)1;
		((Object)val2).hideFlags = (HideFlags)61;
		Object.Destroy((Object)(object)val);
		return val2;
	}

	public static Texture2D Magnifier(Color col, int size = 32)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor((float)size * 0.42f, (float)size * 0.58f);
		float num = (float)size * 0.28f;
		float num2 = (float)size * 0.07f;
		Vector2 val3 = val2 + new Vector2(num * 0.72f, (0f - num) * 0.72f);
		Vector2 val4 = default(Vector2);
		((Vector2)(ref val4))..ctor((float)size * 0.9f, (float)size * 0.1f);
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				Vector2 val5 = new Vector2((float)j + 0.5f, (float)i + 0.5f);
				float num3 = Mathf.Abs(Vector2.Distance(val5, val2) - num) - num2;
				Vector2 val6 = val4 - val3;
				float num4 = Mathf.Clamp01(Vector2.Dot(val5 - val3, val6) / ((Vector2)(ref val6)).sqrMagnitude);
				float num5 = Vector2.Distance(val5, val3 + val6 * num4) - num2 * 1.5f;
				float num6 = Mathf.Clamp01(0.5f - Mathf.Min(num3, num5));
				val.SetPixel(j, i, Px(new Color(col.r, col.g, col.b, num6)));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	public static Texture2D ArrowDown(Color col, int size = 24)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_0066: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				float num = (float)j + 0.5f;
				float num2 = (float)i + 0.5f;
				float num3 = num2 * 0.5f;
				float num4 = Mathf.Abs(num - (float)size / 2f) - num3;
				float num5 = Mathf.Clamp01(0.5f - num4);
				if (num2 > (float)size - 2f)
				{
					num5 = 0f;
				}
				val.SetPixel(j, i, Px(new Color(col.r, col.g, col.b, num5)));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	public static Texture2D Disc(int size = 48)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		float num = (float)(size - 1) / 2f;
		float num2 = (float)size / 2f - 1f;
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				float num3 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num));
				float num4 = Mathf.Clamp01(num2 - num3 + 0.5f);
				float num5 = Mathf.Clamp01(1f - Mathf.Abs(num3 - (num2 - 2.5f)) / 2f);
				float num6 = Mathf.Lerp(0.78f, 1f, num5);
				val.SetPixel(j, i, Px(new Color(num6, num6, num6, num4)));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	public static Texture2D Check(Color col, int size = 32)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//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_007f: 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_0087: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		Vector2 a = default(Vector2);
		((Vector2)(ref a))..ctor((float)size * 0.18f, (float)size * 0.52f);
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor((float)size * 0.42f, (float)size * 0.24f);
		Vector2 b = default(Vector2);
		((Vector2)(ref b))..ctor((float)size * 0.84f, (float)size * 0.8f);
		float num = (float)size * 0.09f;
		Vector2 p = default(Vector2);
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				((Vector2)(ref p))..ctor((float)j + 0.5f, (float)i + 0.5f);
				float num2 = Mathf.Min(SegDist(p, a, val2), SegDist(p, val2, b)) - num;
				val.SetPixel(j, i, Px(new Color(col.r, col.g, col.b, Mathf.Clamp01(0.5f - num2))));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	private static float SegDist(Vector2 p, Vector2 a, Vector2 b)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: 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)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = b - a;
		float num = Mathf.Clamp01(Vector2.Dot(p - a, val) / ((Vector2)(ref val)).sqrMagnitude);
		return Vector2.Distance(p, a + val * num);
	}

	public static Texture2D RectGlow(Color col, int pad = 12)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_00db: 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)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		int num = pad * 2 + 4;
		Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num2 = Mathf.Max(new float[3]
				{
					(float)pad - ((float)j + 0.5f),
					(float)j + 0.5f - (float)(num - pad),
					0f
				});
				float num3 = Mathf.Max(new float[3]
				{
					(float)pad - ((float)i + 0.5f),
					(float)i + 0.5f - (float)(num - pad),
					0f
				});
				float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3) / (float)pad;
				float num5 = (((float)j + 0.5f > (float)pad && (float)j + 0.5f < (float)(num - pad) && (float)i + 0.5f > (float)pad && (float)i + 0.5f < (float)(num - pad)) ? 0f : Mathf.Clamp01(1f - num4));
				val.SetPixel(j, i, Px(new Color(col.r, col.g, col.b, num5 * num5 * col.a)));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	public static Texture2D Star(bool filled, int size = 32)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		return Star(filled, new Color(1f, 0.78f, 0.2f, 1f), new Color(1f, 0.95f, 0.6f, 1f), new Color(0.25f, 0.13f, 0.04f, 1f), size);
	}

	public static Texture2D SilverStar(int size = 32)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		return Star(filled: true, new Color(0.72f, 0.74f, 0.78f, 1f), new Color(0.97f, 0.98f, 1f, 1f), new Color(0.15f, 0.15f, 0.18f, 1f), size);
	}

	public static Texture2D Glow(int size = 64)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		float num = (float)(size - 1) / 2f;
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				float num2 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num)) / ((float)size / 2f);
				float num3 = Mathf.Clamp01(1f - num2);
				num3 = num3 * num3 * 0.9f;
				val.SetPixel(j, i, Px(new Color(1f, 0.8f, 0.25f, num3)));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	private static Texture2D Star(bool filled, Color main, Color light, Color edgeCol, int size)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		Vector2[] array = (Vector2[])(object)new Vector2[10];
		float num = (float)size / 2f;
		float num2 = (float)size * 0.48f;
		float num3 = num2 * 0.45f;
		for (int i = 0; i < 10; i++)
		{
			float num4 = (float)Math.PI / 2f + (float)i * (float)Math.PI / 5f;
			float num5 = ((i % 2 == 0) ? num2 : num3);
			array[i] = new Vector2(num + Mathf.Cos(num4) * num5, num + Mathf.Sin(num4) * num5);
		}
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0.75f, 0.62f, 0.45f, 0.75f);
		for (int j = 0; j < size; j++)
		{
			for (int k = 0; k < size; k++)
			{
				Vector2 p = new Vector2((float)k + 0.5f, (float)j + 0.5f);
				bool flag = Inside(p, array);
				float num6 = DistToEdges(p, array);
				Color c = Color.clear;
				if (filled)
				{
					if (flag)
					{
						c = ((num6 < 1.6f) ? edgeCol : Color.Lerp(main, light, (float)j / (float)size * 0.45f));
					}
				}
				else if (num6 < 1.4f)
				{
					c = val2;
				}
				val.SetPixel(k, j, Px(c));
			}
		}
		val.Apply();
		((Texture)val).filterMode = (FilterMode)1;
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	private static bool Inside(Vector2 p, Vector2[] poly)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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)
		bool flag = false;
		int num = 0;
		int num2 = poly.Length - 1;
		while (num < poly.Length)
		{
			if (poly[num].y > p.y != poly[num2].y > p.y && p.x < (poly[num2].x - poly[num].x) * (p.y - poly[num].y) / (poly[num2].y - poly[num].y) + poly[num].x)
			{
				flag = !flag;
			}
			num2 = num++;
		}
		return flag;
	}

	private static float DistToEdges(Vector2 p, Vector2[] poly)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		float num = float.MaxValue;
		int num2 = 0;
		int num3 = poly.Length - 1;
		while (num2 < poly.Length)
		{
			Vector2 val = poly[num3];
			Vector2 val2 = poly[num2] - val;
			float num4 = Mathf.Clamp01(Vector2.Dot(p - val, val2) / ((Vector2)(ref val2)).sqrMagnitude);
			num = Mathf.Min(num, Vector2.Distance(p, val + val2 * num4));
			num3 = num2++;
		}
		return num;
	}
}
public static class Biomes
{
	public struct Entry
	{
		public string Code;

		public string Display;

		public Entry(string code, string display)
		{
			Code = code;
			Display = display;
		}
	}

	public static readonly Entry[] Order = new Entry[10]
	{
		new Entry("ME", "Meadows"),
		new Entry("BF", "Black Forest"),
		new Entry("SW", "Swamp"),
		new Entry("MO", "Mountain"),
		new Entry("PL", "Plains"),
		new Entry("OC", "Ocean"),
		new Entry("MI", "Mistlands"),
		new Entry("AL", "Ashlands"),
		new Entry("DN", "Deep North"),
		new Entry("XX", "Other")
	};

	private static readonly Dictionary<string, string> ByEnumName = new Dictionary<string, string>
	{
		{ "Meadows", "ME" },
		{ "BlackForest", "BF" },
		{ "Swamp", "SW" },
		{ "Mountain", "MO" },
		{ "Plains", "PL" },
		{ "Ocean", "OC" },
		{ "Mistlands", "MI" },
		{ "AshLands", "AL" },
		{ "DeepNorth", "DN" }
	};

	public unsafe static string CodeAt(Vector3 position)
	{
		//IL_0012: 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_0018: Unknown result type (might be due to invalid IL or missing references)
		if (WorldGenerator.instance == null)
		{
			return "XX";
		}
		Biome biome = WorldGenerator.instance.GetBiome(position);
		if (!ByEnumName.TryGetValue(((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString(), out var value))
		{
			return "XX";
		}
		return value;
	}

	public static int SortIndex(string code)
	{
		for (int i = 0; i < Order.Length; i++)
		{
			if (Order[i].Code == code)
			{
				return i;
			}
		}
		return Order.Length;
	}
}
public static class Categories
{
	public static readonly string[] Keys = new string[9] { "none", "base", "mine", "farm", "trader", "boss", "danger", "dungeon", "explore" };

	public static readonly string[] Names = new string[9] { "None", "Base", "Mine", "Farm", "Trader", "Boss", "Danger", "Dungeon", "Explore" };

	public const int Count = 9;

	public static int Clamp(int c)
	{
		if (c >= 0 && c < 9)
		{
			return c;
		}
		return 0;
	}
}
public static class FlowLine
{
	private delegate void WorldToMapPointFn(Minimap m, Vector3 p, ref float mx, ref float my);

	private static readonly WorldToMapPointFn WorldToMapPoint = AccessTools.MethodDelegate<WorldToMapPointFn>(AccessTools.Method(typeof(Minimap), "WorldToMapPoint", (Type[])null, (Type[])null), (object)null, true);

	private static readonly Func<Minimap, float, float, RawImage, Vector2> MapPointToLocalGuiPos = AccessTools.MethodDelegate<Func<Minimap, float, float, RawImage, Vector2>>(AccessTools.Method(typeof(Minimap), "MapPointToLocalGuiPos", new Type[3]
	{
		typeof(float),
		typeof(float),
		typeof(RawImage)
	}, (Type[])null), (object)null, true);

	private static RectTransform _root;

	private static readonly List<Image> Glow = new List<Image>();

	private static readonly List<Image> Core = new List<Image>();

	private static Sprite _dot;

	private static Vector2 _dotAnchor;

	private const float Spacing = 4f;

	private const int MaxDots = 400;

	private static Color Fire(float t)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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)
		Color val = default(Color);
		((Color)(ref val))..ctor(0.92f, 0.29f, 0.08f);
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(1f, 0.47f, 0.08f);
		Color val3 = default(Color);
		((Color)(ref val3))..ctor(1f, 0.84f, 0.35f);
		if (!(t < 0.5f))
		{
			return Color.Lerp(val2, val3, (t - 0.5f) * 2f);
		}
		return Color.Lerp(val, val2, t * 2f);
	}

	public static void Show(Minimap map, Vector3 fromWorld, Vector3 toWorld)
	{
		//IL_004f: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: 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_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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_00d7: 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)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: 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_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)map == (Object)null || (Object)(object)map.m_pinRootLarge == (Object)null || (Object)(object)map.m_mapImageLarge == (Object)null)
		{
			Hide();
			return;
		}
		EnsureRoot(map);
		float mx = 0f;
		float my = 0f;
		float mx2 = 0f;
		float my2 = 0f;
		WorldToMapPoint(map, fromWorld, ref mx, ref my);
		WorldToMapPoint(map, toWorld, ref mx2, ref my2);
		Vector2 val = MapPointToLocalGuiPos(map, mx, my, map.m_mapImageLarge);
		Vector2 val2 = MapPointToLocalGuiPos(map, mx2, my2, map.m_mapImageLarge);
		Vector2 val3 = val2 - val;
		float magnitude = ((Vector2)(ref val3)).magnitude;
		if (magnitude < 8f)
		{
			Hide();
			return;
		}
		Vector2 val4 = new Vector2(0f - val3.y, val3.x) / magnitude;
		Vector2 val5 = (val + val2) * 0.5f + val4 * magnitude * 0.18f;
		int num = Mathf.Clamp(Mathf.CeilToInt(magnitude * 1.15f / 4f), 6, 400);
		EnsureDots(num);
		float num2 = Mathf.Clamp(((map.m_pinSizeLarge > 0f) ? map.m_pinSizeLarge : 32f) * 0.22f, 5f, 12f);
		float unscaledTime = Time.unscaledTime;
		for (int i = 0; i < Core.Count; i++)
		{
			bool flag = i < num;
			((Behaviour)Core[i]).enabled = flag;
			((Behaviour)Glow[i]).enabled = flag && i % 2 == 0;
			if (flag)
			{
				float num3 = (float)i / (float)(num - 1);
				float num4 = 1f - num3;
				Vector2 anchoredPosition = num4 * num4 * val + 2f * num4 * num3 * val5 + num3 * num3 * val2;
				float num5 = 0.5f + 0.5f * Mathf.Sin((num3 * 7f - unscaledTime * 1.6f) * (float)Math.PI * 2f);
				float num6 = Mathf.Clamp01(num3 / 0.06f) * Mathf.Clamp01((1f - num3) / 0.06f);
				Color val6 = Fire(num3);
				RectTransform rectTransform = ((Graphic)Core[i]).rectTransform;
				rectTransform.anchoredPosition = anchoredPosition;
				float num7 = num2 * (0.85f + 0.45f * num5);
				rectTransform.sizeDelta = new Vector2(num7, num7);
				((Graphic)Core[i]).color = new Color(val6.r, val6.g, val6.b, (0.35f + 0.5f * num5) * num6);
				if (((Behaviour)Glow[i]).enabled)
				{
					RectTransform rectTransform2 = ((Graphic)Glow[i]).rectTransform;
					rectTransform2.anchoredPosition = anchoredPosition;
					float num8 = num2 * 3.2f;
					rectTransform2.sizeDelta = new Vector2(num8, num8);
					((Graphic)Glow[i]).color = new Color(val6.r, val6.g, val6.b, 0.1f * num6);
				}
			}
		}
		((Component)_root).gameObject.SetActive(true);
		((Transform)_root).SetAsFirstSibling();
		PortalClient.SetOnTop(((Component)_root).gameObject, 5);
	}

	public static void Prewarm(Minimap map)
	{
		if ((Object)(object)map == (Object)null || (Object)(object)map.m_pinRootLarge == (Object)null)
		{
			return;
		}
		EnsureRoot(map);
		EnsureDots(400);
		foreach (Image item in Core)
		{
			((Behaviour)item).enabled = false;
		}
		foreach (Image item2 in Glow)
		{
			((Behaviour)item2).enabled = false;
		}
		((Component)_root).gameObject.SetActive(false);
	}

	public static void Hide()
	{
		if ((Object)(object)_root != (Object)null && ((Component)_root).gameObject.activeSelf)
		{
			((Component)_root).gameObject.SetActive(false);
		}
	}

	private static void EnsureRoot(Minimap map)
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_root != (Object)null && (Object)(object)((Transform)_root).parent == (Object)(object)map.m_pinRootLarge)
		{
			return;
		}
		if ((Object)(object)_root != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_root).gameObject);
		}
		Glow.Clear();
		Core.Clear();
		_root = (RectTransform)new GameObject("PortalerFlowLine", new Type[1] { typeof(RectTransform) }).transform;
		((Transform)_root).SetParent((Transform)(object)map.m_pinRootLarge, false);
		_root.anchorMin = Vector2.zero;
		_root.anchorMax = Vector2.one;
		RectTransform root = _root;
		Vector2 offsetMin = (_root.offsetMax = Vector2.zero);
		root.offsetMin = offsetMin;
		_dotAnchor = Vector2.zero;
		if ((Object)(object)map.m_pinPrefab != (Object)null)
		{
			RectTransform component = map.m_pinPrefab.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				_dotAnchor = component.anchorMin;
			}
		}
		if ((Object)(object)_dot == (Object)null)
		{
			_dot = Art.SoftDot();
		}
	}

	private static void EnsureDots(int n)
	{
		while (Core.Count < n)
		{
			Glow.Add(NewDot("g"));
			Core.Add(NewDot("c"));
		}
	}

	private static Image NewDot(string name)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name, new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		RectTransform val2 = (RectTransform)val.transform;
		((Transform)val2).SetParent((Transform)(object)_root, false);
		Vector2 anchorMin = (val2.anchorMax = _dotAnchor);
		val2.anchorMin = anchorMin;
		Image component = val.GetComponent<Image>();
		component.sprite = _dot;
		((Graphic)component).raycastTarget = false;
		return component;
	}
}
internal static class Patches
{
	[HarmonyPatch(typeof(Game), "Start")]
	private static class Game_Start
	{
		private static void Postfix()
		{
			PortalServer.Register();
			PortalClient.Register();
		}
	}

	[HarmonyPatch(typeof(Player), "OnSpawned")]
	private static class Player_OnSpawned
	{
		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				PortalClient.RequestList();
			}
		}
	}

	[HarmonyPatch(typeof(TeleportWorldTrigger), "OnTriggerEnter")]
	private static class TeleportWorldTrigger_OnTriggerEnter
	{
		private static bool Prefix(TeleportWorldTrigger __instance, Collider colliderIn)
		{
			Player component = ((Component)colliderIn).GetComponent<Player>();
			if ((Object)(object)component == (Object)null || (Object)(object)component != (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			TeleportWorld componentInParent = ((Component)__instance).GetComponentInParent<TeleportWorld>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				PortalClient.Activate(componentInParent);
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(TeleportWorld), "HaveTarget")]
	private static class TeleportWorld_HaveTarget
	{
		private static void Postfix(ref bool __result)
		{
			__result = true;
		}
	}

	[HarmonyPatch(typeof(TeleportWorld), "TargetFound")]
	private static class TeleportWorld_TargetFound
	{
		private static void Postfix(ref bool __result)
		{
			__result = true;
		}
	}

	[HarmonyPatch(typeof(Game), "ConnectPortals")]
	private static class Game_ConnectPortals
	{
		private static bool Prefix()
		{
			return false;
		}
	}

	[HarmonyPatch(typeof(ZDOMan), "ConnectPortals")]
	private static class ZDOMan_ConnectPortals
	{
		private static bool Prefix()
		{
			return false;
		}
	}

	[HarmonyPatch(typeof(Piece), "SetCreator")]
	private static class Piece_SetCreator
	{
		private static void Postfix(Piece __instance)
		{
			//IL_0047: 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)
			if (!((Object)(object)((Component)__instance).GetComponent<TeleportWorld>() == (Object)null))
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid() && ZRoutedRpc.instance != null)
				{
					ZRoutedRpc.instance.InvokeRoutedRPC("Portaler_NewPortal", new object[2]
					{
						component.GetZDO().m_uid,
						((Component)__instance).transform.position
					});
				}
			}
		}
	}

	[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
	private static class Minimap_OnMapLeftClick
	{
		private static readonly Func<Minimap, Vector3, Vector3> ScreenToWorld = AccessTools.MethodDelegate<Func<Minimap, Vector3, Vector3>>(AccessTools.Method(typeof(Minimap), "ScreenToWorldPoint", (Type[])null, (Type[])null), (object)null, true);

		private static readonly Func<Minimap, float> PinRadius = AccessTools.MethodDelegate<Func<Minimap, float>>(AccessTools.PropertyGetter(typeof(Minimap), "PinInteractRadius"), (object)null, true);

		private static bool Prefix(Minimap __instance)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!PortalClient.Active)
			{
				return true;
			}
			if (PortalUI.MouseOverList)
			{
				return false;
			}
			PortalClient.TryTeleportAtMapPoint(ScreenToWorld(__instance, ZInput.pointerPosition), PinRadius(__instance) * 1.5f);
			return false;
		}
	}

	[HarmonyPatch(typeof(Minimap), "OnMapDblClick")]
	private static class Minimap_OnMapDblClick
	{
		private static bool Prefix()
		{
			return !PortalClient.Active;
		}
	}

	[HarmonyPatch(typeof(Minimap), "OnMapMiddleClick")]
	private static class Minimap_OnMapMiddleClick
	{
		private static bool Prefix()
		{
			return !PortalClient.Active;
		}
	}

	[HarmonyPatch(typeof(Minimap), "UpdateMap")]
	private static class Minimap_UpdateMap
	{
		private static void Prefix(ref bool takeInput)
		{
			if (PortalClient.Active && PortalUI.ListHasMouse)
			{
				takeInput = false;
			}
		}
	}

	[HarmonyPatch(typeof(Minimap), "OnMapLeftDown")]
	private static class Minimap_OnMapLeftDown
	{
		private static bool Prefix()
		{
			if (PortalClient.Active)
			{
				return !PortalUI.ListHasMouse;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Minimap), "UpdatePins")]
	private static class Minimap_UpdatePins
	{
		private static void Postfix()
		{
			Perf.Token t = Perf.Begin();
			PortalClient.HideForeignPins();
			Perf.End(Perf.S.Hide, t);
		}
	}

	[HarmonyPatch(typeof(Minimap), "InTextInput")]
	private static class Minimap_InTextInput
	{
		private static void Postfix(ref bool __result)
		{
			if (PortalClient.Active && PortalUI.BlocksKeys)
			{
				__result = true;
			}
		}
	}
}
public static class Perf
{
	public enum S
	{
		ServerTick,
		ClientTick,
		PinScan,
		PinRefresh,
		Hide,
		Scale,
		Gui,
		Line,
		Travel,
		MapClose,
		TpStart,
		Count
	}

	public struct Token
	{
		public long T;

		public long M;

		public bool Valid;
	}

	private static readonly string[] Names = new string[11]
	{
		"srvTick", "cliTick", "pinScan", "pinRefresh", "hide", "scale", "gui", "line", "click", "mapClose",
		"tpStart"
	};

	private const float Interval = 10f;

	public const bool DevBuild = false;

	private static readonly double[] FrameMs = new double[11];

	private static long _frameAlloc;

	private static int _guiCalls;

	private static int _frame = -1;

	private static readonly double[] SumMs = new double[11];

	private static readonly double[] MaxMs = new double[11];

	private static readonly int[] Hits = new int[11];

	private static double _sumTotal;

	private static double _maxTotal;

	private static double _sumFrame;

	private static double _maxFrame;

	private static long _sumAlloc;

	private static long _maxAlloc;

	private static int _frames;

	private static int _framesOpen;

	private static int _sumGuiCalls;

	private static float _since;

	private static readonly double MsPerTick = 1000.0 / (double)Stopwatch.Frequency;

	private static readonly FieldRef<Minimap, List<PinData>> PinsRef = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins");

	private static bool _tracking;

	private static float _tpStart;

	private static float _tpMoved;

	private static float _tpReady;

	private static Vector3 _tpTarget;

	private static string _tpName;

	private static float _tpDistance;

	private static float _tpWorstFrame;

	public static bool On
	{
		get
		{
			if (Plugin.PerfLog != null)
			{
				return Plugin.PerfLog.Value;
			}
			return false;
		}
	}

	private static bool Nested(int i)
	{
		if (i != 2 && i != 3 && i != 7 && i != 8 && i != 9)
		{
			return i == 10;
		}
		return true;
	}

	public static Token Begin()
	{
		if (!On)
		{
			return default(Token);
		}
		return new Token
		{
			T = Stopwatch.GetTimestamp(),
			M = Profiler.GetMonoUsedSizeLong(),
			Valid = true
		};
	}

	public static void End(S s, Token t)
	{
		if (t.Valid)
		{
			double num = (double)(Stopwatch.GetTimestamp() - t.T) * MsPerTick;
			long num2 = Profiler.GetMonoUsedSizeLong() - t.M;
			NewFrameIfNeeded();
			FrameMs[(int)s] += num;
			Hits[(int)s]++;
			if (num2 > 0)
			{
				_frameAlloc += num2;
			}
			if (s == S.Gui)
			{
				_guiCalls++;
			}
		}
	}

	public static void Tick()
	{
		if (!On)
		{
			_frame = -1;
			return;
		}
		NewFrameIfNeeded();
		_since += Time.unscaledDeltaTime;
		if (!(_since < 10f) && _frames != 0)
		{
			Report();
		}
	}

	private static void NewFrameIfNeeded()
	{
		int frameCount = Time.frameCount;
		if (frameCount != _frame)
		{
			if (_frame >= 0)
			{
				CloseFrame();
			}
			_frame = frameCount;
		}
	}

	private static void CloseFrame()
	{
		double num = 0.0;
		for (int i = 0; i < FrameMs.Length; i++)
		{
			if (!Nested(i))
			{
				num += FrameMs[i];
			}
			SumMs[i] += FrameMs[i];
			if (FrameMs[i] > MaxMs[i])
			{
				MaxMs[i] = FrameMs[i];
			}
			FrameMs[i] = 0.0;
		}
		_sumTotal += num;
		if (num > _maxTotal)
		{
			_maxTotal = num;
		}
		double num2 = (double)Time.unscaledDeltaTime * 1000.0;
		_sumFrame += num2;
		if (num2 > _maxFrame)
		{
			_maxFrame = num2;
		}
		_sumAlloc += _frameAlloc;
		if (_frameAlloc > _maxAlloc)
		{
			_maxAlloc = _frameAlloc;
		}
		_frameAlloc = 0L;
		_sumGuiCalls += _guiCalls;
		_guiCalls = 0;
		_frames++;
		if (PortalClient.Active)
		{
			_framesOpen++;
		}
	}

	private static void Report()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append($"[Perf] {_since:0}s, {_frames} frames (game frame avg {_sumFrame / (double)_frames:0.0} ms, max {_maxFrame:0} ms), list open {100 * _framesOpen / _frames}%");
		stringBuilder.Append($" | Portaler avg {_sumTotal / (double)_frames:0.000} ms, max {_maxTotal:0.00} ms per frame");
		stringBuilder.Append($" | alloc avg {(double)(_sumAlloc / _frames) / 1024.0:0.0} KB, max {(double)_maxAlloc / 1024.0:0} KB per frame");
		if (_framesOpen > 0)
		{
			stringBuilder.Append($" | OnGUI calls {(double)_sumGuiCalls / (double)_frames:0.0}/frame");
		}
		stringBuilder.Append(" | ms avg/max per frame (* = part of cliTick or gui):");
		for (int i = 0; i < Names.Length; i++)
		{
			if (Hits[i] > 0)
			{
				stringBuilder.Append(string.Format(" {0}{1} {2:0.000}/{3:0.00}", Names[i], Nested(i) ? "*" : "", SumMs[i] / (double)_frames, MaxMs[i]));
			}
		}
		int num = 0;
		try
		{
			if ((Object)(object)Minimap.instance != (Object)null)
			{
				num = PinCount();
			}
		}
		catch
		{
		}
		stringBuilder.Append($" | map pins {num}, portals {PortalClient.Portals.Count}");
		Plugin.Log.LogInfo((object)stringBuilder.ToString());
		for (int j = 0; j < SumMs.Length; j++)
		{
			SumMs[j] = 0.0;
			MaxMs[j] = 0.0;
			Hits[j] = 0;
		}
		_sumTotal = (_maxTotal = (_sumFrame = (_maxFrame = 0.0)));
		_sumAlloc = (_maxAlloc = 0L);
		_frames = (_framesOpen = (_sumGuiCalls = 0));
		_since = 0f;
	}

	private static int PinCount()
	{
		return PinsRef.Invoke(Minimap.instance)?.Count ?? 0;
	}

	public static void TeleportStarted(PortalInfo target, Vector3 exit, float distance)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		if (On)
		{
			_tracking = true;
			_tpStart = Time.realtimeSinceStartup;
			_tpMoved = (_tpReady = -1f);
			_tpTarget = exit;
			_tpName = target.DisplayName;
			_tpDistance = distance;
			_tpWorstFrame = 0f;
		}
	}

	public static void TeleportTick()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		if (!_tracking)
		{
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			_tracking = false;
			return;
		}
		float num = Time.realtimeSinceStartup - _tpStart;
		_tpWorstFrame = Mathf.Max(_tpWorstFrame, Time.unscaledDeltaTime);
		if (_tpMoved < 0f && Utils.DistanceXZ(((Component)localPlayer).transform.position, _tpTarget) < 10f)
		{
			_tpMoved = num;
		}
		if (_tpReady < 0f && _tpMoved >= 0f && (Object)(object)ZNetScene.instance != (Object)null && ZNetScene.instance.IsAreaReady(_tpTarget))
		{
			_tpReady = num;
		}
		if (!((Character)localPlayer).IsTeleporting() && num > 0.5f)
		{
			_tracking = false;
			string arg = ((_tpMoved >= 0f) ? $"{_tpMoved:0.0} s" : "?");
			string arg2 = ((_tpReady >= 0f) ? $"{_tpReady:0.0} s" : "?");
			Plugin.Log.LogInfo((object)($"[Perf] Teleport to '{_tpName}' ({_tpDistance / 1000f:0.0} km): moved after {arg}, " + $"area ready after {arg2}, arrived after {num:0.0} s (worst frame {_tpWorstFrame * 1000f:0} ms, " + "quick arrival " + (QuickArrival.Enabled ? "on" : "off") + ")"));
		}
		else if (num > 60f)
		{
			_tracking = false;
			Plugin.Log.LogWarning((object)("[Perf] Teleport to '" + _tpName + "' still running after 60 s"));
		}
	}
}
[BepInPlugin("nfp007.Portaler", "Portaler", "1.0.13")]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "nfp007.Portaler";

	public const string Name = "Portaler";

	public const string Version = "1.0.13";

	internal static Plugin Instance;

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> VanillaRestrictions;

	internal static ConfigEntry<KeyCode> RenameKey;

	internal static ConfigEntry<KeyCode> CategoryKey;

	internal static ConfigEntry<bool> HoverShowsMap;

	internal static ConfigEntry<bool> HoverReturn;

	internal static ConfigEntry<bool> HoverLine;

	internal static ConfigEntry<bool> PerfLog;

	internal static ConfigEntry<bool> QuickArrival;

	internal static ConfigEntry<float> HoverDelay;

	internal static ConfigEntry<float> HoverZoomMeters;

	internal static ConfigEntry<float> HoverReturnDelay;

	internal static ConfigEntry<float> PinSizePreview;

	internal static ConfigEntry<float> PinSizeHover;

	internal static ConfigEntry<float> HoverMaxFitMeters;

	internal static ConfigEntry<float> HoverMoveSeconds;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		VanillaRestrictions = ((BaseUnityPlugin)this).Config.Bind<bool>("Server", "VanillaRestrictions", false, "false = no restrictions: everything can travel through every portal (default).\ntrue = the game's own rules: no metals/ores etc. through the wooden portal, and the world modifiers 'no portals' / 'no portals during boss fights' apply.\nOnly the server's (or the host's) value counts; it is sent to all players.");
		RenameKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "RenameKey", (KeyCode)101, "Hover a name in the list and press this key to rename the portal.");
		CategoryKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "CategoryKey", (KeyCode)116, "Hover a name in the list and press this key to choose the portal's category.");
		HoverShowsMap = ((BaseUnityPlugin)this).Config.Bind<bool>("Map", "HoverShowsMap", true, "Hovering a name in the list moves the map to that portal.");
		HoverDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Map", "HoverDelay", 0.4f, "Seconds the mouse must rest on a name before the map moves.");
		HoverZoomMeters = ((BaseUnityPlugin)this).Config.Bind<float>("Map", "HoverZoomMeters", 1500f, "For far targets: how much of the world the map shows around the target portal (metres).");
		HoverReturn = ((BaseUnityPlugin)this).Config.Bind<bool>("Map", "HoverReturn", true, "When the mouse leaves the list, the map glides back to where it was (unless you move or zoom the map yourself).");
		HoverReturnDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Map", "HoverStaySeconds", 10f, "Seconds the map stays on the preview after the mouse leaves the list, before it glides back.");
		HoverMaxFitMeters = ((BaseUnityPlugin)this).Config.Bind<float>("Map", "HoverMaxFitMeters", 2000f, "Portals closer than this (metres) are shown together: the map frames both. Farther targets are shown directly, without gliding across the map.");
		HoverMoveSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Map", "HoverMoveSeconds", 1f, "How long the calm glide to a preview (and back) takes, in seconds.");
		PinSizePreview = ((BaseUnityPlugin)this).Config.Bind<float>("Map", "PinSizePreview", 1.6f, "Size of the previewed portal's pin on the map (1 = normal). It stays this big as long as the fiery line is shown.");
		PinSizeHover = ((BaseUnityPlugin)this).Config.Bind<float>("Map", "PinSizeHover", 1.3f, "Size of a portal pin while the mouse is over it on the map (1 = normal).");
		HoverLine = ((BaseUnityPlugin)this).Config.Bind<bool>("Map", "HoverLine", true, "Draw a fiery line from the portal you stand in to the previewed portal.");
		QuickArrival = ((BaseUnityPlugin)this).Config.Bind<bool>("Travel", "QuickArrival", true, "Shorter waits for trips through Portaler: you are moved as soon as the screen is dark and arrive as soon as the target area is loaded, instead of the game's fixed 2 s + at least 8 s. You still never arrive before the area is ready. Switched off automatically when Fast Teleport is installed.");
		PerfLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "PerfLog", false, "Write Portaler's own time and memory use per frame, and how long each teleport takes, to the BepInEx log every 10 seconds.");
		_harmony = new Harmony("nfp007.Portaler");
		_harmony.PatchAll(typeof(Plugin).Assembly);
		Log.LogInfo((object)"Portaler 1.0.13 loaded");
	}

	private void Update()
	{
		try
		{
			Perf.Token t = Perf.Begin();
			PortalServer.Tick();
			Perf.End(Perf.S.ServerTick, t);
			t = Perf.Begin();
			PortalClient.Tick();
			Perf.End(Perf.S.ClientTick, t);
		}
		catch (Exception ex)
		{
			Log.LogError((object)ex);
		}
	}

	private void LateUpdate()
	{
		try
		{
			Perf.Token t = Perf.Begin();
			PortalClient.HideForeignPins();
			Perf.End(Perf.S.Hide, t);
			t = Perf.Begin();
			PortalClient.ScalePins();
			Perf.End(Perf.S.Scale, t);
			Perf.TeleportTick();
			Perf.Tick();
		}
		catch (Exception ex)
		{
			Log.LogError((object)ex);
		}
	}

	private void OnGUI()
	{
		try
		{
			Perf.Token t = Perf.Begin();
			PortalUI.Draw();
			Perf.End(Perf.S.Gui, t);
		}
		catch (Exception ex)
		{
			Log.LogError((object)ex);
		}
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
public static class PortalClient
{
	public enum FavState
	{
		None,
		Personal,
		Shared
	}

	public class TripInfo
	{
		public long PlayerId;

		public string Name;

		public ZDOID PortalId;

		public long AgeAtReceive;

		public float ReceivedAt;

		public float AgeSeconds => (float)AgeAtReceive + (Time.realtimeSinceStartup - ReceivedAt);
	}

	private class RenameReceiver : TextReceiver
	{
		private readonly PortalInfo _portal;

		public RenameReceiver(PortalInfo p)
		{
			_portal = p;
		}

		public string GetText()
		{
			return _portal.Name ?? "";
		}

		public void SetText(string text)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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)
			text = (text ?? "").Trim();
			if (text.Length > 25)
			{
				text = text.Substring(0, 25);
			}
			if (text == (_portal.Name ?? "") || ZRoutedRpc.instance == null)
			{
				return;
			}
			string text2 = "";
			try
			{
				text2 = ((object)((IUser)PlatformManager.DistributionPlatform.LocalUser).PlatformUserID/*cast due to .constrained prefix*/).ToString();
			}
			catch
			{
			}
			ZRoutedRpc.instance.InvokeRoutedRPC("Portaler_Rename", new object[3] { _portal.Id, text, text2 });
			foreach (PortalInfo portal in Portals)
			{
				if (portal.Id == _portal.Id)
				{
					portal.Name = text;
				}
			}
			_pinsDirty = true;
		}
	}

	public const string RpcList = "Portaler_List";

	public const string RpcFavs = "Portaler_Favs";

	public const string RpcShared = "Portaler_Shared";

	public const string RpcSettings = "Portaler_Settings";

	public const string RpcTrips = "Portaler_Trips";

	private static bool? _serverRestrictions;

	private static bool _sourceAllowAllItems = true;

	public static List<PortalInfo> Portals = new List<PortalInfo>();

	public static HashSet<ZDOID> Favorites = new HashSet<ZDOID>();

	public static HashSet<ZDOID> SharedFavorites = new HashSet<ZDOID>();

	private static Transform _sourceTransform;

	private static Vector3 _sourcePos;

	private static float _exitDistance = 1f;

	private static float _activatedAt;

	private const float LeaveDistance = 4f;

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

	private static bool _pinsDirty;

	private static Sprite _pinSprite;

	private static readonly HashSet<Sprite> OurSprites = new HashSet<Sprite>();

	private static float _nextForeignScan;

	private const float ForeignPinRadius = 4f;

	private static readonly AccessTools_FieldRef PinsField = new AccessTools_FieldRef();

	public static List<ZDOID> FavOrder = new List<ZDOID>();

	public static List<TripInfo> Trips = new List<TripInfo>();

	public const int MaxNameLength = 25;

	private static PortalInfo _renamePending;

	private static int _focusFrames;

	private static readonly FieldInfo InputFieldInfo = AccessTools.Field(typeof(TextInput), "m_inputField");

	private static readonly FieldRef<Minimap, Vector3> MapOffset = AccessTools.FieldRefAccess<Minimap, Vector3>("m_mapOffset");

	private static PortalInfo _hoverPortal;

	private static float _hoverSince;

	private static float _leftListAt;

	private static ZDOID _glowId = ZDOID.None;

	private static Canvas _mapCanvas;

	private static readonly Dictionary<PinData, float> PinScale = new Dictionary<PinData, float>();

	private static bool _saved;

	private static bool _returning;

	private static Vector3 _savedOffset;

	private static Vector3 _targetOffset;

	private static float _savedZoom;

	private static float _targetZoom;

	private static bool _moving;

	private static Vector3 _fromOffset;

	private static float _fromZoom;

	private static float _moveStart;

	private static float _moveTime;

	private static Vector3 _lastOffset;

	private static float _lastZoom;

	private static readonly List<PinData> HiddenForeign = new List<PinData>();

	public static bool Restricted => _serverRestrictions ?? Plugin.VanillaRestrictions.Value;

	public static bool Active { get; private set; }

	public static ZDOID SourceId { get; private set; } = ZDOID.None;

	public static Vector3 SourcePosition
	{
		get
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_sourceTransform != (Object)null))
			{
				return _sourcePos;
			}
			return _sourceTransform.position;
		}
	}

	public static int DataVersion { get; private set; }

	private static long LocalPlayerId
	{
		get
		{
			if (!((Object)(object)Player.m_localPlayer != (Object)null))
			{
				return 0L;
			}
			return Player.m_localPlayer.GetPlayerID();
		}
	}

	private static string LocalPlayerName
	{
		get
		{
			if (!((Object)(object)Player.m_localPlayer != (Object)null))
			{
				return "";
			}
			return Player.m_localPlayer.GetPlayerName();
		}
	}

	public static List<PortalInfo> BackPortals
	{
		get
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			List<PortalInfo> list = new List<PortalInfo>();
			foreach (Vector3 back in Prefs.GetBackList())
			{
				PortalInfo portalInfo = null;
				float num = 1.5f;
				foreach (PortalInfo portal in Portals)
				{
					float num2 = Utils.DistanceXZ(portal.Position, back);
					if (num2 < num && Mathf.Abs(portal.Position.y - back.y) < 3f)
					{
						num = num2;
						portalInfo = portal;
					}
				}
				if (portalInfo != null && portalInfo.Id != SourceId && !list.Contains(portalInfo))
				{
					list.Add(portalInfo);
				}
			}
			return list.Take(Prefs.BackCount).ToList();
		}
	}

	public static IEnumerable<PortalInfo> Destinations => Portals.Where((PortalInfo p) => p.Id != SourceId);

	public static List<PortalInfo> LastBuilt => (from p in Portals
		where p.BuiltAt > 0
		orderby p.BuiltAt descending
		select p).Take(Prefs.LastBuiltCount).ToList();

	public static void Register()
	{
		ZRoutedRpc.instance.Register<ZPackage>("Portaler_List", (Action<long, ZPackage>)OnList);
		ZRoutedRpc.instance.Register<ZPackage>("Portaler_Favs", (Action<long, ZPackage>)OnFavs);
		ZRoutedRpc.instance.Register<ZPackage>("Portaler_Shared", (Action<long, ZPackage>)OnShared);
		ZRoutedRpc.instance.Register<bool>("Portaler_Settings", (Action<long, bool>)delegate(long sender, bool restricted)
		{
			_serverRestrictions = restricted;
		});
		ZRoutedRpc.instance.Register<ZPackage>("Portaler_Trips", (Action<long, ZPackage>)OnTrips);
		Trips = new List<TripInfo>();
		_serverRestrictions = null;
		Portals = new List<PortalInfo>();
		Favorites = new HashSet<ZDOID>();
		SharedFavorites = new HashSet<ZDOID>();
		Pins.Clear();
		Active = false;
	}

	public static void RequestList()
	{
		if (ZRoutedRpc.instance != null)
		{
			ZRoutedRpc.instance.InvokeRoutedRPC("Portaler_RequestList", Array.Empty<object>());
			if (LocalPlayerId != 0L)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC("Portaler_RequestFavs", new object[1] { LocalPlayerId });
			}
		}
	}

	private static void OnList(long sender, ZPackage pkg)
	{
		Portals = PortalInfo.ReadList(pkg);
		_pinsDirty = true;
		DataVersion++;
	}

	private static void OnFavs(long sender, ZPackage pkg)
	{
		Favorites = ReadIds(pkg);
		SharedFavorites = ReadIds(pkg);
		FavOrder = new List<ZDOID>(ReadIdList(pkg));
		DataVersion++;
	}

	private static List<ZDOID> ReadIdList(ZPackage pkg)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		List<ZDOID> list = new List<ZDOID>();
		if (pkg.GetPos() >= pkg.Size())
		{
			return list;
		}
		int num = pkg.ReadInt();
		for (int i = 0; i < num; i++)
		{
			list.Add(pkg.ReadZDOID());
		}
		return list;
	}

	public static List<PortalInfo> OrderedFavorites(IEnumerable<PortalInfo> from)
	{
		//IL_0039: 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)
		List<PortalInfo> source = from.Where(IsFavorite).ToList();
		Dictionary<ZDOID, int> rank = new Dictionary<ZDOID, int>();
		for (int i = 0; i < FavOrder.Count; i++)
		{
			if (!rank.ContainsKey(FavOrder[i]))
			{
				rank[FavOrder[i]] = i;
			}
		}
		int value;
		return source.OrderBy((PortalInfo p) => (!rank.TryGetValue(p.Id, out value)) ? int.MaxValue : value).ThenBy<PortalInfo, string>((PortalInfo p) => p.DisplayName, StringComparer.OrdinalIgnoreCase).ToList();
	}

	public static void SetFavoriteOrder(List<PortalInfo> ordered)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		FavOrder = ordered.Select((PortalInfo p) => p.Id).ToList();
		DataVersion++;
		if (ZRoutedRpc.instance == null || LocalPlayerId == 0L)
		{
			return;
		}
		ZPackage val = new ZPackage();
		val.Write(FavOrder.Count);
		foreach (ZDOID item in FavOrder)
		{
			val.Write(item);
		}
		ZRoutedRpc.instance.InvokeRoutedRPC("Portaler_SetFavOrder", new object[2] { LocalPlayerId, val });
	}

	public static void SetCategory(PortalInfo p, int category)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		if (p == null || ZRoutedRpc.instance == null)
		{
			return;
		}
		category = Categories.Clamp(category);
		foreach (PortalInfo portal in Portals)
		{
			if (portal.Id == p.Id)
			{
				portal.Category = category;
			}
		}
		p.Category = category;
		_pinsDirty = true;
		DataVersion++;
		ZRoutedRpc.instance.InvokeRoutedRPC("Portaler_SetCategory", new object[2] { p.Id, category });
	}

	private static void OnShared(long sender, ZPackage pkg)
	{
		SharedFavorites = ReadIds(pkg);
		DataVersion++;
	}

	private static void OnTrips(long sender, ZPackage pkg)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		List<TripInfo> list = new List<TripInfo>();
		int num = pkg.ReadInt();
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		for (int i = 0; i < num; i++)
		{
			list.Add(new TripInfo
			{
				PlayerId = pkg.ReadLong(),
				Name = pkg.ReadString(),
				PortalId = pkg.ReadZDOID(),
				AgeAtReceive = pkg.ReadLong(),
				ReceivedAt = realtimeSinceStartup
			});
		}
		Trips = list;
		DataVersion++;
	}

	public static List<KeyValuePair<string, bool>> KnownPlayers()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		HashSet<string> online = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
		try
		{
			if ((Object)(object)ZNet.instance != (Object)null)
			{
				foreach (PlayerInfo player in ZNet.instance.GetPlayerList())
				{
					if (!string.IsNullOrEmpty(player.m_name))
					{
						online.Add(player.m_name);
					}
				}
			}
		}
		catch
		{
		}
		HashSet<string> hashSet = new HashSet<string>(online, StringComparer.OrdinalIgnoreCase);
		foreach (TripInfo trip in Trips)
		{
			if (trip.PlayerId != LocalPlayerId && !string.IsNullOrEmpty(trip.Name))
			{
				hashSet.Add(trip.Name);
			}
		}
		hashSet.Remove(LocalPlayerName);
		return (from x in hashSet.OrderBy<string, string>((string x) => x, StringComparer.OrdinalIgnoreCase)
			select new KeyValuePair<string, bool>(x, online.Contains(x))).ToList();
	}

	public static bool IsTracked(string name)
	{
		return Prefs.GetTracked()?.Contains(name) ?? true;
	}

	public static List<KeyValuePair<TripInfo, PortalInfo>> TrackedTrips()
	{
		List<KeyValuePair<TripInfo, PortalInfo>> list = new List<KeyValuePair<TripInfo, PortalInfo>>();
		foreach (TripInfo t in Trips.OrderBy((TripInfo tripInfo) => tripInfo.AgeSeconds))
		{
			if (t.PlayerId != LocalPlayerId && !string.Equals(t.Name, LocalPlayerName, StringComparison.OrdinalIgnoreCase) && IsTracked(t.Name))
			{
				PortalInfo portalInfo = Portals.FirstOrDefault((PortalInfo x) => x.Id == t.PortalId);
				if (portalInfo != null)
				{
					list.Add(new KeyValuePair<TripInfo, PortalInfo>(t, portalInfo));
				}
			}
		}
		return list;
	}

	private static HashSet<ZDOID> ReadIds(ZPackage pkg)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		HashSet<ZDOID> hashSet = new HashSet<ZDOID>();
		if (pkg.GetPos() >= pkg.Size())
		{
			return hashSet;
		}
		int num = pkg.ReadInt();
		for (int i = 0; i < num; i++)
		{
			hashSet.Add(pkg.ReadZDOID());
		}
		return hashSet;
	}

	public static FavState GetFav(PortalInfo p)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		if (!SharedFavorites.Contains(p.Id))
		{
			if (!Favorites.Contains(p.Id))
			{
				return FavState.None;
			}
			return FavState.Personal;
		}
		return FavState.Shared;
	}

	public static bool IsFavorite(PortalInfo p)
	{
		return GetFav(p) != FavState.None;
	}

	public static void BeginRename(PortalInfo p)
	{
		if (p != null)
		{
			_renamePending = p;
		}
	}

	private static void UpdateRename()
	{
		if (_renamePending != null)
		{
			PortalInfo renamePending = _renamePending;
			_renamePending = null;
			if ((Object)(object)TextInput.instance != (Object)null && !TextInput.IsVisible())
			{
				TextInput.instance.RequestText((TextReceiver)(object)new RenameReceiver(renamePending), "Rename portal", 25);
				_focusFrames = 15;
			}
		}
		if (_focusFrames <= 0)
		{
			return;
		}
		_focusFrames--;
		if (!TextInput.IsVisible())
		{
			_focusFrames = 0;
			return;
		}
		try
		{
			object? obj = InputFieldInfo?.GetValue(TextInput.instance);
			Selectable val = (Selectable)((obj is Selectable) ? obj : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			PropertyInfo property = ((object)val).GetType().GetProperty("isFocused");
			if (property != null && (bool)property.GetValue(val, null))
			{
				_focusFrames = 0;
				return;
			}
			EventSystem current = EventSystem.current;
			if ((Object)(object)current != (Object)null)
			{
				current.SetSelectedGameObject(((Component)val).gameObject);
			}
			val.Select();
			((object)val).GetType().GetMethod("ActivateInputField", Type.EmptyTypes)?.Invoke(val, null);
		}
		catch (Exception ex)
		{
			_focusFrames = 0;
			Plugin.Log.LogWarning((object)("Could not focus rename box: " + ex.Message));
		}
	}

	public static void ToggleFavorite(PortalInfo p)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		if (ZRoutedRpc.instance == null || LocalPlayerId == 0L)
		{
			return;
		}
		switch (GetFav(p))
		{
		case FavState.None:
			Favorites.Add(p.Id);
			if (!FavOrder.Contains(p.Id))
			{
				FavOrder.Add(p.Id);
			}
			break;
		case FavState.Personal:
			Favorites.Remove(p.Id);
			SharedFavorites.Add(p.Id);
			break;
		default:
			SharedFavorites.Remove(p.Id);
			Favorites.Remove(p.Id);
			break;
		}
		ZRoutedRpc.instance.InvokeRoutedRPC("Portaler_ToggleFav", new object[2] { LocalPlayerId, p.Id });
	}

	public static void Activate(TeleportWorld portal)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		ZNetView component = ((Component)portal).GetComponent<ZNetView>();
		if (!((Object)(object)component == (Object)null) && component.IsValid() && !((Object)(object)Minimap.instance == (Object)null))
		{
			SourceId = component.GetZDO().m_uid;
			_sourceTransform = ((Component)portal).transform;
			_sourcePos = ((Component)portal).transform.position;
			_exitDistance = ((portal.m_exitDistance > 0f) ? portal.m_exitDistance : 1f);
			_sourceAllowAllItems = portal.m_allowAllItems;
			_activatedAt = Time.time;
			Active = true;
			_pinsDirty = true;
			RequestList();
			Minimap.instance.SetMapMode((MapMode)2);
			PortalUI.OnOpened();
		}
	}

	public static void Deactivate(bool closeMap)
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Invalid comparison between Unknown and I4
		if (Active)
		{
			Active = false;
			if (_saved && (Object)(object)Minimap.instance != (Object)null)
			{
				MapOffset.Invoke(Minimap.instance) = _savedOffset;
				Minimap.instance.LargeZoom = _savedZoom;
			}
			_saved = false;
			_moving = false;
			_returning = false;
			StopGlow();
			SourceId = ZDOID.None;
			_sourceTransform = null;
			if (closeMap && (Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode == 2)
			{
				Minimap.instance.SetMapMode((MapMode)1);
			}
		}
	}

	public static void Tick()
	{
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Invalid comparison between Unknown and I4
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		if (_pinsDirty)
		{
			Perf.Token t = Perf.Begin();
			RefreshPins();
			Perf.End(Perf.S.PinRefresh, t);
		}
		UpdateRename();
		if (Time.time >= _nextForeignScan)
		{
			_nextForeignScan = Time.time + 0.5f;
			Perf.Token t2 = Perf.Begin();
			ReskinForeignPins();
			Perf.End(Perf.S.PinScan, t2);
		}
		if (!Active)
		{
			_hoverPortal = null;
			_hoverSince = 0f;
			StopGlow();
			_saved = false;
			FlowLine.Hide();
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || (Object)(object)Minimap.instance == (Object)null)
		{
			Deactivate(closeMap: false);
			return;
		}
		UpdateMapFocus();
		if (Time.time - _activatedAt > 0.3f && (int)Minimap.instance.m_mode != 2)
		{
			Deactivate(closeMap: false);
		}
		else if ((Object)(object)_sourceTransform == (Object)null || Vector3.Distance(((Component)localPlayer).transform.position, _sourceTransform.position) > 4f)
		{
			Deactivate(closeMap: true);
		}
	}

	public static void SetOnTop(GameObject go, int order)
	{
		if ((Object)(object)go == (Object)null)
		{
			return;
		}
		Canvas val = go.GetComponent<Canvas>();
		if (order <= 0)
		{
			if ((Object)(object)val != (Object)null && val.overrideSorting)
			{
				val.overrideSorting = false;
			}
			return;
		}
		if ((Object)(object)val == (Object)null)
		{
			val = go.AddComponent<Canvas>();
		}
		if (!val.overrideSorting)
		{
			val.overrideSorting = true;
		}
		int num = MapSortingOrder();
		if (val.sortingOrder != num + order)
		{
			val.sortingOrder = num + order;
		}
		Canvas val2 = (((Object)(object)_mapCanvas != (Object)null) ? _mapCanvas.rootCanvas : null);
		if ((Object)(object)val2 != (Object)null && val.sortingLayerID != val2.sortingLayerID)
		{
			val.sortingLayerID = val2.sortingLayerID;
		}
	}

	private static int MapSortingOrder()
	{
		Minimap instance = Minimap.instance;
		if ((Object)(object)_mapCanvas == (Object)null && (Object)(object)instance != (Object)null && (Object)(object)instance.m_pinRootLarge != (Object)null)
		{
			_mapCanvas = ((Component)instance.m_pinRootLarge).GetComponentInParent<Canvas>();
		}
		Canvas val = (((Object)(object)_mapCanvas != (Object)null) ? _mapCanvas.rootCanvas : null);
		if (!((Object)(object)val != (Object)null))
		{
			return 0;
		}
		return val.sortingOrder;
	}

	public static void ScalePins()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Invalid comparison between Unknown and I4
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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_0134: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: 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_01e2: 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_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		Minimap instance = Minimap.instance;
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		bool flag = (int)instance.m_mode == 2;
		bool flag2 = flag && Active;
		Vector2 val = Vector2.op_Implicit(ZInput.pointerPosition);
		if ((Object)(object)_mapCanvas == (Object)null && (Object)(object)instance.m_pinRootLarge != (Object)null)
		{
			_mapCanvas = ((Component)instance.m_pinRootLarge).GetComponentInParent<Canvas>();
		}
		Camera val2 = (((Object)(object)_mapCanvas != (Object)null && (int)_mapCanvas.renderMode != 0) ? _mapCanvas.worldCamera : null);
		float num = 1f - Mathf.Exp((0f - Time.unscaledDeltaTime) * 14f);
		foreach (KeyValuePair<ZDOID, PinData> pin in Pins)
		{
			PinData value = pin.Value;
			if (value == null || (Object)(object)value.m_uiElement == (Object)null)
			{
				continue;
			}
			float num2 = 1f;
			if (flag && Active)
			{
				if (pin.Key == _glowId)
				{
					num2 = Plugin.PinSizePreview.Value;
				}
				else if (RectTransformUtility.RectangleContainsScreenPoint(value.m_uiElement, val, val2))
				{
					num2 = Plugin.PinSizeHover.Value;
				}
			}
			else if (flag && RectTransformUtility.RectangleContainsScreenPoint(value.m_uiElement, val, val2))
			{
				num2 = Plugin.PinSizeHover.Value;
			}
			PinScale.TryGetValue(value, out var value2);
			if (value2 <= 0f)
			{
				value2 = 1f;
			}
			value2 = Mathf.Lerp(value2, num2, num);
			if (Mathf.Abs(value2 - num2) < 0.005f)
			{
				value2 = num2;
			}
			PinScale[value] = value2;
			((Transform)value.m_uiElement).localScale = new Vector3(value2, value2, 1f);
			PinNameData namePinData = value.m_NamePinData;
			GameObject val3 = ((namePinData != null) ? namePinData.PinNameGameObject : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val3.transform.localScale = new Vector3(value2, value2, 1f);
			}
			bool flag3 = pin.Key == _glowId;
			SetOnTop(((Component)value.m_uiElement).gameObject, flag2 ? (flag3 ? 12 : 10) : 0);
			if ((Object)(object)val3 != (Object)null)
			{
				SetOnTop(val3, flag2 ? (flag3 ? 13 : 11) : 0);
			}
			if (flag2 && (Object)(object)value.m_iconElement != (Object)null && ((Graphic)value.m_iconElement).color != Color.white)
			{
				((Graphic)value.m_iconElement).color = Color.white;
			}
		}
	}

	private static void StartMove(Minimap map, Vector3 offset, float zoom, bool instant)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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)
		_targetOffset = offset;
		_targetZoom = zoom;
		_fromOffset = MapOffset.Invoke(map);
		_fromZoom = map.LargeZoom;
		_moveStart = Time.unscaledTime;
		_moveTime = (instant ? 0f : Mathf.Max(0.05f, Plugin.HoverMoveSeconds.Value));
		_moving = true;
	}

	private static void PreviewView(Minimap map, Vector3 from, Vector3 to, out Vector3 center, out float zoom, out bool instant)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(1f, (float)map.m_textureSize * map.m_pixelSize);
		float num2 = Mathf.Clamp(Plugin.HoverZoomMeters.Value / num, map.m_minZoom, map.m_maxZoom);
		if (Utils.DistanceXZ(from, to) > Plugin.HoverMaxFitMeters.Value)
		{
			center = to;
			zoom = num2;
			instant = true;
			return;
		}
		float num3 = 150f;
		float num4 = 400f;
		float num5 = Mathf.Min(from.x - num3, to.x - num4);
		float num6 = Mathf.Max(from.x + num3, to.x + num4);
		float num7 = Mathf.Min(from.z - num3, to.z - num4);
		float num8 = Mathf.Max(from.z + num3, to.z + num4);
		Rect val = (Rect)(((Object)(object)map.m_mapImageLarge != (Object)null) ? ((Graphic)map.m_mapImageLarge).rectTransform.rect : new Rect(0f, 0f, (float)Screen.width, (float)Screen.height));
		float num9 = ((((Rect)(ref val)).height > 0f) ? (((Rect)(ref val)).width / ((Rect)(ref val)).height) : ((float)Screen.width / (float)Screen.height));
		float num10 = Mathf.Clamp01(PortalUI.PanelRight / Mathf.Max(1f, (float)Screen.width));
		float num11 = Mathf.Max(0.3f, 1f - num10);
		float num12 = (num8 - num7) / num;
		float num13 = (num6 - num5) / (num * num9 * num11);
		zoom = Mathf.Clamp(Mathf.Max(num12, num13), map.m_minZoom, map.m_maxZoom);
		float num14 = zoom * num * num9;
		float num15 = num10 * 0.5f * num14;
		center = new Vector3((num5 + num6) * 0.5f - num15, to.y, (num7 + num8) * 0.5f);
		instant = false;
	}

	private static void UpdateMapFocus()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Invalid comparison between Unknown and I4
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: 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_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: 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_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: 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_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		Minimap instance = Minimap.instance;
		if (!Plugin.HoverShowsMap.Value || (int)instance.m_mode != 2)
		{
			FlowLine.Hide();
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		PortalInfo hoveredPortal = PortalUI.HoveredPortal;
		if (_saved && hoveredPortal == null)
		{
			Vector3 val = MapOffset.Invoke(instance) - _lastOffset;
			if (((Vector3)(ref val)).sqrMagnitude > 1f || Mathf.Abs(instance.LargeZoom - _lastZoom) > 0.0001f)
			{
				_saved = false;
				_moving = false;
				_returning = false;
			}
		}
		if (hoveredPortal != null)
		{
			_leftListAt = 0f;
			if (_hoverPortal == null || hoveredPortal.Id != _hoverPortal.Id)
			{
				_hoverPortal = hoveredPortal;
				_hoverSince = Time.unscaledTime;
			}
			if (Time.unscaledTime - _hoverSince >= Plugin.HoverDelay.Value && _glowId != hoveredPortal.Id)
			{
				if (!_saved)
				{
					_saved = true;
					_savedOffset = MapOffset.Invoke(instance);
					_savedZoom = instance.LargeZoom;
				}
				PreviewView(instance, SourcePosition, hoveredPortal.Position, out var center, out var zoom, out var instant);
				StartMove(instance, center - ((Component)localPlayer).transform.position, zoom, instant);
				_returning = false;
				SetGlow(hoveredPortal.Id);
			}
		}
		else
		{
			_hoverPortal = null;
			if (_saved && !_returning)
			{
				if (_leftListAt == 0f)
				{
					_leftListAt = Time.unscaledTime;
				}
				if (Time.unscaledTime - _leftListAt > Plugin.HoverReturnDelay.Value)
				{
					StopGlow();
					if (Plugin.HoverReturn.Value)
					{
						StartMove(instance, _savedOffset, _savedZoom, instant: false);
						_returning = true;
					}
					else
					{
						_saved = false;
						_moving = false;
					}
				}
			}
		}
		if (_moving)
		{
			float num = ((_moveTime <= 0f) ? 1f : Mathf.Clamp01((Time.unscaledTime - _moveStart) / _moveTime));
			float num2 = num * num * (3f - 2f * num);
			Vector3 val2 = Vector3.Lerp(_fromOffset, _targetOffset, num2);
			float largeZoom = Mathf.Exp(Mathf.Lerp(Mathf.Log(Mathf.Max(1E-05f, _fromZoom)), Mathf.Log(Mathf.Max(1E-05f, _targetZoom)), num2));
			if (num >= 1f)
			{
				val2 = _targetOffset;
				largeZoom = _targetZoom;
				_moving = false;
				if (_returning)
				{
					_returning = false;
					_saved = false;
				}
			}
			MapOffset.Invoke(instance) = val2;
			instance.LargeZoom = largeZoom;
		}
		_lastOffset = MapOffset.Invoke(instance);
		_lastZoom = instance.LargeZoom;
		PortalInfo portalInfo = ((_glowId != ZDOID.None) ? Portals.FirstOrDefault((PortalInfo p) => p.Id == _glowId) : null);
		if (po