diff options
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 11 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.h | 36 | ||||
-rw-r--r-- | src/server/game/Entities/Object/ObjectDefines.h | 17 | ||||
-rw-r--r-- | src/server/game/Entities/Object/ObjectGuid.cpp | 109 | ||||
-rw-r--r-- | src/server/game/Entities/Object/ObjectGuid.h | 253 | ||||
-rw-r--r-- | src/server/game/Handlers/MiscHandler.cpp | 2 |
6 files changed, 376 insertions, 52 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 45450a0c129..92afb38b4cb 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -82,8 +82,6 @@ Object::Object() : m_PackGUID(sizeof(uint64)+1) m_inWorld = false; m_objectUpdated = false; - - m_PackGUID.appendPackGUID(0); } WorldObject::~WorldObject() @@ -140,8 +138,7 @@ void Object::_Create(uint32 guidlow, uint32 entry, HighGuid guidhigh) uint64 guid = MAKE_NEW_GUID(guidlow, entry, guidhigh); SetUInt64Value(OBJECT_FIELD_GUID, guid); SetUInt32Value(OBJECT_FIELD_TYPE, m_objectType); - m_PackGUID.wpos(0); - m_PackGUID.appendPackGUID(GetGUID()); + m_PackGUID.Set(guid); } std::string Object::_ConcatFields(uint16 startIndex, uint16 size) const @@ -336,6 +333,12 @@ uint16 Object::GetUInt16Value(uint16 index, uint8 offset) const return *(((uint16*)&m_uint32Values[index])+offset); } +ObjectGuid const& Object::GetGuidValue(uint16 index) const +{ + ASSERT(index + 1 < m_valuesCount || PrintIndexError(index, false)); + return *((ObjectGuid*)&(m_uint32Values[index])); +} + void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const { Unit const* unit = NULL; diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 85381c1dfd9..e3b9a5d22e3 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -46,33 +46,6 @@ #define NOMINAL_MELEE_RANGE 5.0f #define MELEE_RANGE (NOMINAL_MELEE_RANGE - MIN_MELEE_REACH * 2) //center to center for players -enum TypeMask -{ - TYPEMASK_OBJECT = 0x0001, - TYPEMASK_ITEM = 0x0002, - TYPEMASK_CONTAINER = 0x0006, // TYPEMASK_ITEM | 0x0004 - TYPEMASK_UNIT = 0x0008, // creature - TYPEMASK_PLAYER = 0x0010, - TYPEMASK_GAMEOBJECT = 0x0020, - TYPEMASK_DYNAMICOBJECT = 0x0040, - TYPEMASK_CORPSE = 0x0080, - TYPEMASK_SEER = TYPEMASK_PLAYER | TYPEMASK_UNIT | TYPEMASK_DYNAMICOBJECT -}; - -enum TypeID -{ - TYPEID_OBJECT = 0, - TYPEID_ITEM = 1, - TYPEID_CONTAINER = 2, - TYPEID_UNIT = 3, - TYPEID_PLAYER = 4, - TYPEID_GAMEOBJECT = 5, - TYPEID_DYNAMICOBJECT = 6, - TYPEID_CORPSE = 7 -}; - -#define NUM_CLIENT_OBJECT_TYPES 8 - uint32 GuidHigh2TypeId(uint32 guid_hi); enum TempSummonType @@ -128,11 +101,11 @@ class Object virtual void AddToWorld(); virtual void RemoveFromWorld(); - uint64 GetGUID() const { return GetUInt64Value(0); } - uint32 GetGUIDLow() const { return GUID_LOPART(GetUInt64Value(0)); } - uint32 GetGUIDMid() const { return GUID_ENPART(GetUInt64Value(0)); } - uint32 GetGUIDHigh() const { return GUID_HIPART(GetUInt64Value(0)); } const ByteBuffer& GetPackGUID() const { return m_PackGUID; } + uint64 GetGUID() const { return GetUInt64Value(OBJECT_FIELD_GUID); } + uint32 GetGUIDLow() const { return GUID_LOPART(GetUInt64Value(OBJECT_FIELD_GUID)); } + uint32 GetGUIDMid() const { return GUID_ENPART(GetUInt64Value(OBJECT_FIELD_GUID)); } + uint32 GetGUIDHigh() const { return GUID_HIPART(GetUInt64Value(OBJECT_FIELD_GUID)); } uint32 GetEntry() const { return GetUInt32Value(OBJECT_FIELD_ENTRY); } void SetEntry(uint32 entry) { SetUInt32Value(OBJECT_FIELD_ENTRY, entry); } @@ -157,6 +130,7 @@ class Object float GetFloatValue(uint16 index) const; uint8 GetByteValue(uint16 index, uint8 offset) const; uint16 GetUInt16Value(uint16 index, uint8 offset) const; + ObjectGuid const& GetGuidValue(uint16 index) const; void SetInt32Value(uint16 index, int32 value); void SetUInt32Value(uint16 index, uint32 value); diff --git a/src/server/game/Entities/Object/ObjectDefines.h b/src/server/game/Entities/Object/ObjectDefines.h index 236f77caf5a..1ccedbaaf9f 100644 --- a/src/server/game/Entities/Object/ObjectDefines.h +++ b/src/server/game/Entities/Object/ObjectDefines.h @@ -20,22 +20,7 @@ #define TRINITY_OBJECTDEFINES_H #include "Define.h" - -enum HighGuid -{ - HIGHGUID_ITEM = 0x4000, // blizz 4000 - HIGHGUID_CONTAINER = 0x4000, // blizz 4000 - HIGHGUID_PLAYER = 0x0000, // blizz 0000 - HIGHGUID_GAMEOBJECT = 0xF110, // blizz F110 - HIGHGUID_TRANSPORT = 0xF120, // blizz F120 (for GAMEOBJECT_TYPE_TRANSPORT) - HIGHGUID_UNIT = 0xF130, // blizz F130 - HIGHGUID_PET = 0xF140, // blizz F140 - HIGHGUID_VEHICLE = 0xF150, // blizz F550 - HIGHGUID_DYNAMICOBJECT = 0xF100, // blizz F100 - HIGHGUID_CORPSE = 0xF101, // blizz F100 - HIGHGUID_MO_TRANSPORT = 0x1FC0, // blizz 1FC0 (for GAMEOBJECT_TYPE_MO_TRANSPORT) - HIGHGUID_GROUP = 0x1F50 -}; +#include "ObjectGuid.h" // used for creating values for respawn for example inline uint64 MAKE_PAIR64(uint32 l, uint32 h); diff --git a/src/server/game/Entities/Object/ObjectGuid.cpp b/src/server/game/Entities/Object/ObjectGuid.cpp new file mode 100644 index 00000000000..68e6ca1b3ce --- /dev/null +++ b/src/server/game/Entities/Object/ObjectGuid.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * 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 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, see <http://www.gnu.org/licenses/>. + */ + +#include "ObjectGuid.h" +#include "World.h" +#include "ObjectMgr.h" +#include <sstream> + +char const* ObjectGuid::GetTypeName(HighGuid high) +{ + switch (high) + { + case HIGHGUID_ITEM: return "Item"; + case HIGHGUID_PLAYER: return "Player"; + case HIGHGUID_GAMEOBJECT: return "Gameobject"; + case HIGHGUID_TRANSPORT: return "Transport"; + case HIGHGUID_UNIT: return "Creature"; + case HIGHGUID_PET: return "Pet"; + case HIGHGUID_VEHICLE: return "Vehicle"; + case HIGHGUID_DYNAMICOBJECT: return "DynObject"; + case HIGHGUID_CORPSE: return "Corpse"; + case HIGHGUID_MO_TRANSPORT: return "MoTransport"; + case HIGHGUID_INSTANCE: return "InstanceID"; + case HIGHGUID_GROUP: return "Group"; + default: + return "<unknown>"; + } +} + +std::string ObjectGuid::ToString() const +{ + std::ostringstream str; + str << GetTypeName(); + + if (IsPlayer()) + { + std::string name; + if (sObjectMgr->GetPlayerNameByGUID(m_guid, name)) + str << " " << name; + } + + str << " ("; + if (HasEntry()) + str << (IsPet() ? "Petnumber: " : "Entry: ") << GetEntry() << " "; + str << "Guid: " << GetCounter() << ")"; + return str.str(); +} + +template<HighGuid high> +uint32 ObjectGuidGenerator<high>::Generate() +{ + if (m_nextGuid >= ObjectGuid::GetMaxCounter(high) - 1) + { + TC_LOG_ERROR("", "%s guid overflow!! Can't continue, shutting down server. ", ObjectGuid::GetTypeName(high)); + World::StopNow(ERROR_EXIT_CODE); + } + return m_nextGuid++; +} + +ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid) +{ + buf << uint64(guid.GetRawValue()); + return buf; +} + +ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid) +{ + guid.Set(buf.read<uint64>()); + return buf; +} + +ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid) +{ + buf.append(guid.m_packedGuid); + return buf; +} + +ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid) +{ + buf.readPackGUID(*reinterpret_cast<uint64*>(guid.m_guidPtr)); + return buf; +} + +template uint32 ObjectGuidGenerator<HIGHGUID_ITEM>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_PLAYER>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_GAMEOBJECT>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_TRANSPORT>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_UNIT>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_PET>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_VEHICLE>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_DYNAMICOBJECT>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_CORPSE>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_INSTANCE>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_GROUP>::Generate(); diff --git a/src/server/game/Entities/Object/ObjectGuid.h b/src/server/game/Entities/Object/ObjectGuid.h new file mode 100644 index 00000000000..fe90c9f9436 --- /dev/null +++ b/src/server/game/Entities/Object/ObjectGuid.h @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * 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 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ObjectGuid_h__ +#define ObjectGuid_h__ + +#include "Common.h" +#include "ByteBuffer.h" + +#include <functional> + +enum TypeID +{ + TYPEID_OBJECT = 0, + TYPEID_ITEM = 1, + TYPEID_CONTAINER = 2, + TYPEID_UNIT = 3, + TYPEID_PLAYER = 4, + TYPEID_GAMEOBJECT = 5, + TYPEID_DYNAMICOBJECT = 6, + TYPEID_CORPSE = 7 +}; + +#define NUM_CLIENT_OBJECT_TYPES 8 + +enum TypeMask +{ + TYPEMASK_OBJECT = 0x0001, + TYPEMASK_ITEM = 0x0002, + TYPEMASK_CONTAINER = 0x0006, // TYPEMASK_ITEM | 0x0004 + TYPEMASK_UNIT = 0x0008, // creature + TYPEMASK_PLAYER = 0x0010, + TYPEMASK_GAMEOBJECT = 0x0020, + TYPEMASK_DYNAMICOBJECT = 0x0040, + TYPEMASK_CORPSE = 0x0080, + TYPEMASK_SEER = TYPEMASK_PLAYER | TYPEMASK_UNIT | TYPEMASK_DYNAMICOBJECT +}; + +enum HighGuid +{ + HIGHGUID_ITEM = 0x4000, // blizz 4000 + HIGHGUID_CONTAINER = 0x4000, // blizz 4000 + HIGHGUID_PLAYER = 0x0000, // blizz 0000 + HIGHGUID_GAMEOBJECT = 0xF110, // blizz F110 + HIGHGUID_TRANSPORT = 0xF120, // blizz F120 (for GAMEOBJECT_TYPE_TRANSPORT) + HIGHGUID_UNIT = 0xF130, // blizz F130 + HIGHGUID_PET = 0xF140, // blizz F140 + HIGHGUID_VEHICLE = 0xF150, // blizz F550 + HIGHGUID_DYNAMICOBJECT = 0xF100, // blizz F100 + HIGHGUID_CORPSE = 0xF101, // blizz F100 + HIGHGUID_MO_TRANSPORT = 0x1FC0, // blizz 1FC0 (for GAMEOBJECT_TYPE_MO_TRANSPORT) + HIGHGUID_INSTANCE = 0x1F40, // blizz 1F40 + HIGHGUID_GROUP = 0x1F50 +}; + +class ObjectGuid; +class PackedGuid; + +struct PackedGuidReader +{ + explicit PackedGuidReader(ObjectGuid& guid) : m_guidPtr(&guid) {} + ObjectGuid* m_guidPtr; +}; + +class ObjectGuid +{ + public: // constructors + ObjectGuid() : m_guid(0) {} + explicit ObjectGuid(uint64 guid) : m_guid(guid) {} + ObjectGuid(HighGuid hi, uint32 entry, uint32 counter) : m_guid(counter ? uint64(counter) | (uint64(entry) << 24) | (uint64(hi) << 48) : 0) {} + ObjectGuid(HighGuid hi, uint32 counter) : m_guid(counter ? uint64(counter) | (uint64(hi) << 48) : 0) {} + + //operator uint64() const { return m_guid; } + PackedGuidReader ReadAsPacked() { return PackedGuidReader(*this); } + + void Set(uint64 guid) { m_guid = guid; } + void Clear() { m_guid = 0; } + + PackedGuid WriteAsPacked() const; + + uint64 GetRawValue() const { return m_guid; } + HighGuid GetHigh() const { return HighGuid((m_guid >> 48) & 0x00000FFF); } + uint32 GetEntry() const { return HasEntry() ? uint32((m_guid >> 24) & UI64LIT(0x0000000000FFFFFF)) : 0; } + uint32 GetCounter() const + { + return HasEntry() + ? uint32(m_guid & UI64LIT(0x0000000000FFFFFF)) + : uint32(m_guid & UI64LIT(0x00000000FFFFFFFF)); + } + + static uint32 GetMaxCounter(HighGuid high) + { + return HasEntry(high) + ? uint32(0x00FFFFFF) + : uint32(0xFFFFFFFF); + } + + uint32 GetMaxCounter() const { return GetMaxCounter(GetHigh()); } + + bool IsEmpty() const { return m_guid == 0; } + bool IsCreature() const { return GetHigh() == HIGHGUID_UNIT; } + bool IsPet() const { return GetHigh() == HIGHGUID_PET; } + bool IsVehicle() const { return GetHigh() == HIGHGUID_VEHICLE; } + bool IsCreatureOrPet() const { return IsCreature() || IsPet(); } + bool IsCreatureOrVehicle() const { return IsCreature() || IsVehicle(); } + bool IsAnyTypeCreature() const { return IsCreature() || IsPet() || IsVehicle(); } + bool IsPlayer() const { return !IsEmpty() && GetHigh() == HIGHGUID_PLAYER; } + bool IsUnit() const { return IsAnyTypeCreature() || IsPlayer(); } + bool IsItem() const { return GetHigh() == HIGHGUID_ITEM; } + bool IsGameObject() const { return GetHigh() == HIGHGUID_GAMEOBJECT; } + bool IsDynamicObject() const { return GetHigh() == HIGHGUID_DYNAMICOBJECT; } + bool IsCorpse() const { return GetHigh() == HIGHGUID_CORPSE; } + bool IsTransport() const { return GetHigh() == HIGHGUID_TRANSPORT; } + bool IsMOTransport() const { return GetHigh() == HIGHGUID_MO_TRANSPORT; } + bool IsInstance() const { return GetHigh() == HIGHGUID_INSTANCE; } + bool IsGroup() const { return GetHigh() == HIGHGUID_GROUP; } + + static TypeID GetTypeId(HighGuid high) + { + switch (high) + { + case HIGHGUID_ITEM: return TYPEID_ITEM; + //case HIGHGUID_CONTAINER: return TYPEID_CONTAINER; HIGHGUID_CONTAINER==HIGHGUID_ITEM currently + case HIGHGUID_UNIT: return TYPEID_UNIT; + case HIGHGUID_PET: return TYPEID_UNIT; + case HIGHGUID_PLAYER: return TYPEID_PLAYER; + case HIGHGUID_GAMEOBJECT: return TYPEID_GAMEOBJECT; + case HIGHGUID_DYNAMICOBJECT: return TYPEID_DYNAMICOBJECT; + case HIGHGUID_CORPSE: return TYPEID_CORPSE; + case HIGHGUID_MO_TRANSPORT: return TYPEID_GAMEOBJECT; + case HIGHGUID_VEHICLE: return TYPEID_UNIT; + // unknown + case HIGHGUID_INSTANCE: + case HIGHGUID_GROUP: + default: return TYPEID_OBJECT; + } + } + + TypeID GetTypeId() const { return GetTypeId(GetHigh()); } + + bool operator!() const { return IsEmpty(); } + bool operator== (ObjectGuid const& guid) const { return GetRawValue() == guid.GetRawValue(); } + bool operator!= (ObjectGuid const& guid) const { return GetRawValue() != guid.GetRawValue(); } + bool operator< (ObjectGuid const& guid) const { return GetRawValue() < guid.GetRawValue(); } + + static char const* GetTypeName(HighGuid high); + char const* GetTypeName() const { return !IsEmpty() ? GetTypeName(GetHigh()) : "None"; } + std::string ToString() const; + + private: + static bool HasEntry(HighGuid high) + { + switch (high) + { + case HIGHGUID_ITEM: + case HIGHGUID_PLAYER: + case HIGHGUID_DYNAMICOBJECT: + case HIGHGUID_CORPSE: + case HIGHGUID_MO_TRANSPORT: + case HIGHGUID_INSTANCE: + case HIGHGUID_GROUP: + return false; + case HIGHGUID_GAMEOBJECT: + case HIGHGUID_TRANSPORT: + case HIGHGUID_UNIT: + case HIGHGUID_PET: + case HIGHGUID_VEHICLE: + default: + return true; + } + } + + bool HasEntry() const { return HasEntry(GetHigh()); } + + explicit ObjectGuid(uint32 const&) = delete; // no implementation, used to catch wrong type assignment + ObjectGuid(HighGuid, uint32, uint64 counter) = delete; // no implementation, used to catch wrong type assignment + ObjectGuid(HighGuid, uint64 counter) = delete; // no implementation, used to catch wrong type assignment + + uint64 m_guid; +}; + +// minimum buffer size for packed guid is 9 bytes +#define PACKED_GUID_MIN_BUFFER_SIZE 9 + +class PackedGuid +{ + friend ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid); + + public: // constructors + explicit PackedGuid() : m_packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { m_packedGuid.appendPackGUID(0); } + explicit PackedGuid(uint64 guid) : m_packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { m_packedGuid.appendPackGUID(guid); } + explicit PackedGuid(ObjectGuid guid) : m_packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { m_packedGuid.appendPackGUID(guid.GetRawValue()); } + + void Set(uint64 guid) { m_packedGuid.wpos(0); m_packedGuid.appendPackGUID(guid); } + void Set(ObjectGuid guid) { m_packedGuid.wpos(0); m_packedGuid.appendPackGUID(guid.GetRawValue()); } + + size_t size() const { return m_packedGuid.size(); } + + //private: // fields + ByteBuffer m_packedGuid; +}; + +template<HighGuid high> +class ObjectGuidGenerator +{ + public: // constructors + explicit ObjectGuidGenerator(uint32 start = 1) : m_nextGuid(start) {} + + void Set(uint32 val) { m_nextGuid = val; } + uint32 Generate(); + uint32 GetNextAfterMaxUsed() const { return m_nextGuid; } + + private: // fields + uint32 m_nextGuid; +}; + +ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid); +ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid); + +ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid); +ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid); + +inline PackedGuid ObjectGuid::WriteAsPacked() const { return PackedGuid(*this); } + +namespace std +{ + template<> + class hash<ObjectGuid> + { + public: + size_t operator()(ObjectGuid const& key) const + { + return hash<uint64>()(key.GetRawValue()); + } + }; +} + +#endif // ObjectGuid_h__ diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index b6c508e9e4c..b1bc9cc0c5d 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -1186,7 +1186,7 @@ void WorldSession::HandleInspectOpcode(WorldPacket& recvData) return; uint32 talent_points = 0x47; - uint32 guid_size = player->GetPackGUID().wpos(); + uint32 guid_size = player->GetPackGUID().size(); WorldPacket data(SMSG_INSPECT_TALENT, guid_size+4+talent_points); data.append(player->GetPackGUID()); |