Decompiled source of PortalMonuments v1.0.5

plugins/PortalMonuments.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using SoftReferenceableAssets;
using Splatform;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PortalMonuments")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Disrod")]
[assembly: AssemblyProduct("PortalMonuments")]
[assembly: AssemblyCopyright("Copyright © 2026 Disrod")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.0.5")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.0")]
namespace PortalMonuments;

internal class MonumentBeam : MonoBehaviour
{
	private struct Layer
	{
		public float Radius;

		public float Sharpness;

		public float Strength;

		public Layer(float radius, float sharpness, float strength)
		{
			Radius = radius;
			Sharpness = sharpness;
			Strength = strength;
		}
	}

	private const string ColumnName = "Column";

	private const string MotesName = "Motes";

	private const float Height = 70f;

	private const int Segments = 20;

	private const float StreakAround = 2f;

	private const float StreakRepeat = 8f;

	private const float StreakSpeed = 0.12f;

	private const float PulseSeconds = 4f;

	private const float PulseAmount = 0.12f;

	private const float NightStrength = 1f;

	private const float DayStrength = 0.75f;

	private const float Intensity = 1.5f;

	private const float NearDistance = 80f;

	private const float MaxDistanceScale = 10f;

	private const float DistanceBrightening = 0.5f;

	private const float MaxBrighteningScale = 3f;

	private const float CloseFadeStart = 7f;

	private const float CloseFadeEnd = 2f;

	private const float CloseStrength = 0.35f;

	private const float FadeInSeconds = 1f;

	private const float FadeOutSeconds = 2.5f;

	private static readonly Color Pale = new Color(0.75f, 0.85f, 1f);

	private static readonly Layer[] Layers = new Layer[2]
	{
		new Layer(1.1f, 2f, 1f),
		new Layer(2.6f, 1.5f, 0.35f)
	};

	private static readonly float[] Rows = new float[13]
	{
		0f, 0.3f, 1f, 2.5f, 5f, 9f, 15f, 23f, 32f, 42f,
		52f, 61f, 70f
	};

	private static Material _columnMaterial;

	private static Material _moteMaterial;

	private static bool _texturesReady;

	private Transform _column;

	private MeshRenderer _columnRenderer;

	private ParticleSystem _motes;

	private ParticleSystemRenderer _motesRenderer;

	private MaterialPropertyBlock _block;

	private float _fade;

	private float _phase;

	private Mesh _mesh;

	private Vector3[] _vertices;

	private Vector3[] _normals;

	private Color[] _colors;

	private float[] _baseAlpha;

	private float[] _sharpness;

	public bool Wanted { get; set; }

	public bool Gone
	{
		get
		{
			if (!Wanted && _fade <= 0f)
			{
				if (!((Object)(object)_motes == (Object)null))
				{
					return _motes.particleCount == 0;
				}
				return true;
			}
			return false;
		}
	}

