//
// This method handles parsing a single file, it can be called
//  many times if a wildcard path was passed to InitParser.
// Input: pszFilePath - FS path to a KeyValue file for parsing.
//		  bWildcard - Is this file the only one to be parsed? or will more come...
//
bool CScriptParser::ParseFile( const char *pszFilePath )
{
	// Load the file into a buffer (null-terminated)
	char *buffer = (char*) UTIL_LoadFileForMe( pszFilePath, NULL );
	if ( !buffer )
		return false;

	// If we are encrypted, decrypt us
	const char *fileName = Q_UnqualifiedFileName( pszFilePath );
	if( CompareExtensions( fileName, GetEncryptedEXT() ) )
		UTIL_DecodeICE( (unsigned char*)buffer, Q_strlen(buffer), g_pGameRules->GetEncryptionKey() );

	// Remove the extension
	char fileNameNoExt[64];
	Q_StripExtension( fileName, fileNameNoExt, 64 );

	KeyValues *pKV = new KeyValues( fileNameNoExt );
	if( !pKV->LoadFromBuffer( fileNameNoExt, buffer ) )
	{
		pKV->deleteThis();
		delete [] buffer;
		return false;
	}

	Parse( pKV, fileNameNoExt );

	pKV->deleteThis();
	delete[] buffer;
	return true;
}
//-----------------------------------------------------------------------------
// Purpose: Parses the vehicle's script for the vehicle view parameters
//-----------------------------------------------------------------------------
bool CPropVehicleChoreoGeneric::ParseViewParams( const char *pScriptName )
{
	byte *pFile = UTIL_LoadFileForMe( pScriptName, NULL );
	if ( !pFile )
		return false;

	IVPhysicsKeyParser *pParse = physcollision->VPhysicsKeyParserCreate( (char *)pFile );
	CVehicleChoreoViewParser viewParser;
	while ( !pParse->Finished() )
	{
		const char *pBlock = pParse->GetCurrentBlockName();
		if ( !strcmpi( pBlock, "vehicle_view" ) )
		{
			pParse->ParseCustom( &m_vehicleView, &viewParser );
		}
		else
		{
			pParse->SkipBlock();
		}
	}
	physcollision->VPhysicsKeyParserDestroy( pParse );
	UTIL_FreeFile( pFile );

	Precache();

	return true;
}
void CEnvEffectsScript::ParseScriptFile( void )
{
	int length = 0;
	m_ScriptElements.RemoveAll();
	const char *pScriptName = GetScriptFile();

	//Reset everything.
	g_bUnget = false;
	currenttoken = NULL;
	tokencount = 0;
	memset( token, 0, 1204 );
	memset( name, 0, 256 );


	unsigned char *buffer = (unsigned char *)UTIL_LoadFileForMe( pScriptName, &length );
	if ( length <= 0 || !buffer )
	{
		DevMsg( 1, "CEnvEffectsScript:  failed to load %s\n", pScriptName );
		return;
	}

	currenttoken = (const char *)buffer;
	LoadFromBuffer( pScriptName, (const char *)buffer );

	UTIL_FreeFile( buffer );
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
// Purpose: Parses the vehicle's script
//-----------------------------------------------------------------------------
bool CFourWheelVehiclePhysics::ParseVehicleScript( const char *pScriptName, solid_t &solid, vehicleparams_t &vehicle)
{
	byte *pFile = UTIL_LoadFileForMe( pScriptName, NULL );
	if ( !pFile )
		return false;

	IVPhysicsKeyParser *pParse = physcollision->VPhysicsKeyParserCreate( (char *)pFile );
	while ( !pParse->Finished() )
	{
		const char *pBlock = pParse->GetCurrentBlockName();
		if ( !strcmpi( pBlock, "vehicle" ) )
		{
			pParse->ParseVehicle( &vehicle, NULL );
		}
		else
		{
			pParse->SkipBlock();
		}
	}
	physcollision->VPhysicsKeyParserDestroy( pParse );

	UTIL_FreeFile( pFile );

	m_debugRadius = vehicle.axles[0].wheels.radius;
	CalcWheelData( vehicle );

	PhysModelParseSolid( solid, m_pOuter, m_pOuter->GetModelIndex() );
	
	// Allow the script to shift the center of mass
	if ( vehicle.body.massCenterOverride != vec3_origin )
	{
		solid.massCenterOverride = vehicle.body.massCenterOverride;
		solid.params.massCenterOverride = &solid.massCenterOverride;
	}

	// allow script to change the mass of the vehicle body
	if ( vehicle.body.massOverride > 0 )
	{
		solid.params.mass = vehicle.body.massOverride;
	}

	return true;
}
Ejemplo n.º 5
0
bool CAI_SchedulesManager::LoadSchedules( const char *prefix, CAI_ClassScheduleIdSpace *pIdSpace  )
{
	char sz[128];

	// Open the weapon's data file and read the weaponry details
	Q_snprintf(sz,sizeof(sz), "scripts/%s.sch",prefix);
	char *pfile = (char*)UTIL_LoadFileForMe(sz, NULL);

	if (!pfile)
	{
		DevMsg( "Unable to open AI Schedule data file for: %s\n", sz);
		return false;
	}
	if (!LoadSchedulesFromBuffer( prefix, pfile, pIdSpace))
	{
		DevMsg( "       Schedule file: %s\n", sz );
		UTIL_FreeFile( (byte*)pfile );
		return false;
	}
	UTIL_FreeFile( (byte*)pfile );
	return true;
}
Ejemplo n.º 6
0
void CNB_Select_Level_Panel::UpdateLevelList() 
{
	const char *mapcfile = m_pMapListFile;

	// Check the time of the mapcycle file and re-populate the list of level names if the file has been modified
	const int nMapCycleTimeStamp = filesystem->GetPathTime( mapcfile, "GAME" );

	char *szDefaultMapName = "sdk_teams_hdr";

	if ( 0 == nMapCycleTimeStamp )
	{
		// Map cycle file does not exist, make a list containing only the default map
		m_MapList.AddToTail( szDefaultMapName );
	}
	else
	{
		// Clear out existing map list. Not using Purge() because I don't think that it will do a 'delete []'
		for ( int i = 0; i < m_MapList.Count(); i++ )
		{
			delete [] m_MapList[i];
		}

		m_MapList.RemoveAll();

		// Repopulate map list from mapcycle file
		int nFileLength;
		char *aFileList = (char*)UTIL_LoadFileForMe( mapcfile, &nFileLength );
		if ( aFileList && nFileLength )
		{
			V_SplitString( aFileList, "\n", m_MapList );

			for ( int i = 0; i < m_MapList.Count(); i++ )
			{
				bool bIgnore = false;

				// Strip out the spaces in the name
				StripChar( m_MapList[i] , '\r');
				StripChar( m_MapList[i] , ' ');
						
				/*
				if ( !engine->IsMapValid( m_MapList[i] ) )
				{
					bIgnore = true;

					// If the engine doesn't consider it a valid map remove it from the lists
					char szWarningMessage[MAX_PATH];
					V_snprintf( szWarningMessage, MAX_PATH, "Invalid map '%s' included in map cycle file. Ignored.\n", m_MapList[i] );
					Warning( szWarningMessage );
				}
				else */if ( !Q_strncmp( m_MapList[i], "//", 2 ) )
				{
					bIgnore = true;
				}

				if ( bIgnore )
				{
					delete [] m_MapList[i];
					m_MapList.Remove( i );
					--i;
				}
			}

			UTIL_FreeFile( (byte *)aFileList );
		}

		// If somehow we have no maps in the list then add the default one
		if ( 0 == m_MapList.Count() )
		{
			m_MapList.AddToTail( szDefaultMapName );
		}

		// Now rebuild the level entry list
		//m_pHorizList->m_Entries.PurgeAndDeleteElements();

		// Create entries
		for ( int i = 0; i < m_MapList.Count(); i++ )
		{
			if ( m_pHorizList->m_Entries.Count() <= i )
			{
				CNB_Select_Level_Entry *pEntry = new CNB_Select_Level_Entry( NULL, "Select_Level_Entry", m_MapList[i] );
				m_pHorizList->AddEntry( pEntry );
			}
			else
			{
				CNB_Select_Level_Entry *pEntry = dynamic_cast<CNB_Select_Level_Entry*>( m_pHorizList->m_Entries[i].Get() );
				pEntry->SetMap( m_MapList[i] );
			}
		}
	}
}
Ejemplo n.º 7
0
	void CMultiplayRules::GetNextLevelName( char *pszNextMap, int bufsize, bool bRandom /* = false */ )
	{
		const char *mapcfile = mapcyclefile.GetString();
		Assert( mapcfile != NULL );

		// Check the time of the mapcycle file and re-populate the list of level names if the file has been modified
		const int nMapCycleTimeStamp = filesystem->GetPathTime( mapcfile, "GAME" );

		if ( 0 == nMapCycleTimeStamp )
		{
			// Map cycle file does not exist, make a list containing only the current map
			char *szCurrentMapName = new char[32];
			Q_strncpy( szCurrentMapName, STRING(gpGlobals->mapname), 32 );
			m_MapList.AddToTail( szCurrentMapName );
		}
		else
		{
			// If map cycle file has changed or this is the first time through ...
			if ( m_nMapCycleTimeStamp != nMapCycleTimeStamp )
			{
				// Reset map index and map cycle timestamp
				m_nMapCycleTimeStamp = nMapCycleTimeStamp;
				m_nMapCycleindex = 0;

				// Clear out existing map list. Not using Purge() because I don't think that it will do a 'delete []'
				for ( int i = 0; i < m_MapList.Count(); i++ )
				{
					delete [] m_MapList[i];
				}

				m_MapList.RemoveAll();

				// Repopulate map list from mapcycle file
				int nFileLength;
				char *aFileList = (char*)UTIL_LoadFileForMe( mapcfile, &nFileLength );
				if ( aFileList && nFileLength )
				{
					V_SplitString( aFileList, "\n", m_MapList );

					for ( int i = 0; i < m_MapList.Count(); i++ )
					{
						bool bIgnore = false;

						// Strip out the spaces in the name
						StripChar( m_MapList[i] , '\r');
						StripChar( m_MapList[i] , ' ');
						
						if ( !engine->IsMapValid( m_MapList[i] ) )
						{
							bIgnore = true;

							// If the engine doesn't consider it a valid map remove it from the lists
							char szWarningMessage[MAX_PATH];
							V_snprintf( szWarningMessage, MAX_PATH, "Invalid map '%s' included in map cycle file. Ignored.\n", m_MapList[i] );
							Warning( szWarningMessage );
						}
						else if ( !Q_strncmp( m_MapList[i], "//", 2 ) )
						{
							bIgnore = true;
						}

						if ( bIgnore )
						{
							delete [] m_MapList[i];
							m_MapList.Remove( i );
							--i;
						}
					}

					UTIL_FreeFile( (byte *)aFileList );
				}
			}
		}

		// If somehow we have no maps in the list then add the current one
		if ( 0 == m_MapList.Count() )
		{
			char *szDefaultMapName = new char[32];
			Q_strncpy( szDefaultMapName, STRING(gpGlobals->mapname), 32 );
			m_MapList.AddToTail( szDefaultMapName );
		}

		if ( bRandom )
		{
			m_nMapCycleindex = RandomInt( 0, m_MapList.Count() - 1 );
		}

		// Here's the return value
		Q_strncpy( pszNextMap, m_MapList[m_nMapCycleindex], bufsize);
	}
Ejemplo n.º 8
0
	void CMultiplayRules::GetNextLevelName( char *pszNextMap, int bufsize )
	{
		char szFirstMapInList[32];
		Q_strncpy( szFirstMapInList, "hldm1" ,sizeof(szFirstMapInList));  // the absolute default level is hldm1

		// find the map to change to

		const char *mapcfile = mapcyclefile.GetString();
		Assert( mapcfile != NULL );
		Q_strncpy( pszNextMap, STRING(gpGlobals->mapname) ,bufsize);
		Q_strncpy( szFirstMapInList, STRING(gpGlobals->mapname) ,sizeof(szFirstMapInList));

		int length;
		char *pFileList;
		char *aFileList = pFileList = (char*)UTIL_LoadFileForMe( mapcfile, &length );
		if ( pFileList && length )
		{
			// the first map name in the file becomes the default
			sscanf( pFileList, " %31s", pszNextMap );
			if ( engine->IsMapValid( pszNextMap ) )
				Q_strncpy( szFirstMapInList, pszNextMap ,sizeof(szFirstMapInList));

			// keep pulling mapnames out of the list until the current mapname
			// if the current mapname isn't found,  load the first map in the list
			bool next_map_is_it = false;
			while ( 1 )
			{
				while ( *pFileList && isspace( *pFileList ) ) pFileList++; // skip over any whitespace
				if ( !(*pFileList) )
					break;

				char cBuf[32];
				int ret = sscanf( pFileList, " %31s", cBuf );
				// Check the map name is valid
				if ( ret != 1 || *cBuf < 13 )
					break;

				if ( next_map_is_it )
				{
					// check that it is a valid map file
					if ( engine->IsMapValid( cBuf ) )
					{
						Q_strncpy( pszNextMap, cBuf, bufsize);
						break;
					}
				}

				if ( FStrEq( cBuf, STRING(gpGlobals->mapname) ) )
				{  // we've found our map;  next map is the one to change to
					next_map_is_it = true;
				}

				pFileList += strlen( cBuf );
			}

			UTIL_FreeFile( (byte *)aFileList );
		}

		if ( !engine->IsMapValid(pszNextMap) )
			Q_strncpy( pszNextMap, szFirstMapInList, bufsize);
	}