Decompiled source of DeleteTrackButton v1.0.1

DeleteTrackButton.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BaboonAPI.Hooks.Initializer;
using BaboonAPI.Hooks.Tracks;
using BepInEx;
using BepInEx.Logging;
using DeleteTrackButton.Patches;
using HarmonyLib;
using TrombLoader.CustomTracks;
using TrombLoader.Helpers;
using UnityEngine;
using UnityEngine.Events;
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: AssemblyTitle("DeleteButtonTromboneMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DeleteButtonTromboneMod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("877b1f7e-c1d3-4542-886c-3bc615cd8c7c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DeleteTrackButton
{
	[BepInPlugin("ch.offbeatwit.deletetrackbutton", "DeleteTrackButton", "1.0.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		public static Plugin Instance;

		public static GameObject DeleteTrackButton;

		public static SingleTrackData SelectedTrack;

		public static int SelectedTrackIndex;

		public static GameObject ConfirmDeletePopup;

		public static ColorBlock CancelButtonColors;

		public static ColorBlock DeleteButtonColors;

		public static bool ResetBackClicked;

		private static SingleTrackData trackToDelete;

		private static int trackToDeleteIndex;

		private Harmony _harmony = new Harmony("ch.offbeatwit.chimpanzee");

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			GameInitializationEvent.Register(((BaseUnityPlugin)this).Info, (Action)TryInitialize);
		}

		private void TryInitialize()
		{
			_harmony.PatchAll();
		}

		public static void OpenPopup()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			ConfirmDeletePopup.SetActive(true);
			trackToDelete = SelectedTrack;
			trackToDeleteIndex = SelectedTrackIndex;
			string[] array = ((CustomTrack)TrackLookup.lookup(SelectedTrack.trackref)).folderPath.Split(new char[1] { Path.DirectorySeparatorChar });
			string obj = array[^2];
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			string text = obj + directorySeparatorChar + array[^1];
			ConfirmDeletePopup.GetComponentInChildren<Text>().text = "<size=51>Delete " + SelectedTrack.trackname_short + "?</size>\n\n The folder <size=25>" + text + "</size>\nwill be permanently deleted.";
			Button[] componentsInChildren = ConfirmDeletePopup.GetComponentsInChildren<Button>();
			((Component)componentsInChildren[0]).GetComponentInChildren<Text>().text = "Delete";
			((Selectable)componentsInChildren[0]).colors = DeleteButtonColors;
			((Component)componentsInChildren[1]).GetComponentInChildren<Text>().text = "Cancel";
			((Selectable)componentsInChildren[1]).colors = CancelButtonColors;
			ConfirmDeletePopup.transform.localScale = new Vector3(1.1f, 1.1f, 1f);
			LeanTween.scale(ConfirmDeletePopup, new Vector3(1f, 1f, 1f), 0.3f).setDelay(0.08f).setEaseOutBounce();
		}

		public static void ClosePopup()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			LeanTween.scale(ConfirmDeletePopup, new Vector3(1f, 0.001f, 1f), 0.2f).setOnComplete((Action)delegate
			{
				ConfirmDeletePopup.SetActive(false);
			}).setEaseInQuart();
		}

		public static void DeleteSong()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			Log.LogInfo((object)("Deleting Track " + trackToDelete.trackref));
			string folderPath = ((CustomTrack)TrackLookup.lookup(trackToDelete.trackref)).folderPath;
			if (Directory.Exists(folderPath))
			{
				Directory.Delete(folderPath, recursive: true);
				TrackLookup.reload();
				AdvanceSongsPatch.advanceSongs(Object.FindObjectOfType<LevelSelectController>(), trackToDeleteIndex - 1, do_full_anim: false);
			}
			ClosePopup();
		}
	}
}
namespace DeleteTrackButton.Patches
{
	[HarmonyPatch(typeof(HomeController), "Start")]
	public class HomeControllerStartPatch : MonoBehaviour
	{
		private static void Postfix(HomeController __instance)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			Button[] componentsInChildren = __instance.canvasyesno.GetComponentsInChildren<Button>();
			Plugin.CancelButtonColors = ((Selectable)componentsInChildren[0]).colors;
			Plugin.DeleteButtonColors = ((Selectable)componentsInChildren[1]).colors;
		}
	}
	[HarmonyPatch(typeof(LevelSelectController), "Start")]
	public class LevelSelectControllerStartPatch : MonoBehaviour
	{
		private static void Postfix(LevelSelectController __instance, ref int ___songindex, ref List<SingleTrackData> ___alltrackslist)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00d6: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Expected O, but got Unknown
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Expected O, but got Unknown
			GameObject val = GameObject.Find("Mute");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"Mute button not found.");
				return;
			}
			Plugin.DeleteTrackButton = Object.Instantiate<GameObject>(val, (Transform)(object)__instance.fullpanel);
			((Object)Plugin.DeleteTrackButton).name = "Delete Track Button";
			Plugin.DeleteTrackButton.GetComponent<RectTransform>().anchorMax = new Vector2(0f, 0f);
			((Transform)Plugin.DeleteTrackButton.GetComponent<RectTransform>()).localScale = new Vector3(-1f, -1f, 1f);
			Plugin.DeleteTrackButton.SetActive(false);
			((UnityEventBase)Plugin.DeleteTrackButton.GetComponentInChildren<Button>().onClick).SetPersistentListenerState(0, (UnityEventCallState)0);
			((UnityEvent)Plugin.DeleteTrackButton.GetComponentInChildren<Button>().onClick).AddListener(new UnityAction(Plugin.OpenPopup));
			Image[] componentsInChildren = Plugin.DeleteTrackButton.GetComponentsInChildren<Image>();
			Image obj = componentsInChildren[3];
			Sprite sprite2 = (componentsInChildren[2].sprite = GetSprite(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location) + "/Assets/trash-bin-icon.png"));
			obj.sprite = sprite2;
			RectTransform rectTransform = ((Graphic)componentsInChildren[3]).rectTransform;
			RectTransform rectTransform2 = ((Graphic)componentsInChildren[2]).rectTransform;
			Vector2 sizeDelta = default(Vector2);
			((Vector2)(ref sizeDelta))..ctor(80f, 80f);
			rectTransform2.sizeDelta = sizeDelta;
			rectTransform.sizeDelta = sizeDelta;
			Transform transform = ((Component)componentsInChildren[3]).transform;
			Quaternion localRotation = (((Component)componentsInChildren[2]).transform.localRotation = Quaternion.Euler(0f, 0f, 180f));
			transform.localRotation = localRotation;
			Plugin.ConfirmDeletePopup = Object.Instantiate<GameObject>(__instance.first_time_popupcanvas, __instance.first_time_popupcanvas.transform.parent);
			Button componentInChildren = Plugin.ConfirmDeletePopup.GetComponentInChildren<Button>();
			Button val3 = Object.Instantiate<Button>(componentInChildren, ((Component)componentInChildren).transform.parent);
			RectTransform component = ((Component)componentInChildren).GetComponent<RectTransform>();
			component.anchoredPosition += new Vector2(150f, 0f);
			RectTransform component2 = ((Component)val3).GetComponent<RectTransform>();
			component2.anchoredPosition -= new Vector2(150f, 0f);
			((UnityEventBase)componentInChildren.onClick).SetPersistentListenerState(0, (UnityEventCallState)0);
			((UnityEventBase)val3.onClick).SetPersistentListenerState(0, (UnityEventCallState)0);
			((UnityEvent)componentInChildren.onClick).AddListener(new UnityAction(Plugin.DeleteSong));
			((UnityEvent)val3.onClick).AddListener(new UnityAction(Plugin.ClosePopup));
			if (___alltrackslist != null)
			{
				Plugin.SelectedTrack = ___alltrackslist[___songindex];
				Plugin.SelectedTrackIndex = ___songindex;
				if ((Object)(object)Plugin.DeleteTrackButton != (Object)null && Plugin.SelectedTrack != null)
				{
					Plugin.DeleteTrackButton.SetActive(Globals.IsCustomTrack(Plugin.SelectedTrack.trackref));
				}
			}
		}

		private static Sprite GetSprite(string path)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(0, 0);
			ImageConversion.LoadImage(val, array);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero, 300f);
		}
	}
	[HarmonyPatch(typeof(LevelSelectController), "populateSongNames")]
	public class LevelSelectControllerPopulateSongNamesPatch : MonoBehaviour
	{
		private static void Postfix(LevelSelectController __instance, ref int ___songindex, ref List<SingleTrackData> ___alltrackslist)
		{
			if (___alltrackslist != null)
			{
				Plugin.SelectedTrack = ___alltrackslist[___songindex];
				Plugin.SelectedTrackIndex = ___songindex;
				if ((Object)(object)Plugin.DeleteTrackButton != (Object)null && Plugin.SelectedTrack != null)
				{
					Plugin.DeleteTrackButton.SetActive(Globals.IsCustomTrack(Plugin.SelectedTrack.trackref));
				}
			}
		}
	}
	[HarmonyPatch(typeof(LevelSelectController), "Update")]
	public class LevelSelectControllerUpdatePatch : MonoBehaviour
	{
		private static void Prefix(ref bool ___back_clicked)
		{
			if (Plugin.ResetBackClicked)
			{
				___back_clicked = false;
				Plugin.ResetBackClicked = false;
			}
			if (Input.GetKeyDown((KeyCode)27) && (Object)(object)Plugin.ConfirmDeletePopup != (Object)null && Plugin.ConfirmDeletePopup.activeSelf)
			{
				Plugin.ClosePopup();
				___back_clicked = true;
				Plugin.ResetBackClicked = true;
			}
		}
	}
	[HarmonyPatch]
	public class AdvanceSongsPatch
	{
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(LevelSelectController), "advanceSongs")]
		public static void advanceSongs(object instance, int dir, bool do_full_anim)
		{
			throw new NotImplementedException("It's a stub");
		}
	}
}