Browse Source

Indicate network validation success or failure in iteminfo

pull/6760/head
staphen 3 years ago committed by Anders Jenbo
parent
commit
1700ab9804
  1. 11
      Source/debug.cpp
  2. 75
      Source/pack.cpp
  3. 16
      Source/pack.h

11
Source/debug.cpp

@ -24,6 +24,7 @@
#include "lighting.h"
#include "monstdat.h"
#include "monster.h"
#include "pack.h"
#include "plrmsg.h"
#include "quests.h"
#include "spells.h"
@ -902,6 +903,13 @@ std::string DebugCmdItemInfo(const string_view parameter)
pItem = &Items[pcursitem];
}
if (pItem != nullptr) {
std::string_view netPackValidation { "N/A" };
if (gbIsMultiplayer) {
ItemNetPack itemPack;
Item unpacked;
PackNetItem(*pItem, itemPack);
netPackValidation = UnPackNetItem(myPlayer, itemPack, unpacked) ? "Success" : "Failure";
}
return StrCat("Name: ", pItem->_iIName,
"\nIDidx: ", pItem->IDidx, " (", AllItemsList[pItem->IDidx].iName, ")",
"\nSeed: ", pItem->_iSeed,
@ -916,7 +924,8 @@ std::string DebugCmdItemInfo(const string_view parameter)
"\nBoy: ", ((pItem->_iCreateInfo & CF_BOY) == 0) ? "False" : "True",
"\nWitch: ", ((pItem->_iCreateInfo & CF_WITCH) == 0) ? "False" : "True",
"\nHealer: ", ((pItem->_iCreateInfo & CF_HEALER) == 0) ? "False" : "True",
"\nPregen: ", ((pItem->_iCreateInfo & CF_PREGEN) == 0) ? "False" : "True");
"\nPregen: ", ((pItem->_iCreateInfo & CF_PREGEN) == 0) ? "False" : "True",
"\nNet Validation: ", netPackValidation);
}
return StrCat("Numitems: ", ActiveItemCount);
}

75
Source/pack.cpp

@ -75,17 +75,6 @@ void VerifyGoldSeeds(Player &player)
}
}
void PackNetItem(const Item &item, ItemNetPack &packedItem)
{
packedItem.def.wIndx = static_cast<_item_indexes>(SDL_SwapLE16(item.IDidx));
packedItem.def.wCI = SDL_SwapLE16(item._iCreateInfo);
packedItem.def.dwSeed = SDL_SwapLE32(item._iSeed);
if (item.IDidx != IDI_EAR)
PrepareItemForNetwork(item, packedItem.item);
else
PrepareEarForNetwork(item, packedItem.ear);
}
bool hasMultipleFlags(uint16_t flags)
{
return (flags & (flags - 1)) > 0;
@ -164,33 +153,6 @@ bool IsDungeonItemValid(uint16_t iCreateInfo, uint32_t dwBuff)
return level <= 30;
}
bool UnPackNetItem(const Player &player, const ItemNetPack &packedItem, Item &item)
{
item = {};
_item_indexes idx = static_cast<_item_indexes>(SDL_SwapLE16(packedItem.def.wIndx));
if (idx < 0 || idx > IDI_LAST)
return true;
if (idx == IDI_EAR) {
RecreateEar(item, SDL_SwapLE16(packedItem.ear.wCI), SDL_SwapLE32(packedItem.ear.dwSeed), packedItem.ear.bCursval, packedItem.ear.heroname);
return true;
}
uint16_t creationFlags = SDL_SwapLE16(packedItem.item.wCI);
uint32_t dwBuff = SDL_SwapLE16(packedItem.item.dwBuff);
if (idx != IDI_GOLD)
ValidateField(creationFlags, IsCreationFlagComboValid(creationFlags));
if ((creationFlags & CF_TOWN) != 0)
ValidateField(creationFlags, IsTownItemValid(creationFlags));
else if ((creationFlags & CF_USEFUL) == CF_UPER15)
ValidateFields(creationFlags, dwBuff, IsUniqueMonsterItemValid(creationFlags, dwBuff));
else
ValidateFields(creationFlags, dwBuff, IsDungeonItemValid(creationFlags, dwBuff));
RecreateItem(player, packedItem.item, item);
return true;
}
} // namespace
void PackItem(ItemPack &packedItem, const Item &item, bool isHellfire)
@ -290,6 +252,17 @@ void PackPlayer(PlayerPack &packed, const Player &player)
packed.bIsHellfire = gbIsHellfire ? 1 : 0;
}
void PackNetItem(const Item &item, ItemNetPack &packedItem)
{
packedItem.def.wIndx = static_cast<_item_indexes>(SDL_SwapLE16(item.IDidx));
packedItem.def.wCI = SDL_SwapLE16(item._iCreateInfo);
packedItem.def.dwSeed = SDL_SwapLE32(item._iSeed);
if (item.IDidx != IDI_EAR)
PrepareItemForNetwork(item, packedItem.item);
else
PrepareEarForNetwork(item, packedItem.ear);
}
void PackNetPlayer(PlayerNetPack &packed, const Player &player)
{
packed.plrlevel = player.plrlevel;
@ -489,6 +462,32 @@ void UnPackPlayer(const PlayerPack &packed, Player &player)
player.pDiabloKillLevel = SDL_SwapLE32(packed.pDiabloKillLevel);
}
bool UnPackNetItem(const Player &player, const ItemNetPack &packedItem, Item &item)
{
item = {};
_item_indexes idx = static_cast<_item_indexes>(SDL_SwapLE16(packedItem.def.wIndx));
if (idx < 0 || idx > IDI_LAST)
return true;
if (idx == IDI_EAR) {
RecreateEar(item, SDL_SwapLE16(packedItem.ear.wCI), SDL_SwapLE32(packedItem.ear.dwSeed), packedItem.ear.bCursval, packedItem.ear.heroname);
return true;
}
uint16_t creationFlags = SDL_SwapLE16(packedItem.item.wCI);
uint32_t dwBuff = SDL_SwapLE16(packedItem.item.dwBuff);
if (idx != IDI_GOLD)
ValidateField(creationFlags, IsCreationFlagComboValid(creationFlags));
if ((creationFlags & CF_TOWN) != 0)
ValidateField(creationFlags, IsTownItemValid(creationFlags));
else if ((creationFlags & CF_USEFUL) == CF_UPER15)
ValidateFields(creationFlags, dwBuff, IsUniqueMonsterItemValid(creationFlags, dwBuff));
else
ValidateFields(creationFlags, dwBuff, IsDungeonItemValid(creationFlags, dwBuff));
RecreateItem(player, packedItem.item, item);
return true;
}
bool UnPackNetPlayer(const PlayerNetPack &packed, Player &player)
{
CopyUtf8(player._pName, packed.pName, sizeof(player._pName));

16
Source/pack.h

@ -165,4 +165,20 @@ void PackItem(ItemPack &packedItem, const Item &item, bool isHellfire);
*/
void UnPackItem(const ItemPack &packedItem, const Player &player, Item &item, bool isHellfire);
/**
* @brief Save the attributes needed to recreate this item into an ItemNetPack struct
* @param item The source item
* @param packedItem The destination packed struct
*/
void PackNetItem(const Item &item, ItemNetPack &packedItem);
/**
* @brief Expand a ItemPack in to a Item
* @param player The player holding the item
* @param packedItem The source packed item
* @param item The destination item
* @return True if the item is valid
*/
bool UnPackNetItem(const Player &player, const ItemNetPack &packedItem, Item &item);
} // namespace devilution

Loading…
Cancel
Save