Decompiled source of TargetToggleandBosstargetting v1.0.2

TargetToggleMod.dll

Decompiled 15 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Assets.Scripts.Actors.Enemies;
using Assets.Scripts.Inventory__Items__Pickups.Weapons;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("TargetToggleMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TargetToggleMod")]
[assembly: AssemblyTitle("TargetToggleMod")]
[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 TargetToggleMod
{
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.tuusuario.targettoggle";

		public const string PLUGIN_NAME = "TargetToggle";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("com.tuusuario.targettoggle", "TargetToggle", "1.0.0")]
	[BepInProcess("Megabonk.exe")]
	public class TargetTogglePlugin : BasePlugin
	{
		[HarmonyPatch(typeof(EnemyTargeting), "GetTargetedEnemy")]
		public static class PatchGetTargetedEnemy
		{
			public static bool Prefix(Il2CppReferenceArray<Collider> colliders, int count, Vector3 pos, bool useVision, GameObject exceptObject, ref Enemy __result)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				if (IsBossFocus)
				{
					Enemy val = FindBossInColliders(colliders, count, exceptObject);
					if ((Object)(object)val != (Object)null)
					{
						__result = val;
						return false;
					}
				}
				if (!IsSmartAim)
				{
					__result = EnemyTargeting.GetClosestEnemy(colliders, count, pos, useVision, exceptObject);
					return false;
				}
				return true;
			}

			private static Enemy FindBossInColliders(Il2CppReferenceArray<Collider> colliders, int count, GameObject exceptObject)
			{
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Invalid comparison between Unknown and I4
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				Enemy result = null;
				float num = float.MaxValue;
				for (int i = 0; i < count; i++)
				{
					Collider val = ((Il2CppArrayBase<Collider>)(object)colliders)[i];
					if ((Object)(object)val == (Object)null || ((Object)(object)exceptObject != (Object)null && ((Object)((Component)val).gameObject).GetInstanceID() == ((Object)exceptObject).GetInstanceID()))
					{
						continue;
					}
					Enemy component = ((Component)val).GetComponent<Enemy>();
					if (!((Object)(object)component == (Object)null) && !component.IsDead() && !component.IsDeadOrDyingNextFrame() && (component.enemyFlag & 0x36) > 0)
					{
						Vector3 centerPosition = component.GetCenterPosition();
						float sqrMagnitude = ((Vector3)(ref centerPosition)).sqrMagnitude;
						if (sqrMagnitude < num)
						{
							num = sqrMagnitude;
							result = component;
						}
					}
				}
				return result;
			}
		}

		public class TargetToggleHUD : MonoBehaviour
		{
			private float _notifyAlpha = 0f;

			private const float FADE_DURATION = 2.5f;

			private GameObject _hudObject;

			public TargetToggleHUD(IntPtr ptr)
				: base(ptr)
			{
			}

			private void Start()
			{
				CreateHUD();
			}

			private bool IsInGame()
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				Scene activeScene = SceneManager.GetActiveScene();
				return ((Scene)(ref activeScene)).name == "GeneratedMap";
			}

			private void CreateHUD()
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Expected O, but got Unknown
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Expected O, but got Unknown
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Expected O, but got Unknown
				//IL_013c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0149: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0177: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
				_hudObject = new GameObject("TargetToggleHUD");
				Object.DontDestroyOnLoad((Object)(object)_hudObject);
				Canvas val = _hudObject.AddComponent<Canvas>();
				val.renderMode = (RenderMode)0;
				val.sortingOrder = 100;
				_hudObject.AddComponent<CanvasScaler>();
				_hudObject.AddComponent<GraphicRaycaster>();
				GameObject val2 = new GameObject("Panel");
				val2.transform.SetParent(_hudObject.transform, false);
				RectTransform val3 = val2.AddComponent<RectTransform>();
				val3.anchorMin = new Vector2(1f, 0f);
				val3.anchorMax = new Vector2(1f, 0f);
				val3.pivot = new Vector2(1f, 0f);
				val3.anchoredPosition = new Vector2(-16f, 16f);
				val3.sizeDelta = new Vector2(240f, 38f);
				Image val4 = val2.AddComponent<Image>();
				((Graphic)val4).color = new Color(0f, 0f, 0f, 0.55f);
				GameObject val5 = new GameObject("Label");
				val5.transform.SetParent(val2.transform, false);
				RectTransform val6 = val5.AddComponent<RectTransform>();
				val6.anchorMin = Vector2.zero;
				val6.anchorMax = Vector2.one;
				val6.offsetMin = new Vector2(8f, 0f);
				val6.offsetMax = new Vector2(-8f, 0f);
				_hudText = val5.AddComponent<Text>();
				_hudText.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
				_hudText.fontSize = 15;
				_hudText.alignment = (TextAnchor)4;
				((Graphic)_hudText).color = Color.white;
				_hudText.text = GetHUDText();
			}

			private void Update()
			{
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0151: Unknown result type (might be due to invalid IL or missing references)
				//IL_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0114: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				bool flag = IsInGame();
				if ((Object)(object)_hudObject != (Object)null)
				{
					_hudObject.SetActive(flag);
				}
				if (!flag)
				{
					return;
				}
				if (Input.GetKeyDown(Instance.ToggleTargetingKey.Value))
				{
					ToggleTargeting();
					_notifyAlpha = 1f;
				}
				if (Input.GetKeyDown(Instance.ToggleBossFocusKey.Value))
				{
					ToggleBossFocus();
					_notifyAlpha = 1f;
				}
				Color val = (Color)(IsBossFocus ? new Color(1f, 0.9f, 0.2f, 1f) : Color.white);
				if (_notifyAlpha > 0f)
				{
					_notifyAlpha -= Time.deltaTime / 2.5f;
					if ((Object)(object)_hudText != (Object)null)
					{
						float num = 1f + _notifyAlpha * 0.6f;
						((Graphic)_hudText).color = new Color(val.r * num, val.g * num, val.b * num, 1f);
					}
				}
				else if ((Object)(object)_hudText != (Object)null)
				{
					((Graphic)_hudText).color = val;
				}
			}
		}

		private Harmony _harmony;

		private static Text _hudText;

		public static TargetTogglePlugin Instance { get; private set; }

		public ConfigEntry<KeyCode> ToggleTargetingKey { get; private set; }

		public ConfigEntry<KeyCode> ToggleBossFocusKey { get; private set; }

		public static bool IsSmartAim { get; private set; }

		public static bool IsBossFocus { get; private set; }

		public override void Load()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			ToggleTargetingKey = ((BasePlugin)this).Config.Bind<KeyCode>("Hotkeys", "ToggleTargetingMode", (KeyCode)116, "Alterna entre Closest Enemy y Smart Aim.");
			ToggleBossFocusKey = ((BasePlugin)this).Config.Bind<KeyCode>("Hotkeys", "ToggleBossFocus", (KeyCode)121, "Alterna el modo Boss Focus (prioriza bosses sobre enemigos normales).");
			_harmony = new Harmony("com.tuusuario.targettoggle");
			_harmony.PatchAll();
			((BasePlugin)this).AddComponent<TargetToggleHUD>();
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(73, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[TargetToggleMod] Cargado! [");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<KeyCode>(ToggleTargetingKey.Value);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] = toggle targeting | [");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<KeyCode>(ToggleBossFocusKey.Value);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] = toggle boss focus");
			}
			log.LogInfo(val);
		}

		public static void ToggleTargeting()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			IsSmartAim = !IsSmartAim;
			UpdateHUD();
			ManualLogSource log = ((BasePlugin)Instance).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[TargetToggleMod] Targeting: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(GetTargetingName());
			}
			log.LogInfo(val);
		}

		public static void ToggleBossFocus()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			IsBossFocus = !IsBossFocus;
			UpdateHUD();
			ManualLogSource log = ((BasePlugin)Instance).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(30, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[TargetToggleMod] Boss Focus: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(IsBossFocus);
			}
			log.LogInfo(val);
		}

		public static string GetTargetingName()
		{
			return IsSmartAim ? "Smart Aim" : "Closest Enemy";
		}

		public static string GetHUDText()
		{
			string text = (IsSmartAim ? "Smart Aim" : "Closest");
			string text2 = (IsBossFocus ? " | BOSS" : "");
			return "TARGET: " + text + text2;
		}

		private static void UpdateHUD()
		{
			if ((Object)(object)_hudText != (Object)null)
			{
				_hudText.text = GetHUDText();
			}
		}
	}
}