SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
PCK.h
Go to the documentation of this file.
1#pragma once
2
4
5#include "../PackFile.h"
6
7namespace vpkpp {
8
10constexpr std::string_view PCK_PATH_PREFIX = "res://";
11constexpr std::string_view PCK_EXTENSION = ".pck";
12
13class PCK : public PackFile {
14protected:
15 enum FlagsDirV2 : uint32_t {
19 };
20
21 enum FlagsFileV2 : uint32_t {
25 };
26
27 struct Header {
28 uint32_t packVersion;
32 FlagsDirV2 flags; // packVersion >= 2
33 };
34
35public:
37 static std::unique_ptr<PackFile> create(const std::string& path, uint32_t version = 2, uint32_t godotMajorVersion = 0, uint32_t godotMinorVersion = 0, uint32_t godotPatchVersion = 0);
38
40 [[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);
41
42 static constexpr inline std::string_view GUID = "28F4A6FF40EB46E38D47EEC6EFB47C4F";
43
44 [[nodiscard]] constexpr std::string_view getGUID() const override {
45 return PCK::GUID;
46 }
47
48 [[nodiscard]] constexpr bool isCaseSensitive() const override {
49 return true;
50 }
51
52 [[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;
53
54 bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override;
55
56 [[nodiscard]] Attribute getSupportedEntryAttributes() const override;
57
58 [[nodiscard]] explicit operator std::string() const override;
59
61 [[nodiscard]] uint32_t getVersion() const;
62
64 void setVersion(uint32_t version);
65
66 [[nodiscard]] std::tuple<uint32_t, uint32_t, uint32_t> getGodotVersion() const;
67
68 void setGodotVersion(uint32_t major, uint32_t minor = 0, uint32_t patch = 0);
69
70protected:
72
73 void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;
74
76
77 std::size_t startOffset = 0;
78 std::size_t dataOffset = 0;
79
80private:
83};
84
85} // namespace vpkpp
#define VPKPP_REGISTER_PACKFILE_OPEN_EXECUTABLE(function)
Definition: PackFile.h:245
#define VPKPP_REGISTER_PACKFILE_OPEN(extension, function)
Definition: PackFile.h:242
This class represents the metadata that a file has inside a PackFile.
Definition: Entry.h:14
Definition: PCK.h:13
void setGodotVersion(uint32_t major, uint32_t minor=0, uint32_t patch=0)
Definition: PCK.cpp:318
void addEntryInternal(Entry &entry, const std::string &path, std::vector< std::byte > &buffer, EntryOptions options) override
Definition: PCK.cpp:155
static constexpr std::string_view GUID
Definition: PCK.h:42
std::size_t startOffset
Definition: PCK.h:77
std::tuple< uint32_t, uint32_t, uint32_t > getGodotVersion() const
Definition: PCK.cpp:314
Header header
Definition: PCK.h:75
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open a PCK file (potentially embedded in an executable)
Definition: PCK.h:82
constexpr std::string_view getGUID() const override
Get the GUID corresponding to the pack file type.
Definition: PCK.h:44
constexpr bool isCaseSensitive() const override
Does the format support case-sensitive file names?
Definition: PCK.h:48
std::optional< std::vector< std::byte > > readEntry(const std::string &path_) const override
Try to read the entry's data to a bytebuffer.
Definition: PCK.cpp:131
uint32_t getVersion() const
Returns 1 for v1, 2 for v2.
Definition: PCK.cpp:304
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
Definition: PCK.cpp:286
bool bake(const std::string &outputDir_, BakeOptions options, const EntryCallback &callback) override
If output folder is an empty string, it will overwrite the original.
Definition: PCK.cpp:165
FlagsFileV2
Definition: PCK.h:21
@ FLAG_FILE_ENCRYPTED
Definition: PCK.h:23
@ FLAG_FILE_NONE
Definition: PCK.h:22
@ FLAG_FILE_REMOVED
Definition: PCK.h:24
std::size_t dataOffset
Definition: PCK.h:78
static std::unique_ptr< PackFile > create(const std::string &path, uint32_t version=2, uint32_t godotMajorVersion=0, uint32_t godotMinorVersion=0, uint32_t godotPatchVersion=0)
Create a new PCK file.
Definition: PCK.cpp:15
void setVersion(uint32_t version)
Change the version of the PCK. Valid values are 1 and 2.
Definition: PCK.cpp:308
FlagsDirV2
Definition: PCK.h:15
@ FLAG_DIR_ENCRYPTED
Definition: PCK.h:17
@ FLAG_DIR_NONE
Definition: PCK.h:16
@ FLAG_DIR_RELATIVE_FILE_DATA
Definition: PCK.h:18
EntryCallbackBase< void > EntryCallback
Definition: PackFile.h:30
PackFile(const PackFile &other)=delete
consteval uint32_t makeFourCC(const char fourCC[4])
Creates a FourCC identifier from a string of 4 characters.
Definition: Binary.h:18
Definition: Attribute.h:5
Attribute
Definition: Attribute.h:7
constexpr auto PCK_SIGNATURE
Definition: PCK.h:9
constexpr std::string_view PCK_EXTENSION
Definition: PCK.h:11
constexpr std::string_view PCK_PATH_PREFIX
Definition: PCK.h:10
uint32_t godotVersionMajor
Definition: PCK.h:29
uint32_t packVersion
Definition: PCK.h:28
FlagsDirV2 flags
Definition: PCK.h:32
uint32_t godotVersionPatch
Definition: PCK.h:31
uint32_t godotVersionMinor
Definition: PCK.h:30