]> git.xonotic.org Git - xonotic/darkplaces.git/blob - vpk.h
fs: Create header for Source engine VPK format
[xonotic/darkplaces.git] / vpk.h
1 /*
2 Copyright (C) 2021 David Knapp (Cloudwalk)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "qtypes.h"
22 #include "qdefs.h"
23
24 /*
25  * The VPK format is Valve's package format for Source engine games,
26  * used to store game content.
27  * 
28  * Game content is spread across multiple VPK files. A single, special
29  * VPK file, ending in _dir.vpk, contains a centralized directory
30  * tree for all of the other files, and has its own header.
31  * Although content can be stored in the directory file.
32  * 
33  * This is useful for navigating game content without having
34  * to guess which VPK some file belongs to, while also
35  * making game updates more efficient by spreading content
36  * across multiple files, where opening and closing thousands
37  * of loose files to update them is less efficient.
38  */
39
40 const uint32_t VPK_SIGNATURE = 0x55aa1234;
41
42 typedef struct dvpk_header_v1_s
43 {
44         const uint32_t signature; // Should always be VPK_SIGNATURE
45         const uint32_t version; // Should always be 1
46
47         // Size of directory tree
48         uint32_t tree_size;
49 } dvpk_header_v1_t;
50
51 typedef struct dvpk_header_v2_s
52 {
53         const uint32_t signature; // Should always be VPK_SIGNATURE
54         const uint32_t version; // Should always be 2
55
56         // Size of directory tree
57         uint32_t tree_size;
58
59         // Section sizes
60         uint32_t filedata_size;
61         uint32_t archivemd5_size;
62         uint32_t othermd5_size;
63         uint32_t signature_size;
64 } dvpk_header_v2_t;
65
66 typedef struct dvpk_dir_entry_s
67 {
68         uint32_t crc32;
69         uint16_t preloadbytes;
70
71         uint16_t archiveindex;
72         uint32_t entryoffset;
73         uint32_t entrylength;
74         const uint16_t terminator; // Should always be 0xFFFF
75 } dvpk_dir_entry_t;
76
77 typedef struct dvpk_archive_md5_entry_s
78 {
79         uint32_t archiveindex;
80         uint32_t startingoffset;
81         uint32_t count;
82         int8_t md5sum[16];
83 } dvpk_archive_md5_entry_t;
84
85 typedef struct dvpk_other_md5_entry_s
86 {
87         int8_t treesum[16];
88         int8_t archivemd5sum[16];
89         int8_t unknown[16]; // ??
90 } dvpk_other_md5_entry_t;
91
92 typedef struct dvpk_signature_entry_s
93 {
94         uint32_t pubkeysize; // Always 160
95         int8_t pubkey[160];
96         uint32_t signaturesize; // Always 128
97         int8_t signature[128];
98 } dvpk_signature_entry_t;