diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/map_extractor/System.cpp | 16 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/adtfile.cpp | 4 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/adtfile.h | 2 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/dbcfile.cpp | 14 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/dbcfile.h | 4 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/gameobject_extract.cpp | 4 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/model.cpp | 6 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/modelheaders.h | 7 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/mpq_libmpq.cpp | 111 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/mpq_libmpq04.h | 90 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/mpqfile.cpp | 86 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/mpqfile.h | 80 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/vmapexport.cpp | 323 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/wdtfile.cpp | 6 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/wdtfile.h | 2 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/wmo.cpp | 8 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/wmo.h | 1 |
18 files changed, 437 insertions, 335 deletions
diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index 41941795b20..e9577d0f108 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -85,7 +85,7 @@ char const* CONF_mpq_list[]= "expansion3.MPQ", }; -uint32 const Builds[] = {13164, 13205, 13287, 13329, 13596, 13623, 13914, 14007, 14333, 14480, 14545, 15005, 15050, 15211, 0}; +uint32 const Builds[] = {13164, 13205, 13287, 13329, 13596, 13623, 13914, 14007, 14333, 14480, 14545, 15005, 15050, 15211, 15354, 15595, 0}; #define LAST_DBC_IN_DATA_BUILD 13623 // after this build mpqs with dbc are back to locale folder char* const Locales[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU"}; @@ -1150,8 +1150,15 @@ void LoadCommonMPQFiles(uint32 build) _stprintf(filename, _T("%s/Data/%s"), input_path, CONF_mpq_list[i]); if (!SFileOpenPatchArchive(WorldMpq, filename, "", 0)) + { if (GetLastError() != ERROR_PATH_NOT_FOUND) _tprintf(_T("Cannot open archive %s\n"), filename); + else + _tprintf(_T("Not found %s\n"), filename); + } + else + _tprintf(_T("Loaded %s\n"), filename); + } char const* prefix = NULL; @@ -1173,8 +1180,12 @@ void LoadCommonMPQFiles(uint32 build) { if (GetLastError() != ERROR_PATH_NOT_FOUND) _tprintf(_T("Cannot open patch archive %s\n"), filename); + else + _tprintf(_T("Not found %s\n"), filename); continue; } + else + _tprintf(_T("Loaded %s\n"), filename); } } @@ -1191,9 +1202,6 @@ int main(int argc, char * arg[]) for (int i = 0; i < LOCALES_COUNT; ++i) { - TCHAR tmp1[512]; - _stprintf(tmp1, _T("%s/Data/%s/locale-%s.MPQ"), input_path, Locales[i], Locales[i]); - //Open MPQs if (!LoadLocaleMPQFile(i)) { diff --git a/src/tools/vmap4_extractor/CMakeLists.txt b/src/tools/vmap4_extractor/CMakeLists.txt index c1ef3125a20..3f6b2673be2 100644 --- a/src/tools/vmap4_extractor/CMakeLists.txt +++ b/src/tools/vmap4_extractor/CMakeLists.txt @@ -15,9 +15,11 @@ file(GLOB_RECURSE sources *.cpp *.h) add_definitions("-DIOMAP_DEBUG") # build setup currently only supports libmpq 0.4.x -add_definitions("-Wall") -add_definitions("-ggdb") -add_definitions("-O3") +if( NOT WIN32 ) + add_definitions("-Wall") + add_definitions("-ggdb") + add_definitions("-O3") +endif() include_directories( ${CMAKE_SOURCE_DIR}/dep/StormLib/src diff --git a/src/tools/vmap4_extractor/adtfile.cpp b/src/tools/vmap4_extractor/adtfile.cpp index a966172a3be..c53b63ffa5e 100644 --- a/src/tools/vmap4_extractor/adtfile.cpp +++ b/src/tools/vmap4_extractor/adtfile.cpp @@ -78,7 +78,9 @@ char * GetExtension(char * FileName) return NULL; } -ADTFile::ADTFile(char* filename): ADT(filename) +extern HANDLE WorldMpq; + +ADTFile::ADTFile(char* filename): ADT(WorldMpq, filename) { Adtfilename.append(filename); } diff --git a/src/tools/vmap4_extractor/adtfile.h b/src/tools/vmap4_extractor/adtfile.h index 08814996f68..795eebc892f 100644 --- a/src/tools/vmap4_extractor/adtfile.h +++ b/src/tools/vmap4_extractor/adtfile.h @@ -19,7 +19,7 @@ #ifndef ADT_H #define ADT_H -#include "mpq_libmpq04.h" +#include "mpqfile.h" #include "wmo.h" #include "model.h" diff --git a/src/tools/vmap4_extractor/dbcfile.cpp b/src/tools/vmap4_extractor/dbcfile.cpp index 5b5fe314799..efc8aeabe8c 100644 --- a/src/tools/vmap4_extractor/dbcfile.cpp +++ b/src/tools/vmap4_extractor/dbcfile.cpp @@ -20,13 +20,16 @@ #include "dbcfile.h" -DBCFile::DBCFile(HANDLE file) : - _file(file), _data(NULL), _stringTable(NULL) +DBCFile::DBCFile(HANDLE mpq, const char* filename) : + _mpq(mpq), _filename(filename), _file(NULL), _data(NULL), _stringTable(NULL) { } bool DBCFile::open() { + if (!SFileOpenFileEx(_mpq, _filename, SFILE_OPEN_PATCHED_FILE, &_file)) + return false; + char header[4]; unsigned int na, nb, es, ss; @@ -38,18 +41,22 @@ bool DBCFile::open() if (header[0] != 'W' || header[1] != 'D' || header[2] != 'B' || header[3] != 'C') return false; + readBytes = 0; SFileReadFile(_file, &na, 4, &readBytes, NULL); if (readBytes != 4) // Number of records return false; + readBytes = 0; SFileReadFile(_file, &nb, 4, &readBytes, NULL); if (readBytes != 4) // Number of fields return false; + readBytes = 0; SFileReadFile(_file, &es, 4, &readBytes, NULL); if (readBytes != 4) // Size of a record return false; + readBytes = 0; SFileReadFile(_file, &ss, 4, &readBytes, NULL); if (readBytes != 4) // String size return false; @@ -65,6 +72,7 @@ bool DBCFile::open() _stringTable = _data + _recordSize*_recordCount; size_t data_size = _recordSize * _recordCount + _stringSize; + readBytes = 0; SFileReadFile(_file, _data, data_size, &readBytes, NULL); if (readBytes != data_size) return false; @@ -75,6 +83,8 @@ bool DBCFile::open() DBCFile::~DBCFile() { delete [] _data; + if (_file != NULL) + SFileCloseFile(_file); } DBCFile::Record DBCFile::getRecord(size_t id) diff --git a/src/tools/vmap4_extractor/dbcfile.h b/src/tools/vmap4_extractor/dbcfile.h index 9fdb7a9e268..007ccb6cdcb 100644 --- a/src/tools/vmap4_extractor/dbcfile.h +++ b/src/tools/vmap4_extractor/dbcfile.h @@ -25,7 +25,7 @@ class DBCFile { public: - DBCFile(HANDLE file); + DBCFile(HANDLE mpq, const char* filename); ~DBCFile(); // Open database. It must be openened before it can be used. @@ -131,6 +131,8 @@ class DBCFile size_t getMaxId(); private: + HANDLE _mpq; + const char* _filename; HANDLE _file; size_t _recordSize; size_t _recordCount; diff --git a/src/tools/vmap4_extractor/gameobject_extract.cpp b/src/tools/vmap4_extractor/gameobject_extract.cpp index 8a1f67cd2c2..4c8e423bfc4 100644 --- a/src/tools/vmap4_extractor/gameobject_extract.cpp +++ b/src/tools/vmap4_extractor/gameobject_extract.cpp @@ -35,10 +35,12 @@ bool ExtractSingleModel(std::string& fname) return mdl.ConvertToVMAPModel(output.c_str()); } +extern HANDLE LocaleMpq; + void ExtractGameobjectModels() { printf("Extracting GameObject models..."); - DBCFile dbc("DBFilesClient\\GameObjectDisplayInfo.dbc"); + DBCFile dbc(LocaleMpq, "DBFilesClient\\GameObjectDisplayInfo.dbc"); if(!dbc.open()) { printf("Fatal error: Invalid GameObjectDisplayInfo.dbc file format!\n"); diff --git a/src/tools/vmap4_extractor/model.cpp b/src/tools/vmap4_extractor/model.cpp index e81972f521f..d98dca9001b 100644 --- a/src/tools/vmap4_extractor/model.cpp +++ b/src/tools/vmap4_extractor/model.cpp @@ -19,18 +19,20 @@ #include "vmapexport.h" #include "model.h" #include "wmo.h" -#include "mpq_libmpq04.h" +#include "mpqfile.h" #include <cassert> #include <algorithm> #include <cstdio> +extern HANDLE WorldMpq; + Model::Model(std::string &filename) : filename(filename), vertices(0), indices(0) { } bool Model::open() { - MPQFile f(filename.c_str()); + MPQFile f(WorldMpq, filename.c_str()); ok = !f.isEof(); diff --git a/src/tools/vmap4_extractor/modelheaders.h b/src/tools/vmap4_extractor/modelheaders.h index d859fd3511e..7fd908d7442 100644 --- a/src/tools/vmap4_extractor/modelheaders.h +++ b/src/tools/vmap4_extractor/modelheaders.h @@ -19,12 +19,7 @@ #ifndef MODELHEADERS_H #define MODELHEADERS_H -/* typedef unsigned char uint8; -typedef char int8; -typedef unsigned short uint16; -typedef short int16; -typedef unsigned int uint32; -typedef int int32; */ +#include "mpqfile.h" // integer typedefs #pragma pack(push,1) diff --git a/src/tools/vmap4_extractor/mpq_libmpq.cpp b/src/tools/vmap4_extractor/mpq_libmpq.cpp deleted file mode 100644 index 528b9679a58..00000000000 --- a/src/tools/vmap4_extractor/mpq_libmpq.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "mpq_libmpq04.h" -#include <deque> -#include <cstdio> - -ArchiveSet gOpenArchives; - -MPQArchive::MPQArchive(const char* filename) -{ - int result = libmpq__archive_open(&mpq_a, filename, -1); - printf("Opening %s\n", filename); - if(result) { - switch(result) { - case LIBMPQ_ERROR_OPEN : - printf("Error opening archive '%s': Does file really exist?\n", filename); - break; - case LIBMPQ_ERROR_FORMAT : /* bad file format */ - printf("Error opening archive '%s': Bad file format\n", filename); - break; - case LIBMPQ_ERROR_SEEK : /* seeking in file failed */ - printf("Error opening archive '%s': Seeking in file failed\n", filename); - break; - case LIBMPQ_ERROR_READ : /* Read error in archive */ - printf("Error opening archive '%s': Read error in archive\n", filename); - break; - case LIBMPQ_ERROR_MALLOC : /* maybe not enough memory? :) */ - printf("Error opening archive '%s': Maybe not enough memory\n", filename); - break; - default: - printf("Error opening archive '%s': Unknown error\n", filename); - break; - } - return; - } - gOpenArchives.push_front(this); -} - -void MPQArchive::close() -{ - //gOpenArchives.erase(erase(&mpq_a); - libmpq__archive_close(mpq_a); -} - -MPQFile::MPQFile(const char* filename): - eof(false), - buffer(0), - pointer(0), - size(0) -{ - for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i) - { - mpq_archive *mpq_a = (*i)->mpq_a; - - uint32 filenum; - if(libmpq__file_number(mpq_a, filename, &filenum)) continue; - libmpq__off_t transferred; - libmpq__file_unpacked_size(mpq_a, filenum, &size); - - // HACK: in patch.mpq some files don't want to open and give 1 for filesize - if (size<=1) { - // printf("info: file %s has size %d; considered dummy file.\n", filename, size); - eof = true; - buffer = 0; - return; - } - buffer = new char[size]; - - //libmpq_file_getdata - libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); - /*libmpq_file_getdata(&mpq_a, hash, fileno, (unsigned char*)buffer);*/ - return; - - } - eof = true; - buffer = 0; -} - -size_t MPQFile::read(void* dest, size_t bytes) -{ - if (eof) return 0; - - size_t rpos = pointer + bytes; - if (rpos > size) { - bytes = size - pointer; - eof = true; - } - - memcpy(dest, &(buffer[pointer]), bytes); - - pointer = rpos; - - return bytes; -} - -void MPQFile::seek(int offset) -{ - pointer = offset; - eof = (pointer >= size); -} - -void MPQFile::seekRelative(int offset) -{ - pointer += offset; - eof = (pointer >= size); -} - -void MPQFile::close() -{ - if (buffer) delete[] buffer; - buffer = 0; - eof = true; -} diff --git a/src/tools/vmap4_extractor/mpq_libmpq04.h b/src/tools/vmap4_extractor/mpq_libmpq04.h deleted file mode 100644 index 5101309002e..00000000000 --- a/src/tools/vmap4_extractor/mpq_libmpq04.h +++ /dev/null @@ -1,90 +0,0 @@ -#define _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_WARNINGS - -#ifndef MPQ_H -#define MPQ_H - -#include "libmpq/mpq.h" -#include <string.h> -#include <ctype.h> -#include <vector> -#include <iostream> -#include <deque> - -using namespace std; - -class MPQArchive -{ - -public: - mpq_archive_s *mpq_a; - - MPQArchive(const char* filename); - 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); - - char *buffer = new char[size]; - - libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); - - char seps[] = "\n"; - char *token; - - token = strtok( buffer, seps ); - uint32 counter = 0; - while ((token != NULL) && (counter < size)) { - //cout << token << endl; - token[strlen(token) - 1] = 0; - string s = token; - filelist.push_back(s); - counter += strlen(token) + 2; - token = strtok(NULL, seps); - } - - delete[] buffer; - } -}; -typedef std::deque<MPQArchive*> ArchiveSet; - -class MPQFile -{ - //MPQHANDLE handle; - bool eof; - char *buffer; - libmpq__off_t pointer,size; - - // disable copying - MPQFile(const MPQFile &f) {} - void operator=(const MPQFile &f) {} - -public: - MPQFile(const char* filename); // filenames are not case sensitive - ~MPQFile() { close(); } - size_t read(void* dest, size_t bytes); - size_t getSize() { return size; } - size_t getPos() { return pointer; } - char* getBuffer() { return buffer; } - char* getPointer() { return buffer + pointer; } - bool isEof() { return eof; } - void seek(int offset); - void seekRelative(int offset); - void close(); -}; - -inline void flipcc(char *fcc) -{ - char t; - t=fcc[0]; - fcc[0]=fcc[3]; - fcc[3]=t; - t=fcc[1]; - fcc[1]=fcc[2]; - fcc[2]=t; -} - -#endif diff --git a/src/tools/vmap4_extractor/mpqfile.cpp b/src/tools/vmap4_extractor/mpqfile.cpp new file mode 100644 index 00000000000..9f019f99f38 --- /dev/null +++ b/src/tools/vmap4_extractor/mpqfile.cpp @@ -0,0 +1,86 @@ +#include "mpqfile.h" +#include <deque> +#include <cstdio> +#include "StormLib.h" + +MPQFile::MPQFile(HANDLE mpq, const char* filename): + eof(false), + buffer(0), + pointer(0), + size(0) +{ + HANDLE file; + if (!SFileOpenFileEx(mpq, filename, SFILE_OPEN_PATCHED_FILE, &file)) + { + fprintf(stderr, "Can't open %s, err=%u!\n", filename, GetLastError()); + eof = true; + return; + } + + DWORD hi = 0; + size = SFileGetFileSize(file, &hi); + + if (hi) + { + fprintf(stderr, "Can't open %s, size[hi] = %u!\n", filename, (uint32)hi); + SFileCloseFile(file); + eof = true; + return; + } + + if (size <= 1) + { + fprintf(stderr, "Can't open %s, size = %u!\n", filename, size); + SFileCloseFile(file); + eof = true; + return; + } + + DWORD read = 0; + buffer = new char[size]; + if (!SFileReadFile(file, buffer, size, &read) || size != read) + { + fprintf(stderr, "Can't read %s, size=%u read=%u!\n", filename, size, read); + SFileCloseFile(file); + eof = true; + return; + } + + SFileCloseFile(file); +} + +size_t MPQFile::read(void* dest, size_t bytes) +{ + if (eof) return 0; + + size_t rpos = pointer + bytes; + if (rpos > size) { + bytes = size - pointer; + eof = true; + } + + memcpy(dest, &(buffer[pointer]), bytes); + + pointer = rpos; + + return bytes; +} + +void MPQFile::seek(int offset) +{ + pointer = offset; + eof = (pointer >= size); +} + +void MPQFile::seekRelative(int offset) +{ + pointer += offset; + eof = (pointer >= size); +} + +void MPQFile::close() +{ + if (buffer) delete[] buffer; + buffer = 0; + eof = true; +} diff --git a/src/tools/vmap4_extractor/mpqfile.h b/src/tools/vmap4_extractor/mpqfile.h new file mode 100644 index 00000000000..115d096a215 --- /dev/null +++ b/src/tools/vmap4_extractor/mpqfile.h @@ -0,0 +1,80 @@ +#define _CRT_SECURE_NO_DEPRECATE +#ifndef _CRT_SECURE_NO_WARNINGS // fuck the police^Wwarnings +#define _CRT_SECURE_NO_WARNINGS +#endif + +#ifndef MPQ_H +#define MPQ_H + +#include <string.h> +#include <ctype.h> +#include <vector> +#include <iostream> +#include <deque> + +#ifdef _WIN32 +#include <Windows.h> // mainly only HANDLE definition is required +typedef __int64 int64; +typedef __int32 int32; +typedef __int16 int16; +typedef __int8 int8; +typedef unsigned __int64 uint64; +typedef unsigned __int32 uint32; +typedef unsigned __int16 uint16; +typedef unsigned __int8 uint8; +#else +#include <stdint.h> +#ifndef uint64_t +#ifdef __linux__ +#include <linux/types.h> +#endif +#endif +typedef int64_t int64; +typedef int32_t int32; +typedef int16_t int16; +typedef int8_t int8; +typedef uint64_t uint64; +typedef uint32_t uint32; +typedef uint16_t uint16; +typedef uint8_t uint8; +#endif + +using namespace std; + +class MPQFile +{ + //MPQHANDLE handle; + bool eof; + char *buffer; + size_t pointer,size; + + // disable copying + MPQFile(const MPQFile &f); + void operator=(const MPQFile &f); + +public: + MPQFile(HANDLE mpq, const char* filename); // filenames are not case sensitive + ~MPQFile() { close(); } + size_t read(void* dest, size_t bytes); + size_t getSize() { return size; } + size_t getPos() { return pointer; } + char* getBuffer() { return buffer; } + char* getPointer() { return buffer + pointer; } + bool isEof() { return eof; } + void seek(int offset); + void seekRelative(int offset); + void close(); +}; + +inline void flipcc(char *fcc) +{ + char t; + t=fcc[0]; + fcc[0]=fcc[3]; + fcc[3]=t; + t=fcc[1]; + fcc[1]=fcc[2]; + fcc[2]=t; +} + +#endif diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index e60a773c6de..a1fd4e8321a 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -45,7 +45,7 @@ #include "wdtfile.h" #include "dbcfile.h" #include "wmo.h" -#include "mpq_libmpq04.h" +#include "mpqfile.h" #include "vmapexport.h" @@ -56,7 +56,37 @@ //----------------------------------------------------------------------------- -extern ArchiveSet gOpenArchives; +HANDLE WorldMpq = NULL; +HANDLE LocaleMpq = NULL; + +uint32 CONF_TargetBuild = 15595; // 4.3.4.15595 + +// List MPQ for extract maps from +char const* CONF_mpq_list[]= +{ + "world.MPQ", + "art.MPQ", + "expansion1.MPQ", + "expansion2.MPQ", + "expansion3.MPQ", + "world2.MPQ", +}; + +uint32 const Builds[] = {13164, 13205, 13287, 13329, 13596, 13623, 13914, 14007, 14333, 14480, 14545, 15005, 15050, 15211, 15354, 15595, 0}; +#define LAST_DBC_IN_DATA_BUILD 13623 // after this build mpqs with dbc are back to locale folder + +char* const Locales[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU"}; +TCHAR* const LocalesT[] = +{ + _T("enGB"), _T("enUS"), + _T("deDE"), _T("esES"), + _T("frFR"), _T("koKR"), + _T("zhCN"), _T("zhTW"), + _T("enCN"), _T("enTW"), + _T("esMX"), _T("ruRU"), +}; + +#define LOCALES_COUNT 12 typedef struct { @@ -69,7 +99,6 @@ uint16 *LiqType = 0; uint32 map_count; char output_path[128]="."; char input_path[1024]="."; -bool hasInputPathParam = false; bool preciseVectorData = false; // Constants @@ -78,6 +107,148 @@ bool preciseVectorData = false; const char* szWorkDirWmo = "./Buildings"; const char* szRawVMAPMagic = "VMAP041"; +bool LoadLocaleMPQFile(int locale) +{ + TCHAR buff[512]; + memset(buff, 0, sizeof(buff)); + _stprintf(buff, _T("%s%s/locale-%s.MPQ"), input_path, LocalesT[locale], LocalesT[locale]); + if (!SFileOpenArchive(buff, 0, MPQ_OPEN_READ_ONLY, &LocaleMpq)) + { + if (GetLastError() != ERROR_PATH_NOT_FOUND) + _tprintf(_T("Cannot open archive %s\n"), buff); + return false; + } + + char const* prefix = NULL; + for (int i = 0; Builds[i] && Builds[i] <= CONF_TargetBuild; ++i) + { + memset(buff, 0, sizeof(buff)); + if (Builds[i] > LAST_DBC_IN_DATA_BUILD) + { + prefix = ""; + _stprintf(buff, _T("%s%s/wow-update-%s-%u.MPQ"), input_path, LocalesT[locale], LocalesT[locale], Builds[i]); + } + else + { + prefix = Locales[locale]; + _stprintf(buff, _T("%swow-update-%u.MPQ"), input_path, Builds[i]); + } + + if (!SFileOpenPatchArchive(LocaleMpq, buff, prefix, 0)) + { + if (GetLastError() != ERROR_FILE_NOT_FOUND) + _tprintf(_T("Cannot open patch archive %s\n"), buff); + continue; + } + } + + return true; +} + +void LoadCommonMPQFiles(uint32 build) +{ + TCHAR filename[512]; + _stprintf(filename, _T("%sworld.MPQ"), input_path); + if (!SFileOpenArchive(filename, 0, MPQ_OPEN_READ_ONLY, &WorldMpq)) + { + if (GetLastError() != ERROR_PATH_NOT_FOUND) + _tprintf(_T("Cannot open archive %s\n"), filename); + return; + } + + int count = sizeof(CONF_mpq_list) / sizeof(char*); + for (int i = 1; i < count; ++i) + { + if (build < 15211 && !strcmp("world2.MPQ", CONF_mpq_list[i])) // 4.3.2 and higher MPQ + continue; + + _stprintf(filename, _T("%s%s"), input_path, CONF_mpq_list[i]); + if (!SFileOpenPatchArchive(WorldMpq, filename, "", 0)) + { + if (GetLastError() != ERROR_PATH_NOT_FOUND) + _tprintf(_T("Cannot open archive %s\n"), filename); + else + _tprintf(_T("Not found %s\n"), filename); + } + else + { + _tprintf(_T("Loaded %s\n"), filename); + + bool found = false; + int count = 0; + SFILE_FIND_DATA data; + HANDLE find = SFileFindFirstFile(WorldMpq, "*.*", &data, NULL); + if (find != NULL) + { + do + { + ++count; + if (data.dwFileFlags & MPQ_FILE_PATCH_FILE) + { + found = true; + break; + } + } + while (SFileFindNextFile(find, &data)); + } + SFileFindClose(find); + printf("Scanned %d files, found patch = %d\n", count, found); + } + } + + char const* prefix = NULL; + for (int i = 0; Builds[i] && Builds[i] <= CONF_TargetBuild; ++i) + { + memset(filename, 0, sizeof(filename)); + if (Builds[i] > LAST_DBC_IN_DATA_BUILD) + { + prefix = ""; + _stprintf(filename, _T("%swow-update-base-%u.MPQ"), input_path, Builds[i]); + } + else + { + prefix = "base"; + _stprintf(filename, _T("%swow-update-%u.MPQ"), input_path, Builds[i]); + } + + if (!SFileOpenPatchArchive(WorldMpq, filename, prefix, 0)) + { + if (GetLastError() != ERROR_PATH_NOT_FOUND) + _tprintf(_T("Cannot open patch archive %s\n"), filename); + else + _tprintf(_T("Not found %s\n"), filename); + continue; + } + else + { + _tprintf(_T("Loaded %s\n"), filename); + + + bool found = false; + int count = 0; + SFILE_FIND_DATA data; + HANDLE find = SFileFindFirstFile(WorldMpq, "*.*", &data, NULL); + if (find != NULL) + { + do + { + ++count; + if (data.dwFileFlags & MPQ_FILE_PATCH_FILE) + { + found = true; + break; + } + } + while (SFileFindNextFile(find, &data)); + } + SFileFindClose(find); + printf("Scanned %d files, found patch = %d\n", count, found); + } + } + +} + + // Local testing functions bool FileExists(const char* file) @@ -103,7 +274,8 @@ void strToLower(char* str) void ReadLiquidTypeTableDBC() { printf("Read LiquidType.dbc file..."); - DBCFile dbc("DBFilesClient\\LiquidType.dbc"); + + DBCFile dbc(LocaleMpq, "DBFilesClient\\LiquidType.dbc"); if(!dbc.open()) { printf("Fatal error: Invalid LiquidType.dbc file format!\n"); @@ -123,21 +295,23 @@ void ReadLiquidTypeTableDBC() bool ExtractWmo() { - bool success = true; + bool success = false; //const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"}; - for (ArchiveSet::const_iterator ar_itr = gOpenArchives.begin(); ar_itr != gOpenArchives.end() && success; ++ar_itr) + SFILE_FIND_DATA data; + HANDLE find = SFileFindFirstFile(WorldMpq, "*.wmo", &data, NULL); + if (find != NULL) { - vector<string> filelist; - - (*ar_itr)->GetFileListTo(filelist); - for (vector<string>::iterator fname = filelist.begin(); fname != filelist.end() && success; ++fname) + do { - if (fname->find(".wmo") != string::npos) - success = ExtractSingleWmo(*fname); + std::string str = data.cFileName; + //printf("Extracting wmo %s\n", str.c_str()); + success |= ExtractSingleWmo(str); } + while (SFileFindNextFile(find, &data)); } + SFileFindClose(find); if (success) printf("\nExtract wmo complete (No (fatal) errors)\n"); @@ -297,91 +471,10 @@ bool scan_patches(char* scanmatch, std::vector<std::string>& pArchiveNames) return(true); } -bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) -{ - if(!hasInputPathParam) - getGamePath(); - - printf("\nGame path: %s\n", input_path); - - char path[512]; - string in_path(input_path); - std::vector<std::string> locales, searchLocales; - - searchLocales.push_back("enGB"); - searchLocales.push_back("enUS"); - searchLocales.push_back("deDE"); - searchLocales.push_back("esES"); - searchLocales.push_back("frFR"); - searchLocales.push_back("koKR"); - searchLocales.push_back("zhCN"); - searchLocales.push_back("zhTW"); - searchLocales.push_back("enCN"); - searchLocales.push_back("enTW"); - searchLocales.push_back("esMX"); - searchLocales.push_back("ruRU"); - - for (std::vector<std::string>::iterator i = searchLocales.begin(); i != searchLocales.end(); ++i) - { - std::string localePath = in_path + *i; - // check if locale exists: - struct stat status; - if (stat(localePath.c_str(), &status)) - continue; - if ((status.st_mode & S_IFDIR) == 0) - continue; - printf("Found locale '%s'\n", i->c_str()); - locales.push_back(*i); - } - printf("\n"); - - // open locale expansion and common files - printf("Adding data files from locale directories.\n"); - for (std::vector<std::string>::iterator i = locales.begin(); i != locales.end(); ++i) - { - pArchiveNames.push_back(in_path + *i + "/locale-" + *i + ".MPQ"); - pArchiveNames.push_back(in_path + *i + "/expansion-locale-" + *i + ".MPQ"); - pArchiveNames.push_back(in_path + *i + "/lichking-locale-" + *i + ".MPQ"); - } - - // open expansion and common files - pArchiveNames.push_back(input_path + string("common.MPQ")); - pArchiveNames.push_back(input_path + string("common-2.MPQ")); - pArchiveNames.push_back(input_path + string("expansion.MPQ")); - pArchiveNames.push_back(input_path + string("lichking.MPQ")); - - // now, scan for the patch levels in the core dir - printf("Scanning patch levels from data directory.\n"); - sprintf(path, "%spatch", input_path); - if (!scan_patches(path, pArchiveNames)) - return(false); - - // now, scan for the patch levels in locale dirs - printf("Scanning patch levels from locale directories.\n"); - bool foundOne = false; - for (std::vector<std::string>::iterator i = locales.begin(); i != locales.end(); ++i) - { - printf("Locale: %s\n", i->c_str()); - sprintf(path, "%s%s/patch-%s", input_path, i->c_str(), i->c_str()); - if(scan_patches(path, pArchiveNames)) - foundOne = true; - } - - printf("\n"); - - if(!foundOne) - { - printf("no locale found\n"); - return false; - } - - return true; -} - bool processArgv(int argc, char ** argv, const char *versionString) { bool result = true; - hasInputPathParam = false; + bool hasInputPathParam = false; bool preciseVectorData = false; for(int i=1; i< argc; ++i) @@ -413,6 +506,11 @@ bool processArgv(int argc, char ** argv, const char *versionString) { preciseVectorData = true; } + else if(strcmp("-b",argv[i]) == 0) + { + if (i + 1 < argc) // all ok + CONF_TargetBuild = atoi(argv[i++ + 1]); + } else { result = false; @@ -428,6 +526,10 @@ bool processArgv(int argc, char ** argv, const char *versionString) printf(" -d <path>: Path to the vector data source folder.\n"); printf(" -? : This message.\n"); } + + if(!hasInputPathParam) + getGamePath(); + return result; } @@ -443,6 +545,7 @@ bool processArgv(int argc, char ** argv, const char *versionString) int main(int argc, char ** argv) { + getc(stdin); bool success=true; const char *versionString = "V4.00 2012_02"; @@ -476,21 +579,24 @@ int main(int argc, char ** argv) )) success = (errno == EEXIST); - // prepare archive name list - std::vector<std::string> archiveNames; - fillArchiveNameVector(archiveNames); - for (size_t i=0; i < archiveNames.size(); ++i) - { - MPQArchive *archive = new MPQArchive(archiveNames[i].c_str()); - if(!gOpenArchives.size() || gOpenArchives.front() != archive) - delete archive; - } + LoadCommonMPQFiles(CONF_TargetBuild); + + int FirstLocale = -1; - if(gOpenArchives.empty()) + for (int i = 0; i < LOCALES_COUNT; ++i) { - printf("FATAL ERROR: None MPQ archive found by path '%s'. Use -d option with proper path.\n",input_path); - return 1; + //Open MPQs + if (!LoadLocaleMPQFile(i)) + { + if (GetLastError() != ERROR_PATH_NOT_FOUND) + printf("Unable to load %s locale archives!\n", Locales[i]); + continue; + } + + printf("Detected and using locale locale: %s\n", Locales[i]); + break; } + ReadLiquidTypeTableDBC(); // extract data @@ -501,7 +607,7 @@ int main(int argc, char ** argv) //map.dbc if(success) { - DBCFile * dbc = new DBCFile("DBFilesClient\\Map.dbc"); + DBCFile * dbc = new DBCFile(LocaleMpq, "DBFilesClient\\Map.dbc"); if(!dbc->open()) { delete dbc; @@ -526,6 +632,9 @@ int main(int argc, char ** argv) ExtractGameobjectModels(); } + SFileCloseArchive(LocaleMpq); + SFileCloseArchive(WorldMpq); + printf("\n"); if(!success) { diff --git a/src/tools/vmap4_extractor/wdtfile.cpp b/src/tools/vmap4_extractor/wdtfile.cpp index e3ee545db19..2dd7396ae7d 100644 --- a/src/tools/vmap4_extractor/wdtfile.cpp +++ b/src/tools/vmap4_extractor/wdtfile.cpp @@ -30,7 +30,9 @@ char * wdtGetPlainName(char * FileName) return FileName; } -WDTFile::WDTFile(char* file_name, char* file_name1):WDT(file_name) +extern HANDLE WorldMpq; + +WDTFile::WDTFile(char* file_name, char* file_name1):WDT(WorldMpq, file_name) { filename.append(file_name1,strlen(file_name1)); } @@ -129,6 +131,6 @@ ADTFile* WDTFile::GetMap(int x, int z) char name[512]; - sprintf(name,"World\\Maps\\%s\\%s_%d_%d.adt", filename.c_str(), filename.c_str(), x, z); + sprintf(name,"World\\Maps\\%s\\%s_%d_%d_obj0.adt", filename.c_str(), filename.c_str(), x, z); return new ADTFile(name); } diff --git a/src/tools/vmap4_extractor/wdtfile.h b/src/tools/vmap4_extractor/wdtfile.h index f3d71c41791..ef3ec6db98c 100644 --- a/src/tools/vmap4_extractor/wdtfile.h +++ b/src/tools/vmap4_extractor/wdtfile.h @@ -1,7 +1,7 @@ #ifndef WDTFILE_H #define WDTFILE_H -#include "mpq_libmpq04.h" +#include "mpqfile.h" #include "wmo.h" #include <string> #include "stdlib.h" diff --git a/src/tools/vmap4_extractor/wmo.cpp b/src/tools/vmap4_extractor/wmo.cpp index 6703872111b..8bba5610c88 100644 --- a/src/tools/vmap4_extractor/wmo.cpp +++ b/src/tools/vmap4_extractor/wmo.cpp @@ -26,7 +26,7 @@ #include <fstream> #undef min #undef max -#include "mpq_libmpq04.h" +#include "mpqfile.h" using namespace std; extern uint16 *LiqType; @@ -35,9 +35,11 @@ WMORoot::WMORoot(std::string &filename) : filename(filename) { } +extern HANDLE WorldMpq; + bool WMORoot::open() { - MPQFile f(filename.c_str()); + MPQFile f(WorldMpq, filename.c_str()); if(f.isEof ()) { printf("No such file.\n"); @@ -143,7 +145,7 @@ WMOGroup::WMOGroup(std::string &filename) : filename(filename), bool WMOGroup::open() { - MPQFile f(filename.c_str()); + MPQFile f(WorldMpq, filename.c_str()); if(f.isEof ()) { printf("No such file.\n"); diff --git a/src/tools/vmap4_extractor/wmo.h b/src/tools/vmap4_extractor/wmo.h index 8c5993d91d5..7020bb90f12 100644 --- a/src/tools/vmap4_extractor/wmo.h +++ b/src/tools/vmap4_extractor/wmo.h @@ -24,6 +24,7 @@ #include <string> #include <set> #include "vec3d.h" +#include "mpqfile.h" // MOPY flags #define WMO_MATERIAL_NOCAMCOLLIDE 0x01 |