diff options
author | Jared Adams <jaxad0127@gmail.com> | 2011-06-04 12:25:25 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2011-06-04 12:25:25 -0600 |
commit | e7e99051910a9a8739d8a50225be868e5dc286d6 (patch) | |
tree | a3b3cb91cc67da70be56934ce0904991a5b8b170 /src/net/tmwa/messagein.cpp | |
parent | 576dfc355cc06109da0bf07ac65fef7ab484a9cf (diff) | |
download | mana-client-e7e99051910a9a8739d8a50225be868e5dc286d6.tar.gz mana-client-e7e99051910a9a8739d8a50225be868e5dc286d6.tar.bz2 mana-client-e7e99051910a9a8739d8a50225be868e5dc286d6.tar.xz mana-client-e7e99051910a9a8739d8a50225be868e5dc286d6.zip |
Fix handling of 16- and 32-bit number in tmwAthena netcode
Diffstat (limited to 'src/net/tmwa/messagein.cpp')
-rw-r--r-- | src/net/tmwa/messagein.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index ca2d52ab..38bc14dd 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -21,6 +21,9 @@ #include "net/tmwa/messagein.h" +#include <SDL.h> +#include <SDL_endian.h> + namespace TmwAthena { MessageIn::MessageIn(const char *data, unsigned int length): @@ -35,7 +38,13 @@ uint16_t MessageIn::readInt16() uint16_t value = 0; if (mPos + 2 <= mLength) { - value = (mData[mPos + 1] << 8) | mData[mPos]; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + uint16_t swap; + memcpy(&swap, mData + mPos, sizeof(uint16_t)); + value = SDL_Swap16(swap); +#else + memcpy(&value, mData + mPos, sizeof(uint16_t)); +#endif } mPos += 2; return value; @@ -46,7 +55,13 @@ uint32_t MessageIn::readInt32() uint32_t value = 0; if (mPos + 4 <= mLength) { - value = (mData[mPos + 3] << 24) | (mData[mPos + 2] << 16) | (mData[mPos + 1] << 8) | mData[mPos]; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + uint32_t swap; + memcpy(&swap, mData + mPos, sizeof(uint32_t)); + value = SDL_Swap32(swap); +#else + memcpy(&value, mData + mPos, sizeof(uint32_t)); +#endif } mPos += 4; return value; |