Decompiled source of LCPrincessPeachShowtimeSoundPackMod v1.1.0

LCPrincessPeachShowtimeSoundPackMod.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using STSharedAudioLib;
using UnityEngine;

[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LCPrincessPeachShowtimeSoundPackMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("LCPrincessPeachShowtimeSoundPackMod")]
[assembly: AssemblyTitle("LCPrincessPeachShowtimeSoundPackMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 LCPrincessPeachShowtimeSoundPackMod
{
	[BepInPlugin("local.SimonTendo.LCPrincessPeachShowtimeSoundPackMod", "LCPrincessPeachShowtimeSoundPackMod", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public class Configs
		{
			public static ConfigEntry<bool> configAddOrOverwrite;

			public static ConfigEntry<bool> configLoadingScreenSong;

			public Configs(ConfigFile cfg)
			{
				configAddOrOverwrite = cfg.Bind<bool>("Boombox Options", "Add Or Overwrite", true, "Choose whether the Princess Peach Showtime music is added to the total list of Boombox songs (true), or is the only music used by the Boombox (false).");
				configLoadingScreenSong = cfg.Bind<bool>("Boombox Options", "Loading Screen Song", false, "Choose whether the loading screen music that will play when entering the atmosphere will also be added to the list of Boombox songs (true), or if it will only be available through LCSimonTendoPlaylistsMod (false).");
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		public class NewStartOfRound
		{
			[HarmonyPrefix]
			public static void Prefix(StartOfRound __instance)
			{
				AssetBundle val = null;
				if (ShouldLoadAssetBundle())
				{
					val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "princesspeachshowtime"));
					if ((Object)(object)val == (Object)null)
					{
						Logger.LogError((object)"Failed to load AssetBundle");
						return;
					}
					if ((Object)(object)loadingScreenClip == (Object)null)
					{
						loadingScreenClip = val.LoadAsset<AudioClip>("Assets/Soon the Curtains Will Rise.ogg");
						if ((Object)(object)loadingScreenClip == (Object)null)
						{
							Logger.LogWarning((object)"Failed to load LCSimonTendoPlaylistsMod Loading Screen Music");
						}
					}
				}
				if (playlistCompatible)
				{
					AddLoadingScreenMusic();
				}
				if (addedMusic)
				{
					return;
				}
				foreach (Item items in __instance.allItemsList.itemsList)
				{
					if (((Object)items).name == "Boombox")
					{
						BoomboxItem component = items.spawnPrefab.GetComponent<BoomboxItem>();
						if ((Object)(object)component != (Object)null)
						{
							AddSongsToBoombox(component, val);
							break;
						}
					}
				}
			}
		}

		internal static ManualLogSource Logger;

		public static bool addedMusic;

		public static bool playlistCompatible;

		public static AudioClip loadingScreenClip;

		public static Configs MyConfig { get; internal set; }

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LCPrincessPeachShowtimeSoundPackMod is loaded!");
			new Harmony("LCPrincessPeachShowtimeSoundPackMod").PatchAll();
			MyConfig = new Configs(((BaseUnityPlugin)this).Config);
			playlistCompatible = CheckForPlugin("LCSimonTendoPlaylistsMod");
			DisplayConfigs();
		}

		private static void DisplayConfigs()
		{
			if (Configs.configAddOrOverwrite.Value)
			{
				Logger.LogInfo((object)"Config [Add Or Overwrite] is set to TRUE. Princess Peach Showtime songs will be added to the total list of songs.");
			}
			else
			{
				Logger.LogInfo((object)"Config [Add Or Overwrite] is set to FALSE. Princess Peach Showtime songs will try to be the only songs in the playlist.");
			}
			if (Configs.configLoadingScreenSong.Value)
			{
				Logger.LogInfo((object)"Config [Loading Screen Song] is set to TRUE. The song \"Soon the Curtains Will Rise\" will be added to the list of boombox songs.");
			}
			else
			{
				Logger.LogInfo((object)"Config [Loading Screen Song] is set to FALSE. The song \"Soon the Curtains Will Rise\" will only be used when loading into a level with LCSimonTendoPlaylistsMod installed.");
			}
		}

		private static void AddSongsToBoombox(BoomboxItem __instance, AssetBundle assetBundle)
		{
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)assetBundle == (Object)null))
			{
				AudioClip[] allBoomboxSongs = GetAllBoomboxSongs(assetBundle);
				if (Configs.configAddOrOverwrite.Value)
				{
					List<AudioClip> list = __instance.musicAudios.ToList();
					list.AddRange(allBoomboxSongs);
					__instance.musicAudios = list.ToArray();
				}
				else
				{
					__instance.musicAudios = allBoomboxSongs;
				}
				addedMusic = true;
			}
		}

		private static AudioClip[] GetAllBoomboxSongs(AssetBundle assetBundle)
		{
			if ((Object)(object)assetBundle == (Object)null)
			{
				return null;
			}
			List<AudioClip> list = assetBundle.LoadAllAssets<AudioClip>().ToList();
			if (list == null || list.Count == 0)
			{
				return null;
			}
			if (!Configs.configLoadingScreenSong.Value && (Object)(object)loadingScreenClip != (Object)null && list.Contains(loadingScreenClip))
			{
				list.Remove(loadingScreenClip);
			}
			return list.ToArray();
		}

		private static bool ShouldLoadAssetBundle()
		{
			if (!addedMusic)
			{
				return true;
			}
			if (playlistCompatible && (Object)(object)loadingScreenClip == (Object)null)
			{
				return true;
			}
			return false;
		}

		private static void AddLoadingScreenMusic()
		{
			if (!((Object)(object)loadingScreenClip == (Object)null))
			{
				SharedAudioComponent genericPlaylistsContainer = GetGenericPlaylistsContainer();
				if ((Object)(object)genericPlaylistsContainer != (Object)null)
				{
					SharedAudioMethods.AudioClipAddNew(loadingScreenClip, SharedAudioMethods.AudioListGetByName("LCSimonTendoPlaylistsMod - Loading Screen", genericPlaylistsContainer, false, true), true, 333, false);
				}
			}
		}

		private static SharedAudioComponent GetGenericPlaylistsContainer()
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return null;
			}
			Transform val = ((Component)StartOfRound.Instance).transform.parent.Find("SimonTendoManagers");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogWarning((object)"failed to find: SimonTendoManagers");
				return null;
			}
			Transform val2 = val.Find("LCSimonTendoPlaylistsMod");
			if ((Object)(object)val2 == (Object)null)
			{
				Logger.LogWarning((object)"failed to find: LCSimonTendoPlaylistsMod");
				return null;
			}
			SharedAudioComponent component = ((Component)val2).GetComponent<SharedAudioComponent>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogError((object)"failed to find: SharedAudioComponent");
			}
			return component;
		}

		private static bool CheckForPlugin(string pluginName, bool printDebug = true, bool printNames = false)
		{
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				string name = value.Metadata.Name;
				if (printNames)
				{
					Logger.LogDebug((object)("* (" + name + ")"));
				}
				if (name == pluginName)
				{
					if (printDebug)
					{
						Logger.LogDebug((object)("Successfully found " + pluginName));
					}
					return true;
				}
			}
			if (printDebug)
			{
				Logger.LogDebug((object)("Failed to find " + pluginName));
			}
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LCPrincessPeachShowtimeSoundPackMod";

		public const string PLUGIN_NAME = "LCPrincessPeachShowtimeSoundPackMod";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}