/* ============ Bspinfo ============ */ void Bspinfo( int count, char **fileNames ) { int i; char source[1024]; int size; FILE *f; if ( count < 1 ) { _printf( "No files to dump info for.\n"); return; } for ( i = 0 ; i < count ; i++ ) { _printf ("---------------------\n"); strcpy (source, fileNames[ i ] ); DefaultExtension (source, ".bsp"); f = fopen (source, "rb"); if (f) { size = Q_filelength (f); fclose (f); } else size = 0; _printf ("%s: %i\n", source, size); LoadBSPFile (source); PrintBSPFileSizes (); _printf ("---------------------\n"); } }
/* ** ASE_Load */ void ASE_Load( const char *filename, qboolean verbose, qboolean grabAnims ) { FILE *fp = fopen( filename, "rb" ); if ( !fp ) Error( "File not found '%s'", filename ); memset( &ase, 0, sizeof( ase ) ); ase.verbose = verbose; ase.grabAnims = grabAnims; ase.len = Q_filelength( fp ); ase.curpos = ase.buffer = malloc( ase.len ); printf( "Processing '%s'\n", filename ); if ( fread( ase.buffer, ase.len, 1, fp ) != 1 ) { fclose( fp ); Error( "fread() != -1 for '%s'", filename ); } fclose( fp ); ASE_Process(); }
/* ============== LoadFile ============== */ int LoadFile (const char *filename, void **bufferptr) { FILE *f; int length; void *buffer; *bufferptr = NULL; if ( filename == NULL || strlen(filename) == 0 ) { return -1; } f = fopen( filename, "rb" ); if ( !f ) { return -1; } length = Q_filelength( f ); buffer = Mem_ClearedAlloc( length+1, TAG_TOOLS ); ((char *)buffer)[length] = 0; if ( (int)fread( buffer, 1, length, f ) != length ) { Error( "File read failure" ); } fclose( f ); *bufferptr = buffer; return length; }
int BSPInfo( int count, char **fileNames ) { int i; char source[ 1024 ], ext[ 64 ]; int size; FILE *f; /* dummy check */ if( count < 1 ) { Sys_Printf( "No files to dump info for.\n"); return -1; } /* enable info mode */ infoMode = qtrue; /* walk file list */ for( i = 0; i < count; i++ ) { Sys_Printf( "---------------------------------\n" ); /* mangle filename and get size */ strcpy( source, fileNames[ i ] ); ExtractFileExtension( source, ext ); if( !Q_stricmp( ext, "map" ) ) StripExtension( source ); DefaultExtension( source, ".bsp" ); f = fopen( source, "rb" ); if( f ) { size = Q_filelength (f); fclose( f ); } else size = 0; /* load the bsp file and print lump sizes */ Sys_Printf( "%s\n", source ); LoadBSPFile( source ); PrintBSPFileSizes(); /* print sizes */ Sys_Printf( "\n" ); Sys_Printf( " total %9d\n", size ); Sys_Printf( " %9d KB\n", size / 1024 ); Sys_Printf( " %9d MB\n", size / (1024 * 1024) ); Sys_Printf( "---------------------------------\n" ); } /* return count */ return i; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int LoadQuakeFile(quakefile_t *qf, void **bufferptr) { FILE *fp; void *buffer; int length; unzFile zf; if(qf->zipfile) { //open the zip file zf = unzOpen(qf->pakfile); //set the file pointer qf->zipinfo.file = ((unz_s *) zf)->file; //open the Quake file in the zip file unzOpenCurrentFile(&qf->zipinfo); //allocate memory for the buffer length = qf->length; buffer = GetMemory(length + 1); //read the Quake file from the zip file length = unzReadCurrentFile(&qf->zipinfo, buffer, length); //close the Quake file in the zip file unzCloseCurrentFile(&qf->zipinfo); //close the zip file unzClose(zf); *bufferptr = buffer; return length; } //end if else { fp = SafeOpenRead(qf->filename); if(qf->offset) { fseek(fp, qf->offset, SEEK_SET); } length = qf->length; if(!length) { length = Q_filelength(fp); } buffer = GetMemory(length + 1); ((char *)buffer)[length] = 0; SafeRead(fp, buffer, length); fclose(fp); *bufferptr = buffer; return length; } //end else } //end of the function LoadQuakeFile
void SB_LoadFile (swappedbuffer_t *sbuf, char *filename) { FILE *f; f = SafeOpenRead (filename); sbuf->maxsize = Q_filelength (f); sbuf->start = qmalloc (sbuf->maxsize + 1); sbuf->start[sbuf->maxsize] = 0; SafeRead (f, sbuf->start, sbuf->maxsize); fclose (f); sbuf->index = sbuf->start; sbuf->initialized = true; }
/* ============== LoadFile ============== */ int LoadFile (const char *filename, void **bufferptr) { FILE *f; size_t length; void *buffer; f = SafeOpenRead (filename); length = (size_t) Q_filelength (f); buffer = malloc (length + 1); if (!buffer) COM_Error ("%s failed for %lu bytes.", __thisfunc__, (unsigned long)length); ((char *)buffer)[length] = 0; SafeRead(f, buffer, length); fclose (f); *bufferptr = buffer; return length; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int LoadQuakeFile(quakefile_t *qf, void **bufferptr) { FILE *fp; void *buffer; int length; unzFile zf; if (qf->zipfile) { //open the zip file zf = unzOpen(qf->pakfile); //set the file position in the zip file (also sets the current file info) unzSetOffset(zf, qf->pos); //open the Quake file in the zip file unzOpenCurrentFile(zf); //allocate memory for the buffer length = qf->length; buffer = GetMemory(length+1); //read the Quake file from the zip file length = unzReadCurrentFile(zf, buffer, length); //close the Quake file in the zip file unzCloseCurrentFile(zf); //close the zip file unzClose(zf); *bufferptr = buffer; return length; } //end if else { fp = SafeOpenRead(qf->filename); length = qf->length; if (!length) length = Q_filelength(fp); buffer = GetMemory(length+1); ((char *)buffer)[length] = 0; SafeRead(fp, buffer, length); fclose(fp); *bufferptr = buffer; return length; } //end else } //end of the function LoadQuakeFile
/* ============== LoadFile ============== */ int LoadFile (char *filename, void **bufferptr) { int length = 0; void *buffer; FileHandle_t f = SafeOpenRead (filename); if ( FILESYSTEM_INVALID_HANDLE != f ) { length = Q_filelength (f); buffer = malloc (length+1); ((char *)buffer)[length] = 0; SafeRead (f, buffer, length); g_pFileSystem->Close (f); *bufferptr = buffer; } else { *bufferptr = NULL; } return length; }
/* ============== LoadSoundtrack ============== */ void LoadSoundtrack( void ){ char name[1024]; FILE *f; int len; int i, val, j; soundtrack = NULL; sprintf( name, "%svideo/%s/%s.wav", gamedir, base, base ); printf( "%s\n", name ); f = fopen( name, "rb" ); if ( !f ) { printf( "no soundtrack for %s\n", base ); return; } len = Q_filelength( f ); soundtrack = malloc( len ); fread( soundtrack, 1, len, f ); fclose( f ); wavinfo = GetWavinfo( name, soundtrack, len ); // count samples for compression memset( samplecounts, 0, sizeof( samplecounts ) ); j = wavinfo.samples / 2; for ( i = 0 ; i < j ; i++ ) { val = ( (unsigned short *)( soundtrack + wavinfo.dataofs ) )[i]; samplecounts[val]++; } val = 0; for ( i = 0 ; i < 0x10000 ; i++ ) if ( samplecounts[i] ) { val++; } printf( "%i unique sample values\n", val ); }
/* ============ Q_CopyFile Used to archive source files ============ */ #define COPY_READ_BUFSIZE 8192 /* BUFSIZ */ int Q_CopyFile (const char *frompath, const char *topath) { char buf[COPY_READ_BUFSIZE]; FILE *in, *out; char temp[1024]; /* off_t remaining, count;*/ size_t remaining, count; strcpy (temp, topath); CreatePath (temp); in = fopen (frompath, "rb"); if (!in) COM_Error ("Unable to open file %s", frompath); out = fopen (topath, "wb"); if (!out) COM_Error ("Unable to create file %s", topath); remaining = Q_filelength (in); while (remaining) { if (remaining < sizeof(buf)) count = remaining; else count = sizeof(buf); if (fread(buf, 1, count, in) != count) break; if (fwrite(buf, 1, count, out) != count) break; remaining -= count; } fclose (in); fclose (out); return (remaining == 0)? 0 : 1; }
/* ============== MD3_Dump ============== */ void MD3_Dump( const char *filename ){ md3Header_t header; md3Tag_t *pTag; md3Surface_t *pSurface; FILE *fp; void *_buffer; void *buffer; long fileSize; int i; if ( ( fp = fopen( filename, "rb" ) ) == 0 ) { Error( "Unable to open '%s'\n", filename ); } fileSize = Q_filelength( fp ); _buffer = malloc( fileSize ); fread( _buffer, fileSize, 1, fp ); fclose( fp ); buffer = ( char * ) _buffer; header = *( md3Header_t * ) _buffer; if ( header.ident != MD3_IDENT ) { Error( "Incorrect ident for '%s'\n", filename ); } printf( "Contents of '%s'\n", filename ); printf( " version: %d\n", header.version ); printf( " name: %s\n", header.name ); printf( " num frames: %d\n", header.numFrames ); printf( " num tags: %d\n", header.numTags ); printf( " num surfaces: %d\n", header.numSurfaces ); printf( " num skins: %d\n", header.numSkins ); printf( " file size: %ld\n", fileSize ); printf( "--- TAGS ---\n" ); pTag = ( md3Tag_t * ) ( ( ( char * ) buffer ) + header.ofsTags ); for ( i = 0; i < header.numTags; i++, pTag++ ) { printf( " tag %d ('%s')\n", i, pTag->name ); printf( " origin: %f,%f,%f\n", pTag->origin[0], pTag->origin[1], pTag->origin[2] ); printf( " vf: %f,%f,%f\n", pTag->axis[0][0], pTag->axis[0][1], pTag->axis[0][2] ); printf( " vr: %f,%f,%f\n", pTag->axis[1][0], pTag->axis[1][1], pTag->axis[1][2] ); printf( " vu: %f,%f,%f\n", pTag->axis[2][0], pTag->axis[2][1], pTag->axis[2][2] ); } printf( "--- SURFACES ---\n" ); pSurface = ( md3Surface_t * ) ( ( ( char * ) buffer ) + header.ofsSurfaces ); for ( i = 0; i < header.numSurfaces; i++ ) { int j; md3Shader_t *pShader = ( md3Shader_t * ) ( ( ( char * ) pSurface ) + pSurface->ofsShaders ); printf( "\n surface %d ('%s')\n", i, pSurface->name ); printf( " num frames: %d\n", pSurface->numFrames ); printf( " num shaders: %d\n", pSurface->numShaders ); printf( " num tris: %d\n", pSurface->numTriangles ); printf( " num verts: %d\n", pSurface->numVerts ); if ( pSurface->numShaders > 0 ) { printf( " --- SHADERS ---\n" ); for ( j = 0; j < pSurface->numShaders; j++, pShader++ ) { printf( " shader %d ('%s')\n", j, pShader->name ); } } pSurface = ( md3Surface_t * ) ( ( ( char * ) pSurface ) + pSurface->ofsEnd ); } free( _buffer ); }