Esempio n. 1
0
        public bool GetEncodingEntry(ulong hash, out EncodingEntry entry)
        {
            var info = RootHandler.GetEntries(hash);

            if (info.Any())
            {
                return(EncodingHandler.GetEntry(info.First().MD5, out entry));
            }

            if ((CASCConfig.LoadFlags & LoadFlags.Install) != 0)
            {
                var installInfo = Install.GetEntries().Where(e => Hasher.ComputeHash(e.Name) == hash);
                if (installInfo.Any())
                {
                    return(EncodingHandler.GetEntry(installInfo.First().MD5, out entry));
                }
            }

            entry = default(EncodingEntry);
            return(false);
        }
Esempio n. 2
0
        public EncodingHandler(BinaryReader stream)
        {
            stream.Skip(2); // EN
            byte b1 = stream.ReadByte();
            byte checksumSizeA = stream.ReadByte();
            byte checksumSizeB = stream.ReadByte();
            ushort flagsA = stream.ReadUInt16();
            ushort flagsB = stream.ReadUInt16();
            int numEntriesA = stream.ReadInt32BE();
            int numEntriesB = stream.ReadInt32BE();
            byte b4 = stream.ReadByte();
            int stringBlockSize = stream.ReadInt32BE();

            stream.Skip(stringBlockSize);
            stream.Skip(numEntriesA * 32);

            long chunkStart = stream.BaseStream.Position;

            for (int i = 0; i < numEntriesA; ++i)
            {
                ushort keysCount;

                while ((keysCount = stream.ReadUInt16()) != 0)
                {
                    int fileSize = stream.ReadInt32BE();
                    MD5Hash hash = stream.Read<MD5Hash>();

                    EncodingEntry entry = new EncodingEntry();
                    entry.Size = fileSize;

                    // how do we handle multiple keys?
                    for (int ki = 0; ki < keysCount; ++ki)
                    {
                        MD5Hash key = stream.Read<MD5Hash>();

                        // use first key for now
                        if (ki == 0)
                            entry.Key = key;
                        else
                            Log.Write("Multiple encoding keys for MD5 hash {0} -> {1}", hash.ToHexString(), key.ToHexString());
                    }

                    EncodingData.Add(hash, entry);
                }

                // each chunk is 4096 bytes, and zero padding at the end
                long remaining = CHUNK_SIZE - ((stream.BaseStream.Position - chunkStart) % CHUNK_SIZE);

                if (remaining > 0)
                    stream.BaseStream.Position += remaining;
            }

            for (int i = 0; i < numEntriesB; ++i)
            {
                byte[] firstKey = stream.ReadBytes(16);
                byte[] blockHash = stream.ReadBytes(16);
            }

            long chunkStart2 = stream.BaseStream.Position;

            for (int i = 0; i < numEntriesB; ++i)
            {
                byte[] key = stream.ReadBytes(16);
                int stringIndex = stream.ReadInt32BE();
                byte unk1 = stream.ReadByte();
                int fileSize = stream.ReadInt32BE();

                // each chunk is 4096 bytes, and zero padding at the end
                long remaining = CHUNK_SIZE - ((stream.BaseStream.Position - chunkStart2) % CHUNK_SIZE);

                if (remaining > 0)
                    stream.BaseStream.Position += remaining;
            }
        }
Esempio n. 3
0
 public bool GetEntry(MD5Hash hash, out EncodingEntry entry)
 {
     return EncodingData.TryGetValue(hash, out entry);
 }
Esempio n. 4
0
        public bool GetEncodingEntry(ulong hash, out EncodingEntry entry)
        {
            var info = RootHandler.GetEntries(hash);
            if (info.Any())
                return EncodingHandler.GetEntry(info.First().MD5, out entry);

            if ((CASCConfig.LoadFlags & LoadFlags.Install) != 0)
            {
                var installInfo = Install.GetEntries().Where(e => Hasher.ComputeHash(e.Name) == hash);
                if (installInfo.Any())
                    return EncodingHandler.GetEntry(installInfo.First().MD5, out entry);
            }

            entry = default(EncodingEntry);
            return false;
        }
Esempio n. 5
0
        public EncodingHandler(BinaryReader stream)
        {
            stream.Skip(2); // EN
            byte   b1              = stream.ReadByte();
            byte   checksumSizeA   = stream.ReadByte();
            byte   checksumSizeB   = stream.ReadByte();
            ushort flagsA          = stream.ReadUInt16();
            ushort flagsB          = stream.ReadUInt16();
            int    numEntriesA     = stream.ReadInt32BE();
            int    numEntriesB     = stream.ReadInt32BE();
            byte   b4              = stream.ReadByte();
            int    stringBlockSize = stream.ReadInt32BE();

            stream.Skip(stringBlockSize);
            stream.Skip(numEntriesA * 32);

            long chunkStart = stream.BaseStream.Position;

            for (int i = 0; i < numEntriesA; ++i)
            {
                ushort keysCount;

                while ((keysCount = stream.ReadUInt16()) != 0)
                {
                    int     fileSize = stream.ReadInt32BE();
                    MD5Hash hash     = stream.Read <MD5Hash>();

                    EncodingEntry entry = new EncodingEntry();
                    entry.Size = fileSize;

                    // how do we handle multiple keys?
                    for (int ki = 0; ki < keysCount; ++ki)
                    {
                        MD5Hash key = stream.Read <MD5Hash>();

                        // use first key for now
                        if (ki == 0)
                        {
                            entry.Key = key;
                        }
                        else
                        {
                            Log.Write("Multiple encoding keys for MD5 hash {0} -> {1}", hash.ToHexString(), key.ToHexString());
                        }
                    }

                    EncodingData.Add(hash, entry);
                }

                // each chunk is 4096 bytes, and zero padding at the end
                long remaining = CHUNK_SIZE - ((stream.BaseStream.Position - chunkStart) % CHUNK_SIZE);

                if (remaining > 0)
                {
                    stream.BaseStream.Position += remaining;
                }
            }

            for (int i = 0; i < numEntriesB; ++i)
            {
                byte[] firstKey  = stream.ReadBytes(16);
                byte[] blockHash = stream.ReadBytes(16);
            }

            long chunkStart2 = stream.BaseStream.Position;

            for (int i = 0; i < numEntriesB; ++i)
            {
                byte[] key         = stream.ReadBytes(16);
                int    stringIndex = stream.ReadInt32BE();
                byte   unk1        = stream.ReadByte();
                int    fileSize    = stream.ReadInt32BE();

                // each chunk is 4096 bytes, and zero padding at the end
                long remaining = CHUNK_SIZE - ((stream.BaseStream.Position - chunkStart2) % CHUNK_SIZE);

                if (remaining > 0)
                {
                    stream.BaseStream.Position += remaining;
                }
            }
        }
Esempio n. 6
0
 public bool GetEntry(MD5Hash hash, out EncodingEntry entry)
 {
     return(EncodingData.TryGetValue(hash, out entry));
 }