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:
parent
35d2a8cb36
commit
a47d20f8be
890 changed files with 11796 additions and 16664 deletions
|
|
@ -4,11 +4,9 @@
|
|||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <emmintrin.h>
|
||||
#include <zlib.h>
|
||||
|
||||
namespace {
|
||||
|
||||
std::uint32_t Read32(const std::uint8_t* bytes) {
|
||||
std::uint32_t value;
|
||||
std::memcpy(&value, bytes, sizeof(value));
|
||||
|
|
@ -29,22 +27,18 @@ namespace {
|
|||
// FUNCTION: fn_05116
|
||||
std::uint64_t ReadAuxiliaryIdentifier(const void* data, std::size_t size) {
|
||||
if (size != 0) {
|
||||
const __m128i header = _mm_loadu_si128(static_cast<const __m128i*>(data));
|
||||
if (static_cast<std::uint8_t>(_mm_cvtsi128_si32(header)) <= 1) {
|
||||
std::uint64_t identifier;
|
||||
_mm_storel_epi64(reinterpret_cast<__m128i*>(&identifier), _mm_srli_si128(header, 4));
|
||||
return identifier;
|
||||
const auto* header = static_cast<const std::uint8_t*>(data);
|
||||
if (header[0] <= 1) {
|
||||
return Read64(header + 4);
|
||||
}
|
||||
}
|
||||
|
||||
return UINT64_MAX;
|
||||
}
|
||||
|
||||
void SortEntries(std::vector<myGPack::PakEntry>& entries) {
|
||||
std::sort(entries.begin(), entries.end(), [](const auto& first, const auto& second) {
|
||||
return first.name < second.name;
|
||||
});
|
||||
std::sort(entries.begin(), entries.end(), [](const auto& first, const auto& second) { return first.name < second.name; });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// OFFSET: 0x00E555A0
|
||||
|
|
@ -80,6 +74,7 @@ bool CGPak::Open(CPakFile* file) {
|
|||
if (!file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->m_file = file;
|
||||
const std::uint8_t* header = file->Read(0, 46);
|
||||
if (std::memcmp(header, "Event Horizon", 14) == 0) {
|
||||
|
|
@ -95,6 +90,7 @@ bool CGPak::Open(CPakFile* file) {
|
|||
}
|
||||
|
||||
bool loaded;
|
||||
|
||||
switch (this->m_version & 0xFF00) {
|
||||
case 0x100:
|
||||
loaded = this->ReadTableV1();
|
||||
|
|
@ -109,9 +105,11 @@ bool CGPak::Open(CPakFile* file) {
|
|||
loaded = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (loaded) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this->Reset();
|
||||
return false;
|
||||
}
|
||||
|
|
@ -119,20 +117,22 @@ bool CGPak::Open(CPakFile* file) {
|
|||
// OFFSET: 0x00AEC050
|
||||
// FUNCTION: fn_18133
|
||||
bool CGPak::ReadTableV1() {
|
||||
this->m_tableSize =
|
||||
static_cast<std::uint32_t>(this->m_file->GetSize()) - static_cast<std::uint32_t>(this->m_tableOffset);
|
||||
this->m_tableSize = static_cast<std::uint32_t>(this->m_file->GetSize()) - static_cast<std::uint32_t>(this->m_tableOffset);
|
||||
const std::uint8_t* cursor = this->m_file->Read(this->m_tableOffset, this->m_tableSize);
|
||||
this->m_entries.resize(this->m_entryCount);
|
||||
|
||||
std::uint32_t maximum = 0;
|
||||
std::uint32_t sequence = 1;
|
||||
std::int32_t legacyKey = 95001;
|
||||
|
||||
for (std::uint32_t i = 0; i < this->m_entryCount; ++i) {
|
||||
std::uint32_t nameSize = Read32(cursor);
|
||||
cursor += 4;
|
||||
char name[256];
|
||||
|
||||
if (this->m_version < 0x101) {
|
||||
std::int32_t length = static_cast<std::int32_t>(std::strlen(reinterpret_cast<const char*>(cursor)) + 1);
|
||||
|
||||
for (std::int32_t j = 0; j < length; ++j) {
|
||||
name[j] = static_cast<char>(SwapNibbles(cursor[j]));
|
||||
}
|
||||
|
|
@ -140,18 +140,23 @@ bool CGPak::ReadTableV1() {
|
|||
if (this->m_version > 0x103) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cursor += 2;
|
||||
std::int32_t length = static_cast<std::int32_t>(nameSize - 6);
|
||||
|
||||
for (std::int32_t j = 0; j < length; ++j) {
|
||||
name[j] = static_cast<char>(SwapNibbles(cursor[j]));
|
||||
}
|
||||
|
||||
std::int32_t number = legacyKey;
|
||||
if (this->m_version != 0x101) {
|
||||
number = static_cast<std::int32_t>(3 * (31669u - (sequence >> 1)));
|
||||
}
|
||||
|
||||
if (number < 10000) {
|
||||
number += 85000;
|
||||
}
|
||||
|
||||
char digits[20];
|
||||
_itoa(number, digits, 10);
|
||||
std::uint8_t key[8];
|
||||
|
|
@ -178,13 +183,14 @@ bool CGPak::ReadTableV1() {
|
|||
entry.name.Assign(name);
|
||||
|
||||
const char* extension = std::strrchr(name, '.');
|
||||
bool special = extension && (_stricmp(extension, ".gnd") == 0 || _stricmp(extension, ".gat") == 0 ||
|
||||
_stricmp(extension, ".act") == 0 || _stricmp(extension, ".str") == 0);
|
||||
bool special = extension && (_stricmp(extension, ".gnd") == 0 || _stricmp(extension, ".gat") == 0 || _stricmp(extension, ".act") == 0 ||
|
||||
_stricmp(extension, ".str") == 0);
|
||||
entry.flags |= special ? 4 : 2;
|
||||
maximum = std::max(maximum, entry.alignedSize);
|
||||
sequence += 5;
|
||||
legacyKey -= 2;
|
||||
}
|
||||
|
||||
SortEntries(this->m_entries);
|
||||
this->m_scratch.resize(maximum);
|
||||
return true;
|
||||
|
|
@ -200,6 +206,7 @@ bool CGPak::ReadTableV2() {
|
|||
const std::uint8_t* source = this->m_file->Read(this->m_tableOffset + 8, compressed);
|
||||
uLongf length = original + 8;
|
||||
std::vector<std::uint8_t> decoded(length);
|
||||
|
||||
if (uncompress(decoded.data(), &length, source, compressed) != Z_OK) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -207,6 +214,7 @@ bool CGPak::ReadTableV2() {
|
|||
this->m_entries.resize(this->m_entryCount);
|
||||
const std::uint8_t* cursor = decoded.data();
|
||||
std::uint32_t maximum = 0;
|
||||
|
||||
for (std::uint32_t i = 0; i < this->m_entryCount; ++i) {
|
||||
const char* name = reinterpret_cast<const char*>(cursor);
|
||||
const std::uint8_t* metadata = cursor + std::strlen(name) + 1;
|
||||
|
|
@ -220,6 +228,7 @@ bool CGPak::ReadTableV2() {
|
|||
entry.name.Assign(name);
|
||||
maximum = std::max(maximum, entry.alignedSize);
|
||||
}
|
||||
|
||||
SortEntries(this->m_entries);
|
||||
this->m_scratch.resize(maximum);
|
||||
return true;
|
||||
|
|
@ -236,6 +245,7 @@ bool CGPak::ReadTableV3() {
|
|||
const std::uint8_t* source = this->m_file->Read(this->m_tableOffset + 12, compressed);
|
||||
uLongf length = original + 8;
|
||||
std::vector<std::uint8_t> decoded(length);
|
||||
|
||||
if (uncompress(decoded.data(), &length, source, compressed) != Z_OK) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -243,6 +253,7 @@ bool CGPak::ReadTableV3() {
|
|||
this->m_entries.resize(this->m_entryCount);
|
||||
const std::uint8_t* cursor = decoded.data();
|
||||
std::uint32_t maximum = 0;
|
||||
|
||||
for (std::uint32_t i = 0; i < this->m_entryCount; ++i) {
|
||||
const char* name = reinterpret_cast<const char*>(cursor);
|
||||
const std::uint8_t* metadata = cursor + std::strlen(name) + 1;
|
||||
|
|
@ -252,12 +263,11 @@ bool CGPak::ReadTableV3() {
|
|||
entry.alignedSize = Read32(metadata + 4);
|
||||
entry.originalSize = Read32(metadata + 8);
|
||||
entry.flags = metadata[12];
|
||||
const std::uint32_t offsetLow = Read32(metadata + 13);
|
||||
reinterpret_cast<std::uint32_t*>(&entry.dataOffset)[1] = Read32(metadata + 17);
|
||||
reinterpret_cast<std::uint32_t*>(&entry.dataOffset)[0] = offsetLow;
|
||||
entry.dataOffset = Read64(metadata + 13);
|
||||
entry.name.Assign(name);
|
||||
maximum = std::max(maximum, entry.alignedSize);
|
||||
}
|
||||
|
||||
SortEntries(this->m_entries);
|
||||
this->m_scratch.resize(maximum);
|
||||
return true;
|
||||
|
|
@ -266,16 +276,17 @@ bool CGPak::ReadTableV3() {
|
|||
// OFFSET: 0x00AEBA30
|
||||
// FUNCTION: fn_18128
|
||||
bool CGPak::Find(const myGPack::PakName& name, myGPack::PakEntry* entry) const {
|
||||
auto found = std::lower_bound(
|
||||
this->m_entries.begin(), this->m_entries.end(), name,
|
||||
[](const myGPack::PakEntry& candidate, const myGPack::PakName& key) { return candidate.name < key; }
|
||||
);
|
||||
auto found = std::lower_bound(this->m_entries.begin(), this->m_entries.end(), name, [](const myGPack::PakEntry& candidate, const myGPack::PakName& key) {
|
||||
return candidate.name < key;
|
||||
});
|
||||
if (found == this->m_entries.end() || found->name != name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entry) {
|
||||
std::memcpy(entry, &*found, sizeof(*entry));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -290,6 +301,7 @@ void CGPak::ReadAuxiliary(std::vector<std::uint8_t>& output, std::uint64_t* iden
|
|||
|
||||
std::uint32_t size;
|
||||
std::uint64_t offset;
|
||||
|
||||
switch (this->m_version & 0xFF00) {
|
||||
case 0x200:
|
||||
if (this->m_version < 0x201) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue