Decompiled source of MoreEntitiesSpawn v1.0.5

BepInEx/plugins/MoreEntitiesSpawn/HitsujiSauce.MoreEntitiesSpawn.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MoreEntitiesSpawn;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HitsujiSauce.MoreEntitiesSpawn")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MoreEntitiesSpawn")]
[assembly: AssemblyTitle("HitsujiSauce.MoreEntitiesSpawn")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
}
[HarmonyPatch(typeof(RoundManager))]
public class RoundManagerPatch
{
	private static float multiplier = 1f;

	private static float cannotDieMultiplier;

	private static bool useCustomMultiplier = false;

	private static float nextSpawnTime = 0f;

	public static int failedSpawnedCount = 0;

	public static List<int> prevEnemies = new List<int>();

	public static int BlackenMaxCount;

	public static int ManeaterMaxCount;

	[HarmonyPatch("RefreshEnemiesList")]
	[HarmonyPostfix]
	public static void RefreshEnemiesListPostfix(RoundManager __instance)
	{
		if (!NetworkManager.Singleton.IsHost)
		{
			return;
		}
		global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.Reload();
		useCustomMultiplier = global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.useCustomMultiplier.Value;
		cannotDieMultiplier = global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.cannotDieMultiplier.Value;
		EnemyAIPatch.despawnTimer = global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.entitiesRespawnTimer.Value;
		ButlerBeeEnemyAIPatch.despawnTimer = global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.butlerBeesDespawnTimer.Value;
		if (useCustomMultiplier)
		{
			multiplier = global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.customMultiplier.Value;
		}
		else
		{
			int num = StartOfRound.Instance.connectedPlayersAmount + 1;
			multiplier = ((num < 4) ? 1f : ((float)num / 4f));
		}
		__instance.currentMaxInsidePower = Mathf.Clamp(__instance.currentMaxInsidePower * (1f + (multiplier - 1f) * 0.5f), __instance.currentMaxInsidePower, global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.maxPower.Value);
		if (prevEnemies.Count > 0)
		{
			prevEnemies.Clear();
		}
		for (int i = 0; i < __instance.currentLevel.Enemies.Count; i++)
		{
			prevEnemies.Add(__instance.currentLevel.Enemies[i].rarity);
			EnemyType enemyType = __instance.currentLevel.Enemies[i].enemyType;
			if (enemyType.canDie && enemyType.enemyName != "Blob")
			{
				float num2 = 1.7f;
				if (enemyType.enemyName == "Butler")
				{
					num2 = 1.5f;
				}
				if (enemyType.enemyName == "Hoarding bug")
				{
					num2 = 1.5f;
				}
				SpawnableEnemyWithRarity obj = __instance.currentLevel.Enemies[i];
				obj.rarity += Mathf.RoundToInt((float)__instance.currentLevel.Enemies[i].rarity * (multiplier - 1f) * num2);
			}
			else
			{
				__instance.currentLevel.Enemies[i].rarity = (int)((float)__instance.currentLevel.Enemies[i].rarity * cannotDieMultiplier);
			}
		}
		failedSpawnedCount = 0;
		BlackenMaxCount = 2;
		ManeaterMaxCount = 2;
		nextSpawnTime = 0f;
	}

	[HarmonyPatch("AdvanceHourAndSpawnNewBatchOfEnemies")]
	[HarmonyPostfix]
	public static void AdvanceHourAndSpawnNewBatchOfEnemiesPostfix(RoundManager __instance)
	{
		if (NetworkManager.Singleton.IsHost && __instance.enemySpawnTimes != null)
		{
			if (useCustomMultiplier)
			{
				multiplier = global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.customMultiplier.Value;
			}
			else
			{
				int connectedPlayersAmount = StartOfRound.Instance.connectedPlayersAmount;
				multiplier = ((connectedPlayersAmount < 4) ? 1f : ((float)connectedPlayersAmount / 4f));
			}
			int count = __instance.enemySpawnTimes.Count;
			float num = (float)__instance.AnomalyRandom.NextDouble();
			float num2 = Mathf.Clamp(multiplier * 0.8f + multiplier * 0.2f * num, 1f, 10f);
			int num3 = Mathf.RoundToInt((float)count * num2);
			if (num3 == 0)
			{
				num3 = (((int)__instance.currentMaxInsidePower > (int)__instance.currentEnemyPower) ? Mathf.Clamp(Mathf.RoundToInt((multiplier - 1f) * 2f * (num + 0.5f)), 0, 5) : Mathf.FloorToInt(multiplier * 0.5f + (num - 0.49f) * multiplier * 0.5f));
			}
			AddVentEnemy(num3);
		}
	}

