28#include <boost/filesystem/directory.hpp>
29#include <boost/filesystem/operations.hpp>
32#include <unordered_map>
50std::unordered_map<std::string, WMODoodadData>
WmoDoodads;
53static constexpr std::array<std::string_view, 12>
MpqLocaleNames = {
"enGB",
"enUS",
"deDE",
"esES",
"frFR",
"koKR",
"zhCN",
"zhTW",
"enCN",
"enTW",
"esMX",
"ruRU" };
68 if (FILE* n = fopen(file,
"rb"))
88 std::string originalName = fname;
100 char const* rchr = strrchr(plain_name,
'_');
104 memcpy(cpy, rchr, 4);
105 for (
int i = 0; i < 4; ++i)
117 printf(
"Extracting %s\n", originalName.c_str());
121 printf(
"Couldn't open RootWmo!!!\n");
124 FILE *output = fopen(szLocalFile.c_str(),
"wb");
127 printf(
"couldn't open %s for writing!\n", szLocalFile.c_str());
133 int Wmo_nVertices = 0;
141 strncpy(temp, fname.c_str(), 1024);
142 temp[fname.length()-4] = 0;
145 if (!fgroup.
open(&froot))
147 printf(
"Could not open all Group file for: %s\n", plain_name);
159 if (groupReference >= doodads.
Spawns.size())
162 uint32 doodadNameIndex = doodads.
Spawns[groupReference].NameIndex;
171 fseek(output, 8, SEEK_SET);
172 fwrite(&Wmo_nVertices,
sizeof(
int),1,output);
174 fwrite(&groupCount,
sizeof(
uint32), 1, output);
179 remove(szLocalFile.c_str());
191 printf(
"Processing Map %u\n[",
map_ids[i].
id);
192 for (
int x=0; x<64; ++x)
194 for (
int y=0; y<64; ++y)
211bool processArgv(
int argc,
char ** argv,
const char *versionString)
217 for(
int i = 1; i < argc; ++i)
219 if(strcmp(
"-s",argv[i]) == 0)
223 else if(strcmp(
"-d",argv[i]) == 0)
240 else if(strcmp(
"-?",argv[1]) == 0)
244 else if(strcmp(
"-l",argv[i]) == 0)
256 printf(
"Extract %s.\n",versionString);
257 printf(
"%s [-?][-s][-l][-d <path>]\n", argv[0]);
258 printf(
" -s : (default) small size (data size optimization), ~500MB less vmap data.\n");
259 printf(
" -l : large size, ~500MB more vmap data. (might contain more details)\n");
260 printf(
" -d <path>: Path to the vector data source folder.\n");
261 printf(
" -? : This message.\n");
275int main(
int argc,
char ** argv)
281 Trinity::Banner::Show(
"VMAP data extractor", [](
char const* text) { printf(
"%s\n", text); },
nullptr);
284 const char *versionString =
"V4.00 2012_02";
291 boost::filesystem::path sdir_bin = boost::filesystem::path(
szWorkDirWmo) /
"dir_bin";
293 boost::system::error_code ec;
294 if (boost::filesystem::exists(sdir_bin, ec))
296 printf(
"Your output directory seems to be polluted, please use an empty directory!\n");
297 printf(
"<press return to exit>");
299 return scanf(
"%c", garbage);
303 printf(
"Extract %s. Beginning work ....\n\n", versionString);
308 auto foundLocale = std::ranges::find_if(
MpqLocaleNames, [](std::string_view localeName)
315 printf(
"FATAL ERROR: None MPQ archive found by path '%s'. Use -d option with proper path.\n",
input_path);
327 printf(
"FATAL ERROR: Map.dbc not found in data file.\n");
332 for (
unsigned int x = 0; x <
map_count; ++x)
337 size_t max_map_name_length =
sizeof(
map_ids[x].name);
338 if (strlen(map_name) >= max_map_name_length)
341 printf(
"FATAL ERROR: Map name too long.\n");
345 strncpy(
map_ids[x].name, map_name, max_map_name_length);
346 map_ids[x].name[max_map_name_length - 1] =
'\0';
347 printf(
"Map - %s\n",
map_ids[x].name);
360 printf(
"ERROR: Extract %s. Work NOT complete.\n Precise vector data=%d.\nPress any key.\n", versionString,
preciseVectorData);
364 printf(
"Extract %s. Work complete. No errors.\n", versionString);
368#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
char const * GetPlainName(char const *FileName)
void FixNameCase(char *name, size_t len)
void FixNameSpaces(char *name, size_t len)
char const * getString(size_t field) const
unsigned int getUInt(size_t field) const
Record getRecord(size_t id)
size_t getRecordCount() const
Trivial.
ADTFile * GetMap(int x, int z)
std::vector< uint16 > DoodadReferences
bool open(WMORoot *rootWMO)
int ConvertToVMAPGroupWmo(FILE *output, bool preciseVectorData)
bool ShouldSkip(WMORoot const *root) const
std::unordered_set< uint32 > ValidDoodadNames
bool ConvertToVMAPRootWmo(FILE *output)
bool OpenArchives(std::string_view inputPath, std::string_view localeName)
TC_COMMON_API void Show(char const *applicationName, void(*log)(char const *text), void(*logExtraInfo)())
TC_COMMON_API void Init()
TC_COMMON_API void VerifyOsVersion()
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
std::unordered_set< uint16 > References
std::vector< WMO::MODD > Spawns
std::vector< map_id > map_ids
std::unordered_map< std::string, WMODoodadData > WmoDoodads
int main(int argc, char **argv)
uint32 GenerateUniqueObjectId(uint32 clientId, uint16 clientDoodadId)
std::map< std::pair< uint32, uint16 >, uint32 > uniqueObjectIds
bool FileExists(char const *file)
bool processArgv(int argc, char **argv, const char *versionString)
void strToLower(char *str)
static constexpr std::array< std::string_view, 12 > MpqLocaleNames
char const * szWorkDirWmo
bool ExtractSingleWmo(std::string &fname)