Skip to content

Commit

Permalink
feat(Vfs): support uncompressed VdfsTool VDFs
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Mar 27, 2024
1 parent aca1179 commit d0b8dcf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Vfs.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright © 2023 GothicKit Contributors.
// SPDX-License-Identifier: MIT
#include "zenkit/Vfs.hh"

#include "Internal.hh"
#include "zenkit/Error.hh"
#include "zenkit/Stream.hh"

Expand All @@ -16,6 +18,7 @@
namespace zenkit {
static constexpr std::string_view VFS_DISK_SIGNATURE_G1 = "PSVDSC_V2.00\r\n\r\n";
static constexpr std::string_view VFS_DISK_SIGNATURE_G2 = "PSVDSC_V2.00\n\r\n\r";
static constexpr std::string_view VFS_DISK_SIGNATURE_VDFSTOOL = "PSVDSC_V2.00\x1A\x1A\x1A\x1A";

class ZKINT RawBufferBacking final : public phoenix::buffer_backing {
public:
Expand Down Expand Up @@ -538,14 +541,24 @@ namespace zenkit {
throw VfsBrokenDiskError {"Detected unsupported Union disk"};
}

if (signature != VFS_DISK_SIGNATURE_G1 && signature != VFS_DISK_SIGNATURE_G2) {
if (signature == VFS_DISK_SIGNATURE_VDFSTOOL) {
ZKLOGI("Vfs", "VDFS tool disk detected");
} else if (signature == VFS_DISK_SIGNATURE_G1) {
ZKLOGD("Vfs", "Gothic 1 disk detected");
} else if (signature == VFS_DISK_SIGNATURE_G2) {
ZKLOGD("Vfs", "Gothic 2 disk detected");
} else {
throw VfsBrokenDiskError {signature};
}

if (auto it = comment.find('\x1A'); it != std::string::npos) {
comment.resize(it);
}

if (catalog_offset == 0) {
catalog_offset = r->tell();
}

std::function<bool(VfsNode*)> load_entry =
[&load_entry, overwrite, catalog_offset, timestamp, &r, buf, size](VfsNode* parent) {
auto e_name = r->read_string(64);
Expand Down

0 comments on commit d0b8dcf

Please sign in to comment.