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 #include <sys/stat.h>
67 }
74 }
76 }
84 }
86 // build wad directory
92 wad_t w;
97 }
102 }
108 }
120 }
126 }
128 //fclose(h);
135 }
144 }
148 }
155 }
156 }
162 }
176 }
180 }
186 }
187 }
188 }
189 }
190 }
191 }
194 }
196 // allocate resources
197 // (called from M_startup)
205 }
207 // load resource
224 }
226 /*
227 // unused
228 void F_saveres(int r, void *p, dword o, dword l) {
229 FILE* fh = wadh[wad[r].f];
230 int oo = ftell(fh);
231 if (fseek(fh, wad[r].o + o, SEEK_SET) != 0) {
232 ERR_fatal("Ошибка при чтении файла");
233 }
234 myfwrite(p, l, 1, fh);
235 fseek(fh, oo, SEEK_SET);
236 }
237 */
239 // get resource id
245 }
246 }
248 }
250 // get resource id
255 }
257 }
261 }
263 // get sprite id
276 }
278 }
279 }
280 }
283 }
287 }
302 }
304 }
311 }
312 }
314 // reads bytes from file until CR
324 }
326 i++;
327 }
329 }
331 /*
332 // unused
333 // reads bytes from file until NUL
334 void F_readstrz (FILE* h,char *s,int m) {
335 int i = 0;
336 size_t len = 0;
337 static char c = 0;
338 while (i < m) {
339 c = 0;
340 len = myfreadc(&c, 1, 1, h);
341 if (len == 0 || c == 0) {
342 break;
343 }
344 s[i] = c;
345 i++;
346 }
347 s[i] = 0;
348 }
349 */
351 /*void F_freemus(void) {
353 int i;
355 if(!pat) return;
356 S_stopmusic();
357 free(pat);free(patp);
358 for(i=0;i<inum;++i) if(dmi[i]!=NULL) free(dmi[i]);
359 free(dmi);
360 pat=NULL;
362 }
363 */
365 /*void F_loadmus(char n[8]) {
366 int r,i,j;
367 FILE *h;
368 int o;
369 struct{
370 char id[4];
371 byte ver,pat;
372 word psz;
373 }d;
374 struct{byte t;char n[13];word r;}di;
376 if((r=F_findres(n))==-1) return;
377 fseek(h=wadh[wad[r].f],wad[r].o,SEEK_SET);
378 myfread(&d,1,sizeof(d),h);
379 if(memcmp(d.id,"DMM",4)!=0) return;
380 if(!(pat=malloc(d.psz<<2))) return;
381 myfread(pat,1,d.psz<<2,h);
382 myfread(&seqn,1,1,h);if(seqn) myfread(seq,1,seqn,h);
383 inum=0;myfread(&inum,1,1,h);
384 if(!(dmi=malloc(inum*4))) {free(pat);pat=NULL;return;}
385 if(!(patp=malloc((word)d.pat*32))) {free(pat);free(dmi);pat=NULL;return;}
386 for(i=0;i<inum;++i) {
387 dmi[i]=NULL;
388 myfread(&di,1,16,h);o=ftell(h);
389 for(r=0;r<12;++r) if(di.n[r]=='.') di.n[r]=0;
390 if((r=F_findres(di.n))==-1) continue;
391 if(!(dmi[i]=malloc(wad[r].l+8))) continue;
392 memset(dmi[i],0,16);
393 F_loadres(r,dmi[i],0,2);
394 F_loadres(r,(int*)dmi[i]+1,2,2);
395 F_loadres(r,(int*)dmi[i]+2,4,2);
396 F_loadres(r,(int*)dmi[i]+3,6,2);
397 F_loadres(r,(int*)dmi[i]+4,8,wad[r].l-8);
398 fseek(h,o,SEEK_SET);
399 }
400 for(i=r=0,j=(word)d.pat<<3;i<j;++i) {
401 patp[i]=r<<2;
402 while(pat[r++].v!=0x80);
403 }
404 }
405 */