From 5b3960b2770f8828008970724cfa9c6db50132cd Mon Sep 17 00:00:00 2001 From: staphen Date: Sat, 19 Oct 2024 10:14:25 -0400 Subject: [PATCH] Don't send spell level in spell casting network message --- Source/diablo.cpp | 9 ++++---- Source/items.cpp | 2 +- Source/msg.cpp | 52 +++++++++++++---------------------------------- Source/msg.h | 6 ++---- Source/player.cpp | 13 ++++-------- 5 files changed, 25 insertions(+), 57 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index d8974ce86fc..782daeda641 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -2668,17 +2668,16 @@ bool TryIconCurs() if (pcurs == CURSOR_TELEPORT) { const SpellID spellID = myPlayer.inventorySpell; const SpellType spellType = SpellType::Scroll; - const int spellLevel = myPlayer.GetSpellLevel(spellID); const int spellFrom = myPlayer.spellFrom; if (IsWallSpell(spellID)) { Direction sd = GetDirection(myPlayer.position.tile, cursPosition); - NetSendCmdLocParam5(true, CMD_SPELLXYD, cursPosition, static_cast(spellID), static_cast(spellType), static_cast(sd), spellLevel, spellFrom); + NetSendCmdLocParam4(true, CMD_SPELLXYD, cursPosition, static_cast(spellID), static_cast(spellType), static_cast(sd), spellFrom); } else if (pcursmonst != -1) { - NetSendCmdParam5(true, CMD_SPELLID, pcursmonst, static_cast(spellID), static_cast(spellType), spellLevel, spellFrom); + NetSendCmdParam4(true, CMD_SPELLID, pcursmonst, static_cast(spellID), static_cast(spellType), spellFrom); } else if (PlayerUnderCursor != nullptr && !myPlayer.friendlyMode) { - NetSendCmdParam5(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast(spellID), static_cast(spellType), spellLevel, spellFrom); + NetSendCmdParam4(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast(spellID), static_cast(spellType), spellFrom); } else { - NetSendCmdLocParam4(true, CMD_SPELLXY, cursPosition, static_cast(spellID), static_cast(spellType), spellLevel, spellFrom); + NetSendCmdLocParam3(true, CMD_SPELLXY, cursPosition, static_cast(spellID), static_cast(spellType), spellFrom); } NewCursor(CURSOR_HAND); return true; diff --git a/Source/items.cpp b/Source/items.cpp index 88f83cd54f9..ca294def2b8 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4253,7 +4253,7 @@ void UseItem(Player &player, item_misc_id mid, SpellID spellID, int spellFrom) target = player.position.future + Displacement(player._pdir); // Use CMD_SPELLXY because it's the same behavior as normal casting assert(IsValidSpellFrom(spellFrom)); - NetSendCmdLocParam4(true, CMD_SPELLXY, target, static_cast(spellID), static_cast(SpellType::Scroll), spellLevel, static_cast(spellFrom)); + NetSendCmdLocParam3(true, CMD_SPELLXY, target, static_cast(spellID), static_cast(SpellType::Scroll), static_cast(spellFrom)); } break; case IMISC_BOOK: { diff --git a/Source/msg.cpp b/Source/msg.cpp index cbcfd6bcb31..453ff2b87fd 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1481,7 +1481,7 @@ bool InitNewSpell(Player &player, uint16_t wParamSpellID, uint16_t wParamSpellTy size_t OnSpellWall(const TCmd *pCmd, Player &player) { - const auto &message = *reinterpret_cast(pCmd); + const auto &message = *reinterpret_cast(pCmd); const Point position { message.x, message.y }; if (gbBufferMsgs == 1) @@ -1494,7 +1494,7 @@ size_t OnSpellWall(const TCmd *pCmd, Player &player) if (wParamDirection > static_cast(Direction::SouthEast)) return sizeof(message); - if (!InitNewSpell(player, message.wParam1, message.wParam2, message.wParam5)) + if (!InitNewSpell(player, message.wParam1, message.wParam2, message.wParam4)) return sizeof(message); ClrPlrPath(player); @@ -1502,14 +1502,14 @@ size_t OnSpellWall(const TCmd *pCmd, Player &player) player.destParam1 = position.x; player.destParam2 = position.y; player.destParam3 = wParamDirection; - player.destParam4 = SDL_SwapLE16(message.wParam4); // Spell Level + player.destParam4 = player.GetSpellLevel(player.queuedSpell.spellId); return sizeof(message); } size_t OnSpellTile(const TCmd *pCmd, Player &player) { - const auto &message = *reinterpret_cast(pCmd); + const auto &message = *reinterpret_cast(pCmd); const Point position { message.x, message.y }; if (gbBufferMsgs == 1) @@ -1519,14 +1519,14 @@ size_t OnSpellTile(const TCmd *pCmd, Player &player) if (!InDungeonBounds(position)) return sizeof(message); - if (!InitNewSpell(player, message.wParam1, message.wParam2, message.wParam4)) + if (!InitNewSpell(player, message.wParam1, message.wParam2, message.wParam3)) return sizeof(message); ClrPlrPath(player); player.destAction = ACTION_SPELL; player.destParam1 = position.x; player.destParam2 = position.y; - player.destParam3 = SDL_SwapLE16(message.wParam3); // Spell Level + player.destParam3 = player.GetSpellLevel(player.queuedSpell.spellId); return sizeof(message); } @@ -1608,7 +1608,7 @@ size_t OnRangedAttackPlayer(const TCmd *pCmd, Player &player) size_t OnSpellMonster(const TCmd *pCmd, Player &player) { - const auto &message = *reinterpret_cast(pCmd); + const auto &message = *reinterpret_cast(pCmd); if (gbBufferMsgs == 1) return sizeof(message); @@ -1618,20 +1618,20 @@ size_t OnSpellMonster(const TCmd *pCmd, Player &player) if (monsterIdx >= MaxMonsters) return sizeof(message); - if (!InitNewSpell(player, message.wParam2, message.wParam3, message.wParam5)) + if (!InitNewSpell(player, message.wParam2, message.wParam3, message.wParam4)) return sizeof(message); ClrPlrPath(player); player.destAction = ACTION_SPELLMON; player.destParam1 = monsterIdx; - player.destParam2 = SDL_SwapLE16(message.wParam4); // Spell Level + player.destParam2 = player.GetSpellLevel(player.queuedSpell.spellId); return sizeof(message); } size_t OnSpellPlayer(const TCmd *pCmd, Player &player) { - const auto &message = *reinterpret_cast(pCmd); + const auto &message = *reinterpret_cast(pCmd); if (gbBufferMsgs == 1) return sizeof(message); @@ -1641,13 +1641,13 @@ size_t OnSpellPlayer(const TCmd *pCmd, Player &player) if (playerIdx >= Players.size()) return sizeof(message); - if (!InitNewSpell(player, message.wParam2, message.wParam3, message.wParam5)) + if (!InitNewSpell(player, message.wParam2, message.wParam3, message.wParam4)) return sizeof(message); ClrPlrPath(player); player.destAction = ACTION_SPELLPLR; player.destParam1 = playerIdx; - player.destParam2 = SDL_SwapLE16(message.wParam4); // Spell Level + player.destParam2 = player.GetSpellLevel(player.queuedSpell.spellId); return sizeof(message); } @@ -2953,29 +2953,6 @@ void NetSendCmdLocParam4(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3); } -void NetSendCmdLocParam5(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4, uint16_t wParam5) -{ - if (WasPlayerCmdAlreadyRequested(bCmd, position, wParam1, wParam2, wParam3, wParam4, wParam5)) - return; - - TCmdLocParam5 cmd; - - 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.wParam5 = SDL_SwapLE16(wParam5); - if (bHiPri) - NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); - else - NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); - - MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3); -} - void NetSendCmdParam1(bool bHiPri, _cmd_id bCmd, uint16_t wParam1) { if (WasPlayerCmdAlreadyRequested(bCmd, {}, wParam1)) @@ -3006,19 +2983,18 @@ void NetSendCmdParam2(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } -void NetSendCmdParam5(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4, uint16_t wParam5) +void NetSendCmdParam4(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4) { if (WasPlayerCmdAlreadyRequested(bCmd, {}, wParam1, wParam2, wParam3, wParam4)) return; - TCmdParam5 cmd; + 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.wParam5 = SDL_SwapLE16(wParam5); if (bHiPri) NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else diff --git a/Source/msg.h b/Source/msg.h index c6229ad7cac..2287824c4fb 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -499,13 +499,12 @@ struct TCmdParam2 { uint16_t wParam2; }; -struct TCmdParam5 { +struct TCmdParam4 { _cmd_id bCmd; uint16_t wParam1; uint16_t wParam2; uint16_t wParam3; uint16_t wParam4; - uint16_t wParam5; }; struct TCmdGolem { @@ -758,10 +757,9 @@ void NetSendCmdLocParam1(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa void NetSendCmdLocParam2(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1, uint16_t wParam2); void NetSendCmdLocParam3(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3); void NetSendCmdLocParam4(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4); -void NetSendCmdLocParam5(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4, uint16_t wParam5); void NetSendCmdParam1(bool bHiPri, _cmd_id bCmd, uint16_t wParam1); void NetSendCmdParam2(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2); -void NetSendCmdParam5(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4, uint16_t wParam5); +void NetSendCmdParam4(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4); void NetSendCmdQuest(bool bHiPri, const Quest &quest); void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, const Player &player, uint8_t ii); void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item); diff --git a/Source/player.cpp b/Source/player.cpp index 2e16cfb8907..564f5b2d8c9 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -1241,22 +1241,18 @@ void CheckNewPath(Player &player, bool pmWillBeCalled) case ACTION_SPELL: d = GetDirection(player.position.tile, { player.destParam1, player.destParam2 }); StartSpell(player, d, player.destParam1, player.destParam2); - player.executedSpell.spellLevel = player.destParam3; break; case ACTION_SPELLWALL: StartSpell(player, static_cast(player.destParam3), player.destParam1, player.destParam2); player.tempDirection = static_cast(player.destParam3); - player.executedSpell.spellLevel = player.destParam4; break; case ACTION_SPELLMON: d = GetDirection(player.position.tile, monster->position.future); StartSpell(player, d, monster->position.future.x, monster->position.future.y); - player.executedSpell.spellLevel = player.destParam2; break; case ACTION_SPELLPLR: d = GetDirection(player.position.tile, target->position.future); StartSpell(player, d, target->position.future.x, target->position.future.y); - player.executedSpell.spellLevel = player.destParam2; break; case ACTION_OPERATE: if (IsPlayerAdjacentToObject(player, *object)) { @@ -3141,21 +3137,20 @@ void CheckPlrSpell(bool isShiftHeld, SpellID spellID, SpellType spellType) return; } - const int spellLevel = myPlayer.GetSpellLevel(spellID); const int spellFrom = 0; if (IsWallSpell(spellID)) { LastMouseButtonAction = MouseActionType::Spell; Direction sd = GetDirection(myPlayer.position.tile, cursPosition); - NetSendCmdLocParam5(true, CMD_SPELLXYD, cursPosition, static_cast(spellID), static_cast(spellType), static_cast(sd), spellLevel, spellFrom); + NetSendCmdLocParam4(true, CMD_SPELLXYD, cursPosition, static_cast(spellID), static_cast(spellType), static_cast(sd), spellFrom); } else if (pcursmonst != -1 && !isShiftHeld) { LastMouseButtonAction = MouseActionType::SpellMonsterTarget; - NetSendCmdParam5(true, CMD_SPELLID, pcursmonst, static_cast(spellID), static_cast(spellType), spellLevel, spellFrom); + NetSendCmdParam4(true, CMD_SPELLID, pcursmonst, static_cast(spellID), static_cast(spellType), spellFrom); } else if (PlayerUnderCursor != nullptr && !isShiftHeld && !myPlayer.friendlyMode) { LastMouseButtonAction = MouseActionType::SpellPlayerTarget; - NetSendCmdParam5(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast(spellID), static_cast(spellType), spellLevel, spellFrom); + NetSendCmdParam4(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast(spellID), static_cast(spellType), spellFrom); } else { LastMouseButtonAction = MouseActionType::Spell; - NetSendCmdLocParam4(true, CMD_SPELLXY, cursPosition, static_cast(spellID), static_cast(spellType), spellLevel, spellFrom); + NetSendCmdLocParam3(true, CMD_SPELLXY, cursPosition, static_cast(spellID), static_cast(spellType), spellFrom); } }