Decompiled source of LethalPlus v0.4.0

LethalPlus.dll

Decompiled a year ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalPlus.Patches;
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: AssemblyTitle("LethalPlus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalPlus")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5704a5bc-01bd-4370-b8e6-25943255fa5e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LethalPlus
{
	[BepInPlugin("OMEGA.LethalPlus", "LethalPlus", "0.4.1")]
	public class Main : BaseUnityPlugin
	{
		private const string modGUID = "OMEGA.LethalPlus";

		private const string modName = "LethalPlus";

		private const string modVersion = "0.4.1";

		private readonly Harmony harmony = new Harmony("OMEGA.LethalPlus");

		private static Main Instance;

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Log = Logger.CreateLogSource("OMEGA.LethalPlus");
			Log.LogInfo((object)"Mod Loaded");
			harmony.PatchAll(typeof(Main));
			harmony.PatchAll(typeof(SprayBeePatch));
			harmony.PatchAll(typeof(SprayPaintItemPatch));
			harmony.PatchAll(typeof(SprayEnemyPatch));
			harmony.PatchAll(typeof(BeeOuchPatch));
		}
	}
	internal class PitFiendAI : EnemyAI
	{
		public float detectionRadius = 12f;

		private Collider[] allPlayerColliders = (Collider[])(object)new Collider[4];

		private float closestPlayerDist;

		private Collider tempTargetCollider;

		public bool detectingPlayers;

		public override void Start()
		{
			((EnemyAI)this).Start();
			base.movingTowardsTargetPlayer = true;
			Main.Log.LogInfo((object)"PitFiend Loaded");
			Main.Log.LogInfo((object)"Mod Loaded");
		}

		public override void DoAIInterval()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			int num = Physics.OverlapSphereNonAlloc(((Component)this).transform.position, detectionRadius, allPlayerColliders, StartOfRound.Instance.playersMask);
			if (num > 0)
			{
				detectingPlayers = true;
				closestPlayerDist = 255555f;
				for (int i = 0; i < num; i++)
				{
					float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)allPlayerColliders[i]).transform.position);
					if (num2 < closestPlayerDist)
					{
						closestPlayerDist = num2;
						tempTargetCollider = allPlayerColliders[i];
					}
				}
				((EnemyAI)this).SetMovingTowardsTargetPlayer(((Component)tempTargetCollider).gameObject.GetComponent<PlayerControllerB>());
			}
			else
			{
				base.agent.speed = 5f;
				detectingPlayers = false;
			}
			((EnemyAI)this).DoAIInterval();
		}

		public override void Update()
		{
			if (((NetworkBehaviour)this).IsOwner && detectingPlayers)
			{
				base.agent.speed = Mathf.Clamp(base.agent.speed + Time.deltaTime / 3f, 0f, 12f);
			}
			((EnemyAI)this).Update();
		}

		protected override void __initializeVariables()
		{
			((EnemyAI)this).__initializeVariables();
		}

		protected override string __getTypeName()
		{
			return "PitFiendAI";
		}
	}
}
namespace LethalPlus.Patches
{
	[HarmonyPatch(typeof(CrawlerAI))]
	internal class CrawlerPatch
	{
		[HarmonyPatch("HitEnemy")]
		[HarmonyPrefix]
		private static void RailingDodgePatch()
		{
		}
	}
	[HarmonyPatch(typeof(SprayPaintItem))]
	internal class SprayPaintItemPatch
	{
		private static FieldInfo SprayHit = typeof(SprayPaintItem).GetField("sprayHit", BindingFlags.Instance | BindingFlags.NonPublic);

		public static RaycastHit ItemSprayed { get; private set; }

		public static PlayerControllerB PlayerSpraying { get; private set; }

		public static bool IsBeeHiveSprayed { get; set; }

		public static bool IsEnemySprayed { get; set; }

		public static RedLocustBees[] Bees { get; set; }

		public static EnemyAI[] Enemies { get; set; }

		public static EnemyAI Enem { get; set; }

		public static SandSpiderAI[] Spiders { get; set; }

		public static CrawlerAI[] Crawlers { get; set; }

		public static CentipedeAI[] Centipedes { get; set; }

		public static HoarderBugAI[] Bugs { get; set; }

