aboutsummaryrefslogtreecommitdiff
path: root/dep/CascLib/src/CascLib.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2019-06-06 16:48:21 +0200
committerShauren <shauren.trinity@gmail.com>2019-06-08 17:09:24 +0200
commitfc330fd8ff0115804d9c4b53a1f810c00dd63de9 (patch)
treecfa10998fed66779834bf0b7a9b8b799d33d91d4 /dep/CascLib/src/CascLib.h
parent82c7b6c5688495d90c4ee5995a4ff74039348296 (diff)
Dep/CascLib: Update to ladislav-zezula/CascLib@a1197edf0b3bd4d52c3f39be7fa7b44bb0b98012
Diffstat (limited to 'dep/CascLib/src/CascLib.h')
-rw-r--r--dep/CascLib/src/CascLib.h240
1 files changed, 179 insertions, 61 deletions
diff --git a/dep/CascLib/src/CascLib.h b/dep/CascLib/src/CascLib.h
index 272d4b4ad4d..1fb1911eade 100644
--- a/dep/CascLib/src/CascLib.h
+++ b/dep/CascLib/src/CascLib.h
@@ -29,14 +29,17 @@ extern "C" {
//-----------------------------------------------------------------------------
// Defines
-#define CASCLIB_VERSION 0x0100 // Current version of CascLib (1.0)
-#define CASCLIB_VERSION_STRING "1.00" // String version of CascLib version
-
-// Values for CascOpenStorage
-#define CASC_STOR_XXXXX 0x00000001 // Not used
+#define CASCLIB_VERSION 0x0132 // Current version of CascLib (1.50)
+#define CASCLIB_VERSION_STRING "1.50" // String version of CascLib version
// Values for CascOpenFile
-#define CASC_OPEN_BY_ENCODING_KEY 0x00000001 // The name is just the encoding key; skip ROOT file processing
+#define CASC_OPEN_BY_NAME 0x00000000 // Open the file by name. This is the default value
+#define CASC_OPEN_BY_CKEY 0x00000001 // The name is just the content key; skip ROOT file processing
+#define CASC_OPEN_BY_EKEY 0x00000002 // The name is just the encoded key; skip ROOT file processing
+#define CASC_OPEN_BY_FILEID 0x00000003 // The name is CASC_IDTONAME(FileDataId)
+#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_LOCALE_ALL 0xFFFFFFFF
#define CASC_LOCALE_NONE 0x00000000
@@ -58,25 +61,14 @@ extern "C" {
#define CASC_LOCALE_ITIT 0x00008000
#define CASC_LOCALE_PTPT 0x00010000
-#define CASC_LOCALE_BIT_ENUS 0x01
-#define CASC_LOCALE_BIT_KOKR 0x02
-#define CASC_LOCALE_BIT_RESERVED 0x03
-#define CASC_LOCALE_BIT_FRFR 0x04
-#define CASC_LOCALE_BIT_DEDE 0x05
-#define CASC_LOCALE_BIT_ZHCN 0x06
-#define CASC_LOCALE_BIT_ESES 0x07
-#define CASC_LOCALE_BIT_ZHTW 0x08
-#define CASC_LOCALE_BIT_ENGB 0x09
-#define CASC_LOCALE_BIT_ENCN 0x0A
-#define CASC_LOCALE_BIT_ENTW 0x0B
-#define CASC_LOCALE_BIT_ESMX 0x0C
-#define CASC_LOCALE_BIT_RURU 0x0D
-#define CASC_LOCALE_BIT_PTBR 0x0E
-#define CASC_LOCALE_BIT_ITIT 0x0F
-#define CASC_LOCALE_BIT_PTPT 0x10
-
-
-#define MAX_CASC_KEY_LENGTH 0x10 // Maximum length of the key (equal to MD5 hash)
+// Content flags on WoW
+#define CASC_CFLAG_LOAD_ON_WINDOWS 0x08
+#define CASC_CFLAG_LOAD_ON_MAC 0x10
+#define CASC_CFLAG_LOW_VIOLENCE 0x80
+#define CASC_CFLAG_DONT_LOAD 0x100
+#define CASC_CFLAG_NO_NAME_HASH 0x10000000
+#define CASC_CFLAG_BUNDLE 0x40000000
+#define CASC_CFLAG_NO_COMPRESSION 0x80000000
#ifndef MD5_HASH_SIZE
#define MD5_HASH_SIZE 0x10
@@ -87,79 +79,205 @@ extern "C" {
#define SHA1_DIGEST_SIZE 0x14 // 160 bits
#endif
-#ifndef LANG_NEUTRAL
-#define LANG_NEUTRAL 0x00 // Neutral locale
-#endif
-
// Return value for CascGetFileSize and CascSetFilePointer
+#define CASC_INVALID_INDEX 0xFFFFFFFF
#define CASC_INVALID_SIZE 0xFFFFFFFF
#define CASC_INVALID_POS 0xFFFFFFFF
#define CASC_INVALID_ID 0xFFFFFFFF
-
-// Flags for CascGetStorageInfo
-#define CASC_FEATURE_LISTFILE 0x00000001 // The storage supports listfile
+#define CASC_INVALID_OFFS64 0xFFFFFFFFFFFFFFFF
+
+// Flags for CASC_STORAGE_FEATURES::dwFeatures
+#define CASC_FEATURE_FILE_NAMES 0x00000001 // File names are supported by the storage
+#define CASC_FEATURE_ROOT_CKEY 0x00000002 // Present if the storage's ROOT returns CKey
+#define CASC_FEATURE_TAGS 0x00000002 // Tags are supported by the storage
+#define CASC_FEATURE_FNAME_HASHES 0x00000004 // The storage contains file name hashes on ALL files
+#define CASC_FEATURE_FNAME_HASHES_OPTIONAL 0x00000008 // The storage contains file name hashes for SOME files
+#define CASC_FEATURE_FILE_DATA_IDS 0x00000010 // The storage indexes files by FileDataId
+#define CASC_FEATURE_LOCALE_FLAGS 0x00000020 // Locale flags are supported
+#define CASC_FEATURE_CONTENT_FLAGS 0x00000040 // Content flags are supported
+#define CASC_FEATURE_ONLINE 0x00000080 // The storage is an online storage
+
+// Macro to convert FileDataId to the argument of CascOpenFile
+#define CASC_FILE_DATA_ID(FileDataId) ((LPCSTR)(size_t)FileDataId)
+#define CASC_FILE_DATA_ID_FROM_STRING(szFileName) ((DWORD)(size_t)szFileName)
//-----------------------------------------------------------------------------
// Structures
typedef enum _CASC_STORAGE_INFO_CLASS
{
- CascStorageFileCount,
+ // Returns the number of local files in the storage. Note that files
+ // can exist under different names, so the total number of files in the archive
+ // can be higher than the value returned by this info class
+ CascStorageLocalFileCount,
+
+ // Returns the total file count, including the offline files
+ CascStorageTotalFileCount,
+
+ // Returns the CASC_STORAGE_FEATURES structure.
CascStorageFeatures,
- CascStorageGameInfo,
- CascStorageGameBuild,
CascStorageInstalledLocales,
+ CascStorageProduct, // Gives CASC_STORAGE_PRODUCT
+ CascStorageTags, // Gives CASC_STORAGE_TAGS structure
CascStorageInfoClassMax
} CASC_STORAGE_INFO_CLASS, *PCASC_STORAGE_INFO_CLASS;
-
-typedef struct _QUERY_KEY
+typedef enum _CASC_FILE_INFO_CLASS
+{
+ CascFileContentKey,
+ CascFileEncodedKey,
+ CascFileFullInfo, // Gives CASC_FILE_FULL_INFO structure
+ CascFileInfoClassMax
+} CASC_FILE_INFO_CLASS, *PCASC_FILE_INFO_CLASS;
+
+// See https://wowdev.wiki/TACT#Products
+typedef enum _CASC_PRODUCT
{
- LPBYTE pbData;
- DWORD cbData;
-} QUERY_KEY, *PQUERY_KEY;
+ UnknownProduct,
+ HeroesOfTheStorm,
+ Diablo3,
+ Overwatch,
+ StarCraft1,
+ StarCraft2,
+ WorldOfWarcraft,
+ WarCraft3,
+ Destiny2,
+ CallOfDutyBlackOps4,
+ Odin,
+ MaxProductValue
+
+} CASC_PRODUCT, *PCASC_PRODUCT;
+
+// CascLib may provide a fake name, constructed from file data id, CKey or EKey.
+// This enum helps to see what name was actually returned
+// Note that any of these names can be passed to CascOpenFile with no extra flags
+typedef enum _CASC_NAME_TYPE
+{
+ CascNameFull, // Fully qualified file name
+ CascNameDataId, // Name created from file data id (FILE%08X.dat)
+ CascNameCKey, // Name created as string representation of CKey
+ CascNameEKey // Name created as string representation of EKey
+} CASC_NAME_TYPE, *PCASC_NAME_TYPE;
// Structure for SFileFindFirstFile and SFileFindNextFile
typedef struct _CASC_FIND_DATA
{
- char szFileName[MAX_PATH]; // Full name of the found file
- char * szPlainName; // Plain name of the found file
- BYTE EncodingKey[MD5_HASH_SIZE]; // Encoding key
- DWORD dwLocaleFlags; // Locale flags (WoW only)
- DWORD dwFileDataId; // File data ID (WoW only)
- DWORD dwFileSize; // Size of the file
+ // Full name of the found file. In case when this is CKey/EKey,
+ // this will be just string representation of the key stored in 'FileKey'
+ char szFileName[MAX_PATH];
+
+ // Content key. This is present if the CASC_FEATURE_ROOT_CKEY is present
+ BYTE CKey[MD5_HASH_SIZE];
+
+ // Encoded key. This is always present.
+ BYTE EKey[MD5_HASH_SIZE];
+
+ // Tag mask. Only valid if the storage supports tags, otherwise 0
+ ULONGLONG TagBitMask;
+
+ // Plain name of the found file. Pointing inside the 'szFileName' array
+ char * szPlainName;
+
+ // File data ID. Only valid if the storage supports file data IDs, otherwise CASC_INVALID_ID
+ DWORD dwFileDataId;
+
+ // Size of the file, as retrieved from CKey entry or EKey entry
+ DWORD dwFileSize;
+
+ // Locale flags. Only valid if the storage supports locale flags, otherwise CASC_INVALID_ID
+ DWORD dwLocaleFlags;
+
+ // Content flags. Only valid if the storage supports content flags, otherwise CASC_INVALID_ID
+ DWORD dwContentFlags;
+
+ // Hints as for which open method is suitable
+ DWORD bFileAvailable:1; // If true the file is available locally
+ DWORD bCanOpenByName:1;
+ DWORD bCanOpenByDataId:1;
+ DWORD bCanOpenByCKey:1;
+ DWORD bCanOpenByEKey:1;
+ CASC_NAME_TYPE NameType;
} CASC_FIND_DATA, *PCASC_FIND_DATA;
-//-----------------------------------------------------------------------------
-// Callback functions
+typedef struct _CASC_STORAGE_TAG
+{
+ LPCSTR szTagName; // Tag name (zero terminated, ANSI)
+ DWORD TagNameLength; // Length of the tag name
+ DWORD TagValue; // Tag value
+} CASC_STORAGE_TAG, *PCASC_STORAGE_TAG;
-typedef struct TFileStream TFileStream;
-typedef void (WINAPI * STREAM_DOWNLOAD_CALLBACK)(void * pvUserData, ULONGLONG ByteOffset, DWORD dwTotalBytes);
+typedef struct _CASC_STORAGE_TAGS
+{
+ size_t TagCount; // Number of items in the Tags array
+ size_t Reserved; // Reserved for future use
-//-----------------------------------------------------------------------------
-// We have our own qsort implementation, optimized for sorting array of pointers
+ CASC_STORAGE_TAG Tags[1]; // Array of CASC tags
+
+} CASC_STORAGE_TAGS, *PCASC_STORAGE_TAGS;
+
+typedef struct _CASC_STORAGE_PRODUCT
+{
+ LPCSTR szProductName;
+ DWORD dwBuildNumber;
+ CASC_PRODUCT Product;
+
+} CASC_STORAGE_PRODUCT, *PCASC_STORAGE_PRODUCT;
-void qsort_pointer_array(void ** base, size_t num, int (*compare)(const void *, const void *, const void *), const void * context);
+typedef struct _CASC_FILE_FULL_INFO
+{
+ BYTE CKey[MD5_HASH_SIZE]; // CKey
+ BYTE EKey[MD5_HASH_SIZE]; // EKey
+ char DataFileName[0x10]; // Plain name of the data file where the file is stored
+ ULONGLONG StorageOffset; // Offset of the file over the entire storage
+ ULONGLONG SegmentOffset; // Offset of the file in the segment file ("data.###")
+ ULONGLONG TagBitMask; // Bitmask of tags. Zero if not supported
+ ULONGLONG FileNameHash; // Hash of the file name. Zero if not supported
+ DWORD SegmentIndex; // Index of the segment file (aka 0 = "data.000")
+ DWORD FileDataId; // File data ID. CASC_INVALID_ID if not supported.
+ DWORD ContentSize; // Content size of the file
+ DWORD EncodedSize; // Encoded size of the file
+ DWORD LocaleFlags; // Locale flags. CASC_INVALID_ID if not supported.
+ DWORD ContentFlags; // Locale flags. CASC_INVALID_ID if not supported
+
+} CASC_FILE_FULL_INFO, *PCASC_FILE_FULL_INFO;
+
+//-----------------------------------------------------------------------------
+// Some operations (e.g. opening an online storage) may take long time.
+// This callback allows an application to be notified about loading progress.
+// This callback only works for a single CascOpen(Online)Storage call.
+
+typedef bool (WINAPI * PFNPROGRESSCALLBACK)( // Return 'true' to cancel the loading process
+ void * PtrUserParam, // User-specific parameter passed to the callback
+ LPCSTR szWork, // Text for the current activity (example: "Loading "ENCODING" file")
+ LPCSTR szObject, // (optional) name of the object tied to the activity (example: index file name)
+ DWORD nCurrent, // (optional) current object being processed
+ DWORD nTotal // (optional) If non-zero, this is the total number of objects to process
+ );
+
+void WINAPI CascSetProgressCallback(
+ PFNPROGRESSCALLBACK PtrUserCallback, // Pointer to the callback function that will be called during opening the storage
+ void * PtrUserParam // Arbitrary user parameter that will be passed to the callback
+ );
//-----------------------------------------------------------------------------
// Functions for storage manipulation
-bool WINAPI CascOpenStorage(const TCHAR * szDataPath, DWORD dwLocaleMask, HANDLE * phStorage);
+bool WINAPI CascOpenStorage(LPCTSTR szDataPath, DWORD dwLocaleMask, HANDLE * phStorage);
+bool WINAPI CascOpenOnlineStorage(LPCTSTR szLocalCache, LPCSTR szCodeName, LPCSTR szRegion, DWORD dwLocaleMask, HANDLE * phStorage);
bool WINAPI CascGetStorageInfo(HANDLE hStorage, CASC_STORAGE_INFO_CLASS InfoClass, void * pvStorageInfo, size_t cbStorageInfo, size_t * pcbLengthNeeded);
+bool WINAPI CascAddEncryptionKey(HANDLE hStorage, ULONGLONG KeyName, LPBYTE Key);
bool WINAPI CascCloseStorage(HANDLE hStorage);
-bool WINAPI CascOpenFileByIndexKey(HANDLE hStorage, PQUERY_KEY pIndexKey, DWORD dwFlags, HANDLE * phFile);
-bool WINAPI CascOpenFileByEncodingKey(HANDLE hStorage, PQUERY_KEY pEncodingKey, DWORD dwFlags, HANDLE * phFile);
-bool WINAPI CascOpenFile(HANDLE hStorage, const char * szFileName, DWORD dwLocale, DWORD dwFlags, HANDLE * phFile);
+bool WINAPI CascOpenFile(HANDLE hStorage, const void * pvFileName, DWORD dwLocaleFlags, DWORD dwOpenFlags, HANDLE * phFile);
+bool WINAPI CascGetFileInfo(HANDLE hFile, CASC_FILE_INFO_CLASS InfoClass, void * pvFileInfo, size_t cbFileInfo, size_t * pcbLengthNeeded);
DWORD WINAPI CascGetFileSize(HANDLE hFile, PDWORD pdwFileSizeHigh);
-DWORD WINAPI CascGetFileId(HANDLE hStorage, const char * szFileName);
DWORD WINAPI CascSetFilePointer(HANDLE hFile, LONG lFilePos, LONG * plFilePosHigh, DWORD dwMoveMethod);
bool WINAPI CascReadFile(HANDLE hFile, void * lpBuffer, DWORD dwToRead, PDWORD pdwRead);
bool WINAPI CascCloseFile(HANDLE hFile);
-HANDLE WINAPI CascFindFirstFile(HANDLE hStorage, const char * szMask, PCASC_FIND_DATA pFindData, const TCHAR * szListFile);
+HANDLE WINAPI CascFindFirstFile(HANDLE hStorage, LPCSTR szMask, PCASC_FIND_DATA pFindData, LPCTSTR szListFile);
bool WINAPI CascFindNextFile(HANDLE hFind, PCASC_FIND_DATA pFindData);
bool WINAPI CascFindClose(HANDLE hFind);
@@ -168,8 +286,8 @@ bool WINAPI CascFindClose(HANDLE hFind);
#ifndef PLATFORM_WINDOWS
-int GetLastError();
-void SetLastError(int nError);
+DWORD GetLastError();
+void SetLastError(DWORD dwErrCode);
#endif // PLATFORM_WINDOWS