From 5138ae74fc79a747d95711a4eb88ffc6ac0a4eb6 Mon Sep 17 00:00:00 2001 From: AoShinHo <126742159+AoShinRO@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:04:38 -0300 Subject: [PATCH] Converted ZC_CHANGE_DIRECTION to struct (#8584) Co-authored-by: Lemongrass3110 --- src/map/buyingstore.cpp | 2 +- src/map/clif.cpp | 35 ++++++++++++++++++++--------------- src/map/clif.hpp | 2 +- src/map/clif_packetdb.hpp | 1 - src/map/packets.hpp | 8 ++++++++ src/map/unit.cpp | 2 +- src/map/vending.cpp | 2 +- 7 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/map/buyingstore.cpp b/src/map/buyingstore.cpp index 4791e0ef73..143e9c6ceb 100644 --- a/src/map/buyingstore.cpp +++ b/src/map/buyingstore.cpp @@ -627,7 +627,7 @@ void buyingstore_reopen( map_session_data* sd ){ { // Make buyer look perfect pc_setdir(sd, at->dir, at->head_dir); - clif_changed_dir(&sd->bl, AREA_WOS); + clif_changed_dir(sd->bl, AREA_WOS); if( at->sit ) { pc_setsit(sd); skill_sit(sd, 1); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 2562d89af4..471cac3e95 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -9787,7 +9787,7 @@ void clif_refresh(map_session_data *sd) if( pc_isdead(sd) ) // When you refresh, resend the death packet. clif_clearunit_single( sd->bl.id, CLR_DEAD, *sd ); else - clif_changed_dir(&sd->bl, SELF); + clif_changed_dir(sd->bl, SELF); clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF); //Issue #2143 @@ -11025,7 +11025,7 @@ void clif_parse_LoadEndAck(int fd,map_session_data *sd) else { skill_usave_trigger(sd); if (battle_config.spawn_direction) - clif_changed_dir(&sd->bl, SELF); + clif_changed_dir(sd->bl, SELF); } // Trigger skill effects if you appear standing on them @@ -11438,21 +11438,26 @@ void clif_parse_MapMove(int fd, map_session_data *sd) /// 5 = southeast /// 6 = east /// 7 = northeast -void clif_changed_dir(struct block_list *bl, enum send_target target) -{ - unsigned char buf[64]; +void clif_changed_dir(block_list& bl, enum send_target target){ - WBUFW(buf,0) = 0x9c; - WBUFL(buf,2) = bl->id; - WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0; - WBUFB(buf,8) = unit_getdir(bl); + PACKET_ZC_CHANGE_DIRECTION p{}; - clif_send(buf, packet_len(0x9c), bl, target); + p.packetType = HEADER_ZC_CHANGE_DIRECTION; + p.srcId = bl.id; + if( bl.type == BL_PC ){ + p.headDir = reinterpret_cast(&bl)->head_dir; + }else{ + p.headDir = 0; + } + p.dir = unit_getdir(&bl); - if (disguised(bl)) { - WBUFL(buf,2) = disguised_bl_id(bl->id); - WBUFW(buf,6) = 0; - clif_send(buf, packet_len(0x9c), bl, SELF); + clif_send(&p, sizeof(p), &bl, target); + + if (disguised(&bl)) { + p.srcId = disguised_bl_id(bl.id); + p.headDir = 0; + + clif_send(&p, sizeof(p), &bl, SELF); } } @@ -11470,7 +11475,7 @@ void clif_parse_ChangeDir(int fd, map_session_data *sd) dir = RFIFOB(fd,info->pos[1]); pc_setdir(sd, dir, headdir); - clif_changed_dir(&sd->bl, AREA_WOS); + clif_changed_dir(sd->bl, AREA_WOS); } diff --git a/src/map/clif.hpp b/src/map/clif.hpp index c965b4e0e1..ba2e9e3252 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -1007,7 +1007,7 @@ void clif_mvp_effect(map_session_data *sd); void clif_mvp_item(map_session_data *sd, t_itemid nameid); void clif_mvp_exp(map_session_data *sd, t_exp exp); void clif_mvp_noitem(map_session_data* sd); -void clif_changed_dir(struct block_list *bl, enum send_target target); +void clif_changed_dir(block_list& bl, enum send_target target); // vending void clif_openvendingreq( map_session_data& sd, uint16 num ); diff --git a/src/map/clif_packetdb.hpp b/src/map/clif_packetdb.hpp index f27aa19b2b..7af1980b16 100644 --- a/src/map/clif_packetdb.hpp +++ b/src/map/clif_packetdb.hpp @@ -49,7 +49,6 @@ parseable_packet(0x0099,-1,clif_parse_Broadcast,2,4); packet(0x009a,-1); parseable_packet(0x009b,5,clif_parse_ChangeDir,2,4); - packet(0x009c,9); packet( HEADER_ZC_ITEM_ENTRY, sizeof( struct PACKET_ZC_ITEM_ENTRY ) ); packet(0x009e,17); parseable_packet(0x009f,6,clif_parse_TakeItem,2); diff --git a/src/map/packets.hpp b/src/map/packets.hpp index 1afd81d2c0..308dddc38d 100644 --- a/src/map/packets.hpp +++ b/src/map/packets.hpp @@ -635,6 +635,14 @@ struct PACKET_ZC_NOTIFY_PLAYERMOVE { } __attribute__((packed)); DEFINE_PACKET_HEADER(ZC_NOTIFY_PLAYERMOVE, 0x87); +struct PACKET_ZC_CHANGE_DIRECTION{ + int16 packetType; + uint32 srcId; + uint16 headDir; + uint8 dir; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_CHANGE_DIRECTION, 0x9c) + struct PACKET_ZC_NPCACK_MAPMOVE { int16 packetType; char mapName[MAP_NAME_LENGTH_EXT]; diff --git a/src/map/unit.cpp b/src/map/unit.cpp index 763cdd6fcf..9153eb7049 100644 --- a/src/map/unit.cpp +++ b/src/map/unit.cpp @@ -1166,7 +1166,7 @@ bool unit_setdir(block_list *bl, uint8 dir, bool send_update) } if (send_update) - clif_changed_dir(bl, AREA); + clif_changed_dir(*bl, AREA); return true; } diff --git a/src/map/vending.cpp b/src/map/vending.cpp index c6de5e4b6a..36ad1b3dcf 100755 --- a/src/map/vending.cpp +++ b/src/map/vending.cpp @@ -562,7 +562,7 @@ void vending_reopen( map_session_data& sd ) if( (fail = vending_openvending(sd, at->title, data, count, at)) == 0 ) { // Make vendor look perfect pc_setdir(&sd, at->dir, at->head_dir); - clif_changed_dir(&sd.bl, AREA_WOS); + clif_changed_dir(sd.bl, AREA_WOS); if( at->sit ) { pc_setsit(&sd); skill_sit(&sd, 1);