summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/map/skill.c455
-rw-r--r--src/map/status.c329
-rw-r--r--src/map/storage.c53
-rw-r--r--src/map/trade.c24
-rw-r--r--src/map/unit.c100
-rw-r--r--src/map/vending.c35
6 files changed, 732 insertions, 264 deletions
diff --git a/src/map/skill.c b/src/map/skill.c
index 5e32e922c..ab1c026f3 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -86,6 +86,7 @@ struct skill_interface *skill;
//Since only mob-casted splash skills can hit ice-walls
int skill_splash_target(struct block_list* bl)
{
+ nullpo_retr(BL_CHAR, bl);
#ifndef RENEWAL
return ( bl->type == BL_MOB ) ? BL_SKILL|BL_CHAR : BL_CHAR;
#else // Some skills can now hit ground skills(traps, ice wall & etc.)
@@ -94,7 +95,8 @@ int skill_splash_target(struct block_list* bl)
}
/// Returns the id of the skill, or 0 if not found.
-int skill_name2id(const char* name) {
+int skill_name2id(const char* name)
+{
if( name == NULL )
return 0;
@@ -103,7 +105,8 @@ int skill_name2id(const char* name) {
/// Maps skill ids to skill db offsets.
/// Returns the skill's array index, or 0 (Unknown Skill).
-int skill_get_index( uint16 skill_id ) {
+int skill_get_index (uint16 skill_id)
+{
// avoid ranges reserved for mapping guild/homun/mercenary skills
if( (skill_id >= GD_SKILLRANGEMIN && skill_id <= GD_SKILLRANGEMAX)
|| (skill_id >= HM_SKILLRANGEMIN && skill_id <= HM_SKILLRANGEMAX)
@@ -215,6 +218,7 @@ int skill_get_fixed_cast( uint16 skill_id ,uint16 skill_lv ) {
return 0;
#endif
}
+
int skill_tree_get_max(uint16 skill_id, int b_class)
{
int i;
@@ -227,7 +231,8 @@ int skill_tree_get_max(uint16 skill_id, int b_class)
return skill->get_max(skill_id);
}
-int skill_get_casttype (uint16 skill_id) {
+int skill_get_casttype(uint16 skill_id)
+{
int inf = skill->get_inf(skill_id);
if (inf&(INF_GROUND_SKILL))
return CAST_GROUND;
@@ -243,8 +248,11 @@ int skill_get_casttype (uint16 skill_id) {
return CAST_DAMAGE;
}
-int skill_get_casttype2 (uint16 index) {
- int inf = skill->dbs->db[index].inf;
+int skill_get_casttype2(uint16 index)
+{
+ int inf;
+ Assert_retr(CAST_NODAMAGE, index < MAX_SKILL_DB);
+ inf = skill->dbs->db[index].inf;
if (inf&(INF_GROUND_SKILL))
return CAST_GROUND;
if (inf&INF_SUPPORT_SKILL)
@@ -260,7 +268,8 @@ int skill_get_casttype2 (uint16 index) {
}
//Returns actual skill range taking into account attack range and AC_OWL [Skotlex]
-int skill_get_range2 (struct block_list *bl, uint16 skill_id, uint16 skill_lv) {
+int skill_get_range2(struct block_list *bl, uint16 skill_id, uint16 skill_lv)
+{
int range;
struct map_session_data *sd = BL_CAST(BL_PC, bl);
if( bl->type == BL_MOB && battle_config.mob_ai&0x400 )
@@ -437,6 +446,7 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk
// Making plagiarize check its own function [Aru]
int can_copy (struct map_session_data *sd, uint16 skill_id, struct block_list* bl)
{
+ nullpo_ret(sd);
// Never copy NPC/Wedding Skills
if (skill->get_inf2(skill_id)&(INF2_NPC_SKILL|INF2_WEDDING_SKILL))
return 0;
@@ -631,6 +641,7 @@ int skillnotok_hom(uint16 skill_id, struct homun_data *hd)
int skillnotok_hom_unknown(uint16 skill_id, struct homun_data *hd)
{
+ nullpo_retr(1, hd);
//Use master's criteria.
return skill->not_ok(skill_id, hd->master);
}
@@ -648,10 +659,12 @@ int skillnotok_mercenary(uint16 skill_id, struct mercenary_data *md)
return skill->not_ok(skill_id, md->master);
}
-struct s_skill_unit_layout* skill_get_unit_layout (uint16 skill_id, uint16 skill_lv, struct block_list* src, int x, int y) {
+struct s_skill_unit_layout* skill_get_unit_layout(uint16 skill_id, uint16 skill_lv, struct block_list* src, int x, int y)
+{
int pos = skill->get_unit_layout_type(skill_id,skill_lv);
uint8 dir;
+ nullpo_retr(&skill->dbs->unit_layout[0], src);
if (pos < -1 || pos >= MAX_SKILL_UNIT_LAYOUT) {
ShowError("skill_get_unit_layout: unsupported layout type %d for skill %d (level %d)\n", pos, skill_id, skill_lv);
pos = cap_value(pos, 0, MAX_SQUARE_LAYOUT); // cap to nearest square layout
@@ -2036,7 +2049,8 @@ int skill_break_equip (struct block_list *bl, unsigned short where, int rate, in
return where; //Return list of pieces broken.
}
-int skill_strip_equip(struct block_list *bl, unsigned short where, int rate, int lv, int time) {
+int skill_strip_equip(struct block_list *bl, unsigned short where, int rate, int lv, int time)
+{
struct status_change *sc;
const int pos[5] = {EQP_WEAPON, EQP_SHIELD, EQP_ARMOR, EQP_HELM, EQP_ACC};
const enum sc_type sc_atk[5] = {SC_NOEQUIPWEAPON, SC_NOEQUIPSHIELD, SC_NOEQUIPARMOR, SC_NOEQUIPHELM, SC__STRIPACCESSARY};
@@ -2062,6 +2076,7 @@ int skill_strip_equip(struct block_list *bl, unsigned short where, int rate, int
}
return where?1:0;
}
+
/*=========================================================================
* Used to knock back players, monsters, traps, etc
* 'count' is the number of squares to knock back
@@ -2077,6 +2092,8 @@ int skill_blown(struct block_list* src, struct block_list* target, int count, in
if (src != target && map->list[src->m].flag.noknockback)
return 0; // No knocking
+
+ nullpo_ret(target);
if (count == 0)
return 0; // Actual knockback distance is 0.
@@ -2127,10 +2144,12 @@ int skill_blown(struct block_list* src, struct block_list* target, int count, in
1 - Regular reflection (Maya)
2 - SL_KAITE reflection
*/
-int skill_magic_reflect(struct block_list* src, struct block_list* bl, int type) {
+int skill_magic_reflect(struct block_list* src, struct block_list* bl, int type)
+{
struct status_change *sc = status->get_sc(bl);
struct map_session_data* sd = BL_CAST(BL_PC, bl);
+ nullpo_ret(src);
if( sc && sc->data[SC_KYOMU] ) // Nullify reflecting ability
return 0;
@@ -2174,7 +2193,8 @@ int skill_magic_reflect(struct block_list* src, struct block_list* bl, int type)
* client (causes player characters to not scream skill name)
* flag&0x4000 - Return 0 if damage was reflected
*-------------------------------------------------------------------------*/
-int skill_attack(int attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int64 tick, int flag) {
+int skill_attack(int attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int64 tick, int flag)
+{
struct Damage dmg;
struct status_data *sstatus, *tstatus;
struct status_change *sc;
@@ -2865,15 +2885,27 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
return (int)cap_value(damage,INT_MIN,INT_MAX);
}
-void skill_attack_combo1_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, struct status_change_entry *sce, int *combo) {
+void skill_attack_combo1_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, struct status_change_entry *sce, int *combo)
+{
if (src == dsrc) // Ground skills are exceptions. [Inkfish]
status_change_end(src, SC_COMBOATTACK, INVALID_TIMER);
}
-void skill_attack_combo2_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *combo) {
+void skill_attack_combo2_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *combo)
+{
}
-void skill_attack_display_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage) {
+void skill_attack_display_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage)
+{
+ nullpo_retv(bl);
+ nullpo_retv(dmg);
+ nullpo_retv(tick);
+ nullpo_retv(flag);
+ nullpo_retv(damage);
+ nullpo_retv(skill_id);
+ nullpo_retv(skill_lv);
+ nullpo_retv(type);
+
if (*flag & SD_ANIMATION && dmg->div_ < 2) //Disabling skill animation doesn't works on multi-hit.
*type = BDT_SPLASH;
if (bl->type == BL_SKILL) {
@@ -2884,15 +2916,24 @@ void skill_attack_display_unknown(int *attack_type, struct block_list* src, stru
dmg->dmotion = clif->skill_damage(dsrc, bl, *tick, dmg->amotion, dmg->dmotion, *damage, dmg->div_, *skill_id, (*flag & SD_LEVEL) ? -1 : *skill_lv, *type);
}
-int skill_attack_copy_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag) {
+int skill_attack_copy_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag)
+{
+ nullpo_ret(skill_id);
return *skill_id;
}
-int skill_attack_dir_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag) {
+int skill_attack_dir_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag)
+{
return -1;
}
-void skill_attack_blow_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, int8 *dir) {
+void skill_attack_blow_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, int8 *dir)
+{
+ nullpo_retv(bl);
+ nullpo_retv(dmg);
+ nullpo_retv(dir);
+ nullpo_retv(damage);
+
skill->blown(dsrc, bl, dmg->blewcount, *dir, 0x0);
if (!dmg->blewcount && bl->type == BL_SKILL && *damage > 0){
struct skill_unit *su = BL_UCAST(BL_SKILL, bl);
@@ -2901,7 +2942,8 @@ void skill_attack_blow_unknown(int *attack_type, struct block_list* src, struct
}
}
-void skill_attack_post_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag) {
+void skill_attack_post_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag)
+{
}
/*==========================================
@@ -2909,7 +2951,8 @@ void skill_attack_post_unknown(int *attack_type, struct block_list* src, struct
* Checking bl battle flag and display damage
* then call func with source,target,skill_id,skill_lv,tick,flag
*------------------------------------------*/
-int skill_area_sub(struct block_list *bl, va_list ap) {
+int skill_area_sub(struct block_list *bl, va_list ap)
+{
struct block_list *src;
uint16 skill_id,skill_lv;
int flag;
@@ -3435,6 +3478,7 @@ bool skill_timerskill_dead_unknown(struct block_list *src, struct unit_data *ud,
void skill_timerskill_target_unknown(int tid, int64 tick, struct block_list *src, struct block_list *target, struct unit_data *ud, struct skill_timerskill *skl)
{
+ nullpo_retv(skl);
skill->attack(skl->type, src, src, target, skl->skill_id, skl->skill_lv, tick, skl->flag);
}
@@ -3445,7 +3489,8 @@ void skill_timerskill_notarget_unknown(int tid, int64 tick, struct block_list *s
/*==========================================
*
*------------------------------------------*/
-int skill_addtimerskill(struct block_list *src, int64 tick, int target, int x,int y, uint16 skill_id, uint16 skill_lv, int type, int flag) {
+int skill_addtimerskill(struct block_list *src, int64 tick, int target, int x,int y, uint16 skill_id, uint16 skill_lv, int type, int flag)
+{
int i;
struct unit_data *ud;
nullpo_retr(1, src);
@@ -3553,6 +3598,7 @@ void skill_castend_type(int type, struct block_list *src, struct block_list *bl,
{
switch (type) {
case CAST_GROUND:
+ nullpo_retv(bl);
skill->castend_pos2(src, bl->x, bl->y, skill_id, skill_lv, tick, flag);
break;
case CAST_NODAMAGE:
@@ -3568,7 +3614,8 @@ void skill_castend_type(int type, struct block_list *src, struct block_list *bl,
*
*
*------------------------------------------*/
-int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int64 tick, int flag) {
+int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int64 tick, int flag)
+{
struct map_session_data *sd = NULL;
struct status_data *tstatus;
struct status_change *sc;
@@ -4868,6 +4915,10 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
bool skill_castend_damage_id_unknown(struct block_list* src, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, struct status_data *tstatus, struct status_change *sc)
{
+ nullpo_retr(true, skill_id);
+ nullpo_retr(true, skill_lv);
+ nullpo_retr(true, tick);
+ nullpo_retr(true, tstatus);
ShowWarning("skill_castend_damage_id: Unknown skill used:%d\n", *skill_id);
clif->skill_damage(src, bl, *tick, status_get_amotion(src), tstatus->dmotion,
0, abs(skill->get_num(*skill_id, *skill_lv)),
@@ -4879,7 +4930,8 @@ bool skill_castend_damage_id_unknown(struct block_list* src, struct block_list *
/*==========================================
*
*------------------------------------------*/
-int skill_castend_id(int tid, int64 tick, int id, intptr_t data) {
+int skill_castend_id(int tid, int64 tick, int id, intptr_t data)
+{
struct block_list *target, *src;
struct map_session_data *sd;
struct mob_data *md;
@@ -5223,7 +5275,8 @@ bool skill_castend_id_unknown(struct unit_data *ud, struct block_list *src, stru
/*==========================================
*
*------------------------------------------*/
-int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int64 tick, int flag) {
+int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int64 tick, int flag)
+{
struct map_session_data *sd, *dstsd;
struct mob_data *md, *dstmd;
struct homun_data *hd;
@@ -6166,7 +6219,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
sd->devotion[i] = bl->id;
}
- else
+ else if (mer != NULL)
mer->devotion_flag = 1; // Mercenary Devoting Owner
clif->skill_nodamage(src, bl, skill_id, skill_lv,
@@ -6539,7 +6592,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case RG_STEALCOIN:
if(sd) {
int amount = pc->steal_coin(sd, bl, skill_lv);
- if( amount > 0 ) {
+ if (amount > 0 && dstmd != NULL) {
dstmd->state.provoke_flag = src->id;
mob->target(dstmd, src, skill->get_range2(src, skill_id, skill_lv));
clif->skill_nodamage(src, bl, skill_id, amount, 1);
@@ -9791,6 +9844,8 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
SC_MANDRAGORA, SC_HARMONIZE, SC_DEEP_SLEEP, SC_SIREN, SC_SLEEP, SC_CONFUSION, SC_ILLUSION
};
int heal;
+ if (hd == NULL)
+ break;
if(tsc){
int i;
for (i = 0; i < ARRAYLENGTH(scs); i++) {
@@ -9912,6 +9967,8 @@ bool skill_castend_nodamage_id_mado_unknown(struct block_list *src, struct block
bool skill_castend_nodamage_id_unknown(struct block_list *src, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag)
{
+ nullpo_retr(true, skill_id);
+ nullpo_retr(true, skill_lv);
ShowWarning("skill_castend_nodamage_id: Unknown skill used:%d\n", *skill_id);
clif->skill_nodamage(src, bl, *skill_id, *skill_lv, 1);
map->freeblock_unlock();
@@ -9928,6 +9985,7 @@ int skill_castend_pos(int tid, int64 tick, int id, intptr_t data)
struct unit_data *ud = unit->bl2ud(src);
struct mob_data *md;
+ nullpo_ret(src);
nullpo_ret(ud);
sd = BL_CAST(BL_PC , src);
@@ -10094,10 +10152,13 @@ int skill_check_npc_chaospanic(struct block_list *bl, va_list args)
return 1;
}
+
/* skill count without self */
int skill_count_wos(struct block_list *bl, va_list ap)
{
struct block_list* src = va_arg(ap, struct block_list*);
+ nullpo_retr(1, bl);
+ nullpo_retr(1, src);
if( src->id != bl->id ) {
return 1;
}
@@ -10107,8 +10168,10 @@ int skill_count_wos(struct block_list *bl, va_list ap)
/*==========================================
*
*------------------------------------------*/
-int skill_castend_map (struct map_session_data *sd, uint16 skill_id, const char *mapname) {
+int skill_castend_map (struct map_session_data *sd, uint16 skill_id, const char *mapname)
+{
nullpo_ret(sd);
+ nullpo_ret(mapname);
//Simplify skill_failed code.
#define skill_failed(sd) ( (sd)->menuskill_id = (sd)->menuskill_val = 0 )
@@ -10245,7 +10308,8 @@ int skill_castend_map (struct map_session_data *sd, uint16 skill_id, const char
/*==========================================
*
*------------------------------------------*/
-int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, uint16 skill_lv, int64 tick, int flag) {
+int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, uint16 skill_lv, int64 tick, int flag)
+{
struct map_session_data* sd;
struct status_change* sc;
struct status_change_entry *sce;
@@ -11037,7 +11101,8 @@ int skill_dance_overlap_sub(struct block_list *bl, va_list ap)
//Does the song/dance overlapping -> dissonance check. [Skotlex]
//When flag is 0, this unit is about to be removed, cancel the dissonance effect
//When 1, this unit has been positioned, so start the cancel effect.
-int skill_dance_overlap(struct skill_unit* su, int flag) {
+int skill_dance_overlap(struct skill_unit* su, int flag)
+{
if (!su || !su->group || !(su->group->state.song_dance&0x1))
return 0;
@@ -11059,7 +11124,8 @@ int skill_dance_overlap(struct skill_unit* su, int flag) {
* @param flag 1 Revert
* @retval true success
**/
-bool skill_dance_switch(struct skill_unit* su, int flag) {
+bool skill_dance_switch(struct skill_unit* su, int flag)
+{
static int prevflag = 1; // by default the backup is empty
static struct skill_unit_group backup;
struct skill_unit_group* group;
@@ -11115,7 +11181,8 @@ bool skill_dance_switch(struct skill_unit* su, int flag) {
* Initializes and sets a ground skill.
* flag&1 is used to determine when the skill 'morphs' (Warp portal becomes active, or Fire Pillar becomes active)
*------------------------------------------*/
-struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_id, uint16 skill_lv, int16 x, int16 y, int flag) {
+struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_id, uint16 skill_lv, int16 x, int16 y, int flag)
+{
struct skill_unit_group *group;
int i,limit,val1=0,val2=0,val3=0;
int target,interval,range,unit_flag,req_item=0;
@@ -11145,6 +11212,7 @@ struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_
sd = BL_CAST(BL_PC, src);
st = status->get_status_data(src);
+ nullpo_retr(NULL, st);
sc = status->get_sc(src); // for traps, firewall and fogwall - celest
switch( skill_id ) {
@@ -11486,6 +11554,7 @@ struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_
break;
}
+ nullpo_retr(NULL, layout);
nullpo_retr(NULL, group=skill->init_unitgroup(src,layout->count,skill_id,skill_lv,skill->get_unit_id(skill_id,flag&1)+subunt, limit, interval));
group->val1=val1;
group->val2=val2;
@@ -11626,10 +11695,15 @@ struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_
return group;
}
-void skill_unitsetting1_unknown(struct block_list *src, uint16 *skill_id, uint16 *skill_lv, int16 *x, int16 *y, int *flag, int *val1, int *val2, int *val3) {
+void skill_unitsetting1_unknown(struct block_list *src, uint16 *skill_id, uint16 *skill_lv, int16 *x, int16 *y, int *flag, int *val1, int *val2, int *val3)
+{
}
-void skill_unitsetting2_unknown(struct block_list *src, uint16 *skill_id, uint16 *skill_lv, int16 *x, int16 *y, int *flag, int *unit_flag, int *val1, int *val2, int *val3, struct skill_unit_group *group) {
+void skill_unitsetting2_unknown(struct block_list *src, uint16 *skill_id, uint16 *skill_lv, int16 *x, int16 *y, int *flag, int *unit_flag, int *val1, int *val2, int *val3, struct skill_unit_group *group)
+{
+ nullpo_retv(group);
+ nullpo_retv(val2);
+ nullpo_retv(unit_flag);
if (group->state.song_dance & 0x1)
*val2 = *unit_flag & (UF_DANCE | UF_SONG); //Store whether this is a song/dance
}
@@ -11637,7 +11711,8 @@ void skill_unitsetting2_unknown(struct block_list *src, uint16 *skill_id, uint16
/*==========================================
*
*------------------------------------------*/
-int skill_unit_onplace(struct skill_unit *src, struct block_list *bl, int64 tick) {
+int skill_unit_onplace(struct skill_unit *src, struct block_list *bl, int64 tick)
+{
struct skill_unit_group *sg;
struct block_list *ss;
struct status_change *sc;
@@ -11889,7 +11964,8 @@ void skill_unit_onplace_unknown(struct skill_unit *src, struct block_list *bl, i
/*==========================================
*
*------------------------------------------*/
-int skill_unit_onplace_timer(struct skill_unit *src, struct block_list *bl, int64 tick) {
+int skill_unit_onplace_timer(struct skill_unit *src, struct block_list *bl, int64 tick)
+{
struct skill_unit_group *sg;
struct block_list *ss;
struct map_session_data *tsd;
@@ -11917,7 +11993,9 @@ int skill_unit_onplace_timer(struct skill_unit *src, struct block_list *bl, int6
return 0;
tstatus = status->get_status_data(bl);
+ nullpo_ret(tstatus);
bst = status->get_base_status(bl);
+ nullpo_ret(bst);
type = status->skill2sc(sg->skill_id);
skill_id = sg->skill_id;
@@ -12664,7 +12742,8 @@ void skill_unit_onplace_timer_unknown(struct skill_unit *src, struct block_list
/*==========================================
* Triggered when a char steps out of a skill cell
*------------------------------------------*/
-int skill_unit_onout(struct skill_unit *src, struct block_list *bl, int64 tick) {
+int skill_unit_onout(struct skill_unit *src, struct block_list *bl, int64 tick)
+{
struct skill_unit_group *sg;
struct status_change *sc;
struct status_change_entry *sce;
@@ -12729,7 +12808,8 @@ int skill_unit_onout(struct skill_unit *src, struct block_list *bl, int64 tick)
/*==========================================
* Triggered when a char steps out of a skill group (entirely) [Skotlex]
*------------------------------------------*/
-int skill_unit_onleft(uint16 skill_id, struct block_list *bl, int64 tick) {
+int skill_unit_onleft(uint16 skill_id, struct block_list *bl, int64 tick)
+{
struct status_change *sc;
struct status_change_entry *sce;
enum sc_type type;
@@ -12814,7 +12894,8 @@ int skill_unit_onleft(uint16 skill_id, struct block_list *bl, int64 tick) {
case PF_FOGWALL:
if (sce) {
status_change_end(bl, type, INVALID_TIMER);
- if ((sce=sc->data[SC_BLIND])) {
+ nullpo_retb(sc);
+ if ((sce = sc->data[SC_BLIND])) {
if (bl->type == BL_PC) //Players get blind ended immediately, others have it still for 30 secs. [Skotlex]
status_change_end(bl, SC_BLIND, INVALID_TIMER);
else {
@@ -12842,14 +12923,19 @@ int skill_unit_onleft(uint16 skill_id, struct block_list *bl, int64 tick) {
* flag&1: Invoke onplace function (otherwise invoke onout)
* flag&4: Invoke a onleft call (the unit might be scheduled for deletion)
*------------------------------------------*/
-int skill_unit_effect(struct block_list* bl, va_list ap) {
+int skill_unit_effect(struct block_list* bl, va_list ap)
+{
struct skill_unit* su = va_arg(ap,struct skill_unit*);
- struct skill_unit_group* group = su->group;
+ struct skill_unit_group* group;
int64 tick = va_arg(ap,int64);
unsigned int flag = va_arg(ap,unsigned int);
uint16 skill_id;
bool dissonance;
+ nullpo_ret(bl);
+ nullpo_ret(su);
+ group = su->group;
+
if( (!su->alive && !(flag&4)) || bl->prev == NULL )
return 0;
@@ -12881,7 +12967,8 @@ int skill_unit_effect(struct block_list* bl, va_list ap) {
/*==========================================
*
*------------------------------------------*/
-int skill_unit_ondamaged(struct skill_unit *src, struct block_list *bl, int64 damage, int64 tick) {
+int skill_unit_ondamaged(struct skill_unit *src, struct block_list *bl, int64 damage, int64 tick)
+{
struct skill_unit_group *sg;
nullpo_ret(src);
@@ -13002,12 +13089,16 @@ int skill_check_condition_char_sub (struct block_list *bl, va_list ap)
/*==========================================
* Checks and stores partners for ensemble skills [Skotlex]
*------------------------------------------*/
-int skill_check_pc_partner (struct map_session_data *sd, uint16 skill_id, uint16* skill_lv, int range, int cast_flag) {
+int skill_check_pc_partner(struct map_session_data *sd, uint16 skill_id, uint16* skill_lv, int range, int cast_flag)
+{
static int c=0;
static int p_sd[2] = { 0, 0 };
int i;
bool is_chorus = ( skill->get_inf2(skill_id)&INF2_CHORUS_SKILL );
+ nullpo_ret(sd);
+ nullpo_ret(skill_lv);
+
if (!battle_config.player_skill_partner_check || pc_has_permission(sd, PC_PERM_SKILL_UNCONDITIONAL))
return is_chorus ? MAX_PARTY : 99; //As if there were infinite partners.
@@ -13084,6 +13175,7 @@ int skill_check_condition_mob_master_sub (struct block_list *bl, va_list ap)
*------------------------------------------*/
int skill_isammotype (struct map_session_data *sd, int skill_id)
{
+ nullpo_ret(sd);
return (
battle_config.arrow_decrement==2 &&
(sd->status.weapon == W_BOW || (sd->status.weapon >= W_REVOLVER && sd->status.weapon <= W_GRENADE)) &&
@@ -13123,7 +13215,8 @@ bool skill_is_combo( int skill_id )
return false;
}
-int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv) {
+int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv)
+{
struct status_data *st;
struct status_change *sc;
struct skill_condition require;
@@ -14089,7 +14182,8 @@ int skill_check_condition_castbegin_unknown(struct status_change *sc, uint16 *sk
return -1;
}
-int skill_check_condition_castend(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv) {
+int skill_check_condition_castend(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv)
+{
struct skill_condition require;
struct status_data *st;
int i;
@@ -14293,12 +14387,14 @@ int skill_check_condition_castend(struct map_session_data* sd, uint16 skill_id,
return 1;
}
-void skill_check_condition_castend_unknown(struct map_session_data* sd, uint16 *skill_id, uint16 *skill_lv) {
+void skill_check_condition_castend_unknown(struct map_session_data* sd, uint16 *skill_id, uint16 *skill_lv)
+{
}
// type&2: consume items (after skill was used)
// type&1: consume the others (before skill was used)
-int skill_consume_requirement( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv, short type) {
+int skill_consume_requirement(struct map_session_data *sd, uint16 skill_id, uint16 skill_lv, short type)
+{
struct skill_condition req;
nullpo_ret(sd);
@@ -14379,7 +14475,8 @@ int skill_consume_requirement( struct map_session_data *sd, uint16 skill_id, uin
return 1;
}
-struct skill_condition skill_get_requirement(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv) {
+struct skill_condition skill_get_requirement(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv)
+{
struct skill_condition req;
struct status_data *st;
struct status_change *sc;
@@ -14724,7 +14821,8 @@ void skill_get_requirement_unknown(struct status_change *sc, struct map_session_
/*==========================================
* Does cast-time reductions based on dex, item bonuses and config setting
*------------------------------------------*/
-int skill_castfix (struct block_list *bl, uint16 skill_id, uint16 skill_lv) {
+int skill_castfix (struct block_list *bl, uint16 skill_id, uint16 skill_lv)
+{
int time = skill->get_cast(skill_id, skill_lv);
nullpo_ret(bl);
@@ -14774,11 +14872,13 @@ int skill_castfix (struct block_list *bl, uint16 skill_id, uint16 skill_lv) {
/*==========================================
* Does cast-time reductions based on sc data.
*------------------------------------------*/
-int skill_castfix_sc (struct block_list *bl, int time) {
+int skill_castfix_sc (struct block_list *bl, int time)
+{
struct status_change *sc = status->get_sc(bl);
if( time < 0 )
return 0;
+ nullpo_ret(bl);
if( bl->type == BL_MOB ) // mobs casttime is fixed nothing to alter.
return time;
@@ -14807,7 +14907,9 @@ int skill_castfix_sc (struct block_list *bl, int time) {
//ShowInfo("Castime castfix_sc = %d\n",time);
return time;
}
-int skill_vfcastfix(struct block_list *bl, double time, uint16 skill_id, uint16 skill_lv) {
+
+int skill_vfcastfix(struct block_list *bl, double time, uint16 skill_id, uint16 skill_lv)
+{
#ifdef RENEWAL_CAST
struct status_change *sc = status->get_sc(bl);
struct map_session_data *sd = BL_CAST(BL_PC,bl);
@@ -14815,6 +14917,7 @@ int skill_vfcastfix(struct block_list *bl, double time, uint16 skill_id, uint16
if( time < 0 )
return 0;
+ nullpo_ret(bl);
if( bl->type == BL_MOB ) // mobs casttime is fixed nothing to alter.
return (int)time;
@@ -14947,7 +15050,8 @@ int skill_vfcastfix(struct block_list *bl, double time, uint16 skill_id, uint16
/*==========================================
* Does delay reductions based on dex/agi, sc data, item bonuses, ...
*------------------------------------------*/
-int skill_delay_fix (struct block_list *bl, uint16 skill_id, uint16 skill_lv) {
+int skill_delay_fix (struct block_list *bl, uint16 skill_id, uint16 skill_lv)
+{
int delaynodex = skill->get_delaynodex(skill_id, skill_lv);
int time = skill->get_delay(skill_id, skill_lv);
struct map_session_data *sd;
@@ -15046,7 +15150,8 @@ struct square {
int val2[5];
};
-void skill_brandishspear_first (struct square *tc, uint8 dir, int16 x, int16 y) {
+void skill_brandishspear_first (struct square *tc, uint8 dir, int16 x, int16 y)
+{
nullpo_retv(tc);
if(dir == 0){
@@ -15141,7 +15246,8 @@ void skill_brandishspear_first (struct square *tc, uint8 dir, int16 x, int16 y)
}
-void skill_brandishspear_dir (struct square* tc, uint8 dir, int are) {
+void skill_brandishspear_dir (struct square* tc, uint8 dir, int are)
+{
int c;
nullpo_retv(tc);
@@ -15159,11 +15265,17 @@ void skill_brandishspear_dir (struct square* tc, uint8 dir, int are) {
}
}
-void skill_brandishspear(struct block_list* src, struct block_list* bl, uint16 skill_id, uint16 skill_lv, int64 tick, int flag) {
+void skill_brandishspear(struct block_list* src, struct block_list* bl, uint16 skill_id, uint16 skill_lv, int64 tick, int flag)
+{
int c,n=4;
- uint8 dir = map->calc_dir(src,bl->x,bl->y);
+ uint8 dir;
struct square tc;
- int x=bl->x,y=bl->y;
+ int x, y;
+
+ nullpo_retv(bl);
+ x = bl->x;
+ y = bl->y;
+ dir = map->calc_dir(src, x, y);
skill->brandishspear_first(&tc,dir,x,y);
skill->brandishspear_dir(&tc,dir,4);
skill->area_temp[1] = bl->id;
@@ -15208,7 +15320,8 @@ void skill_brandishspear(struct block_list* src, struct block_list* bl, uint16 s
/*==========================================
* Weapon Repair [Celest/DracoRPG]
*------------------------------------------*/
-void skill_repairweapon (struct map_session_data *sd, int idx) {
+void skill_repairweapon (struct map_session_data *sd, int idx)
+{
int material;
int materials[4] = {
ITEMID_IRON_ORE,
@@ -15552,10 +15665,12 @@ int skill_frostjoke_scream(struct block_list *bl, va_list ap)
/*==========================================
*
*------------------------------------------*/
-void skill_unitsetmapcell (struct skill_unit *src, uint16 skill_id, uint16 skill_lv, cell_t cell, bool flag) {
+void skill_unitsetmapcell (struct skill_unit *src, uint16 skill_id, uint16 skill_lv, cell_t cell, bool flag)
+{
int range = skill->get_unit_range(skill_id,skill_lv);
int x,y;
+ nullpo_retv(src);
for( y = src->bl.y - range; y <= src->bl.y + range; ++y )
for( x = src->bl.x - range; x <= src->bl.x + range; ++x )
map->list[src->bl.m].setcell(src->bl.m, x, y, cell, flag);
@@ -15564,11 +15679,14 @@ void skill_unitsetmapcell (struct skill_unit *src, uint16 skill_id, uint16 skill
/*==========================================
*
*------------------------------------------*/
-int skill_attack_area(struct block_list *bl, va_list ap) {
+int skill_attack_area(struct block_list *bl, va_list ap)
+{
struct block_list *src,*dsrc;
int atk_type,skill_id,skill_lv,flag,type;
int64 tick;
+ nullpo_ret(bl);
+
if(status->isdead(bl))
return 0;
@@ -15648,7 +15766,8 @@ int skill_clear_group (struct block_list *bl, int flag)
/*==========================================
* Returns the first element field found [Skotlex]
*------------------------------------------*/
-struct skill_unit_group *skill_locate_element_field(struct block_list *bl) {
+struct skill_unit_group *skill_locate_element_field(struct block_list *bl)
+{
struct unit_data *ud = unit->bl2ud(bl);
int i;
nullpo_ret(bl);
@@ -15986,7 +16105,8 @@ int skill_trap_splash(struct block_list *bl, va_list ap)
/*==========================================
*
*------------------------------------------*/
-int skill_enchant_elemental_end (struct block_list *bl, int type) {
+int skill_enchant_elemental_end(struct block_list *bl, int type)
+{
struct status_change *sc;
const enum sc_type scs[] = { SC_ENCHANTPOISON, SC_ASPERSIO, SC_PROPERTYFIRE, SC_PROPERTYWATER, SC_PROPERTYWIND, SC_PROPERTYGROUND, SC_PROPERTYDARK, SC_PROPERTYTELEKINESIS, SC_ENCHANTARMS };
int i;
@@ -16006,6 +16126,7 @@ bool skill_check_cloaking(struct block_list *bl, struct status_change_entry *sce
{
bool wall = true;
+ nullpo_retr(false, bl);
if( (bl->type == BL_PC && battle_config.pc_cloak_check_type&1)
|| (bl->type != BL_PC && battle_config.monster_cloak_check_type&1)
) {
@@ -16040,7 +16161,8 @@ bool skill_check_cloaking(struct block_list *bl, struct status_change_entry *sce
/**
* Verifies if an user can use SC_CLOAKING
**/
-bool skill_can_cloak(struct map_session_data *sd) {
+bool skill_can_cloak(struct map_session_data *sd)
+{
nullpo_retr(false, sd);
//Avoid cloaking with no wall and low skill level. [Skotlex]
@@ -16071,6 +16193,7 @@ bool skill_check_camouflage(struct block_list *bl, struct status_change_entry *s
{
bool wall = true;
+ nullpo_retr(false, bl);
if( bl->type == BL_PC ) { //Check for walls.
static int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1};
static int dy[] = {-1, 0, 1, 0, -1, -1, 1, 1};
@@ -16133,7 +16256,8 @@ bool skill_check_shadowform(struct block_list *bl, int64 damage, int hit)
/*==========================================
*
*------------------------------------------*/
-struct skill_unit *skill_initunit (struct skill_unit_group *group, int idx, int x, int y, int val1, int val2) {
+struct skill_unit *skill_initunit (struct skill_unit_group *group, int idx, int x, int y, int val1, int val2)
+{
struct skill_unit *su;
nullpo_retr(NULL, group);
@@ -16185,7 +16309,8 @@ struct skill_unit *skill_initunit (struct skill_unit_group *group, int idx, int
/*==========================================
*
*------------------------------------------*/
-int skill_delunit (struct skill_unit* su) {
+int skill_delunit (struct skill_unit* su)
+{
struct skill_unit_group *group;
nullpo_ret(su);
@@ -16506,6 +16631,7 @@ struct skill_unit_group_tickset *skill_unitgrouptickset_search(struct block_list
struct skill_unit_group_tickset *set;
nullpo_ret(bl);
+ nullpo_ret(group);
if (group->interval==-1)
return NULL;
@@ -16540,10 +16666,16 @@ struct skill_unit_group_tickset *skill_unitgrouptickset_search(struct block_list
/*==========================================
*
*------------------------------------------*/
-int skill_unit_timer_sub_onplace(struct block_list* bl, va_list ap) {
- struct skill_unit* su = va_arg(ap,struct skill_unit *);
- struct skill_unit_group* group = su->group;
- int64 tick = va_arg(ap,int64);
+int skill_unit_timer_sub_onplace(struct block_list* bl, va_list ap)
+{
+ struct skill_unit* su;
+ struct skill_unit_group* group;
+ int64 tick;
+
+ su = va_arg(ap,struct skill_unit *);
+ nullpo_ret(su);
+ group = su->group;
+ tick = va_arg(ap,int64);
if( !su->alive || bl->prev == NULL )
return 0;
@@ -16566,11 +16698,16 @@ int skill_unit_timer_sub_onplace(struct block_list* bl, va_list ap) {
*/
int skill_unit_timer_sub(union DBKey key, struct DBData *data, va_list ap)
{
- struct skill_unit* su = DB->data2ptr(data);
- struct skill_unit_group* group = su->group;
+ struct skill_unit* su;
+ struct skill_unit_group* group;
int64 tick = va_arg(ap,int64);
bool dissonance;
- struct block_list* bl = &su->bl;
+ struct block_list* bl;
+
+ su = DB->data2ptr(data);
+ nullpo_ret(su);
+ group = su->group;
+ bl = &su->bl;
if( !su->alive )
return 0;
@@ -16778,7 +16915,8 @@ int skill_unit_timer_sub(union DBKey key, struct DBData *data, va_list ap)
/*==========================================
* Executes on all skill units every SKILLUNITTIMER_INTERVAL milliseconds.
*------------------------------------------*/
-int skill_unit_timer(int tid, int64 tick, int id, intptr_t data) {
+int skill_unit_timer(int tid, int64 tick, int id, intptr_t data)
+{
map->freeblock_lock();
skill->unit_db->foreach(skill->unit_db, skill->unit_timer_sub, tick);
@@ -16804,6 +16942,7 @@ int skill_unit_move_sub(struct block_list* bl, va_list ap)
uint16 skill_id;
int i;
+ nullpo_ret(target);
nullpo_ret(bl);
Assert_ret(bl->type == BL_SKILL);
su = BL_UCAST(BL_SKILL, bl);
@@ -16890,7 +17029,8 @@ int skill_unit_move_sub(struct block_list* bl, va_list ap)
* units to figure out when they have left a group.
* flag&4: Force a onleft event (triggered when the bl is killed, for example)
*------------------------------------------*/
-int skill_unit_move(struct block_list *bl, int64 tick, int flag) {
+int skill_unit_move(struct block_list *bl, int64 tick, int flag)
+{
nullpo_ret(bl);
if( bl->prev == NULL )
@@ -16915,7 +17055,8 @@ int skill_unit_move(struct block_list *bl, int64 tick, int flag) {
/*==========================================
*
*------------------------------------------*/
-int skill_unit_move_unit_group(struct skill_unit_group *group, int16 m, int16 dx, int16 dy) {
+int skill_unit_move_unit_group(struct skill_unit_group *group, int16 m, int16 dx, int16 dy)
+{
int i,j;
int64 tick = timer->gettick();
int *m_flag;
@@ -17067,7 +17208,8 @@ int skill_can_produce_mix (struct map_session_data *sd, int nameid, int trigger,
/*==========================================
*
*------------------------------------------*/
-int skill_produce_mix(struct map_session_data *sd, uint16 skill_id, int nameid, int slot1, int slot2, int slot3, int qty) {
+int skill_produce_mix(struct map_session_data *sd, uint16 skill_id, int nameid, int slot1, int slot2, int slot3, int qty)
+{
int slot[3];
int i,sc,ele,idx,equip,wlv,make_per = 0,flag = 0,skill_lv = 0;
int num = -1; // exclude the recipe
@@ -17712,7 +17854,9 @@ int skill_arrow_create (struct map_session_data *sd, int nameid)
return 0;
}
-int skill_poisoningweapon( struct map_session_data *sd, int nameid) {
+
+int skill_poisoningweapon(struct map_session_data *sd, int nameid)
+{
sc_type type;
int chance, i;
nullpo_ret(sd);
@@ -17743,7 +17887,8 @@ int skill_poisoningweapon( struct map_session_data *sd, int nameid) {
return 0;
}
-void skill_toggle_magicpower(struct block_list *bl, uint16 skill_id) {
+void skill_toggle_magicpower(struct block_list *bl, uint16 skill_id)
+{
struct status_change *sc = status->get_sc(bl);
// non-offensive and non-magic skills do not affect the status
@@ -17767,7 +17912,8 @@ void skill_toggle_magicpower(struct block_list *bl, uint16 skill_id) {
}
}
-int skill_magicdecoy(struct map_session_data *sd, int nameid) {
+int skill_magicdecoy(struct map_session_data *sd, int nameid)
+{
int x, y, i, class_ = 0, skill_id;
struct mob_data *md;
nullpo_ret(sd);
@@ -17818,7 +17964,8 @@ int skill_magicdecoy(struct map_session_data *sd, int nameid) {
}
// Warlock Spellbooks. [LimitLine/3CeAM]
-int skill_spellbook (struct map_session_data *sd, int nameid) {
+int skill_spellbook(struct map_session_data *sd, int nameid)
+{
int i, max_preserve, skill_id, point;
struct status_change *sc;
@@ -17866,7 +18013,9 @@ int skill_spellbook (struct map_session_data *sd, int nameid) {
return 1;
}
-int skill_select_menu(struct map_session_data *sd,uint16 skill_id) {
+
+int skill_select_menu(struct map_session_data *sd,uint16 skill_id)
+{
int id, lv, prob, aslvl = 0, idx = 0;
nullpo_ret(sd);
@@ -18012,6 +18161,7 @@ int skill_changematerial(struct map_session_data *sd, const struct itemlist *ite
return 0;
}
+
/**
* for Royal Guard's LG_TRAMPLE
**/
@@ -18047,10 +18197,12 @@ int skill_destroy_trap(struct block_list *bl, va_list ap)
}
return 0;
}
+
/*==========================================
*
*------------------------------------------*/
-int skill_blockpc_end(int tid, int64 tick, int id, intptr_t data) {
+int skill_blockpc_end(int tid, int64 tick, int id, intptr_t data)
+{
struct map_session_data *sd = map->id2sd(id);
struct skill_cd * cd = NULL;
@@ -18102,7 +18254,8 @@ int skill_blockpc_end(int tid, int64 tick, int id, intptr_t data) {
* @param tick the length of time the delay should last
* @return 0 if successful, -1 otherwise
*/
-int skill_blockpc_start_(struct map_session_data *sd, uint16 skill_id, int tick) {
+int skill_blockpc_start_(struct map_session_data *sd, uint16 skill_id, int tick)
+{
struct skill_cd* cd = NULL;
uint16 idx = skill->get_index(skill_id);
int64 now = timer->gettick();
@@ -18197,7 +18350,9 @@ int skill_blockhomun_end(int tid, int64 tick, int id, intptr_t data)
return 1;
}
-int skill_blockhomun_start(struct homun_data *hd, uint16 skill_id, int tick) { // [orn]
+// [orn]
+int skill_blockhomun_start(struct homun_data *hd, uint16 skill_id, int tick)
+{
uint16 idx = skill->get_index(skill_id);
nullpo_retr (-1, hd);
@@ -18239,12 +18394,15 @@ int skill_blockmerc_start(struct mercenary_data *md, uint16 skill_id, int tick)
md->blockskill[idx] = 1;
return timer->add(timer->gettick() + tick, skill->blockmerc_end, md->bl.id, idx);
}
+
/**
* Adds a new skill unit entry for this player to recast after map load
**/
-void skill_usave_add(struct map_session_data * sd, uint16 skill_id, uint16 skill_lv) {
+void skill_usave_add(struct map_session_data * sd, uint16 skill_id, uint16 skill_lv)
+{
struct skill_unit_save * sus = NULL;
+ nullpo_retv(sd);
if( idb_exists(skill->usave_db,sd->status.char_id) ) {
idb_remove(skill->usave_db,sd->status.char_id);
}
@@ -18257,9 +18415,12 @@ void skill_usave_add(struct map_session_data * sd, uint16 skill_id, uint16 skill
return;
}
-void skill_usave_trigger(struct map_session_data *sd) {
+
+void skill_usave_trigger(struct map_session_data *sd)
+{
struct skill_unit_save * sus = NULL;
+ nullpo_retv(sd);
if( ! (sus = idb_get(skill->usave_db,sd->status.char_id)) ) {
return;
}
@@ -18277,6 +18438,8 @@ int skill_split_atoi(char *str, int *val)
{
int i, j, step = 1;
+ nullpo_ret(val);
+
for (i=0; i<MAX_SKILL_LEVEL; i++) {
if (!str) break;
val[i] = atoi(str);
@@ -18595,7 +18758,8 @@ void skill_init_unit_layout_unknown(int skill_idx)
ShowError("unknown unit layout at skill %d\n", skill_idx);
}
-int skill_block_check(struct block_list *bl, sc_type type , uint16 skill_id) {
+int skill_block_check(struct block_list *bl, sc_type type , uint16 skill_id)
+{
int inf = 0;
struct status_change *sc = status->get_sc(bl);
@@ -18742,7 +18906,8 @@ int skill_block_check(struct block_list *bl, sc_type type , uint16 skill_id) {
return 0;
}
-int skill_get_elemental_type( uint16 skill_id , uint16 skill_lv ) {
+int skill_get_elemental_type(uint16 skill_id , uint16 skill_lv)
+{
int type = 0;
switch (skill_id) {
@@ -18761,7 +18926,8 @@ int skill_get_elemental_type( uint16 skill_id , uint16 skill_lv ) {
* update stored skill cooldowns for player logout
* @param sd the affected player structure
*/
-void skill_cooldown_save(struct map_session_data * sd) {
+void skill_cooldown_save(struct map_session_data * sd)
+{
int i;
struct skill_cd* cd = NULL;
int64 now = 0;
@@ -18789,7 +18955,8 @@ void skill_cooldown_save(struct map_session_data * sd) {
* reload stored skill cooldowns when a player logs in.
* @param sd the affected player structure
*/
-void skill_cooldown_load(struct map_session_data * sd) {
+void skill_cooldown_load(struct map_session_data * sd)
+{
int i;
struct skill_cd* cd = NULL;
int64 now = 0;
@@ -18813,11 +18980,14 @@ void skill_cooldown_load(struct map_session_data * sd) {
}
}
-bool skill_parse_row_producedb(char* split[], int columns, int current) {
+bool skill_parse_row_producedb(char* split[], int columns, int current)
+{
// ProduceItemID,ItemLV,RequireSkill,Requireskill_lv,MaterialID1,MaterialAmount1,......
int x,y;
+ int i;
- int i = atoi(split[0]);
+ nullpo_retr(false, split);
+ i = atoi(split[0]);
if( !i )
return false;
@@ -18834,11 +19004,14 @@ bool skill_parse_row_producedb(char* split[], int columns, int current) {
return true;
}
-bool skill_parse_row_createarrowdb(char* split[], int columns, int current) {
+bool skill_parse_row_createarrowdb(char* split[], int columns, int current)
+{
// SourceID,MakeID1,MakeAmount1,...,MakeID5,MakeAmount5
int x,y;
- int i = atoi(split[0]);
+ int i;
+ nullpo_retr(false, split);
+ i = atoi(split[0]);
if( !i )
return false;
@@ -18851,12 +19024,19 @@ bool skill_parse_row_createarrowdb(char* split[], int columns, int current) {
return true;
}
-bool skill_parse_row_spellbookdb(char* split[], int columns, int current) {
+
+bool skill_parse_row_spellbookdb(char* split[], int columns, int current)
+{
// skill_id,PreservePoints
- uint16 skill_id = atoi(split[0]);
- int points = atoi(split[1]);
- int nameid = atoi(split[2]);
+ uint16 skill_id;
+ int points;
+ int nameid;
+
+ nullpo_retr(false, split);
+ skill_id = atoi(split[0]);
+ points = atoi(split[1]);
+ nameid = atoi(split[2]);
if( !skill->get_index(skill_id) || !skill->get_max(skill_id) )
ShowError("spellbook_db: Invalid skill ID %d\n", skill_id);
@@ -18874,10 +19054,16 @@ bool skill_parse_row_spellbookdb(char* split[], int columns, int current) {
return false;
}
-bool skill_parse_row_improvisedb(char* split[], int columns, int current) {
+
+bool skill_parse_row_improvisedb(char* split[], int columns, int current)
+{
// SkillID,Rate
- uint16 skill_id = atoi(split[0]);
- short j = atoi(split[1]);
+ uint16 skill_id;
+ short j;
+
+ nullpo_retr(false, split);
+ skill_id = atoi(split[0]);
+ j = atoi(split[1]);
if( !skill->get_index(skill_id) || !skill->get_max(skill_id) ) {
ShowError("skill_improvise_db: Invalid skill ID %d\n", skill_id);
@@ -18900,10 +19086,14 @@ bool skill_parse_row_improvisedb(char* split[], int columns, int current) {
return true;
}
-bool skill_parse_row_magicmushroomdb(char* split[], int column, int current) {
+
+bool skill_parse_row_magicmushroomdb(char* split[], int column, int current)
+{
// SkillID
- uint16 skill_id = atoi(split[0]);
+ uint16 skill_id;
+ nullpo_retr(false, split);
+ skill_id = atoi(split[0]);
if( !skill->get_index(skill_id) || !skill->get_max(skill_id) ) {
ShowError("magicmushroom_db: Invalid skill ID %d\n", skill_id);
return false;
@@ -18918,9 +19108,13 @@ bool skill_parse_row_magicmushroomdb(char* split[], int column, int current) {
return true;
}
-bool skill_parse_row_reproducedb(char* split[], int column, int current) {
- uint16 skill_id = atoi(split[0]);
- uint16 idx = skill->get_index(skill_id);
+bool skill_parse_row_reproducedb(char* split[], int column, int current)
+{
+ uint16 skill_id;
+ uint16 idx;
+ nullpo_retr(false, split);
+ skill_id = atoi(split[0]);
+ idx = skill->get_index(skill_id);
if( !idx )
return false;
@@ -18929,9 +19123,12 @@ bool skill_parse_row_reproducedb(char* split[], int column, int current) {
return true;
}
-bool skill_parse_row_abradb(char* split[], int columns, int current) {
+bool skill_parse_row_abradb(char* split[], int columns, int current)
+{
// skill_id,DummyName,RequiredHocusPocusLevel,Rate
- uint16 skill_id = atoi(split[0]);
+ uint16 skill_id;
+ nullpo_retr(false, split);
+ skill_id = atoi(split[0]);
if( !skill->get_index(skill_id) || !skill->get_max(skill_id) ) {
ShowError("abra_db: Invalid skill ID %d\n", skill_id);
return false;
@@ -18948,12 +19145,16 @@ bool skill_parse_row_abradb(char* split[], int columns, int current) {
return true;
}
-bool skill_parse_row_changematerialdb(char* split[], int columns, int current) {
+bool skill_parse_row_changematerialdb(char* split[], int columns, int current)
+{
// ProductID,BaseRate,MakeAmount1,MakeAmountRate1...,MakeAmount5,MakeAmountRate5
- uint16 skill_id = atoi(split[0]);
- short j = atoi(split[1]);
+ uint16 skill_id;
+ short j;
int x,y;
+ nullpo_retr(false, split);
+ skill_id = atoi(split[0]);
+ j = atoi(split[1]);
for(x=0; x<MAX_SKILL_PRODUCE_DB; x++){
if( skill->dbs->produce_db[x].nameid == skill_id )
if( skill->dbs->produce_db[x].req_skill == GN_CHANGEMATERIAL )
@@ -18993,6 +19194,7 @@ void skill_config_set_level(struct config_setting_t *conf, int *arr)
{
int i=0;
+ nullpo_retv(arr);
if (config_setting_is_group(conf)) {
for (i=0; i<MAX_SKILL_LEVEL; i++) {
char level[6]; // enough to contain "Lv100" in case of custom MAX_SKILL_LEVEL
@@ -19020,7 +19222,8 @@ void skill_config_set_level(struct config_setting_t *conf, int *arr)
void skill_level_set_value(int *arr, int value)
{
int i=0;
-
+
+ nullpo_retv(arr);
for(i=0; i<MAX_SKILL_LEVEL; i++) {
arr[i] = value;
}
@@ -19030,6 +19233,7 @@ void skill_validate_hittype(struct config_setting_t *conf, struct s_skill_db *sk
{
const char *type = NULL;
+ nullpo_retv(sk);
if (libconfig->setting_lookup_string(conf, "Hit", &type)) {
if (strcmpi(type, "BDT_SKILL") == 0) {
sk->hit = BDT_SKILL;
@@ -19054,6 +19258,7 @@ void skill_validate_skilltype(struct config_setting_t *conf, struct s_skill_db *
{
struct config_setting_t *t = NULL, *tt = NULL;
+ nullpo_retv(sk);
if((t=libconfig->setting_get_member(conf, "SkillType")) && config_setting_is_group(t)) {
int j=0;
while ((tt = libconfig->setting_get_elem(t, j++))) {
@@ -19107,6 +19312,7 @@ void skill_validate_skillinfo(struct config_setting_t *conf, struct s_skill_db *
{
struct config_setting_t *t = NULL, *tt = NULL;
+ nullpo_retv(sk);
if ((t=libconfig->setting_get_member(conf, "SkillInfo")) && config_setting_is_group(t)) {
int j=0;
while ((tt = libconfig->setting_get_elem(t, j++))) {
@@ -19232,6 +19438,7 @@ void skill_validate_attacktype(struct config_setting_t *conf, struct s_skill_db
{
const char *type = NULL;
+ nullpo_retv(sk);
if (libconfig->setting_lookup_string(conf, "AttackType", &type)) {
if (!strcmpi(type, "Weapon")) {
sk->skill_type = BF_WEAPON;
@@ -19257,6 +19464,7 @@ void skill_validate_element(struct config_setting_t *conf, struct s_skill_db *sk
const char *type = NULL;
struct config_setting_t *t = NULL;
+ nullpo_retv(sk);
if ((t=libconfig->setting_get_member(conf, "Element")) && config_setting_is_group(t)) {
int j = 0;
char lv[6]; // enough to contain "Lv100" in case of custom MAX_SKILL_LEVEL
@@ -19303,6 +19511,7 @@ void skill_validate_damagetype(struct config_setting_t *conf, struct s_skill_db
{
struct config_setting_t *t = NULL, *tt = NULL;
+ nullpo_retv(sk);
if ((t=libconfig->setting_get_member(conf, "DamageType")) && config_setting_is_group(t)) {
int j=0;
while ((tt = libconfig->setting_get_elem(t, j++))) {
@@ -19375,6 +19584,7 @@ void skill_validate_castnodex(struct config_setting_t *conf, struct s_skill_db *
{
struct config_setting_t *t = NULL, *tt = NULL;
+ nullpo_retv(sk);
if ((t=libconfig->setting_get_member(conf, delay?"SkillDelayOptions":"CastTimeOptions")) && config_setting_is_group(t)) {
int j = 0, tmpopt = 0;
while ((tt = libconfig->setting_get_elem(t, j++)) && j < 4) {
@@ -19419,6 +19629,7 @@ void skill_validate_castnodex(struct config_setting_t *conf, struct s_skill_db *
*/
int skill_validate_weapontype_sub(const char *type, bool on, struct s_skill_db *sk)
{
+ nullpo_ret(sk);
if (strcmpi(type, "NoWeapon") == 0) {
if (on) {
sk->weapon |= 1<<W_FIST;
@@ -19624,6 +19835,7 @@ void skill_validate_weapontype(struct config_setting_t *conf, struct s_skill_db
struct config_setting_t *tt = NULL;
const char *type = NULL;
+ nullpo_retv(sk);
if ((tt = libconfig->setting_get_member(conf, "WeaponTypes")) && config_setting_is_group(tt)) {
int j = 0;
struct config_setting_t *wpt = NULL;
@@ -19647,6 +19859,7 @@ void skill_validate_weapontype(struct config_setting_t *conf, struct s_skill_db
*/
int skill_validate_ammotype_sub(const char *type, bool on, struct s_skill_db *sk)
{
+ nullpo_ret(sk);
if (strcmpi(type, "A_ARROW") == 0) {
if (on) {
sk->ammo |= 1<<A_ARROW;
@@ -19726,6 +19939,7 @@ void skill_validate_ammotype(struct config_setting_t *conf, struct s_skill_db *s
struct config_setting_t *tt = NULL;
const char *tstr = NULL;
+ nullpo_retv(sk);
if ((tt = libconfig->setting_get_member(conf, "AmmoTypes")) && config_setting_is_group(tt)) {
int j = 0;
struct config_setting_t *amt = { 0 };
@@ -19750,6 +19964,7 @@ void skill_validate_state(struct config_setting_t *conf, struct s_skill_db *sk)
{
const char *type = NULL;
+ nullpo_retv(sk);
if (libconfig->setting_lookup_string(conf, "State", &type) && strcmpi(type,"None") != ST_NONE) {
if ( strcmpi(type,"Hiding") == 0 ) sk->state = ST_HIDING;
else if (strcmpi(type,"Cloaking") == 0 ) sk->state = ST_CLOAKING;
@@ -19790,6 +20005,7 @@ void skill_validate_item_requirements(struct config_setting_t *conf, struct s_sk
{
struct config_setting_t *tt = NULL;
+ nullpo_retv(sk);
if ((tt=libconfig->setting_get_member(conf, "Items")) && config_setting_is_group(conf)) {
int itx=-1;
struct config_setting_t *it;
@@ -19826,6 +20042,7 @@ void skill_validate_unit_target(struct config_setting_t *conf, struct s_skill_db
{
const char *type = NULL;
+ nullpo_retv(sk);
if(libconfig->setting_lookup_string(conf, "Target", &type)) {
if(!strcmpi(type,"NotEnemy")) sk->unit_target = BCT_NOENEMY;
@@ -19865,6 +20082,8 @@ void skill_validate_unit_target(struct config_setting_t *conf, struct s_skill_db
*/
int skill_validate_unit_flag_sub(const char *type, bool on, struct s_skill_db *sk)
{
+ nullpo_ret(type);
+ nullpo_ret(sk);
if (strcmpi(type, "UF_DEFNOTENEMY") == 0) {
if (on) {
sk->unit_flag |= UF_DEFNOTENEMY;
@@ -19961,6 +20180,7 @@ void skill_validate_unit_flag(struct config_setting_t *conf, struct s_skill_db *
{
struct config_setting_t *t = NULL;
+ nullpo_retv(sk);
if ((t=libconfig->setting_get_member(conf, "Flag")) && config_setting_is_group(t)) {
int j=0;
struct config_setting_t *tt = NULL;
@@ -19992,8 +20212,10 @@ void skill_validate_additional_fields(struct config_setting_t *conf, struct s_sk
*/
bool skill_validate_skilldb(struct s_skill_db *sk, const char *source)
{
- int idx = skill->get_index(sk->nameid);
+ int idx;
+ nullpo_retr(false, sk);
+ idx = skill->get_index(sk->nameid);
if (idx == 0) {
ShowWarning("skill_validate_skilldb: Invalid skill Id %d provided in '%s'! ... skipping\n", sk->nameid, source);
ShowInfo("It is possible that the skill Id is 0 or unavailable (interferes with guild/homun/mercenary skill mapping).\n");
@@ -20276,7 +20498,8 @@ bool skill_read_skilldb(const char *filename)
* create_arrow_db.txt
* abra_db.txt
*------------------------------*/
-void skill_readdb(bool minimal) {
+void skill_readdb(bool minimal)
+{
// init skill db structures
db_clear(skill->name2id_db);
@@ -20348,7 +20571,8 @@ void skill_reload(void)
/*==========================================
*
*------------------------------------------*/
-int do_init_skill(bool minimal) {
+int do_init_skill(bool minimal)
+{
skill->name2id_db = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, MAX_SKILL_NAME_LENGTH);
skill->read_db(minimal);
@@ -20381,7 +20605,8 @@ int do_init_skill(bool minimal) {
return 0;
}
-int do_final_skill(void) {
+int do_final_skill(void)
+{
db_destroy(skill->name2id_db);
db_destroy(skill->group_db);
db_destroy(skill->unit_db);
@@ -20394,8 +20619,10 @@ int do_final_skill(void) {
ers_destroy(skill->cd_entry_ers);
return 0;
}
+
/* initialize the interface */
-void skill_defaults(void) {
+void skill_defaults(void)
+{
const int skill_enchant_eff[5] = { 10, 14, 17, 19, 20 };
const int skill_deluge_eff[5] = { 5, 9, 12, 14, 15 };
diff --git a/src/map/status.c b/src/map/status.c
index 6f084e9ab..f10f5fd9f 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -70,7 +70,8 @@ struct status_interface *status;
* @param skill The skill to look up
* @return The status registered for this skill
**/
-sc_type status_skill2sc(int skill_id) {
+sc_type status_skill2sc(int skill_id)
+{
int idx;
if( (idx = skill->get_index(skill_id)) == 0 ) {
ShowError("status_skill2sc: Unsupported skill id %d\n", skill_id);
@@ -147,7 +148,8 @@ void status_set_sc(uint16 skill_id, sc_type sc, int icon, unsigned int flag)
status->dbs->Skill2SCTable[idx] = sc;
}
-void initChangeTables(void) {
+void initChangeTables(void)
+{
#define add_sc(skill,sc) status->set_sc((skill),(sc),SI_BLANK,SCB_NONE)
// indicates that the status displays a visual effect for the affected unit, and should be sent to the client for all supported units
#define set_sc_with_vfx(skill, sc, icon, flag) do { status->set_sc((skill), (sc), (icon), (flag)); if((icon) < SI_MAX) status->dbs->RelevantBLTypes[(icon)] |= BL_SCEFFECT; } while(0)
@@ -1200,13 +1202,16 @@ void initDummyData(void)
//For copying a status_data structure from b to a, without overwriting current Hp and Sp
void status_copy(struct status_data *a, const struct status_data *b)
{
+ nullpo_retv(a);
+ nullpo_retv(b);
memcpy((void*)&a->max_hp, (const void*)&b->max_hp, sizeof(struct status_data)-(sizeof(a->hp)+sizeof(a->sp)));
}
//Sets HP to given value. Flag is the flag passed to status->heal in case
//final value is higher than current (use 2 to make a healing effect display
//on players) It will always succeed (overrides Berserk block), but it can't kill.
-int status_set_hp(struct block_list *bl, unsigned int hp, int flag) {
+int status_set_hp(struct block_list *bl, unsigned int hp, int flag)
+{
struct status_data *st;
if (hp < 1) return 0;
st = status->get_status_data(bl);
@@ -1223,7 +1228,8 @@ int status_set_hp(struct block_list *bl, unsigned int hp, int flag) {
//Sets SP to given value. Flag is the flag passed to status->heal in case
//final value is higher than current (use 2 to make a healing effect display
//on players)
-int status_set_sp(struct block_list *bl, unsigned int sp, int flag) {
+int status_set_sp(struct block_list *bl, unsigned int sp, int flag)
+{
struct status_data *st;
st = status->get_status_data(bl);
@@ -1237,7 +1243,9 @@ int status_set_sp(struct block_list *bl, unsigned int sp, int flag) {
return status_zap(bl, 0, st->sp - sp);
}
-int status_charge(struct block_list* bl, int64 hp, int64 sp) {
+int status_charge(struct block_list* bl, int64 hp, int64 sp)
+{
+ nullpo_retr((int)(hp + sp), bl);
if(!(bl->type&BL_CONSUME))
return (int)(hp+sp); //Assume all was charged so there are no 'not enough' fails.
return status->damage(NULL, bl, hp, sp, 0, 3);
@@ -1248,11 +1256,13 @@ int status_charge(struct block_list* bl, int64 hp, int64 sp) {
//If flag&2, fail if target does not has enough to subtract.
//If flag&4, if killed, mob must not give exp/loot.
//flag will be set to &8 when damaging sp of a dead character
-int status_damage(struct block_list *src,struct block_list *target,int64 in_hp, int64 in_sp, int walkdelay, int flag) {
+int status_damage(struct block_list *src,struct block_list *target,int64 in_hp, int64 in_sp, int walkdelay, int flag)
+{
struct status_data *st;
struct status_change *sc;
int hp,sp;
+ nullpo_ret(target);
/* From here onwards, we consider it a 32-type as the client does not support higher and the value doesn't get through percentage modifiers */
hp = (int)cap_value(in_hp,INT_MIN,INT_MAX);
sp = (int)cap_value(in_sp,INT_MIN,INT_MAX);
@@ -1485,11 +1495,13 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp,
//Heals a character. If flag&1, this is forced healing (otherwise stuff like Berserk can block it)
//If flag&2, when the player is healed, show the HP/SP heal effect.
-int status_heal(struct block_list *bl,int64 in_hp,int64 in_sp, int flag) {
+int status_heal(struct block_list *bl, int64 in_hp, int64 in_sp, int flag)
+{
struct status_data *st;
struct status_change *sc;
int hp,sp;
+ nullpo_ret(bl);
st = status->get_status_data(bl);
if (st == &status->dummy || !st->hp)
@@ -1563,7 +1575,8 @@ int status_heal(struct block_list *bl,int64 in_hp,int64 in_sp, int flag) {
//If rates are < 0, percent is of max HP/SP
//If !flag, this is heal, otherwise it is damage.
//Furthermore, if flag==2, then the target must not die from the subtraction.
-int status_percent_change(struct block_list *src,struct block_list *target,signed char hp_rate, signed char sp_rate, int flag) {
+int status_percent_change(struct block_list *src, struct block_list *target, signed char hp_rate, signed char sp_rate, int flag)
+{
struct status_data *st;
unsigned int hp = 0, sp = 0;
@@ -1615,9 +1628,12 @@ int status_percent_change(struct block_list *src,struct block_list *target,signe
return status->heal(target, hp, sp, 0);
}
-int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per_sp) {
+int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per_sp)
+{
struct status_data *st;
unsigned int hp, sp;
+
+ nullpo_ret(bl);
if (!status->isdead(bl)) return 0;
st = status->get_status_data(bl);
@@ -1651,11 +1667,13 @@ int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per
return 1;
}
-int status_fixed_revive(struct block_list *bl, unsigned int per_hp, unsigned int per_sp) {
+int status_fixed_revive(struct block_list *bl, unsigned int per_hp, unsigned int per_sp)
+{
struct status_data *st;
unsigned int hp, sp;
if (!status->isdead(bl)) return 0;
+ nullpo_ret(bl);
st = status->get_status_data(bl);
if (st == &status->dummy)
return 0; //Invalid target.
@@ -1697,7 +1715,8 @@ int status_fixed_revive(struct block_list *bl, unsigned int per_hp, unsigned int
* target MAY Be null, in which case the checks are only to see
* whether the source can cast or not the skill on the ground.
*------------------------------------------*/
-int status_check_skilluse(struct block_list *src, struct block_list *target, uint16 skill_id, int flag) {
+int status_check_skilluse(struct block_list *src, struct block_list *target, uint16 skill_id, int flag)
+{
struct status_data *st;
struct status_change *sc=NULL, *tsc;
int hide_flag;
@@ -1983,12 +2002,14 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin
//Skotlex: Calculates the initial status for the given mob
//first will only be false when the mob leveled up or got a GuardUp level.
-int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) {
+int status_calc_mob_(struct mob_data *md, enum e_status_calc_opt opt)
+{
struct status_data *mstatus;
struct block_list *mbl = NULL;
int flag=0;
int guardup_lv = 0;
+ nullpo_retr(1, md);
if(opt&SCO_FIRST) { //Set basic level on respawn.
if (md->level > 0 && md->level <= MAX_LEVEL && md->level != md->db->lv)
;
@@ -2216,8 +2237,11 @@ int status_calc_pet_(struct pet_data *pd, enum e_status_calc_opt opt)
unsigned int status_get_base_maxsp(const struct map_session_data *sd, const struct status_data *st)
{
- uint64 val = pc->class2idx(sd->status.class_);
+ uint64 val;
+ nullpo_ret(sd);
+ nullpo_ret(st);
+ val = pc->class2idx(sd->status.class_);
val = status->dbs->SP_table[val][sd->status.base_level];
if ( sd->class_&JOBL_UPPER )
@@ -2234,8 +2258,11 @@ unsigned int status_get_base_maxsp(const struct map_session_data *sd, const stru
unsigned int status_get_base_maxhp(const struct map_session_data *sd, const struct status_data *st)
{
- uint64 val = pc->class2idx(sd->status.class_);
+ uint64 val;
+ nullpo_ret(sd);
+ nullpo_ret(st);
+ val = pc->class2idx(sd->status.class_);
val = status->dbs->HP_table[val][sd->status.base_level];
if ( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_level >= 99 )
@@ -2256,22 +2283,26 @@ unsigned int status_get_base_maxhp(const struct map_session_data *sd, const stru
return (unsigned int)cap_value(val,0,UINT_MAX);
}
-void status_calc_pc_additional(struct map_session_data* sd, enum e_status_calc_opt opt) {
+void status_calc_pc_additional(struct map_session_data* sd, enum e_status_calc_opt opt)
+{
/* Just used for Plugin to give bonuses. */
return;
}
//Calculates player data from scratch without counting SC adjustments.
//Should be invoked whenever players raise stats, learn passive skills or change equipment.
-int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
+int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt)
+{
static int calculating = 0; //Check for recursive call preemption. [Skotlex]
struct status_data *bstatus; // pointer to the player's base status
- const struct status_change *sc = &sd->sc;
+ const struct status_change *sc;
struct s_skill b_skill[MAX_SKILL]; // previous skill tree
int b_weight, b_max_weight, b_cart_weight_max, // previous weight
i, k, index, skill_lv,refinedef=0;
int64 i64;
+ nullpo_retr(-1, sd);
+ sc = &sd->sc;
if (++calculating > 10) //Too many recursive calls!
return -1;
@@ -3144,10 +3175,14 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
return 0;
}
-int status_calc_mercenary_(struct mercenary_data *md, enum e_status_calc_opt opt) {
- struct status_data *mstatus = &md->base_status;
- struct s_mercenary *merc = &md->mercenary;
+int status_calc_mercenary_(struct mercenary_data *md, enum e_status_calc_opt opt)
+{
+ struct status_data *mstatus;
+ struct s_mercenary *merc;
+ nullpo_ret(md);
+ mstatus = &md->base_status;
+ merc = &md->mercenary;
if( opt&SCO_FIRST ) {
memcpy(mstatus, &md->db->status, sizeof(struct status_data));
mstatus->mode = MD_CANMOVE|MD_CANATTACK;
@@ -3163,12 +3198,17 @@ int status_calc_mercenary_(struct mercenary_data *md, enum e_status_calc_opt opt
return 0;
}
-int status_calc_elemental_(struct elemental_data *ed, enum e_status_calc_opt opt) {
- struct status_data *estatus = &ed->base_status;
- struct s_elemental *ele = &ed->elemental;
- struct map_session_data *sd = ed->master;
+int status_calc_elemental_(struct elemental_data *ed, enum e_status_calc_opt opt)
+{
+ struct status_data *estatus;
+ struct s_elemental *ele;
+ struct map_session_data *sd;
- if ( !sd )
+ nullpo_ret(ed);
+ estatus = &ed->base_status;
+ ele = &ed->elemental;
+ sd = ed->master;
+ if (sd == NULL)
return 0;
if ( opt&SCO_FIRST ) {
@@ -3202,7 +3242,8 @@ int status_calc_elemental_(struct elemental_data *ed, enum e_status_calc_opt opt
return 0;
}
-int status_calc_npc_(struct npc_data *nd, enum e_status_calc_opt opt) {
+int status_calc_npc_(struct npc_data *nd, enum e_status_calc_opt opt)
+{
struct status_data *nstatus;
if (!nd)
@@ -3238,12 +3279,16 @@ int status_calc_npc_(struct npc_data *nd, enum e_status_calc_opt opt) {
return 0;
}
-int status_calc_homunculus_(struct homun_data *hd, enum e_status_calc_opt opt) {
- struct status_data *hstatus = &hd->base_status;
- struct s_homunculus *hom = &hd->homunculus;
+int status_calc_homunculus_(struct homun_data *hd, enum e_status_calc_opt opt)
+{
+ struct status_data *hstatus;
+ struct s_homunculus *hom;
int skill_lv;
int amotion;
+ nullpo_retr(1, hd);
+ hstatus = &hd->base_status;
+ hom = &hd->homunculus;
hstatus->str = hom->str / 10;
hstatus->agi = hom->agi / 10;
hstatus->vit = hom->vit / 10;
@@ -3324,7 +3369,8 @@ int status_calc_homunculus_(struct homun_data *hd, enum e_status_calc_opt opt) {
}
//Calculates base regen values.
-void status_calc_regen(struct block_list *bl, struct status_data *st, struct regen_data *regen) {
+void status_calc_regen(struct block_list *bl, struct status_data *st, struct regen_data *regen)
+{
struct map_session_data *sd;
int val, skill_lv, reg_flag;
nullpo_retv(bl);
@@ -3426,6 +3472,7 @@ void status_calc_regen(struct block_list *bl, struct status_data *st, struct reg
//Calculates SC related regen rates.
void status_calc_regen_rate(struct block_list *bl, struct regen_data *regen, struct status_change *sc)
{
+ nullpo_retv(bl);
if (!(bl->type&BL_REGEN) || !regen)
return;
@@ -3543,13 +3590,16 @@ void status_calc_regen_rate(struct block_list *bl, struct regen_data *regen, str
/// Recalculates parts of an object's battle status according to the specified flags.
/// @param flag bitfield of values from enum scb_flag
-void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
+void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag)
+{
const struct status_data *bst = status->get_base_status(bl);
struct status_data *st = status->get_status_data(bl);
struct status_change *sc = status->get_sc(bl);
struct map_session_data *sd = BL_CAST(BL_PC,bl);
int temp;
+ nullpo_retv(bl);
+
if (!bst || !st)
return;
@@ -3816,10 +3866,10 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
if(flag&SCB_MAXSP) {
if( bl->type&BL_PC ) {
st->max_sp = status->get_base_maxsp(sd,st);
- if (sd)
+ if (sd != NULL) {
st->max_sp += bst->max_sp - sd->status.max_sp;
-
- st->max_sp = status->calc_maxsp(&sd->bl, &sd->sc, st->max_sp);
+ st->max_sp = status->calc_maxsp(&sd->bl, &sd->sc, st->max_sp);
+ }
if( st->max_sp > (unsigned int)battle_config.max_sp )
st->max_sp = (unsigned int)battle_config.max_sp;
@@ -3898,10 +3948,17 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
}
#ifdef RENEWAL_ASPD
amotion += (max(0xc3 - amotion, 2) * (st->aspd_rate2 + status->calc_aspd(bl, sc, 2))) / 100;
- amotion = 10 * (200 - amotion) + sd->bonus.aspd_add;
+ amotion = 10 * (200 - amotion);
+ if (sd != NULL) {
+ amotion += sd->bonus.aspd_add;
+ }
#endif
amotion = status->calc_fix_aspd(bl, sc, amotion);
- st->amotion = cap_value(amotion, ((sd->class_&JOBL_THIRD) ? battle_config.max_third_aspd : battle_config.max_aspd), 2000);
+ if (sd != NULL) {
+ st->amotion = cap_value(amotion, ((sd->class_&JOBL_THIRD) ? battle_config.max_third_aspd : battle_config.max_aspd), 2000);
+ } else {
+ st->amotion = cap_value(amotion, battle_config.max_aspd, 2000);
+ }
st->adelay = 2 * st->amotion;
} else { // mercenary and mobs
@@ -3925,6 +3982,7 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
if(flag&SCB_REGEN && bl->type&BL_REGEN)
status->calc_regen_rate(bl, status->get_regen_data(bl), sc);
}
+
/// Recalculates parts of an object's base status and battle status according to the specified flags.
/// Also sends updates to the client wherever applicable.
/// @param flag bitfield of values from enum scb_flag
@@ -3934,6 +3992,7 @@ void status_calc_bl_(struct block_list *bl, enum scb_flag flag, enum e_status_ca
struct status_data bst; // previous battle status
struct status_data *st; // pointer to current battle status
+ nullpo_retv(bl);
if (bl->type == BL_PC) {
struct map_session_data *sd = BL_UCAST(BL_PC, bl);
if (sd->delayed_damage != 0) {
@@ -4111,11 +4170,16 @@ void status_calc_bl_(struct block_list *bl, enum scb_flag flag, enum e_status_ca
clif->mercenary_updatestatus(ed->master, SP_SP);
}
}
+
//Checks whether the source can see and chase target.
-int status_check_visibility(struct block_list *src, struct block_list *target) {
+int status_check_visibility(struct block_list *src, struct block_list *target)
+{
int view_range;
struct status_change *tsc = NULL;
+ nullpo_ret(src);
+ nullpo_ret(target);
+
switch ( src->type ) {
case BL_MOB:
view_range = BL_UCCAST(BL_MOB, src)->min_chase;
@@ -4160,11 +4224,16 @@ int status_check_visibility(struct block_list *src, struct block_list *target) {
}
// Basic ASPD value
-int status_base_amotion_pc(struct map_session_data *sd, struct status_data *st) {
+int status_base_amotion_pc(struct map_session_data *sd, struct status_data *st)
+{
int amotion;
#ifdef RENEWAL_ASPD /* [malufett/Hercules] */
float temp;
int skill_lv, val = 0;
+
+ nullpo_ret(sd);
+ nullpo_ret(st);
+
amotion = status->dbs->aspd_base[pc->class2idx(sd->status.class_)][sd->weapontype1];
if ( sd->status.weapon > MAX_SINGLE_WEAPON_TYPE)
amotion += status->dbs->aspd_base[pc->class2idx(sd->status.class_)][sd->weapontype2] / 4;
@@ -4210,9 +4279,12 @@ int status_base_amotion_pc(struct map_session_data *sd, struct status_data *st)
return amotion;
}
-unsigned short status_base_atk(const struct block_list *bl, const struct status_data *st) {
+unsigned short status_base_atk(const struct block_list *bl, const struct status_data *st)
+{
int flag = 0, str, dex, dstr;
+ nullpo_ret(bl);
+ nullpo_ret(st);
if ( !(bl->type&battle_config.enable_baseatk) )
return 0;
@@ -4269,16 +4341,21 @@ unsigned short status_base_atk(const struct block_list *bl, const struct status_
unsigned short status_base_matk_min(const struct status_data *st)
{
- return st->int_ + (st->int_ / 7) * (st->int_ / 7);
+ nullpo_ret(st);
+ return st->int_ + (st->int_ / 7) * (st->int_ / 7);
}
unsigned short status_base_matk_max(const struct status_data *st)
{
- return st->int_ + (st->int_ / 5)*(st->int_ / 5);
+ nullpo_ret(st);
+ return st->int_ + (st->int_ / 5)*(st->int_ / 5);
}
-unsigned short status_base_matk(struct block_list *bl, const struct status_data *st, int level) {
+unsigned short status_base_matk(struct block_list *bl, const struct status_data *st, int level)
+{
#ifdef RENEWAL
+ nullpo_ret(bl);
+ nullpo_ret(st);
switch ( bl->type ) {
case BL_MOB:
return st->int_ + level;
@@ -4296,7 +4373,10 @@ unsigned short status_base_matk(struct block_list *bl, const struct status_data
}
//Fills in the misc data that can be calculated from the other status info (except for level)
-void status_calc_misc(struct block_list *bl, struct status_data *st, int level) {
+void status_calc_misc(struct block_list *bl, struct status_data *st, int level)
+{
+ nullpo_retv(bl);
+ nullpo_retv(st);
//Non players get the value set, players need to stack with previous bonuses.
if ( bl->type != BL_PC )
st->batk =
@@ -4553,6 +4633,7 @@ unsigned short status_calc_vit(struct block_list *bl, struct status_change *sc,
unsigned short status_calc_int(struct block_list *bl, struct status_change *sc, int int_)
{
+ nullpo_ret(bl);
if(!sc || !sc->count)
return cap_value(int_,0,USHRT_MAX);
@@ -4619,6 +4700,7 @@ unsigned short status_calc_int(struct block_list *bl, struct status_change *sc,
unsigned short status_calc_dex(struct block_list *bl, struct status_change *sc, int dex)
{
+ nullpo_ret(bl);
if(!sc || !sc->count)
return cap_value(dex,0,USHRT_MAX);
@@ -4679,7 +4761,9 @@ unsigned short status_calc_dex(struct block_list *bl, struct status_change *sc,
return (unsigned short)cap_value(dex,0,USHRT_MAX);
}
-unsigned short status_calc_luk(struct block_list *bl, struct status_change *sc, int luk) {
+unsigned short status_calc_luk(struct block_list *bl, struct status_change *sc, int luk)
+{
+ nullpo_ret(bl);
if (!sc || !sc->count)
return cap_value(luk, 0, USHRT_MAX);
@@ -4731,8 +4815,10 @@ unsigned short status_calc_luk(struct block_list *bl, struct status_change *sc,
return (unsigned short)cap_value(luk, 0, USHRT_MAX);
}
+
unsigned short status_calc_batk(struct block_list *bl, struct status_change *sc, int batk, bool viewable)
{
+ nullpo_ret(bl);
if(!sc || !sc->count)
return cap_value(batk,0,USHRT_MAX);
@@ -4828,6 +4914,7 @@ unsigned short status_calc_batk(struct block_list *bl, struct status_change *sc,
unsigned short status_calc_watk(struct block_list *bl, struct status_change *sc, int watk, bool viewable)
{
+ nullpo_ret(bl);
if(!sc || !sc->count)
return cap_value(watk,0,USHRT_MAX);
@@ -4917,9 +5004,10 @@ unsigned short status_calc_watk(struct block_list *bl, struct status_change *sc,
return (unsigned short)cap_value(watk,0,USHRT_MAX);
}
-unsigned short status_calc_ematk(struct block_list *bl, struct status_change *sc, int matk) {
-#ifdef RENEWAL
+unsigned short status_calc_ematk(struct block_list *bl, struct status_change *sc, int matk)
+{
+#ifdef RENEWAL
if (!sc || !sc->count)
return cap_value(matk,0,USHRT_MAX);
if (sc->data[SC_PLUSMAGICPOWER])
@@ -4945,8 +5033,9 @@ unsigned short status_calc_ematk(struct block_list *bl, struct status_change *sc
return 0;
#endif
}
-unsigned short status_calc_matk(struct block_list *bl, struct status_change *sc, int matk, bool viewable) {
+unsigned short status_calc_matk(struct block_list *bl, struct status_change *sc, int matk, bool viewable)
+{
if (!sc || !sc->count)
return cap_value(matk,0,USHRT_MAX);
@@ -5015,8 +5104,8 @@ unsigned short status_calc_matk(struct block_list *bl, struct status_change *sc,
return (unsigned short)cap_value(matk, 0, USHRT_MAX);
}
-signed short status_calc_critical(struct block_list *bl, struct status_change *sc, int critical, bool viewable) {
-
+signed short status_calc_critical(struct block_list *bl, struct status_change *sc, int critical, bool viewable)
+{
if (!sc || !sc->count)
return cap_value(critical, 10, SHRT_MAX);
@@ -5111,7 +5200,9 @@ signed short status_calc_hit(struct block_list *bl, struct status_change *sc, in
return (short)cap_value(hit, 1, SHRT_MAX);
}
-signed short status_calc_flee(struct block_list *bl, struct status_change *sc, int flee, bool viewable) {
+signed short status_calc_flee(struct block_list *bl, struct status_change *sc, int flee, bool viewable)
+{
+ nullpo_retr(1, bl);
if (bl->type == BL_PC) {
if (map_flag_gvg2(bl->m))
@@ -5227,8 +5318,10 @@ signed short status_calc_flee2(struct block_list *bl, struct status_change *sc,
return (short)cap_value(flee2,10,SHRT_MAX);
}
+
defType status_calc_def(struct block_list *bl, struct status_change *sc, int def, bool viewable)
{
+ nullpo_retr(DEFTYPE_MIN, bl);
if (!sc || !sc->count)
return (defType)cap_value(def,DEFTYPE_MIN,DEFTYPE_MAX);
@@ -5333,6 +5426,7 @@ defType status_calc_def(struct block_list *bl, struct status_change *sc, int def
signed short status_calc_def2(struct block_list *bl, struct status_change *sc, int def2, bool viewable)
{
+ nullpo_retr(1, bl);
if(!sc || !sc->count)
#ifdef RENEWAL
return (short)cap_value(def2,SHRT_MIN,SHRT_MAX);
@@ -5407,7 +5501,8 @@ signed short status_calc_def2(struct block_list *bl, struct status_change *sc, i
#endif
}
-defType status_calc_mdef(struct block_list *bl, struct status_change *sc, int mdef, bool viewable) {
+defType status_calc_mdef(struct block_list *bl, struct status_change *sc, int mdef, bool viewable)
+{
if(!sc || !sc->count)
return (defType)cap_value(mdef,DEFTYPE_MIN,DEFTYPE_MAX);
@@ -5701,10 +5796,12 @@ unsigned short status_calc_speed(struct block_list *bl, struct status_change *sc
// flag&1 - fixed value [malufett]
// flag&2 - percentage value
-short status_calc_aspd(struct block_list *bl, struct status_change *sc, short flag) {
+short status_calc_aspd(struct block_list *bl, struct status_change *sc, short flag)
+{
#ifdef RENEWAL_ASPD
int pots = 0, bonus = 0;
+ nullpo_ret(bl);
if (!sc || !sc->count)
return 0;
@@ -5831,7 +5928,9 @@ short status_calc_aspd(struct block_list *bl, struct status_change *sc, short fl
#endif
}
-short status_calc_fix_aspd(struct block_list *bl, struct status_change *sc, int aspd) {
+short status_calc_fix_aspd(struct block_list *bl, struct status_change *sc, int aspd)
+{
+ nullpo_ret(bl);
if (!sc || !sc->count)
return cap_value(aspd, 0, 2000);
@@ -5853,6 +5952,7 @@ short status_calc_aspd_rate(struct block_list *bl, struct status_change *sc, int
{
int i;
+ nullpo_ret(bl);
if(!sc || !sc->count)
return cap_value(aspd_rate,0,SHRT_MAX);
@@ -5993,6 +6093,7 @@ short status_calc_aspd_rate(struct block_list *bl, struct status_change *sc, int
unsigned short status_calc_dmotion(struct block_list *bl, struct status_change *sc, int dmotion)
{
+ nullpo_ret(bl);
// It has been confirmed on official servers that MvP mobs have no dmotion even without endure
if (bl->type == BL_MOB && (BL_UCCAST(BL_MOB, bl)->status.mode&MD_BOSS))
return 0;
@@ -6008,7 +6109,8 @@ unsigned short status_calc_dmotion(struct block_list *bl, struct status_change *
return (unsigned short)cap_value(dmotion,0,USHRT_MAX);
}
-unsigned int status_calc_maxhp(struct block_list *bl, struct status_change *sc, uint64 maxhp) {
+unsigned int status_calc_maxhp(struct block_list *bl, struct status_change *sc, uint64 maxhp)
+{
if (!sc || !sc->count)
return (unsigned int)cap_value(maxhp, 1, UINT_MAX);
@@ -6087,8 +6189,8 @@ unsigned int status_calc_maxhp(struct block_list *bl, struct status_change *sc,
return (unsigned int)cap_value(maxhp, 1, UINT_MAX);
}
-unsigned int status_calc_maxsp(struct block_list *bl, struct status_change *sc, unsigned int maxsp) {
-
+unsigned int status_calc_maxsp(struct block_list *bl, struct status_change *sc, unsigned int maxsp)
+{
if (!sc || !sc->count)
return cap_value(maxsp, 1, UINT_MAX);
@@ -6349,7 +6451,9 @@ struct status_data *status_get_base_status(struct block_list *bl)
return NULL;
}
}
-defType status_get_def(struct block_list *bl) {
+
+defType status_get_def(struct block_list *bl)
+{
struct unit_data *ud;
struct status_data *st = status->get_status_data(bl);
int def = st ? st->def : 0;
@@ -6362,6 +6466,7 @@ defType status_get_def(struct block_list *bl) {
unsigned short status_get_speed(struct block_list *bl)
{
+ nullpo_ret(bl);
if (bl->type == BL_NPC) //Only BL with speed data but no status_data [Skotlex]
return BL_UCCAST(BL_NPC, bl)->speed;
return status->get_status_data(bl)->speed;
@@ -6571,7 +6676,8 @@ int status_get_race2(const struct block_list *bl)
return 0;
}
-int status_isdead(struct block_list *bl) {
+int status_isdead(struct block_list *bl)
+{
nullpo_ret(bl);
return status->get_status_data(bl)->hp == 0;
}
@@ -6773,7 +6879,8 @@ struct status_change *status_get_sc(struct block_list *bl)
return NULL;
}
-void status_change_init(struct block_list *bl) {
+void status_change_init(struct block_list *bl)
+{
struct status_change *sc = status->get_sc(bl);
nullpo_retv(sc);
memset(sc, 0, sizeof (struct status_change));
@@ -6785,7 +6892,8 @@ void status_change_init(struct block_list *bl) {
* @see status_change_start for the expected parameters.
* @return the adjusted duration based on flag values.
*/
-int status_get_sc_def(struct block_list *src, struct block_list *bl, enum sc_type type, int rate, int tick, int flag) {
+int status_get_sc_def(struct block_list *src, struct block_list *bl, enum sc_type type, int rate, int tick, int flag)
+{
//Percentual resistance: 10000 = 100% Resist
//Example: 50% -> sc_def=5000 -> 25%; 5000ms -> tick_def=5000 -> 2500ms
int sc_def = 0, tick_def = -1; //-1 = use sc_def
@@ -6839,6 +6947,7 @@ int status_get_sc_def(struct block_list *src, struct block_list *bl, enum sc_typ
sd = BL_CAST(BL_PC,bl);
st = status->get_status_data(bl);
bst = status->get_base_status(bl);
+ nullpo_ret(bst);
sc = status->get_sc(bl);
if( sc && !sc->count )
sc = NULL;
@@ -7142,11 +7251,14 @@ int status_get_sc_def(struct block_list *src, struct block_list *bl, enum sc_typ
#undef SCDEF_LVL_CAP
#undef SCDEF_LVL_DIFF
}
+
/* [Ind/Hercules] fast-checkin sc-display array */
-void status_display_add(struct map_session_data *sd, enum sc_type type, int dval1, int dval2, int dval3) {
+void status_display_add(struct map_session_data *sd, enum sc_type type, int dval1, int dval2, int dval3)
+{
struct sc_display_entry *entry;
int i;
+ nullpo_retv(sd);
for( i = 0; i < sd->sc_display_count; i++ ) {
if( sd->sc_display[i]->type == type )
break;
@@ -7169,9 +7281,12 @@ void status_display_add(struct map_session_data *sd, enum sc_type type, int dval
RECREATE(sd->sc_display, struct sc_display_entry *, ++sd->sc_display_count);
sd->sc_display[ sd->sc_display_count - 1 ] = entry;
}
-void status_display_remove(struct map_session_data *sd, enum sc_type type) {
+
+void status_display_remove(struct map_session_data *sd, enum sc_type type)
+{
int i;
+ nullpo_retv(sd);
for( i = 0; i < sd->sc_display_count; i++ ) {
if( sd->sc_display[i]->type == type )
break;
@@ -7218,7 +7333,8 @@ void status_display_remove(struct map_session_data *sd, enum sc_type type) {
* @retval 0 if no status change happened.
* @retval 1 if the status change was successfully applied.
*/
-int status_change_start(struct block_list *src, struct block_list *bl, enum sc_type type, int rate, int val1, int val2, int val3, int val4, int tick, int flag) {
+int status_change_start(struct block_list *src, struct block_list *bl, enum sc_type type, int rate, int val1, int val2, int val3, int val4, int tick, int flag)
+{
struct map_session_data *sd = NULL;
struct status_change* sc;
struct status_change_entry* sce;
@@ -10177,6 +10293,7 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t
return 1;
}
+
/*==========================================
* Ending all status except those listed.
* @TODO maybe usefull for dispel instead reseting a liste there.
@@ -10186,7 +10303,8 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t
* 2 - Do clif
* 3 - Do not remove some permanent/time-independent effects
*------------------------------------------*/
-int status_change_clear(struct block_list* bl, int type) {
+int status_change_clear(struct block_list* bl, int type)
+{
struct status_change* sc;
int i;
@@ -10243,7 +10361,8 @@ int status_change_clear(struct block_list* bl, int type) {
/*==========================================
* Special condition we want to effectuate, check before ending a status.
*------------------------------------------*/
-int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const char* file, int line) {
+int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const char* file, int line)
+{
struct map_session_data *sd;
struct status_change *sc;
struct status_change_entry *sce;
@@ -10361,10 +10480,12 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
struct map_session_data *tsd;
if( bl->type == BL_PC ) {
// Clear Status from others
- int i;
- for( i = 0; i < MAX_PC_DEVOTION; i++ ) {
- if (sd->devotion[i] && (tsd = map->id2sd(sd->devotion[i])) != NULL && tsd->sc.data[type])
- status_change_end(&tsd->bl, type, INVALID_TIMER);
+ if (sd != NULL ) {
+ int i;
+ for( i = 0; i < MAX_PC_DEVOTION; i++ ) {
+ if (sd->devotion[i] && (tsd = map->id2sd(sd->devotion[i])) != NULL && tsd->sc.data[type])
+ status_change_end(&tsd->bl, type, INVALID_TIMER);
+ }
}
} else if (bl->type == BL_MER) {
struct mercenary_data *mc = BL_UCAST(BL_MER, bl);
@@ -11011,7 +11132,8 @@ int kaahi_heal_timer(int tid, int64 tick, int id, intptr_t data) {
* For recusive status, like for each 5s we drop sp etc.
* Reseting the end timer.
*------------------------------------------*/
-int status_change_timer(int tid, int64 tick, int id, intptr_t data) {
+int status_change_timer(int tid, int64 tick, int id, intptr_t data)
+{
enum sc_type type = (sc_type)data;
struct block_list *bl;
struct map_session_data *sd;
@@ -11871,7 +11993,8 @@ int status_change_timer(int tid, int64 tick, int id, intptr_t data) {
/*==========================================
* Foreach iteration of repetitive status
*------------------------------------------*/
-int status_change_timer_sub(struct block_list* bl, va_list ap) {
+int status_change_timer_sub(struct block_list* bl, va_list ap)
+{
struct status_change* tsc;
struct block_list* src = va_arg(ap,struct block_list*);
@@ -11879,6 +12002,8 @@ int status_change_timer_sub(struct block_list* bl, va_list ap) {
enum sc_type type = (sc_type)va_arg(ap,int); //gcc: enum args get promoted to int
int64 tick = va_arg(ap, int64);
+ nullpo_ret(bl);
+
if (status->isdead(bl))
return 0;
@@ -11929,13 +12054,13 @@ int status_change_timer_sub(struct block_list* bl, va_list ap) {
break;
case SC_RG_CCONFINE_M:
//Lock char has released the hold on everyone...
- if (tsc && tsc->data[SC_RG_CCONFINE_S] && tsc->data[SC_RG_CCONFINE_S]->val2 == src->id) {
+ if (tsc != NULL && src != NULL && tsc->data[SC_RG_CCONFINE_S] && tsc->data[SC_RG_CCONFINE_S]->val2 == src->id) {
tsc->data[SC_RG_CCONFINE_S]->val2 = 0;
status_change_end(bl, SC_RG_CCONFINE_S, INVALID_TIMER);
}
break;
case SC_CURSEDCIRCLE_TARGET:
- if( tsc && tsc->data[SC_CURSEDCIRCLE_TARGET] && tsc->data[SC_CURSEDCIRCLE_TARGET]->val2 == src->id ) {
+ if (tsc != NULL && src != NULL && tsc->data[SC_CURSEDCIRCLE_TARGET] && tsc->data[SC_CURSEDCIRCLE_TARGET]->val2 == src->id) {
clif->bladestop(bl, tsc->data[SC_CURSEDCIRCLE_TARGET]->val2, 0);
status_change_end(bl, type, INVALID_TIMER);
}
@@ -11946,12 +12071,15 @@ int status_change_timer_sub(struct block_list* bl, va_list ap) {
int status_get_total_def(struct block_list *src) { return status->get_status_data(src)->def2 + (short)status->get_def(src); }
int status_get_total_mdef(struct block_list *src) { return status->get_status_data(src)->mdef2 + (short)status_get_mdef(src); }
+
int status_get_weapon_atk(struct block_list *bl, struct weapon_atk *watk, int flag)
{
#ifdef RENEWAL
int min = 0, max = 0;
struct status_change *sc = status->get_sc(bl);
+ nullpo_ret(bl);
+ nullpo_ret(watk);
if (bl->type == BL_PC && watk->atk) {
float strdex_bonus, variance;
int dstr;
@@ -12013,7 +12141,8 @@ int status_get_weapon_atk(struct block_list *bl, struct weapon_atk *watk, int fl
* 1 - Get MATK w/o SC bonuses
* 3 - Get MATK w/o EATK & SC bonuses
**/
-void status_get_matk_sub(struct block_list *bl, int flag, unsigned short *matk_max, unsigned short *matk_min) {
+void status_get_matk_sub(struct block_list *bl, int flag, unsigned short *matk_max, unsigned short *matk_min)
+{
struct status_data *st;
struct status_change *sc;
struct map_session_data *sd;
@@ -12120,7 +12249,8 @@ void status_get_matk_sub(struct block_list *bl, int flag, unsigned short *matk_m
/**
* Gets a random matk value depending on min matk and max matk
**/
-unsigned short status_get_rand_matk(unsigned short matk_max, unsigned short matk_min) {
+unsigned short status_get_rand_matk(unsigned short matk_max, unsigned short matk_min)
+{
if ( matk_max > matk_min )
return matk_min + rnd() % (matk_max - matk_min);
else
@@ -12138,7 +12268,8 @@ unsigned short status_get_rand_matk(unsigned short matk_max, unsigned short matk
*
* Shouldn't change _any_ value! [Panikon]
**/
-int status_get_matk(struct block_list *bl, int flag) {
+int status_get_matk(struct block_list *bl, int flag)
+{
struct status_data *st;
unsigned short matk_max, matk_min;
@@ -12166,7 +12297,8 @@ int status_get_matk(struct block_list *bl, int flag) {
/**
* Updates bl's MATK values
**/
-void status_update_matk(struct block_list *bl) {
+void status_update_matk(struct block_list *bl)
+{
struct status_data *st;
struct status_change *sc;
unsigned short matk_max, matk_min;
@@ -12194,7 +12326,8 @@ void status_update_matk(struct block_list *bl) {
* type&1 -> buffs, type&2 -> debuffs
* type&4 -> especific debuffs(implemented with refresh)
*------------------------------------------*/
-int status_change_clear_buffs (struct block_list* bl, int type) {
+int status_change_clear_buffs (struct block_list* bl, int type)
+{
int i;
struct status_change *sc= status->get_sc(bl);
@@ -12255,7 +12388,8 @@ int status_change_clear_buffs (struct block_list* bl, int type) {
return 0;
}
-int status_change_spread( struct block_list *src, struct block_list *bl ) {
+int status_change_spread(struct block_list *src, struct block_list *bl)
+{
int i, flag = 0;
struct status_change *sc = status->get_sc(src);
int64 tick;
@@ -12345,7 +12479,8 @@ int status_change_spread( struct block_list *src, struct block_list *bl ) {
}
//Natural regen related stuff.
-int status_natural_heal(struct block_list* bl, va_list args) {
+int status_natural_heal(struct block_list* bl, va_list args)
+{
struct regen_data *regen;
struct status_data *st;
struct status_change *sc;
@@ -12355,6 +12490,7 @@ int status_natural_heal(struct block_list* bl, va_list args) {
struct map_session_data *sd;
int val,rate,bonus = 0,flag;
+ nullpo_ret(bl);
regen = status->get_regen_data(bl);
if (!regen) return 0;
st = status->get_status_data(bl);
@@ -12531,7 +12667,8 @@ int status_natural_heal(struct block_list* bl, va_list args) {
}
//Natural heal main timer.
-int status_natural_heal_timer(int tid, int64 tick, int id, intptr_t data) {
+int status_natural_heal_timer(int tid, int64 tick, int id, intptr_t data)
+{
// This difference is always positive and lower than UINT_MAX (~24 days)
status->natural_heal_diff_tick = (unsigned int)cap_value(DIFF_TICK(tick,status->natural_heal_prev_tick), 0, UINT_MAX);
map->foreachregen(status->natural_heal);
@@ -12545,15 +12682,17 @@ int status_natural_heal_timer(int tid, int64 tick, int id, intptr_t data) {
* @param refine The target refine level
* @return The chance to refine the item, in percent (0~100)
**/
-int status_get_refine_chance(enum refine_type wlv, int refine) {
-
+int status_get_refine_chance(enum refine_type wlv, int refine)
+{
+ Assert_ret((int)wlv >= REFINE_TYPE_ARMOR && wlv < REFINE_TYPE_MAX);
if ( refine < 0 || refine >= MAX_REFINE)
return 0;
return status->dbs->refine_info[wlv].chance[refine];
}
-int status_get_sc_type(sc_type type) {
+int status_get_sc_type(sc_type type)
+{
if( type <= SC_NONE || type >= SC_MAX )
return 0;
@@ -12765,7 +12904,8 @@ void status_read_job_db_sub(int idx, const char *name, struct config_setting_t *
* size_fix.txt - size adjustment table for weapons
* refine_db.txt - refining data table
*------------------------------------------*/
-void status_read_job_db(void) { /* [malufett/Hercules] */
+void status_read_job_db(void) /* [malufett/Hercules] */
+{
int i = 0;
struct config_t job_db_conf;
struct config_setting_t *jdb = NULL;
@@ -12798,6 +12938,7 @@ bool status_readdb_job2(char* fields[], int columns, int current)
{
int idx, class_, i;
+ nullpo_retr(false, fields);
class_ = atoi(fields[0]);
if(!pc->db_checkid(class_))
@@ -12818,6 +12959,7 @@ bool status_readdb_sizefix(char* fields[], int columns, int current)
{
unsigned int i;
+ nullpo_retr(false, fields);
for(i = 0; i < MAX_SINGLE_WEAPON_TYPE; i++)
{
status->dbs->atkmods[current][i] = atoi(fields[i]);
@@ -12928,7 +13070,8 @@ int status_readdb_refine_libconfig_sub(struct config_setting_t *r, const char *n
* @param *filename File name, relative to the database path.
* @return The number of found entries.
*/
-int status_readdb_refine_libconfig(const char *filename) {
+int status_readdb_refine_libconfig(const char *filename)
+{
bool duplicate[REFINE_TYPE_MAX];
struct config_t refine_db_conf;
struct config_setting_t *r;
@@ -12959,10 +13102,12 @@ int status_readdb_refine_libconfig(const char *filename) {
return count;
}
-bool status_readdb_scconfig(char* fields[], int columns, int current) {
+bool status_readdb_scconfig(char* fields[], int columns, int current)
+{
int val = 0;
char* type = fields[0];
+ nullpo_retr(false, fields);
if( !script->get_constant(type, &val) ){
ShowWarning("status_readdb_sc_conf: Invalid status type %s specified.\n", type);
return false;
@@ -13033,7 +13178,8 @@ int status_readdb(void)
/*==========================================
* Status db init and destroy.
*------------------------------------------*/
-int do_init_status(bool minimal) {
+int do_init_status(bool minimal)
+{
if (minimal)
return 0;
@@ -13048,7 +13194,9 @@ int do_init_status(bool minimal) {
timer->add_interval(status->natural_heal_prev_tick + NATURAL_HEAL_INTERVAL, status->natural_heal_timer, 0, 0, NATURAL_HEAL_INTERVAL);
return 0;
}
-void do_final_status(void) {
+
+void do_final_status(void)
+{
ers_destroy(status->data_ers);
}
@@ -13057,7 +13205,8 @@ void do_final_status(void) {
* Generated by HerculesInterfaceMaker
* created by Susu
*-------------------------------------*/
-void status_defaults(void) {
+void status_defaults(void)
+{
status = &status_s;
status->dbs = &statusdbs;
diff --git a/src/map/storage.c b/src/map/storage.c
index 4272f9611..da76a0d30 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -82,6 +82,7 @@ void storage_sortitem(struct item* items, unsigned int size)
int storage_reconnect_sub(union DBKey key, struct DBData *data, va_list ap)
{
struct guild_storage *stor = DB->data2ptr(data);
+ nullpo_ret(stor);
if (stor->dirty && stor->storage_status == 0) //Save closed storages.
gstorage->save(0, stor->guild_id,0);
@@ -89,7 +90,8 @@ int storage_reconnect_sub(union DBKey key, struct DBData *data, va_list ap)
}
//Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex]
-void do_reconnect_storage(void) {
+void do_reconnect_storage(void)
+{
gstorage->db->foreach(gstorage->db, storage->reconnect_sub);
}
@@ -141,11 +143,15 @@ int compare_item(struct item *a, struct item *b)
/*==========================================
* Internal add-item function.
*------------------------------------------*/
-int storage_additem(struct map_session_data* sd, struct item* item_data, int amount) {
- struct storage_data* stor = &sd->status.storage;
+int storage_additem(struct map_session_data* sd, struct item* item_data, int amount)
+{
+ struct storage_data* stor;
struct item_data *data;
int i;
+ nullpo_retr(1, sd);
+ nullpo_retr(1, item_data);
+ stor = &sd->status.storage;
if( item_data->nameid <= 0 || amount <= 0 )
return 1;
@@ -203,6 +209,8 @@ int storage_additem(struct map_session_data* sd, struct item* item_data, int amo
*------------------------------------------*/
int storage_delitem(struct map_session_data* sd, int n, int amount)
{
+ nullpo_retr(1, sd);
+ Assert_retr(1, n >= 0 && n < MAX_STORAGE);
if( sd->status.storage.items[n].nameid == 0 || sd->status.storage.items[n].amount < amount )
return 1;
@@ -226,7 +234,8 @@ int storage_delitem(struct map_session_data* sd, int n, int amount)
* 0 : fail
* 1 : success
*------------------------------------------*/
-int storage_storageadd(struct map_session_data* sd, int index, int amount) {
+int storage_storageadd(struct map_session_data* sd, int index, int amount)
+{
nullpo_ret(sd);
if( sd->status.storage.storage_amount > MAX_STORAGE )
@@ -260,6 +269,7 @@ int storage_storageget(struct map_session_data* sd, int index, int amount)
{
int flag;
+ nullpo_ret(sd);
if( index < 0 || index >= MAX_STORAGE )
return 0;
@@ -313,7 +323,8 @@ int storage_storageaddfromcart(struct map_session_data* sd, int index, int amoun
* 0 : fail
* 1 : success
*------------------------------------------*/
-int storage_storagegettocart(struct map_session_data* sd, int index, int amount) {
+int storage_storagegettocart(struct map_session_data* sd, int index, int amount)
+{
int flag = 0;
nullpo_ret(sd);
@@ -340,7 +351,8 @@ int storage_storagegettocart(struct map_session_data* sd, int index, int amount)
/*==========================================
* Modified By Valaris to save upon closing [massdriller]
*------------------------------------------*/
-void storage_storageclose(struct map_session_data* sd) {
+void storage_storageclose(struct map_session_data* sd)
+{
nullpo_retv(sd);
clif->storageclose(sd);
@@ -354,7 +366,8 @@ void storage_storageclose(struct map_session_data* sd) {
/*==========================================
* When quitting the game.
*------------------------------------------*/
-void storage_storage_quit(struct map_session_data* sd, int flag) {
+void storage_storage_quit(struct map_session_data* sd, int flag)
+{
nullpo_retv(sd);
if (map->save_settings&4)
@@ -382,7 +395,8 @@ struct guild_storage *guild2storage_ensure(int guild_id)
return gs;
}
-int guild_storage_delete(int guild_id) {
+int guild_storage_delete(int guild_id)
+{
idb_remove(gstorage->db,guild_id);
return 0;
}
@@ -503,6 +517,7 @@ int guild_storage_delitem(struct map_session_data* sd, struct guild_storage* sto
nullpo_retr(1, sd);
nullpo_retr(1, stor);
+ Assert_retr(1, n >= 0 && n < MAX_GUILD_STORAGE);
if(stor->items[n].nameid==0 || stor->items[n].amount<amount)
return 1;
@@ -703,7 +718,8 @@ int storage_guild_storagesaved(int guild_id)
}
//Close storage for sd and save it
-int storage_guild_storageclose(struct map_session_data* sd) {
+int storage_guild_storageclose(struct map_session_data* sd)
+{
struct guild_storage *stor;
nullpo_ret(sd);
@@ -722,7 +738,8 @@ int storage_guild_storageclose(struct map_session_data* sd) {
return 0;
}
-int storage_guild_storage_quit(struct map_session_data* sd, int flag) {
+int storage_guild_storage_quit(struct map_session_data* sd, int flag)
+{
struct guild_storage *stor;
nullpo_ret(sd);
@@ -749,15 +766,21 @@ int storage_guild_storage_quit(struct map_session_data* sd, int flag) {
return 0;
}
-void do_init_gstorage(bool minimal) {
+
+void do_init_gstorage(bool minimal)
+{
if (minimal)
return;
gstorage->db = idb_alloc(DB_OPT_RELEASE_DATA);
}
-void do_final_gstorage(void) {
+
+void do_final_gstorage(void)
+{
db_destroy(gstorage->db);
}
-void storage_defaults(void) {
+
+void storage_defaults(void)
+{
storage = &storage_s;
/* */
@@ -776,7 +799,9 @@ void storage_defaults(void) {
storage->sortitem = storage_sortitem;
storage->reconnect_sub = storage_reconnect_sub;
}
-void gstorage_defaults(void) {
+
+void gstorage_defaults(void)
+{
gstorage = &gstorage_s;
/* */
diff --git a/src/map/trade.c b/src/map/trade.c
index d6bdd14e5..6ada188c9 100644
--- a/src/map/trade.c
+++ b/src/map/trade.c
@@ -118,7 +118,8 @@ void trade_traderequest(struct map_session_data *sd, struct map_session_data *ta
* Weird enough, the client should only send 3/4
* and the server is the one that can reply 0~2
*------------------------------------------*/
-void trade_tradeack(struct map_session_data *sd, int type) {
+void trade_tradeack(struct map_session_data *sd, int type)
+{
struct map_session_data *tsd;
nullpo_retv(sd);
@@ -217,6 +218,8 @@ int impossible_trade_check(struct map_session_data *sd)
if (!sd->deal.item[i].amount)
continue;
index = sd->deal.item[i].index;
+ if (index < 0 || index >= MAX_INVENTORY)
+ return 1;
if (inventory[index].amount < sd->deal.item[i].amount) {
// if more than the player have -> hack
snprintf(message_to_gm, sizeof(message_to_gm), msg_txt(538), sd->status.name, sd->status.account_id); // Hack on trade: character '%s' (account: %d) try to trade more items that he has.
@@ -257,6 +260,8 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd)
struct item_data *data;
int trade_i, i, n;
+ nullpo_ret(sd);
+ nullpo_ret(tsd);
// check zenys value against hackers (Zeny was already checked on time of adding, but you never know when you lost some zeny since then.
if(sd->deal.zeny > sd->status.zeny || (tsd->status.zeny > MAX_ZENY - sd->deal.zeny))
return 0;
@@ -303,6 +308,8 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd)
if (!amount)
continue;
n = tsd->deal.item[trade_i].index;
+ if (n < 0 || n >= MAX_INVENTORY)
+ return 0;
if (amount > inventory2[n].amount)
return 0;
// search if it's possible to add item (for full inventory)
@@ -336,7 +343,8 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd)
/*==========================================
* Adds an item/qty to the trade window
*------------------------------------------*/
-void trade_tradeadditem(struct map_session_data *sd, short index, short amount) {
+void trade_tradeadditem(struct map_session_data *sd, short index, short amount)
+{
struct map_session_data *target_sd;
struct item *item;
int trade_i, trade_weight;
@@ -456,9 +464,11 @@ void trade_tradeaddzeny(struct map_session_data* sd, int amount)
/*==========================================
* 'Ok' button on the trade window is pressed.
*------------------------------------------*/
-void trade_tradeok(struct map_session_data *sd) {
+void trade_tradeok(struct map_session_data *sd)
+{
struct map_session_data *target_sd;
+ nullpo_retv(sd);
if(sd->state.deal_locked || !sd->state.trading)
return;
@@ -475,10 +485,12 @@ void trade_tradeok(struct map_session_data *sd) {
/*==========================================
* 'Cancel' is pressed. (or trade was force-canceled by the code)
*------------------------------------------*/
-void trade_tradecancel(struct map_session_data *sd) {
+void trade_tradecancel(struct map_session_data *sd)
+{
struct map_session_data *target_sd;
int trade_i;
+ nullpo_retv(sd);
target_sd = map->id2sd(sd->trade_partner);
if(!sd->state.trading)
@@ -533,11 +545,13 @@ void trade_tradecancel(struct map_session_data *sd) {
/*==========================================
* lock sd and tsd trade data, execute the trade, clear, then save players
*------------------------------------------*/
-void trade_tradecommit(struct map_session_data *sd) {
+void trade_tradecommit(struct map_session_data *sd)
+{
struct map_session_data *tsd;
int trade_i;
int flag;
+ nullpo_retv(sd);
if (!sd->state.trading || !sd->state.deal_locked) //Locked should be 1 (pressed ok) before you can press trade.
return;
diff --git a/src/map/unit.c b/src/map/unit.c
index b919934c7..978dd54b3 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -235,8 +235,8 @@ int unit_step_timer(int tid, int64 tick, int id, intptr_t data)
return 1;
}
-
-int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) {
+int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data)
+{
int i;
int x,y,dx,dy;
unsigned char icewall_walk_block;
@@ -487,7 +487,8 @@ int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) {
return 0;
}
-int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) {
+int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data)
+{
struct block_list *bl = map->id2bl(id);
if (!bl || bl->prev == NULL)
@@ -570,7 +571,8 @@ static inline void set_mobstate(struct block_list* bl, int flag)
md->state.skillstate = md->state.aggressive ? MSS_FOLLOW : MSS_RUSH;
}
-int unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data) {
+int unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data)
+{
struct block_list *bl = map->id2bl(id);
struct unit_data *ud = bl?unit->bl2ud(bl):NULL;
@@ -649,15 +651,21 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
* Called by unit_run when an object was hit
* @param sd Required only when using SC_WUGDASH
**/
-void unit_run_hit( struct block_list *bl, struct status_change *sc, struct map_session_data *sd, enum sc_type type ) {
- int lv = sc->data[type]->val1;
+void unit_run_hit(struct block_list *bl, struct status_change *sc, struct map_session_data *sd, enum sc_type type)
+{
+ int lv;
+ struct unit_data *ud;
+ Assert_retv(type >= 0 && type < SC_MAX);
+ lv = sc->data[type]->val1;
//If you can't run forward, you must be next to a wall, so bounce back. [Skotlex]
if( type == SC_RUN )
clif->sc_load(bl,bl->id,AREA,SI_TING,0,0,0);
+ ud = unit->bl2ud(bl);
+ nullpo_retv(ud);
//Set running to 0 beforehand so status_change_end knows not to enable spurt [Kevin]
- unit->bl2ud(bl)->state.running = 0;
+ ud->state.running = 0;
status_change_end(bl, type, INVALID_TIMER);
if( type == SC_RUN ) {
@@ -677,7 +685,8 @@ void unit_run_hit( struct block_list *bl, struct status_change *sc, struct map_s
* @retval true Finished running
* @retval false Hit an object/Couldn't run
**/
-bool unit_run( struct block_list *bl, struct map_session_data *sd, enum sc_type type ) {
+bool unit_run(struct block_list *bl, struct map_session_data *sd, enum sc_type type)
+{
struct status_change *sc;
short to_x,to_y,dir_x,dir_y;
int i;
@@ -737,15 +746,19 @@ bool unit_run( struct block_list *bl, struct map_session_data *sd, enum sc_type
}
//Makes bl attempt to run dist cells away from target. Uses hard-paths.
-int unit_escape(struct block_list *bl, struct block_list *target, short dist) {
- uint8 dir = map->calc_dir(target, bl->x, bl->y);
+int unit_escape(struct block_list *bl, struct block_list *target, short dist)
+{
+ uint8 dir;
+ nullpo_ret(bl);
+ dir = map->calc_dir(target, bl->x, bl->y);
while (dist > 0 && map->getcell(bl->m, bl, bl->x + dist * dirx[dir], bl->y + dist * diry[dir], CELL_CHKNOREACH))
dist--;
return ( dist > 0 && unit->walktoxy(bl, bl->x + dist*dirx[dir], bl->y + dist*diry[dir], 0) );
}
//Instant warp function.
-int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath) {
+int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath)
+{
short dx,dy;
uint8 dir;
struct unit_data *ud = NULL;
@@ -821,7 +834,8 @@ int unit_setdir(struct block_list *bl,unsigned char dir)
return 0;
}
-uint8 unit_getdir(struct block_list *bl) {
+uint8 unit_getdir(struct block_list *bl)
+{
struct unit_data *ud;
nullpo_ret(bl);
@@ -978,7 +992,8 @@ int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type)
* Flag values: @see unit_stopwalking_flag.
* Upper bytes may be used for other purposes depending on the unit type.
*------------------------------------------*/
-int unit_stop_walking(struct block_list *bl, int flag) {
+int unit_stop_walking(struct block_list *bl, int flag)
+{
struct unit_data *ud;
const struct TimerData* td;
int64 tick;
@@ -1040,7 +1055,8 @@ int unit_is_walking(struct block_list *bl)
/*==========================================
* Determines if the bl can move based on status changes. [Skotlex]
*------------------------------------------*/
-int unit_can_move(struct block_list *bl) {
+int unit_can_move(struct block_list *bl)
+{
struct map_session_data *sd;
struct unit_data *ud;
struct status_change *sc;
@@ -1150,11 +1166,12 @@ int unit_can_move(struct block_list *bl) {
* Resume running after a walk delay
*------------------------------------------*/
-int unit_resume_running(int tid, int64 tick, int id, intptr_t data) {
-
+int unit_resume_running(int tid, int64 tick, int id, intptr_t data)
+{
struct unit_data *ud = (struct unit_data *)data;
struct map_session_data *sd = map->id2sd(id);
+ nullpo_ret(ud);
if(sd && pc_isridingwug(sd))
clif->skill_nodamage(ud->bl,ud->bl,RA_WUGDASH,ud->skill_lv,
sc_start4(ud->bl,ud->bl,status->skill2sc(RA_WUGDASH),100,ud->skill_lv,unit->getdir(ud->bl),0,0,1));
@@ -1174,10 +1191,12 @@ int unit_resume_running(int tid, int64 tick, int id, intptr_t data) {
* if type is 0, this is a damage induced delay: if previous delay is active, do not change it.
* if type is 1, this is a skill induced delay: walk-delay may only be increased, not decreased.
*------------------------------------------*/
-int unit_set_walkdelay(struct block_list *bl, int64 tick, int delay, int type) {
+int unit_set_walkdelay(struct block_list *bl, int64 tick, int delay, int type)
+{
struct unit_data *ud = unit->bl2ud(bl);
if (delay <= 0 || !ud) return 0;
+ nullpo_ret(bl);
if (type) {
//Bosses can ignore skill induced walkdelay (but not damage induced)
if (bl->type == BL_MOB && (BL_UCCAST(BL_MOB, bl)->status.mode&MD_BOSS))
@@ -1213,7 +1232,9 @@ int unit_set_walkdelay(struct block_list *bl, int64 tick, int delay, int type) {
return 1;
}
-int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel) {
+//-------------- stop here
+int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel)
+{
struct unit_data *ud;
struct status_data *tstatus;
struct status_change *sc;
@@ -1357,7 +1378,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
switch (skill_id){
case SA_CASTCANCEL:
- if (ud->skill_id != skill_id){
+ if (ud->skill_id != skill_id) {
sd->skill_id_old = ud->skill_id;
sd->skill_lv_old = ud->skill_lv;
}
@@ -1487,7 +1508,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
}
break;
case AB_CLEARANCE:
- if( target->type != BL_MOB && battle->check_target(src,target,BCT_PARTY) <= 0 && sd ) {
+ if (target->type != BL_MOB && battle->check_target(src, target, BCT_PARTY) <= 0 && sd) {
clif->skill_fail(sd, skill_id, USESKILL_FAIL_TOTARGET, 0);
return 0;
}
@@ -1547,7 +1568,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
}
break;
case NC_DISJOINT:
- if( target->type == BL_PC ){
+ if (target->type == BL_PC) {
struct mob_data *md;
if( (md = map->id2md(target->id)) && md->master_id != src->id )
casttime <<= 1;
@@ -1864,6 +1885,7 @@ void unit_stop_stepaction(struct block_list *bl)
int unit_unattackable(struct block_list *bl)
{
struct unit_data *ud = unit->bl2ud(bl);
+ nullpo_ret(bl);
if (ud) {
ud->state.attack_continue = 0;
ud->state.step_attack = 0;
@@ -1881,11 +1903,13 @@ int unit_unattackable(struct block_list *bl)
* Attack request
* If type is an ongoing attack
*------------------------------------------*/
-int unit_attack(struct block_list *src,int target_id,int continuous) {
+int unit_attack(struct block_list *src, int target_id, int continuous)
+{
struct block_list *target;
struct unit_data *ud;
int range;
+ nullpo_ret(src);
nullpo_ret(ud = unit->bl2ud(src));
target = map->id2bl(target_id);
@@ -1953,6 +1977,7 @@ int unit_cancel_combo(struct block_list *bl)
{
struct unit_data *ud;
+ nullpo_ret(bl);
if (!status_change_end(bl, SC_COMBOATTACK, INVALID_TIMER))
return 0; //Combo wasn't active.
@@ -2089,7 +2114,8 @@ int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
/*==========================================
* Continuous Attack (function timer)
*------------------------------------------*/
-int unit_attack_timer_sub(struct block_list* src, int tid, int64 tick) {
+int unit_attack_timer_sub(struct block_list* src, int tid, int64 tick)
+{
struct block_list *target;
struct unit_data *ud;
struct status_data *sstatus;
@@ -2228,7 +2254,8 @@ int unit_attack_timer_sub(struct block_list* src, int tid, int64 tick) {
return 1;
}
-int unit_attack_timer(int tid, int64 tick, int id, intptr_t data) {
+int unit_attack_timer(int tid, int64 tick, int id, intptr_t data)
+{
struct block_list *bl;
bl = map->id2bl(id);
if(bl && unit->attack_timer_sub(bl, tid, tick) == 0)
@@ -2299,7 +2326,8 @@ int unit_skillcastcancel(struct block_list *bl,int type)
}
// unit_data initialization process
-void unit_dataset(struct block_list *bl) {
+void unit_dataset(struct block_list *bl)
+{
struct unit_data *ud = unit->bl2ud(bl);
nullpo_retv(ud);
@@ -2335,7 +2363,8 @@ int unit_counttargeted(struct block_list* bl)
/*==========================================
*
*------------------------------------------*/
-int unit_fixdamage(struct block_list *src, struct block_list *target, int sdelay, int ddelay, int64 damage, short div, unsigned char type, int64 damage2) {
+int unit_fixdamage(struct block_list *src, struct block_list *target, int sdelay, int ddelay, int64 damage, short div, unsigned char type, int64 damage2)
+{
nullpo_ret(target);
if(damage+damage2 <= 0)
@@ -2371,9 +2400,11 @@ int unit_changeviewsize(struct block_list *bl,short size)
* Otherwise it is assumed bl is being warped.
* On-Kill specific stuff is not performed here, look at status->damage for that.
*------------------------------------------*/
-int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, int line, const char* func) {
+int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, int line, const char* func)
+{
struct unit_data *ud = unit->bl2ud(bl);
struct status_change *sc = status->get_sc(bl);
+ nullpo_ret(bl);
nullpo_ret(ud);
if(bl->prev == NULL)
@@ -2615,6 +2646,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i
void unit_remove_map_pc(struct map_session_data *sd, clr_type clrtype)
{
+ nullpo_retv(sd);
unit->remove_map(&sd->bl,clrtype,ALC_MARK);
//CLR_RESPAWN is the warp from logging out, CLR_TELEPORT is the warp from teleporting, but pets/homunc need to just 'vanish' instead of showing the warping animation.
@@ -2632,6 +2664,7 @@ void unit_remove_map_pc(struct map_session_data *sd, clr_type clrtype)
void unit_free_pc(struct map_session_data *sd)
{
+ nullpo_retv(sd);
if (sd->pd) unit->free(&sd->pd->bl,CLR_OUTSIGHT);
if (sd->hd) unit->free(&sd->hd->bl,CLR_OUTSIGHT);
if (sd->md) unit->free(&sd->md->bl,CLR_OUTSIGHT);
@@ -2643,8 +2676,10 @@ void unit_free_pc(struct map_session_data *sd)
* Function to free all related resources to the bl
* if unit is on map, it is removed using the clrtype specified
*------------------------------------------*/
-int unit_free(struct block_list *bl, clr_type clrtype) {
+int unit_free(struct block_list *bl, clr_type clrtype)
+{
struct unit_data *ud = unit->bl2ud( bl );
+ nullpo_ret(bl);
nullpo_ret(ud);
map->freeblock_lock();
@@ -2888,7 +2923,8 @@ int unit_free(struct block_list *bl, clr_type clrtype) {
return 0;
}
-int do_init_unit(bool minimal) {
+int do_init_unit(bool minimal)
+{
if (minimal)
return 0;
@@ -2900,12 +2936,14 @@ int do_init_unit(bool minimal) {
return 0;
}
-int do_final_unit(void) {
+int do_final_unit(void)
+{
// nothing to do
return 0;
}
-void unit_defaults(void) {
+void unit_defaults(void)
+{
unit = &unit_s;
unit->init = do_init_unit;
diff --git a/src/map/vending.c b/src/map/vending.c
index f92437cb8..80f57b9aa 100644
--- a/src/map/vending.c
+++ b/src/map/vending.c
@@ -44,14 +44,16 @@ struct vending_interface vending_s;
struct vending_interface *vending;
/// Returns an unique vending shop id.
-static inline unsigned int getid(void) {
+static inline unsigned int getid(void)
+{
return vending->next_id++;
}
/*==========================================
* Close shop
*------------------------------------------*/
-void vending_closevending(struct map_session_data* sd) {
+void vending_closevending(struct map_session_data* sd)
+{
nullpo_retv(sd);
if( sd->state.vending ) {
@@ -64,7 +66,8 @@ void vending_closevending(struct map_session_data* sd) {
/*==========================================
* Request a shop's item list
*------------------------------------------*/
-void vending_vendinglistreq(struct map_session_data* sd, unsigned int id) {
+void vending_vendinglistreq(struct map_session_data* sd, unsigned int id)
+{
struct map_session_data* vsd;
nullpo_retv(sd);
@@ -86,13 +89,15 @@ void vending_vendinglistreq(struct map_session_data* sd, unsigned int id) {
/*==========================================
* Purchase item(s) from a shop
*------------------------------------------*/
-void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, const uint8* data, int count) {
+void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, const uint8* data, int count)
+{
int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING];
int64 z;
struct s_vending vend[MAX_VENDING]; // against duplicate packets
struct map_session_data* vsd = map->id2sd(aid);
nullpo_retv(sd);
+ nullpo_retv(data);
if( vsd == NULL || !vsd->state.vending || vsd->bl.id == sd->bl.id )
return; // invalid shop
@@ -240,7 +245,8 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid,
* Open shop
* data := {<index>.w <amount>.w <value>.l}[count]
*------------------------------------------*/
-void vending_openvending(struct map_session_data* sd, const char* message, const uint8* data, int count) {
+void vending_openvending(struct map_session_data* sd, const char* message, const uint8* data, int count)
+{
int i, j;
int vending_skill_lvl;
nullpo_retv(sd);
@@ -309,9 +315,11 @@ void vending_openvending(struct map_session_data* sd, const char* message, const
/// Checks if an item is being sold in given player's vending.
-bool vending_search(struct map_session_data* sd, unsigned short nameid) {
+bool vending_search(struct map_session_data* sd, unsigned short nameid)
+{
int i;
+ nullpo_retr(false, sd);
if( !sd->state.vending ) { // not vending
return false;
}
@@ -327,11 +335,14 @@ bool vending_search(struct map_session_data* sd, unsigned short nameid) {
/// Searches for all items in a vending, that match given ids, price and possible cards.
/// @return Whether or not the search should be continued.
-bool vending_searchall(struct map_session_data* sd, const struct s_search_store_search* s) {
+bool vending_searchall(struct map_session_data* sd, const struct s_search_store_search* s)
+{
int i, c, slot;
unsigned int idx, cidx;
struct item* it;
+ nullpo_retr(false, sd);
+ nullpo_retr(false, s);
if( !sd->state.vending ) // not vending
return true;
@@ -377,16 +388,20 @@ bool vending_searchall(struct map_session_data* sd, const struct s_search_store_
return true;
}
-void final(void) {
+
+void final(void)
+{
db_destroy(vending->db);
}
-void init(bool minimal) {
+void init(bool minimal)
+{
vending->db = idb_alloc(DB_OPT_BASE);
vending->next_id = 0;
}
-void vending_defaults(void) {
+void vending_defaults(void)
+{
vending = &vending_s;
vending->init = init;