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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: AssemblyCompany("VentSpawnFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allows indoor enemies to spawn in groups larger than 1, like outdoor and daytime enemies.")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyInformationalVersion("1.2.2+57ce6790232ca89dd3b454b2b9aa0d7bdd384280")]
[assembly: AssemblyProduct("VentSpawnFix")]
[assembly: AssemblyTitle("VentSpawnFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.2.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.2.2")]
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.2.2";
internal static ManualLogSource Logger;
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
new Harmony("butterystancakes.lethalcompany.ventspawnfix").PatchAll();
Logger.LogInfo((object)"Vent Spawn Fix v1.2.2 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.LogDebug((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.LogDebug((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.LogDebug((object)"Enemy successfully reassigned to another empty vent");
}
return true;
}
[HarmonyPatch(typeof(RoundManager), "AssignRandomEnemyToVent")]
[HarmonyPostfix]
private static void RoundManagerPostAssignRandomEnemyToVent(RoundManager __instance, EnemyVent vent, bool __result, int ___currentHour)
{
if (!__result)
{
return;
}
EnemyType enemy = vent?.enemyType;
if ((Object)(object)enemy == (Object)null)
{
Plugin.Logger.LogWarning((object)"AssignRandomEnemyToVent completed without assigning an enemy to the vent. This shouldn't happen");
}
else if (vent.enemyTypeIndex < 0 || vent.enemyTypeIndex > __instance.currentLevel.Enemies.Count || !__instance.currentLevel.Enemies.Any((SpawnableEnemyWithRarity spawnableEnemyWithRarity) => (Object)(object)spawnableEnemyWithRarity.enemyType == (Object)(object)enemy))
{
Plugin.Logger.LogWarning((object)"AssignRandomEnemyToVent assigned an enemy with an invalid index. This shouldn't happen");
}
else
{
if (enemy.spawnInGroupsOf <= 1)
{
return;
}
Plugin.Logger.LogDebug((object)$"Enemy \"{enemy.enemyName}\" spawned in vent, requesting group of {enemy.spawnInGroupsOf}");
int num = enemy.spawnInGroupsOf - 1;
List<EnemyVent> list = __instance.allEnemyVents.Where((EnemyVent enemyVent) => !enemyVent.occupied).ToList();
while (num > 0)
{
if (list.Count <= 0)
{
Plugin.Logger.LogDebug((object)("Can't spawn additional \"" + enemy.enemyName + "\" (all vents are occupied)"));
return;
}
if (enemy.numberSpawned >= enemy.MaxCount)
{
Plugin.Logger.LogDebug((object)$"Can't spawn additional \"{enemy.enemyName}\" ({enemy.MaxCount} have already spawned)");
return;
}
if (enemy.PowerLevel > __instance.currentMaxInsidePower - __instance.currentEnemyPower)
{
Plugin.Logger.LogDebug((object)$"Can't spawn additional \"{enemy.enemyName}\" ({__instance.currentEnemyPower} + {enemy.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 += enemy.PowerLevel;
val.enemyType = enemy;
val.enemyTypeIndex = vent.enemyTypeIndex;
val.occupied = true;
val.spawnTime = num2;
if (__instance.timeScript.hour - ___currentHour <= 0)
{
val.SyncVentSpawnTimeClientRpc(num2, vent.enemyTypeIndex);
}
EnemyType obj = enemy;
obj.numberSpawned++;
__instance.enemySpawnTimes.Add(num2);
list.Remove(val);
Plugin.Logger.LogDebug((object)("Spawning additional \"" + enemy.enemyName + "\" in vent"));
num--;
}
if (num < enemy.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.2.2";
}
}