Decompiled source of SkaarjPupae v1.0.2

Data/DreWulff.SkaarjPupae.dll

Decompiled 6 hours ago
#define DEBUG
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 DreWulff.SkaarjPupae.NetcodePatcher;
using GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using SkaarjPupae.Configuration;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DreWulff.SkaarjPupae")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cf3d8c495b0e2029d9dc243d456314aff6bf1306")]
[assembly: AssemblyProduct("SkaarjPupae")]
[assembly: AssemblyTitle("DreWulff.SkaarjPupae")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 SkaarjPupae
{
	[RequireComponent(typeof(Rigidbody))]
	internal class PupaeAI : EnemyAI
	{
		private enum State
		{
			ROAMING,
			SURVEILLING,
			SPOTTED,
			CHASING,
			LEAPING
		}

		private enum SquadState
		{
			ROAMING,
			SURVEILLING,
			SPOTTED,
			CHASING
		}

		[Tooltip("Leaping cooldown.")]
		[SerializeField]
		private float _leapCooldown;

		[Tooltip("Curve that defines how gravity increases during a leap.")]
		[SerializeField]
		private AnimationCurve _gravityCurve;

		private bool jumping = false;

		private bool jumped = false;

		private float height;

		private float startingHeight;

		private float timeSinceLeap;

		private Vector3 startingPosition;

		private float followDelay = 0f;

		private float surveillanceTimer = 0f;

		[Tooltip("Cooldown for damage instances.")]
		[SerializeField]
		private float damageCooldown;

		[Tooltip("Damage done to the player when hit during a leap.")]
		[SerializeField]
		private int leapDamage;

		private float timeSinceDamagingPlayer;

		[HideInInspector]
		public Rigidbody rb;

		[HideInInspector]
		public bool isLeader;

		[HideInInspector]
		public PupaeAI[] squad;

		[HideInInspector]
		public PupaeAI squadLeader;

		[HideInInspector]
		public int squadState;

		[HideInInspector]
		public PlayerControllerB? squadTargetPlayer;

		public void StartChase()
		{
			((EnemyAI)this).SwitchToBehaviourClientRpc(3);
			((Behaviour)base.agent).enabled = true;
			base.inSpecialAnimation = false;
			if (isLeader)
			{
				UpdateSquadState(3);
			}
			DoAnimationClientRpc("Chase");
		}

		private void ChaseAI()
		{
			//IL_0096: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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)
			if (squadState == 0)
			{
				StartRoam();
				return;
			}
			if (isLeader && (!IsTargetInRange() || base.targetPlayer.isPlayerDead))
			{
				UpdateSquadState(0);
				StartRoam();
				return;
			}
			if (timeSinceLeap < _leapCooldown)
			{
				timeSinceLeap += base.AIIntervalTime;
			}
			if ((Object)(object)base.targetPlayer != (Object)null)
			{
				if (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < 10f && Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) > 5f && timeSinceLeap >= _leapCooldown && ((Component)base.targetPlayer).transform.position.y - ((Component)this).transform.position.y < 2f && ((EnemyAI)this).CheckLineOfSightForPosition(((Component)base.targetPlayer).transform.position, 45f, 60, -1f, (Transform)null))
				{
					StartLeap();
					return;
				}
				base.agent.speed = 6f;
				((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
			}
		}

		private void StartLeap()
		{
			((EnemyAI)this).SwitchToBehaviourClientRpc(4);
			base.inSpecialAnimation = true;
			DoAnimationClientRpc("Leap");
		}

		[ClientRpc]
		public void LeapClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_007c: 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_0117: 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_0139: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_0178: 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_0191: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: 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(3580704240u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3580704240u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				jumping = true;
				jumped = false;
				base.inSpecialAnimation = false;
				timeSinceLeap = 0f;
				((Behaviour)base.agent).enabled = false;
				rb.isKinematic = false;
				float x = ((Component)base.targetPlayer).transform.position.x;
				float y = ((Component)base.targetPlayer).transform.position.y;
				float x2 = ((Component)this).transform.position.x;
				float y2 = ((Component)this).transform.position.y;
				Rigidbody obj = rb;
				Vector3 val3 = ((Component)base.targetPlayer).transform.position - ((Component)this).transform.position;
				obj.velocity = ((Vector3)(ref val3)).normalized * 30f + new Vector3(0f, 7f, 0f);
				NavMeshHit val4 = default(NavMeshHit);
				if (NavMesh.SamplePosition(((Component)this).transform.position, ref val4, 10f, -1))
				{
					startingPosition = ((Component)this).transform.position;
					startingHeight = Mathf.Max(Mathf.Abs(startingPosition.y - ((NavMeshHit)(ref val4)).position.y), 0.1f);
				}
			}
		}

		private void LeapAI()
		{
			if (!jumping && jumped)
			{
				jumped = false;
				if (squadState == 3)
				{
					StartChase();
				}
				else
				{
					StartRoam();
				}
			}
		}

		private void LeapUpdate()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: 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_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: 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)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: 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 (jumping && !jumped)
			{
				((Behaviour)base.agent).enabled = false;
				NavMeshHit val = default(NavMeshHit);
				if (NavMesh.SamplePosition(((Component)this).transform.position, ref val, 10f, -1))
				{
					Debug.DrawLine(((Component)this).transform.position, ((NavMeshHit)(ref val)).position, Color.cyan);
					height = ((Component)this).transform.position.y - ((NavMeshHit)(ref val)).position.y;
				}
				timeSinceLeap += Time.deltaTime;
				Rigidbody obj = rb;
				obj.velocity += new Vector3(0f, Mathf.Lerp(0f, Physics.gravity.y, _gravityCurve.Evaluate(timeSinceLeap)), 0f);
				Ray val2 = default(Ray);
				((Ray)(ref val2))..ctor(((Component)this).transform.position, rb.velocity);
				RaycastHit val3 = default(RaycastHit);
				if (Physics.Raycast(val2, ref val3, 1f, LayerMask.GetMask(new string[3] { "NavigationSurface", "Terrain", "Room" })) && (double)((RaycastHit)(ref val3)).distance < 0.4)
				{
					EndLeapClientRpc();
					return;
				}
				if ((timeSinceLeap > base.AIIntervalTime && height < startingHeight) || timeSinceLeap > 1.4f)
				{
					EndLeapClientRpc();
				}
			}
			if (!jumping && (Object)(object)base.targetPlayer != (Object)null)
			{
				Vector3 val4 = ((Component)base.targetPlayer).transform.position - ((Component)this).transform.position;
				Vector3 normalized = ((Vector3)(ref val4)).normalized;
				Quaternion val5 = Quaternion.LookRotation(normalized);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val5, Time.deltaTime * 8f);
			}
		}

		[ClientRpc]
		private void EndLeapClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00f1: 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(1966885826u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1966885826u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				jumping = false;
				jumped = true;
				NavMeshHit val3 = default(NavMeshHit);
				if (!NavMesh.SamplePosition(((Component)this).transform.position, ref val3, 10f, -1))
				{
					((Component)this).transform.position = startingPosition;
				}
				rb.isKinematic = true;
				((Behaviour)base.agent).enabled = true;
				base.agent.Warp(((Component)this).transform.position);
				base.inSpecialAnimation = false;
				timeSinceLeap = 0f;
			}
		}

		private void StartRoam()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).SwitchToBehaviourClientRpc(0);
			((Behaviour)base.agent).enabled = true;
			base.inSpecialAnimation = false;
			timeSinceLeap = _leapCooldown;
			DoAnimationClientRpc("Crawl");
			if (isLeader)
			{
				UpdateSquadState(0);
				surveillanceTimer = Random.Range(10f, 25f);
				((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
			}
			else
			{
				StartFollow();
			}
		}

		private void StartFollow()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			followDelay = Random.Range(1, 4);
			((EnemyAI)this).StopSearch(base.currentSearch, true);
			((EnemyAI)this).SetDestinationToPosition(((Component)squadLeader).transform.position, false);
			LogIfDebugBuild("Following leader!");
		}

		private void RoamAI()
		{
			if (FoundClosestPlayerInRange(10f, 10f))
			{
				PlayerSpotted(this);
				return;
			}
			if (squadState == 2)
			{
				StartSpot();
				return;
			}
			if (surveillanceTimer > 0f)
			{
				surveillanceTimer -= base.AIIntervalTime;
			}
			if (surveillanceTimer <= 0f)
			{
				StartSurveillance();
				return;
			}
			base.agent.speed = 3f;
			SetCrawlingSpeed();
		}

		private void RoamFollowerAI()
		{
			if (FoundClosestPlayerInRange(10f, 5f))
			{
				Debug.Log((object)"Spotted player! Alerting group!");
				PlayerSpotted(this);
			}
			else if (followDelay <= 0f)
			{
				if (squadState == 1)
				{
					StartFollowerSurveillance();
				}
				else if (squadState == 2)
				{
					StartSpot();
				}
				else
				{
					FollowLeader();
				}
				followDelay = Random.Range(1, 11);
			}
			else
			{
				followDelay -= 1f;
			}
		}

		private void FollowLeader()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if (Vector3.Distance(((Component)squadLeader).transform.position, ((Component)this).transform.position) > 7f)
			{
				((EnemyAI)this).SetDestinationToPosition(((Component)squadLeader).transform.position, false);
				base.agent.speed = 4.5f;
				SetCrawlingSpeed();
				return;
			}
			if ((Object)(object)((EnemyAI)squadLeader).currentSearch.currentTargetNode != (Object)null)
			{
				((EnemyAI)this).SetDestinationToPosition(((EnemyAI)squadLeader).currentSearch.currentTargetNode.transform.position + new Vector3(Random.Range(-2f, 2f), 0f, Random.Range(-2f, 2f)), false);
			}
			else
			{
				((EnemyAI)this).SetDestinationToPosition(((Component)squadLeader).transform.position, false);
			}
			base.agent.speed = 2.5f + Random.Range(-0.5f, 0.5f);
			SetCrawlingSpeed();
		}

		private void SetCrawlingSpeed()
		{
			SetAnimationParameterClientRpc("CrawlSpeed", base.agent.speed / 3f);
		}

		public void PlayerSpotted(PupaeAI sender)
		{
			UpdateSquadState(2);
			UpdateSquadTarget(((EnemyAI)sender).targetPlayer);
			StartSpot();
		}

		public void StartSpot()
		{
			((EnemyAI)this).SwitchToBehaviourClientRpc(2);
			((EnemyAI)this).StopSearch(base.currentSearch, true);
			((Behaviour)base.agent).enabled = true;
			base.inSpecialAnimation = false;
			base.agent.speed = 0f;
			DoAnimationClientRpc("Spot");
		}

		private void SpotUpdate()
		{
			//IL_001d: 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_002d: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)base.targetPlayer != (Object)null)
			{
				Vector3 val = ((Component)base.targetPlayer).transform.position - ((Component)this).transform.position;
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				Quaternion val2 = Quaternion.LookRotation(normalized);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val2, Time.deltaTime * 2f);
			}
		}

		private void StartSurveillance()
		{
			((EnemyAI)this).SwitchToBehaviourClientRpc(1);
			base.agent.speed = 0f;
			if (isLeader)
			{
				UpdateSquadState(1);
			}
			DoAnimationClientRpc("Surveil");
		}

		private void StartFollowerSurveillance()
		{
			//IL_0055: 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_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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).SwitchToBehaviourClientRpc(1);
			if ((double)Random.Range(0f, 1f) > 0.4)
			{
				base.agent.speed = 0f;
				DoAnimationClientRpc("Surveil");
				return;
			}
			Vector3 position = ((Component)squadLeader).transform.position;
			Vector3 val = Vector3.Cross(((Component)squadLeader).transform.position - ((Component)this).transform.position, Vector3.up);
			Vector3 val2 = position + ((Vector3)(ref val)).normalized * 7f;
			((EnemyAI)this).SetDestinationToPosition(val2, false);
			base.agent.speed = 2f;
			SetCrawlingSpeed();
		}

		private void SurveilAI()
		{
			if (FoundClosestPlayerInRange(12f, 10f))
			{
				PlayerSpotted(this);
			}
			else if (squadState == 2)
			{
				StartSpot();
			}
			else if (squadState == 0)
			{
				StartRoam();
			}
		}

		public void EndSurveillance()
		{
			if (isLeader)
			{
				UpdateSquadState(0);
			}
		}

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

		public override void Start()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Start();
			float num = _gravityCurve.Evaluate(Random.Range(0f, 1f)) * 0.3f + 0.9f;
			if (num > 1f)
			{
				base.enemyHP = (int)((float)base.enemyHP * 1.5f);
				leapDamage = (int)((float)leapDamage * 1.5f);
			}
			((Component)((Component)this).gameObject.transform).transform.localScale = new Vector3(num, num, num);
			rb = ((Component)this).gameObject.GetComponent<Rigidbody>();
			timeSinceDamagingPlayer = damageCooldown;
			squad = new PupaeAI[1] { this };
			isLeader = true;
			squadLeader = this;
			LogIfDebugBuild("Skaarj Pupae Spawned");
			StartRoam();
		}

		public override void Update()
		{
			((EnemyAI)this).Update();
			if (!base.isEnemyDead || jumping)
			{
				if (timeSinceDamagingPlayer < damageCooldown)
				{
					timeSinceDamagingPlayer += Time.deltaTime;
				}
				switch (base.currentBehaviourStateIndex)
				{
				case 0:
					break;
				case 1:
					break;
				case 2:
					SpotUpdate();
					break;
				case 3:
					break;
				case 4:
					LeapUpdate();
					break;
				}
			}
		}

		public override void DoAIInterval()
		{
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead)
			{
				return;
			}
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				if (isLeader)
				{
					RoamAI();
				}
				else
				{
					RoamFollowerAI();
				}
				break;
			case 1:
				SurveilAI();
				break;
			case 2:
				break;
			case 3:
				ChaseAI();
				break;
			case 4:
				LeapAI();
				break;
			}
		}

		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 override void KillEnemy(bool destroy = false)
		{
			((EnemyAI)this).KillEnemy(destroy);
			RemovePupae(this);
			((Behaviour)base.creatureSFX).enabled = false;
			((Behaviour)base.creatureVoice).enabled = false;
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
			if ((Object)(object)val != (Object)null && timeSinceDamagingPlayer >= damageCooldown)
			{
				val.DamagePlayer(leapDamage, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				timeSinceDamagingPlayer = 0f;
			}
		}

		[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(2747714262u, 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, 2747714262u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.creatureAnimator.SetTrigger(animationName);
			}
		}

		[ClientRpc]
		public void SetAnimationParameterClientRpc(string parameter, float value)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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(744276610u, val, (RpcDelivery)0);
				bool flag = parameter != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(parameter, false);
				}
				((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref value, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 744276610u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.creatureAnimator.SetFloat(parameter, value);
			}
		}

		public bool FindTarget(float range = 15f)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (!TargetClosestPlayerInAnyCase() || (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) > range && !((EnemyAI)this).CheckLineOfSightForPosition(((Component)base.targetPlayer).transform.position, 45f, 60, -1f, (Transform)null)) || base.targetPlayer.isPlayerDead)
			{
				return false;
			}
			return true;
		}

		private bool FoundClosestPlayerInRange(float range, float senseRange)
		{
			//IL_004e: 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)
			((EnemyAI)this).TargetClosestPlayer(5f, true, 140f);
			if ((Object)(object)base.targetPlayer == (Object)null)
			{
				((EnemyAI)this).TargetClosestPlayer(5f, false, 70f);
				range = senseRange;
			}
			return (Object)(object)base.targetPlayer != (Object)null && Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < range && !base.targetPlayer.isPlayerDead;
		}

		private bool TargetClosestPlayerInAnyCase()
		{
			//IL_001f: 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)
			base.mostOptimalDistance = 2000f;
			base.targetPlayer = null;
			for (int i = 0; i < StartOfRound.Instance.connectedPlayersAmount + 1; i++)
			{
				base.tempDist = Vector3.Distance(((Component)this).transform.position, ((Component)StartOfRound.Instance.allPlayerScripts[i]).transform.position);
				if (base.tempDist < base.mostOptimalDistance)
				{
					base.mostOptimalDistance = base.tempDist;
					base.targetPlayer = StartOfRound.Instance.allPlayerScripts[i];
				}
			}
			if ((Object)(object)base.targetPlayer == (Object)null || base.targetPlayer.isPlayerDead)
			{
				return false;
			}
			return true;
		}

		public void CreateSquad(PupaeAI other)
		{
			if (squad.Length < 4 && base.currentBehaviourStateIndex == 0 && !squad.Contains(other) && !((EnemyAI)other).isEnemyDead && !base.isEnemyDead && ((Object)other).GetInstanceID() <= ((Object)this).GetInstanceID())
			{
				other.Join(squad);
				UpdateSquadState(0);
			}
		}

		public void BecomeLeader(PupaeAI[] n_squad)
		{
			isLeader = true;
			squadLeader = this;
			UpdateSquad();
		}

		public void RemovePupae(PupaeAI remove)
		{
			PupaeAI remove2 = remove;
			squad = squad.Where((PupaeAI obj) => ((Object)obj).GetInstanceID() != ((Object)remove2).GetInstanceID()).ToArray();
			if (isLeader && squad.Length != 0)
			{
				PupaeAI[] array = squad;
				foreach (PupaeAI pupaeAI in array)
				{
					if (!((EnemyAI)pupaeAI).isEnemyDead)
					{
						pupaeAI.BecomeLeader(squad);
						squadLeader = pupaeAI;
						squadLeader.squadState = squadState;
					}
				}
			}
			UpdateSquad();
		}

		public void Join(PupaeAI[] n_squad)
		{
			squad = squad.Concat(n_squad).ToArray();
			UpdateSquad();
		}

		public void UpdateSquad()
		{
			PupaeAI[] array = squad;
			foreach (PupaeAI pupaeAI in array)
			{
				pupaeAI.isLeader = false;
				pupaeAI.squad = squad;
				pupaeAI.squadLeader = squadLeader;
			}
			squadLeader.isLeader = true;
		}

		public void UpdateSquadTarget(PlayerControllerB target)
		{
			PupaeAI[] array = squad;
			foreach (PupaeAI pupaeAI in array)
			{
				((EnemyAI)pupaeAI).targetPlayer = target;
			}
		}

		public void UpdateSquadState(int state)
		{
			PupaeAI[] array = squad;
			foreach (PupaeAI pupaeAI in array)
			{
				pupaeAI.squadState = state;
			}
		}

		public bool IsTargetInRange()
		{
			PupaeAI[] array = squad;
			foreach (PupaeAI pupaeAI in array)
			{
				if (pupaeAI.FindTarget())
				{
					UpdateSquadTarget(((EnemyAI)pupaeAI).targetPlayer);
					return true;
				}
			}
			return false;
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_PupaeAI()
		{
			//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
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3580704240u, new RpcReceiveHandler(__rpc_handler_3580704240));
			NetworkManager.__rpc_func_table.Add(1966885826u, new RpcReceiveHandler(__rpc_handler_1966885826));
			NetworkManager.__rpc_func_table.Add(2747714262u, new RpcReceiveHandler(__rpc_handler_2747714262));
			NetworkManager.__rpc_func_table.Add(744276610u, new RpcReceiveHandler(__rpc_handler_744276610));
		}

		private static void __rpc_handler_3580704240(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((PupaeAI)(object)target).LeapClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1966885826(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((PupaeAI)(object)target).EndLeapClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2747714262(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;
				((PupaeAI)(object)target).DoAnimationClientRpc(animationName);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_744276610(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_007c: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string parameter = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref parameter, false);
				}
				float value = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref value, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((PupaeAI)(object)target).SetAnimationParameterClientRpc(parameter, value);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "PupaeAI";
		}
	}
	internal class DebugText : MonoBehaviour
	{
		[SerializeField]
		private PupaeAI mainAI;

		private TMP_Text text;

		private void Awake()
		{
			text = ((Component)this).GetComponent<TMP_Text>();
		}

		public void Update()
		{
			text.text = "IS LEADER? " + mainAI.isLeader + "\nSTATE: " + ((EnemyAI)mainAI).currentBehaviourState.name + "\nSQUAD STATE: " + mainAI.squadState + "\n";
		}
	}
	[BepInPlugin("DreWulff.SkaarjPupae", "SkaarjPupae", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static AssetBundle? pupaeAssets;

		internal static PluginConfig BoundConfig { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
			InitializeNetworkBehaviours();
			string path = "skaarj-pupae-assets";
			pupaeAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)pupaeAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			EnemyType val = pupaeAssets.LoadAsset<EnemyType>("SkaarjPupae");
			TerminalNode val2 = pupaeAssets.LoadAsset<TerminalNode>("SkaarjPupaeTN");
			TerminalKeyword val3 = pupaeAssets.LoadAsset<TerminalKeyword>("SkaarjPupaeTK");
			NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
			Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>
			{
				{
					(LevelTypes)4,
					50
				},
				{
					(LevelTypes)8,
					200
				},
				{
					(LevelTypes)16,
					100
				},
				{
					(LevelTypes)32,
					30
				},
				{
					(LevelTypes)2048,
					150
				},
				{
					(LevelTypes)(-1),
					0
				},
				{
					(LevelTypes)1024,
					30
				}
			};
			Dictionary<string, int> dictionary2 = new Dictionary<string, int>
			{
				{ "46 Infernis", 69 },
				{ "76 Acidir", 200 },
				{ "240 Alcatras", 50 },
				{ "84 Junic", 300 },
				{ "6 Mazon", 150 }
			};
			Enemies.RegisterEnemy(val, dictionary, dictionary2, val2, val3);
			Logger.LogInfo((object)"Plugin DreWulff.SkaarjPupae 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);
					}
				}
			}
		}
	}
	internal class PupaeAnimationEvents : MonoBehaviour
	{
		[SerializeField]
		private PupaeAI mainAI;

		public void Chase()
		{
			mainAI.StartChase();
		}

		public void EndLeapAnimation()
		{
			mainAI.LeapClientRpc();
		}

		public void EndSurveillance()
		{
			mainAI.EndSurveillance();
		}
	}
	internal class PupaeScanner : MonoBehaviour
	{
		[SerializeField]
		private PupaeAI mainAI;

		public void OnTriggerEnter(Collider other)
		{
			SquadLogic(other);
		}

		private void SquadLogic(Collider other)
		{
			PupaeScanner pupaeScanner = default(PupaeScanner);
			if (((Component)other).TryGetComponent<PupaeScanner>(ref pupaeScanner))
			{
				pupaeScanner.AttemptSquadJoin(mainAI);
			}
		}

		public void AttemptSquadJoin(PupaeAI otherPupae)
		{
			mainAI.CreateSquad(otherPupae);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DreWulff.SkaarjPupae";

		public const string PLUGIN_NAME = "SkaarjPupae";

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

		public PluginConfig(ConfigFile cfg)
		{
			SpawnWeight = cfg.Bind<int>("General", "Spawn weight", 100, "The spawn chance weight for SkaarjPupae, relative to other existing enemies.\nGoes up from 0, lower is more rare, 100 and up is very common.");
			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 DreWulff.SkaarjPupae.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}