using HarmonyLib; using QSB.Patches; using QSB.Utility; using UnityEngine; namespace QSB.PlayerBodySetup.Remote; /// /// forces the remote prefab audio sources to use AudioVelocityUpdateMode.Dynamic /// so the velocity calculation runs on Update (which is when we move remote objects) /// instead of FixedUpdate /// [RequireComponent(typeof(OWAudioSource))] public class QSBDopplerFixer : MonoBehaviour { public static void AddDopplerFixers(GameObject prefab) => prefab.GetComponentsInChildren(true) .ForEach(x => x.gameObject.AddComponent()); } [HarmonyPatch(typeof(OWAudioSource))] public class DopplerFixerPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; [HarmonyPostfix] [HarmonyPatch(nameof(OWAudioSource.Awake))] [HarmonyPatch(nameof(OWAudioSource.OnGamePaused))] [HarmonyPatch(nameof(OWAudioSource.OnGameUnpaused))] [HarmonyPatch(nameof(OWAudioSource.Start))] private static void FixDoppler(OWAudioSource __instance) { if (__instance.TryGetComponent(out _)) { __instance._audioSource.velocityUpdateMode = AudioVelocityUpdateMode.Dynamic; } } }