summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2018-11-14 22:50:31 +0100
committerGitHub <noreply@github.com>2018-11-14 22:50:31 +0100
commit3b93418544f84f142ea2a6e2bcdf1621267ff989 (patch)
tree3b14fb1d02c4a293bd5506ad8546e8ccd0922edb
parent9f77ce4b9702b1efe079ef9b1abe491482690850 (diff)
parentfb33bf84fde847d8329ec241e83ea3a05595caa5 (diff)
downloadhercules-3b93418544f84f142ea2a6e2bcdf1621267ff989.tar.gz
hercules-3b93418544f84f142ea2a6e2bcdf1621267ff989.tar.bz2
hercules-3b93418544f84f142ea2a6e2bcdf1621267ff989.tar.xz
hercules-3b93418544f84f142ea2a6e2bcdf1621267ff989.zip
Merge pull request #1233 from dastgirp/r5-defense
Fixed defense overflow exploit
-rw-r--r--src/map/battle.c65
-rw-r--r--src/map/unit.c2
2 files changed, 36 insertions, 31 deletions
diff --git a/src/map/battle.c b/src/map/battle.c
index 652453bf0..f51240810 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -1365,24 +1365,28 @@ static int64 battle_calc_defense(int attack_type, struct block_list *src, struct
#endif
}
- if( battle_config.vit_penalty_type && battle_config.vit_penalty_target&target->type ) {
- unsigned char target_count; //256 max targets should be a sane max
- target_count = unit->counttargeted(target);
- if(target_count >= battle_config.vit_penalty_count) {
- if(battle_config.vit_penalty_type == 1) {
- if( !tsc || !tsc->data[SC_STEELBODY] )
- def1 = (def1 * (100 - (target_count - (battle_config.vit_penalty_count - 1))*battle_config.vit_penalty_num))/100;
- def2 = (def2 * (100 - (target_count - (battle_config.vit_penalty_count - 1))*battle_config.vit_penalty_num))/100;
- } else { //Assume type 2
- if( !tsc || !tsc->data[SC_STEELBODY] )
- def1 -= (target_count - (battle_config.vit_penalty_count - 1))*battle_config.vit_penalty_num;
- def2 -= (target_count - (battle_config.vit_penalty_count - 1))*battle_config.vit_penalty_num;
+ if (battle_config.vit_penalty_type != 0 && (battle_config.vit_penalty_target & target->type) != 0) {
+ int target_count = unit->counttargeted(target);
+ if (target_count >= battle_config.vit_penalty_count) {
+ int penalty = (target_count - (battle_config.vit_penalty_count - 1)) * battle_config.vit_penalty_num;
+ if (battle_config.vit_penalty_type == 1) {
+ if (tsc == NULL || tsc->data[SC_STEELBODY] == NULL)
+ def1 = def1 * (100 - penalty) / 100;
+ def2 = def2 * (100 - penalty) / 100;
+ } else { // Assume type 2
+ if (tsc == NULL || tsc->data[SC_STEELBODY] == NULL)
+ def1 -= penalty;
+ def2 -= penalty;
}
}
#ifndef RENEWAL
- if(skill_id == AM_ACIDTERROR) def1 = 0; //Acid Terror ignores only armor defense. [Skotlex]
+ if (skill_id == AM_ACIDTERROR)
+ def1 = 0; // Acid Terror ignores only armor defense. [Skotlex]
#endif
- if(def2 < 1) def2 = 1;
+ if (def1 < 0)
+ def1 = 0;
+ if (def2 < 1)
+ def2 = 1;
}
//Vitality reduction from rodatazone: http://rodatazone.simgaming.net/mechanics/substats.php#def
if (tsd) {
@@ -4224,16 +4228,16 @@ static struct Damage battle_calc_misc_attack(struct block_list *src, struct bloc
hitrate = 80; //Default hitrate
#endif
- if(battle_config.agi_penalty_type && battle_config.agi_penalty_target&target->type) {
- unsigned char attacker_count; //256 max targets should be a sane max
- attacker_count = unit->counttargeted(target);
- if(attacker_count >= battle_config.agi_penalty_count)
- {
+ if (battle_config.agi_penalty_type != 0 && (battle_config.agi_penalty_target & target->type) != 0) {
+ int attacker_count = unit->counttargeted(target);
+ if (attacker_count >= battle_config.agi_penalty_count) {
+ int penalty = (attacker_count - (battle_config.agi_penalty_count - 1)) * battle_config.agi_penalty_num;
if (battle_config.agi_penalty_type == 1)
- flee = (flee * (100 - (attacker_count - (battle_config.agi_penalty_count - 1))*battle_config.agi_penalty_num))/100;
+ flee = flee * (100 - penalty) / 100;
else // assume type 2: absolute reduction
- flee -= (attacker_count - (battle_config.agi_penalty_count - 1))*battle_config.agi_penalty_num;
- if(flee < 1) flee = 1;
+ flee -= penalty;
+ if (flee < 1)
+ flee = 1;
}
}
@@ -4751,15 +4755,16 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src, struct bl
short hitrate = 80; //Default hitrate
#endif
- if(battle_config.agi_penalty_type && battle_config.agi_penalty_target&target->type) {
- unsigned char attacker_count; //256 max targets should be a sane max
- attacker_count = unit->counttargeted(target);
- if(attacker_count >= battle_config.agi_penalty_count) {
+ if (battle_config.agi_penalty_type != 0 && (battle_config.agi_penalty_target & target->type) != 0) {
+ int attacker_count = unit->counttargeted(target);
+ if (attacker_count >= battle_config.agi_penalty_count) {
+ int penalty = (attacker_count - (battle_config.agi_penalty_count - 1)) * battle_config.agi_penalty_num;
if (battle_config.agi_penalty_type == 1)
- flee = (flee * (100 - (attacker_count - (battle_config.agi_penalty_count - 1))*battle_config.agi_penalty_num))/100;
- else //asume type 2: absolute reduction
- flee -= (attacker_count - (battle_config.agi_penalty_count - 1))*battle_config.agi_penalty_num;
- if(flee < 1) flee = 1;
+ flee = flee * (100 - penalty) / 100;
+ else // asume type 2: absolute reduction
+ flee -= penalty;
+ if (flee < 1)
+ flee = 1;
}
}
diff --git a/src/map/unit.c b/src/map/unit.c
index 9174bdccd..371be03db 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -1836,7 +1836,7 @@ static int unit_set_target(struct unit_data *ud, int target_id)
struct block_list* target;
if (ud->target && (target = map->id2bl(ud->target)) != NULL && (ux = unit->bl2ud(target)) != NULL && ux->target_count > 0)
--ux->target_count;
- if (target_id && (target = map->id2bl(target_id)) != NULL && (ux = unit->bl2ud(target)) != NULL)
+ if (target_id && (target = map->id2bl(target_id)) != NULL && (ux = unit->bl2ud(target)) != NULL && ux->target_count < UCHAR_MAX)
++ux->target_count;
}