public static ChunkedFile GetMapFromWDT(CASCLib.CASCHandler cascHandler, ChunkedFile wdt, uint x, uint y, string mapName) { if (!(x >= 0 && y >= 0 && x < 64 && y < 64)) { return(null); } if (adtCache[x][y] != null) { return(adtCache[x][y]); } MPHD header = wdt.GetChunk("MPHD").As <MPHD>(); if (header == null) { return(null); } MAIN main = wdt.GetChunk("MAIN").As <MAIN>(); if (main == null || (main.MapAreaInfo[y][x].Flag & 0x1) == 0) { return(null); } MAID mapFileIDs = wdt.GetChunk("MAID").As <MAID>(); if (mapFileIDs == null) { return(null); } if (mapFileIDs.MapFileDataIDs[y][x].Obj0ADT == 0) { return(null); } ADTFile adt = new(adtCache[x][y] != null); if ((header.Flags & 0x200) != 0) { adt.LoadFile(cascHandler, mapFileIDs.MapFileDataIDs[y][x].Obj0ADT, $"Obj0ADT {x}_{y} for {mapName}"); } else { adt.LoadFile(cascHandler, $"world/maps/{mapName}/{mapName}_{x}_{y}_obj0.adt"); } adtCache[x][y] = adt; return(adt); }
public static void ParsMapFiles(CASCLib.CASCHandler cascHandler) { for (var i = 0; i < 64; ++i) { adtCache[i] = new ChunkedFile[64]; } var mapStorage = DBReader.Read <MapRecord>(1349477); if (mapStorage == null) { Console.WriteLine("Fatal error: Invalid Map.db2 file format!\n"); return; } Dictionary <uint, WDTFile> wdts = new(); WDTFile getWDT(uint mapId) { WDTFile wdtFile = wdts.LookupByKey(mapId); if (wdtFile == null) { MapRecord record = mapStorage.LookupByKey(mapId); if (record == null) { return(null); } wdtFile = new WDTFile(); if (!wdtFile.LoadFile(cascHandler, $"world/maps/{record.Directory}/{record.Directory}.wdt") || !wdtFile.Init(mapId)) { return(null); } wdts.Add(mapId, wdtFile); } return(wdtFile); } foreach (var(id, record) in mapStorage) { WDTFile wdtFile = getWDT(id); if (wdtFile != null) { Console.Write($"Processing Map {id}\n"); for (uint x = 0; x < 64; ++x) { for (uint y = 0; y < 64; ++y) { bool success = true; if (GetMapFromWDT(cascHandler, wdtFile, x, y, record.Directory) is not ADTFile adt || !adt.Init(id, id)) { success = false; } if (!success) { WDTFile parentWDT = record.ParentMapID >= 0 ? getWDT((uint)record.ParentMapID) : null; MapRecord parentMap = mapStorage.LookupByKey((uint)record.ParentMapID); if (parentMap != null && parentWDT != null) { if (GetMapFromWDT(cascHandler, parentWDT, x, y, parentMap.Directory) is not ADTFile parentAdt || !parentAdt.Init(id, id)) { Console.WriteLine($"Failed to process map {id} and {record.ParentMapID}"); continue; } } } } // draw progress bar Console.Write($"Processing........................{(100 * (x + 1)) / 64}%\r"); } Console.Write("\n"); } } }