	public static void Create(GameObject root, Material additive, Vector3 localPosition)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_002a: 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_003b: Expected O, but got Unknown
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Beam");
		val.SetActive(false);
		val.transform.SetParent(root.transform, false);
		val.transform.localPosition = localPosition;
		_columnMaterial = new Material(additive);
		_moteMaterial = new Material(additive);
		GameObject val2 = new GameObject("Column");
		val2.transform.SetParent(val.transform, false);
		val2.AddComponent<MeshFilter>().sharedMesh = CreateColumnMesh();
		MeshRenderer obj = val2.AddComponent<MeshRenderer>();
		((Renderer)obj).sharedMaterial = _columnMaterial;
		((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)obj).receiveShadows = false;
		AddMotes(val.transform);
		val.AddComponent<MonumentBeam>();
	}

	private void Awake()
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		EnsureTextures();
		_column = ((Component)this).transform.Find("Column");
		_columnRenderer = ((Component)_column).GetComponent<MeshRenderer>();
		_motes = ((Component)((Component)this).transform.Find("Motes")).GetComponent<ParticleSystem>();
		_motesRenderer = ((Component)_motes).GetComponent<ParticleSystemRenderer>();
		_block = new MaterialPropertyBlock();
		_phase = Random.value * 4f;
		((Renderer)_columnRenderer).enabled = false;
		SetEmitting(on: false);
		MeshFilter component = ((Component)_column).GetComponent<MeshFilter>();
		_mesh = Object.Instantiate<Mesh>(component.sharedMesh);
		component.sharedMesh = _mesh;
		_vertices = _mesh.vertices;
		_normals = _mesh.normals;
		_colors = _mesh.colors;
		_baseAlpha = new float[_colors.Length];
		_sharpness = new float[_colors.Length];
		Vector2[] uv = _mesh.uv2;
		for (int i = 0; i < _colors.Length; i++)
		{
			_baseAlpha[i] = _colors[i].a;
			_sharpness[i] = uv[i].x;
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)_mesh != (Object)null)
		{
			Object.Destroy((Object)(object)_mesh);
		}
	}

	private void LateUpdate()
	{
		//IL_014e: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		bool flag = Wanted && MonumentSettings.Beam.Value;
		_fade = Mathf.MoveTowards(_fade, flag ? 1f : 0f, Time.deltaTime / (flag ? 1f : 2.5f));
		SetEmitting(flag);
		bool flag2 = _fade > 0f;
		if (((Renderer)_columnRenderer).enabled != flag2)
		{
			((Renderer)_columnRenderer).enabled = flag2;
		}
		if (!flag2 && _motes.particleCount == 0)
		{
			return;
		}
		float num = 1f;
		float num2 = 1f;
		Camera mainCamera = Utils.GetMainCamera();
		if ((Object)(object)mainCamera != (Object)null)
		{
			Vector3 val = Quaternion.Inverse(_column.rotation) * (((Component)mainCamera).transform.position - _column.position);
			Vector2 val2 = new Vector2(val.x, val.z);
			float magnitude = ((Vector2)(ref val2)).magnitude;
			num = Mathf.Clamp(magnitude / 80f, 1f, 10f);
			num2 = Mathf.Lerp(0.35f, 1f, Mathf.InverseLerp(2f, 7f, magnitude));
			if (flag2)
			{
				UpdateFacing(val, num);
			}
		}
		_column.localScale = new Vector3(num, 1f, num);
		float num3 = 1f + 0.12f * Mathf.Sin((Time.time + _phase) * (float)Math.PI * 2f / 4f);
		float num4 = 1.5f * TimeOfDayStrength() * MonumentSettings.BeamBrightness.Value * num3 * (1f + 0.5f * (Mathf.Min(num, 3f) - 1f));
		Color val3 = Pale * 0.7f;
		val3.a = 0.5f * num4 * num2 * _fade;
		_block.Clear();
		_block.SetColor("_TintColor", val3);
		_block.SetVector("_MainTex_ST", new Vector4(1f, 1f, 0f, (0f - Time.time) * 0.12f));
		((Renderer)_columnRenderer).SetPropertyBlock(_block);
		_block.Clear();
		val3.a = 0.5f * num4;
		_block.SetColor("_TintColor", val3);
		((Renderer)_motesRenderer).SetPropertyBlock(_block);
	}

	private void UpdateFacing(Vector3 cameraLocal, float distanceScale)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: 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_0025: 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_0032: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val2 = default(Vector3);
		for (int i = 0; i < _vertices.Length; i++)
		{
			Vector3 val = _vertices[i];
			((Vector3)(ref val2))..ctor(val.x * distanceScale - cameraLocal.x, val.y - cameraLocal.y, val.z * distanceScale - cameraLocal.z);
			float magnitude = ((Vector3)(ref val2)).magnitude;
			Vector3 val3 = _normals[i];
			float num = ((magnitude > 0.001f) ? (Mathf.Abs(val3.x * val2.x + val3.z * val2.z) / magnitude) : 0f);
			_colors[i].a = _baseAlpha[i] * Mathf.Pow(num, _sharpness[i]);
		}
		_mesh.colors = _colors;
	}

	private void SetEmitting(bool on)
	{
		//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)
		EmissionModule emission = _motes.emission;
		if (((EmissionModule)(ref emission)).enabled != on)
		{
			((EmissionModule)(ref emission)).enabled = on;
		}
	}

	private static float TimeOfDayStrength()
	{
		if ((Object)(object)EnvMan.instance == (Object)null)
		{
			return 1f;
		}
		float dayFraction = EnvMan.instance.GetDayFraction();
		float num = Mathf.Clamp01(1f - Mathf.Abs(dayFraction - 0.5f) / 0.25f);
		num = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num * 3f));
		return Mathf.Lerp(1f, 0.75f, num);
	}

	private static Mesh CreateColumnMesh()
	{
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: 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_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Expected O, but got Unknown
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
		int num = 21;
		int num2 = Rows.Length * num;
		Vector3[] array = (Vector3[])(object)new Vector3[Layers.Length * num2];
		Vector3[] array2 = (Vector3[])(object)new Vector3[array.Length];
		Vector2[] array3 = (Vector2[])(object)new Vector2[array.Length];
		Vector2[] array4 = (Vector2[])(object)new Vector2[array.Length];
		Color[] array5 = (Color[])(object)new Color[array.Length];
		int[] array6 = new int[Layers.Length * (Rows.Length - 1) * 20 * 6];
		int num3 = 0;
		Vector3 val = default(Vector3);
		for (int i = 0; i < Layers.Length; i++)
		{
			Layer layer = Layers[i];
			for (int j = 0; j < Rows.Length; j++)
			{
				float num4 = Rows[j];
				float num5 = ((num4 < 1f) ? Mathf.Lerp(0.6f, 1f, num4) : Mathf.Exp((0f - (num4 - 1f)) / 40f));
				num5 *= Mathf.Clamp01((70f - num4) / 15f);
				for (int k = 0; k < num; k++)
				{
					float num6 = (float)k * (float)Math.PI * 2f / 20f;
					((Vector3)(ref val))..ctor(Mathf.Cos(num6), 0f, Mathf.Sin(num6));
					int num7 = i * num2 + j * num + k;
					array[num7] = val * layer.Radius + Vector3.up * num4;
					array2[num7] = val;
					array3[num7] = new Vector2((float)k / 20f * 2f, num4 / 8f);
					array4[num7] = new Vector2(layer.Sharpness, 0f);
					array5[num7] = new Color(1f, 1f, 1f, num5 * layer.Strength);
				}
			}
			for (int l = 0; l < Rows.Length - 1; l++)
			{
				for (int m = 0; m < 20; m++)
				{
					int num8 = i * num2 + l * num + m;
					int num9 = num8 + num;
					array6[num3++] = num8;
					array6[num3++] = num9;
					array6[num3++] = num8 + 1;
					array6[num3++] = num8 + 1;
					array6[num3++] = num9;
					array6[num3++] = num9 + 1;
				}
			}
		}
		Mesh val2 = new Mesh
		{
			name = "MonumentBeam",
			vertices = array,
			normals = array2,
			uv = array3,
			uv2 = array4,
			colors = array5,
			triangles = array6
		};
		val2.RecalculateBounds();
		return val2;
	}

	private static void AddMotes(Transform parent)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0028: 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_0045: 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_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Expected O, but got Unknown
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//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)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Motes");
		val.transform.SetParent(parent, false);
		ParticleSystem val2 = val.AddComponent<ParticleSystem>();
		val2.Stop(true, (ParticleSystemStopBehavior)0);
		MainModule main = val2.main;
		((MainModule)(ref main)).loop = true;
		((MainModule)(ref main)).playOnAwake = true;
		((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(6f);
		((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.08f, 0.16f);
		((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Color.white);
		((MainModule)(ref main)).maxParticles = 40;
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		EmissionModule emission = val2.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(4f);
		ShapeModule shape = val2.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)10;
		((ShapeModule)(ref shape)).radius = 0.7f;
		((ShapeModule)(ref shape)).rotation = new Vector3(90f, 0f, 0f);
		VelocityOverLifetimeModule velocityOverLifetime = val2.velocityOverLifetime;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)1;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(0f);
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(1.6f);
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(0f);
		NoiseModule noise = val2.noise;
		((NoiseModule)(ref noise)).enabled = true;
		((NoiseModule)(ref noise)).strength = MinMaxCurve.op_Implicit(0.25f);
		((NoiseModule)(ref noise)).frequency = 0.5f;
		Gradient val3 = new Gradient();
		val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(Color.white, 0f),
			new GradientColorKey(Color.white, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
		{
			new GradientAlphaKey(0f, 0f),
			new GradientAlphaKey(1f, 0.15f),
			new GradientAlphaKey(0f, 1f)
		});
		ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
		ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
		component.renderMode = (ParticleSystemRenderMode)0;
		((Renderer)component).sharedMaterial = _moteMaterial;
		((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)component).receiveShadows = false;
	}

	private static void EnsureTextures()
	{
		if (!_texturesReady && !((Object)(object)_columnMaterial == (Object)null))
		{
			_columnMaterial.mainTexture = (Texture)(object)MonumentTextures.CreateBeamTexture();
			_moteMaterial.mainTexture = (Texture)(object)MonumentTextures.CreateMoteTexture();
			_texturesReady = true;
		}
	}
}
internal static class MonumentClearance
{
	[HarmonyPatch(typeof(ZoneSystem), "PlaceVegetation")]
	private static class ClearAfterVegetation
	{
		private static void Postfix(Vector3 zoneCenterPos)
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			PortalMonument[] array = _generated.ToArray();
			foreach (PortalMonument portalMonument in array)
			{
				if (!((Object)(object)portalMonument == (Object)null) && Utils.DistanceXZ(((Component)portalMonument).transform.position, zoneCenterPos) < 120f)
				{
					ClearAbove(((Component)portalMonument).transform.position);
				}
			}
		}
	}

	private const float ColumnHalfWidth = 2.6f;

	private const float ColumnBottom = 0.3f;

	private const float ColumnTop = 40f;

	private const float NearbyDistance = 120f;

	private static readonly List<PortalMonument> _generated = new List<PortalMonument>();

	private static HashSet<int> _vegetationPrefabs;

	private static ZoneSystem _vegetationFrom;

	private static int _mask;

	public static void Track(PortalMonument monument)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)((Component)monument).GetComponent<Piece>() != (Object)null))
		{
			_generated.Add(monument);
			ClearAbove(((Component)monument).transform.position);
			((MonoBehaviour)monument).StartCoroutine(ClearAgainLater(monument));
		}
	}

	public static void Untrack(PortalMonument monument)
	{
		_generated.Remove(monument);
	}

	private static IEnumerator ClearAgainLater(PortalMonument monument)
	{
		bool dedicated = (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsDedicated();
		while (!dedicated && ((Object)(object)Player.m_localPlayer == (Object)null || Utils.DistanceXZ(((Component)Player.m_localPlayer).transform.position, ((Component)monument).transform.position) > 120f))
		{
			yield return (object)new WaitForSeconds(2f);
		}
		ClearAbove(((Component)monument).transform.position);
		yield return (object)new WaitForSeconds(2f);
		ClearAbove(((Component)monument).transform.position);
		yield return (object)new WaitForSeconds(4f);
		ClearAbove(((Component)monument).transform.position);
	}

	private static void ClearAbove(Vector3 basePosition)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: 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)
		if ((Object)(object)ZoneSystem.instance == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
		{
			return;
		}
		if (_mask == 0)
		{
			_mask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "vehicle" });
		}
		Physics.SyncTransforms();
		Vector3 val = basePosition + Vector3.up * 20.15f;
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(2.6f, 19.85f, 2.6f);
		HashSet<ZNetView> hashSet = new HashSet<ZNetView>();
		Collider[] array = Physics.OverlapBox(val, val2, Quaternion.identity, _mask, (QueryTriggerInteraction)1);
		for (int i = 0; i < array.Length; i++)
		{
			ZNetView componentInParent = ((Component)array[i]).GetComponentInParent<ZNetView>();
			if (!((Object)(object)componentInParent == (Object)null) && !hashSet.Contains(componentInParent) && componentInParent.GetZDO() != null && IsVegetation(componentInParent.GetZDO().GetPrefab()))
			{
				hashSet.Add(componentInParent);
				Logger.LogInfo((object)("Monument at (" + Mathf.RoundToInt(basePosition.x) + ", " + Mathf.RoundToInt(basePosition.z) + "): removed " + ((Object)componentInParent).name + " above it"));
				componentInParent.ClaimOwnership();
				ZNetScene.instance.Destroy(((Component)componentInParent).gameObject);
			}
		}
	}

	private static bool IsVegetation(int prefabHash)
	{
		ZoneSystem instance = ZoneSystem.instance;
		if (_vegetationPrefabs == null || (Object)(object)_vegetationFrom != (Object)(object)instance)
		{
			_vegetationFrom = instance;
			_vegetationPrefabs = new HashSet<int>();
			foreach (ZoneVegetation item in instance.m_vegetation)
			{
				if ((Object)(object)item.m_prefab != (Object)null)
				{
					_vegetationPrefabs.Add(StringExtensionMethods.GetStableHashCode(((Object)item.m_prefab).name));
				}
			}
		}
		return _vegetationPrefabs.Contains(prefabHash);
	}
}
internal static class MonumentCommands
{
	[HarmonyPatch(typeof(ZNet), "InternalCommand")]
	private static class RememberRemoteSender
	{
		private static void Prefix(ZRpc rpc)
		{
			_remoteSender = rpc;
		}

		private static void Finalizer()
		{
			_remoteSender = null;
		}
	}

