Decompiled source of Portaler v0.5.2

plugins/Portaler.dll

Decompiled 3 weeks 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Splatform;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

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

public static class Art
{
	private static Sprite _pin;

	private static Color Px(Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Invalid comparison between Unknown and I4
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_0008: Unknown result type (might be due to invalid IL or missing references)
		if ((int)QualitySettings.activeColorSpace != 1)
		{
			return c;
		}
		Color linear = ((Color)(ref c)).linear;
		linear.a = c.a;
		return linear;
	}

	public static Sprite PinSprite()
	{
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Expected O, but got Unknown
		if ((Object)(object)_pin != (Object)null)
		{
			return _pin;
		}
		Texture2D val = null;
		try
		{
			using Stream stream = typeof(Art).Assembly.GetManifestResourceStream("Portaler.pin64.png");
			if (stream != null)
			{
				MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, memoryStream.ToArray()))
				{
					val = null;
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not load pin image: " + ex.Message));
			val = null;
		}
		if ((Object)(object)val == (Object)null)
		{
			val = FallbackRing(64);
		}
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		_pin = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		return _pin;
	}

	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_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_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b1: Expected O, but got Unknown
		//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));
			}
		}
		Texture2D val7 = new Texture2D(w, h, (TextureFormat)4, false);
		val7.SetPixels32(array);
		val7.Apply();
		((Texture)val7).filterMode = (FilterMode)1;
		((Texture)val7).wrapMode = (TextureWrapMode)1;
		((Object)val7).hideFlags = (HideFlags)61;
		return val7;
	}

	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 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 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;
	}
}
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()
		{
			PortalClient.HideForeignPins();
		}
	}

	[HarmonyPatch(typeof(Minimap), "InTextInput")]
	private static class Minimap_InTextInput
	{
		private static void Postfix(ref bool __result)
		{
			if (PortalClient.Active && PortalUI.SearchFocused)
			{
				__result = true;
			}
		}
	}
}
[BepInPlugin("nfp007.Portaler", "Portaler", "0.5.2")]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "nfp007.Portaler";

	public const string Name = "Portaler";

	public const string Version = "0.5.2";

	internal static Plugin Instance;

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> VanillaRestrictions;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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.");
		_harmony = new Harmony("nfp007.Portaler");
		_harmony.PatchAll(typeof(Plugin).Assembly);
		Log.LogInfo((object)"Portaler 0.5.2 loaded");
	}

	private void Update()
	{
		try
		{
			PortalServer.Tick();
			PortalClient.Tick();
		}
		catch (Exception ex)
		{
			Log.LogError((object)ex);
		}
	}

	private void OnGUI()
	{
		try
		{
			PortalUI.Draw();
		}
		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
	}

	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";

	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;

	public const int LastBuiltCount = 3;

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

	private static bool _pinsDirty;

	private static Sprite _pinSprite;

	private static float _nextForeignScan;

	private const float ForeignPinRadius = 4f;

	private static readonly AccessTools_FieldRef PinsField = new AccessTools_FieldRef();

	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 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;
		}
	}

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

	public static PortalInfo BackPortal
	{
		get
		{
			//IL_0031: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			Vector3? back = Prefs.GetBack();
			if (!back.HasValue)
			{
				return null;
			}
			PortalInfo portalInfo = null;
			float num = 1.5f;
			foreach (PortalInfo portal in Portals)
			{
				float num2 = Utils.DistanceXZ(portal.Position, back.Value);
				if (num2 < num && Mathf.Abs(portal.Position.y - back.Value.y) < 3f)
				{
					num = num2;
					portalInfo = portal;
				}
			}
			if (portalInfo == null || !(portalInfo.Id != SourceId))
			{
				return null;
			}
			return portalInfo;
		}
	}

	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(3).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;
		});
		_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;
	}

	private static void OnFavs(long sender, ZPackage pkg)
	{
		Favorites = ReadIds(pkg);
		SharedFavorites = ReadIds(pkg);
	}

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

	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_0098: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		if (ZRoutedRpc.instance != null && LocalPlayerId != 0L)
		{
			switch (GetFav(p))
			{
			case FavState.None:
				Favorites.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_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Invalid comparison between Unknown and I4
		if (Active)
		{
			Active = false;
			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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Invalid comparison between Unknown and I4
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		if (_pinsDirty)
		{
			RefreshPins();
		}
		UpdateRename();
		if (Time.time >= _nextForeignScan)
		{
			_nextForeignScan = Time.time + 0.5f;
			ReskinForeignPins();
		}
		if (Active)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)Minimap.instance == (Object)null)
			{
				Deactivate(closeMap: false);
			}
			else 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 TeleportTo(PortalInfo target)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: 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_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_00c7: 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)
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null))
		{
			if (target.Id == SourceId)
			{
				((Character)localPlayer).Message((MessageType)2, "You are already at this portal", 0, (Sprite)null, false);
			}
			else if (!Portals.Any((PortalInfo p) => p.Id == target.Id))
			{
				((Character)localPlayer).Message((MessageType)2, "This portal no longer exists", 0, (Sprite)null, false);
			}
			else if (!Restricted || PassesVanillaRules(localPlayer))
			{
				Vector3 val = target.Position + target.Rotation * Vector3.forward * _exitDistance + Vector3.up;
				Prefs.SetBack(SourcePosition);
				Deactivate(closeMap: true);
				((Character)localPlayer).TeleportTo(val, target.Rotation, true);
				Plugin.Log.LogInfo((object)("Teleporting to " + target.DisplayName));
			}
		}
	}

	private static bool PassesVanillaRules(Player player)
	{
		ZoneSystem instance = ZoneSystem.instance;
		if ((Object)(object)instance != (Object)null && instance.GetGlobalKey((GlobalKeys)32))
		{
			((Character)player).Message((MessageType)2, "$msg_blocked", 0, (Sprite)null, false);
			return false;
		}
		float num = default(float);
		if ((Object)(object)instance != (Object)null && instance.GetGlobalKey((GlobalKeys)33) && (((Object)(object)RandEventSystem.instance != (Object)null && !string.IsNullOrEmpty(RandEventSystem.instance.GetBossEvent())) || instance.GetGlobalKey((GlobalKeys)47, ref num)))
		{
			((Character)player).Message((MessageType)2, "$msg_blockedbyboss", 0, (Sprite)null, false);
			return false;
		}
		if (!((Humanoid)player).IsTeleportable(_sourceAllowAllItems))
		{
			((Character)player).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false);
			return false;
		}
		return true;
	}

	public static bool TryTeleportAtMapPoint(Vector3 worldPoint, float radius)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		PortalInfo portalInfo = null;
		float num = radius;
		foreach (PortalInfo destination in Destinations)
		{
			float num2 = Utils.DistanceXZ(destination.Position, worldPoint);
			if (num2 <= num)
			{
				num = num2;
				portalInfo = destination;
			}
		}
		if (portalInfo == null)
		{
			return false;
		}
		TeleportTo(portalInfo);
		return true;
	}

	private static void RefreshPins()
	{
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: 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)
		if ((Object)(object)Minimap.instance == (Object)null)
		{
			return;
		}
		_pinsDirty = false;
		foreach (PinData value in Pins.Values)
		{
			Minimap.instance.RemovePin(value);
		}
		Pins.Clear();
		if ((Object)(object)_pinSprite == (Object)null)
		{
			_pinSprite = Art.PinSprite();
		}
		foreach (PortalInfo portal in Portals)
		{
			PinData val = Minimap.instance.AddPin(portal.Position, (PinType)6, portal.DisplayName, false, false, 0L, default(PlatformUserID));
			val.m_icon = _pinSprite;
			Pins[portal.Id] = val;
		}
	}

	private static void ReskinForeignPins()
	{
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Invalid comparison between Unknown and I4
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Invalid comparison between Unknown and I4
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Invalid comparison between Unknown and I4
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Invalid comparison between Unknown and I4
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		HiddenForeign.Clear();
		if ((Object)(object)Minimap.instance == (Object)null || Portals.Count == 0)
		{
			return;
		}
		List<PinData> list = PinsField.Get(Minimap.instance);
		if (list == null)
		{
			return;
		}
		HashSet<PinData> hashSet = new HashSet<PinData>(Pins.Values);
		foreach (PinData item in list)
		{
			if (item == null || hashSet.Contains(item) || (int)item.m_type == 10 || (int)item.m_type == 4 || (int)item.m_type == 12 || (int)item.m_type == 7)
			{
				continue;
			}
			foreach (PortalInfo portal in Portals)
			{
				if (Utils.DistanceXZ(portal.Position, item.m_pos) <= 4f)
				{
					HiddenForeign.Add(item);
					break;
				}
			}
		}
	}

	public static void HideForeignPins()
	{
		foreach (PinData item in HiddenForeign)
		{
			if (item != null)
			{
				if ((Object)(object)item.m_uiElement != (Object)null && ((Component)item.m_uiElement).gameObject.activeSelf)
				{
					((Component)item.m_uiElement).gameObject.SetActive(false);
				}
				PinNameData namePinData = item.m_NamePinData;
				GameObject val = ((namePinData != null) ? namePinData.PinNameGameObject : null);
				if ((Object)(object)val != (Object)null && val.activeSelf)
				{
					val.SetActive(false);
				}
			}
		}
	}

	public static bool IsPortalPin(PinData pin)
	{
		if (pin != null)
		{
			return Pins.ContainsValue(pin);
		}
		return false;
	}
}
internal class AccessTools_FieldRef
{
	private readonly FieldRef<Minimap, List<PinData>> _ref = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins");

	public List<PinData> Get(Minimap m)
	{
		return _ref.Invoke(m);
	}
}
public class PortalInfo
{
	public ZDOID Id;

	public string Name;

	public Vector3 Position;

	public Quaternion Rotation;

	public string BiomeCode;

	public long BuiltAt;

	public string DisplayName
	{
		get
		{
			if (!string.IsNullOrEmpty(Name))
			{
				return Name;
			}
			return "(unnamed)";
		}
	}

	public static void WriteList(ZPackage pkg, List<PortalInfo> list)
	{
		//IL_001f: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		pkg.Write(list.Count);
		foreach (PortalInfo item in list)
		{
			pkg.Write(item.Id);
			pkg.Write(item.Name ?? "");
			pkg.Write(item.Position);
			pkg.Write(item.Rotation);
			pkg.Write(item.BiomeCode ?? "");
			pkg.Write(item.BuiltAt);
		}
	}

	public static List<PortalInfo> ReadList(ZPackage pkg)
	{
		//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_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		int num = pkg.ReadInt();
		List<PortalInfo> list = new List<PortalInfo>(num);
		for (int i = 0; i < num; i++)
		{
			list.Add(new PortalInfo
			{
				Id = pkg.ReadZDOID(),
				Name = pkg.ReadString(),
				Position = pkg.ReadVector3(),
				Rotation = pkg.ReadQuaternion(),
				BiomeCode = pkg.ReadString(),
				BuiltAt = pkg.ReadLong()
			});
		}
		return list;
	}
}
public static class PortalServer
{
	private class Pending
	{
		public ZDOID Id;

		public Vector3 Pos;

		public float Since;
	}

	public const string RpcRequestList = "Portaler_RequestList";

	public const string RpcNewPortal = "Portaler_NewPortal";

	public const string RpcRequestFavs = "Portaler_RequestFavs";

	public const string RpcToggleFav = "Portaler_ToggleFav";

	public const string RpcRename = "Portaler_Rename";

	private static bool _sentRestrictions;

	private static bool _lastRestrictions;

	private const float ScanInterval = 2f;

	private const float PendingTimeout = 60f;

	private static float _nextScan;

	private static string _lastHash = "";

	private static List<PortalInfo> _current = new List<PortalInfo>();

	private static readonly Dictionary<string, int> Counters = new Dictionary<string, int>();

	private static readonly Dictionary<string, long> BuiltAt = new Dictionary<string, long>();

	private static readonly Dictionary<long, HashSet<string>> Favs = new Dictionary<long, HashSet<string>>();

	private static readonly HashSet<string> Shared = new HashSet<string>();

	private static string _dataFile;

	private static readonly Dictionary<ZDOID, string> IdToKey = new Dictionary<ZDOID, string>();

	private static readonly Dictionary<string, ZDOID> KeyToId = new Dictionary<string, ZDOID>();

	private static bool _loaded;

	private static readonly List<Pending> PendingNames = new List<Pending>();

	private static readonly Regex AutoName = new Regex("^([A-Z]{2})-(\\d{3,})$");

