Decompiled source of TrumpButler v1.0.3

TrumpButler.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TrumpButler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TrumpButler")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("af17630c-fa9e-46d0-9b5b-8a03d03ed068")]
[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 TrumpButler
{
	[BepInPlugin("KadenBiel.TrumpButler", "TrumpButler", "1.0.0")]
	public class TrumpButlerBase : BaseUnityPlugin
	{
		private const string modGUID = "KadenBiel.TrumpButler";

		private const string modName = "TrumpButler";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("KadenBiel.TrumpButler");

		private static TrumpButlerBase Instance;

		public static ManualLogSource mls;

		public static AssetBundle TrumpButlerAssets;

		public static GameObject TrumpPrefab;

		public static AudioClip Ambient;

		public static AudioClip MurderMusic;

		public static AudioClip Death;

		public static AudioClip Hurt;

		public static AudioClip Angry;

		public static AudioClip Chatter1;

		public static AudioClip Chatter2;

		public static AudioClip Chatter3;

		public static Material[] TrumpMaterials;

		public static string modDir;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			modDir = ((BaseUnityPlugin)this).Info.Location;
			mls = Logger.CreateLogSource("KadenBiel.TrumpButler");
			LoadAssets();
			mls.LogInfo((object)"TrumpButler is awake");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}

		private static void LoadAssets()
		{
			try
			{
				TrumpButlerAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(modDir), "trumpbundle"));
			}
			catch (Exception ex)
			{
				mls.LogError((object)("AssetBundle failed to load -- " + ex.Message));
				return;
			}
			try
			{
				TrumpPrefab = TrumpButlerAssets.LoadAsset<GameObject>("Trump.prefab");
				Ambient = TrumpButlerAssets.LoadAsset<AudioClip>("GodBless.ogg");
				MurderMusic = TrumpButlerAssets.LoadAsset<AudioClip>("MURICA.ogg");
				Death = TrumpButlerAssets.LoadAsset<AudioClip>("DiedLikeADog.ogg");
				Hurt = TrumpButlerAssets.LoadAsset<AudioClip>("SmallLoan.ogg");
				Angry = TrumpButlerAssets.LoadAsset<AudioClip>("GetThoseLightsOff.ogg");
				Chatter1 = TrumpButlerAssets.LoadAsset<AudioClip>("AllBS.ogg");
				Chatter2 = TrumpButlerAssets.LoadAsset<AudioClip>("FakeNews.ogg");
				Chatter3 = TrumpButlerAssets.LoadAsset<AudioClip>("WinMore.ogg");
				mls.LogInfo((object)"Trump Assets Loaded");
			}
			catch (Exception ex2)
			{
				mls.LogError((object)("Failed to load assets -- " + ex2.Message));
			}
		}
	}
}
namespace TrumpButler.Patches
{
	[HarmonyPatch]
	internal class ButlerPatch
	{
		[HarmonyPatch(typeof(ButlerEnemyAI), "Start")]
		[HarmonyPostfix]
		private static void addController(ButlerEnemyAI __instance)
		{
			((Component)__instance).gameObject.AddComponent<TrumpController>();
			TrumpButlerBase.mls.LogInfo((object)"Trump Instantiated");
		}

		[HarmonyPatch(typeof(ButlerEnemyAI), "AnimationEventB")]
		[HarmonyPrefix]
		private static void AnimationEventB(ButlerEnemyAI __instance)
		{
			if (((EnemyAI)__instance).creatureSFX.isPlaying && __instance.broomSweepSFX.Contains(((EnemyAI)__instance).creatureSFX.clip))
			{
				((EnemyAI)__instance).creatureSFX.Stop();
			}
		}
	}
	internal class TrumpController : MonoBehaviour
	{
		private static GameObject Trump;

		private static int Stopped;

		private ButlerEnemyAI ButlerAI { get; set; }

		private Animator Animator { get; set; }

		private bool IsDead { get; set; }

