mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
This update adds null pointer checks and extra validations to the AttackAnythingAction::isUseful() method, preventing invalid accesses that could cause crashes. (#1135)
Checking bots and botAI before method calls. Validating targets and confirming if they are still in the world (IsInWorld()). Adding debug logs (LOG_DEBUG) to make it easier to identify issues.
This commit is contained in:
@@ -31,7 +31,10 @@ bool AttackEnemyFlagCarrierAction::isUseful()
|
|||||||
|
|
||||||
bool AttackAnythingAction::isUseful()
|
bool AttackAnythingAction::isUseful()
|
||||||
{
|
{
|
||||||
if (!botAI->AllowActivity(GRIND_ACTIVITY)) // Bot not allowed to be active
|
if (!bot || !botAI) // Prevents invalid accesses
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!botAI->AllowActivity(GRIND_ACTIVITY)) // Bot cannot be active
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (botAI->HasStrategy("stay", BOT_STATE_NON_COMBAT))
|
if (botAI->HasStrategy("stay", BOT_STATE_NON_COMBAT))
|
||||||
@@ -41,19 +44,17 @@ bool AttackAnythingAction::isUseful()
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
Unit* target = GetTarget();
|
Unit* target = GetTarget();
|
||||||
|
if (!target || !target->IsInWorld()) // Checks if the target is valid and in the world
|
||||||
if (!target)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string const name = std::string(target->GetName());
|
std::string const name = std::string(target->GetName());
|
||||||
// Check for invalid targets: Dummy, Charge Target, Melee Target, Ranged Target
|
|
||||||
if (!name.empty() &&
|
if (!name.empty() &&
|
||||||
(name.find("Dummy") != std::string::npos ||
|
(name.find("Dummy") != std::string::npos ||
|
||||||
name.find("Charge Target") != std::string::npos ||
|
name.find("Charge Target") != std::string::npos ||
|
||||||
name.find("Melee Target") != std::string::npos ||
|
name.find("Melee Target") != std::string::npos ||
|
||||||
name.find("Ranged Target") != std::string::npos))
|
name.find("Ranged Target") != std::string::npos))
|
||||||
{
|
{
|
||||||
return false; // Target is one of the disallowed types
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user