From a578f73002bc55d0efbd746594c567131c2ca221 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 12 Nov 2026 00:18:02 +0000 Subject: [PATCH] Decompile fn_18129 (CGPak::ReadAuxiliary) Batch #17530 by eAthena: 0 byte-identical, 1 confirmed by peer review. - fn_18129 CGPak::ReadAuxiliary: logic confirmed by peer review Peer-reviewed-by: Yommy, bibinir, Eofim Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Archive/GPak.cpp | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/Source/Archive/GPak.cpp b/Source/Archive/GPak.cpp index 5996f633f..dc705da75 100644 --- a/Source/Archive/GPak.cpp +++ b/Source/Archive/GPak.cpp @@ -107,14 +107,14 @@ namespace { return static_cast((c << 4) | ((c >> 4) & 0x0F)); } - __declspec(noinline) std::uint64_t ReadAuxiliaryIdentifier(const void* data, std::size_t size); + __declspec(noinline) std::uint64_t ReadAuxiliaryIdentifier(std::span data); // OFFSET: 0x00658FC0 // FUNCTION: fn_05116 - std::uint64_t ReadAuxiliaryIdentifier(const void* data, std::size_t size) { - if (size != 0) { + std::uint64_t ReadAuxiliaryIdentifier(std::span data) { + if (data.size() != 0) { PakAuxiliaryFile header; - std::memcpy(&header, data, sizeof(header)); + std::memcpy(&header, data.data(), sizeof(header)); if (header.version <= 1) { return header.identifier; } @@ -323,12 +323,12 @@ bool CGPak::ReadTableV2() { uLongf length = table.originalSize + 8; std::vector decoded(length); - if (uncompress(decoded.data(), &length, source, table.compressedSize) != Z_OK) { + if (uncompress(decoded.empty() ? nullptr : &decoded[0], &length, source, table.compressedSize) != Z_OK) { return false; } this->m_entries.resize(this->m_entryCount); - const std::uint8_t* cursor = decoded.data(); + const std::uint8_t* cursor = decoded.empty() ? nullptr : &decoded[0]; std::uint32_t maximum = 0; for (std::uint32_t i = 0; i < this->m_entryCount; ++i) { @@ -415,28 +415,26 @@ void CGPak::ReadAuxiliary(std::vector& output, std::uint64_t* iden *identifier = UINT64_MAX; } - output.clear(); + output.erase(output.begin(), output.end()); std::uint32_t size; std::uint64_t offset; + const std::uint32_t format = this->m_version & 0xFF00; - switch (this->m_version & 0xFF00) { - case 0x200: + if (format == 0x100) { + return; + } else if (format == 0x200) { if (this->m_version < 0x201) { return; } std::memcpy(&size, this->m_file->Read(this->m_tableOffset - sizeof(size), sizeof(size)), sizeof(size)); offset = this->m_tableOffset - size - sizeof(size); - break; - case 0x300: { - PakTableFileV3 table; - std::memcpy(&table, this->m_file->Read(this->m_tableOffset, sizeof(table)), sizeof(table)); - size = table.auxiliarySize; - offset = this->m_tableOffset + table.compressedSize + sizeof(table); - break; - } - default: + } else if (format == 0x300) { + const PakTableFileV3* table = reinterpret_cast(this->m_file->Read(this->m_tableOffset, sizeof(PakTableFileV3))); + size = table->auxiliarySize; + offset = this->m_tableOffset + table->compressedSize + sizeof(PakTableFileV3); + } else { return; } @@ -449,7 +447,7 @@ void CGPak::ReadAuxiliary(std::vector& output, std::uint64_t* iden std::memcpy(output.data(), data, size); if (identifier) { - *identifier = ReadAuxiliaryIdentifier(output.data(), output.size()); + *identifier = ReadAuxiliaryIdentifier(output); } }