From d5b24543e84abe121edeb7471b7e73831f651d46 Mon Sep 17 00:00:00 2001 From: Uleat Date: Mon, 12 Jan 2015 14:35:38 -0500 Subject: [PATCH] Added text link translators for OP_TaskDescription (RoF+ -- all clients current) --- changelog.txt | 1 + common/patches/rof.cpp | 52 +++++++++++++++++++++++++++++++----- common/patches/rof2.cpp | 46 +++++++++++++++++++++++++++++++ common/patches/sod.cpp | 6 ++--- common/patches/sof.cpp | 6 ++--- common/patches/titanium.cpp | 2 +- common/patches/underfoot.cpp | 6 ++--- zone/tasks.cpp | 12 ++++----- 8 files changed, 109 insertions(+), 22 deletions(-) diff --git a/changelog.txt b/changelog.txt index 8ad64ad30..656a861e8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- == 01/12/2015 == Uleat: Fix for OP_FormattedMessage text link server crashes +Uleat: Added text link translators for OP_TaskDescription (RoF+ -- all clients current) == 01/11/2015 == Uleat: Added text link translators for OP_TaskDescription (Ti thru UF..RoF+ in-work) diff --git a/common/patches/rof.cpp b/common/patches/rof.cpp index 2ccac0803..9bf49156f 100644 --- a/common/patches/rof.cpp +++ b/common/patches/rof.cpp @@ -3249,16 +3249,55 @@ namespace RoF EQApplicationPacket *in = *p; *p = nullptr; + unsigned char *__emu_buffer = in->pBuffer; + + char *InBuffer = (char *)in->pBuffer; + char *block_start = InBuffer; + + InBuffer += sizeof(TaskDescriptionHeader_Struct); + uint32 title_size = strlen(InBuffer) + 1; + InBuffer += title_size; + + TaskDescriptionData1_Struct *emu_tdd1 = (TaskDescriptionData1_Struct *)InBuffer; + emu_tdd1->StartTime = (time(nullptr) - emu_tdd1->StartTime); // RoF has elapsed time here rather than start time + + InBuffer += sizeof(TaskDescriptionData1_Struct); + uint32 description_size = strlen(InBuffer) + 1; + InBuffer += description_size; + InBuffer += sizeof(TaskDescriptionData2_Struct); + + std::string old_message = InBuffer; // start 'Reward' as string + std::string new_message; + ServerToRoFTextLink(new_message, old_message); + + in->size = sizeof(TaskDescriptionHeader_Struct) + sizeof(TaskDescriptionData1_Struct)+ + sizeof(TaskDescriptionData2_Struct) + sizeof(TaskDescriptionTrailer_Struct)+ + title_size + description_size + new_message.length() + 1; + + in->pBuffer = new unsigned char[in->size]; + + char *OutBuffer = (char *)in->pBuffer; + + memcpy(OutBuffer, block_start, (InBuffer - block_start)); + OutBuffer += (InBuffer - block_start); + + VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str()); + + InBuffer += strlen(InBuffer) + 1; + + memcpy(OutBuffer, InBuffer, sizeof(TaskDescriptionTrailer_Struct)); + + delete[] __emu_buffer; + dest->FastQueuePacket(&in, ack_req); + +#if 0 // original code + EQApplicationPacket *in = *p; + *p = nullptr; + EQApplicationPacket *outapp = new EQApplicationPacket(OP_TaskDescription, in->size + 1); // Set the Write pointer as we don't know what has been done with the packet before we get it. in->SetReadPosition(0); // Copy the header - // - // Server header struct is { uint32; uint32; uint32; uint32; uint8; } - // Yet, we're writing 5 uint32's... that's 17 vs 20 bytes... - // 3 Bytes difference..but, we only increase packet size by 1 byte..something wrong here? -U - // (Tying to add text link translators and can't figure out if '+1' size is a new RoF field or something else) - // for (int i = 0; i < 5; ++i) outapp->WriteUInt32(in->ReadUInt32()); @@ -3278,6 +3317,7 @@ namespace RoF delete in; dest->FastQueuePacket(&outapp, ack_req); +#endif } ENCODE(OP_TaskHistoryReply) diff --git a/common/patches/rof2.cpp b/common/patches/rof2.cpp index 10798be82..61d09826a 100644 --- a/common/patches/rof2.cpp +++ b/common/patches/rof2.cpp @@ -3315,6 +3315,51 @@ namespace RoF2 EQApplicationPacket *in = *p; *p = nullptr; + unsigned char *__emu_buffer = in->pBuffer; + + char *InBuffer = (char *)in->pBuffer; + char *block_start = InBuffer; + + InBuffer += sizeof(TaskDescriptionHeader_Struct); + uint32 title_size = strlen(InBuffer) + 1; + InBuffer += title_size; + + TaskDescriptionData1_Struct *emu_tdd1 = (TaskDescriptionData1_Struct *)InBuffer; + emu_tdd1->StartTime = (time(nullptr) - emu_tdd1->StartTime); // RoF2 has elapsed time here rather than start time + + InBuffer += sizeof(TaskDescriptionData1_Struct); + uint32 description_size = strlen(InBuffer) + 1; + InBuffer += description_size; + InBuffer += sizeof(TaskDescriptionData2_Struct); + + std::string old_message = InBuffer; // start 'Reward' as string + std::string new_message; + ServerToRoF2TextLink(new_message, old_message); + + in->size = sizeof(TaskDescriptionHeader_Struct) + sizeof(TaskDescriptionData1_Struct)+ + sizeof(TaskDescriptionData2_Struct) + sizeof(TaskDescriptionTrailer_Struct)+ + title_size + description_size + new_message.length() + 1; + + in->pBuffer = new unsigned char[in->size]; + + char *OutBuffer = (char *)in->pBuffer; + + memcpy(OutBuffer, block_start, (InBuffer - block_start)); + OutBuffer += (InBuffer - block_start); + + VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str()); + + InBuffer += strlen(InBuffer) + 1; + + memcpy(OutBuffer, InBuffer, sizeof(TaskDescriptionTrailer_Struct)); + + delete[] __emu_buffer; + dest->FastQueuePacket(&in, ack_req); + +#if 0 // original code + EQApplicationPacket *in = *p; + *p = nullptr; + EQApplicationPacket *outapp = new EQApplicationPacket(OP_TaskDescription, in->size + 1); // Set the Write pointer as we don't know what has been done with the packet before we get it. in->SetReadPosition(0); @@ -3338,6 +3383,7 @@ namespace RoF2 delete in; dest->FastQueuePacket(&outapp, ack_req); +#endif } ENCODE(OP_TaskHistoryReply) diff --git a/common/patches/sod.cpp b/common/patches/sod.cpp index 3938e238f..7e4059414 100644 --- a/common/patches/sod.cpp +++ b/common/patches/sod.cpp @@ -2201,15 +2201,15 @@ namespace SoD std::string new_message; ServerToSoDTextLink(new_message, old_message); - in->size = sizeof(TaskDescriptionHeader_Struct)+sizeof(TaskDescriptionData1_Struct)+ - sizeof(TaskDescriptionData2_Struct)+sizeof(TaskDescriptionTrailer_Struct)+ + in->size = sizeof(TaskDescriptionHeader_Struct) + sizeof(TaskDescriptionData1_Struct)+ + sizeof(TaskDescriptionData2_Struct) + sizeof(TaskDescriptionTrailer_Struct)+ title_size + description_size + new_message.length() + 1; in->pBuffer = new unsigned char[in->size]; char *OutBuffer = (char *)in->pBuffer; - memcpy(OutBuffer, (char *)__emu_buffer, (InBuffer - block_start)); + memcpy(OutBuffer, block_start, (InBuffer - block_start)); OutBuffer += (InBuffer - block_start); VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str()); diff --git a/common/patches/sof.cpp b/common/patches/sof.cpp index a9c5c0ea2..942e36581 100644 --- a/common/patches/sof.cpp +++ b/common/patches/sof.cpp @@ -1800,15 +1800,15 @@ namespace SoF std::string new_message; ServerToSoFTextLink(new_message, old_message); - in->size = sizeof(TaskDescriptionHeader_Struct)+sizeof(TaskDescriptionData1_Struct)+ - sizeof(TaskDescriptionData2_Struct)+sizeof(TaskDescriptionTrailer_Struct)+ + in->size = sizeof(TaskDescriptionHeader_Struct) + sizeof(TaskDescriptionData1_Struct)+ + sizeof(TaskDescriptionData2_Struct) + sizeof(TaskDescriptionTrailer_Struct)+ title_size + description_size + new_message.length() + 1; in->pBuffer = new unsigned char[in->size]; char *OutBuffer = (char *)in->pBuffer; - memcpy(OutBuffer, (char *)__emu_buffer, (InBuffer - block_start)); + memcpy(OutBuffer, block_start, (InBuffer - block_start)); OutBuffer += (InBuffer - block_start); VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str()); diff --git a/common/patches/titanium.cpp b/common/patches/titanium.cpp index 500e5f128..c51f6b078 100644 --- a/common/patches/titanium.cpp +++ b/common/patches/titanium.cpp @@ -1258,7 +1258,7 @@ namespace Titanium char *OutBuffer = (char *)in->pBuffer; - memcpy(OutBuffer, (char *)__emu_buffer, (InBuffer - block_start)); + memcpy(OutBuffer, block_start, (InBuffer - block_start)); OutBuffer += (InBuffer - block_start); VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str()); diff --git a/common/patches/underfoot.cpp b/common/patches/underfoot.cpp index 5a07fed7e..9f595a8e3 100644 --- a/common/patches/underfoot.cpp +++ b/common/patches/underfoot.cpp @@ -2467,15 +2467,15 @@ namespace Underfoot std::string new_message; ServerToUnderfootTextLink(new_message, old_message); - in->size = sizeof(TaskDescriptionHeader_Struct)+sizeof(TaskDescriptionData1_Struct)+ - sizeof(TaskDescriptionData2_Struct)+sizeof(TaskDescriptionTrailer_Struct)+ + in->size = sizeof(TaskDescriptionHeader_Struct) + sizeof(TaskDescriptionData1_Struct)+ + sizeof(TaskDescriptionData2_Struct) + sizeof(TaskDescriptionTrailer_Struct)+ title_size + description_size + new_message.length() + 1; in->pBuffer = new unsigned char[in->size]; char *OutBuffer = (char *)in->pBuffer; - memcpy(OutBuffer, (char *)__emu_buffer, (InBuffer - block_start)); + memcpy(OutBuffer, block_start, (InBuffer - block_start)); OutBuffer += (InBuffer - block_start); VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str()); diff --git a/zone/tasks.cpp b/zone/tasks.cpp index d6f285de6..431a7554c 100644 --- a/zone/tasks.cpp +++ b/zone/tasks.cpp @@ -2756,7 +2756,7 @@ void TaskManager::SendActiveTaskDescription(Client *c, int TaskID, int SequenceN + sizeof(TaskDescriptionData1_Struct) + strlen(Tasks[TaskID]->Description) + 1 + sizeof(TaskDescriptionData2_Struct) + 1 + sizeof(TaskDescriptionTrailer_Struct); - std::string RewardText; + std::string reward_text; int ItemID = NOT_USED; // If there is an item make the Reward text into a link to the item (only the first item if a list @@ -2784,17 +2784,17 @@ void TaskManager::SendActiveTaskDescription(Client *c, int TaskID, int SequenceN linker.SetProxyText(Tasks[TaskID]->Reward); auto reward_link = linker.GenerateLink(); - RewardText += reward_link.c_str(); + reward_text.append(reward_link); } else { - RewardText += Tasks[TaskID]->Reward; + reward_text.append(Tasks[TaskID]->Reward); } } else { - RewardText += Tasks[TaskID]->Reward; + reward_text.append(Tasks[TaskID]->Reward); } - PacketLength += strlen(RewardText.c_str()) + 1; + PacketLength += reward_text.length() + 1; char *Ptr; TaskDescriptionHeader_Struct* tdh; @@ -2850,7 +2850,7 @@ void TaskManager::SendActiveTaskDescription(Client *c, int TaskID, int SequenceN tdd2->unknown3 = 0x0000; Ptr = (char *) tdd2 + sizeof(TaskDescriptionData2_Struct); - sprintf(Ptr, "%s", RewardText.c_str()); + sprintf(Ptr, "%s", reward_text.c_str()); Ptr = Ptr + strlen(Ptr) + 1; tdt = (TaskDescriptionTrailer_Struct*)Ptr;