	private static bool IsServer
	{
		get
		{
			if ((Object)(object)ZNet.instance != (Object)null)
			{
				return ZNet.instance.IsServer();
			}
			return false;
		}
	}

	public static void Register()
	{
		ZRoutedRpc.instance.Register("Portaler_RequestList", (Action<long>)OnRequestList);
		ZRoutedRpc.instance.Register<ZDOID, Vector3>("Portaler_NewPortal", (Action<long, ZDOID, Vector3>)OnNewPortal);
		ZRoutedRpc.instance.Register<long>("Portaler_RequestFavs", (Action<long, long>)OnRequestFavs);
		ZRoutedRpc.instance.Register<long, ZDOID>("Portaler_ToggleFav", (Action<long, long, ZDOID>)OnToggleFav);
		ZRoutedRpc.instance.Register<ZDOID, string, string>("Portaler_Rename", (Action<long, ZDOID, string, string>)OnRename);
		_loaded = false;
		_sentRestrictions = false;
		_lastHash = "";
		_current = new List<PortalInfo>();
		PendingNames.Clear();
	}

	public static void Tick()
	{
		if (IsServer && ZDOMan.instance != null && ZRoutedRpc.instance != null && !(Time.time < _nextScan))
		{
			_nextScan = Time.time + 2f;
			EnsureLoaded();
			ProcessPending();
			Rebuild();
			bool value = Plugin.VanillaRestrictions.Value;
			if (!_sentRestrictions || value != _lastRestrictions)
			{
				_sentRestrictions = true;
				_lastRestrictions = value;
				SendSettings(0L);
			}
		}
	}

	private static void SendSettings(long target)
	{
		ZRoutedRpc.instance.InvokeRoutedRPC(target, "Portaler_Settings", new object[1] { Plugin.VanillaRestrictions.Value });
	}

	private static void OnRequestList(long sender)
	{
		if (IsServer)
		{
			EnsureLoaded();
			Rebuild();
			Send(sender);
			SendSettings(sender);
		}
	}

	private static void OnRequestFavs(long sender, long playerId)
	{
		if (IsServer)
		{
			EnsureLoaded();
			SendFavs(sender, playerId);
		}
	}

