mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Revert "Change patch to transpiler"
This reverts commit 1b7a5d26312af17c8285839ac86bfce0b50913ce.
This commit is contained in:
parent
07ca4e4396
commit
1117b12055
@ -1,6 +1,4 @@
|
||||
using HarmonyLib;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Patches;
|
||||
@ -10,40 +8,31 @@ public class GlobalMusicControllerPatches
|
||||
{
|
||||
private static AudioDetector _audioDetector;
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))]
|
||||
public static IEnumerable<CodeInstruction> GlobalMusicController_UpdateBrambleMusic(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
// This transpiler is to the check if dark bramble music should be playing #651
|
||||
// It essentially adds another boolean to a "should be playing" flag
|
||||
return new CodeMatcher(instructions, generator)
|
||||
// All the other bools point to this so we make a label there
|
||||
.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_I4_0),
|
||||
new CodeMatch(OpCodes.Stloc_0),
|
||||
new CodeMatch(OpCodes.Ldarg_0),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GlobalMusicController), nameof(GlobalMusicController._darkBrambleSource))),
|
||||
new CodeMatch(OpCodes.Callvirt, AccessTools.Property(typeof(OWAudioSource), nameof(OWAudioSource.isPlaying)).GetGetMethod())
|
||||
)
|
||||
.CreateLabel(out Label label)
|
||||
// Find the first part of the boolean assignment
|
||||
.Start()
|
||||
.MatchForward(true,
|
||||
new CodeMatch(OpCodes.Call, typeof(Locator), nameof(Locator.GetPlayerSectorDetector)),
|
||||
new CodeMatch(OpCodes.Callvirt, typeof(PlayerSectorDetector), nameof(PlayerSectorDetector.InBrambleDimension)),
|
||||
new CodeMatch(OpCodes.Brfalse_S)
|
||||
)
|
||||
// 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();
|
||||
}
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))]
|
||||
public static bool GlobalMusicController_UpdateBrambleMusic(GlobalMusicController __instance)
|
||||
{
|
||||
// is this too hacky?
|
||||
if (_audioDetector == null) _audioDetector = Object.FindObjectOfType<AudioDetector>();
|
||||
|
||||
private static bool IsPlayerInNoAudioVolumes()
|
||||
{
|
||||
if (_audioDetector == null) _audioDetector = Object.FindObjectOfType<AudioDetector>();
|
||||
return _audioDetector._activeVolumes.Count == 0;
|
||||
}
|
||||
|
||||
var shouldBePlaying = Locator.GetPlayerSectorDetector().InBrambleDimension() &&
|
||||
!Locator.GetPlayerSectorDetector().InVesselDimension() &&
|
||||
PlayerState.AtFlightConsole() &&
|
||||
!PlayerState.IsHullBreached() &&
|
||||
!__instance._playingFinalEndTimes &&
|
||||
_audioDetector._activeVolumes.Count == 0; // change - don't play if in another audio volume
|
||||
var playing = __instance._darkBrambleSource.isPlaying &&
|
||||
!__instance._darkBrambleSource.IsFadingOut();
|
||||
if (shouldBePlaying && !playing)
|
||||
{
|
||||
__instance._darkBrambleSource.FadeIn(5f);
|
||||
}
|
||||
else if (!shouldBePlaying && playing)
|
||||
{
|
||||
__instance._darkBrambleSource.FadeOut(5f);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user