Decompiled source of RestoredLyrics v1.0.0

doomahreal.ultrakill.RestoredLyrics/RestoredLyrics.dll

Decompiled 9 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("RestoredLyrics")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RestoredLyrics")]
[assembly: AssemblyTitle("RestoredLyrics")]
[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 RestoredLyrics
{
	[BepInPlugin("doomah.ultrakill.RestoredLyrics", "Restored Lyrics", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private AudioSource audioSource;

		private bool hasPlayed = false;

		private GameObject canvas;

		private AssetBundle bundle;

		private void Start()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			UnloadAssetBundle();
		}

		private void OnDestroy()
		{
			UnloadAssetBundle();
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			Debug.Log((object)"doomah.ultrakill.RestoredLyrics is loaded!");
			hasPlayed = false;
			if (((Scene)(ref scene)).name == "7b3cb6a0a342eb54dafe5552d4820eeb")
			{
				Debug.Log((object)"Current scene is 'uk_construct'. Looking for Shop and Music directly in the root hierarchy.");
				GameObject val = GameObject.Find("Shop");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Transform val2 = val.transform.Find("Music");
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				audioSource = ((Component)val2).GetComponent<AudioSource>();
				if ((Object)(object)audioSource == (Object)null)
				{
					return;
				}
			}
			else
			{
				Debug.Log((object)"Current scene is not 'uk_construct'. Looking for FirstRoom, Room, Shop, and Music.");
				GameObject val3 = GameObject.Find("FirstRoom");
				if ((Object)(object)val3 == (Object)null)
				{
					return;
				}
				Transform val4 = val3.transform.Find("Room/Shop");
				if ((Object)(object)val4 == (Object)null)
				{
					return;
				}
				Transform val5 = val4.Find("Music");
				if ((Object)(object)val5 == (Object)null)
				{
					return;
				}
				audioSource = ((Component)val5).GetComponent<AudioSource>();
				if ((Object)(object)audioSource == (Object)null)
				{
					return;
				}
			}
			audioSource.pitch = 1f;
			audioSource.volume = 1f;
			canvas = GameObject.Find("Canvas");
			if ((Object)(object)canvas == (Object)null || !((Object)(object)bundle == (Object)null))
			{
				return;
			}
			byte[] array = LoadEmbeddedResource("RestoredLyrics.RestoredLyrics.bundle");
			if (array == null)
			{
				Debug.LogError((object)"Embedded asset bundle not found.");
				return;
			}
			bundle = AssetBundle.LoadFromMemory(array);
			if ((Object)(object)bundle == (Object)null)
			{
				Debug.LogError((object)"Failed to load embedded asset bundle.");
			}
		}

		private void Update()
		{
			if ((Object)(object)canvas != (Object)null && canvas.activeSelf)
			{
				PlayMusic();
			}
			else
			{
				PauseMusic();
			}
		}

		public void PlayMusic()
		{
			if ((Object)(object)audioSource == (Object)null)
			{
				return;
			}
			if (!hasPlayed)
			{
				AudioClip val = LoadCustomAudioClip("shopcustomlyrics.mp3");
				if ((Object)(object)val == (Object)null)
				{
					Debug.LogError((object)"Custom audio clip not found in the embedded asset bundle.");
					return;
				}
				audioSource.clip = val;
				audioSource.Play();
				hasPlayed = true;
			}
			else if (!audioSource.isPlaying)
			{
				audioSource.UnPause();
			}
		}

		public void PauseMusic()
		{
			if (!((Object)(object)audioSource == (Object)null))
			{
				audioSource.Pause();
			}
		}

		private AudioClip LoadCustomAudioClip(string clipName)
		{
			if ((Object)(object)bundle == (Object)null)
			{
				Debug.LogError((object)"Asset bundle is not loaded.");
				return null;
			}
			return bundle.LoadAsset<AudioClip>(clipName);
		}

		private byte[] LoadEmbeddedResource(string resourceName)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			using Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				Debug.LogError((object)("Failed to load embedded resource: " + resourceName));
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			return array;
		}

		private void UnloadAssetBundle()
		{
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(true);
				bundle = null;
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RestoredLyrics";

		public const string PLUGIN_NAME = "RestoredLyrics";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}