	private static readonly MethodInfo GenerateOne = AccessTools.Method(typeof(ZoneSystem), "GenerateLocationsTimeSliced", new Type[3]
	{
		typeof(ZoneLocation),
		typeof(Stopwatch),
		typeof(ZPackage)
	}, (Type[])null);

	private static readonly MethodInfo SpawnLocation = AccessTools.Method(typeof(ZoneSystem), "SpawnLocation", new Type[7]
	{
		typeof(ZoneLocation),
		typeof(int),
		typeof(Vector3),
		typeof(Quaternion),
		typeof(SpawnMode),
		typeof(List<GameObject>),
		typeof(bool)
	}, (Type[])null);

	private static readonly FieldRef<ZoneSystem, Coroutine> GeneratingNow = AccessTools.FieldRefAccess<ZoneSystem, Coroutine>("m_generateLocationsCoroutine");

	private static bool _generating;

	private static ZRpc _remoteSender;

	private const float RemoveReach = 10f;

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

	private static Minimap _shownOn;

	private static Sprite _brightSprite;

	private static Sprite _dimSprite;

	public static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_0020: 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_004b: Expected O, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		//IL_0092: 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_00bd: Expected O, but got Unknown
		//IL_00b8: 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_00e3: Expected O, but got Unknown
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("pm_help", "Portal Monuments: list the Portal Monuments commands", new ConsoleEvent(Help), false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		new ConsoleCommand("pm_generate", "Portal Monuments: add generated monuments to unexplored areas of this world", new ConsoleEvent(Generate), false, false, true, false, false, false, (ConsoleOptionsFetcher)null, false, true, false);
		new ConsoleCommand("pm_place", "[x z] Portal Monuments: place a generated monument here (or at x z)", new ConsoleEvent(Place), true, false, true, false, false, false, (ConsoleOptionsFetcher)null, false, true, false);
		new ConsoleCommand("pm_show", "Portal Monuments: show/hide every monument on the map", new ConsoleEvent(Show), true, false, true, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		new ConsoleCommand("pm_remove", "Portal Monuments: remove the generated monument you're standing at", new ConsoleEvent(Remove), true, false, true, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		new ConsoleCommand("pm_count", "Portal Monuments: how many monuments this world has", new ConsoleEvent(Count), false, false, true, false, false, false, (ConsoleOptionsFetcher)null, false, true, false);
	}

	private static void Help(ConsoleEventArgs args)
	{
		args.Context.AddString("Portal Monuments commands (F5 console):");
		args.Context.AddString("  pm_help - this list (also /pm_help in chat)");
		args.Context.AddString("  pm_count - how many monuments this world has");
		args.Context.AddString("  pm_show - show/hide every monument on the map (devcommands; single-player or host)");
		args.Context.AddString("  pm_place [x z] - place a generated monument here or at x z (devcommands; single-player or host)");
		args.Context.AddString("  pm_remove - remove the generated monument you're standing at (devcommands; single-player or host)");
		args.Context.AddString("  pm_generate - add generated monuments to unexplored areas of an older world (admin)");
	}

	private static void Print(ConsoleEventArgs args, string text)
	{
		Print(args, text, _remoteSender);
	}

	private static void Print(ConsoleEventArgs args, string text, ZRpc sender)
	{
		if (sender != null && (Object)(object)ZNet.instance != (Object)null)
		{
			ZNet.instance.RemotePrint(sender, text);
		}
		else
		{
			Terminal context = args.Context;
			if (context != null)
			{
				context.AddString(text);
			}
		}
		Logger.LogInfo((object)text);
	}

	private static bool Ready(ConsoleEventArgs args, out ZoneSystem zoneSystem, out ZoneLocation location)
	{
		zoneSystem = ZoneSystem.instance;
		location = (((Object)(object)zoneSystem != (Object)null) ? MonumentLocation.Find(zoneSystem) : null);
		if (location == null)
		{
			Print(args, "Portal Monuments: no world loaded, or the monument location isn't registered.");
		}
		return location != null;
	}

	private static void Generate(ConsoleEventArgs args)
	{
		if (Ready(args, out var zoneSystem, out var location))
		{
			if (_generating || GeneratingNow.Invoke(zoneSystem) != null)
			{
				Print(args, "Portal Monuments: locations are already being generated, try again in a moment.");
				return;
			}
			Print(args, "Portal Monuments: generating monuments in unexplored areas...");
			((MonoBehaviour)zoneSystem).StartCoroutine(RunGenerate(args, zoneSystem, location, _remoteSender));
		}
	}

	private static IEnumerator RunGenerate(ConsoleEventArgs args, ZoneSystem zoneSystem, ZoneLocation location, ZRpc sender)
	{
		_generating = true;
		int before = MonumentLocation.GetInstances(zoneSystem).Count;
		MonumentLocation.ApplyConfig(location);
		yield return (IEnumerator)GenerateOne.Invoke(zoneSystem, new object[3]
		{
			location,
			Stopwatch.StartNew(),
			(object)new ZPackage()
		});
		_generating = false;
		int num = MonumentLocation.GetInstances(zoneSystem).Count - before;
		if (num > 0)
		{
			MonumentLocation.SendPositionsToPlayers(zoneSystem);
		}
		string text = ((MonumentLargeWorlds.LastRadius > 10000f) ? (" (" + MonumentLargeWorlds.LastAdded + " past the vanilla world edge; world reaches about " + Mathf.RoundToInt(MonumentLargeWorlds.LastRadius) + " m)") : "");
		Print(args, "Portal Monuments: added " + num + text + ". " + MonumentLocation.Summary(zoneSystem) + ". They're saved with the next world save.", sender);
	}

	private static void Place(ConsoleEventArgs args)
	{
		//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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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_00c7: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: 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_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: 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_014c: 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_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: 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_0272: Unknown result type (might be due to invalid IL or missing references)
		if (!Ready(args, out var zoneSystem, out var location))
		{
			return;
		}
		Vector3 position = default(Vector3);
		if (args.Length >= 3 && float.TryParse(args[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(args[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
		{
			((Vector3)(ref position))..ctor(result, 0f, result2);
		}
		else
		{
			if (!((Object)(object)Player.m_localPlayer != (Object)null))
			{
				Print(args, "Usage: pm_place x z (on a dedicated server, the position is needed)");
				return;
			}
			position = ((Component)Player.m_localPlayer).transform.position;
		}
		Vector2s zone = ZoneSystem.GetZone(position);
		if (zoneSystem.m_locationInstances.ContainsKey(zone))
		{
			Print(args, "Portal Monuments: this 64 m area already has a location. Try a bit further away.");
			return;
		}
		Vector3 zonePos = ZoneSystem.GetZonePos(zone);
		position.x = Mathf.Clamp(position.x, zonePos.x - 27f, zonePos.x + 27f);
		position.z = Mathf.Clamp(position.z, zonePos.z - 27f, zonePos.z + 27f);
		if (!MonumentLocation.IsZoneGenerated(zoneSystem, zone))
		{
			position.y = MonumentLocation.RealHeight(position.x, position.z);
			MonumentLocation.RegisterInstance(zoneSystem, location, position, placed: false);
			MonumentLocation.SendPositionsToPlayers(zoneSystem);
			Print(args, "Portal Monuments: monument booked at (" + Mathf.RoundToInt(position.x) + ", " + Mathf.RoundToInt(position.z) + "); it appears when someone gets close.");
			return;
		}
		float y = default(float);
		if (!zoneSystem.IsZoneLoaded(zone) || !zoneSystem.GetGroundHeight(position, ref y))
		{
			Print(args, "Portal Monuments: that area isn't loaded right now; go there first.");
			return;
		}
		position.y = y;
		MonumentLocation.RegisterInstance(zoneSystem, location, position, placed: true);
		Quaternion val = Quaternion.Euler(0f, (float)Random.Range(0, 16) * 22.5f, 0f);
		SpawnLocation.Invoke(zoneSystem, new object[7]
		{
			location,
			Random.Range(0, 99999),
			position,
			val,
			(object)(SpawnMode)0,
			new List<GameObject>(),
			false
		});
		MonumentLocation.SendPositionsToPlayers(zoneSystem);
		Print(args, "Portal Monuments: monument placed at (" + Mathf.RoundToInt(position.x) + ", " + Mathf.RoundToInt(position.z) + ").");
	}

	private static void Remove(ConsoleEventArgs args)
	{
		//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)
		//IL_005d: 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_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		if (!Ready(args, out var zoneSystem, out var _))
		{
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
		{
			return;
		}
		Vector3 position = ((Component)localPlayer).transform.position;
		ZDO val = null;
		float num = 10f;
		foreach (ZDO item in MonumentRegistry.FindSaved("PortalMonument_Core"))
		{
			float num2 = Utils.DistanceXZ(item.GetPosition(), position);
			if (num2 < num)
			{
				num = num2;
				val = item;
			}
		}
		if (val == null)
		{
			bool flag = false;
			foreach (ZDO item2 in MonumentRegistry.FindSaved("piece_portal_monument"))
			{
				if (Utils.DistanceXZ(item2.GetPosition(), position) < 10f)
				{
					flag = true;
				}
			}
			Print(args, flag ? "Portal Monuments: that's a built monument; remove it with the hammer." : ("Portal Monuments: no generated monument within " + Mathf.RoundToInt(10f) + " m. Stand on it and try again."));
			return;
		}
		ZNetView val2 = ZNetScene.instance.FindInstance(val);
		if ((Object)(object)val2 == (Object)null)
		{
			Print(args, "Portal Monuments: that monument isn't loaded right now; go closer.");
			return;
		}
		Vector3 position2 = val.GetPosition();
		val2.ClaimOwnership();
		ZNetScene.instance.Destroy(((Component)val2).gameObject);
		ForgetLocation(zoneSystem, position2);
		MonumentLocation.SendPositionsToPlayers(zoneSystem);
		Print(args, "Portal Monuments: removed the monument at (" + Mathf.RoundToInt(position2.x) + ", " + Mathf.RoundToInt(position2.z) + "). Use pm_place to put one somewhere else.");
	}

	private static void ForgetLocation(ZoneSystem zoneSystem, Vector3 position)
	{
		//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_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		List<Vector2s> list = new List<Vector2s>();
		foreach (KeyValuePair<Vector2s, LocationInstance> locationInstance in zoneSystem.m_locationInstances)
		{
			if (Match(locationInstance.Value))
			{
				list.Add(locationInstance.Key);
			}
		}
		foreach (Vector2s item in list)
		{
			zoneSystem.m_locationInstances.Remove(item);
		}
		foreach (List<LocationInstance> value in zoneSystem.m_locationIDCache.Values)
		{
			value.RemoveAll(Match);
		}
		foreach (List<LocationInstance> value2 in zoneSystem.m_locationGroupCache.Values)
		{
			value2.RemoveAll(Match);
		}
		foreach (List<LocationInstance> value3 in zoneSystem.m_locationMaxGroupCache.Values)
		{
			value3.RemoveAll(Match);
		}
		bool Match(LocationInstance l)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			if (MonumentLocation.IsOurs(l.m_location))
			{
				return Utils.DistanceXZ(l.m_position, position) < 10f;
			}
			return false;
		}
	}

	private static Vector3? FindSpawnMonument(ZoneSystem zoneSystem, List<LocationInstance> instances)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_0057: Unknown result type (might be due to invalid IL or missing references)
		if (!MonumentLocation.FindSpawnCircle(zoneSystem, out var circle))
		{
			return null;
		}
		MonumentLocation.GetSpawnRange(circle, out var _, out var max);
		Vector3? result = null;
		foreach (LocationInstance instance in instances)
		{
			float num = Utils.DistanceXZ(instance.m_position, circle.m_position);
			if (num <= max)
			{
				max = num;
				result = instance.m_position;
			}
		}
		return result;
	}

	private static void Count(ConsoleEventArgs args)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		if (!Ready(args, out var zoneSystem, out var _))
		{
			return;
		}
		List<LocationInstance> instances = MonumentLocation.GetInstances(zoneSystem);
		int num = 0;
		foreach (LocationInstance item in instances)
		{
			if (!item.m_placed)
			{
				num++;
			}
		}
		int count = MonumentRegistry.FindSaved("PortalMonument_Core").Count;
		int count2 = MonumentRegistry.FindSaved("piece_portal_monument").Count;
		Vector3? val = FindSpawnMonument(zoneSystem, instances);
		Print(args, "Generated: " + instances.Count + " planned (limit " + MonumentLocation.Count.Value + ", spacing " + Mathf.RoundToInt(MonumentLocation.Spacing.Value) + " m), " + count + " spawned so far, " + num + " in unvisited areas");
		Print(args, "Built: " + count2 + " | Spawn monument: " + (val.HasValue ? ("yes (" + Mathf.RoundToInt(val.Value.x) + ", " + Mathf.RoundToInt(val.Value.z) + ")") : "no"));
	}

	private static void Show(ConsoleEventArgs args)
	{
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: 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_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		if (!Ready(args, out var zoneSystem, out var _))
		{
			return;
		}
		Minimap instance = Minimap.instance;
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		if ((Object)(object)_shownOn == (Object)(object)instance && _shownPins.Count > 0)
		{
			foreach (PinData shownPin in _shownPins)
			{
				instance.RemovePin(shownPin);
			}
			_shownPins.Clear();
			Print(args, "Portal Monuments: monuments hidden from the map.");
			return;
		}
		_shownPins.Clear();
		_shownOn = instance;
		if ((Object)(object)_brightSprite == (Object)null)
		{
			_brightSprite = MonumentTextures.CreatePinSprite();
		}
		if ((Object)(object)_dimSprite == (Object)null)
		{
			_dimSprite = MonumentTextures.CreatePinSprite(dim: true);
		}
		List<LocationInstance> instances = MonumentLocation.GetInstances(zoneSystem);
		Vector3? spawn = FindSpawnMonument(zoneSystem, instances);
		foreach (ZDO item in MonumentRegistry.FindSaved("PortalMonument_Core"))
		{
			AddPin(instance, item.GetPosition(), _brightSprite, spawn);
		}
		foreach (ZDO item2 in MonumentRegistry.FindSaved("piece_portal_monument"))
		{
			AddPin(instance, item2.GetPosition(), _brightSprite, null, "built");
		}
		foreach (LocationInstance item3 in instances)
		{
			if (!item3.m_placed)
			{
				AddPin(instance, item3.m_position, _dimSprite, spawn);
			}
		}
		Print(args, "Portal Monuments: " + _shownPins.Count + " monuments shown on the map (pm_show again to hide).");
	}

	private static void AddPin(Minimap map, Vector3 position, Sprite sprite, Vector3? spawn, string label = "")
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		if (spawn.HasValue && Utils.DistanceXZ(position, spawn.Value) < 3f)
		{
			label = "spawn";
		}
		PinData val = map.AddPin(position, (PinType)6, label, false, false, 0L, default(PlatformUserID));
		val.m_icon = sprite;
		_shownPins.Add(val);
	}
}
internal static class MonumentCore
{
	private struct Ring
	{
		public float Inner;

		public float Outer;

		public float Top;

		public Ring(float inner, float outer, float top)
		{
			Inner = inner;
			Outer = outer;
			Top = top;
		}
	}

	private class MeshBuilder
	{
		private readonly List<Vector3> _vertices = new List<Vector3>();

		private readonly List<Vector2> _uvs = new List<Vector2>();

		private readonly List<int> _triangles = new List<int>();

		public void AddSectorRing(float inner, float outer, float top, float bottom, float angleFrom, float angleTo, int segments, Random random, bool bottomFace = false)
		{
			//IL_0039: 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_003e: 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_0083: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = (Vector2)((random != null) ? new Vector2((float)random.NextDouble(), (float)random.NextDouble()) : Vector2.zero);
			bool flag = angleTo - angleFrom >= 6.2830853f;
			int count = _vertices.Count;
			for (int i = 0; i <= segments; i++)
			{
				Vector3 val2 = Point(inner, AngleAt(i), top);
				Vector3 val3 = Point(outer, AngleAt(i), top);
				AddVertex(val2, new Vector2(val2.x, val2.z) * 0.5f + val);
				AddVertex(val3, new Vector2(val3.x, val3.z) * 0.5f + val);
			}
			for (int j = 0; j < segments; j++)
			{
				int num = count + j * 2;
				int c = num + 1;
				int b = num + 2;
				int num2 = num + 3;
				AddTriangle(num, num2, c);
				AddTriangle(num, b, num2);
			}
			if (bottomFace)
			{
				int count2 = _vertices.Count;
				for (int k = 0; k <= segments; k++)
				{
					Vector3 val4 = Point(inner, AngleAt(k), bottom);
					Vector3 val5 = Point(outer, AngleAt(k), bottom);
					AddVertex(val4, new Vector2(val4.x, val4.z) * 0.5f + val);
					AddVertex(val5, new Vector2(val5.x, val5.z) * 0.5f + val);
				}
				for (int l = 0; l < segments; l++)
				{
					int num3 = count2 + l * 2;
					int b2 = num3 + 1;
					int c2 = num3 + 2;
					int num4 = num3 + 3;
					AddTriangle(num3, b2, num4);
					AddTriangle(num3, num4, c2);
				}
			}
			AddWall(outer, top, bottom, segments, AngleAt, Point, val, facesOut: true);
			if (inner > 0f)
			{
				AddWall(inner, top, bottom, segments, AngleAt, Point, val, facesOut: false);
			}
			if (!flag)
			{
				AddEnd(inner, outer, top, bottom, angleFrom, Point, val, isStart: true);
				AddEnd(inner, outer, top, bottom, angleTo, Point, val, isStart: false);
			}
			float AngleAt(int num5)
			{
				return Mathf.Lerp(angleFrom, angleTo, (float)num5 / (float)segments);
			}
			static Vector3 Point(float radius, float angle, float y)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				return new Vector3(Mathf.Cos(angle) * radius, y, Mathf.Sin(angle) * radius);
			}
		}

		private void AddWall(float radius, float top, float bottom, int segments, Func<int, float> angleAt, Func<float, float, float, Vector3> point, Vector2 offset, bool facesOut)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			int count = _vertices.Count;
			for (int i = 0; i <= segments; i++)
			{
				float num = angleAt(i) * radius * 0.5f;
				AddVertex(point(radius, angleAt(i), top), new Vector2(num, top * 0.5f) + offset);
				AddVertex(point(radius, angleAt(i), bottom), new Vector2(num, bottom * 0.5f) + offset);
			}
			for (int j = 0; j < segments; j++)
			{
				int num2 = count + j * 2;
				int num3 = num2 + 1;
				int num4 = num2 + 2;
				int num5 = num2 + 3;
				if (facesOut)
				{
					AddTriangle(num2, num4, num3);
					AddTriangle(num4, num5, num3);
				}
				else
				{
					AddTriangle(num2, num3, num4);
					AddTriangle(num4, num3, num5);
				}
			}
		}

		private void AddEnd(float inner, float outer, float top, float bottom, float angle, Func<float, float, float, Vector3> point, Vector2 offset, bool isStart)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002b: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			int count = _vertices.Count;
			AddVertex(point(inner, angle, top), new Vector2(inner, top) * 0.5f + offset);
			AddVertex(point(outer, angle, top), new Vector2(outer, top) * 0.5f + offset);
			AddVertex(point(outer, angle, bottom), new Vector2(outer, bottom) * 0.5f + offset);
			AddVertex(point(inner, angle, bottom), new Vector2(inner, bottom) * 0.5f + offset);
			if (isStart)
			{
				AddTriangle(count, count + 1, count + 2);
				AddTriangle(count, count + 2, count + 3);
			}
			else
			{
				AddTriangle(count, count + 2, count + 1);
				AddTriangle(count, count + 3, count + 2);
			}
		}

		private void AddVertex(Vector3 position, Vector2 uv)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			_vertices.Add(position);
			_uvs.Add(uv);
		}

		private void AddTriangle(int a, int b, int c)
		{
			_triangles.Add(a);
			_triangles.Add(b);
			_triangles.Add(c);
		}

		public Mesh ToMesh(string name)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			Mesh val = new Mesh
			{
				name = name
			};
			if (_vertices.Count > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.SetVertices(_vertices);
			val.SetUVs(0, _uvs);
			val.SetTriangles(_triangles, 0);
			val.RecalculateNormals();
			val.RecalculateTangents();
			val.RecalculateBounds();
			return val;
		}
	}

	public const string PrefabName = "PortalMonument_Core";

	public const string PatternName = "FloorPattern";

	public const string LightName = "BlueGlow";

	public const string FoundationColliderName = "FoundationCollider";

	private const float DaisRadius = 1.25f;

	private const float DaisTop = 0.24f;

	private static readonly Ring[] Rings = new Ring[2]
	{
		new Ring(1.25f, 1.75f, 0.16f),
		new Ring(1.75f, 2.3f, 0.08f)
	};

	private const float CurbWidth = 0.16f;

	private const float CurbRaise = 0.02f;

	private const float CurbLengthMin = 0.2f;

	private const float CurbLengthMax = 0.45f;

	private const float PavingLengthMin = 0.4f;

	private const float PavingLengthMax = 0.9f;

	private const float Gap = 0.025f;

	private const float Sink = 0.05f;

	private const float FoundationDepth = 1f;

	private const float FoundationThickness = 0.3f;

	private const float FoundationLengthMin = 0.6f;

	private const float FoundationLengthMax = 1.1f;

	private const float FoundationShade = 0.8f;

	private const double CrackedChance = 0.2;

	private const float StoneTextureGray = 0.51f;

	private const float GraustenTextureGray = 0.417f;

	private static readonly Color StoneColorAdjust = new Color(1.04f, 1.08f, 1.14f);

