void CreateWorldVertexTransitionPatchedMaterial( const char *pOriginalMaterialName, const char *pPatchedMaterialName )
{
	KeyValues *kv = LoadMaterialKeyValues( pOriginalMaterialName, 0 );
	if( kv )
	{
		// change shader to Lightmappedgeneric (from worldvertextransition*)
		kv->SetName( "LightmappedGeneric" );
		// don't need no stinking $basetexture2 or any other second texture vars
		RemoveKey( kv, "$basetexture2" );
		RemoveKey( kv, "$bumpmap2" );
		RemoveKey( kv, "$bumpframe2" );
		RemoveKey( kv, "$basetexture2noenvmap" );
		RemoveKey( kv, "$blendmodulatetexture" );
		RemoveKey( kv, "$maskedblending" );
		RemoveKey( kv, "$surfaceprop2" );
		// If we didn't want a basetexture on the first texture in the blend, we don't want an envmap at all.
		KeyValues *basetexturenoenvmap = kv->FindKey( "$BASETEXTURENOENVMAP" );
		if( basetexturenoenvmap->GetInt() )
		{
			RemoveKey( kv, "$envmap" );
		}

		Warning( "Patching WVT material: %s\n", pPatchedMaterialName );
		WriteMaterialKeyValuesToPak( pPatchedMaterialName, kv );
	}
}
Ejemplo n.º 2
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();
	}
}
Ejemplo n.º 3
0
/*
	CUtlVector< SimpleTexture* > hList_Textures;
	CUtlVector< SimpleCombo* > hList_Combos;
	CUtlVector< SimpleEnvConstant* > hList_EConstants;
*/
void df_SaveDump_File( const char *canvasname, const BasicShaderCfg_t &shader )
{
	KeyValues *pKV = new KeyValues( canvasname );
	char _path[MAX_PATH];
	Q_snprintf( _path, MAX_PATH, "%s/%s.dump", ::GetDumpDirectory(), canvasname );
	Q_FixSlashes( _path );

	pKV->SetString( "vs_name", shader.ProcVSName );
	pKV->SetString( "ps_name", shader.ProcPSName );
	pKV->SetString( "shader_filename", shader.Filename );
	pKV->SetString( GetDumpVersion_KeyName(), GetDumpVersion_Current() );

	pKV->SetInt( "i_sm", shader.iShaderModel );
	pKV->SetInt( "i_cull", shader.iCullmode );
	pKV->SetInt( "i_ablend", shader.iAlphablendmode );
	pKV->SetFloat( "fl_atestref", shader.flAlphaTestRef );
	pKV->SetInt( "i_dtest", shader.iDepthtestmode );
	pKV->SetInt( "i_dwrite", shader.iDepthwritemode );
	pKV->SetInt( "i_srgbw", shader.bsRGBWrite ? 1 : 0 );
	
	pKV->SetInt( "i_vfmt_flags", shader.iVFMT_flags );
	pKV->SetInt( "i_vfmt_texcoords", shader.iVFMT_numTexcoords );
	pKV->SetInt( "i_vfmt_udata", shader.iVFMT_numUserData );
	for ( int i = 0; i < 3; i++ )
	{
		char tmp[48];
		Q_snprintf( tmp, sizeof(tmp), "i_vfmt_texcoordDim_%i", i );
		pKV->SetInt( tmp, shader.iVFMT_texDim[i] );
	}

	pKV->SetInt( "i_vlit", shader.bVertexLighting );
	pKV->SetInt( "i_vrefract", shader.bRefractionSupport );

	KeyValues *pKVIdentVS = __AllocKV_Identifiers( shader.pVS_Identifiers );
	pKVIdentVS->SetName( "identifiers_VS" );
	pKV->AddSubKey( pKVIdentVS );

	KeyValues *pKVIdentPS = __AllocKV_Identifiers( shader.pPS_Identifiers );
	pKVIdentPS->SetName( "identifiers_PS" );
	pKV->AddSubKey( pKVIdentPS );

	pKV->SaveToFile( g_pFullFileSystem, _path, "MOD" );
	pKV->deleteThis();
}
Ejemplo n.º 4
0
void CBaseMapsPage::SetListCellColors(MapData *pData, KeyValues *pKvInto)
{
    KeyValues *pCellColor = new KeyValues("cellcolor");
    // KeyValues *pCellBGColor = new KeyValues("cellbgcolor");
    KeyValues *pSub = pCellColor->CreateNewKey();
    pSub->SetName(CFmtStr("%i", HEADER_MAP_NAME));
    pSub->SetColor("color", pData->m_bInLibrary ? COLOR_BLUE : COLOR_WHITE);
    // pCellBGColor->AddSubKey(pSub->MakeCopy());
    pKvInto->AddSubKey(pCellColor);
    // pKvInto->AddSubKey(pCellBGColor);
}
//---------------------------------------------------------------------
// Purpose: Send all properties and contexts to the matchmaking session
//---------------------------------------------------------------------
void CSessionOptionsDialog::SetupSession( void )
{
	KeyValues *pKeys = new KeyValues( "SessionKeys" );

	// Send user-selected properties and contexts
	for ( int i = 0; i < m_Menu.GetItemCount(); ++i )
	{
		COptionsItem *pItem = dynamic_cast< COptionsItem* >( m_Menu.GetItem( i ) );
		if ( !pItem )
		{                    
			continue;
		}		

		const sessionProperty_t &prop = pItem->GetActiveOption();

		KeyValues *pProperty = pKeys->CreateNewKey();
		pProperty->SetName( prop.szID );
		pProperty->SetInt( "type", prop.nType );
		pProperty->SetString( "valuestring", prop.szValue );
		pProperty->SetString( "valuetype", prop.szValueType );
		pProperty->SetInt( "optionindex", pItem->GetActiveOptionIndex() );
	}

	// Send contexts and properties parsed from the resource file
	for ( int i = 0; i < m_SessionProperties.Count(); ++i )
	{
		const sessionProperty_t &prop = m_SessionProperties[i];

		KeyValues *pProperty = pKeys->CreateNewKey();
		pProperty->SetName( prop.szID );
		pProperty->SetInt( "type", prop.nType );
		pProperty->SetString( "valuestring", prop.szValue );
		pProperty->SetString( "valuetype", prop.szValueType );
	}

	// Matchmaking will make a copy of these keys
	matchmaking->SetSessionProperties( pKeys );
	pKeys->deleteThis();
}
Ejemplo n.º 6
0
bool KeyValues::ProcessResolutionKeys(const char *pResString)
{
	if (!pResString)
		return false;

	KeyValues *pSubKey = GetFirstSubKey();

	if (!pSubKey)
		return false;

	for ( ; pSubKey != NULL; pSubKey = pSubKey->GetNextKey())
	{
		pSubKey->ProcessResolutionKeys(pResString);

		if (Q_stristr(pSubKey->GetName(), pResString) != NULL)
		{
			char normalKeyName[128];
			V_strncpy(normalKeyName, pSubKey->GetName(), sizeof(normalKeyName));

			char *pString = Q_stristr(normalKeyName, pResString);

			if (pString && !Q_stricmp(pString, pResString))
			{
				*pString = '\0';

				KeyValues *pKey = FindKey(normalKeyName);

				if (pKey)
				{
					RemoveSubKey(pKey);
				}

				pSubKey->SetName(normalKeyName);
			}
		}
	}

	return true;
}
Ejemplo n.º 7
0
static cell_t smn_KvSetSectionName(IPluginContext *pCtx, const cell_t *params)
{
	Handle_t hndl = static_cast<Handle_t>(params[1]);
	HandleError herr;
	HandleSecurity sec;
	char *name;
	KeyValueStack *pStk;

	sec.pOwner = NULL;
	sec.pIdentity = g_pCoreIdent;

	if ((herr=handlesys->ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
		!= HandleError_None)
	{
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
	}

	pCtx->LocalToString(params[2], &name);

	KeyValues *pSection = pStk->pCurRoot.front();
	pSection->SetName(name);

	return 1;
}
bool CCompiledKeyValuesReader::CreateInPlaceFromData( KeyValues& head, const FileInfo_t& info )
{
	int first = info.nFirstIndex;
	int num = info.nCount;

	KeyValues *root = NULL;
	KeyValues *tail = NULL;

	CUtlRBTree< CreateHelper_t, int >	helper( 0, 0, CreateHelper_t::Less );

	for ( int i = 0; i < num; ++i )
	{
		int offset = first + i;
		KVInfo_t& info = m_Data[ offset ];

		if ( info.GetParent() != -1 )
		{
			CreateHelper_t search;
			search.index = info.GetParent();
			int idx = helper.Find( search );
			if ( idx == helper.InvalidIndex() )
			{
				return false;
			}

			KeyValues *parent = helper[ idx ].kv;
			Assert( parent );

			KeyValues *sub = new KeyValues( m_StringTable.Lookup( info.key ) );

			if ( !info.IsSubTree() )
			{
				sub->SetStringValue(m_StringTable.Lookup( info.value ) );
			}

			if ( !parent->GetFirstSubKey() )
			{
				parent->AddSubKey( sub );
			}
			else
			{
				KeyValues *last = helper[ idx ].tail;
				last->SetNextKey( sub );
			}

			helper[ idx ].tail = sub;

			CreateHelper_t insert;
			insert.index = offset;
			insert.kv = sub;
			insert.tail = NULL;
			helper.Insert( insert );
		}
		else
		{
			if ( !root )
			{
				root = &head;
				root->SetName( m_StringTable.Lookup( info.key ) );
				tail = root;

				CreateHelper_t insert;
				insert.index = offset;
				insert.kv = root;
				insert.tail = NULL;
				helper.Insert( insert );
			}
			else
			{
				CreateHelper_t insert;
				insert.index = offset;
				insert.kv = new KeyValues( m_StringTable.Lookup( info.key ) );
				insert.tail = NULL;
				helper.Insert( insert );

				tail->SetNextKey( insert.kv );
				tail = insert.kv;
			}
		}
	}
	return true;
}
Ejemplo n.º 9
0
bool KeyValues::ReadAsBinary(CUtlBuffer &buffer)
{
	if (buffer.IsText())
		return false;

	if (!buffer.IsValid())
		return false;

	RemoveEverything();
	Init();

	char token[KEYVALUES_TOKEN_SIZE];
	KeyValues *dat = this;
	types_t type = (types_t)buffer.GetUnsignedChar();

	while (true)
	{
		if (type == TYPE_NUMTYPES)
			break;

		dat->m_iDataType = type;

		buffer.GetString(token, KEYVALUES_TOKEN_SIZE - 1);
		token[KEYVALUES_TOKEN_SIZE - 1] = 0;

		dat->SetName(token);

		switch (type)
		{
			case TYPE_NONE:
			{
				dat->m_pSub = new KeyValues("");
				dat->m_pSub->ReadAsBinary(buffer);
				break;
			}

			case TYPE_STRING:
			{
				buffer.GetString(token, KEYVALUES_TOKEN_SIZE - 1);
				token[KEYVALUES_TOKEN_SIZE - 1] = 0;

				int len = Q_strlen(token);
				dat->m_sValue = new char[len + 1];
				Q_memcpy(dat->m_sValue, token, len + 1);

				break;
			}

			case TYPE_WSTRING:
			{
				Assert(!"TYPE_WSTRING");
				break;
			}

			case TYPE_INT:
			{
				dat->m_iValue = buffer.GetInt();
				break;
			}

			case TYPE_UINT64:
			{
				dat->m_sValue = new char[sizeof(uint64)];
				*((double *)dat->m_sValue) = buffer.GetDouble();
			}

			case TYPE_FLOAT:
			{
				dat->m_flValue = buffer.GetFloat();
				break;
			}

			case TYPE_COLOR:
			{
				dat->m_Color[0] = buffer.GetUnsignedChar();
				dat->m_Color[1] = buffer.GetUnsignedChar();
				dat->m_Color[2] = buffer.GetUnsignedChar();
				dat->m_Color[3] = buffer.GetUnsignedChar();
				break;
			}

			case TYPE_PTR:
			{
				dat->m_pValue = (void *)buffer.GetUnsignedInt();
			}

			default:
			{
				break;
			}
		}

		if (!buffer.IsValid())
			return false;

		type = (types_t)buffer.GetUnsignedChar();

		if (type == TYPE_NUMTYPES)
			break;

		dat->m_pPeer = new KeyValues("");
		dat = dat->m_pPeer;
	}

	return buffer.IsValid();
}
Ejemplo n.º 10
0
bool KeyValues::LoadFromBuffer(char const *resourceName, CUtlBuffer &buf, IFileSystem *pFileSystem, const char *pPathID)
{
	KeyValues *pPreviousKey = NULL;
	KeyValues *pCurrentKey = this;
	CUtlVector<KeyValues *> includedKeys;
	CUtlVector<KeyValues *> baseKeys;
	bool wasQuoted;

	g_KeyValuesErrorStack.SetFilename(resourceName);

	do
	{
		const char *s = ReadToken(buf, wasQuoted);

		if (!buf.IsValid() || !s || *s == 0)
			break;

		if (!Q_stricmp(s, "#include"))
		{
			s = ReadToken(buf, wasQuoted);

			if (!s || *s == 0)
			{
				g_KeyValuesErrorStack.ReportError("#include is NULL ");
			}
			else
			{
				ParseIncludedKeys(resourceName, s, pFileSystem, pPathID, includedKeys);
			}

			continue;
		}
		else if (!Q_stricmp(s, "#base"))
		{
			s = ReadToken(buf, wasQuoted);

			if (!s || *s == 0)
			{
				g_KeyValuesErrorStack.ReportError("#base is NULL ");
			}
			else
			{
				ParseIncludedKeys(resourceName, s, pFileSystem, pPathID, baseKeys);
			}

			continue;
		}

		if (!pCurrentKey)
		{
			pCurrentKey = new KeyValues(s);
			Assert(pCurrentKey);

			pCurrentKey->UsesEscapeSequences(m_bHasEscapeSequences != 0);

			if (pPreviousKey)
			{
				pPreviousKey->SetNextKey(pCurrentKey);
			}
		}
		else
		{
			pCurrentKey->SetName(s);
		}

		s = ReadToken(buf, wasQuoted);

		if (s && *s == '{' && !wasQuoted)
		{
			pCurrentKey->RecursiveLoadFromBuffer(resourceName, buf);
		}
		else
		{
			g_KeyValuesErrorStack.ReportError("LoadFromBuffer: missing {");
		}

		pPreviousKey = pCurrentKey;
		pCurrentKey = NULL;

	}
	while (buf.IsValid());

	AppendIncludedKeys(includedKeys);
	{
		for (int i = includedKeys.Count() - 1; i > 0; i--)
		{
			KeyValues *kv = includedKeys[i];
			kv->deleteThis();
		}
	}

	MergeBaseKeys(baseKeys);
	{
		for (int i = baseKeys.Count() - 1; i >= 0; i--)
		{
			KeyValues *kv = baseKeys[i];
			kv->deleteThis();
		}
	}

	g_KeyValuesErrorStack.SetFilename("");
	return true;
}
Ejemplo n.º 11
0
void ReloadGameShaders( GenericShaderData *data, char **pszMaterialList, int iNumMaterials )
{
	const bool bIsOverriding = !!data;
	char *CanvasName = NULL;

	if ( bIsOverriding )
	{
		const char *ShaderName = data->name;

		int SwapIndex = ::gProcShaderCTRL->FindPreloadShader( ShaderName );
		if ( SwapIndex < 0 )
		{
			const char *pszSearch = Q_stristr( data->name, "_" );
			if ( pszSearch )
			{
				const char *ShaderName_Small = pszSearch + 1;
				SwapIndex = ::gProcShaderCTRL->FindPreloadShader( ShaderName_Small );
			}
		}

		CanvasName = new char[ Q_strlen( ShaderName ) + 1 ];
		Q_strcpy( CanvasName, ShaderName );

		BasicShaderCfg_t *SwapData = new BasicShaderCfg_t( *data->shader );
		Assert( !SwapData->CanvasName );
		SwapData->CanvasName = CanvasName;

		// build shader names
		static unsigned int _HackyIndexIncrement = 0;
		{
			int len = Q_strlen( SwapData->ProcPSName ) + 2 + 7;
			char *uniquifyShader = new char[len];
			Q_snprintf( uniquifyShader, len, "%06X_%s", _HackyIndexIncrement, SwapData->ProcPSName );
			delete [] SwapData->ProcPSName;
			SwapData->ProcPSName = uniquifyShader;
		}
		{
			int len = Q_strlen( SwapData->ProcVSName ) + 2 + 7;
			char *uniquifyShader = new char[len];
			Q_snprintf( uniquifyShader, len, "%06X_%s", _HackyIndexIncrement, SwapData->ProcVSName );
			delete [] SwapData->ProcVSName;
			SwapData->ProcVSName = uniquifyShader;
		}

		char *OldName = data->name;
		char targetname[MAX_PATH];
		Q_snprintf( targetname, MAX_PATH, "%06X_%s", _HackyIndexIncrement, OldName );

		// copy vcs files
		char __path_compiler[MAX_PATH];
		char __path_engine[MAX_PATH];
		ComposeShaderPath_Compiled( data, false, true, __path_compiler, MAX_PATH );
		data->name = targetname;
		ComposeShaderPath_CompiledEngine( data, false, true, __path_engine, MAX_PATH );
		EngineCopy( __path_compiler, __path_engine );

		data->name = OldName;
		ComposeShaderPath_Compiled( data, true, true, __path_compiler, MAX_PATH );
		data->name = targetname;
		ComposeShaderPath_CompiledEngine( data, true, true, __path_engine, MAX_PATH );
		EngineCopy( __path_compiler, __path_engine );


		data->name = OldName;
		_HackyIndexIncrement++;

		if ( SwapIndex >= 0 )
		{
			// swap shader data
			BasicShaderCfg_t *trash = (BasicShaderCfg_t*)gProcShaderCTRL->SwapPreloadShader( SwapIndex, SwapData );
			delete trash;
		}
		else
			gProcShaderCTRL->AddPreloadShader( SwapData );
	}

	// reload materials
	if ( pszMaterialList && iNumMaterials )
	{
		for ( int i = 0; i < iNumMaterials; i++ )
		{
			IMaterial *pMat = materials->FindMaterial( pszMaterialList[i], TEXTURE_GROUP_MODEL );
			if ( IsErrorMaterial( pMat ) )
				continue;

			KeyValues *pKV = new KeyValues( "" );
			char tmppath[ MAX_PATH ];
			Q_snprintf( tmppath, MAX_PATH, "materials/%s.vmt", pszMaterialList[i] );
			if ( !pKV->LoadFromFile( g_pFullFileSystem, tmppath ) )
			{
				pKV->deleteThis();
				continue;
			}

			if ( bIsOverriding )
			{
				pKV->SetName( "EDITOR_SHADER" );
				pKV->SetString( "$SHADERNAME", CanvasName );
			
				const char *curEnvmap = pKV->GetString( "$envmap" );
				if ( !curEnvmap || !*curEnvmap )
					pKV->SetString( "$envmap", "env_cubemap" );
			}
			else
				UnpackMaterial( pKV );

			pMat->SetShaderAndParams( pKV );

			pMat->Refresh();
			pMat->RecomputeStateSnapshots();

			pKV->deleteThis();
		}
		return;
	}

	if ( !bIsOverriding )
		return;

	QuickRefreshEditorShader();
}