Advertisement
Guest User

WoW Packet Class - by l0l1dk

a guest
Mar 21st, 2013
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.22 KB | None | 0 0
  1. // Packet class for WoW by l0l1dk.
  2.  
  3. // Packet.hpp
  4.  
  5. class Packet
  6. {
  7. private:
  8.  
  9.     // Packet data.
  10.     unsigned int Bytes[10];
  11.  
  12. public:
  13.  
  14.     // Default constructor
  15.     Packet ();
  16.  
  17.     // Copy constructor
  18.     Packet (const Packet& Other);
  19.  
  20.     // Release the packet.
  21.     void Release ();
  22.  
  23.     // Send the packet.
  24.     void Send ();
  25.  
  26.     // Add a byte to the packet.
  27.     void PutByte (unsigned char Value);
  28.  
  29.     // Add a short int to the packet.
  30.     void PutShort (short int Value);
  31.  
  32.     // Add an integer to the packet.
  33.     void PutInt (int Value);
  34.  
  35.     // Add an int64 to the packet.
  36.     void PutInt64 (long long Value);
  37.  
  38.     // Add a float to the packet.
  39.     void PutFloat (float Value);
  40.  
  41.     // Add a byte array to the packet.
  42.     void PutBytes (const unsigned char* Bytes, unsigned int Total);
  43.  
  44.     // Add a string to the packet.
  45.     void PutString (const std::string& String);
  46.  
  47.     inline Packet& operator << (unsigned char Value)
  48.     {
  49.         this->PutByte(Value);
  50.         return *this;
  51.     }
  52.  
  53.     inline Packet& operator << (short int Value)
  54.     {
  55.         this->PutShort(Value);
  56.         return *this;
  57.     }
  58.  
  59.     inline Packet& operator << (int Value)
  60.     {
  61.         this->PutInt(Value);
  62.         return *this;
  63.     }
  64.  
  65.     inline Packet& operator << (long long Value)
  66.     {
  67.         this->PutInt64(Value);
  68.         return *this;
  69.     }
  70.  
  71.     inline Packet& operator << (float Value)
  72.     {
  73.         this->PutFloat(Value);
  74.         return *this;
  75.     }
  76.  
  77.     inline Packet& operator << (const std::string& String)
  78.     {
  79.         this->PutString(String);
  80.         return *this;
  81.     }
  82. };
  83.  
  84. // Packet.cpp
  85.  
  86. Packet::Packet ()
  87. {
  88.     // Initialize the packet.
  89.     ZeroMemory(&this->Bytes, sizeof(Packet::Bytes));
  90.     Delegates::CDataStore__InitPacket2(&this->Bytes);
  91. }
  92.  
  93. Packet::Packet (const Packet& Other)
  94. {
  95.     // Copy the packet.
  96.     memcpy(&this->Bytes, &Other.Bytes, sizeof(Packet::Bytes));
  97. }
  98.  
  99. Packet::~Packet ()
  100. {
  101.     // Release the packet.
  102.     Delegates::CDataStore__ReleasePacket2(&this->Bytes);
  103. }
  104.  
  105. void Packet::Send ()
  106. {
  107.     // Finalize and send the packet.
  108.     this->Bytes[5] = 0;
  109.     Delegates::ClientServices__Send2(&this->Bytes);
  110. }
  111.  
  112. void Packet::PutByte (unsigned char Value)
  113. {
  114.     // If the packet has been finalized...
  115.     if(!this->Bytes[5])
  116.     {
  117.         // Throw an exception.
  118.         throw std::exception("The packet has been finalized and cannot be modified.");
  119.     }
  120.  
  121.     // Add a byte to the packet.
  122.     Delegates::CDataStore__PutInt8(&this->Bytes, Value);
  123. }
  124.  
  125. void Packet::PutShort (short int Value)
  126. {
  127.     // If the packet has been finalized...
  128.     if(!this->Bytes[5])
  129.     {
  130.         // Throw an exception.
  131.         throw std::exception("The packet has been finalized and cannot be modified.");
  132.     }
  133.  
  134.     // Add a short int to the packet.
  135.     Delegates::CDataStore__PutInt16(&this->Bytes, Value);
  136. }
  137.  
  138. void Packet::PutInt (int Value)
  139. {
  140.     // If the packet has been finalized...
  141.     if(!this->Bytes[5])
  142.     {
  143.         // Throw an exception.
  144.         throw std::exception("The packet has been finalized and cannot be modified.");
  145.     }
  146.  
  147.     // Add an int to the packet.
  148.     Delegates::CDataStore__PutInt32(&this->Bytes, Value);
  149. }
  150.  
  151. void Packet::PutInt64 (long long Value)
  152. {
  153.     // If the packet has been finalized...
  154.     if(!this->Bytes[5])
  155.     {
  156.         // Throw an exception.
  157.         throw std::exception("The packet has been finalized and cannot be modified.");
  158.     }
  159.  
  160.     // Add a int64 to the packet.
  161.     Delegates::CDataStore__PutInt64(&this->Bytes, Value);
  162. }
  163.  
  164. void Packet::PutFloat (float Value)
  165. {
  166.     // If the packet has been finalized...
  167.     if(!this->Bytes[5])
  168.     {
  169.         // Throw an exception.
  170.         throw std::exception("The packet has been finalized and cannot be modified.");
  171.     }
  172.  
  173.     // Add a float to the packet.
  174.     Delegates::CDataStore__PutFloat(&this->Bytes, Value);
  175. }
  176.  
  177. void Packet::PutBytes (const unsigned char* Bytes, unsigned int Total)
  178. {
  179.     // If the packet has been finalized...
  180.     if(!this->Bytes[5])
  181.     {
  182.         // Throw an exception.
  183.         throw std::exception("The packet has been finalized and cannot be modified.");
  184.     }
  185.  
  186.     // Add a byte array to the packet.
  187.     Delegates::CDataStore__PutBytes(&this->Bytes, Bytes, Total);
  188. }
  189.  
  190. void Packet::PutString (const std::string& String)
  191. {
  192.     // If the packet has been finalized...
  193.     if(!this->Bytes[5])
  194.     {
  195.         // Throw an exception.
  196.         throw std::exception("The packet has been finalized and cannot be modified.");
  197.     }
  198.  
  199.     // Add the string's bytes to the packet.
  200.     this->PutBytes(reinterpret_cast<const unsigned char*>(String.c_str()), String.length() + 1);
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement