Decompiled source of Thumper Chase Music v1.0.2

ThumperChaseMusic.dll

Decompiled 7 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 HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ThumperChaseMusic")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ThumperChaseMusic")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9b2180d0-c688-468f-a1bc-6ed3e069d8cc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ThumperChaseMusic
{
	[BepInPlugin("oe.tweaks.sounds.thumper", "Thumper Chase Music", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("oe.tweaks.sounds.thumper");

		private const string GUID = "oe.tweaks.sounds.thumper";

		private const string NAME = "Thumper Chase Music";

		private const string VERSION = "1.0.0";

		internal static Plugin instance;

		internal static ManualLogSource log;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			log.LogInfo((object)"'Thumper Chase Music' is loading...");
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			harmony.PatchAll();
			log.LogInfo((object)"'Thumper Chase Music' loaded!");
		}
	}
}
namespace ThumperChaseMusic.Patches
{
	[HarmonyPatch(typeof(CrawlerAI))]
	internal class CrawlerAIPatch
	{
		private static AudioClip thumperSound = null;

		internal static Dictionary<CrawlerAI, AudioSource> crawlerSources = new Dictionary<CrawlerAI, AudioSource>();

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void patchThumperChaseSoundStart(CrawlerAI __instance)
		{
			Plugin.log.LogInfo((object)"Patching CrawlerAI...");
			if ((Object)(object)thumperSound == (Object)null)
			{
				AssetBundle val = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetManifestResourceNames()[0]));
				if ((Object)(object)val == (Object)null)
				{
					Plugin.log.LogError((object)"Failed to load thumpersounds asset bundle");
					return;
				}
				thumperSound = val.LoadAsset<AudioClip>("thumper_chase.mp3");
			}
			AudioSource val2 = ((Component)__instance).gameObject.AddComponent<AudioSource>();
			val2.clip = thumperSound;
			val2.volume = 0.8f;
			val2.loop = true;
			val2.dopplerLevel = 0f;
			val2.spatialBlend = 0.7f;
			val2.maxDistance = 150f;
			crawlerSources[__instance] = val2;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void patchTumperChaseSoundUpdate(CrawlerAI __instance)
		{
			AudioSource val = crawlerSources[__instance];
			if (((EnemyAI)__instance).isEnemyDead)
			{
				val.Stop();
			}
			if (((EnemyAI)__instance).currentBehaviourStateIndex == 0 && val.isPlaying)
			{
				val.Pause();
			}
			else if (((EnemyAI)__instance).currentBehaviourStateIndex != 0 && !val.isPlaying)
			{
				if (val.time > 0f && (double)val.time <= (double)thumperSound.length - 0.1)
				{
					val.UnPause();
				}
				else
				{
					val.Play();
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPatch("openingDoorsSequence")]
		[HarmonyPostfix]
		private static void PatchOpeningDoorsSequence()
		{
			CrawlerAIPatch.crawlerSources.Clear();
		}
	}
}