コード例 #1
0
ファイル: CASCHandler.cs プロジェクト: westerjn/CASCExplorer
        public bool GetEncodingEntry(ulong hash, out EncodingEntry enc)
        {
            var rootInfos = RootHandler.GetEntries(hash);

            if (rootInfos.Any())
            {
                return(EncodingHandler.GetEntry(rootInfos.First().MD5, out enc));
            }

            if ((CASCConfig.LoadFlags & LoadFlags.Install) != 0)
            {
                var installInfos = Install.GetEntries().Where(e => Hasher.ComputeHash(e.Name) == hash && e.Tags.Any(t => t.Type == 1 && t.Name == RootHandler.Locale.ToString()));
                if (installInfos.Any())
                {
                    return(EncodingHandler.GetEntry(installInfos.First().MD5, out enc));
                }

                installInfos = Install.GetEntries().Where(e => Hasher.ComputeHash(e.Name) == hash);
                if (installInfos.Any())
                {
                    return(EncodingHandler.GetEntry(installInfos.First().MD5, out enc));
                }
            }

            enc = default(EncodingEntry);
            return(false);
        }
コード例 #2
0
        public long GetFileSize(ulong hash)
        {
            if (Root is TVFSRootHandler vfs)
            {
                var vfsEntries = vfs.GetVfsRootEntries(hash);
                if (vfsEntries != null)
                {
                    if (vfsEntries.Count == 1)
                    {
                        return(vfsEntries[0].ContentLength);
                    }
                    else
                    {
                        return(vfsEntries.Sum(e => (long)e.ContentLength));
                    }
                }
            }

            if (GetCKeyForHash(hash, out MD5Hash cKey))
            {
                if (EncodingHandler.GetEntry(cKey, out EncodingEntry enc))
                {
                    return(enc.Size);
                }
            }

            return(0);
        }
コード例 #3
0
ファイル: CASCHandlerLite.cs プロジェクト: WoW-Tools/CascLib
        private CASCHandlerLite(CASCConfig config, LocaleFlags locale, BackgroundWorkerEx worker) : base(config, worker)
        {
            if (config.GameType != CASCGameType.WoW)
            {
                throw new Exception("Unsupported game " + config.BuildUID);
            }

            Logger.WriteLine("CASCHandlerLite: loading encoding data...");

            EncodingHandler EncodingHandler;

            using (var _ = new PerfCounter("new EncodingHandler()"))
            {
                using (var fs = OpenEncodingFile(this))
                    EncodingHandler = new EncodingHandler(fs, worker);
            }

            Logger.WriteLine("CASCHandlerLite: loaded {0} encoding data", EncodingHandler.Count);

            Logger.WriteLine("CASCHandlerLite: loading root data...");

            WowRootHandler RootHandler;

            using (var _ = new PerfCounter("new RootHandler()"))
            {
                using (var fs = OpenRootFile(EncodingHandler, this))
                    RootHandler = new WowRootHandler(fs, worker);
            }

            Logger.WriteLine("CASCHandlerLite: loaded {0} root data", RootHandler.Count);

            RootHandler.SetFlags(locale, false, false);

            RootEntry rootEntry;

            foreach (var entry in RootHandler.GetAllEntries())
            {
                rootEntry = entry.Value;

                if ((rootEntry.LocaleFlags == locale || (rootEntry.LocaleFlags & locale) != LocaleFlags.None) && (rootEntry.ContentFlags & ContentFlags.Alternate) == ContentFlags.None)
                {
                    if (EncodingHandler.GetEntry(rootEntry.cKey, out EncodingEntry enc))
                    {
                        if (!HashToEKey.ContainsKey(entry.Key))
                        {
                            HashToEKey.Add(entry.Key, enc.Keys[0]);
                            FileDataIdToHash.Add(RootHandler.GetFileDataIdByHash(entry.Key), entry.Key);
                        }
                    }
                }
            }

            RootHandler.Clear();
            RootHandler = null;
            EncodingHandler.Clear();
            EncodingHandler = null;
            GC.Collect();

            Logger.WriteLine("CASCHandlerLite: loaded {0} files", HashToEKey.Count);
        }
コード例 #4
0
        protected BinaryReader OpenRootFile(EncodingHandler enc, CASCHandlerBase casc)
        {
            if (!enc.GetEntry(casc.Config.RootMD5, out EncodingEntry encInfo))
            {
                throw new FileNotFoundException("encoding info for root file missing!");
            }

            //ExtractFile(encInfo.Key, ".", "root");

            return(new BinaryReader(casc.OpenFile(encInfo.Key)));
        }
コード例 #5
0
        public override void Dump(EncodingHandler encodingHandler = null)
        {
            Logger.WriteLine("WowRootHandler Dump:");

            foreach (var fd in RootData.OrderBy(r => r.Key))
            {
                string name;

                if (FileDataStore.TryGetValue(fd.Key, out ulong hash) && CASCFile.Files.TryGetValue(hash, out CASCFile file))
                {
                    name = file.FullName;
                }
                else
                {
                    name = $"FILEDATA_{fd.Key}";
                }

                Logger.WriteLine($"FileData: {fd.Key:D7} Hash: {hash:X16} Locales: {fd.Value.Aggregate(LocaleFlags.None, (a, b) => a | b.LocaleFlags)} Name: {name}");

                foreach (var entry in fd.Value)
                {
                    Logger.WriteLine($"\tcKey: {entry.cKey.ToHexString()} Locale: {entry.LocaleFlags} CF: {entry.ContentFlags}");

                    if (encodingHandler != null)
                    {
                        if (encodingHandler.GetEntry(entry.cKey, out var encodingEntry))
                        {
                            foreach (var eKey in encodingEntry.Keys)
                            {
                                var keys = encodingHandler.GetEncryptionKeys(eKey);
                                if (keys != null)
                                {
                                    Logger.WriteLine($"\teKey: {eKey.ToHexString()} TactKeys: {string.Join(",", keys.Select(k => $"{k:X16}"))} Size: {encodingEntry.Size}");
                                }
                                else
                                {
                                    Logger.WriteLine($"\teKey: {eKey.ToHexString()} TactKeys: NA Size: {encodingEntry.Size}");
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: CASCHandlerLite.cs プロジェクト: ytche/CASCExplorer
        private CASCHandlerLite(CASCConfig config, LocaleFlags locale, BackgroundWorkerEx worker) : base(config, worker)
        {
            if (config.GameType != CASCGameType.WoW)
            {
                throw new Exception("Unsupported game " + config.BuildUID);
            }

            Logger.WriteLine("CASCHandlerLite: loading encoding data...");

            EncodingHandler EncodingHandler;

            using (var _ = new PerfCounter("new EncodingHandler()"))
            {
                using (var fs = OpenEncodingFile(this))
                    EncodingHandler = new EncodingHandler(fs, worker);
            }

            Logger.WriteLine("CASCHandlerLite: loaded {0} encoding data", EncodingHandler.Count);

            Logger.WriteLine("CASCHandlerLite: loading root data...");

            WowRootHandler RootHandler;

            using (var _ = new PerfCounter("new RootHandler()"))
            {
                using (var fs = OpenRootFile(EncodingHandler, this))
                    RootHandler = new WowRootHandler(fs, worker);
            }

            Logger.WriteLine("CASCHandlerLite: loaded {0} root data", RootHandler.Count);

            RootHandler.SetFlags(locale, ContentFlags.None, false);

            CDNIndexData = new Dictionary <MD5Hash, IndexEntry>(comparer);

            if (LocalIndex != null)
            {
                LocalIndexData = new Dictionary <MD5Hash, IndexEntry>(comparer);
            }

            RootEntry rootEntry;

            foreach (var entry in RootHandler.GetAllEntries())
            {
                rootEntry = entry.Value;

                if ((rootEntry.LocaleFlags == locale || (rootEntry.LocaleFlags & locale) != LocaleFlags.None) && (rootEntry.ContentFlags & ContentFlags.LowViolence) == ContentFlags.None)
                {
                    if (EncodingHandler.GetEntry(rootEntry.MD5, out EncodingEntry enc))
                    {
                        if (!HashToKey.ContainsKey(entry.Key))
                        {
                            HashToKey.Add(entry.Key, enc.Key);
                            FileDataIdToHash.Add(RootHandler.GetFileDataIdByHash(entry.Key), entry.Key);

                            if (LocalIndex != null)
                            {
                                IndexEntry iLocal = LocalIndex.GetIndexInfo(enc.Key);

                                if (iLocal != null && !LocalIndexData.ContainsKey(enc.Key))
                                {
                                    LocalIndexData.Add(enc.Key, iLocal);
                                }
                            }

                            IndexEntry iCDN = CDNIndex.GetIndexInfo(enc.Key);

                            if (iCDN != null && !CDNIndexData.ContainsKey(enc.Key))
                            {
                                CDNIndexData.Add(enc.Key, iCDN);
                            }
                        }
                    }
                }
            }

            CDNIndex.Clear();
            //CDNIndex = null;
            LocalIndex?.Clear();
            LocalIndex = null;
            RootHandler.Clear();
            RootHandler = null;
            EncodingHandler.Clear();
            EncodingHandler = null;
            GC.Collect();

            Logger.WriteLine("CASCHandlerLite: loaded {0} files", HashToKey.Count);
        }