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 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 bool useCustomMultiplier = false;
private static float nextSpawnTime = 0f;
public static int failedSpawnedCount = 0;
public static List<int> prevEnemies = new List<int>();
[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;
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 = 1f;
}
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);
}
}
failedSpawnedCount = 0;
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("EnemyCannotBeSpawned")]
[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" || enemyType.enemyName == "Maneater") ? Mathf.Min(Mathf.FloorToInt((float)enemyType.MaxCount * multiplier), 3) : ((!(enemyType.enemyName == "Butler")) ? Mathf.RoundToInt((float)enemyType.MaxCount * multiplier) : (num + (enemyType.MaxCount + Mathf.FloorToInt((float)enemyType.MaxCount * (1f - multiplier) * 0.5f)))));
}
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];
}
}
}
}
[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];
}
}
}
}
[HarmonyPatch(typeof(EnemyAI))]
public class EnemyAIPatch
{
[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);
}
}
}
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;
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
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.");
cfg = config;
}
public static void Reload()
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
useCustomMultiplier = cfg.Bind<bool>("General", "UseCustomMultiplier", false, "Use custom multiplier");
customMultiplier = cfg.Bind<float>("General", "CustomMultiplier", 2f, new ConfigDescription("Set custom multiplier", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
maxPower = cfg.Bind<float>("General", "MaxPower", 25f, "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.");
}
}
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";
}
}