Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.5] Don't send spell level in spell casting network message #7490

Open
wants to merge 1 commit into
base: 1.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2516,17 +2516,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 (pcursplr != -1 && !myPlayer.friendlyMode) {
NetSendCmdParam5(true, CMD_SPELLPID, pcursplr, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdParam4(true, CMD_SPELLPID, pcursplr, 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 @@ -4100,7 +4100,7 @@ void UseItem(size_t pnum, 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 @@ -1454,7 +1454,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 @@ -1467,22 +1467,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 @@ -1492,14 +1492,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 @@ -1581,7 +1581,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 @@ -1591,20 +1591,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 @@ -1614,13 +1614,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 @@ -2908,29 +2908,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, (byte *)&cmd, sizeof(cmd));
else
NetSendLoPri(MyPlayerId, (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 @@ -2961,19 +2938,18 @@ void NetSendCmdParam2(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar
NetSendLoPri(MyPlayerId, (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, (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 @@ -495,13 +495,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 @@ -748,10 +747,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, uint8_t pnum, 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 @@ -1308,22 +1308,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 @@ -3225,21 +3221,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<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 (pcursplr != -1 && !isShiftHeld && !myPlayer.friendlyMode) {
LastMouseButtonAction = MouseActionType::SpellPlayerTarget;
NetSendCmdParam5(true, CMD_SPELLPID, pcursplr, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdParam4(true, CMD_SPELLPID, pcursplr, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellFrom);
} else {
LastMouseButtonAction = MouseActionType::Spell;
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);
}
}

Expand Down
Loading