mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +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
|
@ -28,25 +28,26 @@ public static class AudioModuleManager
|
||||||
foreach (string clipName in clipNames)
|
foreach (string clipName in clipNames)
|
||||||
{
|
{
|
||||||
string clipPath = Path.Combine(path, clipName);
|
string clipPath = Path.Combine(path, clipName);
|
||||||
if (!File.Exists(clipPath))
|
|
||||||
{
|
if (File.Exists(clipPath))
|
||||||
byte[] clipData = null;
|
continue;
|
||||||
|
|
||||||
|
byte[] clipData;
|
||||||
string resourceName = "MuteSFX.SFX." + clipName;
|
string resourceName = "MuteSFX.SFX." + clipName;
|
||||||
|
|
||||||
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
|
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
|
||||||
{
|
{
|
||||||
|
if (stream == null) continue;
|
||||||
clipData = new byte[stream.Length];
|
clipData = new byte[stream.Length];
|
||||||
stream.Read(clipData, 0, clipData.Length);
|
stream.Read(clipData, 0, clipData.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (FileStream fileStream = new FileStream(clipPath, FileMode.CreateNew))
|
using (FileStream fileStream = new FileStream(clipPath, FileMode.CreateNew))
|
||||||
{
|
|
||||||
fileStream.Write(clipData, 0, clipData.Length);
|
fileStream.Write(clipData, 0, clipData.Length);
|
||||||
}
|
|
||||||
|
|
||||||
MuteSFX.Logger.Msg("Placed missing sfx in audio folder: " + clipName);
|
MuteSFX.Logger.Msg("Placed missing sfx in audio folder: " + clipName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void PlayAudioModule(string module) => InterfaceAudio.PlayModule(module);
|
public static void PlayAudioModule(string module) => InterfaceAudio.PlayModule(module);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using ABI_RC.Core.Base;
|
using MelonLoader;
|
||||||
using MelonLoader;
|
using ABI_RC.Systems.GameEventSystem;
|
||||||
using System.Reflection;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace NAK.MuteSFX;
|
namespace NAK.MuteSFX;
|
||||||
|
|
||||||
|
@ -10,12 +8,12 @@ public class MuteSFX : MelonMod
|
||||||
#region Mod Settings
|
#region Mod Settings
|
||||||
|
|
||||||
internal static MelonLogger.Instance Logger;
|
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);
|
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.");
|
Category.CreateEntry("Enabled", true, description: "Toggle MuteSFX entirely.");
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -26,10 +24,8 @@ public class MuteSFX : MelonMod
|
||||||
{
|
{
|
||||||
Logger = LoggerInstance;
|
Logger = LoggerInstance;
|
||||||
|
|
||||||
HarmonyInstance.Patch(
|
CVRGameEventSystem.Microphone.OnMute.AddListener(() => { OnMicrophoneStatusChanged(false); });
|
||||||
typeof(AudioManagement).GetMethod(nameof(AudioManagement.SetMicrophoneActive)),
|
CVRGameEventSystem.Microphone.OnUnmute.AddListener(() => { OnMicrophoneStatusChanged(true); });
|
||||||
postfix: new HarmonyMethod(typeof(MuteSFX).GetMethod(nameof(OnSetMicrophoneActive_Postfix), BindingFlags.NonPublic | BindingFlags.Static))
|
|
||||||
);
|
|
||||||
|
|
||||||
AudioModuleManager.SetupDefaultAudioClips();
|
AudioModuleManager.SetupDefaultAudioClips();
|
||||||
}
|
}
|
||||||
|
@ -38,19 +34,11 @@ public class MuteSFX : MelonMod
|
||||||
|
|
||||||
#region Patched Methods
|
#region Patched Methods
|
||||||
|
|
||||||
private static void OnSetMicrophoneActive_Postfix(bool active)
|
private static void OnMicrophoneStatusChanged(bool active)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (EntryEnabled.Value)
|
if (EntryEnabled.Value)
|
||||||
AudioModuleManager.PlayAudioModule(active ? AudioModuleManager.sfx_unmute : AudioModuleManager.sfx_mute);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
|
@ -27,6 +27,6 @@ using System.Reflection;
|
||||||
namespace NAK.MuteSFX.Properties;
|
namespace NAK.MuteSFX.Properties;
|
||||||
internal static class AssemblyInfoParams
|
internal static class AssemblyInfoParams
|
||||||
{
|
{
|
||||||
public const string Version = "1.0.1";
|
public const string Version = "1.0.2";
|
||||||
public const string Author = "NotAKidoS";
|
public const string Author = "NotAKidoS";
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_id": 172,
|
"_id": 172,
|
||||||
"name": "MuteSFX",
|
"name": "MuteSFX",
|
||||||
"modversion": "1.0.1",
|
"modversion": "1.0.2",
|
||||||
"gameversion": "2023r171",
|
"gameversion": "2023r171",
|
||||||
"loaderversion": "0.6.1",
|
"loaderversion": "0.6.1",
|
||||||
"modtype": "Mod",
|
"modtype": "Mod",
|
||||||
|
@ -18,6 +18,6 @@
|
||||||
],
|
],
|
||||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r14/MuteSFX.dll",
|
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r14/MuteSFX.dll",
|
||||||
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/MuteSFX/",
|
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/MuteSFX/",
|
||||||
"changelog": "- Fixes for 2023r171.",
|
"changelog": "- Fixed Push to Talk spamming SFX. [https://github.com/NotAKidOnSteam/NAK_CVR_Mods/issues/29](#29)",
|
||||||
"embedcolor": "#92e492"
|
"embedcolor": "#92e492"
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue