Decompiled source of RandomPlayerDeathSounds v1.0.0

randomDeathSounds.dll

Decompiled 5 days ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("randomDeathSounds")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("randomDeathSounds")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dbb16179-18f8-46df-8ed8-371fdcbcc9ab")]
[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 randomDeathSounds
{
	[BepInPlugin("automan.randomDeathSounds", "Random player death sounds", "1.0.0")]
	public class randomPlayerDeathSoundsBase : BaseUnityPlugin
	{
		private const string modGUID = "automan.randomDeathSounds";

		private const string modName = "Random player death sounds";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("automan.randomDeathSounds");

		private static randomPlayerDeathSoundsBase Instance;

		internal ManualLogSource mls;

		internal static List<AudioClip> SoundFX;

		internal static AssetBundle Bundle;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("automan.randomDeathSounds");
			mls.LogInfo((object)"Don't die! (:");
			harmony.PatchAll();
			mls = ((BaseUnityPlugin)this).Logger;
			SoundFX = new List<AudioClip>();
			string location = ((BaseUnityPlugin)Instance).Info.Location;
			location = location.TrimEnd("randomDeathSounds.dll".ToCharArray());
			Bundle = AssetBundle.LoadFromFile(location + "deathsounds");
			if ((Object)(object)Bundle != (Object)null)
			{
				mls.LogInfo((object)"works");
				SoundFX = Bundle.LoadAllAssets<AudioClip>().ToList();
			}
			else
			{
				mls.LogError((object)"NOT GOOD");
			}
		}
	}
}
namespace randomDeathSounds.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("SpawnDeadBody")]
		[HarmonyPostfix]
		private static void playNewDeathNoise(ref DeadBodyInfo ___deadBody)
		{
			float num = Random.Range(1, 100);
			if (num >= 87.5f)
			{
				___deadBody.bodyAudio.PlayOneShot(randomPlayerDeathSoundsBase.SoundFX[0], 0.75f);
			}
			else if (num >= 75f)
			{
				___deadBody.bodyAudio.PlayOneShot(randomPlayerDeathSoundsBase.SoundFX[1], 0.75f);
			}
			else if (num >= 62.5f)
			{
				___deadBody.bodyAudio.PlayOneShot(randomPlayerDeathSoundsBase.SoundFX[2], 0.75f);
			}
			else if (num >= 50f)
			{
				___deadBody.bodyAudio.PlayOneShot(randomPlayerDeathSoundsBase.SoundFX[3], 0.75f);
			}
			else if (num >= 37.5f)
			{
				___deadBody.bodyAudio.PlayOneShot(randomPlayerDeathSoundsBase.SoundFX[4], 0.75f);
			}
			else if (num >= 25f)
			{
				___deadBody.bodyAudio.PlayOneShot(randomPlayerDeathSoundsBase.SoundFX[5], 0.75f);
			}
			else if (num >= 12.5f)
			{
				___deadBody.bodyAudio.PlayOneShot(randomPlayerDeathSoundsBase.SoundFX[6], 0.75f);
			}
			else
			{
				___deadBody.bodyAudio.PlayOneShot(randomPlayerDeathSoundsBase.SoundFX[7], 0.75f);
			}
		}
	}
}