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 RandomHorn v1.2.0
RandomHorn.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; 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("RandomHorn")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("RandomHorn")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("7513b0ea-56a7-4b4e-84e5-6a0e5e62eed1")] [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 RandomHorn; internal static class Patches { private static ManualLogSource Logger = Logger.CreateLogSource("RandomHorn"); [HarmonyPatch(typeof(StartOfRound), "Start")] [HarmonyPostfix] private static void StartPatch() { string path = Path.Combine(Paths.PluginPath, "BYRD-RandomHorn", "sounds"); Plugin.LoadRandomAudioClip(path, 0); } [HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")] [HarmonyPostfix] private static void GenerateNewLevelClientRpcPatch(int randomSeed) { string path = Path.Combine(Paths.PluginPath, "BYRD-RandomHorn", "sounds"); Plugin.LoadRandomAudioClip(path, randomSeed); } public static AudioClip LoadAudioClip(string filepath) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Invalid comparison between Unknown and I4 //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Invalid comparison between Unknown and I4 UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(filepath, (AudioType)13); UnityWebRequestAsyncOperation val = audioClip.SendWebRequest(); while (!((AsyncOperation)val).isDone) { } if ((int)audioClip.result != 1) { Logger.LogError((object)("Error loading sound: " + filepath + " - " + audioClip.error)); return null; } AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip); if ((Object)(object)content == (Object)null || (int)content.loadState != 2) { Logger.LogError((object)("Failed to load audio clip: " + filepath)); return null; } ((Object)content).name = Path.GetFileName(filepath); return content; } [HarmonyPatch(typeof(GrabbableObject), "Update")] [HarmonyPostfix] private static void AudioPatch(GrabbableObject __instance) { if (((Object)__instance.itemProperties).name == "Airhorn") { NoisemakerProp component = ((Component)__instance).GetComponent<NoisemakerProp>(); if ((Object)(object)component != (Object)null) { component.noiseSFX[0] = Plugin.RegularClip; component.noiseSFXFar[0] = Plugin.FarClip; } } } } public static class PluginInfo { public const string PLUGIN_GUID = "BYRD.RandomHorn"; public const string PLUGIN_NAME = "RandomHorn"; public const string PLUGIN_VERSION = "1.2.0"; } [BepInPlugin("com.yourdomain.randomhorn", "Random Horn", "1.0.0")] public class Plugin : BaseUnityPlugin { public static AudioClip RegularClip; public static AudioClip FarClip; public static Random Rand; private void Awake() { Rand = new Random(0); Harmony.CreateAndPatchAll(typeof(Patches), (string)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Random Horn Plugin loaded"); } public static void LoadRandomAudioClip(string path, int seed) { Rand = new Random(seed); string[] files = Directory.GetFiles(path, "*.mp3"); if (files.Length >= 2) { int num = Rand.Next(files.Length / 2) * 2; RegularClip = Patches.LoadAudioClip(files[num]); FarClip = Patches.LoadAudioClip(files[num + 1]); } } }