Skip to content

Commit 162e573

Browse files
authored
Fix constructables sending one too many packet when being destroyed (SubnauticaNitrox#2503)
2 parents d32fbc6 + 8014524 commit 162e573

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

NitroxClient/Helpers/ThrottledPacketSender.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ public bool SendThrottled<T>(T packet, Func<T, object> dedupeMethod, float throt
4747
return true;
4848
}
4949

50-
throttledPackets.Add(dedupeKey, new ThrottledPacket(packet, throttleTime));
50+
throttledPacket = new(packet, throttleTime);
51+
throttledPackets.Add(dedupeKey, throttledPacket);
5152
packetSender.Send(packet);
53+
// It's very important to set WasSend to true, otherwise the packet will be sent again in Update()
54+
throttledPacket.WasSend = true;
5255
return true;
5356
}
5457

NitroxPatcher/Patches/Dynamic/Constructable_Construct_Patch.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ public static void ConstructionAmountModified(Constructable constructable, bool
103103
// update as a normal module
104104
Resolve<ThrottledPacketSender>().SendThrottled(new ModifyConstructedAmount(entityId, amount),
105105
(packet) => { return packet.GhostId; }, 0.1f);
106+
107+
// If we're done with that ghost we can remove the throttled packets
108+
if (amount == 0)
109+
{
110+
Resolve<ThrottledPacketSender>().RemovePendingPackets(entityId);
111+
}
106112
}
107113

108114
public static IEnumerator BroadcastObjectBuilt(ConstructableBase constructableBase, NitroxId entityId)

0 commit comments

Comments
 (0)