Skip to content

Commit

Permalink
Fix up monkey implementations with testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Mar 1, 2025
1 parent 4442e51 commit f9c2ad7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
18 changes: 5 additions & 13 deletions ShowmanTools/RestrictedCameraAnchors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ namespace ShowmanTools
[HarmonyPatchCategory(nameof(RestrictedCameraAnchors))]
internal sealed class RestrictedCameraAnchors : ResoniteMonkey<RestrictedCameraAnchors>
{
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;

Expand All @@ -30,7 +31,7 @@ private static void Postfix(InteractiveCameraControl __instance)
return;
}

lastAnchor.GetComponentInChildren<Grabbable>().OnlyUsers.Add().Target = __instance.LocalUser;
lastAnchor.GetComponentInChildren<Grabbable>().OnlyUsers.Add().Target = lastAnchor.LocalUser;
}

private static MethodBase TargetMethod()
Expand All @@ -40,15 +41,6 @@ private static MethodBase TargetMethod()
&& method.GetCustomAttribute<CompilerGeneratedAttribute>() 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;
}
}
}
14 changes: 9 additions & 5 deletions ShowmanTools/ShowMustGoOn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ShowmanTools
[HarmonyPatch(typeof(AudioStreamInterface), nameof(AudioStreamInterface.SetAudioStream))]
internal sealed class ShowMustGoOn : ConfiguredResoniteMonkey<ShowMustGoOn, ShowMustGoOnConfig>
{
private static readonly ConditionalWeakTable<IAudioStream, Component?> _audioStreams = new();
private static readonly ConditionalWeakTable<IAudioStream, object?> _audioStreams = new();

private static void Postfix(IAudioStream source)
{
Expand All @@ -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<MonoSample>.Stream))
.GetValue<IAudioStream>();
.GetValue<ISyncRef>()
.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<MethodBase> TargetMethods()
Expand Down

0 comments on commit f9c2ad7

Please sign in to comment.