当前位置: 首页>>代码示例>>C++>>正文


C++ FS_Seek函数代码示例

本文整理汇总了C++中FS_Seek函数的典型用法代码示例。如果您正苦于以下问题:C++ FS_Seek函数的具体用法?C++ FS_Seek怎么用?C++ FS_Seek使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FS_Seek函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FS_FOpenFile

/*
* CM_LoadMapMessage
*/
char *CM_LoadMapMessage( char *name, char *message, int size )
{
	int file, len;
	qbyte h_v[8];
	char *data, *entitystring;
	lump_t l;
	qboolean isworld;
	char key[MAX_KEY], value[MAX_VALUE], *token;
	const modelFormatDescr_t *descr;
	const bspFormatDesc_t *bspFormat = NULL;

	*message = '\0';

	len = FS_FOpenFile( name, &file, FS_READ );
	if( !file || len < 1 )
	{
		if( file )
			FS_FCloseFile( file );
		return message;
	}

	FS_Read( h_v, 4 + sizeof( int ), file );
	descr = Com_FindFormatDescriptor( cm_supportedformats, h_v, &bspFormat );
	if( !descr )
	{
		Com_Printf( "CM_LoadMapMessage: %s: unknown bsp format\n", name );
		FS_FCloseFile( file );
		return message;
	}

	FS_Seek( file, descr->headerLen + sizeof( int ) + sizeof( lump_t ) * bspFormat->entityLumpNum, FS_SEEK_SET );

	FS_Read( &l.fileofs, sizeof( l.fileofs ), file );
	l.fileofs = LittleLong( l.fileofs );

	FS_Read( &l.filelen, sizeof( l.filelen ), file );
	l.filelen = LittleLong( l.filelen );

	if( !l.filelen )
	{
		FS_FCloseFile( file );
		return message;
	}

	FS_Seek( file, l.fileofs, FS_SEEK_SET );

	entitystring = Mem_TempMalloc( l.filelen );
	FS_Read( entitystring, l.filelen, file );

	FS_FCloseFile( file );

	for( data = entitystring; ( token = COM_Parse( &data ) ) && token[0] == '{'; )
	{
		isworld = qtrue;

		while( 1 )
		{
			token = COM_Parse( &data );
			if( !token[0] || token[0] == '}' )
				break; // end of entity

			Q_strncpyz( key, token, sizeof( key ) );
			while( key[strlen( key )-1] == ' ' )  // remove trailing spaces
				key[strlen( key )-1] = 0;

			token = COM_Parse( &data );
			if( !token[0] )
				break; // error

			Q_strncpyz( value, token, sizeof( value ) );

			// now that we have the key pair worked out...
			if( !strcmp( key, "classname" ) )
			{
				if( strcmp( value, "worldspawn" ) )
					isworld = qfalse;
			}
			else if( !strcmp( key, "message" ) )
			{
				Q_strncpyz( message, token, size );
				break;
			}
		}

		if( isworld )
			break;
	}

	Mem_Free( entitystring );

	return message;
}
开发者ID:Kaperstone,项目名称:warsow,代码行数:95,代码来源:cm_main.c

示例2: GPSLocateNvramLoadDefault

static kal_bool GPSLocateNvramLoadDefault(FS_HANDLE file_handle, kal_bool newCreate)
{
	int result;
	unsigned int len;
	GPSLocateNvramDataStruct_t tmpCache;
	char default_passwd[GPSLOCATE_PRESAVED_PASSWORD_BUFFER_LEN];
	int i;
	unsigned char* pBuff;

	if (newCreate == KAL_TRUE)
	{
		memset(&tmpCache, 0x00, sizeof(GPSLocateNvramDataStruct_t));
	}
	else
	{
		//read from the original file
		FS_Seek(file_handle, 0, FS_FILE_BEGIN);
		result = FS_Read(file_handle, &tmpCache, sizeof(GPSLocateNvramDataStruct_t), &len);
		if (result != FS_NO_ERROR || len != sizeof(GPSLocateNvramDataStruct_t))
		{
			//read fail
			return KAL_FALSE;
		}
	}

	//set version number
	tmpCache.Buff[0] = GPSLOCATE_NVRAM_VER_NO;
	//set default passord to all zero(ascii '0')
	for (i = 0; i < GPSLOCATE_PRESAVED_PASSWORD_BUFFER_LEN-1; i++)
	{
		default_passwd[i] = GPSLOCATE_NVRAMDATA_DEFAULT_PWD_CHAR;
	}
	default_passwd[GPSLOCATE_PRESAVED_PASSWORD_BUFFER_LEN-1] = 0x00;
	//find service password space in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_SERVICEPASSWORD);
	//set service password
	memcpy(pBuff, default_passwd, GPSLOCATE_PRESAVED_PASSWORD_BUFFER_LEN);
	//find user password space in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_USERPASSWORD);
	//set user password one by one
	for (i = 0; i < GPSLOCATE_USER_PASSWORD_MAX; i++)
	{
		memcpy(pBuff, default_passwd, GPSLOCATE_PRESAVED_PASSWORD_BUFFER_LEN);
		pBuff += GPSLOCATE_PRESAVED_PASSWORD_BUFFER_LEN;
	}
	//find service number space in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_SERVICENUMBER);
	//set service number to null
	memset(pBuff, 0, GPSLOCATE_PRESAVED_NUMBER_BUFFER_LEN);
	//find user number space in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_USERNUMBER);
	//set user number to null one by one
	for (i = 0; i < GPSLOCATE_USER_NUMBER_MAX; i++)
	{
		memset(pBuff, 0, GPSLOCATE_PRESAVED_NUMBER_BUFFER_LEN);
		pBuff += GPSLOCATE_PRESAVED_NUMBER_BUFFER_LEN;
	}
	//find timing number space in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_TIMINGNUMBER);
	//set timing number to null
	memset(pBuff, 0, GPSLOCATE_PRESAVED_NUMBER_BUFFER_LEN);

	tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_BSNUMBER)] = 1;
	tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_SETTINGS)] = GPSLOCATE_NVRAMDATA_DEFAULT_TMSETTING;
	tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_GPSONSETTING)] = 0;
	tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_HFREEONSETTING)] = 0;
	tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_GPRSUPLOADSETTING)] = 0;
	tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_DEFENCEONSETTING)] = 0;
	tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_MTCALLPROFILE)] = 0;
	tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_SOSPHONECALL)] = 1;

	//find gprs user space in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_GPRSUSER);
	//set service number to "PS"
	strcpy((char *)pBuff, "V300Q");
	//find gprs password space in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_GPRSPASSWORD);
	//set gprs password
	memcpy(pBuff, default_passwd, GPSLOCATE_PRESAVED_PASSWORD_BUFFER_LEN);
	//find server address space in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_SERVERADDR);
	//set server address to zero
	memset(pBuff, 0, sizeof(GPSLocateServerAddr_t));
	tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_POSMONITORONFF)] = 0;

	//find fixed position in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_FIXEDPOSITION);
	//set fixed position to zero
	memset(pBuff, 0, sizeof(GPS_PostionRange_t));

	if (newCreate == KAL_TRUE)
	{
		//load default value for the follwoing item only when new creating
		tmpCache.Buff[GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_BEARERMODE)] = GPSLOCATE_NVRAMDATA_DEFAULT_BEARERMODE;
	}

	//find gprs apn in the data structure
	pBuff = tmpCache.Buff + GPSLocateNvramGetRecOffset(GPS_NVRAM_RECID_GPRSAPN);
	strcpy((char *)pBuff, "CMNET");
	//find gprs apn user in the data structure
//.........这里部分代码省略.........
开发者ID:robbie-cao,项目名称:tracker,代码行数:101,代码来源:gps_app_nvram_mgr.c

示例3: CL_CgameSystemCalls

/*
====================
CL_CgameSystemCalls

The cgame module is making a system call
====================
*/
intptr_t CL_CgameSystemCalls( intptr_t *args ) {
	switch( args[0] ) {
	case CG_PRINT:
		Com_Printf( "%s", (const char*)VMA(1) );
		return 0;
	case CG_ERROR:
		Com_Error( ERR_DROP, "%s", (const char*)VMA(1) );
		return 0;
	case CG_MILLISECONDS:
		return Sys_Milliseconds();
	case CG_CVAR_REGISTER:
		Cvar_Register( VMA(1), VMA(2), VMA(3), args[4] );
		return 0;
	case CG_CVAR_UPDATE:
		Cvar_Update( VMA(1) );
		return 0;
	case CG_CVAR_SET:
		Cvar_Set( VMA(1), VMA(2) );
		return 0;
	case CG_CVAR_VARIABLESTRINGBUFFER:
		Cvar_VariableStringBuffer( VMA(1), VMA(2), args[3] );
		return 0;
	case CG_ARGC:
		return Cmd_Argc();
	case CG_ARGV:
		Cmd_ArgvBuffer( args[1], VMA(2), args[3] );
		return 0;
	case CG_ARGS:
		Cmd_ArgsBuffer( VMA(1), args[2] );
		return 0;
	case CG_FS_FOPENFILE:
		return FS_FOpenFileByMode( VMA(1), VMA(2), args[3] );
	case CG_FS_READ:
		FS_Read2( VMA(1), args[2], args[3] );
		return 0;
	case CG_FS_WRITE:
		FS_Write( VMA(1), args[2], args[3] );
		return 0;
	case CG_FS_FCLOSEFILE:
		FS_FCloseFile( args[1] );
		return 0;
	case CG_FS_SEEK:
		return FS_Seek( args[1], args[2], args[3] );
	case CG_SENDCONSOLECOMMAND:
		Cbuf_AddText( VMA(1) );
		return 0;
	case CG_ADDCOMMAND:
		CL_AddCgameCommand( VMA(1) );
		return 0;
	case CG_REMOVECOMMAND:
		Cmd_RemoveCommand( VMA(1) );
		return 0;
	case CG_SENDCLIENTCOMMAND:
		CL_AddReliableCommand( VMA(1) );
		return 0;
	case CG_UPDATESCREEN:
		// this is used during lengthy level loading, so pump message loop
//		Com_EventLoop();	// FIXME: if a server restarts here, BAD THINGS HAPPEN!
// We can't call Com_EventLoop here, a restart will crash and this _does_ happen
// if there is a map change while we are downloading at pk3.
// ZOID
		SCR_UpdateScreen();
		return 0;
	case CG_CM_LOADMAP:
		CL_CM_LoadMap( VMA(1) );
		return 0;
	case CG_CM_NUMINLINEMODELS:
		return CM_NumInlineModels();
	case CG_CM_INLINEMODEL:
		return CM_InlineModel( args[1] );
	case CG_CM_TEMPBOXMODEL:
		return CM_TempBoxModel( VMA(1), VMA(2), /*int capsule*/ qfalse );
	case CG_CM_TEMPCAPSULEMODEL:
		return CM_TempBoxModel( VMA(1), VMA(2), /*int capsule*/ qtrue );
	case CG_CM_POINTCONTENTS:
		return CM_PointContents( VMA(1), args[2] );
	case CG_CM_TRANSFORMEDPOINTCONTENTS:
		return CM_TransformedPointContents( VMA(1), args[2], VMA(3), VMA(4) );
	case CG_CM_BOXTRACE:
		CM_BoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qfalse );
		return 0;
	case CG_CM_CAPSULETRACE:
		CM_BoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qtrue );
		return 0;
	case CG_CM_TRANSFORMEDBOXTRACE:
		CM_TransformedBoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qfalse );
		return 0;
	case CG_CM_TRANSFORMEDCAPSULETRACE:
		CM_TransformedBoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qtrue );
		return 0;
	case CG_CM_MARKFRAGMENTS:
		return re.MarkFragments( args[1], VMA(2), VMA(3), args[4], VMA(5), args[6], VMA(7) );
	case CG_S_STARTSOUND:
//.........这里部分代码省略.........
开发者ID:PropheteMath,项目名称:OpenArenaBB,代码行数:101,代码来源:cl_cgame.c

示例4: CL_DemoReadMessage

