plugins/Snowlance.Rats.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Dawn;
using Dawn.Utils;
using Dusk;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Snowlance.Rats.NetcodePatcher;
using SnowyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;

[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: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("DunGen")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.ASPP")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.UnityNav")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.CoreUtils")]
[assembly: IgnoresAccessChecksTo("Unity.XR.Management")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.ConformanceAutomation")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MetaQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MockRuntime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.OculusQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.RuntimeDebugger")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SpatialTracking")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("UnityEngine.XR.LegacyInputHelpers")]
[assembly: AssemblyCompany("Snowlance.Rats")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyInformationalVersion("1.4.0+663681ecebe4b798c0f8f4c83c0f89871a760b32")]
[assembly: AssemblyProduct("Rats")]
[assembly: AssemblyTitle("Snowlance.Rats")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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 Rats
{
	internal static class Configs
	{
		public static int cfgMaxRats { get; private set; }

		public static int cfgBatchGroupCount { get; private set; }

		public static float cfgBatchUpdateInterval { get; private set; }

		public static bool cfgHolidayRats { get; private set; }

		public static bool cfgUseJermaRats { get; private set; }

		public static bool cfgEnableInfestationSystem { get; private set; }

		public static int cfgThreatToAttackPlayer { get; private set; }

		public static int cfgThreatToAttackEnemy { get; private set; }

		public static float cfgSwarmRadius { get; private set; }

		public static int cfgEnemyHitsToDoDamage { get; private set; }

		public static float cfgSqueakChance { get; private set; }

		public static string[] cfgFoodItemNames { get; private set; }

		public static string[] cfgFoodItemTags { get; private set; }

		public static BoundedRange cfgRatSpawnTime { get; private set; }

		public static int cfgFoodToSpawnRat { get; private set; }

		public static int cfgEnemyFoodPerHPPoint { get; private set; }

		public static int cfgMaxDefenseRats { get; private set; }

		public static int cfgPlayerFoodAmount { get; private set; }

		public static bool cfgRatsTakePlayerCorpses { get; private set; }

		public static float cfgMaxFluid { get; private set; }

		public static float cfgPourRate { get; private set; }

		public static float cfgPoisonToCloseNest { get; private set; }

		public static int cfgGlueBoardAmount { get; private set; }

		public static int cfgScrapValuePerRat { get; private set; }

		public static int cfgMaxRatsOnGlueBoard { get; private set; }

		public static int cfgSnapTrapAmount { get; private set; }

		public static float cfgDespawnTime { get; private set; }

		public static void Init()
		{
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Expected O, but got Unknown
			cfgMaxRats = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("Performance", "Max Rats", 100, "The maximum number of rats that can be on the map. Lowering this can improve performance.").Value;
			cfgBatchGroupCount = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("Performance", "Batch Group Count", 5, "The amount of groups the rats will be split into to update. (if you dont know what this means, just leave this config alone)").Value;
			cfgBatchUpdateInterval = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("Performance", "Batch Update Interval", 0.2f, "The amount of time between each group update. (if you dont know what this means, just leave this config alone)").Value;
			cfgHolidayRats = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Other", "Holiday Rats", false, "Rats spawn with a santa hat").Value;
			cfgUseJermaRats = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Other", "Use Jerma Rats", false, "Uses a lower quality model for the rats with no animations. Can help with performance if enabled.").Value;
			cfgEnableInfestationSystem = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Other", "Enable Infestation System", true, "Enables the infestation system").Value;
			cfgThreatToAttackPlayer = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("Rats", "Threat To Attack Player", 75, "The threat level at which rats begin attacking the player").Value;
			cfgThreatToAttackEnemy = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("Rats", "Threat To Attack Enemy", 50, "The threat level at which rats begin attacking other enemies").Value;
			cfgSwarmRadius = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("Rats", "Swarm Radius", 2f, "The radius in which rats swarm around their target").Value;
			cfgEnemyHitsToDoDamage = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("Rats", "Enemy Hits To Do Damage", 10, "The amount of attacks needed to do 1 shovel hit of damage to an enemy. If 10, thumper will need to be attacked 40 times by a rat.").Value;
			cfgSqueakChance = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("Rats", "Squeak Chance", 0.01f, "The chance a rat will squeak when completing a run cycle (every second)").Value;
			cfgFoodItemNames = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>("Rats", "Food Item Names", "melaniemeliciouscooked:meatzero,melaniemeliciouscooked:carrotzero,melaniemeliciouscooked:soupveggiezero,melaniemeliciouscooked:soupmeatzero,melaniemeliciouscooked:loafmeatzero,melaniemeliciouscooked:potatozero,melaniemeliciouscooked:wheatzero,melaniemeliciouscooked:flourzero,melaniemeliciouscooked:loafbreadzero,melaniemeliciouscooked:piezero,melaniemeliciouscooked:sliderzero,melaniemeliciouscooked:burgerzero,melaniemeliciouscooked:meatone,melaniemeliciouscooked:sandwichcheesezero,melaniemeliciouscooked:grapezero,melaniemeliciouscooked:juicezero,melaniemeliciouscooked:grapeone,melaniemeliciouscooked:juiceone,melaniemeliciouscooked:alcoholzero,melaniemeliciouscooked:alcoholone,melaniemeliciouscooked:alcoholtwo,melaniemeliciouscooked:alcoholthree,melaniemeliciouscooked:alcoholfour,melaniemeliciouscooked:juicetwo,melaniemeliciouscooked:juicethree,melaniemeliciouscooked:burstberryzero,melaniemeliciouscooked:burstberryone,melaniemeliciouscooked:pieone,melaniemeliciouscooked:honeyzero,melaniemeliciouscooked:hivezero,melaniemeliciouscooked:alcoholfive,melaniemeliciouscooked:hiveone,melaniemeliciouscooked:fishzero,melaniemeliciouscooked:fishone,melaniemeliciouscooked:baitzero,melaniemeliciouscooked:baitone,melaniemeliciouscooked:tomatozero,melaniemeliciouscooked:tomatoone,melaniemeliciouscooked:seedtomato,melaniemeliciouscooked:barrelone,melaniemeliciouscooked:pietwo,melaniemeliciouscooked:cookiezero,melaniemeliciouscooked:bruschettazero,melaniemeliciouscooked:kabobzero,melaniemeliciouscooked:popsiclezero,melaniemeliciouscooked:popsicleone,melaniemeliciouscooked:popsicletwo,melaniemeliciouscooked:fishtwo,melaniemeliciouscooked:fishthree,melaniemeliciouscooked:fishstickszero,lethal_company:candy,lethal_company:jar_of_pickles,lethal_company:pill_bottle,lethal_company:egg,lethal_company:hand,lethal_company:bone,lethal_company:ribcage,lethal_company:ear,lethal_company:foot,lethal_company:knee,lethal_company:heart,lethal_company:tongue", "Dawnlib NamespaceKeys for items rats should steal").Value.Replace(" ", "").ToLower().Split(",");
			cfgFoodItemTags = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>("Rats", "Food Item Tags", "food,edible,organic,consumable,meat,produce,ingredient,snack,perishable,corpse,garbage,ration,snack,candy,waste,carcass,rat_food", "Dawnlib tags for items rats should steal").Value.Replace(" ", "").ToLower().Split(",");
			cfgRatSpawnTime = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<BoundedRange>("RatNest", "Rat Spawn Time", new BoundedRange(10f, 30f), "The min/max time in seconds before a rat can spawn from a nest after the last rat was spawned").Value;
			cfgFoodToSpawnRat = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("RatNest", "Food To Spawn Rat", 5, "The amount of food needed in the nest to spawn a new rat").Value;
			cfgEnemyFoodPerHPPoint = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("RatNest", "Enemy Food Per HP Point", 10, "How much food points one HP will equal for enemies. ex: if 10, thumper will give 40 food points").Value;
			cfgMaxDefenseRats = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("RatNest", "Max Defense Rats", 10, "The maximum number of defense rats assigned to protect the nest").Value;
			cfgPlayerFoodAmount = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("RatNest", "Player Food Amount", 30, "How much food points a player corpse gives when brought to the nest").Value;
			cfgRatsTakePlayerCorpses = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("RatNest", "Rats Take Player Corpses", true, "If this is true, allows rats to drag players to their nest to eat").Value;
			cfgMaxFluid = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("RatPoison", "Max Fluid", 5f, "The amount of rat poison in a jug of rat poison").Value;
			cfgPourRate = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("RatPoison", "Pour Rate", 0.1f, "How fast the rat poison pours out of the container").Value;
			cfgPoisonToCloseNest = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("RatPoison", "Poison To Close Nest", 1f, "The amount of poison you need to pour in a rat nest to disable it").Value;
			cfgGlueBoardAmount = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("GlueTrap", "Glue Board Amount", 4, "The amount of glue boards you can place down from a glue board trap item").Value;
			cfgScrapValuePerRat = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("GlueTrap", "Scrap Value Per Rat", 2, "The scrap value added to the glue board per rat stuck in trap").Value;
			cfgMaxRatsOnGlueBoard = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("GlueTrap", "Max Rats On Glue Board", 5, "The maximum number of rats that can be caught on a single glue board").Value;
			cfgSnapTrapAmount = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("BoxOfSnapTraps", "Snap Trap Amount", 100, "The amount of snap traps that come with a Box Of Snap Traps").Value;
			cfgDespawnTime = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("BoxOfSnapTraps", "Despawn Time", 65, "The time in seconds for snap traps to despawn after being triggered").Value;
		}
	}
	public class RatAI : NetworkBehaviour
	{
		public enum State
		{
			ReturnToNest,
			Scouting,
			Swarming
		}

		[CompilerGenerated]
		private sealed class <<RallyCall>g__InSpecialAnimationFalseRoutine|71_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public RatAI <>4__this;

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

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

			[DebuggerHidden]
			public <<RallyCall>g__InSpecialAnimationFalseRoutine|71_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(4.7f);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>4__this.inSpecialAnimation = false;
					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();
			}
		}

		public static List<RatAI> Instances = new List<RatAI>();

		public static List<GrabbableObject> StealableObjects = new List<GrabbableObject>();

		public AudioClip[] squeakSFX = null;

		public AudioClip[] attackSFX = null;

		public AudioClip[] hitSFX = null;

		public AudioClip[] nibbleSFX = null;

		public AudioClip screamSFX = null;

		public Transform ratMouthTransform = null;

		public GameObject christmasHat = null;

		public GameObject jermaRatObj = null;

		public GameObject ratObj = null;

		public Animator? animator;

		public Transform eye = null;

		public AudioSource creatureSFX = null;

		public AudioSource creatureVoice = null;

		public SmartAgentNavigator nav = null;

		[HideInInspector]
		public bool isDead;

		private GoToDestinationResult destinationResult = (GoToDestinationResult)1;

		private GameObject? targetNode;

		private bool inSpecialAnimation;

		private State previousBehaviorState;

		private State currentBehaviorState = State.ReturnToNest;

		[HideInInspector]
		public PlayerControllerB? targetPlayer;

		private GrabbableObject? targetObject;

		private GrabbableObject? heldObject;

		private DeadBodyInfo? targetBody;

		private DeadBodyInfo? heldBody;

		private bool holdingFood;

		private int hashDie;

		private int hashSpeed;

		private float timeSinceCollision;

		private float timeSinceCheck;

		private float timeSinceSwitchBehavior;

		private float timeIdle;

		private RatNest? closestNest;

		private GameObject? swarmTarget;

		private Vector3 swarmTargetPos;

		public static UnityEvent<Vector3, GameObject> RallyRats = new UnityEvent<Vector3, GameObject>();

		private bool rallying;

		private int health = 1;

		private float swarmRadiusDefault = 6f;

		private Vector3 lastPosition;

		private float currentSpeed;

		private const float timeToDoChecks = 3f;

		private const float maxIdleTime = 1f;

		private const float distanceNeededToLoseRats = 20f;

		private const float rallyDistance = 20f;

		private const float scentRange = 20f;

		public bool isOutside => nav.IsAgentOutside();

		public void Start()
		{
			hashDie = Animator.StringToHash("die");
			hashSpeed = Animator.StringToHash("speed");
			christmasHat.SetActive(Configs.cfgHolidayRats);
			animator = (Configs.cfgUseJermaRats ? null : animator);
			ratObj.SetActive(!Configs.cfgUseJermaRats);
			jermaRatObj.SetActive(Configs.cfgUseJermaRats);
			nav.SetAllValues(false);
			RallyRats.AddListener((UnityAction<Vector3, GameObject>)ListenForRallyCall);
			ManualLogSource? logger = Plugin.logger;
			if (logger != null)
			{
				logger.LogDebug((object)"Rat spawned");
			}
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			Instances.Add(this);
		}

		public override void OnNetworkDespawn()
		{
			ResetVariables();
			Instances.Remove(this);
			((NetworkBehaviour)this).OnNetworkDespawn();
		}

		public void Update()
		{
			timeSinceCollision += Time.deltaTime;
			timeSinceCheck += Time.deltaTime;
			timeSinceSwitchBehavior += Time.deltaTime;
		}

		public void LateUpdate()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position - lastPosition;
			currentSpeed = ((Vector3)(ref val)).magnitude / Time.deltaTime / 2f;
			Animator? obj = animator;
			if (obj != null)
			{
				obj.SetFloat(hashSpeed, currentSpeed);
			}
			lastPosition = ((Component)this).transform.position;
			timeIdle = ((currentSpeed > 0.1f) ? 0f : (timeIdle + Time.deltaTime));
		}

		public void DoAIInterval()
		{
			//IL_0091: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Invalid comparison between Unknown and I4
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Invalid comparison between Unknown and I4
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Invalid comparison between Unknown and I4
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Invalid comparison between Unknown and I4
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Invalid comparison between Unknown and I4
			//IL_061d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0607: Unknown result type (might be due to invalid IL or missing references)
			//IL_060c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0611: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0598: Unknown result type (might be due to invalid IL or missing references)
			//IL_059d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsServer)
			{
				return;
			}
			if (isDead || StartOfRound.Instance.allPlayersDead || inSpecialAnimation)
			{
				nav.StopAgent();
				return;
			}
			switch (currentBehaviorState)
			{
			case State.ReturnToNest:
				nav.agent.speed = 5f;
				if (closestNest == null)
				{
					closestNest = RatNest.GetClosestNestToPosition(((Component)this).transform.position);
				}
				if ((Object)(object)closestNest == (Object)null)
				{
					EnemyVent closestToPosition = IEnumerableExtensions.GetClosestToPosition<EnemyVent>((IEnumerable<EnemyVent>)RoundManager.Instance.allEnemyVents, ((Component)this).transform.position, (Func<EnemyVent, Vector3>)((EnemyVent x) => ((Component)x).transform.position), false, (IEnumerable<EnemyVent>)null);
					nav.DoPathingToDestination(closestToPosition.floorNode.position);
					if (timeIdle > 1f)
					{
						NetworkObject networkObject = ((NetworkBehaviour)this).NetworkObject;
						if (networkObject != null)
						{
							networkObject.Despawn(true);
						}
					}
					break;
				}
				nav.TryDoPathingToDestination(((Component)closestNest).transform.position, ref destinationResult);
				if (timeIdle > 1f && (int)destinationResult == 0)
				{
					if (holdingFood)
					{
						closestNest.AddFood();
					}
					holdingFood = false;
					if ((Object)(object)heldBody != (Object)null)
					{
						closestNest.AddFood(Configs.cfgPlayerFoodAmount);
						DropObjectClientRpc(despawn: true);
					}
					if ((Object)(object)heldObject != (Object)null)
					{
						closestNest.AddFood(Mathf.CeilToInt(heldObject.itemProperties.weight * 2.5f));
						DropObjectClientRpc(despawn: true);
					}
					if ((Object)(object)closestNest != (Object)null && closestNest.DefenseRats != null && closestNest.DefenseRats.Count < Configs.cfgMaxDefenseRats)
					{
						swarmTarget = ((Component)closestNest).gameObject;
						closestNest.DefenseRats.Add(this);
						SwitchToBehaviorClientRpc(State.Swarming);
					}
					else
					{
						SwitchToBehaviorClientRpc(State.Scouting);
					}
				}
				break;
			case State.Scouting:
				nav.agent.speed = 5f;
				if ((Object)(object)targetBody != (Object)null && nav.TryDoPathingToDestination(((Component)targetBody).transform.position, ref destinationResult) && (int)destinationResult != 2)
				{
					if ((int)destinationResult == 0)
					{
						int attachedLimbIndex = Random.Range(0, targetBody.bodyParts.Length);
						GrabBodyClientRpc(targetBody.playerScript.actualClientId, attachedLimbIndex);
						targetBody = null;
					}
					break;
				}
				if ((Object)(object)targetObject != (Object)null && nav.TryDoPathingToDestination(((Component)targetObject).transform.position, ref destinationResult) && (int)destinationResult != 2)
				{
					if ((int)destinationResult == 0)
					{
						GrabObjectClientRpc(NetworkObjectReference.op_Implicit(((NetworkBehaviour)targetObject).NetworkObject));
						targetObject = null;
					}
					break;
				}
				if (timeSinceCheck > 3f)
				{
					timeSinceCheck = 0f;
					DoChecks();
				}
				if (timeIdle > 1f)
				{
					targetNode = ((Instances.Count >= Configs.cfgMaxRats - Configs.cfgMaxRats / 4) ? IEnumerableExtensions.GetRandom<GameObject>((IEnumerable<GameObject>)Utils.allAINodes) : IEnumerableExtensions.GetRandom<GameObject>((IEnumerable<GameObject>)Utils.insideAINodes));
				}
				if ((Object)(object)targetNode != (Object)null)
				{
					nav.DoPathingToDestination(targetNode.transform.position);
				}
				break;
			case State.Swarming:
			{
				nav.agent.speed = 10f;
				if ((Object)(object)swarmTarget == (Object)null)
				{
					SwitchToBehaviorClientRpc(State.ReturnToNest);
					break;
				}
				float cfgSwarmRadius = Configs.cfgSwarmRadius;
				PlayerControllerB val = default(PlayerControllerB);
				Vector3 val2;
				EnemyAICollisionDetect val3 = default(EnemyAICollisionDetect);
				if (GameObjectExtensions.TryGetComponentInChildren<PlayerControllerB>(swarmTarget, ref val))
				{
					if ((Object)(object)val == (Object)null || !val.isPlayerControlled)
					{
						goto IL_0516;
					}
					if (!rallying && timeIdle > 1f && timeSinceSwitchBehavior > 3f)
					{
						val2 = ((Component)this).transform.position - ((Component)val).transform.position;
						if (((Vector3)(ref val2)).sqrMagnitude > 400f)
						{
							goto IL_0516;
						}
					}
				}
				else if (GameObjectExtensions.TryGetComponentInChildren<EnemyAICollisionDetect>(swarmTarget, ref val3))
				{
					EnemyAI val4 = val3?.mainScript;
					if ((Object)(object)val4 == (Object)null || val4.isEnemyDead)
					{
						goto IL_05be;
					}
					if (!rallying && timeIdle > 1f && timeSinceSwitchBehavior > 2f)
					{
						val2 = ((Component)this).transform.position - ((Component)val4).transform.position;
						if (((Vector3)(ref val2)).sqrMagnitude > 400f)
						{
							goto IL_05be;
						}
					}
				}
				else
				{
					cfgSwarmRadius = swarmRadiusDefault;
				}
				if (timeIdle > 1f)
				{
					swarmTargetPos = RoundManager.Instance.GetRandomNavMeshPositionInRadius(swarmTarget.transform.position, cfgSwarmRadius, RoundManager.Instance.navHit);
				}
				nav.DoPathingToDestination(swarmTargetPos);
				break;
			}
			default:
				{
					ManualLogSource? logger = Plugin.logger;
					if (logger != null)
					{
						logger.LogWarning((object)("Invalid state: " + currentBehaviorState));
					}
					break;
				}
				IL_0516:
				SwitchToBehaviorClientRpc(State.ReturnToNest);
				break;
				IL_05be:
				SwitchToBehaviorClientRpc(State.ReturnToNest);
				break;
			}
		}

		public void ListenForRallyCall(Vector3 rallyPos, GameObject target)
		{
			//IL_0017: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!rallying)
			{
				int num;
				if (!isDead)
				{
					Vector3 val = rallyPos - ((Component)this).transform.position;
					num = ((((Vector3)(ref val)).sqrMagnitude < 400f) ? 1 : 0);
				}
				else
				{
					num = 0;
				}
				rallying = (byte)num != 0;
				if (rallying)
				{
					swarmTarget = target;
					SwitchToBehaviorClientRpc(State.Swarming);
				}
			}
		}

		private void DoChecks()
		{
			CheckForThreatsInLOS();
			CheckLineOfSightForPlayerDeadBody();
			CheckForItemsToSteal();
		}

		private void CheckLineOfSightForPlayerDeadBody()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (!Configs.cfgRatsTakePlayerCorpses)
			{
				return;
			}
			targetBody = null;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				DeadBodyInfo deadBody = val.deadBody;
				if (!((Object)(object)deadBody == (Object)null) && !deadBody.deactivated && CheckLineOfSightForPosition(((Component)deadBody.grabBodyObject).transform.position, 60f, 60, 5f) && SmartAgentNavigatorExtensions.CanPathToPoint(nav, ((Component)deadBody.grabBodyObject).transform.position))
				{
					targetBody = deadBody;
					break;
				}
			}
		}

		private void CheckForThreatsInLOS()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			EnemyAI val = CheckLineOfSightForEnemy(30);
			if ((Object)(object)val != (Object)null && val.enemyType.canDie && (int)val.enemyType.EnemySize == 0)
			{
				AddThreat(val);
			}
			PlayerControllerB val2 = CheckLineOfSightForPlayer(60f, 60, 5);
			if ((Object)(object)val2 != (Object)null && val2.isPlayerControlled)
			{
				AddThreat(val2);
			}
		}

		private void CheckForItemsToSteal()
		{
			//IL_006a: 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)
			if ((Object)(object)targetBody != (Object)null || (Object)(object)heldBody != (Object)null)
			{
				return;
			}
			targetObject = null;
			float num = 400f;
			foreach (GrabbableObject item in StealableObjects.ToList())
			{
				if (IsObjectGrabbable(item))
				{
					Vector3 val = ((Component)this).transform.position - ((Component)item).transform.position;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (!(sqrMagnitude >= num))
					{
						targetObject = item;
						num = sqrMagnitude;
					}
				}
			}
		}

		private bool IsObjectGrabbable(GrabbableObject obj)
		{
			return (Object)(object)heldObject == (Object)null && (Object)(object)heldBody == (Object)null && (Object)(object)obj != (Object)null && obj.grabbable && obj.grabbableToEnemies && !obj.isHeld && !obj.isHeldByEnemy && obj.hasHitGround && (Object)(object)obj.playerHeldBy == (Object)null;
		}

		public bool CheckLineOfSightForPosition(Vector3 objectPosition, float width = 45f, int range = 60, float proximityAwareness = -1f, Transform? overrideEye = null)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!isOutside)
			{
				if (objectPosition.y > -80f)
				{
					return false;
				}
			}
			else if (objectPosition.y < -100f)
			{
				return false;
			}
			Transform val = (Transform)(((Object)(object)overrideEye != (Object)null) ? overrideEye : ((!((Object)(object)eye == (Object)null)) ? ((object)eye) : ((object)((Component)this).transform)));
			Vector3 val2 = val.position - objectPosition;
			RaycastHit val3 = default(RaycastHit);
			if (((Vector3)(ref val2)).sqrMagnitude < (float)(range * range) && !Physics.Linecast(val.position, objectPosition, ref val3, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				Vector3 val4 = objectPosition - val.position;
				if (!(Vector3.Angle(val.forward, val4) < width))
				{
					val2 = ((Component)this).transform.position - objectPosition;
					if (!(((Vector3)(ref val2)).sqrMagnitude < proximityAwareness * proximityAwareness))
					{
						goto IL_0100;
					}
				}
				return true;
			}
			goto IL_0100;
			IL_0100:
			return false;
		}

		public PlayerControllerB? CheckLineOfSightForPlayer(float width = 45f, int range = 60, int proximityAwareness = -1)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_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)
			//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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
			{
				Vector3 position = ((Component)StartOfRound.Instance.allPlayerScripts[i].gameplayCamera).transform.position;
				Vector3 val = position - eye.position;
				if (!(((Vector3)(ref val)).sqrMagnitude < (float)(range * range)) || Physics.Linecast(eye.position, position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
				{
					continue;
				}
				Vector3 val2 = position - eye.position;
				if (!(Vector3.Angle(eye.forward, val2) < width))
				{
					if (proximityAwareness == -1)
					{
						continue;
					}
					val = eye.position - position;
					if (!(((Vector3)(ref val)).sqrMagnitude < (float)(proximityAwareness * proximityAwareness)))
					{
						continue;
					}
				}
				return StartOfRound.Instance.allPlayerScripts[i];
			}
			return null;
		}

		public EnemyAI? CheckLineOfSightForEnemy(int range)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			foreach (EnemyAI spawnedEnemy in RoundManager.Instance.SpawnedEnemies)
			{
				if (!((Object)(object)spawnedEnemy == (Object)null) && spawnedEnemy.enemyType.canDie && (int)spawnedEnemy.enemyType.EnemySize <= 0)
				{
					Vector3 objectPosition = (((Object)(object)spawnedEnemy.eye != (Object)null) ? spawnedEnemy.eye.position : ((Component)spawnedEnemy).transform.position);
					if (CheckLineOfSightForPosition(objectPosition, 60f, range, 5f))
					{
						return spawnedEnemy;
					}
				}
			}
			return null;
		}

		public void HitFromExplosion(float distance)
		{
			KillEnemyClientRpc();
		}

		public void OnCollideWithPlayer(Collider other)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			if (isDead || timeSinceCollision < 1f)
			{
				return;
			}
			timeSinceCollision = 0f;
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)component == (Object)null || !component.isPlayerControlled)
			{
				return;
			}
			rallying = false;
			if (currentBehaviorState == State.Swarming)
			{
				RoundManager.PlayRandomClip(creatureSFX, attackSFX, true, 1f, 0, 1000);
				if (!((Object)(object)component != (Object)(object)Plugin.localPlayer))
				{
					int num = ((Random.Range(0, 2) == 1) ? 7 : 0);
					component.DamagePlayer(1, true, true, (CauseOfDeath)6, num, false, default(Vector3));
					AddThreat(component);
				}
			}
		}

		public void OnCollideWithEnemy(Collider other, EnemyAI? collidedEnemy = null)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			if (isDead || currentBehaviorState == State.ReturnToNest || timeSinceCollision < 1f || (Object)(object)collidedEnemy == (Object)null || !collidedEnemy.enemyType.canDie || (int)collidedEnemy.enemyType.EnemySize > 0)
			{
				return;
			}
			rallying = false;
			ManualLogSource? logger = Plugin.logger;
			if (logger != null)
			{
				logger.LogDebug((object)("Collided with: " + collidedEnemy.enemyType.enemyName));
			}
			timeSinceCollision = 0f;
			if (collidedEnemy.isEnemyDead)
			{
				AutoDictionary<EnemyAI, int> enemyFoodPointsLeft = RatNest.enemyFoodPointsLeft;
				EnemyAI val = collidedEnemy;
				enemyFoodPointsLeft[val] -= 1;
				holdingFood = true;
				if (RatNest.enemyFoodPointsLeft[collidedEnemy] <= 0)
				{
					((Dictionary<EnemyAI, int>)(object)RatNest.enemyFoodPointsLeft).Remove(collidedEnemy);
					RoundManager.Instance.DespawnEnemyOnServer(((NetworkBehaviour)collidedEnemy).NetworkObject);
				}
				RoundManager.PlayRandomClip(creatureSFX, nibbleSFX, true, 1f, 0, 1000);
				if (Plugin.localPlayer.HasLineOfSightToPosition(((Component)this).transform.position, 45f, 60, -1f, -1))
				{
					Plugin.localPlayer.IncreaseFearLevelOverTime(0.8f, 1f);
				}
				if (((NetworkBehaviour)this).IsServer)
				{
					SwitchToBehaviorClientRpc(State.ReturnToNest);
				}
			}
			else if (RatNest.enemyThreatCounter[collidedEnemy] > Configs.cfgThreatToAttackEnemy)
			{
				AutoDictionary<EnemyAI, int> enemyFoodPointsLeft = RatNest.enemyHitCount;
				EnemyAI val = collidedEnemy;
				enemyFoodPointsLeft[val] -= 1;
				if (RatNest.enemyHitCount[collidedEnemy] <= 0)
				{
					collidedEnemy.HitEnemy(1, (PlayerControllerB)null, true, -1);
					RatNest.enemyHitCount[collidedEnemy] = Configs.cfgEnemyHitsToDoDamage;
				}
			}
			if (currentBehaviorState == State.Swarming)
			{
				RoundManager.PlayRandomClip(creatureSFX, attackSFX, true, 1f, 0, 1000);
			}
		}

		private void AddThreat(EnemyAI enemy, int amount = 1)
		{
			if ((Object)(object)enemy == (Object)null)
			{
				return;
			}
			AutoDictionary<EnemyAI, int> enemyThreatCounter = RatNest.enemyThreatCounter;
			enemyThreatCounter[enemy] += amount;
			int num = RatNest.enemyThreatCounter[enemy];
			ManualLogSource? logger = Plugin.logger;
			if (logger != null)
			{
				logger.LogDebug((object)$"{enemy.enemyType.enemyName}: {num} threat");
			}
			if (currentBehaviorState != State.Swarming)
			{
				if (num > Configs.cfgThreatToAttackEnemy * 2 && !rallying && ((NetworkBehaviour)this).IsServer)
				{
					RallyCall(((Component)enemy).gameObject);
				}
				else if (RatNest.enemyThreatCounter[enemy] > Configs.cfgThreatToAttackEnemy && ((NetworkBehaviour)this).IsServer)
				{
					swarmTarget = ((Component)enemy).gameObject;
					SwitchToBehaviorClientRpc(State.Swarming);
				}
			}
		}

		private void AddThreat(PlayerControllerB player, int amount = 1)
		{
			if ((Object)(object)player == (Object)null || !player.isPlayerControlled)
			{
				return;
			}
			if (((Dictionary<PlayerControllerB, int>)(object)RatNest.playerThreatCounter).ContainsKey(player))
			{
				AutoDictionary<PlayerControllerB, int> playerThreatCounter = RatNest.playerThreatCounter;
				playerThreatCounter[player] += amount;
			}
			else
			{
				((Dictionary<PlayerControllerB, int>)(object)RatNest.playerThreatCounter).Add(player, amount);
			}
			int num = RatNest.playerThreatCounter[player];
			ManualLogSource? logger = Plugin.logger;
			if (logger != null)
			{
				logger.LogDebug((object)$"{player.playerUsername}: {num} threat");
			}
			if (currentBehaviorState != State.Swarming)
			{
				if (num > Configs.cfgThreatToAttackPlayer * 2 && !rallying)
				{
					RallyCall(((Component)player).gameObject);
				}
				else if (num > Configs.cfgThreatToAttackPlayer)
				{
					targetPlayer = player;
					swarmTarget = ((Component)player).gameObject;
					SwitchToBehaviorClientRpc(State.Swarming);
				}
			}
		}

		private void RallyCall(GameObject target)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			swarmTarget = target;
			inSpecialAnimation = true;
			rallying = true;
			creatureVoice.PlayOneShot(screamSFX);
			RallyRats.Invoke(((Component)this).transform.position, swarmTarget);
			if (Configs.cfgUseJermaRats)
			{
				((MonoBehaviour)this).StartCoroutine(InSpecialAnimationFalseRoutine());
				return;
			}
			Animator? obj = animator;
			if (obj != null)
			{
				obj.SetTrigger("rally");
			}
			[IteratorStateMachine(typeof(<<RallyCall>g__InSpecialAnimationFalseRoutine|71_0>d))]
			IEnumerator InSpecialAnimationFalseRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<RallyCall>g__InSpecialAnimationFalseRoutine|71_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		public void FinishRunCycle()
		{
			if (Random.Range(0f, 1f) < Configs.cfgSqueakChance)
			{
				RoundManager.PlayRandomClip(creatureSFX, squeakSFX, true, 1f, 0, 1000);
			}
		}

		public void SetInSpecialAnimationFalse()
		{
			inSpecialAnimation = false;
		}

		public void HitEnemy(int force, int playerHitBy = -1)
		{
			if (playerHitBy != -1)
			{
				PlayerControllerB player = Plugin.PlayerFromId((ulong)playerHitBy);
				AddThreat(player);
			}
			health -= force;
			RoundManager.PlayRandomClip(creatureSFX, hitSFX, true, 1f, 0, 1000);
			if (health <= 0)
			{
				KillEnemy();
			}
			if ((Object)(object)heldObject != (Object)null || (Object)(object)heldBody != (Object)null)
			{
				DropObjectOnLocalClient(despawn: false);
			}
		}

		public void KillEnemy()
		{
			isDead = true;
			Animator? obj = animator;
			if (obj != null)
			{
				obj.SetTrigger(hashDie);
			}
			Animator? obj2 = animator;
			if (obj2 != null)
			{
				obj2.Update(0f);
			}
			if (((NetworkBehaviour)this).IsServer)
			{
				((MonoBehaviour)this).StopAllCoroutines();
				((Behaviour)nav.agent).enabled = false;
				nav.OnEnableOrDisableAgent.Invoke(false);
				ResetVariables();
			}
		}

		public void ResetVariables()
		{
			if (previousBehaviorState == State.Swarming)
			{
				foreach (RatNest nest in RatNest.nests)
				{
					nest?.DefenseRats?.Remove(this);
				}
			}
			closestNest = null;
		}

		public void SwitchToBehaviorOnLocalClient(State state)
		{
			if (currentBehaviorState != state)
			{
				previousBehaviorState = currentBehaviorState;
				currentBehaviorState = state;
				timeSinceSwitchBehavior = 0f;
				ResetVariables();
			}
		}

		[ClientRpc]
		public void SwitchToBehaviorClientRpc(State state)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2151512038u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<State>(ref state, default(ForEnums));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2151512038u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					SwitchToBehaviorOnLocalClient(state);
				}
			}
		}

		[ClientRpc]
		public void PlayRallySFXClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2845775495u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2845775495u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					creatureSFX.PlayOneShot(screamSFX);
				}
			}
		}

		[ClientRpc]
		public void GrabObjectClientRpc(NetworkObjectReference netRef)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2230573478u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref netRef, default(ForNetworkSerializable));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2230573478u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					NetworkObject val3 = default(NetworkObject);
					((NetworkObjectReference)(ref netRef)).TryGet(ref val3, (NetworkManager)null);
					GrabbableObject component = ((Component)val3).GetComponent<GrabbableObject>();
					component.parentObject = ratMouthTransform;
					component.hasHitGround = false;
					component.isHeldByEnemy = true;
					component.EnablePhysics(false);
					HoarderBugAI.grabbableObjectsInMap.Remove(((Component)component).gameObject);
					heldObject = component;
					RoundManager.PlayRandomClip(creatureSFX, nibbleSFX, true, 1f, -1, 1000);
					SwitchToBehaviorOnLocalClient(State.ReturnToNest);
				}
			}
		}

		[ClientRpc]
		public void GrabBodyClientRpc(ulong clientId, int attachedLimbIndex)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3500738837u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, clientId);
					BytePacker.WriteValueBitPacked(val2, attachedLimbIndex);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3500738837u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					targetPlayer = Plugin.PlayerFromId(clientId);
					heldBody = targetPlayer.deadBody;
					heldBody.attachedTo = ratMouthTransform;
					heldBody.attachedLimb = targetPlayer.deadBody.bodyParts[attachedLimbIndex];
					heldBody.matchPositionExactly = true;
					RoundManager.PlayRandomClip(creatureSFX, nibbleSFX, true, 1f, -1, 1000);
					SwitchToBehaviorOnLocalClient(State.ReturnToNest);
				}
			}
		}

		[ClientRpc]
		public void DropObjectClientRpc(bool despawn)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3305414665u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref despawn, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3305414665u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					DropObjectOnLocalClient(despawn);
				}
			}
		}

		public void DropObjectOnLocalClient(bool despawn)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00ec: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)heldBody != (Object)null)
			{
				heldBody.attachedTo = null;
				heldBody.attachedLimb = null;
				heldBody.matchPositionExactly = false;
				if (despawn)
				{
					heldBody.DeactivateBody(false);
				}
				heldBody = null;
			}
			if ((Object)(object)heldObject != (Object)null)
			{
				Vector3 floorPosition = Vector3Extensions.GetFloorPosition(((Component)heldObject).transform.position, 0f);
				heldObject.parentObject = null;
				((Component)heldObject).transform.SetParent(StartOfRound.Instance.propsContainer, true);
				heldObject.EnablePhysics(true);
				heldObject.fallTime = 0f;
				heldObject.startFallingPosition = ((Component)heldObject).transform.parent.InverseTransformPoint(((Component)heldObject).transform.position);
				heldObject.targetFloorPosition = ((Component)heldObject).transform.parent.InverseTransformPoint(floorPosition);
				heldObject.DiscardItemFromEnemy();
				heldObject.isHeldByEnemy = false;
				if (despawn)
				{
					((NetworkBehaviour)heldObject).NetworkObject.Despawn(true);
				}
				else
				{
					HoarderBugAI.grabbableObjectsInMap.Add(((Component)heldObject).gameObject);
				}
				heldObject = null;
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void HitEnemyServerRpc(int force, int playerHitBy = -1)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3308590472u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, force);
				BytePacker.WriteValueBitPacked(val2, playerHitBy);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3308590472u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (((NetworkBehaviour)this).IsServer)
				{
					HitEnemyClientRpc(force, playerHitBy);
				}
			}
		}

		[ClientRpc]
		private void HitEnemyClientRpc(int force, int playerHitBy = -1)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2203808049u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, force);
					BytePacker.WriteValueBitPacked(val2, playerHitBy);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2203808049u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					HitEnemy(force, playerHitBy);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void KillEnemyServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3223101186u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3223101186u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (((NetworkBehaviour)this).IsServer)
				{
					KillEnemyClientRpc();
				}
			}
		}

		[ClientRpc]
		private void KillEnemyClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(4064924559u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 4064924559u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					KillEnemy();
				}
			}
		}

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

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(2151512038u, new RpcReceiveHandler(__rpc_handler_2151512038), "SwitchToBehaviorClientRpc");
			((NetworkBehaviour)this).__registerRpc(2845775495u, new RpcReceiveHandler(__rpc_handler_2845775495), "PlayRallySFXClientRpc");
			((NetworkBehaviour)this).__registerRpc(2230573478u, new RpcReceiveHandler(__rpc_handler_2230573478), "GrabObjectClientRpc");
			((NetworkBehaviour)this).__registerRpc(3500738837u, new RpcReceiveHandler(__rpc_handler_3500738837), "GrabBodyClientRpc");
			((NetworkBehaviour)this).__registerRpc(3305414665u, new RpcReceiveHandler(__rpc_handler_3305414665), "DropObjectClientRpc");
			((NetworkBehaviour)this).__registerRpc(3308590472u, new RpcReceiveHandler(__rpc_handler_3308590472), "HitEnemyServerRpc");
			((NetworkBehaviour)this).__registerRpc(2203808049u, new RpcReceiveHandler(__rpc_handler_2203808049), "HitEnemyClientRpc");
			((NetworkBehaviour)this).__registerRpc(3223101186u, new RpcReceiveHandler(__rpc_handler_3223101186), "KillEnemyServerRpc");
			((NetworkBehaviour)this).__registerRpc(4064924559u, new RpcReceiveHandler(__rpc_handler_4064924559), "KillEnemyClientRpc");
			((NetworkBehaviour)this).__initializeRpcs();
		}

		private static void __rpc_handler_2151512038(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				State state = default(State);
				((FastBufferReader)(ref reader)).ReadValueSafe<State>(ref state, default(ForEnums));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RatAI)(object)target).SwitchToBehaviorClientRpc(state);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2845775495(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;
				((RatAI)(object)target).PlayRallySFXClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2230573478(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				NetworkObjectReference netRef = default(NetworkObjectReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref netRef, default(ForNetworkSerializable));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RatAI)(object)target).GrabObjectClientRpc(netRef);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3500738837(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong clientId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
				int attachedLimbIndex = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref attachedLimbIndex);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RatAI)(object)target).GrabBodyClientRpc(clientId, attachedLimbIndex);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3305414665(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool despawn = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref despawn, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RatAI)(object)target).DropObjectClientRpc(despawn);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3308590472(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int force = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref force);
				int playerHitBy = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerHitBy);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RatAI)(object)target).HitEnemyServerRpc(force, playerHitBy);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2203808049(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int force = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref force);
				int playerHitBy = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerHitBy);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RatAI)(object)target).HitEnemyClientRpc(force, playerHitBy);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3223101186(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;
				((RatAI)(object)target).KillEnemyServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_4064924559(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;
				((RatAI)(object)target).KillEnemyClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "RatAI";
		}
	}
	public class RatAICollisionDetect : MonoBehaviour, IHittable
	{
		public RatAI mainScript = null;

		private void OnTriggerStay(Collider other)
		{
			if (((Component)other).CompareTag("Player"))
			{
				mainScript.OnCollideWithPlayer(other);
			}
			else if (((Component)other).CompareTag("Enemy"))
			{
				EnemyAICollisionDetect component = ((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component != (Object)null)
				{
					mainScript.OnCollideWithEnemy(other, component.mainScript);
				}
			}
		}

		bool IHittable.Hit(int force, Vector3 hitDirection, PlayerControllerB? playerWhoHit, bool playHitSFX, int hitID)
		{
			int playerHitBy = (((Object)(object)playerWhoHit != (Object)null) ? ((int)playerWhoHit.actualClientId) : (-1));
			mainScript.HitEnemyServerRpc(force, playerHitBy);
			return true;
		}
	}
	[HarmonyPatch]
	internal static class RatAIPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Landmine), "SpawnExplosion")]
		public static void Landmine_SpawnExplosion_Postfix(Vector3 explosionPosition, bool spawnExplosionEffect = false, float killRange = 1f, float damageRange = 1f, int nonLethalDamage = 50, float physicsForce = 0f, GameObject overridePrefab = null, bool goThroughCar = false)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.IsServerOrHost)
			{
				return;
			}
			foreach (RatAI instance in RatAI.Instances)
			{
				if (!((Object)(object)instance == (Object)null) && !instance.isDead)
				{
					float num = Vector3.Distance(((Component)instance).transform.position, explosionPosition);
					if (num < damageRange)
					{
						instance.HitFromExplosion(num);
					}
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		public static void GrabbableObject_Start_Postfix(GrabbableObject __instance)
		{
			if (Plugin.IsServerOrHost)
			{
				DawnItemInfo dawnInfo = ItemExtensions.GetDawnInfo(__instance.itemProperties);
				if (dawnInfo != null && (((DawnBaseInfo<DawnItemInfo>)(object)dawnInfo).AllTags().Any((NamespacedKey x) => Configs.cfgFoodItemTags.Contains<string>(((object)x).ToString())) || Configs.cfgFoodItemNames.Contains<string>(((object)((DawnBaseInfo<DawnItemInfo>)(object)dawnInfo).TypedKey).ToString())))
				{
					RatAI.StealableObjects.Add(__instance);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GrabbableObject), "OnDestroy")]
		public static void GrabbableObject_OnDestroy_Postfix(GrabbableObject __instance)
		{
			if (Plugin.IsServerOrHost)
			{
				RatAI.StealableObjects.Remove(__instance);
			}
		}
	}
	internal class LethalDiseasesCompatibility
	{
	}
	internal static class LevelInfestations
	{
		public static Dictionary<string, int> levelInfestations = new Dictionary<string, int>();

		public static string currentLevel = "";

		private const string saveName = "RatLevelInfestations";

		public static float currentLevelInfestationPercentage => RatAI.Instances.Where((RatAI x) => !x.isDead).Count() / Configs.cfgMaxRats;

		public static float currentLevelInfestation => RatAI.Instances.Where((RatAI x) => !x.isDead).Count();

		public static void UpdateLevelInfestation()
		{
			if (Configs.cfgEnableInfestationSystem && !(currentLevel == ""))
			{
				if (!levelInfestations.ContainsKey(currentLevel))
				{
					levelInfestations.Add(currentLevel, 0);
				}
				levelInfestations[currentLevel] = Mathf.Min(RatAI.Instances.Where((RatAI x) => !x.isDead).Count(), Configs.cfgMaxRats);
			}
		}

		public static void SpawnRatsForLevel()
		{
			if (!Configs.cfgEnableInfestationSystem)
			{
				return;
			}
			currentLevel = ((Object)StartOfRound.Instance.currentLevel).name;
			if (!levelInfestations.ContainsKey(currentLevel))
			{
				return;
			}
			int num = levelInfestations[currentLevel];
			if (num <= 0 || RatNest.nests.Count == 0)
			{
				return;
			}
			int amount = num / RatNest.nests.Count;
			foreach (RatNest nest in RatNest.nests)
			{
				nest.SpawnRats(amount);
			}
		}

		public static void LoadData()
		{
			if (Configs.cfgEnableInfestationSystem)
			{
				ManualLogSource? logger = Plugin.logger;
				if (logger != null)
				{
					logger.LogDebug((object)"Loading infestation data");
				}
				levelInfestations = ES3.Load<Dictionary<string, int>>("RatLevelInfestations", GameNetworkManager.Instance.currentSaveFileName);
				Log();
			}
		}

		public static void SaveData()
		{
			if (Configs.cfgEnableInfestationSystem)
			{
				ManualLogSource? logger = Plugin.logger;
				if (logger != null)
				{
					logger.LogDebug((object)"Saving infestation data");
				}
				ES3.Save<Dictionary<string, int>>("RatLevelInfestations", levelInfestations, GameNetworkManager.Instance.currentSaveFileName);
			}
		}

		public static void ResetData()
		{
			if (Configs.cfgEnableInfestationSystem)
			{
				levelInfestations.Clear();
				ES3.DeleteKey("RatLevelInfestations", GameNetworkManager.Instance.currentSaveFileName);
			}
		}

		public static void Log()
		{
			foreach (KeyValuePair<string, int> levelInfestation in levelInfestations)
			{
				ManualLogSource? logger = Plugin.logger;
				if (logger != null)
				{
					logger.LogDebug((object)$"{levelInfestation.Key}: {levelInfestation.Value}");
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class LevelInfestationsPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "OnShipLandedMiscEvents")]
		public static void StartOfRound_OnShipLandedMiscEvents_Postfix()
		{
			try
			{
				if (Plugin.IsServerOrHost)
				{
					LevelInfestations.SpawnRatsForLevel();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? logger = Plugin.logger;
				if (logger != null)
				{
					logger.LogError((object)ex);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "SaveGameValues")]
		public static void GameNetworkManager_SaveGameValues_Postfix()
		{
			try
			{
				if (Plugin.IsServerOrHost)
				{
					LevelInfestations.SaveData();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? logger = Plugin.logger;
				if (logger != null)
				{
					logger.LogError((object)ex);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		public static void StartOfRound_Start_Postfix()
		{
			try
			{
				if (Plugin.IsServerOrHost)
				{
					LevelInfestations.SaveData();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? logger = Plugin.logger;
				if (logger != null)
				{
					logger.LogError((object)ex);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "ResetSavedGameValues")]
		public static void GameNetworkManager_ResetSavedGameValues_Postfix()
		{
			try
			{
				if (Plugin.IsServerOrHost)
				{
					LevelInfestations.ResetData();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? logger = Plugin.logger;
				if (logger != null)
				{
					logger.LogError((object)ex);
				}
			}
		}
	}
	[BepInPlugin("Snowlance.Rats", "Rats", "1.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("Snowlance.Rats");

		public static Plugin Instance { get; private set; }

		public static ManualLogSource? logger { get; private set; }

		public static DuskMod Mod { get; private set; }

		public static PlayerControllerB localPlayer => GameNetworkManager.Instance.localPlayerController;

		public static bool IsServerOrHost => NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost;

		public static PlayerControllerB PlayerFromId(ulong id)
		{
			return StartOfRound.Instance.allPlayerScripts[StartOfRound.Instance.ClientPlayerList[id]];
		}

		public void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = (Utils.testing ? ((BaseUnityPlugin)Instance).Logger : null);
			harmony.PatchAll();
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "rats_mainassets"));
			Mod = DuskMod.RegisterMod((BaseUnityPlugin)(object)this, val);
			Mod.RegisterContentHandlers();
			Configs.Init();
			InitializeNetworkBehaviours();
			ManualLogSource? obj = logger;
			if (obj != null)
			{
				obj.LogInfo((object)"Snowlance.Rats v1.4.0 has loaded!");
			}
		}

		public static void InitializeNetworkBehaviours()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
			ManualLogSource? obj = logger;
			if (obj != null)
			{
				obj.LogDebug((object)"Finished initializing network behaviours");
			}
		}
	}
	public class RatNest : NetworkBehaviour
	{
		[CompilerGenerated]
		private sealed class <<SpawnRats>g__SpawnRatsCoroutine|41_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public int amount;

			public RatNest <>4__this;

			private int <i>5__1;

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

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

			[DebuggerHidden]
			public <<SpawnRats>g__SpawnRatsCoroutine|41_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<i>5__1 = 0;
					break;
				case 2:
					<>1__state = -1;
					<>4__this.SpawnRat();
					<i>5__1++;
					break;
				}
				if (<i>5__1 < amount)
				{
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				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();
			}
		}

		public GameObject ratPrefab = null;

		public GameObject jermaRatPrefab = null;

		public GameObject meshObj = null;

		public ScanNodeProperties scanNode = null;

		public MeshRenderer voidPlaneRenderer = null;

		public GameObject poisonLiquidPlaneObj = null;

		public Material yellowMat = null;

		public ParticleSystem gasParticleSystem = null;

		public Animator animator = null;

		public AudioSource audioSource = null;

		public static AutoDictionary<EnemyAI, int> enemyHitCount = new AutoDictionary<EnemyAI, int>((Func<EnemyAI, int>)((EnemyAI enemy) => Configs.cfgEnemyHitsToDoDamage));

		public static AutoDictionary<PlayerControllerB, int> playerThreatCounter = new AutoDictionary<PlayerControllerB, int>((Func<PlayerControllerB, int>)((PlayerControllerB player) => 0));

		public static AutoDictionary<EnemyAI, int> enemyThreatCounter = new AutoDictionary<EnemyAI, int>((Func<EnemyAI, int>)((EnemyAI enemy) => 0));

		public static AutoDictionary<EnemyAI, int> enemyFoodPointsLeft = new AutoDictionary<EnemyAI, int>((Func<EnemyAI, int>)((EnemyAI enemy) => enemy.enemyType.enemyPrefab.GetComponent<EnemyAI>().enemyHP * Configs.cfgEnemyFoodPerHPPoint));

		public bool isOpen = true;

		private float timeSinceSpawnRat;

		private float nextRatSpawnTime;

		private int food;

		public float poisonInNest;

		private Vector3 poisonPlaneStart;

		private Vector3 poisonPlaneEnd;

		private const float poisonUpOffset = 0.0219f;

		private int batchIndex = 0;

		public HashSet<RatAI> DefenseRats = new HashSet<RatAI>();

		public static RatNest? mainInstance => nests.FirstOrDefault();

		public bool isMainInstance => (Object)(object)mainInstance != (Object)null && (Object)(object)mainInstance == (Object)(object)this;

		public static HashSet<RatNest> nests { get; private set; } = new HashSet<RatNest>();


		public static List<RatNest> nestsOpen => nests.Where((RatNest x) => x.isOpen).ToList();

		public void Start()
		{
			//IL_0017: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_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_0066: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource? logger = Plugin.logger;
			if (logger != null)
			{
				Vector3 position = ((Component)this).transform.position;
				logger.LogDebug((object)("Rat nest spawned at: " + ((object)(Vector3)(ref position)).ToString()));
			}
			poisonPlaneStart = poisonLiquidPlaneObj.transform.position;
			poisonPlaneEnd = poisonPlaneStart + Vector3.up * 0.0219f;
			nextRatSpawnTime = Configs.cfgRatSpawnTime.GetRandomInRange(Utils.randomLocal);
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			nests.Add(this);
		}

		public override void OnNetworkDespawn()
		{
			if (nests.Count <= 1)
			{
				LevelInfestations.UpdateLevelInfestation();
				if (((NetworkBehaviour)this).IsServer)
				{
					foreach (RatAI item in RatAI.Instances.ToList())
					{
						if (item != null)
						{
							NetworkObject networkObject = ((NetworkBehaviour)item).NetworkObject;
							if (networkObject != null)
							{
								networkObject.Despawn(true);
							}
						}
					}
				}
				((Dictionary<EnemyAI, int>)(object)enemyHitCount).Clear();
				((Dictionary<PlayerControllerB, int>)(object)playerThreatCounter).Clear();
				((Dictionary<EnemyAI, int>)(object)enemyThreatCounter).Clear();
				((Dictionary<EnemyAI, int>)(object)enemyFoodPointsLeft).Clear();
			}
			nests.Remove(this);
			((NetworkBehaviour)this).OnNetworkDespawn();
		}

		public void Update()
		{
			timeSinceSpawnRat += Time.unscaledDeltaTime;
			if (!((NetworkBehaviour)this).IsServer)
			{
				return;
			}
			if (isOpen)
			{
				if (RatAI.Instances.Count < Configs.cfgMaxRats && timeSinceSpawnRat > nextRatSpawnTime)
				{
					timeSinceSpawnRat = 0f;
					nextRatSpawnTime = Configs.cfgRatSpawnTime.GetRandomInRange(Utils.randomLocal);
					SpawnRat();
				}
				if (poisonInNest >= Configs.cfgPoisonToCloseNest)
				{
					isOpen = false;
					CloseNestClientRpc();
					if (nestsOpen.Count > 1)
					{
					}
				}
			}
			if (isMainInstance && Time.frameCount % Mathf.CeilToInt(Configs.cfgBatchUpdateInterval / Time.deltaTime) == 0)
			{
				RunBatch();
			}
		}

		private void RunBatch()
		{
			List<RatAI> list = RatAI.Instances.Where((RatAI x) => !x.isDead).ToList();
			int count = list.Count;
			if (count == 0)
			{
				return;
			}
			int num = Mathf.Max(1, count / Mathf.CeilToInt(1f / Configs.cfgBatchUpdateInterval));
			for (int i = 0; i < num; i++)
			{
				RatAI ratAI = list[batchIndex];
				if ((Object)(object)ratAI != (Object)null)
				{
					ratAI.DoAIInterval();
				}
				batchIndex++;
				if (batchIndex >= count)
				{
					batchIndex = 0;
				}
			}
		}

		public void AddFood(int amount = 1)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				food += amount;
				int amount2 = food / Configs.cfgFoodToSpawnRat;
				int num = food % Configs.cfgFoodToSpawnRat;
				food = num;
				SpawnRats(amount2);
			}
		}

		private void SpawnRat()
		{
			//IL_0089: 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_0096: 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_00a3: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			if ((Utils.testing || (!StartOfRound.Instance.inShipPhase && !StartOfRound.Instance.shipIsLeaving)) && RatAI.Instances.Where((RatAI x) => !x.isDead).Count() < Configs.cfgMaxRats)
			{
				GameObject val = (Configs.cfgUseJermaRats ? jermaRatPrefab : ratPrefab);
				Vector3 navMeshPosition = RoundManager.Instance.GetNavMeshPosition(((Component)this).transform.position, default(NavMeshHit), 5f, -1);
				GameObject val2 = Object.Instantiate<GameObject>(val, navMeshPosition, Quaternion.identity);
				val2.GetComponent<NetworkObject>().Spawn(false);
			}
		}

		public void SpawnRats(int amount)
		{
			if (amount != 0)
			{
				ManualLogSource? logger = Plugin.logger;
				if (logger != null)
				{
					logger.LogDebug((object)("Spawning rats from food: " + amount));
				}
				((MonoBehaviour)this).StartCoroutine(SpawnRatsCoroutine(amount));
			}
			[IteratorStateMachine(typeof(<<SpawnRats>g__SpawnRatsCoroutine|41_0>d))]
			IEnumerator SpawnRatsCoroutine(int amount)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<SpawnRats>g__SpawnRatsCoroutine|41_0>d(0)
				{
					<>4__this = this,
					amount = amount
				};
			}
		}

		public static RatNest? GetClosestNestToPosition(Vector3 position, bool checkForPath = false)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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)
			float num = float.PositiveInfinity;
			RatNest result = null;
			foreach (RatNest nest in nests)
			{
				if (!((Object)(object)nest == (Object)null) && nest.isOpen)
				{
					Vector3 val = position - ((Component)nest).transform.position;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (!(sqrMagnitude >= num) && (!checkForPath || Utils.CanPathToPoint(position, ((Component)nest).transform.position)))
					{
						num = sqrMagnitude;
						result = nest;
					}
				}
			}
			return result;
		}

		public void OnNestClosed()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				((NetworkBehaviour)this).NetworkObject.Despawn(true);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void AddPoisonServerRpc(float amount)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3899135728u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref amount, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3899135728u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (((NetworkBehaviour)this).IsServer)
				{
					AddPoisonClientRpc(amount);
				}
			}
		}

		[ClientRpc]
		private void AddPoisonClientRpc(float amount)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(493184450u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref amount, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 493184450u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					((Renderer)voidPlaneRenderer).material = yellowMat;
					poisonInNest = Mathf.Min(poisonInNest + amount, Configs.cfgPoisonToCloseNest);
					float num = Mathf.Clamp01(poisonInNest / Configs.cfgPoisonToCloseNest);
					poisonLiquidPlaneObj.transform.position = Vector3.Lerp(poisonPlaneStart, poisonPlaneEnd, num);
				}
			}
		}

		[ClientRpc]
		public void CloseNestClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3776607502u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3776607502u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					isOpen = false;
					gasParticleSystem.Play();
					animator.SetTrigger("destroy");
					((Component)scanNode).gameObject.SetActive(false);
					audioSource.Play();
				}
			}
		}

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

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown