Decompiled source of EndTimes v1.0.0

EndTimesEscapeMusic.dll

Decompiled 3 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
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("EndTimesEscapeMusic")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EndTimesEscapeMusic")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("73169e38-3e19-473a-a571-bbacc99a6b84")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace EndTimesEscapeMusic
{
	[BepInPlugin("MagnusMakesGames.EndTimesEscapeMusic", "End Times Escape Music", "1.0")]
	public class EndTimesEscapeMusicBase : BaseUnityPlugin
	{
		private const string modGUID = "MagnusMakesGames.EndTimesEscapeMusic";

		private const string modName = "End Times Escape Music";

		private const string modVersion = "1.0";

		private readonly Harmony harmony = new Harmony("MagnusMakesGames.EndTimesEscapeMusic");

		public static EndTimesEscapeMusicBase Instance;

		internal ManualLogSource logger;

		internal static AssetBundle assetBundle;

		internal static AudioClip EndTimesTrack;

		internal static AudioClip FinalVoyageTrack;

		internal static object endTimesMusicManagerPrefab;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("MagnusMakesGames.EndTimesEscapeMusic");
			logger.LogInfo((object)"Loading End Times Escape Music Mod");
			harmony.PatchAll();
			string location = ((BaseUnityPlugin)Instance).Info.Location;
			location = location.TrimEnd("EndTimesEscapeMusic.dll".ToCharArray());
			assetBundle = AssetBundle.LoadFromFile(location + "endtimes");
			if ((Object)(object)assetBundle != (Object)null)
			{
				EndTimesTrack = assetBundle.LoadAsset<AudioClip>("end_times");
				FinalVoyageTrack = assetBundle.LoadAsset<AudioClip>("final_voyage");
				endTimesMusicManagerPrefab = assetBundle.LoadAsset("EndTimesMusicManager");
			}
		}

		public static void PlayEndTimes()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			GameObject val = null;
			if (!Object.op_Implicit((Object)(object)GameObject.Find("EndTimesEscapeMusic")))
			{
				object obj = endTimesMusicManagerPrefab;
				val = Object.Instantiate<GameObject>((GameObject)obj);
				((Object)val).name = "EndTimesEscapeMusic";
			}
			if (Object.op_Implicit((Object)(object)GameObject.Find("EndTimesEscapeMusic")))
			{
				val = GameObject.Find("EndTimesEscapeMusic");
				AudioSource component = val.GetComponent<AudioSource>();
				if (!component.isPlaying && (Object)(object)component != (Object)null)
				{
					component.clip = EndTimesTrack;
					component.Play();
				}
			}
		}
	}
}
namespace EndTimesEscapeMusic.Patches
{
	[HarmonyPatch(typeof(TimeOfDay))]
	internal class EndTimes
	{
		[HarmonyPostfix]
		[HarmonyPatch("TimeOfDayEvents")]
		private static void TimeOfDayEventsPatch()
		{
			TimeOfDay instance = TimeOfDay.Instance;
			if (instance.currentDayTime / instance.totalTime >= 0.89f && instance.currentDayTime / instance.totalTime < 0.95f)
			{
				EndTimesEscapeMusicBase.PlayEndTimes();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetShipLeaveEarlyClientRpc")]
		private static void SetShipLeaveEarlyClientRpcPatch()
		{
			EndTimesEscapeMusicBase.PlayEndTimes();
		}
	}
}