Decompiled source of ToemmsensCursedSoundMod v1.0.4

BepInEx/plugins/CursedSoundMod.dll

Decompiled 11 months ago
using System;
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 CursedSoundMod.Patches;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CursedSoundMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CursedSoundMod")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2bf920d3-ca69-423e-8915-8703c9958a34")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CursedSoundMod
{
	[BepInPlugin("toemmsen.CursedSoundMod", "ToemmsensCursedSoundMod", "1.0.4")]
	public class CursedSoundMod : BaseUnityPlugin
	{
		private const string modGUID = "toemmsen.CursedSoundMod";

		private const string modName = "ToemmsensCursedSoundMod";

		private const string modVersion = "1.0.4";

		private readonly Harmony harmony = new Harmony("toemmsen.CursedSoundMod");

		private static string audioFile = "mineTrigger.mp3";

		private static string audioFile2 = "skibidi.mp3";

		private static string audioFile3 = "erika.mp3";

		private static string uPath = null;

		private static CursedSoundMod instance;

		internal ManualLogSource mls;

		internal static AudioClip newSFX;

		internal static AudioClip skibidi;

		internal static AudioClip erika;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("toemmsen.CursedSoundMod");
			mls.LogInfo((object)"Cursed Sounds loading...");
			uPath = FindBooombitchFolder();
			if (uPath == null)
			{
				mls.LogError((object)"Booombitch folder not found!");
				return;
			}
			newSFX = LoadAudioClip(uPath + "\\" + audioFile);
			skibidi = LoadAudioClip(uPath + "\\" + audioFile2);
			erika = LoadAudioClip(uPath + "\\" + audioFile3);
			if (newSFX == null || skibidi == null || erika == null)
			{
				mls.LogError((object)"Failed to load an audio clip");
			}
			harmony.PatchAll(typeof(CursedSoundMod));
			harmony.PatchAll(typeof(LandmineTriggerPatch));
			harmony.PatchAll(typeof(RecordPlayerPatch));
			mls.LogInfo((object)"Cursed Mine sound loaded!");
		}

		private string FindBooombitchFolder()
		{
			string pluginPath = Paths.PluginPath;
			string[] directories = Directory.GetDirectories(pluginPath, "Booombitch", SearchOption.AllDirectories);
			if (directories.Length != 0)
			{
				return directories[0];
			}
			return null;
		}

		private static AudioClip LoadAudioClip(string filepath)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Invalid comparison between Unknown and I4
			ManualLogSource val = Logger.CreateLogSource("toemmsen.CursedSoundMod");
			val.LogInfo((object)("Loading audio clip from " + filepath));
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(filepath, (AudioType)13);
			audioClip.SendWebRequest();
			while (!audioClip.isDone)
			{
			}
			if (audioClip.error != null)
			{
				val.LogError((object)"Failed to load audio clip");
			}
			AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
			if ((Object)(object)content != (Object)null && (int)content.loadState == 2)
			{
				val.LogInfo((object)"Loaded audio clip successfully!");
				return content;
			}
			return null;
		}
	}
}
namespace CursedSoundMod.Patches
{
	[HarmonyPatch(typeof(Landmine))]
	internal class LandmineTriggerPatch
	{
		[HarmonyPatch("SetOffMineAnimation")]
		[HarmonyPrefix]
		private static void TriggerPatch(ref AudioSource ___mineAudio)
		{
			AudioClip newSFX = CursedSoundMod.newSFX;
			___mineAudio.PlayOneShot(newSFX, 1f);
		}
	}
	[HarmonyPatch(typeof(AnimatedObjectTrigger))]
	internal class RecordPlayerPatch
	{
		[HarmonyPatch("PlayAudio")]
		[HarmonyPrefix]
		private static void RecPatch(ref InteractTrigger __instance, ref AudioClip ___playWhileTrue, bool boolVal, bool playSecondaryAudios = false)
		{
			AudioClip erika = CursedSoundMod.erika;
			try
			{
				bool flag = false;
				Component[] componentsInParent = ((Component)__instance).gameObject.GetComponentsInParent(typeof(Component));
				Component[] array = componentsInParent;
				foreach (Component val in array)
				{
					if (((Object)val).name.Contains("RecordPlayer"))
					{
						flag = true;
						break;
					}
				}
				if (flag && (Object)(object)erika != (Object)null)
				{
					___playWhileTrue = erika;
				}
			}
			catch (Exception)
			{
			}
		}
	}
}