summaryrefslogtreecommitdiff
path: root/src/map/battle.c
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-09-13 14:03:55 +0300
committerAndrei Karas <akaras@inbox.ru>2015-09-14 20:12:11 +0300
commitb563e5866facea306b455f4ebadd09ae0bfd7e0e (patch)
treedd671f657d26655ad267a87d94fffbca559cba8c /src/map/battle.c
parentba9c1cc16cb8f696a50d0ae928b6e8a19086405b (diff)
downloadhercules-b563e5866facea306b455f4ebadd09ae0bfd7e0e.tar.gz
hercules-b563e5866facea306b455f4ebadd09ae0bfd7e0e.tar.bz2
hercules-b563e5866facea306b455f4ebadd09ae0bfd7e0e.tar.xz
hercules-b563e5866facea306b455f4ebadd09ae0bfd7e0e.zip
Add missing checks into battle.c.
Diffstat (limited to 'src/map/battle.c')
-rw-r--r--src/map/battle.c60
1 files changed, 51 insertions, 9 deletions
diff --git a/src/map/battle.c b/src/map/battle.c
index 6a6924aa3..d4f789d34 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -48,7 +48,8 @@ struct battle_interface *battle;
int battle_getcurrentskill(struct block_list *bl) { //Returns the current/last skill in use by this bl.
struct unit_data *ud;
- if( bl->type == BL_SKILL ) {
+ nullpo_ret(bl);
+ if (bl->type == BL_SKILL) {
struct skill_unit * su = (struct skill_unit*)bl;
return su->group?su->group->skill_id:0;
}
@@ -67,6 +68,7 @@ int battle_gettargeted_sub(struct block_list *bl, va_list ap) {
int target_id;
int *c;
+ nullpo_ret(bl);
bl_list = va_arg(ap, struct block_list **);
c = va_arg(ap, int *);
target_id = va_arg(ap, int);
@@ -77,7 +79,7 @@ int battle_gettargeted_sub(struct block_list *bl, va_list ap) {
if (*c >= 24)
return 0;
- if ( !(ud = unit->bl2ud(bl)) )
+ if (!(ud = unit->bl2ud(bl)))
return 0;
if (ud->target == target_id || ud->skilltarget == target_id) {
@@ -106,6 +108,7 @@ struct block_list* battle_gettargeted(struct block_list *target) {
//Returns the id of the current targeted character of the passed bl. [Skotlex]
int battle_gettarget(struct block_list* bl) {
+ nullpo_ret(bl);
switch (bl->type) {
case BL_PC: return ((struct map_session_data*)bl)->ud.target;
case BL_MOB: return ((struct mob_data*)bl)->target_id;
@@ -123,6 +126,7 @@ int battle_getenemy_sub(struct block_list *bl, va_list ap) {
struct block_list *target;
int *c;
+ nullpo_ret(bl);
bl_list = va_arg(ap, struct block_list **);
c = va_arg(ap, int *);
target = va_arg(ap, struct block_list *);
@@ -149,6 +153,7 @@ struct block_list* battle_getenemy(struct block_list *target, int type, int rang
struct block_list *bl_list[24];
int c = 0;
+ nullpo_retr(NULL, target);
memset(bl_list, 0, sizeof(bl_list));
map->foreachinrange(battle->get_enemy_sub, target, range, type, bl_list, &c, target);
@@ -164,8 +169,11 @@ int battle_getenemyarea_sub(struct block_list *bl, va_list ap) {
struct block_list **bl_list, *src;
int *c, ignore_id;
+ nullpo_ret(bl);
bl_list = va_arg(ap, struct block_list **);
+ nullpo_ret(bl_list);
c = va_arg(ap, int *);
+ nullpo_ret(c);
src = va_arg(ap, struct block_list *);
ignore_id = va_arg(ap, int);
@@ -191,6 +199,7 @@ struct block_list* battle_getenemyarea(struct block_list *src, int x, int y, int
struct block_list *bl_list[24];
int c = 0;
+ nullpo_retr(NULL, src);
memset(bl_list, 0, sizeof(bl_list));
map->foreachinarea(battle->get_enemy_area_sub, src->m, x - range, y - range, x + range, y + range, type, bl_list, &c, src, ignore_id);
@@ -300,7 +309,6 @@ int battle_delay_damage(int64 tick, int amotion, struct block_list *src, struct
}
int battle_attr_ratio(int atk_elem,int def_type, int def_lv)
{
-
if (atk_elem < ELE_NEUTRAL || atk_elem >= ELE_MAX)
return 100;
@@ -501,7 +509,8 @@ int64 battle_calc_base_damage(struct block_list *src, struct block_list *bl, uin
int64 damage;
struct status_data *st = status->get_status_data(src);
struct status_change *sc = status->get_sc(src);
-
+
+ nullpo_retr(0, src);
if ( !skill_id ) {
s_ele = st->rhw.ele;
s_ele_ = st->lhw.ele;
@@ -536,6 +545,8 @@ int64 battle_calc_base_damage2(struct status_data *st, struct weapon_atk *wa, st
short type = 0;
int64 damage = 0;
+ nullpo_retr(damage, st);
+ nullpo_retr(damage, wa);
if (!sd) { //Mobs/Pets
if(flag&4) {
atkmin = st->matk_min;
@@ -612,6 +623,7 @@ int64 battle_calc_base_damage2(struct status_data *st, struct weapon_atk *wa, st
int64 battle_calc_sizefix(struct map_session_data *sd, int64 damage, int type, int size, bool ignore){
//SizeFix only for players
+ nullpo_retr(damage, sd);
if (!(sd->special_state.no_sizefix || (ignore)))
damage = damage * ( type == EQI_HAND_L ? sd->left_weapon.atkmods[size] : sd->right_weapon.atkmods[size] ) / 100;
return damage;
@@ -627,8 +639,8 @@ int64 battle_addmastery(struct map_session_data *sd,struct block_list *target,in
int weapon, skill_lv;
damage = dmg;
- nullpo_ret(sd);
-
+ nullpo_retr(damage, sd);
+ nullpo_retr(damage, target);
if((skill_lv = pc->checkskill(sd,AL_DEMONBANE)) > 0 &&
target->type == BL_MOB && //This bonus doesn't work against players.
(battle->check_undead(st->race,st->def_ele) || st->race==RC_DEMON) )
@@ -2688,9 +2700,12 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
struct map_session_data *sd = NULL;
struct status_change *sc, *tsc;
struct status_change_entry *sce;
- int div_ = d->div_, flag = d->flag;
+ int div_, flag;
nullpo_ret(bl);
+ nullpo_ret(d);
+ div_ = d->div_;
+ flag = d->flag;
// need check src for null pointer?
@@ -3286,6 +3301,7 @@ int64 battle_calc_bg_damage(struct block_list *src, struct block_list *bl, int64
if( !damage )
return 0;
+ nullpo_retr(damage, bl);
if( bl->type == BL_MOB ) {
struct mob_data* md = BL_CAST(BL_MOB, bl);
@@ -3306,6 +3322,8 @@ int64 battle_calc_gvg_damage(struct block_list *src,struct block_list *bl,int64
if (!damage) //No reductions to make.
return 0;
+ nullpo_retr(damage, src);
+ nullpo_retr(damage, bl);
if(md && md->guardian_data) {
if(class_ == MOBID_EMPERIUM && flag&BF_SKILL) {
@@ -3373,6 +3391,8 @@ int battle_calc_drain(int64 damage, int rate, int per) {
*------------------------------------------*/
void battle_consume_ammo(TBL_PC*sd, int skill_id, int lv) {
int qty=1;
+
+ nullpo_retv(sd);
if (!battle_config.arrow_decrement)
return;
@@ -3386,8 +3406,12 @@ void battle_consume_ammo(TBL_PC*sd, int skill_id, int lv) {
sd->state.arrow_atk = 0;
}
+
//Skill Range Criteria
int battle_range_type(struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv) {
+ nullpo_retr(BF_SHORT, src);
+ nullpo_retr(BF_SHORT, target);
+
if (battle_config.skillrange_by_distance &&
(src->type&battle_config.skillrange_by_distance)
) { //based on distance between src/target [Skotlex]
@@ -3420,8 +3444,10 @@ int battle_adjust_skill_damage(int m, unsigned short skill_id) {
return 0;
}
+
int battle_blewcount_bonus(struct map_session_data *sd, uint16 skill_id) {
int i;
+ nullpo_ret(sd);
if (!sd->skillblown[0].id)
return 0;
//Apply the bonus blow count. [Skotlex]
@@ -5576,6 +5602,7 @@ struct Damage battle_calc_attack(int attack_type,struct block_list *bl,struct bl
break;
}
+ nullpo_retr(d, target);
#ifdef HMAP_ZONE_DAMAGE_CAP_TYPE
if( target && skill_id ) {
int i;
@@ -5613,9 +5640,10 @@ struct Damage battle_calc_attack(int attack_type,struct block_list *bl,struct bl
}
return d;
}
+
//Performs reflect damage (magic (maya) is performed over skill.c).
void battle_reflect_damage(struct block_list *target, struct block_list *src, struct Damage *wd,uint16 skill_id) {
- int64 damage = wd->damage + wd->damage2, rdamage = 0, trdamage = 0;
+ int64 damage, rdamage = 0, trdamage = 0;
struct map_session_data *sd, *tsd;
struct status_change *sc;
int64 tick = timer->gettick();
@@ -5626,6 +5654,10 @@ void battle_reflect_damage(struct block_list *target, struct block_list *src, st
max_reflect_damage = max(status_get_max_hp(target), status_get_max_hp(target) * status->get_lv(target) / 100);
#endif
+ damage = wd->damage + wd->damage2;
+
+ nullpo_retv(wd);
+
sd = BL_CAST(BL_PC, src);
tsd = BL_CAST(BL_PC, target);
@@ -5806,11 +5838,14 @@ void battle_reflect_damage(struct block_list *target, struct block_list *src, st
return;
#undef NORMALIZE_RDAMAGE
}
+
void battle_drain(TBL_PC *sd, struct block_list *tbl, int64 rdamage, int64 ldamage, int race, int boss)
{
struct weapon_data *wd;
int type, thp = 0, tsp = 0, rhp = 0, rsp = 0, hp, sp, i;
int64 *damage;
+
+ nullpo_retv(sd);
for (i = 0; i < 4; i++) {
//First two iterations: Right hand
if (i < 2) { wd = &sd->right_weapon; damage = &rdamage; }
@@ -5873,6 +5908,7 @@ int battle_damage_area(struct block_list *bl, va_list ap) {
if( bl->type == BL_MOB && ((TBL_MOB*)bl)->class_ == MOBID_EMPERIUM )
return 0;
if( bl != src && battle->check_target(src,bl,BCT_ENEMY) > 0 ) {
+ nullpo_ret(src);
map->freeblock_lock();
if( src->type == BL_PC )
battle->drain((TBL_PC*)src, bl, damage, damage, status_get_race(bl), is_boss(bl));
@@ -6273,6 +6309,7 @@ bool battle_check_undead(int race,int element)
//Returns the upmost level master starting with the given object
struct block_list* battle_get_master(struct block_list *src) {
struct block_list *prev; //Used for infinite loop check (master of yourself?)
+ nullpo_retr(NULL, src);
do {
prev = src;
switch (src->type) {
@@ -7270,8 +7307,10 @@ static int Hercules_report_timer(int tid, int64 tick, int id, intptr_t data) {
int battle_set_value(const char* w1, const char* w2)
{
int val = config_switch(w2);
-
int i;
+
+ nullpo_retr(1, w1);
+ nullpo_retr(1, w2);
ARR_FIND(0, ARRAYLENGTH(battle_data), i, strcmpi(w1, battle_data[i].str) == 0);
if (i == ARRAYLENGTH(battle_data)) {
if( HPM->parseConf(w1,w2,HPCT_BATTLE) ) /* if plugin-owned, succeed */
@@ -7292,6 +7331,7 @@ int battle_set_value(const char* w1, const char* w2)
int battle_get_value(const char* w1)
{
int i;
+ nullpo_retr(1, w1);
ARR_FIND(0, ARRAYLENGTH(battle_data), i, strcmpi(w1, battle_data[i].str) == 0);
if (i == ARRAYLENGTH(battle_data))
return 0; // not found
@@ -7374,6 +7414,8 @@ int battle_config_read(const char* cfgName)
FILE* fp;
static int count = 0;
+ nullpo_ret(cfgName);
+
if (count == 0)
battle->config_set_defaults();