From 0c200e53ad49bd443bec30504bd760411bf76015 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 8 Aug 2019 22:00:54 +0300 Subject: Convert ZC_ADD_SKILL into struct and add new packet version --- src/map/clif.c | 41 +++++++++++++++++++++++------------------ src/map/packets_struct.h | 26 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 3b7691ae4..37e2fea64 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -5314,36 +5314,41 @@ static void clif_skillinfoblock(struct map_session_data *sd) /// 0111 .W .L .W .W .W .24B .B static void clif_addskill(struct map_session_data *sd, int id) { - int fd, skill_lv, idx = skill->get_index(id); - nullpo_retv(sd); - fd = sd->fd; - if (!fd) return; + int fd = sd->fd; + if (!fd) + return; + int idx = skill->get_index(id); if (sd->status.skill[idx].id <= 0) return; - skill_lv = sd->status.skill[idx].lv; + int skill_lv = sd->status.skill[idx].lv; - WFIFOHEAD(fd, packet_len(0x111)); - WFIFOW(fd,0) = 0x111; - WFIFOW(fd,2) = id; - WFIFOL(fd,4) = skill->get_inf(id); - WFIFOW(fd,8) = skill_lv; + WFIFOHEAD(fd, sizeof(struct PACKET_ZC_ADD_SKILL)); + struct PACKET_ZC_ADD_SKILL *p = WFIFOP(fd, 0); + p->packetType = HEADER_ZC_ADD_SKILL; + p->id = id; + p->inf = skill->get_inf(id); + p->level = skill_lv; if (skill_lv > 0) { - WFIFOW(fd,10) = skill->get_sp(id, skill_lv); - WFIFOW(fd,12) = skill->get_range2(&sd->bl, id, skill_lv); + p->sp = skill->get_sp(id, skill_lv); + p->range2 = skill->get_range2(&sd->bl, id, skill_lv); } else { - WFIFOW(fd,10) = 0; - WFIFOW(fd,12) = 0; + p->sp = 0; + p->range2 = 0; } - safestrncpy(WFIFOP(fd,14), skill->get_name(id), NAME_LENGTH); +#if PACKETVER_RE_NUM >= 20190807 + p->level2 = 0; +#else + safestrncpy(p->name, skill->get_name(id), NAME_LENGTH); +#endif if (sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT) - WFIFOB(fd,38) = (skill_lv < skill->tree_get_max(id, sd->status.class))? 1:0; + p->upFlag = (skill_lv < skill->tree_get_max(id, sd->status.class)) ? 1 : 0; else - WFIFOB(fd,38) = 0; - WFIFOSET(fd,packet_len(0x111)); + p->upFlag = 0; + WFIFOSET(fd, sizeof(struct PACKET_ZC_ADD_SKILL)); } /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE). diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index 59f148c94..8170f13f2 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -3533,6 +3533,32 @@ struct PACKET_ZC_HAT_EFFECT { DEFINE_PACKET_HEADER(ZC_HAT_EFFECT, 0x0a3b); #endif +#if PACKETVER_RE_NUM >= 20190807 +struct PACKET_ZC_ADD_SKILL { + int16 packetType; + uint16 id; + int inf; + uint16 level; + uint16 sp; + uint16 range2; + uint8 upFlag; + uint16 level2; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_ADD_SKILL, 0x0b31); +#else +struct PACKET_ZC_ADD_SKILL { + int16 packetType; + uint16 id; + int inf; + uint16 level; + uint16 sp; + uint16 range2; + char name[NAME_LENGTH]; + uint8 upFlag; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_ADD_SKILL, 0x0111); +#endif + #if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute #pragma pack(pop) #endif // not NetBSD < 6 / Solaris -- cgit v1.2.3-70-g09d2