Esempio n. 1
0
        private object FromDeflated(byte[] bytes, Type targetType)
        {
            byte[] decoded    = Deflate.Decode(bytes);
            string serialized = Encoding.UTF8.GetString(decoded);

            return(JsonConvert.DeserializeObject(serialized, targetType));
        }
Esempio n. 2
0
        public void RoundTripString(string start)
        {
            byte[] encoded = Deflate.Encode(start);

            byte[] finishBytes = Deflate.Decode(encoded);
            string finish      = Encoding.UTF8.GetString(finishBytes);

            Assert.Equal(start, finish);
        }
Esempio n. 3
0
        public void RoundTripListObject()
        {
            List <int> start = new List <int> {
                1, 3, 4
            };
            string startString = JsonConvert.SerializeObject(start);

            byte[] encoded = Deflate.Encode(startString);

            byte[]     finishBytes  = Deflate.Decode(encoded);
            string     finishString = Encoding.UTF8.GetString(finishBytes);
            List <int> finish       = JsonConvert.DeserializeObject <List <int> >(finishString);

            Assert.Equal(start, finish);
        }
Esempio n. 4
0
        public override GameFile[] Unpack()
        {
            this.file.BaseStream.Position = this.file.Position;
            BinaryReaderBE br = new BinaryReaderBE(this.file.BaseStream);
            GameFile       decoded;

            // Read header
            if (br.ReadUInt32() != MagicStamp)
            {
                throw new InvalidDataException();
            }

            if (br.ReadUInt16() != Version)
            {
                throw new InvalidDataException();
            }

            ushort numBlocks        = br.ReadUInt16();
            int    decompressedSize = br.ReadInt32();
            uint   fileSize         = br.ReadUInt32();

            decoded          = new GameFile(new MemoryStream(decompressedSize));
            decoded.Size     = decompressedSize;
            decoded.FilePath = this.file.FilePath;
            if (this.file.FileName.Contains(".zarc"))
            {
                decoded.FileName = this.file.FileName.Remove(this.file.FileName.LastIndexOf(".zarc"));
            }
            else
            {
                decoded.FileName = this.file.FileName;
            }

            for (int i = 0; i < numBlocks; i++)
            {
                this.file.BaseStream.Position = this.file.Position + HeaderSize + i * EntrySize;

                // Read entry
                int  blockCompSize   = br.ReadUInt16();
                int  blockDecompSize = br.ReadUInt16();
                uint dataOffset      = br.ReadUInt32();

                if (blockDecompSize == 0)
                {
                    blockDecompSize = 0x10000;
                }

                // Invalid file
                if (dataOffset <= 0x20)
                {
                    return(new GameFile[0]);
                }

                Deflate deflate = new Deflate(
                    this.file.BaseStream,
                    this.file.Position + dataOffset - 1,
                    blockCompSize);
                try
                {
                    deflate.Decode(decoded.BaseStream, blockDecompSize);
                }
                catch
                {
                    return(new GameFile[0]);
                }
            }

            br = null;

            return(new GameFile[] { decoded });
        }