Decompiled source of DreadRifts v0.1.4

plugins/DreadRifts/DreadRifts.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using BepInEx;
using BepInEx.Configuration;
using DreadRifts.Core;
using DreadRifts.Runtime;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Ketanol")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyInformationalVersion("0.1.4")]
[assembly: AssemblyProduct("DreadRifts")]
[assembly: AssemblyTitle("DreadRifts")]
[assembly: InternalsVisibleTo("DreadRifts.RuntimeProbe")]
[assembly: AssemblyVersion("0.1.4.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DreadRifts
{
	[BepInPlugin("ketanol.dreadrifts", "DreadRifts", "0.1.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "ketanol.dreadrifts";

		public const string Version = "0.1.4";

		internal static Plugin Instance;

		internal RiftServer Server;

		internal RiftClient Client;

		internal RiftWire Wire;

		internal ConfigEntry<KeyboardShortcut> MenuKey;

		internal ConfigEntry<float> EffectsIntensity;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0021: 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_006e: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			Instance = this;
			MenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "Expedition menu", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Open your current expedition. The gate also opens this menu.");
			EffectsIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "Effects intensity", 1f, new ConfigDescription("Local particle density and light intensity for DreadRifts objects. Does not change combat or other world objects.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1.5f), Array.Empty<object>()));
			Wire = new RiftWire();
			Server = new RiftServer(this);
			Client = new RiftClient(this);
			PrefabManager.OnVanillaPrefabsAvailable += RiftAssets.Register;
			harmony = new Harmony("ketanol.dreadrifts");
			harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"DreadRifts development build 0.1.4");
		}

		private void Update()
		{
			Client.TickUI();
			try
			{
				if (!Object.op_Implicit((Object)(object)ZNet.instance) || !Object.op_Implicit((Object)(object)ZNetScene.instance) || !Object.op_Implicit((Object)(object)ObjectDB.instance))
				{
					Server.Reset();
					Client.Reset();
					return;
				}
				if (ZNet.instance.IsServer())
				{
					Server.Tick();
				}
				Client.Tick();
			}
			catch (Exception error)
			{
				Fail(error);
			}
		}

		internal void Fail(Exception error)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)error);
		}

		internal void LogInfo(string message)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)message);
		}

		private void OnDisable()
		{
			Client?.Close();
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= RiftAssets.Register;
			Client?.Reset();
			Server?.Reset();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			Instance = null;
		}
	}
}
namespace DreadRifts.Runtime
{
	internal sealed class ArenaBiomeServices : MonoBehaviour
	{
		private Vector3[] anchors;

		private Transform[] wispModels;

		public GameObject Campfire { get; private set; }

		public Demister[] Wisps { get; private set; } = (Demister[])(object)new Demister[0];

		public static ArenaBiomeServices Create(ArenaGeometry geometry, int stage, Vector3 firePosition)
		{
			//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_0030: 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)
			GameObject val = new GameObject("DreadRifts biome services");
			val.transform.SetParent(geometry.Root.transform, false);
			ArenaBiomeServices arenaBiomeServices = val.AddComponent<ArenaBiomeServices>();
			if (stage == 3 || stage == 7)
			{
				arenaBiomeServices.CreateCampfire(firePosition);
			}
			if (stage == 5)
			{
				arenaBiomeServices.CreateWisps(geometry.GroundOrigin);
			}
			return arenaBiomeServices;
		}

