Index: /trunk/src/shared/Database/DatabaseMysql.h
===================================================================
--- /trunk/src/shared/Database/DatabaseMysql.h (revision 102)
+++ /trunk/src/shared/Database/DatabaseMysql.h (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: /trunk/src/shared/Database/SqlOperations.h
===================================================================
--- /trunk/src/shared/Database/SqlOperations.h (revision 102)
+++ /trunk/src/shared/Database/SqlOperations.h (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: /trunk/src/shared/Database/SQLStorageImpl.h
===================================================================
--- /trunk/src/shared/Database/SQLStorageImpl.h (revision 261)
+++ /trunk/src/shared/Database/SQLStorageImpl.h (revision 262)
Index: /trunk/src/shared/Database/DatabaseEnv.h
===================================================================
--- /trunk/src/shared/Database/DatabaseEnv.h (revision 149)
+++ /trunk/src/shared/Database/DatabaseEnv.h (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: /trunk/src/shared/Database/Field.h
===================================================================
--- /trunk/src/shared/Database/Field.h (revision 102)
+++ /trunk/src/shared/Database/Field.h (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: /trunk/src/shared/Database/DatabaseMysql.cpp
===================================================================
--- /trunk/src/shared/Database/DatabaseMysql.cpp (revision 102)
+++ /trunk/src/shared/Database/DatabaseMysql.cpp (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: /trunk/src/shared/Database/SqlOperations.cpp
===================================================================
--- /trunk/src/shared/Database/SqlOperations.cpp (revision 230)
+++ /trunk/src/shared/Database/SqlOperations.cpp (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: /trunk/src/shared/Database/DBCEnums.h
===================================================================
--- /trunk/src/shared/Database/DBCEnums.h (revision 261)
+++ /trunk/src/shared/Database/DBCEnums.h (revision 262)
Index: /trunk/src/shared/Database/QueryResult.h
===================================================================
--- /trunk/src/shared/Database/QueryResult.h (revision 102)
+++ /trunk/src/shared/Database/QueryResult.h (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: /trunk/src/shared/Database/Field.cpp
===================================================================
--- /trunk/src/shared/Database/Field.cpp (revision 102)
+++ /trunk/src/shared/Database/Field.cpp (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: /trunk/src/shared/Database/DatabaseImpl.h
===================================================================
--- /trunk/src/shared/Database/DatabaseImpl.h (revision 173)
+++ /trunk/src/shared/Database/DatabaseImpl.h (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: /trunk/src/game/WaypointMovementGenerator.cpp
===================================================================
--- /trunk/src/game/WaypointMovementGenerator.cpp (revision 261)
+++ /trunk/src/game/WaypointMovementGenerator.cpp (revision 262)
Index: /trunk/src/game/WaypointManager.cpp
===================================================================
--- /trunk/src/game/WaypointManager.cpp (revision 261)
+++ /trunk/src/game/WaypointManager.cpp (revision 262)
Index: /trunk/src/game/GMTicketMgr.h
===================================================================
--- /trunk/src/game/GMTicketMgr.h (revision 261)
+++ /trunk/src/game/GMTicketMgr.h (revision 262)
Index: /trunk/src/game/ArenaTeam.cpp
===================================================================
--- /trunk/src/game/ArenaTeam.cpp (revision 261)
+++ /trunk/src/game/ArenaTeam.cpp (revision 262)
Index: /trunk/src/game/CharacterHandler.cpp
===================================================================
--- /trunk/src/game/CharacterHandler.cpp (revision 230)
+++ /trunk/src/game/CharacterHandler.cpp (revision 262)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
@@ -65,5 +65,5 @@
     res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADGROUP,           "SELECT leaderGuid FROM group_member WHERE memberGuid ='%u'", GUID_LOPART(m_guid));
     res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADBOUNDINSTANCES,  "SELECT id, permanent, map, difficulty, resettime FROM character_instance LEFT JOIN instance ON instance = id WHERE guid = '%u'", GUID_LOPART(m_guid));
-    res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS,           "SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'", GUID_LOPART(m_guid));
+    res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS,           "SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'", GUID_LOPART(m_guid));
     res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS,          "SELECT spell,slot,active,disabled FROM character_spell WHERE guid = '%u'", GUID_LOPART(m_guid));
     res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS,     "SELECT quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4 FROM character_queststatus WHERE guid = '%u'", GUID_LOPART(m_guid));
@@ -181,4 +181,5 @@
     std::string name;
     uint8 race_,class_;
+
     recv_data >> name;
 
@@ -215,4 +216,5 @@
     ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(class_);
     ChrRacesEntry const* raceEntry = sChrRacesStore.LookupEntry(race_);
+
     if( !classEntry || !raceEntry )
     {
@@ -608,5 +610,5 @@
     }
 
-    if (!MapManager::Instance().GetMap(pCurrChar->GetMapId(), pCurrChar)->Add(pCurrChar))
+    if (!pCurrChar->GetMap()->Add(pCurrChar))
     {
         AreaTrigger const* at = objmgr.GetGoBackTrigger(pCurrChar->GetMapId());
@@ -1000,14 +1002,14 @@
     uint64 guid;
 
-    CHECK_PACKET_SIZE(recv_data, 8+6);
+    CHECK_PACKET_SIZE(recv_data, 8);
     recv_data >> guid;
 
     // not accept declined names for unsupported languages
     std::string name;
-    if(!objmgr.GetPlayerNameByGUID(guid,name))
-    {
-        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8);
-        data << (uint32)1;
-        data << guid;
+    if(!objmgr.GetPlayerNameByGUID(guid, name))
+    {
+        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
+        data << uint32(1);
+        data << uint64(guid);
         SendPacket(&data);
         return;
@@ -1015,9 +1017,9 @@
 
     std::wstring wname;
-    if(!Utf8toWStr(name,wname))
-    {
-        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8);
-        data << (uint32)1;
-        data << guid;
+    if(!Utf8toWStr(name, wname))
+    {
+        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
+        data << uint32(1);
+        data << uint64(guid);
         SendPacket(&data);
         return;
@@ -1026,7 +1028,7 @@
     if(!isCyrillicCharacter(wname[0]))                      // name already stored as only single alphabet using
     {
-        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8);
-        data << (uint32)1;
-        data << guid;
+        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
+        data << uint32(1);
+        data << uint64(guid);
         SendPacket(&data);
         return;
@@ -1036,11 +1038,12 @@
     DeclinedName declinedname;
 
+    CHECK_PACKET_SIZE(recv_data, recv_data.rpos() + 1);
     recv_data >> name2;
 
-    if(name2!=name)                                         // character have different name
-    {
-        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8);
-        data << (uint32)1;
-        data << guid;
+    if(name2 != name)                                       // character have different name
+    {
+        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
+        data << uint32(1);
+        data << uint64(guid);
         SendPacket(&data);
         return;
@@ -1049,10 +1052,11 @@
     for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
     {
+        CHECK_PACKET_SIZE(recv_data, recv_data.rpos() + 1);
         recv_data >> declinedname.name[i];
         if(!normalizePlayerName(declinedname.name[i]))
         {
-            WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8);
-            data << (uint32)1;
-            data << guid;
+            WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
+            data << uint32(1);
+            data << uint64(guid);
             SendPacket(&data);
             return;
@@ -1060,9 +1064,9 @@
     }
 
-    if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname,0),declinedname))
-    {
-        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8);
-        data << (uint32)1;
-        data << guid;
+    if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname, 0), declinedname))
+    {
+        WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
+        data << uint32(1);
+        data << uint64(guid);
         SendPacket(&data);
         return;
@@ -1075,10 +1079,10 @@
     CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(guid));
     CharacterDatabase.PExecute("INSERT INTO character_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%s','%s','%s','%s','%s')",
-        GUID_LOPART(guid), declinedname.name[0].c_str(),declinedname.name[1].c_str(),declinedname.name[2].c_str(),declinedname.name[3].c_str(),declinedname.name[4].c_str());
+        GUID_LOPART(guid), declinedname.name[0].c_str(), declinedname.name[1].c_str(), declinedname.name[2].c_str(), declinedname.name[3].c_str(), declinedname.name[4].c_str());
     CharacterDatabase.CommitTransaction();
 