	[HarmonyPatch(typeof(RoundManager))]
	[HarmonyPatch("InsideEnemyCannotBeSpawned")]
	[HarmonyPrefix]
	private static bool EnemyCannotBeSpawnedPrefix(RoundManager __instance, int enemyIndex, ref bool __result)
	{
		if (!NetworkManager.Singleton.IsHost)
		{
			return true;
		}
		EnemyType enemyType = __instance.currentLevel.Enemies[enemyIndex].enemyType;
		int num = enemyType.MaxCount;
		if (enemyType.canDie && enemyType.enemyName != "Blob")
		{
			num = ((enemyType.enemyName == "Flowerman") ? Mathf.Min(Mathf.FloorToInt((float)enemyType.MaxCount * multiplier), BlackenMaxCount) : ((!(enemyType.enemyName == "Maneater")) ? Mathf.RoundToInt((float)enemyType.MaxCount * multiplier) : Mathf.Min(Mathf.FloorToInt((float)enemyType.MaxCount * multiplier), ManeaterMaxCount)));
		}
		bool flag = enemyType.spawningDisabled || enemyType.PowerLevel > __instance.currentMaxInsidePower - __instance.currentEnemyPower || enemyType.numberSpawned >= num;
		__result = flag;
		return false;
	}

	[HarmonyPatch("SpawnEnemyFromVent")]
	[HarmonyPostfix]
	public static void SpawnEnemyFromVentPatch(RoundManager __instance, EnemyVent vent)
	{
		if (NetworkManager.Singleton.IsHost && failedSpawnedCount > 0 && (int)__instance.currentMaxInsidePower > (int)__instance.currentEnemyPower)
		{
			float currentDayTime = __instance.timeScript.currentDayTime;
			int num = __instance.AnomalyRandom.Next((int)(20f + currentDayTime), (int)(50f + currentDayTime));
			if (__instance.AssignRandomEnemyToVent(vent, (float)num))
			{
				failedSpawnedCount--;
				__instance.enemySpawnTimes.Add(num);
				__instance.enemySpawnTimes.Sort();
			}
		}
	}

	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	public static void testPatch(RoundManager __instance)
	{
		if (NetworkManager.Singleton.IsHost && Mathf.Abs(nextSpawnTime - (float)__instance.currentHour * __instance.timeScript.lengthOfHours) < 30f)
		{
			nextSpawnTime += 30f;
		}
	}

	public static void AddVentEnemy(int num)
	{
		RoundManager instance = RoundManager.Instance;
		List<EnemyVent> list = new List<EnemyVent>();
		for (int i = 0; i < instance.allEnemyVents.Length; i++)
		{
			if (!instance.allEnemyVents[i].occupied)
			{
				list.Add(instance.allEnemyVents[i]);
			}
		}
		float currentDayTime = instance.timeScript.currentDayTime;
		for (int j = 0; j + instance.enemySpawnTimes.Count < num; j++)
		{
			int num2 = instance.AnomalyRandom.Next((int)(5f + currentDayTime), (int)(15f + currentDayTime));
			int index = instance.AnomalyRandom.Next(list.Count);
			if (list.Count == 0)
			{
				failedSpawnedCount++;
				continue;
			}
			if (!instance.AssignRandomEnemyToVent(list[index], (float)num2))
			{
				failedSpawnedCount++;
				continue;
			}
			failedSpawnedCount--;
			if (failedSpawnedCount < 0)
			{
				failedSpawnedCount = 0;
			}
			list.RemoveAt(index);
			instance.enemySpawnTimes.Add(num2);
		}
		instance.enemySpawnTimes.Sort();
	}
}
[HarmonyPatch(typeof(StartOfRound))]
public class RoundManagerPatches
{
	[HarmonyPatch("EndOfGame")]
	[HarmonyPostfix]
	public static void EndOfGamePostfix(StartOfRound __instance)
	{
		if (NetworkManager.Singleton.IsHost)
		{
			for (int i = 0; i < RoundManagerPatch.prevEnemies.Count; i++)
			{
				RoundManager.Instance.currentLevel.Enemies[i].rarity = RoundManagerPatch.prevEnemies[i];
			}
			ButlerBeeEnemyAIPatch.timer.Clear();
			EnemyAIPatch.timer.Clear();
		}
	}
}
[HarmonyPatch(typeof(GameNetworkManager))]
public class GameNetworkManagerPatch
{
	[HarmonyPatch("Disconnect")]
	[HarmonyPostfix]
	public static void DisconnectPostfix(GameNetworkManager __instance)
	{
		if (NetworkManager.Singleton.IsHost)
		{
			for (int i = 0; i < RoundManagerPatch.prevEnemies.Count; i++)
			{
				RoundManager.Instance.currentLevel.Enemies[i].rarity = RoundManagerPatch.prevEnemies[i];
			}
			ButlerBeeEnemyAIPatch.timer.Clear();
			EnemyAIPatch.timer.Clear();
		}
	}
}
[HarmonyPatch(typeof(EnemyAI))]
public class EnemyAIPatch
{
	[CompilerGenerated]
	private sealed class <DespawnCoroutine>d__9 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public EnemyAI __instance;

