示例#1
0
文件: Program.cs 项目: reon/Tools
        static void ExtractMapData()
        {
            Console.WriteLine("Extracting map files...");

            Directory.CreateDirectory("./Project-WoW/Maps");

            var mapDBC    = cascHandler.ReadFile(@"DBFilesClient\Map.dbc");
            var mapDBData = DBReader.Read(mapDBC, typeof(MapDB));

            Parallel.For(0, mapDBData.Rows.Count, i =>
            {
                var mapId   = Convert.ToUInt16(mapDBData.Rows[i][0]);
                var mapName = mapDBData.Rows[i][1].ToString();
                var mapType = Convert.ToByte(mapDBData.Rows[i][5]);

                // Skip transport & garrison maps.
                if (mapType == 3 || mapType == 4)
                {
                    return;
                }

                var map = new Map {
                    Id = mapId, Name = mapName
                };
                var mapReader = new MapReader();

                // Version 1
                // P A M 1 (50 41 4D 01 ) = MAP1
                mapReader.Write(new byte[] { 0x50, 0x41, 0x4D, 0x01 });
                mapReader.Write(map.Id, 11);
                mapReader.Write(Encoding.UTF8.GetBytes(mapName).Length, 7);
                mapReader.Write(Encoding.UTF8.GetBytes(mapName));

                mapReader.Flush();

                for (var j = 0; j < 64; j++)
                {
                    for (var k = 0; k < 64; k++)
                    {
                        var mapData = cascHandler.ReadFile($@"World\Maps\{mapName}\{mapName}_{j}_{k}.adt");

                        if (mapData != null)
                        {
                            mapReader.Initialize(mapData.ToArray());
                            mapReader.Read(map, k, j);
                        }
                    }
                }

                File.WriteAllBytes($"./Project-WoW/Maps/{map.Id:0000}.map", mapReader.Finish(map).ToArray());

                Console.WriteLine($"Extraction of map '{mapName}' done.");
            });
        }
