void CAntiCheatManager::ParseAntiCheatConfig(const char * filename) { CCryFile file; CryFixedStringT<128> realFileName; realFileName.Format("%s/%s", PathUtil::GetGameFolder().c_str(), filename); if (file.Open( realFileName.c_str(), "rb", ICryPak::FOPEN_HINT_QUIET | ICryPak::FOPEN_ONDISK )) { const size_t fileSize = file.GetLength(); char* pBuffer = new char [fileSize]; file.ReadRaw(pBuffer, fileSize); XmlNodeRef xmlData = gEnv->pSystem->LoadXmlFromBuffer(pBuffer, fileSize); SAFE_DELETE_ARRAY(pBuffer); if(xmlData) { CryLog("Parsing Anti-Cheat Configuration..."); ParseAntiCheatConfig(xmlData); } else { CryLog("Unable to parse Anti-Cheat Configuration"); } } else { CryLog("Unable to load '%s'", realFileName.c_str()); } }
string CLuaRemoteDebug::GetLineFromFile( const char *sFilename,int nLine ) { CCryFile file; if (!file.Open(sFilename,"rb")) { return ""; } int nLen = file.GetLength(); char *sScript = new char [nLen + 1]; char *sString = new char [nLen + 1]; file.ReadRaw( sScript,nLen ); sScript[nLen] = '\0'; int nCurLine = 1; string strLine; strcpy( sString,"" ); const char *strLast = sScript+nLen; const char *str = sScript; while (str < strLast) { char *s = sString; while (str < strLast && *str != '\n' && *str != '\r') { *s++ = *str++; } *s = '\0'; if (str + 2 <= strLast && str[0] == '\r' && str[1] == '\n') { // Skip \r\n (Windows style line endings) str += 2; } else { // Skip \n or \r (Unix/Mac style line endings) str += 1; } if (nCurLine == nLine) { strLine = sString; strLine.replace( '\t',' ' ); strLine.Trim(); break; } nCurLine++; } delete []sString; delete []sScript; return strLine; }
static inline void WriteFccCodes(CCryFile& file, const TFourCCSet& fccs, uint32 keyword) { uint32 fcc = keyword; file.Write( &fcc, sizeof(fcc) ); for ( TFourCCSet::const_iterator it = fccs.begin(); it != fccs.end(); ++it ) { fcc = *it; file.Write( &fcc, sizeof(fcc) ); } fcc = eBK_void; file.Write( &fcc, sizeof(fcc) ); }
void CGameVolumesManager::Export( const char* fileName ) const { CCryFile file; if( false != file.Open( fileName, "wb" ) ) { const uint32 maxVertices = 512; Vec3 writeVertexBuffer[maxVertices]; // File version uint32 nFileVersion = GAME_VOLUMES_FILE_VERSION; file.Write( &nFileVersion,sizeof(nFileVersion) ); // Save volume info uint32 nVolumeCount = (uint32)m_volumesData.size(); file.Write( &nVolumeCount, sizeof(nVolumeCount) ); for (uint32 i = 0; i < nVolumeCount; ++i) { const EntityVolume& volumeInfo = m_volumesData[i]; CRY_ASSERT ( volumeInfo.vertices.size() < maxVertices ); uint32 nVertexCount = min( (uint32)volumeInfo.vertices.size(), maxVertices ); uint32 nEntityId = volumeInfo.entityId; f32 fHeight = volumeInfo.height; bool bClosed = volumeInfo.closed; file.Write( &nEntityId, sizeof(nEntityId) ); file.Write( &fHeight, sizeof(fHeight) ); if( nFileVersion > 1 ) { file.Write( &bClosed, sizeof(bClosed) ); } file.Write( &nVertexCount, sizeof(nVertexCount) ); if (nVertexCount > 0) { for (uint32 v = 0; v < nVertexCount; ++v) { writeVertexBuffer[v] = volumeInfo.vertices[v]; } file.Write( &writeVertexBuffer[0], sizeof(writeVertexBuffer[0]) * nVertexCount ); } } file.Close(); } }
void CLedgeManager::Load( const char* fileName ) { // Clear in case there is anything left Reset(); // In editor we don't load exported data, entities will recreate on load if (m_editorManager.IsInEditorMode()) return; CCryFile file; if( false != file.Open( fileName, "rb" ) ) { // File version uint32 nFileVersion; file.ReadType( &nFileVersion ); if (nFileVersion != LEDGE_DATA_FILE_VERSION) { GameWarning("!LedgeManager: Level data could not be loaded, file %s has version %d, expected %d. Level needs re-export", fileName, nFileVersion, LEDGE_DATA_FILE_VERSION); return; } // Ledges and markers info uint32 totalLedgeObjectsCount, totalLedgeMarkersCount; file.ReadType( &totalLedgeObjectsCount ); file.ReadType( &totalLedgeMarkersCount ); m_levelLedges.Allocate( totalLedgeObjectsCount, totalLedgeMarkersCount ); file.ReadType( &m_levelLedges.m_pLedgeObjects[0], totalLedgeObjectsCount ); file.ReadType( &m_levelLedges.m_pMarkers[0], totalLedgeMarkersCount ); file.Close(); } }
void CLedgeManagerEdit::Export( const char* fileName ) const { const uint32 totalLedgeObjectsCount = m_ledgeObjects.size(); if (totalLedgeObjectsCount > 0) { CCryFile file; if( false != file.Open( fileName, "wb" ) ) { // Count number of markers ... uint32 totalLedgeMarkersCount = 0; for (uint32 objectIdx = 0; objectIdx < totalLedgeObjectsCount; ++objectIdx) { totalLedgeMarkersCount += m_ledgeObjects[objectIdx].m_markers.size(); } // Prepare buffers ... SLedgeObject ledgeObjectBuffer[MAX_LEDGE_ENTITIES]; SLedgeMarkerBuffer ledgeMarkersBuffer(totalLedgeMarkersCount); uint32 currentMarkerIdx = 0; for (uint32 objectIdx = 0; objectIdx < totalLedgeObjectsCount; ++objectIdx) { SLedgeObject& ledgeObject = ledgeObjectBuffer[objectIdx]; const SLedgeObjectEditor& ledgeObjectEdit = m_ledgeObjects[objectIdx]; ledgeObject.m_entityId = ((ledgeObjectEdit.m_ledgeFlags[LedgeSide_In] & kLedgeFlag_static) == 0) ? ledgeObjectEdit.m_entityId : 0; ledgeObject.m_ledgeFlags[LedgeSide_In] = ledgeObjectEdit.m_ledgeFlags[LedgeSide_In]; ledgeObject.m_ledgeFlags[LedgeSide_Out] = ledgeObjectEdit.m_ledgeFlags[LedgeSide_Out]; ledgeObject.m_ledgeCornerEndAdjustAmount = ledgeObjectEdit.m_ledgeCornerEndAdjustAmount; ledgeObject.m_markersStartIdx = currentMarkerIdx; ledgeObject.m_markersCount = ledgeObjectEdit.m_markers.size(); CRY_ASSERT((ledgeObject.m_markersStartIdx + ledgeObject.m_markersCount) <= totalLedgeMarkersCount); for(size_t markerIdx = 0; markerIdx < ledgeObjectEdit.m_markers.size(); ++markerIdx) { ledgeMarkersBuffer.InsertAt( ledgeObjectEdit.m_markers[markerIdx], currentMarkerIdx + markerIdx ); } currentMarkerIdx += ledgeObject.m_markersCount; } // Write to file... // File version uint32 nFileVersion = LEDGE_DATA_FILE_VERSION; file.Write( &nFileVersion,sizeof(nFileVersion) ); // Ledges and markers info file.Write( &totalLedgeObjectsCount, sizeof(totalLedgeObjectsCount) ); file.Write( &totalLedgeMarkersCount, sizeof(totalLedgeMarkersCount) ); file.Write( &ledgeObjectBuffer[0], sizeof(ledgeObjectBuffer[0]) * totalLedgeObjectsCount ); file.Write( &ledgeMarkersBuffer.pMarkers[0], sizeof(ledgeMarkersBuffer.pMarkers[0]) * ledgeMarkersBuffer.bufferSize ); file.Close(); } } }
static inline bool ReadFccCodes(CCryFile& file, TFourCCSet& fccs, uint32 keyword) { uint32 fcc = 0; if ( file.ReadRaw(&fcc, sizeof(fcc)) != sizeof(fcc) ) return false; if (fcc != keyword) return false; while (true) { if ( file.ReadRaw(&fcc, sizeof(fcc)) != sizeof(fcc) ) return false; if (fcc == eBK_tags || fcc == eBK_typs) return false; if (fcc == eBK_void) break; fccs.insert(fcc); } return true; }
void CAreaProxy::ReadPolygonsForAreaSolid( CCryFile& file, int numberOfPolygons, bool bObstruction ) { static const int numberOfStaticVertices(200); Vec3 pStaticVertices[numberOfStaticVertices]; for( int i = 0; i < numberOfPolygons; ++i ) { int numberOfVertices(0); file.ReadType(&numberOfVertices); Vec3* pVertices(NULL); if( numberOfVertices > numberOfStaticVertices ) pVertices = new Vec3[numberOfVertices]; else pVertices = pStaticVertices; for( int k = 0; k < numberOfVertices; ++k ) file.ReadType(&pVertices[k]); m_pArea->AddConvexHullToSolid(pVertices, bObstruction, numberOfVertices); if( pVertices != pStaticVertices ) delete [] pVertices; } }
void CGameVolumesManager::Load( const char* fileName ) { ////////////////////////////////////////////////////////////////////////// /// Free any left data (it should be empty though...) Reset(); ////////////////////////////////////////////////////////////////////////// /// No need to load in editor /// The saved entities will restore the data inside the manager if (gEnv->IsEditor()) return; CCryFile file; if( false != file.Open( fileName, "rb" ) ) { uint32 nFileVersion = GAME_VOLUMES_FILE_VERSION; file.ReadType( &nFileVersion ); // Verify version... if ((nFileVersion >= 1) && (nFileVersion <= GAME_VOLUMES_FILE_VERSION)) { const uint32 maxVertices = 512; Vec3 readVertexBuffer[maxVertices]; // Read volumes uint32 nVolumeCount = 0; file.ReadType( &nVolumeCount ); m_volumesData.resize( nVolumeCount ); for (uint32 i = 0; i < nVolumeCount; ++i) { EntityVolume& volumeInfo = m_volumesData[i]; uint32 nVertexCount = 0; uint32 nEntityId = 0; f32 fHeight = 0; bool bClosed = false; file.ReadType( &nEntityId ); file.ReadType( &fHeight ); if( nFileVersion > 1 ) { file.ReadType( &bClosed ); } file.ReadType( &nVertexCount ); volumeInfo.entityId = (EntityId)nEntityId; volumeInfo.height = fHeight; volumeInfo.closed = bClosed; volumeInfo.vertices.resize( nVertexCount ); if (nVertexCount > 0) { file.ReadType( &readVertexBuffer[0], nVertexCount ); for (uint32 v = 0; v < nVertexCount; ++v) { volumeInfo.vertices[v] = readVertexBuffer[v]; } } } } else { GameWarning("GameVolumesManger:Load - Failed to load file '%s'. Version mis-match, try to re-export your level", fileName); } file.Close(); } }
void CAreaProxy::SerializeXML( XmlNodeRef &entityNode,bool bLoading ) { if (m_nFlags & FLAG_NOT_SERIALIZE) return; if (bLoading) { XmlNodeRef areaNode = entityNode->findChild( "Area" ); if (!areaNode) return; int nId=0,nGroup=0,nPriority=0; float fProximity = 0; float fHeight = 0; areaNode->getAttr( "Id",nId ); areaNode->getAttr( "Group",nGroup ); areaNode->getAttr( "Proximity",fProximity ); areaNode->getAttr( "Priority",nPriority ); m_pArea->SetID(nId); m_pArea->SetGroup(nGroup); m_pArea->SetProximity(fProximity); m_pArea->SetPriority(nPriority); const char* token(0); XmlNodeRef pointsNode = areaNode->findChild( "Points" ); if (pointsNode) { for (int i = 0; i < pointsNode->getChildCount(); i++) { XmlNodeRef pntNode = pointsNode->getChild(i); Vec3 pos; if (pntNode->getAttr( "Pos",pos )) m_localPoints.push_back(pos); // Get sound obstruction bool bObstructSound = 0; pntNode->getAttr("ObstructSound", bObstructSound); m_abObstructSound.push_back(bObstructSound); } m_pArea->SetAreaType( ENTITY_AREA_TYPE_SHAPE ); areaNode->getAttr( "Height",fHeight ); m_pArea->SetHeight(fHeight); // Set points. OnMove(); } else if (areaNode->getAttr("SphereRadius",m_fRadius)) { // Sphere. areaNode->getAttr("SphereCenter",m_vCenter); m_pArea->SetSphere( m_pEntity->GetWorldTM().TransformPoint(m_vCenter),m_fRadius ); } else if (areaNode->getAttr("VolumeRadius",m_fRadius)) { areaNode->getAttr("Gravity",m_fGravity); areaNode->getAttr("DontDisableInvisible", m_bDontDisableInvisible); AABB box; box.Reset(); // Bezier Volume. pointsNode = areaNode->findChild( "BezierPoints" ); if (pointsNode) { for (int i = 0; i < pointsNode->getChildCount(); i++) { XmlNodeRef pntNode = pointsNode->getChild(i); Vec3 pt; if (pntNode->getAttr( "Pos",pt)) { m_bezierPoints.push_back(pt); box.Add( pt ); } } } m_pArea->SetAreaType( ENTITY_AREA_TYPE_GRAVITYVOLUME ); if (!m_pEntity->GetRenderProxy()) { IEntityRenderProxyPtr pRenderProxy = crycomponent_cast<IEntityRenderProxyPtr>(m_pEntity->CreateProxy( ENTITY_PROXY_RENDER )); m_pEntity->SetFlags(m_pEntity->GetFlags() | ENTITY_FLAG_SEND_RENDER_EVENT); if (box.min.x > box.max.x) box.min = box.max = Vec3(0,0,0); box.min-=Vec3(m_fRadius, m_fRadius, m_fRadius); box.max+=Vec3(m_fRadius, m_fRadius, m_fRadius); Matrix34 tm = m_pEntity->GetWorldTM_Fast(); box.SetTransformedAABB( m_pEntity->GetWorldTM_Fast().GetInverted(),box ); pRenderProxy->SetLocalBounds(box, true); } OnEnable(m_bIsEnable); } else if (areaNode->getAttr("AreaSolidFileName",&token)) { CCryFile file; int nAliasLen = sizeof("%level%")-1; const char* areaSolidFileName; if (strncmp(token,"%level%",nAliasLen) == 0) areaSolidFileName = GetIEntitySystem()->GetSystem()->GetI3DEngine()->GetLevelFilePath(token+nAliasLen); else areaSolidFileName = token; if( file.Open(areaSolidFileName,"rb") ) { int numberOfClosedPolygon = 0; int numberOfOpenPolygon = 0; m_pArea->BeginSettingSolid(m_pEntity->GetWorldTM()); file.ReadType(&numberOfClosedPolygon); file.ReadType(&numberOfOpenPolygon); ReadPolygonsForAreaSolid( file, numberOfClosedPolygon, true ); ReadPolygonsForAreaSolid( file, numberOfOpenPolygon, false ); m_pArea->EndSettingSolid(); } } else { // Box. Vec3 bmin(0,0,0),bmax(0,0,0); areaNode->getAttr("BoxMin",bmin); areaNode->getAttr("BoxMax",bmax); m_pArea->SetBox( bmin,bmax,m_pEntity->GetWorldTM() ); // Get sound obstruction XmlNodeRef const pNodeSoundData = areaNode->findChild("SoundData"); if (pNodeSoundData) { assert(m_abObstructSound.size() == 0); for (int i = 0; i < pNodeSoundData->getChildCount(); ++i) { XmlNodeRef const pNodeSide = pNodeSoundData->getChild(i); if (pNodeSide) { bool bObstructSound = false; pNodeSide->getAttr("ObstructSound", bObstructSound); m_abObstructSound.push_back(bObstructSound); } } } OnMove(); } m_pArea->ClearEntities(); XmlNodeRef entitiesNode = areaNode->findChild( "Entities" ); // Export Entities. if (entitiesNode) { for (int i = 0; i < entitiesNode->getChildCount(); i++) { XmlNodeRef entNode = entitiesNode->getChild(i); EntityId entityId; EntityGUID entityGuid; if(gEnv->pEntitySystem->EntitiesUseGUIDs()) { if (entNode->getAttr( "Guid",entityGuid )) m_pArea->AddEntity( entityGuid ); } else { if (entNode->getAttr( "Id",entityId )) m_pArea->AddEntity( entityId ); } } } } else { // Save points. XmlNodeRef areaNode = entityNode->newChild( "Area" ); areaNode->setAttr( "Id",m_pArea->GetID() ); areaNode->setAttr( "Group",m_pArea->GetGroup() ); areaNode->setAttr( "Proximity",m_pArea->GetProximity() ); areaNode->setAttr( "Priority", m_pArea->GetPriority() ); EEntityAreaType type = m_pArea->GetAreaType(); if (type == ENTITY_AREA_TYPE_SHAPE) { XmlNodeRef pointsNode = areaNode->newChild( "Points" ); for (unsigned int i = 0; i < m_localPoints.size(); i++) { XmlNodeRef pntNode = pointsNode->newChild("Point"); pntNode->setAttr( "Pos",m_localPoints[i] ); pntNode->setAttr("ObstructSound", m_abObstructSound[i]); } areaNode->setAttr( "Height",m_pArea->GetHeight() ); } else if (type == ENTITY_AREA_TYPE_SPHERE) { // Box. areaNode->setAttr("SphereCenter",m_vCenter); areaNode->setAttr("SphereRadius",m_fRadius); } else if (type == ENTITY_AREA_TYPE_BOX) { // Box. Vec3 bmin,bmax; m_pArea->GetBox(bmin,bmax); areaNode->setAttr("BoxMin",bmin); areaNode->setAttr("BoxMax",bmax); // Set sound obstruction XmlNodeRef const pNodeSoundData = areaNode->newChild("SoundData"); if (pNodeSoundData) { assert(m_abObstructSound.size() == 6); size_t nIndex = 0; tSoundObstructionIterConst const ItEnd = m_abObstructSound.end(); for (tSoundObstructionIterConst It = m_abObstructSound.begin(); It != ItEnd ; ++It) { bool const bObstructed = (bool)(*It); stack_string sTemp; sTemp.Format("Side%d", ++nIndex); XmlNodeRef const pNodeSide = pNodeSoundData->newChild(sTemp.c_str()); pNodeSide->setAttr("ObstructSound", bObstructed); } } } else if (type == ENTITY_AREA_TYPE_GRAVITYVOLUME) { areaNode->setAttr("VolumeRadius",m_fRadius); areaNode->setAttr("Gravity",m_fGravity); areaNode->setAttr("DontDisableInvisible", m_bDontDisableInvisible); XmlNodeRef pointsNode = areaNode->newChild( "BezierPoints" ); for (unsigned int i = 0; i < m_bezierPoints.size(); i++) { XmlNodeRef pntNode = pointsNode->newChild("Point"); pntNode->setAttr( "Pos",m_bezierPoints[i] ); } } #ifdef SW_ENTITY_ID_USE_GUID const std::vector<EntityGUID>& entGUIDs=*m_pArea->GetEntitiesGuid(); // Export Entities. if (!entGUIDs.empty()) { XmlNodeRef nodes = areaNode->newChild( "Entities" ); for (uint32 i = 0; i < entGUIDs.size(); i++) { EntityGUID guid = entGUIDs[i]; XmlNodeRef entNode = nodes->newChild( "Entity" ); entNode->setAttr( "Guid",guid ); entNode->setAttr( "Id",gEnv->pEntitySystem->GenerateEntityIdFromGuid(guid) ); } } #else const std::vector<EntityId>& entIDs=*m_pArea->GetEntities(); // Export Entities. if (!entIDs.empty()) { XmlNodeRef nodes = areaNode->newChild( "Entities" ); for (uint32 i = 0; i < entIDs.size(); i++) { int entityId = entIDs[i]; XmlNodeRef entNode = nodes->newChild( "Entity" ); entNode->setAttr( "Id",entityId ); } } #endif } }