		private SandSpiderAI <spider>5__1;

		private int <webCount>5__2;

		private int <i>5__3;

		private Vector3 <position>5__4;

		private NutcrackerEnemyAI <nc>5__5;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<spider>5__1 = null;
			<nc>5__5 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				if (__instance.enemyType.enemyName == "Butler")
				{
					__instance.SwitchToBehaviourState(0);
					<>2__current = (object)new WaitForSeconds(5f);
					<>1__state = 1;
					return true;
				}
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if (__instance.enemyType.enemyName == "Bunker Spider")
			{
				<spider>5__1 = (SandSpiderAI)__instance;
				<webCount>5__2 = <spider>5__1.webTraps.Count;
				<i>5__3 = 0;
				while (<i>5__3 < <webCount>5__2)
				{
					<position>5__4 = <spider>5__1.webTraps[0].centerOfWeb.position;
					<spider>5__1.BreakWebClientRpc(<position>5__4, <spider>5__1.webTraps[0].trapID);
					<i>5__3++;
				}
				<spider>5__1 = null;
			}
			((NetworkBehaviour)__instance).NetworkObject.Despawn(true);
			EnemyType enemyType = __instance.enemyType;
			enemyType.numberSpawned--;
			if (__instance.enemyType.numberSpawned < 0)
			{
				__instance.enemyType.numberSpawned = 0;
			}
			RoundManagerPatch.failedSpawnedCount++;
			if (__instance.enemyType.enemyName == "Nutcracker")
			{
				<nc>5__5 = (NutcrackerEnemyAI)__instance;
				((NetworkBehaviour)<nc>5__5.gun).NetworkObject.Despawn(true);
				<nc>5__5 = null;
			}
			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();
		}
	}

	[CompilerGenerated]
	private sealed class <VisionCheckCoroutine>d__6 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public EnemyAI __instance;

		private bool <isLoop>5__1;

		private bool <flag>5__2;

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

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

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

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

		private bool MoveNext()
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<isLoop>5__1 = true;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if (<isLoop>5__1)
			{
				<isLoop>5__1 = !__instance.isEnemyDead && timer.ContainsKey(((NetworkBehaviour)__instance).NetworkObjectId);
				<flag>5__2 = IsBeingWatchedByPlayer(__instance);
				if (<flag>5__2)
				{
					timer[((NetworkBehaviour)__instance).NetworkObjectId].time = RoundManager.Instance.timeScript.currentDayTime + (float)despawnTimer.Value;
				}
				<>2__current = (object)new WaitForSeconds(0.33f);
				<>1__state = 1;
				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 static Dictionary<ulong, EnemyDespawnStatus> timer = new Dictionary<ulong, EnemyDespawnStatus>();

	public static int? despawnTimer = 120;

	[HarmonyPatch("SubtractFromPowerLevel")]
	[HarmonyPostfix]
	public static void SubtractFromPowerLevelPatch(EnemyAI __instance)
	{
		if (RoundManager.Instance.currentMaxInsidePower > RoundManager.Instance.currentEnemyPower && RoundManagerPatch.failedSpawnedCount > 0)
		{
			RoundManagerPatch.AddVentEnemy(RoundManager.Instance.enemySpawnTimes.Count + 1);
		}
	}

	[HarmonyPatch("KillEnemy")]
	[HarmonyPostfix]
	public static void KillEnemyPatch(EnemyAI __instance)
	{
		string enemyName = __instance.enemyType.enemyName;
		string text = enemyName;
		if (!(text == "Flowerman"))
		{
			if (text == "Maneater")
			{
				RoundManagerPatch.ManeaterMaxCount++;
			}
		}
		else
		{
			RoundManagerPatch.BlackenMaxCount++;
		}
	}

	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void StartPatch(ButlerBeesEnemyAI __instance)
	{
		if (NetworkManager.Singleton.IsHost && global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.entitiesRespawn.Value && !((EnemyAI)__instance).enemyType.isOutsideEnemy && !((EnemyAI)__instance).enemyType.isDaytimeEnemy)
		{
			float currentDayTime = RoundManager.Instance.timeScript.currentDayTime;
			if (despawnTimer.HasValue)
			{
				EnemyDespawnStatus value = new EnemyDespawnStatus(currentDayTime);
				timer.Add(((NetworkBehaviour)__instance).NetworkObjectId, value);
				((MonoBehaviour)__instance).StartCoroutine(VisionCheckCoroutine((EnemyAI)(object)__instance));
			}
		}
	}

	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	public static void UpdatePostfix(EnemyAI __instance)
	{
		if (!__instance.isEnemyDead && global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.entitiesRespawn.Value && !__instance.enemyType.isOutsideEnemy && !__instance.enemyType.isDaytimeEnemy && despawnTimer.HasValue)
		{
			float currentDayTime = RoundManager.Instance.timeScript.currentDayTime;
			if (timer.ContainsKey(((NetworkBehaviour)__instance).NetworkObjectId) && timer[((NetworkBehaviour)__instance).NetworkObjectId].time < RoundManager.Instance.timeScript.currentDayTime)
			{
				timer.Remove(((NetworkBehaviour)__instance).NetworkObjectId);
				((MonoBehaviour)__instance).StartCoroutine(DespawnCoroutine(__instance));
			}
		}
	}

	[IteratorStateMachine(typeof(<VisionCheckCoroutine>d__6))]
	public static IEnumerator VisionCheckCoroutine(EnemyAI __instance)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <VisionCheckCoroutine>d__6(0)
		{
			__instance = __instance
		};
	}

	private static bool IsBeingWatchedByPlayer(EnemyAI __instance)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		bool result = false;
		for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
		{
			if (__instance.PlayerIsTargetable(StartOfRound.Instance.allPlayerScripts[i], false, false, true) && (StartOfRound.Instance.allPlayerScripts[i].HasLineOfSightToPosition(((Component)__instance).transform.position + Vector3.up * 0.6f, 68f, 60, -1f, -1) || StartOfRound.Instance.allPlayerScripts[i].HasLineOfSightToPosition(((Component)__instance).transform.position + Vector3.up * 3f, 68f, 60, -1f, -1)) && PlayerHasHorizontalLOS(__instance, StartOfRound.Instance.allPlayerScripts[i]) && Vector3.Distance(((Component)StartOfRound.Instance.allPlayerScripts[i].gameplayCamera).transform.position, __instance.eye.position) > 0.3f)
			{
				result = true;
				break;
			}
		}
		return result;
	}

	private static bool PlayerHasHorizontalLOS(EnemyAI enemy, PlayerControllerB player)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = ((Component)enemy).transform.position - ((Component)player).transform.position;
		val.y = 0f;
		return Vector3.Angle(((Component)player).transform.forward, val) < 68f;
	}

	[IteratorStateMachine(typeof(<DespawnCoroutine>d__9))]
	private static IEnumerator DespawnCoroutine(EnemyAI __instance)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <DespawnCoroutine>d__9(0)
		{
			__instance = __instance
		};
	}
}
[HarmonyPatch(typeof(MaskedPlayerEnemy))]
public class MaskedPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void StartPatch(MaskedPlayerEnemy __instance)
	{
		if (NetworkManager.Singleton.IsHost && global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.entitiesRespawn.Value && !((EnemyAI)__instance).enemyType.isOutsideEnemy && !((EnemyAI)__instance).enemyType.isDaytimeEnemy)
		{
			float currentDayTime = RoundManager.Instance.timeScript.currentDayTime;
			if (EnemyAIPatch.despawnTimer.HasValue)
			{
				EnemyDespawnStatus value = new EnemyDespawnStatus(currentDayTime);
				EnemyAIPatch.timer.Add(((NetworkBehaviour)__instance).NetworkObjectId, value);
				((MonoBehaviour)__instance).StartCoroutine(EnemyAIPatch.VisionCheckCoroutine((EnemyAI)(object)__instance));
			}
		}
	}
}
[HarmonyPatch(typeof(ButlerBeesEnemyAI))]
public class ButlerBeeEnemyAIPatch
{
	public static Dictionary<ulong, float> timer = new Dictionary<ulong, float>();

