[Bots] IsValidTarget Crash Fix (#4187)

* [Bots] IsValidTarget crash fix

This addresses crashes related to IsValidTarget on multiple servers.

Unsure of the exact reason if anyone can explain why changing from const bool to bool in this situation fixes the problem.

Is it because the const is somehow crashing on a bad pointer or is it attempting to be force changed?

* Update bot.cpp

---------

Co-authored-by: Alex King <89047260+Kinglykrab@users.noreply.github.com>
This commit is contained in:
nytmyr 2024-03-12 11:34:27 -05:00 committed by GitHub
parent d94493468c
commit 6ca11256c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2684,16 +2684,19 @@ bool Bot::IsValidTarget(
return false; return false;
} }
const bool valid_target_state = ( bool invalid_target_state = false;
HOLDING || if (HOLDING ||
!tar->IsNPC() || !tar->IsNPC() ||
tar->IsMezzed() || tar->IsMezzed() ||
lo_distance > leash_distance || lo_distance > leash_distance ||
tar_distance > leash_distance tar_distance > leash_distance ||
); (!GetAttackingFlag() && !CheckLosFN(tar) && !leash_owner->CheckLosFN(tar)) ||
const bool valid_target = !GetAttackingFlag() && !CheckLosFN(tar) && !leash_owner->CheckLosFN(tar); !IsAttackAllowed(tar)
) {
invalid_target_state = true;
}
if (valid_target_state || valid_target || !IsAttackAllowed(tar)) { if (invalid_target_state) {
// Normally, we wouldn't want to do this without class checks..but, too many issues can arise if we let enchanter animation pets run rampant // Normally, we wouldn't want to do this without class checks..but, too many issues can arise if we let enchanter animation pets run rampant
if (HasPet()) { if (HasPet()) {
GetPet()->RemoveFromHateList(tar); GetPet()->RemoveFromHateList(tar);