Skip to content

Commit 8bf0c6a

Browse files
authored
Added doorway sync for precursor doorways (SubnauticaNitrox#1032)
* Added doorway sync for precursor doorways * Removed multiplayerSession * Removed unneeded using * Made suggested changes * Removed acidental changes * Added logging as suggested * Changed to getobjectfrom to remove valid check and give valuable error message * Implement with metadata * Add metadata rework * Fixed metadata infinite call * Removed redundant files * Fixed build and removed unneeded imports
1 parent 98eb120 commit 8bf0c6a

7 files changed

Lines changed: 87 additions & 1 deletion

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
2+
using NitroxModel.Logger;
3+
using UnityEngine;
4+
5+
namespace NitroxClient.GameLogic.Spawning.Metadata
6+
{
7+
public class PrecursorDoorwayMetadataProcessor : GenericEntityMetadataProcessor<PrecursorDoorwayMetadata>
8+
{
9+
public override void ProcessMetadata(GameObject gameObject, PrecursorDoorwayMetadata metadata)
10+
{
11+
Log.Info($"Received precursor door metadata change for {gameObject.name} with data of {metadata}");
12+
13+
PrecursorDoorway precursorDoorway = gameObject.GetComponent<PrecursorDoorway>();
14+
precursorDoorway.isOpen = metadata.IsOpen;
15+
16+
if (metadata.IsOpen)
17+
{
18+
precursorDoorway.BroadcastMessage("DisableField");
19+
}
20+
else
21+
{
22+
precursorDoorway.BroadcastMessage("EnableField");
23+
}
24+
}
25+
}
26+
}

NitroxClient/NitroxClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
<Compile Include="GameLogic\Bases\Spawning\BaseLadderSpawnProcessor.cs" />
243243
<Compile Include="GameLogic\Bases\Spawning\NoOpBasePieceSpawnProcessor.cs" />
244244
<Compile Include="GameLogic\ChatUI\PlayerChatManager.cs" />
245+
<Compile Include="GameLogic\Spawning\Metadata\PrecursorDoorwayMetadataProcessor.cs" />
245246
<Compile Include="GameLogic\Spawning\Metadata\SealedDoorMetadataProcessor.cs" />
246247
<Compile Include="GameLogic\Spawning\Metadata\KeypadMetadataProcessor.cs" />
247248
<Compile Include="GameLogic\Spawning\Metadata\EntityMetadataProcessor.cs" />

NitroxModel/DataStructures/GameLogic/Entities/Metadata/EntityMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
55
{
66
[Serializable]
7-
[ProtoContract, ProtoInclude(50, typeof(KeypadMetadata)), ProtoInclude(60, typeof(SealedDoorMetadata))]
7+
[ProtoContract, ProtoInclude(50, typeof(KeypadMetadata)), ProtoInclude(60, typeof(SealedDoorMetadata)), ProtoInclude(70, typeof(PrecursorDoorwayMetadata))]
88
public abstract class EntityMetadata
99
{
1010
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using ProtoBufNet;
3+
4+
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
5+
{
6+
[Serializable]
7+
[ProtoContract]
8+
public class PrecursorDoorwayMetadata : EntityMetadata
9+
{
10+
[ProtoMember(1)]
11+
public bool IsOpen { get; }
12+
13+
public PrecursorDoorwayMetadata()
14+
{
15+
// Constructor for serialization
16+
}
17+
18+
public PrecursorDoorwayMetadata(bool isOpen)
19+
{
20+
IsOpen = isOpen;
21+
}
22+
23+
public override string ToString()
24+
{
25+
return "[PrecursorDoorwayMetadata isOpen: " + IsOpen + "]";
26+
}
27+
}
28+
}

NitroxModel/NitroxModel.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
<Compile Include="Core\IAutoFacRegistrar.cs" />
230230
<Compile Include="Core\NitroxEnvironment.cs" />
231231
<Compile Include="Core\NitroxServiceLocator.cs" />
232+
<Compile Include="DataStructures\GameLogic\Entities\Metadata\PrecursorDoorwayMetadata.cs" />
232233
<Compile Include="DataStructures\GameLogic\Entities\Metadata\SealedDoorMetadata.cs" />
233234
<Compile Include="DataStructures\GameLogic\Entities\Metadata\KeypadMetadata.cs" />
234235
<Compile Include="DataStructures\GameLogic\Entities\Metadata\EntityMetadata.cs" />

NitroxPatcher/NitroxPatcher.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
<Compile Include="Patches\Dynamic\PilotingChair_ReleaseBy_Patch.cs" />
323323
<Compile Include="Patches\Dynamic\Player_SetCurrentSub_Patch.cs" />
324324
<Compile Include="Patches\Dynamic\Player_Update_Patch.cs" />
325+
<Compile Include="Patches\Dynamic\PrecursorDoorway_ToggleDoor_Patch.cs" />
325326
<Compile Include="Patches\Dynamic\PrefabPlaceholdersGroup_Spawn_Patch.cs" />
326327
<Compile Include="Patches\Dynamic\Radio_OnRepair_Patch.cs" />
327328
<Compile Include="Patches\Dynamic\Radio_PlayRadioMessage_Patch.cs" />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using Harmony;
3+
using NitroxClient.GameLogic;
4+
using NitroxClient.MonoBehaviours;
5+
using NitroxModel.Core;
6+
using NitroxModel.DataStructures;
7+
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
8+
9+
namespace NitroxPatcher.Patches.Dynamic
10+
{
11+
class PrecursorDoorway_ToggleDoor_Patch : NitroxPatch, IDynamicPatch
12+
{
13+
public static readonly MethodInfo TARGET_METHOD = typeof(PrecursorDoorway).GetMethod(nameof(PrecursorDoorway.ToggleDoor), BindingFlags.Public | BindingFlags.Instance);
14+
15+
public static void Postfix(PrecursorDoorway __instance)
16+
{
17+
NitroxId id = NitroxEntity.GetId(__instance.gameObject);
18+
PrecursorDoorwayMetadata precursorDoorwayMetadata = new PrecursorDoorwayMetadata(__instance.isOpen);
19+
20+
Entities entities = NitroxServiceLocator.LocateService<Entities>();
21+
entities.BroadcastMetadataUpdate(id, precursorDoorwayMetadata);
22+
}
23+
24+
public override void Patch(HarmonyInstance harmony)
25+
{
26+
PatchPostfix(harmony, TARGET_METHOD);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)