Decompiled source of KikisChaosHell v1.12.0

plugins/KCH.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peak;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KCH")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KCH")]
[assembly: AssemblyTitle("KCH")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace KCH
{
	internal enum Load
	{
		Green,
		Yellow,
		Red
	}
	internal abstract class Chaos
	{
		public string Name;

		public ChaosCfg Cfg;

		public Load Color;

		public float RunningUntil;

		protected int LastTarget = -1;

		public virtual bool IsRunning
		{
			get
			{
				if (!(Time.time < RunningUntil) && Spawns.Alive(Name) <= 0)
				{
					return Spawns.Queued(Name) > 0;
				}
				return true;
			}
		}

		public virtual bool CanStart(out string why)
		{
			why = null;
			return true;
		}

		public abstract bool Start(out string why);

		public virtual void Despawn()
		{
			Spawns.DespawnTag(Name);
			RunningUntil = 0f;
		}

		public virtual void Tick()
		{
		}

		protected static GameObject Net(string prefab, Vector3 pos, Quaternion rot)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			try
			{
				val = PhotonNetwork.Instantiate(prefab, pos, rot, (byte)0, (object[])null);
			}
			catch (Exception)
			{
				return null;
			}
			_ = (Object)(object)val == (Object)null;
			return val;
		}

		protected bool Spawned(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return false;
			}
			return true;
		}

		protected void CountFor(Character t)
		{
		}

		protected static List<Character> PerScout(List<Character> scouts, int amount, int cap)
		{
			List<Character> list = new List<Character>();
			for (int i = 0; i < amount; i++)
			{
				if (list.Count >= cap)
				{
					break;
				}
				foreach (Character scout in scouts)
				{
					if (list.Count >= cap)
					{
						break;
					}
					list.Add(scout);
				}
			}
			return list;
		}

		protected static List<Character> PerScoutF(List<Character> scouts, float perScout, int cap)
		{
			List<Character> list = new List<Character>();
			if (scouts.Count == 0 || perScout <= 0f)
			{
				return list;
			}
			List<Character> list2 = new List<Character>(scouts);
			for (int num = list2.Count - 1; num > 0; num--)
			{
				int index = Random.Range(0, num + 1);
				Character value = list2[num];
				list2[num] = list2[index];
				list2[index] = value;
			}
			int num2 = Mathf.Min(cap, Mathf.Max(1, Mathf.CeilToInt((float)scouts.Count * perScout - 0.0001f)));
			for (int i = 0; i < num2; i++)
			{
				list.Add(list2[i % list2.Count]);
			}
			return list;
		}

		protected bool StillFor(Character t)
		{
			if ((Object)(object)t != (Object)null && Scouts.StillEligible(t))
			{
				return true;
			}
			return false;
		}

		protected static int Living(List<GameObject> gos)
		{
			int num = 0;
			foreach (GameObject go in gos)
			{
				if ((Object)(object)go != (Object)null && go.activeInHierarchy)
				{
					num++;
				}
			}
			return num;
		}
	}
	internal class DynamiteRain : Chaos
	{
		private static string _explosionRes;

		private static bool _resTried;

		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<Character> list2 = Chaos.PerScout(list, S.DynAmount.Value, Spawns.Free());
			if (list2.Count <= 0)
			{
				why = "object limit";
				return false;
			}
			if (S.DynStyle.Value == DynamiteStyle.Bombardment && ResolveExplosion())
			{
				PhotonView gu = (((Object)(object)GameUtils.instance != (Object)null) ? ((Component)GameUtils.instance).GetComponent<PhotonView>() : null);
				if ((Object)(object)gu == (Object)null)
				{
					why = "GameUtils missing";
					return false;
				}
				foreach (Character item in list2)
				{
					Character target = item;
					Spawns.After(Random.Range(0f, 1.5f), delegate
					{
						//IL_006c: Unknown result type (might be due to invalid IL or missing references)
						if (StillFor(target) && Scouts.AbovePlayer(target, S.DynMin.Value, S.DynMax.Value, 0f, out var pos, out var _))
						{
							Send.Rpc(gu, "RPC_SpawnResourceAtPosition", (RpcTarget)0, _explosionRes, pos);
							CountFor(target);
						}
					});
				}
				RunningUntil = Time.time + 3f;
				return true;
			}
			_ = S.DynStyle.Value;
			_ = 1;
			float height = S.U(S.DynHeight.Value);
			foreach (Character item2 in list2)
			{
				Character target2 = item2;
				Spawns.Enqueue(Name, delegate
				{
					//IL_0052: Unknown result type (might be due to invalid IL or missing references)
					//IL_0057: Unknown result type (might be due to invalid IL or missing references)
					//IL_005d: 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_00af: 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)
					if (StillFor(target2) && Scouts.AbovePlayer(target2, S.DynMin.Value, S.DynMax.Value, height, out var pos, out var _))
					{
						Quaternion rotation = Random.rotation;
						GameObject val = Chaos.Net("0_Items/Dynamite", pos, rotation);
						if (Spawned(val))
						{
							CountFor(target2);
							Send.Rpc(val.GetComponent<PhotonView>(), "SetKinematicRPC", (RpcTarget)0, false, pos, rotation);
							Spawns.Track(val, Name, 20f);
							Dynamite d = val.GetComponent<Dynamite>();
							if (!((Object)(object)d == (Object)null))
							{
								Spawns.After(Random.Range(0f, 0.8f), delegate
								{
									if ((Object)(object)d != (Object)null)
									{
										d.LightFlare();
									}
								});
							}
						}
					}
				});
			}
			return true;
		}

		private static bool ResolveExplosion()
		{
			if (_resTried)
			{
				return _explosionRes != null;
			}
			_resTried = true;
			try
			{
				GameObject val = Resources.Load<GameObject>("0_Items/Dynamite");
				Dynamite val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Dynamite>() : null);
				string text = (((Object)(object)val2 != (Object)null && (Object)(object)val2.explosionPrefab != (Object)null) ? ((Object)val2.explosionPrefab).name : null);
				if (text != null && Resources.Load(text) != (Object)null)
				{
					_explosionRes = text;
				}
			}
			catch (Exception)
			{
			}
			return _explosionRes != null;
		}
	}
	internal class CalderaHotspot : Chaos
	{
		private PhotonView _spawner;

		private PhotonView Spawner()
		{
			if ((Object)(object)_spawner != (Object)null)
			{
				return _spawner;
			}
			try
			{
				EruptionSpawner val = Object.FindAnyObjectByType<EruptionSpawner>();
				if ((Object)(object)val == (Object)null)
				{
					EruptionSpawner[] array = Object.FindObjectsByType<EruptionSpawner>((FindObjectsInactive)1, (FindObjectsSortMode)0);
					if (array.Length != 0)
					{
						val = array[0];
					}
				}
				_spawner = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<PhotonView>() : null);
				if ((Object)(object)val != (Object)null)
				{
					_ = (Object)(object)_spawner == (Object)null;
				}
				if ((Object)(object)val != (Object)null)
				{
					_ = (Object)(object)val.eruption == (Object)null;
				}
				if ((Object)(object)val != (Object)null)
				{
					_ = ((Component)val).gameObject.activeInHierarchy;
				}
			}
			catch (Exception)
			{
				_spawner = null;
			}
			return _spawner;
		}

		public void ResetCache()
		{
			_spawner = null;
		}

		public override bool CanStart(out string why)
		{
			why = (((Object)(object)Spawner() == (Object)null) ? "no EruptionSpawner in this map" : null);
			return why == null;
		}

		public override bool Start(out string why)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!CanStart(out why))
			{
				return false;
			}
			List<List<Character>> list = Scouts.Groups(LastTarget);
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			int value = S.HotAmount.Value;
			PhotonView val = Spawner();
			int num = 0;
			for (int i = 0; i < value; i++)
			{
				if ((Object)(object)val == (Object)null)
				{
					break;
				}
				Vector3 pos;
				Character who;
				int num2 = Scouts.GroundNearGroup(list, 0, S.HotMin.Value, S.HotMax.Value, out pos, out who);
				if (num2 >= 0)
				{
					_ = 0;
					Send.Rpc(val, "RPCA_SpawnEruption", (RpcTarget)0, pos);
					CountFor(who);
					LastTarget = Scouts.ActorOf(who);
					num++;
				}
			}
			if (num == 0)
			{
				why = "no ground near any group";
				return false;
			}
			RunningUntil = Time.time + 6f;
			return true;
		}
	}
	internal class BananaRain : Chaos
	{
		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<Character> list2 = Chaos.PerScout(list, S.BanAmount.Value, Spawns.Free());
			if (list2.Count <= 0)
			{
				why = "object limit";
				return false;
			}
			float life = S.BanLifetime.Value;
			float height = S.U(S.BanHeight.Value);
			foreach (Character item in list2)
			{
				Character target = item;
				Spawns.Enqueue(Name, delegate
				{
					//IL_001f: 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_0049: 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_007c: Unknown result type (might be due to invalid IL or missing references)
					if (StillFor(target) && Scouts.GroundNear(target.Center, S.BanMin.Value, S.BanMax.Value, out var pos))
					{
						GameObject go = Chaos.Net("0_Items/Berrynana Peel Yellow", pos + Vector3.up * height, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
						if (Spawned(go))
						{
							CountFor(target);
							Spawns.Track(go, Name, life);
						}
					}
				});
			}
			return true;
		}
	}
	internal class ShroomRain : Chaos
	{
		public override bool Start(out string why)
		{
			why = null;
			if (Scouts.AliveAll().Count == 0)
			{
				why = "no target";
				return false;
			}
			int num = Mathf.Min(S.ShrAmount.Value, Spawns.Free() / 2);
			if (num <= 0)
			{
				why = "object limit";
				return false;
			}
			float life = S.ShrLifetime.Value;
			for (int i = 0; i < num; i++)
			{
				Spawns.Enqueue(Name, delegate
				{
					//IL_0011: 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_0036: 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_0054: Unknown result type (might be due to invalid IL or missing references)
					//IL_0066: Unknown result type (might be due to invalid IL or missing references)
					//IL_0092: 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)
					Character val = Scouts.PickAnyAlive();
					if (!((Object)(object)val == (Object)null) && Scouts.GroundNear(val.Center, S.ShrMin.Value, S.ShrMax.Value, out var pos, ignoreSafezone: true))
					{
						pos += Vector3.up * S.U(S.ShrHeight.Value);
						if (Spawned(Drop("0_Items/HealingPuffShroom", pos, life, safezoneOk: true)))
						{
							CountFor(val);
						}
						if (S.ShrScorpions.Value && !Scouts.InSafezone(pos) && Random.Range(0, 100) < S.ShrScorpionChance.Value)
						{
							_ = (Object)(object)Drop("0_Items/Scorpion", pos, life) != (Object)null;
						}
					}
				});
			}
			return true;
		}

		private GameObject Drop(string prefab, Vector3 p, float life, bool safezoneOk = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Chaos.Net(prefab, p, Quaternion.identity);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Send.Rpc(val.GetComponent<PhotonView>(), "SetKinematicRPC", (RpcTarget)0, false, p, Quaternion.identity);
			Spawns.Track(val, Name, life, null, safezoneOk);
			return val;
		}
	}
	internal class TornadoChaos : Chaos
	{
		internal static readonly HashSet<int> Ours = new HashSet<int>();

		private static int _lastLuggage = -1;

		private static int _lastPlayer = -1;

		private static bool _syncLogged;

		[Conditional("KCH_PRIVATE")]
		private static void LogSync(GameObject go, PhotonView pv)
		{
			if (_syncLogged)
			{
				return;
			}
			_syncLogged = true;
			try
			{
				List<string> list = new List<string>();
				List<string> list2 = new List<string>();
				if (pv.ObservedComponents != null)
				{
					foreach (Component observedComponent in pv.ObservedComponents)
					{
						list.Add(((Object)(object)observedComponent != (Object)null) ? ((object)observedComponent).GetType().Name : "null");
					}
				}
				Component[] components = go.GetComponents<Component>();
				foreach (Component val in components)
				{
					list2.Add(((Object)(object)val != (Object)null) ? ((object)val).GetType().Name : "null");
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("tornado sync check: " + ex.Message);
			}
		}

		public override bool CanStart(out string why)
		{
			why = (Scouts.InKiln() ? "no tornados in the Kiln (like Kin)" : null);
			return why == null;
		}

		public override bool Start(out string why)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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)
			if (!CanStart(out why))
			{
				return false;
			}
			int num = Mathf.Min(S.TorAmount.Value, Spawns.Free());
			List<Vector3> list = new List<Vector3>();
			for (int i = 0; i < num; i++)
			{
				if (Scouts.GroundAway(S.TorMinDist.Value, out var pos))
				{
					list.Add(pos);
				}
			}
			if (list.Count == 0)
			{
				why = "no free ground far enough from the scouts";
				return false;
			}
			_ = list.Count;
			foreach (Vector3 item in list)
			{
				Vector3 p = item;
				Spawns.Enqueue(Name, delegate
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					GameObject val = Chaos.Net("Tornado", p, Quaternion.identity);
					if (Spawned(val))
					{
						Tornado t = val.GetComponent<Tornado>();
						PhotonView component = val.GetComponent<PhotonView>();
						if ((Object)(object)t != (Object)null)
						{
							Ours.Add(((Object)t).GetInstanceID());
						}
						_ = (Object)(object)component != (Object)null;
						Spawns.After(0.2f, delegate
						{
							if ((Object)(object)t != (Object)null && R.TornadoLife != null)
							{
								R.TornadoLife.Invoke(t) = S.TorLifetime.Value;
							}
						});
						Spawns.Track(val, Name, S.TorLifetime.Value + 15f, delegate(GameObject g)
						{
							PhotonView component2 = g.GetComponent<PhotonView>();
							if ((Object)(object)component2 != (Object)null)
							{
								Send.Rpc(component2, "RPCA_TornadoDie", (RpcTarget)0);
							}
						});
					}
				});
			}
			RunningUntil = Time.time + S.TorLifetime.Value + 8f;
			return true;
		}

		private static Vector3 Flat(Vector3 v)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			v.y = 0f;
			return v;
		}

		internal static void PickTargetFor(Tornado t)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			string what;
			Transform val = Desired(out what);
			if ((Object)(object)val != (Object)null)
			{
				t.target = val;
				try
				{
					(Vector3.Distance(((Component)t).transform.position, val.position) * CharacterStats.unitsToMeters).ToString("0");
				}
				catch
				{
				}
			}
		}

		private static Transform Desired(out string what)
		{
			what = null;
			bool flag = S.TorTarget.Value switch
			{
				TornadoTarget.Both => Random.value < 0.5f, 
				TornadoTarget.Luggage => true, 
				_ => false, 
			};
			if (flag)
			{
				Luggage val = Scouts.PickLuggage(ref _lastLuggage);
				if ((Object)(object)val != (Object)null)
				{
					what = "luggage '" + ((Object)((Component)val).gameObject).name + "'";
					return ((Component)val).transform;
				}
			}
			Character val2 = Scouts.Pick(TargetMode.Random, ref _lastPlayer);
			if ((Object)(object)val2 != (Object)null && val2.refs != null && (Object)(object)val2.refs.hip != (Object)null)
			{
				what = "player " + Plugin.Who(val2) + (flag ? " (rolled luggage, but none outside the safezone)" : "");
				return val2.refs.hip.transform;
			}
			if (!flag)
			{
				Luggage val3 = Scouts.PickLuggage(ref _lastLuggage);
				if ((Object)(object)val3 != (Object)null)
				{
					what = "luggage '" + ((Object)((Component)val3).gameObject).name + "' (rolled player, but none eligible)";
					return ((Component)val3).transform;
				}
			}
			return null;
		}
	}
	internal class TumbleweedChaos : Chaos
	{
		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<Character> list2 = Chaos.PerScout(list, S.TumAmount.Value, Spawns.Free());
			if (list2.Count <= 0)
			{
				why = "object limit";
				return false;
			}
			float life = S.TumLifetime.Value;
			foreach (Character item in list2)
			{
				Character target = item;
				Spawns.Enqueue(Name, delegate
				{
					//IL_001f: 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_0049: Unknown result type (might be due to invalid IL or missing references)
					//IL_0053: Unknown result type (might be due to invalid IL or missing references)
					//IL_0058: Unknown result type (might be due to invalid IL or missing references)
					//IL_005d: Unknown result type (might be due to invalid IL or missing references)
					if (StillFor(target) && Scouts.GroundNear(target.Center, S.TumMin.Value, S.TumMax.Value, out var pos))
					{
						GameObject val = Chaos.Net("tumbleweed", pos + Vector3.up * 2f, Quaternion.identity);
						if (Spawned(val))
						{
							CountFor(target);
							RemoveAfterSeconds component = val.GetComponent<RemoveAfterSeconds>();
							if ((Object)(object)component != (Object)null)
							{
								component.seconds = life + 10f;
							}
							Spawns.Track(val, Name, life);
						}
					}
				});
			}
			return true;
		}
	}
	internal class TicksChaos : Chaos
	{
		public override bool IsRunning => Time.time < RunningUntil;

		private static int TicksOn(Character c)
		{
			int num = 0;
			try
			{
				foreach (KeyValuePair<Bugfix, Character> allAttachedBug in Bugfix.AllAttachedBugs)
				{
					if ((Object)(object)allAttachedBug.Key != (Object)null && (Object)(object)allAttachedBug.Value == (Object)(object)c)
					{
						num++;
					}
				}
			}
			catch (Exception)
			{
			}
			return num;
		}

		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			int num = 0;
			Dictionary<Character, int> dictionary = new Dictionary<Character, int>();
			foreach (Character item in list)
			{
				int num2 = S.TikAmount.Value - TicksOn(item);
				if (num2 > 0)
				{
					dictionary[item] = S.TikAmount.Value;
				}
				num += Mathf.Max(0, num2);
			}
			if (num == 0)
			{
				why = ((list.Count == 0) ? "no target" : "everyone already has enough ticks");
				return false;
			}
			foreach (Character key in dictionary.Keys)
			{
				int num3 = S.TikAmount.Value - TicksOn(key);
				for (int i = 0; i < num3; i++)
				{
					Character tc = key;
					Spawns.Enqueue(Name, delegate
					{
						//IL_0026: Unknown result type (might be due to invalid IL or missing references)
						//IL_002b: Unknown result type (might be due to invalid IL or missing references)
						if (!((Object)(object)tc == (Object)null) && !tc.data.dead)
						{
							GameObject val = Chaos.Net("BugfixOnYou", Vector3.zero, Quaternion.identity);
							if (Spawned(val))
							{
								Bugfix component = val.GetComponent<Bugfix>();
								if ((Object)(object)component != (Object)null)
								{
									component.AttachBug(((MonoBehaviourPun)tc).photonView.ViewID);
								}
								Spawns.Track(val, Name, float.MaxValue);
							}
						}
					});
				}
			}
			RunningUntil = Time.time + 2f;
			return true;
		}
	}
	internal class BalloonsChaos : Chaos
	{
		public override bool IsRunning => Time.time < RunningUntil;

		private static int Balloons(Character c)
		{
			try
			{
				return c.refs.balloons.currentBalloonCount;
			}
			catch
			{
				return -1;
			}
		}

		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			float pop = S.BalPopTime.Value;
			int num = 0;
			Dictionary<Character, int> dictionary = new Dictionary<Character, int>();
			foreach (Character item in list)
			{
				dictionary[item] = Balloons(item);
			}
			foreach (Character item2 in list)
			{
				for (int i = 0; i < S.BalAmount.Value; i++)
				{
					Character tc = item2;
					Spawns.Enqueue(Name, delegate
					{
						//IL_00ae: 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_0031: Unknown result type (might be due to invalid IL or missing references)
						if (!((Object)(object)tc == (Object)null) && !tc.data.dead)
						{
							GameObject val = Chaos.Net("TiedBalloon", tc.Center, Quaternion.identity);
							if (Spawned(val))
							{
								TiedBalloon component = val.GetComponent<TiedBalloon>();
								if (!((Object)(object)component == (Object)null))
								{
									component.popTime = pop;
									int num2 = 1;
									try
									{
										num2 = Mathf.Max(1, tc.refs.balloons.balloonColors.Length);
									}
									catch
									{
									}
									component.Init(tc.refs.balloons, tc.Center.y, Random.Range(0, num2));
									Spawns.Track(val, Name, pop + 5f, delegate(GameObject g)
									{
										TiedBalloon component2 = g.GetComponent<TiedBalloon>();
										if ((Object)(object)component2 != (Object)null)
										{
											component2.Pop();
										}
									});
								}
							}
						}
					});
					num++;
				}
			}
			_ = S.BalAmount.Value;
			RunningUntil = Time.time + pop + 2f;
			return true;
		}
	}
	internal class Earthquake : Chaos
	{
		public override bool IsRunning => Time.time < RunningUntil;

		public override bool Start(out string why)
		{
			//IL_006b: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009d: 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)
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			_ = S.EqFallTime.Value;
			_ = 0.3f;
			foreach (Character item in list)
			{
				Forces.Shake(item, S.EqShake.Value);
				Forces.Fall(item, S.EqFallTime.Value);
				if (S.EqGust.Value)
				{
					Vector2 insideUnitCircle = Random.insideUnitCircle;
					Vector2 normalized = ((Vector2)(ref insideUnitCircle)).normalized;
					float num = Mathf.Max(0.001f, Time.fixedDeltaTime);
					Forces.WholeBody(item, new Vector3(normalized.x, 0.25f, normalized.y) * (8f * S.EqGustPower.Value / num), (BodypartType)0);
				}
			}
			RunningUntil = Time.time + S.EqFallTime.Value + 2f;
			return true;
		}
	}
	internal class BridgeCollapse : Chaos
	{
		public override bool IsRunning => Time.time < RunningUntil;

		private static List<BreakableBridge> Candidates()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			List<BreakableBridge> list = new List<BreakableBridge>();
			try
			{
				BreakableBridge[] array = Object.FindObjectsByType<BreakableBridge>((FindObjectsSortMode)0);
				foreach (BreakableBridge val in array)
				{
					if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeInHierarchy && !val.isShaking && (R.BridgeFallen == null || !R.BridgeFallen.Invoke(val)) && !Scouts.InSafezone(((Component)val).transform.position))
					{
						list.Add(val);
					}
				}
			}
			catch (Exception)
			{
			}
			return list;
		}

		public override bool CanStart(out string why)
		{
			why = ((Candidates().Count == 0) ? "no vine bridge in this section" : null);
			return why == null;
		}

		public override bool Start(out string why)
		{
			why = null;
			List<BreakableBridge> list = Candidates();
			if (list.Count == 0)
			{
				why = "no vine bridge in this section";
				return false;
			}
			int num = Mathf.Min(S.BriAmount.Value, list.Count);
			List<BreakableBridge> list2 = new List<BreakableBridge>();
			for (int i = 0; i < num; i++)
			{
				int index = Random.Range(0, list.Count);
				BreakableBridge val = list[index];
				list.RemoveAt(index);
				PhotonView component = ((Component)val).GetComponent<PhotonView>();
				if (!((Object)(object)component == (Object)null))
				{
					_ = component.IsMine;
					Send.Rpc(component, "ShakeBridge_Rpc", (RpcTarget)0);
					list2.Add(val);
				}
			}
			RunningUntil = Time.time + 7f;
			return true;
		}
	}
	internal class ZombiesChaos : Chaos
	{
		public override bool Start(out string why)
		{
			why = null;
			List<List<Character>> groups = Scouts.Groups(LastTarget);
			if (groups.Count == 0)
			{
				why = "no target";
				return false;
			}
			int num = Mathf.Min(new int[3]
			{
				S.ZomAmount.Value,
				6 - Spawns.Alive(Name) - Spawns.Queued(Name),
				Spawns.Free()
			});
			if (num <= 0)
			{
				why = "zombie limit (" + 6 + ")";
				return false;
			}
			float life = S.ZomLifetime.Value;
			bool awake = S.ZomAwake.Value;
			if (awake)
			{
				_ = R.ZombieWake == null;
			}
			for (int i = 0; i < num; i++)
			{
				Spawns.Enqueue(Name, delegate
				{
					//IL_004a: Unknown result type (might be due to invalid IL or missing references)
					//IL_004b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0055: Unknown result type (might be due to invalid IL or missing references)
					//IL_005a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0078: Unknown result type (might be due to invalid IL or missing references)
					Vector3 pos;
					Character who;
					int num2 = Scouts.GroundNearGroup(groups, 0, S.ZomMin.Value, S.ZomMax.Value, out pos, out who);
					if (num2 >= 0)
					{
						_ = 0;
						LastTarget = Scouts.ActorOf(who);
						GameObject val = Chaos.Net("MushroomZombie", pos + Vector3.up * 0.5f, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
						if (Spawned(val))
						{
							CountFor(who);
							MushroomZombie z = val.GetComponent<MushroomZombie>();
							_ = (Object)(object)z == (Object)null;
							Spawns.Track(val, Name, life, delegate(GameObject g)
							{
								MushroomZombie component = g.GetComponent<MushroomZombie>();
								if ((Object)(object)component != (Object)null)
								{
									component.DestroyZombie();
								}
								else
								{
									Spawns.Destroy(g);
								}
							});
							if (awake && (Object)(object)z != (Object)null && R.ZombieWake != null)
							{
								Spawns.After(1.3f, delegate
								{
									if ((Object)(object)z != (Object)null)
									{
										R.ZombieWake.Invoke(z, null);
									}
								});
							}
						}
					}
				});
			}
			_ = awake;
			return true;
		}
	}
	internal static class Dbg
	{
		private const string P = "KCH_PRIVATE";

		private static readonly List<GameObject> _none = new List<GameObject>();

		[Conditional("KCH_PRIVATE")]
		internal static void Fail(string where, string why)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Skip(string where, string why)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Ex(string where, Exception e)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Once(string key, string msg)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Info(string msg)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Count(string key, int add = 1)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Sched(string reason)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Begin(string chaos, string info)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void N(string chaos, string key, int add = 1)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Note(string chaos, string note)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Keep(string chaos, GameObject go)
		{
		}

		internal static List<GameObject> Kept(string chaos)
		{
			return _none;
		}

		[Conditional("KCH_PRIVATE")]
		internal static void CheckAt(string chaos, float delay, string label, Func<string> test)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Manual(string chaos)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void End(string chaos, bool ok, string reason)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void GroundFail(string chaos)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void CheckRpc(PhotonView pv, string method, object[] args)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void SelfTest()
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Section(int segment)
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Tick()
		{
		}

		[Conditional("KCH_PRIVATE")]
		internal static void SceneChanged(string scene)
		{
		}
	}
	internal static class Send
	{
		internal static void Rpc(PhotonView pv, string method, RpcTarget target, params object[] args)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)pv == (Object)null))
			{
				pv.RPC(method, target, args);
			}
		}

		internal static void Rpc(PhotonView pv, string method, Player to, params object[] args)
		{
			if (!((Object)(object)pv == (Object)null))
			{
				pv.RPC(method, to, args);
			}
		}
	}
	internal static class Forces
	{
		internal const float MAX_DV = 45f;

		private const float STEP = 0.025f;

		private static readonly Dictionary<long, float> _acc = new Dictionary<long, float>();

		private static Player Owner(Character c)
		{
			try
			{
				return ((MonoBehaviourPun)c).photonView.Owner;
			}
			catch
			{
				return null;
			}
		}

		private static bool InSafezone(Character c)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (!Scouts.InSafezone(c.Center))
			{
				return false;
			}
			return true;
		}

		private static void ToOwner(Character c, string rpc, params object[] args)
		{
			Player val = Owner(c);
			if (val != null)
			{
				Send.Rpc(((MonoBehaviourPun)c).photonView, rpc, val, args);
			}
			else
			{
				Send.Rpc(((MonoBehaviourPun)c).photonView, rpc, (RpcTarget)0, args);
			}
		}

		private static float MinPartMass(Character c)
		{
			float num = float.MaxValue;
			try
			{
				foreach (Bodypart part in c.refs.ragdoll.partList)
				{
					if ((Object)(object)part != (Object)null && (Object)(object)part.Rig != (Object)null)
					{
						num = Mathf.Min(num, part.Rig.mass);
					}
				}
			}
			catch (Exception)
			{
			}
			if (num != float.MaxValue && !(num <= 0f))
			{
				return num;
			}
			return 1f;
		}

		internal static void WholeBody(Character c, Vector3 move, BodypartType part = (BodypartType)0)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!((Object)(object)c == (Object)null) && !(((Vector3)(ref move)).sqrMagnitude < 1E-06f) && !InSafezone(c))
			{
				float num = Mathf.Max(0.001f, Time.fixedDeltaTime);
				float num2 = ((Vector3)(ref move)).magnitude * num;
				if (num2 > 45f)
				{
					move *= 45f / num2;
				}
				ToOwner(c, "RPCA_AddForceToBodyPart", part, Vector3.zero, move);
			}
		}

		internal static void Impulse(Character c, Vector3 impulse, Vector3 point, float radius)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)c == (Object)null) && !(((Vector3)(ref impulse)).sqrMagnitude < 1E-06f) && !InSafezone(c))
			{
				float num = ((Vector3)(ref impulse)).magnitude / MinPartMass(c);
				if (num > 45f)
				{
					impulse *= 45f / num;
				}
				ToOwner(c, "RPCA_AddForceAtPosition", impulse, point, radius);
			}
		}

		internal static void Fall(Character c, float seconds)
		{
			if (!((Object)(object)c == (Object)null) && !(seconds <= 0f) && !InSafezone(c))
			{
				Send.Rpc(((MonoBehaviourPun)c).photonView, "RPCA_Fall", (RpcTarget)0, seconds, 0f);
			}
		}

		internal static void Shake(Character c, float shake)
		{
			if (!((Object)(object)c == (Object)null) && !(shake <= 0f) && !InSafezone(c))
			{
				ToOwner(c, "RPCA_Fall", 0f, shake);
			}
		}

		internal static void SendStatus(Character c, STATUSTYPE type, float amount)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected I4, but got Unknown
			if (!((Object)(object)c == (Object)null) && !(amount <= 0f) && !InSafezone(c))
			{
				float[] array = new float[CharacterAfflictions.NumStatusTypes];
				int num = (int)type;
				if (num >= 0 && num < array.Length)
				{
					array[num] = amount;
					ToOwner(c, "RPC_ApplyStatusesFromFloatArray", array);
				}
			}
		}

		internal static void AddStatus(Character c, STATUSTYPE type, float amount)
		{
			//IL_0020: 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)
			if (!((Object)(object)c == (Object)null) && !(amount <= 0f))
			{
				long key = ((long)((MonoBehaviourPun)c).photonView.ViewID << 8) | (long)type;
				_acc.TryGetValue(key, out var value);
				value += amount;
				if (value >= 0.025f)
				{
					float num = Mathf.Floor(value / 0.025f) * 0.025f;
					value -= num;
					SendStatus(c, type, num);
				}
				_acc[key] = value;
			}
		}

		internal static void ResetStatus()
		{
			_acc.Clear();
		}
	}
	internal abstract class DoggyChaos : Chaos
	{
		protected static GameObject Room(string item, Vector3 pos, Quaternion rot)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			try
			{
				val = PhotonNetwork.InstantiateItemRoom(item, pos, rot, false);
			}
			catch (Exception)
			{
				return null;
			}
			_ = (Object)(object)val == (Object)null;
			return val;
		}

		protected static Vector3 Head(Character c)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Scouts.Part(c, (BodypartType)4);
			if (!((Object)(object)val != (Object)null))
			{
				return c.Center;
			}
			return val.position;
		}

		protected static Vector3 Torso(Character c)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Scouts.Part(c, (BodypartType)2);
			if (!((Object)(object)val != (Object)null))
			{
				return c.Center;
			}
			return val.position;
		}

		protected static Vector3 Look(Character c, bool flat)
		{
			//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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			try
			{
				val = (flat ? c.data.lookDirection_Flat : c.data.lookDirection);
			}
			catch
			{
			}
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = ((Component)c).transform.forward;
			}
			return ((Vector3)(ref val)).normalized;
		}

		protected static Vector3 Nudge(int k, float units)
		{
			//IL_002b: 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_0004: Unknown result type (might be due to invalid IL or missing references)
			if (k <= 0)
			{
				return Vector3.zero;
			}
			float num = Random.Range(0f, MathF.PI * 2f);
			return new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)) * units;
		}

		protected static List<int> Counts(List<Character> order)
		{
			Dictionary<Character, int> dictionary = new Dictionary<Character, int>();
			List<int> list = new List<int>();
			foreach (Character item in order)
			{
				dictionary.TryGetValue(item, out var value);
				list.Add(value);
				dictionary[item] = value + 1;
			}
			return list;
		}
	}
	internal class BounceShrooms : DoggyChaos
	{
		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<Character> list2 = Chaos.PerScoutF(list, S.BouPerScout.Value, Spawns.Free());
			if (list2.Count == 0)
			{
				why = "object limit";
				return false;
			}
			List<int> list3 = DoggyChaos.Counts(list2);
			float life = S.BouLifetime.Value;
			for (int i = 0; i < list2.Count; i++)
			{
				Character target = list2[i];
				int k = list3[i];
				Spawns.Enqueue(Name, delegate
				{
					//IL_001f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					//IL_002e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0033: Unknown result type (might be due to invalid IL or missing references)
					//IL_0043: Unknown result type (might be due to invalid IL or missing references)
					//IL_0048: Unknown result type (might be due to invalid IL or missing references)
					//IL_004d: 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_0054: Unknown result type (might be due to invalid IL or missing references)
					if (StillFor(target))
					{
						Vector3 pos = Scouts.Feet(target) - Vector3.up * 0.5f + DoggyChaos.Nudge(k, 1.5f);
						GameObject go = DoggyChaos.Room("BounceShroomSpawn", pos, Quaternion.identity);
						if (Spawned(go))
						{
							CountFor(target);
							Spawns.Track(go, Name, life);
						}
					}
				});
			}
			return true;
		}
	}
	internal class AntigravityFields : DoggyChaos
	{
		public override bool IsRunning
		{
			get
			{
				if (!(Time.time < RunningUntil))
				{
					return Spawns.Queued(Name) > 0;
				}
				return true;
			}
		}

		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<Character> list2 = Chaos.PerScoutF(list, S.AntPerScout.Value, int.MaxValue);
			List<int> list3 = DoggyChaos.Counts(list2);
			for (int i = 0; i < list2.Count; i++)
			{
				Character target = list2[i];
				int k = list3[i];
				Spawns.Enqueue(Name, delegate
				{
					//IL_001f: Unknown result type (might be due to invalid IL or missing references)
					//IL_002f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0034: Unknown result type (might be due to invalid IL or missing references)
					//IL_0039: Unknown result type (might be due to invalid IL or missing references)
					if (StillFor(target))
					{
						GameObject go = Chaos.Net("AntiSphere_Projectile", DoggyChaos.Torso(target) + DoggyChaos.Nudge(k, 4f), Quaternion.identity);
						if (Spawned(go))
						{
							CountFor(target);
						}
					}
				});
			}
			RunningUntil = Time.time + 5f;
			return true;
		}
	}
	internal class Chains : DoggyChaos
	{
		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<Character> list2 = Chaos.PerScoutF(list, S.ChaPerScout.Value, Spawns.Free());
			if (list2.Count == 0)
			{
				why = "object limit";
				return false;
			}
			List<int> list3 = DoggyChaos.Counts(list2);
			float life = S.ChaLifetime.Value;
			for (int i = 0; i < list2.Count; i++)
			{
				Character target = list2[i];
				int k = list3[i];
				Spawns.Enqueue(Name, delegate
				{
					//IL_0090: Unknown result type (might be due to invalid IL or missing references)
					//IL_001f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0024: 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_0031: 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_0061: 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_007b: 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_005a: Unknown result type (might be due to invalid IL or missing references)
					//IL_005f: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
					//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
					//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ee: 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_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_007c: Unknown result type (might be due to invalid IL or missing references)
					//IL_007d: Unknown result type (might be due to invalid IL or missing references)
					//IL_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_013b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0144: Unknown result type (might be due to invalid IL or missing references)
					//IL_0157: Unknown result type (might be due to invalid IL or missing references)
					if (StillFor(target))
					{
						Vector3 val = DoggyChaos.Torso(target);
						Vector3 val2 = DoggyChaos.Look(target, flat: false);
						if (k > 0)
						{
							val2 = Quaternion.Euler(0f, Random.Range(-60f, 60f), 0f) * val2;
						}
						Vector3 val3 = val + val2 * S.U(S.ChaMaxLen.Value);
						RaycastHit val4;
						try
						{
							val4 = HelperFunctions.LineCheck(val, val3, (LayerType)1, 0f, (QueryTriggerInteraction)1);
						}
						catch (Exception)
						{
							val4 = default(RaycastHit);
						}
						if ((Object)(object)((RaycastHit)(ref val4)).transform != (Object)null)
						{
							val3 = ((RaycastHit)(ref val4)).point;
						}
						float num = Random.Range(-3f, 0f);
						Vector3 val5 = (val + val3) / 2f + new Vector3(0f, num, 0f);
						GameObject val6 = Chaos.Net("ChainShootable", val, Quaternion.identity);
						if (Spawned(val6))
						{
							CountFor(target);
							Send.Rpc(val6.GetComponent<PhotonView>(), "ForceBuildVine_RPC", (RpcTarget)3, val, val3, num, val5);
							Spawns.Track(val6, Name, life);
						}
					}
				});
			}
			return true;
		}
	}
	internal class MandrakeRain : DoggyChaos
	{
		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<Character> list2 = Chaos.PerScoutF(list, S.ManPerScout.Value, Spawns.Free());
			if (list2.Count == 0)
			{
				why = "object limit";
				return false;
			}
			float life = S.ManLifetime.Value;
			bool scream = S.ManScream.Value;
			float height = S.U(S.ManHeight.Value);
			foreach (Character item in list2)
			{
				Character target = item;
				Spawns.Enqueue(Name, delegate
				{
					//IL_001f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0043: Unknown result type (might be due to invalid IL or missing references)
					//IL_0044: 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_0078: Unknown result type (might be due to invalid IL or missing references)
					//IL_007d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0083: Unknown result type (might be due to invalid IL or missing references)
					//IL_0084: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
					//IL_00df: Unknown result type (might be due to invalid IL or missing references)
					if (StillFor(target) && Scouts.GroundNear(target.Center, S.ManMin.Value, S.ManMax.Value, out var pos))
					{
						Vector3 val = pos + Vector3.up * height;
						Quaternion val2 = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f);
						GameObject val3 = Chaos.Net("0_Items/Mandrake", val, val2);
						if (Spawned(val3))
						{
							CountFor(target);
							PhotonView component = val3.GetComponent<PhotonView>();
							Send.Rpc(component, "SetKinematicRPC", (RpcTarget)0, false, val, val2);
							if (scream)
							{
								Send.Rpc(component, "RPC_Scream", (RpcTarget)0);
							}
							Spawns.Track(val3, Name, life);
						}
					}
				});
			}
			return true;
		}
	}
	internal class Ghosts : DoggyChaos
	{
		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<Character> list2 = Chaos.PerScoutF(list, S.GhoPerScout.Value, Spawns.Free());
			if (list2.Count == 0)
			{
				why = "object limit";
				return false;
			}
			List<int> list3 = DoggyChaos.Counts(list2);
			GhostType type = S.GhoType.Value;
			_ = R.GhostSetTarget == null;
			for (int i = 0; i < list2.Count; i++)
			{
				Character target = list2[i];
				int k = list3[i];
				Spawns.Enqueue(Name, delegate
				{
					//IL_004d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0052: Unknown result type (might be due to invalid IL or missing references)
					//IL_005a: Unknown result type (might be due to invalid IL or missing references)
					//IL_005f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0082: Unknown result type (might be due to invalid IL or missing references)
					//IL_0087: Unknown result type (might be due to invalid IL or missing references)
					//IL_0088: Unknown result type (might be due to invalid IL or missing references)
					//IL_008d: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b8: 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_00c3: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
					//IL_0091: Unknown result type (might be due to invalid IL or missing references)
					//IL_0092: Unknown result type (might be due to invalid IL or missing references)
					//IL_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_00a6: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b1: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e4: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
					//IL_0155: Unknown result type (might be due to invalid IL or missing references)
					//IL_0168: Unknown result type (might be due to invalid IL or missing references)
					if (StillFor(target))
					{
						bool flag = type == GhostType.Chaser || (type == GhostType.Both && Random.value < 0.5f);
						Vector3 val = DoggyChaos.Head(target);
						Vector3 val2 = DoggyChaos.Look(target, flat: true);
						if (k > 0)
						{
							val2 = Quaternion.Euler(0f, Random.Range(-90f, 90f), 0f) * val2;
						}
						Vector3 pos = (flag ? (val + Vector3.up * 3f + val2 * 20f) : (val - Vector3.up * 3f + val2 * 3f));
						GameObject val3 = Chaos.Net("GhostBall", pos, Quaternion.LookRotation(-val2));
						if (Spawned(val3))
						{
							CountFor(target);
							GhostBall component = val3.GetComponent<GhostBall>();
							if ((Object)(object)component == (Object)null)
							{
								Spawns.Track(val3, Name, 20f);
							}
							else
							{
								component.chaseHeight = val.y + 1f;
								component.maxHeight = val.y + 1f;
								float lifetime;
								if (flag)
								{
									component.timeBeforeExplosion = 4f;
									component.timeBeforeNoGoingBackImGonnaExplode = 3.5f;
									component.lifetime = Random.Range(6f, 12f);
									component.repelZoneBuffer = float.NegativeInfinity;
									lifetime = component.lifetime + 5f;
								}
								else
								{
									component.timeBeforeExplosion = Random.Range(10f, 15f);
									component.timeBeforeNoGoingBackImGonnaExplode = 1f;
									lifetime = component.timeBeforeExplosion + 5f;
								}
								try
								{
									if (R.GhostSetTarget != null)
									{
										R.GhostSetTarget.Invoke(component, new object[1] { target });
									}
								}
								catch (Exception)
								{
								}
								Spawns.Track(val3, Name, lifetime);
							}
						}
					}
				});
			}
			return true;
		}
	}
	internal class Bees : DoggyChaos
	{
		public override bool Start(out string why)
		{
			why = null;
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<Character> list2 = Chaos.PerScoutF(list, S.BeePerScout.Value, Spawns.Free());
			if (list2.Count == 0)
			{
				why = "object limit";
				return false;
			}
			List<int> list3 = DoggyChaos.Counts(list2);
			float life = S.BeeLifetime.Value;
			for (int i = 0; i < list2.Count; i++)
			{
				Character target = list2[i];
				int k = list3[i];
				Spawns.Enqueue(Name, delegate
				{
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					//IL_0034: Unknown result type (might be due to invalid IL or missing references)
					//IL_0039: Unknown result type (might be due to invalid IL or missing references)
					//IL_003e: Unknown result type (might be due to invalid IL or missing references)
					if (StillFor(target))
					{
						GameObject val = Chaos.Net("BeeSwarm", DoggyChaos.Head(target) + DoggyChaos.Nudge(k, 2f), Quaternion.identity);
						if (Spawned(val))
						{
							CountFor(target);
							Send.Rpc(val.GetComponent<PhotonView>(), "SetBeesAngryRPC", (RpcTarget)3, true);
							Spawns.Track(val, Name, life);
						}
					}
				});
			}
			return true;
		}
	}
	internal class Treats : DoggyChaos
	{
		private static readonly Vector3 OutOfSight = new Vector3(0f, -9999f, 0f);

		public override bool IsRunning
		{
			get
			{
				if (!(Time.time < RunningUntil))
				{
					return Spawns.Queued(Name) > 0;
				}
				return true;
			}
		}

		private static List<string> EnabledSorts()
		{
			List<string> list = new List<string>();
			if (S.TreCureAll.Value)
			{
				list.Add("Cure-All");
			}
			if (S.TrePandora.Value)
			{
				list.Add("Pandora");
			}
			if (S.TreEnergy.Value)
			{
				list.Add("Energy Drink");
			}
			if (S.TreLollipop.Value)
			{
				list.Add("Lollipop");
			}
			if (S.TreMilk.Value)
			{
				list.Add("Milk");
			}
			return list;
		}

		public override bool CanStart(out string why)
		{
			why = ((EnabledSorts().Count == 0) ? "all treats are switched off" : null);
			return why == null;
		}

		public override bool Start(out string why)
		{
			if (!CanStart(out why))
			{
				return false;
			}
			List<Character> who = Scouts.AliveAll();
			who.RemoveAll((Character c) => Scouts.InSafezone(c.Center));
			if (who.Count == 0)
			{
				why = "no target";
				return false;
			}
			List<string> list = EnabledSorts();
			List<string> list2 = list.FindAll((string s) => s == "Energy Drink" || s == "Lollipop" || s == "Milk");
			List<string> list3 = ((list2.Count < 2 || Random.Range(0, 100) >= S.TreAllBuffs.Value) ? new List<string> { list[Random.Range(0, list.Count)] } : list2);
			foreach (string item in list3)
			{
				string sort = item;
				if (sort == "Cure-All" || sort == "Pandora")
				{
					foreach (Character item2 in who)
					{
						Character target = item2;
						Spawns.Enqueue(Name, delegate
						{
							Burst(sort, target);
						});
					}
				}
				else
				{
					Spawns.Enqueue(Name, delegate
					{
						Feed(sort, who);
					});
				}
			}
			RunningUntil = Time.time + 3f;
			return true;
		}

		private void Burst(string sort, Character target)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null || !Scouts.Alive(target) || Scouts.InSafezone(target.Center) || (sort == "Pandora" && target.data.isSkeleton))
			{
				return;
			}
			GameObject val = DoggyChaos.Room((sort == "Pandora") ? "PandorasBox" : "Cure-All", DoggyChaos.Head(target), Quaternion.identity);
			if (!Spawned(val))
			{
				return;
			}
			CountFor(target);
			Item component = val.GetComponent<Item>();
			if ((Object)(object)component == (Object)null)
			{
				Spawns.Track(val, Name, 5f);
				return;
			}
			if (sort == "Pandora")
			{
				Send.Rpc(((Component)component).GetComponent<PhotonView>(), "Consume", (RpcTarget)0, -1);
			}
			if ((Object)(object)component.cooking != (Object)null)
			{
				component.cooking.Explode();
			}
			Spawns.Track(val, Name, 5f);
		}

		private void Feed(string sort, List<Character> who)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			string item = ((sort == "Milk") ? "FortifiedMilk" : sort);
			int num = ((!(sort == "Milk")) ? 1 : 0);
			GameObject val = DoggyChaos.Room(item, OutOfSight, Quaternion.identity);
			if (!Spawned(val))
			{
				return;
			}
			Item component = val.GetComponent<Item>();
			if ((Object)(object)component == (Object)null)
			{
				Spawns.Track(val, Name, 1f);
				return;
			}
			Send.Rpc(((Component)component).GetComponent<PhotonView>(), "SetCookedAmountRPC", (RpcTarget)0, num);
			foreach (Character item2 in who)
			{
				if (!((Object)(object)item2 == (Object)null) && Scouts.Alive(item2) && !Scouts.InSafezone(item2.Center))
				{
					try
					{
						item2.FeedItem(component);
						CountFor(item2);
					}
					catch (Exception)
					{
					}
				}
			}
			Spawns.Track(val, Name, 1f);
		}
	}
	internal class SwapPlaces : DoggyChaos
	{
		public override bool IsRunning
		{
			get
			{
				if (!(Time.time < RunningUntil))
				{
					return Spawns.Queued(Name) > 0;
				}
				return true;
			}
		}

		private static bool InLava(Character c)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				float y = Scouts.Feet(c).y;
				foreach (LavaRising item in LavaRising.ALL_LAVA)
				{
					if ((Object)(object)item != (Object)null && (Object)(object)item.lava != (Object)null && ((Component)item.lava).transform.position.y + 2f >= y)
					{
						return true;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static List<Character> Players()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			List<Character> list = new List<Character>();
			foreach (Character allCharacter in Character.AllCharacters)
			{
				if (!Scouts.Alive(allCharacter) || (S.SkipPassedOut.Value && Scouts.PassedOut(allCharacter)) || Scouts.InSafezone(allCharacter.Center))
				{
					continue;
				}
				try
				{
					if (allCharacter.data.isInFog)
					{
						continue;
					}
				}
				catch
				{
				}
				if (!InLava(allCharacter))
				{
					list.Add(allCharacter);
				}
			}
			return list;
		}

		public override bool CanStart(out string why)
		{
			why = ((Players().Count < 2) ? "needs at least 2 scouts outside fog/lava and outside the safezone" : null);
			return why == null;
		}

		public override bool Start(out string why)
		{
			//IL_017e: 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_00d6: 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_00ea: 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_0151: 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)
			if (!CanStart(out why))
			{
				return false;
			}
			List<Character> list = Players();
			for (int num = list.Count - 1; num > 0; num--)
			{
				int index = Random.Range(0, num + 1);
				Character value = list[num];
				list[num] = list[index];
				list[index] = value;
			}
			List<Vector3> list2 = new List<Vector3>();
			foreach (Character item in list)
			{
				list2.Add(DoggyChaos.Torso(item));
			}
			for (int i = 0; i < list.Count; i++)
			{
				Character val = list[i];
				bool flag = false;
				try
				{
					flag = !val.data.isGrounded || val.data.isClimbingAnything;
				}
				catch
				{
				}
				if (flag)
				{
					GameObject val2 = DoggyChaos.Room("ShelfShroomSpawn", Scouts.Feet(val) - Vector3.up * 0.5f, Quaternion.identity);
					if ((Object)(object)val2 != (Object)null)
					{
						Spawns.Track(val2, Name + " shelf", 30f);
					}
				}
			}
			for (int j = 0; j < list.Count; j++)
			{
				Character val3 = list[j];
				Vector3 val4 = list2[(j + 1) % list.Count];
				try
				{
					val3.refs.climbing.StopAnyClimbing();
				}
				catch (Exception)
				{
				}
				Send.Rpc(((MonoBehaviourPun)val3).photonView, "WarpPlayerRPC", (RpcTarget)0, val4, true);
				CountFor(val3);
			}
			RunningUntil = Time.time + 3f;
			return true;
		}
	}
	internal class Skeleton : DoggyChaos
	{
		private readonly List<Character> _turned = new List<Character>();

		private float _until;

		public override bool IsRunning => Time.time < _until;

		public override bool CanStart(out string why)
		{
			why = ((Time.time < _until) ? "a skeleton wave is still running" : null);
			return why == null;
		}

		public override bool Start(out string why)
		{
			if (!CanStart(out why))
			{
				return false;
			}
			List<Character> list = Scouts.Eligible();
			if (list.Count == 0)
			{
				why = "no target";
				return false;
			}
			_turned.Clear();
			foreach (Character item in list)
			{
				try
				{
					if (!item.data.isSkeleton)
					{
						item.data.SetSkeleton(true);
						_turned.Add(item);
						CountFor(item);
					}
				}
				catch (Exception)
				{
				}
			}
			if (_turned.Count == 0)
			{
				why = "everyone is already a skeleton";
				return false;
			}
			float num = S.SkeMin.Value;
			float num2 = S.SkeMax.Value;
			if (num2 < num)
			{
				float num3 = num;
				num = num2;
				num2 = num3;
			}
			float num4 = Random.Range(num, num2);
			_until = Time.time + num4;
			Spawns.After(num4, Cure);
			return true;
		}

		private void Cure()
		{
			foreach (Character item in _turned)
			{
				try
				{
					if ((Object)(object)item != (Object)null && (Object)(object)item.data != (Object)null && item.data.isSkeleton)
					{
						item.data.SetSkeleton(false);
					}
				}
				catch (Exception)
				{
				}
			}
			_turned.Clear();
			_until = 0f;
		}

		public override void Despawn()
		{
			Cure();
		}
	}
	internal static class Patches
	{
		internal static int Ok;

		internal static int Total;

		internal static readonly List<string> Missing = new List<string>();

		internal static readonly List<BananaPeel> Peels = new List<BananaPeel>();

		private static readonly Dictionary<long, float> _tumbleHit = new Dictionary<long, float>();

		internal static readonly Dictionary<int, float> _lastPick = new Dictionary<int, float>();

		private static void P(Harmony h, Type t, string method, string prefix = null, string postfix = null, Type[] args = null)
		{
			//IL_0069: 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)
			Total++;
			try
			{
				MethodInfo methodInfo = ((args == null) ? AccessTools.Method(t, method, (Type[])null, (Type[])null) : AccessTools.Method(t, method, args, (Type[])null));
				if (methodInfo == null)
				{
					Missing.Add(t.Name + "." + method);
					return;
				}
				h.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Patches).GetMethod(prefix, BindingFlags.Static | BindingFlags.NonPublic)), (postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Patches).GetMethod(postfix, BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Ok++;
			}
			catch (Exception ex)
			{
				Missing.Add(t.Name + "." + method + " (" + ex.GetType().Name + ")");
			}
		}

		internal static void Apply(Harmony h)
		{
			P(h, typeof(BananaPeel), "Start", null, "BananaStart");
			P(h, typeof(BananaPeel), "RPCA_TriggerBanana", null, "BananaSlip");
			P(h, typeof(TumbleWeed), "Start", null, "TumbleStart");
			P(h, typeof(TumbleWeed), "OnCollisionEnter", "TumbleHit");
			P(h, typeof(AOE), "Explode", null, "AoeExplode");
			P(h, typeof(Tornado), "PickTarget", "TornadoPick");
			P(h, typeof(Tornado), "Movement", "TornadoMove");
			P(h, typeof(Tornado), "RPCA_ThrowPlayer", null, "TornadoThrow");
			P(h, typeof(Scoutmaster), "VerifyTarget", "SmVerify");
			P(h, typeof(Scoutmaster), "HoldPlayer", "SmHold");
			P(h, typeof(Scoutmaster), "DoVisuals", "SmVisuals");
			P(h, typeof(CharacterAfflictions), "RPC_PetrifyInstantly", "DaggerPetrifyPrefix");
			P(h, typeof(PetrifiedScout), "RPC_SpawnPetrifiedScout", "DaggerStatuePrefix");
		}

		private static void DaggerPetrifyPrefix(CharacterAfflictions __instance, bool killedByDagger)
		{
			if (killedByDagger)
			{
				Plugin.Safe("peak safezone (dagger)", delegate
				{
					PeakZone.OnDaggerDeath(((Object)(object)__instance != (Object)null) ? __instance.character : null, "petrify");
				});
			}
		}

		private static void DaggerStatuePrefix(int characterID, bool killedByDagger)
		{
			if (!killedByDagger)
			{
				return;
			}
			Plugin.Safe("peak safezone (statue)", delegate
			{
				Character c = default(Character);
				if (Character.GetCharacterWithPhotonID(characterID, ref c))
				{
					PeakZone.OnDaggerDeath(c, "statue");
				}
			});
		}

		private static void BananaStart(BananaPeel __instance)
		{
			try
			{
				if ((Object)(object)__instance != (Object)null)
				{
					Peels.Add(__instance);
				}
			}
			catch (Exception)
			{
			}
		}

		private static void BananaSlip(int viewID)
		{
			//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_00bd: 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_00d3: 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_007e: 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_0095: 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)
			try
			{
				if (!Plugin.Host)
				{
					return;
				}
				float value = S.BanSlipPower.Value;
				bool value2 = S.BanDastardly.Value;
				if (value <= 1f && !value2)
				{
					return;
				}
				PhotonView val = PhotonView.Find(viewID);
				Character val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Character>() : null);
				if (!((Object)(object)val2 == (Object)null))
				{
					if (value2)
					{
						Vector3 val3 = default(Vector3);
						((Vector3)(ref val3))..ctor(Random.Range(-1f, 1f), 0.5f, -1f);
						Forces.WholeBody(val2, val3 * 40f * Mathf.Max(value, 1f) * 1.75f, (BodypartType)4);
					}
					else
					{
						Forces.WholeBody(val2, (val2.data.lookDirection_Flat + Vector3.up) * 40f * (value - 1f) * 1.75f, (BodypartType)4);
					}
				}
			}
			catch (Exception)
			{
			}
		}

		private static void TumbleStart(TumbleWeed __instance)
		{
			try
			{
				if (Plugin.Host && (Object)(object)__instance != (Object)null && S.TumSpeed.Value != 1f)
				{
					__instance.rollForce *= S.TumSpeed.Value;
				}
				if (Plugin.Host && (Object)(object)__instance != (Object)null)
				{
					Rigidbody component = ((Component)__instance).GetComponent<Rigidbody>();
					if ((Object)(object)component != (Object)null && !component.isKinematic)
					{
						component.collisionDetectionMode = (CollisionDetectionMode)2;
					}
				}
			}
			catch (Exception)
			{
			}
		}

		private static void TumbleHit(TumbleWeed __instance, Collision collision)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007e: 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_0095: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_0105: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Plugin.Host || (Object)(object)__instance == (Object)null || collision == null)
				{
					return;
				}
				Rigidbody component = ((Component)__instance).GetComponent<Rigidbody>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				Vector3 val2;
				if (S.TumBouncy.Value)
				{
					PhotonView component2 = ((Component)__instance).GetComponent<PhotonView>();
					if (component2 != null && component2.IsMine && collision.contactCount > 0)
					{
						ContactPoint val = collision.GetContact(0);
						for (int i = 1; i < collision.contactCount; i++)
						{
							ContactPoint contact = collision.GetContact(i);
							if (Vector3.Distance(((Component)__instance).transform.position, ((ContactPoint)(ref contact)).point) > Vector3.Distance(((Component)__instance).transform.position, ((ContactPoint)(ref val)).point))
							{
								val = contact;
							}
						}
						val2 = ((Component)__instance).transform.position - ((ContactPoint)(ref val)).point;
						Vector3 normalized = ((Vector3)(ref val2)).normalized;
						val2 = component.linearVelocity;
						component.AddForce(normalized * ((Vector3)(ref val2)).magnitude * S.TumBouncePower.Value * 1000f);
					}
				}
				float value = S.TumHitPower.Value;
				Character val3 = default(Character);
				if (value <= 1f || !CharacterRagdoll.TryGetCharacterFromCollider(collision.collider, ref val3) || (Object)(object)val3 == (Object)null || !Scouts.IsPlayer(val3))
				{
					return;
				}
				long key = ((long)((Object)__instance).GetInstanceID() << 20) ^ ((MonoBehaviourPun)val3).photonView.ViewID;
				if (_tumbleHit.TryGetValue(key, out var value2) && Time.time - value2 < 1f)
				{
					return;
				}
				_tumbleHit[key] = Time.time;
				float num = ((R.TumbleOrigScale != null) ? R.TumbleOrigScale.Invoke(__instance) : 1f);
				float num2 = ((num == 0f) ? 1f : Mathf.Clamp01(((Component)__instance).transform.localScale.x / num));
				val2 = component.linearVelocity;
				float num3 = Mathf.Clamp01(((Vector3)(ref val2)).magnitude * num2 * __instance.powerMultiplier);
				if (__instance.testFullPower)
				{
					num3 = 1f;
				}
				if (!(num3 < 0.2f))
				{
					Forces.Fall(val3, 2f * num3 * (value - 1f));
					Vector3 val4;
					if (collision.contactCount <= 0)
					{
						val4 = val3.Center;
					}
					else
					{
						ContactPoint contact2 = collision.GetContact(0);
						val4 = ((ContactPoint)(ref contact2)).point;
					}
					Vector3 point = val4;
					Character c = val3;
					val2 = component.linearVelocity;
					Forces.Impulse(c, ((Vector3)(ref val2)).normalized * __instance.collisionForce * num3 * (value - 1f), point, 2f);
				}
			}
			catch (Exception)
			{
			}
		}

		private static void AoeExplode(AOE __instance)
		{
			//IL_00c3: 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_00d4: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Plugin.Host || (Object)(object)__instance == (Object)null || __instance.range == 0f || __instance.knockback <= 0f)
				{
					return;
				}
				float num = 1f;
				switch (((Object)__instance).name)
				{
				case "VFX_DynamiteExplosion(Clone)":
					num = S.ExDynamite.Value;
					break;
				case "VFX_SporeExploExplo(Clone)":
					num = S.ExSpore.Value;
					break;
				case "Explosion":
					num = S.ExGeyser.Value;
					break;
				case "VFX_BalloonPopWithKnockback(Clone)":
					num = S.ExEnergy.Value;
					break;
				}
				bool value = S.ExDastardly.Value;
				if (num <= 1f && !value)
				{
					return;
				}
				Collider[] array = Physics.OverlapSphere(((Component)__instance).transform.position, __instance.range, LayerMask.op_Implicit(HelperFunctions.GetMask(__instance.mask)));
				HashSet<Character> hashSet = new HashSet<Character>();
				Collider[] array2 = array;
				Character val = default(Character);
				for (int i = 0; i < array2.Length; i++)
				{
					if (!CharacterRagdoll.TryGetCharacterFromCollider(array2[i], ref val) || (Object)(object)val == (Object)null || !hashSet.Add(val) || !Scouts.IsPlayer(val))
					{
						continue;
					}
					float num2 = Vector3.Distance(((Component)__instance).transform.position, val.Center);
					if (num2 > __instance.range)
					{
						continue;
					}
					float num3 = R.Factor(__instance, num2);
					if (!(num3 < __instance.minFactor))
					{
						Vector3 val2;
						Vector3 val3;
						if (!__instance.useSingleDirection || !((Object)(object)__instance.singleDirectionForwardTF != (Object)null))
						{
							val2 = val.Center - ((Component)__instance).transform.position;
							val3 = ((Vector3)(ref val2)).normalized;
						}
						else
						{
							val3 = __instance.singleDirectionForwardTF.forward;
						}
						Vector3 val4 = val3;
						float num4 = __instance.knockback * num3;
						if (value)
						{
							Character c = val;
							val2 = new Vector3(Random.Range(-1f, 1f), 0.5f, -1f);
							Forces.WholeBody(c, ((Vector3)(ref val2)).normalized * num4 * Mathf.Max(num, 1f), (BodypartType)0);
						}
						else
						{
							Forces.WholeBody(val, val4 * num4 * (num - 1f), (BodypartType)0);
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}

		private static bool TornadoPick(Tornado __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return true;
				}
				int instanceID = ((Object)__instance).GetInstanceID();
				if (!TornadoChaos.Ours.Contains(instanceID))
				{
					return true;
				}
				if (!Plugin.Host)
				{
					return false;
				}
				if (_lastPick.TryGetValue(instanceID, out var value) && Time.time - value < 0.5f)
				{
					return false;
				}
				_lastPick[instanceID] = Time.time;
				TornadoChaos.PickTargetFor(__instance);
			}
			catch (Exception)
			{
			}
			return false;
		}

		private static bool TornadoMove(Tornado __instance)
		{
			//IL_0046: 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_00a7: 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_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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_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_0112: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Plugin.Host || (Object)(object)__instance == (Object)null || (Object)(object)__instance.target == (Object)null)
				{
					return true;
				}
				if (!TornadoChaos.Ours.Contains(((Object)__instance).GetInstanceID()))
				{
					return true;
				}
				if (Scouts.InSafezone(__instance.target.position))
				{
					__instance.target = null;
					return true;
				}
				float value = S.TorSpeed.Value;
				if (R.TornadoVel == null || R.TornadoPos == null)
				{
					return true;
				}
				ref Vector3 reference = ref R.TornadoVel.Invoke(__instance);
				ref Vector3 reference2 = ref R.TornadoPos.Invoke(__instance);
				Vector3 val = reference;
				Vector3 val2 = Vector3Extensions.Flat(__instance.target.position - reference2);
				reference = FRILerp.Lerp(val, ((Vector3)(ref val2)).normalized * (15f * value), 0.15f, true);
				reference2 += reference * Time.deltaTime;
				RaycastHit groundPosRaycast = HelperFunctions.GetGroundPosRaycast(reference2 + Vector3.up * 200f, (LayerType)2, 0f);
				if ((Object)(object)((RaycastHit)(ref groundPosRaycast)).transform != (Object)null)
				{
					Mathf.Abs(((RaycastHit)(ref groundPosRaycast)).point.y - reference2.y);
					_ = 100f;
					reference2.y = ((RaycastHit)(ref groundPosRaycast)).point.y;
				}
				((Component)__instance).transform.position = reference2;
				return false;
			}
			catch (Exception)
			{
				return true;
			}
		}

		private static void TornadoThrow(int targetView)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Plugin.Host && S.TorNice.Value)
				{
					PhotonView val = PhotonView.Find(targetView);
					Character val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Character>() : null);
					if (!((Object)(object)val2 == (Object)null))
					{
						Vector3 move = new Vector3(0f, S.TorThrowUp.Value ? 1000f : 0f, 1000f) * S.TorThrowPower.Value * 1.75f;
						Forces.WholeBody(val2, move, (BodypartType)4);
					}
				}
			}
			catch (Exception)
			{
			}
		}

		private static bool SmVerify(Scoutmaster __instance)
		{
			try
			{
				return !Plugin.Host || ScoutmasterChaos.Instance == null || !ScoutmasterChaos.Instance.HuntsWith(__instance);
			}
			catch (Exception)
			{
				return true;
			}
		}

		private static bool SmHold(Scoutmaster __instance)
		{
			try
			{
				if (Plugin.Host && ScoutmasterChaos.Instance != null && ScoutmasterChaos.Instance.HuntsWith(__instance))
				{
					return ScoutmasterChaos.Instance.Hold();
				}
			}
			catch (Exception)
			{
			}
			return true;
		}

		private static bool SmVisuals(Scoutmaster __instance)
		{
			try
			{
				if (Plugin.Host && ScoutmasterChaos.Instance != null && ScoutmasterChaos.Instance.HuntsWith(__instance))
				{
					return !ScoutmasterChaos.Instance.FadeVisuals(__instance);
				}
			}
			catch (Exception)
			{
			}
			return true;
		}
	}
	internal static class PeakZone
	{
		internal const float DURATION = 120f;

		private const float DEDUPE = 10f;

		private const byte CHAT_EVENT = 81;

		private const string WHITE = "#FFFFFF";

		private const string GREEN = "#00CC00";

		private const string RED = "#FF0000";

		private static float _until;

		private static Vector3 _centre;

		private static bool _haveCentre;

		private static int _lastView = -1;

		private static float _lastAt = -100f;

		internal static bool Active
		{
			get
			{
				if (_until > 0f)
				{
					return Time.time < _until;
				}
				return false;
			}
		}

		internal static string Status()
		{
			return "peak safezone " + Mathf.RoundToInt(2f) + " min per dagger sacrifice from biome 5 on";
		}

		internal static bool Contains(Vector3 p, float r)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (Active && _haveCentre)
			{
				return Vector3.Distance(p, _centre) < r;
			}
			return false;
		}

		internal static void SceneChanged(string scene)
		{
			_until = 0f;
			_haveCentre = false;
			_lastView = -1;
		}

		internal static void Tick()
		{
			if (!(_until <= 0f) && !(Time.time < _until))
			{
				_until = 0f;
				if (Plugin.Host)
				{
					Send(C("#FFFFFF", "[SAFEZONE] ") + C("#FF0000", "the peak is no longer safe"), "ended");
				}
			}
		}

		internal static void OnDaggerDeath(Character c, string how)
		{
			if (!Plugin.Host || (Object)(object)c == (Object)null || !Scouts.IsPlayer(c) || !InRun())
			{
				return;
			}
			int viewID = ((MonoBehaviourPun)c).photonView.ViewID;
			if (viewID == _lastView && Time.time - _lastAt < 10f)
			{
				return;
			}
			_lastView = viewID;
			_lastAt = Time.time;
			if (CurrentSegment() >= 4)
			{
				if (!_haveCentre && !FindCentre())
				{
					Plugin.Warn("peak safezone: " + Plugin.Who(c) + " was sacrificed (" + how + "), but this map has no flare box - no safezone");
				}
				else
				{
					_until = Time.time + 120f;
					string text = Mathf.FloorToInt(2f) + ":" + Mathf.RoundToInt(0f).ToString("00");
					Send(C("#FFFFFF", "[SAFEZONE] " + Plugin.Who(c) + " was sacrificed") + C("#00CC00", " - the peak is safe for " + text), "dagger " + how + ", flare box at " + ((Vector3)(ref _centre)).ToString("F1"));
				}
			}
		}

		private static int CurrentSegment()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				MapHandler instance = Singleton<MapHandler>.Instance;
				return (!((Object)(object)instance != (Object)null)) ? (-1) : ((int)instance.GetCurrentSegment());
			}
			catch
			{
				return -1;
			}
		}

		private static bool InRun()
		{
			//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)
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (!string.IsNullOrEmpty(name) && !(name == "Title") && !(name == "Airport"))
			{
				return !(name == "Pretitle");
			}
			return false;
		}

		private static bool FindCentre()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			EndgameFlareSpawner[] array = Object.FindObjectsByType<EndgameFlareSpawner>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			if (array == null || array.Length == 0)
			{
				return false;
			}
			Vector3 val = Vector3.zero;
			int num = 0;
			EndgameFlareSpawner[] array2 = array;
			foreach (EndgameFlareSpawner val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val += ((Component)val2).transform.position;
					num++;
				}
			}
			if (num == 0)
			{
				return false;
			}
			_centre = val / (float)num;
			_haveCentre = true;
			return true;
		}

		private static void Send(string line, string why)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			if (PhotonNetwork.InRoom)
			{
				object[] array = new object[4]
				{
					PhotonNetwork.LocalPlayer.NickName,
					line,
					PhotonNetwork.LocalPlayer.UserId,
					false
				};
				PhotonNetwork.RaiseEvent((byte)81, (object)array, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)1
				}, SendOptions.SendReliable);
			}
		}

		private static string C(string hex, string s)
		{
			return "<color=" + hex + ">" + s + "</color>";
		}
	}
	[BepInPlugin("kikischaoshell.peak.kch", "Kikis Chaos Hell", "1.12.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "kikischaoshell.peak.kch";

		public const string NAME = "Kikis Chaos Hell";

		public const string VERSION = "1.12.0";

		private const string BUILD = "public";

		internal static Plugin Instance;

		internal static ManualLogSource L;

		internal static bool Host;

		private Harmony _harmony;

		private readonly List<Chaos> _chaos = new List<Chaos>();

		private string _scene = "";

		private int _segment = -99;

		private float _holdUntil;

		private float _nextRollAt;

		private int _pendingWant;

		private float _pendingSince;

		private const float RED_WAIT_MAX = 90f;

		private bool _ready;

		private const float LOAD_HOLD = 12f;

		private static readonly Dictionary<string, float> _errAt = new Dictionary<string, float>();

		private void Awake()
		{
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Expected O, but got Unknown
			Instance = this;
			L = ((BaseUnityPlugin)this).Logger;
			S.Bind(((BaseUnityPlugin)this).Config);
			Add("Dynamite Rain", S.Dyn, new DynamiteRain(), Load.Red);
			Add("Caldera Hotspot", S.Hot, new CalderaHotspot(), Load.Green);
			Add("Banana Rain", S.Ban, new BananaRain(), Load.Red);
			Add("Healing Shroom Rain", S.Shr, new ShroomRain(), Load.Red);
			Add("Tornado", S.Tor, new TornadoChaos(), Load.Yellow);
			Add("Tumbleweed", S.Tum, new TumbleweedChaos(), Load.Red);
			Add("Ticks", S.Tik, new TicksChaos(), Load.Yellow);
			Add("Balloons", S.Bal, new BalloonsChaos(), Load.Yellow);
			Add("Earthquake", S.Eq, new Earthquake(), Load.Green);
			Add("Bridge Collapse", S.Bri, new BridgeCollapse(), Load.Green);
			Add("Scoutmaster", S.Sm, new ScoutmasterChaos(), Load.Yellow);
			Add("Zombies", S.Zom, new ZombiesChaos(), Load.Yellow);
			Add("Bounce Shrooms", S.Bou, new BounceShrooms(), Load.Yellow);
			Add("Antigravity Fields", S.Ant, new AntigravityFields(), Load.Yellow);
			Add("Chains", S.Cha, new Chains(), Load.Yellow);
			Add("Mandrake Rain", S.Man, new MandrakeRain(), Load.Yellow);
			Add("Ghosts", S.Gho, new Ghosts(), Load.Yellow);
			Add("Bees", S.Bee, new Bees(), Load.Yellow);
			Add("Treats", S.Tre, new Treats(), Load.Green);
			Add("Swap Places", S.Swp, new SwapPlaces(), Load.Green);
			Add("Skeleton", S.Ske, new Skeleton(), Load.Green);
			_harmony = new Harmony("kikischaoshell.peak.kch");
			Patches.Apply(_harmony);
			int num = R.Total - R.Missing.Count;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[KCH] Kikis Chaos Hell 1.12.0 (public) loaded - " + Patches.Ok + " of " + Patches.Total + " hooks ok, " + num + " of " + R.Total + " game members ok | host-only | " + _chaos.Count + " chaos | " + PeakZone.Status()));
			if (Patches.Missing.Count > 0)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[KCH] HOOK MISSING: " + string.Join(", ", Patches.Missing.ToArray())));
			}
			if (R.Missing.Count > 0)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[KCH] GAME MEMBER MISSING: " + string.Join(", ", R.Missing.ToArray())));
			}
		}

		private void Add(string name, ChaosCfg cfg, Chaos c, Load color)
		{
			c.Name = name;
			c.Cfg = cfg;
			c.Color = color;
			_chaos.Add(c);
		}

		[Conditional("KCH_PRIVATE")]
		internal static void Log(string msg)
		{
			if (L != null)
			{
				L.LogInfo((object)("[KCH] " + msg));
			}
		}

		internal static void Warn(string msg)
		{
			if (L != null)
			{
				L.LogWarning((object)("[KCH] " + msg));
			}
		}

		internal static string Who(Character c)
		{
			try
			{
				string nickName = ((MonoBehaviourPun)c).photonView.Owner.NickName;
				return string.IsNullOrEmpty(nickName) ? "?" : Regex.Replace(nickName, "<[^>]*>", "");
			}
			catch
			{
				return "?";
			}
		}

		internal static void Safe(string where, Action a)
		{
			try
			{
				a();
			}
			catch (Exception ex)
			{
				if (!_errAt.TryGetValue(where, out var value) || Time.time - value > 10f)
				{
					_errAt[where] = Time.time;
					Warn(where + " threw " + ex.GetType().Name + ": " + ex.Message + " @ " + Top(ex));
				}
			}
		}

		internal static string Top(Exception e)
		{
			string text = e?.StackTrace;
			if (string.IsNullOrEmpty(text))
			{
				return "?";
			}
			List<string> list = new List<string>();
			string[] array = text.Split('\n');
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				if (text2.StartsWith("at "))
				{
					text2 = text2.Substring(3);
				}
				int num = text2.IndexOf(" [0x");
				if (num > 0)
				{
					text2 = text2.Substring(0, num);
				}
				num = text2.IndexOf(" (at ");
				if (num > 0)
				{
					text2 = text2.Substring(0, num);
				}
				if (text2.Length != 0)
				{
					list.Add(text2);
					if (list.Count == 3)
					{
						break;
					}
				}
			}
			return string.Join(" < ", list.ToArray());
		}

		private void Update()
		{
			//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)
			bool host = Host;
			try
			{
				Host = PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient;
			}
			catch
			{
				Host = false;
			}
			if (host)
			{
				_ = Host;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (name != _scene)
			{
				PeakZone.SceneChanged(name);
				_scene = name;
				Spawns.Reset();
				Forces.ResetStatus();
				Patches.Peels.Clear();
				TornadoChaos.Ours.Clear();
				Patches._lastPick.Clear();
				_segment = -99;
				_ready = false;
				_nextRollAt = 0f;
				_holdUntil = Time.time + 12f;
			}
			Spawns.Tick(Host);
			Safe("peak safezone", PeakZone.Tick);
			Safe("debugger", delegate
			{
			});
			if (!Host)
			{
				return;
			}
			bool num = InGame();
			if (num)
			{
				Safe("selftest", delegate
				{
				});
				Safe("caches", CheckSegment);
			}
			if (!num)
			{
				_ready = false;
				return;
			}
			foreach (Chaos chao in _chaos)
			{
				Chaos cc = chao;
				Safe("tick " + chao.Name, delegate
				{
					cc.Tick();
				});
			}
			Safe("weather", Weather.Tick);
			if (!S.Enabled.Value || Time.time < _holdUntil)
			{
				return;
			}
			if (!_ready)
			{
				_ready = true;
				_nextRollAt = Time.time + NextInterval();
			}
			if (Time.time >= _nextRollAt)
			{
				if (Roll())
				{
					_nextRollAt = Time.time + NextInterval();
				}
				else
				{
					_nextRollAt = Time.time + 1f;
				}
			}
		}

		private bool InGame()
		{
			if (_scene == "Title" || _scene == "Airport" || _scene == "Pretitle" || _scene.Length == 0)
			{
				return false;
			}
			try
			{
				MapHandler instance = Singleton<MapHandler>.Instance;
				if ((Object)(object)instance == (Object)null || (Object)(object)Character.localCharacter == (Object)null)
				{
					return false;
				}
				if (R.MapReady != null && !R.MapReady.Invoke(instance))
				{
					return false;
				}
				return true;
			}
			catch
			{
				return false;
			}
		}

		private void CheckSegment()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected I4, but got Unknown
			int num = (int)Singleton<MapHandler>.Instance.GetCurrentSegment();
			if (num == _segment)
			{
				return;
			}
			bool flag = _segment == -99;
			_segment = num;
			Scouts.RefreshCaches(num);
			foreach (Chaos chao in _chaos)
			{
				if (chao is CalderaHotspot calderaHotspot)
				{
					calderaHotspot.ResetCache();
				}
			}
			if (!flag)
			{
				_holdUntil = Mathf.Max(_holdUntil, Time.time + 12f);
			}
		}

		private float NextInterval()
		{
			float num = S.IntervalMin.Value;
			float num2 = S.IntervalMax.Value;
			if (num2 < num)
			{
				float num3 = num;
				num = num2;
				num2 = num3;
			}
			return Random.Range(num, num2);
		}

		internal static bool Fits(Chaos cand, List<Chaos> active)
		{
			if (active.Count == 0)
			{
				return true;
			}
			if (!cand.Cfg.AllowSimultaneous.Value)
			{
				return false;
			}
			foreach (Chaos item in active)
			{
				if (!item.Cfg.AllowSimultaneous.Value)
				{
					return false;
				}
			}
			return true;
		}

		private Chaos StartRed(List<Chaos> active, List<string> skipped, out bool wait)
		{
			wait = false;
			List<Chaos> list = new List<Chaos>();
			foreach (Chaos chao in _chaos)
			{
				if (chao.Color == Load.Red && chao.Cfg.Enabled.Value && !(chao.Cfg.Weight.Value <= 0f))
				{
					string why;
					if (chao.IsRunning || active.Contains(chao))
					{
						wait = true;
						skipped.Add(chao.Name + " still running (red)");
					}
					else if (!chao.CanStart(out why))
					{
						skipped.Add(chao.Name + ": " + why);
					}
					else if (!Fits(chao, active))
					{
						wait = true;
						skipped.Add(chao.Name + " waits (Allow Simultaneous off)");
					}
					else
					{
						list.Add(chao);
					}
				}
			}
			if (list.Count > 0)
			{
				wait = false;
			}
			wh