SamSWAT.SixthSense update for 3.5.x
This commit is contained in:
parent
6034c42dd5
commit
672611d5e6
@ -2,8 +2,6 @@
|
|||||||
using BepInEx;
|
using BepInEx;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using Comfort.Common;
|
using Comfort.Common;
|
||||||
using EFT;
|
|
||||||
using EFT.UI;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -17,6 +15,7 @@ namespace SamSWAT.SixthSense
|
|||||||
internal static AudioClip AudioClip;
|
internal static AudioClip AudioClip;
|
||||||
internal static ConfigEntry<bool> PluginEnabled;
|
internal static ConfigEntry<bool> PluginEnabled;
|
||||||
internal static ConfigEntry<float> Cooldown;
|
internal static ConfigEntry<float> Cooldown;
|
||||||
|
internal static ConfigEntry<int> Volume;
|
||||||
async void Awake()
|
async void Awake()
|
||||||
{
|
{
|
||||||
PluginEnabled = Config.Bind(
|
PluginEnabled = Config.Bind(
|
||||||
@ -30,10 +29,18 @@ namespace SamSWAT.SixthSense
|
|||||||
"Sound cooldown",
|
"Sound cooldown",
|
||||||
5f,
|
5f,
|
||||||
"Time between sound playback in seconds");
|
"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();
|
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))
|
using (var web = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.OGGVORBIS))
|
||||||
{
|
{
|
||||||
var asyncOperation = web.SendWebRequest();
|
var asyncOperation = web.SendWebRequest();
|
||||||
@ -56,27 +63,25 @@ namespace SamSWAT.SixthSense
|
|||||||
public class Patch : ModulePatch
|
public class Patch : ModulePatch
|
||||||
{
|
{
|
||||||
private static float nextTime;
|
private static float nextTime;
|
||||||
|
|
||||||
protected override MethodBase GetTargetMethod()
|
protected override MethodBase GetTargetMethod()
|
||||||
{
|
{
|
||||||
return typeof(BotGroupClass).GetMethod("CalcGoalForBot");
|
var t = typeof(BotMemoryClass).GetProperty("GoalEnemy").PropertyType;
|
||||||
|
return t.GetMethod("SetVisible");
|
||||||
}
|
}
|
||||||
|
|
||||||
[PatchPostfix]
|
[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;
|
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);
|
if (!value || !person.GetPlayer.IsYourPlayer || !___bool_0) return;
|
||||||
bool isVisible = (bool)goalEnemy.GetType().GetProperty("IsVisible").GetValue(goalEnemy);
|
|
||||||
|
|
||||||
if (!person.GetPlayer.IsYourPlayer || !isVisible) 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;
|
nextTime = Time.time + Plugin.Cooldown.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user