diff --git a/src/network/net_message.cpp b/src/network/net_message.cpp index 3039d4f54f..69c508f291 100644 --- a/src/network/net_message.cpp +++ b/src/network/net_message.cpp @@ -46,28 +46,32 @@ size_t serialize32(unsigned char *buf, uint32_t data) { if (buf) { - *reinterpret_cast(buf) = htonl(data); + uint32_t val = htonl(data); + memcpy(buf, &val, sizeof(val)); } return sizeof(data); } size_t serialize32(unsigned char *buf, int32_t data) { if (buf) { - *reinterpret_cast(buf) = htonl(data); + int32_t val = htonl(data); + memcpy(buf, &val, sizeof(val)); } return sizeof(data); } size_t serialize16(unsigned char *buf, uint16_t data) { if (buf) { - *reinterpret_cast(buf) = htons(data); + uint16_t val = htons(data); + memcpy(buf, &val, sizeof(val)); } return sizeof(data); } size_t serialize16(unsigned char *buf, int16_t data) { if (buf) { - *reinterpret_cast(buf) = htons(data); + int16_t val = htons(data); + memcpy(buf, &val, sizeof(val)); } return sizeof(data); } @@ -136,22 +140,26 @@ size_t serialize(unsigned char *buf, const std::vector &data) size_t deserialize32(const unsigned char *buf, uint32_t *data) { - *data = ntohl(*reinterpret_cast(buf)); + memcpy(data, buf, sizeof(*data)); + *data = ntohl(*data); return sizeof(*data); } size_t deserialize32(const unsigned char *buf, int32_t *data) { - *data = ntohl(*reinterpret_cast(buf)); + memcpy(data, buf, sizeof(*data)); + *data = ntohl(*data); return sizeof(*data); } size_t deserialize16(const unsigned char *buf, uint16_t *data) { - *data = ntohs(*reinterpret_cast(buf)); + memcpy(data, buf, sizeof(*data)); + *data = ntohs(*data); return sizeof(*data); } size_t deserialize16(const unsigned char *buf, int16_t *data) { - *data = ntohs(*reinterpret_cast(buf)); + memcpy(data, buf, sizeof(*data)); + *data = ntohs(*data); return sizeof(*data); } size_t deserialize8(const unsigned char *buf, uint8_t *data) @@ -285,7 +293,7 @@ size_t CServerSetup::Deserialize(const unsigned char *p) p += deserialize8(p, reinterpret_cast(&this->ServerGameSettings.Resources)); p += deserialize8(p, reinterpret_cast(&this->ServerGameSettings.RevealMap)); // The bitfield contains Inside and NoFogOfWar, as well as game-defined settings - p += deserialize32(p, reinterpret_cast(&this->ServerGameSettings._Bitfield)); + p += deserialize32(p, &this->ServerGameSettings._Bitfield); for (int i = 0; i < PlayerMax; ++i) { p += deserialize8(p, reinterpret_cast(&this->ServerGameSettings.Presets[i].Race)); diff --git a/src/network/online_service.cpp b/src/network/online_service.cpp index a118b13e5e..ffe76052f4 100644 --- a/src/network/online_service.cpp +++ b/src/network/online_service.cpp @@ -356,20 +356,19 @@ class BNCSOutputStream { void serialize32(uint32_t data) { ensureSpace(sizeof(data)); - uint32_t *view = reinterpret_cast(buf + pos); - *view = htonl(data); + uint32_t val = htonl(data); + memcpy(buf + pos, &val, sizeof(val)); pos += sizeof(data); }; void serialize32NativeByteOrder(uint32_t data) { ensureSpace(sizeof(data)); - uint32_t *view = reinterpret_cast(buf + pos); - *view = data; + memcpy(buf + pos, &data, sizeof(data)); pos += sizeof(data); }; void serialize16(uint16_t data) { ensureSpace(sizeof(data)); - uint16_t *view = reinterpret_cast(buf + pos); - *view = htons(data); + uint16_t val = htons(data); + memcpy(buf + pos, &val, sizeof(val)); pos += sizeof(data); }; void serialize8(uint8_t data) { @@ -404,8 +403,8 @@ class BNCSOutputStream { uint8_t *getBuffer() { // if needed, insert length to make it a valid buffer if (length_pos >= 0) { - uint16_t *view = reinterpret_cast(buf + length_pos); - *view = pos; + uint16_t val = pos; + memcpy(buf + length_pos, &val, sizeof(val)); } return buf; }; @@ -1399,7 +1398,8 @@ class Context : public OnlineContext { // (UINT32) 0x05 0x00 0x00 0x00 // (UINT32) UDP Code { - const uint32_t udpCode = reinterpret_cast(buffer)[1]; + uint32_t udpCode; + memcpy(&udpCode, buffer + (sizeof(uint32_t) / sizeof(uint8_t)), sizeof(udpCode)); BNCSOutputStream udppingresponse(0x14); udppingresponse.serialize32(udpCode); udppingresponse.flush(getTCPSocket()); diff --git a/src/pathfinder/astar.cpp b/src/pathfinder/astar.cpp index 57520ba48e..799c2af991 100644 --- a/src/pathfinder/astar.cpp +++ b/src/pathfinder/astar.cpp @@ -28,6 +28,19 @@ // 02111-1307, USA. // +// timfel: How to debug the pathfinder. +// In debug builds, there is a lua function "DumpNextAStar". The way I use this +// is to enter a game with stdout redirected to a file (that's the default on +// Windows), make sure nothing is moving, then hit "Return/Enter" to write a +// cheat code, and then type "eval DumpNextAStar()". Then send a unit somewhere. +// Next, open the stdout file using "less -R -z64 stdout.txt". Replace the "64" +// with the height of your map. The entire map will have been dumped using RGB colors +// to stdout. I use the arrow keys to position the first line of the first A* +// iteration at the top of my terminal, and then hit "Space" repeatedly. If the +// "-z64" argument used the correct map height and the terminal is wide enough, +// each time I hit space, it will scroll exactly far enough to have the next A* +// iteration first line at the top of my terminal, giving a sort of poor animation. + //@{ /*----------------------------------------------------------------------------