Просмотр исходного кода

Merge pull request #73 from paulsapps/master

Some fixes for #70
paulsapps 11 лет назад
Родитель
Сommit
4c99e9d3b9

+ 2 - 2
CMakeLists.txt

@@ -12,8 +12,8 @@ set(QGears_VERSION_PATCH 0)
 if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
   # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
   # differentiation between debug and release builds.
-  set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
-  message("CMAKE_BUILD_TYPE was empty defaulting to RELEASE")
+  set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
+  message("CMAKE_BUILD_TYPE was empty defaulting to Release")
 endif ()
 
 message("CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE} CMAKE_BINARY_DIR is ${CMAKE_BINARY_DIR}")

+ 2 - 2
QGearsMain/include/data/QGearsBackgroundFile.h

@@ -73,8 +73,8 @@ namespace QGears
             bool   flags_20[2];
             uint16 unknown_1C; // maybe some 'mode'
             uint16 data_page;
-            uint16 unknown_20;
-            uint16 unknown_22;
+            uint16 data_page2; // used for special effects pages, when data_page2 != 0, it must be used instead of data_page
+            uint16 colourDepth;
             Ogre::Vector3 unknown_24;
         };
 

+ 8 - 8
QGearsMain/include/data/QGearsFLevelFileSerializer.h

@@ -62,21 +62,21 @@ namespace QGears
         };
 
     protected:
-        virtual void    readFileHeader( Ogre::DataStreamPtr &stream );
+        void    readFileHeader( Ogre::DataStreamPtr &stream );
 
-        virtual void    readSectionData( Ogre::DataStreamPtr &stream, Ogre::DataStreamPtr &out_buffer );
+        void    readSectionData(Ogre::DataStreamPtr &stream, Ogre::DataStreamPtr &out_buffer, size_t sectionSize);
         virtual void    readSection( Ogre::DataStreamPtr &stream, FLevelFile* pDest, const size_t section_index );
 
         template<typename ResourceManagerType>
         Ogre::ResourcePtr createResource( FLevelFile *pDest, const String &extension );
 