-    WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8);
-    data << (uint32)0;                                      // OK
-    data << guid;
+    WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
+    data << uint32(0);                                      // OK
+    data << uint64(guid);
     SendPacket(&data);
 }
Index: /trunk/src/game/SharedDefines.h
===================================================================
--- /trunk/src/game/SharedDefines.h (revision 253)
+++ /trunk/src/game/SharedDefines.h (revision 262)
@@ -249,5 +249,5 @@
 #define SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY    0x00008000            // 15 remove auras on immunity
 #define SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE 0x00010000            // 16 unaffected by school immunity
-#define SPELL_ATTR_EX_UNK17                       0x00020000            // 17
+#define SPELL_ATTR_EX_UNAUTOCASTABLE_BY_PET       0x00020000            // 17
 #define SPELL_ATTR_EX_UNK18                       0x00040000            // 18
 #define SPELL_ATTR_EX_UNK19                       0x00080000            // 19
Index: /trunk/src/game/PlayerDump.cpp
===================================================================
--- /trunk/src/game/PlayerDump.cpp (revision 261)
+++ /trunk/src/game/PlayerDump.cpp (revision 262)
Index: /trunk/src/game/Formulas.h
===================================================================
--- /trunk/src/game/Formulas.h (revision 261)
+++ /trunk/src/game/Formulas.h (revision 262)
Index: /trunk/src/game/GMTicketHandler.cpp
===================================================================
--- /trunk/src/game/GMTicketHandler.cpp (revision 261)
+++ /trunk/src/game/GMTicketHandler.cpp (revision 262)
Index: /trunk/src/game/ObjectMgr.h
===================================================================
--- /trunk/src/game/ObjectMgr.h (revision 261)
+++ /trunk/src/game/ObjectMgr.h (revision 262)
Index: /trunk/src/game/Level2.cpp
===================================================================
--- /trunk/src/game/Level2.cpp (revision 261)
+++ /trunk/src/game/Level2.cpp (revision 262)
Index: /trunk/src/game/Pet.cpp
===================================================================
--- /trunk/src/game/Pet.cpp (revision 253)
+++ /trunk/src/game/Pet.cpp (revision 262)
@@ -287,4 +287,9 @@
             ++iter;
             m_charmInfo->GetActionBarEntry(index)->SpellOrAction = atol((*iter).c_str());
