예제 #1
0
/*
=================
S_CodecUtilOpen
=================
*/
snd_stream_t *S_CodecUtilOpen(const char *filename, snd_codec_t *codec)
{
    snd_stream_t *stream;
    fileHandle_t hnd;
    int length;

    // Try to open the file
    length = FS_FOpenFileRead(filename, &hnd, qtrue);
    if(!hnd)
    {
        Com_Printf(_("Can't read sound file %s\n"), filename);
        return NULL;
    }

    // Allocate a stream
    stream = Z_Malloc(sizeof(snd_stream_t));
    if(!stream)
    {
        FS_FCloseFile(hnd);
        return NULL;
    }

    // Copy over, return
    stream->codec = codec;
    stream->file = hnd;
    stream->length = length;
    return stream;
}
예제 #2
0
	QInputbuf(const std::string& filename) : putBack(1)
	{
		char *end = buffer + BUFFER_SIZE - putBack;

		setg(end, end, end);

		FS_FOpenFileRead(filename.c_str(), &fileHandle, qfalse);
	}
예제 #3
0
파일: sv_init.c 프로젝트: MAN-AT-ARMS/ioq3
/*
================
SV_TouchFile
================
*/
static void SV_TouchFile( const char *filename ) {
	fileHandle_t	f;

	FS_FOpenFileRead( filename, &f, qfalse );
	if ( f ) {
		FS_FCloseFile( f );
	}
}
예제 #4
0
/*
================
SV_TouchCGame

Touch the cgame.qvm and ui.qvm so that a pure client can load it if it's in a seperate pk3, and so it gets on the download list
================
*/
static void SV_TouchCGame(void) {
	fileHandle_t	f;

	FS_FOpenFileRead( "vm/cgame.qvm", &f, qfalse );
	if ( f ) {
		FS_FCloseFile( f );
	} else if ( sv_pure->integer ) {
		Com_Printf( "WARNING: No cgame.qvm found on pure server\n" );
	}

	FS_FOpenFileRead( "vm/ui.qvm", &f, qfalse );
	if ( f ) {
		FS_FCloseFile( f );
	} else if ( sv_pure->integer ) {
		Com_Printf( "WARNING: No ui.qvm found on pure server\n" );
	}
}
예제 #5
0
파일: snd_mem.c 프로젝트: entdark/q3mme
qboolean S_FileExists(char *fileName) {
	fileHandle_t f;
	COM_StripExtension(fileName, fileName);
	COM_DefaultExtension(fileName, MAX_QPATH, ".wav");
	FS_FOpenFileRead(fileName, &f, qtrue);
	if (!f) {
#ifdef HAVE_LIBMAD
		COM_StripExtension(fileName, fileName);
		COM_DefaultExtension(fileName, MAX_QPATH, ".mp3");
		FS_FOpenFileRead(fileName, &f, qtrue);
		if (!f)
#endif
			return qfalse;
	}
	FS_FCloseFile(f);
	return qtrue;
}
예제 #6
0
/*
================
SV_TouchCGame

  touch cgame so that a pure client can load it if it's in a seperate pk3
================
*/
void SV_TouchCGame( void )
{
	fileHandle_t f;

	FS_FOpenFileRead( "vm/cgame.qvm", &f, qfalse );

	if ( f )
	{
		FS_FCloseFile( f );
	}

	// LLVM - even if the server doesn't use llvm itself, it should still add the references.
	FS_FOpenFileRead( "cgamellvm.bc", &f, qfalse );

	if ( f )
	{
		FS_FCloseFile( f );
	}
}
예제 #7
0
/*
================
SV_TouchCGame

  touch the cgame.vm so that a pure client can load it if it's in a seperate pk3
================
*/
void SV_TouchCGame(void) {
    fileHandle_t	f;
    char filename[MAX_QPATH];

    Com_sprintf( filename, sizeof(filename), "vm/%s.qvm", "cgame" );
    FS_FOpenFileRead( filename, &f, qfalse );
    if ( f ) {
        FS_FCloseFile( f );
    }
}
예제 #8
0
void BotLoadOffMeshConnections( const char *filename, NavData_t *nav )
{
	char mapname[ MAX_QPATH ];
	char filePath[ MAX_QPATH ];
	fileHandle_t f = 0;

	Cvar_VariableStringBuffer( "mapname", mapname, sizeof( mapname ) );
	Com_sprintf( filePath, sizeof( filePath ), "maps/%s-%s.navcon", mapname, filename );
	FS_FOpenFileRead( filePath, &f, qtrue );

	if ( !f )
	{
		return;
	}

	OffMeshConnectionHeader header;
	FS_Read( &header, sizeof( header ), f );

	header.version = LittleLong( header.version );
	header.numConnections = LittleLong( header.numConnections );

	if ( header.version != NAVMESHCON_VERSION )
	{
		FS_FCloseFile( f );
		return;
	}

	int conCount = header.numConnections;

	if ( conCount > nav->process.con.MAX_CON )
	{
		FS_FCloseFile( f );
		return;
	}

	nav->process.con.offMeshConCount = conCount;

	FS_Read( nav->process.con.verts, sizeof( float ) * 6 * conCount, f );
	SwapArray( nav->process.con.verts, conCount * 6 );

	FS_Read( nav->process.con.rad, sizeof( float ) * conCount, f );
	SwapArray( nav->process.con.rad, conCount );

	FS_Read( nav->process.con.flags, sizeof( unsigned short ) * conCount, f );
	SwapArray( nav->process.con.flags, conCount );

	FS_Read( nav->process.con.areas, sizeof( unsigned char ) * conCount, f );
	FS_Read( nav->process.con.dirs, sizeof( unsigned char ) * conCount, f );

	FS_Read( nav->process.con.userids, sizeof( unsigned int ) * conCount, f );
	SwapArray( nav->process.con.userids, conCount );

	FS_FCloseFile( f );
}
예제 #9
0
int	FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode )
{
	FS_CheckInit();

	if (mode != FS_READ)
	{
		Com_Error( ERR_FATAL, "FSH_FOpenFile: bad mode" );
		return -1;
	}
	
	return FS_FOpenFileRead( qpath, f, qtrue );
}
예제 #10
0
파일: snd_mem.c 프로젝트: entdark/q3mme
static openSound_t *S_StreamOpen( const char *fileName, int dataSize ) {
	fileHandle_t fileHandle = 0;
	int fileSize = 0;
	openSound_t *open;

	fileSize = FS_FOpenFileRead( fileName, &fileHandle, qtrue );
	if ( fileSize <= 0 || fileHandle <= 0)
		return 0;
	open = Z_Malloc( sizeof( openSound_t ) + dataSize );
	open->fileSize = fileSize;
	open->fileHandle = fileHandle;
	return open;
}
예제 #11
0
/*
================
SV_TouchCGame

  touch the cgamex86.dll so that a pure client can load it if it's in a seperate pk3
================
*/
static void SV_TouchCGame(void) {
	fileHandle_t	f;
	char filename[MAX_QPATH];

	Com_sprintf( filename, sizeof(filename), "cgame" ARCH_STRING ".dll" );
	FS_FOpenFileRead( filename, &f, qfalse );
	if ( f ) {
		FS_FCloseFile( f );
	}
	else if ( sv_pure->integer ) {
		Com_Error( ERR_DROP, "Failed to locate cgame DLL for pure server mode" );
	}
}
예제 #12
0
파일: cl_demo.c 프로젝트: dstaesse/etlegacy
/*
====================
CL_WalkDemoExt
====================
*/
static int CL_WalkDemoExt(char *arg, char *name, int *demofile)
{
	int i = 0;
	*demofile = 0;

	Com_sprintf(name, MAX_OSPATH, "demos/%s.%s%d", arg, DEMOEXT, PROTOCOL_VERSION);
	FS_FOpenFileRead(name, demofile, qtrue);

	if (*demofile)
	{
		Com_FuncPrinf("Demo file: %s\n", name);
		return PROTOCOL_VERSION;
	}

	Com_FuncPrinf("Not found: %s\n", name);

	while (demo_protocols[i])
	{
		if (demo_protocols[i] == PROTOCOL_VERSION)
		{
			continue;
		}

		Com_sprintf(name, MAX_OSPATH, "demos/%s.%s%d", arg, DEMOEXT, demo_protocols[i]);
		FS_FOpenFileRead(name, demofile, qtrue);
		if (*demofile)
		{
			Com_FuncPrinf("Demo file: %s\n", name);
			return demo_protocols[i];
		}
		else
		{
			Com_FuncPrinf("Not found: %s\n", name);
		}
		i++;
	}

	return -1;
}
예제 #13
0
qboolean dmaHD_LoadSound(sfx_t *sfx)
{
	byte *data;
	snd_info_t info;
	char dmahd_soundName[MAX_QPATH];
	char *lpext;

	// Player specific sounds are never directly loaded.
	if (sfx->soundName[0] == '*') return qfalse;

	strcpy(dmahd_soundName, sfx->soundName);
	if ((lpext = strrchr(sfx->soundName, '.')) != NULL)
	{
		strcpy(dmahd_soundName, sfx->soundName);
		*(strrchr(dmahd_soundName, '.')) = '\0'; // for sure there is a '.'
	}
	strcat(dmahd_soundName, "_dmahd");
	if (lpext != NULL) strcat(dmahd_soundName, lpext);

	// Just check if file exists
	if (FS_FOpenFileRead(dmahd_soundName, NULL, qtrue) == qtrue)
	{
		// Load it in.
		if (!(data = S_CodecLoad(dmahd_soundName, &info))) return qfalse;
	}
	else
	{
		// Load it in.
		if (!(data = S_CodecLoad(sfx->soundName, &info))) return qfalse;
	}

	// Information
	Com_DPrintf("Loading sound: %s", sfx->soundName);
	if (info.width == 1) Com_DPrintf(" [8 bit -> 16 bit]");
	if (info.rate != dma.speed) Com_DPrintf(" [%d Hz -> %d Hz]", info.rate, dma.speed);
	Com_DPrintf("\n");

	sfx->lastTimeUsed = Com_Milliseconds() + 1;

	// Do not compress.
	sfx->soundCompressionMethod = 0;
	sfx->soundLength = info.samples;
	sfx->soundData = NULL;
	dmaHD_ResampleSfx(sfx, info.rate, info.width, data + info.dataofs, qfalse);
	
	// Free data allocated by Codec
	Z_Free(data);

	return qtrue;
}
예제 #14
0
/*
============
FS_ReadFile

Filename are relative to the quake search path
a null buffer will just return the file length without loading
============
*/
int FS_ReadFile( const char *qpath, void **buffer )
{
	FS_CheckInit();
	
	if ( !qpath || !qpath[0] ) {
		Com_Error( ERR_FATAL, "FS_ReadFile with empty name\n" );
	}

	// stop sounds from repeating
	S_ClearSoundBuffer();

	fileHandle_t h;
	int len = FS_FOpenFileRead( qpath, &h, qfalse );
	if ( h == 0 )
	{
		if ( buffer ) *buffer = NULL;
		return -1;
	}
	
	if ( !buffer )
	{
		FS_FCloseFile(h);
		return len;
	}

	byte *buf;
	// Try to TempAlloc if we've got the hint that this could fail:
	if( sbLargeRead )
		buf = (byte *)BonePoolTempAlloc( len+1 );

	// If that didn't work, or wasn't suggested:
	if( !sbLargeRead || !buf )
		buf = (byte*)Z_Malloc( len+1, TAG_TEMP_WORKSPACE, qfalse, 32);

	buf[len]='\0';

//	Z_Label(buf, qpath);

	FS_Read(buf, len, h);

	// guarantee that it will have a trailing 0 for string operations
	buf[len] = 0;
	FS_FCloseFile( h );

	*buffer = buf;
	return len;
}
예제 #15
0
/*
====================
SV_SetExpectedHunkUsage

  Sets com_expectedhunkusage, so the client knows how to draw the percentage bar
====================
*/
void SV_SetExpectedHunkUsage( char *mapname )
{
	int  handle;
	const char *memlistfile = "hunkusage.dat";
	char *buf;
	char *buftrav;
	char *token;
	int  len;

	len = FS_FOpenFileRead( memlistfile, &handle, qfalse );

	if ( len >= 0 )
	{
		// the file exists, so read it in, strip out the current entry for this map, and save it out, so we can append the new value
		buf = ( char * ) Z_Malloc( len + 1 );
		memset( buf, 0, len + 1 );

		FS_Read( ( void * ) buf, len, handle );
		FS_FCloseFile( handle );

		// now parse the file, filtering out the current map
		buftrav = buf;

		while ( ( token = COM_Parse( &buftrav ) ) != NULL && token[ 0 ] )
		{
			if ( !Q_stricmp( token, mapname ) )
			{
				// found a match
				token = COM_Parse( &buftrav );  // read the size

				if ( token && token[ 0 ] )
				{
					// this is the usage
					com_expectedhunkusage = atoi( token );
					Z_Free( buf );
					return;
				}
			}
		}

		Z_Free( buf );
	}

	// just set it to a negative number,so the cgame knows not to draw the percent bar
	com_expectedhunkusage = -1;
}
예제 #16
0
/*
================
SV_TouchCGame

  touch the cgame.vm so that a pure client can load it if it's in a seperate pk3
================
*/
void SV_TouchCGame(void) {
	fileHandle_t	f;
	char filename[MAX_QPATH];

	if (Cvar_VariableValue( "vm_cgame" ))
	{
		Com_sprintf( filename, sizeof(filename), "vm/%s.qvm", "cgame" );
	}
	else
	{
		Com_sprintf( filename, sizeof(filename), "cgamex86.dll" );
	}
	FS_FOpenFileRead( filename, &f, qfalse );
	if ( f ) {
		FS_FCloseFile( f );
	}
}
예제 #17
0
/*
==================
CON_Hist_Load
==================
*/
void CON_Hist_Load( void ) {
	fileHandle_t f;
	long len = FS_FOpenFileRead("conhist.log", &f, qtrue);
	if (f) {
		field_t tf {};
		for (long i = 0; i < len; i++) {
			char c;
			FS_Read(&c, 1, f);
			if (c == '\n') {
				Hist_Add(&tf);
				tf = {};
			} else {
				tf.buffer[tf.cursor++] = c;
			}
		}
		FS_FCloseFile(f);
	}
}
예제 #18
0
/*
=================
S_WAV_CodecLoad
=================
*/
void *S_WAV_CodecLoad(const char *filename, snd_info_t *info)
{
	fileHandle_t file;
	void         *buffer;

	// Try to open the file
	FS_FOpenFileRead(filename, &file, qtrue);
	if (!file)
	{
		if (com_developer->integer)
		{
			Com_Printf(S_COLOR_RED "ERROR: Could not open \"%s\"\n", filename);
		}
		return NULL;
	}

	// Read the RIFF header
	if (!S_ReadRIFFHeader(file, info))
	{
		FS_FCloseFile(file);
		if (com_developer->integer)
		{
			Com_Printf(S_COLOR_RED "ERROR: Incorrect/unsupported format in \"%s\"\n", filename);
		}
		return NULL;
	}

	// Allocate some memory
	buffer = Z_Malloc(info->size);
	if (!buffer)
	{
		FS_FCloseFile(file);
		Com_Printf(S_COLOR_RED "ERROR: Out of memory reading \"%s\"\n", filename);
		return NULL;
	}

	// Read, byteswap
	FS_Read(buffer, info->size, file);
	S_ByteSwapRawSamples(info->samples, info->width, info->channels, (byte *)buffer);

	// Close and return
	FS_FCloseFile(file);
	return buffer;
}
예제 #19
0
void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height ) 
{	
	*pic = NULL;	
	
	fileHandle_t	h;
	const int len = FS_FOpenFileRead( filename, &h, qfalse );
	if(!h)
	{
		return;
	}
	//JPEG system reads 4K past input buffer so we tack on an additional 4k.
	byte *pJPGData = (byte *)Z_Malloc(len + 4096, TAG_TEMP_WORKSPACE, qfalse);
	FS_Read(pJPGData, len, h);
	FS_FCloseFile( h );

	Decompress_JPG( filename, pJPGData, pic, width, height );

	Z_Free (pJPGData);
}
예제 #20
0
int FS_ReadFile(const char* path, void** buffer)
{
	fileHandle_t handle;
	int length = FS_FOpenFileRead(path, &handle, true);

	if (length < 0) {
		if (buffer)
			*buffer = nullptr;
		return -1;
	}

	if (buffer) {
		char* buf = new char[length + 1];
		*buffer = buf;
		FS_Read(buf, length, handle);
		buf[length] = '\0';
	}

	FS_FCloseFile(handle);
	return length;
}
예제 #21
0
/*
============
FS_ReadFile

Filename are relative to the quake search path
a null buffer will just return the file length without loading
============
*/
int FS_ReadFile( const char *qpath, void **buffer )
{
	FS_CheckInit();
	
	if ( !qpath || !qpath[0] ) {
		Com_Error( ERR_FATAL, "FS_ReadFile with empty name\n" );
	}

	// stop sounds from repeating
	S_ClearSoundBuffer();

	fileHandle_t h;
	int len = FS_FOpenFileRead( qpath, &h, qfalse );
	if ( h == 0 )
	{
		if ( buffer ) *buffer = NULL;
		return -1;
	}
	
	if ( !buffer )
	{
		FS_FCloseFile(h);
		return len;
	}

	// assume temporary....
	byte* buf = (byte*)Z_Malloc( len+1, TAG_TEMP_WORKSPACE, qfalse, 32);
	buf[len]='\0';

//	Z_Label(buf, qpath);

	FS_Read(buf, len, h);

	// guarantee that it will have a trailing 0 for string operations
	buf[len] = 0;
	FS_FCloseFile( h );

	*buffer = buf;
	return len;
}
예제 #22
0
/*
====================
LAN_LoadCachedServers
====================
*/
void LAN_LoadCachedServers( void )
{
	int          size;
	fileHandle_t fileIn;
	char         filename[ MAX_QPATH ];

	cls.numglobalservers = cls.numfavoriteservers = 0;
	cls.numGlobalServerAddresses = 0;

	if ( cl_profile->string[ 0 ] )
	{
		Com_sprintf( filename, sizeof( filename ), "profiles/%s/servercache.dat", cl_profile->string );
	}
	else
	{
		Q_strncpyz( filename, "servercache.dat", sizeof( filename ) );
	}

	// Arnout: moved to mod/profiles dir
	//if (FS_SV_FOpenFileRead(filename, &fileIn)) {
	if ( FS_FOpenFileRead( filename, &fileIn, qtrue ) )
	{
		FS_Read( &cls.numglobalservers, sizeof( int ), fileIn );
		FS_Read( &cls.numfavoriteservers, sizeof( int ), fileIn );
		FS_Read( &size, sizeof( int ), fileIn );

		if ( size == sizeof( cls.globalServers ) + sizeof( cls.favoriteServers ) )
		{
			FS_Read( &cls.globalServers, sizeof( cls.globalServers ), fileIn );
			FS_Read( &cls.favoriteServers, sizeof( cls.favoriteServers ), fileIn );
		}
		else
		{
			cls.numglobalservers = cls.numfavoriteservers = 0;
			cls.numGlobalServerAddresses = 0;
		}

		FS_FCloseFile( fileIn );
	}
}
예제 #23
0
/*
 * Finds the file in the search path. Returns filesize and an open FILE *. Used
 * for streaming data out of either a pak file or a seperate file.
 */
