SamSWAT.SixthSense update for 3.5.x

This commit is contained in:
SamSWAT 2023-02-16 00:40:05 +03:00
parent 6034c42dd5
commit 672611d5e6
2 changed files with 19 additions and 14 deletions

View File

@ -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<bool> PluginEnabled;
internal static ConfigEntry<float> Cooldown;
internal static ConfigEntry<int> 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<int>(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<GUISounds>.Instance.PlaySound(Plugin.AudioClip);
var betterAudio = Singleton<BetterAudio>.Instance;
var audioSourceGroupType = BetterAudio.AudioSourceGroupType.NonspatialBypass;
betterAudio.PlayNonspatial(Plugin.AudioClip, audioSourceGroupType, 0.0f, Plugin.Volume.Value/100f);
nextTime = Time.time + Plugin.Cooldown.Value;
}
}

Binary file not shown.