aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2012-02-20 19:12:05 +0100
committerShauren <shauren.trinity@gmail.com>2012-02-20 19:12:05 +0100
commitb1e4a1b14f43aa72c750dfb0b3b652d70863c892 (patch)
treef42c64d18953a166420e0078d4a8a5ef9790b69a /src
parent39f96656ab1a559e7fe2f9116fdb2126352d4a2e (diff)
Core/Tools: Replaced libmpq with StormLib and made map extractor use it, you can now extract 4.2.2 dbcs with it (still not maps)
TODO: Update ADT structure
Diffstat (limited to 'src')
-rw-r--r--src/tools/map_extractor/CMakeLists.txt26
-rw-r--r--src/tools/map_extractor/System.cpp408
-rw-r--r--src/tools/map_extractor/adt.h4
-rw-r--r--src/tools/map_extractor/dbcfile.cpp76
-rw-r--r--src/tools/map_extractor/dbcfile.h210
-rw-r--r--src/tools/map_extractor/loadlib.cpp25
-rw-r--r--src/tools/map_extractor/loadlib/loadlib.h5
-rw-r--r--src/tools/map_extractor/mpq_libmpq.cpp111
-rw-r--r--src/tools/map_extractor/mpq_libmpq04.h91
-rw-r--r--src/tools/map_extractor/wdt.cpp2
-rw-r--r--src/tools/map_extractor/wdt.h2
-rw-r--r--src/tools/vmap3_extractor/CMakeLists.txt18
-rw-r--r--src/tools/vmap3_extractor/dbcfile.cpp106
-rw-r--r--src/tools/vmap3_extractor/dbcfile.h242
-rw-r--r--src/tools/vmap3_extractor/loadlib/loadlib.h59
-rw-r--r--src/tools/vmap3_extractor/model.h1
-rw-r--r--src/tools/vmap3_extractor/mpq_libmpq04.h1
-rw-r--r--src/tools/vmap3_extractor/wmo.h1
18 files changed, 620 insertions, 768 deletions
diff --git a/src/tools/map_extractor/CMakeLists.txt b/src/tools/map_extractor/CMakeLists.txt
index afeb8af99ba..af66b73827e 100644
--- a/src/tools/map_extractor/CMakeLists.txt
+++ b/src/tools/map_extractor/CMakeLists.txt
@@ -11,22 +11,12 @@
file(GLOB_RECURSE sources *.cpp *.h)
-if( UNIX )
- include_directories (
- ${CMAKE_SOURCE_DIR}/src/server/shared
- ${CMAKE_SOURCE_DIR}/dep/libmpq
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/loadlib
- )
-elseif( WIN32 )
- include_directories (
- ${CMAKE_SOURCE_DIR}/src/server/shared
- ${CMAKE_SOURCE_DIR}/dep/libmpq
- ${CMAKE_SOURCE_DIR}/dep/libmpq/win
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/loadlib
- )
-endif()
+include_directories (
+ ${CMAKE_SOURCE_DIR}/src/server/shared
+ ${CMAKE_SOURCE_DIR}/dep/StormLib/src
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/loadlib
+)
add_executable(mapextractor
${sources}
@@ -35,10 +25,10 @@ add_executable(mapextractor
target_link_libraries(mapextractor
${BZIP2_LIBRARIES}
${ZLIB_LIBRARIES}
- mpq
+ storm
)
-add_dependencies(mapextractor mpq)
+add_dependencies(mapextractor storm)
if( UNIX )
install(TARGETS mapextractor DESTINATION bin)
diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp
index 335fd924be8..443e9a9ada6 100644
--- a/src/tools/map_extractor/System.cpp
+++ b/src/tools/map_extractor/System.cpp
@@ -2,7 +2,7 @@
#include <stdio.h>
#include <deque>
-#include <set>
+#include <list>
#include <cstdlib>
#ifdef _WIN32
@@ -11,8 +11,8 @@
#include <sys/stat.h>
#endif
+#include "StormLib.h"
#include "dbcfile.h"
-#include "mpq_libmpq04.h"
#include "adt.h"
#include "wdt.h"
@@ -29,11 +29,15 @@
#endif
#ifdef O_LARGEFILE
- #define OPEN_FLAGS (O_RDONLY | O_BINARY | O_LARGEFILE)
+ #define OPEN_FLAGS (O_RDONLY | O_BINARY | O_LARGEFILE)
#else
#define OPEN_FLAGS (O_RDONLY | O_BINARY)
#endif
-extern ArchiveSet gOpenArchives;
+
+typedef std::list<HANDLE> Archives;
+Archives WorldMpqs;
+HANDLE WorldMpq = NULL;
+HANDLE LocaleMpq = NULL;
typedef struct
{
@@ -59,6 +63,7 @@ enum Extract
// Select data for extract
int CONF_extract = EXTRACT_MAP | EXTRACT_DBC;
+
// This option allow limit minimum height to some value (Allow save some memory)
bool CONF_allow_height_limit = true;
float CONF_use_minHeight = -500.0f;
@@ -70,34 +75,46 @@ float CONF_float_to_int16_limit = 2048.0f; // Max accuracy = val/65536
float CONF_flat_height_delta_limit = 0.005f; // If max - min less this value - surface is flat
float CONF_flat_liquid_delta_limit = 0.001f; // If max - min less this value - liquid surface is flat
-// List MPQ for extract from
-char *CONF_mpq_list[]={
- "common.MPQ",
- "common-2.MPQ",
- "lichking.MPQ",
- "expansion.MPQ",
- "patch.MPQ",
- "patch-2.MPQ",
- "patch-3.MPQ",
- "patch-4.MPQ",
- "patch-5.MPQ",
+uint32 CONF_TargetBuild = 14545; // 4.2.2.14545
+
+// List MPQ for extract maps from
+char const* CONF_mpq_list[]=
+{
+ "world.MPQ",
+ "world2.MPQ",
+ "expansion1.MPQ",
+ "expansion2.MPQ",
+ "expansion3.MPQ",
};
-static char* const langs[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" };
-#define LANG_COUNT 12
+uint32 const Builds[] = {13164, 13205, 13287, 13329, 13596, 13623, 13914, 14007, 14333, 14480, 14545, 15005, 15050, 15211, 0};
+#define LAST_DBC_IN_DATA_BUILD 13623 // after this build mpqs with dbc are back to locale folder
-void CreateDir( const std::string& Path )
+char* const Locales[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU"};
+TCHAR* const LocalesT[] =
{
- #ifdef _WIN32
- _mkdir( Path.c_str());
- #else
- mkdir( Path.c_str(), 0777 );
- #endif
+ _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
+
+void CreateDir(std::string const& path)
+{
+#ifdef _WIN32
+ _mkdir(path.c_str());
+#else
+ mkdir(path.c_str(), 777);
+#endif
}
-bool FileExists( const char* FileName )
+bool FileExists(TCHAR const* fileName)
{
- int fp = _open(FileName, OPEN_FLAGS);
+ int fp = _open(fileName, OPEN_FLAGS);
if(fp != -1)
{
_close(fp);
@@ -116,52 +133,62 @@ void Usage(char* prg)
"-o set output path\n"\
"-e extract only MAP(1)/DBC(2) - standard: both(3)\n"\
"-f height stored as int (less map size but lost some accuracy) 1 by default\n"\
+ "-b target build (default 14545)"\
"Example: %s -f 0 -i \"c:\\games\\game\"", prg, prg);
exit(1);
}
void HandleArgs(int argc, char * arg[])
{
- for(int c = 1; c < argc; ++c)
+ for (int c = 1; c < argc; ++c)
{
// i - input path
// o - output path
// e - extract only MAP(1)/DBC(2) - standard both(3)
// f - use float to int conversion
// h - limit minimum height
- if(arg[c][0] != '-')
+ // b - target client build
+ if (arg[c][0] != '-')
Usage(arg[0]);
- switch(arg[c][1])
+ switch (arg[c][1])
{
case 'i':
- if(c + 1 < argc) // all ok
- strcpy(input_path, arg[(c++) + 1]);
+ if (c + 1 < argc) // all ok
+ strcpy(input_path, arg[c++ + 1]);
else
Usage(arg[0]);
break;
case 'o':
- if(c + 1 < argc) // all ok
- strcpy(output_path, arg[(c++) + 1]);
+ if (c + 1 < argc) // all ok
+ strcpy(output_path, arg[c++ + 1]);
else
Usage(arg[0]);
break;
case 'f':
- if(c + 1 < argc) // all ok
- CONF_allow_float_to_int=atoi(arg[(c++) + 1])!=0;
+ if (c + 1 < argc) // all ok
+ CONF_allow_float_to_int = atoi(arg[c++ + 1])!=0;
else
Usage(arg[0]);
break;
case 'e':
- if(c + 1 < argc) // all ok
+ if (c + 1 < argc) // all ok
{
- CONF_extract=atoi(arg[(c++) + 1]);
- if(!(CONF_extract > 0 && CONF_extract < 4))
+ CONF_extract = atoi(arg[c++ + 1]);
+ if (!(CONF_extract > 0 && CONF_extract < 4))
Usage(arg[0]);
}
else
Usage(arg[0]);
break;
+ case 'b':
+ if (c + 1 < argc) // all ok
+ CONF_TargetBuild = atoi(arg[c++ + 1]);
+ else
+ Usage(arg[0]);
+ break;
+ default:
+ break;
}
}
}
@@ -169,22 +196,31 @@ void HandleArgs(int argc, char * arg[])
uint32 ReadBuild(int locale)
{
// include build info file also
- std::string filename = std::string("component.wow-")+langs[locale]+".txt";
+ std::string filename = std::string("component.wow-") + Locales[locale] + ".txt";
//printf("Read %s file... ", filename.c_str());
- MPQFile m(filename.c_str());
- if(m.isEof())
+ HANDLE dbcFile;
+ if (!SFileOpenFileEx(LocaleMpq, filename.c_str(), SFILE_OPEN_PATCHED_FILE, &dbcFile))
+ {
+ printf("Fatal error: Not found %s file!\n", filename.c_str());
+ exit(1);
+ }
+
+ char buff[512];
+ DWORD readBytes = 0;
+ SFileReadFile(dbcFile, buff, 512, &readBytes, NULL);
+ if (!readBytes)
{
printf("Fatal error: Not found %s file!\n", filename.c_str());
exit(1);
}
- std::string text = m.getPointer();
- m.close();
+ std::string text = buff;
+ SFileCloseFile(dbcFile);
size_t pos = text.find("version=\"");
size_t pos1 = pos + strlen("version=\"");
- size_t pos2 = text.find("\"",pos1);
+ size_t pos2 = text.find("\"", pos1);
if (pos == text.npos || pos2 == text.npos || pos1 >= pos2)
{
printf("Fatal error: Invalid %s file format!\n", filename.c_str());
@@ -206,9 +242,16 @@ uint32 ReadBuild(int locale)
uint32 ReadMapDBC()
{
printf("Read Map.dbc file... ");
- DBCFile dbc("DBFilesClient\\Map.dbc");
- if(!dbc.open())
+ HANDLE dbcFile;
+ if (!SFileOpenFileEx(LocaleMpq, "DBFilesClient\\Map.dbc", SFILE_OPEN_PATCHED_FILE, &dbcFile))
+ {
+ printf("Fatal error: Cannot find Map.dbc in archive!\n");
+ exit(1);
+ }
+
+ DBCFile dbc(dbcFile);
+ if (!dbc.open())
{
printf("Fatal error: Invalid Map.dbc file format!\n");
exit(1);
@@ -221,6 +264,8 @@ uint32 ReadMapDBC()
map_ids[x].id = dbc.getRecord(x).getUInt(0);
strcpy(map_ids[x].name, dbc.getRecord(x).getString(1));
}
+
+ SFileCloseFile(dbcFile);
printf("Done! (%u maps loaded)\n", map_count);
return map_count;
}
@@ -228,8 +273,14 @@ uint32 ReadMapDBC()
void ReadAreaTableDBC()
{
printf("Read AreaTable.dbc file...");
- DBCFile dbc("DBFilesClient\\AreaTable.dbc");
+ HANDLE dbcFile;
+ if (!SFileOpenFileEx(LocaleMpq, "DBFilesClient\\AreaTable.dbc", SFILE_OPEN_PATCHED_FILE, &dbcFile))
+ {
+ printf("Fatal error: Cannot find AreaTable.dbc in archive!\n");
+ exit(1);
+ }
+ DBCFile dbc(dbcFile);
if(!dbc.open())
{
printf("Fatal error: Invalid AreaTable.dbc file format!\n");
@@ -246,13 +297,21 @@ void ReadAreaTableDBC()
maxAreaId = dbc.getMaxId();
+ SFileCloseFile(dbcFile);
printf("Done! (%u areas loaded)\n", area_count);
}
void ReadLiquidTypeTableDBC()
{
printf("Read LiquidType.dbc file...");
- DBCFile dbc("DBFilesClient\\LiquidType.dbc");
+ HANDLE dbcFile;
+ if (!SFileOpenFileEx(LocaleMpq, "DBFilesClient\\LiquidType.dbc", SFILE_OPEN_PATCHED_FILE, &dbcFile))
+ {
+ printf("Fatal error: Cannot find LiquidType.dbc in archive!\n");
+ exit(1);
+ }
+
+ DBCFile dbc(dbcFile);
if(!dbc.open())
{
printf("Fatal error: Invalid LiquidType.dbc file format!\n");
@@ -267,6 +326,7 @@ void ReadLiquidTypeTableDBC()
for(uint32 x = 0; x < LiqType_count; ++x)
LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);
+ SFileCloseFile(dbcFile);
printf("Done! (%u LiqTypes loaded)\n", LiqType_count);
}
@@ -367,7 +427,7 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
{
ADT_file adt;
- if (!adt.loadFile(filename))
+ if (!adt.loadFile(WorldMpq, filename))
return false;
adt_MCIN *cells = adt.a_grid->getMCIN();
@@ -887,135 +947,192 @@ void ExtractMapsFromMpq(uint32 build)
CreateDir(path);
printf("Convert map files\n");
- for(uint32 z = 0; z < map_count; ++z)
+ for (uint32 z = 0; z < map_count; ++z)
{
printf("Extract %s (%d/%d) \n", map_ids[z].name, z+1, map_count);
// Loadup map grid data
sprintf(mpq_map_name, "World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name);
WDT_file wdt;
- if (!wdt.loadFile(mpq_map_name, false))
- {
-// printf("Error loading %s map wdt data\n", map_ids[z].name);
+ if (!wdt.loadFile(WorldMpq, mpq_map_name, false))
continue;
- }
- for(uint32 y = 0; y < WDT_MAP_SIZE; ++y)
+ for (uint32 y = 0; y < WDT_MAP_SIZE; ++y)
{
- for(uint32 x = 0; x < WDT_MAP_SIZE; ++x)
+ for (uint32 x = 0; x < WDT_MAP_SIZE; ++x)
{
- if (!wdt.main->adt_list[y][x].exist)
+ if (!(wdt.main->adt_list[y][x].flag & 0x1))
continue;
+
sprintf(mpq_filename, "World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y);
sprintf(output_filename, "%s/maps/%03u%02u%02u.map", output_path, map_ids[z].id, y, x);
ConvertADT(mpq_filename, output_filename, y, x, build);
}
+
// draw progress bar
printf("Processing........................%d%%\r", (100 * (y+1)) / WDT_MAP_SIZE);
}
}
+
printf("\n");
delete [] areas;
delete [] map_ids;
}
-bool ExtractFile( char const* mpq_name, std::string const& filename )
+bool ExtractFile(HANDLE fileInArchive, char const* filename)
{
- FILE *output = fopen(filename.c_str(), "wb");
+ FILE* output = fopen(filename, "wb");
if(!output)
{
- printf("Can't create the output file '%s'\n", filename.c_str());
+ printf("Can't create the output file '%s'\n", filename);
return false;
}
- MPQFile m(mpq_name);
- if(!m.isEof())
- fwrite(m.getPointer(), 1, m.getSize(), output);
+
+ char buffer[0x10000];
+ DWORD readBytes = 1;
+
+ while (readBytes > 0)
+ {
+ SFileReadFile(fileInArchive, buffer, sizeof(buffer), &readBytes, NULL);
+ if (readBytes > 0)
+ fwrite(buffer, 1, readBytes, output);
+ }
fclose(output);
return true;
}
-void ExtractDBCFiles(int locale, bool basicLocale)
+void ExtractDBCFiles(int l, bool basicLocale)
{
printf("Extracting dbc files...\n");
- std::set<std::string> dbcfiles;
-
- // get DBC file list
- for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i)
+ SFILE_FIND_DATA foundFile;
+ memset(&foundFile, 0, sizeof(foundFile));
+ HANDLE listFile = SListFileFindFirstFile(LocaleMpq, NULL, "DBFilesClient\\*dbc", &foundFile);
+ HANDLE dbcFile = NULL;
+ uint32 count = 0;
+ if (listFile)
{
- vector<string> files;
- (*i)->GetFileListTo(files);
- for (vector<string>::iterator iter = files.begin(); iter != files.end(); ++iter)
- if (iter->rfind(".dbc") == iter->length() - strlen(".dbc"))
- dbcfiles.insert(*iter);
- }
-
- std::string path = output_path;
- path += "/dbc/";
- CreateDir(path);
- if(!basicLocale)
- {
- path += langs[locale];
- path += "/";
- CreateDir(path);
- }
+ std::string outputPath = "./dbc/";
+ CreateDir(outputPath);
+ if (!basicLocale)
+ {
+ outputPath += Locales[l];
+ outputPath += "/";
+ CreateDir(outputPath);
+ }
- // extract Build info file
- {
- string mpq_name = std::string("component.wow-") + langs[locale] + ".txt";
- string filename = path + mpq_name;
+ std::string filename;
- ExtractFile(mpq_name.c_str(), filename);
- }
+ do
+ {
+ if (!SFileOpenFileEx(LocaleMpq, foundFile.cFileName, SFILE_OPEN_PATCHED_FILE, &dbcFile))
+ continue;
- // extract DBCs
- int count = 0;
- for (set<string>::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter)
- {
- string filename = path;
- filename += (iter->c_str() + strlen("DBFilesClient\\"));
+ filename = foundFile.cFileName;
+ filename = outputPath + filename.substr(filename.rfind('\\'));
+ if (ExtractFile(dbcFile, filename.c_str()))
+ ++count;
- if(ExtractFile(iter->c_str(), filename))
- ++count;
+ SFileCloseFile(dbcFile);
+ } while (SListFileFindNextFile(listFile, &foundFile));
}
+
printf("Extracted %u DBC files\n\n", count);
}
-void LoadLocaleMPQFiles(int const locale)
+bool LoadLocaleMPQFile(int locale)
{
- char filename[512];
-
- sprintf(filename,"%s/Data/%s/locale-%s.MPQ", input_path, langs[locale], langs[locale]);
- new MPQArchive(filename);
+ TCHAR buff[512];
+ memset(buff, 0, sizeof(buff));
+ _stprintf(buff, _T("./Data/%s/locale-%s.MPQ"), 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;
+ }
- for(int i = 1; i < 5; ++i)
+ char const* prefix = NULL;
+ for (int i = 0; Builds[i] && Builds[i] <= CONF_TargetBuild; ++i)
{
- char ext[3] = "";
- if(i > 1)
- sprintf(ext, "-%i", i);
+ memset(buff, 0, sizeof(buff));
+ if (Builds[i] > LAST_DBC_IN_DATA_BUILD)
+ {
+ prefix = NULL;
+ _stprintf(buff, _T("./Data/%s/wow-update-%s-%u.MPQ"), LocalesT[locale], LocalesT[locale], Builds[i]);
+ }
+ else
+ {
+ prefix = Locales[locale];
+ _stprintf(buff, _T("./Data/wow-update-%u.MPQ"), Builds[i]);
+ }
- sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ", input_path, langs[locale], langs[locale], ext);
- if(FileExists(filename))
- new MPQArchive(filename);
+ if (!SFileOpenPatchArchive(LocaleMpq, buff, prefix, 0))
+ {
+ if (GetLastError() != ERROR_FILE_NOT_FOUND)
+ _tprintf(_T("Cannot open patch archive %s\n"), buff);
+ //SFileCloseArchive(mpq);
+ //err = true;
+ //break;
+ continue;
+ }
}
+
+ return true;
}
void LoadCommonMPQFiles()
{
- char filename[512];
+ TCHAR filename[512];
+ _stprintf(filename, _T("%s/Data/world.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 = 0; i < count; ++i)
+ for(int i = 1; i < count; ++i)
{
- sprintf(filename, "%s/Data/%s", input_path, CONF_mpq_list[i]);
- if(FileExists(filename))
- new MPQArchive(filename);
+ _stprintf(filename, _T("%s/Data/%s"), input_path, CONF_mpq_list[i]);
+ //if (FileExists(filename))
+ {
+ if (!SFileOpenPatchArchive(WorldMpq, filename, NULL, 0))
+ {
+ if (GetLastError() != ERROR_PATH_NOT_FOUND)
+ _tprintf(_T("Cannot open archive %s\n"), filename);
+ break;
+ }
+ }
+ }
+
+ 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 = NULL;
+ _stprintf(filename, _T("%s/Data/wow-update-base-%u.MPQ"), input_path, Builds[i]);
+ }
+ else
+ {
+ prefix = "base";
+ _stprintf(filename, _T("%s/Data/wow-update-%u.MPQ"), input_path, Builds[i]);
+ }
+
+ if (!SFileOpenPatchArchive(LocaleMpq, filename, prefix, 0))
+ {
+ if (GetLastError() != ERROR_PATH_NOT_FOUND)
+ _tprintf(_T("Cannot open patch archive %s\n"), filename);
+ //SFileCloseArchive(mpq);
+ //err = true;
+ //break;
+ continue;
+ }
}
-}
-inline void CloseMPQFiles()
-{
- for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end();++j) (*j)->close();
- gOpenArchives.clear();
}
int main(int argc, char * arg[])
@@ -1028,42 +1145,58 @@ int main(int argc, char * arg[])
int FirstLocale = -1;
uint32 build = 0;
- for (int i = 0; i < LANG_COUNT; i++)
+ for (int i = 0; i < LOCALES_COUNT; ++i)
{
- char tmp1[512];
- sprintf(tmp1, "%s/Data/%s/locale-%s.MPQ", input_path, langs[i], langs[i]);
- if (FileExists(tmp1))
+ TCHAR tmp1[512];
+ _stprintf(tmp1, _T("%s/Data/%s/locale-%s.MPQ"), input_path, Locales[i], Locales[i]);
+ //if (FileExists(tmp1))
{
- printf("Detected locale: %s\n", langs[i]);
//Open MPQs
- LoadLocaleMPQFiles(i);
+ if (!LoadLocaleMPQFile(i))
+ {
+ if (GetLastError() != ERROR_PATH_NOT_FOUND)
+ printf("Unable to load %s locale archives!\n", Locales[i]);
+ continue;
+ }
- if((CONF_extract & EXTRACT_DBC) == 0)
+ printf("Detected locale: %s\n", Locales[i]);
+ if ((CONF_extract & EXTRACT_DBC) == 0)
{
FirstLocale = i;
build = ReadBuild(FirstLocale);
+ if (build > CONF_TargetBuild)
+ {
+ printf("Base locale-%s.MPQ has build higher than target build (%u > %u), nothing extracted!\n", Locales[i], build, CONF_TargetBuild);
+ break;
+ }
printf("Detected client build: %u\n", build);
break;
}
//Extract DBC files
- if(FirstLocale < 0)
+ uint32 tempBuild = ReadBuild(i);
+ printf("Detected client build %u for locale %s\n", tempBuild, Locales[i]);
+ if (tempBuild > CONF_TargetBuild)
+ {
+ printf("Base locale-%s.MPQ has build higher than target build (%u > %u), nothing extracted!\n", Locales[i], tempBuild, CONF_TargetBuild);
+ continue;
+ }
+
+ ExtractDBCFiles(i, FirstLocale < 0);
+
+ if (FirstLocale < 0)
{
FirstLocale = i;
- build = ReadBuild(FirstLocale);
- printf("Detected client build: %u\n", build);
- ExtractDBCFiles(i, true);
+ build = tempBuild;
}
- else
- ExtractDBCFiles(i, false);
//Close MPQs
- CloseMPQFiles();
+ SFileCloseArchive(LocaleMpq);
}
}
- if(FirstLocale < 0)
+ if (FirstLocale < 0)
{
printf("No locales detected\n");
return 0;
@@ -1071,17 +1204,18 @@ int main(int argc, char * arg[])
if (CONF_extract & EXTRACT_MAP)
{
- printf("Using locale: %s\n", langs[FirstLocale]);
+ printf("Using locale: %s\n", Locales[FirstLocale]);
// Open MPQs
- LoadLocaleMPQFiles(FirstLocale);
+ LoadLocaleMPQFile(FirstLocale);
LoadCommonMPQFiles();
// Extract maps
ExtractMapsFromMpq(build);
// Close MPQs
- CloseMPQFiles();
+ SFileCloseArchive(WorldMpq);
+ SFileCloseArchive(LocaleMpq);
}
return 0;
diff --git a/src/tools/map_extractor/adt.h b/src/tools/map_extractor/adt.h
index 5daf5820c3f..e8f79788169 100644
--- a/src/tools/map_extractor/adt.h
+++ b/src/tools/map_extractor/adt.h
@@ -271,8 +271,8 @@ class adt_MHDR
uint32 data5;
public:
bool prepareLoadedData();
- adt_MCIN *getMCIN(){ return (adt_MCIN *)((uint8 *)&pad+offsMCIN);}
- adt_MH2O *getMH2O(){ return offsMH2O ? (adt_MH2O *)((uint8 *)&pad+offsMH2O) : 0;}
+ adt_MCIN *getMCIN(){ return offsMCIN ? (adt_MCIN *)((uint8 *)&pad+offsMCIN) : NULL;}
+ adt_MH2O *getMH2O(){ return offsMH2O ? (adt_MH2O *)((uint8 *)&pad+offsMH2O) : NULL;}
};
diff --git a/src/tools/map_extractor/dbcfile.cpp b/src/tools/map_extractor/dbcfile.cpp
index 927d3d62b7f..021dc6f6e33 100644
--- a/src/tools/map_extractor/dbcfile.cpp
+++ b/src/tools/map_extractor/dbcfile.cpp
@@ -1,83 +1,91 @@
#define _CRT_SECURE_NO_DEPRECATE
#include "dbcfile.h"
-#include "mpq_libmpq04.h"
-DBCFile::DBCFile(const std::string &filename):
- filename(filename),
- data(0)
+DBCFile::DBCFile(HANDLE file) :
+ _file(file), _data(NULL), _stringTable(NULL)
{
-
}
+
bool DBCFile::open()
{
- MPQFile f(filename.c_str());
char header[4];
- unsigned int na,nb,es,ss;
+ unsigned int na, nb, es, ss;
- if(f.read(header,4)!=4) // Number of records
+ DWORD readBytes = 0;
+ SFileReadFile(_file, header, 4, &readBytes, NULL);
+ if (readBytes != 4) // Number of records
return false;
- if(header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3]!='C')
+ if (header[0] != 'W' || header[1] != 'D' || header[2] != 'B' || header[3] != 'C')
return false;
- if(f.read(&na,4)!=4) // Number of records
+ SFileReadFile(_file, &na, 4, &readBytes, NULL);
+ if (readBytes != 4) // Number of records
return false;
- if(f.read(&nb,4)!=4) // Number of fields
+
+ SFileReadFile(_file, &nb, 4, &readBytes, NULL);
+ if (readBytes != 4) // Number of fields
return false;
- if(f.read(&es,4)!=4) // Size of a record
+
+ SFileReadFile(_file, &es, 4, &readBytes, NULL);
+ if (readBytes != 4) // Size of a record
return false;
- if(f.read(&ss,4)!=4) // String size
+
+ SFileReadFile(_file, &ss, 4, &readBytes, NULL);
+ if (readBytes != 4) // String size
return false;
- recordSize = es;
- recordCount = na;
- fieldCount = nb;
- stringSize = ss;
- if(fieldCount*4 != recordSize)
+ _recordSize = es;
+ _recordCount = na;
+ _fieldCount = nb;
+ _stringSize = ss;
+ if (_fieldCount * 4 != _recordSize)
return false;
- data = new unsigned char[recordSize*recordCount+stringSize];
- stringTable = data + recordSize*recordCount;
+ _data = new unsigned char[_recordSize * _recordCount + _stringSize];
+ _stringTable = _data + _recordSize*_recordCount;
- size_t data_size = recordSize*recordCount+stringSize;
- if(f.read(data,data_size)!=data_size)
+ size_t data_size = _recordSize * _recordCount + _stringSize;
+ SFileReadFile(_file, _data, data_size, &readBytes, NULL);
+ if (readBytes != data_size)
return false;
- f.close();
+
return true;
}
+
DBCFile::~DBCFile()
{
- delete [] data;
+ delete [] _data;
}
DBCFile::Record DBCFile::getRecord(size_t id)
{
- assert(data);
- return Record(*this, data + id*recordSize);
+ assert(_data);
+ return Record(*this, _data + id*_recordSize);
}
size_t DBCFile::getMaxId()
{
- assert(data);
+ assert(_data);
size_t maxId = 0;
for(size_t i = 0; i < getRecordCount(); ++i)
- {
- if(maxId < getRecord(i).getUInt(0))
+ if (maxId < getRecord(i).getUInt(0))
maxId = getRecord(i).getUInt(0);
- }
+
return maxId;
}
DBCFile::Iterator DBCFile::begin()
{
- assert(data);
- return Iterator(*this, data);
+ assert(_data);
+ return Iterator(*this, _data);
}
+
DBCFile::Iterator DBCFile::end()
{
- assert(data);
- return Iterator(*this, stringTable);
+ assert(_data);
+ return Iterator(*this, _stringTable);
}
diff --git a/src/tools/map_extractor/dbcfile.h b/src/tools/map_extractor/dbcfile.h
index aef61df7aaa..ce7d8e85ed3 100644
--- a/src/tools/map_extractor/dbcfile.h
+++ b/src/tools/map_extractor/dbcfile.h
@@ -2,118 +2,124 @@
#define DBCFILE_H
#include <cassert>
#include <string>
+#include "StormLib.h"
class DBCFile
{
-public:
- DBCFile(const std::string &filename);
- ~DBCFile();
+ public:
+ DBCFile(HANDLE file);
+ ~DBCFile();
- // Open database. It must be openened before it can be used.
- bool open();
+ // Open database. It must be openened before it can be used.
+ bool open();
- // Database exceptions
- class Exception
- {
- public:
- Exception(const std::string &message): message(message)
- { }
- virtual ~Exception()
- { }
- const std::string &getMessage() {return message;}
- private:
- std::string message;
- };
- class NotFound: public Exception
- {
- public:
- NotFound(): Exception("Key was not found")
- { }
- };
- // Iteration over database
- class Iterator;
- class Record
- {
- public:
- float getFloat(size_t field) const
- {
- assert(field < file.fieldCount);
- return *reinterpret_cast<float*>(offset+field*4);
- }
- unsigned int getUInt(size_t field) const
+ // Database exceptions
+ class Exception
{
- assert(field < file.fieldCount);
- return *reinterpret_cast<unsigned int*>(offset+field*4);
- }
- int getInt(size_t field) const
- {
- assert(field < file.fieldCount);
- return *reinterpret_cast<int*>(offset+field*4);
- }
- const char *getString(size_t field) const
+ public:
+ Exception(const std::string &message) : message(message) { }
+ virtual ~Exception() { }
+ const std::string &getMessage() { return message; }
+ private:
+ std::string message;
+ };
+
+ class NotFound: public Exception
{
- assert(field < file.fieldCount);
- size_t stringOffset = getUInt(field);
- assert(stringOffset < file.stringSize);
- return reinterpret_cast<char*>(file.stringTable + stringOffset);
- }
- private:
- Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
- unsigned char *offset;
- DBCFile &file;
-
- friend class DBCFile;
- friend class DBCFile::Iterator;
- };
- /** Iterator that iterates over records
- */
- class Iterator
- {
- public:
- Iterator(DBCFile &file, unsigned char *offset):
- record(file, offset) {}
- /// Advance (prefix only)
- Iterator & operator++() {
- record.offset += record.file.recordSize;
- return *this;
- }
- /// Return address of current instance
- Record const & operator*() const { return record; }
- const Record* operator->() const {
- return &record;
- }
- /// Comparison
- bool operator==(const Iterator &b) const
+ public:
+ NotFound(): Exception("Key was not found") { }
+ };
+
+ // Iteration over database
+ class Iterator;
+ class Record
{
- return record.offset == b.record.offset;
- }
- bool operator!=(const Iterator &b) const
+ public:
+ float getFloat(size_t field) const
+ {
+ assert(field < file._fieldCount);
+ return *reinterpret_cast<float*>(offset+field*4);
+ }
+
+ unsigned int getUInt(size_t field) const
+ {
+ assert(field < file._fieldCount);
+ return *reinterpret_cast<unsigned int*>(offset+field*4);
+ }
+
+ int getInt(size_t field) const
+ {
+ assert(field < file._fieldCount);
+ return *reinterpret_cast<int*>(offset+field*4);
+ }
+
+ const char *getString(size_t field) const
+ {
+ assert(field < file._fieldCount);
+ size_t stringOffset = getUInt(field);
+ assert(stringOffset < file._stringSize);
+ return reinterpret_cast<char*>(file._stringTable + stringOffset);
+ }
+
+ private:
+ Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
+ unsigned char *offset;
+ DBCFile &file;
+
+ friend class DBCFile;
+ friend class DBCFile::Iterator;
+ };
+ /** Iterator that iterates over records
+ */
+ class Iterator
{
- return record.offset != b.record.offset;
- }
+ public:
+ Iterator(DBCFile &file, unsigned char *offset) : record(file, offset) { }
+
+ /// Advance (prefix only)
+ Iterator & operator++()
+ {
+ record.offset += record.file._recordSize;
+ return *this;
+ }
+
+ /// Return address of current instance
+ Record const & operator*() const { return record; }
+ const Record* operator->() const { return &record; }
+
+ /// Comparison
+ bool operator==(const Iterator &b) const
+ {
+ return record.offset == b.record.offset;
+ }
+
+ bool operator!=(const Iterator &b) const
+ {
+ return record.offset != b.record.offset;
+ }
+ private:
+ Record record;
+ };
+
+ // Get record by id
+ Record getRecord(size_t id);
+ /// Get begin iterator over records
+ Iterator begin();
+ /// Get begin iterator over records
+ Iterator end();
+ /// Trivial
+ size_t getRecordCount() const { return _recordCount; }
+ size_t getFieldCount() const { return _fieldCount; }
+ size_t getMaxId();
+
private:
- Record record;
- };
-
- // Get record by id
- Record getRecord(size_t id);
- /// Get begin iterator over records
- Iterator begin();
- /// Get begin iterator over records
- Iterator end();
- /// Trivial
- size_t getRecordCount() const { return recordCount;}
- size_t getFieldCount() const { return fieldCount; }
- size_t getMaxId();
-private:
- std::string filename;
- size_t recordSize;
- size_t recordCount;
- size_t fieldCount;
- size_t stringSize;
- unsigned char *data;
- unsigned char *stringTable;
+ HANDLE _file;
+ size_t _recordSize;
+ size_t _recordCount;
+ size_t _fieldCount;
+ size_t _stringSize;
+ unsigned char *_data;
+ unsigned char* _stringTable;
};
#endif
-
diff --git a/src/tools/map_extractor/loadlib.cpp b/src/tools/map_extractor/loadlib.cpp
index 465eb04083f..0e2112b2f26 100644
--- a/src/tools/map_extractor/loadlib.cpp
+++ b/src/tools/map_extractor/loadlib.cpp
@@ -1,11 +1,8 @@
#define _CRT_SECURE_NO_DEPRECATE
#include "loadlib.h"
-#include "mpq_libmpq04.h"
#include <cstdio>
-class MPQFile;
-
FileLoader::FileLoader()
{
data = 0;
@@ -18,29 +15,31 @@ FileLoader::~FileLoader()
free();
}
-bool FileLoader::loadFile(char *filename, bool log)
+bool FileLoader::loadFile(HANDLE mpq, char* filename, bool log)
{
free();
- MPQFile mf(filename);
- if(mf.isEof())
+ HANDLE file;
+ if (!SFileOpenFileEx(mpq, filename, SFILE_OPEN_PATCHED_FILE, &file))
{
if (log)
printf("No such file %s\n", filename);
return false;
}
- data_size = mf.getSize();
-
- data = new uint8 [data_size];
+ data_size = SFileGetFileSize(file, NULL);
+ data = new uint8[data_size];
if (data)
{
- mf.read(data, data_size);
- mf.close();
+ SFileReadFile(file, data, data_size, NULL/*bytesRead*/, NULL);
if (prepareLoadedData())
+ {
+ SFileCloseFile(file);
return true;
+ }
}
- printf("Error loading %s", filename);
- mf.close();
+
+ printf("Error loading %s\n", filename);
+ SFileCloseFile(file);
free();
return false;
}
diff --git a/src/tools/map_extractor/loadlib/loadlib.h b/src/tools/map_extractor/loadlib/loadlib.h
index bf6c0706d46..7a158ddfcf1 100644
--- a/src/tools/map_extractor/loadlib/loadlib.h
+++ b/src/tools/map_extractor/loadlib/loadlib.h
@@ -1,6 +1,8 @@
#ifndef LOAD_LIB_H
#define LOAD_LIB_H
+#include "StormLib.h"
+
#ifdef _WIN32
typedef __int64 int64;
typedef __int32 int32;
@@ -42,6 +44,7 @@ struct file_MVER
uint32 ver;
};
+
class FileLoader{
uint8 *data;
uint32 data_size;
@@ -53,7 +56,7 @@ public:
file_MVER *version;
FileLoader();
~FileLoader();
- bool loadFile(char *filename, bool log = true);
+ bool loadFile(HANDLE mpq, char *filename, bool log = true);
virtual void free();
};
#endif
diff --git a/src/tools/map_extractor/mpq_libmpq.cpp b/src/tools/map_extractor/mpq_libmpq.cpp
deleted file mode 100644
index 81aa8cc2894..00000000000
--- a/src/tools/map_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_t 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("warning: file %s has size %d; cannot read.\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/map_extractor/mpq_libmpq04.h b/src/tools/map_extractor/mpq_libmpq04.h
deleted file mode 100644
index 1f3b259bbfc..00000000000
--- a/src/tools/map_extractor/mpq_libmpq04.h
+++ /dev/null
@@ -1,91 +0,0 @@
-#define _CRT_SECURE_NO_DEPRECATE
-#define _CRT_SECURE_NO_WARNINGS
-
-#ifndef MPQ_H
-#define MPQ_H
-
-#include "loadlib/loadlib.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_t 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/map_extractor/wdt.cpp b/src/tools/map_extractor/wdt.cpp
index dedefbb64e5..6c2fa337d4f 100644
--- a/src/tools/map_extractor/wdt.cpp
+++ b/src/tools/map_extractor/wdt.cpp
@@ -57,6 +57,6 @@ bool WDT_file::prepareLoadedData()
return false;
wmo = (wdt_MWMO *)((uint8*)main+ main->size+8);
if (!wmo->prepareLoadedData())
- return false;
+ wmo = NULL; // optional as of cataclysm
return true;
} \ No newline at end of file
diff --git a/src/tools/map_extractor/wdt.h b/src/tools/map_extractor/wdt.h
index fcee8ac64f2..be6df3f173d 100644
--- a/src/tools/map_extractor/wdt.h
+++ b/src/tools/map_extractor/wdt.h
@@ -45,7 +45,7 @@ public:
uint32 size;
struct adtData{
- uint32 exist;
+ uint32 flag;
uint32 data1;
} adt_list[64][64];
diff --git a/src/tools/vmap3_extractor/CMakeLists.txt b/src/tools/vmap3_extractor/CMakeLists.txt
index 2ff2fd0cf6b..2763487cea4 100644
--- a/src/tools/vmap3_extractor/CMakeLists.txt
+++ b/src/tools/vmap3_extractor/CMakeLists.txt
@@ -15,31 +15,23 @@ file(GLOB_RECURSE sources *.cpp *.h)
add_definitions("-DIOMAP_DEBUG")
# build setup currently only supports libmpq 0.4.x
-add_definitions("-DUSE_LIBMPQ04")
add_definitions("-Wall")
add_definitions("-ggdb")
add_definitions("-O3")
-if( UNIX )
- include_directories(
- ${CMAKE_SOURCE_DIR}/dep/libmpq
- )
-elseif( WIN32 )
- include_directories(
- ${CMAKE_SOURCE_DIR}/dep/libmpq
- ${CMAKE_SOURCE_DIR}/dep/libmpq/win
- )
-endif()
+include_directories(
+ ${CMAKE_SOURCE_DIR}/dep/StormLib/src
+)
add_executable(vmap3extractor ${sources})
target_link_libraries(vmap3extractor
${BZIP2_LIBRARIES}
${ZLIB_LIBRARIES}
- mpq
+ storm
)
-add_dependencies(vmap3extractor mpq)
+add_dependencies(vmap3extractor storm)
if( UNIX )
install(TARGETS vmap3extractor DESTINATION bin)
diff --git a/src/tools/vmap3_extractor/dbcfile.cpp b/src/tools/vmap3_extractor/dbcfile.cpp
index 8b8afe9f23c..021dc6f6e33 100644
--- a/src/tools/vmap3_extractor/dbcfile.cpp
+++ b/src/tools/vmap3_extractor/dbcfile.cpp
@@ -1,77 +1,91 @@
-#include "dbcfile.h"
-#include "mpq_libmpq04.h"
-#undef min
-#undef max
+#define _CRT_SECURE_NO_DEPRECATE
-#include <cstdio>
+#include "dbcfile.h"
-DBCFile::DBCFile(const std::string &filename) : filename(filename)
+DBCFile::DBCFile(HANDLE file) :
+ _file(file), _data(NULL), _stringTable(NULL)
{
- data = NULL;
}
bool DBCFile::open()
{
- MPQFile f(filename.c_str());
+ char header[4];
+ unsigned int na, nb, es, ss;
+
+ DWORD readBytes = 0;
+ SFileReadFile(_file, header, 4, &readBytes, NULL);
+ if (readBytes != 4) // Number of records
+ return false;
+
+ if (header[0] != 'W' || header[1] != 'D' || header[2] != 'B' || header[3] != 'C')
+ return false;
+
+ SFileReadFile(_file, &na, 4, &readBytes, NULL);
+ if (readBytes != 4) // Number of records
+ return false;
+
+ SFileReadFile(_file, &nb, 4, &readBytes, NULL);
+ if (readBytes != 4) // Number of fields
+ return false;
- // Need some error checking, otherwise an unhandled exception error occurs
- // if people screw with the data path.
- if (f.isEof() == true)
+ SFileReadFile(_file, &es, 4, &readBytes, NULL);
+ if (readBytes != 4) // Size of a record
return false;
- unsigned char header[4];
- unsigned int na,nb,es,ss;
+ SFileReadFile(_file, &ss, 4, &readBytes, NULL);
+ if (readBytes != 4) // String size
+ return false;
+
+ _recordSize = es;
+ _recordCount = na;
+ _fieldCount = nb;
+ _stringSize = ss;
+ if (_fieldCount * 4 != _recordSize)
+ return false;
- f.read(header,4); // File Header
+ _data = new unsigned char[_recordSize * _recordCount + _stringSize];
+ _stringTable = _data + _recordSize*_recordCount;
- if (header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3] != 'C')
- {
- f.close();
- data = NULL;
- printf("Critical Error: An error occured while trying to read the DBCFile %s.", filename.c_str());
+ size_t data_size = _recordSize * _recordCount + _stringSize;
+ SFileReadFile(_file, _data, data_size, &readBytes, NULL);
+ if (readBytes != data_size)
return false;
- }
-
- //assert(header[0]=='W' && header[1]=='D' && header[2]=='B' && header[3] == 'C');
-
- f.read(&na,4); // Number of records
- f.read(&nb,4); // Number of fields
- f.read(&es,4); // Size of a record
- f.read(&ss,4); // String size
-
- recordSize = es;
- recordCount = na;
- fieldCount = nb;
- stringSize = ss;
- //assert(fieldCount*4 == recordSize);
- assert(fieldCount*4 >= recordSize);
-
- data = new unsigned char[recordSize*recordCount+stringSize];
- stringTable = data + recordSize*recordCount;
- f.read(data,recordSize*recordCount+stringSize);
- f.close();
+
return true;
}
DBCFile::~DBCFile()
{
- delete [] data;
+ delete [] _data;
}
DBCFile::Record DBCFile::getRecord(size_t id)
{
- assert(data);
- return Record(*this, data + id*recordSize);
+ assert(_data);
+ return Record(*this, _data + id*_recordSize);
+}
+
+size_t DBCFile::getMaxId()
+{
+ assert(_data);
+
+ size_t maxId = 0;
+ for(size_t i = 0; i < getRecordCount(); ++i)
+ if (maxId < getRecord(i).getUInt(0))
+ maxId = getRecord(i).getUInt(0);
+
+ return maxId;
}
DBCFile::Iterator DBCFile::begin()
{
- assert(data);
- return Iterator(*this, data);
+ assert(_data);
+ return Iterator(*this, _data);
}
DBCFile::Iterator DBCFile::end()
{
- assert(data);
- return Iterator(*this, stringTable);
+ assert(_data);
+ return Iterator(*this, _stringTable);
}
+
diff --git a/src/tools/vmap3_extractor/dbcfile.h b/src/tools/vmap3_extractor/dbcfile.h
index d405d6ffd60..ce7d8e85ed3 100644
--- a/src/tools/vmap3_extractor/dbcfile.h
+++ b/src/tools/vmap3_extractor/dbcfile.h
@@ -1,155 +1,125 @@
-/*
- * Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2010 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, see <http://www.gnu.org/licenses/>.
- */
-
#ifndef DBCFILE_H
#define DBCFILE_H
-
#include <cassert>
#include <string>
+#include "StormLib.h"
class DBCFile
{
-public:
- DBCFile(const std::string &filename);
- ~DBCFile();
-
- // Open database. It must be openened before it can be used.
- bool open();
-
- // TODO: Add a close function?
-
- // Database exceptions
- class Exception
- {
public:
- Exception(const std::string &message): message(message)
- { }
- virtual ~Exception()
- { }
- const std::string &getMessage() {return message;}
- private:
- std::string message;
- };
+ DBCFile(HANDLE file);
+ ~DBCFile();
- //
- class NotFound: public Exception
- {
- public:
- NotFound(): Exception("Key was not found")
- { }
- };
-
- // Iteration over database
- class Iterator;
- class Record
- {
- public:
- Record& operator= (const Record& r)
- {
- file = r.file;
- offset = r.offset;
- return *this;
- }
- float getFloat(size_t field) const
- {
- assert(field < file.fieldCount);
- return *reinterpret_cast<float*>(offset+field*4);
- }
- unsigned int getUInt(size_t field) const
- {
- assert(field < file.fieldCount);
- return *reinterpret_cast<unsigned int*>(offset+(field*4));
- }
- int getInt(size_t field) const
+ // Open database. It must be openened before it can be used.
+ bool open();
+
+ // Database exceptions
+ class Exception
{
- assert(field < file.fieldCount);
- return *reinterpret_cast<int*>(offset+field*4);
- }
- unsigned char getByte(size_t ofs) const
+ public:
+ Exception(const std::string &message) : message(message) { }
+ virtual ~Exception() { }
+ const std::string &getMessage() { return message; }
+ private:
+ std::string message;
+ };
+
+ class NotFound: public Exception
{
- assert(ofs < file.recordSize);
- return *reinterpret_cast<unsigned char*>(offset+ofs);
- }
- const char *getString(size_t field) const
+ public:
+ NotFound(): Exception("Key was not found") { }
+ };
+
+ // Iteration over database
+ class Iterator;
+ class Record
{
- assert(field < file.fieldCount);
- size_t stringOffset = getUInt(field);
- assert(stringOffset < file.stringSize);
- //char * tmp = (char*)file.stringTable + stringOffset;
- //unsigned char * tmp2 = file.stringTable + stringOffset;
- return reinterpret_cast<char*>(file.stringTable + stringOffset);
- }
- private:
- Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
- DBCFile &file;
- unsigned char *offset;
+ public:
+ float getFloat(size_t field) const
+ {
+ assert(field < file._fieldCount);
+ return *reinterpret_cast<float*>(offset+field*4);
+ }
- friend class DBCFile;
- friend class Iterator;
- };
+ unsigned int getUInt(size_t field) const
+ {
+ assert(field < file._fieldCount);
+ return *reinterpret_cast<unsigned int*>(offset+field*4);
+ }
- /* Iterator that iterates over records */
- class Iterator
- {
- public:
- Iterator(DBCFile &file, unsigned char *offset):
- record(file, offset) {}
- /// Advance (prefix only)
- Iterator & operator++() {
- record.offset += record.file.recordSize;
- return *this;
- }
- /// Return address of current instance
- Record const & operator*() const { return record; }
- const Record* operator->() const {
- return &record;
- }
- /// Comparison
- bool operator==(const Iterator &b) const
- {
- return record.offset == b.record.offset;
- }
- bool operator!=(const Iterator &b) const
+ int getInt(size_t field) const
+ {
+ assert(field < file._fieldCount);
+ return *reinterpret_cast<int*>(offset+field*4);
+ }
+
+ const char *getString(size_t field) const
+ {
+ assert(field < file._fieldCount);
+ size_t stringOffset = getUInt(field);
+ assert(stringOffset < file._stringSize);
+ return reinterpret_cast<char*>(file._stringTable + stringOffset);
+ }
+
+ private:
+ Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
+ unsigned char *offset;
+ DBCFile &file;
+
+ friend class DBCFile;
+ friend class DBCFile::Iterator;
+ };
+ /** Iterator that iterates over records
+ */
+ class Iterator
{
- return record.offset != b.record.offset;
- }
+ public:
+ Iterator(DBCFile &file, unsigned char *offset) : record(file, offset) { }
+
+ /// Advance (prefix only)
+ Iterator & operator++()
+ {
+ record.offset += record.file._recordSize;
+ return *this;
+ }
+
+ /// Return address of current instance
+ Record const & operator*() const { return record; }
+ const Record* operator->() const { return &record; }
+
+ /// Comparison
+ bool operator==(const Iterator &b) const
+ {
+ return record.offset == b.record.offset;
+ }
+
+ bool operator!=(const Iterator &b) const
+ {
+ return record.offset != b.record.offset;
+ }
+ private:
+ Record record;
+ };
+
+ // Get record by id
+ Record getRecord(size_t id);
+ /// Get begin iterator over records
+ Iterator begin();
+ /// Get begin iterator over records
+ Iterator end();
+ /// Trivial
+ size_t getRecordCount() const { return _recordCount; }
+ size_t getFieldCount() const { return _fieldCount; }
+ size_t getMaxId();
+
private:
- Record record;
- };
-
- // Get record by id
- Record getRecord(size_t id);
- /// Get begin iterator over records
- Iterator begin();
- /// Get begin iterator over records
- Iterator end();
- /// Trivial
- size_t getRecordCount() const { return recordCount;}
- size_t getFieldCount() const { return fieldCount; }
-
-private:
- std::string filename;
- size_t recordSize;
- size_t recordCount;
- size_t fieldCount;
- size_t stringSize;
- unsigned char *data;
- unsigned char *stringTable;
+ HANDLE _file;
+ size_t _recordSize;
+ size_t _recordCount;
+ size_t _fieldCount;
+ size_t _stringSize;
+ unsigned char *_data;
+ unsigned char* _stringTable;
};
#endif
diff --git a/src/tools/vmap3_extractor/loadlib/loadlib.h b/src/tools/vmap3_extractor/loadlib/loadlib.h
deleted file mode 100644
index bf6c0706d46..00000000000
--- a/src/tools/vmap3_extractor/loadlib/loadlib.h
+++ /dev/null
@@ -1,59 +0,0 @@
-#ifndef LOAD_LIB_H
-#define LOAD_LIB_H
-
-#ifdef _WIN32
-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
-
-#define FILE_FORMAT_VERSION 18
-
-//
-// File version chunk
-//
-struct file_MVER
-{
- union{
- uint32 fcc;
- char fcc_txt[4];
- };
- uint32 size;
- uint32 ver;
-};
-
-class FileLoader{
- uint8 *data;
- uint32 data_size;
-public:
- virtual bool prepareLoadedData();
- uint8 *GetData() {return data;}
- uint32 GetDataSize() {return data_size;}
-
- file_MVER *version;
- FileLoader();
- ~FileLoader();
- bool loadFile(char *filename, bool log = true);
- virtual void free();
-};
-#endif
diff --git a/src/tools/vmap3_extractor/model.h b/src/tools/vmap3_extractor/model.h
index c131645bd73..f16396bdd40 100644
--- a/src/tools/vmap3_extractor/model.h
+++ b/src/tools/vmap3_extractor/model.h
@@ -1,7 +1,6 @@
#ifndef MODEL_H
#define MODEL_H
-#include "loadlib/loadlib.h"
#include "vec3d.h"
//#include "mpq.h"
#include "modelheaders.h"
diff --git a/src/tools/vmap3_extractor/mpq_libmpq04.h b/src/tools/vmap3_extractor/mpq_libmpq04.h
index f32f09badde..e0c42ba0bfd 100644
--- a/src/tools/vmap3_extractor/mpq_libmpq04.h
+++ b/src/tools/vmap3_extractor/mpq_libmpq04.h
@@ -1,7 +1,6 @@
#ifndef MPQ_H
#define MPQ_H
-#include "loadlib/loadlib.h"
#include "libmpq/mpq.h"
#include <string.h>
#include <ctype.h>
diff --git a/src/tools/vmap3_extractor/wmo.h b/src/tools/vmap3_extractor/wmo.h
index 12979bc13d9..1632b6c5893 100644
--- a/src/tools/vmap3_extractor/wmo.h
+++ b/src/tools/vmap3_extractor/wmo.h
@@ -6,7 +6,6 @@
#include <string>
#include <set>
#include "vec3d.h"
-#include "loadlib/loadlib.h"
// MOPY flags
#define WMO_MATERIAL_NOCAMCOLLIDE 0x01