示例#2
0
        private async Task LoadCASCDBFiles()
        {
            lstFiles.DataSource = null;
            FileNames.Clear();

            try
            {
                await Task.Factory.StartNew(() =>
                {
                    using (var casc = new CASCHandler(filePath))
                    {
                        Parallel.ForEach(ClientDBFileNames, file =>
                        {
                            var stream = casc.ReadFile(file, locale);
                            if (stream != null)
                            {
                                FileNames.TryAdd(file, Path.GetFileName(file));
                                Streams.TryAdd(file, stream);
                            }
                        });
                    }
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#3
0
        public bool loadFile(CASCHandler cascHandler, string fileName)
        {
            var file = cascHandler.ReadFile(fileName);

            if (file == null)
            {
                return(false);
            }

            var fileSize = file.Length;

            if (fileSize == 0xFFFFFFFF)
            {
                return(false);
            }

            data_size = (uint)fileSize;
            _data     = new BinaryReader(file).ReadBytes((int)data_size);

            parseChunks();
            if (prepareLoadedData())
            {
                return(true);
            }

            Console.WriteLine($"Error loading {fileName}\n");

            return(false);
        }
示例#4
0
        /// <summary>
        /// Loads a file into the console
        /// <para>load -f "*.dbc" -s ".mpq/wow dir" -b 11802</para>
        /// </summary>
        /// <param name="args"></param>
        ///
        public static void LoadCommand(string[] args)
        {
            var        pmap      = ConsoleManager.ParseCommand(args);
            string     file      = ParamCheck <string>(pmap, "-f");
            string     filename  = Path.GetFileName(file);
            string     filenoext = Path.GetFileNameWithoutExtension(file);
            string     source    = ParamCheck <string>(pmap, "-s", false);
            int        build     = ParamCheck <int>(pmap, "-b");
            SourceType sType     = GetSourceType(source);

            //Check file exists if loaded from the filesystem
            if (!File.Exists(file) && sType == SourceType.File)
            {
                throw new Exception($"   File not found {file}.");
            }

            //Check the required definition exists
            var def = Database.Definitions.Tables.FirstOrDefault(x => x.Build == build && x.Name.Equals(filenoext, IGNORECASE));

            if (def == null)
            {
                throw new Exception($"   Could not find definition for {Path.GetFileName(file)} build {build}.");
            }

            Database.BuildNumber = build;
            var    dic   = new ConcurrentDictionary <string, MemoryStream>();
            string error = string.Empty;

            switch (sType)
            {
            case SourceType.MPQ:
                Console.WriteLine("Loading from MPQ archive...");
                using (MpqArchive archive = new MpqArchive(source, FileAccess.Read))
                {
                    string line = string.Empty;
                    bool   loop = true;
                    using (MpqFileStream listfile = archive.OpenFile("(listfile)"))
                        using (StreamReader sr = new StreamReader(listfile))
                        {
                            while ((line = sr.ReadLine()) != null && loop)
                            {
                                if (line.EndsWith(filename, IGNORECASE))
                                {
                                    loop = false;
                                    var ms = new MemoryStream();
                                    archive.OpenFile(line).CopyTo(ms);
                                    dic.TryAdd(filename, ms);

                                    error = Database.LoadFiles(dic).Result.FirstOrDefault();
                                }
                            }
                        }
                }
                break;

            case SourceType.CASC:
                Console.WriteLine("Loading from CASC directory...");
                using (var casc = new CASCHandler(source))
                {
                    string fullname = filename;
                    if (!fullname.StartsWith("DBFilesClient", IGNORECASE))
                    {
                        fullname = "DBFilesClient\\" + filename;     //Ensure we have the current file name structure
                    }
                    var stream = casc.ReadFile(fullname);
                    if (stream != null)
                    {
                        dic.TryAdd(filename, stream);

                        error = Database.LoadFiles(dic).Result.FirstOrDefault();
                    }
                }
                break;

            default:
                error = Database.LoadFiles(new string[] { file }).Result.FirstOrDefault();
                break;
            }

            dic.Clear();

            if (!string.IsNullOrWhiteSpace(error))
            {
                throw new Exception("   " + error);
            }

            if (Database.Entries.Count == 0)
            {
                throw new Exception("   File could not be loaded.");
            }

            Console.WriteLine($"{Path.GetFileName(file)} loaded.");
            Console.WriteLine("");
        }
示例#5
0
        public static void ExtractCommand(string[] args)
        {
            var        pmap   = ConsoleManager.ParseCommand(args);
            string     filter = ParamCheck <string>(pmap, "-f", false);
            string     source = ParamCheck <string>(pmap, "-s");
            string     output = ParamCheck <string>(pmap, "-o");
            SourceType sType  = GetSourceType(source);

            if (string.IsNullOrWhiteSpace(filter))
            {
                filter = "*";
            }

            string regexfilter            = "(" + Regex.Escape(filter).Replace(@"\*", @".*").Replace(@"\?", ".") + ")";
            Func <string, bool> TypeCheck = t => Path.GetExtension(t).ToLower() == ".dbc" || Path.GetExtension(t).ToLower() == ".db2";


            var dic = new ConcurrentDictionary <string, MemoryStream>();

            switch (sType)
            {
            case SourceType.MPQ:
                Console.WriteLine("Loading from MPQ archive...");
                using (MpqArchive archive = new MpqArchive(source, FileAccess.Read))
                {
                    string line = string.Empty;
                    using (MpqFileStream listfile = archive.OpenFile("(listfile)"))
                        using (StreamReader sr = new StreamReader(listfile))
                        {
                            while ((line = sr.ReadLine()) != null)
                            {
                                if (TypeCheck(line) && Regex.IsMatch(line, regexfilter, RegexOptions.Compiled | RegexOptions.IgnoreCase))
                                {
                                    var ms = new MemoryStream();
                                    archive.OpenFile(line).CopyTo(ms);
                                    dic.TryAdd(Path.GetFileName(line), ms);
                                }
                            }
                        }
                }
                break;

            case SourceType.CASC:
                Console.WriteLine("Loading from CASC directory...");
                using (var casc = new CASCHandler(source))
                {
                    var files = Constants.ClientDBFileNames.Where(x => Regex.IsMatch(Path.GetFileName(x), regexfilter, RegexOptions.Compiled | RegexOptions.IgnoreCase));
                    foreach (var file in files)
                    {
                        var stream = casc.ReadFile(file);
                        if (stream != null)
                        {
                            dic.TryAdd(Path.GetFileName(file), stream);
                        }
                    }
                }
                break;
            }

            if (dic.Count == 0)
            {
                throw new Exception("   No matching files found.");
            }

            if (!Directory.Exists(output))
            {
                Directory.CreateDirectory(output);
            }

            foreach (var d in dic)
            {
                using (var fs = new FileStream(Path.Combine(output, d.Key), FileMode.Create))
                {
                    fs.Write(d.Value.ToArray(), 0, (int)d.Value.Length);
                    fs.Close();
                }
            }

            dic.Clear();

            Console.WriteLine($"   Successfully extracted files.");
            Console.WriteLine("");
        }
示例#6
0
        static void ExtractMapData()
        {
            Console.WriteLine("Extracting map files...");

            Directory.CreateDirectory("./Project-WoW/Maps");

            var mapDBC          = cascHandler.ReadFile(@"DBFilesClient\Map.db2");
            var mapDBData       = DBReader.Read(mapDBC, typeof(MapDB));
            var apakStream      = new APAKStream();
            var writtenMapCount = 0;
            var apakLock        = new object();
            var mapOffsets      = new Dictionary <ushort, uint>();

            Parallel.For(0, mapDBData.Rows.Count, i =>
            {
                var mapId   = Convert.ToUInt16(mapDBData.Rows[i][0]);
                var mapName = mapDBData.Rows[i][1].ToString();
                var mapType = Convert.ToByte(mapDBData.Rows[i][5]);

                // Skip transport & garrison maps.
                if (mapType == 3 || mapType == 4)
                {
                    return;
                }

                var mapReader = new MapReader();
                var map       = new Map
                {
                    Id   = mapId,
                    Name = mapName
                };

                for (var j = 0; j < 64; j++)
                {
                    for (var k = 0; k < 64; k++)
                    {
                        var mapData = cascHandler.ReadFile($@"World\Maps\{mapName}\{mapName}_{j}_{k}.adt");

                        if (mapData != null)
                        {
                            mapReader.Initialize(mapData.ToArray());
                            mapReader.Read(map, k, j);
                        }
                    }
                }

                if (map.Tiles != null)
                {
                    lock (apakLock)
                    {
                        mapOffsets.Add(map.Id, (uint)(apakStream.BaseStream.Position + apakStream.MapStream.BaseStream.Length));

                        apakStream.GenerateMapData(map);

                        Console.WriteLine($"Extraction of map '{mapName}' done.");

                        ++writtenMapCount;
                    }
                }
            });

            foreach (var kp in mapOffsets)
            {
                apakStream.WriteMapDataOffsets(kp.Key, (uint)(kp.Value + writtenMapCount * 6));
            }

            apakStream.Finish();

            apakStream.BaseStream.Position = 5;
            apakStream.Write((ushort)writtenMapCount);

            File.WriteAllBytes(Directory.GetParent(appFolder) + "/Project-WoW/adt.apak", (apakStream.BaseStream as MemoryStream).ToArray());
        }
示例#7
0
        public static bool LoadFiles(CASCHandler handler)
        {
            //CinematicCamera
            using (MemoryStream stream = handler.ReadFile("DBFilesClient\\CinematicCamera.db2"))
            {
                if (stream == null)
                {
                    Console.WriteLine("Unable to open file DBFilesClient\\CinematicCamera.db2s in the archive");
                    return(false);
                }

                Dictionary <uint, CinematicCameraRecord> storage = DBReader.Read <CinematicCameraRecord>(stream);
                if (storage == null)
                {
                    Console.WriteLine("Invalid CinematicCamera.db2 file format. Camera extract aborted.\n");
                    return(false);
                }

                // get camera file list from DB2
                foreach (var record in storage.Values)
                {
                    CameraFileNames.Add(record.ModelFileDataID);
                }

                storage = null;
            }

            using (MemoryStream stream = Program.cascHandler.ReadFile("DBFilesClient\\GameObjectDisplayInfo.db2"))
            {
                if (stream == null)
                {
                    Console.WriteLine("Unable to open file DBFilesClient\\GameObjectDisplayInfo.db2 in the archive\n");
                    return(false);
                }
                GameObjectDisplayInfoStorage = DBReader.Read <GameObjectDisplayInfoRecord>(stream);
                if (GameObjectDisplayInfoStorage == null)
                {
                    Console.WriteLine("Fatal error: Invalid GameObjectDisplayInfo.db2 file format!\n");
                    return(false);
                }
            }

            //Map
            using (MemoryStream stream = handler.ReadFile("DBFilesClient\\Map.db2"))
            {
                if (stream == null)
                {
                    Console.WriteLine("Unable to open file DBFilesClient\\Map.db2 in the archive\n");
                    return(false);
                }
                MapStorage = DBReader.Read <MapRecord>(stream);
                if (MapStorage == null)
                {
                    Console.WriteLine("Fatal error: Invalid Map.db2 file format!\n");
                    return(false);
                }
            }

            //LiquidMaterial
            using (MemoryStream stream = handler.ReadFile("DBFilesClient\\LiquidMaterial.db2"))
            {
                if (stream == null)
                {
                    Console.WriteLine("Unable to open file DBFilesClient\\LiquidMaterial.db2 in the archive\n");
                    return(false);
                }

                var storage = DBReader.Read <LiquidMaterialRecord>(stream);
                if (storage == null)
                {
                    Console.WriteLine("Fatal error: Invalid LiquidMaterial.db2 file format!\n");
                    return(false);
                }

                foreach (var record in storage.Values)
                {
                    LiquidMaterials[record.Id] = record.LVF;
                }

                storage = null;
            }

            //LiquidObject
            using (MemoryStream stream = handler.ReadFile("DBFilesClient\\LiquidObject.db2"))
            {
                if (stream == null)
                {
                    Console.WriteLine("Unable to open file DBFilesClient\\LiquidObject.db2 in the archive\n");
                    return(false);
                }

                var storage = DBReader.Read <LiquidObjectRecord>(stream);
                if (storage == null)
                {
                    Console.WriteLine("Fatal error: Invalid LiquidObject.db2 file format!\n");
                    return(false);
                }

                foreach (var record in storage.Values)
                {
                    LiquidObjects[record.Id] = record.LiquidTypeID;
                }

                storage = null;
            }

            //LiquidType
            using (MemoryStream stream = handler.ReadFile("DBFilesClient\\LiquidType.db2"))
            {
                if (stream == null)
                {
                    Console.WriteLine("Unable to open file DBFilesClient\\LiquidType.db2 in the archive\n");
                    return(false);
                }

                var storage = DBReader.Read <LiquidTypeRecord>(stream);
                if (storage == null)
                {
                    Console.WriteLine("Fatal error: Invalid LiquidType.db2 file format!\n");
                    return(false);
                }

                foreach (var record in storage.Values)
                {
                    LiquidTypeEntry liquidType = new LiquidTypeEntry();
                    liquidType.SoundBank   = record.SoundBank;
                    liquidType.MaterialID  = record.MaterialID;
                    LiquidTypes[record.Id] = liquidType;
                }

                storage = null;
            }

            return(true);
        }