Decompiled source of InfestationOnly v1.0.6

OreoM.InfestOnly.dll

Decompiled 3 weeks ago
using System;
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 HarmonyLib;
using InfestOnly;
using Microsoft.CodeAnalysis;
using OreoM.InfestOnly.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("OreoM.InfestOnly")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6")]
[assembly: AssemblyProduct("InfestOnly")]
[assembly: AssemblyTitle("OreoM.InfestOnly")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<InfestConfig.infestModeConfig>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedValueEquals<InfestConfig.infestModeConfig>();
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<InfestConfig.fogConfig>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedValueEquals<InfestConfig.fogConfig>();
	}
}
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 InfestOnly
{
	internal class InfestConfig
	{
		public enum fogConfig
		{
			None,
			Vanilla,
			Infestation,
			Always
		}

		public enum infestModeConfig
		{
			Vanilla,
			All,
			Chaotic
		}

		public readonly ConfigEntry<fogConfig> fog;

		public readonly ConfigEntry<infestModeConfig> infestMode;

		public readonly ConfigEntry<int> chaoticSpawnCap;

		public InfestConfig(ConfigFile cfg)
		{
			cfg.SaveOnConfigSet = false;
			fog = cfg.Bind<fogConfig>("General", "Fog rarity", fogConfig.Infestation, "None: disables indoor fog.\nVanilla: vanilla behavior (2% chance with a ~2.5% chance of 20% chance).\nInfestation: 20% as if infestation has been triggered every day\nAlways: 100%");
			infestMode = cfg.Bind<infestModeConfig>("General.Mode", "Infestation mode", infestModeConfig.Vanilla, "Vanilla: vanilla behavior *25/75 split for Nutcracker/Hoarding Bug).\nAll: all enemies can be choosen for infestation except ones with a max count of 1\nChaotic: all enemies can be choosen including those with a max count of 1 (also changes their max spawn)");
			chaoticSpawnCap = cfg.Bind<int>("General.Mode", "Chaotic mode spawn cap", 3, "What spawn cap will be choosen for enemies with max count of 1 if chaotic mode is enabled");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
			dictionary.Clear();
		}
	}
	internal class InfestNetworkHandler : NetworkBehaviour
	{
		private static GameObject prefab;

		internal static InfestNetworkHandler Instance { get; private set; }

		internal NetworkVariable<InfestConfig.infestModeConfig> netInfestModeConfig { get; private set; } = new NetworkVariable<InfestConfig.infestModeConfig>(InfestConfig.infestModeConfig.Vanilla, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);


		internal NetworkVariable<InfestConfig.fogConfig> netFogConfig { get; private set; } = new NetworkVariable<InfestConfig.fogConfig>(InfestConfig.fogConfig.None, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);


		internal NetworkVariable<int> netChaoticSpawnCap { get; private set; } = new NetworkVariable<int>(0, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);


		internal static void Init()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			if ((Object)(object)prefab != (Object)null)
			{
				return;
			}
			try
			{
				prefab = new GameObject("InfestNetworkHandler")
				{
					hideFlags = (HideFlags)61
				};
				NetworkObject val = prefab.AddComponent<NetworkObject>();
				val.GlobalObjectIdHash = XXHash.Hash32("OreoM.InfestOnly" + ((Object)prefab).name);
				prefab.AddComponent<InfestNetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(prefab);
				InfestOnly.Logger.LogInfo((object)"Network handler initilized");
			}
			catch (Exception ex)
			{
				InfestOnly.Logger.LogError((object)("Network handler init handler error\n" + ex));
			}
		}

		internal static void Create()
		{
			try
			{
				if (NetworkManager.Singleton.IsServer && (Object)(object)prefab != (Object)null)
				{
					Object.Instantiate<GameObject>(prefab).GetComponent<NetworkObject>().Spawn(false);
				}
			}
			catch
			{
				InfestOnly.Logger.LogError((object)"Encountered some fatal error while spawning network handler. It is likely that registration failed earlier on start-up, please consult your logs.");
			}
		}

		private void Awake()
		{
			Instance = this;
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			if ((Object)(object)Instance != (Object)(object)this)
			{
				NetworkObject val = default(NetworkObject);
				if (((Component)Instance).TryGetComponent<NetworkObject>(ref val) && !val.IsSpawned && (Object)(object)Instance != (Object)(object)prefab)
				{
					Object.Destroy((Object)(object)Instance);
				}
				InfestOnly.Logger.LogWarning((object)"There are 2 InfestOnlys instantiated, and the wrong one was assigned as Instance. This shouldn't happen, but is recoverable");
				Instance = this;
			}
			InfestOnly.Logger.LogDebug((object)"Successfully spawned network handler.");
		}

		private void Start()
		{
			//IL_0030: 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)
			if (!((Object)(object)this != (Object)(object)Instance) && ((NetworkBehaviour)this).IsSpawned)
			{
				if (((NetworkBehaviour)this).IsServer || ((NetworkBehaviour)this).IsHost)
				{
					SetServerValues();
				}
				else
				{
					RetrieveConfigServerRpc();
				}
			}
		}

		private void SetServerValues()
		{
			netInfestModeConfig.Set(InfestOnly.config.infestMode.Value);
			netFogConfig.Set(InfestOnly.config.fog.Value);
			netChaoticSpawnCap.Set(InfestOnly.config.chaoticSpawnCap.Value);
		}

		[ServerRpc(RequireOwnership = false)]
		private void RetrieveConfigServerRpc(ServerRpcParams serverRpcParams = default(ServerRpcParams))
		{
			//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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(2969615009u, serverRpcParams, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val, 2969615009u, serverRpcParams, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ulong senderClientId = serverRpcParams.Receive.SenderClientId;
					ClientRpcParams val2 = default(ClientRpcParams);
					val2.Send = new ClientRpcSendParams
					{
						TargetClientIds = new ulong[1] { senderClientId }
					};
					ClientRpcParams clientRpcParams = val2;
					RecieveConfigClientRpc(netFogConfig.Value, netInfestModeConfig.Value, netChaoticSpawnCap.Value, clientRpcParams);
				}
			}
		}

		[ClientRpc]
		private void RecieveConfigClientRpc(InfestConfig.fogConfig fogConfig, InfestConfig.infestModeConfig infestMode, int chaoticSpawnCap, ClientRpcParams clientRpcParams = default(ClientRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3450000209u, clientRpcParams, (RpcDelivery)0);
					((FastBufferWriter)(ref val)).WriteValueSafe<InfestConfig.fogConfig>(ref fogConfig, default(ForEnums));
					((FastBufferWriter)(ref val)).WriteValueSafe<InfestConfig.infestModeConfig>(ref infestMode, default(ForEnums));
					BytePacker.WriteValueBitPacked(val, chaoticSpawnCap);
					((NetworkBehaviour)this).__endSendClientRpc(ref val, 3450000209u, clientRpcParams, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					netInfestModeConfig.Set(infestMode);
					netFogConfig.Set(fogConfig);
					netChaoticSpawnCap.Set(chaoticSpawnCap);
				}
			}
		}

		protected override void __initializeVariables()
		{
			if (netInfestModeConfig == null)
			{
				throw new Exception("InfestNetworkHandler.<netInfestModeConfig>k__BackingField cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)netInfestModeConfig).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)netInfestModeConfig, "netInfestModeConfig");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)netInfestModeConfig);
			if (netFogConfig == null)
			{
				throw new Exception("InfestNetworkHandler.<netFogConfig>k__BackingField cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)netFogConfig).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)netFogConfig, "netFogConfig");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)netFogConfig);
			if (netChaoticSpawnCap == null)
			{
				throw new Exception("InfestNetworkHandler.<netChaoticSpawnCap>k__BackingField cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)netChaoticSpawnCap).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)netChaoticSpawnCap, "netChaoticSpawnCap");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)netChaoticSpawnCap);
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_InfestNetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2969615009u, new RpcReceiveHandler(__rpc_handler_2969615009));
			NetworkManager.__rpc_func_table.Add(3450000209u, new RpcReceiveHandler(__rpc_handler_3450000209));
		}

		private static void __rpc_handler_2969615009(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ServerRpcParams server = rpcParams.Server;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((InfestNetworkHandler)(object)target).RetrieveConfigServerRpc(server);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3450000209(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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_0076: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				InfestConfig.fogConfig fogConfig = default(InfestConfig.fogConfig);
				((FastBufferReader)(ref reader)).ReadValueSafe<InfestConfig.fogConfig>(ref fogConfig, default(ForEnums));
				InfestConfig.infestModeConfig infestMode = default(InfestConfig.infestModeConfig);
				((FastBufferReader)(ref reader)).ReadValueSafe<InfestConfig.infestModeConfig>(ref infestMode, default(ForEnums));
				int chaoticSpawnCap = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref chaoticSpawnCap);
				ClientRpcParams client = rpcParams.Client;
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((InfestNetworkHandler)(object)target).RecieveConfigClientRpc(fogConfig, infestMode, chaoticSpawnCap, client);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "InfestNetworkHandler";
		}
	}
	[BepInPlugin("OreoM.InfestOnly", "InfestOnly", "1.0.6")]
	public class InfestOnly : BaseUnityPlugin
	{
		public static InfestOnly Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		internal static InfestConfig config { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			config = new InfestConfig(((BaseUnityPlugin)this).Config);
			Patch();
			NetcodePatch();
			Logger.LogInfo((object)"OreoM.InfestOnly v1.0.6 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("OreoM.InfestOnly");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}

		private static void NetcodePatch()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "OreoM.InfestOnly";

		public const string PLUGIN_NAME = "InfestOnly";

		public const string PLUGIN_VERSION = "1.0.6";
	}
}
namespace InfestOnly.Patches
{
	[HarmonyPatch(typeof(GameNetworkManager))]
	public class GameNetworkManagerPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostPatch()
		{
			InfestNetworkHandler.Init();
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	public class RoundManagerPatches
	{
		private static int enemyTypeCap = -1;

		private static int enemyIndex = -1;

		private static SelectableLevel currMoon = null;

		[HarmonyPatch("RefreshEnemiesList")]
		[HarmonyPostfix]
		private static void RefreshEnemiesListPrePatch(RoundManager __instance)
		{
			Random random = new Random(StartOfRound.Instance.randomMapSeed + 5781);
			enemyTypeCap = -1;
			enemyIndex = -1;
			currMoon = null;
			if (!__instance.currentLevel.spawnEnemiesAndScrap)
			{
				return;
			}
			switch (InfestNetworkHandler.Instance.netFogConfig.Value)
			{
			case InfestConfig.fogConfig.None:
				((Component)__instance.indoorFog).gameObject.SetActive(false);
				break;
			case InfestConfig.fogConfig.Vanilla:
				if (random.Next(0, 210) < 4 || random.Next(0, 1000) < 7)
				{
					((Component)__instance.indoorFog).gameObject.SetActive(random.Next(0, 100) < 20);
				}
				else
				{
					((Component)__instance.indoorFog).gameObject.SetActive(random.Next(0, 150) < 3);
				}
				break;
			case InfestConfig.fogConfig.Infestation:
				((Component)__instance.indoorFog).gameObject.SetActive(random.Next(0, 100) < 20);
				break;
			case InfestConfig.fogConfig.Always:
				((Component)__instance.indoorFog).gameObject.SetActive(true);
				break;
			}
			switch (InfestNetworkHandler.Instance.netInfestModeConfig.Value)
			{
			case InfestConfig.infestModeConfig.Vanilla:
			{
				if (random.Next(0, 100) < 25)
				{
					for (int i = 0; i < __instance.currentLevel.Enemies.Count; i++)
					{
						if (__instance.currentLevel.Enemies[i].enemyType.enemyName == "Nutcracker")
						{
							__instance.enemyRushIndex = i;
							break;
						}
					}
					if (__instance.enemyRushIndex != -1)
					{
						break;
					}
					for (int j = 0; j < __instance.currentLevel.Enemies.Count; j++)
					{
						if (__instance.currentLevel.Enemies[j].enemyType.enemyName == "Hoarding bug")
						{
							__instance.enemyRushIndex = j;
							break;
						}
					}
					break;
				}
				for (int k = 0; k < __instance.currentLevel.Enemies.Count; k++)
				{
					if (__instance.currentLevel.Enemies[k].enemyType.enemyName == "Hoarding bug")
					{
						__instance.enemyRushIndex = k;
						break;
					}
				}
				break;
			}
			case InfestConfig.infestModeConfig.All:
				do
				{
					__instance.enemyRushIndex = random.Next(0, __instance.currentLevel.Enemies.Count);
				}
				while (__instance.currentLevel.Enemies[__instance.enemyRushIndex].enemyType.MaxCount == 1 || __instance.currentLevel.Enemies[__instance.enemyRushIndex].enemyType.enemyName == "Lasso");
				if (__instance.currentLevel.Enemies[__instance.enemyRushIndex].enemyType.MaxCount < 8)
				{
					currMoon = __instance.currentLevel;
					enemyIndex = __instance.enemyRushIndex;
					enemyTypeCap = currMoon.Enemies[enemyIndex].enemyType.MaxCount;
					currMoon.Enemies[enemyIndex].enemyType.MaxCount = 8;
				}
				break;
			case InfestConfig.infestModeConfig.Chaotic:
				do
				{
					__instance.enemyRushIndex = random.Next(0, __instance.currentLevel.Enemies.Count);
				}
				while (__instance.currentLevel.Enemies[__instance.enemyRushIndex].enemyType.enemyName == "Lasso");
				if (__instance.currentLevel.Enemies[__instance.enemyRushIndex].enemyType.MaxCount == 1)
				{
					currMoon = __instance.currentLevel;
					enemyIndex = __instance.enemyRushIndex;
					enemyTypeCap = currMoon.Enemies[enemyIndex].enemyType.MaxCount;
					currMoon.Enemies[enemyIndex].enemyType.MaxCount = InfestNetworkHandler.Instance.netChaoticSpawnCap.Value;
				}
				else if (__instance.currentLevel.Enemies[__instance.enemyRushIndex].enemyType.MaxCount < 8)
				{
					currMoon = __instance.currentLevel;
					enemyIndex = __instance.enemyRushIndex;
					enemyTypeCap = currMoon.Enemies[enemyIndex].enemyType.MaxCount;
					currMoon.Enemies[enemyIndex].enemyType.MaxCount = 8;
				}
				break;
			}
			__instance.currentMaxOutsidePower = __instance.currentLevel.maxOutsideEnemyPowerCount;
			__instance.currentMaxInsidePower = 25f;
		}

		[HarmonyPatch("DespawnPropsAtEndOfRound")]
		[HarmonyPrefix]
		private static void DespawnPropsAtEndOfRoundPrePatch(RoundManager __instance)
		{
			if (enemyTypeCap != -1 && enemyIndex != -1 && (Object)(object)currMoon != (Object)null)
			{
				InfestOnly.Logger.LogInfo((object)("Reseting extra spawns for: " + currMoon.Enemies[enemyIndex].enemyType.enemyName));
				currMoon.Enemies[enemyIndex].enemyType.MaxCount = enemyTypeCap;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePostPatch()
		{
			InfestNetworkHandler.Create();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace OreoM.InfestOnly.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}