Decompiled source of SigmaLabubu v1.0.1

plugins/SigmaLabubu/BakaMODs.SigmaLabubu.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BakaMODs.SigmaLabubu.NetcodePatcher;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using SigmaLabubu.Configuration;
using SigmaLabubu.Spawning;
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("BakaMODs.SigmaLabubu")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SigmaLabubu")]
[assembly: AssemblyTitle("BakaMODs.SigmaLabubu")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedINetworkSerializable<NetworkObjectReference>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<NetworkObjectReference>();
	}
}
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 SigmaLabubu
{
	internal class LabubuPrimeAI : HoarderBugAI
	{
		[CompilerGenerated]
		private sealed class <PrimeVaporDeathRoutine>d__107 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public bool destroy;

			public LabubuPrimeAI <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <PrimeVaporDeathRoutine>d__107(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this.TryMakeNonBlocking();
					<>4__this.TrySpawnDeathFX();
					<>4__this.TryHideModel();
					<>2__current = (object)new WaitForSeconds(0.45f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.<>n__0(destroy);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private const string ANIM_START_WALK = "startWalk";

		private const string ANIM_STOP_WALK = "stopWalk";

		private const string ANIM_DEATH = "KillEnemy";

		private bool walkingAnimActive = false;

		private Animator currentActiveAnimator;

		private static int primeSpawnCount;

		private static readonly int MAX_PRIMES;

		private bool hasSummonedAlly = false;

		private float idleTimer = 0f;

		private float navCheckCooldown = 0f;

		private bool wasHoldingItem = false;

		private float itemSearchCooldown = 0f;

		private float refreshItemsCooldown = 0f;

		private float navDiagLogCooldown = 0f;

		private float doorAssistCooldown = 0f;

		private float doorAssistWaitTimer = 0f;

		private bool colliderDimsInitialized = false;

		private float colliderRadius = 0.4f;

		private float colliderHeight = 1.8f;

		private Vector3 colliderCenter = Vector3.zero;

		private Vector3 lastSetDestination = new Vector3(99999f, 99999f, 99999f);

		private float destinationRefreshCooldown = 0f;

		private static readonly Dictionary<GrabbableObject, LabubuPrimeAI> s_itemReservations;

		private GrabbableObject reservedItem = null;

		private GrabbableObject lastHeldItemRef = null;

		private GrabbableObject lastDroppedItemRef = null;

		private float lastDropTime = 0f;

		private float nextLocalVoiceTime = 0f;

		private static float nextGlobalVoiceTime;

		private float originalVoiceVolume = 1f;

		private bool hadPlayerInSight = false;

		private float voiceSightDwell = 0f;

		private float voiceOutOfSight = 0f;

		private bool voiceArmed = true;

		private float voiceBlockedUntil = 0f;

		private static int organizerVariantIndex;

		private static int sigmaSlotsRemaining;

		private static bool sigmaSlotsDepleted;

		private static readonly HashSet<ulong> variantsWithSigmaActive;

		private bool aggressiveMode = false;

		private bool aggroVoicePlayed = false;

		private readonly Dictionary<PlayerControllerB, GrabbableObject> lastHeldByPlayer = new Dictionary<PlayerControllerB, GrabbableObject>(8);

		private NetworkVariable<int> modelVariantIndex = new NetworkVariable<int>(-1, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public List<GameObject> modelVariants = new List<GameObject>();

		private static bool isNestPositionSet;

		private static Vector3 sharedNestPosition;

		public static List<PlayerControllerB> HuntedPlayers;

		private static int activeSigmaCount;

		public static readonly int MAX_SIGMAS;

		private static Dictionary<PlayerControllerB, SigmaLabubuAI> activeHunts;

		private bool deathSequenceStarted = false;

		private bool IsOrganizer => primeSpawnCount >= 2 && modelVariantIndex.Value == organizerVariantIndex;

		static LabubuPrimeAI()
		{
			primeSpawnCount = 0;
			MAX_PRIMES = 3;
			s_itemReservations = new Dictionary<GrabbableObject, LabubuPrimeAI>(128);
			nextGlobalVoiceTime = 0f;
			organizerVariantIndex = -1;
			sigmaSlotsRemaining = 3;
			sigmaSlotsDepleted = false;
			variantsWithSigmaActive = new HashSet<ulong>();
			isNestPositionSet = false;
			HuntedPlayers = new List<PlayerControllerB>();
			activeSigmaCount = 0;
			MAX_SIGMAS = 3;
			activeHunts = new Dictionary<PlayerControllerB, SigmaLabubuAI>();
			sigmaSlotsRemaining = MAX_SIGMAS;
			sigmaSlotsDepleted = false;
		}

		public static void ResetSigmaSlotsForNewRound()
		{
			sigmaSlotsRemaining = MAX_SIGMAS;
			sigmaSlotsDepleted = false;
			variantsWithSigmaActive.Clear();
		}

		public static void ConsumeSigmaSlot()
		{
			if (!sigmaSlotsDepleted)
			{
				sigmaSlotsRemaining = Mathf.Max(0, sigmaSlotsRemaining - 1);
				if (sigmaSlotsRemaining <= 0)
				{
					sigmaSlotsDepleted = true;
				}
			}
		}

		public static bool CanSpawnMoreSigmas()
		{
			return !sigmaSlotsDepleted && sigmaSlotsRemaining > 0;
		}

		private static void NotifySigmaStartedForSpawner(ulong spawnerId)
		{
			if (spawnerId != 0)
			{
				variantsWithSigmaActive.Add(spawnerId);
			}
		}

		public static void NotifySigmaEndedForSpawner(ulong spawnerId)
		{
			if (spawnerId != 0)
			{
				variantsWithSigmaActive.Remove(spawnerId);
			}
		}

		public override void DoAIInterval()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				((HoarderBugAI)this).DoAIInterval();
			}
			catch (Exception ex)
			{
				try
				{
					Plugin.Logger.LogWarning((object)("[LabubuPrimeAI] base.DoAIInterval NRE: " + ex.Message));
				}
				catch
				{
				}
			}
			if (((EnemyAI)this).isEnemyDead || StartOfRound.Instance.allPlayersDead || (!((NetworkBehaviour)this).IsOwner && !((EnemyAI)this).isClientCalculatingAI))
			{
				return;
			}
			if (sigmaSlotsDepleted)
			{
				aggressiveMode = true;
			}
			if ((Object)(object)((EnemyAI)this).agent != (Object)null)
			{
				Vector3 velocity = ((EnemyAI)this).agent.velocity;
				if (((Vector3)(ref velocity)).sqrMagnitude > 0.1f)
				{
					UpdateWalkAnimation(shouldWalk: true);
					goto IL_00c8;
				}
			}
			UpdateWalkAnimation(shouldWalk: false);
			goto IL_00c8;
			IL_00c8:
			if (aggressiveMode)
			{
				TryAggressiveChaseTick();
				return;
			}
			if (((EnemyAI)this).currentBehaviourStateIndex == 2 && (Object)(object)base.angryAtPlayer != (Object)null)
			{
				((EnemyAI)this).SwitchToBehaviourState(1);
				AttemptToSummonSigma(base.angryAtPlayer);
			}
			DriveHoarderBehaviour();
			PeriodicHousekeeping();
			SigmaTriggerTick();
			KickstartMovementIfStuck();
			DoorAssistTick();
			try
			{
				VoiceOnSightTick();
			}
			catch
			{
			}
			try
			{
				if ((Object)(object)((EnemyAI)this).creatureVoice != (Object)null)
				{
					bool flag = !hadPlayerInSight || Time.time < voiceBlockedUntil;
					if (flag && !((EnemyAI)this).creatureVoice.isPlaying)
					{
						((EnemyAI)this).creatureVoice.mute = true;
					}
					else if (!flag)
					{
						((EnemyAI)this).creatureVoice.mute = false;
					}
				}
			}
			catch
			{
			}
		}

		[ServerRpc(RequireOwnership = false)]
		private void SummonAllyServerRpc()
		{
			//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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(915988411u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 915988411u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && primeSpawnCount < MAX_PRIMES)
			{
				primeSpawnCount++;
				if (!TryFindSafeVariantSpawnNear(((Component)this).transform.position, out var pos) && !TryFindValidIndoorSpawn(out pos))
				{
					Vector3 val3 = ((Component)this).transform.position + Random.insideUnitSphere * 2f;
					val3.y = ((Component)this).transform.position.y;
					NavMeshHit val4 = default(NavMeshHit);
					pos = (NavMesh.SamplePosition(val3, ref val4, 2f, -1) ? ((NavMeshHit)(ref val4)).position : (((Component)this).transform.position + Vector3.up * 0.25f));
				}
				GameObject enemyPrefab = ((EnemyAI)this).enemyType.enemyPrefab;
				if ((Object)(object)enemyPrefab != (Object)null)
				{
					GameObject val5 = Object.Instantiate<GameObject>(enemyPrefab, pos, Quaternion.identity);
					val5.GetComponent<NetworkObject>().Spawn(true);
					Plugin.Logger.LogInfo((object)$"Labubu Prime Ally #{primeSpawnCount} invocado!");
				}
			}
		}

		private void SummonAllyServerSide()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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)
			if (((NetworkBehaviour)this).IsServer && primeSpawnCount < MAX_PRIMES)
			{
				primeSpawnCount++;
				if (!TryFindSafeVariantSpawnNear(((Component)this).transform.position, out var pos) && !TryFindValidIndoorSpawn(out pos))
				{
					Vector3 val = ((Component)this).transform.position + Random.insideUnitSphere * 2f;
					val.y = ((Component)this).transform.position.y;
					NavMeshHit val2 = default(NavMeshHit);
					pos = (NavMesh.SamplePosition(val, ref val2, 2f, -1) ? ((NavMeshHit)(ref val2)).position : (((Component)this).transform.position + Vector3.up * 0.25f));
				}
				GameObject enemyPrefab = ((EnemyAI)this).enemyType.enemyPrefab;
				if ((Object)(object)enemyPrefab != (Object)null)
				{
					GameObject val3 = Object.Instantiate<GameObject>(enemyPrefab, pos, Quaternion.identity);
					val3.GetComponent<NetworkObject>().Spawn(true);
					Plugin.Logger.LogInfo((object)$"Labubu Prime Ally #{primeSpawnCount} invocado!");
				}
			}
		}

		private bool TryFindSafeVariantSpawnNear(Vector3 origin, out Vector3 pos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			pos = Vector3.zero;
			GameObject prefab = (((Object)(object)((EnemyAI)this).enemyType != (Object)null) ? ((EnemyAI)this).enemyType.enemyPrefab : null);
			float radius = 0.45f;
			float height = 1.8f;
			GetVariantColliderDims(prefab, out radius, out height);
			float[] array = new float[3] { 1.2f, 1.8f, 2.4f };
			int[] array2 = new int[6] { 0, 60, -60, 120, -120, 180 };
			NavMeshHit val3 = default(NavMeshHit);
			NavMeshHit val4 = default(NavMeshHit);
			foreach (float num in array)
			{
				foreach (float num2 in array2)
				{
					Vector3 val = Quaternion.AngleAxis(num2, Vector3.up) * ((Component)this).transform.forward;
					Vector3 val2 = origin + val * num;
					try
					{
						if (NavMesh.SamplePosition(val2, ref val3, 1.2f, -1))
						{
							Vector3 position = ((NavMeshHit)(ref val3)).position;
							if (!(Mathf.Abs(position.y - origin.y) > 1f) && !NavMesh.Raycast(origin, position, ref val4, -1) && HasFreeCapsuleAtWithDims(position, radius, height))
							{
								pos = position;
								return true;
							}
						}
					}
					catch
					{
					}
				}
			}
			return false;
		}

		private void GetVariantColliderDims(GameObject prefab, out float radius, out float height)
		{
			radius = 0.45f;
			height = 1.8f;
			try
			{
				if (!((Object)(object)prefab != (Object)null))
				{
					return;
				}
				CapsuleCollider componentInChildren = prefab.GetComponentInChildren<CapsuleCollider>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					radius = Mathf.Max(0.2f, componentInChildren.radius);
					height = Mathf.Max(1f, componentInChildren.height);
					return;
				}
				NavMeshAgent component = prefab.GetComponent<NavMeshAgent>();
				if ((Object)(object)component != (Object)null)
				{
					radius = Mathf.Max(0.2f, component.radius);
					height = Mathf.Max(1f, component.height);
				}
			}
			catch
			{
			}
		}

		[ServerRpc(RequireOwnership = false)]
		private void SummonSigmaServerRpc(ulong targetPlayerClientId)
		{
			//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_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: 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.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1484071541u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, targetPlayerClientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1484071541u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
			{
				return;
			}
			ulong targetPlayerClientId2 = targetPlayerClientId;
			PlayerControllerB val3 = ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB p) => p.actualClientId == targetPlayerClientId2));
			if ((Object)(object)val3 == (Object)null)
			{
				try
				{
					Plugin.Logger.LogWarning((object)"[SigmaSummon] Abort: targetPlayer null");
					return;
				}
				catch
				{
					return;
				}
			}
			if (HuntedPlayers.Contains(val3))
			{
				try
				{
					Plugin.Logger.LogInfo((object)("[SigmaSummon] Abort: " + val3.playerUsername + " already hunted"));
					return;
				}
				catch
				{
					return;
				}
			}
			if (activeSigmaCount >= MAX_SIGMAS)
			{
				try
				{
					Plugin.Logger.LogInfo((object)"[SigmaSummon] Abort: activeSigmaCount >= MAX_SIGMAS");
					return;
				}
				catch
				{
					return;
				}
			}
			if (!CanSpawnMoreSigmas())
			{
				try
				{
					Plugin.Logger.LogInfo((object)$"[SigmaSummon] Abort: sigma slots depleted (remaining={sigmaSlotsRemaining})");
					return;
				}
				catch
				{
					return;
				}
			}
			NetworkObject component = ((Component)this).GetComponent<NetworkObject>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			ulong networkObjectId = component.NetworkObjectId;
			if (variantsWithSigmaActive.Contains(networkObjectId))
			{
				try
				{
					Plugin.Logger.LogInfo((object)$"[SigmaSummon] Abort: variant {networkObjectId} already has Sigma");
					return;
				}
				catch
				{
					return;
				}
			}
			HuntedPlayers.Add(val3);
			activeSigmaCount++;
			GameObject sigmaLabubuPrefab = Plugin.SigmaLabubuPrefab;
			if ((Object)(object)sigmaLabubuPrefab == (Object)null)
			{
				try
				{
					Plugin.Logger.LogError((object)"[SigmaSummon] Abort: SigmaLabubuPrefab is null");
					return;
				}
				catch
				{
					return;
				}
			}
			if (!TryFindSafeSigmaSpawnNear(((Component)this).transform.position, ((Component)this).transform.forward, out var pos))
			{
				Vector3 val4 = ((Component)this).transform.position - ((Component)this).transform.forward * 2f + Vector3.up * 0.25f;
				NavMeshHit val5 = default(NavMeshHit);
				pos = (NavMesh.SamplePosition(val4, ref val5, 2f, -1) ? ((NavMeshHit)(ref val5)).position : (((Component)this).transform.position + Vector3.up * 0.25f));
			}
			GameObject val6 = Object.Instantiate<GameObject>(sigmaLabubuPrefab, pos, Quaternion.identity);
			val6.GetComponent<NetworkObject>().Spawn(true);
			SigmaLabubuAI component2 = val6.GetComponent<SigmaLabubuAI>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.targetPlayerRef.Value = NetworkObjectReference.op_Implicit(((Component)val3).GetComponent<NetworkObject>());
				component2.SetSpawnerVariant(networkObjectId);
				activeHunts[val3] = component2;
			}
			NotifySigmaStartedForSpawner(networkObjectId);
			try
			{
				Plugin.Logger.LogInfo((object)$"[SigmaSummon] Spawned Sigma at {pos} for {val3.playerUsername} by variant {networkObjectId}");
			}
			catch
			{
			}
			ScreamAndRetreatLocal();
		}

		private void SummonSigmaServerSide(PlayerControllerB targetPlayer)
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsServer || (Object)(object)targetPlayer == (Object)null || HuntedPlayers.Contains(targetPlayer) || activeSigmaCount >= MAX_SIGMAS || !CanSpawnMoreSigmas())
			{
				return;
			}
			NetworkObject component = ((Component)this).GetComponent<NetworkObject>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			ulong networkObjectId = component.NetworkObjectId;
			if (variantsWithSigmaActive.Contains(networkObjectId))
			{
				return;
			}
			HuntedPlayers.Add(targetPlayer);
			activeSigmaCount++;
			GameObject sigmaLabubuPrefab = Plugin.SigmaLabubuPrefab;
			if (!((Object)(object)sigmaLabubuPrefab == (Object)null))
			{
				if (!TryFindSafeSigmaSpawnNear(((Component)this).transform.position, ((Component)this).transform.forward, out var pos))
				{
					Vector3 val = ((Component)this).transform.position - ((Component)this).transform.forward * 2f + Vector3.up * 0.25f;
					NavMeshHit val2 = default(NavMeshHit);
					pos = (NavMesh.SamplePosition(val, ref val2, 2f, -1) ? ((NavMeshHit)(ref val2)).position : (((Component)this).transform.position + Vector3.up * 0.25f));
				}
				GameObject val3 = Object.Instantiate<GameObject>(sigmaLabubuPrefab, pos, Quaternion.identity);
				val3.GetComponent<NetworkObject>().Spawn(true);
				SigmaLabubuAI component2 = val3.GetComponent<SigmaLabubuAI>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.targetPlayerRef.Value = NetworkObjectReference.op_Implicit(((Component)targetPlayer).GetComponent<NetworkObject>());
					component2.SetSpawnerVariant(networkObjectId);
					activeHunts[targetPlayer] = component2;
				}
				NotifySigmaStartedForSpawner(networkObjectId);
				ScreamAndRetreatLocal();
			}
		}

		private bool TryFindSafeSigmaSpawnNear(Vector3 origin, Vector3 forward, out Vector3 pos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_009f: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			pos = Vector3.zero;
			float radius = 0.4f;
			float height = 1.8f;
			GetSigmaColliderDims(out radius, out height);
			float[] array = new float[4] { 1f, 1.5f, 2f, 2.5f };
			int[] array2 = new int[12]
			{
				180, 150, -150, 120, -120, 90, -90, 60, -60, 30,
				-30, 0
			};
			NavMeshHit val3 = default(NavMeshHit);
			NavMeshHit val4 = default(NavMeshHit);
			foreach (float num in array)
			{
				foreach (float num2 in array2)
				{
					Vector3 val = Quaternion.AngleAxis(num2, Vector3.up) * ((Vector3)(ref forward)).normalized;
					Vector3 val2 = origin + -val * num + Vector3.up * 0.1f;
					try
					{
						if (NavMesh.SamplePosition(val2, ref val3, 1.5f, -1))
						{
							Vector3 position = ((NavMeshHit)(ref val3)).position;
							if (!(Mathf.Abs(position.y - origin.y) > 1f) && !NavMesh.Raycast(origin, position, ref val4, -1) && HasFreeCapsuleAtWithDims(position, radius, height))
							{
								pos = position;
								return true;
							}
						}
					}
					catch
					{
					}
				}
			}
			return false;
		}

		private void GetSigmaColliderDims(out float radius, out float height)
		{
			radius = 0.4f;
			height = 1.8f;
			try
			{
				GameObject sigmaLabubuPrefab = Plugin.SigmaLabubuPrefab;
				if (!((Object)(object)sigmaLabubuPrefab != (Object)null))
				{
					return;
				}
				CapsuleCollider componentInChildren = sigmaLabubuPrefab.GetComponentInChildren<CapsuleCollider>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					radius = Mathf.Max(0.2f, componentInChildren.radius);
					height = Mathf.Max(1f, componentInChildren.height);
					return;
				}
				NavMeshAgent component = sigmaLabubuPrefab.GetComponent<NavMeshAgent>();
				if ((Object)(object)component != (Object)null)
				{
					radius = Mathf.Max(0.2f, component.radius);
					height = Mathf.Max(1f, component.height);
				}
			}
			catch
			{
			}
		}

		private bool HasFreeCapsuleAtWithDims(Vector3 centerPos, float radius, float height)
		{
			//IL_0010: 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_001d: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0031: 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)
			try
			{
				float num = Mathf.Max(radius, height * 0.5f);
				Vector3 val = Vector3.up * (num - radius);
				Vector3 val2 = centerPos + val;
				Vector3 val3 = centerPos - val;
				int num2 = -1;
				Collider[] array = Physics.OverlapCapsule(val2, val3, radius, num2, (QueryTriggerInteraction)1);
				foreach (Collider val4 in array)
				{
					if (!((Object)(object)val4 == (Object)null) && !val4.isTrigger)
					{
						return false;
					}
				}
				return true;
			}
			catch
			{
			}
			return false;
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			if (((NetworkBehaviour)this).IsServer)
			{
				if (modelVariants.Count > 0)
				{
					int num = ((primeSpawnCount > 0) ? (primeSpawnCount - 1) : 0);
					num = Mathf.Clamp(num, 0, modelVariants.Count - 1);
					modelVariantIndex.Value = num;
					Plugin.Logger.LogInfo((object)$"[Variants] Assigned variant index {num} (primeSpawnCount={primeSpawnCount}).");
				}
				if (organizerVariantIndex == -1 && primeSpawnCount >= 2)
				{
					organizerVariantIndex = 0;
					Plugin.Logger.LogInfo((object)$"[Organizer] Activated: variant index {organizerVariantIndex} organizes/guards nest items.");
				}
				RarityBoostController.NotifyLabubuPrimeSpawned();
			}
			if (((NetworkBehaviour)this).IsOwner)
			{
				EnsureOnNavMeshAndKickstart();
				try
				{
					((EnemyAI)this).SwitchToBehaviourState(0);
				}
				catch
				{
				}
				if ((Object)(object)((EnemyAI)this).agent != (Object)null)
				{
					((EnemyAI)this).agent.isStopped = false;
					try
					{
						((EnemyAI)this).agent.autoBraking = false;
					}
					catch
					{
					}
					try
					{
						NetworkObject component = ((Component)this).GetComponent<NetworkObject>();
						if ((Object)(object)component != (Object)null)
						{
							int num2 = 40;
							((EnemyAI)this).agent.avoidancePriority = Mathf.Clamp(num2 + (int)(component.NetworkObjectId % 40), 20, 80);
						}
					}
					catch
					{
					}
					float num3 = Mathf.Max(0.1f, Plugin.BoundConfig.AgentSpeed.Value);
					float num4 = Mathf.Max(0.1f, Plugin.BoundConfig.AgentAcceleration.Value);
					if (((EnemyAI)this).agent.speed < num3)
					{
						((EnemyAI)this).agent.speed = num3;
					}
					if (((EnemyAI)this).agent.acceleration < num4)
					{
						((EnemyAI)this).agent.acceleration = num4;
					}
				}
				try
				{
					HoarderBugAI.RefreshGrabbableObjectsInMapList();
				}
				catch
				{
				}
			}
			NetworkVariable<int> obj5 = modelVariantIndex;
			obj5.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Combine((Delegate?)(object)obj5.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(OnModelVariantChanged));
			SetModelVariant(modelVariantIndex.Value);
			try
			{
				FixCollisionDetectMainScript();
			}
			catch (Exception)
			{
			}
			try
			{
				if ((Object)(object)((EnemyAI)this).creatureVoice != (Object)null)
				{
					originalVoiceVolume = Mathf.Max(0.01f, ((EnemyAI)this).creatureVoice.volume);
				}
			}
			catch
			{
			}
		}

		public override void OnNetworkDespawn()
		{
			((NetworkBehaviour)this).OnNetworkDespawn();
			NetworkVariable<int> obj = modelVariantIndex;
			obj.OnValueChanged = (OnValueChangedDelegate<int>)(object)Delegate.Remove((Delegate?)(object)obj.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<int>(OnModelVariantChanged));
		}

		private void OnModelVariantChanged(int previousValue, int newValue)
		{
			SetModelVariant(newValue);
		}

		private void SetModelVariant(int index)
		{
			if (modelVariants.Count == 0 || index < 0 || index >= modelVariants.Count)
			{
				return;
			}
			for (int i = 0; i < modelVariants.Count; i++)
			{
				if ((Object)(object)modelVariants[i] != (Object)null)
				{
					bool flag = i == index;
					modelVariants[i].SetActive(flag);
					if (flag)
					{
						currentActiveAnimator = modelVariants[i].GetComponentInChildren<Animator>();
						((EnemyAI)this).creatureAnimator = currentActiveAnimator;
						TryBindAudioSourcesFromModel(modelVariants[i]);
					}
				}
			}
		}

		public override void Start()
		{
			//IL_004a: 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_001c: 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)
			((HoarderBugAI)this).Start();
			if (!isNestPositionSet)
			{
				sharedNestPosition = ((EnemyAI)this).ChooseClosestNodeToPosition(((Component)this).transform.position, false, 0).position;
				isNestPositionSet = true;
				primeSpawnCount = Mathf.Max(primeSpawnCount, 1);
			}
			base.nestPosition = sharedNestPosition;
		}

		[ClientRpc]
		private void SyncSharedNestPositionClientRpc(Vector3 nestPos)
		{
			//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_0089: 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_00ca: 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_00d5: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2797527559u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref nestPos);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2797527559u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					sharedNestPosition = nestPos;
					base.nestPosition = sharedNestPosition;
					isNestPositionSet = true;
				}
			}
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			((HoarderBugAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID);
			if (!((EnemyAI)this).isEnemyDead && ((NetworkBehaviour)this).IsOwner && (Object)(object)playerWhoHit != (Object)null)
			{
				AttemptToSummonSigma(playerWhoHit);
			}
		}

		private void AttemptToSummonSigma(PlayerControllerB triggeredByPlayer)
		{
			if (activeSigmaCount < MAX_SIGMAS && !HuntedPlayers.Contains(triggeredByPlayer) && ((NetworkBehaviour)this).IsServer)
			{
				SummonSigmaServerSide(triggeredByPlayer);
			}
		}

		private void ScreamAndRetreatLocal()
		{
			TryPlayVoiceSafe((base.angryScreechSFX != null && base.angryScreechSFX.Length != 0) ? base.angryScreechSFX[0] : null);
			((EnemyAI)this).SwitchToBehaviourState(1);
		}

		public static void ReleaseHuntedPlayer(PlayerControllerB target)
		{
			if ((Object)(object)target != (Object)null && HuntedPlayers.Contains(target))
			{
				HuntedPlayers.Remove(target);
				activeHunts.Remove(target);
			}
			HuntedPlayers.RemoveAll((PlayerControllerB p) => (Object)(object)p == (Object)null || p.isPlayerDead);
		}

		public static void ReportSigmaDestroyed(PlayerControllerB targetNoLongerHunted)
		{
			ReleaseHuntedPlayer(targetNoLongerHunted);
			activeSigmaCount--;
			if (activeSigmaCount < 0)
			{
				activeSigmaCount = 0;
			}
		}

		private void OnDisable()
		{
			try
			{
				ReleaseReservation(reservedItem);
			}
			catch
			{
			}
		}

		public override void OnDestroy()
		{
			try
			{
				ReleaseReservation(reservedItem);
			}
			catch
			{
			}
			try
			{
				NetworkObject component = ((Component)this).GetComponent<NetworkObject>();
				if ((Object)(object)component != (Object)null)
				{
					NotifySigmaEndedForSpawner(component.NetworkObjectId);
				}
			}
			catch
			{
			}
			((EnemyAI)this).OnDestroy();
			if (((NetworkBehaviour)this).IsServer)
			{
				primeSpawnCount = 0;
				isNestPositionSet = false;
				HuntedPlayers.Clear();
				activeSigmaCount = 0;
				activeHunts.Clear();
				organizerVariantIndex = -1;
			}
		}

		private static bool TryFindValidIndoorSpawn(out Vector3 pos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_00b7: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			pos = Vector3.zero;
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance == (Object)null || instance.insideAINodes == null || instance.insideAINodes.Length == 0)
			{
				return false;
			}
			Vector3 val = (((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)StartOfRound.Instance.elevatorTransform != (Object)null) ? StartOfRound.Instance.elevatorTransform.position : RoundManager.FindMainEntrancePosition(true, false));
			PlayerControllerB[] array = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.allPlayerScripts : null);
			NavMeshHit val3 = default(NavMeshHit);
			for (int i = 0; i < 40; i++)
			{
				Vector3 position = instance.insideAINodes[Random.Range(0, instance.insideAINodes.Length)].transform.position;
				Vector3 val2 = Random.insideUnitSphere * Random.Range(4f, 10f);
				val2.y = 0f;
				if (!NavMesh.SamplePosition(position + val2, ref val3, 8f, -1))
				{
					continue;
				}
				Vector3 position2 = ((NavMeshHit)(ref val3)).position;
				if (Vector3.Distance(position2, val) < 16f)
				{
					continue;
				}
				bool flag = false;
				if (array != null)
				{
					PlayerControllerB[] array2 = array;
					foreach (PlayerControllerB val4 in array2)
					{
						if (!((Object)(object)val4 == (Object)null) && !val4.isPlayerDead && Vector3.Distance(position2, ((Component)val4).transform.position) < 16f)
						{
							flag = true;
							break;
						}
					}
				}
				if (!flag)
				{
					pos = position2;
					return true;
				}
			}
			return false;
		}

		private void FixCollisionDetectMainScript()
		{
			EnemyAICollisionDetect[] componentsInChildren = ((Component)this).GetComponentsInChildren<EnemyAICollisionDetect>(true);
			if (componentsInChildren == null)
			{
				return;
			}
			EnemyAICollisionDetect[] array = componentsInChildren;
			foreach (EnemyAICollisionDetect val in array)
			{
				if (!((Object)(object)val == (Object)null) && (Object)(object)val.mainScript == (Object)null)
				{
					val.mainScript = (EnemyAI)(object)this;
				}
			}
		}

		private void EnsureOnNavMeshAndKickstart()
		{
			//IL_0116: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((EnemyAI)this).agent == (Object)null)
			{
				((EnemyAI)this).agent = ((Component)this).GetComponent<NavMeshAgent>();
			}
			NavMeshHit val = default(NavMeshHit);
			if ((Object)(object)((EnemyAI)this).agent != (Object)null && !((EnemyAI)this).agent.isOnNavMesh && NavMesh.SamplePosition(((Component)this).transform.position, ref val, 6f, -1))
			{
				((EnemyAI)this).agent.Warp(((NavMeshHit)(ref val)).position);
			}
			if ((Object)(object)((EnemyAI)this).agent != (Object)null && ((EnemyAI)this).agent.isOnNavMesh)
			{
				((EnemyAI)this).agent.autoRepath = true;
				((EnemyAI)this).agent.autoTraverseOffMeshLink = true;
				((EnemyAI)this).agent.stoppingDistance = 0.15f;
				((EnemyAI)this).agent.updateRotation = true;
				((EnemyAI)this).agent.isStopped = false;
				try
				{
					((EnemyAI)this).openDoorSpeedMultiplier = Mathf.Max(((EnemyAI)this).openDoorSpeedMultiplier, Plugin.BoundConfig.OpenDoorSpeedMultiplier.Value);
				}
				catch
				{
				}
				if (TryFindValidIndoorSpawn(out var pos))
				{
					SetDestinationThrottled(pos);
				}
			}
		}

		private void KickstartMovementIfStuck()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Invalid comparison between Unknown and I4
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((EnemyAI)this).agent == (Object)null || !((EnemyAI)this).agent.isOnNavMesh)
			{
				return;
			}
			navCheckCooldown -= ((EnemyAI)this).AIIntervalTime;
			navDiagLogCooldown -= ((EnemyAI)this).AIIntervalTime;
			Vector3 velocity = ((EnemyAI)this).agent.velocity;
			if (((Vector3)(ref velocity)).sqrMagnitude < 0.01f)
			{
				idleTimer += ((EnemyAI)this).AIIntervalTime;
			}
			else
			{
				idleTimer = 0f;
			}
			if (!(navCheckCooldown <= 0f))
			{
				return;
			}
			navCheckCooldown = 2f;
			float num = Mathf.Max(0.1f, Plugin.BoundConfig.IdleSecondsBeforeKickstart.Value);
			if (!(idleTimer >= num) && ((EnemyAI)this).agent.hasPath && (int)((EnemyAI)this).agent.pathStatus != 2)
			{
				return;
			}
			if (Plugin.BoundConfig.EnableNavDiagnostics.Value && navDiagLogCooldown <= 0f)
			{
				ManualLogSource logger = Plugin.Logger;
				object[] obj = new object[7]
				{
					modelVariantIndex.Value,
					((EnemyAI)this).agent.isOnNavMesh,
					((EnemyAI)this).agent.hasPath,
					((EnemyAI)this).agent.pathStatus,
					((EnemyAI)this).agent.isStopped,
					((EnemyAI)this).agent.remainingDistance,
					null
				};
				velocity = ((EnemyAI)this).agent.velocity;
				obj[6] = ((Vector3)(ref velocity)).magnitude;
				logger.LogInfo((object)string.Format("[NavDiag] LabubuPrime v{0} stuck: onNavMesh={1} hasPath={2} pathStatus={3} isStopped={4} remaining={5:F2} vel={6:F2}", obj));
				navDiagLogCooldown = 3f;
			}
			ResetNestWaitModes();
			if (!TryFindValidIndoorSpawn(out var pos))
			{
				return;
			}
			if (!IsOrganizer && Vector3.Distance(pos, base.nestPosition) < 6f)
			{
				for (int i = 0; i < 5; i++)
				{
					if (!(Vector3.Distance(pos, base.nestPosition) < 6f))
					{
						break;
					}
					if (!TryFindValidIndoorSpawn(out var pos2))
					{
						break;
					}
					pos = pos2;
				}
			}
			SetDestinationThrottled(pos);
			idleTimer = 0f;
		}

		private void DoorAssistTick()
		{
			//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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((EnemyAI)this).agent == (Object)null || !((EnemyAI)this).agent.isOnNavMesh)
			{
				return;
			}
			doorAssistCooldown -= ((EnemyAI)this).AIIntervalTime;
			if (doorAssistCooldown < 0f)
			{
				doorAssistCooldown = 0f;
			}
			if (doorAssistWaitTimer > 0f)
			{
				doorAssistWaitTimer -= ((EnemyAI)this).AIIntervalTime;
			}
			Vector3 velocity = ((EnemyAI)this).agent.velocity;
			if (((Vector3)(ref velocity)).sqrMagnitude > 0.01f)
			{
				return;
			}
			Vector3 val = ((Component)this).transform.forward;
			float num = float.MaxValue;
			if (((EnemyAI)this).agent.hasPath && ((EnemyAI)this).agent.path != null)
			{
				Vector3[] corners = ((EnemyAI)this).agent.path.corners;
				if (corners != null && corners.Length >= 2)
				{
					Vector3 val2 = corners[1] - ((Component)this).transform.position;
					num = ((Vector3)(ref val2)).magnitude;
					if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
					{
						val = ((Vector3)(ref val2)).normalized;
					}
				}
			}
			if (doorAssistCooldown <= 0f)
			{
				float num2 = Mathf.Max(0.5f, (Plugin.BoundConfig?.DoorScanRadius?.Value).GetValueOrDefault(2.5f));
				Vector3 val3 = ((Component)this).transform.position + val * 1f;
				try
				{
					Collider[] array = Physics.OverlapSphere(val3, num2, -1, (QueryTriggerInteraction)2);
					for (int i = 0; i < array.Length; i++)
					{
						if ((Object)(object)array[i] == (Object)null)
						{
							continue;
						}
						DoorLock val4 = ((Component)array[i]).GetComponentInParent<DoorLock>();
						if ((Object)(object)val4 == (Object)null)
						{
							val4 = ((Component)array[i]).GetComponent<DoorLock>();
						}
						if (!((Object)(object)val4 == (Object)null))
						{
							try
							{
								val4.OpenDoorAsEnemyServerRpc();
							}
							catch
							{
							}
							try
							{
								val4.OpenDoorAsEnemy(true);
							}
							catch
							{
							}
							doorAssistCooldown = 0.25f;
							doorAssistWaitTimer = Mathf.Max(0.1f, (Plugin.BoundConfig?.DoorAssistMaxWaitSeconds?.Value).GetValueOrDefault(1f));
							return;
						}
					}
				}
				catch
				{
				}
			}
			if (!(doorAssistWaitTimer <= 0f) || !(num <= 2.75f))
			{
				return;
			}
			float maxDistance = Mathf.Max(0.2f, (Plugin.BoundConfig?.DoorBypassOffset?.Value).GetValueOrDefault(1.6f));
			if (!TryFindSafeBypassPosition(val, maxDistance, out var safePos))
			{
				return;
			}
			try
			{
				((EnemyAI)this).agent.Warp(safePos);
				if (TryFindValidIndoorSpawn(out var pos))
				{
					SetDestinationThrottled(pos);
				}
				idleTimer = 0f;
				doorAssistCooldown = 0.3f;
			}
			catch
			{
			}
		}

		private bool TryFindSafeBypassPosition(Vector3 dir, float maxDistance, out Vector3 safePos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0062: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00ba: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			safePos = Vector3.zero;
			InitializeColliderDimsIfNeeded();
			float[] array = new float[3] { 0.7f, 1f, 1.3f };
			NavMeshHit val3 = default(NavMeshHit);
			NavMeshHit val4 = default(NavMeshHit);
			for (int i = 0; i < array.Length; i++)
			{
				float num = Mathf.Clamp(maxDistance * array[i], 0.2f, maxDistance * 1.5f);
				Vector3 val = ((Component)this).transform.position + ((Vector3)(ref dir)).normalized * num;
				Vector3 val2 = val;
				try
				{
					if (NavMesh.SamplePosition(val, ref val3, 1f, -1))
					{
						val2 = ((NavMeshHit)(ref val3)).position;
						if (!(Mathf.Abs(val2.y - ((Component)this).transform.position.y) > 0.75f) && !NavMesh.Raycast(((Component)this).transform.position, val2, ref val4, -1) && HasFreeCapsuleAt(val2))
						{
							safePos = val2;
							return true;
						}
					}
				}
				catch
				{
				}
			}
			return false;
		}

		private void InitializeColliderDimsIfNeeded()
		{
			//IL_0040: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			if (colliderDimsInitialized)
			{
				return;
			}
			colliderDimsInitialized = true;
			try
			{
				CapsuleCollider componentInChildren = ((Component)this).GetComponentInChildren<CapsuleCollider>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					colliderRadius = Mathf.Max(0.1f, componentInChildren.radius * Mathf.Max(((Component)this).transform.lossyScale.x, ((Component)this).transform.lossyScale.z));
					colliderHeight = Mathf.Max(0.5f, componentInChildren.height * ((Component)this).transform.lossyScale.y);
					Bounds bounds = ((Collider)componentInChildren).bounds;
					colliderCenter = ((Bounds)(ref bounds)).center - Vector3.up * (colliderHeight * 0.5f - colliderRadius);
					return;
				}
			}
			catch
			{
			}
			try
			{
				if ((Object)(object)((EnemyAI)this).agent != (Object)null)
				{
					colliderRadius = Mathf.Max(0.1f, ((EnemyAI)this).agent.radius);
					colliderHeight = Mathf.Max(1f, ((EnemyAI)this).agent.height);
					colliderCenter = ((Component)this).transform.position + Vector3.up * (colliderHeight * 0.5f - colliderRadius);
				}
			}
			catch
			{
			}
		}

		private bool HasFreeCapsuleAt(Vector3 centerPos)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_002f: 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)
			//IL_0035: 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_0037: 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_0040: 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)
			try
			{
				float num = Mathf.Max(colliderRadius, colliderHeight * 0.5f);
				Vector3 val = Vector3.up * (num - colliderRadius);
				Vector3 val2 = centerPos + val;
				Vector3 val3 = centerPos - val;
				int num2 = -1;
				Collider[] array = Physics.OverlapCapsule(val2, val3, colliderRadius, num2, (QueryTriggerInteraction)1);
				foreach (Collider val4 in array)
				{
					if (!((Object)(object)val4 == (Object)null) && !((Component)val4).transform.IsChildOf(((Component)this).transform) && !val4.isTrigger)
					{
						return false;
					}
				}
				return true;
			}
			catch
			{
			}
			return false;
		}

		private void DriveHoarderBehaviour()
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: 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_0216: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			if (!wasHoldingItem && base.heldItem != null)
			{
				OnItemGrabbed();
			}
			else if (wasHoldingItem && base.heldItem == null)
			{
				OnItemDropped();
			}
			wasHoldingItem = base.heldItem != null;
			if (base.heldItem != null)
			{
				try
				{
					lastHeldItemRef = base.heldItem.itemGrabbableObject;
				}
				catch
				{
					lastHeldItemRef = null;
				}
			}
			if (base.heldItem != null)
			{
				if (Vector3.Distance(((Component)this).transform.position, base.nestPosition) > 1.5f)
				{
					SetDestinationThrottled(base.nestPosition);
				}
				return;
			}
			itemSearchCooldown -= ((EnemyAI)this).AIIntervalTime;
			if ((Object)(object)base.targetItem == (Object)null && itemSearchCooldown <= 0f)
			{
				itemSearchCooldown = 0.5f;
				GrabbableObject val = ((!IsOrganizer) ? FindClosestGrabbableItem(skipReserved: true) : FindItemForOrganizer(1.5f, 6f, skipReserved: true));
				Vector3 pos;
				if ((Object)(object)val != (Object)null)
				{
					if (TryReserveItem(val))
					{
						base.targetItem = val;
						SetDestinationThrottled(((Component)val).transform.position);
					}
				}
				else if (!IsOrganizer && TryFindValidIndoorSpawn(out pos))
				{
					if (!IsOrganizer && Vector3.Distance(pos, base.nestPosition) < 6f)
					{
						for (int i = 0; i < 5; i++)
						{
							if (!(Vector3.Distance(pos, base.nestPosition) < 6f))
							{
								break;
							}
							if (!TryFindValidIndoorSpawn(out var pos2))
							{
								break;
							}
							pos = pos2;
						}
					}
					SetDestinationThrottled(pos);
				}
				else if (IsOrganizer)
				{
					SetDestinationThrottled(base.nestPosition);
				}
			}
			if ((Object)(object)base.targetItem != (Object)null)
			{
				SetDestinationThrottled(((Component)base.targetItem).transform.position);
			}
		}

		private void OnItemGrabbed()
		{
			if (!hasSummonedAlly && primeSpawnCount < MAX_PRIMES)
			{
				if (((NetworkBehaviour)this).IsServer)
				{
					SummonAllyServerSide();
				}
				hasSummonedAlly = true;
				Plugin.Logger.LogInfo((object)"[Variants] Item grabbed; summoning next Labubu Prime variant.");
				if (organizerVariantIndex == -1 && primeSpawnCount >= 2)
				{
					organizerVariantIndex = 0;
					Plugin.Logger.LogInfo((object)$"[Organizer] Activated post-grab: variant {organizerVariantIndex} organizes/guards nest.");
				}
			}
			try
			{
				ReleaseReservation(reservedItem);
			}
			catch
			{
			}
			try
			{
				nextLocalVoiceTime = Mathf.Max(nextLocalVoiceTime, Time.time + 2.5f);
				voiceBlockedUntil = Mathf.Max(voiceBlockedUntil, Time.time + 2f);
			}
			catch
			{
			}
		}

		private void OnItemDropped()
		{
			//IL_007a: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			base.targetItem = null;
			try
			{
				ReleaseReservation(reservedItem);
			}
			catch
			{
			}
			ResetNestWaitModes();
			if ((Object)(object)lastHeldItemRef != (Object)null)
			{
				lastDroppedItemRef = lastHeldItemRef;
				lastDropTime = Time.time;
			}
			try
			{
				((EnemyAI)this).SwitchToBehaviourState(0);
			}
			catch
			{
			}
			if (!IsOrganizer && TryFindValidIndoorSpawn(out var pos))
			{
				if (Vector3.Distance(pos, base.nestPosition) < 6f)
				{
					for (int i = 0; i < 5; i++)
					{
						if (!(Vector3.Distance(pos, base.nestPosition) < 6f))
						{
							break;
						}
						if (!TryFindValidIndoorSpawn(out var pos2))
						{
							break;
						}
						pos = pos2;
					}
				}
				((EnemyAI)this).SetDestinationToPosition(pos, false);
			}
			try
			{
				nextLocalVoiceTime = Mathf.Max(nextLocalVoiceTime, Time.time + 2f);
				voiceBlockedUntil = Mathf.Max(voiceBlockedUntil, Time.time + 1.5f);
			}
			catch
			{
			}
		}

		private GrabbableObject FindClosestGrabbableItem(bool skipReserved = false)
		{
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject result = null;
			float num = float.MaxValue;
			List<GrabbableObject> list = new List<GrabbableObject>(64);
			try
			{
				List<HoarderBugItem> hoarderBugItems = HoarderBugAI.HoarderBugItems;
				if (hoarderBugItems != null)
				{
					for (int i = 0; i < hoarderBugItems.Count; i++)
					{
						HoarderBugItem val = hoarderBugItems[i];
						if (val != null && (Object)(object)val.itemGrabbableObject != (Object)null)
						{
							list.Add(val.itemGrabbableObject);
						}
					}
				}
			}
			catch
			{
			}
			try
			{
				List<GameObject> grabbableObjectsInMap = HoarderBugAI.grabbableObjectsInMap;
				if (grabbableObjectsInMap != null)
				{
					for (int j = 0; j < grabbableObjectsInMap.Count; j++)
					{
						GameObject val2 = grabbableObjectsInMap[j];
						if (!((Object)(object)val2 == (Object)null))
						{
							GrabbableObject component = val2.GetComponent<GrabbableObject>();
							if ((Object)(object)component != (Object)null)
							{
								list.Add(component);
							}
						}
					}
				}
			}
			catch
			{
			}
			for (int k = 0; k < list.Count; k++)
			{
				GrabbableObject val3 = list[k];
				if ((Object)(object)val3 == (Object)null || !val3.grabbableToEnemies || val3.deactivated || (skipReserved && IsItemReservedByOther(val3)))
				{
					continue;
				}
				if (!IsOrganizer)
				{
					float num2 = Vector3.Distance(((Component)val3).transform.position, base.nestPosition);
					if (num2 < 2.5f)
					{
						continue;
					}
				}
				else
				{
					float num3 = Vector3.Distance(((Component)val3).transform.position, base.nestPosition);
					if (num3 < 1.5f || ((Object)(object)lastDroppedItemRef != (Object)null && (Object)(object)val3 == (Object)(object)lastDroppedItemRef && Time.time - lastDropTime < 3f))
					{
						continue;
					}
				}
				float num4 = Vector3.Distance(((Component)this).transform.position, ((Component)val3).transform.position);
				if (num4 < num)
				{
					result = val3;
					num = num4;
				}
			}
			return result;
		}

		private GrabbableObject FindItemForOrganizer(float minNestDistance, float maxNestDistance, bool skipReserved = false)
		{
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: 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)
			GrabbableObject result = null;
			float num = float.MaxValue;
			List<GrabbableObject> list = new List<GrabbableObject>(64);
			try
			{
				List<HoarderBugItem> hoarderBugItems = HoarderBugAI.HoarderBugItems;
				if (hoarderBugItems != null)
				{
					for (int i = 0; i < hoarderBugItems.Count; i++)
					{
						HoarderBugItem val = hoarderBugItems[i];
						if (val != null && (Object)(object)val.itemGrabbableObject != (Object)null)
						{
							list.Add(val.itemGrabbableObject);
						}
					}
				}
			}
			catch
			{
			}
			try
			{
				List<GameObject> grabbableObjectsInMap = HoarderBugAI.grabbableObjectsInMap;
				if (grabbableObjectsInMap != null)
				{
					for (int j = 0; j < grabbableObjectsInMap.Count; j++)
					{
						GameObject val2 = grabbableObjectsInMap[j];
						if (!((Object)(object)val2 == (Object)null))
						{
							GrabbableObject component = val2.GetComponent<GrabbableObject>();
							if ((Object)(object)component != (Object)null)
							{
								list.Add(component);
							}
						}
					}
				}
			}
			catch
			{
			}
			for (int k = 0; k < list.Count; k++)
			{
				GrabbableObject val3 = list[k];
				if ((Object)(object)val3 == (Object)null || !val3.grabbableToEnemies || val3.deactivated || (skipReserved && IsItemReservedByOther(val3)))
				{
					continue;
				}
				float num2 = Vector3.Distance(((Component)val3).transform.position, base.nestPosition);
				if (!(num2 < minNestDistance) && !(num2 > maxNestDistance) && (!((Object)(object)lastDroppedItemRef != (Object)null) || !((Object)(object)val3 == (Object)(object)lastDroppedItemRef) || !(Time.time - lastDropTime < 3f)))
				{
					float num3 = Vector3.Distance(((Component)this).transform.position, ((Component)val3).transform.position);
					if (num3 < num)
					{
						result = val3;
						num = num3;
					}
				}
			}
			return result;
		}

		private bool SetDestinationSmart(Vector3 pos)
		{
			//IL_0005: 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)
			bool flag = false;
			try
			{
				flag = ((EnemyAI)this).SetDestinationToPosition(pos, false);
				if (!flag && (Object)(object)((EnemyAI)this).agent != (Object)null)
				{
					((EnemyAI)this).agent.ResetPath();
					flag = ((EnemyAI)this).agent.SetDestination(pos);
				}
			}
			catch
			{
			}
			return flag;
		}

		private bool SetDestinationThrottled(Vector3 pos)
		{
			//IL_0014: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			destinationRefreshCooldown -= ((EnemyAI)this).AIIntervalTime;
			float num = Vector3.Distance(pos, lastSetDestination);
			if (num < 0.5f && destinationRefreshCooldown > 0f)
			{
				return false;
			}
			bool flag = SetDestinationSmart(pos);
			if (flag)
			{
				lastSetDestination = pos;
				destinationRefreshCooldown = 0.25f;
			}
			return flag;
		}

		private static bool IsItemReservedByOther(GrabbableObject item)
		{
			if ((Object)(object)item == (Object)null)
			{
				return false;
			}
			if (s_itemReservations.TryGetValue(item, out LabubuPrimeAI value))
			{
				if ((Object)(object)value == (Object)null)
				{
					s_itemReservations.Remove(item);
					return false;
				}
				return true;
			}
			return false;
		}

		private bool TryReserveItem(GrabbableObject item)
		{
			if ((Object)(object)item == (Object)null)
			{
				return false;
			}
			if (s_itemReservations.TryGetValue(item, out LabubuPrimeAI value))
			{
				if ((Object)(object)value == (Object)(object)this)
				{
					return true;
				}
				return false;
			}
			s_itemReservations[item] = this;
			reservedItem = item;
			return true;
		}

		private void ReleaseReservation(GrabbableObject item)
		{
			if (!((Object)(object)item == (Object)null) && s_itemReservations.TryGetValue(item, out LabubuPrimeAI value) && (Object)(object)value == (Object)(object)this)
			{
				s_itemReservations.Remove(item);
				if ((Object)(object)reservedItem == (Object)(object)item)
				{
					reservedItem = null;
				}
			}
		}

		private bool TryPlayVoiceSafe(AudioClip clip)
		{
			try
			{
				if ((Object)(object)((EnemyAI)this).creatureVoice == (Object)null || (Object)(object)clip == (Object)null)
				{
					return false;
				}
				float time = Time.time;
				float num = 2.5f;
				float num2 = Mathf.Max(0f, Plugin.BoundConfig.VoiceGlobalGapSeconds.Value);
				if (time < nextLocalVoiceTime)
				{
					return false;
				}
				if (time < nextGlobalVoiceTime)
				{
					return false;
				}
				((EnemyAI)this).creatureVoice.PlayOneShot(clip);
				nextLocalVoiceTime = time + num;
				nextGlobalVoiceTime = time + num2;
				return true;
			}
			catch
			{
			}
			return false;
		}

		private void VoiceOnSightTick()
		{
			bool flag = HasAnyPlayerInSight(25f);
			if (flag)
			{
				voiceOutOfSight = 0f;
				voiceSightDwell += ((EnemyAI)this).AIIntervalTime;
				if (voiceArmed && voiceSightDwell >= 0.6f)
				{
					AudioClip val = null;
					try
					{
						if (base.angryScreechSFX != null && base.angryScreechSFX.Length != 0)
						{
							val = base.angryScreechSFX[0];
						}
					}
					catch
					{
					}
					if ((Object)(object)val == (Object)null && (Object)(object)((EnemyAI)this).creatureVoice != (Object)null && (Object)(object)((EnemyAI)this).creatureVoice.clip != (Object)null)
					{
						val = ((EnemyAI)this).creatureVoice.clip;
					}
					if (TryPlayVoiceSafe(val))
					{
						voiceArmed = false;
						voiceSightDwell = 0f;
					}
				}
			}
			else
			{
				voiceSightDwell = 0f;
				voiceOutOfSight += ((EnemyAI)this).AIIntervalTime;
				if (voiceOutOfSight >= 1.5f)
				{
					voiceArmed = true;
				}
			}
			hadPlayerInSight = flag;
		}

		private bool HasAnyPlayerInSight(float range)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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)
			try
			{
				StartOfRound instance = StartOfRound.Instance;
				if ((Object)(object)instance == (Object)null || instance.allPlayerScripts == null)
				{
					return false;
				}
				RaycastHit val5 = default(RaycastHit);
				for (int i = 0; i < instance.allPlayerScripts.Length; i++)
				{
					PlayerControllerB val = instance.allPlayerScripts[i];
					if ((Object)(object)val == (Object)null || val.isPlayerDead)
					{
						continue;
					}
					float num = Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position);
					if (num > range)
					{
						continue;
					}
					Vector3 val2 = ((Component)this).transform.position + Vector3.up * 1.5f;
					Vector3 val3 = (((Object)(object)val.playerEye != (Object)null) ? val.playerEye.position : (((Component)val).transform.position + Vector3.up * 1.6f));
					Vector3 val4 = val3 - val2;
					float magnitude = ((Vector3)(ref val4)).magnitude;
					if (magnitude <= 0.01f)
					{
						return true;
					}
					val4 /= Mathf.Max(0.0001f, magnitude);
					if (Physics.Raycast(val2, val4, ref val5, magnitude, -1, (QueryTriggerInteraction)2))
					{
						PlayerControllerB componentInParent = ((Component)((RaycastHit)(ref val5)).transform).GetComponentInParent<PlayerControllerB>();
						if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent == (Object)(object)val)
						{
							return true;
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private void ResetNestWaitModes()
		{
			try
			{
				Type typeFromHandle = typeof(HoarderBugAI);
				FieldInfo field = typeFromHandle.GetField("waitingAtNest", BindingFlags.Instance | BindingFlags.NonPublic);
				FieldInfo field2 = typeFromHandle.GetField("inReturnToNestMode", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					field.SetValue(this, false);
				}
				if (field2 != null)
				{
					field2.SetValue(this, false);
				}
			}
			catch
			{
			}
		}

		private void PeriodicHousekeeping()
		{
			refreshItemsCooldown -= ((EnemyAI)this).AIIntervalTime;
			if (refreshItemsCooldown <= 0f)
			{
				refreshItemsCooldown = 5f;
				try
				{
					HoarderBugAI.RefreshGrabbableObjectsInMapList();
				}
				catch
				{
				}
			}
			try
			{
				nextLocalVoiceTime = Mathf.Max(nextLocalVoiceTime, Time.time + Mathf.Max(0.1f, Plugin.BoundConfig.VoiceLocalCooldownSeconds.Value));
			}
			catch
			{
			}
		}

		private void UpdateWalkAnimation(bool shouldWalk)
		{
			if (!((Object)(object)((EnemyAI)this).creatureAnimator == (Object)null))
			{
				if (shouldWalk && !walkingAnimActive)
				{
					walkingAnimActive = true;
					((EnemyAI)this).creatureAnimator.SetTrigger("startWalk");
				}
				else if (!shouldWalk && walkingAnimActive)
				{
					walkingAnimActive = false;
					((EnemyAI)this).creatureAnimator.SetTrigger("stopWalk");
				}
			}
		}

		public override void KillEnemy(bool destroy = false)
		{
			if (!deathSequenceStarted)
			{
				deathSequenceStarted = true;
				UpdateWalkAnimation(shouldWalk: false);
				if ((Object)(object)((EnemyAI)this).creatureAnimator != (Object)null)
				{
					((EnemyAI)this).creatureAnimator.SetTrigger("KillEnemy");
				}
				TryPlayDeathSFX();
				((MonoBehaviour)this).StartCoroutine(PrimeVaporDeathRoutine(destroy));
			}
		}

		[IteratorStateMachine(typeof(<PrimeVaporDeathRoutine>d__107))]
		private IEnumerator PrimeVaporDeathRoutine(bool destroy)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <PrimeVaporDeathRoutine>d__107(0)
			{
				<>4__this = this,
				destroy = destroy
			};
		}

		private void SafeTrigger(string triggerName)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			try
			{
				if ((Object)(object)((EnemyAI)this).creatureAnimator == (Object)null)
				{
					return;
				}
				AnimatorControllerParameter[] parameters = ((EnemyAI)this).creatureAnimator.parameters;
				foreach (AnimatorControllerParameter val in parameters)
				{
					if (val.name == triggerName && (int)val.type == 9)
					{
						((EnemyAI)this).creatureAnimator.SetTrigger(triggerName);
						break;
					}
				}
			}
			catch
			{
			}
		}

		private void TryMakeNonBlocking()
		{
			try
			{
				NavMeshAgent component = ((Component)this).GetComponent<NavMeshAgent>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
			}
			catch
			{
			}
			try
			{
				Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if ((Object)(object)componentsInChildren[i] != (Object)null)
					{
						componentsInChildren[i].enabled = false;
					}
				}
			}
			catch
			{
			}
			try
			{
				Rigidbody[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Rigidbody>(true);
				foreach (Rigidbody val in componentsInChildren2)
				{
					if (!((Object)(object)val == (Object)null))
					{
						val.isKinematic = true;
						val.detectCollisions = false;
					}
				}
			}
			catch
			{
			}
		}

		private void TrySpawnDeathFX()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0036: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)Plugin.ExplosionPrefab != (Object)null)
				{
					GameObject val = Object.Instantiate<GameObject>(Plugin.ExplosionPrefab, ((Component)this).transform.position + Vector3.up * 0.8f, Quaternion.identity);
					Object.Destroy((Object)(object)val, 4f);
				}
			}
			catch
			{
			}
		}

		private void TryHideModel()
		{
			//IL_0045: 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)
			try
			{
				Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if ((Object)(object)componentsInChildren[i] != (Object)null)
					{
						componentsInChildren[i].enabled = false;
					}
				}
			}
			catch
			{
			}
			try
			{
				((Component)this).transform.localScale = Vector3.one * 0.03f;
			}
			catch
			{
			}
		}

		private void TryPlayDeathSFX()
		{
			try
			{
				AudioClip val = null;
				Type typeFromHandle = typeof(EnemyAI);
				FieldInfo field = typeFromHandle.GetField("deathSFX", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null && field.GetValue(this) is AudioClip[] array && array.Length != 0)
				{
					val = array[0];
				}
				if ((Object)(object)val == (Object)null)
				{
					try
					{
						if (base.angryScreechSFX != null && base.angryScreechSFX.Length != 0)
						{
							val = base.angryScreechSFX[Mathf.Min(1, base.angryScreechSFX.Length - 1)];
						}
					}
					catch
					{
					}
				}
				if ((Object)(object)val != (Object)null && (Object)(object)((EnemyAI)this).creatureSFX != (Object)null)
				{
					((EnemyAI)this).creatureSFX.PlayOneShot(val);
				}
			}
			catch
			{
			}
		}

		private void TryAggressiveChaseTick()
		{
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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)
			if ((Object)(object)((EnemyAI)this).agent == (Object)null || !((EnemyAI)this).agent.isOnNavMesh)
			{
				return;
			}
			if (!aggroVoicePlayed)
			{
				try
				{
					TryPlayVoiceSafe((base.angryScreechSFX != null && base.angryScreechSFX.Length != 0) ? base.angryScreechSFX[0] : null);
				}
				catch
				{
				}
				aggroVoicePlayed = true;
			}
			PlayerControllerB val = null;
			float num = float.MaxValue;
			PlayerControllerB[] array = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.allPlayerScripts : null);
			if (array != null)
			{
				foreach (PlayerControllerB val2 in array)
				{
					if (!((Object)(object)val2 == (Object)null) && !val2.isPlayerDead)
					{
						float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)val2).transform.position);
						if (num2 < num && num2 <= 25f)
						{
							num = num2;
							val = val2;
						}
					}
				}
			}
			Vector3 pos;
			if ((Object)(object)val != (Object)null)
			{
				SetDestinationThrottled(((Component)val).transform.position);
			}
			else if (TryFindValidIndoorSpawn(out pos))
			{
				SetDestinationThrottled(pos);
			}
		}

		private void SigmaTriggerTick()
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsOwner && !((EnemyAI)this).isClientCalculatingAI)
			{
				return;
			}
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
			if (allPlayerScripts == null)
			{
				return;
			}
			float num = 2f;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if ((Object)(object)val == (Object)null || val.isPlayerDead)
				{
					continue;
				}
				GrabbableObject val2 = (lastHeldByPlayer.ContainsKey(val) ? lastHeldByPlayer[val] : null);
				GrabbableObject playerHeldItemSafe = GetPlayerHeldItemSafe(val);
				if ((Object)(object)val2 == (Object)null && (Object)(object)playerHeldItemSafe != (Object)null)
				{
					float num2 = Vector3.Distance(((Component)val).transform.position, base.nestPosition);
					if (num2 <= num)
					{
						AttemptToSummonSigma(val);
					}
				}
				lastHeldByPlayer[val] = playerHeldItemSafe;
			}
		}

		private GrabbableObject GetPlayerHeldItemSafe(PlayerControllerB p)
		{
			try
			{
				PropertyInfo property = typeof(PlayerControllerB).GetProperty("currentlyHeldObjectServer");
				if (property != null)
				{
					object? value = property.GetValue(p, null);
					return (GrabbableObject)((value is GrabbableObject) ? value : null);
				}
			}
			catch
			{
			}
			try
			{
				PropertyInfo property2 = typeof(PlayerControllerB).GetProperty("currentlyHeldObject");
				if (property2 != null)
				{
					object? value2 = property2.GetValue(p, null);
					return (GrabbableObject)((value2 is GrabbableObject) ? value2 : null);
				}
			}
			catch
			{
			}
			return null;
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			((HoarderBugAI)this).OnCollideWithPlayer(other);
			if (!aggressiveMode || ((EnemyAI)this).isEnemyDead)
			{
				return;
			}
			try
			{
				PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
				if ((Object)(object)val != (Object)null)
				{
					val.DamagePlayer(10, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
				}
			}
			catch
			{
			}
		}

		private void TryBindAudioSourcesFromModel(GameObject root)
		{
			try
			{
				if ((Object)(object)root == (Object)null)
				{
					return;
				}
				AudioSource[] componentsInChildren = root.GetComponentsInChildren<AudioSource>(true);
				if (componentsInChildren == null || componentsInChildren.Length == 0)
				{
					return;
				}
				AudioSource val = null;
				AudioSource val2 = null;
				foreach (AudioSource val3 in componentsInChildren)
				{
					if (!((Object)(object)val3 == (Object)null))
					{
						string text = ((Object)((Component)val3).gameObject).name.ToLowerInvariant();
						if ((Object)(object)val == (Object)null && (text.Contains("voice") || text.Contains("voc") || text.Contains("mouth")))
						{
							val = val3;
						}
						if ((Object)(object)val2 == (Object)null && (text.Contains("sfx") || text.Contains("step") || text.Contains("foot")))
						{
							val2 = val3;
						}
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					val = componentsInChildren[0];
				}
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = ((componentsInChildren.Length > 1) ? componentsInChildren[1] : componentsInChildren[0]);
				}
				if ((Object)(object)val != (Object)null)
				{
					((EnemyAI)this).creatureVoice = val;
				}
				if ((Object)(object)val2 != (Object)null)
				{
					((EnemyAI)this).creatureSFX = val2;
				}
				try
				{
					if ((Object)(object)((EnemyAI)this).creatureVoice != (Object)null)
					{
						originalVoiceVolume = Mathf.Max(0.01f, ((EnemyAI)this).creatureVoice.volume);
					}
				}
				catch
				{
				}
			}
			catch
			{
			}
		}

		[CompilerGenerated]
		[DebuggerHidden]
		private void <>n__0(bool destroy = false)
		{
			((HoarderBugAI)this).KillEnemy(destroy);
		}

		protected override void __initializeVariables()
		{
			if (modelVariantIndex == null)
			{
				throw new Exception("LabubuPrimeAI.modelVariantIndex cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)modelVariantIndex).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)modelVariantIndex, "modelVariantIndex");
			((NetworkBehaviour)this).NetworkVariableFields.Add((NetworkVariableBase)(object)modelVariantIndex);
			((HoarderBugAI)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_LabubuPrimeAI()
		{
			//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
			NetworkManager.__rpc_func_table.Add(915988411u, (RpcReceiveHandler)new RpcReceiveHandler(__rpc_handler_915988411));
			NetworkManager.__rpc_func_table.Add(1484071541u, (RpcReceiveHandler)new RpcReceiveHandler(__rpc_handler_1484071541));
			NetworkManager.__rpc_func_table.Add(2797527559u, (RpcReceiveHandler)new RpcReceiveHandler(__rpc_handler_2797527559));
		}

		private static void __rpc_handler_915988411(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;
				((LabubuPrimeAI)(object)target).SummonAllyServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1484071541(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)
			{
				ulong targetPlayerClientId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref targetPlayerClientId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((LabubuPrimeAI)(object)target).SummonSigmaServerRpc(targetPlayerClientId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2797527559(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0036: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Vector3 nestPos = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref nestPos);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((LabubuPrimeAI)(object)target).SyncSharedNestPositionClientRpc(nestPos);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "LabubuPrimeAI";
		}
	}
	[BepInPlugin("BakaMODs.SigmaLabubu", "SigmaLabubu", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static AssetBundle? ModAssets;

		public static GameObject? SigmaLabubuPrefab;

		public static GameObject? ExplosionPrefab;

		public static EnemyType? LabubuPrimeType;

		internal static PluginConfig BoundConfig { get; private set; }

		private static float ConfiguredDoorOpenMultiplier => (BoundConfig?.OpenDoorSpeedMultiplier?.Value).GetValueOrDefault(1f);

		private void Awake()
		{
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Expected O, but got Unknown
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
			InitializeNetworkBehaviours();
			string path = "sigmalabubuassets";
			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>("PrimeLabubuObj");
			TerminalNode val2 = ModAssets.LoadAsset<TerminalNode>("LabubuPrimeTN");
			TerminalKeyword val3 = ModAssets.LoadAsset<TerminalKeyword>("LabubuPrimeTK");
			SigmaLabubuPrefab = ModAssets.LoadAsset<GameObject>("SigmaLabubu");
			ExplosionPrefab = ModAssets.LoadAsset<GameObject>("Explosion");
			if ((Object)(object)ExplosionPrefab == (Object)null)
			{
				Logger.LogWarning((object)"[FX] Explosion prefab not found in bundle (name 'Explosion'). Using fallback vapor FX.");
			}
			LabubuPrimeType = val;
			try
			{
				EnemyHelper.SetProbabilityCurve(BoundConfig.SpawnProbabilityCurve.Value);
			}
			catch (Exception ex)
			{
				Logger.LogWarning((object)("[Spawn] Failed to set probability curve: " + ex.Message));
			}
			try
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val.enemyPrefab != (Object)null)
				{
					EnemyAI component = val.enemyPrefab.GetComponent<EnemyAI>();
					if ((Object)(object)component != (Object)null)
					{
						component.openDoorSpeedMultiplier = Mathf.Max(0.01f, ConfiguredDoorOpenMultiplier);
						Logger.LogInfo((object)$"[Doors] Set openDoorSpeedMultiplier on prefab = {component.openDoorSpeedMultiplier}");
					}
				}
			}
			catch (Exception ex2)
			{
				Logger.LogWarning((object)("[Doors] Failed to set openDoorSpeedMultiplier: " + ex2.Message));
			}
			NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(SigmaLabubuPrefab);
			Enemies.RegisterEnemy(val, BoundConfig.EasyMoonSpawnWeight.Value, (LevelTypes)28, val2, val3);
			Enemies.RegisterEnemy(val, BoundConfig.MediumMoonSpawnWeight.Value, (LevelTypes)96, val2, val3);
			Enemies.RegisterEnemy(val, BoundConfig.HardMoonSpawnWeight.Value, (LevelTypes)896, val2, val3);
			Enemies.RegisterEnemy(val, BoundConfig.ModdedMoonSpawnWeight.Value, (LevelTypes)1024, val2, val3);
			GameObject val4 = new GameObject("SpawnControl");
			Object.DontDestroyOnLoad((Object)(object)val4);
			val4.AddComponent<SpawnControl>();
			Logger.LogInfo((object)"[Spawn] SpawnControl anexado e ativo.");
			try
			{
				Harmony val5 = new Harmony("BakaMODs.SigmaLabubu");
				val5.PatchAll();
				Logger.LogInfo((object)"[Spawn] Harmony patches applied (RoundManager, HoarderBug, Intercept).");
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"[Spawn] Failed to apply Harmony patches: {arg}");
			}
			Logger.LogInfo((object)"Plugin BakaMODs.SigmaLabubu 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 | BindingFla