diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/mesh_extractor/ADT.cpp | 9 | ||||
-rw-r--r-- | src/tools/mesh_extractor/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/tools/mesh_extractor/Cache.h | 4 | ||||
-rw-r--r-- | src/tools/mesh_extractor/ContinentBuilder.cpp | 19 | ||||
-rw-r--r-- | src/tools/mesh_extractor/ContinentBuilder.h | 4 | ||||
-rw-r--r-- | src/tools/mesh_extractor/DBC.cpp | 64 | ||||
-rw-r--r-- | src/tools/mesh_extractor/DBC.h | 51 | ||||
-rw-r--r-- | src/tools/mesh_extractor/DoodadHandler.cpp | 2 | ||||
-rw-r--r-- | src/tools/mesh_extractor/MPQManager.cpp | 59 | ||||
-rw-r--r-- | src/tools/mesh_extractor/MPQManager.h | 6 | ||||
-rw-r--r-- | src/tools/mesh_extractor/MeshExtractor.cpp | 13 | ||||
-rw-r--r-- | src/tools/mesh_extractor/TileBuilder.cpp | 7 | ||||
-rw-r--r-- | src/tools/mesh_extractor/TileBuilder.h | 2 | ||||
-rw-r--r-- | src/tools/mesh_extractor/Utils.cpp | 4 | ||||
-rw-r--r-- | src/tools/mesh_extractor/Utils.h | 4 | ||||
-rw-r--r-- | src/tools/mesh_extractor/WorldModelHandler.cpp | 2 |
16 files changed, 214 insertions, 43 deletions
diff --git a/src/tools/mesh_extractor/ADT.cpp b/src/tools/mesh_extractor/ADT.cpp index c564d7193cf..98bce8b2057 100644 --- a/src/tools/mesh_extractor/ADT.cpp +++ b/src/tools/mesh_extractor/ADT.cpp @@ -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; diff --git a/src/tools/mesh_extractor/CMakeLists.txt b/src/tools/mesh_extractor/CMakeLists.txt index 09bd2982213..8ef48a90742 100644 --- a/src/tools/mesh_extractor/CMakeLists.txt +++ b/src/tools/mesh_extractor/CMakeLists.txt @@ -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 diff --git a/src/tools/mesh_extractor/Cache.h b/src/tools/mesh_extractor/Cache.h index 799878bdd3b..83b6ba6ca7a 100644 --- a/src/tools/mesh_extractor/Cache.h +++ b/src/tools/mesh_extractor/Cache.h @@ -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(); } diff --git a/src/tools/mesh_extractor/ContinentBuilder.cpp b/src/tools/mesh_extractor/ContinentBuilder.cpp index c63445b2287..7391ebb8767 100644 --- a/src/tools/mesh_extractor/ContinentBuilder.cpp +++ b/src/tools/mesh_extractor/ContinentBuilder.cpp @@ -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); } diff --git a/src/tools/mesh_extractor/ContinentBuilder.h b/src/tools/mesh_extractor/ContinentBuilder.h index 7db141ddcf1..92c97c5f7e0 100644 --- a/src/tools/mesh_extractor/ContinentBuilder.h +++ b/src/tools/mesh_extractor/ContinentBuilder.h @@ -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
\ No newline at end of file diff --git a/src/tools/mesh_extractor/DBC.cpp b/src/tools/mesh_extractor/DBC.cpp new file mode 100644 index 00000000000..be04ce070ee --- /dev/null +++ b/src/tools/mesh_extractor/DBC.cpp @@ -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; +} diff --git a/src/tools/mesh_extractor/DBC.h b/src/tools/mesh_extractor/DBC.h new file mode 100644 index 00000000000..6c86c1391dd --- /dev/null +++ b/src/tools/mesh_extractor/DBC.h @@ -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
\ No newline at end of file diff --git a/src/tools/mesh_extractor/DoodadHandler.cpp b/src/tools/mesh_extractor/DoodadHandler.cpp index aa298cea698..28bb9da5f21 100644 --- a/src/tools/mesh_extractor/DoodadHandler.cpp +++ b/src/tools/mesh_extractor/DoodadHandler.cpp @@ -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) { diff --git a/src/tools/mesh_extractor/MPQManager.cpp b/src/tools/mesh_extractor/MPQManager.cpp index 35d4c91fc14..24e7e827548 100644 --- a/src/tools/mesh_extractor/MPQManager.cpp +++ b/src/tools/mesh_extractor/MPQManager.cpp @@ -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)); +} diff --git a/src/tools/mesh_extractor/MPQManager.h b/src/tools/mesh_extractor/MPQManager.h index e10066ae4a6..725e0168237 100644 --- a/src/tools/mesh_extractor/MPQManager.h +++ b/src/tools/mesh_extractor/MPQManager.h @@ -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; diff --git a/src/tools/mesh_extractor/MeshExtractor.cpp b/src/tools/mesh_extractor/MeshExtractor.cpp index 38a120449bc..77b5a8e8c3d 100644 --- a/src/tools/mesh_extractor/MeshExtractor.cpp +++ b/src/tools/mesh_extractor/MeshExtractor.cpp @@ -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[]) diff --git a/src/tools/mesh_extractor/TileBuilder.cpp b/src/tools/mesh_extractor/TileBuilder.cpp index 445641fc009..8bbfd5afb69 100644 --- a/src/tools/mesh_extractor/TileBuilder.cpp +++ b/src/tools/mesh_extractor/TileBuilder.cpp @@ -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); diff --git a/src/tools/mesh_extractor/TileBuilder.h b/src/tools/mesh_extractor/TileBuilder.h index 7dff363cabe..261675af7e2 100644 --- a/src/tools/mesh_extractor/TileBuilder.h +++ b/src/tools/mesh_extractor/TileBuilder.h @@ -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(); diff --git a/src/tools/mesh_extractor/Utils.cpp b/src/tools/mesh_extractor/Utils.cpp index c7c0cff0d42..2f07bd20080 100644 --- a/src/tools/mesh_extractor/Utils.cpp +++ b/src/tools/mesh_extractor/Utils.cpp @@ -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; diff --git a/src/tools/mesh_extractor/Utils.h b/src/tools/mesh_extractor/Utils.h index 188d47a88ce..c247169df73 100644 --- a/src/tools/mesh_extractor/Utils.h +++ b/src/tools/mesh_extractor/Utils.h @@ -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
\ No newline at end of file diff --git a/src/tools/mesh_extractor/WorldModelHandler.cpp b/src/tools/mesh_extractor/WorldModelHandler.cpp index 1a772a36558..636b06f6f73 100644 --- a/src/tools/mesh_extractor/WorldModelHandler.cpp +++ b/src/tools/mesh_extractor/WorldModelHandler.cpp @@ -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 ) |