diff --git a/Projects/SamSWAT.SixthSense/Plugin.cs b/Projects/SamSWAT.SixthSense/Plugin.cs index a84d0e0..8dceb6c 100644 --- a/Projects/SamSWAT.SixthSense/Plugin.cs +++ b/Projects/SamSWAT.SixthSense/Plugin.cs @@ -2,8 +2,6 @@ using BepInEx; using BepInEx.Configuration; using Comfort.Common; -using EFT; -using EFT.UI; using System.Reflection; using System.Threading.Tasks; using UnityEngine; @@ -17,6 +15,7 @@ namespace SamSWAT.SixthSense internal static AudioClip AudioClip; internal static ConfigEntry PluginEnabled; internal static ConfigEntry Cooldown; + internal static ConfigEntry Volume; async void Awake() { PluginEnabled = Config.Bind( @@ -30,10 +29,18 @@ namespace SamSWAT.SixthSense "Sound cooldown", 5f, "Time between sound playback in seconds"); + + Volume = Config.Bind( + "Main Settings", + "Sound volume", + 100, + new ConfigDescription("How loud the sound will be, percents", + new AcceptableValueRange(0, 100))); new Patch().Enable(); - string uri = "file://" + (BepInEx.Paths.PluginPath + "/SamSWAT.SixthSense/audio.ogg").Replace("\\", "/"); + var directory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + string uri = $"file://{directory}/audio.ogg".Replace("\\", "/"); using (var web = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.OGGVORBIS)) { var asyncOperation = web.SendWebRequest(); @@ -56,27 +63,25 @@ namespace SamSWAT.SixthSense public class Patch : ModulePatch { private static float nextTime; - + protected override MethodBase GetTargetMethod() { - return typeof(BotGroupClass).GetMethod("CalcGoalForBot"); + var t = typeof(BotMemoryClass).GetProperty("GoalEnemy").PropertyType; + return t.GetMethod("SetVisible"); } [PatchPostfix] - public static void PatchPostfix(BotOwner bot) + public static void PatchPostfix(object __instance, bool value, bool ___bool_0) { 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; + var person = (IAIDetails) __instance.GetType().GetProperty("Person").GetValue(__instance); - IAIDetails person = (IAIDetails)goalEnemy.GetType().GetProperty("Person").GetValue(goalEnemy); - bool isVisible = (bool)goalEnemy.GetType().GetProperty("IsVisible").GetValue(goalEnemy); - - if (!person.GetPlayer.IsYourPlayer || !isVisible) return; + if (!value || !person.GetPlayer.IsYourPlayer || !___bool_0) return; - Singleton.Instance.PlaySound(Plugin.AudioClip); + var betterAudio = Singleton.Instance; + var audioSourceGroupType = BetterAudio.AudioSourceGroupType.NonspatialBypass; + betterAudio.PlayNonspatial(Plugin.AudioClip, audioSourceGroupType, 0.0f, Plugin.Volume.Value/100f); nextTime = Time.time + Plugin.Cooldown.Value; } } diff --git a/References/Assembly-CSharp.dll b/References/Assembly-CSharp.dll index 3877cd3..43873ee 100644 Binary files a/References/Assembly-CSharp.dll and b/References/Assembly-CSharp.dll differ