Esempio n. 1
0
        private void AddFile(string pkg, D3RootEntry e)
        {
            string name;

            switch (e.Type)
            {
            case 0:
                SNOInfo sno1 = tocParser.GetSNO(e.SNO);
                name = string.Format("{0}\\{1}{2}", sno1.GroupId, sno1.Name, sno1.Ext);
                break;

            case 1:
                SNOInfo sno2 = tocParser.GetSNO(e.SNO);
                name = string.Format("{0}\\{1}\\{2:D4}", sno2.GroupId, sno2.Name, e.FileIndex);

                string ext = pkgParser.GetExtension(name);

                if (ext != null)
                {
                    name += ext;
                }
                else
                {
                    CountUnknown++;
                    name += ".xxx";
                }
                break;

            case 2:
                name = e.Name;
                break;

            default:
                name = "Unknown";
                break;
            }

            RootEntry entry = new RootEntry
            {
                MD5 = e.MD5
            };

            if (Enum.TryParse(pkg, out LocaleFlags locale))
            {
                entry.LocaleFlags = locale;
            }
            else
            {
                entry.LocaleFlags = LocaleFlags.All;
            }

            ulong fileHash = Hasher.ComputeHash(name);

            CASCFile.Files[fileHash] = new CASCFile(fileHash, name);

            RootData.Add(fileHash, entry);
        }
Esempio n. 2
0
        public static D3RootEntry Read(int type, BinaryReader s)
        {
            D3RootEntry e = new D3RootEntry()
            {
                Type = type,
                MD5  = s.Read <MD5Hash>()
            };

            if (type == 0 || type == 1) // has SNO id
            {
                e.SNO = s.ReadInt32();

                if (type == 1) // has file index
                {
                    e.FileIndex = s.ReadInt32();
                }
            }
            else // Named file
            {
                e.Name = s.ReadCString();
            }

            return(e);
        }
Esempio n. 3
0
        public D3RootHandler(BinaryReader stream, BackgroundWorkerEx worker, CASCHandler casc)
        {
            worker?.ReportProgress(0, "Loading \"root\"...");

            byte b1 = stream.ReadByte();
            byte b2 = stream.ReadByte();
            byte b3 = stream.ReadByte();
            byte b4 = stream.ReadByte();

            int count = stream.ReadInt32();

            for (int j = 0; j < count; j++)
            {
                MD5Hash md5  = stream.Read <MD5Hash>();
                string  name = stream.ReadCString();

                var entries = new List <D3RootEntry>();
                D3RootData[name] = entries;

                if (!casc.Encoding.GetEntry(md5, out EncodingEntry enc))
                {
                    continue;
                }

                using (BinaryReader s = new BinaryReader(casc.OpenFile(enc.Key)))
                {
                    uint magic = s.ReadUInt32();

                    int nEntries0 = s.ReadInt32();

                    for (int i = 0; i < nEntries0; i++)
                    {
                        entries.Add(D3RootEntry.Read(0, s));
                    }

                    int nEntries1 = s.ReadInt32();

                    for (int i = 0; i < nEntries1; i++)
                    {
                        entries.Add(D3RootEntry.Read(1, s));
                    }

                    int nNamedEntries = s.ReadInt32();

                    for (int i = 0; i < nNamedEntries; i++)
                    {
                        entries.Add(D3RootEntry.Read(2, s));
                    }
                }

                worker?.ReportProgress((int)((j + 1) / (float)(count + 2) * 100));
            }

            // Parse CoreTOC.dat
            var coreTocEntry = D3RootData["Base"].Find(e => e.Name == "CoreTOC.dat");

            casc.Encoding.GetEntry(coreTocEntry.MD5, out EncodingEntry enc1);

            using (var file = casc.OpenFile(enc1.Key))
                tocParser = new CoreTOCParser(file);

            worker?.ReportProgress((int)((count + 1) / (float)(count + 2) * 100));

            // Parse Packages.dat
            var pkgEntry = D3RootData["Base"].Find(e => e.Name == "Data_D3\\PC\\Misc\\Packages.dat");

            casc.Encoding.GetEntry(pkgEntry.MD5, out EncodingEntry enc2);

            using (var file = casc.OpenFile(enc2.Key))
                pkgParser = new PackagesParser(file);

            worker?.ReportProgress(100);
        }