Decompiled source of Hoarder Bug Respawn Mod v1.1.0

LC_BugRespawnMod.dll

Decompiled 11 months 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 System.Threading.Tasks;
using BepInEx;
using GameNetcodeStuff;
using LC_API.GameInterfaceAPI;
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("LC_BugRespawnMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A mod for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LC_BugRespawnMod")]
[assembly: AssemblyTitle("LC_BugRespawnMod")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HoarderMod
{
	[BepInPlugin("LC_BugRespawnMod", "LC_BugRespawnMod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private List<int> hoardID = new List<int>();

		private HoarderBugAI[] bugs;

		private RoundManager curRound;

		private GameObject player;

		private SelectableLevel curLevel;

		private int hoardIndex = 2;

		private PlayerControllerB[] players;

		private bool roundActive;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LC_BugRespawnMod is loaded!");
			GameState.LandOnMoon += RoundStart;
			GameState.ShipStartedLeaving += RoundEnd;
		}

		private void RoundStart()
		{
			roundActive = true;
			curRound = Object.FindObjectOfType<RoundManager>();
			curLevel = curRound.currentLevel;
			player = GameObject.Find("Player");
			players = Object.FindObjectsOfType<PlayerControllerB>();
			hoardIndex = FindEnemyID("Hoarding bug");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Round has started, starting checks");
			try
			{
				BugCheck();
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
		}

		private void RoundEnd()
		{
			roundActive = false;
			hoardID.Clear();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Round has ended, stopping checks");
		}

		private async Task BugCheck()
		{
			while (roundActive)
			{
				bugs = Object.FindObjectsOfType<HoarderBugAI>();
				HoarderBugAI[] array = bugs;
				foreach (HoarderBugAI val in array)
				{
					if (((EnemyAI)val).isEnemyDead && !hoardID.Contains(((Object)val).GetInstanceID()))
					{
						for (int j = 0; j < 5; j++)
						{
							curRound.SpawnEnemyOnServer(((Component)val).transform.position, 0f, hoardIndex);
						}
						hoardID.Add(((Object)val).GetInstanceID());
						try
						{
							AngerBugs(val);
						}
						catch (Exception ex)
						{
							((BaseUnityPlugin)this).Logger.LogError((object)ex);
						}
					}
				}
				await Task.Delay(10);
			}
		}

		public int FindEnemyID(string enemy)
		{
			for (int i = 0; i < curLevel.Enemies.Count; i++)
			{
				if (curLevel.Enemies[i].enemyType.enemyName == enemy)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Found {enemy} at {i}");
					return i;
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)(enemy + " index not found, probably doesn't spawn in that case but I'm defaulting to 2 (Hoarding Bug Index on most moons)"));
			return 2;
		}

		public void AngerBugs(HoarderBugAI b)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			bugs = Object.FindObjectsOfType<HoarderBugAI>();
			PlayerControllerB angryAtPlayer = null;
			float num = float.PositiveInfinity;
			Vector3 position = ((Component)b).transform.position;
			PlayerControllerB[] array = players;
			foreach (PlayerControllerB val in array)
			{
				float num2 = Vector3.Distance(((Component)val).transform.position, position);
				if (num2 < num)
				{
					angryAtPlayer = val;
					num = num2;
				}
			}
			HoarderBugAI[] array2 = bugs;
			foreach (HoarderBugAI obj in array2)
			{
				obj.angryAtPlayer = angryAtPlayer;
				obj.angryTimer += 200f;
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LC_BugRespawnMod";

		public const string PLUGIN_NAME = "LC_BugRespawnMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}