예제 #1
0
        private bool Load( System.IO.FileStream stream )
        {
            CreationTime = stream.ReadUInt64();
            FileHashArrayOffset = stream.ReadUInt32();

            // This should always be 0x20, so we can use it to detect endianness
            if ( FileHashArrayOffset <= 0xFFFF ) {
                Endian = Util.Endianness.LittleEndian;
            } else {
                Endian = Util.Endianness.BigEndian;
                CreationTime = CreationTime.SwapEndian();
                FileHashArrayOffset = FileHashArrayOffset.SwapEndian();
            }

            // We adjust the offsets to be from file start rather than from position, makes them easier to seek to.
            FileHashArrayOffset += (uint)stream.Position - 4;
            FileHashArraySize = stream.ReadUInt32().FromEndian( Endian );
            VirtualHashArrayOffset = (uint)stream.Position;
            VirtualHashArrayOffset += stream.ReadUInt32().FromEndian( Endian );
            VirtualHashArraySize = stream.ReadUInt32().FromEndian( Endian );
            FileArrayOffset = (uint)stream.Position;
            FileArrayOffset += stream.ReadUInt32().FromEndian( Endian );
            FileArraySize = stream.ReadUInt32().FromEndian( Endian );
            VirtualPackArrayOffset = (uint)stream.Position;
            VirtualPackArrayOffset += stream.ReadUInt32().FromEndian( Endian );
            VirtualPackArraySize = stream.ReadUInt32().FromEndian( Endian );

            // Hashes
            stream.Position = FileHashArrayOffset;
            FileHashArray = new List<TOFHDBhash>( (int)FileHashArraySize );
            for ( UInt32 i = 0; i < FileHashArraySize; i++ ) {
                FileHashArray.Add( new TOFHDBhash() {
                    Key = stream.ReadUInt32().FromEndian( Endian ),
                    Value = stream.ReadUInt32().FromEndian( Endian ),
                } );
            }

            // Files
            stream.Position = FileArrayOffset;
            FileArray = new List<TOFHDBfile>( (int)FileArraySize );
            for ( UInt32 i = 0; i < FileArraySize; i++ ) {
                FileArray.Add( new TOFHDBfile() {
                    Filesize = stream.ReadUInt64().FromEndian( Endian ),
                    CompressedSize = stream.ReadUInt64().FromEndian( Endian ),
                    Offset = stream.ReadUInt64().FromEndian( Endian ),
                    Hash = stream.ReadUInt32().FromEndian( Endian ),
                    Extension = stream.ReadAscii( 0x0A ).TrimNull(),
                    Unknown = stream.ReadUInt16().FromEndian( Endian ),
                } );
            }

            return true;
        }