예제 #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();

            entry.MD5 = e.MD5;

            LocaleFlags locale;

            entry.Block = new RootBlock();

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

            ulong fileHash = Hasher.ComputeHash(name);

            CASCFile.FileNames[fileHash] = name;

            RootData.Add(fileHash, entry);
        }
예제 #2
0
        public static D3RootEntry Read(int type, BinaryReader s)
        {
            D3RootEntry e = new D3RootEntry();

            e.Type = type;
            e.MD5 = s.ReadBytes(16);

            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;
        }
예제 #3
0
        public static D3RootEntry Read(int type, BinaryReader s)
        {
            D3RootEntry e = new D3RootEntry();

            e.Type = type;
            e.MD5  = s.ReadBytes(16);

            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);
        }
예제 #4
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();
            entry.MD5 = e.MD5;

            LocaleFlags locale;

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

            ulong fileHash = Hasher.ComputeHash(name);
            CASCFile.FileNames[fileHash] = name;

            RootData.Add(fileHash, entry);
        }
예제 #5
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++)
            {
                byte[] md5  = stream.ReadBytes(16);
                string name = stream.ReadCString();

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

                EncodingEntry enc = casc.Encoding.GetEntry(md5);

                using (BinaryReader s = new BinaryReader(casc.OpenFile(enc.Key)))
                {
                    if (s != null)
                    {
                        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");

            EncodingEntry enc1 = casc.Encoding.GetEntry(coreTocEntry.MD5);

            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");

            EncodingEntry enc2 = casc.Encoding.GetEntry(pkgEntry.MD5);

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

            worker?.ReportProgress(100);
        }