From 600233b7b200ea846bf5462f1501c2a52c4021a4 Mon Sep 17 00:00:00 2001 From: marcinho1994 <44486916+marcinho1994@users.noreply.github.com> Date: Wed, 8 May 2019 23:10:54 -0300 Subject: [PATCH 1/7] Update spells.cpp | fix very rare crash bug. Fixing a very rare bug. In very specific situations, when the creature or target is removed, it can cause a crash, because in this part of the code the methods "creature->getPosition() and target->getPosition()" are used without first checking that they exist. This causes a bug in combat.cpp when trying to use a position that does not exist. --- src/spells.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/spells.cpp b/src/spells.cpp index c12f5884dc..ab2a39159b 100644 --- a/src/spells.cpp +++ b/src/spells.cpp @@ -257,6 +257,8 @@ bool CombatSpell::loadScriptCombat() bool CombatSpell::castSpell(Creature* creature) { + if (!creature) + return false; if (scripted) { LuaVariant var; var.type = VARIANT_POSITION; @@ -283,6 +285,8 @@ bool CombatSpell::castSpell(Creature* creature) bool CombatSpell::castSpell(Creature* creature, Creature* target) { + if (!creature || !target) + return false; if (scripted) { LuaVariant var; From ed26cb8dd789effe79bb1722ff7158b6096350ab Mon Sep 17 00:00:00 2001 From: marcinho1994 <44486916+marcinho1994@users.noreply.github.com> Date: Thu, 9 May 2019 14:38:28 -0300 Subject: [PATCH 2/7] Update spells.cpp --- src/spells.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/spells.cpp b/src/spells.cpp index ab2a39159b..c7387db52d 100644 --- a/src/spells.cpp +++ b/src/spells.cpp @@ -257,8 +257,9 @@ bool CombatSpell::loadScriptCombat() bool CombatSpell::castSpell(Creature* creature) { - if (!creature) + if (!creature) { return false; + } if (scripted) { LuaVariant var; var.type = VARIANT_POSITION; @@ -285,8 +286,9 @@ bool CombatSpell::castSpell(Creature* creature) bool CombatSpell::castSpell(Creature* creature, Creature* target) { - if (!creature || !target) + if (!creature || !target) { return false; + } if (scripted) { LuaVariant var; From ca9f43479cdbf35e287febf235dc43f430362d0a Mon Sep 17 00:00:00 2001 From: marcinho1994 <44486916+marcinho1994@users.noreply.github.com> Date: Tue, 14 May 2019 19:13:30 -0300 Subject: [PATCH 3/7] Update spells.cpp --- src/spells.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/spells.cpp b/src/spells.cpp index c7387db52d..c12f5884dc 100644 --- a/src/spells.cpp +++ b/src/spells.cpp @@ -257,9 +257,6 @@ bool CombatSpell::loadScriptCombat() bool CombatSpell::castSpell(Creature* creature) { - if (!creature) { - return false; - } if (scripted) { LuaVariant var; var.type = VARIANT_POSITION; @@ -286,9 +283,6 @@ bool CombatSpell::castSpell(Creature* creature) bool CombatSpell::castSpell(Creature* creature, Creature* target) { - if (!creature || !target) { - return false; - } if (scripted) { LuaVariant var; From f5e91fa01d2b74cae05ad4eaced2af9798112223 Mon Sep 17 00:00:00 2001 From: marcinho1994 <44486916+marcinho1994@users.noreply.github.com> Date: Tue, 14 May 2019 19:24:06 -0300 Subject: [PATCH 4/7] Update monster.cpp --- src/monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monster.cpp b/src/monster.cpp index f7d4888027..527e866ba3 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -775,7 +775,7 @@ void Monster::doAttacking(uint32_t interval) for (const spellBlock_t& spellBlock : mType->info.attackSpells) { bool inRange = false; - if (canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) { + if (attackedCreature && canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) { if (spellBlock.chance >= static_cast(uniform_random(1, 100))) { if (updateLook) { updateLookDirection(); From 0dd28ac07c564571eef693c9930f0e61a83144a8 Mon Sep 17 00:00:00 2001 From: marcinho1994 <44486916+marcinho1994@users.noreply.github.com> Date: Wed, 15 May 2019 19:57:42 -0300 Subject: [PATCH 5/7] Update monster.cpp --- src/monster.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/monster.cpp b/src/monster.cpp index 527e866ba3..8edccfe1cd 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -774,8 +774,10 @@ void Monster::doAttacking(uint32_t interval) for (const spellBlock_t& spellBlock : mType->info.attackSpells) { bool inRange = false; - - if (attackedCreature && canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) { + if (attackedCreature == nullptr) { + break; + } + if (canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) { if (spellBlock.chance >= static_cast(uniform_random(1, 100))) { if (updateLook) { updateLookDirection(); From d6e089554855cec78045c84f2373e00a7799bf26 Mon Sep 17 00:00:00 2001 From: marcinho1994 <44486916+marcinho1994@users.noreply.github.com> Date: Fri, 17 May 2019 03:31:11 -0300 Subject: [PATCH 6/7] Update monster.cpp --- src/monster.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/monster.cpp b/src/monster.cpp index 8edccfe1cd..b37a273b7b 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -774,6 +774,7 @@ void Monster::doAttacking(uint32_t interval) for (const spellBlock_t& spellBlock : mType->info.attackSpells) { bool inRange = false; + if (attackedCreature == nullptr) { break; } From a2e0e058b49bc7891e6ca1e46e33601470a58ed0 Mon Sep 17 00:00:00 2001 From: marcinho1994 <44486916+marcinho1994@users.noreply.github.com> Date: Fri, 17 May 2019 03:32:16 -0300 Subject: [PATCH 7/7] Update monster.cpp --- src/monster.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/monster.cpp b/src/monster.cpp index b37a273b7b..7848867fb9 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -778,6 +778,7 @@ void Monster::doAttacking(uint32_t interval) if (attackedCreature == nullptr) { break; } + if (canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) { if (spellBlock.chance >= static_cast(uniform_random(1, 100))) { if (updateLook) {