Decompiled source of SoundReplacements v1.5.2

baer1.SoundReplacements.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalModUtils;
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: AssemblyCompany("baer1.SoundReplacements")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.5.2.0")]
[assembly: AssemblyInformationalVersion("1.5.2+7f1966785e5f2a9dbd2c0dc9ed1e34883d4acdaa")]
[assembly: AssemblyProduct("MySoundReplacements")]
[assembly: AssemblyTitle("baer1.SoundReplacements")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 MySoundReplacements
{
	[BepInPlugin("baer1.SoundReplacements", "MySoundReplacements", "1.5.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class MySoundReplacements : BaseUnityPlugin
	{
		public static class Sounds
		{
			internal const string FALL_DEATH = "fall.ogg";

			internal const string FREDDY_FAZBEAR = "music box.wav";

			internal const string EYE_SCREAM = "eye scream.ogg";

			internal const string MIMIC_DEATH = "mimicDeath.wav";

			internal const string GOOFY_CRASH = "goofyCrash.wav";

			internal const string MASK_PIGGIES = "maskPiggies.wav";

			internal const string RED_SUCKER = "redSucker.wav";

			internal static bool FallDeathEnable
			{
				get
				{
					MySoundReplacements instance = Instance;
					int result;
					if (instance != null)
					{
						ConfigEntry<bool> fallDeathEnable = instance.fallDeathEnable;
						if (fallDeathEnable != null)
						{
							result = (fallDeathEnable.Value ? 1 : 0);
							goto IL_001c;
						}
					}
					result = 0;
					goto IL_001c;
					IL_001c:
					return (byte)result != 0;
				}
			}

			public static AudioClip? FallDeath => FallDeathEnable ? Instance.fallDeath : null;

			internal static bool FreddyFazbearEnable
			{
				get
				{
					MySoundReplacements instance = Instance;
					int result;
					if (instance != null)
					{
						ConfigEntry<bool> freddyFazbearEnable = instance.freddyFazbearEnable;
						if (freddyFazbearEnable != null)
						{
							result = (freddyFazbearEnable.Value ? 1 : 0);
							goto IL_001c;
						}
					}
					result = 0;
					goto IL_001c;
					IL_001c:
					return (byte)result != 0;
				}
			}

			public static AudioClip? FreddyFazbear => FreddyFazbearEnable ? Instance.freddyFazbear : null;

			internal static bool EyeScreamEnable
			{
				get
				{
					MySoundReplacements instance = Instance;
					int result;
					if (instance != null)
					{
						ConfigEntry<bool> eyeScreamEnable = instance.eyeScreamEnable;
						if (eyeScreamEnable != null)
						{
							result = (eyeScreamEnable.Value ? 1 : 0);
							goto IL_001c;
						}
					}
					result = 0;
					goto IL_001c;
					IL_001c:
					return (byte)result != 0;
				}
			}

			public static AudioClip? EyeScream => EyeScreamEnable ? Instance.eyeScream : null;

			internal static bool MimicDeathEnable
			{
				get
				{
					MySoundReplacements instance = Instance;
					int result;
					if (instance != null)
					{
						ConfigEntry<bool> mimicDeathEnable = instance.mimicDeathEnable;
						if (mimicDeathEnable != null)
						{
							result = (mimicDeathEnable.Value ? 1 : 0);
							goto IL_001c;
						}
					}
					result = 0;
					goto IL_001c;
					IL_001c:
					return (byte)result != 0;
				}
			}

			public static AudioClip? MimicDeath => MimicDeathEnable ? Instance.mimicDeath : null;

			internal static bool GoofyCrashEnable
			{
				get
				{
					MySoundReplacements instance = Instance;
					int result;
					if (instance != null)
					{
						ConfigEntry<bool> goofyCrashEnable = instance.goofyCrashEnable;
						if (goofyCrashEnable != null)
						{
							result = (goofyCrashEnable.Value ? 1 : 0);
							goto IL_001c;
						}
					}
					result = 0;
					goto IL_001c;
					IL_001c:
					return (byte)result != 0;
				}
			}

			public static AudioClip? GoofyCrash => GoofyCrashEnable ? Instance.goofyCrash : null;

			internal static bool MaskPiggiesEnable
			{
				get
				{
					MySoundReplacements instance = Instance;
					int result;
					if (instance != null)
					{
						ConfigEntry<bool> maskPiggiesEnable = instance.maskPiggiesEnable;
						if (maskPiggiesEnable != null)
						{
							result = (maskPiggiesEnable.Value ? 1 : 0);
							goto IL_001c;
						}
					}
					result = 0;
					goto IL_001c;
					IL_001c:
					return (byte)result != 0;
				}
			}

			public static AudioClip? MaskPiggies => MaskPiggiesEnable ? Instance.maskPiggies : null;

			internal static bool RedSuckerEnable
			{
				get
				{
					MySoundReplacements instance = Instance;
					int result;
					if (instance != null)
					{
						ConfigEntry<bool> redSuckerEnable = instance.redSuckerEnable;
						if (redSuckerEnable != null)
						{
							result = (redSuckerEnable.Value ? 1 : 0);
							goto IL_001c;
						}
					}
					result = 0;
					goto IL_001c;
					IL_001c:
					return (byte)result != 0;
				}
			}

			public static AudioClip? RedSucker => RedSuckerEnable ? Instance.redSucker : null;
		}

		internal ConfigEntry<float> loadTimeOut = null;

		private ConfigEntry<bool>? fallDeathEnable;

		private AudioClip? fallDeath;

		private ConfigEntry<bool>? freddyFazbearEnable;

		private AudioClip? freddyFazbear;

		private ConfigEntry<bool>? eyeScreamEnable;

		private AudioClip? eyeScream;

		private ConfigEntry<bool>? mimicDeathEnable;

		private AudioClip? mimicDeath;

		private ConfigEntry<bool>? goofyCrashEnable;

		private AudioClip? goofyCrash;

		private ConfigEntry<bool>? maskPiggiesEnable;

		private AudioClip? maskPiggies;

		private ConfigEntry<bool>? redSuckerEnable;

		private AudioClip? redSucker;

		public static MySoundReplacements Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		public TimeSpan LoadTimeOut => TimeSpan.FromSeconds(loadTimeOut.Value);

		private void Awake()
		{
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			loadTimeOut = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LoadTimeOut", 10f, "How long to wait before cancelling a sound load operation");
			fallDeathEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Sounds", "FallDeath", true, "Adds scream sound effect on death by Gravity or OutOfBoundsTrigger");
			freddyFazbearEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Sounds", "FreddyFazbear", true, "Adds Five Nights at Freddy's game over music when pulling apparatus");
			eyeScreamEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Sounds", "EyeScream", true, "Replaces Eyeless Dog anger sound with Eye Of Cthulhu from Terraria");
			mimicDeathEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Sounds", "MimicDeath", true, "Adds the Mimic death sound with THE MIMIICCCC (MR BEASTTTT)");
			goofyCrashEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Sounds", "GoofyCrash", true, "Replaces the cruiser crash sound with Goofy dying while listening to Post Malone");
			maskPiggiesEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Sounds", "MaskPiggies", true, "Replaces the Mask Hornets sound with the Bad Piggies theme from Angry Birds (the piggies are pretty bad)");
			redSuckerEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Sounds", "RedSucker", true, "Replaces the Sapsucker scream sound with the sound of Red from Angry Birds screaming (ya hooya!)");
			Logger.LogDebug((object)"Loading sounds...");
			fallDeath = Audio.TryLoad(rel("fall.ogg"), (TimeSpan?)LoadTimeOut);
			freddyFazbear = Audio.TryLoad(rel("music box.wav"), (TimeSpan?)LoadTimeOut);
			eyeScream = Audio.TryLoad(rel("eye scream.ogg"), (TimeSpan?)LoadTimeOut);
			mimicDeath = Audio.TryLoad(rel("mimicDeath.wav"), (TimeSpan?)LoadTimeOut);
			goofyCrash = Audio.TryLoad(rel("goofyCrash.wav"), (TimeSpan?)LoadTimeOut);
			maskPiggies = Audio.TryLoad(rel("maskPiggies.wav"), (TimeSpan?)LoadTimeOut);
			redSucker = Audio.TryLoad(rel("redSucker.wav"), (TimeSpan?)LoadTimeOut);
			Logger.LogDebug((object)"Finished loading sounds!");
			if (Harmony == null)
			{
				Harmony = new Harmony("baer1.SoundReplacements");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
			Logger.LogInfo((object)"baer1.SoundReplacements v1.5.2 has loaded!");
		}

		private Uri rel(string path)
		{
			return new Uri(Path.Combine(Path.GetDirectoryName(((object)this).GetType().Assembly.Location) ?? string.Empty, "Sounds", path));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "baer1.SoundReplacements";

		public const string PLUGIN_NAME = "MySoundReplacements";

		public const string PLUGIN_VERSION = "1.5.2";
	}
}
namespace MySoundReplacements.Patches
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class DogPatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(MouthDogAI), "screamSFX"), (string)null)
			}).Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[1]
			{
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(DogPatch), "a", (Type[])null, (Type[])null))
			})
				.InstructionEnumeration();
		}

		private static AudioClip a(AudioClip _audioClip)
		{
			return MySoundReplacements.Sounds.EyeScream ?? _audioClip;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "KillPlayerClientRpc")]
	internal class FallDeathPatch
	{
		private static void Postfix(ref PlayerControllerB __instance, ref int causeOfDeath)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (causeOfDeath == 2)
			{
				if (Object.op_Implicit((Object)(object)__instance.deadBody))
				{
					a(__instance.placeOfDeath, ((Component)__instance.deadBody).gameObject.transform);
				}
				else
				{
					a(__instance.placeOfDeath);
				}
			}
		}

		internal static void a(Vector3 origin, Transform? parentTo = null)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			AudioClip fallDeath = MySoundReplacements.Sounds.FallDeath;
			if (!((Object)(object)fallDeath == (Object)null))
			{
				AudioPlayer val = (Object.op_Implicit((Object)(object)parentTo) ? Audio.PlayAt(fallDeath, parentTo, (Action<AudioPlayer>)b) : Audio.PlayAt(fallDeath, origin, ((Component)StartOfRound.Instance).transform, (Action<AudioPlayer>)b));
				val.SetRange((float?)50f, (float?)null);
				val.Volume = 0.5f;
			}
			static void b(AudioPlayer player)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Invalid comparison between Unknown and I4
				if ((int)player.State > 0)
				{
					player.Cancel();
				}
			}
		}
	}
	[HarmonyPatch(typeof(OutOfBoundsTrigger), "OnTriggerEnter")]
	internal class OutOfBoundsPatch
	{
		private static void Postfix(ref OutOfBoundsTrigger __instance, ref Collider other)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = default(PlayerControllerB);
			if ((!__instance.disableWhenRoundStarts || StartOfRound.Instance.inShipPhase) && ((Component)other).TryGetComponent<PlayerControllerB>(ref val))
			{
				FallDeathPatch.a(((Component)val).transform.position);
			}
		}
	}
	[HarmonyPatch(typeof(VehicleController), "DestroyCar")]
	public class GoofyCrashPatch
	{
		private static void Prefix(ref VehicleController __instance)
		{
			AudioClip goofyCrash = MySoundReplacements.Sounds.GoofyCrash;
			if (!__instance.carDestroyed && (Object)(object)goofyCrash != (Object)null)
			{
				Audio.PlayAt(goofyCrash, ((Component)__instance).transform, (Action<AudioPlayer>)null).SetRange((float?)50f, (float?)null);
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager), "RadiationWarningHUD")]
	public class LightOffPatch
	{
		private static void Postfix(ref HUDManager __instance)
		{
			AudioClip freddyFazbear = MySoundReplacements.Sounds.FreddyFazbear;
			if ((Object)(object)freddyFazbear == (Object)null)
			{
				return;
			}
			((Component)Audio.PlayAt(freddyFazbear, ((Component)__instance).transform, (Action<AudioPlayer>)delegate(AudioPlayer player)
			{
				GameNetworkManager instance = GameNetworkManager.Instance;
				if (instance != null && (instance.localPlayerController?.isInsideFactory).GetValueOrDefault())
				{
					player.Volume = 0.75f;
					player.BypassEffects = false;
				}
				else
				{
					player.Volume = 0.2f;
					player.BypassEffects = true;
				}
			})._audioSource).gameObject.AddComponent<AudioLowPassFilter>().cutoffFrequency = 2000f;
		}
	}
	[HarmonyPatch(typeof(ButlerBeesEnemyAI), "Start")]
	public static class MaskPiggiesPatch
	{
		private static void Postfix(ref ButlerBeesEnemyAI __instance)
		{
			AudioClip maskPiggies = MySoundReplacements.Sounds.MaskPiggies;
			if (!Object.op_Implicit((Object)(object)__instance.buzzing) || (Object)(object)maskPiggies == (Object)null)
			{
				MySoundReplacements.Logger.LogWarning((object)$"Couldn't replace AudioClip on Mask Hornets: {__instance} AudioSource:{__instance.buzzing} AudioClip:{maskPiggies}");
				return;
			}
			__instance.buzzing.clip = maskPiggies;
			__instance.buzzing.Play();
		}
	}
	[HarmonyPatch(typeof(MaskedPlayerEnemy), "killAnimation")]
	public class MimicDeathPatch
	{
		private static void Prefix(ref MaskedPlayerEnemy __instance)
		{
			((EnemyAI)__instance).enemyType.audioClips[0] = MySoundReplacements.Sounds.MimicDeath;
		}
	}
	[HarmonyPatch(typeof(GiantKiwiAI), "Start")]
	public class RedSuckerPatch
	{
		private static void Postfix(ref GiantKiwiAI __instance)
		{
			__instance.screamSFX = (AudioClip[])(object)new AudioClip[2]
			{
				MySoundReplacements.Sounds.RedSucker,
				MySoundReplacements.Sounds.RedSucker
			};
		}
	}
}