Tools:VMapExtractor: converted filenames and paths to strings

This commit is contained in:
Ovahlord committed 2023-07-08 21:11:02 +02:00
1 parent 3cfee9d3d0
commit e7e4c79ef1
2 files changed
+63 -112

No files matched your search

+4 -16
View File
@@ -174,18 +174,6 @@ uint8 const MpqToWowLocale[LOCALES_COUNT] =
LOCALE_itIT
};
static char const* const LocalesT[LOCALES_COUNT] =
{
"enGB", "enUS",
"deDE", "esES",
"frFR", "koKR",
"zhCN", "zhTW",
"enCN", "enTW",
"esMX", "ruRU",
"ptBR", "ptPT",
"itIT"
};
void CreateDir(boost::filesystem::path const& path)
{
namespace fs = boost::filesystem;
@@ -1262,19 +1250,19 @@ void ExtractCameraFiles()
bool LoadLocaleMPQFile(int locale)
{
std::string fileName = Trinity::StringFormat("%s/Data/%s/locale-%s.MPQ", input_path.string(), LocalesT[locale], LocalesT[locale]);
std::string fileName = Trinity::StringFormat("%s/Data/%s/locale-%s.MPQ", input_path.string(), Locales[locale], Locales[locale]);
if (!SFileOpenArchive(fileName.c_str(), 0, MPQ_OPEN_READ_ONLY, &LocaleMpq))
{
if (GetLastError() != ERROR_PATH_NOT_FOUND)
{
printf("\nLoading %s locale MPQs\n", LocalesT[locale]);
printf("\nLoading %s locale MPQs\n", Locales[locale]);
printf("Cannot open archive %s\n", fileName.c_str());
}
return false;
}
printf("\nLoading %s locale MPQs\n", LocalesT[locale]);
printf("\nLoading %s locale MPQs\n", Locales[locale]);
char const* prefix = nullptr;
for (int i = 0; Builds[i] && Builds[i] <= CLIENT_BUILD; ++i)
{
@@ -1288,7 +1276,7 @@ bool LoadLocaleMPQFile(int locale)
if (Builds[i] > LAST_DBC_IN_DATA_BUILD)
{
prefix = "";
fileName = Trinity::StringFormat("%s/Data/%s/wow-update-%s-%u.MPQ", input_path.string(), LocalesT[locale], LocalesT[locale], Builds[i]);
fileName = Trinity::StringFormat("%s/Data/%s/wow-update-%s-%u.MPQ", input_path.string(), Locales[locale], Locales[locale], Builds[i]);
}
else
{
+59 -96
View File
@@ -20,10 +20,14 @@
#include "dbcfile.h"
#include "wmo.h"
#include "mpqfile.h"
#include "StringFormat.h"
#include "vmapexport.h"
#include "VMapDefinitions.h"
#include "Banner.h"
#include <algorithm>
#include <sys/stat.h>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#ifdef _WIN32
#include <direct.h>
@@ -54,8 +58,6 @@
HANDLE WorldMpq = nullptr;
HANDLE LocaleMpq = nullptr;
uint32 CONF_TargetBuild = 15595; // 4.3.4.15595
// List MPQ for extract maps from
char const* CONF_mpq_list[]=
{
@@ -70,6 +72,7 @@ char const* CONF_mpq_list[]=
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
#define NEW_BASE_SET_BUILD 15211
#define CLIENT_BUILD 15595
#define LOCALES_COUNT 15
@@ -85,18 +88,6 @@ char const* Locales[LOCALES_COUNT] =
"itIT"
};
TCHAR const* LocalesT[LOCALES_COUNT] =
{
_T("enGB"), _T("enUS"),
_T("deDE"), _T("esES"),
_T("frFR"), _T("koKR"),
_T("zhCN"), _T("zhTW"),
_T("enCN"), _T("enTW"),
_T("esMX"), _T("ruRU"),
_T("ptBR"), _T("ptPT"),
_T("itIT"),
};
struct map_info
{
char name[64];
@@ -121,8 +112,7 @@ struct LiquidTypeEntry
std::map<uint32, map_info> map_ids;
std::unordered_set<uint32> maps_that_are_parents;
char output_path[128]=".";
char input_path[1024]=".";
boost::filesystem::path input_path;
bool preciseVectorData = false;
std::unordered_map<std::string, WMODoodadData> WmoDoodads;
@@ -132,46 +122,48 @@ char const* szWorkDirWmo = "./Buildings";
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))
std::string fileName = Trinity::StringFormat("%s/Data/%s/locale-%s.MPQ", input_path.string(), Locales[locale], Locales[locale]);
if (!SFileOpenArchive(fileName.c_str(), 0, MPQ_OPEN_READ_ONLY, &LocaleMpq))
{
if (GetLastError() != ERROR_PATH_NOT_FOUND)
{
_tprintf(_T("Loading %s locale MPQs\n"), LocalesT[locale]);
_tprintf(_T("Cannot open archive %s\n"), buff);
printf("\nLoading %s locale MPQs\n", Locales[locale]);
printf("Cannot open archive %s\n", fileName.c_str());
}
return false;
}
_tprintf(_T("Loading %s locale MPQs\n"), LocalesT[locale]);
printf("\nLoading %s locale MPQs\n", Locales[locale]);
char const* prefix = nullptr;
for (int i = 0; Builds[i] && Builds[i] <= CONF_TargetBuild; ++i)
for (int i = 0; Builds[i] && Builds[i] <= CLIENT_BUILD; ++i)
{
// Do not attempt to read older MPQ patch archives past this build, they were merged with base
// and trying to read them together with new base will not end well
if (CONF_TargetBuild >= NEW_BASE_SET_BUILD && Builds[i] < NEW_BASE_SET_BUILD)
if (CLIENT_BUILD >= NEW_BASE_SET_BUILD && Builds[i] < NEW_BASE_SET_BUILD)
continue;
memset(buff, 0, sizeof(buff));
fileName.clear();
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]);
fileName = Trinity::StringFormat("%s/Data/%s/wow-update-%s-%u.MPQ", input_path.string(), Locales[locale], Locales[locale], Builds[i]);
}
else
{
prefix = Locales[locale];
_stprintf(buff, _T("%swow-update-%u.MPQ"), input_path, Builds[i]);
fileName = Trinity::StringFormat("%s/Data/wow-update-%u.MPQ", input_path.string(), Builds[i]);
}
if (!SFileOpenPatchArchive(LocaleMpq, buff, prefix, 0))
if (!SFileOpenPatchArchive(LocaleMpq, fileName.c_str(), prefix, 0))
{
if (GetLastError() != ERROR_FILE_NOT_FOUND)
_tprintf(_T("Cannot open patch archive %s\n"), buff);
printf("Cannot open patch archive %s\n", fileName.c_str());
continue;
}
else
printf("Loaded %s\n", fileName.c_str());
}
printf("\n");
@@ -180,64 +172,64 @@ bool LoadLocaleMPQFile(int locale)
void LoadCommonMPQFiles(uint32 build)
{
TCHAR filename[512];
_stprintf(filename, _T("%sworld.MPQ"), input_path);
_tprintf(_T("Loading common MPQ files\n"));
if (!SFileOpenArchive(filename, 0, MPQ_OPEN_READ_ONLY, &WorldMpq))
std::string filename = Trinity::StringFormat("%s/Data/world.MPQ", input_path.string());
printf("Loading common MPQ files\n");
if (!SFileOpenArchive(filename.c_str(), 0, MPQ_OPEN_READ_ONLY, &WorldMpq))
{
if (GetLastError() != ERROR_PATH_NOT_FOUND)
_tprintf(_T("Cannot open archive %s\n"), filename);
printf("Cannot open archive %s\n", filename.c_str());
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
if (build < NEW_BASE_SET_BUILD && !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))
filename = Trinity::StringFormat("%s/Data/%s", input_path.string(), CONF_mpq_list[i]);
if (!SFileOpenPatchArchive(WorldMpq, filename.c_str(), "", 0))
{
if (GetLastError() != ERROR_PATH_NOT_FOUND)
_tprintf(_T("Cannot open archive %s\n"), filename);
printf("Cannot open archive %s\n", filename.c_str());
else
_tprintf(_T("Not found %s\n"), filename);
printf("Not found %s\n", filename.c_str());
}
else
_tprintf(_T("Loaded %s\n"), filename);
printf("Loaded %s\n", filename.c_str());
}
char const* prefix = nullptr;
for (int i = 0; Builds[i] && Builds[i] <= CONF_TargetBuild; ++i)
for (int i = 0; Builds[i] && Builds[i] <= CLIENT_BUILD; ++i)
{
// Do not attempt to read older MPQ patch archives past this build, they were merged with base
// and trying to read them together with new base will not end well
if (CONF_TargetBuild >= NEW_BASE_SET_BUILD && Builds[i] < NEW_BASE_SET_BUILD)
if (CLIENT_BUILD >= NEW_BASE_SET_BUILD && Builds[i] < NEW_BASE_SET_BUILD)
continue;
memset(filename, 0, sizeof(filename));
filename.clear();
if (Builds[i] > LAST_DBC_IN_DATA_BUILD)
{
prefix = "";
_stprintf(filename, _T("%swow-update-base-%u.MPQ"), input_path, Builds[i]);
filename = Trinity::StringFormat("%s/Data/wow-update-base-%u.MPQ", input_path.string(), Builds[i]);
}
else
{
prefix = "base";
_stprintf(filename, _T("%swow-update-%u.MPQ"), input_path, Builds[i]);
filename = Trinity::StringFormat("%s/Data/wow-update-%u.MPQ", input_path.string(), Builds[i]);
}
if (!SFileOpenPatchArchive(WorldMpq, filename, prefix, 0))
if (!SFileOpenPatchArchive(WorldMpq, filename.c_str(), prefix, 0))
{
if (GetLastError() != ERROR_PATH_NOT_FOUND)
_tprintf(_T("Cannot open patch archive %s\n"), filename);
printf("Cannot open patch archive %s\n", filename.c_str());
else
_tprintf(_T("Not found %s\n"), filename);
printf("Not found %s\n", filename.c_str());
continue;
}
else
_tprintf(_T("Loaded %s\n"), filename);
printf("Loaded %s\n", filename.c_str());
}
printf("\n");
@@ -329,11 +321,7 @@ bool ExtractSingleWmo(std::string& fname)
strncpy(temp, fname.c_str(), 1024);
temp[fname.length()-4] = 0;
char groupFileName[1024];
sprintf(groupFileName, "%s_%03u.wmo", temp, i);
//printf("Trying to open groupfile %s\n",groupFileName);
std::string s = groupFileName;
std::string s = Trinity::StringFormat("%s_%03u.wmo", temp, i);
WMOGroup fgroup(s);
if (!fgroup.open(&froot))
{
@@ -381,10 +369,8 @@ void ParsMapFiles()
auto itr = wdts.find(mapId);
if (itr == wdts.end())
{
char fn[512];
char* name = map_ids[mapId].name;
sprintf(fn, "World\\Maps\\%s\\%s.wdt", name, name);
itr = wdts.emplace(std::piecewise_construct, std::forward_as_tuple(mapId), std::forward_as_tuple(fn, name, maps_that_are_parents.count(mapId) > 0)).first;
std::string fileName = Trinity::StringFormat("World\\Maps\\%s\\%s.wdt", map_ids[mapId].name, map_ids[mapId].name);
itr = wdts.emplace(std::piecewise_construct, std::forward_as_tuple(mapId), std::forward_as_tuple(fileName.c_str(), map_ids[mapId].name, maps_that_are_parents.count(mapId) > 0)).first;
if (!itr->second.init(mapId))
{
wdts.erase(itr);
@@ -428,37 +414,22 @@ void ParsMapFiles()
}
}
void getGamePath()
{
#ifdef _WIN32
strcpy(input_path,"Data\\");
#else
strcpy(input_path,"Data/");
#endif
}
bool processArgv(int argc, char ** argv, const char *versionString)
{
bool result = true;
bool hasInputPathParam = false;
preciseVectorData = false;
for(int i = 1; i < argc; ++i)
for (int i = 1; i < argc; ++i)
{
if (strcmp("-s",argv[i]) == 0)
if (strcmp("-s", argv[i]) == 0)
{
preciseVectorData = false;
}
else if (strcmp("-d",argv[i]) == 0)
else if (strcmp("-d", argv[i]) == 0)
{
if ((i+1)<argc)
if ((i + 1) < argc)
{
hasInputPathParam = true;
strncpy(input_path, argv[i + 1], sizeof(input_path));
input_path[sizeof(input_path) - 1] = '\0';
if (input_path[strlen(input_path) - 1] != '\\' && input_path[strlen(input_path) - 1] != '/')
strcat(input_path, "/");
input_path = boost::filesystem::path(argv[i + 1]);
++i;
}
else
@@ -466,19 +437,14 @@ bool processArgv(int argc, char ** argv, const char *versionString)
result = false;
}
}
else if (strcmp("-?",argv[1]) == 0)
else if (strcmp("-?", argv[1]) == 0)
{
result = false;
}
else if (strcmp("-l",argv[i]) == 0)
else if (strcmp("-l", argv[i]) == 0)
{
preciseVectorData = true;
}
else if (strcmp("-b",argv[i]) == 0)
{
if (i + 1 < argc) // all ok
CONF_TargetBuild = atoi(argv[i++ + 1]);
}
else
{
result = false;
@@ -493,13 +459,9 @@ bool processArgv(int argc, char ** argv, const char *versionString)
printf(" -s : (default) small size (data size optimization), ~500MB less vmap data.\n");
printf(" -l : large size, ~500MB more vmap data. (might contain more details)\n");
printf(" -d <path>: Path to the vector data source folder.\n");
printf(" -b : target build (default %u)\n", CONF_TargetBuild);
printf(" -? : This message.\n");
}
if (!hasInputPathParam)
getGamePath();
return result;
}
@@ -517,11 +479,12 @@ int main(int argc, char ** argv)
{
Trinity::Banner::Show("VMAP data extractor", [](char const* text) { printf("%s\n", text); }, nullptr);
input_path = boost::filesystem::current_path();
bool success = true;
const char *versionString = "V4.05 2018_03";
// Use command line arguments, when some
if (!processArgv(argc, argv, versionString))
if (!processArgv(argc, argv, VMAP::VMAP_MAGIC))
return 1;
// some simple check if working dir is dirty
@@ -539,7 +502,7 @@ int main(int argc, char ** argv)
}
}
printf("Extract %s. Beginning work ....\n\n", versionString);
printf("Extract %s. Beginning work ....\n", VMAP::VMAP_MAGIC);
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Create the working directory
if (mkdir(szWorkDirWmo
@@ -549,7 +512,7 @@ int main(int argc, char ** argv)
))
success = (errno == EEXIST);
LoadCommonMPQFiles(CONF_TargetBuild);
LoadCommonMPQFiles(CLIENT_BUILD);
for (int i = 0; i < LOCALES_COUNT; ++i)
{
@@ -612,10 +575,10 @@ int main(int argc, char ** argv)
printf("\n");
if (!success)
{
printf("ERROR: Extract %s. Work NOT complete.\n Precise vector data=%d.\nPress any key.\n", versionString, preciseVectorData);
printf("ERROR: Extract %s. Work NOT complete.\n Precise vector data=%d.\nPress any key.\n", VMAP::VMAP_MAGIC, preciseVectorData);
getchar();
}
printf("Extract %s. Work complete. No errors.\n", versionString);
printf("Extract %s. Work complete. No errors.\n", VMAP::VMAP_MAGIC);
return 0;
}