[8001] Fixed display id checks for creature case. Author: VladimirMangos
--HG-- branch : trunk
This commit is contained in:
+55
-17
@@ -36,11 +36,13 @@ class ByteBuffer
|
|||||||
{
|
{
|
||||||
_storage.reserve(DEFAULT_SIZE);
|
_storage.reserve(DEFAULT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
ByteBuffer(size_t res): _rpos(0), _wpos(0)
|
ByteBuffer(size_t res): _rpos(0), _wpos(0)
|
||||||
{
|
{
|
||||||
_storage.reserve(res);
|
_storage.reserve(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy constructor
|
// copy constructor
|
||||||
ByteBuffer(const ByteBuffer &buf): _rpos(buf._rpos), _wpos(buf._wpos), _storage(buf._storage) { }
|
ByteBuffer(const ByteBuffer &buf): _rpos(buf._rpos), _wpos(buf._wpos), _storage(buf._storage) { }
|
||||||
|
|
||||||
@@ -67,16 +69,19 @@ class ByteBuffer
|
|||||||
append<uint8>(value);
|
append<uint8>(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator<<(uint16 value)
|
ByteBuffer &operator<<(uint16 value)
|
||||||
{
|
{
|
||||||
append<uint16>(value);
|
append<uint16>(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator<<(uint32 value)
|
ByteBuffer &operator<<(uint32 value)
|
||||||
{
|
{
|
||||||
append<uint32>(value);
|
append<uint32>(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator<<(uint64 value)
|
ByteBuffer &operator<<(uint64 value)
|
||||||
{
|
{
|
||||||
append<uint64>(value);
|
append<uint64>(value);
|
||||||
@@ -89,16 +94,19 @@ class ByteBuffer
|
|||||||
append<int8>(value);
|
append<int8>(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator<<(int16 value)
|
ByteBuffer &operator<<(int16 value)
|
||||||
{
|
{
|
||||||
append<int16>(value);
|
append<int16>(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator<<(int32 value)
|
ByteBuffer &operator<<(int32 value)
|
||||||
{
|
{
|
||||||
append<int32>(value);
|
append<int32>(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator<<(int64 value)
|
ByteBuffer &operator<<(int64 value)
|
||||||
{
|
{
|
||||||
append<int64>(value);
|
append<int64>(value);
|
||||||
@@ -111,17 +119,20 @@ class ByteBuffer
|
|||||||
append<float>(value);
|
append<float>(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator<<(double value)
|
ByteBuffer &operator<<(double value)
|
||||||
{
|
{
|
||||||
append<double>(value);
|
append<double>(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator<<(const std::string &value)
|
ByteBuffer &operator<<(const std::string &value)
|
||||||
{
|
{
|
||||||
append((uint8 const *)value.c_str(), value.length());
|
append((uint8 const *)value.c_str(), value.length());
|
||||||
append((uint8)0);
|
append((uint8)0);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator<<(const char *str)
|
ByteBuffer &operator<<(const char *str)
|
||||||
{
|
{
|
||||||
append((uint8 const *)str, str ? strlen(str) : 0);
|
append((uint8 const *)str, str ? strlen(str) : 0);
|
||||||
@@ -140,16 +151,19 @@ class ByteBuffer
|
|||||||
value = read<uint8>();
|
value = read<uint8>();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator>>(uint16 &value)
|
ByteBuffer &operator>>(uint16 &value)
|
||||||
{
|
{
|
||||||
value = read<uint16>();
|
value = read<uint16>();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator>>(uint32 &value)
|
ByteBuffer &operator>>(uint32 &value)
|
||||||
{
|
{
|
||||||
value = read<uint32>();
|
value = read<uint32>();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator>>(uint64 &value)
|
ByteBuffer &operator>>(uint64 &value)
|
||||||
{
|
{
|
||||||
value = read<uint64>();
|
value = read<uint64>();
|
||||||
@@ -162,16 +176,19 @@ class ByteBuffer
|
|||||||
value = read<int8>();
|
value = read<int8>();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator>>(int16 &value)
|
ByteBuffer &operator>>(int16 &value)
|
||||||
{
|
{
|
||||||
value = read<int16>();
|
value = read<int16>();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator>>(int32 &value)
|
ByteBuffer &operator>>(int32 &value)
|
||||||
{
|
{
|
||||||
value = read<int32>();
|
value = read<int32>();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator>>(int64 &value)
|
ByteBuffer &operator>>(int64 &value)
|
||||||
{
|
{
|
||||||
value = read<int64>();
|
value = read<int64>();
|
||||||
@@ -183,11 +200,13 @@ class ByteBuffer
|
|||||||
value = read<float>();
|
value = read<float>();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator>>(double &value)
|
ByteBuffer &operator>>(double &value)
|
||||||
{
|
{
|
||||||
value = read<double>();
|
value = read<double>();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer &operator>>(std::string& value)
|
ByteBuffer &operator>>(std::string& value)
|
||||||
{
|
{
|
||||||
value.clear();
|
value.clear();
|
||||||
@@ -212,7 +231,7 @@ class ByteBuffer
|
|||||||
{
|
{
|
||||||
_rpos = rpos_;
|
_rpos = rpos_;
|
||||||
return _rpos;
|
return _rpos;
|
||||||
};
|
}
|
||||||
|
|
||||||
size_t wpos() const { return _wpos; }
|
size_t wpos() const { return _wpos; }
|
||||||
|
|
||||||
@@ -227,7 +246,8 @@ class ByteBuffer
|
|||||||
T r = read<T>(_rpos);
|
T r = read<T>(_rpos);
|
||||||
_rpos += sizeof(T);
|
_rpos += sizeof(T);
|
||||||
return r;
|
return r;
|
||||||
};
|
}
|
||||||
|
|
||||||
template <typename T> T read(size_t pos) const
|
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)));
|
||||||
@@ -253,7 +273,7 @@ class ByteBuffer
|
|||||||
uint8 guidmark = 0;
|
uint8 guidmark = 0;
|
||||||
(*this) >> guidmark;
|
(*this) >> guidmark;
|
||||||
|
|
||||||
for(int i=0;i<8;i++)
|
for(int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
if(guidmark & (uint8(1) << i))
|
if(guidmark & (uint8(1) << i))
|
||||||
{
|
{
|
||||||
@@ -279,28 +299,33 @@ class ByteBuffer
|
|||||||
_storage.resize(newsize);
|
_storage.resize(newsize);
|
||||||
_rpos = 0;
|
_rpos = 0;
|
||||||
_wpos = size();
|
_wpos = size();
|
||||||
};
|
}
|
||||||
|
|
||||||
void reserve(size_t ressize)
|
void reserve(size_t ressize)
|
||||||
{
|
{
|
||||||
if (ressize > size()) _storage.reserve(ressize);
|
if (ressize > size())
|
||||||
};
|
_storage.reserve(ressize);
|
||||||
|
}
|
||||||
|
|
||||||
void append(const std::string& str)
|
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)
|
void append(const char *src, size_t cnt)
|
||||||
{
|
{
|
||||||
return append((const uint8 *)src, 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)
|
void append(const uint8 *src, size_t cnt)
|
||||||
{
|
{
|
||||||
if (!cnt) return;
|
if (!cnt)
|
||||||
|
return;
|
||||||
|
|
||||||
ASSERT(size() < 10000000);
|
ASSERT(size() < 10000000);
|
||||||
|
|
||||||
@@ -309,9 +334,21 @@ class ByteBuffer
|
|||||||
memcpy(&_storage[_wpos], src, cnt);
|
memcpy(&_storage[_wpos], src, cnt);
|
||||||
_wpos += cnt;
|
_wpos += cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void append(const ByteBuffer& buffer)
|
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)
|
void appendPackGUID(uint64 guid)
|
||||||
@@ -321,7 +358,7 @@ class ByteBuffer
|
|||||||
|
|
||||||
size_t mask_position = wpos();
|
size_t mask_position = wpos();
|
||||||
*this << uint8(0);
|
*this << uint8(0);
|
||||||
for(uint8 i = 0; i < 8; i++)
|
for(uint8 i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
if(guid & 0xFF)
|
if(guid & 0xFF)
|
||||||
{
|
{
|
||||||
@@ -338,13 +375,14 @@ class ByteBuffer
|
|||||||
ASSERT(pos + cnt <= size() || PrintPosError(true, pos, cnt));
|
ASSERT(pos + cnt <= size() || PrintPosError(true, pos, cnt));
|
||||||
memcpy(&_storage[pos], src, cnt);
|
memcpy(&_storage[pos], src, cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_storage() const
|
void print_storage() const
|
||||||
{
|
{
|
||||||
if(!sLog.IsOutDebug()) // optimize disabled debug output
|
if(!sLog.IsOutDebug()) // optimize disabled debug output
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sLog.outDebug("STORAGE_SIZE: %lu", (unsigned long)size() );
|
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.outDebugInLine("%u - ", read<uint8>(i) );
|
||||||
sLog.outDebug(" ");
|
sLog.outDebug(" ");
|
||||||
}
|
}
|
||||||
@@ -355,7 +393,7 @@ class ByteBuffer
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
sLog.outDebug("STORAGE_SIZE: %lu", (unsigned long)size() );
|
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.outDebugInLine("%c", read<uint8>(i) );
|
||||||
sLog.outDebug(" ");
|
sLog.outDebug(" ");
|
||||||
}
|
}
|
||||||
@@ -368,7 +406,7 @@ class ByteBuffer
|
|||||||
uint32 j = 1, k = 1;
|
uint32 j = 1, k = 1;
|
||||||
sLog.outDebug("STORAGE_SIZE: %lu", (unsigned long)size() );
|
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))))
|
||||||
{
|
{
|
||||||
@@ -431,7 +469,7 @@ class ByteBuffer
|
|||||||
template <typename T> ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v)
|
template <typename T> ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v)
|
||||||
{
|
{
|
||||||
b << (uint32)v.size();
|
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;
|
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)
|
template <typename T> ByteBuffer &operator<<(ByteBuffer &b, std::list<T> v)
|
||||||
{
|
{
|
||||||
b << (uint32)v.size();
|
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;
|
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)
|
template <typename K, typename V> ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m)
|
||||||
{
|
{
|
||||||
b << (uint32)m.size();
|
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;
|
b << i->first << i->second;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user