89 lines
3.0 KiB
C#
89 lines
3.0 KiB
C#
using Aki.Reflection.Patching;
|
|
using BepInEx;
|
|
using BepInEx.Configuration;
|
|
using Comfort.Common;
|
|
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<bool> PluginEnabled;
|
|
internal static ConfigEntry<float> Cooldown;
|
|
internal static ConfigEntry<int> Volume;
|
|
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");
|
|
|
|
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();
|
|
|
|
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();
|
|
|
|
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()
|
|
{
|
|
var t = typeof(BotMemoryClass).GetProperty("GoalEnemy").PropertyType;
|
|
return t.GetMethod("SetVisible");
|
|
}
|
|
|
|
[PatchPostfix]
|
|
public static void PatchPostfix(object __instance, bool value, bool ___bool_0)
|
|
{
|
|
if (!Plugin.PluginEnabled.Value || Plugin.AudioClip == null || Time.time < nextTime) return;
|
|
|
|
var person = (IAIDetails) __instance.GetType().GetProperty("Person").GetValue(__instance);
|
|
|
|
if (!value || !person.GetPlayer.IsYourPlayer || !___bool_0) return;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|