[7909] Applied coding style. (cherry picked from commit ed7e72975f4d4f95f5c429f1af6a2c021adfd5a1)

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
tomrus88 2009-05-28 18:44:51 +04:00 committed by VladimirMangos
parent 84464e5f3f
commit f84fdc6757
16 changed files with 1433 additions and 1467 deletions

View file

@ -1,6 +1,5 @@
#include "adtfile.h"
char * GetPlainName(char * FileName)
{
char * szTemp;
@ -12,159 +11,149 @@ char * GetPlainName(char * FileName)
void fixnamen(char *name, size_t len)
{
for (size_t i=0; i<len-3; i++) {
if (i>0 && name[i]>='A' && name[i]<='Z' && isalpha(name[i-1]))
{
name[i] |= 0x20;
} else if ((i==0 || !isalpha(name[i-1])) && name[i]>='a' && name[i]<='z')
{
name[i] &= ~0x20;
}
}
for (size_t i=0; i<len-3; i++)
{
if (i>0 && name[i]>='A' && name[i]<='Z' && isalpha(name[i-1]))
{
name[i] |= 0x20;
} else if ((i==0 || !isalpha(name[i-1])) && name[i]>='a' && name[i]<='z')
{
name[i] &= ~0x20;
}
}
}
void fixname2(char *name, size_t len)
{
for (size_t i=0; i<len-3; i++)
{
if(name[i] == ' ')
name[i] = '_';
}
for (size_t i=0; i<len-3; i++)
{
if(name[i] == ' ')
name[i] = '_';
}
}
ADTFile::ADTFile(char* filename): ADT(filename)
{
Adtfilename.append(filename);
Adtfilename.append(filename);
}
bool ADTFile::init(char *map_id)
{
if(ADT.isEof ())
return false;
if(ADT.isEof ())
return false;
size_t size;
size_t size;
string xMap;
string yMap;
string xMap;
string yMap;
Adtfilename.erase(Adtfilename.find(".adt"),4);
string TempMapNumber;
TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6);
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());
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;
const char dirname[] = "buildings\\dir";
FILE *dirfile;
dirfile = fopen(dirname, "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n");
return false;
}
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;
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;
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);
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);
fixnamen(s,strlen(s));
fixname2(s,strlen(s));
p=p+strlen(p)+1;
WmoInstansName[q++] = s;
}
delete[] buf;
}
}
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++)
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;
delete[] ModelInstansName;
}
}
else if (!strcmp(fourcc,"MODF"))
@ -172,7 +161,7 @@ bool ADTFile::init(char *map_id)
if (size)
{
nWMO = (int)size / 64;
for (int i=0; i<nWMO; i++)
for (int i=0; i<nWMO; ++i)
{
int id;
ADT.read(&id, 4);
@ -183,45 +172,43 @@ bool ADTFile::init(char *map_id)
}
//======================
#if 0
else if (!strcmp(fourcc,"MDDF"))
{
if (size)
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)
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);
}
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();
ADT.seek(nextpos);
}
ADT.close();
fclose(dirfile);
return true;
return true;
}
ADTFile::~ADTFile()
{
ADT.close();
ADT.close();
}

View file

@ -17,108 +17,111 @@ typedef unsigned int uint32;
class Liquid;
typedef struct {
float x;
float y;
float z;
typedef struct
{
float x;
float y;
float z;
}svec;
typedef struct {
double x;
double y;
double z;
typedef struct
{
double x;
double y;
double z;
}vec;
typedef struct{
vec v[3];
typedef struc
{
vec v[3];
}triangle;
typedef struct{
float v9[16*8+1][16*8+1];
float v8[16*8][16*8];
typedef struct
{
float v9[16*8+1][16*8+1];
float v8[16*8][16*8];
}Cell;
typedef struct{
double v9[9][9];
double v8[8][8];
uint16 area_id;
//Liquid *lq;
float waterlevel[9][9];
uint8 flag;
typedef struct
{
double v9[9][9];
double v8[8][8];
uint16 area_id;
//Liquid *lq;
float waterlevel[9][9];
uint8 flag;
}chunk;
typedef struct
{
chunk ch[16][16];
chunk ch[16][16];
}mcell;
struct MapChunkHeader {
uint32 flags;
uint32 ix;
uint32 iy;
uint32 nLayers;
uint32 nDoodadRefs;
uint32 ofsHeight;
uint32 ofsNormal;
uint32 ofsLayer;
uint32 ofsRefs;
uint32 ofsAlpha;
uint32 sizeAlpha;
uint32 ofsShadow;
uint32 sizeShadow;
uint32 areaid;
uint32 nMapObjRefs;
uint32 holes;
uint16 s1;
uint16 s2;
uint32 d1;
uint32 d2;
uint32 d3;
uint32 predTex;
uint32 nEffectDoodad;
uint32 ofsSndEmitters;
uint32 nSndEmitters;
uint32 ofsLiquid;
uint32 sizeLiquid;
float zpos;
float xpos;
float ypos;
uint32 textureId;
uint32 props;
uint32 effectId;
struct MapChunkHeader
{
uint32 flags;
uint32 ix;
uint32 iy;
uint32 nLayers;
uint32 nDoodadRefs;
uint32 ofsHeight;
uint32 ofsNormal;
uint32 ofsLayer;
uint32 ofsRefs;
uint32 ofsAlpha;
uint32 sizeAlpha;
uint32 ofsShadow;
uint32 sizeShadow;
uint32 areaid;
uint32 nMapObjRefs;
uint32 holes;
uint16 s1;
uint16 s2;
uint32 d1;
uint32 d2;
uint32 d3;
uint32 predTex;
uint32 nEffectDoodad;
uint32 ofsSndEmitters;
uint32 nSndEmitters;
uint32 ofsLiquid;
uint32 sizeLiquid;
float zpos;
float xpos;
float ypos;
uint32 textureId;
uint32 props;
uint32 effectId;
};
class ADTFile
{
public:
ADTFile(char* filename);
~ADTFile();
int nWMO;
int nMDX;
string* WmoInstansName;
string* ModelInstansName;
bool init(char *map_id);
//void LoadMapChunks();
ADTFile(char* filename);
~ADTFile();
int nWMO;
int nMDX;
string* WmoInstansName;
string* ModelInstansName;
bool init(char *map_id);
//void LoadMapChunks();
//uint32 wmo_count;
//uint32 wmo_count;
/*
const mcell& Getmcell() const
{
return Mcell;
}
const mcell& Getmcell() const
{
return Mcell;
}
*/
private:
//size_t mcnk_offsets[256], mcnk_sizes[256];
MPQFile ADT;
//mcell Mcell;
string Adtfilename;
//size_t mcnk_offsets[256], mcnk_sizes[256];
MPQFile ADT;
//mcell Mcell;
string Adtfilename;
};
void fixnamen(char *name, size_t len);
//void fixMapNamen(char *name, size_t len);
#endif

View file

@ -5,71 +5,71 @@
DBCFile::DBCFile(const std::string &filename) : filename(filename)
{
data = NULL;
data = NULL;
}
bool DBCFile::open()
{
MPQFile f(filename.c_str());
MPQFile f(filename.c_str());
// Need some error checking, otherwise an unhandled exception error occurs
// if people screw with the data path.
if (f.isEof() == true)
return false;
// Need some error checking, otherwise an unhandled exception error occurs
// if people screw with the data path.
if (f.isEof() == true)
return false;
unsigned char header[4];
unsigned int na,nb,es,ss;
unsigned char header[4];
unsigned int na,nb,es,ss;
f.read(header,4); // File Header
f.read(header,4); // File Header
if (header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3] != 'C') {
if (header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3] != 'C')
{
f.close();
data = NULL;
printf("Critical Error: An error occured while trying to read the DBCFile %s.", filename.c_str());
return false;
}
f.close();
data = NULL;
printf("Critical Error: An error occured while trying to read the DBCFile %s.", filename.c_str());
return false;
}
//assert(header[0]=='W' && header[1]=='D' && header[2]=='B' && header[3] == 'C');
//assert(header[0]=='W' && header[1]=='D' && header[2]=='B' && header[3] == 'C');
f.read(&na,4); // Number of records
f.read(&nb,4); // Number of fields
f.read(&es,4); // Size of a record
f.read(&ss,4); // String size
f.read(&na,4); // Number of records
f.read(&nb,4); // Number of fields
f.read(&es,4); // Size of a record
f.read(&ss,4); // String size
recordSize = es;
recordCount = na;
fieldCount = nb;
stringSize = ss;
//assert(fieldCount*4 == recordSize);
assert(fieldCount*4 >= recordSize);
recordSize = es;
recordCount = na;
fieldCount = nb;
stringSize = ss;
//assert(fieldCount*4 == recordSize);
assert(fieldCount*4 >= recordSize);
data = new unsigned char[recordSize*recordCount+stringSize];
stringTable = data + recordSize*recordCount;
f.read(data,recordSize*recordCount+stringSize);
f.close();
return true;
data = new unsigned char[recordSize*recordCount+stringSize];
stringTable = data + recordSize*recordCount;
f.read(data,recordSize*recordCount+stringSize);
f.close();
return true;
}
DBCFile::~DBCFile()
{
delete [] data;
delete [] data;
}
DBCFile::Record DBCFile::getRecord(size_t id)
{
assert(data);
return Record(*this, data + id*recordSize);
assert(data);
return Record(*this, data + id*recordSize);
}
DBCFile::Iterator DBCFile::begin()
{
assert(data);
return Iterator(*this, data);
}
DBCFile::Iterator DBCFile::end()
{
assert(data);
return Iterator(*this, stringTable);
assert(data);
return Iterator(*this, data);
}
DBCFile::Iterator DBCFile::end()
{
assert(data);
return Iterator(*this, stringTable);
}

View file

@ -9,131 +9,131 @@
class DBCFile
{
public:
DBCFile(const std::string &filename);
~DBCFile();
DBCFile(const std::string &filename);
~DBCFile();
// Open database. It must be openened before it can be used.
bool open();
// Open database. It must be openened before it can be used.
bool open();
// TODO: Add a close function?
// TODO: Add a close function?
// Database exceptions
class Exception
{
public:
Exception(const std::string &message): message(message)
{ }
virtual ~Exception()
{ }
const std::string &getMessage() {return message;}
private:
std::string message;
};
// Database exceptions
class Exception
{
public:
Exception(const std::string &message): message(message)
{ }
virtual ~Exception()
{ }
const std::string &getMessage() {return message;}
private:
std::string message;
};
//
class NotFound: public Exception
{
public:
NotFound(): Exception("Key was not found")
{ }
};
//
class NotFound: public Exception
{
public:
NotFound(): Exception("Key was not found")
{ }
};
// Iteration over database
class Iterator;
class Record
{
public:
Record& operator= (const Record& r)
{
// Iteration over database
class Iterator;
class Record
{
public:
Record& operator= (const Record& r)
{
file = r.file;
offset = r.offset;
return *this;
}
float getFloat(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<float*>(offset+field*4);
}
unsigned int getUInt(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<unsigned int*>(offset+(field*4));
}
int getInt(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<int*>(offset+field*4);
}
unsigned char getByte(size_t ofs) const
{
assert(ofs < file.recordSize);
return *reinterpret_cast<unsigned char*>(offset+ofs);
}
const char *getString(size_t field) const
{
assert(field < file.fieldCount);
size_t stringOffset = getUInt(field);
assert(stringOffset < file.stringSize);
//char * tmp = (char*)file.stringTable + stringOffset;
//unsigned char * tmp2 = file.stringTable + stringOffset;
return reinterpret_cast<char*>(file.stringTable + stringOffset);
}
private:
Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
unsigned char *offset;
DBCFile &file;
offset = r.offset;
return *this;
}
float getFloat(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<float*>(offset+field*4);
}
unsigned int getUInt(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<unsigned int*>(offset+(field*4));
}
int getInt(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<int*>(offset+field*4);
}
unsigned char getByte(size_t ofs) const
{
assert(ofs < file.recordSize);
return *reinterpret_cast<unsigned char*>(offset+ofs);
}
const char *getString(size_t field) const
{
assert(field < file.fieldCount);
size_t stringOffset = getUInt(field);
assert(stringOffset < file.stringSize);
//char * tmp = (char*)file.stringTable + stringOffset;
//unsigned char * tmp2 = file.stringTable + stringOffset;
return reinterpret_cast<char*>(file.stringTable + stringOffset);
}
private:
Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
unsigned char *offset;
DBCFile &file;
friend class DBCFile;
friend class Iterator;
};
friend class DBCFile;
friend class Iterator;
};
/* Iterator that iterates over records */
class Iterator
{
public:
Iterator(DBCFile &file, unsigned char *offset):
record(file, offset) {}
/// Advance (prefix only)
Iterator & operator++() {
record.offset += record.file.recordSize;
return *this;
}
/// Return address of current instance
Record const & operator*() const { return record; }
const Record* operator->() const {
return &record;
}
/// Comparison
bool operator==(const Iterator &b) const
{
return record.offset == b.record.offset;
}
bool operator!=(const Iterator &b) const
{
return record.offset != b.record.offset;
}
private:
Record record;
};
/* Iterator that iterates over records */
class Iterator
{
public:
Iterator(DBCFile &file, unsigned char *offset):
record(file, offset) {}
/// Advance (prefix only)
Iterator & operator++() {
record.offset += record.file.recordSize;
return *this;
}
/// Return address of current instance
Record const & operator*() const { return record; }
const Record* operator->() const {
return &record;
}
/// Comparison
bool operator==(const Iterator &b) const
{
return record.offset == b.record.offset;
}
bool operator!=(const Iterator &b) const
{
return record.offset != b.record.offset;
}
private:
Record record;
};
// Get record by id
Record getRecord(size_t id);
/// Get begin iterator over records
Iterator begin();
/// Get begin iterator over records
Iterator end();
/// Trivial
size_t getRecordCount() const { return recordCount;}
size_t getFieldCount() const { return fieldCount; }
// Get record by id
Record getRecord(size_t id);
/// Get begin iterator over records
Iterator begin();
/// Get begin iterator over records
Iterator end();
/// Trivial
size_t getRecordCount() const { return recordCount;}
size_t getFieldCount() const { return fieldCount; }
private:
std::string filename;
size_t recordSize;
size_t recordCount;
size_t fieldCount;
size_t stringSize;
unsigned char *data;
unsigned char *stringTable;
std::string filename;
size_t recordSize;
size_t recordCount;
size_t fieldCount;
size_t stringSize;
unsigned char *data;
unsigned char *stringTable;
};
#endif

View file

@ -23,17 +23,17 @@ bool Model::open()
if(header.nBoundingTriangles > 0)
{
f.seek(0);
f.seekRelative(header.ofsBoundingVertices);
vertices = new Vec3D[header.nBoundingVertices];
f.read(vertices,header.nBoundingVertices*12);
f.seekRelative(header.ofsBoundingVertices);
vertices = new Vec3D[header.nBoundingVertices];
f.read(vertices,header.nBoundingVertices*12);
for (uint32 i=0; i<header.nBoundingVertices; i++)
{
vertices[i] = fixCoordSystem(vertices[i]);
}
f.seek(0);
f.seekRelative(header.ofsBoundingTriangles);
indices = new uint16[header.nBoundingTriangles];
f.read(indices,header.nBoundingTriangles*2);
f.seekRelative(header.ofsBoundingTriangles);
indices = new uint16[header.nBoundingTriangles];
f.read(indices,header.nBoundingTriangles*2);
f.close();
}
else
@ -45,10 +45,8 @@ bool Model::open()
return true;
}
bool Model::ConvertToVMAPModel(char * outfilename)
{
int N[] = {0x00000000};
FILE * output=fopen(outfilename,"wb");
if(!output)
@ -133,18 +131,17 @@ ModelInstance::ModelInstance(MPQFile &f,const char* ModelInstName,const char*Map
sprintf(tempname, ".\\buildings\\%s", ModelInstName);
FILE *input;
input = fopen(tempname, "r+b");
if(!input)
{
return;
}
fseek(input, 8, SEEK_SET); // get the correct no of vertices
int nVertices;
fread(&nVertices, sizeof (int), 1, input);
fclose(input);
int nVertices;
fread(&nVertices, sizeof (int), 1, input);
fclose(input);
if(nVertices == 0)
{
return;
}
if(pDirfile)
{
@ -153,7 +150,6 @@ ModelInstance::ModelInstance(MPQFile &f,const char* ModelInstName,const char*Map
int realx2 = (int) ((float) pos.x / 533.333333f);
int realy2 = (int) ((float) pos.z / 533.333333f);
fprintf(pDirfile,"%s/%s %f,%f,%f_%f,%f,%f %f %d %d %d,%d %d\n",
MapName,
ModelInstName,

View file

@ -11,49 +11,40 @@ class WMOInstance;
Vec3D fixCoordSystem(Vec3D v);
class Model
{
public:
ModelHeader header;
uint32 offsBB_vertices, offsBB_indices;
Vec3D *BB_vertices, *vertices;
uint16 *BB_indices, *indices;
size_t nIndices;
ModelHeader header;
bool open();
bool ConvertToVMAPModel(char * outfilename);
public:
bool ok;
uint32 offsBB_vertices, offsBB_indices;
Vec3D *BB_vertices, *vertices;
uint16 *BB_indices, *indices;
size_t nIndices;
bool open();
bool ConvertToVMAPModel(char * outfilename);
public:
bool ok;
Model(std::string &filename);
~Model();
Model(std::string &filename);
~Model();
private:
std::string filename;
char outfilename;
std::string filename;
char outfilename;
};
class ModelInstance
{
public:
Model *model;
Model *model;
int id;
Vec3D pos, rot;
unsigned int d1, scale;
float w,sc;
int id;
Vec3D pos, rot;
unsigned int d1, scale;
float w,sc;
ModelInstance() {}
ModelInstance(MPQFile &f,const char* ModelInstName,const char*MapName, FILE *pDirfile);
ModelInstance() {}
ModelInstance(MPQFile &f,const char* ModelInstName,const char*MapName, FILE *pDirfile);
};

View file

@ -10,73 +10,72 @@ typedef int int32;
#pragma pack(push,1)
struct ModelHeader {
char id[4];
uint8 version[4];
uint32 nameLength;
uint32 nameOfs;
uint32 type;
uint32 nGlobalSequences;
uint32 ofsGlobalSequences;
uint32 nAnimations;
uint32 ofsAnimations;
struct ModelHeader
{
char id[4];
uint8 version[4];
uint32 nameLength;
uint32 nameOfs;
uint32 type;
uint32 nGlobalSequences;
uint32 ofsGlobalSequences;
uint32 nAnimations;
uint32 ofsAnimations;
uint32 nAnimationLookup;
uint32 ofsAnimationLookup;
uint32 nBones;
uint32 ofsBones;
uint32 nKeyBoneLookup;
uint32 ofsKeyBoneLookup;
uint32 nVertices;
uint32 ofsVertices;
uint32 nViews;
uint32 nColors;
uint32 ofsColors;
uint32 nTextures;
uint32 ofsTextures;
uint32 nTransparency;
uint32 ofsTransparency;
uint32 nTextureanimations;
uint32 ofsTextureanimations;
uint32 nTexReplace;
uint32 ofsTexReplace;
uint32 nRenderFlags;
uint32 ofsRenderFlags;
uint32 nBoneLookupTable;
uint32 ofsBoneLookupTable;
uint32 nTexLookup;
uint32 ofsTexLookup;
uint32 nTexUnits;
uint32 ofsTexUnits;
uint32 nTransLookup;
uint32 ofsTransLookup;
uint32 nTexAnimLookup;
uint32 ofsTexAnimLookup;
float floats[14];
uint32 nBoundingTriangles;
uint32 ofsBoundingTriangles;
uint32 nBoundingVertices;
uint32 ofsBoundingVertices;
uint32 nBoundingNormals;
uint32 ofsBoundingNormals;
uint32 nAttachments;
uint32 ofsAttachments;
uint32 nAttachLookup;
uint32 ofsAttachLookup;
uint32 nAttachments_2;
uint32 ofsAttachments_2;
uint32 nLights;
uint32 ofsLights;
uint32 nCameras;
uint32 ofsCameras;
uint32 nCameraLookup;
uint32 ofsCameraLookup;
uint32 nRibbonEmitters;
uint32 ofsRibbonEmitters;
uint32 nParticleEmitters;
uint32 ofsParticleEmitters;
uint32 nKeyBoneLookup;
uint32 ofsKeyBoneLookup;
uint32 nVertices;
uint32 ofsVertices;
uint32 nViews;
uint32 nColors;
uint32 ofsColors;
uint32 nTextures;
uint32 ofsTextures;
uint32 nTransparency;
uint32 ofsTransparency;
uint32 nTextureanimations;
uint32 ofsTextureanimations;
uint32 nTexReplace;
uint32 ofsTexReplace;
uint32 nRenderFlags;
uint32 ofsRenderFlags;
uint32 nBoneLookupTable;
uint32 ofsBoneLookupTable;
uint32 nTexLookup;
uint32 ofsTexLookup;
uint32 nTexUnits;
uint32 ofsTexUnits;
uint32 nTransLookup;
uint32 ofsTransLookup;
uint32 nTexAnimLookup;
uint32 ofsTexAnimLookup;
float floats[14];
uint32 nBoundingTriangles;
uint32 ofsBoundingTriangles;
uint32 nBoundingVertices;
uint32 ofsBoundingVertices;
uint32 nBoundingNormals;
uint32 ofsBoundingNormals;
uint32 nAttachments;
uint32 ofsAttachments;
uint32 nAttachLookup;
uint32 ofsAttachLookup;
uint32 nAttachments_2;
uint32 ofsAttachments_2;
uint32 nLights;
uint32 ofsLights;
uint32 nCameras;
uint32 ofsCameras;
uint32 nCameraLookup;
uint32 ofsCameraLookup;
uint32 nRibbonEmitters;
uint32 ofsRibbonEmitters;
uint32 nParticleEmitters;
uint32 ofsParticleEmitters;
};
#pragma pack(pop)
#endif

View file

@ -5,88 +5,84 @@
typedef std::vector<MPQArchive*> ArchiveSet;
ArchiveSet gOpenArchives;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MPQArchive::MPQArchive(const char* filename)
{
BOOL succ = SFileOpenArchive(filename, 0, 0,&hMPQ);
if (succ)
{
MPQArchive*ar = (MPQArchive*)(hMPQ);
printf("Opening %s\n", filename);
gOpenArchives.push_back(ar);
BOOL succ = SFileOpenArchive(filename, 0, 0,&hMPQ);
if (succ)
{
MPQArchive*ar = (MPQArchive*)(hMPQ);
printf("Opening %s\n", filename);
gOpenArchives.push_back(ar);
succ = true;
}
else
{
printf("Error!!!Not open archive %s\n", filename);
}
}
else
{
printf("Error!!!Not open archive %s\n", filename);
}
}
void MPQArchive::close()
{
SFileCloseArchive(hMPQ);
SFileCloseArchive(hMPQ);
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MPQFile::MPQFile(const char* filename):
eof(false),
buffer(0),
pointer(0),
size(0)
eof(false),
buffer(0),
pointer(0),
size(0)
{
for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
{
for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
{
HANDLE hFile = "";
MPQArchive*(hMPQ) = *i;
BOOL succ = SFileOpenFileEx(hMPQ,filename,0, &hFile);
if (succ)
{
DWORD s = SFileGetFileSize(hFile, 0);
if (!s)
{
eof = true;
buffer = 0;
return;
}
size = (size_t)s;
buffer = new char[s];
SFileReadFile(hFile, buffer, s, 0, 0);
SFileCloseFile(hFile);
HANDLE hFile = "";
MPQArchive*(hMPQ) = *i;
BOOL succ = SFileOpenFileEx(hMPQ,filename,0, &hFile);
if (succ)
{
DWORD s = SFileGetFileSize(hFile, 0);
if (!s)
{
eof = true;
buffer = 0;
return;
}
size = (size_t)s;
buffer = new char[s];
SFileReadFile(hFile, buffer, s, 0, 0);
SFileCloseFile(hFile);
eof = false;
return;
}
}
eof = true;
buffer = 0;
eof = false;
return;
}
}
eof = true;
buffer = 0;
}
MPQFile::~MPQFile()
{
close();
close();
}
size_t MPQFile::read(void* dest, size_t bytes)
{
if (eof)
return 0;
if (eof)
return 0;
size_t rpos = pointer + bytes;
if (rpos > size)
{
bytes = size - pointer;
eof = true;
}
size_t rpos = pointer + bytes;
if (rpos > size)
{
bytes = size - pointer;
eof = true;
}
memcpy(dest, &(buffer[pointer]), bytes);
memcpy(dest, &(buffer[pointer]), bytes);
pointer = rpos;
pointer = rpos;
return bytes;
return bytes;
}
bool MPQFile::isEof()
@ -96,41 +92,40 @@ bool MPQFile::isEof()
void MPQFile::seek(int offset)
{
pointer = offset;
eof = (pointer >= size);
pointer = offset;
eof = (pointer >= size);
}
void MPQFile::seekRelative(int offset)
{
pointer += offset;
eof = (pointer >= size);
pointer += offset;
eof = (pointer >= size);
}
void MPQFile::close()
{
if (buffer)
delete[] buffer;
buffer = 0;
eof = true;
if (buffer)
delete[] buffer;
buffer = 0;
eof = true;
}
size_t MPQFile::getSize()
{
return size;
return size;
}
size_t MPQFile::getPos()
{
return pointer;
return pointer;
}
char* MPQFile::getBuffer()
{
return buffer;
return buffer;
}
char* MPQFile::getPointer()
{
return buffer + pointer;
return buffer + pointer;
}

View file

@ -15,55 +15,50 @@ using namespace std;
typedef unsigned int uint32;
class MPQArchive
{
public:
HANDLE hMPQ;
MPQArchive(const char* filename);
void close();
HANDLE hMPQ;
MPQArchive(const char* filename);
void close();
};
class MPQFile
{
HANDLE hFile;
HANDLE hFile;
HANDLE hMPQ;
bool eof;
char *buffer;
size_t pointer,
size;
bool eof;
char *buffer;
size_t pointer,
size;
// disable copying
//MPQFile(const MPQFile &f) {}
//void operator=(const MPQFile &f) {}
// disable copying
//MPQFile(const MPQFile &f) {}
//void operator=(const MPQFile &f) {}
public:
MPQFile(const char* filename);
~MPQFile();
size_t read(void* dest, size_t bytes);
size_t getSize();
size_t getPos();
char* getBuffer();
char* getPointer();
bool isEof();
void seek(int offset);
void seekRelative(int offset);
void close();
MPQFile(const char* filename);
~MPQFile();
size_t read(void* dest, size_t bytes);
size_t getSize();
size_t getPos();
char* getBuffer();
char* getPointer();
bool isEof();
void seek(int offset);
void seekRelative(int offset);
void close();
};
inline void flipcc(char *fcc)
{
char t;
t=fcc[0];
fcc[0]=fcc[3];
fcc[3]=t;
t=fcc[1];
fcc[1]=fcc[2];
fcc[2]=t;
char t;
t=fcc[0];
fcc[0]=fcc[3];
fcc[3]=t;
t=fcc[1];
fcc[1]=fcc[2];
fcc[2]=t;
}
#endif

View file

@ -4,227 +4,221 @@
#include <iostream>
#include <cmath>
class Vec3D {
class Vec3D
{
public:
float x,y,z;
float x,y,z;
Vec3D(float x0 = 0.0f, float y0 = 0.0f, float z0 = 0.0f) : x(x0), y(y0), z(z0) {}
Vec3D(float x0 = 0.0f, float y0 = 0.0f, float z0 = 0.0f) : x(x0), y(y0), z(z0) {}
Vec3D(const Vec3D& v) : x(v.x), y(v.y), z(v.z) {}
Vec3D(const Vec3D& v) : x(v.x), y(v.y), z(v.z) {}
Vec3D& operator= (const Vec3D &v) {
Vec3D& operator= (const Vec3D &v) {
x = v.x;
y = v.y;
z = v.z;
return *this;
}
y = v.y;
z = v.z;
return *this;
}
Vec3D operator+ (const Vec3D &v) const
{
Vec3D r(x+v.x,y+v.y,z+v.z);
Vec3D operator+ (const Vec3D &v) const
{
Vec3D r(x+v.x,y+v.y,z+v.z);
return r;
}
}
Vec3D operator- (const Vec3D &v) const
{
Vec3D r(x-v.x,y-v.y,z-v.z);
return r;
}
Vec3D operator- (const Vec3D &v) const
{
Vec3D r(x-v.x,y-v.y,z-v.z);
return r;
}
float operator* (const Vec3D &v) const
{
float operator* (const Vec3D &v) const
{
return x*v.x + y*v.y + z*v.z;
}
}
Vec3D operator* (float d) const
{
Vec3D r(x*d,y*d,z*d);
Vec3D operator* (float d) const
{
Vec3D r(x*d,y*d,z*d);
return r;
}
}
friend Vec3D operator* (float d, const Vec3D& v)
{
return v * d;
}
friend Vec3D operator* (float d, const Vec3D& v)
{
return v * d;
}
Vec3D operator% (const Vec3D &v) const
{
Vec3D operator% (const Vec3D &v) const
{
Vec3D r(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
return r;
}
return r;
}
Vec3D& operator+= (const Vec3D &v)
{
x += v.x;
y += v.y;
z += v.z;
return *this;
}
Vec3D& operator+= (const Vec3D &v)
{
x += v.x;
y += v.y;
z += v.z;
return *this;
}
Vec3D& operator-= (const Vec3D &v)
{
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}
Vec3D& operator-= (const Vec3D &v)
{
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}
Vec3D& operator*= (float d)
{
x *= d;
y *= d;
z *= d;
return *this;
}
Vec3D& operator*= (float d)
{
x *= d;
y *= d;
z *= d;
return *this;
}
float lengthSquared() const
{
return x*x+y*y+z*z;
}
float lengthSquared() const
{
return x*x+y*y+z*z;
}
float length() const
{
float length() const
{
return sqrt(x*x+y*y+z*z);
}
}
Vec3D& normalize()
{
this->operator*= (1.0f/length());
return *this;
}
Vec3D& normalize()
{
this->operator*= (1.0f/length());
return *this;
}
Vec3D operator~ () const
{
Vec3D r(*this);
Vec3D operator~ () const
{
Vec3D r(*this);
r.normalize();
return r;
}
return r;
}
friend std::istream& operator>>(std::istream& in, Vec3D& v)
{
in >> v.x >> v.y >> v.z;
return in;
}
operator float*()
{
return (float*)this;
}
friend std::istream& operator>>(std::istream& in, Vec3D& v)
{
in >> v.x >> v.y >> v.z;
return in;
}
operator float*()
{
return (float*)this;
}
};
class Vec2D {
class Vec2D
{
public:
float x,y;
float x,y;
Vec2D(float x0 = 0.0f, float y0 = 0.0f) : x(x0), y(y0) {}
Vec2D(float x0 = 0.0f, float y0 = 0.0f) : x(x0), y(y0) {}
Vec2D(const Vec2D& v) : x(v.x), y(v.y) {}
Vec2D(const Vec2D& v) : x(v.x), y(v.y) {}
Vec2D& operator= (const Vec2D &v) {
Vec2D& operator= (const Vec2D &v) {
x = v.x;
y = v.y;
return *this;
}
y = v.y;
return *this;
}
Vec2D operator+ (const Vec2D &v) const
{
Vec2D r(x+v.x,y+v.y);
Vec2D operator+ (const Vec2D &v) const
{
Vec2D r(x+v.x,y+v.y);
return r;
}
}
Vec2D operator- (const Vec2D &v) const
{
Vec2D r(x-v.x,y-v.y);
return r;
}
Vec2D operator- (const Vec2D &v) const
{
Vec2D r(x-v.x,y-v.y);
return r;
}
float operator* (const Vec2D &v) const
{
float operator* (const Vec2D &v) const
{
return x*v.x + y*v.y;
}
}
Vec2D operator* (float d) const
{
Vec2D r(x*d,y*d);
Vec2D operator* (float d) const
{
Vec2D r(x*d,y*d);
return r;
}
}
friend Vec2D operator* (float d, const Vec2D& v)
{
return v * d;
}
friend Vec2D operator* (float d, const Vec2D& v)
{
return v * d;
}
Vec2D& operator+= (const Vec2D &v)
{
x += v.x;
y += v.y;
return *this;
}
Vec2D& operator+= (const Vec2D &v)
{
x += v.x;
y += v.y;
return *this;
}
Vec2D& operator-= (const Vec2D &v)
{
x -= v.x;
y -= v.y;
return *this;
}
Vec2D& operator-= (const Vec2D &v)
{
x -= v.x;
y -= v.y;
return *this;
}
Vec2D& operator*= (float d)
{
x *= d;
y *= d;
return *this;
}
Vec2D& operator*= (float d)
{
x *= d;
y *= d;
return *this;
}
float lengthSquared() const
{
return x*x+y*y;
}
float lengthSquared() const
{
return x*x+y*y;
}
float length() const
{
float length() const
{
return sqrt(x*x+y*y);
}
}
Vec2D& normalize()
{
this->operator*= (1.0f/length());
return *this;
}
Vec2D& normalize()
{
this->operator*= (1.0f/length());
return *this;
}
Vec2D operator~ () const
{
Vec2D r(*this);
Vec2D operator~ () const
{
Vec2D r(*this);
r.normalize();
return r;
}
return r;
}
friend std::istream& operator>>(std::istream& in, Vec2D& v)
{
friend std::istream& operator>>(std::istream& in, Vec2D& v)
{
in >> v.x >> v.y;
return in;
}
operator float*()
{
return (float*)this;
}
return in;
}
operator float*()
{
return (float*)this;
}
};
inline void rotate(float x0, float y0, float *x, float *y, float angle)
{
float xa = *x - x0, ya = *y - y0;
*x = xa*cosf(angle) - ya*sinf(angle) + x0;
*y = xa*sinf(angle) + ya*cosf(angle) + y0;
float xa = *x - x0, ya = *y - y0;
*x = xa*cosf(angle) - ya*sinf(angle) + x0;
*y = xa*sinf(angle) + ya*cosf(angle) + y0;
}
#endif

View file

@ -86,7 +86,7 @@ static const char * GetPlainName(const char * szFileName)
szFileName = szTemp + 1;
return szFileName;
}
//------------------------------------------------------------------------------
static void ShowProcessedFile(const char * szFileName)
{
char szLine[80];
@ -101,11 +101,8 @@ static void ShowProcessedFile(const char * szFileName)
printf("\r%s\n", szLine);
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------
int ExtractWmo(const std::vector<std::string>& pArchiveNames)
{
char* szListFile = "";
char szLocalFile[MAX_PATH] = "";
HANDLE hMpq = "";
@ -118,9 +115,8 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
szListFile = NULL;
//char tmp[1024];
//for (size_t i=0; i<4; i++)
for (size_t i=0; i<pArchiveNames.size(); i++)
for (size_t i=0; i<pArchiveNames.size(); ++i)
{
//sprintf(tmp,"%s\\%s", input_path, ParsArchiveNames[i]);
//if(!SFileOpenArchive(tmp, 0, 0, &hMpq))
if(!SFileOpenArchive(pArchiveNames[i].c_str(), 0, 0, &hMpq))
@ -149,7 +145,7 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
{
char cpy[4];
strncpy((char*)cpy,rchr,4);
for (int i=0;i<4;i++)
for (int i=0;i<4; ++i)
{
int m = cpy[i];
if(isdigit(m))
@ -167,12 +163,12 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
bResult = SFileFindNextFile(hFind, &wf);
continue;
}
FILE *output=fopen(szLocalFile,"wb");
FILE *output=fopen(szLocalFile,"wb");
froot->ConvertToVMAPRootWmo(output);
int Wmo_nVertices = 0;
if(froot->nGroups !=0)
{
for (int i=0; i<froot->nGroups; i++)
for (int i=0; i<froot->nGroups; ++i)
{
char temp[512];
strcpy(temp, wf.cFileName);
@ -189,14 +185,16 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
bResult = SFileFindNextFile(hFind, &wf);
break;
}
Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, preciseVectorData);
Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, preciseVectorData);
}
}
fseek(output, 8, SEEK_SET); // store the correct no of vertices
fwrite(&Wmo_nVertices,sizeof(int),1,output);
fclose(output);
}
} else {
}
else
{
fclose(n);
}
wf.dwFileFlags &= ~MPQ_FILE_HAS_EXTRA;
@ -220,29 +218,27 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
printf("\nExtract wmo complete (No errors)\n");
return nError;
}
void ExtractMapsFromMpq()
{
}
//-----------------------------------------------------------------------------
void ParsMapFiles()
{
char fn[512];
char id_filename[64];
char id[10];
for (unsigned int i=0; i<map_count; i++)
for (unsigned int i=0; i<map_count; ++i)
{
sprintf(id,"%03u",map_ids[i].id);
sprintf(fn,"World\\Maps\\%s\\%s.wdt", map_ids[i].name, map_ids[i].name);
WDTFile WDT(fn,map_ids[i].name);
if(WDT.init(id))
{
for (int x=0; x<64; x++)
for (int x=0; x<64; ++x)
{
for (int y=0; y<64; y++)
for (int y=0; y<64; ++y)
{
if (ADTFile*ADT = WDT.GetMap(x,y))
{
@ -250,7 +246,6 @@ void ParsMapFiles()
ADT->init(id_filename);
delete ADT;
}
}
}
}
@ -259,31 +254,28 @@ void ParsMapFiles()
#if 0
void ParsMapFiles()
{
char fn[512];
for (unsigned int i=0; i<map_count; i++)
for (unsigned int i=0; i<map_count; ++i)
{
sprintf(fn,"World\\Maps\\%s\\%s.wdt", map_ids[i].name, map_ids[i].name);
WDTFile WDT(fn,map_ids[i].name);
if(WDT.init())
{
for (int x=0; x<64; x++)
for (int x=0; x<64; ++x)
{
for (int y=0; y<64; y++)
for (int y=0; y<64; ++y)
{
if (ADTFile*ADT = WDT.GetMap(x,y))
{
ADT->init();
delete ADT;
}
}
}
}
}
}
#endif
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void getGamePath()
{
@ -297,18 +289,16 @@ void getGamePath()
//l = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\Burning Crusade Closed Beta",0,KEY_QUERY_VALUE,&key);
l = RegQueryValueEx(key,"InstallPath",0,&t,(LPBYTE)input_path,&s);
RegCloseKey(key);
if (strlen(input_path) > 0)
{
if (input_path[strlen(input_path) - 1] != '\\') strcat(input_path, "\\");
}
if (strlen(input_path) > 0)
{
if (input_path[strlen(input_path) - 1] != '\\') strcat(input_path, "\\");
}
strcat(input_path,"Data\\");
#else
strcpy(input_path,"data/");
#endif
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
bool scan_patches(char* scanmatch, std::vector<std::string>& pArchiveNames)
{
int i;
@ -338,7 +328,7 @@ bool scan_patches(char* scanmatch, std::vector<std::string>& pArchiveNames)
}
matches.reverse();
for (std::list<std::string>::iterator i = matches.begin(); i != matches.end(); i++)
for (std::list<std::string>::iterator i = matches.begin(); i != matches.end(); ++i)
{
pArchiveNames.push_back(i->c_str());
}
@ -348,11 +338,8 @@ bool scan_patches(char* scanmatch, std::vector<std::string>& pArchiveNames)
return(true);
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) {
//srand((unsigned int)time(0));
bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames)
{
if(!hasInputPathParam)
getGamePath();
@ -408,11 +395,12 @@ bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) {
// now, scan for the patch levels in the core dir
printf("Loading patch levels from data directory.\n");
sprintf(path, "%spatch", input_path);
if (!scan_patches(path, pArchiveNames)) return(false);
if (!scan_patches(path, pArchiveNames))
return(false);
// now, scan for the patch levels in locale dirs
printf("Loading patch levels from locale directories.\n");
for (std::vector<std::string>::iterator i = locales.begin(); i != locales.end(); i++)
for (std::vector<std::string>::iterator i = locales.begin(); i != locales.end(); ++i)
{
printf("Locale: %s\n", i->c_str());
sprintf(path, "%s%s\\patch-%s", input_path, i->c_str(), i->c_str());
@ -433,7 +421,7 @@ bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) {
// open locale expansion and common files
printf("Opening data files from locale directories.\n");
for (std::vector<std::string>::iterator i = locales.begin(); i != locales.end(); i++)
for (std::vector<std::string>::iterator i = locales.begin(); i != locales.end(); ++i)
{
printf("Locale: %s\n", i->c_str());
sprintf(path, "%s%s\\lichking-locale-%s.mpq", input_path, i->c_str(), i->c_str());
@ -446,8 +434,6 @@ bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) {
}
return true;
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// return false it normal processing can not proceed
bool processArgv(int argc, char ** argv, char*versionString)
{
@ -455,29 +441,43 @@ bool processArgv(int argc, char ** argv, char*versionString)
hasInputPathParam = false;
bool preciseVectorData = false;
for(int i=1; i< argc; ++i) {
if(strcmp("-s",argv[i]) == 0) {
preciseVectorData = false;
} else if(strcmp("-d",argv[i]) == 0) {
if((i+1)<argc) {
for(int i=1; i< argc; ++i)
{
if(strcmp("-s",argv[i]) == 0)
{
preciseVectorData = false;
}
else if(strcmp("-d",argv[i]) == 0)
{
if((i+1)<argc)
{
hasInputPathParam = true;
strcpy(input_path, argv[i+1]);
if (input_path[strlen(input_path) - 1] != '\\' || input_path[strlen(input_path) - 1] != '/')
strcat(input_path, "\\");
++i;
} else {
}
else
{
result = false;
}
} else if(strcmp("-?",argv[1]) == 0) {
}
else if(strcmp("-?",argv[1]) == 0)
{
result = false;
} else if(strcmp("-l",argv[i]) == 0) {
preciseVectorData = true;
} else {
}
else if(strcmp("-l",argv[i]) == 0)
{
preciseVectorData = true;
}
else
{
result = false;
break;
}
}
if(!result) {
if(!result)
{
printf("Extract %s.\n",versionString);
printf("%s [-?][-s][-l][-d <path>]\n", argv[0]);
printf(" -s : (default) small size (data size optimization), ~500MB less vmap data.\n");
@ -537,7 +537,8 @@ int main(int argc, char ** argv)
std::vector<std::string> archiveNames;
fillArchiveNameVector(archiveNames);
for (size_t i=0; i<archiveNames.size(); i++) {
for (size_t i=0; i<archiveNames.size(); ++i)
{
archives.push_back(new MPQArchive(archiveNames[i].c_str()));
}
ExtractWmo(archiveNames);
@ -550,7 +551,7 @@ int main(int argc, char ** argv)
dbc->open();
map_count=dbc->getRecordCount ();
map_ids=new map_id[map_count];
for(unsigned int x=0;x<map_count;x++)
for(unsigned int x=0;x<map_count;++x)
{
map_ids[x].id=dbc->getRecord (x).getUInt(0);
strcpy(map_ids[x].name,dbc->getRecord(x).getString(1));
@ -564,7 +565,8 @@ int main(int argc, char ** argv)
}
clreol();
if(nError != ERROR_SUCCESS) {
if(nError != ERROR_SUCCESS)
{
printf("ERROR: Extract %s. Work NOT complete.\n Precise vector data=%d.\nPress any key.\n",versionString, preciseVectorData);
_getch();
}

View file

@ -3,7 +3,6 @@
#include "wdtfile.h"
#include "adtfile.h"
char * wdtGetPlainName(char * FileName)
{
char * szTemp;
@ -15,106 +14,102 @@ char * wdtGetPlainName(char * FileName)
WDTFile::WDTFile(char* file_name, char* file_name1):WDT(file_name)
{
filename.append(file_name1,strlen(file_name1));
filename.append(file_name1,strlen(file_name1));
}
bool WDTFile::init(char *map_id)
{
if (WDT.isEof())
{
//printf("Can't find WDT file.\n");
return false;
}
if (WDT.isEof())
{
//printf("Can't find WDT file.\n");
return false;
}
char fourcc[5];
size_t size;
char fourcc[5];
size_t size;
const char dirname[] = "buildings\\dir";
FILE *dirfile;
const char dirname[] = "buildings\\dir";
FILE *dirfile;
dirfile = fopen(dirname, "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n");
return false;
}
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n");
return false;
}
while (!WDT.isEof())
{
WDT.read(fourcc,4);
WDT.read(&size, 4);
while (!WDT.isEof())
{
WDT.read(fourcc,4);
WDT.read(&size, 4);
flipcc(fourcc);
fourcc[4] = 0;
flipcc(fourcc);
fourcc[4] = 0;
size_t nextpos = WDT.getPos() + size;
size_t nextpos = WDT.getPos() + size;
if (!strcmp(fourcc,"MAIN"))
{
}
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)
{
// global map objects
if (size)
{
gnWMO = (int)size / 64;
string gWMO_mapname;
string fake_mapname;
fake_mapname = "65 65 ";
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);
}
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();
WDT.close();
fclose(dirfile);
return true;
return true;
}
WDTFile::~WDTFile(void)
{
WDT.close();
WDT.close();
}
ADTFile* WDTFile::GetMap(int x, int z)
{
if(!(x>=0 && z >= 0 && x<64 && z<64)) return NULL;
if(!(x>=0 && z >= 0 && x<64 && z<64)) return NULL;
char name[512];
char name[512];
sprintf(name,"World\\Maps\\%s\\%s_%d_%d.adt", filename.c_str(), filename.c_str(), x, z);
return new ADTFile(name);
sprintf(name,"World\\Maps\\%s\\%s_%d_%d.adt", filename.c_str(), filename.c_str(), x, z);
return new ADTFile(name);
}

View file

@ -12,19 +12,19 @@
class WDTFile
{
public:
WDTFile(char* file_name, char* file_name1);
~WDTFile(void);
bool init(char *map_id);
WDTFile(char* file_name, char* file_name1);
~WDTFile(void);
bool init(char *map_id);
string* gWmoInstansName;
int gnWMO, nMaps;
string* gWmoInstansName;
int gnWMO, nMaps;
ADTFile* GetMap(int x, int z);
ADTFile* GetMap(int x, int z);
private:
MPQFile WDT;
bool maps[64][64];
string filename;
MPQFile WDT;
bool maps[64][64];
string filename;
};
#endif

View file

@ -6,444 +6,457 @@
using namespace std;
WMORoot::WMORoot(std::string &filename) : filename(filename)
{
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
bool WMORoot::open()
{
MPQFile f(filename.c_str());
if(f.isEof ())
{
printf("No such file.\n");
return false;
}
MPQFile f(filename.c_str());
if(f.isEof ())
{
printf("No such file.\n");
return false;
}
size_t size;
char fourcc[5];
bbcorn1[3] = 0;
bbcorn2[3]= 0;
size_t size;
char fourcc[5];
bbcorn1[3] = 0;
bbcorn2[3]= 0;
while (!f.isEof())
{
f.read(fourcc,4);
f.read(&size, 4);
while (!f.isEof ())
{
f.read(fourcc,4);
f.read(&size, 4);
flipcc(fourcc);
fourcc[4] = 0;
flipcc(fourcc);
fourcc[4] = 0;
size_t nextpos = f.getPos() + size;
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(&RootID, 4);
f.read(bbcorn1,12);
f.read(bbcorn2,12);
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;
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(&RootID, 4);
f.read(bbcorn1,12);
f.read(bbcorn2,12);
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 WMORoot::ConvertToVMAPRootWmo(FILE *pOutfile)
{
//printf("Convert RootWmo...\n");
//printf("Convert RootWmo...\n");
fwrite("VMAP002",1,8,pOutfile);
unsigned int nVectors = 0;
fwrite(&nVectors,sizeof(nVectors),1,pOutfile); // will be filled later
fwrite(&nGroups,4,1,pOutfile);
return true;
fwrite("VMAP002",1,8,pOutfile);
unsigned int nVectors = 0;
fwrite(&nVectors,sizeof(nVectors),1,pOutfile); // will be filled later
fwrite(&nGroups,4,1,pOutfile);
return true;
}
//----------------------------------------------------------------------------
WMORoot::~WMORoot()
{
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
WMOGroup::WMOGroup(std::string &filename) : filename(filename)
{
}
//---------------------------------------------------------------------------
bool WMOGroup::open()
{
MPQFile f(filename.c_str());
if(f.isEof ())
{
printf("No such file.\n");
return false;
}
size_t size;
char fourcc[5];
bbcorn1[3] = 0;
bbcorn2[3] = 0;
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;
MPQFile f(filename.c_str());
if(f.isEof ())
{
printf("No such file.\n");
return false;
}
size_t size;
char fourcc[5];
bbcorn1[3] = 0;
bbcorn2[3] = 0;
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.seekRelative(-4);
f.read(&offsize, 4);
f.read(&flag, 4);
f.read(&flag1, 4);
f.read(&Xid, 4);
f.read(bbcorn1, 12);
f.read(bbcorn2, 12);
f.read(&Xid2, 4);
f.read(&Xid3, 4);
f.read(&zero1, 4);
f.read(&Xflag, 4);
f.read(&nTexture,4);
f.read(&GroupID,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);
if (!strcmp(fourcc,"MOGP"))//header
{
f.seekRelative(-4);
f.read(&offsize, 4);
f.read(&flag, 4);
f.read(&flag1, 4);
f.read(&Xid, 4);
f.read(bbcorn1, 12);
f.read(bbcorn2, 12);
f.read(&Xid2, 4);
f.read(&Xid3, 4);
f.read(&zero1, 4);
f.read(&Xflag, 4);
f.read(&nTexture,4);
f.read(&GroupID,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;
WMOLiquidHeader hlq;
f.read(&hlq, 0x1E);
float ydir = -1.0f;
hlq_xverts = hlq.xverts;
hlq_yverts = hlq.yverts;
int noVer = hlq.xverts * hlq.yverts;
float tilesize = CHUNKSIZE / 8.0f;
LiquEx_size = sizeof(float) * 3 * noVer;
LiquEx = new float[sizeof(float) * 3 * noVer];
int p = 0;
}
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;
WMOLiquidHeader hlq;
f.read(&hlq, 0x1E);
float ydir = -1.0f;
hlq_xverts = hlq.xverts;
hlq_yverts = hlq.yverts;
int noVer = hlq.xverts * hlq.yverts;
float tilesize = CHUNKSIZE / 8.0f;
LiquEx_size = sizeof(float) * 3 * noVer;
LiquEx = new float[sizeof(float) * 3 * noVer];
int p = 0;
for (int j=0; j<hlq.yverts; j++)
{
for (int i=0; i<hlq.xverts; i++)
{
LiquEx[p++] = hlq.pos_x + tilesize * i;
LiquEx[p++] = hlq.pos_z;
LiquEx[p++] = ydir * (hlq.pos_y + tilesize * j);
}
}
}
f.seek((int)nextpos);
}
f.close ();
return true;
for (int j=0; j<hlq.yverts; ++j)
{
for (int i=0; i<hlq.xverts; ++i)
{
LiquEx[p++] = hlq.pos_x + tilesize * i;
LiquEx[p++] = hlq.pos_z;
LiquEx[p++] = ydir * (hlq.pos_y + tilesize * j);
}
}
}
f.seek((int)nextpos);
}
f.close();
return true;
}
//----------------------------------------------------------------------------
int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, bool pPreciseVectorData)
{
if(pPreciseVectorData) {
fwrite(&liquflags,sizeof(uint32),1,output);
char GRP[] = "GRP ";
fwrite(GRP,1,4,output);
if(pPreciseVectorData)
{
fwrite(&liquflags,sizeof(uint32),1,output);
char GRP[] = "GRP ";
fwrite(GRP,1,4,output);
int k = 0;
int moba_batch = moba_size/12;
MobaEx = new int[moba_batch*4];
for(int i=8; i<moba_size; i+=12)
{
MobaEx[k++] = MOBA[i];
}
delete [] MOBA;
int moba_size_grp = moba_batch*4+4;
fwrite(&moba_size_grp,4,1,output);
fwrite(&moba_batch,4,1,output);
fwrite(MobaEx,4,k,output);
delete [] MobaEx;
int k = 0;
int moba_batch = moba_size/12;
MobaEx = new int[moba_batch*4];
for(int i=8; i<moba_size; i+=12)
{
MobaEx[k++] = MOBA[i];
}
delete [] MOBA;
int moba_size_grp = moba_batch*4+4;
fwrite(&moba_size_grp,4,1,output);
fwrite(&moba_batch,4,1,output);
fwrite(MobaEx,4,k,output);
delete [] MobaEx;
uint32 nIdexes = nTriangles * 3;
uint32 nIdexes = nTriangles * 3;
if(fwrite("INDX",4, 1, output) != 1) { printf("Error while writing file nbraches ID"); exit(0); }
int wsize = sizeof(uint32) + sizeof(unsigned short) * nIdexes;
if(fwrite(&wsize, sizeof(int), 1, output) != 1) { printf("Error while writing file wsize"); }
if(fwrite(&nIdexes, sizeof(uint32), 1, output) != 1) { printf("Error while writing file nIndexes"); exit(0); }
if(nIdexes >0) {
if(fwrite(MOVI, sizeof(unsigned short), nIdexes, output) != nIdexes) { printf("Error while writing file indexarray"); exit(0); }
}
if(fwrite("INDX",4, 1, output) != 1)
{
printf("Error while writing file nbraches ID");
exit(0);
}
int wsize = sizeof(uint32) + sizeof(unsigned short) * nIdexes;
if(fwrite(&wsize, sizeof(int), 1, output) != 1)
{
printf("Error while writing file wsize");
// no need to exit?
}
if(fwrite(&nIdexes, sizeof(uint32), 1, output) != 1)
{
printf("Error while writing file nIndexes");
exit(0);
}
if(nIdexes >0)
{
if(fwrite(MOVI, sizeof(unsigned short), nIdexes, output) != nIdexes)
{
printf("Error while writing file indexarray");
exit(0);
}
}
if(fwrite("VERT",4, 1, output) != 1) { printf("Error while writing file nbraches ID"); exit(0); }
wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
if(fwrite(&wsize, sizeof(int), 1, output) != 1) { printf("Error while writing file wsize"); }
if(fwrite(&nVertices, sizeof(int), 1, output) != 1) { printf("Error while writing file nVertices"); exit(0); }
if(nVertices >0) {
if(fwrite(MOVT, sizeof(float)*3, nVertices, output) != nVertices) { printf("Error while writing file vectors"); exit(0); }
}
if(fwrite("VERT",4, 1, output) != 1)
{
printf("Error while writing file nbraches ID");
exit(0);
}
wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
if(fwrite(&wsize, sizeof(int), 1, output) != 1)
{
printf("Error while writing file wsize");
// no need to exit?
}
if(fwrite(&nVertices, sizeof(int), 1, output) != 1)
{
printf("Error while writing file nVertices");
exit(0);
}
if(nVertices >0)
{
if(fwrite(MOVT, sizeof(float)*3, nVertices, output) != nVertices)
{
printf("Error while writing file vectors");
exit(0);
}
}
if(LiquEx_size != 0)
{
int LIQU_h[] = {0x5551494C,LiquEx_size+8,hlq_xverts,hlq_yverts};// "LIQU"
fwrite(LIQU_h,4,4,output);
fwrite(LiquEx,4,LiquEx_size/4,output);
delete [] LiquEx;
}
if(LiquEx_size != 0)
{
int LIQU_h[] = {0x5551494C,LiquEx_size+8,hlq_xverts,hlq_yverts};// "LIQU"
fwrite(LIQU_h,4,4,output);
fwrite(LiquEx,4,LiquEx_size/4,output);
delete [] LiquEx;
}
return nTriangles;
} else {
//printf("Convert GroupWmo...\n");
//-------GRP -------------------------------------
fwrite(&liquflags,sizeof(uint32),1,output);
char GRP[] = "GRP ";
fwrite(GRP,1,4,output);
int k = 0;
int moba_batch = moba_size/12;
MobaEx = new int[moba_batch*4];
for(int i=8; i<moba_size; i+=12)
{
MobaEx[k++] = MOBA[i];
}
delete [] MOBA;
int moba_size_grp = moba_batch*4+4;
fwrite(&moba_size_grp,4,1,output);
fwrite(&moba_batch,4,1,output);
fwrite(MobaEx,4,k,output);
delete [] MobaEx;
return nTriangles;
}
else
{
//printf("Convert GroupWmo...\n");
//-------GRP -------------------------------------
fwrite(&liquflags,sizeof(uint32),1,output);
char GRP[] = "GRP ";
fwrite(GRP,1,4,output);
int k = 0;
int moba_batch = moba_size/12;
MobaEx = new int[moba_batch*4];
for(int i=8; i<moba_size; i+=12)
{
MobaEx[k++] = MOBA[i];
}
delete [] MOBA;
int moba_size_grp = moba_batch*4+4;
fwrite(&moba_size_grp,4,1,output);
fwrite(&moba_batch,4,1,output);
fwrite(MobaEx,4,k,output);
delete [] MobaEx;
//-------INDX------------------------------------
//-------MOPY--------
int n = 0;
int j = 0;
MopyEx = new char[mopy_size];
IndexExTr = new int[mopy_size];
for (int i=0; i<mopy_size; i+=2)
{
//-------INDX------------------------------------
//-------MOPY--------
int n = 0;
int j = 0;
MopyEx = new char[mopy_size];
IndexExTr = new int[mopy_size];
for (int i=0; i<mopy_size; i+=2)
{
// Skip no collision triangles
if ((int)MOPY[i]&WMO_MATERIAL_NO_COLLISION)
continue;
// Use only this triangles
if ((int)MOPY[i]&(WMO_MATERIAL_HINT|WMO_MATERIAL_COLLIDE_HIT))
{
MopyEx[n] = MOPY[i];
MopyEx[(n+1)] = MOPY[(i+1)];
IndexExTr[j] = i/2;
j+=1;
n+=2;
}
}
MopyEx_size = n;
IndexExTr_size = j;
delete [] MOPY;
delete [] MopyEx;
{
MopyEx[n] = MOPY[i];
MopyEx[(n+1)] = MOPY[(i+1)];
IndexExTr[j] = i/2;
j+=1;
n+=2;
}
}
MopyEx_size = n;
IndexExTr_size = j;
delete [] MOPY;
delete [] MopyEx;
//---------MOVI-----------
MoviEx = new uint16[IndexExTr_size*3];
int m = 0;
for (int i=0; i<IndexExTr_size; i++)
{
int n = 0;
n = IndexExTr[i]*3;
for (int x=0; x<3; x++)
{
MoviEx[m] = MOVI[n];
n++;
m++;
}
}
delete [] MOVI;
//---------MOVI-----------
MoviEx = new uint16[IndexExTr_size*3];
int m = 0;
for (int i=0; i<IndexExTr_size; ++i)
{
int n = 0;
n = IndexExTr[i]*3;
for (int x=0; x<3; ++x)
{
MoviEx[m] = MOVI[n];
n++;
m++;
}
}
delete [] MOVI;
MoviExSort = new uint16[IndexExTr_size*3];
for(int y=0; y<IndexExTr_size*3; y++)
{
MoviExSort[y]=MoviEx[y];
}
MoviExSort = new uint16[IndexExTr_size*3];
for(int y=0; y<IndexExTr_size*3; ++y)
{
MoviExSort[y]=MoviEx[y];
}
uint16 hold;
for (int pass = 1; pass < IndexExTr_size*3; pass++)
{
for (int i=0; i < IndexExTr_size*3-1; i++)
{
if (MoviExSort[i] > MoviExSort[i+1])
{
hold = MoviExSort[i];
MoviExSort[i] = MoviExSort[i+1];
MoviExSort[i+1] = hold;
}
//double = 65535
else
if (MoviExSort[i] == MoviExSort[i+1])
MoviExSort[i+1] = 65535;
}
}
// double delet
uint16 s = 0;
for (int i=0; i < IndexExTr_size*3; i++)
{
if (MoviExSort[i]!=65535)
{
MoviExSort[s] = MoviExSort[i];
s++;
}
}
MovtExSort = new uint16[s];
for (int i=0; i < s; i++)
{
MovtExSort[i] = MoviExSort[i];
}
uint16 hold;
for (int pass = 1; pass < IndexExTr_size*3; ++pass)
{
for (int i=0; i < IndexExTr_size*3-1; ++i)
{
if (MoviExSort[i] > MoviExSort[i+1])
{
hold = MoviExSort[i];
MoviExSort[i] = MoviExSort[i+1];
MoviExSort[i+1] = hold;
}
//double = 65535
else
if (MoviExSort[i] == MoviExSort[i+1])
MoviExSort[i+1] = 65535;
}
}
// double delet
uint16 s = 0;
for (int i=0; i < IndexExTr_size*3; ++i)
{
if (MoviExSort[i]!=65535)
{
MoviExSort[s] = MoviExSort[i];
s++;
}
}
MovtExSort = new uint16[s];
for (int i=0; i < s; ++i)
{
MovtExSort[i] = MoviExSort[i];
}
for (int i=0; i < IndexExTr_size*3; i++)
{
uint16 b = MoviEx[i];
for (uint16 x = 0; x < s; x++)
{
if(MoviExSort[x] == b)
{
for (int i=0; i < IndexExTr_size*3; ++i)
{
uint16 b = MoviEx[i];
for (uint16 x = 0; x < s; ++x)
{
if(MoviExSort[x] == b)
{
MoviEx[i] = x;
break;
}
}
}
int INDX[] = {0x58444E49,IndexExTr_size*6+4,IndexExTr_size*3};
fwrite(INDX,4,3,output);
fwrite(MoviEx,2,IndexExTr_size*3,output);
MoviEx[i] = x;
break;
}
}
delete [] MoviEx;
delete [] MoviExSort;
delete [] IndexExTr;
}
int INDX[] = {0x58444E49,IndexExTr_size*6+4,IndexExTr_size*3};
fwrite(INDX,4,3,output);
fwrite(MoviEx,2,IndexExTr_size*3,output);
//----------VERT---------
//-----MOVT----------
int d = 0;
MovtEx = new float[s*3];
for (uint16 i=0; i<s; ++i)
{
int c=0;//!!!!data in MovtExSort[i] more uint16 in great group wmo files!!!!
c = MovtExSort[i]*3;
for (int y=0; y<3; ++y)
{
MovtEx[d] = MOVT[c];
c++;
d++;
}
}
int VERT[] = {0x54524556,d*4+4,d*4/12};// "VERT"
fwrite(VERT,4,3,output);
fwrite(MovtEx,4,d,output);
//------LIQU------------------------
if(LiquEx_size != 0)
{
int LIQU_h[] = {0x5551494C,LiquEx_size+8,hlq_xverts,hlq_yverts};// "LIQU"
fwrite(LIQU_h,4,4,output);
fwrite(LiquEx,4,LiquEx_size/4,output);
delete [] LiquEx;
}
delete [] MoviEx;
delete [] MoviExSort;
delete [] IndexExTr;
delete [] MOVT;
delete [] MovtEx;
delete [] MovtExSort;
//----------VERT---------
//-----MOVT----------
int d = 0;
MovtEx = new float[s*3];
for (uint16 i=0; i<s; i++)
{
int c=0;//!!!!data in MovtExSort[i] more uint16 in great group wmo files!!!!
c = MovtExSort[i]*3;
for (int y=0; y<3; y++)
{
MovtEx[d] = MOVT[c];
c++;
d++;
}
}
int VERT[] = {0x54524556,d*4+4,d*4/12};// "VERT"
fwrite(VERT,4,3,output);
fwrite(MovtEx,4,d,output);
//------LIQU------------------------
if(LiquEx_size != 0)
{
int LIQU_h[] = {0x5551494C,LiquEx_size+8,hlq_xverts,hlq_yverts};// "LIQU"
fwrite(LIQU_h,4,4,output);
fwrite(LiquEx,4,LiquEx_size/4,output);
delete [] LiquEx;
}
delete [] MOVT;
delete [] MovtEx;
delete [] MovtExSort;
//---------------------------------------------
return IndexExTr_size;
}
//---------------------------------------------
return IndexExTr_size;
}
}
WMOGroup::~WMOGroup()
@ -452,84 +465,83 @@ WMOGroup::~WMOGroup()
WMOInstance::WMOInstance(MPQFile &f,const char* WmoInstName,const char*MapName, FILE *pDirfile)
{
pos = Vec3D(0,0,0);
pos = Vec3D(0,0,0);
float ff[3];
f.read(&id, 4);
f.read(ff,12);
pos = Vec3D(ff[0],ff[1],ff[2]);
f.read(ff,12);
rot = Vec3D(ff[0],ff[1],ff[2]);
f.read(ff,12);
pos2 = Vec3D(ff[0],ff[1],ff[2]);
f.read(ff,12);
pos3 = Vec3D(ff[0],ff[1],ff[2]);
f.read(&d2,4);
f.read(&d3,4);
float ff[3];
f.read(&id, 4);
f.read(ff,12);
pos = Vec3D(ff[0],ff[1],ff[2]);
f.read(ff,12);
rot = Vec3D(ff[0],ff[1],ff[2]);
f.read(ff,12);
pos2 = Vec3D(ff[0],ff[1],ff[2]);
f.read(ff,12);
pos3 = Vec3D(ff[0],ff[1],ff[2]);
f.read(&d2,4);
f.read(&d3,4);
doodadset = (d2 & 0xFFFF0000) >> 16;
doodadset = (d2 & 0xFFFF0000) >> 16;
int realx1 = (int) ((float) pos2.x / 533.333333f);
int realy1 = (int) ((float) pos2.z / 533.333333f);
int realx2 = (int) ((float) pos3.x / 533.333333f);
int realy2 = (int) ((float) pos3.z / 533.333333f);
int realx1 = (int) ((float) pos2.x / 533.333333f);
int realy1 = (int) ((float) pos2.z / 533.333333f);
int realx2 = (int) ((float) pos3.x / 533.333333f);
int realy2 = (int) ((float) pos3.z / 533.333333f);
if(realx1 < 0)
{
realx1 +=20; realx2+=20;
}
if(realy1 < 0)
{
realy1 +=20; realy2+=20;
} // hack to prevent neg. values
if(realx1 < 0)
{
realx1 +=20; realx2+=20;
}
if(realy1 < 0)
{
realy1 +=20; realy2+=20;
} // hack to prevent neg. values
//-----------add_in _dir_file----------------
//-----------add_in _dir_file----------------
char tempname[512];
// const char dirname[] = "buildings\\dir";
char tempname[512];
// const char dirname[] = "buildings\\dir";
sprintf(tempname, "buildings\\%s", WmoInstName);
FILE *input;
input = fopen(tempname, "r+b");
if(!input)
{
return;
}
fseek(input, 8, SEEK_SET); // get the correct no of vertices
int nVertices;
fread(&nVertices, sizeof (int), 1, input);
fclose(input);
if(nVertices == 0)
{
return;
}
sprintf(tempname, "buildings\\%s", WmoInstName);
FILE *input;
input = fopen(tempname, "r+b");
/* FILE *dirfile;
dirfile = fopen(dirname, "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n");
return;
}
*/
float x,z;
x = pos.x;
z = pos.z;
if(x==0 && z == 0)
{ x = 533.33333f*32; z = 533.33333f*32; }
fprintf(pDirfile,"%s/%s %f,%f,%f_%f,%f,%f 1.0 %d %d %d,%d %d\n",
MapName,
WmoInstName,
(float) x, (float) pos.y, (float) z,
(float) rot.x, (float) rot.y, (float) rot.z,
nVertices,
realx1, realy1,
realx2, realy2
);
if(!input)
return;
// fclose(dirfile);
fseek(input, 8, SEEK_SET); // get the correct no of vertices
int nVertices;
fread(&nVertices, sizeof (int), 1, input);
fclose(input);
if(nVertices == 0)
return;
/* FILE *dirfile;
dirfile = fopen(dirname, "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n");
return;
}
*/
float x,z;
x = pos.x;
z = pos.z;
if(x==0 && z == 0)
{
x = 533.33333f*32;
z = 533.33333f*32;
}
fprintf(pDirfile,"%s/%s %f,%f,%f_%f,%f,%f 1.0 %d %d %d,%d %d\n",
MapName,
WmoInstName,
(float) x, (float) pos.y, (float) z,
(float) rot.x, (float) rot.y, (float) rot.z,
nVertices,
realx1, realy1,
realx2, realy2
);
// fclose(dirfile);
}

View file

@ -30,86 +30,83 @@ typedef unsigned int uint32;
class WMORoot
{
public:
int nTextures, nGroups, nP, nLights, nModels, nDoodads, nDoodadSets, RootID;
unsigned int col;
int bbcorn1[3];
int bbcorn2[3];
int nTextures, nGroups, nP, nLights, nModels, nDoodads, nDoodadSets, RootID;
unsigned int col;
int bbcorn1[3];
int bbcorn2[3];
WMORoot(std::string &filename);
~WMORoot();
WMORoot(std::string &filename);
~WMORoot();
bool open();
bool ConvertToVMAPRootWmo(FILE *output);
bool open();
bool ConvertToVMAPRootWmo(FILE *output);
private:
std::string filename;
char outfilename;
std::string filename;
char outfilename;
};
class WMOGroup
{
public:
int offsize,flag,flag1,Xid,Xid2,Xid3,zero1,Xflag,nTexture,GroupID;
int mopy_size,moba_size,hlq_xverts,hlq_yverts;
int MopyEx_size,IndexExTr_size,LiquEx_size;
unsigned int nVertices; // number when loaded
int nTriangles; // number when loaded
int bbcorn1[3];
int bbcorn2[3];
int * IndexExTr;
char* MOPY;
char* MopyEx;
uint16* MOVI;
uint16* MoviEx;
uint16* MoviExSort;
float* MOVT;
float* MovtEx;
uint16* MovtExSort;
float* MONR;
float* MonrEx;
uint16* MOBA;
int* MobaEx;
float* LiquEx;
uint32 liquflags;
int offsize,flag,flag1,Xid,Xid2,Xid3,zero1,Xflag,nTexture,GroupID;
int mopy_size,moba_size,hlq_xverts,hlq_yverts;
int MopyEx_size,IndexExTr_size,LiquEx_size;
unsigned int nVertices; // number when loaded
int nTriangles; // number when loaded
int bbcorn1[3];
int bbcorn2[3];
int * IndexExTr;
char* MOPY;
char* MopyEx;
uint16* MOVI;
uint16* MoviEx;
uint16* MoviExSort;
float* MOVT;
float* MovtEx;
uint16* MovtExSort;
float* MONR;
float* MonrEx;
uint16* MOBA;
int* MobaEx;
float* LiquEx;
uint32 liquflags;
WMOGroup(std::string &filename);
~WMOGroup();
WMOGroup(std::string &filename);
~WMOGroup();
bool open();
int ConvertToVMAPGroupWmo(FILE *output, bool pPreciseVectorData);
bool open();
int ConvertToVMAPGroupWmo(FILE *output, bool pPreciseVectorData);
private:
std::string filename;
char outfilename;
std::string filename;
char outfilename;
};
struct WMOLiquidHeader
{
int xverts, yverts, xtiles, ytiles;
float pos_x;
float pos_y;
float pos_z;
short type;
int xverts, yverts, xtiles, ytiles;
float pos_x;
float pos_y;
float pos_z;
short type;
};
class WMOInstance
{
static std::set<int> ids;
static std::set<int> ids;
public:
string MapName;
int currx;
int curry;
WMOGroup *wmo;
Vec3D pos;
Vec3D pos2, pos3, rot;
int indx,id, d2, d3;
int doodadset;
int curry;
WMOGroup *wmo;
Vec3D pos;
Vec3D pos2, pos3, rot;
int indx,id, d2, d3;
int doodadset;
WMOInstance(MPQFile &f,const char* WmoInstName,const char*MapName, FILE *pDirfile);
WMOInstance(MPQFile &f,const char* WmoInstName,const char*MapName, FILE *pDirfile);
static void reset();
static void reset();
};
#endif

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "7908"
#define REVISION_NR "7909"
#endif // __REVISION_NR_H__