diff --git a/ShowmanTools/RestrictedCameraAnchors.cs b/ShowmanTools/RestrictedCameraAnchors.cs index 850f7cf..74f41e8 100644 --- a/ShowmanTools/RestrictedCameraAnchors.cs +++ b/ShowmanTools/RestrictedCameraAnchors.cs @@ -15,10 +15,11 @@ namespace ShowmanTools [HarmonyPatchCategory(nameof(RestrictedCameraAnchors))] internal sealed class RestrictedCameraAnchors : ResoniteMonkey { - private static string slotFieldName = null!; - - private static void Postfix(InteractiveCameraControl __instance) + [HarmonyPostfix] + private static async Task PostfixAsync(Task __result, InteractiveCameraControl __instance) { + await __result; + if (!Enabled) return; @@ -30,7 +31,7 @@ private static void Postfix(InteractiveCameraControl __instance) return; } - lastAnchor.GetComponentInChildren().OnlyUsers.Add().Target = __instance.LocalUser; + lastAnchor.GetComponentInChildren().OnlyUsers.Add().Target = lastAnchor.LocalUser; } private static MethodBase TargetMethod() @@ -40,15 +41,6 @@ private static MethodBase TargetMethod() && method.GetCustomAttribute() is not null); return taskMethod; - - var moveNextMethod = AccessTools.AsyncMoveNext(taskMethod); - - var slotField = AccessTools.GetDeclaredFields(moveNextMethod.DeclaringType) - .First(field => field.FieldType == typeof(Slot)); - - var slotFieldName = slotField.Name; - - return moveNextMethod; } } } \ No newline at end of file diff --git a/ShowmanTools/ShowMustGoOn.cs b/ShowmanTools/ShowMustGoOn.cs index 61193c2..ab522e9 100644 --- a/ShowmanTools/ShowMustGoOn.cs +++ b/ShowmanTools/ShowMustGoOn.cs @@ -17,7 +17,7 @@ namespace ShowmanTools [HarmonyPatch(typeof(AudioStreamInterface), nameof(AudioStreamInterface.SetAudioStream))] internal sealed class ShowMustGoOn : ConfiguredResoniteMonkey { - private static readonly ConditionalWeakTable _audioStreams = new(); + private static readonly ConditionalWeakTable _audioStreams = new(); private static void Postfix(IAudioStream source) { @@ -26,19 +26,23 @@ private static void Postfix(IAudioStream source) } [HarmonyPatch] + [HarmonyPatchCategory(nameof(ShowMustGoOn))] private static class UserAudioStreamPatch { private static bool MuteCheck(Component audioStream) { var world = audioStream.World; - var stream = Traverse.Create(audioStream) + var stream = (IAudioStream)Traverse.Create(audioStream) .Field(nameof(UserAudioStream.Stream)) - .GetValue(); + .GetValue() + .Target; + + var isAudioStream = _audioStreams.TryGetValue(stream, out _); return world.Focus == World.WorldFocus.Focused || (world.Focus == World.WorldFocus.Background - && (ConfigSection.EnableVoiceWhileUnfocused - || (ConfigSection.EnableStreamingWhileUnfocused && _audioStreams.TryGetValue(stream, out _)))); + && ((!isAudioStream && ConfigSection.EnableVoiceWhileUnfocused) + || (isAudioStream && ConfigSection.EnableStreamingWhileUnfocused))); } private static IEnumerable TargetMethods()