Beispiel #1
0
        private Stream InflateData(Stream stream)
        {
            byte[] deflatedDate = new byte[BlockSizes.Sum()];

            // Lock stream while reading deflated data
            lock (stream) {
                stream.Position = Offset;
                stream.Read(deflatedDate);
            }

            BigEndianBinaryReader reader = new(new MemoryStream(deflatedDate));

            const int zHeader = 0x78DA;

            MemoryStream outputStream = new();

            foreach (int size in BlockSizes)
            {
                ushort num = reader.ReadUInt16();
                reader.BaseStream.Position -= 2L;

                byte[] data = reader.ReadBytes(size);

                // Compressed
                if (num == zHeader)
                {
                    try
                    {
                        Archives.Unzip(data, outputStream, false);
                    }
                    catch (Exception ex)
                    {
                        // corrupt CDLC zlib.net exception ... try to unpack
                        Logger.LogError(string.IsNullOrEmpty(Name)
                            ? @$ "CDLC contains a zlib exception.{Environment.NewLine}Warning: {ex}"
                            : @$ "CDLC contains a broken datachunk in file '{Name.Split('/').Last()}'.{Environment.NewLine}Warning Type 1: {ex}");
                    }
                }
                // Raw
                else
                {
                    outputStream.Write(data, 0, data.Length);
                }
            }

            outputStream.Seek(0, SeekOrigin.Begin);
            outputStream.Flush();

            return(outputStream);
        }
Beispiel #2
0
        public void Open(Stream fileStream, GamePlatform platform)
        {
            using MemoryStream decrypted = new();
            using BinaryReader ebrDec    = new(decrypted);

            Decrypt(fileStream, decrypted, GetEncodingKey(platform));

            using MemoryStream output = new();
            //unZip
            ushort xU = ebrDec.ReadUInt16();

            decrypted.Position -= 2;
            if (xU == 0x78DA || xU == 0xDA78) //LE 55928 //BE 30938
            {
                Archives.Unzip(decrypted, output, false);
            }

            output.Seek(0, SeekOrigin.Begin);

            Data = SngData.Read(new BinaryReader(output));
        }