It helps if you actually push more than the changelog message...

This commit is contained in:
Uleat
2015-01-05 13:50:03 -05:00
parent 7557cfd845
commit 4b133c808c
34 changed files with 2936 additions and 212 deletions
+453
View File
@@ -7,6 +7,7 @@
#include "../races.h"
#include "../eq_packet_structs.h"
#include "../misc_functions.h"
#include "../string_util.h"
#include "../item.h"
#include "titanium_structs.h"
@@ -28,6 +29,18 @@ namespace Titanium
static inline uint32 TitaniumToServerSlot(int16 TitaniumSlot);
static inline uint32 TitaniumToServerCorpseSlot(int16 TitaniumCorpse);
// server to client text link converters
static inline void ServerToTitaniumTextLinks(std::string& titaniumTextLink, const std::string& serverTextLink);
static inline bool DegenerateServerTextLinkBody(TextLinkBody_Struct& serverLinkBodyStruct, const std::string& serverLinkBody);
static inline void ServerToTitaniumTextLinkBodyStruct(structs::TextLinkBody_Struct& titaniumLinkBodyStruct, const TextLinkBody_Struct& serverLinkBodyStruct);
static inline bool GenerateTitaniumTextLinkBody(std::string& titaniumLinkBody, const structs::TextLinkBody_Struct& titaniumLinkBodyStruct);
// client to server text link converters
static inline void TitaniumToServerTextLinks(std::string& serverTextLink, const std::string& titaniumTextLink);
static inline bool DegenerateTitaniumTextLinkBody(structs::TextLinkBody_Struct& titaniumLinkBodyStruct, const std::string& titaniumLinkBody);
static inline void TitaniumToServerTextLinkBodyStruct(TextLinkBody_Struct& serverLinkBodyStruct, const structs::TextLinkBody_Struct& titaniumLinkBodyStruct);
static inline bool GenerateServerTextLinkBody(std::string& serverLinkBody, const TextLinkBody_Struct& serverLinkBodyStruct);
void Register(EQStreamIdentifier &into)
{
//create our opcode manager if we havent already
@@ -220,6 +233,35 @@ namespace Titanium
FINISH_ENCODE();
}
ENCODE(OP_ChannelMessage)
{
EQApplicationPacket *in = *p;
*p = nullptr;
ChannelMessage_Struct *emu = (ChannelMessage_Struct *)in->pBuffer;
unsigned char *__emu_buffer = in->pBuffer;
std::string old_message = emu->message;
std::string new_message;
ServerToTitaniumTextLinks(new_message, old_message);
in->size = sizeof(ChannelMessage_Struct) + new_message.length() + 1;
in->pBuffer = new unsigned char[in->size];
char *OutBuffer = (char *)in->pBuffer;
memcpy(OutBuffer, __emu_buffer, sizeof(ChannelMessage_Struct));
OutBuffer += sizeof(ChannelMessage_Struct);
VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str());
delete[] __emu_buffer;
dest->FastQueuePacket(&in, ack_req);
}
ENCODE(OP_CharInventory)
{
//consume the packet
@@ -1070,6 +1112,44 @@ namespace Titanium
FINISH_ENCODE();
}
ENCODE(OP_SpecialMesg)
{
EQApplicationPacket *in = *p;
*p = nullptr;
SpecialMesg_Struct *emu = (SpecialMesg_Struct *)in->pBuffer;
unsigned char *__emu_buffer = in->pBuffer;
std::string old_message = &emu->message[strlen(emu->sayer)];
std::string new_message;
ServerToTitaniumTextLinks(new_message, old_message);
//in->size = 3 + 4 + 4 + strlen(emu->sayer) + 1 + 12 + new_message.length() + 1;
in->size = 25 + strlen(emu->sayer) + new_message.length();
in->pBuffer = new unsigned char[in->size];
char *OutBuffer = (char *)in->pBuffer;
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[2]);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->msg_type);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->target_spawn_id);
VARSTRUCT_ENCODE_STRING(OutBuffer, emu->sayer);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, 0);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, 0);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, 0);
VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str());
delete[] __emu_buffer;
dest->FastQueuePacket(&in, ack_req);
}
ENCODE(OP_Track)
{
EQApplicationPacket *in = *p;
@@ -1371,6 +1451,25 @@ namespace Titanium
FINISH_DIRECT_DECODE();
}
DECODE(OP_ChannelMessage)
{
unsigned char *__eq_buffer = __packet->pBuffer;
std::string old_message = (char *)&__eq_buffer[sizeof(ChannelMessage_Struct)];
std::string new_message;
TitaniumToServerTextLinks(new_message, old_message);
__packet->size = sizeof(ChannelMessage_Struct) + new_message.length() + 1;
__packet->pBuffer = new unsigned char[__packet->size];
ChannelMessage_Struct *emu = (ChannelMessage_Struct *)__packet->pBuffer;
memcpy(emu, __eq_buffer, sizeof(ChannelMessage_Struct));
strcpy(emu->message, new_message.c_str());
delete[] __eq_buffer;
}
DECODE(OP_CharacterCreate)
{
DECODE_LENGTH_EXACT(structs::CharCreate_Struct);
@@ -1763,5 +1862,359 @@ namespace Titanium
//uint32 ServerCorpse;
return TitaniumCorpse;
}
static inline void ServerToTitaniumTextLinks(std::string& titaniumTextLink, const std::string& serverTextLink)
{
const char delimiter = 0x12;
#if EQDEBUG >= 6
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): old message '%s'", serverTextLink.c_str());
if (consts::TEXT_LINK_BODY_LENGTH == EmuConstants::TEXT_LINK_BODY_LENGTH) {
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): link size equal, no conversion necessary");
titaniumTextLink = serverTextLink;
return;
}
if (serverTextLink.find(delimiter) == std::string::npos) {
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): delimiter not found, no conversion necessary");
titaniumTextLink = serverTextLink;
return;
}
bool conversion_error = false;
auto segments = SplitString(serverTextLink, delimiter);
for (size_t iter = 1; iter < segments.size(); iter += 2) {
TextLinkBody_Struct old_body_data;
if (!DegenerateServerTextLinkBody(old_body_data, segments[iter].substr(0, EmuConstants::TEXT_LINK_BODY_LENGTH).c_str())) {
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): body degeneration error '%s'", segments[iter].substr(0, EmuConstants::TEXT_LINK_BODY_LENGTH).c_str());
conversion_error = true;
}
else {
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): body degeneration success '%s'", segments[iter].substr(0, EmuConstants::TEXT_LINK_BODY_LENGTH).c_str());
}
structs::TextLinkBody_Struct new_body_data;
ServerToTitaniumTextLinkBodyStruct(new_body_data, old_body_data);
std::string segment;
if (!GenerateTitaniumTextLinkBody(segment, new_body_data)) {
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): body generation error '%s'", segment.c_str());
conversion_error = true;
}
else {
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): body generation success '%s'", segment.c_str());
segment.append(segments[iter].substr(EmuConstants::TEXT_LINK_BODY_LENGTH).c_str());
segments[iter] = segment.c_str();
}
}
if (conversion_error) {
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): conversion error");
titaniumTextLink = serverTextLink;
return;
}
for (size_t iter = 0; iter < segments.size(); ++iter) {
if (iter & 1) {
titaniumTextLink.push_back(delimiter);
titaniumTextLink.append(segments[iter].c_str());
titaniumTextLink.push_back(delimiter);
}
else {
titaniumTextLink.append(segments[iter].c_str());
}
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): segment[%u] '%s'", iter, segments[iter].c_str());
}
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): new message '%s'", titaniumTextLink.c_str());
#else
if ((consts::TEXT_LINK_BODY_LENGTH == EmuConstants::TEXT_LINK_BODY_LENGTH) || (serverTextLink.find(delimiter) == std::string::npos)) {
titaniumTextLink = serverTextLink;
return;
}
bool conversion_error = false;
auto segments = SplitString(serverTextLink, delimiter);
for (size_t iter = 1; iter < segments.size(); iter += 2) {
TextLinkBody_Struct old_body_data;
if (!DegenerateServerTextLinkBody(old_body_data, segments[iter].substr(0, EmuConstants::TEXT_LINK_BODY_LENGTH).c_str())) {
conversion_error = true;
break;
}
structs::TextLinkBody_Struct new_body_data;
ServerToTitaniumTextLinkBodyStruct(new_body_data, old_body_data);
std::string segment;
if (!GenerateTitaniumTextLinkBody(segment, new_body_data)) {
conversion_error = true;
break;
}
else {
segment.append(segments[iter].substr(EmuConstants::TEXT_LINK_BODY_LENGTH).c_str());
segments[iter] = segment.c_str();
}
}
if (conversion_error) {
_log(CHANNELS__ERROR, "TextLink(Server->Titanium): conversion error");
titaniumTextLink = serverTextLink;
return;
}
for (size_t iter = 0; iter < segments.size(); ++iter) {
if (iter & 1) {
titaniumTextLink.push_back(delimiter);
titaniumTextLink.append(segments[iter].c_str());
titaniumTextLink.push_back(delimiter);
}
else {
titaniumTextLink.append(segments[iter].c_str());
}
}
#endif
}
static inline bool DegenerateServerTextLinkBody(TextLinkBody_Struct& serverLinkBodyStruct, const std::string& serverLinkBody)
{
memset(&serverLinkBodyStruct, 0, sizeof(TextLinkBody_Struct));
if (serverLinkBody.length() != EmuConstants::TEXT_LINK_BODY_LENGTH) { return false; }
serverLinkBodyStruct.unknown_1 = (uint8)strtol(serverLinkBody.substr(0, 1).c_str(), nullptr, 16);
serverLinkBodyStruct.item_id = (uint32)strtol(serverLinkBody.substr(1, 5).c_str(), nullptr, 16);
serverLinkBodyStruct.augment_1 = (uint32)strtol(serverLinkBody.substr(6, 5).c_str(), nullptr, 16);
serverLinkBodyStruct.augment_2 = (uint32)strtol(serverLinkBody.substr(11, 5).c_str(), nullptr, 16);
serverLinkBodyStruct.augment_3 = (uint32)strtol(serverLinkBody.substr(16, 5).c_str(), nullptr, 16);
serverLinkBodyStruct.augment_4 = (uint32)strtol(serverLinkBody.substr(21, 5).c_str(), nullptr, 16);
serverLinkBodyStruct.augment_5 = (uint32)strtol(serverLinkBody.substr(26, 5).c_str(), nullptr, 16);
serverLinkBodyStruct.augment_6 = (uint32)strtol(serverLinkBody.substr(31, 5).c_str(), nullptr, 16);
serverLinkBodyStruct.unknown_2 = (uint8)strtol(serverLinkBody.substr(36, 1).c_str(), nullptr, 16);
serverLinkBodyStruct.unknown_3 = (uint8)strtol(serverLinkBody.substr(37, 1).c_str(), nullptr, 16);
serverLinkBodyStruct.unknown_4 = (uint32)strtol(serverLinkBody.substr(38, 4).c_str(), nullptr, 16);
serverLinkBodyStruct.unknown_5 = (uint8)strtol(serverLinkBody.substr(42, 1).c_str(), nullptr, 16);
serverLinkBodyStruct.ornament_icon = (uint32)strtol(serverLinkBody.substr(43, 5).c_str(), nullptr, 16);
serverLinkBodyStruct.hash = (int)strtol(serverLinkBody.substr(48, 8).c_str(), nullptr, 16);
return true;
}
static inline void ServerToTitaniumTextLinkBodyStruct(structs::TextLinkBody_Struct& titaniumLinkBodyStruct, const TextLinkBody_Struct& serverLinkBodyStruct)
{
titaniumLinkBodyStruct.unknown_1 = serverLinkBodyStruct.unknown_1;
titaniumLinkBodyStruct.item_id = serverLinkBodyStruct.item_id;
titaniumLinkBodyStruct.augment_1 = serverLinkBodyStruct.augment_1;
titaniumLinkBodyStruct.augment_2 = serverLinkBodyStruct.augment_2;
titaniumLinkBodyStruct.augment_3 = serverLinkBodyStruct.augment_3;
titaniumLinkBodyStruct.augment_4 = serverLinkBodyStruct.augment_4;
titaniumLinkBodyStruct.augment_5 = serverLinkBodyStruct.augment_5;
titaniumLinkBodyStruct.unknown_2 = serverLinkBodyStruct.unknown_3;
titaniumLinkBodyStruct.unknown_3 = serverLinkBodyStruct.unknown_4;
titaniumLinkBodyStruct.unknown_4 = serverLinkBodyStruct.unknown_5;
titaniumLinkBodyStruct.hash = serverLinkBodyStruct.hash;
}
static inline bool GenerateTitaniumTextLinkBody(std::string& titaniumLinkBody, const structs::TextLinkBody_Struct& titaniumLinkBodyStruct)
{
titaniumLinkBody = StringFormat(
"%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%1X" "%04X" "%1X" "%08X",
titaniumLinkBodyStruct.unknown_1,
titaniumLinkBodyStruct.item_id,
titaniumLinkBodyStruct.augment_1,
titaniumLinkBodyStruct.augment_2,
titaniumLinkBodyStruct.augment_3,
titaniumLinkBodyStruct.augment_4,
titaniumLinkBodyStruct.augment_5,
titaniumLinkBodyStruct.unknown_2,
titaniumLinkBodyStruct.unknown_3,
titaniumLinkBodyStruct.unknown_4,
titaniumLinkBodyStruct.hash
);
if (titaniumLinkBody.length() != consts::TEXT_LINK_BODY_LENGTH) { return false; }
return true;
}
static inline void TitaniumToServerTextLinks(std::string& serverTextLink, const std::string& titaniumTextLink)
{
const char delimiter = 0x12;
#if EQDEBUG >= 6
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): old message '%s'", titaniumTextLink.c_str());
if (EmuConstants::TEXT_LINK_BODY_LENGTH == consts::TEXT_LINK_BODY_LENGTH) {
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): link size equal, no conversion necessary");
serverTextLink = titaniumTextLink;
return;
}
if (titaniumTextLink.find(delimiter) == std::string::npos) {
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): delimiter not found, no conversion necessary");
serverTextLink = titaniumTextLink;
return;
}
bool conversion_error = false;
auto segments = SplitString(titaniumTextLink, delimiter);
for (size_t iter = 1; iter < segments.size(); iter += 2) {
structs::TextLinkBody_Struct old_body_data;
if (!DegenerateTitaniumTextLinkBody(old_body_data, segments[iter].substr(0, consts::TEXT_LINK_BODY_LENGTH).c_str())) {
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): body degeneration error '%s'", segments[iter].substr(0, consts::TEXT_LINK_BODY_LENGTH).c_str());
conversion_error = true;
}
else {
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): body degeneration success '%s'", segments[iter].substr(0, consts::TEXT_LINK_BODY_LENGTH).c_str());
}
TextLinkBody_Struct new_body_data;
TitaniumToServerTextLinkBodyStruct(new_body_data, old_body_data);
std::string segment;
if (!GenerateServerTextLinkBody(segment, new_body_data)) {
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): body generation error '%s'", segment.c_str());
conversion_error = true;
}
else {
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): body generation success '%s'", segment.c_str());
segment.append(segments[iter].substr(consts::TEXT_LINK_BODY_LENGTH).c_str());
segments[iter] = segment.c_str();
}
}
if (conversion_error) {
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): conversion error");
serverTextLink = titaniumTextLink;
return;
}
for (size_t iter = 0; iter < segments.size(); ++iter) {
if (iter & 1) {
serverTextLink.push_back(delimiter);
serverTextLink.append(segments[iter].c_str());
serverTextLink.push_back(delimiter);
}
else {
serverTextLink.append(segments[iter].c_str());
}
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): segment[%u] '%s'", iter, segments[iter].c_str());
}
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): new message '%s'", serverTextLink.c_str());
#else
if ((EmuConstants::TEXT_LINK_BODY_LENGTH == consts::TEXT_LINK_BODY_LENGTH) || (titaniumTextLink.find(delimiter) == std::string::npos)) {
serverTextLink = titaniumTextLink;
return;
}
bool conversion_error = false;
auto segments = SplitString(titaniumTextLink, delimiter);
for (size_t iter = 1; iter < segments.size(); iter += 2) {
structs::TextLinkBody_Struct old_body_data;
if (!DegenerateTitaniumTextLinkBody(old_body_data, segments[iter].substr(0, consts::TEXT_LINK_BODY_LENGTH).c_str())) {
conversion_error = true;
break;
}
TextLinkBody_Struct new_body_data;
TitaniumToServerTextLinkBodyStruct(new_body_data, old_body_data);
std::string segment;
if (!GenerateServerTextLinkBody(segment, new_body_data)) {
conversion_error = true;
break;
}
else {
segment.append(segments[iter].substr(consts::TEXT_LINK_BODY_LENGTH).c_str());
segments[iter] = segment.c_str();
}
}
if (conversion_error) {
_log(CHANNELS__ERROR, "TextLink(Titanium->Server): conversion error");
serverTextLink = titaniumTextLink;
return;
}
for (size_t iter = 0; iter < segments.size(); ++iter) {
if (iter & 1) {
serverTextLink.push_back(delimiter);
serverTextLink.append(segments[iter].c_str());
serverTextLink.push_back(delimiter);
}
else {
serverTextLink.append(segments[iter].c_str());
}
}
#endif
}
static inline bool DegenerateTitaniumTextLinkBody(structs::TextLinkBody_Struct& titaniumLinkBodyStruct, const std::string& titaniumLinkBody)
{
// 6.2: "%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%1X" "%04X" "%1X" "%08X"
memset(&titaniumLinkBodyStruct, 0, sizeof(structs::TextLinkBody_Struct));
if (titaniumLinkBody.length() != consts::TEXT_LINK_BODY_LENGTH) { return false; }
titaniumLinkBodyStruct.unknown_1 = (uint8)strtol(titaniumLinkBody.substr(0, 1).c_str(), nullptr, 16);
titaniumLinkBodyStruct.item_id = (uint32)strtol(titaniumLinkBody.substr(1, 5).c_str(), nullptr, 16);
titaniumLinkBodyStruct.augment_1 = (uint32)strtol(titaniumLinkBody.substr(6, 5).c_str(), nullptr, 16);
titaniumLinkBodyStruct.augment_2 = (uint32)strtol(titaniumLinkBody.substr(11, 5).c_str(), nullptr, 16);
titaniumLinkBodyStruct.augment_3 = (uint32)strtol(titaniumLinkBody.substr(16, 5).c_str(), nullptr, 16);
titaniumLinkBodyStruct.augment_4 = (uint32)strtol(titaniumLinkBody.substr(21, 5).c_str(), nullptr, 16);
titaniumLinkBodyStruct.augment_5 = (uint32)strtol(titaniumLinkBody.substr(26, 5).c_str(), nullptr, 16);
titaniumLinkBodyStruct.unknown_2 = (uint8)strtol(titaniumLinkBody.substr(31, 1).c_str(), nullptr, 16);
titaniumLinkBodyStruct.unknown_3 = (uint32)strtol(titaniumLinkBody.substr(32, 4).c_str(), nullptr, 16);
titaniumLinkBodyStruct.unknown_4 = (uint8)strtol(titaniumLinkBody.substr(36, 1).c_str(), nullptr, 16);
titaniumLinkBodyStruct.hash = (int)strtol(titaniumLinkBody.substr(37, 8).c_str(), nullptr, 16);
return true;
}
static inline void TitaniumToServerTextLinkBodyStruct(TextLinkBody_Struct& serverLinkBodyStruct, const structs::TextLinkBody_Struct& titaniumLinkBodyStruct)
{
serverLinkBodyStruct.unknown_1 = titaniumLinkBodyStruct.unknown_1;
serverLinkBodyStruct.item_id = titaniumLinkBodyStruct.item_id;
serverLinkBodyStruct.augment_1 = titaniumLinkBodyStruct.augment_1;
serverLinkBodyStruct.augment_2 = titaniumLinkBodyStruct.augment_2;
serverLinkBodyStruct.augment_3 = titaniumLinkBodyStruct.augment_3;
serverLinkBodyStruct.augment_4 = titaniumLinkBodyStruct.augment_4;
serverLinkBodyStruct.augment_5 = titaniumLinkBodyStruct.augment_5;
serverLinkBodyStruct.augment_6 = NOT_USED;
serverLinkBodyStruct.unknown_2 = NOT_USED;
serverLinkBodyStruct.unknown_3 = titaniumLinkBodyStruct.unknown_2;
serverLinkBodyStruct.unknown_4 = titaniumLinkBodyStruct.unknown_3;
serverLinkBodyStruct.unknown_5 = titaniumLinkBodyStruct.unknown_4;
serverLinkBodyStruct.ornament_icon = NOT_USED;
serverLinkBodyStruct.hash = titaniumLinkBodyStruct.hash;
}
static inline bool GenerateServerTextLinkBody(std::string& serverLinkBody, const TextLinkBody_Struct& serverLinkBodyStruct)
{
serverLinkBody = StringFormat(
"%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%01X" "%01X" "%04X" "%01X" "%05X" "%08X",
serverLinkBodyStruct.unknown_1,
serverLinkBodyStruct.item_id,
serverLinkBodyStruct.augment_1,
serverLinkBodyStruct.augment_2,
serverLinkBodyStruct.augment_3,
serverLinkBodyStruct.augment_4,
serverLinkBodyStruct.augment_5,
serverLinkBodyStruct.augment_6,
serverLinkBodyStruct.unknown_2,
serverLinkBodyStruct.unknown_3,
serverLinkBodyStruct.unknown_4,
serverLinkBodyStruct.unknown_5,
serverLinkBodyStruct.ornament_icon,
serverLinkBodyStruct.hash
);
if (serverLinkBody.length() != EmuConstants::TEXT_LINK_BODY_LENGTH) { return false; }
return true;
}
}
// end namespace Titanium