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("AnibusAirHorn")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AnibusAirHorn")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ba33d76d-aa54-4c55-a72c-c474588fd3b9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AnibusHorn;
internal static class Patches
{
public static ManualLogSource logger;
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
private static void StartPatch()
{
string text = Path.Combine(Paths.PluginPath, "Anibus-AnibusAirHorn", "sounds");
if (text == "")
{
text = Path.Combine(Paths.PluginPath, "Anibus-AnibusAirHorn", "plugins", "sounds");
}
if (text == "")
{
text = Path.Combine(Paths.PluginPath, "Anibus-AnibusAirHorn");
}
Plugin.LoadRandomAudioClip(text);
}
[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
[HarmonyPostfix]
private static void GenerateNewLevelClientRpcPatch(int randomSeed)
{
string text = Path.Combine(Paths.PluginPath, "Anibus-AnibusAirHorn", "sounds");
if (text == "")
{
text = Path.Combine(Paths.PluginPath, "Anibus-AnibusAirHorn", "plugins", "sounds");
}
if (text == "")
{
text = Path.Combine(Paths.PluginPath, "Anibus-AnibusAirHorn");
}
Plugin.LoadRandomAudioClip(text);
}
public static AudioClip LoadAudioClip(string filepath)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Invalid comparison between Unknown and I4
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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)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)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
if (((Object)__instance.itemProperties).name == "Airhorn")
{
NoisemakerProp component = ((Component)__instance).GetComponent<NoisemakerProp>();
if ((Object)component != (Object)null)
{
component.noiseSFX[0] = Plugin.RegularClip;
component.noiseSFXFar[0] = Plugin.FarClip;
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "Anibus.AnibusAirHorn";
public const string PLUGIN_NAME = "AnibusAirHorn";
public const string PLUGIN_VERSION = "1.0.1";
}
[BepInPlugin("Anibus.AnibusAirHorn", "AnibusAirHorn", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
public static AudioClip RegularClip;
public static AudioClip FarClip;
public static ManualLogSource logger;
public static int num;
private void Awake()
{
logger = Logger.CreateLogSource("AnibusHorn");
logger.LogInfo((object)"Plugin AnibusAirHorn has been added!");
Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
}
public static void LoadRandomAudioClip(string path)
{
string[] files = Directory.GetFiles(path, "*.mp3");
if (files.Length >= 2)
{
num = Random.Range(0, files.Length);
if (num == 0)
{
num = 0;
}
else if (num % 2 == 1)
{
num--;
}
RegularClip = Patches.LoadAudioClip(files[num]);
FarClip = Patches.LoadAudioClip(files[num + 1]);
}
}
}