Fix bytebuffer

This commit is contained in:
momo5502 2023-04-06 21:16:42 +02:00
parent 163f9c53b8
commit 70ea07fd90
3 changed files with 26 additions and 23 deletions

View File

@ -155,8 +155,8 @@ namespace auth
void post_unpack() override void post_unpack() override
{ {
// Skip connect handler // Skip connect handler
//utils::hook::set<uint8_t>(game::select(0x142253EFA, 0x14053714A), 0xEB); utils::hook::set<uint8_t>(game::select(0x142253EFA, 0x14053714A), 0xEB);
//network::on("connect", handle_connect_packet); network::on("connect", handle_connect_packet);
// Patch steam id bit check // Patch steam id bit check
std::vector<std::pair<size_t, size_t>> patches{}; std::vector<std::pair<size_t, size_t>> patches{};
@ -203,7 +203,7 @@ namespace auth
p(0x141EB5992_g, 0x141EB59D5_g); p(0x141EB5992_g, 0x141EB59D5_g);
p(0x141EB74D2_g, 0x141EB7515_g); // ? p(0x141EB74D2_g, 0x141EB7515_g); // ?
//utils::hook::call(0x14134BF7D_g, send_connect_data_stub); utils::hook::call(0x14134BF7D_g, send_connect_data_stub);
} }
for (const auto& patch : patches) for (const auto& patch : patches)

View File

@ -17,28 +17,28 @@ namespace utils
void byte_buffer::write(const void* buffer, const size_t length) void byte_buffer::write(const void* buffer, const size_t length)
{ {
if (!writing_) if (!this->writing_)
{ {
throw std::runtime_error("Writing to readable byte buffer"); throw std::runtime_error("Writing to readable byte buffer");
} }
buffer_.append(static_cast<const char*>(buffer), length); this->buffer_.append(static_cast<const char*>(buffer), length);
} }
void byte_buffer::read(void* data, const size_t length) void byte_buffer::read(void* data, const size_t length)
{ {
if (writing_) if (this->writing_)
{ {
throw std::runtime_error("Reading from writable byte buffer"); throw std::runtime_error("Reading from writable byte buffer");
} }
if (offset_ + length > buffer_.size()) if (this->offset_ + length > this->buffer_.size())
{ {
throw std::runtime_error("Out of bounds read from byte buffer"); throw std::runtime_error("Out of bounds read from byte buffer");
} }
memcpy(data, buffer_.data() + offset_, length); memcpy(data, this->buffer_.data() + this->offset_, length);
offset_ += length; this->offset_ += length;
} }
std::string byte_buffer::read_string() std::string byte_buffer::read_string()
@ -47,7 +47,7 @@ namespace utils
while (true) while (true)
{ {
const auto b = read<char>(); const auto b = this->read<char>();
if (!b) if (!b)
{ {
break; break;
@ -66,7 +66,7 @@ namespace utils
for (size_t i = 0; i < length; ++i) for (size_t i = 0; i < length; ++i)
{ {
result.push_back(read<char>()); result.push_back(this->read<char>());
} }
return result; return result;
@ -77,7 +77,7 @@ namespace utils
std::vector<uint8_t> result{}; std::vector<uint8_t> result{};
result.resize(length); result.resize(length);
read(result.data(), result.size()); this->read(result.data(), result.size());
return result; return result;
} }

View File

@ -23,41 +23,41 @@ namespace utils
void write(const std::string& string, const bool null_terminate = false) void write(const std::string& string, const bool null_terminate = false)
{ {
const size_t addend = null_terminate ? 1 : 0; const size_t addend = null_terminate ? 1 : 0;
write(string.data(), string.size() + addend); this->write(string.data(), string.size() + addend);
} }
void write_string(const std::string& string) void write_string(const std::string& string)
{ {
write(string, true); this->write(string, true);
} }
template <typename T> template <typename T>
void write(const T& object) void write(const T& object)
{ {
write(&object, sizeof(object)); this->write(&object, sizeof(object));
} }
template <typename T> template <typename T>
void write(const std::vector<T>& vec) void write(const std::vector<T>& vec)
{ {
write(vec.data(), vec.size() * sizeof(T)); this->write(vec.data(), vec.size() * sizeof(T));
} }
template <typename T> template <typename T>
void write_vector(const std::vector<T>& vec) void write_vector(const std::vector<T>& vec)
{ {
write<uint32_t>(static_cast<uint32_t>(vec.size())); this->write<uint32_t>(static_cast<uint32_t>(vec.size()));
write(vec); this->write(vec);
} }
const std::string& get_buffer() const const std::string& get_buffer() const
{ {
return buffer_; return this->buffer_;
} }
std::string move_buffer() std::string move_buffer()
{ {
return std::move(buffer_); return std::move(this->buffer_);
} }
void read(void* data, size_t length); void read(void* data, size_t length);
@ -66,7 +66,7 @@ namespace utils
T read() T read()
{ {
T object{}; T object{};
read(&object, sizeof(object)); this->read(&object, sizeof(object));
return object; return object;
} }
@ -75,12 +75,15 @@ namespace utils
{ {
std::vector<T> result{}; std::vector<T> result{};
const auto size = read<uint32_t>(); const auto size = read<uint32_t>();
if (offset_ + size > buffer_.size()) const auto totalSize = size * sizeof(T);
if (this->offset_ + totalSize > this->buffer_.size())
{ {
throw std::runtime_error("Out of bounds read from byte buffer"); throw std::runtime_error("Out of bounds read from byte buffer");
} }
read(result.data(), size); result.resize(size);
this->read(result.data(), totalSize);
return result; return result;
} }