Skip to content

Commit

Permalink
fix(vpkpp): don't write null file data on bake
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Aug 8, 2024
1 parent 526f105 commit 5dac025
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/vpkpp/format/VPK_VTMB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,25 @@ bool VPK_VTMB::bake(const std::string& outputDir_, const Callback& callback) {
}
}

// Read data before overwriting, we don't know if we're writing to ourself
std::vector<std::byte> fileData;
for (auto* entry : entriesToBake) {
if (auto binData = this->readEntry(*entry)) {
entry->offset = fileData.size();

fileData.insert(fileData.end(), binData->begin(), binData->end());
} else {
entry->offset = 0;
entry->length = 0;
}
}

{
FileStream stream{outputPath, FileStream::OPT_TRUNCATE | FileStream::OPT_CREATE_IF_NONEXISTENT};
stream.seek_out(0);

// File data
for (auto* entry : entriesToBake) {
if (auto binData = this->readEntry(*entry)) {
entry->offset = stream.tell_out();

stream.write(*binData);
} else {
entry->offset = 0;
entry->length = 0;
}
}
stream.write(fileData);

// Directory
auto dirOffset = stream.tell_out();
Expand Down

0 comments on commit 5dac025

Please sign in to comment.