Decompiled source of HatterEnemiesPack v1.0.0

HatterEnemiesPack.dll

Decompiled 16 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
using REPOLib.Objects.Sdk;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("HatterEnemiesPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HatterEnemiesPack")]
[assembly: AssemblyTitle("HatterEnemiesPack")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HatterEnemiesPack;

public class AlterMimic : MonoBehaviour
{
	private enum Mode
	{
		Roam,
		Hunt,
		Head,
		Semibot
	}

	internal const int FormNone = 0;

	internal const int FormHead = 1;

	internal const int FormSemibot = 2;

	private Enemy enemy;

	private EnemyParent parent;

	private EnemyNavMeshAgent nav;

	private EnemyRigidbody body;

	private EnemyHealth health;

	private PhotonView view;

	private Rigidbody rb;

	private PhysGrabObject grab;

	private Mode mode;

	private PlayerAvatar target;

	private PlayerAvatar loneCandidate;

	private float loneSince = -1f;

	private float notLoneSince = -1f;

	private float nextLoneCheck;

	private float nextRoam;

	private float nextHuntPath;

	private float nextFollowFix;

	private bool possessed;

	private bool talking;

	private bool charging;

	private bool countdown;

	private float countdownNext;

	private float nextInsideCheck;

	private float nextPulse;

	private float insideSince = -1f;

	private int insideKind;

	private bool vibrating;

	private int countdownIndex;

	private bool armed;

	private float chargeTime;

	private float nextEpisode = -1f;

	private float episodeNext;

	private int episodeLeft;

	private float seenSince = -1f;

	private bool noticed;

	private bool actionChosen;

	private bool targetDeathLogged;

	private int latchedView = -1;

	private int form;

	private bool possessedLocal;

	private MimicHead head;

	private MimicSemibot bot;

	private bool botDeathHandled;

	private bool deathHandled;

	private float despawnAt = -1f;

	private float dyingSince = -1f;

	private float nextBotAgent;

	private bool wasSpawned;

	private readonly List<Collider> bodyColliders = new List<Collider>();

	private Collider headCollider;

	private bool bodySolid = true;

	private bool originalGravity;

	private float nextHuntLog;

	private bool bodyFreed;

	private bool oldUseGravity;

	private bool oldKinematic;

	private GUIStyle markerStyle;

	private float nextSpeedSet;

	private bool speedLogged;

	private int originalHp = -1;

	private static readonly FieldInfo ResistanceField = AccessTools.Field(typeof(EnemyHealth), "damageResistance");

	private float originalResistance = -1f;

	private static readonly FieldInfo CartItemsField = AccessTools.Field(typeof(PhysGrabCart), "itemsInCart");

	private static readonly FieldInfo BodyOverchargeField = AccessTools.Field(typeof(EnemyRigidbody), "overchargeMultiplier");

	private static readonly FieldInfo ParentOverchargeField = AccessTools.Field(typeof(EnemyParent), "overrideOverchargeMultiplier");

	private bool overchargeWarned;

	private string lastLine;

	private static readonly FieldInfo HurtColorField = AccessTools.Field(typeof(EnemyHealth), "hurtColor");

	private Vector3 BodyPos
	{
		get
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)rb != (Object)null))
			{
				return ((Component)this).transform.position;
			}
			return rb.position;
		}
	}

	internal EnemyHealth Health => health;

	private Vector3 AgentPos => ((Component)this).transform.position;

	private static bool Solo
	{
		get
		{
			if (Settings.DebugSolo.Value)
			{
				return Living().Count <= 1;
			}
			return false;
		}
	}

	private void Awake()
	{
		enemy = ((Component)this).GetComponent<Enemy>();
		parent = ((Component)this).GetComponentInParent<EnemyParent>();
		nav = ((Component)this).GetComponent<EnemyNavMeshAgent>() ?? ((Component)this).GetComponentInChildren<EnemyNavMeshAgent>(true);
		health = ((Component)this).GetComponent<EnemyHealth>() ?? ((Component)this).GetComponentInChildren<EnemyHealth>(true);
		view = ((Component)this).GetComponent<PhotonView>();
		body = (((Object)(object)parent != (Object)null) ? ((Component)parent).GetComponentInChildren<EnemyRigidbody>(true) : null);
		rb = (((Object)(object)body != (Object)null) ? ((Component)body).GetComponent<Rigidbody>() : null);
		grab = (((Object)(object)body != (Object)null) ? ((Component)body).GetComponent<PhysGrabObject>() : null);
		if (!((Object)(object)body != (Object)null))
		{
			return;
		}
		originalGravity = body.gravity;
		Collider[] componentsInChildren = ((Component)body).GetComponentsInChildren<Collider>(true);
		foreach (Collider val in componentsInChildren)
		{
			if (!val.isTrigger)
			{
				bodyColliders.Add(val);
			}
		}
		Type[] array = new Type[3]
		{
			typeof(SphereCollider),
			typeof(CapsuleCollider),
			typeof(BoxCollider)
		};
		foreach (Type type in array)
		{
			if ((Object)(object)headCollider != (Object)null)
			{
				break;
			}
			foreach (Collider bodyCollider in bodyColliders)
			{
				if (type.IsInstanceOfType(bodyCollider))
				{
					headCollider = bodyCollider;
					break;
				}
			}
		}
	}

	private void Start()
	{
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		R.Info("Alter Mimic: started (nav " + (((Object)(object)nav != (Object)null) ? "yes" : "NO") + ", rigidbody " + (((Object)(object)body != (Object)null) ? "yes" : "NO") + ", health " + (((Object)(object)health != (Object)null) ? health.health.ToString() : "NO") + ", view " + (((Object)(object)view != (Object)null) ? view.ViewID.ToString() : "NO") + ").");
		if ((Object)(object)body != (Object)null)
		{
			List<string> list = new List<string>();
			Collider[] componentsInChildren = ((Component)body).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				object[] obj = new object[5]
				{
					((object)val).GetType().Name,
					((Object)val).name,
					null,
					null,
					null
				};
				Bounds bounds = val.bounds;
				obj[2] = ((Bounds)(ref bounds)).size;
				obj[3] = LayerMask.LayerToName(((Component)val).gameObject.layer);
				obj[4] = (val.isTrigger ? " trigger" : "");
				list.Add(string.Format("{0} '{1}' {2} layer {3}{4}", obj));
			}
			R.Info(string.Format("Alter Mimic: rigidbody colliders: {0}; gravity {1}, mass {2}, grabbable {3}.", string.Join("; ", list), body.gravity, ((Object)(object)rb != (Object)null) ? rb.mass : 0f, (Object)(object)grab != (Object)null));
		}
	}

	private void OnDisable()
	{
		EndLocal("disabled (despawned or died)");
	}

	private void LateUpdate()
	{
		bool flag = form == 1;
		if ((Object)(object)body != (Object)null)
		{
			body.gravity = form == 1;
		}
		if (flag == bodySolid && !AnyMismatch(flag))
		{
			return;
		}
		bodySolid = flag;
		foreach (Collider bodyCollider in bodyColliders)
		{
			if ((Object)(object)bodyCollider != (Object)null)
			{
				bodyCollider.enabled = Wanted(bodyCollider, flag);
			}
		}
	}

	private bool Wanted(Collider c, bool solid)
	{
		if (solid)
		{
			if (!((Object)(object)headCollider == (Object)null))
			{
				return (Object)(object)c == (Object)(object)headCollider;
			}
			return true;
		}
		return false;
	}

	private bool AnyMismatch(bool solid)
	{
		foreach (Collider bodyCollider in bodyColliders)
		{
			if ((Object)(object)bodyCollider != (Object)null && bodyCollider.enabled != Wanted(bodyCollider, solid))
			{
				return true;
			}
		}
		return false;
	}

	private void FreeBody(bool free)
	{
		if (!((Object)(object)body == (Object)null) && !((Object)(object)rb == (Object)null) && free != bodyFreed)
		{
			bodyFreed = free;
			if (free)
			{
				oldUseGravity = rb.useGravity;
				oldKinematic = rb.isKinematic;
				((Behaviour)body).enabled = false;
				rb.isKinematic = false;
				rb.useGravity = true;
			}
			else
			{
				rb.useGravity = oldUseGravity;
				rb.isKinematic = oldKinematic;
				((Behaviour)body).enabled = true;
			}
			R.Info("Alter Mimic: the body is " + (free ? "plain physics now (the enemy body script is off)" : "back to normal") + ".");
		}
	}

	private void OnGUI()
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//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_0071: 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_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: 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_015b: 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_016e: Expected O, but got Unknown
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		if (!Settings.DebugSolo.Value || !wasSpawned)
		{
			return;
		}
		Camera main = Camera.main;
		if (!((Object)(object)main == (Object)null))
		{
			bool flag = form == 1 && (Object)(object)head != (Object)null;
			bool flag2 = form == 2 && (Object)(object)bot != (Object)null && (Object)(object)bot.Rig != (Object)null;
			Vector3 val = (flag ? ((Component)head).transform.position : (flag2 ? (bot.Feet + Vector3.up * 2.1f) : AgentPos));
			Vector3 val2 = main.WorldToScreenPoint(val + Vector3.up * 0.2f);
			if (val2.z < 0f)
			{
				val2.x = (float)Screen.width - val2.x;
				val2.y = 0f;
			}
			float num = Mathf.Clamp(val2.x, 40f, (float)Screen.width - 40f);
			float num2 = Mathf.Clamp((float)Screen.height - val2.y, 30f, (float)Screen.height - 30f);
			if (markerStyle == null)
			{
				markerStyle = new GUIStyle(GUI.skin.box)
				{
					fontSize = 16,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				markerStyle.normal.textColor = Color.white;
			}
			float num3 = (((Object)(object)PlayerAvatar.instance != (Object)null) ? Vector3.Distance(((Component)PlayerAvatar.instance).transform.position, val) : 0f);
			string text = (flag ? string.Format("MIMIC HEAD{0}  {1:0} m", possessedLocal ? " (possessed)" : "", num3) : (flag2 ? string.Format("MIMIC SEMIBOT: {0}  {1}{2:0} m", bot.StateLabel, ((Object)(object)health != (Object)null) ? (R.GetHealth(health).ToString("0") + " HP  ") : "", num3) : string.Format("mimic ({0})  {1:0} m", R.IsHost ? mode.ToString().ToLower() : "hidden", num3)));
			Color color = GUI.color;
			GUI.color = ((flag || flag2) ? new Color(1f, 0.25f, 0.25f) : new Color(0.7f, 0.7f, 0.7f, 0.8f));
			float num4 = (flag2 ? 520f : 360f);
			GUI.Box(new Rect(num - num4 * 0.5f, num2 - 16f, num4, 32f), text, markerStyle);
			GUI.color = color;
		}
	}

	private void Update()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)parent != (Object)null) || !R.Spawned(parent))
		{
			if (wasSpawned)
			{
				EndLocal("despawned");
				if (R.IsHost)
				{
					ResetHost();
				}
			}
			wasSpawned = false;
			return;
		}
		if (!wasSpawned)
		{
			wasSpawned = true;
			Plugin.Log.LogInfo((object)$"Alter Mimic: spawned at {AgentPos}.");
		}
		OverchargeTick();
		if (!R.IsHost)
		{
			return;
		}
		if ((Object)(object)health != (Object)null && (R.EnemyDead(health) || R.EnemyDying(health)))
		{
			HostDeath();
			return;
		}
		switch (mode)
		{
		case Mode.Roam:
			Roam();
			break;
		case Mode.Hunt:
			Hunt();
			break;
		case Mode.Head:
			HeadHost();
			break;
		case Mode.Semibot:
			BotHost();
			break;
		}
	}

	private void ResetHost()
	{
		deathHandled = false;
		despawnAt = (dyingSince = -1f);
		mode = Mode.Roam;
		target = (loneCandidate = null);
		loneSince = (notLoneSince = -1f);
		possessed = false;
		targetDeathLogged = false;
	}

	private void HunterSpeedTick()
	{
		if (!((Object)(object)nav == (Object)null) && !(Time.time < nextSpeedSet))
		{
			nextSpeedSet = Time.time + 0.25f;
			PlayerController instance = PlayerController.instance;
			float num = (((Object)(object)instance != (Object)null && instance.MoveSpeed > 0.1f) ? instance.MoveSpeed : 2.5f);
			float num2 = num * Settings.HunterSpeed.Value;
			try
			{
				nav.OverrideAgent(num2, Mathf.Max(num2 * 4f, 8f), 0.5f);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Alter Mimic: setting its speed failed: " + ex.Message));
				nextSpeedSet = float.MaxValue;
			}
			if (!speedLogged)
			{
				speedLogged = true;
				R.Info($"Alter Mimic: invisible speed {num2:0.##} m/s ({Settings.HunterSpeed.Value:0.##} x walking {num:0.##}).");
			}
		}
	}

	private void Roam()
	{
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		HunterSpeedTick();
		if (Time.time >= nextLoneCheck)
		{
			nextLoneCheck = Time.time + 0.5f;
			PlayerAvatar val = FindLone();
			if ((Object)(object)val == (Object)null)
			{
				loneCandidate = null;
			}
			else
			{
				if ((Object)(object)val != (Object)(object)loneCandidate)
				{
					loneCandidate = val;
					loneSince = Time.time;
				}
				if (Time.time - loneSince >= Settings.LoneSeconds.Value)
				{
					target = val;
					mode = Mode.Hunt;
					notLoneSince = -1f;
					R.Info("Alter Mimic: hunting " + R.Name(target) + " (alone in their room).");
					return;
				}
			}
		}
		if (!(Time.time >= nextRoam) || !((Object)(object)nav != (Object)null))
		{
			return;
		}
		nextRoam = Time.time + Random.Range(4f, 9f);
		List<LevelPoint> list = SemiFunc.LevelPointsGetAll();
		if (list != null && list.Count > 0)
		{
			LevelPoint val2 = list[Random.Range(0, list.Count)];
			if ((Object)(object)val2 != (Object)null)
			{
				nav.SetDestination(((Component)val2).transform.position);
			}
		}
	}

	private void Hunt()
	{
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		HunterSpeedTick();
		if (!R.Alive(target))
		{
			R.Info("Alter Mimic: its target is gone; roaming again.");
			ResetHost();
			return;
		}
		if (Time.time >= nextLoneCheck)
		{
			nextLoneCheck = Time.time + 0.5f;
			if (IsLone(target))
			{
				notLoneSince = -1f;
			}
			else if (notLoneSince < 0f)
			{
				notLoneSince = Time.time;
			}
			else if (Time.time - notLoneSince > 3f)
			{
				R.Info("Alter Mimic: " + R.Name(target) + " isn't alone any more; roaming again.");
				ResetHost();
				return;
			}
		}
		if (Time.time >= nextHuntPath && (Object)(object)nav != (Object)null)
		{
			nextHuntPath = Time.time + 0.3f;
			nav.SetDestination(((Component)target).transform.position);
		}
		float num = Vector3.Distance(AgentPos, ((Component)target).transform.position);
		if (Time.time >= nextHuntLog)
		{
			nextHuntLog = Time.time + 2f;
			R.Info($"Alter Mimic: hunting {R.Name(target)}: {num:0.#} m away (agent at {AgentPos}, body at {BodyPos}).");
		}
		if (num <= Settings.LatchDistance.Value)
		{
			Latch();
		}
	}

	internal static List<PlayerAvatar> Living()
	{
		List<PlayerAvatar> list = new List<PlayerAvatar>();
		foreach (PlayerAvatar item in SemiFunc.PlayerGetList())
		{
			if (R.Alive(item) && !IsStandIn(item))
			{
				list.Add(item);
			}
		}
		return list;
	}

	private static HashSet<Object> Rooms(PlayerAvatar p)
	{
		HashSet<Object> hashSet = new HashSet<Object>();
		if ((Object)(object)p == (Object)null || (Object)(object)p.RoomVolumeCheck == (Object)null || p.RoomVolumeCheck.CurrentRooms == null)
		{
			return hashSet;
		}
		foreach (RoomVolume currentRoom in p.RoomVolumeCheck.CurrentRooms)
		{
			if (!((Object)(object)currentRoom == (Object)null))
			{
				Module componentInParent = ((Component)currentRoom).GetComponentInParent<Module>();
				hashSet.Add((Object)(((Object)(object)componentInParent != (Object)null) ? ((object)componentInParent) : ((object)currentRoom)));
			}
		}
		return hashSet;
	}

	private static bool IsLone(PlayerAvatar p)
	{
		if (Solo)
		{
			return R.Alive(p);
		}
		HashSet<Object> hashSet = Rooms(p);
		if (hashSet.Count == 0)
		{
			return false;
		}
		foreach (PlayerAvatar item in Living())
		{
			if ((Object)(object)item == (Object)(object)p)
			{
				continue;
			}
			foreach (Object item2 in Rooms(item))
			{
				if (hashSet.Contains(item2))
				{
					return false;
				}
			}
		}
		return true;
	}

	private PlayerAvatar FindLone()
	{
		//IL_0026: 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)
		PlayerAvatar result = null;
		float num = float.MaxValue;
		foreach (PlayerAvatar item in Living())
		{
			if (IsLone(item))
			{
				float num2 = Vector3.Distance(AgentPos, ((Component)item).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = item;
				}
			}
		}
		return result;
	}

	private static bool IsStandIn(PlayerAvatar p)
	{
		if (R.ViewId(p) < 16000000)
		{
			return R.Name(p) == "Ally Dummy";
		}
		return true;
	}

	private List<PlayerAvatar> Others()
	{
		List<PlayerAvatar> list = new List<PlayerAvatar>();
		foreach (PlayerAvatar item in Living())
		{
			if ((Object)(object)item != (Object)(object)target)
			{
				list.Add(item);
			}
		}
		if (list.Count == 0 && Settings.DebugSolo.Value && R.Alive(target))
		{
			list.Add(target);
		}
		return list;
	}

	private void Latch()
	{
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0369: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: 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_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		List<PlayerAvatar> list = Others();
		if (list.Count == 0)
		{
			List<string> list2 = new List<string>();
			foreach (PlayerAvatar item in SemiFunc.PlayerGetList())
			{
				list2.Add($"{R.Name(item)} (view {R.ViewId(item)}, alive {R.Alive(item)}, stand-in {IsStandIn(item)})");
			}
			R.Info("Alter Mimic: nobody else to appear near; roaming again. Players: " + string.Join(", ", list2) + "; [Debug] SoloTesting is " + (Settings.DebugSolo.Value ? "on" : "OFF") + ".");
			ResetHost();
			return;
		}
		PlayerAvatar val = list[Random.Range(0, list.Count)];
		if (!HiddenSpotNear(val, out var spot))
		{
			R.Info("Alter Mimic: no spot out of sight near " + R.Name(val) + "; roaming again.");
			ResetHost();
			return;
		}
		Teleport(spot);
		string value = Settings.DebugForceForm.Value;
		if (value == "Semibot" || (value != "Head" && Random.value < Settings.BotChance.Value))
		{
			Vector3 val2 = ((Component)val).transform.position - spot;
			val2.y = 0f;
			float num;
			if (!(((Vector3)(ref val2)).sqrMagnitude > 0.01f))
			{
				num = 0f;
			}
			else
			{
				Quaternion val3 = Quaternion.LookRotation(val2);
				num = ((Quaternion)(ref val3)).eulerAngles.y;
			}
			float num2 = num;
			int value2 = Settings.BotHealth.Value;
			SetupHealth(value2, 0, 0, 0);
			SetResistance(0f);
			mode = Mode.Semibot;
			botDeathHandled = false;
			R.Info($"Alter Mimic: latched on to {R.Name(target)} (muted); appears as their semibot {Vector3.Distance(spot, ((Component)val).transform.position):0.#} m from {R.Name(val)}, at {spot}.");
			Send("MimicLatchRPC", R.ViewId(target), 2, spot, num2);
			if ((Object)(object)bot != (Object)null)
			{
				bot.StartHost(val);
				return;
			}
			R.Info("Alter Mimic: the semibot couldn't be built; unlatching.");
			Unlatch("no semibot");
			RestoreHidden();
		}
		else
		{
			SetupHealth(1, 0, 0, 1);
			mode = Mode.Head;
			possessed = false;
			charging = false;
			countdown = false;
			armed = false;
			nextPulse = 0f;
			insideSince = -1f;
			insideKind = 0;
			vibrating = false;
			nextEpisode = -1f;
			seenSince = -1f;
			noticed = false;
			actionChosen = false;
			R.Info($"Alter Mimic: latched on to {R.Name(target)} (muted); appears as their dead head {Vector3.Distance(spot, ((Component)val).transform.position):0.#} m from {R.Name(val)}, at {spot}.");
			Send("MimicLatchRPC", R.ViewId(target), 1, spot, 0f);
		}
	}

	private bool HiddenSpotNear(PlayerAvatar near, out Vector3 spot)
	{
		//IL_0001: 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_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: 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_0142: 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_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: 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)
		spot = Vector3.zero;
		List<LevelPoint> list = SemiFunc.LevelPointGetWithinDistance(((Component)near).transform.position, Settings.TeleportMinDistance.Value, Settings.TeleportMaxDistance.Value);
		if (list == null || list.Count == 0)
		{
			return false;
		}
		List<PlayerAvatar> list2 = Living();
		Vector3[] array = (Vector3[])(object)new Vector3[3]
		{
			Vector3.up * 0.3f,
			Vector3.up * 1f,
			Vector3.up * 1.7f
		};
		for (int i = 0; i < list.Count; i++)
		{
			int num = Random.Range(i, list.Count);
			int index = i;
			List<LevelPoint> list3 = list;
			int index2 = num;
			LevelPoint val = list[num];
			LevelPoint val2 = list[i];
			LevelPoint val3 = (list[index] = val);
			val3 = (list3[index2] = val2);
		}
		foreach (LevelPoint item in list)
		{
			if ((Object)(object)item == (Object)null)
			{
				continue;
			}
			Vector3 position = ((Component)item).transform.position;
			bool flag = false;
			foreach (PlayerAvatar item2 in list2)
			{
				Vector3 val6 = R.Eyes(item2);
				Vector3[] array2 = array;
				foreach (Vector3 val7 in array2)
				{
					if (Clear(val6, position + val7))
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					break;
				}
			}
			if (!flag)
			{
				spot = position;
				return true;
			}
		}
		return false;
	}

	private void SetupHealth(int hp, int light, int medium, int heavy)
	{
		if (!((Object)(object)health == (Object)null))
		{
			if (originalHp < 0)
			{
				originalHp = health.health;
			}
			health.health = hp;
			R.SetHealth(health, hp);
			health.impactHurt = true;
			health.impactLightDamage = light;
			health.impactMediumDamage = medium;
			health.impactHeavyDamage = heavy;
			health.objectHurt = true;
			health.spawnValuable = true;
			if (health.spawnValuableMax < 1)
			{
				health.spawnValuableMax = 1;
			}
			R.Info($"Alter Mimic: {hp} HP; impacts hurt {light}/{medium}/{heavy}; drops a soul orb.");
		}
	}

	private void RestoreHidden()
	{
		if (!((Object)(object)health == (Object)null))
		{
			if (originalHp > 0)
			{
				health.health = originalHp;
				R.SetHealth(health, originalHp);
			}
			if (originalResistance >= 0f)
			{
				SetResistance(originalResistance);
			}
		}
	}

	private void SetResistance(float value)
	{
		if (!((Object)(object)health == (Object)null) && !(ResistanceField == null))
		{
			if (originalResistance < 0f)
			{
				originalResistance = (float)ResistanceField.GetValue(health);
			}
			ResistanceField.SetValue(health, value);
		}
	}

	private void Teleport(Vector3 pos)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_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)
		//IL_0074: 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)
		try
		{
			if ((Object)(object)nav != (Object)null)
			{
				nav.Warp(pos, true);
			}
			if ((Object)(object)rb != (Object)null)
			{
				rb.position = pos + Vector3.up * 0.3f;
				((Component)body).transform.position = pos + Vector3.up * 0.3f;
				rb.linearVelocity = Vector3.zero;
			}
			if ((Object)(object)enemy != (Object)null)
			{
				enemy.EnemyTeleported(pos);
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogWarning((object)$"Alter Mimic: teleport failed: {arg}");
		}
	}

	private void HeadHost()
	{
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: 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_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_0464: Unknown result type (might be due to invalid IL or missing references)
		//IL_0469: Unknown result type (might be due to invalid IL or missing references)
		//IL_0473: Unknown result type (might be due to invalid IL or missing references)
		//IL_0478: Unknown result type (might be due to invalid IL or missing references)
		//IL_047d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0487: Unknown result type (might be due to invalid IL or missing references)
		//IL_0551: Unknown result type (might be due to invalid IL or missing references)
		//IL_0556: Unknown result type (might be due to invalid IL or missing references)
		//IL_055a: Unknown result type (might be due to invalid IL or missing references)
		//IL_055f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0562: Unknown result type (might be due to invalid IL or missing references)
		//IL_056d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0586: Unknown result type (might be due to invalid IL or missing references)
		//IL_0592: Unknown result type (might be due to invalid IL or missing references)
		//IL_0599: 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_05bb: 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_05cb: 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_05d2: 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_05df: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)target == (Object)null)
		{
			Unlatch("its target left");
			return;
		}
		if (!targetDeathLogged && R.IsDead(target))
		{
			targetDeathLogged = true;
			R.Info("Alter Mimic: " + R.Name(target) + " died (it stays a head).");
		}
		if (Time.time >= nextFollowFix && (Object)(object)nav != (Object)null)
		{
			nextFollowFix = Time.time + 0.5f;
			try
			{
				nav.Stop(0.6f);
				nav.Warp(BodyPos, true);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogWarning((object)$"Alter Mimic: moving the agent failed: {arg}");
				nextFollowFix = float.MaxValue;
			}
		}
		if (countdown)
		{
			if (!(Time.time < countdownNext))
			{
				string[] array = CountdownWordList();
				if (countdownIndex < array.Length)
				{
					Send("MimicSayRPC", array[countdownIndex]);
					countdownIndex++;
					countdownNext = Time.time + Settings.CountdownGap.Value;
				}
				else
				{
					Explode();
				}
			}
			return;
		}
		bool flag = (Object)(object)grab != (Object)null && grab.playerGrabbing != null && grab.playerGrabbing.Count > 0;
		if (armed && flag)
		{
			countdown = true;
			countdownIndex = 0;
			countdownNext = Time.time;
			if (!possessed)
			{
				possessed = true;
				Send("MimicPossessRPC", true);
			}
			charging = false;
			R.Info("Alter Mimic: grabbed while armed; counting down (" + Settings.CountdownWords.Value + ") before it explodes.");
			return;
		}
		InsideTick();
		PlayerAvatar val = null;
		float num = float.MaxValue;
		foreach (PlayerAvatar item in Others())
		{
			float num2 = Vector3.Distance(BodyPos, R.Eyes(item));
			if (!(num2 > Settings.HeadSightRange.Value) && !(num2 >= num) && Clear(R.Eyes(item), BodyPos))
			{
				num = num2;
				val = item;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			seenSince = -1f;
		}
		else if (seenSince < 0f)
		{
			seenSince = Time.time;
		}
		if (!possessed)
		{
			if (!noticed)
			{
				if (!(seenSince < 0f) && !(Time.time - seenSince < Settings.HeadNoticeSeconds.Value))
				{
					noticed = true;
					StartPossession(Settings.HeadFirstActions.Value, val, num, "first");
				}
			}
			else if (!(Time.time < nextEpisode) && !((Object)(object)val == (Object)null))
			{
				int value = Settings.HeadLaterActionsMin.Value;
				int num3 = Mathf.Max(value, Settings.HeadLaterActionsMax.Value);
				StartPossession(Random.Range(value, num3 + 1), val, num, "again");
			}
		}
		else
		{
			if (Time.time < episodeNext)
			{
				return;
			}
			if (episodeLeft <= 0)
			{
				possessed = false;
				nextEpisode = Time.time + Settings.HeadPossessWait.Value;
				R.Info($"Alter Mimic: goes still (next time in {Settings.HeadPossessWait.Value:0} s, once someone can see it).");
				Send("MimicPossessRPC", false);
				return;
			}
			if (!actionChosen)
			{
				actionChosen = true;
				talking = Random.value >= Settings.HeadJumpChance.Value;
			}
			if (talking)
			{
				string text = PickLine();
				episodeLeft--;
				actionChosen = false;
				episodeNext = Time.time + 1.2f + 0.4f * (float)text.Split(' ').Length;
				if (text.Length > 0)
				{
					R.Info("Alter Mimic: says \"" + text + "\".");
					Send("MimicSayRPC", text);
				}
			}
			else if ((Object)(object)rb == (Object)null)
			{
				episodeLeft = 0;
			}
			else if (!Physics.Raycast(BodyPos + Vector3.up * 0.1f, Vector3.down, 1.2f, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1))
			{
				episodeNext = Time.time + 0.3f;
			}
			else if (!charging)
			{
				chargeTime = Random.Range(Settings.ChargeMin.Value, Mathf.Max(Settings.ChargeMin.Value, Settings.ChargeMax.Value));
				charging = true;
				episodeNext = Time.time + chargeTime;
				Send("MimicChargeRPC", chargeTime);
			}
			else
			{
				charging = false;
				episodeLeft--;
				actionChosen = false;
				episodeNext = Time.time + Random.Range(0.6f, 1f);
				Vector2 insideUnitCircle = Random.insideUnitCircle;
				Vector2 normalized = ((Vector2)(ref insideUnitCircle)).normalized;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(normalized.x, 0f, normalized.y);
				float num4 = chargeTime;
				rb.AddForce(val2 * Settings.HopSpeedPerCharge.Value * num4 + Vector3.up * (Settings.HopUpward.Value + Settings.HopUpwardPerCharge.Value * num4), (ForceMode)2);
				Vector3 val3 = Vector3.Cross(Vector3.up, val2);
				rb.AddTorque(val3 * (3f + 4f * num4), (ForceMode)2);
				R.Info($"Alter Mimic: jumps after a {num4:0.##} s charge.");
				Send("MimicHopRPC", num4 >= 0.7f);
			}
		}
	}

	private string[] CountdownWordList()
	{
		List<string> list = new List<string>();
		string[] array = (Settings.CountdownWords.Value ?? "").Split('|');
		for (int i = 0; i < array.Length; i++)
		{
			string text = array[i].Trim();
			if (text.Length > 0)
			{
				list.Add(text);
			}
		}
		return list.ToArray();
	}

	private int InsideKind(Vector3 at)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		Collider[] array = Physics.OverlapSphere(at, 0.05f, -1, (QueryTriggerInteraction)2);
		foreach (Collider val in array)
		{
			if (!((Object)(object)val == (Object)null) && !bodyColliders.Contains(val))
			{
				if ((Object)(object)((Component)val).GetComponentInParent<PhysGrabInCart>() != (Object)null)
				{
					return 1;
				}
				RoomVolume componentInParent = ((Component)val).GetComponentInParent<RoomVolume>();
				if ((Object)(object)componentInParent != (Object)null && componentInParent.Extraction)
				{
					flag = true;
				}
			}
		}
		if (CartItemsField != null && (Object)(object)grab != (Object)null)
		{
			PhysGrabCart[] array2 = Object.FindObjectsByType<PhysGrabCart>((FindObjectsSortMode)0);
			foreach (PhysGrabCart obj in array2)
			{
				if (CartItemsField.GetValue(obj) is List<PhysGrabObject> list && list.Contains(grab))
				{
					return 1;
				}
			}
		}
		if (!flag)
		{
			return 0;
		}
		return 2;
	}

	private void InsideTick()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		if (Time.time >= nextInsideCheck)
		{
			nextInsideCheck = Time.time + 0.25f;
			insideKind = InsideKind(BodyPos);
		}
		int num = insideKind;
		if (num == 0)
		{
			nextPulse = 0f;
			insideSince = -1f;
			if (vibrating)
			{
				vibrating = false;
				Send("MimicArmRPC", false);
			}
			return;
		}
		if (!armed)
		{
			if ((Object)(object)grab != (Object)null && grab.playerGrabbing != null && grab.playerGrabbing.Count > 0)
			{
				insideSince = -1f;
				return;
			}
			if (insideSince < 0f)
			{
				insideSince = Time.time;
				R.Info(string.Format("Alter Mimic: left in {0}; arms in {1:0.#} s if nobody picks it up.", (num == 1) ? "a cart" : "an extraction point", Settings.ArmSeconds.Value));
			}
			if (Time.time - insideSince < Settings.ArmSeconds.Value)
			{
				return;
			}
			armed = true;
			nextPulse = 0f;
			R.Info("Alter Mimic: armed in " + ((num == 1) ? "a cart" : "an extraction point") + " (pulses; grabbing it now starts the countdown).");
		}
		if (nextPulse <= 0f)
		{
			nextPulse = Time.time + 1f;
		}
		if (!vibrating && Time.time >= nextPulse - 1f)
		{
			vibrating = true;
			Send("MimicArmRPC", true);
		}
		if (Time.time >= nextPulse)
		{
			nextPulse = Time.time + Settings.ShockwavePulseSeconds.Value;
			float num2 = ((num == 1) ? Settings.ShockwaveRadiusCart.Value : Settings.ShockwaveRadiusExtraction.Value);
			Shockwave(BodyPos, num2);
			Send("MimicPulseRPC", BodyPos, num2);
			vibrating = false;
			Send("MimicArmRPC", false);
		}
	}

	private void Shockwave(Vector3 centre, float radius)
	{
		//IL_0011: 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_0137: 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_014a: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: 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_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		float value = Settings.ShockwaveForce.Value;
		HashSet<PhysGrabObject> hashSet = new HashSet<PhysGrabObject>();
		Collider[] array = Physics.OverlapSphere(centre, radius, -1, (QueryTriggerInteraction)1);
		foreach (Collider val in array)
		{
			PhysGrabObject val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentInParent<PhysGrabObject>() : null);
			if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)grab || !hashSet.Add(val2) || (Object)(object)((Component)val2).GetComponent<PhysGrabCart>() != (Object)null || (Object)(object)((Component)val2).GetComponentInParent<PlayerAvatar>() != (Object)null || (Object)(object)((Component)val2).GetComponentInParent<PlayerTumble>() != (Object)null || (Object)(object)((Component)val2).GetComponentInParent<EnemyRigidbody>() != (Object)null)
			{
				continue;
			}
			Rigidbody component = ((Component)val2).GetComponent<Rigidbody>();
			if (!((Object)(object)component == (Object)null) && !component.isKinematic)
			{
				Vector3 val3 = component.worldCenterOfMass - centre;
				val3 = ((((Vector3)(ref val3)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val3)).normalized : Random.onUnitSphere);
				Vector3 val4 = val3 + Vector3.up * 0.5f;
				val3 = ((Vector3)(ref val4)).normalized;
				try
				{
					val2.OverrideIndestructible(1.5f);
				}
				catch
				{
				}
				component.AddForce(val3 * value, (ForceMode)1);
				component.AddTorque(Random.insideUnitSphere * value * 0.05f, (ForceMode)1);
			}
		}
		R.Info($"Alter Mimic: shockwave ({radius:0.#} m, force {value:0}): pushed {hashSet.Count} object(s).");
	}

	private void OverchargeTick()
	{
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		if (form != 1 || (Object)(object)grab == (Object)null || !grab.grabbedLocal || (Object)(object)body == (Object)null || ((Behaviour)body).enabled || (Object)(object)parent == (Object)null)
		{
			return;
		}
		float num = 1f;
		try
		{
			if (BodyOverchargeField != null)
			{
				num *= (float)BodyOverchargeField.GetValue(body);
			}
			if (ParentOverchargeField != null)
			{
				num *= (float)ParentOverchargeField.GetValue(parent);
			}
			SemiFunc.EnemyOvercharge(grab, parent.difficulty, num);
		}
		catch (Exception ex)
		{
			if (!overchargeWarned)
			{
				overchargeWarned = true;
				Plugin.Log.LogWarning((object)("Alter Mimic: overcharge failed: " + ex.Message));
			}
		}
	}

	private void StartPossession(int actions, PlayerAvatar seer, float seerD, string which)
	{
		possessed = true;
		episodeLeft = Mathf.Max(1, actions);
		episodeNext = Time.time + 0.8f;
		actionChosen = false;
		charging = false;
		R.Info($"Alter Mimic: possessed ({which}; {R.Name(seer)} sees it from {seerD:0.#} m): {episodeLeft} action(s).");
		Send("MimicPossessRPC", true);
	}

	internal static PlayerAvatar NearestPlayer(Vector3 from, float range)
	{
		//IL_0019: 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)
		PlayerAvatar result = null;
		float num = range;
		foreach (PlayerAvatar item in Living())
		{
			float num2 = Vector3.Distance(from, ((Component)item).transform.position);
			if (num2 < num)
			{
				num = num2;
				result = item;
			}
		}
		return result;
	}

	internal static bool CanSee(Vector3 eye, PlayerAvatar p, float range)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: 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)
		if (!R.Alive(p))
		{
			return false;
		}
		Vector3 val = R.Eyes(p);
		if (Vector3.Distance(eye, val) <= range)
		{
			return Clear(eye, val);
		}
		return false;
	}

	internal static bool Clear(Vector3 from, Vector3 to)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = to - from;
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (magnitude < 0.01f)
		{
			return true;
		}
		RaycastHit[] array = Physics.RaycastAll(from, val / magnitude, magnitude, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1);
		for (int i = 0; i < array.Length; i++)
		{
			RaycastHit val2 = array[i];
			Collider collider = ((RaycastHit)(ref val2)).collider;
			if (!((Object)(object)collider == (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<PlayerAvatar>() != (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<PlayerController>() != (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<MimicBotHitbox>() != (Object)null))
			{
				EnemyRigidbody componentInParent = ((Component)collider).GetComponentInParent<EnemyRigidbody>();
				if (!((Object)(object)componentInParent != (Object)null) || !((Object)(object)componentInParent.enemy != (Object)null) || !((Object)(object)((Component)componentInParent.enemy).GetComponent<AlterMimic>() != (Object)null))
				{
					return false;
				}
			}
		}
		return true;
	}

	internal static PlayerAvatar NearestVisible(Vector3 eye, float range, PlayerAvatar exclude)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0039: 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)
		PlayerAvatar result = null;
		float num = range;
		foreach (PlayerAvatar item in Living())
		{
			if (!((Object)(object)item == (Object)(object)exclude))
			{
				Vector3 val = R.Eyes(item);
				float num2 = Vector3.Distance(eye, val);
				if (!(num2 > num) && Clear(eye, val))
				{
					num = num2;
					result = item;
				}
			}
		}
		return result;
	}

	private string PickLine()
	{
		List<string> list = new List<string>();
		string[] array = new string[2]
		{
			Settings.HeadLines.Value,
			Settings.SharedLines.Value
		};
		foreach (string text in array)
		{
			if (string.IsNullOrEmpty(text))
			{
				continue;
			}
			string[] array2 = text.Split('|');
			for (int j = 0; j < array2.Length; j++)
			{
				string text2 = array2[j].Trim();
				if (text2.Length > 0)
				{
					list.Add(text2);
				}
			}
		}
		if (list.Count == 0)
		{
			return "";
		}
		if (list.Count > 1)
		{
			list.Remove(lastLine);
		}
		lastLine = list[Random.Range(0, list.Count)];
		return lastLine;
	}

	private void HostDeath()
	{
		//IL_00b7: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		if (mode == Mode.Semibot && (Object)(object)bot != (Object)null && !botDeathHandled)
		{
			botDeathHandled = true;
			bot.HostDied();
		}
		if (deathHandled)
		{
			if (!(despawnAt > 0f) || !(Time.time >= despawnAt))
			{
				return;
			}
			despawnAt = -1f;
			Vector3 val = ((form == 2 && (Object)(object)bot != (Object)null) ? bot.Chest : BodyPos);
			try
			{
				if ((Object)(object)nav != (Object)null)
				{
					nav.Warp(val, true);
				}
			}
			catch
			{
			}
			R.Info($"Alter Mimic: died; despawning (soul orb) at {val}.");
			Send("MimicDeathFxRPC", val);
			try
			{
				parent.Despawn();
				return;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogWarning((object)$"Alter Mimic: despawning failed: {arg}");
				return;
			}
		}
		if (dyingSince < 0f)
		{
			dyingSince = Time.time;
		}
		if (R.EnemyDead(health) || !(Time.time - dyingSince < 3f))
		{
			deathHandled = true;
			despawnAt = Time.time + ((mode == Mode.Semibot) ? 1.2f : 0.2f);
		}
	}

	internal void HurtVisual()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)bot != (Object)null && (Object)(object)bot.Rig != (Object)null)
		{
			bot.Rig.Flash(HurtColor(), 0.35f);
		}
	}

	private Color HurtColor()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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_003f: 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)
		try
		{
			if (HurtColorField != null && (Object)(object)health != (Object)null)
			{
				Color val = (Color)HurtColorField.GetValue(health);
				if (val.a > 0f)
				{
					return val;
				}
			}
		}
		catch
		{
		}
		return Color.white;
	}

	[PunRPC]
	private void MimicDeathFxRPC(Vector3 at)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Blast.Spawn(at, 1.2f);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Alter Mimic: death puff failed: " + ex.Message));
		}
	}

	private void BotHost()
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)target == (Object)null)
		{
			Unlatch("its target left");
			RestoreHidden();
		}
		else if ((Object)(object)bot == (Object)null || (Object)(object)bot.Rig == (Object)null)
		{
			Unlatch("the semibot is gone");
			RestoreHidden();
		}
		else if (Time.time >= nextBotAgent && (Object)(object)nav != (Object)null)
		{
			nextBotAgent = Time.time + 0.3f;
			try
			{
				nav.Stop(0.6f);
				nav.Warp(bot.Feet, true);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogWarning((object)$"Alter Mimic: moving the agent failed: {arg}");
				nextBotAgent = float.MaxValue;
			}
		}
	}

	internal void BotVanished()
	{
		Unlatch("the semibot ran off");
		RestoreHidden();
		R.Info("Alter Mimic: despawns after running off.");
		try
		{
			parent.Despawn();
		}
		catch (Exception arg)
		{
			Plugin.Log.LogWarning((object)$"Alter Mimic: despawning failed: {arg}");
		}
	}

	internal void SayEverywhere(string line)
	{
		Send("MimicSayRPC", line);
	}

	internal void SendOthers(string method, params object[] args)
	{
		if (R.Multiplayer && (Object)(object)view != (Object)null)
		{
			view.RPC(method, (RpcTarget)1, args);
		}
	}

	private void Explode()
	{
		//IL_0001: 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_0022: 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_0079: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: 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_00a4: 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_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		Vector3 bodyPos = BodyPos;
		int value = Settings.ExplosionDamage.Value;
		float value2 = Settings.ExplosionRadius.Value;
		R.Info($"Alter Mimic: grabbed; exploding at {bodyPos} ({value} damage within {value2} m).");
		Send("MimicExplodeRPC", bodyPos);
		foreach (PlayerAvatar item in Living())
		{
			if (!(Vector3.Distance(((Component)item).transform.position + Vector3.up * 0.9f, bodyPos) > value2))
			{
				try
				{
					item.playerHealth.HurtOther(value, bodyPos, false, -1, false);
					R.Info("Alter Mimic: the blast hits " + R.Name(item) + ".");
				}
				catch (Exception arg)
				{
					Plugin.Log.LogWarning((object)$"Alter Mimic: hurting {R.Name(item)} failed: {arg}");
				}
			}
		}
		HashSet<Enemy> hashSet = new HashSet<Enemy>();
		Collider[] array = Physics.OverlapSphere(bodyPos, value2, -1, (QueryTriggerInteraction)1);
		for (int i = 0; i < array.Length; i++)
		{
			EnemyRigidbody componentInParent = ((Component)array[i]).GetComponentInParent<EnemyRigidbody>();
			Enemy val = (((Object)(object)componentInParent != (Object)null) ? componentInParent.enemy : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)enemy || !hashSet.Add(val))
			{
				continue;
			}
			EnemyHealth val2 = ((Component)val).GetComponent<EnemyHealth>() ?? ((Component)val).GetComponentInChildren<EnemyHealth>();
			if (!((Object)(object)val2 == (Object)null))
			{
				try
				{
					Vector3 val3 = ((Component)val).transform.position - bodyPos;
					val2.Hurt(value, ((Vector3)(ref val3)).normalized);
					R.Info("Alter Mimic: the blast hits " + ((Object)val).name + ".");
				}
				catch (Exception arg2)
				{
					Plugin.Log.LogWarning((object)$"Alter Mimic: hurting {((Object)val).name} failed: {arg2}");
				}
			}
		}
		Unlatch("exploded");
		try
		{
			parent.Despawn();
		}
		catch (Exception arg3)
		{
			Plugin.Log.LogWarning((object)$"Alter Mimic: despawning failed: {arg3}");
		}
	}

	private void Unlatch(string why)
	{
		R.Info("Alter Mimic: unlatches (" + why + ").");
		Send("MimicUnlatchRPC");
		ResetHost();
	}

	private void Send(string method, params object[] args)
	{
		if (R.Multiplayer && (Object)(object)view != (Object)null)
		{
			view.RPC(method, (RpcTarget)0, args);
			return;
		}
		MethodInfo method2 = ((object)this).GetType().GetMethod(method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (method2 != null)
		{
			method2.Invoke(this, args);
		}
	}

	[PunRPC]
	private void MimicLatchRPC(int targetView, int newForm, Vector3 at, float yaw)
	{
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: 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)
		EndLocal(null);
		latchedView = targetView;
		form = newForm;
		MimicVoice.Mute(targetView);
		PlayerAvatar val = R.PlayerByView(targetView);
		if (form == 1 && (Object)(object)body != (Object)null)
		{
			foreach (Collider bodyCollider in bodyColliders)
			{
				if ((Object)(object)bodyCollider != (Object)null)
				{
					bodyCollider.enabled = Wanted(bodyCollider, solid: true);
				}
			}
			bodySolid = true;
			head = MimicHead.Create(((Component)body).transform, val, headCollider);
			if (R.IsHost)
			{
				FreeBody(free: true);
			}
			R.Info(string.Format("Alter Mimic: (this game) the head is at {0}{1}.", ((Component)head).transform.position, ((Object)(object)PlayerAvatar.instance != (Object)null) ? $", {Vector3.Distance(((Component)head).transform.position, ((Component)PlayerAvatar.instance).transform.position):0.#} m from you" : ""));
		}
		if (form == 2)
		{
			bot = MimicSemibot.Create(this, val, at, yaw);
		}
		R.Info("Alter Mimic: (this game) latched on to " + R.Name(val) + "; their voice is muted here" + (((Object)(object)val == (Object)(object)PlayerAvatar.instance) ? " for the others (it's you)" : "") + ".");
	}

	[PunRPC]
	private void MimicPossessRPC(bool on)
	{
		possessedLocal = on;
		if ((Object)(object)head != (Object)null)
		{
			head.SetPossessed(on);
		}
	}

	[PunRPC]
	private void MimicSayRPC(string line)
	{
		if ((Object)(object)head != (Object)null)
		{
			head.Say(line, R.PlayerByView(latchedView));
		}
		else if ((Object)(object)bot != (Object)null)
		{
			bot.Speak(line);
		}
	}

	[PunRPC]
	private void MimicBotStateRPC(Vector3 feet, float yaw, float pitch, int flags)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)bot != (Object)null)
		{
			bot.NetState(feet, yaw, pitch, flags);
		}
	}

	[PunRPC]
	private void MimicBotTumbleRPC(Vector3 velocity, Vector3 spin)
	{
		//IL_0014: 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)
		if ((Object)(object)bot != (Object)null)
		{
			bot.TumbleLocal(velocity, spin);
		}
	}

	[PunRPC]
	private void MimicBotStandRPC(Vector3 feet, float yaw)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)bot != (Object)null)
		{
			bot.StandLocal(feet, yaw);
		}
	}

	[PunRPC]
	private void MimicBotGrabRPC(int viewId)
	{
		if (!((Object)(object)bot == (Object)null))
		{
			PhotonView val = ((viewId >= 0) ? PhotonView.Find(viewId) : null);
			bot.GrabLocal(((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<PhysGrabObject>() : null);
		}
	}

	[PunRPC]
	private void MimicBotGunRPC(bool on)
	{
		if ((Object)(object)bot != (Object)null)
		{
			bot.ShowGun(on);
		}
	}

	[PunRPC]
	private void MimicBotShotRPC(Vector3 to, bool hit, bool surface, int damage, bool effects)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)bot != (Object)null)
		{
			bot.Fire(to, hit, surface, damage, effects);
		}
	}

	[PunRPC]
	private void MimicArmRPC(bool on)
	{
		if ((Object)(object)head != (Object)null)
		{
			head.SetArmed(on);
		}
	}

	[PunRPC]
	private void MimicPulseRPC(Vector3 at, float radius)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		MimicFx.Pulse(at, radius);
	}

	[PunRPC]
	private void MimicChargeRPC(float seconds)
	{
		if ((Object)(object)head != (Object)null)
		{
			head.Charge(seconds);
		}
	}

	[PunRPC]
	private void MimicHopRPC(bool longJump)
	{
		if ((Object)(object)head != (Object)null)
		{
			head.Hop(longJump);
		}
	}

	[PunRPC]
	private void MimicExplodeRPC(Vector3 centre)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		MimicFx.Explode(centre);
		EndLocal(null);
	}

	[PunRPC]
	private void MimicUnlatchRPC()
	{
		EndLocal("unlatched");
	}

	private void EndLocal(string why)
	{
		if (latchedView >= 0)
		{
			MimicVoice.Unmute(latchedView);
			if (why != null)
			{
				R.Info("Alter Mimic: (this game) " + why + "; " + R.Name(R.PlayerByView(latchedView)) + " can be heard again.");
			}
		}
		if (R.IsHost)
		{
			FreeBody(free: false);
		}
		latchedView = -1;
		form = 0;
		possessedLocal = false;
		if ((Object)(object)head != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)head).gameObject);
			head = null;
		}
		if ((Object)(object)bot != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)bot).gameObject);
			bot = null;
		}
	}
}
[HarmonyPatch(typeof(PhysGrabObject), "OverrideTimersTick")]
internal static class GrabErrorProbe
{
	private static readonly HashSet<int> reported = new HashSet<int>();

