Decompiled source of MusicDisplay v1.0.2

RoR2MusicNotification.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RoR2MusicNotification")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Mod for Risk of Rain 2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+34e4c85020f3f31b6fc8b125f68fd1081ca66f21")]
[assembly: AssemblyProduct("RoR2MusicNotification")]
[assembly: AssemblyTitle("RoR2MusicNotification")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
}
namespace RoR2MusicNotification
{
	internal class Data
	{
		public static Dictionary<string, string> trackNames = new Dictionary<string, string>
		{
			{ "muBossfightDLC1_10", "Having Fallen, It Was Blood" },
			{ "muBossfightDLC1_12", "A Boat Made from a Sheet of Newspaper" },
			{ "muEscape", "Escape (Unnamed Track)" },
			{ "muFULLSong02", "Into the Doldrums" },
			{ "muFULLSong06", "Nocturnal Emission" },
			{ "muFULLSong07", "Evapotranspiration" },
			{ "muFULLSong18", "Disdrometer" },
			{ "muFULLSong19", "Terra Pluviam" },
			{ "muGameplayBase_09", "They Might As Well Be Dead" },
			{ "muGameplayDLC1_01", "Once in a Lullaby" },
			{ "muGameplayDLC1_03", "Out of Whose Womb Came the Ice?" },
			{ "muGameplayDLC1_06", "Who Can Fathom the Soundless Depths?" },
			{ "muGameplayDLC1_08", "A Placid Island of Ignorance" },
			{ "muIntroCutscene", "Through a Cloud, Darkly" },
			{ "muLogbook", "The Dehydration of Risk of Rain 2" },
			{ "muMainEndingFull", "Lacrimosum" },
			{ "muMainEndingOutroA", "Lacrimosum" },
			{ "muMainEndingOutroB", "Lacrimosum" },
			{ "muMenu", "Risk of Rain 2" },
			{ "muMenuDLC1", "Prelude in D flat major" },
			{ "muNone", "" },
			{ "muRaidfightDLC1_07", "The Face of the Deep" },
			{ "muSong04", "Parjanya" },
			{ "muSong05", "Thermodynamic Equilibrium" },
			{ "muSong08", "A Glacier Eventually Farts (And Don't You Listen to the Song of Life)" },
			{ "muSong13", "The Raindrop that Fell to the Sky" },
			{ "muSong14", "The Rain Formerly Known as Purple" },
			{ "muSong16", "Hydrophobia" },
			{ "muSong21", "Petrichor V" },
			{ "muSong22", "Köppen As Fuck" },
			{ "muSong23", "Antarctic Oscillation" },
			{ "muSong24", "...con lentitud poderosa" },
			{ "muSong25", "You're Gonna Need A Bigger Ukulele" },
			{ "muSong_Habitat", "Om Mani Padme Hum, part II" },
			{ "muSong_HelminthBoss", "Tlalocan" },
			{ "muSong_HelminthRoost", "屋根の漏り (Yane No Mori)" },
			{ "muSong_Lakes&HabitatBoss", "A Tempestuous Noise of Thunder and Lightning Heard" },
			{ "muSong_LakesGameplay", "It Can't Rain All the Time" },
			{ "muSong_LemurianTemple", "Om Mani Padme Hum, part III" },
			{ "muSong_LemurianTempleBoss", "Forgot the Cry of Gulls" },
			{ "muSong_Meridian", "Om Mani Padme Hum, part I" },
			{ "muSong_MeridianFSB", "Om Mani Padme Hum, part I" },
			{ "muSong_Village", "I Should Build the Man a Statue" },
			{ "muSong_VillageBoss", "Forgot the Cry of Gulls" }
		};

		public static Dictionary<string, string> trackAuthors = new Dictionary<string, string>();
	}
	internal class ModConfig
	{
		public static ConfigEntry<int> cfgXHeight;

		public static ConfigEntry<int> cfgYHeight;

		public static ConfigEntry<float> cfgScale;

		public static ConfigEntry<HorizontalAlignmentOptions> cfgTextAlignment;

		public static void Initialize(ConfigFile config)
		{
			cfgXHeight = config.Bind<int>("Display", "Position X", 810, "");
			cfgYHeight = config.Bind<int>("Display", "Position Y", -200, "");
			cfgScale = config.Bind<float>("Display", "Scale Multiplier", 1f, "");
			cfgTextAlignment = config.Bind<HorizontalAlignmentOptions>("Display", "Text Alignment", (HorizontalAlignmentOptions)4, "");
			cfgXHeight.SettingChanged += CfgXHeight_SettingChanged;
			cfgYHeight.SettingChanged += CfgYHeight_SettingChanged;
			cfgScale.SettingChanged += CfgScale_SettingChanged;
			cfgTextAlignment.SettingChanged += CfgTextAlignment_SettingChanged;
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				ModSupport_RiskOfOptions.Initialize();
			}
		}

