bool ADTFile::LoadMem(ByteBuffer& buf) { uint32 texturecnt=0,modelcnt=0,wmocnt=0; uint32 size; // used for every chunk uint32 mcnkid=0; uint8 _cc[5]; uint8 *fourcc = &_cc[0]; fourcc[4]=0; while(buf.rpos() < buf.size()) { buf.read(fourcc,4); flipcc(fourcc); buf.read((uint8*)&size,4); DEBUG(printf("ADT: reading '%s' size %u\n",fourcc,size)); if(!strcmp((char*)fourcc,"MVER")) { buf >> _version; } else if(!strcmp((char*)fourcc,"MHDR"))
bool WDTFile::LoadMem(ByteBuffer& buf) { uint8 *fourcc = new uint8[5]; fourcc[4] = 0; uint32 size; while(buf.rpos() < buf.size()) { buf.read(fourcc,4); flipcc(fourcc); buf >> size; if(!strcmp((char*)fourcc,"MVER")) { _mver = buf.read<WDT_MVER_Chunk>(); } else if(!strcmp((char*)fourcc,"MPHD")) { _mphd = buf.read<WDT_MPHD_Chunk>(); } else if(!strcmp((char*)fourcc,"MAIN")) { _main = buf.read<WDT_MAIN_Chunk>(); } else if(!strcmp((char*)fourcc,"MWMO")) { if(size) { DEBUG(printf("WDTFile::LoadMem() abort load, MWMO block isnt empty\n")); break; } } else if(!strcmp((char*)fourcc,"MODF")) { DEBUG(printf("WDTFile::LoadMem() abort load, MODF block exists\n")); break; } } delete [] fourcc; return true; }
bool WMORoot::open() { MPQFile f(filename.c_str()); if(f.isEof ()) { printf("No such file.\n"); return false; } uint32 size; char fourcc[5]; while (!f.isEof()) { f.read(fourcc,4); f.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = f.getPos() + size; if (!strcmp(fourcc,"MOHD")) // header { f.read(&nTextures, 4); f.read(&nGroups, 4); f.read(&nP, 4); f.read(&nLights, 4); f.read(&nModels, 4); f.read(&nDoodads, 4); f.read(&nDoodadSets, 4); f.read(&col, 4); f.read(&RootWMOID, 4); f.read(bbcorn1, 12); f.read(bbcorn2, 12); f.read(&liquidType, 4); break; } /* else if (!strcmp(fourcc,"MOTX")) { } else if (!strcmp(fourcc,"MOMT")) { } else if (!strcmp(fourcc,"MOGN")) { } else if (!strcmp(fourcc,"MOGI")) { } else if (!strcmp(fourcc,"MOLT")) { } else if (!strcmp(fourcc,"MODN")) { } else if (!strcmp(fourcc,"MODS")) { } else if (!strcmp(fourcc,"MODD")) { } else if (!strcmp(fourcc,"MOSB")) { } else if (!strcmp(fourcc,"MOPV")) { } else if (!strcmp(fourcc,"MOPT")) { } else if (!strcmp(fourcc,"MOPR")) { } else if (!strcmp(fourcc,"MFOG")) { } */ f.seek((int)nextpos); } f.close (); return true; }
bool WMOGroup::open() { MPQFile f(filename.c_str()); if(f.isEof ()) { printf("No such file.\n"); return false; } uint32 size; char fourcc[5]; while (!f.isEof()) { f.read(fourcc,4); f.read(&size, 4); flipcc(fourcc); if (!strcmp(fourcc,"MOGP"))//Fix sizeoff = Data size. { size = 68; } fourcc[4] = 0; size_t nextpos = f.getPos() + size; LiquEx_size = 0; liquflags = 0; if (!strcmp(fourcc,"MOGP"))//header { f.read(&groupName, 4); f.read(&descGroupName, 4); f.read(&mogpFlags, 4); f.read(bbcorn1, 12); f.read(bbcorn2, 12); f.read(&moprIdx, 2); f.read(&moprNItems, 2); f.read(&nBatchA, 2); f.read(&nBatchB, 2); f.read(&nBatchC, 4); f.read(&fogIdx, 4); f.read(&liquidType, 4); f.read(&groupWMOID,4); } else if (!strcmp(fourcc,"MOPY")) { MOPY = new char[size]; mopy_size = size; nTriangles = (int)size / 2; f.read(MOPY, size); } else if (!strcmp(fourcc,"MOVI")) { MOVI = new uint16[size/2]; f.read(MOVI, size); } else if (!strcmp(fourcc,"MOVT")) { MOVT = new float[size/4]; f.read(MOVT, size); nVertices = (int)size / 12; } else if (!strcmp(fourcc,"MONR")) { } else if (!strcmp(fourcc,"MOTV")) { } else if (!strcmp(fourcc,"MOBA")) { MOBA = new uint16[size/2]; moba_size = size/2; f.read(MOBA, size); } else if (!strcmp(fourcc,"MLIQ")) { liquflags |= 1; hlq = new WMOLiquidHeader(); f.read(hlq, 0x1E); LiquEx_size = sizeof(WMOLiquidVert) * hlq->xverts * hlq->yverts; LiquEx = new WMOLiquidVert[hlq->xverts * hlq->yverts]; f.read(LiquEx, LiquEx_size); int nLiquBytes = hlq->xtiles * hlq->ytiles; LiquBytes = new char[nLiquBytes]; f.read(LiquBytes, nLiquBytes); /* std::ofstream llog("Buildings/liquid.log", ios_base::out | ios_base::app); llog << filename; llog << "\nbbox: " << bbcorn1[0] << ", " << bbcorn1[1] << ", " << bbcorn1[2] << " | " << bbcorn2[0] << ", " << bbcorn2[1] << ", " << bbcorn2[2]; llog << "\nlpos: " << hlq->pos_x << ", " << hlq->pos_y << ", " << hlq->pos_z; llog << "\nx-/yvert: " << hlq->xverts << "/" << hlq->yverts << " size: " << size << " expected size: " << 30 + hlq->xverts*hlq->yverts*8 + hlq->xtiles*hlq->ytiles << std::endl; llog.close(); */ } f.seek((int)nextpos); } f.close(); return true; }
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY) { if(ADT.isEof ()) return false; uint32 size; string xMap; string yMap; Adtfilename.erase(Adtfilename.find(".adt"),4); string TempMapNumber; TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6); xMap = TempMapNumber.substr(TempMapNumber.find("_")+1,(TempMapNumber.find_last_of("_")-1) - (TempMapNumber.find("_"))); yMap = TempMapNumber.substr(TempMapNumber.find_last_of("_")+1,(TempMapNumber.length()) - (TempMapNumber.find_last_of("_"))); Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2)); //string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str()); //printf("Processing map %s...\n", AdtMapNumber.c_str()); //printf("MapNumber = %s\n", TempMapNumber.c_str()); //printf("xMap = %s\n", xMap.c_str()); //printf("yMap = %s\n", yMap.c_str()); std::string dirname = std::string(szWorkDirWmo) + "/dir_bin"; FILE *dirfile; dirfile = fopen(dirname.c_str(), "ab"); if(!dirfile) { printf("Can't open dirfile!'%s'\n", dirname.c_str()); return false; } while (!ADT.isEof()) { char fourcc[5]; ADT.read(&fourcc,4); ADT.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = ADT.getPos() + size; if (!strcmp(fourcc,"MCIN")) { } else if (!strcmp(fourcc,"MTEX")) { } else if (!strcmp(fourcc,"MMDX")) { if (size) { char *buf = new char[size]; ADT.read(buf, size); char *p=buf; int t=0; ModelInstansName = new string[size]; while (p<buf+size) { fixnamen(p,strlen(p)); char* s = GetPlainName(p); fixname2(s,strlen(s)); ModelInstansName[t++] = s; string path(p); ExtractSingleModel(path); p = p+strlen(p)+1; } delete[] buf; } } else if (!strcmp(fourcc,"MWMO")) { if (size) { char* buf = new char[size]; ADT.read(buf, size); char* p=buf; int q = 0; WmoInstansName = new string[size]; while (p<buf+size) { char* s = GetPlainName(p); fixnamen(s, strlen(s)); fixname2(s, strlen(s)); p += strlen(p) + 1; WmoInstansName[q++] = s; } delete[] buf; } } //====================== else if (!strcmp(fourcc,"MDDF")) { if (size) { nMDX = (int)size / 36; for (int i=0; i<nMDX; ++i) { uint32 id; ADT.read(&id, 4); ModelInstance inst(ADT,ModelInstansName[id].c_str(), map_num, tileX, tileY, dirfile); } delete[] ModelInstansName; } } else if (!strcmp(fourcc,"MODF")) { if (size) { nWMO = (int)size / 64; for (int i=0; i<nWMO; ++i) { uint32 id; ADT.read(&id, 4); WMOInstance inst(ADT,WmoInstansName[id].c_str(), map_num, tileX, tileY, dirfile); } delete[] WmoInstansName; } } //====================== ADT.seek(nextpos); } ADT.close(); fclose(dirfile); return true; }
bool WDTFile::init(char* /*map_id*/, unsigned int mapID) { if (WDT.isEof()) { //printf("Can't find WDT file.\n"); return false; } char fourcc[5]; uint32 size; std::string dirname = std::string(szWorkDirWmo) + "/dir_bin"; FILE *dirfile; dirfile = fopen(dirname.c_str(), "ab"); if(!dirfile) { printf("Can't open dirfile!'%s'\n", dirname.c_str()); return false; } while (!WDT.isEof()) { WDT.read(fourcc,4); WDT.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = WDT.getPos() + size; if (!strcmp(fourcc,"MAIN")) { } if (!strcmp(fourcc,"MWMO")) { // global map objects if (size) { char *buf = new char[size]; WDT.read(buf, size); char *p=buf; int q = 0; gWmoInstansName = new string[size]; while (p < buf + size) { char* s=wdtGetPlainName(p); fixnamen(s,strlen(s)); p=p+strlen(p)+1; gWmoInstansName[q++] = s; } delete[] buf; } } else if (!strcmp(fourcc, "MODF")) { // global wmo instance data if (size) { gnWMO = (int)size / 64; for (int i = 0; i < gnWMO; ++i) { int id; WDT.read(&id, 4); WMOInstance inst(WDT,gWmoInstansName[id].c_str(), mapID, 65, 65, dirfile); } delete[] gWmoInstansName; } } WDT.seek((int)nextpos); } WDT.close(); fclose(dirfile); return true; }
inline void LoadMapChunk(MPQFile & mf, chunk*_chunk) { float h; uint32 fourcc; uint32 size; MapChunkHeader header; mf.seekRelative(4); mf.read(&size, 4); size_t lastpos = mf.getPos() + size; mf.read(&header, 0x80); _chunk->area_id =header.areaid ; _chunk->flag =0; float xbase = header.xpos; float ybase = header.ypos; float zbase = header.zpos; zbase = TILESIZE*32-zbase; xbase = TILESIZE*32-xbase; if(wmoc.x >xbase)wmoc.x =xbase; if(wmoc.z >zbase)wmoc.z =zbase; int chunkflags = header.flags; float zmin=999999999.0f; float zmax=-999999999.0f; //must be there, bl!zz uses some crazy format int nTextures; while (mf.getPos() < lastpos) { mf.read(&fourcc,4); mf.read(&size, 4); //if(size!=580) // printf("\n sz=%d",size); size_t nextpos = mf.getPos() + size; if(fourcc==0x4d435654) // MCVT { for (int j=0; j<17; j++) for (int i=0; i<((j%2)?8:9); i++) { mf.read(&h,4); float z=h+ybase; if (j%2) { if(isHole(header.holes,i,j)) _chunk->v8[i][j/2] = -1000; else _chunk->v8[i][j/2] = z; } else { if(isHole(header.holes,i,j)) _chunk->v9[i][j/2] = -1000; else _chunk->v9[i][j/2] = z; } if(z>zmax)zmax=z; //if(z<zmin)zmin=z; } } else if(fourcc==0x4d434e52) // MCNR { nextpos = mf.getPos() + 0x1C0; // size fix } else if(fourcc==0x4d434c51) // MCLQ { // liquid / water level //bool haswater; char fcc1[5]; mf.read(fcc1,4); flipcc(fcc1); fcc1[4]=0; if (!strcmp(fcc1,"MCSE")) { for(int i=0;i<9;i++) for(int j=0;j<9;j++) _chunk->waterlevel[i][j]=-999999; // no liquid/water } else { float maxheight; mf.read(&maxheight, 4); for(int j=0;j<9;j++) for(int i=0;i<9;i++) { mf.read(&h, 4); mf.read(&h, 4); if(h > maxheight) _chunk->waterlevel[i][j]=-999999; else _chunk->waterlevel[i][j]=h; } if(chunkflags & 4 || chunkflags & 8) _chunk->flag |=1; if(chunkflags & 16) _chunk->flag |=2; } break; } else if (fourcc==0x4d434c59) // MCLY { // texture info nTextures = (int)size; } else if (fourcc==0x4d43414c) // MCAL { if (nTextures<=0) continue; } mf.seek(nextpos); } }
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY) { if(ADT.isEof ()) return false; uint32 size; string xMap; string yMap; Adtfilename.erase(Adtfilename.find(".adt"),4); string TempMapNumber; TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6); xMap = TempMapNumber.substr(TempMapNumber.find("_")+1,(TempMapNumber.find_last_of("_")-1) - (TempMapNumber.find("_"))); yMap = TempMapNumber.substr(TempMapNumber.find_last_of("_")+1,(TempMapNumber.length()) - (TempMapNumber.find_last_of("_"))); Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2)); string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str()); //printf("Processing map %s...\n", AdtMapNumber.c_str()); //printf("MapNumber = %s\n", TempMapNumber.c_str()); //printf("xMap = %s\n", xMap.c_str()); //printf("yMap = %s\n", yMap.c_str()); std::string dirname = std::string(szWorkDirWmo) + "/dir_bin"; FILE *dirfile; dirfile = fopen(dirname.c_str(), "ab"); if(!dirfile) { printf("Can't open dirfile!'%s'\n", dirname.c_str()); return false; } while (!ADT.isEof()) { char fourcc[5]; ADT.read(&fourcc,4); ADT.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = ADT.getPos() + size; if (!strcmp(fourcc,"MCIN")) { } else if (!strcmp(fourcc,"MTEX")) { } else if (!strcmp(fourcc,"MMDX")) { if (size) { char *buf = new char[size]; ADT.read(buf, size); char *p=buf; int t=0; ModelInstansName = new string[size]; while (p<buf+size) { fixnamen(p,strlen(p)); string path(p); char* s=GetPlainName(p); fixname2(s,strlen(s)); p=p+strlen(p)+1; ModelInstansName[t++] = s; // < 3.1.0 ADT MMDX section store filename.mdx filenames for corresponded .m2 file std::string ext3 = path.size() >= 4 ? path.substr(path.size()-4,4) : ""; std::transform( ext3.begin(), ext3.end(), ext3.begin(), ::tolower ); if(ext3 == ".mdx") { // replace .mdx -> .m2 path.erase(path.length()-2,2); path.append("2"); } // >= 3.1.0 ADT MMDX section store filename.m2 filenames for corresponded .m2 file // nothing do char szLocalFile[1024]; snprintf(szLocalFile, 1024, "%s/%s", szWorkDirWmo, s); FILE * output = fopen(szLocalFile,"rb"); if(!output) { Model m2(path); if(m2.open()) m2.ConvertToVMAPModel(szLocalFile); } else fclose(output); } delete[] buf; } } else if (!strcmp(fourcc,"MWMO")) { if (size) { char *buf = new char[size]; ADT.read(buf, size); char *p=buf; int q = 0; WmoInstansName = new string[size]; while (p<buf+size) { string path(p); char* s=GetPlainName(p); fixnamen(s,strlen(s)); fixname2(s,strlen(s)); p=p+strlen(p)+1; WmoInstansName[q++] = s; } delete[] buf; } } //====================== else if (!strcmp(fourcc,"MDDF")) { if (size) { nMDX = (int)size / 36; for (int i=0; i<nMDX; ++i) { uint32 id; ADT.read(&id, 4); ModelInstance inst(ADT,ModelInstansName[id].c_str(), map_num, tileX, tileY, dirfile); } delete[] ModelInstansName; } } else if (!strcmp(fourcc,"MODF")) { if (size) { nWMO = (int)size / 64; for (int i=0; i<nWMO; ++i) { uint32 id; ADT.read(&id, 4); WMOInstance inst(ADT,WmoInstansName[id].c_str(), map_num, tileX, tileY, dirfile); } delete[] WmoInstansName; } } //====================== ADT.seek(nextpos); } ADT.close(); fclose(dirfile); return true; }
bool ADTFile::init(uint32 map_num, uint32 originalMapId) { if (dirfileCache) return initFromCache(map_num, originalMapId); if (_file.isEof()) return false; uint32 size; std::string dirname = std::string(szWorkDirWmo) + "/dir_bin"; FILE* dirfile = fopen(dirname.c_str(), "ab"); if(!dirfile) { printf("Can't open dirfile!'%s'\n", dirname.c_str()); return false; } if (cacheable) dirfileCache = new std::vector<ADTOutputCache>(); while (!_file.isEof()) { char fourcc[5]; _file.read(&fourcc,4); _file.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = _file.getPos() + size; if (!strcmp(fourcc,"MCIN")) { } else if (!strcmp(fourcc,"MTEX")) { } else if (!strcmp(fourcc,"MMDX")) { if (size) { char* buf = new char[size]; _file.read(buf, size); char* p = buf; while (p < buf + size) { std::string path(p); char* s = GetPlainName(p); FixNameCase(s, strlen(s)); FixNameSpaces(s, strlen(s)); ModelInstanceNames.emplace_back(s); ExtractSingleModel(path); p += strlen(p) + 1; } delete[] buf; } } else if (!strcmp(fourcc,"MWMO")) { if (size) { char* buf = new char[size]; _file.read(buf, size); char* p = buf; while (p < buf + size) { std::string path(p); char* s = GetPlainName(p); FixNameCase(s, strlen(s)); FixNameSpaces(s, strlen(s)); WmoInstanceNames.emplace_back(s); ExtractSingleWmo(path); p += strlen(p) + 1; } delete[] buf; } } //====================== else if (!strcmp(fourcc, "MDDF")) { if (size) { uint32 doodadCount = size / sizeof(ADT::MDDF); for (uint32 i = 0; i < doodadCount; ++i) { ADT::MDDF doodadDef; _file.read(&doodadDef, sizeof(ADT::MDDF)); if (!(doodadDef.Flags & 0x40)) { Doodad::Extract(doodadDef, ModelInstanceNames[doodadDef.Id].c_str(), map_num, originalMapId, dirfile, dirfileCache); } else { std::string fileName = Trinity::StringFormat("FILE%08X.xxx", doodadDef.Id); ExtractSingleModel(fileName); Doodad::Extract(doodadDef, fileName.c_str(), map_num, originalMapId, dirfile, dirfileCache); } } ModelInstanceNames.clear(); } } else if (!strcmp(fourcc,"MODF")) { if (size) { uint32 mapObjectCount = size / sizeof(ADT::MODF); for (uint32 i = 0; i < mapObjectCount; ++i) { ADT::MODF mapObjDef; _file.read(&mapObjDef, sizeof(ADT::MODF)); if (!(mapObjDef.Flags & 0x8)) { MapObject::Extract(mapObjDef, WmoInstanceNames[mapObjDef.Id].c_str(), false, map_num, originalMapId, dirfile, dirfileCache); Doodad::ExtractSet(WmoDoodads[WmoInstanceNames[mapObjDef.Id]], mapObjDef, false, map_num, originalMapId, dirfile, dirfileCache); } else { std::string fileName = Trinity::StringFormat("FILE%08X.xxx", mapObjDef.Id); ExtractSingleWmo(fileName); MapObject::Extract(mapObjDef, fileName.c_str(), false, map_num, originalMapId, dirfile, dirfileCache); Doodad::ExtractSet(WmoDoodads[fileName], mapObjDef, false, map_num, originalMapId, dirfile, dirfileCache); } } WmoInstanceNames.clear(); } } //====================== _file.seek(nextpos); } _file.close(); fclose(dirfile); return true; }
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY) { if (ADT.isEof()) return false; uint32 size; std::string dirname = std::string(szWorkDirWmo) + "/dir_bin"; FILE *dirfile; dirfile = fopen(dirname.c_str(), "ab"); if(!dirfile) { printf("Can't open dirfile!'%s'\n", dirname.c_str()); return false; } while (!ADT.isEof()) { char fourcc[5]; ADT.read(&fourcc,4); ADT.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = ADT.getPos() + size; if (!strcmp(fourcc,"MCIN")) { } else if (!strcmp(fourcc,"MTEX")) { } else if (!strcmp(fourcc,"MMDX")) { if (size) { char* buf = new char[size]; ADT.read(buf, size); char* p = buf; while (p < buf + size) { std::string path(p); char* s = GetPlainName(p); FixNameCase(s, strlen(s)); FixNameSpaces(s, strlen(s)); ModelInstanceNames.push_back(s); ExtractSingleModel(path); p += strlen(p) + 1; } delete[] buf; } } else if (!strcmp(fourcc,"MWMO")) { if (size) { char* buf = new char[size]; ADT.read(buf, size); char* p = buf; while (p < buf + size) { char* s = GetPlainName(p); FixNameCase(s, strlen(s)); FixNameSpaces(s, strlen(s)); WmoInstanceNames.push_back(s); p += strlen(p) + 1; } delete[] buf; } } //====================== else if (!strcmp(fourcc,"MDDF")) { if (size) { nMDX = (int)size / 36; for (int i=0; i<nMDX; ++i) { uint32 id; ADT.read(&id, 4); ModelInstance inst(ADT, ModelInstanceNames[id].c_str(), map_num, tileX, tileY, dirfile); } ModelInstanceNames.clear(); } } else if (!strcmp(fourcc,"MODF")) { if (size) { nWMO = (int)size / 64; for (int i=0; i<nWMO; ++i) { uint32 id; ADT.read(&id, 4); WMOInstance inst(ADT, WmoInstanceNames[id].c_str(), map_num, tileX, tileY, dirfile); } WmoInstanceNames.clear(); } } //====================== ADT.seek(nextpos); } ADT.close(); fclose(dirfile); return true; }
bool ADTFile::init(char *map_id) { if(ADT.isEof ()) return false; size_t size; string xMap; string yMap; Adtfilename.erase(Adtfilename.find(".adt"),4); string TempMapNumber; TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6); xMap = TempMapNumber.substr(TempMapNumber.find("_")+1,(TempMapNumber.find_last_of("_")-1) - (TempMapNumber.find("_"))); yMap = TempMapNumber.substr(TempMapNumber.find_last_of("_")+1,(TempMapNumber.length()) - (TempMapNumber.find_last_of("_"))); Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2)); string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str()); printf("Processing map %s...\n", AdtMapNumber.c_str()); //printf("MapNumber = %s\n", TempMapNumber.c_str()); //printf("xMap = %s\n", xMap.c_str()); //printf("yMap = %s\n", yMap.c_str()); const char dirname[] = "buildings\\dir"; FILE *dirfile; dirfile = fopen(dirname, "ab"); if(!dirfile) { printf("Can't open dirfile!'%s'\n"); return false; } while (!ADT.isEof ()) { char fourcc[5]; ADT.read(&fourcc,4); ADT.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = ADT.getPos () + size; if (!strcmp(fourcc,"MCIN"))//MCIN { } else if (!strcmp(fourcc,"MTEX")) { } else if (!strcmp(fourcc,"MMDX")) { if (size) { char *buf = new char[size]; ADT.read(buf, size); char *p=buf; int t=0; ModelInstansName = new string[size]; while (p<buf+size) { fixnamen(p,strlen(p)); string path(p); char* s=GetPlainName(p); fixname2(s,strlen(s)); p=p+strlen(p)+1; ModelInstansName[t++] = s; path.erase(path.length()-2,2); path.append("2"); char* szLocalFile[512]; sprintf((char*)szLocalFile, ".\\buildings\\%s", s); FILE * output = fopen((char*)szLocalFile,"rb"); if(!output) { Model * m2 = new Model(path); if(m2->open()) { m2->ConvertToVMAPModel((char*)szLocalFile); } delete m2; } else fclose(output); } delete[] buf; } } else if (!strcmp(fourcc,"MWMO")) { if (size) { char *buf = new char[size]; ADT.read(buf, size); char *p=buf; int q = 0; WmoInstansName = new string[size]; while (p<buf+size) { string path(p); char* s=GetPlainName(p); fixnamen(s,strlen(s)); fixname2(s,strlen(s)); p=p+strlen(p)+1; WmoInstansName[q++] = s; } delete[] buf; } } //====================== else if (!strcmp(fourcc,"MDDF")) { if (size) { nMDX = (int)size / 36; for (int i=0; i<nMDX; i++) { int id; ADT.read(&id, 4); ModelInstance inst(ADT,ModelInstansName[id].c_str(),map_id, dirfile);//!!!!!!!!!!! } delete[] ModelInstansName; } } else if (!strcmp(fourcc,"MODF")) { if (size) { nWMO = (int)size / 64; for (int i=0; i<nWMO; i++) { int id; ADT.read(&id, 4); WMOInstance inst(ADT,WmoInstansName[id].c_str(),map_id, dirfile);//!!!!!!!!!!!!! } delete[] WmoInstansName; } } //====================== #if 0 else if (!strcmp(fourcc,"MDDF")) { if (size) { nMDX = (int)size / 36; for (int i=0; i<nMDX; i++) { int id; ADT.read(&id, 4); ModelInstance inst(ADT,ModelInstansName[id].c_str(),AdtMapNumber.c_str(), dirfile); } delete[] ModelInstansName; } } else if (!strcmp(fourcc,"MODF")) { if (size) { nWMO = (int)size / 64; for (int i=0; i<nWMO; i++) { int id; ADT.read(&id, 4); WMOInstance inst(ADT,WmoInstansName[id].c_str(),AdtMapNumber.c_str(), dirfile); } delete[] WmoInstansName; } } #endif ADT.seek(nextpos); } ADT.close(); fclose(dirfile); return true; }
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY) { if(ADT.isEof ()) return false; uint32 size; string xMap; string yMap; MH20_Header mh2oheader[256]; memset(&mh2oheader,0, sizeof(MH20_Header)*256); uint32 mh2o_base = 0; Adtfilename.erase(Adtfilename.find(".adt"),4); string TempMapNumber; TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6); xMap = TempMapNumber.substr(TempMapNumber.find("_")+1,(TempMapNumber.find_last_of("_")-1) - (TempMapNumber.find("_"))); yMap = TempMapNumber.substr(TempMapNumber.find_last_of("_")+1,(TempMapNumber.length()) - (TempMapNumber.find_last_of("_"))); Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2)); string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str()); std::string dirname = std::string(szWorkDirWmo) + "/dir_bin"; FILE *dirfile = fopen(dirname.c_str(), "ab"); if(!dirfile) { printf("Can't open dirfile!'%s'\n", dirname.c_str()); return false; } while (!ADT.isEof()) { char fourcc[5]; ADT.read(&fourcc, 4); ADT.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = ADT.getPos() + size; if (!strcmp(fourcc,"MCIN")) { } else if (!strcmp(fourcc,"MVER")) { } else if (!strcmp(fourcc,"MHDR")) { } else if (!strcmp(fourcc,"MTEX")) { } else if (!strcmp(fourcc,"MWID")) // offsets for strings in MWMO { } else if (!strcmp(fourcc,"MMID")) // offsets for strings in MMDX { } else if (!strcmp(fourcc,"MTEX")) { } else if (!strcmp(fourcc,"MTXF")) { } else if (!strcmp(fourcc,"MFBO")) { } else if (!strcmp(fourcc,"MMDX")) { if (size) { char *buf = new char[size]; ADT.read(buf, size); char *p=buf; int t=0; ModelInstansName = new string[size]; while (p<buf+size) { fixnamen(p,strlen(p)); string path(p); char* s=GetPlainName(p); fixname2(s,strlen(s)); p=p+strlen(p)+1; ModelInstansName[t++] = s; // < 3.1.0 ADT MMDX section store filename.mdx filenames for corresponded .m2 file std::string ext3 = path.size() >= 4 ? path.substr(path.size()-4,4) : ""; std::transform( ext3.begin(), ext3.end(), ext3.begin(), ::tolower ); if(ext3 == ".mdx") { // replace .mdx -> .m2 path.erase(path.length()-2,2); path.append("2"); } // >= 3.1.0 ADT MMDX section store filename.m2 filenames for corresponded .m2 file // nothing do char szLocalFile[1024]; snprintf(szLocalFile, 1024, "%s/%s", szWorkDirWmo, s); FILE * output = fopen(szLocalFile,"rb"); if(!output) { Model m2(path); if(m2.open()) m2.ConvertToVMAPModel(szLocalFile); } else fclose(output); } delete[] buf; } } else if (!strcmp(fourcc,"MWMO")) { if (size) { char *buf = new char[size]; ADT.read(buf, size); char *p=buf; int q = 0; WmoInstansName = new string[size]; while (p<buf+size) { string path(p); char* s=GetPlainName(p); fixnamen(s,strlen(s)); fixname2(s,strlen(s)); p=p+strlen(p)+1; WmoInstansName[q++] = s; } delete[] buf; } } //====================== else if (!strcmp(fourcc,"MDDF")) { if (size) { nMDX = (int)size / 36; for (int i=0; i<nMDX; ++i) { uint32 id; ADT.read(&id, 4); ModelInstance inst(ADT, ModelInstansName[id].c_str(), map_num, tileX, tileY, dirfile); } delete[] ModelInstansName; } } else if (!strcmp(fourcc,"MODF")) { if (size) { nWMO = (int)size / 64; for (int i=0; i<nWMO; ++i) { uint32 id; ADT.read(&id, 4); WMOInstance inst(ADT, WmoInstansName[id].c_str(), map_num, tileX, tileY, dirfile); } delete[] WmoInstansName; } } else if (!strcmp(fourcc,"MCNK")) { } else if (!strcmp(fourcc,"MH2O")) { if (size) { mh2o_base = ADT.getPos(); for (int i = 0; i < 256; i++) ADT.read(&mh2oheader[i], sizeof(MH20_Header)); } } else { printf("Unknown Chunk type: %s\n", (char*)fourcc); } //====================== ADT.seek(nextpos); } FILE *input = NULL; uint32 Offsets[256]; string output = format("%s/Liquid_%03u_%02u_%02u.L2", szWorkDirWmo, map_num, tileX, tileY); fopen_s(&input, output.c_str(), "w"); for (int j=0; j<16; j++) for (int i=0; i<16; i++) Offsets[j*16+i] = 0; fwrite(&Offsets, sizeof(uint32)*256, 1, input); for (int j=0; j<16; j++) { for (int i=0; i<16; i++) { if (mh2oheader[j*16+i].layerCount > 0) { uint32 Offset = ftell(input); LiquidModelInstance Liq(ADT, mh2o_base, j*16+i, &mh2oheader[j*16+i], map_num, tileX, tileY, input); if(Liq.ShouldWrite()) Offsets[j*16+i] = Offset; } } } fwrite(&Offsets, sizeof(uint32)*256, 1, input); fclose(input); ADT.close(); fclose(dirfile); return true; }
bool WDTFile::init(char *map_id) { if (WDT.isEof()) { //printf("Can't find WDT file.\n"); return false; } char fourcc[5]; size_t size; const char dirname[] = "buildings\\dir"; FILE *dirfile; dirfile = fopen(dirname, "ab"); if(!dirfile) { printf("Can't open dirfile!'%s'\n"); return false; } while (!WDT.isEof()) { WDT.read(fourcc,4); WDT.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = WDT.getPos() + size; if (!strcmp(fourcc,"MAIN")) { } if (!strcmp(fourcc,"MWMO")) { // global map objects if (size) { char *buf = new char[size]; WDT.read(buf, size); char *p=buf; int q = 0; gWmoInstansName = new string[size]; while (p<buf+size) { string path(p); char* s=wdtGetPlainName(p); fixnamen(s,strlen(s)); p=p+strlen(p)+1; gWmoInstansName[q++] = s; } delete[] buf; } } else if (!strcmp(fourcc,"MODF")) { // global wmo instance data if (size) { gnWMO = (int)size / 64; string gWMO_mapname; string fake_mapname; fake_mapname = "65 65 "; //gWMO_mapname = fake_mapname + filename; gWMO_mapname = fake_mapname + std::string(map_id); for (int i=0; i<gnWMO; i++) { int id; WDT.read(&id, 4); WMOInstance inst(WDT,gWmoInstansName[id].c_str(),gWMO_mapname.c_str(), dirfile); } delete[] gWmoInstansName; } } WDT.seek((int)nextpos); } WDT.close(); fclose(dirfile); return true; }
bool WDTFile::init(uint32 mapId) { if (_file.isEof()) return false; char fourcc[5]; uint32 size; std::string dirname = std::string(szWorkDirWmo) + "/dir_bin"; FILE* dirfile = fopen(dirname.c_str(), "ab"); if (!dirfile) { printf("Can't open dirfile!'%s'\n", dirname.c_str()); return false; } while (!_file.isEof()) { _file.read(fourcc,4); _file.read(&size, 4); flipcc(fourcc); fourcc[4] = 0; size_t nextpos = _file.getPos() + size; if (!strcmp(fourcc,"MAIN")) { } if (!strcmp(fourcc,"MWMO")) { // global map objects if (size) { char *buf = new char[size]; _file.read(buf, size); char *p = buf; while (p < buf + size) { std::string path(p); char* s = wdtGetPlainName(p); FixNameCase(s, strlen(s)); FixNameSpaces(s, strlen(s)); p = p + strlen(p) + 1; _wmoNames.push_back(s); ExtractSingleWmo(path); } delete[] buf; } } else if (!strcmp(fourcc, "MODF")) { // global wmo instance data if (size) { int32 gnWMO = (int)size / 64; for (int i = 0; i < gnWMO; ++i) { int id; _file.read(&id, 4); WMOInstance inst(_file, _wmoNames[id].c_str(), mapId, 65, 65, mapId, dirfile, nullptr); } } } _file.seek((int)nextpos); } _file.close(); fclose(dirfile); return true; }
inline void LoadMapChunk(MPQFile &mf, chunk *_chunk) { float h; uint32 fourcc; uint32 size; MapChunkHeader header; mf.seekRelative(4); mf.read(&size, 4); size_t lastpos = mf.getPos() + size; mf.read(&header, 0x80); // what if header size got changed? _chunk->area_id = header.areaid; float xbase = header.xpos; float ybase = header.ypos; float zbase = header.zpos; zbase = TILESIZE * 32 - zbase; xbase = TILESIZE * 32 - xbase; if(wmoc.x > xbase) wmoc.x = xbase; if(wmoc.z > zbase) wmoc.z = zbase; int chunkflags = header.flags; //printf("LMC: flags %X\n", chunkflags); float zmin = 999999999.0f; float zmax = -999999999.0f; // must be there, bl!zz uses some crazy format while (mf.getPos() < lastpos) { mf.read(&fourcc, 4); mf.read(&size, 4); size_t nextpos = mf.getPos() + size; if(fourcc == 0x4d435654) // MCVT { for (int j = 0; j < 17; ++j) { for (int i = 0; i < ((j % 2) ? 8 : 9); ++i) { mf.read(&h, 4); float z = h + ybase; if (j % 2) { if(isHole(header.holes, i, j)) _chunk->v8[i][j / 2] = -1000; else _chunk->v8[i][j / 2] = z; } else { if(isHole(header.holes, i, j)) _chunk->v9[i][j / 2] = -1000; else _chunk->v9[i][j / 2] = z; } if(z > zmax) zmax = z; //if(z < zmin) zmin = z; } } } else if(fourcc == 0x4d434e52) // MCNR { nextpos = mf.getPos() + 0x1C0; // size fix } else if(fourcc == 0x4d434c51) // MCLQ { // liquid / water level char fcc1[5]; mf.read(fcc1, 4); flipcc(fcc1); fcc1[4] = 0; float *ChunkLiqHeight = new float[81]; if (!strcmp(fcc1, "MCSE")) { for(int j = 0; j < 81; ++j) { ChunkLiqHeight[j] = -999999; // no liquid/water } } else { float maxheight; mf.read(&maxheight, 4); for(int j = 0; j < 81; ++j) { LiqData liq; mf.read(&liq, 8); if(liq.height > maxheight) ChunkLiqHeight[j] = -999999; else ChunkLiqHeight[j] = h; } if(chunkflags & 4 || chunkflags & 8) MapLiqFlag[chunk_num] |= 1; // water if(chunkflags & 16) MapLiqFlag[chunk_num] |= 2; // magma/slime } if(!(chunk_num % 16)) m = 1024 * (chunk_num / 16); k = m + (chunk_num % 16) * 8; for(int p = 0; p < 72; p += 9) { for(int s = 0; s < 8; ++s) { MapLiqHeight[k] = ChunkLiqHeight[p + s]; ++k; } k = k + 120; } delete []ChunkLiqHeight; break; } mf.seek(nextpos); } }