Browse Source

Support for ears in PlayerNetPack

pull/6305/head
staphen 3 years ago committed by Anders Jenbo
parent
commit
cc5261fa15
  1. 12
      Source/msg.cpp
  2. 1
      Source/msg.h
  3. 26
      Source/pack.cpp
  4. 12
      Source/pack.h

12
Source/msg.cpp

@ -970,12 +970,6 @@ bool IsPItemValid(const TCmdPItem &message)
return IsItemAvailable(static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)));
}
void PrepareEarForNetwork(const Item &item, TEar &ear)
{
ear.bCursval = item._ivalue | ((item._iCurs - ICURS_EAR_SORCERER) << 6);
CopyUtf8(ear.heroname, item._iIName, sizeof(ear.heroname));
}
void PrepareItemForNetwork(const Item &item, TCmdGItem &message)
{
message.def.wIndx = static_cast<_item_indexes>(SDL_SwapLE16(item.IDidx));
@ -2340,6 +2334,12 @@ void PrepareItemForNetwork(const Item &item, TItem &messageItem)
messageItem.dwBuff = SDL_SwapLE32(item.dwBuff);
}
void PrepareEarForNetwork(const Item &item, TEar &ear)
{
ear.bCursval = item._ivalue | ((item._iCurs - ICURS_EAR_SORCERER) << 6);
CopyUtf8(ear.heroname, item._iIName, sizeof(ear.heroname));
}
void RecreateItem(const Player &player, const TItem &messageItem, Item &item)
{
const uint32_t dwBuff = SDL_SwapLE32(messageItem.dwBuff);

1
Source/msg.h

@ -721,6 +721,7 @@ extern uint8_t gbBufferMsgs;
extern int dwRecCount;
void PrepareItemForNetwork(const Item &item, TItem &messageItem);
void PrepareEarForNetwork(const Item &item, TEar &ear);
void RecreateItem(const Player &player, const TItem &messageItem, Item &item);
void msg_send_drop_pkt(int pnum, int reason);
bool msg_wait_resync();

26
Source/pack.cpp

@ -37,23 +37,27 @@ void VerifyGoldSeeds(Player &player)
}
}
void PackNetItem(const Item &item, TItem &messageItem)
void PackNetItem(const Item &item, ItemNetPack &packedItem)
{
if (item.IDidx == IDI_EAR)
return;
messageItem.wIndx = static_cast<_item_indexes>(SDL_SwapLE16(item.IDidx));
messageItem.wCI = SDL_SwapLE16(item._iCreateInfo);
messageItem.dwSeed = SDL_SwapLE32(item._iSeed);
PrepareItemForNetwork(item, messageItem);
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 UnPackNetItem(const Player &player, const TItem &messageItem, Item &item)
void UnPackNetItem(const Player &player, const ItemNetPack &packedItem, Item &item)
{
item = {};
_item_indexes idx = static_cast<_item_indexes>(SDL_SwapLE16(messageItem.wIndx));
if (idx < 0 || idx > IDI_LAST || idx == IDI_EAR)
_item_indexes idx = static_cast<_item_indexes>(SDL_SwapLE16(packedItem.def.wIndx));
if (idx < 0 || idx > IDI_LAST)
return;
RecreateItem(player, messageItem, item);
if (idx != IDI_EAR)
RecreateItem(player, packedItem.item, item);
else
RecreateEar(item, SDL_SwapLE16(packedItem.ear.wCI), SDL_SwapLE32(packedItem.ear.dwSeed), packedItem.ear.bCursval, packedItem.ear.heroname);
}
} // namespace

12
Source/pack.h

@ -79,6 +79,12 @@ struct PlayerPack {
uint8_t reserved3[20]; // For future use
};
union ItemNetPack {
TItemDef def;
TItem item;
TEar ear;
};
struct PlayerNetPack {
uint8_t plrlevel;
uint8_t px;
@ -98,11 +104,11 @@ struct PlayerNetPack {
int32_t pMaxManaBase;
uint8_t pSplLvl[MAX_SPELLS];
uint64_t pMemSpells;
TItem InvBody[NUM_INVLOC];
TItem InvList[InventoryGridCells];
ItemNetPack InvBody[NUM_INVLOC];
ItemNetPack InvList[InventoryGridCells];
int8_t InvGrid[InventoryGridCells];
uint8_t _pNumInv;
TItem SpdList[MaxBeltItems];
ItemNetPack SpdList[MaxBeltItems];
uint8_t pManaShield;
uint16_t wReflections;
uint8_t pDiabloKillLevel;

Loading…
Cancel
Save