using Aki.Reflection.Patching; using BepInEx; using BepInEx.Configuration; using Comfort.Common; using EFT; using EFT.UI; using System.Reflection; using System.Threading.Tasks; using UnityEngine; using UnityEngine.Networking; namespace SamSWAT.SixthSense { [BepInPlugin("com.samswat.sixthsense", "SamSWAT.SixthSense", "1.0.0")] public class Plugin : BaseUnityPlugin { internal static AudioClip AudioClip; internal static ConfigEntry PluginEnabled; internal static ConfigEntry Cooldown; async void Awake() { PluginEnabled = Config.Bind( "Main Settings", "Plugin on/off", true, ""); Cooldown = Config.Bind( "Main Settings", "Sound cooldown", 5f, "Time between sound playback in seconds"); new Patch().Enable(); string uri = "file://" + (BepInEx.Paths.PluginPath + "/SamSWAT.SixthSense/audio.ogg").Replace("\\", "/"); using (var web = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.OGGVORBIS)) { var asyncOperation = web.SendWebRequest(); while (!asyncOperation.isDone) await Task.Yield(); if (!web.isNetworkError && !web.isHttpError) { AudioClip = DownloadHandlerAudioClip.GetContent(web); } else { Debug.LogError($"Can't load audio at path: '{uri}', error: {web.error}"); } } } } public class Patch : ModulePatch { private static float nextTime; protected override MethodBase GetTargetMethod() { return typeof(BotGroupClass).GetMethod("CalcGoalForBot"); } [PatchPostfix] public static void PatchPostfix(BotOwner bot) { if (!Plugin.PluginEnabled.Value || Plugin.AudioClip == null || Time.time < nextTime) return; //GClass442 goalEnemy = bot.Memory.GoalEnemy; object goalEnemy = bot.Memory.GetType().GetProperty("GoalEnemy").GetValue(bot.Memory); if (goalEnemy == null) return; IAIDetails person = (IAIDetails)goalEnemy.GetType().GetProperty("Person").GetValue(goalEnemy); bool isVisible = (bool)goalEnemy.GetType().GetProperty("IsVisible").GetValue(goalEnemy); if (!person.GetPlayer.IsYourPlayer || !isVisible) return; Singleton.Instance.PlaySound(Plugin.AudioClip); nextTime = Time.time + Plugin.Cooldown.Value; } } }