using System;
using System.Collections;
using System.Collections.Generic;
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.0")]
public class LoadingMusicBase : BaseUnityPlugin
{
private const string modGUID = "ZetaArcade.LoadingMusic";
private const string modName = "LoadingMusic";
private const string modVersion = "1.0.0";
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<float> MusicFadeTime;
public ConfigEntry<float> MusicVolume;
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");
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(typeof(LoadingMusicBase));
harmony.PatchAll(typeof(RoundManager));
harmony.PatchAll(typeof(RoundManagerMusicPatches));
}
}
[HarmonyPatch(typeof(RoundManager))]
public class RoundManagerMusicPatches
{
[CompilerGenerated]
private sealed class <FadeOutMusic>d__6 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public AudioSource source;
private float <originalVolume>5__1;
private float <timeElapsed>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <FadeOutMusic>d__6(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<originalVolume>5__1 = source.volume;
<timeElapsed>5__2 = 0f;
break;
case 1:
<>1__state = -1;
break;
}
if ((double)source.volume > 0.01)
{
source.volume = Mathf.Lerp(<originalVolume>5__1, 0f, <timeElapsed>5__2);
<timeElapsed>5__2 += Time.deltaTime / LoadingMusicBase.Instance.MusicFadeTime.Value;
<>2__current = null;
<>1__state = 1;
return true;
}
source.Stop();
source.volume = <originalVolume>5__1;
ThisLogger.LogDebug((object)"Music faded and stopped");
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal static AudioSource loadingAudioSource;
internal static AudioClip loadingAudioClip = null;
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();
ThisLogger.LogDebug((object)"Music triggered");
}
}
[HarmonyPatch("ResetEnemySpawningVariables")]
[HarmonyPostfix]
private static void StopWaitingMusicPatch()
{
ThisLogger.LogDebug((object)"Music fadeout triggered");
((MonoBehaviour)RoundManager.Instance).StartCoroutine(FadeOutMusic(loadingAudioSource));
}
[IteratorStateMachine(typeof(<FadeOutMusic>d__6))]
private static IEnumerator FadeOutMusic(AudioSource source)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <FadeOutMusic>d__6(0)
{
source = source
};
}
}