/* ==================== W_LoadTextureWadFile ==================== */ void W_LoadTextureWadFile (char *filename, int complain) { wadinfo_t header; int infotableofs; qfile_t *file; int numlumps; mwad_t *w; file = FS_OpenVirtualFile(filename, false); if (!file) { if (complain) Con_Printf("W_LoadTextureWadFile: couldn't find %s\n", filename); return; } if (FS_Read(file, &header, sizeof(wadinfo_t)) != sizeof(wadinfo_t)) {Con_Print("W_LoadTextureWadFile: unable to read wad header\n");FS_Close(file);file = NULL;return;} if(memcmp(header.identification, "WAD3", 4)) {Con_Printf("W_LoadTextureWadFile: Wad file %s doesn't have WAD3 id\n",filename);FS_Close(file);file = NULL;return;} numlumps = LittleLong(header.numlumps); if (numlumps < 1 || numlumps > 65536) {Con_Printf("W_LoadTextureWadFile: invalid number of lumps (%i)\n", numlumps);FS_Close(file);file = NULL;return;} infotableofs = LittleLong(header.infotableofs); if (FS_Seek (file, infotableofs, SEEK_SET)) {Con_Print("W_LoadTextureWadFile: unable to seek to lump table\n");FS_Close(file);file = NULL;return;} if (!wad.hlwads.mempool) Mem_ExpandableArray_NewArray(&wad.hlwads, cls.permanentmempool, sizeof(mwad_t), 16); w = (mwad_t *) Mem_ExpandableArray_AllocRecord(&wad.hlwads); w->file = file; w->numlumps = numlumps; w->lumps = (lumpinfo_t *) Mem_Alloc(cls.permanentmempool, w->numlumps * sizeof(lumpinfo_t)); if (!w->lumps) { Con_Print("W_LoadTextureWadFile: unable to allocate temporary memory for lump table\n"); FS_Close(w->file); w->file = NULL; w->numlumps = 0; return; } if (FS_Read(file, w->lumps, sizeof(lumpinfo_t) * w->numlumps) != (fs_offset_t)sizeof(lumpinfo_t) * numlumps) { Con_Print("W_LoadTextureWadFile: unable to read lump table\n"); FS_Close(w->file); w->file = NULL; w->numlumps = 0; Mem_Free(w->lumps); w->lumps = NULL; return; } W_SwapLumps(w->numlumps, w->lumps); // leaves the file open }
/* ==================== CL_PlayDemo_f play [demoname] ==================== */ void CL_PlayDemo_f (void) { char name[MAX_QPATH]; int c; qboolean neg = false; qfile_t *f; if (Cmd_Argc() != 2) { Con_Print("play <demoname> : plays a demo\n"); return; } // open the demo file strlcpy (name, Cmd_Argv(1), sizeof (name)); FS_DefaultExtension (name, ".dem", sizeof (name)); f = FS_OpenVirtualFile(name, false); if (!f) { Con_Printf("ERROR: couldn't open %s.\n", name); cls.demonum = -1; // stop demo loop return; } cls.demostarting = true; // disconnect from server CL_Disconnect (); Host_ShutdownServer (); // update networking ports (this is mainly just needed at startup) NetConn_UpdateSockets(); cls.protocol = PROTOCOL_QUAKE; Con_Printf("Playing demo %s.\n", name); cls.demofile = f; strlcpy(cls.demoname, name, sizeof(cls.demoname)); cls.demoplayback = true; demoplayback = true; cls.state = ca_connected; cls.forcetrack = 0; while ((c = FS_Getc (cls.demofile)) != '\n') if (c == '-') neg = true; else cls.forcetrack = cls.forcetrack * 10 + (c - '0'); if (neg) cls.forcetrack = -cls.forcetrack; cls.demostarting = false; }
static hz_bitstream_read_t *hz_bitstream_read_open(char *filename) { qfile_t *file; hz_bitstream_read_t *stream; if ((file = FS_OpenVirtualFile(filename, false))) { stream = (hz_bitstream_read_t *)Z_Malloc(sizeof(hz_bitstream_read_t)); memset(stream, 0, sizeof(*stream)); stream->file = file; return stream; } else return NULL; }