当前位置: 首页>>代码示例>>C++>>正文


C++ KeyValues::LoadFromBuffer方法代码示例

本文整理汇总了C++中KeyValues::LoadFromBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ KeyValues::LoadFromBuffer方法的具体用法?C++ KeyValues::LoadFromBuffer怎么用?C++ KeyValues::LoadFromBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KeyValues的用法示例。


在下文中一共展示了KeyValues::LoadFromBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: smn_StringToKeyValues

static cell_t smn_StringToKeyValues(IPluginContext *pCtx, const cell_t *params)
{
	Handle_t hndl = static_cast<Handle_t>(params[1]);
	HandleError herr;
	HandleSecurity sec;
	KeyValueStack *pStk;
	KeyValues *kv;

	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);
	}

	char *buffer;
	char *resourceName;
	pCtx->LocalToString(params[2], &buffer);
	pCtx->LocalToString(params[3], &resourceName);

	kv = pStk->pCurRoot.front();
	return kv->LoadFromBuffer(resourceName, buffer);
}
开发者ID:404UserNotFound,项目名称:sourcemod,代码行数:25,代码来源:smn_keyvalues.cpp

示例2: ParseFile

//
// 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;
}
开发者ID:Entropy-Soldier,项目名称:ges-legacy-code,代码行数:36,代码来源:script_parser.cpp

示例3: FindPoseCycle

static float FindPoseCycle( StudioModel *model, int sequence )
{
	float cycle = 0.0f;
	if ( !model->GetStudioHdr() )
		return cycle;

	KeyValues *seqKeyValues = new KeyValues("");
	if ( seqKeyValues->LoadFromBuffer( model->GetFileName( ), model->GetKeyValueText( sequence ) ) )
	{
		// Do we have a build point section?
		KeyValues *pkvAllFaceposer = seqKeyValues->FindKey("faceposer");
		if ( pkvAllFaceposer )
		{
			int thumbnail_frame = pkvAllFaceposer->GetInt( "thumbnail_frame", 0 );
			if ( thumbnail_frame )
			{
				// Convert frame to cycle if we have valid data
				int maxFrame = model->GetNumFrames( sequence ) - 1;

				if ( maxFrame > 0 )
				{
					cycle = thumbnail_frame / (float)maxFrame;
				}
			}
		}
	}

	seqKeyValues->deleteThis();

	return cycle;
}
开发者ID:DeadZoneLuna,项目名称:SourceEngine2007,代码行数:31,代码来源:faceposer_models.cpp

示例4: CreateVPhysics

//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
bool CNPC_Furniture::CreateVPhysics( void )
{
#ifndef HL2_DLL
	return false;
#endif

	if ( !m_BoneFollowerManager.GetNumBoneFollowers() )
	{
		KeyValues *modelKeyValues = new KeyValues("");
		if ( modelKeyValues->LoadFromBuffer( modelinfo->GetModelName( GetModel() ), modelinfo->GetModelKeyValueText( GetModel() ) ) )
		{
			// Do we have a bone follower section?
			KeyValues *pkvBoneFollowers = modelKeyValues->FindKey("bone_followers");
			if ( pkvBoneFollowers )
			{
				// Loop through the list and create the bone followers
				KeyValues *pBone = pkvBoneFollowers->GetFirstSubKey();
				while ( pBone )
				{
					// Add it to the list
					const char *pBoneName = pBone->GetString();
					m_BoneFollowerManager.AddBoneFollower( this, pBoneName );

					pBone = pBone->GetNextKey();
				}
			}
		}
		modelKeyValues->deleteThis();
	}

	return true;
}
开发者ID:Au-heppa,项目名称:source-sdk-2013,代码行数:35,代码来源:genericmonster.cpp

示例5: LoadFVars

/**
 * @brief Initializes all file variables from the file variable database.
 */
