Skip to content

Commit

Permalink
Cleaned up ZC_INVENTORY_TAB (#8217)
Browse files Browse the repository at this point in the history
Co-authored-by: Atemo <Atemo@users.noreply.github.com>
  • Loading branch information
Lemongrass3110 and Atemo committed Apr 4, 2024
1 parent 4f82aff commit 8745391
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
53 changes: 28 additions & 25 deletions src/map/clif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ unsigned long color_table[COLOR_MAX];
#include "clif_obfuscation.hpp"
static bool clif_session_isValid(map_session_data *sd);
static void clif_loadConfirm( map_session_data *sd );
static void clif_favorite_item( map_session_data& sd, uint16 index );

#if PACKETVER >= 20150513
enum mail_type {
Expand Down Expand Up @@ -3007,7 +3008,6 @@ static void clif_inventoryEnd( map_session_data *sd, e_inventory_type type ){
#endif
}

void clif_favorite_item(map_session_data* sd, unsigned short index);
//Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
void clif_inventorylist( map_session_data *sd ){
nullpo_retv( sd );
Expand Down Expand Up @@ -3093,7 +3093,7 @@ void clif_inventorylist( map_session_data *sd ){
continue;

if ( sd->inventory.u.items_inventory[i].favorite )
clif_favorite_item(sd, i);
clif_favorite_item( *sd, i );
}
#endif
}
Expand Down Expand Up @@ -19730,49 +19730,52 @@ void clif_spiritcharm(map_session_data *sd) {
}


/// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
/// 0907 <index>.W
///
/// R 0908 <index>.w <type>.b
/// Move Item from or to Personal Tab
/// 0907 <index>.W <type>.B (CZ_INVENTORY_TAB)
/// type:
/// 0 = move item to personal tab
/// 1 = move item to normal tab
void clif_parse_MoveItem(int fd, map_session_data *sd) {
#if PACKETVER >= 20111122
struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
int index = RFIFOW(fd,info->pos[0]) - 2;
int type = RFIFOB(fd, info->pos[1]);

void clif_parse_MoveItem( int fd, map_session_data* sd ){
// TODO: Check for correct packet version
#if PACKETVER >= 20120410
/* can't move while dead. */
if(pc_isdead(sd)) {
return;
}

if (index < 0 || index >= MAX_INVENTORY)
PACKET_CZ_INVENTORY_TAB* p = (PACKET_CZ_INVENTORY_TAB*)RFIFOP( fd, 0 );

uint16 index = server_index( p->index );

if( index >= MAX_INVENTORY ){
return;
}

if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
if ( sd->inventory.u.items_inventory[index].favorite && p->favorite == true )
sd->inventory.u.items_inventory[index].favorite = 0;
else if( type == 0 )
else if( p->favorite == false )
sd->inventory.u.items_inventory[index].favorite = 1;
else
return;/* nothing to do. */

clif_favorite_item(sd, index);
clif_favorite_item( *sd, index );
#endif
}


/// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
/// 0900 <index>.W <favorite>.B
void clif_favorite_item(map_session_data* sd, unsigned short index) {
int fd = sd->fd;
/// Items that are in favorite tab of inventory.
/// 0908 <index>.W <favorite>.B (ZC_INVENTORY_TAB)
static void clif_favorite_item( map_session_data& sd, uint16 index ){
// TODO: Check for correct packet version
#if PACKETVER >= 20111122
PACKET_ZC_INVENTORY_TAB p = {};

WFIFOHEAD(fd,packet_len(0x908));
WFIFOW(fd,0) = 0x908;
WFIFOW(fd,2) = index+2;
WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
WFIFOSET(fd,packet_len(0x908));
p.packetType = HEADER_ZC_INVENTORY_TAB;
p.index = client_index( index );
p.favorite = ( sd.inventory.u.items_inventory[index].favorite == true ) ? false : true;

clif_send( &p, sizeof( p ), &sd.bl, SELF );
#endif
}


Expand Down
5 changes: 1 addition & 4 deletions src/map/clif_packetdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,8 +1896,7 @@
packet(0x08f9,6);
packet(0x08fa,6);
parseable_packet(0x08fb,6,NULL,2);
parseable_packet(0x0907,5,clif_parse_MoveItem,2,4);
packet(0x0908,5);
parseable_packet( HEADER_CZ_INVENTORY_TAB, sizeof( PACKET_CZ_INVENTORY_TAB ), clif_parse_MoveItem, 0 );
parseable_packet(0x08D7,28,clif_parse_bg_queue_apply_request,2,4);
packet(0x08D8,27);
packet(0x08D9,30);
Expand Down Expand Up @@ -2005,8 +2004,6 @@
parseable_packet(0x08c9,2,clif_parse_cashshop_list_request,0);
packet(0x08cf,10); //Amulet spirits
packet(0x08d2,10);
parseable_packet(0x0907,5,clif_parse_MoveItem,2,4);
packet(0x0908,5);
parseable_packet(0x0922,-1,clif_parse_ReqTradeBuyingStore,2,4,8,12);
//parseable_packet(0x092e,2,clif_parse_SearchStoreInfoNextPage,0);
parseable_packet(0x0933,6,clif_parse_TakeItem,2);
Expand Down
14 changes: 14 additions & 0 deletions src/map/packets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,18 @@ struct PACKET_ZC_BOSS_INFO{
char name[51];
} __attribute__((packed));

struct PACKET_CZ_INVENTORY_TAB{
int16 packetType;
int16 index;
bool favorite;
} __attribute__((packed));

struct PACKET_ZC_INVENTORY_TAB{
int16 packetType;
int16 index;
bool favorite;
} __attribute__((packed));

// NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
#if !defined( sun ) && ( !defined( __NETBSD__ ) || __NetBSD_Version__ >= 600000000 )
#pragma pack( pop )
Expand Down Expand Up @@ -452,6 +464,8 @@ DEFINE_PACKET_HEADER(CZ_REQ_SE_CASH_TAB_CODE, 0x846)
DEFINE_PACKET_HEADER(ZC_ACK_SE_CASH_ITEM_LIST2, 0x8c0)
DEFINE_PACKET_HEADER(ZC_ACK_SCHEDULER_CASHITEM, 0x8ca)
DEFINE_PACKET_HEADER(ZC_CLEAR_DIALOG, 0x8d6)
DEFINE_PACKET_HEADER(CZ_INVENTORY_TAB, 0x907)
DEFINE_PACKET_HEADER(ZC_INVENTORY_TAB, 0x908)
DEFINE_PACKET_HEADER(ZC_ENTRY_QUEUE_INIT, 0x90e)
DEFINE_PACKET_HEADER(CZ_REQ_MERGE_ITEM, 0x96e)
DEFINE_PACKET_HEADER(ZC_BANKING_CHECK, 0x9a6)
Expand Down

0 comments on commit 8745391

Please sign in to comment.