int
FS_FOpenFile(const char *name, fileHandle_t *f, fsMode_t mode)
{
	int size = 0;
	fsHandle_t *handle;

	handle = FS_HandleForFile(name, f);

	Q_strlcpy(handle->name, name, sizeof(handle->name));
	handle->mode = mode;

	switch (mode)
	{
		case FS_READ:
			size = FS_FOpenFileRead(handle);
			break;
		case FS_WRITE:
			size = FS_FOpenFileWrite(handle);
			break;
		case FS_APPEND:
			size = FS_FOpenFileAppend(handle);
			break;
		default:
			Com_Error(ERR_FATAL, "FS_FOpenFile: bad mode (%i)", mode);
			break;
	}

	if (size != -1)
	{
		return size;
	}

	/* Couldn't open, so free the handle. */
	memset(handle, 0, sizeof(*handle));
	*f = 0;

	return -1;
}
예제 #24
0
파일: snd_mem.cpp 프로젝트: entdark/jaMME
qboolean S_FileExists(char *fileName) {
	char *voice = strstr(fileName,"chars");
	fileHandle_t f;
	int i;
	if (voice && s_language) {
		if (stricmp("DEUTSCH",s_language->string)==0) {				
			strncpy(voice,"chr_d",5);	// same number of letters as "chars"
		} else if (stricmp("FRANCAIS",s_language->string)==0) {				
			strncpy(voice,"chr_f",5);	// same number of letters as "chars"
		} else if (stricmp("ESPANOL",s_language->string)==0) {				
			strncpy(voice,"chr_e",5);	// same number of letters as "chars"
		} else {
			voice = NULL;	// use this ptr as a flag as to whether or not we substituted with a foreign version
		}
	}
tryDefaultLanguage:
	i = 0;
	while (ext[i]) {
		COM_StripExtension(fileName, fileName, MAX_QPATH);
		COM_DefaultExtension(fileName, MAX_QPATH, ext[i]);
		FS_FOpenFileRead(fileName, &f, qtrue);
		if (f)
			break;
		i++;
	}
	/* switch back to english (default) and try again */
	if (!f && voice) {
		strncpy(voice, "chars", 5);
		voice = NULL;
		goto tryDefaultLanguage;
	}
	if (!f)
		return qfalse;
	FS_FCloseFile(f);
	return qtrue;
}
예제 #25
0
파일: cl_ui.c 프로젝트: etlegacy/etlegacy
/**
 * @brief LAN_LoadCachedServers
 */
void LAN_LoadCachedServers(void)
{
    int32_t      size;
    fileHandle_t fileIn;
    char         filename[MAX_QPATH];

    cls.numglobalservers         = cls.numfavoriteservers = 0;
    cls.numGlobalServerAddresses = 0;

    if (cl_profile->string[0])
    {
        Com_sprintf(filename, sizeof(filename), "profiles/%s/favcache.dat", cl_profile->string);
    }
    else
    {
        Q_strncpyz(filename, "favcache.dat", sizeof(filename));
    }

    // moved to mod/profiles dir
    if (FS_FOpenFileRead(filename, &fileIn, qtrue))
    {
        FS_Read(&cls.numfavoriteservers, sizeof(int32_t), fileIn);
        FS_Read(&size, sizeof(int32_t), fileIn);
        if (size == sizeof(cls.favoriteServers))
        {
            FS_Read(&cls.favoriteServers, sizeof(cls.favoriteServers), fileIn);
        }
        else
        {
            cls.numfavoriteservers = 0;
        }
        FS_FCloseFile(fileIn);
    }

    Com_Printf("Total favourite servers restored: %i\n", cls.numfavoriteservers);
}
예제 #26
0
qboolean demoCut(const char *oldName, int startTime, int endTime) {
	fileHandle_t	oldHandle = 0;
	fileHandle_t	newHandle = 0;
	msg_t			oldMsg;
	byte			oldData[MAX_MSGLEN];
	int				oldSize;
	char			newName[MAX_OSPATH];
	int				buf;
	int				readGamestate = 0;
	int				i;
	demoPlay_t		*play = demo.play.handle;
	qboolean		ret = qfalse;
	int				framesSaved = 0;
	char			newGameDir[MAX_QPATH];
	char			next;
	char			*ext;
	if (!play) {
		Com_Printf("Demo cutting is allowed in mme mode only.\n");
		return qfalse;
	}
	startTime += play->startTime;
	endTime += play->startTime;
	ext = Cvar_FindVar("mme_demoExt")->string;
	if (!*ext)
		ext = ".dm_26";
	oldSize = FS_FOpenFileRead(va("demos/%s%s", oldName, ext), &oldHandle, qtrue);
	if (!oldHandle) {
		Com_Printf("Failed to open %s for cutting.\n", oldName);
		return qfalse;
	}
	memset(&demo.cut.Clc, 0, sizeof(demo.cut.Clc));
	Com_SetLoadingMsg("Cutting the demo...");
	while (oldSize > 0) {
cutcontinue:
		MSG_Init(&oldMsg, oldData, sizeof(oldData));
		/* Read the sequence number */
		if (FS_Read(&demo.cut.Clc.serverMessageSequence, 4, oldHandle) != 4)
			goto cuterror;
		demo.cut.Clc.serverMessageSequence = LittleLong(demo.cut.Clc.serverMessageSequence);
		oldSize -= 4;
		/* Read the message size */
		if (FS_Read(&oldMsg.cursize,4, oldHandle) != 4)
			goto cuterror;
		oldMsg.cursize = LittleLong(oldMsg.cursize);
		oldSize -= 4;
		/* Negative size signals end of demo */
		if (oldMsg.cursize < 0)
			break;
		if (oldMsg.cursize > oldMsg.maxsize) 
			goto cuterror;
		/* Read the actual message */
		if (FS_Read(oldMsg.data, oldMsg.cursize, oldHandle) != oldMsg.cursize)
			goto cuterror;
		oldSize -= oldMsg.cursize;
		// init the bitstream
		MSG_BeginReading(&oldMsg);
		// Skip the reliable sequence acknowledge number
		MSG_ReadLong(&oldMsg);
		//
		// parse the message
		//
		while (1) {
			byte cmd;
			if (oldMsg.readcount > oldMsg.cursize) {
				Com_Printf("Demo cutter, read past end of server message.\n");
				goto cuterror;
			}
            cmd = MSG_ReadByte(&oldMsg);
			if (cmd == svc_EOF) {
                break;
			}
			// skip all the gamestates until we reach needed
			if (readGamestate < demo.currentNum) {
				if (cmd == svc_gamestate) {
					readGamestate++;
				}
				goto cutcontinue;
			}
			// other commands
			switch (cmd) {
			default:
				Com_Printf(S_COLOR_RED"ERROR: CL_ParseServerMessage: Illegible server message\n");
				goto cuterror;		
			case svc_nop:
				break;
			case svc_serverCommand:
				demoCutParseCommandString(&oldMsg, &demo.cut.Clc);
				break;
			case svc_gamestate:
				if (readGamestate > demo.currentNum) {
					Com_Printf("Warning: unexpected new gamestate, finishing cutting.\n");
					goto cutcomplete;
				}
				if (!demoCutParseGamestate(&oldMsg, &demo.cut.Clc, &demo.cut.Cl)) {
					goto cuterror;
				}
				Com_sprintf(newName, sizeof(newName), "demos/%s_cut%s", oldName, ext);
				newHandle = FS_FOpenFileWrite(newName);
				if (!newHandle) {
					Com_Printf("Failed to open %s for target cutting.\n", newName);
					return qfalse;
				}
				readGamestate++;
				break;
			case svc_snapshot:
				if (!demoCutParseSnapshot(&oldMsg, &demo.cut.Clc, &demo.cut.Cl)) {
					goto cuterror;
				}
				break;
			case svc_download:
				// read block number
				buf = MSG_ReadShort(&oldMsg);
				if (!buf)	//0 block, read file size
					MSG_ReadLong(&oldMsg);
				// read block size
				buf = MSG_ReadShort(&oldMsg);
				// read the data block
				for (;buf>0;buf--)
					MSG_ReadByte(&oldMsg);
				break;
			case svc_setgame:
				i = 0;
				while (i < MAX_QPATH) {
					next = MSG_ReadByte(&oldMsg);
					if(next) {
						newGameDir[i] = next;
					} else {
						break;
					}
					i++;
				}
				newGameDir[i] = 0;
				// But here we stop, and don't do more. If this goes horribly wrong sometime, you might have to go and actually do something with this.
				break;
			case svc_mapchange:
				// nothing to parse.
				break;
			}
		}
		int firstServerCommand = demo.cut.Clc.lastExecutedServerCommand;
		// process any new server commands
		for (;demo.cut.Clc.lastExecutedServerCommand < demo.cut.Clc.serverCommandSequence; demo.cut.Clc.lastExecutedServerCommand++) {
			char *command = demo.cut.Clc.serverCommands[demo.cut.Clc.lastExecutedServerCommand & (MAX_RELIABLE_COMMANDS - 1)];
			Cmd_TokenizeString(command);
			char *cmd = Cmd_Argv(0);
			if (cmd[0]) {
				firstServerCommand = demo.cut.Clc.lastExecutedServerCommand;
			}
			if (!strcmp(cmd, "cs")) {
				if (!demoCutConfigstringModified(&demo.cut.Cl)) {
					goto cuterror;
				}
			}
		}
		if (demo.cut.Cl.snap.serverTime > endTime) {
			goto cutcomplete;
		} else if (framesSaved > 0) {
			/* this msg is in range, write it */
			if (framesSaved > max(10, demo.cut.Cl.snap.messageNum - demo.cut.Cl.snap.deltaNum)) {
				demoCutWriteDemoMessage(&oldMsg, newHandle, &demo.cut.Clc);
			} else {
				demoCutWriteDeltaSnapshot(firstServerCommand, newHandle, qfalse, &demo.cut.Clc, &demo.cut.Cl);
			}
			framesSaved++;
		} else if (demo.cut.Cl.snap.serverTime >= startTime) {
			demoCutWriteDemoHeader(newHandle, &demo.cut.Clc, &demo.cut.Cl);
			demoCutWriteDeltaSnapshot(firstServerCommand, newHandle, qtrue, &demo.cut.Clc, &demo.cut.Cl);
			// copy rest
			framesSaved = 1;
		}
	}
cutcomplete:
	if (newHandle) {
		buf = -1;
		FS_Write(&buf, 4, newHandle);
		FS_Write(&buf, 4, newHandle);
		ret = qtrue;
	}
cuterror:
	//remove previosly converted demo from the same cut
	if (newHandle) {
		memset(newName, 0, sizeof(newName));
		if (demo.currentNum > 0) {
			Com_sprintf(newName, sizeof(newName), "mmedemos/%s.%d_cut.mme", oldName, demo.currentNum);
		} else {
			Com_sprintf(newName, sizeof(newName), "mmedemos/%s_cut.mme", oldName);
		}
		if (FS_FileExists(newName))
			FS_FileErase(newName);
	}
	FS_FCloseFile(oldHandle);
	FS_FCloseFile(newHandle);
	return ret;
}
예제 #27
0
bool BotLoadNavMesh( const char *filename, NavData_t &nav )
{
	char mapname[ MAX_QPATH ];
	char filePath[ MAX_QPATH ];
	char gameName[ MAX_STRING_CHARS ];
	fileHandle_t f = 0;

	BotLoadOffMeshConnections( filename, &nav );

	Cvar_VariableStringBuffer( "mapname", mapname, sizeof( mapname ) );
	Cvar_VariableStringBuffer( "fs_game", gameName, sizeof( gameName ) );
	Com_sprintf( filePath, sizeof( filePath ), "maps/%s-%s.navMesh", mapname, filename );
	Com_Printf( " loading navigation mesh file '%s'...\n", filePath );

	int len = FS_FOpenFileRead( filePath, &f, qtrue );

	if ( !f )
	{
		Com_Printf( S_COLOR_RED "ERROR: Cannot open Navigaton Mesh file\n" );
		return false;
	}

	if ( len < 0 )
	{
		Com_Printf( S_COLOR_RED "ERROR: Negative Length for Navigation Mesh file\n" );
		return false;
	}

	NavMeshSetHeader header;
	
	FS_Read( &header, sizeof( header ), f );

	SwapNavMeshSetHeader( header );

	if ( header.magic != NAVMESHSET_MAGIC )
	{
		Com_Printf( S_COLOR_RED "ERROR: File is wrong magic\n" );
		FS_FCloseFile( f );
		return false;
	}

	if ( header.version != NAVMESHSET_VERSION )
	{
		Com_Printf( S_COLOR_RED "ERROR: File is wrong version found: %d want: %d\n", header.version, NAVMESHSET_VERSION );
		FS_FCloseFile( f );
		return false;
	}

	nav.mesh = dtAllocNavMesh();

	if ( !nav.mesh )
	{
		Com_Printf( S_COLOR_RED "ERROR: Unable to allocate nav mesh\n" );
		FS_FCloseFile( f );
		return false;
	}

	dtStatus status = nav.mesh->init( &header.params );

	if ( dtStatusFailed( status ) )
	{
		Com_Printf( S_COLOR_RED "ERROR: Could not init navmesh\n" );
		dtFreeNavMesh( nav.mesh );
		nav.mesh = NULL;
		FS_FCloseFile( f );
		return false;
	}

	nav.cache = dtAllocTileCache();

	if ( !nav.cache )
	{
		Com_Printf( S_COLOR_RED "ERROR: Could not allocate tile cache\n" );
		dtFreeNavMesh( nav.mesh );
		nav.mesh = NULL;
		FS_FCloseFile( f );
		return false;
	}

	status = nav.cache->init( &header.cacheParams, &alloc, &comp, &nav.process );

	if ( dtStatusFailed( status ) )
	{
		Com_Printf( S_COLOR_RED "ERROR: Could not init tile cache\n" );
		dtFreeNavMesh( nav.mesh );
		dtFreeTileCache( nav.cache );
		nav.mesh = NULL;
		nav.cache = NULL;
		FS_FCloseFile( f );
		return false;
	}

	for ( int i = 0; i < header.numTiles; i++ )
	{
		NavMeshTileHeader tileHeader;

		FS_Read( &tileHeader, sizeof( tileHeader ), f );

		SwapNavMeshTileHeader( tileHeader );

		if ( !tileHeader.tileRef || !tileHeader.dataSize )
		{
			Com_Printf( S_COLOR_RED "ERROR: NUll Tile in navmesh\n" );
			dtFreeNavMesh( nav.mesh );
			dtFreeTileCache( nav.cache );
			nav.cache = NULL;
			nav.mesh = NULL;
			FS_FCloseFile( f );
			return false;
		}

		unsigned char *data = ( unsigned char * ) dtAlloc( tileHeader.dataSize, DT_ALLOC_PERM );

		if ( !data )
		{
			Com_Printf( S_COLOR_RED "ERROR: Failed to allocate memory for tile data\n" );
			dtFreeNavMesh( nav.mesh );
			dtFreeTileCache( nav.cache );
			nav.cache = NULL;
			nav.mesh = NULL;
			FS_FCloseFile( f );
			return false;
		}

		memset( data, 0, tileHeader.dataSize );

		FS_Read( data, tileHeader.dataSize, f );

		if ( LittleLong( 1 ) != 1 )
		{
			dtTileCacheHeaderSwapEndian( data, tileHeader.dataSize );
		}

		dtCompressedTileRef tile = 0;
		dtStatus status = nav.cache->addTile( data, tileHeader.dataSize, DT_TILE_FREE_DATA, &tile );

		if ( dtStatusFailed( status ) )
		{
			Com_Printf( S_COLOR_RED "ERROR: Failed to add tile to navmesh\n" );
			dtFree( data );
			dtFreeTileCache( nav.cache );
			dtFreeNavMesh( nav.mesh );
			nav.cache = NULL;
			nav.mesh = NULL;
			FS_FCloseFile( f );
			return false;
		}

		if ( tile )
		{
			nav.cache->buildNavMeshTile( tile, nav.mesh );
		}
	}

	FS_FCloseFile( f );
	return true;
}
예제 #28
0
 Rocket::Core::FileHandle Open(const Rocket::Core::String& filePath) {
     fileHandle_t fileHandle;
     FS_FOpenFileRead(filePath.CString(), &fileHandle, false);
     return (Rocket::Core::FileHandle) fileHandle;
 }
