e470830be662a62216d3daac74cda57eec157d4a
1 /* Copyright (C) 1996-1997 Aleksey Volynskov
2 * Copyright (C) 2011 Rambo
3 * Copyright (C) 2020 SovietPony
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
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. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
22 #ifdef UNIX
23 # include <sys/stat.h>
24 #endif
69 }
76 }
78 }
86 }
88 // build wad directory
94 wad_t w;
99 }
104 }
110 }
122 }
128 }
130 //fclose(h);
137 }
146 }
150 }
157 }
158 }
164 }
178 }
182 }
188 }
189 }
190 }
191 }
192 }
193 }
196 }
198 // allocate resources
199 // (called from M_startup)
207 }
209 // load resource
226 }
228 /*
229 // unused
230 void F_saveres(int r, void *p, dword o, dword l) {
231 FILE* fh = wadh[wad[r].f];
232 int oo = ftell(fh);
233 if (fseek(fh, wad[r].o + o, SEEK_SET) != 0) {
234 ERR_fatal("Error while reading file");
235 }
236 myfwrite(p, l, 1, fh);
237 fseek(fh, oo, SEEK_SET);
238 }
239 */
241 // get resource id
247 }
248 }
250 }
252 // get resource id
257 }
259 }
263 }
265 // get sprite id
278 }
280 }
281 }
282 }
285 }
289 }
304 }
306 }
313 }
314 }
316 // reads bytes from file until CR
326 }
328 i++;
329 }
331 }
333 /*
334 // unused
335 // reads bytes from file until NUL
336 void F_readstrz (FILE* h,char *s,int m) {
337 int i = 0;
338 size_t len = 0;
339 static char c = 0;
340 while (i < m) {
341 c = 0;
342 len = myfreadc(&c, 1, 1, h);
343 if (len == 0 || c == 0) {
344 break;
345 }
346 s[i] = c;
347 i++;
348 }
349 s[i] = 0;
350 }
351 */
353 /*void F_freemus(void) {
355 int i;
357 if(!pat) return;
358 S_stopmusic();
359 free(pat);free(patp);
360 for(i=0;i<inum;++i) if(dmi[i]!=NULL) free(dmi[i]);
361 free(dmi);
362 pat=NULL;
364 }
365 */
367 /*void F_loadmus(char n[8]) {
368 int r,i,j;
369 FILE *h;
370 int o;
371 struct{
372 char id[4];
373 byte ver,pat;
374 word psz;
375 }d;
376 struct{byte t;char n[13];word r;}di;
378 if((r=F_findres(n))==-1) return;
379 fseek(h=wadh[wad[r].f],wad[r].o,SEEK_SET);
380 myfread(&d,1,sizeof(d),h);
381 if(memcmp(d.id,"DMM",4)!=0) return;
382 if(!(pat=malloc(d.psz<<2))) return;
383 myfread(pat,1,d.psz<<2,h);
384 myfread(&seqn,1,1,h);if(seqn) myfread(seq,1,seqn,h);
385 inum=0;myfread(&inum,1,1,h);
386 if(!(dmi=malloc(inum*4))) {free(pat);pat=NULL;return;}
387 if(!(patp=malloc((word)d.pat*32))) {free(pat);free(dmi);pat=NULL;return;}
388 for(i=0;i<inum;++i) {
389 dmi[i]=NULL;
390 myfread(&di,1,16,h);o=ftell(h);
391 for(r=0;r<12;++r) if(di.n[r]=='.') di.n[r]=0;
392 if((r=F_findres(di.n))==-1) continue;
393 if(!(dmi[i]=malloc(wad[r].l+8))) continue;
394 memset(dmi[i],0,16);
395 F_loadres(r,dmi[i],0,2);
396 F_loadres(r,(int*)dmi[i]+1,2,2);
397 F_loadres(r,(int*)dmi[i]+2,4,2);
398 F_loadres(r,(int*)dmi[i]+3,6,2);
399 F_loadres(r,(int*)dmi[i]+4,8,wad[r].l-8);
400 fseek(h,o,SEEK_SET);
401 }
402 for(i=r=0,j=(word)d.pat<<3;i<j;++i) {
403 patp[i]=r<<2;
404 while(pat[r++].v!=0x80);
405 }
406 }
407 */