mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-18 08:28:32 +01:00
Tools/MeshExtract:
Fixed linux build, thanks Dev[Acho]. Added a DBC class It will now autodetect your locale and start extracting mmaps as soon as started.
This commit is contained in:
@@ -29,7 +29,14 @@ ADT::~ADT()
|
||||
|
||||
void ADT::Read()
|
||||
{
|
||||
Header.Read(Data->GetChunkByName("MHDR")->GetStream());
|
||||
Chunk* mhdr = Data->GetChunkByName("MHDR");
|
||||
if (!mhdr)
|
||||
{
|
||||
delete Data;
|
||||
Data = NULL;
|
||||
return;
|
||||
}
|
||||
Header.Read(mhdr->GetStream());
|
||||
MapChunks.reserve(16 * 16);
|
||||
int mapChunkIndex = 0;
|
||||
|
||||
|
||||
@@ -15,6 +15,13 @@ if( UNIX )
|
||||
include_directories (
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/src/server/shared
|
||||
${CMAKE_SOURCE_DIR}/src/server/shared/Database
|
||||
${CMAKE_SOURCE_DIR}/src/server/shared/Database/Implementation
|
||||
${CMAKE_SOURCE_DIR}/src/server/shared/Threading
|
||||
${CMAKE_SOURCE_DIR}/src/server/shared/Logging
|
||||
${CMAKE_SOURCE_DIR}/src/server/shared/Utilities
|
||||
${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic
|
||||
${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic/LinkedReference
|
||||
${CMAKE_SOURCE_DIR}/dep/recastnavigation/Recast
|
||||
${CMAKE_SOURCE_DIR}/dep/recastnavigation/Detour
|
||||
${CMAKE_SOURCE_DIR}/dep/libmpq
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
T* Get(K key)
|
||||
{
|
||||
std::map<K, T*>::iterator itr = _items.find(key);
|
||||
typename std::map<K, T*>::iterator itr = _items.find(key);
|
||||
if (itr != _items.end())
|
||||
return itr->second;
|
||||
return NULL;
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
|
||||
void Clear()
|
||||
{
|
||||
for (std::map<K, T*>::iterator itr = _items.begin(); itr != _items.end(); ++itr)
|
||||
for (typename std::map<K, T*>::iterator itr = _items.begin(); itr != _items.end(); ++itr)
|
||||
delete itr->second;
|
||||
_items.clear();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
|
||||
void ContinentBuilder::Build()
|
||||
{
|
||||
FILE* mmap = fopen("608.mmap", "wb");
|
||||
char buff[50];
|
||||
sprintf(buff, "%03u.mmap", MapId);
|
||||
FILE* mmap = fopen(buff, "wb");
|
||||
dtNavMeshParams params;
|
||||
params.maxPolys = 32768;
|
||||
params.maxTiles = 4096;
|
||||
@@ -19,19 +21,26 @@ void ContinentBuilder::Build()
|
||||
fclose(mmap);
|
||||
for (std::vector<TilePos>::iterator itr = TileMap->TileTable.begin(); itr != TileMap->TileTable.end(); ++itr)
|
||||
{
|
||||
TileBuilder builder(Continent, itr->X, itr->Y, TileMap);
|
||||
TileBuilder builder(Continent, itr->X, itr->Y, TileMap, MapId);
|
||||
char buff[100];
|
||||
sprintf(buff, "%03u%02u%02u.mmtile", builder.MapId, itr->X, itr->Y);
|
||||
FILE* f = fopen(buff, "wb");
|
||||
sprintf(buff, "%03u%02u%02u.mmtile", MapId, itr->X, itr->Y);
|
||||
FILE* f = fopen(buff, "r");
|
||||
if (f) // Check if file already exists.
|
||||
{
|
||||
fclose(f);
|
||||
continue;
|
||||
}
|
||||
uint8* nav = builder.Build();
|
||||
if (nav)
|
||||
{
|
||||
fclose(f);
|
||||
f = fopen(buff, "wb");
|
||||
MmapTileHeader header;
|
||||
header.size = builder.DataSize;
|
||||
fwrite(&header, sizeof(MmapTileHeader), 1, f);
|
||||
fwrite(nav, sizeof(unsigned char), builder.DataSize, f);
|
||||
fclose(f);
|
||||
}
|
||||
fclose(f);
|
||||
dtFree(nav);
|
||||
printf("[%02u,%02u] Tile Built!\n", itr->X, itr->Y);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
#define CONT_BUILDER_H
|
||||
#include <string>
|
||||
#include "WDT.h"
|
||||
#include "Common.h"
|
||||
|
||||
class ContinentBuilder
|
||||
{
|
||||
public:
|
||||
ContinentBuilder(std::string continent, WDT* wdt) : Continent(continent), TileMap(wdt) {}
|
||||
ContinentBuilder(std::string continent, uint32 mapId, WDT* wdt) : MapId(mapId), Continent(continent), TileMap(wdt) {}
|
||||
void Build();
|
||||
private:
|
||||
std::string Continent;
|
||||
WDT* TileMap;
|
||||
uint32 MapId;
|
||||
};
|
||||
#endif
|
||||
64
src/tools/mesh_extractor/DBC.cpp
Normal file
64
src/tools/mesh_extractor/DBC.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <cstdio>
|
||||
#include "DBC.h"
|
||||
#include "Common.h"
|
||||
|
||||
DBC::DBC( FILE* stream ) : StringBlock(NULL), IsFaulty(true), StringBlockSize(0)
|
||||
{
|
||||
char magic[5];
|
||||
fread(&magic, sizeof(char), 4, stream);
|
||||
magic[4] = '\0';
|
||||
fread(&RecordCount, sizeof(uint32), 1, stream);
|
||||
Records.reserve(RecordCount);
|
||||
fread(&Fields, sizeof(uint32), 1, stream);
|
||||
fread(&RecordSize, sizeof(uint32), 1, stream);
|
||||
fread(&StringBlockSize, sizeof(uint32), 1, stream);
|
||||
|
||||
for (int i = 0; i < RecordCount; i++)
|
||||
{
|
||||
Record* rec = new Record(this);
|
||||
Records.push_back(rec);
|
||||
int size = 0;
|
||||
for (int f = 0; f < Fields; f++)
|
||||
{
|
||||
if (size + 4 > RecordSize)
|
||||
{
|
||||
IsFaulty = true;
|
||||
break;
|
||||
}
|
||||
uint32 tmp;
|
||||
fread(&tmp, sizeof(uint32), 1, stream);
|
||||
rec->Values.push_back(tmp);
|
||||
size += 4;
|
||||
}
|
||||
}
|
||||
StringBlock = new uint8[StringBlockSize];
|
||||
fread(StringBlock, sizeof(uint8), StringBlockSize, stream);
|
||||
}
|
||||
|
||||
std::string DBC::GetStringByOffset( int offset )
|
||||
{
|
||||
int len = 0;
|
||||
for (int i = offset; i < StringBlockSize; i++)
|
||||
{
|
||||
if (!StringBlock[i])
|
||||
{
|
||||
len = (i - offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
char* d = new char[len+1];
|
||||
strcpy(d, (const char*)(StringBlock + offset));
|
||||
d[len] = '\0';
|
||||
std::string val = std::string(d);
|
||||
delete d;
|
||||
return val;
|
||||
}
|
||||
|
||||
Record* DBC::GetRecordById( int id )
|
||||
{
|
||||
// we assume Id is index 0
|
||||
for (std::vector<Record*>::iterator itr = Records.begin(); itr != Records.end(); ++itr)
|
||||
if ((*itr)->Values[0] == id)
|
||||
return *itr;
|
||||
return NULL;
|
||||
}
|
||||
51
src/tools/mesh_extractor/DBC.h
Normal file
51
src/tools/mesh_extractor/DBC.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef DBC_H
|
||||
#define DBC_H
|
||||
#include <vector>
|
||||
#include "Common.h"
|
||||
|
||||
class Record;
|
||||
|
||||
class DBC
|
||||
{
|
||||
public:
|
||||
DBC(FILE* stream);
|
||||
|
||||
std::string GetStringByOffset(int offset);
|
||||
|
||||
Record* GetRecordById(int id);
|
||||
|
||||
std::string Name;
|
||||
std::vector<Record*> Records;
|
||||
int RecordCount;
|
||||
int Fields;
|
||||
int RecordSize;
|
||||
uint8* StringBlock;
|
||||
uint32 StringBlockSize;
|
||||
bool IsFaulty;
|
||||
};
|
||||
|
||||
class Record
|
||||
{
|
||||
public:
|
||||
Record(DBC* dbc) : Source(dbc) {}
|
||||
|
||||
DBC* Source;
|
||||
std::vector<int> Values;
|
||||
|
||||
int operator[](int index)
|
||||
{
|
||||
return Values[index];
|
||||
}
|
||||
|
||||
float GetFloat(int index)
|
||||
{
|
||||
return *(float*)(&Values[index]);
|
||||
}
|
||||
|
||||
std::string GetString(int index)
|
||||
{
|
||||
return Source->GetStringByOffset(Values[index]);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "Chunk.h"
|
||||
#include "Cache.h"
|
||||
#include "Model.h"
|
||||
#include "g3d/Matrix4.h"
|
||||
#include "G3D/Matrix4.h"
|
||||
|
||||
DoodadHandler::DoodadHandler( ADT* adt ) : ObjectDataHandler(adt), _definitions(NULL), _paths(NULL)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "MPQManager.h"
|
||||
#include "MPQ.h"
|
||||
#include "DBC.h"
|
||||
#include "Utils.h"
|
||||
|
||||
char* MPQManager::Files[] = {
|
||||
"common.MPQ",
|
||||
@@ -11,42 +13,43 @@ char* MPQManager::Files[] = {
|
||||
"patch-3.MPQ"
|
||||
};
|
||||
|
||||
char* MPQManager::Languages[] = { "esES", "enUS", "enGB", "esMX", "deDE" };
|
||||
|
||||
void MPQManager::Initialize()
|
||||
{
|
||||
LoadMPQs();
|
||||
InitializeDBC();
|
||||
uint32 size = sizeof(Files) / sizeof(char*);
|
||||
for (uint32 i = 0; i < size; ++i)
|
||||
{
|
||||
MPQArchive* arc = new MPQArchive(std::string("Data/" + std::string(Files[i])).c_str());
|
||||
Archives.push_front(arc);
|
||||
printf("Opened %s\n", Files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void MPQManager::LoadMaps()
|
||||
{
|
||||
|
||||
DBC* file = GetDBC("Map");
|
||||
printf("NAME %s\n", file->GetRecordById(608)->GetString(1).c_str());
|
||||
}
|
||||
|
||||
void MPQManager::LoadMPQs()
|
||||
void MPQManager::InitializeDBC()
|
||||
{
|
||||
// Load the locale MPQ files first
|
||||
char filename[512];
|
||||
|
||||
/*sprintf(filename,"Data/%s/locale-%s.MPQ", langs[locale], langs[locale]);*/
|
||||
Archives.push_front(new MPQArchive("Data/enUS/locale-enUS.MPQ"));
|
||||
|
||||
for(int i = 0; i < 3; ++i)
|
||||
CurLocale = 0;
|
||||
std::string fileName;
|
||||
uint32 size = sizeof(Languages) / sizeof(char*);
|
||||
for (uint32 i = 0; i < size; ++i)
|
||||
{
|
||||
char ext[3] = "";
|
||||
if (i)
|
||||
sprintf(ext, "-%i", i + 1);
|
||||
|
||||
sprintf(filename, "Data/enUS/patch-enUS%s.MPQ", ext);
|
||||
Archives.push_front(new MPQArchive(filename));
|
||||
fileName = "Data/" + std::string(Languages[i]) + "/locale-" + std::string(Languages[i]) + ".MPQ";
|
||||
FILE* file = fopen(fileName.c_str(), "rb");
|
||||
if (file)
|
||||
{
|
||||
CurLocale = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Now load the common MPQ files
|
||||
int count = sizeof(Files) / sizeof(char*);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
sprintf(filename, "Data/%s", Files[i]);
|
||||
Archives.push_front(new MPQArchive(filename));
|
||||
}
|
||||
printf("Loaded %u MPQ files succesfully\n", Archives.size());
|
||||
Archives.push_front(new MPQArchive(fileName.c_str()));
|
||||
printf("Using locale: %s\n", Languages[CurLocale]);
|
||||
}
|
||||
|
||||
FILE* MPQManager::GetFile( std::string path )
|
||||
@@ -56,3 +59,9 @@ FILE* MPQManager::GetFile( std::string path )
|
||||
return NULL;
|
||||
return file.GetFileStream();
|
||||
}
|
||||
|
||||
DBC* MPQManager::GetDBC( std::string name )
|
||||
{
|
||||
std::string path = "DBFilesClient\\" + name + ".dbc";
|
||||
return new DBC(GetFile(path));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "MPQ.h"
|
||||
|
||||
class DBC;
|
||||
class MPQManager
|
||||
{
|
||||
public:
|
||||
@@ -12,12 +13,15 @@ public:
|
||||
void Initialize();
|
||||
void LoadMaps();
|
||||
FILE* GetFile(std::string path);
|
||||
DBC* GetDBC(std::string name);
|
||||
|
||||
std::deque<MPQArchive*> Archives;
|
||||
uint32 CurLocale;
|
||||
|
||||
static char* Files[];
|
||||
static char* Languages[];
|
||||
protected:
|
||||
void LoadMPQs();
|
||||
void InitializeDBC();
|
||||
};
|
||||
|
||||
extern MPQManager* MPQHandler;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "WDT.h"
|
||||
#include "ContinentBuilder.h"
|
||||
#include "Cache.h"
|
||||
#include "DBC.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "LoginDatabase.h"
|
||||
@@ -12,6 +13,17 @@ CacheClass* Cache;
|
||||
|
||||
void ExtractAllMaps()
|
||||
{
|
||||
DBC* dbc = MPQHandler->GetDBC("Map");
|
||||
for (std::vector<Record*>::iterator itr = dbc->Records.begin(); itr != dbc->Records.end(); ++itr)
|
||||
{
|
||||
std::string name = (*itr)->GetString(1);
|
||||
WDT wdt("World\\maps\\" + name + "\\" + name + ".wdt");
|
||||
if (!wdt.IsValid || wdt.IsGlobalModel)
|
||||
continue;
|
||||
ContinentBuilder builder(name, (*itr)->Values[0], &wdt);
|
||||
builder.Build();
|
||||
}
|
||||
/*
|
||||
WDT wdt("World\\maps\\DalaranPrison\\DalaranPrison.wdt");
|
||||
if (!wdt.IsValid)
|
||||
return;
|
||||
@@ -23,6 +35,7 @@ void ExtractAllMaps()
|
||||
}
|
||||
ContinentBuilder builder("DalaranPrison", &wdt);
|
||||
builder.Build();
|
||||
*/
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "RecastAlloc.h"
|
||||
#include "DetourNavMeshBuilder.h"
|
||||
|
||||
TileBuilder::TileBuilder(std::string world, int x, int y, WDT* wdt) : _Geometry(NULL), World(world), X(x), Y(y), MapId(608), DataSize(0), Wdt(wdt)
|
||||
TileBuilder::TileBuilder(std::string world, int x, int y, WDT* wdt, uint32 mapId) : _Geometry(NULL), World(world), X(x), Y(y), MapId(mapId), DataSize(0), Wdt(wdt)
|
||||
{
|
||||
// Cell Size = TileSize / TileVoxelSize
|
||||
// 1800 = TileVoxelSize
|
||||
@@ -54,6 +54,11 @@ uint8* TileBuilder::Build()
|
||||
{
|
||||
adt = new ADT(Utils::GetAdtPath(World, X, Y));
|
||||
adt->Read();
|
||||
if (!adt->Data)
|
||||
{
|
||||
delete adt;
|
||||
return NULL;
|
||||
}
|
||||
Cache->AdtCache.Insert(std::make_pair(X, Y), adt);
|
||||
}
|
||||
_Geometry->AddAdt(adt);
|
||||
|
||||
@@ -10,7 +10,7 @@ class WDT;
|
||||
class TileBuilder
|
||||
{
|
||||
public:
|
||||
TileBuilder(std::string world, int x, int y, WDT* wdt);
|
||||
TileBuilder(std::string world, int x, int y, WDT* wdt, uint32 mapId);
|
||||
void CalculateTileBounds(float*& bmin, float*& bmax);
|
||||
uint8* Build();
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "WorldModelHandler.h"
|
||||
#include "Constants.h"
|
||||
#include <cstring>
|
||||
#include "g3d/Matrix4.h"
|
||||
#include "g3d/Quat.h"
|
||||
#include "G3D/Matrix4.h"
|
||||
#include "G3D/Quat.h"
|
||||
|
||||
const float Constants::TileSize = 533.0f + (1/3.0f);
|
||||
const float Constants::MaxXY = 32.0f * Constants::TileSize;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "g3d/Matrix4.h"
|
||||
#include "G3D/Matrix4.h"
|
||||
#include "DetourNavMesh.h"
|
||||
|
||||
#include "Common.h"
|
||||
@@ -573,7 +573,7 @@ public:
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
static std::string Utils::Replace( std::string str, const std::string& oldStr, const std::string& newStr );
|
||||
static std::string Replace( std::string str, const std::string& oldStr, const std::string& newStr );
|
||||
static G3D::Matrix4 GetWmoDoodadTransformation( DoodadInstance inst, WorldModelDefinition root );
|
||||
};
|
||||
#endif
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "Cache.h"
|
||||
#include "Model.h"
|
||||
#include "Common.h"
|
||||
#include "g3d/Matrix4.h"
|
||||
#include "G3D/Matrix4.h"
|
||||
#include <cstdio>
|
||||
|
||||
WorldModelDefinition WorldModelDefinition::Read( FILE* file )
|
||||
|
||||
Reference in New Issue
Block a user