mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
[MuteSFX] Fix #29.
Fixed Push to Talk spamming SFX. [https://github.com/NotAKidOnSteam/NAK_CVR_Mods/issues/29](#29)
This commit is contained in:
parent
3d6b1f75a4
commit
22fcd8fe8f
4 changed files with 29 additions and 40 deletions
|
@ -1,7 +1,5 @@
|
|||
using ABI_RC.Core.Base;
|
||||
using MelonLoader;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using MelonLoader;
|
||||
using ABI_RC.Systems.GameEventSystem;
|
||||
|
||||
namespace NAK.MuteSFX;
|
||||
|
||||
|
@ -10,12 +8,12 @@ public class MuteSFX : MelonMod
|
|||
#region Mod Settings
|
||||
|
||||
internal static MelonLogger.Instance Logger;
|
||||
internal const string SettingsCategory = nameof(MuteSFX);
|
||||
private const string SettingsCategory = nameof(MuteSFX);
|
||||
|
||||
public static readonly MelonPreferences_Category Category =
|
||||
private static readonly MelonPreferences_Category Category =
|
||||
MelonPreferences.CreateCategory(SettingsCategory);
|
||||
|
||||
public static readonly MelonPreferences_Entry<bool> EntryEnabled =
|
||||
private static readonly MelonPreferences_Entry<bool> EntryEnabled =
|
||||
Category.CreateEntry("Enabled", true, description: "Toggle MuteSFX entirely.");
|
||||
|
||||
#endregion
|
||||
|
@ -26,10 +24,8 @@ public class MuteSFX : MelonMod
|
|||
{
|
||||
Logger = LoggerInstance;
|
||||
|
||||
HarmonyInstance.Patch(
|
||||
typeof(AudioManagement).GetMethod(nameof(AudioManagement.SetMicrophoneActive)),
|
||||
postfix: new HarmonyMethod(typeof(MuteSFX).GetMethod(nameof(OnSetMicrophoneActive_Postfix), BindingFlags.NonPublic | BindingFlags.Static))
|
||||
);
|
||||
CVRGameEventSystem.Microphone.OnMute.AddListener(() => { OnMicrophoneStatusChanged(false); });
|
||||
CVRGameEventSystem.Microphone.OnUnmute.AddListener(() => { OnMicrophoneStatusChanged(true); });
|
||||
|
||||
AudioModuleManager.SetupDefaultAudioClips();
|
||||
}
|
||||
|
@ -38,18 +34,10 @@ public class MuteSFX : MelonMod
|
|||
|
||||
#region Patched Methods
|
||||
|
||||
private static void OnSetMicrophoneActive_Postfix(bool active)
|
||||
private static void OnMicrophoneStatusChanged(bool active)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (EntryEnabled.Value)
|
||||
AudioModuleManager.PlayAudioModule(active ? AudioModuleManager.sfx_unmute : AudioModuleManager.sfx_mute);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error($"Error during the patched method {nameof(OnSetMicrophoneActive_Postfix)}");
|
||||
Logger.Error(e);
|
||||
}
|
||||
if (EntryEnabled.Value)
|
||||
AudioModuleManager.PlayAudioModule(active ? AudioModuleManager.sfx_unmute : AudioModuleManager.sfx_mute);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue