From 4deae11871b7cf0e684f75733c2eabc467598bdb Mon Sep 17 00:00:00 2001 From: staphen Date: Sun, 27 Aug 2023 14:21:25 -0400 Subject: [PATCH] Fix PlayerNetPack validation and tests --- Source/pack.cpp | 13 +++++++++---- test/pack_test.cpp | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Source/pack.cpp b/Source/pack.cpp index faaf741dd..626fcad5e 100644 --- a/Source/pack.cpp +++ b/Source/pack.cpp @@ -590,12 +590,17 @@ bool UnPackNetPlayer(const PlayerNetPack &packed, Player &player) player.InvGrid[i] = packed.InvGrid[i]; for (int i = 0; i < MaxBeltItems; i++) { - if (!UnPackNetItem(player, packed.SpdList[i], player.SpdList[i])) + Item &item = player.SpdList[i]; + if (!UnPackNetItem(player, packed.SpdList[i], item)) return false; - if (player.SpdList[i].isEmpty()) + if (item.isEmpty()) continue; - auto loc = static_cast(player.GetItemLocation(player.SpdList[i])); - ValidateField(loc, loc == ILOC_BELT); + Size beltItemSize = GetInventorySize(item); + int8_t beltItemType = static_cast(item._itype); + bool beltItemUsable = item.isUsable(); + ValidateFields(beltItemSize.width, beltItemSize.height, (beltItemSize == Size { 1, 1 })); + ValidateField(beltItemType, item._itype != ItemType::Gold); + ValidateField(beltItemUsable, beltItemUsable); } CalcPlrInv(player, false); diff --git a/test/pack_test.cpp b/test/pack_test.cpp index 31fa8d522..e24872687 100644 --- a/test/pack_test.cpp +++ b/test/pack_test.cpp @@ -870,6 +870,7 @@ public: { Players.resize(2); MyPlayer = &Players[0]; + gbIsMultiplayer = true; PlayerPack testPack { 0, 0, -1, 9, 0, 2, 61, 24, 0, 0, "MP-Warrior", 0, 120, 25, 60, 60, 37, 0, 85670061, 3921, 13568, 13568, 3904, 3904,