void CRPG_FileVar::LoadFVars(void) {
    char *fvdb_path, *buf;
    unsigned int fsize;
    FILE *fptr;
    KeyValues *kv;

    if(!ll_count)
        return;

    fvdb_path = (char*)calloc(512, sizeof(char));
    s_engine->GetGameDir(fvdb_path, 256);

#ifdef WIN32
    CRPG::snprintf(fvdb_path, 512, "%s\\cfg\\cssrpg\\", fvdb_path);
#else
    CRPG::snprintf(fvdb_path, 512, "%s/cfg/cssrpg/", fvdb_path);
#endif

    s_filesystem->CreateDirHierarchy(fvdb_path);
    CRPG::snprintf(fvdb_path, 512, "%s%s", fvdb_path, FVAR_DBNAME);

    fptr = fopen(fvdb_path, "rb");
    if(!fptr) {
        CRPG::ConsoleMsg("No file variable database located at \"%s\", using default values", MTYPE_WARNING, fvdb_path);
        free(fvdb_path);
        return ;
    }

    /* Get the file variable database size for allocation */
    fseek(fptr, 0, SEEK_END);
    fsize = ftell(fptr);
    rewind(fptr);

    buf = (char*)calloc(fsize+1, sizeof(char));
    fread(buf, sizeof(char), fsize, fptr);
    fclose(fptr);

    /* Check for "EF BB BF" UTF-8 BOM */
    if(!memcmp(buf, "\xEF\xBB\xBF", 3))
        buf += 3;

    /* Load the file variable database into a KeyValues class */
    kv = new KeyValues(FVAR_DBNAME);
    kv->UsesEscapeSequences(true);
    if(!kv->LoadFromBuffer(FVAR_DBNAME, buf)) {
        CRPG::ConsoleMsg("Failed to parse file variable database \"%s\", using default values", MTYPE_WARNING, fvdb_path);
        kv->deleteThis();
        free(buf);
        free(fvdb_path);
        return ;
    }

    parse_fvdb(kv);

    kv->deleteThis();
    free(buf);
    free(fvdb_path);
    return ;
}
开发者ID:jameslk,项目名称:cssrpg-archive,代码行数:62,代码来源:cssrpg_fvars.cpp

示例6: ReadEncryptedKVPlayerClassFile

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;
}
开发者ID:Au-heppa,项目名称:source-sdk-2013,代码行数:54,代码来源:playerclass_info_parse.cpp

示例7: GetModelPtr

//-----------------------------------------------------------------------------
// Purpose:
// Input  :
// Output :
//-----------------------------------------------------------------------------
KeyValues *CAnimating::GetSequenceKeyValues( int iSequence )
{
	const char *szText = Studio_GetKeyValueText( GetModelPtr(), iSequence );

	if (szText)
	{
		KeyValues *seqKeyValues = new KeyValues("");
		if ( seqKeyValues->LoadFromBuffer( modelinfo->GetModelName( GetModel() ), szText ) )
		{
			return seqKeyValues;
		}
		seqKeyValues->deleteThis();
	}
	return NULL;
}
开发者ID:KissLick,项目名称:sourcemod-npc-in-css,代码行数:20,代码来源:CAnimating.cpp

示例8: CreateBuildPoints

//-----------------------------------------------------------------------------
// Purpose: Parse our model and create the buildpoints in it
//-----------------------------------------------------------------------------
void CBaseObject::CreateBuildPoints( void )
{
	// Clear out any existing build points
	m_BuildPoints.RemoveAll();

	KeyValues * modelKeyValues = new KeyValues("");
	if ( !modelKeyValues->LoadFromBuffer( modelinfo->GetModelName( GetModel() ), modelinfo->GetModelKeyValueText( GetModel() ) ) )
	{
		return;
	}

	// Do we have a build point section?
	KeyValues *pkvAllBuildPoints = modelKeyValues->FindKey("build_points");
	if ( pkvAllBuildPoints )
	{
		KeyValues *pkvBuildPoint = pkvAllBuildPoints->GetFirstSubKey();
		while ( pkvBuildPoint )
		{
			// Find the attachment first
			const char *sAttachment = pkvBuildPoint->GetName();
			int iAttachmentNumber = LookupAttachment( sAttachment );
			if ( iAttachmentNumber )
			{
				AddAndParseBuildPoint( iAttachmentNumber, pkvBuildPoint );
			}
			else
			{
				Msg( "ERROR: Model %s specifies buildpoint %s, but has no attachment named %s.\n", STRING(GetModelName()), pkvBuildPoint->GetString(), pkvBuildPoint->GetString() );
			}

			pkvBuildPoint = pkvBuildPoint->GetNextKey();
		}
	}

	// Any virtual build points (build points that aren't on an attachment)?
	pkvAllBuildPoints = modelKeyValues->FindKey("virtual_build_points");
	if ( pkvAllBuildPoints )
	{
		KeyValues *pkvBuildPoint = pkvAllBuildPoints->GetFirstSubKey();
		while ( pkvBuildPoint )
		{
			AddAndParseBuildPoint( -1, pkvBuildPoint );
			pkvBuildPoint = pkvBuildPoint->GetNextKey();
		}
	}

	modelKeyValues->deleteThis();
}
开发者ID:staticfox,项目名称:TF2Classic,代码行数:51,代码来源:baseobject_shared.cpp

示例9: Unserialize

//-----------------------------------------------------------------------------
// Main entry point for the unserialization
//-----------------------------------------------------------------------------
bool CImportKeyValueBase::Unserialize( CUtlBuffer &buf, const char *pEncodingName, int nEncodingVersion,
									   const char *pSourceFormatName, int nSourceFormatVersion,
									   DmFileId_t fileid, DmConflictResolution_t idConflictResolution, CDmElement **ppRoot )
{
	*ppRoot = NULL;
	m_pFileName = g_pDataModel->GetFileName( fileid );

	KeyValues *kv = new KeyValues( "dmx file" );
	if ( !kv )
		return false;

	bool bOk = kv->LoadFromBuffer( "dmx file", buf );
	if ( bOk )
	{
		*ppRoot = UnserializeFromKeyValues( kv );
	}

	kv->deleteThis();
	return bOk;
}
开发者ID:Axitonium,项目名称:SourceEngine2007,代码行数:23,代码来源:importkeyvaluebase.cpp

示例10: HasPhysgunInteraction

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
bool CRagdollProp::HasPhysgunInteraction( const char *pszKeyName, const char *pszValue )
{
	KeyValues *modelKeyValues = new KeyValues("");
	if ( modelKeyValues->LoadFromBuffer( modelinfo->GetModelName( GetModel() ), modelinfo->GetModelKeyValueText( GetModel() ) ) )
	{
		KeyValues *pkvPropData = modelKeyValues->FindKey("physgun_interactions");
		if ( pkvPropData )
		{
			char const *pszBase = pkvPropData->GetString( pszKeyName );

			if ( pszBase && pszBase[0] && !stricmp( pszBase, pszValue ) )
			{
				modelKeyValues->deleteThis();
				return true;
			}
		}
	}

	modelKeyValues->deleteThis();
	return false;
}
开发者ID:paralin,项目名称:hl2sdk,代码行数:23,代码来源:physics_prop_ragdoll.cpp

示例11: KeyValues

	IMap<String> *PlayerBinder::_ParseKVToMap(const char *propertiesData) {
		KeyValues *keyValues = new KeyValues("Properties");
		keyValues->LoadFromBuffer("Properties", propertiesData);

		IMap<String> *properties = new Map<String>();

		KeyValues *subKey = keyValues->GetFirstSubKey();
				
		while(subKey != NULL) {
			const char *n = subKey->GetName();
			const char *v = subKey->GetString();
				
			properties->SetValue(n, v);

			subKey = subKey->GetNextKey();
		}

		keyValues->deleteThis();

		return properties;
	}
开发者ID:AnthonyIacono,项目名称:War3SourceV2,代码行数:21,代码来源:PlayerBinder.cpp

示例12: ParsePropData

//-----------------------------------------------------------------------------
// Purpose: Parse this prop's data from the model, if it has a keyvalues section.
//			Returns true only if this prop is using a model that has a prop_data section that's invalid.
//-----------------------------------------------------------------------------
int C_PhysPropClientside::ParsePropData( void )
{
	KeyValues *modelKeyValues = new KeyValues("");
	if ( !modelKeyValues->LoadFromBuffer( modelinfo->GetModelName( GetModel() ), modelinfo->GetModelKeyValueText( GetModel() ) ) )
	{
		modelKeyValues->deleteThis();
		return PARSE_FAILED_NO_DATA;
	}

	// Do we have a props section?
	KeyValues *pkvPropData = modelKeyValues->FindKey("prop_data");
	if ( !pkvPropData )
	{
		modelKeyValues->deleteThis();
		return PARSE_FAILED_NO_DATA;
	}

	int iResult = g_PropDataSystem.ParsePropFromKV( this, pkvPropData, modelKeyValues );
	modelKeyValues->deleteThis();
	return iResult;
}
开发者ID:Au-heppa,项目名称:source-sdk-2013,代码行数:25,代码来源:physpropclientside.cpp

示例13: sizeof

CRC32_t IFaceposerModels::CFacePoserModel::GetBitmapCRC( int sequence )
{
	CStudioHdr *hdr = m_pModel ? m_pModel->GetStudioHdr() : NULL;
	if ( !hdr )
		return (CRC32_t)-1;

	if ( sequence < 0 || sequence >= hdr->GetNumSeq() )
		return (CRC32_t)-1;

	mstudioseqdesc_t &seqdesc = hdr->pSeqdesc( sequence );

	CRC32_t crc;
	CRC32_Init( &crc );

	// For sequences, we'll checsum a bit of data

	CRC32_ProcessBuffer( &crc, (void *)seqdesc.pszLabel(), Q_strlen( seqdesc.pszLabel() ) );
	CRC32_ProcessBuffer( &crc, (void *)seqdesc.pszActivityName(), Q_strlen( seqdesc.pszActivityName() ) );
	CRC32_ProcessBuffer( &crc, (void *)&seqdesc.flags, sizeof( seqdesc.flags ) );
	//CRC32_ProcessBuffer( &crc, (void *)&seqdesc.numevents, sizeof( seqdesc.numevents ) );
	CRC32_ProcessBuffer( &crc, (void *)&seqdesc.numblends, sizeof( seqdesc.numblends ) );
	CRC32_ProcessBuffer( &crc, (void *)seqdesc.groupsize, sizeof( seqdesc.groupsize ) );

	KeyValues *seqKeyValues = new KeyValues("");
	if ( seqKeyValues->LoadFromBuffer( m_pModel->GetFileName( ), m_pModel->GetKeyValueText( sequence ) ) )
	{
		// Yuck, but I need it in a contiguous block of memory... oh well...
		CUtlBuffer buf;
		seqKeyValues->RecursiveSaveToFile( buf, 0 );
		CRC32_ProcessBuffer( &crc, ( void * )buf.Base(), buf.TellPut() );
	}

	seqKeyValues->deleteThis();

	CRC32_Final( &crc );

	return crc;
}
开发者ID:DeadZoneLuna,项目名称:SourceEngine2007,代码行数:38,代码来源:faceposer_models.cpp

示例14: ReadKeyValuesFile

KeyValues* ReadKeyValuesFile( const char *pFilename )
{
	// Read in the gameinfo.txt file and null-terminate it.
	FILE *fp = fopen( pFilename, "rb" );
	if ( !fp )
		return NULL;
	CUtlVector<char> buf;
	fseek( fp, 0, SEEK_END );
	buf.SetSize( ftell( fp ) + 1 );
	fseek( fp, 0, SEEK_SET );
	fread( buf.Base(), 1, buf.Count()-1, fp );
	fclose( fp );
	buf[buf.Count()-1] = 0;

	KeyValues *kv = new KeyValues( "" );
	if ( !kv->LoadFromBuffer( pFilename, buf.Base() ) )
	{
		kv->deleteThis();
		return NULL;
	}
	
	return kv;
}
开发者ID:SizzlingStats,项目名称:hl2sdk-ob-valve,代码行数:23,代码来源:filesystem_init.cpp

示例15: CheckSequenceType

bool CEventPropertiesGestureDialog::CheckSequenceType( StudioModel *model, int iSequence, char *szType )
{
	KeyValues *seqKeyValues = new KeyValues("");
	bool isType = false;
	if ( seqKeyValues->LoadFromBuffer( model->GetFileName( ), model->GetKeyValueText( iSequence ) ) )
	{
		// Do we have a build point section?
		KeyValues *pkvAllFaceposer = seqKeyValues->FindKey("faceposer");
		if ( pkvAllFaceposer )
		{
			KeyValues *pkvType = pkvAllFaceposer->FindKey("type");

			if (pkvType)
			{
				isType = (stricmp( pkvType->GetString(), szType ) == 0) ? true : false;
			}
		}
	}

	seqKeyValues->deleteThis();

	return isType;
}
开发者ID:DeadZoneLuna,项目名称:SourceEngine2007,代码行数:23,代码来源:eventproperties_gesture.cpp


注:本文中的KeyValues::LoadFromBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。