Decompiled source of LoadingMusic v1.0.1

LoadingMusic.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LoadingMusic")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoadingMusic")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("85a1a463-8a4d-4d58-b958-04333df36a3d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LoadingMusic;

[BepInPlugin("ZetaArcade.LoadingMusic", "LoadingMusic", "1.0.1")]
public class LoadingMusicBase : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("ZetaArcade.LoadingMusic");

	public static ManualLogSource ThisLogger;

	public static LoadingMusicBase Instance;

	public ConfigEntry<bool> ToggleLoadingMusic;

	public ConfigEntry<bool> ToggleLoadingMusicLoop;

	public ConfigEntry<bool> ToggleCruiserMute;

	public ConfigEntry<float> MusicFadeTime;

	public ConfigEntry<float> MusicVolume;

	public bool IsMusicPlaying { get; set; } = false;

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		ToggleLoadingMusic = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading Music Settings", "Should loading music play", true, "Toggles the loading music in the ship");
		ToggleLoadingMusicLoop = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading Music Settings", "Should loading music loop", true, "When enabled, the loading music will loop until it fades out rather than ending early");
		ToggleCruiserMute = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading Music Settings", "Mute Cruiser Radio", true, "When enabled, the Cruiser's Radio will be muted anytime the Loading Music is playing. This is useful for preventing the Radio overlapping with the Loading Music.");
		MusicFadeTime = ((BaseUnityPlugin)this).Config.Bind<float>("Loading Music Settings", "Loading music fade time", 15f, "How long it should take for the music to fade out");
		MusicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Loading Music Settings", "Loading music volume", 0.75f, "The volume of the loading music");
		ThisLogger = ((BaseUnityPlugin)this).Logger;
		ThisLogger.LogInfo((object)"Plugin is loaded!");
		harmony.PatchAll();
		IsMusicPlaying = false;
	}
}
[HarmonyPatch(typeof(RoundManager))]
public class RoundManagerMusicPatches
{
	internal static AudioSource loadingAudioSource;

	internal static AudioClip loadingAudioClip = null;

	public static VehicleController Cruiser;

	public static ManualLogSource ThisLogger = LoadingMusicBase.ThisLogger;

	[HarmonyPatch("Awake")]
	[HarmonyPrefix]
	private static void CreateAudioSource()
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Invalid comparison between Unknown and I4
		ThisLogger.LogDebug((object)"Audio source being created");
		if ((Object)(object)loadingAudioSource != (Object)null)
		{
			Object.Destroy((Object)(object)loadingAudioSource);
		}
		if ((Object)(object)loadingAudioClip == (Object)null)
		{
			loadingAudioClip = Resources.FindObjectsOfTypeAll(typeof(AudioClip)).Cast<AudioClip>().FirstOrDefault((Func<AudioClip, bool>)((AudioClip a) => ((Object)a).name == "ElevatorJingle"));
		}
		if ((Object)(object)loadingAudioClip == (Object)null)
		{
			ThisLogger.LogDebug((object)"Unable to find elevator jingle");
		}
		if ((int)loadingAudioClip.loadState != 2)
		{
			loadingAudioClip.LoadAudioData();
		}
		loadingAudioSource = Object.Instantiate<AudioSource>(StartOfRound.Instance.speakerAudioSource);
		((Object)loadingAudioSource).name = "LoadingMusic";
		loadingAudioSource.clip = Object.Instantiate<AudioClip>(loadingAudioClip);
		((Object)loadingAudioSource.clip).name = ((Object)loadingAudioSource).name;
		((Component)loadingAudioSource).transform.parent = ((Component)StartOfRound.Instance.speakerAudioSource).transform;
	}

	[HarmonyPatch("GenerateNewLevelClientRpc")]
	[HarmonyPrefix]
	private static void PlayWaitingMusicPatch()
	{
		ThisLogger.LogDebug((object)"PlayWaitingMusicPatch is running");
		if (LoadingMusicBase.Instance.ToggleLoadingMusic.Value)
		{
			loadingAudioSource.loop = LoadingMusicBase.Instance.ToggleLoadingMusicLoop.Value;
			loadingAudioSource.volume = LoadingMusicBase.Instance.MusicVolume.Value;
			loadingAudioSource.Play();
			LoadingMusicBase.Instance.IsMusicPlaying = true;
			if ((Object)(object)Cruiser == (Object)null && LoadingMusicBase.Instance.ToggleCruiserMute.Value)
			{
				Cruiser = Object.FindFirstObjectByType<VehicleController>();
			}
			if ((Object)(object)Cruiser != (Object)null && LoadingMusicBase.Instance.ToggleCruiserMute.Value)
			{
				Cruiser.radioAudio.mute = true;
				Cruiser.radioInterference.mute = true;
			}
			ThisLogger.LogDebug((object)"Music triggered");
		}
	}

	[HarmonyPatch("ResetEnemySpawningVariables")]
	[HarmonyPostfix]
	private static void StopWaitingMusicPatch()
	{
		ThisLogger.LogDebug((object)"Music fadeout triggered");
		((MonoBehaviour)RoundManager.Instance).StartCoroutine(FadeOutMusic(loadingAudioSource));
	}

	private static IEnumerator FadeOutMusic(AudioSource source)
	{
		float originalVolume = source.volume;
		float timeElapsed = 0f;
		while ((double)source.volume > 0.01)
		{
			LoadingMusicBase.Instance.IsMusicPlaying = true;
			source.volume = Mathf.Lerp(originalVolume, 0f, timeElapsed);
			timeElapsed += Time.deltaTime / LoadingMusicBase.Instance.MusicFadeTime.Value;
			yield return null;
		}
		source.Stop();
		source.volume = originalVolume;
		ThisLogger.LogDebug((object)"Music faded and stopped");
		LoadingMusicBase.Instance.IsMusicPlaying = false;
		if ((Object)(object)Cruiser != (Object)null && LoadingMusicBase.Instance.ToggleCruiserMute.Value)
		{
			Cruiser.radioAudio.mute = false;
			Cruiser.radioInterference.mute = false;
		}
	}
}
[HarmonyPatch(typeof(VehicleController))]
internal class VehicleControllerPatch
{
	[HarmonyPostfix]
	[HarmonyPriority(0)]
	[HarmonyPatch("LateUpdate")]
	private static void MuteOnUpdateIfMusicPlaying(VehicleController __instance)
	{
		if (LoadingMusicBase.Instance.IsMusicPlaying && LoadingMusicBase.Instance.ToggleCruiserMute.Value)
		{
			__instance.radioAudio.mute = true;
			__instance.radioInterference.mute = true;
		}
	}
}
public static class PluginInfo
{
	public const string modGUID = "ZetaArcade.LoadingMusic";

	public const string modName = "LoadingMusic";

	public const string modVersion = "1.0.1";
}