Decompiled source of Song Names v1.0.1

SongNames.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DeathStar")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DeathStar")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[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 SongNames;

[BepInPlugin("com.codemob.songnames", "Song Names", "1.0.0")]
public class SongNames : BaseUnityPlugin
{
	public Harmony harmony;

	public static TextMeshProUGUI textComponent;

	public static GameObject overlayObject;

	public static string currentText = string.Empty;

	public static SongNames instance;

	private void Awake()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Expected O, but got Unknown
		instance = this;
		harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
		harmony.PatchAll(typeof(SongNames));
		SceneManager.sceneLoaded += SceneManager_sceneLoaded;
		MethodInfo method = typeof(AudioManager).GetMethod("StartMenuMusic", BindingFlags.Instance | BindingFlags.NonPublic);
		MethodInfo method2 = typeof(SongNames).GetMethod("AudioManager_StartMenuMusic");
		harmony.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo method3 = typeof(AudioManager).GetMethod("StartMusic", BindingFlags.Instance | BindingFlags.NonPublic);
		MethodInfo method4 = typeof(SongNames).GetMethod("AudioManager_StartMusic");
		harmony.Patch((MethodBase)method3, new HarmonyMethod(method4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	public static void AudioManager_StartMenuMusic(AudioManager __instance)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		SetCurrentPlayingSong(__instance.menuSong);
	}

	public static void AudioManager_StartMusic(ref int songIndex, AudioManager __instance)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		SetCurrentPlayingSong(((__instance.test_songs != null && __instance.test_songs.Length != 0) ? __instance.test_songs : __instance.songs)[songIndex]);
	}

	public static void SetCurrentPlayingSong(Song song)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		string name = song.name;
		name = Regex.Replace(name, "(?<=[a-z])[A-Z]", " $&");
		currentText = "Currently playing: " + name;
		((TMP_Text)textComponent).text = currentText;
	}

	private void SceneManager_sceneLoaded(Scene scene, LoadSceneMode arg1)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: 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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: 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_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)overlayObject != (Object)null)
		{
			Object.Destroy((Object)(object)overlayObject);
		}
		overlayObject = new GameObject("song text :3");
		Canvas val = overlayObject.AddComponent<Canvas>();
		CanvasScaler obj = overlayObject.AddComponent<CanvasScaler>();
		val.renderMode = (RenderMode)1;
		val.worldCamera = Camera.current;
		val.sortingLayerName = "behind Walls Infront of everything else";
		val.sortingOrder = 1;
		obj.uiScaleMode = (ScaleMode)1;
		GameObject val2 = new GameObject("SongText", new Type[2]
		{
			typeof(RectTransform),
			typeof(TextMeshProUGUI)
		});
		textComponent = val2.GetComponent<TextMeshProUGUI>();
		val2.transform.SetParent(((Component)val).transform);
		((TMP_Text)textComponent).text = currentText;
		((TMP_Text)textComponent).font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
		((Graphic)textComponent).color = Color.Lerp(Color.blue, Color.black, 0.6f);
		((TMP_Text)textComponent).fontSize = 13f;
		((Graphic)textComponent).raycastTarget = false;
		((TMP_Text)textComponent).alignment = (TextAlignmentOptions)258;
		RectTransform component = val2.GetComponent<RectTransform>();
		component.anchorMin = new Vector2(0.5f, 1f);
		component.anchorMax = new Vector2(0.5f, 1f);
		component.pivot = new Vector2(0.5f, 0.5f);
		component.sizeDelta = new Vector2(1200f, 0f);
		component.anchoredPosition = new Vector2(0f, -2f);
	}
}