	private static Exception Finalizer(Exception __exception, PhysGrabObject __instance)
	{
		if (__exception == null || (Object)(object)__instance == (Object)null)
		{
			return __exception;
		}
		if (reported.Add(((Object)__instance).GetInstanceID()))
		{
			List<string> list = new List<string>();
			Component[] components = ((Component)__instance).GetComponents<Component>();
			foreach (Component val in components)
			{
				if ((Object)(object)val != (Object)null)
				{
					list.Add(((object)val).GetType().Name);
				}
			}
			bool flag = (Object)(object)((Component)__instance).GetComponentInParent<EnemyParent>() != (Object)null && ((Component)__instance).GetComponentInParent<EnemyParent>().enemyName == "Alter Mimic";
			ManualLogSource log = Plugin.Log;
			string[] obj = new string[12]
			{
				"Alter Mimic (diagnostics): OverrideTimersTick failed on '",
				((Object)((Component)__instance).transform.root).name,
				"/",
				((Object)__instance).name,
				"' (",
				flag ? "the Alter Mimic" : "not the mimic",
				"): ",
				string.Join(", ", list),
				". ",
				__exception.GetType().Name,
				": ",
				null
			};
			string? stackTrace = __exception.StackTrace;
			obj[11] = ((stackTrace != null) ? stackTrace.Split('\n')[0] : null);
			log.LogWarning((object)string.Concat(obj));
		}
		return __exception;
	}
}
internal static class MimicBuilder
{
	internal const string DisplayName = "Alter Mimic";

