Decompiled source of LagJutsu v1.0.0

LagJutsu.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
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 GameNetcodeStuff;
using HarmonyLib;
using OPJosMod.LagJutsu.Patches;
using OPJosMod.LagJutsu.Utils;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OPJosMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OPJosMod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("70095872-b952-4e27-bbc4-3d70d0238f39")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OPJosMod.LagJutsu
{
	public static class ConfigVariables
	{
		public static Key DeathToggleButton;

		public static Key KillSelfButton;
	}
	[BepInPlugin("OpJosMod.LagJutsu", "LagJutsu", "1.0.0")]
	public class OpJosMod : BaseUnityPlugin
	{
		private const string modGUID = "OpJosMod.LagJutsu";

		private const string modName = "LagJutsu";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("OpJosMod.LagJutsu");

		private static OpJosMod Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("OpJosMod.LagJutsu");
			mls.LogInfo((object)"mod has started");
			setupConfig();
			PlayerControllerBPatch.SetLogSource(mls);
			EnemyAIPatch.SetLogSource(mls);
			ForestGiantAIPatch.SetLogSource(mls);
			FlowermanAIPatch.SetLogSource(mls);
			CentipedeAIPatch.SetLogSource(mls);
			CrawlerAIPatch.SetLogSource(mls);
			MouthDogAIPatch.SetLogSource(mls);
			harmony.PatchAll();
		}

		private void setupConfig()
		{
			//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)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<Key> val = ((BaseUnityPlugin)this).Config.Bind<Key>("God Mode Toggle", "GodModeToggle", (Key)25, "Button used to toggle God Mode");
			ConfigEntry<Key> val2 = ((BaseUnityPlugin)this).Config.Bind<Key>("Kill Self Button", "KillSelfButton", (Key)26, "Button used to off yourself");
			ConfigVariables.DeathToggleButton = val.Value;
			ConfigVariables.KillSelfButton = val2.Value;
		}
	}
}
namespace OPJosMod.LagJutsu.Patches
{
	[HarmonyPatch(typeof(CentipedeAI))]
	internal class CentipedeAIPatch
	{
		private static ManualLogSource mls;

		public static void SetLogSource(ManualLogSource logSource)
		{
			mls = logSource;
		}

		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool onCollideWithPlayerPatch(CentipedeAI __instance, ref Collider other)
		{
			if (PlayerControllerBPatch.godMode && !((EnemyAI)__instance).isEnemyDead)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if (StartOfRound.Instance.localPlayerController.playerClientId == component.playerClientId)
				{
					PlayerControllerBPatch.teleportPlayerBack();
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MouthDogAI))]
	internal class MouthDogAIPatch
	{
		private static ManualLogSource mls;

		public static void SetLogSource(ManualLogSource logSource)
		{
			mls = logSource;
		}

		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool onCollideWithPlayerPatch(CrawlerAI __instance, ref Collider other)
		{
			if (PlayerControllerBPatch.godMode && !((EnemyAI)__instance).isEnemyDead)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if (StartOfRound.Instance.localPlayerController.playerClientId == component.playerClientId)
				{
					PlayerControllerBPatch.teleportPlayerBack();
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(FlowermanAI))]
	internal class FlowermanAIPatch
	{
		private static ManualLogSource mls;

		public static void SetLogSource(ManualLogSource logSource)
		{
			mls = logSource;
		}

		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool onCollideWithPlayerPatch(FlowermanAI __instance, ref Collider other)
		{
			if (PlayerControllerBPatch.godMode && !((EnemyAI)__instance).isEnemyDead)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if (StartOfRound.Instance.localPlayerController.playerClientId == component.playerClientId)
				{
					PlayerControllerBPatch.teleportPlayerBack();
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(CrawlerAI))]
	internal class CrawlerAIPatch
	{
		private static ManualLogSource mls;

		public static void SetLogSource(ManualLogSource logSource)
		{
			mls = logSource;
		}

		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool onCollideWithPlayerPatch(CrawlerAI __instance, ref Collider other)
		{
			if (PlayerControllerBPatch.godMode && !((EnemyAI)__instance).isEnemyDead)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if (StartOfRound.Instance.localPlayerController.playerClientId == component.playerClientId)
				{
					PlayerControllerBPatch.teleportPlayerBack();
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ForestGiantAI))]
	internal class ForestGiantAIPatch
	{
		private static ManualLogSource mls;

