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 HarmonyLib.Tools;
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 150 songs from the MySims franchise to the Boombox!")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1")]
[assembly: AssemblyProduct("LCMySimsSoundPackMod")]
[assembly: AssemblyTitle("LCMySimsSoundPackMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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 LCMySimsSoundPackMod
{
[BepInPlugin("LCMySimsSoundPackMod", "LCMySimsSoundPackMod", "1.2.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public class Config
{
public static ConfigEntry<string> configSelectedGames;
public static ConfigEntry<string> configSelectedGenres;
public static ConfigEntry<bool> configAddOrOverwrite;
public static ConfigEntry<bool> configOldPhoneSecret;
public static ConfigEntry<bool> configRecordPlayerSecret;
public Config(ConfigFile cfg)
{
configSelectedGames = cfg.Bind<string>("Customization", "Selected Games", "All", "Select which games' music will be played. Options: All, MySims, Kingdom, Party, Racing, Agents, SkyHeroes. When selecting multiple, make sure to split them up! (For example: Agents Party MySims)");
configSelectedGenres = cfg.Bind<string>("Customization", "Selected Genres", "All", "Select what genres music will be played. Options: All, Fun, Cutesy, Exotic, Mellow, Rock, Spooky, Bigband, DJ. When selecting multiple, make sure to split them up! (For example: Fun DJ Spooky)");
configAddOrOverwrite = 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).");
configOldPhoneSecret = cfg.Bind<bool>("Secret", "Replace Old Phone", false, "Want to replace the sounds of the Old Phone? Options: true, false. (true = yes | false = no)");
configRecordPlayerSecret = cfg.Bind<bool>("Secret", "Replace Record Player", false, "Want to replace the sound of the Record Player? Options: true, false. (true = yes | false = no)");
}
}
public static Plugin instance;
internal static ManualLogSource Logger;
public static AssetBundle MySimsSongAssetBundle;
public static AssetBundle MySimsBonusAssetBundle;
public static AudioClip[] MySimsSongs;
public static AudioClip[] PhoneSounds = (AudioClip[])(object)new AudioClip[6];
public static AudioClip RecordPlayerSound;
public static string configGamesToLower;
public static string configGenresToLower;
public static bool ValidConfigEntry;
public static bool LCSimonTendoPlaylistsModCompatible = false;
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 LCMySimsSoundPackMod is loaded!");
Harmony val = new Harmony("LCMySimsSoundPackMod");
val.PatchAll();
HarmonyFileLog.Enabled = false;
MyConfig = new Config(((BaseUnityPlugin)this).Config);
configGamesToLower = Config.configSelectedGames.Value.ToLower();
configGenresToLower = Config.configSelectedGenres.Value.ToLower();
ValidConfigEntry = GetValidConfigEntry();
if (ValidConfigEntry)
{
Logger.LogInfo((object)"Config entry valid. Asset bundles will try to be loaded...");
}
else if (!ValidConfigEntry)
{
Logger.LogWarning((object)"Config entry invalid! Check for typos.");
}
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (ValidConfigEntry)
{
MySimsSongAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "mysimssoundpackassetbundle"));
if ((Object)(object)MySimsSongAssetBundle == (Object)null)
{
Logger.LogError((object)"Failed to load MySimsSongAssetBundle");
}
else
{
MySimsSongs = LoadAssetBundleSongs();
Logger.LogInfo((object)"Loaded MySimsSongAssetBundle");
}
}
if (Config.configOldPhoneSecret.Value || Config.configRecordPlayerSecret.Value)
{
MySimsBonusAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "mysimsbonusassetbundle"));
if ((Object)(object)MySimsBonusAssetBundle == (Object)null)
{
Logger.LogError((object)"Failed to load MySimsBonusAssetBundle");
}
else
{
Logger.LogInfo((object)"Loaded MySimsBonusAssetBundle");
}
}
if (Config.configOldPhoneSecret.Value && (Object)(object)MySimsBonusAssetBundle != (Object)null)
{
Logger.LogInfo((object)"Loading PhoneSounds from MySimsBonusAssetBundle");
PhoneSounds[0] = MySimsBonusAssetBundle.LoadAsset<AudioClip>("Assets/MySimsPhoneCall1.ogg");
PhoneSounds[1] = MySimsBonusAssetBundle.LoadAsset<AudioClip>("Assets/MySimsPhoneCall2.ogg");
PhoneSounds[2] = MySimsBonusAssetBundle.LoadAsset<AudioClip>("Assets/MySimsPhoneCall3.ogg");
PhoneSounds[3] = MySimsBonusAssetBundle.LoadAsset<AudioClip>("Assets/MySimsPhoneCall4.ogg");
PhoneSounds[4] = MySimsBonusAssetBundle.LoadAsset<AudioClip>("Assets/MySimsPhoneCall5.ogg");
PhoneSounds[5] = MySimsBonusAssetBundle.LoadAsset<AudioClip>("Assets/MySimsPhoneCall6.ogg");
}
if (Config.configRecordPlayerSecret.Value && (Object)(object)MySimsBonusAssetBundle != (Object)null)
{
Logger.LogInfo((object)"Loading RecordPlayerSound from MySimsBonusAssetBundle");
RecordPlayerSound = MySimsBonusAssetBundle.LoadAsset<AudioClip>("Assets/MySimsWiiDiskLoading.ogg");
}
if (ValidConfigEntry && Config.configAddOrOverwrite.Value)
{
Logger.LogInfo((object)"Config [Add Or Overwrite] is set to TRUE. MySims songs will be added to the total list of songs.");
}
else if (ValidConfigEntry && !Config.configAddOrOverwrite.Value)
{
Logger.LogInfo((object)"Config [Add Or Overwrite] is set to FALSE. MySims songs will try to be the only songs in the playlist.");
}
if (Config.configRecordPlayerSecret.Value || Config.configOldPhoneSecret.Value)
{
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 void SetAllBoomboxesOnStart(BoomboxItem __instance)
{
if (ValidConfigEntry && (Object)(object)MySimsSongAssetBundle != (Object)null)
{
__instance.musicRandomizer = new Random(GetRandomSeed());
if (Config.configAddOrOverwrite.Value)
{
List<AudioClip> list = __instance.musicAudios.ToList();
list.AddRange(MySimsSongs);
__instance.musicAudios = list.ToArray();
}
else
{
__instance.musicAudios = MySimsSongs;
}
}
}
public static void SetOldPhonePlaylist(GameObject gObject)
{
SharedAudioMethods.AudioClipAddNewRange(PhoneSounds, SharedAudioMethods.AudioListGetByName("LCSimonTendoPlaylistsMod", gObject, false, true), true, 50, false);
}
public static void SetRecordPlayerPlaylist(GameObject gObject)
{
SharedAudioMethods.AudioClipAddNew(RecordPlayerSound, SharedAudioMethods.AudioListGetByName("LCSimonTendoPlaylistsMod", gObject, false, true), true, 100, false);
}
public static AudioClip[] LoadAssetBundleSongs()
{
List<AudioClip> list = new List<AudioClip>();
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 MySimsSongAssetBundle.LoadAllAssets<AudioClip>();
}
if (!configGamesToLower.Contains("all") && configGenresToLower.Contains("all"))
{
list.AddRange(MySimsSongAssetBundle.LoadAllAssets<AudioClip>());
string[] array3 = array;
foreach (string text in array3)
{
foreach (AudioClip item in list)
{
string text2 = ((object)item).ToString();
if (text2.Contains("(" + text + ")"))
{
hashSet.Add(item);
}
}
}
return hashSet.ToArray();
}
if (configGamesToLower.Contains("all") && !configGenresToLower.Contains("all"))
{
list.AddRange(MySimsSongAssetBundle.LoadAllAssets<AudioClip>());
string[] array4 = array2;
foreach (string text3 in array4)
{
foreach (AudioClip item2 in list)
{
string text4 = ((object)item2).ToString();
if (text4.Contains("(" + text3 + ")"))
{
hashSet.Add(item2);
}
}
}
return hashSet.ToArray();
}
if (!configGamesToLower.Contains("all") && !configGenresToLower.Contains("all"))
{
list.AddRange(MySimsSongAssetBundle.LoadAllAssets<AudioClip>());
List<AudioClip> list2 = new List<AudioClip>();
string[] array5 = array;
foreach (string text5 in array5)
{
foreach (AudioClip item3 in list)
{
string text6 = ((object)item3).ToString();
if (text6.Contains("(" + text5 + ")"))
{
list2.Add(item3);
}
}
}
string[] array6 = array2;
foreach (string text7 in array6)
{
foreach (AudioClip item4 in list2)
{
string text8 = ((object)item4).ToString();
if (text8.Contains("(" + text7 + ")"))
{
hashSet.Add(item4);
}
}
}
return hashSet.ToArray();
}
Console.Write("Unexpected error occured. Loading all MySimsSongs.");
return MySimsSongAssetBundle.LoadAllAssets<AudioClip>();
}
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")) || (!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")))
{
return false;
}
return true;
}
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 SetUpBoombox(BoomboxItem __instance)
{
Plugin.SetAllBoomboxesOnStart(__instance);
}
}
[HarmonyPatch(typeof(AnimatedItem), "Start")]
public class NewOldPhoneStart
{
[HarmonyPostfix]
public static void SetUpOldPhone(AnimatedItem __instance)
{
if (!Plugin.LCSimonTendoPlaylistsModCompatible && Plugin.Config.configOldPhoneSecret.Value && ((Object)__instance).name == "OldPhone(Clone)" && (Object)(object)Plugin.MySimsBonusAssetBundle != (Object)null)
{
int num = Random.Range(0, 6);
__instance.grabAudio = Plugin.PhoneSounds[num];
}
}
}
[HarmonyPatch(typeof(StartOfRound), "Start")]
public class NewStartOfRoundStart
{
[HarmonyPrefix]
public static void SetUpOnRoundStart(StartOfRound __instance)
{
if (Plugin.LCSimonTendoPlaylistsModCompatible)
{
foreach (Item items in __instance.allItemsList.itemsList)
{
if (((Object)items).name == "Phone" && Plugin.Config.configOldPhoneSecret.Value && (Object)(object)Plugin.MySimsBonusAssetBundle != (Object)null)
{
Plugin.SetOldPhonePlaylist(items.spawnPrefab);
}
}
}
foreach (UnlockableItem unlockable in __instance.unlockablesList.unlockables)
{
if (unlockable.unlockableName == "Record player" && Plugin.Config.configRecordPlayerSecret.Value && (Object)(object)Plugin.MySimsBonusAssetBundle != (Object)null)
{
if (Plugin.LCSimonTendoPlaylistsModCompatible)
{
Plugin.SetRecordPlayerPlaylist(unlockable.prefabObject);
}
else
{
((Component)unlockable.prefabObject.transform.GetChild(3)).GetComponent<AnimatedObjectTrigger>().playWhileTrue = Plugin.RecordPlayerSound;
}
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "LCMySimsSoundPackMod";
public const string PLUGIN_NAME = "LCMySimsSoundPackMod";
public const string PLUGIN_VERSION = "1.2.1";
}
}