+
+            // patch for old data where some spells have ACT_DECIDE but should have ACT_CAST
+            // so overwrite old state 
+            SpellEntry const *spellInfo = sSpellStore.LookupEntry(m_charmInfo->GetActionBarEntry(index)->SpellOrAction);
+            if (spellInfo && spellInfo->AttributesEx & SPELL_ATTR_EX_UNAUTOCASTABLE_BY_PET) m_charmInfo->GetActionBarEntry(index)->Type = ACT_CAST;
         }
 
@@ -1323,5 +1328,5 @@
         SetUInt32Value(i, 0);
 
-    QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber());
+    QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber());
 
     if(result)
@@ -1333,8 +1338,9 @@
             uint32 spellid = fields[1].GetUInt32();
             uint32 effindex = fields[2].GetUInt32();
-            int32 damage     = (int32)fields[3].GetUInt32();
-            int32 maxduration = (int32)fields[4].GetUInt32();
-            int32 remaintime = (int32)fields[5].GetUInt32();
-            int32 remaincharges = (int32)fields[6].GetUInt32();
+            uint32 stackcount= fields[3].GetUInt32();
+            int32 damage     = (int32)fields[4].GetUInt32();
+            int32 maxduration = (int32)fields[5].GetUInt32();
+            int32 remaintime = (int32)fields[6].GetUInt32();
+            int32 remaincharges = (int32)fields[7].GetUInt32();
 
             SpellEntry const* spellproto = sSpellStore.LookupEntry(spellid);
@@ -1373,10 +1379,13 @@
                 continue;
 
-            Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL);
-
-            if(!damage)
-                damage = aura->GetModifier()->m_amount;
-            aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges);
-            AddAura(aura);
+            for(uint32 i=0; i<stackcount; i++)
+            {
+                Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL);
+
+                if(!damage)
+                    damage = aura->GetModifier()->m_amount;
+                aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges);
+                AddAura(aura);
+            }
         }
         while( result->NextRow() );
@@ -1391,28 +1400,50 @@
 
     AuraMap const& auras = GetAuras();
-    for(AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
-    {
-        // skip all auras from spell that apply at cast SPELL_AURA_MOD_SHAPESHIFT or pet area auras.
-        SpellEntry const *spellInfo = itr->second->GetSpellProto();
-        uint8 i;
-        for (i = 0; i < 3; i++)
-            if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH ||
-                spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_OWNER ||
-                spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PET )
+    if (auras.empty())
+        return;
+
+    spellEffectPair lastEffectPair = auras.begin()->first;
+    uint32 stackCounter = 1;
+
+    for(AuraMap::const_iterator itr = auras.begin(); ; ++itr)
+    {
+        if(itr == auras.end() || lastEffectPair != itr->first)
+        {
+            AuraMap::const_iterator itr2 = itr;
+            // save previous spellEffectPair to db
+            itr2--;
+            SpellEntry const *spellInfo = itr2->second->GetSpellProto();
+            /// do not save single target auras (unless they were cast by the player)
+            if (!(itr2->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo)))
+            {
+                if(!itr2->second->IsPassive())
+                {
+                    // skip all auras from spell that apply at cast SPELL_AURA_MOD_SHAPESHIFT or pet area auras.
+                    uint8 i;
+                    for (i = 0; i < 3; i++)
+                        if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH ||
+                            spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_OWNER ||
+                            spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PET )
+                            break;
+
+                    if (i == 3)
+                    {
+                        CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges) "
+                            "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%u', '%d', '%d', '%d', '%d')",
+                            m_charmInfo->GetPetNumber(), itr2->second->GetCasterGUID(),(uint32)itr2->second->GetId(), (uint32)itr2->second->GetEffIndex(), stackCounter, itr2->second->GetModifier()->m_amount,int(itr2->second->GetAuraMaxDuration()),int(itr2->second->GetAuraDuration()),int(itr2->second->m_procCharges));
+                    }
+                }
+            }
+            if(itr == auras.end())
                 break;
