aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorSubv2112 <s.v.h21@hotmail.com>2012-02-03 16:03:52 -0500
committerSubv <s.v.h21@hotmail.com>2012-02-09 13:58:22 -0500
commit93d199f04382fe3c7f6f08f59fd2ad058568679a (patch)
treeb698029a6cf0649bed6689cd0aa4414d8ad1aa42 /src/tools
parent229d4119e887fa6079a6e0b093860e11b5facb63 (diff)
Core/Collision: Ported dynamic line of sight patch by Silverice from MaNGOS and
added lots of improvements Please re-extract vmaps
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/vmap3_assembler/CMakeLists.txt1
-rw-r--r--src/tools/vmap3_extractor/adtfile.cpp69
-rw-r--r--src/tools/vmap3_extractor/adtfile.h22
-rw-r--r--src/tools/vmap3_extractor/dbcfile.cpp18
-rw-r--r--src/tools/vmap3_extractor/dbcfile.h24
-rw-r--r--src/tools/vmap3_extractor/gameobject_extract.cpp99
-rw-r--r--src/tools/vmap3_extractor/loadlib/loadlib.h20
-rw-r--r--src/tools/vmap3_extractor/model.cpp38
-rw-r--r--src/tools/vmap3_extractor/model.h29
-rw-r--r--src/tools/vmap3_extractor/modelheaders.h18
-rw-r--r--src/tools/vmap3_extractor/mpq_libmpq04.h13
-rw-r--r--src/tools/vmap3_extractor/vmapexport.cpp236
-rw-r--r--src/tools/vmap3_extractor/vmapexport.h33
-rw-r--r--src/tools/vmap3_extractor/wdtfile.cpp18
-rw-r--r--src/tools/vmap3_extractor/wmo.cpp20
-rw-r--r--src/tools/vmap3_extractor/wmo.h18
16 files changed, 505 insertions, 171 deletions
diff --git a/src/tools/vmap3_assembler/CMakeLists.txt b/src/tools/vmap3_assembler/CMakeLists.txt
index ba5d1649d38..42ffc749ba8 100644
--- a/src/tools/vmap3_assembler/CMakeLists.txt
+++ b/src/tools/vmap3_assembler/CMakeLists.txt
@@ -13,6 +13,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/dep/g3dlite/include
${CMAKE_SOURCE_DIR}/src/server/shared
${CMAKE_SOURCE_DIR}/src/server/shared/Debugging
+ ${CMAKE_SOURCE_DIR}/src/server/collision
${CMAKE_SOURCE_DIR}/src/server/collision/Maps
${CMAKE_SOURCE_DIR}/src/server/collision/Models
${ACE_INCLUDE_DIR}
diff --git a/src/tools/vmap3_extractor/adtfile.cpp b/src/tools/vmap3_extractor/adtfile.cpp
index 58c1bb94b1c..a966172a3be 100644
--- a/src/tools/vmap3_extractor/adtfile.cpp
+++ b/src/tools/vmap3_extractor/adtfile.cpp
@@ -1,13 +1,40 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#include "vmapexport.h"
#include "adtfile.h"
#include <algorithm>
#include <cstdio>
-#ifdef _WIN32
+#ifdef WIN32
#define snprintf _snprintf
#endif
+const char * GetPlainName(const char * FileName)
+{
+ const char * szTemp;
+
+ if((szTemp = strrchr(FileName, '\\')) != NULL)
+ FileName = szTemp + 1;
+ return FileName;
+}
+
char * GetPlainName(char * FileName)
{
char * szTemp;
@@ -43,6 +70,14 @@ void fixname2(char *name, size_t len)
}
}
+char * GetExtension(char * FileName)
+{
+ char * szTemp;
+ if((szTemp = strrchr(FileName, '.')) != NULL)
+ return szTemp;
+ return NULL;
+}
+
ADTFile::ADTFile(char* filename): ADT(filename)
{
Adtfilename.append(filename);
@@ -107,35 +142,15 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
while (p<buf+size)
{
fixnamen(p,strlen(p));
- string path(p);
- char* s=GetPlainName(p);
+ char* s = GetPlainName(p);
fixname2(s,strlen(s));
- p=p+strlen(p)+1;
+
ModelInstansName[t++] = s;
- // < 3.1.0 ADT MMDX section store filename.mdx filenames for corresponded .m2 file
- std::string ext3 = path.size() >= 4 ? path.substr(path.size()-4,4) : "";
- std::transform( ext3.begin(), ext3.end(), ext3.begin(), ::tolower );
- if(ext3 == ".mdx")
- {
- // replace .mdx -> .m2
- path.erase(path.length()-2,2);
- path.append("2");
- }
- // >= 3.1.0 ADT MMDX section store filename.m2 filenames for corresponded .m2 file
- // nothing do
-
- char szLocalFile[1024];
- snprintf(szLocalFile, 1024, "%s/%s", szWorkDirWmo, s);
- FILE * output = fopen(szLocalFile,"rb");
- if(!output)
- {
- Model m2(path);
- if(m2.open())
- m2.ConvertToVMAPModel(szLocalFile);
- }
- else
- fclose(output);
+ string path(p);
+ ExtractSingleModel(path);
+
+ p = p+strlen(p)+1;
}
delete[] buf;
}
diff --git a/src/tools/vmap3_extractor/adtfile.h b/src/tools/vmap3_extractor/adtfile.h
index eaf09a9243d..08814996f68 100644
--- a/src/tools/vmap3_extractor/adtfile.h
+++ b/src/tools/vmap3_extractor/adtfile.h
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#ifndef ADT_H
#define ADT_H
@@ -115,7 +133,11 @@ private:
string Adtfilename;
};
+const char * GetPlainName(const char * FileName);
+char * GetPlainName(char * FileName);
+char * GetExtension(char * FileName);
void fixnamen(char *name, size_t len);
+void fixname2(char *name, size_t len);
//void fixMapNamen(char *name, size_t len);
#endif
diff --git a/src/tools/vmap3_extractor/dbcfile.cpp b/src/tools/vmap3_extractor/dbcfile.cpp
index 8b8afe9f23c..2474cea5259 100644
--- a/src/tools/vmap3_extractor/dbcfile.cpp
+++ b/src/tools/vmap3_extractor/dbcfile.cpp
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#include "dbcfile.h"
#include "mpq_libmpq04.h"
#undef min
diff --git a/src/tools/vmap3_extractor/dbcfile.h b/src/tools/vmap3_extractor/dbcfile.h
index d405d6ffd60..56cce9a521c 100644
--- a/src/tools/vmap3_extractor/dbcfile.h
+++ b/src/tools/vmap3_extractor/dbcfile.h
@@ -1,19 +1,19 @@
/*
- * Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DBCFILE_H
diff --git a/src/tools/vmap3_extractor/gameobject_extract.cpp b/src/tools/vmap3_extractor/gameobject_extract.cpp
new file mode 100644
index 00000000000..8a1f67cd2c2
--- /dev/null
+++ b/src/tools/vmap3_extractor/gameobject_extract.cpp
@@ -0,0 +1,99 @@
+#include "model.h"
+#include "dbcfile.h"
+#include "adtfile.h"
+#include "vmapexport.h"
+
+#include <algorithm>
+#include <stdio.h>
+
+bool ExtractSingleModel(std::string& fname)
+{
+ char * name = GetPlainName((char*)fname.c_str());
+ char * ext = GetExtension(name);
+
+ // < 3.1.0 ADT MMDX section store filename.mdx filenames for corresponded .m2 file
+ if (!strcmp(ext, ".mdx"))
+ {
+ // replace .mdx -> .m2
+ fname.erase(fname.length()-2,2);
+ fname.append("2");
+ }
+ // >= 3.1.0 ADT MMDX section store filename.m2 filenames for corresponded .m2 file
+ // nothing do
+
+ std::string output(szWorkDirWmo);
+ output += "/";
+ output += name;
+
+ if (FileExists(output.c_str()))
+ return true;
+
+ Model mdl(fname);
+ if (!mdl.open())
+ return false;
+
+ return mdl.ConvertToVMAPModel(output.c_str());
+}
+
+void ExtractGameobjectModels()
+{
+ printf("Extracting GameObject models...");
+ DBCFile dbc("DBFilesClient\\GameObjectDisplayInfo.dbc");
+ if(!dbc.open())
+ {
+ printf("Fatal error: Invalid GameObjectDisplayInfo.dbc file format!\n");
+ exit(1);
+ }
+
+ std::string basepath = szWorkDirWmo;
+ basepath += "/";
+ std::string path;
+
+ FILE * model_list = fopen((basepath + "temp_gameobject_models").c_str(), "wb");
+
+ for (DBCFile::Iterator it = dbc.begin(); it != dbc.end(); ++it)
+ {
+ path = it->getString(1);
+
+ if (path.length() < 4)
+ continue;
+
+ fixnamen((char*)path.c_str(), path.size());
+ char * name = GetPlainName((char*)path.c_str());
+ fixname2(name, strlen(name));
+
+ char * ch_ext = GetExtension(name);
+ if (!ch_ext)
+ continue;
+
+ strToLower(ch_ext);
+
+ bool result = false;
+ if (!strcmp(ch_ext, ".wmo"))
+ {
+ result = ExtractSingleWmo(path);
+ }
+ else if (!strcmp(ch_ext, ".mdl"))
+ {
+ // TODO: extract .mdl files, if needed
+ continue;
+ }
+ else //if (!strcmp(ch_ext, ".mdx") || !strcmp(ch_ext, ".m2"))
+ {
+ result = ExtractSingleModel(path);
+ }
+
+ if (result)
+ {
+ uint32 displayId = it->getUInt(0);
+ uint32 path_length = strlen(name);
+ fwrite(&displayId, sizeof(uint32), 1, model_list);
+ fwrite(&path_length, sizeof(uint32), 1, model_list);
+ fwrite(name, sizeof(char), path_length, model_list);
+ }
+ }
+
+ fclose(model_list);
+
+ printf("Done!\n");
+}
diff --git a/src/tools/vmap3_extractor/loadlib/loadlib.h b/src/tools/vmap3_extractor/loadlib/loadlib.h
index bf6c0706d46..61865c4b436 100644
--- a/src/tools/vmap3_extractor/loadlib/loadlib.h
+++ b/src/tools/vmap3_extractor/loadlib/loadlib.h
@@ -1,7 +1,25 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#ifndef LOAD_LIB_H
#define LOAD_LIB_H
-#ifdef _WIN32
+#ifdef WIN32
typedef __int64 int64;
typedef __int32 int32;
typedef __int16 int16;
diff --git a/src/tools/vmap3_extractor/model.cpp b/src/tools/vmap3_extractor/model.cpp
index 81e27621956..117c594b41a 100644
--- a/src/tools/vmap3_extractor/model.cpp
+++ b/src/tools/vmap3_extractor/model.cpp
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#include "vmapexport.h"
#include "model.h"
#include "wmo.h"
@@ -6,7 +24,7 @@
#include <algorithm>
#include <cstdio>
-Model::Model(std::string &filename) : filename(filename)
+Model::Model(std::string &filename) : filename(filename), vertices(0), indices(0)
{
}
@@ -23,6 +41,8 @@ bool Model::open()
return false;
}
+ _unload();
+
memcpy(&header, f.getBuffer(), sizeof(ModelHeader));
if(header.nBoundingTriangles > 0)
{
@@ -49,7 +69,7 @@ bool Model::open()
return true;
}
-bool Model::ConvertToVMAPModel(char * outfilename)
+bool Model::ConvertToVMAPModel(const char * outfilename)
{
int N[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
FILE * output=fopen(outfilename,"wb");
@@ -58,7 +78,7 @@ bool Model::ConvertToVMAPModel(char * outfilename)
printf("Can't create the output file '%s'\n",outfilename);
return false;
}
- fwrite("VMAP003",8,1,output);
+ fwrite(szRawVMAPMagic,8,1,output);
uint32 nVertices = 0;
nVertices = header.nBoundingVertices;
fwrite(&nVertices, sizeof(int), 1, output);
@@ -92,24 +112,16 @@ bool Model::ConvertToVMAPModel(char * outfilename)
{
for(uint32 vpos=0; vpos <nVertices; ++vpos)
{
- float sy = vertices[vpos].y;
- vertices[vpos].y = vertices[vpos].z;
- vertices[vpos].z = sy;
+ std::swap(vertices[vpos].y, vertices[vpos].z);
}
fwrite(vertices, sizeof(float)*3, nVertices, output);
}
- delete[] vertices;
- delete[] indices;
-
fclose(output);
return true;
}
-Model::~Model()
-{
-}
Vec3D fixCoordSystem(Vec3D v)
{
@@ -154,7 +166,7 @@ ModelInstance::ModelInstance(MPQFile &f,const char* ModelInstName, uint32 mapID,
uint16 adtId = 0;// not used for models
uint32 flags = MOD_M2;
- if(tileX == 65 && tileY == 65) flags |= MOD_WORLDSPAWN;
+ if(tileX == 65 && tileY == 65) flags |= MOD_WORLDSPAWN;
//write mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, name
fwrite(&mapID, sizeof(uint32), 1, pDirfile);
fwrite(&tileX, sizeof(uint32), 1, pDirfile);
diff --git a/src/tools/vmap3_extractor/model.h b/src/tools/vmap3_extractor/model.h
index c131645bd73..a6f4e27583c 100644
--- a/src/tools/vmap3_extractor/model.h
+++ b/src/tools/vmap3_extractor/model.h
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#ifndef MODEL_H
#define MODEL_H
@@ -23,14 +41,21 @@ public:
size_t nIndices;
bool open();
- bool ConvertToVMAPModel(char * outfilename);
+ bool ConvertToVMAPModel(const char * outfilename);
bool ok;
Model(std::string &filename);
- ~Model();
+ ~Model() {_unload();}
private:
+ void _unload()
+ {
+ delete[] vertices;
+ delete[] indices;
+ vertices = NULL;
+ indices = NULL;
+ }
std::string filename;
char outfilename;
};
diff --git a/src/tools/vmap3_extractor/modelheaders.h b/src/tools/vmap3_extractor/modelheaders.h
index 776a981ebd8..d859fd3511e 100644
--- a/src/tools/vmap3_extractor/modelheaders.h
+++ b/src/tools/vmap3_extractor/modelheaders.h
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#ifndef MODELHEADERS_H
#define MODELHEADERS_H
diff --git a/src/tools/vmap3_extractor/mpq_libmpq04.h b/src/tools/vmap3_extractor/mpq_libmpq04.h
index f32f09badde..4b0a2465bfd 100644
--- a/src/tools/vmap3_extractor/mpq_libmpq04.h
+++ b/src/tools/vmap3_extractor/mpq_libmpq04.h
@@ -1,3 +1,6 @@
+#define _CRT_SECURE_NO_DEPRECATE
+#define _CRT_SECURE_NO_WARNINGS
+
#ifndef MPQ_H
#define MPQ_H
@@ -21,14 +24,14 @@ public:
void close();
void GetFileListTo(vector<string>& filelist) {
- uint32 filenum;
- if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
- libmpq__off_t size, transferred;
- libmpq__file_unpacked_size(mpq_a, filenum, &size);
+ uint32 filenum;
+ if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
+ libmpq__off_t size, transferred;
+ libmpq__file_unpacked_size(mpq_a, filenum, &size);
char *buffer = new char[size];
- libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
+ libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
char seps[] = "\n";
char *token;
diff --git a/src/tools/vmap3_extractor/vmapexport.cpp b/src/tools/vmap3_extractor/vmapexport.cpp
index 689691e1d91..bf5fe1c517f 100644
--- a/src/tools/vmap3_extractor/vmapexport.cpp
+++ b/src/tools/vmap3_extractor/vmapexport.cpp
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
@@ -5,7 +23,7 @@
#include <list>
#include <errno.h>
-#ifdef _WIN32
+#ifdef WIN32
#include <Windows.h>
#include <sys/stat.h>
#include <direct.h>
@@ -29,6 +47,8 @@
#include "wmo.h"
#include "mpq_libmpq04.h"
+#include "vmapexport.h"
+
//------------------------------------------------------------------------------
// Defines
@@ -55,13 +75,19 @@ bool preciseVectorData = false;
// Constants
//static const char * szWorkDirMaps = ".\\Maps";
-const char * szWorkDirWmo = "./Buildings";
+const char* szWorkDirWmo = "./Buildings";
+const char* szRawVMAPMagic = "VMAP004";
// Local testing functions
-static void clreol()
+bool FileExists(const char* file)
{
- printf("\r \r");
+ if (FILE* n = fopen(file, "rb"))
+ {
+ fclose(n);
+ return true;
+ }
+ return false;
}
void strToLower(char* str)
@@ -73,15 +99,6 @@ void strToLower(char* str)
}
}
-static const char * GetPlainName(const char * szFileName)
-{
- const char * szTemp;
-
- if((szTemp = strrchr(szFileName, '\\')) != NULL)
- szFileName = szTemp + 1;
- return szFileName;
-}
-
// copied from contrib/extractor/System.cpp
void ReadLiquidTypeTableDBC()
{
@@ -104,10 +121,9 @@ void ReadLiquidTypeTableDBC()
printf("Done! (%u LiqTypes loaded)\n", (unsigned int)LiqType_count);
}
-int ExtractWmo()
+bool ExtractWmo()
{
- char szLocalFile[1024] = "";
- bool success=true;
+ bool success = true;
//const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"};
@@ -116,99 +132,98 @@ int ExtractWmo()
vector<string> filelist;
(*ar_itr)->GetFileListTo(filelist);
- for (vector<string>::iterator fname=filelist.begin(); fname != filelist.end() && success; ++fname)
+ for (vector<string>::iterator fname = filelist.begin(); fname != filelist.end() && success; ++fname)
{
- bool file_ok=true;
if (fname->find(".wmo") != string::npos)
- {
- // Copy files from archive
- //std::cout << "found *.wmo file " << *fname << std::endl;
- sprintf(szLocalFile, "%s/%s", szWorkDirWmo, GetPlainName(fname->c_str()));
- fixnamen(szLocalFile,strlen(szLocalFile));
- FILE * n;
- if ((n = fopen(szLocalFile, "rb"))== NULL)
- {
- int p = 0;
- //Select root wmo files
- const char * rchr = strrchr(GetPlainName(fname->c_str()),0x5f);
- 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)
- {
- std::cout << "Extracting " << *fname << std::endl;
- WMORoot * froot = new WMORoot(*fname);
- if(!froot->open())
- {
- printf("Couldn't open RootWmo!!!\n");
- delete froot;
- continue;
- }
- FILE *output=fopen(szLocalFile,"wb");
- if(!output)
- {
- printf("couldn't open %s for writing!\n", szLocalFile);
- success=false;
- }
- froot->ConvertToVMAPRootWmo(output);
- int Wmo_nVertices = 0;
- //printf("root has %d groups\n", froot->nGroups);
- 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);
- //printf("Trying to open groupfile %s\n",groupFileName);
- string s = groupFileName;
- WMOGroup * fgroup = new WMOGroup(s);
- if(!fgroup->open())
- {
- printf("Could not open all Group file for: %s\n",GetPlainName(fname->c_str()));
- file_ok=false;
- break;
- }
-
- Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, froot, preciseVectorData);
- delete fgroup;
- }
- }
- fseek(output, 8, SEEK_SET); // store the correct no of vertices
- fwrite(&Wmo_nVertices,sizeof(int),1,output);
- fclose(output);
- delete froot;
- }
- }
- else
- {
- fclose(n);
- }
- }
- // Delete the extracted file in the case of an error
- if(!file_ok)
- remove(szLocalFile);
+ success = ExtractSingleWmo(*fname);
}
}
- if(success)
+ if (success)
printf("\nExtract wmo complete (No (fatal) errors)\n");
return success;
}
-void ExtractMapsFromMpq()
+bool ExtractSingleWmo(std::string& fname)
{
+ // Copy files from archive
+
+ char szLocalFile[1024];
+ const char * plain_name = GetPlainName(fname.c_str());
+ sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
+ fixnamen(szLocalFile,strlen(szLocalFile));
+
+ if (FileExists(szLocalFile))
+ return true;
+
+ int p = 0;
+ //Select root wmo files
+ const char * rchr = strrchr(plain_name, '_');
+ 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;
+ //printf("root has %d groups\n", froot->nGroups);
+ 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);
+ //printf("Trying to open groupfile %s\n",groupFileName);
+
+ string s = groupFileName;
+ WMOGroup fgroup(s);
+ if(!fgroup.open())
+ {
+ printf("Could not open all Group file for: %s\n", plain_name);
+ 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()
@@ -251,8 +266,9 @@ void getGamePath()
LONG l;
s = sizeof(input_path);
memset(input_path,0,s);
- l = RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\World of Warcraft",0,KEY_QUERY_VALUE,&key);
- l = RegQueryValueExA(key,"InstallPath",0,&t,(LPBYTE)input_path,&s);
+ l = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\World of Warcraft",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);
RegCloseKey(key);
if (strlen(input_path) > 0)
{
@@ -379,16 +395,17 @@ bool processArgv(int argc, char ** argv, const char *versionString)
{
bool result = true;
hasInputPathParam = false;
+ bool preciseVectorData = false;
- for (int i=1; i < argc; ++i)
+ for(int i=1; i< argc; ++i)
{
- if (strcmp("-s", argv[i]) == 0)
+ if(strcmp("-s",argv[i]) == 0)
{
preciseVectorData = false;
}
- else if (strcmp("-d", argv[i]) == 0)
+ else if(strcmp("-d",argv[i]) == 0)
{
- if ((i + 1) < argc)
+ if((i+1)<argc)
{
hasInputPathParam = true;
strcpy(input_path, argv[i+1]);
@@ -401,11 +418,11 @@ bool processArgv(int argc, char ** argv, const char *versionString)
result = false;
}
}
- else if (strcmp("-?", argv[1]) == 0)
+ else if(strcmp("-?",argv[1]) == 0)
{
result = false;
}
- else if (strcmp("-l", argv[i]) == 0)
+ else if(strcmp("-l",argv[i]) == 0)
{
preciseVectorData = true;
}
@@ -427,6 +444,7 @@ bool processArgv(int argc, char ** argv, const char *versionString)
return result;
}
+
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Main
//
@@ -465,7 +483,7 @@ int main(int argc, char ** argv)
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Create the working directory
if(mkdir(szWorkDirWmo
-#ifdef _XOPEN_UNIX
+#ifdef __linux__
, 0711
#endif
))
@@ -517,9 +535,11 @@ int main(int argc, char ** argv)
ParsMapFiles();
delete [] map_ids;
//nError = ERROR_SUCCESS;
+ // Extract models, listed in DameObjectDisplayInfo.dbc
+ ExtractGameobjectModels();
}
- clreol();
+ printf("\n");
if(!success)
{
printf("ERROR: Extract %s. Work NOT complete.\n Precise vector data=%d.\nPress any key.\n",versionString, preciseVectorData);
diff --git a/src/tools/vmap3_extractor/vmapexport.h b/src/tools/vmap3_extractor/vmapexport.h
index e8a55fb898e..b407e7a106e 100644
--- a/src/tools/vmap3_extractor/vmapexport.h
+++ b/src/tools/vmap3_extractor/vmapexport.h
@@ -1,13 +1,42 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#ifndef VMAPEXPORT_H
#define VMAPEXPORT_H
+#include <string>
+
enum ModelFlags
{
- MOD_M2 = 1,
- MOD_WORLDSPAWN = 1<<1,
+ MOD_M2 = 1,
+ MOD_WORLDSPAWN = 1<<1,
MOD_HAS_BOUND = 1<<2
};
extern const char * szWorkDirWmo;
+extern const char * szRawVMAPMagic; // vmap magic string for extracted raw vmap data
+
+bool FileExists(const char * file);
+void strToLower(char* str);
+
+bool ExtractSingleWmo(std::string& fname);
+bool ExtractSingleModel(std::string& fname);
+
+void ExtractGameobjectModels();
#endif
diff --git a/src/tools/vmap3_extractor/wdtfile.cpp b/src/tools/vmap3_extractor/wdtfile.cpp
index cd24ef0346c..e3ee545db19 100644
--- a/src/tools/vmap3_extractor/wdtfile.cpp
+++ b/src/tools/vmap3_extractor/wdtfile.cpp
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#include "vmapexport.h"
#include "wdtfile.h"
#include "adtfile.h"
diff --git a/src/tools/vmap3_extractor/wmo.cpp b/src/tools/vmap3_extractor/wmo.cpp
index 216a2248953..58957e007c1 100644
--- a/src/tools/vmap3_extractor/wmo.cpp
+++ b/src/tools/vmap3_extractor/wmo.cpp
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#include "vmapexport.h"
#include "wmo.h"
#include "vec3d.h"
@@ -106,7 +124,7 @@ bool WMORoot::ConvertToVMAPRootWmo(FILE *pOutfile)
{
//printf("Convert RootWmo...\n");
- fwrite("VMAP003",1,8,pOutfile);
+ fwrite(szRawVMAPMagic,1,8,pOutfile);
unsigned int nVectors = 0;
fwrite(&nVectors,sizeof(nVectors),1,pOutfile); // will be filled later
fwrite(&nGroups,4,1,pOutfile);
diff --git a/src/tools/vmap3_extractor/wmo.h b/src/tools/vmap3_extractor/wmo.h
index 12979bc13d9..d1f7b82f0c6 100644
--- a/src/tools/vmap3_extractor/wmo.h
+++ b/src/tools/vmap3_extractor/wmo.h
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
#ifndef WMO_H
#define WMO_H
#define TILESIZE (533.33333f)