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
|
@ -28,23 +28,24 @@ public static class AudioModuleManager
|
|||
foreach (string clipName in clipNames)
|
||||
{
|
||||
string clipPath = Path.Combine(path, clipName);
|
||||
if (!File.Exists(clipPath))
|
||||
|
||||
if (File.Exists(clipPath))
|
||||
continue;
|
||||
|
||||
byte[] clipData;
|
||||
string resourceName = "MuteSFX.SFX." + clipName;
|
||||
|
||||
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
|
||||
{
|
||||
byte[] clipData = null;
|
||||
string resourceName = "MuteSFX.SFX." + clipName;
|
||||
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
|
||||
{
|
||||
clipData = new byte[stream.Length];
|
||||
stream.Read(clipData, 0, clipData.Length);
|
||||
}
|
||||
|
||||
using (FileStream fileStream = new FileStream(clipPath, FileMode.CreateNew))
|
||||
{
|
||||
fileStream.Write(clipData, 0, clipData.Length);
|
||||
}
|
||||
|
||||
MuteSFX.Logger.Msg("Placed missing sfx in audio folder: " + clipName);
|
||||
if (stream == null) continue;
|
||||
clipData = new byte[stream.Length];
|
||||
stream.Read(clipData, 0, clipData.Length);
|
||||
}
|
||||
|
||||
using (FileStream fileStream = new FileStream(clipPath, FileMode.CreateNew))
|
||||
fileStream.Write(clipData, 0, clipData.Length);
|
||||
|
||||
MuteSFX.Logger.Msg("Placed missing sfx in audio folder: " + clipName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,6 +27,6 @@ using System.Reflection;
|
|||
namespace NAK.MuteSFX.Properties;
|
||||
internal static class AssemblyInfoParams
|
||||
{
|
||||
public const string Version = "1.0.1";
|
||||
public const string Version = "1.0.2";
|
||||
public const string Author = "NotAKidoS";
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_id": 172,
|
||||
"name": "MuteSFX",
|
||||
"modversion": "1.0.1",
|
||||
"modversion": "1.0.2",
|
||||
"gameversion": "2023r171",
|
||||
"loaderversion": "0.6.1",
|
||||
"modtype": "Mod",
|
||||
|
@ -18,6 +18,6 @@
|
|||
],
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r14/MuteSFX.dll",
|
||||
"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"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue