]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/pakstuff.h
fix unzip code
[xonotic/netradiant.git] / libs / pakstuff.h
1 /*
2    Copyright (C) 1999-2007 id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #ifndef _PAKSTUFF_H_
23 #define _PAKSTUFF_H_
24
25 #ifndef _WIN32
26 #define WINAPI
27 #else
28 #include <windows.h>
29 #endif
30
31 #ifndef __cplusplus
32 typedef int bool; // leo
33 #endif
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39
40 typedef char Int8;
41 typedef short Int16;
42 typedef long Int32;
43 typedef unsigned char UInt8;
44 typedef unsigned short UInt16;
45 typedef unsigned long UInt32;
46 typedef float Float32;
47 typedef double Float64;
48 #define MAX( a, b )              ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
49 #define MIN( a, b )              ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
50 #define RANDOM( x )              ( random() % ( x ) )
51 #define RANDOMIZE()             srand( (int) time( NULL ) )
52
53 #define FTYPE_UNKNOWN 0
54 #define FTYPE_IWAD    1    /* .wad  "IWAD" */
55 #define FTYPE_PWAD    2    /* .wad  "PWAD" */
56 #define FTYPE_PACK    3    /* .pak  "PACK" */
57 #define FTYPE_WAD2    4    /* .wad  "WAD2" */
58 #define FTYPE_BSP     10   /* .bsp  (0x17 0x00 0x00 0x00) */
59 #define FTYPE_MODEL   11   /* .mdl  "IDPO" */
60 #define FTYPE_SPRITE  12   /* .spr  "IDSP" */
61 #define FTYPE_WAV     20   /* .wav  "RIFF" */
62 #define FTYPE_AU      21   /* .au   ".snd" */
63 #define FTYPE_VOC     22   /* .voc  ?      */
64 #define FTYPE_PBM_ASC 30   /* .pbm  "P1"   */
65 #define FTYPE_PGM_ASC 31   /* .pgm  "P2"   */
66 #define FTYPE_PPM_ASC 32   /* .ppm  "P3"   */
67 #define FTYPE_PBM_RAW 33   /* .pbm  "P4"   */
68 #define FTYPE_PGM_RAW 34   /* .pgm  "P5"   */
69 #define FTYPE_PPM_RAW 35   /* .ppm  "P6"   */
70 #define FTYPE_BMP     36   /* .bmp  "BM"   */
71 #define FTYPE_GIF     37   /* .gif  "GIF8" */
72 #define FTYPE_PCX     38   /* .pcx  (0x0a 0x05 0x01 0x08) */
73 #define FTYPE_ERROR   -1
74
75 #ifdef FAT_ENDIAN
76 Bool    ReadInt16( FILE *file, UInt16 huge *x );
77 Bool    ReadInt32( FILE *file, UInt32 huge *x );
78 Bool    ReadFloat32( FILE *file, Float32 huge *x );
79 Bool    WriteInt16( FILE *file, UInt16 huge *x );
80 Bool    WriteInt32( FILE *file, UInt32 huge *x );
81 Bool    WriteFloat32( FILE *file, Float32 huge *x );
82 UInt16  SwapInt16( UInt16 x );
83 UInt32  SwapInt32( UInt32 x );
84 Float32 SwapFloat32( Float32 x );
85 #else
86 #define ReadInt16( f, p )     ReadBytes( ( f ), ( p ), 2L )
87 #define ReadInt32( f, p )     ReadBytes( ( f ), ( p ), 4L )
88 #define ReadFloat32( f, p )   ReadBytes( ( f ), ( p ), 4L )
89 #define WriteInt16( f, p )    WriteBytes( ( f ), ( p ), 2L )
90 #define WriteInt32( f, p )    WriteBytes( ( f ), ( p ), 4L )
91 #define WriteFloat32( f, p )  WriteBytes( ( f ), ( p ), 4L )
92 #define SwapInt16( x )        ( x )
93 #define SwapInt32( x )        ( x )
94 #define SwapFloat32( x )      ( x )
95 #endif /* FAT_ENDIAN */
96
97 #define FROMDISK    -1
98 struct PACKDirectory
99 {
100         char name[56];              /* name of file */
101         UInt32 offset;              /* offset to start of data */
102         UInt32 size;                /* byte size of data */
103 };
104 typedef struct PACKDirectory *PACKDirPtr;
105
106 typedef struct DirListStruct
107 {
108         char dirname[1024];
109         int from;
110         struct  DirListStruct   *next;
111 } DIRLIST;
112
113 typedef struct FileListStruct
114 {
115         char filename[1024];
116         UInt32 offset;
117         UInt32 size;
118         struct  FileListStruct  *next;
119 } FILELIST;
120
121 typedef struct DirStruct
122 {
123         char name[1024];
124         FILELIST            *files;
125         struct DirStruct    *next;
126 } DIRECTORY;
127
128
129 extern int m_nPAKIndex;
130 extern FILE* pakfile[16];
131 extern bool pakopen;
132 extern DIRECTORY    *paktextures;
133
134 void ClearFileList( FILELIST ** );
135 void ClearDirList( DIRLIST ** );
136 bool GetPackFileList( FILELIST **, char * );
137 bool GetPackTextureDirs( DIRLIST ** );
138 bool AddToDirListAlphabetized( DIRLIST **, char *, int );
139 bool AddToFileListAlphabetized( FILELIST * *t, char *, UInt32, UInt32, bool );
140 bool PakLoadFile( const char *, void ** );
141 void OpenPakFile( const char * );
142 void ClosePakFile( void );
143 int  PakLoadAnyFile( const char *filename, void **bufferptr );
144 void WINAPI InitPakFile( const char * pBasePath, const char *pName );
145
146 #ifdef __cplusplus
147 }
148 #endif
149
150 #endif