Administrative source import: native x86 compilation passed for 423 authored units. Source placement and submission states are migrated separately; this commit does not imply peer acceptance.
Previous head: 35d2a8cb36
Payload SHA256: 592f016d2730c5593bb653aa054c1e5f76a6df72c8f5a09e66f74876e2e33dee
93 lines
2.3 KiB
C++
93 lines
2.3 KiB
C++
#include "Archive/PakFile.h"
|
|
|
|
// OFFSET: 0x005EF660
|
|
// FUNCTION: fn_04009
|
|
CPakFile::~CPakFile() = default;
|
|
|
|
namespace myGPack {
|
|
// OFFSET: 0x005F7790
|
|
// FUNCTION: fn_04046
|
|
CReadPakFile::CReadPakFile() : m_handle(INVALID_HANDLE_VALUE), m_size(0) {
|
|
}
|
|
|
|
// OFFSET: 0x005EF690
|
|
// FUNCTION: fn_04010
|
|
CReadPakFile::~CReadPakFile() {
|
|
this->Close();
|
|
}
|
|
|
|
// OFFSET: 0x005EF710
|
|
// FUNCTION: fn_04011
|
|
CWritePakFile::~CWritePakFile() = default;
|
|
|
|
// OFFSET: 0x005F7780
|
|
std::uint64_t CReadPakFile::GetSize() const {
|
|
return this->m_size;
|
|
}
|
|
|
|
// OFFSET: 0x005F7810
|
|
// FUNCTION: fn_04047
|
|
void CReadPakFile::Close() {
|
|
if (this->m_handle) {
|
|
CloseHandle(this->m_handle);
|
|
this->m_handle = nullptr;
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x005F7890
|
|
// FUNCTION: fn_04048
|
|
bool CWritePakFile::Open(const char* filename) {
|
|
this->m_handle = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL, nullptr);
|
|
if (this->m_handle == INVALID_HANDLE_VALUE) {
|
|
return false;
|
|
}
|
|
|
|
LARGE_INTEGER size;
|
|
|
|
GetFileSizeEx(this->m_handle, &size);
|
|
this->m_size = static_cast<std::uint64_t>(size.QuadPart);
|
|
return true;
|
|
}
|
|
|
|
// OFFSET: 0x005F78F0
|
|
// FUNCTION: fn_04049
|
|
std::uint8_t* CReadPakFile::Read(std::uint64_t offset, std::uint32_t length) {
|
|
if (offset + length > this->m_size) {
|
|
return nullptr;
|
|
}
|
|
|
|
this->m_buffer.resize(length);
|
|
|
|
LARGE_INTEGER position;
|
|
position.QuadPart = static_cast<std::int64_t>(offset);
|
|
|
|
SetFilePointerEx(this->m_handle, position, nullptr, FILE_BEGIN);
|
|
|
|
DWORD read;
|
|
if (ReadFile(this->m_handle, this->m_buffer.data(), length, &read, nullptr) && read == length) {
|
|
return this->m_buffer.data();
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
// OFFSET: 0x005F79C0
|
|
// FUNCTION: fn_04050
|
|
bool CWritePakFile::Write(std::uint64_t offset, const void* bytes, std::uint32_t length) {
|
|
LARGE_INTEGER position;
|
|
position.QuadPart = static_cast<std::int64_t>(offset);
|
|
SetFilePointerEx(this->m_handle, position, nullptr, FILE_BEGIN);
|
|
|
|
DWORD written;
|
|
if (!WriteFile(this->m_handle, bytes, length, &written, nullptr) || written != length) {
|
|
return false;
|
|
}
|
|
|
|
std::uint64_t end = offset + length;
|
|
if (this->m_size < end) {
|
|
this->m_size = end;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|