//////////////////////////////////////////////////////////////////////////
// low level function, reads directly from the file
// TODO: remove all those pOSSaveReader parameter chains and make it a member, passing it along is not needed anymore
void CReader::ReadDataFromFileInternal( IPlatformOS::ISaveReaderPtr& pOSSaveReader, void* pDst, uint32 numBytes )
{
	assert( pOSSaveReader.get() );
	
	if (!m_errorReading)
	{
		IPlatformOS::EFileOperationCode code = pOSSaveReader->ReadBytes( pDst, numBytes );
		CheckErrorFlag( code );
	}
}
bool CReader::ReadBinaryFile( const char* pFileName )
{
	IPlatformOS::ISaveReaderPtr pOSSaveReader = gEnv->pSystem->GetPlatformOS()->SaveGetReader( pFileName, IPlatformOS::Unknown_User );
	if (!m_pZLibBuffer)
		m_pZLibBuffer = new uint8[ XMLCPB_ZLIB_BUFFER_SIZE ];
	if (!m_pZLibCompressedBuffer)
		m_pZLibCompressedBuffer = new uint8[ XMLCPB_ZLIB_BUFFER_SIZE ];
	m_errorReading = pOSSaveReader.get()==NULL;
	
	if (!m_errorReading)
	{
		size_t totalNumBytesInFile = 0;
		IPlatformOS::EFileOperationCode code = pOSSaveReader->GetNumBytes( totalNumBytesInFile );
		m_totalSize = totalNumBytesInFile;
		CheckErrorFlag( code );

		if (!m_errorReading)
		{
			SFileHeader fileHeader;
			pOSSaveReader->Seek( -int(sizeof(fileHeader)), IPlatformOS::ISaveReader::ESM_END );
			ReadDataFromFileInternal( pOSSaveReader, &fileHeader, sizeof(fileHeader) );
#ifdef XMLCPB_CHECK_FILE_INTEGRITY			
			m_errorReading = CheckFileCorruption( pOSSaveReader, fileHeader, m_totalSize );
#endif			
			
			pOSSaveReader->Seek( 0, IPlatformOS::ISaveReader::ESM_BEGIN );
			
			if (fileHeader.m_fileTypeCheck!=fileHeader.FILETYPECHECK)
			{
				CryWarning( VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "XMLCPB ERROR: file type signature not correct. Savegame File corrupted!" );
				m_errorReading = true;
			}
			
			if (!m_errorReading)
			{
				m_nodesDataSize = fileHeader.m_sizeNodes;
				m_numNodes = fileHeader.m_numNodes;
				m_buffer.ReadFromFile( *this, pOSSaveReader, fileHeader.m_sizeNodes );
				m_tableTags.ReadFromFile( *this, pOSSaveReader, fileHeader.m_tags );
				m_tableAttrNames.ReadFromFile( *this, pOSSaveReader, fileHeader.m_attrNames );
				m_tableStrData.ReadFromFile( *this, pOSSaveReader, fileHeader.m_strData );
				m_tableAttrSets.ReadFromFile( *this, pOSSaveReader, fileHeader );
				CreateNodeAddressTables();
			}
			
			if (!m_errorReading)
			{
				const CNodeLiveReader& root = ActivateLiveNodeFromCompact( m_numNodes - 1 ); // the last node is always the root
				assert( root.GetLiveId()==XMLCPB_ROOTNODE_ID );

				pOSSaveReader->TouchFile();
			}
		}	

		pOSSaveReader->Close();
	}
	
	CryLog("[LOAD GAME] --Binary saveload: reading done--");
		
	if (m_errorReading)
		CryWarning( VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "XMLCPB ERROR: while reading the file: '%s'", pFileName );

	return !m_errorReading;
}