Decompiled source of LethalGargoyles v0.0.5

plugins/LethalGargoyles/DropDaDeuce.LethalGargoyles.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DropDaDeuce.LethalGargoyles.NetcodePatcher;
using GameNetcodeStuff;
using HarmonyLib;
using LethalGargoyles.Configuration;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DropDaDeuce.LethalGargoyles")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.5.0")]
[assembly: AssemblyInformationalVersion("0.0.5+fd3cd7e889caf1c3f580751814861e33773e605a")]
[assembly: AssemblyProduct("LethalGargoyles")]
[assembly: AssemblyTitle("DropDaDeuce.LethalGargoyles")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LethalGargoyles
{
	[BepInPlugin("DropDaDeuce.LethalGargoyles", "LethalGargoyles", "0.0.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger = null;

		public static AssetBundle? ModAssets;

		public static List<AudioClip> tauntClips = new List<AudioClip>();

		public static List<AudioClip> aggroClips = new List<AudioClip>();

		public static List<AudioClip> hideClips = new List<AudioClip>();

		public static List<AudioClip> seenClips = new List<AudioClip>();

		public static List<AudioClip> enemyClips = new List<AudioClip>();

		public static List<AudioClip> playerDeathClips = new List<AudioClip>();

		public static List<AudioClip> deathClips = new List<AudioClip>();

		public static List<AudioClip> priorDeathClips = new List<AudioClip>();

		public static List<AudioClip> activityClips = new List<AudioClip>();

		public static Plugin Instance { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		internal static PluginConfig BoundConfig { get; private set; } = null;


		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
			InitializeNetworkBehaviours();
			string path = "gargoyleassets";
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			EnemyType val = ModAssets.LoadAsset<EnemyType>("LethalGargoyle");
			TerminalNode val2 = ModAssets.LoadAsset<TerminalNode>("LethalGargoyleTN");
			TerminalKeyword val3 = ModAssets.LoadAsset<TerminalKeyword>("LethalGargoyleTK");
			Logger.LogInfo((object)"Loading audio clips");
			LoadClips();
			NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
			Enemies.RegisterEnemy(val, BoundConfig.SpawnWeight.Value, (LevelTypes)(-1), val2, val3);
			Instance = this;
			Logger.LogInfo((object)"Plugin DropDaDeuce.LethalGargoyles is loaded!");
		}

		private static void InitializeNetworkBehaviours()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		private void LoadClips()
		{
			if (!((Object)(object)ModAssets != (Object)null))
			{
				return;
			}
			AudioClip[] array = ModAssets.LoadAllAssets<AudioClip>();
			AudioClip[] array2 = array;
			foreach (AudioClip val in array2)
			{
				if (((Object)val).name.StartsWith("taunt_general"))
				{
					tauntClips.Add(val);
				}
				else if (((Object)val).name.StartsWith("taunt_aggro"))
				{
					aggroClips.Add(val);
				}
				else if (((Object)val).name.StartsWith("taunt_seen"))
				{
					seenClips.Add(val);
				}
				else if (((Object)val).name.StartsWith("taunt_hide"))
				{
					hideClips.Add(val);
				}
				else if (((Object)val).name.StartsWith("taunt_enemy"))
				{
					tauntClips.Add(val);
				}
				else if (((Object)val).name.StartsWith("taunt_playerdeath"))
				{
					playerDeathClips.Add(val);
				}
				else if (((Object)val).name.StartsWith("taunt_death"))
				{
					deathClips.Add(val);
				}
				else if (((Object)val).name.StartsWith("taunt_priordeath"))
				{
					priorDeathClips.Add(val);
				}
				else if (((Object)val).name.StartsWith("taunt_activity"))
				{
					activityClips.Add(val);
				}
			}
		}
	}
	public class LethalGargoylesAI : EnemyAI
	{
		private enum State
		{
			SearchingForPlayer,
			StealthyPursuit,
			GetOutOfSight,
			AggressivePursuit,
			Idle
		}

		public Transform turnCompass;

		public Transform attackArea;

		private PlayerControllerB closestPlayer;

		private float randGenTauntTime;

		private float randAgrTauntTime;

		private float lastGenTauntTime;

		private float lastAgrTauntTime;

		private int lastGenTaunt = -1;

		private int lastAgrTaunt = -1;

		private float timeSinceHittingPlayer;

		private float distanceToPlayer;

		private float distanceToClosestPlayer;

		private float idleDistance;

		private Vector3 lastPosition = Vector3.zero;

		private Vector3 curPosition = Vector3.zero;

		private string? lastEnemy;

		public AISearchRoutine? searchForPlayers;

		private float baseSpeed;

		private float attackRange;

		private int attackDamage;

		private float aggroRange;

		private int minTaunt;

		private int maxTaunt;

		private float distWarn;

		private float bufferDist;

		private float awareDist;

		[Conditional("DEBUG")]
		private void LogIfDebugBuild(string text)
		{
			Plugin.Logger.LogInfo((object)text);
		}

		public override void Start()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Start();
			DoAnimationClientRpc("startWalk");
			((EnemyAI)this).SwitchToBehaviourClientRpc(0);
			((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
			baseSpeed = Plugin.BoundConfig.baseSpeed.Value;
			attackRange = Plugin.BoundConfig.attackRange.Value;
			attackDamage = Plugin.BoundConfig.attackDamage.Value;
			aggroRange = Plugin.BoundConfig.aggroRange.Value;
			idleDistance = Plugin.BoundConfig.idleDistance.Value;
			minTaunt = Plugin.BoundConfig.minTaunt.Value;
			maxTaunt = Plugin.BoundConfig.maxTaunt.Value;
			distWarn = Plugin.BoundConfig.distWarn.Value;
			bufferDist = Plugin.BoundConfig.bufferDist.Value;
			awareDist = Plugin.BoundConfig.awareDist.Value;
			AudioSource creatureVoice = base.creatureVoice;
			creatureVoice.maxDistance *= 4f;
		}

		public override void Update()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: 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_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0566: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			if (base.isEnemyDead)
			{
				return;
			}
			closestPlayer = ((EnemyAI)this).GetClosestPlayer(false, false, false);
			distanceToPlayer = (((Object)(object)base.targetPlayer != (Object)null) ? Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) : 0f);
			distanceToClosestPlayer = (((Object)(object)closestPlayer != (Object)null) ? Vector3.Distance(((Component)this).transform.position, ((Component)closestPlayer).transform.position) : 0f);
			if ((Object)(object)base.targetPlayer != (Object)null && !base.isOutside && !base.targetPlayer.isInsideFactory)
			{
				((EnemyAI)this).SwitchToBehaviourClientRpc(0);
			}
			bool flag = false;
			bool flag2 = false;
			if (distanceToClosestPlayer <= awareDist)
			{
				flag2 = GargoyleIsSeen(((Component)this).transform);
				if (flag2 && base.currentBehaviourStateIndex != 3)
				{
					if ((Object)(object)base.targetPlayer != (Object)null)
					{
						if (distanceToPlayer <= aggroRange)
						{
							((EnemyAI)this).SwitchToBehaviourClientRpc(3);
						}
						else
						{
							((EnemyAI)this).SwitchToBehaviourClientRpc(2);
						}
					}
					else
					{
						((EnemyAI)this).SwitchToBehaviourClientRpc(2);
					}
				}
			}
			else if (!flag2 && distanceToPlayer <= idleDistance && base.currentBehaviourStateIndex != 3 && base.currentBehaviourStateIndex != 0)
			{
				((EnemyAI)this).SwitchToBehaviourClientRpc(4);
			}
			switch (base.currentBehaviourStateIndex)
			{
			case 4:
				base.agent.speed = 0f;
				if (!((Object)(object)base.targetPlayer != (Object)null))
				{
					break;
				}
				LookAtTarget(((Component)base.targetPlayer).transform.position);
				if (!base.targetPlayer.isInsideFactory)
				{
					((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
					lastGenTauntTime = 0f;
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
					break;
				}
				if (Time.time - lastGenTauntTime >= randGenTauntTime && ((NetworkBehaviour)this).IsHost)
				{
					Taunt();
				}
				if (!flag2 && distanceToPlayer > idleDistance)
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				break;
			case 0:
				base.agent.speed = baseSpeed * 1.5f;
				SearchForPlayers();
				if (FoundClosestPlayerInRange())
				{
					((EnemyAI)this).StopSearch(base.currentSearch, true);
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				break;
			case 1:
				base.agent.speed = baseSpeed;
				if ((Object)(object)base.targetPlayer != (Object)null)
				{
					if (!base.targetPlayer.isInsideFactory)
					{
						((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
						lastGenTauntTime = 0f;
						((EnemyAI)this).SwitchToBehaviourClientRpc(0);
						break;
					}
					base.creatureSFX.volume = 0.5f;
					if (!SetDestinationToHiddenPosition() && distanceToPlayer < idleDistance)
					{
						((EnemyAI)this).SwitchToBehaviourClientRpc(3);
					}
					else if (Time.time - lastGenTauntTime >= randGenTauntTime && ((NetworkBehaviour)this).IsHost)
					{
						Taunt();
					}
				}
				else
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				}
				break;
			case 3:
			{
				base.agent.speed = baseSpeed * 2.5f;
				if (!((Object)(object)base.targetPlayer != (Object)null))
				{
					break;
				}
				if (!base.targetPlayer.isInsideFactory)
				{
					((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
					lastAgrTauntTime = 0f;
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
					break;
				}
				base.creatureSFX.volume = 1.5f;
				bool flag3 = CanSeePlayer(base.targetPlayer);
				if (distanceToPlayer > aggroRange && distanceToClosestPlayer > aggroRange && SetDestinationToHiddenPosition())
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(2);
				}
				if (!FoundClosestPlayerInRange())
				{
					break;
				}
				if (Time.time - lastAgrTauntTime >= randAgrTauntTime && ((NetworkBehaviour)this).IsHost)
				{
					OtherTaunt("aggro", ref lastAgrTaunt, ref lastAgrTauntTime, ref randAgrTauntTime);
				}
				((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
				timeSinceHittingPlayer += Time.deltaTime;
				if (timeSinceHittingPlayer >= 1f && flag3)
				{
					if (distanceToPlayer < attackRange)
					{
						LookAtTarget(((Component)base.targetPlayer).transform.position);
						AttackPlayer(base.targetPlayer);
					}
					else if (distanceToClosestPlayer < attackRange && (Object)(object)closestPlayer != (Object)null)
					{
						base.targetPlayer = closestPlayer;
						LookAtTarget(((Component)base.targetPlayer).transform.position);
						AttackPlayer(base.targetPlayer);
					}
					else
					{
						((EnemyAI)this).SwitchToBehaviourClientRpc(2);
					}
				}
				break;
			}
			case 2:
				base.agent.speed = baseSpeed * 1.5f;
				if (!((Object)(object)base.targetPlayer != (Object)null))
				{
					break;
				}
				if (!base.targetPlayer.isInsideFactory)
				{
					if (!FoundClosestPlayerInRange())
					{
						break;
					}
					((EnemyAI)this).StopSearch(base.currentSearch, true);
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				if (Time.time - lastGenTauntTime >= randGenTauntTime && ((NetworkBehaviour)this).IsHost)
				{
					Taunt();
				}
				flag = SetDestinationToHiddenPosition();
				if (!flag && flag2)
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(3);
				}
				else if (!flag && (Object)(object)closestPlayer != (Object)null)
				{
					((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
				}
				else if (!flag2)
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				break;
			}
		}

		public override void DoAIInterval()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			lastPosition = curPosition;
			curPosition = ((Component)this).transform.position;
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead)
			{
				return;
			}
			if ((base.currentBehaviourStateIndex == 1 || base.currentBehaviourStateIndex == 4) && ((NetworkBehaviour)this).IsHost)
			{
				EnemyTaunt();
			}
			switch (base.currentBehaviourStateIndex)
			{
			case 1:
				if (curPosition == lastPosition)
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(4);
					DoAnimationClientRpc("startIdle");
				}
				else
				{
					DoAnimationClientRpc("startWalk");
				}
				break;
			case 4:
				DoAnimationClientRpc("startIdle");
				break;
			case 0:
				if (curPosition == lastPosition)
				{
					DoAnimationClientRpc("startIdle");
				}
				else
				{
					DoAnimationClientRpc("startWalk");
				}
				break;
			case 3:
				if (curPosition == lastPosition)
				{
					DoAnimationClientRpc("startIdle");
				}
				else
				{
					DoAnimationClientRpc("startChase");
				}
				break;
			case 2:
				if (curPosition == lastPosition)
				{
					DoAnimationClientRpc("startIdle");
				}
				else
				{
					DoAnimationClientRpc("startWalk");
				}
				break;
			}
		}

		private AudioClip? FindClip(string clipName, List<AudioClip> clips)
		{
			foreach (AudioClip clip in clips)
			{
				if (((Object)clip).name == clipName)
				{
					return clip;
				}
			}
			return null;
		}

		private EnemyAI? EnemyNearGargoyle()
		{
			//IL_0024: 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)
			if ((Object)(object)base.targetPlayer != (Object)null)
			{
				EnemyAI[] array = Object.FindObjectsOfType<EnemyAI>();
				EnemyAI[] array2 = array;
				foreach (EnemyAI val in array2)
				{
					float num = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
					if (num <= distWarn)
					{
						return val;
					}
				}
			}
			return null;
		}

		private bool FoundClosestPlayerInRange()
		{
			//IL_0027: 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)
			PlayerControllerB val = null;
			float num = float.MaxValue;
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
			{
				PlayerControllerB val2 = StartOfRound.Instance.allPlayerScripts[i];
				if (val2.isInsideFactory)
				{
					float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)val2).transform.position);
					if (num2 < num)
					{
						val = val2;
						num = num2;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				base.targetPlayer = val;
				return true;
			}
			return false;
		}

		public void SearchForPlayers()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (searchForPlayers != null && !searchForPlayers.inProgress)
			{
				((EnemyAI)this).StartSearch(((Component)this).transform.position, searchForPlayers);
			}
		}

		private bool SetDestinationToHiddenPosition()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Transform val = null;
			List<Transform> coverPoints = new List<Transform>();
			FindCoverPointsAroundTarget(ref coverPoints);
			if (coverPoints.Count > 0)
			{
				val = ChooseBestCoverPoint(coverPoints);
			}
			if ((Object)(object)val != (Object)null)
			{
				base.agent.SetDestination(val.position);
				return true;
			}
			return false;
		}

		public void FindCoverPointsAroundTarget(ref List<Transform> coverPoints)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			Bounds val = default(Bounds);
			((Bounds)(ref val))..ctor(((Component)base.targetPlayer).transform.position, new Vector3(40f, 20f, 40f));
			Bounds val2 = default(Bounds);
			((Bounds)(ref val2))..ctor(((Component)this).transform.position, new Vector3(40f, 20f, 40f));
			for (int i = 0; i < base.allAINodes.Length; i++)
			{
				if (!((Bounds)(ref val2)).Contains(base.allAINodes[i].transform.position) && !((Bounds)(ref val)).Contains(base.allAINodes[i].transform.position))
				{
					continue;
				}
				bool flag = true;
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				foreach (PlayerControllerB val3 in allPlayerScripts)
				{
					if ((((Bounds)(ref val)).Contains(((Component)val3).transform.position) || ((Bounds)(ref val2)).Contains(((Component)val3).transform.position)) && (val3.HasLineOfSightToPosition(base.allAINodes[i].transform.position, 60f, 60, 25f) || ((EnemyAI)this).PathIsIntersectedByLineOfSight(base.allAINodes[i].transform.position, false, true, false)))
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					coverPoints.Add(base.allAINodes[i].transform);
				}
			}
		}

		public Transform? ChooseBestCoverPoint(List<Transform> coverPoints)
		{
			//IL_0044: 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)
			if (coverPoints.Count == 0)
			{
				return null;
			}
			Transform val = coverPoints[0];
			Transform val2 = coverPoints[0];
			float num = 40f;
			float num2 = 40f;
			foreach (Transform coverPoint in coverPoints)
			{
				float num3 = Vector3.Distance(((Component)base.targetPlayer).transform.position, coverPoint.position);
				if (num3 < num && num3 >= bufferDist)
				{
					val = coverPoint;
					num = num3;
				}
				else if (num3 < num2 && num3 >= aggroRange + 1f)
				{
					val2 = coverPoint;
					num2 = num3;
				}
			}
			if ((Object)(object)val == (Object)(object)coverPoints[0])
			{
				val = val2;
			}
			return val;
		}

		private bool GargoyleIsSeen(Transform t)
		{
			//IL_000d: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			bool result = false;
			bool flag = false;
			Vector3[] array = (Vector3[])(object)new Vector3[4]
			{
				t.position + Vector3.up * 0.25f,
				t.position + Vector3.up * 1.3f,
				t.position + Vector3.left * 1.6f,
				t.position + Vector3.right * 1.6f
			};
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
			{
				PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[i];
				float num = Vector3.Distance(((Component)val).transform.position, t.position);
				if (!(num <= awareDist) || ((base.isOutside || !val.isInsideFactory) && !base.isOutside))
				{
					continue;
				}
				Vector3[] array2 = array;
				foreach (Vector3 val2 in array2)
				{
					if (val.HasLineOfSightToPosition(val2, 68f, 60, -1f))
					{
						flag = true;
						break;
					}
				}
				if (((EnemyAI)this).PlayerIsTargetable(StartOfRound.Instance.allPlayerScripts[i], false, false) && flag && PlayerHasHorizontalLOS(StartOfRound.Instance.allPlayerScripts[i]))
				{
					result = true;
				}
			}
			return result;
		}

		public bool PlayerHasHorizontalLOS(PlayerControllerB player)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position - ((Component)player).transform.position;
			val.y = 0f;
			return Vector3.Angle(((Component)player).transform.forward, val) < 68f;
		}

		public bool CanSeePlayer(PlayerControllerB player, float width = 45f, int range = 60, int proximityAwareness = -1)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)player.gameplayCamera).transform.position;
			if (Vector3.Distance(position, base.eye.position) < (float)range && !Physics.Linecast(base.eye.position, position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				Vector3 val = position - base.eye.position;
				if (Vector3.Angle(base.eye.forward, val) < width || (proximityAwareness != -1 && Vector3.Distance(base.eye.position, position) < (float)proximityAwareness))
				{
					return true;
				}
			}
			return false;
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
			if ((Object)(object)val != (Object)null)
			{
				timeSinceHittingPlayer += Time.deltaTime;
				if (timeSinceHittingPlayer >= 1f)
				{
					AttackPlayer(val);
				}
			}
		}

		public void AttackPlayer(PlayerControllerB player)
		{
			//IL_003f: 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)
			base.agent.speed = 0f;
			timeSinceHittingPlayer = 0f;
			DoAnimationClientRpc("startIdle");
			DoAnimationClientRpc("swingAttack");
			player.DamagePlayer(attackDamage, false, true, (CauseOfDeath)1, 0, false, default(Vector3));
			GameNetworkManager.Instance.localPlayerController.JumpToFearLevel(1f, true);
		}

		public override void HitEnemy(int force = 1, PlayerControllerB? playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID);
			if (!base.isEnemyDead)
			{
				base.enemyHP -= force;
				if (((NetworkBehaviour)this).IsOwner && base.enemyHP <= 0 && !base.isEnemyDead)
				{
					((MonoBehaviour)this).StopCoroutine(base.searchCoroutine);
					((EnemyAI)this).KillEnemyOnOwnerClient(false);
				}
			}
		}

		public void LookAtTarget(Vector3 target)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0034: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Quaternion.LookRotation(target - ((Component)this).transform.position);
			((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, val, 300f * Time.deltaTime);
		}

		public override void KillEnemy(bool destroy = false)
		{
			((EnemyAI)this).KillEnemy(destroy);
			Collider component = ((Component)((Component)this).transform).GetComponent<Collider>();
			component.enabled = false;
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				val.enabled = false;
			}
			int index = Random.Range(0, Plugin.deathClips.Count() - 1);
			TauntClientRpc(((Object)Plugin.deathClips[index]).name, "death");
		}

		public void Taunt()
		{
			int num = Random.Range(1, 100);
			if (num < 3)
			{
				OtherTaunt("enemy", ref lastGenTaunt, ref lastGenTauntTime, ref randGenTauntTime);
			}
			else
			{
				OtherTaunt("general", ref lastGenTaunt, ref lastGenTauntTime, ref randGenTauntTime);
			}
		}

		public void OtherTaunt(string clipType, ref int lastTaunt, ref float lastTauntTime, ref float randTime)
		{
			List<AudioClip> list = new List<AudioClip>();
			switch (clipType)
			{
			case "general":
				list = Plugin.tauntClips;
				break;
			case "enemy":
				list = Plugin.enemyClips;
				break;
			case "aggro":
				list = Plugin.aggroClips;
				break;
			case "death":
				list = Plugin.deathClips;
				break;
			}
			if (list.Count != 0 && !GargoyleIsTalking())
			{
				int num;
				do
				{
					num = Random.Range(0, list.Count() - 1);
				}
				while (num == lastTaunt);
				TauntClientRpc(((Object)list[num]).name, clipType);
				lastTauntTime = Time.time;
				randTime = Random.Range(minTaunt, maxTaunt);
			}
		}

		public bool GargoyleIsTalking()
		{
			EnemyAI[] array = Object.FindObjectsOfType<EnemyAI>();
			EnemyAI[] array2 = array;
			foreach (EnemyAI val in array2)
			{
				if (val.enemyType.enemyName.ToUpper() == "LETHALGARGOYLE" && val.creatureVoice.isPlaying)
				{
					return true;
				}
			}
			return false;
		}

		public void EnemyTaunt()
		{
			int num = Random.Range(1, 200);
			string text = null;
			if (num >= 2 || base.creatureVoice.isPlaying)
			{
				return;
			}
			EnemyAI val = EnemyNearGargoyle();
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			lastEnemy = val.enemyType.enemyName;
			if (val.enemyType.enemyName != lastEnemy)
			{
				switch (val.enemyType.enemyName.ToUpper())
				{
				case "BLOB":
					text = "taunt_enemy_Slime1";
					break;
				case "BUTLER":
					text = "taunt_enemy_Butler1";
					break;
				case "CENTIPEDE":
					text = "taunt_enemy_Centipede1";
					break;
				case "GIRL":
					text = "taunt_enemy_GhostGirl1";
					break;
				case "HOARDINGBUG":
					text = "taunt_enemy_HoardingBug1";
					break;
				case "JESTER":
					text = "taunt_enemy_Jester1";
					break;
				case "MANEATER":
					text = "taunt_enemy_Maneater1";
					break;
				case "MASKED":
					text = "taunt_enemy_Masked1";
					break;
				case "CRAWLER":
					text = "taunt_enemy_Thumper1";
					break;
				case "BUNKERSPIDER":
					text = "taunt_enemy_Spider1";
					break;
				case "SPRING":
					text = "taunt_enemy_SpringHead1";
					break;
				case "NUTCRACKER":
					text = "taunt_enemy_Nutcracker1";
					break;
				case "FLOWERMAN":
					text = "taunt_enemy_Bracken1";
					break;
				}
				if (text != null)
				{
					TauntClientRpc(text, "enemy");
				}
			}
		}

		[ClientRpc]
		private void TauntClientRpc(string clipName, string clipType)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2632180766u, val, (RpcDelivery)0);
				bool flag = clipName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(clipName, false);
				}
				bool flag2 = clipType != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives));
				if (flag2)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(clipType, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2632180766u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				List<AudioClip> list = new List<AudioClip>();
				switch (clipType)
				{
				case "general":
					list = Plugin.tauntClips;
					break;
				case "enemy":
					list = Plugin.enemyClips;
					break;
				case "aggro":
					list = Plugin.aggroClips;
					break;
				case "death":
					list = Plugin.deathClips;
					break;
				}
				if (list.Count > 0)
				{
					base.creatureVoice.PlayOneShot(FindClip(clipName, list));
				}
			}
		}

		[ClientRpc]
		public void DoAnimationClientRpc(string animationName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_008e: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(590826057u, val, (RpcDelivery)0);
				bool flag = animationName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(animationName, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 590826057u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.creatureAnimator.SetTrigger(animationName);
			}
		}

		protected override void __initializeVariables()
		{
			((EnemyAI)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_LethalGargoylesAI()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2632180766u, new RpcReceiveHandler(__rpc_handler_2632180766));
			NetworkManager.__rpc_func_table.Add(590826057u, new RpcReceiveHandler(__rpc_handler_590826057));
		}

		private static void __rpc_handler_2632180766(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string clipName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref clipName, false);
				}
				bool flag2 = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives));
				string clipType = null;
				if (flag2)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref clipType, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((LethalGargoylesAI)(object)target).TauntClientRpc(clipName, clipType);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_590826057(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string animationName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref animationName, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((LethalGargoylesAI)(object)target).DoAnimationClientRpc(animationName);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "LethalGargoylesAI";
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DropDaDeuce.LethalGargoyles";

		public const string PLUGIN_NAME = "LethalGargoyles";

		public const string PLUGIN_VERSION = "0.0.5";
	}
}
namespace LethalGargoyles.Configuration
{
	public class PluginConfig
	{
		public ConfigEntry<int> SpawnWeight;

