Exemple #1
0
        static void Main(string[] args)
        {
            // Read the original listfile.
            ReadOriginalListfile();

            // Load new casc
            Console.WriteLine("Loading casc...");
            CASC.LoadCASC();

            Console.WriteLine($"Going from FileDataId 3081147 to 3723033");
            for (var fileDataId = 3081147u; fileDataId <= 3723033u; ++fileDataId)
            {
                currentFileDataId = fileDataId;

                try
                {
                    var stream = CASC.OpenFile(fileDataId);
                    if (stream == null)
                    {
                        continue;
                    }

                    if (stream.IsModel())
                    {
                        var m2Model = new M2Reader();
                        m2Model.Process(stream);

                        var path = Names.GetPathFromName(m2Model.GetName());
                        AddToListfile(fileDataId, $"{path}/{m2Model.GetName()}.m2");
                        m2Model.NameAllFiles();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine($"Writing listfile, {AddedFileDataIds.Count} new entries");
            GenerateListfile();
        }
        /// <summary>
        /// Process the newly added files and automatically name them.
        /// </summary>
        public static void ProcessFiles(string product, List <RootEntry> entries, string buildConfig, string cdnConfig, uint buildId)
        {
            // Read the original listfile first.
            ReadOriginalListfile();

            Console.WriteLine("Opening CASC Storage..");
            CASC.OpenCasc(product, buildConfig, cdnConfig);

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            Console.WriteLine($"Processing {entries.Count} root entries");
            foreach (var entry in entries)
            {
                using (var reader = CASC.OpenFile(entry.FileDataId))
                {
                    if (reader == null)
                    {
                        return;
                    }

                    var chunkId = (Chunk)reader.ReadUInt32().FlipUInt();
                    if (chunkId == Chunk.MD21)
                    {
                        reader.BaseStream.Position = 0;
                        var m2Reader = new M2Reader(reader);
                        var pathName = Names.GetPathFromName(m2Reader.GetName());

                        AddToListfile(entry.FileDataId, $"{pathName}/{m2Reader.GetName()}.m2");

                        // Name all the files.
                        m2Reader.NameAllFiles();
                    }

                    // Close the streams to save memory.
                    reader.Close();
                }
            }

            stopWatch.Stop();
            Console.WriteLine($"Finished processing {entries.Count} root entries in {stopWatch.Elapsed}\n");

            // Diff the 2 Map.db2 files.
            if (product == "wow_beta")
            {
                var oldMapStorage = new DBReader(CASC.OldStorage.OpenFile(1349477)).GetRecords <Map>();
                var newMapStorage = new DBReader(CASC.NewStorage.OpenFile(1349477)).GetRecords <Map>();

                if (oldMapStorage.Count < newMapStorage.Count)
                {
                    DiscordServer.Log("Diffing Map.db2 for new map entries...");

                    foreach (var entry in newMapStorage)
                    {
                        if (!oldMapStorage.ContainsKey(entry.Key))
                        {
                            if (entry.Value.WdtFileDataId != 0)
                            {
                                var wdt = new WDTReader();
                                wdt.ReadWDT(CASC.NewStorage, entry.Value.WdtFileDataId);

                                AddToListfile(entry.Value.WdtFileDataId, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}.wdt");
                                foreach (var maid in wdt.MAIDs)
                                {
                                    AddToListfile(maid.Value.RootADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}.adt");
                                    AddToListfile(maid.Value.Obj0ADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_obj0.adt");
                                    AddToListfile(maid.Value.Obj1ADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_obj1.adt");
                                    AddToListfile(maid.Value.Tex0ADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_tex0.adt");
                                    AddToListfile(maid.Value.LodADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_lod.adt");
                                    AddToListfile(maid.Value.MapTexture, $"world/maptextures/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}.blp");
                                    AddToListfile(maid.Value.MapTextureN, $"world/maptextures/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_n.blp");
                                    AddToListfile(maid.Value.MinimapTexture, $"world/minimaps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}.blp");
                                }
                            }
                        }
                    }
                }
            }

            // Generate the listfile now.
            GenerateListfile(buildId);
        }