Revert "Change patch to transpiler"

This reverts commit 1b7a5d26312af17c8285839ac86bfce0b50913ce.
This commit is contained in:
Nick 2023-07-22 01:43:39 -04:00
parent 07ca4e4396
commit 1117b12055

View File

@ -1,6 +1,4 @@
using HarmonyLib; using HarmonyLib;
using System.Collections.Generic;
using System.Reflection.Emit;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Patches; namespace NewHorizons.Patches;
@ -10,40 +8,31 @@ public class GlobalMusicControllerPatches
{ {
private static AudioDetector _audioDetector; private static AudioDetector _audioDetector;
[HarmonyTranspiler] [HarmonyPrefix]
[HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))] [HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))]
public static IEnumerable<CodeInstruction> GlobalMusicController_UpdateBrambleMusic(IEnumerable<CodeInstruction> instructions, ILGenerator generator) public static bool GlobalMusicController_UpdateBrambleMusic(GlobalMusicController __instance)
{ {
// This transpiler is to the check if dark bramble music should be playing #651 // is this too hacky?
// It essentially adds another boolean to a "should be playing" flag if (_audioDetector == null) _audioDetector = Object.FindObjectOfType<AudioDetector>();
return new CodeMatcher(instructions, generator)
// All the other bools point to this so we make a label there
.MatchForward(false, var shouldBePlaying = Locator.GetPlayerSectorDetector().InBrambleDimension() &&
new CodeMatch(OpCodes.Ldc_I4_0), !Locator.GetPlayerSectorDetector().InVesselDimension() &&
new CodeMatch(OpCodes.Stloc_0), PlayerState.AtFlightConsole() &&
new CodeMatch(OpCodes.Ldarg_0), !PlayerState.IsHullBreached() &&
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GlobalMusicController), nameof(GlobalMusicController._darkBrambleSource))), !__instance._playingFinalEndTimes &&
new CodeMatch(OpCodes.Callvirt, AccessTools.Property(typeof(OWAudioSource), nameof(OWAudioSource.isPlaying)).GetGetMethod()) _audioDetector._activeVolumes.Count == 0; // change - don't play if in another audio volume
) var playing = __instance._darkBrambleSource.isPlaying &&
.CreateLabel(out Label label) !__instance._darkBrambleSource.IsFadingOut();
// Find the first part of the boolean assignment if (shouldBePlaying && !playing)
.Start() {
.MatchForward(true, __instance._darkBrambleSource.FadeIn(5f);
new CodeMatch(OpCodes.Call, typeof(Locator), nameof(Locator.GetPlayerSectorDetector)), }
new CodeMatch(OpCodes.Callvirt, typeof(PlayerSectorDetector), nameof(PlayerSectorDetector.InBrambleDimension)), else if (!shouldBePlaying && playing)
new CodeMatch(OpCodes.Brfalse_S) {
) __instance._darkBrambleSource.FadeOut(5f);
// Insert a new check to it pointing to the same label as the others
.Insert(
new CodeMatch(OpCodes.Call, typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes)),
new CodeMatch(OpCodes.Brfalse_S, label)
)
.InstructionEnumeration();
} }
private static bool IsPlayerInNoAudioVolumes() return false;
{
if (_audioDetector == null) _audioDetector = Object.FindObjectOfType<AudioDetector>();
return _audioDetector._activeVolumes.Count == 0;
} }
} }