Decompiled source of WheezerBug v1.0.2

WheezerBug.dll

Decompiled 2 weeks 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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WheezerBug")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WheezerBug")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("291b9de5-a65e-4e92-b966-1d39130771d4")]
[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 WheezerBug
{
	[BepInPlugin("KadenBiel.WheezerBug", "WheezerBug", "1.0.1")]
	public class BugBase : BaseUnityPlugin
	{
		private const string modGUID = "KadenBiel.WheezerBug";

		private const string modName = "WheezerBug";

		private const string modVersion = "1.0.1";

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

		private static BugBase Instance;

		public static ManualLogSource mls;

		public static AssetBundle BugAssets;

		public static GameObject BugPrefab;

		public static AudioClip Chat1;

		public static AudioClip Chat2;

		public static AudioClip Chat3;

		public static AudioClip Chat4;

		public static AudioClip Chat5;

		public static AudioClip Chat6;

		public static AudioClip Chat7;

		public static AudioClip Holly;

		public static AudioClip Mad1;

		public static AudioClip Mad2;

		public static AudioClip Mad3;

		public static string modDir;

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

		private static void LoadAssets()
		{
			try
			{
				BugAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(modDir), "wheezerbug"));
			}
			catch (Exception ex)
			{
				mls.LogError((object)("AssetBundle failed to load -- " + ex.Message));
				return;
			}
			try
			{
				BugPrefab = BugAssets.LoadAsset<GameObject>("WheezerBug.prefab");
				Chat1 = BugAssets.LoadAsset<AudioClip>("AlmostAsPretty.ogg");
				Holly = BugAssets.LoadAsset<AudioClip>("BuddyHolly.ogg");
				Chat2 = BugAssets.LoadAsset<AudioClip>("CROISSANT.ogg");
				Chat3 = BugAssets.LoadAsset<AudioClip>("DeadPDF.ogg");
				Mad1 = BugAssets.LoadAsset<AudioClip>("DontFeelGood.ogg");
				Mad2 = BugAssets.LoadAsset<AudioClip>("GonnaCry.ogg");
				Chat4 = BugAssets.LoadAsset<AudioClip>("HiJimmysMom.ogg");
				Chat5 = BugAssets.LoadAsset<AudioClip>("HiMrsNeutron.ogg");
				Chat6 = BugAssets.LoadAsset<AudioClip>("Pincones.ogg");
				Chat7 = BugAssets.LoadAsset<AudioClip>("Valentine.ogg");
				Mad3 = BugAssets.LoadAsset<AudioClip>("WhatWeHave.ogg");
				mls.LogInfo((object)"Wheezer Assets Loaded");
			}
			catch (Exception ex2)
			{
				mls.LogError((object)("Failed to load assets -- " + ex2.Message));
			}
		}
	}
}
namespace WheezerBug.Patches
{
	[HarmonyPatch]
	internal class BugPatch
	{
		[HarmonyPatch(typeof(HoarderBugAI), "Start")]
		[HarmonyPostfix]
		private static void addController(ButlerEnemyAI __instance)
		{
			((Component)__instance).gameObject.AddComponent<CarlController>();
			BugBase.mls.LogInfo((object)"Carl Instantiated");
		}
	}
	internal class CarlController : MonoBehaviour
	{
		private static GameObject Carl;

		private HoarderBugAI BugAI { get; set; }

		private Animator Animator { get; set; }

		private bool IsDead { get; set; }

		private Vector3 prevPosition { get; set; }

		private void LoadAudio()
		{
			BugAI.chitterSFX = (AudioClip[])(object)new AudioClip[7]
			{
				BugBase.Chat1,
				BugBase.Chat2,
				BugBase.Chat3,
				BugBase.Chat4,
				BugBase.Chat5,
				BugBase.Chat6,
				BugBase.Chat7
			};
			BugAI.angryScreechSFX = (AudioClip[])(object)new AudioClip[3]
			{
				BugBase.Mad1,
				BugBase.Mad2,
				BugBase.Mad3
			};
			BugAI.bugFlySFX = BugBase.Holly;
			BugBase.mls.LogInfo((object)"Audio Replaced");
		}

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

		private void EnableCarl()
		{
			try
			{
				MeshRenderer[] componentsInChildren = Carl.GetComponentsInChildren<MeshRenderer>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Renderer)componentsInChildren[i]).enabled = true;
				}
			}
			catch (Exception ex)
			{
				BugBase.mls.LogError((object)("Failed to find Carl 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)
			BugBase.mls.LogInfo((object)"Carl Started");
			BugAI = ((Component)this).GetComponent<HoarderBugAI>();
			Carl = Object.Instantiate<GameObject>(BugBase.BugPrefab, ((Component)BugAI).transform.position, Quaternion.identity, ((Component)BugAI).transform);
			Animator = Carl.GetComponent<Animator>();
			LoadAudio();
			HideBugModel();
			EnableCarl();
		}

		private void Update()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Animator.SetBool("isFlying", ((EnemyAI)BugAI).movingTowardsTargetPlayer);
			Animator.SetBool("isMoving", prevPosition != ((Component)this).transform.position);
			prevPosition = ((Component)this).transform.position;
			if (((EnemyAI)BugAI).isEnemyDead && !IsDead)
			{
				KillGoku();
			}
		}

		private void KillGoku()
		{
			Animator.SetBool("isDead", true);
			IsDead = true;
			BugBase.mls.LogInfo((object)"Carl Died");
		}
	}
}