View Single Post in: TS4 Compression Algorithm

Warrior Gryphon
site owner
#7 Old 9th Jul 2014 at 1:54 PM
So turns out... it's standard C# deflate.

The following will read the compressed chunks: (This is VERY quick and dirty as I have just been experimenting with it)

                    if (this.dbpf.smallHeader.MajorVersion == 2 && this.dbpf.smallHeader.MinorVersion == 1)
                        data = new byte[entry.CompressedSize];
                        this.Stream.Read(data, 0, data.Length);
                        MemoryStream tmpData = new MemoryStream(data);


                        System.IO.Compression.DeflateStream decompress = new System.IO.Compression.DeflateStream(tmpData, System.IO.Compression.CompressionMode.Decompress, true);

                        MemoryStream decompressed = new MemoryStream();
                        MadScience.StreamHelpers.CopyStream(decompress, decompressed);
                        decompressed.Seek(0, SeekOrigin.Begin);

                        data = new byte[entry.DecompressedSize];
                        data = decompressed.ToArray();


The key was actually skipping the first 2 bytes of the compressed stream (with their 0xDA78). Then the resulting decompressed size matches what is in the index.

To prove this works, here's a DDS file:

Story books are full of fairy tales, of Kings and Queens, and the bluest skies.