using System;
using System.Collections;
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 BepInEx;
using BepInEx.Logging;
using FlowerMorgan.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("FlowerMorgan")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FlowerMorgan")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("db01ec03-a680-4a4e-a34d-42be5f4c0f1c")]
[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 FlowerMorgan
{
[BepInPlugin("Q.FlowerMorgan", "Flower Morgan", "1.0.5")]
public class FlowerMorganModBase : BaseUnityPlugin
{
private const string modGUID = "Q.FlowerMorgan";
private const string modName = "Flower Morgan";
private const string modVersion = "1.0.5";
private readonly Harmony harmony = new Harmony("Q.FlowerMorgan");
private static FlowerMorganModBase Instance;
public static ManualLogSource mls;
public static AudioClip[] audioClips = (AudioClip[])(object)new AudioClip[2];
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("Q.FlowerMorgan");
mls.LogInfo((object)"Starting Flower Morgan");
mls.LogWarning((object)"Read sounds start!");
string[] array = new string[2]
{
"file://" + Paths.PluginPath + "\\Lill_q-FlowerMorgan\\Q.FlowerMorgan\\rehehe.mp3",
"file://" + Paths.PluginPath + "\\Lill_q-FlowerMorgan\\Q.FlowerMorgan\\smell.mp3"
};
for (int i = 0; i < array.Length; i++)
{
mls.LogWarning((object)("Sound: " + array[i] + " Loadded!"));
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(array[i], (AudioType)13);
audioClip.SendWebRequest();
while (!audioClip.isDone)
{
}
audioClips[i] = DownloadHandlerAudioClip.GetContent(audioClip);
}
mls.LogWarning((object)"Read sounds end!");
harmony.PatchAll(typeof(FlowerMorganPatch));
}
}
}
namespace FlowerMorgan.Patches
{
internal class FlowerMorganPatch
{
public class FlowermanAudioInfo
{
public bool IsPlaying { get; set; }
public AudioSource AudioSource { get; set; }
}
private const float MinStopDelay = 30f;
private const float MaxStopDelay = 35f;
private static readonly Random random = new Random();
public static Dictionary<FlowermanAI, FlowermanAudioInfo> flowermanAudioInfoMap = new Dictionary<FlowermanAI, FlowermanAudioInfo>();
[HarmonyPatch(typeof(FlowermanAI), "Start")]
[HarmonyPostfix]
public static void FlowerMorganAudioPatch(FlowermanAI __instance)
{
if (!flowermanAudioInfoMap.TryGetValue(__instance, out var value))
{
value = new FlowermanAudioInfo
{
IsPlaying = false,
AudioSource = ((Component)__instance).gameObject.AddComponent<AudioSource>()
};
}
value.AudioSource.spatialBlend = 1f;
value.AudioSource.dopplerLevel = 1f;
value.AudioSource.rolloffMode = (AudioRolloffMode)1;
value.AudioSource.minDistance = 5f;
value.AudioSource.maxDistance = 100f;
value.AudioSource.volume = 1f;
flowermanAudioInfoMap[__instance] = value;
__instance.crackNeckSFX = FlowerMorganModBase.audioClips[0];
}
[HarmonyPatch(typeof(FlowermanAI), "Update")]
[HarmonyPrefix]
private static void UpdatePatch(FlowermanAI __instance, ref bool ___wasInEvadeMode)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
if (flowermanAudioInfoMap.TryGetValue(__instance, out var value))
{
float num = (((Object)(object)((EnemyAI)__instance).GetClosestPlayer(false, false, false) != (Object)null) ? Vector3.Distance(((Component)__instance).transform.position, ((EnemyAI)__instance).GetClosestPlayer(false, false, false).serverPlayerPosition) : 100f);
if (!___wasInEvadeMode && !value.IsPlaying && num <= 50f)
{
value.IsPlaying = true;
FlowerMorganModBase.mls.LogWarning((object)$"{((Object)__instance).GetInstanceID()} Playing audio...");
value.AudioSource.PlayOneShot(FlowerMorganModBase.audioClips[1]);
((MonoBehaviour)__instance).StartCoroutine(StopAudioAfterDelay(value));
}
}
}
private static IEnumerator StopAudioAfterDelay(FlowermanAudioInfo flowermanAudioInfo)
{
float randomDelay = (float)(random.NextDouble() * 5.0 + 30.0);
yield return (object)new WaitForSeconds(FlowerMorganModBase.audioClips[1].length + randomDelay);
flowermanAudioInfo.AudioSource.Stop();
flowermanAudioInfo.IsPlaying = false;
}
[HarmonyPatch(typeof(FlowermanAI), "HitEnemy")]
[HarmonyPrefix]
public static void FlowerMorganCleanPatch(FlowermanAI __instance)
{
if (((EnemyAI)__instance).enemyHP <= 0)
{
FlowerMorganModBase.mls.LogWarning((object)$"{((Object)__instance).GetInstanceID()} Killed!");
flowermanAudioInfoMap.Remove(__instance);
}
}
[HarmonyPatch(typeof(StartMatchLever), "EndGame")]
[HarmonyPatch(typeof(StartOfRound), "gameOverAnimation")]
[HarmonyPostfix]
public static void StartOfRoundCleanUp()
{
FlowerMorganModBase.mls.LogWarning((object)"Clearing `flowermanAudioInfoMap`...");
flowermanAudioInfoMap.Clear();
}
}
}