From 259114635e38d5882a860dcc0ceccacd70ee30ac Mon Sep 17 00:00:00 2001 From: H0zen Date: Tue, 15 Sep 2015 01:46:08 +0300 Subject: [PATCH] Fix a bug in previous commit where some wmo's were not extracted at all. Also: - Skip garbage in GameObjectDisplayInfo.dbc. - Fix the order of library linkage in extractor. - Fix a false positive in vmap-assembler. - Fix an include path in mmap generator --- src/game/vmap/TileAssembler.cpp | 3 +- src/tools/Movemap-Generator/MMapCommon.h | 1 + src/tools/vmap-extractor/CMakeLists.txt | 2 +- src/tools/vmap-extractor/adtfile.cpp | 14 +- src/tools/vmap-extractor/adtfile.h | 4 - src/tools/vmap-extractor/model.cpp | 94 ++++------ src/tools/vmap-extractor/model.h | 19 +- src/tools/vmap-extractor/vec3d.h | 220 ++--------------------- src/tools/vmap-extractor/vmapexport.cpp | 108 ----------- src/tools/vmap-extractor/wdtfile.cpp | 6 +- src/tools/vmap-extractor/wdtfile.h | 10 +- src/tools/vmap-extractor/wmo.cpp | 110 +++++++++++- src/tools/vmap-extractor/wmo.h | 19 +- 13 files changed, 188 insertions(+), 422 deletions(-) diff --git a/src/game/vmap/TileAssembler.cpp b/src/game/vmap/TileAssembler.cpp index c7e633379cccb..ad5a4a28480c4 100644 --- a/src/game/vmap/TileAssembler.cpp +++ b/src/game/vmap/TileAssembler.cpp @@ -355,7 +355,8 @@ namespace VMAP { if (fread(&displayId, sizeof(uint32), 1, model_list) <= 0) { - std::cout << "\nFile '" << GAMEOBJECT_MODELS << "' seems to be corrupted" << std::endl; + if (!feof(model_list)) + std::cout << "\nFile '" << GAMEOBJECT_MODELS << "' seems to be corrupted" << std::endl; break; } if (fread(&name_length, sizeof(uint32), 1, model_list) <= 0) diff --git a/src/tools/Movemap-Generator/MMapCommon.h b/src/tools/Movemap-Generator/MMapCommon.h index e84f140a9bfde..68e14d197f59f 100644 --- a/src/tools/Movemap-Generator/MMapCommon.h +++ b/src/tools/Movemap-Generator/MMapCommon.h @@ -32,6 +32,7 @@ #include #include +#include #include "Platform/Define.h" diff --git a/src/tools/vmap-extractor/CMakeLists.txt b/src/tools/vmap-extractor/CMakeLists.txt index 2315e3dd5026e..ba2d1dda686a7 100644 --- a/src/tools/vmap-extractor/CMakeLists.txt +++ b/src/tools/vmap-extractor/CMakeLists.txt @@ -39,7 +39,7 @@ add_executable(${EXECUTABLE_NAME} ${EXECUTABLE_SRCS} ${CMAKE_SOURCE_DIR}/src/shared/Auth/md5.c ) -target_link_libraries(${EXECUTABLE_NAME} libmpq loadlib bzip2 zlib) +target_link_libraries(${EXECUTABLE_NAME} loadlib libmpq bzip2 zlib) #Output the compiled exes to build/bin/$(Configuration)/tools directory on windows by default if(WIN32) diff --git a/src/tools/vmap-extractor/adtfile.cpp b/src/tools/vmap-extractor/adtfile.cpp index ebd549cec60c6..15792e54a04c5 100644 --- a/src/tools/vmap-extractor/adtfile.cpp +++ b/src/tools/vmap-extractor/adtfile.cpp @@ -22,20 +22,14 @@ * and lore are copyrighted by Blizzard Entertainment, Inc. */ -#include "vmapexport.h" -#include "adtfile.h" - #include #include - -#ifdef WIN32 -#define snprintf _snprintf -#endif - +#include "vmapexport.h" +#include "adtfile.h" ADTFile::ADTFile(char* filename): ADT(filename) { - AdtFilename.append(filename); + AdtFilename.assign(filename); } bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, StringSet& failedPaths) @@ -97,7 +91,6 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, StringSet& failed std::string uName; ExtractSingleModel(path, uName, failedPaths); ModelInstansName[t++] = uName; - p = p + strlen(p) + 1; } delete[] buf; @@ -116,7 +109,6 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, StringSet& failed { std::string path(p); WmoInstansName[q++] = GetUniformName(path); -; p = p + strlen(p) + 1; } delete[] buf; diff --git a/src/tools/vmap-extractor/adtfile.h b/src/tools/vmap-extractor/adtfile.h index b2c87fb88e132..4dff3f13c0328 100644 --- a/src/tools/vmap-extractor/adtfile.h +++ b/src/tools/vmap-extractor/adtfile.h @@ -25,7 +25,6 @@ #ifndef ADT_H #define ADT_H -#include #include #include "wmo.h" #include "vmapexport.h" @@ -35,8 +34,6 @@ #define CHUNKSIZE ((TILESIZE) / 16.0f) #define UNITSIZE (CHUNKSIZE / 8.0f) -class Liquid; - /** * @brief * @@ -142,7 +139,6 @@ struct MapChunkHeader uint32 effectId; /**< TODO */ }; - /** * @brief * diff --git a/src/tools/vmap-extractor/model.cpp b/src/tools/vmap-extractor/model.cpp index 7b2cd80f84617..b7c86ad53eb77 100644 --- a/src/tools/vmap-extractor/model.cpp +++ b/src/tools/vmap-extractor/model.cpp @@ -22,27 +22,15 @@ * and lore are copyrighted by Blizzard Entertainment, Inc. */ -#include "vmapexport.h" #include #include #include + #include #include "model.h" #include "wmo.h" #include "dbcfile.h" - -using namespace std; - -Vec3D fixCoordSystem(Vec3D v) -{ - return Vec3D(v.x, v.z, -v.y); -} - -Vec3D fixCoordSystem2(Vec3D v) -{ - return Vec3D(v.x, v.z, v.y); -} - +#include "vmapexport.h" Model::Model(std::string& filename) : filename(filename), vertices(0), indices(0) { @@ -101,28 +89,28 @@ bool Model::ConvertToVMAPModel(std::string& outfilename) return false; } - std::fwrite(szRawVMAPMagic, 8, 1, output); + fwrite(szRawVMAPMagic, 8, 1, output); uint32 nVertices = 0; nVertices = header.nBoundingVertices; - std::fwrite(&nVertices, sizeof(int), 1, output); + fwrite(&nVertices, sizeof(int), 1, output); uint32 nofgroups = 1; - std::fwrite(&nofgroups, sizeof(uint32), 1, output); - std::fwrite(N, 4 * 3, 1, output); // rootwmoid, flags, groupid - std::fwrite(N, sizeof(float), 3 * 2, output); //bbox, only needed for WMO currently - std::fwrite(N, 4, 1, output); // liquidflags - std::fwrite("GRP ", 4, 1, output); + fwrite(&nofgroups, sizeof(uint32), 1, output); + fwrite(N, 4 * 3, 1, output); // rootwmoid, flags, groupid + fwrite(N, sizeof(float), 3 * 2, output); //bbox, only needed for WMO currently + fwrite(N, 4, 1, output); // liquidflags + fwrite("GRP ", 4, 1, output); uint32 branches = 1; int wsize; wsize = sizeof(branches) + sizeof(uint32) * branches; - std::fwrite(&wsize, sizeof(int), 1, output); - std::fwrite(&branches, sizeof(branches), 1, output); + fwrite(&wsize, sizeof(int), 1, output); + fwrite(&branches, sizeof(branches), 1, output); uint32 nIndexes = (uint32) nIndices; - std::fwrite(&nIndexes, sizeof(uint32), 1, output); - std::fwrite("INDX", 4, 1, output); + fwrite(&nIndexes, sizeof(uint32), 1, output); + fwrite("INDX", 4, 1, output); wsize = sizeof(uint32) + sizeof(unsigned short) * nIndexes; - std::fwrite(&wsize, sizeof(int), 1, output); - std::fwrite(&nIndexes, sizeof(uint32), 1, output); + fwrite(&wsize, sizeof(int), 1, output); + fwrite(&nIndexes, sizeof(uint32), 1, output); if (nIndexes > 0) { for (uint32 i = 0; i < nIndices; ++i) @@ -135,12 +123,12 @@ bool Model::ConvertToVMAPModel(std::string& outfilename) indices[i+1] = tmp; } } - std::fwrite(indices, sizeof(unsigned short), nIndexes, output); + fwrite(indices, sizeof(unsigned short), nIndexes, output); } - std::fwrite("VERT", 4, 1, output); + fwrite("VERT", 4, 1, output); wsize = sizeof(int) + sizeof(float) * 3 * nVertices; - std::fwrite(&wsize, sizeof(int), 1, output); - std::fwrite(&nVertices, sizeof(int), 1, output); + fwrite(&wsize, sizeof(int), 1, output); + fwrite(&nVertices, sizeof(int), 1, output); if (nVertices > 0) { for (uint32 vpos = 0; vpos < nVertices; ++vpos) @@ -149,7 +137,7 @@ bool Model::ConvertToVMAPModel(std::string& outfilename) vertices[vpos].y = -vertices[vpos].z; vertices[vpos].z = tmp; } - std::fwrite(vertices, sizeof(float) * 3, nVertices, output); + fwrite(vertices, sizeof(float) * 3, nVertices, output); } fclose(output); @@ -198,18 +186,18 @@ ModelInstance::ModelInstance(MPQFile& f, string& ModelInstName, uint32 mapID, ui uint32 flags = MOD_M2; if (tileX == 65 && tileY == 65) { flags |= MOD_WORLDSPAWN; } //write mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, name - std::fwrite(&mapID, sizeof(uint32), 1, pDirfile); - std::fwrite(&tileX, sizeof(uint32), 1, pDirfile); - std::fwrite(&tileY, sizeof(uint32), 1, pDirfile); - std::fwrite(&flags, sizeof(uint32), 1, pDirfile); - std::fwrite(&adtId, sizeof(uint16), 1, pDirfile); - std::fwrite(&id, sizeof(uint32), 1, pDirfile); - std::fwrite(&pos, sizeof(float), 3, pDirfile); - std::fwrite(&rot, sizeof(float), 3, pDirfile); - std::fwrite(&sc, sizeof(float), 1, pDirfile); + fwrite(&mapID, sizeof(uint32), 1, pDirfile); + fwrite(&tileX, sizeof(uint32), 1, pDirfile); + fwrite(&tileY, sizeof(uint32), 1, pDirfile); + fwrite(&flags, sizeof(uint32), 1, pDirfile); + fwrite(&adtId, sizeof(uint16), 1, pDirfile); + fwrite(&id, sizeof(uint32), 1, pDirfile); + fwrite(&pos, sizeof(float), 3, pDirfile); + fwrite(&rot, sizeof(float), 3, pDirfile); + fwrite(&sc, sizeof(float), 1, pDirfile); uint32 nlen = ModelInstName.length(); - std::fwrite(&nlen, sizeof(uint32), 1, pDirfile); - std::fwrite(ModelInstName.c_str(), sizeof(char), nlen, pDirfile); + fwrite(&nlen, sizeof(uint32), 1, pDirfile); + fwrite(ModelInstName.c_str(), sizeof(char), nlen, pDirfile); } @@ -218,9 +206,9 @@ bool ExtractSingleModel(std::string& origPath, std::string& fixedName, StringSet string ext = GetExtension(origPath); // < 3.1.0 ADT MMDX section store filename.mdx filenames for corresponded .m2 file - if (ext == "mdx") + if ((ext == "mdx") || (ext=="mdl")) { - // replace .mdx -> .m2 + // replace .md[l,x] -> .m2 origPath.erase(origPath.length() - 2, 2); origPath.append("2"); } @@ -276,25 +264,21 @@ void ExtractGameobjectModels() bool result = false; if (ch_ext == "wmo") { + name = GetUniformName(path); result = ExtractSingleWmo(path); } - else if (ch_ext == "mdl") - { - // TODO: extract .mdl files, if needed - continue; - } else { result = ExtractSingleModel(path, name, failedPaths); } - if (result) + if (result && FileExists((basepath + name).c_str())) { uint32 displayId = it->getUInt(0); uint32 path_length = name.length(); - std::fwrite(&displayId, sizeof(uint32), 1, model_list); - std::fwrite(&path_length, sizeof(uint32), 1, model_list); - std::fwrite(name.c_str(), sizeof(char), path_length, model_list); + fwrite(&displayId, sizeof(uint32), 1, model_list); + fwrite(&path_length, sizeof(uint32), 1, model_list); + fwrite(name.c_str(), sizeof(char), path_length, model_list); } } @@ -309,4 +293,4 @@ void ExtractGameobjectModels() } printf("Done!\n"); -} \ No newline at end of file +} diff --git a/src/tools/vmap-extractor/model.h b/src/tools/vmap-extractor/model.h index 934fd90313e9a..0325607236054 100644 --- a/src/tools/vmap-extractor/model.h +++ b/src/tools/vmap-extractor/model.h @@ -25,22 +25,11 @@ #ifndef MODEL_H #define MODEL_H +#include #include #include "vec3d.h" #include "modelheaders.h" -#include -#include "vmapexport.h" - -class WMOInstance; -class MPQFile; - -/** - * @brief - * - * @param v - * @return Vec3D - */ -Vec3D fixCoordSystem(Vec3D v); +#include "wmo.h" /** * @brief @@ -61,7 +50,7 @@ class Model * @param failedPaths * @return bool */ - bool open(StringSet& failedPaths); + bool open(std::set& failedPaths); /** * @brief * @@ -142,7 +131,7 @@ class ModelInstance * @param failedPaths Set to collect errors * @return bool */ -bool ExtractSingleModel(std::string& origPath, std::string& fixedName, StringSet& failedPaths); +bool ExtractSingleModel(std::string& origPath, std::string& fixedName, std::set& failedPaths); /** * @brief diff --git a/src/tools/vmap-extractor/vec3d.h b/src/tools/vmap-extractor/vec3d.h index d6bb4b185ef2f..c6da3052b11a0 100644 --- a/src/tools/vmap-extractor/vec3d.h +++ b/src/tools/vmap-extractor/vec3d.h @@ -260,210 +260,6 @@ class Vec3D } }; - -/** - * @brief - * - */ -class Vec2D -{ - public: - float x, y; /**< TODO */ - - /** - * @brief - * - * @param x0 - * @param y0 - */ - Vec2D(float x0 = 0.0f, float y0 = 0.0f) : x(x0), y(y0) {} - - /** - * @brief - * - * @param v - */ - Vec2D(const Vec2D& v) : x(v.x), y(v.y) {} - - /** - * @brief - * - * @param v - * @return Vec2D &operator - */ - Vec2D& operator= (const Vec2D& v) - { - x = v.x; - y = v.y; - return *this; - } - - /** - * @brief - * - * @param v - * @return Vec2D operator - */ - Vec2D operator+ (const Vec2D& v) const - { - Vec2D r(x + v.x, y + v.y); - return r; - } - - /** - * @brief - * - * @param v - * @return Vec2D operator - */ - Vec2D operator- (const Vec2D& v) const - { - Vec2D r(x - v.x, y - v.y); - return r; - } - - /** - * @brief - * - * @param v - * @return float operator - */ - float operator* (const Vec2D& v) const - { - return x * v.x + y * v.y; - } - - /** - * @brief - * - * @param d - * @return Vec2D operator - */ - Vec2D operator* (float d) const - { - Vec2D r(x * d, y * d); - return r; - } - - /** - * @brief - * - * @param d - * @param v - * @return Vec2D operator - */ - friend Vec2D operator* (float d, const Vec2D& v) - { - return v * d; - } - - /** - * @brief - * - * @param v - * @return Vec2D &operator - */ - Vec2D& operator+= (const Vec2D& v) - { - x += v.x; - y += v.y; - return *this; - } - - /** - * @brief - * - * @param v - * @return Vec2D &operator - */ - Vec2D& operator-= (const Vec2D& v) - { - x -= v.x; - y -= v.y; - return *this; - } - - /** - * @brief - * - * @param d - * @return Vec2D &operator - */ - Vec2D& operator*= (float d) - { - x *= d; - y *= d; - return *this; - } - - /** - * @brief - * - * @return float - */ - float lengthSquared() const - { - return x * x + y * y; - } - - /** - * @brief - * - * @return float - */ - float length() const - { - return sqrt(x * x + y * y); - } - - /** - * @brief - * - * @return Vec2D - */ - Vec2D& normalize() - { - this->operator*= (1.0f / length()); - return *this; - } - - /** - * @brief - * - * @return Vec2D operator - */ - Vec2D operator~() const - { - Vec2D r(*this); - r.normalize(); - return r; - } - - - /** - * @brief - * - * @param in - * @param v - * @return std::istream &operator >> - */ - friend std::istream& operator>>(std::istream& in, Vec2D& v) - { - in >> v.x >> v.y; - return in; - } - - /** - * @brief - * - * @return operator float - */ - operator float* () - { - return (float*)this; - } -}; - /** * @brief * @@ -480,4 +276,20 @@ inline void rotate(float x0, float y0, float* x, float* y, float angle) *y = xa * sinf(angle) + ya * cosf(angle) + y0; } +/** + * @brief for whatever reason a certain company just can't stick to one coordinate system... + * + * @param v + * @return Vec3D + */ +inline Vec3D fixCoords(const Vec3D& v) { return Vec3D(v.z, v.x, v.y); } + +/** + * @brief + * + * @param v + * @return Vec3D + */ +inline Vec3D fixCoordSystem(const Vec3D& v) { return Vec3D(v.x, v.z, -v.y); } + #endif diff --git a/src/tools/vmap-extractor/vmapexport.cpp b/src/tools/vmap-extractor/vmapexport.cpp index 079fac96504ff..10b364cdde6c6 100644 --- a/src/tools/vmap-extractor/vmapexport.cpp +++ b/src/tools/vmap-extractor/vmapexport.cpp @@ -52,7 +52,6 @@ #include "dbcfile.h" #include "wmo.h" #include - #include "vmapexport.h" #include "Auth/md5.h" @@ -126,9 +125,6 @@ std::string GetUniformName(std::string& path) } else { file = tempPath = path; } - if (tempPath == "") //GameObjectDisplayInfo, OnyxiasLair - tempPath.assign("world\\wmo\\dungeon\\kl_onyxiaslair"); - if(!tempPath.empty()) compute_md5(tempPath.c_str(),digest); else @@ -174,109 +170,6 @@ void ReadLiquidTypeTableDBC() printf("Success! (%u LiqTypes loaded)\n", (unsigned int)LiqType_count); } -bool ExtractWmo() -{ - bool success = true; - - for (ArchiveSet::const_iterator ar_itr = gOpenArchives.begin(); ar_itr != gOpenArchives.end() && success; ++ar_itr) - { - vector filelist; - - (*ar_itr)->GetFileListTo(filelist); - for (vector::iterator fname = filelist.begin(); fname != filelist.end() && success; ++fname) - { - if (fname->find(".wmo") != string::npos) { success = ExtractSingleWmo(*fname);} - } - } - - if (success) - { printf("\nExtract wmo complete (No (fatal) errors)\n"); } - - return success; -} - -bool ExtractSingleWmo(std::string& fname) -{ - // Copy files from archive - - char szLocalFile[1024]; - string plain_name = GetUniformName(fname); - - sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name.c_str()); - - if (FileExists(szLocalFile)) - { return true; } - - int p = 0; - //Select root wmo files - const char* rchr = strrchr(plain_name.c_str(), '_'); - if (rchr != NULL) - { - char cpy[4]; - strncpy((char*)cpy, rchr, 4); - for (int i = 0; i < 4; ++i) - { - int m = cpy[i]; - if (isdigit(m)) - { p++; } - } - } - - if (p == 3) - { return true; } - - bool file_ok = true; - std::cout << "Extracting " << fname << std::endl; - WMORoot froot(fname); - if (!froot.open()) - { - printf("Couldn't open RootWmo!!!\n"); - return true; - } - - FILE* output = fopen(szLocalFile, "wb"); - if (!output) - { - printf("couldn't open %s for writing!\n", szLocalFile); - return false; - } - - froot.ConvertToVMAPRootWmo(output); - int Wmo_nVertices = 0; - if (froot.nGroups != 0) - { - for (uint32 i = 0; i < froot.nGroups; ++i) - { - char temp[1024]; - strcpy(temp, fname.c_str()); - temp[fname.length() - 4] = 0; - char groupFileName[1024]; - sprintf(groupFileName, "%s_%03d.wmo", temp, i); - - string s(groupFileName); - - WMOGroup fgroup(s); - if (!fgroup.open()) - { - printf("Could not open all Group file for: %s\n", plain_name.c_str()); - file_ok = false; - break; - } - - Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, &froot, preciseVectorData); - } - } - - fseek(output, 8, SEEK_SET); // store the correct no of vertices - fwrite(&Wmo_nVertices, sizeof(int), 1, output); - fclose(output); - - // Delete the extracted file in the case of an error - if (!file_ok) - { remove(szLocalFile); } - return true; -} - void ParsMapFiles() { char fn[512]; @@ -538,7 +431,6 @@ int main(int argc, char** argv) printf("Map - %s\n", map_ids[x].name); } - delete dbc; ParsMapFiles(); delete [] map_ids; diff --git a/src/tools/vmap-extractor/wdtfile.cpp b/src/tools/vmap-extractor/wdtfile.cpp index dd2a4b6d9b251..87137dcef010b 100644 --- a/src/tools/vmap-extractor/wdtfile.cpp +++ b/src/tools/vmap-extractor/wdtfile.cpp @@ -22,14 +22,13 @@ * and lore are copyrighted by Blizzard Entertainment, Inc. */ +#include #include "vmapexport.h" #include "wdtfile.h" -#include "adtfile.h" -#include WDTFile::WDTFile(char* file_name, char* file_name1): WDT(file_name) { - filename.append(file_name1, strlen(file_name1)); + filename.assign(file_name1); } bool WDTFile::init(char* map_id, unsigned int mapID) @@ -107,7 +106,6 @@ bool WDTFile::init(char* map_id, unsigned int mapID) WDT.seek((int)nextpos); } - WDT.close(); fclose(dirfile); return true; } diff --git a/src/tools/vmap-extractor/wdtfile.h b/src/tools/vmap-extractor/wdtfile.h index 5c1e69c4687c1..3262a24595fcb 100644 --- a/src/tools/vmap-extractor/wdtfile.h +++ b/src/tools/vmap-extractor/wdtfile.h @@ -25,12 +25,10 @@ #ifndef WDTFILE_H #define WDTFILE_H +#include #include #include "wmo.h" -#include -#include "stdlib.h" - -class ADTFile; +#include "adtfile.h" /** * @brief @@ -60,7 +58,7 @@ class WDTFile */ bool init(char* map_id, unsigned int mapID); - string* gWmoInstansName; /**< TODO */ + std::string* gWmoInstansName; /**< TODO */ int gnWMO, nMaps; /**< TODO */ /** @@ -75,7 +73,7 @@ class WDTFile private: MPQFile WDT; /**< TODO */ bool maps[64][64]; /**< TODO */ - string filename; /**< TODO */ + std::string filename; /**< TODO */ }; #endif diff --git a/src/tools/vmap-extractor/wmo.cpp b/src/tools/vmap-extractor/wmo.cpp index 524a4ecebec65..c767c2b5d9581 100644 --- a/src/tools/vmap-extractor/wmo.cpp +++ b/src/tools/vmap-extractor/wmo.cpp @@ -32,10 +32,10 @@ #include #undef min #undef max -#include -using namespace std; extern uint16* LiqType; +extern bool preciseVectorData; +extern ArchiveSet gOpenArchives; WMORoot::WMORoot(std::string& filename) : filename(filename) { @@ -564,3 +564,109 @@ WMOInstance::WMOInstance(MPQFile& f, std::string& WmoInstName, uint32 mapID, uin fwrite(WmoInstName.c_str(), sizeof(char), nlen, pDirfile); } + +bool ExtractSingleWmo(std::string& fname) +{ + // Copy files from archive + char szLocalFile[1024]; + string plain_name = GetUniformName(fname); + + sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name.c_str()); + + if (FileExists(szLocalFile)) + { return true; } + + int p = 0; + //Select root wmo files + const char* rchr = strrchr(plain_name.c_str(), '_'); + if (rchr != NULL) + { + char cpy[4]; + strncpy((char*)cpy, rchr, 4); + for (int i = 0; i < 4; ++i) + { + int m = cpy[i]; + if (isdigit(m)) + { p++; } + } + } + + if (p == 3) + { return true; } + + bool file_ok = true; + printf("Extracting %s\n", fname.c_str()); + + WMORoot froot(fname); + if (!froot.open()) + { + printf("Couldn't open RootWmo!!!\n"); + return true; + } + + FILE* output = fopen(szLocalFile, "wb"); + if (!output) + { + printf("Couldn't open %s for writing!\n", szLocalFile); + return false; + } + + froot.ConvertToVMAPRootWmo(output); + int Wmo_nVertices = 0; + if (froot.nGroups != 0) + { + for (uint32 i = 0; i < froot.nGroups; ++i) + { + char temp[1024]; + strcpy(temp, fname.c_str()); + temp[fname.length() - 4] = 0; + char groupFileName[1024]; + sprintf(groupFileName, "%s_%03d.wmo", temp, i); + + string s(groupFileName); + + WMOGroup fgroup(s); + if (!fgroup.open()) + { + printf("Could not open all Group file for: %s\n", plain_name.c_str()); + file_ok = false; + break; + } + + Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, &froot, preciseVectorData); + } + } + + fseek(output, 8, SEEK_SET); // store the correct no of vertices + fwrite(&Wmo_nVertices, sizeof(int), 1, output); + fclose(output); + + // Delete the extracted file in the case of an error + if (!file_ok) + { remove(szLocalFile); } + return true; +} + +bool ExtractWmo() +{ + bool success = true; + + for (ArchiveSet::const_iterator ar_itr = gOpenArchives.begin(); ar_itr != gOpenArchives.end() && success; ++ar_itr) + { + vector filelist; + + (*ar_itr)->GetFileListTo(filelist); + for (vector::iterator fname = filelist.begin(); fname != filelist.end() && success; ++fname) + { + if (fname->find(".wmo") != string::npos) + { + ExtractSingleWmo(*fname); + } + } + } + + if (success) + { printf("\nExtract wmo complete (No (fatal) errors)\n"); } + + return success; +} diff --git a/src/tools/vmap-extractor/wmo.h b/src/tools/vmap-extractor/wmo.h index 9dbec935e84b0..8ff7c265c4b2e 100644 --- a/src/tools/vmap-extractor/wmo.h +++ b/src/tools/vmap-extractor/wmo.h @@ -31,6 +31,7 @@ #include #include #include "vec3d.h" +#include #include // MOPY flags @@ -42,17 +43,6 @@ #define WMO_MATERIAL_COLLIDE_HIT 0x20 #define WMO_MATERIAL_WALL_SURFACE 0x40 -class WMOInstance; -class MPQFile; - -/** - * @brief for whatever reason a certain company just can't stick to one coordinate system... - * - * @param v - * @return Vec3D - */ -static inline Vec3D fixCoords(const Vec3D& v) { return Vec3D(v.z, v.x, v.y); } - /** * @brief * @@ -226,5 +216,12 @@ class WMOInstance */ bool ExtractSingleWmo(std::string& fname); +/** + * @brief + * + * @param + * @return bool + */ +bool ExtractWmo(); #endif