|
|
|
|
@ -50,6 +50,7 @@
|
|
|
|
|
#include "sync.h" |
|
|
|
|
#include "tmsg.h" |
|
|
|
|
#include "towners.h" |
|
|
|
|
#include "utils/endian_swap.hpp" |
|
|
|
|
#include "utils/is_of.hpp" |
|
|
|
|
#include "utils/language.h" |
|
|
|
|
#include "utils/str_cat.hpp" |
|
|
|
|
@ -391,7 +392,7 @@ bool WasPlayerCmdAlreadyRequested(_cmd_id bCmd, Point position = {}, uint16_t wP
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const TCmdLocParam5 newSendParam = { bCmd, static_cast<uint8_t>(position.x), static_cast<uint8_t>(position.y), |
|
|
|
|
SDL_SwapLE16(wParam1), SDL_SwapLE16(wParam2), SDL_SwapLE16(wParam3), SDL_SwapLE16(wParam4), SDL_SwapLE16(wParam5) }; |
|
|
|
|
Swap16LE(wParam1), Swap16LE(wParam2), Swap16LE(wParam3), Swap16LE(wParam4), Swap16LE(wParam5) }; |
|
|
|
|
|
|
|
|
|
if (lastSentPlayerCmd.bCmd == newSendParam.bCmd && lastSentPlayerCmd.x == newSendParam.x && lastSentPlayerCmd.y == newSendParam.y |
|
|
|
|
&& lastSentPlayerCmd.wParam1 == newSendParam.wParam1 && lastSentPlayerCmd.wParam2 == newSendParam.wParam2 |
|
|
|
|
@ -437,7 +438,7 @@ void PrePacket()
|
|
|
|
|
auto *cmd = reinterpret_cast<TFakeDropPlr *>(data); |
|
|
|
|
data += sizeof(*cmd); |
|
|
|
|
remainingBytes -= sizeof(*cmd); |
|
|
|
|
multi_player_left(cmd->bPlr, SDL_SwapLE32(cmd->dwReason)); |
|
|
|
|
multi_player_left(cmd->bPlr, Swap32LE(cmd->dwReason)); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -636,12 +637,12 @@ const std::byte *DeltaImportMonster(const std::byte *src, const std::byte *end,
|
|
|
|
|
|
|
|
|
|
std::byte *DeltaExportSpawnedMonsters(std::byte *dst, const ankerl::unordered_dense::map<size_t, DSpawnedMonster> &spawnedMonsters) |
|
|
|
|
{ |
|
|
|
|
uint16_t size = SDL_SwapLE16(static_cast<uint16_t>(spawnedMonsters.size())); |
|
|
|
|
uint16_t size = Swap16LE(static_cast<uint16_t>(spawnedMonsters.size())); |
|
|
|
|
memcpy(dst, &size, sizeof(uint16_t)); |
|
|
|
|
dst += sizeof(uint16_t); |
|
|
|
|
|
|
|
|
|
for (const auto &deltaSpawnedMonster : spawnedMonsters) { |
|
|
|
|
uint16_t monsterId = SDL_SwapLE16(static_cast<uint16_t>(deltaSpawnedMonster.first)); |
|
|
|
|
uint16_t monsterId = Swap16LE(static_cast<uint16_t>(deltaSpawnedMonster.first)); |
|
|
|
|
memcpy(dst, &monsterId, sizeof(uint16_t)); |
|
|
|
|
dst += sizeof(uint16_t); |
|
|
|
|
|
|
|
|
|
@ -659,7 +660,7 @@ const std::byte *DeltaImportSpawnedMonsters(const std::byte *src, const std::byt
|
|
|
|
|
|
|
|
|
|
uint16_t size; |
|
|
|
|
memcpy(&size, src, sizeof(uint16_t)); |
|
|
|
|
size = SDL_SwapLE16(size); |
|
|
|
|
size = Swap16LE(size); |
|
|
|
|
src += sizeof(uint16_t); |
|
|
|
|
if (size > MaxMonsters) |
|
|
|
|
return nullptr; |
|
|
|
|
@ -671,7 +672,7 @@ const std::byte *DeltaImportSpawnedMonsters(const std::byte *src, const std::byt
|
|
|
|
|
for (size_t i = 0; i < size; i++) { |
|
|
|
|
uint16_t monsterId; |
|
|
|
|
memcpy(&monsterId, src, sizeof(uint16_t)); |
|
|
|
|
monsterId = SDL_SwapLE16(monsterId); |
|
|
|
|
monsterId = Swap16LE(monsterId); |
|
|
|
|
src += sizeof(uint16_t); |
|
|
|
|
|
|
|
|
|
DSpawnedMonster spawnedMonster; |
|
|
|
|
@ -703,7 +704,7 @@ std::byte *DeltaExportJunk(std::byte *dst)
|
|
|
|
|
sgJunk.quests[q].qstate = quest._qactive; |
|
|
|
|
sgJunk.quests[q].qvar1 = quest._qvar1; |
|
|
|
|
sgJunk.quests[q].qvar2 = quest._qvar2; |
|
|
|
|
sgJunk.quests[q].qmsg = SDL_SwapLE16(static_cast<int16_t>(quest._qmsg)); |
|
|
|
|
sgJunk.quests[q].qmsg = Swap16LE(static_cast<int16_t>(quest._qmsg)); |
|
|
|
|
memcpy(dst, &sgJunk.quests[q], sizeof(MultiQuests)); |
|
|
|
|
dst += sizeof(MultiQuests); |
|
|
|
|
q++; |
|
|
|
|
@ -856,7 +857,7 @@ void DeltaLoadMonsters(const DLevel &deltaLevel)
|
|
|
|
|
ChangeLightXY(monster.lightId, position); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
monster.hitPoints = SDL_SwapLE32(deltaMonster.hitPoints); |
|
|
|
|
monster.hitPoints = Swap32LE(deltaMonster.hitPoints); |
|
|
|
|
monster.whoHit = deltaMonster.mWhoHit; |
|
|
|
|
if (deltaMonster.hitPoints != 0) |
|
|
|
|
continue; |
|
|
|
|
@ -923,9 +924,9 @@ void DeltaLoadItems(const DLevel &deltaLevel)
|
|
|
|
|
|
|
|
|
|
if (deltaItem.bCmd == TCmdPItem::PickedUpItem) { |
|
|
|
|
const int activeItemIndex = FindGetItem( |
|
|
|
|
SDL_SwapLE32(deltaItem.def.dwSeed), |
|
|
|
|
static_cast<_item_indexes>(SDL_SwapLE16(deltaItem.def.wIndx)), |
|
|
|
|
SDL_SwapLE16(deltaItem.def.wCI)); |
|
|
|
|
Swap32LE(deltaItem.def.dwSeed), |
|
|
|
|
static_cast<_item_indexes>(Swap16LE(deltaItem.def.wIndx)), |
|
|
|
|
Swap16LE(deltaItem.def.wCI)); |
|
|
|
|
if (activeItemIndex != -1) { |
|
|
|
|
const auto &position = Items[ActiveItems[activeItemIndex]].position; |
|
|
|
|
if (dItem[position.x][position.y] == ActiveItems[activeItemIndex] + 1) |
|
|
|
|
@ -949,8 +950,8 @@ void DeltaLoadItems(const DLevel &deltaLevel)
|
|
|
|
|
|
|
|
|
|
size_t OnLevelData(const TCmdPlrInfoHdr &message, size_t maxCmdSize, const Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t wBytes = SDL_SwapLE16(message.wBytes); |
|
|
|
|
const uint16_t wOffset = SDL_SwapLE16(message.wOffset); |
|
|
|
|
const uint16_t wBytes = Swap16LE(message.wBytes); |
|
|
|
|
const uint16_t wOffset = Swap16LE(message.wOffset); |
|
|
|
|
|
|
|
|
|
if (!ValidateCmdSize(wBytes + sizeof(message), maxCmdSize, player.getId())) |
|
|
|
|
return maxCmdSize; |
|
|
|
|
@ -1151,8 +1152,8 @@ void NetSendCmdGItem2(bool usonly, _cmd_id bCmd, uint8_t mast, uint8_t pnum, con
|
|
|
|
|
|
|
|
|
|
auto ticks = static_cast<int32_t>(SDL_GetTicks()); |
|
|
|
|
if (cmd.dwTime == 0) { |
|
|
|
|
cmd.dwTime = SDL_SwapLE32(ticks); |
|
|
|
|
} else if (ticks - SDL_SwapLE32(cmd.dwTime) > 5000) { |
|
|
|
|
cmd.dwTime = Swap32LE(ticks); |
|
|
|
|
} else if (ticks - Swap32LE(cmd.dwTime) > 5000) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1170,8 +1171,8 @@ bool NetSendCmdReq2(_cmd_id bCmd, const Player &player, uint8_t pnum, const TCmd
|
|
|
|
|
|
|
|
|
|
auto ticks = static_cast<int32_t>(SDL_GetTicks()); |
|
|
|
|
if (cmd.dwTime == 0) |
|
|
|
|
cmd.dwTime = SDL_SwapLE32(ticks); |
|
|
|
|
else if (ticks - SDL_SwapLE32(cmd.dwTime) > 5000) |
|
|
|
|
cmd.dwTime = Swap32LE(ticks); |
|
|
|
|
else if (ticks - Swap32LE(cmd.dwTime) > 5000) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
tmsg_add(reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
@ -1207,7 +1208,7 @@ size_t OnAddStrength(const TCmdParam1 &message, Player &player)
|
|
|
|
|
if (gbBufferMsgs == 1) |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
else if (message.wParam1 <= 256) |
|
|
|
|
ModifyPlrStr(player, SDL_SwapLE16(message.wParam1)); |
|
|
|
|
ModifyPlrStr(player, Swap16LE(message.wParam1)); |
|
|
|
|
|
|
|
|
|
return sizeof(message); |
|
|
|
|
} |
|
|
|
|
@ -1217,7 +1218,7 @@ size_t OnAddMagic(const TCmdParam1 &message, Player &player)
|
|
|
|
|
if (gbBufferMsgs == 1) |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
else if (message.wParam1 <= 256) |
|
|
|
|
ModifyPlrMag(player, SDL_SwapLE16(message.wParam1)); |
|
|
|
|
ModifyPlrMag(player, Swap16LE(message.wParam1)); |
|
|
|
|
|
|
|
|
|
return sizeof(message); |
|
|
|
|
} |
|
|
|
|
@ -1227,7 +1228,7 @@ size_t OnAddDexterity(const TCmdParam1 &message, Player &player)
|
|
|
|
|
if (gbBufferMsgs == 1) |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
else if (message.wParam1 <= 256) |
|
|
|
|
ModifyPlrDex(player, SDL_SwapLE16(message.wParam1)); |
|
|
|
|
ModifyPlrDex(player, Swap16LE(message.wParam1)); |
|
|
|
|
|
|
|
|
|
return sizeof(message); |
|
|
|
|
} |
|
|
|
|
@ -1237,7 +1238,7 @@ size_t OnAddVitality(const TCmdParam1 &message, Player &player)
|
|
|
|
|
if (gbBufferMsgs == 1) |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
else if (message.wParam1 <= 256) |
|
|
|
|
ModifyPlrVit(player, SDL_SwapLE16(message.wParam1)); |
|
|
|
|
ModifyPlrVit(player, Swap16LE(message.wParam1)); |
|
|
|
|
|
|
|
|
|
return sizeof(message); |
|
|
|
|
} |
|
|
|
|
@ -1246,10 +1247,10 @@ size_t OnGotoGetItem(const TCmdLocParam1 &message, Player &player)
|
|
|
|
|
{ |
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1 && player.isOnActiveLevel() && InDungeonBounds(position) && SDL_SwapLE16(message.wParam1) < MAXITEMS + 1) { |
|
|
|
|
if (gbBufferMsgs != 1 && player.isOnActiveLevel() && InDungeonBounds(position) && Swap16LE(message.wParam1) < MAXITEMS + 1) { |
|
|
|
|
MakePlrPath(player, position, false); |
|
|
|
|
player.destAction = ACTION_PICKUPITEM; |
|
|
|
|
player.destParam1 = SDL_SwapLE16(message.wParam1); |
|
|
|
|
player.destParam1 = Swap16LE(message.wParam1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return sizeof(message); |
|
|
|
|
@ -1269,7 +1270,7 @@ bool IsGItemValid(const TCmdGItem &message)
|
|
|
|
|
if (!InDungeonBounds({ message.x, message.y })) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
return IsItemAvailable(static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx))); |
|
|
|
|
return IsItemAvailable(static_cast<_item_indexes>(Swap16LE(message.def.wIndx))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsPItemValid(const TCmdPItem &message, const Player &player) |
|
|
|
|
@ -1282,11 +1283,11 @@ bool IsPItemValid(const TCmdPItem &message, const Player &player)
|
|
|
|
|
if (!InDungeonBounds(position)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
auto idx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)); |
|
|
|
|
auto idx = static_cast<_item_indexes>(Swap16LE(message.def.wIndx)); |
|
|
|
|
|
|
|
|
|
if (idx != IDI_EAR) { |
|
|
|
|
const uint16_t creationFlags = SDL_SwapLE16(message.item.wCI); |
|
|
|
|
const uint32_t dwBuff = SDL_SwapLE16(message.item.dwBuff); |
|
|
|
|
const uint16_t creationFlags = Swap16LE(message.item.wCI); |
|
|
|
|
const uint32_t dwBuff = Swap16LE(message.item.dwBuff); |
|
|
|
|
|
|
|
|
|
if (idx != IDI_GOLD) |
|
|
|
|
ValidateField(creationFlags, IsCreationFlagComboValid(creationFlags)); |
|
|
|
|
@ -1305,9 +1306,9 @@ bool IsPItemValid(const TCmdPItem &message, const Player &player)
|
|
|
|
|
|
|
|
|
|
void PrepareItemForNetwork(const Item &item, TCmdGItem &message) |
|
|
|
|
{ |
|
|
|
|
message.def.wIndx = static_cast<_item_indexes>(SDL_SwapLE16(item.IDidx)); |
|
|
|
|
message.def.wCI = SDL_SwapLE16(item._iCreateInfo); |
|
|
|
|
message.def.dwSeed = SDL_SwapLE32(item._iSeed); |
|
|
|
|
message.def.wIndx = static_cast<_item_indexes>(Swap16LE(item.IDidx)); |
|
|
|
|
message.def.wCI = Swap16LE(item._iCreateInfo); |
|
|
|
|
message.def.dwSeed = Swap32LE(item._iSeed); |
|
|
|
|
|
|
|
|
|
if (item.IDidx == IDI_EAR) |
|
|
|
|
PrepareEarForNetwork(item, message.ear); |
|
|
|
|
@ -1317,9 +1318,9 @@ void PrepareItemForNetwork(const Item &item, TCmdGItem &message)
|
|
|
|
|
|
|
|
|
|
void PrepareItemForNetwork(const Item &item, TCmdPItem &message) |
|
|
|
|
{ |
|
|
|
|
message.def.wIndx = static_cast<_item_indexes>(SDL_SwapLE16(item.IDidx)); |
|
|
|
|
message.def.wCI = SDL_SwapLE16(item._iCreateInfo); |
|
|
|
|
message.def.dwSeed = SDL_SwapLE32(item._iSeed); |
|
|
|
|
message.def.wIndx = static_cast<_item_indexes>(Swap16LE(item.IDidx)); |
|
|
|
|
message.def.wCI = Swap16LE(item._iCreateInfo); |
|
|
|
|
message.def.dwSeed = Swap32LE(item._iSeed); |
|
|
|
|
|
|
|
|
|
if (item.IDidx == IDI_EAR) |
|
|
|
|
PrepareEarForNetwork(item, message.ear); |
|
|
|
|
@ -1329,9 +1330,9 @@ void PrepareItemForNetwork(const Item &item, TCmdPItem &message)
|
|
|
|
|
|
|
|
|
|
void PrepareItemForNetwork(const Item &item, TCmdChItem &message) |
|
|
|
|
{ |
|
|
|
|
message.def.wIndx = static_cast<_item_indexes>(SDL_SwapLE16(item.IDidx)); |
|
|
|
|
message.def.wCI = SDL_SwapLE16(item._iCreateInfo); |
|
|
|
|
message.def.dwSeed = SDL_SwapLE32(item._iSeed); |
|
|
|
|
message.def.wIndx = static_cast<_item_indexes>(Swap16LE(item.IDidx)); |
|
|
|
|
message.def.wCI = Swap16LE(item._iCreateInfo); |
|
|
|
|
message.def.dwSeed = Swap32LE(item._iSeed); |
|
|
|
|
|
|
|
|
|
if (item.IDidx == IDI_EAR) |
|
|
|
|
PrepareEarForNetwork(item, message.ear); |
|
|
|
|
@ -1341,16 +1342,16 @@ void PrepareItemForNetwork(const Item &item, TCmdChItem &message)
|
|
|
|
|
|
|
|
|
|
void RecreateItem(const Player &player, const TCmdPItem &message, Item &item) |
|
|
|
|
{ |
|
|
|
|
if (message.def.wIndx == SDL_SwapLE16(IDI_EAR)) |
|
|
|
|
RecreateEar(item, SDL_SwapLE16(message.ear.wCI), SDL_SwapLE32(message.ear.dwSeed), message.ear.bCursval, message.ear.heroname); |
|
|
|
|
if (message.def.wIndx == Swap16LE(IDI_EAR)) |
|
|
|
|
RecreateEar(item, Swap16LE(message.ear.wCI), Swap32LE(message.ear.dwSeed), message.ear.bCursval, message.ear.heroname); |
|
|
|
|
else |
|
|
|
|
RecreateItem(player, message.item, item); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RecreateItem(const Player &player, const TCmdChItem &message, Item &item) |
|
|
|
|
{ |
|
|
|
|
if (message.def.wIndx == SDL_SwapLE16(IDI_EAR)) |
|
|
|
|
RecreateEar(item, SDL_SwapLE16(message.ear.wCI), SDL_SwapLE32(message.ear.dwSeed), message.ear.bCursval, message.ear.heroname); |
|
|
|
|
if (message.def.wIndx == Swap16LE(IDI_EAR)) |
|
|
|
|
RecreateEar(item, Swap16LE(message.ear.wCI), Swap32LE(message.ear.dwSeed), message.ear.bCursval, message.ear.heroname); |
|
|
|
|
else |
|
|
|
|
RecreateItem(player, message.item, item); |
|
|
|
|
} |
|
|
|
|
@ -1359,26 +1360,26 @@ int SyncDropItem(Point position, const TItem &item)
|
|
|
|
|
{ |
|
|
|
|
return SyncDropItem( |
|
|
|
|
position, |
|
|
|
|
static_cast<_item_indexes>(SDL_SwapLE16(item.wIndx)), |
|
|
|
|
SDL_SwapLE16(item.wCI), |
|
|
|
|
SDL_SwapLE32(item.dwSeed), |
|
|
|
|
static_cast<_item_indexes>(Swap16LE(item.wIndx)), |
|
|
|
|
Swap16LE(item.wCI), |
|
|
|
|
Swap32LE(item.dwSeed), |
|
|
|
|
item.bId, |
|
|
|
|
item.bDur, |
|
|
|
|
item.bMDur, |
|
|
|
|
item.bCh, |
|
|
|
|
item.bMCh, |
|
|
|
|
SDL_SwapLE16(item.wValue), |
|
|
|
|
SDL_SwapLE32(item.dwBuff), |
|
|
|
|
SDL_SwapLE16(item.wToHit), |
|
|
|
|
SDL_SwapLE16(item.wMaxDam)); |
|
|
|
|
Swap16LE(item.wValue), |
|
|
|
|
Swap32LE(item.dwBuff), |
|
|
|
|
Swap16LE(item.wToHit), |
|
|
|
|
Swap16LE(item.wMaxDam)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int SyncDropEar(Point position, const TEar &ear) |
|
|
|
|
{ |
|
|
|
|
return SyncDropEar( |
|
|
|
|
position, |
|
|
|
|
SDL_SwapLE16(ear.wCI), |
|
|
|
|
SDL_SwapLE32(ear.dwSeed), |
|
|
|
|
Swap16LE(ear.wCI), |
|
|
|
|
Swap32LE(ear.dwSeed), |
|
|
|
|
ear.bCursval, |
|
|
|
|
ear.heroname); |
|
|
|
|
} |
|
|
|
|
@ -1417,9 +1418,9 @@ size_t OnRequestGetItem(const TCmdGItem &message, Player &player)
|
|
|
|
|
return sizeof(message); |
|
|
|
|
|
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
const uint32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = SDL_SwapLE16(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)); |
|
|
|
|
const uint32_t dwSeed = Swap32LE(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = Swap16LE(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(Swap16LE(message.def.wIndx)); |
|
|
|
|
if (!GetItemRecord(dwSeed, wCI, wIndx)) |
|
|
|
|
return sizeof(message); |
|
|
|
|
|
|
|
|
|
@ -1464,9 +1465,9 @@ size_t OnGetItem(const TCmdGItem &message, Player &player)
|
|
|
|
|
return sizeof(message); |
|
|
|
|
|
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
const uint32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = SDL_SwapLE16(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)); |
|
|
|
|
const uint32_t dwSeed = Swap32LE(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = Swap16LE(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(Swap16LE(message.def.wIndx)); |
|
|
|
|
if (!DeltaGetItem(message, message.bLevel)) { |
|
|
|
|
NetSendCmdGItem2(true, CMD_GETITEM, message.bMaster, message.bPnum, message); |
|
|
|
|
return sizeof(message); |
|
|
|
|
@ -1497,7 +1498,7 @@ size_t OnGotoAutoGetItem(const TCmdLocParam1 &message, Player &player)
|
|
|
|
|
{ |
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
|
|
|
|
|
const uint16_t itemIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t itemIdx = Swap16LE(message.wParam1); |
|
|
|
|
if (gbBufferMsgs != 1 && player.isOnActiveLevel() && InDungeonBounds(position) && itemIdx < MAXITEMS + 1) { |
|
|
|
|
MakePlrPath(player, position, false); |
|
|
|
|
player.destAction = ACTION_PICKUPAITEM; |
|
|
|
|
@ -1511,9 +1512,9 @@ size_t OnRequestAutoGetItem(const TCmdGItem &message, Player &player)
|
|
|
|
|
{ |
|
|
|
|
if (gbBufferMsgs != 1 && player.isLevelOwnedByLocalClient() && IsGItemValid(message)) { |
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
const uint32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = SDL_SwapLE16(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)); |
|
|
|
|
const uint32_t dwSeed = Swap32LE(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = Swap16LE(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(Swap16LE(message.def.wIndx)); |
|
|
|
|
if (GetItemRecord(dwSeed, wCI, wIndx)) { |
|
|
|
|
if (FindGetItem(dwSeed, wIndx, wCI) != -1) { |
|
|
|
|
NetSendCmdGItem2(false, CMD_AGETITEM, MyPlayerId, message.bPnum, message); |
|
|
|
|
@ -1552,7 +1553,7 @@ size_t OnAutoGetItem(const TCmdGItem &message, Player &player)
|
|
|
|
|
return sizeof(message); |
|
|
|
|
|
|
|
|
|
if (message.bPnum != MyPlayerId) { |
|
|
|
|
SyncGetItem(position, SDL_SwapLE32(message.def.dwSeed), static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)), SDL_SwapLE16(message.def.wCI)); |
|
|
|
|
SyncGetItem(position, Swap32LE(message.def.dwSeed), static_cast<_item_indexes>(Swap16LE(message.def.wIndx)), Swap16LE(message.def.wCI)); |
|
|
|
|
return sizeof(message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1575,7 +1576,7 @@ size_t OnItemExtra(const TCmdGItem &message, Player &player)
|
|
|
|
|
DeltaGetItem(message, message.bLevel); |
|
|
|
|
if (player.isOnActiveLevel()) { |
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
SyncGetItem(position, SDL_SwapLE32(message.def.dwSeed), static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)), SDL_SwapLE16(message.def.wCI)); |
|
|
|
|
SyncGetItem(position, Swap32LE(message.def.dwSeed), static_cast<_item_indexes>(Swap16LE(message.def.wIndx)), Swap16LE(message.def.wCI)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1589,9 +1590,9 @@ size_t OnPutItem(const TCmdPItem &message, Player &player)
|
|
|
|
|
} else if (IsPItemValid(message, player)) { |
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
const bool isSelf = &player == MyPlayer; |
|
|
|
|
const int32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = SDL_SwapLE16(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)); |
|
|
|
|
const int32_t dwSeed = Swap32LE(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = Swap16LE(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(Swap16LE(message.def.wIndx)); |
|
|
|
|
if (player.isOnActiveLevel()) { |
|
|
|
|
int ii; |
|
|
|
|
if (isSelf) { |
|
|
|
|
@ -1624,9 +1625,9 @@ size_t OnSyncPutItem(const TCmdPItem &message, Player &player)
|
|
|
|
|
if (gbBufferMsgs == 1) |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
else if (IsPItemValid(message, player)) { |
|
|
|
|
const int32_t dwSeed = SDL_SwapLE32(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = SDL_SwapLE16(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)); |
|
|
|
|
const int32_t dwSeed = Swap32LE(message.def.dwSeed); |
|
|
|
|
const uint16_t wCI = Swap16LE(message.def.wCI); |
|
|
|
|
const auto wIndx = static_cast<_item_indexes>(Swap16LE(message.def.wIndx)); |
|
|
|
|
if (player.isOnActiveLevel()) { |
|
|
|
|
const int ii = SyncDropItem(message); |
|
|
|
|
if (ii != -1) { |
|
|
|
|
@ -1690,9 +1691,9 @@ size_t OnRangedAttackTile(const TCmdLoc &message, Player &player)
|
|
|
|
|
|
|
|
|
|
bool InitNewSpell(Player &player, uint16_t wParamSpellID, uint16_t wParamSpellType, uint16_t wParamSpellFrom) |
|
|
|
|
{ |
|
|
|
|
wParamSpellID = SDL_SwapLE16(wParamSpellID); |
|
|
|
|
wParamSpellType = SDL_SwapLE16(wParamSpellType); |
|
|
|
|
wParamSpellFrom = SDL_SwapLE16(wParamSpellFrom); |
|
|
|
|
wParamSpellID = Swap16LE(wParamSpellID); |
|
|
|
|
wParamSpellType = Swap16LE(wParamSpellType); |
|
|
|
|
wParamSpellFrom = Swap16LE(wParamSpellFrom); |
|
|
|
|
|
|
|
|
|
if (wParamSpellID > static_cast<int8_t>(SpellID::LAST)) |
|
|
|
|
return false; |
|
|
|
|
@ -1732,7 +1733,7 @@ size_t OnSpellWall(const TCmdLocParam4 &message, Player &player)
|
|
|
|
|
return sizeof(message); |
|
|
|
|
if (!InDungeonBounds(position)) |
|
|
|
|
return sizeof(message); |
|
|
|
|
const int16_t wParamDirection = SDL_SwapLE16(message.wParam3); |
|
|
|
|
const int16_t wParamDirection = Swap16LE(message.wParam3); |
|
|
|
|
if (wParamDirection > static_cast<uint16_t>(Direction::SouthEast)) |
|
|
|
|
return sizeof(message); |
|
|
|
|
|
|
|
|
|
@ -1804,7 +1805,7 @@ size_t OnObjectTileAction(const TCmdLoc &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnAttackMonster(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t monsterIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t monsterIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1 && player.isOnActiveLevel() && leveltype != DTYPE_TOWN && monsterIdx < MaxMonsters) { |
|
|
|
|
const Point position = Monsters[monsterIdx].position.future; |
|
|
|
|
@ -1819,7 +1820,7 @@ size_t OnAttackMonster(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnAttackPlayer(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t playerIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t playerIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1 && player.isOnActiveLevel() && leveltype != DTYPE_TOWN && playerIdx < Players.size()) { |
|
|
|
|
MakePlrPath(player, Players[playerIdx].position.future, false); |
|
|
|
|
@ -1832,7 +1833,7 @@ size_t OnAttackPlayer(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnRangedAttackMonster(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t monsterIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t monsterIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1 && player.isOnActiveLevel() && leveltype != DTYPE_TOWN && monsterIdx < MaxMonsters) { |
|
|
|
|
ClrPlrPath(player); |
|
|
|
|
@ -1845,7 +1846,7 @@ size_t OnRangedAttackMonster(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnRangedAttackPlayer(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t playerIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t playerIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1 && player.isOnActiveLevel() && leveltype != DTYPE_TOWN && playerIdx < Players.size()) { |
|
|
|
|
ClrPlrPath(player); |
|
|
|
|
@ -1864,7 +1865,7 @@ size_t OnSpellMonster(const TCmdParam4 &message, Player &player)
|
|
|
|
|
return sizeof(message); |
|
|
|
|
if (leveltype == DTYPE_TOWN) |
|
|
|
|
return sizeof(message); |
|
|
|
|
const uint16_t monsterIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t monsterIdx = Swap16LE(message.wParam1); |
|
|
|
|
if (monsterIdx >= MaxMonsters) |
|
|
|
|
return sizeof(message); |
|
|
|
|
|
|
|
|
|
@ -1885,7 +1886,7 @@ size_t OnSpellPlayer(const TCmdParam4 &message, Player &player)
|
|
|
|
|
return sizeof(message); |
|
|
|
|
if (!player.isOnActiveLevel()) |
|
|
|
|
return sizeof(message); |
|
|
|
|
const uint16_t playerIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t playerIdx = Swap16LE(message.wParam1); |
|
|
|
|
if (playerIdx >= Players.size()) |
|
|
|
|
return sizeof(message); |
|
|
|
|
|
|
|
|
|
@ -1902,7 +1903,7 @@ size_t OnSpellPlayer(const TCmdParam4 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnKnockback(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t monsterIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t monsterIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1 && player.isOnActiveLevel() && leveltype != DTYPE_TOWN && monsterIdx < MaxMonsters) { |
|
|
|
|
Monster &monster = Monsters[monsterIdx]; |
|
|
|
|
@ -1915,7 +1916,7 @@ size_t OnKnockback(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnResurrect(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t playerIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t playerIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
@ -1930,7 +1931,7 @@ size_t OnResurrect(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnHealOther(const TCmdParam1 &message, const Player &caster) |
|
|
|
|
{ |
|
|
|
|
const uint16_t playerIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t playerIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1) { |
|
|
|
|
if (caster.isOnActiveLevel() && playerIdx < Players.size()) { |
|
|
|
|
@ -1944,7 +1945,7 @@ size_t OnHealOther(const TCmdParam1 &message, const Player &caster)
|
|
|
|
|
size_t OnTalkXY(const TCmdLocParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
const uint16_t townerIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t townerIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1 && player.isOnActiveLevel() && InDungeonBounds(position) && townerIdx < NUM_TOWNERS) { |
|
|
|
|
MakePlrPath(player, position, false); |
|
|
|
|
@ -1957,7 +1958,7 @@ size_t OnTalkXY(const TCmdLocParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnNewLevel(const TCmdParam2 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t eventIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t eventIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
@ -1967,7 +1968,7 @@ size_t OnNewLevel(const TCmdParam2 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
auto mode = static_cast<interface_mode>(eventIdx); |
|
|
|
|
|
|
|
|
|
const auto levelId = static_cast<uint8_t>(SDL_SwapLE16(message.wParam2)); |
|
|
|
|
const auto levelId = static_cast<uint8_t>(Swap16LE(message.wParam2)); |
|
|
|
|
if (!IsValidLevel(levelId, mode == WM_DIABSETLVL)) { |
|
|
|
|
return sizeof(message); |
|
|
|
|
} |
|
|
|
|
@ -1980,7 +1981,7 @@ size_t OnNewLevel(const TCmdParam2 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnWarp(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t portalIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t portalIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
@ -1994,7 +1995,7 @@ size_t OnWarp(const TCmdParam1 &message, Player &player)
|
|
|
|
|
size_t OnMonstDeath(const TCmdLocParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
const uint16_t monsterIdx = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t monsterIdx = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1) { |
|
|
|
|
if (&player != MyPlayer && player.plrlevel > 0 && InDungeonBounds(position) && monsterIdx < MaxMonsters) { |
|
|
|
|
@ -2025,7 +2026,7 @@ size_t OnRequestSpawnGolem(const TCmdLocParam1 &message, const Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnMonstDamage(const TCmdMonDamage &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t monsterIdx = SDL_SwapLE16(message.wMon); |
|
|
|
|
const uint16_t monsterIdx = Swap16LE(message.wMon); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1) { |
|
|
|
|
if (&player != MyPlayer) { |
|
|
|
|
@ -2033,7 +2034,7 @@ size_t OnMonstDamage(const TCmdMonDamage &message, Player &player)
|
|
|
|
|
Monster &monster = Monsters[monsterIdx]; |
|
|
|
|
monster.tag(player); |
|
|
|
|
if (monster.hitPoints > 0) { |
|
|
|
|
monster.hitPoints -= SDL_SwapLE32(message.dwDam); |
|
|
|
|
monster.hitPoints -= Swap32LE(message.dwDam); |
|
|
|
|
if ((monster.hitPoints >> 6) < 1) |
|
|
|
|
monster.hitPoints = 1 << 6; |
|
|
|
|
delta_monster_hp(monster, player); |
|
|
|
|
@ -2049,7 +2050,7 @@ size_t OnMonstDamage(const TCmdMonDamage &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnPlayerDeath(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const auto deathReason = static_cast<DeathReason>(SDL_SwapLE16(message.wParam1)); |
|
|
|
|
const auto deathReason = static_cast<DeathReason>(Swap16LE(message.wParam1)); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1) { |
|
|
|
|
if (&player != MyPlayer) |
|
|
|
|
@ -2065,7 +2066,7 @@ size_t OnPlayerDeath(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnPlayerDamage(const TCmdDamage &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint32_t damage = SDL_SwapLE32(message.dwDam); |
|
|
|
|
const uint32_t damage = Swap32LE(message.dwDam); |
|
|
|
|
|
|
|
|
|
Player &target = Players[message.bPlr]; |
|
|
|
|
if (&target == MyPlayer && leveltype != DTYPE_TOWN && gbBufferMsgs != 1) { |
|
|
|
|
@ -2126,7 +2127,7 @@ size_t OnChangePlayerItems(const TCmdChItem &message, Player &player)
|
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
} else if (&player != MyPlayer && IsItemAvailable(static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)))) { |
|
|
|
|
} else if (&player != MyPlayer && IsItemAvailable(static_cast<_item_indexes>(Swap16LE(message.def.wIndx)))) { |
|
|
|
|
Item &item = player.InvBody[message.bLoc]; |
|
|
|
|
item = {}; |
|
|
|
|
RecreateItem(player, message, item); |
|
|
|
|
@ -2157,7 +2158,7 @@ size_t OnChangeInventoryItems(const TCmdChItem &message, Player &player)
|
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
} else if (&player != MyPlayer && IsItemAvailable(static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)))) { |
|
|
|
|
} else if (&player != MyPlayer && IsItemAvailable(static_cast<_item_indexes>(Swap16LE(message.def.wIndx)))) { |
|
|
|
|
Item item {}; |
|
|
|
|
RecreateItem(player, message, item); |
|
|
|
|
CheckInvSwap(player, item, message.bLoc); |
|
|
|
|
@ -2168,7 +2169,7 @@ size_t OnChangeInventoryItems(const TCmdChItem &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnDeleteInventoryItems(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t invGridIndex = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t invGridIndex = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
@ -2186,7 +2187,7 @@ size_t OnChangeBeltItems(const TCmdChItem &message, Player &player)
|
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
} else if (&player != MyPlayer && IsItemAvailable(static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx)))) { |
|
|
|
|
} else if (&player != MyPlayer && IsItemAvailable(static_cast<_item_indexes>(Swap16LE(message.def.wIndx)))) { |
|
|
|
|
Item &item = player.SpdList[message.bLoc]; |
|
|
|
|
item = {}; |
|
|
|
|
RecreateItem(player, message, item); |
|
|
|
|
@ -2197,7 +2198,7 @@ size_t OnChangeBeltItems(const TCmdChItem &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnDeleteBeltItems(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t spdBarIndex = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t spdBarIndex = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
@ -2210,7 +2211,7 @@ size_t OnDeleteBeltItems(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnPlayerLevel(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t playerLevel = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t playerLevel = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1) { |
|
|
|
|
if (playerLevel <= player.getMaxCharacterLevel() && &player != MyPlayer) |
|
|
|
|
@ -2241,7 +2242,7 @@ size_t OnSpawnItem(const TCmdPItem &message, Player &player)
|
|
|
|
|
if (player.isOnActiveLevel() && &player != MyPlayer) { |
|
|
|
|
SyncDropItem(message); |
|
|
|
|
} |
|
|
|
|
PutItemRecord(SDL_SwapLE32(message.def.dwSeed), SDL_SwapLE16(message.def.wCI), static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx))); |
|
|
|
|
PutItemRecord(Swap32LE(message.def.dwSeed), Swap16LE(message.def.wCI), static_cast<_item_indexes>(Swap16LE(message.def.wIndx))); |
|
|
|
|
DeltaPutItem(message, { message.x, message.y }, player); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -2250,7 +2251,7 @@ size_t OnSpawnItem(const TCmdPItem &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnSendPlayerInfo(const TCmdPlrInfoHdr &header, size_t maxCmdSize, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t wBytes = SDL_SwapLE16(header.wBytes); |
|
|
|
|
const uint16_t wBytes = Swap16LE(header.wBytes); |
|
|
|
|
|
|
|
|
|
if (!ValidateCmdSize(wBytes + sizeof(header), maxCmdSize, player.getId())) |
|
|
|
|
return maxCmdSize; |
|
|
|
|
@ -2272,7 +2273,7 @@ size_t OnPlayerJoinLevel(const TCmdLocParam2 &message, Player &player)
|
|
|
|
|
return sizeof(message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const auto playerLevel = static_cast<uint8_t>(SDL_SwapLE16(message.wParam1)); |
|
|
|
|
const auto playerLevel = static_cast<uint8_t>(Swap16LE(message.wParam1)); |
|
|
|
|
const bool isSetLevel = message.wParam2 != 0; |
|
|
|
|
if (!IsValidLevel(playerLevel, isSetLevel) || !InDungeonBounds(position)) { |
|
|
|
|
return sizeof(message); |
|
|
|
|
@ -2321,8 +2322,8 @@ size_t OnPlayerJoinLevel(const TCmdLocParam2 &message, Player &player)
|
|
|
|
|
size_t OnActivatePortal(const TCmdLocParam3 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const Point position { message.x, message.y }; |
|
|
|
|
const auto level = static_cast<uint8_t>(SDL_SwapLE16(message.wParam1)); |
|
|
|
|
const uint16_t dungeonTypeIdx = SDL_SwapLE16(message.wParam2); |
|
|
|
|
const auto level = static_cast<uint8_t>(Swap16LE(message.wParam1)); |
|
|
|
|
const uint16_t dungeonTypeIdx = Swap16LE(message.wParam2); |
|
|
|
|
const bool isSetLevel = message.wParam3 != 0; |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
@ -2386,7 +2387,7 @@ size_t OnRestartTown(const TCmd &cmd, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnSetStrength(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t value = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t value = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1) { |
|
|
|
|
if (value <= 750 && &player != MyPlayer) |
|
|
|
|
@ -2400,7 +2401,7 @@ size_t OnSetStrength(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnSetDexterity(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t value = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t value = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1) { |
|
|
|
|
if (value <= 750 && &player != MyPlayer) |
|
|
|
|
@ -2414,7 +2415,7 @@ size_t OnSetDexterity(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnSetMagic(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t value = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t value = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1) { |
|
|
|
|
if (value <= 750 && &player != MyPlayer) |
|
|
|
|
@ -2428,7 +2429,7 @@ size_t OnSetMagic(const TCmdParam1 &message, Player &player)
|
|
|
|
|
|
|
|
|
|
size_t OnSetVitality(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
const uint16_t value = SDL_SwapLE16(message.wParam1); |
|
|
|
|
const uint16_t value = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs != 1) { |
|
|
|
|
if (value <= 750 && &player != MyPlayer) |
|
|
|
|
@ -2469,7 +2470,7 @@ size_t OnSyncQuest(const TCmdQuest &message, Player &player)
|
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
} else { |
|
|
|
|
if (&player != MyPlayer && message.q < MAXQUESTS && message.qstate <= QUEST_HIVE_DONE) |
|
|
|
|
SetMultiQuest(message.q, message.qstate, message.qlog != 0, message.qvar1, message.qvar2, SDL_SwapLE16(message.qmsg)); |
|
|
|
|
SetMultiQuest(message.q, message.qstate, message.qlog != 0, message.qvar1, message.qvar2, Swap16LE(message.qmsg)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return sizeof(message); |
|
|
|
|
@ -2493,8 +2494,8 @@ size_t OnCheatExperience(const TCmd &cmd, Player &player) // NOLINT(misc-unused-
|
|
|
|
|
|
|
|
|
|
size_t OnChangeSpellLevel(const TCmdParam2 &message, Player &player) // NOLINT(misc-unused-parameters)
|
|
|
|
|
{ |
|
|
|
|
const auto spellID = static_cast<SpellID>(SDL_SwapLE16(message.wParam1)); |
|
|
|
|
const uint8_t spellLevel = std::min(static_cast<uint8_t>(SDL_SwapLE16(message.wParam2)), MaxSpellLevel); |
|
|
|
|
const auto spellID = static_cast<SpellID>(Swap16LE(message.wParam1)); |
|
|
|
|
const uint8_t spellLevel = std::min(static_cast<uint8_t>(Swap16LE(message.wParam2)), MaxSpellLevel); |
|
|
|
|
|
|
|
|
|
if (gbBufferMsgs == 1) { |
|
|
|
|
BufferMessage(player, &message, sizeof(message)); |
|
|
|
|
@ -2530,7 +2531,7 @@ size_t OnRemoveShield(const TCmd &cmd, Player &player)
|
|
|
|
|
size_t OnSetReflect(const TCmdParam1 &message, Player &player) |
|
|
|
|
{ |
|
|
|
|
if (gbBufferMsgs != 1) |
|
|
|
|
player.wReflections = SDL_SwapLE16(message.wParam1); |
|
|
|
|
player.wReflections = Swap16LE(message.wParam1); |
|
|
|
|
|
|
|
|
|
return sizeof(message); |
|
|
|
|
} |
|
|
|
|
@ -2580,8 +2581,8 @@ size_t OnSpawnMonster(const TCmdSpawnMonster &message, const Player &player)
|
|
|
|
|
|
|
|
|
|
const WorldTilePosition position { message.x, message.y }; |
|
|
|
|
|
|
|
|
|
auto typeIndex = static_cast<size_t>(SDL_SwapLE16(message.typeIndex)); |
|
|
|
|
auto monsterId = static_cast<size_t>(SDL_SwapLE16(message.monsterId)); |
|
|
|
|
auto typeIndex = static_cast<size_t>(Swap16LE(message.typeIndex)); |
|
|
|
|
auto monsterId = static_cast<size_t>(Swap16LE(message.monsterId)); |
|
|
|
|
const uint8_t golemOwnerPlayerId = message.golemOwnerPlayerId; |
|
|
|
|
if (golemOwnerPlayerId >= Players.size()) { |
|
|
|
|
return sizeof(message); |
|
|
|
|
@ -2652,10 +2653,10 @@ void PrepareItemForNetwork(const Item &item, TItem &messageItem)
|
|
|
|
|
messageItem.bMDur = item._iMaxDur; |
|
|
|
|
messageItem.bCh = item._iCharges; |
|
|
|
|
messageItem.bMCh = item._iMaxCharges; |
|
|
|
|
messageItem.wValue = SDL_SwapLE16(item._ivalue); |
|
|
|
|
messageItem.wToHit = SDL_SwapLE16(item._iPLToHit); |
|
|
|
|
messageItem.wMaxDam = SDL_SwapLE16(item._iMaxDam); |
|
|
|
|
messageItem.dwBuff = SDL_SwapLE32(item.dwBuff); |
|
|
|
|
messageItem.wValue = Swap16LE(item._ivalue); |
|
|
|
|
messageItem.wToHit = Swap16LE(item._iPLToHit); |
|
|
|
|
messageItem.wMaxDam = Swap16LE(item._iMaxDam); |
|
|
|
|
messageItem.dwBuff = Swap32LE(item.dwBuff); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrepareEarForNetwork(const Item &item, TEar &ear) |
|
|
|
|
@ -2666,10 +2667,10 @@ void PrepareEarForNetwork(const Item &item, TEar &ear)
|
|
|
|
|
|
|
|
|
|
void RecreateItem(const Player &player, const TItem &messageItem, Item &item) |
|
|
|
|
{ |
|
|
|
|
const uint32_t dwBuff = SDL_SwapLE32(messageItem.dwBuff); |
|
|
|
|
const uint32_t dwBuff = Swap32LE(messageItem.dwBuff); |
|
|
|
|
RecreateItem(player, item, |
|
|
|
|
static_cast<_item_indexes>(SDL_SwapLE16(messageItem.wIndx)), SDL_SwapLE16(messageItem.wCI), |
|
|
|
|
SDL_SwapLE32(messageItem.dwSeed), SDL_SwapLE16(messageItem.wValue), dwBuff); |
|
|
|
|
static_cast<_item_indexes>(Swap16LE(messageItem.wIndx)), Swap16LE(messageItem.wCI), |
|
|
|
|
Swap32LE(messageItem.dwSeed), Swap16LE(messageItem.wValue), dwBuff); |
|
|
|
|
if (messageItem.bId != 0) |
|
|
|
|
item._iIdentified = true; |
|
|
|
|
item._iMaxDur = messageItem.bMDur; |
|
|
|
|
@ -2677,8 +2678,8 @@ void RecreateItem(const Player &player, const TItem &messageItem, Item &item)
|
|
|
|
|
item._iMaxCharges = std::clamp<int>(messageItem.bMCh, 0, item._iMaxCharges); |
|
|
|
|
item._iCharges = std::clamp<int>(messageItem.bCh, 0, item._iMaxCharges); |
|
|
|
|
if (gbIsHellfire) { |
|
|
|
|
item._iPLToHit = ClampToHit(item, static_cast<uint8_t>(SDL_SwapLE16(messageItem.wToHit))); |
|
|
|
|
item._iMaxDam = ClampMaxDam(item, static_cast<uint8_t>(SDL_SwapLE16(messageItem.wMaxDam))); |
|
|
|
|
item._iPLToHit = ClampToHit(item, static_cast<uint8_t>(Swap16LE(messageItem.wToHit))); |
|
|
|
|
item._iMaxDam = ClampMaxDam(item, static_cast<uint8_t>(Swap16LE(messageItem.wMaxDam))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -2691,7 +2692,7 @@ void msg_send_drop_pkt(uint8_t pnum, int reason)
|
|
|
|
|
{ |
|
|
|
|
TFakeDropPlr cmd; |
|
|
|
|
|
|
|
|
|
cmd.dwReason = SDL_SwapLE32(reason); |
|
|
|
|
cmd.dwReason = Swap32LE(reason); |
|
|
|
|
cmd.bCmd = FAKE_CMD_DROPID; |
|
|
|
|
cmd.bPlr = pnum; |
|
|
|
|
BufferMessage(pnum, &cmd, sizeof(cmd)); |
|
|
|
|
@ -2803,8 +2804,8 @@ void delta_monster_hp(const Monster &monster, const Player &player)
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
DMonsterStr *pD = &GetDeltaLevel(player).monster[monster.getId()]; |
|
|
|
|
if (SDL_SwapLE32(pD->hitPoints) > monster.hitPoints) |
|
|
|
|
pD->hitPoints = SDL_SwapLE32(monster.hitPoints); |
|
|
|
|
if (Swap32LE(pD->hitPoints) > monster.hitPoints) |
|
|
|
|
pD->hitPoints = Swap32LE(monster.hitPoints); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void delta_sync_monster(const TSyncMonster &monsterSync, uint8_t level) |
|
|
|
|
@ -2852,7 +2853,7 @@ void DeltaSyncJunk()
|
|
|
|
|
quest._qactive = sgJunk.quests[q].qstate; |
|
|
|
|
quest._qvar1 = sgJunk.quests[q].qvar1; |
|
|
|
|
quest._qvar2 = sgJunk.quests[q].qvar2; |
|
|
|
|
quest._qmsg = static_cast<_speech_id>(SDL_SwapLE16(sgJunk.quests[q].qmsg)); |
|
|
|
|
quest._qmsg = static_cast<_speech_id>(Swap16LE(sgJunk.quests[q].qmsg)); |
|
|
|
|
} |
|
|
|
|
q++; |
|
|
|
|
} |
|
|
|
|
@ -2868,9 +2869,9 @@ void DeltaAddItem(int ii)
|
|
|
|
|
|
|
|
|
|
for (const TCmdPItem &item : deltaLevel.item) { |
|
|
|
|
if (item.bCmd != CMD_INVALID |
|
|
|
|
&& static_cast<_item_indexes>(SDL_SwapLE16(item.def.wIndx)) == Items[ii].IDidx |
|
|
|
|
&& SDL_SwapLE16(item.def.wCI) == Items[ii]._iCreateInfo |
|
|
|
|
&& static_cast<uint32_t>(SDL_SwapLE32(item.def.dwSeed)) == Items[ii]._iSeed |
|
|
|
|
&& static_cast<_item_indexes>(Swap16LE(item.def.wIndx)) == Items[ii].IDidx |
|
|
|
|
&& Swap16LE(item.def.wCI) == Items[ii]._iCreateInfo |
|
|
|
|
&& static_cast<uint32_t>(Swap32LE(item.def.dwSeed)) == Items[ii]._iSeed |
|
|
|
|
&& IsAnyOf(item.bCmd, TCmdPItem::PickedUpItem, TCmdPItem::FloorItem)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
@ -2967,9 +2968,9 @@ void NetSendCmdSpawnMonster(Point position, Direction dir, uint16_t typeIndex, u
|
|
|
|
|
cmd.x = position.x; |
|
|
|
|
cmd.y = position.y; |
|
|
|
|
cmd.dir = dir; |
|
|
|
|
cmd.typeIndex = SDL_SwapLE16(typeIndex); |
|
|
|
|
cmd.monsterId = SDL_SwapLE16(monsterId); |
|
|
|
|
cmd.seed = SDL_SwapLE32(seed); |
|
|
|
|
cmd.typeIndex = Swap16LE(typeIndex); |
|
|
|
|
cmd.monsterId = Swap16LE(monsterId); |
|
|
|
|
cmd.seed = Swap32LE(seed); |
|
|
|
|
cmd.golemOwnerPlayerId = golemOwnerPlayerId; |
|
|
|
|
cmd.golemSpellLevel = golemSpellLevel; |
|
|
|
|
NetSendHiPri(MyPlayerId, reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
@ -3003,7 +3004,7 @@ void NetSendCmdLocParam1(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
|
|
|
|
|
cmd.bCmd = bCmd; |
|
|
|
|
cmd.x = position.x; |
|
|
|
|
cmd.y = position.y; |
|
|
|
|
cmd.wParam1 = SDL_SwapLE16(wParam1); |
|
|
|
|
cmd.wParam1 = Swap16LE(wParam1); |
|
|
|
|
if (bHiPri) |
|
|
|
|
NetSendHiPri(MyPlayerId, reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
else |
|
|
|
|
@ -3022,8 +3023,8 @@ void NetSendCmdLocParam2(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
|
|
|
|
|
cmd.bCmd = bCmd; |
|
|
|
|
cmd.x = position.x; |
|
|
|
|
cmd.y = position.y; |
|
|
|
|
cmd.wParam1 = SDL_SwapLE16(wParam1); |
|
|
|
|
cmd.wParam2 = SDL_SwapLE16(wParam2); |
|
|
|
|
cmd.wParam1 = Swap16LE(wParam1); |
|
|
|
|
cmd.wParam2 = Swap16LE(wParam2); |
|
|
|
|
if (bHiPri) |
|
|
|
|
NetSendHiPri(MyPlayerId, reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
else |
|
|
|
|
@ -3042,9 +3043,9 @@ void NetSendCmdLocParam3(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
|
|
|
|
|
cmd.bCmd = bCmd; |
|
|
|
|
cmd.x = position.x; |
|
|
|
|
cmd.y = position.y; |
|
|
|
|
cmd.wParam1 = SDL_SwapLE16(wParam1); |
|
|
|
|
cmd.wParam2 = SDL_SwapLE16(wParam2); |
|
|
|
|
cmd.wParam3 = SDL_SwapLE16(wParam3); |
|
|
|
|
cmd.wParam1 = Swap16LE(wParam1); |
|
|
|
|
cmd.wParam2 = Swap16LE(wParam2); |
|
|
|
|
cmd.wParam3 = Swap16LE(wParam3); |
|
|
|
|
if (bHiPri) |
|
|
|
|
NetSendHiPri(MyPlayerId, reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
else |
|
|
|
|
@ -3063,10 +3064,10 @@ void NetSendCmdLocParam4(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
|
|
|
|
|
cmd.bCmd = bCmd; |
|
|
|
|
cmd.x = position.x; |
|
|
|
|
cmd.y = position.y; |
|
|
|
|
cmd.wParam1 = SDL_SwapLE16(wParam1); |
|
|
|
|
cmd.wParam2 = SDL_SwapLE16(wParam2); |
|
|
|
|
cmd.wParam3 = SDL_SwapLE16(wParam3); |
|
|
|
|
cmd.wParam4 = SDL_SwapLE16(wParam4); |
|
|
|
|
cmd.wParam1 = Swap16LE(wParam1); |
|
|
|
|
cmd.wParam2 = Swap16LE(wParam2); |
|
|
|
|
cmd.wParam3 = Swap16LE(wParam3); |
|
|
|
|
cmd.wParam4 = Swap16LE(wParam4); |
|
|
|
|
if (bHiPri) |
|
|
|
|
NetSendHiPri(MyPlayerId, reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
else |
|
|
|
|
@ -3083,7 +3084,7 @@ void NetSendCmdParam1(bool bHiPri, _cmd_id bCmd, uint16_t wParam1)
|
|
|
|
|
TCmdParam1 cmd; |
|
|
|
|
|
|
|
|
|
cmd.bCmd = bCmd; |
|
|
|
|
cmd.wParam1 = SDL_SwapLE16(wParam1); |
|
|
|
|
cmd.wParam1 = Swap16LE(wParam1); |
|
|
|
|
if (bHiPri) |
|
|
|
|
NetSendHiPri(MyPlayerId, reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
else |
|
|
|
|
@ -3097,8 +3098,8 @@ void NetSendCmdParam2(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar
|
|
|
|
|
TCmdParam2 cmd; |
|
|
|
|
|
|
|
|
|
cmd.bCmd = bCmd; |
|
|
|
|
cmd.wParam1 = SDL_SwapLE16(wParam1); |
|
|
|
|
cmd.wParam2 = SDL_SwapLE16(wParam2); |
|
|
|
|
cmd.wParam1 = Swap16LE(wParam1); |
|
|
|
|
cmd.wParam2 = Swap16LE(wParam2); |
|
|
|
|
if (bHiPri) |
|
|
|
|
NetSendHiPri(MyPlayerId, reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
else |
|
|
|
|
@ -3113,10 +3114,10 @@ void NetSendCmdParam4(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar
|
|
|
|
|
TCmdParam4 cmd; |
|
|
|
|
|
|
|
|
|
cmd.bCmd = bCmd; |
|
|
|
|
cmd.wParam1 = SDL_SwapLE16(wParam1); |
|
|
|
|
cmd.wParam2 = SDL_SwapLE16(wParam2); |
|
|
|
|
cmd.wParam3 = SDL_SwapLE16(wParam3); |
|
|
|
|
cmd.wParam4 = SDL_SwapLE16(wParam4); |
|
|
|
|
cmd.wParam1 = Swap16LE(wParam1); |
|
|
|
|
cmd.wParam2 = Swap16LE(wParam2); |
|
|
|
|
cmd.wParam3 = Swap16LE(wParam3); |
|
|
|
|
cmd.wParam4 = Swap16LE(wParam4); |
|
|
|
|
if (bHiPri) |
|
|
|
|
NetSendHiPri(MyPlayerId, reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
else |
|
|
|
|
@ -3134,7 +3135,7 @@ void NetSendCmdQuest(bool bHiPri, const Quest &quest)
|
|
|
|
|
cmd.qlog = quest._qlog ? 1 : 0; |
|
|
|
|
cmd.qvar1 = quest._qvar1; |
|
|
|
|
cmd.qvar2 = quest._qvar2; |
|
|
|
|
cmd.qmsg = SDL_SwapLE16(quest._qmsg); |
|
|
|
|
cmd.qmsg = Swap16LE(quest._qmsg); |
|
|
|
|
|
|
|
|
|
if (bHiPri) |
|
|
|
|
NetSendHiPri(MyPlayerId, reinterpret_cast<std::byte *>(&cmd), sizeof(cmd)); |
|
|
|
|
|