Decompiled source of CatBrainRot v1.0.5

plugins/CatBrainRot/BakaMODs.CatBrainRot.dll

Decompiled a month 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.Security;
using System.Security.Permissions;
using BakaMODs.CatBrainRot.NetcodePatcher;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Extras;
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("BakaMODs.CatBrainRot")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("CatBrainRot")]
[assembly: AssemblyTitle("BakaMODs.CatBrainRot")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 CatBrainRot
{
	internal class CatBrainRotAI : EnemyAI
	{
		private enum State
		{
			Spawning,
			SearchingForPlayer,
			ChasingPlayer
		}

		public Transform turnCompass;

		public Transform attackArea;

		private float timeSinceLastDamage;

		private Coroutine? executionAudioCoroutine;

		private bool isPlayingExecutionAudio;

		public float damageRadius = 2.5f;

		public float damageInterval = 1f;

		public int damageAmount = 5;

		[Header("Insta-Kill Attack")]
		public float instaKillChancePerSecond = 0.05f;

		public AudioClip instaKillSFX;

		public AudioClip standardAttackSFX;

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

		public override void Start()
		{
			((EnemyAI)this).Start();
			((EnemyAI)this).SwitchToBehaviourClientRpc(0);
			((MonoBehaviour)this).StartCoroutine(SpawnAnimationDelay());
		}

		public override void Update()
		{
			//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)
			((EnemyAI)this).Update();
			if (base.isEnemyDead)
			{
				return;
			}
			if (StartOfRound.Instance.allPlayersDead)
			{
				if (!isPlayingExecutionAudio && (((Object)(object)base.creatureVoice != (Object)null && base.creatureVoice.isPlaying) || ((Object)(object)base.creatureSFX != (Object)null && base.creatureSFX.isPlaying)))
				{
					StopCreatureAudio();
				}
			}
			else if (((NetworkBehaviour)this).IsOwner)
			{
				Animator creatureAnimator = base.creatureAnimator;
				Vector3 velocity = base.agent.velocity;
				creatureAnimator.SetBool("isWalking", ((Vector3)(ref velocity)).magnitude > 0.1f);
			}
		}

		public override void DoAIInterval()
		{
			//IL_00f1: 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_00b4: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead)
			{
				return;
			}
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				base.agent.speed = 0f;
				break;
			case 1:
				base.agent.speed = 2f;
				if (FoundClosestPlayerInRange(25f, 3f))
				{
					((EnemyAI)this).StopSearch(base.currentSearch, true);
					((EnemyAI)this).SwitchToBehaviourClientRpc(2);
					StartChasingLoopClientRpc();
				}
				break;
			case 2:
				base.agent.speed = 4f;
				if (!TargetClosestPlayerInAnyCase() || (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) > 20f && !((EnemyAI)this).CheckLineOfSightForPosition(((Component)base.targetPlayer).transform.position, 45f, 60, -1f, (Transform)null)))
				{
					((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
					StopChasingLoopClientRpc();
					break;
				}
				((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
				if (((NetworkBehaviour)this).IsServer)
				{
					timeSinceLastDamage += base.AIIntervalTime;
					if (timeSinceLastDamage >= damageInterval)
					{
						timeSinceLastDamage = 0f;
						DamagePlayersInAreaServer();
					}
					if ((Object)(object)base.targetPlayer != (Object)null && Random.value < instaKillChancePerSecond * base.AIIntervalTime)
					{
						PerformInstaKillAttackServer();
					}
				}
				break;
			}
		}

		private IEnumerator SpawnAnimationDelay()
		{
			yield return (object)new WaitForSeconds(1.5f);
			if (((NetworkBehaviour)this).IsOwner && !base.isEnemyDead && !StartOfRound.Instance.allPlayersDead)
			{
				((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
				((EnemyAI)this).SwitchToBehaviourClientRpc(1);
			}
		}

		private void PerformInstaKillAttackServer()
		{
			if (!((Object)(object)base.targetPlayer == (Object)null))
			{
				KillPlayerClientRpc((int)base.targetPlayer.playerClientId);
				InterruptLoopWithOneShotClientRpc();
			}
		}

		[ClientRpc]
		private void KillPlayerClientRpc(int playerId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_0071: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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 != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(195252436u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, playerId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 195252436u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				PlayerControllerB playerById = GetPlayerById(playerId);
				if (!((Object)(object)playerById == (Object)null) && !playerById.isPlayerDead)
				{
					playerById.KillPlayer(Vector3.zero, true, (CauseOfDeath)3, 0, default(Vector3), false);
				}
			}
		}

		[ClientRpc]
		private void InterruptLoopWithOneShotClientRpc()
		{
			//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_00c1: 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 != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1753015395u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1753015395u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
			if (!base.isEnemyDead)
			{
				StopCreatureAudio();
				if ((Object)(object)base.creatureVoice == (Object)null || (Object)(object)instaKillSFX == (Object)null)
				{
					Plugin.Logger.LogWarning((object)"Cannot play execution audio: creatureVoice or instaKillSFX is missing.");
					StartChasingLoop();
				}
				else
				{
					executionAudioCoroutine = ((MonoBehaviour)this).StartCoroutine(PauseLoopForSpecialAttack());
				}
			}
		}

		private IEnumerator PauseLoopForSpecialAttack()
		{
			isPlayingExecutionAudio = true;
			base.creatureVoice.loop = false;
			base.creatureVoice.PlayOneShot(instaKillSFX);
			yield return (object)new WaitForSeconds(instaKillSFX.length / Mathf.Max(Mathf.Abs(base.creatureVoice.pitch), 0.01f));
			isPlayingExecutionAudio = false;
			executionAudioCoroutine = null;
			if (!base.isEnemyDead && base.currentBehaviourStateIndex == 2)
			{
				StartChasingLoop();
			}
		}

		[ClientRpc]
		private void PlayStandardAttackSoundClientRpc()
		{
			//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_00c1: 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 != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(891529785u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 891529785u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				if (!base.isEnemyDead && !isPlayingExecutionAudio && (Object)(object)base.creatureVoice != (Object)null && (Object)(object)standardAttackSFX != (Object)null)
				{
					base.creatureVoice.PlayOneShot(standardAttackSFX);
				}
			}
		}

		[ClientRpc]
		private void StartChasingLoopClientRpc()
		{
			//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_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val2 = default(ClientRpcParams);
					FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1310417669u, val2, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val, 1310417669u, val2, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
					StartChasingLoop();
				}
			}
		}

		[ClientRpc]
		private void StopChasingLoopClientRpc()
		{
			//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_00c1: 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 != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(623469361u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 623469361u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				if (!isPlayingExecutionAudio)
				{
					StopCreatureAudio();
				}
			}
		}

		private void StartChasingLoop()
		{
			if (!((Object)(object)base.creatureVoice == (Object)null) && !base.isEnemyDead && !isPlayingExecutionAudio && !StartOfRound.Instance.allPlayersDead && base.currentBehaviourStateIndex == 2)
			{
				base.creatureVoice.loop = true;
				base.creatureVoice.Play();
			}
		}

		private void StopCreatureAudio()
		{
			if (executionAudioCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(executionAudioCoroutine);
				executionAudioCoroutine = null;
			}
			isPlayingExecutionAudio = false;
			if ((Object)(object)base.creatureVoice != (Object)null)
			{
				base.creatureVoice.Stop();
			}
			if ((Object)(object)base.creatureSFX != (Object)null)
			{
				base.creatureSFX.Stop();
			}
		}

		private void DamagePlayersInAreaServer()
		{
			//IL_0034: 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)
			bool flag = false;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (!((Object)(object)val == (Object)null) && !val.isPlayerDead && val.isPlayerControlled && Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position) < damageRadius)
				{
					DamageTargetPlayerClientRpc((int)val.playerClientId, damageAmount);
					flag = true;
				}
			}
			if (flag)
			{
				PlayStandardAttackSoundClientRpc();
			}
		}

		[ClientRpc]
		private void DamageTargetPlayerClientRpc(int playerId, int damage)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_0071: 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_0096: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3104341333u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, playerId);
				BytePacker.WriteValueBitPacked(val, damage);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 3104341333u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				PlayerControllerB playerById = GetPlayerById(playerId);
				if (!((Object)(object)playerById == (Object)null) && !playerById.isPlayerDead)
				{
					playerById.DamagePlayer(damage, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				}
			}
		}

		private static PlayerControllerB GetPlayerById(int playerId)
		{
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			if (playerId < 0 || playerId >= allPlayerScripts.Length)
			{
				return null;
			}
			return allPlayerScripts[playerId];
		}

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

		private bool TargetClosestPlayerInAnyCase()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			base.mostOptimalDistance = 2000f;
			base.targetPlayer = null;
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
			{
				PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[i];
				if (!((Object)(object)val == (Object)null) && !val.isPlayerDead && val.isPlayerControlled)
				{
					base.tempDist = Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position);
					if (base.tempDist < base.mostOptimalDistance)
					{
						base.mostOptimalDistance = base.tempDist;
						base.targetPlayer = val;
					}
				}
			}
			return (Object)(object)base.targetPlayer != (Object)null;
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			((EnemyAI)this).OnCollideWithPlayer(other);
		}

		public override void OnCollideWithEnemy(Collider other, EnemyAI collidedEnemy = null)
		{
			((EnemyAI)this).OnCollideWithEnemy(other, collidedEnemy);
		}

		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).IsServer && base.enemyHP <= 0 && !base.isEnemyDead)
				{
					((EnemyAI)this).StopSearch(base.currentSearch, true);
					((EnemyAI)this).KillEnemyOnOwnerClient(false);
				}
			}
		}

		public override void KillEnemy(bool destroy = false)
		{
			StopCreatureAudio();
			((EnemyAI)this).KillEnemy(destroy);
		}

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

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(195252436u, new RpcReceiveHandler(__rpc_handler_195252436), "KillPlayerClientRpc");
			((NetworkBehaviour)this).__registerRpc(1753015395u, new RpcReceiveHandler(__rpc_handler_1753015395), "InterruptLoopWithOneShotClientRpc");
			((NetworkBehaviour)this).__registerRpc(891529785u, new RpcReceiveHandler(__rpc_handler_891529785), "PlayStandardAttackSoundClientRpc");
			((NetworkBehaviour)this).__registerRpc(1310417669u, new RpcReceiveHandler(__rpc_handler_1310417669), "StartChasingLoopClientRpc");
			((NetworkBehaviour)this).__registerRpc(623469361u, new RpcReceiveHandler(__rpc_handler_623469361), "StopChasingLoopClientRpc");
			((NetworkBehaviour)this).__registerRpc(3104341333u, new RpcReceiveHandler(__rpc_handler_3104341333), "DamageTargetPlayerClientRpc");
			((EnemyAI)this).__initializeRpcs();
		}

		private static void __rpc_handler_195252436(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerId = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((CatBrainRotAI)(object)target).KillPlayerClientRpc(playerId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1753015395(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)1;
				((CatBrainRotAI)(object)target).InterruptLoopWithOneShotClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_891529785(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)1;
				((CatBrainRotAI)(object)target).PlayStandardAttackSoundClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1310417669(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)1;
				((CatBrainRotAI)(object)target).StartChasingLoopClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_623469361(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)1;
				((CatBrainRotAI)(object)target).StopChasingLoopClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3104341333(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0043: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerId = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				int damage = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref damage);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((CatBrainRotAI)(object)target).DamageTargetPlayerClientRpc(playerId, damage);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "CatBrainRotAI";
		}
	}
	public class PentagramTrap : NetworkBehaviour
	{
		public GameObject enemyToSpawnPrefab;

		public AudioClip spawnSFX;

		public AudioSource creatureVoice;

		public Animator pentagramAnimator;

		[Header("Trap Settings")]
		public float spawnDelay = 2f;

		[Header("Glow")]
		public Light glowLight;

		public Color glowColor = new Color(1f, 0.2f, 0.05f);

		public float glowIntensity = 4f;

		public float glowRange = 16f;

		private bool hasBeenTriggered;

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

		public override void OnNetworkSpawn()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			((NetworkBehaviour)this).OnNetworkSpawn();
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>();
			if (componentsInChildren != null)
			{
				Renderer[] array = componentsInChildren;
				foreach (Renderer val in array)
				{
					val.enabled = true;
				}
			}
			EnsureGlowLight();
			if ((Object)(object)glowLight != (Object)null)
			{
				glowLight.color = glowColor;
				glowLight.range = glowRange;
				glowLight.intensity = 0f;
				((Behaviour)glowLight).enabled = false;
			}
			_ = (Object)(object)enemyToSpawnPrefab == (Object)null;
		}

		private void EnsureGlowLight()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)glowLight != (Object)null))
			{
				GameObject val = new GameObject("PentagramGlow");
				val.transform.SetParent(((Component)this).transform, false);
				glowLight = val.AddComponent<Light>();
				glowLight.type = (LightType)2;
				glowLight.color = glowColor;
				glowLight.range = glowRange;
				glowLight.intensity = 0f;
				glowLight.shadows = (LightShadows)0;
				((Behaviour)glowLight).enabled = false;
			}
		}

		private void OnTriggerEnter(Collider other)
		{
			//IL_0044: 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)
			if (!hasBeenTriggered && ((NetworkBehaviour)this).IsServer && ((Component)other).CompareTag("Player"))
			{
				PlayerControllerB component = ((Component)other).GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null)
				{
					hasBeenTriggered = true;
					PlayEffectsClientRpc();
					((MonoBehaviour)this).StartCoroutine(SummonAndDestroyRoutine(((Component)this).transform.position, ((Component)this).transform.rotation));
				}
			}
		}

		private IEnumerator SummonAndDestroyRoutine(Vector3 position, Quaternion rotation)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(spawnDelay);
			if ((Object)(object)enemyToSpawnPrefab != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(enemyToSpawnPrefab, position, rotation);
				NetworkObject val2 = default(NetworkObject);
				if (val.TryGetComponent<NetworkObject>(ref val2))
				{
					val2.Spawn(true);
				}
				else
				{
					Object.Destroy((Object)(object)val);
				}
			}
			if (((NetworkBehaviour)this).IsServer && ((NetworkBehaviour)this).NetworkObject.IsSpawned)
			{
				((NetworkBehaviour)this).NetworkObject.Despawn(true);
			}
		}

		[ClientRpc]
		private void PlayEffectsClientRpc()
		{
			//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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(4262207865u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 4262207865u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>();
				foreach (Collider val3 in componentsInChildren)
				{
					val3.enabled = false;
				}
				if ((Object)(object)pentagramAnimator != (Object)null)
				{
					pentagramAnimator.SetTrigger("startGlow");
				}
				if ((Object)(object)spawnSFX != (Object)null && (Object)(object)creatureVoice != (Object)null)
				{
					creatureVoice.PlayOneShot(spawnSFX);
				}
				EnsureGlowLight();
				if ((Object)(object)glowLight != (Object)null)
				{
					glowLight.color = glowColor;
					glowLight.range = glowRange;
					glowLight.intensity = glowIntensity;
					((Behaviour)glowLight).enabled = true;
				}
			}
		}

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

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(4262207865u, new RpcReceiveHandler(__rpc_handler_4262207865), "PlayEffectsClientRpc");
			((NetworkBehaviour)this).__initializeRpcs();
		}

		private static void __rpc_handler_4262207865(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)1;
				((PentagramTrap)(object)target).PlayEffectsClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "PentagramTrap";
		}
	}
	[BepInPlugin("BakaMODs.CatBrainRot", "CatBrainRot", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(RoundManager))]
		internal class PentagramSpawnCounterPatch
		{
			private static bool hasLoggedSpawnCount;

			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			private static void ResetLogFlagPatch()
			{
				hasLoggedSpawnCount = false;
			}

			[HarmonyPatch("SpawnScrapInLevel")]
			[HarmonyPostfix]
			private static void CountSpawnedPentagramsPatch()
			{
				if (!hasLoggedSpawnCount)
				{
					PentagramTrap[] array = Object.FindObjectsOfType<PentagramTrap>();
					int num = array.Length;
					Logger.LogInfo((object)$"A total of {num} pentagrams have spawned in the facility.");
					hasLoggedSpawnCount = true;
				}
			}
		}

		internal static ManualLogSource Logger;

		public static AssetBundle? ModAssets;

		private readonly Harmony harmony = new Harmony("BakaMODs.CatBrainRot");

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			InitializeNetworkBehaviours();
			string path = "catbrainrotassets";
			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 bundle!");
				return;
			}
			Logger.LogInfo((object)"Successfully loaded assets bundle.");
			GameObject val = ModAssets.LoadAsset<GameObject>("catbrainrot 1");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)"Failed to load 'catbrainrot 1' enemy prefab from bundle!");
				return;
			}
			Logger.LogInfo((object)"Successfully loaded enemy prefab.");
			SpawnableMapObjectDef val2 = ModAssets.LoadAsset<SpawnableMapObjectDef>("PentagramTrapMapObject");
			if ((Object)(object)val2 == (Object)null)
			{
				Logger.LogError((object)"Failed to load 'PentagramTrapMapObject' asset from bundle! Check asset name and ensure it's in the bundle.");
				return;
			}
			Logger.LogInfo((object)"Successfully loaded SpawnableMapObjectDef asset.");
			if (val2.spawnableMapObject == null)
			{
				Logger.LogError((object)"'spawnableMapObject' inside the PentagramTrapMapObjectDef is null!");
				return;
			}
			if ((Object)(object)val2.spawnableMapObject.prefabToSpawn == (Object)null)
			{
				Logger.LogError((object)"'prefabToSpawn' inside the PentagramTrapMapObjectDef is null! Make sure you assigned the prefab in the Unity Editor.");
				return;
			}
			Logger.LogInfo((object)"SpawnableMapObjectDef asset seems valid.");
			GameObject prefabToSpawn = val2.spawnableMapObject.prefabToSpawn;
			PentagramTrap pentagramTrap = default(PentagramTrap);
			if (prefabToSpawn.TryGetComponent<PentagramTrap>(ref pentagramTrap))
			{
				pentagramTrap.enemyToSpawnPrefab = val;
				Logger.LogInfo((object)"Successfully found PentagramTrap script and assigned enemy prefab.");
				EnsureUniqueNetworkHash(prefabToSpawn, 1346719316u);
				EnsureUniqueNetworkHash(val, 1128354882u);
				CatBrainRotAI catBrainRotAI = default(CatBrainRotAI);
				if (val.TryGetComponent<CatBrainRotAI>(ref catBrainRotAI))
				{
					if ((Object)(object)((EnemyAI)catBrainRotAI).dieSFX == (Object)null)
					{
						((EnemyAI)catBrainRotAI).dieSFX = catBrainRotAI.standardAttackSFX;
					}
					if (((EnemyAI)catBrainRotAI).enemyBehaviourStates != null)
					{
						EnemyBehaviourState[] enemyBehaviourStates = ((EnemyAI)catBrainRotAI).enemyBehaviourStates;
						foreach (EnemyBehaviourState val3 in enemyBehaviourStates)
						{
							val3.VoiceClip = null;
						}
					}
				}
				Func<SelectableLevel, AnimationCurve> func = (SelectableLevel level) => new AnimationCurve((Keyframe[])(object)new Keyframe[2]
				{
					new Keyframe(0f, 5f),
					new Keyframe(1f, 5f)
				});
				NetworkPrefabs.RegisterNetworkPrefab(prefabToSpawn);
				NetworkPrefabs.RegisterNetworkPrefab(val);
				MapObjects.RegisterMapObject(val2, (LevelTypes)(-1), func);
				harmony.PatchAll(typeof(PentagramSpawnCounterPatch));
				Logger.LogInfo((object)"Plugin BakaMODs.CatBrainRot is loaded!");
			}
			else
			{
				Logger.LogError((object)"Could not find PentagramTrap script on the pentagram prefab!");
			}
		}

		private static void EnsureUniqueNetworkHash(GameObject prefab, uint hash)
		{
			NetworkObject obj = default(NetworkObject);
			if (!((Object)(object)prefab == (Object)null) && prefab.TryGetComponent<NetworkObject>(ref obj))
			{
				FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field == null)
				{
					Logger.LogWarning((object)"Could not find NetworkObject.GlobalObjectIdHash field; prefab hash was not overridden.");
				}
				else
				{
					field.SetValue(obj, hash);
				}
			}
		}

		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);
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BakaMODs.CatBrainRot";

		public const string PLUGIN_NAME = "CatBrainRot";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace CatBrainRot.Configuration
{
	public class PluginConfig
	{
		public ConfigEntry<int> EasyMoonSpawnWeight;

		public ConfigEntry<int> MediumMoonSpawnWeight;

		public ConfigEntry<int> HardMoonSpawnWeight;

		public ConfigEntry<int> ModdedMoonSpawnWeight;

		public PluginConfig(ConfigFile cfg)
		{
			EasyMoonSpawnWeight = cfg.Bind<int>("Spawn Weights", "1. Easy Moons (Experimentation, Assurance, Vow)", 20, "The spawn chance weight on easy moons. Lower is more rare.");
			MediumMoonSpawnWeight = cfg.Bind<int>("Spawn Weights", "2. Medium Moons (Offense, March)", 40, "The spawn chance weight on medium moons. Lower is more rare.");
			HardMoonSpawnWeight = cfg.Bind<int>("Spawn Weights", "3. Hard Moons (Rend, Dine, Titan)", 80, "The spawn chance weight on hard moons. Lower is more rare.");
			ModdedMoonSpawnWeight = cfg.Bind<int>("Spawn Weights", "4. Modded Moons", 80, "The default spawn chance weight for modded moons that are not specified manually.");
			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 __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace BakaMODs.CatBrainRot.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}