Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Packet class for WoW by l0l1dk.
- // Packet.hpp
- class Packet
- {
- private:
- // Packet data.
- unsigned int Bytes[10];
- public:
- // Default constructor
- Packet ();
- // Copy constructor
- Packet (const Packet& Other);
- // Release the packet.
- void Release ();
- // Send the packet.
- void Send ();
- // Add a byte to the packet.
- void PutByte (unsigned char Value);
- // Add a short int to the packet.
- void PutShort (short int Value);
- // Add an integer to the packet.
- void PutInt (int Value);
- // Add an int64 to the packet.
- void PutInt64 (long long Value);
- // Add a float to the packet.
- void PutFloat (float Value);
- // Add a byte array to the packet.
- void PutBytes (const unsigned char* Bytes, unsigned int Total);
- // Add a string to the packet.
- void PutString (const std::string& String);
- inline Packet& operator << (unsigned char Value)
- {
- this->PutByte(Value);
- return *this;
- }
- inline Packet& operator << (short int Value)
- {
- this->PutShort(Value);
- return *this;
- }
- inline Packet& operator << (int Value)
- {
- this->PutInt(Value);
- return *this;
- }
- inline Packet& operator << (long long Value)
- {
- this->PutInt64(Value);
- return *this;
- }
- inline Packet& operator << (float Value)
- {
- this->PutFloat(Value);
- return *this;
- }
- inline Packet& operator << (const std::string& String)
- {
- this->PutString(String);
- return *this;
- }
- };
- // Packet.cpp
- Packet::Packet ()
- {
- // Initialize the packet.
- ZeroMemory(&this->Bytes, sizeof(Packet::Bytes));
- Delegates::CDataStore__InitPacket2(&this->Bytes);
- }
- Packet::Packet (const Packet& Other)
- {
- // Copy the packet.
- memcpy(&this->Bytes, &Other.Bytes, sizeof(Packet::Bytes));
- }
- Packet::~Packet ()
- {
- // Release the packet.
- Delegates::CDataStore__ReleasePacket2(&this->Bytes);
- }
- void Packet::Send ()
- {
- // Finalize and send the packet.
- this->Bytes[5] = 0;
- Delegates::ClientServices__Send2(&this->Bytes);
- }
- void Packet::PutByte (unsigned char Value)
- {
- // If the packet has been finalized...
- if(!this->Bytes[5])
- {
- // Throw an exception.
- throw std::exception("The packet has been finalized and cannot be modified.");
- }
- // Add a byte to the packet.
- Delegates::CDataStore__PutInt8(&this->Bytes, Value);
- }
- void Packet::PutShort (short int Value)
- {
- // If the packet has been finalized...
- if(!this->Bytes[5])
- {
- // Throw an exception.
- throw std::exception("The packet has been finalized and cannot be modified.");
- }
- // Add a short int to the packet.
- Delegates::CDataStore__PutInt16(&this->Bytes, Value);
- }
- void Packet::PutInt (int Value)
- {
- // If the packet has been finalized...
- if(!this->Bytes[5])
- {
- // Throw an exception.
- throw std::exception("The packet has been finalized and cannot be modified.");
- }
- // Add an int to the packet.
- Delegates::CDataStore__PutInt32(&this->Bytes, Value);
- }
- void Packet::PutInt64 (long long Value)
- {
- // If the packet has been finalized...
- if(!this->Bytes[5])
- {
- // Throw an exception.
- throw std::exception("The packet has been finalized and cannot be modified.");
- }
- // Add a int64 to the packet.
- Delegates::CDataStore__PutInt64(&this->Bytes, Value);
- }
- void Packet::PutFloat (float Value)
- {
- // If the packet has been finalized...
- if(!this->Bytes[5])
- {
- // Throw an exception.
- throw std::exception("The packet has been finalized and cannot be modified.");
- }
- // Add a float to the packet.
- Delegates::CDataStore__PutFloat(&this->Bytes, Value);
- }
- void Packet::PutBytes (const unsigned char* Bytes, unsigned int Total)
- {
- // If the packet has been finalized...
- if(!this->Bytes[5])
- {
- // Throw an exception.
- throw std::exception("The packet has been finalized and cannot be modified.");
- }
- // Add a byte array to the packet.
- Delegates::CDataStore__PutBytes(&this->Bytes, Bytes, Total);
- }
- void Packet::PutString (const std::string& String)
- {
- // If the packet has been finalized...
- if(!this->Bytes[5])
- {
- // Throw an exception.
- throw std::exception("The packet has been finalized and cannot be modified.");
- }
- // Add the string's bytes to the packet.
- this->PutBytes(reinterpret_cast<const unsigned char*>(String.c_str()), String.length() + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement