static DBCD.IDBCDStorage LoadMaps()
        {
            var dbdProvider = new GithubDBDProvider();
            var dbcProvider = new MirrorDBCProvider(BuildConfig);
            var dbcd        = new DBCD.DBCD(dbcProvider, dbdProvider);

            var maps = dbcd.Load("Map");

            return(maps);
        }
Exemple #2
0
        public void TestEncryptedInfo()
        {
            var githubDBDProvider = new GithubDBDProvider();
            var dbcProvider       = new TestDBCProvider(Directory.GetCurrentDirectory());

            DBCD dbcd = new DBCD(dbcProvider, githubDBDProvider);

            var storage = dbcd.Load("SpellName");

            foreach (var section in storage.GetEncryptedSections())
            {
                System.Console.WriteLine($"Found encrypted secttion encrypted with key {section.Key} containing {section.Value} rows");
            }
        }
Exemple #3
0
        private static async Task Run(Options options)
        {
            options.Validate();

            var dbdProvider = new GithubDBDProvider();
            var dbcProvider = new LocalDBCProvider(options.Directory);

            var dbs = Utils.GetFiles(options.Directory, "*.db2|*.dbc")
                      .ToDictionary(Path.GetFileNameWithoutExtension);

            foreach (var db in dbs)
            {
                var dbcStream = await dbcProvider.StreamForTableName(db.Key);

                var dbdStream = await dbdProvider.StreamForTableName(db.Key);

                var dbReader   = new DBReader(dbcStream);
                var builder    = new DefinitionBuilder(db.Key, options.Build);
                var definition = builder.Generate(dbReader, dbdStream, dbs);
                var storage    = dbReader.GetRecords(definition);

                if (storage.Count == 0)
                {
                    Console.WriteLine($"Skipping {db.Key} - empty");
                    continue;
                }

                if (options.ExportType.HasFlag(ExportType.SQL))
                {
                    await DBObjectWriter.WriteToServer(options, builder, storage.Values);
                }
                if (options.ExportType.HasFlag(ExportType.CSV))
                {
                    await CSVObjectWriter.WriteToFile(options, builder, storage.Values);
                }
            }

            // append foreign keys to the database
            if (options.ExportType.HasFlag(ExportType.SQL) && options.ExportForeignKeys)
            {
                Console.WriteLine("Generating foreign keys");
                await DBObjectWriter.WriteForeignKeys(options);
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            if (args.Length < 4)
            {
                throw new ArgumentException("Required arguments: cdndir, buildconfig, cdnconfig, outdir");
            }

            var cdndir = args[0];
            var bc     = args[1];
            var cdnc   = args[2];
            var outdir = args[3];

            var mapFilter = "";

            if (args.Length == 5)
            {
                mapFilter = args[4];
            }

            // Open storage for specific build
            TACTRepo tactRepo = new TACTRepo(cdndir)
            {
                ConfigContainer = new ConfigContainer()
            };

            Console.WriteLine("Loading configs..");
            tactRepo.ConfigContainer.OpenLocal(tactRepo.BaseDirectory, bc, cdnc);

            Console.WriteLine("Loading indices..");
            tactRepo.IndexContainer = new TACT.Net.Indices.IndexContainer();
            tactRepo.IndexContainer.Open(tactRepo.BaseDirectory, tactRepo.ConfigContainer);

            Console.WriteLine("Loading encoding..");
            tactRepo.EncodingFile = new TACT.Net.Encoding.EncodingFile(tactRepo.BaseDirectory, tactRepo.ConfigContainer.EncodingEKey);

            Console.WriteLine("Looking up root..");
            tactRepo.EncodingFile.TryGetCKeyEntry(tactRepo.ConfigContainer.RootCKey, out var rootCEntry);

            Console.WriteLine("Loading root..");
            tactRepo.RootFile = new TACT.Net.Root.RootFile(tactRepo.BaseDirectory, rootCEntry.EKey);

            Console.WriteLine("Loading TACT keys..");
            try
            {
                using (var client = new HttpClient())
                {
                    var result = client.GetAsync("https://wow.tools/api.php?type=tactkeys").Result;
                    var keys   = result.Content.ReadAsStringAsync().Result.Split('\n');
                    foreach (var key in keys)
                    {
                        var split = key.Split(' ');
                        if (split.Length < 2)
                        {
                            continue;
                        }

                        var keyname  = Convert.ToUInt64(split[0], 16);
                        var keybytes = split[1];
                        if (TACT.Net.Cryptography.KeyService.TryAddKey(keyname, keybytes))
                        {
                            Console.WriteLine("Added TACT key " + split[0]);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred retrieving/loading TACT keys: " + e.Message);
            }

            // Set up DBCD
            var dbdProvider = new GithubDBDProvider();
            var dbcProvider = new TACTDBCProvider(tactRepo);
            var dbcd        = new DBCD.DBCD(dbcProvider, dbdProvider);

            // Open Map DBC with local defs
            Console.WriteLine("Opening Map.db2..");

            // This will currently crash on partially encrypted DBs with unknown keys due to https://github.com/wowdev/TACT.Net/issues/12
            var mapdb = dbcd.Load("Map");

            // Run through map db
            Console.WriteLine("Extracting tiles..");

            foreach (dynamic map in mapdb.Values)
            {
                if (!string.IsNullOrEmpty(mapFilter) && map.Directory != mapFilter)
                {
                    continue;
                }

                Console.WriteLine(map.Directory);

                // Load WDT
                Stream wdtStream;

                try
                {
                    if (map.WdtFileDataID == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("Skipping map " + map.Directory + " with no WDT!");
                        Console.ResetColor();
                        continue;
                    }

                    wdtStream = tactRepo.RootFile.OpenFile((uint)map.WdtFileDataID, tactRepo);
                }
                catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Older build detected: map record has no wdtFileDataID property");
                    Console.ResetColor();
                    wdtStream = tactRepo.RootFile.OpenFile("world/maps/" + map.Directory + "/" + map.Directory + ".wdt", tactRepo);
                }

                if (wdtStream == null)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Skipping map " + map.Directory + " with unshipped WDT!");
                    Console.ResetColor();
                    continue;
                }

                var minimapFDIDs = WDT.FileDataIdsFromWDT(wdtStream);
                if (minimapFDIDs.Count() == 0)
                {
                    // Pre-MAID build, extract by filename
                    for (var x = 0; x < 64; x++)
                    {
                        for (var y = 0; y < 64; y++)
                        {
                            string tileName      = "world/minimaps/" + map.Directory + "/map" + x.ToString().PadLeft(2, '0') + "_" + y.ToString().PadLeft(2, '0') + ".blp";
                            var    minimapStream = tactRepo.RootFile.OpenFile(tileName, tactRepo);
                            if (minimapStream == null)
                            {
                                continue;
                            }

                            var minimapName = "map" + x.ToString().PadLeft(2, '0') + "_" + y.ToString().PadLeft(2, '0') + ".blp";
                            var minimapPath = Path.Combine(outdir, "world", "minimaps", map.Directory, minimapName);

                            Directory.CreateDirectory(Path.GetDirectoryName(minimapPath));

                            using (var fileStream = File.Create(minimapPath))
                            {
                                minimapStream.CopyTo(fileStream);
                            }
                        }
                    }
                }
                else
                {
                    // Extract tiles by FDID
                    minimapFDIDs = minimapFDIDs.Where(chunk => chunk.fileDataId != 0).ToArray();
                    foreach (var minimap in minimapFDIDs)
                    {
                        var minimapStream = tactRepo.RootFile.OpenFile(minimap.fileDataId, tactRepo);
                        if (minimapStream == null)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Unable to extract minimap " + minimap.fileDataId + " for tile " + minimap.x + "_" + minimap.y);
                            Console.ResetColor();
                            continue;
                        }

                        var minimapName = "map" + minimap.x.ToString().PadLeft(2, '0') + "_" + minimap.y.ToString().PadLeft(2, '0') + ".blp";
                        var minimapPath = Path.Combine(outdir, "world", "minimaps", map.Directory, minimapName);

                        Directory.CreateDirectory(Path.GetDirectoryName(minimapPath));

                        using (var fileStream = File.Create(minimapPath))
                        {
                            minimapStream.CopyTo(fileStream);
                        }
                    }
                }
            }

            // Append any filenames from listfile for additional non-WDT referenced minimaps?
        }