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// ReSharper disable CppRedundantQualifier
2
3#pragma once
4
6
7#include "../PackFile.h"
8
9namespace vpkpp {
10
12constexpr std::string_view PCK_PATH_PREFIX = "res://";
13constexpr std::string_view PCK_EXTENSION = ".pck";
14
15class PCK : public PackFile {
16protected:
17 enum FlagsDirV2 : uint32_t {
21 };
22
23 enum FlagsFileV2 : uint32_t {
27 };
28
29 struct Header {
30 uint32_t packVersion;
34 FlagsDirV2 flags; // packVersion >= 2
35 };
36
37public:
39 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);
40
42 [[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);
43
44 static constexpr std::string_view GUID = "28F4A6FF40EB46E38D47EEC6EFB47C4F";
45
46 [[nodiscard]] constexpr std::string_view getGUID() const override {
47 return PCK::GUID;
48 }
49
50 [[nodiscard]] constexpr bool isCaseSensitive() const override {
51 return true;
52 }
53
54 [[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;
55
56 bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override;
57
58 [[nodiscard]] Attribute getSupportedEntryAttributes() const override;
59
60 [[nodiscard]] explicit operator std::string() const override;
61
63 [[nodiscard]] uint32_t getVersion() const;
64
66 void setVersion(uint32_t version);
67
68 [[nodiscard]] std::tuple<uint32_t, uint32_t, uint32_t> getGodotVersion() const;
69
70 void setGodotVersion(uint32_t major, uint32_t minor = 0, uint32_t patch = 0);
71
72protected:
74
75 void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;
76
78
79 std::size_t startOffset = 0;
80 std::size_t dataOffset = 0;
81
82private:
85};
86
87} // namespace vpkpp
#define VPKPP_REGISTER_PACKFILE_OPEN_EXECUTABLE(function)
Definition PackFile.h:258
#define VPKPP_REGISTER_PACKFILE_OPEN(extension, function)
Definition PackFile.h:255
This class represents the metadata that a file has inside a PackFile.
Definition Entry.h:14
void setGodotVersion(uint32_t major, uint32_t minor=0, uint32_t patch=0)
Definition PCK.cpp:326
void addEntryInternal(Entry &entry, const std::string &path, std::vector< std::byte > &buffer, EntryOptions options) override
Definition PCK.cpp:160
static constexpr std::string_view GUID
Definition PCK.h:44
std::size_t startOffset
Definition PCK.h:79
std::tuple< uint32_t, uint32_t, uint32_t > getGodotVersion() const
Definition PCK.cpp:322
Header header
Definition PCK.h:77
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:84
constexpr std::string_view getGUID() const override
Get the GUID corresponding to the pack file type.
Definition PCK.h:46
constexpr bool isCaseSensitive() const override
Does the format support case-sensitive file names?
Definition PCK.h:50
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:136
uint32_t getVersion() const
Returns 1 for v1, 2 for v2.
Definition PCK.cpp:312
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
Definition PCK.cpp:294
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:170
FlagsFileV2
Definition PCK.h:23
@ FLAG_FILE_ENCRYPTED
Definition PCK.h:25
@ FLAG_FILE_NONE
Definition PCK.h:24
@ FLAG_FILE_REMOVED
Definition PCK.h:26
std::size_t dataOffset
Definition PCK.h:80
PackFile(const PackFile &other)=delete
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:316
FlagsDirV2
Definition PCK.h:17
@ FLAG_DIR_ENCRYPTED
Definition PCK.h:19
@ FLAG_DIR_NONE
Definition PCK.h:18
@ FLAG_DIR_RELATIVE_FILE_DATA
Definition PCK.h:20
EntryCallbackBase< void > EntryCallback
Definition PackFile.h:38
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:20
Attribute
Definition Attribute.h:7
constexpr auto PCK_SIGNATURE
Definition PCK.h:11
constexpr std::string_view PCK_EXTENSION
Definition PCK.h:13
constexpr std::string_view PCK_PATH_PREFIX
Definition PCK.h:12
uint32_t godotVersionMajor
Definition PCK.h:31
uint32_t packVersion
Definition PCK.h:30
FlagsDirV2 flags
Definition PCK.h:34
uint32_t godotVersionPatch
Definition PCK.h:33
uint32_t godotVersionMinor
Definition PCK.h:32