Decompiled source of MaskedWaves v1.0.2

MaskedWaves.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MaskedWaves.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MaskedWaves")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MaskedWaves")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b389bbc3-d703-4ed3-a069-7d59b5b3572d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MaskedWaves
{
	[BepInPlugin("Waffle.MaskedWaves", "Masked Waves", "1.0.1")]
	public class MaskedSpawn : BaseUnityPlugin
	{
		private const string modGUID = "Waffle.MaskedWaves";

		private const string modName = "Masked Waves";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("Waffle.MaskedWaves");

		internal static bool isHost;

		public static MaskedSpawn Instance;

		public static ManualLogSource mls;

		internal ConfigEntry<int> MaskedBase;

		internal ConfigEntry<float> MaskedMult;

		internal ConfigEntry<float> MaskedMultMult;

		internal ConfigEntry<int> WaveInterval;

		internal ConfigEntry<int> StartDelay;

		internal ConfigEntry<int> IntervalMod;

		public static GameObject maskedPrefab;

		public bool started;

		private int lastSpawned;

		private float combinedMult;

		public int waveCount;

		public float timeToNextWave;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Waffle.MaskedWaves");
			mls.LogInfo((object)"Masked Waves has loaded");
			MaskedBase = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaskedBase", 2, "This value controls how many masked will spawn on the first wave");
			MaskedMult = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaskedMultiplier", 2f, "This value controls the multiplier of each wave (EX: if MaskedBase is 2 and MaskedMultiplier is 2 on wave 2 it will be 4 and so on) rounds so if its too low with too low MaskedBase will stay constant");
			MaskedMultMult = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaskedMultiplierMultiplier", 1f, "This value controls how much the multiplier of each wave changes each wave. Used to make it get less out of hand, but you can make it more than 1 to make it insane or delay when it first multiplies (MaskedMult = 1, MaskedMultMult = 1.1 etc). Set to 1 to disable");
			WaveInterval = ((BaseUnityPlugin)this).Config.Bind<int>("General", "WaveInterval", 60, "This value controls how many seconds are in between each wave");
			StartDelay = ((BaseUnityPlugin)this).Config.Bind<int>("General", "StartDelay", 70, "This value controls how many seconds it will take to spawn the first wave");
			IntervalMod = ((BaseUnityPlugin)this).Config.Bind<int>("General", "IntervalMod", 1, "This value controls how much the wave interval changes each time. Greater than 1 makes it longer, 1 makes it constant (disables), less than 1 makes it less, 0 or less makes it always instant so probably dont do that");
			harmony.PatchAll(typeof(MaskedSpawn));
			harmony.PatchAll(typeof(GetMaskedPrefab));
			harmony.PatchAll(typeof(RoundStartAndEnd));
		}

		private void Update()
		{
			if (!started)
			{
				return;
			}
			timeToNextWave -= Time.deltaTime;
			if (timeToNextWave <= 0f)
			{
				if (waveCount == 0)
				{
					lastSpawned = MaskedBase.Value;
					combinedMult = MaskedMult.Value / MaskedMultMult.Value;
				}
				else
				{
					combinedMult *= MaskedMultMult.Value;
					lastSpawned = (int)Math.Round((float)lastSpawned * combinedMult);
				}
				mls.LogInfo((object)waveCount);
				timeToNextWave = (int)((double)WaveInterval.Value * Math.Pow(IntervalMod.Value, waveCount));
				SpawnEnemies(lastSpawned);
				waveCount++;
			}
		}

		[HarmonyPatch(typeof(RoundManager), "Start")]
		[HarmonyPrefix]
		private static void setIsHost()
		{
			mls.LogInfo((object)("Host Status: " + ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost));
			isHost = ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost;
		}

		private static void SpawnEnemies(int amount)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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)
			if (!isHost)
			{
				mls.LogInfo((object)"not host");
				return;
			}
			mls.LogInfo((object)"Spawning");
			for (int i = 0; i < amount; i++)
			{
				mls.LogInfo((object)("Spawned masked #" + i + "."));
				Object.Instantiate<GameObject>(maskedPrefab, GameObject.FindGameObjectsWithTag("OutsideAINode")[Random.Range(0, GameObject.FindGameObjectsWithTag("OutsideAINode").Length - 1)].transform.position, Quaternion.Euler(Vector3.zero)).gameObject.GetComponentInChildren<NetworkObject>().Spawn(true);
			}
		}
	}
}
namespace MaskedWaves.Patches
{
	[HarmonyPatch]
	internal class GetMaskedPrefab
	{
		[HarmonyPatch(typeof(Terminal), "Start")]
		[HarmonyPostfix]
		private static void SavesPrefab(ref SelectableLevel[] ___moonsCatalogueList)
		{
			SelectableLevel[] array = ___moonsCatalogueList;
			for (int i = 0; i < array.Length; i++)
			{
				foreach (SpawnableEnemyWithRarity enemy in array[i].Enemies)
				{
					if (enemy.enemyType.enemyName == "Masked")
					{
						MaskedSpawn.maskedPrefab = enemy.enemyType.enemyPrefab;
						MaskedSpawn.mls.LogInfo((object)"Masked prefab found");
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class RoundStartAndEnd
	{
		[HarmonyPatch("SetPlayerObjectExtrapolate")]
		[HarmonyPostfix]
		private static void StartSpawning()
		{
			MaskedSpawn.mls.LogInfo((object)"SetPlayerObjectExtrapolate was called");
			MaskedSpawn.Instance.waveCount = 0;
			MaskedSpawn.Instance.timeToNextWave = MaskedSpawn.Instance.StartDelay.Value;
			MaskedSpawn.Instance.started = true;
		}

		[HarmonyPatch("ShipHasLeft")]
		[HarmonyPostfix]
		private static void PauseSpawning()
		{
			MaskedSpawn.mls.LogInfo((object)"ShipHasLeft was called");
			MaskedSpawn.Instance.started = false;
		}
	}
}