Skip to content

Commit 728a405

Browse files
committed
Added syncing for sealed doors using the new entity metadata system.
1 parent 936a621 commit 728a405

File tree

8 files changed

+85
-2
lines changed

8 files changed

+85
-2
lines changed

NitroxClient/GameLogic/Spawning/Metadata/KeypadMetadataProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class KeypadMetadataProcessor : GenericEntityMetadataProcessor<KeypadMeta
88
{
99
public override void ProcessMetadata(GameObject gameObject, KeypadMetadata metadata)
1010
{
11-
Log.Info($"Received keypad metadata chagen for {gameObject.name} with data of {metadata}");
11+
Log.Info($"Received keypad metadata change for {gameObject.name} with data of {metadata}");
1212

1313
KeypadDoorConsole keypad = gameObject.GetComponent<KeypadDoorConsole>();
1414
keypad.unlocked = metadata.Unlocked;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 SealedDoorMetadataProcessor : GenericEntityMetadataProcessor<SealedDoorMetadata>
8+
{
9+
public override void ProcessMetadata(GameObject gameObject, SealedDoorMetadata metadata)
10+
{
11+
Log.Info($"Received door metadata change for {gameObject.name} with data of {metadata}");
12+
13+
Sealed door = gameObject.GetComponent<Sealed>();
14+
door._sealed = metadata.Sealed;
15+
}
16+
}
17+
}

NitroxClient/NitroxClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
<Compile Include="GameLogic\Bases\Spawning\BaseLadderSpawnProcessor.cs" />
244244
<Compile Include="GameLogic\Bases\Spawning\NoOpBasePieceSpawnProcessor.cs" />
245245
<Compile Include="GameLogic\ChatUI\PlayerChatManager.cs" />
246+
<Compile Include="GameLogic\Spawning\Metadata\SealedDoorMetadataProcessor.cs" />
246247
<Compile Include="GameLogic\Spawning\Metadata\KeypadMetadataProcessor.cs" />
247248
<Compile Include="GameLogic\Spawning\Metadata\EntityMetadataProcessor.cs" />
248249
<Compile Include="GameLogic\Spawning\Metadata\GenericEntityMetadataProcessor.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))]
7+
[ProtoContract, ProtoInclude(50, typeof(KeypadMetadata)), ProtoInclude(60, typeof(SealedDoorMetadata))]
88
public abstract class EntityMetadata
99
{
1010
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using ProtoBufNet;
3+
4+
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
5+
{
6+
[Serializable]
7+
[ProtoContract]
8+
public class SealedDoorMetadata : EntityMetadata
9+
{
10+
[ProtoMember(1)]
11+
public bool Sealed { get; }
12+
13+
public SealedDoorMetadata()
14+
{
15+
// Constructor for serialization
16+
}
17+
18+
public SealedDoorMetadata(bool Sealed)
19+
{
20+
this.Sealed = Sealed;
21+
}
22+
}
23+
}

NitroxModel/NitroxModel.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
<Compile Include="Core\IAutoFacRegistrar.cs" />
231231
<Compile Include="Core\NitroxEnvironment.cs" />
232232
<Compile Include="Core\NitroxServiceLocator.cs" />
233+
<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" />
235236
<Compile Include="DataStructures\GameLogic\Entities\UwePrefab.cs" />

NitroxPatcher/NitroxPatcher.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@
228228
<Compile Include="Main.cs" />
229229
<Compile Include="Modules\NitroxPatchesModule.cs" />
230230
<Compile Include="Patches\Dynamic\KeypadDoorConsole_AcceptNumberField_Patch.cs" />
231+
<Compile Include="Patches\Dynamic\Sealed_Weld_Patch.cs" />
231232
<Compile Include="Patches\Dynamic\Base_CopyFrom_Patch.cs" />
232233
<Compile Include="Patches\Dynamic\Constructable_SetState_Patch.cs" />
233234
<Compile Include="Patches\Dynamic\CrashHome_Spawn_Patch.cs" />
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Reflection;
3+
using Harmony;
4+
using NitroxClient.GameLogic;
5+
using NitroxClient.MonoBehaviours;
6+
using NitroxModel.Core;
7+
using NitroxModel.DataStructures;
8+
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
9+
10+
namespace NitroxPatcher.Patches.Dynamic
11+
{
12+
public class Sealed_Weld_Patch : NitroxPatch, IDynamicPatch
13+
{
14+
public static readonly Type TARGET_CLASS = typeof(Sealed);
15+
public static readonly MethodInfo TARGET_METHOD = TARGET_CLASS.GetMethod("Weld", BindingFlags.Public | BindingFlags.Instance);
16+
17+
public static bool Prefix(Sealed __instance, out bool __state)
18+
{
19+
__state = __instance._sealed;
20+
return true;
21+
}
22+
23+
public static void Postfix(Sealed __instance, bool __state)
24+
{
25+
if (__state != __instance._sealed)
26+
{
27+
NitroxId id = NitroxEntity.GetId(__instance.gameObject);
28+
SealedDoorMetadata doorMetadata = new SealedDoorMetadata(__instance._sealed);
29+
30+
Entities entities = NitroxServiceLocator.LocateService<Entities>();
31+
entities.BroadcastMetadataUpdate(id, doorMetadata);
32+
}
33+
}
34+
35+
public override void Patch(HarmonyInstance harmony)
36+
{
37+
PatchMultiple(harmony, TARGET_METHOD, true, true, false);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)