Decompiled source of DeadlyBrackens v1.0.0

DeadlyBrackens.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using DeadlyBrackens.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("DeadlyBrackens")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Bracken becomes wolf from Puss in Boots")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DeadlyBrackens")]
[assembly: AssemblyTitle("DeadlyBrackens")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DeadlyBrackens
{
	[BepInPlugin("DeadlyBrackens", "DeadlyBrackens", "1.0.0")]
	public class DeadlyBrackensPlugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("DeadlyBrackens_1.0.0");

		public static DeadlyBrackensPlugin Instance;

		internal ManualLogSource mls;

		public const string PluginFolderName = "PaTkan-DeadlyBrackens";

		public AudioClip[] whistling { get; set; }

		public static string AudioClipsPath => Path.Combine(Paths.PluginPath, "PaTkan-DeadlyBrackens", "DeadlyBrackens");

		public static void LogInfo(object data)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo(data);
		}

		public static void LogError(object data)
		{
			((BaseUnityPlugin)Instance).Logger.LogError(data);
		}

		public static void DebugLog(object data)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo(data);
		}

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			if ((Object)Instance == (Object)null)
			{
				Instance = this;
			}
			harmony.PatchAll(typeof(BrackenUpdatePatch));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DeadlyBrackens";

		public const string PLUGIN_NAME = "DeadlyBrackens";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace DeadlyBrackens.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))
			{
				DeadlyBrackensPlugin.Instance.whistling = (AudioClip[])(object)new AudioClip[2];
				string path = "file://" + Path.Combine(DeadlyBrackensPlugin.AudioClipsPath, "whistling.mp3");
				UnityWebRequest audioClip2 = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)13);
				audioClip2.SendWebRequest();
				while (!audioClip2.isDone)
				{
				}
				DeadlyBrackensPlugin.Instance.whistling[0] = DownloadHandlerAudioClip.GetContent(audioClip2);
				path = "file://" + Path.Combine(DeadlyBrackensPlugin.AudioClipsPath, "whistling2.mp3");
				audioClip2 = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)13);
				audioClip2.SendWebRequest();
				while (!audioClip2.isDone)
				{
				}
				DeadlyBrackensPlugin.Instance.whistling[1] = DownloadHandlerAudioClip.GetContent(audioClip2);
				flowermanAudioInfo = new FlowermanAudioInfo
				{
					IsPlaying = false,
					AudioSource = ((Component)__instance).gameObject.AddComponent<AudioSource>()
				};
				flowermanAudioInfo.AudioSource.playOnAwake = false;
				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;
				flowermanAudioInfo.AudioSource.loop = true;
				flowermanAudioInfoMap[__instance] = flowermanAudioInfo;
			}
			if ((__instance.evadeStealthTimer != 0f || ((EnemyAI)__instance).movingTowardsTargetPlayer || __instance.isInAngerMode || __instance.inKillAnimation || __instance.carryingPlayerBody || ((EnemyAI)__instance).tempDist > 30f) && flowermanAudioInfo.IsPlaying)
			{
				flowermanAudioInfo.AudioSource.Stop();
				flowermanAudioInfo.AudioSource.clip = null;
				flowermanAudioInfo.IsPlaying = false;
			}
			if (__instance.evadeStealthTimer == 0f && !((EnemyAI)__instance).movingTowardsTargetPlayer && !__instance.isInAngerMode && !__instance.inKillAnimation && !__instance.carryingPlayerBody && !flowermanAudioInfo.IsPlaying && ((EnemyAI)__instance).tempDist <= 30f && (Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null)
			{
				flowermanAudioInfo.IsPlaying = true;
				int idx = Random.Range(0, DeadlyBrackensPlugin.Instance.whistling.Length);
				flowermanAudioInfo.AudioSource.clip = DeadlyBrackensPlugin.Instance.whistling[idx];
				DeadlyBrackensPlugin.DebugLog($"Playing whistling{idx + 1}");
				flowermanAudioInfo.AudioSource.Play();
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}