diff --git a/src/Client/MemoryDataHolder.cpp b/src/Client/MemoryDataHolder.cpp index 3769045..3d73c5e 100644 --- a/src/Client/MemoryDataHolder.cpp +++ b/src/Client/MemoryDataHolder.cpp @@ -96,6 +96,16 @@ namespace MemoryDataHolder sprintf(fn,"./data/model/%s",fname.c_str()); } } + void MakeWMOFilename(char* fn, std::string fname) + { + if(loadFromMPQ) + sprintf(fn,"%s",fname.c_str()); + else + { + NormalizeFilename(_PathToFileName(fname)); + sprintf(fn,"./data/wmos/%s",fname.c_str()); + } + } bool FileExists(std::string fname) { diff --git a/src/Client/MemoryDataHolder.h b/src/Client/MemoryDataHolder.h index 8d7091e..a16dec6 100644 --- a/src/Client/MemoryDataHolder.h +++ b/src/Client/MemoryDataHolder.h @@ -54,6 +54,7 @@ namespace MemoryDataHolder void MakeWDTFilename(char*,uint32,std::string); void MakeTextureFilename(char*, std::string); void MakeModelFilename(char*, std::string); + void MakeWMOFilename(char*, std::string); bool FileExists(std::string); MemoryDataResult GetFile(std::string s, bool threaded = false, callback_func func = NULL,void *ptr = NULL, ZThread::Condition *cond = NULL, bool ref_counted = true); diff --git a/src/Client/World/MapMgr.cpp b/src/Client/World/MapMgr.cpp index 681fb34..31948f3 100644 --- a/src/Client/World/MapMgr.cpp +++ b/src/Client/World/MapMgr.cpp @@ -127,12 +127,18 @@ void MapMgr::_LoadTile(uint32 gx, uint32 gy, uint32 m) bb.append(mdr.data.ptr,mdr.data.size); MemoryDataHolder::Delete(buf); ADTFile *adt = new ADTFile(); - adt->LoadMem(bb); - logdebug("MAPMGR: Loaded ADT '%s'",buf); - MapTile *tile = new MapTile(); - tile->ImportFromADT(adt); + if(adt->LoadMem(bb)) + { + logdebug("MAPMGR: Loaded ADT '%s'",buf); + MapTile *tile = new MapTile(); + tile->ImportFromADT(adt); + _tiles->SetTile(tile,gx,gy); + } + else + { + logerror("MAPMGR: Error loading ADT '%s'",buf);//This should not happen!! + } delete adt; - _tiles->SetTile(tile,gx,gy); logdebug("MAPMGR: Imported MapTile (%u, %u) for map %u",gx,gy,m); } else diff --git a/src/shared/ADTFile.cpp b/src/shared/ADTFile.cpp index 5a152d0..dbbb409 100644 --- a/src/shared/ADTFile.cpp +++ b/src/shared/ADTFile.cpp @@ -215,13 +215,14 @@ bool ADTFile::LoadMem(ByteBuffer& buf) } else if(!strcmp((char*)fourcc,"MCNK")) { + uint32 endpos = buf.rpos()+size; _chunks[mcnkid].hdr = buf.read(); uint8 _cc2[5]; uint8 *mfcc = &_cc2[0]; mfcc[4]=0; uint32 msize; bool mcal_compressed = false; - while(buf.rpos()::iterator it = adt->_textures.begin(); it != adt->_textures.end(); it++) - this->_textures.push_back(_PathToFileName(*it)); - for(std::vector::iterator it = adt->_models.begin(); it != adt->_models.end(); it++) - this->_models.push_back(_PathToFileName(*it)); - for(std::vector::iterator it = adt->_wmos.begin(); it != adt->_wmos.end(); it++) - this->_wmos.push_back(_PathToFileName(*it)); // import the height map for(uint32 ch=0; ch_chunks[ch].hdr.nLayers; ly++) { uint32 texoffs = adt->_chunks[ch].layer[ly].textureId; - _chunks[ch].texlayer.push_back(std::string("data/texture/") + NormalizeFilename(std::string(adt->_textures[texoffs])).c_str()); + char fname[255]; + MemoryDataHolder::MakeTextureFilename(fname,adt->_textures[texoffs]); + _chunks[ch].texlayer.push_back(fname); } memcpy(_chunks[ch].alphamap, adt->_chunks[ch].alphamap, adt->_chunks[ch].hdr.sizeAlpha - 8); @@ -90,7 +86,9 @@ void MapTile::ImportFromADT(ADTFile *adt) d.flags = mddf.flags; d.uniqueid = mddf.uniqueid; d.MPQpath = adt->_models[mddf.id]; - d.model = std::string("./data/model/") + NormalizeFilename(_PathToFileName(adt->_models[mddf.id])); + char fname[255]; + MemoryDataHolder::MakeModelFilename(fname,adt->_models[mddf.id]); + d.model = fname; // this .mdx -> .m2 transformation is annoying >.< - replace "mdx" and end of string with "m2" // d.model = d.model.substr(0, d.model.length() - 3) + "m2"; // 3.1.3 - no more .mdx in ADT @@ -115,7 +113,9 @@ void MapTile::ImportFromADT(ADTFile *adt) wmo.flags = modf.flags; wmo.uniqueid = modf.uniqueid; wmo.MPQpath = adt->_wmos[modf.id]; - wmo.model = std::string("./data/wmo/") + NormalizeFilename(_PathToFileName(adt->_wmos[modf.id])); + char fname[255]; + MemoryDataHolder::MakeWMOFilename(fname,adt->_wmos[modf.id]); + wmo.model = fname; _wmo_data.push_back(wmo); }