Ejemplo n.º 1
0
//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;
}
Ejemplo n.º 2
0
FILE * cfile_find_libfile(char * name, int * length)
{
	FILE * fp;
	int i;

	if ( AltHogfile_initialized )	{
		for (i=0; i<AltNum_hogfiles; i++ )	{
			if ( !strcasecmp( 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( "DESCENT.HOG", HogFiles, &Num_hogfiles );
		Hogfile_initialized = 1;
	}

	for (i=0; i<Num_hogfiles; i++ )	{
		if ( !strcasecmp( HogFiles[i].name, name ))	{
			fp = cfile_get_filehandle( "DESCENT.HOG", "rb" );
			if ( fp == NULL ) return NULL;
			fseek( fp,  HogFiles[i].offset, SEEK_SET );
			*length = HogFiles[i].length;
			return fp;
		}
	}
	return NULL;
}
Ejemplo n.º 3
0
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;
	}
}
Ejemplo n.º 4
0
/*
 * return handle for file called "name", embedded in one of the hogfiles
 */
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;
		}
	}

	if (D1Hogfile_initialized)	{
		for (i = 0; i < D1Num_hogfiles; i++) {
			if (!stricmp(D1HogFiles[i].name, name)) {
				fp = cfile_get_filehandle(D1HogFilename, "rb");
				if (fp == NULL) return NULL;
				fseek(fp,  D1HogFiles[i].offset, SEEK_SET);
				*length = D1HogFiles[i].length;
				return fp;
			}
		}
	}

	return NULL;
}
Ejemplo n.º 5
0
int cfexist( char * filename )
{
	int length;
	FILE *fp;


	if (filename[0] != '\x01')
		fp = cfile_get_filehandle( filename, "rb" );		// Check for non-hog file first...
	else {
		fp = NULL;		//don't look in dir, only in hogfile
		filename++;
	}

	if ( fp )	{
		fclose(fp);
		return 1;
	}

	fp = cfile_find_libfile(filename, &length );
	if ( fp )	{
		fclose(fp);
		return 2;		// file found in hog
	}

	return 0;		// Couldn't find it.
}
Ejemplo n.º 6
0
Archivo: cfile.c Proyecto: paud/d2x-xl
FILE *CFFindHogFile (tHogFileList *hog, char *folder, char *name, int *length)
{
    FILE		*fp;
    int		i;
    hogfile	*phf;
    char		*hogFilename = hog->szName;

    if (!(hog->bInitialized && *hogFilename))
        return NULL;
    if (*folder) {
        char fn [FILENAME_LEN];

        sprintf (fn, "%s/%s", folder, hog->szName);
        hogFilename = fn;
    }

    for (i = hog->nFiles, phf = hog->files; i; i--, phf++) {
        if (stricmp (phf->name, name))
            continue;
        if (!(fp = cfile_get_filehandle (hogFilename, "", "rb")))
            break;
        fseek (fp, phf->offset, SEEK_SET);
        if (length)
            *length = phf->length;
        return fp;
    }
//LogErr ("CFFindHogFile(): '%s:%s' not found\n", hogFilename, name);
    return NULL;
}
Ejemplo n.º 7
0
Archivo: cfile.c Proyecto: paud/d2x-xl
// ----------------------------------------------------------------------------
//returns 1 if file loaded with no errors
int CFInitHogFile (char *fname, char *folder, hogfile *hog_files, int *nfiles)
{
    char	id[4];
    FILE	*fp;
    int	i, len;
    char	fn [FILENAME_LEN];
    char  *psz;

    if (*folder) {
        sprintf (fn, "%s/%s", folder, fname);
        fname = fn;
    }

    *nfiles = 0;
    fp = cfile_get_filehandle (fname, "", "rb");
    if (fp == NULL)
        return 0;

    if ((psz = strstr (fname, ".rdl")) || (psz = strstr (fname, ".rl2"))) {
        while ((psz >= fname) && (*psz != '\\') && (*psz != '/') && (*psz != ':'))
            psz--;
        *nfiles = 1;
        strncpy (hog_files [0].name, psz + 1, 13);
        hog_files [0].offset = 0;
        hog_files [0].length = -1;
        return 1;
    }

    fread (id, 3, 1, fp);
    if (strncmp (id, "DHF", 3)) {
        fclose(fp);
        return 0;
    }

    while (1)
    {
        if (*nfiles >= MAX_HOGFILES) {
            fclose(fp);
            Error ("HOGFILE is limited to %d files.\n",  MAX_HOGFILES);
        }
        i = (int) fread (hog_files[*nfiles].name, 13, 1, fp);
        if (i != 1) 	{		//eof here is ok
            fclose(fp);
            return 1;
        }
        i = (int) fread (&len, 4, 1, fp);
        if (i != 1) 	{
            fclose(fp);
            return 0;
        }
        hog_files[*nfiles].length = INTEL_INT(len);
        hog_files[*nfiles].offset = ftell (fp);
        *nfiles = (*nfiles) + 1;
        // Skip over
        i = fseek (fp, INTEL_INT(len), SEEK_CUR);
    }
}
Ejemplo n.º 8
0
Archivo: cfile.c Proyecto: paud/d2x-xl
CFILE * CFOpen (char *filename, char *folder, char *mode, int bUseD1Hog)
{
    int	length = -1;
    FILE	*fp;
    CFILE *cfile = NULL;
    char	*pszHogExt, *pszFileExt;

    if (! (filename && *filename))
        return NULL;
    if ((*filename != '\x01') /*&& !bUseD1Hog*/) {
        fp = cfile_get_filehandle (filename, folder, mode);		// Check for non-hog file first...
        if (!fp &&
                ((pszFileExt = strstr (filename, ".rdl")) || (pszFileExt = strstr (filename, ".rl2"))) &&
                (pszHogExt = strchr (gameHogFiles.szAltHogFile, '.')) &&
                !stricmp (pszFileExt, pszHogExt))
            fp = cfile_get_filehandle (gameHogFiles.szAltHogFile, folder, mode);		// Check for non-hog file first...
    }
    else {
        fp = NULL;		//don't look in dir, only in hogfile
        if (*filename == '\x01')
            filename++;
    }

    if (!fp) {
        if (fp = CFFindLibFile (filename, &length, bUseD1Hog))
            if (stricmp (mode, "rb")) {
                Error ("Cannot read hog file\n(wrong file io mode).\n");
                return NULL;
            }
    }
    if (fp) {
        if (!(cfile = d_malloc (sizeof (CFILE))))
            fclose (fp);
        else {
            cfile->file = fp;
            cfile->raw_position = 0;
            cfile->size = (length < 0) ? ffilelength (fp) : length;
            cfile->lib_offset = (length < 0) ? 0 : ftell (fp);
        }
    }
//if (!cfile) LogErr ("CFOpen(): error opening %s\n", filename);
    return cfile;
}
Ejemplo n.º 9
0
CFILE * cfopen(char * filename, char * mode ) 
{
	int length;
	FILE * fp;
	CFILE *cfile;
	
	if (strcasecmp(mode, "rb"))	{
		printf( "CFILES CAN ONLY BE OPENED WITH RB\n" );
		exit(1);
	}

	fp = cfile_get_filehandle( filename, mode );		// Check for non-hog file first...
	if ( !fp ) {
		fp = cfile_find_libfile(filename, &length );
		if ( !fp )
			return NULL;		// No file found
		cfile = (CFILE*)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 = (CFILE*)malloc ( sizeof(CFILE) );
		if ( cfile == NULL ) {
			fclose(fp);
			return NULL;
		}
		cfile->file = fp;
		
		fseek(fp, 0L, SEEK_END);
		cfile->size = ftell(fp);
		fseek(fp, 0L, SEEK_SET);
		
		cfile->lib_offset = 0;
		cfile->raw_position = 0;
		return cfile;
	}
}
Ejemplo n.º 10
0
int cfexist( char * filename )
{
	int length;
	FILE *fp;

	fp = cfile_get_filehandle( filename, "rb" );		// Check for non-hog file first...
	if ( fp )	{
		fclose(fp);
		return 1;
	}

	fp = cfile_find_libfile(filename, &length );
	if ( fp )	{
		fclose(fp);
		return 2;		// file found in hog
	}

	return 0;		// Couldn't find it.
}
Ejemplo n.º 11
0
void cfile_init_hogfile(char *fname, hogfile * hog_files, int * nfiles )
{
	char id[4];
	FILE * fp;
	int i, len;

	*nfiles = 0;

	fp = cfile_get_filehandle( fname, "rb" );
	if ( fp == NULL ) return;

	fread( id, 3, 1, fp );
	if ( strncmp( id, "DHF", 3 ) )	{
		fclose(fp);
		return;
	}

	while( 1 )	
	{	
		if ( *nfiles >= MAX_HOGFILES ) {
			printf( "ERROR: HOGFILE IS LIMITED TO %d FILES\n",  MAX_HOGFILES );
			fclose(fp);
			exit(1);
		}
		i = fread( hog_files[*nfiles].name, 13, 1, fp );
		if ( i != 1 )	{
			fclose(fp);
			return;
		}
		i = fread( &len, 4, 1, fp );
		if ( i != 1 )	{
			fclose(fp);
			return;
		}
		hog_files[*nfiles].length = len;
		hog_files[*nfiles].offset = ftell( fp );
		*nfiles = (*nfiles) + 1;
		// Skip over
		i = fseek( fp, len, SEEK_CUR );
	}
}
Ejemplo n.º 12
0
//returns 1 if file loaded with no errors
int cfile_init_hogfile(char *fname, hogfile * hog_files, int * nfiles )
{
	char id[4];
	FILE * fp;
	int i, len;

	*nfiles = 0;

	fp = cfile_get_filehandle( fname, "rb" );
	if ( fp == NULL ) return 0;

	fread( id, 3, 1, fp );
	if ( strncmp( id, "DHF", 3 ) )	{
		fclose(fp);
		return 0;
	}

	while( 1 )
	{
		if ( *nfiles >= MAX_HOGFILES ) {
			fclose(fp);
			Error( "HOGFILE is limited to %d files.\n",  MAX_HOGFILES );
		}
		i = fread( hog_files[*nfiles].name, 13, 1, fp );
		if ( i != 1 )	{		//eof here is ok
			fclose(fp);
			return 1;
		}
		i = fread( &len, 4, 1, fp );
		if ( i != 1 )	{
			fclose(fp);
			return 0;
		}
		hog_files[*nfiles].length = INTEL_INT(len);
		hog_files[*nfiles].offset = ftell( fp );
		*nfiles = (*nfiles) + 1;
		// Skip over
		i = fseek( fp, INTEL_INT(len), SEEK_CUR );
	}
}
Ejemplo n.º 13
0
Archivo: cfile.c Proyecto: paud/d2x-xl
int CFExist (char *filename, char *folder, int bUseD1Hog)
{
    int length;
    FILE *fp;

    if (filename[0] != '\x01')
        fp = cfile_get_filehandle (filename, folder, "rb");		// Check for non-hog file first...
    else {
        fp = NULL;		//don't look in dir, only in hogfile
        filename++;
    }
    if (fp) 	{
        fclose(fp);
        return 1;
    }
    fp = CFFindLibFile (filename, &length, bUseD1Hog);
    if (fp) 	{
        fclose(fp);
        return 2;		// file found in hog
    }
    return 0;		// Couldn't find it.
}