Reconstruct readable C++ and organize cohesive source subsystems

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
This commit is contained in:
ragnarok-clanker 2026-10-25 07:42:41 +00:00
commit a47d20f8be
890 changed files with 11796 additions and 16664 deletions

View file

@ -1,14 +1,10 @@
#include "Archive/MemMapPakFile.h"
#include <bit>
// OFFSET: 0x00AE99D0
// FUNCTION: fn_18111
// OFFSET: 0x00AECAA0
// FUNCTION: fn_18140
CMemMapPakFile::CMemMapPakFile()
: m_handle(nullptr), m_mapping(nullptr), m_viewSize(0), m_windowSize(0x20000000), m_size(0), m_viewOffset(0),
m_view(nullptr) {
CMemMapPakFile::CMemMapPakFile() : m_handle(nullptr), m_mapping(nullptr), m_viewSize(0), m_windowSize(0x20000000), m_size(0), m_viewOffset(0), m_view(nullptr) {
SYSTEM_INFO information;
GetSystemInfo(&information);
this->m_offsetMask = 0xFFFFFFFF00000000ULL | static_cast<std::uint32_t>(~(information.dwAllocationGranularity - 1));
@ -30,8 +26,7 @@ std::uint64_t CMemMapPakFile::GetSize() const {
// OFFSET: 0x00AECB10
// FUNCTION: fn_18141
bool CMemMapPakFile::Open(const char* filename) {
this->m_handle =
CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
this->m_handle = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (this->m_handle == INVALID_HANDLE_VALUE) {
this->m_handle = nullptr;
return false;
@ -39,13 +34,15 @@ bool CMemMapPakFile::Open(const char* filename) {
LARGE_INTEGER size;
GetFileSizeEx(this->m_handle, &size);
this->m_size = std::bit_cast<std::uint64_t>(size.QuadPart);
this->m_size = static_cast<std::uint64_t>(size.QuadPart);
this->m_viewOffset = 0;
this->m_viewSize = 0;
this->m_mapping = CreateFileMappingA(this->m_handle, nullptr, PAGE_READONLY, 0, 0, nullptr);
if (this->m_mapping) {
return true;
}
this->m_windowSize = 0;
return false;
}
@ -57,10 +54,12 @@ void CMemMapPakFile::Close() {
UnmapViewOfFile(this->m_view);
this->m_view = nullptr;
}
if (this->m_mapping) {
CloseHandle(this->m_mapping);
this->m_mapping = nullptr;
}
if (this->m_handle) {
CloseHandle(this->m_handle);
this->m_handle = nullptr;
@ -74,27 +73,29 @@ std::uint8_t* CMemMapPakFile::Read(std::uint64_t offset, std::uint32_t length) {
if (offset >= this->m_viewOffset && offset + length <= this->m_viewOffset + this->m_viewSize) {
return this->m_view + static_cast<std::uint32_t>(offset - this->m_viewOffset);
}
if (this->m_view) {
UnmapViewOfFile(this->m_view);
this->m_view = nullptr;
}
while (this->m_windowSize >=
length + (static_cast<std::uint32_t>(offset) & ~static_cast<std::uint32_t>(this->m_offsetMask))) {
while (this->m_windowSize >= length + (static_cast<std::uint32_t>(offset) & ~static_cast<std::uint32_t>(this->m_offsetMask))) {
this->m_viewOffset = offset & this->m_offsetMask;
this->m_viewSize = this->m_windowSize;
SIZE_T bytes = this->m_windowSize;
if (this->m_viewOffset + this->m_windowSize > this->m_size) {
bytes = 0;
this->m_viewSize = static_cast<std::uint32_t>(this->m_size - this->m_viewOffset);
}
this->m_view = static_cast<std::uint8_t*>(MapViewOfFile(
this->m_mapping, FILE_MAP_READ, static_cast<DWORD>(this->m_viewOffset >> 32),
static_cast<DWORD>(this->m_viewOffset), bytes
));
this->m_view = static_cast<std::uint8_t*>(
MapViewOfFile(this->m_mapping, FILE_MAP_READ, static_cast<DWORD>(this->m_viewOffset >> 32), static_cast<DWORD>(this->m_viewOffset), bytes)
);
if (this->m_view) {
return this->m_view + static_cast<std::uint32_t>(offset - this->m_viewOffset);
}
this->m_windowSize >>= 1;
if (!this->m_windowSize) {
break;
@ -113,14 +114,16 @@ std::uint8_t* CMemMapPakFile::Read(std::uint64_t offset, std::uint32_t length) {
this->m_buffer.resize(length);
this->m_view = this->m_buffer.data();
}
LARGE_INTEGER position;
position.QuadPart = std::bit_cast<std::int64_t>(offset);
position.QuadPart = static_cast<std::int64_t>(offset);
SetFilePointerEx(this->m_handle, position, nullptr, FILE_BEGIN);
DWORD read = 0;
if (ReadFile(this->m_handle, this->m_buffer.data(), length, &read, nullptr)) {
// The original accepts a successful short read; it does not compare read.
this->m_view = this->m_buffer.empty() ? nullptr : this->m_buffer.data();
return this->m_view;
}
return nullptr;
}