mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Dep/CascLib: Update to ladislav-zezula/CascLib@03a3bcaed2
This commit is contained in:
@@ -33,7 +33,7 @@ set(SRC_FILES
|
||||
src/CascReadFile.cpp
|
||||
src/CascRootFile_Diablo3.cpp
|
||||
src/CascRootFile_Install.cpp
|
||||
src/CascRootFile_Mndx.cpp
|
||||
src/CascRootFile_MNDX.cpp
|
||||
src/CascRootFile_Text.cpp
|
||||
src/CascRootFile_TVFS.cpp
|
||||
src/CascRootFile_OW.cpp
|
||||
@@ -52,7 +52,7 @@ target_include_directories(casc
|
||||
PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/dep)
|
||||
|
||||
target_compile_definitions(casc PUBLIC -D__SYS_ZLIB)
|
||||
target_compile_definitions(casc PUBLIC -D__SYS_ZLIB -DCASCLIB_NO_AUTO_LINK_LIBRARY)
|
||||
|
||||
target_link_libraries(casc
|
||||
PRIVATE
|
||||
|
||||
@@ -342,6 +342,7 @@ struct TCascFile
|
||||
DWORD bVerifyIntegrity:1; // If true, then the data are validated more strictly when read
|
||||
DWORD bDownloadFileIf:1; // If true, then the data will be downloaded from the online storage if missing
|
||||
DWORD bLocalFileStream:1; // If true, then the file stream is a local file
|
||||
DWORD bOvercomeEncrypted:1; // If true, then CascReadFile will fill the part that is encrypted (and key was not found) with zeros
|
||||
|
||||
LPBYTE pbFileCache; // Pointer to file cache
|
||||
DWORD cbFileCache; // Size of the file cache
|
||||
|
||||
@@ -480,6 +480,9 @@ int CascDirectCopy(LPBYTE pbOutBuffer, PDWORD pcbOutBuffer, LPBYTE pbInBuffer, D
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Public functions
|
||||
|
||||
bool WINAPI CascAddEncryptionKey(HANDLE hStorage, ULONGLONG KeyName, LPBYTE Key)
|
||||
{
|
||||
PCASC_ENCRYPTION_KEY pEncKey;
|
||||
|
||||
@@ -26,6 +26,49 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use the apropriate library
|
||||
//
|
||||
// The library type is encoded in the library name as the following
|
||||
// CascLibXYZ.lib
|
||||
//
|
||||
// X - D for Debug version, R for Release version
|
||||
// Y - A for ANSI version, U for Unicode version
|
||||
// Z - S for static-linked CRT library, D for multithreaded DLL CRT library
|
||||
//
|
||||
#if defined(_MSC_VER) && !defined(__CASCLIB_SELF__) && !defined(CASCLIB_NO_AUTO_LINK_LIBRARY)
|
||||
|
||||
#ifdef _DEBUG // DEBUG VERSIONS
|
||||
#ifndef _UNICODE
|
||||
#ifdef _DLL
|
||||
#pragma comment(lib, "CascLibDAD.lib") // Debug Ansi CRT-DLL version
|
||||
#else
|
||||
#pragma comment(lib, "CascLibDAS.lib") // Debug Ansi CRT-LIB version
|
||||
#endif
|
||||
#else
|
||||
#ifdef _DLL
|
||||
#pragma comment(lib, "CascLibDUD.lib") // Debug Unicode CRT-DLL version
|
||||
#else
|
||||
#pragma comment(lib, "CascLibDUS.lib") // Debug Unicode CRT-LIB version
|
||||
#endif
|
||||
#endif
|
||||
#else // RELEASE VERSIONS
|
||||
#ifndef _UNICODE
|
||||
#ifdef _DLL
|
||||
#pragma comment(lib, "CascLibRAD.lib") // Release Ansi CRT-DLL version
|
||||
#else
|
||||
#pragma comment(lib, "CascLibRAS.lib") // Release Ansi CRT-LIB version
|
||||
#endif
|
||||
#else
|
||||
#ifdef _DLL
|
||||
#pragma comment(lib, "CascLibRUD.lib") // Release Unicode CRT-DLL version
|
||||
#else
|
||||
#pragma comment(lib, "CascLibRUS.lib") // Release Unicode CRT-LIB version
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
//-----------------------------------------------------------------------------
|
||||
// Defines
|
||||
|
||||
@@ -40,6 +83,7 @@ extern "C" {
|
||||
#define CASC_OPEN_TYPE_MASK 0x0000000F // The mask which gets open type from the dwFlags
|
||||
#define CASC_OPEN_FLAGS_MASK 0xFFFFFFF0 // The mask which gets open type from the dwFlags
|
||||
#define CASC_STRICT_DATA_CHECK 0x00000010 // Verify all data read from a file
|
||||
#define CASC_OVERCOME_ENCRYPTED 0x00000020 // When CascReadFile encounters a block encrypted with a key that is missing, the block is filled with zeros and returned as success
|
||||
|
||||
#define CASC_LOCALE_ALL 0xFFFFFFFF
|
||||
#define CASC_LOCALE_NONE 0x00000000
|
||||
|
||||
@@ -36,8 +36,9 @@ bool OpenFileByCKeyEntry(TCascStorage * hs, PCASC_CKEY_ENTRY pCKeyEntry, DWORD d
|
||||
// Create the file handle structure
|
||||
if((hf = new TCascFile(hs, pCKeyEntry)) != NULL)
|
||||
{
|
||||
hf->bVerifyIntegrity = (dwOpenFlags & CASC_STRICT_DATA_CHECK) ? true : false;
|
||||
hf->bDownloadFileIf = (hs->dwFeatures & CASC_FEATURE_ONLINE) ? true : false;
|
||||
hf->bVerifyIntegrity = (dwOpenFlags & CASC_STRICT_DATA_CHECK) ? true : false;
|
||||
hf->bDownloadFileIf = (hs->dwFeatures & CASC_FEATURE_ONLINE) ? true : false;
|
||||
hf->bOvercomeEncrypted = (dwOpenFlags & CASC_OVERCOME_ENCRYPTED) ? true : false;
|
||||
nError = ERROR_SUCCESS;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -791,6 +791,16 @@ bool WINAPI CascReadFile(HANDLE hFile, void * pvBuffer, DWORD dwBytesToRead, PDW
|
||||
pbEncodedFrame,
|
||||
pFrame->EncodedSize,
|
||||
(DWORD)(pFrame - hf->pFrames));
|
||||
|
||||
// Some people find it handy to extract data from partially encrypted file,
|
||||
// even at the cost producing files that are corrupt.
|
||||
// We overcome missing decryption key by zeroing the encrypted portions
|
||||
if(nError == ERROR_FILE_ENCRYPTED && hf->bOvercomeEncrypted)
|
||||
{
|
||||
memset(pbDecodedFrame, 0, pFrame->ContentSize);
|
||||
nError = ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
if (nError == ERROR_SUCCESS)
|
||||
{
|
||||
// Mark the frame as loaded
|
||||
|
||||
@@ -78,35 +78,6 @@ void SetLastError(DWORD dwErrCode)
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Overloaded "new" and "delete" operators
|
||||
|
||||
void * operator new(size_t size)
|
||||
{
|
||||
return CASC_ALLOC(BYTE, size);
|
||||
}
|
||||
|
||||
void * operator new[](size_t size)
|
||||
{
|
||||
return CASC_ALLOC(BYTE, size);
|
||||
}
|
||||
|
||||
void operator delete(void * ptr)
|
||||
{
|
||||
CASC_FREE(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void * ptr)
|
||||
{
|
||||
CASC_FREE(ptr);
|
||||
}
|
||||
|
||||
// For some reason, VS2015 needs this
|
||||
void operator delete(void * ptr, size_t)
|
||||
{
|
||||
CASC_FREE(ptr);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Linear data stream manipulation
|
||||
|
||||
|
||||
@@ -122,15 +122,6 @@ void CASC_FREE(T *& ptr)
|
||||
ptr = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Overloaded "new" and "delete" operators
|
||||
|
||||
void * operator new(size_t size);
|
||||
void * operator new[](size_t size);
|
||||
void operator delete(void * ptr);
|
||||
void operator delete[](void * ptr);
|
||||
void operator delete(void * ptr, size_t); // For some reason, VS2015 needs this
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Big endian number manipulation
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#define CSV_INVALID_INDEX ((size_t)(-1))
|
||||
#define CSV_ZERO ((size_t)(0)) // Use Csv[0][CSV_ZERO] instead of ambiguous Csv[0][0]
|
||||
#define CSV_MAX_COLUMNS 0x10
|
||||
#define CSV_MAX_COLUMNS 0x20
|
||||
#define CSV_HASH_TABLE_SIZE 0x80
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -62,7 +62,7 @@ recastnavigation (Recast is state of the art navigation mesh construction toolse
|
||||
|
||||
CascLib (An open-source implementation of library for reading CASC storage from Blizzard games since 2014)
|
||||
https://github.com/ladislav-zezula/CascLib
|
||||
Version: a1197edf0b3bd4d52c3f39be7fa7b44bb0b98012
|
||||
Version: 03a3bcaed285ab0d8ff0845a65ffe7d1fa653960
|
||||
|
||||
rapidjson (A fast JSON parser/generator for C++ with both SAX/DOM style API http://rapidjson.org/)
|
||||
https://github.com/miloyip/rapidjson
|
||||
|
||||
@@ -104,10 +104,14 @@ bool CASC::HasTactKey(StorageHandle const& storage, ULONGLONG keyLookup)
|
||||
return CascFindEncryptionKey(storage.get(), keyLookup) != nullptr;
|
||||
}
|
||||
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors /*= false*/)
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/)
|
||||
{
|
||||
DWORD openFlags = CASC_OPEN_BY_NAME;
|
||||
if (zerofillEncryptedParts)
|
||||
openFlags |= CASC_OVERCOME_ENCRYPTED;
|
||||
|
||||
HANDLE handle = nullptr;
|
||||
if (!::CascOpenFile(storage.get(), fileName, localeMask, CASC_OPEN_BY_NAME, &handle))
|
||||
if (!::CascOpenFile(storage.get(), fileName, localeMask, openFlags, &handle))
|
||||
{
|
||||
DWORD lastError = GetLastError(); // support checking error set by *Open* call, not the next *Close*
|
||||
if (printErrors)
|
||||
@@ -121,10 +125,14 @@ CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileNa
|
||||
return FileHandle(handle);
|
||||
}
|
||||
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors /*= false*/)
|
||||
CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/)
|
||||
{
|
||||
DWORD openFlags = CASC_OPEN_BY_FILEID;
|
||||
if (zerofillEncryptedParts)
|
||||
openFlags |= CASC_OVERCOME_ENCRYPTED;
|
||||
|
||||
HANDLE handle = nullptr;
|
||||
if (!::CascOpenFile(storage.get(), CASC_FILE_DATA_ID(fileDataId), localeMask, CASC_OPEN_BY_FILEID, &handle))
|
||||
if (!::CascOpenFile(storage.get(), CASC_FILE_DATA_ID(fileDataId), localeMask, openFlags, &handle))
|
||||
{
|
||||
DWORD lastError = GetLastError(); // support checking error set by *Open* call, not the next *Close*
|
||||
if (printErrors)
|
||||
|
||||
@@ -53,8 +53,8 @@ namespace CASC
|
||||
DWORD GetInstalledLocalesMask(StorageHandle const& storage);
|
||||
bool HasTactKey(StorageHandle const& storage, ULONGLONG keyLookup);
|
||||
|
||||
FileHandle OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors = false);
|
||||
FileHandle OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors = false);
|
||||
FileHandle OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors = false, bool zerofillEncryptedParts = false);
|
||||
FileHandle OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors = false, bool zerofillEncryptedParts = false);
|
||||
DWORD GetFileSize(FileHandle const& file, PDWORD fileSizeHigh);
|
||||
DWORD GetFilePointer(FileHandle const& file);
|
||||
bool SetFilePointer(FileHandle const& file, LONGLONG position);
|
||||
|
||||
@@ -19,15 +19,9 @@
|
||||
#include "StringFormat.h"
|
||||
#include <CascLib.h>
|
||||
|
||||
DB2CascFileSource::DB2CascFileSource(CASC::StorageHandle const& storage, std::string fileName, bool printErrors /*= true*/)
|
||||
{
|
||||
_fileHandle = CASC::OpenFile(storage, fileName.c_str(), CASC_LOCALE_NONE, printErrors);
|
||||
_fileName = std::move(fileName);
|
||||
}
|
||||
|
||||
DB2CascFileSource::DB2CascFileSource(CASC::StorageHandle const& storage, uint32 fileDataId, bool printErrors /*= true*/)
|
||||
{
|
||||
_fileHandle = CASC::OpenFile(storage, fileDataId, CASC_LOCALE_NONE, printErrors);
|
||||
_fileHandle = CASC::OpenFile(storage, fileDataId, CASC_LOCALE_NONE, printErrors, true);
|
||||
_fileName = Trinity::StringFormat("FileDataId: %u", fileDataId);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
struct DB2CascFileSource : public DB2FileSource
|
||||
{
|
||||
DB2CascFileSource(CASC::StorageHandle const& storage, std::string fileName, bool printErrors = true);
|
||||
DB2CascFileSource(CASC::StorageHandle const& storage, uint32 fileDataId, bool printErrors = true);
|
||||
bool IsOpen() const override;
|
||||
bool Read(void* buffer, std::size_t numBytes) override;
|
||||
|
||||
@@ -1251,22 +1251,6 @@ bool ExtractDB2File(uint32 fileDataId, char const* cascFileName, int locale, boo
|
||||
readBytes = 0;
|
||||
if (!CASC::ReadFile(source.GetHandle(), buffer, std::min<DWORD>(fileSize, readBatchSize), &readBytes))
|
||||
{
|
||||
if (GetLastError() == ERROR_FILE_ENCRYPTED)
|
||||
{
|
||||
// shrink block size to read as much unencrypted data as possible
|
||||
if (readBatchSize != 1)
|
||||
{
|
||||
readBatchSize = std::max<DWORD>(1, readBatchSize / 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8 zero = 0;
|
||||
--fileSize;
|
||||
fwrite(&zero, 1, 1, output);
|
||||
source.SetPosition(source.GetPosition() + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("Can't read file '%s'\n", outputFileName.c_str());
|
||||
fclose(output);
|
||||
boost::filesystem::remove(outputPath);
|
||||
|
||||
Reference in New Issue
Block a user