Decompiled source of ThomasTheThumpEngine v1.0.4

ThomasTheThumpEngine.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 HarmonyLib;
using LCSoundTool;
using ThomasTheThumpEngine.Patches;
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("ThomasTheThumpEngine")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ThomasTheThumpEngine")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b4daa324-0181-4b65-a75e-3582a3d0c930")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ThomasTheThumpEngine
{
	[BepInPlugin("LineLoad.ThomasTheThumpEngine", "Thomas The Thump Engine", "1.0.4")]
	public class ThumperThomasBase : BaseUnityPlugin
	{
		private const string pluginGUID = "LineLoad.ThomasTheThumpEngine";

		private const string pluginName = "Thomas The Thump Engine";

		private const string pluginVersion = "1.0.4";

		private readonly Harmony harmony = new Harmony("LineLoad.ThomasTheThumpEngine");

		public static ThumperThomasBase Instance;

		internal ManualLogSource logger;

		public static AudioClip thomasTheme;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("LineLoad.ThomasTheThumpEngine");
			logger.LogInfo((object)"Plugin LineLoad.ThomasTheThumpEngine is loaded!");
			harmony.PatchAll(typeof(ThumperThomasBase));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(CrawlerAIPatch));
			harmony.PatchAll(typeof(EnemyAIPatch));
		}
	}
}
namespace ThomasTheThumpEngine.Patches
{
	[HarmonyPatch(typeof(CrawlerAI))]
	internal class CrawlerAIPatch : MonoBehaviour
	{
		[HarmonyPatch("BeginChasingPlayerClientRpc")]
		[HarmonyPostfix]
		private static void PlayTheme(CrawlerAI __instance, ref bool ___hasEnteredChaseMode)
		{
			if (((EnemyAI)__instance).currentBehaviourStateIndex == 1 && !___hasEnteredChaseMode)
			{
				((EnemyAI)__instance).creatureVoice.PlayOneShot(ThumperThomasBase.thomasTheme);
				ThumperThomasBase.Instance.logger.LogDebug((object)"Chase theme started!");
			}
		}
	}
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyAIPatch : MonoBehaviour
	{
		[HarmonyPatch("KillEnemyClientRpc")]
		[HarmonyPrefix]
		private static void StopThemeOnDeath(EnemyAI __instance)
		{
			if (isEnemy(__instance, "crawler"))
			{
				StopTheme(__instance);
			}
		}

		[HarmonyPatch("SwitchToBehaviourStateOnLocalClient")]
		[HarmonyPostfix]
		private static void StopThemeOnPassiveBehaviourState(EnemyAI __instance)
		{
			if (__instance.currentBehaviourStateIndex == 0 && isEnemy(__instance, "crawler"))
			{
				StopTheme(__instance);
			}
		}

		private static void StopTheme(EnemyAI __instance)
		{
			__instance.creatureVoice.Stop();
			ThumperThomasBase.Instance.logger.LogDebug((object)"Chase theme stopped!");
		}

		private static bool isEnemy(EnemyAI enemy, string enemyName)
		{
			return enemy.enemyType.enemyName.ToLower() == enemyName.ToLower();
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void LoadTheme()
		{
			try
			{
				string text = Path.Combine(Paths.PluginPath, "LineLoad-ThomasTheThumpEngine");
				ThumperThomasBase.thomasTheme = SoundTool.GetAudioClip(text, "Thomas_the_Tank_Engine_Theme.ogg");
				ThumperThomasBase.Instance.logger.LogInfo((object)"Chase theme loaded successfully!");
			}
			catch (Exception ex)
			{
				ThumperThomasBase.Instance.logger.LogWarning((object)ex);
			}
		}
	}
}