Skip to content

Commit

Permalink
NPCBots: Fix a crash in .npcbot order cast when using group target …
Browse files Browse the repository at this point in the history
…icon token while not in group
  • Loading branch information
trickerer committed Jul 11, 2024
1 parent 9b92804 commit 50bbce3
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions src/server/game/AI/NpcBots/botcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,8 @@ class script_bot_commands : public CommandScript
}
}

ObjectGuid target_guid;
ObjectGuid target_guid = ObjectGuid::Empty;
bool token_valid = true;
if (!target_token || target_token == "bot" || target_token == "self")
target_guid = bot->GetGUID();
else if (target_token == "me" || target_token == "master")
Expand All @@ -1835,40 +1836,49 @@ class script_bot_commands : public CommandScript
target_guid = bot->GetTarget();
else if (target_token == "mytarget")
target_guid = owner->GetTarget();
else if (target_token == "star")
target_guid = owner->GetGroup()->GetTargetIcons()[0];
else if (target_token == "circle")
target_guid = owner->GetGroup()->GetTargetIcons()[1];
else if (target_token == "diamond")
target_guid = owner->GetGroup()->GetTargetIcons()[2];
else if (target_token == "triangle")
target_guid = owner->GetGroup()->GetTargetIcons()[3];
else if (target_token == "moon")
target_guid = owner->GetGroup()->GetTargetIcons()[4];
else if (target_token == "square")
target_guid = owner->GetGroup()->GetTargetIcons()[5];
else if (target_token == "cross")
target_guid = owner->GetGroup()->GetTargetIcons()[6];
else if (target_token == "skull")
target_guid = owner->GetGroup()->GetTargetIcons()[7];
else if (target_token->size() == 1u && owner->GetGroup() && std::isdigit(target_token->front()))
{
uint8 digit = static_cast<uint8>(std::stoi(std::string(*target_token)));
switch (digit)
else if (Group const* group = owner->GetGroup())
{
if (target_token == "star")
target_guid = group->GetTargetIcons()[0];
else if (target_token == "circle")
target_guid = group->GetTargetIcons()[1];
else if (target_token == "diamond")
target_guid = group->GetTargetIcons()[2];
else if (target_token == "triangle")
target_guid = group->GetTargetIcons()[3];
else if (target_token == "moon")
target_guid = group->GetTargetIcons()[4];
else if (target_token == "square")
target_guid = group->GetTargetIcons()[5];
else if (target_token == "cross")
target_guid = group->GetTargetIcons()[6];
else if (target_token == "skull")
target_guid = group->GetTargetIcons()[7];
else if (target_token->size() == 1u && std::isdigit(target_token->front()))
{
case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
target_guid = owner->GetGroup()->GetTargetIcons()[digit - 1];
break;
default:
target_guid = ObjectGuid::Empty;
break;
uint8 digit = static_cast<uint8>(std::stoi(std::string(*target_token)));
switch (digit)
{
case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
target_guid = group->GetTargetIcons()[digit - 1];
break;
default:
token_valid = false;
break;
}
}
else
token_valid = false;
}
else
token_valid = false;

if (!token_valid)
{
handler->PSendSysMessage("Invalid target token '%s'!", *target_token);
handler->SendSysMessage("Valid target tokens:\n '','bot','self', 'me','master', 'mypet', 'myvehicle', 'target', 'mytarget', "
"'star','1', 'circle','2', 'diamond','3', 'triangle','4', 'moon','5', 'square','6', 'cross','7', 'skull','8'");
"'star','1', 'circle','2', 'diamond','3', 'triangle','4', 'moon','5', 'square','6', 'cross','7', 'skull','8'"
"\nNote that target icons tokens are only available while in group");
return true;
}

Expand Down

0 comments on commit 50bbce3

Please sign in to comment.