Skip to content

Commit

Permalink
Don't send spell level in spell casting network message
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenCWills committed Nov 16, 2024
1 parent 1b522fe commit 6eae331
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 57 deletions.
9 changes: 4 additions & 5 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2679,17 +2679,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<int8_t>(spellID), static_cast<uint8_t>(spellType), static_cast<uint16_t>(sd), spellLevel, spellFrom);
NetSendCmdLocParam4(true, CMD_SPELLXYD, cursPosition, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), static_cast<uint16_t>(sd), spellFrom);
} else if (pcursmonst != -1) {
NetSendCmdParam5(true, CMD_SPELLID, pcursmonst, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdParam4(true, CMD_SPELLID, pcursmonst, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellFrom);
} else if (PlayerUnderCursor != nullptr && !myPlayer.friendlyMode) {
NetSendCmdParam5(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdParam4(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellFrom);
} else {
NetSendCmdLocParam4(true, CMD_SPELLXY, cursPosition, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdLocParam3(true, CMD_SPELLXY, cursPosition, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellFrom);
}
NewCursor(CURSOR_HAND);
return true;
Expand Down
2 changes: 1 addition & 1 deletion Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4265,7 +4265,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<int8_t>(spellID), static_cast<uint8_t>(SpellType::Scroll), spellLevel, static_cast<uint16_t>(spellFrom));
NetSendCmdLocParam3(true, CMD_SPELLXY, target, static_cast<int8_t>(spellID), static_cast<uint8_t>(SpellType::Scroll), static_cast<uint16_t>(spellFrom));
}
break;
case IMISC_BOOK: {
Expand Down
52 changes: 14 additions & 38 deletions Source/msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const TCmdLocParam5 *>(pCmd);
const auto &message = *reinterpret_cast<const TCmdLocParam4 *>(pCmd);
const Point position { message.x, message.y };

if (gbBufferMsgs == 1)
Expand All @@ -1494,22 +1494,22 @@ size_t OnSpellWall(const TCmd *pCmd, Player &player)
if (wParamDirection > static_cast<uint16_t>(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);
player.destAction = ACTION_SPELLWALL;
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<const TCmdLocParam4 *>(pCmd);
const auto &message = *reinterpret_cast<const TCmdLocParam3 *>(pCmd);
const Point position { message.x, message.y };

if (gbBufferMsgs == 1)
Expand All @@ -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);
}
Expand Down Expand Up @@ -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<const TCmdParam5 *>(pCmd);
const auto &message = *reinterpret_cast<const TCmdParam4 *>(pCmd);

if (gbBufferMsgs == 1)
return sizeof(message);
Expand All @@ -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<const TCmdParam5 *>(pCmd);
const auto &message = *reinterpret_cast<const TCmdParam4 *>(pCmd);

if (gbBufferMsgs == 1)
return sizeof(message);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions Source/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Direction>(player.destParam3), player.destParam1, player.destParam2);
player.tempDirection = static_cast<Direction>(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)) {
Expand Down Expand Up @@ -3151,18 +3147,17 @@ 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<int8_t>(spellID), static_cast<uint8_t>(spellType), static_cast<uint16_t>(sd), spellLevel, spellFrom);
NetSendCmdLocParam4(true, CMD_SPELLXYD, cursPosition, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), static_cast<uint16_t>(sd), spellFrom);
} else if (pcursmonst != -1 && !isShiftHeld) {
LastMouseButtonAction = MouseActionType::SpellMonsterTarget;
NetSendCmdParam5(true, CMD_SPELLID, pcursmonst, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdParam4(true, CMD_SPELLID, pcursmonst, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellFrom);
} else if (PlayerUnderCursor != nullptr && !isShiftHeld && !myPlayer.friendlyMode) {
LastMouseButtonAction = MouseActionType::SpellPlayerTarget;
NetSendCmdParam5(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdParam4(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellFrom);
} else {
Point targetedTile = cursPosition;
if (spellID == SpellID::Teleport && myPlayer.executedSpell.spellId == SpellID::Teleport) {
Expand All @@ -3175,7 +3170,7 @@ void CheckPlrSpell(bool isShiftHeld, SpellID spellID, SpellType spellType)
}
}
LastMouseButtonAction = MouseActionType::Spell;
NetSendCmdLocParam4(true, CMD_SPELLXY, targetedTile, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdLocParam3(true, CMD_SPELLXY, targetedTile, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellFrom);
}
}

Expand Down

0 comments on commit 6eae331

Please sign in to comment.