Decompiled source of Gauntlet Knuckle v0.1.1

LakisArena.dll

Decompiled 6 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.Text;
using BepInEx;
using BepInEx.Logging;
using DarkMachine.AI;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using WKMapLoader;

[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("LakisArena")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("LakisArena")]
[assembly: AssemblyTitle("LakisArena")]
[assembly: AssemblyVersion("0.1.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 LakisArena
{
	internal static class Aggro
	{
		private const float Every = 0.25f;

		private const float Memory = 4f;

		private static float next;

		private static readonly Dictionary<Type, FieldInfo> targetFields = new Dictionary<Type, FieldInfo>();

		private static readonly FieldRef<DEN_Bloodbug, Target> BugTarget = AccessTools.FieldRefAccess<DEN_Bloodbug, Target>("bloodbugTarget");

		private static readonly Perf.Section PerfTick = Perf.Make("*aggro");

		public static void Register()
		{
			MapApi.Tick += Tick;
		}

		private static void Tick()
		{
			if (Time.time < next)
			{
				return;
			}
			next = Time.time + 0.25f;
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject == (Object)null || ((GameEntity)playerObject).dead || CL_GameManager.noTarget || GameEntity.entities == null)
			{
				return;
			}
			using (PerfTick.Time())
			{
				GameEntity[] array = GameEntity.entities.ToArray();
				foreach (GameEntity val in array)
				{
					if ((Object)(object)val == (Object)null || val.dead)
					{
						continue;
					}
					Denizen val2 = (Denizen)(object)((val is Denizen) ? val : null);
					if (val2 != null && ((Component)val2).gameObject.activeInHierarchy)
					{
						try
						{
							Look(val2, playerObject);
						}
						catch (Exception ex)
						{
							ArenaPlugin.Log.LogWarning((object)("Aggro: " + ((Object)val2).name + ": " + ex.Message));
						}
					}
				}
			}
		}

		private static void Look(Denizen d, ENT_Player p)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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)
			//IL_0168: 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)
			Transform transform = ((Component)p).transform;
			ObjectTagger tagger = ((GameEntity)p).GetTagger();
			DEN_Bloodbug val = (DEN_Bloodbug)(object)((d is DEN_Bloodbug) ? d : null);
			if (val == null)
			{
				DEN_Drone val2 = (DEN_Drone)(object)((d is DEN_Drone) ? d : null);
				if (val2 != null)
				{
					Target target = val2.GetTarget();
					if (!val2.alwaysTargetPlayer && val2.lookForTarget && target != null && !((Object)(object)target.transform == (Object)(object)transform) && Hunts(tagger, val2.targetTags, null) && ((AIGameEntity)val2).sight != null && ((AIGameEntity)val2).sight.CanSeeTarget(((Component)val2).transform.position, transform, ((AIGameEntity)val2).sight.sightDistance, (Transform)null, false, true))
					{
						target.transform = transform;
						target.tagger = tagger;
						target.entity = (GameEntity)(object)p;
						target.isVisible = true;
						target.lastSighted = transform.position;
						target.lastSightedTimer = val2.loseTargetTimer;
						val2.aiState = (AIStates)2;
					}
				}
				else
				{
					AITargetComponent val3 = TargetOf(d);
					if (val3 != null && !((AIGameEntity)d).disableAI && ((AIGameEntity)d).sight != null && !((Object)(object)val3.target.targetTransform == (Object)(object)transform) && Hunts(tagger, val3.targetScanTags, val3.targetIgnoreTags) && !Pacified(d, p) && ((AIGameEntity)d).sight.CanSeeTarget(((Component)d).transform.position, transform, ((AIGameEntity)d).sight.sightDistance, (Transform)null, false, true))
					{
						val3.SetTarget(transform);
						((AIGameEntity)d).sight.SetTargetAsVisible(transform, 4f);
						((AIGameEntity)d).target = transform;
					}
				}
			}
			else
			{
				Target val4 = BugTarget.Invoke(val);
				if (!val.alwaysTargetPlayer && val4 != null && !((Object)(object)val4.transform == (Object)(object)transform) && Hunts(tagger, val.targetTags, null) && ((Denizen)val).CanSeeTarget(transform, val.sightDistance))
				{
					val4.transform = transform;
					val4.tagger = tagger;
					val4.entity = (GameEntity)(object)p;
					val4.isVisible = true;
					val4.lastSighted = transform.position;
					val4.lastSightedTimer = val.loseTargetTimer;
					val.aiState = (AIStates)3;
				}
			}
		}

		private static bool Hunts(ObjectTagger you, string[] scan, string[] ignore)
		{
			if ((Object)(object)you != (Object)null && scan != null && you.HasTagInList(scan))
			{
				if (ignore != null)
				{
					return !you.HasTagInList(ignore);
				}
				return true;
			}
			return false;
		}

		private static bool Pacified(Denizen d, ENT_Player p)
		{
			if (d is DEN_Hopper)
			{
				if (!p.HasPerk("Perk_PheromoneGlands"))
				{
					return CL_GameManager.HasActiveFlag("pacifyroaches", false);
				}
				return true;
			}
			return false;
		}

		private static AITargetComponent TargetOf(Denizen d)
		{
			Type type = ((object)d).GetType();
			if (!targetFields.TryGetValue(type, out var value))
			{
				value = AccessTools.Field(type, "targetComponent");
				if (value != null && value.FieldType != typeof(AITargetComponent))
				{
					value = null;
				}
				targetFields[type] = value;
			}
			object? obj = value?.GetValue(d);
			return (AITargetComponent)((obj is AITargetComponent) ? obj : null);
		}
	}
	internal static class ArenaConsole
	{
		private class Entry
		{
			public Action<string[]> run;

			public string desc;

			public Func<int, IReadOnlyList<string>> args;
		}

		private static readonly Dictionary<string, Entry> commands = new Dictionary<string, Entry>();

		private static readonly HashSet<string> done = new HashSet<string>();

		private static CommandConsole console;

		public static void Add(string name, Action<string[]> run, string desc = null, Func<int, IReadOnlyList<string>> args = null)
		{
			commands[name] = new Entry
			{
				run = delegate(string[] a)
				{
					ArenaPlugin.Log.LogInfo((object)("> " + name + " " + string.Join(" ", a)));
					try
					{
						run(a);
					}
					catch (Exception ex)
					{
						ArenaPlugin.Log.LogError((object)$"{name}: {ex}");
						CommandConsole.Log(name + " failed: " + ex.Message);
					}
				},
				desc = desc,
				args = args
			};
		}

		public static void Tick()
		{
			if ((Object)(object)CommandConsole.instance == (Object)null)
			{
				return;
			}
			if ((Object)(object)CommandConsole.instance != (Object)(object)console)
			{
				console = CommandConsole.instance;
				done.Clear();
			}
			foreach (KeyValuePair<string, Entry> command in commands)
			{
				if (!done.Add(command.Key))
				{
					continue;
				}
				Entry e = command.Value;
				CommandBuilder val = CommandConsole.BuildCommand(command.Key, e.run).NotCheat();
				if (e.desc != null)
				{
					val.Description(e.desc);
				}
				if (e.args != null)
				{
					val.AutocompleteCustom((Action<CommandAutocomplete>)delegate(CommandAutocomplete ac)
					{
						IReadOnlyList<string> readOnlyList = e.args(ac.activeArg);
						if (readOnlyList != null)
						{
							ac.FromArray(readOnlyList);
						}
					});
				}
				ArenaPlugin.Log.LogInfo((object)("console: added '" + command.Key + "'"));
			}
		}
	}
	[BepInPlugin("lazar.lakisarena", "Arena", "0.1.0")]
	[BepInDependency("lazar.wkmaploader", "1.1.0")]
	public class ArenaPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private static readonly Perf.Section PerfUpdate = Perf.Make("*plugin (console, spawner, presets, edits, corpses)");

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Part("save", Save.Register);
			Part("campaign", Campaign.Restore);
			Part("kits", Kits.Register);
			Part("game pc", GamePC.Register);
			Part("lobby", Lobby.Register);
			Part("run levels", RunLevels.Register);
			Part("lifespans", Lifespans.Register);
			Part("gallery", Gallery.Register);
			Part("campaign info", CampaignInfo.Register);
			Part("perk trace", PerkTrace.Register);
			Part("spawner", Spawner.Register);
			Part("knuckles", Knuckles.Register);
			Part("sized mobs", SizedMobs.Register);
			Part("bloodbug mother", BloodbugMother.Register);
			Part("swing log", SwingLog.Register);
			Part("hp bars", HpBars.Register);
			Part("boss room", BossRoom.Register);
			Part("level presets", delegate
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Expected O, but got Unknown
				LevelPresets.Register(new Harmony("lazar.lakisarena.presets"));
			});
			Part("level edits", LevelEdits.Register);
			Part("perf", Perf.Register);
			Part("aggro", Aggro.Register);
			Part("combo", Combo.Register);
			Part("coin purse", CoinPurse.Register);
			MapApi.MapReset += ScoreTitle.Reset;
			MapApi.Tick += ScoreTitle.Tick;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Arena ready.");
		}

		private void Update()
		{
			using (PerfUpdate.Time())
			{
				ArenaConsole.Tick();
				Save.Tick();
				Spawner.Tick();
				LevelPresets.Tick();
				LevelEdits.Tick();
				Corpses.Tick();
			}
		}

		private void OnApplicationQuit()
		{
			Save.Flush();
		}

		private static void Part(string name, Action register)
		{
			try
			{
				register();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Arena: '{name}' failed to start: {arg}");
			}
		}
	}
	internal static class BigText
	{
		private const int Size = 90;

		public static void Show(string text, int size = 90, string color = null)
		{
			string arg = ((color != null) ? ("<color=#" + color + ">" + text + "</color>") : text);
			try
			{
				CL_UIManager instance = CL_UIManager.instance;
				if (instance != null)
				{
					UT_TextScrawl highscoreHeader = instance.highscoreHeader;
					if (highscoreHeader != null)
					{
						highscoreHeader.ShowText($"<size={size}><b>{arg}</b></size>");
					}
				}
			}
			catch (Exception ex)
			{
				ArenaPlugin.Log.LogWarning((object)("Big text failed: " + ex.Message));
			}
		}

		public static bool IsBossRoom(string preset)
		{
			return preset?.EndsWith("_boss") ?? false;
		}
	}
	internal static class ScoreTitle
	{
		private const float Delay = 2.5f;

		private static string text;

		private static float at;

		public static void After(string score)
		{
			text = ((text == null) ? score : (text + "   " + score));
			at = Time.time + 2.5f;
		}

		public static void Tick()
		{
			if (text != null && !(Time.time < at))
			{
				MapApi.ShowTitle(text);
				text = null;
			}
		}

		public static void Reset()
		{
			text = null;
		}
	}
	internal static class GameProps
	{
		private static readonly string[] SourceLevels = new string[2] { "Training_Level_01", "M3_Habitation_Pier_03" };

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

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

		private static bool sourcesTried;

		private static readonly Dictionary<string, MeshFilter> cache = new Dictionary<string, MeshFilter>();

		public static bool TryGet(string meshName, out Mesh mesh, out Material[] mats, out CL_Button button)
		{
			mesh = null;
			mats = null;
			button = null;
			if (!cache.TryGetValue(meshName, out var value) || (Object)(object)value == (Object)null)
			{
				LoadSources();
				value = sources.SelectMany((GameObject s) => s.GetComponentsInChildren<MeshFilter>(true)).FirstOrDefault((Func<MeshFilter, bool>)((MeshFilter m) => (Object)(object)m.sharedMesh != (Object)null && ((Object)m.sharedMesh).name == meshName)) ?? ((IEnumerable<MeshFilter>)Resources.FindObjectsOfTypeAll<MeshFilter>()).FirstOrDefault((Func<MeshFilter, bool>)((MeshFilter m) => (Object)(object)m.sharedMesh != (Object)null && ((Object)m.sharedMesh).name == meshName));
				if ((Object)(object)value == (Object)null)
				{
					return false;
				}
				cache[meshName] = value;
			}
			mesh = value.sharedMesh;
			MeshRenderer component = ((Component)value).GetComponent<MeshRenderer>();
			mats = (Material[])(((object)((component != null) ? ((Renderer)component).sharedMaterials : null)) ?? ((object)new Material[0]));
			button = ((Component)value).GetComponent<CL_Button>();
			return true;
		}

		public static MeshFilter FindTree(string meshName)
		{
			LoadSources();
			return (from m in sources.SelectMany((GameObject s) => s.GetComponentsInChildren<MeshFilter>(true))
				where (Object)(object)m.sharedMesh != (Object)null && ((Object)m.sharedMesh).name == meshName
				orderby ((Component)m).GetComponentsInChildren<CL_Button>(true).Length != 0 descending
				select m).FirstOrDefault();
		}

		private static void LoadSources()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if (sourcesTried)
			{
				return;
			}
			sourcesTried = true;
			string[] sourceLevels = SourceLevels;
			foreach (string text in sourceLevels)
			{
				try
				{
					LevelAssetHolder levelAsset = CL_AssetManager.GetLevelAsset(text, "");
					if (levelAsset?.levelAssetReference == null)
					{
						ArenaPlugin.Log.LogWarning((object)("Prop source level '" + text + "' not in the game's database."));
						continue;
					}
					AsyncOperationHandle<GameObject> item = Addressables.LoadAssetAsync<GameObject>(((AssetReference)levelAsset.levelAssetReference).RuntimeKey);
					GameObject val = item.WaitForCompletion();
					if ((int)item.Status == 1 && (Object)(object)val != (Object)null)
					{
						handles.Add(item);
						sources.Add(val);
					}
					else
					{
						ArenaPlugin.Log.LogWarning((object)("Prop source level '" + text + "' failed to load: " + item.OperationException?.Message));
					}
				}
				catch (Exception ex)
				{
					ArenaPlugin.Log.LogWarning((object)("Prop source level '" + text + "': " + ex.Message));
				}
			}
		}
	}
	internal static class Kits
	{
		public static void Register()
		{
			MapApi.RegisterTag("arenastand", (Action<MapPartInfo>)Build);
		}

		private static void Build(MapPartInfo part)
		{
			//IL_003e: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = part.GameObject;
			if (!((Object)(object)gameObject.GetComponent<MeshFilter>() != (Object)null))
			{
				int layer = gameObject.layer;
				if ((Object)(object)gameObject.GetComponent<CL_Button>() == (Object)null)
				{
					gameObject.layer = part.SolidLayer;
				}
				gameObject.transform.localScale = part.Scale;
				if (!Tree("L_ButtonStand_01", gameObject, gameObject.transform.localRotation * Quaternion.Euler(0f, 90f, 0f), part.SolidLayer, layer))
				{
					ArenaPlugin.Log.LogWarning((object)("'arenastand' on '" + part.Name + "': game mesh not found."));
				}
			}
		}

		public static GameObject Stand(Transform parent, Vector3 pos, Quaternion facing, float scale, int solidLayer, int pressLayer, Action onPress)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00dd: Expected O, but got Unknown
			GameObject val = new GameObject("code_stand");
			val.transform.SetParent(parent, true);
			val.transform.position = pos;
			val.transform.localScale = Vector3.one * scale;
			val.transform.rotation = facing;
			if (!Tree("L_ButtonStand_01", val, val.transform.localRotation * Quaternion.Euler(0f, 90f, 0f), solidLayer, pressLayer))
			{
				Object.Destroy((Object)(object)val);
				return null;
			}
			CL_Button[] componentsInChildren = val.GetComponentsInChildren<CL_Button>(true);
			UnityAction val3 = default(UnityAction);
			foreach (CL_Button val2 in componentsInChildren)
			{
				if (val2.activeEvent == null)
				{
					val2.activeEvent = new UnityEvent();
				}
				UnityEvent activeEvent = val2.activeEvent;
				UnityAction obj = val3;
				if (obj == null)
				{
					UnityAction val4 = delegate
					{
						onPress();
					};
					UnityAction val5 = val4;
					val3 = val4;
					obj = val5;
				}
				activeEvent.AddListener(obj);
			}
			return val;
		}

		private static bool Tree(string meshName, GameObject go, Quaternion rot, int solidLayer, int pressLayer)
		{
			//IL_0050: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			MeshFilter val = GameProps.FindTree(meshName);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			go.AddComponent<MeshFilter>().sharedMesh = val.sharedMesh;
			MeshRenderer obj = go.AddComponent<MeshRenderer>();
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterials = (Material[])(((object)((component != null) ? ((Renderer)component).sharedMaterials : null)) ?? ((object)new Material[0]));
			go.transform.localRotation = rot * (Quaternion.Inverse(((Component)val).transform.root.rotation) * ((Component)val).transform.rotation);
			go.AddComponent<BoxCollider>();
			go.layer = solidLayer;
			CopyChildren(((Component)val).transform, go.transform, solidLayer, pressLayer);
			return true;
		}

		private static void CopyChildren(Transform src, Transform dst, int solidLayer, int pressLayer)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_0063: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform item in src)
			{
				Transform val = item;
				MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
				{
					GameObject val2 = new GameObject(((Object)val).name);
					val2.layer = solidLayer;
					val2.transform.SetParent(dst, false);
					val2.transform.localPosition = val.localPosition;
					val2.transform.localRotation = val.localRotation;
					val2.transform.localScale = val.localScale;
					val2.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh;
					MeshRenderer obj = val2.AddComponent<MeshRenderer>();
					MeshRenderer component2 = ((Component)val).GetComponent<MeshRenderer>();
					((Renderer)obj).sharedMaterials = (Material[])(((object)((component2 != null) ? ((Renderer)component2).sharedMaterials : null)) ?? ((object)new Material[0]));
					val2.AddComponent<BoxCollider>();
					CL_Button component3 = ((Component)val).GetComponent<CL_Button>();
					if ((Object)(object)component3 != (Object)null)
					{
						val2.layer = pressLayer;
						val2.AddComponent<ObjectTagger>().AddTag("Button");
						CL_Button obj2 = val2.AddComponent<CL_Button>();
						obj2.pressCooldown = 0.25f;
						CopyLook(obj2, component3);
					}
					CopyChildren(val, val2.transform, solidLayer, pressLayer);
				}
			}
		}

		private static void CopyLook(CL_Button btn, CL_Button source)
		{
			if (!((Object)(object)source == (Object)null))
			{
				btn.pressSound = source.pressSound;
				btn.activeMaterial = source.activeMaterial;
				btn.inactiveMaterial = source.inactiveMaterial;
				btn.materialIndex = source.materialIndex;
				btn.inactiveMaterialOnCooldown = source.inactiveMaterialOnCooldown;
			}
		}
	}
	internal class BarrelSpawns : MonoBehaviour
	{
		public const string Barrel = "Prop_Barrel_Explosive";

		private const float Delay = 30f;

		private const float Clear = 0.45f;

		private static readonly Dictionary<string, float> Rooms = new Dictionary<string, float> { ["arena_silos_boss"] = 30f };

		private string preset;

		private GameObject barrel;

		private float goneAt = -1f;

		private GallerySign sign;

		public static void Mark(string preset, Transform level, Vector3 localPos, Quaternion localRot, GameObject barrel)
		{
			//IL_000f: 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_0024: Expected O, but got Unknown
			//IL_0037: 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_006a: 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_007a: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			if (Rooms.TryGetValue(preset, out var value) && !(localPos.y >= value))
			{
				GameObject val = new GameObject("arena_barrel_spawn");
				val.transform.SetParent(level, false);
				val.transform.localPosition = localPos;
				val.transform.localRotation = localRot;
				BarrelSpawns barrelSpawns = val.AddComponent<BarrelSpawns>();
				barrelSpawns.preset = preset;
				barrelSpawns.barrel = barrel;
				barrelSpawns.sign = GallerySign.Make("", val.transform.position + level.up * 1.8f, 0.3f, Color.white, null);
				((Component)barrelSpawns.sign).transform.SetParent(val.transform, true);
				((Component)barrelSpawns.sign).gameObject.SetActive(false);
			}
		}

		public static void ClearIn(Transform level)
		{
			BarrelSpawns[] componentsInChildren = ((Component)level).GetComponentsInChildren<BarrelSpawns>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)componentsInChildren[i]).gameObject);
			}
		}

		private static bool Gone(GameObject b)
		{
			if ((Object)(object)b == (Object)null || !b.activeSelf)
			{
				return true;
			}
			GameEntity component = b.GetComponent<GameEntity>();
			if ((Object)(object)component != (Object)null)
			{
				return component.dead;
			}
			return false;
		}

		private void Update()
		{
			if (!Gone(barrel))
			{
				goneAt = -1f;
				Label(null);
				return;
			}
			if (goneAt < 0f)
			{
				goneAt = Time.time;
			}
			float num = goneAt + 30f - Time.time;
			if (num > 0f)
			{
				Label($"respawn {num:0.0}s");
				return;
			}
			if (!Free())
			{
				Label("respawn: spot blocked");
				return;
			}
			Spawn();
			Label(null);
		}

		private void Spawn()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Spawner.Prefab("Prop_Barrel_Explosive");
			if ((Object)(object)val == (Object)null)
			{
				ArenaPlugin.Log.LogWarning((object)"Barrel spawn: no 'Prop_Barrel_Explosive' in the game.");
				((Behaviour)this).enabled = false;
			}
			else
			{
				barrel = Object.Instantiate<GameObject>(val, ((Component)this).transform.position, ((Component)this).transform.rotation, ((Component)this).transform.parent);
				barrel.AddComponent<LevelEdits.Made>().preset = preset;
				goneAt = -1f;
			}
		}

		private bool Free()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapSphere(((Component)this).transform.position + ((Component)this).transform.parent.up * 0.6f, 0.45f, -1, (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				if ((Object)(object)((Component)val).GetComponentInParent<GameEntity>() != (Object)null || (Object)(object)((Component)val).GetComponentInParent<Item_Object>() != (Object)null || (Object)(object)((Component)val).GetComponentInParent<ENT_Player>() != (Object)null)
				{
					return false;
				}
			}
			return true;
		}

		private void Label(string s)
		{
			if (!((Object)(object)sign == (Object)null))
			{
				if (((Component)sign).gameObject.activeSelf != (s != null))
				{
					((Component)sign).gameObject.SetActive(s != null);
				}
				if (s != null)
				{
					sign.SetLabel(s);
				}
			}
		}
	}
	internal class BloodbugMother : MonoBehaviour
	{
		private enum Phase
		{
			Fight,
			Flee,
			Landed,
			Shake
		}

		private enum ShakeStep
		{
			Lift,
			Dash
		}

		public const string Id = "arenamini_bloodbug_mother";

		public const string Title = "Bloodbug Mother";

		public const string BasePrefab = "Denizen_Bloodbug";

		private const float GrowBy = 4f;

		private const float HammerHits = 100f;

		private const float CooldownMult = 3f;

		private const float WindUpMult = 2f;

		private const float HitMult = 3f;

		private const float MinionEvery = 2.5f;

		private const float MinionDelay = 1f;

		private const float BackOff = 10f;

		private const int CooldownCap = 2;

		private const float FlashRate = 4f;

		private const float RetreatBreak = 0.5f;

		private const int Steps = 5;

		private const int Babies = 6;

		private const float RetreatTime = 30f;

		private const float FleeSpeed = 8f;

		private const float FleeMaxTime = 12f;

		private const float BabyEvery = 0.3f;

		private const float SightDistance = 30f;

		private const float Heavy = 20f;

		private const float MassClear = 3f;

		private const float MassRise = 6f;

		private static readonly FieldRef<DenizenAttackModule_Basic, float> cooldownUntil = AccessTools.FieldRefAccess<DenizenAttackModule_Basic, float>("attackCooldownTime");

		private DEN_BasicDenizen_Flier den;

		private DenizenMovement_BasicFlier flier;

		private DenizenAttackModule_Basic attacks;

		private AttackClass dash;

		private Rigidbody rigid;

		private float radius;

		private Phase phase;

		private int retreats;

		private float lastCooldown;

		private float nextMinion = float.MaxValue;

		private float fleeStart;

		private float retreatEnd;

		private float nextBaby;

		private int babiesLeft;

		private Vector3 landAt;

		private Vector3 landNormal = Vector3.up;

		private bool announcedDeath;

		private readonly List<GameObject> minions = new List<GameObject>();

		private readonly List<GameObject> babies = new List<GameObject>();

		private readonly List<(AIC_SimpleCreature_Hunt hunt, float hold)> hunts = new List<(AIC_SimpleCreature_Hunt, float)>();

		private static readonly HashSet<BloodbugMother> all = new HashSet<BloodbugMother>();

		private const float HeldHitAngle = 40f;

		private static readonly FieldRef<HandItem_Melee, bool> meleeHasHit = AccessTools.FieldRefAccess<HandItem_Melee, bool>("hasHit");

		private static readonly FieldRef<HandItem_Melee, bool> meleeCharged = AccessTools.FieldRefAccess<HandItem_Melee, bool>("isChargedAttack");

		private static readonly Perf.Section PerfMother = Perf.Make("*bloodbug mother");

		private float retreatHealth;

		private Vector3 clearAt;

		private bool clearSet;

		private static readonly string[] ColorProps = new string[4] { "_Color", "_BaseColor", "_MainColor", "_Tint" };

		private readonly List<(Material mat, string prop, Color own)> tints = new List<(Material, string, Color)>();

		private bool tintsRead;

		private bool flashing;

		private const float ShakeLiftTime = 1.5f;

		private const float LiftSpeed = 20f;

		private const float DashMaxTime = 5f;

		private const float DashMult = 2f;

		private const float SlamSpeed = 6f;

		private const float SlamStop = 0.4f;

		private const float BlockGap = 1f;

		private const float RideHold = 15f;

		private const float RideMax = 40f;

		private const float VelPerMs = 1f / 175f;

		private static readonly FieldRef<ENT_Player, Vector3> playerVel = AccessTools.FieldRefAccess<ENT_Player, Vector3>("vel");

		private ShakeStep step;

		private float stepEnd;

		private Vector3 dashDir;

		private Vector3 rideOffset;

		private Vector3 lastYourVel;

		private bool frozeRotation;

		private float shakeSpeed = 30f;

		private const float KnockReach = 2.5f;

		private const float UngrabTime = 1f;

		private const float KnockForce = 3.8f;

		private const float KnockUpAngle = 75f;

		private float grabbableAt;

		private const float FleeLook = 80f;

		private const float FleeFar = 40f;

		private const float NotAtYou = 60f;

		private static Vector3[] fleeDirs;

		private bool landOnHit;

		private float DashSpeed => shakeSpeed;

		private static int FlyMask => LayerMask.GetMask(new string[2] { "Default", "World" });

		public static GameObject Spawn(Vector3 at, Vector3 normal, Transform parent)
		{
			//IL_0005: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Spawner.Spawn("Denizen_Bloodbug", at, normal, parent, keep: true);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			((Object)val).name = "Bloodbug Mother";
			float num = BodyRadius(val);
			Transform transform = val.transform;
			transform.localScale *= 4f;
			float num2 = BodyRadius(val);
			Transform transform2 = val.transform;
			transform2.position += normal * num2;
			val.AddComponent<BloodbugMother>().Setup(num, num2);
			ArenaPlugin.Log.LogInfo((object)string.Format("{0}: x{1}, body {2:0.##} m across (Bloodbug {3:0.##} m) at {4}", "Bloodbug Mother", 4f, 2f * num2, 2f * num, val.transform.position));
			return val;
		}

		private static float BodyRadius(GameObject go)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			Physics.SyncTransforms();
			Bounds val = default(Bounds);
			bool flag = false;
			Collider[] componentsInChildren = go.GetComponentsInChildren<Collider>();
			foreach (Collider val2 in componentsInChildren)
			{
				if (!((Object)(object)val2 == (Object)null) && !val2.isTrigger)
				{
					if (flag)
					{
						((Bounds)(ref val)).Encapsulate(val2.bounds);
						continue;
					}
					val = val2.bounds;
					flag = true;
				}
			}
			if (!flag)
			{
				return 0.3f * go.transform.lossyScale.x;
			}
			return Mathf.Max(((Bounds)(ref val)).extents.x, ((Bounds)(ref val)).extents.z);
		}

		private void Setup(float before, float r)
		{
			den = ((Component)this).GetComponent<DEN_BasicDenizen_Flier>();
			rigid = ((Component)this).GetComponent<Rigidbody>();
			if ((Object)(object)den == (Object)null || (Object)(object)rigid == (Object)null)
			{
				ArenaPlugin.Log.LogWarning((object)"Bloodbug Mother: not a Bloodbug flier.");
				((Behaviour)this).enabled = false;
				return;
			}
			radius = r;
			float num = 4f;
			float num2 = HammerHit((GameEntity)(object)den);
			((GameEntity)den).maxHealth = (((GameEntity)den).health = 100f * num2);
			ArenaPlugin.Log.LogInfo((object)(string.Format("{0}: a hammer hit does {1:0.##} to her -> {2:0.##} HP; her multipliers: ", "Bloodbug Mother", num2, ((GameEntity)den).maxHealth) + ((((GameEntity)den).damageEffects == null || ((GameEntity)den).damageEffects.Count == 0) ? "none" : string.Join(", ", from x in ((GameEntity)den).damageEffects
				where x != null
				select string.Format("[{0}] x{1}", string.Join(" ", x.requiredTags ?? new List<string>()), x.damageMultiplier)))));
			ref DenizenAttackModule_Basic reference = ref attacks;
			DenizenAttackModule attackModule = ((DEN_BasicDenizen)den).attackModule;
			reference = (DenizenAttackModule_Basic)(object)((attackModule is DenizenAttackModule_Basic) ? attackModule : null);
			dash = attacks?.attacks?.FirstOrDefault((Func<AttackClass, bool>)((AttackClass a) => a != null && a.active && (int)a.attackType == 2));
			if (dash != null)
			{
				ArenaPlugin.Log.LogInfo((object)(string.Format("{0}: Bloodbug dash: cooldown {1} s, wait {2} s, wind-up {3} s, ", "Bloodbug Mother", dash.attackCooldown, dash.chargeAttackBeginWait, dash.chargeAttackDelay) + $"speed {dash.chargeAttackBoost}, reach {dash.chargeAttackDistance} m, hit {dash.meleeAttackHitDamage}, push {dash.meleeAttackHitForce}"));
				AttackClass obj = dash;
				obj.attackCooldown *= 3f;
				AttackClass obj2 = dash;
				obj2.chargeAttackDelay *= 2f;
				AttackClass obj3 = dash;
				obj3.meleeAttackHitDamage *= 3f;
				shakeSpeed = ((dash.chargeAttackBoost > 0f) ? dash.chargeAttackBoost : 15f) * 2f;
				AttackClass obj4 = dash;
				obj4.chargeAttackBoost *= num;
				AttackClass obj5 = dash;
				obj5.chargeAttackDistance *= num;
			}
			else
			{
				ArenaPlugin.Log.LogWarning((object)"Bloodbug Mother: the Bloodbug has no dash attack.");
			}
			ref DenizenMovement_BasicFlier reference2 = ref flier;
			DenizenMovementModule movementModule = ((DEN_BasicDenizen)den).movementModule;
			reference2 = (DenizenMovement_BasicFlier)(object)((movementModule is DenizenMovement_BasicFlier) ? movementModule : null);
			if (flier != null)
			{
				DenizenMovement_BasicFlier obj6 = flier;
				obj6.hoverDistance *= num;
				DenizenMovement_BasicFlier obj7 = flier;
				obj7.flySpeed *= 20f;
				DenizenMovement_BasicFlier obj8 = flier;
				obj8.flySpeedClamp *= 20f;
				DenizenMovement_BasicFlier obj9 = flier;
				obj9.noiseIntensity *= 20f;
			}
			ArenaPlugin.Log.LogInfo((object)string.Format("{0}: mass {1:0.##} -> {2:0.##}", "Bloodbug Mother", rigid.mass, rigid.mass * 20f));
			Rigidbody obj10 = rigid;
			obj10.mass *= 20f;
			((Component)this).gameObject.AddComponent<SizedMobs.GrownBody>().mult = 4f;
			foreach (AIC_SimpleCreature_Hunt item in ((DEN_BasicDenizen)den).aiStateComponents?.OfType<AIC_SimpleCreature_Hunt>() ?? Enumerable.Empty<AIC_SimpleCreature_Hunt>())
			{
				ArenaPlugin.Log.LogInfo((object)string.Format("{0}: hunt holds {1} m -> {2:0.##} m, attacks within {3} m", "Bloodbug Mother", item.huntHoldDistance, item.huntHoldDistance * num, item.attackDistance));
				item.huntHoldDistance *= num;
				hunts.Add((item, item.huntHoldDistance));
				item.attackDistance = Mathf.Max(item.attackDistance, dash?.chargeAttackDistance ?? 0f);
			}
			if (((AIGameEntity)den).sight != null)
			{
				((AIGameEntity)den).sight.sightDistance = Mathf.Max(((AIGameEntity)den).sight.sightDistance, 30f);
			}
			DEN_BasicDenizen_Flier obj11 = den;
			((GameEntity)obj11)._OnDamage = (Action<DamageInfo>)Delegate.Combine(((GameEntity)obj11)._OnDamage, new Action<DamageInfo>(OnHurt));
			HpBars.Track((GameEntity)(object)den, "Bloodbug Mother", boss: true);
			all.Add(this);
		}

		private void OnDestroy()
		{
			all.Remove(this);
		}

		public static void Register()
		{
			//IL_0005: 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_003e: Expected O, but got Unknown
			new Harmony("lazar.lakisarena.bloodbugmother").Patch((MethodBase)AccessTools.Method(typeof(HandItem_Melee), "Hit", (Type[])null, (Type[])null), new HarmonyMethod(typeof(BloodbugMother), "MeleeHitPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static void MeleeHitPrefix(HandItem_Melee __instance)
		{
			if ((Object)(object)__instance == (Object)null || meleeHasHit.Invoke(__instance) || __instance.banHammer || (Object)(object)Camera.main == (Object)null)
			{
				return;
			}
			foreach (BloodbugMother item in all)
			{
				if ((Object)(object)item != (Object)null && (Object)(object)item.den != (Object)null && !((GameEntity)item.den).dead && item.Held() && item.AimedAt(((Component)Camera.main).transform, __instance.range))
				{
					item.HeldHit(__instance);
					break;
				}
			}
		}

		private bool AimedAt(Transform cam, float range)
		{
			//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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !val.isTrigger && val.enabled)
				{
					Vector3 val2 = val.ClosestPoint(cam.position) - cam.position;
					if (!(((Vector3)(ref val2)).magnitude > range + 0.5f) && (((Vector3)(ref val2)).sqrMagnitude < 0.0001f || Vector3.Angle(cam.forward, val2) < 40f))
					{
						return true;
					}
				}
			}
			return false;
		}

		private void HeldHit(HandItem_Melee w)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			ENT_Player playerObject = ENT_Player.playerObject;
			bool flag = meleeCharged.Invoke(w);
			float num = (((Object)(object)playerObject != (Object)null) ? ((GameEntity)playerObject).curBuffs.GetBuff("addStrike") : 0f) + (flag ? w.chargeAttackDamage : w.damage);
			DamageInfo val = DamageInfo.CreateDamageInfo(num, "Melee", new List<string>(w.damageTags ?? new List<string>()), (GameEntity)(object)playerObject);
			val.tags.Add("player");
			val.position = ((Component)this).transform.position;
			if ((Object)(object)playerObject != (Object)null)
			{
				val.sourceEntity = (GameEntity)(object)playerObject;
				val.sourceObject = ((Component)playerObject).gameObject;
			}
			((GameEntity)den).Damage(val);
			ArenaPlugin.Log.LogInfo((object)string.Format("{0}: hit while held ({1} {2}, {3:0.##})", "Bloodbug Mother", flag ? "charged" : "plain", ((Object)w).name, num));
		}

		private void OnHurt(DamageInfo info)
		{
			if ((phase == Phase.Flee || phase == Phase.Landed) && !((Object)(object)den == (Object)null))
			{
				float num = retreatHealth - ((GameEntity)den).maxHealth / 5f * 0.5f;
				if (((GameEntity)den).health < num)
				{
					((GameEntity)den).health = num;
				}
			}
		}

		private static float HammerHit(GameEntity e)
		{
			HandItem_Melee val = ((IEnumerable<HandItem_Melee>)Resources.FindObjectsOfTypeAll<HandItem_Melee>()).FirstOrDefault((Func<HandItem_Melee, bool>)((HandItem_Melee h) => (Object)(object)h != (Object)null && ((Object)h).name.Contains("Hammer") && !((Object)h).name.Contains("Ban")));
			float num = (((Object)(object)val != (Object)null && val.damage > 0f) ? val.damage : 1f);
			List<string> tags = new List<string>
			{
				((Object)(object)val != (Object)null) ? val.damageType : "Melee",
				"Melee",
				"player"
			};
			if (val?.damageTags != null)
			{
				tags.AddRange(val.damageTags);
			}
			return num * ((e.damageEffects?.FirstOrDefault((Func<DamageEffect, bool>)((DamageEffect x) => x != null && x.HasTag(tags))))?.damageMultiplier ?? 1f);
		}

		private void Update()
		{
			using (PerfMother.Time())
			{
				Tick();
			}
		}

		private void Tick()
		{
			if ((Object)(object)den == (Object)null)
			{
				return;
			}
			if (((GameEntity)den).dead)
			{
				Died();
				return;
			}
			if (grabbableAt > 0f && Time.time >= grabbableAt)
			{
				grabbableAt = 0f;
				SetGrabbable(on: true);
			}
			AvoidMass();
			switch (phase)
			{
			case Phase.Fight:
				Fight();
				break;
			case Phase.Flee:
				Flee();
				break;
			case Phase.Landed:
				if (Time.time >= retreatEnd)
				{
					Resume();
				}
				break;
			case Phase.Shake:
				Shake();
				break;
			}
			if (phase == Phase.Fight || phase == Phase.Shake)
			{
				return;
			}
			Flash(on: true, 8f);
			if (retreatHealth - ((GameEntity)den).health >= ((GameEntity)den).maxHealth / 5f * 0.5f)
			{
				ArenaPlugin.Log.LogInfo((object)string.Format("{0}: hurt {1:0.#} while retreating, back up", "Bloodbug Mother", retreatHealth - ((GameEntity)den).health));
				if (phase == Phase.Flee)
				{
					Land();
				}
				Resume();
			}
		}

		private void FixedUpdate()
		{
			//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_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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)den == (Object)null || ((GameEntity)den).dead)
			{
				clearSet = false;
				return;
			}
			Vector3 position = rigid.position;
			if (!clearSet)
			{
				clearAt = position;
				clearSet = true;
				return;
			}
			Vector3 moved = position - clearAt;
			if (((Vector3)(ref moved)).sqrMagnitude < 0.0001f)
			{
				return;
			}
			if (!WallBetween(clearAt, moved, out var wall))
			{
				clearAt = position;
				return;
			}
			Vector3 position2 = clearAt + ((RaycastHit)(ref wall)).normal * 0.05f;
			rigid.position = position2;
			((Component)this).transform.position = position2;
			if (!rigid.isKinematic && Vector3.Dot(rigid.linearVelocity, ((RaycastHit)(ref wall)).normal) < 0f)
			{
				rigid.linearVelocity = Vector3.ProjectOnPlane(rigid.linearVelocity, ((RaycastHit)(ref wall)).normal);
			}
			ArenaPlugin.Log.LogInfo((object)string.Format("{0}: went through {1} ({2:0.##} m, {3}), put back", "Bloodbug Mother", ((Object)((RaycastHit)(ref wall)).collider).name, ((Vector3)(ref moved)).magnitude, phase));
		}

		private bool WallBetween(Vector3 from, Vector3 moved, out RaycastHit wall)
		{
			//IL_0001: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			wall = default(RaycastHit);
			float num = float.MaxValue;
			RaycastHit[] array = Physics.RaycastAll(from, ((Vector3)(ref moved)).normalized, ((Vector3)(ref moved)).magnitude, FlyMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if (!((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) && !((Object)(object)((RaycastHit)(ref val)).rigidbody != (Object)null) && !((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)this).transform) && !(((RaycastHit)(ref val)).distance >= num))
				{
					num = ((RaycastHit)(ref val)).distance;
					wall = val;
				}
			}
			return num < float.MaxValue;
		}

		private void AvoidMass()
		{
			//IL_000c: 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_00a3: 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_00c1: 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)
			float top = Mass.Top;
			if (((Component)this).transform.position.y - radius - top > 3f)
			{
				return;
			}
			if (phase == Phase.Landed)
			{
				ArenaPlugin.Log.LogInfo((object)"Bloodbug Mother: the mass is here, up");
				Resume();
			}
			if (phase == Phase.Flee && landAt.y - radius < top + 3f)
			{
				landAt.y = top + radius + 6f;
				landOnHit = false;
			}
			if (!rigid.isKinematic)
			{
				Vector3 linearVelocity = rigid.linearVelocity;
				if (linearVelocity.y < 6f)
				{
					rigid.linearVelocity = new Vector3(linearVelocity.x, 6f, linearVelocity.z);
				}
			}
		}

		private void Fight()
		{
			//IL_01d6: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Min(4, Mathf.FloorToInt((((GameEntity)den).maxHealth - ((GameEntity)den).health) / (((GameEntity)den).maxHealth / 5f) + 0.0001f));
			if (num > retreats)
			{
				retreats = num;
				StartRetreat();
			}
			else if (Held())
			{
				StartShake();
			}
			else
			{
				if (attacks == null)
				{
					return;
				}
				float num2 = cooldownUntil.Invoke(attacks);
				if (num2 > lastCooldown + 0.01f)
				{
					lastCooldown = num2;
					nextMinion = Time.time + (dash?.chargeAttackDelay ?? 1f) + 1f;
				}
				bool flag = Time.time < num2 && Time.time > lastCooldown - (dash?.attackCooldown ?? 0f) + (dash?.chargeAttackDelay ?? 1f) + 1f;
				Flash(flag);
				foreach (var hunt in hunts)
				{
					AIC_SimpleCreature_Hunt item = hunt.hunt;
					float item2 = hunt.hold;
					item.huntHoldDistance = (flag ? Mathf.Max(item2, 10f) : item2);
				}
				if (Time.time >= nextMinion && Time.time < num2)
				{
					nextMinion += 2.5f;
					Alive(minions);
					Alive(babies);
					if (minions.Count + babies.Count < 2)
					{
						Call(minions, "Bloodbug", ((Component)this).transform.position + Sideways() * (radius + 1f));
					}
				}
			}
		}

		private void Flash(bool on, float rate = 4f)
		{
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			if (!tintsRead)
			{
				tintsRead = true;
				Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val in componentsInChildren)
				{
					if (!(val is MeshRenderer) && !(val is SkinnedMeshRenderer))
					{
						continue;
					}
					Material[] materials = val.materials;
					foreach (Material val2 in materials)
					{
						string[] colorProps = ColorProps;
						foreach (string text in colorProps)
						{
							if ((Object)(object)val2 != (Object)null && val2.HasProperty(text))
							{
								tints.Add((val2, text, val2.GetColor(text)));
							}
						}
					}
				}
				ArenaPlugin.Log.LogInfo((object)(string.Format("{0}: flash tints {1} colour(s): ", "Bloodbug Mother", tints.Count) + string.Join(", ", tints.Select(((Material mat, string prop, Color own) t) => ((Object)t.mat.shader).name + "." + t.prop).Distinct())));
			}
			if (!on && !flashing)
			{
				return;
			}
			flashing = on;
			float num = (on ? (0.5f + 0.5f * Mathf.Sin(Time.time * rate * 2f * MathF.PI)) : 0f);
			foreach (var tint in tints)
			{
				if ((Object)(object)tint.mat != (Object)null)
				{
					tint.mat.SetColor(tint.prop, Color.Lerp(tint.own, new Color(1f, 0.05f, 0.05f, tint.own.a), num));
				}
			}
		}

		private void StartRetreat()
		{
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			phase = Phase.Flee;
			fleeStart = Time.time;
			retreatEnd = Time.time + 30f;
			babiesLeft = 6;
			nextBaby = Time.time + 0.3f;
			nextMinion = float.MaxValue;
			retreatHealth = ((GameEntity)den).health;
			DenizenAttackModule_Basic obj = attacks;
			if (obj != null)
			{
				((DenizenAttackModule)obj).StopAllAttacks();
			}
			Animator animator = ((DEN_BasicDenizen)den).animator;
			if (animator != null)
			{
				animator.SetBool(dash?.chargeAnimationBool ?? "Charging", false);
			}
			((DEN_BasicDenizen)den).active = false;
			if (flier != null)
			{
				flier.isCrawling = false;
			}
			rigid.isKinematic = false;
			rigid.useGravity = false;
			KnockOff();
			PickLanding();
			ArenaPlugin.Log.LogInfo((object)string.Format("{0}: retreat {1} at {2:0.#}/{3:0} HP, to {4} ({5:0.#} m away)", "Bloodbug Mother", retreats, ((GameEntity)den).health, ((GameEntity)den).maxHealth, landAt, Vector3.Distance(((Component)this).transform.position, landAt)));
		}

		private void Flee()
		{
			//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)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0105: 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_0060: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = landAt - ((Component)this).transform.position;
			RaycastHit val2 = default(RaycastHit);
			if (((Vector3)(ref val)).magnitude < 0.6f && !landOnHit && Physics.SphereCast(((Component)this).transform.position, radius * 0.9f, Vector3.down, ref val2, 60f, FlyMask, (QueryTriggerInteraction)1))
			{
				landAt = ((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * radius * 0.6f;
				landNormal = ((RaycastHit)(ref val2)).normal;
				landOnHit = true;
				return;
			}
			if (((Vector3)(ref val)).magnitude < 0.6f || Time.time > fleeStart + 12f)
			{
				Land();
				return;
			}
			rigid.linearVelocity = Vector3.MoveTowards(rigid.linearVelocity, ((Vector3)(ref val)).normalized * 8f, 30f * Time.deltaTime);
			Vector3 val3 = Vector3.ProjectOnPlane(val, Vector3.up);
			if (((Vector3)(ref val3)).sqrMagnitude > 0.01f)
			{
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, Quaternion.LookRotation(val3), Time.deltaTime * 5f);
			}
			if (babiesLeft > 0 && Time.time >= nextBaby)
			{
				nextBaby = Time.time + 0.3f;
				babiesLeft--;
				Call(babies, "Baby Bloodbug", ((Component)this).transform.position - ((Component)this).transform.forward * (radius + 0.5f));
			}
		}

		private void Land()
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_0101: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			phase = Phase.Landed;
			if (!landOnHit || Vector3.Distance(((Component)this).transform.position, landAt) > 1.5f)
			{
				RaycastHit val = default(RaycastHit);
				if (Physics.Raycast(((Component)this).transform.position, Vector3.down, ref val, 30f, FlyMask, (QueryTriggerInteraction)1))
				{
					landAt = ((RaycastHit)(ref val)).point + ((RaycastHit)(ref val)).normal * radius * 0.6f;
					landNormal = ((RaycastHit)(ref val)).normal;
				}
				else
				{
					landAt = ((Component)this).transform.position;
				}
			}
			rigid.linearVelocity = Vector3.zero;
			rigid.isKinematic = true;
			((Component)this).transform.position = landAt;
			Vector3 val2 = Vector3.ProjectOnPlane(((Component)this).transform.forward, landNormal);
			((Component)this).transform.rotation = Quaternion.LookRotation((((Vector3)(ref val2)).sqrMagnitude > 0.01f) ? val2 : Vector3.ProjectOnPlane(Vector3.forward, landNormal), landNormal);
			if (flier != null)
			{
				flier.isCrawling = true;
			}
			while (babiesLeft > 0)
			{
				Call(babies, "Baby Bloodbug", ((Component)this).transform.position + Sideways() * (radius + 1f) + landNormal);
				babiesLeft--;
			}
			ArenaPlugin.Log.LogInfo((object)string.Format("{0}: landed, flies again in {1:0.#} s", "Bloodbug Mother", retreatEnd - Time.time));
		}

		private void Resume()
		{
			Hunt(fromRetreat: true);
		}

		private void Hunt(bool fromRetreat)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			phase = Phase.Fight;
			rigid.isKinematic = false;
			rigid.useGravity = true;
			if (flier != null)
			{
				flier.isCrawling = false;
			}
			((DEN_BasicDenizen)den).active = true;
			if (fromRetreat)
			{
				rigid.AddForce(landNormal * 4f, (ForceMode)2);
				KnockOff();
			}
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject != (Object)null && !((GameEntity)playerObject).dead)
			{
				AITargetComponent targetComponent = ((DEN_BasicDenizen)den).targetComponent;
				if (targetComponent != null)
				{
					targetComponent.SetTarget(((Component)playerObject).transform);
				}
				AISightComponent sight = ((AIGameEntity)den).sight;
				if (sight != null)
				{
					sight.SetTargetAsVisible(((Component)playerObject).transform, 4f);
				}
				((AIGameEntity)den).target = ((Component)playerObject).transform;
				((AIGameEntity)den).ChangeState("hunt");
			}
			ArenaPlugin.Log.LogInfo((object)"Bloodbug Mother: flying again");
		}

		private void StartShake()
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			phase = Phase.Shake;
			nextMinion = float.MaxValue;
			DenizenAttackModule_Basic obj = attacks;
			if (obj != null)
			{
				((DenizenAttackModule)obj).StopAllAttacks();
			}
			Animator animator = ((DEN_BasicDenizen)den).animator;
			if (animator != null)
			{
				animator.SetBool(dash?.chargeAnimationBool ?? "Charging", false);
			}
			((DEN_BasicDenizen)den).active = false;
			if (flier != null)
			{
				flier.isCrawling = false;
			}
			rigid.isKinematic = false;
			rigid.useGravity = false;
			frozeRotation = rigid.freezeRotation;
			rigid.freezeRotation = true;
			rigid.angularVelocity = Vector3.zero;
			step = ShakeStep.Lift;
			stepEnd = Time.time + 1.5f;
			lastYourVel = Vector3.zero;
			ENT_Player playerObject = ENT_Player.playerObject;
			if ((Object)(object)playerObject != (Object)null)
			{
				rideOffset = ((Component)playerObject).transform.position - ((Component)this).transform.position;
				((GameEntity)playerObject).AddForce(Vector3.up * 0.6f, "");
			}
			ArenaPlugin.Log.LogInfo((object)"Bloodbug Mother: grabbed, lifting you");
		}

		private void EndShake()
		{
			rigid.freezeRotation = frozeRotation;
			Animator animator = ((DEN_BasicDenizen)den).animator;
			if (animator != null)
			{
				animator.SetBool(dash?.chargeAnimationBool ?? "Charging", false);
			}
		}

		private void Shake()
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: 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_0134: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			ENT_Player playerObject = ENT_Player.playerObject;
			int num = Mathf.Min(4, Mathf.FloorToInt((((GameEntity)den).maxHealth - ((GameEntity)den).health) / (((GameEntity)den).maxHealth / 5f) + 0.0001f));
			if (num > retreats)
			{
				retreats = num;
				EndShake();
				StartRetreat();
				return;
			}
			if ((Object)(object)playerObject == (Object)null || ((GameEntity)playerObject).dead)
			{
				EndShake();
				Hunt(fromRetreat: false);
				return;
			}
			if (!Held())
			{
				if (Blocked(playerObject))
				{
					Hurt(playerObject, "tore you off");
					Release();
				}
				else
				{
					ArenaPlugin.Log.LogInfo((object)"Bloodbug Mother: let go, hunting again");
				}
				EndShake();
				Hunt(fromRetreat: false);
				return;
			}
			Flash(on: true, 8f);
			rigid.angularVelocity = Vector3.zero;
			if (step == ShakeStep.Lift)
			{
				rigid.linearVelocity = Vector3.up * 20f;
				if (!Slammed(playerObject) && !(Time.time < stepEnd))
				{
					Vector3 val = ((Component)playerObject).transform.position - ((Component)this).transform.position;
					dashDir = ((((Vector3)(ref val)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val)).normalized : ((Component)this).transform.forward);
					step = ShakeStep.Dash;
					stepEnd = Time.time + 5f;
					lastYourVel = Vector3.zero;
					Animator animator = ((DEN_BasicDenizen)den).animator;
					if (animator != null)
					{
						animator.SetBool(dash?.chargeAnimationBool ?? "Charging", true);
					}
					ArenaPlugin.Log.LogInfo((object)string.Format("{0}: dashing at {1:0.#} m/s, way {2}", "Bloodbug Mother", DashSpeed, dashDir));
				}
			}
			else
			{
				rigid.linearVelocity = dashDir * DashSpeed;
				if (!Slammed(playerObject) && Time.time >= stepEnd)
				{
					ArenaPlugin.Log.LogInfo((object)"Bloodbug Mother: dash hit nothing, hunting again");
					EndShake();
					Hunt(fromRetreat: false);
				}
			}
		}

		private bool Slammed(ENT_Player p)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0024: 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 ((Object)(object)p.cCon == (Object)null)
			{
				return false;
			}
			Vector3 velocity = p.cCon.velocity;
			Vector3 val = lastYourVel;
			lastYourVel = velocity;
			if (((Vector3)(ref val)).magnitude < 6f || ((Vector3)(ref velocity)).magnitude > ((Vector3)(ref val)).magnitude * 0.4f)
			{
				return false;
			}
			Release();
			Hurt(p, $"slammed you, {((Vector3)(ref val)).magnitude:0.#} -> {((Vector3)(ref velocity)).magnitude:0.#} m/s");
			EndShake();
			Hunt(fromRetreat: false);
			if (attacks != null)
			{
				cooldownUntil.Invoke(attacks) = (lastCooldown = Time.time);
			}
			return true;
		}

		private bool Blocked(ENT_Player p)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			return Vector3.Distance(((Component)p).transform.position, ((Component)this).transform.position + rideOffset) > 1f;
		}

		private void Hurt(ENT_Player p, string how)
		{
			float num = ((dash != null) ? dash.meleeAttackHitDamage : 0.9f) * (CL_GameManager.IsHardmode() ? 2f : 1f);
			((GameEntity)p).Damage(DamageInfo.CreateDamageInfo(num, "blunt", new List<string> { "denizen", "impact" }, (GameEntity)(object)den));
			ArenaPlugin.Log.LogInfo((object)string.Format("{0}: {1}, -{2:0.##} HP", "Bloodbug Mother", how, num));
		}

		private void LateUpdate()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			if (phase == Phase.Shake && !((Object)(object)den == (Object)null) && !rigid.isKinematic)
			{
				ENT_Player playerObject = ENT_Player.playerObject;
				if (!((Object)(object)playerObject == (Object)null) && !((GameEntity)playerObject).dead)
				{
					Vector3 val = rigid.linearVelocity + (((Component)this).transform.position + rideOffset - ((Component)playerObject).transform.position) * 15f;
					playerVel.Invoke(playerObject) = Vector3.ClampMagnitude(val, 40f) * (1f / 175f);
				}
			}
		}

		private bool Held()
		{
			ENT_Player playerObject = ENT_Player.playerObject;
			if (playerObject?.hands == null)
			{
				return false;
			}
			Hand[] hands = playerObject.hands;
			foreach (Hand val in hands)
			{
				if (val != null && OnHer(val))
				{
					return true;
				}
			}
			return false;
		}

		private bool OnHer(Hand h)
		{
			if (!((Object)(object)h.grabTarget != (Object)null) || !((Component)h.grabTarget).transform.IsChildOf(((Component)this).transform))
			{
				if ((Object)(object)h.holdTarget != (Object)null)
				{
					return h.holdTarget.IsChildOf(((Component)this).transform);
				}
				return false;
			}
			return true;
		}

		private void KnockOff()
		{
			//IL_0025: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			ENT_Player playerObject = ENT_Player.playerObject;
			bool flag = Release();
			if (!((Object)(object)playerObject == (Object)null) && !((GameEntity)playerObject).dead)
			{
				Vector3 val = ((Component)playerObject).transform.position - ((Component)this).transform.position;
				if (flag || !(((Vector3)(ref val)).magnitude > radius + 2.5f))
				{
					Vector3 val2 = Vector3.ProjectOnPlane(val, Vector3.up);
					val2 = ((((Vector3)(ref val2)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val2)).normalized : (-((Component)this).transform.forward));
					Vector3 val3 = Vector3.Slerp(val2, Vector3.up, 5f / 6f) * 3.8f;
					((GameEntity)playerObject).AddForce(val3, "denizen");
					ArenaPlugin.Log.LogInfo((object)string.Format("{0}: bounced you off ({1}), push {2}", "Bloodbug Mother", flag ? "held" : "close", val3));
				}
			}
		}

		private bool Release()
		{
			SetGrabbable(on: false);
			grabbableAt = Time.time + 1f;
			ENT_Player playerObject = ENT_Player.playerObject;
			if (playerObject?.hands == null || ((GameEntity)playerObject).dead)
			{
				return false;
			}
			bool result = false;
			Hand[] hands = playerObject.hands;
			foreach (Hand val in hands)
			{
				if (val != null && OnHer(val))
				{
					result = true;
					playerObject.StopInteraction(val.id, "drop", false);
				}
			}
			return result;
		}

		private void SetGrabbable(bool on)
		{
			CL_Prop[] componentsInChildren = ((Component)this).GetComponentsInChildren<CL_Prop>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].canInteract = on;
			}
		}

		private static Vector3[] FleeDirs()
		{
			//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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (fleeDirs != null)
			{
				return fleeDirs;
			}
			List<Vector3> list = new List<Vector3>();
			Vector3[] array = (Vector3[])(object)new Vector3[3]
			{
				Vector3.right,
				Vector3.up,
				Vector3.forward
			};
			foreach (Vector3 val in array)
			{
				Vector3 val2 = Vector3.Cross(val, (val == Vector3.up) ? Vector3.forward : Vector3.up);
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				for (int j = 0; j < 8; j++)
				{
					Vector3 d = Quaternion.AngleAxis(45f * (float)j, val) * normalized;
					if (!list.Any((Vector3 x) => Vector3.Angle(x, d) < 1f))
					{
						list.Add(((Vector3)(ref d)).normalized);
					}
				}
			}
			return fleeDirs = list.ToArray();
		}

		private void PickLanding()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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)
			//IL_0096: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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_014c: 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_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: 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_00fa: 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_0115: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			ENT_Player playerObject = ENT_Player.playerObject;
			Vector3 val = (((Object)(object)playerObject != (Object)null) ? ((Component)playerObject).transform.position : position);
			Vector3 val2 = position - val;
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			float num = float.MinValue;
			float num2 = 0f;
			Vector3 val3 = Vector3.up;
			RaycastHit val4 = default(RaycastHit);
			bool flag = false;
			Vector3[] array = FleeDirs();
			RaycastHit val6 = default(RaycastHit);
			foreach (Vector3 val5 in array)
			{
				if (!((Object)(object)playerObject != (Object)null) || !(Vector3.Angle(val5, val - position) < 60f))
				{
					bool flag2 = Physics.SphereCast(position, radius * 0.9f, val5, ref val6, 80f, FlyMask, (QueryTriggerInteraction)1) && !((Component)((RaycastHit)(ref val6)).collider).transform.IsChildOf(((Component)this).transform);
					float num3 = (flag2 ? ((RaycastHit)(ref val6)).distance : 80f);
					float num4 = num3 * (1f + 0.3f * Vector3.Dot(val5, normalized));
					if (!(num4 <= num))
					{
						num = num4;
						num2 = num3;
						val3 = val5;
						val4 = val6;
						flag = flag2;
					}
				}
			}
			landOnHit = flag;
			if (flag)
			{
				landNormal = ((RaycastHit)(ref val4)).normal;
				landAt = ((RaycastHit)(ref val4)).point + ((RaycastHit)(ref val4)).normal * radius * 0.6f;
			}
			else
			{
				landNormal = Vector3.up;
				landAt = position + val3 * Mathf.Min(num2, 40f);
			}
			ArenaPlugin.Log.LogInfo((object)string.Format("{0}: flees {1} ({2:0.#} m free{3})", "Bloodbug Mother", val3, num2, flag ? "" : ", lands under the end"));
		}

		private void Call(List<GameObject> list, string name, Vector3 at)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Spawner.Spawn("Denizen_Bloodbug", at - Vector3.up, Vector3.up, ((Component)this).transform.parent, keep: true);
			if (!((Object)(object)val == (Object)null))
			{
				((Object)val).name = name;
				BloodbugChild bloodbugChild = val.AddComponent<BloodbugChild>();
				bloodbugChild.mother = this;
				bloodbugChild.baby = list == babies;
				list.Add(val);
				GameEntity component = val.GetComponent<GameEntity>();
				if ((Object)(object)component != (Object)null)
				{
					HpBars.Track(component, name);
				}
			}
		}

		private static void Alive(List<GameObject> list)
		{
			list.RemoveAll((GameObject g) => (Object)(object)g == (Object)null || (g.GetComponent<GameEntity>()?.dead ?? true));
		}

		private static Vector3 Sideways()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_000e: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			Vector2 insideUnitCircle = Random.insideUnitCircle;
			Vector2 normalized = ((Vector2)(ref insideUnitCircle)).normalized;
			return new Vector3(normalized.x, 0f, normalized.y);
		}

		private void Died()
		{
			if (!announcedDeath)
			{
				announcedDeath = true;
				Flash(on: false);
				rigid.isKinematic = false;
				rigid.useGravity = true;
				((DEN_BasicDenizen)den).active = true;
				BigText.Show("VICTORY!!");
				ArenaPlugin.Log.LogInfo((object)"Bloodbug Mother: dead");
			}
		}
	}
	internal class BloodbugChild : MonoBehaviour
	{
		public const string Id = "arenamini_bloodbug_mother_baby";

		public BloodbugMother mother;

		public bool baby;
	}
	internal static class BossRoom
	{
		public const string Level = "Campaign_Interlude_Silo_To_Pipeworks_01";

		private const string Barrel = "Prop_Barrel_Explosive";

		private const int PerWalkway = 5;

		private const int OnFloor = 5;

		private const int Walkways = 2;

		private const float BarrelRadius = 0.4f;

		private const float BarrelHeight = 1.2f;

		private const float BarrelGap = 1.6f;

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

		public static void Register()
		{
			ArenaConsole.Add("bossroom", delegate
			{
				object obj;
				if (!((Object)(object)ENT_Player.playerObject != (Object)null))
				{
					Camera main = Camera.main;
					obj = ((main != null) ? ((Component)main).transform : null);
				}
				else
				{
					obj = ((Component)ENT_Player.playerObject).transform;
				}
				Transform you = (Transform)obj;
				M_Level val = (from x in Object.FindObjectsOfType<M_Level>().Where(Is)
					orderby (!((Object)(object)you != (Object)null)) ? 0f : Vector3.Distance(((Component)x).transform.position, you.position)
					select x).FirstOrDefault();
				if ((Object)(object)val == (Object)null)
				{
					MapApi.Say("No Campaign_Interlude_Silo_To_Pipeworks_01 loaded.");
				}
				else
				{
					Furnish(val);
				}
			}, "set up the Silos interlude boss fight (Mother Barnacle + barrels) in the nearest copy ");
		}

		private static bool Is(M_Level l)
		{
			if ((Object)(object)l != (Object)null)
			{
				if (!((Object)l).name.StartsWith("Campaign_Interlude_Silo_To_Pipeworks_01"))
				{
					return ((Object)l).name.StartsWith("run_Campaign_Interlude_Silo_To_Pipeworks_01");
				}
				return true;
			}
			return false;
		}

		public static void Furnish(M_Level l)
		{
			try
			{
				Build(l);
			}
			catch (Exception arg)
			{
				ArenaPlugin.Log.LogError((object)$"Boss room: {arg}");
			}
		}

		private static void Build(M_Level l)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_013a: 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_0133: 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_016d: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: 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_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: 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_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: 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_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a4: 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_04ab: 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_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_057e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0593: Unknown result type (might be due to invalid IL or missing references)
			//IL_0598: Unknown result type (might be due to invalid IL or missing references)
			//IL_059e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05da: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject item in made)
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)item);
				}
			}
			made.Clear();
			Physics.SyncTransforms();
			Vector3 up = ((Component)l).transform.up;
			Transform transform = ((Component)l).transform;
			if (!Hole(l, up, out var top))
			{
				ArenaPlugin.Log.LogWarning((object)"Boss room: couldn't find the silo door's hole.");
				return;
			}
			Vector3 val = top;
			float num = float.NaN;
			float num2 = float.MaxValue;
			bool flag = false;
			for (float num3 = 0.3f; num3 < 30f; num3 += 0.5f)
			{
				if (Ring(val - up * num3, up, 12f, out var radius, out var mid))
				{
					flag = true;
					num = num3;
					num2 = Mathf.Min(num2, radius);
					val = mid + up * Vector3.Dot(val - mid, up);
				}
				else if (flag)
				{
					break;
				}
			}
			top = val - up * Vector3.Dot(val - top, up);
			float num4 = (flag ? (2f * num2) : 6f);
			Vector3 val2 = (flag ? (val - up * num) : top);
			ArenaPlugin.Log.LogInfo((object)(flag ? $"Boss room: door hole at {top}, {num4:0.##} m across at its narrowest, {num:0.#} m deep" : $"Boss room: no walls in the door hole at {top}; she gets {num4} m."));
			GameObject val3 = MotherBarnacle.Spawn(top, -up, num4, transform);
			if ((Object)(object)val3 != (Object)null)
			{
				made.Add(val3);
				Bounds val4 = Body(val3);
				float num5 = Vector3.Dot(((Bounds)(ref val4)).center - top, up) + ((Bounds)(ref val4)).extents.y;
				Transform transform2 = val3.transform;
				transform2.position -= up * (num5 + 0.1f);
			}
			GameObject val5 = Spawner.Prefab("Prop_Barrel_Explosive");
			if ((Object)(object)val5 == (Object)null)
			{
				ArenaPlugin.Log.LogWarning((object)"Boss room: no 'Prop_Barrel_Explosive' in the game.");
				return;
			}
			float num6 = Wall(val2 - up * 3f, up);
			if (num6 <= 0f)
			{
				ArenaPlugin.Log.LogWarning((object)"Boss room: couldn't find the room's wall.");
				return;
			}
			List<(float, float)> list = Rings(val2, up, num6);
			ArenaPlugin.Log.LogInfo((object)($"Boss room: wall {num6:0.#} m from the axis; flat rings at " + string.Join(", ", list.Select<(float, float), string>(((float depth, float share) r) => $"{r.depth:0.#} m ({r.share:P0})")) + " under the rim"));
			if (list.Count == 0)
			{
				return;
			}
			List<Vector3> list2 = new List<Vector3>();
			(float, float) tuple = list.Last();
			foreach (var item2 in (from r in list.Take(list.Count - 1)
				orderby r.share descending
				select r).Take(2).ToList())
			{
				float num7 = Random.value * 360f;
				int num8 = 0;
				for (int num9 = 0; num9 < 5; num9++)
				{
					for (int num10 = 0; num10 < 9; num10++)
					{
						float a = num7 + 360f * (float)num9 / 5f + (float)((num10 % 2 == 0) ? 1 : (-1)) * 5f * (float)((num10 + 1) / 2);
						if (OnRing(val2, up, a, num6, item2.Item1, list2, out var at))
						{
							made.Add(Put(val5, at, up, transform));
							list2.Add(at);
							num8++;
							break;
						}
					}
				}
				ArenaPlugin.Log.LogInfo((object)$"Boss room: {num8} barrels on the walkway {item2.Item1:0.#} m under the rim");
			}
			int num11 = 0;
			Vector3 val6 = val2 - up * tuple.Item1;
			for (int num12 = 0; num12 < 200; num12++)
			{
				if (num11 >= 5)
				{
					break;
				}
				float num13 = Random.value * 360f;
				float num14 = Mathf.Lerp(1.5f, num6 * 0.7f, Mathf.Pow(Random.value, 1.5f));
				if (Ground(val6 + Quaternion.AngleAxis(num13, up) * Side(up) * num14 + up * 2f, up, 4f, out var at2) && Mathf.Abs(Vector3.Dot(at2 - val6, up)) < 0.8f && Free(at2, up, list2))
				{
					made.Add(Put(val5, at2, up, transform));
					list2.Add(at2);
					num11++;
				}
			}
			ArenaPlugin.Log.LogInfo((object)$"