summaryrefslogtreecommitdiff
path: root/src/emap
diff options
context:
space:
mode:
Diffstat (limited to 'src/emap')
-rw-r--r--src/emap/clif.c620
-rw-r--r--src/emap/craft.c35
-rw-r--r--src/emap/craftconf.c8
-rw-r--r--src/emap/data/mapd.c3
-rw-r--r--src/emap/data/mobd.c2
-rw-r--r--src/emap/data/session.c2
-rw-r--r--src/emap/horse.c2
-rw-r--r--src/emap/lang.c2
-rw-r--r--src/emap/map.c12
-rw-r--r--src/emap/npc.c9
-rw-r--r--src/emap/packets_struct.h264
-rw-r--r--src/emap/pc.c13
-rw-r--r--src/emap/send.c8
-rw-r--r--src/emap/status.c3
-rw-r--r--src/emap/utils/formatutils.c3
15 files changed, 557 insertions, 429 deletions
diff --git a/src/emap/clif.c b/src/emap/clif.c
index 9cf2c76..ba4a2b7 100644
--- a/src/emap/clif.c
+++ b/src/emap/clif.c
@@ -72,7 +72,7 @@ void eclif_quest_send_list(TBL_PC *sd)
void eclif_quest_add(TBL_PC *sd, struct quest *qd)
{
- if (!sd)
+ if (!sd || !qd)
{
hookStop();
return;
@@ -313,7 +313,7 @@ static void eclif_send_additional_slots2(struct block_list *bl)
void eclif_getareachar_unit_post(TBL_PC* sd, struct block_list *bl)
{
- if (!bl)
+ if (!bl || !sd)
return;
if (bl->type == BL_PC)
{
@@ -324,6 +324,8 @@ void eclif_getareachar_unit_post(TBL_PC* sd, struct block_list *bl)
bool eclif_spawn_post(bool retVal, struct block_list *bl)
{
+ if (!bl)
+ return retVal;
if (retVal == true && bl->type == BL_PC)
{
send_pc_info(bl, bl, AREA);
@@ -344,8 +346,10 @@ void eclif_authok_post(TBL_PC *sd)
send_mapmask(sd->fd, mask);
}
-void eclif_changemap_post(TBL_PC *sd, short *m,
- int *x __attribute__ ((unused)), int *y __attribute__ ((unused)))
+void eclif_changemap_post(TBL_PC *sd,
+ short *m,
+ int *x __attribute__ ((unused)),
+ int *y __attribute__ ((unused)))
{
if (!sd)
return;
@@ -354,7 +358,8 @@ void eclif_changemap_post(TBL_PC *sd, short *m,
send_mapmask(sd->fd, mask);
}
-void eclif_handle_invisible_map(struct block_list *bl, enum send_target target __attribute__ ((unused)))
+void eclif_handle_invisible_map(struct block_list *bl,
+ enum send_target target __attribute__ ((unused)))
{
if (!bl || bl->type != BL_PC)
return;
@@ -595,61 +600,69 @@ static int clif_setlevel_sub(int lv) {
return lv;
}
-static int clif_setlevel(struct block_list* bl) {
- int lv = status->get_lv(bl);
- nullpo_retr(0, bl);
- if( battle->bc->client_limit_unit_lv&bl->type )
- return clif_setlevel_sub(lv);
- if (bl->type == BL_NPC || bl->type == BL_PET)
- return 0;
- return lv;
+static int clif_setlevel(struct block_list* bl)
+{
+ int lv = status->get_lv(bl);
+ nullpo_retr(0, bl);
+ if (battle->bc->client_limit_unit_lv&bl->type)
+ return clif_setlevel_sub(lv);
+ if (bl->type == BL_NPC || bl->type == BL_PET)
+ return 0;
+ return lv;
}
//To identify disguised characters.
-static inline bool disguised(struct block_list* bl) {
- return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise != -1 );
+static inline bool disguised(struct block_list* bl)
+{
+ return (bool)(bl &&
+ bl->type == BL_PC &&
+ ((TBL_PC*)bl)->disguise != -1);
}
-static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
- p += pos;
- p[0] = (uint8)(x>>2);
- p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
- p[2] = (uint8)((y<<4) | (dir&0xf));
+static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir)
+{
+ p += pos;
+ p[0] = (uint8)(x >> 2);
+ p[1] = (uint8)((x << 6) | ((y >> 4) & 0x3f));
+ p[2] = (uint8)((y << 4) | (dir & 0xf));
}
// client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
-static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
- p += pos;
- p[0] = (uint8)(x0>>2);
- p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
- p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
- p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
- p[4] = (uint8)y1;
- p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
+static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
+{
+ p += pos;
+ p[0] = (uint8)(x0>>2);
+ p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
+ p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
+ p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
+ p[4] = (uint8)y1;
+ p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
}
-static inline unsigned char clif_bl_type_old(struct block_list *bl) {
- nullpo_retr(0x1, bl);
- switch (bl->type) {
- case BL_PC: return (disguised(bl) && !pc->db_checkid(status->get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
- case BL_ITEM: return 0x2; //ITEM_TYPE
- case BL_SKILL: return 0x3; //SKILL_TYPE
- case BL_CHAT: return 0x4; //UNKNOWN_TYPE
- case BL_MOB: return pc->db_checkid(status->get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
- case BL_NPC: return pc->db_checkid(status->get_viewdata(bl)->class_)?0x0:0x6; //NPC_EVT_TYPE
- case BL_PET: return pc->db_checkid(status->get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
- case BL_HOM: return 0x8; //NPC_HOM_TYPE
- case BL_MER: return 0x9; //NPC_MERSOL_TYPE
- case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
- default: return 0x1; //NPC_TYPE
- }
+static inline unsigned char clif_bl_type_old(struct block_list *bl)
+{
+ nullpo_retr(0x1, bl);
+ switch (bl->type)
+ {
+ case BL_PC: return (disguised(bl) && !pc->db_checkid(status->get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
+ case BL_ITEM: return 0x2; //ITEM_TYPE
+ case BL_SKILL: return 0x3; //SKILL_TYPE
+ case BL_CHAT: return 0x4; //UNKNOWN_TYPE
+ case BL_MOB: return pc->db_checkid(status->get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
+ case BL_NPC: return pc->db_checkid(status->get_viewdata(bl)->class_)?0x0:0x6; //NPC_EVT_TYPE
+ case BL_PET: return pc->db_checkid(status->get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
+ case BL_HOM: return 0x8; //NPC_HOM_TYPE
+ case BL_MER: return 0x9; //NPC_MERSOL_TYPE
+ case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
+ default: return 0x1; //NPC_TYPE
+ }
}
//Modifies the type of damage according to status changes [Skotlex]
//Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
static inline int clif_calc_delay(int type, int div, int damage, int delay)
{
- return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
+ return (delay == 0 && damage > 0) ? (div > 1 ? 9 : 4) : type;
}
// this function must be used only by clients version < 16
@@ -657,138 +670,150 @@ void eclif_set_unit_idle_old(struct block_list* bl,
struct map_session_data *tsd,
enum send_target target)
{
- struct map_session_data* sd;
- struct status_change* sc = status->get_sc(bl);
- struct view_data* vd = status->get_viewdata(bl);
- struct packet_idle_unit_old p;
- int g_id = status->get_guild_id(bl);
-
- nullpo_retv(bl);
-
- sd = BL_CAST(BL_PC, bl);
-
- p.PacketType = 0x915;
- p.PacketLength = sizeof(p);
- p.objecttype = clif_bl_type_old(bl);
-// p.AID = bl->id;
-// p.GID = (sd) ? sd->status.char_id : 0; // CCODE
- p.GID = bl->id;
- p.speed = status->get_speed(bl);
- p.bodyState = (sc) ? sc->opt1 : 0;
- p.healthState = (sc) ? sc->opt2 : 0;
- p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0;
- p.job = vd->class_;
- p.head = vd->hair_style;
- p.weapon = vd->weapon;
- p.accessory = vd->head_bottom;
- p.accessory2 = vd->head_top;
- p.accessory3 = vd->head_mid;
- if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS ) { //The hell, why flags work like this?
- p.accessory = status->get_emblem_id(bl);
- p.accessory2 = GetWord(g_id, 1);
- p.accessory3 = GetWord(g_id, 0);
- }
- p.headpalette = vd->hair_color;
- p.bodypalette = vd->cloth_color;
- p.headDir = (sd)? sd->head_dir : 0;
- p.robe = vd->robe;
- p.GUID = g_id;
- p.GEmblemVer = status->get_emblem_id(bl);
- p.honor = (sd) ? sd->status.manner : 0;
- p.virtue = (sc) ? sc->opt3 : 0;
- p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
- p.sex = vd->sex;
- WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
- p.xSize = p.ySize = (sd) ? 5 : 0;
- p.state = vd->dead_sit;
- p.clevel = clif_setlevel(bl);
- p.font = (sd) ? sd->status.font : 0;
- if (battle->bc->show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) {
- p.maxHP = status_get_max_hp(bl);
- p.HP = status_get_hp(bl);
- p.isBoss = ( ((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss ) ? 1 : 0;
- } else {
- p.maxHP = -1;
- p.HP = -1;
- p.isBoss = 0;
- }
+ struct map_session_data* sd;
+ struct status_change* sc = status->get_sc(bl);
+ struct view_data* vd = status->get_viewdata(bl);
+ struct packet_idle_unit_old p;
+ int g_id = status->get_guild_id(bl);
- clif->send(&p,sizeof(p),tsd?&tsd->bl:bl,target);
+ nullpo_retv(bl);
- if( disguised(bl) ) {
- p.objecttype = pc->db_checkid(status->get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
- p.GID = -bl->id;
- clif->send(&p,sizeof(p),bl,SELF);
- }
+ sd = BL_CAST(BL_PC, bl);
+
+ p.PacketType = 0x915;
+ p.PacketLength = sizeof(p);
+ p.objecttype = clif_bl_type_old(bl);
+// p.AID = bl->id;
+// p.GID = (sd) ? sd->status.char_id : 0; // CCODE
+ p.GID = bl->id;
+ p.speed = status->get_speed(bl);
+ p.bodyState = (sc) ? sc->opt1 : 0;
+ p.healthState = (sc) ? sc->opt2 : 0;
+ p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0;
+ p.job = vd->class_;
+ p.head = vd->hair_style;
+ p.weapon = vd->weapon;
+ p.accessory = vd->head_bottom;
+ p.accessory2 = vd->head_top;
+ p.accessory3 = vd->head_mid;
+ if (bl->type == BL_NPC && vd->class_ == FLAG_CLASS)
+ { //The hell, why flags work like this?
+ p.accessory = status->get_emblem_id(bl);
+ p.accessory2 = GetWord(g_id, 1);
+ p.accessory3 = GetWord(g_id, 0);
+ }
+ p.headpalette = vd->hair_color;
+ p.bodypalette = vd->cloth_color;
+ p.headDir = (sd)? sd->head_dir : 0;
+ p.robe = vd->robe;
+ p.GUID = g_id;
+ p.GEmblemVer = status->get_emblem_id(bl);
+ p.honor = (sd) ? sd->status.manner : 0;
+ p.virtue = (sc) ? sc->opt3 : 0;
+ p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
+ p.sex = vd->sex;
+ WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
+ p.xSize = p.ySize = (sd) ? 5 : 0;
+ p.state = vd->dead_sit;
+ p.clevel = clif_setlevel(bl);
+ p.font = (sd) ? sd->status.font : 0;
+ if (battle->bc->show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl))
+ {
+ p.maxHP = status_get_max_hp(bl);
+ p.HP = status_get_hp(bl);
+ p.isBoss = (((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss) ? 1 : 0;
+ }
+ else
+ {
+ p.maxHP = -1;
+ p.HP = -1;
+ p.isBoss = 0;
+ }
+
+ clif->send(&p,sizeof(p), tsd ? &tsd->bl : bl, target);
+
+ if (disguised(bl))
+ {
+ p.objecttype = pc->db_checkid(status->get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
+ p.GID = -bl->id;
+ clif->send(&p,sizeof(p),bl,SELF);
+ }
}
void eclif_spawn_unit_old(struct block_list* bl, enum send_target target)
{
- struct map_session_data* sd;
- struct status_change* sc = status->get_sc(bl);
- struct view_data* vd = status->get_viewdata(bl);
- struct packet_spawn_unit_old p;
- int g_id = status->get_guild_id(bl);
-
- nullpo_retv(bl);
-
- sd = BL_CAST(BL_PC, bl);
-
- p.PacketType = 0x90f;
- p.PacketLength = sizeof(p);
- p.objecttype = clif_bl_type_old(bl);
-// p.AID = bl->id;
-// p.GID = (sd) ? sd->status.char_id : 0; // CCODE
- p.GID = bl->id;
- p.speed = status->get_speed(bl);
- p.bodyState = (sc) ? sc->opt1 : 0;
- p.healthState = (sc) ? sc->opt2 : 0;
- p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0;
- p.job = vd->class_;
- p.head = vd->hair_style;
- p.weapon = vd->weapon;
- p.accessory = vd->head_bottom;
- p.accessory2 = vd->head_top;
- p.accessory3 = vd->head_mid;
- if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS ) { //The hell, why flags work like this?
- p.accessory = status->get_emblem_id(bl);
- p.accessory2 = GetWord(g_id, 1);
- p.accessory3 = GetWord(g_id, 0);
- }
- p.headpalette = vd->hair_color;
- p.bodypalette = vd->cloth_color;
- p.headDir = (sd)? sd->head_dir : 0;
- p.robe = vd->robe;
- p.GUID = g_id;
- p.GEmblemVer = status->get_emblem_id(bl);
- p.honor = (sd) ? sd->status.manner : 0;
- p.virtue = (sc) ? sc->opt3 : 0;
- p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
- p.sex = vd->sex;
- WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
- p.xSize = p.ySize = (sd) ? 5 : 0;
- p.clevel = clif_setlevel(bl);
- p.font = (sd) ? sd->status.font : 0;
- if (battle->bc->show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) {
- p.maxHP = status_get_max_hp(bl);
- p.HP = status_get_hp(bl);
- p.isBoss = ( ((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss ) ? 1 : 0;
- } else {
- p.maxHP = -1;
- p.HP = -1;
- p.isBoss = 0;
- }
- if( disguised(bl) ) {
- nullpo_retv(sd);
- if( sd->status.class_ != sd->disguise )
- clif->send(&p,sizeof(p),bl,target);
- p.objecttype = pc->db_checkid(status->get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
- p.GID = -bl->id;
- clif->send(&p,sizeof(p),bl,SELF);
- } else
- clif->send(&p,sizeof(p),bl,target);
+ struct map_session_data* sd;
+ struct status_change* sc = status->get_sc(bl);
+ struct view_data* vd = status->get_viewdata(bl);
+ struct packet_spawn_unit_old p;
+ int g_id = status->get_guild_id(bl);
+
+ nullpo_retv(bl);
+ sd = BL_CAST(BL_PC, bl);
+
+ p.PacketType = 0x90f;
+ p.PacketLength = sizeof(p);
+ p.objecttype = clif_bl_type_old(bl);
+// p.AID = bl->id;
+// p.GID = (sd) ? sd->status.char_id : 0; // CCODE
+ p.GID = bl->id;
+ p.speed = status->get_speed(bl);
+ p.bodyState = (sc) ? sc->opt1 : 0;
+ p.healthState = (sc) ? sc->opt2 : 0;
+ p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0;
+ p.job = vd->class_;
+ p.head = vd->hair_style;
+ p.weapon = vd->weapon;
+ p.accessory = vd->head_bottom;
+ p.accessory2 = vd->head_top;
+ p.accessory3 = vd->head_mid;
+ if (bl->type == BL_NPC && vd->class_ == FLAG_CLASS)
+ { //The hell, why flags work like this?
+ p.accessory = status->get_emblem_id(bl);
+ p.accessory2 = GetWord(g_id, 1);
+ p.accessory3 = GetWord(g_id, 0);
+ }
+ p.headpalette = vd->hair_color;
+ p.bodypalette = vd->cloth_color;
+ p.headDir = (sd)? sd->head_dir : 0;
+ p.robe = vd->robe;
+ p.GUID = g_id;
+ p.GEmblemVer = status->get_emblem_id(bl);
+ p.honor = (sd) ? sd->status.manner : 0;
+ p.virtue = (sc) ? sc->opt3 : 0;
+ p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
+ p.sex = vd->sex;
+ WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
+ p.xSize = p.ySize = (sd) ? 5 : 0;
+ p.clevel = clif_setlevel(bl);
+ p.font = (sd) ? sd->status.font : 0;
+ if (battle->bc->show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl))
+ {
+ p.maxHP = status_get_max_hp(bl);
+ p.HP = status_get_hp(bl);
+ p.isBoss = (((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss) ? 1 : 0;
+ }
+ else
+ {
+ p.maxHP = -1;
+ p.HP = -1;
+ p.isBoss = 0;
+ }
+ if (disguised(bl))
+ {
+ nullpo_retv(sd);
+ if (sd->status.class_ != sd->disguise)
+ clif->send(&p, sizeof(p), bl, target);
+ p.objecttype = pc->db_checkid(status->get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
+ p.GID = -bl->id;
+ clif->send(&p, sizeof(p), bl, SELF);
+ }
+ else
+ {
+ clif->send(&p, sizeof(p), bl, target);
+ }
}
void eclif_set_unit_walking_old(struct block_list* bl,
@@ -796,65 +821,69 @@ void eclif_set_unit_walking_old(struct block_list* bl,
struct unit_data* ud,
enum send_target target)
{
- struct map_session_data* sd;
- struct status_change* sc = status->get_sc(bl);
- struct view_data* vd = status->get_viewdata(bl);
- struct packet_unit_walking_old p;
- int g_id = status->get_guild_id(bl);
-
- nullpo_retv(bl);
- nullpo_retv(ud);
-
- sd = BL_CAST(BL_PC, bl);
-
- p.PacketType = 0x914;
- p.PacketLength = sizeof(p);
- p.objecttype = clif_bl_type_old(bl);
-// p.AID = bl->id;
-// p.GID = (tsd) ? tsd->status.char_id : 0; // CCODE
- p.GID = bl->id;
- p.speed = status->get_speed(bl);
- p.bodyState = (sc) ? sc->opt1 : 0;
- p.healthState = (sc) ? sc->opt2 : 0;
- p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0;
- p.job = vd->class_;
- p.head = vd->hair_style;
- p.weapon = vd->weapon;
- p.accessory = vd->head_bottom;
- p.moveStartTime = (unsigned int)timer->gettick();
- p.accessory2 = vd->head_top;
- p.accessory3 = vd->head_mid;
- p.headpalette = vd->hair_color;
- p.bodypalette = vd->cloth_color;
- p.headDir = (sd)? sd->head_dir : 0;
- p.robe = vd->robe;
- p.GUID = g_id;
- p.GEmblemVer = status->get_emblem_id(bl);
- p.honor = (sd) ? sd->status.manner : 0;
- p.virtue = (sc) ? sc->opt3 : 0;
- p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
- p.sex = vd->sex;
- WBUFPOS2(&p.MoveData[0],0,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
- p.xSize = p.ySize = (sd) ? 5 : 0;
- p.clevel = clif_setlevel(bl);
- p.font = (sd) ? sd->status.font : 0;
- if (battle->bc->show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) {
- p.maxHP = status_get_max_hp(bl);
- p.HP = status_get_hp(bl);
- p.isBoss = ( ((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss ) ? 1 : 0;
- } else {
- p.maxHP = -1;
- p.HP = -1;
- p.isBoss = 0;
- }
+ struct map_session_data* sd;
+ struct status_change* sc = status->get_sc(bl);
+ struct view_data* vd = status->get_viewdata(bl);
+ struct packet_unit_walking_old p;
+ int g_id = status->get_guild_id(bl);
- clif->send(&p,sizeof(p),tsd?&tsd->bl:bl,target);
+ nullpo_retv(bl);
+ nullpo_retv(ud);
- if( disguised(bl) ) {
- p.objecttype = pc->db_checkid(status->get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
- p.GID = -bl->id;
- clif->send(&p,sizeof(p),bl,SELF);
- }
+ sd = BL_CAST(BL_PC, bl);
+
+ p.PacketType = 0x914;
+ p.PacketLength = sizeof(p);
+ p.objecttype = clif_bl_type_old(bl);
+// p.AID = bl->id;
+// p.GID = (tsd) ? tsd->status.char_id : 0; // CCODE
+ p.GID = bl->id;
+ p.speed = status->get_speed(bl);
+ p.bodyState = (sc) ? sc->opt1 : 0;
+ p.healthState = (sc) ? sc->opt2 : 0;
+ p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0;
+ p.job = vd->class_;
+ p.head = vd->hair_style;
+ p.weapon = vd->weapon;
+ p.accessory = vd->head_bottom;
+ p.moveStartTime = (unsigned int)timer->gettick();
+ p.accessory2 = vd->head_top;
+ p.accessory3 = vd->head_mid;
+ p.headpalette = vd->hair_color;
+ p.bodypalette = vd->cloth_color;
+ p.headDir = (sd)? sd->head_dir : 0;
+ p.robe = vd->robe;
+ p.GUID = g_id;
+ p.GEmblemVer = status->get_emblem_id(bl);
+ p.honor = (sd) ? sd->status.manner : 0;
+ p.virtue = (sc) ? sc->opt3 : 0;
+ p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
+ p.sex = vd->sex;
+ WBUFPOS2(&p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8);
+ p.xSize = p.ySize = (sd) ? 5 : 0;
+ p.clevel = clif_setlevel(bl);
+ p.font = (sd) ? sd->status.font : 0;
+ if (battle->bc->show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl))
+ {
+ p.maxHP = status_get_max_hp(bl);
+ p.HP = status_get_hp(bl);
+ p.isBoss = (((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss) ? 1 : 0;
+ }
+ else
+ {
+ p.maxHP = -1;
+ p.HP = -1;
+ p.isBoss = 0;
+ }
+
+ clif->send(&p, sizeof(p), tsd ? &tsd->bl : bl, target);
+
+ if (disguised(bl))
+ {
+ p.objecttype = pc->db_checkid(status->get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
+ p.GID = -bl->id;
+ clif->send(&p, sizeof(p), bl, SELF);
+ }
}
void eclif_damage_old(struct block_list* src,
@@ -866,67 +895,82 @@ void eclif_damage_old(struct block_list* src,
unsigned char type,
int64 in_damage2)
{
- struct packet_damage_old p;
- struct status_change *sc;
- int damage,damage2;
+ struct packet_damage_old p;
+ struct status_change *sc;
+ int damage,damage2;
- nullpo_retv(src);
- nullpo_retv(dst);
+ nullpo_retv(src);
+ nullpo_retv(dst);
- sc = status->get_sc(dst);
+ sc = status->get_sc(dst);
- if(sc && sc->count && sc->data[SC_ILLUSION]) {
- if(in_damage) in_damage = in_damage*(sc->data[SC_ILLUSION]->val2); //+ rnd()%100;
- if(in_damage2) in_damage2 = in_damage2*(sc->data[SC_ILLUSION]->val2); //+ rnd()%100;
- }
+ if (sc && sc->count && sc->data[SC_ILLUSION])
+ {
+ if(in_damage)
+ in_damage = in_damage*(sc->data[SC_ILLUSION]->val2); //+ rnd()%100;
+ if(in_damage2)
+ in_damage2 = in_damage2*(sc->data[SC_ILLUSION]->val2); //+ rnd()%100;
+ }
- damage = (int)min(in_damage,INT_MAX);
- damage2 = (int)min(in_damage2,INT_MAX);
+ damage = (int)min(in_damage,INT_MAX);
+ damage2 = (int)min(in_damage2,INT_MAX);
- type = clif_calc_delay(type,div,damage+damage2,ddelay);
+ type = clif_calc_delay(type,div,damage+damage2,ddelay);
- p.PacketType = 0x2e1;
- p.GID = src->id;
- p.targetGID = dst->id;
- p.startTime = (uint32)timer->gettick();
- p.attackMT = sdelay;
- p.attackedMT = ddelay;
- p.count = div;
- p.action = type;
+ p.PacketType = 0x2e1;
+ p.GID = src->id;
+ p.targetGID = dst->id;
+ p.startTime = (uint32)timer->gettick();
+ p.attackMT = sdelay;
+ p.attackedMT = ddelay;
+ p.count = div;
+ p.action = type;
- if (battle->bc->hide_woe_damage && map_flag_gvg2(src->m) ) {
- p.damage = damage?div:0;
- p.leftDamage = damage2?div:0;
- } else {
- p.damage = damage;
- p.leftDamage = damage2;
- }
-// p.is_sp_damaged = 0; // [ToDo] IsSPDamage - Displays blue digits.
+ if (battle->bc->hide_woe_damage && map_flag_gvg2(src->m))
+ {
+ p.damage = damage ? div : 0;
+ p.leftDamage = damage2 ? div : 0;
+ }
+ else
+ {
+ p.damage = damage;
+ p.leftDamage = damage2;
+ }
+// p.is_sp_damaged = 0; // [ToDo] IsSPDamage - Displays blue digits.
- if(disguised(dst)) {
- clif->send(&p,sizeof(p),dst,AREA_WOS);
- p.targetGID = -dst->id;
- clif->send(&p,sizeof(p),dst,SELF);
- } else
- clif->send(&p,sizeof(p),dst,AREA);
+ if (disguised(dst))
+ {
+ clif->send(&p, sizeof(p), dst, AREA_WOS);
+ p.targetGID = -dst->id;
+ clif->send(&p, sizeof(p), dst, SELF);
+ }
+ else
+ {
+ clif->send(&p, sizeof(p), dst, AREA);
+ }
- if(disguised(src)) {
- p.GID = -src->id;
- if (disguised(dst))
- p.targetGID = dst->id;
+ if (disguised(src))
+ {
+ p.GID = -src->id;
+ if (disguised(dst))
+ p.targetGID = dst->id;
- if(damage > 0) p.damage = -1;
- if(damage2 > 0) p.leftDamage = -1;
+ if(damage > 0)
+ p.damage = -1;
+ if(damage2 > 0)
+ p.leftDamage = -1;
- clif->send(&p,sizeof(p),src,SELF);
- }
+ clif->send(&p, sizeof(p), src, SELF);
+ }
- if(src == dst) {
- unit->setdir(src,unit->getdir(src));
- }
+ if (src == dst)
+ {
+ unit->setdir(src, unit->getdir(src));
+ }
}
-void eclif_set_unit_idle_post(struct block_list* bl, TBL_PC *tsd,
+void eclif_set_unit_idle_post(struct block_list* bl,
+ TBL_PC *tsd,
enum send_target *target)
{
if (!bl || !tsd)
@@ -942,15 +986,21 @@ void eclif_set_unit_idle_post(struct block_list* bl, TBL_PC *tsd,
send_npc_info(bl, &tsd->bl, *target);
}
-void eclif_set_unit_walking_pre(struct block_list* bl, TBL_PC *tsd,
- struct unit_data* ud, enum send_target *target)
+void eclif_set_unit_walking_pre(struct block_list* bl,
+ TBL_PC *tsd,
+ struct unit_data* ud,
+ enum send_target *target)
{
eclif_set_unit_walking_old(bl, tsd, ud, *target);
}
-void eclif_set_unit_walking_post(struct block_list* bl, TBL_PC *tsd,
- struct unit_data* ud, enum send_target *target)
+void eclif_set_unit_walking_post(struct block_list* bl,
+ TBL_PC *tsd,
+ struct unit_data* ud,
+ enum send_target *target)
{
+ if (!ud)
+ return;
TBL_PC *sd = BL_CAST(BL_PC, ud->bl);
if (!sd || !pc_isinvisible(sd))
{
@@ -979,6 +1029,8 @@ int eclif_damage_post(int retVal,
void eclif_move(struct unit_data *ud)
{
+ if (!ud)
+ return;
TBL_PC *sd = BL_CAST(BL_PC, ud->bl);
if (!sd || !pc_isinvisible(sd))
send_advmoving(ud, false, ud->bl, AREA_WOS);
@@ -994,6 +1046,8 @@ bool tempChangeMap;
void eclif_parse_LoadEndAck_pre(int *fdPtr __attribute__ ((unused)),
struct map_session_data *sd)
{
+ if (!sd)
+ return;
sd->state.warp_clean = 0;
tempChangeMap = sd->state.changemap;
}
@@ -1008,8 +1062,11 @@ void eclif_parse_LoadEndAck_post(int *fdPtr __attribute__ ((unused)),
map_alwaysVisible_send(sd);
}
-void eclif_changelook2(struct block_list *bl, int type, int val,
- struct item_data *id, int n)
+void eclif_changelook2(struct block_list *bl,
+ int type,
+ int val,
+ struct item_data *id,
+ int n)
{
struct map_session_data* sd;
struct status_change* sc;
@@ -1142,9 +1199,12 @@ static inline int itemtype(const int type)
}
}
-void eclif_getareachar_item(struct map_session_data *sd, struct flooritem_data *fitem)
+void eclif_getareachar_item(struct map_session_data *sd,
+ struct flooritem_data *fitem)
{
int view;
+ if (!sd || !fitem)
+ return;
int fd = sd->fd;
struct SessionExt *data = session_get(fd);
@@ -1177,6 +1237,8 @@ void eclif_dropflooritem(struct flooritem_data* fitem)
char buf[28];
int view;
+ if (!fitem)
+ return;
struct ItemdExt *itemData = itemd_get_by_item(&fitem->item_data);
if (itemData)
{
diff --git a/src/emap/craft.c b/src/emap/craft.c
index e8e2cdd..59ebfa0 100644
--- a/src/emap/craft.c
+++ b/src/emap/craft.c
@@ -154,6 +154,8 @@ bool craft_checkstr(TBL_PC *sd, const char *craftstr)
struct craft_vardata *craft_str_to_craft(const char *craftstr)
{
+ if (!craftstr)
+ return false;
struct strutil_data *craftdata = strutil_split(craftstr, '|', craft_inventory_size + 1);
if (!craftdata)
return false;
@@ -236,6 +238,8 @@ int str_to_craftvar(TBL_PC *sd, const char *craftstr)
void craft_dump(TBL_PC *sd, const int id)
{
struct craft_vardata *craft = idb_get(craftvar_db, id);
+ if (!sd)
+ return;
if (!craft)
{
ShowError("Craft object with id %d not exists.\n", id);
@@ -312,6 +316,8 @@ struct craft_slot *craft_get_slot(const int id, const int slot)
bool craft_validate(TBL_PC *sd, const int id)
{
struct craft_vardata *craft = idb_get(craftvar_db, id);
+ if (!sd)
+ return false;
if (!craft)
{
ShowError("Craft object with id %d not exists.\n", id);
@@ -364,6 +370,8 @@ static int find_inventory_item(TBL_PC *sd,
const int amount)
{
int i;
+ if (!sd)
+ return -1;
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid == id &&
@@ -380,6 +388,8 @@ static int find_inventory_equipped_item(TBL_PC *sd,
const int id)
{
int i;
+ if (!sd)
+ return -1;
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid == id &&
@@ -396,6 +406,8 @@ static int find_local_inventory_item(struct item_pair *local_inventory,
const int id)
{
int i;
+ if (!local_inventory)
+ return -1;
for (i = 0; i < MAX_INVENTORY; i++)
{
struct item_pair *pair = &local_inventory[i];
@@ -413,6 +425,8 @@ static bool check_items_collection(struct item_pair *local_inventory,
{
int len = VECTOR_LENGTH(*vector);
int i;
+ if (!local_inventory)
+ return false;
if (len > 0)
{
for (i = 0; i < len; i ++)
@@ -467,6 +481,8 @@ static bool check_skills(TBL_PC *sd,
{
int len = VECTOR_LENGTH(*vector);
int i;
+ if (!sd)
+ return false;
if (len > 0)
{
for (i = 0; i < len; i ++)
@@ -487,6 +503,8 @@ static bool check_quests(TBL_PC *sd,
{
int len = VECTOR_LENGTH(*vector);
int i;
+ if (!sd)
+ return false;
if (len > 0)
{
for (i = 0; i < len; i ++)
@@ -508,6 +526,8 @@ static bool check_inventories(TBL_PC *sd,
struct craft_db_entry *entry,
struct item_pair *craft_inventory)
{
+ if (!entry || !craft_inventory)
+ return false;
int inv_count = VECTOR_LENGTH(entry->inventories);
bool correct = true;
@@ -543,6 +563,8 @@ static void simplify_craftvar(TBL_PC *sd,
{
int i;
+ if (!craft || !craft_inventory)
+ return false;
// combine different slots from inventory var into one slot with id and amount
for (i = 0; i < craft_inventory_size; i ++)
{
@@ -571,6 +593,8 @@ static void init_inventory_copy(TBL_PC *sd,
struct item_pair *local_inventory)
{
int f;
+ if (!sd || !local_inventory)
+ return;
for (f = 0; f < MAX_INVENTORY; f ++)
{
const int id = sd->status.inventory[f].nameid;
@@ -596,6 +620,8 @@ static bool apply_craft_inventory(struct craft_db_inventory *entry_inventory,
struct item_pair *local_inventory)
{
int f;
+ if (!entry_inventory || !craft || !local_inventory)
+ return false;
for (f = 0; f < craft_inventory_size; f ++)
{
struct item_pair *entryItem = &entry_inventory->items[f];
@@ -713,6 +739,8 @@ int craft_find_entry(TBL_PC *sd,
static bool craft_delete_items(TBL_PC *sd,
struct craft_items_collection *vector)
{
+ if (!sd || !vector)
+ return false;
int len = VECTOR_LENGTH(*vector);
int i;
if (len > 0)
@@ -732,7 +760,8 @@ static bool craft_delete_items(TBL_PC *sd,
static bool craft_create_items(TBL_PC *sd,
struct craft_db_entry *entry)
{
- // +++ for now used 0 index, but need select random
+ if (!sd || !entry)
+ return false;
const int vars = VECTOR_LENGTH(entry->create_items);
struct craft_items_collection *vector = &VECTOR_INDEX(entry->create_items,
(rand() % (vars * 10)) / 10);
@@ -805,10 +834,12 @@ bool craft_use(TBL_PC *sd,
const int id)
{
struct craft_vardata *craft = idb_get(craftvar_db, id);
+ if (!sd)
+ return false;
if (!craft)
{
ShowError("Craft object with id %d not exists.\n", id);
- return -1;
+ return false;
}
struct craft_db_entry *entry = idb_get(craftconf_db, craft->entry_id);
if (!entry)
diff --git a/src/emap/craftconf.c b/src/emap/craftconf.c
index ecab0ac..f4e52bd 100644
--- a/src/emap/craftconf.c
+++ b/src/emap/craftconf.c
@@ -77,7 +77,7 @@ static int craft_get_item_id(struct craft_db_entry *entry,
const char *const name,
const char *const fieldName)
{
- if (!strcmp(name, "Empty"))
+ if (!strcmp(name, "Empty") || !entry || !errorMessage)
return 0;
struct item_data* id = itemdb->search_name(name);
@@ -94,7 +94,7 @@ static void craft_read_source_inventory(struct craft_db_entry *entry,
{
int i32;
int i = 0;
- if (!tt || !config_setting_is_group(tt))
+ if (!entry || !tt || !config_setting_is_group(tt))
return;
struct config_setting_t *item;
@@ -139,7 +139,7 @@ static void craft_read_create_items(struct craft_db_entry *entry,
{
int i32;
int i = 0;
- if (!tt || !config_setting_is_group(tt))
+ if (!entry || !tt || !config_setting_is_group(tt))
return;
struct config_setting_t *item;
@@ -190,7 +190,7 @@ static void craft_read_items_collection(struct craft_db_entry *entry,
{
int i32;
int i = 0;
- if (!t)
+ if (!entry || !t || !vector)
return;
struct config_setting_t *tt = libconfig->setting_get_member(t, fieldName);
diff --git a/src/emap/data/mapd.c b/src/emap/data/mapd.c
index e7f7ee4..52440d7 100644
--- a/src/emap/data/mapd.c
+++ b/src/emap/data/mapd.c
@@ -19,6 +19,9 @@
struct MapdExt *mapd_get(int m)
{
+ if (m < 0 || m >= map->count)
+ return NULL;
+
struct map_data *md = &map->list[m];
struct MapdExt *data = getFromMAPD(md, 0);
if (!data)
diff --git a/src/emap/data/mobd.c b/src/emap/data/mobd.c
index 0df31e7..e3a6c34 100644
--- a/src/emap/data/mobd.c
+++ b/src/emap/data/mobd.c
@@ -34,7 +34,7 @@ struct MobdExt *mobd_get(struct mob_db *md)
struct MobdExt *mobd_get_by_mob(TBL_MOB *md)
{
- if (!mob)
+ if (!md)
return NULL;
return mobd_get(mob->db_data[md->class_]);
diff --git a/src/emap/data/session.c b/src/emap/data/session.c
index dea86e6..33ddb41 100644
--- a/src/emap/data/session.c
+++ b/src/emap/data/session.c
@@ -19,6 +19,8 @@
struct SessionExt *session_get(int fd)
{
+ if (fd < 0)
+ return NULL;
struct SessionExt *data = getFromSession(sockt->session[fd], 0);
if (!data)
{
diff --git a/src/emap/horse.c b/src/emap/horse.c
index f56926f..90c736e 100644
--- a/src/emap/horse.c
+++ b/src/emap/horse.c
@@ -21,7 +21,7 @@
void horse_add_bonus(TBL_PC *sd)
{
struct SessionExt *data = session_get_bysd(sd);
- if (!data || data->mount == 0)
+ if (!sd || !data || data->mount == 0)
return;
struct status_data *bstatus = &sd->base_status;
diff --git a/src/emap/lang.c b/src/emap/lang.c
index 60259da..2cd838e 100644
--- a/src/emap/lang.c
+++ b/src/emap/lang.c
@@ -205,6 +205,8 @@ const char* lang_pctrans(const char *str, TBL_PC *sd)
int lang_getId(const char *str)
{
+ if (!str)
+ return -1;
char *str1 = aStrdup(str);
char *str2 = NULL;
int f;
diff --git a/src/emap/map.c b/src/emap/map.c
index 7e43f8b..4392132 100644
--- a/src/emap/map.c
+++ b/src/emap/map.c
@@ -79,7 +79,7 @@ int emap_addflooritem_post(int retVal,
if (fitem->cleartimer != INVALID_TIMER)
{
int timeout = battle->bc->flooritem_lifetime;
- struct ItemdExt *data = itemd_get_by_item(item);
+ struct ItemdExt *data = itemd_get_by_item(item);
if (data)
timeout = data->floorLifeTime;
timer->delete(fitem->cleartimer, map->clearflooritem_timer);
@@ -184,6 +184,8 @@ void emap_online_list(int fd)
static int getWalkMask(const struct block_list *bl)
{
int walkMask = 0;
+ if (!bl)
+ return 0;
if (bl->type == BL_NPC)
{
TBL_NPC *nd = (TBL_NPC *)bl;
@@ -367,8 +369,12 @@ void emap_setgatcell2(int16 m, int16 x, int16 y, int gat)
{
int j;
- if (m < 0 || m >= map->count ||
- x < 0 || x >= map->list[m].xs || y < 0 || y >= map->list[m].ys)
+ if (m < 0 ||
+ m >= map->count ||
+ x < 0 ||
+ x >= map->list[m].xs ||
+ y < 0 ||
+ y >= map->list[m].ys)
{
return;
}
diff --git a/src/emap/npc.c b/src/emap/npc.c
index 1fd3328..f4cb0f2 100644
--- a/src/emap/npc.c
+++ b/src/emap/npc.c
@@ -22,8 +22,13 @@
#include "emap/struct/npcdext.h"
#include "emap/npc.h"
-void enpc_parse_unknown_mapflag(const char *name, const char *w3, const char *w4, const char* start,
- const char* buffer, const char* filepath, int *retval)
+void enpc_parse_unknown_mapflag(const char *name,
+ const char *w3,
+ const char *w4,
+ const char* start,
+ const char* buffer,
+ const char* filepath,
+ int *retval)
{
if (!strcmpi(w3, "invisible"))
{
diff --git a/src/emap/packets_struct.h b/src/emap/packets_struct.h
index 52b0dc5..1d218b5 100644
--- a/src/emap/packets_struct.h
+++ b/src/emap/packets_struct.h
@@ -27,222 +27,222 @@
#include "common/mmo.h"
struct packet_idle_unit_old {
- short PacketType;
+ short PacketType;
#if PACKETVER >= 20091103
- short PacketLength;
- unsigned char objecttype;
+ short PacketLength;
+ unsigned char objecttype;
#endif
//#if PACKETVER >= 20131223
-// unsigned int AID;
+// unsigned int AID;
//#endif
- unsigned int GID;
- short speed;
- short bodyState;
- short healthState;
+ unsigned int GID;
+ short speed;
+ short bodyState;
+ short healthState;
#if PACKETVER < 20080102
- short effectState;
+ short effectState;
#else
- int effectState;
+ int effectState;
#endif
- short job;
- short head;
+ short job;
+ short head;
#if PACKETVER < 7
- short weapon;
+ short weapon;
#else
- int weapon;
+ int weapon;
#endif
- short accessory;
+ short accessory;
#if PACKETVER < 7
- short shield;
+ short shield;
#endif
- short accessory2;
- short accessory3;
- short headpalette;
- short bodypalette;
- short headDir;
+ short accessory2;
+ short accessory3;
+ short headpalette;
+ short bodypalette;
+ short headDir;
#if PACKETVER >= 20101124
- short robe;
+ short robe;
#endif
- unsigned int GUID;
- short GEmblemVer;
- short honor;
+ unsigned int GUID;
+ short GEmblemVer;
+ short honor;
#if PACKETVER > 7
- int virtue;
+ int virtue;
#else
- short virtue;
-#endif
- uint8 isPKModeON;
- unsigned char sex;
- unsigned char PosDir[3];
- unsigned char xSize;
- unsigned char ySize;
- unsigned char state;
- short clevel;
+ short virtue;
+#endif
+ uint8 isPKModeON;
+ unsigned char sex;
+ unsigned char PosDir[3];
+ unsigned char xSize;
+ unsigned char ySize;
+ unsigned char state;
+ short clevel;
#if PACKETVER >= 20080102
- short font;
+ short font;
#endif
#if PACKETVER >= 20120221
- int maxHP;
- int HP;
- unsigned char isBoss;
+ int maxHP;
+ int HP;
+ unsigned char isBoss;
#endif
#if PACKETVER >= 20150513
- short body;
+ short body;
#endif
} __attribute__((packed));
struct packet_spawn_unit_old {
- short PacketType;
+ short PacketType;
#if PACKETVER >= 20091103
- short PacketLength;
- unsigned char objecttype;
+ short PacketLength;
+ unsigned char objecttype;
#endif
//#if PACKETVER >= 20131223
-// unsigned int AID;
+// unsigned int AID;
//#endif
- unsigned int GID;
- short speed;
- short bodyState;
- short healthState;
+ unsigned int GID;
+ short speed;
+ short bodyState;
+ short healthState;
#if PACKETVER < 20080102
- short effectState;
+ short effectState;
#else
- int effectState;
+ int effectState;
#endif
- short job;
- short head;
+ short job;
+ short head;
#if PACKETVER < 7
- short weapon;
+ short weapon;
#else
- int weapon;
+ int weapon;
#endif
- short accessory;
+ short accessory;
#if PACKETVER < 7
- short shield;
+ short shield;
#endif
- short accessory2;
- short accessory3;
- short headpalette;
- short bodypalette;
- short headDir;
+ short accessory2;
+ short accessory3;
+ short headpalette;
+ short bodypalette;
+ short headDir;
#if PACKETVER >= 20101124
- short robe;
+ short robe;
#endif
- unsigned int GUID;
- short GEmblemVer;
- short honor;
+ unsigned int GUID;
+ short GEmblemVer;
+ short honor;
#if PACKETVER > 7
- int virtue;
+ int virtue;
#else
- short virtue;
-#endif
- uint8 isPKModeON;
- unsigned char sex;
- unsigned char PosDir[3];
- unsigned char xSize;
- unsigned char ySize;
- short clevel;
+ short virtue;
+#endif
+ uint8 isPKModeON;
+ unsigned char sex;
+ unsigned char PosDir[3];
+ unsigned char xSize;
+ unsigned char ySize;
+ short clevel;
#if PACKETVER >= 20080102
- short font;
+ short font;
#endif
#if PACKETVER >= 20120221
- int maxHP;
- int HP;
- unsigned char isBoss;
+ int maxHP;
+ int HP;
+ unsigned char isBoss;
#endif
#if PACKETVER >= 20150513
- short body;
+ short body;
#endif
} __attribute__((packed));
struct packet_unit_walking_old {
- short PacketType;
+ short PacketType;
#if PACKETVER >= 20091103
- short PacketLength;
+ short PacketLength;
#endif
#if PACKETVER > 20071106
- unsigned char objecttype;
+ unsigned char objecttype;
#endif
//#if PACKETVER >= 20131223
-// unsigned int AID;
+// unsigned int AID;
//#endif
- unsigned int GID;
- short speed;
- short bodyState;
- short healthState;
+ unsigned int GID;
+ short speed;
+ short bodyState;
+ short healthState;
#if PACKETVER < 7
- short effectState;
+ short effectState;
#else
- int effectState;
+ int effectState;
#endif
- short job;
- short head;
+ short job;
+ short head;
#if PACKETVER < 7
- short weapon;
+ short weapon;
#else
- int weapon;
+ int weapon;
#endif
- short accessory;
- unsigned int moveStartTime;
+ short accessory;
+ unsigned int moveStartTime;
#if PACKETVER < 7
- short shield;
+ short shield;
#endif
- short accessory2;
- short accessory3;
- short headpalette;
- short bodypalette;
- short headDir;
+ short accessory2;
+ short accessory3;
+ short headpalette;
+ short bodypalette;
+ short headDir;
#if PACKETVER >= 20101124
- short robe;
+ short robe;
#endif
- unsigned int GUID;
- short GEmblemVer;
- short honor;
+ unsigned int GUID;
+ short GEmblemVer;
+ short honor;
#if PACKETVER > 7
- int virtue;
+ int virtue;
#else
- short virtue;
-#endif
- uint8 isPKModeON;
- unsigned char sex;
- unsigned char MoveData[6];
- unsigned char xSize;
- unsigned char ySize;
- short clevel;
+ short virtue;
+#endif
+ uint8 isPKModeON;
+ unsigned char sex;
+ unsigned char MoveData[6];
+ unsigned char xSize;
+ unsigned char ySize;
+ short clevel;
#if PACKETVER >= 20080102
- short font;
+ short font;
#endif
#if PACKETVER >= 20120221
- int maxHP;
- int HP;
- unsigned char isBoss;
+ int maxHP;
+ int HP;
+ unsigned char isBoss;
#endif
#if PACKETVER >= 20150513
- short body;
+ short body;
#endif
} __attribute__((packed));
struct packet_damage_old {
- short PacketType;
- unsigned int GID;
- unsigned int targetGID;
- unsigned int startTime;
- int attackMT;
- int attackedMT;
+ short PacketType;
+ unsigned int GID;
+ unsigned int targetGID;
+ unsigned int startTime;
+ int attackMT;
+ int attackedMT;
#if PACKETVER < 20071113
- short damage;
+ short damage;
#else
- int damage;
+ int damage;
#endif
//#if PACKETVER >= 20131223
-// unsigned char is_sp_damaged;
+// unsigned char is_sp_damaged;
//#endif
- short count;
- unsigned char action;
+ short count;
+ unsigned char action;
#if PACKETVER < 20071113
- short leftDamage;
+ short leftDamage;
#else
- int leftDamage;
+ int leftDamage;
#endif
} __attribute__((packed));
diff --git a/src/emap/pc.c b/src/emap/pc.c
index 1c7c74e..c7203d0 100644
--- a/src/emap/pc.c
+++ b/src/emap/pc.c
@@ -94,7 +94,7 @@ void epc_equipitem_pos(TBL_PC *sd, struct item_data *id, int *nPtr, int *posPtr)
hookStop();
- if (!id)
+ if (!id || !sd)
return;
if (pos & (EQP_HAND_R|EQP_SHADOW_WEAPON))
@@ -445,6 +445,8 @@ bool epc_can_insert_card_into_post(bool retVal, struct map_session_data* sd,
int f;
if (retVal)
{
+ if (!sd)
+ return retVal;
struct ItemdExt *data = itemd_get(sd->inventory_data[*idx_equip]);
if (!data || !data->allowedCards[0].id) // allow cards if AllowedCards list is empty
return retVal;
@@ -484,7 +486,7 @@ static int tempAmount = 0;
int epc_dropitem_pre(struct map_session_data *sd, int *nPtr, int *amountPtr)
{
const int n = *nPtr;
- if (n < 0 || n >= MAX_INVENTORY)
+ if (!sd || n < 0 || n >= MAX_INVENTORY)
{
tempN = 0;
tempId = 0;
@@ -542,8 +544,11 @@ int epc_takeitem_post(int retVal, struct map_session_data *sd, struct flooritem_
int epc_insert_card_pre(struct map_session_data* sd, int *idx_card, int *idx_equip)
{
- if (!sd || *idx_equip < 0 || *idx_equip >= MAX_INVENTORY ||
- *idx_card < 0 || *idx_card >= MAX_INVENTORY)
+ if (!sd ||
+ *idx_equip < 0 ||
+ *idx_equip >= MAX_INVENTORY ||
+ *idx_card < 0 ||
+ *idx_card >= MAX_INVENTORY)
{
tempN = 0;
tempId = 0;
diff --git a/src/emap/send.c b/src/emap/send.c
index f0d7b66..8a5c5a3 100644
--- a/src/emap/send.c
+++ b/src/emap/send.c
@@ -85,6 +85,8 @@ void send_changelook(struct map_session_data* sd, struct map_session_data* sd2,
{
struct SessionExt *tdata = session_get_bysd(sd2);
int i;
+ if (!sd)
+ return;
//ShowWarning("equip: for type %d = %d\n", type, val);
if (!tdata || tdata->clientVersion < 9)
{
@@ -318,6 +320,8 @@ void send_slave_say(TBL_PC *sd,
const char *const name,
const char *const message)
{
+ if (!sd || !message)
+ return;
const int len = 24 + 7 + strlen(message);
char *buf = NULL;
CREATE(buf, char, len);
@@ -343,6 +347,8 @@ void send_online_list(int fd, const char *buf, unsigned size)
void send_client_command(TBL_PC *sd, const char *const command)
{
+ if (!command)
+ return;
struct SessionExt *data = session_get_bysd(sd);
if (!data || data->clientVersion < 8)
return;
@@ -370,7 +376,7 @@ void send_changelook2(struct map_session_data* sd, struct block_list *bl, int id
WBUFW(buf, 9) = val2;
clif->send(buf, 11, bl, target);
WBUFW(buf, 0) = 0xb17;
- if (data)
+ if (data && sd)
{
//ShowWarning("equip: for type %d\n", type);
for (i = 0; i < data->slot; i++ )
diff --git a/src/emap/status.c b/src/emap/status.c
index 893339a..2463254 100644
--- a/src/emap/status.c
+++ b/src/emap/status.c
@@ -94,6 +94,9 @@ int estatus_calc_pc_additional(struct map_session_data* sd,
hookStop();
+ if (!sd)
+ return 0;
+
for (f = 0; f < MAX_INVENTORY; f ++)
{
struct item_data *const item = sd->inventory_data[f];
diff --git a/src/emap/utils/formatutils.c b/src/emap/utils/formatutils.c
index f81a5c0..57f27cc 100644
--- a/src/emap/utils/formatutils.c
+++ b/src/emap/utils/formatutils.c
@@ -26,6 +26,9 @@
int format_sub(struct script_state* st, int translate)
{
+ if (!st)
+ return 0;
+
TBL_PC *sd = NULL;
if (translate)
sd = script->rid2sd(st);