mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
|
using HarmonyLib;
|
|||
|
using QSB.Audio.Messages;
|
|||
|
using QSB.Messaging;
|
|||
|
using QSB.Patches;
|
|||
|
using QSB.Player;
|
|||
|
|
|||
|
namespace QSB.Audio.Patches;
|
|||
|
|
|||
|
internal class PlayerImpactAudioPatches : QSBPatch
|
|||
|
{
|
|||
|
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
|||
|
|
|||
|
[HarmonyPostfix]
|
|||
|
[HarmonyPatch(typeof(PlayerImpactAudio), nameof(PlayerImpactAudio.Start))]
|
|||
|
public static void PlayerImpactAudio_Start(PlayerImpactAudio __instance)
|
|||
|
{
|
|||
|
__instance.gameObject.AddComponent<QSBAudioSourceOneShotTracker>();
|
|||
|
}
|
|||
|
|
|||
|
[HarmonyPrefix]
|
|||
|
[HarmonyPatch(typeof(PlayerImpactAudio), nameof(PlayerImpactAudio.OnImpact))]
|
|||
|
public static void PlayerImpactAudio_OnImpact_Prefix(PlayerImpactAudio __instance) =>
|
|||
|
// First we reset in case no audio is actually played
|
|||
|
__instance.gameObject.GetComponent<QSBAudioSourceOneShotTracker>()?.Reset();
|
|||
|
|
|||
|
[HarmonyPostfix]
|
|||
|
[HarmonyPatch(typeof(PlayerImpactAudio), nameof(PlayerImpactAudio.OnImpact))]
|
|||
|
public static void PlayerImpactAudio_OnImpact_Postfix(PlayerImpactAudio __instance)
|
|||
|
{
|
|||
|
var tracker = __instance.gameObject.GetComponent<QSBAudioSourceOneShotTracker>();
|
|||
|
if (tracker)
|
|||
|
{
|
|||
|
if (tracker.LastPlayed != AudioType.None)
|
|||
|
{
|
|||
|
new PlayerAudioControllerOneShotMessage(tracker.LastPlayed, QSBPlayerManager.LocalPlayerId, tracker.Pitch, tracker.Volume).Send();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|