-
-        if (i != 3)
-            continue;
-        
-        if(itr->second->IsPassive())
-            continue;
-
-        /// do not save single target auras (unless they were cast by the player)
-        if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo))
-            continue;
-
-        CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) "
-            "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')",
-            m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges));
+        }
+
+        if (lastEffectPair == itr->first)
+            stackCounter++;
+        else
+        {
+            lastEffectPair = itr->first;
+            stackCounter = 1;
+        }
     }
 }
@@ -1434,4 +1465,7 @@
         return false;
     }
+
+    // same spells don't have autocast option
+    if (spellInfo->AttributesEx & SPELL_ATTR_EX_UNAUTOCASTABLE_BY_PET) active = ACT_CAST;
 
     PetSpellMap::iterator itr = m_spells.find(spell_id);
@@ -1509,5 +1543,5 @@
         CastSpell(this, spell_id, true);
     else if(state == PETSPELL_NEW)
-        m_charmInfo->AddSpellToAB(oldspell_id, spell_id);
+        m_charmInfo->AddSpellToAB(oldspell_id, spell_id, active);
 
     if(newspell->active == ACT_ENABLED)
@@ -1659,8 +1693,8 @@
         return;
 
-    if(const SpellEntry *tempSpell = GetSpellStore()->LookupEntry(spellid))
-        if(tempSpell->EffectImplicitTargetA[0] != TARGET_ALL_AROUND_CASTER
-            && tempSpell->EffectImplicitTargetA[0] != TARGET_CHAIN_DAMAGE)
-            return;    
+    //if(const SpellEntry *tempSpell = GetSpellStore()->LookupEntry(spellid))
+    //    if(tempSpell->EffectImplicitTargetA[0] != TARGET_ALL_AROUND_CASTER
+    //        && tempSpell->EffectImplicitTargetA[0] != TARGET_CHAIN_DAMAGE)
+    //        return;    
 
     PetSpellMap::const_iterator itr = m_spells.find((uint16)spellid);
Index: /trunk/src/game/WaypointManager.h
===================================================================
--- /trunk/src/game/WaypointManager.h (revision 261)
+++ /trunk/src/game/WaypointManager.h (revision 262)
Index: /trunk/src/game/ObjectMgr.cpp
===================================================================
--- /trunk/src/game/ObjectMgr.cpp (revision 261)
+++ /trunk/src/game/ObjectMgr.cpp (revision 262)
Index: /trunk/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/instance_mechanar.cpp
===================================================================
--- /trunk/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/instance_mechanar.cpp (revision 261)
+++ /trunk/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/instance_mechanar.cpp (revision 262)
Index: /trunk/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_pathaleon_the_calculator.cpp
===================================================================
--- /trunk/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_pathaleon_the_calculator.cpp (revision 261)
+++ /trunk/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_pathaleon_the_calculator.cpp (revision 262)
Index: /trunk/sql/updates/262_realmd.sql
===================================================================
--- /trunk/sql/updates/262_realmd.sql (revision 261)
+++ /trunk/sql/updates/262_realmd.sql (revision 262)
Index: /trunk/sql/updates/262_world_runthisonlyonce.sql
===================================================================
--- /trunk/sql/updates/262_world_runthisonlyonce.sql (revision 261)
+++ /trunk/sql/updates/262_world_runthisonlyonce.sql (revision 262)
Index: /trunk/sql/updates/262_characters.sql
===================================================================
--- /trunk/sql/updates/262_characters.sql (revision 261)
+++ /trunk/sql/updates/262_characters.sql (revision 262)
Index: /trunk/sql/updates/262_world.sql
===================================================================
--- /trunk/sql/updates/262_world.sql (revision 261)
+++ /trunk/sql/updates/262_world.sql (revision 262)
