From b5b72e9f6c4a6d439ddc158fb6d01fb8391a0257 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Fri, 9 Jun 2023 03:00:45 -0400 Subject: [PATCH] Ensure `TSPlayer.PlayerData` is non-null whilst syncing loadouts During connection, we receive a `SyncLoadout` packet before the `ContinueConnecting2` packet, meaning we have not yet created a `PlayerData` for this player. --- TShockAPI/GetDataHandlers.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 1ef2f4f8..b736a512 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -4445,6 +4445,11 @@ namespace TShockAPI return true; } + // Don't modify the player data if it isn't there. + // This is the case whilst the player is connecting, as we receive the SyncLoadout packet before the ContinueConnecting2 packet. + if (args.Player.PlayerData == null) + return false; + // The client does not sync slot changes when changing loadouts, it only tells the server the loadout index changed, // and the server will replicate the changes the client did. This means that PlayerData.StoreSlot is never called, so we need to // swap around the PlayerData items ourself.