		public static void SetLogSource(ManualLogSource logSource)
		{
			mls = logSource;
		}

		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool onCollideWithPlayerPatch(ref Collider other)
		{
			if (PlayerControllerBPatch.godMode)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if (StartOfRound.Instance.localPlayerController.playerClientId == component.playerClientId)
				{
					PlayerControllerBPatch.teleportPlayerBack();
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyAIPatch
	{
		private static ManualLogSource mls;

		public static EnemyAI[] allEnemies;

		public static void SetLogSource(ManualLogSource logSource)
		{
			mls = logSource;
		}

		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool onCollideWithPlayerPatch(EnemyAI __instance, ref Collider other)
		{
			if (PlayerControllerBPatch.godMode && !__instance.isEnemyDead)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if (StartOfRound.Instance.localPlayerController.playerClientId == component.playerClientId)
				{
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static ManualLogSource mls;

		public static bool godMode = true;

		private static float lastToggledTime = Time.time;

		private static float toggleDelay = 0.2f;

		private static float lastTimeAddedLocation = Time.time;

		private static List<Vector3> lastSafeLocations = new List<Vector3>();

		private static float lastUpdatedKnownEnemies = Time.time;

		public static void SetLogSource(ManualLogSource logSource)
		{
			mls = logSource;
		}

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void startPatch(PlayerControllerB __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			lastSafeLocations.Add(((Component)RoundManager.Instance.playersManager.playerSpawnPositions[0]).transform.position);
			EnemyAIPatch.allEnemies = Object.FindObjectsOfType<EnemyAI>();
		}

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void patchUpdate(PlayerControllerB __instance)
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)StartOfRound.Instance.localPlayerController == (Object)null || __instance.playerClientId != StartOfRound.Instance.localPlayerController.playerClientId)
			{
				return;
			}
			handleGodModeToggle();
			handleTerminateButton();
			updateKnownEnemies();
			if (!((double)(Time.time - lastTimeAddedLocation) > 0.1) || !__instance.thisController.isGrounded)
			{
				return;
			}
			if (lastSafeLocations.Count >= 600)
			{
				lastSafeLocations.RemoveAt(0);
			}
			if (lastSafeLocations.Count > 0)
			{
				if (!GeneralUtil.AreVectorsClose(((Component)__instance).transform.position, lastSafeLocations[lastSafeLocations.Count - 1], 0.5f))
				{
					lastSafeLocations.Add(((Component)__instance).transform.position);
					lastTimeAddedLocation = Time.time;
				}
			}
			else
			{
				lastSafeLocations.Add(((Component)__instance).transform.position);
				lastTimeAddedLocation = Time.time;
			}
		}

		[HarmonyPatch("KillPlayer")]
		[HarmonyPrefix]
		private static bool killPlayerPatch(PlayerControllerB __instance)
		{
			if (((Object)(object)StartOfRound.Instance.localPlayerController == (Object)null || __instance.playerClientId == StartOfRound.Instance.localPlayerController.playerClientId) && godMode)
			{
				teleportPlayerBack();
				return false;
			}
			return true;
		}

		public static void teleportPlayerBack()
		{
			//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)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (lastSafeLocations.Count <= 0)
			{
				return;
			}
			for (int num = lastSafeLocations.Count - 1; num >= 0; num--)
			{
				Vector3 position = ((Component)StartOfRound.Instance.localPlayerController).transform.position;
				if (!GeneralUtil.ExistsCloseEnemy(lastSafeLocations[num]) && !GeneralUtil.AreVectorsClose(lastSafeLocations[num], position, 1f))
				{
					((Component)StartOfRound.Instance.localPlayerController).transform.position = lastSafeLocations[num];
					mls.LogMessage((object)$"teleport player to: {lastSafeLocations[num]}");
					break;
				}
			}
		}

		private static void handleGodModeToggle()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (((ButtonControl)Keyboard.current[ConfigVariables.DeathToggleButton]).wasPressedThisFrame && Time.time - lastToggledTime > toggleDelay)
				{
					string text = "";
					if (godMode)
					{
						godMode = false;
						text = "OFF";
					}
					else
					{
						godMode = true;
						text = "ON";
					}
					lastToggledTime = Time.time;
					HUDManager.Instance.DisplayTip("God Mode", "turned " + text, false, false, "LC_Tip1");
					mls.LogMessage((object)("god mode turned " + text));
				}
			}
			catch
			{
			}
		}

		private static void handleTerminateButton()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((ButtonControl)Keyboard.current[ConfigVariables.KillSelfButton]).wasPressedThisFrame)
				{
					return;
				}
				PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
				if (!localPlayerController.isPlayerDead)
				{
					if (godMode)
					{
						HUDManager.Instance.DisplayTip("Can't Die", "God Mode On", false, false, "LC_Tip1");
					}
					else
					{
						localPlayerController.KillPlayer(new Vector3(0f, 0f, 0f), true, (CauseOfDeath)0, 0);
					}
				}
			}
			catch
			{
			}
		}

		private static void updateKnownEnemies()
		{
			if (Time.time - lastUpdatedKnownEnemies > 15f)
			{
				EnemyAIPatch.allEnemies = Object.FindObjectsOfType<EnemyAI>();
				lastUpdatedKnownEnemies = Time.time;
			}
		}
	}
}
namespace OPJosMod.LagJutsu.Utils
{
	public static class GeneralUtil
	{
		public static bool AreVectorsClose(Vector3 v1, Vector3 v2, float threshold)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Abs(v1.x - v2.x);
			float num2 = Mathf.Abs(v1.z - v2.z);
			return num <= threshold && num2 <= threshold;
		}

		public static bool ExistsCloseEnemy(Vector3 location)
		{
			//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)
			bool result = false;
			EnemyAI[] allEnemies = EnemyAIPatch.allEnemies;
			foreach (EnemyAI val in allEnemies)
			{
				if (AreVectorsClose(((Component)val).transform.position, location, 2f))
				{
					result = true;
				}
			}
			return result;
		}
	}
	public class ReflectionUtils
	{
		public static void InvokeMethod(object obj, string methodName, object[] parameters)
		{
			Type type = obj.GetType();
			MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			method.Invoke(obj, parameters);
		}

		public static void InvokeMethod(object obj, Type forceType, string methodName, object[] parameters)
		{
			MethodInfo method = forceType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			method.Invoke(obj, parameters);
		}

		public static void SetPropertyValue(object obj, string propertyName, object value)
		{
			Type type = obj.GetType();
			PropertyInfo property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			property.SetValue(obj, value);
		}

		public static T InvokeMethod<T>(object obj, string methodName, object[] parameters)
		{
			Type type = obj.GetType();
			MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			return (T)method.Invoke(obj, parameters);
		}

		public static T GetFieldValue<T>(object obj, string fieldName)
		{
			Type type = obj.GetType();
			FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			return (T)field.GetValue(obj);
		}

		public static void SetFieldValue(object obj, string fieldName, object value)
		{
			Type type = obj.GetType();
			FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			field.SetValue(obj, value);
		}
	}
}