Beispiel #1
0
/**
 * @brief Generate a list of textures that should have footsteps when walking on them
 * @param[in] filename Add this texture to the list of
 * textures where we should have footstep sounds for
 * @param[in] mipTexIndex The index in the textures array
 * @sa SV_GetFootstepSound
 * @sa Com_GetTerrainType
 */
static void GenerateFootstepList (const char* filename, int mipTexIndex)
{
	if (!config.generateFootstepFile)
		return;

	if (textureref[mipTexIndex].footstepMarked)
		return;

	assert(filename);

	char fileBase[MAX_OSPATH];
	Com_StripExtension(filename, fileBase, sizeof(fileBase));

	ScopedFile f;
	FS_OpenFile(va("%s.footsteps", fileBase), &f, FILE_APPEND);
	if (!f) {
		Com_Printf("Could not open footstep file '%s.footsteps' for writing\n", fileBase);
		config.generateFootstepFile = false;
		return;
	}
#ifdef _WIN32
	FS_Printf(&f, "terrain %s {\n}\n\n", textureref[mipTexIndex].name);
#else
	FS_Printf(&f, "%s\n", textureref[mipTexIndex].name);
#endif
	footstepsCnt++;
	textureref[mipTexIndex].footstepMarked = true;
}
void R_LoadSkys (void)
{
	int	i, mark;
	FILE	*f;
	char	name[64], texname[20];

	for (i = 0; i < 6; i++)
	{
		q_snprintf (name, sizeof(name), "gfx/env/bkgtst%s.tga", suf[i]);
		FS_OpenFile (name, &f, false);
		if (!f)
		{
			Con_Printf ("Couldn't load %s\n", name);
			continue;
		}

		mark = Hunk_LowMark();
		LoadTGA (f);
	//	LoadPCX (f);

		q_snprintf (texname, sizeof(texname), "skybox%i", i);
		sky_tex[i] = GL_LoadTexture(texname, 256, 256, targa_rgba, false, false, 0, true);
		Hunk_FreeToLowMark(mark);

		glTexParameterf_fp(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max);
		glTexParameterf_fp(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
	}
}
Beispiel #3
0
/**
 * @brief Set the mn_slotX cvar to the comment (remove the date string) for clean
 * editing of the save comment
 * @sa SAV_GameReadGameComments_f
 */
static void SAV_GameSaveNameCleanup_f (void)
{
	int slotID;
	char cvar[16];
	qFILE f;
	saveFileHeader_t header;

	/* get argument */
	if (Cmd_Argc() < 2) {
		Com_Printf("Usage: %s <[0-7]>\n", Cmd_Argv(0));
		return;
	}

	slotID = atoi(Cmd_Argv(1));
	if (slotID < 0 || slotID > 7)
		return;

	FS_OpenFile(va("save/slot%i.%s", slotID, SAVEGAME_EXTENSION), &f, FILE_READ);
	if (!f.f && !f.z)
		return;

	/* read the comment */
	if (FS_Read(&header, sizeof(header), &f) != sizeof(header))
		Com_Printf("Warning: Savefile header may be corrupted\n");

	Com_sprintf(cvar, sizeof(cvar), "mn_slot%i", slotID);
	if (SAV_VerifyHeader(&header))
		Cvar_Set(cvar, header.name);
	else
		Cvar_Set(cvar, "");
	FS_CloseFile(&f);
}
Beispiel #4
0
static void WriteTGA24 (const char* filename, const byte*  data, int width, int height, int offset)
{
	const int size = width * height * 3;
	/* allocate a buffer and set it up */
	byte* buffer = Mem_AllocTypeN(byte, size + TGA_HEADER_SIZE);
	memset(buffer, 0, TGA_HEADER_SIZE);
	buffer[2] = 2;
	buffer[12] = width & 255;
	buffer[13] = width >> 8;
	buffer[14] = height & 255;
	buffer[15] = height >> 8;
	buffer[16] = 24;
	/* create top-down TGA */
	buffer[17] = 32;

	/* swap rgb to bgr */
	for (int i = 0; i < size; i += 3) {
		buffer[i + TGA_HEADER_SIZE] = data[i*2 + offset + 2];	/* blue */
		buffer[i + TGA_HEADER_SIZE + 1] = data[i*2 + offset + 1];	/* green */
		buffer[i + TGA_HEADER_SIZE + 2] = data[i*2 + offset + 0];	/* red */
	}

	/* write it and free the buffer */
	ScopedFile file;
	if (FS_OpenFile(filename, &file, FILE_WRITE) > 0)
		Sys_Error("Unable to open %s for writing", filename);

	FS_Write(buffer, size + TGA_HEADER_SIZE, &file);

	/* close the file */
	Mem_Free(buffer);
}
Beispiel #5
0
/*
-----------------------------------------------------------------------------
 Function: Cmd_Exec_f -Execute script file.
 
 Parameters: Nothing.            
 
 Returns: Nothing.
 
 Notes: Console function, exec <filename>

-----------------------------------------------------------------------------
*/
PRIVATE void Cmd_Exec_f( void )
{
	filehandle_t *hfile;
	char	*f2;
	int		len;

	if( Cmd_Argc () != 2 )
	{
		Com_Printf( "exec <filename> : execute a script file\n" );
		return;
	}

	hfile = FS_OpenFile( Cmd_Argv( 1 ), FA_FILE_IPHONE_DOC_DIR );
	if( ! hfile )
	{
		Com_Printf( "couldn't exec %s\n", Cmd_Argv( 1 ) );
		return;
	}

	len = FS_GetFileSize( hfile );

	Com_Printf( "execing %s\n", Cmd_Argv( 1 ) );
	
	// the file doesn't have a trailing 0, so we need to copy it off
	f2 = Z_Malloc( len + 1 );
	memcpy( f2, hfile->filedata, len );
	f2[ len ] = 0;

	printf( "%s", f2 );		// !@#
	Cbuf_InsertText( f2 );

	Z_Free( f2 );

	FS_CloseFile( hfile );
}
Beispiel #6
0
void CFG_Load(void)
{
	filehandle_t* cfgFile ;
	
	cfgFile = FS_OpenFile(CONFIG_FILENAME, "wrt");
	FS_UploadToRAM(cfgFile);

	if (!cfgFile)
	{
		Log_Printf("[CFG_Load] Unable to find player settings file, creating it.\n");
		CFG_Save();
		CFG_Load();
		return;
	}
	
	
	//Check the magic number
	if(strncmp(cfgFile->filedata, cfgMagicNumber, strlen(cfgMagicNumber)))
	{
		Log_Printf("[CFG_Load] Magic number check failed.\n");
		return;
	}
	
	//Reading visited act
	
	
	FS_CloseFile(cfgFile);
}
Beispiel #7
0
void MD2SkinEdit (const byte* buf, const char* fileName, int bufSize, void* userData)
{
	uint32_t numSkins;
	byte* const copy = Mem_Dup(byte, buf, bufSize);
	dMD2Model_t* md2 = (dMD2Model_t*)copy;
	char* md2Path;

	MD2HeaderCheck(md2, fileName, bufSize);

	md2Path = (char*) copy + LittleLong(md2->ofs_skins);
	numSkins = LittleLong(md2->num_skins);

	Com_Printf("  \\ - skins %i\n", numSkins);
	for (int i = 0; i < numSkins; i++) {
		char* name = md2Path + i * MD2_MAX_SKINNAME;
		Com_Printf("  \\ - skin %i: %s\n", i + 1, name);
		printf("  \\ - new skin: ");
		fflush(stdout);
		scanf(va("%%%is", MD2_MAX_SKINNAME), name);
	}

	ScopedFile md2ModelFile;
	FS_OpenFile(fileName, &md2ModelFile, FILE_WRITE);
	if (!md2ModelFile) {
		Com_Printf("Error writing md2 file %s\n", fileName);
		Mem_Free(copy);
		return;
	}
	FS_Write(copy, bufSize, &md2ModelFile);
	Mem_Free(copy);
}
Beispiel #8
0
/**
 * @note Both client and server can use this, and it will output
 * to the appropriate place.
 */
void Com_vPrintf (const char* fmt, va_list ap)
{
	char msg[MAXPRINTMSG];

	Q_vsnprintf(msg, sizeof(msg), fmt, ap);

	/* redirect the output? */
	if (rd_buffer) {
		if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) {
			NET_OOB_Printf(rd_stream, SV_CMD_PRINT "\n%s", rd_buffer);
			rd_buffer[0] = '\0';
		}
		Q_strcat(rd_buffer, sizeof(char) * rd_buffersize, "%s", msg);
		return;
	}

	Con_Print(msg);

	/* also echo to debugging console */
	Sys_ConsoleOutput(msg);

	/* logfile */
	if (logfile_active && logfile_active->integer) {
		if (!logfile.f) {
			if (logfile_active->integer > 2)
				FS_OpenFile(consoleLogName, &logfile, FILE_APPEND);
			else
				FS_OpenFile(consoleLogName, &logfile, FILE_WRITE);
		}
		if (logfile.f) {
			/* strip color codes */
			const char* output = msg;

			if (output[strlen(output) - 1] == '\n') {
				char timestamp[40];
				Com_MakeTimestamp(timestamp, sizeof(timestamp));
				FS_Write(timestamp, strlen(timestamp), &logfile);
				FS_Write(" ", 1, &logfile);
			}

			FS_Write(output, strlen(output), &logfile);

			if (logfile_active->integer > 1)
				fflush(logfile.f);	/* force it to save every time */
		}
	}
}
Beispiel #9
0
/**
 * @brief Generates material files in case the settings can be guessed from map file
 */
