Skip to content

Commit

Permalink
fix: some combat nullpointers (opentibiabr#788)
Browse files Browse the repository at this point in the history
Fixes pointers that were accessed without checking if they are nullptr, may cause unexpected behaviour.
  • Loading branch information
dudantas committed Feb 7, 2023
1 parent 397cd89 commit aefda68
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void Combat::CombatManaFunc(Creature* caster, Creature* target, const CombatPara
assert(data);
CombatDamage damage = *data;
if (damage.primary.value < 0) {
if (caster && caster->getPlayer() && target->getSkull() != SKULL_BLACK && target->getPlayer()) {
if (caster && target && caster->getPlayer() && target->getSkull() != SKULL_BLACK && target->getPlayer()) {
damage.primary.value /= 2;
}
}
Expand All @@ -606,8 +606,11 @@ void Combat::CombatConditionFunc(Creature* caster, Creature* target, const Comba
}

for (const auto& condition : params.conditionList) {
Player* player = nullptr;
if (target) {
player = target->getPlayer();
}
//Cleanse charm rune (target as player)
Player* player = target->getPlayer();
if (player) {
if (player->isImmuneCleanse(condition->getType())) {
player->sendCancelMessage("You are still immune against this spell.");
Expand All @@ -631,14 +634,16 @@ void Combat::CombatConditionFunc(Creature* caster, Creature* target, const Comba
}
}

if (caster == target || !target->isImmune(condition->getType())) {
if (caster == target || target && !target->isImmune(condition->getType())) {
Condition* conditionCopy = condition->clone();
if (caster) {
conditionCopy->setParam(CONDITION_PARAM_OWNER, caster->getID());
}

//TODO: infight condition until all aggressive conditions has ended
target->addCombatCondition(conditionCopy);
if (target) {
target->addCombatCondition(conditionCopy);
}
}
}
}
Expand Down Expand Up @@ -928,7 +933,7 @@ void Combat::doCombatHealth(Creature* caster, Creature* target, CombatDamage& da
g_game().addMagicEffect(target->getPosition(), params.impactEffect);
}

if (params.combatType == COMBAT_HEALING && target->getMonster()){
if (target && params.combatType == COMBAT_HEALING && target->getMonster()){
if (target != caster) {
return;
}
Expand Down

0 comments on commit aefda68

Please sign in to comment.