Decompiled source of LCPrincessPeachShowtimeSoundPackMod v1.0.0

LCPrincessPeachShowtimeSoundPackMod.dll

Decompiled 6 hours 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LCPrincessPeachShowtimeSoundPackMod")]
[assembly: AssemblyTitle("LCPrincessPeachShowtimeSoundPackMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public class Configs
		{
			public static ConfigEntry<bool> configAddOrOverwrite;

			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).");
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		public class NewStartOfRound
		{
			[HarmonyPrefix]
			public static void Prefix(StartOfRound __instance)
			{
				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);
							break;
						}
					}
				}
			}
		}

		internal static ManualLogSource Logger;

		public static AssetBundle assetBundle;

		public static bool addedMusic;

		public static Configs MyConfig { get; internal set; }

		private void Awake()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LCPrincessPeachShowtimeSoundPackMod is loaded!");
			assetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "princesspeachshowtime"));
			if ((Object)(object)assetBundle == (Object)null)
			{
				Logger.LogError((object)"Failed to load AssetBundle");
				return;
			}
			Logger.LogDebug((object)"Loaded AssetBundle");
			new Harmony("LCPrincessPeachShowtimeSoundPackMod").PatchAll();
			MyConfig = new Configs(((BaseUnityPlugin)this).Config);
			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.");
			}
		}

		public static void AddSongsToBoombox(BoomboxItem __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)assetBundle == (Object)null))
			{
				if (Configs.configAddOrOverwrite.Value)
				{
					List<AudioClip> list = __instance.musicAudios.ToList();
					list.AddRange(assetBundle.LoadAllAssets<AudioClip>());
					__instance.musicAudios = list.ToArray();
				}
				else
				{
					__instance.musicAudios = assetBundle.LoadAllAssets<AudioClip>();
				}
				addedMusic = true;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LCPrincessPeachShowtimeSoundPackMod";

		public const string PLUGIN_NAME = "LCPrincessPeachShowtimeSoundPackMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}