	private const string SourcePath = "Enemies/Enemy - Hidden";

	internal static EnemySetup Setup;

	private static GameObject holder;

	internal static void BuildAndRegister()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_0192: 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_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Resources.Load<GameObject>("Enemies/Enemy - Hidden");
		if ((Object)(object)val == (Object)null)
		{
			Plugin.Log.LogError((object)"Alter Mimic: 'Enemies/Enemy - Hidden' not found; it will not spawn.");
			return;
		}
		if ((Object)(object)holder == (Object)null)
		{
			holder = new GameObject("HatterEnemiesPack.Prefabs");
			holder.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)holder);
			((Object)holder).hideFlags = (HideFlags)61;
		}
		GameObject val2 = Object.Instantiate<GameObject>(val, holder.transform);
		((Object)val2).name = "Enemy - Alter Mimic";
		Plugin.Log.LogInfo((object)("Alter Mimic: the Hidden enemy's parts:\n" + Describe(val2.transform, 0)));
		List<string> list = new List<string>();
		MonoBehaviour[] componentsInChildren = val2.GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val3 in componentsInChildren)
		{
			if (!((Object)(object)val3 == (Object)null))
			{
				string name = ((object)val3).GetType().Name;
				if (name.StartsWith("EnemyHidden"))
				{
					list.Add(name + " on '" + ((Object)val3).name + "'");
					Object.DestroyImmediate((Object)(object)val3);
				}
			}
		}
		Plugin.Log.LogInfo((object)("Alter Mimic: removed " + string.Join(", ", list)));
		Renderer[] componentsInChildren2 = val2.GetComponentsInChildren<Renderer>(true);
		for (int i = 0; i < componentsInChildren2.Length; i++)
		{
			componentsInChildren2[i].enabled = false;
		}
		Light[] componentsInChildren3 = val2.GetComponentsInChildren<Light>(true);
		for (int i = 0; i < componentsInChildren3.Length; i++)
		{
			((Behaviour)componentsInChildren3[i]).enabled = false;
		}
		ParticleSystem[] componentsInChildren4 = val2.GetComponentsInChildren<ParticleSystem>(true);
		foreach (ParticleSystem obj in componentsInChildren4)
		{
			EmissionModule emission = obj.emission;
			((EmissionModule)(ref emission)).enabled = false;
			obj.Stop(true, (ParticleSystemStopBehavior)0);
		}
		AudioSource[] componentsInChildren5 = val2.GetComponentsInChildren<AudioSource>(true);
		foreach (AudioSource obj2 in componentsInChildren5)
		{
			obj2.volume = 0f;
			obj2.mute = true;
		}
		EnemyParent val4 = val2.GetComponent<EnemyParent>() ?? val2.GetComponentInChildren<EnemyParent>(true);
		Enemy componentInChildren = val2.GetComponentInChildren<Enemy>(true);
		if ((Object)(object)val4 == (Object)null || (Object)(object)componentInChildren == (Object)null)
		{
			Plugin.Log.LogError((object)"Alter Mimic: the Hidden enemy has no EnemyParent/Enemy; it will not spawn.");
			return;
		}
		val4.enemyName = "Alter Mimic";
		val4.difficulty = (Difficulty)1;
		((Component)componentInChildren).gameObject.AddComponent<AlterMimic>();
		ManualLogSource log = Plugin.Log;
		string[] obj3 = new string[6]
		{
			string.Format("{0}: Hidden's spawn times {1}-{2} s, despawn {3}-{4} s; ", "Alter Mimic", val4.SpawnedTimeMin, val4.SpawnedTimeMax, val4.DespawnedTimeMin, val4.DespawnedTimeMax),
			"behaviour on '",
			((Object)componentInChildren).name,
			"'; rigidbody '",
			null,
			null
		};
		EnemyRigidbody componentInChildren2 = val2.GetComponentInChildren<EnemyRigidbody>(true);
		obj3[4] = ((componentInChildren2 != null) ? ((Object)componentInChildren2).name : null);
		obj3[5] = "'.";
		log.LogInfo((object)string.Concat(obj3));
		EnemySetup val5 = ScriptableObject.CreateInstance<EnemySetup>();
		((Object)val5).name = "Enemy - Alter Mimic";
		val5.status = (Status)1;
		val5.spawnObjects = new List<PrefabRef>();
		Setup = val5;
		EnemyContent val6 = ScriptableObject.CreateInstance<EnemyContent>();
		((Object)val6).name = "Alter Mimic Content";
		AccessTools.Field(typeof(EnemyContent), "_setup").SetValue(val6, val5);
		AccessTools.Field(typeof(EnemyContent), "_spawnObjects").SetValue(val6, new List<GameObject> { val2 });
		Enemies.RegisterEnemy(val6);
		Plugin.Log.LogInfo((object)string.Format("{0}: registered as a tier 2 enemy ({1} spawn object(s)).", "Alter Mimic", val5.spawnObjects.Count));
	}

	private static string Describe(Transform t, int depth)
	{
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Expected O, but got Unknown
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append(' ', depth * 2).Append(((Object)t).name).Append(((Component)t).gameObject.activeSelf ? "" : " (off)")
			.Append(": ");
		List<string> list = new List<string>();
		Component[] components = ((Component)t).GetComponents<Component>();
		foreach (Component val in components)
		{
			if ((Object)(object)val != (Object)null && !(val is Transform))
			{
				list.Add(((object)val).GetType().Name);
			}
		}
		stringBuilder.Append(string.Join(", ", list)).Append('\n');
		if (depth < 6)
		{
			foreach (Transform item in t)
			{
				Transform t2 = item;
				stringBuilder.Append(Describe(t2, depth + 1));
			}
		}
		return stringBuilder.ToString();
	}
}
[HarmonyPatch(typeof(EnemyDirector), "PickEnemies")]
internal static class MimicPickPatch
{
	private static void Prefix(ref List<EnemySetup> _enemiesList)
	{
		if (!((Object)(object)MimicBuilder.Setup == (Object)null) && _enemiesList != null && _enemiesList.Contains(MimicBuilder.Setup) && !R.Multiplayer && !Settings.DebugSolo.Value)
		{
			List<EnemySetup> list = new List<EnemySetup>(_enemiesList);
			list.Remove(MimicBuilder.Setup);
			_enemiesList = list;
		}
	}
}
internal class MimicDebug : MonoBehaviour
{
	internal static void Create()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("HatterEnemiesPack.Debug");
		Object.DontDestroyOnLoad((Object)val);
		((Object)val).hideFlags = (HideFlags)61;
		val.AddComponent<MimicDebug>();
	}

	private void Update()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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)
		KeyboardShortcut value = Settings.DebugSpawnKey.Value;
		if ((int)((KeyboardShortcut)(ref value)).MainKey != 0 && ((KeyboardShortcut)(ref value)).IsDown())
		{
			if (!R.IsHost || !SemiFunc.RunIsLevel() || (Object)(object)MimicBuilder.Setup == (Object)null || (Object)(object)PlayerAvatar.instance == (Object)null)
			{
				Plugin.Log.LogInfo((object)"Alter Mimic: the spawn key only works for the host, in a level.");
				return;
			}
			Vector3 position = ((Component)PlayerAvatar.instance).transform.position;
			LevelPoint val = SemiFunc.LevelPointGet(position, 3f, 15f);
			Vector3 val2 = (((Object)(object)val != (Object)null) ? ((Component)val).transform.position : (position + ((Component)PlayerAvatar.instance).transform.forward * 3f));
			List<EnemyParent> list = Enemies.SpawnEnemy(MimicBuilder.Setup, val2, Quaternion.identity, false);
			Plugin.Log.LogInfo((object)string.Format("Alter Mimic: debug spawn at {0}: {1}.", val2, (list != null && list.Count > 0) ? "done" : "failed"));
		}
	}
}
internal static class MimicFx
{
	private static ParticleScriptExplosion effects;