	private static void OnToggleFav(long sender, long playerId, ZDOID id)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		if (!IsServer || playerId == 0L)
		{
			return;
		}
		EnsureLoaded();
		if (!Favs.TryGetValue(playerId, out var value))
		{
			value = (Favs[playerId] = new HashSet<string>());
		}
		string text = KeyOf(id);
		if (text != null)
		{
			bool flag = true;
			if (Shared.Contains(text))
			{
				Shared.Remove(text);
				value.Remove(text);
			}
			else if (value.Contains(text))
			{
				value.Remove(text);
				Shared.Add(text);
			}
			else
			{
				value.Add(text);
				flag = false;
			}
			Save();
			SendFavs(sender, playerId);
			if (flag)
			{
				BroadcastShared();
			}
		}
	}

	private static void OnRename(long sender, ZDOID id, string name, string author)
	{
		//IL_000d: 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)
		if (!IsServer)
		{
			return;
		}
		ZDO zDO = ZDOMan.instance.GetZDO(id);
		if (zDO == null)
		{
			return;
		}
		name = (name ?? "").Trim();
		if (name.Length > 25)
		{
			name = name.Substring(0, 25);
		}
		if (zDO.HasOwner() && !zDO.IsOwner() && ZNet.instance.GetPeer(zDO.GetOwner()) != null)
		{
			ZRoutedRpc.instance.InvokeRoutedRPC(0L, id, "RPC_SetTag", new object[2]
			{
				name,
				author ?? ""
			});
		}
		else
		{
			bool num = !zDO.IsOwner();
			if (num)
			{
				zDO.SetOwner(ZDOMan.GetSessionID());
			}
			zDO.Set(ZDOVars.s_tag, name);
			zDO.Set(ZDOVars.s_tagauthor, author ?? "");
			if (num)
			{
				zDO.SetOwner(0L);
			}
		}
		ZDOMan.instance.SetDirtyPortals();
		Plugin.Log.LogInfo((object)("Portal renamed to '" + name + "'"));
		_nextScan = 0f;
	}

	private static void SendFavs(long target, long playerId)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		ZPackage val = new ZPackage();
		Favs.TryGetValue(playerId, out var value);
		if (KeyToId.Count == 0)
		{
			Rebuild();
		}
		List<ZDOID> list = new List<ZDOID>();
		if (value != null)
		{
			foreach (string item in value)
			{
				if (KeyToId.TryGetValue(item, out var value2))
				{
					list.Add(value2);
				}
			}
		}
		WriteIds(val, list);
		WriteIds(val, SharedIds());
		ZRoutedRpc.instance.InvokeRoutedRPC(target, "Portaler_Favs", new object[1] { val });
	}

	private static void BroadcastShared()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		ZPackage val = new ZPackage();
		WriteIds(val, SharedIds());
		ZRoutedRpc.instance.InvokeRoutedRPC(0L, "Portaler_Shared", new object[1] { val });
	}

	private static List<ZDOID> SharedIds()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		List<ZDOID> list = new List<ZDOID>();
		foreach (string item in Shared)
		{
			if (KeyToId.TryGetValue(item, out var value))
			{
				list.Add(value);
			}
		}
		return list;
	}

	private static void WriteIds(ZPackage pkg, List<ZDOID> ids)
	{
		//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)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		pkg.Write(ids.Count);
		foreach (ZDOID id in ids)
		{
			pkg.Write(id);
		}
	}

	private static string KeyOf(ZDOID id)
	{
		//IL_0005: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		if (IdToKey.TryGetValue(id, out var value))
		{
			return value;
		}
		ZDOMan instance = ZDOMan.instance;
		ZDO val = ((instance != null) ? instance.GetZDO(id) : null);
		if (val == null)
		{
			return null;
		}
		return Key(val.GetPosition());
	}

	private static void OnNewPortal(long sender, ZDOID id, Vector3 pos)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		if (IsServer)
		{
			EnsureLoaded();
			PendingNames.Add(new Pending
			{
				Id = id,
				Pos = pos,
				Since = Time.time
			});
			ProcessPending();
		}
	}

	private static void ProcessPending()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		for (int num = PendingNames.Count - 1; num >= 0; num--)
		{
			Pending pending = PendingNames[num];
			ZDO zDO = ZDOMan.instance.GetZDO(pending.Id);
			if (zDO == null)
			{
				if (Time.time - pending.Since > 60f)
				{
					PendingNames.RemoveAt(num);
				}
			}
			else
			{
				PendingNames.RemoveAt(num);
				string text = Key(zDO.GetPosition());
				if (!BuiltAt.ContainsKey(text))
				{
					BuiltAt[text] = DateTime.UtcNow.Ticks;
				}
				if (string.IsNullOrEmpty(zDO.GetString(ZDOVars.s_tag, "")))
				{
					string text2 = Biomes.CodeAt(zDO.GetPosition());
					Counters.TryGetValue(text2, out var value);
					int num2 = value + 1;
					Counters[text2] = num2;
					string text3 = $"{text2}-{num2:000}";
					ZRoutedRpc.instance.InvokeRoutedRPC(0L, pending.Id, "RPC_SetTag", new object[2] { text3, "" });
					Plugin.Log.LogInfo((object)("Named new portal " + text + " as " + text3));
				}
				Save();
				_nextScan = 0f;
			}
		}
	}

	private static void Rebuild()
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		List<PortalInfo> list = new List<PortalInfo>();
		IdToKey.Clear();
		KeyToId.Clear();
		foreach (ZDO portal in ZDOMan.instance.GetPortalList())
		{
			if (portal != null && portal.IsValid())
			{
				string text = Key(portal.GetPosition());
				IdToKey[portal.m_uid] = text;
				KeyToId[text] = portal.m_uid;
				BuiltAt.TryGetValue(text, out var value);
				string name = portal.GetString(ZDOVars.s_tag, "");
				list.Add(new PortalInfo
				{
					Id = portal.m_uid,
					Name = name,
					Position = portal.GetPosition(),
					Rotation = portal.GetRotation(),
					BiomeCode = Biomes.CodeAt(portal.GetPosition()),
					BuiltAt = value
				});
				SeedCounter(name);
			}
		}
		if (list.Count > 0)
		{
			HashSet<string> alive = new HashSet<string>(KeyToId.Keys);
			List<string> list2 = BuiltAt.Keys.Where((string k) => !alive.Contains(k)).ToList();
			bool flag = false;
			foreach (string item in list2)
			{
				BuiltAt.Remove(item);
				flag = true;
			}
			foreach (HashSet<string> value2 in Favs.Values)
			{
				if (value2.RemoveWhere((string k) => !alive.Contains(k)) > 0)
				{
					flag = true;
				}
			}
			if (Shared.RemoveWhere((string k) => !alive.Contains(k)) > 0)
			{
				flag = true;
				BroadcastShared();
			}
			if (flag)
			{
				Save();
			}
		}
		string text2 = Hash(list);
		if (!(text2 == _lastHash))
		{
			if (_lastHash.Length > 0)
			{
				ZDOMan.instance.SetDirtyPortals();
			}
			_lastHash = text2;
			_current = list;
			Send(0L);
		}
	}

	private static void Send(long target)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		ZPackage val = new ZPackage();
		PortalInfo.WriteList(val, _current);
		ZRoutedRpc.instance.InvokeRoutedRPC(target, "Portaler_List", new object[1] { val });
	}

	private static void SeedCounter(string name)
	{
		if (string.IsNullOrEmpty(name))
		{
			return;
		}
		Match match = AutoName.Match(name);
		if (!match.Success)
		{
			return;
		}
		string value = match.Groups[1].Value;
		if (int.TryParse(match.Groups[2].Value, out var result))
		{
			Counters.TryGetValue(value, out var value2);
			if (result > value2)
			{
				Counters[value] = result;
				Save();
			}
		}
	}

	private static string Hash(List<PortalInfo> list)
	{
		StringBuilder stringBuilder = new StringBuilder();
		foreach (PortalInfo item in from p in list
			orderby ((ZDOID)(ref p.Id)).UserID, ((ZDOID)(ref p.Id)).ID
			select p)
		{
			stringBuilder.Append(((ZDOID)(ref item.Id)).UserID).Append(':').Append(((ZDOID)(ref item.Id)).ID)
				.Append('|')
				.Append(item.Name)
				.Append('|')
				.Append(Mathf.RoundToInt(item.Position.x))
				.Append(',')
				.Append(Mathf.RoundToInt(item.Position.z))
				.Append('|')
				.Append(item.BuiltAt)
				.Append(';');
		}
		return stringBuilder.ToString();
	}

	private static string Key(Vector3 pos)
	{
		//IL_0008: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		return Mathf.RoundToInt(pos.x * 10f) + "_" + Mathf.RoundToInt(pos.y * 10f) + "_" + Mathf.RoundToInt(pos.z * 10f);
	}

	private static void EnsureLoaded()
	{
		if (_loaded)
		{
			return;
		}
		_loaded = true;
		Counters.Clear();
		BuiltAt.Clear();
		Favs.Clear();
		Shared.Clear();
		string text = ZNet.instance.GetWorldName() ?? "world";
		char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
		foreach (char oldChar in invalidFileNameChars)
		{
			text = text.Replace(oldChar, '_');
		}
		_dataFile = DataFilePath(text);
		string text2 = _dataFile;
		if (!File.Exists(text2))
		{
			string text3 = Path.Combine(Path.Combine(Paths.ConfigPath, "Portaler"), text + ".txt");
			if (!File.Exists(text3))
			{
				Plugin.Log.LogInfo((object)("New data file: " + _dataFile));
				return;
			}
			text2 = text3;
		}
		string[] array = File.ReadAllLines(text2);
		for (int i = 0; i < array.Length; i++)
		{
			string[] array2 = array[i].Split(' ');
			if (array2.Length == 2 && array2[0] == "shared")
			{
				Shared.Add(array2[1]);
			}
			else
			{
				if (array2.Length != 3)
				{
					continue;
				}
				if (array2[0] == "counter" && int.TryParse(array2[2], out var result))
				{
					Counters[array2[1]] = result;
				}
				else
				{
					if (array2[1].Contains(":"))
					{
						continue;
					}
					long result3;
					if (array2[0] == "built" && long.TryParse(array2[2], out var result2))
					{
						BuiltAt[array2[1]] = result2;
					}
					else if (array2[0] == "fav" && !array2[2].Contains(":") && long.TryParse(array2[1], out result3))
					{
						if (!Favs.TryGetValue(result3, out var value))
						{
							value = (Favs[result3] = new HashSet<string>());
						}
						value.Add(array2[2]);
					}
				}
			}
		}
		Plugin.Log.LogInfo((object)$"Loaded {Counters.Count} counters, {BuiltAt.Count} build times and favorites of {Favs.Count} players from {text2}");
		if (text2 != _dataFile)
		{
			Save();
		}
	}

	private static string DataFilePath(string world)
	{
		try
		{
			World world2 = ZNet.instance.GetWorld();
			string text = ((world2 != null) ? world2.GetDBPath() : null);
			string text2 = (string.IsNullOrEmpty(text) ? null : Path.GetDirectoryName(text));
			if (!string.IsNullOrEmpty(text2))
			{
				Directory.CreateDirectory(text2);
				return Path.Combine(text2, world + ".portaler.txt");
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("World folder not found, using config folder: " + ex.Message));
		}
		string text3 = Path.Combine(Paths.ConfigPath, "Portaler");
		Directory.CreateDirectory(text3);
		return Path.Combine(text3, world + ".txt");
	}

	private static void Save()
	{
		if (_dataFile == null)
		{
			return;
		}
		try
		{
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, int> counter in Counters)
			{
				list.Add($"counter {counter.Key} {counter.Value}");
			}
			foreach (KeyValuePair<string, long> item in BuiltAt)
			{
				list.Add($"built {item.Key} {item.Value}");
			}
			foreach (KeyValuePair<long, HashSet<string>> fav in Favs)
			{
				foreach (string item2 in fav.Value)
				{
					list.Add($"fav {fav.Key} {item2}");
				}
			}
			foreach (string item3 in Shared)
			{
				list.Add("shared " + item3);
			}
			string text = _dataFile + ".tmp";
			File.WriteAllLines(text, list.ToArray());
			if (File.Exists(_dataFile))
			{
				File.Delete(_dataFile);
			}
			File.Move(text, _dataFile);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Could not save " + _dataFile + ": " + ex.Message));
		}
	}
}
public static class PortalUI
{
	private static bool _pressedInList;

