[Crash] Add Checks for valid pointers or fix existing. (#3164)

This commit is contained in:
Aeadoin
2023-04-01 12:44:00 -04:00
committed by GitHub
parent 4c2271ff69
commit 0d509a7f3a
19 changed files with 228 additions and 179 deletions
+20 -7
View File
@@ -1888,11 +1888,15 @@ bool Bot::AIHealRotation(Mob* tar, bool useFastHeals) {
std::list<BotSpell> Bot::GetBotSpellsForSpellEffect(Bot* botCaster, int spellEffect) {
std::list<BotSpell> result;
if (!botCaster) {
return result;
}
if (auto bot_owner = botCaster->GetBotOwner(); !bot_owner) {
return result;
}
if (botCaster && botCaster->AI_HasSpells()) {
if (botCaster->AI_HasSpells()) {
std::vector<BotSpells_Struct> botSpellList = botCaster->AIBot_spells;
for (int i = botSpellList.size() - 1; i >= 0; i--) {
@@ -1919,11 +1923,15 @@ std::list<BotSpell> Bot::GetBotSpellsForSpellEffect(Bot* botCaster, int spellEff
std::list<BotSpell> Bot::GetBotSpellsForSpellEffectAndTargetType(Bot* botCaster, int spellEffect, SpellTargetType targetType) {
std::list<BotSpell> result;
if (!botCaster) {
return result;
}
if (auto bot_owner = botCaster->GetBotOwner(); !bot_owner) {
return result;
}
if (botCaster && botCaster->AI_HasSpells()) {
if (botCaster->AI_HasSpells()) {
std::vector<BotSpells_Struct> botSpellList = botCaster->AIBot_spells;
for (int i = botSpellList.size() - 1; i >= 0; i--) {
@@ -1955,11 +1963,15 @@ std::list<BotSpell> Bot::GetBotSpellsForSpellEffectAndTargetType(Bot* botCaster,
std::list<BotSpell> Bot::GetBotSpellsBySpellType(Bot* botCaster, uint32 spellType) {
std::list<BotSpell> result;
if (!botCaster) {
return result;
}
if (auto bot_owner = botCaster->GetBotOwner(); !bot_owner) {
return result;
}
if (botCaster && botCaster->AI_HasSpells()) {
if (botCaster->AI_HasSpells()) {
std::vector<BotSpells_Struct> botSpellList = botCaster->AIBot_spells;
for (int i = botSpellList.size() - 1; i >= 0; i--) {
@@ -2694,21 +2706,22 @@ BotSpell Bot::GetBestBotSpellForResistDebuff(Bot* botCaster, Mob *tar) {
result.SpellIndex = 0;
result.ManaCost = 0;
if (!tar)
if (!tar || !botCaster) {
return result;
}
int level_mod = (tar->GetLevel() - botCaster->GetLevel())* (tar->GetLevel() - botCaster->GetLevel()) / 2;
if (tar->GetLevel() - botCaster->GetLevel() < 0)
{
if (tar->GetLevel() - botCaster->GetLevel() < 0) {
level_mod = -level_mod;
}
bool needsMagicResistDebuff = (tar->GetMR() + level_mod) > 100;
bool needsColdResistDebuff = (tar->GetCR() + level_mod) > 100;
bool needsFireResistDebuff = (tar->GetFR() + level_mod) > 100;
bool needsPoisonResistDebuff = (tar->GetPR() + level_mod) > 100;
bool needsDiseaseResistDebuff = (tar->GetDR() + level_mod) > 100;
if (botCaster && botCaster->AI_HasSpells()) {
if (botCaster->AI_HasSpells()) {
std::vector<BotSpells_Struct> botSpellList = botCaster->AIBot_spells;
for (int i = botSpellList.size() - 1; i >= 0; i--) {