		public ConfigEntry<int> baseSpeed;

		public ConfigEntry<int> attackRange;

		public ConfigEntry<int> attackDamage;

		public ConfigEntry<int> aggroRange;

		public ConfigEntry<int> idleDistance;

		public ConfigEntry<int> minTaunt;

		public ConfigEntry<int> maxTaunt;

		public ConfigEntry<int> distWarn;

		public ConfigEntry<int> bufferDist;

		public ConfigEntry<int> awareDist;

		public PluginConfig(ConfigFile cfg)
		{
			SpawnWeight = cfg.Bind<int>("General", "Spawn weight", 50, "The spawn chance weight for the Gargoyle, relative to other existing enemies.\nGoes up from 0, lower is more rare, 100 and up is very common.");
			baseSpeed = cfg.Bind<int>("General", "Base Speed", 4, "The base speed that the Gargoyle travels.");
			attackRange = cfg.Bind<int>("General", "Attack Range", 2, "The range that that the Gargoyle can attack.");
			attackDamage = cfg.Bind<int>("General", "Attack Damage", 20, "The base damage that the Gargoyle deals.");
			aggroRange = cfg.Bind<int>("General", "Aggro Range", 6, "The range in which the Gargoyle will agro.");
			idleDistance = cfg.Bind<int>("General", "Idle Distance", 30, "The distance in which the Gargoyle will stay idle if not seen.");
			minTaunt = cfg.Bind<int>("General", "Min Taunt", 15, "The minimum amount of time in seconds to wait between taunts. Other types of taunts will be half this number.");
			maxTaunt = cfg.Bind<int>("General", "Max Taunt", 45, "The maximum amount of time in seconds to wait between general taunts. Other types of taunts will be half this number.");
			distWarn = cfg.Bind<int>("General", "Enemy Distance Warning", 45, "The distance at which a gargoyle will warn players about enemies with his taunts. This taunt is set to a 20% chance to play if an enemy is near the gargoyle, and not all enemy warnings are real!");
			bufferDist = cfg.Bind<int>("General", "Buffer Distance", 12, "How much buffer the Gargoyle will try to keep between him and the target player.");
			awareDist = cfg.Bind<int>("General", "Awareness", 60, "How far away is the gargoyle aware of other players. This will affect performance, as this setting is used to calculate pathing.");
			ClearUnusedEntries(cfg);
		}

		private void ClearUnusedEntries(ConfigFile cfg)
		{
			PropertyInfo property = ((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(cfg, null);
			dictionary.Clear();
			cfg.Save();
		}
	}
}
namespace DropDaDeuce.LethalGargoyles.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}