Decompiled source of FunnyAudio v1.0.2

FunnyAudio.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Hypick.FunnyAudio.NetcodePatcher;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Hypick.FunnyAudio")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+e4b8bd42c7fa604dd332d351e1fb394cf73b06fa")]
[assembly: AssemblyProduct("FunnyAudio")]
[assembly: AssemblyTitle("Hypick.FunnyAudio")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Hypick
{
	[BepInPlugin("Hypick.FunnyAudio", "FunnyAudio", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public static PluginConfig Config;

		private readonly Harmony _harmony = new Harmony("Hypick.FunnyAudio");

		internal static AudioClip[] BonkSFX;

		internal static AudioClip[] VineBoomSFX;

		internal static AudioClip[] YippeeSFX;

		internal static AudioClip[] AhhSFX;

		internal static AudioClip[] AngryScreechSFX;

		internal static List<AudioClip> FartsSFX = new List<AudioClip>();

		internal static List<AudioClip> MoaningsSFX = new List<AudioClip>();

		internal static List<AudioClip> NMBShotgunShoots = new List<AudioClip>();

		internal static AudioClip[] NMBShotgunReload;

		internal static AudioClip[] NMBNutCrackerAim;

		internal static AudioClip[] NMBNutCrackerDie;

		internal static AudioClip[] NMBNutCrackerHitEye;

		public static Plugin Instance { get; set; }

		public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		public Plugin()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Instance = this;
		}

		private void Awake()
		{
			Config = new PluginConfig(((BaseUnityPlugin)this).Config);
			Log.LogInfo((object)"Load assets...");
			LoadAssetBundle("bonk", out BonkSFX);
			LoadAssetBundle("vineboom", out VineBoomSFX);
			LoadAssetBundle("yippee", out YippeeSFX);
			LoadAssetBundle("ahh", out AhhSFX);
			LoadAssetBundle("angryscreech", out AngryScreechSFX);
			LoadListAssetBundle(new string[2] { "fart", "fartfar" }, FartsSFX);
			LoadListAssetBundle(new string[2] { "moaning", "moaningfar" }, MoaningsSFX);
			LoadListAssetBundle(new string[2] { "blast", "blast2" }, NMBShotgunShoots);
			LoadAssetBundle("reload", out NMBShotgunReload);
			LoadAssetBundle("nutcrackerturn", out NMBNutCrackerAim);
			LoadAssetBundle("nutcrackerdie", out NMBNutCrackerDie);
			LoadAssetBundle("nutcrackerhiteye", out NMBNutCrackerHitEye);
			Log.LogInfo((object)"Applying patches...");
			_harmony.PatchAll();
			Log.LogInfo((object)"Patches applied");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Hypick.FunnyAudio is fully loaded!");
		}

		private void LoadAssetBundle(string fileName, out AudioClip[] audioClips)
		{
			string filePath = GetFilePath(fileName);
			AssetBundle val = AssetBundle.LoadFromFile(filePath);
			if ((Object)(object)val == (Object)null)
			{
				Log.LogError((object)("Failed to load asset bundle from " + filePath));
				audioClips = null;
			}
			else
			{
				audioClips = val.LoadAllAssets<AudioClip>();
				Log.LogInfo((object)("Asset " + fileName + " is loaded"));
			}
		}

		private void LoadListAssetBundle(string[] fileNames, List<AudioClip> audioClips)
		{
			foreach (string text in fileNames)
			{
				string filePath = GetFilePath(text);
				AssetBundle val = AssetBundle.LoadFromFile(filePath);
				if ((Object)(object)val == (Object)null)
				{
					Log.LogError((object)("Failed to load asset bundle from " + filePath));
					continue;
				}
				audioClips.Add(val.LoadAllAssets<AudioClip>()[0]);
				Log.LogInfo((object)("Asset " + text + " is loaded"));
			}
		}

		private string GetFilePath(string fileName)
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location);
			return Path.Combine(directoryName, fileName);
		}
	}
	public static class Categories
	{
		public const string Shovel = "Shotgun";

		public const string SpringMan = "SpringMan";

		public const string HoarderBug = "HoarderBug";

		public const string Landmine = "Landmine";

		public const string Airhorn = "Airhorn";

		public const string Shotgun = "Shotgun";

		public const string NutCracker = "NutCracker";
	}
	public class PluginConfig
	{
		public bool ShovelHitSFX { get; private set; }

		public bool SpringNoises { get; private set; }

		public bool ChitterSFX { get; private set; }

		public bool HitPlayerSFX { get; private set; }

		public bool AngryVoiceSFX { get; private set; }

		public bool MineDetonate { get; private set; }

		public bool AirhornActivate { get; private set; }

		public bool ShotgunNeedMoreBullets { get; private set; }

		public PluginConfig(ConfigFile cfg)
		{
			ShovelHitSFX = cfg.Bind<bool>("Shotgun", "ShovelHitSFX", true, "Replaces the impact sound with the Bonk sound (https://www.youtube.com/watch?v=6TP0abZdRXg)").Value;
			SpringNoises = cfg.Bind<bool>("SpringMan", "SpringNoises", true, "Replaces the sound when the spring stops with the Vine Boom sound (https://www.youtube.com/watch?v=Oc7Cin_87H4)").Value;
			ChitterSFX = cfg.Bind<bool>("HoarderBug", "ChitterSFX", true, "Replaces the chirping sound with the Yippee sound (https://www.youtube.com/watch?v=0CqEKoy-fIQ)").Value;
			HitPlayerSFX = cfg.Bind<bool>("HoarderBug", "HitPlayerSFX", true, "Replaces the impact sound with the sound Ahh (https://www.youtube.com/watch?v=09gX0WL0AmI)").Value;
			AngryVoiceSFX = cfg.Bind<bool>("HoarderBug", "AngryVoiceSFX", true, "Replaces the aggressive sound with AAAAAAGHH").Value;
			MineDetonate = cfg.Bind<bool>("Landmine", "MineDetonate", true, "Replaces the explosion sound with a POWERFUL explosion").Value;
			AirhornActivate = cfg.Bind<bool>("Airhorn", "AirhornActivate", true, "Replaces activation sound with moans").Value;
			ShotgunNeedMoreBullets = cfg.Bind<bool>("Shotgun", "ShotgunNeedMoreBullets", true, "Replaces the sounds of shooting and reloading with I NEED MORE BULLETS").Value;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Hypick.FunnyAudio";

		public const string PLUGIN_NAME = "FunnyAudio";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace Hypick.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabbableObjectPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(GrabbableObject __instance)
		{
			if (Plugin.Config.AirhornActivate && (Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).GetComponent<NoisemakerProp>() != (Object)null && ((Object)__instance.itemProperties).name == "Airhorn")
			{
				((Component)__instance).GetComponent<NoisemakerProp>().noiseSFX[0] = Plugin.MoaningsSFX[0];
				((Component)__instance).GetComponent<NoisemakerProp>().noiseSFXFar[0] = Plugin.MoaningsSFX[0];
			}
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI))]
	internal class HoarderBugAIPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(ref AudioClip[] ___chitterSFX, ref AudioClip ___hitPlayerSFX, ref AudioClip ___angryVoiceSFX)
		{
			___chitterSFX = (Plugin.Config.ChitterSFX ? Plugin.YippeeSFX : ___chitterSFX);
			___hitPlayerSFX = (Plugin.Config.HitPlayerSFX ? Plugin.AhhSFX[0] : ___hitPlayerSFX);
			___angryVoiceSFX = (Plugin.Config.AngryVoiceSFX ? Plugin.AngryScreechSFX[0] : ___angryVoiceSFX);
		}
	}
	[HarmonyPatch(typeof(Landmine))]
	internal class LandminePatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(ref AudioClip[] ___mineDetonate, ref AudioClip[] ___mineDetonateFar)
		{
			if (Plugin.Config.MineDetonate)
			{
				___mineDetonate[0] = Plugin.FartsSFX[0];
				___mineDetonateFar[0] = Plugin.FartsSFX[1];
			}
		}
	}
	[HarmonyPatch(typeof(ShotgunItem))]
	internal class ShotgunItemPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(ref AudioClip ___gunReloadSFX)
		{
			if (Plugin.Config.ShotgunNeedMoreBullets)
			{
				___gunReloadSFX = Plugin.NMBShotgunReload[0];
			}
		}

		[HarmonyPatch("ShootGun")]
		[HarmonyPrefix]
		private static void ShootGun(ShotgunItem __instance)
		{
			if (Plugin.Config.ShotgunNeedMoreBullets)
			{
				AudioSource component = ((Component)__instance).gameObject.GetComponent<AudioSource>();
				component.PlayOneShot(Plugin.NMBShotgunShoots[Random.Range(0, Plugin.NMBShotgunShoots.Count)], 1f);
			}
		}
	}
	[HarmonyPatch(typeof(Shovel))]
	internal class ShovelPatch
	{
		[HarmonyPatch("HitShovelClientRpc")]
		[HarmonyPatch("HitShovel")]
		[HarmonyPrefix]
		private static void HitShovel(ref AudioClip[] ___hitSFX)
		{
			if (Plugin.Config.ShovelHitSFX)
			{
				___hitSFX = Plugin.BonkSFX;
			}
		}
	}
	[HarmonyPatch(typeof(SpringManAI))]
	internal class SpringManAIPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void Update(ref AudioClip[] ___springNoises)
		{
			if (Plugin.Config.SpringNoises)
			{
				___springNoises = Plugin.VineBoomSFX;
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace Hypick.FunnyAudio.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}