Rev 300 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 300 | Rev 333 | ||
---|---|---|---|
Line 38... | Line 38... | ||
38 | #include "w_wad.h" |
38 | #include "w_wad.h" |
Line 39... | Line 39... | ||
39 | 39 | ||
Line -... | Line 40... | ||
- | 40 | #include |
|
- | 41 | ||
- | 42 | ||
- | 43 | extern char *main_file; |
|
- | 44 | ||
- | 45 | #ifdef DLHEAP |
|
- | 46 | ||
- | 47 | void* _cdecl dlmalloc(size_t); |
|
- | 48 | void _cdecl dlfree(void*); |
|
- | 49 | void _cdecl mf_init(); |
|
- | 50 | ||
- | 51 | #define malloc dlmalloc |
|
- | 52 | #define free dlfree |
|
- | 53 | #define realloc dlrealloc |
|
- | 54 | ||
- | 55 | #endif |
|
- | 56 | ||
- | 57 | size_t FileSize(FILE *handle); |
|
- | 58 | ||
- | 59 | int _stdcall read_file (char *name, void *buff, |
|
- | 60 | size_t offset, size_t count, size_t *reads); |
|
40 | #include |
61 | |
41 | 62 | ||
42 | 63 | ||
Line 43... | Line 64... | ||
43 | // |
64 | // |
44 | // GLOBALS |
65 | // GLOBALS |
45 | // |
66 | // |
Line 46... | Line 67... | ||
46 | 67 | ||
Line 47... | Line -... | ||
47 | // Location of each lump on disk. |
- | |
48 | lumpinfo_t* lumpinfo; |
- | |
49 | int numlumps; |
- | |
50 | - | ||
51 | void** lumpcache; |
- | |
52 | - | ||
53 | - | ||
54 | int filelength (FILE *handle) |
- | |
55 | { |
- | |
56 | unsigned long pos, size; |
- | |
57 | - | ||
58 | pos = ftell(handle); |
- | |
59 | fseek(handle, 0, SEEK_END); |
- | |
60 | size = ftell(handle); |
68 | // Location of each lump on disk. |
61 | fseek(handle, pos, SEEK_SET); |
69 | lumpinfo_t* lumpinfo; |
62 | return (int)size; |
70 | int numlumps; |
63 | } |
71 | |
64 | 72 | void** lumpcache; |
|
Line 113... | Line 121... | ||
113 | // |
121 | // |
114 | // If filename starts with a tilde, the file is handled |
122 | // If filename starts with a tilde, the file is handled |
115 | // specially to allow map reloads. |
123 | // specially to allow map reloads. |
116 | // But: the reload feature is a fragile hack... |
124 | // But: the reload feature is a fragile hack... |
Line 117... | Line -... | ||
117 | - | ||
118 | #ifdef __BEOS__ |
- | |
119 | #ifdef __GNUC__ |
- | |
120 | extern void *alloca(int); |
- | |
121 | #else |
- | |
122 | #include |
- | |
123 | #endif |
- | |
Line 124... | Line 125... | ||
124 | #endif /* __BEOS__ */ |
125 | |
125 | 126 | ||
Line 136... | Line 137... | ||
136 | int length; |
137 | int length; |
137 | int startlump; |
138 | int startlump; |
138 | filelump_t* fileinfo; |
139 | filelump_t* fileinfo; |
139 | filelump_t singleinfo; |
140 | filelump_t singleinfo; |
140 | int storehandle; |
141 | int storehandle; |
- | 142 | int err; |
|
- | 143 | size_t bytes; |
|
Line 141... | Line 144... | ||
141 | 144 | ||
Line 142... | Line 145... | ||
142 | // open the file and add to directory |
145 | // open the file and add to directory |
143 | 146 | ||
Line 153... | Line 156... | ||
153 | { |
156 | { |
154 | printf (" couldn't open %s\n",filename); |
157 | printf (" couldn't open %s\n",filename); |
155 | return; |
158 | return; |
156 | } |
159 | } |
Line 157... | Line 160... | ||
157 | 160 | ||
158 | printf (" adding %s\n",filename); |
161 | printf (" adding %s\n\r",filename); |
Line 159... | Line 162... | ||
159 | startlump = numlumps; |
162 | startlump = numlumps; |
160 | 163 | ||
161 | if (I_strncasecmp (filename+strlen(filename)-3 , "wad", 3 ) ) |
164 | if (strnicmp (filename+strlen(filename)-3 , "wad", 3 ) ) |
162 | { |
165 | { |
163 | // single lump file |
166 | // single lump file |
164 | fileinfo = &singleinfo; |
167 | fileinfo = &singleinfo; |
165 | singleinfo.filepos = 0; |
168 | singleinfo.filepos = 0; |
166 | singleinfo.size = LONG(filelength(handle)); |
169 | singleinfo.size = FileSize(handle); |
167 | ExtractFileBase (filename, singleinfo.name); |
170 | ExtractFileBase (filename, singleinfo.name); |
168 | numlumps++; |
171 | numlumps++; |
169 | } |
172 | } |
170 | else |
173 | else |
171 | { |
- | |
172 | //WAD file |
174 | { |
173 | printf("f1 at %x,%u\n",&header,handle); |
- | |
- | 175 | //WAD file |
|
174 | fread (&header, 1, sizeof(header), handle); |
176 | fread (&header, 1, sizeof(header), handle); |
175 | printf("f2\n"); |
177 | |
176 | if (strncmp(header.identification,"IWAD",4)) |
178 | if (strncmp(header.identification,"IWAD",4)) |
177 | { |
179 | { |
178 | printf("No IWAD id\n"); |
180 | printf("No IWAD id\n"); |
179 | // Homebrew levels? |
181 | // Homebrew levels? |
180 | if (strncmp(header.identification,"PWAD",4)) |
182 | if (strncmp(header.identification,"PWAD",4)) |
181 | { |
183 | { |
182 | I_Error ("Wad file %s doesn't have IWAD " |
184 | I_Error ("Wad file %s doesn't have IWAD " |
183 | "or PWAD id\n", filename); |
185 | "or PWAD id\n", filename); |
184 | } |
186 | } |
185 | // printf("WAD magic OK\n"); |
187 | printf("WAD magic OK\n"); |
186 | // ???modifiedgame = true; |
- | |
187 | } |
188 | // ???modifiedgame = true; |
188 | printf("after checking hdr\n"); |
- | |
- | 189 | } |
|
189 | header.numlumps = LONG(header.numlumps); |
190 | header.numlumps = LONG(header.numlumps); |
190 | printf("%u lumps in WAD\n",header.numlumps); |
- | |
- | 191 | ||
191 | header.infotableofs = LONG(header.infotableofs); |
192 | header.infotableofs = LONG(header.infotableofs); |
192 | printf("infor table at %x\n",header.infotableofs); |
- | |
- | 193 | ||
193 | length = header.numlumps*sizeof(filelump_t); |
194 | length = header.numlumps*sizeof(filelump_t); |
Line 194... | Line -... | ||
194 | printf("length %u\n",length); |
- | |
195 | fileinfo = alloca(length); |
195 | |
196 | - | ||
197 | printf("seeking to info table\n"); |
196 | fileinfo = alloca(length); |
198 | fseek (handle, header.infotableofs, SEEK_SET); |
- | |
199 | printf("f3\n"); |
197 | |
200 | fread (fileinfo, 1, length, handle); |
198 | fseek (handle, header.infotableofs, SEEK_SET); |
Line 201... | Line 199... | ||
201 | printf("f4\n"); |
199 | fread (fileinfo, 1, length, handle); |
Line 247... | Line 245... | ||
247 | return; |
245 | return; |
Line 248... | Line 246... | ||
248 | 246 | ||
249 | if ( (handle = fopen (reloadname,"rb")) == NULL) |
247 | if ( (handle = fopen (reloadname,"rb")) == NULL) |
Line 250... | Line -... | ||
250 | I_Error ("W_Reload: couldn't open %s",reloadname); |
- | |
251 | 248 | I_Error ("W_Reload: couldn't open %s",reloadname); |
|
252 | printf("f5\n"); |
- | |
- | 249 | ||
253 | fread (&header, 1, sizeof(header), handle); |
250 | fread (&header, 1, sizeof(header), handle); |
254 | printf("f6\n"); |
251 | |
255 | lumpcount = LONG(header.numlumps); |
252 | lumpcount = LONG(header.numlumps); |
256 | header.infotableofs = LONG(header.infotableofs); |
253 | header.infotableofs = LONG(header.infotableofs); |
257 | length = lumpcount*sizeof(filelump_t); |
254 | length = lumpcount*sizeof(filelump_t); |
258 | fileinfo = malloc (length); |
- | |
259 | fseek (handle, header.infotableofs, SEEK_SET); |
255 | fileinfo = malloc (length); |
260 | printf("f7\n"); |
- | |
Line 261... | Line 256... | ||
261 | fread (fileinfo, 1, length, handle); |
256 | fseek (handle, header.infotableofs, SEEK_SET); |
262 | printf("f8\n"); |
257 | fread (fileinfo, 1, length, handle); |
Line 263... | Line 258... | ||
263 | 258 | ||
Line 276... | Line 271... | ||
276 | } |
271 | } |
Line 277... | Line 272... | ||
277 | 272 | ||
278 | fclose (handle); |
273 | fclose (handle); |
Line 279... | Line -... | ||
279 | } |
- | |
280 | - | ||
281 | 274 | } |
|
282 | 275 | ||
283 | // |
276 | // |
284 | // W_InitMultipleFiles |
277 | // W_InitMultipleFiles |
285 | // Pass a null terminated list of files to use. |
278 | // Pass a null terminated list of files to use. |
Line 299... | Line 292... | ||
299 | 292 | ||
300 | // open all the files, load headers, and count lumps |
293 | // open all the files, load headers, and count lumps |
Line 301... | Line 294... | ||
301 | numlumps = 0; |
294 | numlumps = 0; |
302 | 295 | ||
Line 303... | Line 296... | ||
303 | // will be realloced as lumps are added |
296 | // will be realloced as lumps are added |
304 | lumpinfo = malloc(1); |
297 | lumpinfo = malloc(16384); |
Line 305... | Line 298... | ||
305 | 298 | ||
Line 438... | Line 431... | ||
438 | void* dest ) |
431 | void* dest ) |
439 | { |
432 | { |
440 | int c; |
433 | int c; |
441 | lumpinfo_t* l; |
434 | lumpinfo_t* l; |
442 | FILE *handle; |
435 | FILE *handle; |
- | 436 | size_t bytes; |
|
Line 443... | Line 437... | ||
443 | 437 | ||
444 | if (lump >= numlumps) |
438 | if (lump >= numlumps) |
Line 445... | Line 439... | ||
445 | I_Error ("W_ReadLump: %i >= numlumps",lump); |
439 | I_Error ("W_ReadLump: %i >= numlumps",lump); |
Line 480... | Line 474... | ||
480 | ( int lump, |
474 | ( int lump, |
481 | int tag ) |
475 | int tag ) |
482 | { |
476 | { |
483 | byte* ptr; |
477 | byte* ptr; |
Line 484... | Line 478... | ||
484 | 478 | ||
485 | if ((unsigned)lump >= numlumps) |
479 | if ((unsigned)lump >= (unsigned)numlumps) |
Line 486... | Line 480... | ||
486 | I_Error ("W_CacheLumpNum: %i >= numlumps",lump); |
480 | I_Error ("W_CacheLumpNum: %i >= numlumps",lump); |
487 | 481 | ||
488 | if (!lumpcache[lump]) |
482 | if (!lumpcache[lump]) |
Line 566... | Line 560... | ||
566 | break; |
560 | break; |
Line 567... | Line 561... | ||
567 | 561 | ||
568 | for ( ; j<8 ; j++) |
562 | for ( ; j<8 ; j++) |
Line 569... | Line 563... | ||
569 | name[j] = ' '; |
563 | name[j] = ' '; |
Line 570... | Line 564... | ||
570 | 564 | ||
571 | printf ("%s ",name); |
565 | //printf ("%s ",name); |
Line 572... | Line 566... | ||
572 | 566 | ||
573 | for (j=0 ; j |
567 | for (j=0 ; j |
574 | fprintf (f," %c",info[i][j]); |
568 | fprintf (f," %c",info[i][j]); |
575 | 569 | ||
Line 576... | Line 570... | ||
576 | printf ("\n"); |
570 | //printf ("\n"); |
- | 571 | } |
|
- | 572 | fclose (f); |
|
- | 573 | } |
|
- | 574 | ||
- | 575 | #endif8>8>>> |
|
- | 576 | ||
- | 577 |