* Fixed bug in ADT file loading
This commit is contained in:
parent
43a40c3cb0
commit
a281e95d0d
@ -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)
|
||||
{
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<ADTMapChunkHeader>();
|
||||
uint8 _cc2[5];
|
||||
uint8 *mfcc = &_cc2[0];
|
||||
mfcc[4]=0;
|
||||
uint32 msize;
|
||||
bool mcal_compressed = false;
|
||||
while(buf.rpos()<buf.size())
|
||||
while(buf.rpos()<endpos)
|
||||
{
|
||||
buf.read(mfcc,4); flipcc(mfcc);
|
||||
buf.read((uint8*)&msize,4);
|
||||
@ -363,6 +364,7 @@ bool ADTFile::LoadMem(ByteBuffer& buf)
|
||||
|
||||
}
|
||||
mcnkid++;
|
||||
buf.rpos(endpos);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "common.h"
|
||||
#include "MapTile.h"
|
||||
#include "log.h"
|
||||
#include "MemoryDataHolder.h"
|
||||
|
||||
MapTile::MapTile()
|
||||
{
|
||||
@ -12,13 +13,6 @@ MapTile::~MapTile()
|
||||
|
||||
void MapTile::ImportFromADT(ADTFile *adt)
|
||||
{
|
||||
// strip the path name from the dependency files, just store the plain filename
|
||||
for(std::vector<std::string>::iterator it = adt->_textures.begin(); it != adt->_textures.end(); it++)
|
||||
this->_textures.push_back(_PathToFileName(*it));
|
||||
for(std::vector<std::string>::iterator it = adt->_models.begin(); it != adt->_models.end(); it++)
|
||||
this->_models.push_back(_PathToFileName(*it));
|
||||
for(std::vector<std::string>::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_PER_TILE; ch++)
|
||||
@ -53,7 +47,9 @@ void MapTile::ImportFromADT(ADTFile *adt)
|
||||
for(uint32 ly = 0; ly < adt->_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);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user