Decompiled source of Meme Sounds Mod v1.0.1

LCMemeSoundsMod.dll

Decompiled 11 months ago
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 GameNetcodeStuff;
using HarmonyLib;
using LCMemeSounds.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCMemeSoundsMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCMemeSoundsMod")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("D6F95046-8F89-4A6D-AC3D-BBF40793163D")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCMemeSounds
{
	[BepInPlugin("com.jacobfdunbar.mods.lc.memesounds", "Meme Sounds", "0.0.1")]
	public class MemeSoundsMod : BaseUnityPlugin
	{
		private const string ModGUID = "com.jacobfdunbar.mods.lc.memesounds";

		private const string ModName = "Meme Sounds";

		private const string ModVersion = "0.0.1";

		private readonly Harmony _harmony = new Harmony("com.jacobfdunbar.mods.lc.memesounds");

		public ManualLogSource Log { get; private set; }

		public static MemeSoundsMod Instance { get; private set; }

		public AudioClip OofSound { get; private set; }

		public AudioClip DeathSoundMarioFall { get; private set; }

		public AudioClip DeathSoundSpongebobFall { get; private set; }

		public AudioClip DeathSoundWasted { get; private set; }

		public AudioClip DrowningSound { get; private set; }

		public AudioClip DeathSoundDrowned { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
				Log = Logger.CreateLogSource("com.jacobfdunbar.mods.lc.memesounds");
				Log.LogInfo((object)"Initializing Meme Sounds...");
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
				if (directoryName == null)
				{
					Log.LogError((object)"Failed to get mod path!");
					return;
				}
				AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(directoryName, "com.jacobfdunbar.mods.lc.memesounds.assets"));
				OofSound = val.LoadAsset<AudioClip>("steve_oof");
				DeathSoundMarioFall = val.LoadAsset<AudioClip>("mario_death");
				DeathSoundSpongebobFall = val.LoadAsset<AudioClip>("spongebob_fail_crunch");
				DeathSoundWasted = val.LoadAsset<AudioClip>("wasted");
				DrowningSound = val.LoadAsset<AudioClip>("pikmin_drowning");
				DeathSoundDrowned = val.LoadAsset<AudioClip>("pikmin_death");
				_harmony.PatchAll(typeof(MemeSoundsMod));
				_harmony.PatchAll(typeof(StartOfRoundPatch));
				_harmony.PatchAll(typeof(PlayerControllerBPatch));
			}
			else
			{
				Object.Destroy((Object)(object)this);
			}
		}
	}
}
namespace LCMemeSounds.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class PlayerControllerBPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("DamagePlayer")]
		private static void DamagePlayerPatch(bool fallDamage, CauseOfDeath causeOfDeath, AudioSource ___movementAudio, int ___health)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if (!fallDamage && (int)causeOfDeath == 2 && ___health > 0)
			{
				PlaySound(StartOfRound.Instance.fallDamageSFX, ___movementAudio);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("KillPlayer")]
		private static void KillPlayerPatch(CauseOfDeath causeOfDeath, AudioSource ___movementAudio)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			StackTrace stackTrace = new StackTrace();
			if ((int)causeOfDeath != 2)
			{
				if ((int)causeOfDeath != 7)
				{
					if ((int)causeOfDeath == 9)
					{
						PlaySound(MemeSoundsMod.Instance.DeathSoundDrowned, ___movementAudio);
					}
				}
				else
				{
					PlaySound(MemeSoundsMod.Instance.DeathSoundWasted, ___movementAudio);
				}
			}
			else
			{
				PlaySound(stackTrace.ToString().Contains("InteractTrigger") ? MemeSoundsMod.Instance.DeathSoundMarioFall : MemeSoundsMod.Instance.DeathSoundSpongebobFall, ___movementAudio);
			}
		}

		private static void PlaySound(AudioClip clip, AudioSource source)
		{
			HUDManager.Instance.UIAudio.PlayOneShot(clip, 1f);
			WalkieTalkie.TransmitOneShotAudio(source, clip, 1f);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void StartPatch()
		{
			StartOfRound.Instance.fallDamageSFX = MemeSoundsMod.Instance.OofSound;
			StartOfRound.Instance.HUDSystemAlertSFX = MemeSoundsMod.Instance.DrowningSound;
		}
	}
}