예제 #29
0
Rocket::Core::String Rocket_QuakeToRML(const char* in, int parseFlags = 0) {
    const char* p;
    Rocket::Core::String out;
    Rocket::Core::String spanstr;
    bool span = false;
    bool spanHasContent = false;

    if (!*in) {
        return "";
    }

    for (p = in; p && *p; ++p) {
        if (*p == '<') {
            if (span && !spanHasContent) {
                spanHasContent = true;
                out.Append(spanstr);
            }
            out.Append("&lt;");
        } else if (*p == '>') {
            if (span && !spanHasContent) {
                spanHasContent = true;
                out.Append(spanstr);
            }
            out.Append("&gt;");
        } else if (*p == '&') {
            if (span && !spanHasContent) {
                spanHasContent = true;
                out.Append(spanstr);
            }
            out.Append("&amp;");
        } else if (*p == '\n') {
            out.Append(span && spanHasContent ? "</span><br />" : "<br />");
            span = false;
            spanHasContent = false;
        } else if (Q_IsColorString(p)) {
            if (span && spanHasContent) {
                out.Append("</span>");
                span = false;
                spanHasContent = false;
            }

            char rgb[32];
            int code = ColorIndex(*++p);

            Com_sprintf(rgb, sizeof(rgb), "<span style='color: #%02X%02X%02X;'>", (int) (g_color_table[code][0] * 255), (int) (g_color_table[code][1] * 255), (int) (g_color_table[code][2] * 255));

            // don't add the span yet, because it might be empty
            spanstr = rgb;

            span = true;
            spanHasContent = false;
        } else {
            if (span && !spanHasContent) {
                out.Append(spanstr);
                spanHasContent = true;
            }
            out.Append(*p);
        }
    }

    if (span && spanHasContent) {
        out.Append("</span>");
    }

    // ^^ -> ^
    while (out.Find("^^") != Rocket::Core::String::npos) {
        out = out.Replace("^^", "^");
    }

    if (parseFlags & RP_EMOTICONS) {
        // Parse emoticons
        size_t openBracket = 0;
        size_t closeBracket = 0;
        size_t currentPosition = 0;

        while (1) {
            Rocket::Core::String emoticon;
            const char* path;

            openBracket = out.Find("[", currentPosition);
            if (openBracket == Rocket::Core::String::npos) {
                break;
            }

            closeBracket = out.Find("]", openBracket);
            if (closeBracket == Rocket::Core::String::npos) {
                break;
            }

            emoticon = out.Substring(openBracket + 1, closeBracket - openBracket - 1);

            // Certain characters are invalid
            if (emoticon.Empty() || IsInvalidEmoticon(emoticon)) {
                currentPosition = closeBracket + 1;
                continue;
            }

            // TODO: Dont hardcode the extension.
            path = va("emoticons/%s.crn", emoticon.CString());
            if (FS_FOpenFileRead(path, nullptr, true)) {
                out.Erase(openBracket, closeBracket - openBracket + 1);
                path = va("<img class='trem-emoticon' src='/emoticons/%s' />",
                          emoticon.CString());
                out.Insert(openBracket, path);
                currentPosition = openBracket + strlen(path) + 1;
            } else {
                currentPosition = closeBracket + 1;
            }
        }
    }

    return out;
}
예제 #30
0
파일: snd_dma.c 프로젝트: Izhido/qrevpak
/*
======================
S_StartBackgroundTrack
======================
*/
void S_StartBackgroundTrack( const char *intro, const char *loop ){
	int		len;
	char	dump[16];
	char	name[MAX_QPATH];

	if ( !intro ) {
		intro = "";
	}
	if ( !loop || !loop[0] ) {
		loop = intro;
	}
	Com_DPrintf( "S_StartBackgroundTrack( %s, %s )\n", intro, loop );

	Q_strncpyz( name, intro, sizeof( name ) - 4 );
	COM_DefaultExtension( name, sizeof( name ), ".wav" );

	if ( !intro[0] ) {
		return;
	}

	Q_strncpyz( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );

	// close the background track, but DON'T reset s_rawend
	// if restarting the same back ground track
	if ( s_backgroundFile ) {
		Sys_EndStreamedFile( s_backgroundFile );
		FS_FCloseFile( s_backgroundFile );
		s_backgroundFile = 0;
	}

	//
	// open up a wav file and get all the info
	//
	FS_FOpenFileRead( name, &s_backgroundFile, qtrue );
	if ( !s_backgroundFile ) {
		Com_Printf( S_COLOR_YELLOW "WARNING: couldn't open music file %s\n", name );
		return;
	}

	// skip the riff wav header

	FS_Read(dump, 12, s_backgroundFile);

	if ( !S_FindWavChunk( s_backgroundFile, "fmt " ) ) {
		Com_Printf( "No fmt chunk in %s\n", name );
		FS_FCloseFile( s_backgroundFile );
		s_backgroundFile = 0;
		return;
	}

	// save name for soundinfo
	s_backgroundInfo.format = FGetLittleShort( s_backgroundFile );
	s_backgroundInfo.channels = FGetLittleShort( s_backgroundFile );
	s_backgroundInfo.rate = FGetLittleLong( s_backgroundFile );
	FGetLittleLong(  s_backgroundFile );
	FGetLittleShort(  s_backgroundFile );
	s_backgroundInfo.width = FGetLittleShort( s_backgroundFile ) / 8;

	if ( s_backgroundInfo.format != WAV_FORMAT_PCM ) {
		FS_FCloseFile( s_backgroundFile );
		s_backgroundFile = 0;
		Com_Printf("Not a microsoft PCM format wav: %s\n", name);
		return;
	}

	if ( s_backgroundInfo.channels != 2 || s_backgroundInfo.rate != 22050 ) {
		Com_Printf(S_COLOR_YELLOW "WARNING: music file %s is not 22k stereo\n", name );
	}

	if ( ( len = S_FindWavChunk( s_backgroundFile, "data" ) ) == 0 ) {
		FS_FCloseFile( s_backgroundFile );
		s_backgroundFile = 0;
		Com_Printf("No data chunk in %s\n", name);
		return;
	}

	s_backgroundInfo.samples = len / (s_backgroundInfo.width * s_backgroundInfo.channels);

	s_backgroundSamples = s_backgroundInfo.samples;

	//
	// start the background streaming
	//
	Sys_BeginStreamedFile( s_backgroundFile, 0x10000 );
}