Decompiled source of LCTokyoMirageSessionsSoundPackMod v1.0.1

LCTokyoMirageSessionsSoundPackMod.dll

Decompiled 3 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.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("LCTokyoMirageSessionsSoundPackMod")]
[assembly: AssemblyTitle("LCTokyoMirageSessionsSoundPackMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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.1")]
	public class Plugin : BaseUnityPlugin
	{
		public class Config
		{
			public static ConfigEntry<bool> configConcertSongs;

			public static ConfigEntry<bool> configGameplaySongs;

			public static ConfigEntry<bool> configAddOrOverwrite;

			public Config(ConfigFile cfg)
			{
				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.");
				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).");
			}
		}

		public static Plugin instance;

		internal static ManualLogSource Logger;

		public static AssetBundle TMSConcertAssetBundle;

		public static AssetBundle TMSGameplayAssetBundle;

		public static AudioClip[] ConcertSongs;

		public static AudioClip[] GameplaySongs;

		public static string sAssemblyLocation;

		public static bool AddSongs = true;

		public static Config MyConfig { get; internal set; }

		private void Awake()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LCTokyoMirageSessionsSoundPackMod is loaded!");
			Harmony val = new Harmony("LCTokyoMirageSessionsSoundPackMod");
			val.PatchAll();
			HarmonyFileLog.Enabled = false;
			MyConfig = new Config(((BaseUnityPlugin)this).Config);
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (!Config.configConcertSongs.Value && !Config.configGameplaySongs.Value)
			{
				Logger.LogWarning((object)"Both Config [Concert Songs] or [Gameplay Songs] are set to FALSE. No Tokyo Mirage Sessions music will be loaded.");
				AddSongs = false;
				return;
			}
			if (Config.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.LogInfo((object)"Loaded Concert Song asset bundle");
					LoadConcertSongs();
				}
			}
			else
			{
				Logger.LogInfo((object)"Config [Concert Songs] is set to FALSE. Concert songs will not be loaded.");
			}
			if (Config.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.LogInfo((object)"Loaded Gameplay Song asset bundle");
					LoadGameplaySongs();
				}
			}
			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.");
				AddSongs = false;
			}
			else if (Config.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 LoadConcertSongs()
		{
			ConcertSongs = TMSConcertAssetBundle.LoadAllAssets<AudioClip>();
		}

		public static void LoadGameplaySongs()
		{
			GameplaySongs = TMSGameplayAssetBundle.LoadAllAssets<AudioClip>();
		}

		public static void AddSongsToBoombox(BoomboxItem __instance)
		{
			if (!AddSongs)
			{
				return;
			}
			if (Config.configAddOrOverwrite.Value)
			{
				List<AudioClip> list = __instance.musicAudios.ToList();
				if (ConcertSongs != null)
				{
					list.AddRange(ConcertSongs);
				}
				if (GameplaySongs != null)
				{
					list.AddRange(GameplaySongs);
				}
				__instance.musicAudios = list.ToArray();
			}
			else if (!Config.configAddOrOverwrite.Value)
			{
				List<AudioClip> list2 = new List<AudioClip>();
				if (ConcertSongs != null)
				{
					list2.AddRange(ConcertSongs);
				}
				if (GameplaySongs != null)
				{
					list2.AddRange(GameplaySongs);
				}
				__instance.musicAudios = list2.ToArray();
			}
			__instance.musicRandomizer = new Random(GetRandomSeed());
		}

		public static int GetRandomSeed()
		{
			int num = Random.Range(0, 10);
			int num2 = Random.Range(0, 10);
			int num3 = Random.Range(0, 10);
			int num4 = Random.Range(0, 10);
			int num5 = Random.Range(0, 10);
			string s = num.ToString() + num2 + num3 + num4 + num5;
			return int.Parse(s);
		}
	}
	[HarmonyPatch(typeof(BoomboxItem), "Start")]
	public class NewBoomboxStart
	{
		[HarmonyPostfix]
		public static void Postfix(BoomboxItem __instance)
		{
			Plugin.AddSongsToBoombox(__instance);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LCTokyoMirageSessionsSoundPackMod";

		public const string PLUGIN_NAME = "LCTokyoMirageSessionsSoundPackMod";

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