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

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ bool Model::open()
ok = !f.isEof(); ok = !f.isEof();
if (!ok) if (!ok)
{ {
f.close(); f.close();
printf("Error loading model %s\n", filename.c_str()); printf("Error loading model %s\n", filename.c_str());
@ -20,20 +20,20 @@ bool Model::open()
} }
memcpy(&header, f.getBuffer(), sizeof(ModelHeader)); memcpy(&header, f.getBuffer(), sizeof(ModelHeader));
if(header.nBoundingTriangles > 0) if(header.nBoundingTriangles > 0)
{ {
f.seek(0); f.seek(0);
f.seekRelative(header.ofsBoundingVertices); f.seekRelative(header.ofsBoundingVertices);
vertices = new Vec3D[header.nBoundingVertices]; vertices = new Vec3D[header.nBoundingVertices];
f.read(vertices,header.nBoundingVertices*12); f.read(vertices,header.nBoundingVertices*12);
for (uint32 i=0; i<header.nBoundingVertices; i++) for (uint32 i=0; i<header.nBoundingVertices; i++)
{ {
vertices[i] = fixCoordSystem(vertices[i]); vertices[i] = fixCoordSystem(vertices[i]);
} }
f.seek(0); f.seek(0);
f.seekRelative(header.ofsBoundingTriangles); f.seekRelative(header.ofsBoundingTriangles);
indices = new uint16[header.nBoundingTriangles]; indices = new uint16[header.nBoundingTriangles];
f.read(indices,header.nBoundingTriangles*2); f.read(indices,header.nBoundingTriangles*2);
f.close(); f.close();
} }
else else
@ -45,10 +45,8 @@ bool Model::open()
return true; return true;
} }
bool Model::ConvertToVMAPModel(char * outfilename) bool Model::ConvertToVMAPModel(char * outfilename)
{ {
int N[] = {0x00000000}; int N[] = {0x00000000};
FILE * output=fopen(outfilename,"wb"); FILE * output=fopen(outfilename,"wb");
if(!output) if(!output)
@ -76,7 +74,7 @@ bool Model::ConvertToVMAPModel(char * outfilename)
wsize = sizeof(uint32) + sizeof(unsigned short) * nIndexes; wsize = sizeof(uint32) + sizeof(unsigned short) * nIndexes;
fwrite(&wsize, sizeof(int), 1, output); fwrite(&wsize, sizeof(int), 1, output);
fwrite(&nIndexes, sizeof(uint32), 1, output); fwrite(&nIndexes, sizeof(uint32), 1, output);
if(nIndexes >0) if(nIndexes >0)
{ {
fwrite(indices, sizeof(unsigned short), nIndexes, output); fwrite(indices, sizeof(unsigned short), nIndexes, output);
} }
@ -84,7 +82,7 @@ bool Model::ConvertToVMAPModel(char * outfilename)
wsize = sizeof(int) + sizeof(float) * 3 * nVertices; wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
fwrite(&wsize, sizeof(int), 1, output); fwrite(&wsize, sizeof(int), 1, output);
fwrite(&nVertices, sizeof(int), 1, output); fwrite(&nVertices, sizeof(int), 1, output);
if(nVertices >0) if(nVertices >0)
{ {
for(uint32 vpos=0; vpos <nVertices; ++vpos) for(uint32 vpos=0; vpos <nVertices; ++vpos)
{ {
@ -133,27 +131,25 @@ ModelInstance::ModelInstance(MPQFile &f,const char* ModelInstName,const char*Map
sprintf(tempname, ".\\buildings\\%s", ModelInstName); sprintf(tempname, ".\\buildings\\%s", ModelInstName);
FILE *input; FILE *input;
input = fopen(tempname, "r+b"); 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;
}
if(pDirfile) 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;
if(pDirfile)
{ {
int realx1 = (int) ((float) pos.x / 533.333333f); int realx1 = (int) ((float) pos.x / 533.333333f);
int realy1 = (int) ((float) pos.z / 533.333333f); int realy1 = (int) ((float) pos.z / 533.333333f);
int realx2 = (int) ((float) pos.x / 533.333333f); int realx2 = (int) ((float) pos.x / 533.333333f);
int realy2 = (int) ((float) pos.z / 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", fprintf(pDirfile,"%s/%s %f,%f,%f_%f,%f,%f %f %d %d %d,%d %d\n",
MapName, MapName,
ModelInstName, ModelInstName,
@ -163,6 +159,6 @@ ModelInstance::ModelInstance(MPQFile &f,const char* ModelInstName,const char*Map
nVertices, nVertices,
realx1, realy1, realx1, realy1,
realx2, realy2 realx2, realy2
); );
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -58,7 +58,7 @@ char input_path[1024]=".";
bool hasInputPathParam = false; bool hasInputPathParam = false;
char tmp[512]; char tmp[512];
bool preciseVectorData = false; bool preciseVectorData = false;
//char gamepath[1024]; //char gamepath[1024];
//Convert function //Convert function
//bool ConvertADT(char*,char*); //bool ConvertADT(char*,char*);
@ -86,7 +86,7 @@ static const char * GetPlainName(const char * szFileName)
szFileName = szTemp + 1; szFileName = szTemp + 1;
return szFileName; return szFileName;
} }
//------------------------------------------------------------------------------
static void ShowProcessedFile(const char * szFileName) static void ShowProcessedFile(const char * szFileName)
{ {
char szLine[80]; char szLine[80];
@ -101,14 +101,11 @@ static void ShowProcessedFile(const char * szFileName)
printf("\r%s\n", szLine); printf("\r%s\n", szLine);
} }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------
int ExtractWmo(const std::vector<std::string>& pArchiveNames) int ExtractWmo(const std::vector<std::string>& pArchiveNames)
{ {
char* szListFile = "";
char* szListFile = "";
char szLocalFile[MAX_PATH] = ""; char szLocalFile[MAX_PATH] = "";
HANDLE hMpq = ""; HANDLE hMpq = "";
BOOL bResult = FALSE; BOOL bResult = FALSE;
//const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"}; //const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"};
@ -118,9 +115,8 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
szListFile = NULL; szListFile = NULL;
//char tmp[1024]; //char tmp[1024];
//for (size_t i=0; i<4; i++) //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]); //sprintf(tmp,"%s\\%s", input_path, ParsArchiveNames[i]);
//if(!SFileOpenArchive(tmp, 0, 0, &hMpq)) //if(!SFileOpenArchive(tmp, 0, 0, &hMpq))
if(!SFileOpenArchive(pArchiveNames[i].c_str(), 0, 0, &hMpq)) if(!SFileOpenArchive(pArchiveNames[i].c_str(), 0, 0, &hMpq))
@ -128,7 +124,7 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
// Copy files from archive // Copy files from archive
if(nError == ERROR_SUCCESS) if(nError == ERROR_SUCCESS)
{ {
SFILE_FIND_DATA wf; SFILE_FIND_DATA wf;
HANDLE hFind = SFileFindFirstFile(hMpq,"*.wmo*", &wf, szListFile); HANDLE hFind = SFileFindFirstFile(hMpq,"*.wmo*", &wf, szListFile);
bResult = TRUE; bResult = TRUE;
@ -149,11 +145,11 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
{ {
char cpy[4]; char cpy[4];
strncpy((char*)cpy,rchr,4); strncpy((char*)cpy,rchr,4);
for (int i=0;i<4;i++) for (int i=0;i<4; ++i)
{ {
int m = cpy[i]; int m = cpy[i];
if(isdigit(m)) if(isdigit(m))
p++; p++;
} }
} }
if(p != 3) if(p != 3)
@ -167,12 +163,12 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
bResult = SFileFindNextFile(hFind, &wf); bResult = SFileFindNextFile(hFind, &wf);
continue; continue;
} }
FILE *output=fopen(szLocalFile,"wb"); FILE *output=fopen(szLocalFile,"wb");
froot->ConvertToVMAPRootWmo(output); froot->ConvertToVMAPRootWmo(output);
int Wmo_nVertices = 0; int Wmo_nVertices = 0;
if(froot->nGroups !=0) if(froot->nGroups !=0)
{ {
for (int i=0; i<froot->nGroups; i++) for (int i=0; i<froot->nGroups; ++i)
{ {
char temp[512]; char temp[512];
strcpy(temp, wf.cFileName); strcpy(temp, wf.cFileName);
@ -189,14 +185,16 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
bResult = SFileFindNextFile(hFind, &wf); bResult = SFileFindNextFile(hFind, &wf);
break; break;
} }
Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, preciseVectorData); Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, preciseVectorData);
} }
} }
fseek(output, 8, SEEK_SET); // store the correct no of vertices fseek(output, 8, SEEK_SET); // store the correct no of vertices
fwrite(&Wmo_nVertices,sizeof(int),1,output); fwrite(&Wmo_nVertices,sizeof(int),1,output);
fclose(output); fclose(output);
} }
} else { }
else
{
fclose(n); fclose(n);
} }
wf.dwFileFlags &= ~MPQ_FILE_HAS_EXTRA; 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"); printf("\nExtract wmo complete (No errors)\n");
return nError; return nError;
} }
void ExtractMapsFromMpq() void ExtractMapsFromMpq()
{ {
} }
//-----------------------------------------------------------------------------
void ParsMapFiles() void ParsMapFiles()
{ {
char fn[512]; char fn[512];
char id_filename[64]; char id_filename[64];
char id[10]; 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(id,"%03u",map_ids[i].id);
sprintf(fn,"World\\Maps\\%s\\%s.wdt", map_ids[i].name, map_ids[i].name); sprintf(fn,"World\\Maps\\%s\\%s.wdt", map_ids[i].name, map_ids[i].name);
WDTFile WDT(fn,map_ids[i].name); WDTFile WDT(fn,map_ids[i].name);
if(WDT.init(id)) 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)) if (ADTFile*ADT = WDT.GetMap(x,y))
{ {
@ -250,7 +246,6 @@ void ParsMapFiles()
ADT->init(id_filename); ADT->init(id_filename);
delete ADT; delete ADT;
} }
} }
} }
} }
@ -259,31 +254,28 @@ void ParsMapFiles()
#if 0 #if 0
void ParsMapFiles() void ParsMapFiles()
{ {
char fn[512]; 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); sprintf(fn,"World\\Maps\\%s\\%s.wdt", map_ids[i].name, map_ids[i].name);
WDTFile WDT(fn,map_ids[i].name); WDTFile WDT(fn,map_ids[i].name);
if(WDT.init()) 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)) if (ADTFile*ADT = WDT.GetMap(x,y))
{ {
ADT->init(); ADT->init();
delete ADT; delete ADT;
} }
} }
} }
} }
} }
} }
#endif #endif
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void getGamePath() 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 = 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); l = RegQueryValueEx(key,"InstallPath",0,&t,(LPBYTE)input_path,&s);
RegCloseKey(key); RegCloseKey(key);
if (strlen(input_path) > 0) if (strlen(input_path) > 0)
{ {
if (input_path[strlen(input_path) - 1] != '\\') strcat(input_path, "\\"); if (input_path[strlen(input_path) - 1] != '\\') strcat(input_path, "\\");
} }
strcat(input_path,"Data\\"); strcat(input_path,"Data\\");
#else #else
strcpy(input_path,"data/"); strcpy(input_path,"data/");
#endif #endif
} }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
bool scan_patches(char* scanmatch, std::vector<std::string>& pArchiveNames) bool scan_patches(char* scanmatch, std::vector<std::string>& pArchiveNames)
{ {
int i; int i;
@ -338,7 +328,7 @@ bool scan_patches(char* scanmatch, std::vector<std::string>& pArchiveNames)
} }
matches.reverse(); 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()); pArchiveNames.push_back(i->c_str());
} }
@ -348,11 +338,8 @@ bool scan_patches(char* scanmatch, std::vector<std::string>& pArchiveNames)
return(true); return(true);
} }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames)
{
bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) {
//srand((unsigned int)time(0));
if(!hasInputPathParam) if(!hasInputPathParam)
getGamePath(); getGamePath();
@ -408,11 +395,12 @@ bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) {
// now, scan for the patch levels in the core dir // now, scan for the patch levels in the core dir
printf("Loading patch levels from data directory.\n"); printf("Loading patch levels from data directory.\n");
sprintf(path, "%spatch", input_path); 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 // now, scan for the patch levels in locale dirs
printf("Loading patch levels from locale directories.\n"); 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()); printf("Locale: %s\n", i->c_str());
sprintf(path, "%s%s\\patch-%s", input_path, i->c_str(), 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 // open locale expansion and common files
printf("Opening data files from locale directories.\n"); 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()); printf("Locale: %s\n", i->c_str());
sprintf(path, "%s%s\\lichking-locale-%s.mpq", input_path, i->c_str(), 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; return true;
} }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// return false it normal processing can not proceed
bool processArgv(int argc, char ** argv, char*versionString) bool processArgv(int argc, char ** argv, char*versionString)
{ {
@ -455,29 +441,43 @@ bool processArgv(int argc, char ** argv, char*versionString)
hasInputPathParam = false; hasInputPathParam = false;
bool preciseVectorData = false; bool preciseVectorData = false;
for(int i=1; i< argc; ++i) { for(int i=1; i< argc; ++i)
if(strcmp("-s",argv[i]) == 0) { {
preciseVectorData = false; if(strcmp("-s",argv[i]) == 0)
} else if(strcmp("-d",argv[i]) == 0) { {
if((i+1)<argc) { preciseVectorData = false;
}
else if(strcmp("-d",argv[i]) == 0)
{
if((i+1)<argc)
{
hasInputPathParam = true; hasInputPathParam = true;
strcpy(input_path, argv[i+1]); strcpy(input_path, argv[i+1]);
if (input_path[strlen(input_path) - 1] != '\\' || input_path[strlen(input_path) - 1] != '/') if (input_path[strlen(input_path) - 1] != '\\' || input_path[strlen(input_path) - 1] != '/')
strcat(input_path, "\\"); strcat(input_path, "\\");
++i; ++i;
} else { }
else
{
result = false; result = false;
} }
} else if(strcmp("-?",argv[1]) == 0) { }
else if(strcmp("-?",argv[1]) == 0)
{
result = false; result = false;
} else if(strcmp("-l",argv[i]) == 0) { }
preciseVectorData = true; else if(strcmp("-l",argv[i]) == 0)
} else { {
preciseVectorData = true;
}
else
{
result = false; result = false;
break; break;
} }
} }
if(!result) { if(!result)
{
printf("Extract %s.\n",versionString); printf("Extract %s.\n",versionString);
printf("%s [-?][-s][-l][-d <path>]\n", argv[0]); printf("%s [-?][-s][-l][-d <path>]\n", argv[0]);
printf(" -s : (default) small size (data size optimization), ~500MB less vmap data.\n"); printf(" -s : (default) small size (data size optimization), ~500MB less vmap data.\n");
@ -512,9 +512,9 @@ int main(int argc, char ** argv)
char *versionString = "V2.4 2007_07_12"; char *versionString = "V2.4 2007_07_12";
// Use command line arguments, when some // Use command line arguments, when some
if(!processArgv(argc, argv, versionString)) if(!processArgv(argc, argv, versionString))
return 1; return 1;
printf("Extract %s. Beginning work ....\n",versionString); printf("Extract %s. Beginning work ....\n",versionString);
// Set the lowest priority to allow running in the background // Set the lowest priority to allow running in the background
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
@ -528,7 +528,7 @@ int main(int argc, char ** argv)
nError = GetLastError(); nError = GetLastError();
if(nError == ERROR_ALREADY_EXISTS) if(nError == ERROR_ALREADY_EXISTS)
nError = ERROR_SUCCESS; nError = ERROR_SUCCESS;
} }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// patch goes first -> fake priority handling // patch goes first -> fake priority handling
std::vector<MPQArchive*> archives; std::vector<MPQArchive*> archives;
@ -537,7 +537,8 @@ int main(int argc, char ** argv)
std::vector<std::string> archiveNames; std::vector<std::string> archiveNames;
fillArchiveNameVector(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())); archives.push_back(new MPQArchive(archiveNames[i].c_str()));
} }
ExtractWmo(archiveNames); ExtractWmo(archiveNames);
@ -550,11 +551,11 @@ int main(int argc, char ** argv)
dbc->open(); dbc->open();
map_count=dbc->getRecordCount (); map_count=dbc->getRecordCount ();
map_ids=new map_id[map_count]; 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); map_ids[x].id=dbc->getRecord (x).getUInt(0);
strcpy(map_ids[x].name,dbc->getRecord(x).getString(1)); strcpy(map_ids[x].name,dbc->getRecord(x).getString(1));
printf("Map - %s\n",map_ids[x].name); printf("Map - %s\n",map_ids[x].name);
} }
delete dbc; delete dbc;
@ -564,7 +565,8 @@ int main(int argc, char ** argv)
} }
clreol(); 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); printf("ERROR: Extract %s. Work NOT complete.\n Precise vector data=%d.\nPress any key.\n",versionString, preciseVectorData);
_getch(); _getch();
} }

