]> git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/vfswad/unwad.h
fix bobtoolz patch caulk crash
[xonotic/netradiant.git] / plugins / vfswad / unwad.h
1
2 #ifndef _WAD3_H_
3 #define _WAD3_H_
4
5 // WAD3 (Half-Life) Header and mip structs
6 // WAD2 (Quake) Header and mip structs added by LordHavoc
7
8 #define WADBUFSIZE 32768
9
10 #define WAD2_TYPE_MIP   0x44
11 #define WAD2_ID         ( 'W' | 'A' << 8 | 'D' << 16 | '2' << 24 )
12 #define WAD3_TYPE_MIP   0x43
13 #define WAD3_ID         ( 'W' | 'A' << 8 | 'D' << 16 | '3' << 24 )
14 #define GET_MIP_DATA_SIZE( WIDTH, HEIGHT )        ( ( WIDTH * HEIGHT ) + ( WIDTH * HEIGHT / 4 ) + ( WIDTH * HEIGHT / 16 ) + ( WIDTH * HEIGHT / 64 ) )
15
16 /*
17
18    WAD3 pseudo-structure:
19
20     WAD3 Header
21     Mip section
22         First mip
23             Mip header
24             First mip (width * height)
25             Second mip (width * height / 4)
26             Third mip (width * height / 16)
27             Fourth mip (width * height / 64)
28             Palette size (WORD)
29             Palette (Palette size * 3)
30             Padding (WORD)
31         [...]
32         Last mip
33     Lump table
34         First lump entry
35             Lump header
36         [...]
37         Last lump entry
38
39    WAD2 pseudo-structure:
40
41     WAD2 Header
42     Mip section
43         First mip
44             Mip header
45             First mip (width * height)
46             Second mip (width * height / 4)
47             Third mip (width * height / 16)
48             Fourth mip (width * height / 64)
49         [...]
50         Last mip
51     Lump table
52         First lump entry
53             Lump header
54         [...]
55         Last lump entry
56  */
57
58 #define DWORD unsigned int
59 #define BYTE unsigned char
60 #define WORD unsigned short int
61
62 typedef struct
63 {
64         DWORD identification;
65         DWORD numlumps;
66         DWORD infotableofs;                 // Lump table
67 } WAD3_HEADER, *LPWAD3_HEADER;
68
69 typedef struct
70 {
71         DWORD filepos;
72         DWORD disksize;
73         DWORD size;                         // uncompressed
74         BYTE type;
75         BYTE compression;
76         BYTE pad1, pad2;
77         char name[16];                      // must be null terminated
78 } WAD3_LUMP, *LPWAD3_LUMP;
79
80 typedef struct
81 {
82         char name[16];
83         DWORD width, height;
84         DWORD offsets[4];           // four mip maps stored
85 } WAD3_MIP, *LPWAD3_MIP;
86
87
88 typedef struct wadFile_s
89 {
90         FILE * fin;
91         LPWAD3_HEADER lpHeader;
92         LPWAD3_LUMP lpLump;
93         LPWAD3_MIP lpMip;
94
95         DWORD FileSize;
96         unsigned long currentfile;
97         char *wadfilename;
98 } wadFile_t;
99
100
101 wadFile_t *wadOpen( const char* path );
102 wadFile_t *wadCleanup( wadFile_t *wf );
103 int wadGoToFirstFile( wadFile_t *wf );
104 int wadGetCurrentFileInfo( wadFile_t *wf, char *szFileName, unsigned long fileNameBufferSize, unsigned long *filesize );
105 int wadGoToNextFile( wadFile_t *wf );
106
107 int wadOpenCurrentFileByNum( wadFile_t *wf, unsigned long filenumber );
108 void wadCloseCurrentFile( wadFile_t *wf );
109 unsigned long wadReadCurrentFile( wadFile_t *wf, char *bufferptr, unsigned long size );
110
111 #endif      // #ifndef _WAD3_H_