		[HarmonyPatch("SprayPaintClientRpc")]
		[HarmonyPostfix]
		private static void SprayPatch(SprayPaintItem __instance, Vector3 sprayPos, Vector3 sprayRot)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)null))
			{
				return;
			}
			RaycastHit itemSprayed = (RaycastHit)SprayHit.GetValue(__instance);
			Main.Log.LogInfo((object)("Raycast: " + ((object)(RaycastHit)(ref itemSprayed)).ToString()));
			Main.Log.LogInfo((object)("Raycast collider: " + (object)((RaycastHit)(ref itemSprayed)).collider));
			ManualLogSource log = Main.Log;
			Collider collider = ((RaycastHit)(ref itemSprayed)).collider;
			log.LogInfo((object)("Raycast collider name: " + ((collider != null) ? ((Object)collider).name : null)));
			Collider collider2 = ((RaycastHit)(ref itemSprayed)).collider;
			if (((collider2 != null) ? ((Object)collider2).name : null) == "RedLocustHive(Clone)")
			{
				IsBeeHiveSprayed = true;
				ItemSprayed = itemSprayed;
				Main.Log.LogInfo((object)"Sprayed");
			}
			else
			{
				Collider collider3 = ((RaycastHit)(ref itemSprayed)).collider;
				if (!(((collider3 != null) ? ((Object)collider3).name : null) == "Mesh"))
				{
					Collider collider4 = ((RaycastHit)(ref itemSprayed)).collider;
					if (!(((collider4 != null) ? ((Object)collider4).name : null) == "Mesh (1)"))
					{
						Collider collider5 = ((RaycastHit)(ref itemSprayed)).collider;
						if (!(((collider5 != null) ? ((Object)collider5).name : null) == "CollisionMesh"))
						{
							Collider collider6 = ((RaycastHit)(ref itemSprayed)).collider;
							if (!(((collider6 != null) ? ((Object)collider6).name : null) == "AnomalySpawnBox (1)"))
							{
								Collider collider7 = ((RaycastHit)(ref itemSprayed)).collider;
								if (!(((collider7 != null) ? ((Object)collider7).name : null) == "AnomalySpawnBox"))
								{
									goto IL_0199;
								}
							}
						}
					}
				}
				IsEnemySprayed = true;
				ItemSprayed = itemSprayed;
				Main.Log.LogInfo((object)"Sprayed");
			}
			goto IL_0199;
			IL_0199:
			PlayerSpraying = ((GrabbableObject)__instance).playerHeldBy;
			Bees = Object.FindObjectsOfType<RedLocustBees>();
			Enemies = Object.FindObjectsOfType<EnemyAI>();
			Spiders = Object.FindObjectsOfType<SandSpiderAI>();
			Crawlers = Object.FindObjectsOfType<CrawlerAI>();
			Bugs = Object.FindObjectsOfType<HoarderBugAI>();
			Centipedes = Object.FindObjectsOfType<CentipedeAI>();
			ManualLogSource log2 = Main.Log;
			Vector3 val = sprayPos;
			string? text = ((object)(Vector3)(ref val)).ToString();
			val = sprayRot;
			log2.LogInfo((object)("Spray Paint Pos and Rot: " + text + " , " + ((object)(Vector3)(ref val)).ToString()));
			Enem = GetClosestEnemy(sprayPos);
			if ((Object)(object)Enem != (Object)null)
			{
				ManualLogSource log3 = Main.Log;
				string name = ((Object)Enem).name;
				val = sprayPos;
				log3.LogInfo((object)("Enemy Returned from Scan: " + name + "Position: " + ((object)(Vector3)(ref val)).ToString()));
			}
			else
			{
				Main.Log.LogInfo((object)"Enemy Returned from Scan was null ");
			}
		}

		private static EnemyAI GetClosestEnemy(Vector3 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			int mask = LayerMask.GetMask(new string[1] { "Enemies" });
			EnemyAI result = (from collider in Physics.OverlapSphere(position, 50f, mask, (QueryTriggerInteraction)2)
				select ((Component)collider).GetComponentInParent<EnemyAI>() into enemy
				where (Object)(object)enemy != (Object)null
				orderby Vector3.Distance(position, ((Component)enemy).transform.position)
				select enemy).FirstOrDefault();
			Main.Log.LogInfo((object)"Assigned ClosestEnemy");
			return result;
		}
	}
	[HarmonyPatch(typeof(RedLocustBees))]
	internal class SprayBeePatch
	{
		private static float sprayDuration = 8f;

		public static float sprayTimer;

		public static RedLocustBees targetBee;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void SprayBeePatcher(RedLocustBees __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject val = null;
			if (SprayPaintItemPatch.Bees == null || SprayPaintItemPatch.Bees.Length == 0)
			{
				return;
			}
			RaycastHit itemSprayed = SprayPaintItemPatch.ItemSprayed;
			if ((Object)(object)((RaycastHit)(ref itemSprayed)).collider == (Object)null || !SprayPaintItemPatch.IsBeeHiveSprayed)
			{
				return;
			}
			itemSprayed = SprayPaintItemPatch.ItemSprayed;
			Transform transform = ((RaycastHit)(ref itemSprayed)).transform;
			object obj;
			if (transform == null)
			{
				obj = null;
			}
			else
			{
				GameObject gameObject = ((Component)transform).gameObject;
				obj = ((gameObject != null) ? gameObject.GetComponent<GrabbableObject>() : null);
			}
			val = (GrabbableObject)obj;
			bool flag = false;
			RedLocustBees[] bees = SprayPaintItemPatch.Bees;
			foreach (RedLocustBees val2 in bees)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val == (Object)(object)val2.hive)
				{
					targetBee = val2;
					((EnemyAI)val2).agent.speed = 0f;
					((EnemyAI)val2).SwitchToBehaviourState(0);
					flag = true;
					BeeOuchPatch.isStunned = true;
				}
			}
			if (flag && (Object)(object)__instance == (Object)(object)targetBee)
			{
				sprayTimer += Time.deltaTime;
				if (sprayTimer >= sprayDuration)
				{
					BeeOuchPatch.isStunned = false;
					SprayPaintItemPatch.IsBeeHiveSprayed = false;
					sprayTimer = 0f;
					Main.Log.LogInfo((object)"Bees Recovered");
				}
			}
		}
	}
	[HarmonyPatch(typeof(RedLocustBees))]
	internal class BeeOuchPatch
	{
		public static bool isStunned;

		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool BeeOutchPatch(RedLocustBees __instance)
		{
			if (isStunned && (Object)(object)__instance == (Object)(object)SprayBeePatch.targetBee)
			{
				Main.Log.LogInfo((object)"DON'T HURT HIM!");
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(EnemyAI))]
	internal class SprayEnemyPatch
	{
		private static float sprayDuration = 8f;

		private static float sprayTimer;

		public static EnemyAI targetEnemy;

		private static bool enemiesAffected;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void SprayEnemyPatcher(EnemyAI __instance)
		{
			if ((Object)(object)SprayPaintItemPatch.Enem == (Object)null || SprayPaintItemPatch.Enemies.Length == 0 || !SprayPaintItemPatch.IsEnemySprayed)
			{
				return;
			}
			switch (((Object)SprayPaintItemPatch.Enem).name)
			{
			default:
				return;
			case "SandSpider(Clone)":
				enemiesAffected |= ProcessSpider<SandSpiderAI>(SprayPaintItemPatch.Spiders);
				break;
			case "Centipede(Clone)":
				enemiesAffected |= ProcessEnemyType<CentipedeAI>(SprayPaintItemPatch.Centipedes);
				break;
			case "Crawler(Clone)":
				enemiesAffected |= ProcessEnemyType<CrawlerAI>(SprayPaintItemPatch.Crawlers);
				break;
			case "HoarderBug(Clone)":
				enemiesAffected |= ProcessEnemyType<HoarderBugAI>(SprayPaintItemPatch.Bugs);
				break;
			}
			if (enemiesAffected && (Object)(object)__instance == (Object)(object)SprayPaintItemPatch.Enem)
			{
				sprayTimer += Time.deltaTime;
				if (sprayTimer >= sprayDuration)
				{
					ResetSprayEffect();
				}
			}
		}

		private static bool ProcessEnemyType<T>(T[] enemies) where T : EnemyAI
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			foreach (T val in enemies)
			{
				if ((Object)(object)val != (Object)null && ((Component)SprayPaintItemPatch.Enem).transform.position == ((Component)(object)val).transform.position)
				{
					((EnemyAI)val).agent.speed = 0f;
					targetEnemy = (EnemyAI)(object)val;
					return true;
				}
			}
			return false;
		}

		private static bool ProcessSpider<T>(T[] enemies) where T : EnemyAI
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			SandSpiderAI[] spiders = SprayPaintItemPatch.Spiders;
			foreach (SandSpiderAI val in spiders)
			{
				if ((Object)(object)val != (Object)null)
				{
					_ = ((Component)SprayPaintItemPatch.Enem).transform.position;
					_ = ((Component)val).transform.position;
					if (((Component)SprayPaintItemPatch.Enem).transform.position == ((Component)val).transform.position && SprayPaintItemPatch.IsEnemySprayed)
					{
						((EnemyAI)val).agent.speed = 0f;
						val.spiderSpeed = 0f;
						((EnemyAI)val).creatureAnimator.SetBool("moving", true);
						return true;
					}
				}
			}
			return false;
		}

		private static void ResetSprayEffect()
		{
			SprayPaintItemPatch.IsEnemySprayed = false;
			sprayTimer = 0f;
			enemiesAffected = false;
			Main.Log.LogInfo((object)$"{SprayPaintItemPatch.Enem} recovered.");
		}
	}
}