mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-22 16:28:28 +00:00
Added EQEmu::OutBuffer() - stringstream-derived class with a few additional methods
This commit is contained in:
+73
-87
@@ -24,7 +24,7 @@ namespace RoF2
|
||||
static OpcodeManager *opcodes = nullptr;
|
||||
static Strategy struct_strategy;
|
||||
|
||||
void SerializeItem(std::stringstream& ss, const ItemInst *inst, int16 slot_id, uint8 depth, ItemPacketType packet_type);
|
||||
void SerializeItem(EQEmu::OutBuffer& ob, const ItemInst *inst, int16 slot_id, uint8 depth, ItemPacketType packet_type);
|
||||
|
||||
// server to client inventory location converters
|
||||
static inline structs::InventorySlot_Struct ServerToRoF2Slot(uint32 serverSlot, ItemPacketType PacketType = ItemPacketInvalid);
|
||||
@@ -628,24 +628,21 @@ namespace RoF2
|
||||
|
||||
InternalSerializedItem_Struct* eq = (InternalSerializedItem_Struct*)in->pBuffer;
|
||||
|
||||
std::stringstream ss(std::stringstream::in | std::stringstream::out);
|
||||
std::stringstream::pos_type last_pos = ss.tellp();
|
||||
EQEmu::OutBuffer ob;
|
||||
EQEmu::OutBuffer::pos_type last_pos = ob.tellp();
|
||||
|
||||
ss.write((const char*)&item_count, sizeof(uint32));
|
||||
ob.write((const char*)&item_count, sizeof(uint32));
|
||||
|
||||
for (int index = 0; index < item_count; ++index, ++eq) {
|
||||
SerializeItem(ss, (const ItemInst*)eq->inst, eq->slot_id, 0, ItemPacketCharInventory);
|
||||
if (ss.tellp() == last_pos)
|
||||
SerializeItem(ob, (const ItemInst*)eq->inst, eq->slot_id, 0, ItemPacketCharInventory);
|
||||
if (ob.tellp() == last_pos)
|
||||
Log.Out(Logs::General, Logs::Netcode, "[STRUCTS] Serialization failed on item slot %d during OP_CharInventory. Item skipped.", eq->slot_id);
|
||||
|
||||
last_pos = ss.tellp();
|
||||
last_pos = ob.tellp();
|
||||
}
|
||||
|
||||
std::string serialized = ss.str();
|
||||
|
||||
in->size = serialized.size();
|
||||
in->pBuffer = new uchar[in->size];
|
||||
memcpy(in->pBuffer, serialized.c_str(), serialized.size());
|
||||
in->size = ob.size();
|
||||
in->pBuffer = ob.detach();
|
||||
|
||||
delete[] __emu_buffer;
|
||||
|
||||
@@ -1563,29 +1560,24 @@ namespace RoF2
|
||||
|
||||
//store away the emu struct
|
||||
uchar* __emu_buffer = in->pBuffer;
|
||||
|
||||
ItemPacket_Struct* old_item_pkt = (ItemPacket_Struct*)__emu_buffer;
|
||||
//InternalSerializedItem_Struct* int_struct = (InternalSerializedItem_Struct*)(old_item_pkt->SerializedItem);
|
||||
InternalSerializedItem_Struct* int_struct = (InternalSerializedItem_Struct*)(&__emu_buffer[4]);
|
||||
|
||||
std::stringstream ss(std::stringstream::in | std::stringstream::out);
|
||||
std::stringstream::pos_type last_pos = ss.tellp();
|
||||
EQEmu::OutBuffer ob;
|
||||
EQEmu::OutBuffer::pos_type last_pos = ob.tellp();
|
||||
|
||||
ss.write((const char*)__emu_buffer, 4);
|
||||
ob.write((const char*)__emu_buffer, 4);
|
||||
|
||||
SerializeItem(ss, (const ItemInst*)int_struct->inst, int_struct->slot_id, 0, old_item_pkt->PacketType);
|
||||
if (ss.tellp() == last_pos) {
|
||||
SerializeItem(ob, (const ItemInst*)int_struct->inst, int_struct->slot_id, 0, old_item_pkt->PacketType);
|
||||
if (ob.tellp() == last_pos) {
|
||||
Log.Out(Logs::General, Logs::Netcode, "[STRUCTS] Serialization failed on item slot %d.", int_struct->slot_id);
|
||||
delete in;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string serialized = ss.str();
|
||||
|
||||
in->size = serialized.size();
|
||||
in->pBuffer = new uchar[in->size];
|
||||
//ItemPacket_Struct* new_item_pkt = (ItemPacket_Struct*)in->pBuffer;
|
||||
//new_item_pkt->PacketType = old_item_pkt->PacketType;
|
||||
memcpy(in->pBuffer, serialized.c_str(), serialized.size());
|
||||
in->size = ob.size();
|
||||
in->pBuffer = ob.detach();
|
||||
|
||||
delete[] __emu_buffer;
|
||||
|
||||
@@ -5451,7 +5443,7 @@ namespace RoF2
|
||||
return NextItemInstSerialNumber;
|
||||
}
|
||||
|
||||
void SerializeItem(std::stringstream& ss, const ItemInst *inst, int16 slot_id_in, uint8 depth, ItemPacketType packet_type)
|
||||
void SerializeItem(EQEmu::OutBuffer& ob, const ItemInst *inst, int16 slot_id_in, uint8 depth, ItemPacketType packet_type)
|
||||
{
|
||||
const Item_Struct *item = inst->GetUnscaledItem();
|
||||
|
||||
@@ -5483,7 +5475,7 @@ namespace RoF2
|
||||
hdr.unknown052 = 0;
|
||||
hdr.isEvolving = item->EvolvingItem;
|
||||
|
||||
ss.write((const char*)&hdr, sizeof(RoF2::structs::ItemSerializationHeader));
|
||||
ob.write((const char*)&hdr, sizeof(RoF2::structs::ItemSerializationHeader));
|
||||
|
||||
if (item->EvolvingItem > 0) {
|
||||
RoF2::structs::EvolvingItem evotop;
|
||||
@@ -5497,7 +5489,7 @@ namespace RoF2
|
||||
evotop.Activated = 1;
|
||||
evotop.evomaxlevel = item->EvolvingMax;
|
||||
|
||||
ss.write((const char*)&evotop, sizeof(RoF2::structs::EvolvingItem));
|
||||
ob.write((const char*)&evotop, sizeof(RoF2::structs::EvolvingItem));
|
||||
}
|
||||
|
||||
//ORNAMENT IDFILE / ICON
|
||||
@@ -5512,16 +5504,16 @@ namespace RoF2
|
||||
char tmp[30]; memset(tmp, 0x0, 30); sprintf(tmp, "IT%d", inst->GetOrnamentationIDFile());
|
||||
|
||||
//Mainhand
|
||||
ss.write(tmp, strlen(tmp));
|
||||
ss.write("\0", 1);
|
||||
ob.write(tmp, strlen(tmp));
|
||||
ob.write("\0", 1);
|
||||
|
||||
//Offhand
|
||||
ss.write(tmp, strlen(tmp));
|
||||
ss.write("\0", 1);
|
||||
ob.write(tmp, strlen(tmp));
|
||||
ob.write("\0", 1);
|
||||
}
|
||||
else {
|
||||
ss.write("\0", 1); // no main hand Ornamentation
|
||||
ss.write("\0", 1); // no off hand Ornamentation
|
||||
ob.write("\0", 1); // no main hand Ornamentation
|
||||
ob.write("\0", 1); // no off hand Ornamentation
|
||||
}
|
||||
|
||||
RoF2::structs::ItemSerializationHeaderFinish hdrf;
|
||||
@@ -5535,21 +5527,21 @@ namespace RoF2
|
||||
hdrf.unknowna5 = 0;
|
||||
hdrf.ItemClass = item->ItemClass;
|
||||
|
||||
ss.write((const char*)&hdrf, sizeof(RoF2::structs::ItemSerializationHeaderFinish));
|
||||
ob.write((const char*)&hdrf, sizeof(RoF2::structs::ItemSerializationHeaderFinish));
|
||||
|
||||
if (strlen(item->Name) > 0)
|
||||
ss.write(item->Name, strlen(item->Name));
|
||||
ss.write("\0", 1);
|
||||
ob.write(item->Name, strlen(item->Name));
|
||||
ob.write("\0", 1);
|
||||
|
||||
if (strlen(item->Lore) > 0)
|
||||
ss.write(item->Lore, strlen(item->Lore));
|
||||
ss.write("\0", 1);
|
||||
ob.write(item->Lore, strlen(item->Lore));
|
||||
ob.write("\0", 1);
|
||||
|
||||
if (strlen(item->IDFile) > 0)
|
||||
ss.write(item->IDFile, strlen(item->IDFile));
|
||||
ss.write("\0", 1);
|
||||
ob.write(item->IDFile, strlen(item->IDFile));
|
||||
ob.write("\0", 1);
|
||||
|
||||
ss.write("\0", 1);
|
||||
ob.write("\0", 1);
|
||||
|
||||
RoF2::structs::ItemBodyStruct ibs;
|
||||
memset(&ibs, 0, sizeof(RoF2::structs::ItemBodyStruct));
|
||||
@@ -5640,12 +5632,12 @@ namespace RoF2
|
||||
ibs.FactionAmt4 = item->FactionAmt4;
|
||||
ibs.FactionMod4 = item->FactionMod4;
|
||||
|
||||
ss.write((const char*)&ibs, sizeof(RoF2::structs::ItemBodyStruct));
|
||||
ob.write((const char*)&ibs, sizeof(RoF2::structs::ItemBodyStruct));
|
||||
|
||||
//charm text
|
||||
if (strlen(item->CharmFile) > 0)
|
||||
ss.write((const char*)item->CharmFile, strlen(item->CharmFile));
|
||||
ss.write("\0", 1);
|
||||
ob.write((const char*)item->CharmFile, strlen(item->CharmFile));
|
||||
ob.write("\0", 1);
|
||||
|
||||
RoF2::structs::ItemSecondaryBodyStruct isbs;
|
||||
memset(&isbs, 0, sizeof(RoF2::structs::ItemSecondaryBodyStruct));
|
||||
@@ -5674,11 +5666,11 @@ namespace RoF2
|
||||
isbs.book = item->Book;
|
||||
isbs.booktype = item->BookType;
|
||||
|
||||
ss.write((const char*)&isbs, sizeof(RoF2::structs::ItemSecondaryBodyStruct));
|
||||
ob.write((const char*)&isbs, sizeof(RoF2::structs::ItemSecondaryBodyStruct));
|
||||
|
||||
if (strlen(item->Filename) > 0)
|
||||
ss.write((const char*)item->Filename, strlen(item->Filename));
|
||||
ss.write("\0", 1);
|
||||
ob.write((const char*)item->Filename, strlen(item->Filename));
|
||||
ob.write("\0", 1);
|
||||
|
||||
RoF2::structs::ItemTertiaryBodyStruct itbs;
|
||||
memset(&itbs, 0, sizeof(RoF2::structs::ItemTertiaryBodyStruct));
|
||||
@@ -5713,7 +5705,7 @@ namespace RoF2
|
||||
itbs.unknown13 = 0;
|
||||
itbs.unknown14 = 0;
|
||||
|
||||
ss.write((const char*)&itbs, sizeof(RoF2::structs::ItemTertiaryBodyStruct));
|
||||
ob.write((const char*)&itbs, sizeof(RoF2::structs::ItemTertiaryBodyStruct));
|
||||
|
||||
// Effect Structures Broken down to allow variable length strings for effect names
|
||||
int32 effect_unknown = 0;
|
||||
@@ -5730,13 +5722,13 @@ namespace RoF2
|
||||
ices.recast = item->RecastDelay;
|
||||
ices.recast_type = item->RecastType;
|
||||
|
||||
ss.write((const char*)&ices, sizeof(RoF2::structs::ClickEffectStruct));
|
||||
ob.write((const char*)&ices, sizeof(RoF2::structs::ClickEffectStruct));
|
||||
|
||||
if (strlen(item->ClickName) > 0)
|
||||
ss.write((const char*)item->ClickName, strlen(item->ClickName));
|
||||
ss.write("\0", 1);
|
||||
ob.write((const char*)item->ClickName, strlen(item->ClickName));
|
||||
ob.write("\0", 1);
|
||||
|
||||
ss.write((const char*)&effect_unknown, sizeof(int32)); // clickunk7
|
||||
ob.write((const char*)&effect_unknown, sizeof(int32)); // clickunk7
|
||||
|
||||
RoF2::structs::ProcEffectStruct ipes;
|
||||
memset(&ipes, 0, sizeof(RoF2::structs::ProcEffectStruct));
|
||||
@@ -5747,13 +5739,13 @@ namespace RoF2
|
||||
ipes.level = item->Proc.Level;
|
||||
ipes.procrate = item->ProcRate;
|
||||
|
||||
ss.write((const char*)&ipes, sizeof(RoF2::structs::ProcEffectStruct));
|
||||
ob.write((const char*)&ipes, sizeof(RoF2::structs::ProcEffectStruct));
|
||||
|
||||
if (strlen(item->ProcName) > 0)
|
||||
ss.write((const char*)item->ProcName, strlen(item->ProcName));
|
||||
ss.write("\0", 1);
|
||||
ob.write((const char*)item->ProcName, strlen(item->ProcName));
|
||||
ob.write("\0", 1);
|
||||
|
||||
ss.write((const char*)&effect_unknown, sizeof(int32)); // unknown5
|
||||
ob.write((const char*)&effect_unknown, sizeof(int32)); // unknown5
|
||||
|
||||
RoF2::structs::WornEffectStruct iwes;
|
||||
memset(&iwes, 0, sizeof(RoF2::structs::WornEffectStruct));
|
||||
@@ -5763,13 +5755,13 @@ namespace RoF2
|
||||
iwes.type = item->Worn.Type;
|
||||
iwes.level = item->Worn.Level;
|
||||
|
||||
ss.write((const char*)&iwes, sizeof(RoF2::structs::WornEffectStruct));
|
||||
ob.write((const char*)&iwes, sizeof(RoF2::structs::WornEffectStruct));
|
||||
|
||||
if (strlen(item->WornName) > 0)
|
||||
ss.write((const char*)item->WornName, strlen(item->WornName));
|
||||
ss.write("\0", 1);
|
||||
ob.write((const char*)item->WornName, strlen(item->WornName));
|
||||
ob.write("\0", 1);
|
||||
|
||||
ss.write((const char*)&effect_unknown, sizeof(int32)); // unknown6
|
||||
ob.write((const char*)&effect_unknown, sizeof(int32)); // unknown6
|
||||
|
||||
RoF2::structs::WornEffectStruct ifes;
|
||||
memset(&ifes, 0, sizeof(RoF2::structs::WornEffectStruct));
|
||||
@@ -5779,13 +5771,13 @@ namespace RoF2
|
||||
ifes.type = item->Focus.Type;
|
||||
ifes.level = item->Focus.Level;
|
||||
|
||||
ss.write((const char*)&ifes, sizeof(RoF2::structs::WornEffectStruct));
|
||||
ob.write((const char*)&ifes, sizeof(RoF2::structs::WornEffectStruct));
|
||||
|
||||
if (strlen(item->FocusName) > 0)
|
||||
ss.write((const char*)item->FocusName, strlen(item->FocusName));
|
||||
ss.write("\0", 1);
|
||||
ob.write((const char*)item->FocusName, strlen(item->FocusName));
|
||||
ob.write("\0", 1);
|
||||
|
||||
ss.write((const char*)&effect_unknown, sizeof(int32)); // unknown6
|
||||
ob.write((const char*)&effect_unknown, sizeof(int32)); // unknown6
|
||||
|
||||
RoF2::structs::WornEffectStruct ises;
|
||||
memset(&ises, 0, sizeof(RoF2::structs::WornEffectStruct));
|
||||
@@ -5795,13 +5787,13 @@ namespace RoF2
|
||||
ises.type = item->Scroll.Type;
|
||||
ises.level = item->Scroll.Level;
|
||||
|
||||
ss.write((const char*)&ises, sizeof(RoF2::structs::WornEffectStruct));
|
||||
ob.write((const char*)&ises, sizeof(RoF2::structs::WornEffectStruct));
|
||||
|
||||
if (strlen(item->ScrollName) > 0)
|
||||
ss.write((const char*)item->ScrollName, strlen(item->ScrollName));
|
||||
ss.write("\0", 1);
|
||||
ob.write((const char*)item->ScrollName, strlen(item->ScrollName));
|
||||
ob.write("\0", 1);
|
||||
|
||||
ss.write((const char*)&effect_unknown, sizeof(int32)); // unknown6
|
||||
ob.write((const char*)&effect_unknown, sizeof(int32)); // unknown6
|
||||
|
||||
// Bard Effect?
|
||||
RoF2::structs::WornEffectStruct ibes;
|
||||
@@ -5813,18 +5805,18 @@ namespace RoF2
|
||||
ibes.level = item->Bard.Level;
|
||||
//ibes.unknown6 = 0xffffffff;
|
||||
|
||||
ss.write((const char*)&ibes, sizeof(RoF2::structs::WornEffectStruct));
|
||||
ob.write((const char*)&ibes, sizeof(RoF2::structs::WornEffectStruct));
|
||||
|
||||
/*
|
||||
if(strlen(item->BardName) > 0)
|
||||
{
|
||||
ss.write((const char*)item->BardName, strlen(item->BardName));
|
||||
ss.write((const char*)&null_term, sizeof(uint8));
|
||||
ob.write((const char*)item->BardName, strlen(item->BardName));
|
||||
ob.write((const char*)&null_term, sizeof(uint8));
|
||||
}
|
||||
else */
|
||||
ss.write("\0", 1);
|
||||
ob.write("\0", 1);
|
||||
|
||||
ss.write((const char*)&effect_unknown, sizeof(int32)); // unknown6
|
||||
ob.write((const char*)&effect_unknown, sizeof(int32)); // unknown6
|
||||
// End of Effects
|
||||
|
||||
RoF2::structs::ItemQuaternaryBodyStruct iqbs;
|
||||
@@ -5867,12 +5859,12 @@ namespace RoF2
|
||||
iqbs.unknown38 = 0;
|
||||
iqbs.unknown39 = 1;
|
||||
|
||||
ss.write((const char*)&iqbs, sizeof(RoF2::structs::ItemQuaternaryBodyStruct));
|
||||
ob.write((const char*)&iqbs, sizeof(RoF2::structs::ItemQuaternaryBodyStruct));
|
||||
|
||||
std::stringstream::pos_type count_pos = ss.tellp();
|
||||
EQEmu::OutBuffer::pos_type count_pos = ob.tellp();
|
||||
uint32 subitem_count = 0;
|
||||
|
||||
ss.write((const char*)&subitem_count, sizeof(uint32));
|
||||
ob.write((const char*)&subitem_count, sizeof(uint32));
|
||||
|
||||
for (uint32 index = SUB_INDEX_BEGIN; index < EQEmu::legacy::ITEM_CONTAINER_SIZE; ++index) {
|
||||
ItemInst* sub = inst->GetItem(index);
|
||||
@@ -5889,20 +5881,14 @@ namespace RoF2
|
||||
else
|
||||
SubSlotNumber = slot_id_in;
|
||||
|
||||
ss.write((const char*)&index, sizeof(uint32));
|
||||
ob.write((const char*)&index, sizeof(uint32));
|
||||
|
||||
SerializeItem(ss, sub, SubSlotNumber, (depth + 1), packet_type);
|
||||
SerializeItem(ob, sub, SubSlotNumber, (depth + 1), packet_type);
|
||||
++subitem_count;
|
||||
}
|
||||
|
||||
if (subitem_count) {
|
||||
std::stringstream::pos_type cur_pos = ss.tellp();
|
||||
ss.seekp(count_pos);
|
||||
|
||||
ss.write((const char*)&subitem_count, sizeof(uint32));
|
||||
|
||||
ss.seekp(cur_pos);
|
||||
}
|
||||
if (subitem_count)
|
||||
ob.overwrite(count_pos, (const char*)&subitem_count, sizeof(uint32));
|
||||
}
|
||||
|
||||
static inline structs::InventorySlot_Struct ServerToRoF2Slot(uint32 serverSlot, ItemPacketType PacketType)
|
||||
|
||||
Reference in New Issue
Block a user