void CEditorGame::ScanBehaviorTrees(const string& folderName, std::vector<string>& behaviorTrees) { _finddata_t fd; intptr_t handle = 0; ICryPak *pPak = gEnv->pCryPak; string searchString = folderName; searchString += "*.xml"; handle = pPak->FindFirst(searchString.c_str(), &fd); if (handle > -1) { do { if (fd.attrib & _A_HIDDEN) continue; string szFileName = fd.name; PathUtil::RemoveExtension(szFileName); behaviorTrees.push_back(szFileName); } while (pPak->FindNext(handle, &fd) >= 0); pPak->FindClose(handle); } }
void CommunicationVoiceLibrary::ScanFolder(const char* folderName, bool recursing) { string folder(PathUtil::MakeGamePath(string(folderName))); folder += "/"; string searchString(folder + "*.xml"); _finddata_t fd; intptr_t handle = 0; ICryPak *pPak = gEnv->pCryPak; handle = pPak->FindFirst(searchString.c_str(), &fd); if (handle > -1) { do { if (!strcmp(fd.name, ".") || !strcmp(fd.name, "..")) continue; if (fd.attrib & _A_SUBDIR) ScanFolder(folder + fd.name, true); else LoadFromFile(folder + fd.name); } while (pPak->FindNext(handle, &fd) >= 0); pPak->FindClose(handle); } if (!recursing) stl::push_back_unique(m_folderNames, folderName); }
void CMaterialEffects::LoadFXLibraries() { MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "MaterialEffects"); m_mfxLibraries.clear(); m_effectContainers.clear(); m_effectContainers.push_back(0); // 0 -> invalid effect id ICryPak *pak = gEnv->pCryPak; _finddata_t fd; stack_string searchPath; searchPath.Format("%s/*.xml", MATERIAL_EFFECTS_LIBRARIES_FOLDER); intptr_t handle = pak->FindFirst(searchPath.c_str(), &fd); int res = 0; if (handle != -1) { do { LoadFXLibrary(fd.name); res = pak->FindNext(handle, &fd); SLICE_AND_SLEEP(); } while(res >= 0); pak->FindClose(handle); } m_canopySurfaceId = MaterialEffectsUtils::FindSurfaceIdByName(MATERIAL_EFFECTS_SURFACE_TYPE_CANOPY); }
bool CDialogLoader::LoadScriptsFromPath(const string& path, TDialogScriptMap& outScriptMap) { ICryPak * pCryPak = gEnv->pCryPak; _finddata_t fd; int numLoaded = 0; string realPath (path); realPath.TrimRight("/\\"); string search (realPath); search += "/*.xml"; intptr_t handle = pCryPak->FindFirst( search.c_str(), &fd ); if (handle != -1) { do { // fd.name contains the profile name string filename = realPath; filename += "/" ; filename += fd.name; bool ok = LoadScript(filename, outScriptMap); if (ok) ++numLoaded; } while ( pCryPak->FindNext( handle, &fd ) >= 0 ); pCryPak->FindClose( handle ); } return numLoaded > 0; }
void CEntityClassRegistry::LoadClasses( const char *sRootPath,bool bOnlyNewClasses ) { ICryPak *pCryPak = gEnv->pCryPak; _finddata_t fd; char filename[_MAX_PATH]; string sPath = sRootPath; sPath.TrimRight("/\\"); string sSearch = sPath + "/*.ent"; intptr_t handle = pCryPak->FindFirst( sSearch, &fd, 0); if (handle != -1) { int res = 0; do { // Animation file found, load it. cry_strcpy(filename,sPath); cry_strcat(filename,"/"); cry_strcat(filename,fd.name); // Load xml file. XmlNodeRef root = m_pSystem->LoadXmlFromFile(filename); if (root) { LoadClassDescription(root,bOnlyNewClasses); } res = pCryPak->FindNext( handle,&fd ); } while (res >= 0); pCryPak->FindClose(handle); } }
void CGameLocalizationManager::LegacyLoadLocalizationData() { // fallback to old system if localization.xml can not be found GameWarning("Using Legacy localization loading"); ILocalizationManager *pLocMan = GetISystem()->GetLocalizationManager(); string const sLocalizationFolder(PathUtil::GetLocalizationFolder()); string const search(sLocalizationFolder + "*.xml"); ICryPak *pPak = gEnv->pCryPak; _finddata_t fd; intptr_t handle = pPak->FindFirst(search.c_str(), &fd); if (handle > -1) { do { CRY_ASSERT_MESSAGE(stricmp(PathUtil::GetExt(fd.name), "xml") == 0, "expected xml files only"); string filename = sLocalizationFolder + fd.name; pLocMan->LoadExcelXmlSpreadsheet(filename.c_str()); } while (pPak->FindNext(handle, &fd) >= 0); pPak->FindClose(handle); } else { GameWarning("Unable to find any Localization Data!"); } }
//------------------------------------------------------------------------ void CWeaponSystem::Scan(const char *folderName) { string folder = folderName; string search = folder; search += "/*.*"; ICryPak *pPak = m_pSystem->GetIPak(); _finddata_t fd; intptr_t handle = pPak->FindFirst(search.c_str(), &fd); if (!m_recursing) CryLog("Loading ammo XML definitions from '%s'!", folderName); if (handle > -1) { do { if (!strcmp(fd.name, ".") || !strcmp(fd.name, "..")) continue; if (fd.attrib & _A_SUBDIR) { string subName = folder+"/"+fd.name; if (m_recursing) Scan(subName.c_str()); else { m_recursing=true; Scan(subName.c_str()); m_recursing=false; } continue; } if (stricmp(PathUtil::GetExt(fd.name), "xml")) continue; string xmlFile = folder + string("/") + string(fd.name); XmlNodeRef rootNode = m_pSystem->LoadXmlFile(xmlFile.c_str()); if (!rootNode) { GameWarning("Invalid XML file '%s'! Skipping...", xmlFile.c_str()); continue; } if (!ScanXML(rootNode, xmlFile.c_str())) continue; } while (pPak->FindNext(handle, &fd) >= 0); } if (!m_recursing) CryLog("Finished loading ammo XML definitions from '%s'!", folderName); if (!m_reloading && !m_recursing) m_folders.push_back(folderName); }
void CGameAIRecorder::CleanupRemoteArchive() { ICryPak *pCryPak = gEnv->pSystem->GetIPak(); assert(pCryPak); m_pRemoteArchive = NULL; string sPAKFileLocalPath = PathUtil::Make("..", g_szRemoteTempArchive); pCryPak->RemoveFile(sPAKFileLocalPath.c_str()); }
uint32 CModInfoManager::GetDirectoryHash( const char *pPath ) { if (!gEnv || !gEnv->pCryPak) { assert(0); return 0; } ICryPak* pCryPak = gEnv->pCryPak; // Recursively find all files and hash them uint32 result = 0; CryStackStringT<char, _MAX_PATH*2> searchPath; searchPath.Format("%s\\*", pPath); _finddata_t fd; intptr_t h = pCryPak->FindFirst(searchPath.c_str(), &fd, 0, true); if (h != -1) { CryStackStringT<char, _MAX_PATH*2> path; do { if ((fd.attrib & _A_SUBDIR) == 0) { // Add to checksum uint32 fileHash = 0; CryStackStringT<char, _MAX_PATH*2> modPath; modPath.Format("%s\\%s", pPath, fd.name); if (GetFileHash(modPath.c_str(), fileHash)) { result += fileHash; } continue; } if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0) continue; path = pPath; path += "\\"; path += fd.name; result += GetDirectoryHash(path.c_str()); } while(0 == pCryPak->FindNext(h, &fd)); pCryPak->FindClose (h); } return result; }
//------------------------------------------------------------------------ bool CPlayerProfileImplFS::LoginUser(SUserEntry* pEntry) { // lookup stored profiles of the user (pEntry->userId) and fill in the pEntry->profileDesc // vector pEntry->profileDesc.clear(); // scan directory for profiles string path; InternalMakeFSPath(pEntry, "", path); // no profile name -> only path ICryPak * pCryPak = gEnv->pCryPak; _finddata_t fd; path.TrimRight("/\\"); string search = path + "/*.xml"; intptr_t handle = pCryPak->FindFirst( search.c_str(), &fd ); if (handle != -1) { do { // fd.name contains the profile name string filename = path; filename += "/" ; filename += fd.name; XmlNodeRef rootNode = LoadXMLFile(filename.c_str()); // see if the root tag is o.k. if (rootNode && stricmp(rootNode->getTag(), PROFILE_ROOT_TAG) == 0) { string profileName = fd.name; PathUtil::RemoveExtension(profileName); if (rootNode->haveAttr(PROFILE_NAME_TAG)) { const char* profileHumanName = rootNode->getAttr(PROFILE_NAME_TAG); if (profileHumanName!=0 && stricmp(profileHumanName, profileName) == 0) { profileName = profileHumanName; } } pEntry->profileDesc.push_back(SLocalProfileInfo(profileName)); } else { GameWarning("CPlayerProfileImplFS::LoginUser: Profile '%s' of User '%s' seems to exist, but is invalid (File '%s). Skipped", fd.name, pEntry->userId.c_str(), filename.c_str()); } } while ( pCryPak->FindNext( handle, &fd ) >= 0 ); pCryPak->FindClose( handle ); } return true; }
void CDialogLoaderMK2::InternalLoadFromPath(const string& stripPath, const string& path, TDialogScriptMap& outScriptMap, int& numLoaded, const char *levelName) { ICryPak * pCryPak = gEnv->pCryPak; _finddata_t fd; string realPath (path); realPath.TrimRight("/\\"); string search (realPath); search += "/*.*"; intptr_t handle = pCryPak->FindFirst( search.c_str(), &fd ); if (handle != -1) { do { if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0) continue; if (fd.attrib & _A_SUBDIR) { if(!gEnv->IsEditor()) //only load current levels dialogs { if(!levelName || stricmp(levelName, fd.name)) continue; } string subPath = realPath; subPath+="/"; subPath+=fd.name; InternalLoadFromPath(stripPath, subPath, outScriptMap, numLoaded, levelName); continue; } if (stricmp(PathUtil::GetExt(fd.name), "dlg") != 0) continue; // fd.name contains the profile name string filename = realPath; filename += "/" ; filename += fd.name; bool ok = LoadScript(stripPath, filename, outScriptMap); if (ok) ++numLoaded; } while ( pCryPak->FindNext( handle, &fd ) >= 0 ); pCryPak->FindClose( handle ); } }
void CFlowGraphModuleManager::ScanFolder(const string& folderName, bool bGlobal) { _finddata_t fd; intptr_t handle = 0; ICryPak *pPak = gEnv->pCryPak; CryFixedStringT<512> searchString = folderName.c_str(); searchString.append("*.*"); handle = pPak->FindFirst(searchString.c_str(), &fd); CryFixedStringT<512> moduleName(""); string newFolder(""); if (handle > -1) { do { if (!strcmp(fd.name, ".") || !strcmp(fd.name, "..") || (fd.attrib & _A_HIDDEN)) continue; if (fd.attrib & _A_SUBDIR) { newFolder = folderName; newFolder = newFolder + fd.name; newFolder = newFolder + "\\"; ScanFolder(newFolder, bGlobal); } else { moduleName = fd.name; if(!strcmpi(PathUtil::GetExt(moduleName.c_str()), "xml")) { PathUtil::RemoveExtension(moduleName); PathUtil::MakeGamePath(folderName); // initial load: creates module, registers nodes CFlowGraphModule* pModule = PreLoadModuleFile(moduleName.c_str(), PathUtil::GetPath(folderName)+fd.name, bGlobal); // important: the module should be added using its internal name rather than the filename m_ModulesPathInfo.insert(TModulesPathInfo::value_type(pModule->GetName(), PathUtil::GetPath(folderName)+fd.name)); } } } while (pPak->FindNext(handle, &fd) >= 0); pPak->FindClose(handle); } }
void CGameAIRecorder::OnRecordingStart(EAIRecorderMode mode, const char *filename) { m_bIsRecording = true; m_bBookmarkAdded = false; CleanupRemoteArchive(); // Create a new temp archive if (CGameAIRecorderCVars::ai_remoteRecorder_enabled != 0) { ICryPak *pCryPak = gEnv->pSystem->GetIPak(); if (pCryPak) { m_pRemoteArchive = pCryPak->OpenArchive(g_szRemoteTempArchive); } } }
void CLuaRemoteDebug::ReceiveFileContentsRequest(CSerializationHelper &buffer) { const char* fileName = buffer.ReadString(); ICryPak* pCryPak = gEnv->pCryPak; FILE* pFile = pCryPak->FOpen(fileName + 1, "rb"); if (pFile != NULL) { m_sendBuffer.Write((char)ePT_FileContents); m_sendBuffer.WriteString(fileName); // Get file length pCryPak->FSeek(pFile, 0, SEEK_END); uint32 length = (uint32)pCryPak->FTell(pFile); pCryPak->FSeek(pFile, 0, SEEK_SET); m_sendBuffer.Write(length); const int CHUNK_BUF_SIZE = 1024; char buf[CHUNK_BUF_SIZE]; size_t lenRead; while (!pCryPak->FEof(pFile)) { lenRead = pCryPak->FRead(buf, CHUNK_BUF_SIZE, pFile); m_sendBuffer.WriteBuffer(buf, (int)lenRead); } SendBuffer(); } else { assert(false); } }
void CGameStartup::LoadLocalizationData() { LOADING_TIME_PROFILE_SECTION // Loads any XML files in Languages directory ILocalizationManager *pLocMan = GetISystem()->GetLocalizationManager(); string sLocaFolderName = "Libs/Localization/"; string locaFile = sLocaFolderName + "localization.xml"; if (pLocMan->InitLocalizationData(locaFile.c_str())) { if (!gEnv->IsEditor()) { // load only the init xml files pLocMan->LoadLocalizationDataByTag("init"); } } else { // fallback to old system if localization.xml can not be found string const sLocalizationFolder(PathUtil::GetLocalizationFolder()); string const search(sLocalizationFolder + "*.xml"); ICryPak *pPak = gEnv->pCryPak; _finddata_t fd; intptr_t handle = pPak->FindFirst(search.c_str(), &fd); if (handle > -1) { do { CRY_ASSERT_MESSAGE(stricmp(PathUtil::GetExt(fd.name), "xml") == 0, "expected xml files only"); string filename = sLocalizationFolder + fd.name; pLocMan->LoadExcelXmlSpreadsheet(filename.c_str()); } while (pPak->FindNext(handle, &fd) >= 0); pPak->FindClose(handle); } else { CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Unable to find any Localization Data!"); } } }
void CGameTokenSystem::LoadLibs( const char *sFileSpec ) { LOADING_TIME_PROFILE_SECTION(GetISystem()); ICryPak *pPak = gEnv->pCryPak; _finddata_t fd; string dir = PathUtil::GetPath(sFileSpec); intptr_t handle = pPak->FindFirst( sFileSpec,&fd ); if (handle != -1) { int res = 0; do { _InternalLoadLibrary( PathUtil::Make(dir,fd.name), "GameTokensLibrary" ); res = pPak->FindNext( handle,&fd ); } while (res >= 0); pPak->FindClose(handle); } }
void CVehicleMovementAerodynamic::ReadFile(string _strFile,TPointsMap *_pPointsMap) { ICryPak *pCryPak = gEnv->pCryPak; assert(pCryPak); FILE *pFile = pCryPak->FOpen(_strFile.c_str(),"r"); if(pFile) { char acBuffer[256]; while(pCryPak->FGets(acBuffer,256,pFile)) { float fX; float fY; sscanf(acBuffer,"%f %f\n",&fX,&fY); _pPointsMap->insert(std::make_pair(fX,fY)); } pCryPak->FClose(pFile); } }
static bool ModInfo_LoadFromFile(ModInfo* pMod, const char* pFilename) { if (!pMod) return false; if (!gEnv || !gEnv->pCryPak) { assert(0); return false; } ICryPak* pCryPak = gEnv->pCryPak; FILE* f = pCryPak->FOpen(pFilename, "rb", ICryPak::FOPEN_ONDISK); if (!f) return false; pCryPak->FSeek(f, 0, SEEK_END); const size_t fileSize = pCryPak->FTell(f); pCryPak->FSeek(f, 0, SEEK_SET); if (fileSize == 0) { pCryPak->FClose(f); return false; } std::vector<char> buffer; buffer.resize(fileSize); if (pCryPak->FRead(&buffer[0], fileSize, f) != fileSize) { pCryPak->FClose(f); return false; } pCryPak->FClose(f); std::auto_ptr<IXmlParser> pParser(GetISystem()->GetXmlUtils()->CreateXmlParser()); XmlNodeRef pRoot = pParser->ParseBuffer(&buffer[0], buffer.size(), true); if (!pRoot) return false; if (!ModInfo_LoadFromXML(pMod, pRoot)) return false; return true; }
//------------------------------------------------------------------------ bool CVehicleDamagesTemplateRegistry::Init(const string& defaultDefFilename, const string& damagesTemplatesPath) { if (damagesTemplatesPath.empty()) return false; m_templateFiles.clear(); m_templates.clear(); m_defaultDefFilename = defaultDefFilename; ICryPak *pCryPak = gEnv->pCryPak; _finddata_t fd; int ret; intptr_t handle; if ((handle = pCryPak->FindFirst(damagesTemplatesPath + string("*") + ".xml", &fd)) != -1) { do { string name(fd.name); if (name.substr(0,4) != "def_") { string filename = damagesTemplatesPath + name; if (!RegisterTemplates(filename, m_defaultDefFilename)) CryLog("VehicleDamagesTemplateRegistry: error parsing template file <%s>.", filename.c_str()); } ret = pCryPak->FindNext( handle,&fd ); } while (ret >= 0); pCryPak->FindClose(handle); } return true; }
CSDLMixerProjectLoader::CSDLMixerProjectLoader(const string& sAssetsPath, IAudioSystemEditor* pAudioSystemImpl) : m_pAudioSystemImpl(pAudioSystemImpl) { _finddata_t fd; ICryPak* pCryPak = gEnv->pCryPak; intptr_t handle = pCryPak->FindFirst(sAssetsPath + "/*.*", &fd); if (handle != -1) { do { const string name = fd.name; if (name != "." && name != ".." && !name.empty()) { if (name.find(".wav") != string::npos || name.find(".ogg") != string::npos /*|| name.find(".mp3") != string::npos*/) { // Create the event with the same name as the file m_pAudioSystemImpl->CreateControl(SControlDef(name, eSDLMT_EVENT)); } } } while (pCryPak->FindNext(handle, &fd) >= 0); pCryPak->FindClose(handle); } }
// Load all equipment packs from a certain folder void CEquipmentManager::LoadEquipmentPacksFromPath(const char* path) { MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Equipment Packs"); ICryPak * pCryPak = gEnv->pCryPak; _finddata_t fd; string realPath (path); realPath.TrimRight("/\\"); string search (realPath); search += "/*.xml"; intptr_t handle = pCryPak->FindFirst( search.c_str(), &fd ); if (handle != -1) { do { // fd.name contains the profile name string filename = path; filename += "/" ; filename += fd.name; MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Other, 0, "EquipmentPack XML (%s)", filename.c_str()); XmlNodeRef rootNode = gEnv->pSystem->LoadXmlFromFile(filename.c_str()); // load from XML node const bool ok = rootNode ? LoadEquipmentPack(rootNode) : false; if (!ok) { GameWarning("[EquipmentMgr]: Cannot load XML file '%s'. Skipping.", filename.c_str()); } } while ( pCryPak->FindNext( handle, &fd ) >= 0 ); pCryPak->FindClose( handle ); } }
bool CGameAIRecorder::AddFileToRemoteArchive(const char* szFile) { bool bResult = false; ICryPak *pCryPak = gEnv->pSystem->GetIPak(); assert(pCryPak); if (m_pRemoteArchive && pCryPak) { string sLocalPath = PathUtil::Make("..", szFile); AZ::IO::HandleType fileHandle = pCryPak->FOpen(sLocalPath.c_str(), "rb"); if (fileHandle != AZ::IO::InvalidHandle) { // Add the file to the PAK size_t iFileSize = pCryPak->FGetSize(fileHandle); BYTE* pBuffer = (BYTE*)pCryPak->PoolMalloc(iFileSize); if (!pBuffer) { CryLogAlways("[Warning] Failed when packing file to remote archive: Out of memory. (\'%s\')", szFile); } else { pCryPak->FReadRaw(pBuffer, iFileSize, 1, fileHandle); int iResult = m_pRemoteArchive->UpdateFile(PathUtil::GetFile(szFile), pBuffer, iFileSize, ICryArchive::METHOD_DEFLATE, ICryArchive::LEVEL_BETTER); if (0 != iResult) { CryLogAlways("[Warning] Failed when packing file to remote archive: File update failed. (\'%s\')", szFile); } else { bResult = true; } pCryPak->PoolFree(pBuffer); } pCryPak->FClose(fileHandle); } } return bResult; }
bool CGameAIRecorder::SendRemoteArchive(const char* szRecordingFile) { ICryPak *pCryPak = gEnv->pSystem->GetIPak(); assert(pCryPak); bool bResult = false; string sPAKFileName; sPAKFileName.Format("%s_%s", gEnv->pSystem->GetUserName(), PathUtil::GetFileName(szRecordingFile).c_str()); string sDestFile = PathUtil::Make(CGameAIRecorderCVars::ai_remoteRecorder_serverDir, sPAKFileName.c_str(), "zip"); CryLogAlways("AI Recording packed successfully! Copying to remote directory \'%s\'...", sDestFile.c_str()); // Remote copy the file string sPAKFileLocalPath = PathUtil::Make("..", g_szRemoteTempArchive); AZ::IO::HandleType pakFileHandle = pCryPak->FOpen(sPAKFileLocalPath.c_str(), "rb"); if (pakFileHandle != AZ::IO::InvalidHandle) { AZ::IO::HandleType destFileHandle = pCryPak->FOpen(sDestFile.c_str(), "wb"); if (destFileHandle != AZ::IO::InvalidHandle) { BYTE pBuffer[512]; while (true) { const int iReadAmount = pCryPak->FReadRaw(pBuffer, 1, 512, pakFileHandle); if (iReadAmount <= 0) break; if (pCryPak->FWrite(pBuffer, iReadAmount, 1, destFileHandle) > 0) bResult = true; } pCryPak->FClose(destFileHandle); pCryPak->FClose(pakFileHandle); } } return bResult; }
void CEditorGame::InitEntityArchetypeEnums(IGameToEditorInterface* pGTE, const char* levelFolder /*= NULL*/, const char* levelName /*= NULL*/) { CRY_ASSERT(pGTE); // Look in all the archetype files ICryPak* pCryPak = gEnv->pCryPak; CRY_ASSERT(pCryPak); std::vector<string> vecArchetypeNames; if (levelFolder && levelName) { string levelPath = string(levelFolder) + "/" + string(levelName) + ".cry"; if (pCryPak && pCryPak->OpenPack(levelPath)) { string editorXML = string(levelFolder) + "/Level.editor_xml"; XmlNodeRef pRoot = gEnv->pSystem->LoadXmlFromFile(editorXML); if (pRoot) GetArchetypesFromLevelLib(pRoot, &vecArchetypeNames); pCryPak->ClosePack(levelPath); } } _finddata_t fd; string sSearchPath = PathUtil::Make("Libs\\EntityArchetypes", "*", "xml"); intptr_t handle = pCryPak->FindFirst(sSearchPath, &fd); if (handle >= 0) { do { string sFilePath = PathUtil::Make("Libs\\EntityArchetypes", fd.name, "xml"); XmlNodeRef pRoot = gEnv->pSystem->LoadXmlFromFile(sFilePath.c_str()); if (!pRoot || stricmp(pRoot->getTag(), "EntityPrototypeLibrary")) continue; XmlString sRootName; pRoot->getAttr("Name", sRootName); GetArchetypesFromLib(pRoot, sRootName, &vecArchetypeNames); } while (pCryPak->FindNext(handle, &fd) >= 0); pCryPak->FindClose(handle); } if (!vecArchetypeNames.empty()) { size_t numFilters = 0; const int allArchetypeCount = vecArchetypeNames.size()+1; const char** allArchetypeNames = new const char*[allArchetypeCount]; allArchetypeNames[numFilters++] = ""; // Blank entry at top std::vector<string>::const_iterator iter = vecArchetypeNames.begin(); std::vector<string>::const_iterator iterEnd = vecArchetypeNames.end(); while (iter != iterEnd) { assert(numFilters > 0 && numFilters < allArchetypeCount); PREFAST_ASSUME(numFilters > 0 && numFilters < allArchetypeCount); allArchetypeNames[numFilters++] = iter->c_str(); ++iter; } pGTE->SetUIEnums("entity_archetypes", allArchetypeNames, numFilters); delete[] allArchetypeNames; } }
bool GetFileHash(const char *pPath, uint32 &outResult) { if (!gEnv || !gEnv->pCryPak) { assert(0); return false; } ICryPak* pCryPak = gEnv->pCryPak; // Try to open file on disk and hash it (using algorithm taken from CryHashStringId) FILE *file = pCryPak->FOpen( pPath,"rb",ICryPak::FOPEN_ONDISK ); if (file) { pCryPak->FSeek( file,0,SEEK_END ); unsigned int nFileSize = pCryPak->FTell(file); pCryPak->FSeek( file,0,SEEK_SET ); outResult = FILE_HASH_SEED; unsigned char *pBuf = (unsigned char*)malloc( FILE_CHECK_BUFFER_SIZE ); if (!pBuf) { pCryPak->FClose(file); return false; } while (nFileSize) { unsigned int fetchLength=min(nFileSize,(unsigned int)FILE_CHECK_BUFFER_SIZE); unsigned int result = pCryPak->FRead( pBuf,fetchLength,file ); if (result != fetchLength) { free( pBuf ); pCryPak->FClose(file); return false; } const char *pChar = (const char*)pBuf; for (unsigned int i = 0; i < fetchLength; ++ i, ++ pChar) { outResult += *pChar; outResult += (outResult << 10); outResult ^= (outResult >> 6); } nFileSize-=fetchLength; } outResult += (outResult << 3); outResult ^= (outResult >> 11); outResult += (outResult << 15); free( pBuf ); pCryPak->FClose(file); return true; } return false; }
void CModInfoManager::Refresh() { #ifndef _WIN32 assert(0 && "Calling Windows-specific code"); return; #endif if (!gEnv || !gEnv->pCryPak) { assert(0); return; } ICryPak* pCryPak = gEnv->pCryPak; m_mods.clear(); // look for MODs { _finddata_t fd; intptr_t h = pCryPak->FindFirst ("Mods\\*", &fd, 0, true); if (h != -1) { CryStackStringT<char, _MAX_PATH*2> path; do { if ((fd.attrib & _A_SUBDIR) == 0) continue; if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0) continue; path = "Mods\\"; path += fd.name; ModInfo mod; if (ModInfo_LoadFromFile(&mod, (path + "\\info.xml").c_str()) && mod.modType != eMIT_SPLEVEL) { mod.keyName = fd.name; if (mod.displayName.empty()) mod.displayName = mod.keyName; path.replace('\\', '/'); path.insert(0, '/'); mod.mainImage = (path + "/modpreview.jpg").c_str(); mod.logoImage = (path + "/modteamlogo.jpg").c_str(); m_mods.push_back(mod); } } while(0 == pCryPak->FindNext(h, &fd)); pCryPak->FindClose (h); } } // look for SP-levels { CryStackStringT<char, _MAX_PATH*2> path; path += PathUtil::GetGameFolder(); path += "\\Levels\\*"; _finddata_t fd; intptr_t h = pCryPak->FindFirst (path.c_str(), &fd, 0, true); if (h != -1) { do { if ((fd.attrib & _A_SUBDIR) == 0) continue; if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0) continue; path = PathUtil::GetGameFolder(); path += "\\Levels\\"; path += fd.name; ModInfo mod; if (ModInfo_LoadFromFile(&mod, (path + "\\info.xml").c_str())) { mod.modType = eMIT_SPLEVEL; mod.keyName = fd.name; path = "/Levels/"; path += fd.name; mod.mainImage = (path + "/modpreview.jpg").c_str(); mod.logoImage = (path + "/modteamlogo.jpg").c_str(); if (mod.displayName.empty()) mod.displayName = mod.keyName; m_mods.push_back(mod); } } while(0 == pCryPak->FindNext(h, &fd)); pCryPak->FindClose (h); } } // look for MOD levels { m_modLevels.clear(); CryStackStringT<char, _MAX_PATH*2> path; ILevelSystem* pLevelSystem = g_pGame->GetIGameFramework()->GetILevelSystem(); size_t levelCount = pLevelSystem->GetLevelCount(); for (size_t i = 0; i < levelCount; ++i) { ILevelInfo* pInfo = pLevelSystem->GetLevelInfo(i); if (!pInfo) continue; if (pInfo->GetIsModLevel() && (!pInfo->HasGameRules() || pInfo->SupportsGameType("SinglePlayer"))) { ModInfo mod; const char* szLevelInfoDisplayName = pInfo->GetDisplayName(); if (strcmp(szLevelInfoDisplayName, "") != 0) { mod.displayName = szLevelInfoDisplayName; } else // Fallback to directory name { mod.displayName = pInfo->GetName(); } // load info.xml as well path = pInfo->GetPath(); path.replace('/', '\\'); if (ModInfo_LoadFromFile(&mod, (path + "\\info.xml").c_str())) { path.replace('\\', '/'); path.insert(0, '/'); mod.mainImage = (path + "/modpreview.jpg").c_str(); mod.logoImage = (path + "/modteamlogo.jpg").c_str(); } mod.keyName = pInfo->GetName(); mod.modType = eMIT_SPLEVEL; m_modLevels.push_back(mod); } } } }
bool CScriptSurfaceTypesLoader::LoadSurfaceTypes( const char *sFolder,bool bReload ) { { if (!gEnv->p3DEngine) return false; I3DEngine *pEngine = gEnv->p3DEngine; ISurfaceTypeEnumerator *pEnum = pEngine->GetMaterialManager()->GetSurfaceTypeManager()->GetEnumerator(); if (pEnum) { for (ISurfaceType *pSurfaceType = pEnum->GetFirst(); pSurfaceType; pSurfaceType = pEnum->GetNext()) { SmartScriptTable mtlTable(gEnv->pScriptSystem); gEnv->pScriptSystem->SetGlobalValue( pSurfaceType->GetName(),mtlTable ); SmartScriptTable aiTable(gEnv->pScriptSystem); mtlTable->SetValue("AI",aiTable); aiTable->SetValue( "fImpactRadius",5.0f ); aiTable->SetValue( "fFootStepRadius",15.0f ); aiTable->SetValue( "proneMult",0.2f ); aiTable->SetValue( "crouchMult",0.5f ); aiTable->SetValue( "movingMult",2.5f ); } pEnum->Release(); } } return true; // Do not load surface types from script anymore. m_root = GetISystem()->CreateXmlNode("SurfaceTypes"); IScriptSystem *pScriptSystem = gEnv->pScriptSystem; ////////////////////////////////////////////////////////////////////////// // Make sure Materials table exist. ////////////////////////////////////////////////////////////////////////// SmartScriptTable mtlTable; if (!pScriptSystem->GetGlobalValue("Materials", mtlTable) || bReload) { mtlTable = pScriptSystem->CreateTable(); pScriptSystem->SetGlobalValue("Materials", mtlTable); } ICryPak *pIPak = gEnv->pCryPak; ISurfaceTypeManager *pSurfaceManager = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceTypeManager(); if (!bReload) stl::push_back_unique( m_folders,sFolder ); string searchFolder = string(sFolder) + "/";; string searchFilter = searchFolder + "mat_*.lua"; gEnv->pScriptSystem->ExecuteFile(searchFolder+"common.lua", false, bReload); _finddata_t fd; intptr_t fhandle; fhandle = pIPak->FindFirst( searchFilter,&fd ); if (fhandle != -1) { do { // Skip back folders. if (fd.attrib & _A_SUBDIR) // skip if directory. continue; char name[_MAX_PATH]; _splitpath( fd.name,NULL,NULL,name,NULL ); if (strlen(name) == 0) continue; if (bReload) { ISurfaceType *pSurfaceType = pSurfaceManager->GetSurfaceTypeByName(name); if (pSurfaceType) { pSurfaceType->Load( pSurfaceType->GetId() ); continue; } } ISurfaceType *pSurfaceType = new CScriptSurfaceType( this,name,searchFolder+fd.name,0 ); if (pSurfaceManager->RegisterSurfaceType( pSurfaceType )) m_surfaceTypes.push_back(pSurfaceType); else pSurfaceType->Release(); } while (pIPak->FindNext( fhandle,&fd ) == 0); pIPak->FindClose(fhandle); } if (m_root) { m_root->saveToFile( "SurfaceTypes.xml" ); } return true; }