Decompiled source of Advanced Portal v1.0.0

AdvancedPortal.dll

Decompiled 3 days ago
using System;
using System.Collections;
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.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AdvancedPortal
{
	internal static class Assets
	{
		internal static GameObject Storage;

		internal static readonly List<Object> Owned = new List<Object>();

		internal static void CreateStorage(ZNetScene scene)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			Release();
			Storage = new GameObject("Advanced Portal storage");
			Storage.SetActive(false);
			Storage.transform.SetParent(((Component)scene).transform, false);
		}

		internal static void Release()
		{
			foreach (Object item in Owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
			Owned.Clear();
			if ((Object)(object)Storage != (Object)null)
			{
				Object.Destroy((Object)(object)Storage);
			}
			Storage = null;
		}

		internal static void RegisterScene(ZNetScene scene, GameObject prefab)
		{
			Dictionary<int, GameObject> obj = (Dictionary<int, GameObject>)AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs").GetValue(scene);
			int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)prefab).name);
			if (obj.ContainsKey(stableHashCode))
			{
				throw new InvalidOperationException("Prefab name collision: " + ((Object)prefab).name);
			}
			obj.Add(stableHashCode, prefab);
			scene.m_prefabs.Add(prefab);
		}

		internal static GameObject Need(ZNetScene scene, string name)
		{
			return scene.GetPrefab(name) ?? throw new InvalidOperationException("Prefab missing: " + name);
		}

		internal static IEnumerable<ZDO> AllZdos()
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(ZDOMan), "m_objectsByID");
			IDictionary dictionary = ((fieldInfo != null) ? (fieldInfo.GetValue(ZDOMan.instance) as IDictionary) : null);
			if (dictionary == null)
			{
				yield break;
			}
			foreach (object value in dictionary.Values)
			{
				ZDO val = (ZDO)((value is ZDO) ? value : null);
				if (val != null)
				{
					yield return val;
				}
			}
		}

		internal static Stream Resource(string name)
		{
			return Assembly.GetExecutingAssembly().GetManifestResourceStream("advancedportal." + name) ?? throw new FileNotFoundException("Embedded resource missing: " + name);
		}

		private static byte[] Bytes(string resource)
		{
			using Stream stream = Resource(resource);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		internal static Texture2D LoadTexture(string resource)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
			if (!ImageConversion.LoadImage(val, Bytes(resource)))
			{
				throw new InvalidDataException(resource);
			}
			((Object)val).name = "AP " + resource;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Owned.Add((Object)(object)val);
			return val;
		}

		internal static Sprite LoadIcon(string resource)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0054: 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(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, Bytes(resource)))
			{
				throw new InvalidDataException(resource);
			}
			((Object)val).name = "AP " + resource;
			Owned.Add((Object)(object)val);
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			Owned.Add((Object)(object)val2);
			return val2;
		}

		internal static void ReadMeshes(string resource, out Mesh visual, out Mesh collision)
		{
			//IL_00d2: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			BinaryReader reader = new BinaryReader(Resource(resource));
			try
			{
				if (Encoding.ASCII.GetString(reader.ReadBytes(8)) != "COAHS100")
				{
					throw new InvalidDataException(resource + ": bad header");
				}
				int num = reader.ReadInt32();
				int arg = reader.ReadInt32();
				int arg2 = reader.ReadInt32();
				int arg3 = reader.ReadInt32();
				Func<int, Vector3[]> func = delegate(int count)
				{
					//IL_002e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0033: Unknown result type (might be due to invalid IL or missing references)
					Vector3[] array2 = (Vector3[])(object)new Vector3[count];
					for (int i = 0; i < count; i++)
					{
						array2[i] = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
					}
					return array2;
				};
				Func<int, int[]> func2 = delegate(int count)
				{
					int[] array2 = new int[count];
					for (int i = 0; i < count; i++)
					{
						array2[i] = reader.ReadInt32();
					}
					return array2;
				};
				Vector3[] vertices = func(num);
				Vector3[] normals = func(num);
				Vector2[] array = (Vector2[])(object)new Vector2[num];
				for (int num2 = 0; num2 < num; num2++)
				{
					array[num2] = new Vector2(reader.ReadSingle(), reader.ReadSingle());
				}
				visual = new Mesh
				{
					name = "AP " + resource
				};
				if (num > 65000)
				{
					visual.indexFormat = (IndexFormat)1;
				}
				visual.vertices = vertices;
				visual.normals = normals;
				visual.uv = array;
				visual.triangles = func2(arg);
				visual.RecalculateBounds();
				visual.RecalculateTangents();
				collision = new Mesh
				{
					name = "AP " + resource + " collider",
					vertices = func(arg2),
					triangles = func2(arg3)
				};
				collision.RecalculateBounds();
				collision.RecalculateNormals();
				Owned.Add((Object)(object)visual);
				Owned.Add((Object)(object)collision);
			}
			finally
			{
				if (reader != null)
				{
					((IDisposable)reader).Dispose();
				}
			}
		}

		private static void SetTexture(Material m, string name, Texture t)
		{
			if (m.HasProperty(name))
			{
				m.SetTexture(name, t);
			}
		}

		private static void SetFloat(Material m, string name, float v)
		{
			if (m.HasProperty(name))
			{
				m.SetFloat(name, v);
			}
		}

		internal static Material Surface(string colour, string normal, string glow, float glowStrength)
		{
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			ZNetScene instance = ZNetScene.instance;
			GameObject prefab = instance.GetPrefab("StoneGolem");
			GameObject val = Need(instance, "JotunWarrior");
			Material val2 = (from r in val.GetComponentsInChildren<SkinnedMeshRenderer>(true)
				where ((Object)r).name == "bodymale"
				select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null)) ?? (from r in val.GetComponentsInChildren<SkinnedMeshRenderer>(true)
				select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null));
			if ((Object)(object)val2 == (Object)null && (Object)(object)prefab != (Object)null)
			{
				val2 = (from r in prefab.GetComponentsInChildren<SkinnedMeshRenderer>(true)
					select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null));
			}
			Material val3 = (((Object)(object)val2 != (Object)null) ? new Material(val2) : new Material(Shader.Find("Standard") ?? Shader.Find("Diffuse")));
			((Object)val3).name = "AP " + colour;
			Owned.Add((Object)(object)val3);
			Texture2D val4 = new Texture2D(2, 2, (TextureFormat)4, true);
			if (!ImageConversion.LoadImage(val4, Bytes(colour)))
			{
				throw new InvalidDataException(colour);
			}
			((Object)val4).name = "AP " + colour;
			((Texture)val4).wrapMode = (TextureWrapMode)1;
			((Texture)val4).filterMode = (FilterMode)1;
			((Texture)val4).anisoLevel = 4;
			try
			{
				val4.Compress(false);
				val4.Apply(false, true);
			}
			catch (Exception ex)
			{
				AdvancedPortalPlugin.Log.LogWarning((object)("Texture compression skipped for " + colour + ": " + ex.Message));
			}
			Owned.Add((Object)(object)val4);
			Texture2D val5 = new Texture2D(2, 2, (TextureFormat)4, true, true);
			if (!ImageConversion.LoadImage(val5, Bytes(normal)))
			{
				throw new InvalidDataException(normal);
			}
			((Object)val5).name = "AP " + normal;
			((Texture)val5).wrapMode = (TextureWrapMode)1;
			((Texture)val5).anisoLevel = 4;
			Owned.Add((Object)(object)val5);
			val3.mainTexture = (Texture)(object)val4;
			val3.color = Color.white;
			if (val3.HasProperty("_BumpMap"))
			{
				val3.SetTexture("_BumpMap", (Texture)(object)val5);
				SetFloat(val3, "_BumpScale", 1f);
				val3.EnableKeyword("_NORMALMAP");
			}
			SetTexture(val3, "_MetallicGlossMap", null);
			SetTexture(val3, "_EmissionMap", null);
			val3.DisableKeyword("_METALLICGLOSSMAP");
			val3.DisableKeyword("_EMISSION");
			SetFloat(val3, "_Metallic", 0f);
			SetFloat(val3, "_MetalGloss", 0f);
			SetFloat(val3, "_Glossiness", 0.06f);
			SetFloat(val3, "_GlossMapScale", 0.06f);
			SetFloat(val3, "_UseGlossmap", 0f);
			SetFloat(val3, "_Hue", 0f);
			SetFloat(val3, "_Saturation", 0f);
			SetFloat(val3, "_Value", 0f);
			if (val3.HasProperty("_EmissionColor"))
			{
				val3.SetColor("_EmissionColor", Color.black);
			}
			if (glow != null && val3.HasProperty("_EmissionMap") && val3.HasProperty("_EmissionColor"))
			{
				val3.SetTexture("_EmissionMap", (Texture)(object)LoadTexture(glow));
				val3.SetColor("_EmissionColor", new Color(glowStrength, glowStrength, glowStrength, 1f));
				val3.EnableKeyword("_EMISSION");
			}
			return val3;
		}
	}
	[BepInPlugin("p0kahontazz.advancedportal", "Advanced Portal", "1.0.0")]
	public sealed class AdvancedPortalPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static class RegisterPatch
		{
			private static void Postfix(ZNetScene __instance)
			{
				try
				{
					Assets.CreateStorage(__instance);
					AdvancedPortals.Register(__instance);
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Advanced Portal registration failed: " + ex));
				}
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "OnDestroy")]
		private static class UnregisterPatch
		{
			private static void Prefix()
			{
				Assets.Release();
			}
		}

		public const string Id = "p0kahontazz.advancedportal";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("p0kahontazz.advancedportal");
			Type[] array = new Type[7]
			{
				typeof(RegisterPatch),
				typeof(UnregisterPatch),
				typeof(AdvancedPortals.UnlockPatch),
				typeof(AdvancedPortals.TakeInputPatch),
				typeof(AdvancedPortals.VisiblePatch),
				typeof(AdvancedPortals.MouseCapturePatch),
				typeof(AdvancedPortals.EscapePatch)
			};
			foreach (Type type in array)
			{
				try
				{
					harmony.CreateClassProcessor(type).Patch();
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Patch " + type.Name + " failed: " + ex));
				}
			}
			Log.LogInfo((object)"Advanced Portal 1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		private void Update()
		{
			AdvancedPortals.Tick();
		}
	}
	internal static class PortalBlue
	{
		private const float Hue = 0.58f;

		private static readonly Dictionary<Texture, Texture2D> shiftedTextures = new Dictionary<Texture, Texture2D>();

		private static int logged;

		internal static Color Shift(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(c, ref num, ref num2, ref num3);
			if (num2 < 0.2f)
			{
				return c;
			}
			Color result = Color.HSVToRGB(0.58f, num2, num3, true);
			result.a = c.a;
			return result;
		}

		private static Gradient Shift(Gradient g)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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)
			Gradient val = new Gradient();
			GradientColorKey[] colorKeys = g.colorKeys;
			for (int i = 0; i < colorKeys.Length; i++)
			{
				colorKeys[i].color = Shift(colorKeys[i].color);
			}
			val.SetKeys(colorKeys, g.alphaKeys);
			val.mode = g.mode;
			return val;
		}

		private static MinMaxGradient Shift(MinMaxGradient m)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected I4, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref m)).mode;
			switch ((int)mode)
			{
			case 0:
				return new MinMaxGradient(Shift(((MinMaxGradient)(ref m)).color));
			case 2:
				return new MinMaxGradient(Shift(((MinMaxGradient)(ref m)).colorMin), Shift(((MinMaxGradient)(ref m)).colorMax));
			case 1:
				return new MinMaxGradient(Shift(((MinMaxGradient)(ref m)).gradient));
			case 3:
				return new MinMaxGradient(Shift(((MinMaxGradient)(ref m)).gradientMin), Shift(((MinMaxGradient)(ref m)).gradientMax));
			default:
			{
				MinMaxGradient result = default(MinMaxGradient);
				((MinMaxGradient)(ref result))..ctor(Shift(((MinMaxGradient)(ref m)).gradient));
				((MinMaxGradient)(ref result)).mode = (ParticleSystemGradientMode)4;
				return result;
			}
			}
		}

		private static Texture2D ShiftTexture(Texture source)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			if (shiftedTextures.TryGetValue(source, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			if (source.width > 512 || source.height > 512)
			{
				return null;
			}
			RenderTexture temporary = RenderTexture.GetTemporary(source.width, source.height, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			Texture2D val = new Texture2D(source.width, source.height, (TextureFormat)4, false);
			try
			{
				Graphics.Blit(source, temporary);
				RenderTexture.active = temporary;
				val.ReadPixels(new Rect(0f, 0f, (float)source.width, (float)source.height), 0, 0);
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
			}
			Color[] pixels = val.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				pixels[i] = Shift(pixels[i]);
			}
			val.SetPixels(pixels);
			val.Apply(false);
			((Texture)val).wrapMode = source.wrapMode;
			((Texture)val).filterMode = source.filterMode;
			((Object)val).name = "AP blue " + ((Object)source).name;
			shiftedTextures[source] = val;
			return val;
		}

		private static void ShiftMaterial(Material material, StringBuilder report)
		{
			//IL_001a: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Invalid comparison between Unknown and I4
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Invalid comparison between Unknown and I4
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			Shader shader = material.shader;
			if ((Object)(object)shader == (Object)null)
			{
				return;
			}
			for (int i = 0; i < shader.GetPropertyCount(); i++)
			{
				if ((int)shader.GetPropertyType(i) == 0)
				{
					string propertyName = shader.GetPropertyName(i);
					Color color = material.GetColor(propertyName);
					Color val = Shift(color);
					if (val != color)
					{
						material.SetColor(propertyName, val);
					}
					report?.Append(propertyName + " " + color.r.ToString("0.0") + "," + color.g.ToString("0.0") + "," + color.b.ToString("0.0") + ">" + val.r.ToString("0.0") + "," + val.g.ToString("0.0") + "," + val.b.ToString("0.0") + " ");
				}
			}
			for (int j = 0; j < shader.GetPropertyCount(); j++)
			{
				ShaderPropertyType propertyType = shader.GetPropertyType(j);
				string propertyName2 = shader.GetPropertyName(j);
				if ((int)propertyType == 1)
				{
					string text = propertyName2.ToLowerInvariant();
					if (text.Contains("color") || text.Contains("tint") || text.Contains("emis"))
					{
						Vector4 vector = material.GetVector(propertyName2);
						Color val2 = PortalBlue.Shift(new Color(vector.x, vector.y, vector.z, vector.w));
						material.SetVector(propertyName2, new Vector4(val2.r, val2.g, val2.b, val2.a));
						report?.Append("vec " + propertyName2 + " ");
					}
				}
				else
				{
					if ((int)propertyType != 4)
					{
						continue;
					}
					Texture texture = material.GetTexture(propertyName2);
					if (!((Object)(object)texture == (Object)null))
					{
						Texture2D val3 = ShiftTexture(texture);
						if ((Object)(object)val3 != (Object)null)
						{
							material.SetTexture(propertyName2, (Texture)(object)val3);
						}
						report?.Append("tex " + propertyName2 + " " + ((Object)texture).name + " " + texture.width + "x" + texture.height + (((Object)(object)val3 != (Object)null) ? " (shifted) " : " (kept) "));
					}
				}
			}
			report?.Append("| props: ");
			if (report != null)
			{
				for (int k = 0; k < shader.GetPropertyCount() && k < 24; k++)
				{
					report.Append(shader.GetPropertyName(k) + ":" + ((object)shader.GetPropertyType(k)/*cast due to .constrained prefix*/).ToString() + " ");
				}
			}
		}

		private static string Show(MinMaxGradient m)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_002d: Invalid comparison between Unknown and I4
			//IL_0051: 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)
			//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)
			Func<Color, string> func = (Color k) => k.r.ToString("0.00") + "," + k.g.ToString("0.00") + "," + k.b.ToString("0.00");
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref m)).mode;
			if ((int)mode != 0)
			{
				if ((int)mode == 2)
				{
					return "two " + func(((MinMaxGradient)(ref m)).colorMin) + " / " + func(((MinMaxGradient)(ref m)).colorMax);
				}
				return ((object)((MinMaxGradient)(ref m)).mode/*cast due to .constrained prefix*/).ToString();
			}
			return "color " + func(((MinMaxGradient)(ref m)).color);
		}

		internal static void Apply(GameObject root)
		{
			//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_0023: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Expected O, but got Unknown
			StringBuilder stringBuilder = new StringBuilder();
			ParticleSystem[] componentsInChildren = root.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				MainModule main = val.main;
				string text = Show(((MainModule)(ref main)).startColor);
				((MainModule)(ref main)).startColor = Shift(((MainModule)(ref main)).startColor);
				if (logged < 4)
				{
					string[] obj = new string[6]
					{
						((Object)val).name,
						" [",
						text,
						" -> ",
						null,
						null
					};
					MainModule main2 = val.main;
					obj[4] = Show(((MainModule)(ref main2)).startColor);
					obj[5] = "] ";
					stringBuilder.Append(string.Concat(obj));
				}
				ColorOverLifetimeModule colorOverLifetime = val.colorOverLifetime;
				if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
				{
					((ColorOverLifetimeModule)(ref colorOverLifetime)).color = Shift(((ColorOverLifetimeModule)(ref colorOverLifetime)).color);
				}
				ColorBySpeedModule colorBySpeed = val.colorBySpeed;
				if (((ColorBySpeedModule)(ref colorBySpeed)).enabled)
				{
					((ColorBySpeedModule)(ref colorBySpeed)).color = Shift(((ColorBySpeedModule)(ref colorBySpeed)).color);
				}
				TrailModule trails = val.trails;
				if (((TrailModule)(ref trails)).enabled)
				{
					((TrailModule)(ref trails)).colorOverLifetime = Shift(((TrailModule)(ref trails)).colorOverLifetime);
					((TrailModule)(ref trails)).colorOverTrail = Shift(((TrailModule)(ref trails)).colorOverTrail);
				}
			}
			ParticleSystemRenderer[] componentsInChildren2 = root.GetComponentsInChildren<ParticleSystemRenderer>(true);
			foreach (ParticleSystemRenderer val2 in componentsInChildren2)
			{
				Material[] materials = ((Renderer)val2).materials;
				Material[] array = materials;
				foreach (Material val3 in array)
				{
					if (logged < 4)
					{
						stringBuilder.Append("{" + ((Object)val2).name + ": " + ((Object)val3).name + " (" + (((Object)(object)val3.shader != (Object)null) ? ((Object)val3.shader).name : "?") + ") ");
					}
					ShiftMaterial(val3, (logged < 4) ? stringBuilder : null);
					if (logged < 4)
					{
						stringBuilder.Append("} ");
					}
				}
				((Renderer)val2).materials = materials;
				if ((Object)(object)val2.trailMaterial != (Object)null)
				{
					Material val4 = new Material(val2.trailMaterial);
					ShiftMaterial(val4, null);
					val2.trailMaterial = val4;
				}
			}
			Light[] componentsInChildren3 = root.GetComponentsInChildren<Light>(true);
			foreach (Light obj2 in componentsInChildren3)
			{
				obj2.color = Shift(obj2.color);
			}
			if (logged++ < 4)
			{
				AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal blue: " + ((Object)root).name + " - " + stringBuilder));
			}
		}
	}
	internal static class AdvancedPortals
	{
		[HarmonyPatch(typeof(Player), "HaveRequirements", new Type[]
		{
			typeof(Piece),
			typeof(RequirementMode)
		})]
		internal static class UnlockPatch
		{
			private static void Postfix(Player __instance, Piece piece, RequirementMode mode, ref bool __result)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Invalid comparison between Unknown and I4
				if (__result || (int)mode != 1 || (Object)(object)piece == (Object)null || ((Object)((Component)piece).gameObject).name != "AdvancedPortal" || (Object)(object)ObjectDB.instance == (Object)null)
				{
					return;
				}
				string[] array = new string[3] { "TrophyEikthyr", "TrophyTheElder", "TrophyBonemass" };
				foreach (string text in array)
				{
					GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text);
					ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
					if ((Object)(object)val != (Object)null && __instance.IsMaterialKnown(val.m_itemData.m_shared.m_name))
					{
						__result = true;
						break;
					}
				}
			}
		}

		internal sealed class Entry
		{
			public ZDOID Id;

			public string Name;

			public Vector3 Pos;

			public float Yaw;

			public bool Advanced;

			public bool Busy;
		}

		[HarmonyPatch(typeof(Player), "TakeInput")]
		internal static class TakeInputPatch
		{
			private static void Postfix(ref bool __result)
			{
				if (PortalWindow.IsOpen)
				{
					__result = false;
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "IsVisible")]
		internal static class VisiblePatch
		{
			private static void Postfix(ref bool __result)
			{
				if (PortalWindow.IsOpen)
				{
					__result = true;
				}
			}
		}

		[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
		internal static class MouseCapturePatch
		{
			private static bool Prefix()
			{
				if (!PortalWindow.IsOpen)
				{
					return true;
				}
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
				return false;
			}
		}

		[HarmonyPatch(typeof(Menu), "Update")]
		internal static class EscapePatch
		{
			private static bool Prefix()
			{
				if (!PortalWindow.IsOpen)
				{
					return true;
				}
				if (ZInput.GetKeyDown((KeyCode)27, true))
				{
					PortalWindow.Close();
					return false;
				}
				return true;
			}
		}

		internal const string PrefabName = "AdvancedPortal";

		internal const float Sink = 0.28f;

		internal const float Scale = 2.6f;

		internal static readonly Vector3 OpeningMiddle = new Vector3(-0.036f, 0.69f, -0.23f);

		internal static readonly int Hash = StringExtensionMethods.GetStableHashCode("AdvancedPortal");

		internal const string NameKey = "ap_name";

		internal const string TargetKey = "ap_target";

		internal const string PosKey = "ap_pos";

		internal const string YawKey = "ap_yaw";

		internal const string ExitKey = "ap_exit";

		internal const string TargetNameKey = "ap_tname";

		internal const float OwnExit = 2.2f;

		internal const string TrophyEikthyr = "TrophyEikthyr";

		internal const string TrophyElder = "TrophyTheElder";

		internal const string TrophyBonemass = "TrophyBonemass";

		private static readonly Tuple<string, int>[] Cost = new Tuple<string, int>[6]
		{
			Tuple.Create("TrophyEikthyr", 1),
			Tuple.Create("TrophyTheElder", 1),
			Tuple.Create("TrophyBonemass", 1),
			Tuple.Create("FineWood", 40),
			Tuple.Create("Stone", 30),
			Tuple.Create("SurtlingCore", 3)
		};

		private static readonly float[] HoleXY = new float[128]
		{
			0.3897f, 0f, 0.3854f, 0.038f, 0.381f, 0.0758f, 0.3789f, 0.115f, 0.3774f, 0.1563f,
			0.3955f, 0.2114f, 0.3979f, 0.2658f, 0.3776f, 0.3099f, 0.3454f, 0.3454f, 0.3099f, 0.3776f,
			0.2658f, 0.3979f, 0.2097f, 0.3922f, 0.1654f, 0.3993f, 0.1262f, 0.416f, 0.0846f, 0.4252f,
			0.0426f, 0.4327f, 0f, 0.441f, -0.0442f, 0.4488f, -0.0912f, 0.4583f, -0.1429f, 0.4711f,
			-0.2089f, 0.5044f, -0.2509f, 0.4694f, -0.2888f, 0.4322f, -0.3416f, 0.4163f, -0.3737f, 0.3737f,
			-0.3805f, 0.3123f, -0.3573f, 0.2388f, -0.3746f, 0.2002f, -0.3982f, 0.1649f, -0.4089f, 0.124f,
			-0.4129f, 0.0821f, -0.404f, 0.0398f, -0.391f, 0f, -0.3904f, -0.0384f, -0.3908f, -0.0777f,
			-0.3909f, -0.1186f, -0.3901f, -0.1616f, -0.3735f, -0.1996f, -0.3365f, -0.2249f, -0.3245f, -0.2663f,
			-0.3083f, -0.3083f, -0.2853f, -0.3477f, -0.254f, -0.3802f, -0.232f, -0.4341f, -0.2008f, -0.4848f,
			-0.1512f, -0.4986f, -0.0992f, -0.4987f, -0.0491f, -0.4986f, -0f, -0.501f, 0.0495f, -0.5023f,
			0.1004f, -0.5049f, 0.1545f, -0.5093f, 0.2094f, -0.5056f, 0.2544f, -0.476f, 0.2707f, -0.4051f,
			0.3075f, -0.3747f, 0.3419f, -0.3419f, 0.368f, -0.302f, 0.3875f, -0.2589f, 0.4132f, -0.2208f,
			0.4109f, -0.1702f, 0.4053f, -0.1229f, 0.3994f, -0.0795f, 0.3953f, -0.0389f
		};

		private static ZRoutedRpc registered;

		private static float nextCheck;

		internal static void Register(ZNetScene scene)
		{
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: 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_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Expected O, but got Unknown
			//IL_0335: 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_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_062c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0639: Unknown result type (might be due to invalid IL or missing references)
			//IL_0645: Expected O, but got Unknown
			GameObject val = Assets.Storage ?? throw new InvalidOperationException("Advanced Portal storage missing.");
			GameObject val2 = Assets.Need(scene, "stone_wall_1x1");
			GameObject prefab = scene.GetPrefab("Hammer");
			PieceTable val3 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val3.m_pieces.RemoveAll((GameObject p) => (Object)(object)p == (Object)null || ((Object)p).name == "AdvancedPortal");
			}
			Assets.ReadMeshes("portal.bin", out var visual, out var collision);
			Material val4 = Assets.Surface("portal.jpg", "portal_n.jpg", "portal_e.jpg", 0f);
			((Object)val4).name = "Advanced Portal";
			string[] array = new string[2] { "_Glossiness", "_MetalGloss" };
			foreach (string text in array)
			{
				if (val4.HasProperty(text))
				{
					val4.SetFloat(text, 0.25f);
				}
			}
			if (val4.HasProperty("_Metallic"))
			{
				val4.SetFloat("_Metallic", 0f);
			}
			GameObject val5 = Object.Instantiate<GameObject>(val2, val.transform, false);
			((Object)val5).name = "AdvancedPortal";
			for (int num2 = val5.transform.childCount - 1; num2 >= 0; num2--)
			{
				Object.DestroyImmediate((Object)(object)((Component)val5.transform.GetChild(num2)).gameObject);
			}
			WearNTear[] components = val5.GetComponents<WearNTear>();
			for (int num = 0; num < components.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)components[num]);
			}
			Collider[] components2 = val5.GetComponents<Collider>();
			for (int num = 0; num < components2.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)components2[num]);
			}
			Renderer[] components3 = val5.GetComponents<Renderer>();
			for (int num = 0; num < components3.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)components3[num]);
			}
			MeshFilter[] components4 = val5.GetComponents<MeshFilter>();
			for (int num = 0; num < components4.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)components4[num]);
			}
			LODGroup[] components5 = val5.GetComponents<LODGroup>();
			for (int num = 0; num < components5.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)components5[num]);
			}
			int layer = LayerMask.NameToLayer("piece");
			Vector3 val6 = Vector3.down * 0.28f;
			GameObject val7 = new GameObject("visual");
			val7.transform.SetParent(val5.transform, false);
			val7.layer = layer;
			val7.transform.localScale = Vector3.one * 2.6f;
			val7.transform.localPosition = val6;
			val7.AddComponent<MeshFilter>().sharedMesh = visual;
			MeshRenderer val8 = val7.AddComponent<MeshRenderer>();
			((Renderer)val8).sharedMaterial = val4;
			GameObject val9 = new GameObject("collider");
			val9.transform.SetParent(val5.transform, false);
			val9.layer = layer;
			val9.transform.localScale = Vector3.one * 2.6f;
			val9.transform.localPosition = val6;
			val9.AddComponent<MeshCollider>().sharedMesh = collision;
			GameObject val10 = new GameObject("membrane");
			val10.transform.SetParent(val5.transform, false);
			val10.transform.localPosition = OpeningMiddle * 2.6f + val6;
			Shader shader = Shader.Find("Sprites/Default") ?? Shader.Find("Standard");
			Transform layerA = HoleLayer(val10.transform, "vortex a", (Texture)(object)Assets.LoadTexture("vortex_a.png"), shader, 1f, 0f, 1f, 1.25f);
			Transform layerB = HoleLayer(val10.transform, "vortex b", (Texture)(object)Assets.LoadTexture("vortex_b.png"), shader, 0.93f, 0.103999995f, 0.8f, 1f);
			Light val11 = new GameObject("light").AddComponent<Light>();
			((Component)val11).transform.SetParent(val10.transform, false);
			((Component)val11).transform.localPosition = new Vector3(0f, 0f, 0.9f);
			val11.type = (LightType)2;
			val11.color = new Color(0.3f, 0.65f, 1f);
			val11.range = 9f;
			val11.intensity = 0f;
			val11.shadows = (LightShadows)0;
			val10.SetActive(false);
			GameObject val12 = new GameObject("door");
			val12.transform.SetParent(val5.transform, false);
			val12.transform.localPosition = new Vector3(OpeningMiddle.x * 2.6f, OpeningMiddle.y * 2.6f, -0.31f) + val6;
			BoxCollider obj = val12.AddComponent<BoxCollider>();
			((Collider)obj).isTrigger = true;
			obj.size = new Vector3(1.872f, 2.34f, 0.98f);
			val12.AddComponent<AdvancedPortalDoor>();
			Piece component = val5.GetComponent<Piece>();
			component.m_name = "Advanced Portal";
			component.m_description = "A portal that opens wherever its keeper chooses. Press E to choose the destination, Shift+E to name it.";
			component.m_icon = Assets.LoadIcon("portal_icon.png");
			component.m_category = (PieceCategory)0;
			component.m_craftingStation = null;
			component.m_allowedInDungeons = false;
			component.m_groundOnly = false;
			component.m_groundPiece = false;
			component.m_cultivatedGroundOnly = false;
			component.m_waterPiece = false;
			component.m_notOnWood = false;
			component.m_notOnTiltingSurface = false;
			component.m_inCeilingOnly = false;
			component.m_notOnFloor = false;
			component.m_onlyInTeleportArea = false;
			component.m_onlyInBiome = (Biome)0;
			component.m_clipGround = true;
			component.m_clipEverything = true;
			component.m_noClipping = false;
			component.m_comfort = 0;
			component.m_enabled = true;
			component.m_canBeRemoved = true;
			List<Requirement> list = new List<Requirement>();
			Tuple<string, int>[] cost = Cost;
			foreach (Tuple<string, int> tuple in cost)
			{
				GameObject prefab2 = scene.GetPrefab(tuple.Item1);
				ItemDrop val13 = (((Object)(object)prefab2 != (Object)null) ? prefab2.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val13 == (Object)null)
				{
					AdvancedPortalPlugin.Log.LogWarning((object)("Advanced Portal: requirement " + tuple.Item1 + " not found, left out."));
					continue;
				}
				list.Add(new Requirement
				{
					m_resItem = val13,
					m_amount = tuple.Item2,
					m_recover = true
				});
			}
			component.m_resources = list.ToArray();
			GameObject prefab3 = scene.GetPrefab("portal_wood");
			WearNTear val14 = (((Object)(object)prefab3 != (Object)null) ? prefab3.GetComponent<WearNTear>() : null);
			WearNTear val15 = val5.AddComponent<WearNTear>();
			if ((Object)(object)val14 != (Object)null)
			{
				FieldInfo[] fields = typeof(WearNTear).GetFields(BindingFlags.Instance | BindingFlags.Public);
				foreach (FieldInfo fieldInfo in fields)
				{
					fieldInfo.SetValue(val15, fieldInfo.GetValue(val14));
				}
			}
			val15.m_new = null;
			val15.m_worn = null;
			val15.m_broken = null;
			val15.m_snow = null;
			val15.m_snowWorn = null;
			val15.m_snowBroken = null;
			val15.m_fragmentRoots = (GameObject[])(object)new GameObject[0];
			val15.m_autoCreateFragments = false;
			val15.m_health = (((Object)(object)val14 != (Object)null) ? val14.m_health : 400f) * 2f;
			AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal: health " + val15.m_health + (((Object)(object)val14 == (Object)null) ? " (the game's portal was not found, 400 assumed)" : " (twice the game's portal)") + "."));
			AdvancedPortalPiece advancedPortalPiece = val5.AddComponent<AdvancedPortalPiece>();
			advancedPortalPiece.Runes = val8;
			advancedPortalPiece.Membrane = val10;
			advancedPortalPiece.LayerA = layerA;
			advancedPortalPiece.LayerB = layerB;
			advancedPortalPiece.Lamp = val11;
			Assets.RegisterScene(scene, val5);
			if ((Object)(object)val3 != (Object)null)
			{
				val3.m_pieces.Add(val5);
			}
			AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal registered" + (((Object)(object)val3 != (Object)null) ? " (hammer, Misc tab)." : " (no hammer table found).")));
		}

		private static Transform HoleLayer(Transform parent, string name, Texture texture, Shader shader, float shrink, float z, float alpha, float uvSpan)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_00b3: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = new Vector3(0f, 0f, z);
			int num = HoleXY.Length / 2;
			Vector3[] array = (Vector3[])(object)new Vector3[num + 1];
			Vector2[] array2 = (Vector2[])(object)new Vector2[num + 1];
			int[] array3 = new int[num * 3];
			array2[0] = new Vector2(0.5f, 0.5f);
			for (int i = 0; i < num; i++)
			{
				float num2 = HoleXY[i * 2] * shrink;
				float num3 = HoleXY[i * 2 + 1] * shrink;
				array[i + 1] = new Vector3(num2 * 2.6f, num3 * 2.6f, 0f);
				array2[i + 1] = new Vector2(0.5f + num2 / uvSpan, 0.5f + num3 / uvSpan);
				array3[i * 3] = 0;
				array3[i * 3 + 1] = i + 1;
				array3[i * 3 + 2] = (i + 1) % num + 1;
			}
			Mesh val2 = new Mesh
			{
				name = "AP membrane " + name,
				vertices = array,
				uv = array2,
				triangles = array3
			};
			val2.RecalculateBounds();
			Assets.Owned.Add((Object)(object)val2);
			val.AddComponent<MeshFilter>().sharedMesh = val2;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = new Material(shader)
			{
				mainTexture = texture,
				color = new Color(1f, 1f, 1f, alpha)
			};
			return val.transform;
		}

		private static string NameOf(ZDO zdo, bool advanced)
		{
			string text = zdo.GetString(advanced ? "ap_name" : "tag", "");
			if (text.Length <= 0)
			{
				if (!advanced)
				{
					return "(unnamed)";
				}
				return "Advanced Portal";
			}
			return text;
		}

		internal static bool BusyFor(ZDO other, ZDOID self)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_002c: 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)
			ZDOID val = ((other.GetPrefab() == Hash) ? other.GetZDOID("ap_target") : other.GetConnectionZDOID((ConnectionType)1));
			if (!((ZDOID)(ref val)).IsNone() && val != self)
			{
				return ZDOMan.instance.GetZDO(val) != null;
			}
			return false;
		}

		internal static List<Entry> KnownPortals(ZDOID self)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_005c: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			List<Entry> list = new List<Entry>();
			if (ZDOMan.instance == null)
			{
				return list;
			}
			try
			{
				Quaternion rotation;
				foreach (ZDO portal in ZDOMan.instance.GetPortalList())
				{
					if (portal != null && portal.m_uid != self)
					{
						Entry obj = new Entry
						{
							Id = portal.m_uid,
							Name = NameOf(portal, advanced: false),
							Pos = portal.GetPosition()
						};
						rotation = portal.GetRotation();
						obj.Yaw = ((Quaternion)(ref rotation)).eulerAngles.y;
						obj.Advanced = false;
						obj.Busy = BusyFor(portal, self);
						list.Add(obj);
					}
				}
				foreach (ZDO item in Assets.AllZdos())
				{
					if (item.GetPrefab() == Hash && item.m_uid != self)
					{
						Entry obj2 = new Entry
						{
							Id = item.m_uid,
							Name = NameOf(item, advanced: true),
							Pos = item.GetPosition()
						};
						rotation = item.GetRotation();
						obj2.Yaw = ((Quaternion)(ref rotation)).eulerAngles.y;
						obj2.Advanced = true;
						obj2.Busy = BusyFor(item, self);
						list.Add(obj2);
					}
				}
			}
			catch (Exception ex)
			{
				AdvancedPortalPlugin.Log.LogError((object)("Advanced Portal: the list failed: " + ex));
			}
			return list;
		}

		internal static void OnList(long sender, ZPackage pkg)
		{
			//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_005a: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || ZDOMan.instance == null)
			{
				return;
			}
			List<Entry> list = KnownPortals(pkg.ReadZDOID());
			AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal: " + list.Count + " portals sent to the player who asked."));
			ZPackage val = new ZPackage();
			val.Write(list.Count);
			foreach (Entry item in list)
			{
				val.Write(item.Id);
				val.Write(item.Name);
				val.Write(item.Pos);
				val.Write(item.Yaw);
				val.Write(item.Advanced);
				val.Write(item.Busy);
			}
			ZRoutedRpc.instance.InvokeRoutedRPC(sender, "AP_PortalListReply", new object[1] { val });
		}

		internal static void OnListReply(long sender, ZPackage pkg)
		{
			//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)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			int num = pkg.ReadInt();
			List<Entry> list = new List<Entry>();
			for (int i = 0; i < num; i++)
			{
				list.Add(new Entry
				{
					Id = pkg.ReadZDOID(),
					Name = pkg.ReadString(),
					Pos = pkg.ReadVector3(),
					Yaw = pkg.ReadSingle(),
					Advanced = pkg.ReadBool(),
					Busy = pkg.ReadBool()
				});
			}
			AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal: the server's list has " + list.Count + " portals."));
			PortalWindow.Fill(list, fromServer: true);
		}

		internal static void OnSet(long sender, ZPackage pkg)
		{
			//IL_001b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			ZDOID val = pkg.ReadZDOID();
			ZDOID val2 = pkg.ReadZDOID();
			ZDO zDO = ZDOMan.instance.GetZDO(val);
			if (zDO == null || zDO.GetPrefab() != Hash)
			{
				return;
			}
			zDO.SetOwner(ZDOMan.GetSessionID());
			if (((ZDOID)(ref val2)).IsNone())
			{
				ZDO zDO2 = ZDOMan.instance.GetZDO(zDO.GetZDOID("ap_target"));
				if (zDO2 != null && zDO2.GetPrefab() == Hash && zDO2.GetZDOID("ap_target") == val)
				{
					zDO2.SetOwner(ZDOMan.GetSessionID());
					Clear(zDO2);
				}
				Clear(zDO);
				return;
			}
			ZDO zDO3 = ZDOMan.instance.GetZDO(val2);
			if (zDO3 == null || zDO3.m_uid == val)
			{
				return;
			}
			if (BusyFor(zDO3, val))
			{
				AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal: " + NameOf(zDO3, zDO3.GetPrefab() == Hash) + " is connected to another portal already; refused."));
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "ShowMessage", new object[2] { 2, "That portal is already connected to another portal." });
				return;
			}
			bool flag = zDO3.GetPrefab() == Hash;
			float num = 2.2f;
			if (!flag)
			{
				GameObject val3 = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(zDO3.GetPrefab()) : null);
				TeleportWorld val4 = (((Object)(object)val3 != (Object)null) ? val3.GetComponentInChildren<TeleportWorld>(true) : null);
				num = (((Object)(object)val4 != (Object)null) ? val4.m_exitDistance : 1f);
			}
			Unpair(zDO);
			zDO.Set("ap_target", val2);
			zDO.Set("ap_pos", zDO3.GetPosition());
			Quaternion rotation = zDO3.GetRotation();
			zDO.Set("ap_yaw", ((Quaternion)(ref rotation)).eulerAngles.y);
			zDO.Set("ap_exit", num);
			zDO.Set("ap_tname", NameOf(zDO3, flag));
			if (!flag)
			{
				Pair(zDO, zDO3);
			}
			if (flag)
			{
				ZDOID zDOID = zDO3.GetZDOID("ap_target");
				if (((ZDOID)(ref zDOID)).IsNone())
				{
					zDO3.SetOwner(ZDOMan.GetSessionID());
					zDO3.Set("ap_target", val);
					zDO3.Set("ap_pos", zDO.GetPosition());
					rotation = zDO.GetRotation();
					zDO3.Set("ap_yaw", ((Quaternion)(ref rotation)).eulerAngles.y);
					zDO3.Set("ap_exit", 2.2f);
					zDO3.Set("ap_tname", NameOf(zDO, advanced: true));
					AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal: " + NameOf(zDO3, advanced: true) + " leads back here (paired)."));
					goto IL_02fe;
				}
			}
			if (flag)
			{
				AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal: " + NameOf(zDO3, advanced: true) + " already leads somewhere (" + zDO3.GetString("ap_tname", "?") + "), it stays as it is."));
			}
			goto IL_02fe;
			IL_02fe:
			ManualLogSource log = AdvancedPortalPlugin.Log;
			string[] obj = new string[7] { "Advanced Portal at ", null, null, null, null, null, null };
			Vector3 position = zDO.GetPosition();
			obj[1] = ((Vector3)(ref position)).ToString("F0");
			obj[2] = " now leads to ";
			obj[3] = NameOf(zDO3, flag);
			obj[4] = " at ";
			position = zDO3.GetPosition();
			obj[5] = ((Vector3)(ref position)).ToString("F0");
			obj[6] = ".";
			log.LogInfo((object)string.Concat(obj));
		}

		private static void Pair(ZDO advanced, ZDO vanilla)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			try
			{
				ZDOID connectionZDOID = vanilla.GetConnectionZDOID((ConnectionType)1);
				if (!((ZDOID)(ref connectionZDOID)).IsNone() && connectionZDOID != advanced.m_uid)
				{
					AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal: " + NameOf(vanilla, advanced: false) + " is paired with another portal already; it stays one-way."));
					return;
				}
				advanced.Set(ZDOVars.s_tag, vanilla.GetString(ZDOVars.s_tag, ""));
				advanced.SetConnection((ConnectionType)1, vanilla.m_uid);
				vanilla.SetOwner(ZDOMan.GetSessionID());
				vanilla.SetConnection((ConnectionType)1, advanced.m_uid);
				ZDOMan.instance.ForceSendZDO(vanilla.m_uid);
				ZDOMan.instance.ForceSendZDO(advanced.m_uid);
				AdvancedPortalPlugin.Log.LogInfo((object)("Advanced Portal: " + NameOf(vanilla, advanced: false) + " is connected back to the Advanced Portal."));
			}
			catch (Exception ex)
			{
				AdvancedPortalPlugin.Log.LogWarning((object)("Advanced Portal: the pairing with the game's portal failed (" + ex.Message + ")"));
			}
		}

		private static void Unpair(ZDO advanced)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			ZDOID connectionZDOID = advanced.GetConnectionZDOID((ConnectionType)1);
			if (!((ZDOID)(ref connectionZDOID)).IsNone())
			{
				ZDO zDO = ZDOMan.instance.GetZDO(connectionZDOID);
				advanced.SetConnection((ConnectionType)1, ZDOID.None);
				if (zDO != null && zDO.GetPrefab() != Hash && zDO.GetConnectionZDOID((ConnectionType)1) == advanced.m_uid)
				{
					zDO.SetOwner(ZDOMan.GetSessionID());
					zDO.SetConnection((ConnectionType)1, ZDOID.None);
					ZDOMan.instance.ForceSendZDO(zDO.m_uid);
				}
			}
		}

		private static void Clear(ZDO zdo)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Unpair(zdo);
			zdo.Set("ap_target", ZDOID.None);
			zdo.Set("ap_tname", "");
		}

		internal static void OnName(long sender, ZPackage pkg)
		{
			//IL_001b: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			ZDOID val = pkg.ReadZDOID();
			string text = pkg.ReadString();
			ZDO zDO = ZDOMan.instance.GetZDO(val);
			if (zDO != null && zDO.GetPrefab() == Hash)
			{
				if (text.Length > 40)
				{
					text = text.Substring(0, 40);
				}
				zDO.SetOwner(ZDOMan.GetSessionID());
				zDO.Set("ap_name", text);
			}
		}

		internal static void Tick()
		{
			if (ZRoutedRpc.instance != null && ZRoutedRpc.instance != registered)
			{
				registered = ZRoutedRpc.instance;
				registered.Register<ZPackage>("AP_PortalList", (Action<long, ZPackage>)OnList);
				registered.Register<ZPackage>("AP_PortalListReply", (Action<long, ZPackage>)OnListReply);
				registered.Register<ZPackage>("AP_PortalSet", (Action<long, ZPackage>)OnSet);
				registered.Register<ZPackage>("AP_PortalName", (Action<long, ZPackage>)OnName);
			}
			if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
			{
				ServerCheck();
			}
		}

		internal static void ServerCheck()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < nextCheck || ZDOMan.instance == null)
			{
				return;
			}
			nextCheck = Time.unscaledTime + 15f;
			foreach (ZDO item in (from z in Assets.AllZdos()
				where z.GetPrefab() == Hash
				select z).ToList())
			{
				ZDOID zDOID = item.GetZDOID("ap_target");
				if (!((ZDOID)(ref zDOID)).IsNone() && ZDOMan.instance.GetZDO(zDOID) == null)
				{
					item.SetOwner(ZDOMan.GetSessionID());
					Clear(item);
					ManualLogSource log = AdvancedPortalPlugin.Log;
					Vector3 position = item.GetPosition();
					log.LogInfo((object)("Advanced Portal at " + ((Vector3)(ref position)).ToString("F0") + ": its destination is gone, the portal is shut."));
				}
			}
		}
	}
	public sealed class AdvancedPortalDoor : MonoBehaviour
	{
		private void OnTriggerEnter(Collider other)
		{
			Player componentInParent = ((Component)other).GetComponentInParent<Player>();
			if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent != (Object)(object)Player.m_localPlayer))
			{
				AdvancedPortalPiece componentInParent2 = ((Component)this).GetComponentInParent<AdvancedPortalPiece>();
				if ((Object)(object)componentInParent2 != (Object)null)
				{
					componentInParent2.Enter(componentInParent);
				}
			}
		}
	}
	public sealed class AdvancedPortalPiece : MonoBehaviour, Hoverable, Interactable, TextReceiver
	{
		public MeshRenderer Runes;

		public GameObject Membrane;

		public Transform LayerA;

		public Transform LayerB;

		public Light Lamp;

		private ZNetView view;

		private Material runes;

		private float level;

		private float seed;

		private float nextEnter;

		private static readonly Color Blue = new Color(0.35f, 0.75f, 1f);

		private Mesh meshA;

		private Mesh meshB;

		private Vector2[] baseA;

		private Vector2[] baseB;

		private float angleA;

		private float angleB;

		private GameObject swirl;

		private bool wasOn;

		private bool seen;

		private GameObject near;

		private EffectFade nearFade;

		private float nextNear;

		private bool nearOn;

		private const float NearRange = 5f;

		private const float NearScale = 1.5f;

		private const float SparkFactor = 4f;

		private ZDO Zdo
		{
			get
			{
				if (!((Object)(object)view != (Object)null) || !view.IsValid())
				{
					return null;
				}
				return view.GetZDO();
			}
		}

		internal ZDOID Id => Zdo?.m_uid ?? ZDOID.None;

		internal string PortalName
		{
			get
			{
				ZDO zdo = Zdo;
				if (zdo == null)
				{
					return "";
				}
				return zdo.GetString("ap_name", "");
			}
		}

		internal ZDOID Target
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				ZDO zdo = Zdo;
				if (zdo == null)
				{
					return ZDOID.None;
				}
				return zdo.GetZDOID("ap_target");
			}
		}

		internal string TargetName
		{
			get
			{
				ZDO zdo = Zdo;
				if (zdo == null)
				{
					return "";
				}
				return zdo.GetString("ap_tname", "");
			}
		}

		private void Awake()
		{
			if ((Object)(object)LayerA != (Object)null)
			{
				MeshFilter component = ((Component)LayerA).GetComponent<MeshFilter>();
				meshA = component.mesh;
				baseA = meshA.uv;
			}
			if ((Object)(object)LayerB != (Object)null)
			{
				MeshFilter component2 = ((Component)LayerB).GetComponent<MeshFilter>();
				meshB = component2.mesh;
				baseB = meshB.uv;
			}
			view = ((Component)this).GetComponent<ZNetView>();
			seed = Random.value * 10f;
			if ((Object)(object)Runes != (Object)null)
			{
				runes = ((Renderer)Runes).material;
			}
		}

		private void Update()
		{
			//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)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			ZDOID target = Target;
			bool flag = !((ZDOID)(ref target)).IsNone();
			if (!seen)
			{
				seen = true;
				wasOn = flag;
			}
			if (flag && !wasOn)
			{
				Connected();
			}
			else if (!flag && wasOn && (Object)(object)swirl != (Object)null)
			{
				Object.Destroy((Object)(object)swirl);
				swirl = null;
			}
			wasOn = flag;
			if (!flag && (Object)(object)near != (Object)null)
			{
				Object.Destroy((Object)(object)near);
				near = null;
				nearFade = null;
				nearOn = false;
			}
			level = Mathf.MoveTowards(level, flag ? 1f : 0f, Time.deltaTime * 1.2f);
			if ((Object)(object)Membrane != (Object)null && Membrane.activeSelf != level > 0.01f)
			{
				Membrane.SetActive(level > 0.01f);
			}
			if (level <= 0.01f)
			{
				if ((Object)(object)runes != (Object)null && runes.HasProperty("_EmissionColor"))
				{
					runes.SetColor("_EmissionColor", Color.black);
				}
				return;
			}
			float num = Time.time + seed;
			float num2 = 0.82f + 0.2f * Mathf.Sin(num * 2.3f) + 0.08f * Mathf.Sin(num * 6.1f + 1f);
			if ((Object)(object)meshA != (Object)null)
			{
				angleA += 14f * Time.deltaTime;
				Turn(meshA, baseA, angleA);
			}
			if ((Object)(object)meshB != (Object)null)
			{
				angleB -= 27f * Time.deltaTime;
				Turn(meshB, baseB, angleB);
			}
			if ((Object)(object)runes != (Object)null && runes.HasProperty("_EmissionColor"))
			{
				runes.EnableKeyword("_EMISSION");
				runes.SetColor("_EmissionColor", Blue * (1.25f * num2 * level));
			}
			if ((Object)(object)Lamp != (Object)null)
			{
				Lamp.intensity = 1.8f * num2 * level;
			}
			if (Time.time >= nextNear)
			{
				nextNear = Time.time + 0.4f;
				Near(flag);
			}
			Transform[] array = (Transform[])(object)new Transform[2] { LayerA, LayerB };
			foreach (Transform val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					Renderer component = ((Component)val).GetComponent<Renderer>();
					Color color = component.material.color;
					color.a = (((Object)(object)val == (Object)(object)LayerA) ? 1f : 0.8f) * level;
					component.material.color = color;
				}
			}
		}

		private void Near(bool on)
		{
			//IL_0026: 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)
			try
			{
				Player localPlayer = Player.m_localPlayer;
				bool flag = on && (Object)(object)Membrane != (Object)null && (Object)(object)localPlayer != (Object)null && Vector3.Distance(((Component)localPlayer).transform.position, Membrane.transform.position) < 5f;
				if (flag && (Object)(object)near == (Object)null)
				{
					MakeNear();
				}
				if ((Object)(object)nearFade != (Object)null && nearOn != flag)
				{
					nearFade.SetActive(flag);
					nearOn = flag;
				}
			}
			catch (Exception ex)
			{
				AdvancedPortalPlugin.Log.LogWarning((object)("Advanced Portal: the near effect failed (" + ex.Message + ")"));
				nextNear = Time.time + 30f;
			}
		}

		private void MakeNear()
		{
			//IL_00b1: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			ZNetScene instance = ZNetScene.instance;
			GameObject val = (((Object)(object)instance != (Object)null) ? instance.GetPrefab("portal_wood") : null);
			Transform val2 = (((Object)(object)val != (Object)null) ? (val.transform.Find("_target_found_red") ?? val.transform.Find("_target_found")) : null);
			if ((Object)(object)val2 == (Object)null)
			{
				AdvancedPortalPlugin.Log.LogWarning((object)"Advanced Portal: the game's portal effect was not found.");
				nextNear = Time.time + 30f;
				return;
			}
			near = Object.Instantiate<GameObject>(((Component)val2).gameObject, Membrane.transform, false);
			((Object)near).name = "near";
			near.transform.localScale = Vector3.one * 1.5f;
			near.transform.localRotation = Quaternion.identity;
			near.transform.localPosition = new Vector3(0f, -2.055f, 0f);
			foreach (Transform item in near.GetComponentsInChildren<Transform>(true).ToList())
			{
				if ((Object)(object)item != (Object)null && (((Object)item).name == "Black_suck" || ((Object)item).name == "blue flames"))
				{
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
			}
			ParticleSystem[] componentsInChildren = near.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val3 in componentsInChildren)
			{
				if (!(((Object)val3).name != "suck particles"))
				{
					EmissionModule emission = val3.emission;
					MinMaxCurve rateOverTime = ((EmissionModule)(ref emission)).rateOverTime;
					((EmissionModule)(ref emission)).rateOverTime = new MinMaxCurve(Mathf.Max(((MinMaxCurve)(ref rateOverTime)).constantMax, 1f) * 4f);
					MainModule main = val3.main;
					((MainModule)(ref main)).maxParticles = Mathf.Max(((MainModule)(ref main)).maxParticles, 4000);
				}
			}
			near.SetActive(true);
			PortalBlue.Apply(near);
			nearFade = near.GetComponent<EffectFade>();
			nearOn = false;
		}

		private void Connected()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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)
			try
			{
				ZNetScene instance = ZNetScene.instance;
				GameObject val = (((Object)(object)instance != (Object)null) ? instance.GetPrefab("portal_wood") : null);
				if ((Object)(object)val == (Object)null || (Object)(object)Membrane == (Object)null)
				{
					return;
				}
				TeleportWorld component = val.GetComponent<TeleportWorld>();
				if (!((Object)(object)component != (Object)null) || component.m_connected == null)
				{
					return;
				}
				GameObject[] array = component.m_connected.Create(Membrane.transform.position, ((Component)this).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
				if (array == null)
				{
					return;
				}
				GameObject[] array2 = array;
				foreach (GameObject val2 in array2)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						PortalBlue.Apply(val2);
					}
				}
			}
			catch (Exception ex)
			{
				AdvancedPortalPlugin.Log.LogWarning((object)("Advanced Portal: its connected effect could not be made (" + ex.Message + ")"));
			}
		}

		private static void Turn(Mesh mesh, Vector2[] baseUv, float degrees)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Cos(degrees * ((float)Math.PI / 180f));
			float num2 = Mathf.Sin(degrees * ((float)Math.PI / 180f));
			Vector2[] array = (Vector2[])(object)new Vector2[baseUv.Length];
			for (int i = 0; i < array.Length; i++)
			{
				float num3 = baseUv[i].x - 0.5f;
				float num4 = baseUv[i].y - 0.5f;
				array[i] = new Vector2(0.5f + num3 * num - num4 * num2, 0.5f + num3 * num2 + num4 * num);
			}
			mesh.uv = array;
		}

		public string GetHoverName()
		{
			return "Advanced Portal";
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public string GetHoverText()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			string portalName = PortalName;
			string targetName = TargetName;
			string text = ((portalName.Length > 0) ? ("Advanced Portal \"" + portalName + "\"") : "Advanced Portal");
			ZDOID target = Target;
			string text2 = (((ZDOID)(ref target)).IsNone() ? "<color=orange>(no destination)</color>" : ("-> " + targetName));
			return Localization.instance.Localize(text + " " + text2 + "\n[<color=yellow><b>$KEY_Use</b></color>] Choose destination\n[<color=yellow><b>Shift + $KEY_Use</b></color>] Name");
		}

		public bool Interact(Humanoid human, bool hold, bool alt)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (hold)
			{
				return false;
			}
			if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false))
			{
				((Character)human).Message((MessageType)2, "$piece_noaccess", 0, (Sprite)null, false);
				return true;
			}
			if (alt)
			{
				if ((Object)(object)TextInput.instance != (Object)null)
				{
					TextInput.instance.RequestText((TextReceiver)(object)this, "Name", 40);
				}
				return true;
			}
			PortalWindow.Open(this);
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}

		public string GetText()
		{
			return PortalName;
		}

		public void SetText(string text)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (Zdo != null && ZRoutedRpc.instance != null)
			{
				ZPackage val = new ZPackage();
				val.Write(Id);
				val.Write(text ?? "");
				ZRoutedRpc.instance.InvokeRoutedRPC("AP_PortalName", new object[1] { val });
			}
		}

		internal void Enter(Player player)
		{
			//IL_000b: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			ZDO zdo = Zdo;
			if (zdo == null)
			{
				return;
			}
			ZDOID target = Target;
			if (!((ZDOID)(ref target)).IsNone() && !(Time.time < nextEnter))
			{
				nextEnter = Time.time + 2f;
				if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)32))
				{
					((Character)player).Message((MessageType)2, "$msg_blocked", 0, (Sprite)null, false);
					return;
				}
				float num = default(float);
				if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)33) && (RandEventSystem.instance.GetBossEvent() != null || (ZoneSystem.instance.GetGlobalKey((GlobalKeys)47, ref num) && num > 0f)))
				{
					((Character)player).Message((MessageType)2, "$msg_blockedbyboss", 0, (Sprite)null, false);
					return;
				}
				if (!((Humanoid)player).IsTeleportable(false))
				{
					((Character)player).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false);
					return;
				}
				Vector3 vec = zdo.GetVec3("ap_pos", Vector3.zero);
				Quaternion val = Quaternion.Euler(0f, zdo.GetFloat("ap_yaw", 0f), 0f);
				float num2 = zdo.GetFloat("ap_exit", 1f);
				((Character)player).TeleportTo(vec + val * Vector3.forward * num2 + Vector3.up, val, true);
			}
		}
	}
	internal static class PortalWindow
	{
		private static GameObject root;

		private static AdvancedPortalPiece portal;

		private static List<AdvancedPortals.Entry> entries = new List<AdvancedPortals.Entry>();

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

		private static int selected = -1;

		private static TMP_Text title;

		private static TMP_Text subtitle;

		private static TMP_Text loading;

		private static TMP_Text chosen;

		private static TMP_Text active;

		private static Text titleText;

		private static RawImage map;

		private static RectTransform pinThere;

		private static RectTransform pinHere;

		private static Button connect;

		private static Button disconnect;

		private static TMP_FontAsset font;

		private static Transform listContent;

		private static int sortBy = 2;

		private static bool distanceFar;

		private static List<AdvancedPortals.Entry> source = new List<AdvancedPortals.Entry>();

		private static readonly Image[] sortChips = (Image[])(object)new Image[3];

		private static readonly Color ChipOff = new Color(0f, 0f, 0f, 0.5f);

		private static readonly Color MarkGrey = new Color(0.55f, 0.55f, 0.55f, 1f);

		private static readonly Color Row = new Color(1f, 1f, 1f, 0.05f);

		private static readonly Color RowOn = new Color(1f, 0.63f, 0.235f, 0.47f);

		private static readonly Color Beige = new Color(0.98f, 0.95f, 0.9f);

		private static readonly Color Grey = new Color(0.65f, 0.62f, 0.58f);

		private static float askedAt;

		private static bool answered;

		private static readonly Dictionary<string, Sprite> sprites = new Dictionary<string, Sprite>();

		private static readonly Color MarkGreen = new Color(0.45f, 0.9f, 0.45f, 1f);

		private static Sprite panelSprite;

		private static Type panelType;

		private static Color panelColor = Color.white;

		private static float panelPpu = 1f;

		private static Material panelMaterial;

		private static Button buttonTemplate;

		private static TMP_FontAsset titleFont;

		private static TMP_FontAsset bodyFont;

		private static Color titleColor = new Color(1f, 0.63f, 0.235f);

		private static Color bodyColor = new Color(0.98f, 0.95f, 0.9f);

		private static bool skin;

		private static readonly Vector2 half = new Vector2(0.5f, 0.5f);

		internal static bool IsOpen => (Object)(object)root != (Object)null;

		internal static void Open(AdvancedPortalPiece piece)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			Close();
			portal = piece;
			entries = new List<AdvancedPortals.Entry>();
			source = new List<AdvancedPortals.Entry>();
			selected = -1;
			Build();
			askedAt = Time.unscaledTime;
			answered = false;
			Fill(AdvancedPortals.KnownPortals(piece.Id), fromServer: false);
			ZPackage val = new ZPackage();
			val.Write(piece.Id);
			if (ZRoutedRpc.instance != null)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC("AP_PortalList", new object[1] { val });
			}
			root.AddComponent<PortalWindowWatch>();
		}

		internal static void Close()
		{
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			root = null;
			portal = null;
			rows.Clear();
			if ((Object)(object)map != (Object)null && (Object)(object)((Graphic)map).material != (Object)null)
			{
				Object.Destroy((Object)(object)((Graphic)map).material);
			}
			map = null;
		}

		private static RectTransform Rect(string name, Transform parent, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0045: 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)
			RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) })
			{
				layer = LayerMask.NameToLayer("UI")
			}.GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			component.anchorMin = aMin;
			component.anchorMax = aMax;
			component.offsetMin = oMin;
			component.offsetMax = oMax;
			return component;
		}

		private static Image Box(string name, Transform parent, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Image obj = ((Component)Rect(name, parent, aMin, aMax, oMin, oMax)).gameObject.AddComponent<Image>();
			((Graphic)obj).color = color;
			return obj;
		}

		private static Sprite FindSprite(string name)
		{
			if (sprites.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = null;
			Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
			foreach (Sprite val in array)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name == name)
				{
					value = val;
					break;
				}
			}
			sprites[name] = value;
			return value;
		}

		private static void Mark(Transform parent, float x, bool open)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0073: 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_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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			Sprite val = FindSprite("checkbox");
			Sprite val2 = FindSprite("checkbox_marker");
			Image val3 = Box("mark", parent, new Vector2(0f, 0.5f), new Vector2(0f, 0.5f), new Vector2(x, -17f), new Vector2(x + 34f, 17f), ((Object)(object)val != (Object)null) ? new Color(1f, 1f, 1f, open ? 0.9f : 0.55f) : new Color(0f, 0f, 0f, 0.45f));
			((Graphic)val3).raycastTarget = false;
			if ((Object)(object)val != (Object)null)
			{
				val3.sprite = val;
			}
			Image val4 = Box("fill", ((Component)val3).transform, half, half, new Vector2(-17f, -17f), new Vector2(17f, 17f), open ? MarkGreen : MarkGrey);
			((Graphic)val4).raycastTarget = false;
			if ((Object)(object)val2 != (Object)null)
			{
				val4.sprite = val2;
			}
		}

		private static Image Chip(string name, Transform parent, float x0, float x1, float yTop, float yBottom, string text, Action click)
		{
			//IL_0021: 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_0026: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_009f: 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_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_00ba: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			Image val2 = Box(name, parent, val, val, new Vector2(x0, yBottom), new Vector2(x1, yTop), ChipOff);
			Button obj = ((Component)val2).gameObject.AddComponent<Button>();
			((Selectable)obj).targetGraphic = (Graphic)(object)val2;
			ColorBlock colors = ((Selectable)obj).colors;
			((ColorBlock)(ref colors)).highlightedColor = new Color(1.3f, 1.2f, 1.1f, 1f);
			((Selectable)obj).colors = colors;
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				ClickSound();
				click();
			});
			Label("text", ((Component)val2).transform, Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero, text, 24f, Beige, (TextAlignmentOptions)514);
			return val2;
		}

		private static TMP_Text Label(string name, Transform parent, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax, string text, float size, Color color, TextAlignmentOptions align)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = ((Component)Rect(name, parent, aMin, aMax, oMin, oMax)).gameObject.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)val).font = font;
			}
			((TMP_Text)val).text = text;
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = color;
			((TMP_Text)val).alignment = align;
			((Graphic)val).raycastTarget = false;
			((TMP_Text)val).enableWordWrapping = false;
			((TMP_Text)val).overflowMode = (TextOverflowModes)1;
			return (TMP_Text)(object)val;
		}

		private static void Discover()
		{
			//IL_00fd: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			skin = false;
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_crafting == (Object)null)
			{
				return;
			}
			try
			{
				List<Image> list = ((Component)instance.m_crafting).GetComponentsInChildren<Image>(true).ToList();
				Transform parent = ((Transform)instance.m_crafting).parent;
				int num = 0;
				while (num < 3 && (Object)(object)parent != (Object)null)
				{
					Image component = ((Component)parent).GetComponent<Image>();
					if ((Object)(object)component != (Object)null)
					{
						list.Add(component);
					}
					num++;
					parent = parent.parent;
				}
				Func<Image, bool> bad = delegate(Image i)
				{
					string text = (((Object)i).name + " " + ((Object)i.sprite).name).ToLowerInvariant();
					string[] array = new string[12]
					{
						"darken", "blob", "shadow", "glow", "select", "icon", "scroll", "handle", "bar", "highlight",
						"button", "tab"
					};
					foreach (string value in array)
					{
						if (text.Contains(value))
						{
							return true;
						}
					}
					return false;
				};
				Image val = list.Where((Image i) => (Object)(object)i.sprite != (Object)null && !bad(i) && ((Graphic)i).color.a > 0.5f).OrderByDescending(delegate(Image i)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_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)
					Rect rect = ((Graphic)i).rectTransform.rect;
					float width = ((Rect)(ref rect)).width;
					rect = ((Graphic)i).rectTransform.rect;
					return width * ((Rect)(ref rect)).height;
				}).FirstOrDefault();
				if ((Object)(object)val != (Object)null)
				{
					panelSprite = val.sprite;
					panelType = val.type;
					panelColor = ((Graphic)val).color;
					panelPpu = val.pixelsPerUnitMultiplier;
					panelMaterial = ((Graphic)val).material;
				}
				buttonTemplate = instance.m_craftButton;
				if ((Object)(object)instance.m_recipeName != (Object)null)
				{
					titleFont = instance.m_recipeName.font;
				}
				if ((Object)(object)instance.m_recipeDecription != (Object)null)
				{
					bodyFont = instance.m_recipeDecription.font;
					bodyColor = ((Graphic)instance.m_recipeDecription).color;
				}
				font = bodyFont;
				skin = (Object)(object)val != (Object)null;
			}
			catch (Exception ex)
			{
				AdvancedPortalPlugin.Log.LogWarning((object)("Advanced Portal window: the game's skin was not found (" + ex.Message + "), plain colours are used."));
			}
		}

		private static bool Keep(Component c)
		{
			if (!(c is Graphic) && !(c is Selectable) && !(c is Mask) && !(c is RectMask2D) && !(c is LayoutGroup) && !(c is ContentSizeFitter) && !(c is LayoutElement))
			{
				return c is BaseMeshEffect;
			}
			return true;
		}

		private static Button MakeButton(string name, Transform parent, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax, string text, Color colour, Action click)
		{
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: 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_0055: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: 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_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing