From 91b8ee104eac7446f9b8cbea7ed9dce641740c8e Mon Sep 17 00:00:00 2001 From: raczman Date: Sun, 7 Mar 2010 15:20:19 +0100 Subject: Added new type-safe cast functions. This, when properly used, should get rid of most memory corruption issues, currently, casting types C-style with no checks leads to some abstract crashing. Functionality is same as with dynamic_cast<>, but with no RTTI check - so when casting into invalid type you will receive NULL, and most probably crash. At the same time, i took the liberty to convert most Player* casts to ToPlayer(). Still needs crapload of casts being moved to new facility. --HG-- branch : trunk --- src/game/Level1.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/game/Level1.cpp') diff --git a/src/game/Level1.cpp b/src/game/Level1.cpp index 9a9c60f245e..d84cb06352a 100644 --- a/src/game/Level1.cpp +++ b/src/game/Level1.cpp @@ -1113,9 +1113,9 @@ bool ChatHandler::HandleModifyHPCommand(const char* args) if (chr->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player*)chr, 0)) return false; - PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink((Player*)chr).c_str(), hp, hpm); - if (chr->GetTypeId() == TYPEID_PLAYER && needReportToTarget((Player*)chr)) - ChatHandler((Player*)chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm); + PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr->ToPlayer()).c_str(), hp, hpm); + if (chr->GetTypeId() == TYPEID_PLAYER && needReportToTarget(chr->ToPlayer())) + ChatHandler(chr->ToPlayer()).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm); chr->SetMaxHealth( hpm ); chr->SetHealth( hp ); @@ -1460,20 +1460,20 @@ bool ChatHandler::HandleModifyTalentCommand (const char* args) // check online security if (HasLowerSecurity((Player*)target, 0)) return false; - ((Player*)target)->SetFreeTalentPoints(tp); - ((Player*)target)->SendTalentsInfoData(false); + target->ToPlayer()->SetFreeTalentPoints(tp); + target->ToPlayer()->SendTalentsInfoData(false); return true; } else if(((Creature*)target)->isPet()) { Unit *owner = target->GetOwner(); - if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)target)->IsPermanentPetFor((Player*)owner)) + if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)target)->IsPermanentPetFor(owner->ToPlayer())) { // check online security if (HasLowerSecurity((Player*)owner, 0)) return false; ((Pet *)target)->SetFreeTalentPoints(tp); - ((Player*)owner)->SendTalentsInfoData(true); + owner->ToPlayer()->SendTalentsInfoData(true); return true; } } -- cgit v1.2.3