Decompiled source of HazardChaos v0.1.14

plugins/HazardChaos.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace HazardChaos
{
	public class AggressiveTumbleweedMover : MonoBehaviour
	{
		public Plugin plugin;

		public Func<Transform> AnchorProvider;

		public float speedMult = 1f;

		public float retargetSec = 2.5f;

		public float maxHorizSpeed = 7.5f;

		public float torqueMag = 15f;

		public float keepDownForce = 2f;

		private Rigidbody rb;

		private Vector3 desiredDir = Vector3.forward;

		private float nextRetargetAt = -1f;

		private void Awake()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_009a: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			rb = ((Component)this).GetComponent<Rigidbody>() ?? ((Component)this).gameObject.AddComponent<Rigidbody>();
			rb.isKinematic = false;
			rb.useGravity = true;
			rb.mass = 4f;
			rb.drag = 1.6f;
			rb.angularDrag = 2f;
			rb.collisionDetectionMode = (CollisionDetectionMode)2;
			rb.constraints = (RigidbodyConstraints)0;
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(((Component)this).transform.position + Vector3.up * 50f, Vector3.down, ref val, 200f, -1, (QueryTriggerInteraction)1))
			{
				((Component)this).transform.position = new Vector3(((Component)this).transform.position.x, ((RaycastHit)(ref val)).point.y + 0.12f, ((Component)this).transform.position.z);
			}
			nextRetargetAt = Time.time;
		}

		private void FixedUpdate()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00b0: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time >= nextRetargetAt)
			{
				desiredDir = ComputeDesiredDir();
				nextRetargetAt = Time.time + Mathf.Max(0.25f, retargetSec);
			}
			if (((Vector3)(ref desiredDir)).sqrMagnitude > 0.0001f)
			{
				Vector3 val = desiredDir;
				rb.AddForce(val * (20f * speedMult), (ForceMode)5);
				Vector3 val2 = Vector3.Cross(Vector3.up, val);
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				rb.AddTorque(normalized * (torqueMag * speedMult), (ForceMode)5);
			}
			Vector3 velocity = rb.velocity;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(velocity.x, 0f, velocity.z);
			float num = maxHorizSpeed * Mathf.Max(0.2f, speedMult);
			if (((Vector3)(ref val3)).magnitude > num)
			{
				Vector3 val4 = ((Vector3)(ref val3)).normalized * num;
				rb.velocity = new Vector3(val4.x, velocity.y, val4.z);
			}
			rb.AddForce(Vector3.down * keepDownForce, (ForceMode)5);
		}

		private Vector3 ComputeDesiredDir()
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_005f: Expected O, but got Unknown
			//IL_00c5: 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)
			Transform val = null;
			if (AnchorProvider != null)
			{
				val = AnchorProvider();
			}
			if (!Object.op_Implicit((Object)(object)val) && (Object)(object)plugin != (Object)null)
			{
				MethodInfo method = typeof(Plugin).GetMethod("PickAnchorByMode", BindingFlags.Instance | BindingFlags.Public);
				if (method != null)
				{
					val = (Transform)method.Invoke(plugin, null);
				}
			}
			if (!Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)Camera.main))
			{
				val = ((Component)Camera.main).transform;
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return Vector3.forward;
			}
			Vector3 val2 = val.position - ((Component)this).transform.position;
			val2.y = 0f;
			if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
			{
				return Vector3.zero;
			}
			return ((Vector3)(ref val2)).normalized;
		}
	}
	[BepInPlugin("com.hazardchaos.mod", "HazardChaos", "0.1.14")]
	public class Plugin : BaseUnityPlugin
	{
		private enum GameMode
		{
			Off,
			NormalOnly,
			ChallengeOnly,
			Both
		}

		public enum ChallengeKind
		{
			Tumbleweed,
			Tornado,
			BothRandom
		}

		private enum Corner
		{
			TopLeft,
			TopRight,
			BottomLeft,
			BottomRight
		}

		private enum AnchorMode
		{
			HostOnly,
			RandomPlayer,
			RoundRobin,
			NearestToHostCamera
		}

		private enum HazardKind
		{
			Dynamite,
			Tornado,
			Tumbleweed
		}

		[CompilerGenerated]
		private sealed class <DespawnAfter>d__160 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float seconds;

			public GameObject go;

			public Plugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DespawnAfter>d__160(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Expected O, but got Unknown
				int num = <>1__state;
				Plugin plugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(seconds);
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					if ((Object)(object)go != (Object)null)
					{
						PhotonView component = go.GetComponent<PhotonView>();
						if ((Object)(object)component != (Object)null && component.IsMine)
						{
							PhotonNetwork.Destroy(go);
						}
						else
						{
							Object.Destroy((Object)(object)go);
						}
					}
					if ((Object)(object)go != (Object)null && plugin._kindOf.TryGetValue(go, out var value))
					{
						if (value == HazardKind.Dynamite)
						{
							plugin.liveDyn.Remove(go);
						}
						if (value == HazardKind.Tornado)
						{
							plugin.liveTor.Remove(go);
						}
						if (value == HazardKind.Tumbleweed)
						{
							plugin.liveTum.Remove(go);
						}
						plugin._kindOf.Remove(go);
					}
					plugin.liveAll.Remove(go);
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <SpawnBurst>d__161 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float totalSpreadSec;

			public int count;

			public Plugin <>4__this;

			public HazardKind kind;

			private float <step>5__2;

			private int <i>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SpawnBurst>d__161(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0247: Unknown result type (might be due to invalid IL or missing references)
				//IL_0251: Expected O, but got Unknown
				int num = <>1__state;
				Plugin plugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<step>5__2 = ((totalSpreadSec > 0f && count > 1) ? (totalSpreadSec / (float)(count - 1)) : 0f);
					<i>5__3 = 0;
					break;
				case 1:
					<>1__state = -1;
					goto IL_027a;
				case 2:
					{
						<>1__state = -1;
						goto IL_027a;
					}
					IL_027a:
					<i>5__3++;
					break;
				}
				if (<i>5__3 < count)
				{
					int num2 = ((PhotonNetwork.CurrentRoom == null) ? 1 : PhotonNetwork.CurrentRoom.PlayerCount);
					int num3 = Math.Max(0, num2 - 1) * Math.Max(0, plugin.mpPerPlayerExtraSlots.Value);
					int num4 = plugin.maxSimultaneousGlobal.Value + num3;
					int num5 = plugin.maxDynamite.Value + num3;
					int num6 = plugin.maxTornado.Value + num3;
					int num7 = plugin.maxTumbleweed.Value + num3;
					if (plugin.liveAll.Count >= num4)
					{
						return false;
					}
					if (kind == HazardKind.Dynamite && plugin.liveDyn.Count >= num5)
					{
						return false;
					}
					if (kind == HazardKind.Tornado && plugin.liveTor.Count >= num6)
					{
						return false;
					}
					if (kind == HazardKind.Tumbleweed && plugin.liveTum.Count >= num7)
					{
						return false;
					}
					Vector3? val = null;
					for (int i = 0; i < 3; i++)
					{
						if (val.HasValue)
						{
							break;
						}
						Transform anchor = plugin.PickAnchorByMode();
						float minDist = ((kind == HazardKind.Tornado) ? 10f : 8f);
						float maxDist = ((kind == HazardKind.Tornado) ? 22f : 18f);
						val = plugin.PickSpawnPosNear(anchor, minDist, maxDist, plugin.requireLineOfSight.Value);
					}
					if (val.HasValue)
					{
						GameObject val2 = plugin.Spawn(kind, val.Value);
						if ((Object)(object)val2 != (Object)null)
						{
							plugin.liveAll.Add(val2);
							plugin._kindOf[val2] = kind;
							if (kind == HazardKind.Dynamite)
							{
								plugin.liveDyn.Add(val2);
							}
							if (kind == HazardKind.Tornado)
							{
								plugin.liveTor.Add(val2);
							}
							if (kind == HazardKind.Tumbleweed)
							{
								plugin.liveTum.Add(val2);
							}
						}
					}
					if (<step>5__2 > 0f)
					{
						<>2__current = (object)new WaitForSeconds(<step>5__2);
						<>1__state = 1;
						return true;
					}
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <SpawnChallengeTornadoAfterDelay>d__145 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Plugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SpawnChallengeTornadoAfterDelay>d__145(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Expected O, but got Unknown
				//IL_015b: 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_0161: Unknown result type (might be due to invalid IL or missing references)
				//IL_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_0164: Unknown result type (might be due to invalid IL or missing references)
				//IL_0169: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: 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_0177: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_019d: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				Plugin plugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					plugin._activeChallengeTornados?.RemoveWhere((GameObject o) => (Object)(object)o == (Object)null);
					if (plugin._activeChallengeTornados != null && plugin._activeChallengeTornados.Count > 0)
					{
						return false;
					}
					SimpleAnnounce.ShowAll("Tornado incoming.", Mathf.Max(0f, plugin.chTorBannerSeconds.Value));
					<>2__current = (object)new WaitForSeconds(Mathf.Max(0f, plugin.chTorPreSpawnDelaySec.Value));
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					if (!PhotonNetwork.IsMasterClient && !PhotonNetwork.OfflineMode)
					{
						return false;
					}
					Transform anchor = plugin.GetAnchorForAI();
					if (!Object.op_Implicit((Object)(object)anchor))
					{
						anchor = (Object.op_Implicit((Object)(object)Camera.main) ? ((Component)Camera.main).transform : plugin.worldRoot);
					}
					if (!Object.op_Implicit((Object)(object)anchor))
					{
						return false;
					}
					if (!plugin.TryPickChallengeSpawnNearAnchor(anchor, out var pos))
					{
						pos = plugin.ForceSpawnNearAnchor(anchor, Mathf.Clamp(plugin.chTorCloseSpawnMin.Value, 10f, 200f), Mathf.Clamp(plugin.chTorCloseSpawnMax.Value, plugin.chTorCloseSpawnMin.Value + 1f, 220f));
					}
					pos = plugin.EnforceNearAnchor(anchor, pos);
					pos = plugin.ClampToLevelBand(pos);
					pos = plugin.PushOutFromAnchor(anchor, pos, 6f);
					if (!plugin.EnforceHostProximity(ref anchor, ref pos, plugin.chTorCloseSpawnMin.Value, plugin.chTorCloseSpawnMax.Value))
					{
						return false;
					}
					plugin.SpawnChallengeTornadoOnce(pos);
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <SpawnerLoop>d__162 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Plugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SpawnerLoop>d__162(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Expected O, but got Unknown
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0094: Expected O, but got Unknown
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Expected O, but got Unknown
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Expected O, but got Unknown
				//IL_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_0162: Expected O, but got Unknown
				//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b3: Expected O, but got Unknown
				//IL_06d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_06e1: Expected O, but got Unknown
				int num = <>1__state;
				Plugin plugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					break;
				case 2:
					<>1__state = -1;
					break;
				case 3:
					<>1__state = -1;
					break;
				case 4:
					<>1__state = -1;
					break;
				case 5:
					<>1__state = -1;
					break;
				case 6:
					<>1__state = -1;
					break;
				case 7:
					<>1__state = -1;
					break;
				case 8:
					<>1__state = -1;
					break;
				}
				plugin._blockReason = "";
				if (!ShouldRunInScene(plugin._currentScene))
				{
					plugin._blockReason = "Scene blocked";
					<>2__current = (object)new WaitForSeconds(0.25f);
					<>1__state = 2;
					return true;
				}
				if (!PhotonNetwork.InRoom)
				{
					plugin._blockReason = "Not in room";
					<>2__current = (object)new WaitForSeconds(0.25f);
					<>1__state = 3;
					return true;
				}
				if (!PhotonNetwork.IsMasterClient)
				{
					plugin._blockReason = "Only host spawns";
					<>2__current = (object)new WaitForSeconds(0.25f);
					<>1__state = 4;
					return true;
				}
				float num2 = Mathf.Max(0f, plugin._sceneEnteredAt + plugin.startProtectionSec.Value - Time.time);
				if (num2 > 0f)
				{
					plugin._blockReason = $"Protection {num2:0.0}s";
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 5;
					return true;
				}
				if (plugin.worldRoot == null)
				{
					plugin.worldRoot = plugin.FindWorldRoot();
				}
				if (!Object.op_Implicit((Object)(object)plugin.worldRoot))
				{
					plugin._blockReason = "WorldRoot missing";
					<>2__current = (object)new WaitForSeconds(0.2f);
					<>1__state = 6;
					return true;
				}
				plugin.liveAll.RemoveWhere((GameObject g) => (Object)(object)g == (Object)null);
				plugin.liveDyn.RemoveWhere((GameObject g) => (Object)(object)g == (Object)null);
				plugin.liveTor.RemoveWhere((GameObject g) => (Object)(object)g == (Object)null);
				plugin.liveTum.RemoveWhere((GameObject g) => (Object)(object)g == (Object)null);
				plugin._activeChallengeTornados.RemoveWhere((GameObject g) => (Object)(object)g == (Object)null);
				int num3 = ((PhotonNetwork.CurrentRoom == null) ? 1 : PhotonNetwork.CurrentRoom.PlayerCount);
				int num4 = Math.Max(0, num3 - 1) * Math.Max(0, plugin.mpPerPlayerExtraSlots.Value);
				int num5 = plugin.maxSimultaneousGlobal.Value + num4;
				int num6 = plugin.maxDynamite.Value + num4;
				int num7 = plugin.maxTornado.Value + num4;
				int num8 = plugin.maxTumbleweed.Value + num4;
				float time = Time.time;
				bool flag = false;
				GameMode value = plugin.gameMode.Value;
				bool flag2 = value == GameMode.NormalOnly || value == GameMode.Both;
				bool flag3 = value == GameMode.ChallengeOnly || value == GameMode.Both;
				bool flag4 = plugin.perfThrottleWhileWindowOpen.Value && plugin.IsGameWindowOpen();
				if (flag4 && flag2)
				{
					plugin._blockReason = "UI open (normal paused)";
				}
				if (flag2 && !flag4)
				{
					if (time >= plugin._nextDynaAt)
					{
						int num9 = Mathf.Max(0, num5 - plugin.liveAll.Count);
						int num10 = Mathf.Max(0, num6 - plugin.liveDyn.Count);
						int num11 = Mathf.Min(new int[3]
						{
							plugin.burstDynamite.Value,
							num9,
							num10
						});
						if (num11 > 0)
						{
							((MonoBehaviour)plugin).StartCoroutine(plugin.SpawnBurst(HazardKind.Dynamite, num11, plugin.burstSpreadSeconds.Value));
							plugin._nextDynaAt = time + plugin.intervalDynamiteSec.Value;
							flag = true;
						}
						else
						{
							plugin._nextDynaAt = time + plugin.intervalDynamiteSec.Value;
						}
					}
					if (time >= plugin._nextTornAt)
					{
						int num12 = Mathf.Max(0, num5 - plugin.liveAll.Count);
						int num13 = Mathf.Max(0, num7 - plugin.liveTor.Count);
						if (num12 > 0 && num13 > 0)
						{
							int num14 = ((!plugin.moreTornados.Value) ? 1 : Mathf.Clamp(plugin.burstTornado.Value, 1, 5));
							num14 = Mathf.Min(new int[3] { num14, num12, num13 });
							if (num14 > 0)
							{
								float totalSpreadSec = (plugin.moreTornados.Value ? plugin.burstSpreadSeconds.Value : 0f);
								((MonoBehaviour)plugin).StartCoroutine(plugin.SpawnBurst(HazardKind.Tornado, num14, totalSpreadSec));
								plugin._nextTornAt = time + plugin.intervalTornadoSec.Value;
								flag = true;
							}
							else
							{
								plugin._nextTornAt = time + plugin.intervalTornadoSec.Value;
							}
						}
						else
						{
							plugin._nextTornAt = time + plugin.intervalTornadoSec.Value;
						}
					}
					if (time >= plugin._nextTumbAt)
					{
						int num15 = Mathf.Max(0, num5 - plugin.liveAll.Count);
						int num16 = Mathf.Max(0, num8 - plugin.liveTum.Count);
						int num17 = Mathf.Min(new int[3]
						{
							plugin.burstTumbleweed.Value,
							num15,
							num16
						});
						if (num17 > 0)
						{
							((MonoBehaviour)plugin).StartCoroutine(plugin.SpawnBurst(HazardKind.Tumbleweed, num17, plugin.burstSpreadSeconds.Value));
							plugin._nextTumbAt = time + plugin.intervalTumbleweedSec.Value;
							flag = true;
						}
						else
						{
							plugin._nextTumbAt = time + plugin.intervalTumbleweedSec.Value;
						}
					}
				}
				else if (!flag2)
				{
					plugin._blockReason = "paused (normal spawns disabled)";
				}
				if (flag3)
				{
					if (plugin._nextChallengeAt < 0f)
					{
						plugin._nextChallengeAt = plugin.NextChallengeTime(plugin.challengeIntervalSec.Value, plugin.challengeRandomJitterSec.Value);
					}
					if (Time.time >= plugin._nextChallengeAt)
					{
						bool flag5 = plugin.challengeKind.Value switch
						{
							ChallengeKind.Tornado => true, 
							ChallengeKind.BothRandom => Random.value < 0.5f, 
							_ => false, 
						};
						if (flag5 && plugin.challengeKind.Value == ChallengeKind.BothRandom && plugin._activeChallengeTornados != null && plugin._activeChallengeTornados.Count > 0)
						{
							flag5 = false;
						}
						if (flag5)
						{
							((MonoBehaviour)plugin).StartCoroutine(plugin.SpawnChallengeTornadoAfterDelay());
						}
						else
						{
							plugin.SpawnChallengeTumbleweedOnce();
						}
						plugin._nextChallengeAt = plugin.NextChallengeTime(plugin.challengeIntervalSec.Value, plugin.challengeRandomJitterSec.Value);
					}
				}
				if (flag)
				{
					<>2__current = (object)new WaitForSeconds(0.03f);
					<>1__state = 7;
					return true;
				}
				<>2__current = null;
				<>1__state = 8;
				return true;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private readonly Collider[] _spawnOverlapBuf = (Collider[])(object)new Collider[32];

		public const string PLUGIN_GUID = "com.hazardchaos.mod";

		public const string PLUGIN_NAME = "HazardChaos";

		public const string PLUGIN_VERSION = "0.1.14";

		private ConfigEntry<ChallengeKind> challengeKind;

		private ConfigEntry<GameMode> gameMode;

		private ConfigEntry<float> challengeIntervalSec;

		private ConfigEntry<float> challengeRandomJitterSec;

		private ConfigEntry<float> chTumScale;

		private ConfigEntry<float> chTumSpeedMult;

		private ConfigEntry<float> chTumRetargetSec;

		private float _nextChallengeAt = -1f;

		private GameMode _lastGameMode = (GameMode)(-1);

		private ConfigEntry<float> intervalDynamiteSec;

		private ConfigEntry<float> intervalTornadoSec;

		private ConfigEntry<float> intervalTumbleweedSec;

		private ConfigEntry<int> maxSimultaneousGlobal;

		private ConfigEntry<int> maxDynamite;

		private ConfigEntry<int> maxTornado;

		private ConfigEntry<int> maxTumbleweed;

		private ConfigEntry<int> burstDynamite;

		private ConfigEntry<int> burstTumbleweed;

		private ConfigEntry<float> burstSpreadSeconds;

		private ConfigEntry<bool> moreTornados;

		private ConfigEntry<int> burstTornado;

		private ConfigEntry<float> ttlDynamite;

		private ConfigEntry<float> ttlTornado;

		private ConfigEntry<float> ttlTumbleweed;

		private ConfigEntry<float> tornadoSpeed;

		private ConfigEntry<float> tornadoRetargetSec;

		private ConfigEntry<bool> tornadoUseVanillaAIWhenAvailable;

		private ConfigEntry<bool> tornadoForceModMover;

		private ConfigEntry<bool> requireLineOfSight;

		private ConfigEntry<float> startProtectionSec;

		private ConfigEntry<bool> uiEnabled;

		private ConfigEntry<KeyboardShortcut> uiToggleKey;

		private ConfigEntry<bool> uiVersionWatermarkEnabled;

		private ConfigEntry<KeyboardShortcut> uiVersionToggleKey;

		private ConfigEntry<Corner> uiVersionCorner;

		private ConfigEntry<int> uiVersionFontSize;

		private ConfigEntry<float> uiVersionAlpha;

		private ConfigEntry<int> uiVersionMargin;

		private ConfigEntry<AnchorMode> mpAnchorMode;

		private ConfigEntry<int> mpPerPlayerExtraSlots;

		private const string TORNADO_PREFAB_NAME = "Tornado";

		private const string TUMBLEWEED_PREFAB_NAME = "TumbleWeed";

		private const string DYNAMITE_ITEM_NAME = "Dynamite";

		private ConfigEntry<KeyboardShortcut> keyTornado;

		private ConfigEntry<KeyboardShortcut> keyDynamite;

		private ConfigEntry<KeyboardShortcut> keyTumbleweed;

		private Transform worldRoot;

		private readonly HashSet<GameObject> liveAll = new HashSet<GameObject>();

		private readonly HashSet<GameObject> liveDyn = new HashSet<GameObject>();

		private readonly HashSet<GameObject> liveTor = new HashSet<GameObject>();

		private readonly HashSet<GameObject> liveTum = new HashSet<GameObject>();

		private readonly Dictionary<GameObject, HazardKind> _kindOf = new Dictionary<GameObject, HazardKind>();

		private Coroutine _loop;

		private string _currentScene = "";

		private string _blockReason = "";

		private readonly List<Transform> _cachedAnchors = new List<Transform>();

		private float _lastAnchorRefreshAt = -999f;

		private int _lastKnownPlayerCount = -1;

		private int _roundRobinIndex;

		private float _nextDynaAt = -1f;

		private float _nextTornAt = -1f;

		private float _nextTumbAt = -1f;

		private float _sceneEnteredAt;

		private ConfigEntry<KeyboardShortcut> uiSettingsKey;

		private bool _showSettings;

		private Rect _settingsRect = new Rect(80f, 80f, 560f, 560f);

		private Vector2 _settingsScroll;

		private readonly Dictionary<string, bool> _fold = new Dictionary<string, bool>();

		private ConfigEntry<float> settingsDimAlpha;

		private ConfigEntry<float> chTorScale;

		private ConfigEntry<float> chTorSpeedMult;

		private ConfigEntry<float> chTorRetargetSec;

		private ConfigEntry<float> chTorPullRadius;

		private ConfigEntry<float> chTorPullForce;

		private ConfigEntry<string> chTorPullLayers;

		private ConfigEntry<float> chTorVerticalPullBias;

		private ConfigEntry<float> chTorMaxClimbSpeed;

		private ConfigEntry<bool> chTorLiberateKinematic;

		private ConfigEntry<float> chTorLiberateMaxMass;

		private ConfigEntry<float> chTorCloseSpawnMin;

		private ConfigEntry<float> chTorCloseSpawnMax;

		private ConfigEntry<float> chTorMaxVerticalDelta;

		private ConfigEntry<float> chTorPreSpawnDelaySec;

		private ConfigEntry<float> chTorBannerSeconds;

		private ConfigEntry<string> chTorBannerFontName;

		private ConfigEntry<bool> perfThrottleWhileWindowOpen;

		private ConfigEntry<string> perfWindowKeywords;

		private HashSet<GameObject> _activeChallengeTornados = new HashSet<GameObject>();

		private ConfigEntry<bool> chRequireHostNear;

		private ConfigEntry<float> chHostNearMeters;

		private ConfigEntry<float> perfUiProbeHz;

		private ConfigEntry<int> perfUiMaxScan;

		private ConfigEntry<bool> perfUiUseStrictScan;

		private ConfigEntry<bool> perfHardPauseHazardsWhileWindowOpen;

		private ConfigEntry<bool> perfAlsoPauseHazardLogic;

		private float _uiScanNextAtUnscaled;

		private bool _uiLikelyOpenCached;

		private bool _hazardsPaused;

		private float _perfNextTickAt;

		private bool _logicPaused;

		public static Plugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		public bool HazardsPaused => _hazardsPaused;

		private void RefreshAnchorsIfNeeded()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			int num = ((PhotonNetwork.CurrentRoom == null) ? 1 : PhotonNetwork.CurrentRoom.PlayerCount);
			if (Time.time - _lastAnchorRefreshAt < 1f && num == _lastKnownPlayerCount && _cachedAnchors.Count > 0)
			{
				return;
			}
			_cachedAnchors.Clear();
			Scene activeScene = SceneManager.GetActiveScene();
			MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
			MonoBehaviour[] array2 = array;
			foreach (MonoBehaviour val in array2)
			{
				if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeInHierarchy && !(((Component)val).gameObject.scene != activeScene) && !(((object)val).GetType().Name != "Character"))
				{
					_cachedAnchors.Add(((Component)val).transform);
				}
			}
			Camera main = Camera.main;
			if (Object.op_Implicit((Object)(object)main) && ((Component)main).gameObject.activeInHierarchy && ((Component)main).gameObject.scene == activeScene && !_cachedAnchors.Contains(((Component)main).transform))
			{
				_cachedAnchors.Add(((Component)main).transform);
			}
			_lastAnchorRefreshAt = Time.time;
			_lastKnownPlayerCount = num;
			if (_roundRobinIndex >= _cachedAnchors.Count)
			{
				_roundRobinIndex = 0;
			}
		}

		public Transform GetAnchorForAI()
		{
			int num = ((PhotonNetwork.CurrentRoom == null) ? 1 : PhotonNetwork.CurrentRoom.PlayerCount);
			if (num <= 1 && Object.op_Implicit((Object)(object)Camera.main))
			{
				return ((Component)Camera.main).transform;
			}
			Transform val = null;
			try
			{
				val = PickAnchorByMode();
			}
			catch
			{
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				return val;
			}
			if (Object.op_Implicit((Object)(object)Camera.main))
			{
				return ((Component)Camera.main).transform;
			}
			if (!Object.op_Implicit((Object)(object)worldRoot))
			{
				return null;
			}
			return worldRoot;
		}

		public Transform PickAnchorByMode()
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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)
			RefreshAnchorsIfNeeded();
			switch (mpAnchorMode.Value)
			{
			case AnchorMode.HostOnly:
				return LocalCam() ?? _cachedAnchors.FirstOrDefault();
			case AnchorMode.RandomPlayer:
				if (_cachedAnchors.Count == 0)
				{
					return LocalCam();
				}
				return _cachedAnchors[Random.Range(0, _cachedAnchors.Count)];
			case AnchorMode.RoundRobin:
			{
				if (_cachedAnchors.Count == 0)
				{
					return LocalCam();
				}
				Transform result2 = _cachedAnchors[_roundRobinIndex];
				_roundRobinIndex = (_roundRobinIndex + 1) % _cachedAnchors.Count;
				return result2;
			}
			default:
			{
				Transform val = LocalCam();
				if (!Object.op_Implicit((Object)(object)val) || _cachedAnchors.Count == 0)
				{
					return val;
				}
				float num = float.MaxValue;
				Transform result = val;
				{
					foreach (Transform cachedAnchor in _cachedAnchors)
					{
						if (Object.op_Implicit((Object)(object)cachedAnchor))
						{
							Vector3 val2 = cachedAnchor.position - val.position;
							float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
							if (sqrMagnitude < num)
							{
								num = sqrMagnitude;
								result = cachedAnchor;
							}
						}
					}
					return result;
				}
			}
			}
			static Transform LocalCam()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				Scene activeScene = SceneManager.GetActiveScene();
				Camera main = Camera.main;
				if (!Object.op_Implicit((Object)(object)main) || !((Component)main).gameObject.activeInHierarchy || !(((Component)main).gameObject.scene == activeScene))
				{
					return null;
				}
				return ((Component)main).transform;
			}
		}

		public Vector3? PickSpawnPosNear(Transform anchor, float minDist = 8f, float maxDist = 18f, bool requireLOS = true)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01d7: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: 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_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: 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)
			//IL_021c: 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_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)anchor))
			{
				return null;
			}
			Vector3 val = anchor.position + Vector3.up * 1.6f;
			Vector3 forward = anchor.forward;
			bool flag = ((Vector3)(ref forward)).sqrMagnitude > 0.05f;
			Vector3 val3;
			RaycastHit val5 = default(RaycastHit);
			RaycastHit val8 = default(RaycastHit);
			for (int i = 0; i < 28; i++)
			{
				float num = (flag ? Random.Range(-90f, 90f) : Random.Range(-180f, 180f));
				Vector3 val2 = (flag ? (Quaternion.Euler(0f, num, 0f) * forward) : (Quaternion.Euler(0f, num, 0f) * Vector3.forward));
				float num2 = Random.Range(minDist, maxDist);
				Vector3 position = anchor.position;
				val3 = new Vector3(val2.x, 0f, val2.z);
				Vector3 val4 = position + ((Vector3)(ref val3)).normalized * num2;
				if (!Physics.Raycast(val4 + Vector3.up * 60f, Vector3.down, ref val5, 200f, -1, (QueryTriggerInteraction)1))
				{
					continue;
				}
				Vector3 val6 = ((RaycastHit)(ref val5)).point + Vector3.up * 0.1f;
				if (Physics.CheckSphere(val6 + Vector3.up * 0.5f, 0.35f, -1, (QueryTriggerInteraction)1))
				{
					continue;
				}
				if (requireLOS)
				{
					Vector3 val7 = val6 - val;
					float magnitude = ((Vector3)(ref val7)).magnitude;
					if (magnitude > 0.5f && Physics.Raycast(val, ((Vector3)(ref val7)).normalized, ref val8, magnitude - 0.5f, -1, (QueryTriggerInteraction)1))
					{
						continue;
					}
				}
				return val6;
			}
			RaycastHit val11 = default(RaycastHit);
			for (int j = 0; j < 10; j++)
			{
				float num3 = Random.Range(-180f, 180f);
				Vector3 val9 = Quaternion.Euler(0f, num3, 0f) * Vector3.forward;
				float num4 = Random.Range(minDist, maxDist);
				Vector3 position2 = anchor.position;
				val3 = new Vector3(val9.x, 0f, val9.z);
				Vector3 val10 = position2 + ((Vector3)(ref val3)).normalized * num4;
				if (Physics.Raycast(val10 + Vector3.up * 60f, Vector3.down, ref val11, 200f, -1, (QueryTriggerInteraction)1))
				{
					return ((RaycastHit)(ref val11)).point + Vector3.up * 0.1f;
				}
			}
			return null;
		}

		public Vector3? PickSpawnPosNearPlayer(float minDist = 10f, float maxDist = 22f, bool requireLOS = false)
		{
			Transform anchor = (Object.op_Implicit((Object)(object)Camera.main) ? ((Component)Camera.main).transform : PickAnchorByMode());
			return PickSpawnPosNear(anchor, minDist, maxDist, requireLOS);
		}

		private Transform FindWorldRoot()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			string[] array = new string[6] { "WorldRoot", "DynamicRoot", "LevelRoot", "Environment", "Hazards", "Map" };
			string[] array2 = array;
			foreach (string text in array2)
			{
				GameObject val = GameObject.Find(text);
				if (Object.op_Implicit((Object)(object)val))
				{
					return val.transform;
				}
			}
			Scene activeScene = SceneManager.GetActiveScene();
			GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
			GameObject? obj = ((IEnumerable<GameObject>)rootGameObjects).FirstOrDefault((Func<GameObject, bool>)((GameObject r) => r.activeInHierarchy && !Object.op_Implicit((Object)(object)r.GetComponentInChildren<Canvas>())));
			if (obj == null)
			{
				return null;
			}
			return obj.transform;
		}

		private bool TryPickChallengeSpawnNearAnchor(Transform anchor, out Vector3 pos)
		{
			//IL_0001: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00eb: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			pos = default(Vector3);
			if (!Object.op_Implicit((Object)(object)anchor))
			{
				return false;
			}
			float num = Mathf.Clamp(chTorCloseSpawnMin.Value, 10f, 200f);
			float num2 = Mathf.Clamp(chTorCloseSpawnMax.Value, num + 1f, 220f);
			float num3 = Mathf.Clamp(chTorMaxVerticalDelta.Value, 4f, 80f);
			int num4 = 18;
			float num5 = Random.value * (float)Math.PI * 2f;
			float y = anchor.position.y;
			Vector3 val = default(Vector3);
			for (int i = 0; i < num4; i++)
			{
				float num6 = num5 + (float)i * ((float)Math.PI * 2f / (float)num4);
				float num7 = Random.Range(num, num2);
				((Vector3)(ref val))..ctor(Mathf.Cos(num6), 0f, Mathf.Sin(num6));
				Vector3 p = anchor.position + val * num7 + Vector3.up * 2f;
				if (GroundSnapEx(p, out var snapped, out var normal) && !(normal.y < 0.5f) && !(Mathf.Abs(snapped.y - y) > num3) && IsCapsuleFreeLight(snapped))
				{
					pos = snapped + ((Vector3)(ref normal)).normalized * 0.35f;
					return true;
				}
			}
			return false;
		}

		private Vector3 ForceSpawnNearAnchor(Transform anchor, float min, float max)
		{
			//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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)anchor))
			{
				return (Object.op_Implicit((Object)(object)worldRoot) ? worldRoot.position : Vector3.zero) + Vector3.up * 2f;
			}
			float num = Random.Range(Mathf.Clamp(min, 10f, 200f), Mathf.Clamp(max, Mathf.Max(min + 1f, 11f), 220f));
			float num2 = Random.Range(0f, (float)Math.PI * 2f);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(Mathf.Cos(num2), 0f, Mathf.Sin(num2));
			Vector3 val2 = anchor.position + val * num + Vector3.up * 2f;
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Raycast(val2 + Vector3.up * 80f, Vector3.down, ref val3, 200f, -1, (QueryTriggerInteraction)1))
			{
				Vector3 point = ((RaycastHit)(ref val3)).point;
				Vector3 normal = ((RaycastHit)(ref val3)).normal;
				return point + ((Vector3)(ref normal)).normalized * 0.25f;
			}
			return val2;
		}

		private Vector3 EnforceNearAnchor(Transform anchor, Vector3 pos)
		{
			//IL_0060: 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_0081: 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_0097: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00fe: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_0110: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_0163: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)anchor))
			{
				return pos;
			}
			float num = Mathf.Clamp(chTorCloseSpawnMin.Value, 10f, 200f);
			float num2 = Mathf.Clamp(chTorCloseSpawnMax.Value, num + 1f, 220f);
			float num3 = Mathf.Clamp(chTorMaxVerticalDelta.Value, 4f, 80f);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(anchor.position.x, 0f, anchor.position.z);
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(pos.x, 0f, pos.z);
			Vector3 val3 = val2 - val;
			float magnitude = ((Vector3)(ref val3)).magnitude;
			if (magnitude < 0.001f)
			{
				Vector3 forward = anchor.forward;
				val3 = ((((Vector3)(ref forward)).sqrMagnitude > 0.01f) ? anchor.forward : Vector3.forward);
			}
			Vector3 val4 = ((magnitude < num) ? (val + ((Vector3)(ref val3)).normalized * num) : ((magnitude > num2) ? (val + ((Vector3)(ref val3)).normalized * num2) : val2));
			float num4 = Mathf.Clamp(pos.y, anchor.position.y - num3, anchor.position.y + num3);
			Vector3 val5 = new Vector3(val4.x, num4, val4.z) + Vector3.up * 2f;
			if (!GroundSnapEx(val5, out var snapped, out var normal))
			{
				return val5;
			}
			return snapped + ((Vector3)(ref normal)).normalized * 0.35f;
		}

		private bool GroundSnapEx(Vector3 p, out Vector3 snapped, out Vector3 normal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//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_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)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(p + Vector3.up * 80f, Vector3.down, ref val, 200f, -1, (QueryTriggerInteraction)1))
			{
				snapped = ((RaycastHit)(ref val)).point + Vector3.up * 0.05f;
				normal = ((RaycastHit)(ref val)).normal;
				return true;
			}
			if (Physics.Raycast(p + Vector3.down * 5f, Vector3.up, ref val, 40f, -1, (QueryTriggerInteraction)1))
			{
				snapped = ((RaycastHit)(ref val)).point + Vector3.up * 0.05f;
				normal = ((RaycastHit)(ref val)).normal;
				return true;
			}
			snapped = p;
			normal = Vector3.up;
			return false;
		}

		private bool IsCapsuleFreeLight(Vector3 pos)
		{
			//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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(1f, (chTorScale != null) ? chTorScale.Value : 1f);
			float num2 = Mathf.Max(0.7f, 0.6f * num);
			float num3 = Mathf.Max(3f, 2.4f * num);
			Vector3 val = pos + Vector3.up * 0.5f;
			Vector3 val2 = pos + Vector3.up * (0.5f + num3);
			int num4 = Physics.OverlapCapsuleNonAlloc(val, val2, num2, _spawnOverlapBuf, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < num4; i++)
			{
				Collider val3 = _spawnOverlapBuf[i];
				if (Object.op_Implicit((Object)(object)val3) && !val3.isTrigger)
				{
					Rigidbody attachedRigidbody = val3.attachedRigidbody;
					if ((Object)(object)attachedRigidbody == (Object)null || attachedRigidbody.isKinematic)
					{
						return false;
					}
				}
			}
			return true;
		}

		private Vector3 ClampToLevelBand(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0051: 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_0060: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			Vector3 normal;
			if (Physics.Raycast(p + Vector3.up * 80f, Vector3.down, ref val, 200f, -1, (QueryTriggerInteraction)1))
			{
				Vector3 point = ((RaycastHit)(ref val)).point;
				normal = ((RaycastHit)(ref val)).normal;
				return point + ((Vector3)(ref normal)).normalized * 0.25f;
			}
			if (Physics.Raycast(p + Vector3.down * 5f, Vector3.up, ref val, 40f, -1, (QueryTriggerInteraction)1))
			{
				Vector3 point2 = ((RaycastHit)(ref val)).point;
				normal = ((RaycastHit)(ref val)).normal;
				return point2 + ((Vector3)(ref normal)).normalized * 0.25f;
			}
			return p;
		}

		private Transform GetHostAnchor()
		{
			try
			{
				if ((PhotonNetwork.OfflineMode || PhotonNetwork.IsMasterClient) && Object.op_Implicit((Object)(object)Camera.main))
				{
					return ((Component)Camera.main).transform;
				}
				Transform val = null;
				PhotonView[] array = Object.FindObjectsOfType<PhotonView>(true);
				foreach (PhotonView val2 in array)
				{
					if (!Object.op_Implicit((Object)(object)val2) || val2.Owner == null || !val2.Owner.IsMasterClient)
					{
						continue;
					}
					Transform transform = ((Component)val2).transform;
					if (Object.op_Implicit((Object)(object)transform) && ((Component)transform).gameObject.activeInHierarchy)
					{
						if ((Object)(object)((Component)transform).GetComponent<CharacterController>() != (Object)null || (Object)(object)((Component)transform).GetComponentInChildren<CharacterController>(true) != (Object)null || ((Component)transform).CompareTag("Player"))
						{
							return transform;
						}
						if (val == null)
						{
							val = transform;
						}
					}
				}
				if (Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
				if (Object.op_Implicit((Object)(object)Camera.main))
				{
					return ((Component)Camera.main).transform;
				}
				return Object.op_Implicit((Object)(object)worldRoot) ? worldRoot : null;
			}
			catch
			{
				return Object.op_Implicit((Object)(object)Camera.main) ? ((Component)Camera.main).transform : worldRoot;
			}
		}

		private static float PlanarDistance(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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			float num = a.x - b.x;
			float num2 = a.z - b.z;
			return Mathf.Sqrt(num * num + num2 * num2);
		}

		private bool EnforceHostProximity(ref Transform anchor, ref Vector3 pos, float ringMin, float ringMax)
		{
			//IL_004e: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			if (chRequireHostNear == null || !chRequireHostNear.Value)
			{
				return true;
			}
			Transform hostAnchor = GetHostAnchor();
			if (!Object.op_Implicit((Object)(object)hostAnchor))
			{
				return true;
			}
			float num = Mathf.Max(1f, (chHostNearMeters != null) ? chHostNearMeters.Value : 150f);
			if (PlanarDistance(hostAnchor.position, pos) <= num)
			{
				return true;
			}
			anchor = hostAnchor;
			if (!TryPickChallengeSpawnNearAnchor(hostAnchor, out var pos2))
			{
				pos2 = ForceSpawnNearAnchor(hostAnchor, Mathf.Clamp(ringMin, 10f, 200f), Mathf.Clamp(ringMax, Mathf.Max(ringMin + 1f, 11f), 220f));
			}
			pos2 = EnforceNearAnchor(hostAnchor, pos2);
			pos2 = ClampToLevelBand(pos2);
			if (PlanarDistance(hostAnchor.position, pos2) > num * 1.1f)
			{
				return false;
			}
			pos = pos2;
			return true;
		}

		private void ResetTimersForMode(GameMode mode)
		{
			float now = Time.time;
			_nextDynaAt = -1f;
			_nextTornAt = -1f;
			_nextTumbAt = -1f;
			_nextChallengeAt = -1f;
			int num;
			switch (mode)
			{
			case GameMode.Off:
				return;
			default:
				num = ((mode == GameMode.Both) ? 1 : 0);
				break;
			case GameMode.NormalOnly:
				num = 1;
				break;
			}
			bool flag = (byte)num != 0;
			bool flag2 = mode == GameMode.ChallengeOnly || mode == GameMode.Both;
			if (flag)
			{
				_nextDynaAt = Seed(intervalDynamiteSec.Value);
				_nextTornAt = Seed(intervalTornadoSec.Value);
				_nextTumbAt = Seed(intervalTumbleweedSec.Value);
			}
			if (flag2)
			{
				_nextChallengeAt = NextChallengeTime(challengeIntervalSec.Value, challengeRandomJitterSec.Value);
			}
			Log.LogInfo((object)$"[HazardChaos] Timers reset for mode: {mode}");
			float Seed(float baseInterval)
			{
				return now + Random.Range(0.4f, 1.2f) * Mathf.Max(0.01f, baseInterval);
			}
		}

		private void Awake()
		{
			//IL_0789: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_082d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0948: Unknown result type (might be due to invalid IL or missing references)
			//IL_0977: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a6: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			intervalDynamiteSec = ((BaseUnityPlugin)this).Config.Bind<float>("Intervals", "IntervalDynamiteSec", 15f, "Spawn interval for Dynamite (seconds)");
			intervalTornadoSec = ((BaseUnityPlugin)this).Config.Bind<float>("Intervals", "IntervalTornadoSec", 90f, "Spawn interval for Tornado (seconds)");
			intervalTumbleweedSec = ((BaseUnityPlugin)this).Config.Bind<float>("Intervals", "IntervalTumbleweedSec", 12f, "Spawn interval for Tumbleweed (seconds)");
			maxSimultaneousGlobal = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "MaxSimultaneousGlobal", 6, "Global cap across all hazards");
			maxDynamite = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "MaxDynamite", 2, "Max simultaneous Dynamite");
			maxTornado = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "MaxTornado", 1, "Max simultaneous Tornado");
			maxTumbleweed = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "MaxTumbleweed", 3, "Max simultaneous Tumbleweed");
			burstDynamite = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "BurstDynamite", 2, "How many Dynamite to spawn per tick");
			burstTumbleweed = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "BurstTumbleweed", 3, "How many Tumbleweeds to spawn per tick");
			burstSpreadSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "BurstSpreadSeconds", 3f, "Distribute a burst across this duration (0 = spawn instantly)");
			requireLineOfSight = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "RequireLineOfSight", false, "Require LoS from anchor to spawn point");
			startProtectionSec = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "StartProtectionSec", 60f, "Protection window after level load (seconds)");
			gameMode = ((BaseUnityPlugin)this).Config.Bind<GameMode>("Mode", "GameMode", GameMode.NormalOnly, "Off | NormalOnly | ChallengeOnly | Both");
			challengeKind = ((BaseUnityPlugin)this).Config.Bind<ChallengeKind>("Mode", "ChallengeMode", ChallengeKind.Tornado, "Tumbleweed, Tornado or BothRandom.");
			challengeIntervalSec = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge", "IntervalSeconds", 30f, "Base interval (s)");
			challengeRandomJitterSec = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge", "RandomJitterSeconds", 0f, "Random +/- jitter (s)");
			chRequireHostNear = ((BaseUnityPlugin)this).Config.Bind<bool>("Challenge", "RequireHostNear", true, "Only if Host is nearby.");
			chHostNearMeters = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge", "HostNearMeters", 150f, "Host near Anchor in Meters.");
			chTumScale = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tumbleweed", "Scale", 4f, "Visual scale multiplier");
			chTumSpeedMult = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tumbleweed", "SpeedMult", 3f, "Chase speed multiplier");
			chTumRetargetSec = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tumbleweed", "RetargetSeconds", 1.5f, "Retarget cadence (s)");
			chTorScale = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "Scale", 3f, "Visual scale of the tornado (2–5 recommended).");
			chTorSpeedMult = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "SpeedMult", 2f, "Movement speed multiplier for the challenge tornado.");
			chTorRetargetSec = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "RetargetSec", 2f, "Seconds between retargeting (1.5–3 recommended).");
			chTorPullRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "PullRadius", 50f, "Pull radius (m)");
			chTorPullForce = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "PullForce", 100f, "Pull force (acceleration)");
			chTorPullLayers = ((BaseUnityPlugin)this).Config.Bind<string>("Challenge.Tornado", "PullLayers", "Default;Player;Item;Interactable;Grabbable", "Layer list");
			chTorVerticalPullBias = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "VerticalPullBias", 0.35f, "Vertical pull factor (0..1)");
			chTorMaxClimbSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "MaxClimbSpeed", 10f, "Max climb speed (m/s, 0 = off)");
			chTorLiberateKinematic = ((BaseUnityPlugin)this).Config.Bind<bool>("Challenge.Tornado", "LiberateKinematic", true, "Toggle kinematic");
			chTorLiberateMaxMass = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "LiberateMaxMass", 150f, "Max Mass");
			chTorCloseSpawnMin = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "CloseSpawnMin", 40f, "Minimum distance to anchor (m)");
			chTorCloseSpawnMax = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "CloseSpawnMax", 50f, "Maximum distance to anchor (m)");
			chTorMaxVerticalDelta = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "MaxVerticalDelta", 20f, "Max vertical delta to anchor (m)");
			chTorPreSpawnDelaySec = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "PreSpawnDelaySec", 8f, "Delay after banner (s)");
			chTorBannerSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge.Tornado", "BannerSeconds", 6f, "Banner display time (s)");
			chTorBannerFontName = ((BaseUnityPlugin)this).Config.Bind<string>("Challenge.Tornado", "BannerFont", "Darumadrop One", "Banner font (if available)");
			perfThrottleWhileWindowOpen = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "ThrottleWhileWindowOpen", true, "Throttle spawns while a UI window is open");
			perfWindowKeywords = ((BaseUnityPlugin)this).Config.Bind<string>("Performance", "WindowKeywords", "Passport;Terminal;Boarding;Ticket;Popup;Window;opening window", "Root canvas names to detect in-game windows");
			perfUiProbeHz = ((BaseUnityPlugin)this).Config.Bind<float>("Performance", "UIProbeHz", 2f, "How often to scan for in-game windows (Hz). Lower = cheaper. 0 = every 0.5s fallback.");
			perfUiMaxScan = ((BaseUnityPlugin)this).Config.Bind<int>("Performance", "UIMaxScan", 800, "Hard cap for inspected objects during UI scan (safety against huge UIs).");
			perfUiUseStrictScan = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "UIUseStrictScan", false, "If true, also checks for active 'Selectable' controls via reflection (slower).");
			perfHardPauseHazardsWhileWindowOpen = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "HardPauseHazardsWhenWindowOpen", true, "If true, all hazard Renderers/Particles are disabled while an in-game UI window is open (huge GPU win).");
			perfAlsoPauseHazardLogic = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "AlsoPauseHazardLogic", false, "If true, movement and puller logic are paused while UI is open (CPU win). Off keeps hazards dangerous.");
			ttlDynamite = ((BaseUnityPlugin)this).Config.Bind<float>("TTL", "DynamiteDespawn", 10f, "Lifetime Dynamite (s)");
			ttlTornado = ((BaseUnityPlugin)this).Config.Bind<float>("TTL", "TornadoDespawn", 120f, "Lifetime Tornado (s)");
			ttlTumbleweed = ((BaseUnityPlugin)this).Config.Bind<float>("TTL", "TumbleweedDespawn", 20f, "Lifetime Tumbleweed (s)");
			tornadoSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Tornado", "MoveSpeed", 10f, "Tornado speed (m/s)");
			tornadoRetargetSec = ((BaseUnityPlugin)this).Config.Bind<float>("Tornado", "RetargetSeconds", 3f, "Seconds until new target");
			tornadoUseVanillaAIWhenAvailable = ((BaseUnityPlugin)this).Config.Bind<bool>("Tornado", "UseVanillaWhenAvailable", true, "If a TornadoSpawner exists and can init, use the game's AI");
			tornadoForceModMover = ((BaseUnityPlugin)this).Config.Bind<bool>("Tornado", "ForceModMover", false, "Force using mod's mover even if Vanilla AI is available");
			moreTornados = ((BaseUnityPlugin)this).Config.Bind<bool>("Tornado", "MoreTornados", false, "If ON, Tornado spawns can use burst logic (up to 5 per tick, subject to caps). If OFF, only one per tick.");
			burstTornado = ((BaseUnityPlugin)this).Config.Bind<int>("Tornado", "BurstTornado", 1, "How many Tornados to spawn per tick when MoreTornados is ON (1..5).");
			uiToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Overlay", "HotkeyOverlay", new KeyboardShortcut((KeyCode)290, Array.Empty<KeyCode>()), "Toggle UI");
			uiEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Overlay", "SpawnTimerUI", false, "Show per-hazard timers UI");
			uiSettingsKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Overlay", "HotkeySettings", new KeyboardShortcut((KeyCode)292, Array.Empty<KeyCode>()), "Open/close the in-game HazardChaos settings window");
			settingsDimAlpha = ((BaseUnityPlugin)this).Config.Bind<float>("Overlay", "SettingsDimAlpha", 0.55f, "Background dim alpha when settings are open (0..1)");
			uiVersionToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Version", "HotkeyVersion", new KeyboardShortcut((KeyCode)291, Array.Empty<KeyCode>()), "Toggle version watermark");
			uiVersionWatermarkEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Version", "WatermarkEnabled", false, "Show version watermark in all scenes");
			uiVersionCorner = ((BaseUnityPlugin)this).Config.Bind<Corner>("Version", "Corner", Corner.TopRight, "Corner for version watermark");
			uiVersionFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Version", "FontSize", 10, "Font size of version watermark");
			uiVersionAlpha = ((BaseUnityPlugin)this).Config.Bind<float>("Version", "Alpha", 0.65f, "Background alpha (0..1) of version watermark");
			uiVersionMargin = ((BaseUnityPlugin)this).Config.Bind<int>("Version", "Margin", 8, "Margin to screen edges (px)");
			mpAnchorMode = ((BaseUnityPlugin)this).Config.Bind<AnchorMode>("Multiplayer", "AnchorMode", AnchorMode.RandomPlayer, "How to pick player anchors");
			mpPerPlayerExtraSlots = ((BaseUnityPlugin)this).Config.Bind<int>("Multiplayer", "PerPlayerExtraSlots", 1, "Extra concurrent slots per additional player (applied to all caps)");
			keyTornado = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Debug", "HotkeyTornado", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), "Spawn Tornado (Host)");
			keyDynamite = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Debug", "HotkeyDynamite", new KeyboardShortcut((KeyCode)288, Array.Empty<KeyCode>()), "Spawn Dynamite (Host)");
			keyTumbleweed = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Debug", "HotkeyTumbleweed", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Spawn Tumbleweed (Host)");
			SceneManager.sceneLoaded += OnSceneLoaded;
			Log.LogInfo((object)"HazardChaos loaded (v0.1.14).");
		}

		private static bool ShouldRunInScene(string sceneName)
		{
			if (string.IsNullOrEmpty(sceneName))
			{
				return false;
			}
			if (sceneName.IndexOf("Airport", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return false;
			}
			if (sceneName.IndexOf("Title", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return false;
			}
			if (sceneName.IndexOf("Pretitle", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return false;
			}
			if (sceneName.StartsWith("Level_", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			return false;
		}

		private void Update()
		{
			//IL_007f: 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_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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime >= _perfNextTickAt)
			{
				_perfNextTickAt = unscaledTime + 0.33f;
				bool flag = perfThrottleWhileWindowOpen.Value && IsGameWindowOpen();
				if (perfHardPauseHazardsWhileWindowOpen.Value)
				{
					if (flag && !_hazardsPaused)
					{
						SetHazardsPaused(paused: true);
					}
					else if (!flag && _hazardsPaused)
					{
						SetHazardsPaused(paused: false);
					}
				}
				_logicPaused = perfAlsoPauseHazardLogic.Value && flag;
			}
			KeyboardShortcut value = uiToggleKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				uiEnabled.Value = !uiEnabled.Value;
			}
			value = uiVersionToggleKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				uiVersionWatermarkEnabled.Value = !uiVersionWatermarkEnabled.Value;
			}
			value = uiSettingsKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				_showSettings = !_showSettings;
			}
			if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
			{
				if (_lastGameMode != gameMode.Value)
				{
					ResetTimersForMode(gameMode.Value);
					_lastGameMode = gameMode.Value;
				}
				value = keyTornado.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					Hotkey(HazardKind.Tornado);
				}
				value = keyDynamite.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					Hotkey(HazardKind.Dynamite);
				}
				value = keyTumbleweed.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					Hotkey(HazardKind.Tumbleweed);
				}
			}
			void Hotkey(HazardKind kind)
			{
				int count = 1;
				float totalSpreadSec = 0f;
				if (kind == HazardKind.Dynamite)
				{
					count = Mathf.Max(1, burstDynamite.Value);
					totalSpreadSec = burstSpreadSeconds.Value;
				}
				if (kind == HazardKind.Tumbleweed)
				{
					count = Mathf.Max(1, burstTumbleweed.Value);
					totalSpreadSec = burstSpreadSeconds.Value;
				}
				if (kind == HazardKind.Tornado)
				{
					if (moreTornados.Value)
					{
						count = Mathf.Clamp(burstTornado.Value, 1, 5);
						totalSpreadSec = burstSpreadSeconds.Value;
					}
					else
					{
						count = 1;
						totalSpreadSec = 0f;
					}
				}
				((MonoBehaviour)this).StartCoroutine(SpawnBurst(kind, count, totalSpreadSec));
				float time = Time.time;
				if (kind == HazardKind.Dynamite)
				{
					_nextDynaAt = time + intervalDynamiteSec.Value;
				}
				if (kind == HazardKind.Tornado)
				{
					_nextTornAt = time + intervalTornadoSec.Value;
				}
				if (kind == HazardKind.Tumbleweed)
				{
					_nextTumbAt = time + intervalTumbleweedSec.Value;
				}
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene s, LoadSceneMode mode)
		{
			_currentScene = ((Scene)(ref s)).name ?? "";
			_sceneEnteredAt = Time.time;
			worldRoot = FindWorldRoot();
			_cachedAnchors.Clear();
			_lastKnownPlayerCount = -1;
			_lastAnchorRefreshAt = -999f;
			_roundRobinIndex = 0;
			liveAll.Clear();
			liveDyn.Clear();
			liveTor.Clear();
			liveTum.Clear();
			_kindOf.Clear();
			_nextDynaAt = (_nextTornAt = (_nextTumbAt = -1f));
			Log.LogInfo((object)("WorldRoot: " + (Object.op_Implicit((Object)(object)worldRoot) ? ((Object)worldRoot).name : "<null>") + " (Scene: " + _currentScene + ")"));
			if (_loop != null)
			{
				((MonoBehaviour)this).StopCoroutine(_loop);
				_loop = null;
			}
			if (ShouldRunInScene(_currentScene))
			{
				_loop = ((MonoBehaviour)this).StartCoroutine(SpawnerLoop());
			}
			else
			{
				_blockReason = "Scene blocked";
			}
			_lastGameMode = gameMode.Value;
			ResetTimersForMode(_lastGameMode);
		}

		private bool IsGameWindowOpen()
		{
			if (_showSettings)
			{
				return true;
			}
			if (perfThrottleWhileWindowOpen == null || !perfThrottleWhileWindowOpen.Value)
			{
				return false;
			}
			string text = ((perfWindowKeywords != null) ? perfWindowKeywords.Value : "");
			if (string.IsNullOrWhiteSpace(text))
			{
				return false;
			}
			string[] array = (from s in text.Split(new char[2] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim() into s
				where s.Length >= 3
				select s).ToArray();
			if (array.Length == 0)
			{
				return false;
			}
			float unscaledTime = Time.unscaledTime;
			float num = ((perfUiProbeHz != null && perfUiProbeHz.Value > 0f) ? (1f / perfUiProbeHz.Value) : 0.5f);
			if (unscaledTime < _uiScanNextAtUnscaled)
			{
				return _uiLikelyOpenCached;
			}
			_uiScanNextAtUnscaled = unscaledTime + num;
			bool flag = perfUiUseStrictScan != null && perfUiUseStrictScan.Value;
			int num2 = Mathf.Max(100, (perfUiMaxScan != null) ? perfUiMaxScan.Value : 800);
			int num3 = 0;
			bool flag2 = false;
			try
			{
				Canvas[] array2 = Object.FindObjectsOfType<Canvas>();
				foreach (Canvas val in array2)
				{
					if (!Object.op_Implicit((Object)(object)val) || !((Behaviour)val).isActiveAndEnabled)
					{
						continue;
					}
					GameObject gameObject = ((Component)val).gameObject;
					if (!Object.op_Implicit((Object)(object)gameObject) || !gameObject.activeInHierarchy)
					{
						continue;
					}
					string text2 = ((Object)gameObject).name ?? "";
					if (IsIgnoredHudName(text2))
					{
						continue;
					}
					bool flag3 = false;
					for (int j = 0; j < array.Length; j++)
					{
						if (text2.IndexOf(array[j], StringComparison.OrdinalIgnoreCase) >= 0)
						{
							flag3 = true;
							break;
						}
					}
					if (!flag3)
					{
						continue;
					}
					CanvasGroup componentInChildren = gameObject.GetComponentInChildren<CanvasGroup>(true);
					if ((Object)(object)componentInChildren != (Object)null && (componentInChildren.alpha < 0.8f || (!componentInChildren.blocksRaycasts && !componentInChildren.interactable)))
					{
						continue;
					}
					if (flag)
					{
						MonoBehaviour[] componentsInChildren = gameObject.GetComponentsInChildren<MonoBehaviour>(true);
						foreach (MonoBehaviour val2 in componentsInChildren)
						{
							if (!Object.op_Implicit((Object)(object)val2))
							{
								continue;
							}
							num3++;
							if (num3 > num2)
							{
								break;
							}
							Type type = ((object)val2).GetType();
							if (type.Name != "Selectable")
							{
								continue;
							}
							bool flag4 = true;
							PropertyInfo property = type.GetProperty("interactable");
							if (property != null && property.PropertyType == typeof(bool))
							{
								try
								{
									flag4 = (bool)property.GetValue(val2, null);
								}
								catch
								{
								}
							}
							Behaviour val3 = (Behaviour)(object)val2;
							if (val3 != null && val3.isActiveAndEnabled && flag4)
							{
								flag2 = true;
								break;
							}
						}
						if (num3 > num2 || flag2)
						{
							break;
						}
						continue;
					}
					flag2 = true;
					break;
				}
			}
			catch
			{
			}
			_uiLikelyOpenCached = flag2;
			return flag2;
			static bool IsIgnoredHudName(string n)
			{
				if (n.IndexOf("HUD", StringComparison.OrdinalIgnoreCase) < 0 && n.IndexOf("Overlay", StringComparison.OrdinalIgnoreCase) < 0 && n.IndexOf("Crosshair", StringComparison.OrdinalIgnoreCase) < 0 && n.IndexOf("Watermark", StringComparison.OrdinalIgnoreCase) < 0 && n.IndexOf("Compass", StringComparison.OrdinalIgnoreCase) < 0 && n.IndexOf("FPS", StringComparison.OrdinalIgnoreCase) < 0 && n.IndexOf("Debug", StringComparison.OrdinalIgnoreCase) < 0)
				{
					return n.IndexOf("HazardChaos", StringComparison.OrdinalIgnoreCase) >= 0;
				}
				return true;
			}
		}

		private void SetHazardsPaused(bool paused)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			_hazardsPaused = paused;
			liveAll.RemoveWhere((GameObject g) => (Object)(object)g == (Object)null);
			foreach (GameObject item in liveAll)
			{
				if (!Object.op_Implicit((Object)(object)item))
				{
					continue;
				}
				ParticleSystem[] componentsInChildren = item.GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem val in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						EmissionModule emission = val.emission;
						((EmissionModule)(ref emission)).enabled = !paused;
					}
				}
				Renderer[] componentsInChildren2 = item.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val2 in componentsInChildren2)
				{
					if (Object.op_Implicit((Object)(object)val2))
					{
						val2.enabled = !paused;
					}
				}
			}
			Log.LogInfo((object)(paused ? "[Perf] Hazards rendering paused (UI open)." : "[Perf] Hazards rendering resumed (UI closed)."));
		}

		public bool IsLogicPaused()
		{
			return _logicPaused;
		}

		public static bool IsLogicPausedStatic()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				return Instance._logicPaused;
			}
			return false;
		}

		private float NextChallengeTime(float baseInterval, float jitter)
		{
			float num = ((jitter > 0f) ? Random.Range(0f - jitter, jitter) : 0f);
			return Time.time + Mathf.Max(1f, baseInterval + num);
		}

		[IteratorStateMachine(typeof(<SpawnChallengeTornadoAfterDelay>d__145))]
		private IEnumerator SpawnChallengeTornadoAfterDelay()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SpawnChallengeTornadoAfterDelay>d__145(0)
			{
				<>4__this = this
			};
		}

		private Vector3 PushOutFromAnchor(Transform anchor, Vector3 p, float extra)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)anchor) || extra <= 0f)
			{
				return p;
			}
			Vector3 position = anchor.position;
			position.y = 0f;
			Vector3 val = p;
			val.y = 0f;
			Vector3 val2 = val - position;
			if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
			{
				Vector3 forward = anchor.forward;
				val2 = ((((Vector3)(ref forward)).sqrMagnitude > 0.01f) ? anchor.forward : Vector3.forward);
			}
			float num = ((Vector3)(ref val2)).magnitude + extra;
			Vector3 val3 = position + ((Vector3)(ref val2)).normalized * num;
			Vector3 p2 = default(Vector3);
			((Vector3)(ref p2))..ctor(val3.x, p.y, val3.z);
			return ClampToLevelBand(p2);
		}

		private void ScaleTornadoVisualsSafe(GameObject go, float s)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)go) || s <= 0f)
			{
				return;
			}
			ParticleSystem[] componentsInChildren = go.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				MainModule main = val.main;
				((MainModule)(ref main)).startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier * s;
				((MainModule)(ref main)).startSpeedMultiplier = ((MainModule)(ref main)).startSpeedMultiplier * Mathf.Lerp(1f, s, 0.7f);
				ShapeModule shape = val.shape;
				if (((ShapeModule)(ref shape)).enabled)
				{
					((ShapeModule)(ref shape)).radius = ((ShapeModule)(ref shape)).radius * s;
					Vector3 scale = ((ShapeModule)(ref shape)).scale;
					scale *= s;
					((ShapeModule)(ref shape)).scale = scale;
				}
			}
			Transform[] componentsInChildren2 = go.GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren2)
			{
				if (Object.op_Implicit((Object)(object)val2) && !((Object)(object)val2 == (Object)(object)go.transform))
				{
					bool flag = (Object)(object)((Component)val2).GetComponent<Renderer>() != (Object)null;
					bool flag2 = (Object)(object)((Component)val2).GetComponent<Collider>() != (Object)null || (Object)(object)((Component)val2).GetComponentInChildren<Collider>(true) != (Object)null;
					bool flag3 = (Object)(object)((Component)val2).GetComponent<Rigidbody>() != (Object)null;
					if (flag && !flag2 && !flag3)
					{
						val2.localScale *= s;
					}
				}
			}
		}

		private void SpawnChallengeTornadoOnce(Vector3 pos)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: 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_0227: Unknown result type (might be due to invalid IL or missing references)
			int num = ((PhotonNetwork.CurrentRoom == null) ? 1 : PhotonNetwork.CurrentRoom.PlayerCount);
			int num2 = Mathf.Max(0, num - 1) * Mathf.Max(0, mpPerPlayerExtraSlots.Value);
			if (liveAll.Count >= maxSimultaneousGlobal.Value + num2 || liveTor.Count >= maxTornado.Value + num2)
			{
				return;
			}
			GameObject val = null;
			try
			{
				val = PhotonNetwork.Instantiate("Tornado", pos, Quaternion.identity, (byte)0, (object[])null);
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Instantiate 'Tornado' failed: " + ex.Message));
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			PhotonView component = val.GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null && PhotonNetwork.IsMasterClient && !component.IsMine)
			{
				try
				{
					component.TransferOwnership(PhotonNetwork.LocalPlayer);
				}
				catch
				{
				}
			}
			EnsureTransformSync(component);
			TryDisableVanillaMovement(val);
			Transform val2 = SetupTornadoFallback(val);
			val.transform.SetParent(val2, true);
			ScaleTornadoVisualsSafe(val, Mathf.Max(0.1f, chTorScale.Value));
			ModTornadoMover modTornadoMover = val.GetComponent<ModTornadoMover>() ?? val.AddComponent<ModTornadoMover>();
			modTornadoMover.plugin = this;
			modTornadoMover.drive = (Object.op_Implicit((Object)(object)val2) ? val2 : val.transform);
			modTornadoMover.speed = Mathf.Max(2f, tornadoSpeed.Value) * Mathf.Max(0.1f, chTorSpeedMult.Value);
			modTornadoMover.retargetSec = Mathf.Max(0.5f, chTorRetargetSec.Value);
			modTornadoMover.groundFollow = true;
			modTornadoMover.hoverHeight = 2.5f;
			modTornadoMover.maxClimbY = Mathf.Max(0f, chTorMaxClimbSpeed.Value);
			modTornadoMover.probeUp = 40f;
			modTornadoMover.probeDown = 250f;
			modTornadoMover.enableFallWhenNoGround = true;
			modTornadoMover.fallSpeed = 14f;
			ChallengeTornadoPuller challengeTornadoPuller = val.GetComponent<ChallengeTornadoPuller>() ?? val.AddComponent<ChallengeTornadoPuller>();
			LayerMask val3 = ParseLayerMask(chTorPullLayers.Value);
			if (LayerMask.op_Implicit(val3) == 0)
			{
				val3 = ChallengeTornadoPuller.DefaultMask();
			}
			float num3 = Mathf.Max(0.8f, chTorScale.Value);
			challengeTornadoPuller.Setup(val.transform, Mathf.Max(6f, chTorPullRadius.Value) * num3, Mathf.Max(8f, chTorPullForce.Value), val3, chTorLiberateKinematic.Value, Mathf.Max(0f, chTorLiberateMaxMass.Value), Mathf.Clamp01(chTorVerticalPullBias.Value));
			((MonoBehaviour)this).StartCoroutine(DespawnAfter(val, ttlTornado.Value));
			liveAll.Add(val);
			_kindOf[val] = HazardKind.Tornado;
			liveTor.Add(val);
			_activeChallengeTornados.Add(val);
			Log.LogInfo((object)$"[HazardChaos] Challenge Tornado @ {pos} (scale={chTorScale.Value}, speed*={chTorSpeedMult.Value})");
		}

		private void SpawnChallengeTumbleweedOnce()
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			int num = ((PhotonNetwork.CurrentRoom == null) ? 1 : PhotonNetwork.CurrentRoom.PlayerCount);
			int num2 = Math.Max(0, num - 1) * Math.Max(0, mpPerPlayerExtraSlots.Value);
			int num3 = maxSimultaneousGlobal.Value + num2;
			int num4 = maxTumbleweed.Value + num2;
			if (liveAll.Count >=