View file

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

@ -1,7 +1,7 @@
#ifndef WDTFILE_H #ifndef WDTFILE_H
#define WDTFILE_H #define WDTFILE_H
#define __STORMLIB_SELF__ #define __STORMLIB_SELF__
#include "mpq.h" #include "mpq.h"
#include "adtfile.h" #include "adtfile.h"
@ -12,19 +12,19 @@
class WDTFile class WDTFile
{ {
public: public:
WDTFile(char* file_name, char* file_name1); WDTFile(char* file_name, char* file_name1);
~WDTFile(void); ~WDTFile(void);
bool init(char *map_id); bool init(char *map_id);
string* gWmoInstansName; string* gWmoInstansName;
int gnWMO, nMaps; int gnWMO, nMaps;
ADTFile* GetMap(int x, int z); ADTFile* GetMap(int x, int z);
private: private:
MPQFile WDT; MPQFile WDT;
bool maps[64][64]; bool maps[64][64];
string filename; string filename;
}; };
#endif #endif

View file

@ -6,444 +6,457 @@
using namespace std; using namespace std;
WMORoot::WMORoot(std::string &filename) : filename(filename) WMORoot::WMORoot(std::string &filename) : filename(filename)
{ {
} }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
bool WMORoot::open() bool WMORoot::open()
{ {
MPQFile f(filename.c_str());
if(f.isEof ())
{
printf("No such file.\n");
return false;
}
MPQFile f(filename.c_str()); size_t size;
if(f.isEof ()) char fourcc[5];
{ bbcorn1[3] = 0;
printf("No such file.\n"); bbcorn2[3]= 0;
return false;
}
size_t size; while (!f.isEof())
char fourcc[5]; {
bbcorn1[3] = 0; f.read(fourcc,4);
bbcorn2[3]= 0; f.read(&size, 4);
while (!f.isEof ()) flipcc(fourcc);
{ fourcc[4] = 0;
f.read(fourcc,4);
f.read(&size, 4);
flipcc(fourcc); size_t nextpos = f.getPos() + size;
fourcc[4] = 0;
size_t nextpos = f.getPos() + size; if (!strcmp(fourcc,"MOHD"))//header
{
if (!strcmp(fourcc,"MOHD"))//header f.read(&nTextures, 4);
{ f.read(&nGroups, 4);
f.read(&nP, 4);
f.read(&nTextures, 4); f.read(&nLights, 4);
f.read(&nGroups, 4); f.read(&nModels, 4);
f.read(&nP, 4); f.read(&nDoodads, 4);
f.read(&nLights, 4); f.read(&nDoodadSets, 4);
f.read(&nModels, 4); f.read(&col, 4);
f.read(&nDoodads, 4); f.read(&RootID, 4);
f.read(&nDoodadSets, 4); f.read(bbcorn1,12);
f.read(&col, 4); f.read(bbcorn2,12);
f.read(&RootID, 4); break;
f.read(bbcorn1,12); }
f.read(bbcorn2,12); /*
break; else if (!strcmp(fourcc,"MOTX"))
} {
/* }
else if (!strcmp(fourcc,"MOTX")) else if (!strcmp(fourcc,"MOMT"))
{ {
}
} else if (!strcmp(fourcc,"MOGN"))
else if (!strcmp(fourcc,"MOMT")) {
{ }
else if (!strcmp(fourcc,"MOGI"))
} {
else if (!strcmp(fourcc,"MOGN")) }
{ else if (!strcmp(fourcc,"MOLT"))
{
} }
else if (!strcmp(fourcc,"MOGI")) else if (!strcmp(fourcc,"MODN"))
{ {
}
} else if (!strcmp(fourcc,"MODS"))
else if (!strcmp(fourcc,"MOLT")) {
{ }
else if (!strcmp(fourcc,"MODD"))
} {
else if (!strcmp(fourcc,"MODN")) }
{ else if (!strcmp(fourcc,"MOSB"))
{
} }
else if (!strcmp(fourcc,"MODS")) else if (!strcmp(fourcc,"MOPV"))
{ {
}
} else if (!strcmp(fourcc,"MOPT"))
else if (!strcmp(fourcc,"MODD")) {
{ }
else if (!strcmp(fourcc,"MOPR"))
} {
else if (!strcmp(fourcc,"MOSB")) }
{ else if (!strcmp(fourcc,"MFOG"))
{
} }
else if (!strcmp(fourcc,"MOPV")) */
{ f.seek((int)nextpos);
}
} f.close ();
else if (!strcmp(fourcc,"MOPT")) return true;
{
}
else if (!strcmp(fourcc,"MOPR"))
{
}
else if (!strcmp(fourcc,"MFOG"))
{
}
*/
f.seek((int)nextpos);
}
f.close ();
return true;
} }
//---------------------------------------------------------------------------
bool WMORoot::ConvertToVMAPRootWmo(FILE *pOutfile) bool WMORoot::ConvertToVMAPRootWmo(FILE *pOutfile)
{ {
//printf("Convert RootWmo...\n"); //printf("Convert RootWmo...\n");
fwrite("VMAP002",1,8,pOutfile); fwrite("VMAP002",1,8,pOutfile);
unsigned int nVectors = 0; unsigned int nVectors = 0;
fwrite(&nVectors,sizeof(nVectors),1,pOutfile); // will be filled later fwrite(&nVectors,sizeof(nVectors),1,pOutfile); // will be filled later
fwrite(&nGroups,4,1,pOutfile); fwrite(&nGroups,4,1,pOutfile);
return true; return true;
} }
//----------------------------------------------------------------------------
WMORoot::~WMORoot() WMORoot::~WMORoot()
{ {
} }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
WMOGroup::WMOGroup(std::string &filename) : filename(filename) WMOGroup::WMOGroup(std::string &filename) : filename(filename)
{ {
} }
//---------------------------------------------------------------------------
bool WMOGroup::open() bool WMOGroup::open()
{ {
MPQFile f(filename.c_str()); MPQFile f(filename.c_str());
if(f.isEof ()) if(f.isEof ())
{ {
printf("No such file.\n"); printf("No such file.\n");
return false; return false;
} }
size_t size; size_t size;
char fourcc[5]; char fourcc[5];
bbcorn1[3] = 0; bbcorn1[3] = 0;
bbcorn2[3] = 0; bbcorn2[3] = 0;
while (!f.isEof ()) while (!f.isEof())
{ {
f.read(fourcc,4); f.read(fourcc,4);
f.read(&size, 4); f.read(&size, 4);
flipcc(fourcc); flipcc(fourcc);
if (!strcmp(fourcc,"MOGP"))//Fix sizeoff = Data size. if (!strcmp(fourcc,"MOGP"))//Fix sizeoff = Data size.
{ {
size = 68; size = 68;
} }
fourcc[4] = 0; fourcc[4] = 0;
size_t nextpos = f.getPos() + size; size_t nextpos = f.getPos() + size;
LiquEx_size = 0; LiquEx_size = 0;
liquflags = 0; liquflags = 0;
if (!strcmp(fourcc,"MOGP"))//header if (!strcmp(fourcc,"MOGP"))//header
{ {
f.seekRelative(-4); f.seekRelative(-4);
f.read(&offsize, 4); f.read(&offsize, 4);
f.read(&flag, 4); f.read(&flag, 4);
f.read(&flag1, 4); f.read(&flag1, 4);
f.read(&Xid, 4); f.read(&Xid, 4);
f.read(bbcorn1, 12); f.read(bbcorn1, 12);
f.read(bbcorn2, 12); f.read(bbcorn2, 12);
f.read(&Xid2, 4); f.read(&Xid2, 4);
f.read(&Xid3, 4); f.read(&Xid3, 4);
f.read(&zero1, 4); f.read(&zero1, 4);
f.read(&Xflag, 4); f.read(&Xflag, 4);
f.read(&nTexture,4); f.read(&nTexture,4);
f.read(&GroupID,4); f.read(&GroupID,4);
} }
else if (!strcmp(fourcc,"MOPY")) else if (!strcmp(fourcc,"MOPY"))
{ {
MOPY = new char[size]; MOPY = new char[size];
mopy_size = size; mopy_size = size;
nTriangles = (int)size / 2; nTriangles = (int)size / 2;
f.read(MOPY, size); f.read(MOPY, size);
} }
else if (!strcmp(fourcc,"MOVI")) else if (!strcmp(fourcc,"MOVI"))
{ {
MOVI = new uint16[size/2]; MOVI = new uint16[size/2];
f.read(MOVI, size); 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;
} for (int j=0; j<hlq.yverts; ++j)
else if (!strcmp(fourcc,"MOVT")) {
{ for (int i=0; i<hlq.xverts; ++i)
MOVT = new float[size/4]; {
f.read(MOVT, size); LiquEx[p++] = hlq.pos_x + tilesize * i;
nVertices = (int)size / 12; LiquEx[p++] = hlq.pos_z;
} LiquEx[p++] = ydir * (hlq.pos_y + tilesize * j);
else if (!strcmp(fourcc,"MONR")) }
{ }
} }
else if (!strcmp(fourcc,"MOTV")) f.seek((int)nextpos);
{ }
} f.close();
else if (!strcmp(fourcc,"MOBA")) return true;
{
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;
} }
//----------------------------------------------------------------------------
int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, bool pPreciseVectorData) int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, bool pPreciseVectorData)
{ {
if(pPreciseVectorData) { if(pPreciseVectorData)
fwrite(&liquflags,sizeof(uint32),1,output); {
char GRP[] = "GRP "; fwrite(&liquflags,sizeof(uint32),1,output);
fwrite(GRP,1,4,output); char GRP[] = "GRP ";
fwrite(GRP,1,4,output);
int k = 0; int k = 0;
int moba_batch = moba_size/12; int moba_batch = moba_size/12;
MobaEx = new int[moba_batch*4]; MobaEx = new int[moba_batch*4];
for(int i=8; i<moba_size; i+=12) for(int i=8; i<moba_size; i+=12)
{ {
MobaEx[k++] = MOBA[i]; MobaEx[k++] = MOBA[i];
} }
delete [] MOBA; delete [] MOBA;
int moba_size_grp = moba_batch*4+4; int moba_size_grp = moba_batch*4+4;
fwrite(&moba_size_grp,4,1,output); fwrite(&moba_size_grp,4,1,output);
fwrite(&moba_batch,4,1,output); fwrite(&moba_batch,4,1,output);
fwrite(MobaEx,4,k,output); fwrite(MobaEx,4,k,output);
delete [] MobaEx; 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); } if(fwrite("INDX",4, 1, output) != 1)
int wsize = sizeof(uint32) + sizeof(unsigned short) * nIdexes; {
if(fwrite(&wsize, sizeof(int), 1, output) != 1) { printf("Error while writing file wsize"); } printf("Error while writing file nbraches ID");
if(fwrite(&nIdexes, sizeof(uint32), 1, output) != 1) { printf("Error while writing file nIndexes"); exit(0); } exit(0);
if(nIdexes >0) { }
if(fwrite(MOVI, sizeof(unsigned short), nIdexes, output) != nIdexes) { printf("Error while writing file indexarray"); 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); } if(fwrite("VERT",4, 1, output) != 1)
wsize = sizeof(int) + sizeof(float) * 3 * nVertices; {
if(fwrite(&wsize, sizeof(int), 1, output) != 1) { printf("Error while writing file wsize"); } printf("Error while writing file nbraches ID");
if(fwrite(&nVertices, sizeof(int), 1, output) != 1) { printf("Error while writing file nVertices"); exit(0); } exit(0);
if(nVertices >0) { }
if(fwrite(MOVT, sizeof(float)*3, nVertices, output) != nVertices) { printf("Error while writing file vectors"); 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) if(LiquEx_size != 0)
{ {
int LIQU_h[] = {0x5551494C,LiquEx_size+8,hlq_xverts,hlq_yverts};// "LIQU" int LIQU_h[] = {0x5551494C,LiquEx_size+8,hlq_xverts,hlq_yverts};// "LIQU"
fwrite(LIQU_h,4,4,output); fwrite(LIQU_h,4,4,output);
fwrite(LiquEx,4,LiquEx_size/4,output); fwrite(LiquEx,4,LiquEx_size/4,output);
delete [] LiquEx; delete [] LiquEx;
} }
return nTriangles; return nTriangles;
} else { }
//printf("Convert GroupWmo...\n"); else
//-------GRP ------------------------------------- {
fwrite(&liquflags,sizeof(uint32),1,output); //printf("Convert GroupWmo...\n");
char GRP[] = "GRP "; //-------GRP -------------------------------------
fwrite(GRP,1,4,output); fwrite(&liquflags,sizeof(uint32),1,output);
int k = 0; char GRP[] = "GRP ";
int moba_batch = moba_size/12; fwrite(GRP,1,4,output);
MobaEx = new int[moba_batch*4]; int k = 0;
for(int i=8; i<moba_size; i+=12) int moba_batch = moba_size/12;
{ MobaEx = new int[moba_batch*4];
MobaEx[k++] = MOBA[i]; for(int i=8; i<moba_size; i+=12)
} {
delete [] MOBA; MobaEx[k++] = MOBA[i];
int moba_size_grp = moba_batch*4+4; }
fwrite(&moba_size_grp,4,1,output); delete [] MOBA;
fwrite(&moba_batch,4,1,output); int moba_size_grp = moba_batch*4+4;
fwrite(MobaEx,4,k,output); fwrite(&moba_size_grp,4,1,output);
delete [] MobaEx; fwrite(&moba_batch,4,1,output);
fwrite(MobaEx,4,k,output);
delete [] MobaEx;
//-------INDX------------------------------------ //-------INDX------------------------------------
//-------MOPY-------- //-------MOPY--------
int n = 0; int n = 0;
int j = 0; int j = 0;
MopyEx = new char[mopy_size]; MopyEx = new char[mopy_size];
IndexExTr = new int[mopy_size]; IndexExTr = new int[mopy_size];
for (int i=0; i<mopy_size; i+=2) for (int i=0; i<mopy_size; i+=2)
{ {
// Skip no collision triangles // Skip no collision triangles
if ((int)MOPY[i]&WMO_MATERIAL_NO_COLLISION) if ((int)MOPY[i]&WMO_MATERIAL_NO_COLLISION)
continue; continue;
// Use only this triangles // Use only this triangles
if ((int)MOPY[i]&(WMO_MATERIAL_HINT|WMO_MATERIAL_COLLIDE_HIT)) if ((int)MOPY[i]&(WMO_MATERIAL_HINT|WMO_MATERIAL_COLLIDE_HIT))
{ {
MopyEx[n] = MOPY[i]; MopyEx[n] = MOPY[i];
MopyEx[(n+1)] = MOPY[(i+1)]; MopyEx[(n+1)] = MOPY[(i+1)];
IndexExTr[j] = i/2; IndexExTr[j] = i/2;
j+=1; j+=1;
n+=2; n+=2;
} }
} }
MopyEx_size = n; MopyEx_size = n;
IndexExTr_size = j; IndexExTr_size = j;
delete [] MOPY; delete [] MOPY;
delete [] MopyEx; delete [] MopyEx;
//---------MOVI----------- //---------MOVI-----------
MoviEx = new uint16[IndexExTr_size*3]; MoviEx = new uint16[IndexExTr_size*3];
int m = 0; int m = 0;
for (int i=0; i<IndexExTr_size; i++) for (int i=0; i<IndexExTr_size; ++i)
{ {
int n = 0; int n = 0;
n = IndexExTr[i]*3; n = IndexExTr[i]*3;
for (int x=0; x<3; x++) for (int x=0; x<3; ++x)
{ {
MoviEx[m] = MOVI[n]; MoviEx[m] = MOVI[n];
n++; n++;
m++; m++;
} }
} }
delete [] MOVI; delete [] MOVI;
MoviExSort = new uint16[IndexExTr_size*3]; MoviExSort = new uint16[IndexExTr_size*3];
for(int y=0; y<IndexExTr_size*3; y++) for(int y=0; y<IndexExTr_size*3; ++y)
{ {
MoviExSort[y]=MoviEx[y]; MoviExSort[y]=MoviEx[y];
} }
uint16 hold; uint16 hold;
for (int pass = 1; pass < IndexExTr_size*3; pass++) for (int pass = 1; pass < IndexExTr_size*3; ++pass)
{ {
for (int i=0; i < IndexExTr_size*3-1; i++) for (int i=0; i < IndexExTr_size*3-1; ++i)
{ {
if (MoviExSort[i] > MoviExSort[i+1]) if (MoviExSort[i] > MoviExSort[i+1])
{ {
hold = MoviExSort[i]; hold = MoviExSort[i];
MoviExSort[i] = MoviExSort[i+1]; MoviExSort[i] = MoviExSort[i+1];
MoviExSort[i+1] = hold; MoviExSort[i+1] = hold;
} }
//double = 65535 //double = 65535
else else
if (MoviExSort[i] == MoviExSort[i+1]) if (MoviExSort[i] == MoviExSort[i+1])
MoviExSort[i+1] = 65535; MoviExSort[i+1] = 65535;
} }
} }
// double delet // double delet
uint16 s = 0; uint16 s = 0;
for (int i=0; i < IndexExTr_size*3; i++) for (int i=0; i < IndexExTr_size*3; ++i)
{ {
if (MoviExSort[i]!=65535) if (MoviExSort[i]!=65535)
{ {
MoviExSort[s] = MoviExSort[i]; MoviExSort[s] = MoviExSort[i];
s++; s++;
} }
} }
MovtExSort = new uint16[s]; MovtExSort = new uint16[s];
for (int i=0; i < s; i++) for (int i=0; i < s; ++i)
{ {
MovtExSort[i] = MoviExSort[i]; MovtExSort[i] = MoviExSort[i];
} }
for (int i=0; i < IndexExTr_size*3; i++) for (int i=0; i < IndexExTr_size*3; ++i)
{ {
uint16 b = MoviEx[i]; uint16 b = MoviEx[i];
for (uint16 x = 0; x < s; x++) for (uint16 x = 0; x < s; ++x)
{ {
if(MoviExSort[x] == b) 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; delete [] MoviEx;
break; delete [] MoviExSort;
} delete [] IndexExTr;
}
} //----------VERT---------
int INDX[] = {0x58444E49,IndexExTr_size*6+4,IndexExTr_size*3}; //-----MOVT----------
fwrite(INDX,4,3,output); int d = 0;
fwrite(MoviEx,2,IndexExTr_size*3,output); 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 [] MOVT;
delete [] MoviExSort; delete [] MovtEx;
delete [] IndexExTr; delete [] MovtExSort;
//----------VERT--------- //---------------------------------------------
//-----MOVT---------- return IndexExTr_size;
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;
}
} }
WMOGroup::~WMOGroup() WMOGroup::~WMOGroup()
@ -452,84 +465,83 @@ WMOGroup::~WMOGroup()
WMOInstance::WMOInstance(MPQFile &f,const char* WmoInstName,const char*MapName, FILE *pDirfile) 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]; float ff[3];
f.read(&id, 4); f.read(&id, 4);
f.read(ff,12); f.read(ff,12);
pos = Vec3D(ff[0],ff[1],ff[2]); pos = Vec3D(ff[0],ff[1],ff[2]);
f.read(ff,12); f.read(ff,12);
rot = Vec3D(ff[0],ff[1],ff[2]); rot = Vec3D(ff[0],ff[1],ff[2]);
f.read(ff,12); f.read(ff,12);
pos2 = Vec3D(ff[0],ff[1],ff[2]); pos2 = Vec3D(ff[0],ff[1],ff[2]);
f.read(ff,12); f.read(ff,12);
pos3 = Vec3D(ff[0],ff[1],ff[2]); pos3 = Vec3D(ff[0],ff[1],ff[2]);
f.read(&d2,4); f.read(&d2,4);
f.read(&d3,4); f.read(&d3,4);
doodadset = (d2 & 0xFFFF0000) >> 16; doodadset = (d2 & 0xFFFF0000) >> 16;
int realx1 = (int) ((float) pos2.x / 533.333333f); int realx1 = (int) ((float) pos2.x / 533.333333f);
int realy1 = (int) ((float) pos2.z / 533.333333f); int realy1 = (int) ((float) pos2.z / 533.333333f);
int realx2 = (int) ((float) pos3.x / 533.333333f); int realx2 = (int) ((float) pos3.x / 533.333333f);
int realy2 = (int) ((float) pos3.z / 533.333333f); int realy2 = (int) ((float) pos3.z / 533.333333f);
if(realx1 < 0) if(realx1 < 0)
{ {
realx1 +=20; realx2+=20; realx1 +=20; realx2+=20;
} }
if(realy1 < 0) if(realy1 < 0)
{ {
realy1 +=20; realy2+=20; realy1 +=20; realy2+=20;
} // hack to prevent neg. values } // hack to prevent neg. values
//-----------add_in _dir_file---------------- //-----------add_in _dir_file----------------
char tempname[512]; char tempname[512];
// const char dirname[] = "buildings\\dir"; // const char dirname[] = "buildings\\dir";
sprintf(tempname, "buildings\\%s", WmoInstName); sprintf(tempname, "buildings\\%s", WmoInstName);
FILE *input; FILE *input;
input = fopen(tempname, "r+b"); 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;
}
/* FILE *dirfile; if(!input)
dirfile = fopen(dirname, "ab"); return;
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); 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 class WMORoot
{ {
public: public:
int nTextures, nGroups, nP, nLights, nModels, nDoodads, nDoodadSets, RootID; int nTextures, nGroups, nP, nLights, nModels, nDoodads, nDoodadSets, RootID;
unsigned int col; unsigned int col;
int bbcorn1[3]; int bbcorn1[3];
int bbcorn2[3]; int bbcorn2[3];
WMORoot(std::string &filename); WMORoot(std::string &filename);
~WMORoot(); ~WMORoot();
bool open(); bool open();
bool ConvertToVMAPRootWmo(FILE *output); bool ConvertToVMAPRootWmo(FILE *output);
private: private:
std::string filename; std::string filename;
char outfilename; char outfilename;
}; };
class WMOGroup class WMOGroup
{ {
public: public:
int offsize,flag,flag1,Xid,Xid2,Xid3,zero1,Xflag,nTexture,GroupID;
int offsize,flag,flag1,Xid,Xid2,Xid3,zero1,Xflag,nTexture,GroupID; int mopy_size,moba_size,hlq_xverts,hlq_yverts;
int mopy_size,moba_size,hlq_xverts,hlq_yverts; int MopyEx_size,IndexExTr_size,LiquEx_size;
int MopyEx_size,IndexExTr_size,LiquEx_size; unsigned int nVertices; // number when loaded
unsigned int nVertices; // number when loaded int nTriangles; // number when loaded
int nTriangles; // number when loaded int bbcorn1[3];
int bbcorn1[3]; int bbcorn2[3];
int bbcorn2[3]; int * IndexExTr;
int * IndexExTr; char* MOPY;
char* MOPY; char* MopyEx;
char* MopyEx; uint16* MOVI;
uint16* MOVI; uint16* MoviEx;
uint16* MoviEx; uint16* MoviExSort;
uint16* MoviExSort; float* MOVT;
float* MOVT; float* MovtEx;
float* MovtEx; uint16* MovtExSort;
uint16* MovtExSort; float* MONR;
float* MONR; float* MonrEx;
float* MonrEx; uint16* MOBA;
uint16* MOBA; int* MobaEx;
int* MobaEx; float* LiquEx;
float* LiquEx; uint32 liquflags;
uint32 liquflags;
WMOGroup(std::string &filename);
~WMOGroup();
bool open(); WMOGroup(std::string &filename);
int ConvertToVMAPGroupWmo(FILE *output, bool pPreciseVectorData); ~WMOGroup();
bool open();
int ConvertToVMAPGroupWmo(FILE *output, bool pPreciseVectorData);
private: private:
std::string filename; std::string filename;
char outfilename; char outfilename;
}; };
struct WMOLiquidHeader struct WMOLiquidHeader
{ {
int xverts, yverts, xtiles, ytiles; int xverts, yverts, xtiles, ytiles;
float pos_x; float pos_x;
float pos_y; float pos_y;
float pos_z; float pos_z;
short type; short type;
}; };
class WMOInstance class WMOInstance
{ {
static std::set<int> ids; static std::set<int> ids;
public: public:
string MapName; string MapName;
int currx; int currx;
int curry; int curry;
WMOGroup *wmo; WMOGroup *wmo;
Vec3D pos; Vec3D pos;
Vec3D pos2, pos3, rot; Vec3D pos2, pos3, rot;
int indx,id, d2, d3; int indx,id, d2, d3;
int doodadset; 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 #endif

View file

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