public static bool GenerateMapFiles(CMapObj map) { try { Logger.Notice($"Generating .map files for Map {map.DBCMap.MapName_enUS}"); var fileCount = 0; for (int tileBlockX = 0; tileBlockX < Constants.TileBlockSize; tileBlockX++) { for (int tileBlockY = 0; tileBlockY < Constants.TileBlockSize; tileBlockY++) { var tileBlock = map.TileBlocks[tileBlockX, tileBlockY]; if (tileBlock != null) { var mapID = map.DBCMap.ID.ToString("000"); var blockX = tileBlockX.ToString("00"); var blockY = tileBlockY.ToString("00"); var outputFileName = $@"{Paths.OutputMapsPath}{mapID}{blockX}{blockY}.map"; if (File.Exists(outputFileName)) { throw new Exception("Found existent invalid file!"); } var cell = TransformHeightData(tileBlock); using (FileStream fs = new FileStream(outputFileName, FileMode.Create)) { fs.Write(Encoding.ASCII.GetBytes(Globals.MapVersion), 0, 10); using (BinaryWriter br = new BinaryWriter(fs)) for (int cy = 0; cy < 256; cy++) { for (int cx = 0; cx < 256; cx++) { br.Write(CalculateZ(cell, (double)cy, (double)cx)); } } } fileCount++; } } } if (fileCount == 0) { Logger.Warning($"No tile data for Map {map.DBCMap.MapName_enUS}"); } else { Logger.Success($"Generated {fileCount} .map files for Map {map.DBCMap.MapName_enUS}"); } return(true); } catch (Exception ex) { Logger.Error(ex.Message); } return(false); }
public AsyncMapLoader(string fileName) : base() { this.WorkerReportsProgress = true; this.DoWork += new DoWorkEventHandler((o, e) => { CMapObj Map = new CMapObj(fileName, this); Map.LoadData(); e.Result = Map; }); this.ProgressChanged += new ProgressChangedEventHandler((o, e) => { Program.UpdateLoadingStatus(); }); this.RunWorkerCompleted += new RunWorkerCompletedEventHandler((o, e) => { if (e.Result is CMapObj map) { OnMapLoaded?.Invoke(this, new AsyncMapLoaderEventArgs(map)); } OnMapLoaded = null; }); }
static void Main(string[] args) { Version = Assembly.GetExecutingAssembly().GetName().Version; SetDefaultTitle(); PrintHeader(); if (!DBCExtractor.ExtractDBC()) { Console.WriteLine("Unable to extract DBC files, exiting..."); Console.ReadLine(); Environment.Exit(0); } if (!DBCStorage.Initialize()) { Console.WriteLine("Unable to initialize DBC Storage, exiting..."); Console.ReadLine(); Environment.Exit(0); } List <string> WDTFiles; if (!WDTExtractor.ExtractWDTFiles(out WDTFiles)) { Console.WriteLine("Unable to extract WDT files, exiting..."); Console.ReadLine(); Environment.Exit(0); } // For test only, extract only Azeroth. // TODO: We need to process, build map files, and release memory ASAP. // Right now, loading all data we are parsing would result in around 10gb. //Begin loading all wdt information. if (!Globals.LoadAsync) { foreach (var wdt in WDTFiles) { var map = new CMapObj(wdt, null); map.LoadData(); LoadedMaps.Add(map); break; } } else { foreach (var wdt in WDTFiles) { AsyncMapLoader loadMapTask = new AsyncMapLoader(wdt); loadMapTask.OnMapLoaded += OnMapLoaded; loadMapTask.RunWorkerAsync(); break; } } Console.ReadLine(); }
public AsyncMapLoaderEventArgs(CMapObj map) { Map = map; }
private static void StartProcess() { Version = Assembly.GetExecutingAssembly().GetName().Version; SetDefaultTitle(); PrintHeader(); try { // Extract Map.dbc and AreaTable.dbc if (!DBCExtractor.ExtractDBC()) { Logger.Error("Unable to extract DBC files, exiting..."); Console.ReadLine(); Environment.Exit(0); } // Load both files in memory. if (!DBCStorage.Initialize()) { Logger.Error("Unable to initialize DBC Storage, exiting..."); Console.ReadLine(); Environment.Exit(0); } // Extract available maps inside MPQ Dictionary <DBCMap, string> WDTFiles; if (!WDTExtractor.ExtractWDTFiles(out WDTFiles)) { Logger.Error("Unable to extract WDT files, exiting..."); Console.ReadLine(); Environment.Exit(0); } // Flush .map files output dir. Directory.Delete(Paths.OutputMapsPath, true); //Begin parsing adt files and generate .map files. foreach (var entry in WDTFiles) { using (CMapObj map = new CMapObj(entry.Key, entry.Value)) // Key:DbcMap Value:FilePath { MapFilesGenerator.GenerateMapFiles(map); LoadedMaps.Add(entry.Key); } GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true); } WDTFiles?.Clear(); Console.WriteLine(); Logger.Success("Process Complete, press any key to exit..."); } catch (Exception ex) { Logger.Error(ex.Message); Logger.Error(ex.StackTrace); } finally { IsRunning = false; } }