	public const float FootprintRadius = 2.3f;

	private const float LightHeight = 3.5f;

	private const float LightIntensity = 3f;

	private const float LightRange = 12f;

	private const float GlowBrightness = 5f;

	private const float HumMinDistance = 3f;

	private const float HumMaxDistance = 14f;

	public static EffectList ActivateSound;

	private static Material _patternMaterial;

	private static bool _texturesReady;

	public static GameObject Create()
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = PrefabManager.Instance.CreateEmptyPrefab("PortalMonument_Core", true);
		Object.DestroyImmediate((Object)(object)obj.GetComponent<MeshRenderer>());
		Object.DestroyImmediate((Object)(object)obj.GetComponent<MeshFilter>());
		Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
		obj.AddComponent<PortalMonument>();
		AddStonework(obj);
		Material val = FindAdditiveMaterial();
		_patternMaterial = new Material(val);
		_patternMaterial.SetColor("_TintColor", new Color(0.5f, 0.5f, 0.5f, 0.5f) * 5f);
		float radius = 1.0250001f;
		AddMesh(obj, "FloorPattern", CreateDisc(radius, 64), _patternMaterial, new Vector3(0f, 0.255f, 0f), shadows: false).SetActive(false);
		AddBlueLight(obj);
		MonumentBeam.Create(obj, val, new Vector3(0f, 0.24f, 0f));
		AddAmbientSound(obj);
		obj.GetComponent<ZNetView>().m_distant = true;
		ActivateSound = FindActivateSound();
		return obj;
	}

	public static void EnsureTextures()
	{
		if (!_texturesReady && !((Object)(object)_patternMaterial == (Object)null))
		{
			_patternMaterial.mainTexture = (Texture)(object)MonumentTextures.CreatePattern();
			_texturesReady = true;
		}
	}

	private static void AddStonework(GameObject root)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Expected O, but got Unknown
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Expected O, but got Unknown
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_038c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
		Material val = new Material(FindGraustenMaterial("Grausten_mat"));
		MakeSolid(val);
		Material val2 = new Material(FindGraustenMaterial("Grausten_Broken_mat"));
		MakeSolid(val2);
		Color val3 = ((Renderer)((Component)Cache.GetPrefab<GameObject>("stone_floor_2x2").transform.Find("new/high")).GetComponent<MeshRenderer>()).sharedMaterial.color * 1.2230216f * StoneColorAdjust;
		val3.a = 1f;
		val.color = val3;
		val2.color = val3;
		Material val4 = new Material(val);
		val4.SetColor("_Color", new Color(0.3f, 0.3f, 0.32f));
		MeshBuilder meshBuilder = new MeshBuilder();
		MeshBuilder meshBuilder2 = new MeshBuilder();
		MeshBuilder meshBuilder3 = new MeshBuilder();
		MeshBuilder meshBuilder4 = new MeshBuilder();
		Random random = new Random(4242);
		Random crackRandom = new Random(777);
		float num = 1.09f;
		meshBuilder4.AddSectorRing(0f, num - 0.025f, 0.24f, -0.05f, 0f, (float)Math.PI * 2f, 64, random);
		AddStoneRow(meshBuilder, meshBuilder2, crackRandom, num, 1.25f, 0.26f, -0.05f, 0.2f, 0.45f, random);
		AddGrout(meshBuilder3, 1.25f, 0.24f);
		AddTierCollider(root, "DaisCollider", 1.25f, 0.24f);
		for (int i = 0; i < Rings.Length; i++)
		{
			Ring ring = Rings[i];
			float num2 = ring.Outer - 0.16f;
			AddStoneRow(meshBuilder, meshBuilder2, crackRandom, ring.Inner + 0.025f, num2 - 0.025f, ring.Top, ring.Top - 0.06f, 0.4f, 0.9f, random);
			AddStoneRow(meshBuilder, meshBuilder2, crackRandom, num2, ring.Outer, ring.Top + 0.02f, -0.05f, 0.2f, 0.45f, random);
			AddGrout(meshBuilder3, ring.Outer, ring.Top);
			AddTierCollider(root, "RingCollider" + i, ring.Outer, ring.Top);
		}
		MeshBuilder meshBuilder5 = new MeshBuilder();
		Random random2 = new Random(1234);
		float num3 = 2f;
		float num4 = 0.475f;
		for (int j = 0; j < 2; j++)
		{
			float top = -0.05f - (float)j * num4 - 0.025f;
			float bottom = -0.05f - (float)(j + 1) * num4;
			AddStoneRow(meshBuilder5, meshBuilder5, random2, num3, 2.3f, top, bottom, 0.6f, 1.1f, random2, bottomFace: true);
		}
		meshBuilder3.AddSectorRing(0f, num3 - 0.02f, -0.05f, -1f, 0f, (float)Math.PI * 2f, 64, null, bottomFace: true);
		Material val5 = new Material(val);
		Color color = val3 * 0.8f;
		color.a = 1f;
		val5.color = color;
		AddFoundationCollider(root);
		AddMesh(root, "Stones", meshBuilder.ToMesh("MonumentStones"), val, Vector3.zero, shadows: true);
		AddMesh(root, "Foundation", meshBuilder5.ToMesh("MonumentFoundation"), val5, Vector3.zero, shadows: true);
		AddMesh(root, "CrackedStones", meshBuilder2.ToMesh("MonumentCrackedStones"), val2, Vector3.zero, shadows: true);
		AddMesh(root, "Grout", meshBuilder3.ToMesh("MonumentGrout"), val4, Vector3.zero, shadows: true);
		AddMesh(root, "CenterStone", meshBuilder4.ToMesh("MonumentCenterStone"), val, Vector3.zero, shadows: true);
	}

	private static void AddStoneRow(MeshBuilder plain, MeshBuilder cracked, Random crackRandom, float inner, float outer, float top, float bottom, float lengthMin, float lengthMax, Random random, bool bottomFace = false)
	{
		float num = (inner + outer) / 2f;
		float num2 = (float)Math.PI * 2f * num;
		List<float> list = new List<float>();
		float num3 = 0f;
		while (true)
		{
			float num4 = Mathf.Lerp(lengthMin, lengthMax, (float)random.NextDouble());
			if (num3 + num4 + 0.025f > num2)
			{
				break;
			}
			list.Add(num4);
			num3 += num4 + 0.025f;
		}
		float num5 = (num2 - (float)list.Count * 0.025f) / list.Sum();
		float num6 = (float)random.NextDouble() * (float)Math.PI * 2f;
		foreach (float item in list)
		{
			float num7 = item * num5 / num;
			int segments = Mathf.Max(2, Mathf.CeilToInt(num7 / ((float)Math.PI / 36f)));
			((crackRandom.NextDouble() < 0.2) ? cracked : plain).AddSectorRing(inner, outer, top, bottom, num6, num6 + num7, segments, random, bottomFace);
			num6 += num7 + 0.025f / num;
		}
	}

	private static void AddGrout(MeshBuilder grout, float radius, float top)
	{
		grout.AddSectorRing(0f, radius - 0.02f, top - 0.015f, -0.05f, 0f, (float)Math.PI * 2f, 64, null);
	}

	private static void AddTierCollider(GameObject root, string name, float radius, float top)
	{
		//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_0016: 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_003d: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name)
		{
			layer = LayerMask.NameToLayer("piece")
		};
		val.transform.SetParent(root.transform, false);
		val.transform.localPosition = new Vector3(0f, -0.05f, 0f);
		MeshCollider obj = val.AddComponent<MeshCollider>();
		obj.sharedMesh = CreateCylinder(radius, top + 0.05f, 32);
		obj.convex = true;
	}

	private static void AddFoundationCollider(GameObject root)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("FoundationCollider")
		{
			layer = LayerMask.NameToLayer("piece")
		};
		val.transform.SetParent(root.transform, false);
		val.transform.localPosition = new Vector3(0f, -1f, 0f);
		MeshCollider obj = val.AddComponent<MeshCollider>();
		obj.sharedMesh = CreateCylinder(2.3f, 0.95f, 32);
		obj.convex = true;
	}

	private static void MakeSolid(Material material)
	{
		if (material.HasProperty("_Cutoff"))
		{
			material.SetFloat("_Cutoff", 0f);
		}
		material.DisableKeyword("_ALPHATEST_ON");
	}

	private static Material FindGraustenMaterial(string materialName)
	{
		return Cache.GetPrefab<GameObject>("Piece_grausten_floor_2x2").GetComponentsInChildren<MeshRenderer>(true).SelectMany((MeshRenderer r) => ((Renderer)r).sharedMaterials)
			.First((Material m) => (Object)(object)m != (Object)null && ((Object)m).name == materialName);
	}

	private static Material FindAdditiveMaterial()
	{
		return Cache.GetPrefab<GameObject>("portal_wood").GetComponentsInChildren<ParticleSystemRenderer>(true).SelectMany((ParticleSystemRenderer r) => ((Renderer)r).sharedMaterials)
			.First((Material m) => (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null && ((Object)m.shader).name == "Legacy Shaders/Particles/Additive");
	}

	private static GameObject AddMesh(GameObject root, string name, Mesh mesh, Material material, Vector3 position, bool shadows)
	{
		//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_0018: 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_0025: 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_0054: Expected O, but got Unknown
		GameObject val = new GameObject(name);
		val.transform.SetParent(root.transform, false);
		val.transform.localPosition = position;
		val.AddComponent<MeshFilter>().sharedMesh = mesh;
		MeshRenderer obj = val.AddComponent<MeshRenderer>();
		((Renderer)obj).sharedMaterial = material;
		((Renderer)obj).shadowCastingMode = (ShadowCastingMode)(shadows ? 1 : 0);
		((Renderer)obj).receiveShadows = shadows;
		return val;
	}

	private static Mesh CreateCylinder(float radius, float height, int segments)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: 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_0179: Expected O, but got Unknown
		Vector3[] array = (Vector3[])(object)new Vector3[1 + segments + segments * 2];
		List<int> list = new List<int>();
		array[0] = new Vector3(0f, height, 0f);
		for (int i = 0; i < segments; i++)
		{
			float num = (float)i * (float)Math.PI * 2f / (float)segments;
			array[1 + i] = new Vector3(Mathf.Cos(num) * radius, height, Mathf.Sin(num) * radius);
			list.Add(0);
			list.Add(1 + (i + 1) % segments);
			list.Add(1 + i);
		}
		int num2 = 1 + segments;
		Vector3 val = default(Vector3);
		for (int j = 0; j < segments; j++)
		{
			float num3 = (float)j * (float)Math.PI * 2f / (float)segments;
			((Vector3)(ref val))..ctor(Mathf.Cos(num3), 0f, Mathf.Sin(num3));
			array[num2 + j] = val * radius + Vector3.up * height;
			array[num2 + segments + j] = val * radius;
			int num4 = (j + 1) % segments;
			list.Add(num2 + j);
			list.Add(num2 + num4);
			list.Add(num2 + segments + j);
			list.Add(num2 + num4);
			list.Add(num2 + segments + num4);
			list.Add(num2 + segments + j);
		}
		Mesh val2 = new Mesh
		{
			name = "MonumentCollider",
			vertices = array,
			triangles = list.ToArray()
		};
		val2.RecalculateNormals();
		return val2;
	}

	private static Mesh CreateDisc(float radius, int segments)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//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_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: 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_0174: Expected O, but got Unknown
		Vector3[] array = (Vector3[])(object)new Vector3[segments * 3];
		Vector2[] array2 = (Vector2[])(object)new Vector2[segments * 3];
		int[] array3 = new int[segments * 3];
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(0.5f, 0.5f);
		for (int i = 0; i < segments; i++)
		{
			float num = (float)i * (float)Math.PI * 2f / (float)segments;
			float num2 = (float)(i + 1) * (float)Math.PI * 2f / (float)segments;
			int num3 = i * 3;
			array[num3] = Vector3.zero;
			array[num3 + 1] = new Vector3(Mathf.Cos(num) * radius, 0f, Mathf.Sin(num) * radius);
			array[num3 + 2] = new Vector3(Mathf.Cos(num2) * radius, 0f, Mathf.Sin(num2) * radius);
			array2[num3] = val;
			array2[num3 + 1] = new Vector2(Mathf.Cos(num), Mathf.Sin(num)) * 0.5f + val;
			array2[num3 + 2] = new Vector2(Mathf.Cos(num2), Mathf.Sin(num2)) * 0.5f + val;
			array3[num3] = num3;
			array3[num3 + 1] = num3 + 2;
			array3[num3 + 2] = num3 + 1;
		}
		Mesh val2 = new Mesh
		{
			name = "MonumentDisc",
			vertices = array,
			uv = array2,
			triangles = array3
		};
		val2.RecalculateNormals();
		return val2;
	}

	public static void SetSweep(Color[] colors, float progress, float softness)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		int num = colors.Length / 3;
		Color val = default(Color);
		for (int i = 0; i < num; i++)
		{
			float num2 = (float)(num - 1 - i) / (float)num;
			float num3 = Mathf.Clamp01((progress * (1f + softness) - num2) / softness);
			((Color)(ref val))..ctor(num3, num3, num3, num3);
			colors[i * 3] = (colors[i * 3 + 1] = (colors[i * 3 + 2] = val));
		}
	}

	private static void AddBlueLight(GameObject root)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("BlueGlow");
		val.SetActive(false);
		val.transform.SetParent(root.transform, false);
		val.transform.localPosition = new Vector3(0f, 3.5f, 0f);
		Light obj = val.AddComponent<Light>();
		obj.type = (LightType)2;
		obj.color = new Color(0.2f, 0.5f, 1f);
		obj.intensity = 3f;
		obj.range = 12f;
		obj.shadows = (LightShadows)0;
	}

	private static EffectList FindActivateSound()
	{
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		//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_00b6: Expected O, but got Unknown
		GameObject val = Cache.GetPrefab<GameObject>("guard_stone").GetComponent<PrivateArea>().m_activateEffect.m_effectPrefabs.Select((EffectData e) => e.m_prefab).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && (Object)(object)p.GetComponentInChildren<ZSFX>(true) != (Object)null));
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		GameObject val2 = PrefabManager.Instance.CreateClonedPrefab("PortalMonument_ActivateSfx", val);
		StripVisuals(val2.transform);
		PrefabManager.Instance.AddPrefab(new CustomPrefab(val2, false));
		EffectList val3 = new EffectList();
		val3.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
		{
			new EffectData
			{
				m_prefab = val2
			}
		};
		return val3;
	}

	private static void StripVisuals(Transform t)
	{
		for (int num = t.childCount - 1; num >= 0; num--)
		{
			Transform child = t.GetChild(num);
			if ((Object)(object)((Component)child).GetComponentInChildren<AudioSource>(true) == (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)child).gameObject);
			}
			else
			{
				StripVisuals(child);
			}
		}
		LightFlicker[] components = ((Component)t).GetComponents<LightFlicker>();
		for (int i = 0; i < components.Length; i++)
		{
			Object.DestroyImmediate((Object)(object)components[i]);
		}
		Light[] components2 = ((Component)t).GetComponents<Light>();
		for (int i = 0; i < components2.Length; i++)
		{
			Object.DestroyImmediate((Object)(object)components2[i]);
		}
		ParticleSystemRenderer[] components3 = ((Component)t).GetComponents<ParticleSystemRenderer>();
		for (int i = 0; i < components3.Length; i++)
		{
			Object.DestroyImmediate((Object)(object)components3[i]);
		}
		ParticleSystem[] components4 = ((Component)t).GetComponents<ParticleSystem>();
		for (int i = 0; i < components4.Length; i++)
		{
			Object.DestroyImmediate((Object)(object)components4[i]);
		}
		MeshRenderer[] components5 = ((Component)t).GetComponents<MeshRenderer>();
		for (int i = 0; i < components5.Length; i++)
		{
			Object.DestroyImmediate((Object)(object)components5[i]);
		}
		MeshFilter[] components6 = ((Component)t).GetComponents<MeshFilter>();
		for (int i = 0; i < components6.Length; i++)
		{
			Object.DestroyImmediate((Object)(object)components6[i]);
		}
	}

	private static void AddAmbientSound(GameObject root)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		AudioSource val = Cache.GetPrefab<GameObject>("guard_stone").GetComponentsInChildren<AudioSource>(true).First((AudioSource a) => (Object)(object)a.clip != (Object)null);
		GameObject val2 = new GameObject("AmbientHum");
		val2.transform.SetParent(root.transform, false);
		val2.transform.localPosition = new Vector3(0f, 1f, 0f);
		AudioSource obj = val2.AddComponent<AudioSource>();
		obj.clip = val.clip;
		obj.outputAudioMixerGroup = val.outputAudioMixerGroup;
		obj.loop = true;
		obj.playOnAwake = false;
		obj.spatialBlend = 1f;
		obj.rolloffMode = (AudioRolloffMode)1;
		obj.minDistance = 3f;
		obj.maxDistance = 14f;
		obj.volume = 0f;
	}
}
internal static class MonumentDiscovery
{
	public class Entry
	{
		public string Id;

