aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-12-19 19:43:06 +0100
committerOvahlord <dreadkiller@gmx.de>2024-12-20 15:34:27 +0100
commita98256c57a335e91ad93bc9f6bcd9d671877ec3d (patch)
treee7e5105505c066f4914bdffa9e10756b8104ff66
parent744a435f447415dd8bf2a3889d0c1d149c9c78f7 (diff)
Core/PacketIO: Fixed endian conversions for array operations
(cherry picked from commit 736836a3f5307c9cdf5f843893ff9d144efa69d1)
-rw-r--r--src/server/shared/Packets/ByteBuffer.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index 2f59f0db873..0f9d3f753d3 100644
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -457,7 +457,11 @@ class TC_SHARED_API ByteBuffer
void read(T* dest, size_t count)
{
static_assert(std::is_trivially_copyable_v<T>, "read(T*, size_t) must be used with trivially copyable types");
- return read(reinterpret_cast<uint8*>(dest), count * sizeof(T));
+ read(reinterpret_cast<uint8*>(dest), count * sizeof(T));
+#if TRINITY_ENDIAN == TRINITY_BIGENDIAN
+ for (size_t i = 0; i < count; ++i)
+ EndianConvert(dest[i]);
+#endif
}
void read(uint8* dest, size_t len)
@@ -556,7 +560,12 @@ class TC_SHARED_API ByteBuffer
template <typename T>
void append(T const* src, size_t cnt)
{
- return append(reinterpret_cast<uint8 const*>(src), cnt * sizeof(T));
+#if TRINITY_ENDIAN == TRINITY_LITTLEENDIAN
+ append(reinterpret_cast<uint8 const*>(src), cnt * sizeof(T));
+#else
+ for (size_t i = 0; i < cnt; ++i)
+ append<T>(src[i]);
+#endif
}
void append(uint8 const* src, size_t cnt);