Tools/Extractors: Implement remote casc mode (#27993)

This commit is contained in:
Luzifix
2022-06-09 17:58:35 +02:00
committed by GitHub
parent 69d960b63f
commit b11574871e
4 changed files with 126 additions and 5 deletions

View File

@@ -190,6 +190,29 @@ CASC::Storage* CASC::Storage::Open(boost::filesystem::path const& path, uint32 l
return storage;
}
CASC::Storage* CASC::Storage::OpenRemote(boost::filesystem::path const& path, uint32 localeMask, char const* product, char const* region)
{
HANDLE handle = nullptr;
std::string cacheArgument = std::string(path.string() + ":" + product + ":" + region);
printf("Open casc remote storage...\n");
if (!::CascOpenOnlineStorage(cacheArgument.c_str(), localeMask, &handle))
{
DWORD lastError = GetCascError(); // support checking error set by *Open* call, not the next *Close*
printf("Error opening remote casc storage: %s\n", HumanReadableCASCError(lastError));
CascCloseStorage(handle);
SetCascError(lastError);
return nullptr;
}
Storage* storage = new Storage(handle);
if (!storage->LoadOnlineTactKeys())
printf("Failed to load additional encryption keys from wow.tools, some files might not be extracted.\n");
return storage;
}
uint32 CASC::Storage::GetBuildNumber() const
{
CASC_STORAGE_PRODUCT product;

View File

@@ -41,6 +41,7 @@ namespace CASC
~Storage();
static Storage* Open(boost::filesystem::path const& path, uint32 localeMask, char const* product);
static Storage* OpenRemote(boost::filesystem::path const& path, uint32 localeMask, char const* product, char const* region);
uint32 GetBuildNumber() const;
uint32 GetInstalledLocalesMask() const;

View File

@@ -108,6 +108,8 @@ float CONF_flat_liquid_delta_limit = 0.001f; // If max - min less this value - l
uint32 CONF_Locale = 0;
char const* CONF_Product = "wow";
char const* CONF_Region = "eu";
bool CONF_UseRemoteCasc = false;
#define CASC_LOCALES_COUNT 17
@@ -161,6 +163,8 @@ void Usage(char const* prg)
"-f height stored as int (less map size but lost some accuracy) 1 by default\n"\
"-l dbc locale\n"\
"-p which installed product to open (wow/wowt/wow_beta)\n"\
"-c use remote casc\n"\
"-r set remote casc region - standard: eu\n"\
"Example: %s -f 0 -i \"c:\\games\\game\"\n", prg, prg);
exit(1);
}
@@ -175,6 +179,8 @@ void HandleArgs(int argc, char* arg[])
// f - use float to int conversion
// h - limit minimum height
// l - dbc locale
// c - use remote casc
// r - set casc remote region - standard: eu
if (arg[c][0] != '-')
Usage(arg[0]);
@@ -225,6 +231,18 @@ void HandleArgs(int argc, char* arg[])
else
Usage(arg[0]);
break;
case 'c':
if (c + 1 < argc) // all ok
CONF_UseRemoteCasc = atoi(arg[c++ + 1]) != 0;
else
Usage(arg[0]);
break;
case 'r':
if (c + 1 < argc && strlen(arg[c + 1])) // all ok
CONF_Region = arg[c++ + 1];
else
Usage(arg[0]);
break;
case 'h':
Usage(arg[0]);
break;
@@ -1359,6 +1377,16 @@ bool OpenCascStorage(int locale)
{
try
{
if (CONF_UseRemoteCasc)
{
boost::filesystem::path const cache_dir(boost::filesystem::canonical(input_path) / "CascCache");
CascStorage.reset(CASC::Storage::OpenRemote(cache_dir, WowLocaleToCascLocaleFlags[locale], CONF_Product, CONF_Region));
if (CascStorage)
return true;
printf("Unable to open remote casc fallback to local casc\n");
}
boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
CascStorage.reset(CASC::Storage::Open(storage_dir, WowLocaleToCascLocaleFlags[locale], CONF_Product));
if (!CascStorage)
@@ -1380,6 +1408,16 @@ uint32 GetInstalledLocalesMask()
{
try
{
if (CONF_UseRemoteCasc)
{
boost::filesystem::path const cache_dir(boost::filesystem::canonical(input_path) / "CascCache");
std::unique_ptr<CASC::Storage> storage(CASC::Storage::OpenRemote(cache_dir, CASC_LOCALE_ALL_WOW, CONF_Product, CONF_Region));
if (storage)
return CASC_LOCALE_ALL_WOW;
printf("Unable to open remote casc fallback to local casc\n");
}
boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
std::unique_ptr<CASC::Storage> storage(CASC::Storage::Open(storage_dir, CASC_LOCALE_ALL_WOW, CONF_Product));
if (!storage)
@@ -1397,6 +1435,9 @@ uint32 GetInstalledLocalesMask()
static bool RetardCheck()
{
if (CONF_UseRemoteCasc)
return true;
try
{
boost::filesystem::path storageDir(boost::filesystem::canonical(input_path) / "Data");

View File

@@ -62,6 +62,9 @@ std::unordered_set<uint32> maps_that_are_parents;
boost::filesystem::path input_path;
bool preciseVectorData = false;
char const* CascProduct = "wow";
char const* CascRegion = "eu";
bool UseRemoteCasc = false;
uint32 DbcLocale = 0;
std::unordered_map<std::string, WMODoodadData> WmoDoodads;
// Constants
@@ -102,6 +105,16 @@ bool OpenCascStorage(int locale)
{
try
{
if (UseRemoteCasc)
{
boost::filesystem::path const casc_cache_dir(boost::filesystem::canonical(input_path) / "CascCache");
CascStorage.reset(CASC::Storage::OpenRemote(casc_cache_dir, WowLocaleToCascLocaleFlags[locale], CascProduct, CascRegion));
if (CascStorage)
return true;
printf("Unable to open remote casc fallback to local casc\n");
}
boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
CascStorage.reset(CASC::Storage::Open(storage_dir, WowLocaleToCascLocaleFlags[locale], CascProduct));
if (!CascStorage)
@@ -123,6 +136,17 @@ uint32 GetInstalledLocalesMask()
{
try
{
if (UseRemoteCasc)
{
boost::filesystem::path const casc_cache_dir(boost::filesystem::canonical(input_path) / "CascCache");
std::unique_ptr<CASC::Storage> storage(CASC::Storage::OpenRemote(casc_cache_dir, 0, CascProduct, CascRegion));
if (storage)
return CASC_LOCALE_ALL_WOW;
printf("Unable to open remote casc fallback to local casc\n");
}
boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
std::unique_ptr<CASC::Storage> storage(CASC::Storage::Open(storage_dir, 0, CascProduct));
if (!storage)
@@ -340,6 +364,29 @@ bool processArgv(int argc, char ** argv, const char *versionString)
else
result = false;
}
else if (strcmp("-c", argv[i]) == 0)
{
UseRemoteCasc = true;
}
else if (strcmp("-r", argv[i]) == 0)
{
if (i + 1 < argc && strlen(argv[i + 1]))
CascRegion = argv[++i];
else
result = false;
}
else if (strcmp("-dl", argv[i]) == 0)
{
if (i + 1 < argc && strlen(argv[i + 1]))
{
for (uint32 l = 0; l < TOTAL_LOCALES; ++l)
if (!strcmp(argv[i + 1], localeNames[l]))
DbcLocale = 1 << l;
i++;
}
else
result = false;
}
else
{
result = false;
@@ -351,10 +398,13 @@ bool processArgv(int argc, char ** argv, const char *versionString)
{
printf("Extract %s.\n",versionString);
printf("%s [-?][-s][-l][-d <path>][-p <product>]\n", argv[0]);
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(" -p <product>: which installed product to open (wow/wowt/wow_beta)\n");
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(" -p <product>: which installed product to open (wow/wowt/wow_beta)\n");
printf(" -c use remote casc\n");
printf(" -r set remote casc region - standard: eu\n");
printf(" -dl dbc locale\n");
printf(" -? : This message.\n");
}
@@ -365,6 +415,9 @@ static bool RetardCheck()
{
try
{
if (UseRemoteCasc)
return true;
boost::filesystem::path storageDir(boost::filesystem::canonical(input_path) / "Data");
boost::filesystem::directory_iterator end;
for (boost::filesystem::directory_iterator itr(storageDir); itr != end; ++itr)
@@ -432,6 +485,9 @@ int main(int argc, char ** argv)
int32 FirstLocale = -1;
for (int i = 0; i < TOTAL_LOCALES; ++i)
{
if (DbcLocale && !(DbcLocale & (1 << i)))
continue;
if (i == LOCALE_none)
continue;
@@ -449,7 +505,7 @@ int main(int argc, char ** argv)
continue;
}
printf("Detected client build: %u\n\n", build);
printf("Detected client build %u for locale %s\n\n", build, localeNames[i]);
break;
}