Decompiled source of CreepyBrackensReplacement v1.0.1

CreepyBrackens.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using CreepyBrackens.Patches;
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("CreepyBrackens")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CreepyBrackens")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9568b680-cde8-423a-b296-7890f2293a27")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace CreepyBrackens
{
	[BepInPlugin("ColtG5.CreepyBrackens", "CreepyBrackens", "1.0.0")]
	public class CreepyBrackens : BaseUnityPlugin
	{
		private const string modGUID = "ColtG5.CreepyBrackens";

		private const string modName = "CreepyBrackens";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("ColtG5.CreepyBrackens");

		private static CreepyBrackens Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("ColtG5.CreepyBrackens");
			harmony.PatchAll(typeof(BrackenUpdatePatch));
			mls.LogInfo((object)"Successfully patched CreepyBrackens into the game !!!!");
		}
	}
}
namespace CreepyBrackens.Patches
{
	[HarmonyPatch(typeof(FlowermanAI))]
	internal class BrackenUpdatePatch
	{
		private class FlowermanAudioInfo
		{
			public bool IsPlaying { get; set; }

			public AudioSource AudioSource { get; set; }
		}

		private static Dictionary<FlowermanAI, FlowermanAudioInfo> flowermanAudioInfoMap = new Dictionary<FlowermanAI, FlowermanAudioInfo>();

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static async void UpdatePatch(FlowermanAI __instance)
		{
			if (!flowermanAudioInfoMap.TryGetValue(__instance, out var flowermanAudioInfo))
			{
				flowermanAudioInfo = new FlowermanAudioInfo
				{
					IsPlaying = false,
					AudioSource = ((Component)__instance).gameObject.AddComponent<AudioSource>()
				};
				flowermanAudioInfo.AudioSource.spatialBlend = 1f;
				flowermanAudioInfo.AudioSource.dopplerLevel = 1f;
				flowermanAudioInfo.AudioSource.rolloffMode = (AudioRolloffMode)0;
				flowermanAudioInfo.AudioSource.minDistance = 5f;
				flowermanAudioInfo.AudioSource.maxDistance = 50f;
				flowermanAudioInfo.AudioSource.volume = 0.8f;
				flowermanAudioInfoMap[__instance] = flowermanAudioInfo;
			}
			if (__instance.wasInEvadeMode && flowermanAudioInfo.IsPlaying)
			{
				flowermanAudioInfo.AudioSource.Stop();
				flowermanAudioInfo.IsPlaying = false;
			}
			if (!__instance.wasInEvadeMode && !flowermanAudioInfo.IsPlaying && ((EnemyAI)__instance).mostOptimalDistance <= 50f)
			{
				flowermanAudioInfo.IsPlaying = true;
				string path = "file://" + Paths.PluginPath + "\\ColtG5-CreepyBrackens\\creepy-bracken-sound.mp3";
				UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)13);
				audioClip.SendWebRequest();
				while (!audioClip.isDone)
				{
				}
				AudioClip clip = DownloadHandlerAudioClip.GetContent(audioClip);
				flowermanAudioInfo.AudioSource.clip = clip;
				flowermanAudioInfo.AudioSource.PlayOneShot(clip);
				Random random = new Random();
				double randomDelay = random.NextDouble() * 5.0 + 5.0;
				Task.Run(async delegate
				{
					await Task.Delay(TimeSpan.FromSeconds((double)clip.length + randomDelay));
					flowermanAudioInfo.AudioSource.Stop();
					flowermanAudioInfo.IsPlaying = false;
				});
			}
		}
	}
}