Decompiled source of VentSpawnFix v1.1.1

VentSpawnFix.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("VentSpawnFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes a bug with the \"spawn wave\" logic for indoor enemies.")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+2b11dcc03a32dae7869cea2b33f4969b6e50de01")]
[assembly: AssemblyProduct("VentSpawnFix")]
[assembly: AssemblyTitle("VentSpawnFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VentSpawnFix
{
	[BepInPlugin("butterystancakes.lethalcompany.ventspawnfix", "Vent Spawn Fix", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "butterystancakes.lethalcompany.ventspawnfix";

		private const string PLUGIN_NAME = "Vent Spawn Fix";

		private const string PLUGIN_VERSION = "1.1.1";

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (Chainloader.PluginInfos.ContainsKey("Dev1A3.LethalFixes"))
			{
				Logger.LogWarning((object)"LethalFixes has been detected in your plugin list, which as of v1.1.5, already contains the same fixes for vent spawning.");
				Logger.LogWarning((object)"Loading has been cancelled to prevent conflicts. You can safely remove VentSpawnFix next time you exit the game, since you don't need it.");
			}
			else
			{
				Logger = ((BaseUnityPlugin)this).Logger;
				new Harmony("butterystancakes.lethalcompany.ventspawnfix").PatchAll();
				Logger.LogInfo((object)"Vent Spawn Fix v1.1.1 loaded");
			}
		}
	}
	[HarmonyPatch]
	internal class VentSpawnFixPatches
	{
		[HarmonyPatch(typeof(RoundManager), "AssignRandomEnemyToVent")]
		[HarmonyPrefix]
		private static bool RoundManagerPreAssignRandomEnemyToVent(RoundManager __instance, ref EnemyVent vent, ref bool __result)
		{
			if (vent.occupied)
			{
				Plugin.Logger.LogInfo((object)("A new enemy tried to occupy vent with \"" + vent.enemyType.enemyName + "\" already inside"));
				List<EnemyVent> list = __instance.allEnemyVents.Where((EnemyVent enemyVent) => !enemyVent.occupied).ToList();
				if (list.Count < 1)
				{
					Plugin.Logger.LogInfo((object)"Enemy spawn cancelled because all vents on the map are occupied");
					__result = false;
					return false;
				}
				vent = list[__instance.AnomalyRandom.Next(0, list.Count)];
				Plugin.Logger.LogInfo((object)"Enemy successfully reassigned to another empty vent");
			}
			return true;
		}

		[HarmonyPatch(typeof(RoundManager), "AssignRandomEnemyToVent")]
		[HarmonyPostfix]
		private static void RoundManagerPostAssignRandomEnemyToVent(RoundManager __instance, EnemyVent vent, int ___currentHour)
		{
			EnemyType enemyType = vent.enemyType;
			if (enemyType.spawnInGroupsOf <= 1)
			{
				return;
			}
			Plugin.Logger.LogInfo((object)$"Enemy \"{enemyType.enemyName}\" spawned in vent, requesting group of {enemyType.spawnInGroupsOf}");
			int num = enemyType.spawnInGroupsOf - 1;
			List<EnemyVent> list = __instance.allEnemyVents.Where((EnemyVent enemyVent) => !enemyVent.occupied).ToList();
			while (num > 0)
			{
				if (list.Count <= 0)
				{
					Plugin.Logger.LogInfo((object)("Can't spawn additional \"" + enemyType.enemyName + "\" (all vents are occupied)"));
					return;
				}
				if (enemyType.PowerLevel > __instance.currentMaxInsidePower - __instance.currentEnemyPower)
				{
					Plugin.Logger.LogInfo((object)$"Can't spawn additional \"{enemyType.enemyName}\" ({__instance.currentEnemyPower} + {enemyType.PowerLevel} would exceed max power level of {__instance.currentMaxInsidePower})");
					return;
				}
				int num2 = (int)vent.spawnTime;
				EnemyVent val = list[__instance.AnomalyRandom.Next(0, list.Count)];
				__instance.currentEnemyPower += enemyType.PowerLevel;
				val.enemyType = enemyType;
				val.enemyTypeIndex = vent.enemyTypeIndex;
				val.occupied = true;
				val.spawnTime = num2;
				if (__instance.timeScript.hour - ___currentHour <= 0)
				{
					val.SyncVentSpawnTimeClientRpc(num2, vent.enemyTypeIndex);
				}
				enemyType.numberSpawned++;
				__instance.enemySpawnTimes.Add(num2);
				list.Remove(val);
				Plugin.Logger.LogInfo((object)("Spawning additional \"" + enemyType.enemyName + "\" in vent"));
				num--;
			}
			if (num < enemyType.spawnInGroupsOf - 1)
			{
				__instance.enemySpawnTimes.Sort();
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "VentSpawnFix";

		public const string PLUGIN_NAME = "VentSpawnFix";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}