	public static int? despawnTimer;

	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void StartPatch(ButlerBeesEnemyAI __instance)
	{
		if (NetworkManager.Singleton.IsHost)
		{
			float currentDayTime = RoundManager.Instance.timeScript.currentDayTime;
			if (despawnTimer.HasValue)
			{
				timer.Add(((NetworkBehaviour)__instance).NetworkObjectId, currentDayTime + (float)despawnTimer.Value);
			}
		}
	}

	[HarmonyPatch("DoAIInterval")]
	[HarmonyPostfix]
	public static void UpdatePatch(ButlerBeesEnemyAI __instance)
	{
		if (NetworkManager.Singleton.IsHost && global::MoreEntitiesSpawn.MoreEntitiesSpawn.ConfigUtil.butlerBeesDespawn.Value && timer.ContainsKey(((NetworkBehaviour)__instance).NetworkObjectId) && timer[((NetworkBehaviour)__instance).NetworkObjectId] < RoundManager.Instance.timeScript.currentDayTime)
		{
			((EnemyAI)__instance).thisNetworkObject.Despawn(true);
		}
	}
}
public class EnemyDespawnStatus
{
	public float time;

	public float updatedTime;

	public EnemyDespawnStatus(float time)
	{
		updatedTime = time;
		if (EnemyAIPatch.despawnTimer.HasValue)
		{
			this.time = time + (float)EnemyAIPatch.despawnTimer.Value;
		}
		else
		{
			this.time = time;
		}
	}
}
namespace MoreEntitiesSpawn
{
	[BepInPlugin("HitsujiSauce.MoreEntitiesSpawn", "MoreEntitiesSpawn", "1.0.0")]
	public class MoreEntitiesSpawn : BaseUnityPlugin
	{
		public class ConfigUtil
		{
			public static ConfigEntry<bool> useCustomMultiplier;

