SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
GCF.h
Go to the documentation of this file.
1#pragma once
2
3#include "../PackFile.h"
4
5namespace vpkpp {
6
7constexpr std::string_view GCF_EXTENSION = ".gcf";
8
9class GCF : public PackFileReadOnly {
10protected:
11#pragma pack(push, 1)
12 struct Header {
13 uint32_t dummy1;
14 uint32_t dummy2;
15 uint32_t gcfversion;
16 uint32_t appid;
17 uint32_t appversion;
18 uint32_t dummy3;
19 uint32_t dummy4;
20 uint32_t filesize;
21 uint32_t blocksize;
22 uint32_t blockcount;
23 uint32_t dummy5;
24 };
25
26 // second header with info about blocks inside the file
27 // appears only ONCE not before every block!
28 struct BlockHeader {
29 uint32_t count;
30 uint32_t used;
31 uint32_t dummy1;
32 uint32_t dummy2;
33 uint32_t dummy3;
34 uint32_t dummy4;
35 uint32_t dummy5;
36 uint32_t checksum;
37 };
38
39 struct Block {
40 enum class CompressionType : uint32_t {
41 UNCOMPRESSED = 0,
42 COMPRESSED, // compressed on the server, client automatically extracts it so not really
45 };
46
47 uint16_t flags;
48 uint16_t open;
54 uint32_t dir_index;
55
56 [[nodiscard]] CompressionType getCompressionType() const {
57 static constexpr std::array compressionTypeLUT = {
62 };
63 const auto idx = (static_cast<std::uint8_t>(flags) & 7) - 1;
64 if (idx <= 3) {
65 return compressionTypeLUT[idx];
66 }
68 }
69
70 [[nodiscard]] bool isEncrypted() const {
71 return static_cast<uint32_t>(this->getCompressionType()) - 2 <= 1;
72 }
73 };
74
76 uint32_t dummy1;
77 uint32_t cacheid;
78 uint32_t gcfversion;
79 uint32_t itemcount;
80 uint32_t filecount;
81 uint32_t dummy2;
82 uint32_t dirsize;
83 uint32_t namesize;
84 uint32_t info1count;
85 uint32_t copycount;
86 uint32_t localcount;
87 uint32_t dummy3;
88 uint32_t dummy4;
89 uint32_t checksum;
90 };
91
93 uint32_t nameoffset;
94 uint32_t itemsize;
95 uint32_t fileid;
96 uint32_t dirtype;
97 uint32_t parentindex;
98 uint32_t nextindex;
99 uint32_t firstindex;
100 };
101
104 std::string filename;
105 };
106
108 uint32_t dummy1;
109 uint32_t dummy2;
110 };
111
114 };
115
117 uint32_t appversion;
118 uint32_t blockcount;
119 uint32_t blocksize;
121 uint32_t used;
122 uint32_t checksum;
123 };
124
126 uint32_t dummy1;
127 uint32_t dummy2;
128 uint32_t item_count;
130 };
131
133 uint32_t count;
134 uint32_t firstindex;
135 };
136#pragma pack(pop)
137
138public:
139 [[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr, const OpenPropertyRequest& requestProperty = nullptr);
140
141 static constexpr inline std::string_view GUID = "0C088488F666451E9361297528F2446D";
142
143 [[nodiscard]] constexpr std::string_view getGUID() const override {
144 return GCF::GUID;
145 }
146
147 [[nodiscard]] constexpr bool hasEntryChecksums() const override {
148 return true;
149 }
150
151 [[nodiscard]] std::vector<std::string> verifyEntryChecksums() const override;
152
153 [[nodiscard]] constexpr bool isCaseSensitive() const override {
154 return true;
155 }
156
157 [[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;
158
159 [[nodiscard]] Attribute getSupportedEntryAttributes() const override;
160
161 [[nodiscard]] explicit operator std::string() const override;
162
163 [[nodiscard]] uint32_t getVersion() const;
164
165 [[nodiscard]] uint32_t getAppID() const;
166
167 [[nodiscard]] uint32_t getAppVersion() const;
168
169protected:
171
174 std::vector<Block> blockdata{};
175 std::vector<uint32_t> fragmap{};
177 //std::vector<DirectoryEntry2> direntries{};
178 std::vector<DirectoryMapEntry> dirmap_entries{};
180 std::vector<ChecksumMapEntry> chksum_map{};
181 std::vector<uint32_t> checksums{};
182 std::array<std::byte, 16> decryption_key;
183private:
185};
186
187} // namespace vpkpp
#define VPKPP_REGISTER_PACKFILE_OPEN(extension, function)
Definition: PackFile.h:252
Definition: GCF.h:9
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr, const OpenPropertyRequest &requestProperty=nullptr)
Definition: GCF.cpp:17
Header header
Definition: GCF.h:172
std::vector< DirectoryMapEntry > dirmap_entries
Definition: GCF.h:178
std::vector< Block > blockdata
Definition: GCF.h:174
BlockHeader blockheader
Definition: GCF.h:173
std::vector< ChecksumMapEntry > chksum_map
Definition: GCF.h:180
std::array< std::byte, 16 > decryption_key
Definition: GCF.h:182
uint32_t getVersion() const
Definition: GCF.cpp:366
std::vector< std::string > verifyEntryChecksums() const override
Verify the checksums of each file, if a file fails the check its path will be added to the vector If ...
Definition: GCF.cpp:204
uint32_t getAppVersion() const
Definition: GCF.cpp:374
constexpr std::string_view getGUID() const override
Get the GUID corresponding to the pack file type.
Definition: GCF.h:143
DataBlockHeader datablockheader
Definition: GCF.h:179
constexpr bool isCaseSensitive() const override
Does the format support case-sensitive file names?
Definition: GCF.h:153
constexpr bool hasEntryChecksums() const override
Returns true if the format has a checksum for each entry.
Definition: GCF.h:147
static constexpr std::string_view GUID
Definition: GCF.h:141
DirectoryHeader dirheader
Definition: GCF.h:176
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
Definition: GCF.cpp:354
std::vector< uint32_t > checksums
Definition: GCF.h:181
uint32_t getAppID() const
Definition: GCF.cpp:370
std::optional< std::vector< std::byte > > readEntry(const std::string &path_) const override
Try to read the entry's data to a bytebuffer.
Definition: GCF.cpp:229
std::vector< uint32_t > fragmap
Definition: GCF.h:175
PackFileReadOnly(const std::string &fullFilePath_)
Definition: PackFile.cpp:729
EntryCallbackBase< void > EntryCallback
Definition: PackFile.h:37
std::function< std::vector< std::byte >(PackFile *packFile, OpenProperty property)> OpenPropertyRequest
Definition: PackFile.h:32
Definition: Attribute.h:5
Attribute
Definition: Attribute.h:7
constexpr std::string_view GCF_EXTENSION
Definition: GCF.h:7
uint32_t checksum
Definition: GCF.h:36
uint32_t dummy5
Definition: GCF.h:35
uint32_t dummy4
Definition: GCF.h:34
uint32_t used
Definition: GCF.h:30
uint32_t dummy2
Definition: GCF.h:32
uint32_t count
Definition: GCF.h:29
uint32_t dummy3
Definition: GCF.h:33
uint32_t dummy1
Definition: GCF.h:31
uint32_t file_data_offset
Definition: GCF.h:49
uint32_t file_data_size
Definition: GCF.h:50
bool isEncrypted() const
Definition: GCF.h:70
uint16_t flags
Definition: GCF.h:47
uint32_t dir_index
Definition: GCF.h:54
uint32_t next_block_entry_index
Definition: GCF.h:52
CompressionType getCompressionType() const
Definition: GCF.h:56
uint16_t open
Definition: GCF.h:48
uint32_t prev_block_entry_index
Definition: GCF.h:53
uint32_t first_data_block_index
Definition: GCF.h:51
uint32_t firstblockoffset
Definition: GCF.h:120
std::string filename
Definition: GCF.h:104
DirectoryEntry entry_real
Definition: GCF.h:103
uint32_t nameoffset
Definition: GCF.h:93
uint32_t nextindex
Definition: GCF.h:98
uint32_t firstindex
Definition: GCF.h:99
uint32_t parentindex
Definition: GCF.h:97
uint32_t dummy5
Definition: GCF.h:23
uint32_t filesize
Definition: GCF.h:20
uint32_t appversion
Definition: GCF.h:17
uint32_t blocksize
Definition: GCF.h:21
uint32_t appid
Definition: GCF.h:16
uint32_t dummy4
Definition: GCF.h:19
uint32_t blockcount
Definition: GCF.h:22
uint32_t dummy2
Definition: GCF.h:14
uint32_t dummy1
Definition: GCF.h:13
uint32_t gcfversion
Definition: GCF.h:15
uint32_t dummy3
Definition: GCF.h:18