		public Vector3 Position;

		public bool HasHeight;
	}

	private const string KeyPrefix = "PortalMonuments.Discovered.";

	public static bool IsDiscovered(string monumentId)
	{
		if (string.IsNullOrEmpty(monumentId))
		{
			return false;
		}
		string[] rawEntries = GetRawEntries();
		for (int i = 0; i < rawEntries.Length; i++)
		{
			if (rawEntries[i].StartsWith(monumentId + "@", StringComparison.Ordinal))
			{
				return true;
			}
		}
		return false;
	}

	public static void Add(string monumentId, Vector3 position)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)ZNet.instance == (Object)null) && !string.IsNullOrEmpty(monumentId) && !IsDiscovered(monumentId))
		{
			string text = monumentId + "@" + Mathf.RoundToInt(position.x).ToString(CultureInfo.InvariantCulture) + "," + position.y.ToString("0.##", CultureInfo.InvariantCulture) + "," + Mathf.RoundToInt(position.z).ToString(CultureInfo.InvariantCulture);
			string raw = GetRaw();
			localPlayer.m_customData[GetKey()] = ((raw.Length == 0) ? text : (raw + ";" + text));
		}
	}

	public static List<Entry> GetAll()
	{
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		List<Entry> list = new List<Entry>();
		string[] rawEntries = GetRawEntries();
		foreach (string text in rawEntries)
		{
			int num = text.IndexOf('@');
			if (num > 0)
			{
				string[] array = text.Substring(num + 1).Split(new char[1] { ',' });
				float[] array2 = new float[array.Length];
				bool flag = array.Length == 2 || array.Length == 3;
				int num2 = 0;
				while (flag && num2 < array.Length)
				{
					flag = float.TryParse(array[num2], NumberStyles.Float, CultureInfo.InvariantCulture, out array2[num2]);
					num2++;
				}
				if (flag)
				{
					bool flag2 = array.Length == 3;
					list.Add(new Entry
					{
						Id = text.Substring(0, num),
						Position = (flag2 ? new Vector3(array2[0], array2[1], array2[2]) : new Vector3(array2[0], 0f, array2[1])),
						HasHeight = flag2
					});
				}
			}
		}
		return list;
	}

	private static string[] GetRawEntries()
	{
		return GetRaw().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
	}

	private static string GetRaw()
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZNet.instance == (Object)null)
		{
			return "";
		}
		if (!localPlayer.m_customData.TryGetValue(GetKey(), out var value))
		{
			return "";
		}
		return value;
	}

	private static string GetKey()
	{
		return "PortalMonuments.Discovered." + ZNet.instance.GetWorldUID().ToString(CultureInfo.InvariantCulture);
	}
}
internal static class MonumentDust
{
	private struct Anchor
	{
		public Transform Part;

