Decompiled source of FavoritePriorities v1.0.5

FavoritePriorities.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("FavoritePriorities")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3586e87e3da53854f0bea8e5493b22afff60a738")]
[assembly: AssemblyProduct("FavoritePriorities")]
[assembly: AssemblyTitle("FavoritePriorities")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FavoritePriorities;

[HarmonyPatch(typeof(TowerUI), "Start")]
public static class Patch_TowerUI_Start
{
	private static void Postfix(TowerUI __instance)
	{
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Expected O, but got Unknown
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		Transform val = ((Component)__instance).transform.Find("Canvas");
		Transform val2 = val.Find("FavoritePrioritiesPanel");
		GameObject val4;
		if ((Object)(object)val2 == (Object)null)
		{
			Transform val3 = val.Find("RightPanel");
			if ((Object)(object)val3 == (Object)null)
			{
				Plugin.Log.LogError((object)"[FavoritePriorities] No se encontró RightPanel para clonar.");
				return;
			}
			val4 = Object.Instantiate<GameObject>(((Component)val3).gameObject, val);
			((Object)val4).name = "FavoritePrioritiesPanel";
			val2 = val4.transform;
			foreach (Transform item in val2)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			RectTransform component = val4.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0.5f);
			component.anchorMax = new Vector2(0f, 0.5f);
			component.pivot = new Vector2(1f, 1f);
			((Transform)component).localPosition = new Vector3(-0.8f, -3.75f, 0f);
			component.sizeDelta = new Vector2(5f, 3f);
			((Transform)component).localScale = Vector3.one;
			Image component2 = val4.GetComponent<Image>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Graphic)component2).color = new Color(1f, 1f, 0.7f, 0f);
			}
			VerticalLayoutGroup obj = val4.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj).padding = new RectOffset(0, 0, 0, 0);
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 0.2f;
			((LayoutGroup)obj).childAlignment = (TextAnchor)4;
			val2.SetAsLastSibling();
			val4.SetActive(true);
		}
		else
		{
			val4 = ((Component)val2).gameObject;
		}
		GameObject gameObject = ((Component)val.Find("Demolish Button")).gameObject;
		Text componentInChildren = gameObject.GetComponentInChildren<Text>();
		Image component3 = gameObject.GetComponent<Image>();
		ColorBlock colors = ((Selectable)gameObject.GetComponent<Button>()).colors;
		for (int i = 0; i < 5; i++)
		{
			GameObject obj2 = Object.Instantiate<GameObject>(gameObject, val2);
			((Object)obj2).name = $"FavoriteBtn{i + 1}";
			RectTransform component4 = obj2.GetComponent<RectTransform>();
			component4.sizeDelta = new Vector2(3.5f, 0.3f);
			component4.pivot = new Vector2(0.5f, 0.5f);
			((Transform)component4).localScale = Vector3.one;
			((Transform)component4).localPosition = Vector3.zero;
			Button component5 = obj2.GetComponent<Button>();
			if ((Object)(object)component5 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component5);
			}
			Button val5 = obj2.AddComponent<Button>();
			((Selectable)val5).colors = colors;
			((Selectable)val5).transition = (Transition)1;
			Image component6 = obj2.GetComponent<Image>();
			component6.sprite = component3.sprite;
			component6.type = component3.type;
			((Graphic)component6).color = ((Graphic)component3).color;
			Text componentInChildren2 = obj2.GetComponentInChildren<Text>();
			componentInChildren2.text = Plugin.Instance.Priorities[i].Value.Replace(",", ", ");
			componentInChildren2.font = componentInChildren.font;
			componentInChildren2.fontSize = componentInChildren.fontSize;
			((Graphic)componentInChildren2).color = ((Graphic)componentInChildren).color;
			componentInChildren2.alignment = componentInChildren.alignment;
			componentInChildren2.resizeTextForBestFit = componentInChildren.resizeTextForBestFit;
			componentInChildren2.resizeTextMinSize = 6;
			componentInChildren2.resizeTextMaxSize = 24;
			int idx = i;
			((UnityEvent)val5.onClick).AddListener((UnityAction)delegate
			{
				ApplyPreset(__instance, idx);
			});
		}
		((MonoBehaviour)__instance).StartCoroutine(HandleShortcutsAndToggle(__instance, val4));
	}

	private static void ApplyPreset(TowerUI ui, int idx)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected I4, but got Unknown
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected I4, but got Unknown
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Expected I4, but got Unknown
		Tower val = (Tower)AccessTools.Field(typeof(TowerUI), "myTower").GetValue(ui);
		string[] array = Plugin.Instance.Priorities[idx].Value.Split(new char[1] { ',' });
		if (array.Length != 0 && Enum.TryParse<Priority>(array[0], out Priority result))
		{
			val.priorities[0] = (Priority)(int)result;
		}
		if (array.Length > 1 && Enum.TryParse<Priority>(array[1], out Priority result2))
		{
			val.priorities[1] = (Priority)(int)result2;
		}
		if (array.Length > 2 && Enum.TryParse<Priority>(array[2], out Priority result3))
		{
			val.priorities[2] = (Priority)(int)result3;
		}
		val.CopyPriorities();
		val.PastePriorities();
		ui.SetStats(val);
	}

	private static IEnumerator HandleShortcutsAndToggle(TowerUI ui, GameObject panel)
	{
		panel.SetActive(Plugin.ShowFavoritePanel);
		while ((Object)(object)ui != (Object)null && ((Behaviour)ui).isActiveAndEnabled)
		{
			if (Input.GetKeyDown(Plugin.Instance.TogglePanelKey.Value))
			{
				Plugin.ShowFavoritePanel = !Plugin.ShowFavoritePanel;
				panel.SetActive(Plugin.ShowFavoritePanel);
			}
			for (int i = 0; i < Plugin.Instance.PriorityKeybinds.Length; i++)
			{
				if (Input.GetKeyDown(Plugin.Instance.PriorityKeybinds[i].Value))
				{
					ApplyPreset(ui, i);
				}
			}
			yield return null;
		}
	}
}
[BepInPlugin("AgusBut.FavoritePriorities", "FavoritePriorities", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static bool ShowFavoritePanel = true;

	private ConfigEntry<string>[] priorities = new ConfigEntry<string>[5];

	private ConfigEntry<KeyCode>[] priorityKeybinds = new ConfigEntry<KeyCode>[5];

	private ConfigEntry<KeyCode> togglePanelKey;

	public static Plugin Instance { get; private set; }

	public static ManualLogSource Log { get; private set; }

	public ConfigEntry<string>[] Priorities => priorities;

	public ConfigEntry<KeyCode>[] PriorityKeybinds => priorityKeybinds;

	public ConfigEntry<KeyCode> TogglePanelKey => togglePanelKey;

	private void Awake()
	{
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		string[] array = new string[5] { "NearDeath,MostHealth,Progress", "MostArmor,LeastShield,Slowest", "Fastest,MostArmor,LeastShield", "Fastest,MostShield,Progress", "MostHealth,MostArmor,MostShield" };
		KeyCode[] array2 = new KeyCode[5];
		RuntimeHelpers.InitializeArray(array2, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		KeyCode[] array3 = (KeyCode[])(object)array2;
		for (int i = 0; i < priorities.Length; i++)
		{
			priorities[i] = ((BaseUnityPlugin)this).Config.Bind<string>("FavoritePriorities", $"Priority{i + 1}", array[i], $"Priority combination for button {i + 1}\nAcceptable values: Progress, NearDeath, MostHealth, MostArmor, MostShield, LeastHealth, LeastArmor, LeastShield, Fastest, Slowest, Marked");
		}
		for (int j = 0; j < priorityKeybinds.Length; j++)
		{
			priorityKeybinds[j] = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("FavoritePriorities.Keybinds", $"PriorityKey{j + 1}", array3[j], $"Key to activate priority {j + 1}");
		}
		togglePanelKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("FavoritePriorities.Keybinds", "TogglePanelKey", (KeyCode)9, "Key to show/hide the priority panel");
		new Harmony("AgusBut.FavoritePriorities").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading [FavoritePriorities 1.0.5]");
	}
}