int CASW_Mission_Chooser_Source_Local::GetNumMissionsCompleted(const char *szSaveName)
{
	Msg("GetNumMissionsCompleted %s\n", szSaveName);
	// check the save file exists
	char stripped[MAX_PATH];
	V_StripExtension( szSaveName, stripped, MAX_PATH );
	Msg("  stripped = %s\n", stripped);
	char tempfile[MAX_PATH];
	Q_snprintf( tempfile, sizeof( tempfile ), "save/%s.campaignsave", stripped );
	Msg("  tempfile = %s\n", tempfile);
	Q_strlower( tempfile );
	Msg("  tempfile lowered = %s\n", tempfile);
	if (!g_pFullFileSystem->FileExists(tempfile))
	{
		Msg("  this save doesn't exist! returning -1 missions\n");		
		return -1;
	}

	KeyValues *pSaveKeyValues = new KeyValues( szSaveName );
	if (pSaveKeyValues->LoadFromFile(g_pFullFileSystem, tempfile))
	{
		int iMissions = pSaveKeyValues->GetInt("NumMissionsComplete");
		pSaveKeyValues->deleteThis();
		Msg(" loaded keyvalues from file and it thinks num missions is %d\n", iMissions);
		return iMissions;
	}
	
	Msg("  Couldn't load save keyvalues from file, returning -1\n");
	if (pSaveKeyValues->LoadFromFile(g_pFullFileSystem, tempfile, "MOD"))
		Msg("  but it loaded if we use the MOD path\n");
	else if (pSaveKeyValues->LoadFromFile(g_pFullFileSystem, tempfile, "GAME"))
		Msg("  but it loaded if we use the GAME path\n");
	pSaveKeyValues->deleteThis();
	return -1;
}
CVGUIProjectable *CProjectableFactory::AllocateProjectableByScript( const char *pszFileName )
{
	CVGUIProjectable *pPanel = NULL;

	KeyValues *pKV = new KeyValues("");

	bool bSuccess = pKV->LoadFromFile( g_pFullFileSystem, VarArgs( "%s/%s", PATHLOCATION_PROJECTABLE_SCRIPTS, pszFileName ) );
	if ( !bSuccess )
		bSuccess = pKV->LoadFromFile( g_pFullFileSystem, VarArgs( "%s/%s.txt", PATHLOCATION_PROJECTABLE_SCRIPTS, pszFileName ) );

	if ( bSuccess )
	{
		const char *pszFactoryName = pKV->GetString( "factory" );

		if ( pszFactoryName != NULL && *pszFactoryName != '\0' )
			pPanel = AllocateProjectableByName( pszFactoryName );

		if ( pPanel != NULL )
		{
			KeyValues *pConfig = pKV->FindKey( "config" );

			if ( pConfig != NULL )
			{
				pPanel->LoadProjectableConfig( pConfig );
				pPanel->InvalidateLayout( true, true );
			}
		}
	}

	pKV->deleteThis();

	return pPanel;
}
Example #3
0
// Load the control settings 
void CBaseModFrame::LoadControlSettings( const char *dialogResourceName, const char *pathID, KeyValues *pPreloadedKeyValues, KeyValues *pConditions )
{
	// Use the keyvalues they passed in or load them using special hook for flyouts generation
	KeyValues *rDat = pPreloadedKeyValues;
	if ( !rDat )
	{
		// load the resource data from the file
		rDat  = new KeyValues(dialogResourceName);

		// check the skins directory first, if an explicit pathID hasn't been set
		bool bSuccess = false;
		if ( !IsX360() && !pathID )
		{
			bSuccess = rDat->LoadFromFile( g_pFullFileSystem, dialogResourceName, "SKIN" );
		}
		if ( !bSuccess )
		{
			bSuccess = rDat->LoadFromFile( g_pFullFileSystem, dialogResourceName, pathID );
		}
		if ( bSuccess )
		{
			if ( IsX360() )
			{
				rDat->ProcessResolutionKeys( surface()->GetResolutionKey() );
			}
			if ( pConditions && pConditions->GetFirstSubKey() )
			{
				GetBuildGroup()->ProcessConditionalKeys( rDat, pConditions );
			}
		}
	}

	// Find the auto-generated-chapter hook
	if ( KeyValues *pHook = rDat->FindKey( "FlmChapterXXautogenerated" ) )
	{
		const int numMaxAutogeneratedFlyouts = 20;
		for ( int k = 1; k <= numMaxAutogeneratedFlyouts; ++ k )
		{
			KeyValues *pFlyoutInfo = pHook->MakeCopy();
			
			CFmtStr strName( "FlmChapter%d", k );
			pFlyoutInfo->SetName( strName );
			pFlyoutInfo->SetString( "fieldName", strName );
			
			pFlyoutInfo->SetString( "ResourceFile", CFmtStr( "FlmChapterXXautogenerated_%d/%s", k, pHook->GetString( "ResourceFile" ) ) );

			rDat->AddSubKey( pFlyoutInfo );
		}

		rDat->RemoveSubKey( pHook );
		pHook->deleteThis();
	}

	BaseClass::LoadControlSettings( dialogResourceName, pathID, rDat, pConditions );
	if ( rDat != pPreloadedKeyValues )
	{
		rDat->deleteThis();
	}
}
Example #4
0
// first scheme loaded becomes the default scheme, and all subsequent loaded scheme are derivitives of that
HScheme  CSchemeManager::LoadSchemeFromFileEx( VPANEL sizingPanel, const char *fileName, const char *tag)
{
	// Look to see if we've already got this scheme...
	HScheme hScheme = FindLoadedScheme(fileName);
	if (hScheme != 0)
	{
		CScheme *pScheme = static_cast< CScheme * >( GetIScheme( hScheme ) );
		if ( IsPC() && pScheme )
		{
			pScheme->ReloadFontGlyphs();
		}
		return hScheme;
	}

	KeyValues *data;
	data = new KeyValues("Scheme");

	data->UsesEscapeSequences( true );	// VGUI uses this
	
	// look first in skins directory
	bool result = data->LoadFromFile( g_pFullFileSystem, fileName, "SKIN" );
	if (!result)
	{
		result = data->LoadFromFile( g_pFullFileSystem, fileName, "GAME" );
		if ( !result )
		{
			// look in any directory
			result = data->LoadFromFile( g_pFullFileSystem, fileName, NULL );
		}
	}

	if (!result)
	{
		data->deleteThis();
		return 0;
	}
	
	if ( IsX360() )
	{
		data->ProcessResolutionKeys( g_pSurface->GetResolutionKey() );
	}
	if ( IsPC() )
	{
		ConVarRef cl_hud_minmode( "cl_hud_minmode", true );
		if ( cl_hud_minmode.IsValid() && cl_hud_minmode.GetBool() )
		{
			data->ProcessResolutionKeys( "_minmode" );
		}
	}

	CScheme *newScheme = new CScheme();
	newScheme->LoadFromFile( sizingPanel, fileName, tag, data );

	return m_Schemes.AddToTail(newScheme);
}
const char* CASW_Mission_Chooser_Source_Local::GetCampaignSaveIntroMap(const char *szSaveName)
{
	// check the save file exists
	char stripped[MAX_PATH];
	V_StripExtension( szSaveName, stripped, MAX_PATH );
	char tempfile[MAX_PATH];
	Q_snprintf( tempfile, sizeof( tempfile ), "save/%s.campaignsave", stripped );
	if (!g_pFullFileSystem->FileExists(tempfile))
		return ASW_DEFAULT_INTRO_MAP;

	KeyValues *pSaveKeyValues = new KeyValues( szSaveName );
	const char* pszCampaign = NULL;
	if (pSaveKeyValues->LoadFromFile(g_pFullFileSystem, tempfile))
	{		
		pszCampaign = pSaveKeyValues->GetString("CampaignName");
	}
	if (!pszCampaign)
	{
		pSaveKeyValues->deleteThis();
		return ASW_DEFAULT_INTRO_MAP;
	}

	char ctempfile[MAX_PATH];
	Q_snprintf( ctempfile, sizeof( ctempfile ), "resource/campaigns/%s.txt", pszCampaign );
	if (!g_pFullFileSystem->FileExists(ctempfile))	/// check it exists
	{
		pSaveKeyValues->deleteThis();
		return ASW_DEFAULT_INTRO_MAP;
	}

	// now read in the campaign txt and find the intro map name
	KeyValues *pCampaignKeyValues = new KeyValues( pszCampaign );
	if (pCampaignKeyValues->LoadFromFile(g_pFullFileSystem, ctempfile))
	{
		static char s_introname[128];
		Q_strncpy( s_introname, pCampaignKeyValues->GetString("IntroMap"), 128 );
		// check we actually got a valid intro map name string
		if ( Q_strlen(s_introname) > 5 && !Q_strnicmp( s_introname, "intro", 5 ) )
		{
			pSaveKeyValues->deleteThis();
			pCampaignKeyValues->deleteThis();
			return s_introname;
		}
	}

	pSaveKeyValues->deleteThis();
	pCampaignKeyValues->deleteThis();
	return ASW_DEFAULT_INTRO_MAP;
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CButtonPanel::CButtonPanel() : EditablePanel(NULL, "button_panel")
{
	SetParent(enginevgui->GetPanel( PANEL_GAMEUIDLL ));

	SetProportional(true);

	LoadControlSettings( "Resource/UI/buttonpanel.res" );
	InvalidateLayout();

	m_pNews = new ImageButton(this, "NewsButton", "news", NULL, NULL, "opennews");
	m_pLeaderboard = new ImageButton(this, "LeaderboardButton", "leaderboard", NULL, NULL, "openleaderboard");

	MakeReadyForUse();

	Update();

	KeyValues *manifest = new KeyValues( "latest_news" );
	if ( manifest->LoadFromFile( filesystem, "latest_news.txt" ) )
		m_iLatestNews = atol(manifest->GetFirstValue()->GetString());
	else
		m_iLatestNews = 0;

	// Start us out with the leaderboard.
	CloseAll();
	Leaderboard()->SetVisible(true);
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CGameMenuButton::CGameMenuButton(vgui::Panel *parent, const char *panelName, const char *text)
								: vgui::MenuButton( parent, panelName, text )
{
	g_pGameMenuButton = this;
	vgui::Menu *gameMenu = NULL;

	// load settings from config file
	KeyValues *datafile = new KeyValues("GameMenu");
	datafile->UsesEscapeSequences( true );
	if (datafile->LoadFromFile(filesystem(), "Resource/GameMenu.res"))
	{
		gameMenu = RecursiveLoadGameMenu(datafile);
		datafile->deleteThis();
	}
	else
	{
		// add a bunch of default stuff
		assert(!("Could not load file Resource/GameMenu.res"));
		gameMenu = new vgui::Menu(this, "GameMenu");
		gameMenu->AddMenuItem( "#GameUI_GameMenu_NewGame ", "OpenNewGameDialog", this );
		gameMenu->AddMenuItem( "#GameUI_GameMenu_LoadGame ", "OpenLoadGameDialog", this );
		gameMenu->AddMenuItem( "SaveGame", "#GameUI_GameMenu_SaveGame ", "OpenSaveGameDialog", this );
		gameMenu->AddMenuItem( "#GameUI_GameMenu_Multiplayer ", "OpenMultiplayerDialog", this );
		gameMenu->AddMenuItem( "#GameUI_GameMenu_Options ", "OpenOptionsDialog", this );
		gameMenu->AddMenuItem( "#GameUI_GameMenu_Quit ", "Quit", this );
	}

	m_pMenu = gameMenu;

	gameMenu->MakePopup();
	MenuButton::SetMenu(gameMenu);
	SetOpenDirection(MenuButton::UP);
}
bool CMapAdd::RunPlayerInit( const char *mapaddMap, const char *szLabel)
{
	if(AllocPooledString(mapaddMap) == AllocPooledString("") || !mapaddMap)
		return false; //Failed to load!
	if(!szLabel)
		szLabel = "Init";
	//FileHandle_t fh = filesystem->Open(szMapadd,"r","MOD");
	// Open the mapadd data file, and abort if we can't
	KeyValues *pMapAdd = new KeyValues( "MapAdd" );
	if(pMapAdd->LoadFromFile( filesystem, mapaddMap, "MOD" ))
	{
		KeyValues *pMapAdd2 = pMapAdd->FindKey(szLabel);
		if(pMapAdd2)
		{
			KeyValues *pMapAddEnt = pMapAdd2->GetFirstTrueSubKey();
			while (pMapAddEnt)
			{
				HandlePlayerEntity(pMapAddEnt, false);
				pMapAddEnt = pMapAddEnt->GetNextTrueSubKey(); //Got to keep this!
			}
		}
	}
	pMapAdd->deleteThis();
	return true;
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void MountExtraContent()
{
	memset(g_AppStatus, 0, sizeof(g_AppStatus));

	KeyValues *pMountList = new KeyValues( "MountList" );
	if( !pMountList->LoadFromFile( filesystem, "mountlist.txt" ) )
	{
		// Create default
		pMountList->SetString( "dota", "0" );
		pMountList->SetString( "left4dead", "0" );
		pMountList->SetString( "left4dead2", "0" );
		pMountList->SetString( "portal2", "0" );
		pMountList->SetString( "csgo", "0" );
		pMountList->SetString( "dearesther", "0" );
		
		pMountList->SaveToFile( filesystem, "mountlist.txt", "MOD" );
	}

	if( TryMountVPKGame( "DOTA", "../../common/dota 2 beta/dota", APP_DOTA, "dota", pMountList ) )
		PostProcessDota2( "models" );
	TryMountVPKGame( "Portal 2", "../../common/portal 2/portal2", APP_PORTAL2, "portal2", pMountList );
	TryMountVPKGame( "Left 4 Dead 2", "../../common/left 4 dead 2/left4dead2", APP_L4D2, "left4dead2", pMountList );
	TryMountVPKGame( "Left 4 Dead", "../../common/left 4 dead/left4dead", APP_L4D1, "left4dead", pMountList );
	TryMountVPKGame( "Counter-Strike Global Offensive", "../../common/Counter-Strike Global Offensive/csgo", APP_CSGO, "csgo", pMountList );
	TryMountVPKGame( "Dear Esther", "../../common/dear esther/dearesther", APP_DEARESTHER, "dearesther", pMountList );

	if( pMountList )
	{
		pMountList->deleteThis();
		pMountList = NULL;
	}
}
Example #10
0
//-----------------------------------------------------------------------------
// Purpose: Loads the surface properties database into the physics DLL
//-----------------------------------------------------------------------------
void LoadSurfaceProperties( void )
{
	CreateInterfaceFn physicsFactory = GetPhysicsFactory();
	if ( !physicsFactory )
		return;

	physprops = (IPhysicsSurfaceProps *)physicsFactory( VPHYSICS_SURFACEPROPS_INTERFACE_VERSION, NULL );

	const char *SURFACEPROP_MANIFEST_FILE = "scripts/surfaceproperties_manifest.txt";
	KeyValues *manifest = new KeyValues( SURFACEPROP_MANIFEST_FILE );
	if ( manifest->LoadFromFile( g_pFileSystem, SURFACEPROP_MANIFEST_FILE, "GAME" ) )
	{
		for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() )
		{
			if ( !Q_stricmp( sub->GetName(), "file" ) )
			{
				// Add
				LoadSurfacePropFile( sub->GetString() );
				continue;
			}
		}
	}

	manifest->deleteThis();
}
Example #11
0
//-----------------------------------------------------------------------------
// Purpose: Loads additional commandline arguments from a config file for an app.
//			Filesystem must be initialized before calling this function.
// keyname: Name of the block containing the key/args pairs (ie map or model name)
// appname: Keyname for the commandline arguments to be loaded - typically the exe name.
//-----------------------------------------------------------------------------
void LoadCmdLineFromFile( int &argc, char **&argv, const char *keyname, const char *appname )
{
	sFoundConfigArgs = false;

	assert( g_pFileSystem );
	if( !g_pFileSystem )
		return;

	// Load the cfg file, and find the keyname
	KeyValues *kv = new KeyValues( "CommandLine" );

	char filename[512];
	Q_snprintf( filename, sizeof( filename ), "%s/cfg/commandline.cfg", gamedir );

	if ( kv->LoadFromFile( g_pFileSystem, filename ) )
	{
		// Load the commandline arguments for this app
		KeyValues  *appKey	= kv->FindKey( keyname );
		if( appKey )
		{
			const char *str	= appKey->GetString( appname );
			Msg( "Command Line found: %s\n", str );

			AddArguments( argc, argv, str );
		}
	}

	kv->deleteThis();
}
bool GetValueFromMaterial( const char *pMaterialName, const char *pKey, char *pValue, int len )
{
	char name[512];
	sprintf( name, "materials/%s.vmt", GetOriginalMaterialNameForPatchedMaterial( pMaterialName ) );
	KeyValues *kv = new KeyValues( "blah" );
	// Load the underlying file so that we can check if env_cubemap is in there.
	if ( !kv->LoadFromFile( g_pFileSystem, name ) )
	{
//		Assert( 0 );
		kv->deleteThis();
		return NULL;
	}

	const char *pTmpValue = kv->GetString( pKey, NULL );
	
	if( pTmpValue )
	{
		Q_strncpy( pValue, pTmpValue, len );
	}

	kv->deleteThis();
	if( pTmpValue )
	{
		return true;
	}
	else
	{
		return false;
	}
}
Example #13
0
int UTIL_GetMapKeyCount( const char *pszCustomKey )
{
	if ( !pszCustomKey )
		return 0;

	char szFilename[ _MAX_PATH ];
	if ( !UTIL_GetMapLoadCountFileName( MAP_KEY_FILE, szFilename, _MAX_PATH ) )
		return 0;

	int iCount = 0;

	KeyValues *kvMapLoadFile = new KeyValues( MAP_KEY_FILE );
	if ( kvMapLoadFile )
	{
		kvMapLoadFile->LoadFromFile( g_pFullFileSystem, szFilename, "MOD" );

		char mapname[MAX_MAP_NAME];
		Q_FileBase( engine->GetLevelName(), mapname, sizeof( mapname) );
		Q_strlower( mapname );

		KeyValues *pMapKey = kvMapLoadFile->FindKey( mapname );
		if ( pMapKey )
		{
			iCount = pMapKey->GetInt( pszCustomKey );
		}

		kvMapLoadFile->deleteThis();
	}

	return iCount;
}
void PrecacheFileWeaponInfoDatabase( IFileSystem *filesystem, const unsigned char *pICEKey )
{
	if ( m_WeaponInfoDatabase.Count() )
		return;

	KeyValues *manifest = new KeyValues( "weaponscripts" );
	if ( manifest->LoadFromFile( filesystem, "scripts/weapon_manifest.txt", "GAME" ) )
	{
		for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL ; sub = sub->GetNextKey() )
		{
			if ( !Q_stricmp( sub->GetName(), "file" ) )
			{
				char fileBase[512];
				Q_FileBase( sub->GetString(), fileBase, sizeof(fileBase) );
				WEAPON_FILE_INFO_HANDLE tmp;
#ifdef CLIENT_DLL
				if ( ReadWeaponDataFromFileForSlot( filesystem, fileBase, &tmp, pICEKey ) )
				{
					gWR.LoadWeaponSprites( tmp );
				}
#else
				ReadWeaponDataFromFileForSlot( filesystem, fileBase, &tmp, pICEKey );
#endif
			}
			else
			{
				Error( "Expecting 'file', got %s\n", sub->GetName() );
			}
		}
	}
	manifest->deleteThis();
}
void C_SoundscapeSystem::AddSoundScapeFile( const char *filename )
{
	KeyValues *script = new KeyValues( filename );
#ifndef _XBOX
	if ( script->LoadFromFile( filesystem, filename ) )
#else
	if ( filesystem->LoadKeyValues( *script, IFileSystem::TYPE_SOUNDSCAPE, filename, "GAME" ) )
#endif
	{
		// parse out all of the top level sections and save their names
		KeyValues *pKeys = script;
		while ( pKeys )
		{
			// save pointers to all sections in the root
			// each one is a soundscape
			if ( pKeys->GetFirstSubKey() )
			{
				m_soundscapes.AddToTail( pKeys );
			}
			pKeys = pKeys->GetNextKey();
		}

		// Keep pointer around so we can delete it at exit
		m_SoundscapeScripts.AddToTail( script );
	}
	else
	{
		script->deleteThis();
	}
}
Example #16
0
void CClientTimesDisplay::LoadLocalTimes(KeyValues *kv)
{
    if (!m_bLocalTimesLoaded || m_bLocalTimesNeedUpdate)
    {
        //Clear the local times for a refresh
        m_vLocalTimes.RemoveAll();

        //Load from .tim file
        KeyValues *pLoaded = new KeyValues("local");
        char fileName[MAX_PATH];

        Q_snprintf(fileName, MAX_PATH, "maps/%s.tim", g_pGameRules->MapName() ? g_pGameRules->MapName() : "FIXME");

        if (pLoaded->LoadFromFile(filesystem, fileName, "MOD"))
        {
            DevLog("Loading from file %s...\n", fileName);
            for (KeyValues* kvLocalTime = pLoaded->GetFirstSubKey(); kvLocalTime; kvLocalTime = kvLocalTime->GetNextKey())
            {
                Time t = Time(kvLocalTime);
                m_vLocalTimes.AddToTail(t);
            }
            m_bLocalTimesLoaded = true;
            m_bLocalTimesNeedUpdate = false;
        }
        pLoaded->deleteThis();
    }

    //Convert
    if (!m_vLocalTimes.IsEmpty())
        ConvertLocalTimes(kv);
}
Example #17
0
void VMFExporter::LoadUniqueKeyList()
{
    m_UniqueKeys.RemoveAll();
    m_NodeIDKeys.RemoveAll();

    // Open the manifest file, and read the particles specified inside it
    KeyValues *manifest = new KeyValues( UNIQUE_KEYS_FILE );
    if ( manifest->LoadFromFile( g_pFullFileSystem, UNIQUE_KEYS_FILE, "GAME" ) )
    {
        for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() )
        {
            if ( !Q_stricmp( sub->GetName(), "key" ) )
            {
                m_UniqueKeys.AddToTail( sub->GetString() );
                continue;
            }
            if ( !Q_stricmp( sub->GetName(), "NodeID" ) )
            {
                m_NodeIDKeys.AddToTail( sub->GetString() );
                continue;
            }

            Warning( "VMFExporter::LoadUniqueKeyList:  Manifest '%s' with bogus file type '%s', expecting 'key' or 'NodeID'\n", UNIQUE_KEYS_FILE, sub->GetName() );
        }
    }
    else
    {
        Warning( "VMFExporter: Unable to load manifest file '%s'\n", UNIQUE_KEYS_FILE );
    }

    manifest->deleteThis();
}
Example #18
0
void PhysParseSurfaceData( IPhysicsSurfaceProps *pProps, IFileSystem *pFileSystem )
{
	KeyValues *manifest = new KeyValues( SURFACEPROP_MANIFEST_FILE );
	if ( manifest->LoadFromFile( pFileSystem, SURFACEPROP_MANIFEST_FILE, "GAME" ) )
	{
		for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() )
		{
			if ( !Q_stricmp( sub->GetName(), "file" ) )
			{
				// Add
				AddSurfacepropFile( sub->GetString(), pProps, pFileSystem );
				continue;
			}

			Warning( "surfaceprops::Init:  Manifest '%s' with bogus file type '%s', expecting 'file'\n", 
				SURFACEPROP_MANIFEST_FILE, sub->GetName() );
		}
	}
	else
	{
		Error( "Unable to load manifest file '%s'\n", SURFACEPROP_MANIFEST_FILE );
	}

	manifest->deleteThis();
}
bool CASW_Location_Grid::LoadLocationGrid()
{
    m_Groups.PurgeAndDeleteElements();

    // open our mission grid file
    KeyValues *pGridKeys = new KeyValues( "MissionGrid" );
    if ( !pGridKeys->LoadFromFile( g_pFullFileSystem, "resource/mission_grid.txt", "GAME" ) )
    {
        Msg( "Failed to load resource/mission_grid.txt\n" );
        pGridKeys->deleteThis();
        return false;
    }

    KeyValues *pKeys = pGridKeys;
    while ( pKeys )
    {
        if ( !Q_stricmp( pKeys->GetName(), "Group" ) )
        {
            CASW_Location_Group *pGroup = new CASW_Location_Group( this );
            pGroup->LoadFromKeyValues( pKeys );
            m_Groups.AddToTail( pGroup );
        }
        pKeys = pKeys->GetNextKey();
    }
    return true;
}
Example #20
0
bool VMFExporter::AddLevelContainer()
{
    KeyValues *pLevelContainerKeys = new KeyValues( "LevelContainer" );
    if ( !pLevelContainerKeys->LoadFromFile( g_pFullFileSystem, "tilegen/roomtemplates/levelcontainer.vmf.no_func_detail", "GAME" ) )
        return false;

    m_bWritingLevelContainer = true;

    // set the extents of the map
    m_pMapLayout->GetExtents(m_iMapExtents_XMin, m_iMapExtents_XMax, m_iMapExtents_YMin, m_iMapExtents_YMax);
    Msg( "Layout extents: Topleft: %f %f - Lower right: %f %f\n", m_iMapExtents_XMin, m_iMapExtents_YMin, m_iMapExtents_XMax, m_iMapExtents_YMax );
    // adjust to be relative to the centre of the map
    int half_map_size = MAP_LAYOUT_TILES_WIDE * 0.5f;
    m_iMapExtents_XMin -= half_map_size;
    m_iMapExtents_XMax -= half_map_size;
    m_iMapExtents_YMin -= half_map_size;
    m_iMapExtents_YMax -= half_map_size;
    // pad them by 2 blocks, so the player doesn't move his camera into the wall when at an edge block
    m_iMapExtents_XMin -= 2;
    m_iMapExtents_XMax += 2;
    m_iMapExtents_YMin -= 2;
    m_iMapExtents_YMax += 2;

    Msg( "   Adjusted to: Topleft: %d %d - Lower right: %d %d\n", m_iMapExtents_XMin, m_iMapExtents_YMin, m_iMapExtents_XMax, m_iMapExtents_YMax );

    // find world keys
    KeyValues *pWorldKeys = NULL;
    for ( KeyValues *pKeys = pLevelContainerKeys; pKeys; pKeys = pKeys->GetNextKey() )
    {
        const char *szName = pKeys->GetName();
        if ( !Q_stricmp( szName, "world" ) )
        {
            pWorldKeys = pKeys;
            break;
        }
    }
    if ( !pWorldKeys || !ProcessWorld( pWorldKeys ) )
    {
        Q_snprintf( m_szLastExporterError, sizeof(m_szLastExporterError), "Failed to copy level container\n" );
        return false;
    }

    m_bWritingLevelContainer = false;

    for ( KeyValues *pKeys = pWorldKeys->GetFirstSubKey(); pKeys; pKeys = pKeys->GetNextKey() )
    {
        const char *szName = pKeys->GetName();
        if ( !Q_stricmp( szName, "solid" ) )
        {
            m_pExportWorldKeys->AddSubKey( pKeys->MakeCopy() );
        }
    }
    pLevelContainerKeys->deleteThis();

    m_pTemplateKeys->deleteThis();
    m_pTemplateKeys = NULL;

    return true;
}
Example #21
0
//-----------------------------------------------------------------------------
// A version which allows you to patch multiple key values
//-----------------------------------------------------------------------------
void CreateMaterialPatch( const char *pOriginalMaterialName, const char *pNewMaterialName,
						 int nKeys, const MaterialPatchInfo_t *pInfo, MaterialPatchType_t nPatchType )
{	
	char pOldVMTFile[ 512 ];
	char pNewVMTFile[ 512 ];

	AddNewTranslation( pOriginalMaterialName, pNewMaterialName );
	
	Q_snprintf( pOldVMTFile, 512, "materials/%s.vmt", pOriginalMaterialName );
	Q_snprintf( pNewVMTFile, 512, "materials/%s.vmt", pNewMaterialName );

//	printf( "Creating material patch file %s which points at %s\n", newVMTFile, oldVMTFile );

	KeyValues *kv = new KeyValues( "patch" );
	if ( !kv )
	{
		Error( "Couldn't allocate KeyValues for %s!!!", pNewMaterialName );
	}

	kv->SetString( "include", pOldVMTFile );

	const char *pSectionName = (nPatchType == PATCH_INSERT) ? "insert" : "replace";
	KeyValues *section = kv->FindKey( pSectionName, true );

	if( nPatchType == PATCH_REPLACE )
	{
		char name[512];
		Q_snprintf( name, 512, "materials/%s.vmt", GetOriginalMaterialNameForPatchedMaterial( pOriginalMaterialName ) );
		KeyValues *origkv = new KeyValues( "blah" );

		if ( !origkv->LoadFromFile( g_pFileSystem, name ) )
		{
			origkv->deleteThis();
			Assert( 0 );
			return;
		}

		CreateMaterialPatchRecursive( origkv, section, nKeys, pInfo );
		origkv->deleteThis();
	}
	else
	{
		for ( int i = 0; i < nKeys; ++i )
		{
			section->SetString( pInfo[i].m_pKey, pInfo[i].m_pValue );
		}
	}
	
	// Write patched .vmt into a memory buffer
	CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
	kv->RecursiveSaveToFile( buf, 0 );

	// Add to pak file for this .bsp
	AddBufferToPak( GetPakFile(), pNewVMTFile, (void*)buf.Base(), buf.TellPut(), true );

	// Cleanup
	kv->deleteThis();
}
//-----------------------------------------------------------------------------
// Scan all materials for errors
//-----------------------------------------------------------------------------
void _CheckMateralsInDirectoryRecursive( const char *pRoot, const char *pDirectory, CUtlVector< VTFInfo_t > &vtf )
{
#define BUF_SIZE 1024
	char buf[BUF_SIZE];
	WIN32_FIND_DATA wfd;
	HANDLE findHandle;
	
	sprintf( buf, "%s/%s/*.vmt", pRoot, pDirectory );
	findHandle = FindFirstFile( buf, &wfd );
	if ( findHandle != INVALID_HANDLE_VALUE ) 
	{ 
		do 
		{
			KeyValues * vmtKeyValues = new KeyValues("vmt");

			char pFileName[MAX_PATH];
			Q_snprintf( pFileName, sizeof( pFileName ), "%s/%s", pDirectory, wfd.cFileName );
			if ( !vmtKeyValues->LoadFromFile( g_pFullFileSystem, pFileName, "GAME" ) )
			{
				Warning( "CheckMateralsInDirectoryRecursive: can't open \"%s\"\n", pFileName );
				continue;
			}

			CheckMaterial( vmtKeyValues, pRoot, pFileName, vtf );

			vmtKeyValues->deleteThis();

		} while ( FindNextFile ( findHandle, &wfd ) ); 
		
		FindClose ( findHandle ); 
	}

	// do subdirectories
	sprintf( buf, "%s/%s/*.*", pRoot, pDirectory );
	findHandle = FindFirstFile( buf, &wfd );
	if ( findHandle != INVALID_HANDLE_VALUE ) 
	{ 
		do 
		{ 
			if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
			{
				if( ( strcmp( wfd.cFileName, ".." ) == 0 ) || 
					( strcmp( wfd.cFileName, "." ) == 0 ) )
				{
					continue;
				}

				char buf[MAX_PATH];
				Q_snprintf( buf, MAX_PATH, "%s/%s", pDirectory, wfd.cFileName );
				_CheckMateralsInDirectoryRecursive( pRoot, buf, vtf );
			}
		} while ( FindNextFile ( findHandle, &wfd ) ); 
		FindClose ( findHandle ); 
	}

//	Msg( "Normal only %d/%d/%d Normal w alpha %d/%d\n", s_nNormalBytes, s_nNormalPalettizedBytes, s_nNormalCompressedBytes, s_nNormalWithAlphaBytes, s_nNormalWithAlphaCompressedBytes );
#undef BUF_SIZE
}
KeyValues *df_LoadDump_List()
{
	char path_dump_list[MAX_PATH];
	GetDumpListFilePath( path_dump_list, MAX_PATH );

	KeyValues *pKV = new KeyValues( "shaderlist" );
	pKV->LoadFromFile( g_pFullFileSystem, path_dump_list, "MOD" );
	return pKV;
}
	virtual void FrameUpdatePostEntityThink( void )
	{
		// Wait until we're all spawned in
		if ( gpGlobals->curtime < 5 )
			return;

		if ( m_bIssuedNextMapCommand )
			return;

		if ( !m_bParsedMapFile )
		{
			m_bParsedMapFile = true;

			// See if we've got a camera file to import cameras from
			char szFullName[512];
			Q_snprintf(szFullName,sizeof(szFullName), "maps/%s.txt", STRING( gpGlobals->mapname ));
			KeyValues *pkvMapCameras = new KeyValues( "MapCameras" );
			if ( pkvMapCameras->LoadFromFile( filesystem, szFullName, "MOD" ) )
			{
				Warning( "Devshots: Loading point_devshot_camera positions from %s. \n", szFullName );

				// Get each camera, and add it to our list
				KeyValues *pkvCamera = pkvMapCameras->GetFirstSubKey();
				while ( pkvCamera )
				{
					// Get camera name
					const char *pCameraName = pkvCamera->GetName();

					// Make a camera, and move it to the position specified
					CPointDevShotCamera	*pCamera = (CPointDevShotCamera*)CreateEntityByName( "point_devshot_camera" );
					Assert( pCamera );
					pCamera->KeyValue( "cameraname", pCameraName );
					pCamera->KeyValue( "origin", pkvCamera->GetString( "origin", "0 0 0" ) );
					pCamera->KeyValue( "angles", pkvCamera->GetString( "angles", "0 0 0" ) );
					pCamera->KeyValue( "FOV", pkvCamera->GetString( "FOV", "75" ) );
					DispatchSpawn( pCamera );
					pCamera->Activate();

					// Move to next camera
					pkvCamera = pkvCamera->GetNextKey();
				}
			}

			if ( !g_iDevShotCameraCount )
			{
				Warning( "Devshots: No point_devshot_camera in %s. Moving to next map.\n", STRING( gpGlobals->mapname ) );

				CBasePlayer *pPlayer = UTIL_GetLocalPlayerOrListenServerHost();
				if ( pPlayer )
				{
					engine->ClientCommand( pPlayer->edict(), "devshots_nextmap" );
					m_bIssuedNextMapCommand = true;
					return;
				}
			}
		}
	}
