From 735b4181facad352f845dc15ed3ef3bdc786d241 Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Fri, 15 Mar 2013 03:27:45 -0400 Subject: [PATCH 1/9] Test --- zone/client.cpp | 106 ++++++++++++++++++++++++----------------- zone/client_packet.cpp | 77 ++++++++++++++++-------------- zone/merc.cpp | 11 ++++- 3 files changed, 113 insertions(+), 81 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index 155047aa6..70126a0a6 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -1472,7 +1472,7 @@ void Client::SendSound(){//Makes a sound. memset(&x[64],0xffffffff,sizeof(uint32)); memcpy(outapp->pBuffer,x,outapp->size); QueuePacket(outapp); - DumpPacket(outapp); + //DumpPacket(outapp); safe_delete(outapp); } @@ -7137,68 +7137,76 @@ void Client::SendMercPersonalInfo() if (GetClientVersion() >= EQClientRoF) { - MercenaryDataUpdate_Struct* mdus = new MercenaryDataUpdate_Struct; - MercTemplate *mercData = &zone->merc_templates[GetMercInfo().MercTemplateID]; if (mercData) { + int i = 0; + int stancecount = 0; + stancecount += zone->merc_stance_list[GetMercInfo().MercTemplateID].size(); + + if (mercCount > 0) + { + EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataUpdate, sizeof(MercenaryDataUpdate_Struct) + (mercTypeCount * sizeof(MercenaryData_Struct)) + stancecount * sizeof(MercenaryStance_Struct)); + MercenaryDataUpdate_Struct* mdus = (MercenaryDataUpdate_Struct*)outapp->pBuffer; mdus->MercStatus = 0; mdus->MercCount = mercCount; - if (mercCount > 0) + mdus->MercData = new MercenaryData_Struct[mercCount]; + mdus->MercData[i].MercID = mercData->MercTemplateID; + mdus->MercData[i].MercType = mercData->MercType; + mdus->MercData[i].MercSubType = mercData->MercSubType; + mdus->MercData[i].PurchaseCost = Merc::CalcPurchaseCost(mercData->MercTemplateID, GetLevel(), 0); + mdus->MercData[i].UpkeepCost = Merc::CalcUpkeepCost(mercData->MercTemplateID, GetLevel(), 0); + mdus->MercData[i].Status = 0; + mdus->MercData[i].AltCurrencyCost = Merc::CalcPurchaseCost(mercData->MercTemplateID, GetLevel(), altCurrentType); + mdus->MercData[i].AltCurrencyUpkeep = Merc::CalcPurchaseCost(mercData->MercTemplateID, GetLevel(), altCurrentType); + mdus->MercData[i].AltCurrencyType = altCurrentType; + mdus->MercData[i].MercUnk01 = 0; + mdus->MercData[i].TimeLeft = GetMercInfo().MercTimerRemaining; //GetMercTimer().GetRemainingTime(); + mdus->MercData[i].MerchantSlot = i + 1; + mdus->MercData[i].MercUnk02 = 1; + mdus->MercData[i].StanceCount = zone->merc_stance_list[mercData->MercTemplateID].size(); + mdus->MercData[i].MercUnk03 = 0; + mdus->MercData[i].MercUnk04 = 1; + strn0cpy(mdus->MercData[i].MercName, GetMercInfo().merc_name , sizeof(mdus->MercData[i].MercName)); + uint32 stanceindex = 0; + if (mdus->MercData[i].StanceCount != 0) { - mdus->MercData = new MercenaryData_Struct[mercCount]; - mdus->MercData[i].MercID = mercData->MercTemplateID; - mdus->MercData[i].MercType = mercData->MercType; - mdus->MercData[i].MercSubType = mercData->MercSubType; - mdus->MercData[i].PurchaseCost = Merc::CalcPurchaseCost(mercData->MercTemplateID, GetLevel(), 0); - mdus->MercData[i].UpkeepCost = Merc::CalcUpkeepCost(mercData->MercTemplateID, GetLevel(), 0); - mdus->MercData[i].Status = 0; - mdus->MercData[i].AltCurrencyCost = Merc::CalcPurchaseCost(mercData->MercTemplateID, GetLevel(), altCurrentType); - mdus->MercData[i].AltCurrencyUpkeep = Merc::CalcPurchaseCost(mercData->MercTemplateID, GetLevel(), altCurrentType); - mdus->MercData[i].AltCurrencyType = altCurrentType; - mdus->MercData[i].MercUnk01 = 0; - mdus->MercData[i].TimeLeft = GetMercInfo().MercTimerRemaining; //GetMercTimer().GetRemainingTime(); - mdus->MercData[i].MerchantSlot = i + 1; - mdus->MercData[i].MercUnk02 = 1; - mdus->MercData[i].StanceCount = zone->merc_stance_list[mercData->MercTemplateID].size(); - mdus->MercData[i].MercUnk03 = 0; - mdus->MercData[i].MercUnk04 = 1; - strn0cpy(mdus->MercData[i].MercName, GetMercInfo().merc_name , sizeof(mdus->MercData[i].MercName)); - uint32 stanceindex = 0; - if (mdus->MercData[i].StanceCount != 0) + mdus->MercData[i].Stances = new MercenaryStance_Struct[mdus->MercData[i].StanceCount]; + list::iterator iter = zone->merc_stance_list[mercData->MercTemplateID].begin(); + while(iter != zone->merc_stance_list[mercData->MercTemplateID].end()) { - mdus->MercData[i].Stances = new MercenaryStance_Struct[mdus->MercData[i].StanceCount]; - list::iterator iter = zone->merc_stance_list[mercData->MercTemplateID].begin(); - while(iter != zone->merc_stance_list[mercData->MercTemplateID].end()) - { - mdus->MercData[i].Stances[stanceindex].StanceIndex = stanceindex; - mdus->MercData[i].Stances[stanceindex].Stance = (iter->StanceID); - stanceindex++; - iter++; - } + mdus->MercData[i].Stances[stanceindex].StanceIndex = stanceindex; + mdus->MercData[i].Stances[stanceindex].Stance = (iter->StanceID); + stanceindex++; + iter++; } + } - mdus->MercData[i].MercUnk05 = 1; - - EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataUpdate, 1); //Packet sizes are handled by the encoder. - outapp->pBuffer = (unsigned char*)mdus; - //DumpPacket(outapp); - FastQueuePacket(&outapp); + mdus->MercData[i].MercUnk05 = 1; + //DumpPacket(outapp); + FastQueuePacket(&outapp); + return; } } } else { - MercenaryMerchantList_Struct* mml = new MercenaryMerchantList_Struct; + int stancecount = 0; + stancecount += zone->merc_stance_list[GetMercInfo().MercTemplateID].size(); + + EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataResponse, sizeof(MercenaryMerchantList_Struct) + (mercTypeCount * sizeof(MercenaryGrade_Struct)) + (mercCount * sizeof(MercenaryListEntry_Struct)) + stancecount * sizeof(MercenaryStance_Struct)); //Packet sizes are handled by the encoder. + MercenaryMerchantList_Struct* mml = (MercenaryMerchantList_Struct*)outapp->pBuffer; MercTemplate *mercData = &zone->merc_templates[GetMercInfo().MercTemplateID]; + if(mercData) { if(mercTypeCount > 0) { mml->MercTypeCount = mercTypeCount; //We only should have one merc entry. mml->MercGrades = new MercenaryGrade_Struct[mercTypeCount]; // DBStringID for Type + mml->MercGrades[0].GradeCountEntry = 1; } mml->MercCount = mercCount; if(mercCount > 0) @@ -7234,17 +7242,25 @@ void Client::SendMercPersonalInfo() iter++; } } - - EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataResponse, 1); //Packet sizes are handled by the encoder. - outapp->pBuffer = (unsigned char*)mml; - // DumpPacket(outapp); FastQueuePacket(&outapp); } + else + { + safe_delete(outapp); + SendMercMerchantResponsePacket(0); + return; + } if (GetClientVersion() == EQClientSoD) { SendMercMerchantResponsePacket(0); } } + else + { + safe_delete(outapp); + SendMercMerchantResponsePacket(0); + return; + } } } @@ -7256,7 +7272,7 @@ void Client::SendClearMercInfo() nmhs->MercCount = 0; nmhs->MercID = 1; - DumpPacket(outapp); + //DumpPacket(outapp); FastQueuePacket(&outapp); } diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index f4adef8ce..3d1bff42a 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -13496,8 +13496,6 @@ void Client::Handle_OP_MercenaryDataRequest(const EQApplicationPacket *app) //send info about your current merc(s) } - DumpPacket(app); - if(!RuleB(Mercs, AllowMercs)) { return; } @@ -13515,19 +13513,28 @@ void Client::Handle_OP_MercenaryDataRequest(const EQApplicationPacket *app) return; } - MercenaryMerchantList_Struct* mml = new MercenaryMerchantList_Struct; - mercTypeCount = tar->GetNumMercTypes(GetClientVersion()); mercCount = tar->GetNumMercs(GetClientVersion()); - std::list mercTypeList = tar->GetMercTypesList(GetClientVersion()); std::list mercDataList = tar->GetMercsList(GetClientVersion()); - mml->MercTypeCount = mercTypeCount; int i = 0; + int StanceCount = 0; + for(std::list::iterator mercListItr = mercDataList.begin(); mercListItr != mercDataList.end(); mercListItr++) + { + list::iterator siter = zone->merc_stance_list[mercListItr->MercTemplateID].begin(); + for(siter = zone->merc_stance_list[mercListItr->MercTemplateID].begin(); siter != zone->merc_stance_list[mercListItr->MercTemplateID].end(); siter++) + { + StanceCount++; + } + } + EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataResponse, sizeof(MercenaryMerchantList_Struct) + (mercTypeCount * sizeof(MercenaryGrade_Struct)) + (mercCount * sizeof(MercenaryListEntry_Struct)) + (StanceCount * sizeof(MercenaryStance_Struct))); + MercenaryMerchantList_Struct* mml = (MercenaryMerchantList_Struct*)outapp->pBuffer; + + mml->MercTypeCount = mercTypeCount; if(mercTypeCount > 0) { mml->MercGrades = new MercenaryGrade_Struct[mercTypeCount]; @@ -13540,50 +13547,50 @@ void Client::Handle_OP_MercenaryDataRequest(const EQApplicationPacket *app) if(mercCount > 0) { - mml->Mercs = new MercenaryListEntry_Struct[mercCount]; i = 0; - for(std::list::iterator mercListItr = mercDataList.begin(); mercListItr != mercDataList.end(); mercListItr++) + mml->Mercs = new MercenaryListEntry_Struct[mercCount]; + for(std::list::iterator mercListIter = mercDataList.begin(); mercListIter != mercDataList.end(); mercListIter++) { - mml->Mercs[i].MercID = mercListItr->MercTemplateID; - mml->Mercs[i].MercType = mercListItr->MercType; - mml->Mercs[i].MercSubType = mercListItr->MercSubType; - mml->Mercs[i].PurchaseCost = RuleB(Mercs, ChargeMercPurchaseCost) ? Merc::CalcPurchaseCost(mercListItr->MercTemplateID, GetLevel(), 0): 0; - mml->Mercs[i].UpkeepCost = RuleB(Mercs, ChargeMercUpkeepCost) ? Merc::CalcUpkeepCost(mercListItr->MercTemplateID, GetLevel(), 0): 0; + mml->Mercs[i].MercID = mercListIter->MercTemplateID; + mml->Mercs[i].MercType = mercListIter->MercType; + mml->Mercs[i].MercSubType = mercListIter->MercSubType; + mml->Mercs[i].PurchaseCost = RuleB(Mercs, ChargeMercPurchaseCost) ? Merc::CalcPurchaseCost(mercListIter->MercTemplateID, GetLevel(), 0): 0; + mml->Mercs[i].UpkeepCost = RuleB(Mercs, ChargeMercUpkeepCost) ? Merc::CalcUpkeepCost(mercListIter->MercTemplateID, GetLevel(), 0): 0; mml->Mercs[i].Status = 0; - mml->Mercs[i].AltCurrencyCost = RuleB(Mercs, ChargeMercPurchaseCost) ? Merc::CalcPurchaseCost(mercListItr->MercTemplateID, GetLevel(), altCurrentType): 0; - mml->Mercs[i].AltCurrencyUpkeep = RuleB(Mercs, ChargeMercUpkeepCost) ? Merc::CalcUpkeepCost(mercListItr->MercTemplateID, GetLevel(), altCurrentType): 0; + mml->Mercs[i].AltCurrencyCost = RuleB(Mercs, ChargeMercPurchaseCost) ? Merc::CalcPurchaseCost(mercListIter->MercTemplateID, GetLevel(), altCurrentType): 0; + mml->Mercs[i].AltCurrencyUpkeep = RuleB(Mercs, ChargeMercUpkeepCost) ? Merc::CalcUpkeepCost(mercListIter->MercTemplateID, GetLevel(), altCurrentType): 0; mml->Mercs[i].AltCurrencyType = altCurrentType; mml->Mercs[i].MercUnk01 = 0; mml->Mercs[i].TimeLeft = -1; mml->Mercs[i].MerchantSlot = i + 1; mml->Mercs[i].MercUnk02 = 1; - mml->Mercs[i].StanceCount = zone->merc_stance_list[mercListItr->MercTemplateID].size(); + int mercStanceCount = 0; + list::iterator iter = zone->merc_stance_list[mercListIter->MercTemplateID].begin(); + for(iter = zone->merc_stance_list[mercListIter->MercTemplateID].begin(); iter != zone->merc_stance_list[mercListIter->MercTemplateID].end(); iter++) + { + mercStanceCount++; + } + mml->Mercs[i].StanceCount = mercStanceCount; mml->Mercs[i].MercUnk03 = 519044964; mml->Mercs[i].MercUnk04 = 1; //mml->Mercs[i].MercName; int stanceindex = 0; - if(mml->Mercs[i].StanceCount != 0) + if(mercStanceCount > 0) { - mml->Mercs[i].Stances = new MercenaryStance_Struct[mml->Mercs[i].StanceCount]; - list::iterator iter = zone->merc_stance_list[mercListItr->MercTemplateID].begin(); - while(iter != zone->merc_stance_list[mercListItr->MercTemplateID].end()) + mml->Mercs[i].Stances = new MercenaryStance_Struct[mercStanceCount]; + list::iterator iter2 = zone->merc_stance_list[mercListIter->MercTemplateID].begin(); + while(iter2 != zone->merc_stance_list[mercListIter->MercTemplateID].end()) { mml->Mercs[i].Stances[stanceindex].StanceIndex = stanceindex; - mml->Mercs[i].Stances[stanceindex].Stance = (iter->StanceID); + mml->Mercs[i].Stances[stanceindex].Stance = (iter2->StanceID); stanceindex++; - iter++; + iter2++; } } i++; } } - - - EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataResponse, 1); //Packet sizes are handled by the encoder. - outapp->pBuffer = (unsigned char*)mml; - // DumpPacket(outapp); FastQueuePacket(&outapp); - } } @@ -13605,7 +13612,7 @@ void Client::Handle_OP_MercenaryHire(const EQApplicationPacket *app) uint32 merc_unk1 = mmrq->MercUnk01; uint32 merc_unk2 = mmrq->MercUnk02; - DumpPacket(app); + //DumpPacket(app); if(MERC_DEBUG > 0) Message(7, "Mercenary Debug: Template ID (%i), Merchant ID (%i), Unknown1 (%i), Unknown2 (%i)", merc_template_id, merchant_id, merc_unk1, merc_unk2); @@ -13668,7 +13675,7 @@ void Client::Handle_OP_MercenarySuspendRequest(const EQApplicationPacket *app) SuspendMercenary_Struct* sm = (SuspendMercenary_Struct*) app->pBuffer; uint32 merc_suspend = sm->SuspendMerc; // Seen 30 for suspending or unsuspending - DumpPacket(app); + //DumpPacket(app); if(MERC_DEBUG > 0) Message(7, "Mercenary Debug: Suspend ( %i ) received.", merc_suspend); @@ -13699,7 +13706,7 @@ void Client::Handle_OP_MercenaryCommand(const EQApplicationPacket *app) GetMercInfo().State = option; } - DumpPacket(app); + //DumpPacket(app); if(MERC_DEBUG > 0) Message(7, "Mercenary Debug: Command %i, Option %i received.", merc_command, option); @@ -13723,7 +13730,7 @@ void Client::Handle_OP_MercenaryDataUpdateRequest(const EQApplicationPacket *app return; } - DumpPacket(app); + //DumpPacket(app); if(MERC_DEBUG > 0) Message(7, "Mercenary Debug: Data Update Request Received."); @@ -13745,7 +13752,7 @@ void Client::Handle_OP_MercenaryDismiss(const EQApplicationPacket *app) return; } - DumpPacket(app); + //DumpPacket(app); uint8 Command = 0; if(app->size > 0) @@ -13765,7 +13772,7 @@ void Client::Handle_OP_MercenaryDismiss(const EQApplicationPacket *app) merc->Dismiss(); } - // Unsure if there is a server response to this packet + SendMercMerchantResponsePacket(10); } @@ -13780,7 +13787,7 @@ void Client::Handle_OP_MercenaryTimerRequest(const EQApplicationPacket *app) return; } - DumpPacket(app); + //DumpPacket(app); if(MERC_DEBUG > 0) Message(7, "Mercenary Debug: Timer Request received."); diff --git a/zone/merc.cpp b/zone/merc.cpp index 267cbfdda..18722cf52 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -5123,7 +5123,7 @@ bool Merc::Unsuspend(bool setMaxStats) { if(!mercOwner->IsGrouped()) { Group *g = new Group(mercOwner); - if(AddMercToGroup(this, g)) + if(g && AddMercToGroup(this, g)) { entity_list.AddGroup(g); database.SetGroupLeaderName(g->GetID(), mercOwner->GetName()); @@ -5134,6 +5134,15 @@ bool Merc::Unsuspend(bool setMaxStats) { loaded = true; } + else + { + if(MERC_DEBUG > 0) + mercOwner->Message(7, "Mercenary failed to join the group - Suspending"); + + Suspend(); + safe_delete(g); + return false; + } } else if (AddMercToGroup(this, mercOwner->GetGroup())) { From b8170df4986b983673a843c7217a7ecd9139bb2f Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Sun, 17 Mar 2013 06:18:32 -0400 Subject: [PATCH 2/9] Hopefully fixed that pesky merc memleak and cleaned up mercs a tad. --- common/eq_packet_structs.h | 36 ++++++++++++++++++++++++-------- common/patches/RoF.cpp | 2 +- common/patches/SoD.cpp | 2 +- common/patches/Underfoot.cpp | 2 +- zone/client.cpp | 40 +++++++++++++++++++++++------------- zone/client_packet.cpp | 10 ++++----- zone/merc.cpp | 10 --------- zone/worldserver.cpp | 4 +--- 8 files changed, 63 insertions(+), 43 deletions(-) diff --git a/common/eq_packet_structs.h b/common/eq_packet_structs.h index 7b8ca52b0..1be8eddc5 100644 --- a/common/eq_packet_structs.h +++ b/common/eq_packet_structs.h @@ -27,6 +27,9 @@ //#include "../common/item_struct.h" static const uint32 BUFF_COUNT = 25; +static const uint32 MAX_MERC = 100; +static const uint32 MAX_MERC_GRADES = 10; +static const uint32 MAX_MERC_STANCES = 10; static const uint32 BLOCKED_BUFF_COUNT = 20; #include "eq_constants.h" @@ -4871,11 +4874,28 @@ struct ItemPreview_Struct /*026*/ uint8 unknown026[54]; }; -//Not an EQ packet, just a single int for the mercenary merchant structure. -struct MercenaryGrade_Struct { -uint32 GradeCountEntry; +// Used by specific packets +struct MercenaryList_Struct { +/*0000*/ uint32 MercID; // ID unique to each type of mercenary (probably a DB id) +/*0004*/ uint32 MercType; // From dbstr_us.txt - Apprentice (330000100), Journeyman (330000200), Master (330000300) +/*0008*/ uint32 MercSubType; // From dbstr_us.txt - 330020105^23^Race: Guktan
Type: Healer
Confidence: High
Proficiency: Apprentice, Tier V... +/*0012*/ uint32 PurchaseCost; // Purchase Cost (in gold) +/*0016*/ uint32 UpkeepCost; // Upkeep Cost (in gold) +/*0020*/ uint32 Status; // Required Account Status (Free = 0, Silver = 1, Gold = 2) at merchants - Seen 0 (suspended) or 1 (unsuspended) on hired mercs ? +/*0024*/ uint32 AltCurrencyCost; // Alternate Currency Purchase Cost? (all seen costs show N/A Bayle Mark) - Seen 0 +/*0028*/ uint32 AltCurrencyUpkeep; // Alternate Currency Upkeep Cost? (all seen costs show 1 Bayle Mark) - Seen 1 +/*0032*/ uint32 AltCurrencyType; // Alternate Currency Type? - 19^17^Bayle Mark^0 - Seen 19 +/*0036*/ uint8 MercUnk01; // Unknown (always see 0) +/*0037*/ int32 TimeLeft; // Unknown (always see -1 at merchant) - Seen 900000 (15 minutes in ms for newly hired merc) +/*0041*/ uint32 MerchantSlot; // Merchant Slot? Increments, but not always by 1 - May be for Merc Window Options (Seen 5, 36, 1 for active mercs)? +/*0045*/ uint32 MercUnk02; // Unknown (normally see 1, but sometimes 2 or 0) +/*0049*/ uint32 StanceCount; // Iterations of MercenaryStance_Struct - Normally 2 to 4 seen +/*0053*/ int32 MercUnk03; // Unknown (always 0 at merchant) - Seen on active merc: 93 a4 03 77, b8 ed 2f 26, 88 d5 8b c3, and 93 a4 ad 77 +/*0057*/ uint8 MercUnk04; // Seen 1 +/*0058*/ char MercName[1]; // Null Terminated Mercenary Name (00 at merchants) }; + // Used by MercenaryMerchantList_Struct struct MercenaryListEntry_Struct { /*0000*/ uint32 MercID; // ID unique to each type of mercenary (probably a DB id) @@ -4895,7 +4915,7 @@ struct MercenaryListEntry_Struct { /*0053*/ int32 MercUnk03; // Unknown (always 0 at merchant) - Seen on active merc: 93 a4 03 77, b8 ed 2f 26, 88 d5 8b c3, and 93 a4 ad 77 /*0057*/ uint8 MercUnk04; // Seen 1 /*0058*/ char MercName[1]; // Null Terminated Mercenary Name (00 at merchants) -/*0000*/ MercenaryStance_Struct* Stances; // Count Varies, but hard set to 5 max for now - From dbstr_us.txt - 1^24^Passive^0, 2^24^Balanced^0, etc (1 to 9 as of April 2012) +/*0000*/ MercenaryStance_Struct Stances[MAX_MERC_STANCES]; // Count Varies, but hard set to 5 max for now - From dbstr_us.txt - 1^24^Passive^0, 2^24^Balanced^0, etc (1 to 9 as of April 2012) }; // [OPCode: 0x27ac OP_MercenaryDataResponse] On Live as of April 2 2012 [Server->Client] @@ -4903,9 +4923,9 @@ struct MercenaryListEntry_Struct { // Sent by the server when browsing the Mercenary Merchant struct MercenaryMerchantList_Struct { /*0000*/ uint32 MercTypeCount; // Number of Merc Types to follow -/*0004*/ MercenaryGrade_Struct* MercGrades; // Count varies, but hard set to 3 max for now - From dbstr_us.txt - Apprentice (330000100), Journeyman (330000200), Master (330000300) +/*0004*/ uint32 MercGrades[MAX_MERC_GRADES]; // Count varies, but hard set to 3 max for now - From dbstr_us.txt - Apprentice (330000100), Journeyman (330000200), Master (330000300) /*0016*/ uint32 MercCount; // Number of MercenaryInfo_Struct to follow -/*0020*/ MercenaryListEntry_Struct* Mercs; // Data for individual mercenaries in the Merchant List +/*0020*/ MercenaryListEntry_Struct Mercs[MAX_MERC]; // Data for individual mercenaries in the Merchant List }; // [OPCode: 0x4dd9 OP_MercenaryDataRequest] On Live as of April 2 2012 [Client->Server] @@ -4935,7 +4955,7 @@ struct MercenaryData_Struct { /*0053*/ int32 MercUnk03; // Unknown (always 0 at merchant) - Seen on active merc: 93 a4 03 77, b8 ed 2f 26, 88 d5 8b c3, and 93 a4 ad 77 /*0057*/ uint8 MercUnk04; // Seen 1 /*0058*/ char MercName[64]; // Null Terminated Mercenary Name (00 at merchants) -/*0000*/ MercenaryStance_Struct* Stances; // Count Varies, but hard set to 2 for now - From dbstr_us.txt - 1^24^Passive^0, 2^24^Balanced^0, etc (1 to 9 as of April 2012) +/*0000*/ MercenaryStance_Struct Stances[MAX_MERC_STANCES]; // Count Varies, but hard set to 2 for now - From dbstr_us.txt - 1^24^Passive^0, 2^24^Balanced^0, etc (1 to 9 as of April 2012) /*0000*/ uint32 MercUnk05; // Seen 1 - Extra Merc Data field that differs from MercenaryListEntry_Struct // MercUnk05 may be a field that is at the end of the packet only, even if multiple mercs are listed (haven't seen examples of multiple mercs owned at once) }; @@ -4947,7 +4967,7 @@ struct MercenaryData_Struct { struct MercenaryDataUpdate_Struct { /*0000*/ int32 MercStatus; // Seen 0 with merc and -1 with no merc hired /*0004*/ uint32 MercCount; // Seen 1 with 1 merc hired and 0 with no merc hired -/*0008*/ MercenaryData_Struct* MercData; // Data for individual mercenaries in the Merchant List +/*0008*/ MercenaryData_Struct MercData[MAX_MERC]; // Data for individual mercenaries in the Merchant List }; // [OPCode: 0x6537] On Live as of April 2 2012 [Server->Client] diff --git a/common/patches/RoF.cpp b/common/patches/RoF.cpp index 0f5bcaa3f..1c56e27cd 100644 --- a/common/patches/RoF.cpp +++ b/common/patches/RoF.cpp @@ -2099,7 +2099,7 @@ ENCODE(OP_MercenaryDataResponse) { for(r = 0; r < emu->MercTypeCount; r++) { - VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercGrades[r].GradeCountEntry); + VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercGrades[r]); } VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercCount); diff --git a/common/patches/SoD.cpp b/common/patches/SoD.cpp index 685595737..99e6cd8c0 100644 --- a/common/patches/SoD.cpp +++ b/common/patches/SoD.cpp @@ -1289,7 +1289,7 @@ ENCODE(OP_MercenaryDataResponse) { { if(emu->MercTypeCount > 0) { - VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercGrades[r].GradeCountEntry); + VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercGrades[r]); } } VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercCount); diff --git a/common/patches/Underfoot.cpp b/common/patches/Underfoot.cpp index 656decd55..0da4f60c9 100644 --- a/common/patches/Underfoot.cpp +++ b/common/patches/Underfoot.cpp @@ -1297,7 +1297,7 @@ ENCODE(OP_MercenaryDataResponse) { for(r = 0; r < emu->MercTypeCount; r++) { - VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercGrades[r].GradeCountEntry); + VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercGrades[r]); } VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercCount); diff --git a/zone/client.cpp b/zone/client.cpp index e8f661d78..425309810 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -1476,7 +1476,6 @@ void Client::SendSound(){//Makes a sound. memset(&x[64],0xffffffff,sizeof(uint32)); memcpy(outapp->pBuffer,x,outapp->size); QueuePacket(outapp); - //DumpPacket(outapp); safe_delete(outapp); } @@ -7149,13 +7148,17 @@ void Client::SendMercPersonalInfo() int stancecount = 0; stancecount += zone->merc_stance_list[GetMercInfo().MercTemplateID].size(); - if (mercCount > 0) + if(stancecount > MAX_MERC_STANCES || mercCount > MAX_MERC || mercTypeCount > MAX_MERC_GRADES) { - EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataUpdate, sizeof(MercenaryDataUpdate_Struct) + (mercTypeCount * sizeof(MercenaryData_Struct)) + stancecount * sizeof(MercenaryStance_Struct)); + SendMercMerchantResponsePacket(0); + return; + } + if (mercCount > 0 && mercCount) + { + EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataUpdate, sizeof(MercenaryDataUpdate_Struct)); MercenaryDataUpdate_Struct* mdus = (MercenaryDataUpdate_Struct*)outapp->pBuffer; mdus->MercStatus = 0; mdus->MercCount = mercCount; - mdus->MercData = new MercenaryData_Struct[mercCount]; mdus->MercData[i].MercID = mercData->MercTemplateID; mdus->MercData[i].MercType = mercData->MercType; mdus->MercData[i].MercSubType = mercData->MercSubType; @@ -7176,7 +7179,6 @@ void Client::SendMercPersonalInfo() uint32 stanceindex = 0; if (mdus->MercData[i].StanceCount != 0) { - mdus->MercData[i].Stances = new MercenaryStance_Struct[mdus->MercData[i].StanceCount]; list::iterator iter = zone->merc_stance_list[mercData->MercTemplateID].begin(); while(iter != zone->merc_stance_list[mercData->MercTemplateID].end()) { @@ -7188,7 +7190,6 @@ void Client::SendMercPersonalInfo() } mdus->MercData[i].MercUnk05 = 1; - //DumpPacket(outapp); FastQueuePacket(&outapp); return; } @@ -7199,7 +7200,16 @@ void Client::SendMercPersonalInfo() int stancecount = 0; stancecount += zone->merc_stance_list[GetMercInfo().MercTemplateID].size(); - EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataResponse, sizeof(MercenaryMerchantList_Struct) + (mercTypeCount * sizeof(MercenaryGrade_Struct)) + (mercCount * sizeof(MercenaryListEntry_Struct)) + stancecount * sizeof(MercenaryStance_Struct)); //Packet sizes are handled by the encoder. + if(mercCount > MAX_MERC || mercTypeCount > MAX_MERC_GRADES) + { + if (GetClientVersion() == EQClientSoD) + { + SendMercMerchantResponsePacket(0); + } + return; + } + + EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataResponse, sizeof(MercenaryMerchantList_Struct)); MercenaryMerchantList_Struct* mml = (MercenaryMerchantList_Struct*)outapp->pBuffer; MercTemplate *mercData = &zone->merc_templates[GetMercInfo().MercTemplateID]; @@ -7209,13 +7219,12 @@ void Client::SendMercPersonalInfo() if(mercTypeCount > 0) { mml->MercTypeCount = mercTypeCount; //We only should have one merc entry. - mml->MercGrades = new MercenaryGrade_Struct[mercTypeCount]; // DBStringID for Type - mml->MercGrades[0].GradeCountEntry = 1; + mml->MercGrades[i] = 1; } mml->MercCount = mercCount; if(mercCount > 0) { - mml->Mercs = new MercenaryListEntry_Struct[mercCount]; + mml->Mercs[i].MercID = mercData->MercTemplateID; mml->Mercs[i].MercType = mercData->MercType; mml->Mercs[i].MercSubType = mercData->MercSubType; @@ -7236,7 +7245,6 @@ void Client::SendMercPersonalInfo() int stanceindex = 0; if(mml->Mercs[i].StanceCount != 0) { - mml->Mercs[i].Stances = new MercenaryStance_Struct[mml->Mercs[i].StanceCount]; list::iterator iter = zone->merc_stance_list[mercData->MercTemplateID].begin(); while(iter != zone->merc_stance_list[mercData->MercTemplateID].end()) { @@ -7251,7 +7259,10 @@ void Client::SendMercPersonalInfo() else { safe_delete(outapp); - SendMercMerchantResponsePacket(0); + if (GetClientVersion() == EQClientSoD) + { + SendMercMerchantResponsePacket(0); + } return; } if (GetClientVersion() == EQClientSoD) @@ -7262,7 +7273,10 @@ void Client::SendMercPersonalInfo() else { safe_delete(outapp); + if (GetClientVersion() == EQClientSoD) + { SendMercMerchantResponsePacket(0); + } return; } } @@ -7275,8 +7289,6 @@ void Client::SendClearMercInfo() nmhs->MercStatus = -1; nmhs->MercCount = 0; nmhs->MercID = 1; - - //DumpPacket(outapp); FastQueuePacket(&outapp); } diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 1949c7c59..e60f759bd 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -13515,6 +13515,9 @@ void Client::Handle_OP_MercenaryDataRequest(const EQApplicationPacket *app) mercTypeCount = tar->GetNumMercTypes(GetClientVersion()); mercCount = tar->GetNumMercs(GetClientVersion()); + if(mercCount > MAX_MERC) + return; + std::list mercTypeList = tar->GetMercTypesList(GetClientVersion()); std::list mercDataList = tar->GetMercsList(GetClientVersion()); @@ -13530,15 +13533,14 @@ void Client::Handle_OP_MercenaryDataRequest(const EQApplicationPacket *app) } } - EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataResponse, sizeof(MercenaryMerchantList_Struct) + (mercTypeCount * sizeof(MercenaryGrade_Struct)) + (mercCount * sizeof(MercenaryListEntry_Struct)) + (StanceCount * sizeof(MercenaryStance_Struct))); + EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryDataResponse, sizeof(MercenaryMerchantList_Struct)); MercenaryMerchantList_Struct* mml = (MercenaryMerchantList_Struct*)outapp->pBuffer; mml->MercTypeCount = mercTypeCount; if(mercTypeCount > 0) { - mml->MercGrades = new MercenaryGrade_Struct[mercTypeCount]; for(std::list::iterator mercTypeListItr = mercTypeList.begin(); mercTypeListItr != mercTypeList.end(); mercTypeListItr++) { - mml->MercGrades[i].GradeCountEntry = mercTypeListItr->Type; // DBStringID for Type + mml->MercGrades[i] = mercTypeListItr->Type; // DBStringID for Type i++; } } @@ -13547,7 +13549,6 @@ void Client::Handle_OP_MercenaryDataRequest(const EQApplicationPacket *app) if(mercCount > 0) { i = 0; - mml->Mercs = new MercenaryListEntry_Struct[mercCount]; for(std::list::iterator mercListIter = mercDataList.begin(); mercListIter != mercDataList.end(); mercListIter++) { mml->Mercs[i].MercID = mercListIter->MercTemplateID; @@ -13576,7 +13577,6 @@ void Client::Handle_OP_MercenaryDataRequest(const EQApplicationPacket *app) int stanceindex = 0; if(mercStanceCount > 0) { - mml->Mercs[i].Stances = new MercenaryStance_Struct[mercStanceCount]; list::iterator iter2 = zone->merc_stance_list[mercListIter->MercTemplateID].begin(); while(iter2 != zone->merc_stance_list[mercListIter->MercTemplateID].end()) { diff --git a/zone/merc.cpp b/zone/merc.cpp index 086a87211..8326b8b97 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -5886,24 +5886,18 @@ void Client::SendMercMerchantResponsePacket(int32 response_type) { EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryHire, sizeof(MercenaryMerchantResponse_Struct)); MercenaryMerchantResponse_Struct* mmr = (MercenaryMerchantResponse_Struct*)outapp->pBuffer; mmr->ResponseType = response_type; // send specified response type - - DumpPacket(outapp); FastQueuePacket(&outapp); } void Client::SendMercenaryUnknownPacket(uint8 type) { EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryUnknown1, 1); outapp->WriteUInt8(type); - - DumpPacket(outapp); FastQueuePacket(&outapp); } void Client::SendMercenaryUnsuspendPacket(uint8 type) { EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenaryUnsuspendResponse, 1); outapp->WriteUInt8(type); - - DumpPacket(outapp); FastQueuePacket(&outapp); } @@ -5911,8 +5905,6 @@ void Client::SendMercSuspendResponsePacket(uint32 suspended_time) { EQApplicationPacket *outapp = new EQApplicationPacket(OP_MercenarySuspendResponse, sizeof(SuspendMercenaryResponse_Struct)); SuspendMercenaryResponse_Struct* smr = (SuspendMercenaryResponse_Struct*)outapp->pBuffer; smr->SuspendTime = suspended_time; // Seen 0 (not suspended) or c9 c2 64 4f (suspended on Sat Mar 17 11:58:49 2012) - Unix Timestamp - - DumpPacket(outapp); FastQueuePacket(&outapp); } @@ -5930,8 +5922,6 @@ void Client::SendMercTimerPacket(int32 entity_id, int32 merc_state, int32 suspen mss->MercUnk01 = unk01; // Seen 180000 - 3 minutes in ms - Used for the unsuspend button refresh timer mss->MercState = merc_state; // Seen 5 (normal) or 1 (suspended) mss->SuspendedTime = suspended_time; // Seen 0 for not suspended or Unix Timestamp for suspended merc - - DumpPacket(outapp); FastQueuePacket(&outapp); } diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index 486e6a02a..f7be0ac0b 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -392,7 +392,6 @@ void WorldServer::Process() { _log(ZONE__WORLD, "Error: WhoAllReturnStruct did not point to a valid client! " "id=%i, playerineqstring=%i, playersinzonestring=%i. Dumping WhoAllReturnStruct:", wars->id, wars->playerineqstring, wars->playersinzonestring); - //DumpPacket(pack); #endif } } @@ -495,7 +494,7 @@ void WorldServer::Process() { if (!(Zone::Bootup(zst->zoneid, zst->instanceid, zst->makestatic))) { SendChannelMessage(0, 0, 10, 0, 0, "%s:%i Zone::Bootup failed: %s", net.GetZoneAddress(), net.GetZonePort(), database.GetZoneName(zst->zoneid)); } - // Moved annoucement to ZoneBootup() - Quagmire + // Moved annoucement to ZoneBootup() // else // SendEmoteMessage(0, 0, 15, "Zone bootup: %s", zone->GetLongName()); break; @@ -1822,7 +1821,6 @@ void WorldServer::Process() { default: { cout << " Unknown ZSopcode:" << (int)pack->opcode; cout << " size:" << pack->size << endl; - //DumpPacket(pack->pBuffer, pack->size); break; } } From 9fbf9abd47c66d84274aa19b78f1fc8ec394002f Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Sun, 17 Mar 2013 06:20:12 -0400 Subject: [PATCH 3/9] Forgot changelog :x --- changelog.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.txt b/changelog.txt index 5a91b9e74..2fa5d5594 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,9 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- +== 03/17/2013 == +Secrets: Fixed that pesky merc memleak. +Secrets: Bit of code cleanup regarding mercs. + == 03/15/2013 == Derision: RoF: Added ENCODE for Resurrect_struct (Accepting a rez should now work). Derision: Fixed a couple of memory leaks in Rez code. From cabf8631d449e5c523932f306f54df3be101e7cc Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Wed, 20 Mar 2013 04:00:08 -0400 Subject: [PATCH 4/9] Fixed mercenary memleaks in AI_Start and Unsuspend. --- CMakeLists.txt | 73 ++++++++++++++++++++++++++++++++++- eqlaunch/CMakeLists.txt | 2 +- eqlaunch/worldserver.cpp | 1 - queryserv/CMakeLists.txt | 2 +- shared_memory/CMakeLists.txt | 2 +- ucs/CMakeLists.txt | 2 +- world/CMakeLists.txt | 2 +- zone/CMakeLists.txt | 74 +++++++++++++++++++++++++++++++++++- zone/client_packet.cpp | 24 ++++++++++-- zone/client_process.cpp | 2 +- zone/doors.cpp | 1 - zone/merc.cpp | 50 ++++++++++++++---------- zone/net.cpp | 1 + zone/npc.cpp | 1 + zone/tasks.cpp | 1 - zone/tradeskills.cpp | 2 - 16 files changed, 203 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7897be92..a1b60619f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,77 @@ IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) ENDIF(NOT CMAKE_BUILD_TYPE) +SET(VLD_FOUND FALSE) + +## VLD works only in Microsoft Visual Studio on Windows: +IF(WIN32) +IF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)") + +FIND_PATH(VLD_INCLUDE_DIR vld.h + $ENV{VLD_HOME}/include + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/include" + ) +#MESSAGE("VLD_INCLUDE_DIR=${VLD_INCLUDE_DIR}") + +## this is just required for runtim enabling/disabling: +FIND_PATH(VLD_INCLUDE_DIR_API vldapi.h + $ENV{VLD_HOME}/include + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/include" +) +#MESSAGE("VLD_INCLUDE_DIR_API=${VLD_INCLUDE_DIR}") + +FIND_LIBRARY(VLD_LIBRARY_VLD + NAMES vld + PATHS + $ENV{VLD_HOME}/lib + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" + DOC "Visual Leak Debugger multithreaded library" + ) +#MESSAGE("VLD_LIBRARY_VLD=${VLD_LIBRARY_VLD}") + +FIND_LIBRARY(VLD_LIBRARY_VLDMT + NAMES vldmt + PATHS + $ENV{VLD_HOME}/lib + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" + DOC "Visual Leak Debugger multithreaded library" + ) +#MESSAGE("VLD_LIBRARY_VLDMT=${VLD_LIBRARY_VLDMT}") + +FIND_LIBRARY(VLD_LIBRARY_VLDMTDLL + NAMES vldmtdll + PATHS + $ENV{VLD_HOME}/lib + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" + DOC "Visual Leak Debugger multithreaded library" + ) +#MESSAGE("VLD_LIBRARY_VLDMTDLL=${VLD_LIBRARY_VLDMTDLL}") + +IF(VLD_INCLUDE_DIR) + IF (VLD_LIBRARY_VLD OR VLD_LIBRARY_VLDMT OR VLD_LIBRARY_VLDMTDLL) + ## do NOT add LIBRARIES because dependencies are handled through pragmas. + SET(VLD_FOUND TRUE) + # MESSAGE("found VLD.") + ENDIF (VLD_LIBRARY_VLD OR VLD_LIBRARY_VLDMT OR VLD_LIBRARY_VLDMTDLL) +ENDIF(VLD_INCLUDE_DIR) + +MARK_AS_ADVANCED( + VLD_INCLUDE_DIR + VLD_INCLUDE_DIR_API + VLD_LIBRARY_VLD + VLD_LIBRARY_VLDMT + VLD_LIBRARY_VLDMTDLL + VLD_LIBRARIES +) + +ENDIF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)") +ENDIF(WIN32) + #Add our various windows definitions IF(MSVC OR MINGW) ADD_DEFINITIONS(-D_WINDOWS) @@ -139,7 +210,7 @@ ADD_DEFINITIONS(-DMAP_DIR="./Maps") FIND_PACKAGE(ZLIB REQUIRED) FIND_PACKAGE(MySQL REQUIRED) FIND_PACKAGE(PerlLibs REQUIRED) -INCLUDE_DIRECTORIES("${ZLIB_INCLUDE_DIRS}" "${PERL_INCLUDE_PATH}" "${MySQL_INCLUDE_DIR}") +INCLUDE_DIRECTORIES("${ZLIB_INCLUDE_DIRS}" "${PERL_INCLUDE_PATH}" "${MySQL_INCLUDE_DIR}" "${VLD_INCLUDE_DIR}") IF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS) ADD_SUBDIRECTORY(common) diff --git a/eqlaunch/CMakeLists.txt b/eqlaunch/CMakeLists.txt index 8483b9bb0..14257fef9 100644 --- a/eqlaunch/CMakeLists.txt +++ b/eqlaunch/CMakeLists.txt @@ -13,7 +13,7 @@ SET(eqlaunch_headers ADD_EXECUTABLE(eqlaunch ${eqlaunch_sources} ${eqlaunch_headers}) -TARGET_LINK_LIBRARIES(eqlaunch Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE}) +TARGET_LINK_LIBRARIES(eqlaunch Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) IF(MSVC) diff --git a/eqlaunch/worldserver.cpp b/eqlaunch/worldserver.cpp index a3071f3df..1f314bd8f 100644 --- a/eqlaunch/worldserver.cpp +++ b/eqlaunch/worldserver.cpp @@ -126,7 +126,6 @@ void WorldServer::Process() { default: { _log(LAUNCHER__NET, "Unknown opcode 0x%x from World of len %d", pack->opcode, pack->size); - //DumpPacket(pack->pBuffer, pack->size); break; } } diff --git a/queryserv/CMakeLists.txt b/queryserv/CMakeLists.txt index 96cdaf69c..4e319ddad 100644 --- a/queryserv/CMakeLists.txt +++ b/queryserv/CMakeLists.txt @@ -19,7 +19,7 @@ ADD_EXECUTABLE(queryserv ${qserv_sources} ${qserv_headers}) ADD_DEFINITIONS(-DQSERV) -TARGET_LINK_LIBRARIES(queryserv Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE}) +TARGET_LINK_LIBRARIES(queryserv Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) IF(MSVC) diff --git a/shared_memory/CMakeLists.txt b/shared_memory/CMakeLists.txt index 74629fdd1..902ffb2ff 100644 --- a/shared_memory/CMakeLists.txt +++ b/shared_memory/CMakeLists.txt @@ -19,7 +19,7 @@ SET(shared_memory_headers ADD_EXECUTABLE(shared_memory ${shared_memory_sources} ${shared_memory_headers}) -TARGET_LINK_LIBRARIES(shared_memory Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE}) +TARGET_LINK_LIBRARIES(shared_memory Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) IF(MSVC) SET_TARGET_PROPERTIES(shared_memory PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") diff --git a/ucs/CMakeLists.txt b/ucs/CMakeLists.txt index 6f0d023a0..1218541a3 100644 --- a/ucs/CMakeLists.txt +++ b/ucs/CMakeLists.txt @@ -21,7 +21,7 @@ ADD_EXECUTABLE(ucs ${ucs_sources} ${ucs_headers}) ADD_DEFINITIONS(-DUCS) -TARGET_LINK_LIBRARIES(ucs Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE}) +TARGET_LINK_LIBRARIES(ucs Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) IF(MSVC) diff --git a/world/CMakeLists.txt b/world/CMakeLists.txt index f36ba87fa..768072677 100644 --- a/world/CMakeLists.txt +++ b/world/CMakeLists.txt @@ -67,7 +67,7 @@ ADD_EXECUTABLE(world ${world_sources} ${world_headers}) ADD_DEFINITIONS(-DWORLD) -TARGET_LINK_LIBRARIES(world Common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE}) +TARGET_LINK_LIBRARIES(world Common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) IF(MSVC) diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index e0b0d01b6..9554802bf 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -155,12 +155,82 @@ ADD_EXECUTABLE(zone ${zone_sources} ${zone_headers}) ADD_DEFINITIONS(-DZONE) -TARGET_LINK_LIBRARIES(zone Common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE}) +TARGET_LINK_LIBRARIES(zone Common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} ${VLD_LIBRARY_VLD}) IF(MSVC) SET_TARGET_PROPERTIES(zone PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") TARGET_LINK_LIBRARIES(zone "Ws2_32.lib") ENDIF(MSVC) +SET(VLD_FOUND FALSE) + +## VLD works only in Microsoft Visual Studio on Windows: +IF(WIN32) +IF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)") + +FIND_PATH(VLD_INCLUDE_DIR vld.h + $ENV{VLD_HOME}/include + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/include" + ) +#MESSAGE("VLD_INCLUDE_DIR=${VLD_INCLUDE_DIR}") + +## this is just required for runtim enabling/disabling: +FIND_PATH(VLD_INCLUDE_DIR_API vldapi.h + $ENV{VLD_HOME}/include + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/include" +) +#MESSAGE("VLD_INCLUDE_DIR_API=${VLD_INCLUDE_DIR}") + +FIND_LIBRARY(VLD_LIBRARY_VLD + NAMES vld + PATHS + $ENV{VLD_HOME}/lib + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" + DOC "Visual Leak Debugger multithreaded library" + ) +#MESSAGE("VLD_LIBRARY_VLD=${VLD_LIBRARY_VLD}") + +FIND_LIBRARY(VLD_LIBRARY_VLDMT + NAMES vldmt + PATHS + $ENV{VLD_HOME}/lib + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" + DOC "Visual Leak Debugger multithreaded library" + ) +#MESSAGE("VLD_LIBRARY_VLDMT=${VLD_LIBRARY_VLDMT}") + +FIND_LIBRARY(VLD_LIBRARY_VLDMTDLL + NAMES vldmtdll + PATHS + $ENV{VLD_HOME}/lib + $ENV{VLD_HOME} + "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" + DOC "Visual Leak Debugger multithreaded library" + ) +#MESSAGE("VLD_LIBRARY_VLDMTDLL=${VLD_LIBRARY_VLDMTDLL}") + +IF(VLD_INCLUDE_DIR) + IF (VLD_LIBRARY_VLD OR VLD_LIBRARY_VLDMT OR VLD_LIBRARY_VLDMTDLL) + ## do NOT add LIBRARIES because dependencies are handled through pragmas. + SET(VLD_FOUND TRUE) + # MESSAGE("found VLD.") + ENDIF (VLD_LIBRARY_VLD OR VLD_LIBRARY_VLDMT OR VLD_LIBRARY_VLDMTDLL) +ENDIF(VLD_INCLUDE_DIR) + +MARK_AS_ADVANCED( + VLD_INCLUDE_DIR + VLD_INCLUDE_DIR_API + VLD_LIBRARY_VLD + VLD_LIBRARY_VLDMT + VLD_LIBRARY_VLDMTDLL + VLD_LIBRARIES +) + +ENDIF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)") +ENDIF(WIN32) IF(MINGW) TARGET_LINK_LIBRARIES(zone "WS2_32") @@ -175,4 +245,6 @@ IF(UNIX) ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) +INCLUDE_DIRECTORIES(${VLD_INCLUDE_DIR}) + SET(EXECUTABLE_OUTPUT_PATH ../Bin) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 778d2fdd4..5e0a9d578 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -3540,7 +3540,6 @@ void Client::Handle_OP_WearChange(const EQApplicationPacket *app) { if (app->size != sizeof(WearChange_Struct)) { cout << "Wrong size: OP_WearChange, size=" << app->size << ", expected " << sizeof(WearChange_Struct) << endl; - DumpPacket(app); return; } @@ -3595,7 +3594,6 @@ void Client::Handle_OP_WhoAllRequest(const EQApplicationPacket *app) { if (app->size != sizeof(Who_All_Struct)) { cout << "Wrong size on OP_WhoAll. Got: " << app->size << ", Expected: " << sizeof(Who_All_Struct) << endl; - DumpPacket(app); return; } Who_All_Struct* whoall = (Who_All_Struct*) app->pBuffer; @@ -7385,6 +7383,24 @@ void Client::Handle_OP_Emote(const EQApplicationPacket *app) memcpy(out->message, name, len_name); memcpy(&out->message[len_name], in->message, len_msg); + /* + if (target && target->IsClient()) { + entity_list.QueueCloseClients(this, outapp, false, 100, target); + + cptr = outapp->pBuffer + 2; + + // not sure if live does this or not. thought it was a nice feature, but would take a lot to + // clean up grammatical and other errors. Maybe with a regex parser... + replacestr((char *)cptr, target->GetName(), "you"); + replacestr((char *)cptr, " he", " you"); + replacestr((char *)cptr, " she", " you"); + replacestr((char *)cptr, " him", " you"); + replacestr((char *)cptr, " her", " you"); + target->CastToClient()->QueuePacket(outapp); + + } + else + */ entity_list.QueueCloseClients(this, outapp, true, 100,0,true,FilterSocials); safe_delete(outapp); @@ -13580,6 +13596,7 @@ void Client::Handle_OP_MercenaryHire(const EQApplicationPacket *app) uint32 merchant_id = mmrq->MercMerchantID; uint32 merc_unk1 = mmrq->MercUnk01; uint32 merc_unk2 = mmrq->MercUnk02; + if(MERC_DEBUG > 0) Message(7, "Mercenary Debug: Template ID (%i), Merchant ID (%i), Unknown1 (%i), Unknown2 (%i)", merc_template_id, merchant_id, merc_unk1, merc_unk2); @@ -13641,7 +13658,6 @@ void Client::Handle_OP_MercenarySuspendRequest(const EQApplicationPacket *app) SuspendMercenary_Struct* sm = (SuspendMercenary_Struct*) app->pBuffer; uint32 merc_suspend = sm->SuspendMerc; // Seen 30 for suspending or unsuspending - if(MERC_DEBUG > 0) Message(7, "Mercenary Debug: Suspend ( %i ) received.", merc_suspend); @@ -13666,7 +13682,7 @@ void Client::Handle_OP_MercenaryCommand(const EQApplicationPacket *app) uint32 merc_command = mc->MercCommand; // Seen 0 (zone in with no merc or suspended), 1 (dismiss merc), 5 (normal state), 20 (unknown), 36 (zone in with merc) int32 option = mc->Option; // Seen -1 (zone in with no merc), 0 (setting to passive stance), 1 (normal or setting to balanced stance) - if(MERC_DEBUG > 0) + if(MERC_DEBUG > 0) Message(7, "Mercenary Debug: Command %i, Option %i received.", merc_command, option); if(!RuleB(Mercs, AllowMercs)) diff --git a/zone/client_process.cpp b/zone/client_process.cpp index 87afcf62a..aa81f9371 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -1307,7 +1307,7 @@ void Client::OPMoveCoin(const EQApplicationPacket* app) uint64 value = 0, amount_to_take = 0, amount_to_add = 0; int32 *from_bucket = 0, *to_bucket = 0; Mob* trader = trade->With(); - + // could just do a range, but this is clearer and explicit if ( diff --git a/zone/doors.cpp b/zone/doors.cpp index 53315f413..c638ef746 100644 --- a/zone/doors.cpp +++ b/zone/doors.cpp @@ -148,7 +148,6 @@ void Doors::HandleClick(Client* sender, uint8 trigger) EQApplicationPacket* outapp = new EQApplicationPacket(OP_MoveDoor, sizeof(MoveDoor_Struct)); MoveDoor_Struct* md = (MoveDoor_Struct*)outapp->pBuffer; - md->doorid = door_id; ///////////////////////////////////////////////////////////////// //used_pawn: Locked doors! Rogue friendly too =) diff --git a/zone/merc.cpp b/zone/merc.cpp index 8326b8b97..eda622255 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -71,6 +71,7 @@ Merc::Merc(const NPCType* d, float x, float y, float z, float heading) } Merc::~Merc() { + AI_Stop(); safe_delete(ourNPCData); //Since mercs are dynamically alloc'd we should probably safe_delete the data they were made from. I'm not entirely sure this is safe to delete a const. entity_list.RemoveMerc(this->GetID()); UninitializeBuffSlots(); @@ -1911,15 +1912,16 @@ void Merc::AI_Process() { } void Merc::AI_Start(int32 iMoveDelay) { - Mob::AI_Start(iMoveDelay); + NPC::AI_Start(iMoveDelay); + if (!pAIControlled) return; if (merc_spells.size() == 0) { - AIautocastspell_timer = new Timer(1000); + AIautocastspell_timer->SetTimer(1000); AIautocastspell_timer->Disable(); } else { - AIautocastspell_timer = new Timer(750); + AIautocastspell_timer->SetTimer(750); AIautocastspell_timer->Start(RandomTimer(0, 2000), false); } @@ -5572,10 +5574,6 @@ bool Merc::Suspend() { SetSuspended(true); - if(HasGroup()) { - RemoveMercFromGroup(this, GetGroup()); - } - Save(); mercOwner->GetMercInfo().IsSuspended = true; @@ -5623,31 +5621,43 @@ bool Merc::Unsuspend(bool setMaxStats) { mercOwner->GetPTimers().Clear(&database, pTimerMercSuspend); mercOwner->SendMercPersonalInfo(); + Group* g = entity_list.GetGroupByClient(mercOwner); - if(!mercOwner->IsGrouped()) - { - Group *g = new Group(mercOwner); - if(g && AddMercToGroup(this, g)) + if(!g) + { //nobody from our group is here... start a new group + g = new Group(mercOwner); + + if(!g) { - entity_list.AddGroup(g); + delete g; + g = NULL; + return false; + } + entity_list.AddGroup(g); + + if(g->GetID() == 0) { + delete g; + g = NULL; + Message(13, "Unable to get new group id. Cannot create group."); + mercOwner->Message(13, "Unable to get new group id. Cannot create group."); + return false; + } + + if(AddMercToGroup(this, g)) + { + entity_list.AddGroup(g, g->GetID()); database.SetGroupLeaderName(g->GetID(), mercOwner->GetName()); database.SetGroupID(mercOwner->GetName(), g->GetID(), mercOwner->CharacterID()); database.SetGroupID(this->GetName(), g->GetID(), mercOwner->CharacterID(), true); database.RefreshGroupFromDB(mercOwner); g->SaveGroupLeaderAA(); - loaded = true; } else { - if(MERC_DEBUG > 0) - mercOwner->Message(7, "Mercenary failed to join the group - Suspending"); - - Suspend(); - safe_delete(g); - return false; + g->DisbandGroup(); } - } + } //else, somebody from our group is already here... else if (AddMercToGroup(this, mercOwner->GetGroup())) { database.SetGroupID(GetName(), mercOwner->GetGroup()->GetID(), mercOwner->CharacterID(), true); diff --git a/zone/net.cpp b/zone/net.cpp index 33a0997c4..2b152f01c 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -20,6 +20,7 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) #include "../common/features.h" #include using namespace std; +#include #include #include #include diff --git a/zone/npc.cpp b/zone/npc.cpp index 86efc0579..121eae692 100644 --- a/zone/npc.cpp +++ b/zone/npc.cpp @@ -248,6 +248,7 @@ NPC::NPC(const NPCType* d, Spawn2* in_respawn, float x, float y, float z, float npc_aggro = d->npc_aggro; + if(!IsMerc()) //memleak fix, this really shouldn't be here AI_Start(); d_meele_texture1 = d->d_meele_texture1; diff --git a/zone/tasks.cpp b/zone/tasks.cpp index 56b9de4d4..efc45175f 100644 --- a/zone/tasks.cpp +++ b/zone/tasks.cpp @@ -2559,7 +2559,6 @@ void Client::SendTaskFailed(int TaskID, int TaskIndex) { tac->unknown5 = 0; // 0 for task complete or failed. _log(TASKS__UPDATE, "TaskFailed"); - _pkt(TASKS__PACKETS, outapp); QueuePacket(outapp); diff --git a/zone/tradeskills.cpp b/zone/tradeskills.cpp index 30851b038..0f050368d 100644 --- a/zone/tradeskills.cpp +++ b/zone/tradeskills.cpp @@ -517,7 +517,6 @@ void Object::HandleAutoCombine(Client* user, const RecipeAutoCombine_Struct* rac outp->reply_code = 0x00000000; //success for finding it... user->QueuePacket(outapp); - safe_delete(outapp); @@ -664,7 +663,6 @@ void Client::TradeskillSearchResults(const char *query, unsigned long qlen, reply->recipe_id = recipe; reply->trivial = trivial; strn0cpy(reply->recipe_name, name, sizeof(reply->recipe_name)); - FastQueuePacket(&outapp); } mysql_free_result(result); From f90a5b5b71b20d71320cd3bd275822bb5b9ef67c Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Wed, 20 Mar 2013 04:02:33 -0400 Subject: [PATCH 5/9] Merc message removed. --- zone/merc.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/zone/merc.cpp b/zone/merc.cpp index 17fbcba66..f6eb6bb96 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -5660,8 +5660,6 @@ bool Merc::Unsuspend(bool setMaxStats) { if(g->GetID() == 0) { delete g; g = NULL; - Message(13, "Unable to get new group id. Cannot create group."); - mercOwner->Message(13, "Unable to get new group id. Cannot create group."); return false; } From 549455b3df08212a9fee96717ebcdf33c7e204f2 Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Wed, 20 Mar 2013 04:02:33 -0400 Subject: [PATCH 6/9] Merc message removed. VLD removed, oops. --- zone/CMakeLists.txt | 72 +-------------------------------------------- zone/merc.cpp | 2 -- zone/net.cpp | 1 - 3 files changed, 1 insertion(+), 74 deletions(-) diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 9554802bf..7079942ab 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -155,82 +155,12 @@ ADD_EXECUTABLE(zone ${zone_sources} ${zone_headers}) ADD_DEFINITIONS(-DZONE) -TARGET_LINK_LIBRARIES(zone Common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} ${VLD_LIBRARY_VLD}) +TARGET_LINK_LIBRARIES(zone Common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) IF(MSVC) SET_TARGET_PROPERTIES(zone PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") TARGET_LINK_LIBRARIES(zone "Ws2_32.lib") ENDIF(MSVC) -SET(VLD_FOUND FALSE) - -## VLD works only in Microsoft Visual Studio on Windows: -IF(WIN32) -IF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)") - -FIND_PATH(VLD_INCLUDE_DIR vld.h - $ENV{VLD_HOME}/include - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/include" - ) -#MESSAGE("VLD_INCLUDE_DIR=${VLD_INCLUDE_DIR}") - -## this is just required for runtim enabling/disabling: -FIND_PATH(VLD_INCLUDE_DIR_API vldapi.h - $ENV{VLD_HOME}/include - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/include" -) -#MESSAGE("VLD_INCLUDE_DIR_API=${VLD_INCLUDE_DIR}") - -FIND_LIBRARY(VLD_LIBRARY_VLD - NAMES vld - PATHS - $ENV{VLD_HOME}/lib - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" - DOC "Visual Leak Debugger multithreaded library" - ) -#MESSAGE("VLD_LIBRARY_VLD=${VLD_LIBRARY_VLD}") - -FIND_LIBRARY(VLD_LIBRARY_VLDMT - NAMES vldmt - PATHS - $ENV{VLD_HOME}/lib - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" - DOC "Visual Leak Debugger multithreaded library" - ) -#MESSAGE("VLD_LIBRARY_VLDMT=${VLD_LIBRARY_VLDMT}") - -FIND_LIBRARY(VLD_LIBRARY_VLDMTDLL - NAMES vldmtdll - PATHS - $ENV{VLD_HOME}/lib - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" - DOC "Visual Leak Debugger multithreaded library" - ) -#MESSAGE("VLD_LIBRARY_VLDMTDLL=${VLD_LIBRARY_VLDMTDLL}") - -IF(VLD_INCLUDE_DIR) - IF (VLD_LIBRARY_VLD OR VLD_LIBRARY_VLDMT OR VLD_LIBRARY_VLDMTDLL) - ## do NOT add LIBRARIES because dependencies are handled through pragmas. - SET(VLD_FOUND TRUE) - # MESSAGE("found VLD.") - ENDIF (VLD_LIBRARY_VLD OR VLD_LIBRARY_VLDMT OR VLD_LIBRARY_VLDMTDLL) -ENDIF(VLD_INCLUDE_DIR) - -MARK_AS_ADVANCED( - VLD_INCLUDE_DIR - VLD_INCLUDE_DIR_API - VLD_LIBRARY_VLD - VLD_LIBRARY_VLDMT - VLD_LIBRARY_VLDMTDLL - VLD_LIBRARIES -) - -ENDIF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)") -ENDIF(WIN32) IF(MINGW) TARGET_LINK_LIBRARIES(zone "WS2_32") diff --git a/zone/merc.cpp b/zone/merc.cpp index 17fbcba66..f6eb6bb96 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -5660,8 +5660,6 @@ bool Merc::Unsuspend(bool setMaxStats) { if(g->GetID() == 0) { delete g; g = NULL; - Message(13, "Unable to get new group id. Cannot create group."); - mercOwner->Message(13, "Unable to get new group id. Cannot create group."); return false; } diff --git a/zone/net.cpp b/zone/net.cpp index 2b152f01c..33a0997c4 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -20,7 +20,6 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) #include "../common/features.h" #include using namespace std; -#include #include #include #include From 925ba2199edee6716103b36a9dc12a15636c59a9 Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Wed, 20 Mar 2013 07:19:20 -0400 Subject: [PATCH 7/9] Whoops, forgot CMakeLists.txt --- CMakeLists.txt | 73 +------------------------------------------------- 1 file changed, 1 insertion(+), 72 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1b60619f..a7897be92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,77 +18,6 @@ IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) ENDIF(NOT CMAKE_BUILD_TYPE) -SET(VLD_FOUND FALSE) - -## VLD works only in Microsoft Visual Studio on Windows: -IF(WIN32) -IF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)") - -FIND_PATH(VLD_INCLUDE_DIR vld.h - $ENV{VLD_HOME}/include - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/include" - ) -#MESSAGE("VLD_INCLUDE_DIR=${VLD_INCLUDE_DIR}") - -## this is just required for runtim enabling/disabling: -FIND_PATH(VLD_INCLUDE_DIR_API vldapi.h - $ENV{VLD_HOME}/include - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/include" -) -#MESSAGE("VLD_INCLUDE_DIR_API=${VLD_INCLUDE_DIR}") - -FIND_LIBRARY(VLD_LIBRARY_VLD - NAMES vld - PATHS - $ENV{VLD_HOME}/lib - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" - DOC "Visual Leak Debugger multithreaded library" - ) -#MESSAGE("VLD_LIBRARY_VLD=${VLD_LIBRARY_VLD}") - -FIND_LIBRARY(VLD_LIBRARY_VLDMT - NAMES vldmt - PATHS - $ENV{VLD_HOME}/lib - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" - DOC "Visual Leak Debugger multithreaded library" - ) -#MESSAGE("VLD_LIBRARY_VLDMT=${VLD_LIBRARY_VLDMT}") - -FIND_LIBRARY(VLD_LIBRARY_VLDMTDLL - NAMES vldmtdll - PATHS - $ENV{VLD_HOME}/lib - $ENV{VLD_HOME} - "$ENV{ProgramFiles}/Microsoft Visual Studio .NET 2003/Vc7/lib" - DOC "Visual Leak Debugger multithreaded library" - ) -#MESSAGE("VLD_LIBRARY_VLDMTDLL=${VLD_LIBRARY_VLDMTDLL}") - -IF(VLD_INCLUDE_DIR) - IF (VLD_LIBRARY_VLD OR VLD_LIBRARY_VLDMT OR VLD_LIBRARY_VLDMTDLL) - ## do NOT add LIBRARIES because dependencies are handled through pragmas. - SET(VLD_FOUND TRUE) - # MESSAGE("found VLD.") - ENDIF (VLD_LIBRARY_VLD OR VLD_LIBRARY_VLDMT OR VLD_LIBRARY_VLDMTDLL) -ENDIF(VLD_INCLUDE_DIR) - -MARK_AS_ADVANCED( - VLD_INCLUDE_DIR - VLD_INCLUDE_DIR_API - VLD_LIBRARY_VLD - VLD_LIBRARY_VLDMT - VLD_LIBRARY_VLDMTDLL - VLD_LIBRARIES -) - -ENDIF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)") -ENDIF(WIN32) - #Add our various windows definitions IF(MSVC OR MINGW) ADD_DEFINITIONS(-D_WINDOWS) @@ -210,7 +139,7 @@ ADD_DEFINITIONS(-DMAP_DIR="./Maps") FIND_PACKAGE(ZLIB REQUIRED) FIND_PACKAGE(MySQL REQUIRED) FIND_PACKAGE(PerlLibs REQUIRED) -INCLUDE_DIRECTORIES("${ZLIB_INCLUDE_DIRS}" "${PERL_INCLUDE_PATH}" "${MySQL_INCLUDE_DIR}" "${VLD_INCLUDE_DIR}") +INCLUDE_DIRECTORIES("${ZLIB_INCLUDE_DIRS}" "${PERL_INCLUDE_PATH}" "${MySQL_INCLUDE_DIR}") IF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS) ADD_SUBDIRECTORY(common) From 56825e9ed0bbb460da0ea8ceca4f223ee70db104 Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Wed, 20 Mar 2013 10:46:09 -0400 Subject: [PATCH 8/9] Two crash fixes reported on the forums are hopefully fixed. --- common/patches/RoF.cpp | 3 ++- zone/MobAI.cpp | 7 +++++-- zone/attack.cpp | 8 ++++---- zone/client.cpp | 2 +- zone/command.cpp | 4 ++-- zone/entity.cpp | 2 +- zone/mob.cpp | 4 +++- zone/mob.h | 4 ++++ zone/npc.cpp | 3 ++- zone/npc.h | 1 - 10 files changed, 24 insertions(+), 14 deletions(-) diff --git a/common/patches/RoF.cpp b/common/patches/RoF.cpp index b44cb8f37..d3f96e6e7 100644 --- a/common/patches/RoF.cpp +++ b/common/patches/RoF.cpp @@ -3015,7 +3015,8 @@ ENCODE(OP_ReadBook) { eq->window = emu->window; OUT(type); eq->invslot = 0; // Set to hard 0 since it's not required for the structure to work - memcpy(eq->txtfile, emu->booktext, sizeof(eq->txtfile)); + if(sizeof(emu->booktext) > 0 && sizeof(emu->booktext) < 8194) + strncpy(eq->txtfile, emu->booktext, sizeof(eq->txtfile)); FINISH_ENCODE(); } diff --git a/zone/MobAI.cpp b/zone/MobAI.cpp index 4bc063998..a2030aa7d 100644 --- a/zone/MobAI.cpp +++ b/zone/MobAI.cpp @@ -1721,7 +1721,7 @@ void Mob::AI_Event_Engaged(Mob* attacker, bool iYellForHelp) { if(!CastToNPC()->GetCombatEvent() && GetHP() > 0) { parse->EventNPC(EVENT_COMBAT, CastToNPC(), attacker, "1", 0); - uint16 emoteid = CastToNPC()->GetNPCEmoteID(); + uint16 emoteid = GetEmoteID(); if(emoteid != 0) CastToNPC()->DoNPCEmote(ENTERCOMBAT,emoteid); CastToNPC()->SetCombatEvent(true); @@ -1754,11 +1754,14 @@ void Mob::AI_Event_NoLongerEngaged() { { if(CastToNPC()->GetCombatEvent() && GetHP() > 0) { - uint16 emoteid = CastToNPC()->GetNPCEmoteID(); + if(entity_list.GetNPCByID(this->GetID())) + { + uint16 emoteid = CastToNPC()->GetEmoteID(); parse->EventNPC(EVENT_COMBAT, CastToNPC(), NULL, "0", 0); if(emoteid != 0) CastToNPC()->DoNPCEmote(LEAVECOMBAT,emoteid); CastToNPC()->SetCombatEvent(false); + } } } } diff --git a/zone/attack.cpp b/zone/attack.cpp index 1d787b0e9..141aa50ec 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -1451,7 +1451,7 @@ void Client::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_ { if (killerMob->IsNPC()) { parse->EventNPC(EVENT_SLAY, killerMob->CastToNPC(), this, "", 0); - uint16 emoteid = killerMob->CastToNPC()->GetNPCEmoteID(); + uint16 emoteid = killerMob->GetEmoteID(); if(emoteid != 0) killerMob->CastToNPC()->DoNPCEmote(KILLEDPC,emoteid); killerMob->TrySpellOnKill(killed_level,spell); @@ -2209,7 +2209,7 @@ void NPC::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_ski this->CheckMinMaxLevel(killer); } entity_list.RemoveFromAutoXTargets(this); - uint16 emoteid = this->GetNPCEmoteID(); + uint16 emoteid = this->GetEmoteID(); Corpse* corpse = new Corpse(this, &itemlist, GetNPCTypeID(), &NPCTypedata,level>54?RuleI(NPC,MajorNPCCorpseDecayTimeMS):RuleI(NPC,MinorNPCCorpseDecayTimeMS)); entity_list.LimitRemoveNPC(this); entity_list.AddCorpse(corpse, this->GetID()); @@ -2302,13 +2302,13 @@ void NPC::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_ski if(killerMob) { Mob *oos = killerMob->GetOwnerOrSelf(); parse->EventNPC(EVENT_DEATH, this, oos, "", 0); - uint16 emoteid = this->GetNPCEmoteID(); + uint16 emoteid = this->GetEmoteID(); if(emoteid != 0) this->DoNPCEmote(ONDEATH,emoteid); if(oos->IsNPC()) { parse->EventNPC(EVENT_NPC_SLAY, oos->CastToNPC(), this, "", 0); - uint16 emoteid = oos->CastToNPC()->GetNPCEmoteID(); + uint16 emoteid = oos->GetEmoteID(); if(emoteid != 0) oos->CastToNPC()->DoNPCEmote(KILLEDNPC,emoteid); killerMob->TrySpellOnKill(killed_level,spell); diff --git a/zone/client.cpp b/zone/client.cpp index 425309810..c582fc8a0 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -5915,7 +5915,7 @@ void Client::CheckEmoteHail(Mob *target, const char* message) { return; } - uint16 emoteid = target->CastToNPC()->GetNPCEmoteID(); + uint16 emoteid = target->GetEmoteID(); if(emoteid != 0) target->CastToNPC()->DoNPCEmote(HAILED,emoteid); } diff --git a/zone/command.cpp b/zone/command.cpp index dce3257ee..8451d851f 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -1867,7 +1867,7 @@ void command_npcstats(Client *c, const Seperator *sep) c->Message(0, "Gender: %i Size: %f Bodytype: %d", c->GetTarget()->GetGender(), c->GetTarget()->GetSize(), c->GetTarget()->GetBodyType()); c->Message(0, "Runspeed: %f Walkspeed: %f", c->GetTarget()->GetRunspeed(), c->GetTarget()->GetWalkspeed()); c->Message(0, "Spawn Group: %i Grid: %i", c->GetTarget()->CastToNPC()->GetSp2(), c->GetTarget()->CastToNPC()->GetGrid()); - c->Message(0, "EmoteID: %i", c->GetTarget()->CastToNPC()->GetNPCEmoteID()); + c->Message(0, "EmoteID: %i", c->GetTarget()->CastToNPC()->GetEmoteID()); c->GetTarget()->CastToNPC()->QueryLoot(c); } } @@ -11031,7 +11031,7 @@ void command_emoteview(Client *c, const Seperator *sep) if(c->GetTarget() && c->GetTarget()->IsNPC()) { int count=0; - int emoteid = c->GetTarget()->CastToNPC()->GetNPCEmoteID(); + int emoteid = c->GetTarget()->CastToNPC()->GetEmoteID(); LinkedListIterator iterator(zone->NPCEmoteList); iterator.Reset(); diff --git a/zone/entity.cpp b/zone/entity.cpp index 393abb8ea..dc162312b 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -621,7 +621,7 @@ void EntityList::AddNPC(NPC* npc, bool SendSpawnPacket, bool dontqueue) { npc->SetID(GetFreeID()); parse->EventNPC(EVENT_SPAWN, npc, NULL, "", 0); - uint16 emoteid = npc->GetNPCEmoteID(); + uint16 emoteid = npc->GetEmoteID(); if(emoteid != 0) npc->DoNPCEmote(ONSPAWN,emoteid); diff --git a/zone/mob.cpp b/zone/mob.cpp index 6c8bbc398..2d1539086 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -378,6 +378,8 @@ Mob::Mob(const char* in_name, m_DisableMelee = false; for (int i = 0; i < HIGHEST_SKILL+2; i++) { SkillDmgTaken_Mod[i] = 0; } for (int i = 0; i < HIGHEST_RESIST+2; i++) { Vulnerability_Mod[i] = 0; } + + emoteid = 0; } Mob::~Mob() @@ -1194,7 +1196,7 @@ void Mob::ShowStats(Client* client) if(n->respawn2 != 0) spawngroupid = n->respawn2->SpawnGroupID(); client->Message(0, " NPCID: %u SpawnGroupID: %u Grid: %i LootTable: %u FactionID: %i SpellsID: %u ", GetNPCTypeID(),spawngroupid, n->GetGrid(), n->GetLoottableID(), n->GetNPCFactionID(), n->GetNPCSpellsID()); - client->Message(0, " Accuracy: %i MerchantID: %i EmoteID: %i Runspeed: %f Walkspeed: %f", n->GetAccuracyRating(), n->MerchantType, n->GetNPCEmoteID(), n->GetRunspeed(), n->GetWalkspeed()); + client->Message(0, " Accuracy: %i MerchantID: %i EmoteID: %i Runspeed: %f Walkspeed: %f", n->GetAccuracyRating(), n->MerchantType, n->GetEmoteID(), n->GetRunspeed(), n->GetWalkspeed()); n->QueryLoot(client); } if (IsAIControlled()) { diff --git a/zone/mob.h b/zone/mob.h index 1b3407620..5f29227d5 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -784,6 +784,9 @@ public: void TarGlobal(const char *varname, const char *value, const char *duration, int npcid, int charid, int zoneid); void DelGlobal(const char *varname); + inline void SetEmoteID(uint16 emote) { emoteid = emote; } + inline uint16 GetEmoteID() { return emoteid; } + protected: void CommonDamage(Mob* other, int32 &damage, const uint16 spell_id, const SkillType attack_skill, bool &avoidable, const int8 buffslot, const bool iBuffTic); static uint16 GetProcID(uint16 spell_id, uint8 effect_index); @@ -1110,6 +1113,7 @@ protected: bool m_targetable; int QGVarDuration(const char *fmt); void InsertQuestGlobal(int charid, int npcid, int zoneid, const char *name, const char *value, int expdate); + uint16 emoteid; private: void _StopSong(); //this is not what you think it is diff --git a/zone/npc.cpp b/zone/npc.cpp index 121eae692..4dd24aba1 100644 --- a/zone/npc.cpp +++ b/zone/npc.cpp @@ -350,6 +350,7 @@ NPC::NPC(const NPCType* d, Spawn2* in_respawn, float x, float y, float z, float guard_y_saved = 0; guard_z_saved = 0; guard_heading_saved = 0; + SetEmoteID(d->emoteid); InitializeBuffSlots(); CalcBonuses(); } @@ -734,7 +735,7 @@ void NPC::DumpLoot(uint32 npcdump_index, ZSDump_NPC_Loot* npclootdump, uint32* N } void NPC::Depop(bool StartSpawnTimer) { - uint16 emoteid = this->GetNPCEmoteID(); + uint16 emoteid = this->GetEmoteID(); if(emoteid != 0) this->DoNPCEmote(ONDESPAWN,emoteid); p_depop = true; diff --git a/zone/npc.h b/zone/npc.h index f2fa91116..e810cfe1f 100644 --- a/zone/npc.h +++ b/zone/npc.h @@ -327,7 +327,6 @@ public: //The corpse we make can only be looted by people who got credit for the kill const bool HasPrivateCorpse() const { return NPCTypedata->private_corpse; } const bool IsUnderwaterOnly() const { return NPCTypedata->underwater; } - const uint32 GetNPCEmoteID() const { return NPCTypedata->emoteid; } const char* GetRawNPCTypeName() const { return NPCTypedata->name; } bool GetDepop() { return p_depop; } From 2124b6398293ab8eeb2fccfb27821528ae561a75 Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Thu, 21 Mar 2013 00:40:59 -0400 Subject: [PATCH 9/9] -Fixed a memleak in inviting mercs to group. -Fixed a duplicate merc in window bug. --- zone/client_packet.cpp | 68 ++++++++++++++++++++++++++++-------------- zone/groups.cpp | 3 ++ 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 5e0a9d578..ba67e4ba7 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -6482,15 +6482,6 @@ void Client::Handle_OP_GroupFollow2(const EQApplicationPacket *app) database.SetGroupID(inviter->GetName(), group->GetID(), inviter->CastToClient()->CharacterID()); database.SetGroupLeaderName(group->GetID(), inviter->GetName()); - // Add the merc back into the new group - if (GetMerc()) - { - if (GetMerc()->AddMercToGroup(GetMerc(), group)) - { - database.SetGroupID(GetMerc()->GetName(), group->GetID(), inviter->CastToClient()->CharacterID(), true); - } - } - group->UpdateGroupAAs(); //Invite the inviter into the group first.....dont ask @@ -6525,11 +6516,6 @@ void Client::Handle_OP_GroupFollow2(const EQApplicationPacket *app) if(!group->AddMember(this)) return; - if(GetMerc()) - { - group->AddMember(GetMerc()); - } - if(inviter->CastToClient()->IsLFP()) { // If the player who invited us to a group is LFP, have them update world now that we have joined // their group. @@ -6546,6 +6532,16 @@ void Client::Handle_OP_GroupFollow2(const EQApplicationPacket *app) if(inviter->CastToClient()->GetClientVersion() >= EQClientSoD) database.RefreshGroupFromDB(inviter->CastToClient()); + // Add the merc back into the new group + if (GetMerc()) + { + if (GetMerc()->AddMercToGroup(GetMerc(), group)) + { + database.SetGroupID(GetMerc()->GetName(), group->GetID(), inviter->CastToClient()->CharacterID(), true); + } + } + + //send updates to clients out of zone... ServerPacket* pack = new ServerPacket(ServerOP_GroupJoin, sizeof(ServerGroupJoin_Struct)); ServerGroupJoin_Struct* gj = (ServerGroupJoin_Struct*)pack->pBuffer; @@ -6661,9 +6657,9 @@ void Client::Handle_OP_GroupDisband(const EQApplicationPacket *app) { if(group->IsLeader(this)) // the group leader can kick other members out of the group... { - group->DelMember(memberToDisband,false); if(memberToDisband->IsClient()) { + group->DelMember(memberToDisband,false); Client* memberClient = memberToDisband->CastToClient(); Merc* memberMerc = memberToDisband->CastToClient()->GetMerc(); if(memberMerc != NULL) @@ -6672,8 +6668,22 @@ void Client::Handle_OP_GroupDisband(const EQApplicationPacket *app) if(!memberMerc->IsGrouped() && !memberClient->IsGrouped()) { Group *g = new Group(memberClient); + + if(!g) + { + delete g; + g = NULL; + return; + } + + entity_list.AddGroup(g); + + if(g->GetID() == 0) + { + safe_delete(g); + return; + } if(memberMerc->AddMercToGroup(memberMerc, g)) { - entity_list.AddGroup(g); database.SetGroupLeaderName(g->GetID(), memberClient->GetName()); g->SaveGroupLeaderAA(); database.SetGroupID(memberClient->GetName(), g->GetID(), memberClient->CharacterID()); @@ -6685,19 +6695,36 @@ void Client::Handle_OP_GroupDisband(const EQApplicationPacket *app) } else if(memberToDisband->IsMerc()) { + memberToDisband->CastToMerc()->RemoveMercFromGroup(memberToDisband->CastToMerc(), group); memberToDisband->CastToMerc()->Suspend(); } } else - { // ...but other members can only remove themselves + { + // ...but other members can only remove themselves group->DelMember(this,false); if(!IsGrouped() && GetMerc() != NULL) { if(!IsGrouped()) { - Group *g = new Group(this); + Group *g = new Group(this); + + if(!g) + { + delete g; + g = NULL; + return; + } + + entity_list.AddGroup(g); + + if(g->GetID() == 0) + { + safe_delete(g); + return; + } + if(GetMerc()->AddMercToGroup(GetMerc(), g)) { - entity_list.AddGroup(g); database.SetGroupLeaderName(g->GetID(), this->GetName()); g->SaveGroupLeaderAA(); database.SetGroupID(this->GetName(), g->GetID(), this->CharacterID()); @@ -13771,9 +13798,6 @@ void Client::Handle_OP_MercenaryDismiss(const EQApplicationPacket *app) if(merc) merc->Dismiss(); } - - SendMercMerchantResponsePacket(10); - } void Client::Handle_OP_MercenaryTimerRequest(const EQApplicationPacket *app) diff --git a/zone/groups.cpp b/zone/groups.cpp index 8457e5ad0..bcb100147 100644 --- a/zone/groups.cpp +++ b/zone/groups.cpp @@ -214,6 +214,9 @@ bool Group::AddMember(Mob* newmember, const char *NewMemberName, uint32 Characte if(!newmember && !NewMemberName) return false; + if(GroupCount() >= MAX_GROUP_MEMBERS) //Sanity check for merging groups together. + return false; + if(!newmember) InZone = false; else