summaryrefslogtreecommitdiff
path: root/src/net/tmwa
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/tmwa')
-rw-r--r--src/net/tmwa/messagein.cpp28
-rw-r--r--src/net/tmwa/messagein.h4
-rw-r--r--src/net/tmwa/messageout.cpp47
-rw-r--r--src/net/tmwa/messageout.h10
4 files changed, 30 insertions, 59 deletions
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp
index 0074cfdd..1a860a25 100644
--- a/src/net/tmwa/messagein.cpp
+++ b/src/net/tmwa/messagein.cpp
@@ -24,10 +24,6 @@
#include <SDL.h>
#include <SDL_endian.h>
-#define MAKEWORD(low,high) \
- ((unsigned short)(((unsigned char)(low)) | \
- ((unsigned short)((unsigned char)(high))) << 8))
-
namespace TmwAthena {
MessageIn::MessageIn(const char *data, unsigned int length):
@@ -37,35 +33,23 @@ MessageIn::MessageIn(const char *data, unsigned int length):
mId = readInt16();
}
-int MessageIn::readInt16()
+Uint16 MessageIn::readInt16()
{
- Sint16 value = -1;
+ Uint16 value = 0;
if (mPos + 2 <= mLength)
{
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- Sint16 swap;
- memcpy(&swap, mData + mPos, sizeof(Sint16));
- value = SDL_Swap16(swap);
-#else
- memcpy(&value, mData + mPos, sizeof(Sint16));
-#endif
+ value = (mData[mPos + 1] << 8) | mData[mPos];
}
mPos += 2;
return value;
}
-int MessageIn::readInt32()
+Uint32 MessageIn::readInt32()
{
- Sint32 value = -1;
+ Uint32 value = 0;
if (mPos + 4 <= mLength)
{
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- Sint32 swap;
- memcpy(&swap, mData + mPos, sizeof(Sint32));
- value = SDL_Swap32(swap);
-#else
- memcpy(&value, mData + mPos, sizeof(Sint32));
-#endif
+ value = (mData[mPos + 3] << 24) | (mData[mPos + 2] << 16) | (mData[mPos + 1] << 8) | mData[mPos];
}
mPos += 4;
return value;
diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h
index 13d6adf5..21375257 100644
--- a/src/net/tmwa/messagein.h
+++ b/src/net/tmwa/messagein.h
@@ -39,8 +39,8 @@ namespace TmwAthena {
public:
MessageIn(const char *data, unsigned int length);
- int readInt16(); /**< Reads a short. */
- int readInt32(); /**< Reads a long. */
+ Uint16 readInt16(); /**< Reads a short. */
+ Uint32 readInt32(); /**< Reads a "long". */
};
}
diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp
index 8b407c47..71b8f756 100644
--- a/src/net/tmwa/messageout.cpp
+++ b/src/net/tmwa/messageout.cpp
@@ -31,7 +31,7 @@
namespace TmwAthena {
-MessageOut::MessageOut(short id):
+MessageOut::MessageOut(Uint16 id):
Net::MessageOut(id)
{
mNetwork = TmwAthena::Network::instance();
@@ -44,52 +44,39 @@ void MessageOut::expand(size_t bytes)
mNetwork->mOutSize += bytes;
}
-void MessageOut::writeInt16(Sint16 value)
+void MessageOut::writeInt16(Uint16 value)
{
expand(2);
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- Sint16 swap=SDL_Swap16(value);
- memcpy(mData + mPos, &swap, sizeof(Sint16));
-#else
- memcpy(mData + mPos, &value, sizeof(Sint16));
-#endif
+ mData[mPos] = value;
+ mData[mPos + 1] = value >> 8;
mPos += 2;
}
-void MessageOut::writeInt32(Sint32 value)
+void MessageOut::writeInt32(Uint32 value)
{
expand(4);
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- Sint32 swap=SDL_Swap32(value);
- memcpy(mData + mPos, &swap, sizeof(Sint32));
-#else
- memcpy(mData + mPos, &value, sizeof(Sint32));
-#endif
+ mData[mPos] = value;
+ mData[mPos + 1] = value >> 8;
+ mData[mPos + 2] = value >> 16;
+ mData[mPos + 3] = value >> 24;
mPos += 4;
}
-#define LOBYTE(w) ((unsigned char)(w))
-#define HIBYTE(w) ((unsigned char)(((unsigned short)(w)) >> 8))
-
-void MessageOut::writeCoordinates(unsigned short x, unsigned short y,
- unsigned char direction)
+void MessageOut::writeCoordinates(Uint16 x, Uint16 y, Uint8 direction)
{
char *data = mData + mPos;
mNetwork->mOutSize += 3;
mPos += 3;
- short temp;
- temp = x;
+ Uint16 temp = x;
temp <<= 6;
- data[0] = 0;
- data[1] = 1;
- data[2] = 2;
- data[0] = HIBYTE(temp);
- data[1] = (unsigned char) temp;
+ data[0] = temp >> 8;
+ data[1] = temp;
+
temp = y;
temp <<= 4;
- data[1] |= HIBYTE(temp);
- data[2] = LOBYTE(temp);
+ data[1] |= temp << 8;
+ data[2] = temp;
// Translate direction to eAthena format
switch (direction)
@@ -120,7 +107,7 @@ void MessageOut::writeCoordinates(unsigned short x, unsigned short y,
break;
default:
// OOPSIE! Impossible or unknown
- direction = (unsigned char) -1;
+ direction = 15;
}
data[2] |= direction;
}
diff --git a/src/net/tmwa/messageout.h b/src/net/tmwa/messageout.h
index 34958e82..3a6f34a9 100644
--- a/src/net/tmwa/messageout.h
+++ b/src/net/tmwa/messageout.h
@@ -39,16 +39,16 @@ class Network;
class MessageOut : public Net::MessageOut
{
public:
- MessageOut(short id);
+ MessageOut(Uint16 id);
- void writeInt16(Sint16 value); /**< Writes a short. */
- void writeInt32(Sint32 value); /**< Writes a long. */
+ void writeInt16(Uint16 value); /**< Writes a short. */
+ void writeInt32(Uint32 value); /**< Writes a "long". */
/**
* Encodes coordinates and direction in 3 bytes.
*/
- void writeCoordinates(unsigned short x, unsigned short y,
- unsigned char direction);
+ void writeCoordinates(Uint16 x, Uint16 y,
+ Uint8 direction);
private:
void expand(size_t size);