//Specify the name of the hogfile. Returns 1 if hogfile found & had files int cfile_init(char *hogname) { #ifdef MACINTOSH char mac_path[255]; macify_dospath(hogname, mac_path); #endif Assert(Hogfile_initialized == 0); #ifndef MACINTOSH if (cfile_init_hogfile(hogname, HogFiles, &Num_hogfiles )) { strcpy( HogFilename, hogname ); #else if (cfile_init_hogfile(mac_path, HogFiles, &Num_hogfiles )) { strcpy( HogFilename, mac_path ); #endif Hogfile_initialized = 1; return 1; } else return 0; //not loaded! } FILE * cfile_find_libfile(char * name, int * length) { FILE * fp; int i; if ( AltHogfile_initialized ) { for (i=0; i<AltNum_hogfiles; i++ ) { if ( !stricmp( AltHogFiles[i].name, name )) { fp = cfile_get_filehandle( AltHogFilename, "rb" ); if ( fp == NULL ) return NULL; fseek( fp, AltHogFiles[i].offset, SEEK_SET ); *length = AltHogFiles[i].length; return fp; } } } if ( !Hogfile_initialized ) { //@@cfile_init_hogfile( "DESCENT2.HOG", HogFiles, &Num_hogfiles ); //@@Hogfile_initialized = 1; //Int3(); //hogfile ought to be initialized } for (i=0; i<Num_hogfiles; i++ ) { if ( !stricmp( HogFiles[i].name, name )) { fp = cfile_get_filehandle( HogFilename, "rb" ); if ( fp == NULL ) return NULL; fseek( fp, HogFiles[i].offset, SEEK_SET ); *length = HogFiles[i].length; return fp; } } return NULL; }
CFILE * cfopen(char * filename, char * mode ) { int length; FILE * fp; CFILE *cfile; if (stricmp( mode, "rb")) { Error( "cfiles can only be opened with mode==rb\n" ); } if (filename[0] != '\x01') { #ifdef MACINTOSH char mac_path[255]; macify_dospath(filename, mac_path); fp = cfile_get_filehandle( mac_path, mode); #else fp = cfile_get_filehandle( filename, mode ); // Check for non-hog file first... #endif } else { fp = NULL; //don't look in dir, only in hogfile filename++; } if ( !fp ) { fp = cfile_find_libfile(filename, &length ); if ( !fp ) return NULL; // No file found cfile = d_malloc ( sizeof(CFILE) ); if ( cfile == NULL ) { fclose(fp); return NULL; } cfile->file = fp; cfile->size = length; cfile->lib_offset = ftell( fp ); cfile->raw_position = 0; return cfile; } else { cfile = d_malloc ( sizeof(CFILE) ); if ( cfile == NULL ) { fclose(fp); return NULL; } cfile->file = fp; cfile->size = filelength( fileno(fp) ); cfile->lib_offset = 0; cfile->raw_position = 0; return cfile; } }
int cfile_use_descent1_hogfile( char * name ) { if (name) { #ifdef MACINTOSH char mac_path[255]; macify_dospath(name, mac_path); strcpy(D1HogFilename, mac_path); #else strcpy(D1HogFilename, name); #endif cfile_init_hogfile(D1HogFilename, D1HogFiles, &D1Num_hogfiles); D1Hogfile_initialized = 1; return (D1Num_hogfiles > 0); } else { D1Hogfile_initialized = 0; return 1; } }
int cfile_use_alternate_hogfile( char * name ) { if ( name ) { #ifdef MACINTOSH char mac_path[255]; macify_dospath(name, mac_path); strcpy( AltHogFilename, mac_path); #else strcpy( AltHogFilename, name ); #endif cfile_init_hogfile( AltHogFilename, AltHogFiles, &AltNum_hogfiles ); AltHogfile_initialized = 1; return (AltNum_hogfiles > 0); } else { AltHogfile_initialized = 0; return 1; } }
//Specify the name of the hogfile. Returns 1 if hogfile found & had files int cfile_init(char *hogname) { #ifdef MACINTOSH char mac_path[255]; macify_dospath(hogname, mac_path); #endif Assert(Hogfile_initialized == 0); #ifndef MACINTOSH if (cfile_init_hogfile(hogname, HogFiles, &Num_hogfiles )) { strcpy( HogFilename, hogname ); #else if (cfile_init_hogfile(mac_path, HogFiles, &Num_hogfiles )) { strcpy( HogFilename, mac_path ); #endif Hogfile_initialized = 1; return 1; } else return 0; //not loaded! } int cfile_size(char *hogname) { CFILE *fp; struct stat statbuf; fp = cfopen(hogname, "rb"); if (fp == NULL) return -1; fstat(fileno(fp->file), &statbuf); cfclose(fp); return statbuf.st_size; }