		private static void CfgTextAlignment_SettingChanged(object sender, EventArgs e)
		{
			Plugin.SetNotifAlignment();
		}

		private static void CfgScale_SettingChanged(object sender, EventArgs e)
		{
			Plugin.SetNotifScale();
		}

		private static void CfgYHeight_SettingChanged(object sender, EventArgs e)
		{
			Plugin.SetNotifPosition();
		}

		private static void CfgXHeight_SettingChanged(object sender, EventArgs e)
		{
			Plugin.SetNotifPosition();
		}
	}
	internal class ModSupport_RiskOfOptions
	{
		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void Initialize()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			ModSettingsManager.SetModDescription("Adds a persistent music notification.", "com.DestroyedClone.MusicDisplay", "Music Display");
			ModSettingsManager.AddOption((BaseOption)new IntFieldOption(ModConfig.cfgXHeight, false));
			ModSettingsManager.AddOption((BaseOption)new IntFieldOption(ModConfig.cfgYHeight, false));
			ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(ModConfig.cfgScale, false));
			ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)ModConfig.cfgTextAlignment, false));
		}
	}
	[BepInPlugin("com.DestroyedClone.MusicDisplay", "Music Display", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private class FadeOutText : MonoBehaviour
		{
			public float stopwatch = 0f;

			public float fadeDuration = 0f;

			public HGTextMeshProUGUI textMesh;

			public void Update()
			{
				stopwatch += Time.deltaTime;
				if (!(stopwatch > fadeDuration))
				{
				}
			}
		}

		public static MusicController musicController;

		public static GameObject notif;

		public static HGTextMeshProUGUI notifTextMesh;

		public static GameObject ReferenceGameObject;

		public static bool canLoad = false;

		public static string currentlyPlaying = string.Empty;

		public void Awake()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			ModConfig.Initialize(((BaseUnityPlugin)this).Config);
			MusicTrackDef.Play += new hook_Play(MusicTrackDef_Play);
			AsyncOperationHandle<GameObject> val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/UI/HGCreditNameLabel.prefab");
			val.Completed += delegate(AsyncOperationHandle<GameObject> obj)
			{
				ReferenceGameObject = obj.Result;
			};
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnLoad));
		}

		private void OnLoad()
		{
			canLoad = true;
			CreateDisplay();
		}

		private void MusicTrackDef_Play(orig_Play orig, MusicTrackDef self)
		{
			orig.Invoke(self);
			currentlyPlaying = self.cachedName;
			CreateDisplay();
		}

		private static void CreateDisplay()
		{
			if (!canLoad)
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)notif))
			{
				Canvas userCanvas = AchievementNotificationPanel.GetUserCanvas(LocalUserManager.GetFirstLocalUser());
				if (!Object.op_Implicit((Object)(object)userCanvas))
				{
					return;
				}
				notif = Object.Instantiate<GameObject>(ReferenceGameObject);
				notif.transform.parent = ((Component)userCanvas).transform;
				((Object)notif).name = "MusicNameDisplay";
			}
			notifTextMesh = notif.GetComponent<HGTextMeshProUGUI>();
			((TMP_Text)notifTextMesh).text = GetTrackInfo(currentlyPlaying);
			SetNotifAlignment();
			SetNotifPosition();
			SetNotifScale();
		}

		public static void SetNotifAlignment()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)notifTextMesh) && canLoad)
			{
				((TMP_Text)notifTextMesh).horizontalAlignment = ModConfig.cfgTextAlignment.Value;
			}
		}

		public static void SetNotifPosition()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)notif) && canLoad)
			{
				notif.transform.localPosition = new Vector3((float)ModConfig.cfgXHeight.Value, (float)ModConfig.cfgYHeight.Value);
			}
		}

		public static void SetNotifScale()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)notif) && canLoad)
			{
				notif.transform.localScale = Vector3.one * ModConfig.cfgScale.Value;
			}
		}

		public static string GetTrackInfo(string trackDefName)
		{
			if (Data.trackNames.TryGetValue(trackDefName, out var value))
			{
				if (1 == 0)
				{
				}
				string result = ((trackDefName == "muNone") ? string.Empty : ((!(trackDefName == "muSong_LemurianTemple")) ? (value + "\nChris Christodoulou") : (value + "\nStavros Markonis")));
				if (1 == 0)
				{
				}
				return result;
			}
			return trackDefName;
		}
	}
}