Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/vpkpp/format/HOG.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ class HOG : public PackFileReadOnly {
return HOG::GUID;
}

[[nodiscard]] constexpr bool isCaseSensitive() const override {
return true;
}

[[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;

[[nodiscard]] Attribute getSupportedEntryAttributes() const override;
Expand Down
4 changes: 0 additions & 4 deletions include/vpkpp/format/VPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class VPP : public PackFileReadOnly {
return VPP::GUID;
}

[[nodiscard]] constexpr bool isCaseSensitive() const override {
return true;
}

[[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;

[[nodiscard]] Attribute getSupportedEntryAttributes() const override;
Expand Down
59 changes: 53 additions & 6 deletions src/vpkpp/format/VPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ std::unique_ptr<PackFile> VPP::open(const std::string& path, const EntryCallback
}

// Create entries
if (const auto version = reader.read<uint32_t>(); version == 1) {
// Get header fields
const auto version = reader.read<uint32_t>();
if (version == 1) {
// Get number of entries
const auto entryCount = reader.read<uint32_t>();

// Verify file size
if (reader.read<uint32_t>() != std::filesystem::file_size(path)) {
return nullptr;
}

// Seek past header to 2048 byte boundary
reader.seek_in(VPP_ALIGNMENT);
// Get file table offset
static constexpr uint32_t headerSize = sizeof(uint32_t) * 4;
reader.seek_in(headerSize + sourcepp::math::paddingForAlignment(VPP_ALIGNMENT, headerSize));

// Get first file offset
// 64 is the byte size of each file directory entry
uint32_t entryOffset = VPP_ALIGNMENT + sourcepp::math::paddingForAlignment(VPP_ALIGNMENT, 64 * entryCount);
const uint32_t fileTableSize = (60 + sizeof(uint32_t)) * entryCount;
uint32_t entryOffset = reader.tell_in() + fileTableSize + sourcepp::math::paddingForAlignment(VPP_ALIGNMENT, fileTableSize);

// Read file entries
for (uint32_t i = 0; i < entryCount; i++) {
Expand All @@ -60,6 +62,51 @@ std::unique_ptr<PackFile> VPP::open(const std::string& path, const EntryCallback
// Put it in
vpp->entries.emplace(entryPath, entry);

if (callback) {
callback(entryPath, entry);
}
}
} else if (version == 2) {
// Get number of entries
const auto entryCount = reader.read<uint32_t>();

// Verify file size
if (reader.read<uint32_t>() != std::filesystem::file_size(path)) {
return nullptr;
}

// Get file table offset
static constexpr uint32_t headerSize = sizeof(uint32_t) * 4;
reader.seek_in(headerSize + sourcepp::math::paddingForAlignment(VPP_ALIGNMENT, headerSize));

// Get first file offset
const uint32_t fileTableSize = (24 + sizeof(uint32_t) * 2) * entryCount;
uint32_t entryOffset = reader.tell_in() + fileTableSize + sourcepp::math::paddingForAlignment(VPP_ALIGNMENT, fileTableSize);

// Read file entries
for (uint32_t i = 0; i < entryCount; i++) {
Entry entry = createNewEntry();

// Get file path
const auto entryPath = vpp->cleanEntryPath(reader.read_string(24));

// Get file size
entry.length = reader.read<uint32_t>();

// There's a duplicate size field here
// Probably one means compressed, the other uncompressed
// Just bail out for now
if (reader.read<uint32_t>() != entry.length) {
return nullptr;
}

// Calculate file offset
entry.offset = entryOffset;
entryOffset += entry.length + sourcepp::math::paddingForAlignment(VPP_ALIGNMENT, entry.length);

// Put it in
vpp->entries.emplace(entryPath, entry);

if (callback) {
callback(entryPath, entry);
}
Expand Down
8 changes: 7 additions & 1 deletion test/vpkpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ TEST(vpkpp, hog_read) {
EXPECT_EQ(hog->getEntryCount(), 5);
}

TEST(vpkpp, vpp_read) {
TEST(vpkpp, vpp_v1_read) {
const auto vpp = PackFile::open(ASSET_ROOT "vpkpp/vpp/v1.vpp");
ASSERT_TRUE(vpp);
EXPECT_EQ(vpp->getEntryCount(), 29);
}

TEST(vpkpp, vpp_v2_read) {
const auto vpp = PackFile::open(ASSET_ROOT "vpkpp/vpp/v2.vpp");
ASSERT_TRUE(vpp);
EXPECT_EQ(vpp->getEntryCount(), 32);
}