Decompiled source of LCMySimsSoundPackMod v1.3.0

LCMySimsSoundPackMod.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
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("LCMySimsSoundPackMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Add 200 songs from the MySims franchise to the Boombox!")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0")]
[assembly: AssemblyProduct("LCMySimsSoundPackMod")]
[assembly: AssemblyTitle("LCMySimsSoundPackMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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 LCMySimsSoundPackMod
{
	public class Configs
	{
		private static ManualLogSource Logger;

		public static ConfigEntry<bool> optionsAddOrOverwrite;

		public static ConfigEntry<bool> optionsPerformanceMode;

		public static ConfigEntry<string> customizationSelectedGames;

		public static ConfigEntry<string> customizationSelectedGenres;

		public static ConfigEntry<bool> secretOldPhone;

		public static ConfigEntry<bool> secretRecordPlayer;

		public static ConfigEntry<bool> secretLoadingScreen;

		public static ConfigEntry<bool> secretToyRobot;

		public static ConfigEntry<bool> secretJackOLantern;

		public static ConfigEntry<bool> secretDiscoBallMusic;

		public Configs(ConfigFile cfg)
		{
			optionsAddOrOverwrite = cfg.Bind<bool>("Boombox Options", "Add Or Overwrite", true, "Choose whether the MySims music is added to the total list of Boombox songs (true), or is the only music used by the Boombox (false).");
			optionsPerformanceMode = cfg.Bind<bool>("Boombox Options", "Prioritize Selected Games", true, "If [Selected Games] is not All, choose whether the MySims music added to the boombox only loads songs if the selected game is the song's first appearance to save performance (true), or loads all songs to include songs that got recycled in later games (false). ");
			customizationSelectedGames = cfg.Bind<string>("Customization", "Selected Games", "All", "Select which games' music will be played. Options: All, None, MySims, Kingdom, Party, Racing, Agents, SkyHeroes. When selecting multiple, make sure to split them up! (For example: Agents Party MySims)");
			customizationSelectedGenres = cfg.Bind<string>("Customization", "Selected Genres", "All", "Select what genres music will be played. Options: All, None, Fun, Cutesy, Exotic, Mellow, Rock, Spooky, Bigband, DJ. When selecting multiple, make sure to split them up! (For example: Fun DJ Spooky)");
			secretOldPhone = cfg.Bind<bool>("Secret", "Replace Old Phone", false, "Want to replace the sounds of the Old Phone? Options: true, false. (true = yes | false = no)");
			secretRecordPlayer = cfg.Bind<bool>("Secret", "Replace Record Player", false, "Want to replace the sound of the Record Player? Options: true, false. (true = yes | false = no)");
			secretLoadingScreen = cfg.Bind<bool>("Secret", "Replace Loading Screen", false, "Want to replace the sound of the loading screen? Options: true, false. (true = yes | false = no)");
			secretToyRobot = cfg.Bind<bool>("Secret", "Replace Toy Robot", false, "Want to replace the sound of the Toy Robot? Options: true, false. (true = yes | false = no)");
			secretJackOLantern = cfg.Bind<bool>("Secret", "Replace Jack O Lantern", false, "Want to replace the sound of the Jack O Lantern? Options: true, false. (true = yes | false = no)");
			secretDiscoBallMusic = cfg.Bind<bool>("Secret", "Replace Disco Ball", false, "Want to replace the sound of the Disco Ball? Options: true, false. (true = yes | false = no)");
		}

		public static void DisplayConfigs()
		{
			Logger = Plugin.Logger;
			if (optionsAddOrOverwrite.Value)
			{
				Logger.LogInfo((object)"Config [Add Or Overwrite] is set to TRUE. MySims songs will be added to the total list of songs.");
			}
			else
			{
				Logger.LogInfo((object)"Config [Add Or Overwrite] is set to FALSE. MySims songs will try to be the only songs in the playlist.");
			}
			if (optionsPerformanceMode.Value)
			{
				Logger.LogInfo((object)"Config [Prioritize Selected Games] is set to TRUE. MySims songs will try to save performance by only loading songs explicitly selected in [Selected Games].");
			}
			else
			{
				Logger.LogInfo((object)"Config [Prioritize Selected Games] is set to FALSE. All MySims songs will be loaded from memory, regardless of [Selected Games]'s selection.");
			}
			Logger.LogInfo((object)("Config [Selected Games] received input: " + customizationSelectedGames.Value));
			Logger.LogInfo((object)("Config [Selected Genres] received input: " + customizationSelectedGenres.Value));
			if (secretOldPhone.Value)
			{
				Logger.LogDebug((object)"Config [Replace Old Phone] is set to TRUE.");
			}
			if (secretRecordPlayer.Value)
			{
				Logger.LogDebug((object)"Config [Replace Record Player] is set to TRUE.");
			}
			if (secretLoadingScreen.Value)
			{
				Logger.LogDebug((object)"Config [Replace Loading Screen] is set to TRUE.");
			}
			if (secretToyRobot.Value)
			{
				Logger.LogDebug((object)"Config [Replace Toy Robot] is set to TRUE.");
			}
			if (secretJackOLantern.Value)
			{
				Logger.LogDebug((object)"Config [Replace Jack O Lantern] is set to TRUE.");
			}
			if (secretDiscoBallMusic.Value)
			{
				Logger.LogDebug((object)"Config [Replace Disco Ball] is set to TRUE.");
			}
		}
	}
	internal class HarmonyPatches
	{
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		public class NewStartOfRoundStart
		{
			[HarmonyPrefix]
			public static void SetUpOnRoundStart(StartOfRound __instance)
			{
				if (Logger == null)
				{
					Logger = Plugin.Logger;
				}
				if (!alreadyAddedToOrigin)
				{
					alreadyAddedToOrigin = true;
					foreach (Item items in __instance.allItemsList.itemsList)
					{
						if (((Object)items).name == "Boombox")
						{
							BoomboxItem component = items.spawnPrefab.GetComponent<BoomboxItem>();
							if ((Object)(object)component != (Object)null)
							{
								Plugin.SetBoomboxOnStart(component);
							}
						}
						if (Plugin.LCSimonTendoPlaylistsModCompatible && ((Object)items).name == "Phone" && Configs.secretOldPhone.Value && Plugin.PhoneSounds != null)
						{
							PlaylistsModCompatibility.OldPhone(items.spawnPrefab);
						}
						if (((Object)items).name == "RobotToy" && Configs.secretToyRobot.Value && (Object)(object)Plugin.ToyRobotSound != (Object)null)
						{
							if (Plugin.LCSimonTendoPlaylistsModCompatible)
							{
								PlaylistsModCompatibility.ToyRobot(items.spawnPrefab);
							}
							else
							{
								items.spawnPrefab.GetComponent<AnimatedItem>().grabAudio = Plugin.ToyRobotSound;
							}
						}
					}
					foreach (UnlockableItem unlockable in __instance.unlockablesList.unlockables)
					{
						if (unlockable.unlockableName == "Record player" && Configs.secretRecordPlayer.Value && (Object)(object)Plugin.RecordPlayerSound != (Object)null)
						{
							if (Plugin.LCSimonTendoPlaylistsModCompatible)
							{
								PlaylistsModCompatibility.RecordPlayer(unlockable.prefabObject);
							}
							else
							{
								((Component)unlockable.prefabObject.transform.GetChild(3)).GetComponent<AnimatedObjectTrigger>().playWhileTrue = Plugin.RecordPlayerSound;
							}
						}
						if (Plugin.LCSimonTendoPlaylistsModCompatible && unlockable.unlockableName == "Disco Ball" && Configs.secretDiscoBallMusic.Value && Plugin.DiscoBallSounds != null)
						{
							PlaylistsModCompatibility.DiscoBall(unlockable.prefabObject);
						}
						if (unlockable.unlockableName == "JackOLantern" && Configs.secretJackOLantern.Value && Plugin.PumpkinSounds != null)
						{
							if (Plugin.LCSimonTendoPlaylistsModCompatible)
							{
								PlaylistsModCompatibility.Pumpkin(unlockable.prefabObject);
							}
							else
							{
								((Component)unlockable.prefabObject.transform.GetChild(2)).GetComponent<AnimatedObjectTrigger>().boolFalseAudios = Plugin.PumpkinSounds;
							}
						}
					}
				}
				if (!Configs.secretLoadingScreen.Value)
				{
					return;
				}
				if (!Plugin.LCSimonTendoPlaylistsModCompatible)
				{
					if ((Object)(object)Plugin.managerPrefab != (Object)null)
					{
						GameObject val = Plugin.SearchForObject("SimonTendoManagers", ((Component)__instance).transform.parent);
						GameObject val2 = Object.Instantiate<GameObject>(Plugin.managerPrefab, val.transform);
						((Object)val2).name = "LCMySimsSoundPackMod";
						val2.AddComponent<MySimsBehaviour>();
					}
				}
				else
				{
					PlaylistsModCompatibility.LoadingScreen();
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "SceneManager_OnLoad")]
		public class NewStartOfRoundSceneManagerOnLoad
		{
			[HarmonyPrefix]
			public static void StartLoadingScreenMusic()
			{
				if ((Object)(object)MySimsBehaviour.Instance != (Object)null && Configs.secretLoadingScreen.Value && !Plugin.LCSimonTendoPlaylistsModCompatible)
				{
					MySimsBehaviour.Instance.StartLoadingMusic();
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
		public class NewRoundManagerFinishGeneratingNewLevelClientRpc
		{
			[HarmonyPostfix]
			public static void StopLoadingScreenMusic()
			{
				if ((Object)(object)MySimsBehaviour.Instance != (Object)null && Configs.secretLoadingScreen.Value && !Plugin.LCSimonTendoPlaylistsModCompatible)
				{
					MySimsBehaviour.Instance.StopLoadingMusic();
				}
			}
		}

		[HarmonyPatch(typeof(AnimatedItem), "Start")]
		public class NewOldPhoneStart
		{
			[HarmonyPostfix]
			public static void SetUpOldPhone(AnimatedItem __instance)
			{
				if (!Plugin.LCSimonTendoPlaylistsModCompatible && Configs.secretOldPhone.Value && ((Object)__instance).name == "OldPhone(Clone)" && (Object)(object)Plugin.BonusAssetBundle != (Object)null)
				{
					int num = Random.Range(0, 6);
					__instance.grabAudio = Plugin.PhoneSounds[num];
				}
			}
		}

		[HarmonyPatch(typeof(CozyLights), "SetAudio")]
		public class NewCozyLightsSetAudio
		{
			[HarmonyPrefix]
			public static void DiscoBallPrefix(CozyLights __instance, bool ___cozyLightsOn)
			{
				int num;
				if (!Plugin.LCSimonTendoPlaylistsModCompatible)
				{
					Transform parent = ((Component)__instance).gameObject.transform.parent;
					if (((parent != null) ? ((Object)parent).name : null) == "DiscoBallContainer(Clone)")
					{
						num = ((Plugin.DiscoBallSounds != null) ? 1 : 0);
						goto IL_003b;
					}
				}
				num = 0;
				goto IL_003b;
				IL_003b:
				if (((uint)num & (___cozyLightsOn ? 1u : 0u)) == 0 || __instance.turnOnAudio.isPlaying)
				{
					return;
				}
				int num2 = -1;
				for (int i = 0; i < Plugin.DiscoBallSounds.Length; i++)
				{
					if ((Object)(object)__instance.turnOnAudio.clip == (Object)(object)Plugin.DiscoBallSounds[i])
					{
						num2 = i + 1;
						if (num2 == Plugin.DiscoBallSounds.Length)
						{
							num2 = 0;
						}
						break;
					}
				}
				if (num2 == -1)
				{
					num2 = 0;
				}
				if (num2 >= 0 && num2 < Plugin.DiscoBallSounds.Length)
				{
					Logger.LogDebug((object)$"indexToUse = {num2} | clip = {Plugin.DiscoBallSounds[num2]}");
					__instance.turnOnAudio.clip = Plugin.DiscoBallSounds[num2];
				}
			}
		}

		private static ManualLogSource Logger;

		private static bool alreadyAddedToOrigin;
	}
	internal class MySimsBehaviour : MonoBehaviour
	{
		private static ManualLogSource Logger;

		public static MySimsBehaviour Instance;

		public AudioSource audio2D;

		private Coroutine fadeOutMusicCoroutine;

		private void Awake()
		{
			Instance = this;
			Logger = Plugin.Logger;
			audio2D = ((Component)this).GetComponent<AudioSource>();
			if ((Object)(object)audio2D == (Object)null)
			{
				Logger.LogError((object)("Failed to find audio2D on " + ((Object)this).name + "!"));
			}
		}

		public void StartLoadingMusic()
		{
			if (Configs.secretLoadingScreen.Value && !Plugin.LCSimonTendoPlaylistsModCompatible && !((Object)(object)audio2D == (Object)null))
			{
				if (fadeOutMusicCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(fadeOutMusicCoroutine);
					fadeOutMusicCoroutine = null;
				}
				if (audio2D.isPlaying)
				{
					audio2D.Stop();
				}
				int num = GetLoadingScreenClipIndex() - 1;
				if (num < 0 || num >= Plugin.LoadingScreenSounds.Length)
				{
					Logger.LogError((object)$"StartLoadingMusic() got invalid clipIndex {num}");
					return;
				}
				audio2D.clip = Plugin.LoadingScreenSounds[num];
				audio2D.volume = 1f;
				audio2D.Play();
			}
		}

		private int GetLoadingScreenClipIndex()
		{
			int currentLevelID = StartOfRound.Instance.currentLevelID;
			int num = -1;
			if (currentLevelID == 0 || currentLevelID == 3)
			{
				return 1;
			}
			if (currentLevelID == 1 || currentLevelID == 8)
			{
				return 3;
			}
			if (currentLevelID == 2 || currentLevelID == 4 || currentLevelID == 5)
			{
				return 7;
			}
			if (currentLevelID == 6 || currentLevelID == 7)
			{
				return 5;
			}
			if (currentLevelID == 9 || currentLevelID == 10)
			{
				return 6;
			}
			if (currentLevelID == 12)
			{
				return 2;
			}
			return 4;
		}

		public void StopLoadingMusic()
		{
			if (fadeOutMusicCoroutine == null)
			{
				fadeOutMusicCoroutine = ((MonoBehaviour)this).StartCoroutine(FadeOutMusic());
			}
		}

		private IEnumerator FadeOutMusic()
		{
			while (audio2D.volume > 0.1f)
			{
				AudioSource obj = audio2D;
				obj.volume -= Time.deltaTime * 0.067f;
				yield return null;
			}
			audio2D.volume = 0f;
			audio2D.Stop();
			fadeOutMusicCoroutine = null;
		}
	}
	internal class PlaylistsModCompatibility
	{
		private static ManualLogSource Logger;

		private static SharedAudioComponent PlaylistsContainer;

		private static string modName = "LCSimonTendoPlaylistsMod";

		public static void OldPhone(GameObject gObject)
		{
			SharedAudioMethods.AudioClipAddNewRange(Plugin.PhoneSounds, SharedAudioMethods.AudioListGetByName(modName, gObject, false, true), true, 50, false);
		}

		public static void RecordPlayer(GameObject gObject)
		{
			SharedAudioMethods.AudioClipAddNew(Plugin.RecordPlayerSound, SharedAudioMethods.AudioListGetByName(modName, gObject, false, true), true, 100, false);
		}

		public static void LoadingScreen()
		{
			GetGenericPlaylistsContainer();
			AudioList val = SharedAudioMethods.AudioListGetByName(modName + " - Loading Screen", PlaylistsContainer, false, true);
			SharedAudioMethods.AudioClipAddNew(Plugin.LoadingScreenSounds[0], val, true, 100, false);
			SharedAudioMethods.AudioClipAddNew(Plugin.LoadingScreenSounds[1], val, true, 50, false);
			SharedAudioMethods.AudioClipAddNew(Plugin.LoadingScreenSounds[2], val, true, 25, false);
			SharedAudioMethods.AudioClipAddNew(Plugin.LoadingScreenSounds[3], val, true, 10, false);
			SharedAudioMethods.AudioClipAddNew(Plugin.LoadingScreenSounds[4], val, true, 50, false);
			SharedAudioMethods.AudioClipAddNew(Plugin.LoadingScreenSounds[5], val, true, 50, false);
			SharedAudioMethods.AudioClipAddNew(Plugin.LoadingScreenSounds[6], val, true, 25, false);
		}

		public static void ToyRobot(GameObject gObject)
		{
			SharedAudioMethods.AudioClipAddNew(Plugin.ToyRobotSound, SharedAudioMethods.AudioListGetByName(modName, gObject, false, true), true, 150, false);
		}

		public static void Pumpkin(GameObject gObject)
		{
			SharedAudioMethods.AudioClipAddNewRange(Plugin.PumpkinSounds, SharedAudioMethods.AudioListGetByName(modName, gObject, false, true), true, 33, false);
		}

		public static void DiscoBall(GameObject gObject)
		{
			SharedAudioMethods.AudioClipAddNewRange(Plugin.DiscoBallSounds, SharedAudioMethods.AudioListGetByName(modName, gObject, false, true), true, 100, false);
		}

		private static void GetGenericPlaylistsContainer()
		{
			if (Logger == null)
			{
				Logger = Plugin.Logger;
			}
			if ((Object)(object)PlaylistsContainer != (Object)null || (Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			GameObject gameObject = ((Component)((Component)StartOfRound.Instance).transform.parent.Find("SimonTendoManagers")).gameObject;
			if ((Object)(object)gameObject == (Object)null)
			{
				Logger.LogWarning((object)"failed to find: SimonTendoManagers");
				return;
			}
			GameObject gameObject2 = ((Component)gameObject.transform.Find(modName)).gameObject;
			if ((Object)(object)gameObject2 == (Object)null)
			{
				Logger.LogWarning((object)("failed to find: " + modName));
				return;
			}
			PlaylistsContainer = gameObject2.GetComponent<SharedAudioComponent>();
			if ((Object)(object)PlaylistsContainer == (Object)null)
			{
				Logger.LogError((object)"failed to find: SharedAudioComponent");
			}
		}
	}
	[BepInPlugin("LCMySimsSoundPackMod", "LCMySimsSoundPackMod", "1.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static AssetBundle MySimsAssetBundle;

		public static AssetBundle AgentsAssetBundle;

		public static AssetBundle KingdomAssetBundle;

		public static AssetBundle SkyHeroesAssetBundle;

		public static AssetBundle RacingAssetBundle;

		public static AssetBundle PartyAssetBundle;

		public static AssetBundle BonusAssetBundle;

		public static AudioClip[] AllSongs;

		public static GameObject managerPrefab;

		public static AudioClip[] PhoneSounds;

		public static AudioClip RecordPlayerSound;

		public static AudioClip[] LoadingScreenSounds;

		public static AudioClip ToyRobotSound;

		public static AudioClip[] PumpkinSounds;

		public static AudioClip[] DiscoBallSounds;

		public static string configGamesToLower;

		public static string configGenresToLower;

		public static bool ValidConfigEntry;

		public static bool LCSimonTendoPlaylistsModCompatible;

		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 LCMySimsSoundPackMod is loaded!");
			new Harmony("LCMySimsSoundPackMod").PatchAll();
			MyConfig = new Configs(((BaseUnityPlugin)this).Config);
			Configs.DisplayConfigs();
			configGamesToLower = Configs.customizationSelectedGames.Value.ToLower();
			configGenresToLower = Configs.customizationSelectedGenres.Value.ToLower();
			ValidConfigEntry = GetValidConfigEntry();
			if (ValidConfigEntry)
			{
				Logger.LogInfo((object)"Config entry valid. Asset bundles will try to be loaded...");
			}
			else
			{
				Logger.LogWarning((object)"Config entry invalid! Check for typos.");
			}
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			bool flag = false;
			if (ValidConfigEntry)
			{
				if (!Configs.optionsPerformanceMode.Value || GamesConfigsContains("mysims"))
				{
					MySimsAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "mysimsassetbundle"));
					if ((Object)(object)MySimsAssetBundle == (Object)null)
					{
						Logger.LogError((object)"Failed to load AssetBundle: MySims");
					}
					else
					{
						Logger.LogInfo((object)"Loaded AssetBundle: MySims");
						flag = true;
					}
				}
				else
				{
					Logger.LogDebug((object)"Not loading AssetBundle: MySims");
				}
				if (!Configs.optionsPerformanceMode.Value || GamesConfigsContains("agents"))
				{
					AgentsAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "agentsassetbundle"));
					if ((Object)(object)AgentsAssetBundle == (Object)null)
					{
						Logger.LogError((object)"Failed to load AssetBundle: Agents");
					}
					else
					{
						Logger.LogInfo((object)"Loaded AssetBundle: Agents");
						flag = true;
					}
				}
				else
				{
					Logger.LogDebug((object)"Not loading AssetBundle: Agents");
				}
				if (!Configs.optionsPerformanceMode.Value || GamesConfigsContains("kingdom"))
				{
					KingdomAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "kingdomassetbundle"));
					if ((Object)(object)KingdomAssetBundle == (Object)null)
					{
						Logger.LogError((object)"Failed to load AssetBundle: Kingdom");
					}
					else
					{
						Logger.LogInfo((object)"Loaded AssetBundle: Kingdom");
						flag = true;
					}
				}
				else
				{
					Logger.LogDebug((object)"Not loading AssetBundle: Kingdom");
				}
				if (!Configs.optionsPerformanceMode.Value || GamesConfigsContains("skyheroes"))
				{
					SkyHeroesAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "skyheroesassetbundle"));
					if ((Object)(object)SkyHeroesAssetBundle == (Object)null)
					{
						Logger.LogError((object)"Failed to load AssetBundle: SkyHeroes");
					}
					else
					{
						Logger.LogInfo((object)"Loaded AssetBundle: SkyHeroes");
						flag = true;
					}
				}
				else
				{
					Logger.LogDebug((object)"Not loading AssetBundle: SkyHeroes");
				}
				if (!Configs.optionsPerformanceMode.Value || GamesConfigsContains("racing"))
				{
					RacingAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "racingassetbundle"));
					if ((Object)(object)RacingAssetBundle == (Object)null)
					{
						Logger.LogError((object)"Failed to load AssetBundle: Racing");
					}
					else
					{
						Logger.LogInfo((object)"Loaded AssetBundle: Racing");
						flag = true;
					}
				}
				else
				{
					Logger.LogDebug((object)"Not loading AssetBundle: Racing");
				}
				if (!Configs.optionsPerformanceMode.Value || GamesConfigsContains("party"))
				{
					PartyAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "partyassetbundle"));
					if ((Object)(object)PartyAssetBundle == (Object)null)
					{
						Logger.LogError((object)"Failed to load AssetBundle: Party");
					}
					else
					{
						Logger.LogInfo((object)"Loaded AssetBundle: Party");
						flag = true;
					}
				}
				else
				{
					Logger.LogDebug((object)"Not loading AssetBundle: Party");
				}
				if (flag)
				{
					AllSongs = LoadAssetBundleSongs();
				}
				else if (configGamesToLower.Contains("none"))
				{
					Logger.LogInfo((object)"Config [Selected Games] contained input 'None', no boombox music will be loaded.");
				}
				else if (configGenresToLower.Contains("none"))
				{
					Logger.LogInfo((object)"Config [Selected Genres] contained input 'None', no boombox music will be loaded.");
				}
			}
			if (Configs.secretOldPhone.Value || Configs.secretRecordPlayer.Value || Configs.secretLoadingScreen.Value || Configs.secretToyRobot.Value || Configs.secretJackOLantern.Value || Configs.secretDiscoBallMusic.Value)
			{
				BonusAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "bonusassetbundle"));
				if ((Object)(object)BonusAssetBundle == (Object)null)
				{
					Logger.LogError((object)"Failed to load MySimsBonusAssetBundle");
				}
				else
				{
					Logger.LogInfo((object)"Loaded AssetBundle: Bonus");
				}
			}
			else
			{
				Logger.LogDebug((object)"Not loading AssetBundle: Bonus");
			}
			if ((Object)(object)BonusAssetBundle != (Object)null)
			{
				managerPrefab = BonusAssetBundle.LoadAsset<GameObject>("Assets/ManagerObject.prefab");
				if (Configs.secretOldPhone.Value)
				{
					Logger.LogDebug((object)"Loading PhoneSounds from BonusAssetBundle");
					PhoneSounds = (AudioClip[])(object)new AudioClip[6];
					for (int i = 0; i < PhoneSounds.Length; i++)
					{
						PhoneSounds[i] = BonusAssetBundle.LoadAsset<AudioClip>($"Assets/Bonus - PhoneCall{i + 1}.ogg");
					}
				}
				if (Configs.secretRecordPlayer.Value)
				{
					Logger.LogDebug((object)"Loading RecordPlayerSound from BonusAssetBundle");
					RecordPlayerSound = BonusAssetBundle.LoadAsset<AudioClip>("Assets/Bonus - WiiDiskLoading.ogg");
				}
				if (Configs.secretLoadingScreen.Value)
				{
					Logger.LogDebug((object)"Loading LoadingScreenSounds from BonusAssetBundle");
					LoadingScreenSounds = (AudioClip[])(object)new AudioClip[7];
					for (int j = 0; j < LoadingScreenSounds.Length; j++)
					{
						LoadingScreenSounds[j] = BonusAssetBundle.LoadAsset<AudioClip>($"Assets/Bonus - Loading Screen {j + 1}.ogg");
					}
				}
				if (Configs.secretToyRobot.Value)
				{
					Logger.LogDebug((object)"Loading ToyRobotSound from BonusAssetBundle");
					ToyRobotSound = BonusAssetBundle.LoadAsset<AudioClip>("Assets/Bonus - Toy Robot T.O.B.O.R..ogg");
				}
				if (Configs.secretJackOLantern.Value)
				{
					Logger.LogDebug((object)"Loading PumpkinSounds from BonusAssetBundle");
					PumpkinSounds = (AudioClip[])(object)new AudioClip[3];
					for (int k = 0; k < PumpkinSounds.Length; k++)
					{
						PumpkinSounds[k] = BonusAssetBundle.LoadAsset<AudioClip>($"Assets/Bonus - Pumpkin Item {k + 1}.ogg");
					}
				}
				if (Configs.secretDiscoBallMusic.Value)
				{
					Logger.LogDebug((object)"Loading DiscoBallSounds from BonusAssetBundle");
					DiscoBallSounds = (AudioClip[])(object)new AudioClip[4];
					for (int l = 0; l < DiscoBallSounds.Length; l++)
					{
						DiscoBallSounds[l] = BonusAssetBundle.LoadAsset<AudioClip>($"Assets/Bonus - Disco DJ Booth {l + 1}.ogg");
					}
				}
			}
			LCSimonTendoPlaylistsModCompatible = CheckForPlugin("LCSimonTendoPlaylistsMod");
		}

		public static bool CheckForPlugin(string pluginName, bool printDebug = true)
		{
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if (value.Metadata.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 GameObject SearchForObject(string name, Transform parentTransform = null)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			Logger.LogDebug((object)("Starting search for " + name));
			GameObject[] array = Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0);
			GameObject[] array2 = array;
			GameObject result;
			foreach (GameObject val in array2)
			{
				if (((Object)val).name == name)
				{
					result = val;
					Logger.LogDebug((object)("Found existing " + ((Object)val).name + ", using as parent."));
					return result;
				}
			}
			result = new GameObject(name);
			if ((Object)(object)parentTransform != (Object)null)
			{
				result.transform.SetParent(parentTransform, false);
			}
			Logger.LogDebug((object)("Did not find existing " + name + ", instantiating new " + ((Object)result).name));
			return result;
		}

		public static void SetBoomboxOnStart(BoomboxItem __instance)
		{
			if (ValidConfigEntry && AllSongs != null)
			{
				if (Configs.optionsAddOrOverwrite.Value)
				{
					List<AudioClip> list = __instance.musicAudios.ToList();
					list.AddRange(AllSongs);
					__instance.musicAudios = list.ToArray();
				}
				else
				{
					__instance.musicAudios = AllSongs;
				}
			}
		}

		public static AudioClip[] LoadAssetBundleSongs()
		{
			List<AudioClip> listToAdd = new List<AudioClip>();
			listToAdd = AddSongsFromAllAssetBundles(listToAdd);
			HashSet<AudioClip> hashSet = new HashSet<AudioClip>();
			char[] separator = new char[5] { ',', ' ', '.', ';', '/' };
			string[] array = configGamesToLower.Split(separator, StringSplitOptions.RemoveEmptyEntries);
			string[] array2 = configGenresToLower.Split(separator, StringSplitOptions.RemoveEmptyEntries);
			if (configGamesToLower.Contains("all") && configGenresToLower.Contains("all"))
			{
				return listToAdd.ToArray();
			}
			if (!configGamesToLower.Contains("all") && configGenresToLower.Contains("all"))
			{
				string[] array3 = array;
				foreach (string text in array3)
				{
					foreach (AudioClip item in listToAdd)
					{
						string text2 = ((object)item).ToString();
						if (text2.Contains("(" + text + ")"))
						{
							hashSet.Add(item);
						}
					}
				}
				return hashSet.ToArray();
			}
			if (configGamesToLower.Contains("all") && !configGenresToLower.Contains("all"))
			{
				string[] array4 = array2;
				foreach (string text3 in array4)
				{
					foreach (AudioClip item2 in listToAdd)
					{
						if (((Object)item2).name.Contains("(" + text3 + ")"))
						{
							hashSet.Add(item2);
						}
					}
				}
				return hashSet.ToArray();
			}
			if (!configGamesToLower.Contains("all") && !configGenresToLower.Contains("all"))
			{
				List<AudioClip> list = new List<AudioClip>();
				string[] array5 = array;
				foreach (string text4 in array5)
				{
					foreach (AudioClip item3 in listToAdd)
					{
						if (((Object)item3).name.Contains("(" + text4 + ")"))
						{
							list.Add(item3);
						}
					}
				}
				string[] array6 = array2;
				foreach (string text5 in array6)
				{
					foreach (AudioClip item4 in list)
					{
						if (((Object)item4).name.Contains("(" + text5 + ")"))
						{
							hashSet.Add(item4);
						}
					}
				}
				return hashSet.ToArray();
			}
			Logger.LogWarning((object)"Unexpected error occured. Loading all MySimsSongs.");
			return listToAdd.ToArray();
		}

		public static bool GetValidConfigEntry()
		{
			if ((!configGamesToLower.Contains("all") && !configGamesToLower.Contains("mysims") && !configGamesToLower.Contains("kingdom") && !configGamesToLower.Contains("party") && !configGamesToLower.Contains("agents") && !configGamesToLower.Contains("racing") && !configGamesToLower.Contains("skyheroes") && !configGamesToLower.Contains("none")) || (!configGenresToLower.Contains("all") && !configGenresToLower.Contains("fun") && !configGenresToLower.Contains("cutesy") && !configGenresToLower.Contains("dj") && !configGenresToLower.Contains("mellow") && !configGenresToLower.Contains("rock") && !configGenresToLower.Contains("spooky") && !configGenresToLower.Contains("bigband") && !configGenresToLower.Contains("exotic") && !configGenresToLower.Contains("none")))
			{
				return false;
			}
			return true;
		}

		public static bool GamesConfigsContains(string gameName)
		{
			if (configGamesToLower.Contains("none"))
			{
				return false;
			}
			if (configGenresToLower.Contains("none"))
			{
				return false;
			}
			if (configGamesToLower.Contains("all"))
			{
				return true;
			}
			if (configGamesToLower.Contains(gameName.ToLower()))
			{
				return true;
			}
			return false;
		}

		public static List<AudioClip> AddSongsFromAllAssetBundles(List<AudioClip> listToAdd)
		{
			int num = 0;
			Logger.LogDebug((object)$"added {listToAdd.Count - num} songs; allSongsList.Count: {listToAdd.Count} (Start // [Prioritize Selected Games]? {Configs.optionsPerformanceMode.Value})");
			num = listToAdd.Count;
			listToAdd = AddSongsToList(listToAdd, MySimsAssetBundle);
			Logger.LogDebug((object)$"added {listToAdd.Count - num} songs; allSongsList.Count: {listToAdd.Count} (MySims // valid? {(Object)(object)MySimsAssetBundle != (Object)null})");
			num = listToAdd.Count;
			listToAdd = AddSongsToList(listToAdd, AgentsAssetBundle);
			Logger.LogDebug((object)$"added {listToAdd.Count - num} songs; allSongsList.Count: {listToAdd.Count} (Agents // valid? {(Object)(object)AgentsAssetBundle != (Object)null})");
			num = listToAdd.Count;
			listToAdd = AddSongsToList(listToAdd, KingdomAssetBundle);
			Logger.LogDebug((object)$"added {listToAdd.Count - num} songs; allSongsList.Count: {listToAdd.Count} (Kingdom // valid? {(Object)(object)KingdomAssetBundle != (Object)null})");
			num = listToAdd.Count;
			listToAdd = AddSongsToList(listToAdd, SkyHeroesAssetBundle);
			Logger.LogDebug((object)$"added {listToAdd.Count - num} songs; allSongsList.Count: {listToAdd.Count} (SkyHeroes // valid? {(Object)(object)SkyHeroesAssetBundle != (Object)null})");
			num = listToAdd.Count;
			listToAdd = AddSongsToList(listToAdd, RacingAssetBundle);
			Logger.LogDebug((object)$"added {listToAdd.Count - num} songs; allSongsList.Count: {listToAdd.Count} (Racing // valid? {(Object)(object)RacingAssetBundle != (Object)null})");
			num = listToAdd.Count;
			listToAdd = AddSongsToList(listToAdd, PartyAssetBundle);
			Logger.LogDebug((object)$"added {listToAdd.Count - num} songs; allSongsList.Count: {listToAdd.Count} (Party // valid? {(Object)(object)PartyAssetBundle != (Object)null})");
			num = listToAdd.Count;
			return listToAdd;
		}

		public static List<AudioClip> AddSongsToList(List<AudioClip> listToAdd, AssetBundle fromBundle)
		{
			AudioClip[] allSongsOfBundle = GetAllSongsOfBundle(fromBundle);
			if (allSongsOfBundle == null)
			{
				return listToAdd;
			}
			listToAdd.AddRange(allSongsOfBundle);
			return listToAdd;
		}

		public static AudioClip[] GetAllSongsOfBundle(AssetBundle bundle)
		{
			if ((Object)(object)bundle == (Object)null)
			{
				return null;
			}
			return bundle.LoadAllAssets<AudioClip>();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LCMySimsSoundPackMod";

		public const string PLUGIN_NAME = "LCMySimsSoundPackMod";

		public const string PLUGIN_VERSION = "1.3.0";
	}
}