void UTIL_IncrementMapKey( const char *pszCustomKey )
{
	if ( !pszCustomKey )
		return;

	char szFilename[ _MAX_PATH ];
	if ( !UTIL_GetMapLoadCountFileName( MAP_KEY_FILE, szFilename, _MAX_PATH ) )
		return;

	int iCount = 1;

	KeyValues *kvMapLoadFile = new KeyValues( MAP_KEY_FILE );
	if ( kvMapLoadFile )
	{
		kvMapLoadFile->LoadFromFile( g_pFullFileSystem, szFilename, "MOD" );

		char mapname[MAX_MAP_NAME];
		Q_FileBase( engine->GetLevelName(), mapname, sizeof( mapname) );
		Q_strlower( mapname );

		// Increment existing, or add a new one
		KeyValues *pMapKey = kvMapLoadFile->FindKey( mapname );
		if ( pMapKey )
		{
			iCount = pMapKey->GetInt( pszCustomKey, 0 ) + 1;
			pMapKey->SetInt( pszCustomKey, iCount );
		}
		else 
		{
			KeyValues *pNewKey = new KeyValues( mapname );
			if ( pNewKey )
			{
				pNewKey->SetString( pszCustomKey, "1" );
				kvMapLoadFile->AddSubKey( pNewKey );
			}
		}

		// Write it out

		// force create this directory incase it doesn't exist
		filesystem->CreateDirHierarchy( MAP_KEY_FILE_DIR, "MOD");

		CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
		kvMapLoadFile->RecursiveSaveToFile( buf, 0 );
		g_pFullFileSystem->WriteFile( szFilename, "MOD", buf );

		kvMapLoadFile->deleteThis();
	}

	if ( IsX360() )
	{
#ifdef _X360
		xboxsystem->FinishContainerWrites();
#endif
	}
}
Example #26
0
void PrecacheFileWeaponInfoDatabase( IFileSystem *filesystem, const unsigned char *pICEKey )
{
	if ( m_WeaponInfoDatabase.Count() )
		return;

#if !defined( _XBOX )
	FileFindHandle_t findHandle;
	const char *pFilename = filesystem->FindFirstEx( "scripts/weapon_*.txt", IsXbox() ? "XGAME" : "GAME", &findHandle );
	while ( pFilename != NULL )
	{
		char fileBase[512];
		Q_FileBase( pFilename, fileBase, sizeof(fileBase) );
		WEAPON_FILE_INFO_HANDLE tmp;
#ifdef CLIENT_DLL
		if ( ReadWeaponDataFromFileForSlot( filesystem, fileBase, &tmp, pICEKey ) )
		{
			gWR.LoadWeaponSprites( tmp );
		}
#else
		ReadWeaponDataFromFileForSlot( filesystem, fileBase, &tmp, pICEKey );
#endif
		pFilename = filesystem->FindNext( findHandle );
	}
	filesystem->FindClose( findHandle );
#else
#define WEAPON_SCRIPT_MANIFEST_FILE		"scripts/_weapon_manifest.txt"

	// Use a manifest file on the xbox
	KeyValues *manifest = new KeyValues( "weaponscripts" );
	if ( manifest->LoadFromFile( filesystem, WEAPON_SCRIPT_MANIFEST_FILE, "XGAME" ) )
	{
		for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL ; sub = sub->GetNextKey() )
		{
			if ( !Q_stricmp( sub->GetName(), "file" ) )
			{
				char fileBase[512];
				Q_FileBase( sub->GetString(), fileBase, sizeof(fileBase) );
				WEAPON_FILE_INFO_HANDLE tmp;
#ifdef CLIENT_DLL
				if ( ReadWeaponDataFromFileForSlot( filesystem, fileBase, &tmp, pICEKey ) )
				{
					gWR.LoadWeaponSprites( tmp );
				}
#else
				ReadWeaponDataFromFileForSlot( filesystem, fileBase, &tmp, pICEKey );
#endif
			}
			else
			{
				Error( "Expecting 'file', got %s\n", sub->GetName() );
			}
		}
	}
	manifest->deleteThis();
