Decompiled source of Barber Clock Tower v0.1.0

plugins/BarberClockTower.dll

Decompiled 3 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BarberClockTower.Patches;
using BepInEx;
using BepInEx.Logging;
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("BarberClockTower")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BarberClockTower")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("65891697-b0dc-4cdd-b269-fbf8965a338b")]
[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 BarberClockTower
{
	[BepInPlugin("Zomagon.BarberClockTower", "Barber Clock Tower Mod", "1.0.0.0")]
	public class BarberClockTower : BaseUnityPlugin
	{
		private const string modGUID = "Zomagon.BarberClockTower";

		private const string modName = "Barber Clock Tower Mod";

		private const string modVersion = "1.0.0.0";

		private readonly Harmony harmony = new Harmony("Zomagon.BarberClockTower");

		private static BarberClockTower Instance;

		internal static ManualLogSource mls;

		public static AssetBundle ModAssets;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Zomagon.BarberClockTower");
			mls.LogInfo((object)"The Scissorman has awoken.");
			harmony.PatchAll(typeof(BarberClockTower));
			harmony.PatchAll(typeof(ClaySurgeonAIPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			string path = "barberclocktower";
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load custom assets.");
			}
		}
	}
}
namespace BarberClockTower.Patches
{
	[HarmonyPatch(typeof(ClaySurgeonAI))]
	internal class ClaySurgeonAIPatch
	{
		private static AudioClip clockTowerMus = null;

		internal static Dictionary<ClaySurgeonAI, AudioSource> surgeonSources = new Dictionary<ClaySurgeonAI, AudioSource>();

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void claySurgeonMusicStart(ClaySurgeonAI __instance)
		{
			if ((Object)(object)clockTowerMus == (Object)null)
			{
				if ((Object)(object)BarberClockTower.ModAssets == (Object)null)
				{
					BarberClockTower.mls.LogInfo((object)"Failed to load clockTowerMus asset bundle");
					return;
				}
				clockTowerMus = BarberClockTower.ModAssets.LoadAsset<AudioClip>("Clock Tower - Scissorman.mp3");
			}
			if (StartOfRoundPatch.surgeonSourceCount < 1)
			{
				AudioSource val = ((Component)__instance).gameObject.AddComponent<AudioSource>();
				val.clip = clockTowerMus;
				val.volume = 40f;
				val.loop = true;
				val.dopplerLevel = 0f;
				val.spatialBlend = 1f;
				val.maxDistance = 300f;
				val.spatialize = false;
				surgeonSources[__instance] = val;
			}
			StartOfRoundPatch.surgeonSourceCount++;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void claySurgeonMusicUpdate(ClaySurgeonAI __instance)
		{
			AudioSource val = surgeonSources[__instance];
			if (((EnemyAI)__instance).isEnemyDead)
			{
				val.Stop();
			}
			else if (!val.isPlaying)
			{
				if (val.time > 0f && (double)val.time <= (double)clockTowerMus.length - 0.1)
				{
					val.UnPause();
				}
				else
				{
					val.Play();
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		internal static int surgeonSourceCount;

		private static StartOfRoundPatch Instance;

		[HarmonyPatch("openingDoorsSequence")]
		[HarmonyPostfix]
		private static void PatchOpeningDoorsSequence()
		{
			ClaySurgeonAIPatch.surgeonSources.Clear();
			surgeonSourceCount = 0;
		}
	}
}