Skip to content

Commit

Permalink
Tools/Extractors: Improved game build reported by extractors
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren committed Jun 13, 2017
1 parent 1ec8228 commit ff1a71d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 93 deletions.
17 changes: 17 additions & 0 deletions src/tools/extractor_common/CascHandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ CASC::StorageHandle CASC::OpenStorage(boost::filesystem::path const& path, DWORD
return StorageHandle(handle);
}

DWORD CASC::GetBuildNumber(StorageHandle const& storage)
{
DWORD buildNumber = 0;
size_t infoDataSizeNeeded = 0;
if (!::CascGetStorageInfo(storage.get(), CascStorageGameBuild, &buildNumber, sizeof(buildNumber), &infoDataSizeNeeded))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
std::unique_ptr<char> buf(new char[infoDataSizeNeeded]);
::CascGetStorageInfo(storage.get(), CascStorageGameBuild, buf.get(), infoDataSizeNeeded, &infoDataSizeNeeded);
return *reinterpret_cast<DWORD*>(buf.get());
}
}

return buildNumber;
}

CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors /*= false*/)
{
HANDLE handle = nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/tools/extractor_common/CascHandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace CASC
char const* HumanReadableCASCError(DWORD error);

StorageHandle OpenStorage(boost::filesystem::path const& path, DWORD localeMask);
DWORD GetBuildNumber(StorageHandle const& storage);

FileHandle OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors = false);
DWORD GetFileSize(FileHandle const& file, PDWORD fileSizeHigh);
Expand Down
49 changes: 2 additions & 47 deletions src/tools/map_extractor/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,51 +325,6 @@ void HandleArgs(int argc, char* arg[])
}
}

uint32 ReadBuild(int locale)
{
// include build info file also
std::string filename = Trinity::StringFormat("component.wow-%s.txt", localeNames[locale]);
//printf("Read %s file... ", filename.c_str());

CASC::FileHandle dbcFile = CASC::OpenFile(CascStorage, filename.c_str(), CASC_LOCALE_ALL);
if (!dbcFile)
{
printf("Locale %s not installed.\n", localeNames[locale]);
return 0;
}

char buff[512];
DWORD readBytes = 0;
CASC::ReadFile(dbcFile, buff, 512, &readBytes);
if (!readBytes)
{
printf("Fatal error: Not found %s file!\n", filename.c_str());
exit(1);
}

std::string text = std::string(buff, readBytes);

size_t pos = text.find("version=\"");
size_t pos1 = pos + strlen("version=\"");
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());
exit(1);
}

std::string build_str = text.substr(pos1,pos2-pos1);

int build = atoi(build_str.c_str());
if (build <= 0)
{
printf("Fatal error: Invalid %s file format!\n", filename.c_str());
exit(1);
}

return build;
}

void ReadMapDBC()
{
printf("Read Map.db2 file...\n");
Expand Down Expand Up @@ -1384,7 +1339,7 @@ int main(int argc, char * arg[])
if ((CONF_extract & EXTRACT_DBC) == 0)
{
FirstLocale = i;
build = ReadBuild(i);
build = CASC::GetBuildNumber(CascStorage);
if (!build)
{
CascStorage.reset();
Expand All @@ -1396,7 +1351,7 @@ int main(int argc, char * arg[])
}

//Extract DBC files
uint32 tempBuild = ReadBuild(i);
uint32 tempBuild = CASC::GetBuildNumber(CascStorage);
if (!tempBuild)
{
CascStorage.reset();
Expand Down
47 changes: 1 addition & 46 deletions src/tools/vmap4_extractor/vmapexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,51 +141,6 @@ uint32 WowLocaleToCascLocaleFlags[12] =
CASC_LOCALE_ITIT,
};

uint32 ReadBuild(int locale)
{
// include build info file also
std::string filename = std::string("component.wow-") + localeNames[locale] + ".txt";
//printf("Read %s file... ", filename.c_str());

CASC::FileHandle dbcFile = CASC::OpenFile(CascStorage, filename.c_str(), CASC_LOCALE_ALL);
if (!dbcFile)
{
printf("Locale %s not installed.\n", localeNames[locale]);
return 0;
}

char buff[512];
DWORD readBytes = 0;
CASC::ReadFile(dbcFile, buff, 512, &readBytes);
if (!readBytes)
{
printf("Fatal error: Not found %s file!\n", filename.c_str());
exit(1);
}

std::string text = std::string(buff, readBytes);

size_t pos = text.find("version=\"");
size_t pos1 = pos + strlen("version=\"");
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());
exit(1);
}

std::string build_str = text.substr(pos1, pos2 - pos1);

int build = atoi(build_str.c_str());
if (build <= 0)
{
printf("Fatal error: Invalid %s file format!\n", filename.c_str());
exit(1);
}

return build;
}

bool OpenCascStorage(int locale)
{
try
Expand Down Expand Up @@ -437,7 +392,7 @@ int main(int argc, char ** argv)
continue;

FirstLocale = i;
uint32 build = ReadBuild(i);
uint32 build = CASC::GetBuildNumber(CascStorage);
if (!build)
{
CascStorage.reset();
Expand Down

0 comments on commit ff1a71d

Please sign in to comment.