Decompiled source of Floor Is Lava v1.0.0

FloorIsLava.dll

Decompiled 36 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FloorIsLava
{
	[BepInPlugin("lakisa.floorislava", "Floor Is Lava", "1.0.0")]
	public class FloorIsLavaPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> Survey;

		internal static ConfigEntry<bool> LavaMass;

		internal static ConfigEntry<bool> MovingLava;

		internal static ConfigEntry<float> MaxSlope;

		internal static ConfigEntry<float> MassTileMeters;

		internal static ConfigEntry<float> MinWidth;

		internal static ConfigEntry<float> MinArea;

		internal static ConfigEntry<float> CrawlHeadroom;

		internal static ConfigEntry<float> DuctHeight;

		internal static ConfigEntry<float> DuctWidth;

		internal static ConfigEntry<float> TileMeters;

		internal static ConfigEntry<float> Damage;

		internal static ConfigEntry<float> TickSeconds;

		internal static ConfigEntry<float> Hop;

		internal static ConfigEntry<float> GraceSeconds;

		internal static ConfigEntry<string> SolidKindsCfg;

		internal static ConfigEntry<string> SeeThroughWordsCfg;

		internal static ConfigEntry<string> SolidWordsCfg;

		internal static ConfigEntry<string> HarmlessCfg;

		internal static string[] SolidKinds = new string[0];

		internal static string[] SeeThroughWords = new string[0];

		internal static string[] SolidWords = new string[0];

		internal static HashSet<string> HarmlessScripts = new HashSet<string>();

		internal static float MinUp => Mathf.Cos(MaxSlope.Value * (MathF.PI / 180f));

		private void Awake()
		{
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Expected O, but got Unknown
			//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_03aa: Expected O, but got Unknown
			//IL_03ab: 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_03e0: Expected O, but got Unknown
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Expected O, but got Unknown
			//IL_041b: 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_0426: Expected O, but got Unknown
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Turn the floors into lava.");
			MaxSlope = ((BaseUnityPlugin)this).Config.Bind<float>("Floors", "WalkableSlope", 60f, "Steepest tilt (degrees) that's lava. The player slides past 45; 60 makes the steep ramps (Abyss tracks) lava too. Read when a level loads, like the rest of this section.");
			Upgrade<float>(MaxSlope, 45f);
			MinWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Floors", "MinWidth", 1.5f, "Narrowest a floor can be (metres): beams, pipes and thin ledges under this stay safe.");
			MinArea = ((BaseUnityPlugin)this).Config.Bind<float>("Floors", "MinArea", 2f, "Smallest lava patch (square metres).");
			DuctHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Floors", "DuctHeight", 2.1f, "A tunnel lower than this (metres) is a vent or duct: safe. The game's ducts are 2.0 m tall, rooms 5 m or more. 0 = off.");
			DuctWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Floors", "DuctWidth", 3f, "...if its walls on two opposite sides are closer together than this (metres). Wider low rooms are lava.");
			CrawlHeadroom = ((BaseUnityPlugin)this).Config.Bind<float>("Floors", "CrawlHeadroom", 1.6f, "Floor with less room than this (metres) above it is a crawlspace (vents, ducts): safe. You stand 1.5 m tall, crouch 0.75 m. 0 = off.");
			SolidKindsCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Floors", "LavaSurfaces", "standard,metal,vent,carpet,wood,dirt,ice,metafungus,flesh", "The game's footstep surfaces (ObjectMaterial: standard, metal, vent, carpet, water, sludge, acid, wood, flesh, dirt, ice, chain, metafungus, barnacle) that can be lava. Others (chain, liquids, barnacle) stay safe.");
			Upgrade<string>(SolidKindsCfg, "standard,metal,vent,carpet,wood,dirt,ice,metafungus");
			SeeThroughWordsCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Floors", "SafeNames", "glass,window", "A surface whose material or texture name has one of these stays safe (see-through). Cutout and transparent shaders (render queue 2450+) always are.");
			SolidWordsCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Floors", "SolidNames", "root", "A cutout surface (render queue 2450-2499) whose material or texture name has one of these is solid anyway (the Nest's giant roots).");
			HarmlessCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Floors", "HarmlessScripts", "ObjectMaterial,ObjectTagger,BakeryLightMesh", "Game scripts that don't stop a surface being floor (comma separated class names). Any other script on it or above it in the level does.");
			MovingLava = ((BaseUnityPlugin)this).Config.Bind<bool>("Floors", "MovingLava", true, "Moving and scripted parts (doors, hatches, lifts, fan blades, machines) are lava too. Off = they stay safe.");
			Survey = ((BaseUnityPlugin)this).Config.Bind<bool>("Floors", "Survey", false, "Log every level's surfaces and why each is or isn't lava.");
			TileMeters = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "TileMeters", 3f, "Size of one lava texture tile in metres.");
			LavaMass = ((BaseUnityPlugin)this).Config.Bind<bool>("Look", "LavaMass", true, "The mass gets the lava texture too.");
			MassTileMeters = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "MassTileMeters", 5f, "Size of one lava tile on the mass in metres.");
			Damage = ((BaseUnityPlugin)this).Config.Bind<float>("Burn", "Damage", 1f, "Damage per burn while standing on lava (you have 5 HP).");
			TickSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Burn", "TickSeconds", 0.5f, "Seconds between burns while you stay on the lava.");
			Hop = ((BaseUnityPlugin)this).Config.Bind<float>("Burn", "Hop", 4f, "Upward kick (m/s) each burn gives you, so you can jump off. 0 = none.");
			GraceSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Burn", "GraceSeconds", 8f, "Seconds after you spawn before the lava burns, to get off the start floor.");
			ReadWords();
			((BaseUnityPlugin)this).Config.Save();
			((BaseUnityPlugin)this).Config.SettingChanged += delegate
			{
				ReadWords();
			};
			Harmony val = new Harmony("lakisa.floorislava");
			val.Patch((MethodBase)AccessTools.Method(typeof(ENT_Player), "OnControllerColliderHit", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(LavaBurn), "HitPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.Method(typeof(M_Level), "OnSpawn", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(LavaSurfaces), "SpawnPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.Method(typeof(DEN_DeathFloor), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(FloorIsLavaPlugin), "MassStartPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.Method(typeof(DEN_DeathFloor), "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(FloorIsLavaPlugin), "MassUpdatePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			GameObject val2 = new GameObject("FloorIsLava");
			Object.DontDestroyOnLoad((Object)val2);
			val2.AddComponent<LavaSurfaces>();
			val2.AddComponent<LavaBurn>();
		}

		private static void MassStartPostfix(DEN_DeathFloor __instance)
		{
			if (Enabled.Value && LavaMass.Value)
			{
				MassLava.Start(__instance);
			}
		}

		private static void MassUpdatePostfix(DEN_DeathFloor __instance)
		{
			MassLava.Update(__instance);
		}

		private static void Upgrade<T>(ConfigEntry<T> e, params T[] oldDefaults)
		{
			if (oldDefaults.Contains(e.Value))
			{
				e.Value = (T)((ConfigEntryBase)e).DefaultValue;
			}
		}

		private static string[] Words(string s)
		{
			return (from w in s.ToLowerInvariant().Split(',')
				select w.Trim() into w
				where w.Length > 0
				select w).ToArray();
		}

		private static void ReadWords()
		{
			SolidKinds = Words(SolidKindsCfg.Value);
			SeeThroughWords = Words(SeeThroughWordsCfg.Value);
			SolidWords = Words(SolidWordsCfg.Value);
			HarmlessScripts = new HashSet<string>(from w in HarmlessCfg.Value.Split(',')
				select w.Trim() into w
				where w.Length > 0
				select w);
		}

		internal static string SeeThrough(string mat, string kind, int queue)
		{
			if (!SolidKinds.Contains(kind.ToLowerInvariant()))
			{
				return "kind " + kind;
			}
			if (queue >= 2450 && (queue >= 2500 || !SolidWords.Any((string w) => mat.Contains(w))))
			{
				return "shader queue " + queue;
			}
			string[] seeThroughWords = SeeThroughWords;
			foreach (string text in seeThroughWords)
			{
				if (mat.Contains(text))
				{
					return "name " + text;
				}
			}
			return null;
		}
	}
	internal class LavaBurn : MonoBehaviour
	{
		internal static float LastTouch = -10f;

		internal static int Burns;

		internal static string LastHit = "";

		private static float nextBurn;

		private ENT_Player player;

		private float spawnTime;

		public static void HitPostfix(ENT_Player __instance, ControllerColliderHit hit)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (FloorIsLavaPlugin.Enabled.Value && !((Object)(object)hit.collider == (Object)null) && !(hit.normal.y < 0.5f))
			{
				LavaMap lavaMap = LavaSurfaces.MapOf(hit.collider);
				bool flag = (lavaMap != null && lavaMap.IsLava(hit.point)) || (hit.normal.y >= FloorIsLavaPlugin.MinUp && LavaSurfaces.Movers.Contains(((Object)hit.collider).GetInstanceID()));
				LastHit = ((Object)hit.collider).name + (flag ? " (lava)" : " (safe)");
				if (flag)
				{
					LastTouch = Time.time;
				}
			}
		}

		private void Update()
		{
			//IL_00de: 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_00ee: 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)
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject != (Object)(object)player)
			{
				player = playerObject;
				spawnTime = Time.time;
			}
			if (!((Object)(object)playerObject == (Object)null) && !((GameEntity)playerObject).dead && FloorIsLavaPlugin.Enabled.Value && !(Time.time - LastTouch > 0.15f) && !(Time.time - spawnTime < FloorIsLavaPlugin.GraceSeconds.Value) && !(Time.time < nextBurn))
			{
				nextBurn = Time.time + Mathf.Max(0.05f, FloorIsLavaPlugin.TickSeconds.Value);
				Burns++;
				((GameEntity)playerObject).Damage(DamageInfo.CreateDamageInfo(FloorIsLavaPlugin.Damage.Value, "heat"));
				float value = FloorIsLavaPlugin.Hop.Value;
				if (value > 0f && !((GameEntity)playerObject).dead)
				{
					((GameEntity)playerObject).AddForce(Vector3.up * value * 10f / 175f, "");
				}
			}
		}
	}
	internal class LavaMap
	{
		public struct Sample
		{
			public float y;

			public float slope;

			public Vector3 normal;

			public Collider col;

			public string mat;

			public string kind;

			public bool solid;

			public bool lava;

			public bool mover;

			public int patch;
		}

		public class Patch
		{
			public int id;

			public int cells;

			public float area;

			public float yMin;

			public float yMax;

			public float ySum;

			public float slopeSum;

			public int lavaCells;

			public float cover;

			public float height;

			public bool lava;

			public string why = "";

			public Dictionary<string, int> mats = new Dictionary<string, int>();
		}

		private class ColInfo
		{
			public M_Level level;

			public string still;

			public string kind;

			public string mat;

			public string clear;

			public string label;

			public int queue;

			public bool multi;

			public bool mover;
		}

		public readonly M_Level level;

		public Bounds bounds;

		public float step;

		public int nx;

		public int nz;

		public List<Sample>[] columns;

		public readonly List<Patch> patches = new List<Patch>();

		public int footprint;

		public float bottom;

		public readonly Dictionary<string, int> stillRejects = new Dictionary<string, int>();

		public readonly Dictionary<string, int> seeThrough = new Dictionary<string, int>();

		public readonly Dictionary<string, int> rejected = new Dictionary<string, int>();

		private static readonly Dictionary<int, ColInfo> infos = new Dictionary<int, ColInfo>();

		public static bool Detail;

		public static string[] Watch;

		public long ms;

		private static readonly Dictionary<int, string> stillCache = new Dictionary<int, string>();

		public static float Budget = 3f;

		private const float CrouchHeight = 0.75f;

		private static readonly Vector3[] Sides;

		private const float BigCreature = 4f;

		private static void Count(Dictionary<string, int> d, string k)
		{
			d.TryGetValue(k, out var value);
			d[k] = value + 1;
		}

		private static ColInfo Info(Collider c)
		{
			int instanceID = ((Object)c).GetInstanceID();
			if (infos.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			if (infos.Count > 200000)
			{
				infos.Clear();
			}
			value = new ColInfo
			{
				level = ((Component)c).GetComponentInParent<M_Level>()
			};
			if ((Object)(object)value.level != (Object)null)
			{
				value.still = StillReason(c, ((Component)value.level).transform);
				value.kind = Kind(c);
				value.mat = MaterialOf(c, -1, out value.queue, out value.multi);
				value.clear = FloorIsLavaPlugin.SeeThrough(value.mat, value.kind, value.queue);
				value.label = " | " + ((Object)c).name + " | " + value.mat + " q" + value.queue + " " + value.kind;
				value.mover = value.still != null && FloorIsLavaPlugin.MovingLava.Value && CanCarryLava(c, value);
				if (Bouncy(c))
				{
					value.still = "trampoline";
					value.mover = false;
				}
			}
			infos[instanceID] = value;
			return value;
		}

		public string TopRejects(int n)
		{
			return string.Join("\n", from kv in rejected.OrderByDescending((KeyValuePair<string, int> kv) => kv.Value).Take(n)
				select $"    not lava {(float)kv.Value * step * step:F0} m2: {kv.Key}");
		}

		public LavaMap(M_Level l)
		{
			level = l;
		}

		private static Bounds WorldBounds(M_Level l)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)l == (Object)null)
			{
				return default(Bounds);
			}
			Bounds val = l.GetLocalBounds();
			Vector3 size = ((Bounds)(ref val)).size;
			if (((Vector3)(ref size)).sqrMagnitude < 1f)
			{
				val = l.CalculateBounds();
			}
			Matrix4x4 localToWorldMatrix = ((Component)l).transform.localToWorldMatrix;
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(((Bounds)(ref val)).center), Vector3.zero);
			for (int i = 0; i < 8; i++)
			{
				((Bounds)(ref result)).Encapsulate(((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(((Bounds)(ref val)).center + Vector3.Scale(((Bounds)(ref val)).extents, new Vector3((float)((i & 1) * 2 - 1), (float)((i & 2) - 1), (float)((i & 4) / 2 - 1)))));
			}
			return result;
		}

		public int Column(Vector3 p)
		{
			//IL_0000: 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_0024: 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)
			int num = Mathf.FloorToInt((p.x - ((Bounds)(ref bounds)).min.x) / step);
			int num2 = Mathf.FloorToInt((p.z - ((Bounds)(ref bounds)).min.z) / step);
			if (num >= 0 && num2 >= 0 && num < nx && num2 < nz)
			{
				return num2 * nx + num;
			}
			return -1;
		}

		public List<string> LavaSpots(int n)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_00dc: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
			List<Patch> list = (from p in patches
				where p.lava
				orderby p.lavaCells descending
				select p).Take(n).ToList();
			List<string> list2 = new List<string>();
			foreach (Patch item in list)
			{
				Vector3 val = Vector3.zero;
				int num = 0;
				for (int num2 = 0; num2 < columns.Length; num2++)
				{
					if (columns[num2] == null)
					{
						continue;
					}
					foreach (Sample item2 in columns[num2])
					{
						if (item2.lava && item2.patch == item.id)
						{
							Vector3 val2 = CellCentre(num2);
							val2.y = item2.y;
							val += val2;
							num++;
						}
					}
				}
				Vector3 val3 = val / (float)Mathf.Max(1, num);
				Vector3 val4 = val3;
				string text = "";
				float num3 = float.MaxValue;
				for (int num4 = 0; num4 < columns.Length; num4++)
				{
					if (columns[num4] == null)
					{
						continue;
					}
					foreach (Sample item3 in columns[num4])
					{
						if (item3.lava && item3.patch == item.id)
						{
							Vector3 val5 = CellCentre(num4);
							val5.y = item3.y;
							Vector3 val6 = val5 - val3;
							if (((Vector3)(ref val6)).sqrMagnitude < num3)
							{
								val6 = val5 - val3;
								num3 = ((Vector3)(ref val6)).sqrMagnitude;
								val4 = val5;
								text = (((Object)(object)item3.col != (Object)null) ? ((Object)item3.col).name : "?");
							}
						}
					}
				}
				list2.Add($"{val4.x:F2};{val4.y:F2};{val4.z:F2};{(float)item.lavaCells * step * step:F0};{text}");
			}
			return list2;
		}

		public Vector3 CellCentre(int c)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(((Bounds)(ref bounds)).min.x + ((float)(c % nx) + 0.5f) * step, 0f, ((Bounds)(ref bounds)).min.z + ((float)(c / nx) + 0.5f) * step);
		}

		public bool IsLava(Vector3 p)
		{
			//IL_0001: 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)
			int num = Column(p);
			if (num < 0 || columns[num] == null)
			{
				return false;
			}
			foreach (Sample item in columns[num])
			{
				if (item.lava && Mathf.Abs(item.y - p.y) < 0.4f)
				{
					return true;
				}
			}
			return false;
		}

		public IEnumerator Scan()
		{
			Stopwatch watch = Stopwatch.StartNew();
			if ((Object)(object)level == (Object)null)
			{
				yield break;
			}
			Physics.SyncTransforms();
			bounds = WorldBounds(level);
			float num = ((Bounds)(ref bounds)).size.x * ((Bounds)(ref bounds)).size.z;
			step = Mathf.Max(0.5f, Mathf.Sqrt(num / 60000f));
			nx = Mathf.Max(1, Mathf.CeilToInt(((Bounds)(ref bounds)).size.x / step));
			nz = Mathf.Max(1, Mathf.CeilToInt(((Bounds)(ref bounds)).size.z / step));
			columns = new List<Sample>[nx * nz];
			float minUp = Mathf.Cos(FloorIsLavaPlugin.MaxSlope.Value * (MathF.PI / 180f));
			float top = ((Bounds)(ref bounds)).max.y + 1f;
			float depth = ((Bounds)(ref bounds)).size.y + 2f;
			bottom = float.MaxValue;
			bool backfaces = Physics.queriesHitBackfaces;
			Stopwatch frame = Stopwatch.StartNew();
			RaycastHit val2 = default(RaycastHit);
			RaycastHit val3 = default(RaycastHit);
			for (int c = 0; c < columns.Length; c++)
			{
				if ((Object)(object)level == (Object)null)
				{
					yield break;
				}
				Vector3 val = CellCentre(c);
				val.y = top;
				bool flag = false;
				Physics.queriesHitBackfaces = false;
				for (int i = 0; i < 40; i++)
				{
					float num2 = top - depth - val.y;
					if (num2 >= 0f || !Physics.Raycast(val, Vector3.down, ref val2, 0f - num2, -1, (QueryTriggerInteraction)1))
					{
						break;
					}
					val = ((RaycastHit)(ref val2)).point + Vector3.down * 0.002f;
					ColInfo colInfo = Info(((RaycastHit)(ref val2)).collider);
					if ((Object)(object)colInfo.level != (Object)(object)level)
					{
						continue;
					}
					flag = true;
					if (((RaycastHit)(ref val2)).normal.y < minUp)
					{
						continue;
					}
					if (colInfo.still != null && !colInfo.mover)
					{
						Count(stillRejects, colInfo.still);
						Count(rejected, "still:" + colInfo.still + colInfo.label);
						continue;
					}
					float num3 = Mathf.Max(FloorIsLavaPlugin.CrawlHeadroom.Value, FloorIsLavaPlugin.DuctHeight.Value);
					if (num3 > 0f && Physics.Raycast(((RaycastHit)(ref val2)).point + Vector3.up * 0.05f, Vector3.up, ref val3, num3 - 0.05f, -1, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val3)).distance + 0.05f >= 0.75f && (Object)(object)((RaycastHit)(ref val3)).collider.attachedRigidbody == (Object)null && (Object)(object)((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<ENT_Player>() == (Object)null)
					{
						float num4 = ((RaycastHit)(ref val3)).distance + 0.05f;
						string text = ((num4 < FloorIsLavaPlugin.CrawlHeadroom.Value) ? "crawlspace" : ((num4 < FloorIsLavaPlugin.DuctHeight.Value && Narrow(((RaycastHit)(ref val2)).point + Vector3.up * Mathf.Min(1f, num4 * 0.5f))) ? "duct" : null));
						if (text != null)
						{
							Count(stillRejects, text);
							Count(rejected, $"{text} under {((Object)((RaycastHit)(ref val3)).collider).name} at {Mathf.Floor(num4 * 5f) / 5f:F1} m" + colInfo.label);
							continue;
						}
					}
					string mat = colInfo.mat;
					string kind = colInfo.kind;
					string text2 = colInfo.clear;
					if (colInfo.multi)
					{
						mat = MaterialOf(((RaycastHit)(ref val2)).collider, ((RaycastHit)(ref val2)).triangleIndex, out var queue, out var _);
						text2 = FloorIsLavaPlugin.SeeThrough(mat, kind, queue);
					}
					if (text2 != null)
					{
						Count(seeThrough, text2);
						Count(rejected, "clear:" + text2 + colInfo.label);
						continue;
					}
					List<Sample>[] array = columns;
					int num5 = c;
					(array[num5] ?? (array[num5] = new List<Sample>())).Add(new Sample
					{
						y = ((RaycastHit)(ref val2)).point.y,
						normal = ((RaycastHit)(ref val2)).normal,
						slope = Mathf.Acos(Mathf.Clamp01(((RaycastHit)(ref val2)).normal.y)) * 57.29578f,
						col = ((RaycastHit)(ref val2)).collider,
						mat = mat,
						kind = kind,
						solid = true,
						mover = colInfo.mover,
						patch = -1
					});
					bottom = Mathf.Min(bottom, ((RaycastHit)(ref val2)).point.y);
				}
				Physics.queriesHitBackfaces = backfaces;
				if (flag)
				{
					footprint++;
				}
				if (frame.Elapsed.TotalMilliseconds > (double)Budget)
				{
					watch.Stop();
					yield return null;
					watch.Start();
					frame.Restart();
				}
			}
			BuildPatches();
			Judge();
			ms = watch.ElapsedMilliseconds;
		}

		private void BuildPatches()
		{
			float num = step * Mathf.Tan(FloorIsLavaPlugin.MaxSlope.Value * (MathF.PI / 180f)) + 0.1f;
			Stack<(int, int)> stack = new Stack<(int, int)>();
			for (int i = 0; i < columns.Length; i++)
			{
				if (columns[i] == null)
				{
					continue;
				}
				for (int j = 0; j < columns[i].Count; j++)
				{
					if (columns[i][j].patch >= 0)
					{
						continue;
					}
					Patch patch = new Patch
					{
						id = patches.Count,
						yMin = float.MaxValue,
						yMax = float.MinValue
					};
					patches.Add(patch);
					Mark(i, j, patch);
					stack.Push((i, j));
					while (stack.Count > 0)
					{
						(int, int) tuple = stack.Pop();
						int item = tuple.Item1;
						int item2 = tuple.Item2;
						float y = columns[item][item2].y;
						int num2 = item % nx;
						int num3 = item / nx;
						for (int k = 0; k < 4; k++)
						{
							int num4 = num2 + k switch
							{
								1 => -1, 
								0 => 1, 
								_ => 0, 
							};
							int num5 = num3 + k switch
							{
								3 => -1, 
								2 => 1, 
								_ => 0, 
							};
							if (num4 < 0 || num5 < 0 || num4 >= nx || num5 >= nz)
							{
								continue;
							}
							List<Sample> list = columns[num5 * nx + num4];
							if (list == null)
							{
								continue;
							}
							for (int l = 0; l < list.Count; l++)
							{
								if (list[l].patch < 0 && Mathf.Abs(list[l].y - y) <= num)
								{
									Mark(num5 * nx + num4, l, patch);
									stack.Push((num5 * nx + num4, l));
								}
							}
						}
					}
				}
			}
		}

		private void Mark(int c, int i, Patch p)
		{
			Sample value = columns[c][i];
			value.patch = p.id;
			columns[c][i] = value;
			p.cells++;
			p.ySum += value.y;
			p.slopeSum += value.slope;
			p.yMin = Mathf.Min(p.yMin, value.y);
			p.yMax = Mathf.Max(p.yMax, value.y);
			string key = value.kind + " " + value.mat;
			p.mats.TryGetValue(key, out var value2);
			p.mats[key] = value2 + 1;
		}

		private static bool Narrow(Vector3 at)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			float value = FloorIsLavaPlugin.DuctWidth.Value;
			Vector3[] sides = Sides;
			RaycastHit val2 = default(RaycastHit);
			RaycastHit val3 = default(RaycastHit);
			foreach (Vector3 val in sides)
			{
				if (Physics.Raycast(at, val, ref val2, value, -1, (QueryTriggerInteraction)1) && Physics.Raycast(at, -val, ref val3, value, -1, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val2)).distance + ((RaycastHit)(ref val3)).distance < value)
				{
					return true;
				}
			}
			return false;
		}

		private int Find(int x, int z, int patch)
		{
			if (x < 0 || z < 0 || x >= nx || z >= nz)
			{
				return -1;
			}
			List<Sample> list = columns[z * nx + x];
			if (list == null)
			{
				return -1;
			}
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].patch == patch)
				{
					return i;
				}
			}
			return -1;
		}

		private static long Key(int c, int i)
		{
			return ((long)c << 8) | i;
		}

		private void Judge()
		{
			float num = step * step;
			float num2 = (float)Mathf.Max(1, footprint) * num;
			int num3 = Mathf.Max(0, Mathf.CeilToInt((FloorIsLavaPlugin.MinWidth.Value / step - 1f) / 2f));
			HashSet<long> hashSet = new HashSet<long>();
			for (int i = 0; i < columns.Length; i++)
			{
				if (columns[i] == null)
				{
					continue;
				}
				int num4 = i % nx;
				int num5 = i / nx;
				for (int j = 0; j < columns[i].Count; j++)
				{
					int patch = columns[i][j].patch;
					bool flag = true;
					for (int k = -num3; k <= num3 && flag; k++)
					{
						for (int l = -num3; l <= num3 && flag; l++)
						{
							if (Find(num4 + l, num5 + k, patch) < 0)
							{
								flag = false;
							}
						}
					}
					if (flag)
					{
						hashSet.Add(Key(i, j));
					}
				}
			}
			for (int m = 0; m < columns.Length; m++)
			{
				if (columns[m] == null)
				{
					continue;
				}
				int num6 = m % nx;
				int num7 = m / nx;
				for (int n = 0; n < columns[m].Count; n++)
				{
					Sample value = columns[m][n];
					for (int num8 = -num3; num8 <= num3; num8++)
					{
						if (value.lava)
						{
							break;
						}
						for (int num9 = -num3; num9 <= num3; num9++)
						{
							if (value.lava)
							{
								break;
							}
							int num10 = Find(num6 + num9, num7 + num8, value.patch);
							if (num10 >= 0 && hashSet.Contains(Key((num7 + num8) * nx + num6 + num9, num10)))
							{
								value.lava = true;
							}
						}
					}
					if (value.mover)
					{
						value.lava = true;
					}
					columns[m][n] = value;
					if (value.lava)
					{
						patches[value.patch].lavaCells++;
					}
				}
			}
			float value2 = FloorIsLavaPlugin.MinArea.Value;
			foreach (Patch patch2 in patches)
			{
				patch2.area = (float)patch2.cells * num;
				patch2.cover = patch2.area / num2;
				patch2.height = patch2.ySum / (float)patch2.cells - bottom;
				patch2.lava = (float)patch2.lavaCells * num >= value2;
				patch2.why = ((patch2.lavaCells == 0) ? "narrow " : (patch2.lava ? "" : "small "));
			}
			for (int num11 = 0; num11 < columns.Length; num11++)
			{
				if (columns[num11] == null)
				{
					continue;
				}
				for (int num12 = 0; num12 < columns[num11].Count; num12++)
				{
					Sample value3 = columns[num11][num12];
					if (value3.lava && !value3.mover && !patches[value3.patch].lava)
					{
						value3.lava = false;
						columns[num11][num12] = value3;
					}
				}
			}
		}

		public static string StillReason(Collider c, Transform root)
		{
			if ((Object)(object)c.attachedRigidbody != (Object)null)
			{
				return "Rigidbody";
			}
			int instanceID = ((Object)c).GetInstanceID();
			if (stillCache.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			value = null;
			Transform val = ((Component)c).transform;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root && value == null)
			{
				Component[] components = ((Component)val).GetComponents<Component>();
				foreach (Component val2 in components)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						if (val2 is Animator || val2 is Animation || val2 is Joint)
						{
							value = ((object)val2).GetType().Name;
							break;
						}
						if (val2 is MonoBehaviour && !Harmless(((object)val2).GetType()))
						{
							value = ((object)val2).GetType().Name;
							break;
						}
					}
				}
				val = val.parent;
			}
			stillCache[instanceID] = value;
			return value;
		}

		private static bool CanCarryLava(Collider c, ColInfo i)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)c.attachedRigidbody != (Object)null && !c.attachedRigidbody.isKinematic)
			{
				return false;
			}
			if (i.mat == "(none)" || Bouncy(c))
			{
				return false;
			}
			if ((Object)(object)((Component)c).GetComponentInParent<Item_Object>() != (Object)null || (Object)(object)((Component)c).GetComponentInParent<ENT_Player>() != (Object)null)
			{
				return false;
			}
			Bounds val = c.bounds;
			Vector3 size = ((Bounds)(ref val)).size;
			if (!((Object)(object)((Component)c).GetComponentInParent<GameEntity>() == (Object)null))
			{
				return Mathf.Max(size.x, size.z) >= 4f;
			}
			return true;
		}

		private static bool Bouncy(Collider c)
		{
			if (!((Object)(object)((Component)c).GetComponentInParent<ENV_JumpPad>() != (Object)null) && !((Object)(object)((Component)c).GetComponentInChildren<ENV_JumpPad>() != (Object)null))
			{
				return ((Object)c).name.IndexOf("trampoline", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return true;
		}

		public static string Kind(Collider c)
		{
			ObjectMaterial componentInParent = ((Component)c).GetComponentInParent<ObjectMaterial>();
			if (!((Object)(object)componentInParent != (Object)null))
			{
				return "standard";
			}
			return ((object)Unsafe.As<MaterialType, MaterialType>(ref componentInParent.type)/*cast due to .constrained prefix*/).ToString();
		}

		private static bool Harmless(Type t)
		{
			string text = t.Namespace ?? "";
			if (!text.StartsWith("UnityEngine") && !text.StartsWith("TMPro") && !t.Name.StartsWith("Bakery") && !t.Name.StartsWith("CL_Handhold"))
			{
				return FloorIsLavaPlugin.HarmlessScripts.Contains(t.Name);
			}
			return true;
		}

		public static string MaterialName(RaycastHit hit, out int queue)
		{
			bool multi;
			return MaterialOf(((RaycastHit)(ref hit)).collider, ((RaycastHit)(ref hit)).triangleIndex, out queue, out multi);
		}

		public static string MaterialOf(Collider c, int triangle, out int queue, out bool multi)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			queue = 2000;
			multi = false;
			Renderer val = ((Component)c).GetComponent<Renderer>() ?? ((Component)c).GetComponentInParent<Renderer>() ?? ((Component)c).GetComponentInChildren<Renderer>();
			if ((Object)(object)val == (Object)null)
			{
				return "(none)";
			}
			Material[] sharedMaterials = val.sharedMaterials;
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				return "(none)";
			}
			Material val2 = sharedMaterials[0];
			if (sharedMaterials.Length > 1)
			{
				MeshCollider val3 = (MeshCollider)(object)((c is MeshCollider) ? c : null);
				if (val3 != null && (Object)(object)val3.sharedMesh != (Object)null && val3.sharedMesh.isReadable)
				{
					multi = true;
				}
			}
			if (multi && triangle >= 0)
			{
				Mesh sharedMesh = ((MeshCollider)c).sharedMesh;
				int num = triangle * 3;
				int num2 = 0;
				for (int i = 0; i < sharedMesh.subMeshCount && i < sharedMaterials.Length; i++)
				{
					int indexCount = (int)sharedMesh.GetIndexCount(i);
					if (num < num2 + indexCount)
					{
						val2 = sharedMaterials[i];
						break;
					}
					num2 += indexCount;
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return "(none)";
			}
			queue = val2.renderQueue;
			string text = ((val2.HasProperty("_MainTex") && (Object)(object)val2.mainTexture != (Object)null) ? ((Object)val2.mainTexture).name : "");
			return (((Object)val2).name + "|" + text).ToLowerInvariant();
		}

		public string Ceilings()
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			RaycastHit val2 = default(RaycastHit);
			foreach (Patch item in patches.Where((Patch p) => p.lava))
			{
				List<float> list = new List<float>();
				string text = "";
				string text2 = "";
				for (int num = 0; num < columns.Length; num++)
				{
					if (columns[num] == null)
					{
						continue;
					}
					foreach (Sample item2 in columns[num])
					{
						if (item2.patch == item.id && item2.lava)
						{
							Vector3 val = CellCentre(num);
							val.y = item2.y;
							if (Physics.Raycast(val + Vector3.up * 0.05f, Vector3.up, ref val2, 6f, -1, (QueryTriggerInteraction)1))
							{
								list.Add(((RaycastHit)(ref val2)).distance + 0.05f);
								text2 = ((Object)((RaycastHit)(ref val2)).collider).name;
							}
							else
							{
								list.Add(99f);
							}
							if (text == "" && (Object)(object)item2.col != (Object)null)
							{
								text = ((Object)item2.col).name;
							}
						}
					}
				}
				list.Sort();
				float num2 = ((list.Count > 0) ? list[list.Count / 2] : 99f);
				if (num2 < 6f)
				{
					stringBuilder.AppendLine($"  CEILING {num2:F2} m over {(float)item.lavaCells * step * step:F0} m2 lava on {text} (under {text2}), {item.mats.OrderByDescending((KeyValuePair<string, int> kv) => kv.Value).First().Key}");
				}
			}
			return stringBuilder.ToString();
		}

		public string Report(int maxPatches)
		{
			//IL_0029: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine($"SURVEY {((Object)level).name}: bounds {((Bounds)(ref bounds)).size.x:F0}x{((Bounds)(ref bounds)).size.y:F0}x{((Bounds)(ref bounds)).size.z:F0} m, step {step:F2}, footprint {(float)footprint * step * step:F0} m2, bottom {bottom:F1}, {patches.Count} patches, {patches.Count((Patch patch) => patch.lava)} lava, {ms} ms");
			foreach (Patch p in (from patch in patches
				where patch.area >= 2f
				orderby patch.area descending
				select patch).Take(maxPatches))
			{
				string text = string.Join(", ", from kv in p.mats.OrderByDescending((KeyValuePair<string, int> kv) => kv.Value).Take(3)
					select $"{kv.Key} {100 * kv.Value / p.cells}%");
				stringBuilder.AppendLine(string.Format("  PATCH {0} {1} {2}area {3:F0} m2 cover {4:F1}% up {5:F1} m slope {6:F0} lava {7:F0} m2 | {8}", p.id, p.lava ? "LAVA" : "safe", p.why, p.area, 100f * p.cover, p.height, p.slopeSum / (float)p.cells, (float)p.lavaCells * step * step, text));
			}
			foreach (KeyValuePair<string, int> item in rejected.OrderByDescending((KeyValuePair<string, int> kv) => kv.Value).Take((Watch != null) ? 40 : 15))
			{
				stringBuilder.AppendLine($"  REJECT {(float)item.Value * step * step:F0} m2: {item.Key}");
			}
			if (seeThrough.Count > 0)
			{
				stringBuilder.AppendLine("  SEE-THROUGH: " + string.Join(", ", from kv in seeThrough.OrderByDescending((KeyValuePair<string, int> kv) => kv.Value).Take(12)
					select $"{kv.Key} {kv.Value}"));
			}
			if (Watch != null)
			{
				Dictionary<string, float[]> dictionary = new Dictionary<string, float[]>();
				List<Sample>[] array = columns;
				foreach (List<Sample> list in array)
				{
					if (list == null)
					{
						continue;
					}
					foreach (Sample s in list)
					{
						if (!((Object)(object)s.col == (Object)null) && Watch.Any((string w) => ((Object)s.col).name.IndexOf(w, StringComparison.OrdinalIgnoreCase) >= 0))
						{
							string key = ((Object)s.col).name + " | " + s.mat + " " + s.kind + (s.mover ? " mover" : "") + " | patch " + patches[s.patch].why + patches[s.patch].area.ToString("F0") + " m2";
							if (!dictionary.TryGetValue(key, out var value))
							{
								value = (dictionary[key] = new float[2]);
							}
							value[(!s.lava) ? 1u : 0u] += step * step;
						}
					}
				}
				foreach (KeyValuePair<string, float[]> item2 in dictionary.OrderByDescending((KeyValuePair<string, float[]> k) => k.Value[0] + k.Value[1]).Take(40))
				{
					stringBuilder.AppendLine($"  WATCH lava {item2.Value[0]:F0} / safe {item2.Value[1]:F0} m2: {item2.Key}");
				}
				foreach (KeyValuePair<string, int> item3 in (from kv in rejected
					where Watch.Any((string w) => kv.Key.IndexOf(w, StringComparison.OrdinalIgnoreCase) >= 0)
					orderby kv.Value descending
					select kv).Take(40))
				{
					stringBuilder.AppendLine($"  WATCH REJECT {(float)item3.Value * step * step:F0} m2: {item3.Key}");
				}
			}
			if (stillRejects.Count > 0)
			{
				stringBuilder.AppendLine("  NOT STILL: " + string.Join(", ", from kv in stillRejects.OrderByDescending((KeyValuePair<string, int> kv) => kv.Value).Take(12)
					select $"{kv.Key} {kv.Value}"));
			}
			return stringBuilder.ToString();
		}

		static LavaMap()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] obj = new Vector3[4]
			{
				Vector3.right,
				Vector3.forward,
				default(Vector3),
				default(Vector3)
			};
			Vector3 val = Vector3.right + Vector3.forward;
			obj[2] = ((Vector3)(ref val)).normalized;
			val = Vector3.right - Vector3.forward;
			obj[3] = ((Vector3)(ref val)).normalized;
			Sides = (Vector3[])(object)obj;
		}
	}
	internal class LavaSurfaces : MonoBehaviour
	{
		private const float Lift = 0.02f;

		private readonly HashSet<int> done = new HashSet<int>();

		private static readonly List<(M_Level level, int frame)> queue = new List<(M_Level, int)>();

		internal static readonly Dictionary<M_Level, LavaMap> Maps = new Dictionary<M_Level, LavaMap>();

		internal static readonly HashSet<int> Movers = new HashSet<int>();

		private bool busy;

		private float nextScan;

		internal static int Levels;

		internal static int Skins;

		internal static int Triangles;

		internal static int Quads;

		private static bool nearYou;

		private static readonly Dictionary<int, M_Level> levelOf = new Dictionary<int, M_Level>();

		internal static bool Rush
		{
			get
			{
				if (!((Object)(object)ENT_Player.playerObject == (Object)null) && !nearYou)
				{
					return Loading();
				}
				return true;
			}
		}

		internal static void SpawnPostfix(M_Level __instance)
		{
			queue.Add((__instance, Time.frameCount));
		}

		private void Awake()
		{
			SceneManager.sceneLoaded += delegate
			{
				nextScan = 0f;
			};
		}

		private static bool Loading()
		{
			try
			{
				return (Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.IsLoading();
			}
			catch (Exception)
			{
				return true;
			}
		}

		private static bool Near(M_Level l)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject == (Object)null || (Object)(object)l == (Object)null)
			{
				return false;
			}
			Bounds localBounds = l.GetLocalBounds();
			((Bounds)(ref localBounds)).Expand(60f);
			return ((Bounds)(ref localBounds)).Contains(((Component)l).transform.InverseTransformPoint(((Component)playerObject).transform.position));
		}

		private void Update()
		{
			LavaTexture.Tick();
			LavaMap.Budget = (Rush ? 200f : 3f);
			if (!FloorIsLavaPlugin.Enabled.Value || busy)
			{
				return;
			}
			int num = -1;
			for (int i = 0; i < queue.Count; i++)
			{
				var (val, num2) = queue[i];
				if ((Object)(object)val == (Object)null || done.Contains(((Object)val).GetInstanceID()))
				{
					queue.RemoveAt(i--);
				}
				else if (num2 < Time.frameCount && ((Component)val).gameObject.activeInHierarchy)
				{
					if (num < 0)
					{
						num = i;
					}
					if (Near(val))
					{
						num = i;
						break;
					}
				}
			}
			if (num >= 0)
			{
				M_Level item = queue[num].level;
				queue.RemoveAt(num);
				done.Add(((Object)item).GetInstanceID());
				((MonoBehaviour)this).StartCoroutine(Cover(item));
			}
			else
			{
				if (Time.unscaledTime < nextScan)
				{
					return;
				}
				nextScan = Time.unscaledTime + 2f;
				M_Level[] array = Object.FindObjectsByType<M_Level>((FindObjectsSortMode)0);
				foreach (M_Level l in array)
				{
					if (!done.Contains(((Object)l).GetInstanceID()) && !queue.Exists(((M_Level level, int frame) q) => (Object)(object)q.level == (Object)(object)l))
					{
						queue.Add((l, Time.frameCount - 1));
					}
				}
			}
		}

		internal static LavaMap MapOf(Collider c)
		{
			int instanceID = ((Object)c).GetInstanceID();
			if (!levelOf.TryGetValue(instanceID, out var value))
			{
				value = (levelOf[instanceID] = ((Component)c).GetComponentInParent<M_Level>());
			}
			if (!((Object)(object)value != (Object)null) || !Maps.TryGetValue(value, out var value2))
			{
				return null;
			}
			return value2;
		}

		private IEnumerator Cover(M_Level level)
		{
			busy = true;
			try
			{
				return CoverSteps(level);
			}
			catch (Exception)
			{
				busy = false;
				nearYou = false;
				throw;
			}
		}

		private IEnumerator CoverSteps(M_Level level)
		{
			try
			{
				nearYou = Near(level);
				LavaMap.Budget = (Rush ? 200f : 3f);
				float started = Time.realtimeSinceStartup;
				LavaMap map = new LavaMap(level);
				yield return map.Scan();
				if (!((Object)(object)level != (Object)null))
				{
					yield break;
				}
				List<M_Level> list = new List<M_Level>();
				foreach (M_Level key in Maps.Keys)
				{
					if ((Object)(object)key == (Object)null)
					{
						list.Add(key);
					}
				}
				foreach (M_Level item in list)
				{
					Maps.Remove(item);
				}
				Maps[level] = map;
				int t0 = Triangles;
				int s0 = Skins;
				int q0 = Quads;
				yield return Skin(map);
				if (!((Object)(object)level == (Object)null))
				{
					Levels++;
					FloorIsLavaPlugin.Log.LogInfo((object)string.Format("Lava on {0}: {1} floor patches, {2} skins, {3} triangles, {4} squares, scan {5} ms, ready {6:F2} s after it was queued{7}", ((Object)level).name, map.patches.FindAll((LavaMap.Patch p) => p.lava).Count, Skins - s0, Triangles - t0, Quads - q0, map.ms, Time.realtimeSinceStartup - started, Rush ? " (loading)" : ""));
					if (FloorIsLavaPlugin.Survey.Value)
					{
						FloorIsLavaPlugin.Log.LogInfo((object)map.Report(25));
					}
					else if (map.rejected.Count > 0)
					{
						FloorIsLavaPlugin.Log.LogInfo((object)map.TopRejects(6));
					}
				}
			}
			finally
			{
				busy = false;
				nearYou = false;
			}
		}

		internal static IEnumerator SurveyLevel(M_Level level, List<LavaMap> into)
		{
			LavaMap map = new LavaMap(level);
			yield return map.Scan();
			into.Add(map);
		}

		private IEnumerator Skin(LavaMap map)
		{
			HashSet<MeshRenderer> hashSet = new HashSet<MeshRenderer>();
			List<(Vector3 p, Vector3 n)> quads = new List<(Vector3, Vector3)>();
			Dictionary<Transform, List<(Vector3 p, Vector3 n)>> moving = new Dictionary<Transform, List<(Vector3, Vector3)>>();
			for (int i = 0; i < map.columns.Length; i++)
			{
				if (map.columns[i] == null)
				{
					continue;
				}
				foreach (LavaMap.Sample item2 in map.columns[i])
				{
					if (!item2.lava || (Object)(object)item2.col == (Object)null)
					{
						continue;
					}
					if (item2.mover)
					{
						Movers.Add(((Object)item2.col).GetInstanceID());
					}
					MeshRenderer component = ((Component)item2.col).GetComponent<MeshRenderer>();
					MeshFilter val = (((Object)(object)component != (Object)null) ? ((Component)component).GetComponent<MeshFilter>() : null);
					if ((Object)(object)component != (Object)null && ((Renderer)component).enabled && (Object)(object)val != (Object)null && (Object)(object)val.sharedMesh != (Object)null && val.sharedMesh.isReadable)
					{
						hashSet.Add(component);
						continue;
					}
					Vector3 item = map.CellCentre(i);
					item.y = item2.y;
					if (!item2.mover)
					{
						quads.Add((item, item2.normal));
						continue;
					}
					if (!moving.TryGetValue(((Component)item2.col).transform, out List<(Vector3, Vector3)> value))
					{
						value = (moving[((Component)item2.col).transform] = new List<(Vector3, Vector3)>());
					}
					value.Add((item, item2.normal));
				}
			}
			Stopwatch frame = Stopwatch.StartNew();
			foreach (MeshRenderer item3 in hashSet)
			{
				if (!((Object)(object)item3 == (Object)null))
				{
					try
					{
						FromMesh(map, item3);
					}
					catch (Exception ex)
					{
						FloorIsLavaPlugin.Log.LogWarning((object)("skin " + ((Object)item3).name + ": " + ex.Message));
					}
					if (frame.Elapsed.TotalMilliseconds > (double)LavaMap.Budget)
					{
						yield return null;
						frame.Restart();
					}
				}
			}
			if (quads.Count > 0 && (Object)(object)map.level != (Object)null)
			{
				FromCells(map, ((Component)map.level).transform, quads);
			}
			foreach (KeyValuePair<Transform, List<(Vector3, Vector3)>> item4 in moving)
			{
				if ((Object)(object)item4.Key != (Object)null)
				{
					FromCells(map, item4.Key, item4.Value);
				}
			}
		}

		private void FromMesh(LavaMap map, MeshRenderer r)
		{
			//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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			Mesh sharedMesh = ((Component)r).GetComponent<MeshFilter>().sharedMesh;
			Matrix4x4 localToWorldMatrix = ((Component)r).transform.localToWorldMatrix;
			Matrix4x4 inverse = ((Matrix4x4)(ref localToWorldMatrix)).inverse;
			Matrix4x4 transpose = ((Matrix4x4)(ref inverse)).transpose;
			float num = Mathf.Cos(FloorIsLavaPlugin.MaxSlope.Value * (MathF.PI / 180f));
			Vector3[] vertices = sharedMesh.vertices;
			List<Vector3> verts = new List<Vector3>();
			List<int> list = new List<int>();
			for (int i = 0; i < sharedMesh.subMeshCount; i++)
			{
				if ((int)sharedMesh.GetTopology(i) != 0)
				{
					continue;
				}
				int[] triangles = sharedMesh.GetTriangles(i);
				for (int j = 0; j + 2 < triangles.Length; j += 3)
				{
					Vector3 val = vertices[triangles[j]];
					Vector3 val2 = vertices[triangles[j + 1]];
					Vector3 val3 = vertices[triangles[j + 2]];
					Vector3 val4 = ((Matrix4x4)(ref transpose)).MultiplyVector(Vector3.Cross(val2 - val, val3 - val));
					if (!(((Vector3)(ref val4)).sqrMagnitude < 1E-12f) && !(((Vector3)(ref val4)).normalized.y < num))
					{
						Vector3 a = ((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(val);
						Vector3 b = ((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(val2);
						Vector3 c = ((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(val3);
						Split(map, a, b, c, verts, list, 0);
					}
				}
			}
			if (list.Count > 0)
			{
				MakeSkin(((Component)r).transform, ((Component)r).gameObject.layer, verts, list);
				Triangles += list.Count / 3;
			}
		}

		private static void Split(LavaMap map, Vector3 a, Vector3 b, Vector3 c, List<Vector3> verts, List<int> tris, int depth)
		{
			//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_0002: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00ed: 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_00ff: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_00b5: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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)
			Vector3 val = b - a;
			float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
			val = c - b;
			float sqrMagnitude2 = ((Vector3)(ref val)).sqrMagnitude;
			val = a - c;
			float sqrMagnitude3 = ((Vector3)(ref val)).sqrMagnitude;
			if (Mathf.Max(sqrMagnitude, Mathf.Max(sqrMagnitude2, sqrMagnitude3)) > map.step * map.step && depth < 16)
			{
				if (sqrMagnitude >= sqrMagnitude2 && sqrMagnitude >= sqrMagnitude3)
				{
					Vector3 val2 = (a + b) * 0.5f;
					Split(map, a, val2, c, verts, tris, depth + 1);
					Split(map, val2, b, c, verts, tris, depth + 1);
				}
				else if (sqrMagnitude2 >= sqrMagnitude3)
				{
					Vector3 val3 = (b + c) * 0.5f;
					Split(map, a, b, val3, verts, tris, depth + 1);
					Split(map, a, val3, c, verts, tris, depth + 1);
				}
				else
				{
					Vector3 val4 = (c + a) * 0.5f;
					Split(map, a, b, val4, verts, tris, depth + 1);
					Split(map, val4, b, c, verts, tris, depth + 1);
				}
			}
			else if (map.IsLava((a + b + c) / 3f))
			{
				int count = verts.Count;
				verts.Add(a);
				verts.Add(b);
				verts.Add(c);
				tris.Add(count);
				tris.Add(count + 1);
				tris.Add(count + 2);
			}
		}

		private void FromCells(LavaMap map, Transform parent, List<(Vector3 p, Vector3 n)> centres)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			float num = map.step * 0.5f;
			List<Vector3> list = new List<Vector3>();
			List<int> list2 = new List<int>();
			foreach (var centre in centres)
			{
				Vector3 p = centre.p;
				Vector3 n = centre.n;
				int count = list.Count;
				float ny = Mathf.Max(0.3f, n.y);
				list.Add(Corner(0f - num, 0f - num));
				list.Add(Corner(0f - num, num));
				list.Add(Corner(num, num));
				list.Add(Corner(num, 0f - num));
				list2.Add(count);
				list2.Add(count + 1);
				list2.Add(count + 2);
				list2.Add(count);
				list2.Add(count + 2);
				list2.Add(count + 3);
				Vector3 Corner(float dx, float dz)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_002b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Unknown result type (might be due to invalid IL or missing references)
					return p + new Vector3(dx, (0f - (n.x * dx + n.z * dz)) / ny, dz);
				}
			}
			MakeSkin(parent, ((Component)parent).gameObject.layer, list, list2);
			Quads += centres.Count;
		}

		private void MakeSkin(Transform parent, int layer, List<Vector3> verts, List<int> tris)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_0120: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(0.1f, FloorIsLavaPlugin.TileMeters.Value);
			Vector3[] array = (Vector3[])(object)new Vector3[verts.Count];
			Vector2[] array2 = (Vector2[])(object)new Vector2[verts.Count];
			Color32[] array3 = (Color32[])(object)new Color32[verts.Count];
			for (int i = 0; i < verts.Count; i++)
			{
				array[i] = parent.InverseTransformPoint(verts[i] + Vector3.up * 0.02f);
				array2[i] = new Vector2(verts[i].x / num, verts[i].z / num);
				array3[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			}
			Mesh val = new Mesh
			{
				name = "FloorIsLava_Skin"
			};
			if (array.Length > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.vertices = array;
			val.uv = array2;
			val.colors32 = array3;
			val.SetTriangles(tris, 0);
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject val2 = new GameObject("FloorIsLava_Skin")
			{
				layer = layer
			};
			val2.transform.SetParent(parent, false);
			val2.AddComponent<MeshFilter>().sharedMesh = val;
			MeshRenderer obj = val2.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = LavaTexture.Material;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			((Renderer)obj).lightProbeUsage = (LightProbeUsage)0;
			((Renderer)obj).reflectionProbeUsage = (ReflectionProbeUsage)0;
			Skins++;
		}
	}
	internal static class LavaTexture
	{
		private const int N = 256;

		private const int Frames = 16;

		private const int Cells = 5;

		private const float FrameSeconds = 0.2f;

		private static Texture2D[] frames;

		private static Material material;

		private static int shown = -1;

		private static readonly List<Material> also = new List<Material>();

		private static float[][] grids = new float[128][];

		private static readonly float[] StopT = new float[5] { 0f, 0.25f, 0.5f, 0.75f, 1f };

		private static readonly Color[] StopC = (Color[])(object)new Color[5]
		{
			new Color(0.05f, 0.01f, 0f),
			new Color(0.55f, 0.05f, 0f),
			new Color(1f, 0.32f, 0.02f),
			new Color(1f, 0.68f, 0.1f),
			new Color(1f, 0.95f, 0.65f)
		};

		public static Material Material
		{
			get
			{
				if ((Object)(object)material == (Object)null)
				{
					Make();
				}
				return material;
			}
		}

		public static void Tick()
		{
			if ((Object)(object)material == (Object)null || frames == null)
			{
				return;
			}
			int num = (int)(Time.time / 0.2f) % 16;
			if (num == shown)
			{
				return;
			}
			shown = num;
			material.mainTexture = (Texture)(object)frames[num];
			also.RemoveAll((Material m) => (Object)(object)m == (Object)null);
			foreach (Material item in also)
			{
				item.mainTexture = (Texture)(object)frames[num];
			}
		}

		public static void Paint(Material m)
		{
			if (!((Object)(object)m == (Object)null))
			{
				if ((Object)(object)material == (Object)null)
				{
					Make();
				}
				m.mainTexture = (Texture)(object)frames[(int)(Time.time / 0.2f) % 16];
				if (!also.Contains(m))
				{
					also.Add(m);
				}
			}
		}

		private static void Make()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			Stopwatch stopwatch = Stopwatch.StartNew();
			frames = Build();
			Shader val = Shader.Find("Unlit/Texture");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Sprites/Default");
			}
			material = new Material(val)
			{
				name = "FloorIsLava",
				mainTexture = (Texture)(object)frames[0]
			};
			if (((Object)val).name == "Sprites/Default")
			{
				material.renderQueue = 2450;
			}
			FloorIsLavaPlugin.Log.LogInfo((object)$"Lava texture made in {stopwatch.ElapsedMilliseconds} ms, shader {((Object)val).name}");
		}

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

		private static float Frac(float x)
		{
			return x - Mathf.Floor(x);
		}

		private static float Value(float u, float v, int p, int seed)
		{
			float[] array = grids[seed];
			if (array == null)
			{
				Random random = new Random(seed * 7919 + p);
				array = (grids[seed] = new float[p * p]);
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = (float)random.NextDouble();
				}
			}
			float num = Frac(u) * (float)p;
			float num2 = Frac(v) * (float)p;
			int num3 = (int)num;
			int num4 = (int)num2;
			float num5 = Smooth(num - (float)num3);
			float num6 = Smooth(num2 - (float)num4);
			num3 %= p;
			num4 %= p;
			int num7 = (num3 + 1) % p;
			int num8 = (num4 + 1) % p;
			float num9 = array[num4 * p + num3];
			float num10 = array[num4 * p + num7];
			float num11 = array[num8 * p + num3];
			float num12 = array[num8 * p + num7];
			return Mathf.Lerp(Mathf.Lerp(num9, num10, num5), Mathf.Lerp(num11, num12, num5), num6);
		}

		private static float Fbm(float u, float v, int basePeriod, int octaves, int seed)
		{
			float num = 0f;
			float num2 = 0.5f;
			float num3 = 0f;
			for (int i = 0; i < octaves; i++)
			{
				num += num2 * Value(u, v, basePeriod << i, seed + i);
				num3 += num2;
				num2 *= 0.5f;
			}
			return num / num3;
		}

		private static Color Ramp(float t)
		{
			//IL_0065: 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_0021: 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)
			for (int i = 1; i < StopT.Length; i++)
			{
				if (t <= StopT[i])
				{
					return Color.Lerp(StopC[i - 1], StopC[i], (t - StopT[i - 1]) / (StopT[i] - StopT[i - 1]));
				}
			}
			return StopC[StopC.Length - 1];
		}

		private static Texture2D[] Build()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: 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_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: 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_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			Random random = new Random(7);
			Vector2[] array = (Vector2[])(object)new Vector2[25];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = new Vector2((float)random.NextDouble(), (float)random.NextDouble());
			}
			float[] array2 = new float[65536];
			float[] array3 = new float[65536];
			float[] array4 = new float[65536];
			float[] array5 = new float[65536];
			float[] array6 = new float[65536];
			float[] array7 = new float[65536];
			for (int j = 0; j < 256; j++)
			{
				for (int k = 0; k < 256; k++)
				{
					int num = j * 256 + k;
					float num2 = ((float)k + 0.5f) / 256f;
					float num3 = ((float)j + 0.5f) / 256f;
					float num4 = Frac(num2 + 0.06f * (Fbm(num2, num3, 4, 3, 11) - 0.5f));
					float num5 = Frac(num3 + 0.06f * (Fbm(num2, num3, 4, 3, 23) - 0.5f));
					float num6 = 9f;
					float num7 = 9f;
					for (int l = -1; l <= 5; l++)
					{
						for (int m = -1; m <= 5; m++)
						{
							Vector2 val = array[(l + 5) % 5 * 5 + (m + 5) % 5];
							float num8 = num4 - ((float)m + val.x) / 5f;
							float num9 = num5 - ((float)l + val.y) / 5f;
							float num10 = Mathf.Sqrt(num8 * num8 + num9 * num9) * 5f;
							if (num10 < num6)
							{
								num7 = num6;
								num6 = num10;
							}
							else if (num10 < num7)
							{
								num7 = num10;
							}
						}
					}
					float num11 = num7 - num6;
					float num12 = 0.06f + 0.22f * Mathf.Pow(Fbm(num2, num3, 8, 2, 31), 1.5f);
					float num13 = Mathf.Clamp01(0.35f + 1.1f * Fbm(num2, num3, 4, 3, 91));
					array2[num] = Mathf.Pow(Mathf.Clamp01(1f - num11 / num12), 1.3f) * num13;
					array3[num] = Mathf.Pow(Mathf.Clamp01(1f - num11 / 0.55f), 2.5f) * num13;
					array4[num] = Mathf.Clamp01((Fbm(num2, num3, 4, 3, 61) - 0.55f) * 4f);
					array5[num] = Fbm(num2, num3, 4, 3, 71) - 0.5f;
					array6[num] = Fbm(num2, num3, 4, 3, 83) - 0.5f;
					array7[num] = 0.04f + 0.1f * Mathf.Pow(Fbm(num2, num3, 16, 4, 41), 1.5f) + 0.05f * Fbm(num2, num3, 4, 2, 51);
				}
			}
			Texture2D[] array8 = (Texture2D[])(object)new Texture2D[16];
			Color32[] array9 = (Color32[])(object)new Color32[65536];
			for (int n = 0; n < 16; n++)
			{
				float num14 = MathF.PI * 2f * (float)n / 16f;
				float num15 = Mathf.Cos(num14) * 1.6f;
				float num16 = Mathf.Sin(num14) * 1.6f;
				for (int num17 = 0; num17 < array9.Length; num17++)
				{
					float num18 = Mathf.Clamp01(0.5f + array5[num17] * num15 + array6[num17] * num16);
					float num19 = Mathf.Clamp01(array2[num17] * (0.7f + 0.4f * num18) + array3[num17] * 0.45f * (0.5f + 0.7f * num18) + array4[num17] * 0.22f * num18);
					Color val2 = Ramp(num19);
					float num20 = Mathf.Clamp01(num19 * 1.4f);
					Color val3 = new Color(array7[num17], array7[num17] * 0.82f, array7[num17] * 0.72f) * (1f - num20) + val2 * num20 + val2 * 0.15f;
					val3.a = 1f;
					array9[num17] = Color32.op_Implicit(val3);
				}
				Texture2D val4 = new Texture2D(256, 256, (TextureFormat)4, true)
				{
					name = "FloorIsLava_" + n,
					wrapMode = (TextureWrapMode)0,
					filterMode = (FilterMode)1,
					anisoLevel = 4
				};
				val4.SetPixels32(array9);
				val4.Apply(true, true);
				array8[n] = val4;
			}
			return array8;
		}
	}
	internal static class MassLava
	{
		private const string Name = "FloorIsLava_Mass";

		private const int Rings = 48;

		private const int Segments = 96;

		private const float Glow = 1.15f;

		private static float Tile => Mathf.Max(0.5f, FloorIsLavaPlugin.MassTileMeters.Value);

		public static void Start(DEN_DeathFloor mass)
		{
			//IL_002a: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Expected O, but got Unknown
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: 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_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer deathFloorRenderer = mass.deathFloorRenderer;
			if ((Object)(object)deathFloorRenderer == (Object)null || (Object)(object)((Component)mass).transform.Find("FloorIsLava_Mass") != (Object)null)
			{
				return;
			}
			Bounds bounds = ((Renderer)deathFloorRenderer).bounds;
			Vector3 position = ((Component)mass).transform.position;
			float num = Mathf.Max(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.z);
			float num2 = ((Bounds)(ref bounds)).max.y - position.y;
			float num3 = ((Bounds)(ref bounds)).min.y - position.y;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(((Bounds)(ref bounds)).center.x - position.x, 0f, ((Bounds)(ref bounds)).center.z - position.z);
			Vector3[] array = (Vector3[])(object)new Vector3[4609];
			Color32[] array2 = (Color32[])(object)new Color32[array.Length];
			int[] array3 = new int[27360];
			array[0] = val + Vector3.up * num2;
			for (int i = 1; i <= 48; i++)
			{
				float num4 = (float)i / 48f;
				float num5 = num * num4;
				float num6 = Mathf.Lerp(num2, num3, num4 * num4);
				for (int j = 0; j < 96; j++)
				{
					float num7 = MathF.PI * 2f * (float)j / 96f;
					array[1 + (i - 1) * 96 + j] = val + new Vector3(Mathf.Cos(num7) * num5, num6, Mathf.Sin(num7) * num5);
				}
			}
			int num8 = 0;
			for (int k = 0; k < 96; k++)
			{
				array3[num8++] = 0;
				array3[num8++] = 1 + (k + 1) % 96;
				array3[num8++] = 1 + k;
			}
			for (int l = 1; l < 48; l++)
			{
				for (int m = 0; m < 96; m++)
				{
					int num9 = 1 + (l - 1) * 96 + m;
					int num10 = 1 + (l - 1) * 96 + (m + 1) % 96;
					int num11 = num9 + 96;
					int num12 = num10 + 96;
					array3[num8++] = num9;
					array3[num8++] = num10;
					array3[num8++] = num11;
					array3[num8++] = num10;
					array3[num8++] = num12;
					array3[num8++] = num11;
				}
			}
			float tile = Tile;
			Vector2[] array4 = (Vector2[])(object)new Vector2[array.Length];
			for (int n = 0; n < array.Length; n++)
			{
				array4[n] = new Vector2(array[n].x / tile, array[n].z / tile);
				array2[n] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			}
			Mesh val2 = new Mesh
			{
				name = "FloorIsLava_Mass",
				vertices = array,
				uv = array4,
				colors32 = array2,
				triangles = array3
			};
			val2.RecalculateNormals();
			val2.bounds = new Bounds(val + Vector3.up * (num2 + num3) * 0.5f, new Vector3(num * 2f, num2 - num3 + 2f, num * 2f));
			GameObject val3 = new GameObject("FloorIsLava_Mass")
			{
				layer = ((Component)deathFloorRenderer).gameObject.layer
			};
			val3.transform.SetParent(((Component)mass).transform, false);
			val3.transform.rotation = Quaternion.identity;
			val3.transform.localScale = new Vector3(1f / ((Component)mass).transform.lossyScale.x, 1f / ((Component)mass).transform.lossyScale.y, 1f / ((Component)mass).transform.lossyScale.z);
			val3.AddComponent<MeshFilter>().sharedMesh = val2;
			MeshRenderer obj = val3.AddComponent<MeshRenderer>();
			Material val4 = (Material)(((object)Opaque()) ?? ((object)new Material(LavaTexture.Material)));
			((Object)val4).name = "FloorIsLava_Mass";
			((Renderer)obj).sharedMaterial = val4;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			LavaTexture.Paint(val4);
			((Renderer)deathFloorRenderer).forceRenderingOff = true;
			ParticleSystemRenderer[] componentsInChildren = ((Component)mass).GetComponentsInChildren<ParticleSystemRenderer>(true);
			foreach (ParticleSystemRenderer val5 in componentsInChildren)
			{
				if ((Object)(object)((Renderer)val5).sharedMaterial != (Object)null && ((Object)((Renderer)val5).sharedMaterial.shader).name.Contains("Mass Only Corruption"))
				{
					((Renderer)val5).forceRenderingOff = true;
				}
			}
			ManualLogSource log = FloorIsLavaPlugin.Log;
			object[] obj2 = new object[4]
			{
				num * 2f,
				num2 - num3,
				((Object)val4.shader).name,
				null
			};
			Material sharedMaterial = ((Renderer)deathFloorRenderer).sharedMaterial;
			obj2[3] = ((sharedMaterial != null) ? ((Object)sharedMaterial.shader).name : null);
			log.LogInfo((object)string.Format("Mass is lava: {0:F0} m dome, {1:F0} m high, shader {2} (the game's {3} hidden)", obj2));
		}

		private static Material Opaque()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Particles/Standard Unlit");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val);
			val2.SetFloat("_Mode", 0f);
			val2.SetFloat("_SrcBlend", 1f);
			val2.SetFloat("_DstBlend", 0f);
			val2.SetFloat("_ZWrite", 1f);
			val2.SetFloat("_Cull", 0f);
			string[] array = new string[4] { "_ALPHABLEND_ON", "_ALPHAPREMULTIPLY_ON", "_ALPHATEST_ON", "_ALPHAMODULATE_ON" };
			foreach (string text in array)
			{
				val2.DisableKeyword(text);
			}
			val2.SetColor("_Color", Color.white * 1.15f);
			val2.renderQueue = 2000;
			return val2;
		}

		public static void Update(DEN_DeathFloor mass)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)mass).transform.Find("FloorIsLava_Mass");
			if (!((Object)(object)val == (Object)null))
			{
				MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
				Vector3 position = val.position;
				((Renderer)component).sharedMaterial.mainTextureOffset = new Vector2(position.x / Tile, position.z / Tile);
				if (val.rotation != Quaternion.identity)
				{
					val.rotation = Quaternion.identity;
				}
				if ((Object)(object)mass.deathFloorRenderer != (Object)null && !((Renderer)mass.deathFloorRenderer).forceRenderingOff)
				{
					((Renderer)mass.deathFloorRenderer).forceRenderingOff = true;
				}
			}
		}
	}
}