From 6ca11256c64c4c33f0090c42ab7e6640ec302a4b Mon Sep 17 00:00:00 2001 From: nytmyr <53322305+nytmyr@users.noreply.github.com> Date: Tue, 12 Mar 2024 11:34:27 -0500 Subject: [PATCH] [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> --- zone/bot.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index 16338d0d8..6f0a6032c 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -2684,16 +2684,19 @@ bool Bot::IsValidTarget( return false; } - const bool valid_target_state = ( - HOLDING || + bool invalid_target_state = false; + if (HOLDING || !tar->IsNPC() || tar->IsMezzed() || lo_distance > leash_distance || - tar_distance > leash_distance - ); - const bool valid_target = !GetAttackingFlag() && !CheckLosFN(tar) && !leash_owner->CheckLosFN(tar); + tar_distance > leash_distance || + (!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 if (HasPet()) { GetPet()->RemoveFromHateList(tar);