public static void ParsMapFiles() { var mapStorage = DBReader.Read <MapRecord>("DBFilesClient\\Map.db2"); if (mapStorage == null) { Console.WriteLine("Fatal error: Invalid Map.db2 file format!\n"); return; } Dictionary <uint, Tuple <string, int> > map_ids = new Dictionary <uint, Tuple <string, int> >(); List <uint> maps_that_are_parents = new List <uint>(); foreach (var record in mapStorage.Values) { map_ids[record.Id] = Tuple.Create(record.Directory, (int)record.ParentMapID); if (record.ParentMapID >= 0) { maps_that_are_parents.Add((uint)record.ParentMapID); } } Dictionary <uint, WDTFile> wdts = new Dictionary <uint, WDTFile>(); Func <uint, WDTFile> getWDT = mapId => { var wdtFile = wdts.LookupByKey(mapId); if (wdtFile == null) { string fn = $"World\\Maps\\{map_ids[mapId].Item1}\\{map_ids[mapId].Item1}"; bool v1 = maps_that_are_parents.Contains(mapId); bool v2 = map_ids[mapId].Item2 != -1; wdtFile = new WDTFile(fn, maps_that_are_parents.Contains(mapId)); wdts.Add(mapId, wdtFile); if (!wdtFile.init(mapId)) { wdts.Remove(mapId); return(null); } } return(wdtFile); }; foreach (var pair in map_ids) { WDTFile WDT = getWDT(pair.Key); if (WDT != null) { WDTFile parentWDT = pair.Value.Item2 >= 0 ? getWDT((uint)pair.Value.Item2) : null; Console.Write($"Processing Map {pair.Key}\n"); for (uint x = 0; x < 64; ++x) { for (uint y = 0; y < 64; ++y) { bool success = false; ADTFile ADT = WDT.GetMap(x, y); if (ADT != null) { success = ADT.init(pair.Key, pair.Key); } if (!success && parentWDT != null) { ADTFile parentADT = parentWDT.GetMap(x, y); if (parentADT != null) { parentADT.init(pair.Key, (uint)pair.Value.Item2); } } } // draw progress bar Console.Write($"Processing........................{(100 * (x + 1)) / 64}%\r"); } Console.Write("\n"); } } }
public static void ParsMapFiles() { var mapStorage = DBReader.Read <MapRecord>(1349477); if (mapStorage == null) { Console.WriteLine("Fatal error: Invalid Map.db2 file format!\n"); return; } Dictionary <uint, MapRecord> map_ids = new Dictionary <uint, MapRecord>(); List <uint> maps_that_are_parents = new List <uint>(); foreach (var record in mapStorage.Values) { map_ids[record.Id] = record; if (record.ParentMapID >= 0) { maps_that_are_parents.Add((uint)record.ParentMapID); } } Dictionary <uint, WDTFile> wdts = new Dictionary <uint, WDTFile>(); Func <uint, WDTFile> getWDT = mapId => { var wdtFile = wdts.LookupByKey(mapId); if (wdtFile == null) { uint fileDataId = map_ids[mapId].WdtFileDataID; if (fileDataId == 0) { return(null); } string directory = map_ids[mapId].Directory; wdtFile = new WDTFile(fileDataId, directory, maps_that_are_parents.Contains(mapId)); wdts.Add(mapId, wdtFile); if (!wdtFile.init(mapId)) { wdts.Remove(mapId); return(null); } } return(wdtFile); }; foreach (var pair in map_ids) { WDTFile WDT = getWDT(pair.Key); if (WDT != null) { WDTFile parentWDT = pair.Value.ParentMapID >= 0 ? getWDT((uint)pair.Value.ParentMapID) : null; Console.Write($"Processing Map {pair.Key}\n"); for (uint x = 0; x < 64; ++x) { for (uint y = 0; y < 64; ++y) { bool success = false; ADTFile ADT = WDT.GetMap(x, y); if (ADT != null) { success = ADT.init(pair.Key, pair.Key); } if (!success && parentWDT != null) { ADTFile parentADT = parentWDT.GetMap(x, y); if (parentADT != null) { parentADT.init(pair.Key, (uint)pair.Value.ParentMapID); } } } // draw progress bar Console.Write($"Processing........................{(100 * (x + 1)) / 64}%\r"); } Console.Write("\n"); } } }