using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LCSoundTool;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EverlongEscapeMusic")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EverlongEscapeMusic")]
[assembly: AssemblyTitle("EverlongEscapeMusic")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
public class EverlongEscapeMusicManager : MonoBehaviour
{
[CompilerGenerated]
private sealed class <LoadSoundWhenReady>d__8 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public EverlongEscapeMusicManager <>4__this;
private AudioClip <clip>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadSoundWhenReady>d__8(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<clip>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Expected O, but got Unknown
int num = <>1__state;
EverlongEscapeMusicManager everlongEscapeMusicManager = <>4__this;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
goto IL_008d;
}
<>1__state = -1;
Debug.Log((object)"----------------------------------------------------");
Debug.Log((object)"Loading EverlongEscapeMusic music...");
<clip>5__2 = null;
goto IL_00be;
IL_008d:
everlongEscapeMusicManager.everlongMusic = <clip>5__2;
everlongEscapeMusicManager.musicSource.clip = everlongEscapeMusicManager.everlongMusic;
Debug.Log((object)"EverlongEscapeMusic audio file loaded!");
Debug.Log((object)"----------------------------------------------------");
goto IL_00be;
IL_00be:
if ((Object)(object)<clip>5__2 == (Object)null)
{
try
{
<clip>5__2 = SoundTool.GetAudioClip("ZodiacGSK-EverlongEscapeMusic", "Sounds", everlongEscapeMusicManager.musicName);
}
catch
{
}
if ((Object)(object)<clip>5__2 == (Object)null)
{
<>2__current = (object)new WaitForSeconds(0.5f);
<>1__state = 1;
return true;
}
goto IL_008d;
}
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();
}
}
public AudioClip everlongMusic;
public AudioSource musicSource;
private bool musicPlayed;
private bool musicTransition;
public float musicVolume = 0.6f;
public float musicOffset = -12f;
public string musicName = "Everlong.ogg";
private float musicTransitionValue = 1f;
[IteratorStateMachine(typeof(<LoadSoundWhenReady>d__8))]
private IEnumerator LoadSoundWhenReady()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadSoundWhenReady>d__8(0)
{
<>4__this = this
};
}
private void Awake()
{
musicSource = ((Component)this).gameObject.AddComponent<AudioSource>();
musicSource.loop = false;
musicSource.playOnAwake = false;
musicSource.volume = musicVolume;
musicSource.spatialBlend = 0f;
musicSource.Stop();
((MonoBehaviour)this).StartCoroutine(LoadSoundWhenReady());
}
private void Update()
{
if ((Object)(object)TimeOfDay.Instance != (Object)null && TimeOfDay.Instance.currentLevel.planetHasTime && !StartOfRound.Instance.shipIsLeaving && (TimeOfDay.Instance.currentDayTime + Mathf.Sign(musicOffset) * (musicOffset * TimeOfDay.Instance.globalTimeSpeedMultiplier)) / TimeOfDay.Instance.totalTime > 0.9f && !TimeOfDay.Instance.shipLeavingAlertCalled)
{
PlayMusic();
}
if (!musicTransition && StartOfRound.Instance.shipIsLeaving)
{
musicTransition = true;
}
if (musicTransition)
{
musicSource.volume = Mathf.Lerp(0f, musicVolume, musicTransitionValue);
musicTransitionValue -= 0.1f * Time.deltaTime;
}
if (StartOfRound.Instance.inShipPhase)
{
musicPlayed = false;
musicTransition = false;
musicTransitionValue = 1f;
musicSource.Stop();
musicSource.volume = musicVolume;
}
}
private void PlayMusic()
{
if ((Object)(object)everlongMusic != (Object)null && (Object)(object)musicSource != (Object)null && !musicPlayed)
{
Debug.Log((object)("Starting " + musicName));
musicTransitionValue = 1f;
musicSource.volume = musicVolume;
musicSource.Stop();
musicSource.Play();
musicPlayed = true;
}
}
}
[BepInPlugin("com.ZodiacGSK.EverlongEscapeMusic", "EverlongEscapeMusic", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(StartOfRound), "Start")]
public static class StartPatch
{
private static bool Prefix(StartOfRound __instance)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
if ((Object)(object)GameObject.Find("EverlongEscapeMusicPlayer") == (Object)null)
{
GameObject val = new GameObject("EverlongEscapeMusicPlayer");
Object.DontDestroyOnLoad((Object)val);
EverlongEscapeMusicManager everlongEscapeMusicManager = val.AddComponent<EverlongEscapeMusicManager>();
everlongEscapeMusicManager.musicVolume = MusicVolume.Value / 100f;
everlongEscapeMusicManager.musicName = MusicPath.Value;
everlongEscapeMusicManager.musicOffset = MusicOffset.Value;
MyLogger.LogInfo((object)"EverlongMusicEscapeManager instantiated (config enabled).");
}
return true;
}
}
public static ManualLogSource MyLogger;
public static ConfigEntry<float> MusicVolume { get; private set; }
public static ConfigEntry<float> MusicOffset { get; private set; }
public static ConfigEntry<string> MusicPath { get; private set; }
private void Awake()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
MyLogger = ((BaseUnityPlugin)this).Logger;
MusicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MusicVolume", 60f, new ConfigDescription("Volume of the custom music.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
MusicOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Advanced", "MusicOffset", -12f, new ConfigDescription("Delay (in seconds) before the music start playing, in sync with the ship alert so try using the beat drop if custom music.", (AcceptableValueBase)null, Array.Empty<object>()));
MusicPath = ((BaseUnityPlugin)this).Config.Bind<string>("Advanced", "MusicName", "Everlong.ogg", new ConfigDescription("name of the music file in /Sounds/.", (AcceptableValueBase)null, Array.Empty<object>()));
new Harmony("com.ZodiacGSK.EverlongEscapeMusic").PatchAll();
MyLogger.LogInfo((object)"EverlongEscapeMusic loaded ! 1.1.0");
}
}