Sync playback to the actual beat count rather than relying on BPM #5
|
@ -1,18 +1,18 @@
|
||||||
using System;
|
using BepInEx.Configuration;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
using BepInEx.Configuration;
|
|
||||||
using CSync.Extensions;
|
using CSync.Extensions;
|
||||||
using CSync.Lib;
|
using CSync.Lib;
|
||||||
using LethalConfig;
|
|
||||||
using LethalConfig.ConfigItems;
|
|
||||||
using LethalConfig.ConfigItems.Options;
|
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using LethalConfig.ConfigItems.Options;
|
||||||
|
using LethalConfig.ConfigItems;
|
||||||
|
using LethalConfig;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MuzikaGromche
|
namespace MuzikaGromche
|
||||||
{
|
{
|
||||||
|
@ -387,6 +387,8 @@ namespace MuzikaGromche
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// farAudio is during windup, Start overrides popGoesTheWeaselTheme
|
||||||
|
// creatureVoice is when popped, Loop overrides screamingSFX
|
||||||
[HarmonyPatch(typeof(JesterAI))]
|
[HarmonyPatch(typeof(JesterAI))]
|
||||||
internal class JesterPatch
|
internal class JesterPatch
|
||||||
{
|
{
|
||||||
|
@ -404,13 +406,18 @@ namespace MuzikaGromche
|
||||||
{
|
{
|
||||||
__state = new State
|
__state = new State
|
||||||
{
|
{
|
||||||
previousState = __instance.previousState
|
farAudio = __instance.farAudio,
|
||||||
|
previousState = __instance.previousState,
|
||||||
};
|
};
|
||||||
if (__instance.currentBehaviourStateIndex == 2 && __instance.previousState != 2)
|
if (__instance.currentBehaviourStateIndex == 2 && __instance.previousState != 2)
|
||||||
{
|
{
|
||||||
// if just popped out
|
// If just popped out, then override farAudio so that vanilla logic does not stop the modded Start music.
|
||||||
// then override farAudio so that vanilla logic does not stop the music
|
// The game will stop farAudio it during its Update, so we temporarily set it to any other AudioSource
|
||||||
__state.farAudio = __instance.farAudio;
|
// which we don't care about stopping for now.
|
||||||
|
//
|
||||||
|
// Why creatureVoice though? We gonna need creatureVoice later in Postfix to schedule the Loop,
|
||||||
|
// but right now we still don't care if it's stopped, so it shouldn't matter.
|
||||||
|
// And it's cheaper and simpler than figuring out how to instantiate an AudioSource behaviour.
|
||||||
__instance.farAudio = __instance.creatureVoice;
|
__instance.farAudio = __instance.creatureVoice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -419,11 +426,6 @@ namespace MuzikaGromche
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void DoNotStopTheMusic(JesterAI __instance, State __state)
|
public static void DoNotStopTheMusic(JesterAI __instance, State __state)
|
||||||
{
|
{
|
||||||
if (__state.farAudio != null)
|
|
||||||
{
|
|
||||||
__instance.farAudio = __state.farAudio;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (__instance.previousState == 1 && __state.previousState != 1)
|
if (__instance.previousState == 1 && __state.previousState != 1)
|
||||||
{
|
{
|
||||||
// if just started winding up
|
// if just started winding up
|
||||||
|
@ -433,18 +435,16 @@ namespace MuzikaGromche
|
||||||
|
|
||||||
// ...and start modded music
|
// ...and start modded music
|
||||||
Plugin.CurrentTrack = Plugin.ChooseTrack();
|
Plugin.CurrentTrack = Plugin.ChooseTrack();
|
||||||
|
// Set up custom popup timer, which is shorter than Start audio
|
||||||
__instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer;
|
__instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer;
|
||||||
|
|
||||||
|
// Override popGoesTheWeaselTheme with Start audio
|
||||||
__instance.farAudio.maxDistance = 150;
|
__instance.farAudio.maxDistance = 150;
|
||||||
__instance.farAudio.clip = Plugin.CurrentTrack.LoadedStart;
|
__instance.farAudio.clip = Plugin.CurrentTrack.LoadedStart;
|
||||||
__instance.farAudio.loop = false;
|
__instance.farAudio.loop = false;
|
||||||
Debug.Log($"Playing start music: maxDistance: {__instance.farAudio.maxDistance}, minDistance: {__instance.farAudio.minDistance}, volume: {__instance.farAudio.volume}, spread: {__instance.farAudio.spread}");
|
|
||||||
__instance.farAudio.Play();
|
__instance.farAudio.Play();
|
||||||
}
|
|
||||||
|
|
||||||
if (__instance.previousState == 2 && __state.previousState != 2)
|
Debug.Log($"Playing start music: maxDistance: {__instance.farAudio.maxDistance}, minDistance: {__instance.farAudio.minDistance}, volume: {__instance.farAudio.volume}, spread: {__instance.farAudio.spread}");
|
||||||
{
|
|
||||||
__instance.creatureVoice.Stop();
|
|
||||||
Plugin.StartLightSwitching(__instance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__instance.previousState != 2 && __state.previousState == 2)
|
if (__instance.previousState != 2 && __state.previousState == 2)
|
||||||
|
@ -453,15 +453,24 @@ namespace MuzikaGromche
|
||||||
Plugin.ResetLightColor();
|
Plugin.ResetLightColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__instance.previousState == 2 && !__instance.creatureVoice.isPlaying)
|
if (__instance.previousState == 2 && __state.previousState != 2)
|
||||||
{
|
{
|
||||||
__instance.creatureVoice.maxDistance = 150;
|
// Restore stashed AudioSource. See the comment in Prefix
|
||||||
__instance.creatureVoice.clip = Plugin.CurrentTrack.LoadedLoop;
|
__instance.farAudio = __state.farAudio;
|
||||||
|
|
||||||
var time = __instance.farAudio.time;
|
var time = __instance.farAudio.time;
|
||||||
var delay = Plugin.CurrentTrack.LoadedStart.length - time;
|
var delay = Plugin.CurrentTrack.LoadedStart.length - time;
|
||||||
|
|
||||||
|
// Override screamingSFX with Loop, delayed by the remaining time of the Start audio
|
||||||
|
__instance.creatureVoice.Stop();
|
||||||
|
__instance.creatureVoice.maxDistance = 150;
|
||||||
|
__instance.creatureVoice.clip = Plugin.CurrentTrack.LoadedLoop;
|
||||||
|
__instance.creatureVoice.PlayDelayed(delay);
|
||||||
|
|
||||||
Debug.Log($"Start length: {Plugin.CurrentTrack.LoadedStart.length}; played time: {time}");
|
Debug.Log($"Start length: {Plugin.CurrentTrack.LoadedStart.length}; played time: {time}");
|
||||||
Debug.Log($"Playing loop music: maxDistance: {__instance.creatureVoice.maxDistance}, minDistance: {__instance.creatureVoice.minDistance}, volume: {__instance.creatureVoice.volume}, spread: {__instance.creatureVoice.spread}, in seconds: {delay}");
|
Debug.Log($"Playing loop music: maxDistance: {__instance.creatureVoice.maxDistance}, minDistance: {__instance.creatureVoice.minDistance}, volume: {__instance.creatureVoice.volume}, spread: {__instance.creatureVoice.spread}, in seconds: {delay}");
|
||||||
__instance.creatureVoice.PlayDelayed(delay);
|
|
||||||
|
Plugin.StartLightSwitching(__instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue