void CAntiCheatManager::LoadAntiCheatVars(XmlNodeRef child) { int numVars = child->getChildCount(); for (int i=0; i<numVars; ++i) { XmlNodeRef varsChild = child->getChild(i); if (varsChild->isTag("Var")) { const char* sVarName = varsChild->getAttr("name"); TAntiCheatVarIdx antiCheatVarIdx = FindAntiCheatVarIdx_Float(sVarName); if (antiCheatVarIdx != eAV_Invalid_Float) { varsChild->getAttr("value", m_cheatVarsFloat[antiCheatVarIdx]); } else { antiCheatVarIdx = FindAntiCheatVarIdx_Int(sVarName); if (antiCheatVarIdx != eAV_Invalid_Int) { varsChild->getAttr("value", m_cheatVarsInt[antiCheatVarIdx]); } else { CryLog("Unrecognised anti cheat var '%s'", sVarName); } } } else { CryLog("Unrecognised child node '%s'", varsChild->getTag()); } } }
// Loads equipment packs from rootNode void CEquipmentManager::LoadEquipmentPacks(const XmlNodeRef& rootNode) { MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Equipment Packs"); if (rootNode->isTag("EquipPacks") == false) return; for (int i=0; i<rootNode->getChildCount(); ++i) { XmlNodeRef packNode = rootNode->getChild(i); LoadEquipmentPack(packNode, true); } }
//--------------------------------------- void CMiscAnnouncer::InitXML(XmlNodeRef root) { IEntityClassRegistry *pEntityClassRegistry = gEnv->pEntitySystem->GetClassRegistry(); XmlNodeRef onWeaponFiringRoot = root->findChild("OnWeaponFiring"); CryLog("CMiscAnnouncer::InitXML()"); if(onWeaponFiringRoot) { const int numChildren = onWeaponFiringRoot->getChildCount(); CryLog("CMiscAnnouncer::InitXML() found OnWeaponFiringRoot with %d children", numChildren); for(int i=0; i<numChildren; ++i) { XmlNodeRef child = onWeaponFiringRoot->getChild(i); if(child->isTag("OnWeaponFired")) { const char *pWeaponClassName = child->getAttr("weaponClass"); CRY_ASSERT(pWeaponClassName && pWeaponClassName[0] != 0); CryLog("CMiscAnnouncer::InitXML() OnWeaponFired tag - pWeaponClassName=%s", pWeaponClassName ? pWeaponClassName : "NULL"); if(IEntityClass* pWeaponEntityClass = pEntityClassRegistry->FindClass(pWeaponClassName)) { const char *pAnnouncement = child->getAttr("announcement"); CRY_ASSERT(pAnnouncement && pAnnouncement[0] != 0); EAnnouncementID announcementID = CAnnouncer::NameToID(pAnnouncement); CryLog("CMiscAnnouncer::InitXML() found weapon entity class for pWeaponClassName=%s; found pAnnouncement=%s announcementID=%x", pWeaponClassName, pAnnouncement ? pAnnouncement : "NULL", announcementID); SOnWeaponFired newWeaponFired(pWeaponEntityClass, pAnnouncement, announcementID); m_weaponFiredMap.insert(TWeaponFiredMap::value_type(pWeaponEntityClass, newWeaponFired)); } else { CryLog("CMiscAnnouncer::InitXML() failed to find entityClass for pWeaponClassName=%s", pWeaponClassName); CRY_ASSERT_MESSAGE(0, string().Format("CMiscAnnouncer::InitXML() failed to find entityClass for pWeaponClassName=%s", pWeaponClassName)); } } else { CryLog("CMiscAnnouncer::InitXML() unhandled childtag of %s found", child->getTag()); } } } }
void CEntityClassRegistry::LoadClassDescription( XmlNodeRef &root,bool bOnlyNewClasses ) { assert( root != (IXmlNode*)NULL ); if (root->isTag("Entity")) { const char *sName = root->getAttr("Name"); if (*sName == 0) return; // Empty name. const char *sScript = root->getAttr("Script"); IEntityClass *pClass = FindClass( sName ); if (!pClass) { // New class. SEntityClassDesc cd; cd.flags = 0; cd.sName = sName; cd.sScriptFile = sScript; bool bInvisible = false; if (root->getAttr("Invisible",bInvisible)) { if (bInvisible) cd.flags |= ECLF_INVISIBLE; } bool bBBoxSelection = false; if (root->getAttr("BBoxSelection",bBBoxSelection)) { if (bBBoxSelection) cd.flags |= ECLF_BBOX_SELECTION; } RegisterStdClass( cd ); } else { // This class already registered. if (!bOnlyNewClasses) { EntityWarning( "[CEntityClassRegistry] LoadClassDescription failed, Entity Class name %s already registered",sName ); } } } }
bool CCommonSaveGameHelper::FetchMetaData(XmlNodeRef& root, CPlayerProfileManager::SSaveGameMetaData& metaData) { // TODO: use CXmlLoadGame for this XmlNodeRef metaDataNode = root; if (metaDataNode->isTag("Metadata") == false) metaDataNode = root->findChild("Metadata"); if (metaDataNode == 0) return false; bool ok = true; ok &= GetAttr(metaDataNode, "level", metaData.levelName); ok &= GetAttr(metaDataNode, "gameRules", metaData.gameRules); ok &= GetAttr(metaDataNode, "version", metaData.fileVersion); ok &= GetAttr(metaDataNode, "build", metaData.buildVersion); ok &= GetTimeAttr(metaDataNode, "saveTime", metaData.saveTime); metaData.loadTime = metaData.saveTime; metaData.xmlMetaDataNode = metaDataNode; return ok; }
bool CDialogLoader::LoadScript(const string& filename, TDialogScriptMap& outScriptMap) { // parse MS Excel spreadsheet XmlNodeRef rootNode = GetISystem()->LoadXmlFromFile(filename); if (!rootNode) { GameWarning("[DIALOG] CDialogLoader::LoadScripts: Cannot find file '%s'", filename.c_str()); return false; } // iterate over all children and load all worksheets int nChilds = rootNode->getChildCount(); if (nChilds == 0) { GameWarning("[DIALOG] CDialogLoader::LoadScripts: Cannot find any 'Worksheet's in file '%s'", filename.c_str()); return false; } int numScripts = 0; string baseName = PathUtil::GetFileName(filename); for (int i=0; i<nChilds; ++i) { XmlNodeRef childNode = rootNode->getChild(i); if (childNode && childNode->isTag("Worksheet")) { const char* wsName = childNode->getAttr("ss:Name"); XmlNodeRef tableNode = childNode->findChild("Table"); if (!tableNode) { GameWarning("[DIALOG] CDialogLoader::LoadScripts: Worksheet '%s' in file '%s' has no Table", wsName ? wsName : "<noname>", filename.c_str()); } else { const string& groupName = baseName; // maybe we add the Worksheets name later on! numScripts = LoadFromTable(tableNode, groupName, outScriptMap); break; // only load first worksheet } } } return numScripts > 0; }
void FillMapping(XmlNodeRef row, unsigned char* pIndexToAttrMap) { int nCellIndex = 0; int nNewIndex = 0; for (int cell=0; cell<row->getChildCount(); ++cell) { if (cell >= MAX_CELL_COUNT) continue; XmlNodeRef nodeCell = row->getChild(cell); if (!nodeCell->isTag("Cell")) continue; if (nodeCell->getAttr("ss:Index",nNewIndex)) { // Check if some cells are skipped. nCellIndex = nNewIndex-1; } XmlNodeRef nodeCellData = nodeCell->findChild("Data"); if (!nodeCellData) { ++nCellIndex; continue; } const char *sCellContent = nodeCellData->getContent(); for (int i = 0; i < sizeof(sColumnNames)/sizeof(*sColumnNames); ++i) { // this is a begins-with-check! if (CryStringUtils::stristr(sCellContent, sColumnNames[i]) == sCellContent) { pIndexToAttrMap[nCellIndex] = i; break; } } ++nCellIndex; } }
bool CDialogLoaderMK2::ProcessScript(CDialogScript* pScript, const XmlNodeRef& node) { CDialogScript::SScriptLine scriptLine; const char* scriptID = pScript->GetID(); string desc = node->getAttr("Description"); pScript->SetDescription(desc); for (int i=0; i<node->getChildCount(); ++i) { XmlNodeRef lineNode = node->getChild(i); if (lineNode && lineNode->isTag("Line")) { ResetLine(scriptLine); if (ReadLine (lineNode, scriptLine, scriptID, i) == true) { pScript->AddLine(scriptLine); } } } return true; }
bool CEntityPoolSignature::CompareNodes(const XmlNodeRef &a, const XmlNodeRef &b, bool bRecursive) { FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY); assert(bool(a)); assert(bool(b)); bool bResult = (a && b && a->isTag(b->getTag())); // Check value bResult &= (bResult && 0 == strcmp(a->getContent(), b->getContent())); // Check attributes bResult &= (bResult && CompareNodeAttributes(a, b)); // Check children if recursive if (bResult && bRecursive) { const int childCount_a = a->getChildCount(); const int childCount_b = b->getChildCount(); bResult &= (childCount_a == childCount_b); if (bResult) { for (int child = 0; bResult && child < childCount_a; ++child) { XmlNodeRef child_a = a->getChild(child); XmlNodeRef child_b = b->getChild(child); if (child_a && child_b) { bResult &= CompareNodes(child_a, child_b, true); } } } } return bResult; }
bool CDialogLoaderMK2::LoadScript(const string& stripPath, const string& filename, TDialogScriptMap& outScriptMap) { XmlNodeRef rootNode = GetISystem()->LoadXmlFromFile(filename); if (!rootNode) { GameWarning("[DIALOG] CDialogLoaderMK2::LoadScripts: Cannot find/load file '%s'", filename.c_str()); return false; } if (rootNode->isTag("DialogScript") == false) { GameWarning("[DIALOG] CDialogLoaderMK2::LoadScripts: File '%s' not a dialog script.", filename.c_str()); return false; } string scriptName = PathUtil::ToUnixPath(filename); // now remove prefix if (CryStringUtils::stristr(scriptName.c_str(), stripPath.c_str()) == scriptName.c_str()) scriptName = scriptName.Mid(stripPath.length()); PathUtil::RemoveExtension(scriptName); scriptName.replace('/', '.'); // Make nice uppercase name, if storedId and filename match case-insensitive const char* storedId = rootNode->getAttr("Name"); if (storedId!=0 && stricmp(storedId, scriptName.c_str()) == 0) { scriptName.assign(storedId); } CDialogScript* pScript = new CDialogScript(scriptName); bool bOK = ProcessScript(pScript, rootNode); if (bOK) { // try to complete the script if (pScript->Complete() == true) { // add it to the map std::pair<TDialogScriptMap::iterator, bool> inserted = outScriptMap.insert(TDialogScriptMap::value_type(pScript->GetID(), pScript)); if (inserted.second == false) { bOK = false; GameWarning("[DIALOG] CDialogLoaderMK2::ProcessScript '%s': Script already defined. Discarded", scriptName.c_str()); } } // completion not successful -> discard else { bOK = false; GameWarning("[DIALOG] CDialogLoaderMK2::ProcessScript '%s': Cannot complete Script. Discarded.", scriptName.c_str()); } } // discard pScript if (bOK == false) { delete pScript; } return bOK; }
bool CommunicationVoiceLibrary::LoadFromFile(const char* fileName) { MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Communication Voice Library" ); MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Other, 0, "Voice Lib: %s",fileName ); XmlNodeRef root = GetISystem()->LoadXmlFromFile(fileName); if (!root) return false; XmlNodeRef nodeWorksheet = root->findChild("Worksheet"); if (!nodeWorksheet) return false; XmlNodeRef nodeTable = nodeWorksheet->findChild("Table"); if (!nodeTable) return false; stack_string libName(PathUtil::GetFileName(fileName)); VoiceLibraryID libraryID = GetVoiceLibraryID(libName.c_str()); std::pair<VoiceLibraries::iterator, bool> iresult = m_libraries.insert( VoiceLibraries::value_type(libraryID, VoiceLibrary())); if (!iresult.second) { if (iresult.first->second.name == libName.c_str()) { AIWarningID("<AICommunicationVoiceLibrary::LoadFromFile> ", "Duplicate voice library '%s'!", libName.c_str()); return false; } else { AIWarningID("<AICommunicationVoiceLibrary::LoadFromFile> ", "Hash collision for voice library name '%s' and '%s'!", libName.c_str(), iresult.first->second.name.c_str()); return false; } } VoiceLibrary& library = iresult.first->second; library.name = string(libName); VoiceGroup* voiceGroup = 0; string signalName; string lastSignalName; string voiceName; for (int rowCntr = 0, childN = 0; childN < nodeTable->getChildCount(); ++childN) { XmlNodeRef nodeRow = nodeTable->getChild(childN); if (!nodeRow->isTag("Row")) continue; ++rowCntr; if (rowCntr == 1) // skip language continue; if (rowCntr == 2) // path { int cellN = 0; for (int childrenCntr = 0; childrenCntr < nodeRow->getChildCount(); ++childrenCntr) { XmlNodeRef nodeCell = nodeRow->getChild(childrenCntr); if (!nodeCell->isTag("Cell")) continue; ++cellN; if (cellN == 2) { XmlNodeRef nodeCellData = nodeCell->findChild("Data"); if (!nodeCellData) break; library.base = PathUtil::GetLocalizationFolder() + nodeCellData->getContent(); if (!library.base.empty()) { library.base.replace("\\", "/"); if (library.base[library.base.length()-1] != '/') library.base.append("/"); } break; } } continue; } if (rowCntr == 3) // headers continue; signalName.clear(); voiceName.clear(); for (int childrenCntr = 0, cellIndex = 1; childrenCntr < nodeRow->getChildCount(); ++childrenCntr, ++cellIndex) { XmlNodeRef nodeCell = nodeRow->getChild(childrenCntr); if (!nodeCell->isTag("Cell")) continue; if (nodeCell->haveAttr("ss:Index")) { const char* strIdx = nodeCell->getAttr("ss:Index"); if (sscanf(strIdx, "%d", &cellIndex) != 1) continue; } XmlNodeRef nodeCellData = nodeCell->findChild("Data"); if (!nodeCellData) continue; switch (cellIndex) { case 1: signalName = nodeCellData->getContent(); break; case 2: voiceName = nodeCellData->getContent(); break; } } if (!signalName.empty()) { signalName.MakeLower(); std::pair<VoiceGroups::iterator, bool> itresult = library.voiceGroups.insert( VoiceGroups::value_type(signalName, VoiceGroup())); voiceGroup = &itresult.first->second; // The 20 here comes from inspection of the resulting contents in memreplay voiceGroup->variations.reserve(20); if (!itresult.second) { if (lastSignalName != signalName) AIWarningID("<AICommunicationVoiceLibrary::LoadFromFile> ", "Duplicate voice signal '%s' in file '%s'.", signalName.c_str(), libName.c_str()); } lastSignalName = signalName; } if (!voiceGroup || voiceName.empty()) continue; if ((library.base.find_first_of(':') == string::npos) && (voiceName.find_first_of(':') == string::npos)) voiceName.append(".wav"); if (voiceGroup->variations.size() < MaxVariationCount) voiceGroup->variations.push_back(voiceName); else AIWarningID("<AICommunicationVoiceLibrary::LoadFromFile> ", "Too many voice variations for signal '%s' in file '%s'. Limit is 32.", signalName.c_str(), libName.c_str()); } return true; }
int CDialogLoader::LoadFromTable(XmlNodeRef tableNode, const string& groupName, TDialogScriptMap& outScriptMap) { unsigned char nCellIndexToType[MAX_CELL_COUNT]; memset(nCellIndexToType, ATTR_SKIP, sizeof(nCellIndexToType) ); IMScript theScript; int nNumGoodScripts = 0; int nRowIndex = 0; int nChilds = tableNode->getChildCount(); for (int i=0; i<nChilds; ++i) { XmlNodeRef rowNode = tableNode->getChild(i); if (!rowNode || !rowNode->isTag("Row")) continue; ++nRowIndex; // skip first row as it should only contain column description if (nRowIndex == 1) { FillMapping(rowNode, nCellIndexToType); continue; } IMScriptLine scriptLine; bool bLineValid = false; int nColCount = rowNode->getChildCount(); int nCellIndex = 0; for (int j=0; j<nColCount; ++j) { XmlNodeRef cellNode = rowNode->getChild(j); if (!cellNode || !cellNode->isTag("Cell")) continue; int tmpIndex = 0; if (cellNode->getAttr("ss:Index", tmpIndex)) { nCellIndex = tmpIndex-1; } if (nCellIndex < 0 || nCellIndex >= MAX_CELL_COUNT) break; XmlNodeRef cellDataNode = cellNode->findChild("Data"); if (!cellDataNode) { ++nCellIndex; continue; } unsigned char nCellType = nCellIndexToType[nCellIndex]; const char* content = cellDataNode->getContent(); // nRowIndex and nCellIndex should be correct now [1-based, not 0-based!] switch (nCellType) { case ATTR_SKIP: break; case ATTR_DIALOG: if (theScript.IsValid()) { const bool ok = ProcessScript(theScript, groupName, outScriptMap); if (ok) ++nNumGoodScripts; theScript.Reset(); } theScript.name = content; break; case ATTR_ACTOR: scriptLine.actor = content; bLineValid = true; break; case ATTR_AUDIO: if (bLineValid) { if(content == 0) scriptLine.audioID = INVALID_AUDIO_CONTROL_ID; else gEnv->pAudioSystem->GetAudioTriggerID(content, scriptLine.audioID); } break; case ATTR_ANIM: if (bLineValid) scriptLine.anim = content; break; case ATTR_FACIAL: if (bLineValid) { size_t n = strcspn(content, ":; "); if (n == strlen(content)) { scriptLine.facial = content; scriptLine.facialWeight = 0.5f; scriptLine.facialFadeTime = 0.5f; } else { scriptLine.facial.assign ( content, n ); float w = 0.5f; float t = 0.5f; int nGood = sscanf(content+n+1, "%f%*[:; ]%f",&w,&t); if (nGood != 1 && nGood != 2) { GameWarning("[DIALOG] CDialogLoader::LoadFromTable: DialogScript '%s' has invalid Facial Expression Content '%s'. Using weight=%f fadetime=%f.", groupName.c_str(), content,w,t); } scriptLine.facialWeight = w; scriptLine.facialFadeTime = t; } } break; case ATTR_LOOKAT: if (bLineValid) scriptLine.lookat = content; break; case ATTR_DELAY: if (bLineValid) { float val = 0.0f; int n = sscanf(content,"%f", &val); if (n == 1) { scriptLine.delay = val; } } break; default: break; } ++nCellIndex; } if (scriptLine.IsValid()) { theScript.lines.push_back(scriptLine); } } if (theScript.IsValid()) { const bool ok = ProcessScript(theScript, groupName, outScriptMap); if (ok) ++nNumGoodScripts; } return nNumGoodScripts; }
void CAntiCheatManager::ParseAntiCheatConfig(XmlNodeRef xmlData) { ResetAntiCheatVars(); // Reset the previous configuration so that we can call this function multiple times for (int i=0; i<eCT_Num; ++i) { m_cheats[i].actions.clear(); } m_globalActions.clear(); m_assetGroupWeights.clear(); m_assetGroupWeights.resize(eAG_Num); m_totalAssetWeighting = 0; m_fileProtectConfig = NULL; int numChildren = xmlData->getChildCount(); for (int i=0; i<numChildren; ++i) { XmlNodeRef child = xmlData->getChild(i); if (child->isTag("Cheat")) { int numActions = child->getChildCount(); const char* sTypeName = child->getAttr("type"); TCheatType cheatType = FindCheatType(sTypeName); if (cheatType != eCT_Invalid) { SCheatType &cheat = m_cheats[cheatType]; cheat.actions.reserve(numActions); for (int j=0; j<numActions; ++j) { XmlNodeRef actionChild = child->getChild(j); if (actionChild->isTag("Action")) { bool addAction = true; int numConditions = actionChild->getChildCount(); SCheatAction cheatAction; const char* sActionName = actionChild->getAttr("value"); cheatAction.action = FindCheatAction(sActionName); if (cheatAction.action != eCA_Invalid) { int nConfidence = kDefaultConfidence; actionChild->getAttr("confidence", nConfidence); cheatAction.confidence = nConfidence; if (cheatAction.action == eCA_Infraction) { actionChild->getAttr("severity", cheatAction.severity); if (cheatAction.severity <= 0.f) { CryLog("Invalid severity %f", cheatAction.severity); cheatAction.severity = 0.f; } } else if (cheatAction.action == eCA_Ban) { actionChild->getAttr("timeout", cheatAction.banTimeout); } cheatAction.conditions.reserve(numConditions); for (int k=0; k<numConditions; ++k) { XmlNodeRef conditionChild = actionChild->getChild(k); if (conditionChild->isTag("Condition")) { SCheatCondition cheatCondition; const char* sOperatorName = conditionChild->getAttr("operator"); cheatCondition.op = FindCheatOperator(sOperatorName); if (cheatCondition.op != eCO_Invalid) { conditionChild->getAttr("value", cheatCondition.value); conditionChild->getAttr("param", cheatCondition.paramNum); cheatAction.conditions.push_back(cheatCondition); } else { CryLog("Unrecognised operator %s", sOperatorName); } } else if (conditionChild->isTag("DediVersion")) { #if defined(DEDICATED_SERVER) const char* sOperatorName = conditionChild->getAttr("operator"); ECheatOperator op = FindCheatOperator(sOperatorName); if (op != eCO_Invalid) { int value; if (conditionChild->getAttr("value", value)) { if (!MeetsCondition(op, DEDI_VERSION, value)) { // Ignore this action if it doesn't meet the gamespy dedi version check addAction = false; break; } } } else { CryLog("Unrecognised operator %s", sOperatorName); } #endif } else { CryLog("Unrecognised child node %s", conditionChild->getTag()); } } if (addAction) { cheat.actions.push_back(cheatAction); } } else { CryLog("Unrecognised action %s", sActionName); } } else { CryLog("Unrecognised child node %s", actionChild->getTag()); } } } else { CryLog("Unrecognised cheat type %s", sTypeName); } } else if (child->isTag("Global")) { child->getAttr("decay_rate", m_decayRate); int numActions = child->getChildCount(); m_globalActions.reserve(numActions); for (int j=0; j<numActions; ++j) { XmlNodeRef actionChild = child->getChild(j); if (actionChild->isTag("Action")) { SGlobalCheatAction cheatAction; const char* sActionName = actionChild->getAttr("value"); cheatAction.action = FindCheatAction(sActionName); if (cheatAction.action != eCA_Invalid) { if (cheatAction.action == eCA_Ban) { actionChild->getAttr("timeout", cheatAction.banTimeout); } actionChild->getAttr("threshhold", cheatAction.threshhold); if (cheatAction.threshhold > 0.f) { m_globalActions.push_back(cheatAction); } else { CryLog("Invalid threshhold %f", cheatAction.threshhold); } } else { CryLog("Unrecognised action %s", sActionName); } } else { CryLog("Unrecognised child node %s", actionChild->getTag()); } } } else if (child->isTag("DataProbe")) { child->getAttr("hash_method", m_hashMethod); int numChildren = child->getChildCount(); for ( int groupidx = 0; groupidx < numChildren; ++groupidx ) { XmlNodeRef groupChild = child->getChild(groupidx); if (groupChild->isTag("Asset")) { const char* sGroupExtName = groupChild->getAttr("ext"); TCheatAssetGroup assetGroup = FindAssetTypeByExtension(sGroupExtName); if (assetGroup != eAG_Invalid ) { int weight = 0; if ( groupChild->getAttr("weight",weight) ) { m_totalAssetWeighting += m_assetGroupWeights[assetGroup] = weight; } else { CryLog("Extension had no weighting %s", sGroupExtName); } } else { CryLog("Unrecognised extension %s", sGroupExtName); } } else if (groupChild->isTag("protect")) { m_fileProtectConfig = groupChild; } else { CryLog("Unrecognised child node %s", groupChild->getTag()); } } } else if (child->isTag("AntiCheatVars")) { LoadAntiCheatVars(child); } else { CryLog("Unrecognised child node %s", child->getTag()); } } }
// Load an equipment pack from an XML node bool CEquipmentManager::LoadEquipmentPack(const XmlNodeRef& rootNode, bool bOverrideExisting) { if (rootNode->isTag("EquipPack") == false) return false; const char* packName = rootNode->getAttr("name"); const char* primaryName = rootNode->getAttr("primary"); if (!packName || packName[0] == 0) return false; // re-use existing pack SEquipmentPack* pPack = GetPack(packName); if (pPack == 0) { pPack = new SEquipmentPack; m_equipmentPacks.push_back(pPack); } else if (bOverrideExisting == false) return false; pPack->Init(packName); for (int iChild=0; iChild<rootNode->getChildCount(); ++iChild) { const XmlNodeRef childNode = rootNode->getChild(iChild); if (childNode == 0) continue; if (childNode->isTag("Items")) { pPack->PrepareForItems(childNode->getChildCount()); for (int i=0; i<childNode->getChildCount(); ++i) { XmlNodeRef itemNode = childNode->getChild(i); const char* itemName = itemNode->getTag(); const char* itemType = itemNode->getAttr("type"); const char* itemSetup = itemNode->getAttr("setup"); pPack->AddItem(itemName, itemType, itemSetup); } } else if (childNode->isTag("Ammo")) // legacy { const char *ammoName = ""; const char *ammoCount = ""; int nAttr = childNode->getNumAttributes(); for (int j=0; j<nAttr; ++j) { if (childNode->getAttributeByIndex(j, &ammoName, &ammoCount)) { int nAmmoCount = atoi(ammoCount); pPack->m_ammoCount[ammoName] = nAmmoCount; } } } else if (childNode->isTag("Ammos")) { for (int i=0; i<childNode->getChildCount(); ++i) { XmlNodeRef ammoNode = childNode->getChild(i); if (ammoNode->isTag("Ammo") == false) continue; const char* ammoName = ammoNode->getAttr("name"); if (ammoName == 0 || ammoName[0] == '\0') continue; int nAmmoCount = 0; ammoNode->getAttr("amount", nAmmoCount); pPack->m_ammoCount[ammoName] = nAmmoCount; } } } // assign primary. if (pPack->HasItem(primaryName)) pPack->m_primaryItem = primaryName; else pPack->m_primaryItem = ""; return true; }
void CDataPatchDownloader::ApplyCVarPatch() { // Open the file regardless of whether or not we're going to use it - makes sure the file is in the MP mode // switch pak FILE * f = gEnv->pCryPak->FOpen( "Scripts/DataPatcher/patchablecvars.txt", "rt" ); if (!f) { // Failed to open whitelist - don't patch any cvars return; } if (m_patchingEnabled) { AssertPatchDownloaded(); if (m_patchXML) { std::vector<string> cvarsWhiteList; cvarsWhiteList.reserve(64); // Parse the cvars white list - code taken from CVarListProcessor.cpp const int BUFSZ = 4096; char buf[BUFSZ]; size_t nRead; string cvar; bool comment = false; do { cvar.resize(0); buf[0]='\0'; nRead = gEnv->pCryPak->FRead( buf, BUFSZ, f ); for (size_t i=0; i<nRead; i++) { char c = buf[i]; if (comment) { if (c == '\r' || c == '\n') comment = false; } else { if (c == '_' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '.')) { cvar += c; } else if (c == '\t' || c == '\r' || c == '\n' || c == ' ') { if (ICVar * pV = gEnv->pConsole->GetCVar(cvar.c_str())) { cvarsWhiteList.push_back(cvar); } cvar.resize(0); } else if (c == '#') { comment = true; } } } } while (nRead != 0); // Now apply the patch const int numAllowedCVars = cvarsWhiteList.size(); const int numChildren = m_patchXML->getChildCount(); for (int i = 0; i < numChildren; i ++) { XmlNodeRef xmlChild = m_patchXML->getChild(i); if (xmlChild->isTag("cvarpatch")) { const int numCVars = xmlChild->getChildCount(); const char *pCVar = NULL; const char *pValue = NULL; for (int cvarIndex = 0; cvarIndex < numCVars; ++ cvarIndex) { XmlNodeRef xmlCVar = xmlChild->getChild(cvarIndex); if (xmlCVar->isTag("cvar")) { if (xmlCVar->getAttr("name", &pCVar) && xmlCVar->getAttr("value", &pValue)) { bool bAllowed = false; for (int allowedIndex = 0; allowedIndex < numAllowedCVars; ++ allowedIndex) { string &allowedCVar = cvarsWhiteList[allowedIndex]; if (!stricmp(allowedCVar.c_str(), pCVar)) { bAllowed = true; break; } } if (bAllowed) { CryLog("ApplyCVarPatch() patching cvar '%s' to '%s'", pCVar, pValue); g_pGame->GetGameModeCVars().ApplyAndStoreCVar(pCVar, pValue); } else { CryLog("ApplyCVarPatch() cvar '%s' not allowed - ignoring", pCVar); } } } } break; } } } } gEnv->pCryPak->FClose( f ); }