		public Vector3 Local;

		public Vector3 World
		{
			get
			{
				//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_000e: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)Part != (Object)null))
				{
					return Vector3.zero;
				}
				return Part.TransformPoint(Local);
			}
		}
	}

	private class CharacterLook
	{
		private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");

		private readonly GameObject _glowTarget;

		private readonly List<Renderer> _renderers;

		private bool _glowing;

		public CharacterLook(Player player, List<Renderer> renderers)
		{
			_glowTarget = ((Component)(((object)((Component)player).GetComponent<VisEquipment>()) ?? ((object)player))).gameObject;
			_renderers = renderers;
		}

		public void HideAll()
		{
			SetVisible(_renderers, visible: false);
		}

		public void ShowAll()
		{
			SetVisible(_renderers, visible: true);
		}

		public void SetGlow(float glow)
		{
			//IL_0027: 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)
			if (!((Object)(object)_glowTarget == (Object)null))
			{
				if (glow > 0.001f)
				{
					MaterialMan.instance.SetValue<Color>(_glowTarget, EmissionColor, Blue * (glow * 1.5f), false);
					_glowing = true;
				}
				else if (_glowing)
				{
					MaterialMan.instance.ResetValue(_glowTarget, EmissionColor);
					_glowing = false;
				}
			}
		}

		public void Restore()
		{
			SetVisible(_renderers, visible: true);
			SetGlow(0f);
		}
	}

	private class DustLayer : MonoBehaviour
	{
		public DustGraphic Graphic;

		public static DustLayer Create()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PortalMonumentsDust");
			Object.DontDestroyOnLoad((Object)(object)val);
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 10000;
			GameObject val2 = new GameObject("Dust", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(val.transform, false);
			RectTransform val3 = (RectTransform)val2.transform;
			Vector2 val4 = (val3.pivot = Vector2.zero);
			Vector2 anchorMin = (val3.anchorMax = val4);
			val3.anchorMin = anchorMin;
			val3.anchoredPosition = Vector2.zero;
			val3.sizeDelta = new Vector2((float)Screen.width, (float)Screen.height);
			DustLayer dustLayer = val.AddComponent<DustLayer>();
			dustLayer.Graphic = val2.AddComponent<DustGraphic>();
			((Graphic)dustLayer.Graphic).raycastTarget = false;
			return dustLayer;
		}
	}

	private class DustGraphic : MaskableGraphic
	{
		public Vector2[] Positions = (Vector2[])(object)new Vector2[0];

		public float[] Sizes = new float[0];

		public Color[] Colors = (Color[])(object)new Color[0];