#endif
}
Example #27
0
// Loads in all level themes found in tilegen/themes/
void CLevelTheme::LoadLevelThemes()
{
	if ( s_bLoadedThemes )
		return;

	s_pCurrentTheme = NULL;
	s_LevelThemes.PurgeAndDeleteElements();
	s_bLoadedThemes = true;

	// Search the directory structure.
	char mapwild[MAX_PATH];
	Q_strncpy(mapwild,"tilegen/themes/*.theme", sizeof( mapwild ) );
	char const *filename;
	filename = Sys_FindFirst( g_hthemefind, mapwild, NULL, 0 );

	while (filename)
	{
		// load the level theme
		char szFullFileName[256];
		Q_snprintf(szFullFileName, sizeof(szFullFileName), "tilegen/themes/%s", filename);
		KeyValues *pThemeKeyValues = new KeyValues( filename );
		if (pThemeKeyValues->LoadFromFile(g_pFullFileSystem, szFullFileName, "GAME"))
		{
			//CLevelTheme* pTheme = new CLevelTheme(pThemeKeyValues->GetString("ThemeName"),
			//									pThemeKeyValues->GetString("ThemeDescription"),
			//									pThemeKeyValues->GetInt("VMFTweak", 0) > 0 );
			//pTheme->m_bSkipErrorCheck = ( pThemeKeyValues->GetInt( "SkipErrorCheck", 0 ) > 0 );
			//sscanf( pThemeKeyValues->GetString( "AmbientLight" ) , "%f %f %f", &pTheme->m_vecAmbientLight.x, &pTheme->m_vecAmbientLight.y, &pTheme->m_vecAmbientLight.z );
			//// temp to avoid the 0,0,0 losing ambient light bug
			//if ( pTheme->m_vecAmbientLight == vec3_origin )
			//{
			//	pTheme->m_vecAmbientLight.x = 1;
			//	pTheme->m_vecAmbientLight.y = 1;
			//	pTheme->m_vecAmbientLight.z = 1;
			//}
			//pTheme->LoadRoomTemplates();
			//s_LevelThemes.AddToTail(pTheme);
			//if (!Q_stricmp(pTheme->m_szName, asw_tilegen_theme.GetString()))	// default to the Rydberg theme
			//	SetCurrentTheme(pTheme);
		}
		else
		{
			Msg("Error: failed to load theme %s\n", szFullFileName);
		}
		pThemeKeyValues->deleteThis();
		filename = Sys_FindNext(g_hthemefind, NULL, 0);
	}

	if ( s_pCurrentTheme == NULL && s_LevelThemes.Count() > 0 )
	{
		SetCurrentTheme( s_LevelThemes[0] );
	}
		
	Sys_FindClose(g_hthemefind);
}
Example #28
0
//-----------------------------------------------------------------------------
// Purpose: This is called every time the DLL is loaded
//-----------------------------------------------------------------------------
void CHud::Init( void )
{
	ASSERT_LOCAL_PLAYER_RESOLVABLE();

	m_nSplitScreenSlot = GET_ACTIVE_SPLITSCREEN_SLOT();
	g_HudHelper.Init();

	InitFonts();

	// Create all the Hud elements
	CHudElementHelper::CreateAllElements();

	gLCD.Init();

	// Initialize all created elements
	for ( int i = 0; i < GetHudList().Count(); i++ )
	{
		GetHudList()[ i ]->Init();
	}

	KeyValues *kv = new KeyValues( "layout" );
	if ( kv )
	{
		if ( kv->LoadFromFile( filesystem, "scripts/HudLayout.res" ) )
		{
			int numelements = GetHudList().Count();

			for ( int i = 0; i < numelements; i++ )
			{
				CHudElement *element = GetHudList()[i];
				vgui::Panel *pPanel = GetHudPanelList()[i];
				KeyValues *key = kv->FindKey( pPanel->GetName(), false );
				if ( !key )
				{
					Msg( "Hud element '%s' doesn't have an entry '%s' in scripts/HudLayout.res\n", element->GetName(), pPanel->GetName() );
				}

				// Note:  When a panel is parented to the module root, it's "parent" is returned as NULL.
				if ( !element->IsParentedToClientDLLRootPanel() && 
					 !pPanel->GetParent() )
				{
					DevMsg( "Hud element '%s'/'%s' doesn't have a parent\n", element->GetName(), pPanel->GetName() );
				}
			}
		}

		kv->deleteThis();
	}

	if ( GET_ACTIVE_SPLITSCREEN_SLOT() == 0 )
	{
		HudIcons().Init();
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CTFIntroMenu::LoadCaptions( void )
{
	bool bSuccess = false;

	// clear any current captions
	m_Captions.PurgeAndDeleteElements();
	m_iCurrentCaption = 0;

	if ( m_pCaptionLabel )
	{
		KeyValues *kvCaptions = NULL;
		char strFullpath[MAX_PATH];

		Q_strncpy( strFullpath, TFGameRules()->GetVideoFileForMap( false ), MAX_PATH );	// Assume we must play out of the media directory
		Q_strncat( strFullpath, ".res", MAX_PATH );					// Assume we're a .res extension type

		if ( g_pFullFileSystem->FileExists( strFullpath ) )
		{
			kvCaptions = new KeyValues( strFullpath );

			if ( kvCaptions )
			{
				if ( kvCaptions->LoadFromFile( g_pFullFileSystem, strFullpath ) )
				{
					for ( KeyValues *pData = kvCaptions->GetFirstSubKey(); pData != NULL; pData = pData->GetNextKey() )
					{
						CVideoCaption *pCaption = new CVideoCaption;
						if ( pCaption )
						{
							pCaption->m_pszString = ReadAndAllocStringValue( pData, "string" );
							pCaption->m_flStartTime = pData->GetFloat( "start", 0.0 );
							pCaption->m_flDisplayTime = pData->GetFloat( "length", 3.0 );

							m_Captions.AddToTail( pCaption );

							// we have at least one caption to show
							bSuccess = true;
						}
					}
				}

				kvCaptions->deleteThis();
			}
		}
	}

	if ( bSuccess )
	{
		// sort the captions so we show them in the correct order (they're not necessarily in order in the .res file)
		m_Captions.Sort( CaptionsSort );
	}

	return bSuccess;
}
KeyValues* ReadEncryptedKVPlayerClassFile( IFileSystem *filesystem, const char *szFilenameWithoutExtension, const unsigned char *pICEKey )
{
	Assert( strchr( szFilenameWithoutExtension, '.' ) == NULL );
	char szFullName[512];

	// Open the weapon data file, and abort if we can't
	KeyValues *pKV = new KeyValues( "PlayerClassDatafile" );

	Q_snprintf(szFullName,sizeof(szFullName), "%s.txt", szFilenameWithoutExtension);

	if ( !pKV->LoadFromFile( filesystem, szFullName, "GAME" ) ) // try to load the normal .txt file first
	{
		if ( pICEKey )
		{
			Q_snprintf(szFullName,sizeof(szFullName), "%s.ctx", szFilenameWithoutExtension); // fall back to the .ctx file

			FileHandle_t f = filesystem->Open( szFullName, "rb", "GAME");

			if (!f)
			{
				pKV->deleteThis();
				return NULL;
			}
			// load file into a null-terminated buffer
			int fileSize = filesystem->Size(f);
			char *buffer = (char*)MemAllocScratch(fileSize + 1);
		
			Assert(buffer);
		
			filesystem->Read(buffer, fileSize, f); // read into local buffer
			buffer[fileSize] = 0; // null terminate file as EOF
			filesystem->Close( f );	// close file after reading

			UTIL_DecodeICE( (unsigned char*)buffer, fileSize, pICEKey );

			bool retOK = pKV->LoadFromBuffer( szFullName, buffer, filesystem );

			MemFreeScratch();

			if ( !retOK )
			{
				pKV->deleteThis();
				return NULL;
			}
		}
		else
		{
			pKV->deleteThis();
			return NULL;
		}
	}

	return pKV;
}