	private static readonly FieldInfo PrefabField = AccessTools.Field(typeof(ParticleScriptExplosion), "explosionPrefab");

	private static Material soft;

	private static Sound pulseSound;

	private static bool pulseSoundTried;

	internal static Material Soft
	{
		get
		{
			//IL_0019: 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_0026: Expected O, but got Unknown
			//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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)soft != (Object)null)
			{
				return soft;
			}
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)j + 0.5f) / 64f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 64f * 2f - 1f;
					float num3 = Mathf.Clamp01(1f - Mathf.Sqrt(num * num + num2 * num2));
					val.SetPixel(j, i, new Color(1f, 1f, 1f, num3 * num3));
				}
			}
			val.Apply();
			((Object)val).hideFlags = (HideFlags)32;
			soft = new Material(Shader.Find("Sprites/Default"))
			{
				mainTexture = (Texture)(object)val,
				hideFlags = (HideFlags)32
			};
			return soft;
		}
	}

	internal static void Warm()
	{
		try
		{
			Effects();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Alter Mimic: preparing the explosion failed: " + ex.Message));
		}
	}

	private static ParticleScriptExplosion Effects()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)effects != (Object)null)
		{
			return effects;
		}
		GameObject val = new GameObject("HatterEnemiesPack.Explosions");
		Object.DontDestroyOnLoad((Object)val);
		((Object)val).hideFlags = (HideFlags)61;
		GameObject val2 = Resources.Load<GameObject>("Items/Item Grenade Explosive");
		ParticleScriptExplosion val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponentInChildren<ParticleScriptExplosion>(true) : null);
		effects = val.AddComponent<ParticleScriptExplosion>();
		if ((Object)(object)val3 != (Object)null)
		{
			effects.explosionPreset = val3.explosionPreset;
		}
		else
		{
			Plugin.Log.LogWarning((object)"Alter Mimic: the explosive grenade wasn't found; the explosion uses only its own effects.");
		}
		GameObject val4 = Resources.Load<GameObject>("Effects/Part Prefab Explosion");
		if (PrefabField != null && (Object)(object)val4 != (Object)null)
		{
			PrefabField.SetValue(effects, val4);
		}
		else
		{
			Plugin.Log.LogWarning((object)"Alter Mimic: the game's explosion prefab wasn't found; only the mod's own blast shows.");
		}
		return effects;
	}

	internal static void Explode(Vector3 centre)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		float value = Settings.ExplosionRadius.Value;
		try
		{
			ParticleScriptExplosion val = Effects();
			if ((Object)(object)val.explosionPreset != (Object)null)
			{
				val.Spawn(centre, Mathf.Clamp(value * 0.6f, 1.5f, 5f), 0, 0, 0f, true, false, 5f, 15f);
				for (int i = 0; i < 5; i++)
				{
					float num = (float)i * MathF.PI * 2f / 5f + Random.Range(-0.3f, 0.3f);
					Vector3 val2 = new Vector3(Mathf.Cos(num), Random.Range(0.1f, 0.6f), Mathf.Sin(num)) * value * 0.3f;
					val.Spawn(centre + val2, Mathf.Clamp(value * 0.3f, 0.8f, 2.5f), 0, 0, 0f, true, true, 0f, 0f);
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogWarning((object)$"Alter Mimic: the game's explosion effect failed: {arg}");
		}
		try
		{
			Blast.Spawn(centre, value);
		}
		catch (Exception arg2)
		{
			Plugin.Log.LogWarning((object)$"Alter Mimic: explosion effect failed: {arg2}");
		}
	}

	private static Sound PulseSound()
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		if (pulseSoundTried)
		{
			return pulseSound;
		}
		pulseSoundTried = true;
		AudioClip val = SoundLibrary.Get("orb_shockwave.pcm");
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		GameObject obj = Resources.Load<GameObject>("Items/Item Gun Shotgun");
		Sound val2 = ((obj == null) ? null : obj.GetComponent<ItemGun>()?.soundShoot);
		Sound val3 = new Sound();
		if (val2 != null)
		{
			Sound.CopySound(val2, val3);
		}
		val3.Sounds = (AudioClip[])(object)new AudioClip[1] { val };
		val3.Volume = 1f;
		val3.VolumeRandom = 0f;
		val3.Pitch = 1f;
		val3.PitchRandom = 0f;
		pulseSound = val3;
		return val3;
	}

	internal static void Pulse(Vector3 at, float radius)
	{
		//IL_000b: 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)
		try
		{
			Sound obj = PulseSound();
			if (obj != null)
			{
				obj.Play(at, 1f, 1f, 1f, 1f);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Alter Mimic: pulse sound failed: " + ex.Message));
		}
		try
		{
			PulseFx.Spawn(at, radius);
		}
		catch (Exception ex2)
		{
			Plugin.Log.LogWarning((object)("Alter Mimic: pulse effect failed: " + ex2.Message));
		}
	}
}
internal class Blast : MonoBehaviour
{
	private Light flash;

