Skip to content

Commit

Permalink
Merge pull request #45 from H0zen/develop21-tools
Browse files Browse the repository at this point in the history
[Tools] Fix a bug in previous commit where some wmo's were not extracted at all.
  • Loading branch information
billy1arm committed Sep 15, 2015
2 parents e88d908 + 2591146 commit a11f1e6
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 422 deletions.
3 changes: 2 additions & 1 deletion src/game/vmap/TileAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/tools/Movemap-Generator/MMapCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <string>
#include <vector>
#include <errno.h>

#include "Platform/Define.h"

Expand Down
2 changes: 1 addition & 1 deletion src/tools/vmap-extractor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 3 additions & 11 deletions src/tools/vmap-extractor/adtfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/

#include "vmapexport.h"
#include "adtfile.h"

#include <algorithm>
#include <cstdio>

#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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/tools/vmap-extractor/adtfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#ifndef ADT_H
#define ADT_H

#include <libmpq/mpq.h>
#include <ml/mpq.h>
#include "wmo.h"
#include "vmapexport.h"
Expand All @@ -35,8 +34,6 @@
#define CHUNKSIZE ((TILESIZE) / 16.0f)
#define UNITSIZE (CHUNKSIZE / 8.0f)

class Liquid;

/**
* @brief
*
Expand Down Expand Up @@ -142,7 +139,6 @@ struct MapChunkHeader
uint32 effectId; /**< TODO */
};


/**
* @brief
*
Expand Down
94 changes: 39 additions & 55 deletions src/tools/vmap-extractor/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,15 @@
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/

#include "vmapexport.h"
#include <cassert>
#include <algorithm>
#include <cstdio>

#include <ml/mpq.h>
#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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);

}

Expand All @@ -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");
}
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -309,4 +293,4 @@ void ExtractGameobjectModels()
}

printf("Done!\n");
}
}
19 changes: 4 additions & 15 deletions src/tools/vmap-extractor/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,11 @@
#ifndef MODEL_H
#define MODEL_H

#include <vector>
#include <ml/loadlib.h>
#include "vec3d.h"
#include "modelheaders.h"
#include <vector>
#include "vmapexport.h"

class WMOInstance;
class MPQFile;

/**
* @brief
*
* @param v
* @return Vec3D
*/
Vec3D fixCoordSystem(Vec3D v);
#include "wmo.h"

/**
* @brief
Expand All @@ -61,7 +50,7 @@ class Model
* @param failedPaths
* @return bool
*/
bool open(StringSet& failedPaths);
bool open(std::set<std::string>& failedPaths);
/**
* @brief
*
Expand Down Expand Up @@ -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<std::string>& failedPaths);

/**
* @brief
Expand Down
Loading

0 comments on commit a11f1e6

Please sign in to comment.