Oof/Oof.dll

Decompiled 9 months ago
using System.Collections.Generic;
using System.Diagnostics;
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("Oof")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Oof")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("00116bc3-29c8-4020-bd4c-02b8d10b87dc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Oof
{
	[BepInPlugin("beef_gristle.Oof", "Oof", "1.0.0")]
	public class OofBase : BaseUnityPlugin
	{
		private const string modGUID = "beef_gristle.Oof";

		private const string modName = "Oof";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("beef_gristle.Oof");

		private static OofBase Instance;

		internal ManualLogSource mls;

		public static Dictionary<PlayerControllerB, AudioSource> oofSources = new Dictionary<PlayerControllerB, AudioSource>();

		internal static AudioClip[] oofSFX;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("beef_gristle.Oof");
			mls.LogInfo((object)"Starting Oof");
			mls.LogInfo((object)(((BaseUnityPlugin)Instance).Info.Location.TrimEnd("Oof.dll".ToCharArray()) + "oof"));
			AssetBundle val = AssetBundle.LoadFromFile(((BaseUnityPlugin)Instance).Info.Location.TrimEnd("Oof.dll".ToCharArray()) + "oof");
			if ((Object)(object)val == (Object)null)
			{
				mls.LogError((object)"Failed to load audio assets");
				return;
			}
			oofSFX = val.LoadAssetWithSubAssets<AudioClip>("oof.mp3");
			harmony.PatchAll();
			mls.LogInfo((object)"Oof successfully loaded!");
		}
	}
}
namespace Oof.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class DeathPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		public static void CreateAudioSource(ref PlayerControllerB __instance)
		{
			OofBase.oofSources[__instance] = ((Component)__instance).gameObject.AddComponent<AudioSource>();
		}

		[HarmonyPatch("KillPlayer")]
		[HarmonyPostfix]
		public static void OofPatch(ref PlayerControllerB __instance)
		{
			AudioClip[] oofSFX = OofBase.oofSFX;
			if (oofSFX != null && oofSFX.Length != 0)
			{
				OofBase.oofSources[__instance].PlayOneShot(oofSFX[0]);
			}
		}
	}
}