Please disclose if your mod was created primarily 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 SoundCompany v1.1.4
SoundCompany.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using BepInEx; using BepInEx.Logging; using HarmonyLib; using LCSoundTool; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("SoundCompany")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("SoundCompany")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("c1eb512a-2a02-4d09-8e2c-f31b2dabb7d8")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace SoundCompany; [BepInPlugin("SoundCompany", "Sound Company", "1.0.0")] public class SoundCompanyBase : BaseUnityPlugin { private const string PLUGIN_GUID = "SoundCompany"; private const string PLUGIN_NAME = "Sound Company"; private const string PLUGIN_VERSION = "1.0.0"; internal ManualLogSource logger; private Harmony harmony; public HashSet<string> currentSounds = new HashSet<string>(); public HashSet<string> oldSounds = new HashSet<string>(); public HashSet<string> modifiedSounds = new HashSet<string>(); public Dictionary<string, string> soundHashes = new Dictionary<string, string>(); private static SoundCompanyBase Instance; private void Awake() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown if ((Object)(object)Instance == (Object)null) { Instance = this; logger = Logger.CreateLogSource("SoundCompany"); logger.LogInfo((object)"Plugin SoundCompany is loaded!"); harmony = new Harmony("SoundCompany"); harmony.PatchAll(); modifiedSounds = new HashSet<string>(); } } public void RevertSounds() { foreach (string currentSound in currentSounds) { SoundTool.RestoreAudioClip(currentSound); } currentSounds = new HashSet<string>(); logger.LogInfo((object)"Original game sounds restored."); } public static string CalculateMD5(string filename) { MD5 mD = MD5.Create(); FileStream inputStream = File.OpenRead(filename); byte[] array = mD.ComputeHash(inputStream); return BitConverter.ToString(array).Replace("-", "").ToLowerInvariant(); } public void ReloadSounds() { foreach (string currentSound in currentSounds) { SoundTool.RestoreAudioClip(currentSound); } oldSounds = new HashSet<string>(currentSounds); modifiedSounds.Clear(); string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string text = Path.Combine(directoryName, "sounds"); logger.LogInfo((object)("SoundCompany path is: " + text)); try { if (!Directory.Exists(text)) { DirectoryInfo directoryInfo = Directory.CreateDirectory(text); logger.LogInfo((object)("Sounds folder created successfully at: " + directoryInfo.FullName)); string text2 = Path.Combine(directoryName, "sample_sounds.zip"); string text3 = Path.Combine(directoryName, "sounds"); try { if (File.Exists(text2)) { Directory.CreateDirectory(text3); ZipFile.ExtractToDirectory(text2, text3); Console.WriteLine("Successfully extracted contents to: " + text3); } else { Console.WriteLine("Zip file does not exist at: " + text2); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } } else { logger.LogInfo((object)("Folder already exists at: " + text)); } } catch (Exception ex2) { logger.LogInfo((object)("Error: " + ex2.Message)); } currentSounds.Clear(); if (Directory.Exists(text)) { string[] files = Directory.GetFiles(text, "*.wav"); string[] array = files; foreach (string text4 in array) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text4); string text5 = CalculateMD5(text4); if (soundHashes.TryGetValue(fileNameWithoutExtension, out var value) && value != text5) { modifiedSounds.Add(fileNameWithoutExtension); } AudioClip audioClip = SoundTool.GetAudioClip(directoryName, "CustomSounds", text4); SoundTool.ReplaceAudioClip(fileNameWithoutExtension, audioClip); soundHashes[fileNameWithoutExtension] = text5; currentSounds.Add(fileNameWithoutExtension); logger.LogInfo((object)(fileNameWithoutExtension + " sound replaced!")); } } else { logger.LogInfo((object)"SoundCompany folder not found."); } } public string GetSoundChanges() { StringBuilder stringBuilder = new StringBuilder("SoundCompany reloaded.\n"); List<string> list = currentSounds.Except(oldSounds).ToList(); List<string> list2 = oldSounds.Except(currentSounds).ToList(); List<string> list3 = oldSounds.Intersect(currentSounds).Except(modifiedSounds).ToList(); if (list.Count > 0) { stringBuilder.AppendLine("Newly Added Sounds:"); foreach (string item in list) { stringBuilder.AppendLine("- " + item); } } if (list2.Count > 0) { stringBuilder.AppendLine("Deleted Sounds:"); foreach (string item2 in list2) { stringBuilder.AppendLine("- " + item2); } } if (modifiedSounds.Count > 0) { stringBuilder.AppendLine("Modified Sounds:"); foreach (string modifiedSound in modifiedSounds) { stringBuilder.AppendLine("- " + modifiedSound); } } if (list3.Count > 0) { stringBuilder.AppendLine("Existing Sounds:"); foreach (string item3 in list3) { stringBuilder.AppendLine("- " + item3); } } return stringBuilder.ToString(); } private void Start() { ReloadSounds(); } }