		public float ScreenFlash;

		public void Resize(int n)
		{
			Positions = (Vector2[])(object)new Vector2[n];
			Sizes = new float[n];
			Colors = (Color[])(object)new Color[n];
		}

		protected override void OnPopulateMesh(VertexHelper vh)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			vh.Clear();
			if (ScreenFlash > 0.001f)
			{
				Color color = Color.Lerp(Blue, Color.white, 0.7f);
				color.a = ScreenFlash;
				AddQuad(vh, 0f, 0f, Screen.width, Screen.height, color);
			}
			for (int i = 0; i < Positions.Length; i++)
			{
				if (!(Colors[i].a <= 0.01f))
				{
					float num = Mathf.Round(Positions[i].x);
					float num2 = Mathf.Round(Positions[i].y);
					float num3 = Sizes[i] * 0.5f;
					AddQuad(vh, num - num3, num2 - num3, num + num3, num2 + num3, Colors[i]);
				}
			}
		}

		private static void AddQuad(VertexHelper vh, float x0, float y0, float x1, float y1, Color color)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_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)
			int currentVertCount = vh.currentVertCount;
			vh.AddVert(new Vector3(x0, y0), Color32.op_Implicit(color), Vector4.op_Implicit(Vector2.zero));
			vh.AddVert(new Vector3(x0, y1), Color32.op_Implicit(color), Vector4.op_Implicit(Vector2.zero));
			vh.AddVert(new Vector3(x1, y1), Color32.op_Implicit(color), Vector4.op_Implicit(Vector2.zero));
			vh.AddVert(new Vector3(x1, y0), Color32.op_Implicit(color), Vector4.op_Implicit(Vector2.zero));
			vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
			vh.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
		}
	}

	[HarmonyPatch(typeof(Player), "ShowTeleportAnimation")]
	private static class HideVanillaSwirl
	{
		private static void Postfix(ref bool __result)
		{
			if (Active)
			{
				__result = false;
			}
		}
	}

	private const int Count = 300;

	private const float SizeDivider = 120f;

	private const float MinSize = 2f;

	private const float MaxSize = 6f;

	private const float FlashSeconds = 0.3f;

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

	private const float GlowInSeconds = 0.5f;

	private const float ReleaseStart = 0.2f;

	private const float ReleaseSpread = 0.8f;

	private const float VanishAt = 1.1f;

	private const float BurstShare = 0.4f;

	private const float LeaveSeconds = 1.6f;

	private const float FlashRise = 0.06f;

	private const float FlashFall = 0.35f;

	private const float ScreenFlashAlpha = 0.3f;

	private const float WispRadius = 0.8f;

	private const float WispSpinSlow = 0.8f;

	private const float WispSpinFast = 2.5f;

	private const float RiseMin = 50f;

	private const float RiseMax = 140f;

	private const float LifeMin = 0.8f;

	private const float LifeMax = 6f;

	private const float FadeOutSeconds = 0.6f;

	private const float GatherSeconds = 1.3f;

	private const float AppearAt = 2.25f;

	private const float AppearFadeSeconds = 0.4f;

	private const float GlowOutSeconds = 0.6f;

	private const float GlowStrength = 1.5f;

	private const float MaxWaitSeconds = 40f;

	private const float MaxPointDistance = 2.5f;

	public static bool Active { get; private set; }

	public static void Play(Player player, Func<bool> startTeleport)
	{
		if (Active)
		{
			return;
		}
		bool teleportCalled = false;
		Func<bool> teleport = delegate
		{
			teleportCalled = true;
			return startTeleport();
		};
		((MonoBehaviour)PortalMonuments.Instance).StartCoroutine(Guard(Run(player, teleport), delegate
		{
			if (!teleportCalled && (Object)(object)player != (Object)null && (Object)(object)Player.m_localPlayer == (Object)(object)player)
			{
				teleport();
			}
		}));
	}

	private static IEnumerator Guard(IEnumerator effect, Action onError)
	{
		while (true)
		{
			bool flag = false;
			try
			{
				if (!effect.MoveNext())
				{
					yield break;
				}
			}
			catch (Exception e)
			{
				MonumentTeleport.ReportError("playing the teleport effect", e);
				flag = true;
			}
			if (flag)
			{
				break;
			}
			yield return effect.Current;
		}
		onError();
	}

	private static IEnumerator Run(Player player, Func<bool> startTeleport)
	{
		Active = true;
		DustLayer layer = null;
		CharacterLook look = null;
		MonumentWisps wisps = null;
		try
		{
			List<Renderer> renderers = new List<Renderer>();
			List<Anchor> anchors = SampleCharacter(player, renderers);
			look = new CharacterLook(player, renderers);
			wisps = new MonumentWisps(player);
			layer = DustLayer.Create();
			DustGraphic g = layer.Graphic;
			int n = anchors.Count;
			g.Resize(n);
			Vector2[] velocity = (Vector2[])(object)new Vector2[n];
			float[] height = new float[n];
			float[] jitter = new float[n];
			bool[] burst = new bool[n];
			float[] phase = new float[n];
			float[] rise = new float[n];
			float[] life = new float[n];
			Vector2[] gatherFrom = (Vector2[])(object)new Vector2[n];
			float[] returnAlpha = new float[n];
			Color[] baseColor = (Color[])(object)new Color[n];
			float unit = (float)Screen.height / 1080f;
			float num = float.MaxValue;
			float num2 = float.MinValue;
			foreach (Anchor item in anchors)
			{
				num = Mathf.Min(num, item.World.y);
				num2 = Mathf.Max(num2, item.World.y);
			}
			Rect val = ScreenBounds(anchors);
			float num3 = Mathf.Clamp(((Rect)(ref val)).height / 120f, 2f, 6f);
			float wispTop = Mathf.Max(num2 - ((Component)player).transform.position.y, 1f) + 0.65999997f + 0.2f;
			for (int i = 0; i < n; i++)
			{
				height[i] = ((num2 > num) ? Mathf.Clamp01((anchors[i].World.y - num) / (num2 - num)) : 0.5f);
				jitter[i] = Random.value * 0.08f;
				burst[i] = Random.value < 0.4f;
				phase[i] = Random.value * 10f;
				rise[i] = Random.Range(50f, 140f) * unit;
				life[i] = Random.Range(0.8f, 6f);
				baseColor[i] = Color.Lerp(Blue, Color.white, Random.value * 0.4f);
				g.Sizes[i] = Mathf.Round(num3 * Random.Range(0.8f, 1.2f));
				g.Positions[i] = Project(anchors[i].World);
				g.Colors[i] = Color.clear;
			}
			Vector2 charCenter = Average(g.Positions, n);
			for (float t = 0f; t < 1.6f; t += Time.deltaTime)
			{
				if ((Object)(object)Player.m_localPlayer != (Object)(object)player)
				{
					yield break;
				}
				MonumentTeleportLock.Hold(player, frozen: true);
				float deltaTime = Time.deltaTime;
				float num4 = Flash(t, 1.1f);
				look.SetGlow(Mathf.Clamp01(t / 0.5f) + num4);
				if (t >= 1.1f)
				{
					look.HideAll();
				}
				wisps.SetFlash(num4);
				g.ScreenFlash = 0.3f * num4;
				float num5 = Mathf.Max(0f, t - 1.1f);
				wisps.Pose(Mathf.Lerp(0f, wispTop, Ramp(0.1f, 1.1f, t)) + num5 * 1.5f, Mathf.Lerp(0.8f, 1.4399999f, Ramp(1.1f, 1.45f, t)), Ramp(0f, 0.3f, t) * (1f - Ramp(1.1f, 1.45f, t)), Mathf.Lerp(0.8f, 2.5f, Ramp(0f, 1.1f, t)), deltaTime);
				for (int j = 0; j < n; j++)
				{
					float num6 = (burst[j] ? (1.1f + jitter[j] * 0.5f) : (0.2f + height[j] * 0.8f + jitter[j]));
					float num7 = t - num6;
					if (num7 < 0f)
					{
						g.Positions[j] = Project(anchors[j].World);
						continue;
					}
					if (velocity[j] == Vector2.zero)
					{
						Vector2 val2 = g.Positions[j] - charCenter;
						Vector2 normalized = ((Vector2)(ref val2)).normalized;
						float num8 = (burst[j] ? Random.Range(60f, 160f) : Random.Range(10f, 40f));
						velocity[j] = (normalized * num8 + Vector2.up * Random.Range(30f, 80f)) * unit;
					}
					Rise(ref g.Positions[j], ref velocity[j], rise[j], phase[j], t, unit, deltaTime);
					Color color = Color.Lerp(Color.white, baseColor[j], num7 / 0.3f);
					g.Colors[j] = Twinkle(color, phase[j], t);
				}
				((Graphic)g).SetVerticesDirty();
				yield return null;
			}
			look.HideAll();
			wisps.Pose(0f, 0f