Beispiel #1
0
        public void WriteFilesToStream(EdataPackage pack, Stream s, int version = Version2)
        {
            int dirSize = GetSubTreeSize(pack.Root, Version2); // TODO verify

            s.Seek(dirSize, SeekOrigin.Current);

            WriteAllFilesInTree(pack.Root, pack, s, s.Position);
        }
Beispiel #2
0
        public void WriteAllFilesInTree(EdataDir node, EdataPackage pack, Stream s, long fileOffset)
        {
            foreach (var file in node.Files)
            {
                var data = pack.GetRawData(file, false);
                file.Offset = s.Position - fileOffset;
                file.Size   = data.Length;
                s.Write(data, 0, data.Length);
            }

            foreach (var child in node.Children)
            {
                WriteAllFilesInTree(child, pack, s, fileOffset);
            }
        }
Beispiel #3
0
        public void Write(EdataPackage package, Stream toStream, int version = 2)
        {
            if (version != Version1 && version != Version2)
            {
                throw new NotSupportedException("Requested Edata version not supported");
            }

            var initStreamPos = toStream.Position;

            toStream.Write(EdataPackage.EdataMagic, 0, EdataPackage.EdataMagic.Length);
            toStream.Write(BitConverter.GetBytes(version), 0, 4);

            // v1 checksum, keep space free if > v1
            toStream.Seek(16, SeekOrigin.Current);
            // Skip
            toStream.Seek(1, SeekOrigin.Current);

            // DictionaryOffset ASM seems to say it must be 1037: CMP DWORD PTR DS:[ESI+0x19],0x40D   (Compare value at offset 25 is 1037)
            toStream.Write(BitConverter.GetBytes(DictionaryOffset), 0, 4);

            // DictionaryLength, FileOffset, FileLength
            toStream.Seek(12, SeekOrigin.Current);

            // unkown, padding, will be kept as 0.
            toStream.Seek(8, SeekOrigin.Current);

            toStream.Seek(16, SeekOrigin.Current);

            NormalizeDirs(package.Root);
            package.Root = NormalizeFiles(package.Root);

            toStream.Seek(initStreamPos + DictionaryOffset, SeekOrigin.Begin);
            WriteFilesToStream(package, toStream);

            toStream.Seek(initStreamPos + DictionaryOffset, SeekOrigin.Begin);
            WriteDirToStream(package.Root, toStream);
        }