-        virtual void    readCameraMatrix( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-        virtual void    readModelList   ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-        virtual void    readPalette     ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-        virtual void    readWalkmesh    ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-        virtual void    readBackground  ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
+        void    readCameraMatrix( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
+        void    readModelList   ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
+        void    readPalette     ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
+        void    readWalkmesh    ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
+        void    readBackground  ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
 
-        virtual void    readEnd( Ogre::DataStreamPtr &stream );
+        void    readEnd( Ogre::DataStreamPtr &stream );
 
         template<typename ValueType> void
         readVector( Ogre::DataStreamPtr &stream, std::vector<ValueType> &pDest, size_t count );

+ 9 - 9
QGearsMain/include/data/QGearsLZSDataStream.h

@@ -94,19 +94,19 @@ namespace QGears
                     LZSDataStream( const String &name, const Ogre::DataStreamPtr &compressed_stream );
         virtual    ~LZSDataStream();
 
-        virtual size_t 	read( void *buf, size_t count );
+        virtual size_t 	read( void *buf, size_t count ) override;
 
-        virtual bool    eof( void ) const;
+        virtual bool    eof( void ) const override;
 
-		virtual void skip(long count);
-	    virtual void seek( size_t pos );
-	    virtual size_t tell(void) const;
-        virtual void close(void);
+		virtual void skip(long count) override;
+	    virtual void seek( size_t pos ) override;
+	    virtual size_t tell(void) const override;
+        virtual void close(void) override;
 
-        virtual size_t availableCompressed( void ) const { return m_available_compressed; }
-        virtual size_t availableUncompressed( void ) const { return m_buffer.avail(); }
+        size_t availableCompressed( void ) const { return m_available_compressed; }
+        size_t availableUncompressed( void ) const { return m_buffer.avail(); }
 
-        virtual void flipEndian( uint32 &inout_data );
+        void flipEndian( uint32 &inout_data );
 
     protected:
         virtual void init();

+ 50 - 40
QGearsMain/src/data/QGearsBackgroundFile.cpp

@@ -158,55 +158,65 @@ namespace QGears
             ;++it)
         {
             const Page& data_page( m_pages[it->data_page] );
-            const PaletteFile::Page& palette_page( palette->getPage( it->palette_page ) );
-            const Pixel& src( it->src );
-            if( !data_page.enabled )
+            if (data_page.value_size == 2)
             {
+                // TODO FIX ME
                 Ogre::LogManager::getSingleton().stream()
-                    << "Error: referencing an disabled data page";
+                    << "Error: value_size(RGB16) not implemented";
+                break;
             }
-            for( uint16 y( SPRITE_HEIGHT ); y--; )
+            else if (data_page.value_size == 1)
             {
-                for( uint16 x( SPRITE_WIDTH ); x--; )
+                const PaletteFile::Page& palette_page(palette->getPage(it->palette_page));
+                const Pixel& src(it->src);
+                if (!data_page.enabled)
                 {
-                    size_t data_index( (src.y + y) * PAGE_DATA_WIDTH + src.x + x );
-                    if( data_index >= data_page.data.size() )
-                    {
-                        Ogre::LogManager::getSingleton().stream()
-                            << "Error: data page Index out of Bounds " << data_index;
-                    }
-                    uint8 index( data_page.data.at(data_index) );
-                    if( index >= palette_page.size() )
-                    {
-                        Ogre::LogManager::getSingleton().stream()
-                            << "Error: palette page Index out of Bounds " << index;
-                    }
-
-                    data_index = (dst_y + y ) * row_pitch + dst_x + x;
-                    if( data_index >= pixel_count )
-                    {
-                        Ogre::LogManager::getSingleton().stream()
-                            << "Error: writing Pixel out of Bounds " << data_index
-                            << " " << (dst_x + x) << " x " << dst_y + y;
-                    }
-                    Ogre::ColourValue colour( palette_page[ index ] );
-                    if( index == 0 && colour != Ogre::ColourValue::Black)
-                    {
-                        colour.a = 0;
-                    }
-                    else
+                    Ogre::LogManager::getSingleton().stream()
+                        << "Error: referencing an disabled data page";
+                }
+                for (uint16 y(SPRITE_HEIGHT); y--;)
+                {
+                    for (uint16 x(SPRITE_WIDTH); x--;)
                     {
-                        colour.a = 1;
+                        size_t data_index((src.y + y) * PAGE_DATA_WIDTH + src.x + x);
+                        if (data_index >= data_page.data.size())
+                        {
+                            Ogre::LogManager::getSingleton().stream()
+                                << "Error: data page Index out of Bounds " << data_index;
+                        }
+                        uint8 index(data_page.data.at(data_index));
+                        if (index >= palette_page.size())
+                        {
+                            Ogre::LogManager::getSingleton().stream()
+                                << "Error: palette page Index out of Bounds " << index;
+                        }
+
+                        data_index = (dst_y + y) * row_pitch + dst_x + x;
+                        if (data_index >= pixel_count)
+                        {
+                            Ogre::LogManager::getSingleton().stream()
+                                << "Error: writing Pixel out of Bounds " << data_index
+                                << " " << (dst_x + x) << " x " << dst_y + y;
+                        }
+                        Ogre::ColourValue colour(palette_page[index]);
+                        if (index == 0 && colour != Ogre::ColourValue::Black)
+                        {
+                            colour.a = 0;
+                        }
+                        else
+                        {
+                            colour.a = 1;
+                        }
+                        color[data_index] = colour.getAsARGB();
                     }
-                    color[data_index] = colour.getAsARGB();
                 }
-            }
 
-            dst_x += SPRITE_WIDTH;
-            if( dst_x >= width )
-            {
-                dst_x = 0;
-                dst_y += SPRITE_HEIGHT;
+                dst_x += SPRITE_WIDTH;
+                if (dst_x >= width)
+                {
+                    dst_x = 0;
+                    dst_y += SPRITE_HEIGHT;
+                }
             }
         }
 

+ 2 - 2
QGearsMain/src/data/QGearsBackgroundFileSerializer.cpp

@@ -172,8 +172,8 @@ namespace QGears
 
         readShort( stream, pDest.unknown_1C );
         readShort( stream, pDest.data_page );
-        readShort( stream, pDest.unknown_20 );
-        readShort( stream, pDest.unknown_22 );
+        readShort( stream, pDest.data_page2 );
+        readShort( stream, pDest.colourDepth );
         readObject( stream, pDest.unknown_24 );
         pDest.unknown_24 /= unknown_24_SCALE;
         stream->skip( 2 * 2 ); // 2 * uint16 unused

+ 50 - 19
QGearsMain/src/data/QGearsFLevelFileSerializer.cpp

@@ -65,49 +65,68 @@ namespace QGears
 
     //--------------------------------------------------------------------------
     void
-    FLevelFileSerializer::importFLevelFile( Ogre::DataStreamPtr &stream, FLevelFile* pDest )
+        FLevelFileSerializer::importFLevelFile(Ogre::DataStreamPtr &stream, FLevelFile* pDest)
     {
-        size_t start_position( stream->tell() );
-        readFileHeader( stream );
+        // Read header
+        const size_t start_position(stream->tell());
+        readFileHeader(stream);
 
+        // Read section offsets
         std::vector<uint32> section_offsetsVec(m_header.section_count);
+        std::vector<uint32> section_sizesVec(m_header.section_count);
+        readInts(stream, section_offsetsVec.data(), m_header.section_count);
 
-        uint32* section_offsets = section_offsetsVec.data();
+        // Now calculate section sizes
+        size_t fileSize = stream->size();
+
+        for (size_t i = 0; i < section_offsetsVec.size(); i++)
+        {
+            if (i+1 == section_offsetsVec.size())
+            {
+                // We need to know the file size to calculate this, since we don't have it we
+                // just read till end of stream on the final section.
+                section_sizesVec[i] = 0;
+            }
+            else
+            {
+                section_sizesVec[i] = section_offsetsVec[i + 1] - section_offsetsVec[i] - 4;
+            }
+        }
 
-        readInts( stream, section_offsets, m_header.section_count );
 
         Ogre::DataStreamPtr section;
-        for( size_t i(0); i < m_header.section_count; ++i )
+        for (size_t i(0); i < m_header.section_count; ++i)
         {
-            size_t current_offset( stream->tell() - start_position );
-            size_t section_gap( section_offsets[i] - current_offset );
-            if( current_offset > section_offsets[i] )
+            const size_t current_offset(stream->tell() - start_position);
+            const size_t section_gap(section_offsetsVec[i] - current_offset);
+            if (current_offset > section_offsetsVec[i])
             {
                 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
-                    ,"FLevel sections overlap"
-                    ,"FLevelFileSerializer::importFLevelFile" );
+                    , "FLevel sections overlap"
+                    , "FLevelFileSerializer::importFLevelFile");
             }
-            else if( section_gap )
+            else if (section_gap)
             {
-                stream->skip( section_gap );
+                stream->skip(section_gap);
                 Ogre::LogManager::getSingleton().stream()
                     << "Warning: skiping gap in front of section " << i
                     << " gap size " << section_gap
                     << " FLevelFileSerializer::importFLevelFile";
             }
 
-            readSectionData( stream, section );
-            readSection( section, pDest, i );
+            readSectionData(stream, section, section_sizesVec[i]);
+            readSection(section, pDest, i);
             section->close();
             section.setNull();
         }
