| 8 | |
| 9 | |
| 10 | Tr2CmfContents::Tr2CmfContents( IBlueStream& stream, const char* filename ) |
| 11 | { |
| 12 | void* data; |
| 13 | if( !stream.LockData( &data, 0 ) ) |
| 14 | { |
| 15 | CCP_LOGERR( "Failed to read CMF file %s", filename ); |
| 16 | return; |
| 17 | } |
| 18 | auto size = stream.GetSize(); |
| 19 | auto validated = cmf::ValidateFile( data, size, { true, true } ); |
| 20 | if( !validated ) |
| 21 | { |
| 22 | CCP_LOGERR( "Invalid CMF file %s: %s", filename, validated.error.c_str() ); |
| 23 | return; |
| 24 | } |
| 25 | auto header = static_cast<cmf::Header*>( data ); |
| 26 | m_sections.reserve( header->sections.size() ); |
| 27 | for( const auto& section : header->sections ) |
| 28 | { |
| 29 | m_sections.emplace_back(); |
| 30 | auto& dest = m_sections.back(); |
| 31 | dest.section = section; |
| 32 | dest.data = std::make_unique<uint8_t[]>( section.compressedSize ); |
| 33 | memcpy( dest.data.get(), (uint8_t*)data + section.offset, section.compressedSize ); |
| 34 | } |
| 35 | cmf::OffsetsToPointers( *reinterpret_cast<cmf::Data*>( m_sections[0].data.get() ) ); |
| 36 | } |
| 37 | |
| 38 | Tr2CmfContents::operator bool() const |
| 39 | { |