From 99f1db754f40e42af9402157acc9f1d0cbbaa64e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Jul 2019 02:42:49 +0300 Subject: Convert packet ZC_HAT_EFFECT into struct and fix allowed packet versions --- src/map/clif.c | 54 +++++++++++++++++++++--------------------------- src/map/packets_struct.h | 11 ++++++++++ 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 310bbebff..6656d12f6 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -21983,53 +21983,47 @@ static void clif_skill_scale(struct block_list *bl, int src_id, int x, int y, ui /// 0A3B .W .L .B { .W } static void clif_hat_effect(struct block_list *bl, struct block_list *tbl, enum send_target target) { -#if PACKETVER >= 20150422 - unsigned char *buf; - int len, i; - struct map_session_data *sd; - +#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO) nullpo_retv(bl); - - sd = BL_CAST(BL_PC, bl); - + struct map_session_data *sd = BL_CAST(BL_PC, bl); nullpo_retv(sd); - len = 9 + VECTOR_LENGTH(sd->hatEffectId) * 2; + const int len = sizeof(struct PACKET_ZC_HAT_EFFECT) + VECTOR_LENGTH(sd->hatEffectId) * 2; + struct PACKET_ZC_HAT_EFFECT *p = aMalloc(len); - buf = (unsigned char*)aMalloc(len); - - WBUFW(buf, 0) = 0xa3b; - WBUFW(buf, 2) = len; - WBUFL(buf, 4) = bl->id; - WBUFB(buf, 8) = 1; + p->packetType = HEADER_ZC_HAT_EFFECT; + p->packetLength = len; + p->aid = bl->id; + p->status = 1; - for( i = 0; i < VECTOR_LENGTH(sd->hatEffectId); i++ ){ - WBUFW(buf, 9 + i * 2) = VECTOR_INDEX(sd->hatEffectId, i); + for (int i = 0; i < VECTOR_LENGTH(sd->hatEffectId); i++) { + p->effects[i] = VECTOR_INDEX(sd->hatEffectId, i); } if (tbl != NULL) { - clif->send(buf, len, tbl, target); + clif->send(p, len, tbl, target); } else { - clif->send(buf, len, bl, target); + clif->send(p, len, bl, target); } - - aFree(buf); + aFree(p); #endif } static void clif_hat_effect_single(struct block_list *bl, uint16 effectId, bool enable){ -#if PACKETVER >= 20150422 - unsigned char buf[13]; - +#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO) nullpo_retv(bl); - WBUFW(buf,0) = 0xa3b; - WBUFW(buf,2) = 13; - WBUFL(buf,4) = bl->id; - WBUFB(buf,8) = enable; - WBUFL(buf,9) = effectId; + const int len = sizeof(struct PACKET_ZC_HAT_EFFECT) + 2; + struct PACKET_ZC_HAT_EFFECT *p = aMalloc(len); + + p->packetType = HEADER_ZC_HAT_EFFECT; + p->packetLength = len; + p->aid = bl->id; + p->status = enable; + p->effects[0] = effectId; - clif->send(buf, 13, bl, AREA); + clif->send(p, len, bl, AREA); + aFree(p); #endif } diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index aeb57bdc4..f41008889 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -3522,6 +3522,17 @@ struct PACKET_ZC_STATUS_CHANGE_ACK { } __attribute__((packed)); DEFINE_PACKET_HEADER(ZC_STATUS_CHANGE_ACK, 0x00bc); +#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO) +struct PACKET_ZC_HAT_EFFECT { + int16 packetType; + int16 packetLength; + uint32 aid; + int8 status; + uint16 effects[]; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_HAT_EFFECT, 0x0a3b); +#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-60-g2f50