-        readEnd( stream );
+        readEnd(stream);
     }
 
     //--------------------------------------------------------------------------
     void
     FLevelFileSerializer::readFileHeader( Ogre::DataStreamPtr &stream )
     {
+        // Read version, check its zero
         readShort( stream, m_header.version );
         if( m_header.version != 0 )
         {
@@ -116,6 +135,7 @@ namespace QGears
                 ,"FLevelFileSerializer::importFLevelFile" );
         }
 
+        // Read number of sections, check its 9
         readUInt32(   stream, m_header.section_count );
         if( m_header.section_count != SECTION_COUNT )
         {
@@ -129,14 +149,25 @@ namespace QGears
     //--------------------------------------------------------------------------
     void
     FLevelFileSerializer::readSectionData( Ogre::DataStreamPtr &stream
-                                          ,Ogre::DataStreamPtr &out_buffer )
+                                          ,Ogre::DataStreamPtr &out_buffer,
+                                          size_t sectionSize )
     {
+        // This can be wrong, we read it so we're at the correct stream position
+        // but use our manually calculated section size instead.
         uint32 length( 0 );
         readUInt32( stream, length );
+
         // TODO: implement SubDataStream class to restrict access size etc
         // so we don't have to copy the whole memory
-        Ogre::MemoryDataStream *buffer( new Ogre::MemoryDataStream( length ) );
-        stream->read( buffer->getPtr(), length );
+        if (sectionSize == 0)
+        {
+            // TODO FIX ME - read to EOS
+            // Hope this is actually correct :)
+            sectionSize = length;
+        }
+
+        Ogre::MemoryDataStream *buffer(new Ogre::MemoryDataStream(sectionSize));
+        stream->read(buffer->getPtr(), sectionSize);
         out_buffer = Ogre::DataStreamPtr( buffer );
     }
 

+ 1 - 0
QGearsMain/src/data/QGearsLGPArchive.cpp

@@ -70,6 +70,7 @@ namespace QGears
             file_info.archive = this;
             file_info.filename = it->file_name;
             StringUtil::splitFilename( it->file_name, file_info.basename, file_info.path );
+            // TODO: This is actually still the compressed size!!
             file_info.uncompressedSize = it->data_size;
             file_info.compressedSize = file_info.uncompressedSize;
 

+ 1 - 0
QGearsMain/src/data/QGearsLZSDataStream.cpp

@@ -68,6 +68,7 @@ namespace QGears
         #if OGRE_ENDIAN == OGRE_ENDIAN_BIG
             flipEndian( m_available_compressed );
         #endif
+        mSize = m_available_compressed; // so the base size() works
     }
 
     //---------------------------------------------------------------------

+ 4 - 3
utilities/q-gears-launcher/src/ff7DataInstaller.cpp

@@ -138,9 +138,9 @@ void FF7DataInstaller::ConvertFields(std::string archive, std::string outDir)
     Ogre::StringVectorPtr resources = mApp.ResMgr()->listResourceNames("FFVIIFields", "*");
     for (auto& resourceName : *resources)
     {
-        if (!QGears::StringUtil::endsWith(resourceName, ".tex"))
+        if (!QGears::StringUtil::endsWith(resourceName, ".tex") /*&& resourceName == "blin67_4"*/)
         {
-            try
+            //try
             {
                 QGears::FLevelFilePtr field = QGears::LZSFLevelFileManager::getSingleton().load(resourceName, "FFVIIFields").staticCast<QGears::FLevelFile>();
 
@@ -150,6 +150,7 @@ void FF7DataInstaller::ConvertFields(std::string archive, std::string outDir)
                 bgImage->save(outDir + "/" + field->getName() + ".png");
                 delete bgImage;
             }
+            /*
             catch (const Ogre::Exception& ex)
             {
                 std::cout << "ERROR converting: " << resourceName << " Exception: " << ex.what() << std::endl;
@@ -157,7 +158,7 @@ void FF7DataInstaller::ConvertFields(std::string archive, std::string outDir)
             catch (const std::exception& ex)
             {
                 std::cout << "ERROR converting: " << resourceName << " Exception: " << ex.what() << std::endl;
-            }
+            }*/
         }
     }
 }