			public static ConfigEntry<float> customMultiplier;

			public static ConfigEntry<float> maxPower;

			public static ConfigEntry<float> cannotDieMultiplier;

			public static ConfigEntry<bool> butlerBeesDespawn;

			public static ConfigEntry<int> butlerBeesDespawnTimer;

			public static ConfigEntry<bool> entitiesRespawn;

			public static ConfigEntry<int> entitiesRespawnTimer;

			private static ConfigFile cfg;

			public static void Init(ConfigFile config)
			{
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Expected O, but got Unknown
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Expected O, but got Unknown
				useCustomMultiplier = config.Bind<bool>("General", "UseCustomMultiplier", false, "Use custom multiplier");
				customMultiplier = config.Bind<float>("General", "CustomMultiplier", 2f, new ConfigDescription("Set custom multiplier", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
				maxPower = config.Bind<float>("General", "MaxPower", 30f, "The MaxInsidePower of entities that can spawn at the same time. If your PC's frame rate drops due to too many entities, adjust this setting.");
				cannotDieMultiplier = config.Bind<float>("General", "Cannot be killed multiplier", 1f, new ConfigDescription("Adjusts the spawn rate of enemies that cannot be killed.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
				entitiesRespawn = config.Bind<bool>("General", "EntitiesRespawn", false, "If an entity remains unseen for an extended period, it despawns and a new entity spawns.");
				entitiesRespawnTimer = config.Bind<int>("General", "Entities resporn Timer", 120, "");
				butlerBeesDespawn = config.Bind<bool>("Butler", "ButlerBeesDespawn", false, "After a certain amount of time has passed, despawn the ButlerBees.");
				butlerBeesDespawnTimer = config.Bind<int>("Butler", "ButlerBeesDespawn Timer", 60, "The timer until ButlerBees despawn.\n60 = 1 hour(in game).");
				cfg = config;
			}

			public static void Reload()
			{
				Init(cfg);
			}
		}

		public static MoreEntitiesSpawn Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			ConfigUtil.Init(((BaseUnityPlugin)this).Config);
			Patch();
			Logger.LogInfo((object)"HitsujiSauce.MoreEntitiesSpawn v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("HitsujiSauce.MoreEntitiesSpawn");
			}
			Harmony.PatchAll();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "HitsujiSauce.MoreEntitiesSpawn";

		public const string PLUGIN_NAME = "MoreEntitiesSpawn";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}