Decompiled source of CadaverWilt v1.0.0

CadaverWilt.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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("CadaverWilt")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CadaverWilt")]
[assembly: AssemblyTitle("CadaverWilt")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
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;
		}
	}
	[CompilerGenerated]
	[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 CadaverWilt
{
	[HarmonyPatch(typeof(SprayPaintItem), "KillCadaverPlantRpc")]
	internal static class KillPlantPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			CadaverWipe.TryKillBlooms();
		}
	}
	[HarmonyPatch(typeof(CadaverGrowthAI), "DestroyPlantAtPosition")]
	internal static class DestroyPlantPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			CadaverWipe.TryKillBlooms();
		}
	}
	internal static class CadaverWipe
	{
		internal static void TryKillBlooms()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton != (Object)null && !singleton.IsServer)
			{
				return;
			}
			CadaverGrowthAI[] array = Object.FindObjectsOfType<CadaverGrowthAI>();
			if (array == null || array.Length == 0)
			{
				return;
			}
			bool flag = false;
			bool flag2 = false;
			CadaverGrowthAI[] array2 = array;
			foreach (CadaverGrowthAI val in array2)
			{
				if ((Object)(object)val == (Object)null || val.GrowthTiles == null)
				{
					continue;
				}
				foreach (TileWithGrowth growthTile in val.GrowthTiles)
				{
					if (growthTile != null)
					{
						flag2 = true;
						if (growthTile.plantsInTile > 0)
						{
							flag = true;
						}
						if (growthTile.plantPositions != null && growthTile.plantPositions.Count > 0)
						{
							flag = true;
						}
					}
				}
				if (val.growingRecentPlant)
				{
					flag = true;
				}
			}
			if (!flag2 || flag)
			{
				return;
			}
			int num = 0;
			CadaverBloomAI[] array3 = Object.FindObjectsOfType<CadaverBloomAI>();
			if (array3 == null)
			{
				return;
			}
			CadaverBloomAI[] array4 = array3;
			foreach (CadaverBloomAI val2 in array4)
			{
				if (!((Object)(object)val2 == (Object)null) && !((EnemyAI)val2).isEnemyDead)
				{
					try
					{
						((EnemyAI)val2).KillEnemy(true);
						num++;
					}
					catch
					{
					}
				}
			}
			if (num > 0)
			{
				Plugin.Log.LogInfo((object)$"All cadaver plants gone. Killed {num} cadaver(s).");
			}
		}
	}
	[BepInPlugin("com.benhough.lethal.CadaverWilt", "CadaverWilt", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "com.benhough.lethal.CadaverWilt";

		public const string ModName = "CadaverWilt";

		public const string ModVersion = "1.0.0";

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("com.benhough.lethal.CadaverWilt").PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"CadaverWilt v1.0.0 loaded.");
		}
	}
	internal static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.benhough.lethal.CadaverWilt";

		public const string PLUGIN_NAME = "CadaverWilt";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}