Decompiled source of LCTokyoMirageSessionsSoundPackMod v1.0.2

LCTokyoMirageSessionsSoundPackMod.dll

Decompiled 2 months 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 HarmonyLib.Tools;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LCTokyoMirageSessionsSoundPackMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Add 40 songs from Tokyo Mirage Sessions #FE to the Boombox!")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("LCTokyoMirageSessionsSoundPackMod")]
[assembly: AssemblyTitle("LCTokyoMirageSessionsSoundPackMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 LCTokyoMirageSessionsSoundPackMod
{
	[BepInPlugin("LCTokyoMirageSessionsSoundPackMod", "LCTokyoMirageSessionsSoundPackMod", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public class Configs
		{
			public static ConfigEntry<bool> configConcertSongs;

			public static ConfigEntry<bool> configGameplaySongs;

			public static ConfigEntry<bool> configAddOrOverwrite;

			public Configs(ConfigFile cfg)
			{
				configAddOrOverwrite = cfg.Bind<bool>("Boombox Options", "Add Or Overwrite", true, "Choose whether the Tokyo Mirage Sessions music is added to the total list of Boombox songs (true), or is the only music used by the Boombox (false).");
				configConcertSongs = cfg.Bind<bool>("Customization", "Concert Songs", true, "Select if full vocal songs will be loaded.");
				configGameplaySongs = cfg.Bind<bool>("Customization", "Gameplay Songs", true, "Select if regular gameplay songs will be loaded.");
			}
		}

		internal static ManualLogSource Logger;

		public static AssetBundle TMSConcertAssetBundle;

		public static AssetBundle TMSGameplayAssetBundle;

		public static bool addedMusic;

		public static Configs MyConfig { get; internal set; }

		private void Awake()
		{
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LCTokyoMirageSessionsSoundPackMod is loaded!");
			MyConfig = new Configs(((BaseUnityPlugin)this).Config);
			if (!Configs.configConcertSongs.Value && !Configs.configGameplaySongs.Value)
			{
				Logger.LogWarning((object)"Both Config [Concert Songs] or [Gameplay Songs] are set to FALSE. No Tokyo Mirage Sessions music will be loaded.");
				return;
			}
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (Configs.configConcertSongs.Value)
			{
				Logger.LogInfo((object)"Config [Concert Songs] is set to TRUE. Loading concert songs...");
				TMSConcertAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "tmsconcertsongassetbundle"));
				if ((Object)(object)TMSConcertAssetBundle == (Object)null)
				{
					Logger.LogError((object)"Failed to load Concert Song asset bundle");
				}
				else
				{
					Logger.LogDebug((object)"Loaded Concert Song asset bundle");
				}
			}
			else
			{
				Logger.LogInfo((object)"Config [Concert Songs] is set to FALSE. Concert songs will not be loaded.");
			}
			if (Configs.configGameplaySongs.Value)
			{
				Logger.LogInfo((object)"Config [Gameplay Songs] is set to TRUE. Loading gameplay songs...");
				TMSGameplayAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "tmsgameplaysongassetbundle"));
				if ((Object)(object)TMSGameplayAssetBundle == (Object)null)
				{
					Logger.LogError((object)"Failed to load Gameplay Song asset bundle");
				}
				else
				{
					Logger.LogDebug((object)"Loaded Gameplay Song asset bundle");
				}
			}
			else
			{
				Logger.LogInfo((object)"Config [Gameplay Songs] is set to FALSE. Gameplay songs will not be loaded.");
			}
			if ((Object)(object)TMSConcertAssetBundle == (Object)null && (Object)(object)TMSGameplayAssetBundle == (Object)null)
			{
				Logger.LogError((object)"Failed to load any Concert Song and/or Gameplay Song asset bundle. No Tokyo Mirage Sessions music will be loaded.");
				return;
			}
			new Harmony("LCTokyoMirageSessionsSoundPackMod").PatchAll();
			HarmonyFileLog.Enabled = false;
			if (Configs.configAddOrOverwrite.Value)
			{
				Logger.LogInfo((object)"Config [Add Or Overwrite] is set to TRUE. Tokyo Mirage Sessions songs will be added to the total list of songs.");
			}
			else
			{
				Logger.LogInfo((object)"Config [Add Or Overwrite] is set to FALSE. Tokyo Mirage Sessions songs will try to be the only songs in the playlist.");
			}
		}

		public static void AddSongsToBoombox(BoomboxItem __instance)
		{
			List<AudioClip> list = new List<AudioClip>();
			if (Configs.configAddOrOverwrite.Value)
			{
				list = __instance.musicAudios.ToList();
			}
			if ((Object)(object)TMSConcertAssetBundle != (Object)null)
			{
				list.AddRange(TMSConcertAssetBundle.LoadAllAssets<AudioClip>());
			}
			if ((Object)(object)TMSGameplayAssetBundle != (Object)null)
			{
				list.AddRange(TMSGameplayAssetBundle.LoadAllAssets<AudioClip>());
			}
			__instance.musicAudios = list.ToArray();
			addedMusic = true;
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	public class NewStartOfRound
	{
		[HarmonyPrefix]
		public static void Prefix(StartOfRound __instance)
		{
			if (Plugin.addedMusic || (Object)(object)__instance == (Object)null || (Object)(object)__instance.allItemsList == (Object)null || __instance.allItemsList.itemsList == null)
			{
				return;
			}
			foreach (Item items in __instance.allItemsList.itemsList)
			{
				if ((Object)(object)items != (Object)null && ((Object)items).name == "Boombox" && (Object)(object)items.spawnPrefab != (Object)null)
				{
					BoomboxItem component = items.spawnPrefab.GetComponent<BoomboxItem>();
					if ((Object)(object)component != (Object)null)
					{
						Plugin.AddSongsToBoombox(component);
						break;
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LCTokyoMirageSessionsSoundPackMod";

		public const string PLUGIN_NAME = "LCTokyoMirageSessionsSoundPackMod";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}