void SFDLoadableHeader::loadInitialHeader( SharedBuffer& buf ) { // Load initial header. const char* str = buf.readNextString(); if ( strcmp( str, "storkafinger" ) != 0 ) { m_state = failed_to_load; m_nbrBytesToRead = 0; innerLoad(); return; } // Version m_version = buf.readNextBAByte(); // Encryption type. m_encryptionType = encryption_t( buf.readNextBAByte() ); // Set the right xorbuffer depending on the encryption type. switch ( m_encryptionType ) { case ( no_encryption ) : m_xorBuffer = NULL; break; case ( uid_encryption ) : MC2_ASSERT( m_uidXorBuffer != NULL ); m_xorBuffer = m_uidXorBuffer; break; case ( warez_encryption ) : MC2_ASSERT( m_warezXorBuffer != NULL ); m_xorBuffer = m_warezXorBuffer; break; } // Header size. m_headerSize = buf.readNextBALong(); // Rest of buffer is encrypted. if ( m_xorBuffer != NULL ) { m_fileHandler->setXorHelper( XorHelper( m_xorBuffer->getBufferAddress(), m_xorBuffer->getBufferSize(), buf.getCurrentOffset() ) ); } m_nbrBytesToRead = m_headerSize; // Load the rest. m_state = loaded_initial_header; innerLoad(); }
void SFDLoadableHeader::loadRemainingHeader( SharedBuffer& buf ) { // File size. m_fileSize = buf.readNextBALong(); // The name. m_name = buf.readNextString(); mc2dbg << "[SFDLH] m_name = " << m_name << endl; // Check the file size. if ( m_fileHandler->getFileSize() != m_fileSize ) { m_state = failed_to_load; m_nbrBytesToRead = 0; innerLoad(); return; } // Creation time. m_creationTime = buf.readNextBALong(); // Null terminated strings? m_stringsAreNullTerminated = buf.readNextBAByte(); // Longest length of string. m_maxStringSize = buf.readNextBAByte(); // Nbr initial chars. byte nbrInitialChars = buf.readNextBAByte(); m_initialCharacters.resize( nbrInitialChars ); // Initial chars. {for ( byte b = 0; b < nbrInitialChars; ++b ) { m_initialCharacters[ b ] = buf.readNextBAByte(); }} // Nbr route ids. byte nbrRouteIDs = buf.readNextBAByte(); m_routeIDs.reserve( nbrRouteIDs ); {for ( byte b = 0; b < nbrRouteIDs; ++b ) { uint32 id = buf.readNextBALong(); uint32 creationTime = buf.readNextBALong(); m_routeIDs.push_back( RouteID( id, creationTime ) ); }} // Number of bits for the string index. m_strIdxEntrySizeBits = buf.readNextBALong(); // Position for the start of strings index. m_strIdxStartOffset = buf.readNextBALong(); // Number strings. m_nbrStrings = buf.readNextBALong(); // Position for the start of string data. m_strDataStartOffset = buf.readNextBALong(); // Position for the start of the buffers index. m_bufferIdxStartOffset = buf.readNextBALong(); // Position for the start of the buffer data. m_bufferDataStartOffset = buf.readNextBALong(); // If to read debug param strings for the multi buffers. m_readDebugParams = buf.readNextBAByte(); // The tile collections. uint32 nbrCollections = buf.readNextBAShort(); m_tileCollection.resize( nbrCollections ); {for ( uint32 i = 0; i < nbrCollections; ++i ) { m_tileCollection[ i ].load( buf ); }} // All is now loaded. m_state = loaded_all_header; m_nbrBytesToRead = 0; innerLoad(); }