Decompiled source of TickingHoardingBugs v1.1.0

BepInEx/plugins/CarksMod.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("CarksMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CarksMod")]
[assembly: AssemblyTitle("CarksMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
namespace CarksMod
{
	[BepInPlugin("carks.firstmod", "Ticking Hoarding Bugs", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("carks.tickingbugs").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"TICKING HOARDING BUGS LOADED!");
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI), "Update")]
	public static class BugUpdatePatch
	{
		[HarmonyPostfix]
		private static void Postfix(HoarderBugAI __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer || ((EnemyAI)__instance).isEnemyDead)
			{
				return;
			}
			BugFuse bugFuse = ((Component)__instance).GetComponent<BugFuse>();
			if ((Object)(object)bugFuse == (Object)null)
			{
				bugFuse = ((Component)__instance).gameObject.AddComponent<BugFuse>();
				bugFuse.Bug = __instance;
			}
			((EnemyAI)__instance).enemyHP = 10000;
			if (((EnemyAI)__instance).currentBehaviourStateIndex == 2)
			{
				bugFuse.Arm();
			}
			if (bugFuse.Armed)
			{
				__instance.angryTimer = 30f;
				if (((EnemyAI)__instance).currentBehaviourStateIndex != 2)
				{
					((EnemyAI)__instance).SwitchToBehaviourClientRpc(2);
				}
			}
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI), "HitEnemy")]
	public static class BugDamagePatch
	{
		[HarmonyPrefix]
		private static void Prefix(HoarderBugAI __instance)
		{
			if (((NetworkBehaviour)__instance).IsServer && !((EnemyAI)__instance).isEnemyDead)
			{
				((EnemyAI)__instance).enemyHP = 10000;
			}
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI), "OnCollideWithPlayer")]
	public static class BugBitePatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI), "HitPlayerServerRpc")]
	public static class BugAttackRpcPatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI), "KillEnemy")]
	public static class BugDeathPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(HoarderBugAI __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return true;
			}
			BugFuse component = ((Component)__instance).GetComponent<BugFuse>();
			return (Object)(object)component != (Object)null && component.Exploded;
		}
	}
	public class BugFuse : MonoBehaviour
	{
		public HoarderBugAI Bug;

		public bool Exploded;

		private bool armed;

		private float elapsed;

		private float nextBeep;

		private AudioClip beepClip;

		private const float FuseTime = 7f;

		public bool Armed => armed && !Exploded;

		public void Arm()
		{
			if (!armed && !Exploded)
			{
				armed = true;
				elapsed = 0f;
				nextBeep = 0f;
				beepClip = FindBeep();
				Debug.Log((object)"[TickingBugs] Hoarding Bug armed!");
			}
		}

		private void Update()
		{
			if (armed && !Exploded && !((Object)(object)Bug == (Object)null) && ((NetworkBehaviour)Bug).IsServer && !((EnemyAI)Bug).isEnemyDead)
			{
				elapsed += Time.deltaTime;
				Bug.angryTimer = 30f;
				float num = Mathf.Clamp01(elapsed / 7f);
				if (elapsed >= nextBeep)
				{
					PlayBeep();
					float num2 = Mathf.Lerp(1.1f, 0.09f, num * num);
					nextBeep = elapsed + num2;
				}
				if (elapsed >= 7f)
				{
					Explode();
				}
			}
		}

		private void PlayBeep()
		{
			if (!((Object)(object)beepClip == (Object)null))
			{
				AudioSource val = ((EnemyAI)Bug).creatureSFX;
				if ((Object)(object)val == (Object)null)
				{
					val = ((EnemyAI)Bug).creatureVoice;
				}
				if ((Object)(object)val != (Object)null)
				{
					val.PlayOneShot(beepClip, 1f);
				}
			}
		}

		private static AudioClip FindBeep()
		{
			AudioClip[] array = Resources.FindObjectsOfTypeAll<AudioClip>();
			AudioClip[] array2 = array;
			foreach (AudioClip val in array2)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name.IndexOf("MineBeep", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return val;
				}
			}
			int num = 24000;
			int num2 = 3600;
			AudioClip val2 = AudioClip.Create("TickingBugFallbackBeep", num2, 1, num, false);
			float[] array3 = new float[num2];
			for (int j = 0; j < num2; j++)
			{
				float num3 = (float)j / (float)num;
				float num4 = Mathf.Min(1f, (float)(num2 - j) / 500f);
				array3[j] = (float)Math.Sin(Math.PI * 1760.0 * (double)num3) * 0.25f * num4;
			}
			val2.SetData(array3, 0);
			return val2;
		}

		private void Explode()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if (!Exploded && !((Object)(object)Bug == (Object)null))
			{
				Exploded = true;
				Vector3 val = ((Component)Bug).transform.position + Vector3.up * 0.5f;
				Debug.Log((object)"[TickingBugs] BOOM!");
				Landmine.SpawnExplosion(val, true, 5.7f, 6f, 50, 0f, (GameObject)null, false);
				((EnemyAI)Bug).KillEnemyClientRpc(false);
				armed = false;
			}
		}
	}
}