From 92c59963f82f81aa3202657e7fdbb2592924ede3 Mon Sep 17 00:00:00 2001 From: "cedeel@gmail.com" Date: Thu, 14 Jun 2012 13:06:06 +0000 Subject: Attempt to bring sanity to newlines across systems. git-svn-id: http://mc-server.googlecode.com/svn/trunk@606 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/packets/cPacket.cpp | 614 ++++++++++----------- source/packets/cPacket.h | 188 +++---- source/packets/cPacket_13.cpp | 40 +- source/packets/cPacket_13.h | 68 +-- source/packets/cPacket_AddToInventory.cpp | 40 +- source/packets/cPacket_AddToInventory.h | 52 +- source/packets/cPacket_ArmAnim.cpp | 62 +-- source/packets/cPacket_ArmAnim.h | 40 +- source/packets/cPacket_BlockChange.cpp | 44 +- source/packets/cPacket_BlockChange.h | 52 +- source/packets/cPacket_BlockDig.cpp | 72 +-- source/packets/cPacket_BlockDig.h | 64 +-- source/packets/cPacket_BlockPlace.cpp | 72 +-- source/packets/cPacket_BlockPlace.h | 80 +-- source/packets/cPacket_Chat.cpp | 58 +- source/packets/cPacket_Chat.h | 44 +- source/packets/cPacket_CollectItem.cpp | 38 +- source/packets/cPacket_CollectItem.h | 54 +- source/packets/cPacket_CreativeInventoryAction.cpp | 134 ++--- source/packets/cPacket_DestroyEntity.cpp | 60 +- source/packets/cPacket_DestroyEntity.h | 66 +-- source/packets/cPacket_Disconnect.cpp | 58 +- source/packets/cPacket_Disconnect.h | 52 +- source/packets/cPacket_EntityEquipment.cpp | 96 ++-- source/packets/cPacket_EntityEquipment.h | 68 +-- source/packets/cPacket_EntityLook.cpp | 128 ++--- source/packets/cPacket_EntityLook.h | 118 ++-- source/packets/cPacket_EntityStatus.cpp | 38 +- source/packets/cPacket_EntityStatus.h | 62 +-- source/packets/cPacket_Flying.cpp | 38 +- source/packets/cPacket_Flying.h | 54 +- source/packets/cPacket_Handshake.cpp | 58 +- source/packets/cPacket_Handshake.h | 50 +- source/packets/cPacket_InventoryProgressBar.cpp | 40 +- source/packets/cPacket_InventoryProgressBar.h | 62 +-- source/packets/cPacket_InventorySlot.cpp | 46 +- source/packets/cPacket_InventorySlot.h | 88 +-- source/packets/cPacket_ItemData.cpp | 162 +++--- source/packets/cPacket_ItemData.h | 68 +-- source/packets/cPacket_ItemSwitch.cpp | 58 +- source/packets/cPacket_ItemSwitch.h | 56 +- source/packets/cPacket_KeepAlive.cpp | 58 +- source/packets/cPacket_KeepAlive.h | 54 +- source/packets/cPacket_Login.cpp | 104 ++-- source/packets/cPacket_Login.h | 84 +-- source/packets/cPacket_MapChunk.cpp | 308 +++++------ source/packets/cPacket_MapChunk.h | 90 +-- source/packets/cPacket_MultiBlock.cpp | 100 ++-- source/packets/cPacket_MultiBlock.h | 94 ++-- source/packets/cPacket_NamedEntitySpawn.cpp | 68 +-- source/packets/cPacket_NamedEntitySpawn.h | 80 +-- source/packets/cPacket_PickupSpawn.cpp | 94 ++-- source/packets/cPacket_PickupSpawn.h | 92 +-- source/packets/cPacket_Ping.h | 48 +- source/packets/cPacket_Player.cpp | 486 ++++++++-------- source/packets/cPacket_Player.h | 300 +++++----- source/packets/cPacket_PreChunk.cpp | 40 +- source/packets/cPacket_PreChunk.h | 72 +-- source/packets/cPacket_RelativeEntityMove.cpp | 42 +- source/packets/cPacket_RelativeEntityMove.h | 66 +-- source/packets/cPacket_RelativeEntityMoveLook.cpp | 48 +- source/packets/cPacket_RelativeEntityMoveLook.h | 74 +-- source/packets/cPacket_Respawn.cpp | 78 +-- source/packets/cPacket_Respawn.h | 74 +-- source/packets/cPacket_SpawnMob.cpp | 150 ++--- source/packets/cPacket_SpawnMob.h | 78 +-- source/packets/cPacket_TeleportEntity.cpp | 82 +-- source/packets/cPacket_TeleportEntity.h | 78 +-- source/packets/cPacket_TimeUpdate.cpp | 58 +- source/packets/cPacket_TimeUpdate.h | 58 +- source/packets/cPacket_UpdateHealth.cpp | 40 +- source/packets/cPacket_UpdateHealth.h | 64 +-- source/packets/cPacket_UpdateSign.cpp | 82 +-- source/packets/cPacket_UpdateSign.h | 72 +-- source/packets/cPacket_UseEntity.cpp | 42 +- source/packets/cPacket_UseEntity.h | 62 +-- source/packets/cPacket_WholeInventory.cpp | 152 ++--- source/packets/cPacket_WholeInventory.h | 94 ++-- source/packets/cPacket_WindowClick.cpp | 86 +-- source/packets/cPacket_WindowClick.h | 104 ++-- source/packets/cPacket_WindowClose.cpp | 58 +- source/packets/cPacket_WindowClose.h | 56 +- source/packets/cPacket_WindowOpen.cpp | 42 +- source/packets/cPacket_WindowOpen.h | 64 +-- 84 files changed, 3709 insertions(+), 3709 deletions(-) (limited to 'source/packets') diff --git a/source/packets/cPacket.cpp b/source/packets/cPacket.cpp index ec7181762..6fad331ed 100644 --- a/source/packets/cPacket.cpp +++ b/source/packets/cPacket.cpp @@ -1,307 +1,307 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket.h" -#include "../Endianness.h" - - - - - -/* -// These checks cannot be done in preprocessor, since sizeof() is evaluated while compiling, so in preprocessing it's unknown. -// Check some basic type assumptions: -#if (sizeof(int) != 4) - #error "Bad size for int, protocol won't work" -#endif - -#if (sizeof(float) != 4) - #error "Bad size for float, protocol won't work" -#endif - -#if (sizeof(double) != 8) - #error "Bad size for double, protocol won't work" -#endif -*/ - - - - - -int cPacket::ReadString16(const char * a_Data, int a_Size, AString & a_OutString ) -{ - int TotalBytes = 0; - short StrLen; - HANDLE_PACKET_READ(ReadShort, StrLen, TotalBytes); - - if (2 * StrLen > a_Size - TotalBytes) - { - // The string is not yet complete in the buffer - return PACKET_INCOMPLETE; - } - - // Simple UTF-16 to UTF-8 conversion - discard higher bits, ignore multishort sequences: - a_OutString.clear(); - a_OutString.reserve(StrLen); - short * UTF16 = (short *)(a_Data + TotalBytes); - for ( int i = 0; i < StrLen; ++i ) - { - a_OutString.push_back( (char)ntohs(UTF16[i]) ); - } - - return TotalBytes + StrLen * sizeof(short); -} - - - - - -int cPacket::ReadShort(const char * a_Data, int a_Size, short & a_OutShort ) -{ - if (a_Size < 2) - { - return PACKET_INCOMPLETE; - } - a_OutShort = ntohs(*((short *)a_Data)); - return 2; -} - - - - - -int cPacket::ReadInteger(const char * a_Data, int a_Size, int & a_OutInteger ) -{ - if (a_Size < 4) - { - return PACKET_INCOMPLETE; - } - a_OutInteger = ntohl(*((int *)a_Data)); - return 4; -} - - - - - -int cPacket::ReadInteger(const char * a_Data, int a_Size, unsigned int & a_OutInteger ) -{ - if (a_Size < 4) - { - return PACKET_INCOMPLETE; - } - a_OutInteger = ntohl(*((unsigned int *)a_Data)); - return 4; -} - - - - - -int cPacket::ReadFloat(const char * a_Data, int a_Size, float & a_OutFloat ) -{ - if (a_Size < sizeof(float)) - { - return PACKET_INCOMPLETE; - } - a_OutFloat = NetworkToHostFloat4(a_Data); - return sizeof(float); -} - - - - - -int cPacket::ReadDouble(const char * a_Data, int a_Size, double & a_OutDouble ) -{ - if (a_Size < sizeof(double)) - { - return PACKET_INCOMPLETE; - } - a_OutDouble = NetworkToHostDouble8(a_Data); - return sizeof(double); -} - - - - - -int cPacket::ReadByte(const char * a_Data, int a_Size, char & a_OutByte ) -{ - if (a_Size < 1) - { - return PACKET_INCOMPLETE; - } - a_OutByte = *a_Data; - return 1; -} - - - - - -int cPacket::ReadByte(const char * a_Data, int a_Size, unsigned char & a_OutByte ) -{ - if (a_Size < 1) - { - return PACKET_INCOMPLETE; - } - a_OutByte = *((unsigned char *)a_Data); - return 1; -} - - - - - -int cPacket::ReadLong(const char * a_Data, int a_Size, long long & a_OutLong ) -{ - if (a_Size < sizeof(a_OutLong)) - { - return PACKET_INCOMPLETE; - } - a_OutLong = NetworkToHostLong8(a_Data); - return sizeof(a_OutLong); -} - - - - - -int cPacket::ReadBool(const char * a_Data, int a_Size, bool & a_OutBool ) -{ - if (a_Size < sizeof(bool)) - { - return PACKET_INCOMPLETE; - } - a_OutBool = (*a_Data != 0); - return sizeof(bool); -} - - - - - -void cPacket::AppendString(AString & a_Dst, const AString & a_String) -{ - AppendShort(a_Dst, (unsigned short)a_String.size()); - a_Dst.append(a_String); -} - - - - - -void cPacket::AppendString16(AString & a_Dst, const AString & a_String) -{ - AppendShort(a_Dst, (unsigned short)a_String.size()); - AString UTF16; - UTF16.resize(a_String.size() * sizeof(short)); - for( unsigned int i = 0; i < a_String.size(); ++i ) - { - UTF16[i * sizeof( short )] = 0x00; - UTF16[i * sizeof( short ) + 1] = a_String[i]; - } - a_Dst.append(UTF16.data(), a_String.size() * sizeof(short)); -} - - - - - -void cPacket::AppendShort(AString & a_Dst, short a_Short) -{ - short ConvertedShort = htons( a_Short ); - a_Dst.append((const char *)&ConvertedShort, sizeof(short)); -} - - - - - -void cPacket::AppendShort(AString & a_Dst, unsigned short a_Short) -{ - short ConvertedShort = htons( a_Short ); - a_Dst.append((const char *)&ConvertedShort, sizeof(short)); -} - - - - - -void cPacket::AppendInteger(AString & a_Dst, int a_Integer) -{ - int ConvertedInt = htonl( a_Integer ); - a_Dst.append((const char *)&ConvertedInt, sizeof(int)); -} - - - - - -void cPacket::AppendInteger(AString & a_Dst, unsigned int a_Integer) -{ - unsigned int ConvertedInt = htonl( a_Integer ); - a_Dst.append((const char *)&ConvertedInt, sizeof(int)); -} - - - - - -void cPacket::AppendFloat(AString & a_Dst, float a_Float) -{ - unsigned int ConvertedFloat = HostToNetwork4(&a_Float); - a_Dst.append((const char *)&ConvertedFloat, sizeof(int)); -} - - - - - -void cPacket::AppendDouble(AString & a_Dst, const double & a_Double) -{ - unsigned long long ConvertedDouble = HostToNetwork8(&a_Double); - a_Dst.append((const char *)&ConvertedDouble, 8); -} - - - - - -void cPacket::AppendByte(AString & a_Dst, char a_Byte) -{ - a_Dst.append(&a_Byte, 1); -} - - - - - -void cPacket::AppendLong(AString & a_Dst, const long long & a_Long) -{ - unsigned long long ConvertedLong = HostToNetwork8(&a_Long); - a_Dst.append((const char *)&ConvertedLong, sizeof(a_Long)); -} - - - - - -void cPacket::AppendBool(AString & a_Dst, bool a_Bool) -{ - a_Dst.append((const char *)&a_Bool, 1); -} - - - - - -void cPacket::AppendData(AString & a_Dst, const char * a_Data, unsigned int a_Size) -{ - a_Dst.append(a_Data, a_Size); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket.h" +#include "../Endianness.h" + + + + + +/* +// These checks cannot be done in preprocessor, since sizeof() is evaluated while compiling, so in preprocessing it's unknown. +// Check some basic type assumptions: +#if (sizeof(int) != 4) + #error "Bad size for int, protocol won't work" +#endif + +#if (sizeof(float) != 4) + #error "Bad size for float, protocol won't work" +#endif + +#if (sizeof(double) != 8) + #error "Bad size for double, protocol won't work" +#endif +*/ + + + + + +int cPacket::ReadString16(const char * a_Data, int a_Size, AString & a_OutString ) +{ + int TotalBytes = 0; + short StrLen; + HANDLE_PACKET_READ(ReadShort, StrLen, TotalBytes); + + if (2 * StrLen > a_Size - TotalBytes) + { + // The string is not yet complete in the buffer + return PACKET_INCOMPLETE; + } + + // Simple UTF-16 to UTF-8 conversion - discard higher bits, ignore multishort sequences: + a_OutString.clear(); + a_OutString.reserve(StrLen); + short * UTF16 = (short *)(a_Data + TotalBytes); + for ( int i = 0; i < StrLen; ++i ) + { + a_OutString.push_back( (char)ntohs(UTF16[i]) ); + } + + return TotalBytes + StrLen * sizeof(short); +} + + + + + +int cPacket::ReadShort(const char * a_Data, int a_Size, short & a_OutShort ) +{ + if (a_Size < 2) + { + return PACKET_INCOMPLETE; + } + a_OutShort = ntohs(*((short *)a_Data)); + return 2; +} + + + + + +int cPacket::ReadInteger(const char * a_Data, int a_Size, int & a_OutInteger ) +{ + if (a_Size < 4) + { + return PACKET_INCOMPLETE; + } + a_OutInteger = ntohl(*((int *)a_Data)); + return 4; +} + + + + + +int cPacket::ReadInteger(const char * a_Data, int a_Size, unsigned int & a_OutInteger ) +{ + if (a_Size < 4) + { + return PACKET_INCOMPLETE; + } + a_OutInteger = ntohl(*((unsigned int *)a_Data)); + return 4; +} + + + + + +int cPacket::ReadFloat(const char * a_Data, int a_Size, float & a_OutFloat ) +{ + if (a_Size < sizeof(float)) + { + return PACKET_INCOMPLETE; + } + a_OutFloat = NetworkToHostFloat4(a_Data); + return sizeof(float); +} + + + + + +int cPacket::ReadDouble(const char * a_Data, int a_Size, double & a_OutDouble ) +{ + if (a_Size < sizeof(double)) + { + return PACKET_INCOMPLETE; + } + a_OutDouble = NetworkToHostDouble8(a_Data); + return sizeof(double); +} + + + + + +int cPacket::ReadByte(const char * a_Data, int a_Size, char & a_OutByte ) +{ + if (a_Size < 1) + { + return PACKET_INCOMPLETE; + } + a_OutByte = *a_Data; + return 1; +} + + + + + +int cPacket::ReadByte(const char * a_Data, int a_Size, unsigned char & a_OutByte ) +{ + if (a_Size < 1) + { + return PACKET_INCOMPLETE; + } + a_OutByte = *((unsigned char *)a_Data); + return 1; +} + + + + + +int cPacket::ReadLong(const char * a_Data, int a_Size, long long & a_OutLong ) +{ + if (a_Size < sizeof(a_OutLong)) + { + return PACKET_INCOMPLETE; + } + a_OutLong = NetworkToHostLong8(a_Data); + return sizeof(a_OutLong); +} + + + + + +int cPacket::ReadBool(const char * a_Data, int a_Size, bool & a_OutBool ) +{ + if (a_Size < sizeof(bool)) + { + return PACKET_INCOMPLETE; + } + a_OutBool = (*a_Data != 0); + return sizeof(bool); +} + + + + + +void cPacket::AppendString(AString & a_Dst, const AString & a_String) +{ + AppendShort(a_Dst, (unsigned short)a_String.size()); + a_Dst.append(a_String); +} + + + + + +void cPacket::AppendString16(AString & a_Dst, const AString & a_String) +{ + AppendShort(a_Dst, (unsigned short)a_String.size()); + AString UTF16; + UTF16.resize(a_String.size() * sizeof(short)); + for( unsigned int i = 0; i < a_String.size(); ++i ) + { + UTF16[i * sizeof( short )] = 0x00; + UTF16[i * sizeof( short ) + 1] = a_String[i]; + } + a_Dst.append(UTF16.data(), a_String.size() * sizeof(short)); +} + + + + + +void cPacket::AppendShort(AString & a_Dst, short a_Short) +{ + short ConvertedShort = htons( a_Short ); + a_Dst.append((const char *)&ConvertedShort, sizeof(short)); +} + + + + + +void cPacket::AppendShort(AString & a_Dst, unsigned short a_Short) +{ + short ConvertedShort = htons( a_Short ); + a_Dst.append((const char *)&ConvertedShort, sizeof(short)); +} + + + + + +void cPacket::AppendInteger(AString & a_Dst, int a_Integer) +{ + int ConvertedInt = htonl( a_Integer ); + a_Dst.append((const char *)&ConvertedInt, sizeof(int)); +} + + + + + +void cPacket::AppendInteger(AString & a_Dst, unsigned int a_Integer) +{ + unsigned int ConvertedInt = htonl( a_Integer ); + a_Dst.append((const char *)&ConvertedInt, sizeof(int)); +} + + + + + +void cPacket::AppendFloat(AString & a_Dst, float a_Float) +{ + unsigned int ConvertedFloat = HostToNetwork4(&a_Float); + a_Dst.append((const char *)&ConvertedFloat, sizeof(int)); +} + + + + + +void cPacket::AppendDouble(AString & a_Dst, const double & a_Double) +{ + unsigned long long ConvertedDouble = HostToNetwork8(&a_Double); + a_Dst.append((const char *)&ConvertedDouble, 8); +} + + + + + +void cPacket::AppendByte(AString & a_Dst, char a_Byte) +{ + a_Dst.append(&a_Byte, 1); +} + + + + + +void cPacket::AppendLong(AString & a_Dst, const long long & a_Long) +{ + unsigned long long ConvertedLong = HostToNetwork8(&a_Long); + a_Dst.append((const char *)&ConvertedLong, sizeof(a_Long)); +} + + + + + +void cPacket::AppendBool(AString & a_Dst, bool a_Bool) +{ + a_Dst.append((const char *)&a_Bool, 1); +} + + + + + +void cPacket::AppendData(AString & a_Dst, const char * a_Data, unsigned int a_Size) +{ + a_Dst.append(a_Data, a_Size); +} + + + + diff --git a/source/packets/cPacket.h b/source/packets/cPacket.h index 7eb224c9e..f5a014ed5 100644 --- a/source/packets/cPacket.h +++ b/source/packets/cPacket.h @@ -1,94 +1,94 @@ - -#pragma once - -#include "../cSocket.h" -#include "../PacketID.h" - - - - - -#define PACKET_INCOMPLETE -2 -#define PACKET_ERROR -1 - - - - - -// Use this macro to simplify handling several ReadXXX in a row. It assumes that you want [a_Data, a_Size] parsed (which is true for all Parse() functions) -#define HANDLE_PACKET_READ(Proc, Var, TotalBytes) \ - { \ - int res = Proc(a_Data + TotalBytes, a_Size - TotalBytes, Var); \ - if (res < 0) \ - { \ - return res; \ - } \ - TotalBytes += res; \ - } - - - - - -class cPacket -{ -public: - cPacket() - : m_PacketID( 0 ) - {} - virtual ~cPacket() {} - - /// Called to parse the packet. Packet type has already been read and the correct packet type created. Return the number of characters processed, PACKET_INCOMPLETE for incomplete data, PACKET_ERROR for error - virtual int Parse(const char * a_Data, int a_Size) - { - LOGERROR("Undefined Parse function for packet type 0x%x\n", m_PacketID ); - ASSERT(!"Undefined Parse function"); - return -1; - } - - /// Called to serialize the packet into a string. Append all packet data to a_Data, including the packet type! - virtual void Serialize(AString & a_Data) const - { - LOGERROR("Undefined Serialize function for packet type 0x%x\n", m_PacketID ); - ASSERT(!"Undefined Serialize function"); - } - - virtual cPacket * Clone() const = 0; - - unsigned char m_PacketID; - -protected: - - // These return the number of characters processed, PACKET_INCOMPLETE for incomplete data, PACKET_ERROR for error: - static int ReadString16(const char * a_Data, int a_Size, AString & a_OutString ); - static int ReadShort (const char * a_Data, int a_Size, short & a_Short ); - static int ReadInteger (const char * a_Data, int a_Size, int & a_OutInteger ); - static int ReadInteger (const char * a_Data, int a_Size, unsigned int & a_OutInteger ); - static int ReadFloat (const char * a_Data, int a_Size, float & a_OutFloat ); - static int ReadDouble (const char * a_Data, int a_Size, double & a_OutDouble ); - static int ReadByte (const char * a_Data, int a_Size, char & a_OutByte ); - static int ReadByte (const char * a_Data, int a_Size, unsigned char & a_OutByte ); - static int ReadLong (const char * a_Data, int a_Size, long long & a_OutLong ); - static int ReadBool (const char * a_Data, int a_Size, bool & a_OutBool ); - - // These append the data into the a_Dst string: - static void AppendString ( AString & a_Dst, const AString & a_String); - static void AppendString16( AString & a_Dst, const AString & a_String); - static void AppendShort ( AString & a_Dst, short a_Short); - static void AppendShort ( AString & a_Dst, unsigned short a_Short); - static void AppendInteger ( AString & a_Dst, int a_Integer); - static void AppendInteger ( AString & a_Dst, unsigned int a_Integer); - static void AppendFloat ( AString & a_Dst, float a_Float); - static void AppendDouble ( AString & a_Dst, const double & a_Double); - static void AppendByte ( AString & a_Dst, char a_Byte); - static void AppendLong ( AString & a_Dst, const long long & a_Long); - static void AppendBool ( AString & a_Dst, bool a_Bool); - static void AppendData ( AString & a_Dst, const char * a_Data, unsigned int a_Size); -}; - -typedef std::list PacketList; -typedef std::deque PacketQueue; - - - - + +#pragma once + +#include "../cSocket.h" +#include "../PacketID.h" + + + + + +#define PACKET_INCOMPLETE -2 +#define PACKET_ERROR -1 + + + + + +// Use this macro to simplify handling several ReadXXX in a row. It assumes that you want [a_Data, a_Size] parsed (which is true for all Parse() functions) +#define HANDLE_PACKET_READ(Proc, Var, TotalBytes) \ + { \ + int res = Proc(a_Data + TotalBytes, a_Size - TotalBytes, Var); \ + if (res < 0) \ + { \ + return res; \ + } \ + TotalBytes += res; \ + } + + + + + +class cPacket +{ +public: + cPacket() + : m_PacketID( 0 ) + {} + virtual ~cPacket() {} + + /// Called to parse the packet. Packet type has already been read and the correct packet type created. Return the number of characters processed, PACKET_INCOMPLETE for incomplete data, PACKET_ERROR for error + virtual int Parse(const char * a_Data, int a_Size) + { + LOGERROR("Undefined Parse function for packet type 0x%x\n", m_PacketID ); + ASSERT(!"Undefined Parse function"); + return -1; + } + + /// Called to serialize the packet into a string. Append all packet data to a_Data, including the packet type! + virtual void Serialize(AString & a_Data) const + { + LOGERROR("Undefined Serialize function for packet type 0x%x\n", m_PacketID ); + ASSERT(!"Undefined Serialize function"); + } + + virtual cPacket * Clone() const = 0; + + unsigned char m_PacketID; + +protected: + + // These return the number of characters processed, PACKET_INCOMPLETE for incomplete data, PACKET_ERROR for error: + static int ReadString16(const char * a_Data, int a_Size, AString & a_OutString ); + static int ReadShort (const char * a_Data, int a_Size, short & a_Short ); + static int ReadInteger (const char * a_Data, int a_Size, int & a_OutInteger ); + static int ReadInteger (const char * a_Data, int a_Size, unsigned int & a_OutInteger ); + static int ReadFloat (const char * a_Data, int a_Size, float & a_OutFloat ); + static int ReadDouble (const char * a_Data, int a_Size, double & a_OutDouble ); + static int ReadByte (const char * a_Data, int a_Size, char & a_OutByte ); + static int ReadByte (const char * a_Data, int a_Size, unsigned char & a_OutByte ); + static int ReadLong (const char * a_Data, int a_Size, long long & a_OutLong ); + static int ReadBool (const char * a_Data, int a_Size, bool & a_OutBool ); + + // These append the data into the a_Dst string: + static void AppendString ( AString & a_Dst, const AString & a_String); + static void AppendString16( AString & a_Dst, const AString & a_String); + static void AppendShort ( AString & a_Dst, short a_Short); + static void AppendShort ( AString & a_Dst, unsigned short a_Short); + static void AppendInteger ( AString & a_Dst, int a_Integer); + static void AppendInteger ( AString & a_Dst, unsigned int a_Integer); + static void AppendFloat ( AString & a_Dst, float a_Float); + static void AppendDouble ( AString & a_Dst, const double & a_Double); + static void AppendByte ( AString & a_Dst, char a_Byte); + static void AppendLong ( AString & a_Dst, const long long & a_Long); + static void AppendBool ( AString & a_Dst, bool a_Bool); + static void AppendData ( AString & a_Dst, const char * a_Data, unsigned int a_Size); +}; + +typedef std::list PacketList; +typedef std::deque PacketQueue; + + + + diff --git a/source/packets/cPacket_13.cpp b/source/packets/cPacket_13.cpp index aebef4410..4edeb8c95 100644 --- a/source/packets/cPacket_13.cpp +++ b/source/packets/cPacket_13.cpp @@ -1,20 +1,20 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_13.h" - - - - - -int cPacket_13::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_EntityID, TotalBytes); - HANDLE_PACKET_READ(ReadByte , m_ActionID, TotalBytes); - return TotalBytes; -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_13.h" + + + + + +int cPacket_13::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadInteger, m_EntityID, TotalBytes); + HANDLE_PACKET_READ(ReadByte , m_ActionID, TotalBytes); + return TotalBytes; +} + + + + diff --git a/source/packets/cPacket_13.h b/source/packets/cPacket_13.h index 361e35fe7..d0a257302 100644 --- a/source/packets/cPacket_13.h +++ b/source/packets/cPacket_13.h @@ -1,34 +1,34 @@ -#pragma once - -#include "cPacket.h" - - -class cPacket_13 : public cPacket -{ -public: - enum ENUM_ACTION - { - ACTION_CROUCH = 1, - ACTION_UNCROUCH = 2, - ACTION_LEAVEBED = 3, - ACTION_STARTSPRINTING = 4, - ACTION_STOPSPRINTING = 5, - }; - - cPacket_13() - : m_EntityID( 0 ) - , m_ActionID( 0 ) - { m_PacketID = E_PACKET_13; } - virtual cPacket* Clone() const { return new cPacket_13( *this ); } - - virtual int Parse(const char * a_Data, int a_Size) override; - - int m_EntityID; - char m_ActionID; - - static const unsigned int c_Size = 1; -}; - - - - +#pragma once + +#include "cPacket.h" + + +class cPacket_13 : public cPacket +{ +public: + enum ENUM_ACTION + { + ACTION_CROUCH = 1, + ACTION_UNCROUCH = 2, + ACTION_LEAVEBED = 3, + ACTION_STARTSPRINTING = 4, + ACTION_STOPSPRINTING = 5, + }; + + cPacket_13() + : m_EntityID( 0 ) + , m_ActionID( 0 ) + { m_PacketID = E_PACKET_13; } + virtual cPacket* Clone() const { return new cPacket_13( *this ); } + + virtual int Parse(const char * a_Data, int a_Size) override; + + int m_EntityID; + char m_ActionID; + + static const unsigned int c_Size = 1; +}; + + + + diff --git a/source/packets/cPacket_AddToInventory.cpp b/source/packets/cPacket_AddToInventory.cpp index c8606afe0..b9231112c 100644 --- a/source/packets/cPacket_AddToInventory.cpp +++ b/source/packets/cPacket_AddToInventory.cpp @@ -1,20 +1,20 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_AddToInventory.h" -#include "cPacket_WholeInventory.h" -#include "cPacket_ItemData.h" - - - - - -void cPacket_AddToInventory::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - cPacket_ItemData::AppendItem(a_Data, m_ItemType, m_Count, m_Life); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_AddToInventory.h" +#include "cPacket_WholeInventory.h" +#include "cPacket_ItemData.h" + + + + + +void cPacket_AddToInventory::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + cPacket_ItemData::AppendItem(a_Data, m_ItemType, m_Count, m_Life); +} + + + + diff --git a/source/packets/cPacket_AddToInventory.h b/source/packets/cPacket_AddToInventory.h index 4317607a5..f7e1a084b 100644 --- a/source/packets/cPacket_AddToInventory.h +++ b/source/packets/cPacket_AddToInventory.h @@ -1,26 +1,26 @@ -#pragma once - -#include "cPacket.h" - -#include "../BlockID.h" - -class cPacket_AddToInventory : public cPacket -{ -public: - cPacket_AddToInventory() - : m_ItemType( E_ITEM_EMPTY ) - , m_Count( 0 ) - , m_Life( 0 ) - { m_PacketID = E_ADD_TO_INV; } - virtual cPacket* Clone() const { return new cPacket_AddToInventory(*this); } - - // _X: This was unimplemented, do we need it?: - // bool Parse( cSocket & a_Socket ); - - virtual void Serialize(AString & a_Data) const override; - - ENUM_ITEM_ID m_ItemType; - char m_Count; - short m_Life; - static const unsigned int c_Size = 1; -}; +#pragma once + +#include "cPacket.h" + +#include "../BlockID.h" + +class cPacket_AddToInventory : public cPacket +{ +public: + cPacket_AddToInventory() + : m_ItemType( E_ITEM_EMPTY ) + , m_Count( 0 ) + , m_Life( 0 ) + { m_PacketID = E_ADD_TO_INV; } + virtual cPacket* Clone() const { return new cPacket_AddToInventory(*this); } + + // _X: This was unimplemented, do we need it?: + // bool Parse( cSocket & a_Socket ); + + virtual void Serialize(AString & a_Data) const override; + + ENUM_ITEM_ID m_ItemType; + char m_Count; + short m_Life; + static const unsigned int c_Size = 1; +}; diff --git a/source/packets/cPacket_ArmAnim.cpp b/source/packets/cPacket_ArmAnim.cpp index c1766e8ce..dcd416449 100644 --- a/source/packets/cPacket_ArmAnim.cpp +++ b/source/packets/cPacket_ArmAnim.cpp @@ -1,31 +1,31 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_ArmAnim.h" - - - - - -int cPacket_ArmAnim::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_EntityID, TotalBytes); - HANDLE_PACKET_READ(ReadByte , m_Animation, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_ArmAnim::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_EntityID); - AppendByte (a_Data, m_Animation); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_ArmAnim.h" + + + + + +int cPacket_ArmAnim::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadInteger, m_EntityID, TotalBytes); + HANDLE_PACKET_READ(ReadByte , m_Animation, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_ArmAnim::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_EntityID); + AppendByte (a_Data, m_Animation); +} + + + + diff --git a/source/packets/cPacket_ArmAnim.h b/source/packets/cPacket_ArmAnim.h index 07753ebcb..79670de1c 100644 --- a/source/packets/cPacket_ArmAnim.h +++ b/source/packets/cPacket_ArmAnim.h @@ -1,21 +1,21 @@ -#pragma once - -#include "cPacket.h" - - -class cPacket_ArmAnim : public cPacket -{ -public: - cPacket_ArmAnim() - : m_EntityID( 0 ) - , m_Animation( 0 ) - { m_PacketID = E_ANIMATION; } - virtual cPacket* Clone() const { return new cPacket_ArmAnim(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - int m_EntityID; - char m_Animation; - static const unsigned int c_Size = 1 + 4 + 1; +#pragma once + +#include "cPacket.h" + + +class cPacket_ArmAnim : public cPacket +{ +public: + cPacket_ArmAnim() + : m_EntityID( 0 ) + , m_Animation( 0 ) + { m_PacketID = E_ANIMATION; } + virtual cPacket* Clone() const { return new cPacket_ArmAnim(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + int m_EntityID; + char m_Animation; + static const unsigned int c_Size = 1 + 4 + 1; }; \ No newline at end of file diff --git a/source/packets/cPacket_BlockChange.cpp b/source/packets/cPacket_BlockChange.cpp index 57c938814..e0ef5c001 100644 --- a/source/packets/cPacket_BlockChange.cpp +++ b/source/packets/cPacket_BlockChange.cpp @@ -1,22 +1,22 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_BlockChange.h" - - - - - -void cPacket_BlockChange::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_PosX); - AppendByte (a_Data, m_PosY); - AppendInteger(a_Data, m_PosZ); - AppendByte (a_Data, m_BlockType); - AppendByte (a_Data, m_BlockMeta); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_BlockChange.h" + + + + + +void cPacket_BlockChange::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_PosX); + AppendByte (a_Data, m_PosY); + AppendInteger(a_Data, m_PosZ); + AppendByte (a_Data, m_BlockType); + AppendByte (a_Data, m_BlockMeta); +} + + + + diff --git a/source/packets/cPacket_BlockChange.h b/source/packets/cPacket_BlockChange.h index a0b3c8843..039043cf0 100644 --- a/source/packets/cPacket_BlockChange.h +++ b/source/packets/cPacket_BlockChange.h @@ -1,27 +1,27 @@ -#pragma once - -#include "cPacket.h" - - -class cPacket_BlockChange : public cPacket -{ -public: - cPacket_BlockChange() - : m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_BlockType( 0 ) - , m_BlockMeta( 0 ) - { m_PacketID = E_BLOCK_CHANGE; } - virtual cPacket* Clone() const { return new cPacket_BlockChange(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_PosX; - unsigned char m_PosY; - int m_PosZ; - char m_BlockType; - char m_BlockMeta; - - static const unsigned int c_Size = 1 + 4 + 1 + 4 + 1 + 1; +#pragma once + +#include "cPacket.h" + + +class cPacket_BlockChange : public cPacket +{ +public: + cPacket_BlockChange() + : m_PosX( 0 ) + , m_PosY( 0 ) + , m_PosZ( 0 ) + , m_BlockType( 0 ) + , m_BlockMeta( 0 ) + { m_PacketID = E_BLOCK_CHANGE; } + virtual cPacket* Clone() const { return new cPacket_BlockChange(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_PosX; + unsigned char m_PosY; + int m_PosZ; + char m_BlockType; + char m_BlockMeta; + + static const unsigned int c_Size = 1 + 4 + 1 + 4 + 1 + 1; }; \ No newline at end of file diff --git a/source/packets/cPacket_BlockDig.cpp b/source/packets/cPacket_BlockDig.cpp index 466e77340..be2088cd0 100644 --- a/source/packets/cPacket_BlockDig.cpp +++ b/source/packets/cPacket_BlockDig.cpp @@ -1,36 +1,36 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_BlockDig.h" - - - - - -void cPacket_BlockDig::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_PosX); - AppendByte (a_Data, m_PosY); - AppendInteger(a_Data, m_PosZ); - AppendByte (a_Data, m_Direction); -} - - - - - -int cPacket_BlockDig::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadByte, m_Status, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Direction, TotalBytes); - return TotalBytes; -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_BlockDig.h" + + + + + +void cPacket_BlockDig::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_PosX); + AppendByte (a_Data, m_PosY); + AppendInteger(a_Data, m_PosZ); + AppendByte (a_Data, m_Direction); +} + + + + + +int cPacket_BlockDig::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadByte, m_Status, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_Direction, TotalBytes); + return TotalBytes; +} + + + + diff --git a/source/packets/cPacket_BlockDig.h b/source/packets/cPacket_BlockDig.h index 56ddfa9ca..1fde63db6 100644 --- a/source/packets/cPacket_BlockDig.h +++ b/source/packets/cPacket_BlockDig.h @@ -1,32 +1,32 @@ -#pragma once - -#include "cPacket.h" - - -class cPacket_BlockDig : public cPacket //tolua_export -{ //tolua_export -public: - cPacket_BlockDig() //tolua_export - : m_Status( 0 ) - , m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_Direction( 0 ) - { m_PacketID = E_BLOCK_DIG; } //tolua_export - virtual cPacket* Clone() const { return new cPacket_BlockDig(*this); } //tolua_export - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - char m_Status; // tolua_export - int m_PosX; // tolua_export - char m_PosY; // tolua_export - int m_PosZ; // tolua_export - char m_Direction; // tolua_export - - static const unsigned int c_Size = 12; -}; //tolua_export - - - - +#pragma once + +#include "cPacket.h" + + +class cPacket_BlockDig : public cPacket //tolua_export +{ //tolua_export +public: + cPacket_BlockDig() //tolua_export + : m_Status( 0 ) + , m_PosX( 0 ) + , m_PosY( 0 ) + , m_PosZ( 0 ) + , m_Direction( 0 ) + { m_PacketID = E_BLOCK_DIG; } //tolua_export + virtual cPacket* Clone() const { return new cPacket_BlockDig(*this); } //tolua_export + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + char m_Status; // tolua_export + int m_PosX; // tolua_export + char m_PosY; // tolua_export + int m_PosZ; // tolua_export + char m_Direction; // tolua_export + + static const unsigned int c_Size = 12; +}; //tolua_export + + + + diff --git a/source/packets/cPacket_BlockPlace.cpp b/source/packets/cPacket_BlockPlace.cpp index 6582c7890..2033bd91e 100644 --- a/source/packets/cPacket_BlockPlace.cpp +++ b/source/packets/cPacket_BlockPlace.cpp @@ -1,36 +1,36 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_BlockPlace.h" -#include "cPacket_ItemData.h" - - - - - -int cPacket_BlockPlace::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Direction, TotalBytes); - - cPacket_ItemData Item; - int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes); - if (res < 0) - { - return res; - } - TotalBytes += res; - - m_ItemType = Item.m_ItemID; - m_Count = Item.m_ItemCount; - m_Uses = Item.m_ItemUses; - - return TotalBytes; -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_BlockPlace.h" +#include "cPacket_ItemData.h" + + + + + +int cPacket_BlockPlace::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_Direction, TotalBytes); + + cPacket_ItemData Item; + int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes); + if (res < 0) + { + return res; + } + TotalBytes += res; + + m_ItemType = Item.m_ItemID; + m_Count = Item.m_ItemCount; + m_Uses = Item.m_ItemUses; + + return TotalBytes; +} + + + + diff --git a/source/packets/cPacket_BlockPlace.h b/source/packets/cPacket_BlockPlace.h index 9fa2fbbce..b8db56fd0 100644 --- a/source/packets/cPacket_BlockPlace.h +++ b/source/packets/cPacket_BlockPlace.h @@ -1,40 +1,40 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_BlockPlace : public cPacket //tolua_export -{ //tolua_export -public: - cPacket_BlockPlace() - : m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_Direction( 0 ) - , m_ItemType( 0 ) - , m_Count( 0 ) - , m_Uses( 0 ) - { m_PacketID = E_BLOCK_PLACE; } - virtual cPacket* Clone() const { return new cPacket_BlockPlace(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - - int m_PosX; //tolua_export - unsigned char m_PosY; //tolua_export - int m_PosZ; //tolua_export - char m_Direction; //tolua_export - - short m_ItemType; //tolua_export - char m_Count; //tolua_export - short m_Uses; //tolua_export - - static const unsigned int c_Size = 1 + 4 + 1 + 4 + 1 + 2;// ( + 2 ) -}; //tolua_export - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_BlockPlace : public cPacket //tolua_export +{ //tolua_export +public: + cPacket_BlockPlace() + : m_PosX( 0 ) + , m_PosY( 0 ) + , m_PosZ( 0 ) + , m_Direction( 0 ) + , m_ItemType( 0 ) + , m_Count( 0 ) + , m_Uses( 0 ) + { m_PacketID = E_BLOCK_PLACE; } + virtual cPacket* Clone() const { return new cPacket_BlockPlace(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + + int m_PosX; //tolua_export + unsigned char m_PosY; //tolua_export + int m_PosZ; //tolua_export + char m_Direction; //tolua_export + + short m_ItemType; //tolua_export + char m_Count; //tolua_export + short m_Uses; //tolua_export + + static const unsigned int c_Size = 1 + 4 + 1 + 4 + 1 + 2;// ( + 2 ) +}; //tolua_export + + + + diff --git a/source/packets/cPacket_Chat.cpp b/source/packets/cPacket_Chat.cpp index 04a65d18e..43b1af3fa 100644 --- a/source/packets/cPacket_Chat.cpp +++ b/source/packets/cPacket_Chat.cpp @@ -1,29 +1,29 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_Chat.h" - - - - - -int cPacket_Chat::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadString16, m_Message, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_Chat::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendString16(a_Data, m_Message); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_Chat.h" + + + + + +int cPacket_Chat::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadString16, m_Message, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_Chat::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendString16(a_Data, m_Message); +} + + + + diff --git a/source/packets/cPacket_Chat.h b/source/packets/cPacket_Chat.h index 4141439d9..fac4a4097 100644 --- a/source/packets/cPacket_Chat.h +++ b/source/packets/cPacket_Chat.h @@ -1,22 +1,22 @@ -#pragma once - -#include "cPacket.h" - - -class cPacket_Chat : public cPacket -{ -public: - cPacket_Chat() { m_PacketID = E_CHAT; } - cPacket_Chat( const std::string & a_Message ) : m_Message( a_Message) { m_PacketID = E_CHAT; } - virtual cPacket* Clone() const { return new cPacket_Chat(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - AString m_Message; - static const unsigned int c_Size = 3; // Minimum size -}; - - - - +#pragma once + +#include "cPacket.h" + + +class cPacket_Chat : public cPacket +{ +public: + cPacket_Chat() { m_PacketID = E_CHAT; } + cPacket_Chat( const std::string & a_Message ) : m_Message( a_Message) { m_PacketID = E_CHAT; } + virtual cPacket* Clone() const { return new cPacket_Chat(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + AString m_Message; + static const unsigned int c_Size = 3; // Minimum size +}; + + + + diff --git a/source/packets/cPacket_CollectItem.cpp b/source/packets/cPacket_CollectItem.cpp index 466eda6b7..39f4cdde2 100644 --- a/source/packets/cPacket_CollectItem.cpp +++ b/source/packets/cPacket_CollectItem.cpp @@ -1,19 +1,19 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_CollectItem.h" - - - - - -void cPacket_CollectItem::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_CollectedID); - AppendInteger(a_Data, m_CollectorID); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_CollectItem.h" + + + + + +void cPacket_CollectItem::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_CollectedID); + AppendInteger(a_Data, m_CollectorID); +} + + + + diff --git a/source/packets/cPacket_CollectItem.h b/source/packets/cPacket_CollectItem.h index b424ab4b7..29ab78ff8 100644 --- a/source/packets/cPacket_CollectItem.h +++ b/source/packets/cPacket_CollectItem.h @@ -1,27 +1,27 @@ -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_CollectItem : public cPacket -{ -public: - cPacket_CollectItem() - : m_CollectedID( 0 ) - , m_CollectorID( 0 ) - { m_PacketID = E_COLLECT_ITEM; } - virtual cPacket* Clone() const { return new cPacket_CollectItem(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_CollectedID; - int m_CollectorID; - static const unsigned int c_Size = 1 + 4 + 4; -}; - - - - +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_CollectItem : public cPacket +{ +public: + cPacket_CollectItem() + : m_CollectedID( 0 ) + , m_CollectorID( 0 ) + { m_PacketID = E_COLLECT_ITEM; } + virtual cPacket* Clone() const { return new cPacket_CollectItem(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_CollectedID; + int m_CollectorID; + static const unsigned int c_Size = 1 + 4 + 4; +}; + + + + diff --git a/source/packets/cPacket_CreativeInventoryAction.cpp b/source/packets/cPacket_CreativeInventoryAction.cpp index de6cc1488..46f125701 100644 --- a/source/packets/cPacket_CreativeInventoryAction.cpp +++ b/source/packets/cPacket_CreativeInventoryAction.cpp @@ -1,67 +1,67 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_CreativeInventoryAction.h" -#include "cPacket_ItemData.h" - - - - - -cPacket_CreativeInventoryAction::cPacket_CreativeInventoryAction( const cPacket_CreativeInventoryAction & a_Copy ) -{ - m_PacketID = E_CREATIVE_INVENTORY_ACTION; - m_Slot = a_Copy.m_Slot; - m_ItemID = a_Copy.m_ItemID; - m_Quantity = a_Copy.m_Quantity; - m_Damage = a_Copy.m_Damage; -} - - - - - -int cPacket_CreativeInventoryAction::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadShort, m_Slot, TotalBytes); - - cPacket_ItemData Item; - int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes); - if (res < 0) - { - return res; - } - TotalBytes += res; - - m_ItemID = Item.m_ItemID; - m_Quantity = Item.m_ItemCount; - m_Damage = Item.m_ItemUses; - - return TotalBytes; -} - - - - - -void cPacket_CreativeInventoryAction::Serialize(AString & a_Data) const -{ - short ItemID = m_ItemID; - ASSERT(ItemID >= -1); // Check validity of packets in debug runtime - if (ItemID <= 0) - { - ItemID = -1; - // Fix, to make sure no invalid values are sent. - // WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !! - } - - AppendByte (a_Data, m_PacketID); - AppendShort (a_Data, m_Slot); - - cPacket_ItemData::AppendItem(a_Data, ItemID, m_Quantity, m_Damage); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_CreativeInventoryAction.h" +#include "cPacket_ItemData.h" + + + + + +cPacket_CreativeInventoryAction::cPacket_CreativeInventoryAction( const cPacket_CreativeInventoryAction & a_Copy ) +{ + m_PacketID = E_CREATIVE_INVENTORY_ACTION; + m_Slot = a_Copy.m_Slot; + m_ItemID = a_Copy.m_ItemID; + m_Quantity = a_Copy.m_Quantity; + m_Damage = a_Copy.m_Damage; +} + + + + + +int cPacket_CreativeInventoryAction::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadShort, m_Slot, TotalBytes); + + cPacket_ItemData Item; + int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes); + if (res < 0) + { + return res; + } + TotalBytes += res; + + m_ItemID = Item.m_ItemID; + m_Quantity = Item.m_ItemCount; + m_Damage = Item.m_ItemUses; + + return TotalBytes; +} + + + + + +void cPacket_CreativeInventoryAction::Serialize(AString & a_Data) const +{ + short ItemID = m_ItemID; + ASSERT(ItemID >= -1); // Check validity of packets in debug runtime + if (ItemID <= 0) + { + ItemID = -1; + // Fix, to make sure no invalid values are sent. + // WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !! + } + + AppendByte (a_Data, m_PacketID); + AppendShort (a_Data, m_Slot); + + cPacket_ItemData::AppendItem(a_Data, ItemID, m_Quantity, m_Damage); +} + + + + diff --git a/source/packets/cPacket_DestroyEntity.cpp b/source/packets/cPacket_DestroyEntity.cpp index cd41b380b..d7e1d085b 100644 --- a/source/packets/cPacket_DestroyEntity.cpp +++ b/source/packets/cPacket_DestroyEntity.cpp @@ -1,30 +1,30 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_DestroyEntity.h" -#include "../cEntity.h" - - - - - -cPacket_DestroyEntity::cPacket_DestroyEntity(cEntity* a_Entity) -{ - m_PacketID = E_DESTROY_ENT; - - m_UniqueID = a_Entity->GetUniqueID(); -} - - - - - -void cPacket_DestroyEntity::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_DestroyEntity.h" +#include "../cEntity.h" + + + + + +cPacket_DestroyEntity::cPacket_DestroyEntity(cEntity* a_Entity) +{ + m_PacketID = E_DESTROY_ENT; + + m_UniqueID = a_Entity->GetUniqueID(); +} + + + + + +void cPacket_DestroyEntity::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_UniqueID); +} + + + + diff --git a/source/packets/cPacket_DestroyEntity.h b/source/packets/cPacket_DestroyEntity.h index 5f2314e55..b4146e971 100644 --- a/source/packets/cPacket_DestroyEntity.h +++ b/source/packets/cPacket_DestroyEntity.h @@ -1,33 +1,33 @@ -#pragma once - -#include "cPacket.h" - - - - - -class cEntity; - - - - - -class cPacket_DestroyEntity : public cPacket -{ -public: - cPacket_DestroyEntity() - : m_UniqueID( 0 ) - { m_PacketID = E_DESTROY_ENT; } - cPacket_DestroyEntity(cEntity* a_Entity); - virtual cPacket* Clone() const { return new cPacket_DestroyEntity(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - - static const unsigned int c_Size = 1 + 4; -}; - - - - +#pragma once + +#include "cPacket.h" + + + + + +class cEntity; + + + + + +class cPacket_DestroyEntity : public cPacket +{ +public: + cPacket_DestroyEntity() + : m_UniqueID( 0 ) + { m_PacketID = E_DESTROY_ENT; } + cPacket_DestroyEntity(cEntity* a_Entity); + virtual cPacket* Clone() const { return new cPacket_DestroyEntity(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + + static const unsigned int c_Size = 1 + 4; +}; + + + + diff --git a/source/packets/cPacket_Disconnect.cpp b/source/packets/cPacket_Disconnect.cpp index 82342c303..0ddad3744 100644 --- a/source/packets/cPacket_Disconnect.cpp +++ b/source/packets/cPacket_Disconnect.cpp @@ -1,29 +1,29 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_Disconnect.h" - - - - - -int cPacket_Disconnect::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadString16, m_Reason, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_Disconnect::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendString16(a_Data, m_Reason); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_Disconnect.h" + + + + + +int cPacket_Disconnect::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadString16, m_Reason, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_Disconnect::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendString16(a_Data, m_Reason); +} + + + + diff --git a/source/packets/cPacket_Disconnect.h b/source/packets/cPacket_Disconnect.h index ccb3811b5..e91a09980 100644 --- a/source/packets/cPacket_Disconnect.h +++ b/source/packets/cPacket_Disconnect.h @@ -1,26 +1,26 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_Disconnect : public cPacket -{ -public: - cPacket_Disconnect() { m_PacketID = E_DISCONNECT; } - cPacket_Disconnect(const AString & a_Reason) { m_PacketID = E_DISCONNECT; m_Reason = a_Reason; } - virtual cPacket* Clone() const { return new cPacket_Disconnect(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - AString m_Reason; - static const unsigned int c_Size = 3; // Minimum size -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_Disconnect : public cPacket +{ +public: + cPacket_Disconnect() { m_PacketID = E_DISCONNECT; } + cPacket_Disconnect(const AString & a_Reason) { m_PacketID = E_DISCONNECT; m_Reason = a_Reason; } + virtual cPacket* Clone() const { return new cPacket_Disconnect(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + AString m_Reason; + static const unsigned int c_Size = 3; // Minimum size +}; + + + + diff --git a/source/packets/cPacket_EntityEquipment.cpp b/source/packets/cPacket_EntityEquipment.cpp index a89cb9724..08bf30a6e 100644 --- a/source/packets/cPacket_EntityEquipment.cpp +++ b/source/packets/cPacket_EntityEquipment.cpp @@ -1,48 +1,48 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_EntityEquipment.h" - - - - - -cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ) -{ - m_PacketID = E_ENTITY_EQUIPMENT; - m_UniqueID = a_Copy.m_UniqueID; - m_Slot = a_Copy.m_Slot; - m_ItemID = a_Copy.m_ItemID; - m_Short = 0; -} - - - - - -int cPacket_EntityEquipment::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Slot, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_ItemID, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Short, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_EntityEquipment::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendShort (a_Data, m_Slot); - AppendShort (a_Data, m_ItemID); - AppendShort (a_Data, m_Short); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_EntityEquipment.h" + + + + + +cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ) +{ + m_PacketID = E_ENTITY_EQUIPMENT; + m_UniqueID = a_Copy.m_UniqueID; + m_Slot = a_Copy.m_Slot; + m_ItemID = a_Copy.m_ItemID; + m_Short = 0; +} + + + + + +int cPacket_EntityEquipment::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_Slot, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_ItemID, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_Short, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_EntityEquipment::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_UniqueID); + AppendShort (a_Data, m_Slot); + AppendShort (a_Data, m_ItemID); + AppendShort (a_Data, m_Short); +} + + + + diff --git a/source/packets/cPacket_EntityEquipment.h b/source/packets/cPacket_EntityEquipment.h index 4beda6063..ec09bbf5c 100644 --- a/source/packets/cPacket_EntityEquipment.h +++ b/source/packets/cPacket_EntityEquipment.h @@ -1,34 +1,34 @@ -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_EntityEquipment : public cPacket -{ -public: - cPacket_EntityEquipment() - : m_UniqueID( 0 ) - , m_Slot( 0 ) - , m_ItemID( 0 ) - , m_Short( 0 ) - { m_PacketID = E_ENTITY_EQUIPMENT; m_Short = 0; } - cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ); - virtual cPacket* Clone() const { return new cPacket_EntityEquipment(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - short m_Slot; // 0 = hold 1-4 = armor - short m_ItemID; - short m_Short; - - static const unsigned int c_Size = 1 + 4 + 2 + 2 + 2; -}; - - - - +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_EntityEquipment : public cPacket +{ +public: + cPacket_EntityEquipment() + : m_UniqueID( 0 ) + , m_Slot( 0 ) + , m_ItemID( 0 ) + , m_Short( 0 ) + { m_PacketID = E_ENTITY_EQUIPMENT; m_Short = 0; } + cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ); + virtual cPacket* Clone() const { return new cPacket_EntityEquipment(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + short m_Slot; // 0 = hold 1-4 = armor + short m_ItemID; + short m_Short; + + static const unsigned int c_Size = 1 + 4 + 2 + 2 + 2; +}; + + + + diff --git a/source/packets/cPacket_EntityLook.cpp b/source/packets/cPacket_EntityLook.cpp index d25f788c0..04fc46d4d 100644 --- a/source/packets/cPacket_EntityLook.cpp +++ b/source/packets/cPacket_EntityLook.cpp @@ -1,64 +1,64 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_EntityLook.h" - -#include "../cEntity.h" - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPacket_EntityLook: - -cPacket_EntityLook::cPacket_EntityLook(const cEntity & a_Entity) -{ - m_PacketID = E_ENT_LOOK; - - m_UniqueID = a_Entity.GetUniqueID(); - m_Rotation = (char)((a_Entity.GetRotation() / 360.f) * 256); - m_Pitch = (char)((a_Entity.GetPitch() / 360.f) * 256); -} - - - - - -void cPacket_EntityLook::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_Rotation); - AppendByte (a_Data, m_Pitch); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPacket_EntityHeadLook: - -cPacket_EntityHeadLook::cPacket_EntityHeadLook(const cEntity & a_Entity) -{ - m_PacketID = E_ENT_HEAD_LOOK; - - m_UniqueID = a_Entity.GetUniqueID(); - m_HeadYaw = (char)((a_Entity.GetRotation() / 360.f) * 256); -} - - - - - -void cPacket_EntityHeadLook::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_HeadYaw); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_EntityLook.h" + +#include "../cEntity.h" + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPacket_EntityLook: + +cPacket_EntityLook::cPacket_EntityLook(const cEntity & a_Entity) +{ + m_PacketID = E_ENT_LOOK; + + m_UniqueID = a_Entity.GetUniqueID(); + m_Rotation = (char)((a_Entity.GetRotation() / 360.f) * 256); + m_Pitch = (char)((a_Entity.GetPitch() / 360.f) * 256); +} + + + + + +void cPacket_EntityLook::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_UniqueID); + AppendByte (a_Data, m_Rotation); + AppendByte (a_Data, m_Pitch); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPacket_EntityHeadLook: + +cPacket_EntityHeadLook::cPacket_EntityHeadLook(const cEntity & a_Entity) +{ + m_PacketID = E_ENT_HEAD_LOOK; + + m_UniqueID = a_Entity.GetUniqueID(); + m_HeadYaw = (char)((a_Entity.GetRotation() / 360.f) * 256); +} + + + + + +void cPacket_EntityHeadLook::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_UniqueID); + AppendByte (a_Data, m_HeadYaw); +} + + + + diff --git a/source/packets/cPacket_EntityLook.h b/source/packets/cPacket_EntityLook.h index e4aac18e3..7f2864d46 100644 --- a/source/packets/cPacket_EntityLook.h +++ b/source/packets/cPacket_EntityLook.h @@ -1,59 +1,59 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cEntity; - - - - - -class cPacket_EntityLook : - public cPacket -{ -public: - cPacket_EntityLook(void) - : m_UniqueID( 0 ) - , m_Rotation( 0 ) - , m_Pitch( 0 ) - { m_PacketID = E_ENT_LOOK; } - cPacket_EntityLook(const cEntity & a_Entity); - virtual cPacket* Clone(void) const { return new cPacket_EntityLook(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_Rotation; - char m_Pitch; -}; - - - - - -class cPacket_EntityHeadLook : - public cPacket -{ -public: - cPacket_EntityHeadLook(void) - : m_UniqueID( 0 ) - , m_HeadYaw( 0 ) - { m_PacketID = E_ENT_LOOK; } - cPacket_EntityHeadLook(const cEntity & a_Entity); - - virtual cPacket * Clone(void) const { return new cPacket_EntityHeadLook(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_HeadYaw; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cEntity; + + + + + +class cPacket_EntityLook : + public cPacket +{ +public: + cPacket_EntityLook(void) + : m_UniqueID( 0 ) + , m_Rotation( 0 ) + , m_Pitch( 0 ) + { m_PacketID = E_ENT_LOOK; } + cPacket_EntityLook(const cEntity & a_Entity); + virtual cPacket* Clone(void) const { return new cPacket_EntityLook(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + char m_Rotation; + char m_Pitch; +}; + + + + + +class cPacket_EntityHeadLook : + public cPacket +{ +public: + cPacket_EntityHeadLook(void) + : m_UniqueID( 0 ) + , m_HeadYaw( 0 ) + { m_PacketID = E_ENT_LOOK; } + cPacket_EntityHeadLook(const cEntity & a_Entity); + + virtual cPacket * Clone(void) const { return new cPacket_EntityHeadLook(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + char m_HeadYaw; +}; + + + + diff --git a/source/packets/cPacket_EntityStatus.cpp b/source/packets/cPacket_EntityStatus.cpp index 0fc6195b3..1ea468a51 100644 --- a/source/packets/cPacket_EntityStatus.cpp +++ b/source/packets/cPacket_EntityStatus.cpp @@ -1,19 +1,19 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_EntityStatus.h" - - - - - -void cPacket_EntityStatus::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_Status); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_EntityStatus.h" + + + + + +void cPacket_EntityStatus::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_UniqueID); + AppendByte (a_Data, m_Status); +} + + + + diff --git a/source/packets/cPacket_EntityStatus.h b/source/packets/cPacket_EntityStatus.h index a50a25390..ecacd03c5 100644 --- a/source/packets/cPacket_EntityStatus.h +++ b/source/packets/cPacket_EntityStatus.h @@ -1,31 +1,31 @@ -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_EntityStatus : public cPacket -{ -public: - cPacket_EntityStatus() - : m_UniqueID( 0 ) - , m_Status( 0 ) - { m_PacketID = E_ENT_STATUS; } - virtual cPacket* Clone() const { return new cPacket_EntityStatus( *this ); } - - virtual void Serialize(AString & a_Data) const override; - - static const char STATUS_TAKEDAMAGE = 2; - static const char STATUS_DIE = 3; - - int m_UniqueID; - char m_Status; - - static const unsigned int c_Size = 1 + 4 + 1; -}; - - - - +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_EntityStatus : public cPacket +{ +public: + cPacket_EntityStatus() + : m_UniqueID( 0 ) + , m_Status( 0 ) + { m_PacketID = E_ENT_STATUS; } + virtual cPacket* Clone() const { return new cPacket_EntityStatus( *this ); } + + virtual void Serialize(AString & a_Data) const override; + + static const char STATUS_TAKEDAMAGE = 2; + static const char STATUS_DIE = 3; + + int m_UniqueID; + char m_Status; + + static const unsigned int c_Size = 1 + 4 + 1; +}; + + + + diff --git a/source/packets/cPacket_Flying.cpp b/source/packets/cPacket_Flying.cpp index c7916957a..64fbf11ea 100644 --- a/source/packets/cPacket_Flying.cpp +++ b/source/packets/cPacket_Flying.cpp @@ -1,19 +1,19 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_Flying.h" - - - - - -int cPacket_Flying::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes= 0; - HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); - return TotalBytes; -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_Flying.h" + + + + + +int cPacket_Flying::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes= 0; + HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); + return TotalBytes; +} + + + + diff --git a/source/packets/cPacket_Flying.h b/source/packets/cPacket_Flying.h index 19b0ee213..2d19820de 100644 --- a/source/packets/cPacket_Flying.h +++ b/source/packets/cPacket_Flying.h @@ -1,27 +1,27 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_Flying : public cPacket -{ -public: - // The BS packet - cPacket_Flying() - : m_bFlying( false ) - { m_PacketID = E_FLYING; } - virtual cPacket* Clone() const { return new cPacket_Flying(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - - bool m_bFlying; - static const unsigned int c_Size = 2; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_Flying : public cPacket +{ +public: + // The BS packet + cPacket_Flying() + : m_bFlying( false ) + { m_PacketID = E_FLYING; } + virtual cPacket* Clone() const { return new cPacket_Flying(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + + bool m_bFlying; + static const unsigned int c_Size = 2; +}; + + + + diff --git a/source/packets/cPacket_Handshake.cpp b/source/packets/cPacket_Handshake.cpp index 2c4f058e7..737eca330 100644 --- a/source/packets/cPacket_Handshake.cpp +++ b/source/packets/cPacket_Handshake.cpp @@ -1,29 +1,29 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_Handshake.h" - - - - - -int cPacket_Handshake::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadString16, m_Username, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_Handshake::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendString16(a_Data, m_Username); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_Handshake.h" + + + + + +int cPacket_Handshake::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadString16, m_Username, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_Handshake::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendString16(a_Data, m_Username); +} + + + + diff --git a/source/packets/cPacket_Handshake.h b/source/packets/cPacket_Handshake.h index e66827851..020be9eaf 100644 --- a/source/packets/cPacket_Handshake.h +++ b/source/packets/cPacket_Handshake.h @@ -1,25 +1,25 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_Handshake : public cPacket -{ -public: - cPacket_Handshake() { m_PacketID = E_HANDSHAKE; } - virtual cPacket* Clone() const { return new cPacket_Handshake(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - std::string m_Username; - static const unsigned int c_Size = 3; // Minimal size -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_Handshake : public cPacket +{ +public: + cPacket_Handshake() { m_PacketID = E_HANDSHAKE; } + virtual cPacket* Clone() const { return new cPacket_Handshake(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + std::string m_Username; + static const unsigned int c_Size = 3; // Minimal size +}; + + + + diff --git a/source/packets/cPacket_InventoryProgressBar.cpp b/source/packets/cPacket_InventoryProgressBar.cpp index 9df92b390..61541c8e9 100644 --- a/source/packets/cPacket_InventoryProgressBar.cpp +++ b/source/packets/cPacket_InventoryProgressBar.cpp @@ -1,20 +1,20 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_InventoryProgressBar.h" - - - - - -void cPacket_InventoryProgressBar::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendByte (a_Data, m_WindowID); - AppendShort(a_Data, m_ProgressBar); - AppendShort(a_Data, m_Value); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_InventoryProgressBar.h" + + + + + +void cPacket_InventoryProgressBar::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendByte (a_Data, m_WindowID); + AppendShort(a_Data, m_ProgressBar); + AppendShort(a_Data, m_Value); +} + + + + diff --git a/source/packets/cPacket_InventoryProgressBar.h b/source/packets/cPacket_InventoryProgressBar.h index 70bafcf9e..0aa2fd3a8 100644 --- a/source/packets/cPacket_InventoryProgressBar.h +++ b/source/packets/cPacket_InventoryProgressBar.h @@ -1,31 +1,31 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_InventoryProgressBar : public cPacket -{ -public: - cPacket_InventoryProgressBar() - : m_WindowID( 0 ) - , m_ProgressBar( 0 ) - , m_Value( 0 ) - { m_PacketID = E_INVENTORY_PROGRESS; } - virtual cPacket* Clone() const { return new cPacket_InventoryProgressBar(*this); } - - virtual void Serialize(AString & a_Data) const override; - - char m_WindowID; - short m_ProgressBar; - short m_Value; - - static const unsigned int c_Size = 1 + 1 + 2 + 2; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_InventoryProgressBar : public cPacket +{ +public: + cPacket_InventoryProgressBar() + : m_WindowID( 0 ) + , m_ProgressBar( 0 ) + , m_Value( 0 ) + { m_PacketID = E_INVENTORY_PROGRESS; } + virtual cPacket* Clone() const { return new cPacket_InventoryProgressBar(*this); } + + virtual void Serialize(AString & a_Data) const override; + + char m_WindowID; + short m_ProgressBar; + short m_Value; + + static const unsigned int c_Size = 1 + 1 + 2 + 2; +}; + + + + diff --git a/source/packets/cPacket_InventorySlot.cpp b/source/packets/cPacket_InventorySlot.cpp index 46f3bf3d4..5bf247541 100644 --- a/source/packets/cPacket_InventorySlot.cpp +++ b/source/packets/cPacket_InventorySlot.cpp @@ -1,23 +1,23 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_InventorySlot.h" -#include "cPacket_WholeInventory.h" -#include "cPacket_ItemData.h" - - - - - -void cPacket_InventorySlot::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendByte (a_Data, m_WindowID); - AppendShort(a_Data, m_SlotNum); - - cPacket_ItemData::AppendItem(a_Data, m_ItemID, m_ItemCount, m_ItemUses); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_InventorySlot.h" +#include "cPacket_WholeInventory.h" +#include "cPacket_ItemData.h" + + + + + +void cPacket_InventorySlot::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendByte (a_Data, m_WindowID); + AppendShort(a_Data, m_SlotNum); + + cPacket_ItemData::AppendItem(a_Data, m_ItemID, m_ItemCount, m_ItemUses); +} + + + + diff --git a/source/packets/cPacket_InventorySlot.h b/source/packets/cPacket_InventorySlot.h index cc04a0bb0..3f9fdc13f 100644 --- a/source/packets/cPacket_InventorySlot.h +++ b/source/packets/cPacket_InventorySlot.h @@ -1,44 +1,44 @@ - -#pragma once - -#include "cPacket.h" - -#include "../BlockID.h" - - - - - -class cPacket_InventorySlot : public cPacket // Set item [S -> C] ? -{ -public: - cPacket_InventorySlot() - : m_WindowID( 0 ) - , m_SlotNum( 0 ) - , m_ItemID( E_ITEM_EMPTY ) - , m_ItemCount( 0 ) - , m_ItemUses( 0 ) - { m_PacketID = E_INVENTORY_SLOT; } - virtual cPacket* Clone() const { return new cPacket_InventorySlot(*this); } - - virtual void Serialize(AString & a_Data) const override; - - char m_WindowID; - short m_SlotNum; // Slot - // 0 = craft result - // 1-4 = crafting table - // 5-8 = armor - // 9-35 = inventory - // 36-44 = Hot bar - - // Below = item - short m_ItemID; // if this is -1 the next stuff dont exist - char m_ItemCount; - short m_ItemUses; - - static const unsigned int c_Size = 1 + 1 + 2; // Minimal size ( +1+1 = max) -}; - - - - + +#pragma once + +#include "cPacket.h" + +#include "../BlockID.h" + + + + + +class cPacket_InventorySlot : public cPacket // Set item [S -> C] ? +{ +public: + cPacket_InventorySlot() + : m_WindowID( 0 ) + , m_SlotNum( 0 ) + , m_ItemID( E_ITEM_EMPTY ) + , m_ItemCount( 0 ) + , m_ItemUses( 0 ) + { m_PacketID = E_INVENTORY_SLOT; } + virtual cPacket* Clone() const { return new cPacket_InventorySlot(*this); } + + virtual void Serialize(AString & a_Data) const override; + + char m_WindowID; + short m_SlotNum; // Slot + // 0 = craft result + // 1-4 = crafting table + // 5-8 = armor + // 9-35 = inventory + // 36-44 = Hot bar + + // Below = item + short m_ItemID; // if this is -1 the next stuff dont exist + char m_ItemCount; + short m_ItemUses; + + static const unsigned int c_Size = 1 + 1 + 2; // Minimal size ( +1+1 = max) +}; + + + + diff --git a/source/packets/cPacket_ItemData.cpp b/source/packets/cPacket_ItemData.cpp index db025a838..0892f433a 100644 --- a/source/packets/cPacket_ItemData.cpp +++ b/source/packets/cPacket_ItemData.cpp @@ -1,81 +1,81 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_ItemData.h" - - - - - -int cPacket_ItemData::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadShort, m_ItemID, TotalBytes); - - if (m_ItemID <= -1) - { - m_ItemCount = 0; - m_ItemUses = 0; - return TotalBytes; - } - - HANDLE_PACKET_READ(ReadByte , m_ItemCount, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_ItemUses, TotalBytes); - - if (cItem::IsEnchantable((ENUM_ITEM_ID) m_ItemID)) - { - HANDLE_PACKET_READ(ReadShort, m_EnchantNums, TotalBytes); - - if ( m_EnchantNums > -1 ) - { - // TODO: Enchantment not implemented yet! - } - } - return TotalBytes; -} - - - - - -int cPacket_ItemData::GetSize(short a_ItemID) -{ - if(a_ItemID <= -1) - return 2; - if(cItem::IsEnchantable((ENUM_ITEM_ID) a_ItemID)) - return 7; - return 5; -} - - - - - -void cPacket_ItemData::AppendItem(AString & a_Data, const cItem * a_Item) -{ - return AppendItem(a_Data, a_Item->m_ItemID, a_Item->m_ItemCount, a_Item->m_ItemHealth); -} - - - - - -void cPacket_ItemData::AppendItem(AString & a_Data, short a_ItemID, char a_Quantity, short a_Damage) -{ - AppendShort(a_Data, (short) a_ItemID); - if (a_ItemID > -1) - { - AppendByte (a_Data, a_Quantity); - AppendShort(a_Data, a_Damage); - - if (cItem::IsEnchantable((ENUM_ITEM_ID) a_ItemID)) - { - // TODO: Implement enchantments - AppendShort(a_Data, (short) -1); - } - } -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_ItemData.h" + + + + + +int cPacket_ItemData::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadShort, m_ItemID, TotalBytes); + + if (m_ItemID <= -1) + { + m_ItemCount = 0; + m_ItemUses = 0; + return TotalBytes; + } + + HANDLE_PACKET_READ(ReadByte , m_ItemCount, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_ItemUses, TotalBytes); + + if (cItem::IsEnchantable((ENUM_ITEM_ID) m_ItemID)) + { + HANDLE_PACKET_READ(ReadShort, m_EnchantNums, TotalBytes); + + if ( m_EnchantNums > -1 ) + { + // TODO: Enchantment not implemented yet! + } + } + return TotalBytes; +} + + + + + +int cPacket_ItemData::GetSize(short a_ItemID) +{ + if(a_ItemID <= -1) + return 2; + if(cItem::IsEnchantable((ENUM_ITEM_ID) a_ItemID)) + return 7; + return 5; +} + + + + + +void cPacket_ItemData::AppendItem(AString & a_Data, const cItem * a_Item) +{ + return AppendItem(a_Data, a_Item->m_ItemID, a_Item->m_ItemCount, a_Item->m_ItemHealth); +} + + + + + +void cPacket_ItemData::AppendItem(AString & a_Data, short a_ItemID, char a_Quantity, short a_Damage) +{ + AppendShort(a_Data, (short) a_ItemID); + if (a_ItemID > -1) + { + AppendByte (a_Data, a_Quantity); + AppendShort(a_Data, a_Damage); + + if (cItem::IsEnchantable((ENUM_ITEM_ID) a_ItemID)) + { + // TODO: Implement enchantments + AppendShort(a_Data, (short) -1); + } + } +} + + + + diff --git a/source/packets/cPacket_ItemData.h b/source/packets/cPacket_ItemData.h index 6aa1eed69..47878969f 100644 --- a/source/packets/cPacket_ItemData.h +++ b/source/packets/cPacket_ItemData.h @@ -1,35 +1,35 @@ -#pragma once - - -#include "cPacket.h" -#include "../cItem.h" - -class cPacket_ItemData : public cPacket -{ -public: - cPacket_ItemData() - : m_ItemID( 0 ) - , m_ItemCount( 0 ) - , m_ItemUses( 0 ) - , m_EnchantNums(-1) - { - } - - virtual cPacket* Clone() const { return new cPacket_ItemData(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - - static void AppendItem(AString & a_Data, short a_ItemID, char a_Quantity, short a_Damage); - static void AppendItem(AString & a_Data, const cItem * a_Item); - - int GetSize(short a_ItemID); - - // Below = item - short m_ItemID; // if this is -1 the next stuff dont exist - char m_ItemCount; - short m_ItemUses; - - short m_EnchantNums; - - static unsigned int c_Size; // Minimal size ( +1+1 = max) +#pragma once + + +#include "cPacket.h" +#include "../cItem.h" + +class cPacket_ItemData : public cPacket +{ +public: + cPacket_ItemData() + : m_ItemID( 0 ) + , m_ItemCount( 0 ) + , m_ItemUses( 0 ) + , m_EnchantNums(-1) + { + } + + virtual cPacket* Clone() const { return new cPacket_ItemData(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + + static void AppendItem(AString & a_Data, short a_ItemID, char a_Quantity, short a_Damage); + static void AppendItem(AString & a_Data, const cItem * a_Item); + + int GetSize(short a_ItemID); + + // Below = item + short m_ItemID; // if this is -1 the next stuff dont exist + char m_ItemCount; + short m_ItemUses; + + short m_EnchantNums; + + static unsigned int c_Size; // Minimal size ( +1+1 = max) }; \ No newline at end of file diff --git a/source/packets/cPacket_ItemSwitch.cpp b/source/packets/cPacket_ItemSwitch.cpp index 630c2ada4..bd4532938 100644 --- a/source/packets/cPacket_ItemSwitch.cpp +++ b/source/packets/cPacket_ItemSwitch.cpp @@ -1,29 +1,29 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_ItemSwitch.h" - - - - - -int cPacket_ItemSwitch::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadShort, m_SlotNum, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_ItemSwitch::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendShort(a_Data, m_SlotNum); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_ItemSwitch.h" + + + + + +int cPacket_ItemSwitch::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadShort, m_SlotNum, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_ItemSwitch::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendShort(a_Data, m_SlotNum); +} + + + + diff --git a/source/packets/cPacket_ItemSwitch.h b/source/packets/cPacket_ItemSwitch.h index 00e37b9c8..fb6860624 100644 --- a/source/packets/cPacket_ItemSwitch.h +++ b/source/packets/cPacket_ItemSwitch.h @@ -1,28 +1,28 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_ItemSwitch : public cPacket -{ -public: - cPacket_ItemSwitch() - : m_SlotNum( 0 ) - { m_PacketID = E_ITEM_SWITCH; } - virtual cPacket* Clone() const { return new cPacket_ItemSwitch(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - short m_SlotNum; - - static const unsigned int c_Size = 1 + 2; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_ItemSwitch : public cPacket +{ +public: + cPacket_ItemSwitch() + : m_SlotNum( 0 ) + { m_PacketID = E_ITEM_SWITCH; } + virtual cPacket* Clone() const { return new cPacket_ItemSwitch(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + short m_SlotNum; + + static const unsigned int c_Size = 1 + 2; +}; + + + + diff --git a/source/packets/cPacket_KeepAlive.cpp b/source/packets/cPacket_KeepAlive.cpp index cf251bf16..cfc6b99b3 100644 --- a/source/packets/cPacket_KeepAlive.cpp +++ b/source/packets/cPacket_KeepAlive.cpp @@ -1,29 +1,29 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_KeepAlive.h" - - - - - -void cPacket_KeepAlive::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_KeepAliveID); -} - - - - - -int cPacket_KeepAlive::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_KeepAliveID, TotalBytes); - return TotalBytes; -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_KeepAlive.h" + + + + + +void cPacket_KeepAlive::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_KeepAliveID); +} + + + + + +int cPacket_KeepAlive::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadInteger, m_KeepAliveID, TotalBytes); + return TotalBytes; +} + + + + diff --git a/source/packets/cPacket_KeepAlive.h b/source/packets/cPacket_KeepAlive.h index 3611b6e18..e94ec72a6 100644 --- a/source/packets/cPacket_KeepAlive.h +++ b/source/packets/cPacket_KeepAlive.h @@ -1,27 +1,27 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_KeepAlive : public cPacket -{ -public: - cPacket_KeepAlive() { m_PacketID = E_KEEP_ALIVE; } - cPacket_KeepAlive(int a_PingID) { m_KeepAliveID = a_PingID; } - virtual cPacket* Clone() const { return new cPacket_KeepAlive(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - int m_KeepAliveID; - - static const unsigned int c_Size = 1 + 4; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_KeepAlive : public cPacket +{ +public: + cPacket_KeepAlive() { m_PacketID = E_KEEP_ALIVE; } + cPacket_KeepAlive(int a_PingID) { m_KeepAliveID = a_PingID; } + virtual cPacket* Clone() const { return new cPacket_KeepAlive(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + int m_KeepAliveID; + + static const unsigned int c_Size = 1 + 4; +}; + + + + diff --git a/source/packets/cPacket_Login.cpp b/source/packets/cPacket_Login.cpp index 588892b3a..2a8ae7135 100644 --- a/source/packets/cPacket_Login.cpp +++ b/source/packets/cPacket_Login.cpp @@ -1,52 +1,52 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_Login.h" - - - - - -const std::string cPacket_Login::LEVEL_TYPE_DEFAULT = "DEFAULT"; -const std::string cPacket_Login::LEVEL_TYPE_SUPERFLAT = "SUPERFLAT"; - - - - - -int cPacket_Login::Parse(const char * a_Data, int a_Size) -{ - //printf("Parse: NEW Login\n"); - int TotalBytes = 0; - m_Username.clear(); - HANDLE_PACKET_READ(ReadInteger, m_ProtocolVersion, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Username, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_LevelType, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_ServerMode, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_Dimension, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Difficulty, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_WorldHeight, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_MaxPlayers, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_Login::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger (a_Data, m_ProtocolVersion); - AppendString16(a_Data, m_Username); - AppendString16(a_Data, m_LevelType); - AppendInteger (a_Data, m_ServerMode); - AppendInteger (a_Data, m_Dimension); - AppendByte (a_Data, m_Difficulty); - AppendByte (a_Data, m_WorldHeight); - AppendByte (a_Data, m_MaxPlayers); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_Login.h" + + + + + +const std::string cPacket_Login::LEVEL_TYPE_DEFAULT = "DEFAULT"; +const std::string cPacket_Login::LEVEL_TYPE_SUPERFLAT = "SUPERFLAT"; + + + + + +int cPacket_Login::Parse(const char * a_Data, int a_Size) +{ + //printf("Parse: NEW Login\n"); + int TotalBytes = 0; + m_Username.clear(); + HANDLE_PACKET_READ(ReadInteger, m_ProtocolVersion, TotalBytes); + HANDLE_PACKET_READ(ReadString16, m_Username, TotalBytes); + HANDLE_PACKET_READ(ReadString16, m_LevelType, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_ServerMode, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_Dimension, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_Difficulty, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_WorldHeight, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_MaxPlayers, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_Login::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger (a_Data, m_ProtocolVersion); + AppendString16(a_Data, m_Username); + AppendString16(a_Data, m_LevelType); + AppendInteger (a_Data, m_ServerMode); + AppendInteger (a_Data, m_Dimension); + AppendByte (a_Data, m_Difficulty); + AppendByte (a_Data, m_WorldHeight); + AppendByte (a_Data, m_MaxPlayers); +} + + + + diff --git a/source/packets/cPacket_Login.h b/source/packets/cPacket_Login.h index 86666090c..b9769fdec 100644 --- a/source/packets/cPacket_Login.h +++ b/source/packets/cPacket_Login.h @@ -1,42 +1,42 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_Login : public cPacket //tolua_export -{ //tolua_export -public: - cPacket_Login() - : m_ProtocolVersion( 0 ) - , m_ServerMode( 0 ) - , m_Dimension( 0 ) - , m_Difficulty( 0 ) - , m_WorldHeight( 0 ) - , m_MaxPlayers( 0 ) - , m_LevelType( LEVEL_TYPE_DEFAULT ) - { m_PacketID = E_LOGIN; } - virtual cPacket* Clone() const { return new cPacket_Login(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - int m_ProtocolVersion; //tolua_export - AString m_Username; //tolua_export - AString m_LevelType; //tolua_export - int m_ServerMode; //tolua_export - int m_Dimension; - char m_Difficulty; //tolua_export - unsigned char m_WorldHeight; //tolua_export - unsigned char m_MaxPlayers; //tolua_export - - static const AString LEVEL_TYPE_DEFAULT; - static const AString LEVEL_TYPE_SUPERFLAT; -}; //tolua_export - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_Login : public cPacket //tolua_export +{ //tolua_export +public: + cPacket_Login() + : m_ProtocolVersion( 0 ) + , m_ServerMode( 0 ) + , m_Dimension( 0 ) + , m_Difficulty( 0 ) + , m_WorldHeight( 0 ) + , m_MaxPlayers( 0 ) + , m_LevelType( LEVEL_TYPE_DEFAULT ) + { m_PacketID = E_LOGIN; } + virtual cPacket* Clone() const { return new cPacket_Login(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + int m_ProtocolVersion; //tolua_export + AString m_Username; //tolua_export + AString m_LevelType; //tolua_export + int m_ServerMode; //tolua_export + int m_Dimension; + char m_Difficulty; //tolua_export + unsigned char m_WorldHeight; //tolua_export + unsigned char m_MaxPlayers; //tolua_export + + static const AString LEVEL_TYPE_DEFAULT; + static const AString LEVEL_TYPE_SUPERFLAT; +}; //tolua_export + + + + diff --git a/source/packets/cPacket_MapChunk.cpp b/source/packets/cPacket_MapChunk.cpp index 279dee808..21c62da45 100644 --- a/source/packets/cPacket_MapChunk.cpp +++ b/source/packets/cPacket_MapChunk.cpp @@ -1,154 +1,154 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_MapChunk.h" -#include "../ChunkDef.h" - -#include "zlib.h" - - - - - -cPacket_MapChunk::~cPacket_MapChunk() -{ - delete [] m_CompressedData; -} - - - - - -cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const BLOCKTYPE * a_BlockData, const unsigned char * a_BiomeData) -{ - m_PacketID = E_MAP_CHUNK; - - m_PosX = a_ChunkX; // Chunk coordinates now, instead of block coordinates - m_PosZ = a_ChunkZ; - - m_bContiguous = true; // false = no biome data, true = with biome data - m_BitMap1 = 0; - m_BitMap2 = 0; - - m_UnusedInt = 0; - - - const int BlockDataSize = (cChunkDef::Height / 16) * (4096 + 2048 + 2048 + 2048); - const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width; - char AllData [ BlockDataSize + BiomeDataSize ]; - -#if AXIS_ORDER == AXIS_ORDER_YZX - memset( AllData, 0, BlockDataSize ); - - unsigned int iterator = 0; - for ( int i = 0; i < (cChunkDef::Height / 16); ++i ) - { - m_BitMap1 |= (1 << i); // This tells what chunks are sent. Use this to NOT send air only chunks (right now everything is sent) - for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) for( int x = 0; x < 16; ++x ) - { - int idx = cChunk::MakeIndex(x, y + i * 16, z); - AllData[iterator] = a_BlockData[idx]; - ++iterator; - } // for y, z, x - } - - // Send block metadata: - char * Meta = a_BlockData + cChunkDef::NumBlocks; - for ( int i = 0; i < (cChunkDef::Height / 16); ++i ) - { - for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) - { - for ( int x = 0; x < 8; ++x ) - { - AllData[iterator] = cChunk::GetNibble(Meta, x * 2 + 0, y + i * 16, z) | (cChunk::GetNibble(Meta, x * 2 + 1, y + i * 16, z ) << 4); - ++iterator; - } // for x - } // for y, z - } - - // Send block light: - char * Light = Meta + cChunkDef::NumBlocks / 2; - for ( int i = 0; i < (cChunkDef::Height / 16); ++i ) - { - for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) - { - for ( int x = 0; x < 8; ++x ) - { - AllData[iterator] = cChunk::GetNibble(Light, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(Light, x * 2 + 1, y + i * 16, z ) << 4); - ++iterator; - } - } - } - - // Send sky light: - char * SkyLight = Light + cChunkDef::NumBlocks / 2; - for( int i = 0; i < (cChunkDef::Height/16); ++i ) - { - for( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) - { - for( int x = 0; x < 8; ++x ) - { - AllData[iterator] = cChunk::GetNibble(SkyLight, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(SkyLight, x * 2 + 1, y + i * 16, z ) << 4); - ++iterator; - } - } - } - memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize); -#elif AXIS_ORDER == AXIS_ORDER_XZY - for ( int i = 0; i < 16; ++i ) - { - m_BitMap1 |= (1 << i); - } - memcpy(AllData, a_BlockData, BlockDataSize); - memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize); -#endif // AXIS_ORDER - - uLongf CompressedSize = compressBound( sizeof(AllData) ); - char * CompressedBlockData = new char[CompressedSize]; - - compress2( (Bytef*)CompressedBlockData, &CompressedSize, (const Bytef*)AllData, sizeof(AllData), Z_DEFAULT_COMPRESSION); - - m_CompressedData = CompressedBlockData; - m_CompressedSize = CompressedSize; -} - - - - - -cPacket_MapChunk::cPacket_MapChunk( const cPacket_MapChunk & a_Copy ) -{ - m_PacketID = E_MAP_CHUNK; - - m_PosX = a_Copy.m_PosX; - m_PosZ = a_Copy.m_PosZ; - m_bContiguous = a_Copy.m_bContiguous; - m_BitMap1 = a_Copy.m_BitMap1; - m_BitMap2 = a_Copy.m_BitMap2; - - m_CompressedSize = a_Copy.m_CompressedSize; - m_CompressedData = new char[m_CompressedSize]; - memcpy( m_CompressedData, a_Copy.m_CompressedData, m_CompressedSize ); -} - - - - - -void cPacket_MapChunk::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - - AppendInteger(a_Data, m_PosX); - AppendInteger(a_Data, m_PosZ); - AppendBool (a_Data, m_bContiguous); - AppendShort (a_Data, m_BitMap1); - AppendShort (a_Data, m_BitMap2); - AppendInteger(a_Data, m_CompressedSize); - AppendInteger(a_Data, m_UnusedInt); - AppendData (a_Data, m_CompressedData, m_CompressedSize); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_MapChunk.h" +#include "../ChunkDef.h" + +#include "zlib.h" + + + + + +cPacket_MapChunk::~cPacket_MapChunk() +{ + delete [] m_CompressedData; +} + + + + + +cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const BLOCKTYPE * a_BlockData, const unsigned char * a_BiomeData) +{ + m_PacketID = E_MAP_CHUNK; + + m_PosX = a_ChunkX; // Chunk coordinates now, instead of block coordinates + m_PosZ = a_ChunkZ; + + m_bContiguous = true; // false = no biome data, true = with biome data + m_BitMap1 = 0; + m_BitMap2 = 0; + + m_UnusedInt = 0; + + + const int BlockDataSize = (cChunkDef::Height / 16) * (4096 + 2048 + 2048 + 2048); + const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width; + char AllData [ BlockDataSize + BiomeDataSize ]; + +#if AXIS_ORDER == AXIS_ORDER_YZX + memset( AllData, 0, BlockDataSize ); + + unsigned int iterator = 0; + for ( int i = 0; i < (cChunkDef::Height / 16); ++i ) + { + m_BitMap1 |= (1 << i); // This tells what chunks are sent. Use this to NOT send air only chunks (right now everything is sent) + for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) for( int x = 0; x < 16; ++x ) + { + int idx = cChunk::MakeIndex(x, y + i * 16, z); + AllData[iterator] = a_BlockData[idx]; + ++iterator; + } // for y, z, x + } + + // Send block metadata: + char * Meta = a_BlockData + cChunkDef::NumBlocks; + for ( int i = 0; i < (cChunkDef::Height / 16); ++i ) + { + for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) + { + for ( int x = 0; x < 8; ++x ) + { + AllData[iterator] = cChunk::GetNibble(Meta, x * 2 + 0, y + i * 16, z) | (cChunk::GetNibble(Meta, x * 2 + 1, y + i * 16, z ) << 4); + ++iterator; + } // for x + } // for y, z + } + + // Send block light: + char * Light = Meta + cChunkDef::NumBlocks / 2; + for ( int i = 0; i < (cChunkDef::Height / 16); ++i ) + { + for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) + { + for ( int x = 0; x < 8; ++x ) + { + AllData[iterator] = cChunk::GetNibble(Light, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(Light, x * 2 + 1, y + i * 16, z ) << 4); + ++iterator; + } + } + } + + // Send sky light: + char * SkyLight = Light + cChunkDef::NumBlocks / 2; + for( int i = 0; i < (cChunkDef::Height/16); ++i ) + { + for( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) + { + for( int x = 0; x < 8; ++x ) + { + AllData[iterator] = cChunk::GetNibble(SkyLight, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(SkyLight, x * 2 + 1, y + i * 16, z ) << 4); + ++iterator; + } + } + } + memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize); +#elif AXIS_ORDER == AXIS_ORDER_XZY + for ( int i = 0; i < 16; ++i ) + { + m_BitMap1 |= (1 << i); + } + memcpy(AllData, a_BlockData, BlockDataSize); + memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize); +#endif // AXIS_ORDER + + uLongf CompressedSize = compressBound( sizeof(AllData) ); + char * CompressedBlockData = new char[CompressedSize]; + + compress2( (Bytef*)CompressedBlockData, &CompressedSize, (const Bytef*)AllData, sizeof(AllData), Z_DEFAULT_COMPRESSION); + + m_CompressedData = CompressedBlockData; + m_CompressedSize = CompressedSize; +} + + + + + +cPacket_MapChunk::cPacket_MapChunk( const cPacket_MapChunk & a_Copy ) +{ + m_PacketID = E_MAP_CHUNK; + + m_PosX = a_Copy.m_PosX; + m_PosZ = a_Copy.m_PosZ; + m_bContiguous = a_Copy.m_bContiguous; + m_BitMap1 = a_Copy.m_BitMap1; + m_BitMap2 = a_Copy.m_BitMap2; + + m_CompressedSize = a_Copy.m_CompressedSize; + m_CompressedData = new char[m_CompressedSize]; + memcpy( m_CompressedData, a_Copy.m_CompressedData, m_CompressedSize ); +} + + + + + +void cPacket_MapChunk::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + + AppendInteger(a_Data, m_PosX); + AppendInteger(a_Data, m_PosZ); + AppendBool (a_Data, m_bContiguous); + AppendShort (a_Data, m_BitMap1); + AppendShort (a_Data, m_BitMap2); + AppendInteger(a_Data, m_CompressedSize); + AppendInteger(a_Data, m_UnusedInt); + AppendData (a_Data, m_CompressedData, m_CompressedSize); +} + + + + diff --git a/source/packets/cPacket_MapChunk.h b/source/packets/cPacket_MapChunk.h index 0daf5af34..ec2f68632 100644 --- a/source/packets/cPacket_MapChunk.h +++ b/source/packets/cPacket_MapChunk.h @@ -1,45 +1,45 @@ - -#pragma once - -#include "cPacket.h" -#include "../ChunkDef.h" - - - - - -class cPacket_MapChunk : - public cPacket -{ -public: - cPacket_MapChunk() - : m_PosX( 0 ) - , m_PosZ( 0 ) - , m_bContiguous( false ) - , m_BitMap1( 0 ) - , m_BitMap2( 0 ) - , m_CompressedSize( 0 ) - , m_UnusedInt( 0 ) - , m_CompressedData( NULL ) - { m_PacketID = E_MAP_CHUNK; } - - cPacket_MapChunk( const cPacket_MapChunk & a_Copy ); - cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const BLOCKTYPE * a_BlockData, const unsigned char * a_BiomeData); - ~cPacket_MapChunk(); - virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_PosX; - int m_PosZ; - bool m_bContiguous; - short m_BitMap1; - short m_BitMap2; - int m_CompressedSize; - int m_UnusedInt; - char * m_CompressedData; -}; - - - - + +#pragma once + +#include "cPacket.h" +#include "../ChunkDef.h" + + + + + +class cPacket_MapChunk : + public cPacket +{ +public: + cPacket_MapChunk() + : m_PosX( 0 ) + , m_PosZ( 0 ) + , m_bContiguous( false ) + , m_BitMap1( 0 ) + , m_BitMap2( 0 ) + , m_CompressedSize( 0 ) + , m_UnusedInt( 0 ) + , m_CompressedData( NULL ) + { m_PacketID = E_MAP_CHUNK; } + + cPacket_MapChunk( const cPacket_MapChunk & a_Copy ); + cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const BLOCKTYPE * a_BlockData, const unsigned char * a_BiomeData); + ~cPacket_MapChunk(); + virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_PosX; + int m_PosZ; + bool m_bContiguous; + short m_BitMap1; + short m_BitMap2; + int m_CompressedSize; + int m_UnusedInt; + char * m_CompressedData; +}; + + + + diff --git a/source/packets/cPacket_MultiBlock.cpp b/source/packets/cPacket_MultiBlock.cpp index cfa13c4d4..9ae175508 100644 --- a/source/packets/cPacket_MultiBlock.cpp +++ b/source/packets/cPacket_MultiBlock.cpp @@ -1,50 +1,50 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_MultiBlock.h" - - - - - -cPacket_MultiBlock::cPacket_MultiBlock( const cPacket_MultiBlock & a_Copy ) -{ - m_PacketID = E_MULTI_BLOCK; - m_ChunkX = a_Copy.m_ChunkX; - m_ChunkZ = a_Copy.m_ChunkZ; - m_NumBlocks = a_Copy.m_NumBlocks; - m_DataSize = a_Copy.m_DataSize; - m_Data = new sBlockChange[m_NumBlocks]; - memcpy( m_Data, a_Copy.m_Data, sizeof(sBlockChange)*m_NumBlocks ); -} - - - - - -cPacket_MultiBlock::~cPacket_MultiBlock() -{ - delete [] m_Data; -} - - - - - -void cPacket_MultiBlock::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_ChunkX); - AppendInteger(a_Data, m_ChunkZ); - AppendShort (a_Data, m_NumBlocks); - - AppendInteger(a_Data, m_DataSize); - for( int i = 0; i < m_NumBlocks; ++i ) - { - AppendInteger(a_Data, m_Data[i].Data); - } -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_MultiBlock.h" + + + + + +cPacket_MultiBlock::cPacket_MultiBlock( const cPacket_MultiBlock & a_Copy ) +{ + m_PacketID = E_MULTI_BLOCK; + m_ChunkX = a_Copy.m_ChunkX; + m_ChunkZ = a_Copy.m_ChunkZ; + m_NumBlocks = a_Copy.m_NumBlocks; + m_DataSize = a_Copy.m_DataSize; + m_Data = new sBlockChange[m_NumBlocks]; + memcpy( m_Data, a_Copy.m_Data, sizeof(sBlockChange)*m_NumBlocks ); +} + + + + + +cPacket_MultiBlock::~cPacket_MultiBlock() +{ + delete [] m_Data; +} + + + + + +void cPacket_MultiBlock::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_ChunkX); + AppendInteger(a_Data, m_ChunkZ); + AppendShort (a_Data, m_NumBlocks); + + AppendInteger(a_Data, m_DataSize); + for( int i = 0; i < m_NumBlocks; ++i ) + { + AppendInteger(a_Data, m_Data[i].Data); + } +} + + + + diff --git a/source/packets/cPacket_MultiBlock.h b/source/packets/cPacket_MultiBlock.h index 31cb96628..af3d24267 100644 --- a/source/packets/cPacket_MultiBlock.h +++ b/source/packets/cPacket_MultiBlock.h @@ -1,47 +1,47 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_MultiBlock : public cPacket -{ -public: - struct sBlockChange - { - sBlockChange() - : Data( 0 ) - {} - unsigned int Data; -// short Data; // 4bits metadata ... 12bits block ID -// short Coords; // 8bits Y ... 4bits Z ... 4bits X - }; - - cPacket_MultiBlock() - : m_ChunkX( 0 ) - , m_ChunkZ( 0 ) - , m_NumBlocks( 0 ) - , m_DataSize( 0 ) - , m_Data( NULL ) - { m_PacketID = E_MULTI_BLOCK; } - - cPacket_MultiBlock( const cPacket_MultiBlock & a_Copy ); - ~cPacket_MultiBlock(); - virtual cPacket* Clone() const { return new cPacket_MultiBlock(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_ChunkX; - int m_ChunkZ; - short m_NumBlocks; - - int m_DataSize; // Should be 4 * m_NumBlocks ?? - sBlockChange * m_Data; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_MultiBlock : public cPacket +{ +public: + struct sBlockChange + { + sBlockChange() + : Data( 0 ) + {} + unsigned int Data; +// short Data; // 4bits metadata ... 12bits block ID +// short Coords; // 8bits Y ... 4bits Z ... 4bits X + }; + + cPacket_MultiBlock() + : m_ChunkX( 0 ) + , m_ChunkZ( 0 ) + , m_NumBlocks( 0 ) + , m_DataSize( 0 ) + , m_Data( NULL ) + { m_PacketID = E_MULTI_BLOCK; } + + cPacket_MultiBlock( const cPacket_MultiBlock & a_Copy ); + ~cPacket_MultiBlock(); + virtual cPacket* Clone() const { return new cPacket_MultiBlock(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_ChunkX; + int m_ChunkZ; + short m_NumBlocks; + + int m_DataSize; // Should be 4 * m_NumBlocks ?? + sBlockChange * m_Data; +}; + + + + diff --git a/source/packets/cPacket_NamedEntitySpawn.cpp b/source/packets/cPacket_NamedEntitySpawn.cpp index 8b4b912d8..798376372 100644 --- a/source/packets/cPacket_NamedEntitySpawn.cpp +++ b/source/packets/cPacket_NamedEntitySpawn.cpp @@ -1,34 +1,34 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_NamedEntitySpawn.h" - - - - - -void cPacket_NamedEntitySpawn::Serialize(AString & a_Data) const -{ - short CurrentItem = m_CurrentItem; - ASSERT(CurrentItem >= 0); - if (CurrentItem <= 0) - { - CurrentItem = 0; - // Fix, to make sure no invalid values are sent. - // WARNING: HERE ITS 0, BUT IN EQUIP PACKET ITS -1 !! - } - - AppendByte (a_Data, m_PacketID); - AppendInteger (a_Data, m_UniqueID); - AppendString16(a_Data, m_PlayerName); - AppendInteger (a_Data, m_PosX); - AppendInteger (a_Data, m_PosY); - AppendInteger (a_Data, m_PosZ); - AppendByte (a_Data, m_Rotation); - AppendByte (a_Data, m_Pitch); - AppendShort (a_Data, CurrentItem); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_NamedEntitySpawn.h" + + + + + +void cPacket_NamedEntitySpawn::Serialize(AString & a_Data) const +{ + short CurrentItem = m_CurrentItem; + ASSERT(CurrentItem >= 0); + if (CurrentItem <= 0) + { + CurrentItem = 0; + // Fix, to make sure no invalid values are sent. + // WARNING: HERE ITS 0, BUT IN EQUIP PACKET ITS -1 !! + } + + AppendByte (a_Data, m_PacketID); + AppendInteger (a_Data, m_UniqueID); + AppendString16(a_Data, m_PlayerName); + AppendInteger (a_Data, m_PosX); + AppendInteger (a_Data, m_PosY); + AppendInteger (a_Data, m_PosZ); + AppendByte (a_Data, m_Rotation); + AppendByte (a_Data, m_Pitch); + AppendShort (a_Data, CurrentItem); +} + + + + diff --git a/source/packets/cPacket_NamedEntitySpawn.h b/source/packets/cPacket_NamedEntitySpawn.h index ceec10c35..365d28c37 100644 --- a/source/packets/cPacket_NamedEntitySpawn.h +++ b/source/packets/cPacket_NamedEntitySpawn.h @@ -1,40 +1,40 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_NamedEntitySpawn : public cPacket -{ -public: - cPacket_NamedEntitySpawn() - : m_UniqueID( 0 ) - , m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_Rotation( 0 ) - , m_Pitch( 0 ) - , m_CurrentItem( 0 ) - { m_PacketID = E_NAMED_ENTITY_SPAWN; } - virtual cPacket* Clone() const { return new cPacket_NamedEntitySpawn(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - AString m_PlayerName; - int m_PosX; // Pixel position, devide by 32 for block position - int m_PosY; - int m_PosZ; - char m_Rotation; - char m_Pitch; - short m_CurrentItem; - - static const unsigned int c_Size = 1 + 4 + 2 + 4 + 4 + 4 + 1 + 1 + 2; // Minimum size -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_NamedEntitySpawn : public cPacket +{ +public: + cPacket_NamedEntitySpawn() + : m_UniqueID( 0 ) + , m_PosX( 0 ) + , m_PosY( 0 ) + , m_PosZ( 0 ) + , m_Rotation( 0 ) + , m_Pitch( 0 ) + , m_CurrentItem( 0 ) + { m_PacketID = E_NAMED_ENTITY_SPAWN; } + virtual cPacket* Clone() const { return new cPacket_NamedEntitySpawn(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + AString m_PlayerName; + int m_PosX; // Pixel position, devide by 32 for block position + int m_PosY; + int m_PosZ; + char m_Rotation; + char m_Pitch; + short m_CurrentItem; + + static const unsigned int c_Size = 1 + 4 + 2 + 4 + 4 + 4 + 1 + 1 + 2; // Minimum size +}; + + + + diff --git a/source/packets/cPacket_PickupSpawn.cpp b/source/packets/cPacket_PickupSpawn.cpp index d8970650d..a1a60947d 100644 --- a/source/packets/cPacket_PickupSpawn.cpp +++ b/source/packets/cPacket_PickupSpawn.cpp @@ -1,47 +1,47 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_PickupSpawn.h" - - - - - -int cPacket_PickupSpawn::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Item, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Count, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Health, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Pitch, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Roll, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_PickupSpawn::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendShort (a_Data, m_Item); - AppendByte (a_Data, m_Count); - AppendShort (a_Data, m_Health); - AppendInteger(a_Data, m_PosX); - AppendInteger(a_Data, m_PosY); - AppendInteger(a_Data, m_PosZ); - AppendByte (a_Data, m_Rotation); - AppendByte (a_Data, m_Pitch); - AppendByte (a_Data, m_Roll); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_PickupSpawn.h" + + + + + +int cPacket_PickupSpawn::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_Item, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_Count, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_Health, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_Rotation, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_Pitch, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_Roll, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_PickupSpawn::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_UniqueID); + AppendShort (a_Data, m_Item); + AppendByte (a_Data, m_Count); + AppendShort (a_Data, m_Health); + AppendInteger(a_Data, m_PosX); + AppendInteger(a_Data, m_PosY); + AppendInteger(a_Data, m_PosZ); + AppendByte (a_Data, m_Rotation); + AppendByte (a_Data, m_Pitch); + AppendByte (a_Data, m_Roll); +} + + + + diff --git a/source/packets/cPacket_PickupSpawn.h b/source/packets/cPacket_PickupSpawn.h index d46999a5a..1c1a6c640 100644 --- a/source/packets/cPacket_PickupSpawn.h +++ b/source/packets/cPacket_PickupSpawn.h @@ -1,46 +1,46 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_PickupSpawn : public cPacket -{ -public: - cPacket_PickupSpawn() - : m_UniqueID( 0 ) - , m_Item( 0 ) - , m_Count( 0 ) - , m_Health( 0 ) - , m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_Rotation( 0 ) - , m_Pitch( 0 ) - , m_Roll( 0 ) - { m_PacketID = E_PICKUP_SPAWN; } - virtual cPacket* Clone() const { return new cPacket_PickupSpawn(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - short m_Item; - char m_Count; - short m_Health; - int m_PosX; - int m_PosY; - int m_PosZ; - char m_Rotation; - char m_Pitch; - char m_Roll; - - static const unsigned int c_Size = 1 + 4 + 2 + 1 + 2 + 4 + 4 + 4 + 1 + 1 + 1; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_PickupSpawn : public cPacket +{ +public: + cPacket_PickupSpawn() + : m_UniqueID( 0 ) + , m_Item( 0 ) + , m_Count( 0 ) + , m_Health( 0 ) + , m_PosX( 0 ) + , m_PosY( 0 ) + , m_PosZ( 0 ) + , m_Rotation( 0 ) + , m_Pitch( 0 ) + , m_Roll( 0 ) + { m_PacketID = E_PICKUP_SPAWN; } + virtual cPacket* Clone() const { return new cPacket_PickupSpawn(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + short m_Item; + char m_Count; + short m_Health; + int m_PosX; + int m_PosY; + int m_PosZ; + char m_Rotation; + char m_Pitch; + char m_Roll; + + static const unsigned int c_Size = 1 + 4 + 2 + 1 + 2 + 4 + 4 + 4 + 1 + 1 + 1; +}; + + + + diff --git a/source/packets/cPacket_Ping.h b/source/packets/cPacket_Ping.h index 0a0609aeb..0a856c7ec 100644 --- a/source/packets/cPacket_Ping.h +++ b/source/packets/cPacket_Ping.h @@ -1,24 +1,24 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_Ping : public cPacket -{ -public: - cPacket_Ping() - { m_PacketID = E_PING; } - virtual cPacket* Clone() const { return new cPacket_Ping(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override {return 0; } - - static const unsigned int c_Size = 1; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_Ping : public cPacket +{ +public: + cPacket_Ping() + { m_PacketID = E_PING; } + virtual cPacket* Clone() const { return new cPacket_Ping(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override {return 0; } + + static const unsigned int c_Size = 1; +}; + + + + diff --git a/source/packets/cPacket_Player.cpp b/source/packets/cPacket_Player.cpp index 86214d725..7d9a5de6b 100644 --- a/source/packets/cPacket_Player.cpp +++ b/source/packets/cPacket_Player.cpp @@ -1,243 +1,243 @@ - -// cPacket_Player.cpp - -/* Implements the player-related packets: - - PlayerAbilities (0xca) - - PlayerListItem (0xc9) - - PlayerLook (0x0c) - - PlayerMoveLook (0x0d) - - PlayerPosition (0x0b) -*/ - -#include "Globals.h" - -#include "cPacket_Player.h" -#include "../cPlayer.h" -#include "../cChatColor.h" - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPacket_PlayerAbilities: - -int cPacket_PlayerAbilities::Parse(const char * a_Data, int a_Size) -{ - if (a_Size < 4) - { - return PACKET_INCOMPLETE; - } - m_Invulnerable = (a_Data[0] != 0); - m_IsFlying = (a_Data[1] != 0); - m_CanFly = (a_Data[2] != 0); - m_InstaMine = (a_Data[3] != 0); - return 4; -} - - - - - -void cPacket_PlayerAbilities::Serialize(AString & a_Data) const -{ - char Data[5]; - Data[0] = m_PacketID; - Data[1] = (char)m_Invulnerable; - Data[2] = (char)m_IsFlying; - Data[3] = (char)m_CanFly; - Data[4] = (char)m_InstaMine; - a_Data.append(Data, 5); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPacket_PlayerListItem: - -cPacket_PlayerListItem::cPacket_PlayerListItem(const AString & a_PlayerName, bool a_Online, short a_Ping) -{ - m_PacketID = E_PLAYER_LIST_ITEM; - m_PlayerName = a_PlayerName; - m_Online = a_Online; - m_Ping = a_Ping; -} - - - - - -int cPacket_PlayerListItem::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadString16, m_PlayerName, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_Online, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Ping, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_PlayerListItem::Serialize(AString & a_Data) const -{ - AString PlayerName(m_PlayerName); - if (PlayerName.length() > 16) - { - PlayerName.erase(16); - } - else if (PlayerName.length() <= 14) - { - PlayerName += cChatColor::White; - } - - AppendByte (a_Data, m_PacketID); - AppendString16(a_Data, PlayerName); - AppendBool (a_Data, m_Online); - AppendShort (a_Data, m_Ping); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPacket_PlayerLook: - -cPacket_PlayerLook::cPacket_PlayerLook( cPlayer* a_Player ) -{ - m_PacketID = E_PLAYERLOOK; - m_Rotation = a_Player->GetRotation(); - m_Pitch = a_Player->GetPitch(); - m_bFlying = a_Player->GetFlying(); -} - - - - - -int cPacket_PlayerLook::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadFloat, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadFloat, m_Pitch, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_PlayerLook::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendFloat (a_Data, m_Rotation); - AppendFloat (a_Data, m_Pitch); - AppendBool (a_Data, m_bFlying); -} - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPacket_PlayerMoveLook: - -cPacket_PlayerMoveLook::cPacket_PlayerMoveLook( cPlayer* a_Player ) -{ - m_PacketID = E_PLAYERMOVELOOK; - m_PosX = a_Player->GetPosX(); - m_PosY = a_Player->GetPosY() + 1.65; - m_PosZ = a_Player->GetPosZ(); - m_Stance = a_Player->GetStance(); - m_Rotation = a_Player->GetRotation(); - m_Pitch = a_Player->GetPitch(); - m_bFlying = a_Player->GetFlying(); -} - - - - - -int cPacket_PlayerMoveLook::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadDouble, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_Stance, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadFloat, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadFloat, m_Pitch, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_PlayerMoveLook::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendDouble(a_Data, m_PosX); - AppendDouble(a_Data, m_PosY); - AppendDouble(a_Data, m_Stance); - AppendDouble(a_Data, m_PosZ); - AppendFloat (a_Data, m_Rotation); - AppendFloat (a_Data, m_Pitch); - AppendBool (a_Data, m_bFlying); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPacket_PlayerPosition: - -cPacket_PlayerPosition::cPacket_PlayerPosition( cPlayer* a_Player ) -{ - m_PacketID = E_PLAYERPOS; - - m_PosX = a_Player->GetPosX(); - m_PosY = a_Player->GetPosY() + 1.65; - m_PosZ = a_Player->GetPosZ(); - m_Stance = a_Player->GetStance(); - m_bFlying = a_Player->GetFlying(); -} - - - - - -int cPacket_PlayerPosition::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadDouble, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_Stance, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_PlayerPosition::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendDouble (a_Data, m_PosX); - AppendDouble (a_Data, m_PosY); - AppendDouble (a_Data, m_Stance); - AppendDouble (a_Data, m_PosZ); - AppendBool (a_Data, m_bFlying); -} - - - - + +// cPacket_Player.cpp + +/* Implements the player-related packets: + - PlayerAbilities (0xca) + - PlayerListItem (0xc9) + - PlayerLook (0x0c) + - PlayerMoveLook (0x0d) + - PlayerPosition (0x0b) +*/ + +#include "Globals.h" + +#include "cPacket_Player.h" +#include "../cPlayer.h" +#include "../cChatColor.h" + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPacket_PlayerAbilities: + +int cPacket_PlayerAbilities::Parse(const char * a_Data, int a_Size) +{ + if (a_Size < 4) + { + return PACKET_INCOMPLETE; + } + m_Invulnerable = (a_Data[0] != 0); + m_IsFlying = (a_Data[1] != 0); + m_CanFly = (a_Data[2] != 0); + m_InstaMine = (a_Data[3] != 0); + return 4; +} + + + + + +void cPacket_PlayerAbilities::Serialize(AString & a_Data) const +{ + char Data[5]; + Data[0] = m_PacketID; + Data[1] = (char)m_Invulnerable; + Data[2] = (char)m_IsFlying; + Data[3] = (char)m_CanFly; + Data[4] = (char)m_InstaMine; + a_Data.append(Data, 5); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPacket_PlayerListItem: + +cPacket_PlayerListItem::cPacket_PlayerListItem(const AString & a_PlayerName, bool a_Online, short a_Ping) +{ + m_PacketID = E_PLAYER_LIST_ITEM; + m_PlayerName = a_PlayerName; + m_Online = a_Online; + m_Ping = a_Ping; +} + + + + + +int cPacket_PlayerListItem::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadString16, m_PlayerName, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_Online, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_Ping, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_PlayerListItem::Serialize(AString & a_Data) const +{ + AString PlayerName(m_PlayerName); + if (PlayerName.length() > 16) + { + PlayerName.erase(16); + } + else if (PlayerName.length() <= 14) + { + PlayerName += cChatColor::White; + } + + AppendByte (a_Data, m_PacketID); + AppendString16(a_Data, PlayerName); + AppendBool (a_Data, m_Online); + AppendShort (a_Data, m_Ping); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPacket_PlayerLook: + +cPacket_PlayerLook::cPacket_PlayerLook( cPlayer* a_Player ) +{ + m_PacketID = E_PLAYERLOOK; + m_Rotation = a_Player->GetRotation(); + m_Pitch = a_Player->GetPitch(); + m_bFlying = a_Player->GetFlying(); +} + + + + + +int cPacket_PlayerLook::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadFloat, m_Rotation, TotalBytes); + HANDLE_PACKET_READ(ReadFloat, m_Pitch, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_PlayerLook::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendFloat (a_Data, m_Rotation); + AppendFloat (a_Data, m_Pitch); + AppendBool (a_Data, m_bFlying); +} + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPacket_PlayerMoveLook: + +cPacket_PlayerMoveLook::cPacket_PlayerMoveLook( cPlayer* a_Player ) +{ + m_PacketID = E_PLAYERMOVELOOK; + m_PosX = a_Player->GetPosX(); + m_PosY = a_Player->GetPosY() + 1.65; + m_PosZ = a_Player->GetPosZ(); + m_Stance = a_Player->GetStance(); + m_Rotation = a_Player->GetRotation(); + m_Pitch = a_Player->GetPitch(); + m_bFlying = a_Player->GetFlying(); +} + + + + + +int cPacket_PlayerMoveLook::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadDouble, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadDouble, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadDouble, m_Stance, TotalBytes); + HANDLE_PACKET_READ(ReadDouble, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadFloat, m_Rotation, TotalBytes); + HANDLE_PACKET_READ(ReadFloat, m_Pitch, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_PlayerMoveLook::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendDouble(a_Data, m_PosX); + AppendDouble(a_Data, m_PosY); + AppendDouble(a_Data, m_Stance); + AppendDouble(a_Data, m_PosZ); + AppendFloat (a_Data, m_Rotation); + AppendFloat (a_Data, m_Pitch); + AppendBool (a_Data, m_bFlying); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPacket_PlayerPosition: + +cPacket_PlayerPosition::cPacket_PlayerPosition( cPlayer* a_Player ) +{ + m_PacketID = E_PLAYERPOS; + + m_PosX = a_Player->GetPosX(); + m_PosY = a_Player->GetPosY() + 1.65; + m_PosZ = a_Player->GetPosZ(); + m_Stance = a_Player->GetStance(); + m_bFlying = a_Player->GetFlying(); +} + + + + + +int cPacket_PlayerPosition::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadDouble, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadDouble, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadDouble, m_Stance, TotalBytes); + HANDLE_PACKET_READ(ReadDouble, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_PlayerPosition::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendDouble (a_Data, m_PosX); + AppendDouble (a_Data, m_PosY); + AppendDouble (a_Data, m_Stance); + AppendDouble (a_Data, m_PosZ); + AppendBool (a_Data, m_bFlying); +} + + + + diff --git a/source/packets/cPacket_Player.h b/source/packets/cPacket_Player.h index ce88cc451..5b17feabf 100644 --- a/source/packets/cPacket_Player.h +++ b/source/packets/cPacket_Player.h @@ -1,150 +1,150 @@ - -// cPacket_Player.h - -/* Interfaces to the player-related packets: - - PlayerAbilities (0xca) - - PlayerListItem (0xc9) - - PlayerLook (0x0c) - - PlayerMoveLook (0x0d) - - PlayerPosition (0x0b) -*/ - -#pragma once - - - - - -#include "cPacket.h" - - - - - -// fwd: -class cPlayer; - - - - - -class cPacket_PlayerAbilities : public cPacket -{ -public: - cPacket_PlayerAbilities(void) { m_PacketID = E_PLAYER_LIST_ITEM; } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - virtual cPacket * Clone() const { return new cPacket_PlayerAbilities(*this); } - - bool m_Invulnerable; // Speculation - bool m_IsFlying; - bool m_CanFly; - bool m_InstaMine; // Speculation -} ; - - - - - -class cPacket_PlayerListItem : public cPacket -{ -public: - cPacket_PlayerListItem() { m_PacketID = E_PLAYER_LIST_ITEM; } - cPacket_PlayerListItem(const AString & a_PlayerName, bool a_Online, short a_Ping); - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - virtual cPacket* Clone() const { return new cPacket_PlayerListItem(*this); } - - AString m_PlayerName; // Supports chat coloring, limited to 16 characters. - bool m_Online; - short m_Ping; -} ; - - - - - -class cPacket_PlayerLook : public cPacket -{ -public: - cPacket_PlayerLook() - : m_Rotation( 0 ) - , m_Pitch( 0 ) - , m_bFlying( false ) - { m_PacketID = E_PLAYERLOOK; } - cPacket_PlayerLook( cPlayer* a_Player ); - virtual cPacket* Clone() const { return new cPacket_PlayerLook(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - float m_Rotation; - float m_Pitch; - bool m_bFlying; // Yeah.. wtf -} ; - - - - - -class cPacket_PlayerMoveLook : public cPacket -{ -public: - cPacket_PlayerMoveLook() - : m_PosX( 0.0 ) - , m_PosY( 0.0 ) - , m_Stance( 0.0 ) - , m_PosZ( 0.0 ) - , m_Rotation( 0.f ) - , m_Pitch( 0.f ) - , m_bFlying( false ) - { m_PacketID = E_PLAYERMOVELOOK; } - cPacket_PlayerMoveLook( cPlayer* a_Player ); - virtual cPacket* Clone() const { return new cPacket_PlayerMoveLook(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - double m_PosX; - double m_PosY; - double m_Stance; - double m_PosZ; - float m_Rotation; - float m_Pitch; - bool m_bFlying; // Yeah.. wtf -} ; - - - - - -class cPacket_PlayerPosition : public cPacket -{ -public: - cPacket_PlayerPosition( cPlayer* a_Player ); - cPacket_PlayerPosition() - : m_PosX( 0.0 ) - , m_PosY( 0.0 ) - , m_Stance( 0.0 ) - , m_PosZ( 0.0 ) - , m_bFlying( false ) - { m_PacketID = E_PLAYERPOS; } - virtual cPacket* Clone() const { return new cPacket_PlayerPosition(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - double m_PosX; - double m_PosY; - double m_Stance; - double m_PosZ; - bool m_bFlying; // Yeah.. wtf -} ; - - - - + +// cPacket_Player.h + +/* Interfaces to the player-related packets: + - PlayerAbilities (0xca) + - PlayerListItem (0xc9) + - PlayerLook (0x0c) + - PlayerMoveLook (0x0d) + - PlayerPosition (0x0b) +*/ + +#pragma once + + + + + +#include "cPacket.h" + + + + + +// fwd: +class cPlayer; + + + + + +class cPacket_PlayerAbilities : public cPacket +{ +public: + cPacket_PlayerAbilities(void) { m_PacketID = E_PLAYER_LIST_ITEM; } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + virtual cPacket * Clone() const { return new cPacket_PlayerAbilities(*this); } + + bool m_Invulnerable; // Speculation + bool m_IsFlying; + bool m_CanFly; + bool m_InstaMine; // Speculation +} ; + + + + + +class cPacket_PlayerListItem : public cPacket +{ +public: + cPacket_PlayerListItem() { m_PacketID = E_PLAYER_LIST_ITEM; } + cPacket_PlayerListItem(const AString & a_PlayerName, bool a_Online, short a_Ping); + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + virtual cPacket* Clone() const { return new cPacket_PlayerListItem(*this); } + + AString m_PlayerName; // Supports chat coloring, limited to 16 characters. + bool m_Online; + short m_Ping; +} ; + + + + + +class cPacket_PlayerLook : public cPacket +{ +public: + cPacket_PlayerLook() + : m_Rotation( 0 ) + , m_Pitch( 0 ) + , m_bFlying( false ) + { m_PacketID = E_PLAYERLOOK; } + cPacket_PlayerLook( cPlayer* a_Player ); + virtual cPacket* Clone() const { return new cPacket_PlayerLook(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + float m_Rotation; + float m_Pitch; + bool m_bFlying; // Yeah.. wtf +} ; + + + + + +class cPacket_PlayerMoveLook : public cPacket +{ +public: + cPacket_PlayerMoveLook() + : m_PosX( 0.0 ) + , m_PosY( 0.0 ) + , m_Stance( 0.0 ) + , m_PosZ( 0.0 ) + , m_Rotation( 0.f ) + , m_Pitch( 0.f ) + , m_bFlying( false ) + { m_PacketID = E_PLAYERMOVELOOK; } + cPacket_PlayerMoveLook( cPlayer* a_Player ); + virtual cPacket* Clone() const { return new cPacket_PlayerMoveLook(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + double m_PosX; + double m_PosY; + double m_Stance; + double m_PosZ; + float m_Rotation; + float m_Pitch; + bool m_bFlying; // Yeah.. wtf +} ; + + + + + +class cPacket_PlayerPosition : public cPacket +{ +public: + cPacket_PlayerPosition( cPlayer* a_Player ); + cPacket_PlayerPosition() + : m_PosX( 0.0 ) + , m_PosY( 0.0 ) + , m_Stance( 0.0 ) + , m_PosZ( 0.0 ) + , m_bFlying( false ) + { m_PacketID = E_PLAYERPOS; } + virtual cPacket* Clone() const { return new cPacket_PlayerPosition(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + double m_PosX; + double m_PosY; + double m_Stance; + double m_PosZ; + bool m_bFlying; // Yeah.. wtf +} ; + + + + diff --git a/source/packets/cPacket_PreChunk.cpp b/source/packets/cPacket_PreChunk.cpp index a792ce124..f7824bba2 100644 --- a/source/packets/cPacket_PreChunk.cpp +++ b/source/packets/cPacket_PreChunk.cpp @@ -1,20 +1,20 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_PreChunk.h" - - - - - -void cPacket_PreChunk::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_PosX); - AppendInteger(a_Data, m_PosZ); - AppendBool (a_Data, m_bLoad); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_PreChunk.h" + + + + + +void cPacket_PreChunk::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_PosX); + AppendInteger(a_Data, m_PosZ); + AppendBool (a_Data, m_bLoad); +} + + + + diff --git a/source/packets/cPacket_PreChunk.h b/source/packets/cPacket_PreChunk.h index cc8147c4a..902fa2a02 100644 --- a/source/packets/cPacket_PreChunk.h +++ b/source/packets/cPacket_PreChunk.h @@ -1,36 +1,36 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_PreChunk: public cPacket -{ -public: - cPacket_PreChunk() - : m_PosX( 0 ) - , m_PosZ( 0 ) - , m_bLoad( false ) - { m_PacketID = E_PRE_CHUNK; } - cPacket_PreChunk( int a_PosX, int a_PosZ, bool a_bLoad ) - : m_PosX( a_PosX ) - , m_PosZ( a_PosZ ) - , m_bLoad( a_bLoad ) - { m_PacketID = E_PRE_CHUNK; } - virtual cPacket* Clone() const { return new cPacket_PreChunk(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_PosX; - int m_PosZ; - bool m_bLoad; - - static const unsigned int c_Size = 10; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_PreChunk: public cPacket +{ +public: + cPacket_PreChunk() + : m_PosX( 0 ) + , m_PosZ( 0 ) + , m_bLoad( false ) + { m_PacketID = E_PRE_CHUNK; } + cPacket_PreChunk( int a_PosX, int a_PosZ, bool a_bLoad ) + : m_PosX( a_PosX ) + , m_PosZ( a_PosZ ) + , m_bLoad( a_bLoad ) + { m_PacketID = E_PRE_CHUNK; } + virtual cPacket* Clone() const { return new cPacket_PreChunk(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_PosX; + int m_PosZ; + bool m_bLoad; + + static const unsigned int c_Size = 10; +}; + + + + diff --git a/source/packets/cPacket_RelativeEntityMove.cpp b/source/packets/cPacket_RelativeEntityMove.cpp index c4d0f3196..de3746024 100644 --- a/source/packets/cPacket_RelativeEntityMove.cpp +++ b/source/packets/cPacket_RelativeEntityMove.cpp @@ -1,21 +1,21 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_RelativeEntityMove.h" - - - - - -void cPacket_RelativeEntityMove::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_MoveX); - AppendByte (a_Data, m_MoveY); - AppendByte (a_Data, m_MoveZ); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_RelativeEntityMove.h" + + + + + +void cPacket_RelativeEntityMove::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_UniqueID); + AppendByte (a_Data, m_MoveX); + AppendByte (a_Data, m_MoveY); + AppendByte (a_Data, m_MoveZ); +} + + + + diff --git a/source/packets/cPacket_RelativeEntityMove.h b/source/packets/cPacket_RelativeEntityMove.h index 9ccf0d95f..7dd2cbdbc 100644 --- a/source/packets/cPacket_RelativeEntityMove.h +++ b/source/packets/cPacket_RelativeEntityMove.h @@ -1,33 +1,33 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_RelativeEntityMove : public cPacket -{ -public: - cPacket_RelativeEntityMove() - : m_UniqueID( 0 ) - , m_MoveX( 0 ) - , m_MoveY( 0 ) - , m_MoveZ( 0 ) - { m_PacketID = E_REL_ENT_MOVE; } - virtual cPacket* Clone() const { return new cPacket_RelativeEntityMove(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_MoveX; // Pixels, devide by 32 for block - char m_MoveY; - char m_MoveZ; - - static const unsigned int c_Size = 1 + 4 + 1 + 1 + 1; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_RelativeEntityMove : public cPacket +{ +public: + cPacket_RelativeEntityMove() + : m_UniqueID( 0 ) + , m_MoveX( 0 ) + , m_MoveY( 0 ) + , m_MoveZ( 0 ) + { m_PacketID = E_REL_ENT_MOVE; } + virtual cPacket* Clone() const { return new cPacket_RelativeEntityMove(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + char m_MoveX; // Pixels, devide by 32 for block + char m_MoveY; + char m_MoveZ; + + static const unsigned int c_Size = 1 + 4 + 1 + 1 + 1; +}; + + + + diff --git a/source/packets/cPacket_RelativeEntityMoveLook.cpp b/source/packets/cPacket_RelativeEntityMoveLook.cpp index 1e8a9ae6c..fad2c0620 100644 --- a/source/packets/cPacket_RelativeEntityMoveLook.cpp +++ b/source/packets/cPacket_RelativeEntityMoveLook.cpp @@ -1,24 +1,24 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_RelativeEntityMoveLook.h" - - - - - -void cPacket_RelativeEntityMoveLook::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_MoveX); - AppendByte (a_Data, m_MoveY); - AppendByte (a_Data, m_MoveZ); - AppendByte (a_Data, m_Yaw); - AppendByte (a_Data, m_Pitch); -} - - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_RelativeEntityMoveLook.h" + + + + + +void cPacket_RelativeEntityMoveLook::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_UniqueID); + AppendByte (a_Data, m_MoveX); + AppendByte (a_Data, m_MoveY); + AppendByte (a_Data, m_MoveZ); + AppendByte (a_Data, m_Yaw); + AppendByte (a_Data, m_Pitch); +} + + + + + diff --git a/source/packets/cPacket_RelativeEntityMoveLook.h b/source/packets/cPacket_RelativeEntityMoveLook.h index 79cb1a7eb..8fa6bf015 100644 --- a/source/packets/cPacket_RelativeEntityMoveLook.h +++ b/source/packets/cPacket_RelativeEntityMoveLook.h @@ -1,37 +1,37 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_RelativeEntityMoveLook : public cPacket -{ -public: - cPacket_RelativeEntityMoveLook() - : m_UniqueID( 0 ) - , m_MoveX( 0 ) - , m_MoveY( 0 ) - , m_MoveZ( 0 ) - , m_Yaw( 0 ) - , m_Pitch( 0 ) - { m_PacketID = E_REL_ENT_MOVE_LOOK; } - virtual cPacket* Clone() const { return new cPacket_RelativeEntityMoveLook(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_MoveX; // Pixels, divide by 32 for block - char m_MoveY; - char m_MoveZ; - char m_Yaw; - char m_Pitch; - - static const unsigned int c_Size = 1 + 4 + 1 + 1 + 1 + 1 + 1; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_RelativeEntityMoveLook : public cPacket +{ +public: + cPacket_RelativeEntityMoveLook() + : m_UniqueID( 0 ) + , m_MoveX( 0 ) + , m_MoveY( 0 ) + , m_MoveZ( 0 ) + , m_Yaw( 0 ) + , m_Pitch( 0 ) + { m_PacketID = E_REL_ENT_MOVE_LOOK; } + virtual cPacket* Clone() const { return new cPacket_RelativeEntityMoveLook(*this); } + + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + char m_MoveX; // Pixels, divide by 32 for block + char m_MoveY; + char m_MoveZ; + char m_Yaw; + char m_Pitch; + + static const unsigned int c_Size = 1 + 4 + 1 + 1 + 1 + 1 + 1; +}; + + + + diff --git a/source/packets/cPacket_Respawn.cpp b/source/packets/cPacket_Respawn.cpp index a6b3b5bc4..657fd70b5 100644 --- a/source/packets/cPacket_Respawn.cpp +++ b/source/packets/cPacket_Respawn.cpp @@ -1,39 +1,39 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_Respawn.h" - - - - - -void cPacket_Respawn::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - - AppendInteger (a_Data, m_Dimension); - AppendByte (a_Data, m_Difficulty); - AppendByte (a_Data, m_CreativeMode); - AppendShort (a_Data, m_WorldHeight); - AppendString16(a_Data, m_LevelType); -} - - - - - -int cPacket_Respawn::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - - HANDLE_PACKET_READ(ReadInteger, m_Dimension, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Difficulty, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_CreativeMode, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_WorldHeight, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_LevelType, TotalBytes); - return TotalBytes; -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_Respawn.h" + + + + + +void cPacket_Respawn::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + + AppendInteger (a_Data, m_Dimension); + AppendByte (a_Data, m_Difficulty); + AppendByte (a_Data, m_CreativeMode); + AppendShort (a_Data, m_WorldHeight); + AppendString16(a_Data, m_LevelType); +} + + + + + +int cPacket_Respawn::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + + HANDLE_PACKET_READ(ReadInteger, m_Dimension, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_Difficulty, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_CreativeMode, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_WorldHeight, TotalBytes); + HANDLE_PACKET_READ(ReadString16, m_LevelType, TotalBytes); + return TotalBytes; +} + + + + diff --git a/source/packets/cPacket_Respawn.h b/source/packets/cPacket_Respawn.h index b95ecc384..302dbe25e 100644 --- a/source/packets/cPacket_Respawn.h +++ b/source/packets/cPacket_Respawn.h @@ -1,37 +1,37 @@ - -#pragma once - -#include "cPacket.h" - -#include "cPacket_Login.h" - - - - - -class cPacket_Respawn : public cPacket -{ -public: - cPacket_Respawn() - : m_Dimension( 0 ) - , m_Difficulty( 0 ) - , m_CreativeMode( 0 ) - , m_WorldHeight( 0 ) - , m_LevelType( cPacket_Login::LEVEL_TYPE_DEFAULT ) - { m_PacketID = E_RESPAWN; } - - virtual cPacket* Clone() const { return new cPacket_Respawn( *this ); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - int m_Dimension; - char m_Difficulty; - char m_CreativeMode; - short m_WorldHeight; - AString m_LevelType; -}; - - - - + +#pragma once + +#include "cPacket.h" + +#include "cPacket_Login.h" + + + + + +class cPacket_Respawn : public cPacket +{ +public: + cPacket_Respawn() + : m_Dimension( 0 ) + , m_Difficulty( 0 ) + , m_CreativeMode( 0 ) + , m_WorldHeight( 0 ) + , m_LevelType( cPacket_Login::LEVEL_TYPE_DEFAULT ) + { m_PacketID = E_RESPAWN; } + + virtual cPacket* Clone() const { return new cPacket_Respawn( *this ); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + int m_Dimension; + char m_Difficulty; + char m_CreativeMode; + short m_WorldHeight; + AString m_LevelType; +}; + + + + diff --git a/source/packets/cPacket_SpawnMob.cpp b/source/packets/cPacket_SpawnMob.cpp index d3f1850b3..47339c7e0 100644 --- a/source/packets/cPacket_SpawnMob.cpp +++ b/source/packets/cPacket_SpawnMob.cpp @@ -1,75 +1,75 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_SpawnMob.h" -#include "../Vector3i.h" - - - - - -cPacket_SpawnMob::~cPacket_SpawnMob() -{ - if( m_MetaData ) delete [] m_MetaData; - delete m_Pos; -} - - - - - -cPacket_SpawnMob::cPacket_SpawnMob() - : m_UniqueID( 0 ) - , m_Type( 0 ) - , m_Pos( new Vector3i() ) - , m_Yaw( 0 ) - , m_Pitch( 0 ) - , m_MetaDataSize( 0 ) - , m_MetaData( 0 ) - , m_HeadYaw(0) -{ - m_PacketID = E_SPAWN_MOB; -} - - - - - -cPacket_SpawnMob::cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone ) -{ - m_Pos = new Vector3i(); - - m_PacketID = E_SPAWN_MOB; - m_UniqueID = a_Clone.m_UniqueID; - m_Type = a_Clone.m_Type; - *m_Pos = *a_Clone.m_Pos; - m_Yaw = a_Clone.m_Yaw; - m_Pitch = a_Clone.m_Pitch; - m_HeadYaw = a_Clone.m_HeadYaw; - - m_MetaDataSize = a_Clone.m_MetaDataSize; - m_MetaData = new char[m_MetaDataSize]; - memcpy( m_MetaData, a_Clone.m_MetaData, sizeof( char ) * m_MetaDataSize ); -} - - - - - -void cPacket_SpawnMob::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger (a_Data, m_UniqueID); - AppendByte (a_Data, m_Type); - AppendInteger (a_Data, m_Pos->x); - AppendInteger (a_Data, m_Pos->y); - AppendInteger (a_Data, m_Pos->z); - AppendByte (a_Data, m_Yaw); - AppendByte (a_Data, m_Pitch); - AppendByte (a_Data, m_HeadYaw); - AppendData (a_Data, m_MetaData, m_MetaDataSize); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_SpawnMob.h" +#include "../Vector3i.h" + + + + + +cPacket_SpawnMob::~cPacket_SpawnMob() +{ + if( m_MetaData ) delete [] m_MetaData; + delete m_Pos; +} + + + + + +cPacket_SpawnMob::cPacket_SpawnMob() + : m_UniqueID( 0 ) + , m_Type( 0 ) + , m_Pos( new Vector3i() ) + , m_Yaw( 0 ) + , m_Pitch( 0 ) + , m_MetaDataSize( 0 ) + , m_MetaData( 0 ) + , m_HeadYaw(0) +{ + m_PacketID = E_SPAWN_MOB; +} + + + + + +cPacket_SpawnMob::cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone ) +{ + m_Pos = new Vector3i(); + + m_PacketID = E_SPAWN_MOB; + m_UniqueID = a_Clone.m_UniqueID; + m_Type = a_Clone.m_Type; + *m_Pos = *a_Clone.m_Pos; + m_Yaw = a_Clone.m_Yaw; + m_Pitch = a_Clone.m_Pitch; + m_HeadYaw = a_Clone.m_HeadYaw; + + m_MetaDataSize = a_Clone.m_MetaDataSize; + m_MetaData = new char[m_MetaDataSize]; + memcpy( m_MetaData, a_Clone.m_MetaData, sizeof( char ) * m_MetaDataSize ); +} + + + + + +void cPacket_SpawnMob::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger (a_Data, m_UniqueID); + AppendByte (a_Data, m_Type); + AppendInteger (a_Data, m_Pos->x); + AppendInteger (a_Data, m_Pos->y); + AppendInteger (a_Data, m_Pos->z); + AppendByte (a_Data, m_Yaw); + AppendByte (a_Data, m_Pitch); + AppendByte (a_Data, m_HeadYaw); + AppendData (a_Data, m_MetaData, m_MetaDataSize); +} + + + + diff --git a/source/packets/cPacket_SpawnMob.h b/source/packets/cPacket_SpawnMob.h index ff579af99..bc7fbe235 100644 --- a/source/packets/cPacket_SpawnMob.h +++ b/source/packets/cPacket_SpawnMob.h @@ -1,39 +1,39 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class Vector3i; - - - - - -class cPacket_SpawnMob : public cPacket -{ -public: - cPacket_SpawnMob(); - cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone ); - virtual cPacket* Clone() const { return new cPacket_SpawnMob( *this ); } - ~cPacket_SpawnMob(); - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_Type; - Vector3i* m_Pos; - char m_Yaw; - char m_Pitch; - char m_HeadYaw; - - unsigned int m_MetaDataSize; - char * m_MetaData; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class Vector3i; + + + + + +class cPacket_SpawnMob : public cPacket +{ +public: + cPacket_SpawnMob(); + cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone ); + virtual cPacket* Clone() const { return new cPacket_SpawnMob( *this ); } + ~cPacket_SpawnMob(); + + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + char m_Type; + Vector3i* m_Pos; + char m_Yaw; + char m_Pitch; + char m_HeadYaw; + + unsigned int m_MetaDataSize; + char * m_MetaData; +}; + + + + diff --git a/source/packets/cPacket_TeleportEntity.cpp b/source/packets/cPacket_TeleportEntity.cpp index a888f009d..396095037 100644 --- a/source/packets/cPacket_TeleportEntity.cpp +++ b/source/packets/cPacket_TeleportEntity.cpp @@ -1,41 +1,41 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_TeleportEntity.h" - -#include "../cEntity.h" - - - - - -cPacket_TeleportEntity::cPacket_TeleportEntity(cEntity* a_Client) -{ - m_PacketID = E_ENT_TELEPORT; - - m_UniqueID = a_Client->GetUniqueID(); - m_PosX = (int)(a_Client->GetPosX() * 32); - m_PosY = (int)(a_Client->GetPosY() * 32); - m_PosZ = (int)(a_Client->GetPosZ() * 32); - m_Rotation = (char)((a_Client->GetRotation() / 360.f) * 256); - m_Pitch = (char)((a_Client->GetPitch() / 360.f) * 256); -} - - - - - -void cPacket_TeleportEntity::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendInteger(a_Data, m_PosX); - AppendInteger(a_Data, m_PosY); - AppendInteger(a_Data, m_PosZ); - AppendByte (a_Data, m_Rotation); - AppendByte (a_Data, m_Pitch); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_TeleportEntity.h" + +#include "../cEntity.h" + + + + + +cPacket_TeleportEntity::cPacket_TeleportEntity(cEntity* a_Client) +{ + m_PacketID = E_ENT_TELEPORT; + + m_UniqueID = a_Client->GetUniqueID(); + m_PosX = (int)(a_Client->GetPosX() * 32); + m_PosY = (int)(a_Client->GetPosY() * 32); + m_PosZ = (int)(a_Client->GetPosZ() * 32); + m_Rotation = (char)((a_Client->GetRotation() / 360.f) * 256); + m_Pitch = (char)((a_Client->GetPitch() / 360.f) * 256); +} + + + + + +void cPacket_TeleportEntity::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger(a_Data, m_UniqueID); + AppendInteger(a_Data, m_PosX); + AppendInteger(a_Data, m_PosY); + AppendInteger(a_Data, m_PosZ); + AppendByte (a_Data, m_Rotation); + AppendByte (a_Data, m_Pitch); +} + + + + diff --git a/source/packets/cPacket_TeleportEntity.h b/source/packets/cPacket_TeleportEntity.h index 0cff50a85..d0504f901 100644 --- a/source/packets/cPacket_TeleportEntity.h +++ b/source/packets/cPacket_TeleportEntity.h @@ -1,39 +1,39 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cEntity; -class cPacket_TeleportEntity : public cPacket -{ -public: - cPacket_TeleportEntity() - : m_UniqueID( 0 ) - , m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_Rotation( 0 ) - , m_Pitch( 0 ) - { m_PacketID = E_ENT_TELEPORT; } - virtual cPacket* Clone() const { return new cPacket_TeleportEntity(*this); } - cPacket_TeleportEntity(cEntity* a_Client); - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - int m_PosX; // Pixel position, divide by 32 for block position - int m_PosY; - int m_PosZ; - char m_Rotation; - char m_Pitch; - - static const unsigned int c_Size = 1 + 4 + 4 + 4 + 4 + 1 + 1; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cEntity; +class cPacket_TeleportEntity : public cPacket +{ +public: + cPacket_TeleportEntity() + : m_UniqueID( 0 ) + , m_PosX( 0 ) + , m_PosY( 0 ) + , m_PosZ( 0 ) + , m_Rotation( 0 ) + , m_Pitch( 0 ) + { m_PacketID = E_ENT_TELEPORT; } + virtual cPacket* Clone() const { return new cPacket_TeleportEntity(*this); } + cPacket_TeleportEntity(cEntity* a_Client); + + virtual void Serialize(AString & a_Data) const override; + + int m_UniqueID; + int m_PosX; // Pixel position, divide by 32 for block position + int m_PosY; + int m_PosZ; + char m_Rotation; + char m_Pitch; + + static const unsigned int c_Size = 1 + 4 + 4 + 4 + 4 + 1 + 1; +}; + + + + diff --git a/source/packets/cPacket_TimeUpdate.cpp b/source/packets/cPacket_TimeUpdate.cpp index a0bf05677..be54e1484 100644 --- a/source/packets/cPacket_TimeUpdate.cpp +++ b/source/packets/cPacket_TimeUpdate.cpp @@ -1,29 +1,29 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_TimeUpdate.h" - - - - - -int cPacket_TimeUpdate::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadLong, m_Time, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_TimeUpdate::Serialize(AString & a_Data) const -{ - AppendByte(a_Data, m_PacketID); - AppendLong(a_Data, m_Time); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_TimeUpdate.h" + + + + + +int cPacket_TimeUpdate::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadLong, m_Time, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_TimeUpdate::Serialize(AString & a_Data) const +{ + AppendByte(a_Data, m_PacketID); + AppendLong(a_Data, m_Time); +} + + + + diff --git a/source/packets/cPacket_TimeUpdate.h b/source/packets/cPacket_TimeUpdate.h index 1cc66c2f9..8864c9b00 100644 --- a/source/packets/cPacket_TimeUpdate.h +++ b/source/packets/cPacket_TimeUpdate.h @@ -1,29 +1,29 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_TimeUpdate : public cPacket -{ -public: - cPacket_TimeUpdate() - : m_Time( 0 ) - { m_PacketID = E_UPDATE_TIME; } - cPacket_TimeUpdate( long long a_Time ) { m_PacketID = E_UPDATE_TIME; m_Time = a_Time; } - virtual cPacket* Clone() const { return new cPacket_TimeUpdate(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - long long m_Time; - - static const unsigned int c_Size = 1 + 8; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_TimeUpdate : public cPacket +{ +public: + cPacket_TimeUpdate() + : m_Time( 0 ) + { m_PacketID = E_UPDATE_TIME; } + cPacket_TimeUpdate( long long a_Time ) { m_PacketID = E_UPDATE_TIME; m_Time = a_Time; } + virtual cPacket* Clone() const { return new cPacket_TimeUpdate(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + long long m_Time; + + static const unsigned int c_Size = 1 + 8; +}; + + + + diff --git a/source/packets/cPacket_UpdateHealth.cpp b/source/packets/cPacket_UpdateHealth.cpp index 4380e25d6..ff54b6530 100644 --- a/source/packets/cPacket_UpdateHealth.cpp +++ b/source/packets/cPacket_UpdateHealth.cpp @@ -1,20 +1,20 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_UpdateHealth.h" - - - - - -void cPacket_UpdateHealth::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendShort(a_Data, m_Health); - AppendShort(a_Data, m_Food); - AppendFloat(a_Data, m_Saturation); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_UpdateHealth.h" + + + + + +void cPacket_UpdateHealth::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendShort(a_Data, m_Health); + AppendShort(a_Data, m_Food); + AppendFloat(a_Data, m_Saturation); +} + + + + diff --git a/source/packets/cPacket_UpdateHealth.h b/source/packets/cPacket_UpdateHealth.h index 3a6135e07..67fd32399 100644 --- a/source/packets/cPacket_UpdateHealth.h +++ b/source/packets/cPacket_UpdateHealth.h @@ -1,32 +1,32 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_UpdateHealth : public cPacket -{ -public: - cPacket_UpdateHealth() - : m_Health( 0 ) - , m_Food( 0 ) - , m_Saturation( 0.f ) - { m_PacketID = E_UPDATE_HEALTH; } - cPacket_UpdateHealth( short a_Health ) { m_Health = a_Health; m_PacketID = E_UPDATE_HEALTH; } - virtual cPacket* Clone() const { return new cPacket_UpdateHealth( *this ); } - - virtual void Serialize(AString & a_Data) const override; - - short m_Health; - short m_Food; - float m_Saturation; - - static const unsigned int c_Size = 1 + 2 + 2 + 4; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_UpdateHealth : public cPacket +{ +public: + cPacket_UpdateHealth() + : m_Health( 0 ) + , m_Food( 0 ) + , m_Saturation( 0.f ) + { m_PacketID = E_UPDATE_HEALTH; } + cPacket_UpdateHealth( short a_Health ) { m_Health = a_Health; m_PacketID = E_UPDATE_HEALTH; } + virtual cPacket* Clone() const { return new cPacket_UpdateHealth( *this ); } + + virtual void Serialize(AString & a_Data) const override; + + short m_Health; + short m_Food; + float m_Saturation; + + static const unsigned int c_Size = 1 + 2 + 2 + 4; +}; + + + + diff --git a/source/packets/cPacket_UpdateSign.cpp b/source/packets/cPacket_UpdateSign.cpp index 723fca6af..a3ea53968 100644 --- a/source/packets/cPacket_UpdateSign.cpp +++ b/source/packets/cPacket_UpdateSign.cpp @@ -1,41 +1,41 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_UpdateSign.h" - - - - - -int cPacket_UpdateSign::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Line1, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Line2, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Line3, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Line4, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_UpdateSign::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger (a_Data, m_PosX); - AppendShort (a_Data, m_PosY); - AppendInteger (a_Data, m_PosZ); - AppendString16(a_Data, m_Line1); - AppendString16(a_Data, m_Line2); - AppendString16(a_Data, m_Line3); - AppendString16(a_Data, m_Line4); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_UpdateSign.h" + + + + + +int cPacket_UpdateSign::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadString16, m_Line1, TotalBytes); + HANDLE_PACKET_READ(ReadString16, m_Line2, TotalBytes); + HANDLE_PACKET_READ(ReadString16, m_Line3, TotalBytes); + HANDLE_PACKET_READ(ReadString16, m_Line4, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_UpdateSign::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendInteger (a_Data, m_PosX); + AppendShort (a_Data, m_PosY); + AppendInteger (a_Data, m_PosZ); + AppendString16(a_Data, m_Line1); + AppendString16(a_Data, m_Line2); + AppendString16(a_Data, m_Line3); + AppendString16(a_Data, m_Line4); +} + + + + diff --git a/source/packets/cPacket_UpdateSign.h b/source/packets/cPacket_UpdateSign.h index 1e4da6471..b2c0effad 100644 --- a/source/packets/cPacket_UpdateSign.h +++ b/source/packets/cPacket_UpdateSign.h @@ -1,36 +1,36 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_UpdateSign : public cPacket -{ -public: - cPacket_UpdateSign() - : m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - { m_PacketID = E_UPDATE_SIGN; } - virtual cPacket* Clone() const { return new cPacket_UpdateSign( *this ); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - int m_PosX; - short m_PosY; - int m_PosZ; - AString m_Line1; - AString m_Line2; - AString m_Line3; - AString m_Line4; - - static const unsigned int c_Size = 1 + 4 + 2 + 4 + 2 + 2 + 2 + 2; // minimum size -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_UpdateSign : public cPacket +{ +public: + cPacket_UpdateSign() + : m_PosX( 0 ) + , m_PosY( 0 ) + , m_PosZ( 0 ) + { m_PacketID = E_UPDATE_SIGN; } + virtual cPacket* Clone() const { return new cPacket_UpdateSign( *this ); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + int m_PosX; + short m_PosY; + int m_PosZ; + AString m_Line1; + AString m_Line2; + AString m_Line3; + AString m_Line4; + + static const unsigned int c_Size = 1 + 4 + 2 + 4 + 2 + 2 + 2 + 2; // minimum size +}; + + + + diff --git a/source/packets/cPacket_UseEntity.cpp b/source/packets/cPacket_UseEntity.cpp index b131cb4fa..6f296e96b 100644 --- a/source/packets/cPacket_UseEntity.cpp +++ b/source/packets/cPacket_UseEntity.cpp @@ -1,21 +1,21 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_UseEntity.h" - - - - - -int cPacket_UseEntity::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_TargetID, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bLeftClick, TotalBytes); - return TotalBytes; -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_UseEntity.h" + + + + + +int cPacket_UseEntity::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes); + HANDLE_PACKET_READ(ReadInteger, m_TargetID, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_bLeftClick, TotalBytes); + return TotalBytes; +} + + + + diff --git a/source/packets/cPacket_UseEntity.h b/source/packets/cPacket_UseEntity.h index a81352664..7a35bd54c 100644 --- a/source/packets/cPacket_UseEntity.h +++ b/source/packets/cPacket_UseEntity.h @@ -1,31 +1,31 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_UseEntity : public cPacket -{ -public: - cPacket_UseEntity() - : m_UniqueID( 0 ) - , m_TargetID( 0 ) - , m_bLeftClick( false ) - { m_PacketID = E_USE_ENTITY; } - virtual cPacket* Clone() const { return new cPacket_UseEntity(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - - int m_UniqueID; - int m_TargetID; - bool m_bLeftClick; - - static const unsigned int c_Size = 1 + 4 + 4 + 1; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_UseEntity : public cPacket +{ +public: + cPacket_UseEntity() + : m_UniqueID( 0 ) + , m_TargetID( 0 ) + , m_bLeftClick( false ) + { m_PacketID = E_USE_ENTITY; } + virtual cPacket* Clone() const { return new cPacket_UseEntity(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + + int m_UniqueID; + int m_TargetID; + bool m_bLeftClick; + + static const unsigned int c_Size = 1 + 4 + 4 + 1; +}; + + + + diff --git a/source/packets/cPacket_WholeInventory.cpp b/source/packets/cPacket_WholeInventory.cpp index 5e83f481f..3b8fa5cde 100644 --- a/source/packets/cPacket_WholeInventory.cpp +++ b/source/packets/cPacket_WholeInventory.cpp @@ -1,77 +1,77 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_WholeInventory.h" -#include "../cItem.h" -#include "../cInventory.h" -#include "../cWindow.h" -#include "cPacket_ItemData.h" - - - - - -cPacket_WholeInventory::cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone ) -{ - m_PacketID = E_INVENTORY_WHOLE; - m_WindowID = a_Clone.m_WindowID; - m_Count = a_Clone.m_Count; - m_Items = new cItem[m_Count]; - memcpy( m_Items, a_Clone.m_Items, sizeof(cItem)*m_Count ); -} - - - - - -cPacket_WholeInventory::cPacket_WholeInventory( cInventory* a_Inventory ) -{ - m_PacketID = E_INVENTORY_WHOLE; - m_WindowID = 0; - m_Count = a_Inventory->c_NumSlots; - m_Items = new cItem[m_Count]; - memcpy( m_Items, a_Inventory->GetSlots(), sizeof(cItem)*m_Count ); -} - - - - - -cPacket_WholeInventory::cPacket_WholeInventory( cWindow* a_Window ) -{ - m_PacketID = E_INVENTORY_WHOLE; - m_WindowID = (char)a_Window->GetWindowID(); - m_Count = (short)a_Window->GetNumSlots(); - m_Items = new cItem[m_Count]; - memcpy( m_Items, a_Window->GetSlots(), sizeof(cItem)*m_Count ); -} - - - - - -cPacket_WholeInventory::~cPacket_WholeInventory() -{ - delete [] m_Items; -} - - - - - -void cPacket_WholeInventory::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendByte (a_Data, m_WindowID); - AppendShort(a_Data, m_Count); - - for (int j = 0; j < m_Count; j++) - { - cPacket_ItemData::AppendItem(a_Data, &(m_Items[j])); - } -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_WholeInventory.h" +#include "../cItem.h" +#include "../cInventory.h" +#include "../cWindow.h" +#include "cPacket_ItemData.h" + + + + + +cPacket_WholeInventory::cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone ) +{ + m_PacketID = E_INVENTORY_WHOLE; + m_WindowID = a_Clone.m_WindowID; + m_Count = a_Clone.m_Count; + m_Items = new cItem[m_Count]; + memcpy( m_Items, a_Clone.m_Items, sizeof(cItem)*m_Count ); +} + + + + + +cPacket_WholeInventory::cPacket_WholeInventory( cInventory* a_Inventory ) +{ + m_PacketID = E_INVENTORY_WHOLE; + m_WindowID = 0; + m_Count = a_Inventory->c_NumSlots; + m_Items = new cItem[m_Count]; + memcpy( m_Items, a_Inventory->GetSlots(), sizeof(cItem)*m_Count ); +} + + + + + +cPacket_WholeInventory::cPacket_WholeInventory( cWindow* a_Window ) +{ + m_PacketID = E_INVENTORY_WHOLE; + m_WindowID = (char)a_Window->GetWindowID(); + m_Count = (short)a_Window->GetNumSlots(); + m_Items = new cItem[m_Count]; + memcpy( m_Items, a_Window->GetSlots(), sizeof(cItem)*m_Count ); +} + + + + + +cPacket_WholeInventory::~cPacket_WholeInventory() +{ + delete [] m_Items; +} + + + + + +void cPacket_WholeInventory::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendByte (a_Data, m_WindowID); + AppendShort(a_Data, m_Count); + + for (int j = 0; j < m_Count; j++) + { + cPacket_ItemData::AppendItem(a_Data, &(m_Items[j])); + } +} + + + + \ No newline at end of file diff --git a/source/packets/cPacket_WholeInventory.h b/source/packets/cPacket_WholeInventory.h index 5d895b367..3a9cc0a1b 100644 --- a/source/packets/cPacket_WholeInventory.h +++ b/source/packets/cPacket_WholeInventory.h @@ -1,47 +1,47 @@ - -#pragma once - -#include "cPacket.h" - -#include "../BlockID.h" - - - - - -class cInventory; -class cWindow; -class cItem; - - - - - -class cPacket_WholeInventory : public cPacket // full inventory [S -> C] ? -{ -public: - cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone ); - cPacket_WholeInventory( cInventory* a_Inventory ); - cPacket_WholeInventory( cWindow* a_Window ); - ~cPacket_WholeInventory(); - cPacket_WholeInventory() - : m_WindowID( 0 ) - , m_Count( 0 ) - , m_Items( 0 ) - { m_PacketID = E_INVENTORY_WHOLE; } - - - virtual cPacket* Clone() const { return new cPacket_WholeInventory(*this); } - - virtual void Serialize(AString & a_Data) const override; - - char m_WindowID; // WTF? - short m_Count; // Number of items - cItem * m_Items; // Array of m_Count items - - static const unsigned int c_Size = 1 + 1 + 2; // Minimal size -}; - - - - + +#pragma once + +#include "cPacket.h" + +#include "../BlockID.h" + + + + + +class cInventory; +class cWindow; +class cItem; + + + + + +class cPacket_WholeInventory : public cPacket // full inventory [S -> C] ? +{ +public: + cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone ); + cPacket_WholeInventory( cInventory* a_Inventory ); + cPacket_WholeInventory( cWindow* a_Window ); + ~cPacket_WholeInventory(); + cPacket_WholeInventory() + : m_WindowID( 0 ) + , m_Count( 0 ) + , m_Items( 0 ) + { m_PacketID = E_INVENTORY_WHOLE; } + + + virtual cPacket* Clone() const { return new cPacket_WholeInventory(*this); } + + virtual void Serialize(AString & a_Data) const override; + + char m_WindowID; // WTF? + short m_Count; // Number of items + cItem * m_Items; // Array of m_Count items + + static const unsigned int c_Size = 1 + 1 + 2; // Minimal size +}; + + + + diff --git a/source/packets/cPacket_WindowClick.cpp b/source/packets/cPacket_WindowClick.cpp index 0b2d18415..ac3191c28 100644 --- a/source/packets/cPacket_WindowClick.cpp +++ b/source/packets/cPacket_WindowClick.cpp @@ -1,43 +1,43 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_WindowClick.h" -#include "cPacket_WholeInventory.h" -#include "cPacket_ItemData.h" - - - - - -int cPacket_WindowClick::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadByte, m_WindowID, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_SlotNum, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_RightMouse, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_NumClicks, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_Bool, TotalBytes); - - // LOG("WindowClick: WindowID: %i; FromSlot: %i; Right/Le: %i; NumClick: %i", m_Type, m_SlotNum, m_RightMouse, m_NumClicks ); - - cPacket_ItemData Item; - - int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes); - if (res < 0) - { - return res; - } - TotalBytes += res; - - m_ItemID = Item.m_ItemID; - m_ItemCount = Item.m_ItemCount; - m_ItemUses = Item.m_ItemUses; - - m_EnchantNums = Item.m_EnchantNums; - - return TotalBytes; -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_WindowClick.h" +#include "cPacket_WholeInventory.h" +#include "cPacket_ItemData.h" + + + + + +int cPacket_WindowClick::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadByte, m_WindowID, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_SlotNum, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_RightMouse, TotalBytes); + HANDLE_PACKET_READ(ReadShort, m_NumClicks, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_Bool, TotalBytes); + + // LOG("WindowClick: WindowID: %i; FromSlot: %i; Right/Le: %i; NumClick: %i", m_Type, m_SlotNum, m_RightMouse, m_NumClicks ); + + cPacket_ItemData Item; + + int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes); + if (res < 0) + { + return res; + } + TotalBytes += res; + + m_ItemID = Item.m_ItemID; + m_ItemCount = Item.m_ItemCount; + m_ItemUses = Item.m_ItemUses; + + m_EnchantNums = Item.m_EnchantNums; + + return TotalBytes; +} + + + + diff --git a/source/packets/cPacket_WindowClick.h b/source/packets/cPacket_WindowClick.h index 09fc1d862..2d78d3f00 100644 --- a/source/packets/cPacket_WindowClick.h +++ b/source/packets/cPacket_WindowClick.h @@ -1,52 +1,52 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_WindowClick : public cPacket // [C -> S] -{ -public: - cPacket_WindowClick() - : m_WindowID( 0 ) - , m_SlotNum( 0 ) - , m_RightMouse( 0 ) - , m_NumClicks( 0 ) - , m_Bool( false ) - , m_ItemID( 0 ) - , m_ItemCount( 0 ) - , m_ItemUses( 0 ) - , m_EnchantNums(-1) - { m_PacketID = E_WINDOW_CLICK; } - virtual cPacket* Clone() const { return new cPacket_WindowClick(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - - char m_WindowID; - short m_SlotNum; // Slot - // 0 = craft result - // 1-4 = crafting table - // 5-8 = armor - // 9-35 = inventory - // 36-44 = Hot bar - - char m_RightMouse; // 0 = left 1 = Right mb - short m_NumClicks; // Num clicks - bool m_Bool; // unkown???????????? SHIFT clicked - - // Below = item - short m_ItemID; // if this is -1 the next stuff dont exist - char m_ItemCount; - short m_ItemUses; - - short m_EnchantNums; - - static const unsigned int c_Size = 1 + 1 + 2 + 1 + 2 + 2; // Minimal size ( +1+1 = max) -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_WindowClick : public cPacket // [C -> S] +{ +public: + cPacket_WindowClick() + : m_WindowID( 0 ) + , m_SlotNum( 0 ) + , m_RightMouse( 0 ) + , m_NumClicks( 0 ) + , m_Bool( false ) + , m_ItemID( 0 ) + , m_ItemCount( 0 ) + , m_ItemUses( 0 ) + , m_EnchantNums(-1) + { m_PacketID = E_WINDOW_CLICK; } + virtual cPacket* Clone() const { return new cPacket_WindowClick(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + + char m_WindowID; + short m_SlotNum; // Slot + // 0 = craft result + // 1-4 = crafting table + // 5-8 = armor + // 9-35 = inventory + // 36-44 = Hot bar + + char m_RightMouse; // 0 = left 1 = Right mb + short m_NumClicks; // Num clicks + bool m_Bool; // unkown???????????? SHIFT clicked + + // Below = item + short m_ItemID; // if this is -1 the next stuff dont exist + char m_ItemCount; + short m_ItemUses; + + short m_EnchantNums; + + static const unsigned int c_Size = 1 + 1 + 2 + 1 + 2 + 2; // Minimal size ( +1+1 = max) +}; + + + + diff --git a/source/packets/cPacket_WindowClose.cpp b/source/packets/cPacket_WindowClose.cpp index 25669bf79..f4361e4a1 100644 --- a/source/packets/cPacket_WindowClose.cpp +++ b/source/packets/cPacket_WindowClose.cpp @@ -1,29 +1,29 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_WindowClose.h" - - - - - -int cPacket_WindowClose::Parse(const char * a_Data, int a_Size) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadByte, m_Close, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_WindowClose::Serialize(AString & a_Data) const -{ - AppendByte(a_Data, m_PacketID); - AppendByte(a_Data, m_Close); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_WindowClose.h" + + + + + +int cPacket_WindowClose::Parse(const char * a_Data, int a_Size) +{ + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadByte, m_Close, TotalBytes); + return TotalBytes; +} + + + + + +void cPacket_WindowClose::Serialize(AString & a_Data) const +{ + AppendByte(a_Data, m_PacketID); + AppendByte(a_Data, m_Close); +} + + + + diff --git a/source/packets/cPacket_WindowClose.h b/source/packets/cPacket_WindowClose.h index 1063896ff..674c071d1 100644 --- a/source/packets/cPacket_WindowClose.h +++ b/source/packets/cPacket_WindowClose.h @@ -1,28 +1,28 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_WindowClose : public cPacket -{ -public: - cPacket_WindowClose() - : m_Close( 0 ) - { m_PacketID = E_WINDOW_CLOSE; } - virtual cPacket* Clone() const { return new cPacket_WindowClose(*this); } - - virtual int Parse(const char * a_Data, int a_Size) override; - virtual void Serialize(AString & a_Data) const override; - - char m_Close; // m_Close == cWindow WindowType number - - static const unsigned int c_Size = 1 + 1; -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_WindowClose : public cPacket +{ +public: + cPacket_WindowClose() + : m_Close( 0 ) + { m_PacketID = E_WINDOW_CLOSE; } + virtual cPacket* Clone() const { return new cPacket_WindowClose(*this); } + + virtual int Parse(const char * a_Data, int a_Size) override; + virtual void Serialize(AString & a_Data) const override; + + char m_Close; // m_Close == cWindow WindowType number + + static const unsigned int c_Size = 1 + 1; +}; + + + + diff --git a/source/packets/cPacket_WindowOpen.cpp b/source/packets/cPacket_WindowOpen.cpp index a5c3ade7e..8c4402139 100644 --- a/source/packets/cPacket_WindowOpen.cpp +++ b/source/packets/cPacket_WindowOpen.cpp @@ -1,21 +1,21 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_WindowOpen.h" - - - - - -void cPacket_WindowOpen::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendByte (a_Data, m_WindowID); - AppendByte (a_Data, m_InventoryType); - AppendString16(a_Data, m_WindowTitle); - AppendByte (a_Data, m_NumSlots); -} - - - - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cPacket_WindowOpen.h" + + + + + +void cPacket_WindowOpen::Serialize(AString & a_Data) const +{ + AppendByte (a_Data, m_PacketID); + AppendByte (a_Data, m_WindowID); + AppendByte (a_Data, m_InventoryType); + AppendString16(a_Data, m_WindowTitle); + AppendByte (a_Data, m_NumSlots); +} + + + + diff --git a/source/packets/cPacket_WindowOpen.h b/source/packets/cPacket_WindowOpen.h index f3b225639..3896f5f02 100644 --- a/source/packets/cPacket_WindowOpen.h +++ b/source/packets/cPacket_WindowOpen.h @@ -1,32 +1,32 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_WindowOpen : public cPacket -{ -public: - cPacket_WindowOpen() - : m_WindowID( 0 ) - , m_InventoryType( 0 ) - , m_NumSlots( 0 ) - { m_PacketID = E_WINDOW_OPEN; } - virtual cPacket* Clone() const { return new cPacket_WindowOpen(*this); } - - virtual void Serialize(AString & a_Data) const override; - - char m_WindowID; - char m_InventoryType; - AString m_WindowTitle; - char m_NumSlots; - - static const unsigned int c_Size = 1 + 1 + 1 + 2 + 1; // + sizeof(string) -}; - - - - + +#pragma once + +#include "cPacket.h" + + + + + +class cPacket_WindowOpen : public cPacket +{ +public: + cPacket_WindowOpen() + : m_WindowID( 0 ) + , m_InventoryType( 0 ) + , m_NumSlots( 0 ) + { m_PacketID = E_WINDOW_OPEN; } + virtual cPacket* Clone() const { return new cPacket_WindowOpen(*this); } + + virtual void Serialize(AString & a_Data) const override; + + char m_WindowID; + char m_InventoryType; + AString m_WindowTitle; + char m_NumSlots; + + static const unsigned int c_Size = 1 + 1 + 1 + 2 + 1; // + sizeof(string) +}; + + + + -- cgit v1.2.3