Decompiled source of BKBracken v1.0.2

MichaelBracken.dll

Decompiled 6 months ago
using System;
using System.Collections;
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 HEHE.Patch;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MichaelBracken")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MichaelBracken")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("879d6f79-45d4-4f88-8ad2-dd273c46fb3b")]
[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")]
public static class CoroutineHelper
{
	private class CoroutineRunner : MonoBehaviour
	{
	}

	private static GameObject coroutineObject;

	public static void StartCoroutine(IEnumerator coroutine)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		if ((Object)(object)coroutineObject == (Object)null)
		{
			coroutineObject = new GameObject("CoroutineHelper");
			Object.DontDestroyOnLoad((Object)(object)coroutineObject);
		}
		((MonoBehaviour)coroutineObject.AddComponent<CoroutineRunner>()).StartCoroutine(coroutine);
	}
}
namespace HEHE
{
	[BepInPlugin("Lecre.MichaelBrackenMod", "LC MichaelBrackenMod", "1.0.0")]
	public class HeheBase : BaseUnityPlugin
	{
		private const string modGUID = "Lecre.MichaelBrackenMod";

		private const string modName = "LC MichaelBrackenMod";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Lecre.MichaelBrackenMod");

		public static HeheBase instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("Lecre.MichaelBrackenMod");
			mls.LogInfo((object)"Lecre.MichaelBrackenMod is loading");
			harmony.PatchAll(typeof(HeheBase));
			harmony.PatchAll(typeof(HeheSound));
		}
	}
}
namespace HEHE.Patch
{
	[HarmonyPatch(typeof(FlowermanAI))]
	internal class HeheSound
	{
		public static FlowermanAI killingFlowerMan;

		private static AudioClip newSFX;

		private static ManualLogSource mls;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void prepareAudio()
		{
			mls = Logger.CreateLogSource("Lecre.MichaelBrackenMod");
			mls.LogInfo((object)"Starting to upload audio");
			if ((Object)(object)HeheBase.instance != (Object)null)
			{
				string location = ((BaseUnityPlugin)HeheBase.instance).Info.Location;
				string text = "MichaelBracken.dll";
				string text2 = location.TrimEnd(text.ToCharArray());
				string text3 = text2 + "HEHEsound.wav";
				((MonoBehaviour)HeheBase.instance).StartCoroutine(LoadAudio("file:///" + text3, delegate(AudioClip clip)
				{
					newSFX = clip;
				}));
				return;
			}
			mls.LogWarning((object)"Instance was readed like <null> retriying to load audio files");
			string location2 = Assembly.GetExecutingAssembly().Location;
			string directoryName = Path.GetDirectoryName(location2);
			string text4 = Path.Combine(directoryName, "HEHEsound.wav");
			mls.LogInfo((object)("(else) IS THE AUDIO FILE LOCATED HERE??: " + text4));
			CoroutineHelper.StartCoroutine(LoadAudio("file:///" + text4, delegate(AudioClip sound)
			{
				newSFX = sound;
			}));
		}

		private static IEnumerator LoadAudio(string url, Action<AudioClip> callback)
		{
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, (AudioType)20);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result == 2)
				{
					mls.LogError((object)"Failed to load audio assets!");
					yield break;
				}
				AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
				if ((Object)(object)clip == (Object)null)
				{
					mls.LogError((object)"The audio clip is null after loading!");
					yield break;
				}
				callback(clip);
				mls.LogInfo((object)"Audio inserted");
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void FlowerManAudioKillPatch(ref FlowermanAI __instance)
		{
			if (__instance.inKillAnimation && (Object)(object)killingFlowerMan == (Object)null)
			{
				float maxDistance = 100f;
				killingFlowerMan = __instance;
				AudioSource val = ((Component)__instance).gameObject.AddComponent<AudioSource>();
				val.clip = newSFX;
				val.maxDistance = maxDistance;
				val.Play();
				mls.LogInfo((object)"The Bracken got someone HEHE");
			}
			if (!__instance.inKillAnimation && (Object)(object)__instance == (Object)(object)killingFlowerMan)
			{
				killingFlowerMan = null;
			}
		}
	}
}