Decompiled source of AAAHHHorn v1.0.1

AAAAHHHHHorn.dll

Decompiled 8 months ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using ActualClownHorn.Patches;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ActualClownHorn")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ActualClownHorn")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2e059ba3-b0cc-451b-80dd-b8c9e81c756f")]
[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 ActualClownHorn
{
	[BepInPlugin("AAAHHHorn", "AAAHHHorn", "1.0.0")]
	public class ActualClownHornBase : BaseUnityPlugin
	{
		internal const string ModGuid = "AAAHHHorn";

		internal const string ModName = "AAAHHHorn";

		internal const string ModVersion = "1.0.0";

		internal const string ModAuthor = "pppoe252110";

		private readonly Harmony _harmony = new Harmony("AAAHHHorn");

		public static ActualClownHornBase Instance;

		internal ManualLogSource logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("AAAHHHorn");
			logger.LogInfo((object)"AAAHHHorn Has loaded");
			_harmony.PatchAll(typeof(GrabbableObjectPatch));
		}
	}
}
namespace ActualClownHorn.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabbableObjectPatch
	{
		private static ManualLogSource logger;

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void HonkPatch(GrabbableObject __instance)
		{
			Item itemProperties = __instance.itemProperties;
			logger.LogInfo((object)((Object)itemProperties).name);
			if (!(((Object)itemProperties).name != "Airhorn"))
			{
				NoisemakerProp component = ((Component)__instance).GetComponent<NoisemakerProp>();
				AudioClip val = LoadAudio("near.mp3");
				AudioClip val2 = LoadAudio("far.mp3");
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
				{
					component.noiseSFX = (AudioClip[])(object)new AudioClip[1] { val };
					component.noiseSFXFar = (AudioClip[])(object)new AudioClip[1] { val2 };
				}
			}
		}

		private static AudioClip LoadAudio(string fileName)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Invalid comparison between Unknown and I4
			string text = Path.Combine(Paths.PluginPath, "AAAHHHorn", fileName);
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(text, (AudioType)13);
			audioClip.SendWebRequest();
			logger.LogInfo((object)"Waiting for audio...");
			while (!audioClip.isDone)
			{
			}
			if (audioClip.error != null)
			{
				logger.LogError((object)("There was an error downloading audio: " + text + "\n" + audioClip.error));
				return null;
			}
			logger.LogInfo((object)"Audio downloaded");
			AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
			if ((Object)(object)content != (Object)null && (int)content.loadState == 2)
			{
				logger.LogInfo((object)("Loaded audio " + text));
				((Object)content).name = Path.GetFileName(text);
				return content;
			}
			logger.LogError((object)("There was an error loading audio " + text));
			return null;
		}

		static GrabbableObjectPatch()
		{
			logger = Logger.CreateLogSource("ActualClownHorn.GrabbableObjectPatch");
		}
	}
}