Skip to content

Commit

Permalink
vpkpp: switch to GUID system over type enum, revamp C# bindings, upda…
Browse files Browse the repository at this point in the history
…te C options header
  • Loading branch information
craftablescience committed Dec 30, 2024
1 parent 073abe1 commit be97344
Show file tree
Hide file tree
Showing 75 changed files with 924 additions and 756 deletions.
6 changes: 3 additions & 3 deletions include/vpkpp/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ struct EntryOptions {
/// BSP/ZIP - The compression strength
int16_t zip_compressionStrength = 5;

/// VPK - The amount in bytes of the file to preload. Maximum is controlled by VPK_MAX_PRELOAD_BYTES (format/VPK.h)
uint16_t vpk_preloadBytes = 0;

/// VPK - Save this entry to the directory VPK
bool vpk_saveToDirectory = false;

/// VPK - The amount in bytes of the file to preload. Maximum is controlled by VPK_MAX_PRELOAD_BYTES (format/VPK.h)
uint32_t vpk_preloadBytes = 0;
};

} // namespace vpkpp
17 changes: 10 additions & 7 deletions include/vpkpp/PackFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "Attribute.h"
#include "Entry.h"
#include "Options.h"
#include "PackFileType.h"

namespace vpkpp {

Expand Down Expand Up @@ -50,8 +49,15 @@ class PackFile {
/// Returns a sorted list of supported extensions for opening, e.g. {".bsp", ".vpk"}
[[nodiscard]] static std::vector<std::string> getOpenableExtensions();

/// Get the file type of the pack file
[[nodiscard]] PackFileType getType() const;
/// Get the GUID corresponding to the pack file type
[[nodiscard]] virtual constexpr std::string_view getGUID() const = 0;

/// Check if the pack file is an instance of the given pack file class
template<typename T>
requires requires (const T&) {{T::GUID} -> std::convertible_to<std::string_view>;}
[[nodiscard]] bool isInstanceOf() const {
return this->getGUID() == T::GUID;
}

/// Returns true if the format has a checksum for each entry
[[nodiscard]] virtual constexpr bool hasEntryChecksums() const {
Expand All @@ -77,7 +83,7 @@ class PackFile {
[[nodiscard]] virtual bool verifyPackFileSignature() const;

/// Does the format support case-sensitive file names?
[[nodiscard]] virtual constexpr bool isCaseSensitive() const noexcept {
[[nodiscard]] virtual constexpr bool isCaseSensitive() const {
return false;
}

Expand Down Expand Up @@ -211,9 +217,6 @@ class PackFile {
static const OpenFactoryFunction& registerOpenExtensionForTypeFactory(std::string_view extension, const OpenFactoryFunction& factory);

std::string fullFilePath;

PackFileType type = PackFileType::UNKNOWN;

EntryTrie entries;
EntryTrie unbakedEntries;
};
Expand Down
20 changes: 0 additions & 20 deletions include/vpkpp/PackFileType.h

This file was deleted.

37 changes: 0 additions & 37 deletions include/vpkpp/format/BSP.h

This file was deleted.

8 changes: 7 additions & 1 deletion include/vpkpp/format/FPX.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ class FPX : public VPK {
/// Open an FPX file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "57D4C78A6198489C81D715D42DD21D2F";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return FPX::GUID;
}

protected:
explicit FPX(const std::string& fullFilePath_);
using VPK::VPK;

[[nodiscard]] static std::unique_ptr<PackFile> openInternal(const std::string& path, const EntryCallback& callback = nullptr);

Expand Down
12 changes: 7 additions & 5 deletions include/vpkpp/format/GCF.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,26 @@ class GCF : public PackFileReadOnly {
public:
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "0C088488F666451E9361297528F2446D";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return GCF::GUID;
}

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

[[nodiscard]] std::vector<std::string> verifyEntryChecksums() const override;

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

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

[[nodiscard]] Attribute getSupportedEntryAttributes() const override;

[[nodiscard]] explicit operator std::string() const override;

protected:
explicit GCF(const std::string& fullFilePath_);
using PackFileReadOnly::PackFileReadOnly;

Header header{};
BlockHeader blockheader{};
Expand Down
8 changes: 7 additions & 1 deletion include/vpkpp/format/GMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class GMA : public PackFile {
/// Open a GMA file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "49191CA83B7B4EBBA86D0EA364AAC457";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return GMA::GUID;
}

[[nodiscard]] constexpr bool hasEntryChecksums() const override {
return true;
}
Expand All @@ -46,7 +52,7 @@ class GMA : public PackFile {
[[nodiscard]] explicit operator std::string() const override;

protected:
explicit GMA(const std::string& fullFilePath_);
using PackFile::PackFile;

void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;

Expand Down
8 changes: 7 additions & 1 deletion include/vpkpp/format/ORE.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ class ORE : public PackFileReadOnly {
/// Open an ORE file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "E7E541C05CFE4934B1CDA931EF2E1D99";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return ORE::GUID;
}

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

[[nodiscard]] Attribute getSupportedEntryAttributes() const override;

protected:
explicit ORE(const std::string& fullFilePath_);
using PackFileReadOnly::PackFileReadOnly;

private:
VPKPP_REGISTER_PACKFILE_OPEN(ORE_EXTENSION, &ORE::open);
Expand Down
8 changes: 7 additions & 1 deletion include/vpkpp/format/PAK.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ class PAK : public PackFile {
/// Open a PAK file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "C282210FE64D46D1AE364D7E8E925542";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return PAK::GUID;
}

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

bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override;

[[nodiscard]] Attribute getSupportedEntryAttributes() const override;

protected:
explicit PAK(const std::string& fullFilePath_);
using PackFile::PackFile;

void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;

Expand Down
10 changes: 8 additions & 2 deletions include/vpkpp/format/PCK.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ class PCK : public PackFile {
/// Open a PCK file (potentially embedded in an executable)
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

[[nodiscard]] constexpr bool isCaseSensitive() const noexcept override {
static constexpr inline std::string_view GUID = "28F4A6FF40EB46E38D47EEC6EFB47C4F";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return PCK::GUID;
}

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

Expand All @@ -62,7 +68,7 @@ class PCK : public PackFile {
void setGodotVersion(uint32_t major, uint32_t minor = 0, uint32_t patch = 0);

protected:
explicit PCK(const std::string& fullFilePath_);
using PackFile::PackFile;

void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;

Expand Down
10 changes: 8 additions & 2 deletions include/vpkpp/format/VPK.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ constexpr std::string_view VPK_KEYPAIR_PUBLIC_KEY_TEMPLATE = "public_key\n{\n\tt
constexpr std::string_view VPK_KEYPAIR_PRIVATE_KEY_TEMPLATE = "private_key\n{\n\ttype \"rsa\"\n\trsa_private_key \"%s\"\n\tprivate_key_encrypted 0\n\tpublic_key\n\t{\n\t\ttype \"rsa\"\n\t\trsa_public_key \"%s\"\n\t}\n}\n";

/// Maximum preload data size in bytes
constexpr uint32_t VPK_MAX_PRELOAD_BYTES = 1024;
constexpr uint16_t VPK_MAX_PRELOAD_BYTES = 1024;

/// Chunk size in bytes (default is 200mb)
constexpr uint32_t VPK_DEFAULT_CHUNK_SIZE = 200 * 1024 * 1024;
Expand Down Expand Up @@ -70,6 +70,12 @@ class VPK : public PackFile {
/// Open a VPK file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "98148F7C8701469CB2D8F8620FD738A3";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return VPK::GUID;
}

[[nodiscard]] constexpr bool hasEntryChecksums() const override {
return true;
}
Expand Down Expand Up @@ -122,7 +128,7 @@ class VPK : public PackFile {
void setChunkSize(uint32_t newChunkSize);

protected:
explicit VPK(const std::string& fullFilePath_);
using PackFile::PackFile;

[[nodiscard]] static std::unique_ptr<PackFile> openInternal(const std::string& path, const EntryCallback& callback = nullptr);

Expand Down
8 changes: 7 additions & 1 deletion include/vpkpp/format/VPK_VTMB.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class VPK_VTMB : public PackFile {
/// Open Vampire: The Masquerade - Bloodlines VPK files
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "5942653FBD0F4A2D9EF33CDDA668C396";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return VPK_VTMB::GUID;
}

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

bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override;
Expand All @@ -23,7 +29,7 @@ class VPK_VTMB : public PackFile {
[[nodiscard]] Attribute getSupportedEntryAttributes() const override;

protected:
explicit VPK_VTMB(const std::string& fullFilePath_);
using PackFile::PackFile;

void openNumbered(uint32_t archiveIndex, const std::string& path, const EntryCallback& callback);

Expand Down
8 changes: 7 additions & 1 deletion include/vpkpp/format/WAD3.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ class WAD3 : public PackFile {
/// Open a WAD3 file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "1B4D626A278F47B9B2D4ADB244218B03";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return WAD3::GUID;
}

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

bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override;

[[nodiscard]] Attribute getSupportedEntryAttributes() const override;

protected:
explicit WAD3(const std::string& fullFilePath_);
using PackFile::PackFile;

void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;

Expand Down
12 changes: 9 additions & 3 deletions include/vpkpp/format/ZIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ class ZIP : public PackFile {
/// Open a ZIP file
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);

static constexpr inline std::string_view GUID = "3F3FDBC4F5D44B1F8A8E3AF5611B561B";

[[nodiscard]] constexpr std::string_view getGUID() const override {
return ZIP::GUID;
}

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

[[nodiscard]] std::vector<std::string> verifyEntryChecksums() const override;

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

Expand All @@ -39,9 +45,9 @@ class ZIP : public PackFile {

void setEntryCompressionType(const std::string& path_, EntryCompressionType type);

[[nodiscard]] uint16_t getEntryCompressionStrength(const std::string& path_) const;
[[nodiscard]] int16_t getEntryCompressionStrength(const std::string& path_) const;

void setEntryCompressionStrength(const std::string& path_, uint16_t strength);
void setEntryCompressionStrength(const std::string& path_, int16_t strength);

protected:
explicit ZIP(const std::string& fullFilePath_);
Expand Down
1 change: 0 additions & 1 deletion include/vpkpp/vpkpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
#include "Entry.h"
#include "Options.h"
#include "PackFile.h"
#include "PackFileType.h"
Loading

0 comments on commit be97344

Please sign in to comment.