Decompiled source of EvenMoreMaps v0.7.3

EvenMoreMaps.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameEvent;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.7.3.0")]
[module: UnverifiableCode]
[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 EvenMoreMaps
{
	public class Ambience : MonoBehaviour
	{
		public string kind;

		public float param;

		private Vector3 basePos;

		private Vector3 baseScale;

		private Vector3 baseWorld;

		private float fallTop;

		private float fallBottom;

		private float ka;

		private float kb;

		private float tileW;

		private Quaternion baseRot;

		private SpriteRenderer sr;

		private Color baseColor;

		private float seed;

		public static void Attach(GameObject go, string kind)
		{
			Ambience ambience = go.AddComponent<Ambience>();
			string[] array = kind.Split(new char[1] { ':' });
			ambience.kind = array[0];
			if (array.Length > 1)
			{
				float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out ambience.param);
			}
		}

		private void Start()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			basePos = ((Component)this).transform.localPosition;
			baseScale = ((Component)this).transform.localScale;
			baseRot = ((Component)this).transform.localRotation;
			sr = ((Component)this).GetComponent<SpriteRenderer>();
			if ((Object)(object)sr != (Object)null)
			{
				baseColor = sr.color;
			}
			seed = (float)Mathf.Abs(((Object)this).name.GetHashCode() % 1000) * 0.137f;
			if (kind == "scroll")
			{
				float num;
				if (!((Object)(object)sr != (Object)null))
				{
					num = 1f;
				}
				else
				{
					Bounds bounds = ((Renderer)sr).bounds;
					num = Mathf.Max(0.01f, ((Bounds)(ref bounds)).size.x);
				}
				tileW = num;
			}
			if (kind == "fall")
			{
				baseWorld = ((Component)this).transform.position;
				StageData data = StageBuilder.Data;
				if (data != null && data.camera != null)
				{
					Rect val = data.WorldRect(data.camera);
					fallTop = ((Rect)(ref val)).yMax + 2f;
					fallBottom = ((Rect)(ref val)).yMin - 2f;
				}
				else
				{
					fallTop = baseWorld.y + 20f;
					fallBottom = baseWorld.y - 20f;
				}
				ka = Mathf.Repeat(seed * 7.31f, 1f);
				kb = Mathf.Repeat(seed * 3.17f, 1f);
			}
		}

		private float GustHere()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (Gust.Strength <= 0f)
			{
				return 0f;
			}
			Rect area = Gust.Area;
			float num = ((Rect)(ref area)).yMin - ((Component)this).transform.position.y;
			return Gust.Strength * Mathf.Clamp01(1f - num / 4f);
		}

		private void Update()
		{
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ec9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ef7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0efc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b09: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0791: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0585: Unknown result type (might be due to invalid IL or missing references)
			//IL_061a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0631: Unknown result type (might be due to invalid IL or missing references)
			//IL_0636: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f5f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b87: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a27: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a4d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a52: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0691: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e00: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e1a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e1f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e30: Unknown result type (might be due to invalid IL or missing references)
			//IL_087b: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0728: Unknown result type (might be due to invalid IL or missing references)
			//IL_0739: Unknown result type (might be due to invalid IL or missing references)
			//IL_075a: Unknown result type (might be due to invalid IL or missing references)
			//IL_075f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bd8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c07: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c0c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c1d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c30: Unknown result type (might be due to invalid IL or missing references)
			//IL_0837: Unknown result type (might be due to invalid IL or missing references)
			//IL_0848: Unknown result type (might be due to invalid IL or missing references)
			//IL_0864: Unknown result type (might be due to invalid IL or missing references)
			//IL_0869: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a10: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a15: Unknown result type (might be due to invalid IL or missing references)
			//IL_0914: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c8b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d01: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d14: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d25: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d3c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d41: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e56: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d91: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eb7: Unknown result type (might be due to invalid IL or missing references)
			float num = Time.time + seed;
			switch (kind)
			{
			case "flicker":
			{
				float num2 = 0.85f + 0.1f * Mathf.PerlinNoise(num * 3.1f, seed) + 0.05f * Mathf.Sin(num * 17f);
				if ((Object)(object)sr != (Object)null)
				{
					sr.color = new Color(baseColor.r, baseColor.g, baseColor.b, baseColor.a * num2);
				}
				((Component)this).transform.localScale = baseScale * (0.97f + 0.05f * num2);
				break;
			}
			case "bob":
				((Component)this).transform.localPosition = basePos + new Vector3(0f, 0.25f * Mathf.Sin(num * 1.3f), 0f);
				break;
			case "sway":
				((Component)this).transform.localRotation = baseRot * Quaternion.Euler(0f, 0f, 1.2f * Mathf.Sin(num * 0.9f) - 6f * GustHere() * Gust.Dir.x);
				break;
			case "pulse":
				if ((Object)(object)sr != (Object)null)
				{
					sr.color = new Color(baseColor.r, baseColor.g, baseColor.b, baseColor.a * (0.65f + 0.35f * Mathf.Sin(num * 1.1f)));
				}
				break;
			case "cloud":
				((Component)this).transform.localPosition = basePos + new Vector3(2.5f * Mathf.Sin(num * 0.045f + seed), 0f, 0f);
				break;
			case "flutter":
			{
				float num22 = GustHere();
				((Component)this).transform.localRotation = baseRot * Quaternion.Euler(0f, 0f, (7f + 9f * num22) * Mathf.Sin(num * (2.3f + 6f * num22)) + 3f * Mathf.Sin(num * 5.3f + seed) + 35f * num22 * Gust.Dir.x);
				((Component)this).transform.localScale = new Vector3(baseScale.x * (1f + (0.08f + 0.1f * num22) * Mathf.Sin(num * (6.1f + 8f * num22) + seed)), baseScale.y, baseScale.z);
				break;
			}
			case "fly":
			{
				float num13 = Mathf.Repeat(basePos.x + 15f + Time.time * 1.6f, 85f) - 15f;
				((Component)this).transform.localPosition = new Vector3(num13, basePos.y + 0.6f * Mathf.Sin(num * 0.4f) + 0.15f * Mathf.Sin(num * 2.1f), basePos.z);
				float num14 = ((Mathf.Repeat(num, 5f) < 1.6f) ? Mathf.Cos(num * 9f) : 1f);
				((Component)this).transform.localScale = new Vector3(baseScale.x, baseScale.y * (0.35f + 0.65f * num14), baseScale.z);
				break;
			}
			case "flow":
			{
				float num7 = Mathf.Repeat(Time.time / 1.8f + param, 1f);
				((Component)this).transform.localPosition = basePos + new Vector3(0f, -1.4f * num7, 0f);
				if ((Object)(object)sr != (Object)null)
				{
					sr.color = new Color(baseColor.r, baseColor.g, baseColor.b, baseColor.a * Mathf.Sin((float)Math.PI * num7));
				}
				break;
			}
			case "glide":
			{
				float num17 = ((param > 0f) ? param : 1.6f);
				float num18 = Mathf.Repeat(basePos.x + 15f + Time.time * num17, 85f) - 15f;
				((Component)this).transform.localPosition = new Vector3(num18, basePos.y + 0.7f * Mathf.Sin(num * 0.35f) + 0.12f * Mathf.Sin(num * 1.7f), basePos.z);
				((Component)this).transform.localRotation = baseRot * Quaternion.Euler(0f, 0f, 4f * Mathf.Cos(num * 0.35f));
				break;
			}
			case "circle":
			{
				float num11 = (Time.time / 22f + seed) * 2f * (float)Math.PI;
				((Component)this).transform.localPosition = basePos + new Vector3(5f * Mathf.Cos(num11), 1.3f * Mathf.Sin(num11) + 0.3f * Mathf.Sin(3f * num11), 0f);
				float num12 = ((Mathf.Sin(num11) > 0f) ? (-1f) : 1f);
				((Component)this).transform.localScale = new Vector3(Mathf.Abs(baseScale.x) * num12, baseScale.y * (0.9f - 0.1f * Mathf.Sin(num11)), baseScale.z);
				((Component)this).transform.localRotation = baseRot * Quaternion.Euler(0f, 0f, -9f * Mathf.Cos(num11));
				break;
			}
			case "mist":
				((Component)this).transform.localPosition = basePos + new Vector3(4f * Mathf.Sin(num * 0.08f), 0.2f * Mathf.Sin(num * 0.3f), 0f);
				if ((Object)(object)sr != (Object)null)
				{
					sr.color = new Color(baseColor.r, baseColor.g, baseColor.b, baseColor.a * (0.6f + 0.4f * Mathf.Sin(num * 0.13f)));
				}
				break;
			case "fall":
			{
				float num23 = ((param > 0f) ? param : 0.8f);
				float num24 = fallTop - fallBottom;
				float num25 = fallBottom + Mathf.Repeat(baseWorld.y - fallBottom - Time.time * num23, num24);
				float num26 = baseWorld.x + (0.2f + 0.3f * ka) * Mathf.Sin(num * (0.6f + 0.7f * kb)) + 0.06f * Mathf.Sin(num * 2.3f);
				((Component)this).transform.position = new Vector3(num26, num25, baseWorld.z);
				((Component)this).transform.localRotation = baseRot * Quaternion.Euler(0f, 0f, 18f * Mathf.Sin(num * (0.8f + kb)));
				break;
			}
			case "scroll":
				((Component)this).transform.localPosition = basePos + new Vector3(Mathf.Repeat(Time.time * param, tileW), 0f, 0f);
				break;
			case "ember":
			{
				float num19 = 2.2f + 1.8f * Mathf.Repeat(seed * 5.13f, 1f);
				float num20 = Mathf.Repeat(Time.time / num19 + seed, 1f);
				float num21 = 3.5f + 3f * Mathf.Repeat(seed * 2.71f, 1f);
				((Component)this).transform.localPosition = basePos + new Vector3(0.45f * Mathf.Sin(num20 * 7f + seed) * num20, num21 * num20, 0f);
				((Component)this).transform.localScale = baseScale * (1f - 0.6f * num20);
				if ((Object)(object)sr != (Object)null)
				{
					sr.color = new Color(baseColor.r, baseColor.g, baseColor.b, baseColor.a * Mathf.Sin((float)Math.PI * Mathf.Min(1f, num20 * 1.3f)));
				}
				break;
			}
			case "steam":
			{
				float num15 = 4f + 2.5f * Mathf.Repeat(seed * 6.07f, 1f);
				float num16 = Mathf.Repeat(Time.time / num15 + seed, 1f);
				((Component)this).transform.localPosition = basePos + new Vector3(0.6f * Mathf.Sin(num16 * 4f + seed) * num16, 3f * num16, 0f);
				((Component)this).transform.localScale = baseScale * (0.5f + 1.1f * num16);
				if ((Object)(object)sr != (Object)null)
				{
					sr.color = new Color(baseColor.r, baseColor.g, baseColor.b, baseColor.a * Mathf.Sin((float)Math.PI * num16));
				}
				break;
			}
			case "twinkle":
			{
				float num8 = 3f + 3f * Mathf.Repeat(seed * 3.37f, 1f);
				float num9 = Mathf.Repeat(Time.time / num8 + seed, 1f);
				float num10 = ((num9 < 0.12f) ? Mathf.Sin((float)Math.PI * num9 / 0.12f) : 0f);
				((Component)this).transform.localScale = baseScale * (0.3f + 0.9f * num10);
				((Component)this).transform.localRotation = baseRot * Quaternion.Euler(0f, 0f, 40f * num9);
				if ((Object)(object)sr != (Object)null)
				{
					sr.color = new Color(baseColor.r, baseColor.g, baseColor.b, baseColor.a * num10);
				}
				break;
			}
			case "drip":
			{
				float num3 = 2.5f + 2f * Mathf.Repeat(seed * 4.19f, 1f);
				float num4 = Mathf.Repeat(Time.time / num3 + seed, 1f) * num3;
				float num5 = num3 - 0.7f;
				float num6 = Mathf.Max(0f, num4 - num5);
				((Component)this).transform.localPosition = basePos + new Vector3(0f, -11f * num6 * num6, 0f);
				((Component)this).transform.localScale = baseScale * ((num6 > 0f) ? 1f : (0.4f + 0.6f * num4 / num5));
				if ((Object)(object)sr != (Object)null)
				{
					sr.color = new Color(baseColor.r, baseColor.g, baseColor.b, baseColor.a * (1f - Mathf.Clamp01(num6 / 0.7f)));
				}
				break;
			}
			case "drift":
				((Component)this).transform.localPosition = basePos + new Vector3(1.5f * Mathf.Sin(num * 0.21f), 0.3f * Mathf.Sin(num * 1.1f), 0f);
				if ((Object)(object)sr != (Object)null)
				{
					sr.color = new Color(baseColor.r, baseColor.g, baseColor.b, baseColor.a * (0.55f + 0.35f * Mathf.Sin(num * 0.37f)));
				}
				break;
			}
		}
	}
	public class Avalanche : PhaseClock
	{
		public Vector2 release;

		public Vector2 end;

		public float width = 2f;

		public float length = 6f;

		public float tail = 6f;

		public float period = 10f;

		public float first = 4f;

		public float warn = 2f;

		public float run = 1.5f;

		public float settle = 2.5f;

		public float accel = 0.5f;

		public string warnSound;

		public string runSound;

		public BoxCollider2D hit;

		public SpriteRenderer debug;

		public SpriteRenderer[] warnArt = (SpriteRenderer[])(object)new SpriteRenderer[0];

		public SpriteRenderer[] massArt = (SpriteRenderer[])(object)new SpriteRenderer[0];

		public SpriteRenderer[] streamArt = (SpriteRenderer[])(object)new SpriteRenderer[0];

		public SpriteRenderer[] powderArt = (SpriteRenderer[])(object)new SpriteRenderer[0];

		private const int Idle = 0;

		private const int Warn = 1;

		private const int Run = 2;

		private const int Settle = 3;

		private const float EndFade = 0.6f;

		private float chute;

		private Vector2 dir;

		private Transform head;

		private int state = -1;

		private Color[] warnColor;

		private Color[] massColor;

		private Color[] streamColor;

		private Color[] powderColor;

		private float[] warnAlong;

		private float[] massAlong;

		private float[] powderAt;

		private Vector3[] warnBase;

		private Vector3[] powderScale;

		private Quaternion[] massRot;

		private float[] streamWidth;

		private float[] streamBaseY;

		private float warnReach;

		private bool Cycling
		{
			get
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Invalid comparison between Unknown and I4
				if (!base.Playing)
				{
					return (int)Phase == 3;
				}
				return true;
			}
		}

		protected override void Start()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_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)
			//IL_0081: 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_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			base.Start();
			chute = Mathf.Max(0.01f, Vector2.Distance(release, end));
			dir = (end - release) / chute;
			float num = Mathf.Atan2(dir.y, dir.x) * 57.29578f;
			((Component)hit).transform.rotation = Quaternion.Euler(0f, 0f, num);
			warnColor = Opaque(warnArt);
			massColor = Opaque(massArt);
			streamColor = Opaque(streamArt);
			powderColor = Opaque(powderArt);
			warnAlong = warnArt.Select((SpriteRenderer r) => Along(((Component)r).transform.position)).ToArray();
			warnBase = warnArt.Select((SpriteRenderer r) => ((Component)r).transform.position).ToArray();
			warnReach = Mathf.Max(0.5f, warnAlong.DefaultIfEmpty(0f).Max());
			head = new GameObject("AvalancheHead").transform;
			head.SetParent(((Component)this).transform, false);
			head.position = Vector2.op_Implicit(release);
			SpriteRenderer[] array = massArt;
			for (int num2 = 0; num2 < array.Length; num2++)
			{
				((Component)array[num2]).transform.SetParent(head, true);
			}
			massAlong = massArt.Select((SpriteRenderer r) => Vector2.Dot(Vector2.op_Implicit(((Component)r).transform.position) - release, dir)).ToArray();
			massRot = massArt.Select((SpriteRenderer r) => ((Component)r).transform.localRotation).ToArray();
			streamWidth = streamArt.Select(delegate(SpriteRenderer r)
			{
				//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_0027: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)r.sprite != (Object)null))
				{
					return 1f;
				}
				Bounds bounds = r.sprite.bounds;
				return Mathf.Max(0.01f, ((Bounds)(ref bounds)).size.x);
			}).ToArray();
			streamBaseY = streamArt.Select((SpriteRenderer r) => ((Component)r).transform.localScale.y).ToArray();
			array = streamArt;
			for (int num2 = 0; num2 < array.Length; num2++)
			{
				((Component)array[num2]).transform.rotation = Quaternion.Euler(0f, 0f, num);
			}
			powderAt = powderArt.Select((SpriteRenderer r) => FrontReaches(Mathf.Clamp(Along(((Component)r).transform.position), 0f, chute))).ToArray();
			powderScale = powderArt.Select((SpriteRenderer r) => ((Component)r).transform.localScale).ToArray();
			Enter(0);
			Plugin.Log.LogInfo((object)($"Avalanche: chute {chute:0.#} long at {num:0}°, every {period}s; art warn {warnArt.Length}, " + $"mass {massArt.Length}, stream {streamArt.Length}, powder {powderArt.Length}"));
		}

		private float Along(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return Vector2.Dot(Vector2.op_Implicit(p) - release, dir);
		}

		private float Front(float u)
		{
			return (chute + length) * u * (1f - accel + accel * u);
		}

		private float FrontReaches(float s)
		{
			float num = s / (chute + length);
			if (accel < 0.0001f)
			{
				return Mathf.Clamp01(num);
			}
			float num2 = 1f - accel;
			return Mathf.Clamp01((0f - num2 + Mathf.Sqrt(num2 * num2 + 4f * accel * num)) / (2f * accel));
		}

		protected override void Update()
		{
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			base.Update();
			float num = PhaseTime - first;
			float num2 = Mathf.Repeat(num, period);
			int num3 = ((Cycling && !(num < 0f)) ? ((num2 < warn) ? 1 : ((num2 < warn + run) ? 2 : ((num2 < warn + run + settle) ? 3 : 0))) : 0);
			if (num3 != state)
			{
				Enter(num3);
			}
			float u = num3 switch
			{
				3 => 1f, 
				2 => (num2 - warn) / run, 
				_ => 0f, 
			};
			float num4 = ((num3 == 3) ? ((num2 - warn - run) / settle) : 0f);
			float num5 = ((num3 == 2 || num3 == 3) ? Front(u) : 0f);
			float num6 = Mathf.Max(0f, num5 - length);
			float num7 = Mathf.Min(chute, num5);
			bool flag = num3 == 2 && num7 - num6 > 0.05f;
			if (flag)
			{
				((Component)hit).transform.position = Vector2.op_Implicit(release + dir * ((num6 + num7) * 0.5f));
				hit.size = new Vector2(num7 - num6, width);
			}
			((Behaviour)hit).enabled = flag && base.Playing;
			if ((Object)(object)debug != (Object)null)
			{
				((Renderer)debug).enabled = flag;
				((Component)debug).transform.localScale = new Vector3(Mathf.Max(0.01f, num7 - num6), width, 1f);
				debug.color = new Color(1f, 0.25f, 0.2f, base.Playing ? 0.85f : 0.35f);
			}
			float time = Time.time;
			UpdateWarn(num3, num2, time);
			head.position = Vector2.op_Implicit(release + dir * num5);
			for (int i = 0; i < massArt.Length; i++)
			{
				SpriteRenderer obj = massArt[i];
				float num8 = num5 + massAlong[i];
				Set(alpha: (num3 == 2) ? (Mathf.Clamp01(num8 / 0.6f) * Mathf.Clamp01((chute - num8) / 0.6f)) : 0f, r: obj, c: massColor[i]);
				float num9 = ((i % 2 == 0) ? 1f : (-1f)) * (220f + 140f * Mathf.Repeat((float)i * 0.618f, 1f));
				((Component)obj).transform.localRotation = massRot[i] * Quaternion.Euler(0f, 0f, num9 * (num2 - warn));
			}
			float num10 = Mathf.Max(0f, num5 - length - tail);
			float num11 = num7;
			if (num3 == 3)
			{
				num10 = Mathf.Lerp(num10, num11, num4);
			}
			float num12 = num3 switch
			{
				3 => 1f - num4, 
				2 => Mathf.Clamp01((num2 - warn) / 0.08f), 
				_ => 0f, 
			};
			for (int j = 0; j < streamArt.Length; j++)
			{
				SpriteRenderer obj2 = streamArt[j];
				float num13 = num11 - num10;
				Set(obj2, streamColor[j], (num13 > 0.05f) ? num12 : 0f);
				((Component)obj2).transform.position = Vector2.op_Implicit(release + dir * num10);
				Vector3 localScale = ((Component)obj2).transform.localScale;
				((Component)obj2).transform.localScale = new Vector3(Mathf.Max(0.001f, num13) / streamWidth[j], streamBaseY[j], localScale.z);
			}
			for (int k = 0; k < powderArt.Length; k++)
			{
				SpriteRenderer val = powderArt[k];
				float num14 = warn + powderAt[k] * run;
				float num15 = warn + run + settle - num14;
				float num16 = ((num3 == 2 || num3 == 3) ? (num2 - num14) : (-1f));
				if (num16 < 0f || num15 <= 0f)
				{
					Set(val, powderColor[k], 0f);
					continue;
				}
				float num17 = Mathf.Clamp01(num16 / num15);
				Set(val, powderColor[k], Mathf.Clamp01(num16 / 0.12f) * (1f - num17 * num17));
				float num18 = 0.7f + 0.8f * Mathf.Sqrt(num17);
				((Component)val).transform.localScale = new Vector3(powderScale[k].x * num18, powderScale[k].y * num18, powderScale[k].z);
			}
		}

		private void UpdateWarn(int s, float c, float now)
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			float num = ((s == 1) ? (c / warn) : 0f);
			float num2 = ((s == 2) ? Mathf.Clamp01(1f - (c - warn) / 0.3f) : 0f);
			for (int i = 0; i < warnArt.Length; i++)
			{
				SpriteRenderer obj = warnArt[i];
				float alpha = 0f;
				switch (s)
				{
				case 1:
				{
					float num3 = Mathf.Clamp01((Mathf.Clamp01(num * 1.4f) * warnReach - warnAlong[i]) / 0.8f + 0.001f);
					alpha = Mathf.Sqrt(num) * num3 * (0.75f + 0.25f * Mathf.PerlinNoise(now * 6f, (float)i * 1.7f));
					break;
				}
				case 2:
					alpha = num2;
					break;
				}
				Set(obj, warnColor[i], alpha);
				float num4 = ((s == 1 && c > warn - 0.5f) ? 0.06f : 0f);
				((Component)obj).transform.position = warnBase[i] + new Vector3(num4 * Mathf.Sin(now * 53f + (float)i), num4 * Mathf.Sin(now * 41f + 2f * (float)i), 0f);
			}
		}

		private void Enter(int s)
		{
			if (s == 1)
			{
				FxSound.Post(warnSound, ((Component)this).gameObject);
			}
			if (s == 2)
			{
				FxSound.Post(runSound, ((Component)this).gameObject);
			}
			state = s;
		}

		private static Color[] Opaque(SpriteRenderer[] rs)
		{
			//IL_0012: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			Color[] array = (Color[])(object)new Color[rs.Length];
			for (int i = 0; i < rs.Length; i++)
			{
				array[i] = new Color(rs[i].color.r, rs[i].color.g, rs[i].color.b, 1f);
			}
			return array;
		}

		private static void Set(SpriteRenderer r, Color c, float alpha)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)r != (Object)null)
			{
				r.color = new Color(c.r, c.g, c.b, alpha);
			}
		}

		protected override void OnDestroy()
		{
			base.OnDestroy();
			if (!string.IsNullOrEmpty(warnSound) || !string.IsNullOrEmpty(runSound))
			{
				AkSoundEngine.StopAll(((Component)this).gameObject);
			}
		}
	}
	public class Bubbles : MonoBehaviour
	{
		private sealed class Bubble
		{
			public SpriteRenderer r;

			public float x;

			public float y;

			public float size;

			public float speed;

			public float phase;

			public float age;
		}

		public Sprite sprite;

		public string layer = "Effects";

		public int order;

		public Color color = Color.white;

		public float x0;

		public float x1;

		public float bottom;

		public float top;

		public float rate = 2f;

		public float sizeMin = 0.08f;

		public float sizeMax = 0.2f;

		public float speedMin = 0.8f;

		public float speedMax = 1.6f;

		public float offsetY;

		private readonly List<Bubble> live = new List<Bubble>();

		private readonly Stack<SpriteRenderer> spare = new Stack<SpriteRenderer>();

		private float due;

		private void Start()
		{
			if ((Object)(object)sprite == (Object)null || rate <= 0f || top <= bottom)
			{
				((Behaviour)this).enabled = false;
				return;
			}
			float num = (top - bottom) / Mathf.Max(0.05f, (speedMin + speedMax) / 2f);
			int num2 = Mathf.Min(200, Mathf.RoundToInt(rate * num));
			for (int i = 0; i < num2; i++)
			{
				Spawn(Random.Range(bottom, top));
			}
		}

		private void Update()
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			float deltaTime = Time.deltaTime;
			due += rate * deltaTime;
			while (due >= 1f && live.Count < 400)
			{
				due -= 1f;
				Spawn(bottom);
			}
			for (int num = live.Count - 1; num >= 0; num--)
			{
				Bubble bubble = live[num];
				bubble.age += deltaTime;
				bubble.y += bubble.speed * deltaTime;
				if (bubble.y + bubble.size / 2f >= top)
				{
					((Component)bubble.r).gameObject.SetActive(false);
					spare.Push(bubble.r);
					live.RemoveAt(num);
				}
				else
				{
					float num2 = 0.04f * Mathf.Sin(bubble.age * 5f + bubble.phase);
					((Component)bubble.r).transform.position = new Vector3(bubble.x + num2, bubble.y + offsetY, 0f);
					bubble.r.color = new Color(color.r, color.g, color.b, color.a * Mathf.Clamp01(bubble.age / 0.25f));
				}
			}
		}

		private void Spawn(float y)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			float num = Random.Range(sizeMin, sizeMax);
			float num2 = x0 + num / 2f;
			float num3 = x1 - num / 2f;
			if (num3 < num2)
			{
				num2 = (num3 = (x0 + x1) / 2f);
			}
			SpriteRenderer val = ((spare.Count > 0) ? spare.Pop() : NewRenderer());
			((Component)val).gameObject.SetActive(true);
			((Component)val).transform.localScale = new Vector3(num, num, 1f);
			Bubble bubble = new Bubble
			{
				r = val,
				x = Random.Range(num2, num3),
				y = y,
				size = num,
				speed = Random.Range(speedMin, speedMax),
				phase = Random.value * 6.3f
			};
			bubble.age = ((y > bottom) ? 1f : 0f);
			((Component)val).transform.position = new Vector3(bubble.x, bubble.y + offsetY, 0f);
			val.color = new Color(color.r, color.g, color.b, (bubble.age > 0f) ? color.a : 0f);
			live.Add(bubble);
		}

		private SpriteRenderer NewRenderer()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("bubble");
			val.transform.SetParent(((Component)this).transform, false);
			SpriteRenderer obj = val.AddComponent<SpriteRenderer>();
			obj.sprite = sprite;
			((Renderer)obj).sortingLayerName = layer;
			((Renderer)obj).sortingOrder = order;
			return obj;
		}
	}
	public class Conveyor : MonoBehaviour
	{
		public Collider2D belt;

		public float speed = 1.6f;

		public float direction = 1f;

		public Transform[] rollers = (Transform[])(object)new Transform[0];

		public float rollerRadius = 0.36f;

		private void FixedUpdate()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			GameControl val = (((Object)(object)LobbyManager.instance != (Object)null) ? LobbyManager.instance.CurrentGameController : null);
			if ((Object)(object)belt == (Object)null || (Object)(object)val == (Object)null || val.CurrentPlayerQueue == null)
			{
				return;
			}
			foreach (GamePlayer item in val.CurrentPlayerQueue)
			{
				Character val2 = (((Object)(object)item != (Object)null) ? item.CharacterInstance : null);
				if (!((Object)(object)val2 == (Object)null) && !val2.Waiting && val2.OnGround && OnBelt(val2))
				{
					val2.ApplyPhysicsModifier(new PhysicsModifier((ModType)11, speed, new Vector2(direction, 0f), ((Component)this).gameObject));
				}
			}
		}

		private bool OnBelt(Character c)
		{
			//IL_005c: 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_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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			CharacterRaycaster feet = c.Feet;
			if ((Object)(object)feet == (Object)null || (Object)(object)feet.raycastStartAnchor == (Object)null || (Object)(object)feet.raycastEndAnchor == (Object)null)
			{
				return false;
			}
			float num = feet.raycastLength * Modifiers.GetInstance().CharacterRelativeScale + 0.05f;
			bool queriesHitTriggers = Physics2D.queriesHitTriggers;
			Physics2D.queriesHitTriggers = false;
			try
			{
				for (int i = 0; i < 3; i++)
				{
					RaycastHit2D val = Physics2D.Raycast(Vector2.op_Implicit(Vector3.Lerp(feet.raycastStartAnchor.position, feet.raycastEndAnchor.position, (float)i / 2f)), Vector2.op_Implicit(feet.raycastDirection), num, ((LayerMask)(ref feet.layerMask)).value);
					if ((Object)(object)((RaycastHit2D)(ref val)).collider == (Object)(object)belt)
					{
						return true;
					}
				}
			}
			finally
			{
				Physics2D.queriesHitTriggers = queriesHitTriggers;
			}
			return false;
		}

		private void Update()
		{
			float num = (0f - direction) * speed / rollerRadius * 57.29578f * Time.deltaTime;
			Transform[] array = rollers;
			foreach (Transform val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.Rotate(0f, 0f, num);
				}
			}
		}
	}
	public class DevTools : MonoBehaviour
	{
		public static DevTools Instance;

		private float nextPoll;

		private DateTime lastStageWrite;

		private GameObject overlay;

		private static readonly string[] TourScenes = new string[9] { "Farm", "Iceberg", "JungleTemple", "Waterfall", "WindMill", "CrumblingBridge", "Volcano", "Pier", "Raft" };

		private bool touring;

		private void Awake()
		{
			Instance = this;
			if (Plugin.DevMode.Value)
			{
				((Component)this).gameObject.AddComponent<JumpMeter>();
			}
		}

		public void Shot(float delay, string tag)
		{
			((MonoBehaviour)this).StartCoroutine(ScreenshotLater(delay, tag));
		}

		public void OnSceneLoaded(Scene scene)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if ((from s in Plugin.DevDumpScenes.Value.Split(new char[1] { ',' })
				select s.Trim()).Contains(((Scene)(ref scene)).name))
			{
				((MonoBehaviour)this).StartCoroutine(DumpLater(scene, 2f));
			}
		}

		private IEnumerator DumpLater(Scene scene, float delay)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSecondsRealtime(delay);
			if (((Scene)(ref scene)).isLoaded)
			{
				Safe(delegate
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					SceneDumper.Dump(scene);
				});
			}
		}

		public static void TakeScreenshot(string tag)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			string text = $"shot_{((Scene)(ref activeScene)).name}_{tag}_{DateTime.Now:HHmmss}.png";
			string text2 = Path.Combine(Plugin.DevDir, text);
			ScreenCapture.CaptureScreenshot(text2);
			File.WriteAllText(Path.Combine(Plugin.DevDir, "last_screenshot.txt"), text);
			Plugin.Log.LogInfo((object)("Screenshot -> " + text2));
		}

		private void Update()
		{
			if (!Plugin.DevMode.Value)
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)286))
			{
				((MonoBehaviour)this).StartCoroutine(Tour());
			}
			if (Input.GetKeyDown((KeyCode)287))
			{
				ReloadStage("key");
			}
			if (Input.GetKeyDown((KeyCode)288))
			{
				((MonoBehaviour)this).StartCoroutine(QuickLaunch());
			}
			if (Input.GetKeyDown((KeyCode)289))
			{
				ToggleOverlay();
			}
			if (Input.GetKeyDown((KeyCode)290))
			{
				Safe(delegate
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					SceneDumper.Dump(SceneManager.GetActiveScene());
				});
			}
			if (Input.GetKeyDown((KeyCode)291))
			{
				TakeScreenshot("key");
			}
			if (!(Time.unscaledTime >= nextPoll))
			{
				return;
			}
			nextPoll = Time.unscaledTime + 0.5f;
			string text = ((StageBuilder.StageDir == null) ? null : Path.Combine(StageBuilder.StageDir, "stage.json"));
			if (text == null || !File.Exists(text))
			{
				return;
			}
			DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(text);
			if (lastStageWrite == default(DateTime))
			{
				lastStageWrite = lastWriteTimeUtc;
			}
			else if (lastWriteTimeUtc != lastStageWrite)
			{
				lastStageWrite = lastWriteTimeUtc;
				if (StageBuilder.Active)
				{
					ReloadStage("hot");
				}
			}
		}

		private void ReloadStage(string why)
		{
			if (StageBuilder.Active)
			{
				StageBuilder.Rebuild();
				if ((Object)(object)overlay != (Object)null)
				{
					Object.Destroy((Object)(object)overlay);
					overlay = null;
					ToggleOverlay();
				}
				((MonoBehaviour)this).StartCoroutine(ScreenshotLater(1f, "reload"));
			}
		}

		private IEnumerator ScreenshotLater(float delay, string tag)
		{
			yield return (object)new WaitForSecondsRealtime(delay);
			TakeScreenshot(tag);
		}

		private IEnumerator Tour()
		{
			if (touring)
			{
				yield break;
			}
			touring = true;
			CustomMap home = QuickLaunchTarget();
			if (home == null)
			{
				Plugin.Log.LogWarning((object)"Tour: no enabled map");
				touring = false;
				yield break;
			}
			Scene activeScene;
			if ((Object)(object)Object.FindObjectOfType<GameControl>() == (Object)null && (Object)(object)Object.FindObjectOfType<LevelSelectController>() != (Object)null)
			{
				yield return QuickLaunch();
				float tl = Time.realtimeSinceStartup;
				while (true)
				{
					activeScene = SceneManager.GetActiveScene();
					if (!(((Scene)(ref activeScene)).name != home.HostScene) || !(Time.realtimeSinceStartup - tl < 30f))
					{
						break;
					}
					yield return null;
				}
				yield return (object)new WaitForSecondsRealtime(4f);
			}
			foreach (string scene in TourScenes.Concat(new string[1] { home.HostScene }))
			{
				GameControl val = Object.FindObjectOfType<GameControl>();
				if ((Object)(object)val == (Object)null || !((NetworkBehaviour)val).isServer)
				{
					Plugin.Log.LogWarning((object)"Tour: start it from inside a level, as host");
					break;
				}
				Plugin.Log.LogInfo((object)("Tour: -> " + scene));
				val.CallRpcStartFadingOut(false, scene);
				float tl = Time.realtimeSinceStartup;
				while (true)
				{
					activeScene = SceneManager.GetActiveScene();
					if (!(((Scene)(ref activeScene)).name != scene) || !(Time.realtimeSinceStartup - tl < 30f))
					{
						break;
					}
					yield return null;
				}
				activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name != scene)
				{
					Plugin.Log.LogWarning((object)("Tour: " + scene + " did not load"));
					break;
				}
				float[] array = new float[3] { 2.5f, 3.5f, 5f };
				foreach (float num in array)
				{
					yield return (object)new WaitForSecondsRealtime(num);
					List<Renderer> hidden = (from r in Object.FindObjectsOfType<PartyBox>().SelectMany((PartyBox b) => ((Component)b).GetComponentsInChildren<Renderer>()).Concat(Object.FindObjectsOfType<PiecePlacementCursor>().SelectMany((PiecePlacementCursor c) => ((Component)c).GetComponentsInChildren<Renderer>()))
						where r.enabled
						select r).ToList();
					hidden.ForEach(delegate(Renderer r)
					{
						r.enabled = false;
					});
					TakeScreenshot("tour");
					yield return null;
					yield return (object)new WaitForEndOfFrame();
					yield return null;
					hidden.ForEach(delegate(Renderer r)
					{
						if ((Object)(object)r != (Object)null)
						{
							r.enabled = true;
						}
					});
				}
			}
			touring = false;
		}

		private void ToggleOverlay()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)overlay != (Object)null)
			{
				Object.Destroy((Object)(object)overlay);
				overlay = null;
				return;
			}
			overlay = new GameObject("CS_ColliderOverlay");
			Material sharedMaterial = new Material(Shader.Find("Sprites/Default"));
			int num = 0;
			foreach (KeyValuePair<Collider2D, CollisionTag> allTag in CollisionTag.AllTags)
			{
				Collider2D key = allTag.Key;
				if (!((Object)(object)key == (Object)null) && ((Behaviour)key).enabled && ((Component)key).gameObject.activeInHierarchy && !((Object)(object)((Component)key).GetComponentInParent<Character>() != (Object)null) && !((Object)(object)((Component)key).GetComponentInParent<PiecePlacementCursor>() != (Object)null))
				{
					Tag bitMask = allTag.Value.bitMask;
					Color val = Color.cyan;
					if ((bitMask & 0x100) != 0)
					{
						val = Color.red;
					}
					else if ((bitMask & 0x80000) != 0)
					{
						val = Color.magenta;
					}
					else if ((bitMask & 0x400000) != 0)
					{
						val = Color.green;
					}
					else if ((bitMask & 0x200) != 0)
					{
						val = Color.yellow;
					}
					else if ((bitMask & 0x1000) != 0)
					{
						val = Color.white;
					}
					else if ((bitMask & 0x80) == 0)
					{
						((Color)(ref val))..ctor(1f, 0.5f, 0f);
					}
					Bounds bounds = key.bounds;
					GameObject val2 = new GameObject("o");
					val2.transform.SetParent(overlay.transform, false);
					LineRenderer val3 = val2.AddComponent<LineRenderer>();
					((Renderer)val3).sharedMaterial = sharedMaterial;
					val3.useWorldSpace = true;
					val3.loop = true;
					val3.positionCount = 4;
					val3.SetPositions((Vector3[])(object)new Vector3[4]
					{
						new Vector3(((Bounds)(ref bounds)).min.x, ((Bounds)(ref bounds)).min.y),
						new Vector3(((Bounds)(ref bounds)).max.x, ((Bounds)(ref bounds)).min.y),
						new Vector3(((Bounds)(ref bounds)).max.x, ((Bounds)(ref bounds)).max.y),
						new Vector3(((Bounds)(ref bounds)).min.x, ((Bounds)(ref bounds)).max.y)
					});
					float startWidth = (val3.endWidth = 0.08f);
					val3.startWidth = startWidth;
					Color startColor = (val3.endColor = val);
					val3.startColor = startColor;
					((Renderer)val3).sortingLayerName = "UI 1";
					num++;
				}
			}
			Plugin.Log.LogInfo((object)$"Collider overlay on ({num} colliders)");
		}

		private static CustomMap QuickLaunchTarget()
		{
			string value = Plugin.DevQuickLaunchMap.Value;
			return (string.IsNullOrEmpty(value) ? null : MapRegistry.Get(value)) ?? MapRegistry.Enabled.FirstOrDefault();
		}

		private IEnumerator QuickLaunch()
		{
			LevelSelectController lsc = Object.FindObjectOfType<LevelSelectController>();
			if ((Object)(object)lsc == (Object)null || !lsc.HostIsLoaded)
			{
				Plugin.Log.LogWarning((object)"F7: not in a loaded Treehouse (host).");
				yield break;
			}
			Plugin.Log.LogInfo((object)$"F7: game mode {GameSettings.GetInstance().GameMode}");
			NetworkLobbyPlayer[] lobbySlots = ((NetworkLobbyManager)LobbyManager.instance).lobbySlots;
			foreach (NetworkLobbyPlayer obj in lobbySlots)
			{
				LobbyPlayer val = (LobbyPlayer)(object)((obj is LobbyPlayer) ? obj : null);
				if (!((Object)(object)val == (Object)null) && (int)val.PickedAnimal == 0)
				{
					Character free = (from c in Object.FindObjectsOfType<Character>()
						where !c.Picked && (int)c.CharacterSprite > 0
						orderby (int)c.CharacterSprite
						select c).FirstOrDefault();
					if ((Object)(object)free == (Object)null)
					{
						break;
					}
					Plugin.Log.LogInfo((object)$"F7: picking {free.CharacterSprite} for lobby player");
					val.RequestPickCharacter(free);
					float t = 0f;
					while (!free.Picked && t < 3f)
					{
						t += Time.unscaledDeltaTime;
						yield return null;
					}
				}
			}
			if (!((NetworkLobbyManager)LobbyManager.instance).lobbySlots.OfType<LobbyPlayer>().Any((LobbyPlayer p) => (Object)(object)p != (Object)null && (int)p.PickedAnimal > 0))
			{
				Plugin.Log.LogWarning((object)"F7: no player with a character — join with a controller/keyboard first.");
				yield break;
			}
			CustomMap map = QuickLaunchTarget();
			CustomMapDoor? customMapDoor = Object.FindObjectsOfType<CustomMapDoor>().FirstOrDefault((CustomMapDoor d) => d.Map == map);
			LevelPortal val2 = ((customMapDoor != null) ? ((Component)customMapDoor).GetComponent<LevelPortal>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogWarning((object)("F7: no door for map " + (map?.Id ?? "(none)")));
				yield break;
			}
			Plugin.Log.LogInfo((object)("F7: launching " + map.Name + " via its door"));
			lsc.LaunchLevel(val2);
		}

		public static void Safe(Action a)
		{
			try
			{
				a();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
			}
		}
	}
	public class Fireballs : PhaseClock
	{
		private class Shot
		{
			public bool fires;

			public bool done;

			public bool solid;

			public float launch;

			public float doneAt;

			public Vector2 p0;

			public Vector2 v;

			public Vector2 last;

			public Vector2 point;

			public bool launched;

			public bool seen;
		}

		public float x0;

		public float x1;

		public float surface;

		public float period = 1.6f;

		public float chance = 0.55f;

		public float first = 2f;

		public float warn = 0.7f;

		public float speedMin = 9f;

		public float speedMax = 13f;

		public float angle = 25f;

		public float gravity = 9.81f;

		public float radius = 0.27f;

		public float fps = 12f;

		public float killY = -100f;

		public int seed = 7;

		public string launchSound;

		public string hitSound;

		public string splashSound;

		public Sprite[] frames = (Sprite[])(object)new Sprite[0];

		public Sprite[] boilFrames = (Sprite[])(object)new Sprite[0];

		public SpriteRenderer ball;

		public SpriteRenderer spark;

		public SpriteRenderer boil;

		public float boilDepth = 1.4f;

		public float boilRise = 0.8f;

		private const int SparksPer = 6;

		private const float BurstTime = 0.6f;

		private const float Emerge = 0.2f;

		private const float SinkTime = 0.35f;

		private readonly Dictionary<int, Shot> shots = new Dictionary<int, Shot>();

		private SpriteRenderer[] balls;

		private SpriteRenderer[] sparks;

		private SpriteRenderer[] boils;

		private Collider2D[] hits;

		private Color ballColor;

		private Color sparkColor;

		private Color boilColor;

		private int pool;

		private int back;

		private int phaseCount;

		private int mask = -1;

		private bool Cycling
		{
			get
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Invalid comparison between Unknown and I4
				if (!base.Playing)
				{
					return (int)Phase == 3;
				}
				return true;
			}
		}

		protected override void Start()
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			base.Start();
			float num = 2f * speedMax / Mathf.Max(0.1f, gravity) + 1f;
			back = Mathf.CeilToInt((warn + period + num + 0.6f) / Mathf.Max(0.1f, period)) + 1;
			pool = back + 1;
			balls = (SpriteRenderer[])(object)new SpriteRenderer[((Object)(object)ball != (Object)null) ? pool : 0];
			hits = (Collider2D[])(object)new Collider2D[balls.Length];
			sparks = (SpriteRenderer[])(object)new SpriteRenderer[((Object)(object)spark != (Object)null) ? (pool * 6) : 0];
			boils = (SpriteRenderer[])(object)new SpriteRenderer[((Object)(object)boil != (Object)null && boilFrames.Length != 0) ? pool : 0];
			if ((Object)(object)ball != (Object)null)
			{
				ballColor = Opaque(ball.color);
			}
			if ((Object)(object)spark != (Object)null)
			{
				sparkColor = Opaque(spark.color);
			}
			if ((Object)(object)boil != (Object)null)
			{
				boilColor = Opaque(boil.color);
			}
			for (int i = 0; i < balls.Length; i++)
			{
				balls[i] = Clone(ball, "Fireball");
				hits[i] = MakeHit(((Component)balls[i]).transform);
			}
			for (int j = 0; j < sparks.Length; j++)
			{
				sparks[j] = Clone(spark, "FireballSpark");
			}
			for (int k = 0; k < boils.Length; k++)
			{
				boils[k] = Clone(boil, "FireballBoil");
			}
			Plugin.Log.LogInfo((object)($"Fireballs: x {x0:0.#}-{x1:0.#} at y {surface:0.#}, a slot every {period}s ({chance:P0}), " + $"speed {speedMin}-{speedMax}; art frames {frames.Length}, pool {pool}"));
		}

		private SpriteRenderer Clone(SpriteRenderer template, string name)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(((Component)template).gameObject, ((Component)this).transform, true);
			((Object)obj).name = name;
			SpriteRenderer component = obj.GetComponent<SpriteRenderer>();
			component.color = Clear(component.color);
			return component;
		}

		private Collider2D MakeHit(Transform fb)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("FireballHit");
			val.layer = 18;
			val.tag = "Hazard";
			val.transform.SetParent(fb, false);
			CircleCollider2D obj = val.AddComponent<CircleCollider2D>();
			obj.radius = radius / Mathf.Max(0.01f, Mathf.Abs(fb.lossyScale.x));
			((Collider2D)obj).isTrigger = true;
			((Behaviour)obj).enabled = false;
			val.AddComponent<CollisionTag>().bitMask = (Tag)256;
			return (Collider2D)(object)obj;
		}

		protected override void OnPhase(GamePhase from, GamePhase to)
		{
			phaseCount++;
			shots.Clear();
		}

		private float Rand(int k, int salt)
		{
			int num = (seed * 73856093) ^ (phaseCount * 19349663) ^ ((k + 1) * 83492791) ^ ((salt + 1) * -1640531535);
			int num2 = (num ^ (num >>> 13)) * 1540483477;
			return (float)(uint)((num2 ^ (num2 >>> 15)) & 0xFFFFFF) / 16777216f;
		}

		private Shot Get(int k)
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			if (shots.TryGetValue(k, out var value))
			{
				return value;
			}
			value = new Shot
			{
				fires = (Rand(k, 0) < chance)
			};
			value.launch = first + (float)k * period + warn + Rand(k, 1) * period * 0.5f;
			float num = Mathf.Lerp(x0, x1, Rand(k, 2));
			float num2 = (Rand(k, 3) * 2f - 1f) * angle * ((float)Math.PI / 180f);
			float num3 = Mathf.Lerp(speedMin, speedMax, Rand(k, 4));
			value.p0 = new Vector2(num, surface - 0.2f);
			value.v = new Vector2(Mathf.Sin(num2) * num3, Mathf.Cos(num2) * num3);
			shots[k] = value;
			if (shots.Count > 4 * pool)
			{
				foreach (int item in shots.Keys.Where((int q) => q < k - 2 * pool).ToList())
				{
					shots.Remove(item);
				}
			}
			return value;
		}

		protected override void Update()
		{
			//IL_0014: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			base.Update();
			for (int i = 0; i < balls.Length; i++)
			{
				Show(balls[i], on: false, ballColor);
			}
			for (int j = 0; j < sparks.Length; j++)
			{
				Show(sparks[j], on: false, sparkColor);
			}
			for (int k = 0; k < boils.Length; k++)
			{
				Show(boils[k], on: false, boilColor);
			}
			for (int l = 0; l < hits.Length; l++)
			{
				((Behaviour)hits[l]).enabled = false;
			}
			if (!Cycling)
			{
				return;
			}
			int num = Mathf.FloorToInt((PhaseTime - first) / period);
			for (int m = Mathf.Max(0, num - back); m <= num; m++)
			{
				Shot shot = Get(m);
				if (!shot.fires)
				{
					continue;
				}
				float num2 = PhaseTime - shot.launch;
				if (num2 < 0f - warn)
				{
					continue;
				}
				int slot = m % pool;
				if (boils.Length != 0 && num2 < 0.35f)
				{
					Boil(slot, shot, num2, m);
				}
				if (!(num2 < 0f))
				{
					if (!shot.done)
					{
						Fly(slot, shot, num2);
					}
					if (shot.done)
					{
						Burst(slot, shot, num2 - shot.doneAt, m);
					}
				}
			}
		}

		private void Boil(int slot, Shot s, float tau, int k)
		{
			//IL_0079: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			SpriteRenderer val = boils[slot];
			float num = ((tau < 0f) ? Smooth(Mathf.Clamp01((tau + warn) / (0.5f * warn))) : (1f - Smooth(tau / 0.35f)));
			((Component)val).transform.position = new Vector3(s.p0.x, surface - boilDepth + (boilDepth + boilRise) * num, ((Component)val).transform.position.z);
			int num2 = Mathf.FloorToInt((tau + warn) * fps) + k * 5;
			val.sprite = boilFrames[(num2 % boilFrames.Length + boilFrames.Length) % boilFrames.Length];
			Show(val, num > 0.01f, boilColor);
		}

		private static float Smooth(float t)
		{
			return t * t * (3f - 2f * t);
		}

		private void Fly(int slot, Shot s, float tau)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: 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_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: 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)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 0f - gravity);
			Vector2 val2 = s.p0 + s.v * tau + 0.5f * val * tau * tau;
			Vector2 val3 = s.v + val * tau;
			if (!s.launched)
			{
				s.launched = true;
				FxSound.Post(launchSound, (balls.Length != 0) ? ((Component)balls[slot]).gameObject : ((Component)this).gameObject);
			}
			if (!s.seen)
			{
				s.seen = true;
				s.last = val2;
			}
			Vector2? val4 = ((tau > 0.02f) ? Sweep(s.last, val2) : ((Vector2?)null));
			if (val4.HasValue)
			{
				Finish(s, tau, val4.Value, solid: true);
				FxSound.Post(hitSound, (balls.Length != 0) ? ((Component)balls[slot]).gameObject : ((Component)this).gameObject);
				return;
			}
			if (val3.y < 0f && val2.y < surface - 0.2f)
			{
				Finish(s, tau, new Vector2(val2.x, surface), solid: false);
				FxSound.Post(splashSound, (balls.Length != 0) ? ((Component)balls[slot]).gameObject : ((Component)this).gameObject);
				return;
			}
			if (val2.y < killY)
			{
				Finish(s, tau, val2, solid: false);
				return;
			}
			s.last = val2;
			if (balls.Length != 0)
			{
				SpriteRenderer val5 = balls[slot];
				((Component)val5).transform.position = new Vector3(val2.x, val2.y, ((Component)val5).transform.position.z);
				((Component)val5).transform.rotation = Quaternion.Euler(0f, 0f, Mathf.Atan2(val3.y, val3.x) * 57.29578f - 90f);
				if (frames.Length != 0)
				{
					val5.sprite = frames[Mathf.FloorToInt(tau * fps) % frames.Length];
				}
				Show(val5, on: true, ballColor);
				((Behaviour)hits[slot]).enabled = base.Playing;
			}
		}

		private static void Finish(Shot s, float tau, Vector2 at, bool solid)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			s.done = true;
			s.doneAt = tau;
			s.point = at;
			s.solid = solid;
		}

		private void Burst(int slot, Shot s, float a, int k)
		{
			//IL_00f1: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			if (!(a > 0.6f) && sparks.Length != 0 && !(s.point.y <= killY))
			{
				for (int i = 0; i < 6 && (s.solid || i < 4); i++)
				{
					SpriteRenderer obj = sparks[slot * 6 + i];
					float num = ((float)i + 0.5f) / 6f;
					float num2 = (Rand(k, 10 + i) - 0.5f) * 0.6f;
					float num3 = (s.solid ? (Mathf.Lerp(-150f, 150f, num) * ((float)Math.PI / 180f) + num2) : (Mathf.Lerp(-35f, 35f, (float)i / 3f) * ((float)Math.PI / 180f)));
					float num4 = (s.solid ? (4.5f + 2f * Rand(k, 20 + i)) : (3f + Rand(k, 20 + i)));
					Vector2 val = new Vector2(Mathf.Sin(num3), Mathf.Cos(num3)) * num4;
					((Component)obj).transform.position = new Vector3(s.point.x + val.x * a, s.point.y + val.y * a - 8f * a * a, 0f);
					Show(obj, on: true, sparkColor, 1f - a / 0.6f);
				}
			}
		}

		private Vector2? Sweep(Vector2 from, Vector2 to)
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			if (mask < 0)
			{
				GameControl obj = (((Object)(object)LobbyManager.instance != (Object)null) ? LobbyManager.instance.CurrentGameController : null);
				Character val = ((obj == null) ? null : obj.CurrentPlayerQueue?.Select((GamePlayer p) => p?.CharacterInstance).FirstOrDefault((Func<Character, bool>)((Character x) => (Object)(object)x != (Object)null && (Object)(object)x.Feet != (Object)null)));
				if ((Object)(object)val != (Object)null)
				{
					mask = ((LayerMask)(ref val.Feet.layerMask)).value;
				}
			}
			int num = ((mask >= 0) ? mask : 256);
			Vector2 val2 = to - from;
			float magnitude = ((Vector2)(ref val2)).magnitude;
			if (magnitude < 0.0001f)
			{
				return null;
			}
			bool queriesHitTriggers = Physics2D.queriesHitTriggers;
			Physics2D.queriesHitTriggers = false;
			try
			{
				RaycastHit2D val3 = Physics2D.CircleCast(from, radius * 0.6f, val2 / magnitude, magnitude, num);
				return ((Object)(object)((RaycastHit2D)(ref val3)).collider != (Object)null) ? new Vector2?(((RaycastHit2D)(ref val3)).point) : ((Vector2?)null);
			}
			finally
			{
				Physics2D.queriesHitTriggers = queriesHitTriggers;
			}
		}

		private static void Show(SpriteRenderer r, bool on, Color c, float alpha = 1f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			r.color = new Color(c.r, c.g, c.b, on ? Mathf.Clamp01(alpha) : 0f);
		}

		private static Color Opaque(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			return new Color(c.r, c.g, c.b, 1f);
		}

		private static Color Clear(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			return new Color(c.r, c.g, c.b, 0f);
		}
	}
	public class FrameAnim : MonoBehaviour
	{
		public Sprite[] frames;

		public float fps = 12f;

		public bool flapGlide;

		public bool synced;

		private SpriteRenderer sr;

		private float clock;

		private float glideUntil = -1f;

		private int cyclesLeft;

		private void Start()
		{
			sr = ((Component)this).GetComponent<SpriteRenderer>();
			clock = Random.value * (float)frames.Length / fps;
			cyclesLeft = Random.Range(1, 4);
		}

		private void Update()
		{
			if ((Object)(object)sr == (Object)null || frames == null || frames.Length == 0)
			{
				return;
			}
			if (synced)
			{
				sr.sprite = frames[(int)(Time.time * fps) % frames.Length];
				return;
			}
			if (flapGlide && Time.time < glideUntil)
			{
				sr.sprite = frames[0];
				return;
			}
			float num = clock;
			clock += Time.deltaTime;
			float num2 = (float)frames.Length / fps;
			if (flapGlide && Mathf.Floor(clock / num2) > Mathf.Floor(num / num2) && --cyclesLeft <= 0)
			{
				glideUntil = Time.time + Random.Range(1.2f, 3.2f);
				cyclesLeft = Random.Range(1, 4);
				clock = 0f;
				sr.sprite = frames[0];
			}
			else
			{
				sr.sprite = frames[(int)(clock * fps) % frames.Length];
			}
		}
	}
	public class Gust : MonoBehaviour, IGameEventListener
	{
		public Rect area;

		public float period = 10f;

		public float duration = 2f;

		public float ramp = 0.35f;

		public float power = 0.2f;

		public Vector2 dir = Vector2.right;

		private float clock;

		private bool playing;

		private ParticleSystem particles;

		public static float Strength { get; private set; }

		public static Rect Area { get; private set; }

		public static Vector2 Dir { get; private set; }

		private void Start()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Area = area;
			Dir = dir;
			GameEventManager.ChangeListener<StartPhaseEvent>((IGameEventListener)(object)this, true);
			DevTools.Safe(BuildParticles);
		}

		private void OnDestroy()
		{
			GameEventManager.ChangeListener<StartPhaseEvent>((IGameEventListener)(object)this, false);
			Strength = 0f;
		}

		public void handleEvent(GameEvent e)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			StartPhaseEvent val = (StartPhaseEvent)(object)((e is StartPhaseEvent) ? e : null);
			if (val != null)
			{
				clock = 0f;
				playing = (int)val.Phase == 2 || (int)val.Phase == 4;
			}
		}

		private float StrengthAt(float t)
		{
			float num = Mathf.Repeat(t, period) - (period - duration);
			if (!(num < 0f))
			{
				return Mathf.Clamp01(Mathf.Min(num, duration - num) / ramp);
			}
			return 0f;
		}

		private void FixedUpdate()
		{
			//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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			clock += Time.deltaTime;
			float num = (Strength = StrengthAt(clock));
			if ((Object)(object)particles != (Object)null)
			{
				EmissionModule emission = particles.emission;
				((EmissionModule)(ref emission)).enabled = num > 0.1f;
			}
			if (!playing || num <= 0f)
			{
				return;
			}
			GameControl val = (((Object)(object)LobbyManager.instance != (Object)null) ? LobbyManager.instance.CurrentGameController : null);
			if ((Object)(object)val == (Object)null || val.CurrentPlayerQueue == null)
			{
				return;
			}
			foreach (GamePlayer item in val.CurrentPlayerQueue)
			{
				Character val2 = (((Object)(object)item != (Object)null) ? item.CharacterInstance : null);
				if (!((Object)(object)val2 == (Object)null) && !val2.Waiting && ((Rect)(ref area)).Contains(((Component)val2).transform.position))
				{
					val2.ApplyPhysicsModifier(new PhysicsModifier((ModType)12, power * num, dir, ((Component)this).gameObject));
				}
			}
		}

		private void BuildParticles()
		{
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: 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_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			PlaceableMetadataList instance = PlaceableMetadataList.Instance;
			UpblowerParticleControl val = null;
			if ((Object)(object)instance != (Object)null && instance.allBlockPrefabs != null)
			{
				GameObject[] allBlockPrefabs = instance.allBlockPrefabs;
				foreach (GameObject val2 in allBlockPrefabs)
				{
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.GetComponent<UpBlower>() == (Object)null))
					{
						val = val2.GetComponentInChildren<UpblowerParticleControl>(true);
						if ((Object)(object)val != (Object)null)
						{
							break;
						}
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Gust: no Fan particles found - the gust blows without them");
				return;
			}
			GameObject val3 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)this).transform);
			((Object)val3).name = "GustParticles";
			MonoBehaviour[] componentsInChildren = val3.GetComponentsInChildren<MonoBehaviour>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			particles = val3.GetComponent<ParticleSystem>();
			particles.Stop(true, (ParticleSystemStopBehavior)0);
			Vector2 normalized = ((Vector2)(ref dir)).normalized;
			float num = ((Mathf.Abs(normalized.x) >= Mathf.Abs(normalized.y)) ? ((Rect)(ref area)).height : ((Rect)(ref area)).width);
			float num2 = ((Mathf.Abs(normalized.x) >= Mathf.Abs(normalized.y)) ? ((Rect)(ref area)).width : ((Rect)(ref area)).height);
			Rect val4 = ((StageBuilder.Data != null) ? StageBuilder.Data.WorldRect(StageBuilder.Data.camera) : area);
			Rect val5 = Rect.MinMaxRect(Mathf.Max(((Rect)(ref area)).xMin, ((Rect)(ref val4)).xMin), Mathf.Max(((Rect)(ref area)).yMin, ((Rect)(ref val4)).yMin), Mathf.Min(((Rect)(ref area)).xMax, ((Rect)(ref val4)).xMax), Mathf.Min(((Rect)(ref area)).yMax, ((Rect)(ref val4)).yMax));
			val3.transform.position = new Vector3(((Rect)(ref val5)).center.x - normalized.x * ((Rect)(ref val5)).width / 2f, ((Rect)(ref val5)).center.y - normalized.y * ((Rect)(ref val5)).height / 2f, 0f);
			val3.transform.rotation = Quaternion.identity;
			val3.transform.localScale = Vector3.one;
			float num3 = 22f;
			MainModule main = particles.main;
			MinMaxGradient val6 = default(MinMaxGradient);
			((MinMaxGradient)(ref val6))..ctor(val.runmodeParticlaGradient);
			((MinMaxGradient)(ref val6)).mode = (ParticleSystemGradientMode)4;
			MinMaxGradient startColor = val6;
			((MainModule)(ref main)).startColor = startColor;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(Mathf.Min(num2, (Mathf.Abs(normalized.x) >= Mathf.Abs(normalized.y)) ? ((Rect)(ref val5)).width : ((Rect)(ref val5)).height) / num3);
			((MainModule)(ref main)).startRotation = MinMaxCurve.op_Implicit(Mathf.Atan2(0f - normalized.x, normalized.y));
			((MainModule)(ref main)).maxParticles = Mathf.Max(((MainModule)(ref main)).maxParticles, 1500);
			((MainModule)(ref main)).loop = true;
			ShapeModule shape = particles.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5;
			((ShapeModule)(ref shape)).position = Vector3.zero;
			((ShapeModule)(ref shape)).rotation = Vector3.zero;
			((ShapeModule)(ref shape)).scale = ((Mathf.Abs(normalized.x) >= Mathf.Abs(normalized.y)) ? new Vector3(0.1f, ((Rect)(ref val5)).height, 0.1f) : new Vector3(((Rect)(ref val5)).width, 0.1f, 0.1f));
			VelocityOverLifetimeModule velocityOverLifetime = particles.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)1;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(num3 * normalized.x * 0.85f, num3 * normalized.x * 1.15f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(num3 * normalized.y * 0.85f - 0.6f, num3 * normalized.y * 1.15f + 0.6f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(0f, 0f);
			EmissionModule emission = particles.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(9f * Mathf.Min(num, 20f));
			((EmissionModule)(ref emission)).enabled = false;
			ParticleSystemRenderer component = val3.GetComponent<ParticleSystemRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				((Renderer)component).sortingLayerName = "Effects";
				((Renderer)component).sortingOrder = 5;
			}
			particles.Play(true);
			Plugin.Log.LogInfo((object)$"Gust: fan particles across {val5} blowing {normalized}");
		}
	}
	public class IceSurface : MonoBehaviour
	{
		public const float FallbackSlickness = 0.95f;

		public static readonly HashSet<GameObject> All = new HashSet<GameObject>();

		private static PhysicsModifier modifier;

		private static GameObject fallbackSource;

		private static bool loggedContact;

		private static bool loggedRays;

		public static bool Any => All.Count > 0;

		public static PhysicsModifier Modifier
		{
			get
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Expected O, but got Unknown
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Expected O, but got Unknown
				if (modifier != null)
				{
					return modifier;
				}
				Ice val = FindIcePrefab();
				if ((Object)(object)val != (Object)null)
				{
					modifier = new PhysicsModifier((ModType)5, 0f - val.Slickness, ((Component)val).gameObject);
					Plugin.Log.LogInfo((object)$"Ice: the Ice block's slickness {val.Slickness:0.###} (prefab {((Object)((Component)val).gameObject).name})");
				}
				else
				{
					if ((Object)(object)fallbackSource == (Object)null)
					{
						fallbackSource = new GameObject("EMM_IceSource");
						((Object)fallbackSource).hideFlags = (HideFlags)61;
						Object.DontDestroyOnLoad((Object)(object)fallbackSource);
					}
					modifier = new PhysicsModifier((ModType)5, -0.95f, fallbackSource);
					Plugin.Log.LogWarning((object)$"Ice: no Ice block prefab found - slickness {0.95f} without ice streaks");
				}
				return modifier;
			}
		}

		private void OnEnable()
		{
			All.Add(((Component)this).gameObject);
		}

		private void OnDisable()
		{
			All.Remove(((Component)this).gameObject);
		}

		public static void Reset()
		{
			modifier = null;
			loggedContact = (loggedRays = false);
		}

		private static Ice FindIcePrefab()
		{
			PlaceableMetadataList instance = PlaceableMetadataList.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			GameObject[][] array = new GameObject[2][] { instance.allBlockPrefabs, instance.extraBlocks };
			foreach (GameObject[] array2 in array)
			{
				if (array2 == null)
				{
					continue;
				}
				GameObject[] array3 = array2;
				foreach (GameObject val in array3)
				{
					Ice val2 = (((Object)(object)val != (Object)null) ? val.GetComponentInChildren<Ice>(true) : null);
					if ((Object)(object)val2 != (Object)null)
					{
						return val2;
					}
				}
			}
			return null;
		}

		public static bool UnderRays(CharacterRaycaster r)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)r.raycastStartAnchor == (Object)null || (Object)(object)r.raycastEndAnchor == (Object)null || r.numRays <= 0)
			{
				return false;
			}
			float num = r.raycastLength * Modifiers.GetInstance().CharacterRelativeScale;
			bool queriesHitTriggers = Physics2D.queriesHitTriggers;
			Physics2D.queriesHitTriggers = false;
			try
			{
				for (int i = 0; i < r.numRays; i++)
				{
					RaycastHit2D val = Physics2D.Raycast(Vector2.op_Implicit((i == 0 || r.numRays == 1) ? r.raycastStartAnchor.position : Vector3.Lerp(r.raycastStartAnchor.position, r.raycastEndAnchor.position, (float)i / (float)(r.numRays - 1))), Vector2.op_Implicit(r.raycastDirection), num, ((LayerMask)(ref r.layerMask)).value);
					if ((Object)(object)((RaycastHit2D)(ref val)).collider != (Object)null && ((RaycastHit2D)(ref val)).distance <= r.realCollisionDistance + 0.02f && All.Contains(((Component)((RaycastHit2D)(ref val)).collider).gameObject))
					{
						return true;
					}
				}
			}
			finally
			{
				Physics2D.queriesHitTriggers = queriesHitTriggers;
			}
			return false;
		}

		internal static void Apply(Character c, bool viaRays)
		{
			c.ApplyPhysicsModifier(Modifier);
			if (Plugin.DevMode.Value)
			{
				if (viaRays && !loggedRays)
				{
					loggedRays = true;
					Plugin.Log.LogInfo((object)"Ice: slippery via the character's rays");
				}
				if (!viaRays && !loggedContact)
				{
					loggedContact = true;
					Plugin.Log.LogInfo((object)"Ice: slippery via contact");
				}
			}
		}
	}
	[HarmonyPatch(typeof(CheckCollidingPlayer), "PassPhysicsModifier")]
	internal static class IceContactPatch
	{
		private static void Postfix(CheckCollidingPlayer __instance, GameObject go)
		{
			if (IceSurface.Any && !((Object)(object)go == (Object)null) && !((Object)(object)__instance.AssociatedCharacter == (Object)null) && IceSurface.All.Contains(go))
			{
				IceSurface.Apply(__instance.AssociatedCharacter, viaRays: false);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterRaycaster), "RaycastUpdate")]
	internal static class IceRaycastPatch
	{
		private static void Postfix(CharacterRaycaster __instance)
		{
			if (IceSurface.Any && __instance.Colliding)
			{
				Character character = __instance.character;
				if (!((Object)(object)character == (Object)null) && (!__instance.NoPhysicsModifiersIfOnGround || !character.OnGround) && IceSurface.UnderRays(__instance))
				{
					IceSurface.Apply(character, viaRays: true);
				}
			}
		}
	}
	public class Icicles : PhaseClock
	{
		public float period = 10f;

		public float first = 3f;

		public float warn = 1.2f;

		public float gravity = 30f;

		public float regrow = 3f;

		public float length = 1.2f;

		public float width = 0.7f;

		public float killY = -100f;

		public int seed = 1;

		public string warnSound;

		public string fallSound;

		public string shatterSound;

		public SpriteRenderer[] icicles = (SpriteRenderer[])(object)new SpriteRenderer[0];

		public SpriteRenderer[] shards = (SpriteRenderer[])(object)new SpriteRenderer[0];

		public SpriteRenderer[] crumbs = (SpriteRenderer[])(object)new SpriteRenderer[0];

		public SpriteRenderer[] shatter = (SpriteRenderer[])(object)new SpriteRenderer[0];

		public float shatterFps = 12f;

		private const float GrowTime = 0.8f;

		private const float ShardTime = 0.7f;

		private Vector3[] home;

		private Vector3[] homeScale;

		private Quaternion[] homeRot;

		private Collider2D[] hits;

		private Color[] shardColor;

		private Color[] crumbColor;

		private Color[] shatterColor;

		private int phaseCount;

		private int cycle = -1;

		private int active = -1;

		private int mask = -1;

		private bool impacted;

		private float impactAt;

		private float lastY;

		private Vector2 impactPoint;

		private bool Cycling
		{
			get
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Invalid comparison between Unknown and I4
				if (!base.Playing)
				{
					return (int)Phase == 3;
				}
				return true;
			}
		}

		protected override void Start()
		{
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			base.Start();
			home = icicles.Select((SpriteRenderer r) => ((Component)r).transform.position).ToArray();
			homeScale = icicles.Select((SpriteRenderer r) => ((Component)r).transform.localScale).ToArray();
			homeRot = icicles.Select((SpriteRenderer r) => ((Component)r).transform.rotation).ToArray();
			hits = (Collider2D[])(object)new Collider2D[icicles.Length];
			for (int num = 0; num < icicles.Length; num++)
			{
				hits[num] = MakeHit(((Component)icicles[num]).transform);
			}
			shardColor = shards.Select((SpriteRenderer r) => Opaque(r.color)).ToArray();
			crumbColor = crumbs.Select((SpriteRenderer r) => Opaque(r.color)).ToArray();
			shatterColor = shatter.Select((SpriteRenderer r) => Opaque(r.color)).ToArray();
			foreach (SpriteRenderer item in shards.Concat(crumbs).Concat(shatter))
			{
				item.color = Clear(item.color);
			}
			Plugin.Log.LogInfo((object)$"Icicles: {icicles.Length} hanging, one falls every {period}s; art shards {shards.Length}, crumbs {crumbs.Length}");
		}

		private Collider2D MakeHit(Transform icicle)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//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_0043: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("IcicleHit");
			val.layer = 18;
			val.tag = "Hazard";
			val.transform.SetParent(icicle, false);
			Vector3 lossyScale = icicle.lossyScale;
			float num = width * 0.5f / Mathf.Max(0.01f, Mathf.Abs(lossyScale.x));
			float num2 = length / Mathf.Max(0.01f, Mathf.Abs(lossyScale.y));
			PolygonCollider2D val2 = val.AddComponent<PolygonCollider2D>();
			val2.points = (Vector2[])(object)new Vector2[3]
			{
				new Vector2(0f - num, 0f),
				new Vector2(num, 0f),
				new Vector2(0f, (0f - num2) * 0.95f)
			};
			((Collider2D)val2).isTrigger = true;
			((Behaviour)val2).enabled = false;
			val.AddComponent<CollisionTag>().bitMask = (Tag)256;
			return (Collider2D)(object)val2;
		}

		protected override void OnPhase(GamePhase from, GamePhase to)
		{
			phaseCount++;
		}

		private int Pick(int k)
		{
			int num = icicles.Length;
			if (num == 0)
			{
				return -1;
			}
			int num2 = Hash(k) % num;
			if (num > 1 && k > 0 && num2 == Hash(k - 1) % num)
			{
				num2 = (num2 + 1) % num;
			}
			return num2;
		}

		private int Hash(int k)
		{
			int num = (seed * 73856093) ^ (phaseCount * 19349663) ^ ((k + 1) * 83492791);
			int num2 = (num ^ (num >>> 13)) * 1540483477;
			return (num2 ^ (num2 >>> 15)) & 0x7FFFFFFF;
		}

		protected override void Update()
		{
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0466: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			base.Update();
			float num = PhaseTime - first;
			int num2 = ((Cycling && num >= 0f) ? Mathf.FloorToInt(num / period) : (-1));
			float num3 = ((num2 >= 0) ? (num - (float)num2 * period) : 0f);
			if (num2 != cycle)
			{
				if (active >= 0)
				{
					Rest(active);
				}
				cycle = num2;
				active = ((num2 >= 0) ? Pick(num2) : (-1));
				impacted = false;
				if (active >= 0)
				{
					lastY = home[active].y;
					FxSound.Post(warnSound, ((Component)icicles[active]).gameObject);
				}
			}
			for (int i = 0; i < icicles.Length; i++)
			{
				if (i != active)
				{
					SetHit(i, on: true);
				}
			}
			UpdateCrumbs(num3);
			UpdateShards(num3);
			UpdateShatter(num3);
			if (active < 0)
			{
				return;
			}
			Transform transform = ((Component)icicles[active]).transform;
			SpriteRenderer val = icicles[active];
			if (num3 < warn)
			{
				float num4 = num3 / warn;
				transform.position = home[active] + new Vector3(0.04f * num4 * Mathf.Sin(num3 * 61f), -0.12f * num4 * num4, 0f);
				transform.rotation = homeRot[active] * Quaternion.Euler(0f, 0f, 7f * num4 * Math