/*
=================
CL_DemoReadMessage

reads demo data and write it to client
=================
*/
qboolean CL_DemoReadMessage( byte *buffer, size_t *length )
{
	float	f = 0.0f;
	int	curpos = 0;
	float	fElapsedTime = 0.0f;
	qboolean	swallowmessages = true;
	byte	*userbuf = NULL;
	size_t	size;
	byte	cmd;

	if( !cls.demofile )
	{
		MsgDev( D_ERROR, "tried to read a demo message with no demo file\n" );
		CL_DemoCompleted();
		return false;
	}

	// HACKHACK: changedemo issues
	if( !cls.netchan.remote_address.type )
		cls.netchan.remote_address.type = NA_LOOPBACK;

	if(( !cl.background && ( cl.refdef.paused || cls.key_dest != key_game )) || cls.key_dest == key_console )
	{
		demo.starttime += host.frametime;
		return false; // paused
	}

	do
	{
		qboolean	bSkipMessage = false;

		if( !cls.demofile ) break;
		curpos = FS_Tell( cls.demofile );

		CL_ReadDemoCmdHeader( &cmd, &f );

		fElapsedTime = CL_GetDemoPlaybackClock() - demo.starttime;
		bSkipMessage = (f >= fElapsedTime) ? true : false;

		if( cls.changelevel )
			demo.framecount = 1;

		// HACKHACK: changelevel issues
		if( demo.framecount <= 10 && ( fElapsedTime - f ) > host.frametime )
			demo.starttime = CL_GetDemoPlaybackClock();

		// not ready for a message yet, put it back on the file.
		if( cmd != dem_norewind && cmd != dem_stop && bSkipMessage )
		{
			// never skip first message
			if( demo.framecount != 0 )
			{
				FS_Seek( cls.demofile, curpos, SEEK_SET );
				return false; // not time yet.
			}
		}

		// COMMAND HANDLERS
		switch( cmd )
		{
		case dem_jumptime:
			demo.starttime = CL_GetDemoPlaybackClock();
			break;
		case dem_stop:
			CL_DemoMoveToNextSection();
			break;
		case dem_userdata:
			FS_Read( cls.demofile, &size, sizeof( int ));
			userbuf = Mem_Alloc( cls.mempool, size );
			FS_Read( cls.demofile, userbuf, size );

			if( clgame.hInstance )
				clgame.dllFuncs.pfnDemo_ReadBuffer( size, userbuf );
			Mem_Free( userbuf );
			userbuf = NULL;
			break;
		case dem_usercmd:
			CL_ReadDemoUserCmd( false );
			break;
		default:
			swallowmessages = false;
			break;
		}
	} while( swallowmessages );

	if( !cls.demofile )
		return false;

	// if not on "LOADING" section, check a few things
	if( demo.entryIndex )
	{
		// We are now on the second frame of a new section,
		// if so, reset start time (unless in a timedemo)
//.........这里部分代码省略.........
开发者ID:nekonomicon,项目名称:xash3d,代码行数:101,代码来源:cl_demo.c

示例5: _GeoIP_seek_record

unsigned int _GeoIP_seek_record ( unsigned long ipnum ) {

	fileHandle_t file;

	int depth;
	unsigned int x;
	unsigned char stack_buffer[2 * MAX_RECORD_LENGTH];
	const unsigned char *buf = stack_buffer;
	unsigned int offset = 0;

	const unsigned char * p;
	int j;

	FS_SV_FOpenFileRead("GeoIP.dat", &file);

	if(!file){
		Com_Printf("File Read error.\n");
		return 0;
	}

/*
	unsigned char *data; = malloc(1024*1024*2);
	if(!FS_Seek(file, 0, SEEK_SET)){
		FS_Read(data , 1024*1024*2, file);
	}
*/
	unsigned int foffset;


	for (depth = 31; depth >= 0; depth--) {
		/* read from disk */
		foffset = (long)RECORD_LENGTH * 2 *offset;

		if(!FS_Seek(file, foffset, FS_SEEK_SET)){
			FS_Read(stack_buffer , RECORD_LENGTH * 2, file);
		}
		/* simply point to record in memory */
//		buf = data + (long)RECORD_LENGTH * 2 *offset;
		if (ipnum & (1 << depth)) {
			/* Take the right-hand branch */
			if ( RECORD_LENGTH == 3 ) {
				/* Most common case is completely unrolled and uses constants. */
				x =   (buf[3*1 + 0] << (0*8))  + (buf[3*1 + 1] << (1*8))  + (buf[3*1 + 2] << (2*8));

			} else {
				/* General case */
				j = RECORD_LENGTH;
				p = &buf[2*j];
				x = 0;
				do {
					x <<= 8;
					x += *(--p);
				} while ( --j );
			}

		} else {
			/* Take the left-hand branch */
			if ( RECORD_LENGTH == 3 ) {
				/* Most common case is completely unrolled and uses constants. */
				x =   (buf[3*0 + 0] << (0*8))  + (buf[3*0 + 1] << (1*8))  + (buf[3*0 + 2] << (2*8));
			} else {
				/* General case */
				j = RECORD_LENGTH;
				p = &buf[1*j];
				x = 0;
				do {
					x <<= 8;
					x += *(--p);
				} while ( --j );
			}
		}

		if (x >= BEGIN_OFFSET) {
			//gi->netmask = gl->netmask = 32 - depth;
			FS_FCloseFile(file);
			return x - BEGIN_OFFSET;
		}
		offset = x;
	}
	/* shouldn't reach here */
	Com_PrintError("Traversing Database for ipnum = %lu - Perhaps database is corrupt?\n",ipnum);
	FS_FCloseFile(file);
	return 0;
}
开发者ID:BraXi,项目名称:CoD4X18-Server,代码行数:84,代码来源:maxmind_geoip.c

示例6: CL_PlayDemo_f

/*
====================
CL_PlayDemo_f

playdemo <demoname>
====================
*/
void CL_PlayDemo_f( void )
{
	string	filename;
	string	demoname;
	int	i;

	if( Cmd_Argc() != 2 )
	{
		Msg( "Usage: playdemo <demoname>\n" );
		return;
	}

	if( cls.demoplayback )
	{
		CL_StopPlayback();
	}

	if( cls.demorecording )
	{
		Msg( "Can't playback during demo record.\n");
		return;
	}

	Q_strncpy( demoname, Cmd_Argv( 1 ), sizeof( demoname ) - 1 );
	Q_snprintf( filename, sizeof( filename ), "demos/%s.dem", demoname );

	if( !FS_FileExists( filename, true ))
	{
		MsgDev( D_ERROR, "couldn't open %s\n", filename );
		cls.demonum = -1; // stop demo loop
		return;
	}

	cls.demofile = FS_Open( filename, "rb", true );
	Q_strncpy( cls.demoname, demoname, sizeof( cls.demoname ));
	Q_strncpy( menu.globals->demoname, demoname, sizeof( menu.globals->demoname ));

	// read in the m_DemoHeader
	FS_Read( cls.demofile, &demo.header, sizeof( demoheader_t ));

	if( demo.header.id != IDEMOHEADER )
	{
		MsgDev( D_ERROR, "%s is not a demo file\n", filename );
		FS_Close( cls.demofile );
		cls.demofile = NULL;
		cls.demonum = -1; // stop demo loop
		return;
	}

	if( demo.header.net_protocol != PROTOCOL_VERSION || demo.header.dem_protocol != DEMO_PROTOCOL )
	{
		MsgDev( D_ERROR, "demo protocol outdated\n"
			"Demo file protocols Network(%i), Demo(%i)\n"
			"Server protocol is at Network(%i), Demo(%i)\n",
			demo.header.net_protocol, 
			demo.header.dem_protocol,
			PROTOCOL_VERSION,
			DEMO_PROTOCOL
		);

		FS_Close( cls.demofile );
		cls.demofile = NULL;
		cls.demonum = -1; // stop demo loop
		return;
	}

	// now read in the directory structure.
	FS_Seek( cls.demofile, demo.header.directory_offset, SEEK_SET );
	FS_Read( cls.demofile, &demo.directory.numentries, sizeof( int ));

	if( demo.directory.numentries < 1 || demo.directory.numentries > 1024 )
	{
		MsgDev( D_ERROR, "demo had bogus # of directory entries: %i\n", demo.directory.numentries );
		FS_Close( cls.demofile );
		cls.demofile = NULL;
		cls.demonum = -1; // stop demo loop
		cls.changedemo = false;
		return;
	}

	if( cls.changedemo )
	{
		S_StopAllSounds();
		SCR_BeginLoadingPlaque( false );

		CL_ClearState ();
		CL_InitEdicts (); // re-arrange edicts
	}
	else
	{
		// NOTE: at this point demo is still valid
		CL_Disconnect();
		Host_ShutdownServer();
//.........这里部分代码省略.........
开发者ID:nekonomicon,项目名称:xash3d,代码行数:101,代码来源:cl_demo.c

示例7: CL_UISystemCalls

/*
====================
CL_UISystemCalls

The ui module is making a system call
====================
*/
int CL_UISystemCalls( int *args ) {
	switch( args[0] ) {
	case UI_ERROR:
		Com_Error( ERR_DROP, "%s", VMA(1) );
		return 0;

	case UI_PRINT:
		Com_Printf( "%s", VMA(1) );
		return 0;

	case UI_MILLISECONDS:
		return Sys_Milliseconds();

	case UI_CVAR_REGISTER:
		Cvar_Register( VMA(1), VMA(2), VMA(3), args[4] ); 
		return 0;

	case UI_CVAR_UPDATE:
		Cvar_Update( VMA(1) );
		return 0;

	case UI_CVAR_SET:
		Cvar_Set( VMA(1), VMA(2) );
		return 0;

	case UI_CVAR_VARIABLEVALUE:
		return FloatAsInt( Cvar_VariableValue( VMA(1) ) );

	case UI_CVAR_VARIABLESTRINGBUFFER:
		Cvar_VariableStringBuffer( VMA(1), VMA(2), args[3] );
		return 0;

	case UI_CVAR_SETVALUE:
		Cvar_SetValue( VMA(1), VMF(2) );
		return 0;

	case UI_CVAR_RESET:
		Cvar_Reset( VMA(1) );
		return 0;

	case UI_CVAR_CREATE:
		Cvar_Get( VMA(1), VMA(2), args[3] );
		return 0;

	case UI_CVAR_INFOSTRINGBUFFER:
		Cvar_InfoStringBuffer( args[1], VMA(2), args[3] );
		return 0;

	case UI_ARGC:
		return Cmd_Argc();

	case UI_ARGV:
		Cmd_ArgvBuffer( args[1], VMA(2), args[3] );
		return 0;

	case UI_CMD_EXECUTETEXT:
		Cbuf_ExecuteText( args[1], VMA(2) );
		return 0;

	case UI_FS_FOPENFILE:
		return FS_FOpenFileByMode( VMA(1), VMA(2), args[3] );

	case UI_FS_READ:
		FS_Read2( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_WRITE:
		FS_Write( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_FCLOSEFILE:
		FS_FCloseFile( args[1] );
		return 0;

	case UI_FS_GETFILELIST:
		return FS_GetFileList( VMA(1), VMA(2), VMA(3), args[4] );

	case UI_FS_SEEK:
		return FS_Seek( args[1], args[2], args[3] );
	
	case UI_R_REGISTERMODEL:
		return re.RegisterModel( VMA(1) );

	case UI_R_REGISTERSKIN:
		return re.RegisterSkin( VMA(1) );

	case UI_R_REGISTERSHADERNOMIP:
		return re.RegisterShaderNoMip( VMA(1) );

	case UI_R_CLEARSCENE:
		re.ClearScene();
		return 0;

//.........这里部分代码省略.........
开发者ID:DaveHogan,项目名称:FQuake3,代码行数:101,代码来源:cl_ui.c

示例8: CL_CgameSystemCalls


//.........这里部分代码省略.........
			return 0;

		case CG_R_ADDREFENTITYTOSCENE:
			re.AddRefEntityToScene( VMA( 1 ) );
			return 0;

#if defined( USE_REFLIGHT )
		case CG_R_ADDREFLIGHTSTOSCENE:
			re.AddRefLightToScene( VMA( 1 ) );
			return 0;
#endif

		case CG_R_ADDPOLYTOSCENE:
			re.AddPolyToScene( args[ 1 ], args[ 2 ], VMA( 3 ) );
			return 0;

		case CG_R_ADDPOLYSTOSCENE:
			re.AddPolysToScene( args[ 1 ], args[ 2 ], VMA( 3 ), args[ 4 ] );
			return 0;

		case CG_R_ADDPOLYBUFFERTOSCENE:
			re.AddPolyBufferToScene( VMA( 1 ) );
			return 0;

		case CG_R_ADDLIGHTTOSCENE:
			re.AddLightToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ), args[ 7 ], args[ 8 ] );
			return 0;

		case CG_R_ADDADDITIVELIGHTTOSCENE:
			re.AddAdditiveLightToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ) );
			return 0;

		case CG_FS_SEEK:
			return FS_Seek( args[ 1 ], args[ 2 ], args[ 3 ] );

		case CG_R_ADDCORONATOSCENE:
			re.AddCoronaToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), args[ 6 ], args[ 7 ] );
			return 0;

		case CG_R_SETFOG:
			re.SetFog( args[ 1 ], args[ 2 ], args[ 3 ], VMF( 4 ), VMF( 5 ), VMF( 6 ), VMF( 7 ) );
			return 0;

		case CG_R_SETGLOBALFOG:
			re.SetGlobalFog( args[ 1 ], args[ 2 ], VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ) );
			return 0;

		case CG_R_RENDERSCENE:
			re.RenderScene( VMA( 1 ) );
			return 0;

		case CG_R_SAVEVIEWPARMS:
			re.SaveViewParms();
			return 0;

		case CG_R_RESTOREVIEWPARMS:
			re.RestoreViewParms();
			return 0;

		case CG_R_SETCOLOR:
			re.SetColor( VMA( 1 ) );
			return 0;

			// Tremulous
		case CG_R_SETCLIPREGION:
			re.SetClipRegion( VMA( 1 ) );
开发者ID:justhacking,项目名称:Unvanquished,代码行数:67,代码来源:cl_cgame.c

示例9: CL_ParseDemo

// Do very shallow parse of the demo (could be extended) just to get times and snapshot count
static void CL_ParseDemo(void)
{
	int tstart   = 0;
	int demofile = 0;

	// Reset our demo data
	memset(&di, 0, sizeof(di));

	// Parse start
	di.gameStartTime = -1;
	di.gameEndTime   = -1;
	FS_Seek(clc.demofile, 0, FS_SEEK_SET);
	tstart = Sys_Milliseconds();

	while (qtrue)
	{
		int   r;
		msg_t buf;
		msg_t *msg;
		byte  bufData[MAX_MSGLEN];
		int   s;
		int   cmd;

		di.demoPos = FS_FTell(clc.demofile);

		// get the sequence number
		r = FS_Read(&s, 4, clc.demofile);
		if (r != 4)
		{
			CL_DemoCompleted();
			return;
		}

		clc.serverMessageSequence = LittleLong(s);

		// init the message
		MSG_Init(&buf, bufData, sizeof(bufData));

		// get the length
		r = FS_Read(&buf.cursize, 4, clc.demofile);

		if (r != 4)
		{
			break;
		}

		buf.cursize = LittleLong(buf.cursize);
		if (buf.cursize == -1)
		{
			break;
		}

		if (buf.cursize > buf.maxsize)
		{
			Com_FuncPrinf("demoMsglen > MAX_MSGLEN");
			break;
		}

		r = FS_Read(buf.data, buf.cursize, clc.demofile);
		if (r != buf.cursize)
		{
			Com_FuncPrinf("Demo file was truncated.\n");
			break;
		}

		clc.lastPacketTime = cls.realtime;
		buf.readcount      = 0;

		// parse
		msg = &buf;
		MSG_Bitstream(msg);

		// get the reliable sequence acknowledge number
		clc.reliableAcknowledge = MSG_ReadLong(msg);

		if (clc.reliableAcknowledge < clc.reliableSequence - MAX_RELIABLE_COMMANDS)
		{
			clc.reliableAcknowledge = clc.reliableSequence;
		}

		// parse the message
		while (qtrue)
		{
			if (msg->readcount > msg->cursize)
			{
				Com_FuncDrop("read past end of server message");
				return;
			}

			cmd = MSG_ReadByte(msg);

			if (cmd == svc_EOF)
			{
				break;
			}

			// other commands
			switch (cmd)
			{
//.........这里部分代码省略.........
开发者ID:dstaesse,项目名称:etlegacy,代码行数:101,代码来源:cl_demo.c

示例10: Com_Error

bool
Md3Utils::getModelDimensions( fileHandle_t const& file,
							  vec3_t& mins,
							  vec3_t& maxs,
							  int checkFrame )
{
	if( !file )
	{
		Com_Error(ERR_FATAL, "Invalid filehandle passed to Md3Utils::getModelDimensions\n" );
		return false;
	}

	// put it back to beginning of file (just in case)
	if( FS_Seek( file, 0, FS_SEEK_SET ) != 0 )
	{
		Com_Error(ERR_FATAL, "Unable to set file pointer in file!\n" );
		return false;
	}

	bool found = false;

	// get body bounding boxes
	md3Header_t header;
	md3Frame_t currentFrame;

	FS_Read2(&header, sizeof(header), file);
	int number = header.numFrames;

	if( checkFrame >= number )
	{
		Com_Error(ERR_FATAL, "File only has %d frames, therefore unable to check frame %d\n", 
					number, checkFrame );
		return false;
	}
	else if( checkFrame == FRAMESIZE_FIRST )
		checkFrame = 0;
	else if( checkFrame == FRAMESIZE_LAST )
		checkFrame = number - 1;

	found = true;

	for( int i = 0; i < number; ++i ) 
	{
		FS_Read2(&currentFrame, sizeof(currentFrame), file);

		if( checkFrame >= 0 && i == checkFrame )
		{
			VectorCopy( currentFrame.bounds[0], mins );
			VectorCopy( currentFrame.bounds[1], maxs );
			break;
		}
		else	// check for all
		{
			if( i == 0 )
			{
				VectorCopy( currentFrame.bounds[0], mins );
				VectorCopy( currentFrame.bounds[1], maxs );
			}
			else
			{
				if( currentFrame.bounds[0][0] < mins[0] )
					mins[0] = currentFrame.bounds[0][0];
				if( currentFrame.bounds[0][1] < mins[1] )
					mins[1] = currentFrame.bounds[0][1];
				if( currentFrame.bounds[0][2] < mins[2] )
					mins[2] = currentFrame.bounds[0][2];

				if( currentFrame.bounds[1][0] > maxs[0] )
					maxs[0] = currentFrame.bounds[1][0];
				if( currentFrame.bounds[1][1] > maxs[1] )
					maxs[1] = currentFrame.bounds[1][1];
				if( currentFrame.bounds[1][2] > maxs[2] )
					maxs[2] = currentFrame.bounds[1][2];
			}
		}
	}
	return found;
}
开发者ID:MilitaryForces,项目名称:MilitaryForces,代码行数:78,代码来源:bg_md3utils.cpp

示例11: CL_PeekSnapshot

qboolean CL_PeekSnapshot(int snapshotNumber, snapshot_t *snapshot)
{
	clSnapshot_t *clSnap;
	clSnapshot_t csn;
	int          i, count;
	int          origPosition;
	int          cmd;
	//char         *s;
	char     buffer[16];
	qboolean success = qfalse;
	int      r;
	msg_t    buf;
	byte     bufData[MAX_MSGLEN];
	int      j;
	int      lastPacketTimeOrig;
	int      parseEntitiesNumOrig;
	int      currentSnapNum;
	//int      serverMessageSequence;

	clSnap = &csn;

	if (!clc.demoplaying)
	{
		return qfalse;
	}

	if (snapshotNumber <= cl.snap.messageNum)
	{
		success = CL_GetSnapshot(snapshotNumber, snapshot);
		if (!success)
		{
			Com_FuncPrinf("snapshot number outside of backup buffer\n");
			return qfalse;
		}
		return qtrue;
	}

	if (snapshotNumber > cl.snap.messageNum + 1)
	{
		Com_FuncPrinf("FIXME CL_PeekSnapshot  %d >  cl.snap.messageNum + 1 (%d)\n", snapshotNumber, cl.snap.messageNum);
		return qfalse; // FIXME:
	}

	parseEntitiesNumOrig = cl.parseEntitiesNum;
	lastPacketTimeOrig   = clc.lastPacketTime;
	// CL_ReadDemoMessage()
	origPosition = FS_FTell(clc.demofile);

	if (origPosition < 0)
	{
		// FS_FTell prints the warning ...
		return qfalse;
	}

	currentSnapNum = cl.snap.messageNum;

	for (j = 0; j < snapshotNumber - currentSnapNum; j++)
	{
		// get the sequence number
		memset(buffer, 0, sizeof(buffer));
		r = FS_Read(&buffer, 4, clc.demofile);
		if (r != 4)
		{
			Com_FuncPrinf("couldn't read sequence number\n");
			FS_Seek(clc.demofile, origPosition, FS_SEEK_SET);
			clc.lastPacketTime  = lastPacketTimeOrig;
			cl.parseEntitiesNum = parseEntitiesNumOrig;
			return qfalse;
		}
		//serverMessageSequence = LittleLong(*((int *)buffer));

		// init the message
		memset(&buf, 0, sizeof(msg_t));
		MSG_Init(&buf, bufData, sizeof(bufData));

		// get the length
		r = FS_Read(&buf.cursize, 4, clc.demofile);
		if (r != 4)
		{
			Com_FuncPrinf("couldn't get length\n");
			FS_Seek(clc.demofile, origPosition, FS_SEEK_SET);
			clc.lastPacketTime  = lastPacketTimeOrig;
			cl.parseEntitiesNum = parseEntitiesNumOrig;
			return qfalse;
		}

		buf.cursize = LittleLong(buf.cursize);
		if (buf.cursize == -1)
		{
			Com_FuncPrinf("buf.cursize == -1\n");
			FS_Seek(clc.demofile, origPosition, FS_SEEK_SET);
			clc.lastPacketTime  = lastPacketTimeOrig;
			cl.parseEntitiesNum = parseEntitiesNumOrig;
			return qfalse;
		}

		if (buf.cursize > buf.maxsize)
		{
			Com_FuncDrop("demoMsglen > MAX_MSGLEN");
			return qfalse;
//.........这里部分代码省略.........
开发者ID:dstaesse,项目名称:etlegacy,代码行数:101,代码来源:cl_demo.c

示例12: CL_ReadDemoMessage

/*
====================
CL_ReadDemoMessage

Handles playback of demos
====================
*/
void CL_ReadDemoMessage(void)
{
	int i;
	float f;

	if (!cls.demoplayback)
		return;

	// LordHavoc: pausedemo
	if (cls.demopaused)
		return;

	for (;;)
	{
		// decide if it is time to grab the next message
		// always grab until fully connected
		if (cls.signon == SIGNONS)
		{
			if (cls.timedemo)
			{
				cls.td_frames++;
				cls.td_onesecondframes++;
				// if this is the first official frame we can now grab the real
				// td_starttime so the bogus time on the first frame doesn't
				// count against the final report
				if (cls.td_frames == 0)
				{
					cls.td_starttime = realtime;
					cls.td_onesecondnexttime = cl.time + 1;
					cls.td_onesecondrealtime = realtime;
					cls.td_onesecondframes = 0;
					cls.td_onesecondminfps = 0;
					cls.td_onesecondmaxfps = 0;
					cls.td_onesecondavgfps = 0;
					cls.td_onesecondavgcount = 0;
				}
				if (cl.time >= cls.td_onesecondnexttime)
				{
					double fps = cls.td_onesecondframes / (realtime - cls.td_onesecondrealtime);
					if (cls.td_onesecondavgcount == 0)
					{
						cls.td_onesecondminfps = fps;
						cls.td_onesecondmaxfps = fps;
					}
					cls.td_onesecondrealtime = realtime;
					cls.td_onesecondminfps = min(cls.td_onesecondminfps, fps);
					cls.td_onesecondmaxfps = max(cls.td_onesecondmaxfps, fps);
					cls.td_onesecondavgfps += fps;
					cls.td_onesecondavgcount++;
					cls.td_onesecondframes = 0;
					cls.td_onesecondnexttime++;
				}
			}
			else if (cl.time <= cl.mtime[0])
			{
				// don't need another message yet
				return;
			}
		}

		// get the next message
		FS_Read(cls.demofile, &cl_message.cursize, 4);
		cl_message.cursize = LittleLong(cl_message.cursize);
		if(cl_message.cursize & DEMOMSG_CLIENT_TO_SERVER) // This is a client->server message! Ignore for now!
		{
			// skip over demo packet
			FS_Seek(cls.demofile, 12 + (cl_message.cursize & (~DEMOMSG_CLIENT_TO_SERVER)), SEEK_CUR);
			continue;
		}
		if (cl_message.cursize > cl_message.maxsize)
		{
			Con_Printf("Demo message (%i) > cl_message.maxsize (%i)", cl_message.cursize, cl_message.maxsize);
			cl_message.cursize = 0;
			CL_Disconnect();
			return;
		}
		VectorCopy(cl.mviewangles[0], cl.mviewangles[1]);
		for (i = 0;i < 3;i++)
		{
			FS_Read(cls.demofile, &f, 4);
			cl.mviewangles[0][i] = LittleFloat(f);
		}

		if (FS_Read(cls.demofile, cl_message.data, cl_message.cursize) == cl_message.cursize)
		{
			MSG_BeginReading(&cl_message);
			CL_ParseServerMessage();

			if (cls.signon != SIGNONS)
				Cbuf_Execute(); // immediately execute svc_stufftext if in the demo before connect!

			// In case the demo contains a "svc_disconnect" message
			if (!cls.demoplayback)
//.........这里部分代码省略.........
开发者ID:SMBXon,项目名称:darkplaces,代码行数:101,代码来源:cl_demo.c

示例13: aud_trim_open_req_hdlr

/*****************************************************************************
 * FUNCTION
 *  aud_trim_open_req_hdlr
 * DESCRIPTION
 *  This function is used to open a trimming handler.
 * PARAMETERS
 *
 * RETURNS
 *  void
 *****************************************************************************/
void aud_trim_open_req_hdlr(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint32                  file_len = 0;
    FSAL_Status                 fsal_result;
    kal_uint8*                  fsal_buf_p = NULL;
    media_open_func_ptr         open_fct = NULL;
    kal_int32                   result = MED_RES_FAIL;
    l4aud_trim_open_req_struct* msg_p = (l4aud_trim_open_req_struct*) ilm_ptr->local_para_ptr;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ASSERT(msg_p->file_name_in && msg_p->file_name_out && msg_p->handle_p);
    
    /* Check if trimming handler is already opened. Currently, we only support one instance. */
    if (g_is_trim_opened)
    {
        result = MED_RES_BUSY;
        goto aud_trim_open_failed;
    }

    /* Initialize context */
    g_is_trim_opened = KAL_TRUE;
    memset(&g_trim_ctx, 0, sizeof(aud_trim_context_t));
    g_trim_ctx.file_output = -1;
    g_trim_ctx.src_mod_id = ilm_ptr->src_mod_id;

    /* Select a MHdl open function per media format */
    g_trim_ctx.format = med_get_media_type(msg_p->file_name_in);

    switch (g_trim_ctx.format)
    {
    #ifdef DAF_DECODE
        case MED_TYPE_DAF:
    #endif /* DAF_DECODE */
            open_fct = DAF_Open;
            break;
        default:
            /* Unsupport format */
            ASSERT(0);
    }

    if (open_fct)
    {
        /* Create a FSAL handler */
        if ((fsal_result = FSAL_Open(&g_trim_ctx.fsal_handle, msg_p->file_name_in, FSAL_READ_SHARED)) != FSAL_OK)
        {
            result = MED_RES_OPEN_FILE_FAIL;
            goto aud_trim_open_failed;
        }

        g_trim_ctx.is_fsal_opened = KAL_TRUE;
        
        fsal_buf_p = (kal_uint8*) get_ctrl_buffer(sizeof(kal_uint8) * AUD_PROC_BUF_SIZE);
        FSAL_SetBuffer(&g_trim_ctx.fsal_handle, AUD_PROC_BUF_SIZE, fsal_buf_p);

        /* Open a MHdl handler */
        g_trim_ctx.mhdl_handle_p = open_fct(_aud_trim_event_callback_fct, &g_trim_ctx.fsal_handle, NULL);
        _AUD_TRIM_TRACE(g_trim_ctx.mhdl_handle_p, g_trim_ctx.format, fsal_buf_p);

        if (g_trim_ctx.mhdl_handle_p == NULL)
        {
            result = MED_RES_BAD_FORMAT;
            goto aud_trim_open_failed;
        }

        /* Create output file handle */
        g_trim_ctx.file_output = FS_Open(msg_p->file_name_out, FS_READ_WRITE | FS_OPEN_SHARED | FS_NOBUSY_CHECK_MODE);
    
        if (g_trim_ctx.file_output >= 0) /* File already exists */
        {
            /* Check if the size of file is 0 because MMI may create the file to be trimmed to in advance */
            FS_GetFileSize(g_trim_ctx.file_output, &file_len);
            
            if (file_len != 0)
            {
                /* Seek to the beginning of the file to overwrite all the data */
                FS_Seek(g_trim_ctx.file_output, 0, FS_FILE_BEGIN);
            }
        }
        else /* File does not exist */
        {
            /* Create a new file */
            g_trim_ctx.file_output = FS_Open(msg_p->file_name_out, FS_CREATE | FS_READ_WRITE | FS_OPEN_SHARED | FS_NOBUSY_CHECK_MODE);
        }

        _AUD_TRIM_TRACE(g_trim_ctx.file_output, file_len, -1);
//.........这里部分代码省略.........
开发者ID:WayWingsDev,项目名称:testmywatch,代码行数:101,代码来源:aud_trim.c

示例14: HPAK_RemoveLump

void HPAK_RemoveLump( const char *name, resource_t *resource )
{
	string		read_path;
	string		save_path;
	file_t		*f1, *f2;
	hpak_container_t	hpak_read;
	hpak_container_t	hpak_save;
	int		i, j;

	if( !name || !name[0] || !resource )
		return;

	HPAK_FlushHostQueue();

	Q_strncpy( read_path, name, sizeof( read_path ));
	FS_StripExtension( read_path );
	FS_DefaultExtension( read_path, ".hpk" );

	f1 = FS_Open( read_path, "rb", false );
	if( !f1 )
	{
		MsgDev( D_ERROR, "HPAK_RemoveLump: %s couldn't open.\n", read_path );
		return;
	}

	Q_strncpy( save_path, read_path, sizeof( save_path ));
	FS_StripExtension( save_path );
	FS_DefaultExtension( save_path, ".hp2" );
	f2 = FS_Open( save_path, "w+b", false );
	if( !f2 )
	{
		MsgDev( D_ERROR, "HPAK_RemoveLump: %s couldn't open.\n", save_path );
		FS_Close( f1 );
		return;
	}

	FS_Seek( f1, 0, SEEK_SET );
	FS_Seek( f2, 0, SEEK_SET );

	// header copy
	FS_Read( f1, &hash_pack_header, sizeof( hpak_header_t ));
	FS_Write( f2, &hash_pack_header, sizeof( hpak_header_t ));

	if( hash_pack_header.ident != IDCUSTOMHEADER || hash_pack_header.version != IDCUSTOM_VERSION )
	{
		MsgDev( D_ERROR, "HPAK_RemoveLump: %s has invalid header.\n", read_path );
		FS_Close( f1 );
		FS_Close( f2 );
		FS_Delete( save_path ); // delete temp file
		return;
	}

	FS_Seek( f1, hash_pack_header.seek, SEEK_SET );
	FS_Read( f1, &hpak_read.count, sizeof( hpak_read.count ));

	if( hpak_read.count < 1 || hpak_read.count > MAX_FILES_IN_WAD )
	{
		MsgDev( D_ERROR, "HPAK_RemoveLump: %s has invalid number of lumps.\n", read_path );
		FS_Close( f1 );
		FS_Close( f2 );
		FS_Delete( save_path ); // delete temp file
		return;
	}

	if( hpak_read.count == 1 )
	{
		MsgDev( D_ERROR, "HPAK_RemoveLump: %s only has one element, so it's not deleted.\n", read_path );
		FS_Close( f1 );
		FS_Close( f2 );
		FS_Delete( read_path );
		FS_Delete( save_path );
		return;
	}

	hpak_save.count = hpak_read.count - 1;
	hpak_read.dirs = Z_Malloc( sizeof( hpak_dir_t ) * hpak_read.count );
	hpak_save.dirs = Z_Malloc( sizeof( hpak_dir_t ) * hpak_save.count );

	FS_Read( f1, hpak_read.dirs, sizeof( hpak_dir_t ) * hpak_read.count );

	if( !HPAK_FindResource( &hpak_read, resource->rgucMD5_hash, NULL ))
	{
		MsgDev( D_ERROR, "HPAK_RemoveLump: Couldn't find the lump %s in hpak %s.n", resource->szFileName, read_path );
		Mem_Free( hpak_read.dirs );
		Mem_Free( hpak_save.dirs );
		FS_Close( f1 );
		FS_Close( f2 );
		FS_Delete( save_path );
		return;
	}

	MsgDev( D_INFO, "Removing lump %s from %s.\n", resource->szFileName, read_path );

	// If there's a collision, we've just corrupted this hpak.
	for( i = 0, j = 0; i < hpak_read.count; i++ )
	{
		if( !Q_memcmp( hpak_read.dirs[i].DirectoryResource.rgucMD5_hash, resource->rgucMD5_hash, 16 ))
			continue;

		hpak_save.dirs[j] = hpak_read.dirs[i];
//.........这里部分代码省略.........
开发者ID:DavidKnight247,项目名称:xash3d,代码行数:101,代码来源:hpak.c

示例15: HPAK_CreatePak

void HPAK_CreatePak( const char *filename, resource_t *DirEnt, byte *data, file_t *f )
{
	int		filelocation;
	string		pakname;
	char		md5[16];
	char		*temp;
	MD5Context_t	MD5_Hash;
	file_t		*fout;

	if( !filename || !filename[0] )
	{
		MsgDev( D_ERROR, "HPAK_CreatePak: NULL name\n" );
		return;
	}

	if(( f != NULL && data != NULL ) || ( f == NULL && data == NULL ))
	{
		MsgDev( D_ERROR, "HPAK_CreatePak: too many sources, please leave one.\n" );
		return;
	}

	Q_strncpy( pakname, filename, sizeof( pakname ));
	FS_StripExtension( pakname );
	FS_DefaultExtension( pakname, ".hpk" );

	MsgDev( D_INFO, "creating HPAK %s.\n", pakname );
	fout = FS_Open( pakname, "wb", false );
	if( !fout )
	{
		MsgDev( D_ERROR, "HPAK_CreatePak: can't write %s.\n", pakname );
		return;
	}

	// let's hash it.
	Q_memset( &MD5_Hash, 0, sizeof( MD5Context_t ));
	MD5Init( &MD5_Hash );

	if( data == NULL )
	{
		// there are better ways
		filelocation = FS_Tell( f );
		temp = Z_Malloc( DirEnt->nDownloadSize );
		FS_Read( f, temp, DirEnt->nDownloadSize );
		FS_Seek( f, filelocation, SEEK_SET );

		MD5Update( &MD5_Hash, temp, DirEnt->nDownloadSize );
		Mem_Free( temp );
	}
	else
	{
		MD5Update( &MD5_Hash, data, DirEnt->nDownloadSize );
	}

	MD5Final( md5, &MD5_Hash );

	if( Q_memcmp( md5, DirEnt->rgucMD5_hash, 16 ))
	{
		MsgDev( D_ERROR, "HPAK_CreatePak: bad checksum for %s. Ignored\n", pakname );
		return;
	}

	hash_pack_header.ident = IDCUSTOMHEADER;
	hash_pack_header.version = IDCUSTOM_VERSION;
	hash_pack_header.seek = 0;

	FS_Write( fout, &hash_pack_header, sizeof( hash_pack_header ));

	hash_pack_dir.count = 1;
	hash_pack_dir.dirs = Z_Malloc( sizeof( hpak_dir_t ));
	hash_pack_dir.dirs[0].DirectoryResource = *DirEnt;
	hash_pack_dir.dirs[0].seek = FS_Tell( fout );
	hash_pack_dir.dirs[0].size = DirEnt->nDownloadSize;

	if( data == NULL )
	{
		HPAK_FileCopy( fout, f, hash_pack_dir.dirs[0].size );
	}
	else
	{
		FS_Write( fout, data, hash_pack_dir.dirs[0].size );
	}

	filelocation = FS_Tell( fout );
	FS_Write( fout, &hash_pack_dir.count, sizeof( hash_pack_dir.count ));
	FS_Write( fout, &hash_pack_dir.dirs[0], sizeof( hpak_dir_t ));

	Mem_Free( hash_pack_dir.dirs );
	Q_memset( &hash_pack_dir, 0, sizeof( hpak_container_t ));

	hash_pack_header.seek = filelocation;
	FS_Seek( fout, 0, SEEK_SET );
	FS_Write( fout, &hash_pack_header, sizeof( hpak_header_t ));
	FS_Close( fout );
}
开发者ID:DavidKnight247,项目名称:xash3d,代码行数:94,代码来源:hpak.c


注:本文中的FS_Seek函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。