mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Patch UpdateEndTimesMusic
This commit is contained in:
parent
c0b8d9ebc9
commit
63cd86883b
@ -204,12 +204,12 @@ namespace NewHorizons.External.Configs
|
||||
public string travelAudio;
|
||||
|
||||
/// <summary>
|
||||
/// The audio that will play for 85 seconds before the loop ends. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list.
|
||||
/// The audio that will play right before the loop ends. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list.
|
||||
/// </summary>
|
||||
public string endTimesAudio;
|
||||
|
||||
/// <summary>
|
||||
/// The audio that will play for 85 seconds before the loop ends while inside the dreamworld. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list.
|
||||
/// The audio that will play right before the loop ends while inside the dreamworld. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list.
|
||||
/// </summary>
|
||||
public string endTimesDreamAudio;
|
||||
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
using HarmonyLib;
|
||||
using NewHorizons.Components.EOTE;
|
||||
using NewHorizons.Utility;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(GlobalMusicController))]
|
||||
public class GlobalMusicControllerPatches
|
||||
public static class GlobalMusicControllerPatches
|
||||
{
|
||||
private static AudioDetector _audioDetector;
|
||||
|
||||
@ -35,10 +38,42 @@ public class GlobalMusicControllerPatches
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces any <c>85f</c> with <see cref="NewHorizonsExtensions.GetSecondsBeforeSupernovaPlayTime(GlobalMusicController)"/>
|
||||
/// </summary>
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(nameof(GlobalMusicController.UpdateEndTimesMusic))]
|
||||
public static IEnumerable<CodeInstruction> GlobalMusicController_UpdateEndTimesMusic(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
return new CodeMatcher(instructions, generator).MatchForward(true,
|
||||
new CodeMatch(OpCodes.Call),
|
||||
new CodeMatch(OpCodes.Ldc_R4, 85f),
|
||||
new CodeMatch(OpCodes.Ble_Un)
|
||||
).Advance(-1).RemoveInstruction().Insert(
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(NewHorizonsExtensions), nameof(NewHorizonsExtensions.GetSecondsBeforeSupernovaPlayTime)))
|
||||
).MatchForward(true,
|
||||
new CodeMatch(OpCodes.Call),
|
||||
new CodeMatch(OpCodes.Ldc_R4, 85f),
|
||||
new CodeMatch(OpCodes.Bge_Un)
|
||||
).Advance(-1).RemoveInstruction().Insert(
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(NewHorizonsExtensions), nameof(NewHorizonsExtensions.GetSecondsBeforeSupernovaPlayTime)))
|
||||
).MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_R4, 85f),
|
||||
new CodeMatch(OpCodes.Call),
|
||||
new CodeMatch(OpCodes.Sub)
|
||||
).RemoveInstruction().Insert(
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(NewHorizonsExtensions), nameof(NewHorizonsExtensions.GetSecondsBeforeSupernovaPlayTime)))
|
||||
).InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
// Custom end times for dreamworld
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GlobalMusicController.OnEnterDreamWorld))]
|
||||
public static bool GlobalMusicController_OnEnterDreamWorld(GlobalMusicController __instance)
|
||||
{
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using HarmonyLib;
|
||||
using NewHorizons.External.Configs;
|
||||
using NewHorizons.External.Modules.VariableSize;
|
||||
using NewHorizons.External.SerializableData;
|
||||
@ -425,5 +426,28 @@ namespace NewHorizons.Utility
|
||||
playerCameraEffectController._owCamera.postProcessingSettings.bloom.threshold = 0f;
|
||||
playerCameraEffectController._owCamera.postProcessingSettings.eyeMaskEnabled = true;
|
||||
}
|
||||
|
||||
public static float GetSecondsBeforeSupernovaPlayTime(this GlobalMusicController globalMusicController)
|
||||
{
|
||||
var clip = globalMusicController._endTimesSource.audioLibraryClip;
|
||||
if (clip == AudioType.EndOfTime || clip == AudioType.EndOfTime_Dream)
|
||||
return GlobalMusicController.secondsBeforeSupernovaPlayTime;
|
||||
return globalMusicController._endTimesSource.clip.length;
|
||||
}
|
||||
|
||||
public static CodeMatcher LogInstructions(this CodeMatcher matcher, string prefix)
|
||||
{
|
||||
matcher.InstructionEnumeration().LogInstructions(prefix);
|
||||
return matcher;
|
||||
}
|
||||
|
||||
public static IEnumerable<CodeInstruction> LogInstructions(this IEnumerable<CodeInstruction> instructions, string prefix)
|
||||
{
|
||||
var message = prefix;
|
||||
foreach (var instruction in instructions)
|
||||
message += $"\n{instruction}";
|
||||
Debug.LogError(message);
|
||||
return instructions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user