[MuteSFX] Fix #29.

Fixed Push to Talk spamming SFX. [https://github.com/NotAKidOnSteam/NAK_CVR_Mods/issues/29](#29)
This commit is contained in:
NotAKidoS 2023-09-15 18:50:02 -05:00
parent 3d6b1f75a4
commit 22fcd8fe8f
4 changed files with 29 additions and 40 deletions

View file

@ -28,23 +28,24 @@ 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))
continue;
byte[] clipData;
string resourceName = "MuteSFX.SFX." + clipName;
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{ {
byte[] clipData = null; if (stream == null) continue;
string resourceName = "MuteSFX.SFX." + clipName; clipData = new byte[stream.Length];
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) stream.Read(clipData, 0, clipData.Length);
{
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);
} }
using (FileStream fileStream = new FileStream(clipPath, FileMode.CreateNew))
fileStream.Write(clipData, 0, clipData.Length);
MuteSFX.Logger.Msg("Placed missing sfx in audio folder: " + clipName);
} }
} }

View file

@ -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,18 +34,10 @@ 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)
{ AudioModuleManager.PlayAudioModule(active ? AudioModuleManager.sfx_unmute : AudioModuleManager.sfx_mute);
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);
}
} }
#endregion #endregion

View file

@ -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";
} }

View file

@ -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"
} }