Decompiled source of ActualClownHorn v1.0.1

ActualClownHorn.dll

Decompiled a year 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("ActualClownHorn", "Actual Clown Horn", "1.0.0")]
	public class ActualClownHornBase : BaseUnityPlugin
	{
		internal const string ModGuid = "ActualClownHorn";

		internal const string ModName = "Actual Clown Horn";

		internal const string ModVersion = "1.0.0";

		internal const string ModAuthor = "flillip";

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

		public static ActualClownHornBase Instance;

		internal ManualLogSource logger;

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

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void HonkPatch(GrabbableObject __instance)
		{
			Item itemProperties = __instance.itemProperties;
			logger.LogInfo((object)((Object)itemProperties).name);
			if (((Object)itemProperties).name != "ClownHorn")
			{
				logger.LogWarning((object)"not a clown horn");
				return;
			}
			logger.LogInfo((object)"found a clown horn!");
			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, "flillip-ActualClownHorn", 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;
		}
	}
}