		private static GameObject CopyInactive(string native, Vector3 position, Transform parent)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = PrefabManager.Instance.GetPrefab(native);
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				throw new InvalidOperationException("Required native biome asset is missing: " + native);
			}
			GameObject val = new GameObject("DreadRifts " + native);
			val.SetActive(false);
			val.transform.SetParent(parent, false);
			return Object.Instantiate<GameObject>(prefab, position, Quaternion.identity, val.transform);
		}

		private void CreateCampfire(Vector3 position)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = CopyInactive("fire_pit", position, ((Component)this).transform);
			Fireplace component = val.GetComponent<Fireplace>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				throw new InvalidOperationException("The native campfire no longer exposes its fire visuals.");
			}
			SetActive(component.m_enabledObject, active: true);
			SetActive(component.m_enabledObjectHigh, active: true);
			SetActive(component.m_enabledObjectLow, active: false);
			SetActive(component.m_fullObject, active: true);
			SetActive(component.m_halfObject, active: false);
			SetActive(component.m_emptyObject, active: false);
			SetActive(component.m_playerBaseObject, active: false);
			int num = 0;
			EffectArea[] componentsInChildren = val.GetComponentsInChildren<EffectArea>(true);
			foreach (EffectArea val2 in componentsInChildren)
			{
				if ((val2.m_type & 1) != 0)
				{
					val2.m_type = (Type)67;
					val2.m_statusEffect = "";
					val2.m_playerOnly = true;
					((Component)val2).gameObject.SetActive(true);
					num++;
				}
				else
				{
					Collider component2 = ((Component)val2).GetComponent<Collider>();
					if (Object.op_Implicit((Object)(object)component2))
					{
						component2.enabled = false;
					}
					Object.DestroyImmediate((Object)(object)val2);
				}
			}
			if (num == 0)
			{
				throw new InvalidOperationException("The native campfire heat trigger is missing.");
			}
			foreach (MonoBehaviour item in val.GetComponentsInChildren<MonoBehaviour>(true).Reverse())
			{
				if (!(item is EffectArea) && !Appearance(item))
				{
					Object.DestroyImmediate((Object)(object)item);
				}
			}
			Rigidbody[] componentsInChildren2 = val.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody obj in componentsInChildren2)
			{
				obj.isKinematic = true;
				obj.useGravity = false;
			}
			Campfire = val;
			val.SetActive(true);
			((Component)val.transform.parent).gameObject.SetActive(true);
		}

		private void CreateWisps(Vector3 origin)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_002e: 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_003d: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_005e: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			anchors = (Vector3[])(object)new Vector3[5]
			{
				origin,
				origin + Vector3.right * 17f,
				origin + Vector3.left * 17f,
				origin + Vector3.forward * 17f,
				origin + Vector3.back * 17f
			};
			Wisps = (Demister[])(object)new Demister[anchors.Length];
			wispModels = (Transform[])(object)new Transform[anchors.Length];
			for (int i = 0; i < anchors.Length; i++)
			{
				GameObject val = CopyInactive("demister_ball", anchors[i] + Vector3.up * 3.2f, ((Component)this).transform);
				Demister componentInChildren = val.GetComponentInChildren<Demister>(true);
				if (!Object.op_Implicit((Object)(object)componentInChildren))
				{
					throw new InvalidOperationException("The native wisplight mist-clearing component is missing.");
				}
				ParticleSystemForceField component = ((Component)componentInChildren).GetComponent<ParticleSystemForceField>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					throw new InvalidOperationException("The native wisplight force field is missing.");
				}
				componentInChildren.m_disableForcefieldDelay = 0f;
				component.endRange = 20f;
				((Behaviour)component).enabled = true;
				foreach (MonoBehaviour item in val.GetComponentsInChildren<MonoBehaviour>(true).Reverse())
				{
					if (!(item is Demister) && !Appearance(item))
					{
						Object.DestroyImmediate((Object)(object)item);
					}
				}
				Collider[] componentsInChildren = val.GetComponentsInChildren<Collider>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					componentsInChildren[j].enabled = false;
				}
				Rigidbody[] componentsInChildren2 = val.GetComponentsInChildren<Rigidbody>(true);
				foreach (Rigidbody obj in componentsInChildren2)
				{
					obj.isKinematic = true;
					obj.useGravity = false;
				}
				Wisps[i] = componentInChildren;
				wispModels[i] = val.transform;
				val.SetActive(true);
				((Component)val.transform.parent).gameObject.SetActive(true);
			}
		}

		private void Update()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			if (Wisps.Length == 0)
			{
				return;
			}
			double num = (Object.op_Implicit((Object)(object)ZNet.instance) ? ZNet.instance.GetTime().TimeOfDay.TotalSeconds : ((double)Time.time));
			for (int i = 0; i < Wisps.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)Wisps[i]))
				{
					float num2 = (float)((num * 0.35 + (double)i * 1.7) % (Math.PI * 2.0));
					wispModels[i].position = anchors[i] + new Vector3(Mathf.Cos(num2) * 0.8f, 3.2f + Mathf.Sin(num2 * 2f) * 0.45f, Mathf.Sin(num2) * 0.8f);
				}
			}
		}

		private static bool Appearance(MonoBehaviour script)
		{
			if (Object.op_Implicit((Object)(object)script))
			{
				if (!(((object)script).GetType().Name == "LightFlicker") && !(((object)script).GetType().Name == "LightLod"))
				{
					return ((object)script).GetType().Name == "ZSFX";
				}
				return true;
			}
			return false;
		}

		private static void SetActive(GameObject item, bool active)
		{
			if (Object.op_Implicit((Object)(object)item))
			{
				item.SetActive(active);
			}
		}
	}
	internal sealed class ArenaGeometry : IDisposable
	{
		private sealed class SourceLease
		{
			public GameObject Prefab;

			public Action Release;
		}

		public const float MinimumHeight = 5312f;

		private static readonly HashSet<string> appearanceScripts = new HashSet<string> { "LightFlicker", "LightLod", "ZSFX", "LodFadeInOut", "SimpleMeshCombine", "MeshLod", "Billboard" };

		public GameObject Root { get; private set; }

		public Bounds Bounds { get; private set; }

		public string Kind { get; private set; }

		public Vector3 GroundOrigin { get; private set; }

		public ArenaPortals Portals { get; private set; }

		public bool OnTerrain => Kind == "fader_walls";

		public static ArenaGeometry Create(string kind, Vector3 floorOrigin)
		{
			//IL_0032: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_007e: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			if (kind != "north" && kind != "queen" && kind != "fader")
			{
				throw new ArgumentException("Unknown native arena.");
			}
			if (floorOrigin.y < 5312f || floorOrigin.y > 5400f)
			{
				throw new ArgumentException("Arena is outside the supported navigation range.");
			}
			SourceLease sourceLease = Acquire(kind);
			GameObject val = null;
			try
			{
				val = new GameObject("DreadRifts Arena " + kind);
				val.SetActive(false);
				GameObject val2 = Object.Instantiate<GameObject>(sourceLease.Prefab, Vector3.zero, Quaternion.identity, val.transform);
				Character[] componentsInChildren = val2.GetComponentsInChildren<Character>(true);
				foreach (Character val3 in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val3) && (Object)(object)((Component)val3).gameObject != (Object)(object)val2)
					{
						Object.DestroyImmediate((Object)(object)((Component)val3).gameObject);
					}
				}
				Bounds val4 = MeshBounds(val2.transform);
				Transform transform = val2.transform;
				transform.position += floorOrigin - new Vector3(((Bounds)(ref val4)).center.x, ((Bounds)(ref val4)).min.y, ((Bounds)(ref val4)).center.z);
				foreach (MonoBehaviour item in val2.GetComponentsInChildren<MonoBehaviour>(true).Reverse())
				{
					if (Object.op_Implicit((Object)(object)item) && !appearanceScripts.Contains(((object)item).GetType().Name))
					{
						Object.DestroyImmediate((Object)(object)item);
					}
				}
				Rigidbody[] componentsInChildren2 = val2.GetComponentsInChildren<Rigidbody>(true);
				foreach (Rigidbody obj in componentsInChildren2)
				{
					obj.isKinematic = true;
					obj.useGravity = false;
				}
				Bounds bounds = MeshBounds(val2.transform);
				if (((Bounds)(ref bounds)).max.y > 5490f)
				{
					throw new InvalidOperationException("Native room exceeds the navigation ceiling.");
				}
				val.AddComponent<ArenaAssetLease>().Release = sourceLease.Release;
				val.SetActive(true);
				val2.SetActive(true);
				Physics.SyncTransforms();
				return new ArenaGeometry
				{
					Kind = kind,
					Root = val,
					Bounds = bounds
				};
			}
			catch
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
				sourceLease.Release();
				throw;
			}
		}

		public List<Vector3> FloorSamples(float spacing = 5f)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			if (spacing < 2f)
			{
				throw new ArgumentOutOfRangeException("spacing");
			}
			if (OnTerrain)
			{
				return BiomeTerrain.FloorSamples(GroundOrigin, 25f, spacing);
			}
			List<Vector3> list = new List<Vector3>();
			Bounds bounds = Bounds;
			float num = ((Bounds)(ref bounds)).min.x + 5f;
			while (true)
			{
				float num2 = num;
				bounds = Bounds;
				if (!(num2 <= ((Bounds)(ref bounds)).max.x - 5f))
				{
					break;
				}
				bounds = Bounds;
				float num3 = ((Bounds)(ref bounds)).min.z + 5f;
				while (true)
				{
					float num4 = num3;
					bounds = Bounds;
					if (!(num4 <= ((Bounds)(ref bounds)).max.z - 5f))
					{
						break;
					}
					float num5 = num;
					bounds = Bounds;
					Vector3 val = new Vector3(num5, ((Bounds)(ref bounds)).max.y + 3f, num3);
					Vector3 down = Vector3.down;
					bounds = Bounds;
					foreach (RaycastHit item in from h in Physics.RaycastAll(val, down, ((Bounds)(ref bounds)).size.y + 10f, -1, (QueryTriggerInteraction)1)
						where ((Component)((RaycastHit)(ref h)).collider).transform.IsChildOf(Root.transform) && ((RaycastHit)(ref h)).normal.y > 0.8f
						orderby ((RaycastHit)(ref h)).point.y
						select h)
					{
						RaycastHit current = item;
						if (!Physics.CheckCapsule(((RaycastHit)(ref current)).point + Vector3.up * 0.5f, ((RaycastHit)(ref current)).point + Vector3.up * 2f, 0.35f, -1, (QueryTriggerInteraction)1))
						{
							list.Add(((RaycastHit)(ref current)).point);
							break;
						}
					}
					num3 += spacing;
				}
				num += spacing;
			}
			return list;
		}

		public bool Contains(Vector3 point, float margin = 5f)
		{
			//IL_0086: 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_0095: 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_000f: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00d2: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			if (OnTerrain)
			{
				if (point.y >= GroundOrigin.y - 15f - margin && point.y <= GroundOrigin.y + 200f + margin)
				{
					Vector2 val = new Vector2(point.x - GroundOrigin.x, point.z - GroundOrigin.z);
					return ((Vector2)(ref val)).sqrMagnitude <= (32f + margin) * (32f + margin);
				}
				return false;
			}
			float y = point.y;
			Bounds bounds = Bounds;
			if (y >= ((Bounds)(ref bounds)).min.y - margin)
			{
				float y2 = point.y;
				bounds = Bounds;
				if (y2 <= ((Bounds)(ref bounds)).max.y + margin)
				{
					float x = point.x;
					bounds = Bounds;
					float num = Mathf.Abs(x - ((Bounds)(ref bounds)).center.x);
					bounds = Bounds;
					if (num <= ((Bounds)(ref bounds)).extents.x + margin)
					{
						float z = point.z;
						bounds = Bounds;
						float num2 = Mathf.Abs(z - ((Bounds)(ref bounds)).center.z);
						bounds = Bounds;
						return num2 <= ((Bounds)(ref bounds)).extents.z + margin;
					}
				}
			}
			return false;
		}

		public static ArenaGeometry CreateWalls(Vector3 groundOrigin)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0045: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			if (!BiomeTerrain.Finite(groundOrigin) || groundOrigin.y < -100f || groundOrigin.y > 2000f)
			{
				throw new ArgumentException("Invalid native terrain origin.");
			}
			SourceLease sourceLease = Acquire("fader");
			GameObject val = null;
			try
			{
				val = new GameObject("DreadRifts Arena fader_walls");
				val.SetActive(false);
				GameObject val2 = Object.Instantiate<GameObject>(sourceLease.Prefab, groundOrigin, Quaternion.identity, val.transform);
				State state = Random.state;
				try
				{
					Random.InitState(9417363);
					RandomSpawn[] componentsInChildren = val2.GetComponentsInChildren<RandomSpawn>(true);
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						componentsInChildren[i].Prepare();
					}
					componentsInChildren = val2.GetComponentsInChildren<RandomSpawn>(true);
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						componentsInChildren[i].Randomize(groundOrigin, (Location)null, (DungeonGenerator)null);
					}
				}
				finally
				{
					Random.state = state;
				}
				Character[] componentsInChildren2 = val2.GetComponentsInChildren<Character>(true);
				foreach (Character val3 in componentsInChildren2)
				{
					if (Object.op_Implicit((Object)(object)val3) && (Object)(object)((Component)val3).gameObject != (Object)(object)val2)
					{
						Object.DestroyImmediate((Object)(object)((Component)val3).gameObject);
					}
				}
				foreach (ZNetView item in val2.GetComponentsInChildren<ZNetView>(true).Reverse())
				{
					if (Object.op_Implicit((Object)(object)item) && Radius(((Component)item).transform.position, groundOrigin) < 24f && (Object)(object)((Component)item).gameObject != (Object)(object)val2)
					{
						Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
					}
				}
				MeshFilter[] componentsInChildren3 = val2.GetComponentsInChildren<MeshFilter>(true);
				foreach (MeshFilter val4 in componentsInChildren3)
				{
					if (Object.op_Implicit((Object)(object)val4) && Object.op_Implicit((Object)(object)val4.sharedMesh))
					{
						Transform transform = ((Component)val4).transform;
						Bounds bounds = val4.sharedMesh.bounds;
						if (Radius(transform.TransformPoint(((Bounds)(ref bounds)).center), groundOrigin) < 24f)
						{
							Object.DestroyImmediate((Object)(object)((Component)val4).gameObject);
						}
					}
				}
				Collider[] componentsInChildren4 = val2.GetComponentsInChildren<Collider>(true);
				foreach (Collider val5 in componentsInChildren4)
				{
					if (Object.op_Implicit((Object)(object)val5) && Radius(((Component)val5).transform.position, groundOrigin) < 24f)
					{
						Object.DestroyImmediate((Object)(object)val5);
					}
				}
				Light[] componentsInChildren5 = val2.GetComponentsInChildren<Light>(true);
				foreach (Light val6 in componentsInChildren5)
				{
					if (Object.op_Implicit((Object)(object)val6) && Radius(((Component)val6).transform.position, groundOrigin) < 24f)
					{
						Object.DestroyImmediate((Object)(object)val6);
					}
				}
				ParticleSystem[] componentsInChildren6 = val2.GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem val7 in componentsInChildren6)
				{
					if (Object.op_Implicit((Object)(object)val7) && Radius(((Component)val7).transform.position, groundOrigin) < 24f)
					{
						Object.DestroyImmediate((Object)(object)((Component)val7).gameObject);
					}
				}
				foreach (MonoBehaviour item2 in val2.GetComponentsInChildren<MonoBehaviour>(true).Reverse())
				{
					if (Object.op_Implicit((Object)(object)item2) && !appearanceScripts.Contains(((object)item2).GetType().Name))
					{
						Object.DestroyImmediate((Object)(object)item2);
					}
				}
				Rigidbody[] componentsInChildren7 = val2.GetComponentsInChildren<Rigidbody>(true);
				foreach (Rigidbody obj in componentsInChildren7)
				{
					obj.isKinematic = true;
					obj.useGravity = false;
				}
				if (val2.GetComponentsInChildren<MeshFilter>(true).Length < 20)
				{
					throw new InvalidOperationException("The installed FaderLocation wall hierarchy differs from the supported layout.");
				}
				Bounds bounds2 = MeshBounds(val2.transform);
				val.AddComponent<ArenaAssetLease>().Release = sourceLease.Release;
				ArenaPortals portals = ArenaStartSide.Create(val.transform, groundOrigin);
				val.SetActive(true);
				val2.SetActive(true);
				Physics.SyncTransforms();
				return new ArenaGeometry
				{
					Kind = "fader_walls",
					Root = val,
					Bounds = bounds2,
					GroundOrigin = groundOrigin,
					Portals = portals
				};
			}
			catch
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
				sourceLease.Release();
				throw;
			}
		}

		private static float Radius(Vector3 point, Vector3 origin)
		{
			//IL_0000: 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_000d: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = new Vector2(point.x - origin.x, point.z - origin.z);
			return ((Vector2)(ref val)).magnitude;
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)Root))
			{
				Object.Destroy((Object)(object)Root);
			}
			Root = null;
		}

		private static SourceLease Acquire(string kind)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Expected O, but got Unknown
			string text = ((kind == "fader") ? "FaderLocation" : ((kind == "north") ? "DN_Bossroom" : "Mistlands_DvergrBossEntrance1"));
			ZoneLocation location = ZoneManager.Instance.GetZoneLocation(text);
			if (location == null)
			{
				throw new InvalidOperationException("The installed game does not provide the required arena.");
			}
			location.m_prefab.Load();
			try
			{
				if (kind == "fader")
				{
					return new SourceLease
					{
						Prefab = location.m_prefab.Asset,
						Release = Once(delegate
						{
							location.m_prefab.Release();
						})
					};
				}
				if (kind == "north")
				{
					Transform val = (from x in (from t in location.m_prefab.Asset.GetComponentsInChildren<Transform>(true)
							select new
							{
								Node = t,
								Count = ((Component)t).GetComponentsInChildren<MeshFilter>(true).Length,
								Bounds = MeshBounds(t)
							}).Where(x =>
						{
							//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_0012: 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)
							if (x.Count > 0)
							{
								Bounds bounds = x.Bounds;
								return ((Bounds)(ref bounds)).min.y > location.m_prefab.Asset.transform.position.y + 1000f;
							}
							return false;
						})
						orderby x.Count descending
						select x.Node).FirstOrDefault();
					if (!Object.op_Implicit((Object)(object)val))
					{
						throw new InvalidOperationException("The native Northern interior is missing.");
					}
					return new SourceLease
					{
						Prefab = ((Component)val).gameObject,
						Release = Once(delegate
						{
							location.m_prefab.Release();
						})
					};
				}
				DungeonGenerator componentInChildren = location.m_prefab.Asset.GetComponentInChildren<DungeonGenerator>(true);
				AccessTools.Method(typeof(DungeonGenerator), "SetupAvailableRooms", (Type[])null, (Type[])null).Invoke(componentInChildren, null);
				foreach (object item in (IEnumerable)AccessTools.Field(typeof(DungeonGenerator), "m_availableRooms").GetValue(componentInChildren))
				{
					object reference = AccessTools.Field(item.GetType(), "m_prefab").GetValue(item);
					AccessTools.Method(reference.GetType(), "Load", (Type[])null, (Type[])null).Invoke(reference, null);
					GameObject val2 = (GameObject)reference.GetType().GetProperty("Asset").GetValue(reference);
					if (((Object)val2).name == "dvergr_new_bossroom_ENTRANCE02")
					{
						return new SourceLease
						{
							Prefab = val2,
							Release = Once(delegate
							{
								AccessTools.Method(reference.GetType(), "Release", (Type[])null, (Type[])null).Invoke(reference, null);
								location.m_prefab.Release();
							})
						};
					}
					AccessTools.Method(reference.GetType(), "Release", (Type[])null, (Type[])null).Invoke(reference, null);
				}
				throw new InvalidOperationException("The native Queen room is missing.");
			}
			catch
			{
				location.m_prefab.Release();
				throw;
			}
		}

		private static Action Once(Action action)
		{
			bool released = false;
			return delegate
			{
				if (!released)
				{
					released = true;
					action();
				}
			};
		}

		private static Bounds MeshBounds(Transform 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(root.position, Vector3.zero);
			MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val.sharedMesh))
				{
					continue;
				}
				Bounds bounds = val.sharedMesh.bounds;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val2 = ((Component)val).transform.TransformPoint(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1)))));
					if (!flag)
					{
						((Bounds)(ref result))..ctor(val2, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(val2);
					}
				}
			}
			return result;
		}
	}
	internal sealed class ArenaAssetLease : MonoBehaviour
	{
		public Action Release;

		private void OnDestroy()
		{
			Release?.Invoke();
			Release = null;
		}
	}
	internal static class ArenaMusic
	{
		[HarmonyPatch(typeof(MusicMan), "UpdateCurrentMusic")]
		private static class Choose
		{
			private static bool Prefix(MusicMan __instance)
			{
				return !Select(__instance);
			}
		}

		[HarmonyPatch(typeof(MusicMan), "UpdateMusic")]
		private static class Loop
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				FieldInfo field = AccessTools.Field(typeof(Settings), "ContinousMusic");
				foreach (CodeInstruction instruction in instructions)
				{
					if (instruction.opcode == OpCodes.Ldsfld && object.Equals(instruction.operand, field))
					{
						instruction.opcode = OpCodes.Call;
						instruction.operand = AccessTools.Method(typeof(ArenaMusic), "Continuous", (Type[])null, (Type[])null);
					}
					yield return instruction;
				}
			}
		}

		private static MusicMan owner;

		private static NamedMusic source;

		private static NamedMusic track;

		private static string selection = "";

		private static readonly FieldInfo Current = AccessTools.Field(typeof(MusicMan), "m_currentMusic");

		private static readonly FieldInfo Queued = AccessTools.Field(typeof(MusicMan), "m_queuedMusic");

		private static readonly MethodInfo Start = AccessTools.Method(typeof(MusicMan), "StartMusic", new Type[1] { typeof(NamedMusic) }, (Type[])null);

		private static readonly MethodInfo Stop = AccessTools.Method(typeof(MusicMan), "StopMusic", (Type[])null, (Type[])null);

		private static readonly MethodInfo EnvironmentMusic = AccessTools.Method(typeof(MusicMan), "GetEnvironmentMusic", (Type[])null, (Type[])null);

		private static readonly string[] BossNames = new string[8] { "boss_eikthyr", "boss_gdking", "boss_bonemass", "boss_moder", "boss_goblinking", "boss_seekerqueen", "boss_fader", "boss_frozenking" };

		private static string Normalize(string value)
		{
			return new string((value ?? "").Where(char.IsLetterOrDigit).Select(char.ToLowerInvariant).ToArray());
		}

		private static NamedMusic Match(List<NamedMusic> tracks, params string[] names)
		{
			foreach (string item in names.Where((string n) => !string.IsNullOrEmpty(n)))
			{
				string key = Normalize(item);
				NamedMusic val = ((IEnumerable<NamedMusic>)tracks).FirstOrDefault((Func<NamedMusic, bool>)((NamedMusic t) => Normalize(t.m_name) == key && t.m_clips != null && t.m_clips.Any((AudioClip c) => Object.op_Implicit((Object)(object)c))));
				if (val != null)
				{
					return val;
				}
			}
			return null;
		}

		public static void Reset()
		{
			if (Object.op_Implicit((Object)(object)owner) && track != null && (Current.GetValue(owner) == track || Queued.GetValue(owner) == track))
			{
				Stop.Invoke(owner, null);
			}
			owner = null;
			source = null;
			track = null;
			selection = "";
		}

		private static bool Select(MusicMan manager)
		{
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Expected O, but got Unknown
			RiftClient riftClient = (Object.op_Implicit((Object)(object)Plugin.Instance) ? Plugin.Instance.Client : null);
			if (riftClient == null || !riftClient.InTrial || !riftClient.ArenaReady || !Object.op_Implicit((Object)(object)Game.instance) || Game.instance.IsShuttingDown())
			{
				Reset();
				return false;
			}
			RunState run = riftClient.Run;
			string text = run.Id + ":" + run.Stage + ":" + ((run.Phase != RunPhase.Combat) ? "rest" : ((run.Level == 10) ? "boss" : "wave"));
			if ((Object)(object)owner != (Object)(object)manager || selection != text || track == null)
			{
				if (!(AccessTools.Field(typeof(MusicMan), "m_music").GetValue(manager) is List<NamedMusic> tracks))
				{
					return false;
				}
				NamedMusic val = null;
				if (run.Phase == RunPhase.Combat)
				{
					if (run.Level == 10)
					{
						GameObject prefab = ZNetScene.instance.GetPrefab(StageCatalog.Stages[run.Stage].BossPrefab);
						Character val2 = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<Character>() : null);
						string text2 = (Object.op_Implicit((Object)(object)val2) ? (AccessTools.Field(typeof(Character), "m_bossMusic")?.GetValue(val2) as string) : null);
						val = Match(tracks, text2, BossNames[run.Stage], "boss_" + StageCatalog.Stages[run.Stage].BossPrefab, (run.Stage == 3) ? "boss_dragon" : ((run.Stage == 5) ? "boss_queen" : null));
					}
					val = val ?? Match(tracks, "combat", "event_forest", "The Forest is moving");
					val = val ?? ((IEnumerable<NamedMusic>)tracks).FirstOrDefault((Func<NamedMusic, bool>)((NamedMusic t) => t.m_clips != null && t.m_clips.Any((AudioClip c) => Object.op_Implicit((Object)(object)c) && Normalize(((Object)c).name).Contains("forestismoving"))));
					val = val ?? Match(tracks, "boss_gdking", "boss_eikthyr");
				}
				else
				{
					object? obj = EnvironmentMusic.Invoke(manager, null);
					val = (NamedMusic)((obj is NamedMusic) ? obj : null);
				}
				if (val?.m_clips == null || !val.m_clips.Any((AudioClip c) => Object.op_Implicit((Object)(object)c)))
				{
					Reset();
					return false;
				}
				owner = manager;
				selection = text;
				if (source != val || track == null)
				{
					source = val;
					track = new NamedMusic
					{
						m_name = "dreadrifts_" + val.m_name,
						m_clips = val.m_clips.Where((AudioClip c) => Object.op_Implicit((Object)(object)c)).ToArray(),
						m_volume = val.m_volume,
						m_fadeInTime = 2f,
						m_alwaysFadeout = true,
						m_loop = true,
						m_resume = false,
						m_enabled = true,
						m_ambientMusic = false
					};
				}
			}
			if (Current.GetValue(manager) != track && Queued.GetValue(manager) != track)
			{
				AccessTools.Field(typeof(MusicMan), "m_resetMusicTimer").SetValue(manager, 0f);
				Start.Invoke(manager, new object[1] { track });
			}
			return true;
		}

		private static bool Continuous()
		{
			if (!Settings.ContinousMusic)
			{
				if (Object.op_Implicit((Object)(object)owner) && track != null)
				{
					return Current.GetValue(owner) == track;
				}
				return false;
			}
			return true;
		}
	}
	internal sealed class ArenaPortals : MonoBehaviour
	{
		public string RunId = "";

		public string ArenaId = "";

		private readonly GameObject[] effects = (GameObject[])(object)new GameObject[12];

		private readonly Light[] lights = (Light[])(object)new Light[12];

		private readonly Renderer[] surfaces = (Renderer[])(object)new Renderer[12];

		private readonly ParticleSystem[][] particles = new ParticleSystem[12][];

		private float[][] emissionRates;

		private MaterialPropertyBlock surfaceColour;

		private float nextUpdate;

		private static readonly Color violet = new Color(0.65f, 0.2f, 1f, 1f);

		public int ActivePortal { get; private set; } = -1;

		public static Vector3 Direction(int portal)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (portal < 0 || portal >= 12)
			{
				throw new ArgumentOutOfRangeException("portal");
			}
			float num = (56.25f + (float)portal * 22.5f) * ((float)Math.PI / 180f);
			return new Vector3(Mathf.Sin(num), 0f, 0f - Mathf.Cos(num));
		}

		public static ArenaPortals Create(Transform parent, Material black, int layer)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("DreadRifts Enemy Entrances");
			val.transform.SetParent(parent, false);
			ArenaPortals arenaPortals = val.AddComponent<ArenaPortals>();
			arenaPortals.emissionRates = new float[12][];
			bool flag = GUIManager.IsHeadless();
			if (!flag)
			{
				arenaPortals.surfaceColour = new MaterialPropertyBlock();
			}
			for (int i = 0; i < 12; i++)
			{
				arenaPortals.surfaces[i] = (Renderer)(object)ArenaStartSide.Backing(val.transform, Direction(i), black, layer, "DreadRifts Enemy Arch " + (i + 1));
				if (!flag)
				{
					arenaPortals.CreateEffects(i);
				}
			}
			return arenaPortals;
		}

		private void CreateEffects(int index)
		{
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0042: 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_0058: 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_007b: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: 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_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Direction(index);
			GameObject val2 = new GameObject("DreadRifts Arch Warning " + (index + 1));
			val2.SetActive(false);
			val2.transform.SetParent(((Component)this).transform, false);
			val2.transform.localPosition = val * 29.1f;
			val2.transform.localRotation = Quaternion.LookRotation(-val, Vector3.up);
			effects[index] = val2;
			GameObject val3 = new GameObject("DreadRifts entrance light");
			val3.transform.SetParent(val2.transform, false);
			val3.transform.localPosition = new Vector3(0f, 3f, 1.3f);
			Light val4 = val3.AddComponent<Light>();
			val4.color = violet;
			val4.range = 11f;
			val4.intensity = 3.2f;
			val4.shadows = (LightShadows)0;
			lights[index] = val4;
			GameObject prefab = PrefabManager.Instance.GetPrefab("vfx_prespawn");
			particles[index] = Array.Empty<ParticleSystem>();
			emissionRates[index] = Array.Empty<float>();
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				return;
			}
			GameObject val5 = Object.Instantiate<GameObject>(prefab, val2.transform);
			((Object)val5).name = "DreadRifts native entrance mist";
			val5.transform.localPosition = new Vector3(0f, 1.8f, 0.6f);
			val5.transform.localRotation = Quaternion.identity;
			val5.transform.localScale = new Vector3(1.2f, 1.4f, 1.2f);
			foreach (MonoBehaviour item in val5.GetComponentsInChildren<MonoBehaviour>(true).Reverse())
			{
				Object.DestroyImmediate((Object)(object)item);
			}
			Collider[] componentsInChildren = val5.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			AudioSource[] componentsInChildren2 = val5.GetComponentsInChildren<AudioSource>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			Light[] componentsInChildren3 = val5.GetComponentsInChildren<Light>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			particles[index] = val5.GetComponentsInChildren<ParticleSystem>(true);
			emissionRates[index] = new float[particles[index].Length];
			for (int j = 0; j < particles[index].Length; j++)
			{
				ParticleSystem obj = particles[index][j];
				((Component)obj).gameObject.SetActive(true);
				MainModule main = obj.main;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(violet);
				((MainModule)(ref main)).loop = true;
				((MainModule)(ref main)).playOnAwake = false;
				((MainModule)(ref main)).stopAction = (ParticleSystemStopAction)0;
				((MainModule)(ref main)).maxParticles = Math.Min(((MainModule)(ref main)).maxParticles, 100);
				ColorOverLifetimeModule colorOverLifetime = obj.colorOverLifetime;
				((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = false;
				EmissionModule emission = obj.emission;
				emissionRates[index][j] = ((EmissionModule)(ref emission)).rateOverTimeMultiplier;
			}
			val5.SetActive(true);
		}

		private void Update()
		{
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Plugin.Instance) || GUIManager.IsHeadless() || Time.unscaledTime < nextUpdate)
			{
				return;
			}
			nextUpdate = Time.unscaledTime + 0.05f;
			RunState runState = Plugin.Instance.Server.FindRun(RunId) ?? ((Plugin.Instance.Client.Run?.Id == RunId) ? Plugin.Instance.Client.Run : null);
			if (runState != null && runState.ArenaId != ArenaId)
			{
				runState = null;
			}
			float value = Plugin.Instance.EffectsIntensity.Value;
			long num = ((runState == null) ? 0 : ((Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer()) ? runState.PortalClockMs : PortalWaves.PredictClock(runState, Plugin.Instance.Client.ServerNow)));
			EnemyRecord enemyRecord = ((runState == null || value <= 0f) ? null : PortalWaves.ActiveGroup(runState, num));
			int num2 = enemyRecord?.PortalIndex ?? (-1);
			if (num2 != ActivePortal)
			{
				if (ActivePortal >= 0)
				{
					ParticleSystem[] array = particles[ActivePortal];
					for (int i = 0; i < array.Length; i++)
					{
						array[i].Stop(false, (ParticleSystemStopBehavior)0);
					}
					effects[ActivePortal].SetActive(false);
					surfaces[ActivePortal].SetPropertyBlock((MaterialPropertyBlock)null);
				}
				ActivePortal = num2;
				if (num2 >= 0)
				{
					effects[num2].SetActive(true);
					ParticleSystem[] array = particles[num2];
					for (int i = 0; i < array.Length; i++)
					{
						array[i].Play(false);
					}
				}
			}
			if (num2 >= 0)
			{
				float num3 = (float)(num - enemyRecord.PortalOpensAtMs) / 1000f;
				float num4 = Mathf.Lerp(0.2f, 1f, Mathf.Clamp01(num3 / 2f));
				float num5 = Mathf.Clamp01(((float)PortalWaves.Duration(enemyRecord) / 1000f - num3) / 0.65f);
				float num6 = 0.9f + 0.1f * Mathf.Sin(num3 * 8f);
				float num7 = num4 * num5 * num6 * value;
				lights[num2].intensity = 3.2f * num7;
				surfaceColour.SetColor("_Color", Color.Lerp(Color.black, new Color(0.13f, 0.012f, 0.22f, 1f), Mathf.Clamp01(num7)));
				surfaces[num2].SetPropertyBlock(surfaceColour);
				for (int j = 0; j < particles[num2].Length; j++)
				{
					EmissionModule emission = particles[num2][j].emission;
					((EmissionModule)(ref emission)).rateOverTimeMultiplier = emissionRates[num2][j] * num4 * num5 * value;
				}
			}
		}
	}
	internal sealed class ArenaReturnGate : MonoBehaviour
	{
		public string RunId;

		public string ArenaId;

		private float nextAttempt;

		private bool armed;

		public bool OpenPose { get; private set; }

		internal static Quaternion RotationFor(ArenaSite site)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0036: 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)
			Vector3 val = RiftWire.Vec(site.Origin) - RiftWire.Vec(site.Checkpoint);
			val.y = 0f;
			return Quaternion.LookRotation((((Vector3)(ref val)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val)).normalized : Vector3.forward);
		}

		internal static Vector3 PositionFor(ArenaSite site)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			return RiftWire.Vec(site.Checkpoint) - RotationFor(site) * Vector3.forward * 3.25f - Vector3.up * 1.2f;
		}

		internal static bool Contains(ArenaSite site, Vector3 position)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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)
			if (site != null)
			{
				return RiftGate.ContainsEntry(Quaternion.Inverse(RotationFor(site)) * (position - PositionFor(site)));
			}
			return false;
		}

		internal static bool BlocksStation(ArenaSite site, Vector3 position)
		{
			//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_000b: 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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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)
			Vector3 val = Quaternion.Inverse(RotationFor(site)) * (position - PositionFor(site));
			if (Mathf.Abs(val.x) < 6.5f && val.z > -8.5f)
			{
				return val.z < 3.5f;
			}
			return false;
		}

		internal static ArenaReturnGate Create(ArenaRuntime arena, ArenaSite site)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_003e: 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)
			GameObject val = new GameObject("DreadRifts Return Gate");
			val.transform.SetParent(arena.Geometry.Root.transform, false);
			val.SetActive(false);
			GameObject val2 = Object.Instantiate<GameObject>(PrefabManager.Instance.GetPrefab("DreadRifts_Gate"), PositionFor(site), RotationFor(site), val.transform);
			((Object)val2).name = "DreadRifts Arena Gate";
			Door component = val2.GetComponent<Door>();
			GameObject val3 = (Object.op_Implicit((Object)(object)component) ? component.m_openEnable : null);
			foreach (MonoBehaviour item in val2.GetComponentsInChildren<MonoBehaviour>(true).Reverse())
			{
				Object.DestroyImmediate((Object)(object)item);
			}
			Rigidbody[] componentsInChildren = val2.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody obj in componentsInChildren)
			{
				obj.isKinematic = true;
				obj.useGravity = false;
			}
			Animator componentInChildren = val2.GetComponentInChildren<Animator>(true);
			if (!Object.op_Implicit((Object)(object)componentInChildren) || !Object.op_Implicit((Object)(object)componentInChildren.runtimeAnimatorController))
			{
				throw new InvalidOperationException("The return gate has no native Queen animation.");
			}
			AnimationClip val4 = ((IEnumerable<AnimationClip>)componentInChildren.runtimeAnimatorController.animationClips).FirstOrDefault((Func<AnimationClip, bool>)((AnimationClip x) => ((Object)x).name == "Open"));
			if (!Object.op_Implicit((Object)(object)val4))
			{
				throw new InvalidOperationException("The native Queen open pose is unavailable.");
			}
			ArenaReturnGate arenaReturnGate = val2.AddComponent<ArenaReturnGate>();
			arenaReturnGate.RunId = arena.RunId;
			arenaReturnGate.ArenaId = arena.Id;
			((Behaviour)componentInChildren).enabled = false;
			val2.SetActive(true);
			val.SetActive(true);
			val4.SampleAnimation(((Component)componentInChildren).gameObject, val4.length);
			if (Object.op_Implicit((Object)(object)val3))
			{
				val3.SetActive(true);
			}
			arenaReturnGate.OpenPose = true;
			Physics.SyncTransforms();
			return arenaReturnGate;
		}

		private void Update()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Plugin.Instance) && !GUIManager.IsHeadless())
			{
				Player localPlayer = Player.m_localPlayer;
				RiftClient client = Plugin.Instance.Client;
				if (!Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting() || !client.InTrial || client.Own.Dead || client.Run.Id != RunId || client.Run.ArenaId != ArenaId)
				{
					armed = false;
				}
				else if (!RiftGate.ContainsEntry(((Component)this).transform.InverseTransformPoint(((Component)localPlayer).transform.position)))
				{
					armed = true;
				}
				else if (armed && !(Time.unscaledTime < nextAttempt))
				{
					nextAttempt = Time.unscaledTime + 3f;
					client.Send("leave_gate");
				}
			}
		}
	}
	internal sealed class ArenaRuntime
	{
		private static readonly Dictionary<string, ArenaRuntime> arenas = new Dictionary<string, ArenaRuntime>();

		public string Id;

		public string RunId;

		public ArenaGeometry Geometry;

		public Vector3 Checkpoint;

		public Vector3 AltarPosition;

		public List<Vector3> Floors;

		public StaticTarget AltarTarget;

		public ArenaBiomeServices BiomeServices;

		public ArenaTransition Transition;

		public ArenaReturnGate ReturnGate;

		private ArenaSite site;

		private readonly List<Vector3> stationPoints = new List<Vector3>();

		private GameObject altarObject;

		public Vector3 WarehousePoint => stationPoints[0];

		public Quaternion ArrivalRotation => ArenaReturnGate.RotationFor(site);

		public static ArenaRuntime Ensure(RunState run)
		{
			if (TryEnsure(run, out var arena))
			{
				return arena;
			}
			throw new InvalidOperationException("Площадка испытания ещё загружается.");
		}

		public static bool TryEnsure(RunState run, out ArenaRuntime arena)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Invalid comparison between I4 and Unknown
			//IL_005b: 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_006c: 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_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			arena = null;
			ArenaSite site = ArenaSites.Current(run);
			if (site == null)
			{
				return false;
			}
			if (site.LayoutVersion != 1 || site.Biome != (int)BiomeTerrain.StageBiome(run.Stage))
			{
				throw new InvalidOperationException("Сохранённая арена не соответствует этапу.");
			}
			Vector3 val = RiftWire.Vec(site.Origin);
			BiomeArenaPlacement.Register(site);
			if (!BiomeTerrain.Prepare(val))
			{
				return false;
			}
			if (!NativeArenaGround.Ensure(site))
			{
				return false;
			}
			if (arenas.TryGetValue(site.Id, out arena))
			{
				arena.UpdateObjective(run);
				return true;
			}
			if (!site.Ready && !ZNet.instance.IsServer())
			{
				return false;
			}
			ArenaGeometry arenaGeometry = ArenaGeometry.CreateWalls(val);
			try
			{
				if (!site.Ready)
				{
					List<Vector3> list = arenaGeometry.FloorSamples(4f);
					if (list.Count < 100)
					{
						throw new InvalidOperationException("Недостаточно безопасной земли внутри арены.");
					}
					Vector3 checkpoint = Nearest(list, val + Vector3.back * 18f) + Vector3.up * 1.2f;
					Vector3 value = Nearest(list, val);
					Vector3[] obj = new Vector3[4]
					{
						val + new Vector3(-12f, 0f, -18f),
						val + new Vector3(-6f, 0f, -23f),
						val + new Vector3(6f, 0f, -23f),
						val + new Vector3(12f, 0f, -18f)
					};
					List<Vector3> services = new List<Vector3>();
					Vector3[] array = (Vector3[])(object)obj;
					foreach (Vector3 target in array)
					{
						Vector3 item = (from p in list
							where Vector3.Distance(p, checkpoint) >= 3f && services.All((Vector3 q) => Vector3.Distance(p, q) >= 4f)
							orderby HorizontalSquared(p, target)
							select p).First();
						services.Add(item);
					}
					site.Floors = list.Select(RiftWire.Pos).ToList();
					site.Checkpoint = RiftWire.Pos(checkpoint);
					site.Altar = RiftWire.Pos(value);
					site.Services = services.Select(RiftWire.Pos).ToList();
					ArenaSites.SetReady(run, site);
				}
				arena = new ArenaRuntime
				{
					Id = site.Id,
					RunId = run.Id,
					site = site,
					Geometry = arenaGeometry,
					Floors = site.Floors.Select(RiftWire.Vec).ToList(),
					Checkpoint = RiftWire.Vec(site.Checkpoint),
					AltarPosition = RiftWire.Vec(site.Altar)
				};
				arenaGeometry.Portals.RunId = run.Id;
				arenaGeometry.Portals.ArenaId = site.Id;
				arena.MakeStation("guard_stone", arena.AltarPosition, "altar", "Алтарь испытания");
				arena.ReturnGate = ArenaReturnGate.Create(arena, site);
				arena.MakeStation("piece_chest_wood", arena.StationPoint(0), "bank", "Склад экспедиции");
				arena.MakeStation("forge", arena.StationPoint(1), "repair", "Ремонт снаряжения");
				arena.MakeStation("piece_chest_wood", arena.StationPoint(2), "reward", "Личная награда");
				List<Vector3> occupiedServices = arena.stationPoints;
				Vector3 firePosition = Nearest(arena.Floors.Where((Vector3 p) => !ArenaReturnGate.BlocksStation(site, p) && occupiedServices.All((Vector3 s) => Vector3.Distance(p, s) >= 4f) && Vector3.Distance(p, RiftWire.Vec(site.Checkpoint)) >= 4f), val + new Vector3(-17f, 0f, -15f));
				arena.BiomeServices = ArenaBiomeServices.Create(arenaGeometry, run.Stage, firePosition);
				if (site.ReadyCircle == null)
				{
					Vector3 altarForCircle = arena.AltarPosition;
					Vector3 value2 = Nearest(arena.Floors.Where((Vector3 p) => !ArenaReturnGate.BlocksStation(site, p) && Vector3.Distance(p, altarForCircle) >= 5f && occupiedServices.All((Vector3 s) => Vector3.Distance(p, s) >= 5f)), val + Vector3.back * 10f);
					site.ReadyCircle = RiftWire.Pos(value2);
				}
				arena.Transition = ArenaTransition.Create(arena);
				arenaGeometry.Root.AddComponent<RiftEffects>();
				arena.UpdateObjective(run);
				arenas.Add(site.Id, arena);
				return true;
			}
			catch
			{
				arenaGeometry.Dispose();
				throw;
			}
		}

		private static float HorizontalSquared(Vector3 a, Vector3 b)
		{
			//IL_0000: 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_000d: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = new Vector2(a.x - b.x, a.z - b.z);
			return ((Vector2)(ref val)).sqrMagnitude;
		}

		private static Vector3 Nearest(IEnumerable<Vector3> floors, Vector3 target)
		{
			//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_001f: Unknown result type (might be due to invalid IL or missing references)
			return floors.OrderBy((Vector3 p) => HorizontalSquared(p, target)).First();
		}

		private Vector3 StationPoint(int index)
		{
			//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_002e: 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_0034: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			Vector3 target = RiftWire.Vec(site.Services[index]);
			Vector3 val = Nearest(Floors.Where((Vector3 p) => !ArenaReturnGate.BlocksStation(site, p) && Vector3.Distance(p, Checkpoint) >= 3f && stationPoints.All((Vector3 q) => Vector3.Distance(p, q) >= 4f)), target);
			stationPoints.Add(val);
			return val;
		}

		internal void UpdateObjective(RunState run)
		{
			if (Object.op_Implicit((Object)(object)altarObject))
			{
				altarObject.SetActive(Expedition.Objective(run.Level) == ObjectiveKind.Defend && run.Phase != RunPhase.Intermission && run.Phase != RunPhase.Complete);
			}
		}

		public bool CheckpointSupported()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (BiomeTerrain.TryFloor(Checkpoint, out var floor, checkObstacles: false))
			{
				return Mathf.Abs(floor.y + 1.2f - Checkpoint.y) < 1f;
			}
			return false;
		}

		public Vector3 SpawnPoint(int index)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0057: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			Vector3 center = RiftWire.Vec(site.Origin);
			float num = (float)index * 2.3999631f;
			Vector3 target = center + new Vector3(Mathf.Sin(num), 0f, Mathf.Cos(num)) * 16f;
			Vector3[] array = Floors.Where((Vector3 x) => Vector3.Distance(x, Checkpoint) > 14f && HorizontalSquared(x, center) < 441f && Vector3.Distance(x, AltarPosition) > 4f && stationPoints.All((Vector3 p) => Vector3.Distance(x, p) > 4f)).ToArray();
			if (array.Length == 0)
			{
				throw new InvalidOperationException("На арене нет подходящих точек появления противников.");
			}
			return Nearest(array, target) + Vector3.up * 0.6f;
		}

		public bool TryPortalSpawn(int portal, int slot, GameObject prefab, out Vector3 position)
		{
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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_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_0166: 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_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ArenaPortals.Direction(portal);
			Vector3 val2 = Vector3.Cross(Vector3.up, val);
			CapsuleCollider component = prefab.GetComponent<CapsuleCollider>();
			Vector3 lossyScale = prefab.transform.lossyScale;
			float num = (Object.op_Implicit((Object)(object)component) ? (component.radius * Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Abs(lossyScale.z))) : 1f);
			float num2 = (Object.op_Implicit((Object)(object)component) ? (component.height * Mathf.Abs(lossyScale.y)) : 2f);
			num = Mathf.Max(0.4f, num);
			num2 = Mathf.Max(num * 2f, num2);
			float num3 = Mathf.Max(14f, 29.4f - num);
			float num4 = Mathf.Min(0.9f, Mathf.Max(0f, 2.5f - num));
			int num5 = slot % 3 - 1;
			float[] array = new float[3] { 0f, 1.5f, 3f };
			foreach (float num6 in array)
			{
				foreach (int item in new int[4] { num5, 0, -1, 1 }.Distinct())
				{
					if (BiomeTerrain.TryFloor(RiftWire.Vec(site.Origin) + val * (num3 - num6) + val2 * ((float)item * num4), out var floor, checkObstacles: false))
					{
						Vector3 val3 = floor + Vector3.up * (num + 0.2f);
						Vector3 val4 = floor + Vector3.up * (num2 - num + 0.2f);
						if (!Physics.OverlapCapsule(val3, val4, num, -1, (QueryTriggerInteraction)1).Any((Collider c) => Object.op_Implicit((Object)(object)c) && !Object.op_Implicit((Object)(object)((Component)c).GetComponentInParent<ItemDrop>()) && LayerMask.LayerToName(((Component)c).gameObject.layer) != "terrain"))
						{
							position = floor + Vector3.up * 0.2f;
							return true;
						}
					}
				}
			}
			position = Vector3.zero;
			return false;
		}

		private void MakeStation(string native, Vector3 point, string action, string label)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0058: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = PrefabManager.Instance.GetPrefab(native);
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				throw new InvalidOperationException("Required native station is missing: " + native);
			}
			GameObject val = new GameObject("DreadRifts " + action);
			val.transform.SetParent(Geometry.Root.transform, false);
			val.SetActive(false);
			GameObject val2 = Object.Instantiate<GameObject>(prefab, point, Quaternion.identity, val.transform);
			foreach (MonoBehaviour item in val2.GetComponentsInChildren<MonoBehaviour>(true).Reverse())
			{
				Object.DestroyImmediate((Object)(object)item);
			}
			Rigidbody[] componentsInChildren = val2.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody obj in componentsInChildren)
			{
				obj.isKinematic = true;
				obj.useGravity = false;
			}
			Rigidbody obj2 = val2.GetComponent<Rigidbody>() ?? val2.AddComponent<Rigidbody>();
			obj2.isKinematic = true;
			obj2.useGravity = false;
			RiftStation riftStation = val2.AddComponent<RiftStation>();
			riftStation.RunId = RunId;
			riftStation.Action = action;
			riftStation.Label = label;
			if (action == "altar")
			{
				altarObject = val;
				AltarTarget = val2.AddComponent<StaticTarget>();
				AltarTarget.m_primaryTarget = true;
				val2.AddComponent<RiftAltar>().RunId = RunId;
			}
			if (action == "reward")
			{
				Light obj3 = val2.AddComponent<Light>();
				obj3.color = new Color(1f, 0.68f, 0.22f);
				obj3.range = 5f;
				obj3.intensity = 1.1f;
			}
			val.SetActive(true);
			val2.SetActive(true);
		}

		public static ArenaRuntime Find(string runId, Vector3 position)
		{
			//IL_000e: 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)
			return arenas.Values.FirstOrDefault((ArenaRuntime x) => x.RunId == runId && x.Geometry.Contains(position));
		}

		public static ArenaRuntime At(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)
			return arenas.Values.FirstOrDefault((ArenaRuntime x) => x.Geometry.Contains(position, 10f));
		}

		public static void Reset()
		{
			foreach (ArenaRuntime value in arenas.Values)
			{
				value.Geometry.Dispose();
			}
			arenas.Clear();
		}
	}
	internal sealed class RiftStation : MonoBehaviour, Hoverable, Interactable
	{
		public string RunId;

		public string Action;

		public string Label;

		public string GetHoverName()
		{
			return Label;
		}

		public float GetHoverOffset()
		{
			return 1f;
		}

		public string GetHoverText()
		{
			return Localization.instance.Localize(Label + "\n[<color=yellow>$KEY_Use</color>] Открыть");
		}

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

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (hold || (Object)(object)user != (Object)(object)Player.m_localPlayer || Plugin.Instance.Client.Run?.Id != RunId)
			{
				return false;
			}
			Plugin.Instance.Client.Station(Action);
			return true;
		}
	}
	internal sealed class RiftAltar : MonoBehaviour, IDestructible
	{
		public string RunId;

		public DestructibleType GetDestructibleType()
		{
			return (DestructibleType)1;
		}

		public void Damage(HitData hit)
		{
			Character attacker = hit.GetAttacker();
			RiftActor riftActor = (Object.op_Implicit((Object)(object)attacker) ? ((Component)attacker).GetComponent<RiftActor>() : null);
			if (Object.op_Implicit((Object)(object)riftActor) && Object.op_Implicit((Object)(object)riftActor.View) && riftActor.View.IsOwner() && !(riftActor.RunId != RunId))
			{
				float num = ((DamageTypes)(ref hit.m_damage)).GetTotalDamage() * riftActor.DamageFactor;
				if (!(num <= 0f))
				{
					Plugin.Instance.Wire.Request(new RiftRequest
					{
						Command = "altar_hit",
						RunId = RunId,
						ActorId = riftActor.ActorId,
						NetworkId = RiftWire.Identity(riftActor.View.GetZDO()),
						Amount = num
					});
				}
			}
		}
	}
	internal static class ArenaSpectator
	{
		[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
		private static class Camera
		{
			private static bool Prefix(GameCamera __instance)
			{
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Unknown result type (might be due to invalid IL or missing references)
				//IL_0179: Unknown result type (might be due to invalid IL or missing references)
				//IL_0183: Unknown result type (might be due to invalid IL or missing references)
				//IL_0188: 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_018f: 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_0197: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ec: 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_01f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0200: Unknown result type (might be due to invalid IL or missing references)
				//IL_0147: 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_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_015b: 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_0250: Unknown result type (might be due to invalid IL or missing references)
				//IL_0255: Unknown result type (might be due to invalid IL or missing references)
				//IL_026d: Unknown result type (might be due to invalid IL or missing references)
				//IL_027d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0285: Unknown result type (might be due to invalid IL or missing references)
				//IL_028a: Unknown result type (might be due to invalid IL or missing references)
				//IL_028f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0294: Unknown result type (might be due to invalid IL or missing references)
				//IL_0218: Unknown result type (might be due to invalid IL or missing references)
				//IL_021c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0238: Unknown result type (might be due to invalid IL or missing references)
				//IL_023d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0242: Unknown result type (might be due to invalid IL or missing references)
				//IL_02af: Unknown result type (might be due to invalid IL or missing references)
				if (!Active)
				{
					return true;
				}
				RiftClient client = Client;
				Player[] array = (from p in Player.GetAllPlayers()
					where Object.op_Implicit((Object)(object)p) && (Object)(object)p != (Object)(object)Player.m_localPlayer && !((Character)p).IsDead() && !((Character)p).IsTeleporting() && client.Run.Members.Any((Member m) => m.PlayerId == p.GetPlayerID() && m.Present && m.Connected && !m.Dead)
					orderby p.GetPlayerID()
					select p).ToArray();
				int num = Array.FindIndex(array, (Player p) => p.GetPlayerID() == targetId);
				if (num < 0)
				{
					num = 0;
				}
				if (array.Length > 1 && !Menu.IsVisible() && !client.MenuOpen && !Console.IsVisible() && (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()))
				{
					if (Input.GetKeyDown((KeyCode)275))
					{
						num = (num + 1) % array.Length;
					}
					if (Input.GetKeyDown((KeyCode)276))
					{
						num = (num + array.Length - 1) % array.Length;
					}
				}
				Vector3 val = Vector3.back;
				if (array.Length != 0)
				{
					Player obj = array[num];
					targetId = obj.GetPlayerID();
					TargetName = client.Run.Members.First((Member m) => m.PlayerId == targetId).Name;
					lastFocus = ((Component)obj).transform.position;
					val = -((Component)obj).transform.forward;
				}
				else
				{
					targetId = 0L;
					TargetName = "Обзор арены";
				}
				Vector3 val2 = lastFocus + Vector3.up * 1.7f;
				Vector3 val3 = val2 + val * 8f + Vector3.up * 4f;
				int mask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "terrain" });
				Vector3 val4 = val3 - val2;
				RaycastHit val5 = default(RaycastHit);
				if (Physics.SphereCast(val2, 0.25f, ((Vector3)(ref val4)).normalized, ref val5, ((Vector3)(ref val4)).magnitude, mask, (QueryTriggerInteraction)1))
				{
					val3 = val2 + ((Vector3)(ref val4)).normalized * Mathf.Max(0.5f, ((RaycastHit)(ref val5)).distance - 0.3f);
				}
				((Component)__instance).transform.position = Vector3.Lerp(((Component)__instance).transform.position, val3, 1f - Mathf.Exp(-5f * Time.unscaledDeltaTime));
				((Component)__instance).transform.rotation = Quaternion.LookRotation(val2 - ((Component)__instance).transform.position, Vector3.up);
				if (Object.op_Implicit((Object)(object)ZNet.instance))
				{
					ZNet.instance.SetReferencePosition(lastFocus);
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(Hud), "UpdateBlackScreen")]
		private static class DeathScreen
		{
			private static bool Prefix(Hud __instance)
			{
				if (!Active)
				{
					return true;
				}
				object? value = AccessTools.Field(typeof(Hud), "m_loadingScreen").GetValue(__instance);
				CanvasGroup val = (CanvasGroup)((value is CanvasGroup) ? value : null);
				if (Object.op_Implicit((Object)(object)val))
				{
					val.alpha = 0f;
					((Component)val).gameObject.SetActive(false);
				}
				return false;
			}
		}

		private static bool witnessedDeath;

		private static bool requestedRespawn;

		private static string runId = "";

		private static Vector3 lastFocus;

		private static long targetId;

		public static string TargetName { get; private set; } = "";

		private static RiftClient Client
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)Plugin.Instance))
				{
					return null;
				}
				return Plugin.Instance.Client;
			}
		}

		public static bool Active
		{
			get
			{
				RiftClient client = Client;
				if (client != null && client.InTrial && Object.op_Implicit((Object)(object)Game.instance) && !Game.instance.IsShuttingDown() && (witnessedDeath || Client.Own.Dead))
				{
					if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
					{
						return ((Character)Player.m_localPlayer).IsDead();
					}
					return true;
				}
				return false;
			}
		}

		public static void Begin(Player player)
		{
			//IL_002d: 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)
			witnessedDeath = true;
			requestedRespawn = false;
			targetId = 0L;
			runId = Client.Run.Id;
			lastFocus = ((Component)player).transform.position;
			TargetName = "";
		}

		public static void Reset()
		{
			witnessedDeath = false;
			requestedRespawn = false;
			targetId = 0L;
			runId = "";
			TargetName = "";
		}

		public static void Tick()
		{
			//IL_0061: 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)
			RiftClient client = Client;
			if (client == null || !client.InTrial)
			{
				Reset();
				return;
			}
			if (runId != client.Run.Id)
			{
				Reset();
				runId = client.Run.Id;
				if (client.Run.Checkpoint != null)
				{
					lastFocus = RiftWire.Vec(client.Run.Checkpoint);
				}
			}
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && !((Character)Player.m_localPlayer).IsDead())
			{
				witnessedDeath = false;
				requestedRespawn = false;
				TargetName = "";
			}
			else if (Active && client.Own.Dead && client.ServerNow >= client.Own.RespawnAtMs && !requestedRespawn && client.Run.HasCheckpoint)
			{
				requestedRespawn = true;
				if (((MonoBehaviour)Game.instance).IsInvoking("_RequestRespawn") || !Game.instance.WaitingForRespawn())
				{
					Game.instance.RequestRespawn(0f, true);
				}
			}
		}
	}
	internal sealed class ArenaStartSide : MonoBehaviour
	{
		private Material blackout;

		public static ArenaPortals Create(Transform arena, Vector3 groundOrigin)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Unlit/Color") ?? Shader.Find("Sprites/Default");
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("The arena blackout shader is unavailable.");
			}
			int num = LayerMask.NameToLayer("piece");
			if (num < 0)
			{
				throw new InvalidOperationException("The native structure collision layer is unavailable.");
			}
			GameObject val2 = new GameObject("DreadRifts Arch Backings");
			val2.transform.SetParent(arena, false);
			val2.transform.position = groundOrigin;
			ArenaStartSide arenaStartSide = val2.AddComponent<ArenaStartSide>();
			arenaStartSide.blackout = new Material(val)
			{
				name = "DreadRifts opaque black arch backing",
				color = Color.black,
				hideFlags = (HideFlags)52
			};
			if (arenaStartSide.blackout.HasProperty("_MainTex"))
			{
				arenaStartSide.blackout.SetTexture("_MainTex", (Texture)(object)Texture2D.whiteTexture);
			}
			for (int i = 0; i < 4; i++)
			{
				float num2 = (33.75f - (float)i * 22.5f) * ((float)Math.PI / 180f);
				Backing(val2.transform, new Vector3(Mathf.Sin(num2), 0f, 0f - Mathf.Cos(num2)), arenaStartSide.blackout, num, "DreadRifts Start Arch " + (i + 1));
			}
			return ArenaPortals.Create(val2.transform, arenaStartSide.blackout, num);
		}

		internal static MeshRenderer Backing(Transform parent, Vector3 outward, Material material, int layer, string name)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)obj).name = name;
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = outward * 30.4f + Vector3.up * 3f;
			obj.transform.localRotation = Quaternion.LookRotation(outward, Vector3.up);
			obj.transform.localScale = new Vector3(7.2f, 10f, 0.8f);
			obj.layer = layer;
			((Collider)obj.GetComponent<BoxCollider>()).i