From 57a00242acca2a64d00da5f96d07a75d35215577 Mon Sep 17 00:00:00 2001 From: caxanga334 <10157643+caxanga334@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:30:21 -0300 Subject: [PATCH] Crash Fix --- extension/bot/interfaces/inventory.cpp | 8 ++++---- extension/util/helpers.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/extension/bot/interfaces/inventory.cpp b/extension/bot/interfaces/inventory.cpp index f5410d0..0d32c30 100644 --- a/extension/bot/interfaces/inventory.cpp +++ b/extension/bot/interfaces/inventory.cpp @@ -32,7 +32,7 @@ void IInventory::Reset() edict_t* weapon = GetBot()->GetActiveWeapon(); - if (weapon != nullptr) + if (UtilHelpers::IsValidEdict(weapon)) { m_cachedActiveWeapon = std::make_shared(weapon); } @@ -48,7 +48,7 @@ void IInventory::Update() edict_t* weapon = GetBot()->GetActiveWeapon(); - if (weapon != nullptr && m_cachedActiveWeapon->GetEdict() != weapon) + if (UtilHelpers::IsValidEdict(weapon) && m_cachedActiveWeapon->GetEdict() != weapon) { m_cachedActiveWeapon = std::make_shared(weapon); } @@ -95,7 +95,7 @@ void IInventory::BuildInventory() edict_t* weapon = gamehelpers->EdictOfIndex(index); - if (!weapon || weapon->IsFree() || weapon->GetIServerEntity() == nullptr) + if (!UtilHelpers::IsValidEdict(weapon)) continue; m_weapons.emplace_back(new CBotWeapon(weapon)); @@ -168,7 +168,7 @@ std::shared_ptr IInventory::GetActiveBotWeapon() { edict_t* weapon = GetBot()->GetActiveWeapon(); - if (weapon == nullptr) + if (!UtilHelpers::IsValidEdict(weapon)) { return nullptr; } diff --git a/extension/util/helpers.h b/extension/util/helpers.h index 169177a..48e161d 100644 --- a/extension/util/helpers.h +++ b/extension/util/helpers.h @@ -39,6 +39,16 @@ namespace UtilHelpers return edict != nullptr; } + inline bool IsValidEdict(edict_t* edict) + { + if (edict == nullptr || edict->IsFree() || edict->GetIServerEntity() == nullptr) + { + return false; + } + + return true; + } + // Returns whether or not an entity has a valid networkable edict. bool IsEntNetworkable(int index); // Returns whether or not an entity has a valid networkable edict.