From c496ebb313a431e1c39d4b9150ebdb34ac8a6954 Mon Sep 17 00:00:00 2001 From: kafeijao Date: Tue, 3 Jan 2023 14:37:01 +0000 Subject: [PATCH] [BetterLipsync] Fixed bug where lipsync was on even though we were muted. --- BetterLipsync/CVRMicLipsyncSubscriber.cs | 21 +++++++++++++++++---- BetterLipsync/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/BetterLipsync/CVRMicLipsyncSubscriber.cs b/BetterLipsync/CVRMicLipsyncSubscriber.cs index 9e89444..2be183c 100644 --- a/BetterLipsync/CVRMicLipsyncSubscriber.cs +++ b/BetterLipsync/CVRMicLipsyncSubscriber.cs @@ -11,12 +11,14 @@ public class CVRMicLipsyncSubscriber : BaseMicrophoneSubscriber { private int _channels; private bool _initialized; private CVRLipSyncContext _lipSyncContext; - private static CVRMicLipsyncSubscriber Instance; + private static CVRMicLipsyncSubscriber _instance; + private static bool _muted; public void Initialize(CVRLipSyncContext lipSyncContext) { _lipSyncContext = lipSyncContext; + _lipSyncContext.Muted = _muted; _initialized = true; - Instance = this; + _instance = this; } protected override void ProcessAudio(ArraySegment data) { @@ -33,13 +35,24 @@ private void OnDestroy() { RootLogic.Instance.comms.MicrophoneCapture.Unsubscribe(this); } + private static void SetMuted(bool isMuted) { + _muted = isMuted; + if (_instance == null) return; + _instance._lipSyncContext.Muted = isMuted; + } + [HarmonyPatch] private static class HarmonyPatches { [HarmonyPostfix] [HarmonyPatch(typeof(Audio), nameof(Audio.SetMicrophoneActive))] private static void After_Audio_SetMicrophoneActive(bool muted) { - if (Instance == null) return; - Instance._lipSyncContext.Muted = muted; + SetMuted(muted); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(DissonanceComms), nameof(DissonanceComms.IsMuted), MethodType.Setter)] + private static void After_DissonanceComms_IsMuted_Setter(bool value) { + SetMuted(value); } } } diff --git a/BetterLipsync/Properties/AssemblyInfo.cs b/BetterLipsync/Properties/AssemblyInfo.cs index ead7384..7381026 100644 --- a/BetterLipsync/Properties/AssemblyInfo.cs +++ b/BetterLipsync/Properties/AssemblyInfo.cs @@ -25,6 +25,6 @@ namespace BetterLipsync.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.2"; + public const string Version = "1.0.3"; public const string Author = "kafeijao"; }