Пример #1
0
        /// <summary>
        /// Load the ADT by MapId and given coords.
        /// </summary>
        /// <param name="mapId"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public static void Load(uint mapId, uint x, uint y)
        {
            var stream = CASC.OpenFile(DB2Constants.MapFileDataId);

            if (stream == null)
            {
                throw new Exception("Map.db2 is null!");
            }

            var mapStorage = new DBReader(stream).GetRecords <Map>();

            if (!mapStorage.TryGetValue((int)mapId, out var map))
            {
                throw new Exception($"{mapId} cannot be found in Map.db2");
            }

            // Read the WDT file
            WDTReader.ReadWDT(map.WdtFileDataId);

            var maid     = WDTData.MAIDs[(map.WdtFileDataId, x, y)];
Пример #2
0
        /// <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);
        }