Decompiled source of OE Tweaks FlowermanISeeYou v1.0.3

FlowermanISeeYou.dll

Decompiled 11 months ago
using System.Collections.Generic;
using System.Diagnostics;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FlowermanISeeYou")]
[assembly: AssemblyDescription("Adds a creepy sound effect to the flowerman")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("OE.Tweaks")]
[assembly: AssemblyProduct("FlowermanISeeYou")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2b125f01-965c-4e77-b82d-31d99dd36577")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace FlowermanISeeYou
{
	[BepInPlugin("oe.tweaks.sounds.flowerman", "Flowerman I See You", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("oe.tweaks.sounds.flowerman");

		private const string GUID = "oe.tweaks.sounds.flowerman";

		private const string NAME = "Flowerman I See You";

		private const string VERSION = "1.0.0";

		internal static Plugin instance;

		internal static ManualLogSource log;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			log.LogInfo((object)"'Flowerman I See You' is loading...");
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			harmony.PatchAll();
			log.LogInfo((object)"'Flowerman I See You' loaded!");
		}
	}
}
namespace FlowermanISeeYou.Patches
{
	[HarmonyPatch(typeof(FlowermanAI))]
	internal class FlowermanAIPatch
	{
		internal static AudioClip flowermanISeeYouSound = null;

		internal static Dictionary<FlowermanAI, int> timesTriggeredSound = new Dictionary<FlowermanAI, int>();

		internal static float nextTimeToSwitchSlot = 0f;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch(FlowermanAI __instance)
		{
			Plugin.log.LogInfo((object)"Patching flowerman sounds...");
			if ((Object)(object)flowermanISeeYouSound == (Object)null)
			{
				AssetBundle val = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetManifestResourceNames()[0]));
				if ((Object)(object)val == (Object)null)
				{
					Plugin.log.LogError((object)"Failed to load flowermansounds asset bundle");
					return;
				}
				flowermanISeeYouSound = val.LoadAsset<AudioClip>("flowerman_i_see_you.mp3");
			}
			timesTriggeredSound[__instance] = 0;
			((Component)__instance).GetComponent<AudioSource>().clip = flowermanISeeYouSound;
			((Component)__instance).GetComponent<AudioSource>().volume = 0.8f;
			((Component)__instance).GetComponent<AudioSource>().maxDistance = 50f;
			((Component)__instance).GetComponent<AudioSource>().spatialBlend = 0.5f;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void patchFlowermanISeeYouSoundUpdate(FlowermanAI __instance)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)flowermanISeeYouSound == (Object)null)
			{
				Plugin.log.LogWarning((object)"Flowerman sound asset bundle not found");
			}
			else if (timesTriggeredSound[__instance] <= 2 && GameNetworkManager.Instance.localPlayerController.HasLineOfSightToPosition(((Component)__instance).transform.position + Vector3.up * 0.5f, 30f, 60, -1f) && ((EnemyAI)__instance).currentBehaviourStateIndex != 2 && !((Component)__instance).GetComponent<AudioSource>().isPlaying)
			{
				((Component)__instance).GetComponent<AudioSource>().Play();
				timesTriggeredSound[__instance]++;
			}
		}

		[HarmonyPatch(typeof(RoundManager), "GenerateNewFloor")]
		[HarmonyPrefix]
		private static void resetSavedData()
		{
			timesTriggeredSound.Clear();
		}
	}
}