Skip to content

Commit

Permalink
Fixes for sound errors from RC3 (#1730)
Browse files Browse the repository at this point in the history
* Remove bubbles from whitelist

* Refactor Model.helper.Validate

* Fix MedicalCabinet sounds

* Dev-QoL for FMOD Processors
  • Loading branch information
Jannify authored Feb 20, 2022
1 parent 8c5c52c commit 7bdea41
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using NitroxClient.Communication.Abstract;
using NitroxModel.Helper;
using NitroxModel.MultiplayerSession;
using NitroxModel.Packets.Exceptions;

namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
Expand Down Expand Up @@ -62,7 +63,10 @@ private static void ReservationIsNotNull(IMultiplayerSessionConnectionContext se

private void ReservationPacketIsCorrelated(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
Validate.PacketCorrelation(sessionConnectionContext.Reservation, reservationCorrelationId);
if (!reservationCorrelationId.Equals(sessionConnectionContext.Reservation.CorrelationId))
{
throw new UncorrelatedPacketException(sessionConnectionContext.Reservation, reservationCorrelationId);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using NitroxClient.Communication.Abstract;
using NitroxModel.Helper;
using NitroxModel.Packets.Exceptions;

namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
{
Expand Down Expand Up @@ -50,7 +51,10 @@ private static void SessionPolicyIsNotNull(IMultiplayerSessionConnectionContext

private void SessionPolicyPacketCorrelation(IMultiplayerSessionConnectionContext sessionConnectionContext)
{
Validate.PacketCorrelation(sessionConnectionContext.SessionPolicy, policyRequestCorrelationId);
if (!policyRequestCorrelationId.Equals(sessionConnectionContext.SessionPolicy.CorrelationId))
{
throw new UncorrelatedPacketException(sessionConnectionContext.SessionPolicy, policyRequestCorrelationId);
}
}

private void AwaitReservationCredentials(IMultiplayerSessionConnectionContext sessionConnectionContext)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.GameLogic.FMOD;
using NitroxClient.MonoBehaviours;
using NitroxClient.Unity.Helper;
using NitroxModel.Helper;
using NitroxModel.Packets;
using UnityEngine;

namespace NitroxClient.Communication.Packets.Processors
namespace NitroxClient.Communication.Packets.Processors;

public class MedicalCabinetClickedProcessor : ClientPacketProcessor<MedicalCabinetClicked>
{
public class MedicalCabinetClickedProcessor : ClientPacketProcessor<MedicalCabinetClicked>
private readonly IPacketSender packetSender;

public MedicalCabinetClickedProcessor(IPacketSender packetSender)
{
public override void Process(MedicalCabinetClicked packet)
{
GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.Id);
MedicalCabinet cabinet = gameObject.RequireComponent<MedicalCabinet>();
this.packetSender = packetSender;
}

bool medkitPickedUp = !packet.HasMedKit && cabinet.hasMedKit;
public override void Process(MedicalCabinetClicked packet)
{
GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.Id);
MedicalCabinet cabinet = gameObject.RequireComponent<MedicalCabinet>();

cabinet.hasMedKit = packet.HasMedKit;
cabinet.timeSpawnMedKit = packet.NextSpawnTime;
bool medkitPickedUp = !packet.HasMedKit && cabinet.hasMedKit;
bool doorChangedState = cabinet.doorOpen != packet.DoorOpen;

bool isDoorOpen = cabinet.doorOpen;
bool doorChangedState = isDoorOpen != packet.DoorOpen;
cabinet.hasMedKit = packet.HasMedKit;
cabinet.timeSpawnMedKit = packet.NextSpawnTime;

using (packetSender.Suppress<PlayFMODCustomEmitter>())
using (FMODSystem.SuppressSounds())
{
if (doorChangedState)
{
cabinet.Invoke(nameof(MedicalCabinet.ToggleDoorState), 0f);
}
else if (medkitPickedUp)
{
cabinet.Invoke(nameof(MedicalCabinet.ToggleDoorState), 1.8f);
cabinet.Invoke(nameof(MedicalCabinet.ToggleDoorState), 2f);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.MonoBehaviours;
using NitroxModel.DataStructures.Util;
using NitroxModel.Helper;
using NitroxClient.Unity.Helper;
using NitroxModel.Packets;
using UnityEngine;

namespace NitroxClient.Communication.Packets.Processors
namespace NitroxClient.Communication.Packets.Processors;

public class PlayFMODCustomEmitterProcessor : ClientPacketProcessor<PlayFMODCustomEmitter>
{
public class PlayFMODCustomEmitterProcessor : ClientPacketProcessor<PlayFMODCustomEmitter>
private readonly IPacketSender packetSender;

public PlayFMODCustomEmitterProcessor(IPacketSender packetSender)
{
private readonly IPacketSender packetSender;
this.packetSender = packetSender;
}

public PlayFMODCustomEmitterProcessor(IPacketSender packetSender)
{
this.packetSender = packetSender;
}

public override void Process(PlayFMODCustomEmitter packet)
{
GameObject soundSource = NitroxEntity.RequireObjectFrom(packet.Id);
FMODEmitterController fmodEmitterController = soundSource.RequireComponent<FMODEmitterController>();

public override void Process(PlayFMODCustomEmitter packet)
using (packetSender.Suppress<PlayFMODCustomEmitter>())
using (packetSender.Suppress<PlayFMODCustomLoopingEmitter>())
{
Optional<GameObject> soundSource = NitroxEntity.GetObjectFrom(packet.Id);
Validate.IsPresent(soundSource);

FMODEmitterController fmodEmitterController = soundSource.Value.GetComponent<FMODEmitterController>();
Validate.IsTrue(fmodEmitterController);

using (packetSender.Suppress<PlayFMODCustomEmitter>())
if (packet.Play)
{
fmodEmitterController.PlayCustomEmitter(packet.AssetPath);
}
else
{
if (packet.Play)
{
fmodEmitterController.PlayCustomEmitter(packet.AssetPath);
}
else
{
fmodEmitterController.StopCustomEmitter(packet.AssetPath);
}
fmodEmitterController.StopCustomEmitter(packet.AssetPath);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.MonoBehaviours;
using NitroxModel.DataStructures.Util;
using NitroxModel.Helper;
using NitroxClient.Unity.Helper;
using NitroxModel.Packets;
using UnityEngine;

namespace NitroxClient.Communication.Packets.Processors
namespace NitroxClient.Communication.Packets.Processors;

public class PlayFMODCustomLoopingEmitterProcessor : ClientPacketProcessor<PlayFMODCustomLoopingEmitter>
{
public class PlayFMODCustomLoopingEmitterProcessor : ClientPacketProcessor<PlayFMODCustomLoopingEmitter>
public override void Process(PlayFMODCustomLoopingEmitter packet)
{
public override void Process(PlayFMODCustomLoopingEmitter packet)
{
Optional<GameObject> soundSource = NitroxEntity.GetObjectFrom(packet.Id);
Validate.IsPresent(soundSource);

FMODEmitterController fmodEmitterController = soundSource.Value.GetComponent<FMODEmitterController>();
Validate.IsTrue(fmodEmitterController);
GameObject soundSource = NitroxEntity.RequireObjectFrom(packet.Id);
FMODEmitterController fmodEmitterController = soundSource.RequireComponent<FMODEmitterController>();

fmodEmitterController.PlayCustomLoopingEmitter(packet.AssetPath);
}
fmodEmitterController.PlayCustomLoopingEmitter(packet.AssetPath);
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.MonoBehaviours;
using NitroxModel.DataStructures.Util;
using NitroxModel.Helper;
using NitroxClient.Unity.Helper;
using NitroxModel.Packets;
using UnityEngine;

namespace NitroxClient.Communication.Packets.Processors
namespace NitroxClient.Communication.Packets.Processors;

public class PlayFMODStudioEventEmitterProcessor : ClientPacketProcessor<PlayFMODStudioEmitter>
{
public class PlayFMODStudioEventEmitterProcessor : ClientPacketProcessor<PlayFMODStudioEmitter>
private readonly IPacketSender packetSender;

public PlayFMODStudioEventEmitterProcessor(IPacketSender packetSender)
{
private readonly IPacketSender packetSender;
this.packetSender = packetSender;
}

public PlayFMODStudioEventEmitterProcessor(IPacketSender packetSender)
{
this.packetSender = packetSender;
}

public override void Process(PlayFMODStudioEmitter packet)
{
GameObject soundSource = NitroxEntity.RequireObjectFrom(packet.Id);
FMODEmitterController fmodEmitterController = soundSource.RequireComponent<FMODEmitterController>();

public override void Process(PlayFMODStudioEmitter packet)
using (packetSender.Suppress<PlayFMODStudioEmitter>())
{
Optional<GameObject> soundSource = NitroxEntity.GetObjectFrom(packet.Id);
Validate.IsPresent(soundSource);

FMODEmitterController fmodEmitterController = soundSource.Value.GetComponent<FMODEmitterController>();
Validate.IsTrue(fmodEmitterController);

using (packetSender.Suppress<PlayFMODStudioEmitter>())
if (packet.Play)
{
fmodEmitterController.PlayStudioEmitter(packet.AssetPath);
}
else
{
if (packet.Play)
{
fmodEmitterController.PlayStudioEmitter(packet.AssetPath);
}
else
{
fmodEmitterController.StopStudioEmitter(packet.AssetPath, packet.AllowFadeout);
}
fmodEmitterController.StopStudioEmitter(packet.AssetPath, packet.AllowFadeout);
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions NitroxClient/GameLogic/EscapePodManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,29 @@ public GameObject CreateNewEscapePod(EscapePodModel model)
NitroxEntity.SetNewId(radio.gameObject, model.RadioId);

DamageEscapePod(model.Damaged, model.RadioDamaged);
FixStartMethods(escapePod);

SURPRESS_ESCAPE_POD_AWAKE_METHOD = false;

return escapePod;
}

/// <summary>
/// Start() isn't executed for the EscapePod and children (Why? Idk, maybe because it's a scene...) so we call the components here where we have patches in Start.
/// </summary>
private static void FixStartMethods(GameObject escapePod)
{
foreach (FMOD_CustomEmitter customEmitter in escapePod.GetComponentsInChildren<FMOD_CustomEmitter>())
{
customEmitter.Start();
}

foreach (FMOD_StudioEventEmitter studioEventEmitter in escapePod.GetComponentsInChildren<FMOD_StudioEventEmitter>())
{
studioEventEmitter.Start();
}
}

public void DamageEscapePod(bool damage, bool radio)
{
if (damage)
Expand Down
8 changes: 4 additions & 4 deletions NitroxClient/Resources/soundsWhitelist.csv
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ event:/player/adviseSelfScan;false;false;0
event:/player/aurora_warning_1;false;false;0
event:/player/aurora_warning_2;false;false;0
event:/player/aurora_warning_3;false;false;0
event:/player/breathing;true;false;20
event:/player/bubbles;true;false;20
event:/player/breathing;false;false;20
event:/player/bubbles;false;false;20
event:/player/cold_damage;true;false;20
event:/player/coughing;true;false;20
event:/player/cube terminal_close;false;false;0
Expand Down Expand Up @@ -712,7 +712,7 @@ event:/sub_module/fabricator/fabricator_click;false;false;0
event:/sub_module/fabricator/menu_up;false;false;0
event:/sub_module/fabricator/negative;false;false;0
event:/sub_module/fabricator/open;true;false;20
event:/sub_module/first_aid/spawn;true;false;20
event:/sub_module/first_aid/spawn;false;false;20
event:/sub_module/workbench/close;true;false;20
event:/sub_module/workbench/open;true;false;20
event:/tools/airbladder/airbladder_deflate;false;false;0
Expand Down Expand Up @@ -814,4 +814,4 @@ event:/tools/transfuser/take_sample;false;false;0
event:/tools/use_loot;false;false;0
event:/tools/welder/deploy;false;false;20
event:/tools/welder/first_use;false;false;20
event:/tools/welder/weld_loop;true;false;20
event:/tools/welder/weld_loop;true;false;20
8 changes: 4 additions & 4 deletions NitroxClient/Unity/Helper/GameObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ public static bool TryGetComponentInParent<T>(this GameObject go, out T componen
public static T RequireComponent<T>(this GameObject o) where T : Component
{
T component = o.GetComponent<T>();
Validate.NotNull(component, $"{o.name} did not have a component of type {typeof(T)}");
Validate.IsTrue(component, $"{o.name} did not have a component of type {typeof(T)}");

return component;
}

public static T RequireComponentInChildren<T>(this GameObject o, bool includeInactive = false) where T : Component
{
T component = o.GetComponentInChildren<T>(includeInactive);
Validate.NotNull(component, $"{o.name} did not have a component of type {typeof(T)} in its children");
Validate.IsTrue(component, $"{o.name} did not have a component of type {typeof(T)} in its children");

return component;
}

public static T RequireComponentInParent<T>(this GameObject o) where T : Component
{
T component = o.GetComponentInParent<T>();
Validate.NotNull(component, $"{o.name} did not have a component of type {typeof(T)} in its parent");
Validate.IsTrue(component, $"{o.name} did not have a component of type {typeof(T)} in its parent");

return component;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public static Transform RequireTransform(this Transform tf, string name)
public static GameObject RequireGameObject(string name)
{
GameObject go = GameObject.Find(name);
Validate.NotNull(go, "No global GameObject found with " + name + "!");
Validate.IsTrue(go, "No global GameObject found with " + name + "!");

return go;
}
Expand Down
12 changes: 12 additions & 0 deletions NitroxModel/Helper/CallerArgumentExpressionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class CallerArgumentExpressionAttribute : Attribute
{
public CallerArgumentExpressionAttribute(string parameterName)
{
ParameterName = parameterName;
}

public string ParameterName { get; }
}
Loading

0 comments on commit 7bdea41

Please sign in to comment.