	private const string SearchControl = "PortalerSearch";

	private static string _search = "";

	private static GUIStyle _searchStyle;

	private static GUIStyle _placeholder;

	private static GUIStyle _clearStyle;

	private static GUIStyle _backText;

	private static GUIStyle _backLabel;

	private static Texture2D _magnifier;

	private static Texture2D _backIcon;

	private const int NameChars = 25;

	private const float StarSize = 22f;

	private const float ArrowSize = 16f;

	private const int RowHeight = 36;

	private const int Variants = 3;

	private static Vector2 _scroll;

	private static PortalInfo _hovered;

	private static Rect _rect;

	private static bool _stylesReady;

	private static GUIStyle _headerButton;

	private static Texture2D _foldOpen;

	private static Texture2D _foldClosed;

	private static GUIStyle _title;

	private static GUIStyle _hint;

	private static GUIStyle _header;

	private static GUIStyle _rowText;

	private static GUIStyle _hereText;

	private static GUIStyle _hereTag;

	private static GUIStyle _closeText;

	private static GUIStyle _scrollbar;

	private static GUIStyle _distTag;

	private static GUIStyle _sortText;

	private static GUIStyle _sortLabel;

	private const int SortHeight = 30;

	private static Texture2D _starOn;

	private static Texture2D _starOff;

	private static Texture2D _starSilver;

	private static Texture2D _glow;

	private static Texture2D _arrow;

	private static Texture2D _thumb;

	private static float _width;

	private static Texture2D _panelTex;

	private static Vector2Int _panelSize;

	private static readonly Dictionary<string, Texture2D> RowTex = new Dictionary<string, Texture2D>();

	private static readonly Color PanelFill = Color32.op_Implicit(new Color32((byte)70, (byte)48, (byte)33, byte.MaxValue));

	private static readonly Color PanelFrame = Color32.op_Implicit(new Color32((byte)150, (byte)107, (byte)68, byte.MaxValue));

	private static readonly Color RowFill = Color32.op_Implicit(new Color32((byte)44, (byte)30, (byte)21, byte.MaxValue));

	private static readonly Color RowFrame = Color32.op_Implicit(new Color32((byte)126, (byte)90, (byte)58, byte.MaxValue));

	private static readonly Color HoverFill = Color32.op_Implicit(new Color32((byte)80, (byte)55, (byte)35, byte.MaxValue));

	private static readonly Color HoverFrame = Color32.op_Implicit(new Color32((byte)160, (byte)115, (byte)70, byte.MaxValue));

	private static readonly Color HereFrame = Color32.op_Implicit(new Color32((byte)196, (byte)42, (byte)26, byte.MaxValue));

	private static readonly Color HereFill = Color32.op_Implicit(new Color32((byte)58, (byte)26, (byte)18, byte.MaxValue));

	private static readonly Color CloseFill = Color32.op_Implicit(new Color32((byte)96, (byte)60, (byte)26, byte.MaxValue));

	private static readonly Color CloseHoverFill = Color32.op_Implicit(new Color32((byte)130, (byte)82, (byte)34, byte.MaxValue));

	private static readonly Color Orange = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)178, (byte)64, byte.MaxValue));

	private static readonly Color TextLight = Color32.op_Implicit(new Color32((byte)242, (byte)230, (byte)205, byte.MaxValue));

	private static readonly Color HereText = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)150, (byte)130, byte.MaxValue));

	private static bool _wantUnfocus;

	private static bool _forceOpen;

	private static string _highlight;

	private static GUIStyle _distTagLeft;

	public static bool MouseOverList { get; private set; }

	public static bool ListHasMouse
	{
		get
		{
			if (!MouseOverList)
			{
				return _pressedInList;
			}
			return true;
		}
	}

	public static bool SearchFocused { get; private set; }

	public static void OnOpened()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		_scroll = Vector2.zero;
		_search = "";
		_wantUnfocus = true;
	}

	public static void Draw()
	{
		//IL_0055: 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_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Invalid comparison between Unknown and I4
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Invalid comparison between Unknown and I4
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Invalid comparison between Unknown and I4
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Invalid comparison between Unknown and I4
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Invalid comparison between Unknown and I4
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Invalid comparison between Unknown and I4
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Invalid comparison between Unknown and I4
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Invalid comparison between Unknown and I4
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Invalid comparison between Unknown and I4
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Expected O, but got Unknown
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Invalid comparison between Unknown and I4
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0537: Unknown result type (might be due to invalid IL or missing references)
		//IL_053c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0762: Unknown result type (might be due to invalid IL or missing references)
		if (!PortalClient.Active)
		{
			MouseOverList = false;
			_pressedInList = false;
			if (SearchFocused)
			{
				GUIUtility.keyboardControl = 0;
				SearchFocused = false;
			}
			return;
		}
		EnsureStyles();
		float num = 80f;
		_rect = new Rect(16f, num, _width, Mathf.Max(300f, (float)Screen.height - num - 70f));
		Event current = Event.current;
		MouseOverList = ((Rect)(ref _rect)).Contains(current.mousePosition);
		if ((int)current.type == 0 && MouseOverList)
		{
			_pressedInList = true;
		}
		if ((int)current.rawType == 1)
		{
			_pressedInList = false;
		}
		bool num2 = TextInput.IsVisible();
		if (num2 && (current.isMouse || (int)current.type == 6))
		{
			current.Use();
		}
		if (_wantUnfocus)
		{
			_wantUnfocus = false;
			GUIUtility.keyboardControl = 0;
		}
		SearchFocused = GUI.GetNameOfFocusedControl() == "PortalerSearch";
		if (SearchFocused && (int)current.type == 4)
		{
			if ((int)current.keyCode == 27)
			{
				_search = "";
				GUIUtility.keyboardControl = 0;
				current.Use();
			}
			else if ((int)current.keyCode == 13 || (int)current.keyCode == 271)
			{
				GUIUtility.keyboardControl = 0;
				current.Use();
			}
		}
		if (SearchFocused && (int)current.type == 0 && !MouseOverList)
		{
			GUIUtility.keyboardControl = 0;
		}
		if (!num2 && !SearchFocused && (int)current.type == 4 && (int)current.keyCode == 101 && _hovered != null && MouseOverList)
		{
			PortalClient.BeginRename(_hovered);
		}
		if ((int)current.type == 7)
		{
			_hovered = null;
		}
		if ((int)current.type == 7)
		{
			GUI.DrawTexture(_rect, (Texture)(object)PanelTexture((int)((Rect)(ref _rect)).width, (int)((Rect)(ref _rect)).height));
		}
		GUIStyle verticalScrollbarThumb = GUI.skin.verticalScrollbarThumb;
		Texture2D background = verticalScrollbarThumb.normal.background;
		RectOffset border = verticalScrollbarThumb.border;
		verticalScrollbarThumb.normal.background = _thumb;
		verticalScrollbarThumb.border = new RectOffset(2, 2, 2, 2);
		PortalInfo travel = null;
		PortalInfo toggle = null;
		try
		{
			GUILayout.BeginArea(new Rect(((Rect)(ref _rect)).x + 22f, ((Rect)(ref _rect)).y + 18f, ((Rect)(ref _rect)).width - 44f, ((Rect)(ref _rect)).height - 36f));
			GUILayout.Label("Portaler", _title, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Click a name or a map pin to travel. E over a name = rename.\nRight click a name = favorite: mine (silver) > shared (gold) > off.", _hint, Array.Empty<GUILayoutOption>());
			GUILayout.Space(6f);
			SortBar();
			GUILayout.Space(6f);
			SearchBox();
			GUILayout.Space(6f);
			_scroll = GUILayout.BeginScrollView(_scroll, false, true, GUIStyle.none, _scrollbar, Array.Empty<GUILayoutOption>());
			string q = (_search ?? "").Trim();
			bool flag = q.Length > 0;
			List<PortalInfo> portals = PortalClient.Portals;
			List<PortalInfo> list = (flag ? portals.Where((PortalInfo p) => p.DisplayName.IndexOf(q, StringComparison.OrdinalIgnoreCase) >= 0).ToList() : portals);
			_highlight = (flag ? q : null);
			_forceOpen = flag;
			List<PortalInfo> list2 = (from p in list.Where(PortalClient.IsFavorite)
				orderby (PortalClient.GetFav(p) != PortalClient.FavState.Shared) ? 1 : 0
				select p).ThenBy<PortalInfo, string>((PortalInfo p) => p.DisplayName, StringComparer.OrdinalIgnoreCase).ToList();
			List<PortalInfo> lastBuilt = PortalClient.LastBuilt;
			int index = 0;
			if (flag)
			{
				GUILayout.Label($"{list.Count} of {portals.Count} portals match \"{q}\"", _distTagLeft, Array.Empty<GUILayoutOption>());
			}
			else
			{
				PortalInfo backPortal = PortalClient.BackPortal;
				if (backPortal != null)
				{
					BackRow(backPortal, ref travel, ref toggle);
					GUILayout.Space(6f);
				}
				if (list2.Count > 0)
				{
					Group("FAV", $"Favorites  ({list2.Count})", list2, ref index, ref travel, ref toggle);
				}
				if (lastBuilt.Count > 0)
				{
					Group("LAST", "Last built", lastBuilt, ref index, ref travel, ref toggle);
				}
			}
			bool rev = Prefs.SortReversed;
			StringComparer ordinalIgnoreCase = StringComparer.OrdinalIgnoreCase;
			string sortMode = Prefs.SortMode;
			if (!(sortMode == "Name"))
			{
				if (sortMode == "Distance")
				{
					Vector3 here = PortalClient.SourcePosition;
					List<PortalInfo> list3 = (rev ? list.OrderByDescending((PortalInfo p) => Utils.DistanceXZ(p.Position, here)).ToList() : list.OrderBy((PortalInfo p) => Utils.DistanceXZ(p.Position, here)).ToList());
					Group("ALL", $"All portals  ({list3.Count})", list3, ref index, ref travel, ref toggle);
				}
				else
				{
					foreach (IGrouping<string, PortalInfo> g in from p in list
						group p by p.BiomeCode into grouping
						orderby (grouping.Key == "XX") ? 1 : 0, (!rev) ? (-Biomes.SortIndex(grouping.Key)) : Biomes.SortIndex(grouping.Key)
						select grouping)
					{
						Biomes.Entry entry = Biomes.Order.FirstOrDefault((Biomes.Entry b) => b.Code == g.Key);
						string arg = (string.IsNullOrEmpty(entry.Display) ? g.Key : entry.Display);
						Group(g.Key, $"{arg}  ({g.Count()})", g.OrderBy<PortalInfo, string>((PortalInfo p) => p.DisplayName, ordinalIgnoreCase).ToList(), ref index, ref travel, ref toggle);
					}
				}
			}
			else
			{
				List<PortalInfo> list4 = (rev ? list.OrderByDescending<PortalInfo, string>((PortalInfo p) => p.DisplayName, ordinalIgnoreCase).ToList() : list.OrderBy<PortalInfo, string>((PortalInfo p) => p.DisplayName, ordinalIgnoreCase).ToList());
				Group("ALL", $"All portals  ({list4.Count})", list4, ref index, ref travel, ref toggle);
			}
			if (flag && list.Count == 0)
			{
				GUILayout.Label("No portal matches. Esc or x clears the search.", _hint, Array.Empty<GUILayoutOption>());
			}
			else if (!flag && list.Count <= 1)
			{
				GUILayout.Label("No other portals yet.", _hint, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndScrollView();
			GUILayout.Space(8f);
			if (Board(GUILayoutUtility.GetRect(GUIContent.none, _closeText, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.ExpandWidth(true),
				GUILayout.Height(36f)
			}), "Close", _closeText, "close", 0))
			{
				PortalClient.Deactivate(closeMap: true);
			}
			GUILayout.EndArea();
		}
		finally
		{
			verticalScrollbarThumb.normal.background = background;
			verticalScrollbarThumb.border = border;
		}
		if (toggle != null)
		{
			PortalClient.ToggleFavorite(toggle);
		}
		else if (travel != null)
		{
			PortalClient.TeleportTo(travel);
		}
	}

	private static void SearchBox()
	{
		//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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Invalid comparison between Unknown and I4
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: 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_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Invalid comparison between Unknown and I4
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Expected O, but got Unknown
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Expected O, but got Unknown
		Rect rect = GUILayoutUtility.GetRect(GUIContent.none, _searchStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.ExpandWidth(true),
			GUILayout.Height(34f)
		});
		((Rect)(ref rect)).width = ((Rect)(ref rect)).width - 4f;
		Event current = Event.current;
		bool flag = GUI.GetNameOfFocusedControl() == "PortalerSearch";
		if ((int)current.type == 7)
		{
			GUI.DrawTexture(rect, (Texture)(object)RowTexture((int)((Rect)(ref rect)).width, (int)((Rect)(ref rect)).height, flag ? "search-on" : "search", 0));
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 9f, ((Rect)(ref rect)).y + 8f, 18f, 18f), (Texture)(object)_magnifier);
		}
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref rect)).xMax - 30f, ((Rect)(ref rect)).y + 4f, 26f, ((Rect)(ref rect)).height - 8f);
		bool flag2 = !string.IsNullOrEmpty(_search);
		if (flag2 && (int)current.type == 0 && ((Rect)(ref val)).Contains(current.mousePosition))
		{
			_search = "";
			GUIUtility.keyboardControl = 0;
			current.Use();
		}
		GUI.SetNextControlName("PortalerSearch");
		_search = GUI.TextField(new Rect(((Rect)(ref rect)).x + 32f, ((Rect)(ref rect)).y + 2f, ((Rect)(ref rect)).width - (float)(flag2 ? 66 : 36), ((Rect)(ref rect)).height - 4f), _search ?? "", 40, _searchStyle);
		if ((int)current.type == 7)
		{
			if (!flag && string.IsNullOrEmpty(_search))
			{
				_placeholder.Draw(new Rect(((Rect)(ref rect)).x + 32f, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 36f, ((Rect)(ref rect)).height), new GUIContent("Search...  (click to type)"), false, false, false, false);
			}
			if (flag2)
			{
				_clearStyle.Draw(val, new GUIContent("x"), ((Rect)(ref val)).Contains(current.mousePosition), false, false, false);
			}
		}
	}

	private static string Highlight(string name)
	{
		if (string.IsNullOrEmpty(_highlight))
		{
			return name;
		}
		int num = name.IndexOf(_highlight, StringComparison.OrdinalIgnoreCase);
		if (num < 0)
		{
			return name;
		}
		return name.Substring(0, num) + "<color=#ffbe3c>" + name.Substring(num, _highlight.Length) + "</color>" + name.Substring(num + _highlight.Length);
	}

	private static void BackRow(PortalInfo p, ref PortalInfo travel, ref PortalInfo toggle)
	{
		//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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Invalid comparison between Unknown and I4
		//IL_0064: 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_008c: 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_00af: Invalid comparison between Unknown and I4
		//IL_0077: 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_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Expected O, but got Unknown
		//IL_0137: 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_014b: Expected O, but got Unknown
		Rect rect = GUILayoutUtility.GetRect(GUIContent.none, _backText, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.ExpandWidth(true),
			GUILayout.Height(36f)
		});
		((Rect)(ref rect)).width = ((Rect)(ref rect)).width - 4f;
		Event current = Event.current;
		if ((int)current.type == 7 && ((Rect)(ref rect)).Contains(current.mousePosition))
		{
			_hovered = p;
		}
		if ((int)current.type == 0 && current.button == 1 && ((Rect)(ref rect)).Contains(current.mousePosition))
		{
			toggle = p;
			current.Use();
		}
		if (Board(rect, p.DisplayName, _backText, "back", 0))
		{
			travel = p;
		}
		if ((int)current.type == 7)
		{
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 10f, ((Rect)(ref rect)).y + (((Rect)(ref rect)).height - 18f) / 2f, 18f, 18f), (Texture)(object)_backIcon);
			_backLabel.Draw(new Rect(((Rect)(ref rect)).x + 36f, ((Rect)(ref rect)).y, 90f, ((Rect)(ref rect)).height), new GUIContent("Back to:"), false, false, false, false);
			_hereTag.Draw(rect, new GUIContent("previous portal"), false, false, false, false);
		}
	}

	private static void SortBar()
	{
		string sortMode = Prefs.SortMode;
		bool sortReversed = Prefs.SortReversed;
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Sort:", _sortLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
		SortButton("Biome", sortMode, sortReversed ? "Biome  ME-DN" : "Biome  DN-ME");
		SortButton("Name", sortMode, sortReversed ? "Name  Z-A" : "Name  A-Z");
		SortButton("Distance", sortMode, sortReversed ? "Far first" : "Near first");
		GUILayout.EndHorizontal();
	}

	private static void SortButton(string key, string mode, string activeText)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		//IL_0064: 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)
		bool flag = mode == key || (key == "Biome" && mode != "Name" && mode != "Distance");
		string text = (flag ? activeText : key);
		if (Board(GUILayoutUtility.GetRect(new GUIContent(text), _sortText, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(30f),
			GUILayout.ExpandWidth(true)
		}), text, _sortText, flag ? "sort-on" : "sort", key.Length))
		{
			if (flag)
			{
				Prefs.SortReversed = !Prefs.SortReversed;
			}
			else
			{
				Prefs.SortMode = key;
				Prefs.SortReversed = false;
			}
			_scroll = Vector2.zero;
		}
	}

	private static string DistanceText(PortalInfo p)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		float num = Utils.DistanceXZ(p.Position, PortalClient.SourcePosition);
		if (!(num < 1000f))
		{
			return $"{num / 1000f:0.0} km";
		}
		return $"{Mathf.RoundToInt(num / 10f) * 10} m";
	}

	private static void Group(string key, string title, List<PortalInfo> items, ref int index, ref PortalInfo travel, ref PortalInfo toggle)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Invalid comparison between Unknown and I4
		//IL_0089: 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)
		bool flag = !_forceOpen && Prefs.IsCollapsed(key);
		Rect rect = GUILayoutUtility.GetRect(new GUIContent(title), _headerButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
		if ((int)Event.current.type == 7)
		{
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 2f, ((Rect)(ref rect)).y + (((Rect)(ref rect)).height - 12f) / 2f, 12f, 12f), (Texture)(object)(flag ? _foldClosed : _foldOpen));
		}
		if (GUI.Button(rect, title, _headerButton) && !_forceOpen)
		{
			Prefs.SetCollapsed(key, !flag);
		}
		if (!flag)
		{
			foreach (PortalInfo item in items)
			{
				Row(item, index++, ref travel, ref toggle);
			}
		}
		else
		{
			index += items.Count;
		}
		GUILayout.Space((float)(flag ? 2 : 6));
	}

	private static void Row(PortalInfo p, int index, ref PortalInfo travel, ref PortalInfo toggle)
	{
		//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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Invalid comparison between Unknown and I4
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Invalid comparison between Unknown and I4
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Invalid comparison between Unknown and I4
		//IL_019e: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Expected O, but got Unknown
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Expected O, but got Unknown
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Invalid comparison between Unknown and I4
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Expected O, but got Unknown
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		Rect rect = GUILayoutUtility.GetRect(GUIContent.none, _rowText, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.ExpandWidth(true),
			GUILayout.Height(36f)
		});
		((Rect)(ref rect)).width = ((Rect)(ref rect)).width - 4f;
		Event current = Event.current;
		bool num = p.Id == PortalClient.SourceId;
		if ((int)current.type == 7 && ((Rect)(ref rect)).Contains(current.mousePosition))
		{
			_hovered = p;
		}
		Rect star = default(Rect);
		((Rect)(ref star))..ctor(((Rect)(ref rect)).x + 8f, ((Rect)(ref rect)).y + (((Rect)(ref rect)).height - 22f) / 2f, 22f, 22f);
		if ((int)current.type == 0 && ((Rect)(ref rect)).Contains(current.mousePosition) && (current.button == 1 || (current.button == 0 && ((Rect)(ref star)).Contains(current.mousePosition))))
		{
			toggle = p;
			current.Use();
		}
		if (num)
		{
			if ((int)current.type == 7)
			{
				GUI.DrawTexture(rect, (Texture)(object)RowTexture((int)((Rect)(ref rect)).width, (int)((Rect)(ref rect)).height, "here", index));
				GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 12f + 22f, ((Rect)(ref rect)).y + (((Rect)(ref rect)).height - 16f) / 2f, 16f, 16f), (Texture)(object)_arrow);
				_hereText.Draw(rect, new GUIContent(Highlight(p.DisplayName)), false, false, false, false);
				_hereTag.Draw(rect, new GUIContent("you are here"), false, false, false, false);
			}
			if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref rect)).Contains(current.mousePosition))
			{
				current.Use();
			}
		}
		else
		{
			if (Board(rect, Highlight(p.DisplayName), _rowText, "row", index))
			{
				travel = p;
			}
			if ((int)current.type == 7 && Prefs.SortMode == "Distance")
			{
				_distTag.Draw(rect, new GUIContent(DistanceText(p)), false, false, false, false);
			}
		}
		if ((int)current.type == 7)
		{
			DrawStar(star, PortalClient.GetFav(p));
		}
	}

	private static void DrawStar(Rect star, PortalClient.FavState state)
	{
		//IL_000d: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: 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)
		switch (state)
		{
		case PortalClient.FavState.Personal:
			GUI.DrawTexture(star, (Texture)(object)_starSilver, (ScaleMode)2, true);
			break;
		case PortalClient.FavState.Shared:
		{
			Vector2 center = ((Rect)(ref star)).center;
			float num = 0.5f + 0.5f * Mathf.Sin(Time.realtimeSinceStartup * 3f);
			float num2 = 22f * (1.9f + 0.35f * num);
			Color color = GUI.color;
			GUI.color = new Color(1f, 1f, 1f, 0.55f + 0.45f * num);
			GUI.DrawTexture(new Rect(center.x - num2 / 2f, center.y - num2 / 2f, num2, num2), (Texture)(object)_glow, (ScaleMode)0, true);
			GUI.color = color;
			float num3 = 26.400002f;
			GUI.DrawTexture(new Rect(center.x - num3 / 2f, center.y - num3 / 2f, num3, num3), (Texture)(object)_starOn, (ScaleMode)2, true);
			break;
		}
		default:
			GUI.DrawTexture(star, (Texture)(object)_starOff, (ScaleMode)2, true);
			break;
		}
	}

	private static bool Board(Rect r, string text, GUIStyle textStyle, string kind, int index)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		Event current = Event.current;
		if ((int)current.type == 7)
		{
			bool flag = ((Rect)(ref r)).Contains(current.mousePosition);
			GUI.DrawTexture(r, (Texture)(object)RowTexture((int)((Rect)(ref r)).width, (int)((Rect)(ref r)).height, flag ? (kind + "-hover") : kind, index));
		}
		return GUI.Button(r, text, textStyle);
	}

	private static Texture2D PanelTexture(int w, int h)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unkn