		private Vector3 prevPosition { get; set; }

		private void LoadAudio()
		{
			((EnemyAI)ButlerAI).dieSFX = TrumpButlerBase.Death;
			ButlerAI.broomSweepSFX = (AudioClip[])(object)new AudioClip[3]
			{
				TrumpButlerBase.Chatter1,
				TrumpButlerBase.Chatter2,
				TrumpButlerBase.Chatter3
			};
			ButlerEnemyAI.murderMusicAudio.clip = TrumpButlerBase.MurderMusic;
			ButlerAI.ambience1.clip = TrumpButlerBase.Ambient;
			ButlerAI.ambience1.maxDistance = 20f;
			((EnemyAI)ButlerAI).enemyType.deathSFX = TrumpButlerBase.Death;
			((EnemyAI)ButlerAI).enemyType.hitBodySFX = TrumpButlerBase.Hurt;
			TrumpButlerBase.mls.LogInfo((object)"Audio Replaced");
		}

		private void HideButlerModel()
		{
			try
			{
				TrumpButlerBase.mls.LogInfo((object)"Attempting to find butler");
				Renderer[] componentsInChildren = ((Component)((Component)ButlerAI).transform.Find("MeshContainer")).GetComponentsInChildren<Renderer>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].enabled = false;
				}
				for (int j = 0; j < ((Component)ButlerAI).transform.childCount - 1; j++)
				{
					TrumpButlerBase.mls.LogInfo((object)("Index: " + j + " Name: " + ((Object)((Component)ButlerAI).transform.GetChild(j)).name));
				}
				TrumpButlerBase.mls.LogInfo((object)"Butler Hidden");
			}
			catch (Exception ex)
			{
				TrumpButlerBase.mls.LogError((object)("Failed to find Butler Model: " + ex.Message));
			}
		}

		private void EnableTrump()
		{
			try
			{
				TrumpButlerBase.mls.LogInfo((object)"Attempting to find butler");
				MeshRenderer[] componentsInChildren = Trump.GetComponentsInChildren<MeshRenderer>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Renderer)componentsInChildren[i]).enabled = true;
				}
				TrumpButlerBase.mls.LogInfo((object)"Butler Hidden");
			}
			catch (Exception ex)
			{
				TrumpButlerBase.mls.LogError((object)("Failed to find Trump Model: " + ex.Message));
			}
		}

		private void Start()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			TrumpButlerBase.mls.LogInfo((object)"Trump Started");
			ButlerAI = ((Component)this).GetComponent<ButlerEnemyAI>();
			Trump = Object.Instantiate<GameObject>(TrumpButlerBase.TrumpPrefab, ((Component)ButlerAI).transform.position, Quaternion.identity, ((Component)ButlerAI).transform);
			Animator = Trump.GetComponent<Animator>();
			LoadAudio();
			HideButlerModel();
			EnableTrump();
		}

		private void Update()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)ButlerAI).creatureSFX.isPlaying && Stopped < 10)
			{
				((EnemyAI)ButlerAI).creatureSFX.Stop();
				Stopped++;
			}
			Animator.SetBool("isAngry", 2 == ((EnemyAI)ButlerAI).currentBehaviourStateIndex);
			Animator.SetBool("isWalking", prevPosition != ((Component)this).transform.position && !Animator.GetBool("isAngry"));
			Animator.SetBool("isStabbing", ButlerAI.stabBloodParticle.isPlaying);
			prevPosition = ((Component)this).transform.position;
			if (((EnemyAI)ButlerAI).isEnemyDead && !IsDead)
			{
				KillGoku();
			}
		}

		private void KillGoku()
		{
			Animator.SetBool("isAngry", false);
			Animator.SetBool("isDead", true);
			IsDead = true;
			TrumpButlerBase.mls.LogInfo((object)"Trump Died");
			((EnemyAI)ButlerAI).creatureSFX.Stop();
		}
	}
}