Exemple #1
0
        public void LoadEntries(DataFile file, IndexEntry indexEntry)
        {
            var list = new List<RootEntry>();
            var blteEntry = new BinaryReader(DataFile.LoadBLTEEntry(indexEntry, file.readStream));

            while (blteEntry.BaseStream.Position < blteEntry.BaseStream.Length)
            {
                var entries = new RootEntry[blteEntry.ReadInt32()];

                blteEntry.BaseStream.Position += 4;

                var locales = (Locales)blteEntry.ReadUInt32();

                blteEntry.BaseStream.Position += (entries.Length << 2);

                for (var i = 0; i < entries.Length; i++)
                {
                    list.Add(new RootEntry
                    {
                        MD5 = blteEntry.ReadBytes(16),
                        Hash = blteEntry.ReadUInt64(),
                        Locales = locales
                    });
                }
            }

            entries = list.ToLookup(re => re.Hash);
        }
        public void LoadEntries(DataFile file, IndexEntry indexEntry)
        {
            var blteEntry = new BinaryReader(DataFile.LoadBLTEEntry(indexEntry, file.readStream));

            blteEntry.BaseStream.Position = 9;

            var entries = blteEntry.ReadBEUInt32();

            blteEntry.BaseStream.Position += 5;

            var offsetEntries = blteEntry.ReadBEUInt32();

            blteEntry.BaseStream.Position += offsetEntries + (entries << 5);

            for (var i = 0; i < entries; i++)
            {
                var keys = blteEntry.ReadUInt16();

                while (keys != 0)
                {
                    var encodingEntry = new EncodingEntry
                    {
                        Keys = new byte[keys][],
                        Size = blteEntry.ReadBEUInt32()
                    };

                    var md5 = blteEntry.ReadBytes(16);

                    for (var j = 0; j < keys; j++)
                        encodingEntry.Keys[j] = blteEntry.ReadBytes(16);

                    this.entries.Add(md5, encodingEntry);

                    keys = blteEntry.ReadUInt16();
                }

                while (blteEntry.ReadByte() == 0);

                blteEntry.BaseStream.Position -= 1;
            }

        }
Exemple #3
0
        public IndexFile(string idx, bool cdnIndex = false, ushort fileIndex = 0)
        {
            if (cdnIndex)
            {
                var nullHash = new byte[16];

                using (var br = new BinaryReader(File.OpenRead(idx)))
                {
                    br.BaseStream.Position = br.BaseStream.Length - 12;

                    var entries = br.ReadUInt32();

                    br.BaseStream.Position = 0;

                    for (var i = 0; i < entries; i++)
                    {
                        var hash = br.ReadBytes(16);

                        if (hash.Compare(nullHash))
                            hash = br.ReadBytes(16);

                        var entry = new IndexEntry
                        {
                            Index = fileIndex,
                            Size = br.ReadBEUInt32(),
                            Offset = br.ReadBEUInt32()
                        };

                        if (this.entries.ContainsKey(hash))
                            continue;

                        this.entries.Add(hash, entry);
                    }
                }
            }
            else
            {
                using (var br = new BinaryReader(File.OpenRead(idx)))
                {
                    br.BaseStream.Position = 0x20;

                    var dataLength = br.ReadUInt32();

                    br.BaseStream.Position += 4;

                    // 18 bytes per entry.
                    for (var i = 0; i < dataLength / 18; i++)
                    {
                        var hash = br.ReadBytes(9);
                        var index = br.ReadByte();
                        var offset = br.ReadBEUInt32();

                        var entry = new IndexEntry();

                        entry.Size = br.ReadUInt32();
                        entry.Index = (ushort)((ushort)(index << 2) | (offset >> 30));
                        entry.Offset = (uint)(offset & 0x3FFFFFFF);

                        if (entries.ContainsKey(hash))
                            continue;

                        entries.Add(hash, entry);
                    }
                }
            }
        }
Exemple #4
0
        public static MemoryStream LoadBLTEEntry(IndexEntry idxEntry, BinaryReader readStream = null)
        {
            lock (readLock)
            {
                if (readStream == null)
                    return null;

                readStream.BaseStream.Position = idxEntry.Offset + 30;

                if (readStream.ReadUInt32() != 0x45544C42)
                {
                    Trace.TraceError($"data.{idxEntry.Index:000}: Invalid BLTE signature at 0x{readStream.BaseStream.Position:X8}.");

                    return null;
                }

                var blte = new BLTEEntry();
                var frameHeaderLength = readStream.ReadBEUInt32();
                var chunks = 0u;
                var size = 0L;

                if (frameHeaderLength == 0)
                {
                    chunks = 1;
                    size = idxEntry.Size - 38;
                }
                else
                {
                    readStream.BaseStream.Position += 1;

                    chunks = readStream.ReadUInt24();
                }

                blte.Chunks = new BLTEChunk[chunks];

                for (var i = 0; i < chunks; i++)
                {
                    if (frameHeaderLength == 0)
                    {
                        blte.Chunks[i].CompressedSize = size;
                        blte.Chunks[i].UncompressedSize = size - 1;
                    }
                    else
                    {
                        blte.Chunks[i].CompressedSize = readStream.ReadBEUInt32();
                        blte.Chunks[i].UncompressedSize = readStream.ReadBEUInt32();

                        // Skip MD5 hash
                        readStream.BaseStream.Position += 16;
                    }
                }

                var data = new MemoryStream();

                for (var i = 0; i < chunks; i++)
                {
                    var formatCode = readStream.ReadByte();
                    var dataBytes = readStream.ReadBytes((int)blte.Chunks[i].CompressedSize - 1);

                    // Not compressed
                    if (formatCode == 0x4E)
                        data.Write(dataBytes, 0, (int)blte.Chunks[i].UncompressedSize);
                    // Compressed
                    else if (formatCode == 0x5A)
                    {
                        using (var decompressed = new MemoryStream())
                        {
                            using (var inflate = new DeflateStream(new MemoryStream(dataBytes, 2, dataBytes.Length - 2), CompressionMode.Decompress))
                                inflate.CopyTo(decompressed);

                            var inflateData = decompressed.ToArray();
                            data.Write(inflateData, 0, inflateData.Length);
                        }
                    }
                }

                data.Position = 0;


                return data;
            }
        }
Exemple #5
0
        public BinaryReader DownloadFile(string archive, IndexEntry indexEntry)
        {
            var url = $"http://{DownloadUrl}/data/{archive.GetHexAt(0)}/{archive.GetHexAt(2)}/{archive}.index";

            throw new NotImplementedException("CDNConfig.DownloadFile not implemented.");
        }