Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of MusicPlus v1.1.1
MusicPlus.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Threading; using BepInEx; using BepInEx.Logging; using HarmonyLib; using MusicPlus.Patches; using UnityEngine; using UnityEngine.Networking; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("MusicPlus")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("MusicPlus")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("a54ca277-bddd-42ef-a6a9-59b4285be2dc")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace MusicPlus { [BepInPlugin("SZAKI.MusicPlus", "Music Plus", "1.1.1.0")] [BepInProcess("Lethal Company.exe")] public class Base : BaseUnityPlugin { private static Base _instance; private ManualLogSource _log; private string _configPath = string.Empty; private string _recordPlayerPath = string.Empty; private string _boomboxPath = string.Empty; private List<AudioClip> _boomboxAudios = new List<AudioClip>(); private List<AudioClip> _recordPlayerAudios = new List<AudioClip>(); private static Harmony harmony = new Harmony("SZAKI.MusicPlus"); public static Base Instance { get { return _instance; } private set { _instance = value; } } public ManualLogSource Log { get { return _log; } private set { _log = value; } } public string ConfigPath { get { return _configPath; } private set { _configPath = value; } } public string RecordPlayerPath { get { return _recordPlayerPath; } private set { _recordPlayerPath = value; } } public string BoomboxPath { get { return _boomboxPath; } private set { _boomboxPath = value; } } public List<AudioClip> BoomboxAudios { get { return _boomboxAudios; } private set { _boomboxAudios = value; } } public List<AudioClip> RecordPlayerAudios { get { return _recordPlayerAudios; } private set { _recordPlayerAudios = value; } } private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } if (Log == null) { Log = Logger.CreateLogSource("SZAKI.MusicPlus"); } if (ConfigPath.Equals(string.Empty)) { ConfigPath = Paths.ConfigPath; } if (RecordPlayerPath.Equals(string.Empty)) { RecordPlayerPath = $"{ConfigPath}{Path.DirectorySeparatorChar}Record_Player_Sounds"; } if (BoomboxPath.Equals(string.Empty)) { BoomboxPath = $"{ConfigPath}{Path.DirectorySeparatorChar}Boombox_Sounds"; } if (!Directory.Exists(ConfigPath)) { Directory.CreateDirectory(ConfigPath); } if (!Directory.Exists(RecordPlayerPath)) { Directory.CreateDirectory(RecordPlayerPath); } if (!Directory.Exists(BoomboxPath)) { Directory.CreateDirectory(BoomboxPath); } List<AudioClip> list = LoadAudios(RecordPlayerPath); List<AudioClip> list2 = LoadAudios(BoomboxPath); list?.ForEach(delegate(AudioClip audio) { RecordPlayerAudios.Add(audio); }); list2?.ForEach(delegate(AudioClip audio) { BoomboxAudios.Add(audio); }); RecordPlayerAudios = RecordPlayerAudios.OrderBy((AudioClip a) => ((Object)a).name).ToList(); BoomboxAudios = BoomboxAudios.OrderBy((AudioClip a) => ((Object)a).name).ToList(); Log.LogInfo((object)" Sorted record player audios: "); RecordPlayerAudios.ForEach(delegate(AudioClip audio) { Log.LogInfo((object)(" " + ((Object)audio).name)); }); harmony.PatchAll(typeof(Base)); harmony.PatchAll(typeof(BoomboxPatch)); harmony.PatchAll(typeof(RecordPlayerPatch)); Log.LogInfo((object)" Successfully awakened and everything is fine!"); } private List<AudioClip> LoadAudios(string path) { //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Invalid comparison between Unknown and I4 DirectoryInfo directoryInfo = new DirectoryInfo(path); Log.LogInfo((object)(" Start loading audios from: " + path)); FileInfo[] files = directoryInfo.GetFiles("*.wav"); if (files.Length == 0) { Log.LogInfo((object)"No audio file found!"); return null; } Log.LogInfo((object)(files.Length + " audio file found!")); List<AudioClip> list = new List<AudioClip>(); FileInfo[] array = files; foreach (FileInfo fileInfo in array) { char directorySeparatorChar = Path.DirectorySeparatorChar; UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path + directorySeparatorChar + fileInfo.Name, (AudioType)20); audioClip.SendWebRequest(); while (!audioClip.isDone) { Thread.Sleep(100); } if ((int)audioClip.result != 2) { AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip); ((Object)content).name = fileInfo.Name; list.Add(content); } } Log.LogInfo((object)(list.Count + " audio file loaded!")); return list; } } public static class PluginInfos { public const string GUID = "SZAKI.MusicPlus"; public const string NAME = "Music Plus"; public const string VERSION = "1.1.1.0"; } } namespace MusicPlus.Patches { [HarmonyPatch(typeof(BoomboxItem))] internal class BoomboxPatch { [HarmonyPatch(typeof(BoomboxItem), "Start")] [HarmonyPostfix] private static void StartPatch(ref BoomboxItem __instance) { if (Base.Instance.BoomboxAudios.Count >= 1) { __instance.musicAudios = Base.Instance.BoomboxAudios.ToArray(); } } } [HarmonyPatch(typeof(AnimatedObjectTrigger))] internal class RecordPlayerPatch { [HarmonyPatch(typeof(AnimatedObjectTrigger), "PlayAudio")] [HarmonyPrefix] public static void Prefix(ref InteractTrigger __instance, ref AudioClip ___playWhileTrue, bool boolVal, bool playSecondaryAudios = false) { try { bool flag = false; Component[] componentsInParent = ((Component)__instance).gameObject.GetComponentsInParent(typeof(Component)); foreach (Component val in componentsInParent) { if (((Object)val).name.Contains("RecordPlayer")) { flag = true; break; } } if (flag && Base.Instance.RecordPlayerAudios.Count >= 1) { ___playWhileTrue = Base.Instance.RecordPlayerAudios.ElementAt(new Random().Next(0, Base.Instance.RecordPlayerAudios.Count)); } } catch (Exception) { } } } }