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 bool init(uint mapId) { if (_fileStream == null) { return(false); } string dirname = Program.WmoDirectory + "dir_bin"; using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(dirname, FileMode.Append, FileAccess.Write))) { using (BinaryReader binaryReader = new BinaryReader(_fileStream)) { long fileLength = binaryReader.BaseStream.Length; while (binaryReader.BaseStream.Position < fileLength) { string fourcc = binaryReader.ReadStringFromChars(4, true); uint size = binaryReader.ReadUInt32(); long nextpos = binaryReader.BaseStream.Position + size; if (fourcc == "MPHD") { _header = binaryReader.Read <MPHD>(); } else if (fourcc == "MAIN") { _adtInfo = new MAIN(); _adtInfo.Read(binaryReader); } else if (fourcc == "MAID") { _adtFileDataIds = new MAID(); _adtFileDataIds.Read(binaryReader); } else if (fourcc == "MWMO") { // global map objects if (size != 0) { while (size > 0) { string path = binaryReader.ReadCString(); _wmoNames.Add(path.GetPlainName()); VmapFile.ExtractSingleWmo(path); size -= (uint)(path.Length + 1); } } } else if (fourcc == "MODF") { // global wmo instance data if (size != 0) { uint mapObjectCount = size / 64; //sizeof(ADT::MODF); for (int i = 0; i < mapObjectCount; ++i) { MODF mapObjDef = binaryReader.Read <MODF>(); if (!Convert.ToBoolean(mapObjDef.Flags & 0x8)) { WMORoot.Extract(mapObjDef, _wmoNames[(int)mapObjDef.Id], true, mapId, mapId, binaryWriter, null); Model.ExtractSet(VmapFile.WmoDoodads[_wmoNames[(int)mapObjDef.Id]], mapObjDef, true, mapId, mapId, binaryWriter, null); } else { string fileName = $"FILE{mapObjDef.Id}:8X.xxx"; VmapFile.ExtractSingleWmo(fileName); WMORoot.Extract(mapObjDef, fileName, true, mapId, mapId, binaryWriter, null); Model.ExtractSet(VmapFile.WmoDoodads[fileName], mapObjDef, true, mapId, mapId, binaryWriter, null); } } } } binaryReader.BaseStream.Seek(nextpos, SeekOrigin.Begin); } } } return(true); }