From 23820a369e32fac92d44bedf8de73151127612e3 Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Sun, 24 Mar 2013 18:08:03 -0400 Subject: [PATCH 1/2] Moved around some data in Mercs to help prevent another crash... dunno if it actually will fix it but it can't hurt >_< --- zone/merc.cpp | 6 ++---- zone/merc.h | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/zone/merc.cpp b/zone/merc.cpp index 7fe95e4b4..a91593cbd 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -50,7 +50,6 @@ Merc::Merc(const NPCType* d, float x, float y, float z, float heading) _lost_confidence = false; _hatedCount = 0; - ourNPCData = d; memset(equipment, 0, sizeof(equipment)); SetMercID(0); @@ -74,7 +73,6 @@ 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(); } @@ -1915,9 +1913,9 @@ void Merc::AI_Start(int32 iMoveDelay) { AIautocastspell_timer->Start(RandomTimer(0, 2000), false); } - if (ourNPCData) { + if (NPCTypedata_ours) { //AI_AddNPCSpells(ourNPCData->npc_spells_id); - NPCSpecialAttacks(ourNPCData->npc_attacks,0); + NPCSpecialAttacks(NPCTypedata_ours->npc_attacks,0); } SendTo(GetX(), GetY(), GetZ()); diff --git a/zone/merc.h b/zone/merc.h index b76bb566d..dadba3fc1 100644 --- a/zone/merc.h +++ b/zone/merc.h @@ -379,8 +379,6 @@ private: bool _lost_confidence; int _hatedCount; uint32 owner_char_id; - const NPCType* ourNPCData; - Timer endupkeep_timer; Timer rest_timer; Timer confidence_timer; From c7ff207017a6c882e2578aa55aded886cb90b024 Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Mon, 25 Mar 2013 13:07:58 -0400 Subject: [PATCH 2/2] Made Merc::AddMercToGroup handle cleaning up old groups as opposed to doing it in each location before AddMercToGroup. This should fix cases where the Merc's owner is invalid and being referenced, which causes the crash located in: http://www.eqemulator.org/forums/showthread.php?t=36670&page=2 --- zone/client_packet.cpp | 21 ++++++++------------- zone/merc.cpp | 13 ++++++------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index bc74cc148..c29f9d9b9 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -6459,15 +6459,6 @@ void Client::Handle_OP_GroupFollow2(const EQApplicationPacket *app) } } - // Remove the merc from the old group - if (GetMerc()) - { - if(GetMerc()->GetGroup()) - { - Merc::RemoveMercFromGroup(GetMerc(), GetMerc()->GetGroup()); - } - } - Group* group = entity_list.GetGroupByClient(inviter->CastToClient()); if(!group){ @@ -6539,8 +6530,9 @@ void Client::Handle_OP_GroupFollow2(const EQApplicationPacket *app) // Add the merc back into the new group if (GetMerc()) { - if (GetMerc()->AddMercToGroup(GetMerc(), group)) { + if (Merc::AddMercToGroup(GetMerc(), group)) { database.SetGroupID(GetMerc()->GetName(), group->GetID(), inviter->CastToClient()->CharacterID(), true); + database.RefreshGroupFromDB(this); } } @@ -6667,8 +6659,6 @@ void Client::Handle_OP_GroupDisband(const EQApplicationPacket *app) Merc* memberMerc = memberToDisband->CastToClient()->GetMerc(); if(memberClient && memberMerc && group) { - Merc::RemoveMercFromGroup(memberMerc, group); - if(!memberMerc->IsGrouped() && !memberClient->IsGrouped()) { Group *g = new Group(memberClient); @@ -6713,13 +6703,18 @@ void Client::Handle_OP_GroupDisband(const EQApplicationPacket *app) return; } - if(GetMerc()->AddMercToGroup(GetMerc(), g)) { + if(Merc::AddMercToGroup(GetMerc(), g)) { database.SetGroupLeaderName(g->GetID(), this->GetName()); g->SaveGroupLeaderAA(); database.SetGroupID(this->GetName(), g->GetID(), this->CharacterID()); database.SetGroupID(GetMerc()->GetName(), g->GetID(), this->CharacterID(), true); database.RefreshGroupFromDB(this); } + else + { + if(GetMerc()) + GetMerc()->Depop(); + } } } } diff --git a/zone/merc.cpp b/zone/merc.cpp index a91593cbd..077b48cc7 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -5839,16 +5839,15 @@ bool Merc::AddMercToGroup(Merc* merc, Group* group) { if(merc->HasGroup()) { Merc::RemoveMercFromGroup(merc, merc->GetGroup()); } - // Add merc to this group - if(group->AddMember(merc)) { - merc->SetFollowID(merc->GetMercOwner()->GetID()); - Result = true; + //Try and add the member, followed by checking if the merc owner exists. + if(group->AddMember(merc) && merc->GetMercOwner() != NULL) { + merc->SetFollowID(merc->GetMercOwner()->GetID()); + Result = true; } - else - { + else { + //Suspend it if the member is not added and the merc's owner is not valid. merc->Suspend(); } - } return Result;