Skip to content

Commit c1967e9

Browse files
author
Jannify
authored
Added support to sync sound (SubnauticaNitrox#1291)
* Added support to sync sound called from `Utils.PlayFMODAsset()`. * Sync sounds played with `FMOD_CustomEmitter` Added list to indicate which sounds should be synced * Fixed bug where not all sounds were played. * Fixed volume calculation. Added seaglide to soundsWhitelist. * Add suppressor * Refactored Component finding Added support for Seamoth RPM parameter setting * Fis SoundDebugger and remove tools from sync
1 parent b59c029 commit c1967e9

46 files changed

Lines changed: 2154 additions & 159 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Nitrox.sln.DotSettings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<s:String x:Key="/Default/CodeStyle/Generate/=Constructor/Options/=CheckForNull/@EntryIndexedValue">False</s:String>
3838
<s:Boolean x:Key="/Default/CodeStyle/Generate/=Implementations/@KeyIndexDefined">True</s:Boolean>
3939
<s:String x:Key="/Default/CodeStyle/Generate/=Implementations/Options/=Mutable/@EntryIndexedValue">False</s:String>
40+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FMOD/@EntryIndexedValue">FMOD</s:String>
4041
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GUI/@EntryIndexedValue">GUI</s:String>
4142
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HSB/@EntryIndexedValue">HSB</s:String>
4243
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
@@ -237,6 +238,9 @@
237238
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
238239
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bootstrappers/@EntryIndexedValue">True</s:Boolean>
239240
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coroutine/@EntryIndexedValue">True</s:Boolean>
241+
<s:Boolean x:Key="/Default/UserDictionary/Words/=exosuit/@EntryIndexedValue">True</s:Boolean>
242+
<s:Boolean x:Key="/Default/UserDictionary/Words/=FMOD/@EntryIndexedValue">True</s:Boolean>
243+
<s:Boolean x:Key="/Default/UserDictionary/Words/=FMODUWE/@EntryIndexedValue">True</s:Boolean>
240244
<s:Boolean x:Key="/Default/UserDictionary/Words/=gameobject/@EntryIndexedValue">True</s:Boolean>
241245
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mathf/@EntryIndexedValue">True</s:Boolean>
242246
<s:Boolean x:Key="/Default/UserDictionary/Words/=Moonpool/@EntryIndexedValue">True</s:Boolean>

NitroxClient/ClientAutoFacRegistrar.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using NitroxClient.GameLogic.Bases;
1212
using NitroxClient.GameLogic.Bases.Spawning;
1313
using NitroxClient.GameLogic.ChatUI;
14+
using NitroxClient.GameLogic.FMOD;
1415
using NitroxClient.GameLogic.HUD;
1516
using NitroxClient.GameLogic.InitialSync.Base;
1617
using NitroxClient.GameLogic.PlayerModel;
@@ -51,9 +52,12 @@ public void RegisterDependencies(ContainerBuilder containerBuilder)
5152

5253
private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
5354
{
54-
containerBuilder.RegisterType<EntityDebugger>().As<BaseDebugger>().AsSelf().SingleInstance();
55-
containerBuilder.RegisterType<SceneDebugger>().As<BaseDebugger>().AsSelf().SingleInstance();
56-
containerBuilder.RegisterType<NetworkDebugger>().As<BaseDebugger>().AsSelf().As<INetworkDebugger>().SingleInstance();
55+
containerBuilder.RegisterAssemblyTypes(currentAssembly)
56+
.AssignableTo<BaseDebugger>()
57+
.As<BaseDebugger>()
58+
.AsImplementedInterfaces()
59+
.AsSelf()
60+
.SingleInstance();
5761

5862
containerBuilder.Register(c => new NitroxProtobufSerializer($"{nameof(NitroxModel)}.dll"));
5963

@@ -119,6 +123,7 @@ private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
119123
containerBuilder.RegisterType<EscapePodManager>().InstancePerLifetimeScope();
120124
containerBuilder.RegisterType<Debugger>().InstancePerLifetimeScope();
121125
containerBuilder.RegisterType<Fires>().InstancePerLifetimeScope();
126+
containerBuilder.RegisterType<FMODSystem>().InstancePerLifetimeScope();
122127
containerBuilder.RegisterType<LiveMixinManager>().InstancePerLifetimeScope();
123128
}
124129

NitroxClient/Communication/Packets/Processors/CyclopsActivateHornProcessor.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using FMOD.Studio;
2+
using FMODUnity;
3+
using NitroxClient.Communication.Packets.Processors.Abstract;
4+
using NitroxModel.Packets;
5+
using NitroxModel_Subnautica.DataStructures;
6+
#pragma warning disable 618
7+
8+
namespace NitroxClient.Communication.Packets.Processors
9+
{
10+
public class PlayFMODAssetProcessor : ClientPacketProcessor<PlayFMODAsset>
11+
{
12+
public override void Process(PlayFMODAsset packet)
13+
{
14+
EventInstance instance = FMODUWE.GetEvent(packet.AssetPath);
15+
instance.setProperty(EVENT_PROPERTY.MINIMUM_DISTANCE, 1f);
16+
instance.setProperty(EVENT_PROPERTY.MAXIMUM_DISTANCE, packet.Radius);
17+
instance.setVolume(packet.Volume);
18+
instance.set3DAttributes(packet.Position.ToUnity().To3DAttributes());
19+
instance.start();
20+
instance.release();
21+
}
22+
}
23+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using NitroxClient.Communication.Abstract;
2+
using NitroxClient.Communication.Packets.Processors.Abstract;
3+
using NitroxClient.MonoBehaviours;
4+
using NitroxModel.DataStructures.Util;
5+
using NitroxModel.Helper;
6+
using NitroxModel.Packets;
7+
using UnityEngine;
8+
9+
namespace NitroxClient.Communication.Packets.Processors
10+
{
11+
public class PlayFMODCustomEmitterProcessor : ClientPacketProcessor<PlayFMODCustomEmitter>
12+
{
13+
private readonly IPacketSender packetSender;
14+
15+
public PlayFMODCustomEmitterProcessor(IPacketSender packetSender)
16+
{
17+
this.packetSender = packetSender;
18+
}
19+
20+
21+
public override void Process(PlayFMODCustomEmitter packet)
22+
{
23+
Optional<GameObject> soundSource = NitroxEntity.GetObjectFrom(packet.Id);
24+
Validate.IsPresent(soundSource);
25+
26+
FMODEmitterController fmodEmitterController = soundSource.Value.GetComponent<FMODEmitterController>();
27+
Validate.IsTrue(fmodEmitterController);
28+
29+
using (packetSender.Suppress<PlayFMODCustomEmitter>())
30+
{
31+
if (packet.Play)
32+
{
33+
fmodEmitterController.PlayCustomEmitter(packet.AssetPath);
34+
}
35+
else
36+
{
37+
fmodEmitterController.StopCustomEmitter(packet.AssetPath);
38+
}
39+
}
40+
}
41+
}
42+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NitroxClient.Communication.Packets.Processors.Abstract;
2+
using NitroxClient.MonoBehaviours;
3+
using NitroxModel.DataStructures.Util;
4+
using NitroxModel.Helper;
5+
using NitroxModel.Packets;
6+
using UnityEngine;
7+
8+
namespace NitroxClient.Communication.Packets.Processors
9+
{
10+
public class PlayFMODCustomLoopingEmitterProcessor : ClientPacketProcessor<PlayFMODCustomLoopingEmitter>
11+
{
12+
public override void Process(PlayFMODCustomLoopingEmitter packet)
13+
{
14+
Optional<GameObject> soundSource = NitroxEntity.GetObjectFrom(packet.Id);
15+
Validate.IsPresent(soundSource);
16+
17+
FMODEmitterController fmodEmitterController = soundSource.Value.GetComponent<FMODEmitterController>();
18+
Validate.IsTrue(fmodEmitterController);
19+
20+
fmodEmitterController.PlayCustomLoopingEmitter(packet.AssetPath);
21+
}
22+
}
23+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using NitroxClient.Communication.Abstract;
2+
using NitroxClient.Communication.Packets.Processors.Abstract;
3+
using NitroxClient.MonoBehaviours;
4+
using NitroxModel.DataStructures.Util;
5+
using NitroxModel.Helper;
6+
using NitroxModel.Packets;
7+
using UnityEngine;
8+
9+
namespace NitroxClient.Communication.Packets.Processors
10+
{
11+
public class PlayFMODStudioEventEmitterProcessor : ClientPacketProcessor<PlayFMODStudioEmitter>
12+
{
13+
private readonly IPacketSender packetSender;
14+
15+
public PlayFMODStudioEventEmitterProcessor(IPacketSender packetSender)
16+
{
17+
this.packetSender = packetSender;
18+
}
19+
20+
21+
public override void Process(PlayFMODStudioEmitter packet)
22+
{
23+
Optional<GameObject> soundSource = NitroxEntity.GetObjectFrom(packet.Id);
24+
Validate.IsPresent(soundSource);
25+
26+
FMODEmitterController fmodEmitterController = soundSource.Value.GetComponent<FMODEmitterController>();
27+
Validate.IsTrue(fmodEmitterController);
28+
29+
using (packetSender.Suppress<PlayFMODStudioEmitter>())
30+
{
31+
if (packet.Play)
32+
{
33+
fmodEmitterController.PlayStudioEmitter(packet.AssetPath);
34+
}
35+
else
36+
{
37+
fmodEmitterController.StopStudioEmitter(packet.AssetPath, packet.AllowFadeout);
38+
}
39+
}
40+
}
41+
}
42+
}

NitroxClient/Communication/Packets/Processors/ToggleLightsProcessor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NitroxClient.Communication.Abstract;
22
using NitroxClient.Communication.Packets.Processors.Abstract;
3+
using NitroxClient.GameLogic.FMOD;
34
using NitroxClient.MonoBehaviours;
45
using NitroxClient.Unity.Helper;
56
using UnityEngine;
@@ -18,14 +19,15 @@ public override void Process(NitroxModel.Packets.ToggleLights packet)
1819
{
1920
GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.Id);
2021
ToggleLights toggleLights = gameObject.GetComponent<ToggleLights>();
21-
if (toggleLights == null)
22+
if (!toggleLights)
2223
{
2324
toggleLights = gameObject.RequireComponentInChildren<ToggleLights>();
2425
}
2526

2627
if (packet.IsOn != toggleLights.GetLightsActive())
2728
{
2829
using (packetSender.Suppress<NitroxModel.Packets.ToggleLights>())
30+
using (FMODSystem.SuppressSounds())
2931
{
3032
toggleLights.SetLightsActive(packet.IsOn);
3133
}

NitroxClient/Debuggers/BaseDebugger.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected BaseDebugger(int desiredWidth, string debuggerName = null, KeyCode hot
4343
desiredWidth = 200;
4444
}
4545

46-
WindowRect = new Rect(Screen.width / 2 - (desiredWidth / 2), 100, desiredWidth, 0); // Default position in center of screen.
46+
WindowRect = new Rect(Screen.width / 2 - (desiredWidth / 2), 75, desiredWidth, 0); // Default position in center of screen.
4747
Hotkey = hotkey;
4848
HotkeyAltRequired = alt;
4949
HotkeyShiftRequired = shift;
@@ -106,8 +106,7 @@ public Optional<DebuggerTab> GetTab(string name)
106106
{
107107
Validate.NotNull(name);
108108

109-
DebuggerTab tab;
110-
tabs.TryGetValue(name, out tab);
109+
tabs.TryGetValue(name, out DebuggerTab tab);
111110
return Optional.OfNullable(tab);
112111
}
113112

@@ -257,7 +256,7 @@ private void SetBaseStyle(GUISkin skin)
257256

258257
public void ResetWindowPosition()
259258
{
260-
WindowRect = new Rect(Screen.width / 2 - (WindowRect.width / 2), 100, WindowRect.width, WindowRect.height); //Reset postion of debuggers because SN sometimes throws the windows from planet 4546B
259+
WindowRect = new Rect(Screen.width / 2f - (WindowRect.width / 2), 100, WindowRect.width, WindowRect.height); //Reset position of debuggers because SN sometimes throws the windows from planet 4546B
261260
}
262261

263262
public class DebuggerTab

0 commit comments

Comments
 (0)