]> git.xonotic.org Git - xonotic/darkplaces.git/blob - vpk.h
CREDITS: Add name
[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 #ifndef VPK_H
22 #define VPK_H
23
24 #include "qtypes.h"
25 #include "qdefs.h"
26
27 /*
28  * The VPK format is Valve's package format for Source engine games,
29  * used to store game content.
30  * 
31  * Game content is spread across multiple VPK files. A single, special
32  * VPK file, ending in _dir.vpk, contains a centralized directory
33  * tree for all of the other files, and has its own header.
34  * Although content can be stored in the directory file.
35  * 
36  * This is useful for navigating game content without having
37  * to guess which VPK some file belongs to, while also
38  * making game updates more efficient by spreading content
39  * across multiple files, where opening and closing thousands
40  * of loose files to update them is less efficient.
41  */
42
43 const uint32_t VPK_SIGNATURE = 0x55aa1234;
44
45 typedef struct dvpk_header_v1_s
46 {
47         const uint32_t signature; // Should always be VPK_SIGNATURE
48         const uint32_t version; // Should always be 1
49
50         // Size of directory tree
51         uint32_t tree_size;
52 } dvpk_header_v1_t;
53
54 typedef struct dvpk_header_v2_s
55 {
56         const uint32_t signature; // Should always be VPK_SIGNATURE
57         const uint32_t version; // Should always be 2
58
59         // Size of directory tree
60         uint32_t tree_size;
61
62         // Section sizes
63         uint32_t filedata_size;
64         uint32_t archivemd5_size;
65         uint32_t othermd5_size;
66         uint32_t signature_size;
67 } dvpk_header_v2_t;
68
69 typedef struct dvpk_dir_entry_s
70 {
71         uint32_t crc32;
72         uint16_t preloadbytes;
73
74         uint16_t archiveindex;
75         uint32_t entryoffset;
76         uint32_t entrylength;
77         const uint16_t terminator; // Should always be 0xFFFF
78 } dvpk_dir_entry_t;
79
80 typedef struct dvpk_archive_md5_entry_s
81 {
82         uint32_t archiveindex;
83         uint32_t startingoffset;
84         uint32_t count;
85         int8_t md5sum[16];
86 } dvpk_archive_md5_entry_t;
87
88 typedef struct dvpk_other_md5_entry_s
89 {
90         int8_t treesum[16];
91         int8_t archivemd5sum[16];
92         int8_t unknown[16]; // ??
93 } dvpk_other_md5_entry_t;
94
95 typedef struct dvpk_signature_entry_s
96 {
97         uint32_t pubkeysize; // Always 160
98         int8_t pubkey[160];
99         uint32_t signaturesize; // Always 128
100         int8_t signature[128];
101 } dvpk_signature_entry_t;
102
103 #endif