	private float t;

	private float range;

	internal static void Spawn(Vector3 at, float radius)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Alter Mimic Blast");
		val.transform.position = at;
		val.AddComponent<Blast>().Setup(radius);
	}

	private void Setup(float radius)
	{
		//IL_0049: 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_0095: 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_00ba: 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_00ec: 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_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		range = Mathf.Max(8f, radius * 3f);
		flash = ((Component)this).gameObject.AddComponent<Light>();
		flash.type = (LightType)2;
		flash.color = new Color(1f, 0.6f, 0.25f);
		flash.range = range;
		flash.intensity = 10f;
		Burst("Fire", 45, new Vector2(0.35f, 0.7f), new Vector2(2f, 7f), new Vector2(1.2f, 2.4f) * Mathf.Max(1f, radius * 0.3f), new Color(1f, 0.75f, 0.3f, 1f), new Color(0.9f, 0.2f, 0.02f, 0f), -0.2f, radius * 0.15f);
		Burst("Sparks", 70, new Vector2(0.4f, 1.1f), new Vector2(6f, 16f), new Vector2(0.03f, 0.08f), new Color(1f, 0.85f, 0.4f, 1f), new Color(1f, 0.35f, 0.05f, 0f), 1.2f, 0.1f);
		Burst("Smoke", 40, new Vector2(1.8f, 3.2f), new Vector2(0.6f, 2.5f), new Vector2(0.8f, 1.8f) * Mathf.Max(1f, radius * 0.35f), new Color(0.25f, 0.23f, 0.22f, 0.7f), new Color(0.15f, 0.15f, 0.15f, 0f), -0.08f, radius * 0.25f);
	}

	private void Burst(string name, int count, Vector2 life, Vector2 speed, Vector2 size, Color from, Color to, float gravity, float shapeRadius)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//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_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Expected O, but got Unknown
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: 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_0187: 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_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Expected O, but got Unknown
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		val.transform.SetParent(((Component)this).transform, false);
		ParticleSystem val2 = val.AddComponent<ParticleSystem>();
		val2.Stop(true, (ParticleSystemStopBehavior)0);
		MainModule main = val2.main;
		((MainModule)(ref main)).duration = 0.2f;
		((MainModule)(ref main)).loop = false;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(life.x, life.y);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(speed.x, speed.y);
		((MainModule)(ref main)).startSize = new MinMaxCurve(size.x, size.y);
		((MainModule)(ref main)).startRotation = new MinMaxCurve(0f, MathF.PI * 2f);
		((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(from);
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(gravity);
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		((MainModule)(ref main)).maxParticles = count * 2;
		EmissionModule emission = val2.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
		((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
		{
			new Burst(0f, (short)count)
		});
		ShapeModule shape = val2.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
		((ShapeModule)(ref shape)).radius = Mathf.Max(0.05f, shapeRadius);
		ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val3 = new Gradient();
		val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(from, 0f),
			new GradientColorKey(to, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
		{
			new GradientAlphaKey(from.a, 0f),
			new GradientAlphaKey(from.a * 0.6f, 0.5f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
		SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, new AnimationCurve((Keyframe[])(object)new Keyframe[2]
		{
			new Keyframe(0f, 0.6f),
			new Keyframe(1f, (name == "Smoke") ? 1.8f : ((name == "Fire") ? 1.6f : 0.2f))
		}));
		LimitVelocityOverLifetimeModule limitVelocityOverLifetime = val2.limitVelocityOverLifetime;
		((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).enabled = true;
		((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).dampen = ((name == "Smoke") ? 0.15f : ((name == "Fire") ? 0.3f : 0.05f));
		((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limit = MinMaxCurve.op_Implicit((name == "Smoke") ? 0.8f : ((name == "Fire") ? 1.5f : 4f));
		ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
		((Renderer)component).sharedMaterial = MimicFx.Soft;
		((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)component).receiveShadows = false;
		val2.Play();
	}

	private void Update()
	{
		t += Time.deltaTime;
		if ((Object)(object)flash != (Object)null)
		{
			flash.intensity = 16f * Mathf.Clamp01(1f - t / 0.8f) * Random.Range(0.85f, 1.15f);
		}
		if (t >= 4f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
}
internal class PulseFx : MonoBehaviour
{
	private const float Life = 0.45f;

	private const float Grey = 0.45f;

	private const float Alpha = 0.06f;

	private float t;

	private float radius;

	private Material mat;

	private Light glow;

	internal static void Spawn(Vector3 at, float radius)
	{
		//IL_002d: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
		((Object)obj).name = "Alter Mimic Pulse";
		Collider component = obj.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.Destroy((Object)(object)component);
		}
		obj.transform.position = at;
		obj.transform.localScale = Vector3.one * 0.2f;
		obj.AddComponent<PulseFx>().Setup(radius);
	}

	private void Setup(float r)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		radius = r;
		MeshRenderer component = ((Component)this).GetComponent<MeshRenderer>();
		mat = new Material(Shader.Find("Sprites/Default"))
		{
			color = new Color(0.45f, 0.45f, 0.45f, 0.06f)
		};
		((Renderer)component).sharedMaterial = mat;
		((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)component).receiveShadows = false;
		glow = ((Component)this).gameObject.AddComponent<Light>();
		glow.type = (LightType)2;
		glow.color = new Color(0.6f, 0.6f, 0.62f);
		glow.range = Mathf.Max(3f, radius * 1.5f);
		glow.intensity = 0.8f;
	}

	private void Update()
	{
		//IL_0040: 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_0096: Unknown result type (might be due to invalid IL or missing references)
		t += Time.deltaTime;
		float num = Mathf.Clamp01(t / 0.45f);
		float num2 = 1f - (1f - num) * (1f - num);
		((Component)this).transform.localScale = Vector3.one * Mathf.Lerp(0.2f, radius * 2f, num2);
		if ((Object)(object)mat != (Object)null)
		{
			mat.color = new Color(0.45f, 0.45f, 0.45f, 0.06f * (1f - num));
		}
		if ((Object)(object)glow != (Object)null)
		{
			glow.intensity = 0.8f * (1f - num);
		}
		if (t >= 0.45f)
		{
			if ((Object)(object)mat != (Object)null)
			{
				Object.Destroy((Object)(object)mat);
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
}
internal class MimicGun : MonoBehaviour
{
	internal const string GunPath = "Items/Item Gun Shotgun";

	private static bool read;

	private static GameObject bulletPrefab;

	private static GameObject flashPrefab;

	private static Sound soundShoot;

	private static Sound soundShootGlobal;

	private static Sound soundHit;

	private static AnimationCurve lineCurve;

	private static int enemyDamage = 25;

	private static int playerDamage = 25;

	private static int pellets = 6;

	private static float spread = 10f;

	private static float range = 50f;

	private Transform muzzle;

	private Quaternion muzzleToRoot = Quaternion.identity;

	private Vector3 muzzleLocal;

	internal static int PelletPlayerDamage
	{
		get
		{
			Read();
			return playerDamage;
		}
	}

	internal static int Pellets
	{
		get
		{
			Read();
			return pellets;
		}
	}

	internal static float Spread
	{
		get
		{
			Read();
			return spread;
		}
	}

	internal static float Range
	{
		get
		{
			Read();
			return range;
		}
	}

	internal Vector3 Muzzle
	{
		get
		{
			//IL_0026: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)muzzle != (Object)null))
			{
				return ((Component)this).transform.TransformPoint(muzzleLocal);
			}
			return muzzle.position;
		}
	}

	private static void Read()
	{
		if (read)
		{
			return;
		}
		read = true;
		GameObject val = Resources.Load<GameObject>("Items/Item Gun Shotgun");
		ItemGun val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemGun>() : null);
		if ((Object)(object)val2 == (Object)null)
		{
			Plugin.Log.LogWarning((object)"Alter Mimic: no shotgun at Items/Item Gun Shotgun; the semibot can't shoot.");
			return;
		}
		pellets = Mathf.Max(1, val2.numberOfBullets);
		spread = val2.gunRandomSpread;
		range = ((val2.gunRange > 1f) ? val2.gunRange : 50f);
		bulletPrefab = val2.bulletPrefab;
		flashPrefab = val2.muzzleFlashPrefab;
		soundShoot = val2.soundShoot;
		soundShootGlobal = val2.soundShootGlobal;
		soundHit = val2.soundHit;
		lineCurve = val2.shootLineWidthCurve;
		HurtCollider val3 = (((Object)(object)bulletPrefab != (Object)null) ? bulletPrefab.GetComponentInChildren<HurtCollider>(true) : null);
		if ((Object)(object)val3 != (Object)null && val3.enemyDamage > 0)
		{
			enemyDamage = val3.enemyDamage;
		}
		if ((Object)(object)val3 != (Object)null && val3.playerDamage > 0)
		{
			playerDamage = val3.playerDamage;
		}
		R.Info(string.Format("Alter Mimic: the shotgun: bullet {0}, {1} pellet(s), spread {2:0.#}°, range {3:0} m, per pellet: enemy damage {4}, player damage {5}; muzzle flash {6}.", ((Object)(object)bulletPrefab != (Object)null) ? ((Object)bulletPrefab).name : "NONE", pellets, spread, range, enemyDamage, playerDamage, ((Object)(object)flashPrefab != (Object)null) ? "yes" : "no"));
	}

	internal static MimicGun Create()
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Expected O, but got Unknown
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		Read();
		GameObject val = Resources.Load<GameObject>("Items/Item Gun Shotgun");
		ItemGun val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemGun>() : null);
		if ((Object)(object)val2 == (Object)null)
		{
			return null;
		}
		string text = Path(val.transform, val2.gunMuzzle);
		Vector3 val3 = (((Object)(object)val2.gunMuzzle != (Object)null) ? val.transform.InverseTransformPoint(val2.gunMuzzle.position) : (Vector3.forward * 0.25f));
		Quaternion val4 = (((Object)(object)val2.gunMuzzle != (Object)null) ? (Quaternion.Inverse(val.transform.rotation) * val2.gunMuzzle.rotation) : Quaternion.identity);
		GameObject val5 = new GameObject("Alter Mimic Gun (building)");
		val5.SetActive(false);
		GameObject val6 = Object.Instantiate<GameObject>(val, val5.transform);
		((Object)val6).name = "Alter Mimic Gun";
		for (int i = 0; i < 4; i++)
		{
			Component[] componentsInChildren = val6.GetComponentsInChildren<Component>(true);
			foreach (Component val7 in componentsInChildren)
			{
				if (!((Object)(object)val7 == (Object)null) && !(val7 is Transform) && !(val7 is MeshFilter) && !(val7 is Renderer) && (i >= 2 || val7 is MonoBehaviour) && (i != 2 || val7 is Joint || val7 is Collider))
				{
					try
					{
						Object.DestroyImmediate((Object)(object)val7);
					}
					catch
					{
					}
				}
			}
		}
		int layer = LayerMask.NameToLayer("Default");
		Transform[] componentsInChildren2 = val6.GetComponentsInChildren<Transform>(true);
		for (int j = 0; j < componentsInChildren2.Length; j++)
		{
			((Component)componentsInChildren2[j]).gameObject.layer = layer;
		}
		List<string> list = new List<string>();
		List<string> list2 = new List<string>();
		Renderer[] componentsInChildren3 = val6.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val8 in componentsInChildren3)
		{
			if ((Object)(object)val8 == (Object)null)
			{
				continue;
			}
			string text2 = null;
			if (!(val8 is MeshRenderer) && !(val8 is SkinnedMeshRenderer))
			{
				text2 = ((object)val8).GetType().Name;
			}
			else if (!val8.enabled || !((Component)val8).gameObject.activeSelf || !ActiveUnder(((Component)val8).transform, val6.transform))
			{
				text2 = "off in the prefab";
			}
			else
			{
				SkinnedMeshRenderer val9 = (SkinnedMeshRenderer)(object)((val8 is SkinnedMeshRenderer) ? val8 : null);
				object obj2;
				if (val9 == null)
				{
					MeshFilter component = ((Component)val8).GetComponent<MeshFilter>();
					obj2 = ((component != null) ? component.sharedMesh : null);
				}
				else
				{
					obj2 = val9.sharedMesh;
				}
				Mesh val10 = (Mesh)obj2;
				Vector3 val11;
				if (!((Object)(object)val10 != (Object)null))
				{
					val11 = Vector3.zero;
				}
				else
				{
					Bounds bounds = val10.bounds;
					val11 = Vector3.Scale(((Bounds)(ref bounds)).size, Abs(((Component)val8).transform.lossyScale));
				}
				Vector3 val12 = val11;
				if ((Object)(object)val10 == (Object)null)
				{
					text2 = "no mesh";
				}
				else if (((Vector3)(ref val12)).magnitude > 2f)
				{
					text2 = $"too big ({((Vector3)(ref val12)).magnitude:0.#} m)";
				}
			}
			if (text2 != null)
			{
				list2.Add(((Object)val8).name + " [" + text2 + "]");
				try
				{
					Object.DestroyImmediate((Object)(object)val8);
				}
				catch
				{
					val8.enabled = false;
				}
			}
			else
			{
				val8.shadowCastingMode = (ShadowCastingMode)1;
				list.Add(((Object)val8).name);
			}
		}
		R.Info("Alter Mimic: the gun copy shows [" + string.Join(", ", list) + "]; removed [" + string.Join(", ", list2) + "].");
		val6.SetActive(false);
		val6.transform.SetParent((Transform)null, false);
		Object.Destroy((Object)(object)val5);
		MimicGun mimicGun = val6.AddComponent<MimicGun>();
		mimicGun.muzzle = ((text == null) ? null : ((text.Length == 0) ? val6.transform : val6.transform.Find(text)));
		mimicGun.muzzleLocal = val3;
		mimicGun.muzzleToRoot = Quaternion.Inverse(val4);
		return mimicGun;
	}

	private static bool ActiveUnder(Transform t, Transform root)
	{
		while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
		{
			if (!((Component)t).gameObject.activeSelf)
			{
				return false;
			}
			t = t.parent;
		}
		return tru