diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game/Creature.cpp | 20 | ||||
-rw-r--r-- | src/game/Creature.h | 8 | ||||
-rw-r--r-- | src/game/CreatureEventAI.cpp | 4 | ||||
-rw-r--r-- | src/game/DBCStores.cpp | 3 | ||||
-rw-r--r-- | src/game/DBCStructure.h | 4 | ||||
-rw-r--r-- | src/game/Object.cpp | 8 | ||||
-rw-r--r-- | src/game/ObjectMgr.cpp | 88 | ||||
-rw-r--r-- | src/game/Player.cpp | 5 | ||||
-rw-r--r-- | src/game/QueryHandler.cpp | 8 | ||||
-rw-r--r-- | src/game/Totem.cpp | 16 | ||||
-rw-r--r-- | src/game/Unit.cpp | 2 | ||||
-rw-r--r-- | src/shared/ByteBuffer.h | 104 |
12 files changed, 173 insertions, 97 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index e7d3bbbccb6..bfa185010fd 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -92,20 +92,20 @@ uint32 CreatureInfo::GetRandomValidModelId() const uint32 c = 0; uint32 modelIDs[4]; - if (Modelid_A1) modelIDs[c++] = Modelid_A1; - if (Modelid_A2) modelIDs[c++] = Modelid_A2; - if (Modelid_H1) modelIDs[c++] = Modelid_H1; - if (Modelid_H2) modelIDs[c++] = Modelid_H2; + if (DisplayID_A) modelIDs[c++] = DisplayID_A; + if (DisplayID_A2) modelIDs[c++] = DisplayID_A2; + if (DisplayID_H) modelIDs[c++] = DisplayID_H; + if (DisplayID_H2) modelIDs[c++] = DisplayID_H2; return ((c>0) ? modelIDs[urand(0,c-1)] : 0); } uint32 CreatureInfo::GetFirstValidModelId() const { - if(Modelid_A1) return Modelid_A1; - if(Modelid_A2) return Modelid_A2; - if(Modelid_H1) return Modelid_H1; - if(Modelid_H2) return Modelid_H2; + if(DisplayID_A) return DisplayID_A; + if(DisplayID_A2) return DisplayID_A2; + if(DisplayID_H) return DisplayID_H; + if(DisplayID_H2) return DisplayID_H2; return 0; } @@ -1272,8 +1272,8 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask) CreatureInfo const *cinfo = GetCreatureInfo(); if(cinfo) { - if(displayId == cinfo->Modelid_A1 || displayId == cinfo->Modelid_A2 || - displayId == cinfo->Modelid_H1 || displayId == cinfo->Modelid_H2) displayId = 0; + if(displayId == cinfo->DisplayID_A || displayId == cinfo->DisplayID_A2 || + displayId == cinfo->DisplayID_H || displayId == cinfo->DisplayID_H2) displayId = 0; } // data->guid = guid don't must be update at save diff --git a/src/game/Creature.h b/src/game/Creature.h index 133fee38479..d7d070fc526 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -179,10 +179,10 @@ struct CreatureInfo uint32 HeroicEntry; uint32 unk1; uint32 unk2; - uint32 Modelid_A1; - uint32 Modelid_A2; - uint32 Modelid_H1; - uint32 Modelid_H2; + uint32 DisplayID_A; + uint32 DisplayID_A2; + uint32 DisplayID_H; + uint32 DisplayID_H2; char* Name; char* SubName; char* IconName; diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 3eb3a75c874..0e1c6c02319 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -386,8 +386,8 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 if (CreatureInfo const* ci = GetCreatureTemplateStore(action.morph.creatureId)) { //use default display - if (ci->Modelid_A1) - m_creature->SetDisplayId(ci->Modelid_A1); + if (ci->DisplayID_A) + m_creature->SetDisplayId(ci->DisplayID_A); } } //if no param1, then use value from param2 (modelId) diff --git a/src/game/DBCStores.cpp b/src/game/DBCStores.cpp index 4b11346f4b2..f618b8cfb8c 100644 --- a/src/game/DBCStores.cpp +++ b/src/game/DBCStores.cpp @@ -69,7 +69,6 @@ DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt); DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt); DBCStorage <GameObjectDisplayInfoEntry> sGameObjectDisplayInfoStore(GameObjectDisplayInfofmt); - DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt); DBCStorage <GlyphPropertiesEntry> sGlyphPropertiesStore(GlyphPropertiesfmt); DBCStorage <GlyphSlotEntry> sGlyphSlotStore(GlyphSlotfmt); @@ -205,7 +204,7 @@ void LoadDBCStores(const std::string& dataPath) { std::string dbcPath = dataPath+"dbc/"; - const uint32 DBCFilesCount = 78; + const uint32 DBCFilesCount = 79; barGoLink bar( DBCFilesCount ); diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h index cfc12510095..bfcf3647c57 100644 --- a/src/game/DBCStructure.h +++ b/src/game/DBCStructure.h @@ -861,8 +861,8 @@ struct FactionTemplateEntry struct GameObjectDisplayInfoEntry { - uint32 ID; //0 - //char* mdx; //1 + uint32 Displayid; // 0 m_ID + // char* filename; // 1 //uint32 unk1[10]; //2-11 float minX; float minY; diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 01a07770bd1..af96905b529 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -540,15 +540,15 @@ void Object::_BuildValuesUpdate(uint8 updatetype, ByteBuffer * data, UpdateMask { if(target->isGameMaster()) { - if(cinfo->Modelid_A1) - *data << cinfo->Modelid_A1; + if(cinfo->DisplayID_A) + *data << cinfo->DisplayID_A; else *data << 17519; // world invisible trigger's model } else { - if(cinfo->Modelid_A2) - *data << cinfo->Modelid_A2; + if(cinfo->DisplayID_A2) + *data << cinfo->DisplayID_A2; else *data << 11686; // world invisible trigger's model } diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 3c0e645b81e..f090a95af8e 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -614,28 +614,43 @@ void ObjectMgr::LoadCreatureTemplates() if(!factionTemplate) sLog.outErrorDb("Creature (Entry: %u) has non-existing faction_H template (%u)", cInfo->Entry, cInfo->faction_H); - // check model ids, supplying and sending non-existent ids to the client might crash them - if(cInfo->Modelid_A1 && !sCreatureModelStorage.LookupEntry<CreatureModelInfo>(cInfo->Modelid_A1)) - { - sLog.outErrorDb("Creature (Entry: %u) has non-existing Modelid_A1 (%u), setting it to 0", cInfo->Entry, cInfo->Modelid_A1); - const_cast<CreatureInfo*>(cInfo)->Modelid_A1 = 0; - } - if(cInfo->Modelid_A2 && !sCreatureModelStorage.LookupEntry<CreatureModelInfo>(cInfo->Modelid_A2)) - { - sLog.outErrorDb("Creature (Entry: %u) has non-existing Modelid_A2 (%u), setting it to 0", cInfo->Entry, cInfo->Modelid_A2); - const_cast<CreatureInfo*>(cInfo)->Modelid_A2 = 0; - } - if(cInfo->Modelid_H1 && !sCreatureModelStorage.LookupEntry<CreatureModelInfo>(cInfo->Modelid_H1)) + // used later for scale + CreatureDisplayInfoEntry const* displayEntryA = cInfo->DisplayID_A ? sCreatureDisplayInfoStore.LookupEntry(cInfo->DisplayID_A) : NULL; + if(cInfo->DisplayID_A && !displayEntryA) + sLog.outErrorDb("Creature (Entry: %u) has non-existing DisplayID_A id (%u), can crash client", cInfo->Entry, cInfo->DisplayID_A); + + if(cInfo->DisplayID_A2) { - sLog.outErrorDb("Creature (Entry: %u) has non-existing Modelid_H1 (%u), setting it to 0", cInfo->Entry, cInfo->Modelid_H1); - const_cast<CreatureInfo*>(cInfo)->Modelid_H1 = 0; + CreatureDisplayInfoEntry const* displayEntry = sCreatureDisplayInfoStore.LookupEntry(cInfo->DisplayID_A2); + if(!displayEntry) + { + sLog.outErrorDb("Creature (Entry: %u) has non-existing DisplayID_A2 id (%u), can crash client", cInfo->Entry, cInfo->DisplayID_A2); + const_cast<CreatureInfo*>(cInfo)->DisplayID_A2 = 0; + } } - if(cInfo->Modelid_H2 && !sCreatureModelStorage.LookupEntry<CreatureModelInfo>(cInfo->Modelid_H2)) + + // used later for scale + CreatureDisplayInfoEntry const* displayEntryH = cInfo->DisplayID_H ? sCreatureDisplayInfoStore.LookupEntry(cInfo->DisplayID_H) : NULL; + if(cInfo->DisplayID_H && !displayEntryH) + sLog.outErrorDb("Creature (Entry: %u) has non-existing DisplayID_H id (%u), can crash client", cInfo->Entry, cInfo->DisplayID_H); + + if(cInfo->DisplayID_H2) { - sLog.outErrorDb("Creature (Entry: %u) has non-existing Modelid_H2 (%u), setting it to 0", cInfo->Entry, cInfo->Modelid_H2); - const_cast<CreatureInfo*>(cInfo)->Modelid_H2 = 0; + CreatureDisplayInfoEntry const* displayEntry = sCreatureDisplayInfoStore.LookupEntry(cInfo->DisplayID_H2); + if(!displayEntry) + { + sLog.outErrorDb("Creature (Entry: %u) has non-existing DisplayID_H2 id (%u), can crash client", cInfo->Entry, cInfo->DisplayID_H2); + const_cast<CreatureInfo*>(cInfo)->DisplayID_H2 = 0; + } } + CreatureModelInfo const* minfo = sCreatureModelStorage.LookupEntry<CreatureModelInfo>(cInfo->DisplayID_A); + if (!minfo) + sLog.outErrorDb("Creature (Entry: %u) has non-existing modelId_A (%u)", cInfo->Entry, cInfo->DisplayID_A); + minfo = sCreatureModelStorage.LookupEntry<CreatureModelInfo>(cInfo->DisplayID_H); + if (!minfo) + sLog.outErrorDb("Creature (Entry: %u) has non-existing modelId_H (%u)", cInfo->Entry, cInfo->DisplayID_H); + if (cInfo->unit_class && ((1 << (cInfo->unit_class-1)) & CLASSMASK_ALL_CREATURES) == 0) sLog.outErrorDb("Creature (Entry: %u) has invalid unit_class(%u) for creature_template", cInfo->Entry, cInfo->unit_class); @@ -806,7 +821,10 @@ void ObjectMgr::LoadCreatureAddons() if (addon->mount) { if (!sCreatureDisplayInfoStore.LookupEntry(addon->mount)) + { sLog.outErrorDb("Creature (Entry %u) have invalid displayInfoId for mount (%u) defined in `creature_template_addon`.",addon->guidOrEntry, addon->mount); + const_cast<CreatureDataAddon*>(addon)->mount = 0; + } } if (!sEmotesStore.LookupEntry(addon->emote)) @@ -833,7 +851,10 @@ void ObjectMgr::LoadCreatureAddons() if (addon->mount) { if (!sCreatureDisplayInfoStore.LookupEntry(addon->mount)) + { sLog.outErrorDb("Creature (GUID %u) have invalid displayInfoId for mount (%u) defined in `creature_addon`.",addon->guidOrEntry, addon->mount); + const_cast<CreatureDataAddon*>(addon)->mount = 0; + } } if (!sEmotesStore.LookupEntry(addon->emote)) @@ -1130,8 +1151,8 @@ void ObjectMgr::LoadCreatures() { (const_cast<CreatureInfo*>(cInfo))->flags_extra |= CREATURE_FLAG_EXTRA_TRIGGER; } - else if(data.displayid == cInfo->Modelid_A1 || data.displayid == cInfo->Modelid_A2 - || data.displayid == cInfo->Modelid_H1 || data.displayid == cInfo->Modelid_H2) + else if(data.displayid == cInfo->DisplayID_A || data.displayid == cInfo->DisplayID_A2 + || data.displayid == cInfo->DisplayID_H || data.displayid == cInfo->DisplayID_H2) data.displayid = 0; */ @@ -1387,6 +1408,12 @@ void ObjectMgr::LoadGameobjects() continue; } + if(gInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(gInfo->displayId)) + { + sLog.outErrorDb("Gameobject (GUID: %u Entry %u GoType: %u) have invalid displayId (%u), not loaded.",guid, entry, gInfo->type, gInfo->displayId); + continue; + } + GameObjectData& data = mGameObjectDataMap[guid]; data.id = entry; @@ -1833,7 +1860,6 @@ void ObjectMgr::LoadItemPrototypes() } { - // can be used in equip slot, as page read use in inventory, or spell casting at use bool req = proto->InventoryType!=INVTYPE_NON_EQUIP || proto->PageText; if(!req) @@ -1887,7 +1913,7 @@ void ObjectMgr::LoadItemPrototypes() const_cast<ItemPrototype*>(proto)->MaxCount = -1; } - if(proto->Stackable==0) + if(proto->Stackable == 0) { sLog.outErrorDb("Item (Entry: %u) has wrong value in stackable (%i), replace by default 1.",i,proto->Stackable); const_cast<ItemPrototype*>(proto)->Stackable = 1; @@ -1897,10 +1923,10 @@ void ObjectMgr::LoadItemPrototypes() sLog.outErrorDb("Item (Entry: %u) has too large negative in stackable (%i), replace by value (-1) no stacking limits.",i,proto->Stackable); const_cast<ItemPrototype*>(proto)->Stackable = -1; } - else if(proto->Stackable > 255) + else if(proto->Stackable > 1000) { - sLog.outErrorDb("Item (Entry: %u) has too large value in stackable (%u), replace by hardcoded upper limit (255).",i,proto->Stackable); - const_cast<ItemPrototype*>(proto)->Stackable = 255; + sLog.outErrorDb("Item (Entry: %u) has too large value in stackable (%u), replace by hardcoded upper limit (1000).",i,proto->Stackable); + const_cast<ItemPrototype*>(proto)->Stackable = 1000; } if(proto->StatsCount > MAX_ITEM_PROTO_STATS) @@ -2092,7 +2118,7 @@ void ObjectMgr::LoadItemPrototypes() if(proto->TotemCategory && !sTotemCategoryStore.LookupEntry(proto->TotemCategory)) sLog.outErrorDb("Item (Entry: %u) has wrong TotemCategory (%u)",i,proto->TotemCategory); - for (int j = 0; j < MAX_ITEM_PROTO_SOCKETS; j++) + for (int j = 0; j < MAX_ITEM_PROTO_SOCKETS; ++j) { if(proto->Socket[j].Color && (proto->Socket[j].Color & SOCKET_COLOR_ALL) != proto->Socket[j].Color) { @@ -2115,6 +2141,12 @@ void ObjectMgr::LoadItemPrototypes() sLog.outErrorDb("Item (Entry: %u) has wrong LimitCategory value (%u)",i,proto->ItemLimitCategory); const_cast<ItemPrototype*>(proto)->ItemLimitCategory = 0; } + + if(proto->HolidayId && !sHolidaysStore.LookupEntry(proto->HolidayId)) + { + sLog.outErrorDb("Item (Entry: %u) has wrong HolidayId value (%u)", i, proto->HolidayId); + const_cast<ItemPrototype*>(proto)->HolidayId = 0; + } } } @@ -5077,7 +5109,7 @@ uint16 ObjectMgr::GetTaxiMount( uint32 id, uint32 team, bool allowed_alt_team /* CreatureInfo const *ci = GetCreatureTemplate(mount_entry); if(ci) - mount_id = ci->Modelid_A1; + mount_id = ci->DisplayID_A; } if (team == HORDE) { @@ -5088,7 +5120,7 @@ uint16 ObjectMgr::GetTaxiMount( uint32 id, uint32 team, bool allowed_alt_team /* CreatureInfo const *ci = GetCreatureTemplate(mount_entry); if(ci) - mount_id = ci->Modelid_H1; + mount_id = ci->DisplayID_H; } } @@ -6011,6 +6043,8 @@ void ObjectMgr::LoadGameobjectInfo() if (!goInfo) continue; + // some GO types have unused go template, check goInfo->displayId at GO spawn data loading or ignore + switch(goInfo->type) { case GAMEOBJECT_TYPE_DOOR: //0 diff --git a/src/game/Player.cpp b/src/game/Player.cpp index cd0cb336f64..9e86cab3615 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -3191,6 +3191,11 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool update_action_bar_ for (uint32 i=reqMap.count(spell_id);i>0;i--,itr2++) removeSpell(itr2->second,disabled); + // re-search, it can be corrupted in prev loop + itr = m_spells.find(spell_id); + if (itr == m_spells.end()) + return; // already unleared + bool cur_active = itr->second->active; bool cur_dependent = itr->second->dependent; diff --git a/src/game/QueryHandler.cpp b/src/game/QueryHandler.cpp index 5786e24eaef..1ed9fd77db3 100644 --- a/src/game/QueryHandler.cpp +++ b/src/game/QueryHandler.cpp @@ -189,10 +189,10 @@ void WorldSession::HandleCreatureQueryOpcode( WorldPacket & recv_data ) data << uint32(ci->rank); // Creature Rank (elite, boss, etc) data << uint32(ci->unk1); // new in 3.1, creature entry? data << uint32(ci->unk2); // new in 3.1, creature entry? - data << (uint32)ci->Modelid_A1; // Modelid_A1 - data << (uint32)ci->Modelid_A2; // Modelid_A2 - data << (uint32)ci->Modelid_H1; // Modelid_H1 - data << (uint32)ci->Modelid_H2; // Modelid_H2 + data << (uint32)ci->DisplayID_A; // DisplayID_A + data << (uint32)ci->DisplayID_A2; // DisplayID_A2 + data << (uint32)ci->DisplayID_H; // DisplayID_H + data << (uint32)ci->DisplayID_H2; // DisplayID_H2 data << float(ci->unk16); // unk data << float(ci->unk17); // unk data << uint8(ci->RacialLeader); diff --git a/src/game/Totem.cpp b/src/game/Totem.cpp index 3cdc8050d53..98701b7f6b5 100644 --- a/src/game/Totem.cpp +++ b/src/game/Totem.cpp @@ -62,17 +62,17 @@ void Totem::InitStats(uint32 duration) uint32 modelid = 0; if(((Player*)m_owner)->GetTeam() == HORDE) { - if(cinfo->Modelid_H1) - modelid = cinfo->Modelid_H1; - else if(cinfo->Modelid_H2) - modelid = cinfo->Modelid_H2; + if(cinfo->DisplayID_H) + modelid = cinfo->DisplayID_H; + else if(cinfo->DisplayID_H2) + modelid = cinfo->DisplayID_H2; } else { - if(cinfo->Modelid_A1) - modelid = cinfo->Modelid_A1; - else if(cinfo->Modelid_A2) - modelid = cinfo->Modelid_A2; + if(cinfo->DisplayID_A) + modelid = cinfo->DisplayID_A; + else if(cinfo->DisplayID_A2) + modelid = cinfo->DisplayID_A2; } if (modelid) SetDisplayId(modelid); diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 5929f774f1f..a7fdab050e0 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -5598,7 +5598,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger target = GetGuardianPet(); if (!target) return false; - basepoints0 = damage * 15 / 100; + basepoints0 = damage * triggerAmount / 100; triggered_spell_id = 54181; break; } diff --git a/src/shared/ByteBuffer.h b/src/shared/ByteBuffer.h index 7ff6d32fd12..75c33dcf3ca 100644 --- a/src/shared/ByteBuffer.h +++ b/src/shared/ByteBuffer.h @@ -36,11 +36,13 @@ class ByteBuffer { _storage.reserve(DEFAULT_SIZE); } + // constructor ByteBuffer(size_t res): _rpos(0), _wpos(0) { _storage.reserve(res); } + // copy constructor ByteBuffer(const ByteBuffer &buf): _rpos(buf._rpos), _wpos(buf._wpos), _storage(buf._storage) { } @@ -67,16 +69,19 @@ class ByteBuffer append<uint8>(value); return *this; } + ByteBuffer &operator<<(uint16 value) { append<uint16>(value); return *this; } + ByteBuffer &operator<<(uint32 value) { append<uint32>(value); return *this; } + ByteBuffer &operator<<(uint64 value) { append<uint64>(value); @@ -89,16 +94,19 @@ class ByteBuffer append<int8>(value); return *this; } + ByteBuffer &operator<<(int16 value) { append<int16>(value); return *this; } + ByteBuffer &operator<<(int32 value) { append<int32>(value); return *this; } + ByteBuffer &operator<<(int64 value) { append<int64>(value); @@ -111,17 +119,20 @@ class ByteBuffer append<float>(value); return *this; } + ByteBuffer &operator<<(double value) { append<double>(value); return *this; } + ByteBuffer &operator<<(const std::string &value) { append((uint8 const *)value.c_str(), value.length()); append((uint8)0); return *this; } + ByteBuffer &operator<<(const char *str) { append((uint8 const *)str, str ? strlen(str) : 0); @@ -140,16 +151,19 @@ class ByteBuffer value = read<uint8>(); return *this; } + ByteBuffer &operator>>(uint16 &value) { value = read<uint16>(); return *this; } + ByteBuffer &operator>>(uint32 &value) { value = read<uint32>(); return *this; } + ByteBuffer &operator>>(uint64 &value) { value = read<uint64>(); @@ -162,16 +176,19 @@ class ByteBuffer value = read<int8>(); return *this; } + ByteBuffer &operator>>(int16 &value) { value = read<int16>(); return *this; } + ByteBuffer &operator>>(int32 &value) { value = read<int32>(); return *this; } + ByteBuffer &operator>>(int64 &value) { value = read<int64>(); @@ -183,20 +200,22 @@ class ByteBuffer value = read<float>(); return *this; } + ByteBuffer &operator>>(double &value) { value = read<double>(); return *this; } + ByteBuffer &operator>>(std::string& value) { value.clear(); while (rpos() < size()) // prevent crash at wrong string format in packet { - char c=read<char>(); - if (c==0) + char c = read<char>(); + if (c == 0) break; - value+=c; + value += c; } return *this; } @@ -212,7 +231,7 @@ class ByteBuffer { _rpos = rpos_; return _rpos; - }; + } size_t wpos() const { return _wpos; } @@ -224,13 +243,14 @@ class ByteBuffer template <typename T> T read() { - T r=read<T>(_rpos); + T r = read<T>(_rpos); _rpos += sizeof(T); return r; - }; + } + template <typename T> T read(size_t pos) const { - ASSERT(pos + sizeof(T) <= size() || PrintPosError(false,pos,sizeof(T))); + ASSERT(pos + sizeof(T) <= size() || PrintPosError(false, pos, sizeof(T))); T val = *((T const*)&_storage[pos]); EndianConvert(val); return val; @@ -238,31 +258,31 @@ class ByteBuffer void read(uint8 *dest, size_t len) { - ASSERT(_rpos + len <= size() || PrintPosError(false,_rpos,len)); + ASSERT(_rpos + len <= size() || PrintPosError(false, _rpos, len)); memcpy(dest, &_storage[_rpos], len); _rpos += len; } bool readPackGUID(uint64& guid) { - if(rpos()+1 > size()) + if(rpos() + 1 > size()) return false; guid = 0; - uint8 guidmark=0; + uint8 guidmark = 0; (*this) >> guidmark; - for(int i=0;i<8;i++) + for(int i = 0; i < 8; ++i) { if(guidmark & (uint8(1) << i)) { - if(rpos()+1 > size()) + if(rpos() + 1 > size()) return false; uint8 bit; (*this) >> bit; - guid |= (uint64(bit) << (i*8)); + guid |= (uint64(bit) << (i * 8)); } } @@ -279,28 +299,33 @@ class ByteBuffer _storage.resize(newsize); _rpos = 0; _wpos = size(); - }; + } + void reserve(size_t ressize) { - if (ressize > size()) _storage.reserve(ressize); - }; + if (ressize > size()) + _storage.reserve(ressize); + } void append(const std::string& str) { - append((uint8 const*)str.c_str(),str.size() + 1); + append((uint8 const*)str.c_str(), str.size() + 1); } + void append(const char *src, size_t cnt) { return append((const uint8 *)src, cnt); } - template<class T> - void append(const T *src, size_t cnt) + + template<class T> void append(const T *src, size_t cnt) { - return append((const uint8 *)src, cnt*sizeof(T)); + return append((const uint8 *)src, cnt * sizeof(T)); } + void append(const uint8 *src, size_t cnt) { - if (!cnt) return; + if (!cnt) + return; ASSERT(size() < 10000000); @@ -309,9 +334,21 @@ class ByteBuffer memcpy(&_storage[_wpos], src, cnt); _wpos += cnt; } + void append(const ByteBuffer& buffer) { - if(buffer.wpos()) append(buffer.contents(),buffer.wpos()); + if(buffer.wpos()) + append(buffer.contents(), buffer.wpos()); + } + + // can be used in SMSG_MONSTER_MOVE opcode + void appendPackXYZ(float x, float y, float z) + { + uint32 packed = 0; + packed |= ((int)(x / 0.25f) & 0x7FF); + packed |= ((int)(y / 0.25f) & 0x7FF) << 11; + packed |= ((int)(z / 0.25f) & 0x3FF) << 22; + *this << packed; } void appendPackGUID(uint64 guid) @@ -321,11 +358,11 @@ class ByteBuffer size_t mask_position = wpos(); *this << uint8(0); - for(uint8 i = 0; i < 8; i++) + for(uint8 i = 0; i < 8; ++i) { if(guid & 0xFF) { - _storage[mask_position] |= uint8(1<<i); + _storage[mask_position] |= uint8(1 << i); *this << uint8(guid & 0xFF); } @@ -335,16 +372,17 @@ class ByteBuffer void put(size_t pos, const uint8 *src, size_t cnt) { - ASSERT(pos + cnt <= size() || PrintPosError(true,pos,cnt)); + ASSERT(pos + cnt <= size() || PrintPosError(true, pos, cnt)); memcpy(&_storage[pos], src, cnt); } + void print_storage() const { if(!sLog.IsOutDebug()) // optimize disabled debug output return; sLog.outDebug("STORAGE_SIZE: %lu", (unsigned long)size() ); - for(uint32 i = 0; i < size(); i++) + for(uint32 i = 0; i < size(); ++i) sLog.outDebugInLine("%u - ", read<uint8>(i) ); sLog.outDebug(" "); } @@ -355,7 +393,7 @@ class ByteBuffer return; sLog.outDebug("STORAGE_SIZE: %lu", (unsigned long)size() ); - for(uint32 i = 0; i < size(); i++) + for(uint32 i = 0; i < size(); ++i) sLog.outDebugInLine("%c", read<uint8>(i) ); sLog.outDebug(" "); } @@ -368,9 +406,9 @@ class ByteBuffer uint32 j = 1, k = 1; sLog.outDebug("STORAGE_SIZE: %lu", (unsigned long)size() ); - for(uint32 i = 0; i < size(); i++) + for(uint32 i = 0; i < size(); ++i) { - if ((i == (j*8)) && ((i != (k*16)))) + if ((i == (j * 8)) && ((i != (k * 16)))) { if (read<uint8>(i) < 0x10) { @@ -382,7 +420,7 @@ class ByteBuffer } ++j; } - else if (i == (k*16)) + else if (i == (k * 16)) { if (read<uint8>(i) < 0x10) { @@ -431,7 +469,7 @@ class ByteBuffer template <typename T> ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v) { b << (uint32)v.size(); - for (typename std::vector<T>::iterator i = v.begin(); i != v.end(); i++) + for (typename std::vector<T>::iterator i = v.begin(); i != v.end(); ++i) { b << *i; } @@ -455,7 +493,7 @@ template <typename T> ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v) template <typename T> ByteBuffer &operator<<(ByteBuffer &b, std::list<T> v) { b << (uint32)v.size(); - for (typename std::list<T>::iterator i = v.begin(); i != v.end(); i++) + for (typename std::list<T>::iterator i = v.begin(); i != v.end(); ++i) { b << *i; } @@ -479,7 +517,7 @@ template <typename T> ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v) template <typename K, typename V> ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m) { b << (uint32)m.size(); - for (typename std::map<K, V>::iterator i = m.begin(); i != m.end(); i++) + for (typename std::map<K, V>::iterator i = m.begin(); i != m.end(); ++i) { b << i->first << i->second; } |