Beispiel #1
0
        public void generateBlocks()
        {
            blocks.Clear();
            int blockCount = (uncompressedSize + blocksize - 1) / blocksize;

            compressedSize = 0;
            for (int i = 0; i < blockCount; i++)
            {
                int blockOffset = i * blocksize;
                int blockEnd    = blockOffset + blocksize;
                if (blockEnd > uncompressedSize)
                {
                    blockEnd = uncompressedSize;
                }

                var block = new ChunkBlock();
                block.uncompressedDataSize = blockEnd - blockOffset;
                block.uncompressedData     = new byte[block.uncompressedDataSize];
                Array.ConstrainedCopy(uncompressedData, blockOffset, block.uncompressedData, 0, block.uncompressedData.Length);

                block.compress(compFlag);

                compressedSize += block.compressedSize;
                blocks.Add(block);
            }
        }
Beispiel #2
0
        public void Decompress(byte[] uncompressedData, int blockCount, BinaryReader reader, int compFlag)
        {
            int blockOffset = 0;

            for (int j = 0; j < blockCount; ++j)
            {
                var block = new ChunkBlock();
                block.compressedSize       = reader.ReadInt32();
                block.uncompressedDataSize = reader.ReadInt32();

                chunkBlocks.Add(block);
            }


            foreach (ChunkBlock block in chunkBlocks)
            {
                block.compressedData = reader.ReadBytes(block.compressedSize);
                block.decompressPackageFlags(compFlag);

                Array.ConstrainedCopy(block.uncompressedData, 0, uncompressedData, blockOffset, block.uncompressedDataSize);
                blockOffset += block.uncompressedDataSize;

                //save memory
                block.uncompressedData = null;
            }
        }
Beispiel #3
0
        public void ReadData(GpkPackage package, GpkExport export)
        {
            objectExport = export;
            BinaryReader reader     = new BinaryReader(new MemoryStream(export.Data));
            IProperty    formatProp = export.Properties.Find(t => ((GpkBaseProperty)t).name == "Format");
            String       format     = ((GpkByteProperty)formatProp).nameValue;

            startUnk = reader.ReadBytes(16);
            int length = reader.ReadInt32();

            if (length > 0)
            {
                tgaPath = Reader.ReadString(reader, length);
            }
            else
            {
                inUnicode = true;
                tgaPath   = Reader.ReadUnicodeString(reader, (length * -1) * 2);
            }


            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                MipMap map = new MipMap();

                //chunk
                //info
                map.compFlag = reader.ReadInt32();

                map.uncompressedSize = reader.ReadInt32();
                map.compChunkSize    = reader.ReadInt32();
                map.compChunkOffset  = reader.ReadInt32();
                var temp = ((CompressionTypes)map.compFlag & NothingToDo);

                if (((CompressionTypes)map.compFlag & NothingToDo) == 0)
                {
                    //header
                    map.signature = reader.ReadUInt32(); //0x9e2a83c1
                    Debug.Assert(map.signature == MipMap.DEFAULT_SIGNATURE);

                    map.blocksize = reader.ReadInt32();

                    map.compressedSize = reader.ReadInt32();
                    map.uncompressedSize_chunkheader = reader.ReadInt32();
                    map.uncompressedData             = new byte[map.uncompressedSize];

                    int blockCount  = (map.uncompressedSize + map.blocksize - 1) / map.blocksize;
                    int blockOffset = 0;


                    for (int j = 0; j < blockCount; ++j)
                    {
                        var block = new ChunkBlock();
                        block.compressedSize       = reader.ReadInt32();
                        block.uncompressedDataSize = reader.ReadInt32();

                        map.blocks.Add(block);
                    }


                    foreach (ChunkBlock block in map.blocks)
                    {
                        block.compressedData = reader.ReadBytes(block.compressedSize);
                        block.decompress(map.compFlag);

                        Array.ConstrainedCopy(block.uncompressedData, 0, map.uncompressedData, blockOffset, block.uncompressedDataSize);
                        blockOffset += block.uncompressedDataSize;

                        //save memory
                        block.uncompressedData = null;
                    }
                }
                else
                {
                    logger.Trace("{0}, MipMap {0}, no data!!", export.ObjectName, i);
                }

                map.sizeX = reader.ReadInt32();
                map.sizeY = reader.ReadInt32();


                maps.Add(map);
            }

            guid = reader.ReadBytes(16);
        }