mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-24 16:10:14 +00:00
Initial commit: wowee native WoW 3.3.5a client
This commit is contained in:
commit
ce6cb8f38e
147 changed files with 32347 additions and 0 deletions
90
src/network/packet.cpp
Normal file
90
src/network/packet.cpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#include "network/packet.hpp"
|
||||
#include <cstring>
|
||||
|
||||
namespace wowee {
|
||||
namespace network {
|
||||
|
||||
Packet::Packet(uint16_t opcode) : opcode(opcode) {}
|
||||
|
||||
Packet::Packet(uint16_t opcode, const std::vector<uint8_t>& data)
|
||||
: opcode(opcode), data(data), readPos(0) {}
|
||||
|
||||
void Packet::writeUInt8(uint8_t value) {
|
||||
data.push_back(value);
|
||||
}
|
||||
|
||||
void Packet::writeUInt16(uint16_t value) {
|
||||
data.push_back(value & 0xFF);
|
||||
data.push_back((value >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
void Packet::writeUInt32(uint32_t value) {
|
||||
data.push_back(value & 0xFF);
|
||||
data.push_back((value >> 8) & 0xFF);
|
||||
data.push_back((value >> 16) & 0xFF);
|
||||
data.push_back((value >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
void Packet::writeUInt64(uint64_t value) {
|
||||
writeUInt32(value & 0xFFFFFFFF);
|
||||
writeUInt32((value >> 32) & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
void Packet::writeString(const std::string& value) {
|
||||
for (char c : value) {
|
||||
data.push_back(static_cast<uint8_t>(c));
|
||||
}
|
||||
data.push_back(0); // Null terminator
|
||||
}
|
||||
|
||||
void Packet::writeBytes(const uint8_t* bytes, size_t length) {
|
||||
data.insert(data.end(), bytes, bytes + length);
|
||||
}
|
||||
|
||||
uint8_t Packet::readUInt8() {
|
||||
if (readPos >= data.size()) return 0;
|
||||
return data[readPos++];
|
||||
}
|
||||
|
||||
uint16_t Packet::readUInt16() {
|
||||
uint16_t value = 0;
|
||||
value |= readUInt8();
|
||||
value |= (readUInt8() << 8);
|
||||
return value;
|
||||
}
|
||||
|
||||
uint32_t Packet::readUInt32() {
|
||||
uint32_t value = 0;
|
||||
value |= readUInt8();
|
||||
value |= (readUInt8() << 8);
|
||||
value |= (readUInt8() << 16);
|
||||
value |= (readUInt8() << 24);
|
||||
return value;
|
||||
}
|
||||
|
||||
uint64_t Packet::readUInt64() {
|
||||
uint64_t value = readUInt32();
|
||||
value |= (static_cast<uint64_t>(readUInt32()) << 32);
|
||||
return value;
|
||||
}
|
||||
|
||||
float Packet::readFloat() {
|
||||
// Read as uint32 and reinterpret as float
|
||||
uint32_t bits = readUInt32();
|
||||
float value;
|
||||
std::memcpy(&value, &bits, sizeof(float));
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string Packet::readString() {
|
||||
std::string result;
|
||||
while (readPos < data.size()) {
|
||||
uint8_t c = data[readPos++];
|
||||
if (c == 0) break;
|
||||
result += static_cast<char>(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace network
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue