Since strings seem to be separated by a single 0 bit, those should be easy to change over to the new format of removing the pipes | from the serialization. But, for chars and ints, I need to find a way that I can define a certain number of bits to use. It seems like most of them are set to work like int8, int16, int32 or so using 1, 2, 4 or so hex bits for each field. So, I need the serialization to be able to figure out how many bits to send for each field.
For example; If I want to send the Item ID, the example I gave in the last post would be to send "bb 88 00 00". That would be item ID 35003, but it is important to send the last to 0 bits there to make sure the item structure aligns properly. Maybe I could make an actual structure in the structs file to do it, but I don't really know how to pull database fields for structures.
From looking at the anniversary_itemfields.h "TRY NEW" section, it looks like they tried to assign lengths to each field. But I can't figure out how the serialization would work for that. Here is an excerpt from the file:
Code:
#ifdef NEW_TRY
/* 000 */ //I(ItemClass) Leave this one off on purpose
/* 001 */ S(Name)
/* 002 */ S(Lore)
/* 003 */ MISSINGCS("") //LoreFile? missing from binary
/* 003 */ S(IDFile)
/* 004 */ I4(ID)
/* 005 */ I1(Weight)
/* 006 */ I1(NoRent)
/* 007 */ I2(NoDrop)
/* 008 */ I4(Size)
/* 009 */ I1(Slots)
/* 010 */ I4(Price)
/* 011 */ I4(Icon)
/* 013 */ C4(0)
/* 014 */ C1(0)
/* 014 */ I1(BenefitFlag)
/* 015 */ I1(Tradeskills)
/* 016 */ I1(CR)
/* 017 */ I1(DR)
/* 018 */ I1(PR)
/* 019 */ I1(MR)
/* 020 */ I1(FR)
I replaced that section on my test server a while back and had almost forgotten about it. I didn't understand what the numbers next to the defines were, but it makes sense now, lol. I guess the serialization was changed back when Anniversary actually came out or before it.
Any suggestions on how to change the SerializeItem below to work with the "TRY NEW" itemfields the way it needs to for clients later than Titanium? I don't think it would require much of a change, but I just don't know how to set it to know that "I4" means to use 4 bit even if only 1 of them gets filled with data.
Code:
char *SerializeItem(const ItemInst *inst, sint16 slot_id, uint32 *length, uint8 depth) {
char *serialization = NULL;
char *instance = NULL;
const char *protection=(const char *)"\\\\\\\\\\";
char *sub_items[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
bool stackable=inst->IsStackable();
uint32 merchant_slot=inst->GetMerchantSlot();
sint16 charges=inst->GetCharges();
const Item_Struct *item=inst->GetItem();
int i;
uint32 sub_length;
//not sure how these truely shifted, as this dosent seem right.
MakeAnyLenString(&instance,
"%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|",
stackable ? charges : 0,
0,
(merchant_slot==0) ? slot_id : merchant_slot,
inst->GetPrice(),
(merchant_slot==0) ? 1 : inst->GetMerchantCount(),
0,
merchant_slot + item->ID, //instance ID, bullshit for now
inst->IsInstNoDrop() ? 1 : 0, //not sure where this field is
(stackable ? ((inst->GetItem()->ItemType == ItemTypePotion) ? 1 : 0) : charges),
0,
0,
0,
0
);
for(i=0;i<10;i++) {
ItemInst *sub=inst->GetItem(i);
if (sub) {
sub_items[i]=SerializeItem(sub,0,&sub_length,depth+1);
}
}
*length=MakeAnyLenString(&serialization,
"%.*s%s" // For leading quotes (and protection) if a subitem;
"%s" // Instance data
"%.*s\"" // Quotes (and protection, if needed) around static data
"%i" // item->ItemClass so we can do |%s instead of %s|
#define I(field) "|%i"
#define C(field) "|%s"
#define S(field) "|%s"
#define F(field) "|%f"
#include "Anniversary_itemfields.h"
"%.*s\"" // Quotes (and protection, if needed) around static data
"|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s" // Sub items
"%.*s%s" // For trailing quotes (and protection) if a subitem;
,depth ? depth-1 : 0,protection,(depth) ? "\"" : ""
,instance
,depth,protection
,item->ItemClass
#define I(field) ,item->field
#define C(field) ,field
#define S(field) ,item->field
#define F(field) ,item->field
#include "Anniversary_itemfields.h"
,depth,protection
,sub_items[0] ? sub_items[0] : ""
,sub_items[1] ? sub_items[1] : ""
,sub_items[2] ? sub_items[2] : ""
,sub_items[3] ? sub_items[3] : ""
,sub_items[4] ? sub_items[4] : ""
,sub_items[5] ? sub_items[5] : ""
,sub_items[6] ? sub_items[6] : ""
,sub_items[7] ? sub_items[7] : ""
,sub_items[8] ? sub_items[8] : ""
,sub_items[9] ? sub_items[9] : ""
,(depth) ? depth-1 : 0,protection,(depth) ? "\"" : ""
);
for(i=0;i<10;i++) {
if (sub_items[i])
safe_delete_array(sub_items[i]);
}
safe_delete_array(instance);
printf("ITEM: \n%s\n", serialization);
return serialization;
}
} //end namespace Anniversary