static void GenerateMaterialFile (const char* filename, int mipTexIndex, side_t* s)
{
	bool terrainByTexture = false;
	char fileBase[MAX_OSPATH], materialPath[MAX_OSPATH];

	if (!config.generateMaterialFile)
		return;

	/* we already have a material definition for this texture */
	if (textureref[mipTexIndex].materialMarked)
		return;

	assert(filename);

	Com_StripExtension(filename, fileBase, sizeof(fileBase));
	Com_sprintf(materialPath, sizeof(materialPath), "materials/%s.mat", Com_SkipPath(fileBase));

	ScopedFile f;
	FS_OpenFile(materialPath, &f, FILE_APPEND);
	if (!f) {
		Com_Printf("Could not open material file '%s' for writing\n", materialPath);
		config.generateMaterialFile = false;
		return;
	}

	if (strstr(textureref[mipTexIndex].name, "dirt")
	 || strstr(textureref[mipTexIndex].name, "rock")
	 || strstr(textureref[mipTexIndex].name, "grass")) {
		terrainByTexture = true;
	}

	if ((s->contentFlags & CONTENTS_TERRAIN) || terrainByTexture) {
		FS_Printf(&f, "{\n\tmaterial %s\n\t{\n\t\ttexture <fillme>\n\t\tterrain 0 64\n\t\tlightmap\n\t}\n}\n", textureref[mipTexIndex].name);
		textureref[mipTexIndex].materialMarked = true;
		materialsCnt++;
	}

	/* envmap for water surfaces */
	if ((s->contentFlags & CONTENTS_WATER)
	 || strstr(textureref[mipTexIndex].name, "glass")
	 || strstr(textureref[mipTexIndex].name, "window")) {
		FS_Printf(&f, "{\n\tmaterial %s\n\tspecular 2.0\n\t{\n\t\tenvmap 0\n\t}\n}\n", textureref[mipTexIndex].name);
		textureref[mipTexIndex].materialMarked = true;
		materialsCnt++;
	}

	if (strstr(textureref[mipTexIndex].name, "wood")) {
		FS_Printf(&f, "{\n\tmaterial %s\n\tspecular 0.2\n}\n", textureref[mipTexIndex].name);
		textureref[mipTexIndex].materialMarked = true;
		materialsCnt++;
	}

	if (strstr(textureref[mipTexIndex].name, "wall")) {
		FS_Printf(&f, "{\n\tmaterial %s\n\tspecular 0.6\n\tbump 2.0\n}\n", textureref[mipTexIndex].name);
		textureref[mipTexIndex].materialMarked = true;
		materialsCnt++;
	}
}
Beispiel #10
0
void dEngine_WriteScreenshot(char* directory)
{
	
	int i;//,j;
	filehandle_t* pScreenshot;
	char fullPath[256];
	
	uchar tga_header[18];
	uchar* pixel;
	uchar tmpChannel;
	
	/*
	char num[64];
	sprintf(num, "scene%05d_t=%05d",engine.sceneId, simulationTime);
	memset(fullPath, 256, sizeof(char));
	strcat(fullPath,directory);
	strcat(fullPath,num);
	strcat(fullPath,".tga");
	*/
	fullPath[0] = '\0';
	sprintf(fullPath,"%sscene%05d_t=%05d.tga",directory,engine.sceneId, simulationTime);
	
	
	
	
	SCR_GetColorBuffer(screenShotBuffer);
	
	pScreenshot = FS_OpenFile(fullPath, "wb");
	
	memset(tga_header, 0, 18);
	tga_header[2] = 2;
	tga_header[12] = (renderer.glBuffersDimensions[WIDTH] & 0x00FF);
	tga_header[13] = (renderer.glBuffersDimensions[WIDTH]  & 0xFF00) / 256; // /256
	tga_header[14] = (renderer.glBuffersDimensions[HEIGHT]  & 0x00FF) ;
	tga_header[15] =(renderer.glBuffersDimensions[HEIGHT] & 0xFF00) / 256;
	tga_header[16] = 32 ;
	
	
	
	FS_Write(&tga_header, 18, sizeof(uchar), pScreenshot);
	
	// RGB > BGR
	pixel = screenShotBuffer;
	for(i=0 ; i < renderer.glBuffersDimensions[WIDTH] * renderer.glBuffersDimensions[HEIGHT] ; i++)
	{
		tmpChannel = pixel[0];
		pixel[0] = pixel[2];
		pixel[2] = tmpChannel;
		
		pixel += 4;
	}
	
	
	FS_Write(screenShotBuffer, renderer.glBuffersDimensions[WIDTH] * renderer.glBuffersDimensions[HEIGHT], 4 * sizeof(uchar), pScreenshot);
	
	FS_CloseFile(pScreenshot);
	
}
Beispiel #11
0
/**
 * \brief OGG read Callback.
 * \param[in] name File name to open.
 * \param[in/out] Music track data structure.
 * \return False on error, otherwise true.
 * \note
 */
PRIVATE _boolean Sound_OpenBGTrack( const char *name, musicTrack_t *track )
{
	OggVorbis_File	*vorbisFile;
	vorbis_info		*vorbisInfo;
	ov_callbacks	vorbisCallbacks = {ovc_read, ovc_seek, ovc_close, ovc_tell};
	int ret;

	track->hFile = FS_OpenFile( name, 0 );
	if( ! track->hFile )
	{
		return false;
	}


	track->vorbisFile = vorbisFile = Z_Malloc( sizeof( OggVorbis_File ) );

	if( (ret = ov_open_callbacks( track, vorbisFile, NULL, 0, vorbisCallbacks )) < 0 )
	{
		switch( ret )
		{
			case OV_EREAD:
				Com_DPrintf( "A read from media returned an error.(%s)\n", name );
				break;
			case OV_ENOTVORBIS:
				Com_DPrintf( "Bitstream is not Vorbis data.(%s)\n", name );
				break;
			case OV_EVERSION:
				Com_DPrintf( "Vorbis version mismatch.(%s)\n", name );
				break;
			case OV_EBADHEADER:
				Com_DPrintf( "Invalid Vorbis bitstream header.(%s)\n", name );
				break;
			case OV_EFAULT:
				Com_DPrintf( "Internal logic fault; indicates a bug or heap/stack corruption.(%s)\n", name );
				break;

		}
		Com_DPrintf( "Could not open OGG stream (%s)\n", name );

		return false;
	}

	vorbisInfo = ov_info( vorbisFile, -1 );
	if( vorbisInfo->channels != 1 && vorbisInfo->channels != 2 )
	{
		Com_DPrintf( "Only mono and stereo OGG files supported (%s)\n", name );

		return false;
	}

	track->start = ov_raw_tell( vorbisFile );
	track->rate = vorbisInfo->rate;
	track->format = (vorbisInfo->channels == 2) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;

	return true;
}
Beispiel #12
0
/**
 * @sa LoadMapFile
 * @sa FixErrors
 */
void WriteMapFile (const char* filename)
{
	int removed;

	Verb_Printf(VERB_NORMAL, "writing map: '%s'\n", filename);

	ScopedFile f;
	FS_OpenFile(filename, &f, FILE_WRITE);
	if (!f)
		Sys_Error("Could not open %s for writing", filename);

	removed = 0;
	FS_Printf(&f, "\n");
	for (int i = 0; i < num_entities; i++) {
		const entity_t* mapent = &entities[i];
		const epair_t* e = mapent->epairs;

		/* maybe we don't want to write it back into the file */
		if (mapent->skip) {
			removed++;
			continue;
		}
		FS_Printf(&f, "// entity %i\n{\n", i - removed);
		WriteMapEntities(&f, e);

		/* need 2 counters. j counts the brushes in the source entity.
		 * jc counts the brushes written back. they may differ if some are skipped,
		 * eg they are microbrushes */
		int j, jc;
		for (j = 0, jc = 0; j < mapent->numbrushes; j++) {
			const mapbrush_t* brush = &mapbrushes[mapent->firstbrush + j];
			if (brush->skipWriteBack)
				continue;
			WriteMapBrush(brush, jc++, &f);
		}

		/* add brushes from func_groups with single members to worldspawn */
		if (i == 0) {
			int numToAdd;
			mapbrush_t** brushesToAdd = Check_ExtraBrushesForWorldspawn(&numToAdd);
			if (brushesToAdd != nullptr) {
				for (int k = 0; k < numToAdd; k++) {
					if (brushesToAdd[k]->skipWriteBack)
						continue;
					WriteMapBrush(brushesToAdd[k], j++, &f);
				}
				Mem_Free(brushesToAdd);
			}
		}
		FS_Printf(&f, "}\n");
	}

	if (removed)
		Verb_Printf(VERB_NORMAL, "removed %i entities\n", removed);
}
Beispiel #13
0
void* Util_LoadFileToBuffer(char* path, uint32_t* size)
{
	FSFile file;
	FS_InitFile(&file);
	FS_OpenFile(&file, path);
	uint32_t mSize = FS_GetLength(&file);
	void* buffer = NNS_FndAllocFromExpHeapEx(mHeapHandle, mSize, 16);
	FS_ReadFile(&file, buffer, (int)mSize);
	FS_CloseFile(&file);
	if(size != NULL) *size = mSize;
	return buffer;
}
Beispiel #14
0
static bool SL_CreatePNGFile (const char* filename, unsigned char* buffer, int width, int height)
{
	ScopedFile f;

	/* create the .bmp file... */
	if (FS_OpenFile(filename, &f, FILE_WRITE) == -1)
		return false;

	R_WritePNG(&f, buffer, width, height);

	return true;
}
Beispiel #15
0
void CFG_Save(void)
{
	filehandle_t* cfgFile ;
	
	cfgFile = FS_OpenFile(CONFIG_FILENAME, "wt");
	FS_UploadToRAM(cfgFile);
	//Writing the magic number
	fwrite(cfgMagicNumber,1,strlen(cfgMagicNumber), cfgFile->hFile);
	
	//Writing visited act
	
	FS_CloseFile(cfgFile);
}
Beispiel #16
0
Datei: fs.c Projekt: deurk/qwfwd
char *FS_ReadFile(char *gamedir, char *filename, char *buf, int *size)
{
	FILE *f = NULL;
	int buf_size;

	if (!size)
		return NULL; // we need return filesize somehow, so this is not valid

	if (buf) // using pre alloced by user buffer
	{
		if (size[0] < 1)
		{
			size[0] = -1;
			return NULL; // specified buffer not valid, zero or less sized
		}

		buf_size = size[0]; // greater than zero, valid
	}
	else
		buf_size = 0; // this trigger use of Sys_malloc() below

	if (!(f = FS_OpenFile(gamedir, filename, size)))
		return NULL;

	if (buf_size) // using pre alloced by user buffer
	{
		if (buf_size < size[0] + 1) // can't fit file in user buffer, count null terminator too
		{
			fclose(f);
			size[0] = -1;
			return NULL;
		}
	}
	else // malloc buffer
	{
		buf_size = size[0] + 1; // space for null terminator, quake style
		buf	= Sys_malloc(buf_size);
	}

	if (fread(buf, size[0], 1, f) != 1)
	{ // read error
		fclose(f);
		size[0] = -1;
		return NULL;
	}

	fclose(f); // do not need it anymore

	buf[size[0]] = 0;
	return buf;
}
Beispiel #17
0
static qboolean SL_CreatePNGFile (const char *filename, unsigned char *buffer, int width, int height)
{
	qFILE f;

	/* create the .bmp file... */
	if (FS_OpenFile(filename, &f, FILE_WRITE) == -1)
		return qfalse;

	R_WritePNG(&f, buffer, width, height);

	FS_CloseFile(&f);

	return qtrue;
}
Beispiel #18
0
/**
 * @brief Checks whether there is a quicksave file and opens the quickload menu if there is one
 * @note This does not work while we are in the battlescape
 */
static void SAV_GameQuickLoadInit_f (void)
{
	qFILE f;

	if (cgi->CL_OnBattlescape()) {
		return;
	}

	FS_OpenFile(va("save/slotquick.%s", SAVEGAME_EXTENSION), &f, FILE_READ);
	if (f.f || f.z) {
		cgi->UI_PushWindow("quickload");
		FS_CloseFile(&f);
	}
}
Beispiel #19
0
void R_ReadPointFile_f (void)
{
	FILE	*f;
	vec3_t	org;
	int		r;
	int		c;
	particle_t	*p;
	char	name[MAX_QPATH];
	byte	color;

	if (cls.state != ca_connected)
		return; // need an active map.

	color = (byte)Cvar_VariableValue("leak_color");
	q_snprintf (name, sizeof(name), "maps/%s.pts", cl.mapname);

	FS_OpenFile (name, &f, NULL);
	if (!f)
	{
		Con_Printf ("couldn't open %s\n", name);
		return;
	}

	Con_Printf ("Reading %s...\n", name);
	c = 0;
	VectorClear (org); // silence pesky compiler warnings
	for ( ;; )
	{
		r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
		if (r != 3)
			break;
		c++;

		p = AllocParticle();
		if (!p)
		{
			Con_Printf ("Not enough free particles\n");
			break;
		}

		p->die = 99999;
		p->color = color; // (-c)&15;
		p->type = pt_static;
		VectorClear (p->vel);
		VectorCopy (org, p->org);
	}

	fclose (f);
	Con_Printf ("%i points read\n", c);
}
Beispiel #20
0
/**
 * @sa Key_WriteBindings
 */
void Com_WriteConfigToFile (const char* filename)
{
	ScopedFile f;

	FS_OpenFile(filename, &f, FILE_WRITE);
	if (!f.file()) {
		Com_Printf("Couldn't write %s.\n", filename);
		return;
	}

	FS_Printf(&f, "// generated by ufo, do not modify\n");
	FS_Printf(&f, "// variables\n");
	Cvar_WriteVariables(&f);
	FS_Printf(&f, "// aliases\n");
	Cmd_WriteAliases(&f);
	Com_Printf("Wrote %s.\n", filename);
}
Beispiel #21
0
void CAM_StartPlaying(char* filename)
{
	uint i;	
	filehandle_t* file ;
	uchar isCP1 = 0;
	
	file = FS_OpenFile(filename, "rt");
	
	if (!file)
		return;
	
	isCP1 = (*file->ptrStart == 'c' && *(file->ptrStart+1) == 'p' && *(file->ptrStart+2) == '1') ;
	
	if (!isCP1)
	{
		printf("Camera path is not a valid file:");
		return;
	}
	
	LE_init(file);
	
	LE_readToken(); //CP1
	LE_readToken(); //num_frames
	
	
	
	camera.path.num_frames = LE_readReal();
	
	camera.path.frames = CAM_ReadFrameFromFile();
	camera.path.frames->next = 0;
	camera.path.currentFrame = camera.path.frames;
	
	for(i=1 ; i < camera.path.num_frames ; i++)
	{
		camera.path.currentFrame->next = CAM_ReadFrameFromFile();
		camera.path.currentFrame = camera.path.currentFrame->next;
		camera.path.currentFrame->next = 0;
	}
							  
	camera.playing = 1;
	camera.path.currentFrame = camera.path.frames;
	strcpy(camera.recordFilename, filename);
	simulationTime = camera.path.frames[0].time;
	
	FS_CloseFile(file);
}
Beispiel #22
0
PakFileHandle DevAssetManager::OpenFile( ObjectGUIDArg fileGuid )
{
	if( fileGuid.IsNull() ) {
		return BadPakFileHandle;
	}

	const SAssetInfo* pAssetInfo = this->Find_Asset_Info_By_Guid( fileGuid );
	const String fileName = m_pathToBinAssets + pAssetInfo->binFileName.ToChars();

	const FileHandle fileHandle = FS_OpenFile( fileName, EAccessMode::ReadAccess );

	if( fileHandle == InvalidFileHandle ) {
		mxErrf("Failed to open file '%s' for reading.\n", fileName.ToChars());
		return BadPakFileHandle;
	}

	return OS_To_Pak_File_Handle( fileHandle );
}
Beispiel #23
0
/**
 * @note not moved into V_UI_NODEMETHOD because it is more a generic
 * tool than a method of the node editor
 */
static void UI_EditorNodeExtract_f (void)
{
	if (Cmd_Argc() != 2) {
		Com_Printf("Usage: %s <windowname>\n", Cmd_Argv(0));
		return;
	}
	uiNode_t* window = UI_GetWindow(Cmd_Argv(1));
	if (!window) {
		Com_Printf("Window '%s' not found\n", Cmd_Argv(1));
		return;
	}

	ScopedFile file;
	FS_OpenFile(va("window_%s_extracted.ufo", window->name), &file, FILE_WRITE);
	UI_EditorNodeExtractNode(&file, window, 0);

	Com_Printf("Window '%s' extracted.\n", Cmd_Argv(1));
}
Beispiel #24
0
static int MID2STREAM_fileopen(const char *filename)
{
	FILE *handle;
	qboolean pak;
	size_t length;

	length = FS_OpenFile(filename, &handle, NULL);
	pak = file_from_pak;
	if (length == (size_t)-1)
		return -1;

	midi_fh.file = handle;
	midi_fh.start = ftell(handle);
	midi_fh.pos = 0;
	midi_fh.length = (long)length;
	midi_fh.pak = pak;
	return 0;
}
Beispiel #25
0
/**
 * @brief Swaps the bsp file in place, so it should not be referenced again
 * @sa LoadBSPFile
 */
long WriteBSPFile (const char* filename)
{
    dBspHeader_t outheader;
    long size;

    OBJZERO(outheader);

    SwapBSPFile();

    outheader.ident = LittleLong(IDBSPHEADER);
    outheader.version = LittleLong(BSPVERSION);

    ScopedFile bspfile;
    FS_OpenFile(filename, &bspfile, FILE_WRITE);
    if (!bspfile)
        Sys_Error("Could not write bsp file");
    FS_Write(&outheader, sizeof(outheader), &bspfile);	/* overwritten later */

    AddLump(&bspfile, &outheader, LUMP_PLANES, curTile->planes, curTile->numplanes * sizeof(dBspPlane_t));
    AddLump(&bspfile, &outheader, LUMP_LEAFS, curTile->leafs, curTile->numleafs * sizeof(dBspLeaf_t));
    AddLump(&bspfile, &outheader, LUMP_VERTEXES, curTile->vertexes, curTile->numvertexes * sizeof(dBspVertex_t));
    AddLump(&bspfile, &outheader, LUMP_NORMALS, curTile->normals, curTile->numnormals * sizeof(dBspNormal_t));
    AddLump(&bspfile, &outheader, LUMP_NODES, curTile->nodes, curTile->numnodes * sizeof(dBspNode_t));
    AddLump(&bspfile, &outheader, LUMP_TEXINFO, curTile->texinfo, curTile->numtexinfo * sizeof(dBspTexinfo_t));
    AddLump(&bspfile, &outheader, LUMP_FACES, curTile->faces, curTile->numfaces * sizeof(dBspSurface_t));
    AddLump(&bspfile, &outheader, LUMP_BRUSHES, curTile->dbrushes, curTile->numbrushes * sizeof(dBspBrush_t));
    AddLump(&bspfile, &outheader, LUMP_BRUSHSIDES, curTile->brushsides, curTile->numbrushsides * sizeof(dBspBrushSide_t));
    AddLump(&bspfile, &outheader, LUMP_LEAFBRUSHES, curTile->leafbrushes, curTile->numleafbrushes * sizeof(curTile->leafbrushes[0]));
    AddLump(&bspfile, &outheader, LUMP_SURFEDGES, curTile->surfedges, curTile->numsurfedges * sizeof(curTile->surfedges[0]));
    AddLump(&bspfile, &outheader, LUMP_EDGES, curTile->edges, curTile->numedges * sizeof(dBspEdge_t));
    AddLump(&bspfile, &outheader, LUMP_MODELS, curTile->models, curTile->nummodels * sizeof(dBspModel_t));
    AddLump(&bspfile, &outheader, LUMP_LIGHTING_NIGHT, curTile->lightdata[0], curTile->lightdatasize[0]);
    AddLump(&bspfile, &outheader, LUMP_LIGHTING_DAY, curTile->lightdata[1], curTile->lightdatasize[1]);
    AddLump(&bspfile, &outheader, LUMP_ROUTING, curTile->routedata, curTile->routedatasize);
    AddLump(&bspfile, &outheader, LUMP_ENTITIES, curTile->entdata, curTile->entdatasize);
    size = ftell(bspfile.getFile());

    fseek(bspfile.getFile(), 0L, SEEK_SET);
    FS_Write(&outheader, sizeof(outheader), &bspfile);

    SwapBSPFile();

    return size;
}
Beispiel #26
0
/**
 * @brief Reads the comments from team files
 */
void GAME_TeamSlotComments_f (void)
{
	UI_ExecuteConfunc("teamsaveslotsclear");

	char relSavePath[MAX_OSPATH];
	GAME_GetRelativeSavePath(relSavePath, sizeof(relSavePath));
	char pattern[MAX_OSPATH];
	Q_strncpyz(pattern, relSavePath, sizeof(pattern));
	Q_strcat(pattern, sizeof(pattern), "*.mpt");

	FS_BuildFileList(pattern);
	int i = 0;
	const char* filename;
	while ((filename = FS_NextFileFromFileList(pattern)) != nullptr) {
		ScopedFile f;
		const char* savePath = va("%s/%s", relSavePath, filename);
		FS_OpenFile(savePath, &f, FILE_READ);
		if (!f) {
			Com_Printf("Warning: Could not open '%s'\n", filename);
			continue;
		}
		teamSaveFileHeader_t header;
		const int clen = sizeof(header);
		if (FS_Read(&header, clen, &f) != clen) {
			Com_Printf("Warning: Could not read %i bytes from savefile\n", clen);
			continue;
		}
		if (LittleLong(header.version) != TEAM_SAVE_FILE_VERSION) {
			Com_Printf("Warning: Version mismatch in '%s'\n", filename);
			continue;
		}

		char absSavePath[MAX_OSPATH];
		GAME_GetAbsoluteSavePath(absSavePath, sizeof(absSavePath));
		const bool uploadable = FS_FileExists("%s/%s", absSavePath, filename);
		UI_ExecuteConfunc("teamsaveslotadd %i \"%s\" \"%s\" %i %i", i++, filename, header.name, LittleLong(header.soldiercount), uploadable ? 1 : 0);
	}
	FS_NextFileFromFileList(nullptr);
}
Beispiel #27
0
/**
 * @brief Init menu cvar for one savegame slot given by actual index.
 * @param[in] idx the savegame slot to retrieve gamecomment for
 * @sa SAV_GameReadGameComments_f
 */
static void SAV_GameReadGameComment (const int idx)
{
	saveFileHeader_t header;
	qFILE f;

	FS_OpenFile(va("save/slot%i.%s", idx, SAVEGAME_EXTENSION), &f, FILE_READ);
	if (f.f || f.z) {
		if (FS_Read(&header, sizeof(header), &f) != sizeof(header))
			Com_Printf("Warning: Savefile header may be corrupted\n");

		header.compressed = LittleLong(header.compressed);
		header.version = LittleLong(header.version);
		header.xmlSize = LittleLong(header.xmlSize);
		header.subsystems = LittleLong(header.subsystems);

		if (!SAV_VerifyHeader(&header))
			Com_Printf("Savegame header for slot%d is corrupted!\n", idx);
		else
			cgi->UI_ExecuteConfunc("update_save_game_info %i \"%s\" \"%s\" \"%s\"", idx, header.name, header.gameDate, header.realDate);

		FS_CloseFile(&f);
	}
}
Beispiel #28
0
void MD2SkinNum (const byte* buf, const char* fileName, int bufSize, void* userData)
{
	byte* copy = Mem_Dup(byte, buf, bufSize);
	dMD2Model_t* md2 = (dMD2Model_t*)copy;

	MD2HeaderCheck(md2, fileName, bufSize);

	const uint32_t numSkins = LittleLong(md2->num_skins);

	const uint32_t ofsST = LittleLong(md2->ofs_st);
	const uint32_t ofsTris = LittleLong(md2->ofs_tris);
	const uint32_t ofsFrames = LittleLong(md2->ofs_frames);
	const uint32_t ofsGLCmds = LittleLong(md2->ofs_glcmds);
	const uint32_t ofsEnd = LittleLong(md2->ofs_end);
	const uint32_t ofsSkins = LittleLong(md2->ofs_skins);

	uint32_t moveOffset = ofsEnd;
#define CHECKMAX(val) 	if ((val) > ofsSkins && (val) < moveOffset) moveOffset = (val);
	CHECKMAX(ofsST);
	CHECKMAX(ofsTris);
	CHECKMAX(ofsFrames);
	CHECKMAX(ofsGLCmds);
	CHECKMAX(ofsSkins);
#undef CHECKMAX

	Com_Printf("  \\ - skins %i\n", numSkins);
	int newSkins = 0;
	printf("  \\ - new skin number: ");
	fflush(stdout);
	scanf("%i", &newSkins);
	if (newSkins <= 0) {
		Com_Printf("A model must have a skin\n");
		Mem_Free(copy);
		return;
	}
	if (newSkins > MD2_MAX_SKINS) {
		Com_Printf("Only %i skins are allowed\n", MD2_MAX_SKINS);
		Mem_Free(copy);
		return;
	}

	if (newSkins == numSkins) {
		Mem_Free(copy);
		return;
	}

	const int32_t deltaSkins = newSkins - numSkins;
	const int32_t offsetDelta = deltaSkins * MD2_MAX_SKINNAME;
	if (ofsST > ofsSkins)
		md2->ofs_st = LittleLong(ofsST + offsetDelta);
	if (ofsTris > ofsSkins)
		md2->ofs_tris = LittleLong(ofsTris + offsetDelta);
	if (ofsFrames > ofsSkins)
		md2->ofs_frames = LittleLong(ofsFrames + offsetDelta);
	if (ofsGLCmds > ofsSkins)
		md2->ofs_glcmds = LittleLong(ofsGLCmds + offsetDelta);
	md2->ofs_end = LittleLong(ofsEnd + offsetDelta);
	md2->num_skins = LittleLong(newSkins);

	Com_Printf("change to %i skins\n", newSkins);
	if (deltaSkins > 0) {
		copy = (byte*)Mem_ReAlloc(copy, md2->ofs_end);
		md2 = (dMD2Model_t*)copy;
	}

	const int n = ofsEnd - moveOffset;
	byte* from = copy + moveOffset;
	byte* to = from + offsetDelta;
	memmove(to, from, n);

	if (deltaSkins > 0) {
		char*  md2Path = (char*) copy + LittleLong(md2->ofs_skins);
		for (int i = numSkins; i < numSkins + deltaSkins; i++) {
			char* name = md2Path + i * MD2_MAX_SKINNAME;
			memset(name, 0, MD2_MAX_SKINNAME);
			strcpy(name, ".none");
			Com_Printf("  \\ - skin %i: %s\n", i + 1, name);
			printf("  \\ - new skin: ");
			fflush(stdout);
			scanf(va("%%%is", MD2_MAX_SKINNAME), name);
		}
	}
	ScopedFile md2ModelFile;
	FS_OpenFile(fileName, &md2ModelFile, FILE_WRITE);
	if (!md2ModelFile) {
		Com_Printf("Error writing md2 file %s\n", fileName);
		Mem_Free(copy);
		return;
	}
	FS_Write(copy, md2->ofs_end, &md2ModelFile);
	Mem_Free(copy);
}
/*
 ==================
 CIN_PlayCinematic

 TODO: read the .cin file header
 TODO: fill in cinematic_t
 ==================
*/
int	CIN_PlayCinematic (const char *name, int flags){

	cinematic_t		*cin;
	fileHandle_t	file;
	byte			buffer[ROQ_CHUNK_HEADER_SIZE];
	word			id, fps;
	char			checkName[MAX_PATH_LENGTH], loadName[MAX_PATH_LENGTH];
	bool			isRoQ;
	int				handle;
	int				size;
	int				i;

	// Check if already playing
	for (i = 0, cin = cin_cinematics; i < MAX_CINEMATICS; i++, cin++){
		if (!cin->playing)
			continue;

		if (!Str_ICompare(cin->name, name)){
			if (cin->flags != flags)
				continue;

			return i + 1;
		}
	}

	// Get a free handle
	cin = CIN_HandleForCinematic(&handle);

	if (flags & CIN_SYSTEM){
		cls.playingCinematic = true;

		S_StopAllSounds();

		Com_Printf("Playing cinematic %s\n", name);
	}

	// Strip file extension
	Str_Copy(checkName, name, sizeof(checkName));
	Str_StripFileExtension(checkName);

	// Check for a static PCX image
	Str_SPrintf(loadName, sizeof(loadName), "%s.pcx", checkName);

	if (FS_FileExists(loadName)){
		if (!CIN_LoadPCX(cin, checkName, flags))
			return 0;

		return handle;
	}

	// Open the file
	Str_SPrintf(loadName, sizeof(loadName), "%s.RoQ", checkName);

	size = FS_OpenFile(loadName, FS_READ, &file);
	if (file)
		isRoQ = true;
	else {
		Str_SPrintf(loadName, sizeof(loadName), "%s.cin", checkName);

		size = FS_OpenFile(loadName, FS_READ, &file);
		if (file)
			isRoQ = false;
		else {
			if (flags & CIN_SYSTEM){
				cls.playingCinematic = false;

				Com_Printf("Cinematic %s not found\n", name);
			}

			return 0;
		}
	}

	if (isRoQ){
		// Read the file header
		FS_Read(file, buffer, ROQ_CHUNK_HEADER_SIZE);

		id = buffer[0] | (buffer[1] << 8);
		fps = buffer[6] | (buffer[7] << 8);

		if (id != ROQ_ID){
			FS_CloseFile(file);

			if (flags & CIN_SYSTEM){
				cls.playingCinematic = false;

				Com_Printf("Cinematic %s is not a RoQ file\n", name);
			}

			return 0;
		}

		// Fill it in
		cin->playing = true;

		cin->isRoQ = isRoQ;

		Str_Copy(cin->name, name, sizeof(cin->name));
		cin->flags = flags;

		cin->file = file;
		cin->size = size;
		cin->offset = ROQ_CHUNK_HEADER_SIZE;

		cin->startTime = 0;

		cin->frameRate = (fps) ? fps : 30;

		cin->frameCount = 0;
	}
	else {
		// Read the file header

		// Fill it in
		cin->playing = true;

		cin->isRoQ = isRoQ;

		Str_Copy(cin->name, name, sizeof(cin->name));
		cin->flags = flags;

		cin->file = file;
		cin->size = size;
		cin->offset = 20;

		cin->startTime = 0;

		cin->frameRate = 14;

		cin->frameCount = 0;
	}

	return handle;
}
Beispiel #30
0
void dEngine_ReadConfig(void)
{
	filehandle_t* config;
	int currentSceneId=0;
	
    
    
	config = FS_OpenFile(CONFIG_PATH, "rt");
	FS_UploadToRAM(config);
	
	if (!config)
	{
		Log_Printf("Configuration file: data/config.cfg not found");
		exit(0);
	}
	
	//renderer.resolution = 1;

	LE_pushLexer();
	LE_init(config);
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();

		if (!strcmp("scenes", LE_getCurrentToken()))
		{
			LE_readToken(); // {
			LE_readToken(); // numScenes
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("numScenes", LE_getCurrentToken()))
				{
					engine.numScenes = LE_readReal();
				}
				else 
				if (!strcmp("scene", LE_getCurrentToken()))
				{
					currentSceneId = LE_readReal();
					
					LE_readToken(); //The name of the scene, here only to help developer to keep track of config.cfg
					strReplace(LE_getCurrentToken(), '_', ' ');
					strcpy(engine.scenes[currentSceneId].name, LE_getCurrentToken());
					
					LE_readToken();
					strcpy(engine.scenes[currentSceneId].path, LE_getCurrentToken());
					
					Log_Printf("Read scene %d, name %s, path %s\n",currentSceneId,engine.scenes[currentSceneId].name,engine.scenes[currentSceneId].path);
					
					
				}
				
				LE_readToken();
				
			}
		}
		else if (!strcmp("fx", LE_getCurrentToken()))
		{
			LE_readToken(); //{
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				LE_readToken();
				
				if (!strcmp("impactTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//			explosionTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(explosionTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("smokeTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//				smokeTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(smokeTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("ghostTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//				ghostTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(ghostTexture.path, LE_getCurrentToken());
				}
			}
		}
		/*
		else if (!strcmp("video", LE_getCurrentToken()))
		{
			
			LE_readToken(); // {
			LE_readToken();
			while (strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("record", LE_getCurrentToken()))
				{
					engine.recordVideo = LE_readReal();
				}
				LE_readToken();
			}
		}
		*/
		else if (!strcmp("players", LE_getCurrentToken()))
		{
			LE_readToken();	//{
			LE_readToken();
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("model1", LE_getCurrentToken()))
				{
					LE_readToken();
					strcpy(players[1].modelPath, LE_getCurrentToken());
				}
				else 
				if (!strcmp("model0", LE_getCurrentToken()))
				{
					LE_readToken();
					strcpy(players[0].modelPath, LE_getCurrentToken());
				}
				else 
					if (!strcmp("bulletTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
//					bulletConfig.bulletTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(bulletConfig.bulletTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("ttl", LE_getCurrentToken()))
				{
					bulletConfig.ttl = LE_readReal();
				}
				else 
				if (!strcmp("heightRatio", LE_getCurrentToken()))
				{
					bulletConfig.heightRatio = LE_readReal();
				}
				else 
				if (!strcmp("widthRatio", LE_getCurrentToken()))
				{
					bulletConfig.widthRatio = LE_readReal();
				}
				else 
				if (!strcmp("screenSpaceXDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.screenSpaceXDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("screenSpaceYDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.screenSpaceYDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashHeightRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashHeightRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashWidthRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashWidthRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashScreenSpaceXDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashScreenSpaceXDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashScreenSpaceYDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashScreenSpaceYDeltaRatio = LE_readReal();
				}
				
				LE_readToken();
			}
			
		}
		
	}
	
	
	LE_popLexer();
	FS_CloseFile(config);
	
	
}